@topogram/cli 0.3.64 → 0.3.66

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 (278) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan/index.js +716 -0
  3. package/src/adoption/plan.js +12 -703
  4. package/src/adoption/reporting.js +1 -1
  5. package/src/agent-brief.js +7 -21
  6. package/src/agent-ops/query-builders/auth.js +375 -0
  7. package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
  8. package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
  9. package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
  10. package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
  11. package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
  12. package/src/agent-ops/query-builders/change-risk.js +25 -0
  13. package/src/agent-ops/query-builders/common.js +149 -0
  14. package/src/agent-ops/query-builders/maintained-risk.js +539 -0
  15. package/src/agent-ops/query-builders/maintained-shared.js +120 -0
  16. package/src/agent-ops/query-builders/multi-agent.js +547 -0
  17. package/src/agent-ops/query-builders/projection-impacts.js +514 -0
  18. package/src/agent-ops/query-builders/work-packets.js +417 -0
  19. package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
  20. package/src/agent-ops/query-builders/workflow-context.js +398 -0
  21. package/src/agent-ops/query-builders/workflow-presets-core.js +677 -0
  22. package/src/agent-ops/query-builders/workflow-presets.js +341 -0
  23. package/src/agent-ops/query-builders.d.ts +26 -26
  24. package/src/agent-ops/query-builders.js +42 -5021
  25. package/src/archive/jsonl.js +2 -2
  26. package/src/archive/resolver-bridge.js +1 -1
  27. package/src/archive/unarchive.js +2 -1
  28. package/src/catalog/constants.js +10 -0
  29. package/src/catalog/copy.js +65 -0
  30. package/src/catalog/diagnostics.js +15 -0
  31. package/src/catalog/entries.js +42 -0
  32. package/src/catalog/files.js +67 -0
  33. package/src/catalog/provenance.js +123 -0
  34. package/src/catalog/source.js +150 -0
  35. package/src/catalog/validation.js +252 -0
  36. package/src/catalog.d.ts +2 -0
  37. package/src/catalog.js +18 -746
  38. package/src/cli/command-parsers/project.js +3 -0
  39. package/src/cli/command-parsers/shared.js +1 -1
  40. package/src/cli/commands/agent.js +2 -2
  41. package/src/cli/commands/catalog/check.js +31 -0
  42. package/src/cli/commands/catalog/copy.js +59 -0
  43. package/src/cli/commands/catalog/doctor.js +248 -0
  44. package/src/cli/commands/catalog/help.js +21 -0
  45. package/src/cli/commands/catalog/list.js +52 -0
  46. package/src/cli/commands/catalog/runner.js +92 -0
  47. package/src/cli/commands/catalog/shared.js +17 -0
  48. package/src/cli/commands/catalog/show.js +134 -0
  49. package/src/cli/commands/catalog.js +30 -615
  50. package/src/cli/commands/check.js +3 -3
  51. package/src/cli/commands/doctor.js +2 -9
  52. package/src/cli/commands/generator-policy/package-info.js +162 -0
  53. package/src/cli/commands/generator-policy/payloads.js +372 -0
  54. package/src/cli/commands/generator-policy/printers.js +159 -0
  55. package/src/cli/commands/generator-policy/runner.js +81 -0
  56. package/src/cli/commands/generator-policy/shared.js +39 -0
  57. package/src/cli/commands/generator-policy.js +15 -783
  58. package/src/cli/commands/import/adopt.js +170 -0
  59. package/src/cli/commands/import/check.js +91 -0
  60. package/src/cli/commands/import/diff.js +84 -0
  61. package/src/cli/commands/import/help.js +47 -0
  62. package/src/cli/commands/import/paths.js +269 -0
  63. package/src/cli/commands/import/plan.js +292 -0
  64. package/src/cli/commands/import/refresh.js +471 -0
  65. package/src/cli/commands/import/status-history.js +196 -0
  66. package/src/cli/commands/import/workspace.js +233 -0
  67. package/src/cli/commands/import.js +33 -1732
  68. package/src/cli/commands/migrate.js +153 -0
  69. package/src/cli/commands/package/constants.js +17 -0
  70. package/src/cli/commands/package/doctor.js +240 -0
  71. package/src/cli/commands/package/help.js +27 -0
  72. package/src/cli/commands/package/lockfile.js +135 -0
  73. package/src/cli/commands/package/npm.js +97 -0
  74. package/src/cli/commands/package/reporting.js +35 -0
  75. package/src/cli/commands/package/runner.js +33 -0
  76. package/src/cli/commands/package/shared.js +9 -0
  77. package/src/cli/commands/package/update-cli.js +252 -0
  78. package/src/cli/commands/package/versions.js +35 -0
  79. package/src/cli/commands/package.js +29 -813
  80. package/src/cli/commands/query/change-plan.js +68 -0
  81. package/src/cli/commands/query/definitions.js +202 -0
  82. package/src/cli/commands/query/import-adopt.js +121 -0
  83. package/src/cli/commands/query/runner/artifacts.js +102 -0
  84. package/src/cli/commands/query/runner/boundaries.js +211 -0
  85. package/src/cli/commands/query/runner/change.js +182 -0
  86. package/src/cli/commands/query/runner/import-adopt.js +111 -0
  87. package/src/cli/commands/query/runner/index.js +31 -0
  88. package/src/cli/commands/query/runner/output.js +12 -0
  89. package/src/cli/commands/query/runner/workflow.js +241 -0
  90. package/src/cli/commands/query/runner.js +3 -0
  91. package/src/cli/commands/query/workflow-context.js +5 -0
  92. package/src/cli/commands/query/workspace.js +270 -0
  93. package/src/cli/commands/query.js +9 -1300
  94. package/src/cli/commands/source.js +3 -12
  95. package/src/cli/commands/template/baseline.js +100 -0
  96. package/src/cli/commands/template/check.js +467 -0
  97. package/src/cli/commands/template/constants.js +8 -0
  98. package/src/cli/commands/template/diagnostics.js +26 -0
  99. package/src/cli/commands/template/help.js +28 -0
  100. package/src/cli/commands/template/lifecycle.js +404 -0
  101. package/src/cli/commands/template/list-show.js +287 -0
  102. package/src/cli/commands/template/policy.js +422 -0
  103. package/src/cli/commands/template/shared.js +127 -0
  104. package/src/cli/commands/template/updates.js +352 -0
  105. package/src/cli/commands/template-runner.js +6 -6
  106. package/src/cli/commands/template.js +41 -2143
  107. package/src/cli/commands/trust.js +1 -1
  108. package/src/cli/commands/workflow.js +6 -1
  109. package/src/cli/dispatcher.js +6 -1
  110. package/src/cli/help.js +15 -14
  111. package/src/cli/migration-guidance.js +1 -1
  112. package/src/cli/output-safety.js +2 -1
  113. package/src/cli/path-normalization.js +3 -13
  114. package/src/generator/api/contracts.js +497 -0
  115. package/src/generator/api/metadata.js +221 -0
  116. package/src/generator/api/openapi.js +559 -0
  117. package/src/generator/api/schema.js +124 -0
  118. package/src/generator/api/types.d.ts +98 -0
  119. package/src/generator/api.js +3 -1195
  120. package/src/generator/context/domain-page.js +1 -1
  121. package/src/generator/context/shared/domain-sdlc.js +282 -0
  122. package/src/generator/context/shared/maintained-boundary.js +665 -0
  123. package/src/generator/context/shared/metrics.js +85 -0
  124. package/src/generator/context/shared/primitives.js +64 -0
  125. package/src/generator/context/shared/relationships.js +453 -0
  126. package/src/generator/context/shared/summaries.js +263 -0
  127. package/src/generator/context/shared/types.d.ts +207 -0
  128. package/src/generator/context/shared.d.ts +42 -0
  129. package/src/generator/context/shared.js +80 -1390
  130. package/src/generator/context/slice/core.js +397 -0
  131. package/src/generator/context/slice/sdlc.js +417 -0
  132. package/src/generator/context/slice/ui-packets.js +183 -0
  133. package/src/generator/context/slice.js +2 -859
  134. package/src/generator/context/task-mode.js +2 -2
  135. package/src/generator/registry/index.js +507 -0
  136. package/src/generator/registry.js +18 -504
  137. package/src/generator/runtime/environment/index.js +666 -0
  138. package/src/generator/runtime/environment.js +4 -666
  139. package/src/generator/runtime/runtime-check/index.js +554 -0
  140. package/src/generator/runtime/runtime-check.js +4 -554
  141. package/src/generator/runtime/shared/index.js +572 -0
  142. package/src/generator/runtime/shared.js +19 -570
  143. package/src/generator/sdlc/doc-page.js +1 -1
  144. package/src/generator/shared.d.ts +2 -0
  145. package/src/generator/surfaces/databases/lifecycle-shared.js +1 -1
  146. package/src/generator/surfaces/native/swiftui-templates/README.generated.md +1 -1
  147. package/src/generator/surfaces/shared.d.ts +3 -0
  148. package/src/generator/widget-conformance/behavior-report.js +258 -0
  149. package/src/generator/widget-conformance/checks.js +371 -0
  150. package/src/generator/widget-conformance/projection-context.js +200 -0
  151. package/src/generator/widget-conformance/report.js +166 -0
  152. package/src/generator/widget-conformance/types.d.ts +121 -0
  153. package/src/generator/widget-conformance.js +3 -824
  154. package/src/import/core/context.d.ts +3 -0
  155. package/src/import/core/context.js +5 -7
  156. package/src/import/core/contracts.d.ts +1 -0
  157. package/src/import/core/registry.d.ts +4 -0
  158. package/src/import/core/runner/candidates.js +337 -0
  159. package/src/import/core/runner/options.js +22 -0
  160. package/src/import/core/runner/reports.js +51 -0
  161. package/src/import/core/runner/run.js +79 -0
  162. package/src/import/core/runner/tracks.js +150 -0
  163. package/src/import/core/runner/ui-drafts.js +393 -0
  164. package/src/import/core/runner.js +3 -698
  165. package/src/import/core/shared/api-routes.js +221 -0
  166. package/src/import/core/shared/candidates.js +97 -0
  167. package/src/import/core/shared/files.js +177 -0
  168. package/src/import/core/shared/next-app.js +389 -0
  169. package/src/import/core/shared/types.d.ts +51 -0
  170. package/src/import/core/shared/ui-routes.js +230 -0
  171. package/src/import/core/shared.js +60 -861
  172. package/src/new-project/constants.js +128 -0
  173. package/src/new-project/create.js +90 -0
  174. package/src/new-project/json.js +28 -0
  175. package/src/new-project/metadata.js +96 -0
  176. package/src/new-project/package-spec.js +161 -0
  177. package/src/new-project/project-files.js +351 -0
  178. package/src/new-project/template-policy.js +269 -0
  179. package/src/new-project/template-resolution.js +370 -0
  180. package/src/new-project/template-snapshots.js +442 -0
  181. package/src/new-project/template-updates.js +512 -0
  182. package/src/new-project/types.d.ts +83 -0
  183. package/src/new-project.js +6 -2277
  184. package/src/parser.d.ts +87 -1
  185. package/src/parser.js +118 -0
  186. package/src/policy/review-boundaries.d.ts +15 -0
  187. package/src/project-config/index.js +591 -0
  188. package/src/project-config.js +19 -561
  189. package/src/resolver/enrich/acceptance-criterion.js +2 -0
  190. package/src/resolver/enrich/bug.js +2 -0
  191. package/src/resolver/enrich/pitch.js +2 -0
  192. package/src/resolver/enrich/requirement.js +2 -0
  193. package/src/resolver/enrich/task.js +2 -0
  194. package/src/resolver/index.js +19 -2089
  195. package/src/resolver/normalize.js +384 -1
  196. package/src/resolver/plans.js +168 -0
  197. package/src/resolver/projections-api.js +494 -0
  198. package/src/resolver/projections-db.js +133 -0
  199. package/src/resolver/projections-ui.js +317 -0
  200. package/src/resolver/shapes.js +251 -0
  201. package/src/resolver/shared.js +278 -0
  202. package/src/resolver/widgets.js +132 -0
  203. package/src/sdlc/adopt.js +6 -5
  204. package/src/sdlc/paths.js +3 -5
  205. package/src/sdlc/scaffold.js +2 -1
  206. package/src/template-trust/constants.js +62 -0
  207. package/src/template-trust/content.js +258 -0
  208. package/src/template-trust/diff.js +92 -0
  209. package/src/template-trust/policy.js +61 -0
  210. package/src/template-trust/record.js +90 -0
  211. package/src/template-trust/status.js +182 -0
  212. package/src/template-trust.js +24 -687
  213. package/src/text-helpers.d.ts +1 -0
  214. package/src/topogram-types.d.ts +69 -0
  215. package/src/validator/common.js +488 -0
  216. package/src/validator/data-model.js +237 -0
  217. package/src/validator/docs.js +167 -0
  218. package/src/validator/expressions.js +146 -1
  219. package/src/validator/index.d.ts +23 -0
  220. package/src/validator/index.js +32 -3585
  221. package/src/validator/kinds.d.ts +41 -0
  222. package/src/validator/kinds.js +2 -0
  223. package/src/validator/model-helpers.js +46 -0
  224. package/src/validator/per-kind/acceptance-criterion.js +5 -0
  225. package/src/validator/per-kind/bug.js +6 -0
  226. package/src/validator/per-kind/domain.js +15 -2
  227. package/src/validator/per-kind/pitch.js +7 -0
  228. package/src/validator/per-kind/requirement.js +5 -0
  229. package/src/validator/per-kind/task.js +7 -0
  230. package/src/validator/per-kind/widget.js +14 -0
  231. package/src/validator/projections/api-http-async.js +410 -0
  232. package/src/validator/projections/api-http-authz.js +88 -0
  233. package/src/validator/projections/api-http-core.js +205 -0
  234. package/src/validator/projections/api-http-policies.js +339 -0
  235. package/src/validator/projections/api-http-responses.js +233 -0
  236. package/src/validator/projections/api-http.js +44 -0
  237. package/src/validator/projections/db.js +353 -0
  238. package/src/validator/projections/generator-defaults.js +45 -0
  239. package/src/validator/projections/helpers.js +87 -0
  240. package/src/validator/projections/ui-helpers.js +214 -0
  241. package/src/validator/projections/ui-navigation.js +344 -0
  242. package/src/validator/projections/ui-structure.js +364 -0
  243. package/src/validator/projections/ui-widgets.js +493 -0
  244. package/src/validator/projections/ui.js +46 -0
  245. package/src/validator/registry.js +48 -1
  246. package/src/validator/utils.d.ts +20 -0
  247. package/src/validator/utils.js +115 -12
  248. package/src/widget-behavior.d.ts +1 -0
  249. package/src/workflows/import-app/api/collect.js +221 -0
  250. package/src/workflows/import-app/api/openapi.js +257 -0
  251. package/src/workflows/import-app/api/routes.js +327 -0
  252. package/src/workflows/import-app/api/sources.js +22 -0
  253. package/src/workflows/import-app/api.js +2 -797
  254. package/src/workflows/reconcile/adoption-plan/build.js +212 -0
  255. package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
  256. package/src/workflows/reconcile/adoption-plan/outputs.js +153 -0
  257. package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
  258. package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
  259. package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
  260. package/src/workflows/reconcile/adoption-plan.js +30 -740
  261. package/src/workflows/reconcile/auth/closures.js +115 -0
  262. package/src/workflows/reconcile/auth/formatters.js +142 -0
  263. package/src/workflows/reconcile/auth/inference.js +330 -0
  264. package/src/workflows/reconcile/auth/roles.js +122 -0
  265. package/src/workflows/reconcile/auth.js +35 -690
  266. package/src/workflows/reconcile/bundle-core/index.js +600 -0
  267. package/src/workflows/reconcile/bundle-core.js +12 -598
  268. package/src/workflows/reconcile/candidate-model.js +18 -2
  269. package/src/workflows/reconcile/canonical-surface.js +1 -1
  270. package/src/workflows/reconcile/impacts/adoption-plan.js +196 -0
  271. package/src/workflows/reconcile/impacts/indexes.js +105 -0
  272. package/src/workflows/reconcile/impacts/patches.js +252 -0
  273. package/src/workflows/reconcile/impacts/reports.js +80 -0
  274. package/src/workflows/reconcile/impacts.js +14 -623
  275. package/src/workflows/reconcile/renderers.js +41 -6
  276. package/src/workflows/shared.js +5 -11
  277. package/src/workspace-docs.d.ts +29 -0
  278. package/src/workspace-paths.js +328 -0
