@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,175 @@
1
+ import path from "node:path";
2
+
3
+ import {
4
+ canonicalCandidateTerm,
5
+ dedupeCandidateRecords,
6
+ findImportFiles,
7
+ idHintify,
8
+ makeCandidateRecord,
9
+ relativeTo,
10
+ slugify,
11
+ titleCase
12
+ } from "../../core/shared.js";
13
+
14
+ function parseRailsArray(rawValue) {
15
+ return [...String(rawValue || "").matchAll(/["']([^"']+)["']/g)].map((entry) => entry[1]);
16
+ }
17
+
18
+ function parseRailsColumns(block) {
19
+ const fields = [];
20
+ const indexes = [];
21
+ const lines = String(block || "").split(/\r?\n/);
22
+ for (const line of lines) {
23
+ const trimmed = line.trim();
24
+ if (!trimmed) continue;
25
+
26
+ const columnMatch = trimmed.match(/^t\.([a-z_]+)\s+"([^"]+)"(.*)$/i);
27
+ if (columnMatch) {
28
+ const [, rawType, fieldName, options = ""] = columnMatch;
29
+ if (rawType !== "index") {
30
+ fields.push({
31
+ name: fieldName,
32
+ field_type: rawType.toLowerCase(),
33
+ required: /null:\s*false/.test(options),
34
+ list: false,
35
+ unique: false,
36
+ primary_key: false
37
+ });
38
+ }
39
+ continue;
40
+ }
41
+
42
+ const indexMatch = trimmed.match(/^t\.index\s+(\[[^\]]+\]|"[^"]+")\s*,\s*name:\s*"([^"]+)"(.*)$/i);
43
+ if (indexMatch) {
44
+ const [, rawFields, indexName, options = ""] = indexMatch;
45
+ const fieldsForIndex = rawFields.startsWith("[")
46
+ ? parseRailsArray(rawFields)
47
+ : [rawFields.replace(/^"|"$/g, "")];
48
+ indexes.push({
49
+ id_hint: idHintify(indexName),
50
+ fields: fieldsForIndex,
51
+ unique: /unique:\s*true/.test(options)
52
+ });
53
+ }
54
+ }
55
+ return { fields, indexes };
56
+ }
57
+
58
+ function parseRailsSchema(schemaText) {
59
+ const entities = [];
60
+ const indexes = [];
61
+ const relations = [];
62
+ const entityFieldMap = new Map();
63
+
64
+ for (const match of schemaText.matchAll(/create_table\s+"([^"]+)"[\s\S]*?do\s+\|t\|\n([\s\S]*?)^\s*end$/gm)) {
65
+ const [, tableName, block] = match;
66
+ const entityStem = canonicalCandidateTerm(tableName);
67
+ const entityId = `entity_${entityStem}`;
68
+ const parsed = parseRailsColumns(block);
69
+ entities.push({
70
+ id_hint: entityId,
71
+ label: titleCase(entityStem),
72
+ table_name: tableName,
73
+ fields: parsed.fields
74
+ });
75
+ entityFieldMap.set(tableName, parsed.fields);
76
+ indexes.push(...parsed.indexes.map((index) => ({
77
+ ...index,
78
+ entity: entityId
79
+ })));
80
+ }
81
+
82
+ for (const match of schemaText.matchAll(/add_foreign_key\s+"([^"]+)"\s*,\s*"([^"]+)"/g)) {
83
+ const [, fromTable, toTable] = match;
84
+ const fromEntity = `entity_${canonicalCandidateTerm(fromTable)}`;
85
+ const toEntity = `entity_${canonicalCandidateTerm(toTable)}`;
86
+ const candidateFieldNames = [
87
+ `${canonicalCandidateTerm(toTable).replace(/-/g, "_")}_id`,
88
+ `${canonicalCandidateTerm(toTable).replace(/-/g, "_")}Id`
89
+ ];
90
+ const knownFields = entityFieldMap.get(fromTable) || [];
91
+ const relationField = candidateFieldNames.find((fieldName) => knownFields.some((field) => field.name === fieldName))
92
+ || knownFields.find((field) => field.name.endsWith("_id"))?.name
93
+ || `${canonicalCandidateTerm(toTable).replace(/-/g, "_")}_id`;
94
+ relations.push({
95
+ from_entity: fromEntity,
96
+ to_entity: toEntity,
97
+ relation_field: relationField,
98
+ fields: [relationField],
99
+ references: ["id"]
100
+ });
101
+ }
102
+
103
+ return { entities, indexes, relations };
104
+ }
105
+
106
+ export const railsSchemaExtractor = {
107
+ id: "db.rails-schema",
108
+ track: "db",
109
+ detect(context) {
110
+ const schemaFiles = findImportFiles(context.paths, (filePath) => /db\/schema\.rb$/i.test(filePath));
111
+ return {
112
+ score: schemaFiles.length > 0 ? 92 : 0,
113
+ reasons: schemaFiles.length > 0 ? ["Found Rails schema.rb"] : []
114
+ };
115
+ },
116
+ extract(context) {
117
+ const schemaFiles = findImportFiles(context.paths, (filePath) => /db\/schema\.rb$/i.test(filePath));
118
+ const findings = [];
119
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
120
+
121
+ for (const filePath of schemaFiles) {
122
+ const schemaText = context.helpers.readTextIfExists(filePath) || "";
123
+ const parsed = parseRailsSchema(schemaText);
124
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
125
+
126
+ findings.push({
127
+ kind: "rails_schema",
128
+ file: provenance,
129
+ entity_count: parsed.entities.length,
130
+ relation_count: parsed.relations.length
131
+ });
132
+
133
+ candidates.entities.push(...parsed.entities.map((entity) => makeCandidateRecord({
134
+ kind: "entity",
135
+ idHint: entity.id_hint,
136
+ label: entity.label,
137
+ confidence: "high",
138
+ sourceKind: "schema",
139
+ provenance,
140
+ table_name: entity.table_name,
141
+ fields: entity.fields,
142
+ track: "db"
143
+ })));
144
+
145
+ candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
146
+ kind: "relation",
147
+ idHint: slugify(`${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`),
148
+ label: `${relation.from_entity} -> ${relation.to_entity}`,
149
+ confidence: "high",
150
+ sourceKind: "schema",
151
+ provenance,
152
+ ...relation,
153
+ track: "db"
154
+ })));
155
+
156
+ candidates.indexes.push(...parsed.indexes.map((index) => makeCandidateRecord({
157
+ kind: "index",
158
+ idHint: index.id_hint,
159
+ label: titleCase(index.id_hint.replace(/^index_/, "")),
160
+ confidence: "medium",
161
+ sourceKind: "schema",
162
+ provenance,
163
+ entity: index.entity,
164
+ fields: index.fields,
165
+ unique: index.unique,
166
+ track: "db"
167
+ })));
168
+ }
169
+
170
+ candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
171
+ candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
172
+ candidates.indexes = dedupeCandidateRecords(candidates.indexes, (record) => record.id_hint);
173
+ return { findings, candidates };
174
+ }
175
+ };
@@ -0,0 +1,95 @@
1
+ import {
2
+ canonicalCandidateTerm,
3
+ dedupeCandidateRecords,
4
+ findImportFiles,
5
+ idHintify,
6
+ makeCandidateRecord,
7
+ relativeTo,
8
+ titleCase
9
+ } from "../../core/shared.js";
10
+
11
+ function normalizeTsFieldType(typeName) {
12
+ const normalized = String(typeName || "").trim().replace(/\[\]$/, "");
13
+ switch (normalized) {
14
+ case "string": return "string";
15
+ case "number": return "int";
16
+ case "boolean": return "boolean";
17
+ default: return idHintify(normalized) || "string";
18
+ }
19
+ }
20
+
21
+ function contextStemFromPath(filePath) {
22
+ const contextMatch = String(filePath || "").match(/\/src\/([^/]+)\//);
23
+ const entityMatch = String(filePath || "").match(/\/([^/]+)Entity\.ts$/);
24
+ return canonicalCandidateTerm(
25
+ entityMatch?.[1] ||
26
+ contextMatch?.[1] ||
27
+ "item"
28
+ );
29
+ }
30
+
31
+ function parseEntityFile(text, provenance, filePath) {
32
+ const interfaceMatch = String(text || "").match(/interface\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}/m);
33
+ if (!interfaceMatch) return null;
34
+ const [, interfaceName, body] = interfaceMatch;
35
+ const fields = [...String(body || "").matchAll(/([A-Za-z_][A-Za-z0-9_]*)\??:\s*([^;\n]+)/g)]
36
+ .map((match) => ({
37
+ name: match[1],
38
+ field_type: normalizeTsFieldType(match[2]),
39
+ required: !match[0].includes("?:"),
40
+ list: /\[\]\s*$/.test(match[2]),
41
+ unique: false,
42
+ primary_key: /^id$/i.test(match[1])
43
+ }));
44
+ if (fields.length === 0) return null;
45
+ const stem = contextStemFromPath(filePath);
46
+ return makeCandidateRecord({
47
+ kind: "entity",
48
+ idHint: `entity_${stem}`,
49
+ label: titleCase(stem),
50
+ confidence: "high",
51
+ sourceKind: "schema",
52
+ provenance,
53
+ model_name: interfaceName,
54
+ fields,
55
+ track: "db"
56
+ });
57
+ }
58
+
59
+ export const reactNativeEntitiesExtractor = {
60
+ id: "db.react-native-entities",
61
+ track: "db",
62
+ detect(context) {
63
+ const entityFiles = findImportFiles(
64
+ context.paths,
65
+ (filePath) => /\/src\/.+\/domain\/entities\/.+Entity\.ts$/i.test(filePath)
66
+ );
67
+ const score = entityFiles.length > 0 ? 82 : 0;
68
+ return {
69
+ score,
70
+ reasons: score > 0 ? ["Found React Native domain entity interfaces"] : []
71
+ };
72
+ },
73
+ extract(context) {
74
+ const entityFiles = findImportFiles(
75
+ context.paths,
76
+ (filePath) => /\/src\/.+\/domain\/entities\/.+Entity\.ts$/i.test(filePath)
77
+ );
78
+ const findings = [];
79
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
80
+ for (const filePath of entityFiles) {
81
+ const text = context.helpers.readTextIfExists(filePath) || "";
82
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
83
+ const entity = parseEntityFile(text, provenance, filePath);
84
+ if (!entity) continue;
85
+ findings.push({
86
+ kind: "react_native_domain_entity",
87
+ file: provenance,
88
+ entity_id: entity.id_hint
89
+ });
90
+ candidates.entities.push(entity);
91
+ }
92
+ candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
93
+ return { findings, candidates };
94
+ }
95
+ };
@@ -0,0 +1,193 @@
1
+ import {
2
+ canonicalCandidateTerm,
3
+ dedupeCandidateRecords,
4
+ findImportFiles,
5
+ idHintify,
6
+ makeCandidateRecord,
7
+ relativeTo,
8
+ titleCase
9
+ } from "../../core/shared.js";
10
+
11
+ function kotlinTypeToFieldType(typeName) {
12
+ const normalized = String(typeName || "").replace(/\?$/, "");
13
+ switch (normalized) {
14
+ case "String": return "string";
15
+ case "Int": return "int";
16
+ case "Long": return "bigint";
17
+ case "Float": return "float";
18
+ case "Double": return "double";
19
+ case "Boolean": return "boolean";
20
+ default:
21
+ if (/^List<.+>$/.test(normalized)) return "json";
22
+ return normalized || "string";
23
+ }
24
+ }
25
+
26
+ function roomEntityStem(name) {
27
+ return idHintify(
28
+ canonicalCandidateTerm(
29
+ String(name || "").replace(/([a-z0-9])([A-Z])/g, "$1_$2")
30
+ )
31
+ );
32
+ }
33
+
34
+ function parseEntityFile(text, provenance) {
35
+ const classMatch = String(text || "").match(/@Entity(?:\([^)]*\))?[\s\S]*?data\s+class\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*?)\)\s*$/m);
36
+ if (!classMatch) return null;
37
+ const className = classMatch[1];
38
+ const fieldsBlock = classMatch[2];
39
+ const fields = [];
40
+ let currentPrimaryKey = false;
41
+
42
+ for (const rawLine of fieldsBlock.split(/\r?\n/)) {
43
+ const line = rawLine.trim().replace(/,$/, "");
44
+ if (!line) continue;
45
+ if (line.startsWith("@PrimaryKey")) {
46
+ currentPrimaryKey = true;
47
+ continue;
48
+ }
49
+ const match = line.match(/^(?:var|val)\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([^=,]+)/);
50
+ if (!match) continue;
51
+ const [, name, typeName] = match;
52
+ const required = !String(typeName).includes("?");
53
+ fields.push({
54
+ name,
55
+ field_type: kotlinTypeToFieldType(typeName.trim()),
56
+ required,
57
+ list: /^List</.test(String(typeName).trim()),
58
+ unique: false,
59
+ primary_key: currentPrimaryKey
60
+ });
61
+ currentPrimaryKey = false;
62
+ }
63
+
64
+ const entityStem = roomEntityStem(className.replace(/Entity$/, ""));
65
+ return makeCandidateRecord({
66
+ kind: "entity",
67
+ idHint: `entity_${entityStem}`,
68
+ label: titleCase(entityStem),
69
+ confidence: "high",
70
+ sourceKind: "schema",
71
+ provenance,
72
+ model_name: className,
73
+ fields,
74
+ track: "db"
75
+ });
76
+ }
77
+
78
+ function inferDaoCapability(daoName, methodName, queryText) {
79
+ const entityStem = roomEntityStem(daoName.replace(/Dao$/, "").replace(/Info$/, "_info"));
80
+ const normalizedMethod = methodName.toLowerCase();
81
+ if (/insert|upsert|save|create/.test(normalizedMethod)) return `cap_create_${entityStem}`;
82
+ if (/getall|list|fetchall/.test(normalizedMethod)) return `cap_list_${entityStem}s`;
83
+ if (/get|fetch|load/.test(normalizedMethod)) return `cap_get_${entityStem}`;
84
+ if (/delete|remove/.test(normalizedMethod)) return `cap_delete_${entityStem}`;
85
+ if (/update|edit/.test(normalizedMethod)) return `cap_update_${entityStem}`;
86
+ if (/select \*/i.test(queryText || "") && /where/i.test(queryText || "")) return `cap_get_${entityStem}`;
87
+ if (/select \*/i.test(queryText || "")) return `cap_list_${entityStem}s`;
88
+ return null;
89
+ }
90
+
91
+ function parseDaoFile(text, provenance) {
92
+ const daoMatch = String(text || "").match(/@Dao[\s\S]*?interface\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/m);
93
+ if (!daoMatch) return [];
94
+ const daoName = daoMatch[1];
95
+ const capabilities = [];
96
+ let pendingQuery = null;
97
+ let pendingInsert = false;
98
+
99
+ for (const rawLine of String(text || "").split(/\r?\n/)) {
100
+ const line = rawLine.trim();
101
+ const queryMatch = line.match(/^@Query\("(.+)"\)$/);
102
+ if (queryMatch) {
103
+ pendingQuery = queryMatch[1];
104
+ pendingInsert = false;
105
+ continue;
106
+ }
107
+ if (/^@Insert\b/.test(line)) {
108
+ pendingInsert = true;
109
+ pendingQuery = null;
110
+ continue;
111
+ }
112
+ const methodMatch = line.match(/fun\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*?)\)\s*:\s*([A-Za-z0-9_<>,?. ]+)/);
113
+ if (!methodMatch) continue;
114
+ const methodName = methodMatch[1];
115
+ const params = methodMatch[2];
116
+ const returnType = methodMatch[3].trim();
117
+ const entityStem = canonicalCandidateTerm(daoName.replace(/Dao$/, "").replace(/Info$/, "_info"));
118
+ const capabilityId = pendingInsert
119
+ ? `cap_create_${entityStem}`
120
+ : inferDaoCapability(daoName, methodName, pendingQuery);
121
+ if (!capabilityId) {
122
+ pendingInsert = false;
123
+ pendingQuery = null;
124
+ continue;
125
+ }
126
+ const queryParams = [...String(params || "").matchAll(/([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([A-Za-z0-9_<>,?.]+)/g)]
127
+ .map((entry) => ({ name: entry[1], required: !entry[2].includes("?"), type: entry[2] }));
128
+ capabilities.push(makeCandidateRecord({
129
+ kind: "capability",
130
+ idHint: capabilityId,
131
+ label: titleCase(capabilityId.replace(/^cap_/, "")),
132
+ confidence: "medium",
133
+ sourceKind: "schema",
134
+ provenance,
135
+ entity_id: `entity_${entityStem}`,
136
+ dao_name: daoName,
137
+ dao_method: methodName,
138
+ query: pendingQuery,
139
+ input_fields: queryParams.map((entry) => entry.name),
140
+ output_fields: /^List</.test(returnType) ? [canonicalCandidateTerm(entityStem), `${canonicalCandidateTerm(entityStem)}s`] : [canonicalCandidateTerm(entityStem)],
141
+ track: "db"
142
+ }));
143
+ pendingInsert = false;
144
+ pendingQuery = null;
145
+ }
146
+
147
+ return capabilities;
148
+ }
149
+
150
+ export const roomExtractor = {
151
+ id: "db.room",
152
+ track: "db",
153
+ detect(context) {
154
+ const entityFiles = findImportFiles(context.paths, (filePath) => /Entity\.kt$/i.test(filePath) || /\/entitiy\/.+\.kt$/i.test(filePath) || /\/entity\/.+\.kt$/i.test(filePath));
155
+ const daoFiles = findImportFiles(context.paths, (filePath) => /Dao\.kt$/i.test(filePath));
156
+ const score = entityFiles.length > 0 && daoFiles.length > 0 ? 89 : 0;
157
+ return {
158
+ score,
159
+ reasons: score > 0 ? ["Found Android Room entities and DAO interfaces"] : []
160
+ };
161
+ },
162
+ extract(context) {
163
+ const entityFiles = findImportFiles(context.paths, (filePath) => /Entity\.kt$/i.test(filePath) || /\/entitiy\/.+\.kt$/i.test(filePath) || /\/entity\/.+\.kt$/i.test(filePath));
164
+ const daoFiles = findImportFiles(context.paths, (filePath) => /Dao\.kt$/i.test(filePath));
165
+ const findings = [];
166
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
167
+
168
+ for (const filePath of entityFiles) {
169
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
170
+ const parsed = parseEntityFile(context.helpers.readTextIfExists(filePath) || "", provenance);
171
+ if (!parsed) continue;
172
+ candidates.entities.push(parsed);
173
+ }
174
+
175
+ const daoCapabilities = [];
176
+ for (const filePath of daoFiles) {
177
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
178
+ daoCapabilities.push(...parseDaoFile(context.helpers.readTextIfExists(filePath) || "", provenance));
179
+ }
180
+
181
+ if (candidates.entities.length > 0 || daoCapabilities.length > 0) {
182
+ findings.push({
183
+ kind: "android_room",
184
+ entities: candidates.entities.length,
185
+ dao_capabilities: daoCapabilities.length
186
+ });
187
+ }
188
+
189
+ candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
190
+ candidates.indexes = dedupeCandidateRecords(daoCapabilities, (record) => record.id_hint);
191
+ return { findings, candidates };
192
+ }
193
+ };
@@ -0,0 +1,112 @@
1
+ import { findImportFiles, makeCandidateRecord, relativeTo, slugify, titleCase, idHintify } from "../../core/shared.js";
2
+
3
+ function parseDbSchemaSnapshot(snapshot) {
4
+ return {
5
+ entities: (snapshot.tables || []).map((table) => ({
6
+ name: table.table,
7
+ table_name: table.table,
8
+ fields: (table.columns || []).map((column) => ({
9
+ name: column.name,
10
+ field_type: column.type,
11
+ required: !column.nullable,
12
+ list: false,
13
+ unique: false,
14
+ primary_key: Boolean(column.primaryKey)
15
+ }))
16
+ })),
17
+ enums: (snapshot.enums || []).map((entry) => ({
18
+ name: entry.id,
19
+ values: entry.values || []
20
+ })),
21
+ relations: (snapshot.tables || []).flatMap((table) =>
22
+ (table.foreignKeys || []).map((foreignKey) => ({
23
+ from_entity: `entity_${slugify(table.table)}`,
24
+ to_entity: `entity_${slugify(foreignKey.referencesTable)}`,
25
+ relation_field: foreignKey.columns?.[0] || "relation",
26
+ fields: foreignKey.columns || [],
27
+ references: foreignKey.referencesColumns || []
28
+ }))
29
+ ),
30
+ indexes: (snapshot.tables || []).flatMap((table) =>
31
+ (table.indexes || []).map((index) => ({
32
+ id_hint: idHintify(index.name || `${table.table}_${(index.columns || []).join("_")}`),
33
+ entity: `entity_${slugify(table.table)}`,
34
+ fields: index.columns || [],
35
+ unique: Boolean(index.unique)
36
+ }))
37
+ )
38
+ };
39
+ }
40
+
41
+ export const snapshotExtractor = {
42
+ id: "db.snapshot",
43
+ track: "db",
44
+ detect(context) {
45
+ const files = findImportFiles(context.paths, (filePath) => filePath.endsWith(".db-schema-snapshot.json"));
46
+ return {
47
+ score: files.length > 0 ? 40 : 0,
48
+ reasons: files.length > 0 ? ["Found DB schema snapshot artifacts"] : []
49
+ };
50
+ },
51
+ extract(context) {
52
+ const snapshotFiles = findImportFiles(context.paths, (filePath) => filePath.endsWith(".db-schema-snapshot.json"));
53
+ const findings = [];
54
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
55
+ for (const filePath of snapshotFiles) {
56
+ const snapshot = context.helpers.readJsonIfExists(filePath);
57
+ if (!snapshot) continue;
58
+ const parsed = parseDbSchemaSnapshot(snapshot);
59
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
60
+ findings.push({
61
+ kind: "db_schema_snapshot",
62
+ file: provenance,
63
+ entity_count: parsed.entities.length,
64
+ enum_count: parsed.enums.length
65
+ });
66
+ candidates.entities.push(...parsed.entities.map((entity) => makeCandidateRecord({
67
+ kind: "entity",
68
+ idHint: `entity_${slugify(entity.name)}`,
69
+ label: titleCase(entity.name),
70
+ confidence: "medium",
71
+ sourceKind: "generated_artifact",
72
+ provenance,
73
+ table_name: entity.table_name || slugify(entity.name),
74
+ fields: entity.fields,
75
+ track: "db"
76
+ })));
77
+ candidates.enums.push(...parsed.enums.map((entry) => makeCandidateRecord({
78
+ kind: "enum",
79
+ idHint: idHintify(entry.name),
80
+ label: titleCase(entry.name),
81
+ confidence: "medium",
82
+ sourceKind: "generated_artifact",
83
+ provenance,
84
+ values: entry.values,
85
+ track: "db"
86
+ })));
87
+ candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
88
+ kind: "relation",
89
+ idHint: slugify(`${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`),
90
+ label: `${relation.from_entity} -> ${relation.to_entity}`,
91
+ confidence: "medium",
92
+ sourceKind: "generated_artifact",
93
+ provenance,
94
+ ...relation,
95
+ track: "db"
96
+ })));
97
+ candidates.indexes.push(...parsed.indexes.map((index) => makeCandidateRecord({
98
+ kind: "index",
99
+ idHint: index.id_hint,
100
+ label: titleCase(index.id_hint.replace(/^index_/, "")),
101
+ confidence: "medium",
102
+ sourceKind: "generated_artifact",
103
+ provenance,
104
+ entity: index.entity,
105
+ fields: index.fields,
106
+ unique: index.unique,
107
+ track: "db"
108
+ })));
109
+ }
110
+ return { findings, candidates };
111
+ }
112
+ };