glassbrain 0.2.0-alpha.6 → 0.2.0-alpha.7
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/chunks/{chunk-3P34XHQ2.js → chunk-3KUNYSJE.js} +3 -1
- package/dist/chunks/{chunk-3SAL4526.js → chunk-FNTYI7VP.js} +38 -22
- package/dist/chunks/{chunk-LMYD4QHC.js → chunk-GZSWZSSE.js} +373 -321
- package/dist/chunks/{chunk-M3MAM2VD.js → chunk-LK77SYCN.js} +34 -1
- package/dist/chunks/{chunk-5DEN6HXJ.js → chunk-Q35ZKWKF.js} +2 -2
- package/dist/cli/glassbrain.js +124 -109
- package/dist/cli/viewer.js +88 -59
- package/dist/core.d.ts +1 -0
- package/dist/core.js +11 -3
- package/dist/index.js +13 -5
- package/dist/internal.js +13 -5
- package/dist/kinds.d.ts +23 -0
- package/dist/profile.d.ts +5 -1
- package/dist/react/DetailPanel.js +2 -2
- package/dist/react/GlassPlanes.d.ts +11 -0
- package/dist/react/GraphCanvas.d.ts +2 -0
- package/dist/react/GraphCanvas.js +4 -4
- package/dist/react/icons.d.ts +2 -0
- package/dist/strings.d.ts +2 -2
- package/package.json +1 -1
- package/schema/profile.schema.json +2 -2
|
@@ -59,9 +59,42 @@ function layerIndexOf(derived, id) {
|
|
|
59
59
|
return lid ? derived.layers.findIndex((l) => l.id === lid) : -1;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// src/kinds.ts
|
|
63
|
+
function kindDistribution(items) {
|
|
64
|
+
const counts = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const item of items) if (item.kind) counts.set(item.kind, (counts.get(item.kind) ?? 0) + 1);
|
|
66
|
+
const sizes = [...counts].map(([kind, count]) => ({ kind, count })).sort((a, b) => b.count - a.count || a.kind.localeCompare(b.kind));
|
|
67
|
+
const typed = sizes.reduce((sum, row) => sum + row.count, 0);
|
|
68
|
+
const effective = sizes.reduce((sum, row) => sum + Math.sqrt(row.count / typed), 0) ** 2;
|
|
69
|
+
const fragmentation = typed > 1 ? effective / Math.log(typed) : 0;
|
|
70
|
+
return {
|
|
71
|
+
total: items.length,
|
|
72
|
+
typed,
|
|
73
|
+
missing: items.length - typed,
|
|
74
|
+
count: sizes.length,
|
|
75
|
+
sizes,
|
|
76
|
+
effective,
|
|
77
|
+
fragmentation,
|
|
78
|
+
reason: typed >= 10 && fragmentation > 2 ? "too fragmented" : null
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function kindHeading(space, d) {
|
|
82
|
+
return `${space} kinds: ${d.count}${d.reason ? ` (${d.reason})` : ""}`;
|
|
83
|
+
}
|
|
84
|
+
function kindSummary(space, d, labels = {}) {
|
|
85
|
+
return [
|
|
86
|
+
kindHeading(space, d),
|
|
87
|
+
...d.sizes.map((row) => `${Object.hasOwn(labels, row.kind) ? labels[row.kind] : row.kind} ${row.count}/${d.total}`),
|
|
88
|
+
...d.missing ? [`(no kind) ${d.missing}/${d.total}`] : []
|
|
89
|
+
].join(" | ");
|
|
90
|
+
}
|
|
91
|
+
|
|
62
92
|
export {
|
|
63
93
|
orderedChildren,
|
|
64
94
|
childrenMap,
|
|
65
95
|
deriveLayers,
|
|
66
|
-
layerIndexOf
|
|
96
|
+
layerIndexOf,
|
|
97
|
+
kindDistribution,
|
|
98
|
+
kindHeading,
|
|
99
|
+
kindSummary
|
|
67
100
|
};
|
|
@@ -28,8 +28,8 @@ var EN = {
|
|
|
28
28
|
more: "More",
|
|
29
29
|
origins: "Source",
|
|
30
30
|
allOrigins: "All sources",
|
|
31
|
-
issuesTip: (e, w) => [e && `${e} error${e > 1 ? "s" : ""}`, w && `${w} warning${w > 1 ? "s" : ""}`].filter(Boolean).join(" \xB7 "),
|
|
32
|
-
issuesTitle: (e, w) => `Checks \xB7 ${[e && `${e} errors`, w && `${w} warnings`].filter(Boolean).join(" \xB7 ")}`,
|
|
31
|
+
issuesTip: (e, w, i) => [e && `${e} error${e > 1 ? "s" : ""}`, w && `${w} warning${w > 1 ? "s" : ""}`, i && `${i} info`].filter(Boolean).join(" \xB7 "),
|
|
32
|
+
issuesTitle: (e, w, i) => `Checks \xB7 ${[e && `${e} errors`, w && `${w} warnings`, i && `${i} info`].filter(Boolean).join(" \xB7 ")}`,
|
|
33
33
|
moreItems: (n) => `${n} more`,
|
|
34
34
|
cameraTip: "Scroll / two fingers to pan \xB7 \u2318 + scroll or pinch to zoom",
|
|
35
35
|
zoomIn: "Zoom in (+)",
|
package/dist/cli/glassbrain.js
CHANGED
|
@@ -296,6 +296,9 @@ 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
|
+
}
|
|
299
302
|
function defineProfile(input) {
|
|
300
303
|
const layers = input.layers?.length ? input.layers : [DEFAULT_LAYER];
|
|
301
304
|
const fallbackLayer = layers[0].id;
|
|
@@ -305,15 +308,15 @@ function defineProfile(input) {
|
|
|
305
308
|
merge: input.merge ?? mergeSlices,
|
|
306
309
|
layers,
|
|
307
310
|
layerOf: input.layerOf ?? ((n) => n.layer ?? fallbackLayer),
|
|
308
|
-
nodePalette: input.nodePalette
|
|
309
|
-
edgePalette: input.edgePalette
|
|
310
|
-
nodeSize: input.nodeSize
|
|
311
|
-
edgeWidth: input.edgeWidth
|
|
311
|
+
nodePalette: kindTable(input.nodePalette),
|
|
312
|
+
edgePalette: kindTable(input.edgePalette),
|
|
313
|
+
nodeSize: kindTable(input.nodeSize),
|
|
314
|
+
edgeWidth: kindTable(input.edgeWidth),
|
|
312
315
|
placeholderFlags: input.placeholderFlags ?? [],
|
|
313
316
|
style: input.style ?? [],
|
|
314
317
|
nodeClass: input.nodeClass ?? (() => ""),
|
|
315
318
|
edgeClass: input.edgeClass ?? ((e) => e.kind ?? ""),
|
|
316
|
-
kindLabels: input.kindLabels
|
|
319
|
+
kindLabels: kindTable(input.kindLabels),
|
|
317
320
|
detail: input.detail ?? {},
|
|
318
321
|
validate: input.validate ?? (() => []),
|
|
319
322
|
layoutEdge: input.layoutEdge ?? (() => false),
|
|
@@ -984,7 +987,12 @@ function load(spec, opts = {}) {
|
|
|
984
987
|
const f = tree2.files.find((x) => x.path === name);
|
|
985
988
|
if (!f) return null;
|
|
986
989
|
try {
|
|
987
|
-
|
|
990
|
+
const value = JSON.parse(f.text);
|
|
991
|
+
if (name === "_profile.json" && (!value || typeof value !== "object" || Array.isArray(value))) {
|
|
992
|
+
metaErrors.push({ file: name, message: "expected a profile object" });
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
return value;
|
|
988
996
|
} catch (e) {
|
|
989
997
|
metaErrors.push({ file: name, message: `not JSON: ${e.message}` });
|
|
990
998
|
return null;
|
|
@@ -1015,7 +1023,7 @@ function load(spec, opts = {}) {
|
|
|
1015
1023
|
suggested ??= r.profile;
|
|
1016
1024
|
}
|
|
1017
1025
|
ignored.push(...r.skipped.map((p) => versioned ? `${g.name}/${p}` : p));
|
|
1018
|
-
return { name: g.name, sources: r.sources };
|
|
1026
|
+
return { name: g.name, sources: r.sources, format: r.adapter?.id ?? "native" };
|
|
1019
1027
|
});
|
|
1020
1028
|
return {
|
|
1021
1029
|
title: tree2.title,
|
|
@@ -1456,7 +1464,7 @@ var profile_schema_default = {
|
|
|
1456
1464
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1457
1465
|
$id: "https://unpkg.com/glassbrain/schema/profile.schema.json",
|
|
1458
1466
|
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
|
|
1467
|
+
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
1468
|
type: "object",
|
|
1461
1469
|
properties: {
|
|
1462
1470
|
nodePalette: {
|
|
@@ -1496,7 +1504,7 @@ var profile_schema_default = {
|
|
|
1496
1504
|
properties: {
|
|
1497
1505
|
defaultLayers: {
|
|
1498
1506
|
type: "boolean",
|
|
1499
|
-
description: "Open with the layer (2.5D plane) view on when the graph has ordered siblings.
|
|
1507
|
+
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
1508
|
},
|
|
1501
1509
|
layerColors: {
|
|
1502
1510
|
type: "array",
|
|
@@ -1639,9 +1647,9 @@ function checkSchema(root, value, limit = 50) {
|
|
|
1639
1647
|
}
|
|
1640
1648
|
if (typeOf(v) === "object") {
|
|
1641
1649
|
const o = v;
|
|
1642
|
-
for (const r of s.required ?? []) if (!(r
|
|
1650
|
+
for (const r of s.required ?? []) if (!Object.hasOwn(o, r)) out2.push({ path: path3, message: `missing "${r}"` });
|
|
1643
1651
|
for (const [k, val] of Object.entries(o)) {
|
|
1644
|
-
const sub = s.properties
|
|
1652
|
+
const sub = s.properties && Object.hasOwn(s.properties, k) ? s.properties[k] : typeof s.additionalProperties === "object" ? s.additionalProperties : null;
|
|
1645
1653
|
if (sub !== null && sub !== void 0) walk2(sub, val, `${path3}.${k}`, out2);
|
|
1646
1654
|
else if (s.additionalProperties === false) out2.push({ path: path3, message: `unknown field "${k}"` });
|
|
1647
1655
|
}
|
|
@@ -1658,6 +1666,36 @@ function checkSchema(root, value, limit = 50) {
|
|
|
1658
1666
|
return out;
|
|
1659
1667
|
}
|
|
1660
1668
|
|
|
1669
|
+
// src/kinds.ts
|
|
1670
|
+
function kindDistribution(items) {
|
|
1671
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1672
|
+
for (const item of items) if (item.kind) counts.set(item.kind, (counts.get(item.kind) ?? 0) + 1);
|
|
1673
|
+
const sizes = [...counts].map(([kind, count2]) => ({ kind, count: count2 })).sort((a2, b) => b.count - a2.count || a2.kind.localeCompare(b.kind));
|
|
1674
|
+
const typed = sizes.reduce((sum, row) => sum + row.count, 0);
|
|
1675
|
+
const effective = sizes.reduce((sum, row) => sum + Math.sqrt(row.count / typed), 0) ** 2;
|
|
1676
|
+
const fragmentation = typed > 1 ? effective / Math.log(typed) : 0;
|
|
1677
|
+
return {
|
|
1678
|
+
total: items.length,
|
|
1679
|
+
typed,
|
|
1680
|
+
missing: items.length - typed,
|
|
1681
|
+
count: sizes.length,
|
|
1682
|
+
sizes,
|
|
1683
|
+
effective,
|
|
1684
|
+
fragmentation,
|
|
1685
|
+
reason: typed >= 10 && fragmentation > 2 ? "too fragmented" : null
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
function kindHeading(space, d) {
|
|
1689
|
+
return `${space} kinds: ${d.count}${d.reason ? ` (${d.reason})` : ""}`;
|
|
1690
|
+
}
|
|
1691
|
+
function kindSummary(space, d, labels = {}) {
|
|
1692
|
+
return [
|
|
1693
|
+
kindHeading(space, d),
|
|
1694
|
+
...d.sizes.map((row) => `${Object.hasOwn(labels, row.kind) ? labels[row.kind] : row.kind} ${row.count}/${d.total}`),
|
|
1695
|
+
...d.missing ? [`(no kind) ${d.missing}/${d.total}`] : []
|
|
1696
|
+
].join(" | ");
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1661
1699
|
// cli/shape.ts
|
|
1662
1700
|
var rounded = (x) => +x.toFixed(6);
|
|
1663
1701
|
function analyzeShape(nodes) {
|
|
@@ -1876,10 +1914,8 @@ function analyzeShape(nodes) {
|
|
|
1876
1914
|
}
|
|
1877
1915
|
|
|
1878
1916
|
// cli/checks.ts
|
|
1879
|
-
var
|
|
1880
|
-
var WIDE_WARN = 10;
|
|
1917
|
+
var WIDE_WARN = 5;
|
|
1881
1918
|
var MAX_NAMES = 4;
|
|
1882
|
-
var MIN_SAMPLE = 10;
|
|
1883
1919
|
var names = (xs) => `${xs.slice(0, MAX_NAMES).join(", ")}${xs.length > MAX_NAMES ? ` and ${xs.length - MAX_NAMES} more` : ""}`;
|
|
1884
1920
|
var misplacedField = {
|
|
1885
1921
|
code: "schema",
|
|
@@ -2014,10 +2050,9 @@ var duplicateEdge = {
|
|
|
2014
2050
|
};
|
|
2015
2051
|
var unevenKinds = {
|
|
2016
2052
|
code: "bad-structure",
|
|
2017
|
-
level: "
|
|
2053
|
+
level: "warn",
|
|
2018
2054
|
run: ({ model }) => analyzeShape(model.nodes).branches.filter((b) => b.score >= 0.2).sort((a2, b) => b.score - a2.score).map((b) => ({
|
|
2019
2055
|
node: b.parent,
|
|
2020
|
-
level: b.children.length > WIDE_WARN ? "error" : b.score >= 0.4 ? "warn" : "info",
|
|
2021
2056
|
message: `"${b.parent}": ${b.children.length} children with uneven structural relationships (structure pressure ${b.score.toFixed(3)}, dispersion ${b.dispersion.toFixed(3)}, effective template support ${b.support.toFixed(2)})`,
|
|
2022
2057
|
fix: `inspect this branch: glassbrain tree <path> --path "${b.parent}"
|
|
2023
2058
|
closest compared pair: ${b.closest?.a} / ${b.closest?.b} (distance ${b.closest?.distance}). Differences can be intentional.
|
|
@@ -2031,12 +2066,10 @@ var wideNode = {
|
|
|
2031
2066
|
const out = [];
|
|
2032
2067
|
for (const [id, kids] of children) {
|
|
2033
2068
|
const n = kids.length;
|
|
2034
|
-
if (n <=
|
|
2035
|
-
const level = n > WIDE_WARN ? "warn" : "info";
|
|
2069
|
+
if (n <= WIDE_WARN) continue;
|
|
2036
2070
|
const isAnchor = layers.anchor === id;
|
|
2037
2071
|
const what = isAnchor ? `${n} layers` : `${n} children`;
|
|
2038
2072
|
out.push({
|
|
2039
|
-
level,
|
|
2040
2073
|
node: id,
|
|
2041
2074
|
message: `"${labelOf(id)}" holds ${what}; ${isAnchor ? "review whether each floor is a major section" : "review whether this is one natural collection"}`,
|
|
2042
2075
|
fix: `inspect membership and depth: glassbrain tree <path> --path "${id}"
|
|
@@ -2049,10 +2082,10 @@ var wideNode = {
|
|
|
2049
2082
|
};
|
|
2050
2083
|
var uncoloredKind = {
|
|
2051
2084
|
code: "uncolored-kind",
|
|
2052
|
-
level: "
|
|
2085
|
+
level: "warn",
|
|
2053
2086
|
run: ({ model, profile }) => {
|
|
2054
2087
|
const used = [...new Set(model.nodes.map((n) => n.kind).filter((k) => !!k))];
|
|
2055
|
-
const missing = used.filter((k) => !(
|
|
2088
|
+
const missing = used.filter((k) => !Object.hasOwn(profile.nodePalette, k));
|
|
2056
2089
|
if (!missing.length) return [];
|
|
2057
2090
|
const shown = missing.slice(0, 5);
|
|
2058
2091
|
const palette = Object.fromEntries(shown.map((k, i) => [k, ["#6366f1", "#f59e0b", "#10b981", "#ef4444", "#8b5cf6"][i % 5]]));
|
|
@@ -2065,45 +2098,16 @@ ${missing.length > shown.length ? ` \u2026 and ${missing.length - shown.length}
|
|
|
2065
2098
|
}];
|
|
2066
2099
|
}
|
|
2067
2100
|
};
|
|
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.`
|
|
2077
|
-
}];
|
|
2078
|
-
}
|
|
2079
|
-
};
|
|
2080
2101
|
var kindNote = {
|
|
2081
2102
|
code: "kind-note",
|
|
2082
|
-
level: "
|
|
2083
|
-
run: ({ model }) => {
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
out.push({
|
|
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
|
-
}
|
|
2103
|
+
level: "warn",
|
|
2104
|
+
run: ({ model }) => ["node", "edge"].flatMap((space) => {
|
|
2105
|
+
const d = kindDistribution(space === "node" ? model.nodes : model.edges);
|
|
2106
|
+
return d.reason ? [{
|
|
2107
|
+
message: `${kindHeading(space, d)}; ${d.typed} typed ${space}s`,
|
|
2108
|
+
fix: "review the vocabulary as a whole; merge synonymous kinds and keep meaningful distinctions, including rare ones. Do not add instances just to satisfy a count."
|
|
2109
|
+
}] : [];
|
|
2110
|
+
})
|
|
2107
2111
|
};
|
|
2108
2112
|
var lowCoverage = {
|
|
2109
2113
|
code: "coverage-note",
|
|
@@ -2155,7 +2159,6 @@ var rules = [
|
|
|
2155
2159
|
unevenKinds,
|
|
2156
2160
|
wideNode,
|
|
2157
2161
|
uncoloredKind,
|
|
2158
|
-
singleKind,
|
|
2159
2162
|
kindNote,
|
|
2160
2163
|
colorNote,
|
|
2161
2164
|
lowCoverage
|
|
@@ -2178,7 +2181,8 @@ function checkGraph(model, profile, opts) {
|
|
|
2178
2181
|
labelOf: (id) => model.index.get(id)?.label ?? id
|
|
2179
2182
|
};
|
|
2180
2183
|
const invalidStructure = unknownParent.run(ctx).length > 0 || parentCycle.run(ctx).length > 0;
|
|
2181
|
-
const
|
|
2184
|
+
const applicable = opts.quality === false ? rules.filter((rule) => rule.level === "error") : rules;
|
|
2185
|
+
const out = applicable.filter((rule) => !invalidStructure || rule !== unevenKinds).flatMap((rule) => rule.run(ctx).map((issue) => ({
|
|
2182
2186
|
level: issue.level ?? rule.level,
|
|
2183
2187
|
code: rule.code,
|
|
2184
2188
|
where: opts.where,
|
|
@@ -2221,11 +2225,6 @@ function structureOf(model) {
|
|
|
2221
2225
|
ordered: derived.layers.length > 0 || [...children.keys()].some((id) => orderedChildren(children, id, model.index.get(id)?.data?.unordered === true) !== null)
|
|
2222
2226
|
};
|
|
2223
2227
|
}
|
|
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
2228
|
function hexLab(value) {
|
|
2230
2229
|
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(value.trim());
|
|
2231
2230
|
if (!m) return null;
|
|
@@ -2244,9 +2243,10 @@ function deltaE(a2, b) {
|
|
|
2244
2243
|
|
|
2245
2244
|
// cli/model.ts
|
|
2246
2245
|
function profileFromJson(id, json) {
|
|
2247
|
-
if (!json) return defineProfile({ id });
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2246
|
+
if (!json || checkSchema(profile_schema_default, json, 1).length) return defineProfile({ id });
|
|
2247
|
+
const fields = Object.fromEntries(Object.entries(json).filter(([key]) => Object.hasOwn(profile_schema_default.properties, key)));
|
|
2248
|
+
const kindLabels = { ...json.kindLabels, ...json.edgeLabels };
|
|
2249
|
+
return defineProfile({ id, ...fields, kindLabels });
|
|
2250
2250
|
}
|
|
2251
2251
|
function profileOf(l) {
|
|
2252
2252
|
const json = l.profile;
|
|
@@ -2264,48 +2264,58 @@ function derivedProfile(base2, sources, json, force) {
|
|
|
2264
2264
|
}
|
|
2265
2265
|
var modelOf = (v, profile) => parseSources(v.sources, profile);
|
|
2266
2266
|
var RANK = { error: 0, warn: 1, info: 2 };
|
|
2267
|
-
function
|
|
2267
|
+
function inspectProfile(json) {
|
|
2268
|
+
if (!json) return [];
|
|
2269
|
+
const out = checkSchema(profile_schema_default, json).map((e) => ({ level: "error", code: "schema", where: "_profile.json", message: `${e.path}: ${e.message}` }));
|
|
2270
|
+
if (typeof json !== "object" || Array.isArray(json)) return out;
|
|
2271
|
+
const retired = ["layers", "singleRoot"].filter((k) => k in json);
|
|
2272
|
+
if (retired.length) out.push({
|
|
2273
|
+
level: "warn",
|
|
2274
|
+
code: "schema",
|
|
2275
|
+
where: "_profile.json",
|
|
2276
|
+
message: `${retired.map((k) => `"${k}"`).join(" and ")} no longer configure anything: layers come from the ordered children structure`,
|
|
2277
|
+
fix: 'delete the retired keys from _profile.json. Use "appearance": { "defaultLayers": false } to open flat.'
|
|
2278
|
+
});
|
|
2279
|
+
return out;
|
|
2280
|
+
}
|
|
2281
|
+
function inspectGraph(model, profile, sources, opts) {
|
|
2268
2282
|
const out = [];
|
|
2269
|
-
const
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
}
|
|
2283
|
+
const prefix = opts.prefix ?? "";
|
|
2284
|
+
const notJson = /* @__PURE__ */ new Set();
|
|
2285
|
+
if (opts.native !== false) for (const f of sources) {
|
|
2286
|
+
let doc;
|
|
2287
|
+
try {
|
|
2288
|
+
doc = JSON.parse(f.text);
|
|
2289
|
+
} catch (e) {
|
|
2290
|
+
notJson.add(f.origin);
|
|
2291
|
+
out.push({ level: "error", code: "schema", where: prefix + f.origin, message: `not JSON: ${e.message}` });
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
if (!doc || typeof doc !== "object" || !("nodes" in doc) && !("edges" in doc)) {
|
|
2295
|
+
out.push({ level: "warn", code: "schema", where: prefix + f.origin, message: 'not a graph (no "nodes" or "edges"), skipped' });
|
|
2296
|
+
continue;
|
|
2297
|
+
}
|
|
2298
|
+
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
2299
|
}
|
|
2300
|
+
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 });
|
|
2301
|
+
out.push(...checkGraph(model, profile, { where: opts.where, quality: opts.quality }));
|
|
2302
|
+
if (!model.nodes.length) out.push({ level: "warn", code: "schema", where: opts.where, message: "No nodes found" });
|
|
2303
|
+
return out.sort((a2, b) => RANK[a2.level] - RANK[b.level]);
|
|
2304
|
+
}
|
|
2305
|
+
function lint(loaded) {
|
|
2306
|
+
const out = inspectProfile(loaded.profile);
|
|
2307
|
+
const profile = profileOf(loaded);
|
|
2281
2308
|
for (const e of loaded.metaErrors) out.push({ level: "error", code: "schema", where: e.file, message: e.message });
|
|
2282
2309
|
const latest = loaded.raw[loaded.raw.length - 1]?.version;
|
|
2283
2310
|
for (const { version, files } of loaded.raw) {
|
|
2284
2311
|
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
2312
|
const v = loaded.versions.find((x) => x.name === version);
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2313
|
+
out.push(...inspectGraph(
|
|
2314
|
+
modelOf(v, profile),
|
|
2315
|
+
profile,
|
|
2316
|
+
files.filter((f) => /\.json$/i.test(f.path)).map((f) => ({ origin: f.path, text: f.text })),
|
|
2317
|
+
{ where: prefix || loaded.title, prefix, native: (v.format ?? loaded.format) === "native", quality: version === latest }
|
|
2318
|
+
));
|
|
2309
2319
|
}
|
|
2310
2320
|
return out.sort((a2, b) => RANK[a2.level] - RANK[b.level]);
|
|
2311
2321
|
}
|
|
@@ -2478,6 +2488,10 @@ function tree(model, opts) {
|
|
|
2478
2488
|
};
|
|
2479
2489
|
const structure = structureOf(model);
|
|
2480
2490
|
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")}` : ""} \xB7 structure pressure ${structure.shape.peak.toFixed(3)} \xB7 ${structure.shape.assessed} assessed / ${structure.shape.unassessed} unassessed`;
|
|
2491
|
+
const kinds = { nodes: kindDistribution(model.nodes), edges: kindDistribution(model.edges) };
|
|
2492
|
+
header += `
|
|
2493
|
+
${kindSummary("node", kinds.nodes, opts.kindLabels)}
|
|
2494
|
+
${kindSummary("edge", kinds.edges, opts.kindLabels)}`;
|
|
2481
2495
|
const roots = model.nodes.filter((n) => !n.parent || broken(n));
|
|
2482
2496
|
if (opts.path) {
|
|
2483
2497
|
const start = model.index.get(opts.path);
|
|
@@ -2520,7 +2534,7 @@ path: ${[...chain, labelOf(start.id)].join(" \u203A ")}`;
|
|
|
2520
2534
|
}
|
|
2521
2535
|
}
|
|
2522
2536
|
const more = Math.max(0, entries.length - maxLines);
|
|
2523
|
-
return { header, entries: more ? entries.slice(0, maxLines) : entries, more };
|
|
2537
|
+
return { header, kinds, entries: more ? entries.slice(0, maxLines) : entries, more };
|
|
2524
2538
|
}
|
|
2525
2539
|
function treeText(result) {
|
|
2526
2540
|
const lines = [result.header, ...result.entries.map((e) => e.text)];
|
|
@@ -2733,7 +2747,7 @@ var HELP = (schema) => `glassbrain: open, diff and lint a knowledge graph, writt
|
|
|
2733
2747
|
GUIDELINES
|
|
2734
2748
|
* \`id\` identifies a node; nest it in \`children\` in reading order. Recommend \`kind\` for its category.
|
|
2735
2749
|
* Children structure helps readability. Prefer fewer than 5 children; keep natural collections. Consider deeper grouping if crowded.
|
|
2736
|
-
*
|
|
2750
|
+
* Reuse consistent node and edge kinds; check their distributions with tree.
|
|
2737
2751
|
* Keep depth and detail meaningful. Lint flags structural imbalance as \`bad-structure\`.
|
|
2738
2752
|
* Put supporting details in descriptions. Extra fields are kept and shown.
|
|
2739
2753
|
|
|
@@ -2758,7 +2772,7 @@ var HELP = (schema) => `glassbrain: open, diff and lint a knowledge graph, writt
|
|
|
2758
2772
|
A local pass profile overrides it; an exported bundle carries its own profile.
|
|
2759
2773
|
|
|
2760
2774
|
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
|
|
2775
|
+
every uncoloured kind looks the same, so lint reports it as a warning.
|
|
2762
2776
|
{ "nodePalette": { "file": "#6366f1", "folder": "#94a3b8" },
|
|
2763
2777
|
"edgePalette": { "uses": "#2563eb" } }
|
|
2764
2778
|
Colors closer than 10 in Lab distance read as one kind (lint notes it).
|
|
@@ -3010,13 +3024,14 @@ function runTree(a2) {
|
|
|
3010
3024
|
if (latest.errors.length) fail(latest.errors.map((e) => `${e.origin}: ${e.message}`).join("\n"), 1);
|
|
3011
3025
|
const version = l.versions[l.versions.length - 1].name;
|
|
3012
3026
|
const result = tree(latest, {
|
|
3027
|
+
kindLabels: profileOf(l).kindLabels,
|
|
3013
3028
|
title: l.versions.length > 1 ? `${l.title}/${version}` : l.title,
|
|
3014
3029
|
depth,
|
|
3015
3030
|
path: typeof a2.flags.path === "string" ? a2.flags.path : void 0,
|
|
3016
3031
|
orphans: a2.flags.orphans === true
|
|
3017
3032
|
});
|
|
3018
3033
|
if (a2.flags.json) {
|
|
3019
|
-
console.log(JSON.stringify({ title: l.title, ...structureOf(latest), entries: result.entries, more: result.more }, null, 1));
|
|
3034
|
+
console.log(JSON.stringify({ title: l.title, ...structureOf(latest), kinds: result.kinds, entries: result.entries, more: result.more }, null, 1));
|
|
3020
3035
|
} else {
|
|
3021
3036
|
console.log(treeText(result));
|
|
3022
3037
|
}
|
|
@@ -3069,8 +3084,8 @@ function runRestructure(a2) {
|
|
|
3069
3084
|
const abs = path2.resolve(a2.pos[0]);
|
|
3070
3085
|
const dir = fs2.existsSync(abs) && fs2.statSync(abs).isDirectory() ? abs : path2.dirname(abs);
|
|
3071
3086
|
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" };
|
|
3087
|
+
const palette = kindTable();
|
|
3088
|
+
const known = kindTable({ folder: "#94a3b8", file: "#64748b", overview: "#a855f7", group: "#a855f7" });
|
|
3074
3089
|
const wheel = ["#6366f1", "#f59e0b", "#10b981", "#ef4444", "#8b5cf6", "#06b6d4"];
|
|
3075
3090
|
let wi = 0;
|
|
3076
3091
|
for (const k of new Set(plan.nodes.map((n) => n.kind))) {
|