@radicaltools/cli 0.3.3 → 0.3.4

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.
Files changed (2) hide show
  1. package/dist/index.js +75 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // <define:__RADICAL_BUILD__>
4
- var define_RADICAL_BUILD_default = { version: "0.3.3", commit: "b56a895", date: "2026-11-03", release: true };
4
+ var define_RADICAL_BUILD_default = { version: "0.3.4", commit: "1a00a35", date: "2026-11-06", release: true };
5
5
 
6
6
  // src/index.ts
7
7
  import { spawn as spawn8 } from "child_process";
@@ -3461,7 +3461,12 @@ function parseRepositoryFile(text3, file = REPOSITORY_FILE) {
3461
3461
  };
3462
3462
  const tests = settings("tests", ["include", "exclude"]);
3463
3463
  const ci = settings("ci", ["artifacts"]);
3464
+ const model = raw?.model;
3465
+ if (model !== void 0 && (typeof model?.repo !== "string" || !model.repo || model.ref !== void 0 && typeof model.ref !== "string")) {
3466
+ throw new Error(`${file}: "model" needs "repo" (the address of the model's repository), and "ref" is a branch or tag`);
3467
+ }
3464
3468
  return {
3469
+ ...model ? { model: { repo: model.repo, ...model.ref ? { ref: model.ref } : {} } } : {},
3465
3470
  ...tests ? { tests } : {},
3466
3471
  ...ci ? { ci } : {},
3467
3472
  implements: list("implements").map((e2, i) => {
@@ -3487,6 +3492,7 @@ ${lines.join(",\n")}
3487
3492
  ` : ""}]`;
3488
3493
  const inline = (v) => `{ ${Object.entries(v).map(([k, list]) => `${JSON.stringify(k)}: [${list.map((x) => JSON.stringify(x)).join(", ")}]`).join(", ")} }`;
3489
3494
  const settings = [
3495
+ ...file.model ? [` "model": { ${Object.entries(file.model).map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`).join(", ")} }`] : [],
3490
3496
  ...file.tests ? [` "tests": ${inline(file.tests)}`] : [],
3491
3497
  ...file.ci ? [` "ci": ${inline(file.ci)}`] : []
3492
3498
  ];
@@ -3511,6 +3517,43 @@ function builtIn(mapped, id, parentOf) {
3511
3517
  function elementPaths(mapped, id, parentOf) {
3512
3518
  return builtIn(mapped, id, parentOf)?.paths ?? [];
3513
3519
  }
3520
+ var OTHER_REPOSITORIES = "other repositories";
3521
+ function repositoryPartIds(data, mapped) {
3522
+ const parent = new Map(data.nodes.map((n) => [n.id, n.parentId]));
3523
+ const under = (id, roots) => {
3524
+ for (let at = id; at; at = parent.get(at)) if (roots.has(at)) return true;
3525
+ return false;
3526
+ };
3527
+ const from = (type, targets) => data.relations.filter((r) => r.relationType === type && targets.has(r.targetId)).map((r) => r.sourceId);
3528
+ const to2 = (type, sources) => data.relations.filter((r) => r.relationType === type && sources.has(r.sourceId)).map((r) => r.targetId);
3529
+ const elements = new Set(data.nodes.filter((n) => builtIn(mapped, n.id, (id) => parent.get(id))).map((n) => n.id));
3530
+ const requirements = new Set(to2("satisfies", elements));
3531
+ for (let size = -1; size !== requirements.size; ) {
3532
+ size = requirements.size;
3533
+ for (const id of to2("derives", requirements)) requirements.add(id);
3534
+ }
3535
+ const realised = new Set(to2("realises", elements));
3536
+ const machines = /* @__PURE__ */ new Set([...to2("implements", elements), ...from("lifecycle-of", realised)]);
3537
+ const entities = [...realised, ...to2("lifecycle-of", machines)];
3538
+ const behaviour = data.nodes.filter((n) => under(n.id, machines)).map((n) => n.id);
3539
+ const adrs = new Set(from("constrains", elements));
3540
+ return /* @__PURE__ */ new Set([
3541
+ ...elements,
3542
+ ...requirements,
3543
+ ...entities,
3544
+ ...behaviour,
3545
+ ...from("verifies", /* @__PURE__ */ new Set([...requirements, ...machines])),
3546
+ ...adrs,
3547
+ ...from("implements", adrs)
3548
+ ]);
3549
+ }
3550
+ function repositoryPart(data, mapped) {
3551
+ const here = repositoryPartIds(data, mapped);
3552
+ return {
3553
+ nodes: data.nodes.map((n) => here.has(n.id) || n.origin ? n : { ...n, origin: OTHER_REPOSITORIES }),
3554
+ relations: data.relations.map((r) => here.has(r.sourceId) && here.has(r.targetId) || r.origin ? r : { ...r, origin: OTHER_REPOSITORIES })
3555
+ };
3556
+ }
3514
3557
 
3515
3558
  // ../../packages/node-files/src/repositoryLayout.ts
3516
3559
  var RADICAL_DIR = ".radical";
@@ -3535,7 +3578,8 @@ async function upwards(from) {
3535
3578
  const dirs = [];
3536
3579
  for (let dir = resolve(from); ; dir = dirname2(dir)) {
3537
3580
  dirs.push(dir);
3538
- if (await exists(join(dir, ".git")) || dirname2(dir) === dir) return dirs;
3581
+ const checkout = basename(dir) === "model" && basename(dirname2(dir)) === RADICAL_DIR;
3582
+ if (!checkout && await exists(join(dir, ".git")) || dirname2(dir) === dir) return dirs;
3539
3583
  }
3540
3584
  }
3541
3585
  async function repositoryRoot(from) {
@@ -6524,6 +6568,7 @@ function settingsInModel(config) {
6524
6568
  function checkData(data, options, config) {
6525
6569
  const found = [];
6526
6570
  data = { ...data, nodes: withBoundTests(data.nodes, options.repository?.verifies) };
6571
+ if (options.repository?.model) data = { ...data, ...repositoryPart(data, options.repository.implements) };
6527
6572
  const nodes = byId(data.nodes);
6528
6573
  const relations = byId(data.relations);
6529
6574
  staleReferences(data.views ?? [], data.sequences ?? [], data.presentations ?? [], nodes, relations, data.snapshots ?? []).forEach((finding) => found.push({ rule: STALE_REFERENCE, ...finding }));
@@ -11975,6 +12020,14 @@ import { join as join10 } from "path";
11975
12020
  import { promisify as promisify2 } from "util";
11976
12021
 
11977
12022
  // ../../packages/common/src/modelChanges.ts
12023
+ function onlyPart(report, ids) {
12024
+ const element = (list) => list.filter((e2) => ids.has(e2.id));
12025
+ const relation = (list) => list.filter((r) => ids.has(r.source.id) || ids.has(r.target.id));
12026
+ return {
12027
+ elements: { added: element(report.elements.added), removed: element(report.elements.removed), changed: element(report.elements.changed) },
12028
+ relations: { added: relation(report.relations.added), removed: relation(report.relations.removed), changed: relation(report.relations.changed) }
12029
+ };
12030
+ }
11978
12031
  var NOT_MODEL = /* @__PURE__ */ new Set(["id", "x", "y", "width", "height", "collapsed"]);
11979
12032
  var SHOWN = /* @__PURE__ */ new Set(["type", "label", "parentId", "sourceId", "targetId", "relationType"]);
11980
12033
  var present = (value) => modelValue(value) !== null;
@@ -12219,8 +12272,12 @@ async function modelChangesSince(folder, current, since, options = {}) {
12219
12272
  }
12220
12273
  const before = { nodes: byId2(old.nodes), relations: byId2(old.relations) };
12221
12274
  const after = { nodes: byId2(current.nodes), relations: byId2(current.relations) };
12222
- const report = modelChangeReport(before, after);
12275
+ let report = modelChangeReport(before, after);
12223
12276
  const mapping = await readRepositoryMapping(folder).catch(() => null);
12277
+ if (options.part) {
12278
+ if (!mapping) throw new Error("--part needs the repository's .radical/radical.json");
12279
+ report = onlyPart(report, /* @__PURE__ */ new Set([...repositoryPartIds(old, mapping.implements), ...repositoryPartIds(current, mapping.implements)]));
12280
+ }
12224
12281
  if (mapping) {
12225
12282
  for (const change of [...report.elements.added, ...report.elements.changed, ...report.elements.removed]) {
12226
12283
  if (change.type === "scenario" || change.type === "fitness-fn") change.tests = testsBoundTo(mapping.verifies, change.id);
@@ -12635,6 +12692,8 @@ var CHECK_USAGE = `Usage: radical check [folder] [options]
12635
12692
 
12636
12693
  Checks a Radical Markdown model folder: its files, its metamodel, and that it
12637
12694
  is complete (requirements have scenarios, accepted ADRs fitness functions, \u2026).
12695
+ In a repository whose .radical/radical.json names a model in a repository of
12696
+ its own ("model": { "repo": \u2026 }), it judges that repository's part of the model.
12638
12697
 
12639
12698
  folder the model folder (default: the working directory)
12640
12699
  --config <file> rule settings (default: check.json in the model folder,
@@ -12773,6 +12832,7 @@ ${CHECK_USAGE}`);
12773
12832
  const mapping = await readRepositoryMapping(root);
12774
12833
  repository = mapping && {
12775
12834
  file: relative5(io2.cwd, mapping.file),
12835
+ ...mapping.model ? { model: mapping.model } : {},
12776
12836
  implements: mapping.implements.map((entry) => ({ ...entry, missing: entry.paths.filter((path) => !existsSync2(resolve10(mapping.root, path))) })),
12777
12837
  verifies: mapping.verifies,
12778
12838
  ...mapping.tests ? { tests: mapping.tests } : {},
@@ -12906,6 +12966,7 @@ ${CHECK_USAGE}`);
12906
12966
  }
12907
12967
  if (values.evidence && result.evidence) await writeBeside(resolve10(io2.cwd, values.evidence), JSON.stringify(result.evidence, null, 2) + "\n");
12908
12968
  const options = { folder, verbose: values.verbose };
12969
+ if (repository?.model && values.format !== "json" && !values.quiet) io2.out(`Judged this repository's part of the model of ${repository.model.repo}.`);
12909
12970
  if (federation && values.format !== "json" && !values.quiet) {
12910
12971
  io2.out(`Checked with ${describeDeps(federation.fetched) || "no other model"} (${DEPS_FILE}).`);
12911
12972
  for (const note of federation.notes) io2.out(`Note: ${note}`);
@@ -12966,6 +13027,10 @@ folding are left out. The MCP server's get_changes tool gives the same list.
12966
13027
  --since <ref> the git branch, tag or commit to compare with (default:
12967
13028
  the merge base with the default branch, origin/main)
12968
13029
  --format <format> text (default) or json
13030
+ --part only the repository's part of the model, by its
13031
+ .radical/radical.json, as it is now and as it was at the
13032
+ base: what the repository has left to build when the base
13033
+ is the commit its code has reached
12969
13034
  --save-base also save the model at the base to .state/base.json in
12970
13035
  the folder, for Studio to show the changes (radical hooks
12971
13036
  install keeps it fresh)
@@ -12982,6 +13047,7 @@ async function diffCommand(args, io2) {
12982
13047
  since: { type: "string" },
12983
13048
  format: { type: "string", default: "text" },
12984
13049
  "save-base": { type: "boolean", default: false },
13050
+ part: { type: "boolean", default: false },
12985
13051
  quiet: { type: "boolean", default: false },
12986
13052
  help: { type: "boolean", short: "h", default: false }
12987
13053
  }
@@ -13006,7 +13072,7 @@ ${DIFF_USAGE}`);
13006
13072
  const root = await realpath5(resolve11(io2.cwd, folder));
13007
13073
  if (!(await stat8(root)).isDirectory()) throw new Error("not a directory");
13008
13074
  const data = deserializeFromMdFolder(await new MdFolderSession(diskFolderStorage(root), { writeCache: false }).readAll()).data;
13009
- const changes = await modelChangesSince(root, data, values.since, { saveBase: values["save-base"] });
13075
+ const changes = await modelChangesSince(root, data, values.since, { saveBase: values["save-base"], part: values.part });
13010
13076
  if (values.quiet && values["save-base"]) return 0;
13011
13077
  if (values["save-base"]) io2.err(`Saved the base (${changes.base.commit.slice(0, 7)}) to ${folder}/.state/base.json.`);
13012
13078
  io2.out(values.format === "json" ? JSON.stringify({ base: changes.base, ...changes.report }, null, 2) : changes.text);
@@ -15799,8 +15865,11 @@ ${SENSE_USAGE}`);
15799
15865
  const own = deserializeFromMdFolder(files).data;
15800
15866
  const federation = await composeFolder(folder);
15801
15867
  const others = federation ? federationOthers(files, federation.fetched) : null;
15802
- nodes = [...own.nodes, ...others?.nodes ?? []];
15803
- model = sensorModel({ nodes, relations: [...own.relations, ...others?.relations ?? []] }, federation?.deps.name || basename5(folder), (await readRepositoryMapping(folder))?.implements ?? []);
15868
+ const mapping = await readRepositoryMapping(folder);
15869
+ const whole = { nodes: [...own.nodes, ...others?.nodes ?? []], relations: [...own.relations, ...others?.relations ?? []] };
15870
+ const part = mapping?.model ? repositoryPart(whole, mapping.implements) : whole;
15871
+ nodes = part.nodes;
15872
+ model = sensorModel(part, federation?.deps.name || basename5(folder), mapping?.implements ?? []);
15804
15873
  sensors = await repositorySensors(folder);
15805
15874
  } catch (error) {
15806
15875
  io2.err(`Cannot read the model folder ${named}: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radicaltools/cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Connect coding agents to Radical Markdown architecture models, check, diff and export them, and fuzz a project against them, from the command line.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://radical.tools",