@topogram/cli 0.3.64 → 0.3.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/adoption/plan/index.js +703 -0
- package/src/adoption/plan.js +12 -703
- package/src/agent-ops/query-builders/auth.js +375 -0
- package/src/agent-ops/query-builders/change-risk/change-plan.js +123 -0
- package/src/agent-ops/query-builders/change-risk/import-plan.js +49 -0
- package/src/agent-ops/query-builders/change-risk/maintained.js +286 -0
- package/src/agent-ops/query-builders/change-risk/review-packets.js +123 -0
- package/src/agent-ops/query-builders/change-risk/risk.js +189 -0
- package/src/agent-ops/query-builders/change-risk.js +25 -0
- package/src/agent-ops/query-builders/common.js +149 -0
- package/src/agent-ops/query-builders/maintained-risk.js +539 -0
- package/src/agent-ops/query-builders/maintained-shared.js +120 -0
- package/src/agent-ops/query-builders/multi-agent.js +547 -0
- package/src/agent-ops/query-builders/projection-impacts.js +514 -0
- package/src/agent-ops/query-builders/work-packets.js +417 -0
- package/src/agent-ops/query-builders/workflow-context-shared.js +300 -0
- package/src/agent-ops/query-builders/workflow-context.js +398 -0
- package/src/agent-ops/query-builders/workflow-presets-core.js +676 -0
- package/src/agent-ops/query-builders/workflow-presets.js +341 -0
- package/src/agent-ops/query-builders.d.ts +26 -26
- package/src/agent-ops/query-builders.js +42 -5021
- package/src/catalog/constants.js +10 -0
- package/src/catalog/copy.js +60 -0
- package/src/catalog/diagnostics.js +15 -0
- package/src/catalog/entries.js +42 -0
- package/src/catalog/files.js +67 -0
- package/src/catalog/provenance.js +122 -0
- package/src/catalog/source.js +150 -0
- package/src/catalog/validation.js +252 -0
- package/src/catalog.d.ts +2 -0
- package/src/catalog.js +18 -746
- package/src/cli/commands/catalog/check.js +31 -0
- package/src/cli/commands/catalog/copy.js +59 -0
- package/src/cli/commands/catalog/doctor.js +248 -0
- package/src/cli/commands/catalog/help.js +21 -0
- package/src/cli/commands/catalog/list.js +52 -0
- package/src/cli/commands/catalog/runner.js +92 -0
- package/src/cli/commands/catalog/shared.js +17 -0
- package/src/cli/commands/catalog/show.js +134 -0
- package/src/cli/commands/catalog.js +30 -615
- package/src/cli/commands/generator-policy/package-info.js +162 -0
- package/src/cli/commands/generator-policy/payloads.js +372 -0
- package/src/cli/commands/generator-policy/printers.js +159 -0
- package/src/cli/commands/generator-policy/runner.js +81 -0
- package/src/cli/commands/generator-policy/shared.js +39 -0
- package/src/cli/commands/generator-policy.js +15 -783
- package/src/cli/commands/import/adopt.js +170 -0
- package/src/cli/commands/import/check.js +91 -0
- package/src/cli/commands/import/diff.js +84 -0
- package/src/cli/commands/import/help.js +47 -0
- package/src/cli/commands/import/paths.js +277 -0
- package/src/cli/commands/import/plan.js +284 -0
- package/src/cli/commands/import/refresh.js +470 -0
- package/src/cli/commands/import/status-history.js +196 -0
- package/src/cli/commands/import/workspace.js +230 -0
- package/src/cli/commands/import.js +33 -1732
- package/src/cli/commands/package/constants.js +17 -0
- package/src/cli/commands/package/doctor.js +240 -0
- package/src/cli/commands/package/help.js +27 -0
- package/src/cli/commands/package/lockfile.js +135 -0
- package/src/cli/commands/package/npm.js +97 -0
- package/src/cli/commands/package/reporting.js +35 -0
- package/src/cli/commands/package/runner.js +33 -0
- package/src/cli/commands/package/shared.js +9 -0
- package/src/cli/commands/package/update-cli.js +252 -0
- package/src/cli/commands/package/versions.js +35 -0
- package/src/cli/commands/package.js +29 -813
- package/src/cli/commands/query/change-plan.js +68 -0
- package/src/cli/commands/query/definitions.js +202 -0
- package/src/cli/commands/query/import-adopt.js +121 -0
- package/src/cli/commands/query/runner/artifacts.js +102 -0
- package/src/cli/commands/query/runner/boundaries.js +211 -0
- package/src/cli/commands/query/runner/change.js +182 -0
- package/src/cli/commands/query/runner/import-adopt.js +111 -0
- package/src/cli/commands/query/runner/index.js +31 -0
- package/src/cli/commands/query/runner/output.js +12 -0
- package/src/cli/commands/query/runner/workflow.js +241 -0
- package/src/cli/commands/query/runner.js +3 -0
- package/src/cli/commands/query/workflow-context.js +5 -0
- package/src/cli/commands/query/workspace.js +274 -0
- package/src/cli/commands/query.js +9 -1300
- package/src/cli/commands/template/baseline.js +100 -0
- package/src/cli/commands/template/check.js +466 -0
- package/src/cli/commands/template/constants.js +8 -0
- package/src/cli/commands/template/diagnostics.js +26 -0
- package/src/cli/commands/template/help.js +28 -0
- package/src/cli/commands/template/lifecycle.js +404 -0
- package/src/cli/commands/template/list-show.js +287 -0
- package/src/cli/commands/template/policy.js +422 -0
- package/src/cli/commands/template/shared.js +127 -0
- package/src/cli/commands/template/updates.js +352 -0
- package/src/cli/commands/template.js +41 -2143
- package/src/generator/api/contracts.js +497 -0
- package/src/generator/api/metadata.js +221 -0
- package/src/generator/api/openapi.js +559 -0
- package/src/generator/api/schema.js +124 -0
- package/src/generator/api/types.d.ts +98 -0
- package/src/generator/api.js +3 -1195
- package/src/generator/context/shared/domain-sdlc.js +282 -0
- package/src/generator/context/shared/maintained-boundary.js +665 -0
- package/src/generator/context/shared/metrics.js +85 -0
- package/src/generator/context/shared/primitives.js +64 -0
- package/src/generator/context/shared/relationships.js +453 -0
- package/src/generator/context/shared/summaries.js +263 -0
- package/src/generator/context/shared/types.d.ts +207 -0
- package/src/generator/context/shared.d.ts +42 -0
- package/src/generator/context/shared.js +80 -1390
- package/src/generator/context/slice/core.js +397 -0
- package/src/generator/context/slice/sdlc.js +417 -0
- package/src/generator/context/slice/ui-packets.js +183 -0
- package/src/generator/context/slice.js +2 -859
- package/src/generator/registry/index.js +507 -0
- package/src/generator/registry.js +18 -504
- package/src/generator/runtime/environment/index.js +666 -0
- package/src/generator/runtime/environment.js +4 -666
- package/src/generator/runtime/runtime-check/index.js +554 -0
- package/src/generator/runtime/runtime-check.js +4 -554
- package/src/generator/runtime/shared/index.js +572 -0
- package/src/generator/runtime/shared.js +19 -570
- package/src/generator/shared.d.ts +2 -0
- package/src/generator/surfaces/shared.d.ts +3 -0
- package/src/generator/widget-conformance/behavior-report.js +258 -0
- package/src/generator/widget-conformance/checks.js +371 -0
- package/src/generator/widget-conformance/projection-context.js +200 -0
- package/src/generator/widget-conformance/report.js +166 -0
- package/src/generator/widget-conformance/types.d.ts +121 -0
- package/src/generator/widget-conformance.js +3 -824
- package/src/import/core/context.d.ts +3 -0
- package/src/import/core/contracts.d.ts +1 -0
- package/src/import/core/registry.d.ts +4 -0
- package/src/import/core/runner/candidates.js +217 -0
- package/src/import/core/runner/options.js +22 -0
- package/src/import/core/runner/reports.js +50 -0
- package/src/import/core/runner/run.js +79 -0
- package/src/import/core/runner/tracks.js +150 -0
- package/src/import/core/runner/ui-drafts.js +337 -0
- package/src/import/core/runner.js +3 -698
- package/src/import/core/shared/api-routes.js +221 -0
- package/src/import/core/shared/candidates.js +97 -0
- package/src/import/core/shared/files.js +177 -0
- package/src/import/core/shared/next-app.js +389 -0
- package/src/import/core/shared/types.d.ts +51 -0
- package/src/import/core/shared/ui-routes.js +230 -0
- package/src/import/core/shared.js +60 -861
- package/src/new-project/constants.js +128 -0
- package/src/new-project/create.js +83 -0
- package/src/new-project/json.js +28 -0
- package/src/new-project/metadata.js +96 -0
- package/src/new-project/package-spec.js +161 -0
- package/src/new-project/project-files.js +348 -0
- package/src/new-project/template-policy.js +269 -0
- package/src/new-project/template-resolution.js +368 -0
- package/src/new-project/template-snapshots.js +430 -0
- package/src/new-project/template-updates.js +512 -0
- package/src/new-project/types.d.ts +83 -0
- package/src/new-project.js +6 -2277
- package/src/parser.d.ts +87 -1
- package/src/parser.js +118 -0
- package/src/policy/review-boundaries.d.ts +15 -0
- package/src/project-config/index.js +564 -0
- package/src/project-config.js +19 -561
- package/src/resolver/enrich/acceptance-criterion.js +2 -0
- package/src/resolver/enrich/bug.js +2 -0
- package/src/resolver/enrich/pitch.js +2 -0
- package/src/resolver/enrich/requirement.js +2 -0
- package/src/resolver/enrich/task.js +2 -0
- package/src/resolver/index.js +19 -2089
- package/src/resolver/normalize.js +384 -1
- package/src/resolver/plans.js +168 -0
- package/src/resolver/projections-api.js +494 -0
- package/src/resolver/projections-db.js +133 -0
- package/src/resolver/projections-ui.js +317 -0
- package/src/resolver/shapes.js +251 -0
- package/src/resolver/shared.js +278 -0
- package/src/resolver/widgets.js +132 -0
- package/src/template-trust/constants.js +62 -0
- package/src/template-trust/content.js +258 -0
- package/src/template-trust/diff.js +92 -0
- package/src/template-trust/policy.js +61 -0
- package/src/template-trust/record.js +90 -0
- package/src/template-trust/status.js +182 -0
- package/src/template-trust.js +24 -687
- package/src/text-helpers.d.ts +1 -0
- package/src/topogram-types.d.ts +69 -0
- package/src/validator/common.js +488 -0
- package/src/validator/data-model.js +237 -0
- package/src/validator/docs.js +167 -0
- package/src/validator/expressions.js +146 -1
- package/src/validator/index.d.ts +23 -0
- package/src/validator/index.js +32 -3585
- package/src/validator/kinds.d.ts +41 -0
- package/src/validator/kinds.js +2 -0
- package/src/validator/model-helpers.js +46 -0
- package/src/validator/per-kind/acceptance-criterion.js +5 -0
- package/src/validator/per-kind/bug.js +6 -0
- package/src/validator/per-kind/domain.js +15 -2
- package/src/validator/per-kind/pitch.js +7 -0
- package/src/validator/per-kind/requirement.js +5 -0
- package/src/validator/per-kind/task.js +7 -0
- package/src/validator/per-kind/widget.js +14 -0
- package/src/validator/projections/api-http-async.js +410 -0
- package/src/validator/projections/api-http-authz.js +88 -0
- package/src/validator/projections/api-http-core.js +205 -0
- package/src/validator/projections/api-http-policies.js +339 -0
- package/src/validator/projections/api-http-responses.js +233 -0
- package/src/validator/projections/api-http.js +44 -0
- package/src/validator/projections/db.js +353 -0
- package/src/validator/projections/generator-defaults.js +45 -0
- package/src/validator/projections/helpers.js +87 -0
- package/src/validator/projections/ui-helpers.js +214 -0
- package/src/validator/projections/ui-navigation.js +344 -0
- package/src/validator/projections/ui-structure.js +364 -0
- package/src/validator/projections/ui-widgets.js +493 -0
- package/src/validator/projections/ui.js +46 -0
- package/src/validator/registry.js +48 -1
- package/src/validator/utils.d.ts +20 -0
- package/src/validator/utils.js +115 -12
- package/src/widget-behavior.d.ts +1 -0
- package/src/workflows/import-app/api/collect.js +221 -0
- package/src/workflows/import-app/api/openapi.js +257 -0
- package/src/workflows/import-app/api/routes.js +327 -0
- package/src/workflows/import-app/api/sources.js +22 -0
- package/src/workflows/import-app/api.js +2 -797
- package/src/workflows/reconcile/adoption-plan/build.js +208 -0
- package/src/workflows/reconcile/adoption-plan/dependencies.js +75 -0
- package/src/workflows/reconcile/adoption-plan/outputs.js +143 -0
- package/src/workflows/reconcile/adoption-plan/paths.js +58 -0
- package/src/workflows/reconcile/adoption-plan/projection-patches.js +177 -0
- package/src/workflows/reconcile/adoption-plan/reasons.js +107 -0
- package/src/workflows/reconcile/adoption-plan.js +30 -740
- package/src/workflows/reconcile/auth/closures.js +115 -0
- package/src/workflows/reconcile/auth/formatters.js +142 -0
- package/src/workflows/reconcile/auth/inference.js +330 -0
- package/src/workflows/reconcile/auth/roles.js +122 -0
- package/src/workflows/reconcile/auth.js +35 -690
- package/src/workflows/reconcile/bundle-core/index.js +600 -0
- package/src/workflows/reconcile/bundle-core.js +12 -598
- package/src/workflows/reconcile/canonical-surface.js +1 -1
- package/src/workflows/reconcile/impacts/adoption-plan.js +192 -0
- package/src/workflows/reconcile/impacts/indexes.js +101 -0
- package/src/workflows/reconcile/impacts/patches.js +252 -0
- package/src/workflows/reconcile/impacts/reports.js +80 -0
- package/src/workflows/reconcile/impacts.js +14 -623
- package/src/workspace-docs.d.ts +29 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { adoptionItemKey } from "../../../adoption/plan.js";
|
|
4
|
+
import { confidenceRank } from "../../docs.js";
|
|
5
|
+
import {
|
|
6
|
+
adoptionStatusForStep,
|
|
7
|
+
blockingDependenciesForProjectionImpacts,
|
|
8
|
+
blockingDependenciesForUiImpacts,
|
|
9
|
+
blockingDependenciesForWorkflowImpacts,
|
|
10
|
+
projectionImpactsForAdoptionItem
|
|
11
|
+
} from "./dependencies.js";
|
|
12
|
+
import {
|
|
13
|
+
canonicalDisplayPathForItem,
|
|
14
|
+
canonicalRelativePathForItem,
|
|
15
|
+
candidateSourcePathForItem
|
|
16
|
+
} from "./paths.js";
|
|
17
|
+
import {
|
|
18
|
+
reasonForAdoptionItem,
|
|
19
|
+
recommendationForAdoptionItem
|
|
20
|
+
} from "./reasons.js";
|
|
21
|
+
|
|
22
|
+
/** @param {CandidateBundle[]} bundles @returns {any} */
|
|
23
|
+
export function buildAdoptionPlan(bundles) {
|
|
24
|
+
/** @type {any[]} */
|
|
25
|
+
const items = [];
|
|
26
|
+
for (const bundle of bundles) {
|
|
27
|
+
for (const step of bundle.adoptionPlan || []) {
|
|
28
|
+
const itemKind =
|
|
29
|
+
step.action === "merge_bundle_into_existing_entity" ? "bundle" :
|
|
30
|
+
step.action === "apply_projection_permission_patch" ? "projection_permission_patch" :
|
|
31
|
+
step.action === "apply_projection_auth_patch" ? "projection_auth_patch" :
|
|
32
|
+
step.action === "apply_projection_ownership_patch" ? "projection_ownership_patch" :
|
|
33
|
+
step.action.includes("doc") ? "doc" :
|
|
34
|
+
step.action.includes("decision") ? "decision" :
|
|
35
|
+
step.action.includes("verification") ? "verification" :
|
|
36
|
+
step.action.includes("widget") ? "widget" :
|
|
37
|
+
step.action.includes("ui_") ? "ui" :
|
|
38
|
+
step.action.includes("actor") ? "actor" :
|
|
39
|
+
step.action.includes("role") ? "role" :
|
|
40
|
+
step.action.includes("enum") ? "enum" :
|
|
41
|
+
step.action.includes("shape") ? "shape" :
|
|
42
|
+
step.action.includes("capability") ? "capability" :
|
|
43
|
+
step.action.includes("entity") ? "entity" :
|
|
44
|
+
"bundle";
|
|
45
|
+
if (itemKind === "bundle") {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const projectionImpacts = projectionImpactsForAdoptionItem(bundle, step);
|
|
49
|
+
const directProjectionBlockingDependencies =
|
|
50
|
+
(step.action === "apply_projection_permission_patch" || step.action === "apply_projection_auth_patch" || step.action === "apply_projection_ownership_patch") && step.target
|
|
51
|
+
? blockingDependenciesForProjectionImpacts([
|
|
52
|
+
{
|
|
53
|
+
projection_id: step.target,
|
|
54
|
+
kind: step.projection_kind || "api",
|
|
55
|
+
projection_type: null,
|
|
56
|
+
reason: `Projection ${step.target} auth rules need explicit review before promotion.`
|
|
57
|
+
}
|
|
58
|
+
])
|
|
59
|
+
: [];
|
|
60
|
+
const uiImpacts = step.action.includes("ui_") ? bundle.uiImpacts || [] : [];
|
|
61
|
+
const workflowImpacts = step.action.includes("workflow") ? bundle.workflowImpacts || [] : [];
|
|
62
|
+
const blockingDependencies = [
|
|
63
|
+
...blockingDependenciesForProjectionImpacts(projectionImpacts),
|
|
64
|
+
...directProjectionBlockingDependencies,
|
|
65
|
+
...blockingDependenciesForUiImpacts(uiImpacts),
|
|
66
|
+
...blockingDependenciesForWorkflowImpacts(workflowImpacts)
|
|
67
|
+
];
|
|
68
|
+
items.push({
|
|
69
|
+
bundle: bundle.slug,
|
|
70
|
+
item: step.item,
|
|
71
|
+
kind: itemKind,
|
|
72
|
+
track:
|
|
73
|
+
step.action.includes("workflow") ? "workflows" :
|
|
74
|
+
step.action.includes("verification") ? "verification" :
|
|
75
|
+
step.action.includes("ui_") ? "ui" :
|
|
76
|
+
step.action === "apply_projection_permission_patch" ? "projection" :
|
|
77
|
+
step.action === "apply_projection_auth_patch" ? "projection" :
|
|
78
|
+
step.action === "apply_projection_ownership_patch" ? "projection" :
|
|
79
|
+
step.action.includes("doc") ? "docs" :
|
|
80
|
+
itemKind,
|
|
81
|
+
suggested_action: step.action,
|
|
82
|
+
target: step.target || null,
|
|
83
|
+
confidence: step.confidence || null,
|
|
84
|
+
inference_summary: step.inference_summary || null,
|
|
85
|
+
related_docs: step.related_docs || [],
|
|
86
|
+
related_capabilities: step.related_capabilities || [],
|
|
87
|
+
permission: step.permission || null,
|
|
88
|
+
claim: step.claim || null,
|
|
89
|
+
claim_value: Object.prototype.hasOwnProperty.call(step, "claim_value") ? step.claim_value : null,
|
|
90
|
+
ownership: step.ownership || null,
|
|
91
|
+
ownership_field: step.ownership_field || null,
|
|
92
|
+
projection_surface: step.projection_surface || null,
|
|
93
|
+
status: adoptionStatusForStep(step, projectionImpacts, uiImpacts, workflowImpacts),
|
|
94
|
+
source_path: step.source_path || candidateSourcePathForItem(bundle, itemKind, step.item),
|
|
95
|
+
canonical_path:
|
|
96
|
+
step.action === "skip_duplicate_shape"
|
|
97
|
+
? (step.target ? canonicalDisplayPathForItem("shape", step.target) : null)
|
|
98
|
+
: (step.canonical_rel_path ? `topogram/${step.canonical_rel_path}` : canonicalDisplayPathForItem(itemKind, step.item)),
|
|
99
|
+
canonical_rel_path: step.canonical_rel_path || canonicalRelativePathForItem(itemKind, step.item),
|
|
100
|
+
reason: reasonForAdoptionItem(step),
|
|
101
|
+
recommendation: recommendationForAdoptionItem(step),
|
|
102
|
+
projection_impacts: projectionImpacts,
|
|
103
|
+
ui_impacts: uiImpacts,
|
|
104
|
+
workflow_impacts: workflowImpacts,
|
|
105
|
+
blocking_dependencies: blockingDependencies
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
for (const patch of bundle.projectionPatches || []) {
|
|
109
|
+
items.push({
|
|
110
|
+
bundle: bundle.slug,
|
|
111
|
+
item: `projection_patch:${patch.projection_id}`,
|
|
112
|
+
kind: "projection_patch",
|
|
113
|
+
track: "projection",
|
|
114
|
+
suggested_action: "review_projection_patch",
|
|
115
|
+
target: patch.projection_id,
|
|
116
|
+
status: "needs_projection_review",
|
|
117
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
|
|
118
|
+
canonical_path: null,
|
|
119
|
+
canonical_rel_path: null,
|
|
120
|
+
reason: patch.reason || `Projection ${patch.projection_id} needs additive review.`,
|
|
121
|
+
projection_impacts: [
|
|
122
|
+
{
|
|
123
|
+
projection_id: patch.projection_id,
|
|
124
|
+
kind: patch.kind,
|
|
125
|
+
projection_type: patch.projection_type,
|
|
126
|
+
missing_capabilities: patch.missing_realizes || []
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
ui_impacts: (patch.missing_screens || []).length > 0 ? [
|
|
130
|
+
{
|
|
131
|
+
projection_id: patch.projection_id,
|
|
132
|
+
kind: patch.kind,
|
|
133
|
+
projection_type: patch.projection_type,
|
|
134
|
+
missing_screens: patch.missing_screens || []
|
|
135
|
+
}
|
|
136
|
+
] : [],
|
|
137
|
+
workflow_impacts: [],
|
|
138
|
+
blocking_dependencies: blockingDependenciesForProjectionImpacts([
|
|
139
|
+
{
|
|
140
|
+
projection_id: patch.projection_id,
|
|
141
|
+
kind: patch.kind,
|
|
142
|
+
projection_type: patch.projection_type,
|
|
143
|
+
reason: patch.reason || `Projection ${patch.projection_id} needs additive review.`
|
|
144
|
+
}
|
|
145
|
+
])
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
for (const patch of bundle.docLinkSuggestions || []) {
|
|
149
|
+
items.push({
|
|
150
|
+
bundle: bundle.slug,
|
|
151
|
+
item: `doc_link_patch:${patch.doc_id}`,
|
|
152
|
+
kind: "doc_link_patch",
|
|
153
|
+
track: "docs",
|
|
154
|
+
suggested_action: "apply_doc_link_patch",
|
|
155
|
+
target: patch.doc_id,
|
|
156
|
+
status: "pending",
|
|
157
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
|
|
158
|
+
canonical_path: patch.canonical_rel_path ? `topogram/${patch.canonical_rel_path}` : null,
|
|
159
|
+
canonical_rel_path: patch.canonical_rel_path || null,
|
|
160
|
+
reason: `Apply suggested related actor/role links to \`${patch.doc_id}\`.`,
|
|
161
|
+
recommendation: recommendationForAdoptionItem({ action: "apply_doc_link_patch", target: patch.doc_id }),
|
|
162
|
+
related_docs: [patch.doc_id],
|
|
163
|
+
related_actors: patch.add_related_actors || [],
|
|
164
|
+
related_roles: patch.add_related_roles || [],
|
|
165
|
+
related_capabilities: patch.add_related_capabilities || [],
|
|
166
|
+
related_rules: patch.add_related_rules || [],
|
|
167
|
+
related_workflows: patch.add_related_workflows || [],
|
|
168
|
+
projection_impacts: [],
|
|
169
|
+
ui_impacts: [],
|
|
170
|
+
workflow_impacts: [],
|
|
171
|
+
blocking_dependencies: []
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
for (const patch of bundle.docMetadataPatches || []) {
|
|
175
|
+
items.push({
|
|
176
|
+
bundle: bundle.slug,
|
|
177
|
+
item: `doc_metadata_patch:${patch.doc_id}`,
|
|
178
|
+
kind: "doc_metadata_patch",
|
|
179
|
+
track: "docs",
|
|
180
|
+
suggested_action: "apply_doc_metadata_patch",
|
|
181
|
+
target: patch.doc_id,
|
|
182
|
+
status: "pending",
|
|
183
|
+
confidence: patch.imported_confidence || "low",
|
|
184
|
+
source_path: `candidates/reconcile/model/bundles/${bundle.slug}/${patch.patch_rel_path}`,
|
|
185
|
+
canonical_path: patch.canonical_rel_path ? `topogram/${patch.canonical_rel_path}` : null,
|
|
186
|
+
canonical_rel_path: patch.canonical_rel_path || null,
|
|
187
|
+
reason: `Apply suggested safe metadata updates to \`${patch.doc_id}\`.`,
|
|
188
|
+
recommendation: recommendationForAdoptionItem({ action: "apply_doc_metadata_patch", target: patch.doc_id }),
|
|
189
|
+
related_docs: [patch.doc_id],
|
|
190
|
+
summary: patch.summary || null,
|
|
191
|
+
success_outcome: patch.success_outcome || null,
|
|
192
|
+
actors: patch.actors || [],
|
|
193
|
+
projection_impacts: [],
|
|
194
|
+
ui_impacts: [],
|
|
195
|
+
workflow_impacts: [],
|
|
196
|
+
blocking_dependencies: []
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return items.sort((/** @type {any} */ a, /** @type {any} */ b) =>
|
|
201
|
+
a.bundle.localeCompare(b.bundle) ||
|
|
202
|
+
confidenceRank(b.confidence || "low") - confidenceRank(a.confidence || "low") ||
|
|
203
|
+
a.kind.localeCompare(b.kind) ||
|
|
204
|
+
a.item.localeCompare(b.item)
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const ADOPT_SELECTORS = new Set(["from-plan", "actors", "roles", "enums", "shapes", "entities", "capabilities", "widgets", "docs", "journeys", "workflows", "verification", "ui"]);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** @param {WorkflowRecord} step @param {any[]} projectionImpacts @param {any[]} uiImpacts @param {any[]} workflowImpacts @returns {any} */
|
|
4
|
+
export function adoptionStatusForStep(step, projectionImpacts = [], uiImpacts = [], workflowImpacts = []) {
|
|
5
|
+
if (step.action === "skip_duplicate_shape") {
|
|
6
|
+
return "skipped";
|
|
7
|
+
}
|
|
8
|
+
if (step.action === "apply_projection_permission_patch") {
|
|
9
|
+
return "needs_projection_review";
|
|
10
|
+
}
|
|
11
|
+
if (step.action === "apply_projection_auth_patch") {
|
|
12
|
+
return "needs_projection_review";
|
|
13
|
+
}
|
|
14
|
+
if (step.action === "apply_projection_ownership_patch") {
|
|
15
|
+
return "needs_projection_review";
|
|
16
|
+
}
|
|
17
|
+
if (step.action.includes("capability") && projectionImpacts.length > 0) {
|
|
18
|
+
return "needs_projection_review";
|
|
19
|
+
}
|
|
20
|
+
if (step.action.includes("ui_") && uiImpacts.length > 0) {
|
|
21
|
+
return "needs_ui_review";
|
|
22
|
+
}
|
|
23
|
+
if (step.action.includes("workflow") && workflowImpacts.length > 0) {
|
|
24
|
+
return "needs_workflow_review";
|
|
25
|
+
}
|
|
26
|
+
return "pending";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @param {CandidateBundle} bundle @param {WorkflowRecord} step @returns {any} */
|
|
30
|
+
export function projectionImpactsForAdoptionItem(bundle, step) {
|
|
31
|
+
if (!step.action.includes("capability")) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return (bundle.projectionImpacts || [])
|
|
35
|
+
.filter((/** @type {any} */ impact) => (impact.missing_capabilities || []).includes(step.item))
|
|
36
|
+
.map((/** @type {any} */ impact) => ({
|
|
37
|
+
projection_id: impact.projection_id,
|
|
38
|
+
kind: impact.kind,
|
|
39
|
+
projection_type: impact.projection_type,
|
|
40
|
+
reason: impact.reason
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @param {any[]} projectionImpacts @returns {any} */
|
|
45
|
+
export function blockingDependenciesForProjectionImpacts(projectionImpacts) {
|
|
46
|
+
return projectionImpacts.map((/** @type {any} */ impact) => ({
|
|
47
|
+
type: "projection_review",
|
|
48
|
+
id: `projection_review:${impact.projection_id}`,
|
|
49
|
+
projection_id: impact.projection_id,
|
|
50
|
+
kind: impact.kind,
|
|
51
|
+
projection_type: impact.projection_type,
|
|
52
|
+
reason: impact.reason
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @param {any[]} uiImpacts @returns {any} */
|
|
57
|
+
export function blockingDependenciesForUiImpacts(uiImpacts) {
|
|
58
|
+
return uiImpacts.map((/** @type {any} */ impact) => ({
|
|
59
|
+
type: "ui_review",
|
|
60
|
+
id: `ui_review:${impact.projection_id}`,
|
|
61
|
+
projection_id: impact.projection_id,
|
|
62
|
+
kind: impact.kind,
|
|
63
|
+
projection_type: impact.projection_type,
|
|
64
|
+
reason: impact.reason
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @param {any[]} workflowImpacts @returns {any} */
|
|
69
|
+
export function blockingDependenciesForWorkflowImpacts(workflowImpacts) {
|
|
70
|
+
return workflowImpacts.map((/** @type {any} */ impact) => ({
|
|
71
|
+
type: "workflow_review",
|
|
72
|
+
id: impact.review_group_id,
|
|
73
|
+
reason: impact.reason
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { adoptionItemKey } from "../../../adoption/plan.js";
|
|
7
|
+
import {
|
|
8
|
+
applyDocLinkPatchToMarkdown as applyDocLinkPatchToMarkdownReconcile,
|
|
9
|
+
applyDocMetadataPatchToMarkdown as applyDocMetadataPatchToMarkdownReconcile
|
|
10
|
+
} from "../../../reconcile/docs.js";
|
|
11
|
+
import { readJsonIfExists, readTextIfExists } from "../../shared.js";
|
|
12
|
+
import { canonicalRelativePathForItem } from "./paths.js";
|
|
13
|
+
import { applyProjectionAuthPatchToTopogram } from "./projection-patches.js";
|
|
14
|
+
|
|
15
|
+
/** @param {WorkspacePaths} paths @returns {any} */
|
|
16
|
+
export function readAdoptionPlan(paths) {
|
|
17
|
+
return readJsonIfExists(path.join(paths.topogramRoot, "candidates", "reconcile", "adoption-plan.json"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @param {WorkspacePaths} paths @param {any[]} candidateFiles @param {any[]} planItems @param {any[]} selectedItems @param {WorkflowOptions} options @returns {any} */
|
|
21
|
+
export function buildCanonicalAdoptionOutputs(paths, candidateFiles, planItems, selectedItems, options = {}) {
|
|
22
|
+
const refreshAdopted = Boolean(options.refreshAdopted);
|
|
23
|
+
/** @type {WorkflowFiles} */
|
|
24
|
+
/** @type {WorkflowFiles} */
|
|
25
|
+
const files = {};
|
|
26
|
+
/** @type {any[]} */
|
|
27
|
+
const refreshedFiles = [];
|
|
28
|
+
const selectedSet = new Set(selectedItems);
|
|
29
|
+
const itemMap = new Map(planItems.map((/** @type {any} */ item) => [adoptionItemKey(item), item]));
|
|
30
|
+
const capabilityBundleSet = new Set(
|
|
31
|
+
[...selectedSet]
|
|
32
|
+
.map((/** @type {any} */ key) => itemMap.get(key))
|
|
33
|
+
.filter((/** @type {any} */ item) => item?.kind === "capability")
|
|
34
|
+
.map((/** @type {any} */ item) => item.bundle)
|
|
35
|
+
);
|
|
36
|
+
for (const item of planItems) {
|
|
37
|
+
if (item.kind === "shape" && item.status !== "skipped" && capabilityBundleSet.has(item.bundle)) {
|
|
38
|
+
selectedSet.add(adoptionItemKey(item));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const item of planItems) {
|
|
42
|
+
if (!selectedSet.has(adoptionItemKey(item))) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (item.suggested_action === "skip_duplicate_shape") {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const relativeCanonicalPath = item.canonical_rel_path || canonicalRelativePathForItem(item.kind, item.item);
|
|
49
|
+
if (!relativeCanonicalPath) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const canonicalPath = path.join(paths.topogramRoot, relativeCanonicalPath);
|
|
53
|
+
if (item.suggested_action === "apply_doc_link_patch") {
|
|
54
|
+
const baseContents = files[relativeCanonicalPath] || (fs.existsSync(canonicalPath) ? fs.readFileSync(canonicalPath, "utf8") : null);
|
|
55
|
+
if (!baseContents) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const updatedContents = applyDocLinkPatchToMarkdownReconcile(baseContents, item);
|
|
59
|
+
if (!updatedContents || updatedContents === baseContents) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
files[relativeCanonicalPath] = updatedContents;
|
|
63
|
+
refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (item.suggested_action === "apply_doc_metadata_patch") {
|
|
67
|
+
const baseContents = files[relativeCanonicalPath] || (fs.existsSync(canonicalPath) ? fs.readFileSync(canonicalPath, "utf8") : null);
|
|
68
|
+
if (!baseContents) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const updatedContents = applyDocMetadataPatchToMarkdownReconcile(baseContents, item);
|
|
72
|
+
if (!updatedContents || updatedContents === baseContents) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
files[relativeCanonicalPath] = updatedContents;
|
|
76
|
+
refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (item.suggested_action === "apply_projection_permission_patch" || item.suggested_action === "apply_projection_auth_patch" || item.suggested_action === "apply_projection_ownership_patch") {
|
|
80
|
+
const baseContents = files[relativeCanonicalPath] || (fs.existsSync(canonicalPath) ? fs.readFileSync(canonicalPath, "utf8") : null);
|
|
81
|
+
if (!baseContents) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const updatedContents = applyProjectionAuthPatchToTopogram(baseContents, item);
|
|
85
|
+
if (!updatedContents || updatedContents === baseContents) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
files[relativeCanonicalPath] = updatedContents;
|
|
89
|
+
refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (fs.existsSync(canonicalPath)) {
|
|
93
|
+
if (!refreshAdopted) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const existingContents = fs.readFileSync(canonicalPath, "utf8");
|
|
97
|
+
const machineManagedImported =
|
|
98
|
+
existingContents.startsWith("# imported ") ||
|
|
99
|
+
/\bsource_of_truth:\s*imported\b/.test(existingContents);
|
|
100
|
+
if (!machineManagedImported) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const candidateContents =
|
|
105
|
+
candidateFiles[item.source_path] ||
|
|
106
|
+
(item.source_path ? readTextIfExists(path.join(paths.topogramRoot, item.source_path)) : null);
|
|
107
|
+
if (!candidateContents) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
files[relativeCanonicalPath] = candidateContents;
|
|
111
|
+
if (fs.existsSync(canonicalPath)) {
|
|
112
|
+
refreshedFiles.push(relativeCanonicalPath.replaceAll(path.sep, "/"));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { files, refreshedFiles: [...new Set(refreshedFiles)].sort() };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @param {any[]} planItems @param {any[]} selectedItems @param {any[]} writtenCanonicalFiles @param {string} selector @returns {any} */
|
|
119
|
+
export function buildPromotedCanonicalItems(planItems, selectedItems, writtenCanonicalFiles, selector) {
|
|
120
|
+
const itemMap = new Map((planItems || []).map((/** @type {any} */ item) => [adoptionItemKey(item), item]));
|
|
121
|
+
const writtenSet = new Set((writtenCanonicalFiles || []).map((/** @type {any} */ item) => String(item).replaceAll(path.sep, "/")));
|
|
122
|
+
return [...new Set(selectedItems || [])]
|
|
123
|
+
.map((/** @type {any} */ key) => itemMap.get(key))
|
|
124
|
+
.filter(Boolean)
|
|
125
|
+
.filter((/** @type {any} */ item) => item.canonical_rel_path && writtenSet.has(String(item.canonical_rel_path).replaceAll(path.sep, "/")))
|
|
126
|
+
.map((/** @type {any} */ item) => ({
|
|
127
|
+
selector: selector || null,
|
|
128
|
+
bundle: item.bundle,
|
|
129
|
+
item: item.item,
|
|
130
|
+
kind: item.kind,
|
|
131
|
+
track: item.track || null,
|
|
132
|
+
source_path: item.source_path || null,
|
|
133
|
+
canonical_rel_path: String(item.canonical_rel_path).replaceAll(path.sep, "/"),
|
|
134
|
+
canonical_path: item.canonical_path || `topogram/${String(item.canonical_rel_path).replaceAll(path.sep, "/")}`,
|
|
135
|
+
suggested_action: item.suggested_action || null
|
|
136
|
+
}))
|
|
137
|
+
.sort((/** @type {any} */ a, /** @type {any} */ b) =>
|
|
138
|
+
(a.bundle || "").localeCompare(b.bundle || "") ||
|
|
139
|
+
(a.track || "").localeCompare(b.track || "") ||
|
|
140
|
+
(a.kind || "").localeCompare(b.kind || "") ||
|
|
141
|
+
(a.item || "").localeCompare(b.item || "")
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { dashedTopogramId } from "../ids.js";
|
|
4
|
+
|
|
5
|
+
/** @param {string} kind @param {string} item @returns {any} */
|
|
6
|
+
export function canonicalRelativePathForItem(kind, item) {
|
|
7
|
+
switch (kind) {
|
|
8
|
+
case "actor":
|
|
9
|
+
return `actors/${dashedTopogramId(item)}.tg`;
|
|
10
|
+
case "role":
|
|
11
|
+
return `roles/${dashedTopogramId(item)}.tg`;
|
|
12
|
+
case "enum":
|
|
13
|
+
return `enums/enum-${dashedTopogramId(String(item || "").replace(/^enum_/, ""))}.tg`;
|
|
14
|
+
case "entity":
|
|
15
|
+
return `entities/${dashedTopogramId(item)}.tg`;
|
|
16
|
+
case "shape":
|
|
17
|
+
return `shapes/${dashedTopogramId(item)}.tg`;
|
|
18
|
+
case "capability":
|
|
19
|
+
return `capabilities/${dashedTopogramId(item)}.tg`;
|
|
20
|
+
case "widget":
|
|
21
|
+
return `widgets/${dashedTopogramId(item)}.tg`;
|
|
22
|
+
case "verification":
|
|
23
|
+
return `verifications/${dashedTopogramId(item)}.tg`;
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @param {string} kind @param {string} item @returns {any} */
|
|
30
|
+
export function canonicalDisplayPathForItem(kind, item) {
|
|
31
|
+
const relativePath = canonicalRelativePathForItem(kind, item);
|
|
32
|
+
return relativePath ? `topogram/${relativePath}` : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @param {CandidateBundle} bundle @param {string} kind @param {WorkflowRecord} item @returns {any} */
|
|
36
|
+
export function candidateSourcePathForItem(bundle, kind, item) {
|
|
37
|
+
const base = `candidates/reconcile/model/bundles/${bundle.slug}`;
|
|
38
|
+
switch (kind) {
|
|
39
|
+
case "actor":
|
|
40
|
+
return `${base}/actors/${item}.tg`;
|
|
41
|
+
case "role":
|
|
42
|
+
return `${base}/roles/${item}.tg`;
|
|
43
|
+
case "enum":
|
|
44
|
+
return `${base}/enums/${item}.tg`;
|
|
45
|
+
case "entity":
|
|
46
|
+
return `${base}/entities/${item}.tg`;
|
|
47
|
+
case "shape":
|
|
48
|
+
return `${base}/shapes/${item}.tg`;
|
|
49
|
+
case "capability":
|
|
50
|
+
return `${base}/capabilities/${item}.tg`;
|
|
51
|
+
case "widget":
|
|
52
|
+
return `${base}/widgets/${item}.tg`;
|
|
53
|
+
case "verification":
|
|
54
|
+
return `${base}/verifications/${item}.tg`;
|
|
55
|
+
default:
|
|
56
|
+
return `${base}/README.md`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { ensureTrailingNewline } from "../../../text-helpers.js";
|
|
4
|
+
|
|
5
|
+
/** @param {any[]} lines @param {string} blockName @returns {any} */
|
|
6
|
+
export function ensureProjectionBlock(lines, blockName) {
|
|
7
|
+
const startIndex = lines.findIndex((/** @type {any} */ line) => new RegExp(`^\\s*${blockName}\\s*\\{\\s*$`).test(line));
|
|
8
|
+
if (startIndex !== -1) {
|
|
9
|
+
let endIndex = -1;
|
|
10
|
+
for (let index = startIndex + 1; index < lines.length; index += 1) {
|
|
11
|
+
if (/^\s*\}\s*$/.test(lines[index])) {
|
|
12
|
+
endIndex = index;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (endIndex !== -1) {
|
|
17
|
+
return { lines, startIndex, endIndex };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const insertBeforeStatus = lines.findIndex((/** @type {any} */ line) => /^\s*status\s+\w+/.test(line));
|
|
21
|
+
const insertIndex = insertBeforeStatus === -1 ? lines.length : insertBeforeStatus;
|
|
22
|
+
const blockLines = ["", ` ${blockName} {`, " }"];
|
|
23
|
+
lines.splice(insertIndex, 0, ...blockLines);
|
|
24
|
+
return {
|
|
25
|
+
lines,
|
|
26
|
+
startIndex: insertIndex + 1,
|
|
27
|
+
endIndex: insertIndex + 2
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @param {any[]} lines @param {any[]} capabilityIds @returns {any} */
|
|
32
|
+
export function ensureProjectionRealizes(lines, capabilityIds) {
|
|
33
|
+
const startIndex = lines.findIndex((/** @type {any} */ line) => /^\s*realizes\s*\[/.test(line));
|
|
34
|
+
if (startIndex === -1) {
|
|
35
|
+
return { changed: false, lines };
|
|
36
|
+
}
|
|
37
|
+
let endIndex = startIndex;
|
|
38
|
+
while (endIndex < lines.length && !/\]/.test(lines[endIndex])) {
|
|
39
|
+
endIndex += 1;
|
|
40
|
+
}
|
|
41
|
+
if (endIndex >= lines.length) {
|
|
42
|
+
return { changed: false, lines };
|
|
43
|
+
}
|
|
44
|
+
/** @type {any[]} */
|
|
45
|
+
const existingItems = [];
|
|
46
|
+
for (let index = startIndex; index <= endIndex; index += 1) {
|
|
47
|
+
const text = lines[index]
|
|
48
|
+
.replace(/^\s*realizes\s*\[/, "")
|
|
49
|
+
.replace(/\]\s*$/, "")
|
|
50
|
+
.trim();
|
|
51
|
+
if (!text) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
for (const item of text.split(",").map((/** @type {any} */ entry) => entry.trim()).filter(Boolean)) {
|
|
55
|
+
existingItems.push(item);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const merged = [...new Set([...existingItems, ...(capabilityIds || [])])];
|
|
59
|
+
if (merged.length === existingItems.length) {
|
|
60
|
+
return { changed: false, lines };
|
|
61
|
+
}
|
|
62
|
+
const replacement = [" realizes [", ...merged.map((/** @type {any} */ item, /** @type {any} */ index) => ` ${item}${index === merged.length - 1 ? "" : ","}`), " ]"];
|
|
63
|
+
lines.splice(startIndex, endIndex - startIndex + 1, ...replacement);
|
|
64
|
+
return { changed: true, lines };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {string} baseContents @param {WorkflowRecord} item @returns {any} */
|
|
68
|
+
export function applyProjectionAuthPatchToTopogram(baseContents, item) {
|
|
69
|
+
const lines = String(baseContents || "").replace(/\r\n/g, "\n").split("\n");
|
|
70
|
+
const capabilities = [...new Set(item.related_capabilities || [])];
|
|
71
|
+
let changed = false;
|
|
72
|
+
|
|
73
|
+
const realizesResult = ensureProjectionRealizes(lines, capabilities);
|
|
74
|
+
changed = changed || realizesResult.changed;
|
|
75
|
+
|
|
76
|
+
if (item.projection_surface === "authorization") {
|
|
77
|
+
const block = ensureProjectionBlock(lines, "authorization");
|
|
78
|
+
for (const capabilityId of capabilities) {
|
|
79
|
+
const lineIndex = lines.findIndex((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
80
|
+
index > block.startIndex &&
|
|
81
|
+
index < block.endIndex &&
|
|
82
|
+
new RegExp(`^\\s*${capabilityId}(\\s|$)`).test(line)
|
|
83
|
+
);
|
|
84
|
+
if (item.suggested_action === "apply_projection_ownership_patch") {
|
|
85
|
+
const ownershipFragment = `ownership ${item.ownership}${item.ownership_field ? ` ownership_field ${item.ownership_field}` : ""}`;
|
|
86
|
+
if (lineIndex !== -1) {
|
|
87
|
+
if (!/\bownership\s+/.test(lines[lineIndex])) {
|
|
88
|
+
lines[lineIndex] = `${lines[lineIndex].trimEnd()} ${ownershipFragment}`;
|
|
89
|
+
changed = true;
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
lines.splice(block.endIndex, 0, ` ${capabilityId} ${ownershipFragment}`);
|
|
94
|
+
block.endIndex += 1;
|
|
95
|
+
changed = true;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (item.suggested_action === "apply_projection_permission_patch") {
|
|
100
|
+
const permissionFragment = `permission ${item.permission}`;
|
|
101
|
+
if (lineIndex !== -1) {
|
|
102
|
+
if (!/\bpermission\s+/.test(lines[lineIndex])) {
|
|
103
|
+
lines[lineIndex] = `${lines[lineIndex].trimEnd()} ${permissionFragment}`;
|
|
104
|
+
changed = true;
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
lines.splice(block.endIndex, 0, ` ${capabilityId} ${permissionFragment}`);
|
|
109
|
+
block.endIndex += 1;
|
|
110
|
+
changed = true;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const claimFragment = `claim ${item.claim}${item.claim_value != null ? ` claim_value ${item.claim_value}` : ""}`;
|
|
115
|
+
if (lineIndex !== -1) {
|
|
116
|
+
if (!/\bclaim\s+/.test(lines[lineIndex])) {
|
|
117
|
+
lines[lineIndex] = `${lines[lineIndex].trimEnd()} ${claimFragment}`;
|
|
118
|
+
changed = true;
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
lines.splice(block.endIndex, 0, ` ${capabilityId} ${claimFragment}`);
|
|
123
|
+
block.endIndex += 1;
|
|
124
|
+
changed = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (item.projection_surface === "visibility_rules") {
|
|
129
|
+
const block = ensureProjectionBlock(lines, "visibility_rules");
|
|
130
|
+
for (const capabilityId of capabilities) {
|
|
131
|
+
if (item.suggested_action === "apply_projection_permission_patch") {
|
|
132
|
+
const hasExistingPermissionRule = lines.some((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
133
|
+
index > block.startIndex &&
|
|
134
|
+
index < block.endIndex &&
|
|
135
|
+
new RegExp(`^\\s*action\\s+${capabilityId}\\s+visible_if\\s+permission\\s+${item.permission}(\\s|$)`).test(line)
|
|
136
|
+
);
|
|
137
|
+
if (hasExistingPermissionRule) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const hasAnyVisibilityRule = lines.some((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
141
|
+
index > block.startIndex &&
|
|
142
|
+
index < block.endIndex &&
|
|
143
|
+
new RegExp(`^\\s*action\\s+${capabilityId}\\s+visible_if\\s+`).test(line)
|
|
144
|
+
);
|
|
145
|
+
if (hasAnyVisibilityRule) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
lines.splice(block.endIndex, 0, ` action ${capabilityId} visible_if permission ${item.permission}`);
|
|
149
|
+
block.endIndex += 1;
|
|
150
|
+
changed = true;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const hasExistingClaimRule = lines.some((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
155
|
+
index > block.startIndex &&
|
|
156
|
+
index < block.endIndex &&
|
|
157
|
+
new RegExp(`^\\s*action\\s+${capabilityId}\\s+visible_if\\s+claim\\s+${item.claim}(\\s|$)`).test(line)
|
|
158
|
+
);
|
|
159
|
+
if (hasExistingClaimRule) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const hasAnyVisibilityRule = lines.some((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
163
|
+
index > block.startIndex &&
|
|
164
|
+
index < block.endIndex &&
|
|
165
|
+
new RegExp(`^\\s*action\\s+${capabilityId}\\s+visible_if\\s+`).test(line)
|
|
166
|
+
);
|
|
167
|
+
if (hasAnyVisibilityRule) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
lines.splice(block.endIndex, 0, ` action ${capabilityId} visible_if claim ${item.claim}${item.claim_value != null ? ` claim_value ${item.claim_value}` : ""}`);
|
|
171
|
+
block.endIndex += 1;
|
|
172
|
+
changed = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return changed ? ensureTrailingNewline(lines.join("\n")) : baseContents;
|
|
177
|
+
}
|