@topogram/cli 0.3.34

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 (257) hide show
  1. package/ARCHITECTURE.md +67 -0
  2. package/CHANGELOG.md +240 -0
  3. package/README.md +223 -0
  4. package/package.json +51 -0
  5. package/src/adoption/index.js +3 -0
  6. package/src/adoption/plan.js +702 -0
  7. package/src/adoption/reporting.js +464 -0
  8. package/src/adoption/review-groups.js +313 -0
  9. package/src/agent-ops/query-builders.js +5012 -0
  10. package/src/archive/archive.js +141 -0
  11. package/src/archive/compact.js +26 -0
  12. package/src/archive/jsonl.js +70 -0
  13. package/src/archive/resolver-bridge.js +82 -0
  14. package/src/archive/schema.js +87 -0
  15. package/src/archive/unarchive.js +108 -0
  16. package/src/catalog.js +752 -0
  17. package/src/cli/catalog-alias.js +166 -0
  18. package/src/cli.js +9738 -0
  19. package/src/component-behavior.js +173 -0
  20. package/src/example-implementation.js +91 -0
  21. package/src/format.js +19 -0
  22. package/src/generator/adapters.d.ts +4 -0
  23. package/src/generator/adapters.js +325 -0
  24. package/src/generator/api.d.ts +1 -0
  25. package/src/generator/api.js +1196 -0
  26. package/src/generator/check.js +355 -0
  27. package/src/generator/component-conformance.js +767 -0
  28. package/src/generator/components.js +39 -0
  29. package/src/generator/context/bundle.js +291 -0
  30. package/src/generator/context/diff.js +256 -0
  31. package/src/generator/context/digest.js +182 -0
  32. package/src/generator/context/domain-coverage.js +94 -0
  33. package/src/generator/context/domain-page.js +137 -0
  34. package/src/generator/context/index.js +42 -0
  35. package/src/generator/context/report.js +121 -0
  36. package/src/generator/context/shared.js +1397 -0
  37. package/src/generator/context/slice.js +703 -0
  38. package/src/generator/context/task-mode.js +466 -0
  39. package/src/generator/docs.js +327 -0
  40. package/src/generator/index.js +161 -0
  41. package/src/generator/native/parity-bundle.js +311 -0
  42. package/src/generator/output.js +300 -0
  43. package/src/generator/registry.js +482 -0
  44. package/src/generator/runtime/app-bundle.js +456 -0
  45. package/src/generator/runtime/bundle-shared.js +166 -0
  46. package/src/generator/runtime/compile-check.js +163 -0
  47. package/src/generator/runtime/deployment.js +287 -0
  48. package/src/generator/runtime/environment.js +635 -0
  49. package/src/generator/runtime/index.js +32 -0
  50. package/src/generator/runtime/runtime-check.js +554 -0
  51. package/src/generator/runtime/shared.js +515 -0
  52. package/src/generator/runtime/smoke.js +219 -0
  53. package/src/generator/schema.js +204 -0
  54. package/src/generator/sdlc/board.js +66 -0
  55. package/src/generator/sdlc/doc-page.js +53 -0
  56. package/src/generator/sdlc/index.js +23 -0
  57. package/src/generator/sdlc/release-notes.js +62 -0
  58. package/src/generator/sdlc/traceability-matrix.js +65 -0
  59. package/src/generator/shared.js +29 -0
  60. package/src/generator/surfaces/contracts.js +146 -0
  61. package/src/generator/surfaces/databases/contract.js +40 -0
  62. package/src/generator/surfaces/databases/index.js +84 -0
  63. package/src/generator/surfaces/databases/lifecycle-shared.d.ts +1 -0
  64. package/src/generator/surfaces/databases/lifecycle-shared.js +612 -0
  65. package/src/generator/surfaces/databases/migration-plan.js +281 -0
  66. package/src/generator/surfaces/databases/postgres/capabilities.js +14 -0
  67. package/src/generator/surfaces/databases/postgres/drizzle.js +99 -0
  68. package/src/generator/surfaces/databases/postgres/index.js +9 -0
  69. package/src/generator/surfaces/databases/postgres/lifecycle.js +16 -0
  70. package/src/generator/surfaces/databases/postgres/prisma.js +159 -0
  71. package/src/generator/surfaces/databases/postgres/sql-migration.js +102 -0
  72. package/src/generator/surfaces/databases/postgres/sql-schema.js +34 -0
  73. package/src/generator/surfaces/databases/shared.d.ts +1 -0
  74. package/src/generator/surfaces/databases/shared.js +350 -0
  75. package/src/generator/surfaces/databases/snapshot.js +96 -0
  76. package/src/generator/surfaces/databases/sqlite/capabilities.js +14 -0
  77. package/src/generator/surfaces/databases/sqlite/index.js +8 -0
  78. package/src/generator/surfaces/databases/sqlite/lifecycle.js +16 -0
  79. package/src/generator/surfaces/databases/sqlite/prisma.js +143 -0
  80. package/src/generator/surfaces/databases/sqlite/sql-migration.js +65 -0
  81. package/src/generator/surfaces/databases/sqlite/sql-schema.js +27 -0
  82. package/src/generator/surfaces/index.js +25 -0
  83. package/src/generator/surfaces/native/swiftui-app.js +38 -0
  84. package/src/generator/surfaces/native/swiftui-templates/Package.swift.txt +20 -0
  85. package/src/generator/surfaces/native/swiftui-templates/README.generated.md +26 -0
  86. package/src/generator/surfaces/native/swiftui-templates/runtime/DynamicScreens.swift +682 -0
  87. package/src/generator/surfaces/native/swiftui-templates/runtime/TodoAPIClient.swift +156 -0
  88. package/src/generator/surfaces/native/swiftui-templates/runtime/TodoSwiftUIApp.swift +44 -0
  89. package/src/generator/surfaces/native/swiftui-templates/runtime/Visibility.swift +183 -0
  90. package/src/generator/surfaces/services/express.d.ts +1 -0
  91. package/src/generator/surfaces/services/express.js +766 -0
  92. package/src/generator/surfaces/services/hono.d.ts +1 -0
  93. package/src/generator/surfaces/services/hono.js +204 -0
  94. package/src/generator/surfaces/services/index.js +42 -0
  95. package/src/generator/surfaces/services/persistence-wiring.js +240 -0
  96. package/src/generator/surfaces/services/runtime-helpers.js +631 -0
  97. package/src/generator/surfaces/services/server-contract.js +80 -0
  98. package/src/generator/surfaces/services/stateless.d.ts +1 -0
  99. package/src/generator/surfaces/services/stateless.js +97 -0
  100. package/src/generator/surfaces/shared.js +64 -0
  101. package/src/generator/surfaces/web/api-client.js +1 -0
  102. package/src/generator/surfaces/web/forms.js +1 -0
  103. package/src/generator/surfaces/web/index.d.ts +2 -0
  104. package/src/generator/surfaces/web/index.js +53 -0
  105. package/src/generator/surfaces/web/react-components.js +248 -0
  106. package/src/generator/surfaces/web/react.js +538 -0
  107. package/src/generator/surfaces/web/routes.js +1 -0
  108. package/src/generator/surfaces/web/screens.js +1 -0
  109. package/src/generator/surfaces/web/shared.js +369 -0
  110. package/src/generator/surfaces/web/sveltekit-actions.js +28 -0
  111. package/src/generator/surfaces/web/sveltekit-components.js +234 -0
  112. package/src/generator/surfaces/web/sveltekit.js +426 -0
  113. package/src/generator/surfaces/web/ui-web-contract.js +65 -0
  114. package/src/generator/surfaces/web/vanilla.js +239 -0
  115. package/src/generator/verification.js +84 -0
  116. package/src/generator.js +1 -0
  117. package/src/import/core/context.js +52 -0
  118. package/src/import/core/contracts.js +23 -0
  119. package/src/import/core/registry.js +81 -0
  120. package/src/import/core/runner.js +646 -0
  121. package/src/import/core/shared.js +910 -0
  122. package/src/import/enrichers/auth-session.js +18 -0
  123. package/src/import/enrichers/django-rest.js +226 -0
  124. package/src/import/enrichers/doc-linking.js +20 -0
  125. package/src/import/enrichers/rails-controllers.js +246 -0
  126. package/src/import/enrichers/rails-models.js +130 -0
  127. package/src/import/enrichers/workflow-target-state.js +10 -0
  128. package/src/import/extractors/api/aspnet-core.js +304 -0
  129. package/src/import/extractors/api/django-routes.js +318 -0
  130. package/src/import/extractors/api/express.js +154 -0
  131. package/src/import/extractors/api/fastify.js +371 -0
  132. package/src/import/extractors/api/flutter-dio.js +135 -0
  133. package/src/import/extractors/api/generic-route-fallback.js +90 -0
  134. package/src/import/extractors/api/graphql-code-first.js +565 -0
  135. package/src/import/extractors/api/graphql-sdl.js +309 -0
  136. package/src/import/extractors/api/jaxrs.js +303 -0
  137. package/src/import/extractors/api/micronaut.js +213 -0
  138. package/src/import/extractors/api/next-route.js +50 -0
  139. package/src/import/extractors/api/next-server-action.js +51 -0
  140. package/src/import/extractors/api/nextauth.js +52 -0
  141. package/src/import/extractors/api/openapi-code.js +242 -0
  142. package/src/import/extractors/api/openapi.js +232 -0
  143. package/src/import/extractors/api/rails-routes.js +230 -0
  144. package/src/import/extractors/api/react-native-repository.js +128 -0
  145. package/src/import/extractors/api/retrofit.js +103 -0
  146. package/src/import/extractors/api/spring-web.js +372 -0
  147. package/src/import/extractors/api/swift-webapi.js +116 -0
  148. package/src/import/extractors/api/trpc.js +212 -0
  149. package/src/import/extractors/db/django-models.js +232 -0
  150. package/src/import/extractors/db/dotnet-models.js +93 -0
  151. package/src/import/extractors/db/drizzle.js +242 -0
  152. package/src/import/extractors/db/ef-core.js +221 -0
  153. package/src/import/extractors/db/flutter-entities.js +120 -0
  154. package/src/import/extractors/db/jpa.js +120 -0
  155. package/src/import/extractors/db/liquibase.js +180 -0
  156. package/src/import/extractors/db/mybatis-xml.js +145 -0
  157. package/src/import/extractors/db/prisma.js +185 -0
  158. package/src/import/extractors/db/rails-schema.js +175 -0
  159. package/src/import/extractors/db/react-native-entities.js +95 -0
  160. package/src/import/extractors/db/room.js +193 -0
  161. package/src/import/extractors/db/snapshot.js +112 -0
  162. package/src/import/extractors/db/sql.js +180 -0
  163. package/src/import/extractors/db/swiftdata.js +137 -0
  164. package/src/import/extractors/ui/android-compose.js +230 -0
  165. package/src/import/extractors/ui/backend-only.js +70 -0
  166. package/src/import/extractors/ui/blazor.js +227 -0
  167. package/src/import/extractors/ui/flutter-screens.js +152 -0
  168. package/src/import/extractors/ui/maui-xaml.js +135 -0
  169. package/src/import/extractors/ui/next-app-router.js +83 -0
  170. package/src/import/extractors/ui/next-pages-router.js +141 -0
  171. package/src/import/extractors/ui/razor-pages.js +181 -0
  172. package/src/import/extractors/ui/react-native-screens.js +166 -0
  173. package/src/import/extractors/ui/react-router.js +139 -0
  174. package/src/import/extractors/ui/sveltekit.js +123 -0
  175. package/src/import/extractors/ui/swiftui.js +193 -0
  176. package/src/import/extractors/ui/uikit.js +175 -0
  177. package/src/import/extractors/verification/generic.js +290 -0
  178. package/src/import/extractors/workflows/generic.js +137 -0
  179. package/src/import/index.js +7 -0
  180. package/src/import/provenance.js +158 -0
  181. package/src/new-project.js +2107 -0
  182. package/src/parser.js +439 -0
  183. package/src/policy/review-boundaries.js +165 -0
  184. package/src/project-config.js +535 -0
  185. package/src/proofs/backend-parity.js +19 -0
  186. package/src/proofs/contract-audit.js +220 -0
  187. package/src/proofs/ios-parity.js +7 -0
  188. package/src/proofs/issues-parity.js +10 -0
  189. package/src/proofs/web-parity.js +50 -0
  190. package/src/realization/api/build-api-realization.js +5 -0
  191. package/src/realization/api/index.js +1 -0
  192. package/src/realization/backend/build-backend-runtime-realization.js +82 -0
  193. package/src/realization/backend/index.d.ts +1 -0
  194. package/src/realization/backend/index.js +4 -0
  195. package/src/realization/db/build-db-realization.js +17 -0
  196. package/src/realization/db/index.js +3 -0
  197. package/src/realization/db/migration-plan.js +5 -0
  198. package/src/realization/db/snapshot.js +5 -0
  199. package/src/realization/ui/build-ui-shared-realization.js +305 -0
  200. package/src/realization/ui/build-web-realization.js +189 -0
  201. package/src/realization/ui/index.js +2 -0
  202. package/src/reconcile/docs.js +280 -0
  203. package/src/reconcile/index.js +3 -0
  204. package/src/reconcile/journeys.js +441 -0
  205. package/src/resolver/docs.js +1 -0
  206. package/src/resolver/enrich/acceptance-criterion.js +14 -0
  207. package/src/resolver/enrich/bug.js +12 -0
  208. package/src/resolver/enrich/component.js +2 -0
  209. package/src/resolver/enrich/index.js +1 -0
  210. package/src/resolver/enrich/pitch.js +18 -0
  211. package/src/resolver/enrich/requirement.js +20 -0
  212. package/src/resolver/enrich/task.js +16 -0
  213. package/src/resolver/expressions.js +1 -0
  214. package/src/resolver/index.js +2422 -0
  215. package/src/resolver/normalize.js +1 -0
  216. package/src/resolver.js +1 -0
  217. package/src/sdlc/adopt.js +65 -0
  218. package/src/sdlc/check.js +86 -0
  219. package/src/sdlc/dod/acceptance-criterion.js +22 -0
  220. package/src/sdlc/dod/bug.js +26 -0
  221. package/src/sdlc/dod/document.js +23 -0
  222. package/src/sdlc/dod/index.js +25 -0
  223. package/src/sdlc/dod/pitch.js +23 -0
  224. package/src/sdlc/dod/requirement.js +34 -0
  225. package/src/sdlc/dod/task.js +39 -0
  226. package/src/sdlc/explain.js +116 -0
  227. package/src/sdlc/history.js +80 -0
  228. package/src/sdlc/paths.js +11 -0
  229. package/src/sdlc/release.js +106 -0
  230. package/src/sdlc/scaffold.js +89 -0
  231. package/src/sdlc/status-filter.js +54 -0
  232. package/src/sdlc/transition.js +112 -0
  233. package/src/sdlc/transitions/acceptance-criterion.js +28 -0
  234. package/src/sdlc/transitions/bug.js +31 -0
  235. package/src/sdlc/transitions/document.js +29 -0
  236. package/src/sdlc/transitions/index.js +56 -0
  237. package/src/sdlc/transitions/pitch.js +34 -0
  238. package/src/sdlc/transitions/requirement.js +31 -0
  239. package/src/sdlc/transitions/task.js +34 -0
  240. package/src/template-trust.js +597 -0
  241. package/src/validator/expressions.js +1 -0
  242. package/src/validator/index.js +3424 -0
  243. package/src/validator/kinds.js +346 -0
  244. package/src/validator/per-kind/acceptance-criterion.js +91 -0
  245. package/src/validator/per-kind/bug.js +77 -0
  246. package/src/validator/per-kind/component.js +274 -0
  247. package/src/validator/per-kind/domain.js +205 -0
  248. package/src/validator/per-kind/pitch.js +101 -0
  249. package/src/validator/per-kind/requirement.js +75 -0
  250. package/src/validator/per-kind/task.js +96 -0
  251. package/src/validator/registry.js +1 -0
  252. package/src/validator/utils.js +12 -0
  253. package/src/validator.js +1 -0
  254. package/src/workflows.js +7597 -0
  255. package/src/workspace-docs.js +265 -0
  256. package/template-helpers/react.js +5 -0
  257. package/template-helpers/sveltekit.js +5 -0
