@topogram/cli 0.3.64 → 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 (245) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan/index.js +703 -0
  3. package/src/adoption/plan.js +12 -703
  4. package/src/agent-ops/query-builders/auth.js +375 -0
  5. package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
  6. package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
  7. package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
  8. package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
  9. package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
  10. package/src/agent-ops/query-builders/change-risk.js +25 -0
  11. package/src/agent-ops/query-builders/common.js +149 -0
  12. package/src/agent-ops/query-builders/maintained-risk.js +539 -0
  13. package/src/agent-ops/query-builders/maintained-shared.js +120 -0
  14. package/src/agent-ops/query-builders/multi-agent.js +547 -0
  15. package/src/agent-ops/query-builders/projection-impacts.js +514 -0
  16. package/src/agent-ops/query-builders/work-packets.js +417 -0
  17. package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
  18. package/src/agent-ops/query-builders/workflow-context.js +398 -0
  19. package/src/agent-ops/query-builders/workflow-presets-core.js +676 -0
  20. package/src/agent-ops/query-builders/workflow-presets.js +341 -0
  21. package/src/agent-ops/query-builders.d.ts +26 -26
  22. package/src/agent-ops/query-builders.js +42 -5021
  23. package/src/catalog/constants.js +10 -0
  24. package/src/catalog/copy.js +60 -0
  25. package/src/catalog/diagnostics.js +15 -0
  26. package/src/catalog/entries.js +42 -0
  27. package/src/catalog/files.js +67 -0
  28. package/src/catalog/provenance.js +122 -0
  29. package/src/catalog/source.js +150 -0
  30. package/src/catalog/validation.js +252 -0
  31. package/src/catalog.d.ts +2 -0
  32. package/src/catalog.js +18 -746
  33. package/src/cli/commands/catalog/check.js +31 -0
  34. package/src/cli/commands/catalog/copy.js +59 -0
  35. package/src/cli/commands/catalog/doctor.js +248 -0
  36. package/src/cli/commands/catalog/help.js +21 -0
  37. package/src/cli/commands/catalog/list.js +52 -0
  38. package/src/cli/commands/catalog/runner.js +92 -0
  39. package/src/cli/commands/catalog/shared.js +17 -0
  40. package/src/cli/commands/catalog/show.js +134 -0
  41. package/src/cli/commands/catalog.js +30 -615
  42. package/src/cli/commands/generator-policy/package-info.js +162 -0
  43. package/src/cli/commands/generator-policy/payloads.js +372 -0
  44. package/src/cli/commands/generator-policy/printers.js +159 -0
  45. package/src/cli/commands/generator-policy/runner.js +81 -0
  46. package/src/cli/commands/generator-policy/shared.js +39 -0
  47. package/src/cli/commands/generator-policy.js +15 -783
  48. package/src/cli/commands/import/adopt.js +170 -0
  49. package/src/cli/commands/import/check.js +91 -0
  50. package/src/cli/commands/import/diff.js +84 -0
  51. package/src/cli/commands/import/help.js +47 -0
  52. package/src/cli/commands/import/paths.js +277 -0
  53. package/src/cli/commands/import/plan.js +284 -0
  54. package/src/cli/commands/import/refresh.js +470 -0
  55. package/src/cli/commands/import/status-history.js +196 -0
  56. package/src/cli/commands/import/workspace.js +230 -0
  57. package/src/cli/commands/import.js +33 -1732
  58. package/src/cli/commands/package/constants.js +17 -0
  59. package/src/cli/commands/package/doctor.js +240 -0
  60. package/src/cli/commands/package/help.js +27 -0
  61. package/src/cli/commands/package/lockfile.js +135 -0
  62. package/src/cli/commands/package/npm.js +97 -0
  63. package/src/cli/commands/package/reporting.js +35 -0
  64. package/src/cli/commands/package/runner.js +33 -0
  65. package/src/cli/commands/package/shared.js +9 -0
  66. package/src/cli/commands/package/update-cli.js +252 -0
  67. package/src/cli/commands/package/versions.js +35 -0
  68. package/src/cli/commands/package.js +29 -813
  69. package/src/cli/commands/query/change-plan.js +68 -0
  70. package/src/cli/commands/query/definitions.js +202 -0
  71. package/src/cli/commands/query/import-adopt.js +121 -0
  72. package/src/cli/commands/query/runner/artifacts.js +102 -0
  73. package/src/cli/commands/query/runner/boundaries.js +211 -0
  74. package/src/cli/commands/query/runner/change.js +182 -0
  75. package/src/cli/commands/query/runner/import-adopt.js +111 -0
  76. package/src/cli/commands/query/runner/index.js +31 -0
  77. package/src/cli/commands/query/runner/output.js +12 -0
  78. package/src/cli/commands/query/runner/workflow.js +241 -0
  79. package/src/cli/commands/query/runner.js +3 -0
  80. package/src/cli/commands/query/workflow-context.js +5 -0
  81. package/src/cli/commands/query/workspace.js +274 -0
  82. package/src/cli/commands/query.js +9 -1300
  83. package/src/cli/commands/template/baseline.js +100 -0
  84. package/src/cli/commands/template/check.js +466 -0
  85. package/src/cli/commands/template/constants.js +8 -0
  86. package/src/cli/commands/template/diagnostics.js +26 -0
  87. package/src/cli/commands/template/help.js +28 -0
  88. package/src/cli/commands/template/lifecycle.js +404 -0
  89. package/src/cli/commands/template/list-show.js +287 -0
  90. package/src/cli/commands/template/policy.js +422 -0
  91. package/src/cli/commands/template/shared.js +127 -0
  92. package/src/cli/commands/template/updates.js +352 -0
  93. package/src/cli/commands/template.js +41 -2143
  94. package/src/generator/api/contracts.js +497 -0
  95. package/src/generator/api/metadata.js +221 -0
  96. package/src/generator/api/openapi.js +559 -0
  97. package/src/generator/api/schema.js +124 -0
  98. package/src/generator/api/types.d.ts +98 -0
  99. package/src/generator/api.js +3 -1195
  100. package/src/generator/context/shared/domain-sdlc.js +282 -0
  101. package/src/generator/context/shared/maintained-boundary.js +665 -0
  102. package/src/generator/context/shared/metrics.js +85 -0
  103. package/src/generator/context/shared/primitives.js +64 -0
  104. package/src/generator/context/shared/relationships.js +453 -0
  105. package/src/generator/context/shared/summaries.js +263 -0
  106. package/src/generator/context/shared/types.d.ts +207 -0
  107. package/src/generator/context/shared.d.ts +42 -0
  108. package/src/generator/context/shared.js +80 -1390
  109. package/src/generator/context/slice/core.js +397 -0
  110. package/src/generator/context/slice/sdlc.js +417 -0
  111. package/src/generator/context/slice/ui-packets.js +183 -0
  112. package/src/generator/context/slice.js +2 -859
  113. package/src/generator/registry/index.js +507 -0
  114. package/src/generator/registry.js +18 -504
  115. package/src/generator/runtime/environment/index.js +666 -0
  116. package/src/generator/runtime/environment.js +4 -666
  117. package/src/generator/runtime/runtime-check/index.js +554 -0
  118. package/src/generator/runtime/runtime-check.js +4 -554
  119. package/src/generator/runtime/shared/index.js +572 -0
  120. package/src/generator/runtime/shared.js +19 -570
  121. package/src/generator/shared.d.ts +2 -0
  122. package/src/generator/surfaces/shared.d.ts +3 -0
  123. package/src/generator/widget-conformance/behavior-report.js +258 -0
  124. package/src/generator/widget-conformance/checks.js +371 -0
  125. package/src/generator/widget-conformance/projection-context.js +200 -0
  126. package/src/generator/widget-conformance/report.js +166 -0
  127. package/src/generator/widget-conformance/types.d.ts +121 -0
  128. package/src/generator/widget-conformance.js +3 -824
  129. package/src/import/core/context.d.ts +3 -0
  130. package/src/import/core/contracts.d.ts +1 -0
  131. package/src/import/core/registry.d.ts +4 -0
  132. package/src/import/core/runner/candidates.js +217 -0
  133. package/src/import/core/runner/options.js +22 -0
  134. package/src/import/core/runner/reports.js +50 -0
  135. package/src/import/core/runner/run.js +79 -0
  136. package/src/import/core/runner/tracks.js +150 -0
  137. package/src/import/core/runner/ui-drafts.js +337 -0
  138. package/src/import/core/runner.js +3 -698
  139. package/src/import/core/shared/api-routes.js +221 -0
  140. package/src/import/core/shared/candidates.js +97 -0
  141. package/src/import/core/shared/files.js +177 -0
  142. package/src/import/core/shared/next-app.js +389 -0
  143. package/src/import/core/shared/types.d.ts +51 -0
  144. package/src/import/core/shared/ui-routes.js +230 -0
  145. package/src/import/core/shared.js +60 -861
  146. package/src/new-project/constants.js +128 -0
  147. package/src/new-project/create.js +83 -0
  148. package/src/new-project/json.js +28 -0
  149. package/src/new-project/metadata.js +96 -0
  150. package/src/new-project/package-spec.js +161 -0
  151. package/src/new-project/project-files.js +348 -0
  152. package/src/new-project/template-policy.js +269 -0
  153. package/src/new-project/template-resolution.js +368 -0
  154. package/src/new-project/template-snapshots.js +430 -0
  155. package/src/new-project/template-updates.js +512 -0
  156. package/src/new-project/types.d.ts +83 -0
  157. package/src/new-project.js +6 -2277
  158. package/src/parser.d.ts +87 -1
  159. package/src/parser.js +118 -0
  160. package/src/policy/review-boundaries.d.ts +15 -0
  161. package/src/project-config/index.js +564 -0
  162. package/src/project-config.js +19 -561
  163. package/src/resolver/enrich/acceptance-criterion.js +2 -0
  164. package/src/resolver/enrich/bug.js +2 -0
  165. package/src/resolver/enrich/pitch.js +2 -0
  166. package/src/resolver/enrich/requirement.js +2 -0
  167. package/src/resolver/enrich/task.js +2 -0
  168. package/src/resolver/index.js +19 -2089
  169. package/src/resolver/normalize.js +384 -1
  170. package/src/resolver/plans.js +168 -0
  171. package/src/resolver/projections-api.js +494 -0
  172. package/src/resolver/projections-db.js +133 -0
  173. package/src/resolver/projections-ui.js +317 -0
  174. package/src/resolver/shapes.js +251 -0
  175. package/src/resolver/shared.js +278 -0
  176. package/src/resolver/widgets.js +132 -0
  177. package/src/template-trust/constants.js +62 -0
  178. package/src/template-trust/content.js +258 -0
  179. package/src/template-trust/diff.js +92 -0
  180. package/src/template-trust/policy.js +61 -0
  181. package/src/template-trust/record.js +90 -0
  182. package/src/template-trust/status.js +182 -0
  183. package/src/template-trust.js +24 -687
  184. package/src/text-helpers.d.ts +1 -0
  185. package/src/topogram-types.d.ts +69 -0
  186. package/src/validator/common.js +488 -0
  187. package/src/validator/data-model.js +237 -0
  188. package/src/validator/docs.js +167 -0
  189. package/src/validator/expressions.js +146 -1
  190. package/src/validator/index.d.ts +23 -0
  191. package/src/validator/index.js +32 -3585
  192. package/src/validator/kinds.d.ts +41 -0
  193. package/src/validator/kinds.js +2 -0
  194. package/src/validator/model-helpers.js +46 -0
  195. package/src/validator/per-kind/acceptance-criterion.js +5 -0
  196. package/src/validator/per-kind/bug.js +6 -0
  197. package/src/validator/per-kind/domain.js +15 -2
  198. package/src/validator/per-kind/pitch.js +7 -0
  199. package/src/validator/per-kind/requirement.js +5 -0
  200. package/src/validator/per-kind/task.js +7 -0
  201. package/src/validator/per-kind/widget.js +14 -0
  202. package/src/validator/projections/api-http-async.js +410 -0
  203. package/src/validator/projections/api-http-authz.js +88 -0
  204. package/src/validator/projections/api-http-core.js +205 -0
  205. package/src/validator/projections/api-http-policies.js +339 -0
  206. package/src/validator/projections/api-http-responses.js +233 -0
  207. package/src/validator/projections/api-http.js +44 -0
  208. package/src/validator/projections/db.js +353 -0
  209. package/src/validator/projections/generator-defaults.js +45 -0
  210. package/src/validator/projections/helpers.js +87 -0
  211. package/src/validator/projections/ui-helpers.js +214 -0
  212. package/src/validator/projections/ui-navigation.js +344 -0
  213. package/src/validator/projections/ui-structure.js +364 -0
  214. package/src/validator/projections/ui-widgets.js +493 -0
  215. package/src/validator/projections/ui.js +46 -0
  216. package/src/validator/registry.js +48 -1
  217. package/src/validator/utils.d.ts +20 -0
  218. package/src/validator/utils.js +115 -12
  219. package/src/widget-behavior.d.ts +1 -0
  220. package/src/workflows/import-app/api/collect.js +221 -0
  221. package/src/workflows/import-app/api/openapi.js +257 -0
  222. package/src/workflows/import-app/api/routes.js +327 -0
  223. package/src/workflows/import-app/api/sources.js +22 -0
  224. package/src/workflows/import-app/api.js +2 -797
  225. package/src/workflows/reconcile/adoption-plan/build.js +208 -0
  226. package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
  227. package/src/workflows/reconcile/adoption-plan/outputs.js +143 -0
  228. package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
  229. package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
  230. package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
  231. package/src/workflows/reconcile/adoption-plan.js +30 -740
  232. package/src/workflows/reconcile/auth/closures.js +115 -0
  233. package/src/workflows/reconcile/auth/formatters.js +142 -0
  234. package/src/workflows/reconcile/auth/inference.js +330 -0
  235. package/src/workflows/reconcile/auth/roles.js +122 -0
  236. package/src/workflows/reconcile/auth.js +35 -690
  237. package/src/workflows/reconcile/bundle-core/index.js +600 -0
  238. package/src/workflows/reconcile/bundle-core.js +12 -598
  239. package/src/workflows/reconcile/canonical-surface.js +1 -1
  240. package/src/workflows/reconcile/impacts/adoption-plan.js +192 -0
  241. package/src/workflows/reconcile/impacts/indexes.js +101 -0
  242. package/src/workflows/reconcile/impacts/patches.js +252 -0
  243. package/src/workflows/reconcile/impacts/reports.js +80 -0
  244. package/src/workflows/reconcile/impacts.js +14 -623
  245. package/src/workspace-docs.d.ts +29 -0
