@topogram/cli 0.3.63 → 0.3.65

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 (344) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan/index.js +703 -0
  3. package/src/adoption/plan.d.ts +6 -0
  4. package/src/adoption/plan.js +12 -703
  5. package/src/adoption/reporting.d.ts +10 -0
  6. package/src/adoption/review-groups.d.ts +6 -0
  7. package/src/agent-brief.d.ts +3 -0
  8. package/src/agent-brief.js +495 -0
  9. package/src/agent-ops/query-builders/auth.js +375 -0
  10. package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
  11. package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
  12. package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
  13. package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
  14. package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
  15. package/src/agent-ops/query-builders/change-risk.js +25 -0
  16. package/src/agent-ops/query-builders/common.js +149 -0
  17. package/src/agent-ops/query-builders/maintained-risk.js +539 -0
  18. package/src/agent-ops/query-builders/maintained-shared.js +120 -0
  19. package/src/agent-ops/query-builders/multi-agent.js +547 -0
  20. package/src/agent-ops/query-builders/projection-impacts.js +514 -0
  21. package/src/agent-ops/query-builders/work-packets.js +417 -0
  22. package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
  23. package/src/agent-ops/query-builders/workflow-context.js +398 -0
  24. package/src/agent-ops/query-builders/workflow-presets-core.js +676 -0
  25. package/src/agent-ops/query-builders/workflow-presets.js +341 -0
  26. package/src/agent-ops/query-builders.d.ts +26 -0
  27. package/src/agent-ops/query-builders.js +42 -5021
  28. package/src/archive/archive.d.ts +2 -0
  29. package/src/archive/compact.d.ts +1 -0
  30. package/src/archive/unarchive.d.ts +1 -0
  31. package/src/catalog/constants.js +10 -0
  32. package/src/catalog/copy.js +60 -0
  33. package/src/catalog/diagnostics.js +15 -0
  34. package/src/catalog/entries.js +42 -0
  35. package/src/catalog/files.js +67 -0
  36. package/src/catalog/provenance.js +122 -0
  37. package/src/catalog/source.js +150 -0
  38. package/src/catalog/validation.js +252 -0
  39. package/src/catalog.d.ts +12 -0
  40. package/src/catalog.js +18 -750
  41. package/src/cli/catalog-alias.d.ts +1 -0
  42. package/src/cli/command-parser.js +38 -0
  43. package/src/cli/command-parsers/core.js +102 -0
  44. package/src/cli/command-parsers/generator.js +39 -0
  45. package/src/cli/command-parsers/import.js +44 -0
  46. package/src/cli/command-parsers/legacy-workflow.js +21 -0
  47. package/src/cli/command-parsers/project.js +47 -0
  48. package/src/cli/command-parsers/sdlc.js +47 -0
  49. package/src/cli/command-parsers/shared.js +51 -0
  50. package/src/cli/command-parsers/template.js +48 -0
  51. package/src/cli/commands/agent.js +47 -0
  52. package/src/cli/commands/catalog/check.js +31 -0
  53. package/src/cli/commands/catalog/copy.js +59 -0
  54. package/src/cli/commands/catalog/doctor.js +248 -0
  55. package/src/cli/commands/catalog/help.js +21 -0
  56. package/src/cli/commands/catalog/list.js +52 -0
  57. package/src/cli/commands/catalog/runner.js +92 -0
  58. package/src/cli/commands/catalog/shared.js +17 -0
  59. package/src/cli/commands/catalog/show.js +134 -0
  60. package/src/cli/commands/catalog.js +32 -0
  61. package/src/cli/commands/check.js +268 -0
  62. package/src/cli/commands/doctor.js +268 -0
  63. package/src/cli/commands/emit.js +149 -0
  64. package/src/cli/commands/generate.js +96 -0
  65. package/src/cli/commands/generator-policy/package-info.js +162 -0
  66. package/src/cli/commands/generator-policy/payloads.js +372 -0
  67. package/src/cli/commands/generator-policy/printers.js +159 -0
  68. package/src/cli/commands/generator-policy/runner.js +81 -0
  69. package/src/cli/commands/generator-policy/shared.js +39 -0
  70. package/src/cli/commands/generator-policy.js +17 -0
  71. package/src/cli/commands/generator.js +443 -0
  72. package/src/cli/commands/import/adopt.js +170 -0
  73. package/src/cli/commands/import/check.js +91 -0
  74. package/src/cli/commands/import/diff.js +84 -0
  75. package/src/cli/commands/import/help.js +47 -0
  76. package/src/cli/commands/import/paths.js +277 -0
  77. package/src/cli/commands/import/plan.js +284 -0
  78. package/src/cli/commands/import/refresh.js +470 -0
  79. package/src/cli/commands/import/status-history.js +196 -0
  80. package/src/cli/commands/import/workspace.js +230 -0
  81. package/src/cli/commands/import-runner.js +157 -0
  82. package/src/cli/commands/import.js +35 -0
  83. package/src/cli/commands/inspect.js +55 -0
  84. package/src/cli/commands/new.js +94 -0
  85. package/src/cli/commands/package/constants.js +17 -0
  86. package/src/cli/commands/package/doctor.js +240 -0
  87. package/src/cli/commands/package/help.js +27 -0
  88. package/src/cli/commands/package/lockfile.js +135 -0
  89. package/src/cli/commands/package/npm.js +97 -0
  90. package/src/cli/commands/package/reporting.js +35 -0
  91. package/src/cli/commands/package/runner.js +33 -0
  92. package/src/cli/commands/package/shared.js +9 -0
  93. package/src/cli/commands/package/update-cli.js +252 -0
  94. package/src/cli/commands/package/versions.js +35 -0
  95. package/src/cli/commands/package.js +31 -0
  96. package/src/cli/commands/query/change-plan.js +68 -0
  97. package/src/cli/commands/query/definitions.js +202 -0
  98. package/src/cli/commands/query/import-adopt.js +121 -0
  99. package/src/cli/commands/query/runner/artifacts.js +102 -0
  100. package/src/cli/commands/query/runner/boundaries.js +211 -0
  101. package/src/cli/commands/query/runner/change.js +182 -0
  102. package/src/cli/commands/query/runner/import-adopt.js +111 -0
  103. package/src/cli/commands/query/runner/index.js +31 -0
  104. package/src/cli/commands/query/runner/output.js +12 -0
  105. package/src/cli/commands/query/runner/workflow.js +241 -0
  106. package/src/cli/commands/query/runner.js +3 -0
  107. package/src/cli/commands/query/workflow-context.js +5 -0
  108. package/src/cli/commands/query/workspace.js +274 -0
  109. package/src/cli/commands/query.js +11 -0
  110. package/src/cli/commands/release-rollout.js +257 -0
  111. package/src/cli/commands/release-shared.js +528 -0
  112. package/src/cli/commands/release-status.js +429 -0
  113. package/src/cli/commands/release.js +107 -0
  114. package/src/cli/commands/sdlc.js +168 -0
  115. package/src/cli/commands/setup.js +76 -0
  116. package/src/cli/commands/source.js +291 -0
  117. package/src/cli/commands/template/baseline.js +100 -0
  118. package/src/cli/commands/template/check.js +466 -0
  119. package/src/cli/commands/template/constants.js +8 -0
  120. package/src/cli/commands/template/diagnostics.js +26 -0
  121. package/src/cli/commands/template/help.js +28 -0
  122. package/src/cli/commands/template/lifecycle.js +404 -0
  123. package/src/cli/commands/template/list-show.js +287 -0
  124. package/src/cli/commands/template/policy.js +422 -0
  125. package/src/cli/commands/template/shared.js +127 -0
  126. package/src/cli/commands/template/updates.js +352 -0
  127. package/src/cli/commands/template-runner.js +198 -0
  128. package/src/cli/commands/template.js +43 -0
  129. package/src/cli/commands/trust.js +219 -0
  130. package/src/cli/commands/version.js +40 -0
  131. package/src/cli/commands/widget.js +168 -0
  132. package/src/cli/commands/workflow.js +63 -0
  133. package/src/cli/dispatcher.js +392 -0
  134. package/src/cli/help-dispatch.js +188 -0
  135. package/src/cli/help.js +296 -0
  136. package/src/cli/migration-guidance.js +59 -0
  137. package/src/cli/options.js +96 -0
  138. package/src/cli/output-safety.js +107 -0
  139. package/src/cli/path-normalization.js +29 -0
  140. package/src/cli.js +47 -11711
  141. package/src/example-implementation.d.ts +2 -0
  142. package/src/format.d.ts +1 -0
  143. package/src/generator/api/contracts.js +497 -0
  144. package/src/generator/api/metadata.js +221 -0
  145. package/src/generator/api/openapi.js +559 -0
  146. package/src/generator/api/schema.js +124 -0
  147. package/src/generator/api/types.d.ts +98 -0
  148. package/src/generator/api.js +3 -1195
  149. package/src/generator/check.d.ts +1 -0
  150. package/src/generator/context/bundle.d.ts +1 -0
  151. package/src/generator/context/shared/domain-sdlc.js +282 -0
  152. package/src/generator/context/shared/maintained-boundary.js +665 -0
  153. package/src/generator/context/shared/metrics.js +85 -0
  154. package/src/generator/context/shared/primitives.js +64 -0
  155. package/src/generator/context/shared/relationships.js +453 -0
  156. package/src/generator/context/shared/summaries.js +263 -0
  157. package/src/generator/context/shared/types.d.ts +207 -0
  158. package/src/generator/context/shared.d.ts +44 -0
  159. package/src/generator/context/shared.js +80 -1390
  160. package/src/generator/context/slice/core.js +397 -0
  161. package/src/generator/context/slice/sdlc.js +417 -0
  162. package/src/generator/context/slice/ui-packets.js +183 -0
  163. package/src/generator/context/slice.js +2 -859
  164. package/src/generator/native/parity-bundle.js +2 -1
  165. package/src/generator/registry/index.js +507 -0
  166. package/src/generator/registry.js +18 -504
  167. package/src/generator/runtime/environment/index.js +666 -0
  168. package/src/generator/runtime/environment.js +4 -666
  169. package/src/generator/runtime/runtime-check/index.js +554 -0
  170. package/src/generator/runtime/runtime-check.js +4 -554
  171. package/src/generator/runtime/shared/index.js +572 -0
  172. package/src/generator/runtime/shared.js +19 -570
  173. package/src/generator/shared.d.ts +2 -0
  174. package/src/generator/surfaces/shared.d.ts +3 -0
  175. package/src/generator/surfaces/web/html-escape.js +22 -0
  176. package/src/generator/surfaces/web/react.js +10 -8
  177. package/src/generator/surfaces/web/sveltekit.js +7 -5
  178. package/src/generator/surfaces/web/vanilla.js +8 -4
  179. package/src/generator/widget-conformance/behavior-report.js +258 -0
  180. package/src/generator/widget-conformance/checks.js +371 -0
  181. package/src/generator/widget-conformance/projection-context.js +200 -0
  182. package/src/generator/widget-conformance/report.js +166 -0
  183. package/src/generator/widget-conformance/types.d.ts +121 -0
  184. package/src/generator/widget-conformance.js +3 -824
  185. package/src/generator.d.ts +2 -0
  186. package/src/github-client.js +520 -0
  187. package/src/import/core/context.d.ts +3 -0
  188. package/src/import/core/contracts.d.ts +1 -0
  189. package/src/import/core/registry.d.ts +4 -0
  190. package/src/import/core/runner/candidates.js +217 -0
  191. package/src/import/core/runner/options.js +22 -0
  192. package/src/import/core/runner/reports.js +50 -0
  193. package/src/import/core/runner/run.js +79 -0
  194. package/src/import/core/runner/tracks.js +150 -0
  195. package/src/import/core/runner/ui-drafts.js +337 -0
  196. package/src/import/core/runner.js +3 -698
  197. package/src/import/core/shared/api-routes.js +221 -0
  198. package/src/import/core/shared/candidates.js +97 -0
  199. package/src/import/core/shared/files.js +177 -0
  200. package/src/import/core/shared/next-app.js +389 -0
  201. package/src/import/core/shared/types.d.ts +51 -0
  202. package/src/import/core/shared/ui-routes.js +230 -0
  203. package/src/import/core/shared.js +67 -910
  204. package/src/import/extractors/api/flutter-dio.js +4 -8
  205. package/src/import/extractors/api/react-native-repository.js +4 -8
  206. package/src/import/index.d.ts +4 -0
  207. package/src/import/provenance.d.ts +4 -0
  208. package/src/new-project/constants.js +128 -0
  209. package/src/new-project/create.js +83 -0
  210. package/src/new-project/json.js +28 -0
  211. package/src/new-project/metadata.js +96 -0
  212. package/src/new-project/package-spec.js +161 -0
  213. package/src/new-project/project-files.js +348 -0
  214. package/src/new-project/template-policy.js +269 -0
  215. package/src/new-project/template-resolution.js +368 -0
  216. package/src/new-project/template-snapshots.js +430 -0
  217. package/src/new-project/template-updates.js +512 -0
  218. package/src/new-project/types.d.ts +83 -0
  219. package/src/new-project.js +6 -2188
  220. package/src/npm-safety.js +79 -0
  221. package/src/parser.d.ts +87 -0
  222. package/src/parser.js +118 -0
  223. package/src/path-helpers.d.ts +1 -0
  224. package/src/path-helpers.js +20 -0
  225. package/src/policy/review-boundaries.d.ts +15 -0
  226. package/src/project-config/index.js +564 -0
  227. package/src/project-config.js +19 -560
  228. package/src/reconcile/docs.d.ts +8 -0
  229. package/src/reconcile/journeys.d.ts +1 -0
  230. package/src/resolver/enrich/acceptance-criterion.js +2 -0
  231. package/src/resolver/enrich/bug.js +2 -0
  232. package/src/resolver/enrich/pitch.js +2 -0
  233. package/src/resolver/enrich/requirement.js +2 -0
  234. package/src/resolver/enrich/task.js +2 -0
  235. package/src/resolver/index.js +19 -2089
  236. package/src/resolver/normalize.js +384 -1
  237. package/src/resolver/plans.js +168 -0
  238. package/src/resolver/projections-api.js +494 -0
  239. package/src/resolver/projections-db.js +133 -0
  240. package/src/resolver/projections-ui.js +317 -0
  241. package/src/resolver/shapes.js +251 -0
  242. package/src/resolver/shared.js +278 -0
  243. package/src/resolver/widgets.js +132 -0
  244. package/src/resolver.d.ts +1 -0
  245. package/src/runtime-support.js +29 -0
  246. package/src/sdlc/adopt.d.ts +1 -0
  247. package/src/sdlc/check.d.ts +1 -0
  248. package/src/sdlc/explain.d.ts +1 -0
  249. package/src/sdlc/release.d.ts +1 -0
  250. package/src/sdlc/scaffold.d.ts +1 -0
  251. package/src/sdlc/transition.d.ts +1 -0
  252. package/src/template-trust/constants.js +62 -0
  253. package/src/template-trust/content.js +258 -0
  254. package/src/template-trust/diff.js +92 -0
  255. package/src/template-trust/policy.js +61 -0
  256. package/src/template-trust/record.js +90 -0
  257. package/src/template-trust/status.js +182 -0
  258. package/src/template-trust.js +24 -687
  259. package/src/text-helpers.d.ts +7 -0
  260. package/src/text-helpers.js +245 -0
  261. package/src/topogram-config.js +306 -0
  262. package/src/topogram-types.d.ts +69 -0
  263. package/src/validator/common.js +488 -0
  264. package/src/validator/data-model.js +237 -0
  265. package/src/validator/docs.js +167 -0
  266. package/src/validator/expressions.js +146 -1
  267. package/src/validator/index.d.ts +23 -0
  268. package/src/validator/index.js +32 -3585
  269. package/src/validator/kinds.d.ts +41 -0
  270. package/src/validator/kinds.js +2 -0
  271. package/src/validator/model-helpers.js +46 -0
  272. package/src/validator/per-kind/acceptance-criterion.js +5 -0
  273. package/src/validator/per-kind/bug.js +6 -0
  274. package/src/validator/per-kind/domain.js +15 -2
  275. package/src/validator/per-kind/pitch.js +7 -0
  276. package/src/validator/per-kind/requirement.js +5 -0
  277. package/src/validator/per-kind/task.js +7 -0
  278. package/src/validator/per-kind/widget.js +14 -0
  279. package/src/validator/projections/api-http-async.js +410 -0
  280. package/src/validator/projections/api-http-authz.js +88 -0
  281. package/src/validator/projections/api-http-core.js +205 -0
  282. package/src/validator/projections/api-http-policies.js +339 -0
  283. package/src/validator/projections/api-http-responses.js +233 -0
  284. package/src/validator/projections/api-http.js +44 -0
  285. package/src/validator/projections/db.js +353 -0
  286. package/src/validator/projections/generator-defaults.js +45 -0
  287. package/src/validator/projections/helpers.js +87 -0
  288. package/src/validator/projections/ui-helpers.js +214 -0
  289. package/src/validator/projections/ui-navigation.js +344 -0
  290. package/src/validator/projections/ui-structure.js +364 -0
  291. package/src/validator/projections/ui-widgets.js +493 -0
  292. package/src/validator/projections/ui.js +46 -0
  293. package/src/validator/registry.js +48 -1
  294. package/src/validator/utils.d.ts +20 -0
  295. package/src/validator/utils.js +115 -12
  296. package/src/validator.d.ts +2 -0
  297. package/src/widget-behavior.d.ts +1 -0
  298. package/src/workflows/adoption/index.js +26 -0
  299. package/src/workflows/docs-generate.js +262 -0
  300. package/src/workflows/docs-scan.js +703 -0
  301. package/src/workflows/docs.js +15 -0
  302. package/src/workflows/import-app/api/collect.js +221 -0
  303. package/src/workflows/import-app/api/openapi.js +257 -0
  304. package/src/workflows/import-app/api/routes.js +327 -0
  305. package/src/workflows/import-app/api/sources.js +22 -0
  306. package/src/workflows/import-app/api.js +4 -0
  307. package/src/workflows/import-app/db.js +538 -0
  308. package/src/workflows/import-app/index.js +30 -0
  309. package/src/workflows/import-app/shared.js +218 -0
  310. package/src/workflows/import-app/ui.js +443 -0
  311. package/src/workflows/import-app/workflow.js +159 -0
  312. package/src/workflows/reconcile/adoption-plan/build.js +208 -0
  313. package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
  314. package/src/workflows/reconcile/adoption-plan/outputs.js +143 -0
  315. package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
  316. package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
  317. package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
  318. package/src/workflows/reconcile/adoption-plan.js +32 -0
  319. package/src/workflows/reconcile/auth/closures.js +115 -0
  320. package/src/workflows/reconcile/auth/formatters.js +142 -0
  321. package/src/workflows/reconcile/auth/inference.js +330 -0
  322. package/src/workflows/reconcile/auth/roles.js +122 -0
  323. package/src/workflows/reconcile/auth.js +37 -0
  324. package/src/workflows/reconcile/bundle-core/index.js +600 -0
  325. package/src/workflows/reconcile/bundle-core.js +14 -0
  326. package/src/workflows/reconcile/bundle-shared.js +75 -0
  327. package/src/workflows/reconcile/candidate-model.js +477 -0
  328. package/src/workflows/reconcile/canonical-surface.js +264 -0
  329. package/src/workflows/reconcile/gap-report.js +333 -0
  330. package/src/workflows/reconcile/ids.js +6 -0
  331. package/src/workflows/reconcile/impacts/adoption-plan.js +192 -0
  332. package/src/workflows/reconcile/impacts/indexes.js +101 -0
  333. package/src/workflows/reconcile/impacts/patches.js +252 -0
  334. package/src/workflows/reconcile/impacts/reports.js +80 -0
  335. package/src/workflows/reconcile/impacts.js +16 -0
  336. package/src/workflows/reconcile/index.js +7 -0
  337. package/src/workflows/reconcile/renderers.js +461 -0
  338. package/src/workflows/reconcile/summary.js +90 -0
  339. package/src/workflows/reconcile/workflow.js +309 -0
  340. package/src/workflows/shared.js +189 -0
  341. package/src/workflows/types.d.ts +93 -0
  342. package/src/workflows.d.ts +1 -0
  343. package/src/workflows.js +10 -7652
  344. package/src/workspace-docs.d.ts +29 -0