@@ -0,0 +1,39 @@
1
+ function stableSortedComponents(graph) {
2
+ return [...(graph?.byKind?.component || [])].sort((a, b) => a.id.localeCompare(b.id));
3
+ }
4
+
5
+ function componentContract(component) {
6
+ return component.componentContract || {
7
+ type: "component_contract",
8
+ id: component.id,
9
+ name: component.name || component.id,
10
+ description: component.description || null,
11
+ category: component.category || null,
12
+ version: component.version || null,
13
+ status: component.status || null,
14
+ props: component.props || [],
15
+ events: component.events || [],
16
+ slots: component.slots || [],
17
+ behavior: component.behavior || [],
18
+ behaviors: component.behaviors || [],
19
+ patterns: component.patterns || [],
20
+ regions: component.regions || [],
21
+ approvals: component.approvals || [],
22
+ lookups: component.lookups || [],
23
+ dependencies: component.dependencies || []
24
+ };
25
+ }
26
+
27
+ export function generateUiComponentContract(graph, options = {}) {
28
+ if (options.componentId) {
29
+ const component = (graph?.byKind?.component || []).find((entry) => entry.id === options.componentId);
30
+ if (!component) {
31
+ throw new Error(`No component found with id '${options.componentId}'`);
32
+ }
33
+ return componentContract(component);
34
+ }
35
+
36
+ return Object.fromEntries(
37
+ stableSortedComponents(graph).map((component) => [component.id, componentContract(component)])
38
+ );
39
+ }
@@ -0,0 +1,291 @@
1
+ import {
2
+ buildMaintainedOutputs,
3
+ buildMaintainedBoundaryArtifact,
4
+ buildMaintainedSeams,
5
+ buildDefaultWriteScope,
6
+ buildMaintainedWriteScope,
7
+ maintainedProofMetadata,
8
+ relatedCapabilitiesForEntity,
9
+ relatedCapabilitiesForProjection,
10
+ relatedEntitiesForProjection,
11
+ recommendedVerificationTargets,
12
+ stableSortedStrings,
13
+ summarizeById,
14
+ summarizeDocsByIds,
15
+ summarizeStatementsByIds,
16
+ verificationIdsForTarget
17
+ } from "./shared.js";
18
+ import {
19
+ defaultOwnershipBoundary,
20
+ ownershipBoundaryForMaintainedSurface,
21
+ reviewBoundaryForJourneyDoc,
22
+ reviewBoundaryForWorkflowDoc
23
+ } from "../../policy/review-boundaries.js";
24
+
25
+ function apiBundle(graph) {
26
+ const capabilities = stableSortedStrings((graph.byKind.capability || []).map((item) => item.id));
27
+ const projections = stableSortedStrings(
28
+ (graph.byKind.projection || [])
29
+ .filter((projection) => (projection.http || []).length > 0)
30
+ .map((projection) => projection.id)
31
+ );
32
+ const shapes = stableSortedStrings(capabilities.flatMap((capabilityId) => {
33
+ const capability = (graph.byKind.capability || []).find((item) => item.id === capabilityId);
34
+ return [...(capability?.input || []).map((item) => item.id), ...(capability?.output || []).map((item) => item.id)];
35
+ }));
36
+ const rules = stableSortedStrings(capabilities.flatMap((capabilityId) => {
37
+ return (graph.byKind.rule || [])
38
+ .filter((rule) => (rule.appliesTo || []).some((target) => target.id === capabilityId))
39
+ .map((rule) => rule.id);
40
+ }));
41
+
42
+ return {
43
+ type: "context_bundle",
44
+ version: 1,
45
+ task: "api",
46
+ summary: {
47
+ focus: "API-facing capability, shape, and projection context",
48
+ capabilityCount: capabilities.length,
49
+ projectionCount: projections.length
50
+ },
51
+ included_surfaces: {
52
+ capabilities: summarizeStatementsByIds(graph, capabilities),
53
+ shapes: summarizeStatementsByIds(graph, shapes),
54
+ projections: summarizeStatementsByIds(graph, projections),
55
+ rules: summarizeStatementsByIds(graph, rules)
56
+ },
57
+ dependencies: {
58
+ capabilities,
59
+ shapes,
60
+ projections,
61
+ rules
62
+ },
63
+ verification: summarizeStatementsByIds(graph, verificationIdsForTarget(graph, [...capabilities, ...projections])),
64
+ verification_targets: recommendedVerificationTargets(graph, [...capabilities, ...projections], {
65
+ rationale: "API bundle should point agents at API-facing generated checks instead of full workspace verification."
66
+ }),
67
+ write_scope: buildDefaultWriteScope(),
68
+ ownership_boundary: defaultOwnershipBoundary(),
69
+ review_boundaries: {
70
+ capabilities: capabilities.map((id) => ({ id, review_boundary: summarizeById(graph, id)?.reviewBoundary || null })),
71
+ projections: projections.map((id) => ({ id, review_boundary: summarizeById(graph, id)?.reviewBoundary || null }))
72
+ }
73
+ };
74
+ }
75
+
76
+ function uiBundle(graph) {
77
+ const projections = stableSortedStrings(
78
+ (graph.byKind.projection || [])
79
+ .filter((projection) => (projection.uiScreens || []).length > 0 || (projection.uiWeb || []).length > 0)
80
+ .map((projection) => projection.id)
81
+ );
82
+ const capabilities = stableSortedStrings(projections.flatMap((projectionId) => {
83
+ const projection = (graph.byKind.projection || []).find((item) => item.id === projectionId);
84
+ return relatedCapabilitiesForProjection(projection);
85
+ }));
86
+ const workflows = stableSortedStrings(
87
+ (graph.docs || [])
88
+ .filter((doc) => doc.kind === "workflow" && (doc.relatedProjections || []).some((id) => projections.includes(id)))
89
+ .map((doc) => doc.id)
90
+ );
91
+ const journeys = stableSortedStrings(
92
+ (graph.docs || [])
93
+ .filter((doc) => doc.kind === "journey" && (doc.relatedProjections || []).some((id) => projections.includes(id)))
94
+ .map((doc) => doc.id)
95
+ );
96
+ const rules = stableSortedStrings(capabilities.flatMap((capabilityId) => {
97
+ return (graph.byKind.rule || [])
98
+ .filter((rule) => (rule.appliesTo || []).some((target) => target.id === capabilityId))
99
+ .map((rule) => rule.id);
100
+ }));
101
+
102
+ return {
103
+ type: "context_bundle",
104
+ version: 1,
105
+ task: "ui",
106
+ summary: {
107
+ focus: "UI workflows, journeys, projections, and action semantics",
108
+ projectionCount: projections.length,
109
+ workflowCount: workflows.length
110
+ },
111
+ included_surfaces: {
112
+ projections: summarizeStatementsByIds(graph, projections),
113
+ capabilities: summarizeStatementsByIds(graph, capabilities),
114
+ workflows: summarizeDocsByIds(graph, workflows),
115
+ journeys: summarizeDocsByIds(graph, journeys),
116
+ rules: summarizeStatementsByIds(graph, rules)
117
+ },
118
+ dependencies: {
119
+ projections,
120
+ capabilities,
121
+ workflows,
122
+ journeys,
123
+ rules
124
+ },
125
+ verification: summarizeStatementsByIds(graph, verificationIdsForTarget(graph, [...capabilities, ...projections, ...workflows, ...journeys])),
126
+ verification_targets: recommendedVerificationTargets(graph, [...capabilities, ...projections, ...workflows, ...journeys], {
127
+ rationale: "UI bundle should target workflow and UI verification linked to the selected projections."
128
+ }),
129
+ write_scope: buildDefaultWriteScope(),
130
+ ownership_boundary: defaultOwnershipBoundary(),
131
+ review_boundaries: {
132
+ projections: projections.map((id) => ({ id, review_boundary: summarizeById(graph, id)?.reviewBoundary || null })),
133
+ workflows: workflows.map((id) => ({ id, review_boundary: reviewBoundaryForWorkflowDoc((graph.docs || []).find((doc) => doc.id === id)) })),
134
+ journeys: journeys.map((id) => ({ id, review_boundary: reviewBoundaryForJourneyDoc((graph.docs || []).find((doc) => doc.id === id)) }))
135
+ }
136
+ };
137
+ }
138
+
139
+ function dbBundle(graph) {
140
+ const projections = stableSortedStrings(
141
+ (graph.byKind.projection || [])
142
+ .filter((projection) => (projection.dbTables || []).length > 0 || (projection.dbColumns || []).length > 0)
143
+ .map((projection) => projection.id)
144
+ );
145
+ const entities = stableSortedStrings(projections.flatMap((projectionId) => {
146
+ const projection = (graph.byKind.projection || []).find((item) => item.id === projectionId);
147
+ return relatedEntitiesForProjection(projection);
148
+ }));
149
+ const capabilities = stableSortedStrings(entities.flatMap((entityId) => relatedCapabilitiesForEntity(graph, entityId)));
150
+ const enums = stableSortedStrings((graph.byKind.enum || []).map((item) => item.id));
151
+
152
+ return {
153
+ type: "context_bundle",
154
+ version: 1,
155
+ task: "db",
156
+ summary: {
157
+ focus: "DB schema, relations, and migration-sensitive semantics",
158
+ projectionCount: projections.length,
159
+ entityCount: entities.length
160
+ },
161
+ included_surfaces: {
162
+ projections: summarizeStatementsByIds(graph, projections),
163
+ entities: summarizeStatementsByIds(graph, entities),
164
+ enums: summarizeStatementsByIds(graph, enums),
165
+ capabilities: summarizeStatementsByIds(graph, capabilities)
166
+ },
167
+ dependencies: {
168
+ projections,
169
+ entities,
170
+ enums,
171
+ capabilities
172
+ },
173
+ verification: summarizeStatementsByIds(graph, verificationIdsForTarget(graph, [...projections, ...entities])),
174
+ verification_targets: recommendedVerificationTargets(graph, [...projections, ...entities], {
175
+ rationale: "DB bundle should target schema and runtime checks tied to affected entities and projections."
176
+ }),
177
+ write_scope: buildDefaultWriteScope(),
178
+ ownership_boundary: defaultOwnershipBoundary(),
179
+ review_boundaries: {
180
+ projections: projections.map((id) => ({ id, review_boundary: summarizeById(graph, id)?.reviewBoundary || null })),
181
+ entities: entities.map((id) => ({ id, review_boundary: { automation_class: "review_required", reasons: ["schema_surface"] } }))
182
+ }
183
+ };
184
+ }
185
+
186
+ function maintainedAppBundle(graph) {
187
+ const proofStories = maintainedProofMetadata(graph);
188
+ const projections = stableSortedStrings((graph.byKind.projection || []).map((item) => item.id));
189
+ const journeys = stableSortedStrings((graph.docs || []).filter((doc) => doc.kind === "journey").map((doc) => doc.id));
190
+ const verifications = stableSortedStrings((graph.byKind.verification || []).map((item) => item.id));
191
+ const maintainedFiles = stableSortedStrings(proofStories.flatMap((item) => item.maintainedFiles || []));
192
+ const emittedDependencies = stableSortedStrings(proofStories.flatMap((item) => item.emittedDependencies || []));
193
+ const humanOwnedSeams = stableSortedStrings(proofStories.flatMap((item) => item.humanOwnedSeams || []));
194
+ const verificationTargets = recommendedVerificationTargets(graph, [...verifications, ...emittedDependencies], {
195
+ includeMaintainedApp: true,
196
+ rationale: "Maintained-app bundle should point agents at both generated verification and maintained proof gates."
197
+ });
198
+ const maintainedBoundaryArtifact = buildMaintainedBoundaryArtifact({
199
+ proofStories,
200
+ verificationTargets,
201
+ graph
202
+ });
203
+ const outputs = maintainedBoundaryArtifact?.outputs || [];
204
+ const seams = maintainedBoundaryArtifact?.seams || [];
205
+
206
+ return {
207
+ type: "context_bundle",
208
+ version: 1,
209
+ task: "maintained-app",
210
+ summary: {
211
+ focus: "Maintained-app proof boundaries and human-owned change surfaces",
212
+ accepted_change_count: proofStories.filter((item) => item.classification === "accepted_change").length,
213
+ guarded_change_count: proofStories.filter((item) => item.classification === "guarded_manual_decision").length,
214
+ no_go_count: proofStories.filter((item) => item.classification === "no_go").length
215
+ },
216
+ included_surfaces: {
217
+ projections: summarizeStatementsByIds(graph, projections),
218
+ journeys: summarizeDocsByIds(graph, journeys),
219
+ maintained_files_in_scope: maintainedFiles,
220
+ emitted_artifact_dependencies: emittedDependencies,
221
+ human_owned_seams: humanOwnedSeams,
222
+ outputs,
223
+ seams,
224
+ proof_stories: proofStories.map((item) => ({
225
+ classification: item.classification,
226
+ relativePath: item.relativePath,
227
+ maintained_files: item.maintainedFiles || [],
228
+ emitted_dependencies: item.emittedDependencies || [],
229
+ human_owned_seams: item.humanOwnedSeams || [],
230
+ review_boundary: item.reviewBoundary
231
+ }))
232
+ },
233
+ dependencies: {
234
+ projections,
235
+ journeys,
236
+ verifications,
237
+ maintained_files: maintainedFiles,
238
+ emitted_dependencies: emittedDependencies
239
+ },
240
+ verification: summarizeStatementsByIds(graph, verifications),
241
+ verification_targets: verificationTargets,
242
+ write_scope: buildMaintainedWriteScope(graph, maintainedFiles),
243
+ ownership_boundary: ownershipBoundaryForMaintainedSurface(),
244
+ maintained_boundary: maintainedBoundaryArtifact,
245
+ review_boundaries: {
246
+ maintained_surfaces: [
247
+ {
248
+ class: "accepted_change",
249
+ description: "Maintained surface should mirror emitted Topogram artifacts directly.",
250
+ review_boundary: proofStories.find((item) => item.classification === "accepted_change")?.reviewBoundary || null
251
+ },
252
+ {
253
+ class: "guarded_manual_decision",
254
+ description: "Topogram identifies the affected surface, but product or UX treatment remains human-owned.",
255
+ review_boundary: proofStories.find((item) => item.classification === "guarded_manual_decision")?.reviewBoundary || null
256
+ },
257
+ {
258
+ class: "no_go",
259
+ description: "Unsafe semantic drift or relation changes should not be auto-applied.",
260
+ review_boundary: proofStories.find((item) => item.classification === "no_go")?.reviewBoundary || null
261
+ }
262
+ ],
263
+ human_owned_seams: humanOwnedSeams,
264
+ independent_review_artifacts: proofStories
265
+ .filter((item) => item.classification === "independent_review")
266
+ .map((item) => item.relativePath)
267
+ }
268
+ };
269
+ }
270
+
271
+ export function generateContextBundle(graph, options = {}) {
272
+ const task = options.taskId;
273
+ if (!task) {
274
+ throw new Error("context-bundle requires --task <api|ui|db|maintained-app>");
275
+ }
276
+
277
+ if (task === "api") {
278
+ return apiBundle(graph);
279
+ }
280
+ if (task === "ui") {
281
+ return uiBundle(graph);
282
+ }
283
+ if (task === "db") {
284
+ return dbBundle(graph);
285
+ }
286
+ if (task === "maintained-app") {
287
+ return maintainedAppBundle(graph);
288
+ }
289
+
290
+ throw new Error(`Unsupported context bundle task '${task}'`);
291
+ }
@@ -0,0 +1,256 @@
1
+ import { parsePath } from "../../parser.js";
2
+ import { resolveWorkspace } from "../../resolver.js";
3
+ import {
4
+ buildMaintainedOutputs,
5
+ buildMaintainedSeams,
6
+ maintainedProofMetadata,
7
+ relatedCapabilitiesForEntity,
8
+ relatedProjectionsForCapability,
9
+ relatedProjectionsForComponent,
10
+ relatedProjectionsForEntity,
11
+ stableSortedStrings,
12
+ summarizeById,
13
+ summarizeDoc,
14
+ summarizeStatement
15
+ } from "./shared.js";
16
+ import { defaultOwnershipBoundary } from "../../policy/review-boundaries.js";
17
+
18
+ function normalizeTargetMap(graph, kind) {
19
+ if (kind === "workflow" || kind === "journey") {
20
+ const docs = (graph.docs || []).filter((doc) => doc.kind === kind);
21
+ return new Map(docs.map((doc) => [doc.id, summarizeDoc(doc)]));
22
+ }
23
+
24
+ return new Map(((graph.byKind[kind] || []).map((statement) => [statement.id, summarizeStatement(statement)])));
25
+ }
26
+
27
+ function diffMaps(currentMap, baselineMap) {
28
+ const ids = stableSortedStrings([...currentMap.keys(), ...baselineMap.keys()]);
29
+ const output = [];
30
+
31
+ for (const id of ids) {
32
+ const current = currentMap.get(id);
33
+ const baseline = baselineMap.get(id);
34
+ if (!baseline && current) {
35
+ output.push({
36
+ id,
37
+ classification: "additive",
38
+ current
39
+ });
40
+ continue;
41
+ }
42
+ if (baseline && !current) {
43
+ output.push({
44
+ id,
45
+ classification: "removed",
46
+ baseline
47
+ });
48
+ continue;
49
+ }
50
+
51
+ const currentJson = JSON.stringify(current);
52
+ const baselineJson = JSON.stringify(baseline);
53
+ if (currentJson === baselineJson) {
54
+ continue;
55
+ }
56
+
57
+ const currentBoundary = current?.reviewBoundary || current?.review_boundary || null;
58
+ const baselineBoundary = baseline?.reviewBoundary || baseline?.review_boundary || null;
59
+ const classification =
60
+ JSON.stringify(currentBoundary) !== JSON.stringify(baselineBoundary) ? "review_boundary_changed" : "modified";
61
+
62
+ output.push({
63
+ id,
64
+ classification,
65
+ current,
66
+ baseline
67
+ });
68
+ }
69
+
70
+ return output;
71
+ }
72
+
73
+ function changedIdsForDiffSections(diff) {
74
+ const sectionNames = [
75
+ "entities",
76
+ "enums",
77
+ "shapes",
78
+ "capabilities",
79
+ "rules",
80
+ "workflows",
81
+ "projections",
82
+ "components",
83
+ "journeys",
84
+ "verifications",
85
+ "domains",
86
+ "pitches",
87
+ "requirements",
88
+ "acceptance_criteria",
89
+ "tasks",
90
+ "bugs"
91
+ ];
92
+ const ids = [];
93
+ for (const section of sectionNames) {
94
+ ids.push(...(diff[section] || []).map((entry) => entry.id));
95
+ }
96
+ return stableSortedStrings(ids);
97
+ }
98
+
99
+ function collectAffectedProjectionIds(graph, baselineGraph, diff) {
100
+ const changedCapabilities = stableSortedStrings((diff.capabilities || []).map((entry) => entry.id));
101
+ const changedEntities = stableSortedStrings((diff.entities || []).map((entry) => entry.id));
102
+ const changedProjections = stableSortedStrings((diff.projections || []).map((entry) => entry.id));
103
+ const changedComponentProjections = stableSortedStrings((diff.components || []).flatMap((entry) => {
104
+ if (entry.classification === "additive") {
105
+ return relatedProjectionsForComponent(graph, entry.id);
106
+ }
107
+ if (entry.classification === "removed") {
108
+ return relatedProjectionsForComponent(baselineGraph, entry.id);
109
+ }
110
+ return [
111
+ ...relatedProjectionsForComponent(graph, entry.id),
112
+ ...relatedProjectionsForComponent(baselineGraph, entry.id)
113
+ ];
114
+ }));
115
+
116
+ return stableSortedStrings([
117
+ ...changedProjections,
118
+ ...changedCapabilities.flatMap((id) => relatedProjectionsForCapability(graph, id)),
119
+ ...changedEntities.flatMap((id) => relatedProjectionsForEntity(graph, id)),
120
+ ...changedComponentProjections
121
+ ]);
122
+ }
123
+
124
+ function collectAffectedCapabilityIds(graph, diff) {
125
+ const changedCapabilities = stableSortedStrings((diff.capabilities || []).map((entry) => entry.id));
126
+ const changedEntities = stableSortedStrings((diff.entities || []).map((entry) => entry.id));
127
+ return stableSortedStrings([
128
+ ...changedCapabilities,
129
+ ...changedEntities.flatMap((id) => relatedCapabilitiesForEntity(graph, id))
130
+ ]);
131
+ }
132
+
133
+ function collectAffectedVerificationIds(graph, diff) {
134
+ const changedIds = changedIdsForDiffSections(diff);
135
+ const explicitVerificationIds = stableSortedStrings((diff.verifications || []).map((entry) => entry.id));
136
+ const affected = (graph.byKind.verification || [])
137
+ .filter((verification) => (verification.validates || []).some((target) => changedIds.includes(target.id)))
138
+ .map((verification) => verification.id);
139
+ return stableSortedStrings([...explicitVerificationIds, ...affected]);
140
+ }
141
+
142
+ function reviewBoundaryChanges(diff) {
143
+ const sectionNames = [
144
+ "entities",
145
+ "capabilities",
146
+ "workflows",
147
+ "projections",
148
+ "journeys"
149
+ ];
150
+ return sectionNames.flatMap((section) =>
151
+ (diff[section] || [])
152
+ .filter((entry) => entry.classification === "review_boundary_changed")
153
+ .map((entry) => ({
154
+ kind: section.slice(0, -1),
155
+ id: entry.id,
156
+ baseline: entry.baseline?.reviewBoundary || entry.baseline?.review_boundary || null,
157
+ current: entry.current?.reviewBoundary || entry.current?.review_boundary || null
158
+ }))
159
+ );
160
+ }
161
+
162
+ function loadBaselineGraph(fromTopogramPath) {
163
+ if (!fromTopogramPath) {
164
+ throw new Error("context-diff requires --from-topogram <path>");
165
+ }
166
+
167
+ const parsed = parsePath(fromTopogramPath);
168
+ const resolved = resolveWorkspace(parsed);
169
+ if (!resolved.ok) {
170
+ throw Object.assign(new Error("Failed to resolve baseline Topogram"), { validation: resolved.validation });
171
+ }
172
+
173
+ return resolved.graph;
174
+ }
175
+
176
+ export function generateContextDiff(graph, options = {}) {
177
+ const baselineGraph = loadBaselineGraph(options.fromTopogramPath);
178
+ const diff = {
179
+ entities: diffMaps(normalizeTargetMap(graph, "entity"), normalizeTargetMap(baselineGraph, "entity")),
180
+ enums: diffMaps(normalizeTargetMap(graph, "enum"), normalizeTargetMap(baselineGraph, "enum")),
181
+ shapes: diffMaps(normalizeTargetMap(graph, "shape"), normalizeTargetMap(baselineGraph, "shape")),
182
+ capabilities: diffMaps(normalizeTargetMap(graph, "capability"), normalizeTargetMap(baselineGraph, "capability")),
183
+ rules: diffMaps(normalizeTargetMap(graph, "rule"), normalizeTargetMap(baselineGraph, "rule")),
184
+ workflows: diffMaps(normalizeTargetMap(graph, "workflow"), normalizeTargetMap(baselineGraph, "workflow")),
185
+ projections: diffMaps(normalizeTargetMap(graph, "projection"), normalizeTargetMap(baselineGraph, "projection")),
186
+ components: diffMaps(normalizeTargetMap(graph, "component"), normalizeTargetMap(baselineGraph, "component")),
187
+ journeys: diffMaps(normalizeTargetMap(graph, "journey"), normalizeTargetMap(baselineGraph, "journey")),
188
+ verifications: diffMaps(normalizeTargetMap(graph, "verification"), normalizeTargetMap(baselineGraph, "verification")),
189
+ domains: diffMaps(normalizeTargetMap(graph, "domain"), normalizeTargetMap(baselineGraph, "domain")),
190
+ pitches: diffMaps(normalizeTargetMap(graph, "pitch"), normalizeTargetMap(baselineGraph, "pitch")),
191
+ requirements: diffMaps(normalizeTargetMap(graph, "requirement"), normalizeTargetMap(baselineGraph, "requirement")),
192
+ acceptance_criteria: diffMaps(
193
+ normalizeTargetMap(graph, "acceptance_criterion"),
194
+ normalizeTargetMap(baselineGraph, "acceptance_criterion")
195
+ ),
196
+ tasks: diffMaps(normalizeTargetMap(graph, "task"), normalizeTargetMap(baselineGraph, "task")),
197
+ bugs: diffMaps(normalizeTargetMap(graph, "bug"), normalizeTargetMap(baselineGraph, "bug"))
198
+ };
199
+ const sdlcChanges = {
200
+ pitches: diff.pitches || [],
201
+ requirements: diff.requirements || [],
202
+ acceptance_criteria: diff.acceptance_criteria || [],
203
+ tasks: diff.tasks || [],
204
+ bugs: diff.bugs || []
205
+ };
206
+ const affectedCapabilities = collectAffectedCapabilityIds(graph, diff);
207
+ const affectedProjections = collectAffectedProjectionIds(graph, baselineGraph, diff);
208
+ const affectedVerifications = collectAffectedVerificationIds(graph, diff);
209
+ const changedSemanticIds = changedIdsForDiffSections(diff);
210
+ const affectedMaintainedStories = maintainedProofMetadata(graph).filter((item) => {
211
+ const emittedDependencies = item.emittedDependencies || [];
212
+ return emittedDependencies.includes("maintained-proof-package") || emittedDependencies.some((dependency) => changedSemanticIds.includes(dependency));
213
+ });
214
+ const affectedMaintainedSeams = buildMaintainedSeams(affectedMaintainedStories);
215
+ const affectedMaintainedOutputs = buildMaintainedOutputs({
216
+ seams: affectedMaintainedSeams,
217
+ proofStories: affectedMaintainedStories,
218
+ ownershipBoundary: defaultOwnershipBoundary(),
219
+ graph
220
+ });
221
+ const reviewBoundaryChangeItems = reviewBoundaryChanges(diff);
222
+
223
+ return {
224
+ type: "context_diff",
225
+ version: 1,
226
+ current_root: graph.root,
227
+ baseline_root: baselineGraph.root,
228
+ ownership_boundary: defaultOwnershipBoundary(),
229
+ ...diff,
230
+ affected_generated_surfaces: {
231
+ capabilities: affectedCapabilities.map((id) => summarizeById(graph, id)).filter(Boolean),
232
+ projections: affectedProjections.map((id) => summarizeById(graph, id) || summarizeById(baselineGraph, id)).filter(Boolean),
233
+ workflows: stableSortedStrings((diff.workflows || []).map((entry) => entry.id)).map((id) => summarizeById(graph, id) || summarizeById(baselineGraph, id)).filter(Boolean),
234
+ journeys: stableSortedStrings((diff.journeys || []).map((entry) => entry.id)).map((id) => summarizeById(graph, id) || summarizeById(baselineGraph, id)).filter(Boolean)
235
+ },
236
+ affected_maintained_surfaces: {
237
+ ownership_interpretation: {
238
+ generated_only_impact: affectedMaintainedStories.length === 0,
239
+ maintained_code_impact: affectedMaintainedStories.length > 0,
240
+ human_review_required_impact: affectedMaintainedStories.some((item) => item.reviewBoundary?.automation_class !== "safe")
241
+ },
242
+ maintained_files_in_scope: stableSortedStrings(affectedMaintainedStories.flatMap((item) => item.maintainedFiles || [])),
243
+ outputs: affectedMaintainedOutputs,
244
+ affected_seams: affectedMaintainedSeams,
245
+ proof_stories: affectedMaintainedStories.map((item) => ({
246
+ classification: item.classification,
247
+ relativePath: item.relativePath,
248
+ maintained_files: item.maintainedFiles || [],
249
+ review_boundary: item.reviewBoundary
250
+ }))
251
+ },
252
+ affected_verifications: affectedVerifications.map((id) => summarizeById(graph, id) || summarizeById(baselineGraph, id)).filter(Boolean),
253
+ review_boundary_changes: reviewBoundaryChangeItems,
254
+ sdlc: sdlcChanges
255
+ };
256
+ }