@radicaltools/mcp 0.5.0 → 0.6.0

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/dist/index.js CHANGED
@@ -83,13 +83,13 @@ import {
83
83
  viewShowsEveryNode,
84
84
  wikiDepthOf,
85
85
  withCanvasPositions
86
- } from "./chunk-DSR2PAMW.js";
86
+ } from "./chunk-5N36X7LP.js";
87
87
  import {
88
88
  __commonJS,
89
89
  __toESM,
90
90
  define_RADICAL_BUILD_default,
91
91
  init_define_RADICAL_BUILD
92
- } from "./chunk-ULUOEM3X.js";
92
+ } from "./chunk-COZU3R23.js";
93
93
 
94
94
  // ../../node_modules/webcola/dist/src/powergraph.js
95
95
  var require_powergraph = __commonJS({
@@ -6848,8 +6848,8 @@ function buildAlignmentToolHandlers() {
6848
6848
  if (input.nodeIds !== void 0 && (!Array.isArray(input.nodeIds) || input.nodeIds.some((id) => typeof id !== "string"))) return fail("remove_alignment: nodeIds must be an array of node ids");
6849
6849
  const canvas2 = canvasFor(ctx, "remove_alignment", input.viewId, true);
6850
6850
  if ("error" in canvas2) return fail(canvas2.error);
6851
- const among = input.nodeIds ? new Set(input.nodeIds.map((id) => ctx.resolveId(id))) : null;
6852
- const matches = ctx.diagram.getLayoutConstraints(canvas2.viewId).filter((c) => (input.id === void 0 ? c.type !== "pin" : c.id === input.id) && (!among || c.nodeIds.every((id) => among.has(id))));
6851
+ const among2 = input.nodeIds ? new Set(input.nodeIds.map((id) => ctx.resolveId(id))) : null;
6852
+ const matches = ctx.diagram.getLayoutConstraints(canvas2.viewId).filter((c) => (input.id === void 0 ? c.type !== "pin" : c.id === input.id) && (!among2 || c.nodeIds.every((id) => among2.has(id))));
6853
6853
  if (!matches.length) {
6854
6854
  const existing = ctx.diagram.getLayoutConstraints(canvas2.viewId);
6855
6855
  return fail(`remove_alignment: no such alignment on this canvas.${existing.length ? ` It has: ${existing.map(describeConstraint).join("; ")}.` : " It has none."}`);
@@ -11846,7 +11846,7 @@ init_define_RADICAL_BUILD();
11846
11846
 
11847
11847
  // ../../packages/common/src/check/sensors.ts
11848
11848
  init_define_RADICAL_BUILD();
11849
- var SENSOR_NAMES = ["command", "json", "playwright"];
11849
+ var SENSOR_NAMES = ["command", "github-actions", "json", "lighthouse", "machine", "playwright"];
11850
11850
  function commandWords(line) {
11851
11851
  const words2 = [];
11852
11852
  let word = "";
@@ -12640,6 +12640,7 @@ function parseMeasurementStore(text3) {
12640
12640
  var TEST_LINE = /^test\((.+)\)(?:\s+passed)?$/;
12641
12641
  var REVIEW_LINE = /^review\((.+)\)\s+passed$/i;
12642
12642
  var REVIEW_METRIC = "review";
12643
+ var SCALED = /\s+scaled$/i;
12643
12644
  var METRIC_LINE = /^([A-Za-z_][\w.:/-]*)\s*(?:\{([^}]*)\})?\s*(<=|>=|==|!=|=|<|>)\s*(-?\d+(?:\.\d+)?(?:e-?\d+)?)\s*(\S+)?$/i;
12644
12645
  var BASELINE_LINE = /^([A-Za-z_][\w.:/-]*)\s*(?:\{([^}]*)\})?\s*(<=|>=|==|!=|=|<|>)\s*baseline(?:\s*([+-])\s*(\d+(?:\.\d+)?(?:e-?\d+)?)\s*(%|[^\s%]+)?)?$/i;
12645
12646
  function parseLabels(text3) {
@@ -12668,11 +12669,14 @@ function parseCondition(line) {
12668
12669
  const baseline = b[4] ? { sign: b[4] === "-" ? -1 : 1, by: Number(b[5]), percent: b[6] === "%", ...b[6] !== "%" ? { unit: b[6] } : {} } : { sign: 1, by: 0, percent: true };
12669
12670
  return { kind: "metric", raw, metric: b[1], labels: labels2, op: b[3] === "=" ? "==" : b[3], value: Number.NaN, baseline };
12670
12671
  }
12671
- const m = METRIC_LINE.exec(raw);
12672
- if (!m) return { kind: "invalid", raw, problem: "it is neither `test(<file> \u203A <title>) passed`, `review(<name>) passed`, `<metric>{<labels>} <op> <number> [unit]` nor `<metric>{<labels>} <op> baseline [+|- <number> %|unit]`" };
12672
+ const scaled = SCALED.test(raw);
12673
+ const m = METRIC_LINE.exec(scaled ? raw.replace(SCALED, "") : raw);
12674
+ if (!m) return { kind: "invalid", raw, problem: "it is neither `test(<file> \u203A <title>) passed`, `review(<name>) passed`, `<metric>{<labels>} <op> <number> [unit] [scaled]` nor `<metric>{<labels>} <op> baseline [+|- <number> %|unit]`" };
12673
12675
  const labels = m[2] === void 0 ? {} : parseLabels(m[2]);
12674
12676
  if (typeof labels === "string") return { kind: "invalid", raw, problem: labels };
12675
- return { kind: "metric", raw, metric: m[1], labels, op: m[3] === "=" ? "==" : m[3], value: Number(m[4]), ...m[5] ? { unit: m[5] } : {} };
12677
+ const op = m[3] === "=" ? "==" : m[3];
12678
+ if (scaled && (op === "==" || op === "!=")) return { kind: "invalid", raw, problem: "scaled stretches a limit: it takes <, <=, > or >=, not == or !=" };
12679
+ return { kind: "metric", raw, metric: m[1], labels, op, value: Number(m[4]), ...m[5] ? { unit: m[5] } : {}, ...scaled ? { scaled: true } : {} };
12676
12680
  }
12677
12681
  function parseConditions(text3) {
12678
12682
  if (typeof text3 !== "string") return [];
@@ -12731,6 +12735,24 @@ function baselineOf(condition2, baseline, unit) {
12731
12735
  return { median: values.length % 2 ? values[mid] : (values[mid - 1] + values[mid]) / 2, runs: values.length };
12732
12736
  }
12733
12737
  var round = (n) => Math.round(n * 100) / 100;
12738
+ var MACHINE_SPEED_METRIC = "machine.speed";
12739
+ function machineSpeedAt(measurements, at) {
12740
+ const t = Date.parse(at);
12741
+ let best;
12742
+ for (const m of measurements) {
12743
+ if (m.metric !== MACHINE_SPEED_METRIC || !Number.isFinite(m.value) || m.value <= 0) continue;
12744
+ if (!best || Math.abs(Date.parse(m.at) - t) < Math.abs(Date.parse(best.at) - t)) best = m;
12745
+ }
12746
+ return best;
12747
+ }
12748
+ function scaledLimit(condition2, speed) {
12749
+ const factor = Math.max(1, round(speed));
12750
+ const upper = condition2.op === "<" || condition2.op === "<=";
12751
+ const limit = upper ? condition2.value * factor : condition2.value / factor;
12752
+ const unit = condition2.unit ? ` ${condition2.unit}` : "";
12753
+ const text3 = `${condition2.value}${unit} ${upper ? "\xD7" : "\xF7"} ${factor} = ${round(limit)}${unit}${speed < 1 ? ` (machine.speed ${round(speed)}, never below \xD71)` : ""}`;
12754
+ return { limit, factor, text: text3 };
12755
+ }
12734
12756
  function evaluateMetric(condition2, measurements, maxAge, now4, baseline = []) {
12735
12757
  const measurement = latestMeasurement(condition2, measurements);
12736
12758
  if (!measurement) return { outcome: "not-run" };
@@ -12758,6 +12780,12 @@ function evaluateMetric(condition2, measurements, maxAge, now4, baseline = []) {
12758
12780
  value = converted;
12759
12781
  }
12760
12782
  if (maxAge !== void 0 && age > maxAge) return { outcome: "stale", measurement, detail: `measured ${formatAge(age)} ago` };
12783
+ if (condition2.scaled) {
12784
+ const machine = machineSpeedAt(measurements, measurement.at);
12785
+ if (!machine) return { outcome: "not-run", measurement, detail: `scaled to the machine, and no ${MACHINE_SPEED_METRIC} was measured: run radical sense machine where the value is measured` };
12786
+ const scaled = scaledLimit(condition2, machine.value);
12787
+ return { outcome: COMPARE[condition2.op](value, scaled.limit) ? "passed" : "failed", measurement, detail: `limit ${scaled.text}` };
12788
+ }
12761
12789
  return { outcome: COMPARE[condition2.op](value, condition2.value) ? "passed" : "failed", measurement };
12762
12790
  }
12763
12791
 
@@ -13217,6 +13245,10 @@ function concernStatuses(packs, nodes, relations) {
13217
13245
  }
13218
13246
  return out;
13219
13247
  }
13248
+ function openConcerns(packs, nodes, relations, metamodel) {
13249
+ if (!holdsConcerns(metamodel)) return [];
13250
+ return concernStatuses(packs, nodes, relations).filter((s) => s.open.length);
13251
+ }
13220
13252
  var prop = (node, key) => {
13221
13253
  const value = node[key];
13222
13254
  return typeof value === "string" ? value.trim() : "";
@@ -14315,7 +14347,7 @@ var CHECK_RULES = [
14315
14347
  description: "Every concern a Hub concern pack finds in the model is settled by an accepted ADR marked with it (property `concern`) that constrains the elements it applies to, or what contains them.",
14316
14348
  severity: "warning",
14317
14349
  dimension: "decisions",
14318
- run: (model) => holdsConcerns(model.metamodel) ? concernStatuses(model.concerns ?? [], model.nodes, model.relations).filter((s) => s.open.length).map(({ pack, open, pending }) => {
14350
+ run: (model) => openConcerns(model.concerns ?? [], model.nodes, model.relations, model.metamodel).map(({ pack, open, pending }) => {
14319
14351
  const names = open.map((id) => quote(model.nodes[id])).join(", ");
14320
14352
  const being = pending.length ? ` ${pending.map(quote).join(", ")} ${pending.length === 1 ? "is" : "are"} proposed: the decision is being made.` : "";
14321
14353
  return {
@@ -14325,7 +14357,7 @@ var CHECK_RULES = [
14325
14357
  message: `${pack.name}: ${pack.concern.why} No accepted ADR marked "${pack.concern.id}" settles it for ${names}.${being}`,
14326
14358
  details: (pack.templateParams ?? []).map(questionLine)
14327
14359
  };
14328
- }) : []
14360
+ })
14329
14361
  },
14330
14362
  {
14331
14363
  id: "concern-unbound",
@@ -14532,6 +14564,27 @@ function wordFindings(model, off = /* @__PURE__ */ new Set()) {
14532
14564
  return CHECK_RULES.filter((r) => WORD_RULES.has(r.id) && !off.has(r.id)).flatMap((rule) => rule.run(model).map((f) => ({ rule: rule.id, severity: f.severity ?? rule.severity, message: f.message, ...f.nodeId ? { nodeId: f.nodeId } : {}, ...f.relationId ? { relationId: f.relationId } : {}, ...f.about ? { about: f.about } : {} })));
14533
14565
  }
14534
14566
 
14567
+ // ../../packages/common/src/check/profiles.ts
14568
+ init_define_RADICAL_BUILD();
14569
+ var ADOPT_RULE = {
14570
+ id: "baselines-pending",
14571
+ description: 'check.json does not wait for the baselines of its first run ("adopt": true); radical check --adopt takes them once.',
14572
+ severity: "error",
14573
+ dimension: "consistency"
14574
+ };
14575
+ function strictCheckConfig(ruleIds, metricIds) {
14576
+ return {
14577
+ rules: Object.fromEntries(ruleIds.filter((id) => id !== ADOPT_RULE.id).map((id) => [id, "error"])),
14578
+ goals: Object.fromEntries(metricIds.map((id) => [id, { min: 100 }]))
14579
+ };
14580
+ }
14581
+ function existingCodeCheckConfig(ruleIds) {
14582
+ return {
14583
+ adopt: true,
14584
+ rules: Object.fromEntries(ruleIds.filter((id) => id !== ADOPT_RULE.id).map((id) => [id, "error"]))
14585
+ };
14586
+ }
14587
+
14535
14588
  // ../../packages/common/src/check/goals.ts
14536
14589
  init_define_RADICAL_BUILD();
14537
14590
  var GOAL_RULE = {
@@ -14640,6 +14693,66 @@ var CHECK_METRICS = [
14640
14693
  ];
14641
14694
  var METRIC_IDS = new Set(CHECK_METRICS.map((m) => m.id));
14642
14695
 
14696
+ // ../../packages/common/src/check/files.ts
14697
+ init_define_RADICAL_BUILD();
14698
+ var CHECK_CONFIG_FILE = "check.json";
14699
+ var TEST_RESULTS_FILE = `${STATE_DIR}/test-results.json`;
14700
+ var MEASUREMENTS_FILE = `${STATE_DIR}/measurements.json`;
14701
+ function testsRanAt(results) {
14702
+ const runs = results.ci?.runs.map((r) => r.ranAt).filter((at) => !Number.isNaN(Date.parse(at))).sort() ?? [];
14703
+ return runs.length ? runs[runs.length - 1] : results.readAt;
14704
+ }
14705
+ function ciSourceOf(value) {
14706
+ const ci = value;
14707
+ if (!ci || ci.provider !== "github" || typeof ci.commit !== "string" || typeof ci.behind !== "number" || !Array.isArray(ci.runs)) return void 0;
14708
+ const runs = ci.runs.filter((r) => !!r && typeof r.id === "number" && typeof r.url === "string" && typeof r.sha === "string" && typeof r.ranAt === "string" && typeof r.workflow === "string" && Array.isArray(r.artifacts));
14709
+ return { provider: "github", commit: ci.commit, behind: ci.behind, runs };
14710
+ }
14711
+ var STATUSES = /* @__PURE__ */ new Set(["passed", "failed", "skipped"]);
14712
+ function parseTestResults(text3) {
14713
+ let data;
14714
+ try {
14715
+ data = JSON.parse(text3);
14716
+ } catch {
14717
+ return null;
14718
+ }
14719
+ const r = data;
14720
+ if (r?.version !== 1 || typeof r.readAt !== "string" || !Array.isArray(r.cases)) return null;
14721
+ const cases = r.cases.filter((c) => !!c && typeof c.file === "string" && Array.isArray(c.title) && c.title.every((t) => typeof t === "string") && STATUSES.has(c.status));
14722
+ const ci = ciSourceOf(r.ci);
14723
+ return {
14724
+ version: 1,
14725
+ readAt: r.readAt,
14726
+ reports: Array.isArray(r.reports) ? r.reports.filter((x) => typeof x === "string") : [],
14727
+ cases,
14728
+ ...typeof r.commit === "string" ? { commit: r.commit } : {},
14729
+ ...ci ? { ci } : {}
14730
+ };
14731
+ }
14732
+ function parseCheckConfig(text3) {
14733
+ const data = JSON.parse(stripBom(text3));
14734
+ if (!data || typeof data !== "object" || Array.isArray(data)) throw new Error("a config is a JSON object");
14735
+ const rules = data.rules;
14736
+ if (rules !== void 0 && (typeof rules !== "object" || rules === null || Array.isArray(rules))) throw new Error('"rules" is an object of rule settings');
14737
+ const goals = data.goals;
14738
+ if (goals !== void 0) {
14739
+ if (typeof goals !== "object" || goals === null || Array.isArray(goals)) throw new Error('"goals" is an object of goals by metric');
14740
+ for (const [id, goal] of Object.entries(goals)) {
14741
+ const min = goal?.min;
14742
+ if (typeof min !== "number" || !(min >= 0 && min <= 100)) throw new Error(`goal "${id}" needs a "min" from 0 to 100 (percent)`);
14743
+ }
14744
+ }
14745
+ const adopt = data.adopt;
14746
+ if (adopt !== void 0 && typeof adopt !== "boolean") throw new Error('"adopt" is true while check.json waits for the baselines of its first run (radical check --adopt), else left out');
14747
+ const ci = data.ci;
14748
+ if (ci !== void 0) {
14749
+ const artifacts = ci?.artifacts;
14750
+ if (typeof ci !== "object" || ci === null || Array.isArray(ci) || artifacts !== void 0 && !(Array.isArray(artifacts) && artifacts.every((a) => typeof a === "string" && a)))
14751
+ throw new Error('"ci" is an object whose "artifacts" lists the names of the CI artifacts that hold test reports');
14752
+ }
14753
+ return data;
14754
+ }
14755
+
14643
14756
  // ../../packages/common/src/check/testSource.ts
14644
14757
  init_define_RADICAL_BUILD();
14645
14758
 
@@ -14800,64 +14913,6 @@ function formatTrace(trace, nodes, now4 = Date.now()) {
14800
14913
  return out.join("\n");
14801
14914
  }
14802
14915
 
14803
- // ../../packages/common/src/check/files.ts
14804
- init_define_RADICAL_BUILD();
14805
- var CHECK_CONFIG_FILE = "check.json";
14806
- var TEST_RESULTS_FILE = `${STATE_DIR}/test-results.json`;
14807
- var MEASUREMENTS_FILE = `${STATE_DIR}/measurements.json`;
14808
- function testsRanAt(results) {
14809
- const runs = results.ci?.runs.map((r) => r.ranAt).filter((at) => !Number.isNaN(Date.parse(at))).sort() ?? [];
14810
- return runs.length ? runs[runs.length - 1] : results.readAt;
14811
- }
14812
- function ciSourceOf(value) {
14813
- const ci = value;
14814
- if (!ci || ci.provider !== "github" || typeof ci.commit !== "string" || typeof ci.behind !== "number" || !Array.isArray(ci.runs)) return void 0;
14815
- const runs = ci.runs.filter((r) => !!r && typeof r.id === "number" && typeof r.url === "string" && typeof r.sha === "string" && typeof r.ranAt === "string" && typeof r.workflow === "string" && Array.isArray(r.artifacts));
14816
- return { provider: "github", commit: ci.commit, behind: ci.behind, runs };
14817
- }
14818
- var STATUSES = /* @__PURE__ */ new Set(["passed", "failed", "skipped"]);
14819
- function parseTestResults(text3) {
14820
- let data;
14821
- try {
14822
- data = JSON.parse(text3);
14823
- } catch {
14824
- return null;
14825
- }
14826
- const r = data;
14827
- if (r?.version !== 1 || typeof r.readAt !== "string" || !Array.isArray(r.cases)) return null;
14828
- const cases = r.cases.filter((c) => !!c && typeof c.file === "string" && Array.isArray(c.title) && c.title.every((t) => typeof t === "string") && STATUSES.has(c.status));
14829
- const ci = ciSourceOf(r.ci);
14830
- return {
14831
- version: 1,
14832
- readAt: r.readAt,
14833
- reports: Array.isArray(r.reports) ? r.reports.filter((x) => typeof x === "string") : [],
14834
- cases,
14835
- ...typeof r.commit === "string" ? { commit: r.commit } : {},
14836
- ...ci ? { ci } : {}
14837
- };
14838
- }
14839
- function parseCheckConfig(text3) {
14840
- const data = JSON.parse(stripBom(text3));
14841
- if (!data || typeof data !== "object" || Array.isArray(data)) throw new Error("a config is a JSON object");
14842
- const rules = data.rules;
14843
- if (rules !== void 0 && (typeof rules !== "object" || rules === null || Array.isArray(rules))) throw new Error('"rules" is an object of rule settings');
14844
- const goals = data.goals;
14845
- if (goals !== void 0) {
14846
- if (typeof goals !== "object" || goals === null || Array.isArray(goals)) throw new Error('"goals" is an object of goals by metric');
14847
- for (const [id, goal] of Object.entries(goals)) {
14848
- const min = goal?.min;
14849
- if (typeof min !== "number" || !(min >= 0 && min <= 100)) throw new Error(`goal "${id}" needs a "min" from 0 to 100 (percent)`);
14850
- }
14851
- }
14852
- const ci = data.ci;
14853
- if (ci !== void 0) {
14854
- const artifacts = ci?.artifacts;
14855
- if (typeof ci !== "object" || ci === null || Array.isArray(ci) || artifacts !== void 0 && !(Array.isArray(artifacts) && artifacts.every((a) => typeof a === "string" && a)))
14856
- throw new Error('"ci" is an object whose "artifacts" lists the names of the CI artifacts that hold test reports');
14857
- }
14858
- return data;
14859
- }
14860
-
14861
14916
  // ../../packages/common/src/check/reviews.ts
14862
14917
  init_define_RADICAL_BUILD();
14863
14918
 
@@ -14877,11 +14932,14 @@ var FOLDER_RULES = [
14877
14932
  { id: "stale-reference", description: "Views, sequences and slides point only at elements, relations and views the model has.", severity: "warning", dimension: "consistency" }
14878
14933
  ];
14879
14934
  var STALE_REFERENCE = "stale-reference";
14880
- var MODEL_RULE_IDS = /* @__PURE__ */ new Set([STALE_REFERENCE, ...CHECK_RULES.map((r) => r.id), GOAL_RULE.id]);
14881
- var ALL_RULES = [...FOLDER_RULES, ...CHECK_RULES, GOAL_RULE];
14935
+ var MODEL_RULE_IDS = /* @__PURE__ */ new Set([STALE_REFERENCE, ...CHECK_RULES.map((r) => r.id), GOAL_RULE.id, ADOPT_RULE.id]);
14936
+ var ALL_RULES = [...FOLDER_RULES, ...CHECK_RULES, GOAL_RULE, ADOPT_RULE];
14882
14937
  var RULE_IDS = new Set(ALL_RULES.map((r) => r.id));
14883
14938
  var DEFAULT_SEVERITY = new Map(ALL_RULES.map((r) => [r.id, r.severity]));
14884
14939
  var DEFAULT_OFF = new Set(ALL_RULES.filter((r) => r.off).map((r) => r.id));
14940
+ var strictCheckConfig2 = () => strictCheckConfig(ALL_RULES.map((r) => r.id), CHECK_METRICS.map((m) => m.id));
14941
+ var existingCodeCheckConfig2 = () => existingCodeCheckConfig(ALL_RULES.map((r) => r.id));
14942
+ var serializeCheckConfig = (config) => JSON.stringify(config, null, 2) + "\n";
14885
14943
 
14886
14944
  // ../../packages/common/src/federation.ts
14887
14945
  init_define_RADICAL_BUILD();
@@ -22583,7 +22641,7 @@ function unchangedResult(nodes, relations, style = "curved") {
22583
22641
  }
22584
22642
  async function runSmartLayoutELKPhase(inputNodes, inputRelations, metamodel, onProgress) {
22585
22643
  const { nodes, relations } = projectToVisibleGraph(inputNodes, inputRelations);
22586
- const { applyElkLayout } = await import("./elkLayout-YXJWF5QP.js");
22644
+ const { applyElkLayout } = await import("./elkLayout-EA73VLB2.js");
22587
22645
  const depth2 = maxContainmentDepth(metamodel);
22588
22646
  const mmDirection = depth2 >= 2 ? "RIGHT" : "DOWN";
22589
22647
  const engines = [
@@ -25291,39 +25349,91 @@ init_define_RADICAL_BUILD();
25291
25349
  init_define_RADICAL_BUILD();
25292
25350
  var CONCERNS_QUESTION_ID = "concerns";
25293
25351
  var CONCERN_QUESTION_PREFIX = "concern:";
25294
- var packLine = (p) => `- ${p.id} | ${p.name}: ${p.description}`;
25295
- function concernsClarifyLines(packs, mode) {
25352
+ var BASELINE_PACK_IDS = ["concern-ci-cd-pipeline", "concern-test-strategy", "concern-release-versioning", "concern-code-quality-gate"];
25353
+ var SCREEN_PACK_IDS = ["concern-usability", "concern-accessibility", "concern-mobile-performance"];
25354
+ var concernsStageOf = (stage) => stage === "requirements" || stage === "review" ? stage : void 0;
25355
+ var packLine = (p, appliesTo) => `- ${p.id} | ${p.name}: ${p.description}${appliesTo?.length ? ` Open for: ${appliesTo.map((l) => `"${l}"`).join(", ")}.` : ""}`;
25356
+ var among = (packs, ids) => ids.map((id) => packs.find((p) => p.id === id)).filter((p) => !!p);
25357
+ function concernsClarifyLines(packs, mode, options = {}) {
25296
25358
  if (!packs.length) return [];
25359
+ if (options.stage === "review") return reviewClarifyLines(packs, mode, options.appliesTo ?? {});
25360
+ const baseline = among(packs, BASELINE_PACK_IDS);
25361
+ const screens = among(packs, SCREEN_PACK_IDS);
25362
+ const names = (list) => list.map((p) => p.name).join(", ");
25297
25363
  const lines = [
25298
25364
  "",
25299
25365
  "Concern packs of the Hub (id | name: what it settles). Each brings the requirements, the decision, its",
25300
25366
  "fitness functions and scenarios for one concern, as the user's answers to its questions pick them:",
25301
- ...packs.map(packLine),
25367
+ ...packs.map((p) => packLine(p)),
25302
25368
  "",
25303
25369
  "Pick the packs whose concern this system clearly has, from the description in whatever language it is",
25304
- "written (people sign in, data about people is kept, other systems are called, \u2026); none if none fits."
25370
+ "written (people sign in, data about people is kept, other systems are called, \u2026)."
25305
25371
  ];
25372
+ if (baseline.length) {
25373
+ lines.push(
25374
+ `Always include the baseline packs: ${names(baseline)}. They are the good practices every system needs`,
25375
+ "(how a change is built, tested, released and held to a quality gate); the user unchecks what does not apply."
25376
+ );
25377
+ }
25378
+ if (screens.length) {
25379
+ lines.push(
25380
+ `When people use the system through screens (a web, mobile or desktop app), also include ${names(screens)}:`,
25381
+ "the good practices of what people see and use. Leave them out for a system nobody uses through a screen."
25382
+ );
25383
+ }
25384
+ if (!baseline.length) lines.push("None if none fits.");
25306
25385
  if (mode === "ask") {
25307
25386
  lines.push(
25308
- "Ask the user to confirm your picks. Where the description clearly settles one of a confirmed pack's",
25387
+ "Present your picks to the user as proposed, each checked, the baseline packs among them, and let the user",
25388
+ "drop any that does not apply. Where the description clearly settles one of a kept pack's",
25309
25389
  "questions (listed below), propose the answer, quoting the words of the description it rests on, and ask",
25310
25390
  "the user to accept or change those answers; ask the other questions with their options. Answer only what",
25311
- "the description says, not what is usual. Pass the packs with the answers the user accepted or gave to",
25312
- "forge_generate as concerns."
25391
+ "the description says, not what is usual. Pass the packs the user kept, with the answers the user accepted",
25392
+ "or gave, to forge_generate as concerns; a pack the user dropped is left out."
25393
+ );
25394
+ } else {
25395
+ lines.push(
25396
+ `Include one question with id "${CONCERNS_QUESTION_ID}", kind "select", multiSelect true, whose options are the`,
25397
+ `names of your picks exactly as written above, asking which of them to settle now.${baseline.length ? "" : " Leave it out if none fits."}`,
25398
+ ...jsonAnswerLines()
25399
+ );
25400
+ }
25401
+ return lines;
25402
+ }
25403
+ function reviewClarifyLines(packs, mode, appliesTo) {
25404
+ const lines = [
25405
+ "",
25406
+ "These concerns the model raises are still open: Hub concern packs whose concern applies to elements of the",
25407
+ "model that no accepted decision settles (id | name: what it settles, and where it is open). Settle them",
25408
+ "before Forge ends. Each brings the requirements, the decision, its fitness functions and scenarios for its",
25409
+ "concern, as the user's answers to its questions pick them, bound to the elements it is open for:",
25410
+ ...packs.map((p) => packLine(p, appliesTo[p.id])),
25411
+ ""
25412
+ ];
25413
+ if (mode === "ask") {
25414
+ lines.push(
25415
+ "Present all of them to the user as proposed, each checked, and let the user drop any that does not apply.",
25416
+ "Where the description or the earlier answers clearly settle one of a kept pack's questions (listed below),",
25417
+ "propose the answer, quoting the words it rests on, and ask the user to accept or change those answers; ask",
25418
+ "the other questions with their options. Pass the packs the user kept, with the answers the user accepted or",
25419
+ "gave, to forge_generate as concerns: each comes into the model bound at once where its concern applies."
25313
25420
  );
25314
25421
  } else {
25315
25422
  lines.push(
25316
25423
  `Include one question with id "${CONCERNS_QUESTION_ID}", kind "select", multiSelect true, whose options are the`,
25317
- "names of your picks exactly as written above, asking which of them to settle now. Leave it out if none fits.",
25318
- "Do not ask the packs' own questions (listed below): they are added for the picks. Where the description",
25319
- `clearly settles one of a pick's questions, add to the "${CONCERNS_QUESTION_ID}" question an "answers" array of`,
25320
- '{"pack": pack id, "key": question key, "answer": option value, "because": the words of the description it',
25321
- "rests on, quoted as written}. Answer only what the description says, not what is usual: the user sees",
25322
- "each answer with its words and accepts or changes it."
25424
+ "names of all of them exactly as written above, asking which of them to settle now.",
25425
+ ...jsonAnswerLines()
25323
25426
  );
25324
25427
  }
25325
25428
  return lines;
25326
25429
  }
25430
+ var jsonAnswerLines = () => [
25431
+ "Do not ask the packs' own questions (listed below): they are added for the picks. Where the description",
25432
+ `clearly settles one of a pick's questions, add to the "${CONCERNS_QUESTION_ID}" question an "answers" array of`,
25433
+ '{"pack": pack id, "key": question key, "answer": option value, "because": the words of the description it',
25434
+ "rests on, quoted as written}. Answer only what the description says, not what is usual: the user sees",
25435
+ "each answer with its words and accepts or changes it."
25436
+ ];
25327
25437
  function concernQuestionLines(packs) {
25328
25438
  if (!packs.length) return [];
25329
25439
  return [
@@ -25335,6 +25445,20 @@ function concernQuestionLines(packs) {
25335
25445
  ])
25336
25446
  ];
25337
25447
  }
25448
+ function openConcernsForReview(packs, nodes, relations, metamodel) {
25449
+ const open = openConcerns(packs, nodes, relations, metamodel);
25450
+ return {
25451
+ packs: open.map((s) => s.pack),
25452
+ appliesTo: Object.fromEntries(open.map((s) => [s.pack.id, s.open.map((id) => nodes[id].label)]))
25453
+ };
25454
+ }
25455
+ function concernBindTargets(pack, nodes, relations, metamodel) {
25456
+ return suggestedCover(bindSuggestions(pack, nodes, relations, metamodel));
25457
+ }
25458
+ function reviewConcernLine(settled, nodes) {
25459
+ if (!settled.length) return "";
25460
+ return `Settled the open concerns the user confirmed, each bound where its concern applies: ${settled.map((s) => `${s.name} (${s.boundTo.length ? s.boundTo.map((id) => `"${nodes[id]?.label ?? id}"`).join(", ") : "unbound: nothing it applies to"})`).join(", ")}.`;
25461
+ }
25338
25462
  function decidedConcern(pack, insert) {
25339
25463
  const ids = (type2) => Object.values(insert.nodes).filter((n) => n.type === type2).map((n) => n.id);
25340
25464
  return { packId: pack.id, name: pack.name, concern: pack.concern.id, adrIds: ids("adr"), fitnessIds: ids("fitness-fn"), requirementIds: ids("requirement") };
@@ -25369,7 +25493,7 @@ function bindUnboundConcerns(decided, packs, nodes, relations, metamodel) {
25369
25493
  const adrs = d.adrIds.filter((id) => nodes[id] && nodes[id][CONCERN_KEY]);
25370
25494
  if (!adrs.length || adrs.some((id) => constrains.has(id))) continue;
25371
25495
  const pack = packs.find((p) => p.id === d.packId);
25372
- const where = pack ? suggestedCover(bindSuggestions(pack, nodes, relations, metamodel)) : [];
25496
+ const where = pack ? concernBindTargets(pack, nodes, relations, metamodel) : [];
25373
25497
  if (!where.length) {
25374
25498
  lines.push(`${d.name}: nothing it applies to yet, so its decision is left unbound (concern-unbound reports it).`);
25375
25499
  continue;
@@ -25384,7 +25508,7 @@ function bindUnboundConcerns(decided, packs, nodes, relations, metamodel) {
25384
25508
  }
25385
25509
 
25386
25510
  // ../../packages/common/src/ai/forge/clarify.ts
25387
- function buildClarifyPrompt(stageTitle2, description, concernPacks2, priorQA, mode = "json") {
25511
+ function buildClarifyPrompt(stageTitle2, description, concernPacks2, priorQA, mode = "json", concerns = {}) {
25388
25512
  const lines = [
25389
25513
  `You are about to generate the "${stageTitle2}" stage of a Radical Forge run for the system described below.`,
25390
25514
  "",
@@ -25411,7 +25535,7 @@ function buildClarifyPrompt(stageTitle2, description, concernPacks2, priorQA, mo
25411
25535
  lines.push(
25412
25536
  "Ask the user those questions and wait for the answers; offer options where",
25413
25537
  "an answer is a choice. If nothing needs clarifying, ask nothing.",
25414
- ...concernsClarifyLines(concernPacks2 ?? [], "ask"),
25538
+ ...concernsClarifyLines(concernPacks2 ?? [], "ask", concerns),
25415
25539
  ...concernQuestionLines(concernPacks2 ?? [])
25416
25540
  );
25417
25541
  return lines.join("\n");
@@ -25421,7 +25545,7 @@ function buildClarifyPrompt(stageTitle2, description, concernPacks2, priorQA, mo
25421
25545
  '{"id": string, "question": string, "kind": "text" | "select", "options"?: string[], "multiSelect"?: boolean}',
25422
25546
  "If nothing needs clarifying, respond with exactly: []"
25423
25547
  );
25424
- lines.push(...concernsClarifyLines(concernPacks2 ?? [], "json"), ...concernQuestionLines(concernPacks2 ?? []));
25548
+ lines.push(...concernsClarifyLines(concernPacks2 ?? [], "json", concerns), ...concernQuestionLines(concernPacks2 ?? []));
25425
25549
  return lines.join("\n");
25426
25550
  }
25427
25551
  function formatClarificationAnswers(questions, answers) {
@@ -26367,10 +26491,13 @@ var FORGE_PROCEDURE = [
26367
26491
  " and write the model in the other.",
26368
26492
  "2. For each stage, in order:",
26369
26493
  " a. forge_clarify: read it and ask the user the clarifying questions it calls for, if any. In the",
26370
- " Requirements stage it also lists the Hub's concern packs: pick those the description calls for, have",
26371
- " the user confirm them and ask their questions. Wait for the answers.",
26372
- " b. forge_generate with those answers (in Requirements, the confirmed packs with their answers as",
26373
- " concerns: they come into the model whole, unbound, before the stage). It returns the stage task:",
26494
+ " Requirements stage it also lists the Hub's concern packs: pick those the description calls for, the",
26495
+ " baseline packs every system needs always among them, present them to the user as proposed, let the user",
26496
+ " drop any and ask the questions of the packs kept. In the Review stage it lists the concerns the model",
26497
+ " raises that are still open, to settle the same way. Wait for the answers.",
26498
+ " b. forge_generate with those answers (in Requirements and Review, the packs the user kept with their",
26499
+ " answers as concerns: in Requirements they come into the model whole, unbound, before the stage; in",
26500
+ " Review bound at once where their concern applies). It returns the stage task:",
26374
26501
  " carry it out with the model tools (add_node, add_relation, update_node, search_model, \u2026).",
26375
26502
  " A stage may also close gaps in earlier stages within the description (a requirement or scenario a",
26376
26503
  " process shows is missing, a wrong name), but only by proposing it: forge_propose_refinement returns",
@@ -26422,7 +26549,7 @@ var FORGE_TOOL_DEFS = [
26422
26549
  },
26423
26550
  {
26424
26551
  name: "forge_clarify",
26425
- description: "Before generating a Forge stage: returns what to clarify with the user first, and in the Requirements stage the Hub's concern packs to pick from with their questions. Ask the user, then call forge_generate with the answers.",
26552
+ description: "Before generating a Forge stage: returns what to clarify with the user first; in the Requirements stage the Hub's concern packs to pick from with their questions (the baseline packs every system needs always proposed), and in the Review stage the concerns the model raises that are still open. Ask the user, then call forge_generate with the answers.",
26426
26553
  inputSchema: {
26427
26554
  type: "object",
26428
26555
  properties: { stage: { ...stageEnum, description: "The next stage of the run, or one already generated (to regenerate it with new answers)." } },
@@ -26449,7 +26576,7 @@ var FORGE_TOOL_DEFS = [
26449
26576
  },
26450
26577
  concerns: {
26451
26578
  type: "array",
26452
- description: "Requirements stage only: the concern packs (from forge_clarify) the user confirmed, each with the user's answers by question key (option values). They come into the model whole and unbound before the stage; the C4 stage binds them. Omit to keep the last run's; [] imports none.",
26579
+ description: "Requirements and Review stages only: the concern packs (from forge_clarify) the user kept, each with the user's answers by question key (option values); leave out those the user dropped. In Requirements they come into the model whole and unbound before the stage, and the C4 stage binds them; in Review each comes in bound at once where its concern applies. Omit to keep the last run's; [] imports none.",
26453
26580
  items: {
26454
26581
  type: "object",
26455
26582
  properties: { id: { type: "string" }, answers: { type: "object", additionalProperties: { type: "string" } } },
@@ -26670,7 +26797,7 @@ var Forge = class {
26670
26797
  case "forge_start":
26671
26798
  return this.start(args, ctx, facade);
26672
26799
  case "forge_clarify":
26673
- return this.clarify(args);
26800
+ return this.clarify(args, facade);
26674
26801
  case "forge_generate":
26675
26802
  return this.generate(args, facade);
26676
26803
  case "forge_complete_stage":
@@ -26810,7 +26937,7 @@ var Forge = class {
26810
26937
  }
26811
26938
  } });
26812
26939
  }
26813
- clarify(args) {
26940
+ clarify(args, facade) {
26814
26941
  const run = this.run;
26815
26942
  if (!run) return fail2("forge_clarify: no Forge run; call forge_start first");
26816
26943
  const stage = this.stageArg(args, "forge_clarify");
@@ -26818,9 +26945,11 @@ var Forge = class {
26818
26945
  const id = stage;
26819
26946
  const blocked = this.blocked(run, id);
26820
26947
  if (blocked) return fail2(`forge_clarify: ${blocked}`);
26821
- const packs = id === "requirements" ? this.concernPacks() : [];
26948
+ const concernsStage = concernsStageOf(id);
26949
+ const offered = concernsStage === "review" ? openConcernsForReview(this.concernPacks(), facade.getNodes(), facade.getRelations(), facade.getMetamodel?.()) : { packs: concernsStage ? this.concernPacks() : [], appliesTo: {} };
26950
+ const packs = offered.packs;
26822
26951
  const priorQA = STAGE_IDS3.slice(0, STAGE_IDS3.indexOf(id)).map((prior) => run.stages[prior]?.clarifications ?? "").filter(Boolean).join("\n\n");
26823
- const lines = [buildClarifyPrompt(stageTitle(id), run.description, packs, priorQA, "ask"), "", ...forgeLanguageRules(run.languages)];
26952
+ const lines = [buildClarifyPrompt(stageTitle(id), run.description, packs, priorQA, "ask", { stage: concernsStage, appliesTo: offered.appliesTo }), "", ...forgeLanguageRules(run.languages)];
26824
26953
  lines.push("", `Then call forge_generate with stage "${id}"${packs.length ? ", the answers and the concerns" : " and the answers"}.`);
26825
26954
  return ok(lines.join("\n"), { readOnly: true, commit: () => {
26826
26955
  run.clarified.add(id);
@@ -26855,7 +26984,7 @@ var Forge = class {
26855
26984
  }
26856
26985
  let concernPicks = previous?.concernPicks;
26857
26986
  if (args.concerns !== void 0) {
26858
- if (id !== "requirements") return fail2("forge_generate: concerns are picked in the Requirements stage");
26987
+ if (!concernsStageOf(id)) return fail2("forge_generate: concerns are settled in the Requirements and Review stages");
26859
26988
  if (!Array.isArray(args.concerns)) return fail2("forge_generate: concerns must be an array of { id, answers }");
26860
26989
  const picks = [];
26861
26990
  for (const raw of args.concerns) {
@@ -26894,18 +27023,25 @@ var Forge = class {
26894
27023
  const openedNames = opened.map((v) => views[v]?.name).filter(Boolean);
26895
27024
  let data;
26896
27025
  let decided = run.concerns;
26897
- if (id === "requirements") {
26898
- decided = [];
27026
+ const stageDecided = [];
27027
+ const settled = [];
27028
+ if (concernsStageOf(id)) {
27029
+ if (id === "requirements") decided = [];
26899
27030
  if (concernPicks?.length) {
26900
27031
  data = facade.toDiagramData();
26901
27032
  const roots = data.nodes.filter((n) => !n.parentId);
26902
27033
  let top = roots.length ? Math.max(...roots.map((n) => n.y + n.height)) + IMPORT_GAP : 0;
27034
+ const metamodel = facade.getMetamodel?.();
27035
+ const modelNodes = facade.getNodes();
26903
27036
  for (const pick of concernPicks) {
27037
+ const pack = this.concernPacks().find((p) => p.id === pick.id);
26904
27038
  const concept = docToConcept(this.hub().docs.get(pick.id));
27039
+ const bindTo = id === "review" ? concernBindTargets(pack, modelNodes, facade.getRelations(), metamodel) : [];
26905
27040
  const insert = buildConcernInsert(concept, {
26906
27041
  answers: pick.answers,
26907
- elements: [],
26908
- metamodel: facade.getMetamodel?.(),
27042
+ elements: bindTo.map((el) => modelNodes[el]),
27043
+ nodes: modelNodes,
27044
+ metamodel,
26909
27045
  today: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
26910
27046
  newId: () => crypto.randomUUID(),
26911
27047
  place: ({ height }) => {
@@ -26918,7 +27054,8 @@ var Forge = class {
26918
27054
  data.nodes.push(...Object.values(insert.nodes));
26919
27055
  data.relations.push(...Object.values(insert.relations));
26920
27056
  data.views = [...data.views ?? [], ...insert.views];
26921
- decided.push(decidedConcern(this.concernPacks().find((p) => p.id === pick.id), insert));
27057
+ (id === "requirements" ? decided : stageDecided).push(decidedConcern(pack, insert));
27058
+ settled.push({ name: pack.name, boundTo: bindTo });
26922
27059
  }
26923
27060
  readOnly = false;
26924
27061
  }
@@ -26934,7 +27071,7 @@ var Forge = class {
26934
27071
  const prompt = buildForgeStagePrompt(
26935
27072
  id,
26936
27073
  run.description,
26937
- buildConcernsBlock(id, decided, nodes),
27074
+ buildConcernsBlock(id, [...decided, ...stageDecided], nodes),
26938
27075
  clarifications,
26939
27076
  priorSummaries,
26940
27077
  needNode ? { id: needNode.id, label: needNode.label } : void 0,
@@ -26951,6 +27088,7 @@ var Forge = class {
26951
27088
  FORGE_STAGES[stageIdx].blurb,
26952
27089
  ...openedNames.length ? [`Made the stage's views before it begins: ${openedNames.join(", ")}. What you add shows up in them as you add it.`] : [],
26953
27090
  ...id === "requirements" && decided.length ? [`Imported the concern packs the user confirmed, whole and unbound: ${decided.map((d) => d.name).join(", ")}. The C4 stage links them.`] : [],
27091
+ ...id === "review" && settled.length ? [reviewConcernLine(settled, nodes)] : [],
26954
27092
  "",
26955
27093
  "Carry out the task at the end with the model tools (add_node, add_relation, update_node, move_node, search_model, \u2026).",
26956
27094
  "A Forge stage only builds the model: do not change the metamodel, presentations or milestones.",
@@ -30513,7 +30651,7 @@ function htmlToMarkdown(html) {
30513
30651
  `;
30514
30652
  }
30515
30653
  async function pdfText(bytes) {
30516
- const { extractText, getDocumentProxy } = await import("./dist-4NNGZXOU.js");
30654
+ const { extractText, getDocumentProxy } = await import("./dist-4A76JBX4.js");
30517
30655
  let timer2;
30518
30656
  const late = new Promise((_, fail3) => {
30519
30657
  timer2 = setTimeout(() => fail3(new Error(`not read within ${PDF_TIMEOUT / 1e3} s`)), PDF_TIMEOUT);
@@ -41973,6 +42111,23 @@ var FolderModel = class _FolderModel {
41973
42111
  /** Saves `content` (the model before a Forge run) as the folder's base
41974
42112
  * unless git saved one; a line for the answer when it did. A failed write
41975
42113
  * never fails the call. */
42114
+ /** The gate a model made by Forge or Assay starts with, written into a
42115
+ * folder that has no check.json (ADR Strict gate for new models): Forge's
42116
+ * model starts with its code, so every rule is an error and every goal
42117
+ * 100%; Assay's describes code that was there, so every rule is an error
42118
+ * waiting for the baselines of its first run. */
42119
+ async writeGate(name) {
42120
+ if (name !== "forge_start" && name !== "assay_finish") return "";
42121
+ const file = join17(this.folder, CHECK_CONFIG_FILE);
42122
+ if (await stat4(file).then(() => true, () => false)) return "";
42123
+ const forge = name === "forge_start";
42124
+ await writeFile5(file, serializeCheckConfig(forge ? strictCheckConfig2() : existingCodeCheckConfig2()));
42125
+ return forge ? `
42126
+
42127
+ Wrote ${CHECK_CONFIG_FILE}, the gate the new model starts with: every rule an error and every goal at 100% (radical check and Studio's Inspector read it).` : `
42128
+
42129
+ Wrote ${CHECK_CONFIG_FILE} for existing code: every rule an error, waiting for the baselines of its first run. Once the model is complete, run radical check --adopt (with the test reports) and commit check.json.`;
42130
+ }
41976
42131
  async saveForgeBase(content) {
41977
42132
  try {
41978
42133
  if (!mayReplaceWithForgeBase(await readEditorStateFile(this.folder, MODEL_BASE_FILE))) return "";
@@ -42438,7 +42593,7 @@ ${buildMetamodelBrief(metamodel2)}` };
42438
42593
  result.commit?.();
42439
42594
  if (FORGE_TOOLS.has(name)) await this.writeForgeStatus();
42440
42595
  if (ASSAY_TOOLS.has(name)) await this.writeAssayStatus();
42441
- return { ok: true, text: result.resultText + (forgeBase ? await this.saveForgeBase(forgeBase) : "") + (result.afterWrite ? await result.afterWrite() : "") };
42596
+ return { ok: true, text: result.resultText + (forgeBase ? await this.saveForgeBase(forgeBase) : "") + (result.afterWrite ? await result.afterWrite() : "") + await this.writeGate(name) };
42442
42597
  }
42443
42598
  let changed = result.data ?? facade.toDiagramData();
42444
42599
  settleGeometry(data, changed);
@@ -42467,6 +42622,7 @@ ${buildMetamodelBrief(metamodel2)}` };
42467
42622
  if (FORGE_TOOLS.has(name)) await this.writeForgeStatus();
42468
42623
  if (ASSAY_TOOLS.has(name)) await this.writeAssayStatus();
42469
42624
  if (forgeBase) outcome.text += await this.saveForgeBase(forgeBase);
42625
+ outcome.text += await this.writeGate(name);
42470
42626
  if (this.refreshTools(metamodel)) return { ...outcome, toolsChanged: true };
42471
42627
  return outcome;
42472
42628
  } catch (error) {