@topogram/cli 0.3.64 → 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 (245) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan/index.js +703 -0
  3. package/src/adoption/plan.js +12 -703
  4. package/src/agent-ops/query-builders/auth.js +375 -0
  5. package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
  6. package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
  7. package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
  8. package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
  9. package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
  10. package/src/agent-ops/query-builders/change-risk.js +25 -0
  11. package/src/agent-ops/query-builders/common.js +149 -0
  12. package/src/agent-ops/query-builders/maintained-risk.js +539 -0
  13. package/src/agent-ops/query-builders/maintained-shared.js +120 -0
  14. package/src/agent-ops/query-builders/multi-agent.js +547 -0
  15. package/src/agent-ops/query-builders/projection-impacts.js +514 -0
  16. package/src/agent-ops/query-builders/work-packets.js +417 -0
  17. package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
  18. package/src/agent-ops/query-builders/workflow-context.js +398 -0
  19. package/src/agent-ops/query-builders/workflow-presets-core.js +676 -0
  20. package/src/agent-ops/query-builders/workflow-presets.js +341 -0
  21. package/src/agent-ops/query-builders.d.ts +26 -26
  22. package/src/agent-ops/query-builders.js +42 -5021
  23. package/src/catalog/constants.js +10 -0
  24. package/src/catalog/copy.js +60 -0
  25. package/src/catalog/diagnostics.js +15 -0
  26. package/src/catalog/entries.js +42 -0
  27. package/src/catalog/files.js +67 -0
  28. package/src/catalog/provenance.js +122 -0
  29. package/src/catalog/source.js +150 -0
  30. package/src/catalog/validation.js +252 -0
  31. package/src/catalog.d.ts +2 -0
  32. package/src/catalog.js +18 -746
  33. package/src/cli/commands/catalog/check.js +31 -0
  34. package/src/cli/commands/catalog/copy.js +59 -0
  35. package/src/cli/commands/catalog/doctor.js +248 -0
  36. package/src/cli/commands/catalog/help.js +21 -0
  37. package/src/cli/commands/catalog/list.js +52 -0
  38. package/src/cli/commands/catalog/runner.js +92 -0
  39. package/src/cli/commands/catalog/shared.js +17 -0
  40. package/src/cli/commands/catalog/show.js +134 -0
  41. package/src/cli/commands/catalog.js +30 -615
  42. package/src/cli/commands/generator-policy/package-info.js +162 -0
  43. package/src/cli/commands/generator-policy/payloads.js +372 -0
  44. package/src/cli/commands/generator-policy/printers.js +159 -0
  45. package/src/cli/commands/generator-policy/runner.js +81 -0
  46. package/src/cli/commands/generator-policy/shared.js +39 -0
  47. package/src/cli/commands/generator-policy.js +15 -783
  48. package/src/cli/commands/import/adopt.js +170 -0
  49. package/src/cli/commands/import/check.js +91 -0
  50. package/src/cli/commands/import/diff.js +84 -0
  51. package/src/cli/commands/import/help.js +47 -0
  52. package/src/cli/commands/import/paths.js +277 -0
  53. package/src/cli/commands/import/plan.js +284 -0
  54. package/src/cli/commands/import/refresh.js +470 -0
  55. package/src/cli/commands/import/status-history.js +196 -0
  56. package/src/cli/commands/import/workspace.js +230 -0
  57. package/src/cli/commands/import.js +33 -1732
  58. package/src/cli/commands/package/constants.js +17 -0
  59. package/src/cli/commands/package/doctor.js +240 -0
  60. package/src/cli/commands/package/help.js +27 -0
  61. package/src/cli/commands/package/lockfile.js +135 -0
  62. package/src/cli/commands/package/npm.js +97 -0
  63. package/src/cli/commands/package/reporting.js +35 -0
  64. package/src/cli/commands/package/runner.js +33 -0
  65. package/src/cli/commands/package/shared.js +9 -0
  66. package/src/cli/commands/package/update-cli.js +252 -0
  67. package/src/cli/commands/package/versions.js +35 -0
  68. package/src/cli/commands/package.js +29 -813
  69. package/src/cli/commands/query/change-plan.js +68 -0
  70. package/src/cli/commands/query/definitions.js +202 -0
  71. package/src/cli/commands/query/import-adopt.js +121 -0
  72. package/src/cli/commands/query/runner/artifacts.js +102 -0
  73. package/src/cli/commands/query/runner/boundaries.js +211 -0
  74. package/src/cli/commands/query/runner/change.js +182 -0
  75. package/src/cli/commands/query/runner/import-adopt.js +111 -0
  76. package/src/cli/commands/query/runner/index.js +31 -0
  77. package/src/cli/commands/query/runner/output.js +12 -0
  78. package/src/cli/commands/query/runner/workflow.js +241 -0
  79. package/src/cli/commands/query/runner.js +3 -0
  80. package/src/cli/commands/query/workflow-context.js +5 -0
  81. package/src/cli/commands/query/workspace.js +274 -0
  82. package/src/cli/commands/query.js +9 -1300
  83. package/src/cli/commands/template/baseline.js +100 -0
  84. package/src/cli/commands/template/check.js +466 -0
  85. package/src/cli/commands/template/constants.js +8 -0
  86. package/src/cli/commands/template/diagnostics.js +26 -0
  87. package/src/cli/commands/template/help.js +28 -0
  88. package/src/cli/commands/template/lifecycle.js +404 -0
  89. package/src/cli/commands/template/list-show.js +287 -0
  90. package/src/cli/commands/template/policy.js +422 -0
  91. package/src/cli/commands/template/shared.js +127 -0
  92. package/src/cli/commands/template/updates.js +352 -0
  93. package/src/cli/commands/template.js +41 -2143
  94. package/src/generator/api/contracts.js +497 -0
  95. package/src/generator/api/metadata.js +221 -0
  96. package/src/generator/api/openapi.js +559 -0
  97. package/src/generator/api/schema.js +124 -0
  98. package/src/generator/api/types.d.ts +98 -0
  99. package/src/generator/api.js +3 -1195
  100. package/src/generator/context/shared/domain-sdlc.js +282 -0
  101. package/src/generator/context/shared/maintained-boundary.js +665 -0
  102. package/src/generator/context/shared/metrics.js +85 -0
  103. package/src/generator/context/shared/primitives.js +64 -0
  104. package/src/generator/context/shared/relationships.js +453 -0
  105. package/src/generator/context/shared/summaries.js +263 -0
  106. package/src/generator/context/shared/types.d.ts +207 -0
  107. package/src/generator/context/shared.d.ts +42 -0
  108. package/src/generator/context/shared.js +80 -1390
  109. package/src/generator/context/slice/core.js +397 -0
  110. package/src/generator/context/slice/sdlc.js +417 -0
  111. package/src/generator/context/slice/ui-packets.js +183 -0
  112. package/src/generator/context/slice.js +2 -859
  113. package/src/generator/registry/index.js +507 -0
  114. package/src/generator/registry.js +18 -504
  115. package/src/generator/runtime/environment/index.js +666 -0
  116. package/src/generator/runtime/environment.js +4 -666
  117. package/src/generator/runtime/runtime-check/index.js +554 -0
  118. package/src/generator/runtime/runtime-check.js +4 -554
  119. package/src/generator/runtime/shared/index.js +572 -0
  120. package/src/generator/runtime/shared.js +19 -570
  121. package/src/generator/shared.d.ts +2 -0
  122. package/src/generator/surfaces/shared.d.ts +3 -0
  123. package/src/generator/widget-conformance/behavior-report.js +258 -0
  124. package/src/generator/widget-conformance/checks.js +371 -0
  125. package/src/generator/widget-conformance/projection-context.js +200 -0
  126. package/src/generator/widget-conformance/report.js +166 -0
  127. package/src/generator/widget-conformance/types.d.ts +121 -0
  128. package/src/generator/widget-conformance.js +3 -824
  129. package/src/import/core/context.d.ts +3 -0
  130. package/src/import/core/contracts.d.ts +1 -0
  131. package/src/import/core/registry.d.ts +4 -0
  132. package/src/import/core/runner/candidates.js +217 -0
  133. package/src/import/core/runner/options.js +22 -0
  134. package/src/import/core/runner/reports.js +50 -0
  135. package/src/import/core/runner/run.js +79 -0
  136. package/src/import/core/runner/tracks.js +150 -0
  137. package/src/import/core/runner/ui-drafts.js +337 -0
  138. package/src/import/core/runner.js +3 -698
  139. package/src/import/core/shared/api-routes.js +221 -0
  140. package/src/import/core/shared/candidates.js +97 -0
  141. package/src/import/core/shared/files.js +177 -0
  142. package/src/import/core/shared/next-app.js +389 -0
  143. package/src/import/core/shared/types.d.ts +51 -0
  144. package/src/import/core/shared/ui-routes.js +230 -0
  145. package/src/import/core/shared.js +60 -861
  146. package/src/new-project/constants.js +128 -0
  147. package/src/new-project/create.js +83 -0
  148. package/src/new-project/json.js +28 -0
  149. package/src/new-project/metadata.js +96 -0
  150. package/src/new-project/package-spec.js +161 -0
  151. package/src/new-project/project-files.js +348 -0
  152. package/src/new-project/template-policy.js +269 -0
  153. package/src/new-project/template-resolution.js +368 -0
  154. package/src/new-project/template-snapshots.js +430 -0
  155. package/src/new-project/template-updates.js +512 -0
  156. package/src/new-project/types.d.ts +83 -0
  157. package/src/new-project.js +6 -2277
  158. package/src/parser.d.ts +87 -1
  159. package/src/parser.js +118 -0
  160. package/src/policy/review-boundaries.d.ts +15 -0
  161. package/src/project-config/index.js +564 -0
  162. package/src/project-config.js +19 -561
  163. package/src/resolver/enrich/acceptance-criterion.js +2 -0
  164. package/src/resolver/enrich/bug.js +2 -0
  165. package/src/resolver/enrich/pitch.js +2 -0
  166. package/src/resolver/enrich/requirement.js +2 -0
  167. package/src/resolver/enrich/task.js +2 -0
  168. package/src/resolver/index.js +19 -2089
  169. package/src/resolver/normalize.js +384 -1
  170. package/src/resolver/plans.js +168 -0
  171. package/src/resolver/projections-api.js +494 -0
  172. package/src/resolver/projections-db.js +133 -0
  173. package/src/resolver/projections-ui.js +317 -0
  174. package/src/resolver/shapes.js +251 -0
  175. package/src/resolver/shared.js +278 -0
  176. package/src/resolver/widgets.js +132 -0
  177. package/src/template-trust/constants.js +62 -0
  178. package/src/template-trust/content.js +258 -0
  179. package/src/template-trust/diff.js +92 -0
  180. package/src/template-trust/policy.js +61 -0
  181. package/src/template-trust/record.js +90 -0
  182. package/src/template-trust/status.js +182 -0
  183. package/src/template-trust.js +24 -687
  184. package/src/text-helpers.d.ts +1 -0
  185. package/src/topogram-types.d.ts +69 -0
  186. package/src/validator/common.js +488 -0
  187. package/src/validator/data-model.js +237 -0
  188. package/src/validator/docs.js +167 -0
  189. package/src/validator/expressions.js +146 -1
  190. package/src/validator/index.d.ts +23 -0
  191. package/src/validator/index.js +32 -3585
  192. package/src/validator/kinds.d.ts +41 -0
  193. package/src/validator/kinds.js +2 -0
  194. package/src/validator/model-helpers.js +46 -0
  195. package/src/validator/per-kind/acceptance-criterion.js +5 -0
  196. package/src/validator/per-kind/bug.js +6 -0
  197. package/src/validator/per-kind/domain.js +15 -2
  198. package/src/validator/per-kind/pitch.js +7 -0
  199. package/src/validator/per-kind/requirement.js +5 -0
  200. package/src/validator/per-kind/task.js +7 -0
  201. package/src/validator/per-kind/widget.js +14 -0
  202. package/src/validator/projections/api-http-async.js +410 -0
  203. package/src/validator/projections/api-http-authz.js +88 -0
  204. package/src/validator/projections/api-http-core.js +205 -0
  205. package/src/validator/projections/api-http-policies.js +339 -0
  206. package/src/validator/projections/api-http-responses.js +233 -0
  207. package/src/validator/projections/api-http.js +44 -0
  208. package/src/validator/projections/db.js +353 -0
  209. package/src/validator/projections/generator-defaults.js +45 -0
  210. package/src/validator/projections/helpers.js +87 -0
  211. package/src/validator/projections/ui-helpers.js +214 -0
  212. package/src/validator/projections/ui-navigation.js +344 -0
  213. package/src/validator/projections/ui-structure.js +364 -0
  214. package/src/validator/projections/ui-widgets.js +493 -0
  215. package/src/validator/projections/ui.js +46 -0
  216. package/src/validator/registry.js +48 -1
  217. package/src/validator/utils.d.ts +20 -0
  218. package/src/validator/utils.js +115 -12
  219. package/src/widget-behavior.d.ts +1 -0
  220. package/src/workflows/import-app/api/collect.js +221 -0
  221. package/src/workflows/import-app/api/openapi.js +257 -0
  222. package/src/workflows/import-app/api/routes.js +327 -0
  223. package/src/workflows/import-app/api/sources.js +22 -0
  224. package/src/workflows/import-app/api.js +2 -797
  225. package/src/workflows/reconcile/adoption-plan/build.js +208 -0
  226. package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
  227. package/src/workflows/reconcile/adoption-plan/outputs.js +143 -0
  228. package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
  229. package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
  230. package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
  231. package/src/workflows/reconcile/adoption-plan.js +30 -740
  232. package/src/workflows/reconcile/auth/closures.js +115 -0
  233. package/src/workflows/reconcile/auth/formatters.js +142 -0
  234. package/src/workflows/reconcile/auth/inference.js +330 -0
  235. package/src/workflows/reconcile/auth/roles.js +122 -0
  236. package/src/workflows/reconcile/auth.js +35 -690
  237. package/src/workflows/reconcile/bundle-core/index.js +600 -0
  238. package/src/workflows/reconcile/bundle-core.js +12 -598
  239. package/src/workflows/reconcile/canonical-surface.js +1 -1
  240. package/src/workflows/reconcile/impacts/adoption-plan.js +192 -0
  241. package/src/workflows/reconcile/impacts/indexes.js +101 -0
  242. package/src/workflows/reconcile/impacts/patches.js +252 -0
  243. package/src/workflows/reconcile/impacts/reports.js +80 -0
  244. package/src/workflows/reconcile/impacts.js +14 -623
  245. package/src/workspace-docs.d.ts +29 -0