@@ -0,0 +1,159 @@
1
+ // @ts-check
2
+ import { idHintify, titleCase } from "../../text-helpers.js";
3
+ import { scanDocsWorkflow } from "../docs.js";
4
+ import { collectApiImport } from "./api.js";
5
+ import { collectDbImport } from "./db.js";
6
+ import { dedupeCandidateRecords, inferCapabilityEntityId, makeCandidateRecord } from "./shared.js";
7
+
8
+ /** @param {WorkflowRecord} capability @returns {any} */
9
+ function workflowEntityIdForCapability(capability) {
10
+ return inferCapabilityEntityId(capability);
11
+ }
12
+
13
+ /** @param {WorkflowRecord} entity @param {any} enumCandidatesById @returns {any} */
14
+ function findEntityStatusFields(entity, enumCandidatesById) {
15
+ return (entity?.fields || []).filter((/** @type {any} */ field) =>
16
+ ["status", "state"].includes(field.name) && enumCandidatesById.has(idHintify(field.field_type))
17
+ );
18
+ }
19
+
20
+ /** @param {WorkflowRecord} capability @param {any[]} knownStates @returns {any} */
21
+ function targetStateForCapability(capability, knownStates) {
22
+ if (capability.target_state) {
23
+ const explicitState = idHintify(capability.target_state);
24
+ if (knownStates.length === 0 || knownStates.includes(explicitState)) {
25
+ return explicitState;
26
+ }
27
+ }
28
+ const id = capability.id_hint || "";
29
+ const method = String(capability.endpoint?.method || "").toUpperCase();
30
+ const candidates = [
31
+ ["sign_in", "authenticated"],
32
+ ["login", "authenticated"],
33
+ ["authenticate", "authenticated"],
34
+ ["register", "registered"],
35
+ ["approve", "approved"],
36
+ ["reject", "rejected"],
37
+ ["revision", "needs_revision"],
38
+ ["request_revision", "needs_revision"],
39
+ ["submit", "submitted"],
40
+ ["close", "closed"],
41
+ ["complete", "completed"],
42
+ ["archive", "archived"],
43
+ ["delete", "deleted"],
44
+ [method === "POST" && id.startsWith("cap_create_") ? "create" : "", knownStates[0] || "created"]
45
+ ].filter((/** @type {any} */ [needle]) => needle);
46
+ for (const [needle, state] of candidates) {
47
+ if (id.includes(needle) && state) {
48
+ const canonicalState = idHintify(state);
49
+ if (knownStates.length === 0 || knownStates.includes(canonicalState)) {
50
+ return canonicalState;
51
+ }
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+
57
+ /** @param {WorkspacePaths} paths @returns {any} */
58
+ export function collectWorkflowImport(paths) {
59
+ /** @type {any[]} */
60
+ const findings = [];
61
+ /** @type {WorkflowRecord} */
62
+ const candidates = {
63
+ workflows: [],
64
+ workflow_states: [],
65
+ workflow_transitions: []
66
+ };
67
+ const dbImport = collectDbImport(paths);
68
+ const apiImport = collectApiImport(paths);
69
+ const docScan = scanDocsWorkflow(paths.topogramRoot).summary;
70
+ const enumCandidatesById = new Map((dbImport.candidates.enums || []).map((/** @type {any} */ entry) => [entry.id_hint, entry]));
71
+ const entityCandidatesById = new Map((dbImport.candidates.entities || []).map((/** @type {any} */ entry) => [entry.id_hint, entry]));
72
+ const workflowDocs = (docScan.candidate_docs || []).filter((/** @type {any} */ doc) => doc.kind === "workflow");
73
+ const workflows = new Map();
74
+
75
+ for (const capability of apiImport.candidates.capabilities || []) {
76
+ const entityId = workflowEntityIdForCapability(capability);
77
+ const workflowId = `workflow_${entityId.replace(/^entity_/, "")}`;
78
+ const capabilityActors =
79
+ capability.auth_hint === "secured" ? ["user"] :
80
+ capability.auth_hint === "public" ? ["anonymous"] :
81
+ [];
82
+ if (!workflows.has(workflowId)) {
83
+ const entity = entityCandidatesById.get(entityId);
84
+ const statusFields = findEntityStatusFields(entity, enumCandidatesById);
85
+ const states = statusFields.flatMap((/** @type {any} */ field) => enumCandidatesById.get(idHintify(field.field_type))?.values || []).map(idHintify);
86
+ workflows.set(workflowId, {
87
+ workflow: makeCandidateRecord({
88
+ kind: "workflow",
89
+ idHint: workflowId,
90
+ label: `${titleCase(entityId.replace(/^entity_/, ""))} Workflow`,
91
+ confidence: "medium",
92
+ sourceKind: "generated_artifact",
93
+ provenance: capability.provenance || [],
94
+ track: "workflows",
95
+ entity_id: entityId,
96
+ actor_hints: capabilityActors,
97
+ related_capabilities: []
98
+ }),
99
+ states: states.map((/** @type {any} */ state) =>
100
+ makeCandidateRecord({
101
+ kind: "workflow_state",
102
+ idHint: `${workflowId}_${state}`,
103
+ label: titleCase(state),
104
+ confidence: "medium",
105
+ sourceKind: "schema",
106
+ provenance: entity?.provenance || capability.provenance || [],
107
+ track: "workflows",
108
+ workflow_id: workflowId,
109
+ entity_id: entityId,
110
+ state_id: state
111
+ })
112
+ ),
113
+ transitions: []
114
+ });
115
+ }
116
+ const workflow = workflows.get(workflowId);
117
+ workflow.workflow.related_capabilities.push(capability.id_hint);
118
+ workflow.workflow.actor_hints = [...new Set([...(workflow.workflow.actor_hints || []), ...capabilityActors])].sort();
119
+ const knownStates = workflow.states.map((/** @type {any} */ entry) => entry.state_id);
120
+ const targetState = targetStateForCapability(capability, knownStates);
121
+ if (targetState) {
122
+ workflow.transitions.push(
123
+ makeCandidateRecord({
124
+ kind: "workflow_transition",
125
+ idHint: `${workflowId}_${idHintify(capability.id_hint)}`,
126
+ label: titleCase(capability.id_hint.replace(/^cap_/, "")),
127
+ confidence: "low",
128
+ sourceKind: capability.source_kind || "generated_artifact",
129
+ provenance: capability.provenance || [],
130
+ track: "workflows",
131
+ workflow_id: workflowId,
132
+ entity_id: entityId,
133
+ capability_id: capability.id_hint,
134
+ actor_hints: capabilityActors,
135
+ to_state: targetState
136
+ })
137
+ );
138
+ }
139
+ }
140
+
141
+ for (const workflow of workflows.values()) {
142
+ workflow.workflow.related_capabilities = [...new Set(workflow.workflow.related_capabilities)].sort();
143
+ candidates.workflows.push(workflow.workflow);
144
+ candidates.workflow_states.push(...workflow.states);
145
+ candidates.workflow_transitions.push(...workflow.transitions);
146
+ }
147
+
148
+ findings.push({
149
+ kind: "workflow_inference",
150
+ workflow_count: candidates.workflows.length,
151
+ workflow_doc_signals: workflowDocs.map((/** @type {any} */ doc) => doc.id)
152
+ });
153
+
154
+ candidates.workflows = dedupeCandidateRecords(candidates.workflows, (/** @type {any} */ record) => record.id_hint);
155
+ candidates.workflow_states = dedupeCandidateRecords(candidates.workflow_states, (/** @type {any} */ record) => record.id_hint);
156
+ candidates.workflow_transitions = dedupeCandidateRecords(candidates.workflow_transitions, (/** @type {any} */ record) => record.id_hint);
157
+
158
+ return { findings, candidates };
159
+ }
@@ -0,0 +1,208 @@
1
+ // @ts-check
2
+
3
+ import { adoptionItemKey } from "../../../adoption/plan.js";
4
+ import { confidenceRank } from "../../docs.js";
5
+ import {
6
+ adoptionStatusForStep,
7
+ blockingDependenciesForProjectionImpacts,
8
+ blockingDependenciesForUiImpacts,
9
+ blockingDependenciesForWorkflowImpacts,
10
+ projectionImpactsForAdoptionItem
11
+ } from "./dependencies.js";
12
+ import {
13
+ canonicalDisplayPathForItem,
14
+ canonicalRelativePathForItem,
15
+ candidateSourcePathForItem
16
+ } from "./paths.js";
17
+ import {
18
+ reasonForAdoptionItem,
19
+ recommendationForAdoptionItem
20
+ } from "./reasons.js";
21
+
22
+ /** @param {CandidateBundle[]} bundles @returns {any} */
23
+ export function buildAdoptionPlan(bundles) {
24
+ /** @type {any[]} */
25
+ const items = [];
26
+ for (const bundle of bundles) {
27
+ for (const step of bundle.adoptionPlan || []) {
28
+ const itemKind =
29
+ step.action === "merge_bundle_into_existing_entity" ? "bundle" :
30
+ step.action === "apply_projection_permission_patch" ? "projection_permission_patch" :
31
+ step.action === "apply_projection_auth_patch" ? "projection_auth_patch" :
32
+ step.action === "apply_projection_ownership_patch" ? "projection_ownership_patch" :
33
+ step.action.includes("doc") ? "doc" :
34
+ step.action.includes("decision") ? "decision" :
35
+ step.action.includes("verification") ? "verification" :
36
+ step.action.includes("widget") ? "widget" :
37
+ step.action.includes("ui_") ? "ui" :
38
+ step.action.includes("actor") ? "actor" :
39
+ step.action.includes("role") ? "role" :
40
+ step.action.includes("enum") ? "enum" :
41
+ step.action.includes("shape") ? "shape" :
42
+ step.action.includes("capability") ? "capability" :
43
+ step.action.includes("entity") ? "entity" :
44
+ "bundle";
45
+ if (itemKind === "bundle") {
46
+ continue;
47
+ }
48
+ const projectionImpacts = projectionImpactsForAdoptionItem(bundle, step);
49
+ const directProjectionBlockingDependencies =
50
+ (step.action === "apply_projection_permission_patch" || step.action === "apply_projection_auth_patch" || step.action === "apply_projection_ownership_patch") && step.target
51
+ ? blockingDependenciesForProjectionImpacts([
52
+ {
53
+ projection_id: step.target,
54
+ kind: step.projection_kind || "api",
55
+ projection_type: null,
56
+ reason: `Projection ${step.target} auth rules need explicit review before promotion.`
57
+ }
58
+ ])
59
+ : [];
60
+ const uiImpacts = step.action.includes("ui_") ? bundle.uiImpacts || [] : [];
61
+ const workflowImpacts = step.action.includes("workflow") ? bundle.workflowImpacts || [] : [];
62
+ const blockingDependencies = [
63
+ ...blockingDependenciesForProjectionImpacts(projectionImpacts),
64
+ ...directProjectionBlockingDependencies,
65
+ ...blockingDependenciesForUiImpacts(uiImpacts),
66
+ ...blockingDependenciesForWorkflowImpacts(workflowImpacts)
67
+ ];
68
+ items.push({
69
+ bundle: bundle.slug,
70
+ item: step.item,
71
+ kind: itemKind,
72
+ track:
73
+ step.action.includes("workflow") ? "workflows" :
74
+ step.action.includes("verification") ? "verification" :
75
+ step.action.includes("ui_") ? "ui" :
76
+ step.action === "apply_projection_permission_patch" ? "projection" :
77
+ step.action === "apply_projection_auth_patch" ? "projection" :
78
+ step.action === "apply_projection_ownership_patch" ? "projection" :
79
+ step.action.includes("doc") ? "docs" :
80
+ itemKind,
81
+ suggested_action: step.action,
82
+ target: step.target || null,
83
+ confidence: step.confidence || null,
84
+ inference_summary: step.inference_summary || null,
85
+ related_docs: step.related_docs || [],
86
+ related_capabilities: step.related_capabilities || [],
87
+ permission: step.permission || null,
88
+ claim: step.claim || null,
89
+ claim_value: Object.prototype.hasOwnProperty.call(step, "claim_value") ? step.claim_value : null,
90
+ ownership: step.ownership || null,
91
+ ownership_field: step.ownership_field || null,
92
+ projection_surface: step.projection_surface || null,
93
+ status: adoptionStatusForStep(step, projectionImpacts, uiImpacts, workflowImpacts),
94
+ source_path: step.source_path || candidateSourcePathForItem(bundle, itemKind, step.item),
95
+ canonical_path:
96
+ step.action === "skip_duplicate_shape"
97
+ ? (step.target ? canonicalDisplayPathForItem("shape", step.target) : null)
98
+ : (step.canonical_rel_path ? `topogram/${step.canonical_rel_path}` : canonicalDisplayPathForItem(itemKind, step.item)),
99
+ canonical_rel_path: step.canonical_rel_path || canonicalRelativePathForItem(itemKind, step.item),
100
+ reason: reasonForAdoptionItem(step),
101
+ recommendation: recommendationForAdoptionItem(step),
102
+ projection_impacts: projectionImpacts,
103
+ ui_impacts: uiImpacts,
104
+ workflow_impacts: workflowImpacts,
105
+ blocking_dependencies: blockingDependencies
106
+ });
107
+ }
108
+ for (const patch of bundle.projectionPatches || []) {
109
+ items.push({
110
+ bundle: bundle.slug,
111
+ item: `projection_patch:${patch.projection_id}`,
112
+ kind: "projection_patch",
113
+ track: "projection",
114
+ suggested_action: "review_projection_patch",
115
+ target: patch.projection_id,
116
+ status: "needs_projection_review",
117
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
118
+ canonical_path: null,
119
+ canonical_rel_path: null,
120
+ reason: patch.reason || `Projection ${patch.projection_id} needs additive review.`,
121
+ projection_impacts: [
122
+ {
123
+ projection_id: patch.projection_id,
124
+ kind: patch.kind,
125
+ projection_type: patch.projection_type,
126
+ missing_capabilities: patch.missing_realizes || []
127
+ }
128
+ ],
129
+ ui_impacts: (patch.missing_screens || []).length > 0 ? [
130
+ {
131
+ projection_id: patch.projection_id,
132
+ kind: patch.kind,
133
+ projection_type: patch.projection_type,
134
+ missing_screens: patch.missing_screens || []
135
+ }
136
+ ] : [],
137
+ workflow_impacts: [],
138
+ blocking_dependencies: blockingDependenciesForProjectionImpacts([
139
+ {
140
+ projection_id: patch.projection_id,
141
+ kind: patch.kind,
142
+ projection_type: patch.projection_type,
143
+ reason: patch.reason || `Projection ${patch.projection_id} needs additive review.`
144
+ }
145
+ ])
146
+ });
147
+ }
148
+ for (const patch of bundle.docLinkSuggestions || []) {
149
+ items.push({
150
+ bundle: bundle.slug,
151
+ item: `doc_link_patch:${patch.doc_id}`,
152
+ kind: "doc_link_patch",
153
+ track: "docs",
154
+ suggested_action: "apply_doc_link_patch",
155
+ target: patch.doc_id,
156
+ status: "pending",
157
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
158
+ canonical_path: patch.canonical_rel_path ? `topogram/${patch.canonical_rel_path}` : null,
159
+ canonical_rel_path: patch.canonical_rel_path || null,
160
+ reason: `Apply suggested related actor/role links to \`${patch.doc_id}\`.`,
161
+ recommendation: recommendationForAdoptionItem({ action: "apply_doc_link_patch", target: patch.doc_id }),
162
+ related_docs: [patch.doc_id],
163
+ related_actors: patch.add_related_actors || [],
164
+ related_roles: patch.add_related_roles || [],
165
+ related_capabilities: patch.add_related_capabilities || [],
166
+ related_rules: patch.add_related_rules || [],
167
+ related_workflows: patch.add_related_workflows || [],
168
+ projection_impacts: [],
169
+ ui_impacts: [],
170
+ workflow_impacts: [],
171
+ blocking_dependencies: []
172
+ });
173
+ }
174
+ for (const patch of bundle.docMetadataPatches || []) {
175
+ items.push({
176
+ bundle: bundle.slug,
177
+ item: `doc_metadata_patch:${patch.doc_id}`,
178
+ kind: "doc_metadata_patch",
179
+ track: "docs",
180
+ suggested_action: "apply_doc_metadata_patch",
181
+ target: patch.doc_id,
182
+ status: "pending",
183
+ confidence: patch.imported_confidence || "low",
184
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
185
+ canonical_path: patch.canonical_rel_path ? `topogram/${patch.canonical_rel_path}` : null,
186
+ canonical_rel_path: patch.canonical_rel_path || null,
187
+ reason: `Apply suggested safe metadata updates to \`${patch.doc_id}\`.`,
188
+ recommendation: recommendationForAdoptionItem({ action: "apply_doc_metadata_patch", target: patch.doc_id }),
189
+ related_docs: [patch.doc_id],
190
+ summary: patch.summary || null,
191
+ success_outcome: patch.success_outcome || null,
192
+ actors: patch.actors || [],
193
+ projection_impacts: [],
194
+ ui_impacts: [],
195
+ workflow_impacts: [],
196
+ blocking_dependencies: []
197
+ });
198
+ }
199
+ }
200
+ return items.sort((/** @type {any} */ a, /** @type {any} */ b) =>
201
+ a.bundle.localeCompare(b.bundle) ||
202
+ confidenceRank(b.confidence || "low") - confidenceRank(a.confidence || "low") ||
203
+ a.kind.localeCompare(b.kind) ||
204
+ a.item.localeCompare(b.item)
205
+ );
206
+ }
207
+
208
+ export const ADOPT_SELECTORS = new Set(["from-plan", "actors", "roles", "enums", "shapes", "entities", "capabilities", "widgets", "docs", "journeys", "workflows", "verification", "ui"]);
@@ -0,0 +1,75 @@
1
+ // @ts-check
2
+
3
+ /** @param {WorkflowRecord} step @param {any[]} projectionImpacts @param {any[]} uiImpacts @param {any[]} workflowImpacts @returns {any} */
4
+ export function adoptionStatusForStep(step, projectionImpacts = [], uiImpacts = [], workflowImpacts = []) {
5
+ if (step.action === "skip_duplicate_shape") {
6
+ return "skipped";
7
+ }
8
+ if (step.action === "apply_projection_permission_patch") {
9
+ return "needs_projection_review";
10
+ }
11
+ if (step.action === "apply_projection_auth_patch") {
12
+ return "needs_projection_review";
13
+ }
14
+ if (step.action === "apply_projection_ownership_patch") {
15
+ return "needs_projection_review";
16
+ }
17
+ if (step.action.includes("capability") && projectionImpacts.length > 0) {
18
+ return "needs_projection_review";
19
+ }
20
+ if (step.action.includes("ui_") && uiImpacts.length > 0) {
21
+ return "needs_ui_review";
22
+ }
23
+ if (step.action.includes("workflow") && workflowImpacts.length > 0) {
24
+ return "needs_workflow_review";
25
+ }
26
+ return "pending";
27
+ }
28
+
29
+ /** @param {CandidateBundle} bundle @param {WorkflowRecord} step @returns {any} */
30
+ export function projectionImpactsForAdoptionItem(bundle, step) {
31
+ if (!step.action.includes("capability")) {
32
+ return [];
33
+ }
34
+ return (bundle.projectionImpacts || [])
35
+ .filter((/** @type {any} */ impact) => (impact.missing_capabilities || []).includes(step.item))
36
+ .map((/** @type {any} */ impact) => ({
37
+ projection_id: impact.projection_id,
38
+ kind: impact.kind,
39
+ projection_type: impact.projection_type,
40
+ reason: impact.reason
41
+ }));
42
+ }
43
+
44
+ /** @param {any[]} projectionImpacts @returns {any} */
45
+ export function blockingDependenciesForProjectionImpacts(projectionImpacts) {
46
+ return projectionImpacts.map((/** @type {any} */ impact) => ({
47
+ type: "projection_review",
48
+ id: `projection_review:${impact.projection_id}`,
49
+ projection_id: impact.projection_id,
50
+ kind: impact.kind,
51
+ projection_type: impact.projection_type,
52
+ reason: impact.reason
53
+ }));
54
+ }
55
+
56
+ /** @param {any[]} uiImpacts @returns {any} */
57
+ export function blockingDependenciesForUiImpacts(uiImpacts) {
58
+ return uiImpacts.map((/** @type {any} */ impact) => ({
59
+ type: "ui_review",
60
+ id: `ui_review:${impact.projection_id}`,
61
+ projection_id: impact.projection_id,
62
+ kind: impact.kind,
63
+ projection_type: impact.projection_type,
64
+ reason: impact.reason
65
+ }));
66
+ }
67
+
68
+ /** @param {any[]} workflowImpacts @returns {any} */
69
+ export function blockingDependenciesForWorkflowImpacts(workflowImpacts) {
70
+ return workflowImpacts.map((/** @type {any} */ impact) => ({
71
+ type: "workflow_review",
72
+ id: impact.review_group_id,
73
+ reason: impact.reason
74
+ }));
75
+ }
@@ -0,0 +1,143 @@
1
+ // @ts-check
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+
6
+ import { adoptionItemKey } from "../../../adoption/plan.js";
7
+ import {
8
+ applyDocLinkPatchToMarkdown as applyDocLinkPatchToMarkdownReconcile,
9
+ applyDocMetadataPatchToMarkdown as applyDocMetadataPatchToMarkdownReconcile
10
+ } from "../../../reconcile/docs.js";
11
+ import { readJsonIfExists, readTextIfExists } from "../../shared.js";
12
+ import { canonicalRelativePathForItem } from "./paths.js";
13
+ import { applyProjectionAuthPatchToTopogram } from "./projection-patches.js";
14
+
15
+ /** @param {WorkspacePaths} paths @returns {any} */
16
+ export function readAdoptionPlan(paths) {
17
+ return readJsonIfExists(path.join(paths.topogramRoot, "candidates", "reconcile", "adoption-plan.json"));
18
+ }
19
+
20
+ /** @param {WorkspacePaths} paths @param {any[]} candidateFiles @param {any[]} planItems @param {any[]} selectedItems @param {WorkflowOptions} options @returns {any} */
21
+ export function buildCanonicalAdoptionOutputs(paths, candidateFiles, planItems, selectedItems, options = {}) {
22
+ const refreshAdopted = Boolean(options.refreshAdopted);
23
+ /** @type {WorkflowFiles} */
24
+ /** @type {WorkflowFiles} */
25
+ const files = {};
26
+ /** @type {any[]} */
27
+ const refreshedFiles = [];
28
+ const selectedSet = new Set(selectedItems);
29
+ const itemMap = new Map(planItems.map((/** @type {any} */ item) => [adoptionItemKey(item), item]));
30
+ const capabilityBundleSet = new Set(
31
+ [...selectedSet]
32
+ .map((/** @type {any} */ key) => itemMap.get(key))
33
+ .filter((/** @type {any} */ item) => item?.kind === "capability")
34
+ .map((/** @type {any} */ item) => item.bundle)
35
+ );
36
+ for (const item of planItems) {
37
+ if (item.kind === "shape" && item.status !== "skipped" && capabilityBundleSet.has(item.bundle)) {
38
+ selectedSet.add(adoptionItemKey(item));
39
+ }
40
+ }
41
+ for (const item of planItems) {
42
+ if (!selectedSet.has(adoptionItemKey(item))) {
43
+ continue;
44
+ }
45
+ if (item.suggested_action === "skip_duplicate_shape") {
46
+ continue;
47
+ }
48
+ const relativeCanonicalPath = item.canonical_rel_path || canonicalRelativePathForItem(item.kind, item.item);
49
+ if (!relativeCanonicalPath) {
50
+ continue;
51
+ }
52
+ const canonicalPath = path.join(paths.topogramRoot, relativeCanonicalPath);
53
+ if (item.suggested_action === "apply_doc_link_patch") {
54
+ const baseContents = files[relativeCanonicalPath] || (fs.existsSync(canonicalPath) ? fs.readFileSync(canonicalPath, "utf8") : null);
55
+ if (!baseContents) {
56
+ continue;
57
+ }
58
+ const updatedContents = applyDocLinkPatchToMarkdownReconcile(baseContents, item);
59
+ if (!updatedContents || updatedContents === baseContents) {
60
+ continue;
61
+ }
62
+ files[relativeCanonicalPath] = updatedContents;
63
+ refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
64
+ continue;
65
+ }
66
+ if (item.suggested_action === "apply_doc_metadata_patch") {
67
+ const baseContents = files[relativeCanonicalPath] || (fs.existsSync(canonicalPath) ? fs.readFileSync(canonicalPath, "utf8") : null);
68
+ if (!baseContents) {
69
+ continue;
70
+ }
71
+ const updatedContents = applyDocMetadataPatchToMarkdownReconcile(baseContents, item);
72
+ if (!updatedContents || updatedContents === baseContents) {
73
+ continue;
74
+ }
75
+ files[relativeCanonicalPath] = updatedContents;
76
+ refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
77
+ continue;
78
+ }
79
+ if (item.suggested_action === "apply_projection_permission_patch" || item.suggested_action === "apply_projection_auth_patch" || item.suggested_action === "apply_projection_ownership_patch") {
80
+ const baseContents = files[relativeCanonicalPath] || (fs.existsSync(canonicalPath) ? fs.readFileSync(canonicalPath, "utf8") : null);
81
+ if (!baseContents) {
82
+ continue;
83
+ }
84
+ const updatedContents = applyProjectionAuthPatchToTopogram(baseContents, item);
85
+ if (!updatedContents || updatedContents === baseContents) {
86
+ continue;
87
+ }
88
+ files[relativeCanonicalPath] = updatedContents;
89
+ refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
90
+ continue;
91
+ }
92
+ if (fs.existsSync(canonicalPath)) {
93
+ if (!refreshAdopted) {
94
+ continue;
95
+ }
96
+ const existingContents = fs.readFileSync(canonicalPath, "utf8");
97
+ const machineManagedImported =
98
+ existingContents.startsWith("# imported ") ||
99
+ /\bsource_of_truth:\s*imported\b/.test(existingContents);
100
+ if (!machineManagedImported) {
101
+ continue;
102
+ }
103
+ }
104
+ const candidateContents =
105
+ candidateFiles[item.source_path] ||
106
+ (item.source_path ? readTextIfExists(path.join(paths.topogramRoot, item.source_path)) : null);
107
+ if (!candidateContents) {
108
+ continue;
109
+ }
110
+ files[relativeCanonicalPath] = candidateContents;
111
+ if (fs.existsSync(canonicalPath)) {
112
+ refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
113
+ }
114
+ }
115
+ return { files, refreshedFiles: [...new Set(refreshedFiles)].sort() };
116
+ }
117
+
118
+ /** @param {any[]} planItems @param {any[]} selectedItems @param {any[]} writtenCanonicalFiles @param {string} selector @returns {any} */
119
+ export function buildPromotedCanonicalItems(planItems, selectedItems, writtenCanonicalFiles, selector) {
120
+ const itemMap = new Map((planItems || []).map((/** @type {any} */ item) => [adoptionItemKey(item), item]));
121
+ const writtenSet = new Set((writtenCanonicalFiles || []).map((/** @type {any} */ item) => String(item).replaceAll(path.sep, "/")));
122
+ return [...new Set(selectedItems || [])]
123
+ .map((/** @type {any} */ key) => itemMap.get(key))
124
+ .filter(Boolean)
125
+ .filter((/** @type {any} */ item) => item.canonical_rel_path && writtenSet.has(String(item.canonical_rel_path).replaceAll(path.sep, "/")))
126
+ .map((/** @type {any} */ item) => ({
127
+ selector: selector || null,
128
+ bundle: item.bundle,
129
+ item: item.item,
130
+ kind: item.kind,
131
+ track: item.track || null,
132
+ source_path: item.source_path || null,
133
+ canonical_rel_path: String(item.canonical_rel_path).replaceAll(path.sep, "/"),
134
+ canonical_path: item.canonical_path || `topogram/${String(item.canonical_rel_path).replaceAll(path.sep, "/")}`,
135
+ suggested_action: item.suggested_action || null
136
+ }))
137
+ .sort((/** @type {any} */ a, /** @type {any} */ b) =>
138
+ (a.bundle || "").localeCompare(b.bundle || "") ||
139
+ (a.track || "").localeCompare(b.track || "") ||
140
+ (a.kind || "").localeCompare(b.kind || "") ||
141
+ (a.item || "").localeCompare(b.item || "")
142
+ );
143
+ }
@@ -0,0 +1,58 @@
1
+ // @ts-check
2
+
3
+ import { dashedTopogramId } from "../ids.js";
4
+
5
+ /** @param {string} kind @param {string} item @returns {any} */
6
+ export function canonicalRelativePathForItem(kind, item) {
7
+ switch (kind) {
8
+ case "actor":
9
+ return `actors/${dashedTopogramId(item)}.tg`;
10
+ case "role":
11
+ return `roles/${dashedTopogramId(item)}.tg`;
12
+ case "enum":
13
+ return `enums/enum-${dashedTopogramId(String(item || "").replace(/^enum_/, ""))}.tg`;
14
+ case "entity":
15
+ return `entities/${dashedTopogramId(item)}.tg`;
16
+ case "shape":
17
+ return `shapes/${dashedTopogramId(item)}.tg`;
18
+ case "capability":
19
+ return `capabilities/${dashedTopogramId(item)}.tg`;
20
+ case "widget":
21
+ return `widgets/${dashedTopogramId(item)}.tg`;
22
+ case "verification":
23
+ return `verifications/${dashedTopogramId(item)}.tg`;
24
+ default:
25
+ return null;
26
+ }
27
+ }
28
+
29
+ /** @param {string} kind @param {string} item @returns {any} */
30
+ export function canonicalDisplayPathForItem(kind, item) {
31
+ const relativePath = canonicalRelativePathForItem(kind, item);
32
+ return relativePath ? `topogram/${relativePath}` : null;
33
+ }
34
+
35
+ /** @param {CandidateBundle} bundle @param {string} kind @param {WorkflowRecord} item @returns {any} */
36
+ export function candidateSourcePathForItem(bundle, kind, item) {
37
+ const base = `candidates/reconcile/model/bundles/${bundle.slug}`;
38
+ switch (kind) {
39
+ case "actor":
40
+ return `${base}/actors/${item}.tg`;
41
+ case "role":
42
+ return `${base}/roles/${item}.tg`;
43
+ case "enum":
44
+ return `${base}/enums/${item}.tg`;
45
+ case "entity":
46
+ return `${base}/entities/${item}.tg`;
47
+ case "shape":
48
+ return `${base}/shapes/${item}.tg`;
49
+ case "capability":
50
+ return `${base}/capabilities/${item}.tg`;
51
+ case "widget":
52
+ return `${base}/widgets/${item}.tg`;
53
+ case "verification":
54
+ return `${base}/verifications/${item}.tg`;
55
+ default:
56
+ return `${base}/README.md`;
57
+ }
58
+ }