@topogram/cli 0.3.64 → 0.3.66

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 (278) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan/index.js +716 -0
  3. package/src/adoption/plan.js +12 -703
  4. package/src/adoption/reporting.js +1 -1
  5. package/src/agent-brief.js +7 -21
  6. package/src/agent-ops/query-builders/auth.js +375 -0
  7. package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
  8. package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
  9. package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
  10. package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
  11. package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
  12. package/src/agent-ops/query-builders/change-risk.js +25 -0
  13. package/src/agent-ops/query-builders/common.js +149 -0
  14. package/src/agent-ops/query-builders/maintained-risk.js +539 -0
  15. package/src/agent-ops/query-builders/maintained-shared.js +120 -0
  16. package/src/agent-ops/query-builders/multi-agent.js +547 -0
  17. package/src/agent-ops/query-builders/projection-impacts.js +514 -0
  18. package/src/agent-ops/query-builders/work-packets.js +417 -0
  19. package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
  20. package/src/agent-ops/query-builders/workflow-context.js +398 -0
  21. package/src/agent-ops/query-builders/workflow-presets-core.js +677 -0
  22. package/src/agent-ops/query-builders/workflow-presets.js +341 -0
  23. package/src/agent-ops/query-builders.d.ts +26 -26
  24. package/src/agent-ops/query-builders.js +42 -5021
  25. package/src/archive/jsonl.js +2 -2
  26. package/src/archive/resolver-bridge.js +1 -1
  27. package/src/archive/unarchive.js +2 -1
  28. package/src/catalog/constants.js +10 -0
  29. package/src/catalog/copy.js +65 -0
  30. package/src/catalog/diagnostics.js +15 -0
  31. package/src/catalog/entries.js +42 -0
  32. package/src/catalog/files.js +67 -0
  33. package/src/catalog/provenance.js +123 -0
  34. package/src/catalog/source.js +150 -0
  35. package/src/catalog/validation.js +252 -0
  36. package/src/catalog.d.ts +2 -0
  37. package/src/catalog.js +18 -746
  38. package/src/cli/command-parsers/project.js +3 -0
  39. package/src/cli/command-parsers/shared.js +1 -1
  40. package/src/cli/commands/agent.js +2 -2
  41. package/src/cli/commands/catalog/check.js +31 -0
  42. package/src/cli/commands/catalog/copy.js +59 -0
  43. package/src/cli/commands/catalog/doctor.js +248 -0
  44. package/src/cli/commands/catalog/help.js +21 -0
  45. package/src/cli/commands/catalog/list.js +52 -0
  46. package/src/cli/commands/catalog/runner.js +92 -0
  47. package/src/cli/commands/catalog/shared.js +17 -0
  48. package/src/cli/commands/catalog/show.js +134 -0
  49. package/src/cli/commands/catalog.js +30 -615
  50. package/src/cli/commands/check.js +3 -3
  51. package/src/cli/commands/doctor.js +2 -9
  52. package/src/cli/commands/generator-policy/package-info.js +162 -0
  53. package/src/cli/commands/generator-policy/payloads.js +372 -0
  54. package/src/cli/commands/generator-policy/printers.js +159 -0
  55. package/src/cli/commands/generator-policy/runner.js +81 -0
  56. package/src/cli/commands/generator-policy/shared.js +39 -0
  57. package/src/cli/commands/generator-policy.js +15 -783
  58. package/src/cli/commands/import/adopt.js +170 -0
  59. package/src/cli/commands/import/check.js +91 -0
  60. package/src/cli/commands/import/diff.js +84 -0
  61. package/src/cli/commands/import/help.js +47 -0
  62. package/src/cli/commands/import/paths.js +269 -0
  63. package/src/cli/commands/import/plan.js +292 -0
  64. package/src/cli/commands/import/refresh.js +471 -0
  65. package/src/cli/commands/import/status-history.js +196 -0
  66. package/src/cli/commands/import/workspace.js +233 -0
  67. package/src/cli/commands/import.js +33 -1732
  68. package/src/cli/commands/migrate.js +153 -0
  69. package/src/cli/commands/package/constants.js +17 -0
  70. package/src/cli/commands/package/doctor.js +240 -0
  71. package/src/cli/commands/package/help.js +27 -0
  72. package/src/cli/commands/package/lockfile.js +135 -0
  73. package/src/cli/commands/package/npm.js +97 -0
  74. package/src/cli/commands/package/reporting.js +35 -0
  75. package/src/cli/commands/package/runner.js +33 -0
  76. package/src/cli/commands/package/shared.js +9 -0
  77. package/src/cli/commands/package/update-cli.js +252 -0
  78. package/src/cli/commands/package/versions.js +35 -0
  79. package/src/cli/commands/package.js +29 -813
  80. package/src/cli/commands/query/change-plan.js +68 -0
  81. package/src/cli/commands/query/definitions.js +202 -0
  82. package/src/cli/commands/query/import-adopt.js +121 -0
  83. package/src/cli/commands/query/runner/artifacts.js +102 -0
  84. package/src/cli/commands/query/runner/boundaries.js +211 -0
  85. package/src/cli/commands/query/runner/change.js +182 -0
  86. package/src/cli/commands/query/runner/import-adopt.js +111 -0
  87. package/src/cli/commands/query/runner/index.js +31 -0
  88. package/src/cli/commands/query/runner/output.js +12 -0
  89. package/src/cli/commands/query/runner/workflow.js +241 -0
  90. package/src/cli/commands/query/runner.js +3 -0
  91. package/src/cli/commands/query/workflow-context.js +5 -0
  92. package/src/cli/commands/query/workspace.js +270 -0
  93. package/src/cli/commands/query.js +9 -1300
  94. package/src/cli/commands/source.js +3 -12
  95. package/src/cli/commands/template/baseline.js +100 -0
  96. package/src/cli/commands/template/check.js +467 -0
  97. package/src/cli/commands/template/constants.js +8 -0
  98. package/src/cli/commands/template/diagnostics.js +26 -0
  99. package/src/cli/commands/template/help.js +28 -0
  100. package/src/cli/commands/template/lifecycle.js +404 -0
  101. package/src/cli/commands/template/list-show.js +287 -0
  102. package/src/cli/commands/template/policy.js +422 -0
  103. package/src/cli/commands/template/shared.js +127 -0
  104. package/src/cli/commands/template/updates.js +352 -0
  105. package/src/cli/commands/template-runner.js +6 -6
  106. package/src/cli/commands/template.js +41 -2143
  107. package/src/cli/commands/trust.js +1 -1
  108. package/src/cli/commands/workflow.js +6 -1
  109. package/src/cli/dispatcher.js +6 -1
  110. package/src/cli/help.js +15 -14
  111. package/src/cli/migration-guidance.js +1 -1
  112. package/src/cli/output-safety.js +2 -1
  113. package/src/cli/path-normalization.js +3 -13
  114. package/src/generator/api/contracts.js +497 -0
  115. package/src/generator/api/metadata.js +221 -0
  116. package/src/generator/api/openapi.js +559 -0
  117. package/src/generator/api/schema.js +124 -0
  118. package/src/generator/api/types.d.ts +98 -0
  119. package/src/generator/api.js +3 -1195
  120. package/src/generator/context/domain-page.js +1 -1
  121. package/src/generator/context/shared/domain-sdlc.js +282 -0
  122. package/src/generator/context/shared/maintained-boundary.js +665 -0
  123. package/src/generator/context/shared/metrics.js +85 -0
  124. package/src/generator/context/shared/primitives.js +64 -0
  125. package/src/generator/context/shared/relationships.js +453 -0
  126. package/src/generator/context/shared/summaries.js +263 -0
  127. package/src/generator/context/shared/types.d.ts +207 -0
  128. package/src/generator/context/shared.d.ts +42 -0
  129. package/src/generator/context/shared.js +80 -1390
  130. package/src/generator/context/slice/core.js +397 -0
  131. package/src/generator/context/slice/sdlc.js +417 -0
  132. package/src/generator/context/slice/ui-packets.js +183 -0
  133. package/src/generator/context/slice.js +2 -859
  134. package/src/generator/context/task-mode.js +2 -2
  135. package/src/generator/registry/index.js +507 -0
  136. package/src/generator/registry.js +18 -504
  137. package/src/generator/runtime/environment/index.js +666 -0
  138. package/src/generator/runtime/environment.js +4 -666
  139. package/src/generator/runtime/runtime-check/index.js +554 -0
  140. package/src/generator/runtime/runtime-check.js +4 -554
  141. package/src/generator/runtime/shared/index.js +572 -0
  142. package/src/generator/runtime/shared.js +19 -570
  143. package/src/generator/sdlc/doc-page.js +1 -1
  144. package/src/generator/shared.d.ts +2 -0
  145. package/src/generator/surfaces/databases/lifecycle-shared.js +1 -1
  146. package/src/generator/surfaces/native/swiftui-templates/README.generated.md +1 -1
  147. package/src/generator/surfaces/shared.d.ts +3 -0
  148. package/src/generator/widget-conformance/behavior-report.js +258 -0
  149. package/src/generator/widget-conformance/checks.js +371 -0
  150. package/src/generator/widget-conformance/projection-context.js +200 -0
  151. package/src/generator/widget-conformance/report.js +166 -0
  152. package/src/generator/widget-conformance/types.d.ts +121 -0
  153. package/src/generator/widget-conformance.js +3 -824
  154. package/src/import/core/context.d.ts +3 -0
  155. package/src/import/core/context.js +5 -7
  156. package/src/import/core/contracts.d.ts +1 -0
  157. package/src/import/core/registry.d.ts +4 -0
  158. package/src/import/core/runner/candidates.js +337 -0
  159. package/src/import/core/runner/options.js +22 -0
  160. package/src/import/core/runner/reports.js +51 -0
  161. package/src/import/core/runner/run.js +79 -0
  162. package/src/import/core/runner/tracks.js +150 -0
  163. package/src/import/core/runner/ui-drafts.js +393 -0
  164. package/src/import/core/runner.js +3 -698
  165. package/src/import/core/shared/api-routes.js +221 -0
  166. package/src/import/core/shared/candidates.js +97 -0
  167. package/src/import/core/shared/files.js +177 -0
  168. package/src/import/core/shared/next-app.js +389 -0
  169. package/src/import/core/shared/types.d.ts +51 -0
  170. package/src/import/core/shared/ui-routes.js +230 -0
  171. package/src/import/core/shared.js +60 -861
  172. package/src/new-project/constants.js +128 -0
  173. package/src/new-project/create.js +90 -0
  174. package/src/new-project/json.js +28 -0
  175. package/src/new-project/metadata.js +96 -0
  176. package/src/new-project/package-spec.js +161 -0
  177. package/src/new-project/project-files.js +351 -0
  178. package/src/new-project/template-policy.js +269 -0
  179. package/src/new-project/template-resolution.js +370 -0
  180. package/src/new-project/template-snapshots.js +442 -0
  181. package/src/new-project/template-updates.js +512 -0
  182. package/src/new-project/types.d.ts +83 -0
  183. package/src/new-project.js +6 -2277
  184. package/src/parser.d.ts +87 -1
  185. package/src/parser.js +118 -0
  186. package/src/policy/review-boundaries.d.ts +15 -0
  187. package/src/project-config/index.js +591 -0
  188. package/src/project-config.js +19 -561
  189. package/src/resolver/enrich/acceptance-criterion.js +2 -0
  190. package/src/resolver/enrich/bug.js +2 -0
  191. package/src/resolver/enrich/pitch.js +2 -0
  192. package/src/resolver/enrich/requirement.js +2 -0
  193. package/src/resolver/enrich/task.js +2 -0
  194. package/src/resolver/index.js +19 -2089
  195. package/src/resolver/normalize.js +384 -1
  196. package/src/resolver/plans.js +168 -0
  197. package/src/resolver/projections-api.js +494 -0
  198. package/src/resolver/projections-db.js +133 -0
  199. package/src/resolver/projections-ui.js +317 -0
  200. package/src/resolver/shapes.js +251 -0
  201. package/src/resolver/shared.js +278 -0
  202. package/src/resolver/widgets.js +132 -0
  203. package/src/sdlc/adopt.js +6 -5
  204. package/src/sdlc/paths.js +3 -5
  205. package/src/sdlc/scaffold.js +2 -1
  206. package/src/template-trust/constants.js +62 -0
  207. package/src/template-trust/content.js +258 -0
  208. package/src/template-trust/diff.js +92 -0
  209. package/src/template-trust/policy.js +61 -0
  210. package/src/template-trust/record.js +90 -0
  211. package/src/template-trust/status.js +182 -0
  212. package/src/template-trust.js +24 -687
  213. package/src/text-helpers.d.ts +1 -0
  214. package/src/topogram-types.d.ts +69 -0
  215. package/src/validator/common.js +488 -0
  216. package/src/validator/data-model.js +237 -0
  217. package/src/validator/docs.js +167 -0
  218. package/src/validator/expressions.js +146 -1
  219. package/src/validator/index.d.ts +23 -0
  220. package/src/validator/index.js +32 -3585
  221. package/src/validator/kinds.d.ts +41 -0
  222. package/src/validator/kinds.js +2 -0
  223. package/src/validator/model-helpers.js +46 -0
  224. package/src/validator/per-kind/acceptance-criterion.js +5 -0
  225. package/src/validator/per-kind/bug.js +6 -0
  226. package/src/validator/per-kind/domain.js +15 -2
  227. package/src/validator/per-kind/pitch.js +7 -0
  228. package/src/validator/per-kind/requirement.js +5 -0
  229. package/src/validator/per-kind/task.js +7 -0
  230. package/src/validator/per-kind/widget.js +14 -0
  231. package/src/validator/projections/api-http-async.js +410 -0
  232. package/src/validator/projections/api-http-authz.js +88 -0
  233. package/src/validator/projections/api-http-core.js +205 -0
  234. package/src/validator/projections/api-http-policies.js +339 -0
  235. package/src/validator/projections/api-http-responses.js +233 -0
  236. package/src/validator/projections/api-http.js +44 -0
  237. package/src/validator/projections/db.js +353 -0
  238. package/src/validator/projections/generator-defaults.js +45 -0
  239. package/src/validator/projections/helpers.js +87 -0
  240. package/src/validator/projections/ui-helpers.js +214 -0
  241. package/src/validator/projections/ui-navigation.js +344 -0
  242. package/src/validator/projections/ui-structure.js +364 -0
  243. package/src/validator/projections/ui-widgets.js +493 -0
  244. package/src/validator/projections/ui.js +46 -0
  245. package/src/validator/registry.js +48 -1
  246. package/src/validator/utils.d.ts +20 -0
  247. package/src/validator/utils.js +115 -12
  248. package/src/widget-behavior.d.ts +1 -0
  249. package/src/workflows/import-app/api/collect.js +221 -0
  250. package/src/workflows/import-app/api/openapi.js +257 -0
  251. package/src/workflows/import-app/api/routes.js +327 -0
  252. package/src/workflows/import-app/api/sources.js +22 -0
  253. package/src/workflows/import-app/api.js +2 -797
  254. package/src/workflows/reconcile/adoption-plan/build.js +212 -0
  255. package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
  256. package/src/workflows/reconcile/adoption-plan/outputs.js +153 -0
  257. package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
  258. package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
  259. package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
  260. package/src/workflows/reconcile/adoption-plan.js +30 -740
  261. package/src/workflows/reconcile/auth/closures.js +115 -0
  262. package/src/workflows/reconcile/auth/formatters.js +142 -0
  263. package/src/workflows/reconcile/auth/inference.js +330 -0
  264. package/src/workflows/reconcile/auth/roles.js +122 -0
  265. package/src/workflows/reconcile/auth.js +35 -690
  266. package/src/workflows/reconcile/bundle-core/index.js +600 -0
  267. package/src/workflows/reconcile/bundle-core.js +12 -598
  268. package/src/workflows/reconcile/candidate-model.js +18 -2
  269. package/src/workflows/reconcile/canonical-surface.js +1 -1
  270. package/src/workflows/reconcile/impacts/adoption-plan.js +196 -0
  271. package/src/workflows/reconcile/impacts/indexes.js +105 -0
  272. package/src/workflows/reconcile/impacts/patches.js +252 -0
  273. package/src/workflows/reconcile/impacts/reports.js +80 -0
  274. package/src/workflows/reconcile/impacts.js +14 -623
  275. package/src/workflows/reconcile/renderers.js +41 -6
  276. package/src/workflows/shared.js +5 -11
  277. package/src/workspace-docs.d.ts +29 -0
  278. package/src/workspace-paths.js +328 -0
