@topogram/cli 0.3.63 → 0.3.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (344) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan/index.js +703 -0
  3. package/src/adoption/plan.d.ts +6 -0
  4. package/src/adoption/plan.js +12 -703
  5. package/src/adoption/reporting.d.ts +10 -0
  6. package/src/adoption/review-groups.d.ts +6 -0
  7. package/src/agent-brief.d.ts +3 -0
  8. package/src/agent-brief.js +495 -0
  9. package/src/agent-ops/query-builders/auth.js +375 -0
  10. package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
  11. package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
  12. package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
  13. package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
  14. package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
  15. package/src/agent-ops/query-builders/change-risk.js +25 -0
  16. package/src/agent-ops/query-builders/common.js +149 -0
  17. package/src/agent-ops/query-builders/maintained-risk.js +539 -0
  18. package/src/agent-ops/query-builders/maintained-shared.js +120 -0
  19. package/src/agent-ops/query-builders/multi-agent.js +547 -0
  20. package/src/agent-ops/query-builders/projection-impacts.js +514 -0
  21. package/src/agent-ops/query-builders/work-packets.js +417 -0
  22. package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
  23. package/src/agent-ops/query-builders/workflow-context.js +398 -0
  24. package/src/agent-ops/query-builders/workflow-presets-core.js +676 -0
  25. package/src/agent-ops/query-builders/workflow-presets.js +341 -0
  26. package/src/agent-ops/query-builders.d.ts +26 -0
  27. package/src/agent-ops/query-builders.js +42 -5021
  28. package/src/archive/archive.d.ts +2 -0
  29. package/src/archive/compact.d.ts +1 -0
  30. package/src/archive/unarchive.d.ts +1 -0
  31. package/src/catalog/constants.js +10 -0
  32. package/src/catalog/copy.js +60 -0
  33. package/src/catalog/diagnostics.js +15 -0
  34. package/src/catalog/entries.js +42 -0
  35. package/src/catalog/files.js +67 -0
  36. package/src/catalog/provenance.js +122 -0
  37. package/src/catalog/source.js +150 -0
  38. package/src/catalog/validation.js +252 -0
  39. package/src/catalog.d.ts +12 -0
  40. package/src/catalog.js +18 -750
  41. package/src/cli/catalog-alias.d.ts +1 -0
  42. package/src/cli/command-parser.js +38 -0
  43. package/src/cli/command-parsers/core.js +102 -0
  44. package/src/cli/command-parsers/generator.js +39 -0
  45. package/src/cli/command-parsers/import.js +44 -0
  46. package/src/cli/command-parsers/legacy-workflow.js +21 -0
  47. package/src/cli/command-parsers/project.js +47 -0
  48. package/src/cli/command-parsers/sdlc.js +47 -0
  49. package/src/cli/command-parsers/shared.js +51 -0
  50. package/src/cli/command-parsers/template.js +48 -0
  51. package/src/cli/commands/agent.js +47 -0
  52. package/src/cli/commands/catalog/check.js +31 -0
  53. package/src/cli/commands/catalog/copy.js +59 -0
  54. package/src/cli/commands/catalog/doctor.js +248 -0
  55. package/src/cli/commands/catalog/help.js +21 -0
  56. package/src/cli/commands/catalog/list.js +52 -0
  57. package/src/cli/commands/catalog/runner.js +92 -0
  58. package/src/cli/commands/catalog/shared.js +17 -0
  59. package/src/cli/commands/catalog/show.js +134 -0
  60. package/src/cli/commands/catalog.js +32 -0
  61. package/src/cli/commands/check.js +268 -0
  62. package/src/cli/commands/doctor.js +268 -0
  63. package/src/cli/commands/emit.js +149 -0
  64. package/src/cli/commands/generate.js +96 -0
  65. package/src/cli/commands/generator-policy/package-info.js +162 -0
  66. package/src/cli/commands/generator-policy/payloads.js +372 -0
  67. package/src/cli/commands/generator-policy/printers.js +159 -0
  68. package/src/cli/commands/generator-policy/runner.js +81 -0
  69. package/src/cli/commands/generator-policy/shared.js +39 -0
  70. package/src/cli/commands/generator-policy.js +17 -0
  71. package/src/cli/commands/generator.js +443 -0
  72. package/src/cli/commands/import/adopt.js +170 -0
  73. package/src/cli/commands/import/check.js +91 -0
  74. package/src/cli/commands/import/diff.js +84 -0
  75. package/src/cli/commands/import/help.js +47 -0
  76. package/src/cli/commands/import/paths.js +277 -0
  77. package/src/cli/commands/import/plan.js +284 -0
  78. package/src/cli/commands/import/refresh.js +470 -0
  79. package/src/cli/commands/import/status-history.js +196 -0
  80. package/src/cli/commands/import/workspace.js +230 -0
  81. package/src/cli/commands/import-runner.js +157 -0
  82. package/src/cli/commands/import.js +35 -0
  83. package/src/cli/commands/inspect.js +55 -0
  84. package/src/cli/commands/new.js +94 -0
  85. package/src/cli/commands/package/constants.js +17 -0
  86. package/src/cli/commands/package/doctor.js +240 -0
  87. package/src/cli/commands/package/help.js +27 -0
  88. package/src/cli/commands/package/lockfile.js +135 -0
  89. package/src/cli/commands/package/npm.js +97 -0
  90. package/src/cli/commands/package/reporting.js +35 -0
  91. package/src/cli/commands/package/runner.js +33 -0
  92. package/src/cli/commands/package/shared.js +9 -0
  93. package/src/cli/commands/package/update-cli.js +252 -0
  94. package/src/cli/commands/package/versions.js +35 -0
  95. package/src/cli/commands/package.js +31 -0
  96. package/src/cli/commands/query/change-plan.js +68 -0
  97. package/src/cli/commands/query/definitions.js +202 -0
  98. package/src/cli/commands/query/import-adopt.js +121 -0
  99. package/src/cli/commands/query/runner/artifacts.js +102 -0
  100. package/src/cli/commands/query/runner/boundaries.js +211 -0
  101. package/src/cli/commands/query/runner/change.js +182 -0
  102. package/src/cli/commands/query/runner/import-adopt.js +111 -0
  103. package/src/cli/commands/query/runner/index.js +31 -0
  104. package/src/cli/commands/query/runner/output.js +12 -0
  105. package/src/cli/commands/query/runner/workflow.js +241 -0
  106. package/src/cli/commands/query/runner.js +3 -0
  107. package/src/cli/commands/query/workflow-context.js +5 -0
  108. package/src/cli/commands/query/workspace.js +274 -0
  109. package/src/cli/commands/query.js +11 -0
  110. package/src/cli/commands/release-rollout.js +257 -0
  111. package/src/cli/commands/release-shared.js +528 -0
  112. package/src/cli/commands/release-status.js +429 -0
  113. package/src/cli/commands/release.js +107 -0
  114. package/src/cli/commands/sdlc.js +168 -0
  115. package/src/cli/commands/setup.js +76 -0
  116. package/src/cli/commands/source.js +291 -0
  117. package/src/cli/commands/template/baseline.js +100 -0
  118. package/src/cli/commands/template/check.js +466 -0
  119. package/src/cli/commands/template/constants.js +8 -0
  120. package/src/cli/commands/template/diagnostics.js +26 -0
  121. package/src/cli/commands/template/help.js +28 -0
  122. package/src/cli/commands/template/lifecycle.js +404 -0
  123. package/src/cli/commands/template/list-show.js +287 -0
  124. package/src/cli/commands/template/policy.js +422 -0
  125. package/src/cli/commands/template/shared.js +127 -0
  126. package/src/cli/commands/template/updates.js +352 -0
  127. package/src/cli/commands/template-runner.js +198 -0
  128. package/src/cli/commands/template.js +43 -0
  129. package/src/cli/commands/trust.js +219 -0
  130. package/src/cli/commands/version.js +40 -0
  131. package/src/cli/commands/widget.js +168 -0
  132. package/src/cli/commands/workflow.js +63 -0
  133. package/src/cli/dispatcher.js +392 -0
  134. package/src/cli/help-dispatch.js +188 -0
  135. package/src/cli/help.js +296 -0
  136. package/src/cli/migration-guidance.js +59 -0
  137. package/src/cli/options.js +96 -0
  138. package/src/cli/output-safety.js +107 -0
  139. package/src/cli/path-normalization.js +29 -0
  140. package/src/cli.js +47 -11711
  141. package/src/example-implementation.d.ts +2 -0
  142. package/src/format.d.ts +1 -0
  143. package/src/generator/api/contracts.js +497 -0
  144. package/src/generator/api/metadata.js +221 -0
  145. package/src/generator/api/openapi.js +559 -0
  146. package/src/generator/api/schema.js +124 -0
  147. package/src/generator/api/types.d.ts +98 -0
  148. package/src/generator/api.js +3 -1195
  149. package/src/generator/check.d.ts +1 -0
  150. package/src/generator/context/bundle.d.ts +1 -0
  151. package/src/generator/context/shared/domain-sdlc.js +282 -0
  152. package/src/generator/context/shared/maintained-boundary.js +665 -0
  153. package/src/generator/context/shared/metrics.js +85 -0
  154. package/src/generator/context/shared/primitives.js +64 -0
  155. package/src/generator/context/shared/relationships.js +453 -0
  156. package/src/generator/context/shared/summaries.js +263 -0
  157. package/src/generator/context/shared/types.d.ts +207 -0
  158. package/src/generator/context/shared.d.ts +44 -0
  159. package/src/generator/context/shared.js +80 -1390
  160. package/src/generator/context/slice/core.js +397 -0
  161. package/src/generator/context/slice/sdlc.js +417 -0
  162. package/src/generator/context/slice/ui-packets.js +183 -0
  163. package/src/generator/context/slice.js +2 -859
  164. package/src/generator/native/parity-bundle.js +2 -1
  165. package/src/generator/registry/index.js +507 -0
  166. package/src/generator/registry.js +18 -504
  167. package/src/generator/runtime/environment/index.js +666 -0
  168. package/src/generator/runtime/environment.js +4 -666
  169. package/src/generator/runtime/runtime-check/index.js +554 -0
  170. package/src/generator/runtime/runtime-check.js +4 -554
  171. package/src/generator/runtime/shared/index.js +572 -0
  172. package/src/generator/runtime/shared.js +19 -570
  173. package/src/generator/shared.d.ts +2 -0
  174. package/src/generator/surfaces/shared.d.ts +3 -0
  175. package/src/generator/surfaces/web/html-escape.js +22 -0
  176. package/src/generator/surfaces/web/react.js +10 -8
  177. package/src/generator/surfaces/web/sveltekit.js +7 -5
  178. package/src/generator/surfaces/web/vanilla.js +8 -4
  179. package/src/generator/widget-conformance/behavior-report.js +258 -0
  180. package/src/generator/widget-conformance/checks.js +371 -0
  181. package/src/generator/widget-conformance/projection-context.js +200 -0
  182. package/src/generator/widget-conformance/report.js +166 -0
  183. package/src/generator/widget-conformance/types.d.ts +121 -0
  184. package/src/generator/widget-conformance.js +3 -824
  185. package/src/generator.d.ts +2 -0
  186. package/src/github-client.js +520 -0
  187. package/src/import/core/context.d.ts +3 -0
  188. package/src/import/core/contracts.d.ts +1 -0
  189. package/src/import/core/registry.d.ts +4 -0
  190. package/src/import/core/runner/candidates.js +217 -0
  191. package/src/import/core/runner/options.js +22 -0
  192. package/src/import/core/runner/reports.js +50 -0
  193. package/src/import/core/runner/run.js +79 -0
  194. package/src/import/core/runner/tracks.js +150 -0
  195. package/src/import/core/runner/ui-drafts.js +337 -0
  196. package/src/import/core/runner.js +3 -698
  197. package/src/import/core/shared/api-routes.js +221 -0
  198. package/src/import/core/shared/candidates.js +97 -0
  199. package/src/import/core/shared/files.js +177 -0
  200. package/src/import/core/shared/next-app.js +389 -0
  201. package/src/import/core/shared/types.d.ts +51 -0
  202. package/src/import/core/shared/ui-routes.js +230 -0
  203. package/src/import/core/shared.js +67 -910
  204. package/src/import/extractors/api/flutter-dio.js +4 -8
  205. package/src/import/extractors/api/react-native-repository.js +4 -8
  206. package/src/import/index.d.ts +4 -0
  207. package/src/import/provenance.d.ts +4 -0
  208. package/src/new-project/constants.js +128 -0
  209. package/src/new-project/create.js +83 -0
  210. package/src/new-project/json.js +28 -0
  211. package/src/new-project/metadata.js +96 -0
  212. package/src/new-project/package-spec.js +161 -0
  213. package/src/new-project/project-files.js +348 -0
  214. package/src/new-project/template-policy.js +269 -0
  215. package/src/new-project/template-resolution.js +368 -0
  216. package/src/new-project/template-snapshots.js +430 -0
  217. package/src/new-project/template-updates.js +512 -0
  218. package/src/new-project/types.d.ts +83 -0
  219. package/src/new-project.js +6 -2188
  220. package/src/npm-safety.js +79 -0
  221. package/src/parser.d.ts +87 -0
  222. package/src/parser.js +118 -0
  223. package/src/path-helpers.d.ts +1 -0
  224. package/src/path-helpers.js +20 -0
  225. package/src/policy/review-boundaries.d.ts +15 -0
  226. package/src/project-config/index.js +564 -0
  227. package/src/project-config.js +19 -560
  228. package/src/reconcile/docs.d.ts +8 -0
  229. package/src/reconcile/journeys.d.ts +1 -0
  230. package/src/resolver/enrich/acceptance-criterion.js +2 -0
  231. package/src/resolver/enrich/bug.js +2 -0
  232. package/src/resolver/enrich/pitch.js +2 -0
  233. package/src/resolver/enrich/requirement.js +2 -0
  234. package/src/resolver/enrich/task.js +2 -0
  235. package/src/resolver/index.js +19 -2089
  236. package/src/resolver/normalize.js +384 -1
  237. package/src/resolver/plans.js +168 -0
  238. package/src/resolver/projections-api.js +494 -0
  239. package/src/resolver/projections-db.js +133 -0
  240. package/src/resolver/projections-ui.js +317 -0
  241. package/src/resolver/shapes.js +251 -0
  242. package/src/resolver/shared.js +278 -0
  243. package/src/resolver/widgets.js +132 -0
  244. package/src/resolver.d.ts +1 -0
  245. package/src/runtime-support.js +29 -0
  246. package/src/sdlc/adopt.d.ts +1 -0
  247. package/src/sdlc/check.d.ts +1 -0
  248. package/src/sdlc/explain.d.ts +1 -0
  249. package/src/sdlc/release.d.ts +1 -0
  250. package/src/sdlc/scaffold.d.ts +1 -0
  251. package/src/sdlc/transition.d.ts +1 -0
  252. package/src/template-trust/constants.js +62 -0
  253. package/src/template-trust/content.js +258 -0
  254. package/src/template-trust/diff.js +92 -0
  255. package/src/template-trust/policy.js +61 -0
  256. package/src/template-trust/record.js +90 -0
  257. package/src/template-trust/status.js +182 -0
  258. package/src/template-trust.js +24 -687
  259. package/src/text-helpers.d.ts +7 -0
  260. package/src/text-helpers.js +245 -0
  261. package/src/topogram-config.js +306 -0
  262. package/src/topogram-types.d.ts +69 -0
  263. package/src/validator/common.js +488 -0
  264. package/src/validator/data-model.js +237 -0
  265. package/src/validator/docs.js +167 -0
  266. package/src/validator/expressions.js +146 -1
  267. package/src/validator/index.d.ts +23 -0
  268. package/src/validator/index.js +32 -3585
  269. package/src/validator/kinds.d.ts +41 -0
  270. package/src/validator/kinds.js +2 -0
  271. package/src/validator/model-helpers.js +46 -0
  272. package/src/validator/per-kind/acceptance-criterion.js +5 -0
  273. package/src/validator/per-kind/bug.js +6 -0
  274. package/src/validator/per-kind/domain.js +15 -2
  275. package/src/validator/per-kind/pitch.js +7 -0
  276. package/src/validator/per-kind/requirement.js +5 -0
  277. package/src/validator/per-kind/task.js +7 -0
  278. package/src/validator/per-kind/widget.js +14 -0
  279. package/src/validator/projections/api-http-async.js +410 -0
  280. package/src/validator/projections/api-http-authz.js +88 -0
  281. package/src/validator/projections/api-http-core.js +205 -0
  282. package/src/validator/projections/api-http-policies.js +339 -0
  283. package/src/validator/projections/api-http-responses.js +233 -0
  284. package/src/validator/projections/api-http.js +44 -0
  285. package/src/validator/projections/db.js +353 -0
  286. package/src/validator/projections/generator-defaults.js +45 -0
  287. package/src/validator/projections/helpers.js +87 -0
  288. package/src/validator/projections/ui-helpers.js +214 -0
  289. package/src/validator/projections/ui-navigation.js +344 -0
  290. package/src/validator/projections/ui-structure.js +364 -0
  291. package/src/validator/projections/ui-widgets.js +493 -0
  292. package/src/validator/projections/ui.js +46 -0
  293. package/src/validator/registry.js +48 -1
  294. package/src/validator/utils.d.ts +20 -0
  295. package/src/validator/utils.js +115 -12
  296. package/src/validator.d.ts +2 -0
  297. package/src/widget-behavior.d.ts +1 -0
  298. package/src/workflows/adoption/index.js +26 -0
  299. package/src/workflows/docs-generate.js +262 -0
  300. package/src/workflows/docs-scan.js +703 -0
  301. package/src/workflows/docs.js +15 -0
  302. package/src/workflows/import-app/api/collect.js +221 -0
  303. package/src/workflows/import-app/api/openapi.js +257 -0
  304. package/src/workflows/import-app/api/routes.js +327 -0
  305. package/src/workflows/import-app/api/sources.js +22 -0
  306. package/src/workflows/import-app/api.js +4 -0
  307. package/src/workflows/import-app/db.js +538 -0
  308. package/src/workflows/import-app/index.js +30 -0
  309. package/src/workflows/import-app/shared.js +218 -0
  310. package/src/workflows/import-app/ui.js +443 -0
  311. package/src/workflows/import-app/workflow.js +159 -0
  312. package/src/workflows/reconcile/adoption-plan/build.js +208 -0
  313. package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
  314. package/src/workflows/reconcile/adoption-plan/outputs.js +143 -0
  315. package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
  316. package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
  317. package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
  318. package/src/workflows/reconcile/adoption-plan.js +32 -0
  319. package/src/workflows/reconcile/auth/closures.js +115 -0
  320. package/src/workflows/reconcile/auth/formatters.js +142 -0
  321. package/src/workflows/reconcile/auth/inference.js +330 -0
  322. package/src/workflows/reconcile/auth/roles.js +122 -0
  323. package/src/workflows/reconcile/auth.js +37 -0
  324. package/src/workflows/reconcile/bundle-core/index.js +600 -0
  325. package/src/workflows/reconcile/bundle-core.js +14 -0
  326. package/src/workflows/reconcile/bundle-shared.js +75 -0
  327. package/src/workflows/reconcile/candidate-model.js +477 -0
  328. package/src/workflows/reconcile/canonical-surface.js +264 -0
  329. package/src/workflows/reconcile/gap-report.js +333 -0
  330. package/src/workflows/reconcile/ids.js +6 -0
  331. package/src/workflows/reconcile/impacts/adoption-plan.js +192 -0
  332. package/src/workflows/reconcile/impacts/indexes.js +101 -0
  333. package/src/workflows/reconcile/impacts/patches.js +252 -0
  334. package/src/workflows/reconcile/impacts/reports.js +80 -0
  335. package/src/workflows/reconcile/impacts.js +16 -0
  336. package/src/workflows/reconcile/index.js +7 -0
  337. package/src/workflows/reconcile/renderers.js +461 -0
  338. package/src/workflows/reconcile/summary.js +90 -0
  339. package/src/workflows/reconcile/workflow.js +309 -0
  340. package/src/workflows/shared.js +189 -0
  341. package/src/workflows/types.d.ts +93 -0
  342. package/src/workflows.d.ts +1 -0
  343. package/src/workflows.js +10 -7652
  344. package/src/workspace-docs.d.ts +29 -0
