@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,182 @@
1
+ import {
2
+ maintainedProofMetadata,
3
+ graphCounts,
4
+ relatedJourneysForCapability,
5
+ relatedProjectionsForCapability,
6
+ relatedWorkflowDocsForCapability,
7
+ summarizeById,
8
+ summarizeProjection,
9
+ summarizeStatement,
10
+ verificationIdsForTarget,
11
+ workspaceInventory
12
+ } from "./shared.js";
13
+ import {
14
+ defaultOwnershipBoundary,
15
+ reviewBoundaryForEntity,
16
+ reviewBoundaryForJourneyDoc,
17
+ reviewBoundaryForWorkflowDoc
18
+ } from "../../policy/review-boundaries.js";
19
+
20
+ function workspaceDigest(graph) {
21
+ const inventory = workspaceInventory(graph);
22
+
23
+ return {
24
+ type: "context_digest",
25
+ version: 1,
26
+ focus: {
27
+ kind: "workspace",
28
+ id: "workspace"
29
+ },
30
+ workspace: {
31
+ root: graph.root,
32
+ counts: graphCounts(graph)
33
+ },
34
+ inventory,
35
+ review_boundary: {
36
+ automation_class: "manual_decision",
37
+ reasons: ["workspace_requires_scoped_review"]
38
+ },
39
+ ownership_boundary: defaultOwnershipBoundary(),
40
+ maintained_boundary_pointer: "maintained-boundary.context.json",
41
+ pointers: {
42
+ capabilities: inventory.capabilities.map((id) => `capabilities/${id}.context-digest.json`),
43
+ workflows: inventory.workflows.map((id) => `workflows/${id}.context-digest.json`),
44
+ entities: inventory.entities.map((id) => `entities/${id}.context-digest.json`),
45
+ projections: inventory.projections.map((id) => `projections/${id}.context-digest.json`),
46
+ journeys: inventory.journeys.map((id) => `journeys/${id}.context-digest.json`),
47
+ maintained_boundary: "maintained-boundary.context.json"
48
+ }
49
+ };
50
+ }
51
+
52
+ function capabilityDigest(graph, capability) {
53
+ const projections = relatedProjectionsForCapability(graph, capability.id);
54
+ const journeys = relatedJourneysForCapability(graph, capability.id).map((doc) => doc.id).sort();
55
+ const workflows = relatedWorkflowDocsForCapability(graph, capability.id).map((doc) => doc.id).sort();
56
+
57
+ return {
58
+ type: "context_digest",
59
+ version: 1,
60
+ focus: {
61
+ kind: "capability",
62
+ id: capability.id
63
+ },
64
+ summary: summarizeStatement(capability),
65
+ dependencies: {
66
+ shapes: [...new Set([...(capability.input || []).map((item) => item.id), ...(capability.output || []).map((item) => item.id)])].sort(),
67
+ entities: [...new Set([
68
+ ...(capability.reads || []).map((item) => item.id),
69
+ ...(capability.creates || []).map((item) => item.id),
70
+ ...(capability.updates || []).map((item) => item.id),
71
+ ...(capability.deletes || []).map((item) => item.id)
72
+ ])].sort()
73
+ },
74
+ journeys,
75
+ workflows,
76
+ projections,
77
+ verifications: verificationIdsForTarget(graph, [capability.id, ...projections]),
78
+ review_boundary: capability.reviewBoundary,
79
+ ownership_boundary: defaultOwnershipBoundary()
80
+ };
81
+ }
82
+
83
+ function workflowDigest(graph, workflow) {
84
+ return {
85
+ type: "context_digest",
86
+ version: 1,
87
+ focus: {
88
+ kind: "workflow",
89
+ id: workflow.id
90
+ },
91
+ summary: summarizeById(graph, workflow.id),
92
+ dependencies: {
93
+ capabilities: [...(workflow.relatedCapabilities || [])].sort(),
94
+ projections: [...(workflow.relatedProjections || [])].sort()
95
+ },
96
+ verifications: verificationIdsForTarget(graph, [workflow.id, ...(workflow.relatedCapabilities || [])]),
97
+ review_boundary: reviewBoundaryForWorkflowDoc(workflow),
98
+ ownership_boundary: defaultOwnershipBoundary()
99
+ };
100
+ }
101
+
102
+ function entityDigest(graph, entity) {
103
+ return {
104
+ type: "context_digest",
105
+ version: 1,
106
+ focus: {
107
+ kind: "entity",
108
+ id: entity.id
109
+ },
110
+ summary: summarizeStatement(entity),
111
+ verifications: verificationIdsForTarget(graph, [entity.id]),
112
+ review_boundary: reviewBoundaryForEntity(entity),
113
+ ownership_boundary: defaultOwnershipBoundary()
114
+ };
115
+ }
116
+
117
+ function projectionDigest(graph, projection) {
118
+ return {
119
+ type: "context_digest",
120
+ version: 1,
121
+ focus: {
122
+ kind: "projection",
123
+ id: projection.id
124
+ },
125
+ summary: summarizeProjection(projection),
126
+ verifications: verificationIdsForTarget(graph, [projection.id, ...projection.realizes.map((item) => item.id)]),
127
+ review_boundary: projection.reviewBoundary,
128
+ ownership_boundary: defaultOwnershipBoundary()
129
+ };
130
+ }
131
+
132
+ function journeyDigest(graph, journey) {
133
+ return {
134
+ type: "context_digest",
135
+ version: 1,
136
+ focus: {
137
+ kind: "journey",
138
+ id: journey.id
139
+ },
140
+ summary: summarizeById(graph, journey.id),
141
+ verifications: verificationIdsForTarget(graph, [journey.id, ...(journey.relatedCapabilities || [])]),
142
+ review_boundary: reviewBoundaryForJourneyDoc(journey),
143
+ ownership_boundary: defaultOwnershipBoundary()
144
+ };
145
+ }
146
+
147
+ export function generateContextDigest(graph) {
148
+ const files = {
149
+ "workspace.context-digest.json": workspaceDigest(graph),
150
+ "maintained-boundary.context.json": {
151
+ type: "maintained_boundary",
152
+ version: 1,
153
+ summary: {
154
+ focus: "Machine-readable maintained-app ownership and change boundary surface",
155
+ story_count: maintainedProofMetadata(graph).length
156
+ },
157
+ stories: maintainedProofMetadata(graph)
158
+ }
159
+ };
160
+
161
+ for (const capability of (graph.byKind.capability || []).slice().sort((a, b) => a.id.localeCompare(b.id))) {
162
+ files[`capabilities/${capability.id}.context-digest.json`] = capabilityDigest(graph, capability);
163
+ }
164
+
165
+ for (const workflow of (graph.docs || []).filter((doc) => doc.kind === "workflow").sort((a, b) => a.id.localeCompare(b.id))) {
166
+ files[`workflows/${workflow.id}.context-digest.json`] = workflowDigest(graph, workflow);
167
+ }
168
+
169
+ for (const entity of (graph.byKind.entity || []).slice().sort((a, b) => a.id.localeCompare(b.id))) {
170
+ files[`entities/${entity.id}.context-digest.json`] = entityDigest(graph, entity);
171
+ }
172
+
173
+ for (const projection of (graph.byKind.projection || []).slice().sort((a, b) => a.id.localeCompare(b.id))) {
174
+ files[`projections/${projection.id}.context-digest.json`] = projectionDigest(graph, projection);
175
+ }
176
+
177
+ for (const journey of (graph.docs || []).filter((doc) => doc.kind === "journey").sort((a, b) => a.id.localeCompare(b.id))) {
178
+ files[`journeys/${journey.id}.context-digest.json`] = journeyDigest(graph, journey);
179
+ }
180
+
181
+ return files;
182
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ domainById,
3
+ relatedCapabilitiesForDomain,
4
+ relatedEntitiesForDomain,
5
+ relatedProjectionsForDomain,
6
+ relatedRulesForDomain,
7
+ relatedVerificationsForDomain,
8
+ stableSortedStrings,
9
+ summarizeDomain
10
+ } from "./shared.js";
11
+
12
+ function platformsFromProjections(projections) {
13
+ const platforms = new Set();
14
+ for (const projection of projections) {
15
+ if (projection?.platform) {
16
+ platforms.add(projection.platform);
17
+ }
18
+ }
19
+ return [...platforms].sort();
20
+ }
21
+
22
+ export function generateDomainCoverage(graph, options = {}) {
23
+ if (!options.domainId) {
24
+ throw new Error("generateDomainCoverage requires options.domainId");
25
+ }
26
+ const domain = domainById(graph, options.domainId);
27
+ if (!domain) {
28
+ throw new Error(`No domain found with id '${options.domainId}'`);
29
+ }
30
+ const capabilities = relatedCapabilitiesForDomain(graph, options.domainId);
31
+ const entities = relatedEntitiesForDomain(graph, options.domainId);
32
+ const rules = relatedRulesForDomain(graph, options.domainId);
33
+ const verifications = relatedVerificationsForDomain(graph, options.domainId);
34
+ const projectionIds = relatedProjectionsForDomain(graph, options.domainId);
35
+ const projectionsByCapability = {};
36
+ const projectionStatements = (graph?.byKind?.projection || []).filter((projection) =>
37
+ projectionIds.includes(projection.id)
38
+ );
39
+
40
+ for (const capabilityId of capabilities) {
41
+ projectionsByCapability[capabilityId] = stableSortedStrings(
42
+ projectionStatements
43
+ .filter((projection) => (projection.realizes || []).some((entry) => entry.id === capabilityId))
44
+ .map((projection) => projection.id)
45
+ );
46
+ }
47
+
48
+ const platforms = platformsFromProjections(projectionStatements);
49
+ const matrix = {};
50
+ for (const capabilityId of capabilities) {
51
+ matrix[capabilityId] = {};
52
+ for (const platform of platforms) {
53
+ const realized = projectionStatements.some(
54
+ (projection) =>
55
+ projection.platform === platform &&
56
+ (projection.realizes || []).some((entry) => entry.id === capabilityId)
57
+ );
58
+ matrix[capabilityId][platform] = realized;
59
+ }
60
+ }
61
+
62
+ return {
63
+ type: "domain_coverage",
64
+ version: 1,
65
+ focus: { kind: "domain", id: domain.id },
66
+ summary: summarizeDomain(domain),
67
+ platforms,
68
+ capabilities,
69
+ entities,
70
+ rules,
71
+ verifications,
72
+ projections: stableSortedStrings(projectionStatements.map((p) => p.id)),
73
+ projections_by_capability: projectionsByCapability,
74
+ coverage_matrix: matrix
75
+ };
76
+ }
77
+
78
+ export function generateDomainList(graph) {
79
+ const domains = (graph?.byKind?.domain || []).map((domain) => ({
80
+ id: domain.id,
81
+ name: domain.name,
82
+ description: domain.description,
83
+ status: domain.status,
84
+ parent_domain: domain.parentDomain ? domain.parentDomain.id : null,
85
+ members_count: Object.values(domain.members || {}).reduce((total, list) => total + list.length, 0)
86
+ }));
87
+ domains.sort((a, b) => a.id.localeCompare(b.id));
88
+
89
+ return {
90
+ type: "domain_list",
91
+ version: 1,
92
+ domains
93
+ };
94
+ }
@@ -0,0 +1,137 @@
1
+ import {
2
+ domainById,
3
+ relatedCapabilitiesForDomain,
4
+ relatedEntitiesForDomain,
5
+ relatedProjectionsForDomain,
6
+ relatedRulesForDomain,
7
+ relatedVerificationsForDomain,
8
+ summarizeDomain
9
+ } from "./shared.js";
10
+ import { generateDomainCoverage } from "./domain-coverage.js";
11
+
12
+ function summarizeStatementForRow(graph, id, kind) {
13
+ const statement = (graph?.byKind?.[kind] || []).find((item) => item.id === id);
14
+ if (!statement) return { id, name: id, status: null };
15
+ return {
16
+ id,
17
+ name: statement.name || id,
18
+ status: statement.status || null
19
+ };
20
+ }
21
+
22
+ function renderTable(headers, rows) {
23
+ const lines = [
24
+ `| ${headers.join(" | ")} |`,
25
+ `| ${headers.map(() => "---").join(" | ")} |`,
26
+ ...rows.map((row) => `| ${row.join(" | ")} |`)
27
+ ];
28
+ return lines.join("\n");
29
+ }
30
+
31
+ function renderMembersSection(graph, title, ids, kind) {
32
+ if (!ids.length) {
33
+ return `### ${title}\n\nNone.`;
34
+ }
35
+ const rows = ids.map((id) => {
36
+ const summary = summarizeStatementForRow(graph, id, kind);
37
+ return [`\`${summary.id}\``, summary.name, summary.status || "—"];
38
+ });
39
+ return `### ${title}\n\n${renderTable(["Id", "Name", "Status"], rows)}`;
40
+ }
41
+
42
+ export function generateDomainPage(graph, options = {}) {
43
+ if (!options.domainId) {
44
+ throw new Error("generateDomainPage requires options.domainId");
45
+ }
46
+ const domain = domainById(graph, options.domainId);
47
+ if (!domain) {
48
+ throw new Error(`No domain found with id '${options.domainId}'`);
49
+ }
50
+ const summary = summarizeDomain(domain);
51
+ const coverage = generateDomainCoverage(graph, options);
52
+
53
+ const lines = [];
54
+ lines.push(`# ${summary.name || domain.id}`);
55
+ lines.push("");
56
+ lines.push(`> ${summary.description || ""}`);
57
+ lines.push("");
58
+ lines.push(`- Identifier: \`${domain.id}\``);
59
+ lines.push(`- Status: \`${summary.status || "unknown"}\``);
60
+ if (summary.parent_domain) {
61
+ lines.push(`- Parent domain: \`${summary.parent_domain}\``);
62
+ }
63
+ if (summary.aliases.length) {
64
+ lines.push(`- Aliases: ${summary.aliases.map((a) => `\`${a}\``).join(", ")}`);
65
+ }
66
+ lines.push("");
67
+
68
+ if (summary.in_scope.length) {
69
+ lines.push("## In scope");
70
+ lines.push("");
71
+ for (const item of summary.in_scope) {
72
+ lines.push(`- ${item}`);
73
+ }
74
+ lines.push("");
75
+ }
76
+
77
+ if (summary.out_of_scope.length) {
78
+ lines.push("## Out of scope");
79
+ lines.push("");
80
+ for (const item of summary.out_of_scope) {
81
+ lines.push(`- ${item}`);
82
+ }
83
+ lines.push("");
84
+ }
85
+
86
+ lines.push("## Members");
87
+ lines.push("");
88
+ lines.push(renderMembersSection(graph, "Capabilities", relatedCapabilitiesForDomain(graph, domain.id), "capability"));
89
+ lines.push("");
90
+ lines.push(renderMembersSection(graph, "Entities", relatedEntitiesForDomain(graph, domain.id), "entity"));
91
+ lines.push("");
92
+ lines.push(renderMembersSection(graph, "Rules", relatedRulesForDomain(graph, domain.id), "rule"));
93
+ lines.push("");
94
+ lines.push(renderMembersSection(graph, "Verifications", relatedVerificationsForDomain(graph, domain.id), "verification"));
95
+ lines.push("");
96
+
97
+ if (coverage.platforms.length) {
98
+ lines.push("## Per-platform coverage");
99
+ lines.push("");
100
+ const headers = ["Capability", ...coverage.platforms];
101
+ const rows = coverage.capabilities.map((capabilityId) => {
102
+ const cells = coverage.platforms.map((platform) =>
103
+ coverage.coverage_matrix[capabilityId]?.[platform] ? "✓" : "—"
104
+ );
105
+ return [`\`${capabilityId}\``, ...cells];
106
+ });
107
+ lines.push(renderTable(headers, rows));
108
+ lines.push("");
109
+ lines.push(`Projections involved: ${coverage.projections.map((id) => `\`${id}\``).join(", ") || "none"}`);
110
+ } else {
111
+ lines.push("## Per-platform coverage");
112
+ lines.push("");
113
+ lines.push("No projections currently realize capabilities in this domain.");
114
+ }
115
+
116
+ return {
117
+ type: "domain_page",
118
+ version: 1,
119
+ focus: { kind: "domain", id: domain.id },
120
+ output: {
121
+ path: `topogram/docs-generated/domains/${domain.id}.md`,
122
+ contents: lines.join("\n") + "\n"
123
+ },
124
+ summary
125
+ };
126
+ }
127
+
128
+ export function generateAllDomainPages(graph) {
129
+ const pages = (graph?.byKind?.domain || []).map((domain) =>
130
+ generateDomainPage(graph, { domainId: domain.id })
131
+ );
132
+ return {
133
+ type: "domain_pages",
134
+ version: 1,
135
+ pages
136
+ };
137
+ }
@@ -0,0 +1,42 @@
1
+ import { generateContextBundle } from "./bundle.js";
2
+ import { generateContextDigest } from "./digest.js";
3
+ import { generateContextDiff } from "./diff.js";
4
+ import { generateContextReport } from "./report.js";
5
+ import { generateContextSlice } from "./slice.js";
6
+ import { generateContextTaskMode } from "./task-mode.js";
7
+ import { generateDomainCoverage, generateDomainList } from "./domain-coverage.js";
8
+ import { generateAllDomainPages, generateDomainPage } from "./domain-page.js";
9
+
10
+ export function generateContextTarget(target, graph, options = {}) {
11
+ if (target === "context-digest") {
12
+ return generateContextDigest(graph, options);
13
+ }
14
+ if (target === "context-diff") {
15
+ return generateContextDiff(graph, options);
16
+ }
17
+ if (target === "context-slice") {
18
+ return generateContextSlice(graph, options);
19
+ }
20
+ if (target === "context-bundle") {
21
+ return generateContextBundle(graph, options);
22
+ }
23
+ if (target === "context-report") {
24
+ return generateContextReport(graph, options);
25
+ }
26
+ if (target === "context-task-mode") {
27
+ return generateContextTaskMode(graph, options);
28
+ }
29
+ if (target === "domain-coverage") {
30
+ return generateDomainCoverage(graph, options);
31
+ }
32
+ if (target === "domain-list") {
33
+ return generateDomainList(graph);
34
+ }
35
+ if (target === "domain-page") {
36
+ return options.domainId
37
+ ? generateDomainPage(graph, options)
38
+ : generateAllDomainPages(graph);
39
+ }
40
+
41
+ throw new Error(`Unsupported context target '${target}'`);
42
+ }
@@ -0,0 +1,121 @@
1
+ import fs from "node:fs";
2
+
3
+ import { generateContextBundle } from "./bundle.js";
4
+ import { generateContextDigest } from "./digest.js";
5
+ import { generateContextDiff } from "./diff.js";
6
+ import { generateContextSlice } from "./slice.js";
7
+ import { jsonByteSize, jsonLineCount, percentOf } from "./shared.js";
8
+
9
+ function walkTopogramFiles(root) {
10
+ const output = [];
11
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
12
+ const absolutePath = `${root}/${entry.name}`;
13
+ if (entry.isDirectory()) {
14
+ output.push(...walkTopogramFiles(absolutePath));
15
+ continue;
16
+ }
17
+ if (entry.isFile() && entry.name.endsWith(".tg")) {
18
+ output.push(absolutePath);
19
+ }
20
+ }
21
+ return output;
22
+ }
23
+
24
+ function rawWorkspaceMetrics(graph) {
25
+ const files = walkTopogramFiles(graph.root);
26
+ let bytes = 0;
27
+ let lines = 0;
28
+
29
+ for (const file of files) {
30
+ const contents = fs.readFileSync(file, "utf8");
31
+ bytes += Buffer.byteLength(contents);
32
+ lines += contents.split("\n").length;
33
+ }
34
+
35
+ return { bytes, lines };
36
+ }
37
+
38
+ function pickFirstId(items) {
39
+ return (items || [])[0]?.id || null;
40
+ }
41
+
42
+ export function generateContextReport(graph, options = {}) {
43
+ const rawWorkspace = rawWorkspaceMetrics(graph);
44
+ const resolvedGraph = {
45
+ bytes: jsonByteSize(graph),
46
+ lines: jsonLineCount(graph)
47
+ };
48
+ const digest = generateContextDigest(graph);
49
+ const digestMetrics = {
50
+ bytes: jsonByteSize(digest),
51
+ lines: jsonLineCount(digest)
52
+ };
53
+
54
+ const sliceRows = [];
55
+ const capabilityId = pickFirstId(graph.byKind.capability);
56
+ const workflowId = (graph.docs || []).find((doc) => doc.kind === "workflow")?.id || null;
57
+ const projectionId = pickFirstId(graph.byKind.projection);
58
+ const entityId = pickFirstId(graph.byKind.entity);
59
+
60
+ for (const [kind, selector] of [
61
+ ["capability", capabilityId ? { capabilityId } : null],
62
+ ["workflow", workflowId ? { workflowId } : null],
63
+ ["projection", projectionId ? { projectionId } : null],
64
+ ["entity", entityId ? { entityId } : null]
65
+ ]) {
66
+ if (!selector) {
67
+ continue;
68
+ }
69
+ const slice = generateContextSlice(graph, selector);
70
+ const bytes = jsonByteSize(slice);
71
+ sliceRows.push({
72
+ kind,
73
+ id: slice.focus.id,
74
+ bytes,
75
+ lines: jsonLineCount(slice),
76
+ slice_vs_resolved_percent: percentOf(bytes, resolvedGraph.bytes)
77
+ });
78
+ }
79
+
80
+ const bundleRows = [];
81
+ for (const task of ["api", "ui", "db", "maintained-app"]) {
82
+ const bundle = generateContextBundle(graph, { taskId: task });
83
+ const bytes = jsonByteSize(bundle);
84
+ bundleRows.push({
85
+ task,
86
+ bytes,
87
+ lines: jsonLineCount(bundle),
88
+ bundle_vs_resolved_percent: percentOf(bytes, resolvedGraph.bytes)
89
+ });
90
+ }
91
+
92
+ let diffMetrics = null;
93
+ if (options.fromTopogramPath) {
94
+ const diff = generateContextDiff(graph, options);
95
+ const bytes = jsonByteSize(diff);
96
+ diffMetrics = {
97
+ bytes,
98
+ lines: jsonLineCount(diff),
99
+ diff_vs_resolved_percent: percentOf(bytes, resolvedGraph.bytes),
100
+ diff_vs_digest_percent: percentOf(bytes, digestMetrics.bytes)
101
+ };
102
+ }
103
+
104
+ return {
105
+ type: "context_report",
106
+ version: 1,
107
+ roots: {
108
+ workspace: graph.root,
109
+ baseline: options.fromTopogramPath || null
110
+ },
111
+ raw_workspace: rawWorkspace,
112
+ resolved_graph: resolvedGraph,
113
+ workspace_digest: {
114
+ ...digestMetrics,
115
+ digest_vs_resolved_percent: percentOf(digestMetrics.bytes, resolvedGraph.bytes)
116
+ },
117
+ slices: sliceRows,
118
+ bundles: bundleRows,
119
+ diff: diffMetrics
120
+ };
121
+ }