@@ -1,625 +1,16 @@
1
1
  // @ts-check
2
- import { stableStringify } from "../../format.js";
3
- import { docDirForKind } from "../docs.js";
4
- import { dashedTopogramId } from "./ids.js";
5
- import {
6
- buildAuthClaimReviewGuidance,
7
- buildAuthOwnershipReviewGuidance,
8
- buildAuthPermissionReviewGuidance,
9
- describeAuthClaimWhyInferred,
10
- describeAuthOwnershipWhyInferred,
11
- describeAuthPermissionWhyInferred,
12
- formatAuthClaimHintInline,
13
- formatAuthOwnershipHintInline,
14
- formatAuthPermissionHintInline
15
- } from "./auth.js";
16
2
 
17
- /** @param {any[]} fields @returns {any} */
18
- export function shapeFieldSignature(fields) {
19
- return [...new Set((fields || []).filter(Boolean))].sort().join("|");
20
- }
21
-
22
- /** @param {ResolvedGraph} graph @returns {any} */
23
- export function buildCanonicalShapeIndex(graph) {
24
- const bySignature = new Map();
25
- for (const shape of graph?.byKind.shape || []) {
26
- const fields = (shape.projectedFields || shape.fields || []).map((/** @type {any} */ field) => field.name).filter(Boolean);
27
- const signature = shapeFieldSignature(fields);
28
- if (!signature) {
29
- continue;
30
- }
31
- if (!bySignature.has(signature)) {
32
- bySignature.set(signature, []);
33
- }
34
- bySignature.get(signature).push(shape.id);
35
- }
36
- return bySignature;
37
- }
38
-
39
- /** @param {WorkflowRecord} capability @returns {any} */
40
- export function capabilityEntityTargets(capability) {
41
- return [
42
- ...(capability.creates || []),
43
- ...(capability.updates || []),
44
- ...(capability.deletes || []),
45
- ...(capability.reads || [])
46
- ]
47
- .map((/** @type {any} */ ref) => ref?.id || ref?.target?.id || null)
48
- .filter((/** @type {any} */ id) => typeof id === "string" && id.startsWith("entity_"));
49
- }
50
-
51
- /** @param {WorkflowRecord} projection @returns {any} */
52
- export function projectionKindForImpact(projection) {
53
- if ((projection.http || []).length > 0 || projection.type === "api_contract") {
54
- return "api";
55
- }
56
- if (
57
- (projection.uiRoutes || []).length > 0 ||
58
- (projection.uiWeb || []).length > 0 ||
59
- (projection.uiIos || []).length > 0 ||
60
- projection.type === "web_surface" ||
61
- projection.type === "ios_surface"
62
- ) {
63
- return "ui";
64
- }
65
- if ((projection.dbTables || []).length > 0) {
66
- return "db";
67
- }
68
- return "other";
69
- }
70
-
71
- /** @param {ResolvedGraph} graph @returns {any} */
72
- export function buildProjectionEntityIndex(graph) {
73
- const projections = graph?.byKind.projection || [];
74
- const capabilities = new Map((graph?.byKind.capability || []).map((/** @type {any} */ capability) => [capability.id, capability]));
75
- const projectionsById = new Map(projections.map((/** @type {any} */ projection) => [projection.id, projection]));
76
- const memo = new Map();
77
-
78
- /** @param {string} projectionId @param {any} stack @returns {any} */
79
- function collectEntities(projectionId, stack = new Set()) {
80
- if (memo.has(projectionId)) {
81
- return memo.get(projectionId);
82
- }
83
- if (stack.has(projectionId)) {
84
- return new Set();
85
- }
86
- stack.add(projectionId);
87
- const projection = projectionsById.get(projectionId);
88
- const entities = new Set();
89
- for (const realized of projection?.realizes || []) {
90
- const realizedKind = realized?.target?.kind || realized?.kind || null;
91
- const realizedId = realized?.target?.id || realized?.id || null;
92
- if (realizedKind === "capability") {
93
- const capability = capabilities.get(realizedId);
94
- for (const entityId of capabilityEntityTargets(capability || {})) {
95
- entities.add(entityId);
96
- }
97
- } else if (realizedKind === "projection") {
98
- for (const entityId of collectEntities(realizedId, stack)) {
99
- entities.add(entityId);
100
- }
101
- }
102
- }
103
- memo.set(projectionId, entities);
104
- stack.delete(projectionId);
105
- return entities;
106
- }
107
-
108
- return projections.map((/** @type {any} */ projection) => ({
109
- id: projection.id,
110
- projection_type: projection.type || null,
111
- kind: projectionKindForImpact(projection),
112
- realizes: (projection.realizes || []).map((/** @type {any} */ entry) => entry.id),
113
- entityIds: [...collectEntities(projection.id)].sort()
114
- }));
115
- }
116
-
117
- /** @param {CandidateBundle} bundle @param {any} canonicalShapeIndex @returns {any} */
118
- export function buildBundleAdoptionPlan(bundle, canonicalShapeIndex) {
119
- /** @type {any[]} */
120
- const steps = [];
121
- for (const entry of bundle.actors) {
122
- steps.push({
123
- action: "promote_actor",
124
- item: entry.id_hint,
125
- target: null,
126
- confidence: entry.confidence || "low",
127
- inference_summary: entry.inference_summary || null,
128
- related_docs: entry.related_docs || [],
129
- related_capabilities: entry.related_capabilities || [],
130
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/actors/${entry.id_hint}.tg`,
131
- canonical_rel_path: `actors/${dashedTopogramId(entry.id_hint)}.tg`
132
- });
133
- }
134
- for (const entry of bundle.roles) {
135
- steps.push({
136
- action: "promote_role",
137
- item: entry.id_hint,
138
- target: null,
139
- confidence: entry.confidence || "low",
140
- inference_summary: entry.inference_summary || null,
141
- related_docs: entry.related_docs || [],
142
- related_capabilities: entry.related_capabilities || [],
143
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/roles/${entry.id_hint}.tg`,
144
- canonical_rel_path: `roles/${dashedTopogramId(entry.id_hint)}.tg`
145
- });
146
- }
147
- if (bundle.mergeHints?.canonicalEntityTarget) {
148
- steps.push({
149
- action: "merge_bundle_into_existing_entity",
150
- item: bundle.slug,
151
- target: bundle.mergeHints.canonicalEntityTarget
152
- });
153
- } else if (bundle.entities.length > 0) {
154
- for (const entry of bundle.entities) {
155
- steps.push({
156
- action: "promote_entity",
157
- item: entry.id_hint,
158
- target: null
159
- });
160
- }
161
- }
162
- for (const entry of bundle.enums) {
163
- steps.push({
164
- action: "promote_enum",
165
- item: entry.id_hint,
166
- target: bundle.mergeHints?.canonicalEntityTarget || null
167
- });
168
- }
169
- for (const entry of bundle.capabilities) {
170
- steps.push({
171
- action: bundle.mergeHints?.canonicalEntityTarget ? "merge_capability_into_existing_entity" : "promote_capability",
172
- item: entry.id_hint,
173
- target: bundle.mergeHints?.canonicalEntityTarget || null
174
- });
175
- }
176
- for (const entry of bundle.shapes) {
177
- const signature = shapeFieldSignature(entry.fields || []);
178
- const duplicateTargets = canonicalShapeIndex.get(signature) || [];
179
- if (duplicateTargets.length > 0) {
180
- steps.push({
181
- action: "skip_duplicate_shape",
182
- item: entry.id,
183
- target: duplicateTargets[0]
184
- });
185
- continue;
186
- }
187
- steps.push({
188
- action: "promote_shape",
189
- item: entry.id,
190
- target: bundle.mergeHints?.canonicalEntityTarget || null
191
- });
192
- }
193
- for (const entry of bundle.docs) {
194
- if (entry.existing_canonical) {
195
- continue;
196
- }
197
- steps.push({
198
- action: entry.kind === "workflow" ? "promote_workflow_doc" : "promote_doc",
199
- item: entry.id,
200
- target: null,
201
- doc_kind: entry.kind,
202
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/${docDirForKind(entry.kind)}/${entry.id}.md`,
203
- canonical_rel_path: `docs/${docDirForKind(entry.kind)}/${entry.id}.md`
204
- });
205
- }
206
- for (const entry of bundle.workflows) {
207
- steps.push({
208
- action: "promote_workflow_decision",
209
- item: `dec_${entry.id_hint.replace(/^workflow_/, "")}`,
210
- target: null,
211
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/decisions/dec_${entry.id_hint.replace(/^workflow_/, "")}.tg`,
212
- canonical_rel_path: `decisions/decision-${dashedTopogramId(entry.id_hint.replace(/^workflow_/, ""))}.tg`
213
- });
214
- steps.push({
215
- action: "promote_workflow_doc",
216
- item: entry.id_hint,
217
- target: null,
218
- doc_kind: "workflow",
219
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/workflows/${entry.id_hint}.md`,
220
- canonical_rel_path: `docs/workflows/${entry.id_hint}.md`
221
- });
222
- }
223
- for (const entry of bundle.verifications || []) {
224
- steps.push({
225
- action: "promote_verification",
226
- item: entry.id_hint,
227
- target: null,
228
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/verifications/${entry.id_hint}.tg`,
229
- canonical_rel_path: `verifications/${dashedTopogramId(entry.id_hint)}.tg`
230
- });
231
- }
232
- for (const entry of bundle.widgets || []) {
233
- steps.push({
234
- action: "promote_widget",
235
- item: entry.id_hint,
236
- target: null,
237
- confidence: entry.confidence || "low",
238
- inference_summary: entry.inference_summary || null,
239
- related_capabilities: [entry.data_source].filter(Boolean),
240
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/widgets/${entry.id_hint}.tg`,
241
- canonical_rel_path: `widgets/${dashedTopogramId(entry.id_hint)}.tg`
242
- });
243
- }
244
- for (const screen of bundle.screens) {
245
- steps.push({
246
- action: "promote_ui_report",
247
- item: `ui_${screen.id_hint}`,
248
- target: null,
249
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/reports/ui-${screen.id_hint}.md`,
250
- canonical_rel_path: `docs/reports/ui-${screen.id_hint}.md`
251
- });
252
- }
253
- for (const patch of bundle.projectionPatches || []) {
254
- for (const hint of patch.missing_auth_permissions || []) {
255
- steps.push({
256
- action: "apply_projection_permission_patch",
257
- item: `projection_permission_patch:${patch.projection_id}:${hint.projection_surface}:${hint.permission}`,
258
- target: patch.projection_id,
259
- projection_kind: patch.kind,
260
- projection_surface: hint.projection_surface,
261
- permission: hint.permission,
262
- confidence: hint.confidence || "low",
263
- inference_summary: hint.why_inferred || hint.explanation || null,
264
- related_capabilities: hint.related_capabilities || [],
265
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
266
- canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
267
- });
268
- }
269
- for (const hint of patch.missing_auth_claims || []) {
270
- steps.push({
271
- action: "apply_projection_auth_patch",
272
- item: `projection_auth_patch:${patch.projection_id}:${hint.projection_surface}:${hint.claim}`,
273
- target: patch.projection_id,
274
- projection_kind: patch.kind,
275
- projection_surface: hint.projection_surface,
276
- claim: hint.claim,
277
- claim_value: hint.claim_value,
278
- confidence: hint.confidence || "low",
279
- inference_summary: hint.why_inferred || hint.explanation || null,
280
- related_capabilities: hint.related_capabilities || [],
281
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
282
- canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
283
- });
284
- }
285
- for (const hint of patch.missing_auth_ownerships || []) {
286
- steps.push({
287
- action: "apply_projection_ownership_patch",
288
- item: `projection_ownership_patch:${patch.projection_id}:${hint.ownership_field}`,
289
- target: patch.projection_id,
290
- projection_kind: patch.kind,
291
- projection_surface: "authorization",
292
- ownership: hint.ownership,
293
- ownership_field: hint.ownership_field,
294
- confidence: hint.confidence || "low",
295
- inference_summary: hint.why_inferred || hint.explanation || null,
296
- related_capabilities: hint.related_capabilities || [],
297
- source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
298
- canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
299
- });
300
- }
301
- }
302
- return steps;
303
- }
304
-
305
- /** @param {CandidateBundle} bundle @param {any} projectionIndex @returns {any} */
306
- export function buildProjectionImpacts(bundle, projectionIndex) {
307
- const bundleEntityIds = new Set([
308
- bundle.mergeHints?.canonicalEntityTarget || null,
309
- ...bundle.entities.map((/** @type {any} */ entry) => entry.id_hint)
310
- ].filter(Boolean));
311
- if (bundle.capabilities.length === 0 || bundleEntityIds.size === 0) {
312
- return [];
313
- }
314
- return projectionIndex
315
- .filter((/** @type {any} */ projection) => projection.kind === "api" || projection.kind === "ui")
316
- .filter((/** @type {any} */ projection) => projection.entityIds.some((/** @type {any} */ entityId) => bundleEntityIds.has(entityId)))
317
- .map((/** @type {any} */ projection) => {
318
- const missingCapabilities = bundle.capabilities
319
- .map((/** @type {any} */ entry) => entry.id_hint)
320
- .filter((/** @type {any} */ id) => !projection.realizes.includes(id));
321
- if (missingCapabilities.length === 0) {
322
- return null;
323
- }
324
- return {
325
- projection_id: projection.id,
326
- projection_type: projection.type,
327
- kind: projection.kind,
328
- missing_capabilities: missingCapabilities,
329
- reason: `Projection ${projection.id} already covers the same entity surface but does not realize these imported capabilities.`
330
- };
331
- })
332
- .filter(Boolean)
333
- .sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
334
- }
335
-
336
- /** @param {CandidateBundle} bundle @param {ResolvedGraph} graph @returns {any} */
337
- export function buildUiImpacts(bundle, graph) {
338
- if ((bundle.screens || []).length === 0) {
339
- return [];
340
- }
341
- const uiProjections = (graph?.byKind.projection || []).filter((/** @type {any} */ projection) => ["ui_contract", "web_surface"].includes(projection.type));
342
- const bundleScreenIds = bundle.screens.map((/** @type {any} */ screen) => screen.id_hint);
343
- return uiProjections
344
- .map((/** @type {any} */ projection) => {
345
- const projectionScreens = new Set((projection.uiScreens || []).map((/** @type {any} */ screen) => screen.id));
346
- const missingScreens = bundleScreenIds.filter((/** @type {any} */ screenId) => !projectionScreens.has(screenId));
347
- if (missingScreens.length === 0) {
348
- return null;
349
- }
350
- return {
351
- projection_id: projection.id,
352
- kind: "ui",
353
- projection_type: projection.type,
354
- missing_screens: missingScreens,
355
- reason: `UI projection ${projection.id} does not currently represent these imported screens.`
356
- };
357
- })
358
- .filter(Boolean)
359
- .sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
360
- }
361
-
362
- /** @param {CandidateBundle} bundle @param {ResolvedGraph} graph @returns {any} */
363
- export function buildWorkflowImpacts(bundle, graph) {
364
- if ((bundle.workflows || []).length === 0) {
365
- return [];
366
- }
367
- const canonicalWorkflowDocs = new Set((graph?.docs || []).filter((/** @type {any} */ doc) => doc.kind === "workflow").map((/** @type {any} */ doc) => doc.id));
368
- const impacted = bundle.workflows
369
- .map((/** @type {any} */ workflow) => workflow.id_hint)
370
- .filter((/** @type {any} */ id) => !canonicalWorkflowDocs.has(id));
371
- if (impacted.length === 0) {
372
- return [];
373
- }
374
- return [
375
- {
376
- review_group_id: `workflow_review:${bundle.slug}`,
377
- kind: "workflow",
378
- items: impacted,
379
- reason: `Workflow semantics for ${bundle.slug} need canonical review before promotion.`
380
- }
381
- ];
382
- }
383
-
384
- /** @param {CandidateBundle} bundle @returns {any} */
385
- export function buildProjectionPatchCandidates(bundle) {
386
- const capabilityById = new Map((bundle.capabilities || []).map((/** @type {any} */ entry) => [entry.id_hint, entry]));
387
- const routesByScreen = new Map();
388
- for (const route of bundle.uiRoutes || []) {
389
- const screenId = route.screen_id || route.id_hint;
390
- if (!routesByScreen.has(screenId)) {
391
- routesByScreen.set(screenId, []);
392
- }
393
- routesByScreen.get(screenId).push(route);
394
- }
395
- const actionsByScreen = new Map();
396
- for (const action of bundle.uiActions || []) {
397
- const screenId = action.screen_id || action.id_hint;
398
- if (!actionsByScreen.has(screenId)) {
399
- actionsByScreen.set(screenId, []);
400
- }
401
- actionsByScreen.get(screenId).push(action);
402
- }
403
-
404
- /** @type {any[]} */
405
-
406
- const patches = [];
407
- for (const impact of bundle.projectionImpacts || []) {
408
- const missingRealizes = [...(impact.missing_capabilities || [])];
409
- const missingHttp = impact.kind === "api"
410
- ? missingRealizes
411
- .map((/** @type {any} */ capabilityId) => capabilityById.get(capabilityId))
412
- .filter(Boolean)
413
- .map((/** @type {any} */ entry) => ({
414
- capability_id: entry.id_hint,
415
- method: entry.endpoint?.method || "GET",
416
- path: entry.endpoint?.path || "/"
417
- }))
418
- : [];
419
- patches.push({
420
- projection_id: impact.projection_id,
421
- kind: impact.kind,
422
- projection_type: impact.projection_type,
423
- reason: impact.reason,
424
- missing_realizes: missingRealizes,
425
- missing_http: missingHttp,
426
- missing_screens: [],
427
- missing_routes: [],
428
- missing_actions: []
429
- });
430
- }
431
-
432
- for (const impact of bundle.uiImpacts || []) {
433
- const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
434
- const missingScreens = [...(impact.missing_screens || [])];
435
- const missingRoutes = missingScreens.flatMap((/** @type {any} */ screenId) => routesByScreen.get(screenId) || []).map((/** @type {any} */ route) => ({
436
- screen_id: route.screen_id,
437
- path: route.path
438
- }));
439
- const missingActions = missingScreens.flatMap((/** @type {any} */ screenId) => actionsByScreen.get(screenId) || []).map((/** @type {any} */ action) => ({
440
- screen_id: action.screen_id,
441
- capability_hint: action.capability_hint
442
- }));
443
- if (existing) {
444
- existing.missing_screens = [...new Set([...(existing.missing_screens || []), ...missingScreens])];
445
- existing.missing_routes = [...(existing.missing_routes || []), ...missingRoutes];
446
- existing.missing_actions = [...(existing.missing_actions || []), ...missingActions];
447
- continue;
448
- }
449
- patches.push({
450
- projection_id: impact.projection_id,
451
- kind: impact.kind,
452
- projection_type: impact.projection_type,
453
- reason: impact.reason,
454
- missing_realizes: [],
455
- missing_http: [],
456
- missing_screens: missingScreens,
457
- missing_routes: missingRoutes,
458
- missing_actions: missingActions
459
- });
460
- }
461
-
462
- for (const hint of bundle.authClaimHints || []) {
463
- for (const impact of bundle.projectionImpacts || []) {
464
- const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
465
- if (relatedCapabilities.length === 0) {
466
- continue;
467
- }
468
- const projectionSurface = impact.kind === "ui" ? "visibility_rules" : "authorization";
469
- const entry = {
470
- claim: hint.claim,
471
- claim_value: hint.claim_value,
472
- confidence: hint.confidence,
473
- review_required: true,
474
- explanation: hint.explanation,
475
- why_inferred: hint.why_inferred || describeAuthClaimWhyInferred(hint),
476
- review_guidance: hint.review_guidance || buildAuthClaimReviewGuidance(hint),
477
- related_capabilities: relatedCapabilities,
478
- projection_surface: projectionSurface,
479
- evidence: hint.evidence || {}
480
- };
481
- const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
482
- if (existing) {
483
- existing.missing_auth_claims = existing.missing_auth_claims || [];
484
- const duplicate = existing.missing_auth_claims.some((/** @type {any} */ candidate) =>
485
- candidate.claim === entry.claim &&
486
- String(candidate.claim_value || "") === String(entry.claim_value || "") &&
487
- candidate.projection_surface === entry.projection_surface &&
488
- stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
489
- );
490
- if (!duplicate) {
491
- existing.missing_auth_claims.push(entry);
492
- }
493
- continue;
494
- }
495
- patches.push({
496
- projection_id: impact.projection_id,
497
- kind: impact.kind,
498
- projection_type: impact.projection_type,
499
- reason: `Projection ${impact.projection_id} likely needs claim-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
500
- missing_realizes: relatedCapabilities,
501
- missing_http: [],
502
- missing_screens: [],
503
- missing_routes: [],
504
- missing_actions: [],
505
- missing_auth_claims: [entry]
506
- });
507
- }
508
- }
509
-
510
- for (const hint of bundle.authPermissionHints || []) {
511
- for (const impact of bundle.projectionImpacts || []) {
512
- const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
513
- if (relatedCapabilities.length === 0) {
514
- continue;
515
- }
516
- const projectionSurface = impact.kind === "ui" ? "visibility_rules" : "authorization";
517
- const entry = {
518
- permission: hint.permission,
519
- confidence: hint.confidence,
520
- review_required: true,
521
- explanation: hint.explanation,
522
- why_inferred: hint.why_inferred || describeAuthPermissionWhyInferred(hint),
523
- review_guidance: hint.review_guidance || buildAuthPermissionReviewGuidance(hint),
524
- related_capabilities: relatedCapabilities,
525
- projection_surface: projectionSurface,
526
- evidence: hint.evidence || {}
527
- };
528
- const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
529
- if (existing) {
530
- existing.missing_auth_permissions = existing.missing_auth_permissions || [];
531
- const duplicate = existing.missing_auth_permissions.some((/** @type {any} */ candidate) =>
532
- candidate.permission === entry.permission &&
533
- candidate.projection_surface === entry.projection_surface &&
534
- stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
535
- );
536
- if (!duplicate) {
537
- existing.missing_auth_permissions.push(entry);
538
- }
539
- continue;
540
- }
541
- patches.push({
542
- projection_id: impact.projection_id,
543
- kind: impact.kind,
544
- projection_type: impact.projection_type,
545
- reason: `Projection ${impact.projection_id} likely needs permission-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
546
- missing_realizes: relatedCapabilities,
547
- missing_http: [],
548
- missing_screens: [],
549
- missing_routes: [],
550
- missing_actions: [],
551
- missing_auth_permissions: [entry]
552
- });
553
- }
554
- }
555
-
556
- for (const hint of bundle.authOwnershipHints || []) {
557
- for (const impact of bundle.projectionImpacts || []) {
558
- if (impact.kind !== "api") {
559
- continue;
560
- }
561
- const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
562
- if (relatedCapabilities.length === 0) {
563
- continue;
564
- }
565
- const entry = {
566
- ownership: hint.ownership,
567
- ownership_field: hint.ownership_field,
568
- confidence: hint.confidence,
569
- review_required: true,
570
- explanation: hint.explanation,
571
- why_inferred: hint.why_inferred || describeAuthOwnershipWhyInferred(hint),
572
- review_guidance: hint.review_guidance || buildAuthOwnershipReviewGuidance(hint),
573
- related_capabilities: relatedCapabilities,
574
- related_entities: hint.related_entities || [],
575
- evidence: hint.evidence || {}
576
- };
577
- const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
578
- if (existing) {
579
- existing.missing_auth_ownerships = existing.missing_auth_ownerships || [];
580
- const duplicate = existing.missing_auth_ownerships.some((/** @type {any} */ candidate) =>
581
- candidate.ownership === entry.ownership &&
582
- candidate.ownership_field === entry.ownership_field &&
583
- stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
584
- );
585
- if (!duplicate) {
586
- existing.missing_auth_ownerships.push(entry);
587
- }
588
- continue;
589
- }
590
- patches.push({
591
- projection_id: impact.projection_id,
592
- kind: impact.kind,
593
- projection_type: impact.projection_type,
594
- reason: `Projection ${impact.projection_id} likely needs ownership-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
595
- missing_realizes: relatedCapabilities,
596
- missing_http: [],
597
- missing_screens: [],
598
- missing_routes: [],
599
- missing_actions: [],
600
- missing_auth_ownerships: [entry]
601
- });
602
- }
603
- }
604
-
605
- return patches
606
- .map((/** @type {any} */ patch) => ({
607
- ...patch,
608
- missing_auth_permissions: (patch.missing_auth_permissions || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
609
- (a.projection_surface || "").localeCompare(b.projection_surface || "") ||
610
- (a.permission || "").localeCompare(b.permission || "") ||
611
- stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
612
- ),
613
- missing_auth_claims: (patch.missing_auth_claims || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
614
- (a.projection_surface || "").localeCompare(b.projection_surface || "") ||
615
- (a.claim || "").localeCompare(b.claim || "") ||
616
- stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
617
- ),
618
- missing_auth_ownerships: (patch.missing_auth_ownerships || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
619
- (a.ownership_field || "").localeCompare(b.ownership_field || "") ||
620
- stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
621
- ),
622
- patch_rel_path: `projection-patches/${patch.projection_id}.md`
623
- }))
624
- .sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
625
- }
3
+ export { buildBundleAdoptionPlan } from "./impacts/adoption-plan.js";
4
+ export {
5
+ buildCanonicalShapeIndex,
6
+ buildProjectionEntityIndex,
7
+ capabilityEntityTargets,
8
+ projectionKindForImpact,
9
+ shapeFieldSignature
10
+ } from "./impacts/indexes.js";
11
+ export { buildProjectionPatchCandidates } from "./impacts/patches.js";
12
+ export {
13
+ buildProjectionImpacts,
14
+ buildUiImpacts,
15
+ buildWorkflowImpacts
16
+ } from "./impacts/reports.js";
@@ -0,0 +1,29 @@
1
+ import type { TopogramLocation } from "./topogram-types.js";
2
+
3
+ export const DOC_KINDS: Set<string>;
4
+ export const DOC_STATUSES: Set<string>;
5
+ export const DOC_CONFIDENCE: Set<string>;
6
+ export const DOC_AUDIENCES: Set<string>;
7
+ export const DOC_PRIORITIES: Set<string>;
8
+ export const DOC_ARRAY_FIELDS: Set<string>;
9
+ export const DOC_REFERENCE_FIELDS: Record<string, string>;
10
+ export const DOC_SCALAR_FIELDS: Set<string>;
11
+
12
+ export interface TopogramDocParseError {
13
+ message: string;
14
+ loc: TopogramLocation;
15
+ }
16
+
17
+ export interface TopogramDoc {
18
+ type: "doc";
19
+ file: string;
20
+ relativePath: string;
21
+ metadata: Record<string, any>;
22
+ body: string;
23
+ loc: TopogramLocation;
24
+ parseError: TopogramDocParseError | null;
25
+ }
26
+
27
+ export function collectTopogramDocFiles(inputPath: string): string[];
28
+ export function parseDocFile(filePath: string, workspaceRoot: string): TopogramDoc;
29
+ export function parseDocsPath(inputPath: string): TopogramDoc[];