@@ -0,0 +1,389 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { relativeTo } from "../../../path-helpers.js";
5
+ import { canonicalCandidateTerm, idHintify } from "./candidates.js";
6
+ import { listFilesRecursive, readTextIfExists } from "./files.js";
7
+ import {
8
+ inferApiCapabilityIdFromOperation,
9
+ inferRouteCapabilityId,
10
+ normalizeEndpointPathForMatch,
11
+ normalizeOpenApiPath
12
+ } from "./api-routes.js";
13
+ import { entityIdForRoute, screenIdForRoute, screenKindForRoute, uiCapabilityHintsForRoute } from "./ui-routes.js";
14
+
15
+ /**
16
+ * @param {string} rootDir
17
+ * @returns {any}
18
+ */
19
+ export function inferNextAppRoutes(rootDir) {
20
+ const appDir = path.join(rootDir, "app");
21
+ if (!fs.existsSync(appDir)) return [];
22
+ const routeFiles = listFilesRecursive(
23
+ appDir,
24
+ /** @param {any} child */ (child) => /\/page\.(tsx|ts|jsx|js|mdx)$/.test(child) || /\/route\.(tsx|ts|jsx|js)$/.test(child)
25
+ );
26
+ const routes = [];
27
+ for (const filePath of routeFiles) {
28
+ const relative = relativeTo(appDir, filePath);
29
+ const isPage = /\/page\.(tsx|ts|jsx|js|mdx)$/.test(`/${relative}`) || /^page\.(tsx|ts|jsx|js|mdx)$/.test(relative);
30
+ const normalizedPath = `/${relative}`
31
+ .replace(/\/page\.(tsx|ts|jsx|js|mdx)$/, "")
32
+ .replace(/\/route\.(tsx|ts|jsx|js)$/, "")
33
+ .replace(/\[(\.\.\.)?([^\]]+)\]/g, /** @param {any} _m @param {any} catchAll @param {any} name */ (_m, catchAll, name) => catchAll ? `:${name}*` : `:${name}`)
34
+ .replace(/\/index$/, "")
35
+ .replace(/^\/$/, "/");
36
+ routes.push({
37
+ path: normalizedPath === "" ? "/" : normalizedPath,
38
+ kind: isPage ? "page" : "route",
39
+ file: filePath
40
+ });
41
+ }
42
+ return routes.sort(/** @param {any} a @param {any} b */ (a, b) => a.path.localeCompare(b.path) || a.kind.localeCompare(b.kind));
43
+ }
44
+
45
+ /**
46
+ * @param {string} routePath
47
+ * @returns {any}
48
+ */
49
+ export function nextScreenKindForRoute(routePath) {
50
+ const normalized = String(routePath || "");
51
+ if (/\/(login|register|setup)$/.test(normalized)) return "flow";
52
+ return screenKindForRoute(routePath);
53
+ }
54
+
55
+ /**
56
+ * @param {string} routePath
57
+ * @returns {any}
58
+ */
59
+ export function nextScreenIdForRoute(routePath) {
60
+ const normalized = String(routePath || "");
61
+ if (normalized === "/") return "home";
62
+ if (/\/login$/.test(normalized)) return "login";
63
+ if (/\/register$/.test(normalized)) return "register";
64
+ if (/\/setup$/.test(normalized)) return "setup";
65
+ return screenIdForRoute(routePath);
66
+ }
67
+
68
+ /**
69
+ * @param {string} routePath
70
+ * @returns {any}
71
+ */
72
+ export function entityIdForNextRoute(routePath) {
73
+ const normalized = String(routePath || "");
74
+ if (/^\/posts(\/|$)/.test(normalized)) return "entity_post";
75
+ if (/^\/users(\/|$)/.test(normalized)) return "entity_user";
76
+ return null;
77
+ }
78
+
79
+ /**
80
+ * @param {string} routePath
81
+ * @returns {any}
82
+ */
83
+ export function conceptIdForNextRoute(routePath) {
84
+ const normalized = String(routePath || "");
85
+ if (normalized === "/") return "surface_home";
86
+ if (/\/login$/.test(normalized)) return "flow_login";
87
+ if (/\/register$/.test(normalized)) return "flow_register";
88
+ if (/\/setup$/.test(normalized)) return "flow_setup";
89
+ return entityIdForNextRoute(routePath) || entityIdForRoute(routePath);
90
+ }
91
+
92
+ /**
93
+ * @param {string} routePath
94
+ * @returns {any}
95
+ */
96
+ export function uiCapabilityHintsForNextRoute(routePath) {
97
+ const normalized = String(routePath || "");
98
+ if (normalized === "/") return { load: null, submit: null, primary_action: null };
99
+ if (/\/login$/.test(normalized)) return { load: null, submit: "cap_sign_in_user", primary_action: "cap_sign_in_user" };
100
+ if (/\/register$/.test(normalized)) return { load: null, submit: "cap_register_user", primary_action: "cap_register_user" };
101
+ if (/\/setup$/.test(normalized)) return { load: null, submit: null, primary_action: null };
102
+ if (/^\/posts\/new$/.test(normalized)) return { load: null, submit: "cap_create_post", primary_action: "cap_create_post" };
103
+ if (/^\/posts\/:id$/.test(normalized) || /^\/posts\/:[^/]+$/.test(normalized)) return { load: "cap_get_post", submit: null, primary_action: "cap_update_post" };
104
+ if (/^\/posts$/.test(normalized)) return { load: "cap_list_posts", submit: null, primary_action: "cap_create_post" };
105
+ if (/^\/users\/new$/.test(normalized)) return { load: null, submit: "cap_create_user", primary_action: "cap_create_user" };
106
+ return uiCapabilityHintsForRoute(routePath);
107
+ }
108
+
109
+ /**
110
+ * @param {string} text
111
+ * @returns {any}
112
+ */
113
+ export function inferRouteQueryParams(text) {
114
+ const params = new Set();
115
+ for (const match of String(text || "").matchAll(/\bquery\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g)) params.add(match[1]);
116
+ for (const match of String(text || "").matchAll(/\bquery\.([A-Za-z_][A-Za-z0-9_]*)\b/g)) params.add(match[1]);
117
+ return [...params].sort();
118
+ }
119
+
120
+ /**
121
+ * @param {string} routeArguments
122
+ * @param {string} handlerContext
123
+ * @returns {any}
124
+ */
125
+ export function inferRouteAuthHint(routeArguments, handlerContext) {
126
+ const combined = `${routeArguments || ""}\n${handlerContext || ""}`.toLowerCase();
127
+ if (/\b(signin|sign_in|login|register|credentialsprovider)\b/.test(combined)) {
128
+ return "public";
129
+ }
130
+ return /\b(auth|session|permission|guard|protected|require_auth|requireauth|ensureauth)\b/.test(combined)
131
+ ? "secured"
132
+ : "unknown";
133
+ }
134
+
135
+ /**
136
+ * @param {string} text
137
+ * @param {string} exportName
138
+ * @returns {any}
139
+ */
140
+ export function extractNamedExportBlock(text, exportName) {
141
+ const escapedName = exportName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
142
+ const match = text.match(new RegExp(`export\\s+async\\s+function\\s+${escapedName}\\s*\\([^)]*\\)\\s*\\{([\\s\\S]{0,2000}?)\\n\\}`, "m"));
143
+ return match ? match[1] : "";
144
+ }
145
+
146
+ /**
147
+ * @param {string} text
148
+ * @returns {any}
149
+ */
150
+ export function inferNextRequestSearchParams(text) {
151
+ const params = new Set();
152
+ for (const match of String(text || "").matchAll(/searchParams\.get\(\s*["'`]([^"'`]+)["'`]\s*\)/g)) {
153
+ params.add(match[1]);
154
+ }
155
+ return [...params].sort();
156
+ }
157
+
158
+ /**
159
+ * @param {string} text
160
+ * @returns {any}
161
+ */
162
+ export function inferNextJsonFields(text) {
163
+ const fields = new Set();
164
+ for (const match of String(text || "").matchAll(/NextResponse\.json\(\s*\{([\s\S]{0,400}?)\}\s*\)/g)) {
165
+ for (const fieldMatch of match[1].matchAll(/\b([A-Za-z_][A-Za-z0-9_]*)\b\s*[:,]/g)) {
166
+ fields.add(fieldMatch[1]);
167
+ }
168
+ }
169
+ return [...fields].sort();
170
+ }
171
+
172
+ /**
173
+ * @param {string} text
174
+ * @param {string} handlerName
175
+ * @returns {any}
176
+ */
177
+ export function extractHandlerContext(text, handlerName) {
178
+ if (!handlerName) return "";
179
+ const escapedName = handlerName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
180
+ const patterns = [
181
+ new RegExp(`function\\s+${escapedName}\\s*\\([^)]*\\)\\s*\\{([\\s\\S]{0,1200}?)\\n\\}`, "m"),
182
+ new RegExp(`const\\s+${escapedName}\\s*=\\s*(?:async\\s*)?\\([^)]*\\)\\s*=>\\s*\\{([\\s\\S]{0,1200}?)\\n\\}`, "m")
183
+ ];
184
+ for (const pattern of patterns) {
185
+ const match = text.match(pattern);
186
+ if (match) return match[1];
187
+ }
188
+ return "";
189
+ }
190
+
191
+ /**
192
+ * @param {string} appRoot
193
+ * @param {string} filePath
194
+ * @returns {any}
195
+ */
196
+ export function nextAppRoutePathFromFile(appRoot, filePath) {
197
+ const relative = relativeTo(appRoot, filePath);
198
+ return `/${relative}`
199
+ .replace(/\/actions\.(tsx|ts|jsx|js)$/, "")
200
+ .replace(/\/page\.(tsx|ts|jsx|js|mdx)$/, "")
201
+ .replace(/\[(\.\.\.)?([^\]]+)\]/g, /** @param {any} _match @param {any} catchAll @param {any} name */ (_match, catchAll, name) => catchAll ? `:${name}*` : `:${name}`)
202
+ .replace(/\/index$/, "")
203
+ .replace(/^\/$/, "/") || "/";
204
+ }
205
+
206
+ /**
207
+ * @param {string} text
208
+ * @returns {any}
209
+ */
210
+ export function inferFormDataFields(text) {
211
+ const fields = new Set();
212
+ for (const match of String(text || "").matchAll(/formData\.get\(\s*["'`]([^"'`]+)["'`]\s*\)/g)) {
213
+ fields.add(match[1]);
214
+ }
215
+ return [...fields].sort();
216
+ }
217
+
218
+ /**
219
+ * @param {string} text
220
+ * @returns {any}
221
+ */
222
+ export function inferInputNames(text) {
223
+ const fields = new Set();
224
+ for (const match of String(text || "").matchAll(/\bname=["'`]([^"'`]+)["'`]/g)) {
225
+ fields.add(match[1]);
226
+ }
227
+ return [...fields].sort();
228
+ }
229
+
230
+ /**
231
+ * @param {string} workspaceRoot
232
+ * @param {import("./types.d.ts").ImportReadHelpers} helpers
233
+ * @returns {any}
234
+ */
235
+ export function inferNextApiRoutes(workspaceRoot, helpers = { readTextIfExists }) {
236
+ const apiRoot = path.join(workspaceRoot, "app", "api");
237
+ if (!fs.existsSync(apiRoot)) return [];
238
+ const routeFiles = listFilesRecursive(
239
+ apiRoot,
240
+ /** @param {any} child */ (child) => /\/route\.(tsx|ts|jsx|js)$/.test(child) || /^route\.(tsx|ts|jsx|js)$/.test(path.basename(child))
241
+ );
242
+ const routes = [];
243
+ for (const filePath of routeFiles) {
244
+ const text = helpers.readTextIfExists(filePath) || "";
245
+ const relative = relativeTo(apiRoot, filePath);
246
+ const routePath = `/${relative}`
247
+ .replace(/\/route\.(tsx|ts|jsx|js)$/, "")
248
+ .replace(/\[(\.\.\.)?([^\]]+)\]/g, /** @param {any} _match @param {any} catchAll @param {any} name */ (_match, catchAll, name) => catchAll ? `:${name}*` : `:${name}`);
249
+ for (const match of text.matchAll(/export\s+async\s+function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(([^)]*)\)/g)) {
250
+ const method = match[1].toUpperCase();
251
+ const handlerContext = extractNamedExportBlock(text, match[1]) || "";
252
+ routes.push({
253
+ file: filePath,
254
+ method,
255
+ path: routePath === "" ? "/" : routePath,
256
+ handler_hint: match[1].toLowerCase(),
257
+ path_params: [...normalizeOpenApiPath(routePath).matchAll(/\{([^}]+)\}/g)].map(/** @param {any} entry */ (entry) => entry[1]),
258
+ query_params: inferNextRequestSearchParams(handlerContext),
259
+ output_fields: inferNextJsonFields(handlerContext),
260
+ auth_hint: inferRouteAuthHint(match[0], handlerContext),
261
+ source_kind: "route_code"
262
+ });
263
+ }
264
+ }
265
+ return routes;
266
+ }
267
+
268
+ /**
269
+ * @param {import("./types.d.ts").ImportRouteRecord} record
270
+ * @returns {any}
271
+ */
272
+ export function inferCapabilityEntityId(record) {
273
+ if (record.entity_id) {
274
+ return record.entity_id;
275
+ }
276
+ const pathSegments = normalizeEndpointPathForMatch(record.endpoint?.path || "")
277
+ .split("/")
278
+ .filter(Boolean)
279
+ .filter(/** @param {any} segment */ (segment) => segment !== "{}");
280
+ const resourceSegment = pathSegments[0] || String(record.id_hint || "").replace(/^cap_(create|update|delete|get|list)_/, "");
281
+ return `entity_${idHintify(canonicalCandidateTerm(resourceSegment))}`;
282
+ }
283
+
284
+ /**
285
+ * @param {string} workspaceRoot
286
+ * @param {import("./types.d.ts").ImportReadHelpers} helpers
287
+ * @returns {any}
288
+ */
289
+ export function inferNextServerActionCapabilities(workspaceRoot, helpers = { readTextIfExists }) {
290
+ const appRoot = path.join(workspaceRoot, "app");
291
+ if (!fs.existsSync(appRoot)) return [];
292
+ const actionFiles = listFilesRecursive(
293
+ appRoot,
294
+ /** @param {any} child */ (child) =>
295
+ /\/actions\.(tsx|ts|jsx|js)$/.test(child) ||
296
+ /\/page\.(tsx|ts|jsx|js|mdx)$/.test(child) ||
297
+ /^page\.(tsx|ts|jsx|js|mdx)$/.test(path.basename(child))
298
+ );
299
+ const capabilities = [];
300
+ for (const filePath of actionFiles) {
301
+ const text = helpers.readTextIfExists(filePath) || "";
302
+ const routePath = nextAppRoutePathFromFile(appRoot, filePath);
303
+ for (const match of text.matchAll(/(?:export\s+)?async\s+function\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([^)]*)\)\s*\{([\s\S]{0,2400}?)\n\}/g)) {
304
+ const functionName = match[1];
305
+ const body = match[3] || "";
306
+ const trimmedBody = body.trimStart();
307
+ const isServerAction =
308
+ /\/actions\.(tsx|ts|jsx|js)$/.test(filePath) ||
309
+ trimmedBody.startsWith('"use server"') ||
310
+ trimmedBody.startsWith("'use server'");
311
+ if (!isServerAction) continue;
312
+ const routeLike = {
313
+ file: filePath,
314
+ method: "POST",
315
+ path: routePath,
316
+ handler_hint: functionName,
317
+ auth_hint: inferRouteAuthHint(functionName, body)
318
+ };
319
+ const idHint = inferRouteCapabilityId(routeLike);
320
+ capabilities.push({
321
+ file: filePath,
322
+ function_name: functionName,
323
+ method: "POST",
324
+ path: routePath,
325
+ id_hint: idHint,
326
+ input_fields: inferFormDataFields(body),
327
+ output_fields: [],
328
+ path_params: [...normalizeOpenApiPath(routePath).matchAll(/\{([^}]+)\}/g)].map(/** @param {any} entry */ (entry) => entry[1]),
329
+ auth_hint: routeLike.auth_hint,
330
+ entity_id: inferCapabilityEntityId({ endpoint: { path: routePath }, id_hint: idHint }),
331
+ source_kind: "route_code"
332
+ });
333
+ }
334
+ }
335
+ return capabilities.sort(/** @param {any} a @param {any} b */ (a, b) => a.id_hint.localeCompare(b.id_hint) || a.path.localeCompare(b.path));
336
+ }
337
+
338
+ /**
339
+ * @param {import("./types.d.ts").ImportPaths} paths
340
+ * @param {import("./types.d.ts").ImportReadHelpers} helpers
341
+ * @returns {any}
342
+ */
343
+ export function inferNextAuthCapabilities(paths, helpers = { readTextIfExists }) {
344
+ const authConfigPath = path.join(paths.workspaceRoot, "auth.ts");
345
+ const authConfigText = helpers.readTextIfExists(authConfigPath) || "";
346
+ const hasCredentialsProvider = /CredentialsProvider\s*\(/.test(authConfigText);
347
+ const createsUserOnAuthorize = /prisma\.user\.create\s*\(/.test(authConfigText);
348
+ const pages = [
349
+ {
350
+ file: path.join(paths.workspaceRoot, "app", "login", "page.tsx"),
351
+ path: "/login",
352
+ id_hint: "cap_sign_in_user",
353
+ label: "Sign In User",
354
+ target_state: "authenticated"
355
+ },
356
+ {
357
+ file: path.join(paths.workspaceRoot, "app", "register", "page.tsx"),
358
+ path: "/register",
359
+ id_hint: "cap_register_user",
360
+ label: "Register User",
361
+ target_state: createsUserOnAuthorize ? "registered" : "created"
362
+ }
363
+ ];
364
+ const capabilities = [];
365
+ for (const page of pages) {
366
+ const text = helpers.readTextIfExists(page.file) || "";
367
+ if (!text || !/signIn\(\s*["'`]credentials["'`]/.test(text)) continue;
368
+ capabilities.push({
369
+ file: page.file,
370
+ function_name: page.id_hint.replace(/^cap_/, ""),
371
+ method: "POST",
372
+ path: page.path,
373
+ id_hint: page.id_hint,
374
+ label: page.label,
375
+ input_fields: inferInputNames(text),
376
+ output_fields: [],
377
+ path_params: [],
378
+ auth_hint: "public",
379
+ entity_id: "entity_user",
380
+ target_state: page.target_state,
381
+ provenance: [
382
+ relativeTo(paths.repoRoot, page.file),
383
+ ...(hasCredentialsProvider ? [relativeTo(paths.repoRoot, authConfigPath)] : [])
384
+ ],
385
+ source_kind: "route_code"
386
+ });
387
+ }
388
+ return capabilities.sort(/** @param {any} a @param {any} b */ (a, b) => a.id_hint.localeCompare(b.id_hint));
389
+ }
@@ -0,0 +1,51 @@
1
+ export type ImportPaths = {
2
+ repoRoot: string;
3
+ workspaceRoot: string;
4
+ topogramRoot: string;
5
+ [key: string]: any;
6
+ };
7
+
8
+ export type ImportReadHelpers = {
9
+ readTextIfExists(filePath: string): string | null;
10
+ [key: string]: any;
11
+ };
12
+
13
+ export type ImportRouteRecord = {
14
+ endpoint?: {
15
+ path?: string;
16
+ };
17
+ path?: string;
18
+ method?: string;
19
+ handler_hint?: string;
20
+ id_hint?: string;
21
+ entity_id?: string | null;
22
+ auth_hint?: string;
23
+ tags?: string[];
24
+ [key: string]: any;
25
+ };
26
+
27
+ export type ImportCandidateRecord = {
28
+ kind: string;
29
+ id?: string;
30
+ id_hint?: string;
31
+ idHint?: string;
32
+ label: string;
33
+ confidence?: string;
34
+ source_kind?: string;
35
+ source_of_truth?: string;
36
+ [key: string]: any;
37
+ };
38
+
39
+ export type NavigationStructure = {
40
+ hasHeader?: boolean;
41
+ hasSidebar?: boolean;
42
+ hasTopbar?: boolean;
43
+ hasBottomTabs?: boolean;
44
+ hasTabs?: boolean;
45
+ hasBreadcrumbs?: boolean;
46
+ hasCommandPalette?: boolean;
47
+ hasSegmentedControl?: boolean;
48
+ hasRail?: boolean;
49
+ navLinks?: string[];
50
+ [key: string]: any;
51
+ };
@@ -0,0 +1,230 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { relativeTo } from "../../../path-helpers.js";
5
+ import { canonicalCandidateTerm } from "./candidates.js";
6
+ import { listFilesRecursive, readTextIfExists } from "./files.js";
7
+
8
+ /**
9
+ * @param {string} routePath
10
+ * @returns {any}
11
+ */
12
+ export function routeSegments(routePath) {
13
+ return String(routePath || "")
14
+ .split("/")
15
+ .filter(Boolean)
16
+ .map(/** @param {any} segment */ (segment) => segment.replace(/^:/, ""));
17
+ }
18
+
19
+ /**
20
+ * @param {string} routePath
21
+ * @returns {any}
22
+ */
23
+ export function screenKindForRoute(routePath) {
24
+ const normalized = String(routePath || "");
25
+ const segments = routeSegments(normalized);
26
+ if (/\/new$/.test(normalized)) return "form";
27
+ if (/\/:?[A-Za-z0-9_]+\/edit$/.test(normalized)) return "form";
28
+ if (segments.length >= 2 && !/\/new$/.test(normalized) && !/\/edit$/.test(normalized)) return "detail";
29
+ return "list";
30
+ }
31
+
32
+ /**
33
+ * @param {string} routePath
34
+ * @returns {any}
35
+ */
36
+ export function screenIdForRoute(routePath) {
37
+ const segments = routeSegments(routePath);
38
+ const resource = canonicalCandidateTerm(segments[0] || "home");
39
+ const kind = screenKindForRoute(routePath);
40
+ if (kind === "form" && /\/new$/.test(routePath)) return `${resource}_create`;
41
+ if (kind === "form" && /\/edit$/.test(routePath)) return `${resource}_edit`;
42
+ if (kind === "detail") return `${resource}_detail`;
43
+ return `${resource}_list`;
44
+ }
45
+
46
+ /**
47
+ * @param {string} routePath
48
+ * @returns {any}
49
+ */
50
+ export function uiCapabilityHintsForRoute(routePath) {
51
+ const segments = routeSegments(routePath);
52
+ const resource = canonicalCandidateTerm(segments[0] || "item");
53
+ const idSegment = segments[1] || null;
54
+ if (/\/new$/.test(routePath)) {
55
+ return { load: null, submit: `cap_create_${resource}`, primary_action: `cap_create_${resource}` };
56
+ }
57
+ if (/\/edit$/.test(routePath)) {
58
+ return { load: `cap_get_${resource}`, submit: `cap_update_${resource}`, primary_action: `cap_update_${resource}` };
59
+ }
60
+ if (idSegment && !/new|edit/.test(idSegment)) {
61
+ return { load: `cap_get_${resource}`, submit: null, primary_action: `cap_update_${resource}` };
62
+ }
63
+ return { load: `cap_list_${resource}s`, submit: null, primary_action: `cap_create_${resource}` };
64
+ }
65
+
66
+ /**
67
+ * @param {string} routePath
68
+ * @returns {any}
69
+ */
70
+ export function entityIdForRoute(routePath) {
71
+ const segments = routeSegments(routePath);
72
+ return `entity_${canonicalCandidateTerm(segments[0] || "item")}`;
73
+ }
74
+
75
+ /**
76
+ * @param {string} rootDir
77
+ * @returns {any}
78
+ */
79
+ export function inferReactRoutes(rootDir) {
80
+ const appPath = path.join(rootDir, "src", "App.tsx");
81
+ const text = readTextIfExists(appPath);
82
+ if (!text) return [];
83
+ const routes = new Set();
84
+ for (const match of text.matchAll(/path:\s*"([^"]+)"/g)) routes.add(match[1]);
85
+ for (const match of text.matchAll(/path="([^"]+)"/g)) routes.add(match[1]);
86
+ return [...routes].sort();
87
+ }
88
+
89
+ /**
90
+ * @param {string} rootDir
91
+ * @returns {any}
92
+ */
93
+ export function inferSvelteRoutes(rootDir) {
94
+ const routesRoot = path.join(rootDir, "src", "routes");
95
+ if (!fs.existsSync(routesRoot)) return [];
96
+ const files = listFilesRecursive(routesRoot, /** @param {any} child */ (child) => child.endsWith("+page.svelte") || child.endsWith("+page.ts") || child.endsWith("+page.server.ts"));
97
+ const routes = new Set();
98
+ for (const filePath of files) {
99
+ const relative = relativeTo(routesRoot, filePath)
100
+ .replace(/(^|\/)\+page(\.server|)\.(svelte|ts)$/, "")
101
+ .replace(/\[(.+?)\]/g, ":$1")
102
+ .replace(/^$/, "/");
103
+ routes.add(relative.startsWith("/") ? relative : `/${relative}`);
104
+ }
105
+ return [...routes].sort();
106
+ }
107
+
108
+ /**
109
+ * @param {string} rootDir
110
+ * @param {any} options
111
+ * @returns {any}
112
+ */
113
+ export function inferNavigationStructure(rootDir, options = {}) {
114
+ const filePatterns = options.filePatterns || [/(^|\/)App\.(tsx|jsx)$/i, /(^|\/)\+layout\.svelte$/i];
115
+ const files = listFilesRecursive(rootDir, /** @param {any} filePath */ (filePath) => filePatterns.some(/** @param {any} pattern */ (pattern) => pattern.test(filePath)));
116
+ const result = /** @type {any} */ ({
117
+ hasHeader: false,
118
+ hasSidebar: false,
119
+ hasTopbar: false,
120
+ hasBottomTabs: false,
121
+ hasTabs: false,
122
+ hasBreadcrumbs: false,
123
+ hasCommandPalette: false,
124
+ hasSegmentedControl: false,
125
+ navLinks: []
126
+ });
127
+
128
+ for (const filePath of files) {
129
+ const text = readTextIfExists(filePath) || "";
130
+ if (!text) continue;
131
+ if (/<header\b|class(Name)?=["'][^"']*(topbar|app-nav|navbar)/i.test(text)) {
132
+ result.hasHeader = true;
133
+ result.hasTopbar = true;
134
+ }
135
+ if (/<aside\b|class(Name)?=["'][^"']*(sidebar|side-nav|sidenav)/i.test(text)) {
136
+ result.hasSidebar = true;
137
+ }
138
+ if (/\bbottom[-_ ]tabs\b|\bTabBar\b|\bBottomNavigation\b/i.test(text)) {
139
+ result.hasBottomTabs = true;
140
+ }
141
+ if (/breadcrumb/i.test(text)) {
142
+ result.hasBreadcrumbs = true;
143
+ }
144
+ if (/\bcommand palette\b|\bCommandPalette\b/i.test(text)) {
145
+ result.hasCommandPalette = true;
146
+ }
147
+ if (/\bsegmented\b|\bSegmentedControl\b/i.test(text)) {
148
+ result.hasSegmentedControl = true;
149
+ }
150
+ if (/<nav\b|role=["']tablist["']|class(Name)?=["'][^"']*\btabs?\b/i.test(text)) {
151
+ result.hasTabs = result.hasTabs || /role=["']tablist["']|class(Name)?=["'][^"']*\btabs?\b/i.test(text);
152
+ for (const match of text.matchAll(/(?:href|to)=["'`]([^"'`]+)["'`]/g)) {
153
+ result.navLinks.push(match[1]);
154
+ }
155
+ }
156
+ }
157
+
158
+ result.navLinks = [...new Set(result.navLinks)].sort();
159
+ return result;
160
+ }
161
+
162
+ /**
163
+ * @param {import("./types.d.ts").NavigationStructure} navigation
164
+ * @returns {any}
165
+ */
166
+ export function shellKindFromNavigation(navigation) {
167
+ if (!navigation) return null;
168
+ if (navigation.hasBottomTabs) return "bottom_tabs";
169
+ if (navigation.hasSidebar && navigation.hasHeader) return "split_view";
170
+ if (navigation.hasSidebar) return "sidebar";
171
+ if (navigation.hasTopbar || navigation.hasHeader) return "topbar";
172
+ return null;
173
+ }
174
+
175
+ /**
176
+ * @param {import("./types.d.ts").NavigationStructure} navigation
177
+ * @returns {any}
178
+ */
179
+ export function navigationPatternsFromStructure(navigation) {
180
+ const patterns = new Set();
181
+ if (!navigation) return [];
182
+ if (navigation.hasTabs) patterns.add("tabs");
183
+ if (navigation.hasBreadcrumbs) patterns.add("breadcrumbs");
184
+ if (navigation.hasBottomTabs) patterns.add("bottom_tabs");
185
+ if (navigation.hasRail) patterns.add("navigation_rail");
186
+ if (navigation.hasCommandPalette) patterns.add("command_palette");
187
+ if (navigation.hasSegmentedControl) patterns.add("segmented_control");
188
+ if (navigation.hasSidebar && navigation.hasHeader) patterns.add("split_view");
189
+ return [...patterns].sort();
190
+ }
191
+
192
+ /**
193
+ * @param {string} rootDir
194
+ * @returns {any}
195
+ */
196
+ export function detectUiPresentationFeatures(rootDir) {
197
+ const files = listFilesRecursive(rootDir, /** @param {any} filePath */ (filePath) => /\.(tsx|ts|jsx|js|svelte|vue|html)$/i.test(filePath));
198
+ const features = new Set();
199
+
200
+ for (const filePath of files) {
201
+ const text = readTextIfExists(filePath) || "";
202
+ if (!text) continue;
203
+ if (/\bDataGrid\b|\bag-grid\b|\bAGGrid\b|\bTanStackTable\b|\breact-data-grid\b|\bmui[-_ ]?datagrid\b/i.test(text)) {
204
+ features.add("data_grid");
205
+ }
206
+ if (/<table\b|react-table/i.test(text)) features.add("table");
207
+ if (/\b(card|cards|Card)\b/.test(text)) features.add("cards");
208
+ if (/\bkanban|board\b/i.test(text)) features.add("board");
209
+ if (/\bcalendar\b/i.test(text)) features.add("calendar");
210
+ if (/\bgallery\b/i.test(text)) features.add("gallery");
211
+ if (/\bmodal\b|Dialog|AlertDialog/i.test(text)) features.add("modal");
212
+ if (/\bdrawer\b|Sheet/i.test(text)) features.add("drawer");
213
+ if (/\bsheet\b|BottomSheet|ModalBottomSheet/i.test(text)) features.add("sheet");
214
+ if (/\bBottomSheet\b|\bModalBottomSheet\b/i.test(text)) features.add("bottom_sheet");
215
+ if (/\bFloatingActionButton\b|\bExtendedFloatingActionButton\b|\bfloating action button\b/i.test(text)) features.add("fab");
216
+ if (/\bempty state\b|empty-state|No results|No items/i.test(text)) features.add("empty_state");
217
+ if (/\berror state\b|Something went wrong|error/i.test(text)) features.add("error_state");
218
+ if (/\bloading\b|skeleton|spinner/i.test(text)) features.add("loading_state");
219
+ if (/\bbreadcrumb/i.test(text)) features.add("breadcrumbs");
220
+ if (/\bactivity\b|\btimeline\b|\bcomment/i.test(text)) features.add("activity");
221
+ if (/\bsettings\b|\bpreferences\b|\bbilling\b|\bsecurity\b/i.test(text)) features.add("settings");
222
+ if (/\bonboarding\b|\bwizard\b|\bstepper\b/i.test(text)) features.add("wizard");
223
+ if (/\bpull[-_ ]to[-_ ]refresh\b|SwipeRefresh|refreshable\b/i.test(text)) features.add("pull_to_refresh");
224
+ if (/\bcommand palette\b|\bCommandPalette\b/i.test(text)) features.add("command_palette");
225
+ if (/\binspector\b|\bDetailsPane\b|\bproperties pane\b/i.test(text)) features.add("inspector_pane");
226
+ if (/\bWindowGroup\b|\bBrowserWindow\b|\bmulti[-_ ]window\b/i.test(text)) features.add("multi_window");
227
+ }
228
+
229
+ return [...features].sort();
230
+ }