@@ -3,7 +3,7 @@ import { generateApiContractGraph } from "../../generator/api.js";
3
3
  import { confidenceRank } from "../docs.js";
4
4
  import { normalizeEndpointPathForMatch, normalizeOpenApiPath } from "../import-app/index.js";
5
5
 
6
- /** @param {any} importedEntity @param {any} graphEntity @returns {any} */
6
+ /** @param {import("../types.d.ts").CandidateRecord} importedEntity @param {WorkflowRecord} graphEntity @returns {any} */
7
7
  export function compareEntityFields(importedEntity, graphEntity) {
8
8
  const graphFields = new Map((graphEntity.fields || []).map((/** @type {any} */ field) => [field.name, field]));
9
9
  /** @type {any[]} */
@@ -0,0 +1,196 @@
1
+ // @ts-check
2
+ import { docDirForKind } from "../../docs.js";
3
+ import { dashedTopogramId } from "../ids.js";
4
+ import { shapeFieldSignature } from "./indexes.js";
5
+
6
+ /** @param {CandidateBundle} bundle @param {any} canonicalShapeIndex @returns {any} */
7
+ export function buildBundleAdoptionPlan(bundle, canonicalShapeIndex) {
8
+ /** @type {any[]} */
9
+ const steps = [];
10
+ for (const entry of bundle.actors) {
11
+ steps.push({
12
+ action: "promote_actor",
13
+ item: entry.id_hint,
14
+ target: null,
15
+ confidence: entry.confidence || "low",
16
+ inference_summary: entry.inference_summary || null,
17
+ related_docs: entry.related_docs || [],
18
+ related_capabilities: entry.related_capabilities || [],
19
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/actors/${entry.id_hint}.tg`,
20
+ canonical_rel_path: `actors/${dashedTopogramId(entry.id_hint)}.tg`
21
+ });
22
+ }
23
+ for (const entry of bundle.roles) {
24
+ steps.push({
25
+ action: "promote_role",
26
+ item: entry.id_hint,
27
+ target: null,
28
+ confidence: entry.confidence || "low",
29
+ inference_summary: entry.inference_summary || null,
30
+ related_docs: entry.related_docs || [],
31
+ related_capabilities: entry.related_capabilities || [],
32
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/roles/${entry.id_hint}.tg`,
33
+ canonical_rel_path: `roles/${dashedTopogramId(entry.id_hint)}.tg`
34
+ });
35
+ }
36
+ if (bundle.mergeHints?.canonicalEntityTarget) {
37
+ steps.push({
38
+ action: "merge_bundle_into_existing_entity",
39
+ item: bundle.slug,
40
+ target: bundle.mergeHints.canonicalEntityTarget
41
+ });
42
+ } else if (bundle.entities.length > 0) {
43
+ for (const entry of bundle.entities) {
44
+ steps.push({
45
+ action: "promote_entity",
46
+ item: entry.id_hint,
47
+ target: null
48
+ });
49
+ }
50
+ }
51
+ for (const entry of bundle.enums) {
52
+ steps.push({
53
+ action: "promote_enum",
54
+ item: entry.id_hint,
55
+ target: bundle.mergeHints?.canonicalEntityTarget || null
56
+ });
57
+ }
58
+ for (const entry of bundle.capabilities) {
59
+ steps.push({
60
+ action: bundle.mergeHints?.canonicalEntityTarget ? "merge_capability_into_existing_entity" : "promote_capability",
61
+ item: entry.id_hint,
62
+ target: bundle.mergeHints?.canonicalEntityTarget || null
63
+ });
64
+ }
65
+ for (const entry of bundle.shapes) {
66
+ const signature = shapeFieldSignature(entry.fields || []);
67
+ const duplicateTargets = canonicalShapeIndex.get(signature) || [];
68
+ if (duplicateTargets.length > 0 && entry.source_kind !== "ui_widget_event") {
69
+ steps.push({
70
+ action: "skip_duplicate_shape",
71
+ item: entry.id,
72
+ target: duplicateTargets[0]
73
+ });
74
+ continue;
75
+ }
76
+ steps.push({
77
+ action: "promote_shape",
78
+ item: entry.id,
79
+ target: bundle.mergeHints?.canonicalEntityTarget || null,
80
+ source_kind: entry.source_kind || null,
81
+ widget_id: entry.widget_id || null,
82
+ event_name: entry.event_name || null
83
+ });
84
+ }
85
+ for (const entry of bundle.docs) {
86
+ if (entry.existing_canonical) {
87
+ continue;
88
+ }
89
+ steps.push({
90
+ action: entry.kind === "workflow" ? "promote_workflow_doc" : "promote_doc",
91
+ item: entry.id,
92
+ target: null,
93
+ doc_kind: entry.kind,
94
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/${docDirForKind(entry.kind)}/${entry.id}.md`,
95
+ canonical_rel_path: `docs/${docDirForKind(entry.kind)}/${entry.id}.md`
96
+ });
97
+ }
98
+ for (const entry of bundle.workflows) {
99
+ steps.push({
100
+ action: "promote_workflow_decision",
101
+ item: `dec_${entry.id_hint.replace(/^workflow_/, "")}`,
102
+ target: null,
103
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/decisions/dec_${entry.id_hint.replace(/^workflow_/, "")}.tg`,
104
+ canonical_rel_path: `decisions/decision-${dashedTopogramId(entry.id_hint.replace(/^workflow_/, ""))}.tg`
105
+ });
106
+ steps.push({
107
+ action: "promote_workflow_doc",
108
+ item: entry.id_hint,
109
+ target: null,
110
+ doc_kind: "workflow",
111
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/workflows/${entry.id_hint}.md`,
112
+ canonical_rel_path: `docs/workflows/${entry.id_hint}.md`
113
+ });
114
+ }
115
+ for (const entry of bundle.verifications || []) {
116
+ steps.push({
117
+ action: "promote_verification",
118
+ item: entry.id_hint,
119
+ target: null,
120
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/verifications/${entry.id_hint}.tg`,
121
+ canonical_rel_path: `verifications/${dashedTopogramId(entry.id_hint)}.tg`
122
+ });
123
+ }
124
+ for (const entry of bundle.widgets || []) {
125
+ steps.push({
126
+ action: "promote_widget",
127
+ item: entry.id_hint,
128
+ target: null,
129
+ confidence: entry.confidence || "low",
130
+ inference_summary: entry.inference_summary || null,
131
+ related_capabilities: [entry.data_source].filter(Boolean),
132
+ related_shapes: [...new Set((entry.inferred_events || []).map((/** @type {any} */ event) => event.payload_shape).filter(Boolean))],
133
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/widgets/${entry.id_hint}.tg`,
134
+ canonical_rel_path: `widgets/${dashedTopogramId(entry.id_hint)}.tg`
135
+ });
136
+ }
137
+ for (const screen of bundle.screens) {
138
+ steps.push({
139
+ action: "promote_ui_report",
140
+ item: `ui_${screen.id_hint}`,
141
+ target: null,
142
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/reports/ui-${screen.id_hint}.md`,
143
+ canonical_rel_path: `docs/reports/ui-${screen.id_hint}.md`
144
+ });
145
+ }
146
+ for (const patch of bundle.projectionPatches || []) {
147
+ for (const hint of patch.missing_auth_permissions || []) {
148
+ steps.push({
149
+ action: "apply_projection_permission_patch",
150
+ item: `projection_permission_patch:${patch.projection_id}:${hint.projection_surface}:${hint.permission}`,
151
+ target: patch.projection_id,
152
+ projection_kind: patch.kind,
153
+ projection_surface: hint.projection_surface,
154
+ permission: hint.permission,
155
+ confidence: hint.confidence || "low",
156
+ inference_summary: hint.why_inferred || hint.explanation || null,
157
+ related_capabilities: hint.related_capabilities || [],
158
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
159
+ canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
160
+ });
161
+ }
162
+ for (const hint of patch.missing_auth_claims || []) {
163
+ steps.push({
164
+ action: "apply_projection_auth_patch",
165
+ item: `projection_auth_patch:${patch.projection_id}:${hint.projection_surface}:${hint.claim}`,
166
+ target: patch.projection_id,
167
+ projection_kind: patch.kind,
168
+ projection_surface: hint.projection_surface,
169
+ claim: hint.claim,
170
+ claim_value: hint.claim_value,
171
+ confidence: hint.confidence || "low",
172
+ inference_summary: hint.why_inferred || hint.explanation || null,
173
+ related_capabilities: hint.related_capabilities || [],
174
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
175
+ canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
176
+ });
177
+ }
178
+ for (const hint of patch.missing_auth_ownerships || []) {
179
+ steps.push({
180
+ action: "apply_projection_ownership_patch",
181
+ item: `projection_ownership_patch:${patch.projection_id}:${hint.ownership_field}`,
182
+ target: patch.projection_id,
183
+ projection_kind: patch.kind,
184
+ projection_surface: "authorization",
185
+ ownership: hint.ownership,
186
+ ownership_field: hint.ownership_field,
187
+ confidence: hint.confidence || "low",
188
+ inference_summary: hint.why_inferred || hint.explanation || null,
189
+ related_capabilities: hint.related_capabilities || [],
190
+ source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
191
+ canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
192
+ });
193
+ }
194
+ }
195
+ return steps;
196
+ }
@@ -0,0 +1,105 @@
1
+ // @ts-check
2
+
3
+ /** @param {any[]} fields @returns {any} */
4
+ export function shapeFieldSignature(fields) {
5
+ return [...new Set((fields || [])
6
+ .map((field) => typeof field === "string" ? field : field?.name)
7
+ .filter(Boolean))]
8
+ .sort()
9
+ .join("|");
10
+ }
11
+
12
+ /** @param {ResolvedGraph} graph @returns {any} */
13
+ export function buildCanonicalShapeIndex(graph) {
14
+ const bySignature = new Map();
15
+ for (const shape of graph?.byKind.shape || []) {
16
+ const fields = (shape.projectedFields || shape.fields || []).map((/** @type {any} */ field) => field.name).filter(Boolean);
17
+ const signature = shapeFieldSignature(fields);
18
+ if (!signature) {
19
+ continue;
20
+ }
21
+ if (!bySignature.has(signature)) {
22
+ bySignature.set(signature, []);
23
+ }
24
+ bySignature.get(signature).push(shape.id);
25
+ }
26
+ return bySignature;
27
+ }
28
+
29
+ /** @param {WorkflowRecord} capability @returns {any} */
30
+ export function capabilityEntityTargets(capability) {
31
+ return [
32
+ ...(capability.creates || []),
33
+ ...(capability.updates || []),
34
+ ...(capability.deletes || []),
35
+ ...(capability.reads || [])
36
+ ]
37
+ .map((/** @type {any} */ ref) => ref?.id || ref?.target?.id || null)
38
+ .filter((/** @type {any} */ id) => typeof id === "string" && id.startsWith("entity_"));
39
+ }
40
+
41
+ /** @param {WorkflowRecord} projection @returns {any} */
42
+ export function projectionKindForImpact(projection) {
43
+ if ((projection.http || []).length > 0 || projection.type === "api_contract") {
44
+ return "api";
45
+ }
46
+ if (
47
+ (projection.uiRoutes || []).length > 0 ||
48
+ (projection.uiWeb || []).length > 0 ||
49
+ (projection.uiIos || []).length > 0 ||
50
+ projection.type === "web_surface" ||
51
+ projection.type === "ios_surface"
52
+ ) {
53
+ return "ui";
54
+ }
55
+ if ((projection.dbTables || []).length > 0) {
56
+ return "db";
57
+ }
58
+ return "other";
59
+ }
60
+
61
+ /** @param {ResolvedGraph} graph @returns {any} */
62
+ export function buildProjectionEntityIndex(graph) {
63
+ const projections = graph?.byKind.projection || [];
64
+ const capabilities = new Map((graph?.byKind.capability || []).map((/** @type {any} */ capability) => [capability.id, capability]));
65
+ const projectionsById = new Map(projections.map((/** @type {any} */ projection) => [projection.id, projection]));
66
+ const memo = new Map();
67
+
68
+ /** @param {string} projectionId @param {any} stack @returns {any} */
69
+ function collectEntities(projectionId, stack = new Set()) {
70
+ if (memo.has(projectionId)) {
71
+ return memo.get(projectionId);
72
+ }
73
+ if (stack.has(projectionId)) {
74
+ return new Set();
75
+ }
76
+ stack.add(projectionId);
77
+ const projection = projectionsById.get(projectionId);
78
+ const entities = new Set();
79
+ for (const realized of projection?.realizes || []) {
80
+ const realizedKind = realized?.target?.kind || realized?.kind || null;
81
+ const realizedId = realized?.target?.id || realized?.id || null;
82
+ if (realizedKind === "capability") {
83
+ const capability = capabilities.get(realizedId);
84
+ for (const entityId of capabilityEntityTargets(capability || {})) {
85
+ entities.add(entityId);
86
+ }
87
+ } else if (realizedKind === "projection") {
88
+ for (const entityId of collectEntities(realizedId, stack)) {
89
+ entities.add(entityId);
90
+ }
91
+ }
92
+ }
93
+ memo.set(projectionId, entities);
94
+ stack.delete(projectionId);
95
+ return entities;
96
+ }
97
+
98
+ return projections.map((/** @type {any} */ projection) => ({
99
+ id: projection.id,
100
+ projection_type: projection.type || null,
101
+ kind: projectionKindForImpact(projection),
102
+ realizes: (projection.realizes || []).map((/** @type {any} */ entry) => entry.id),
103
+ entityIds: [...collectEntities(projection.id)].sort()
104
+ }));
105
+ }
@@ -0,0 +1,252 @@
1
+ // @ts-check
2
+ import { stableStringify } from "../../../format.js";
3
+ import {
4
+ buildAuthClaimReviewGuidance,
5
+ buildAuthOwnershipReviewGuidance,
6
+ buildAuthPermissionReviewGuidance,
7
+ describeAuthClaimWhyInferred,
8
+ describeAuthOwnershipWhyInferred,
9
+ describeAuthPermissionWhyInferred
10
+ } from "../auth.js";
11
+
12
+ /** @param {CandidateBundle} bundle @returns {any} */
13
+ export function buildProjectionPatchCandidates(bundle) {
14
+ const capabilityById = new Map((bundle.capabilities || []).map((/** @type {any} */ entry) => [entry.id_hint, entry]));
15
+ const routesByScreen = new Map();
16
+ for (const route of bundle.uiRoutes || []) {
17
+ const screenId = route.screen_id || route.id_hint;
18
+ if (!routesByScreen.has(screenId)) {
19
+ routesByScreen.set(screenId, []);
20
+ }
21
+ routesByScreen.get(screenId).push(route);
22
+ }
23
+ const actionsByScreen = new Map();
24
+ for (const action of bundle.uiActions || []) {
25
+ const screenId = action.screen_id || action.id_hint;
26
+ if (!actionsByScreen.has(screenId)) {
27
+ actionsByScreen.set(screenId, []);
28
+ }
29
+ actionsByScreen.get(screenId).push(action);
30
+ }
31
+
32
+ /** @type {any[]} */
33
+ const patches = [];
34
+ for (const impact of bundle.projectionImpacts || []) {
35
+ const missingRealizes = [...(impact.missing_capabilities || [])];
36
+ const missingHttp = impact.kind === "api"
37
+ ? missingRealizes
38
+ .map((/** @type {any} */ capabilityId) => capabilityById.get(capabilityId))
39
+ .filter(Boolean)
40
+ .map((/** @type {any} */ entry) => ({
41
+ capability_id: entry.id_hint,
42
+ method: entry.endpoint?.method || "GET",
43
+ path: entry.endpoint?.path || "/"
44
+ }))
45
+ : [];
46
+ patches.push({
47
+ projection_id: impact.projection_id,
48
+ kind: impact.kind,
49
+ projection_type: impact.projection_type,
50
+ reason: impact.reason,
51
+ missing_realizes: missingRealizes,
52
+ missing_http: missingHttp,
53
+ missing_screens: [],
54
+ missing_routes: [],
55
+ missing_actions: []
56
+ });
57
+ }
58
+
59
+ for (const impact of bundle.uiImpacts || []) {
60
+ const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
61
+ const missingScreens = [...(impact.missing_screens || [])];
62
+ const missingRoutes = missingScreens.flatMap((/** @type {any} */ screenId) => routesByScreen.get(screenId) || []).map((/** @type {any} */ route) => ({
63
+ screen_id: route.screen_id,
64
+ path: route.path
65
+ }));
66
+ const missingActions = missingScreens.flatMap((/** @type {any} */ screenId) => actionsByScreen.get(screenId) || []).map((/** @type {any} */ action) => ({
67
+ screen_id: action.screen_id,
68
+ capability_hint: action.capability_hint
69
+ }));
70
+ if (existing) {
71
+ existing.missing_screens = [...new Set([...(existing.missing_screens || []), ...missingScreens])];
72
+ existing.missing_routes = [...(existing.missing_routes || []), ...missingRoutes];
73
+ existing.missing_actions = [...(existing.missing_actions || []), ...missingActions];
74
+ continue;
75
+ }
76
+ patches.push({
77
+ projection_id: impact.projection_id,
78
+ kind: impact.kind,
79
+ projection_type: impact.projection_type,
80
+ reason: impact.reason,
81
+ missing_realizes: [],
82
+ missing_http: [],
83
+ missing_screens: missingScreens,
84
+ missing_routes: missingRoutes,
85
+ missing_actions: missingActions
86
+ });
87
+ }
88
+
89
+ for (const hint of bundle.authClaimHints || []) {
90
+ for (const impact of bundle.projectionImpacts || []) {
91
+ const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
92
+ if (relatedCapabilities.length === 0) {
93
+ continue;
94
+ }
95
+ const projectionSurface = impact.kind === "ui" ? "visibility_rules" : "authorization";
96
+ const entry = {
97
+ claim: hint.claim,
98
+ claim_value: hint.claim_value,
99
+ confidence: hint.confidence,
100
+ review_required: true,
101
+ explanation: hint.explanation,
102
+ why_inferred: hint.why_inferred || describeAuthClaimWhyInferred(hint),
103
+ review_guidance: hint.review_guidance || buildAuthClaimReviewGuidance(hint),
104
+ related_capabilities: relatedCapabilities,
105
+ projection_surface: projectionSurface,
106
+ evidence: hint.evidence || {}
107
+ };
108
+ const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
109
+ if (existing) {
110
+ existing.missing_auth_claims = existing.missing_auth_claims || [];
111
+ const duplicate = existing.missing_auth_claims.some((/** @type {any} */ candidate) =>
112
+ candidate.claim === entry.claim &&
113
+ String(candidate.claim_value || "") === String(entry.claim_value || "") &&
114
+ candidate.projection_surface === entry.projection_surface &&
115
+ stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
116
+ );
117
+ if (!duplicate) {
118
+ existing.missing_auth_claims.push(entry);
119
+ }
120
+ continue;
121
+ }
122
+ patches.push({
123
+ projection_id: impact.projection_id,
124
+ kind: impact.kind,
125
+ projection_type: impact.projection_type,
126
+ reason: `Projection ${impact.projection_id} likely needs claim-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
127
+ missing_realizes: relatedCapabilities,
128
+ missing_http: [],
129
+ missing_screens: [],
130
+ missing_routes: [],
131
+ missing_actions: [],
132
+ missing_auth_claims: [entry]
133
+ });
134
+ }
135
+ }
136
+
137
+ for (const hint of bundle.authPermissionHints || []) {
138
+ for (const impact of bundle.projectionImpacts || []) {
139
+ const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
140
+ if (relatedCapabilities.length === 0) {
141
+ continue;
142
+ }
143
+ const projectionSurface = impact.kind === "ui" ? "visibility_rules" : "authorization";
144
+ const entry = {
145
+ permission: hint.permission,
146
+ confidence: hint.confidence,
147
+ review_required: true,
148
+ explanation: hint.explanation,
149
+ why_inferred: hint.why_inferred || describeAuthPermissionWhyInferred(hint),
150
+ review_guidance: hint.review_guidance || buildAuthPermissionReviewGuidance(hint),
151
+ related_capabilities: relatedCapabilities,
152
+ projection_surface: projectionSurface,
153
+ evidence: hint.evidence || {}
154
+ };
155
+ const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
156
+ if (existing) {
157
+ existing.missing_auth_permissions = existing.missing_auth_permissions || [];
158
+ const duplicate = existing.missing_auth_permissions.some((/** @type {any} */ candidate) =>
159
+ candidate.permission === entry.permission &&
160
+ candidate.projection_surface === entry.projection_surface &&
161
+ stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
162
+ );
163
+ if (!duplicate) {
164
+ existing.missing_auth_permissions.push(entry);
165
+ }
166
+ continue;
167
+ }
168
+ patches.push({
169
+ projection_id: impact.projection_id,
170
+ kind: impact.kind,
171
+ projection_type: impact.projection_type,
172
+ reason: `Projection ${impact.projection_id} likely needs permission-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
173
+ missing_realizes: relatedCapabilities,
174
+ missing_http: [],
175
+ missing_screens: [],
176
+ missing_routes: [],
177
+ missing_actions: [],
178
+ missing_auth_permissions: [entry]
179
+ });
180
+ }
181
+ }
182
+
183
+ for (const hint of bundle.authOwnershipHints || []) {
184
+ for (const impact of bundle.projectionImpacts || []) {
185
+ if (impact.kind !== "api") {
186
+ continue;
187
+ }
188
+ const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
189
+ if (relatedCapabilities.length === 0) {
190
+ continue;
191
+ }
192
+ const entry = {
193
+ ownership: hint.ownership,
194
+ ownership_field: hint.ownership_field,
195
+ confidence: hint.confidence,
196
+ review_required: true,
197
+ explanation: hint.explanation,
198
+ why_inferred: hint.why_inferred || describeAuthOwnershipWhyInferred(hint),
199
+ review_guidance: hint.review_guidance || buildAuthOwnershipReviewGuidance(hint),
200
+ related_capabilities: relatedCapabilities,
201
+ related_entities: hint.related_entities || [],
202
+ evidence: hint.evidence || {}
203
+ };
204
+ const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
205
+ if (existing) {
206
+ existing.missing_auth_ownerships = existing.missing_auth_ownerships || [];
207
+ const duplicate = existing.missing_auth_ownerships.some((/** @type {any} */ candidate) =>
208
+ candidate.ownership === entry.ownership &&
209
+ candidate.ownership_field === entry.ownership_field &&
210
+ stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
211
+ );
212
+ if (!duplicate) {
213
+ existing.missing_auth_ownerships.push(entry);
214
+ }
215
+ continue;
216
+ }
217
+ patches.push({
218
+ projection_id: impact.projection_id,
219
+ kind: impact.kind,
220
+ projection_type: impact.projection_type,
221
+ reason: `Projection ${impact.projection_id} likely needs ownership-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
222
+ missing_realizes: relatedCapabilities,
223
+ missing_http: [],
224
+ missing_screens: [],
225
+ missing_routes: [],
226
+ missing_actions: [],
227
+ missing_auth_ownerships: [entry]
228
+ });
229
+ }
230
+ }
231
+
232
+ return patches
233
+ .map((/** @type {any} */ patch) => ({
234
+ ...patch,
235
+ missing_auth_permissions: (patch.missing_auth_permissions || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
236
+ (a.projection_surface || "").localeCompare(b.projection_surface || "") ||
237
+ (a.permission || "").localeCompare(b.permission || "") ||
238
+ stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
239
+ ),
240
+ missing_auth_claims: (patch.missing_auth_claims || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
241
+ (a.projection_surface || "").localeCompare(b.projection_surface || "") ||
242
+ (a.claim || "").localeCompare(b.claim || "") ||
243
+ stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
244
+ ),
245
+ missing_auth_ownerships: (patch.missing_auth_ownerships || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
246
+ (a.ownership_field || "").localeCompare(b.ownership_field || "") ||
247
+ stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
248
+ ),
249
+ patch_rel_path: `projection-patches/${patch.projection_id}.md`
250
+ }))
251
+ .sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
252
+ }
@@ -0,0 +1,80 @@
1
+ // @ts-check
2
+
3
+ /** @param {CandidateBundle} bundle @param {ProjectionImpact[]} projectionIndex @returns {any} */
4
+ export function buildProjectionImpacts(bundle, projectionIndex) {
5
+ const bundleEntityIds = new Set([
6
+ bundle.mergeHints?.canonicalEntityTarget || null,
7
+ ...bundle.entities.map((/** @type {any} */ entry) => entry.id_hint)
8
+ ].filter(Boolean));
9
+ if (bundle.capabilities.length === 0 || bundleEntityIds.size === 0) {
10
+ return [];
11
+ }
12
+ return projectionIndex
13
+ .filter((/** @type {any} */ projection) => projection.kind === "api" || projection.kind === "ui")
14
+ .filter((/** @type {any} */ projection) => projection.entityIds.some((/** @type {any} */ entityId) => bundleEntityIds.has(entityId)))
15
+ .map((/** @type {any} */ projection) => {
16
+ const missingCapabilities = bundle.capabilities
17
+ .map((/** @type {any} */ entry) => entry.id_hint)
18
+ .filter((/** @type {any} */ id) => !projection.realizes.includes(id));
19
+ if (missingCapabilities.length === 0) {
20
+ return null;
21
+ }
22
+ return {
23
+ projection_id: projection.id,
24
+ projection_type: projection.type,
25
+ kind: projection.kind,
26
+ missing_capabilities: missingCapabilities,
27
+ reason: `Projection ${projection.id} already covers the same entity surface but does not realize these imported capabilities.`
28
+ };
29
+ })
30
+ .filter(Boolean)
31
+ .sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
32
+ }
33
+
34
+ /** @param {CandidateBundle} bundle @param {ResolvedGraph} graph @returns {any} */
35
+ export function buildUiImpacts(bundle, graph) {
36
+ if ((bundle.screens || []).length === 0) {
37
+ return [];
38
+ }
39
+ const uiProjections = (graph?.byKind.projection || []).filter((/** @type {any} */ projection) => ["ui_contract", "web_surface"].includes(projection.type));
40
+ const bundleScreenIds = bundle.screens.map((/** @type {any} */ screen) => screen.id_hint);
41
+ return uiProjections
42
+ .map((/** @type {any} */ projection) => {
43
+ const projectionScreens = new Set((projection.uiScreens || []).map((/** @type {any} */ screen) => screen.id));
44
+ const missingScreens = bundleScreenIds.filter((/** @type {any} */ screenId) => !projectionScreens.has(screenId));
45
+ if (missingScreens.length === 0) {
46
+ return null;
47
+ }
48
+ return {
49
+ projection_id: projection.id,
50
+ kind: "ui",
51
+ projection_type: projection.type,
52
+ missing_screens: missingScreens,
53
+ reason: `UI projection ${projection.id} does not currently represent these imported screens.`
54
+ };
55
+ })
56
+ .filter(Boolean)
57
+ .sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
58
+ }
59
+
60
+ /** @param {CandidateBundle} bundle @param {ResolvedGraph} graph @returns {any} */
61
+ export function buildWorkflowImpacts(bundle, graph) {
62
+ if ((bundle.workflows || []).length === 0) {
63
+ return [];
64
+ }
65
+ const canonicalWorkflowDocs = new Set((graph?.docs || []).filter((/** @type {any} */ doc) => doc.kind === "workflow").map((/** @type {any} */ doc) => doc.id));
66
+ const impacted = bundle.workflows
67
+ .map((/** @type {any} */ workflow) => workflow.id_hint)
68
+ .filter((/** @type {any} */ id) => !canonicalWorkflowDocs.has(id));
69
+ if (impacted.length === 0) {
70
+ return [];
71
+ }
72
+ return [
73
+ {
74
+ review_group_id: `workflow_review:${bundle.slug}`,
75
+ kind: "workflow",
76
+ items: impacted,
77
+ reason: `Workflow semantics for ${bundle.slug} need canonical review before promotion.`
78
+ }
79
+ ];
80
+ }