@@ -1,12 +1,115 @@
1
- export {
2
- blockEntries,
3
- collectFieldMap,
4
- formatLoc,
5
- getField,
6
- getFieldValue,
7
- pushError,
8
- stringValue,
9
- symbolValue,
10
- symbolValues,
11
- valueAsArray
12
- } from "./index.js";
1
+ // @ts-check
2
+
3
+ /**
4
+ * @param {ValidationErrors} errors
5
+ * @param {string} message
6
+ * @param {TopogramLocation | null | undefined} [loc]
7
+ * @returns {void}
8
+ */
9
+ export function pushError(errors, message, loc) {
10
+ errors.push({
11
+ message,
12
+ loc
13
+ });
14
+ }
15
+
16
+ /**
17
+ * @param {TopogramLocation | null | undefined} loc
18
+ * @returns {string}
19
+ */
20
+ export function formatLoc(loc) {
21
+ const line = loc?.start?.line ?? 1;
22
+ const column = loc?.start?.column ?? 1;
23
+ const file = loc?.file ?? "<unknown>";
24
+ return `${file}:${line}:${column}`;
25
+ }
26
+
27
+ /**
28
+ * @param {TopogramBlockEntry} entry
29
+ * @returns {TopogramToken[]}
30
+ */
31
+ export function blockSymbolItems(entry) {
32
+ return entry.items.filter((item) => item.type === "symbol" || item.type === "string");
33
+ }
34
+
35
+ /**
36
+ * @param {TopogramToken | null | undefined} value
37
+ * @returns {TopogramToken[]}
38
+ */
39
+ export function valueAsArray(value) {
40
+ if (!value) {
41
+ return [];
42
+ }
43
+ if (value.type === "list") {
44
+ return value.items;
45
+ }
46
+ if (value.type === "sequence") {
47
+ return value.items;
48
+ }
49
+ return [value];
50
+ }
51
+
52
+ /**
53
+ * @param {TopogramToken | null | undefined} value
54
+ * @returns {string[]}
55
+ */
56
+ export function symbolValues(value) {
57
+ return valueAsArray(value).filter((item) => item.type === "symbol").map((item) => item.value);
58
+ }
59
+
60
+ /**
61
+ * @param {TopogramStatement} statement
62
+ * @returns {TopogramFieldMap}
63
+ */
64
+ export function collectFieldMap(statement) {
65
+ const map = new Map();
66
+ for (const field of statement.fields) {
67
+ if (!map.has(field.key)) {
68
+ map.set(field.key, []);
69
+ }
70
+ map.get(field.key).push(field);
71
+ }
72
+ return map;
73
+ }
74
+
75
+ /**
76
+ * @param {TopogramStatement} statement
77
+ * @param {string} key
78
+ * @returns {TopogramField | null}
79
+ */
80
+ export function getField(statement, key) {
81
+ return collectFieldMap(statement).get(key)?.[0] || null;
82
+ }
83
+
84
+ /**
85
+ * @param {TopogramStatement} statement
86
+ * @param {string} key
87
+ * @returns {TopogramToken | null}
88
+ */
89
+ export function getFieldValue(statement, key) {
90
+ return getField(statement, key)?.value || null;
91
+ }
92
+
93
+ /**
94
+ * @param {TopogramToken | null | undefined} value
95
+ * @returns {string | null}
96
+ */
97
+ export function stringValue(value) {
98
+ return value?.type === "string" ? value.value : null;
99
+ }
100
+
101
+ /**
102
+ * @param {TopogramToken | null | undefined} value
103
+ * @returns {string | null}
104
+ */
105
+ export function symbolValue(value) {
106
+ return value?.type === "symbol" ? value.value : null;
107
+ }
108
+
109
+ /**
110
+ * @param {TopogramToken | null | undefined} value
111
+ * @returns {TopogramBlockEntry[]}
112
+ */
113
+ export function blockEntries(value) {
114
+ return value?.type === "block" ? value.entries : [];
115
+ }
@@ -0,0 +1 @@
1
+ export function buildWidgetBehaviorRealizations(...args: any[]): any;
@@ -0,0 +1,221 @@
1
+ // @ts-check
2
+
3
+ import path from "node:path";
4
+
5
+ import { relativeTo } from "../../../path-helpers.js";
6
+ import { titleCase } from "../../../text-helpers.js";
7
+ import { readTextIfExists } from "../../shared.js";
8
+ import { dedupeCandidateRecords, makeCandidateRecord, normalizeOpenApiPath } from "../shared.js";
9
+ import { inferReactRoutes, inferSvelteRoutes } from "../ui.js";
10
+ import { parseOpenApiDocument, parseOpenApiYaml } from "./openapi.js";
11
+ import {
12
+ inferNextApiRoutes,
13
+ inferNextAuthCapabilities,
14
+ inferNextServerActionCapabilities,
15
+ inferRouteCapabilityId,
16
+ inferServerRoutes
17
+ } from "./routes.js";
18
+ import { discoverApiSources } from "./sources.js";
19
+
20
+ /** @param {WorkspacePaths} paths @returns {any} */
21
+ export function collectApiImport(paths) {
22
+ /** @type {any[]} */
23
+ const findings = [];
24
+ /** @type {WorkflowRecord} */
25
+ const candidates = {
26
+ capabilities: [],
27
+ routes: [],
28
+ stacks: []
29
+ };
30
+ const { openApiFiles } = discoverApiSources(paths);
31
+ let usedOpenApi = false;
32
+ for (const filePath of openApiFiles) {
33
+ const provenance = relativeTo(paths.repoRoot, filePath);
34
+ const text = readTextIfExists(filePath) || "";
35
+ const document = filePath.endsWith(".json") ? JSON.parse(text) : parseOpenApiYaml(text);
36
+ const parsed = parseOpenApiDocument(document, provenance, "openapi");
37
+ usedOpenApi = true;
38
+ findings.push({
39
+ kind: "openapi",
40
+ file: provenance,
41
+ capability_count: parsed.capabilities.length
42
+ });
43
+ candidates.capabilities.push(...parsed.capabilities);
44
+ candidates.routes.push(...parsed.routes.map((/** @type {any} */ route) => ({
45
+ path: route.path,
46
+ method: route.method,
47
+ confidence: "high",
48
+ source_kind: route.source_kind,
49
+ provenance: route.provenance
50
+ })));
51
+ }
52
+ if (!usedOpenApi) {
53
+ const inferredRoutes = [
54
+ ...inferNextApiRoutes(paths),
55
+ ...inferServerRoutes(paths)
56
+ ];
57
+ const inferredServerActions = inferNextServerActionCapabilities(paths);
58
+ const inferredAuthCapabilities = inferNextAuthCapabilities(paths);
59
+ if (inferredRoutes.length > 0) {
60
+ findings.push({
61
+ kind: "route_inventory",
62
+ files: [...new Set(inferredRoutes.map((/** @type {any} */ route) => relativeTo(paths.repoRoot, route.file)))],
63
+ route_count: inferredRoutes.length
64
+ });
65
+ candidates.capabilities.push(
66
+ ...inferredRoutes.map((/** @type {any} */ route) =>
67
+ makeCandidateRecord({
68
+ kind: "capability",
69
+ idHint: inferRouteCapabilityId(route),
70
+ label: `${route.method} ${route.path}`,
71
+ confidence: "medium",
72
+ sourceKind: "route_code",
73
+ provenance: `${relativeTo(paths.repoRoot, route.file)}#${route.method} ${route.path}`,
74
+ endpoint: {
75
+ method: route.method,
76
+ path: normalizeOpenApiPath(route.path)
77
+ },
78
+ path_params: (route.path_params || []).map((/** @type {any} */ name) => ({ name, required: true, type: null })),
79
+ query_params: (route.query_params || []).map((/** @type {any} */ name) => ({ name, required: false, type: null })),
80
+ header_params: [],
81
+ input_fields: [],
82
+ output_fields: route.output_fields || [],
83
+ auth_hint: route.auth_hint || "unknown"
84
+ })
85
+ )
86
+ );
87
+ candidates.routes.push(
88
+ ...inferredRoutes.map((/** @type {any} */ route) => ({
89
+ path: normalizeOpenApiPath(route.path),
90
+ method: route.method,
91
+ confidence: "medium",
92
+ source_kind: "route_code",
93
+ provenance: `${relativeTo(paths.repoRoot, route.file)}#${route.method} ${route.path}`
94
+ }))
95
+ );
96
+ }
97
+ if (inferredServerActions.length > 0) {
98
+ findings.push({
99
+ kind: "next_server_actions",
100
+ files: [...new Set(inferredServerActions.map((/** @type {any} */ action) => relativeTo(paths.repoRoot, action.file)))],
101
+ action_count: inferredServerActions.length
102
+ });
103
+ candidates.capabilities.push(
104
+ ...inferredServerActions.map((/** @type {any} */ action) =>
105
+ makeCandidateRecord({
106
+ kind: "capability",
107
+ idHint: action.id_hint,
108
+ label: titleCase(action.id_hint.replace(/^cap_/, "")),
109
+ confidence: "medium",
110
+ sourceKind: action.source_kind,
111
+ provenance: `${relativeTo(paths.repoRoot, action.file)}#${action.function_name}`,
112
+ endpoint: {
113
+ method: action.method,
114
+ path: normalizeOpenApiPath(action.path)
115
+ },
116
+ path_params: (action.path_params || []).map((/** @type {any} */ name) => ({ name, required: true, type: null })),
117
+ query_params: [],
118
+ header_params: [],
119
+ input_fields: action.input_fields || [],
120
+ output_fields: action.output_fields || [],
121
+ auth_hint: action.auth_hint || "unknown"
122
+ })
123
+ )
124
+ );
125
+ candidates.routes.push(
126
+ ...inferredServerActions.map((/** @type {any} */ action) => ({
127
+ path: normalizeOpenApiPath(action.path),
128
+ method: action.method,
129
+ confidence: "medium",
130
+ source_kind: action.source_kind,
131
+ provenance: `${relativeTo(paths.repoRoot, action.file)}#${action.function_name}`
132
+ }))
133
+ );
134
+ }
135
+ if (inferredAuthCapabilities.length > 0) {
136
+ findings.push({
137
+ kind: "next_auth_flows",
138
+ files: [...new Set(inferredAuthCapabilities.flatMap((/** @type {any} */ capability) => capability.provenance || []))],
139
+ capability_count: inferredAuthCapabilities.length
140
+ });
141
+ candidates.capabilities.push(
142
+ ...inferredAuthCapabilities.map((/** @type {any} */ capability) =>
143
+ makeCandidateRecord({
144
+ kind: "capability",
145
+ idHint: capability.id_hint,
146
+ label: capability.label,
147
+ confidence: "medium",
148
+ sourceKind: capability.source_kind,
149
+ provenance: capability.provenance,
150
+ endpoint: {
151
+ method: capability.method,
152
+ path: normalizeOpenApiPath(capability.path)
153
+ },
154
+ path_params: [],
155
+ query_params: [],
156
+ header_params: [],
157
+ input_fields: capability.input_fields || [],
158
+ output_fields: capability.output_fields || [],
159
+ auth_hint: capability.auth_hint || "unknown",
160
+ entity_id: capability.entity_id,
161
+ target_state: capability.target_state || null
162
+ })
163
+ )
164
+ );
165
+ candidates.routes.push(
166
+ ...inferredAuthCapabilities.map((/** @type {any} */ capability) => ({
167
+ path: normalizeOpenApiPath(capability.path),
168
+ method: capability.method,
169
+ confidence: "medium",
170
+ source_kind: capability.source_kind,
171
+ provenance: capability.provenance
172
+ }))
173
+ );
174
+ }
175
+ }
176
+ const reactRoutes = inferReactRoutes(path.join(paths.workspaceRoot, "apps", "web"));
177
+ if (reactRoutes.length > 0) {
178
+ findings.push({
179
+ kind: "react_routes",
180
+ file: relativeTo(paths.repoRoot, path.join(paths.workspaceRoot, "apps", "web", "src", "App.tsx")),
181
+ routes: reactRoutes
182
+ });
183
+ candidates.routes.push(...reactRoutes.map((/** @type {any} */ route) => ({
184
+ path: route,
185
+ method: "GET",
186
+ confidence: "medium",
187
+ source_kind: "generated_artifact",
188
+ provenance: relativeTo(paths.repoRoot, path.join(paths.workspaceRoot, "apps", "web", "src", "App.tsx"))
189
+ })));
190
+ candidates.stacks.push("react_web");
191
+ }
192
+ const svelteRoutes = inferSvelteRoutes(path.join(paths.workspaceRoot, "apps", "web-sveltekit"));
193
+ if (svelteRoutes.length > 0) {
194
+ findings.push({
195
+ kind: "sveltekit_routes",
196
+ file: relativeTo(paths.repoRoot, path.join(paths.workspaceRoot, "apps", "web-sveltekit", "src", "routes")),
197
+ routes: svelteRoutes
198
+ });
199
+ candidates.routes.push(...svelteRoutes.map((/** @type {any} */ route) => ({
200
+ path: route,
201
+ method: "GET",
202
+ confidence: "medium",
203
+ source_kind: "generated_artifact",
204
+ provenance: relativeTo(paths.repoRoot, path.join(paths.workspaceRoot, "apps", "web-sveltekit", "src", "routes"))
205
+ })));
206
+ candidates.stacks.push("sveltekit_web");
207
+ }
208
+ candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (/** @type {any} */ record) => record.id_hint);
209
+ candidates.routes = dedupeCandidateRecords(
210
+ candidates.routes.map((/** @type {any} */ route) => ({
211
+ ...route,
212
+ id_hint: route.id_hint || `${route.method}_${route.path}`
213
+ })),
214
+ (/** @type {any} */ record) => `${record.method}:${record.path}:${record.source_kind}`
215
+ ).map((/** @type {any} */ record) => {
216
+ const { id_hint, ...route } = record;
217
+ return route;
218
+ });
219
+
220
+ return { findings, candidates };
221
+ }
@@ -0,0 +1,257 @@
1
+ // @ts-check
2
+
3
+ import { slugify, titleCase } from "../../../text-helpers.js";
4
+ import { makeCandidateRecord } from "../shared.js";
5
+
6
+ /** @param {WorkflowRecord} document @param {any} provenance @param {string} sourceKind @returns {any} */
7
+ export function parseOpenApiDocument(document, provenance, sourceKind = "openapi") {
8
+ /** @type {any[]} */
9
+ const capabilities = [];
10
+ /** @type {any[]} */
11
+ const routes = [];
12
+ const pathsObject = document.paths || {};
13
+ for (const [endpointPath, operations] of Object.entries(pathsObject)) {
14
+ for (const [method, operation] of Object.entries(operations || {})) {
15
+ const normalizedMethod = method.toUpperCase();
16
+ const operationId = operation.operationId || `candidate_${normalizedMethod.toLowerCase()}_${slugify(endpointPath)}`;
17
+ const requestSchema =
18
+ operation.requestBody?.content?.["application/json"]?.schema?.$ref ||
19
+ operation.requestBody?.content?.["application/json"]?.schema?.type ||
20
+ null;
21
+ const successResponse = Object.entries(operation.responses || {}).find((/** @type {any} */ [status]) => /^2/.test(status));
22
+ const responseSchema =
23
+ successResponse?.[1]?.content?.["application/json"]?.schema?.$ref ||
24
+ successResponse?.[1]?.content?.["application/json"]?.schema?.type ||
25
+ null;
26
+ const parameterHints = extractOpenApiParameterHints(document, endpointPath, operation);
27
+ const requestFieldHints = extractOpenApiSchemaFieldHints(document, operation.requestBody?.content?.["application/json"]?.schema);
28
+ const responseFieldHints = extractOpenApiSchemaFieldHints(document, successResponse?.[1]?.content?.["application/json"]?.schema);
29
+ const securitySchemes = extractOpenApiSecuritySchemes(document, operation);
30
+ capabilities.push(
31
+ makeCandidateRecord({
32
+ kind: "capability",
33
+ idHint: operationId,
34
+ label: operation.summary || titleCase(operationId.replace(/^cap_/, "")),
35
+ confidence: "high",
36
+ sourceKind,
37
+ provenance: `${provenance}#${normalizedMethod} ${endpointPath}`,
38
+ endpoint: {
39
+ method: normalizedMethod,
40
+ path: endpointPath
41
+ },
42
+ input_hint: requestSchema,
43
+ output_hint: responseSchema,
44
+ input_fields: requestFieldHints.body_fields,
45
+ output_fields: responseFieldHints.body_fields,
46
+ path_params: parameterHints.path,
47
+ query_params: parameterHints.query,
48
+ header_params: parameterHints.header,
49
+ security_schemes: securitySchemes,
50
+ auth_hint: securitySchemes.length > 0 ? "secured" : "unknown"
51
+ })
52
+ );
53
+ routes.push({
54
+ path: endpointPath,
55
+ method: normalizedMethod,
56
+ source_kind: sourceKind,
57
+ provenance: `${provenance}#${normalizedMethod} ${endpointPath}`
58
+ });
59
+ }
60
+ }
61
+ return { capabilities, routes };
62
+ }
63
+
64
+ /** @param {string} ref @returns {any} */
65
+ function openApiRefName(ref) {
66
+ if (!ref || typeof ref !== "string") {
67
+ return null;
68
+ }
69
+ return ref.split("/").pop() || null;
70
+ }
71
+
72
+ /** @param {WorkflowRecord} document @param {WorkflowRecord} schema @param {Set<any>} seen @returns {any} */
73
+ function resolveOpenApiSchema(document, schema, seen = new Set()) {
74
+ if (!schema || typeof schema !== "object") {
75
+ return null;
76
+ }
77
+ if (schema.$ref) {
78
+ if (seen.has(schema.$ref)) {
79
+ return null;
80
+ }
81
+ seen.add(schema.$ref);
82
+ if (!schema.$ref.startsWith("#/")) {
83
+ return null;
84
+ }
85
+ const segments = schema.$ref.slice(2).split("/");
86
+ let current = document;
87
+ for (const segment of segments) {
88
+ current = current?.[segment];
89
+ if (current == null) {
90
+ return null;
91
+ }
92
+ }
93
+ return resolveOpenApiSchema(document, current, seen) || current;
94
+ }
95
+ return schema;
96
+ }
97
+
98
+ /** @param {WorkflowRecord} document @param {WorkflowRecord} schema @param {Set<any>} fields @param {Set<any>} seen @returns {any} */
99
+ function collectOpenApiObjectFields(document, schema, fields = new Set(), seen = new Set()) {
100
+ const resolved = resolveOpenApiSchema(document, schema, seen);
101
+ if (!resolved || typeof resolved !== "object") {
102
+ return fields;
103
+ }
104
+ if (resolved.type === "array" && resolved.items) {
105
+ collectOpenApiObjectFields(document, resolved.items, fields, seen);
106
+ return fields;
107
+ }
108
+ for (const propertyName of Object.keys(resolved.properties || {})) {
109
+ fields.add(propertyName);
110
+ }
111
+ for (const entry of resolved.allOf || []) {
112
+ collectOpenApiObjectFields(document, entry, fields, seen);
113
+ }
114
+ for (const entry of resolved.oneOf || []) {
115
+ collectOpenApiObjectFields(document, entry, fields, seen);
116
+ }
117
+ for (const entry of resolved.anyOf || []) {
118
+ collectOpenApiObjectFields(document, entry, fields, seen);
119
+ }
120
+ return fields;
121
+ }
122
+
123
+ /** @param {WorkflowRecord} document @param {WorkflowRecord} schema @returns {any} */
124
+ function extractOpenApiSchemaFieldHints(document, schema) {
125
+ const fieldNames = [...collectOpenApiObjectFields(document, schema)].sort();
126
+ return {
127
+ schema_ref: openApiRefName(schema?.$ref || null),
128
+ body_fields: fieldNames
129
+ };
130
+ }
131
+
132
+ /** @param {string} endpointPath @param {WorkflowRecord} operation @returns {any} */
133
+ function collectOpenApiParameters(endpointPath, operation) {
134
+ const pathParams = [...String(endpointPath || "").matchAll(/\{([^}]+)\}/g)].map((/** @type {any} */ match) => ({
135
+ name: match[1],
136
+ in: "path",
137
+ required: true
138
+ }));
139
+ return [...pathParams, ...((operation.parameters || []).filter(Boolean))];
140
+ }
141
+
142
+ /** @param {WorkflowRecord} document @param {string} endpointPath @param {WorkflowRecord} operation @returns {any} */
143
+ function extractOpenApiParameterHints(document, endpointPath, operation) {
144
+ /** @type {WorkflowRecord} */
145
+ const grouped = {
146
+ path: [],
147
+ query: [],
148
+ header: []
149
+ };
150
+ for (const parameter of collectOpenApiParameters(endpointPath, operation)) {
151
+ const schema = resolveOpenApiSchema(document, parameter.schema || null);
152
+ const target = parameter.in === "query" ? "query" : parameter.in === "header" ? "header" : "path";
153
+ grouped[target].push({
154
+ name: parameter.name,
155
+ required: Boolean(parameter.required),
156
+ type: schema?.type || null
157
+ });
158
+ }
159
+ for (const key of Object.keys(grouped)) {
160
+ grouped[key] = grouped[key].sort((/** @type {any} */ a, /** @type {any} */ b) => a.name.localeCompare(b.name));
161
+ }
162
+ return grouped;
163
+ }
164
+
165
+ /** @param {WorkflowRecord} document @param {WorkflowRecord} operation @returns {any} */
166
+ function extractOpenApiSecuritySchemes(document, operation) {
167
+ const securityEntries = [...(operation.security || []), ...(document.security || [])];
168
+ const schemes = new Set();
169
+ for (const entry of securityEntries) {
170
+ for (const key of Object.keys(entry || {})) {
171
+ schemes.add(key);
172
+ }
173
+ }
174
+ return [...schemes].sort();
175
+ }
176
+
177
+ /** @param {string} text @returns {any} */
178
+ export function parseOpenApiYaml(text) {
179
+ /** @type {WorkflowRecord} */
180
+ const doc = { paths: {} };
181
+ let currentPath = null;
182
+ let currentMethod = null;
183
+ let inRequestBody = false;
184
+ let inResponses = false;
185
+ let currentResponseStatus = null;
186
+
187
+ for (const rawLine of text.split(/\r?\n/)) {
188
+ const line = rawLine.replace(/#.*$/, "");
189
+ if (!line.trim()) {
190
+ continue;
191
+ }
192
+ const pathMatch = line.match(/^\s{2}(\/[^:]+):\s*$/);
193
+ if (pathMatch) {
194
+ currentPath = pathMatch[1];
195
+ currentMethod = null;
196
+ doc.paths[currentPath] = doc.paths[currentPath] || {};
197
+ inRequestBody = false;
198
+ inResponses = false;
199
+ currentResponseStatus = null;
200
+ continue;
201
+ }
202
+ const methodMatch = line.match(/^\s{4}(get|post|put|patch|delete):\s*$/i);
203
+ if (methodMatch && currentPath) {
204
+ currentMethod = methodMatch[1].toLowerCase();
205
+ doc.paths[currentPath][currentMethod] = { responses: {} };
206
+ inRequestBody = false;
207
+ inResponses = false;
208
+ currentResponseStatus = null;
209
+ continue;
210
+ }
211
+ if (!currentPath || !currentMethod) {
212
+ continue;
213
+ }
214
+ const operation = doc.paths[currentPath][currentMethod];
215
+ const operationIdMatch = line.match(/^\s{6}operationId:\s*(.+)$/);
216
+ if (operationIdMatch) {
217
+ operation.operationId = operationIdMatch[1].trim().replace(/^["']|["']$/g, "");
218
+ continue;
219
+ }
220
+ const summaryMatch = line.match(/^\s{6}summary:\s*(.+)$/);
221
+ if (summaryMatch) {
222
+ operation.summary = summaryMatch[1].trim().replace(/^["']|["']$/g, "");
223
+ continue;
224
+ }
225
+ if (/^\s{6}requestBody:\s*$/.test(line)) {
226
+ inRequestBody = true;
227
+ inResponses = false;
228
+ currentResponseStatus = null;
229
+ continue;
230
+ }
231
+ if (/^\s{6}responses:\s*$/.test(line)) {
232
+ inResponses = true;
233
+ inRequestBody = false;
234
+ currentResponseStatus = null;
235
+ continue;
236
+ }
237
+ const responseStatusMatch = line.match(/^\s{8}['"]?([0-9Xx]{3})['"]?:\s*$/);
238
+ if (inResponses && responseStatusMatch) {
239
+ currentResponseStatus = responseStatusMatch[1];
240
+ operation.responses[currentResponseStatus] = operation.responses[currentResponseStatus] || {};
241
+ continue;
242
+ }
243
+ const refMatch = line.match(/^\s+\$ref:\s*(.+)$/);
244
+ if (refMatch) {
245
+ const ref = refMatch[1].trim().replace(/^["']|["']$/g, "");
246
+ if (inRequestBody) {
247
+ operation.requestBody = operation.requestBody || { content: { "application/json": { schema: {} } } };
248
+ operation.requestBody.content["application/json"].schema.$ref = ref;
249
+ } else if (inResponses && currentResponseStatus) {
250
+ operation.responses[currentResponseStatus].content = operation.responses[currentResponseStatus].content || { "application/json": { schema: {} } };
251
+ operation.responses[currentResponseStatus].content["application/json"].schema.$ref = ref;
252
+ }
253
+ }
254
+ }
255
+
256
+ return doc;
257
+ }