@@ -1,1302 +1,11 @@
1
1
  // @ts-check
2
2
 
3
- import fs from "node:fs";
4
- import path from "node:path";
5
-
6
- import { stableStringify } from "../../format.js";
7
- import { generateWorkspace } from "../../generator.js";
8
- import { recommendedVerificationTargets } from "../../generator/context/shared.js";
9
- import { parsePath } from "../../parser.js";
10
- import { resolveWorkspace } from "../../resolver.js";
11
- import { formatValidationErrors } from "../../validator.js";
12
- import {
13
- buildAuthHintsQueryPayload,
14
- buildAuthReviewPacketPayload,
15
- buildCanonicalWritesPayloadForChangePlan,
16
- buildCanonicalWritesPayloadForImportPlan,
17
- buildChangePlanPayload,
18
- buildHandoffStatusPayload,
19
- buildImportPlanPayload,
20
- buildLaneStatusPayload,
21
- buildMaintainedConformancePayload,
22
- buildMaintainedDriftPayload,
23
- buildMaintainedRiskSummary,
24
- buildMultiAgentPlanPayload,
25
- buildResolvedWorkflowContextPayload,
26
- buildReviewPacketPayloadForChangePlan,
27
- buildReviewPacketPayloadForImportPlan,
28
- buildRiskSummaryPayload,
29
- buildSeamCheckPayload,
30
- buildSingleAgentPlanPayload,
31
- buildWorkflowPresetActivationPayload,
32
- buildWorkflowPresetCustomizationPayload,
33
- buildWorkflowPresetDiffPayload,
34
- buildWorkflowPresetState,
35
- buildWorkPacketPayload,
36
- classifyRisk,
37
- proceedDecisionFromRisk,
38
- summarizeDiffArtifact
39
- } from "../../agent-ops/query-builders.js";
40
-
41
- /**
42
- * @typedef {{
43
- * name: string,
44
- * purpose: string,
45
- * description: string,
46
- * selectors: string[],
47
- * args: string[],
48
- * output: string,
49
- * example: string
50
- * }} QueryDefinition
51
- *
52
- * @typedef {{
53
- * type: "query_list",
54
- * version: 1,
55
- * queries: QueryDefinition[]
56
- * }} QueryListPayload
57
- *
58
- * @typedef {{
59
- * type: "query_definition",
60
- * version: 1,
61
- * query: QueryDefinition
62
- * }} QueryDefinitionPayload
63
- */
64
-
65
- /**
66
- * @typedef {Record<string, any>} AnyRecord
67
- */
68
-
69
- /**
70
- * @returns {QueryDefinition[]}
71
- */
72
- export function queryDefinitions() {
73
- return [
74
- {
75
- name: "slice",
76
- purpose: "Give an agent the smallest graph slice needed to reason about one selected semantic surface.",
77
- description: "Return a focused semantic context slice for one selected surface.",
78
- selectors: ["capability", "workflow", "projection", "widget", "entity", "journey", "domain"],
79
- args: ["[path]", "[selectors]", "[--json]"],
80
- output: "context_slice",
81
- example: "topogram query slice ./topogram --widget widget_data_grid"
82
- },
83
- {
84
- name: "verification-targets",
85
- purpose: "Map a selected change or mode to the smallest verification set worth running.",
86
- description: "Return the smallest verification target set for a mode, selector, or diff.",
87
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "from-topogram"],
88
- args: ["[path]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
89
- output: "verification_targets",
90
- example: "topogram query verification-targets ./topogram --widget widget_data_grid"
91
- },
92
- {
93
- name: "widget-behavior",
94
- purpose: "Show how reusable widget behavior is realized by projection usage.",
95
- description: "Return widget behavior realization data grouped by widget, screen, capability, and effect.",
96
- selectors: ["projection", "widget"],
97
- args: ["[path]", "[--projection <id>]", "[--widget <id>]", "[--json]"],
98
- output: "widget_behavior_report",
99
- example: "topogram query widget-behavior ./topogram --projection proj_web_surface --widget widget_data_grid --json"
100
- },
101
- {
102
- name: "change-plan",
103
- purpose: "Summarize what a selected change affects before code or Topogram edits start.",
104
- description: "Return the semantic change plan, generator targets, risk, and alignment recommendations.",
105
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "surface", "from-topogram"],
106
- args: ["[path]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
107
- output: "change_plan_query",
108
- example: "topogram query change-plan ./topogram --widget widget_data_grid"
109
- },
110
- {
111
- name: "review-packet",
112
- purpose: "Bundle the context a human or agent needs to review a selected semantic change.",
113
- description: "Return the review packet for a selected change or diff.",
114
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "surface", "from-topogram"],
115
- args: ["[path]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
116
- output: "review_packet_query",
117
- example: "topogram query review-packet ./topogram --widget widget_data_grid"
118
- },
119
- {
120
- name: "resolved-workflow-context",
121
- purpose: "Resolve workflow guidance and artifact load order for a selected mode or change.",
122
- description: "Return resolved workflow guidance, artifact load order, preset policy, and recommended artifact queries.",
123
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "surface", "provider", "preset", "from-topogram"],
124
- args: ["[path]", "[--mode <id>]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
125
- output: "resolved_workflow_context_query",
126
- example: "topogram query resolved-workflow-context ./topogram --mode modeling --widget widget_data_grid --json"
127
- },
128
- {
129
- name: "single-agent-plan",
130
- purpose: "Give one coding agent a bounded plan, artifact set, and write guidance.",
131
- description: "Return a single-agent operating plan for a mode and optional selector.",
132
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "surface", "from-topogram"],
133
- args: ["[path]", "[--mode <id>]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
134
- output: "single_agent_plan_query",
135
- example: "topogram query single-agent-plan ./topogram --mode modeling --widget widget_data_grid --json"
136
- },
137
- {
138
- name: "risk-summary",
139
- purpose: "Surface behavioral, ownership, and verification risks for a selected change.",
140
- description: "Return the risk summary for a selected change, mode, or diff.",
141
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "surface", "from-topogram"],
142
- args: ["[path]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
143
- output: "risk_summary_query",
144
- example: "topogram query risk-summary ./topogram --widget widget_data_grid"
145
- },
146
- {
147
- name: "proceed-decision",
148
- purpose: "Tell a human or agent whether enough context and proof exist to proceed.",
149
- description: "Return a proceed/no-go decision for the current selected work.",
150
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "surface", "from-topogram"],
151
- args: ["[path]", "[--mode <id>]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
152
- output: "proceed_decision_query",
153
- example: "topogram query proceed-decision ./topogram --mode verification"
154
- },
155
- {
156
- name: "write-scope",
157
- purpose: "Define where an agent may edit for a selected semantic surface.",
158
- description: "Return safe edit boundaries for a selected mode or semantic surface.",
159
- selectors: ["mode", "capability", "workflow", "projection", "widget", "entity", "journey", "from-topogram"],
160
- args: ["[path]", "[selectors]", "[--from-topogram <path>]", "[--json]"],
161
- output: "write_scope_query",
162
- example: "topogram query write-scope ./topogram --widget widget_data_grid"
163
- }
164
- ];
165
- }
166
-
167
- /**
168
- * @returns {QueryListPayload}
169
- */
170
- export function buildQueryListPayload() {
171
- return {
172
- type: "query_list",
173
- version: 1,
174
- queries: queryDefinitions()
175
- };
176
- }
177
-
178
- /**
179
- * @param {string} name
180
- * @returns {QueryDefinitionPayload}
181
- */
182
- export function buildQueryShowPayload(name) {
183
- const query = queryDefinitions().find((entry) => entry.name === name);
184
- if (!query) {
185
- const known = queryDefinitions().map((entry) => entry.name).join(", ");
186
- throw new Error(`Unknown query '${name}'. Run 'topogram query list' to inspect available queries. Known queries: ${known}`);
187
- }
188
- return {
189
- type: "query_definition",
190
- version: 1,
191
- query
192
- };
193
- }
194
-
195
- /**
196
- * @returns {void}
197
- */
198
- export function printQueryHelp() {
199
- console.log("Usage: topogram query list [--json]");
200
- console.log(" or: topogram query show <name> [--json]");
201
- console.log(" or: topogram query widget-behavior [path] [--projection <id>] [--widget <id>] [--json]");
202
- console.log(" or: topogram query <name> [path] [selectors] [--json]");
203
- console.log("");
204
- console.log("Agent-facing queries return focused JSON packets for context, review, verification, and generation follow-up.");
205
- console.log("");
206
- console.log("Common queries:");
207
- for (const query of queryDefinitions()) {
208
- console.log(` ${query.name}`);
209
- console.log(` ${query.description}`);
210
- console.log(` example: ${query.example}`);
211
- }
212
- }
213
-
214
- /**
215
- * @param {QueryDefinitionPayload} payload
216
- * @returns {void}
217
- */
218
- export function printQueryDefinition(payload) {
219
- const query = payload.query;
220
- console.log(`Query: ${query.name}`);
221
- console.log(`Purpose: ${query.purpose}`);
222
- console.log(`Description: ${query.description}`);
223
- console.log(`Output: ${query.output}`);
224
- console.log(`Arguments: ${query.args.join(" ")}`);
225
- console.log(`Selectors: ${query.selectors.join(", ") || "none"}`);
226
- console.log(`Example: ${query.example}`);
227
- }
228
-
229
- /**
230
- * @param {QueryListPayload} payload
231
- * @returns {void}
232
- */
233
- export function printQueryList(payload) {
234
- console.log("Topogram queries:");
235
- for (const query of payload.queries) {
236
- console.log(`- ${query.name}: ${query.description}`);
237
- console.log(` selectors: ${query.selectors.join(", ") || "none"}`);
238
- console.log(` example: ${query.example}`);
239
- }
240
- }
241
-
242
- /**
243
- * @param {string} inputPath
244
- * @returns {string}
245
- */
246
- function normalizeTopogramPath(inputPath) {
247
- const absolute = path.resolve(inputPath);
248
- if (path.basename(absolute) === "topogram") {
249
- return absolute;
250
- }
251
- const candidate = path.join(absolute, "topogram");
252
- return fs.existsSync(candidate) ? candidate : absolute;
253
- }
254
-
255
- /**
256
- * @param {AnyRecord} taskModeArtifact
257
- * @param {string|null} providerId
258
- * @param {string|null} presetId
259
- * @param {string|null} queryFamily
260
- * @returns {AnyRecord}
261
- */
262
- function workflowPresetSelectors(taskModeArtifact, providerId = null, presetId = null, queryFamily = null) {
263
- const categories = [];
264
- if (taskModeArtifact?.mode === "import-adopt") categories.push("provider_adoption");
265
- if (taskModeArtifact?.mode === "maintained-app-edit") categories.push("maintained_app");
266
- if ((taskModeArtifact?.verification_targets?.maintained_app_checks || []).length > 0) categories.push("maintained_boundary");
267
- return {
268
- mode: taskModeArtifact?.mode || null,
269
- task_class: taskModeArtifact?.mode || null,
270
- provider_id: providerId,
271
- preset_id: presetId,
272
- query_family: queryFamily,
273
- integration_categories: categories
274
- };
275
- }
276
-
277
- /**
278
- * @param {AnyRecord} options
279
- * @returns {AnyRecord[]}
280
- */
281
- function generatorTargetsForWorkflowContext(options = {}) {
282
- const { graph, taskModeArtifact, sliceArtifact = null, diffArtifact = null, maintainedBoundaryArtifact = null } = options;
283
- if (!graph || !taskModeArtifact) {
284
- return [];
285
- }
286
- return buildChangePlanPayload({
287
- graph,
288
- taskModeArtifact,
289
- sliceArtifact,
290
- diffArtifact,
291
- maintainedBoundaryArtifact
292
- }).generator_targets || [];
293
- }
294
-
295
- /**
296
- * @param {AnyRecord} options
297
- * @returns {boolean}
298
- */
299
- function importAdoptOnlyRequested(options = {}) {
300
- return options.modeId === "import-adopt" && !(
301
- options.capabilityId ||
302
- options.workflowId ||
303
- options.projectionId ||
304
- options.componentId ||
305
- options.entityId ||
306
- options.journeyId ||
307
- options.surfaceId ||
308
- options.domainId ||
309
- options.fromTopogramPath
310
- );
311
- }
312
-
313
- /**
314
- * @param {AnyRecord} result
315
- * @returns {boolean}
316
- */
317
- function resultOk(result) {
318
- return Boolean(result?.ok);
319
- }
320
-
321
- /**
322
- * @param {AnyRecord} result
323
- * @returns {number}
324
- */
325
- function printValidationFailure(result) {
326
- console.error(formatValidationErrors(result.validation));
327
- return 1;
328
- }
329
-
330
- /**
331
- * @param {AnyRecord} ast
332
- * @param {AnyRecord} selectors
333
- * @param {string} modeId
334
- * @param {string|null} fromTopogramPath
335
- * @returns {AnyRecord}
336
- */
337
- function buildTaskMode(ast, selectors, modeId, fromTopogramPath = null) {
338
- return generateWorkspace(ast, {
339
- target: "context-task-mode",
340
- modeId,
341
- ...selectors,
342
- widgetId: selectors.componentId,
343
- fromTopogramPath
344
- });
345
- }
346
-
347
- /**
348
- * @param {AnyRecord} ast
349
- * @param {AnyRecord} selectors
350
- * @returns {AnyRecord}
351
- */
352
- function buildSlice(ast, selectors) {
353
- return generateWorkspace(ast, {
354
- target: "context-slice",
355
- ...selectors,
356
- widgetId: selectors.componentId
357
- });
358
- }
359
-
360
- /**
361
- * @param {AnyRecord} ast
362
- * @returns {AnyRecord}
363
- */
364
- function buildMaintainedBundle(ast) {
365
- return generateWorkspace(ast, {
366
- target: "context-bundle",
367
- taskId: "maintained-app"
368
- });
369
- }
370
-
371
- /**
372
- * @param {AnyRecord} ast
373
- * @param {string|null} fromTopogramPath
374
- * @returns {AnyRecord|null}
375
- */
376
- function buildDiff(ast, fromTopogramPath) {
377
- return fromTopogramPath
378
- ? generateWorkspace(ast, {
379
- target: "context-diff",
380
- fromTopogramPath
381
- })
382
- : null;
383
- }
384
-
385
- /**
386
- * @param {AnyRecord|null} result
387
- * @returns {AnyRecord|null}
388
- */
389
- function artifactOrNull(result) {
390
- return result?.artifact || null;
391
- }
392
-
393
- /**
394
- * @param {string} topogramRoot
395
- * @returns {string}
396
- */
397
- function adoptionPlanPath(topogramRoot) {
398
- return path.join(topogramRoot, "candidates", "reconcile", "adoption-plan.agent.json");
399
- }
400
-
401
- /**
402
- * @param {string} topogramRoot
403
- * @param {string} label
404
- * @returns {{ reportPath: string, adoptionStatusPath: string, adoptionPlanPath: string }}
405
- */
406
- function requireReconcileArtifacts(topogramRoot, label) {
407
- const reportPath = path.join(topogramRoot, "candidates", "reconcile", "report.json");
408
- const adoptionStatusPath = path.join(topogramRoot, "candidates", "reconcile", "adoption-status.json");
409
- const planPath = adoptionPlanPath(topogramRoot);
410
- if (!fs.existsSync(reportPath) || !fs.existsSync(adoptionStatusPath) || !fs.existsSync(planPath)) {
411
- throw new Error(`No reconcile ${label} artifacts found under '${path.join(topogramRoot, "candidates", "reconcile")}'. Run 'node ./src/cli.js reconcile ${topogramRoot}' first.`);
412
- }
413
- return { reportPath, adoptionStatusPath, adoptionPlanPath: planPath };
414
- }
415
-
416
- /**
417
- * @param {string} filePath
418
- * @returns {AnyRecord}
419
- */
420
- function readJson(filePath) {
421
- return JSON.parse(fs.readFileSync(filePath, "utf8"));
422
- }
423
-
424
- /**
425
- * @param {AnyRecord} options
426
- * @returns {boolean}
427
- */
428
- function hasSelectors(options) {
429
- return Boolean(
430
- options.capabilityId ||
431
- options.workflowId ||
432
- options.projectionId ||
433
- options.componentId ||
434
- options.entityId ||
435
- options.journeyId ||
436
- options.surfaceId ||
437
- options.domainId
438
- );
439
- }
440
-
441
- /**
442
- * @param {AnyRecord} options
443
- * @returns {boolean}
444
- */
445
- function shouldUseImportAdoptPath(options) {
446
- const selectorOrDiff = hasSelectors(options) || Boolean(options.fromTopogramPath);
447
- return importAdoptOnlyRequested(options) || (!selectorOrDiff && !options.modeId);
448
- }
449
-
450
- /**
451
- * @param {AnyRecord} options
452
- * @returns {AnyRecord}
453
- */
454
- function selectorOptions(options) {
455
- return {
456
- capabilityId: options.capabilityId,
457
- workflowId: options.workflowId,
458
- projectionId: options.projectionId,
459
- componentId: options.componentId,
460
- entityId: options.entityId,
461
- journeyId: options.journeyId,
462
- surfaceId: options.surfaceId,
463
- domainId: options.domainId
464
- };
465
- }
466
-
467
- /**
468
- * @param {AnyRecord} context
469
- * @param {string} defaultMode
470
- * @returns {{ ast: AnyRecord, resolved: AnyRecord, taskModeResult: AnyRecord, sliceResult: AnyRecord|null, diffResult: AnyRecord|null, maintainedBundleResult: AnyRecord|null, changePlan: AnyRecord, diffSummary: AnyRecord|null, maintainedRisk: AnyRecord }}
471
- */
472
- function buildChangePlanContext(context, defaultMode = "modeling") {
473
- const ast = parsePath(context.inputPath);
474
- const resolved = resolveWorkspace(ast);
475
- if (!resultOk(resolved)) {
476
- return /** @type {any} */ ({ ast, resolved });
477
- }
478
- const selectors = selectorOptions(context);
479
- const effectiveModeId = context.modeId || defaultMode;
480
- const taskModeResult = buildTaskMode(ast, selectors, effectiveModeId, context.fromTopogramPath);
481
- if (!resultOk(taskModeResult)) {
482
- return /** @type {any} */ ({ ast, resolved, taskModeResult });
483
- }
484
- const sliceResult = hasSelectors(context) ? buildSlice(ast, selectors) : null;
485
- if (sliceResult && !resultOk(sliceResult)) {
486
- return /** @type {any} */ ({ ast, resolved, taskModeResult, sliceResult });
487
- }
488
- const diffResult = buildDiff(ast, context.fromTopogramPath);
489
- if (diffResult && !resultOk(diffResult)) {
490
- return /** @type {any} */ ({ ast, resolved, taskModeResult, sliceResult, diffResult });
491
- }
492
- const includeMaintainedBoundary =
493
- effectiveModeId === "maintained-app-edit" ||
494
- context.surfaceId === "maintained-boundary" ||
495
- Boolean(diffResult?.artifact?.affected_maintained_surfaces?.ownership_interpretation?.maintained_code_impact);
496
- const maintainedBundleResult = includeMaintainedBoundary ? buildMaintainedBundle(ast) : null;
497
- if (maintainedBundleResult && !resultOk(maintainedBundleResult)) {
498
- return /** @type {any} */ ({ ast, resolved, taskModeResult, sliceResult, diffResult, maintainedBundleResult });
499
- }
500
- const changePlan = buildChangePlanPayload({
501
- graph: resolved.graph,
502
- taskModeArtifact: taskModeResult.artifact,
503
- sliceArtifact: artifactOrNull(sliceResult),
504
- diffArtifact: artifactOrNull(diffResult),
505
- maintainedBoundaryArtifact: maintainedBundleResult?.artifact?.maintained_boundary || null
506
- });
507
- const diffSummary = changePlan.diff_summary || summarizeDiffArtifact(diffResult?.artifact || null);
508
- const maintainedRisk = buildMaintainedRiskSummary({
509
- maintainedImpacts: changePlan.maintained_impacts,
510
- maintainedBoundary: changePlan.maintained_boundary,
511
- diffSummary
512
- });
513
- return { ast, resolved, taskModeResult, sliceResult, diffResult, maintainedBundleResult, changePlan, diffSummary, maintainedRisk };
514
- }
515
-
516
- /**
517
- * @param {AnyRecord} context
518
- * @param {string} queryFamily
519
- * @returns {AnyRecord}
520
- */
521
- function buildImportPlanForContext(context, queryFamily) {
522
- const topogramRoot = normalizeTopogramPath(context.inputPath);
523
- const planPath = adoptionPlanPath(topogramRoot);
524
- if (!fs.existsSync(planPath)) {
525
- throw new Error(`No agent adoption plan found at '${planPath}'`);
526
- }
527
- const adoptionPlan = readJson(planPath);
528
- const ast = parsePath(context.inputPath);
529
- const taskModeResult = buildTaskMode(ast, {}, "import-adopt");
530
- if (!resultOk(taskModeResult)) {
531
- return taskModeResult;
532
- }
533
- const maintainedBundleResult = buildMaintainedBundle(ast);
534
- if (!resultOk(maintainedBundleResult)) {
535
- return maintainedBundleResult;
536
- }
537
- const workflowPresets = buildWorkflowPresetState({
538
- workspace: topogramRoot,
539
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, queryFamily)
540
- });
541
- return {
542
- ok: true,
543
- topogramRoot,
544
- taskModeResult,
545
- maintainedBundleResult,
546
- adoptionPlan,
547
- importPlan: buildImportPlanPayload(
548
- adoptionPlan,
549
- taskModeResult.artifact,
550
- maintainedBundleResult.artifact.maintained_boundary || null,
551
- workflowPresets
552
- )
553
- };
554
- }
555
-
556
- /**
557
- * @param {AnyRecord} context
558
- * @param {string} queryFamily
559
- * @returns {AnyRecord}
560
- */
561
- function buildImportAdoptAgentContext(context, queryFamily) {
562
- const topogramRoot = normalizeTopogramPath(context.inputPath);
563
- const artifacts = requireReconcileArtifacts(topogramRoot, queryFamily);
564
- const ast = parsePath(context.inputPath);
565
- const taskModeResult = buildTaskMode(ast, {}, "import-adopt");
566
- if (!resultOk(taskModeResult)) {
567
- return taskModeResult;
568
- }
569
- const adoptionPlanArtifact = readJson(artifacts.adoptionPlanPath);
570
- const reconcileReport = readJson(artifacts.reportPath);
571
- const adoptionStatus = readJson(artifacts.adoptionStatusPath);
572
- const workflowPresets = buildWorkflowPresetState({
573
- workspace: topogramRoot,
574
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, queryFamily)
575
- });
576
- const importPlan = buildImportPlanPayload(adoptionPlanArtifact, taskModeResult.artifact, null, workflowPresets);
577
- const resolvedWorkflowContext = buildResolvedWorkflowContextPayload({
578
- workspace: topogramRoot,
579
- taskModeArtifact: taskModeResult.artifact,
580
- importPlan,
581
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, queryFamily)
582
- });
583
- const singleAgentPlan = buildSingleAgentPlanPayload({
584
- workspace: topogramRoot,
585
- taskModeArtifact: taskModeResult.artifact,
586
- importPlan,
587
- resolvedWorkflowContext
588
- });
589
- const multiAgentPlan = buildMultiAgentPlanPayload({
590
- workspace: topogramRoot,
591
- singleAgentPlan,
592
- importPlan,
593
- report: reconcileReport,
594
- adoptionStatus,
595
- resolvedWorkflowContext
596
- });
597
- return {
598
- ok: true,
599
- topogramRoot,
600
- taskModeResult,
601
- adoptionPlanArtifact,
602
- reconcileReport,
603
- adoptionStatus,
604
- importPlan,
605
- resolvedWorkflowContext,
606
- singleAgentPlan,
607
- multiAgentPlan
608
- };
609
- }
610
-
611
- /**
612
- * @param {AnyRecord} nextAction
613
- * @param {string|null} mode
614
- * @returns {string}
615
- */
616
- function resolveRecommendedQueryFamily(nextAction, mode) {
617
- switch (nextAction?.kind) {
618
- case "review_staged":
619
- case "review_bundle":
620
- case "inspect_review_group":
621
- case "inspect_proposal_surface":
622
- case "customize_workflow_preset":
623
- case "refresh_workflow_preset_customization":
624
- case "import_declared_workflow_preset":
625
- return "import-plan";
626
- case "review_diff_impact":
627
- case "inspect_projection":
628
- case "inspect_diff":
629
- case "review_diff_boundaries":
630
- return "change-plan";
631
- case "inspect_maintained_impact":
632
- case "inspect_boundary_before_edit":
633
- case "run_maintained_checks":
634
- return "maintained-boundary";
635
- case "inspect_verification_targets":
636
- return "verification-targets";
637
- case "inspect_workspace_digest":
638
- return "single-agent-plan";
639
- default:
640
- break;
641
- }
642
- if (mode === "import-adopt") return "import-plan";
643
- if (mode === "maintained-app-edit") return "maintained-boundary";
644
- if (mode === "verification") return "verification-targets";
645
- return "change-plan";
646
- }
647
-
648
- /**
649
- * @param {AnyRecord} context
650
- * @returns {Promise<number|null>}
651
- */
652
- export async function runQueryCommand(context) {
653
- const queryName = context.commandArgs?.queryName;
654
- const selectors = selectorOptions(context);
655
- const selectedWidgetId = context["componentId"];
656
-
657
- if (queryName === "task-mode") {
658
- const result = generateWorkspace(parsePath(context.inputPath), {
659
- target: "context-task-mode",
660
- modeId: context.modeId,
661
- ...selectors,
662
- widgetId: selectedWidgetId,
663
- fromTopogramPath: context.fromTopogramPath
664
- });
665
- if (!resultOk(result)) return printValidationFailure(result);
666
- console.log(stableStringify(result.artifact));
667
- return 0;
668
- }
669
-
670
- if (queryName === "diff") {
671
- const result = generateWorkspace(parsePath(context.inputPath), {
672
- target: "context-diff",
673
- fromTopogramPath: context.fromTopogramPath
674
- });
675
- if (!resultOk(result)) return printValidationFailure(result);
676
- console.log(stableStringify(result.artifact));
677
- return 0;
678
- }
679
-
680
- if (queryName === "slice") {
681
- const result = buildSlice(parsePath(context.inputPath), selectors);
682
- if (!resultOk(result)) return printValidationFailure(result);
683
- console.log(stableStringify(result.artifact));
684
- return 0;
685
- }
686
-
687
- if (queryName === "adoption-plan") {
688
- const topogramRoot = normalizeTopogramPath(context.inputPath);
689
- const planPath = adoptionPlanPath(topogramRoot);
690
- if (!fs.existsSync(planPath)) {
691
- throw new Error(`No agent adoption plan found at '${planPath}'`);
692
- }
693
- console.log(stableStringify(readJson(planPath)));
694
- return 0;
695
- }
696
-
697
- if (queryName === "maintained-boundary") {
698
- const result = buildMaintainedBundle(parsePath(context.inputPath));
699
- if (!resultOk(result)) return printValidationFailure(result);
700
- console.log(stableStringify(result.artifact.maintained_boundary));
701
- return 0;
702
- }
703
-
704
- if (queryName === "maintained-drift") {
705
- if (!context.fromTopogramPath) {
706
- throw new Error("query maintained-drift requires --from-topogram <path>.");
707
- }
708
- const ast = parsePath(context.inputPath);
709
- const diffResult = buildDiff(ast, context.fromTopogramPath);
710
- if (diffResult && !resultOk(diffResult)) return printValidationFailure(diffResult);
711
- const maintainedBundleResult = buildMaintainedBundle(ast);
712
- if (!resultOk(maintainedBundleResult)) return printValidationFailure(maintainedBundleResult);
713
- const taskModeResult = buildTaskMode(ast, {}, "diff-review", context.fromTopogramPath);
714
- if (!resultOk(taskModeResult)) return printValidationFailure(taskModeResult);
715
- console.log(stableStringify(buildMaintainedDriftPayload({
716
- diffArtifact: diffResult?.artifact || null,
717
- maintainedBoundaryArtifact: maintainedBundleResult.artifact.maintained_boundary || null,
718
- verificationTargets: maintainedBundleResult.artifact.verification_targets || taskModeResult.artifact.verification_targets || null,
719
- nextAction: taskModeResult.artifact.next_action || null
720
- })));
721
- return 0;
722
- }
723
-
724
- if (queryName === "maintained-conformance") {
725
- const ast = parsePath(context.inputPath);
726
- const resolved = resolveWorkspace(ast);
727
- if (!resultOk(resolved)) return printValidationFailure(resolved);
728
- const diffResult = buildDiff(ast, context.fromTopogramPath);
729
- if (diffResult && !resultOk(diffResult)) return printValidationFailure(diffResult);
730
- const maintainedBundleResult = buildMaintainedBundle(ast);
731
- if (!resultOk(maintainedBundleResult)) return printValidationFailure(maintainedBundleResult);
732
- const taskModeResult = buildTaskMode(ast, {}, context.fromTopogramPath ? "diff-review" : "verification", context.fromTopogramPath);
733
- if (!resultOk(taskModeResult)) return printValidationFailure(taskModeResult);
734
- console.log(stableStringify(buildMaintainedConformancePayload({
735
- graph: resolved.graph,
736
- diffArtifact: artifactOrNull(diffResult),
737
- maintainedBoundaryArtifact: maintainedBundleResult.artifact.maintained_boundary || null,
738
- verificationTargets: maintainedBundleResult.artifact.verification_targets || taskModeResult.artifact.verification_targets || null,
739
- nextAction: taskModeResult.artifact.next_action || null
740
- })));
741
- return 0;
742
- }
743
-
744
- if (queryName === "domain-list") {
745
- const result = generateWorkspace(parsePath(context.inputPath), { target: "domain-list" });
746
- if (!resultOk(result)) return printValidationFailure(result);
747
- console.log(stableStringify(result.artifact));
748
- return 0;
749
- }
750
-
751
- if (queryName === "domain-coverage") {
752
- if (!context.domainId) {
753
- console.error("query domain-coverage requires --domain <id>");
754
- return 2;
755
- }
756
- const result = generateWorkspace(parsePath(context.inputPath), { target: "domain-coverage", domainId: context.domainId });
757
- if (!resultOk(result)) return printValidationFailure(result);
758
- console.log(stableStringify(result.artifact));
759
- return 0;
760
- }
761
-
762
- if (queryName === "seam-check") {
763
- const ast = parsePath(context.inputPath);
764
- const resolved = resolveWorkspace(ast);
765
- if (!resultOk(resolved)) return printValidationFailure(resolved);
766
- const diffResult = buildDiff(ast, context.fromTopogramPath);
767
- if (diffResult && !resultOk(diffResult)) return printValidationFailure(diffResult);
768
- const maintainedBundleResult = buildMaintainedBundle(ast);
769
- if (!resultOk(maintainedBundleResult)) return printValidationFailure(maintainedBundleResult);
770
- const taskModeResult = buildTaskMode(ast, {}, context.fromTopogramPath ? "diff-review" : "verification", context.fromTopogramPath);
771
- if (!resultOk(taskModeResult)) return printValidationFailure(taskModeResult);
772
- console.log(stableStringify(buildSeamCheckPayload({
773
- graph: resolved.graph,
774
- maintainedBoundaryArtifact: maintainedBundleResult.artifact.maintained_boundary || null,
775
- diffArtifact: artifactOrNull(diffResult),
776
- verificationTargets: maintainedBundleResult.artifact.verification_targets || taskModeResult.artifact.verification_targets || null,
777
- nextAction: taskModeResult.artifact.next_action || null,
778
- seamId: context.seamId
779
- })));
780
- return 0;
781
- }
782
-
783
- if (queryName === "review-boundary") {
784
- const result = buildSlice(parsePath(context.inputPath), selectors);
785
- if (!resultOk(result)) return printValidationFailure(result);
786
- console.log(stableStringify({
787
- type: "review_boundary_query",
788
- focus: result.artifact.focus,
789
- review_boundary: result.artifact.review_boundary,
790
- ownership_boundary: result.artifact.ownership_boundary,
791
- write_scope: result.artifact.write_scope || null,
792
- verification_targets: result.artifact.verification_targets || null
793
- }));
794
- return 0;
795
- }
796
-
797
- if (queryName === "write-scope") {
798
- const ast = parsePath(context.inputPath);
799
- if (context.modeId || (!hasSelectors(context) && !context.fromTopogramPath)) {
800
- const result = buildTaskMode(ast, selectors, context.modeId || "verification", context.fromTopogramPath);
801
- if (!resultOk(result)) return printValidationFailure(result);
802
- console.log(stableStringify({
803
- type: "write_scope_query",
804
- source: "context-task-mode",
805
- mode: result.artifact.mode,
806
- summary: result.artifact.summary || null,
807
- rationale: "Task mode write scope is the safest file-boundary contract for the selected operating mode.",
808
- write_scope: result.artifact.write_scope || null
809
- }));
810
- return 0;
811
- }
812
- if (context.surfaceId === "maintained-boundary") {
813
- const result = buildMaintainedBundle(ast);
814
- if (!resultOk(result)) return printValidationFailure(result);
815
- console.log(stableStringify({
816
- type: "write_scope_query",
817
- source: "maintained-boundary",
818
- summary: {
819
- maintained_file_count: (result.artifact.maintained_boundary?.maintained_files_in_scope || []).length
820
- },
821
- rationale: "Maintained-boundary write scope isolates the human-owned application files currently in scope.",
822
- write_scope: result.artifact.write_scope || null
823
- }));
824
- return 0;
825
- }
826
- const result = buildSlice(ast, selectors);
827
- if (!resultOk(result)) return printValidationFailure(result);
828
- console.log(stableStringify({
829
- type: "write_scope_query",
830
- source: "context-slice",
831
- focus: result.artifact.focus,
832
- summary: result.artifact.summary || null,
833
- rationale: "Slice write scope is the narrowest file-boundary contract attached to the selected semantic surface.",
834
- write_scope: result.artifact.write_scope || null
835
- }));
836
- return 0;
837
- }
838
-
839
- if (queryName === "verification-targets") {
840
- const ast = parsePath(context.inputPath);
841
- if (context.modeId || (!hasSelectors(context) && !context.fromTopogramPath)) {
842
- const result = buildTaskMode(ast, selectors, context.modeId || "verification", context.fromTopogramPath);
843
- if (!resultOk(result)) return printValidationFailure(result);
844
- console.log(stableStringify({
845
- type: "verification_targets_query",
846
- source: "context-task-mode",
847
- mode: result.artifact.mode,
848
- summary: result.artifact.summary || null,
849
- verification_targets: result.artifact.verification_targets || null
850
- }));
851
- return 0;
852
- }
853
- if (context.fromTopogramPath) {
854
- const resolved = resolveWorkspace(ast);
855
- if (!resultOk(resolved)) return printValidationFailure(resolved);
856
- const result = buildDiff(ast, context.fromTopogramPath);
857
- if (result && !resultOk(result)) return printValidationFailure(result);
858
- const affectedVerificationIds = (result?.artifact?.affected_verifications || []).map((/** @type {AnyRecord} */ item) => item.id);
859
- const verificationTargets = recommendedVerificationTargets(resolved.graph, affectedVerificationIds, {
860
- includeMaintainedApp: Boolean(result?.artifact?.affected_maintained_surfaces?.ownership_interpretation?.maintained_code_impact),
861
- rationale: "Diff verification targets should cover the affected semantic proof set and any maintained-app proof gates."
862
- });
863
- console.log(stableStringify({
864
- type: "verification_targets_query",
865
- source: "context-diff",
866
- summary: {
867
- baseline_root: result?.artifact?.baseline_root,
868
- affected_verification_count: affectedVerificationIds.length,
869
- maintained_code_impact: Boolean(result?.artifact?.affected_maintained_surfaces?.ownership_interpretation?.maintained_code_impact)
870
- },
871
- verification_targets: verificationTargets,
872
- affected_verifications: result?.artifact?.affected_verifications || []
873
- }));
874
- return 0;
875
- }
876
- const result = buildSlice(ast, selectors);
877
- if (!resultOk(result)) return printValidationFailure(result);
878
- console.log(stableStringify({
879
- type: "verification_targets_query",
880
- source: "context-slice",
881
- focus: result.artifact.focus,
882
- summary: result.artifact.summary || null,
883
- verification_targets: result.artifact.verification_targets || null
884
- }));
885
- return 0;
886
- }
887
-
888
- if (queryName === "widget-behavior") {
889
- const result = generateWorkspace(parsePath(normalizeTopogramPath(context.inputPath)), {
890
- target: "widget-behavior-report",
891
- projectionId: context.projectionId,
892
- componentId: selectedWidgetId
893
- });
894
- if (!resultOk(result)) return printValidationFailure(result);
895
- console.log(stableStringify(result.artifact));
896
- return (result.artifact.summary?.errors || 0) === 0 ? 0 : 1;
897
- }
898
-
899
- if (queryName === "change-plan") {
900
- const built = buildChangePlanContext(context, "modeling");
901
- if (!resultOk(built.resolved)) return printValidationFailure(built.resolved);
902
- if (!resultOk(built.taskModeResult)) return printValidationFailure(built.taskModeResult);
903
- if (built.sliceResult && !resultOk(built.sliceResult)) return printValidationFailure(built.sliceResult);
904
- if (built.diffResult && !resultOk(built.diffResult)) return printValidationFailure(built.diffResult);
905
- if (built.maintainedBundleResult && !resultOk(built.maintainedBundleResult)) return printValidationFailure(built.maintainedBundleResult);
906
- console.log(stableStringify(built.changePlan));
907
- return 0;
908
- }
909
-
910
- if (queryName === "import-plan") {
911
- const built = buildImportPlanForContext(context, "import-plan");
912
- if (!resultOk(built)) return printValidationFailure(built);
913
- console.log(stableStringify(built.importPlan));
914
- return 0;
915
- }
916
-
917
- if (queryName === "risk-summary") {
918
- if (shouldUseImportAdoptPath(context) && fs.existsSync(adoptionPlanPath(normalizeTopogramPath(context.inputPath)))) {
919
- const built = buildImportPlanForContext(context, "risk-summary");
920
- if (!resultOk(built)) return printValidationFailure(built);
921
- const risk = classifyRisk({
922
- importPlan: built.importPlan,
923
- verificationTargets: built.importPlan.verification_targets,
924
- maintainedRisk: built.importPlan.maintained_risk || null
925
- });
926
- console.log(stableStringify(buildRiskSummaryPayload({
927
- source: "import-plan",
928
- risk,
929
- nextAction: built.importPlan.next_action || null,
930
- maintainedRisk: built.importPlan.maintained_risk || null
931
- })));
932
- return 0;
933
- }
934
- const built = buildChangePlanContext(context, "modeling");
935
- if (!resultOk(built.resolved)) return printValidationFailure(built.resolved);
936
- if (!resultOk(built.taskModeResult)) return printValidationFailure(built.taskModeResult);
937
- if (built.sliceResult && !resultOk(built.sliceResult)) return printValidationFailure(built.sliceResult);
938
- if (built.diffResult && !resultOk(built.diffResult)) return printValidationFailure(built.diffResult);
939
- if (built.maintainedBundleResult && !resultOk(built.maintainedBundleResult)) return printValidationFailure(built.maintainedBundleResult);
940
- const risk = classifyRisk({
941
- reviewBoundary: built.changePlan.review_boundary,
942
- maintainedBoundary: built.changePlan.maintained_boundary,
943
- diffSummary: built.diffSummary,
944
- verificationTargets: built.changePlan.verification_targets,
945
- maintainedRisk: built.maintainedRisk
946
- });
947
- console.log(stableStringify(buildRiskSummaryPayload({
948
- source: "change-plan",
949
- risk,
950
- nextAction: built.changePlan.next_action || null,
951
- maintainedRisk: built.maintainedRisk
952
- })));
953
- return 0;
954
- }
955
-
956
- if (queryName === "canonical-writes") {
957
- if (shouldUseImportAdoptPath(context) && fs.existsSync(adoptionPlanPath(normalizeTopogramPath(context.inputPath)))) {
958
- const adoptionPlan = readJson(adoptionPlanPath(normalizeTopogramPath(context.inputPath)));
959
- console.log(stableStringify(buildCanonicalWritesPayloadForImportPlan(adoptionPlan.imported_proposal_surfaces || [])));
960
- return 0;
961
- }
962
- const result = buildTaskMode(parsePath(context.inputPath), selectors, context.modeId || "modeling", context.fromTopogramPath);
963
- if (!resultOk(result)) return printValidationFailure(result);
964
- console.log(stableStringify(buildCanonicalWritesPayloadForChangePlan(result.artifact.write_scope)));
965
- return 0;
966
- }
967
-
968
- if (queryName === "proceed-decision") {
969
- if (shouldUseImportAdoptPath(context) && fs.existsSync(adoptionPlanPath(normalizeTopogramPath(context.inputPath)))) {
970
- const built = buildImportPlanForContext(context, "proceed-decision");
971
- if (!resultOk(built)) return printValidationFailure(built);
972
- const risk = classifyRisk({
973
- importPlan: built.importPlan,
974
- verificationTargets: built.importPlan.verification_targets,
975
- maintainedRisk: built.importPlan.maintained_risk || null
976
- });
977
- const resolvedWorkflowContext = buildResolvedWorkflowContextPayload({
978
- workspace: built.topogramRoot,
979
- taskModeArtifact: built.taskModeResult.artifact,
980
- importPlan: built.importPlan,
981
- selectors: workflowPresetSelectors(built.taskModeResult.artifact, context.providerId, context.presetId, "proceed-decision")
982
- });
983
- console.log(stableStringify(proceedDecisionFromRisk(
984
- risk,
985
- built.importPlan.next_action,
986
- built.importPlan.write_scope,
987
- built.importPlan.verification_targets,
988
- built.importPlan.maintained_risk || null,
989
- built.importPlan.workflow_presets || null,
990
- resolvedWorkflowContext
991
- )));
992
- return 0;
993
- }
994
- const built = buildChangePlanContext(context, "modeling");
995
- if (!resultOk(built.resolved)) return printValidationFailure(built.resolved);
996
- if (!resultOk(built.taskModeResult)) return printValidationFailure(built.taskModeResult);
997
- if (built.sliceResult && !resultOk(built.sliceResult)) return printValidationFailure(built.sliceResult);
998
- if (built.diffResult && !resultOk(built.diffResult)) return printValidationFailure(built.diffResult);
999
- if (built.maintainedBundleResult && !resultOk(built.maintainedBundleResult)) return printValidationFailure(built.maintainedBundleResult);
1000
- const risk = classifyRisk({
1001
- reviewBoundary: built.changePlan.review_boundary,
1002
- maintainedBoundary: built.changePlan.maintained_boundary,
1003
- diffSummary: built.diffSummary,
1004
- verificationTargets: built.changePlan.verification_targets,
1005
- maintainedRisk: built.maintainedRisk
1006
- });
1007
- console.log(stableStringify(proceedDecisionFromRisk(
1008
- risk,
1009
- built.changePlan.next_action || null,
1010
- built.changePlan.write_scope || null,
1011
- built.changePlan.verification_targets || null,
1012
- built.maintainedRisk,
1013
- null,
1014
- null
1015
- )));
1016
- return 0;
1017
- }
1018
-
1019
- if (queryName === "review-packet") {
1020
- if (shouldUseImportAdoptPath(context) && fs.existsSync(adoptionPlanPath(normalizeTopogramPath(context.inputPath)))) {
1021
- const built = buildImportPlanForContext(context, "review-packet");
1022
- if (!resultOk(built)) return printValidationFailure(built);
1023
- const risk = classifyRisk({
1024
- importPlan: built.importPlan,
1025
- verificationTargets: built.importPlan.verification_targets,
1026
- maintainedRisk: built.importPlan.maintained_risk || null
1027
- });
1028
- console.log(stableStringify(buildReviewPacketPayloadForImportPlan({ importPlan: built.importPlan, risk })));
1029
- return 0;
1030
- }
1031
- const built = buildChangePlanContext(context, "modeling");
1032
- if (!resultOk(built.resolved)) return printValidationFailure(built.resolved);
1033
- if (!resultOk(built.taskModeResult)) return printValidationFailure(built.taskModeResult);
1034
- if (built.sliceResult && !resultOk(built.sliceResult)) return printValidationFailure(built.sliceResult);
1035
- if (built.diffResult && !resultOk(built.diffResult)) return printValidationFailure(built.diffResult);
1036
- if (built.maintainedBundleResult && !resultOk(built.maintainedBundleResult)) return printValidationFailure(built.maintainedBundleResult);
1037
- const risk = classifyRisk({
1038
- reviewBoundary: built.changePlan.review_boundary,
1039
- maintainedBoundary: built.changePlan.maintained_boundary,
1040
- diffSummary: built.diffSummary,
1041
- verificationTargets: built.changePlan.verification_targets,
1042
- maintainedRisk: built.maintainedRisk
1043
- });
1044
- console.log(stableStringify(buildReviewPacketPayloadForChangePlan({ changePlan: built.changePlan, risk })));
1045
- return 0;
1046
- }
1047
-
1048
- if (queryName === "next-action") {
1049
- const result = buildTaskMode(parsePath(context.inputPath), selectors, context.modeId || "import-adopt", context.fromTopogramPath);
1050
- if (!resultOk(result)) return printValidationFailure(result);
1051
- console.log(stableStringify({
1052
- type: "next_action_query",
1053
- mode: result.artifact.mode,
1054
- summary: result.artifact.summary || null,
1055
- next_action: result.artifact.next_action || null,
1056
- recommended_query_family: resolveRecommendedQueryFamily(result.artifact.next_action || null, result.artifact.mode),
1057
- immediate_artifacts: (result.artifact.preferred_context_artifacts || []).slice(0, 2),
1058
- preferred_context_artifacts: result.artifact.preferred_context_artifacts || [],
1059
- review_emphasis: result.artifact.review_emphasis || [],
1060
- write_scope: result.artifact.write_scope || null,
1061
- verification_targets: result.artifact.verification_targets || null
1062
- }));
1063
- return 0;
1064
- }
1065
-
1066
- if (queryName === "single-agent-plan") {
1067
- if (!context.modeId) {
1068
- throw new Error("query single-agent-plan requires --mode <modeling|maintained-app-edit|import-adopt|diff-review|verification>.");
1069
- }
1070
- const ast = parsePath(context.inputPath);
1071
- const result = buildTaskMode(ast, selectors, context.modeId, context.fromTopogramPath);
1072
- if (!resultOk(result)) return printValidationFailure(result);
1073
- const sliceResult = hasSelectors(context) ? buildSlice(ast, selectors) : null;
1074
- if (sliceResult && !resultOk(sliceResult)) return printValidationFailure(sliceResult);
1075
- const resolved = resolveWorkspace(ast);
1076
- if (!resultOk(resolved)) return printValidationFailure(resolved);
1077
- const generatorTargets = generatorTargetsForWorkflowContext({
1078
- graph: resolved.graph,
1079
- taskModeArtifact: result.artifact,
1080
- sliceArtifact: artifactOrNull(sliceResult)
1081
- });
1082
- const topogramRoot = normalizeTopogramPath(context.inputPath);
1083
- let importPlan = null;
1084
- if (context.modeId === "import-adopt" && fs.existsSync(adoptionPlanPath(topogramRoot))) {
1085
- const workflowPresets = buildWorkflowPresetState({
1086
- workspace: topogramRoot,
1087
- selectors: workflowPresetSelectors(result.artifact, context.providerId, context.presetId, "single-agent-plan")
1088
- });
1089
- importPlan = buildImportPlanPayload(readJson(adoptionPlanPath(topogramRoot)), result.artifact, null, workflowPresets);
1090
- }
1091
- const resolvedWorkflowContext = buildResolvedWorkflowContextPayload({
1092
- workspace: topogramRoot,
1093
- taskModeArtifact: result.artifact,
1094
- generatorTargets,
1095
- selectors: workflowPresetSelectors(result.artifact, context.providerId, context.presetId, "single-agent-plan"),
1096
- importPlan
1097
- });
1098
- console.log(stableStringify(buildSingleAgentPlanPayload({
1099
- workspace: topogramRoot,
1100
- taskModeArtifact: result.artifact,
1101
- importPlan,
1102
- resolvedWorkflowContext
1103
- })));
1104
- return 0;
1105
- }
1106
-
1107
- if (queryName === "resolved-workflow-context") {
1108
- if (!context.modeId) {
1109
- throw new Error("query resolved-workflow-context requires --mode <modeling|maintained-app-edit|import-adopt|diff-review|verification>.");
1110
- }
1111
- const topogramRoot = normalizeTopogramPath(context.inputPath);
1112
- const ast = parsePath(context.inputPath);
1113
- const taskModeResult = buildTaskMode(ast, selectors, context.modeId, context.fromTopogramPath);
1114
- if (!resultOk(taskModeResult)) return printValidationFailure(taskModeResult);
1115
- const resolved = resolveWorkspace(ast);
1116
- if (!resultOk(resolved)) return printValidationFailure(resolved);
1117
- const sliceResult = hasSelectors(context) ? buildSlice(ast, selectors) : null;
1118
- if (sliceResult && !resultOk(sliceResult)) return printValidationFailure(sliceResult);
1119
- const includeMaintainedBoundary =
1120
- context.modeId === "maintained-app-edit" ||
1121
- context.surfaceId === "maintained-boundary" ||
1122
- context.fromTopogramPath;
1123
- const maintainedBundleResult = includeMaintainedBoundary ? buildMaintainedBundle(ast) : null;
1124
- if (maintainedBundleResult && !resultOk(maintainedBundleResult)) return printValidationFailure(maintainedBundleResult);
1125
- const generatorTargets = generatorTargetsForWorkflowContext({
1126
- graph: resolved.graph,
1127
- taskModeArtifact: taskModeResult.artifact,
1128
- sliceArtifact: artifactOrNull(sliceResult),
1129
- maintainedBoundaryArtifact: maintainedBundleResult?.artifact?.maintained_boundary || null
1130
- });
1131
- let importPlan = null;
1132
- if (context.modeId === "import-adopt" && fs.existsSync(adoptionPlanPath(topogramRoot))) {
1133
- const workflowPresets = buildWorkflowPresetState({
1134
- workspace: topogramRoot,
1135
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, "resolved-workflow-context")
1136
- });
1137
- importPlan = buildImportPlanPayload(
1138
- readJson(adoptionPlanPath(topogramRoot)),
1139
- taskModeResult.artifact,
1140
- maintainedBundleResult?.artifact?.maintained_boundary || null,
1141
- workflowPresets
1142
- );
1143
- }
1144
- console.log(stableStringify(buildResolvedWorkflowContextPayload({
1145
- workspace: topogramRoot,
1146
- taskModeArtifact: taskModeResult.artifact,
1147
- importPlan,
1148
- reviewBoundary: sliceResult?.artifact?.review_boundary || null,
1149
- maintainedBoundary: maintainedBundleResult?.artifact?.maintained_boundary || null,
1150
- generatorTargets,
1151
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, "resolved-workflow-context")
1152
- })));
1153
- return 0;
1154
- }
1155
-
1156
- if (queryName === "workflow-preset-activation") {
1157
- if (!context.modeId) {
1158
- throw new Error("query workflow-preset-activation requires --mode <modeling|maintained-app-edit|import-adopt|diff-review|verification>.");
1159
- }
1160
- const topogramRoot = normalizeTopogramPath(context.inputPath);
1161
- const taskModeResult = buildTaskMode(parsePath(context.inputPath), selectors, context.modeId, context.fromTopogramPath);
1162
- if (!resultOk(taskModeResult)) return printValidationFailure(taskModeResult);
1163
- let importPlan = null;
1164
- if (context.modeId === "import-adopt" && fs.existsSync(adoptionPlanPath(topogramRoot))) {
1165
- const workflowPresets = buildWorkflowPresetState({
1166
- workspace: topogramRoot,
1167
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, "workflow-preset-activation")
1168
- });
1169
- importPlan = buildImportPlanPayload(readJson(adoptionPlanPath(topogramRoot)), taskModeResult.artifact, null, workflowPresets);
1170
- }
1171
- console.log(stableStringify(buildWorkflowPresetActivationPayload({
1172
- workspace: topogramRoot,
1173
- taskModeArtifact: taskModeResult.artifact,
1174
- importPlan,
1175
- selectors: workflowPresetSelectors(taskModeResult.artifact, context.providerId, context.presetId, "workflow-preset-activation")
1176
- })));
1177
- return 0;
1178
- }
1179
-
1180
- if (queryName === "workflow-preset-diff") {
1181
- if (!context.providerId) {
1182
- throw new Error("query workflow-preset-diff requires --provider <id>.");
1183
- }
1184
- console.log(stableStringify(buildWorkflowPresetDiffPayload({
1185
- workspace: normalizeTopogramPath(context.inputPath),
1186
- providerId: context.providerId,
1187
- presetId: context.presetId
1188
- })));
1189
- return 0;
1190
- }
1191
-
1192
- if (queryName === "workflow-preset-customization" || context.commandArgs?.workflowPresetCommand === "customize") {
1193
- if (!context.providerId || !context.presetId) {
1194
- throw new Error(`${queryName ? "query workflow-preset-customization" : "workflow-preset customize"} requires --provider <id> and --preset <id>.`);
1195
- }
1196
- const topogramRoot = normalizeTopogramPath(context.inputPath);
1197
- const payload = buildWorkflowPresetCustomizationPayload({
1198
- workspace: topogramRoot,
1199
- providerId: context.providerId,
1200
- presetId: context.presetId
1201
- });
1202
- if (queryName === "workflow-preset-customization" || !context.shouldWrite) {
1203
- console.log(stableStringify(payload));
1204
- return 0;
1205
- }
1206
- const targetPath = path.resolve(topogramRoot, context.outPath || payload.recommended_local_path);
1207
- if (fs.existsSync(targetPath)) {
1208
- throw new Error(`Refusing to overwrite existing workflow preset customization at '${targetPath}'.`);
1209
- }
1210
- fs.mkdirSync(path.dirname(targetPath), { recursive: true });
1211
- fs.writeFileSync(targetPath, `${stableStringify(payload.customization_template)}\n`);
1212
- console.log(stableStringify({
1213
- ...payload,
1214
- written: true,
1215
- written_path: targetPath
1216
- }));
1217
- return 0;
1218
- }
1219
-
1220
- if (queryName === "multi-agent-plan") {
1221
- if (context.modeId !== "import-adopt") {
1222
- throw new Error("query multi-agent-plan currently supports only --mode import-adopt.");
1223
- }
1224
- const built = buildImportAdoptAgentContext(context, "multi-agent-plan");
1225
- if (!resultOk(built)) return printValidationFailure(built);
1226
- console.log(stableStringify(built.multiAgentPlan));
1227
- return 0;
1228
- }
1229
-
1230
- if (queryName === "work-packet") {
1231
- if (context.modeId !== "import-adopt") {
1232
- throw new Error("query work-packet currently supports only --mode import-adopt.");
1233
- }
1234
- if (!context.laneId) {
1235
- throw new Error("query work-packet requires --lane <id>.");
1236
- }
1237
- const built = buildImportAdoptAgentContext(context, "work-packet");
1238
- if (!resultOk(built)) return printValidationFailure(built);
1239
- console.log(stableStringify(buildWorkPacketPayload({
1240
- workspace: built.topogramRoot,
1241
- multiAgentPlan: built.multiAgentPlan,
1242
- laneId: context.laneId
1243
- })));
1244
- return 0;
1245
- }
1246
-
1247
- if (queryName === "lane-status" || queryName === "handoff-status") {
1248
- if (context.modeId !== "import-adopt") {
1249
- throw new Error(`query ${queryName} currently supports only --mode import-adopt.`);
1250
- }
1251
- const built = buildImportAdoptAgentContext(context, queryName);
1252
- if (!resultOk(built)) return printValidationFailure(built);
1253
- const payload = queryName === "lane-status"
1254
- ? buildLaneStatusPayload({
1255
- workspace: built.topogramRoot,
1256
- multiAgentPlan: built.multiAgentPlan,
1257
- report: built.reconcileReport,
1258
- adoptionStatus: built.adoptionStatus
1259
- })
1260
- : buildHandoffStatusPayload({
1261
- workspace: built.topogramRoot,
1262
- multiAgentPlan: built.multiAgentPlan,
1263
- report: built.reconcileReport,
1264
- adoptionStatus: built.adoptionStatus
1265
- });
1266
- console.log(stableStringify(payload));
1267
- return 0;
1268
- }
1269
-
1270
- if (queryName === "auth-hints") {
1271
- const topogramRoot = normalizeTopogramPath(context.inputPath);
1272
- const reportPath = path.join(topogramRoot, "candidates", "reconcile", "report.json");
1273
- const adoptionStatusPath = path.join(topogramRoot, "candidates", "reconcile", "adoption-status.json");
1274
- if (!fs.existsSync(reportPath) || !fs.existsSync(adoptionStatusPath)) {
1275
- throw new Error(`No reconcile auth-hint artifacts found under '${path.join(topogramRoot, "candidates", "reconcile")}'. Run 'node ./src/cli.js reconcile ${topogramRoot}' first.`);
1276
- }
1277
- console.log(stableStringify(buildAuthHintsQueryPayload(readJson(reportPath), readJson(adoptionStatusPath))));
1278
- return 0;
1279
- }
1280
-
1281
- if (queryName === "auth-review-packet") {
1282
- if (!context.bundleSlug) {
1283
- throw new Error("query auth-review-packet requires --bundle <slug>.");
1284
- }
1285
- const topogramRoot = normalizeTopogramPath(context.inputPath);
1286
- const reportPath = path.join(topogramRoot, "candidates", "reconcile", "report.json");
1287
- const adoptionStatusPath = path.join(topogramRoot, "candidates", "reconcile", "adoption-status.json");
1288
- if (!fs.existsSync(reportPath) || !fs.existsSync(adoptionStatusPath)) {
1289
- throw new Error(`No reconcile auth-review artifacts found under '${path.join(topogramRoot, "candidates", "reconcile")}'. Run 'node ./src/cli.js reconcile ${topogramRoot}' first.`);
1290
- }
1291
- const reconcileReport = readJson(reportPath);
1292
- const packet = buildAuthReviewPacketPayload(reconcileReport, readJson(adoptionStatusPath), context.bundleSlug);
1293
- if (!packet) {
1294
- const knownBundles = (reconcileReport.candidate_model_bundles || []).map((/** @type {AnyRecord} */ bundle) => bundle.slug).sort();
1295
- throw new Error(`No auth review bundle '${context.bundleSlug}' found in '${path.join(topogramRoot, "candidates", "reconcile")}'. Known bundles: ${knownBundles.length ? knownBundles.join(", ") : "none"}.`);
1296
- }
1297
- console.log(stableStringify(packet));
1298
- return 0;
1299
- }
1300
-
1301
- return null;
1302
- }
3
+ export {
4
+ queryDefinitions,
5
+ buildQueryListPayload,
6
+ buildQueryShowPayload,
7
+ printQueryHelp,
8
+ printQueryDefinition,
9
+ printQueryList
10
+ } from "./query/definitions.js";
11
+ export { runQueryCommand } from "./query/runner.js";