@magmonium/cli 0.10.23 → 0.10.26

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/bin/cli.js CHANGED
@@ -28,6 +28,7 @@ const validateCommand = require('./commands/validate');
28
28
  const apiOpsCommand = require('./commands/api-ops');
29
29
  const gestureCommand = require('./commands/gesture');
30
30
  const inspectCommand = require('./commands/inspect');
31
+ const findingsCommand = require('./commands/findings');
31
32
 
32
33
  const program = new Command();
33
34
 
@@ -65,5 +66,7 @@ validateCommand(program);
65
66
  apiOpsCommand(program);
66
67
  gestureCommand(program);
67
68
  inspectCommand(program);
69
+ findingsCommand(program);
70
+ findingsCommand.fixCommand(program);
68
71
 
69
72
  program.parse();
@@ -0,0 +1,263 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { readDesignFiles, isNewer } = require('./gen-code');
4
+ const pkg = require('../../package.json');
5
+ const {
6
+ DESIGN_ROOT,
7
+ appTypeScript,
8
+ findViolations,
9
+ loadBundles,
10
+ messageText,
11
+ pinsBehindStamp,
12
+ readApiSpec,
13
+ readDesignFilesAt,
14
+ readPackageJson,
15
+ themeCatalogOf,
16
+ translationAdvisories,
17
+ } = require('./validate');
18
+ const { gesture, printReport: printGesture, EXIT: GESTURE_EXIT } = require('./gesture');
19
+
20
+ const TAGS = ['error', 'warning', 'suggestion'];
21
+
22
+ /**
23
+ * Every standing fact one design holds, by source: its Violations (the editor's
24
+ * Invariants and the cli's own checks), its EmitGaps, and — with a spec — its
25
+ * DriftRows. The same three the FindingsStore reads.
26
+ */
27
+ function sweep(bundles, { source, files, root, catalog, ts, spec }) {
28
+ const { codegen, invariants, inspections } = bundles;
29
+ const operationOf = codegen.operationResolverOf(source.operations);
30
+ const violations = [
31
+ ...findViolations(bundles, source, catalog, operationOf, files, ts, { gaps: false }),
32
+ ...pinsBehindStamp(readPackageJson(root), files[`${DESIGN_ROOT}/index.json`]),
33
+ ...(translationAdvisories(root, source) || []),
34
+ ];
35
+ const gaps = invariants.collectEmitGaps({
36
+ screens: source.screens,
37
+ features: source.features,
38
+ navMap: source.navMap,
39
+ functions: source.functions,
40
+ enums: source.enums,
41
+ operationOf,
42
+ });
43
+ let rows = [];
44
+ if (spec) {
45
+ const run = inspections.runInspection(inspections.inspectionByName('drift'), { source, spec }, {});
46
+ rows = run.ok ? run.result : [];
47
+ }
48
+ return { violations, gaps, rows };
49
+ }
50
+
51
+ // Where a Finding is, by the ids its source holds — the target the Show Fix
52
+ // would reveal. Names are in `where`.
53
+ function targetOf(finding) {
54
+ const pick = (from, keys) =>
55
+ Object.fromEntries(keys.filter((key) => from[key] !== undefined && from[key] !== '').map((key) => [key, from[key]]));
56
+ switch (finding.source) {
57
+ case 'violation':
58
+ return finding.violation.target;
59
+ case 'gap':
60
+ return pick(finding.gap, ['screenId', 'controlId', 'output', 'slot', 'methodId', 'functionId', 'navId', 'anchor']);
61
+ case 'drift':
62
+ return pick(finding.row, ['featureId', 'methodId', 'shapeId', 'propertyId', 'functionId', 'code']);
63
+ }
64
+ return {};
65
+ }
66
+
67
+ const textOf = (finding) =>
68
+ finding.source === 'violation' && finding.violation.text
69
+ ? finding.violation.text
70
+ : messageText(finding.message);
71
+
72
+ function rowOf(bundles, finding, held) {
73
+ return {
74
+ key: finding.key,
75
+ source: finding.source,
76
+ kind: finding.kind,
77
+ tag: finding.tag,
78
+ text: textOf(finding),
79
+ where: finding.where,
80
+ ...(finding.detail ? { detail: finding.detail } : {}),
81
+ owner: finding.owner,
82
+ target: targetOf(finding),
83
+ fixes: bundles.findings.fixesOf(finding).map(({ kind, id }) => ({ kind, id })),
84
+ ...(finding.alsoSeen ? { alsoSeen: finding.alsoSeen } : {}),
85
+ ...(finding.aliases ? { aliases: finding.aliases } : {}),
86
+ ...(held && [finding.key, ...(finding.aliases || [])].some((key) => held.has(key)) ? { preexisting: true } : {}),
87
+ };
88
+ }
89
+
90
+ const findingsOf = (bundles, swept, source) =>
91
+ bundles.findings.inRegisterOrder(
92
+ bundles.findings.collectFindings(swept, {
93
+ screens: source.screens.map(({ meta }) => meta),
94
+ features: source.features,
95
+ })
96
+ );
97
+
98
+ /**
99
+ * The Repair Register as a report (GLOSSARY.md Finding, Repair Register; ADR
100
+ * 0192): every standing Finding of `.magmonium/`, one per fact, by Tag —
101
+ * `error`, `warning`, `suggestion` — with the Fixes each offers. Never writes.
102
+ *
103
+ * `spec`: undefined reads the Environment backend's `swagger.json`, a string
104
+ * reads that one, `false` skips drift. A spec that cannot be read does not
105
+ * fail the report: `drift` says it was not checked and why.
106
+ *
107
+ * `status`: `unreadable` (the codec refused), `findings` (a Finding with one
108
+ * of `tags` that the baseline did not hold), `ok`.
109
+ */
110
+ async function findings({ root = process.cwd(), spec, baseline, tags = TAGS, bundles } = {}) {
111
+ const report = { status: 'ok', drift: { checked: false }, counts: {}, findings: [] };
112
+ if (!fs.existsSync(path.join(root, DESIGN_ROOT, 'index.json'))) {
113
+ return { ...report, status: 'unreadable', refusal: { reason: 'absent', path: `${DESIGN_ROOT}/index.json` } };
114
+ }
115
+ bundles = bundles || loadBundles();
116
+ const { codegen } = bundles;
117
+ const files = readDesignFiles(root);
118
+ const read = codegen.readDesignSource(files);
119
+ if (!read.ok || !read.source)
120
+ return { ...report, status: 'unreadable', refusal: read.refusal || { reason: 'unreadable' } };
121
+ const source = read.source;
122
+ if (source.codegen && isNewer(source.codegen, pkg.version))
123
+ return { ...report, status: 'unreadable', refusal: { reason: 'newer', version: source.codegen } };
124
+
125
+ let apiSpec;
126
+ if (spec !== false) {
127
+ try {
128
+ const fetched = await readApiSpec(bundles, spec || undefined, source.appTarget);
129
+ apiSpec = fetched.spec;
130
+ report.drift = { checked: true, spec: fetched.where };
131
+ } catch (error) {
132
+ report.drift = { checked: false, reason: error && error.message ? error.message : String(error) };
133
+ }
134
+ } else {
135
+ report.drift = { checked: false, reason: '--no-spec' };
136
+ }
137
+
138
+ const catalog = themeCatalogOf(root);
139
+ const ts = appTypeScript(root);
140
+ const ctx = { root, catalog, ts, spec: apiSpec };
141
+ const now = findingsOf(bundles, sweep(bundles, { ...ctx, source, files }), source);
142
+
143
+ let held;
144
+ if (baseline) {
145
+ const beforeFiles = readDesignFilesAt(root, baseline);
146
+ const before = codegen.readDesignSource(beforeFiles);
147
+ held = new Set(
148
+ before.ok && before.source
149
+ ? findingsOf(bundles, sweep(bundles, { ...ctx, source: before.source, files: beforeFiles }), before.source).flatMap(
150
+ (one) => [one.key, ...(one.aliases || [])]
151
+ )
152
+ : []
153
+ );
154
+ report.baseline = baseline;
155
+ }
156
+
157
+ report.findings = now.filter((one) => tags.includes(one.tag)).map((one) => rowOf(bundles, one, held));
158
+ report.counts = Object.fromEntries(TAGS.map((tag) => [tag, report.findings.filter((one) => one.tag === tag).length]));
159
+ if (report.findings.some((one) => !one.preexisting)) report.status = 'findings';
160
+ return report;
161
+ }
162
+
163
+ const EXIT = { ok: 0, findings: 1, unreadable: 2 };
164
+ const MARK = { error: '❌', warning: '⚠️ ', suggestion: '💡' };
165
+
166
+ function printReport(report) {
167
+ if (report.status === 'unreadable') {
168
+ const r = report.refusal || {};
169
+ console.error(`❌ findings: cannot read ${DESIGN_ROOT}/ (${r.reason || 'unreadable'}${r.path ? `: ${r.path}` : ''})`);
170
+ return;
171
+ }
172
+ report.findings.forEach((one, index) => {
173
+ const mark = one.preexisting ? '· ' : MARK[one.tag];
174
+ console.log(`${String(index + 1).padStart(3)}. ${mark} ${one.tag} ${one.kind} — ${one.where.join(' · ')}`);
175
+ console.log(` ${one.text}${one.detail ? ` (${one.detail})` : ''}`);
176
+ console.log(` key ${one.key} · fixes: ${one.fixes.map((fix) => `${fix.kind}:${fix.id}`).join(', ')}`);
177
+ });
178
+ if (!report.drift.checked) console.log(`⏭️ drift not checked — ${report.drift.reason}`);
179
+ const fresh = report.findings.filter((one) => !one.preexisting).length;
180
+ const held = report.findings.length - fresh;
181
+ const counts = TAGS.filter((tag) => tag in report.counts)
182
+ .map((tag) => `${report.counts[tag]} ${tag}`)
183
+ .join(', ');
184
+ console.log(
185
+ `${report.status === 'ok' ? '✅' : '❌'} findings: ${counts}${report.baseline ? ` — ${fresh} new, ${held} already at ${report.baseline}` : ''}`
186
+ );
187
+ }
188
+
189
+ const parseTags = (value) => {
190
+ const tags = String(value)
191
+ .split(',')
192
+ .map((tag) => tag.trim())
193
+ .filter(Boolean);
194
+ const unknown = tags.filter((tag) => !TAGS.includes(tag));
195
+ if (unknown.length) throw new Error(`unknown tag ${unknown.join(', ')} — one of ${TAGS.join(', ')}`);
196
+ return tags;
197
+ };
198
+
199
+ function findingsCommand(program) {
200
+ program
201
+ .command('findings')
202
+ .description(
203
+ "List every Finding of .magmonium/ the way the editor's Repair Register does — Violations, EmitGaps and SpecDrift, one per fact, by Tag, with each one's Fixes. Never writes."
204
+ )
205
+ .option('--root <path>', 'App root (default: cwd)')
206
+ .option('--spec <urlOrFile>', "swagger.json to read drift against (default: the Environment backend's)")
207
+ .option('--no-spec', 'Skip drift')
208
+ .option('--baseline <ref>', 'Mark Findings the design already held at this git ref as preexisting; only new ones decide the status')
209
+ .option('--tag <tags>', `Only these Tags, comma-separated (${TAGS.join(', ')}; default: all)`)
210
+ .option('--json', 'Print the report as JSON')
211
+ .action(async (options) => {
212
+ let report;
213
+ try {
214
+ report = await findings({
215
+ root: options.root || process.cwd(),
216
+ spec: options.spec === true ? undefined : options.spec,
217
+ baseline: options.baseline,
218
+ tags: options.tag ? parseTags(options.tag) : TAGS,
219
+ });
220
+ } catch (error) {
221
+ console.error(`❌ findings: ${error.message}`);
222
+ process.exit(EXIT.unreadable);
223
+ }
224
+ if (options.json) console.log(JSON.stringify(report, null, 2));
225
+ else printReport(report);
226
+ process.exit(EXIT[report.status]);
227
+ });
228
+ }
229
+
230
+ /**
231
+ * One apply-Fix on one Finding — the `finding-fix` gesture under its own name:
232
+ * a dry run unless `--write`, and the gesture's refusals as the editor's.
233
+ */
234
+ function fixCommand(program) {
235
+ program
236
+ .command('fix <key>')
237
+ .description("Apply one of a Finding's apply-Fixes by its key (the finding-fix gesture). Dry run unless --write.")
238
+ .requiredOption('--apply <fixId>', 'The apply-Fix id, as `findings` lists it (computed-fix, route-input-fix)')
239
+ .option('--root <path>', 'App root (default: cwd)')
240
+ .option('--write', 'Land the result when nothing new blocks (canonical form, fresh write-id)')
241
+ .option('--json', 'Print the report as JSON')
242
+ .action(async (key, options) => {
243
+ let report;
244
+ try {
245
+ report = await gesture({
246
+ root: options.root || process.cwd(),
247
+ name: 'finding-fix',
248
+ args: { key, fix: options.apply },
249
+ write: Boolean(options.write),
250
+ });
251
+ } catch (error) {
252
+ console.error(`❌ fix: ${error.message}`);
253
+ process.exit(GESTURE_EXIT.invalid);
254
+ }
255
+ if (options.json) console.log(JSON.stringify(report, null, 2));
256
+ else printGesture(report);
257
+ process.exit(GESTURE_EXIT[report.status] ?? GESTURE_EXIT.invalid);
258
+ });
259
+ }
260
+
261
+ module.exports = findingsCommand;
262
+ module.exports.fixCommand = fixCommand;
263
+ module.exports.findings = findings;
@@ -198,3 +198,5 @@ function gestureCommand(program) {
198
198
 
199
199
  module.exports = gestureCommand;
200
200
  module.exports.gesture = gesture;
201
+ module.exports.printReport = printReport;
202
+ module.exports.EXIT = EXIT;
@@ -21,6 +21,7 @@ function loadBundles() {
21
21
  invariants: 'invariant-catalog.js',
22
22
  gestures: 'gesture-catalog.js',
23
23
  inspections: 'inspect-catalog.js',
24
+ findings: 'finding-catalog.js',
24
25
  swagger: 'swagger-helper.js',
25
26
  };
26
27
  const missing = Object.values(names).filter(
@@ -596,14 +597,16 @@ function configsAdvisories(catalog, source) {
596
597
 
597
598
  // Every Violation a read design holds: the editor's Invariants, plus what its
598
599
  // gestures would have refused, what resolves to no ApiOperation, the rows the
599
- // codec dropped on read, every body that does not compile, and the EmitGaps.
600
+ // codec dropped on read, every body that does not compile, and the EmitGaps —
601
+ // unless `gaps: false`, for `findings`, which reads the gaps as their own source.
600
602
  function findViolations(
601
603
  bundles,
602
604
  source,
603
605
  catalog,
604
606
  operationOf,
605
607
  files = {},
606
- ts = undefined
608
+ ts = undefined,
609
+ { gaps = true } = {}
607
610
  ) {
608
611
  const { codegen, invariants } = bundles;
609
612
  return [
@@ -613,7 +616,7 @@ function findViolations(
613
616
  ...rawNavBreaches(source, files),
614
617
  ...unresolvedMethods(codegen, source.features, operationOf),
615
618
  ...bodyBreaches(bundles, source, ts),
616
- ...emitGapAdvisories(bundles, source, operationOf),
619
+ ...(gaps ? emitGapAdvisories(bundles, source, operationOf) : []),
617
620
  ...configsAdvisories(controlConfigsCatalog(), source),
618
621
  ...invariants
619
622
  .runInvariants(invariants.invariantScopeOf(source, catalog || []))
@@ -856,4 +859,6 @@ module.exports.appTypeScript = appTypeScript;
856
859
  module.exports.readDesignFilesAt = readDesignFilesAt;
857
860
  module.exports.messageText = messageText;
858
861
  module.exports.pinsBehindStamp = pinsBehindStamp;
862
+ module.exports.translationAdvisories = translationAdvisories;
863
+ module.exports.readPackageJson = readPackageJson;
859
864
  module.exports.DESIGN_ROOT = DESIGN_ROOT;
@@ -852,6 +852,10 @@
852
852
  "minHeight": null
853
853
  },
854
854
  "section_pagination": {
855
+ "mode": [
856
+ "pages",
857
+ "scroll"
858
+ ],
855
859
  "perPageOptions": null,
856
860
  "showPerPage": null,
857
861
  "hideOnSinglePage": null,
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // apps/m-one-ui/src/app/pages/design/lib/finding-catalog.ts
21
+ var finding_catalog_exports = {};
22
+ __export(finding_catalog_exports, {
23
+ applyFixesOf: () => applyFixesOf,
24
+ collectFindings: () => collectFindings,
25
+ fixesOf: () => fixesOf,
26
+ inRegisterOrder: () => inRegisterOrder,
27
+ isShadowGap: () => isShadowGap,
28
+ panelFixOf: () => panelFixOf
29
+ });
30
+ module.exports = __toCommonJS(finding_catalog_exports);
31
+
32
+ // apps/m-one-ui/src/app/pages/design/lib/finding.ts
33
+ var import_codegen = require("./index.js");
34
+ var segment = (part) => encodeURIComponent(String(part)).replace(/%3A/g, ":");
35
+ var keyOf = (source, kind, ids) => [
36
+ source,
37
+ kind,
38
+ ...ids.filter((id) => id !== void 0 && id !== "")
39
+ ].map(segment).join("/");
40
+ var gapFindingKey = (gap) => keyOf("gap", gap.kind, [
41
+ gap.screenId,
42
+ gap.controlId,
43
+ gap.output,
44
+ gap.slot,
45
+ gap.methodId,
46
+ gap.paramIndex,
47
+ gap.autoCallId,
48
+ gap.functionId,
49
+ gap.navId,
50
+ gap.anchor
51
+ ]);
52
+ var violationFindingKey = (violation) => keyOf("violation", violation.invariant, violation.id.split("::").slice(1));
53
+ var driftFindingKey = (row) => keyOf("drift", row.kind, [
54
+ row.featureId,
55
+ row.methodId,
56
+ row.shapeId,
57
+ row.propertyId,
58
+ row.functionId,
59
+ row.code,
60
+ row.key,
61
+ (row.target ?? row.source ?? []).join("."),
62
+ row.paramIndex
63
+ ]);
64
+ var SUGGESTION_INVARIANTS = [
65
+ "method-variant-unused",
66
+ "shape-match"
67
+ ];
68
+ var violationTag = (invariant, severity) => severity === "blocking" ? "error" : SUGGESTION_INVARIANTS.includes(invariant) ? "suggestion" : "warning";
69
+ var DRIFT_TAGS = {
70
+ // Nothing left to call: the method is uncallable until it is removed.
71
+ "operation-gone": "error",
72
+ "input-gone": "warning",
73
+ "input-retyped": "warning",
74
+ "input-now-required": "warning",
75
+ // A mapping that no longer lands is dropped from the emitted store, which is
76
+ // the `response` gap's error said by the source that knows why (ADR 0211).
77
+ "response-code-gone": "error",
78
+ "response-path-gone": "error",
79
+ "response-retyped": "error",
80
+ // The api grew a key: nothing the design draws stopped working.
81
+ "shape-key-added": "suggestion",
82
+ "shape-key-gone": "warning",
83
+ "shape-key-retyped": "warning",
84
+ // Emitted reads are spelled `.name` against a payload read by `[i]`.
85
+ "shape-layout-changed": "warning",
86
+ "signature-shape-gone": "warning",
87
+ "signature-shape-retyped": "warning"
88
+ };
89
+ var driftTag = (kind) => DRIFT_TAGS[kind];
90
+ var GAP_TAGS = {
91
+ "call-arg": "warning",
92
+ "state-write": "warning",
93
+ "screen-write": "warning",
94
+ "auto-call": "warning",
95
+ response: "error",
96
+ binding: "warning",
97
+ "function-body": "error",
98
+ "nav-instance": "warning",
99
+ "output-open": "warning",
100
+ "output-link": "warning",
101
+ emit: "warning",
102
+ "output-open-output": "warning",
103
+ "call-outcome": "warning",
104
+ method: "warning"
105
+ };
106
+ var gapTag = (kind) => GAP_TAGS[kind];
107
+ var APP = { kind: "app" };
108
+ var SHARED = { kind: "shared" };
109
+ var featureOwner = (featureId) => featureId === import_codegen.SHARED_SHAPES ? SHARED : featureId ? { kind: "feature", featureId } : APP;
110
+ var screenOwner = (ctx, screenId) => featureOwner(ctx.screens.find((screen) => screen.id === screenId)?.featureId);
111
+ var methodOwner = (ctx, methodId) => featureOwner(
112
+ Object.values(ctx.features).find(
113
+ (feature) => (0, import_codegen.storesOf)(feature).some((store) => methodId in store.methods)
114
+ )?.id
115
+ );
116
+ var whereOf = (subject) => subject.split(/ · | → /).map((part) => part.trim()).filter(Boolean);
117
+ var violationOwner = (ctx, target) => {
118
+ switch (target.kind) {
119
+ case "panel":
120
+ case "function":
121
+ return featureOwner(target.featureId);
122
+ case "nav":
123
+ return APP;
124
+ case "compare":
125
+ return target.item.featureId ? featureOwner(target.item.featureId) : SHARED;
126
+ case "screen":
127
+ case "control":
128
+ return screenOwner(ctx, target.screenId);
129
+ }
130
+ };
131
+ var violationFinding = (violation, ctx) => ({
132
+ source: "violation",
133
+ violation,
134
+ key: violationFindingKey(violation),
135
+ kind: violation.invariant,
136
+ tag: violationTag(violation.invariant, violation.severity),
137
+ owner: violationOwner(ctx, violation.target),
138
+ message: violation.message,
139
+ where: whereOf(violation.subject)
140
+ });
141
+ var driftFinding = (row) => ({
142
+ source: "drift",
143
+ row,
144
+ key: driftFindingKey(row),
145
+ kind: row.kind,
146
+ tag: driftTag(row.kind),
147
+ owner: featureOwner(row.featureId),
148
+ message: row.message,
149
+ where: whereOf(row.subject),
150
+ ...row.detail ? { detail: row.detail } : {}
151
+ });
152
+ var gapFinding = (gap, ctx) => ({
153
+ source: "gap",
154
+ gap,
155
+ key: gapFindingKey(gap),
156
+ kind: gap.kind,
157
+ tag: gapTag(gap.kind),
158
+ owner: gap.screenId ? screenOwner(ctx, gap.screenId) : gap.methodId ? methodOwner(ctx, gap.methodId) : APP,
159
+ message: gap.message,
160
+ where: whereOf(gap.subject),
161
+ ...gap.detail ? { detail: gap.detail } : {}
162
+ });
163
+ function factKeys(finding) {
164
+ switch (finding.source) {
165
+ case "drift": {
166
+ const { row } = finding;
167
+ if (row.kind === "response-path-gone" || row.kind === "response-retyped")
168
+ return [`response|${row.methodId}|${row.code}:${row.propertyId}`];
169
+ if (row.kind === "input-now-required" || row.kind === "operation-gone")
170
+ return [`method|${row.methodId}`];
171
+ if (row.kind === "input-retyped") return [`member|${row.methodId}`];
172
+ return [];
173
+ }
174
+ case "gap": {
175
+ const { gap } = finding;
176
+ if (gap.kind === "response" && gap.anchor)
177
+ return [`response|${gap.methodId}|${gap.anchor}`];
178
+ if (gap.kind === "method") return [`method|${gap.methodId}`];
179
+ if (gap.kind === "screen-write" || gap.kind === "output-open")
180
+ return [`control-input|${gap.screenId}|${gap.controlId}`];
181
+ if (gap.kind === "binding")
182
+ return [`control-binding|${gap.screenId}|${gap.controlId}`];
183
+ return [];
184
+ }
185
+ case "violation": {
186
+ const { violation } = finding;
187
+ const target = violation.target;
188
+ if (target.kind === "control") {
189
+ if (violation.invariant === "screen-input-bound")
190
+ return [`control-input|${target.screenId}|${target.controlId}`];
191
+ if (violation.invariant === "binding-resolves")
192
+ return [`control-binding|${target.screenId}|${target.controlId}`];
193
+ }
194
+ if (violation.invariant === "state-path-resolves" && target.kind === "panel" && target.memberId)
195
+ return [`member|${target.memberId}`];
196
+ return [];
197
+ }
198
+ }
199
+ }
200
+ var TAG_RANK = { error: 0, warning: 1, suggestion: 2 };
201
+ var SOURCE_RANK = {
202
+ drift: 0,
203
+ violation: 1,
204
+ gap: 2
205
+ };
206
+ function mergeFindings(findings) {
207
+ const ranked = findings.map((finding, order) => ({ finding, order })).sort(
208
+ (a, b) => TAG_RANK[a.finding.tag] - TAG_RANK[b.finding.tag] || SOURCE_RANK[a.finding.source] - SOURCE_RANK[b.finding.source] || a.order - b.order
209
+ );
210
+ const claimed = /* @__PURE__ */ new Map();
211
+ const kept = /* @__PURE__ */ new Map();
212
+ for (const { finding, order } of ranked) {
213
+ const facts = factKeys(finding);
214
+ const into = facts.map((fact) => claimed.get(fact)).find(
215
+ (winner) => winner !== void 0 && kept.get(winner).source !== finding.source
216
+ );
217
+ if (into !== void 0) {
218
+ const winner = kept.get(into);
219
+ kept.set(into, {
220
+ ...winner,
221
+ alsoSeen: [...winner.alsoSeen ?? [], finding.kind],
222
+ aliases: [...winner.aliases ?? [], finding.key]
223
+ });
224
+ continue;
225
+ }
226
+ kept.set(order, finding);
227
+ for (const fact of facts) if (!claimed.has(fact)) claimed.set(fact, order);
228
+ }
229
+ return [...kept.entries()].sort(([a], [b]) => a - b).map(([, finding]) => finding);
230
+ }
231
+
232
+ // apps/m-one-ui/src/app/pages/design/lib/finding-catalog.ts
233
+ var CAST = { id: "cast", label: "fix-cast" };
234
+ var PRUNE = { id: "prune", label: "fix-prune" };
235
+ var REMOVE = { id: "remove", label: "fix-remove-method" };
236
+ var SHOW = { kind: "show", id: "show", label: "fix-show" };
237
+ var isShadowGap = (finding) => finding.source === "gap" && finding.gap.message === "emit-gap-shape-shadowed" && !!finding.gap.anchor && !!finding.gap.methodId;
238
+ function applyFixesOf(finding) {
239
+ switch (finding.source) {
240
+ case "drift":
241
+ return finding.row.repair === "cast" ? [CAST] : finding.row.repair === "prune" ? [PRUNE] : finding.row.repair === "remove" ? [REMOVE] : [];
242
+ case "violation":
243
+ return finding.violation.computedFix ? [{ id: "computed-fix", label: "fix-retype-parameters" }] : finding.violation.routeInputFix ? [{ id: "route-input-fix", label: "fix-route-inputs" }] : [];
244
+ case "gap":
245
+ return isShadowGap(finding) ? [CAST] : [];
246
+ }
247
+ }
248
+ function panelFixOf(finding) {
249
+ switch (finding.source) {
250
+ case "drift": {
251
+ const { row } = finding;
252
+ if (row.methodId && row.repair !== "cast") {
253
+ return { kind: "panel", id: "method-editor", label: "fix-open-method" };
254
+ }
255
+ if (row.functionId && row.repair === "none") {
256
+ return {
257
+ kind: "panel",
258
+ id: "function-editor",
259
+ label: "fix-open-function"
260
+ };
261
+ }
262
+ return void 0;
263
+ }
264
+ case "violation": {
265
+ const { violation } = finding;
266
+ if (violation.screenRetarget) {
267
+ return { kind: "panel", id: "retarget", label: "fix-retarget" };
268
+ }
269
+ return violation.target.kind === "panel" ? { kind: "panel", id: "violation-panel", label: "fix-open-panel" } : void 0;
270
+ }
271
+ case "gap":
272
+ return finding.gap.kind === "method" || finding.gap.kind === "response" ? { kind: "panel", id: "method-editor", label: "fix-open-method" } : void 0;
273
+ }
274
+ }
275
+ function fixesOf(finding) {
276
+ const panel = panelFixOf(finding);
277
+ return [
278
+ ...applyFixesOf(finding).map((fix) => ({ kind: "apply", ...fix })),
279
+ ...panel ? [panel] : [],
280
+ SHOW
281
+ ];
282
+ }
283
+ var TAG_RANK2 = {
284
+ error: 0,
285
+ warning: 1,
286
+ suggestion: 2
287
+ };
288
+ var SOURCE_RANK2 = {
289
+ drift: 0,
290
+ violation: 1,
291
+ gap: 2
292
+ };
293
+ var inRegisterOrder = (findings) => findings.map((finding, order) => ({ finding, order })).sort(
294
+ (a, b) => TAG_RANK2[a.finding.tag] - TAG_RANK2[b.finding.tag] || SOURCE_RANK2[a.finding.source] - SOURCE_RANK2[b.finding.source] || a.order - b.order
295
+ ).map(({ finding }) => finding);
296
+ var collectFindings = (sources, ctx) => mergeFindings([
297
+ ...sources.violations.map((v) => violationFinding(v, ctx)),
298
+ ...sources.rows.map(driftFinding),
299
+ // A body that will not compile is checked on a gesture, never swept.
300
+ ...sources.gaps.filter((gap) => gap.kind !== "function-body").map((gap) => gapFinding(gap, ctx))
301
+ ]);
302
+ // Annotate the CommonJS export names for ESM import in node:
303
+ 0 && (module.exports = {
304
+ applyFixesOf,
305
+ collectFindings,
306
+ fixesOf,
307
+ inRegisterOrder,
308
+ isShadowGap,
309
+ panelFixOf
310
+ });