@topogram/cli 0.3.62 → 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,625 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { stableStringify } from "../../format.js";
|
|
3
|
+
import { docDirForKind } from "../docs.js";
|
|
4
|
+
import { dashedTopogramId } from "./ids.js";
|
|
5
|
+
import {
|
|
6
|
+
buildAuthClaimReviewGuidance,
|
|
7
|
+
buildAuthOwnershipReviewGuidance,
|
|
8
|
+
buildAuthPermissionReviewGuidance,
|
|
9
|
+
describeAuthClaimWhyInferred,
|
|
10
|
+
describeAuthOwnershipWhyInferred,
|
|
11
|
+
describeAuthPermissionWhyInferred,
|
|
12
|
+
formatAuthClaimHintInline,
|
|
13
|
+
formatAuthOwnershipHintInline,
|
|
14
|
+
formatAuthPermissionHintInline
|
|
15
|
+
} from "./auth.js";
|
|
16
|
+
|
|
17
|
+
/** @param {any[]} fields @returns {any} */
|
|
18
|
+
export function shapeFieldSignature(fields) {
|
|
19
|
+
return [...new Set((fields || []).filter(Boolean))].sort().join("|");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param {ResolvedGraph} graph @returns {any} */
|
|
23
|
+
export function buildCanonicalShapeIndex(graph) {
|
|
24
|
+
const bySignature = new Map();
|
|
25
|
+
for (const shape of graph?.byKind.shape || []) {
|
|
26
|
+
const fields = (shape.projectedFields || shape.fields || []).map((/** @type {any} */ field) => field.name).filter(Boolean);
|
|
27
|
+
const signature = shapeFieldSignature(fields);
|
|
28
|
+
if (!signature) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (!bySignature.has(signature)) {
|
|
32
|
+
bySignature.set(signature, []);
|
|
33
|
+
}
|
|
34
|
+
bySignature.get(signature).push(shape.id);
|
|
35
|
+
}
|
|
36
|
+
return bySignature;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @param {WorkflowRecord} capability @returns {any} */
|
|
40
|
+
export function capabilityEntityTargets(capability) {
|
|
41
|
+
return [
|
|
42
|
+
...(capability.creates || []),
|
|
43
|
+
...(capability.updates || []),
|
|
44
|
+
...(capability.deletes || []),
|
|
45
|
+
...(capability.reads || [])
|
|
46
|
+
]
|
|
47
|
+
.map((/** @type {any} */ ref) => ref?.id || ref?.target?.id || null)
|
|
48
|
+
.filter((/** @type {any} */ id) => typeof id === "string" && id.startsWith("entity_"));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @param {WorkflowRecord} projection @returns {any} */
|
|
52
|
+
export function projectionKindForImpact(projection) {
|
|
53
|
+
if ((projection.http || []).length > 0 || projection.type === "api_contract") {
|
|
54
|
+
return "api";
|
|
55
|
+
}
|
|
56
|
+
if (
|
|
57
|
+
(projection.uiRoutes || []).length > 0 ||
|
|
58
|
+
(projection.uiWeb || []).length > 0 ||
|
|
59
|
+
(projection.uiIos || []).length > 0 ||
|
|
60
|
+
projection.type === "web_surface" ||
|
|
61
|
+
projection.type === "ios_surface"
|
|
62
|
+
) {
|
|
63
|
+
return "ui";
|
|
64
|
+
}
|
|
65
|
+
if ((projection.dbTables || []).length > 0) {
|
|
66
|
+
return "db";
|
|
67
|
+
}
|
|
68
|
+
return "other";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @param {ResolvedGraph} graph @returns {any} */
|
|
72
|
+
export function buildProjectionEntityIndex(graph) {
|
|
73
|
+
const projections = graph?.byKind.projection || [];
|
|
74
|
+
const capabilities = new Map((graph?.byKind.capability || []).map((/** @type {any} */ capability) => [capability.id, capability]));
|
|
75
|
+
const projectionsById = new Map(projections.map((/** @type {any} */ projection) => [projection.id, projection]));
|
|
76
|
+
const memo = new Map();
|
|
77
|
+
|
|
78
|
+
/** @param {string} projectionId @param {any} stack @returns {any} */
|
|
79
|
+
function collectEntities(projectionId, stack = new Set()) {
|
|
80
|
+
if (memo.has(projectionId)) {
|
|
81
|
+
return memo.get(projectionId);
|
|
82
|
+
}
|
|
83
|
+
if (stack.has(projectionId)) {
|
|
84
|
+
return new Set();
|
|
85
|
+
}
|
|
86
|
+
stack.add(projectionId);
|
|
87
|
+
const projection = projectionsById.get(projectionId);
|
|
88
|
+
const entities = new Set();
|
|
89
|
+
for (const realized of projection?.realizes || []) {
|
|
90
|
+
const realizedKind = realized?.target?.kind || realized?.kind || null;
|
|
91
|
+
const realizedId = realized?.target?.id || realized?.id || null;
|
|
92
|
+
if (realizedKind === "capability") {
|
|
93
|
+
const capability = capabilities.get(realizedId);
|
|
94
|
+
for (const entityId of capabilityEntityTargets(capability || {})) {
|
|
95
|
+
entities.add(entityId);
|
|
96
|
+
}
|
|
97
|
+
} else if (realizedKind === "projection") {
|
|
98
|
+
for (const entityId of collectEntities(realizedId, stack)) {
|
|
99
|
+
entities.add(entityId);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
memo.set(projectionId, entities);
|
|
104
|
+
stack.delete(projectionId);
|
|
105
|
+
return entities;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return projections.map((/** @type {any} */ projection) => ({
|
|
109
|
+
id: projection.id,
|
|
110
|
+
projection_type: projection.type || null,
|
|
111
|
+
kind: projectionKindForImpact(projection),
|
|
112
|
+
realizes: (projection.realizes || []).map((/** @type {any} */ entry) => entry.id),
|
|
113
|
+
entityIds: [...collectEntities(projection.id)].sort()
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @param {CandidateBundle} bundle @param {any} canonicalShapeIndex @returns {any} */
|
|
118
|
+
export function buildBundleAdoptionPlan(bundle, canonicalShapeIndex) {
|
|
119
|
+
/** @type {any[]} */
|
|
120
|
+
const steps = [];
|
|
121
|
+
for (const entry of bundle.actors) {
|
|
122
|
+
steps.push({
|
|
123
|
+
action: "promote_actor",
|
|
124
|
+
item: entry.id_hint,
|
|
125
|
+
target: null,
|
|
126
|
+
confidence: entry.confidence || "low",
|
|
127
|
+
inference_summary: entry.inference_summary || null,
|
|
128
|
+
related_docs: entry.related_docs || [],
|
|
129
|
+
related_capabilities: entry.related_capabilities || [],
|
|
130
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/actors/${entry.id_hint}.tg`,
|
|
131
|
+
canonical_rel_path: `actors/${dashedTopogramId(entry.id_hint)}.tg`
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
for (const entry of bundle.roles) {
|
|
135
|
+
steps.push({
|
|
136
|
+
action: "promote_role",
|
|
137
|
+
item: entry.id_hint,
|
|
138
|
+
target: null,
|
|
139
|
+
confidence: entry.confidence || "low",
|
|
140
|
+
inference_summary: entry.inference_summary || null,
|
|
141
|
+
related_docs: entry.related_docs || [],
|
|
142
|
+
related_capabilities: entry.related_capabilities || [],
|
|
143
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/roles/${entry.id_hint}.tg`,
|
|
144
|
+
canonical_rel_path: `roles/${dashedTopogramId(entry.id_hint)}.tg`
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (bundle.mergeHints?.canonicalEntityTarget) {
|
|
148
|
+
steps.push({
|
|
149
|
+
action: "merge_bundle_into_existing_entity",
|
|
150
|
+
item: bundle.slug,
|
|
151
|
+
target: bundle.mergeHints.canonicalEntityTarget
|
|
152
|
+
});
|
|
153
|
+
} else if (bundle.entities.length > 0) {
|
|
154
|
+
for (const entry of bundle.entities) {
|
|
155
|
+
steps.push({
|
|
156
|
+
action: "promote_entity",
|
|
157
|
+
item: entry.id_hint,
|
|
158
|
+
target: null
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const entry of bundle.enums) {
|
|
163
|
+
steps.push({
|
|
164
|
+
action: "promote_enum",
|
|
165
|
+
item: entry.id_hint,
|
|
166
|
+
target: bundle.mergeHints?.canonicalEntityTarget || null
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
for (const entry of bundle.capabilities) {
|
|
170
|
+
steps.push({
|
|
171
|
+
action: bundle.mergeHints?.canonicalEntityTarget ? "merge_capability_into_existing_entity" : "promote_capability",
|
|
172
|
+
item: entry.id_hint,
|
|
173
|
+
target: bundle.mergeHints?.canonicalEntityTarget || null
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
for (const entry of bundle.shapes) {
|
|
177
|
+
const signature = shapeFieldSignature(entry.fields || []);
|
|
178
|
+
const duplicateTargets = canonicalShapeIndex.get(signature) || [];
|
|
179
|
+
if (duplicateTargets.length > 0) {
|
|
180
|
+
steps.push({
|
|
181
|
+
action: "skip_duplicate_shape",
|
|
182
|
+
item: entry.id,
|
|
183
|
+
target: duplicateTargets[0]
|
|
184
|
+
});
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
steps.push({
|
|
188
|
+
action: "promote_shape",
|
|
189
|
+
item: entry.id,
|
|
190
|
+
target: bundle.mergeHints?.canonicalEntityTarget || null
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
for (const entry of bundle.docs) {
|
|
194
|
+
if (entry.existing_canonical) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
steps.push({
|
|
198
|
+
action: entry.kind === "workflow" ? "promote_workflow_doc" : "promote_doc",
|
|
199
|
+
item: entry.id,
|
|
200
|
+
target: null,
|
|
201
|
+
doc_kind: entry.kind,
|
|
202
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/${docDirForKind(entry.kind)}/${entry.id}.md`,
|
|
203
|
+
canonical_rel_path: `docs/${docDirForKind(entry.kind)}/${entry.id}.md`
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
for (const entry of bundle.workflows) {
|
|
207
|
+
steps.push({
|
|
208
|
+
action: "promote_workflow_decision",
|
|
209
|
+
item: `dec_${entry.id_hint.replace(/^workflow_/, "")}`,
|
|
210
|
+
target: null,
|
|
211
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/decisions/dec_${entry.id_hint.replace(/^workflow_/, "")}.tg`,
|
|
212
|
+
canonical_rel_path: `decisions/decision-${dashedTopogramId(entry.id_hint.replace(/^workflow_/, ""))}.tg`
|
|
213
|
+
});
|
|
214
|
+
steps.push({
|
|
215
|
+
action: "promote_workflow_doc",
|
|
216
|
+
item: entry.id_hint,
|
|
217
|
+
target: null,
|
|
218
|
+
doc_kind: "workflow",
|
|
219
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/workflows/${entry.id_hint}.md`,
|
|
220
|
+
canonical_rel_path: `docs/workflows/${entry.id_hint}.md`
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
for (const entry of bundle.verifications || []) {
|
|
224
|
+
steps.push({
|
|
225
|
+
action: "promote_verification",
|
|
226
|
+
item: entry.id_hint,
|
|
227
|
+
target: null,
|
|
228
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/verifications/${entry.id_hint}.tg`,
|
|
229
|
+
canonical_rel_path: `verifications/${dashedTopogramId(entry.id_hint)}.tg`
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
for (const entry of bundle.widgets || []) {
|
|
233
|
+
steps.push({
|
|
234
|
+
action: "promote_widget",
|
|
235
|
+
item: entry.id_hint,
|
|
236
|
+
target: null,
|
|
237
|
+
confidence: entry.confidence || "low",
|
|
238
|
+
inference_summary: entry.inference_summary || null,
|
|
239
|
+
related_capabilities: [entry.data_source].filter(Boolean),
|
|
240
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/widgets/${entry.id_hint}.tg`,
|
|
241
|
+
canonical_rel_path: `widgets/${dashedTopogramId(entry.id_hint)}.tg`
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
for (const screen of bundle.screens) {
|
|
245
|
+
steps.push({
|
|
246
|
+
action: "promote_ui_report",
|
|
247
|
+
item: `ui_${screen.id_hint}`,
|
|
248
|
+
target: null,
|
|
249
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/docs/reports/ui-${screen.id_hint}.md`,
|
|
250
|
+
canonical_rel_path: `docs/reports/ui-${screen.id_hint}.md`
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
for (const patch of bundle.projectionPatches || []) {
|
|
254
|
+
for (const hint of patch.missing_auth_permissions || []) {
|
|
255
|
+
steps.push({
|
|
256
|
+
action: "apply_projection_permission_patch",
|
|
257
|
+
item: `projection_permission_patch:${patch.projection_id}:${hint.projection_surface}:${hint.permission}`,
|
|
258
|
+
target: patch.projection_id,
|
|
259
|
+
projection_kind: patch.kind,
|
|
260
|
+
projection_surface: hint.projection_surface,
|
|
261
|
+
permission: hint.permission,
|
|
262
|
+
confidence: hint.confidence || "low",
|
|
263
|
+
inference_summary: hint.why_inferred || hint.explanation || null,
|
|
264
|
+
related_capabilities: hint.related_capabilities || [],
|
|
265
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
|
|
266
|
+
canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
for (const hint of patch.missing_auth_claims || []) {
|
|
270
|
+
steps.push({
|
|
271
|
+
action: "apply_projection_auth_patch",
|
|
272
|
+
item: `projection_auth_patch:${patch.projection_id}:${hint.projection_surface}:${hint.claim}`,
|
|
273
|
+
target: patch.projection_id,
|
|
274
|
+
projection_kind: patch.kind,
|
|
275
|
+
projection_surface: hint.projection_surface,
|
|
276
|
+
claim: hint.claim,
|
|
277
|
+
claim_value: hint.claim_value,
|
|
278
|
+
confidence: hint.confidence || "low",
|
|
279
|
+
inference_summary: hint.why_inferred || hint.explanation || null,
|
|
280
|
+
related_capabilities: hint.related_capabilities || [],
|
|
281
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
|
|
282
|
+
canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
for (const hint of patch.missing_auth_ownerships || []) {
|
|
286
|
+
steps.push({
|
|
287
|
+
action: "apply_projection_ownership_patch",
|
|
288
|
+
item: `projection_ownership_patch:${patch.projection_id}:${hint.ownership_field}`,
|
|
289
|
+
target: patch.projection_id,
|
|
290
|
+
projection_kind: patch.kind,
|
|
291
|
+
projection_surface: "authorization",
|
|
292
|
+
ownership: hint.ownership,
|
|
293
|
+
ownership_field: hint.ownership_field,
|
|
294
|
+
confidence: hint.confidence || "low",
|
|
295
|
+
inference_summary: hint.why_inferred || hint.explanation || null,
|
|
296
|
+
related_capabilities: hint.related_capabilities || [],
|
|
297
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
|
|
298
|
+
canonical_rel_path: `projections/${dashedTopogramId(patch.projection_id)}.tg`
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return steps;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** @param {CandidateBundle} bundle @param {any} projectionIndex @returns {any} */
|
|
306
|
+
export function buildProjectionImpacts(bundle, projectionIndex) {
|
|
307
|
+
const bundleEntityIds = new Set([
|
|
308
|
+
bundle.mergeHints?.canonicalEntityTarget || null,
|
|
309
|
+
...bundle.entities.map((/** @type {any} */ entry) => entry.id_hint)
|
|
310
|
+
].filter(Boolean));
|
|
311
|
+
if (bundle.capabilities.length === 0 || bundleEntityIds.size === 0) {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
return projectionIndex
|
|
315
|
+
.filter((/** @type {any} */ projection) => projection.kind === "api" || projection.kind === "ui")
|
|
316
|
+
.filter((/** @type {any} */ projection) => projection.entityIds.some((/** @type {any} */ entityId) => bundleEntityIds.has(entityId)))
|
|
317
|
+
.map((/** @type {any} */ projection) => {
|
|
318
|
+
const missingCapabilities = bundle.capabilities
|
|
319
|
+
.map((/** @type {any} */ entry) => entry.id_hint)
|
|
320
|
+
.filter((/** @type {any} */ id) => !projection.realizes.includes(id));
|
|
321
|
+
if (missingCapabilities.length === 0) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
projection_id: projection.id,
|
|
326
|
+
projection_type: projection.type,
|
|
327
|
+
kind: projection.kind,
|
|
328
|
+
missing_capabilities: missingCapabilities,
|
|
329
|
+
reason: `Projection ${projection.id} already covers the same entity surface but does not realize these imported capabilities.`
|
|
330
|
+
};
|
|
331
|
+
})
|
|
332
|
+
.filter(Boolean)
|
|
333
|
+
.sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** @param {CandidateBundle} bundle @param {ResolvedGraph} graph @returns {any} */
|
|
337
|
+
export function buildUiImpacts(bundle, graph) {
|
|
338
|
+
if ((bundle.screens || []).length === 0) {
|
|
339
|
+
return [];
|
|
340
|
+
}
|
|
341
|
+
const uiProjections = (graph?.byKind.projection || []).filter((/** @type {any} */ projection) => ["ui_contract", "web_surface"].includes(projection.type));
|
|
342
|
+
const bundleScreenIds = bundle.screens.map((/** @type {any} */ screen) => screen.id_hint);
|
|
343
|
+
return uiProjections
|
|
344
|
+
.map((/** @type {any} */ projection) => {
|
|
345
|
+
const projectionScreens = new Set((projection.uiScreens || []).map((/** @type {any} */ screen) => screen.id));
|
|
346
|
+
const missingScreens = bundleScreenIds.filter((/** @type {any} */ screenId) => !projectionScreens.has(screenId));
|
|
347
|
+
if (missingScreens.length === 0) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
projection_id: projection.id,
|
|
352
|
+
kind: "ui",
|
|
353
|
+
projection_type: projection.type,
|
|
354
|
+
missing_screens: missingScreens,
|
|
355
|
+
reason: `UI projection ${projection.id} does not currently represent these imported screens.`
|
|
356
|
+
};
|
|
357
|
+
})
|
|
358
|
+
.filter(Boolean)
|
|
359
|
+
.sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** @param {CandidateBundle} bundle @param {ResolvedGraph} graph @returns {any} */
|
|
363
|
+
export function buildWorkflowImpacts(bundle, graph) {
|
|
364
|
+
if ((bundle.workflows || []).length === 0) {
|
|
365
|
+
return [];
|
|
366
|
+
}
|
|
367
|
+
const canonicalWorkflowDocs = new Set((graph?.docs || []).filter((/** @type {any} */ doc) => doc.kind === "workflow").map((/** @type {any} */ doc) => doc.id));
|
|
368
|
+
const impacted = bundle.workflows
|
|
369
|
+
.map((/** @type {any} */ workflow) => workflow.id_hint)
|
|
370
|
+
.filter((/** @type {any} */ id) => !canonicalWorkflowDocs.has(id));
|
|
371
|
+
if (impacted.length === 0) {
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
return [
|
|
375
|
+
{
|
|
376
|
+
review_group_id: `workflow_review:${bundle.slug}`,
|
|
377
|
+
kind: "workflow",
|
|
378
|
+
items: impacted,
|
|
379
|
+
reason: `Workflow semantics for ${bundle.slug} need canonical review before promotion.`
|
|
380
|
+
}
|
|
381
|
+
];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** @param {CandidateBundle} bundle @returns {any} */
|
|
385
|
+
export function buildProjectionPatchCandidates(bundle) {
|
|
386
|
+
const capabilityById = new Map((bundle.capabilities || []).map((/** @type {any} */ entry) => [entry.id_hint, entry]));
|
|
387
|
+
const routesByScreen = new Map();
|
|
388
|
+
for (const route of bundle.uiRoutes || []) {
|
|
389
|
+
const screenId = route.screen_id || route.id_hint;
|
|
390
|
+
if (!routesByScreen.has(screenId)) {
|
|
391
|
+
routesByScreen.set(screenId, []);
|
|
392
|
+
}
|
|
393
|
+
routesByScreen.get(screenId).push(route);
|
|
394
|
+
}
|
|
395
|
+
const actionsByScreen = new Map();
|
|
396
|
+
for (const action of bundle.uiActions || []) {
|
|
397
|
+
const screenId = action.screen_id || action.id_hint;
|
|
398
|
+
if (!actionsByScreen.has(screenId)) {
|
|
399
|
+
actionsByScreen.set(screenId, []);
|
|
400
|
+
}
|
|
401
|
+
actionsByScreen.get(screenId).push(action);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** @type {any[]} */
|
|
405
|
+
|
|
406
|
+
const patches = [];
|
|
407
|
+
for (const impact of bundle.projectionImpacts || []) {
|
|
408
|
+
const missingRealizes = [...(impact.missing_capabilities || [])];
|
|
409
|
+
const missingHttp = impact.kind === "api"
|
|
410
|
+
? missingRealizes
|
|
411
|
+
.map((/** @type {any} */ capabilityId) => capabilityById.get(capabilityId))
|
|
412
|
+
.filter(Boolean)
|
|
413
|
+
.map((/** @type {any} */ entry) => ({
|
|
414
|
+
capability_id: entry.id_hint,
|
|
415
|
+
method: entry.endpoint?.method || "GET",
|
|
416
|
+
path: entry.endpoint?.path || "/"
|
|
417
|
+
}))
|
|
418
|
+
: [];
|
|
419
|
+
patches.push({
|
|
420
|
+
projection_id: impact.projection_id,
|
|
421
|
+
kind: impact.kind,
|
|
422
|
+
projection_type: impact.projection_type,
|
|
423
|
+
reason: impact.reason,
|
|
424
|
+
missing_realizes: missingRealizes,
|
|
425
|
+
missing_http: missingHttp,
|
|
426
|
+
missing_screens: [],
|
|
427
|
+
missing_routes: [],
|
|
428
|
+
missing_actions: []
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
for (const impact of bundle.uiImpacts || []) {
|
|
433
|
+
const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
|
|
434
|
+
const missingScreens = [...(impact.missing_screens || [])];
|
|
435
|
+
const missingRoutes = missingScreens.flatMap((/** @type {any} */ screenId) => routesByScreen.get(screenId) || []).map((/** @type {any} */ route) => ({
|
|
436
|
+
screen_id: route.screen_id,
|
|
437
|
+
path: route.path
|
|
438
|
+
}));
|
|
439
|
+
const missingActions = missingScreens.flatMap((/** @type {any} */ screenId) => actionsByScreen.get(screenId) || []).map((/** @type {any} */ action) => ({
|
|
440
|
+
screen_id: action.screen_id,
|
|
441
|
+
capability_hint: action.capability_hint
|
|
442
|
+
}));
|
|
443
|
+
if (existing) {
|
|
444
|
+
existing.missing_screens = [...new Set([...(existing.missing_screens || []), ...missingScreens])];
|
|
445
|
+
existing.missing_routes = [...(existing.missing_routes || []), ...missingRoutes];
|
|
446
|
+
existing.missing_actions = [...(existing.missing_actions || []), ...missingActions];
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
patches.push({
|
|
450
|
+
projection_id: impact.projection_id,
|
|
451
|
+
kind: impact.kind,
|
|
452
|
+
projection_type: impact.projection_type,
|
|
453
|
+
reason: impact.reason,
|
|
454
|
+
missing_realizes: [],
|
|
455
|
+
missing_http: [],
|
|
456
|
+
missing_screens: missingScreens,
|
|
457
|
+
missing_routes: missingRoutes,
|
|
458
|
+
missing_actions: missingActions
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
for (const hint of bundle.authClaimHints || []) {
|
|
463
|
+
for (const impact of bundle.projectionImpacts || []) {
|
|
464
|
+
const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
|
|
465
|
+
if (relatedCapabilities.length === 0) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const projectionSurface = impact.kind === "ui" ? "visibility_rules" : "authorization";
|
|
469
|
+
const entry = {
|
|
470
|
+
claim: hint.claim,
|
|
471
|
+
claim_value: hint.claim_value,
|
|
472
|
+
confidence: hint.confidence,
|
|
473
|
+
review_required: true,
|
|
474
|
+
explanation: hint.explanation,
|
|
475
|
+
why_inferred: hint.why_inferred || describeAuthClaimWhyInferred(hint),
|
|
476
|
+
review_guidance: hint.review_guidance || buildAuthClaimReviewGuidance(hint),
|
|
477
|
+
related_capabilities: relatedCapabilities,
|
|
478
|
+
projection_surface: projectionSurface,
|
|
479
|
+
evidence: hint.evidence || {}
|
|
480
|
+
};
|
|
481
|
+
const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
|
|
482
|
+
if (existing) {
|
|
483
|
+
existing.missing_auth_claims = existing.missing_auth_claims || [];
|
|
484
|
+
const duplicate = existing.missing_auth_claims.some((/** @type {any} */ candidate) =>
|
|
485
|
+
candidate.claim === entry.claim &&
|
|
486
|
+
String(candidate.claim_value || "") === String(entry.claim_value || "") &&
|
|
487
|
+
candidate.projection_surface === entry.projection_surface &&
|
|
488
|
+
stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
|
|
489
|
+
);
|
|
490
|
+
if (!duplicate) {
|
|
491
|
+
existing.missing_auth_claims.push(entry);
|
|
492
|
+
}
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
patches.push({
|
|
496
|
+
projection_id: impact.projection_id,
|
|
497
|
+
kind: impact.kind,
|
|
498
|
+
projection_type: impact.projection_type,
|
|
499
|
+
reason: `Projection ${impact.projection_id} likely needs claim-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
|
|
500
|
+
missing_realizes: relatedCapabilities,
|
|
501
|
+
missing_http: [],
|
|
502
|
+
missing_screens: [],
|
|
503
|
+
missing_routes: [],
|
|
504
|
+
missing_actions: [],
|
|
505
|
+
missing_auth_claims: [entry]
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
for (const hint of bundle.authPermissionHints || []) {
|
|
511
|
+
for (const impact of bundle.projectionImpacts || []) {
|
|
512
|
+
const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
|
|
513
|
+
if (relatedCapabilities.length === 0) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const projectionSurface = impact.kind === "ui" ? "visibility_rules" : "authorization";
|
|
517
|
+
const entry = {
|
|
518
|
+
permission: hint.permission,
|
|
519
|
+
confidence: hint.confidence,
|
|
520
|
+
review_required: true,
|
|
521
|
+
explanation: hint.explanation,
|
|
522
|
+
why_inferred: hint.why_inferred || describeAuthPermissionWhyInferred(hint),
|
|
523
|
+
review_guidance: hint.review_guidance || buildAuthPermissionReviewGuidance(hint),
|
|
524
|
+
related_capabilities: relatedCapabilities,
|
|
525
|
+
projection_surface: projectionSurface,
|
|
526
|
+
evidence: hint.evidence || {}
|
|
527
|
+
};
|
|
528
|
+
const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
|
|
529
|
+
if (existing) {
|
|
530
|
+
existing.missing_auth_permissions = existing.missing_auth_permissions || [];
|
|
531
|
+
const duplicate = existing.missing_auth_permissions.some((/** @type {any} */ candidate) =>
|
|
532
|
+
candidate.permission === entry.permission &&
|
|
533
|
+
candidate.projection_surface === entry.projection_surface &&
|
|
534
|
+
stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
|
|
535
|
+
);
|
|
536
|
+
if (!duplicate) {
|
|
537
|
+
existing.missing_auth_permissions.push(entry);
|
|
538
|
+
}
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
patches.push({
|
|
542
|
+
projection_id: impact.projection_id,
|
|
543
|
+
kind: impact.kind,
|
|
544
|
+
projection_type: impact.projection_type,
|
|
545
|
+
reason: `Projection ${impact.projection_id} likely needs permission-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
|
|
546
|
+
missing_realizes: relatedCapabilities,
|
|
547
|
+
missing_http: [],
|
|
548
|
+
missing_screens: [],
|
|
549
|
+
missing_routes: [],
|
|
550
|
+
missing_actions: [],
|
|
551
|
+
missing_auth_permissions: [entry]
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
for (const hint of bundle.authOwnershipHints || []) {
|
|
557
|
+
for (const impact of bundle.projectionImpacts || []) {
|
|
558
|
+
if (impact.kind !== "api") {
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
const relatedCapabilities = (impact.missing_capabilities || []).filter((/** @type {any} */ capabilityId) => (hint.related_capabilities || []).includes(capabilityId));
|
|
562
|
+
if (relatedCapabilities.length === 0) {
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
const entry = {
|
|
566
|
+
ownership: hint.ownership,
|
|
567
|
+
ownership_field: hint.ownership_field,
|
|
568
|
+
confidence: hint.confidence,
|
|
569
|
+
review_required: true,
|
|
570
|
+
explanation: hint.explanation,
|
|
571
|
+
why_inferred: hint.why_inferred || describeAuthOwnershipWhyInferred(hint),
|
|
572
|
+
review_guidance: hint.review_guidance || buildAuthOwnershipReviewGuidance(hint),
|
|
573
|
+
related_capabilities: relatedCapabilities,
|
|
574
|
+
related_entities: hint.related_entities || [],
|
|
575
|
+
evidence: hint.evidence || {}
|
|
576
|
+
};
|
|
577
|
+
const existing = patches.find((/** @type {any} */ patch) => patch.projection_id === impact.projection_id);
|
|
578
|
+
if (existing) {
|
|
579
|
+
existing.missing_auth_ownerships = existing.missing_auth_ownerships || [];
|
|
580
|
+
const duplicate = existing.missing_auth_ownerships.some((/** @type {any} */ candidate) =>
|
|
581
|
+
candidate.ownership === entry.ownership &&
|
|
582
|
+
candidate.ownership_field === entry.ownership_field &&
|
|
583
|
+
stableStringify(candidate.related_capabilities || []) === stableStringify(entry.related_capabilities || [])
|
|
584
|
+
);
|
|
585
|
+
if (!duplicate) {
|
|
586
|
+
existing.missing_auth_ownerships.push(entry);
|
|
587
|
+
}
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
patches.push({
|
|
591
|
+
projection_id: impact.projection_id,
|
|
592
|
+
kind: impact.kind,
|
|
593
|
+
projection_type: impact.projection_type,
|
|
594
|
+
reason: `Projection ${impact.projection_id} likely needs ownership-based auth rules for the imported ${bundle.label.toLowerCase()} surface.`,
|
|
595
|
+
missing_realizes: relatedCapabilities,
|
|
596
|
+
missing_http: [],
|
|
597
|
+
missing_screens: [],
|
|
598
|
+
missing_routes: [],
|
|
599
|
+
missing_actions: [],
|
|
600
|
+
missing_auth_ownerships: [entry]
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return patches
|
|
606
|
+
.map((/** @type {any} */ patch) => ({
|
|
607
|
+
...patch,
|
|
608
|
+
missing_auth_permissions: (patch.missing_auth_permissions || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
|
|
609
|
+
(a.projection_surface || "").localeCompare(b.projection_surface || "") ||
|
|
610
|
+
(a.permission || "").localeCompare(b.permission || "") ||
|
|
611
|
+
stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
|
|
612
|
+
),
|
|
613
|
+
missing_auth_claims: (patch.missing_auth_claims || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
|
|
614
|
+
(a.projection_surface || "").localeCompare(b.projection_surface || "") ||
|
|
615
|
+
(a.claim || "").localeCompare(b.claim || "") ||
|
|
616
|
+
stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
|
|
617
|
+
),
|
|
618
|
+
missing_auth_ownerships: (patch.missing_auth_ownerships || []).sort((/** @type {any} */ a, /** @type {any} */ b) =>
|
|
619
|
+
(a.ownership_field || "").localeCompare(b.ownership_field || "") ||
|
|
620
|
+
stableStringify(a.related_capabilities || []).localeCompare(stableStringify(b.related_capabilities || []))
|
|
621
|
+
),
|
|
622
|
+
patch_rel_path: `projection-patches/${patch.projection_id}.md`
|
|
623
|
+
}))
|
|
624
|
+
.sort((/** @type {any} */ a, /** @type {any} */ b) => a.projection_id.localeCompare(b.projection_id));
|
|
625
|
+
}
|