glassbrain 0.2.0-alpha.6 → 0.2.0-alpha.8
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/README.md +6 -7
- package/dist/chunks/{chunk-LMYD4QHC.js → chunk-3CNHFYHG.js} +1329 -1610
- package/dist/chunks/chunk-7PWRJEZT.js +35 -0
- package/dist/chunks/chunk-CHOCJIOD.js +1340 -0
- package/dist/chunks/chunk-DHYIMBHU.js +960 -0
- package/dist/chunks/{chunk-3SAL4526.js → chunk-NDUF3CBQ.js} +349 -989
- package/dist/cli/glassbrain.js +441 -230
- package/dist/cli/viewer.js +228 -194
- package/dist/core.d.ts +2 -0
- package/dist/core.js +54 -26
- package/dist/diff.d.ts +9 -1
- package/dist/edit.d.ts +10 -0
- package/dist/index.js +63 -35
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +103 -73
- package/dist/kinds.d.ts +23 -0
- package/dist/layers.d.ts +3 -1
- package/dist/lint-report.d.ts +70 -0
- package/dist/profile.d.ts +15 -3
- package/dist/react/DetailPanel.d.ts +31 -1
- package/dist/react/DetailPanel.js +8 -4
- package/dist/react/EdgeMark.d.ts +22 -0
- package/dist/react/EditPanel.d.ts +6 -6
- package/dist/react/GraphCanvas.d.ts +18 -5
- package/dist/react/GraphCanvas.js +4 -4
- package/dist/react/Inspector.d.ts +72 -0
- package/dist/react/ObjectRef.d.ts +12 -0
- package/dist/react/Toolbar.d.ts +10 -3
- package/dist/react/ZoomBoundary.d.ts +4 -0
- package/dist/react/camera.d.ts +7 -0
- package/dist/react/i18n.d.ts +2 -2
- package/dist/react/icons.d.ts +7 -1
- package/dist/react/input.d.ts +5 -3
- package/dist/react/useSubgraph.d.ts +15 -0
- package/dist/shell.d.ts +1 -0
- package/dist/strings.d.ts +24 -3
- package/dist/style.d.ts +2 -0
- package/dist/subgraph.d.ts +13 -0
- package/dist/tree.d.ts +1 -0
- package/dist/view.d.ts +3 -1
- package/package.json +1 -1
- package/schema/profile.schema.json +2 -2
- package/dist/chunks/chunk-3P34XHQ2.js +0 -244
- package/dist/chunks/chunk-5DEN6HXJ.js +0 -99
- package/dist/chunks/chunk-M3MAM2VD.js +0 -67
package/dist/cli/glassbrain.js
CHANGED
|
@@ -41,10 +41,10 @@ function mergeRuntimeSlices(slices) {
|
|
|
41
41
|
return dup.size ? { ...m, duplicateIds: [...dup] } : m;
|
|
42
42
|
}
|
|
43
43
|
var defOf = ({ origin: _o, origins: _os, ...rest }) => JSON.stringify(rest);
|
|
44
|
-
function addOrigin(
|
|
45
|
-
if (!origin) return
|
|
46
|
-
if (!
|
|
47
|
-
return
|
|
44
|
+
function addOrigin(list2, origin) {
|
|
45
|
+
if (!origin) return list2 ?? [];
|
|
46
|
+
if (!list2) return [origin];
|
|
47
|
+
return list2.includes(origin) ? list2 : [...list2, origin];
|
|
48
48
|
}
|
|
49
49
|
function originsOfNode(n) {
|
|
50
50
|
return n.origins?.length ? n.origins : n.origin ? [n.origin] : [];
|
|
@@ -102,7 +102,7 @@ function indexModel(model) {
|
|
|
102
102
|
// src/tree.ts
|
|
103
103
|
var object = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
104
104
|
var ref = (x) => typeof x === "string" || typeof x === "number" ? String(x) : void 0;
|
|
105
|
-
var
|
|
105
|
+
var stableJson = (x) => JSON.stringify(x, function(_key, value) {
|
|
106
106
|
return object(value) ? Object.fromEntries(Object.keys(value).sort().map((k) => [k, value[k]])) : value;
|
|
107
107
|
});
|
|
108
108
|
function treeDeclarations(raw, origin) {
|
|
@@ -168,12 +168,12 @@ function composeTrees(input) {
|
|
|
168
168
|
if (!r.origins.includes(slice.origin)) r.origins.push(slice.origin);
|
|
169
169
|
for (const [field, value] of [...Object.entries(d.fields), ...d.children === void 0 ? [] : [["children", d.children]]]) {
|
|
170
170
|
const previous = field === "children" ? r.children : r.fields[field];
|
|
171
|
-
if (r.locations.has(field) &&
|
|
171
|
+
if (r.locations.has(field) && stableJson(previous) !== stableJson(value)) {
|
|
172
172
|
errors.push({
|
|
173
173
|
origin: slice.origin,
|
|
174
174
|
node: d.id,
|
|
175
175
|
code: field === "children" ? "children-conflict" : "field-conflict",
|
|
176
|
-
message: `"${d.id}".${field}: ${r.locations.get(field)} = ${
|
|
176
|
+
message: `"${d.id}".${field}: ${r.locations.get(field)} = ${stableJson(previous)} conflicts with ${d.path} = ${stableJson(value)}.`
|
|
177
177
|
});
|
|
178
178
|
} else if (!r.locations.has(field)) {
|
|
179
179
|
if (field === "children") r.children = value;
|
|
@@ -248,7 +248,7 @@ function serializeTree(model) {
|
|
|
248
248
|
group.push(n);
|
|
249
249
|
groups.set(n.parent, group);
|
|
250
250
|
}
|
|
251
|
-
for (const
|
|
251
|
+
for (const list2 of groups.values()) list2.sort((a2, b) => (a2.order ?? Infinity) - (b.order ?? Infinity));
|
|
252
252
|
const roots = groups.get(void 0) ?? [];
|
|
253
253
|
const visited = /* @__PURE__ */ new Set(), stack = [...roots];
|
|
254
254
|
while (stack.length) {
|
|
@@ -296,6 +296,10 @@ function toPhysical(model) {
|
|
|
296
296
|
return serializeTree(model);
|
|
297
297
|
}
|
|
298
298
|
var DEFAULT_LAYER = { id: "default", label: "Graph", z: 0, structural: true };
|
|
299
|
+
function kindTable(...entries) {
|
|
300
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), ...entries);
|
|
301
|
+
}
|
|
302
|
+
var noDataReview = () => [];
|
|
299
303
|
function defineProfile(input) {
|
|
300
304
|
const layers = input.layers?.length ? input.layers : [DEFAULT_LAYER];
|
|
301
305
|
const fallbackLayer = layers[0].id;
|
|
@@ -304,18 +308,19 @@ function defineProfile(input) {
|
|
|
304
308
|
parse: input.parse ?? parsePhysical,
|
|
305
309
|
merge: input.merge ?? mergeSlices,
|
|
306
310
|
layers,
|
|
311
|
+
structuralLayers: input.structuralLayers ?? !input.layers?.length,
|
|
307
312
|
layerOf: input.layerOf ?? ((n) => n.layer ?? fallbackLayer),
|
|
308
|
-
nodePalette: input.nodePalette
|
|
309
|
-
edgePalette: input.edgePalette
|
|
310
|
-
nodeSize: input.nodeSize
|
|
311
|
-
edgeWidth: input.edgeWidth
|
|
313
|
+
nodePalette: kindTable(input.nodePalette),
|
|
314
|
+
edgePalette: kindTable(input.edgePalette),
|
|
315
|
+
nodeSize: kindTable(input.nodeSize),
|
|
316
|
+
edgeWidth: kindTable(input.edgeWidth),
|
|
312
317
|
placeholderFlags: input.placeholderFlags ?? [],
|
|
313
318
|
style: input.style ?? [],
|
|
314
319
|
nodeClass: input.nodeClass ?? (() => ""),
|
|
315
320
|
edgeClass: input.edgeClass ?? ((e) => e.kind ?? ""),
|
|
316
|
-
kindLabels: input.kindLabels
|
|
321
|
+
kindLabels: kindTable(input.kindLabels),
|
|
317
322
|
detail: input.detail ?? {},
|
|
318
|
-
validate: input.validate ??
|
|
323
|
+
validate: input.validate ?? noDataReview,
|
|
319
324
|
layoutEdge: input.layoutEdge ?? (() => false),
|
|
320
325
|
singleRoot: input.singleRoot ?? true,
|
|
321
326
|
rootLabel: input.rootLabel ?? "Overview"
|
|
@@ -972,21 +977,30 @@ var natural = (a2, b) => a2.localeCompare(b, void 0, { numeric: true });
|
|
|
972
977
|
function load(spec, opts = {}) {
|
|
973
978
|
const tree2 = readSpec(spec, opts.cwd);
|
|
974
979
|
const abs = path.resolve(opts.cwd ?? process.cwd(), spec);
|
|
980
|
+
let profileFile = "_profile.json";
|
|
975
981
|
if (fs.existsSync(abs) && !tree2.files.some((f) => f.path === "_profile.json")) {
|
|
976
982
|
const dir = tree2.isDir ? abs : path.dirname(abs);
|
|
977
983
|
const candidates = [path.join(dir, "_profile.json")];
|
|
978
984
|
if (/^\d+-/.test(path.basename(dir))) candidates.push(path.join(path.dirname(dir), "_profile.json"));
|
|
979
985
|
const file = candidates.find((p) => fs.existsSync(p));
|
|
980
|
-
if (file)
|
|
986
|
+
if (file) {
|
|
987
|
+
profileFile = path.relative(dir, file);
|
|
988
|
+
tree2.files.push({ path: "_profile.json", text: fs.readFileSync(file, "utf8") });
|
|
989
|
+
}
|
|
981
990
|
}
|
|
982
991
|
const metaErrors = [];
|
|
983
992
|
const meta = (name) => {
|
|
984
993
|
const f = tree2.files.find((x) => x.path === name);
|
|
985
994
|
if (!f) return null;
|
|
986
995
|
try {
|
|
987
|
-
|
|
996
|
+
const value = JSON.parse(f.text);
|
|
997
|
+
if (name === "_profile.json" && (!value || typeof value !== "object" || Array.isArray(value))) {
|
|
998
|
+
metaErrors.push({ file: name === "_profile.json" ? profileFile : name, message: "expected a profile object" });
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
return value;
|
|
988
1002
|
} catch (e) {
|
|
989
|
-
metaErrors.push({ file: name, message: `not JSON: ${e.message}` });
|
|
1003
|
+
metaErrors.push({ file: name === "_profile.json" ? profileFile : name, message: `not JSON: ${e.message}` });
|
|
990
1004
|
return null;
|
|
991
1005
|
}
|
|
992
1006
|
};
|
|
@@ -999,7 +1013,8 @@ function load(spec, opts = {}) {
|
|
|
999
1013
|
return null;
|
|
1000
1014
|
}
|
|
1001
1015
|
};
|
|
1002
|
-
const
|
|
1016
|
+
const embedded = bundled();
|
|
1017
|
+
const explicit = embedded ?? meta("_profile.json");
|
|
1003
1018
|
const data = tree2.files.filter((f) => !META.has(path.posix.basename(f.path)));
|
|
1004
1019
|
const isJson = (f) => /\.json$/i.test(f.path);
|
|
1005
1020
|
const dirs = [...new Set(data.filter((f) => f.path.includes("/")).map((f) => f.path.split("/")[0]))].sort(natural);
|
|
@@ -1015,10 +1030,11 @@ function load(spec, opts = {}) {
|
|
|
1015
1030
|
suggested ??= r.profile;
|
|
1016
1031
|
}
|
|
1017
1032
|
ignored.push(...r.skipped.map((p) => versioned ? `${g.name}/${p}` : p));
|
|
1018
|
-
return { name: g.name, sources: r.sources };
|
|
1033
|
+
return { name: g.name, sources: r.sources, format: r.adapter?.id ?? "native" };
|
|
1019
1034
|
});
|
|
1020
1035
|
return {
|
|
1021
1036
|
title: tree2.title,
|
|
1037
|
+
paletteTarget: embedded ? { file: tree2.files[0].path, field: "profile.nodePalette" } : { file: profileFile, field: "nodePalette" },
|
|
1022
1038
|
versions,
|
|
1023
1039
|
// A `_profile.json` that only carries demo metadata used to *replace* the adapter's profile, taking its palette
|
|
1024
1040
|
// with it: a converted graph then drew every kind as skeleton. Explicit keys win; the adapter fills the rest.
|
|
@@ -1040,7 +1056,7 @@ var DIFF_FLAG = {
|
|
|
1040
1056
|
merged: "gb-merged"
|
|
1041
1057
|
};
|
|
1042
1058
|
var KEPT_FLAG = "gb-kept";
|
|
1043
|
-
var
|
|
1059
|
+
var stable = (v, ignore) => {
|
|
1044
1060
|
const walk2 = (x) => {
|
|
1045
1061
|
if (Array.isArray(x)) return x.map(walk2);
|
|
1046
1062
|
if (x && typeof x === "object") {
|
|
@@ -1058,7 +1074,7 @@ function changedFields(a2, b, ignore) {
|
|
|
1058
1074
|
const ob = b ?? {};
|
|
1059
1075
|
const keys = new Set([...Object.keys(oa), ...Object.keys(ob)].filter((k) => !ignore.has(k)));
|
|
1060
1076
|
const out = [];
|
|
1061
|
-
for (const k of keys) if (
|
|
1077
|
+
for (const k of keys) if (stable(oa[k], ignore) !== stable(ob[k], ignore)) out.push(k);
|
|
1062
1078
|
return out.sort();
|
|
1063
1079
|
}
|
|
1064
1080
|
var EDIT_CAP = 512;
|
|
@@ -1093,10 +1109,17 @@ function editDistance(a2, b) {
|
|
|
1093
1109
|
return prev[m] + over;
|
|
1094
1110
|
}
|
|
1095
1111
|
function changeAmount(a2, b, fields, ignore) {
|
|
1096
|
-
const pick = (n) => fields.map((k) =>
|
|
1112
|
+
const pick = (n) => fields.map((k) => stable((n.data ?? {})[k], ignore)).join("\0");
|
|
1097
1113
|
return editDistance(pick(a2), pick(b)) + editDistance(a2.label ?? "", b.label ?? "");
|
|
1098
1114
|
}
|
|
1099
|
-
var edgeKey = (e) =>
|
|
1115
|
+
var edgeKey = (e) => JSON.stringify([e.source, e.target, e.kind ?? ""]);
|
|
1116
|
+
function edgeContent(edge) {
|
|
1117
|
+
const { source, target, from, to, kind, ...data } = edge.data ?? {};
|
|
1118
|
+
return { ...data, label: edge.label ?? data.label, weight: edge.weight ?? data.weight };
|
|
1119
|
+
}
|
|
1120
|
+
function edgeContentChanged(before, after, ignore) {
|
|
1121
|
+
return stable(edgeContent(before), ignore) !== stable(edgeContent(after), ignore);
|
|
1122
|
+
}
|
|
1100
1123
|
var withFlag = (x, flag) => ({ ...x, flags: [...x.flags ?? [], flag] });
|
|
1101
1124
|
function diffModels(before, after, opts = {}) {
|
|
1102
1125
|
const ignore = new Set(opts.ignore ?? []);
|
|
@@ -1112,9 +1135,9 @@ function diffModels(before, after, opts = {}) {
|
|
|
1112
1135
|
const afterByKey = /* @__PURE__ */ new Map();
|
|
1113
1136
|
for (const b of after.nodes) if (!afterByKey.has(keyOf(b))) afterByKey.set(keyOf(b), b);
|
|
1114
1137
|
const resolve = /* @__PURE__ */ new Map();
|
|
1115
|
-
for (const [k,
|
|
1138
|
+
for (const [k, list2] of beforeByKey) {
|
|
1116
1139
|
const b = afterByKey.get(k);
|
|
1117
|
-
if (b) resolve.set(
|
|
1140
|
+
if (b) resolve.set(list2[0].id, b.id);
|
|
1118
1141
|
}
|
|
1119
1142
|
const ref2 = (id) => id === void 0 ? void 0 : resolve.get(id) ?? id;
|
|
1120
1143
|
const consumed = new Set(resolve.keys());
|
|
@@ -1210,7 +1233,9 @@ function diffModels(before, after, opts = {}) {
|
|
|
1210
1233
|
);
|
|
1211
1234
|
const edges = [];
|
|
1212
1235
|
for (const [k, e] of afterEdges) {
|
|
1213
|
-
|
|
1236
|
+
const previous = beforeEdges.get(k);
|
|
1237
|
+
const flag = !previous ? DIFF_FLAG.added : edgeContentChanged(previous, e, ignore) ? DIFF_FLAG.changed : KEPT_FLAG;
|
|
1238
|
+
edges.push(withFlag(e, flag));
|
|
1214
1239
|
}
|
|
1215
1240
|
for (const [k, e] of beforeEdges) {
|
|
1216
1241
|
if (afterEdges.has(k)) continue;
|
|
@@ -1233,7 +1258,9 @@ function diffModels(before, after, opts = {}) {
|
|
|
1233
1258
|
prevData,
|
|
1234
1259
|
labels,
|
|
1235
1260
|
before,
|
|
1236
|
-
after
|
|
1261
|
+
after,
|
|
1262
|
+
ignore: opts.ignore,
|
|
1263
|
+
options: opts
|
|
1237
1264
|
};
|
|
1238
1265
|
}
|
|
1239
1266
|
|
|
@@ -1456,7 +1483,7 @@ var profile_schema_default = {
|
|
|
1456
1483
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1457
1484
|
$id: "https://unpkg.com/glassbrain/schema/profile.schema.json",
|
|
1458
1485
|
title: "glassbrain profile (_profile.json)",
|
|
1459
|
-
description: "The declarative part of a glassbrain profile, as a `_profile.json` next to the graph files. Everything is optional: with no profile a graph still renders (kinds without a color are drawn as skeleton). Layers are not configured here: they are derived from
|
|
1486
|
+
description: "The declarative part of a glassbrain profile, as a `_profile.json` next to the graph files. Everything is optional: with no profile a graph still renders (kinds without a color are drawn as skeleton). Layers are not configured here: they are derived from the order of children in the graph. Parsers, merge and domain validation are code and live in a TypeScript profile instead.",
|
|
1460
1487
|
type: "object",
|
|
1461
1488
|
properties: {
|
|
1462
1489
|
nodePalette: {
|
|
@@ -1496,7 +1523,7 @@ var profile_schema_default = {
|
|
|
1496
1523
|
properties: {
|
|
1497
1524
|
defaultLayers: {
|
|
1498
1525
|
type: "boolean",
|
|
1499
|
-
description: "Open with the layer (2.5D plane) view on when the graph has ordered siblings.
|
|
1526
|
+
description: "Open with the layer (2.5D plane) view on when the graph has ordered siblings. By default, opens layered when the graph has two or more floors."
|
|
1500
1527
|
},
|
|
1501
1528
|
layerColors: {
|
|
1502
1529
|
type: "array",
|
|
@@ -1639,9 +1666,9 @@ function checkSchema(root, value, limit = 50) {
|
|
|
1639
1666
|
}
|
|
1640
1667
|
if (typeOf(v) === "object") {
|
|
1641
1668
|
const o = v;
|
|
1642
|
-
for (const r of s.required ?? []) if (!(r
|
|
1669
|
+
for (const r of s.required ?? []) if (!Object.hasOwn(o, r)) out2.push({ path: path3, message: `missing "${r}"` });
|
|
1643
1670
|
for (const [k, val] of Object.entries(o)) {
|
|
1644
|
-
const sub = s.properties
|
|
1671
|
+
const sub = s.properties && Object.hasOwn(s.properties, k) ? s.properties[k] : typeof s.additionalProperties === "object" ? s.additionalProperties : null;
|
|
1645
1672
|
if (sub !== null && sub !== void 0) walk2(sub, val, `${path3}.${k}`, out2);
|
|
1646
1673
|
else if (s.additionalProperties === false) out2.push({ path: path3, message: `unknown field "${k}"` });
|
|
1647
1674
|
}
|
|
@@ -1658,6 +1685,32 @@ function checkSchema(root, value, limit = 50) {
|
|
|
1658
1685
|
return out;
|
|
1659
1686
|
}
|
|
1660
1687
|
|
|
1688
|
+
// src/shell.ts
|
|
1689
|
+
var shellArg = (s) => "'" + s.replace(/'/g, `'"'"'`) + "'";
|
|
1690
|
+
|
|
1691
|
+
// src/kinds.ts
|
|
1692
|
+
function kindDistribution(items) {
|
|
1693
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1694
|
+
for (const item of items) if (item.kind) counts.set(item.kind, (counts.get(item.kind) ?? 0) + 1);
|
|
1695
|
+
const sizes = [...counts].map(([kind, count2]) => ({ kind, count: count2 })).sort((a2, b) => b.count - a2.count || a2.kind.localeCompare(b.kind));
|
|
1696
|
+
const typed = sizes.reduce((sum, row) => sum + row.count, 0);
|
|
1697
|
+
const effective = sizes.reduce((sum, row) => sum + Math.sqrt(row.count / typed), 0) ** 2;
|
|
1698
|
+
const fragmentation = typed > 1 ? effective / Math.log(typed) : 0;
|
|
1699
|
+
return {
|
|
1700
|
+
total: items.length,
|
|
1701
|
+
typed,
|
|
1702
|
+
missing: items.length - typed,
|
|
1703
|
+
count: sizes.length,
|
|
1704
|
+
sizes,
|
|
1705
|
+
effective,
|
|
1706
|
+
fragmentation,
|
|
1707
|
+
reason: typed >= 10 && fragmentation > 2 ? "too fragmented" : null
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
function kindHeading(space, d) {
|
|
1711
|
+
return `${space} kinds: ${d.count}${d.reason ? ` (${d.reason})` : ""}`;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1661
1714
|
// cli/shape.ts
|
|
1662
1715
|
var rounded = (x) => +x.toFixed(6);
|
|
1663
1716
|
function analyzeShape(nodes) {
|
|
@@ -1876,10 +1929,8 @@ function analyzeShape(nodes) {
|
|
|
1876
1929
|
}
|
|
1877
1930
|
|
|
1878
1931
|
// cli/checks.ts
|
|
1879
|
-
var
|
|
1880
|
-
var WIDE_WARN = 10;
|
|
1932
|
+
var WIDE_WARN = 5;
|
|
1881
1933
|
var MAX_NAMES = 4;
|
|
1882
|
-
var MIN_SAMPLE = 10;
|
|
1883
1934
|
var names = (xs) => `${xs.slice(0, MAX_NAMES).join(", ")}${xs.length > MAX_NAMES ? ` and ${xs.length - MAX_NAMES} more` : ""}`;
|
|
1884
1935
|
var misplacedField = {
|
|
1885
1936
|
code: "schema",
|
|
@@ -1894,6 +1945,8 @@ var misplacedField = {
|
|
|
1894
1945
|
if (!found.length) continue;
|
|
1895
1946
|
out.push({
|
|
1896
1947
|
node: n.id,
|
|
1948
|
+
where: n.origins?.length === 1 ? n.origin : void 0,
|
|
1949
|
+
facts: { type: "misplaced", fields: found },
|
|
1897
1950
|
message: `"${n.id}" keeps ${found.map((k) => `"${k}"`).join(", ")} under "data"; only top-level fields are read`,
|
|
1898
1951
|
fix: `move ${found.length > 1 ? "them" : "it"} up one level, next to "id":
|
|
1899
1952
|
- { "id": "${n.id}", "data": { ${found.map((k) => `"${k}": \u2026`).join(", ")} } }
|
|
@@ -1975,16 +2028,16 @@ var conflictingDefinition = {
|
|
|
1975
2028
|
var danglingEdge = {
|
|
1976
2029
|
code: "dangling-edge",
|
|
1977
2030
|
level: "error",
|
|
1978
|
-
run: ({ model, index
|
|
2031
|
+
run: ({ model, index }) => {
|
|
1979
2032
|
const out = [];
|
|
1980
2033
|
for (const e of model.edges) {
|
|
1981
|
-
const missing = [
|
|
1982
|
-
if (!missing) continue;
|
|
2034
|
+
const missing = [...new Set([e.source, e.target].filter((id) => !index.has(id)))];
|
|
2035
|
+
if (!missing.length) continue;
|
|
1983
2036
|
out.push({
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2037
|
+
where: e.origin,
|
|
2038
|
+
facts: { type: "dangling", source: e.source, target: e.target, kind: e.kind, missing },
|
|
2039
|
+
message: `${e.source} \u2192 ${e.target}: missing ${missing.join(", ")}`,
|
|
2040
|
+
fix: "Add the missing node or correct the endpoint ID."
|
|
1988
2041
|
});
|
|
1989
2042
|
}
|
|
1990
2043
|
return out;
|
|
@@ -1993,20 +2046,32 @@ var danglingEdge = {
|
|
|
1993
2046
|
var duplicateEdge = {
|
|
1994
2047
|
code: "duplicate-edge",
|
|
1995
2048
|
level: "warn",
|
|
1996
|
-
run: ({ model }) => {
|
|
1997
|
-
const
|
|
2049
|
+
run: ({ model, prefix }) => {
|
|
2050
|
+
const copies = /* @__PURE__ */ new Map();
|
|
1998
2051
|
for (const e of model.edges) {
|
|
1999
|
-
const key =
|
|
2000
|
-
|
|
2052
|
+
const key = JSON.stringify([e.source, e.target, e.kind ?? ""]);
|
|
2053
|
+
const group = copies.get(key);
|
|
2054
|
+
if (group) group.push(e);
|
|
2055
|
+
else copies.set(key, [e]);
|
|
2001
2056
|
}
|
|
2002
2057
|
const out = [];
|
|
2003
|
-
for (const
|
|
2004
|
-
if (
|
|
2005
|
-
const
|
|
2058
|
+
for (const edges of copies.values()) {
|
|
2059
|
+
if (edges.length < 2) continue;
|
|
2060
|
+
const { source, target, kind } = edges[0];
|
|
2061
|
+
const files = [...new Set(edges.flatMap((e) => e.origin ? [prefix + e.origin] : []))].sort();
|
|
2062
|
+
const records = edges.map((e) => ({ ...e.data, ...e.label !== void 0 ? { label: e.label } : {}, ...e.weight !== void 0 ? { weight: e.weight } : {} }));
|
|
2063
|
+
const differences = [...new Set(records.flatMap(Object.keys))].flatMap((field) => {
|
|
2064
|
+
const copies2 = records.map((r, i) => ({
|
|
2065
|
+
file: edges[i].origin ? prefix + edges[i].origin : void 0,
|
|
2066
|
+
value: Object.hasOwn(r, field) ? stableJson(r[field]) : void 0
|
|
2067
|
+
}));
|
|
2068
|
+
return new Set(copies2.map((c) => c.value)).size > 1 ? [{ field, copies: copies2 }] : [];
|
|
2069
|
+
});
|
|
2070
|
+
const differing = differences.length > 0;
|
|
2006
2071
|
out.push({
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2072
|
+
facts: { type: "duplicate", source, target, kind, count: edges.length, files, differing, ...differing ? { differences } : {} },
|
|
2073
|
+
message: `${source} \u2192 ${target}${kind ? ` (${kind})` : ""} appears ${edges.length} times`,
|
|
2074
|
+
fix: differing ? "Compare the differing attributes and combine the intended values in one entry." : "Keep one copy of this relation."
|
|
2010
2075
|
});
|
|
2011
2076
|
}
|
|
2012
2077
|
return out;
|
|
@@ -2014,14 +2079,12 @@ var duplicateEdge = {
|
|
|
2014
2079
|
};
|
|
2015
2080
|
var unevenKinds = {
|
|
2016
2081
|
code: "bad-structure",
|
|
2017
|
-
level: "
|
|
2082
|
+
level: "warn",
|
|
2018
2083
|
run: ({ model }) => analyzeShape(model.nodes).branches.filter((b) => b.score >= 0.2).sort((a2, b) => b.score - a2.score).map((b) => ({
|
|
2019
2084
|
node: b.parent,
|
|
2020
|
-
|
|
2021
|
-
message: `"${b.parent}"
|
|
2022
|
-
fix: `
|
|
2023
|
-
closest compared pair: ${b.closest?.a} / ${b.closest?.b} (distance ${b.closest?.distance}). Differences can be intentional.
|
|
2024
|
-
glassbrain restructure <path> --dry-run --json shows grouping suggestions; no content is deleted.`
|
|
2085
|
+
facts: { type: "uneven", closest: b.closest },
|
|
2086
|
+
message: `Sibling branches under "${b.parent}" differ in shape.`,
|
|
2087
|
+
fix: `Inspect ${b.closest?.a} and ${b.closest?.b} with glassbrain tree <path> --path ${shellArg(b.parent)}. Group them only if they share a subject.`
|
|
2025
2088
|
}))
|
|
2026
2089
|
};
|
|
2027
2090
|
var wideNode = {
|
|
@@ -2029,19 +2092,16 @@ var wideNode = {
|
|
|
2029
2092
|
level: "warn",
|
|
2030
2093
|
run: ({ children, labelOf, layers }) => {
|
|
2031
2094
|
const out = [];
|
|
2032
|
-
|
|
2095
|
+
const wideParents = [...children].filter(([, kids]) => kids.length > WIDE_WARN).sort(([, a2], [, b]) => b.length - a2.length);
|
|
2096
|
+
for (const [id, kids] of wideParents) {
|
|
2033
2097
|
const n = kids.length;
|
|
2034
|
-
if (n <= WIDE_INFO) continue;
|
|
2035
|
-
const level = n > WIDE_WARN ? "warn" : "info";
|
|
2036
2098
|
const isAnchor = layers.anchor === id;
|
|
2037
2099
|
const what = isAnchor ? `${n} layers` : `${n} children`;
|
|
2038
2100
|
out.push({
|
|
2039
|
-
level,
|
|
2040
2101
|
node: id,
|
|
2102
|
+
facts: { type: "wide", count: n, layers: isAnchor },
|
|
2041
2103
|
message: `"${labelOf(id)}" holds ${what}; ${isAnchor ? "review whether each floor is a major section" : "review whether this is one natural collection"}`,
|
|
2042
|
-
fix: `
|
|
2043
|
-
glassbrain restructure <path> --dry-run shows candidate groups and their ids.
|
|
2044
|
-
Prefer fewer than 5 children per group; this is guidance, not a quota. Keep a natural collection together; add a named group only when it explains membership.${isAnchor ? "\n Each root child can be shown as a floor; use the view switch to read them together." : ""}`
|
|
2104
|
+
fix: `Inspect glassbrain tree <path> --path ${shellArg(id)}. ${isAnchor ? "Keep major sections as floors." : "Group by subject where useful."}`
|
|
2045
2105
|
});
|
|
2046
2106
|
}
|
|
2047
2107
|
return out;
|
|
@@ -2049,61 +2109,29 @@ var wideNode = {
|
|
|
2049
2109
|
};
|
|
2050
2110
|
var uncoloredKind = {
|
|
2051
2111
|
code: "uncolored-kind",
|
|
2052
|
-
level: "
|
|
2053
|
-
run: ({ model, profile }) => {
|
|
2112
|
+
level: "warn",
|
|
2113
|
+
run: ({ model, profile, paletteTarget }) => {
|
|
2054
2114
|
const used = [...new Set(model.nodes.map((n) => n.kind).filter((k) => !!k))];
|
|
2055
|
-
const missing = used.filter((k) => !(
|
|
2115
|
+
const missing = used.filter((k) => !Object.hasOwn(profile.nodePalette, k));
|
|
2056
2116
|
if (!missing.length) return [];
|
|
2057
|
-
const shown = missing.slice(0, 5);
|
|
2058
|
-
const palette = Object.fromEntries(shown.map((k, i) => [k, ["#6366f1", "#f59e0b", "#10b981", "#ef4444", "#8b5cf6"][i % 5]]));
|
|
2059
2117
|
return [{
|
|
2118
|
+
facts: { type: "palette", kinds: missing, target: paletteTarget },
|
|
2060
2119
|
message: `${missing.length} node kind${missing.length > 1 ? "s are" : " is"} not in nodePalette, so ${missing.length > 1 ? "they are" : "it is"} drawn as skeleton: ${names(missing)}`,
|
|
2061
|
-
fix: `
|
|
2062
|
-
{ "nodePalette": ${JSON.stringify(palette)} }
|
|
2063
|
-
${missing.length > shown.length ? ` \u2026 and ${missing.length - shown.length} more; every kind in the data needs an entry.
|
|
2064
|
-
` : ""} Colors that land closer than 10 in Lab distance read as one kind (lint notes it).`
|
|
2065
|
-
}];
|
|
2066
|
-
}
|
|
2067
|
-
};
|
|
2068
|
-
var singleKind = {
|
|
2069
|
-
code: "single-kind",
|
|
2070
|
-
level: "info",
|
|
2071
|
-
run: ({ model }) => {
|
|
2072
|
-
const used = new Set(model.nodes.map((n) => n.kind).filter(Boolean));
|
|
2073
|
-
if (used.size !== 1 || model.nodes.length < MIN_SAMPLE) return [];
|
|
2074
|
-
return [{
|
|
2075
|
-
message: `every node has kind "${[...used][0]}"; check whether this is one natural category`,
|
|
2076
|
-
fix: `keep one kind for genuinely similar things. Introduce another only when it expresses a useful distinction; counts alone do not justify it.`
|
|
2120
|
+
fix: `Add a distinct color for each missing kind in ${paletteTarget?.file ?? "_profile.json"} under ${paletteTarget?.field ?? "nodePalette"}.`
|
|
2077
2121
|
}];
|
|
2078
2122
|
}
|
|
2079
2123
|
};
|
|
2080
2124
|
var kindNote = {
|
|
2081
2125
|
code: "kind-note",
|
|
2082
|
-
level: "
|
|
2083
|
-
run: ({ model }) => {
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
message: `${space} kinds: ${kinds} (${average.toFixed(1)} per kind); around 8 colors and repeated kinds are easier to scan, but counts are advisory`,
|
|
2092
|
-
fix: `inspect whether kinds express distinct meanings. Preserve precise relation kinds and meaningful rare categories; merge only synonyms.`
|
|
2093
|
-
});
|
|
2094
|
-
}
|
|
2095
|
-
};
|
|
2096
|
-
const lone = (space, counts, total) => {
|
|
2097
|
-
if (total < MIN_SAMPLE) return;
|
|
2098
|
-
const once = [...counts].filter(([, c]) => c === 1).map(([k]) => k);
|
|
2099
|
-
if (once.length) out.push({ message: `${once.length} ${space} kind${once.length > 1 ? "s" : ""} used once: ${names(once)}`, fix: `keep a rare kind when its meaning is distinct; do not add instances merely to meet a count.` });
|
|
2100
|
-
};
|
|
2101
|
-
spread("node", countsBy(model.nodes.map((n) => n.kind)), model.nodes.length);
|
|
2102
|
-
spread("edge", countsBy(model.edges.map((e) => e.kind)), model.edges.length);
|
|
2103
|
-
lone("node", countsBy(model.nodes.map((n) => n.kind)), model.nodes.length);
|
|
2104
|
-
lone("edge", countsBy(model.edges.map((e) => e.kind)), model.edges.length);
|
|
2105
|
-
return out;
|
|
2106
|
-
}
|
|
2126
|
+
level: "warn",
|
|
2127
|
+
run: ({ model }) => ["node", "edge"].flatMap((space) => {
|
|
2128
|
+
const d = kindDistribution(space === "node" ? model.nodes : model.edges);
|
|
2129
|
+
return d.reason ? [{
|
|
2130
|
+
facts: { type: "vocabulary", space, kinds: d.sizes.map((row) => row.kind) },
|
|
2131
|
+
message: `${kindHeading(space, d)}; ${d.typed} typed ${space}s`,
|
|
2132
|
+
fix: "Merge synonymous kinds. Keep distinct meanings, including rare ones."
|
|
2133
|
+
}] : [];
|
|
2134
|
+
})
|
|
2107
2135
|
};
|
|
2108
2136
|
var lowCoverage = {
|
|
2109
2137
|
code: "coverage-note",
|
|
@@ -2111,19 +2139,19 @@ var lowCoverage = {
|
|
|
2111
2139
|
run: ({ model, children }) => {
|
|
2112
2140
|
const leaves = model.nodes.filter((n) => !children.has(n.id));
|
|
2113
2141
|
if (leaves.length < 20) return [];
|
|
2114
|
-
const
|
|
2115
|
-
if (
|
|
2142
|
+
const missing = leaves.filter((n) => !(typeof n.data?.description === "string" && n.data.description.trim())).map((n) => n.id);
|
|
2143
|
+
if (missing.length <= leaves.length / 2) return [];
|
|
2116
2144
|
return [{
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2145
|
+
facts: { type: "coverage", leaves: missing },
|
|
2146
|
+
message: `${missing.length} of ${leaves.length} leaves have no description`,
|
|
2147
|
+
fix: "Add a sentence in each leaf\u2019s description."
|
|
2120
2148
|
}];
|
|
2121
2149
|
}
|
|
2122
2150
|
};
|
|
2123
2151
|
var colorNote = {
|
|
2124
2152
|
code: "color-note",
|
|
2125
2153
|
level: "info",
|
|
2126
|
-
run: ({ profile }) => {
|
|
2154
|
+
run: ({ profile, paletteTarget }) => {
|
|
2127
2155
|
const colors = Object.entries(profile.nodePalette).map(([kind, hex]) => ({ kind, lab: hexLab(hex) }));
|
|
2128
2156
|
const usable = colors.filter((c) => c.lab !== null);
|
|
2129
2157
|
if (usable.length < 6) return [];
|
|
@@ -2136,6 +2164,7 @@ var colorNote = {
|
|
|
2136
2164
|
}
|
|
2137
2165
|
if (worst.d >= 10) return [];
|
|
2138
2166
|
return [{
|
|
2167
|
+
facts: { type: "colors", kinds: [worst.a, worst.b], target: paletteTarget },
|
|
2139
2168
|
message: `"${worst.a}" and "${worst.b}" are ${worst.d.toFixed(1)} apart in color (under 10 reads as the same kind)`,
|
|
2140
2169
|
fix: `push them apart in lightness, not just hue:
|
|
2141
2170
|
"${worst.a}": darker \u2192 e.g. #4338ca
|
|
@@ -2155,7 +2184,6 @@ var rules = [
|
|
|
2155
2184
|
unevenKinds,
|
|
2156
2185
|
wideNode,
|
|
2157
2186
|
uncoloredKind,
|
|
2158
|
-
singleKind,
|
|
2159
2187
|
kindNote,
|
|
2160
2188
|
colorNote,
|
|
2161
2189
|
lowCoverage
|
|
@@ -2169,6 +2197,8 @@ function checkGraph(model, profile, opts) {
|
|
|
2169
2197
|
else children.set(n.parent, [n]);
|
|
2170
2198
|
}
|
|
2171
2199
|
const ctx = {
|
|
2200
|
+
paletteTarget: opts.paletteTarget,
|
|
2201
|
+
prefix: opts.prefix ?? "",
|
|
2172
2202
|
model,
|
|
2173
2203
|
profile,
|
|
2174
2204
|
where: opts.where,
|
|
@@ -2178,10 +2208,13 @@ function checkGraph(model, profile, opts) {
|
|
|
2178
2208
|
labelOf: (id) => model.index.get(id)?.label ?? id
|
|
2179
2209
|
};
|
|
2180
2210
|
const invalidStructure = unknownParent.run(ctx).length > 0 || parentCycle.run(ctx).length > 0;
|
|
2181
|
-
const
|
|
2211
|
+
const applicable = opts.quality === false ? rules.filter((rule) => rule.level === "error") : rules;
|
|
2212
|
+
const out = applicable.filter((rule) => !invalidStructure || rule !== unevenKinds).flatMap((rule) => rule.run(ctx).map((issue) => ({
|
|
2182
2213
|
level: issue.level ?? rule.level,
|
|
2183
2214
|
code: rule.code,
|
|
2184
|
-
where: opts.
|
|
2215
|
+
scope: issue.where ? void 0 : opts.prefix ? "version" : "graph",
|
|
2216
|
+
where: issue.where ? (opts.prefix ?? "") + issue.where : opts.where,
|
|
2217
|
+
...issue.facts ? { facts: issue.facts } : {},
|
|
2185
2218
|
message: issue.message,
|
|
2186
2219
|
...issue.fix !== void 0 ? { fix: issue.fix } : {},
|
|
2187
2220
|
...issue.node !== void 0 ? { node: issue.node } : {}
|
|
@@ -2221,11 +2254,6 @@ function structureOf(model) {
|
|
|
2221
2254
|
ordered: derived.layers.length > 0 || [...children.keys()].some((id) => orderedChildren(children, id, model.index.get(id)?.data?.unordered === true) !== null)
|
|
2222
2255
|
};
|
|
2223
2256
|
}
|
|
2224
|
-
function countsBy(values) {
|
|
2225
|
-
const out = /* @__PURE__ */ new Map();
|
|
2226
|
-
for (const v of values) if (v) out.set(v, (out.get(v) ?? 0) + 1);
|
|
2227
|
-
return out;
|
|
2228
|
-
}
|
|
2229
2257
|
function hexLab(value) {
|
|
2230
2258
|
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(value.trim());
|
|
2231
2259
|
if (!m) return null;
|
|
@@ -2244,9 +2272,10 @@ function deltaE(a2, b) {
|
|
|
2244
2272
|
|
|
2245
2273
|
// cli/model.ts
|
|
2246
2274
|
function profileFromJson(id, json) {
|
|
2247
|
-
if (!json) return defineProfile({ id });
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2275
|
+
if (!json || checkSchema(profile_schema_default, json, 1).length) return defineProfile({ id });
|
|
2276
|
+
const fields = Object.fromEntries(Object.entries(json).filter(([key]) => Object.hasOwn(profile_schema_default.properties, key)));
|
|
2277
|
+
const kindLabels = { ...json.kindLabels, ...json.edgeLabels };
|
|
2278
|
+
return defineProfile({ id, ...fields, kindLabels });
|
|
2250
2279
|
}
|
|
2251
2280
|
function profileOf(l) {
|
|
2252
2281
|
const json = l.profile;
|
|
@@ -2264,48 +2293,58 @@ function derivedProfile(base2, sources, json, force) {
|
|
|
2264
2293
|
}
|
|
2265
2294
|
var modelOf = (v, profile) => parseSources(v.sources, profile);
|
|
2266
2295
|
var RANK = { error: 0, warn: 1, info: 2 };
|
|
2267
|
-
function
|
|
2296
|
+
function inspectProfile(json, file = "_profile.json") {
|
|
2297
|
+
if (!json) return [];
|
|
2298
|
+
const out = checkSchema(profile_schema_default, json).map((e) => ({ level: "error", code: "schema", where: file, message: `${e.path}: ${e.message}` }));
|
|
2299
|
+
if (typeof json !== "object" || Array.isArray(json)) return out;
|
|
2300
|
+
const retired = ["layers", "singleRoot"].filter((k) => k in json);
|
|
2301
|
+
if (retired.length) out.push({
|
|
2302
|
+
level: "warn",
|
|
2303
|
+
code: "schema",
|
|
2304
|
+
where: file,
|
|
2305
|
+
message: `${retired.map((k) => `"${k}"`).join(" and ")} no longer configure anything: layers come from the ordered children structure`,
|
|
2306
|
+
fix: 'Remove the retired keys from the profile. Use "appearance": { "defaultLayers": false } to open flat.'
|
|
2307
|
+
});
|
|
2308
|
+
return out;
|
|
2309
|
+
}
|
|
2310
|
+
function inspectGraph(model, profile, sources, opts) {
|
|
2268
2311
|
const out = [];
|
|
2269
|
-
const
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
}
|
|
2312
|
+
const prefix = opts.prefix ?? "";
|
|
2313
|
+
const notJson = /* @__PURE__ */ new Set();
|
|
2314
|
+
if (opts.native !== false) for (const f of sources) {
|
|
2315
|
+
let doc;
|
|
2316
|
+
try {
|
|
2317
|
+
doc = JSON.parse(f.text);
|
|
2318
|
+
} catch (e) {
|
|
2319
|
+
notJson.add(f.origin);
|
|
2320
|
+
out.push({ level: "error", code: "schema", where: prefix + f.origin, message: `not JSON: ${e.message}` });
|
|
2321
|
+
continue;
|
|
2322
|
+
}
|
|
2323
|
+
if (!doc || typeof doc !== "object" || !("nodes" in doc) && !("edges" in doc)) {
|
|
2324
|
+
out.push({ level: "warn", code: "schema", where: prefix + f.origin, message: 'not a graph (no "nodes" or "edges"), skipped' });
|
|
2325
|
+
continue;
|
|
2326
|
+
}
|
|
2327
|
+
for (const e of checkSchema(graph_schema_default, doc)) out.push({ level: "error", code: "schema", where: prefix + f.origin, message: `${e.path}: ${e.message}` });
|
|
2280
2328
|
}
|
|
2329
|
+
for (const e of model.errors) if (!notJson.has(e.origin)) out.push({ level: "error", code: e.code ?? "schema", where: prefix + e.origin, message: e.message, node: e.node });
|
|
2330
|
+
out.push(...checkGraph(model, profile, { where: opts.where, prefix, paletteTarget: opts.paletteTarget, quality: opts.quality }));
|
|
2331
|
+
if (!model.nodes.length) out.push({ level: "warn", code: "schema", where: opts.where, scope: prefix ? "version" : "graph", message: "No nodes found" });
|
|
2332
|
+
return out.sort((a2, b) => RANK[a2.level] - RANK[b.level]);
|
|
2333
|
+
}
|
|
2334
|
+
function lint(loaded) {
|
|
2335
|
+
const out = inspectProfile(loaded.profile, loaded.paletteTarget?.file);
|
|
2336
|
+
const profile = profileOf(loaded);
|
|
2281
2337
|
for (const e of loaded.metaErrors) out.push({ level: "error", code: "schema", where: e.file, message: e.message });
|
|
2282
2338
|
const latest = loaded.raw[loaded.raw.length - 1]?.version;
|
|
2283
2339
|
for (const { version, files } of loaded.raw) {
|
|
2284
2340
|
const prefix = loaded.versions.length > 1 ? `${version}/` : "";
|
|
2285
|
-
const notJson = /* @__PURE__ */ new Set();
|
|
2286
|
-
if (loaded.format === "native") {
|
|
2287
|
-
for (const f of files) {
|
|
2288
|
-
if (!/\.json$/i.test(f.path)) continue;
|
|
2289
|
-
let doc;
|
|
2290
|
-
try {
|
|
2291
|
-
doc = JSON.parse(f.text);
|
|
2292
|
-
} catch (e) {
|
|
2293
|
-
notJson.add(f.path);
|
|
2294
|
-
out.push({ level: "error", code: "schema", where: prefix + f.path, message: `not JSON: ${e.message}` });
|
|
2295
|
-
continue;
|
|
2296
|
-
}
|
|
2297
|
-
if (!doc || typeof doc !== "object" || !("nodes" in doc) && !("edges" in doc)) {
|
|
2298
|
-
out.push({ level: "warn", code: "schema", where: prefix + f.path, message: 'not a graph (no "nodes" or "edges"), skipped' });
|
|
2299
|
-
continue;
|
|
2300
|
-
}
|
|
2301
|
-
for (const e of checkSchema(graph_schema_default, doc)) out.push({ level: "error", code: "schema", where: prefix + f.path, message: `${e.path}: ${e.message}` });
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
2341
|
const v = loaded.versions.find((x) => x.name === version);
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2342
|
+
out.push(...inspectGraph(
|
|
2343
|
+
modelOf(v, profile),
|
|
2344
|
+
profile,
|
|
2345
|
+
files.filter((f) => /\.json$/i.test(f.path)).map((f) => ({ origin: f.path, text: f.text })),
|
|
2346
|
+
{ where: prefix || loaded.title, prefix, paletteTarget: loaded.paletteTarget, native: (v.format ?? loaded.format) === "native", quality: version === latest }
|
|
2347
|
+
));
|
|
2309
2348
|
}
|
|
2310
2349
|
return out.sort((a2, b) => RANK[a2.level] - RANK[b.level]);
|
|
2311
2350
|
}
|
|
@@ -2355,22 +2394,181 @@ function diffText(s, labelOf, limit = 20) {
|
|
|
2355
2394
|
L.push(`edges: +${s.edges.added} \u2212${s.edges.removed} (${s.edges.kept} unchanged)`);
|
|
2356
2395
|
const SIGN = { added: "+", removed: "\u2212", changed: "~", moved: "\u21B7", merged: "\u21C9" };
|
|
2357
2396
|
for (const kind of ["added", "removed", "changed", "moved", "merged"]) {
|
|
2358
|
-
const
|
|
2359
|
-
if (!
|
|
2360
|
-
L.push("", `${kind} (${
|
|
2361
|
-
for (const c of
|
|
2362
|
-
if (
|
|
2397
|
+
const list2 = s.changes.filter((c) => c.kind === kind);
|
|
2398
|
+
if (!list2.length) continue;
|
|
2399
|
+
L.push("", `${kind} (${list2.length})`);
|
|
2400
|
+
for (const c of list2.slice(0, limit)) L.push(` ${SIGN[kind]} ${c.label}${c.label !== c.id ? ` [${c.id}]` : ""}${c.detail ? ` \u2014 ${c.detail}` : ""}`);
|
|
2401
|
+
if (list2.length > limit) L.push(` \u2026 ${list2.length - limit} more (--all)`);
|
|
2363
2402
|
}
|
|
2364
2403
|
for (const kind of ["added", "removed"]) {
|
|
2365
|
-
const
|
|
2366
|
-
if (!
|
|
2367
|
-
L.push("", `edges ${kind} (${
|
|
2368
|
-
for (const e of
|
|
2369
|
-
if (
|
|
2404
|
+
const list2 = s.edgeChanges.filter((e) => e.kind === kind);
|
|
2405
|
+
if (!list2.length) continue;
|
|
2406
|
+
L.push("", `edges ${kind} (${list2.length})`);
|
|
2407
|
+
for (const e of list2.slice(0, limit)) L.push(` ${kind === "added" ? "+" : "\u2212"} ${labelOf(e.source)} \u2192 ${labelOf(e.target)}${e.relation ? ` (${e.relation})` : ""}`);
|
|
2408
|
+
if (list2.length > limit) L.push(` \u2026 ${list2.length - limit} more (--all)`);
|
|
2370
2409
|
}
|
|
2371
2410
|
return L.join("\n");
|
|
2372
2411
|
}
|
|
2373
2412
|
|
|
2413
|
+
// src/lint-report.ts
|
|
2414
|
+
var headings = {
|
|
2415
|
+
"bad-structure": "Sibling subtrees differ in shape or node kind.",
|
|
2416
|
+
"wide-node": "These parent nodes have many direct children.",
|
|
2417
|
+
"duplicate-edge": "Multiple edge records have the same source ID, kind and target ID.",
|
|
2418
|
+
"dangling-edge": "An edge references a missing node ID. Add the node or correct the endpoint.",
|
|
2419
|
+
"field-conflict": "Choose one value for the conflicting node field.",
|
|
2420
|
+
"children-conflict": "Use the same ordered child IDs in each declaration, with each child listed once.",
|
|
2421
|
+
"parent-error": "Repair the parent\u2013child placement.",
|
|
2422
|
+
"duplicate-id": "Resolve conflicting definitions of a node ID.",
|
|
2423
|
+
"schema": "Check the named fields against the graph or profile format.",
|
|
2424
|
+
"kind-note": "Review kind names. Merge synonyms and keep distinct meanings.",
|
|
2425
|
+
"uncolored-kind": "Assign a distinct color to each listed node kind.",
|
|
2426
|
+
"coverage-note": "These leaf nodes have no `description`. Add a sentence explaining each one.",
|
|
2427
|
+
"color-note": "These node kinds have similar colors. Make one lighter or darker."
|
|
2428
|
+
};
|
|
2429
|
+
function delimiter(text, minimum) {
|
|
2430
|
+
let length = minimum;
|
|
2431
|
+
for (const run of text.matchAll(/`+/g)) length = Math.max(length, run[0].length + 1);
|
|
2432
|
+
return "`".repeat(length);
|
|
2433
|
+
}
|
|
2434
|
+
function codeBlock(text, indent, language = "") {
|
|
2435
|
+
const fence = delimiter(text, 3);
|
|
2436
|
+
return [indent + fence + language, ...text.split("\n").map((line) => indent + line), indent + fence];
|
|
2437
|
+
}
|
|
2438
|
+
function literal(value) {
|
|
2439
|
+
const text = /[\u0000-\u001f]|^\s|\s$|^$/.test(value) ? JSON.stringify(value) : value;
|
|
2440
|
+
const fence = delimiter(text, 1);
|
|
2441
|
+
const pad = text.startsWith("`") || text.endsWith("`") ? " " : "";
|
|
2442
|
+
return fence + pad + text + pad + fence;
|
|
2443
|
+
}
|
|
2444
|
+
function plain(value) {
|
|
2445
|
+
return value.replace(/[\\`*_\[\]<>#&~!|]/g, "\\$&").replace(/[\r\n]+/g, " ");
|
|
2446
|
+
}
|
|
2447
|
+
var list = (values) => values.map(literal).join(", ");
|
|
2448
|
+
function groupBy(items, keyOf) {
|
|
2449
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2450
|
+
for (const item of items) {
|
|
2451
|
+
const key = keyOf(item);
|
|
2452
|
+
const group = groups.get(key);
|
|
2453
|
+
if (group) group.push(item);
|
|
2454
|
+
else groups.set(key, [item]);
|
|
2455
|
+
}
|
|
2456
|
+
return groups;
|
|
2457
|
+
}
|
|
2458
|
+
function duplicateLines(edges) {
|
|
2459
|
+
const lines = [];
|
|
2460
|
+
const batches = [...groupBy(edges, (e) => JSON.stringify([e.differing, e.count, e.files])).values()];
|
|
2461
|
+
for (const group of batches.sort((a2, b) => Number(b[0].differing) - Number(a2[0].differing))) {
|
|
2462
|
+
const { differing, count: count2, files } = group[0];
|
|
2463
|
+
const redundant = group.length * (count2 - 1);
|
|
2464
|
+
const action = differing ? "Attributes differ. Decide which values to retain before merging." : `Remove ${redundant} identical ${redundant === 1 ? "copy" : "copies"}, leaving one record per edge.`;
|
|
2465
|
+
lines.push(` - ${group.length} ${group.length === 1 ? "edge" : "edges"}, ${count2} copies each${files.length ? (files.length === 1 ? " in " : " across ") + list(files) : ""}. ${action}`);
|
|
2466
|
+
for (const [source, outgoing] of groupBy(group, (e) => e.source)) {
|
|
2467
|
+
const targets = [...groupBy(outgoing, (e) => JSON.stringify(e.kind ?? null)).values()].map((sameKind) => {
|
|
2468
|
+
const kind = sameKind[0].kind;
|
|
2469
|
+
return `${kind === void 0 ? "(no kind)" : literal(kind)} \u2192 ${list(sameKind.map((e) => e.target))}`;
|
|
2470
|
+
});
|
|
2471
|
+
lines.push(` - From node ID ${literal(source)}: ${targets.join(" | ")}`);
|
|
2472
|
+
for (const edge of outgoing) for (const diff2 of edge.differences ?? []) {
|
|
2473
|
+
const values = diff2.copies.map((c) => (c.value === void 0 ? "(absent)" : literal(c.value)) + (c.file ? " in " + literal(c.file) : ""));
|
|
2474
|
+
lines.push(` - ${edge.kind ? "Kind " + literal(edge.kind) + ", " : ""}target ID ${literal(edge.target)}, field ${literal(diff2.field)}: ${values.join(" / ")}.`);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
return lines;
|
|
2479
|
+
}
|
|
2480
|
+
function ruleLines(rows, input) {
|
|
2481
|
+
const lines = [];
|
|
2482
|
+
const duplicates = [];
|
|
2483
|
+
const uneven = [];
|
|
2484
|
+
for (const f of rows) {
|
|
2485
|
+
const d = f.facts;
|
|
2486
|
+
const place = f.where && f.scope !== "graph" ? literal(f.where) : "";
|
|
2487
|
+
const location = place ? " in " + (f.scope === "version" ? "version " : "") + place : "";
|
|
2488
|
+
switch (d?.type) {
|
|
2489
|
+
case "duplicate":
|
|
2490
|
+
duplicates.push(d);
|
|
2491
|
+
break;
|
|
2492
|
+
case "uneven":
|
|
2493
|
+
uneven.push(f);
|
|
2494
|
+
break;
|
|
2495
|
+
case "wide":
|
|
2496
|
+
lines.push(` - Node ID ${literal(f.node)}: ${d.count} direct children${d.layers ? " (floors; check that each is a major section)" : ""}.`);
|
|
2497
|
+
break;
|
|
2498
|
+
case "dangling":
|
|
2499
|
+
lines.push(` - Source ID ${literal(d.source)} \u2192 target ID ${literal(d.target)}${d.kind ? ", edge kind " + literal(d.kind) : ""}${location}. Missing: ${list(d.missing)}.`);
|
|
2500
|
+
break;
|
|
2501
|
+
case "misplaced":
|
|
2502
|
+
lines.push(` - On node ID ${literal(f.node)}${location}, move ${list(d.fields)} out of \`data\` and beside \`id\`.`);
|
|
2503
|
+
break;
|
|
2504
|
+
case "palette":
|
|
2505
|
+
case "colors": {
|
|
2506
|
+
const target = d.target ?? { file: "_profile.json", field: "nodePalette" };
|
|
2507
|
+
lines.push(` - In ${literal(target.file)}, edit ${literal(target.field)} for node kinds: ${list(d.kinds)}`);
|
|
2508
|
+
break;
|
|
2509
|
+
}
|
|
2510
|
+
case "coverage":
|
|
2511
|
+
lines.push(" - Leaf node IDs: " + list(d.leaves));
|
|
2512
|
+
break;
|
|
2513
|
+
case "vocabulary":
|
|
2514
|
+
lines.push(` - ${d.space === "node" ? "Node" : "Edge"} kinds (${d.kinds.length}): ${list(d.kinds)}`);
|
|
2515
|
+
break;
|
|
2516
|
+
default:
|
|
2517
|
+
lines.push(" - " + (place ? (f.scope === "version" ? "Version " : "File ") + place + ": " : "") + plain(f.message));
|
|
2518
|
+
if (f.fix) {
|
|
2519
|
+
const [action, ...example] = f.fix.split("\n");
|
|
2520
|
+
lines.push(" - " + plain(action));
|
|
2521
|
+
if (example.length) lines.push(...codeBlock(example.join("\n"), " "));
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
if (uneven.length) {
|
|
2526
|
+
const example = uneven[0];
|
|
2527
|
+
lines.push(" - Parent node IDs: " + list(uneven.map((f) => f.node)));
|
|
2528
|
+
if (example.facts?.type === "uneven" && example.facts.closest) {
|
|
2529
|
+
const { a: a2, b } = example.facts.closest;
|
|
2530
|
+
lines.push(` - Example: Under the node with ID ${literal(example.node)}, child nodes ${literal(a2)} and ${literal(b)} have the most similar subtrees.`);
|
|
2531
|
+
}
|
|
2532
|
+
const commands = [
|
|
2533
|
+
"glassbrain tree " + shellArg(input) + " --path " + shellArg(example.node),
|
|
2534
|
+
"glassbrain restructure " + shellArg(input) + " --dry-run"
|
|
2535
|
+
].join("\n");
|
|
2536
|
+
lines.push(
|
|
2537
|
+
" - If two siblings share a subject, move both under a new group node. Inspect and preview:",
|
|
2538
|
+
...codeBlock(commands, " ", "sh")
|
|
2539
|
+
);
|
|
2540
|
+
const pairs = uneven.slice(1).flatMap((f) => f.facts?.type === "uneven" && f.facts.closest ? [`${literal(f.node)} \u2192 ${list([f.facts.closest.a, f.facts.closest.b])}`] : []);
|
|
2541
|
+
if (pairs.length) {
|
|
2542
|
+
lines.push(" - Other pairs to inspect (parent node ID \u2192 two child node IDs):");
|
|
2543
|
+
for (const pair of pairs) lines.push(" - " + pair);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
if (rows.some((f) => f.facts?.type === "wide" && !f.facts.layers)) lines.push(" - Group children by subject where useful. Keep a natural collection together.");
|
|
2547
|
+
if (duplicates.length) {
|
|
2548
|
+
lines.push(" - Each source below lists edge kind \u2192 target node IDs.");
|
|
2549
|
+
for (const line of duplicateLines(duplicates)) lines.push(line);
|
|
2550
|
+
}
|
|
2551
|
+
return lines;
|
|
2552
|
+
}
|
|
2553
|
+
var severities = [["error", "Errors"], ["warn", "Warnings"], ["info", "Info"]];
|
|
2554
|
+
function reportText(found, input, versions = 1) {
|
|
2555
|
+
const lines = ["# Graph lint"];
|
|
2556
|
+
if (versions > 1) lines.push(`${versions} versions checked. Quality warnings apply to the latest version.`);
|
|
2557
|
+
for (const [level, heading] of severities) {
|
|
2558
|
+
const findings = found.filter((f) => f.level === level);
|
|
2559
|
+
const policy = { error: "Blocks export.", warn: "Fails lint with `--strict`.", info: "Advisory. Info alone passes lint, including with `--strict`." };
|
|
2560
|
+
lines.push(`## ${heading} (${findings.length})${findings.length ? " \u2014 " + policy[level] : ""}`);
|
|
2561
|
+
const groups = groupBy(findings, (f) => f.code);
|
|
2562
|
+
const codes = [...groups.keys()].sort((a2, b) => Number(a2 === "duplicate-edge") - Number(b === "duplicate-edge"));
|
|
2563
|
+
for (const code of codes) {
|
|
2564
|
+
const rows = groups.get(code);
|
|
2565
|
+
lines.push(`- **${plain(code)}** (${rows.length})${Object.hasOwn(headings, code) ? " \u2014 " + headings[code] : ""}`);
|
|
2566
|
+
for (const line of ruleLines(rows, input)) lines.push(line);
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
return lines.join("\n") + "\n";
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2374
2572
|
// cli/tree.ts
|
|
2375
2573
|
var one = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
2376
2574
|
var MAX_SIBLINGS = 12;
|
|
@@ -2378,7 +2576,6 @@ var MAX_LINES = 200;
|
|
|
2378
2576
|
var MAX_EDGES = 6;
|
|
2379
2577
|
function tree(model, opts) {
|
|
2380
2578
|
const derived = deriveLayers(model);
|
|
2381
|
-
const evidence = new Map(analyzeShape(model.nodes).branches.map((b) => [b.parent, b]));
|
|
2382
2579
|
const layerOf = (n) => derived.layerOf.get(n.id);
|
|
2383
2580
|
const labelOf = (id) => model.index.get(id)?.label ?? id;
|
|
2384
2581
|
const depth = Math.max(1, opts.depth ?? 3);
|
|
@@ -2413,8 +2610,8 @@ function tree(model, opts) {
|
|
|
2413
2610
|
for (const n of model.nodes) measure(n.id);
|
|
2414
2611
|
const bySize = (a2, b) => (size.get(b.id) ?? 1) - (size.get(a2.id) ?? 1) || labelOf(a2.id).localeCompare(labelOf(b.id));
|
|
2415
2612
|
const sorted = /* @__PURE__ */ new Map();
|
|
2416
|
-
for (const [id,
|
|
2417
|
-
sorted.set(id, orderedChildren(kids, id, model.index.get(id)?.data?.unordered === true) ?? [...
|
|
2613
|
+
for (const [id, list2] of kids) {
|
|
2614
|
+
sorted.set(id, orderedChildren(kids, id, model.index.get(id)?.data?.unordered === true) ?? [...list2].sort(bySize));
|
|
2418
2615
|
}
|
|
2419
2616
|
const outgoing = /* @__PURE__ */ new Map();
|
|
2420
2617
|
for (const e of model.edges) {
|
|
@@ -2424,22 +2621,19 @@ function tree(model, opts) {
|
|
|
2424
2621
|
if (arr) arr.push(item);
|
|
2425
2622
|
else outgoing.set(e.source, [item]);
|
|
2426
2623
|
}
|
|
2427
|
-
for (const
|
|
2624
|
+
for (const list2 of outgoing.values()) list2.sort();
|
|
2428
2625
|
const entries = [];
|
|
2429
2626
|
const edgeText = (all) => `(${all.slice(0, MAX_EDGES).join(", ")}${all.length > MAX_EDGES ? ` \u2026 ${all.length - MAX_EDGES} more` : ""})`;
|
|
2430
2627
|
const broken = (n) => n.parent && !model.index.has(n.parent);
|
|
2431
2628
|
const visit = (node, level, prefix, connector) => {
|
|
2432
|
-
const
|
|
2433
|
-
const canExpand = level + 1 < depth &&
|
|
2434
|
-
const collapsed =
|
|
2629
|
+
const list2 = sorted.get(node.id) ?? [];
|
|
2630
|
+
const canExpand = level + 1 < depth && list2.length > 0;
|
|
2631
|
+
const collapsed = list2.length > 0 && !canExpand;
|
|
2435
2632
|
const inside = (size.get(node.id) ?? 1) - 1;
|
|
2436
2633
|
const tall = height.get(node.id) ?? 0;
|
|
2437
2634
|
const edges = collapsed ? [] : outgoing.get(node.id) ?? [];
|
|
2438
2635
|
const bits = [];
|
|
2439
|
-
|
|
2440
|
-
if (assessment) bits.push(`${list.length} ${list.length === 1 ? "child" : "children"} \xB7 ${assessment.assessed ? `pressure ${assessment.score.toFixed(3)}` : "unassessed"}`);
|
|
2441
|
-
if (inside > 0) bits.push(one(inside, "node"));
|
|
2442
|
-
if (collapsed && tall > 0) bits.push(`${tall} deep`);
|
|
2636
|
+
if (collapsed) bits.push(`${one(inside, "node")} below \xB7 ${tall} deep`);
|
|
2443
2637
|
if (edges.length) bits.push(edgeText(edges));
|
|
2444
2638
|
const label = `${labelOf(node.id)}${broken(node) ? " (parent missing)" : ""}`;
|
|
2445
2639
|
const order = node.parent && model.index.get(node.parent)?.data?.unordered === true ? void 0 : node.order;
|
|
@@ -2457,27 +2651,28 @@ function tree(model, opts) {
|
|
|
2457
2651
|
text: `${prefix}${connector}${orderTag}${label}${labelOf(node.id) !== node.id ? ` [${node.id}]` : ""}${bits.length ? ` ${bits.join(" \xB7 ")}` : ""}`
|
|
2458
2652
|
});
|
|
2459
2653
|
if (!canExpand) return;
|
|
2460
|
-
const shown =
|
|
2654
|
+
const shown = list2.slice(0, perNode);
|
|
2461
2655
|
const childPrefix = prefix + (level === 0 ? "" : connector.includes("\u2514") ? " " : "\u2502 ");
|
|
2462
2656
|
shown.forEach((child, i) => {
|
|
2463
|
-
const last = i === shown.length - 1 &&
|
|
2657
|
+
const last = i === shown.length - 1 && list2.length <= perNode;
|
|
2464
2658
|
visit(child, level + 1, childPrefix, last ? "\u2514\u2500 " : "\u251C\u2500 ");
|
|
2465
2659
|
});
|
|
2466
|
-
if (
|
|
2660
|
+
if (list2.length > perNode) {
|
|
2467
2661
|
entries.push({
|
|
2468
2662
|
id: null,
|
|
2469
|
-
label: `\u2026 ${
|
|
2663
|
+
label: `\u2026 ${list2.length - perNode} more`,
|
|
2470
2664
|
depth: level + 1,
|
|
2471
2665
|
nodes: 0,
|
|
2472
2666
|
deep: 0,
|
|
2473
2667
|
collapsed: false,
|
|
2474
2668
|
edges: [],
|
|
2475
|
-
text: `${childPrefix}\u2514\u2500 \u2026 ${
|
|
2669
|
+
text: `${childPrefix}\u2514\u2500 \u2026 ${list2.length - perNode} more`
|
|
2476
2670
|
});
|
|
2477
2671
|
}
|
|
2478
2672
|
};
|
|
2479
2673
|
const structure = structureOf(model);
|
|
2480
|
-
let header = `${opts.title} ${one(structure.nodes, "node")} \xB7 ${one(structure.edges, "edge")} \xB7 ${one(structure.roots, "root")} \xB7 depth ${structure.depth}${structure.layers ? ` \xB7 ${one(structure.layers, "layer")}` : ""}
|
|
2674
|
+
let header = `${opts.title} ${one(structure.nodes, "node")} \xB7 ${one(structure.edges, "edge")} \xB7 ${one(structure.roots, "root")} \xB7 depth ${structure.depth}${structure.layers ? ` \xB7 ${one(structure.layers, "layer")}` : ""}`;
|
|
2675
|
+
const kinds = { nodes: kindDistribution(model.nodes), edges: kindDistribution(model.edges) };
|
|
2481
2676
|
const roots = model.nodes.filter((n) => !n.parent || broken(n));
|
|
2482
2677
|
if (opts.path) {
|
|
2483
2678
|
const start = model.index.get(opts.path);
|
|
@@ -2520,11 +2715,13 @@ path: ${[...chain, labelOf(start.id)].join(" \u203A ")}`;
|
|
|
2520
2715
|
}
|
|
2521
2716
|
}
|
|
2522
2717
|
const more = Math.max(0, entries.length - maxLines);
|
|
2523
|
-
return { header, entries: more ? entries.slice(0, maxLines) : entries, more };
|
|
2718
|
+
return { header, kinds, entries: more ? entries.slice(0, maxLines) : entries, more };
|
|
2524
2719
|
}
|
|
2525
2720
|
function treeText(result) {
|
|
2526
2721
|
const lines = [result.header, ...result.entries.map((e) => e.text)];
|
|
2527
|
-
if (result.more) lines.push(`\u2026 ${result.more} more lines
|
|
2722
|
+
if (result.more) lines.push(`\u2026 ${result.more} more lines`);
|
|
2723
|
+
if (result.more || result.entries.some((e) => e.collapsed || e.id === null))
|
|
2724
|
+
lines.push("Explore a branch with --path <id> and --depth <levels>.");
|
|
2528
2725
|
return lines.join("\n");
|
|
2529
2726
|
}
|
|
2530
2727
|
|
|
@@ -2691,14 +2888,34 @@ function restructure(input, edges, opts = {}) {
|
|
|
2691
2888
|
note: "Structure pressure is not correctness. No original node or relation was removed. Group suggestions require --group; lower pressure after grouping is not proof of improvement."
|
|
2692
2889
|
};
|
|
2693
2890
|
}
|
|
2891
|
+
function repairLines(r) {
|
|
2892
|
+
const lines = [];
|
|
2893
|
+
const root = "top level";
|
|
2894
|
+
for (const n of r.created)
|
|
2895
|
+
lines.push(`Create ${n.label} [${n.id}] under ${n.parent ?? root}`);
|
|
2896
|
+
const moves = /* @__PURE__ */ new Map();
|
|
2897
|
+
for (const m of r.moves) {
|
|
2898
|
+
const key = JSON.stringify([m.from, m.to, m.why]);
|
|
2899
|
+
const group = moves.get(key) ?? { from: m.from ?? root, to: m.to ?? root, why: m.why, ids: [] };
|
|
2900
|
+
group.ids.push(m.id);
|
|
2901
|
+
moves.set(key, group);
|
|
2902
|
+
}
|
|
2903
|
+
for (const m of moves.values())
|
|
2904
|
+
lines.push(`${m.from} \u2192 ${m.to} \xB7 ${m.ids.join(", ")} (${m.why})`);
|
|
2905
|
+
for (const o of r.orders)
|
|
2906
|
+
lines.push(`Reorder ${o.id}: ${o.from ?? "unset"} \u2192 ${o.to}`);
|
|
2907
|
+
return lines;
|
|
2908
|
+
}
|
|
2694
2909
|
function planText(r, title, inputPath = "<path>") {
|
|
2695
|
-
const
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
for (const s of r.suggestions)
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2910
|
+
const repairs = repairLines(r);
|
|
2911
|
+
const lines = [`${title} \u2014 ${repairs.length ? "Planned changes" : "No automatic changes needed."}`, ...repairs.map((line) => " " + line)];
|
|
2912
|
+
if (r.suggestions.length) lines.push("Optional groups \xB7 These siblings have similar branches. Group them if they share a subject.");
|
|
2913
|
+
for (const s of r.suggestions) {
|
|
2914
|
+
const members = s.members.join(",");
|
|
2915
|
+
lines.push(` ${s.parent} \u2192 one new group for ${s.members.join(", ")}`);
|
|
2916
|
+
if (s.members.every((id) => !id.includes(","))) lines.push(` glassbrain restructure ${inputPath} --group ${shellArg(members)}`);
|
|
2917
|
+
}
|
|
2918
|
+
return lines.join("\n");
|
|
2702
2919
|
}
|
|
2703
2920
|
function planNodesOf(model) {
|
|
2704
2921
|
return model.nodes.map((n, seq) => ({
|
|
@@ -2733,7 +2950,7 @@ var HELP = (schema) => `glassbrain: open, diff and lint a knowledge graph, writt
|
|
|
2733
2950
|
GUIDELINES
|
|
2734
2951
|
* \`id\` identifies a node; nest it in \`children\` in reading order. Recommend \`kind\` for its category.
|
|
2735
2952
|
* Children structure helps readability. Prefer fewer than 5 children; keep natural collections. Consider deeper grouping if crowded.
|
|
2736
|
-
*
|
|
2953
|
+
* Reuse consistent node and edge kinds; check their distributions with tree.
|
|
2737
2954
|
* Keep depth and detail meaningful. Lint flags structural imbalance as \`bad-structure\`.
|
|
2738
2955
|
* Put supporting details in descriptions. Extra fields are kept and shown.
|
|
2739
2956
|
|
|
@@ -2758,7 +2975,7 @@ var HELP = (schema) => `glassbrain: open, diff and lint a knowledge graph, writt
|
|
|
2758
2975
|
A local pass profile overrides it; an exported bundle carries its own profile.
|
|
2759
2976
|
|
|
2760
2977
|
COLORS one entry per kind you use. A kind without an entry is drawn as skeleton \u2014
|
|
2761
|
-
every uncoloured kind looks the same, so lint reports it as
|
|
2978
|
+
every uncoloured kind looks the same, so lint reports it as a warning.
|
|
2762
2979
|
{ "nodePalette": { "file": "#6366f1", "folder": "#94a3b8" },
|
|
2763
2980
|
"edgePalette": { "uses": "#2563eb" } }
|
|
2764
2981
|
Colors closer than 10 in Lab distance read as one kind (lint notes it).
|
|
@@ -2797,7 +3014,7 @@ var HELP = (schema) => `glassbrain: open, diff and lint a knowledge graph, writt
|
|
|
2797
3014
|
--out <file.html> write the page here instead of a temp file (view, diff)
|
|
2798
3015
|
--open / --no-open open the browser or not (diff opens only in a terminal)
|
|
2799
3016
|
--exit-code exit 1 when anything changed (diff)
|
|
2800
|
-
--all list every change
|
|
3017
|
+
--all list every change (diff); lint always lists all findings
|
|
2801
3018
|
--ignore <a,b> fields that do not count as a change (diff)
|
|
2802
3019
|
--format <id> force a format: native, graphify, understand-anything, memory, obsidian
|
|
2803
3020
|
-h, --help / -v, --version this help / the version
|
|
@@ -2853,18 +3070,13 @@ function writePage(payload, out) {
|
|
|
2853
3070
|
return file;
|
|
2854
3071
|
}
|
|
2855
3072
|
var count = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
2856
|
-
var TAG = { error: "error", warn: "warn ", info: "info " };
|
|
2857
3073
|
var tally = (found) => ({
|
|
2858
3074
|
error: found.filter((f) => f.level === "error").length,
|
|
2859
3075
|
warn: found.filter((f) => f.level === "warn").length,
|
|
2860
3076
|
info: found.filter((f) => f.level === "info").length
|
|
2861
3077
|
});
|
|
2862
|
-
function printFindings(found,
|
|
2863
|
-
|
|
2864
|
-
console.log(`${TAG[f.level]} ${f.code} ${f.where} ${f.message}`);
|
|
2865
|
-
if (f.fix) console.log(f.fix.split("\n").map((l) => ` ${l}`).join("\n"));
|
|
2866
|
-
}
|
|
2867
|
-
if (found.length > limit) console.log(`\u2026 ${found.length - limit} more (--json)`);
|
|
3078
|
+
function printFindings(found, input, versions = 1) {
|
|
3079
|
+
process.stdout.write(reportText(found, input, versions));
|
|
2868
3080
|
}
|
|
2869
3081
|
var slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "graph";
|
|
2870
3082
|
function openFile(file) {
|
|
@@ -2890,28 +3102,27 @@ function notes(l, models) {
|
|
|
2890
3102
|
});
|
|
2891
3103
|
}
|
|
2892
3104
|
var summaryOf = (l, m) => `${l.title}: ${l.versions.length > 1 ? `${l.versions.length} versions, latest ` : ""}${count(m.nodes.length, "node")}, ${count(m.edges.length, "edge")}${l.format !== "native" ? ` (read as ${l.format})` : ""}`;
|
|
2893
|
-
var
|
|
2894
|
-
var findingsAt = (l, input) => lint(l).map((f) => ({ ...f, ...f.fix ? { fix: f.fix.replaceAll("<path>", shellArg(input)) } : {} }));
|
|
3105
|
+
var findingsAt = (l, input) => lint(l).map((f) => ({ ...f, ...f.fix ? { fix: f.fix.replaceAll("<path>", () => shellArg(input)) } : {} }));
|
|
2895
3106
|
function view(a2) {
|
|
2896
3107
|
if (a2.pos.length !== 1) fail("view needs exactly one <path>");
|
|
2897
3108
|
const l = load(a2.pos[0], { format: a2.flags.format });
|
|
2898
3109
|
const models = nodesOf(l);
|
|
2899
|
-
notes(l,
|
|
3110
|
+
notes(l, []);
|
|
2900
3111
|
const found = findingsAt(l, a2.pos[0]);
|
|
2901
3112
|
const n = tally(found);
|
|
2902
3113
|
if (n.error || a2.flags.strict && n.warn) {
|
|
2903
3114
|
console.log(summaryOf(l, models[models.length - 1]));
|
|
2904
|
-
printFindings(found);
|
|
3115
|
+
printFindings(found, a2.pos[0], l.versions.length);
|
|
2905
3116
|
console.log(`
|
|
2906
3117
|
${count(n.error, "error")} \xB7 ${count(n.warn, "warning")} \u2014 page not written. Fix them, then lint again.`);
|
|
2907
3118
|
process.exitCode = 1;
|
|
2908
3119
|
return;
|
|
2909
3120
|
}
|
|
2910
|
-
const file = writePage({ title: l.title, profile: l.profile, versions: l.versions, layouts: l.layouts, start: { at: l.versions.length - 1, compare: false } }, a2.flags.out);
|
|
3121
|
+
const file = writePage({ lint: { input: a2.pos[0], findings: found, paletteTarget: l.paletteTarget }, title: l.title, profile: l.profile, versions: l.versions, layouts: l.layouts, start: { at: l.versions.length - 1, compare: false } }, a2.flags.out);
|
|
2911
3122
|
console.log(summaryOf(l, models[models.length - 1]));
|
|
2912
3123
|
console.log(file);
|
|
2913
3124
|
if (n.warn) {
|
|
2914
|
-
printFindings(found.
|
|
3125
|
+
printFindings(found, a2.pos[0], l.versions.length);
|
|
2915
3126
|
console.log(`${count(n.warn, "warning")} (not blocking; \`glassbrain lint\` has the details)`);
|
|
2916
3127
|
}
|
|
2917
3128
|
if (a2.flags.open !== false) openFile(file);
|
|
@@ -2950,10 +3161,14 @@ function runDiff(a2) {
|
|
|
2950
3161
|
const wantOpen = a2.flags.open === true || a2.flags.open === void 0 && !a2.flags.json && process.stdout.isTTY;
|
|
2951
3162
|
let file = null;
|
|
2952
3163
|
if (wantOpen || a2.flags.out) {
|
|
3164
|
+
const versionInput = (spec, loaded) => loaded.versions.length > 1 ? spec.replace(/\/$/, "") + "/" + pick(loaded).name : spec;
|
|
2953
3165
|
file = writePage({
|
|
2954
3166
|
title: `${labels.before} \u2192 ${labels.after}`,
|
|
2955
3167
|
profile: profileJson || ignore.length ? { ...profileJson, diffIgnore: ignore } : null,
|
|
2956
|
-
versions: [
|
|
3168
|
+
versions: [
|
|
3169
|
+
{ name: labels.before, input: versionInput(oldSpec, before), sources: vb.sources },
|
|
3170
|
+
{ name: labels.after, input: versionInput(newSpec, after), sources: va.sources }
|
|
3171
|
+
],
|
|
2957
3172
|
layouts: null,
|
|
2958
3173
|
start: { at: 1, compare: true }
|
|
2959
3174
|
}, a2.flags.out);
|
|
@@ -2974,7 +3189,6 @@ function runLint(a2) {
|
|
|
2974
3189
|
const models = nodesOf(l);
|
|
2975
3190
|
const latest = models[models.length - 1];
|
|
2976
3191
|
const n = tally(found);
|
|
2977
|
-
const structure = structureOf(latest);
|
|
2978
3192
|
const failing = n.error > 0 || a2.flags.strict && n.warn > 0;
|
|
2979
3193
|
if (a2.flags.json) {
|
|
2980
3194
|
console.log(JSON.stringify({
|
|
@@ -2984,16 +3198,11 @@ function runLint(a2) {
|
|
|
2984
3198
|
errors: n.error,
|
|
2985
3199
|
warnings: n.warn,
|
|
2986
3200
|
infos: n.info,
|
|
2987
|
-
structure,
|
|
3201
|
+
structure: structureOf(latest),
|
|
2988
3202
|
issues: found
|
|
2989
3203
|
}, null, 1));
|
|
2990
3204
|
} else {
|
|
2991
|
-
|
|
2992
|
-
if (found.length) console.log("");
|
|
2993
|
-
printFindings(found);
|
|
2994
|
-
console.log(`${count(n.error, "error")} \xB7 ${count(n.warn, "warning")} \xB7 ${count(n.info, "info")}`);
|
|
2995
|
-
console.log(`structure: ${count(structure.roots, "root")} \xB7 depth ${structure.depth}${structure.layers ? ` \xB7 ${count(structure.layers, "layer")}` : ""} \xB7 ${structure.parented}/${structure.nodes} parented \xB7 structure pressure ${structure.shape.peak.toFixed(3)} \xB7 ${structure.shape.assessed} assessed / ${structure.shape.unassessed} unassessed`);
|
|
2996
|
-
console.log(`tree: glassbrain tree ${shellArg(a2.pos[0])} --depth=3`);
|
|
3205
|
+
printFindings(found, a2.pos[0], l.versions.length);
|
|
2997
3206
|
if (l.ignored.length) process.stderr.write(`note: not read: ${l.ignored.slice(0, 5).join(", ")}${l.ignored.length > 5 ? ` and ${l.ignored.length - 5} more` : ""}
|
|
2998
3207
|
`);
|
|
2999
3208
|
}
|
|
@@ -3005,18 +3214,19 @@ function runTree(a2) {
|
|
|
3005
3214
|
if (!Number.isInteger(depth) || depth < 1) fail("--depth needs a positive integer");
|
|
3006
3215
|
const l = load(a2.pos[0], { format: a2.flags.format });
|
|
3007
3216
|
const models = nodesOf(l);
|
|
3008
|
-
notes(l, models);
|
|
3009
3217
|
const latest = models[models.length - 1];
|
|
3218
|
+
notes(l, models.slice(0, -1));
|
|
3010
3219
|
if (latest.errors.length) fail(latest.errors.map((e) => `${e.origin}: ${e.message}`).join("\n"), 1);
|
|
3011
3220
|
const version = l.versions[l.versions.length - 1].name;
|
|
3012
3221
|
const result = tree(latest, {
|
|
3222
|
+
kindLabels: profileOf(l).kindLabels,
|
|
3013
3223
|
title: l.versions.length > 1 ? `${l.title}/${version}` : l.title,
|
|
3014
3224
|
depth,
|
|
3015
3225
|
path: typeof a2.flags.path === "string" ? a2.flags.path : void 0,
|
|
3016
3226
|
orphans: a2.flags.orphans === true
|
|
3017
3227
|
});
|
|
3018
3228
|
if (a2.flags.json) {
|
|
3019
|
-
console.log(JSON.stringify({ title: l.title, ...structureOf(latest), entries: result.entries, more: result.more }, null, 1));
|
|
3229
|
+
console.log(JSON.stringify({ title: l.title, ...structureOf(latest), kinds: result.kinds, entries: result.entries, more: result.more }, null, 1));
|
|
3020
3230
|
} else {
|
|
3021
3231
|
console.log(treeText(result));
|
|
3022
3232
|
}
|
|
@@ -3025,11 +3235,12 @@ function runRestructure(a2) {
|
|
|
3025
3235
|
if (a2.pos.length !== 1) fail("restructure needs exactly one <path>");
|
|
3026
3236
|
const l = load(a2.pos[0], { format: a2.flags.format });
|
|
3027
3237
|
const blockers = lint(l).filter((f) => ["duplicate-id", "dangling-edge", "field-conflict", "children-conflict"].includes(f.code));
|
|
3028
|
-
if (blockers.length) fail(`
|
|
3238
|
+
if (blockers.length) fail(`Repair these before restructuring:
|
|
3239
|
+
${reportText(blockers, a2.pos[0]).trimEnd()}`, 1);
|
|
3029
3240
|
const models = nodesOf(l);
|
|
3030
|
-
notes(l, models);
|
|
3031
3241
|
const latest = models[models.length - 1];
|
|
3032
|
-
|
|
3242
|
+
notes(l, models.slice(0, -1));
|
|
3243
|
+
if (latest.errors.length) fail(latest.errors.map((e) => `${e.origin}: ${e.message}`).join("\n"), 1);
|
|
3033
3244
|
const phys = toPhysical(latest);
|
|
3034
3245
|
const nodes = planNodesOf(latest);
|
|
3035
3246
|
const edges = phys.edges.map((e) => ({
|
|
@@ -3069,8 +3280,8 @@ function runRestructure(a2) {
|
|
|
3069
3280
|
const abs = path2.resolve(a2.pos[0]);
|
|
3070
3281
|
const dir = fs2.existsSync(abs) && fs2.statSync(abs).isDirectory() ? abs : path2.dirname(abs);
|
|
3071
3282
|
const passes = fs2.existsSync(dir) ? fs2.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => /^(\d+)-/.exec(e.name)?.[1]).filter(Boolean).map(Number) : [];
|
|
3072
|
-
const palette =
|
|
3073
|
-
const known = { folder: "#94a3b8", file: "#64748b", overview: "#a855f7", group: "#a855f7" };
|
|
3283
|
+
const palette = kindTable();
|
|
3284
|
+
const known = kindTable({ folder: "#94a3b8", file: "#64748b", overview: "#a855f7", group: "#a855f7" });
|
|
3074
3285
|
const wheel = ["#6366f1", "#f59e0b", "#10b981", "#ef4444", "#8b5cf6", "#06b6d4"];
|
|
3075
3286
|
let wi = 0;
|
|
3076
3287
|
for (const k of new Set(plan.nodes.map((n) => n.kind))) {
|