@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,232 @@
1
+ import { findImportFiles, makeCandidateRecord, normalizeOpenApiPath, relativeTo, selectPreferredImportFiles, slugify, titleCase } from "../../core/shared.js";
2
+
3
+ function openApiRefName(ref) {
4
+ return typeof ref === "string" ? ref.split("/").pop() || null : null;
5
+ }
6
+
7
+ function resolveOpenApiSchema(document, schema, seen = new Set()) {
8
+ if (!schema || typeof schema !== "object") return null;
9
+ if (schema.$ref) {
10
+ if (seen.has(schema.$ref) || !schema.$ref.startsWith("#/")) return null;
11
+ seen.add(schema.$ref);
12
+ let current = document;
13
+ for (const segment of schema.$ref.slice(2).split("/")) {
14
+ current = current?.[segment];
15
+ if (current == null) return null;
16
+ }
17
+ return resolveOpenApiSchema(document, current, seen) || current;
18
+ }
19
+ return schema;
20
+ }
21
+
22
+ function collectOpenApiObjectFields(document, schema, fields = new Set(), seen = new Set()) {
23
+ const resolved = resolveOpenApiSchema(document, schema, seen);
24
+ if (!resolved || typeof resolved !== "object") return fields;
25
+ if (resolved.type === "array" && resolved.items) {
26
+ collectOpenApiObjectFields(document, resolved.items, fields, seen);
27
+ return fields;
28
+ }
29
+ for (const propertyName of Object.keys(resolved.properties || {})) fields.add(propertyName);
30
+ for (const entry of resolved.allOf || []) collectOpenApiObjectFields(document, entry, fields, seen);
31
+ for (const entry of resolved.oneOf || []) collectOpenApiObjectFields(document, entry, fields, seen);
32
+ for (const entry of resolved.anyOf || []) collectOpenApiObjectFields(document, entry, fields, seen);
33
+ return fields;
34
+ }
35
+
36
+ function extractOpenApiSchemaFieldHints(document, schema) {
37
+ return {
38
+ schema_ref: openApiRefName(schema?.$ref || null),
39
+ body_fields: [...collectOpenApiObjectFields(document, schema)].sort()
40
+ };
41
+ }
42
+
43
+ function collectOpenApiParameters(endpointPath, operation) {
44
+ const pathParams = [...String(endpointPath || "").matchAll(/\{([^}]+)\}/g)].map((match) => ({
45
+ name: match[1],
46
+ in: "path",
47
+ required: true
48
+ }));
49
+ return [...pathParams, ...((operation.parameters || []).filter(Boolean))];
50
+ }
51
+
52
+ function extractOpenApiParameterHints(document, endpointPath, operation) {
53
+ const grouped = { path: [], query: [], header: [] };
54
+ for (const parameter of collectOpenApiParameters(endpointPath, operation)) {
55
+ const schema = resolveOpenApiSchema(document, parameter.schema || null);
56
+ const target = parameter.in === "query" ? "query" : parameter.in === "header" ? "header" : "path";
57
+ grouped[target].push({
58
+ name: parameter.name,
59
+ required: Boolean(parameter.required),
60
+ type: schema?.type || null
61
+ });
62
+ }
63
+ for (const key of Object.keys(grouped)) {
64
+ grouped[key] = grouped[key].sort((a, b) => a.name.localeCompare(b.name));
65
+ }
66
+ return grouped;
67
+ }
68
+
69
+ function extractOpenApiSecuritySchemes(document, operation) {
70
+ const schemes = new Set();
71
+ for (const entry of [...(operation.security || []), ...(document.security || [])]) {
72
+ for (const key of Object.keys(entry || {})) schemes.add(key);
73
+ }
74
+ return [...schemes].sort();
75
+ }
76
+
77
+ function parseOpenApiYaml(text) {
78
+ const doc = { paths: {} };
79
+ let currentPath = null;
80
+ let currentMethod = null;
81
+ let inRequestBody = false;
82
+ let inResponses = false;
83
+ let currentResponseStatus = null;
84
+ for (const rawLine of text.split(/\r?\n/)) {
85
+ const line = rawLine.replace(/#.*$/, "");
86
+ if (!line.trim()) continue;
87
+ const pathMatch = line.match(/^\s{2}(\/[^:]+):\s*$/);
88
+ if (pathMatch) {
89
+ currentPath = pathMatch[1];
90
+ currentMethod = null;
91
+ doc.paths[currentPath] = doc.paths[currentPath] || {};
92
+ inRequestBody = false;
93
+ inResponses = false;
94
+ currentResponseStatus = null;
95
+ continue;
96
+ }
97
+ const methodMatch = line.match(/^\s{4}(get|post|put|patch|delete):\s*$/i);
98
+ if (methodMatch && currentPath) {
99
+ currentMethod = methodMatch[1].toLowerCase();
100
+ doc.paths[currentPath][currentMethod] = { responses: {} };
101
+ inRequestBody = false;
102
+ inResponses = false;
103
+ currentResponseStatus = null;
104
+ continue;
105
+ }
106
+ if (!currentPath || !currentMethod) continue;
107
+ const operation = doc.paths[currentPath][currentMethod];
108
+ const operationIdMatch = line.match(/^\s{6}operationId:\s*(.+)$/);
109
+ if (operationIdMatch) {
110
+ operation.operationId = operationIdMatch[1].trim().replace(/^["']|["']$/g, "");
111
+ continue;
112
+ }
113
+ const summaryMatch = line.match(/^\s{6}summary:\s*(.+)$/);
114
+ if (summaryMatch) {
115
+ operation.summary = summaryMatch[1].trim().replace(/^["']|["']$/g, "");
116
+ continue;
117
+ }
118
+ if (/^\s{6}requestBody:\s*$/.test(line)) {
119
+ inRequestBody = true;
120
+ inResponses = false;
121
+ currentResponseStatus = null;
122
+ continue;
123
+ }
124
+ if (/^\s{6}responses:\s*$/.test(line)) {
125
+ inResponses = true;
126
+ inRequestBody = false;
127
+ currentResponseStatus = null;
128
+ continue;
129
+ }
130
+ const responseStatusMatch = line.match(/^\s{8}['"]?([0-9Xx]{3})['"]?:\s*$/);
131
+ if (inResponses && responseStatusMatch) {
132
+ currentResponseStatus = responseStatusMatch[1];
133
+ operation.responses[currentResponseStatus] = operation.responses[currentResponseStatus] || {};
134
+ continue;
135
+ }
136
+ const refMatch = line.match(/^\s+\$ref:\s*(.+)$/);
137
+ if (refMatch) {
138
+ const ref = refMatch[1].trim().replace(/^["']|["']$/g, "");
139
+ if (inRequestBody) {
140
+ operation.requestBody = operation.requestBody || { content: { "application/json": { schema: {} } } };
141
+ operation.requestBody.content["application/json"].schema.$ref = ref;
142
+ } else if (inResponses && currentResponseStatus) {
143
+ operation.responses[currentResponseStatus].content = operation.responses[currentResponseStatus].content || { "application/json": { schema: {} } };
144
+ operation.responses[currentResponseStatus].content["application/json"].schema.$ref = ref;
145
+ }
146
+ }
147
+ }
148
+ return doc;
149
+ }
150
+
151
+ function parseOpenApiDocument(document, provenance, sourceKind = "openapi") {
152
+ const capabilities = [];
153
+ const routes = [];
154
+ for (const [endpointPath, operations] of Object.entries(document.paths || {})) {
155
+ for (const [method, operation] of Object.entries(operations || {})) {
156
+ const normalizedMethod = method.toUpperCase();
157
+ const operationId = operation.operationId || `candidate_${normalizedMethod.toLowerCase()}_${slugify(endpointPath)}`;
158
+ const successResponse = Object.entries(operation.responses || {}).find(([status]) => /^2/.test(status));
159
+ const requestFieldHints = extractOpenApiSchemaFieldHints(document, operation.requestBody?.content?.["application/json"]?.schema);
160
+ const responseFieldHints = extractOpenApiSchemaFieldHints(document, successResponse?.[1]?.content?.["application/json"]?.schema);
161
+ const parameterHints = extractOpenApiParameterHints(document, endpointPath, operation);
162
+ const securitySchemes = extractOpenApiSecuritySchemes(document, operation);
163
+ capabilities.push(makeCandidateRecord({
164
+ kind: "capability",
165
+ idHint: operationId,
166
+ label: operation.summary || titleCase(operationId.replace(/^cap_/, "")),
167
+ confidence: "high",
168
+ sourceKind,
169
+ provenance: `${provenance}#${normalizedMethod} ${endpointPath}`,
170
+ endpoint: { method: normalizedMethod, path: endpointPath },
171
+ input_hint: operation.requestBody?.content?.["application/json"]?.schema?.$ref || operation.requestBody?.content?.["application/json"]?.schema?.type || null,
172
+ output_hint: successResponse?.[1]?.content?.["application/json"]?.schema?.$ref || successResponse?.[1]?.content?.["application/json"]?.schema?.type || null,
173
+ input_fields: requestFieldHints.body_fields,
174
+ output_fields: responseFieldHints.body_fields,
175
+ path_params: parameterHints.path,
176
+ query_params: parameterHints.query,
177
+ header_params: parameterHints.header,
178
+ security_schemes: securitySchemes,
179
+ auth_hint: securitySchemes.length > 0 ? "secured" : "unknown",
180
+ track: "api"
181
+ }));
182
+ routes.push({
183
+ path: endpointPath,
184
+ method: normalizedMethod,
185
+ source_kind: sourceKind,
186
+ provenance: `${provenance}#${normalizedMethod} ${endpointPath}`
187
+ });
188
+ }
189
+ }
190
+ return { capabilities, routes };
191
+ }
192
+
193
+ export const openApiExtractor = {
194
+ id: "api.openapi",
195
+ track: "api",
196
+ detect(context) {
197
+ const files = selectPreferredImportFiles(
198
+ context.paths,
199
+ findImportFiles(context.paths, (filePath) => /(openapi|swagger)\.(json|ya?ml)$/i.test(filePath)),
200
+ "openapi"
201
+ );
202
+ return {
203
+ score: files.length > 0 ? 100 : 0,
204
+ reasons: files.length > 0 ? ["Found OpenAPI source"] : []
205
+ };
206
+ },
207
+ extract(context) {
208
+ const openApiFiles = selectPreferredImportFiles(
209
+ context.paths,
210
+ findImportFiles(context.paths, (filePath) => /(openapi|swagger)\.(json|ya?ml)$/i.test(filePath)),
211
+ "openapi"
212
+ );
213
+ const findings = [];
214
+ const candidates = { capabilities: [], routes: [], stacks: [] };
215
+ for (const filePath of openApiFiles) {
216
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
217
+ const text = context.helpers.readTextIfExists(filePath) || "";
218
+ const document = filePath.endsWith(".json") ? JSON.parse(text) : parseOpenApiYaml(text);
219
+ const parsed = parseOpenApiDocument(document, provenance, "openapi");
220
+ findings.push({ kind: "openapi", file: provenance, capability_count: parsed.capabilities.length });
221
+ candidates.capabilities.push(...parsed.capabilities);
222
+ candidates.routes.push(...parsed.routes.map((route) => ({
223
+ path: route.path,
224
+ method: route.method,
225
+ confidence: "high",
226
+ source_kind: route.source_kind,
227
+ provenance: route.provenance
228
+ })));
229
+ }
230
+ return { findings, candidates };
231
+ }
232
+ };
@@ -0,0 +1,230 @@
1
+ import path from "node:path";
2
+
3
+ import {
4
+ dedupeCandidateRecords,
5
+ findImportFiles,
6
+ inferApiEntityIdFromPath,
7
+ inferRouteCapabilityId,
8
+ makeCandidateRecord,
9
+ normalizeOpenApiPath,
10
+ relativeTo,
11
+ titleCase
12
+ } from "../../core/shared.js";
13
+
14
+ const RESOURCE_ACTIONS = {
15
+ index: "GET",
16
+ create: "POST",
17
+ show: "GET",
18
+ update: "PUT",
19
+ destroy: "DELETE"
20
+ };
21
+
22
+ function singularControllerName(resourceName) {
23
+ return String(resourceName || "")
24
+ .replace(/ies$/, "y")
25
+ .replace(/s$/, "");
26
+ }
27
+
28
+ function parseOnlyActions(rawOptions) {
29
+ if (!rawOptions) return null;
30
+ const arrayMatch = rawOptions.match(/only:\s*(\[[^\]]+\]|:[A-Za-z_][A-Za-z0-9_]*)/);
31
+ if (!arrayMatch) return null;
32
+ const rawValue = arrayMatch[1];
33
+ if (rawValue.startsWith(":")) {
34
+ return [rawValue.slice(1)];
35
+ }
36
+ return [...rawValue.matchAll(/:([A-Za-z_][A-Za-z0-9_]*)/g)].map((entry) => entry[1]);
37
+ }
38
+
39
+ function parseParamName(rawOptions) {
40
+ const match = String(rawOptions || "").match(/param:\s*:([A-Za-z_][A-Za-z0-9_]*)/);
41
+ return match ? match[1] : "id";
42
+ }
43
+
44
+ function joinRoutePath(...parts) {
45
+ const normalized = parts
46
+ .filter(Boolean)
47
+ .join("/")
48
+ .replace(/\/+/g, "/");
49
+ return normalized.startsWith("/") ? normalized : `/${normalized}`;
50
+ }
51
+
52
+ function buildResourceRoutes(state, resourceName, rawOptions = "") {
53
+ const onlyActions = parseOnlyActions(rawOptions) || ["index", "create", "show", "update", "destroy"];
54
+ const paramName = parseParamName(rawOptions);
55
+ const parentBasePath = state.controller ? (state.memberPath || state.collectionPath) : state.collectionPath;
56
+ const collectionPath = joinRoutePath(parentBasePath, resourceName);
57
+ const memberPath = joinRoutePath(collectionPath, `:${paramName}`);
58
+ const controllerName = resourceName;
59
+ const routes = [];
60
+
61
+ for (const action of onlyActions) {
62
+ const method = RESOURCE_ACTIONS[action];
63
+ if (!method) continue;
64
+ routes.push({
65
+ method,
66
+ path: action === "index" || action === "create" ? collectionPath : memberPath,
67
+ handler_hint: null,
68
+ controller: controllerName,
69
+ action,
70
+ auth_hint: "unknown"
71
+ });
72
+ }
73
+
74
+ return {
75
+ routes,
76
+ nextState: {
77
+ collectionPath,
78
+ memberPath,
79
+ controller: controllerName,
80
+ singular: singularControllerName(resourceName)
81
+ }
82
+ };
83
+ }
84
+
85
+ function buildExplicitRoute(state, method, rawPath, rawOptions = "") {
86
+ const pathValue = rawPath.startsWith(":") ? rawPath.slice(1) : rawPath.replace(/^["']|["']$/g, "");
87
+ const collectionScoped = /on:\s*:collection/.test(rawOptions);
88
+ const memberScoped = /on:\s*:member/.test(rawOptions);
89
+ const basePath = collectionScoped
90
+ ? (state.collectionPath || state.memberPath || "")
91
+ : memberScoped
92
+ ? (state.memberPath || state.collectionPath || "")
93
+ : (state.memberPath || state.collectionPath || "");
94
+ const pathValueWithLeadingSlash = pathValue.startsWith("/") ? pathValue : `/${pathValue}`;
95
+ const combinedPath = state.controller && !/^\//.test(rawPath)
96
+ ? joinRoutePath(basePath, pathValue)
97
+ : joinRoutePath(state.collectionPath, pathValueWithLeadingSlash);
98
+
99
+ const toMatch = String(rawOptions || "").match(/to:\s*["']([^#"']+)#([^"']+)["']/);
100
+ const controllerName = toMatch ? toMatch[1] : state.controller;
101
+ const actionName = toMatch ? toMatch[2] : pathValue;
102
+ const singular = singularControllerName(controllerName || state.singular || "item");
103
+ const preferPathInference = new Set(["index", "show", "create", "update", "destroy", "login", "current", "custom_update"]);
104
+ const handlerHint = actionName && !preferPathInference.has(actionName)
105
+ ? `${actionName}_${singular}`
106
+ : null;
107
+
108
+ return {
109
+ method: method.toUpperCase(),
110
+ path: combinedPath,
111
+ handler_hint: handlerHint,
112
+ controller: controllerName,
113
+ action: actionName,
114
+ auth_hint: /auth\/login/.test(combinedPath) ? "public" : "unknown"
115
+ };
116
+ }
117
+
118
+ function parseRailsRoutes(routesText) {
119
+ const routes = [];
120
+ const stack = [{ collectionPath: "", memberPath: "", controller: null, singular: null }];
121
+ const lines = String(routesText || "").split(/\r?\n/);
122
+
123
+ for (const rawLine of lines) {
124
+ const line = rawLine.trim();
125
+ if (!line || line.startsWith("#") || line === "Rails.application.routes.draw do") continue;
126
+
127
+ if (line === "end") {
128
+ if (stack.length > 1) stack.pop();
129
+ continue;
130
+ }
131
+
132
+ const state = stack[stack.length - 1];
133
+
134
+ const scopeMatch = line.match(/^scope\s+:([A-Za-z_][A-Za-z0-9_]*)\s+do$/);
135
+ if (scopeMatch) {
136
+ const segment = scopeMatch[1];
137
+ stack.push({
138
+ ...state,
139
+ collectionPath: joinRoutePath(state.collectionPath, segment),
140
+ memberPath: joinRoutePath(state.memberPath || state.collectionPath, segment)
141
+ });
142
+ continue;
143
+ }
144
+
145
+ const resourcesMatch = line.match(/^resources\s+:([A-Za-z_][A-Za-z0-9_]*)(?:,\s*(.*?))?\s*(do)?$/);
146
+ if (resourcesMatch) {
147
+ const [, resourceName, rawOptions = "", hasBlock] = resourcesMatch;
148
+ const built = buildResourceRoutes(state, resourceName, rawOptions);
149
+ routes.push(...built.routes);
150
+ if (hasBlock) {
151
+ stack.push(built.nextState);
152
+ }
153
+ continue;
154
+ }
155
+
156
+ const explicitRouteMatch = line.match(/^(get|post|put|patch|delete)\s+(:[A-Za-z_][A-Za-z0-9_]*|["'][^"']+["'])(?:,\s*(.*))?$/);
157
+ if (explicitRouteMatch) {
158
+ const [, method, rawPath, rawOptions = ""] = explicitRouteMatch;
159
+ routes.push(buildExplicitRoute(state, method, rawPath, rawOptions));
160
+ }
161
+ }
162
+
163
+ return routes;
164
+ }
165
+
166
+ export const railsRoutesExtractor = {
167
+ id: "api.rails-routes",
168
+ track: "api",
169
+ detect(context) {
170
+ const routeFiles = findImportFiles(context.paths, (filePath) => /config\/routes\.rb$/i.test(filePath));
171
+ return {
172
+ score: routeFiles.length > 0 ? 90 : 0,
173
+ reasons: routeFiles.length > 0 ? ["Found Rails routes.rb"] : []
174
+ };
175
+ },
176
+ extract(context) {
177
+ const routeFiles = findImportFiles(context.paths, (filePath) => /config\/routes\.rb$/i.test(filePath));
178
+ const findings = [];
179
+ const candidates = { capabilities: [], routes: [], stacks: [] };
180
+
181
+ for (const filePath of routeFiles) {
182
+ let routes = parseRailsRoutes(context.helpers.readTextIfExists(filePath) || "");
183
+ if (routes.some((route) => normalizeOpenApiPath(route.path).startsWith("/api/"))) {
184
+ routes = routes.filter((route) => normalizeOpenApiPath(route.path).startsWith("/api/"));
185
+ }
186
+
187
+ const provenanceBase = relativeTo(context.paths.repoRoot, filePath);
188
+ findings.push({
189
+ kind: "rails_routes",
190
+ file: provenanceBase,
191
+ route_count: routes.length
192
+ });
193
+
194
+ candidates.capabilities.push(...routes.map((route) => makeCandidateRecord({
195
+ kind: "capability",
196
+ idHint: inferRouteCapabilityId(route),
197
+ label: route.handler_hint ? titleCase(route.handler_hint) : `${route.method} ${route.path}`,
198
+ confidence: "high",
199
+ sourceKind: "route_code",
200
+ provenance: `${provenanceBase}#${route.method} ${route.path}`,
201
+ endpoint: { method: route.method, path: normalizeOpenApiPath(route.path) },
202
+ path_params: [...normalizeOpenApiPath(route.path).matchAll(/\{([^}]+)\}/g)].map((entry) => ({ name: entry[1], required: true, type: null })),
203
+ query_params: [],
204
+ header_params: [],
205
+ input_fields: [],
206
+ output_fields: [],
207
+ auth_hint: route.auth_hint || "unknown",
208
+ entity_id: inferApiEntityIdFromPath(route.path),
209
+ track: "api"
210
+ })));
211
+
212
+ candidates.routes.push(...routes.map((route) => ({
213
+ path: normalizeOpenApiPath(route.path),
214
+ method: route.method,
215
+ confidence: "high",
216
+ source_kind: "route_code",
217
+ provenance: `${provenanceBase}#${route.method} ${route.path}`
218
+ })));
219
+ }
220
+
221
+ candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (record) => record.id_hint);
222
+ candidates.routes = dedupeCandidateRecords(
223
+ candidates.routes.map((route) => ({ ...route, id_hint: `${route.method}_${route.path}` })),
224
+ (record) => `${record.method}:${record.path}:${record.source_kind}`
225
+ ).map(({ id_hint, ...route }) => route);
226
+ candidates.stacks = ["rails"];
227
+
228
+ return { findings, candidates };
229
+ }
230
+ };
@@ -0,0 +1,128 @@
1
+ import {
2
+ canonicalCandidateTerm,
3
+ dedupeCandidateRecords,
4
+ findImportFiles,
5
+ makeCandidateRecord,
6
+ relativeTo,
7
+ titleCase
8
+ } from "../../core/shared.js";
9
+
10
+ function pluralizeStem(stem) {
11
+ if (stem.endsWith("s")) return stem;
12
+ return `${stem}s`;
13
+ }
14
+
15
+ function stemFromRepoPath(filePath) {
16
+ return canonicalCandidateTerm(filePath.match(/\/src\/([^/]+)\//)?.[1] || "item");
17
+ }
18
+
19
+ function capabilityIdFor(stem, methodName, httpMethod) {
20
+ const normalizedMethod = String(methodName || "").toLowerCase();
21
+ if (httpMethod === "GET" && /^find/.test(normalizedMethod)) {
22
+ return `cap_get_${stem}`;
23
+ }
24
+ if (httpMethod === "GET") {
25
+ return `cap_list_${pluralizeStem(stem)}`;
26
+ }
27
+ if (httpMethod === "POST") {
28
+ return `cap_create_${stem}`;
29
+ }
30
+ if (httpMethod === "PATCH" || httpMethod === "PUT") {
31
+ return `cap_update_${stem}`;
32
+ }
33
+ if (httpMethod === "DELETE") {
34
+ return `cap_delete_${stem}`;
35
+ }
36
+ return `cap_${normalizedMethod}_${stem}`;
37
+ }
38
+
39
+ function parseRepositoryFile(text, provenance, filePath) {
40
+ const stem = stemFromRepoPath(filePath);
41
+ const baseUrlMatch = String(text || "").match(/baseUrl\s*=\s*["'`]([^"'`]+)["'`]/);
42
+ const basePath = baseUrlMatch?.[1] || `/${pluralizeStem(stem)}`;
43
+ const capabilities = [];
44
+ const methods = [...String(text || "").matchAll(/public\s+async\s+([A-Za-z_][A-Za-z0-9_]*)\(([\s\S]*?)\)\s*(?::\s*[\s\S]*?)?\s*\{/g)];
45
+ for (let index = 0; index < methods.length; index += 1) {
46
+ const [, methodName, argsSource] = methods[index];
47
+ const bodyStart = methods[index].index + methods[index][0].length;
48
+ const bodyEnd = index + 1 < methods.length ? methods[index + 1].index : String(text || "").length;
49
+ const body = String(text || "").slice(bodyStart, bodyEnd);
50
+ const callMatch = body.match(/this\.httpClient\.(get|post|patch|put|delete)(?:<[\s\S]*?>)?\(([\s\S]*?)\)/i);
51
+ if (!callMatch) continue;
52
+ const httpMethod = callMatch[1].toUpperCase();
53
+ const path = /\$\{this\.baseUrl\}\/\$\{/.test(callMatch[2])
54
+ ? `${basePath}/{id}`
55
+ : basePath;
56
+ const pathParams = /\{id\}/.test(path) ? [{ name: "id", required: true, type: "int" }] : [];
57
+ const inputFields = [...new Set([
58
+ ...[...String(argsSource || "").matchAll(/([A-Za-z_][A-Za-z0-9_]*)\s*:/g)].map((entry) => entry[1]),
59
+ ...[...String(body || "").matchAll(/payload\.([A-Za-z_][A-Za-z0-9_]*)/g)].map((entry) => entry[1])
60
+ ])].filter((field) => field !== "id");
61
+ const outputFields = httpMethod === "GET"
62
+ ? (/count/.test(body) ? [pluralizeStem(stem), "count"] : (/map\(/.test(body) ? [pluralizeStem(stem)] : ["id", "title", "body"]))
63
+ : [];
64
+ capabilities.push(makeCandidateRecord({
65
+ kind: "capability",
66
+ idHint: capabilityIdFor(stem, methodName, httpMethod),
67
+ label: titleCase(capabilityIdFor(stem, methodName, httpMethod).replace(/^cap_/, "")),
68
+ confidence: "high",
69
+ sourceKind: "route_code",
70
+ provenance: `${provenance}#${methodName}`,
71
+ endpoint: { method: httpMethod, path },
72
+ path_params: pathParams,
73
+ query_params: [],
74
+ header_params: [],
75
+ input_fields: inputFields,
76
+ output_fields: outputFields,
77
+ auth_hint: "public",
78
+ entity_id: `entity_${stem}`,
79
+ track: "api"
80
+ }));
81
+ }
82
+ return capabilities;
83
+ }
84
+
85
+ export const reactNativeRepositoryExtractor = {
86
+ id: "api.react-native-repository",
87
+ track: "api",
88
+ detect(context) {
89
+ const files = findImportFiles(
90
+ context.paths,
91
+ (filePath) => /\/src\/.+\/infrastructure\/implementations\/.+Repository\.ts$/i.test(filePath)
92
+ );
93
+ const score = files.some((filePath) => /this\.httpClient\.(get|post|patch|put|delete)\(/.test(context.helpers.readTextIfExists(filePath) || "")) ? 84 : 0;
94
+ return {
95
+ score,
96
+ reasons: score > 0 ? ["Found React Native repositories backed by an HTTP client"] : []
97
+ };
98
+ },
99
+ extract(context) {
100
+ const files = findImportFiles(
101
+ context.paths,
102
+ (filePath) => /\/src\/.+\/infrastructure\/implementations\/.+Repository\.ts$/i.test(filePath)
103
+ );
104
+ const capabilities = [];
105
+ for (const filePath of files) {
106
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
107
+ capabilities.push(...parseRepositoryFile(context.helpers.readTextIfExists(filePath) || "", provenance, filePath));
108
+ }
109
+ return {
110
+ findings: capabilities.length > 0 ? [{
111
+ kind: "react_native_repository",
112
+ files: [...new Set(capabilities.flatMap((entry) => entry.provenance || []).map((entry) => String(entry).split("#")[0]))],
113
+ capability_count: capabilities.length
114
+ }] : [],
115
+ candidates: {
116
+ capabilities: dedupeCandidateRecords(capabilities, (record) => `${record.id_hint}:${record.endpoint?.method}:${record.endpoint?.path}`),
117
+ routes: capabilities.map((entry) => ({
118
+ path: entry.endpoint.path,
119
+ method: entry.endpoint.method,
120
+ confidence: entry.confidence,
121
+ source_kind: entry.source_kind,
122
+ provenance: entry.provenance?.[0] || null
123
+ })),
124
+ stacks: capabilities.length > 0 ? ["react_native_http"] : []
125
+ }
126
+ };
127
+ }
128
+ };