@topogram/cli 0.3.63 → 0.3.64
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.
- package/package.json +1 -1
- package/src/adoption/plan.d.ts +6 -0
- package/src/adoption/reporting.d.ts +10 -0
- package/src/adoption/review-groups.d.ts +6 -0
- package/src/agent-brief.d.ts +3 -0
- package/src/agent-brief.js +495 -0
- package/src/agent-ops/query-builders.d.ts +26 -0
- package/src/archive/archive.d.ts +2 -0
- package/src/archive/compact.d.ts +1 -0
- package/src/archive/unarchive.d.ts +1 -0
- package/src/catalog.d.ts +10 -0
- package/src/catalog.js +62 -66
- package/src/cli/catalog-alias.d.ts +1 -0
- package/src/cli/command-parser.js +38 -0
- package/src/cli/command-parsers/core.js +102 -0
- package/src/cli/command-parsers/generator.js +39 -0
- package/src/cli/command-parsers/import.js +44 -0
- package/src/cli/command-parsers/legacy-workflow.js +21 -0
- package/src/cli/command-parsers/project.js +47 -0
- package/src/cli/command-parsers/sdlc.js +47 -0
- package/src/cli/command-parsers/shared.js +51 -0
- package/src/cli/command-parsers/template.js +48 -0
- package/src/cli/commands/agent.js +47 -0
- package/src/cli/commands/catalog.js +617 -0
- package/src/cli/commands/check.js +268 -0
- package/src/cli/commands/doctor.js +268 -0
- package/src/cli/commands/emit.js +149 -0
- package/src/cli/commands/generate.js +96 -0
- package/src/cli/commands/generator-policy.js +785 -0
- package/src/cli/commands/generator.js +443 -0
- package/src/cli/commands/import-runner.js +157 -0
- package/src/cli/commands/import.js +1734 -0
- package/src/cli/commands/inspect.js +55 -0
- package/src/cli/commands/new.js +94 -0
- package/src/cli/commands/package.js +815 -0
- package/src/cli/commands/query.js +1302 -0
- package/src/cli/commands/release-rollout.js +257 -0
- package/src/cli/commands/release-shared.js +528 -0
- package/src/cli/commands/release-status.js +429 -0
- package/src/cli/commands/release.js +107 -0
- package/src/cli/commands/sdlc.js +168 -0
- package/src/cli/commands/setup.js +76 -0
- package/src/cli/commands/source.js +291 -0
- package/src/cli/commands/template-runner.js +198 -0
- package/src/cli/commands/template.js +2145 -0
- package/src/cli/commands/trust.js +219 -0
- package/src/cli/commands/version.js +40 -0
- package/src/cli/commands/widget.js +168 -0
- package/src/cli/commands/workflow.js +63 -0
- package/src/cli/dispatcher.js +392 -0
- package/src/cli/help-dispatch.js +188 -0
- package/src/cli/help.js +296 -0
- package/src/cli/migration-guidance.js +59 -0
- package/src/cli/options.js +96 -0
- package/src/cli/output-safety.js +107 -0
- package/src/cli/path-normalization.js +29 -0
- package/src/cli.js +47 -11711
- package/src/example-implementation.d.ts +2 -0
- package/src/format.d.ts +1 -0
- package/src/generator/check.d.ts +1 -0
- package/src/generator/context/bundle.d.ts +1 -0
- package/src/generator/context/shared.d.ts +2 -0
- package/src/generator/native/parity-bundle.js +2 -1
- package/src/generator/surfaces/web/html-escape.js +22 -0
- package/src/generator/surfaces/web/react.js +10 -8
- package/src/generator/surfaces/web/sveltekit.js +7 -5
- package/src/generator/surfaces/web/vanilla.js +8 -4
- package/src/generator.d.ts +2 -0
- package/src/github-client.js +520 -0
- package/src/import/core/shared.js +20 -62
- package/src/import/extractors/api/flutter-dio.js +4 -8
- package/src/import/extractors/api/react-native-repository.js +4 -8
- package/src/import/index.d.ts +4 -0
- package/src/import/provenance.d.ts +4 -0
- package/src/new-project.js +100 -11
- package/src/npm-safety.js +79 -0
- package/src/parser.d.ts +1 -0
- package/src/path-helpers.d.ts +1 -0
- package/src/path-helpers.js +20 -0
- package/src/project-config.js +1 -0
- package/src/reconcile/docs.d.ts +8 -0
- package/src/reconcile/journeys.d.ts +1 -0
- package/src/resolver.d.ts +1 -0
- package/src/runtime-support.js +29 -0
- package/src/sdlc/adopt.d.ts +1 -0
- package/src/sdlc/check.d.ts +1 -0
- package/src/sdlc/explain.d.ts +1 -0
- package/src/sdlc/release.d.ts +1 -0
- package/src/sdlc/scaffold.d.ts +1 -0
- package/src/sdlc/transition.d.ts +1 -0
- package/src/text-helpers.d.ts +6 -0
- package/src/text-helpers.js +245 -0
- package/src/topogram-config.js +306 -0
- package/src/validator.d.ts +2 -0
- package/src/workflows/adoption/index.js +26 -0
- package/src/workflows/docs-generate.js +262 -0
- package/src/workflows/docs-scan.js +703 -0
- package/src/workflows/docs.js +15 -0
- package/src/workflows/import-app/api.js +799 -0
- package/src/workflows/import-app/db.js +538 -0
- package/src/workflows/import-app/index.js +30 -0
- package/src/workflows/import-app/shared.js +218 -0
- package/src/workflows/import-app/ui.js +443 -0
- package/src/workflows/import-app/workflow.js +159 -0
- package/src/workflows/reconcile/adoption-plan.js +742 -0
- package/src/workflows/reconcile/auth.js +692 -0
- package/src/workflows/reconcile/bundle-core.js +600 -0
- package/src/workflows/reconcile/bundle-shared.js +75 -0
- package/src/workflows/reconcile/candidate-model.js +477 -0
- package/src/workflows/reconcile/canonical-surface.js +264 -0
- package/src/workflows/reconcile/gap-report.js +333 -0
- package/src/workflows/reconcile/ids.js +6 -0
- package/src/workflows/reconcile/impacts.js +625 -0
- package/src/workflows/reconcile/index.js +7 -0
- package/src/workflows/reconcile/renderers.js +461 -0
- package/src/workflows/reconcile/summary.js +90 -0
- package/src/workflows/reconcile/workflow.js +309 -0
- package/src/workflows/shared.js +189 -0
- package/src/workflows/types.d.ts +93 -0
- package/src/workflows.d.ts +1 -0
- package/src/workflows.js +10 -7652
|
@@ -0,0 +1,1302 @@
|
|
|
1
|
+
// @ts-check
|
|
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
|
+
}
|