glassbrain 0.2.0-alpha.2 → 0.2.0-alpha.3
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 +10 -2
- package/dist/adapters/graphify.d.ts +3 -0
- package/dist/adapters/understand.d.ts +3 -0
- package/dist/adapters.js +18 -3
- package/dist/chunks/{chunk-TM27EXYP.js → chunk-7C3QZVGJ.js} +58 -10
- package/dist/chunks/{chunk-F3DN7SLR.js → chunk-H2WV3DTN.js} +4 -0
- package/dist/chunks/{chunk-ZHPUQDOJ.js → chunk-PBF4KMQB.js} +1 -1
- package/dist/chunks/chunk-QJ4B3U76.js +68 -0
- package/dist/chunks/{chunk-7R6PO7AE.js → chunk-WW23WBYG.js} +2 -1
- package/dist/cli/glassbrain.js +120 -30
- package/dist/cli/viewer.js +43 -43
- package/dist/core.d.ts +1 -0
- package/dist/core.js +14 -3
- package/dist/index.js +16 -5
- package/dist/internal.js +16 -5
- package/dist/layers.d.ts +1 -1
- package/dist/react/DetailPanel.js +2 -2
- package/dist/react/GraphCanvas.d.ts +4 -0
- package/dist/react/GraphCanvas.js +4 -4
- package/dist/react/Toolbar.d.ts +3 -0
- package/dist/strings.d.ts +4 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-LEYJCT6O.js +0 -0
package/README.md
CHANGED
|
@@ -31,6 +31,14 @@ lets you read one at a glance, and when the agent learns something, shows you ex
|
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
Next to it, one colour per kind — a kind with no colour is drawn as skeleton, so `validate` reports
|
|
35
|
+
it as an error (forty kinds without colours look exactly like one kind):
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{ "nodePalette": { "folder": "#94a3b8", "file": "#6366f1" },
|
|
39
|
+
"edgePalette": { "uses": "#2563eb" } }
|
|
40
|
+
```
|
|
41
|
+
|
|
34
42
|
`parent` is required on every node (null for the one root) and says what sits inside what: that is
|
|
35
43
|
the whole structure. `order`, optional, turns the children of one node into a numbered list — the
|
|
36
44
|
layout reads it clockwise, and a numbered root *is* the 2.5D layer view. There is no layer field.
|
|
@@ -44,8 +52,8 @@ error dangling-edge graph.json edge src/auth/login.ts → src/session points
|
|
|
44
52
|
- { "source": "src/auth/login.ts", "target": "src/session" }
|
|
45
53
|
+ { "source": "src/auth/login.ts", "target": "EXISTING_ID" }
|
|
46
54
|
|
|
47
|
-
kg:
|
|
48
|
-
structure: 1 root · depth 2 · 1/
|
|
55
|
+
kg: 2 nodes, 1 edge — 1 error · 0 warnings · 0 infos
|
|
56
|
+
structure: 1 root · depth 2 · 1/2 parented · isomorphism 1.00
|
|
49
57
|
|
|
50
58
|
$ npx glassbrain diff kg/1-skeleton kg/2-filled
|
|
51
59
|
1-skeleton → 2-filled
|
package/dist/adapters.js
CHANGED
|
@@ -103,7 +103,18 @@ function convertGraphify(d, name) {
|
|
|
103
103
|
var score = (l) => typeof l.confidence_score === "number" ? l.confidence_score : typeof l.weight === "number" ? Math.min(1, l.weight) : void 0;
|
|
104
104
|
var groupLabel = (t) => ({ concept: "Concepts", rationale: "Rationale", document: "Documents" })[t] ?? t;
|
|
105
105
|
var PROFILE = {
|
|
106
|
-
|
|
106
|
+
// The adapter invents these three while building the folder / file boxes, so it must colour them too.
|
|
107
|
+
nodePalette: {
|
|
108
|
+
symbol: "#6366f1",
|
|
109
|
+
concept: "#e63b7a",
|
|
110
|
+
rationale: "#f59e0b",
|
|
111
|
+
document: "#0891b2",
|
|
112
|
+
paper: "#0891b2",
|
|
113
|
+
image: "#16a34a",
|
|
114
|
+
folder: "#94a3b8",
|
|
115
|
+
file: "#64748b",
|
|
116
|
+
group: "#a855f7"
|
|
117
|
+
},
|
|
107
118
|
edgePalette: {
|
|
108
119
|
calls: "#6366f1",
|
|
109
120
|
imports: "#94a3b8",
|
|
@@ -318,7 +329,8 @@ var obsidian = {
|
|
|
318
329
|
return {
|
|
319
330
|
sources,
|
|
320
331
|
profile: {
|
|
321
|
-
|
|
332
|
+
// `folder` is invented by the walk, not present in frontmatter kinds: colour it here.
|
|
333
|
+
nodePalette: { ...autoPalette(kinds), folder: "#94a3b8" },
|
|
322
334
|
edgePalette: { link: "#94a3b8" },
|
|
323
335
|
kindLabels: { folder: "Folder", note: "Note", link: "link" },
|
|
324
336
|
detail: { line: [{ key: "path", label: "File" }], list: [{ key: "tags", label: "Tags" }] },
|
|
@@ -409,7 +421,10 @@ var PROFILE2 = {
|
|
|
409
421
|
source: "#64748b",
|
|
410
422
|
screen: "#0891b2",
|
|
411
423
|
component: "#6366f1",
|
|
412
|
-
token: "#f59e0b"
|
|
424
|
+
token: "#f59e0b",
|
|
425
|
+
layer: "#a855f7",
|
|
426
|
+
folder: "#94a3b8",
|
|
427
|
+
file: "#64748b"
|
|
413
428
|
},
|
|
414
429
|
edgePalette: {
|
|
415
430
|
imports: "#94a3b8",
|
|
@@ -52,17 +52,17 @@ import {
|
|
|
52
52
|
unionSides,
|
|
53
53
|
untheme,
|
|
54
54
|
validateModel
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-WW23WBYG.js";
|
|
56
56
|
import {
|
|
57
57
|
DetailPanel,
|
|
58
58
|
I,
|
|
59
59
|
Icon,
|
|
60
60
|
StringsContext,
|
|
61
61
|
useStrings
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-PBF4KMQB.js";
|
|
63
63
|
import {
|
|
64
64
|
EN
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-H2WV3DTN.js";
|
|
66
66
|
import {
|
|
67
67
|
inlinePool
|
|
68
68
|
} from "./chunk-YGRPNAXE.js";
|
|
@@ -1802,6 +1802,48 @@ function LayerPicker({ layers, view, setView, disabled }) {
|
|
|
1802
1802
|
)
|
|
1803
1803
|
] });
|
|
1804
1804
|
}
|
|
1805
|
+
function LayerUnavailable(p) {
|
|
1806
|
+
const t = useStrings();
|
|
1807
|
+
const pop = usePopover(MENU_PLACE);
|
|
1808
|
+
return /* @__PURE__ */ jsxs("div", { className: "gb-menu", ref: pop.ref, children: [
|
|
1809
|
+
/* @__PURE__ */ jsx(
|
|
1810
|
+
"button",
|
|
1811
|
+
{
|
|
1812
|
+
className: "gb-icon-btn",
|
|
1813
|
+
style: { opacity: 0.45 },
|
|
1814
|
+
"aria-label": t.layersOff,
|
|
1815
|
+
title: t.layersOff,
|
|
1816
|
+
"aria-expanded": pop.open,
|
|
1817
|
+
onClick: () => pop.setOpen(!pop.open),
|
|
1818
|
+
children: /* @__PURE__ */ jsx(Icon, { d: I.stack })
|
|
1819
|
+
}
|
|
1820
|
+
),
|
|
1821
|
+
pop.open && /* @__PURE__ */ jsxs(
|
|
1822
|
+
"div",
|
|
1823
|
+
{
|
|
1824
|
+
ref: pop.panelRef,
|
|
1825
|
+
className: "gb-panel",
|
|
1826
|
+
role: "dialog",
|
|
1827
|
+
"data-x": pop.placement?.align,
|
|
1828
|
+
"data-y": pop.placement?.side,
|
|
1829
|
+
style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
|
|
1830
|
+
children: [
|
|
1831
|
+
/* @__PURE__ */ jsxs("div", { className: "gb-panel-sec", children: [
|
|
1832
|
+
/* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.layersOff }),
|
|
1833
|
+
/* @__PURE__ */ jsx("p", { style: { margin: "4px 0 0", maxWidth: 260, fontSize: 12, lineHeight: 1.45, opacity: 0.75 }, children: p.reason })
|
|
1834
|
+
] }),
|
|
1835
|
+
/* @__PURE__ */ jsxs("div", { className: "gb-panel-sec gb-menu-list", children: [
|
|
1836
|
+
p.onForce && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: () => {
|
|
1837
|
+
pop.setOpen(false);
|
|
1838
|
+
p.onForce();
|
|
1839
|
+
}, children: t.forceLayers }),
|
|
1840
|
+
/* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: () => pop.setOpen(false), children: t.ok })
|
|
1841
|
+
] })
|
|
1842
|
+
]
|
|
1843
|
+
}
|
|
1844
|
+
)
|
|
1845
|
+
] });
|
|
1846
|
+
}
|
|
1805
1847
|
var MENU_PLACE = { side: "bottom", align: "start" };
|
|
1806
1848
|
var ISSUES_PLACE = { side: "top", align: "end" };
|
|
1807
1849
|
function usePopover(prefer) {
|
|
@@ -2006,6 +2048,7 @@ function Toolbar(p) {
|
|
|
2006
2048
|
}
|
|
2007
2049
|
),
|
|
2008
2050
|
multi && /* @__PURE__ */ jsx(LayerPicker, { layers: p.layers, view, setView, disabled: p.busy }),
|
|
2051
|
+
controls.layers && !multi && /* @__PURE__ */ jsx(LayerUnavailable, { reason: p.layerIssue ?? "", onForce: p.onForceLayers }),
|
|
2009
2052
|
originPick && view.origins?.length === 1 && /* Filtering by source: the state is in plain sight, and one × returns to everything. */
|
|
2010
2053
|
/* @__PURE__ */ jsxs("span", { className: "gb-chip", title: view.origins[0], children: [
|
|
2011
2054
|
/* @__PURE__ */ jsx(Icon, { d: I.file, size: 13 }),
|
|
@@ -2846,7 +2889,7 @@ function tally(model, profile) {
|
|
|
2846
2889
|
let plain = 0;
|
|
2847
2890
|
for (const n of model.nodes) {
|
|
2848
2891
|
const hollow = !!n.flags?.some((f) => profile.placeholderFlags.includes(f));
|
|
2849
|
-
if (!hollow && n.kind
|
|
2892
|
+
if (!hollow && n.kind) nodes[n.kind] = (nodes[n.kind] ?? 0) + 1;
|
|
2850
2893
|
else plain++;
|
|
2851
2894
|
}
|
|
2852
2895
|
for (const e of model.edges) if (e.kind && e.kind in profile.edgePalette) edges[e.kind] = (edges[e.kind] ?? 0) + 1;
|
|
@@ -3155,7 +3198,7 @@ function Legend(p) {
|
|
|
3155
3198
|
picking: (on) => setPicking(on)
|
|
3156
3199
|
}), [close]);
|
|
3157
3200
|
const slot = (key) => ({ k: key, open: open === key, ctl });
|
|
3158
|
-
const nodeKinds = Object.keys(
|
|
3201
|
+
const nodeKinds = Object.keys(count.nodes).sort((a, b) => count.nodes[b] - count.nodes[a] || a.localeCompare(b));
|
|
3159
3202
|
const edgeKinds = Object.keys(profile.edgePalette).filter((k) => count.edges[k]);
|
|
3160
3203
|
const markCache = useRef3({ cy: null, style: null, shapes: /* @__PURE__ */ new Map(), strokes: /* @__PURE__ */ new Map() });
|
|
3161
3204
|
const marks = readMarks(markCache.current, p.cy, profile.style, nodeKinds, edgeKinds);
|
|
@@ -3169,6 +3212,7 @@ function Legend(p) {
|
|
|
3169
3212
|
const set = (key, kind, v) => onLook({ ...look, [key]: { ...look[key], [kind]: v } });
|
|
3170
3213
|
const setSkeleton = (c) => onLook({ ...look, skeleton: c });
|
|
3171
3214
|
const name = (k) => profile.kindLabels[k] ?? k;
|
|
3215
|
+
const colorOfKind = (k) => profile.nodePalette[k] ?? theme.skeleton;
|
|
3172
3216
|
const shown = (c) => themeColor(theme, c);
|
|
3173
3217
|
const content = p.collapsed ? /* @__PURE__ */ jsx3(
|
|
3174
3218
|
"button",
|
|
@@ -3185,7 +3229,7 @@ function Legend(p) {
|
|
|
3185
3229
|
/* @__PURE__ */ jsxs3("div", { className: "gb-lg-body", children: [
|
|
3186
3230
|
p.caption && /* @__PURE__ */ jsx3("div", { className: "gb-lg-cap", children: p.caption }),
|
|
3187
3231
|
/* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
|
|
3188
|
-
/* @__PURE__ */ jsx3(
|
|
3232
|
+
count.plain > 0 && /* @__PURE__ */ jsx3(
|
|
3189
3233
|
Item,
|
|
3190
3234
|
{
|
|
3191
3235
|
...slot("n:"),
|
|
@@ -3204,15 +3248,15 @@ function Legend(p) {
|
|
|
3204
3248
|
Item,
|
|
3205
3249
|
{
|
|
3206
3250
|
...slot(`n:${k}`),
|
|
3207
|
-
color: shown(
|
|
3208
|
-
title: name(k)
|
|
3251
|
+
color: shown(colorOfKind(k)),
|
|
3252
|
+
title: profile.nodePalette[k] ? name(k) : `${name(k)} \u2014 ${t.noColor}`,
|
|
3209
3253
|
off,
|
|
3210
3254
|
onToggle: () => p.onToggle("nodes", k),
|
|
3211
3255
|
onPick: (c) => set("nodePalette", k, untheme(theme, c)),
|
|
3212
3256
|
scale,
|
|
3213
3257
|
glyph: "dot",
|
|
3214
3258
|
onScale: (s) => set("nodeSize", k, s),
|
|
3215
|
-
mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(
|
|
3259
|
+
mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(colorOfKind(k)), shape: marks.shape(k), ring: theme.canvas, off, scale }),
|
|
3216
3260
|
label: name(k),
|
|
3217
3261
|
count: count.nodes[k]
|
|
3218
3262
|
},
|
|
@@ -3737,6 +3781,8 @@ function GraphCanvas(props) {
|
|
|
3737
3781
|
renderEditor,
|
|
3738
3782
|
resolveUrl,
|
|
3739
3783
|
onRestructure,
|
|
3784
|
+
layerIssue,
|
|
3785
|
+
onForceLayers,
|
|
3740
3786
|
animate = true,
|
|
3741
3787
|
matchKey,
|
|
3742
3788
|
onTransition,
|
|
@@ -5679,7 +5725,9 @@ ${lt}`;
|
|
|
5679
5725
|
inputRef: searchInputRef,
|
|
5680
5726
|
onAdd: editable ? startAdd : void 0,
|
|
5681
5727
|
onRelayout: controls.relayout && !diff ? relayout : void 0,
|
|
5682
|
-
onRestructure: controls.relayout && !diff ? onRestructure : void 0
|
|
5728
|
+
onRestructure: controls.relayout && !diff ? onRestructure : void 0,
|
|
5729
|
+
layerIssue,
|
|
5730
|
+
onForceLayers
|
|
5683
5731
|
}
|
|
5684
5732
|
),
|
|
5685
5733
|
(note || model.errors.length > 0 || legend && !compact) && /* Bottom left: the host's caption (if any) on top, the legend below. Top left is tools, bottom right is the camera. */
|
|
@@ -22,6 +22,9 @@ var EN = {
|
|
|
22
22
|
stackLayer: (l, on) => `${on ? "Hide" : "Stack"} \u201C${l}\u201D`,
|
|
23
23
|
stack: "Stack layers",
|
|
24
24
|
stackTip: (on) => on ? "Stacked (turn off to view one layer at a time)" : "Stack layers (2.5D)",
|
|
25
|
+
layersOff: "Layers are off",
|
|
26
|
+
forceLayers: "Open the floors anyway",
|
|
27
|
+
ok: "OK",
|
|
25
28
|
more: "More",
|
|
26
29
|
origins: "Source",
|
|
27
30
|
allOrigins: "All sources",
|
|
@@ -34,6 +37,7 @@ var EN = {
|
|
|
34
37
|
fit: "Fit (0)",
|
|
35
38
|
legend: "Legend",
|
|
36
39
|
legendPlainName: "Default",
|
|
40
|
+
noColor: "no colour set",
|
|
37
41
|
legendPlain: "Nodes without a color of their own: containers and placeholders, shaded by how much hangs under them",
|
|
38
42
|
legendContainsName: "Contains",
|
|
39
43
|
legendHint: "Hover an item: color, hide, size",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/layers.ts
|
|
2
|
+
var MAX_DERIVED_LAYERS = 8;
|
|
3
|
+
var EMPTY = { layers: [], layerOf: /* @__PURE__ */ new Map() };
|
|
4
|
+
function orderedChildren(children, id) {
|
|
5
|
+
const kids = children.get(id) ?? [];
|
|
6
|
+
if (kids.length < 2) return null;
|
|
7
|
+
const withOrder = kids.filter((n) => typeof n.order === "number" && Number.isFinite(n.order));
|
|
8
|
+
if (withOrder.length !== kids.length) return null;
|
|
9
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10
|
+
for (const k of withOrder) {
|
|
11
|
+
if (seen.has(k.order)) return null;
|
|
12
|
+
seen.add(k.order);
|
|
13
|
+
}
|
|
14
|
+
return [...kids].sort((a, b) => a.order - b.order);
|
|
15
|
+
}
|
|
16
|
+
function childrenMap(model) {
|
|
17
|
+
const out = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const n of model.nodes) {
|
|
19
|
+
if (!n.parent || !model.index.has(n.parent)) continue;
|
|
20
|
+
const arr = out.get(n.parent);
|
|
21
|
+
arr ? arr.push(n) : out.set(n.parent, [n]);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
function deriveLayers(model, colors = [], force = false) {
|
|
26
|
+
if (!model.nodes.length) return EMPTY;
|
|
27
|
+
const children = childrenMap(model);
|
|
28
|
+
const roots = model.nodes.filter((n) => !n.parent || !model.index.has(n.parent));
|
|
29
|
+
let ordered = null;
|
|
30
|
+
let anchor;
|
|
31
|
+
if (roots.length === 1) {
|
|
32
|
+
anchor = roots[0];
|
|
33
|
+
ordered = orderedChildren(children, anchor.id);
|
|
34
|
+
if (!ordered && force) ordered = children.get(anchor.id) ?? null;
|
|
35
|
+
} else if (force && roots.length > 1) {
|
|
36
|
+
ordered = roots;
|
|
37
|
+
}
|
|
38
|
+
if (!ordered || ordered.length < 2 || ordered.length > MAX_DERIVED_LAYERS) return EMPTY;
|
|
39
|
+
const layers = ordered.map((n, i) => ({
|
|
40
|
+
id: n.id,
|
|
41
|
+
label: n.label || n.id,
|
|
42
|
+
z: i,
|
|
43
|
+
...colors[i] ? { color: colors[i] } : {}
|
|
44
|
+
}));
|
|
45
|
+
const layerOf = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const [i, layer] of ordered.entries()) {
|
|
47
|
+
const stack = [layer.id];
|
|
48
|
+
while (stack.length) {
|
|
49
|
+
const id = stack.pop();
|
|
50
|
+
layerOf.set(id, layers[i].id);
|
|
51
|
+
for (const k of children.get(id) ?? []) stack.push(k.id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (anchor) layerOf.set(anchor.id, layers[0].id);
|
|
55
|
+
return { layers, layerOf, anchor: anchor?.id };
|
|
56
|
+
}
|
|
57
|
+
function layerIndexOf(derived, id) {
|
|
58
|
+
const lid = derived.layerOf.get(id);
|
|
59
|
+
return lid ? derived.layers.findIndex((l) => l.id === lid) : -1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
MAX_DERIVED_LAYERS,
|
|
64
|
+
orderedChildren,
|
|
65
|
+
childrenMap,
|
|
66
|
+
deriveLayers,
|
|
67
|
+
layerIndexOf
|
|
68
|
+
};
|
|
@@ -128,7 +128,8 @@ function toPhysical(model) {
|
|
|
128
128
|
const clean = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== ""));
|
|
129
129
|
return {
|
|
130
130
|
// `layer` is derived, never written: a file that gains it would freeze a view decision into the data.
|
|
131
|
-
|
|
131
|
+
// `parent` is always written, `null` for a root: dropping it (it was `undefined`) made every export invalid in 0.2.
|
|
132
|
+
nodes: model.nodes.map((n) => clean({ ...n.data, id: n.id, label: n.label, kind: n.kind, parent: n.parent ?? null, order: n.order })),
|
|
132
133
|
edges: model.edges.map((e) => clean({ ...e.data, source: e.source, target: e.target, kind: e.kind, label: e.label, weight: e.weight }))
|
|
133
134
|
};
|
|
134
135
|
}
|
package/dist/cli/glassbrain.js
CHANGED
|
@@ -132,7 +132,8 @@ function toPhysical(model) {
|
|
|
132
132
|
const clean2 = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== ""));
|
|
133
133
|
return {
|
|
134
134
|
// `layer` is derived, never written: a file that gains it would freeze a view decision into the data.
|
|
135
|
-
|
|
135
|
+
// `parent` is always written, `null` for a root: dropping it (it was `undefined`) made every export invalid in 0.2.
|
|
136
|
+
nodes: model.nodes.map((n) => clean2({ ...n.data, id: n.id, label: n.label, kind: n.kind, parent: n.parent ?? null, order: n.order })),
|
|
136
137
|
edges: model.edges.map((e) => clean2({ ...e.data, source: e.source, target: e.target, kind: e.kind, label: e.label, weight: e.weight }))
|
|
137
138
|
};
|
|
138
139
|
}
|
|
@@ -317,7 +318,18 @@ function convertGraphify(d, name) {
|
|
|
317
318
|
var score = (l) => typeof l.confidence_score === "number" ? l.confidence_score : typeof l.weight === "number" ? Math.min(1, l.weight) : void 0;
|
|
318
319
|
var groupLabel = (t) => ({ concept: "Concepts", rationale: "Rationale", document: "Documents" })[t] ?? t;
|
|
319
320
|
var PROFILE = {
|
|
320
|
-
|
|
321
|
+
// The adapter invents these three while building the folder / file boxes, so it must colour them too.
|
|
322
|
+
nodePalette: {
|
|
323
|
+
symbol: "#6366f1",
|
|
324
|
+
concept: "#e63b7a",
|
|
325
|
+
rationale: "#f59e0b",
|
|
326
|
+
document: "#0891b2",
|
|
327
|
+
paper: "#0891b2",
|
|
328
|
+
image: "#16a34a",
|
|
329
|
+
folder: "#94a3b8",
|
|
330
|
+
file: "#64748b",
|
|
331
|
+
group: "#a855f7"
|
|
332
|
+
},
|
|
321
333
|
edgePalette: {
|
|
322
334
|
calls: "#6366f1",
|
|
323
335
|
imports: "#94a3b8",
|
|
@@ -532,7 +544,8 @@ var obsidian = {
|
|
|
532
544
|
return {
|
|
533
545
|
sources,
|
|
534
546
|
profile: {
|
|
535
|
-
|
|
547
|
+
// `folder` is invented by the walk, not present in frontmatter kinds: colour it here.
|
|
548
|
+
nodePalette: { ...autoPalette(kinds), folder: "#94a3b8" },
|
|
536
549
|
edgePalette: { link: "#94a3b8" },
|
|
537
550
|
kindLabels: { folder: "Folder", note: "Note", link: "link" },
|
|
538
551
|
detail: { line: [{ key: "path", label: "File" }], list: [{ key: "tags", label: "Tags" }] },
|
|
@@ -623,7 +636,10 @@ var PROFILE2 = {
|
|
|
623
636
|
source: "#64748b",
|
|
624
637
|
screen: "#0891b2",
|
|
625
638
|
component: "#6366f1",
|
|
626
|
-
token: "#f59e0b"
|
|
639
|
+
token: "#f59e0b",
|
|
640
|
+
layer: "#a855f7",
|
|
641
|
+
folder: "#94a3b8",
|
|
642
|
+
file: "#64748b"
|
|
627
643
|
},
|
|
628
644
|
edgePalette: {
|
|
629
645
|
imports: "#94a3b8",
|
|
@@ -760,9 +776,23 @@ function gitSpec(spec, cwd) {
|
|
|
760
776
|
return { files, title, isDir: true };
|
|
761
777
|
}
|
|
762
778
|
var META = /* @__PURE__ */ new Set(["_profile.json", "_layout.json"]);
|
|
779
|
+
function mergeProfile(base2, over) {
|
|
780
|
+
const pal = (a2, b) => ({ ...a2 && typeof a2 === "object" ? a2 : {}, ...b && typeof b === "object" ? b : {} });
|
|
781
|
+
return {
|
|
782
|
+
...base2,
|
|
783
|
+
...over,
|
|
784
|
+
nodePalette: pal(base2.nodePalette, over.nodePalette),
|
|
785
|
+
edgePalette: pal(base2.edgePalette, over.edgePalette),
|
|
786
|
+
kindLabels: pal(base2.kindLabels, over.kindLabels)
|
|
787
|
+
};
|
|
788
|
+
}
|
|
763
789
|
var natural = (a2, b) => a2.localeCompare(b, void 0, { numeric: true });
|
|
764
790
|
function load(spec, opts = {}) {
|
|
765
791
|
const tree2 = readSpec(spec, opts.cwd);
|
|
792
|
+
if (!tree2.isDir) {
|
|
793
|
+
const beside = path.join(path.dirname(path.resolve(opts.cwd ?? process.cwd(), spec)), "_profile.json");
|
|
794
|
+
if (fs.existsSync(beside)) tree2.files.push({ path: "_profile.json", text: fs.readFileSync(beside, "utf8") });
|
|
795
|
+
}
|
|
766
796
|
const metaErrors = [];
|
|
767
797
|
const meta = (name) => {
|
|
768
798
|
const f = tree2.files.find((x) => x.path === name);
|
|
@@ -774,6 +804,16 @@ function load(spec, opts = {}) {
|
|
|
774
804
|
return null;
|
|
775
805
|
}
|
|
776
806
|
};
|
|
807
|
+
const bundled = () => {
|
|
808
|
+
if (tree2.isDir || tree2.files.length !== 1) return null;
|
|
809
|
+
try {
|
|
810
|
+
const d = JSON.parse(tree2.files[0].text);
|
|
811
|
+
return d && typeof d === "object" && d.profile && typeof d.profile === "object" ? d.profile : null;
|
|
812
|
+
} catch {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
const explicit = meta("_profile.json") ?? bundled();
|
|
777
817
|
const data = tree2.files.filter((f) => !META.has(f.path));
|
|
778
818
|
const isJson = (f) => /\.json$/i.test(f.path);
|
|
779
819
|
const dirs = [...new Set(data.filter((f) => f.path.includes("/")).map((f) => f.path.split("/")[0]))].sort(natural);
|
|
@@ -794,7 +834,9 @@ function load(spec, opts = {}) {
|
|
|
794
834
|
return {
|
|
795
835
|
title: tree2.title,
|
|
796
836
|
versions,
|
|
797
|
-
|
|
837
|
+
// A `_profile.json` that only carries demo metadata used to *replace* the adapter's profile, taking its palette
|
|
838
|
+
// with it: a converted graph then drew every kind as skeleton. Explicit keys win; the adapter fills the rest.
|
|
839
|
+
profile: explicit && suggested ? mergeProfile(suggested, explicit) : explicit ?? suggested,
|
|
798
840
|
layouts: meta("_layout.json"),
|
|
799
841
|
format,
|
|
800
842
|
metaErrors,
|
|
@@ -1006,14 +1048,20 @@ function childrenMap(model) {
|
|
|
1006
1048
|
}
|
|
1007
1049
|
return out;
|
|
1008
1050
|
}
|
|
1009
|
-
function deriveLayers(model, colors = []) {
|
|
1051
|
+
function deriveLayers(model, colors = [], force = false) {
|
|
1010
1052
|
if (!model.nodes.length) return EMPTY;
|
|
1011
1053
|
const children = childrenMap(model);
|
|
1012
1054
|
const roots = model.nodes.filter((n) => !n.parent || !model.index.has(n.parent));
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1055
|
+
let ordered = null;
|
|
1056
|
+
let anchor;
|
|
1057
|
+
if (roots.length === 1) {
|
|
1058
|
+
anchor = roots[0];
|
|
1059
|
+
ordered = orderedChildren(children, anchor.id);
|
|
1060
|
+
if (!ordered && force) ordered = children.get(anchor.id) ?? null;
|
|
1061
|
+
} else if (force && roots.length > 1) {
|
|
1062
|
+
ordered = roots;
|
|
1063
|
+
}
|
|
1064
|
+
if (!ordered || ordered.length < 2 || ordered.length > MAX_DERIVED_LAYERS) return EMPTY;
|
|
1017
1065
|
const layers = ordered.map((n, i) => ({
|
|
1018
1066
|
id: n.id,
|
|
1019
1067
|
label: n.label || n.id,
|
|
@@ -1029,8 +1077,8 @@ function deriveLayers(model, colors = []) {
|
|
|
1029
1077
|
for (const k of children.get(id) ?? []) stack.push(k.id);
|
|
1030
1078
|
}
|
|
1031
1079
|
}
|
|
1032
|
-
layerOf.set(anchor.id, layers[0].id);
|
|
1033
|
-
return { layers, layerOf, anchor: anchor
|
|
1080
|
+
if (anchor) layerOf.set(anchor.id, layers[0].id);
|
|
1081
|
+
return { layers, layerOf, anchor: anchor?.id };
|
|
1034
1082
|
}
|
|
1035
1083
|
|
|
1036
1084
|
// schema/graph.schema.json
|
|
@@ -1581,6 +1629,37 @@ var wideNode = {
|
|
|
1581
1629
|
return out;
|
|
1582
1630
|
}
|
|
1583
1631
|
};
|
|
1632
|
+
var uncoloredKind = {
|
|
1633
|
+
code: "uncolored-kind",
|
|
1634
|
+
level: "error",
|
|
1635
|
+
run: ({ model, profile }) => {
|
|
1636
|
+
const used = [...new Set(model.nodes.map((n) => n.kind).filter((k) => !!k))];
|
|
1637
|
+
const missing = used.filter((k) => !(k in profile.nodePalette));
|
|
1638
|
+
if (!missing.length) return [];
|
|
1639
|
+
const shown = missing.slice(0, 5);
|
|
1640
|
+
const palette = Object.fromEntries(shown.map((k, i) => [k, ["#6366f1", "#f59e0b", "#10b981", "#ef4444", "#8b5cf6"][i % 5]]));
|
|
1641
|
+
return [{
|
|
1642
|
+
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)}`,
|
|
1643
|
+
fix: `add one colour per kind to _profile.json (one entry per kind, not per node):
|
|
1644
|
+
{ "nodePalette": ${JSON.stringify(palette)} }
|
|
1645
|
+
${missing.length > shown.length ? ` \u2026 and ${missing.length - shown.length} more; every kind in the data needs an entry.
|
|
1646
|
+
` : ""} Colors that land closer than 10 in Lab distance read as one kind (validate notes it).`
|
|
1647
|
+
}];
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
var singleKind = {
|
|
1651
|
+
code: "single-kind",
|
|
1652
|
+
level: "warn",
|
|
1653
|
+
run: ({ model }) => {
|
|
1654
|
+
const used = new Set(model.nodes.map((n) => n.kind).filter(Boolean));
|
|
1655
|
+
if (used.size !== 1 || model.nodes.length < MIN_SAMPLE) return [];
|
|
1656
|
+
return [{
|
|
1657
|
+
message: `every node has kind "${[...used][0]}"; a single kind tells the reader nothing about what differs`,
|
|
1658
|
+
fix: `split it by what the node is for. The palette only shows differences it has a colour for:
|
|
1659
|
+
{ "nodePalette": { "${[...used][0]}": "#6366f1", "concept": "#f59e0b", "person": "#10b981" } }`
|
|
1660
|
+
}];
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1584
1663
|
var preferFewerKinds = {
|
|
1585
1664
|
code: "prefer-fewer-kinds",
|
|
1586
1665
|
level: "info",
|
|
@@ -1669,6 +1748,8 @@ var rules = [
|
|
|
1669
1748
|
noHierarchy,
|
|
1670
1749
|
unevenBranches,
|
|
1671
1750
|
wideNode,
|
|
1751
|
+
uncoloredKind,
|
|
1752
|
+
singleKind,
|
|
1672
1753
|
preferFewerKinds,
|
|
1673
1754
|
loneKind,
|
|
1674
1755
|
lowCoverage,
|
|
@@ -1783,12 +1864,12 @@ function profileOf(l) {
|
|
|
1783
1864
|
const base2 = profileFromJson("cli", json);
|
|
1784
1865
|
const latest = l.versions[l.versions.length - 1];
|
|
1785
1866
|
if (!latest) return base2;
|
|
1786
|
-
return derivedProfile(base2, latest.sources, json);
|
|
1867
|
+
return derivedProfile(base2, latest.sources, json, false);
|
|
1787
1868
|
}
|
|
1788
|
-
function derivedProfile(base2, sources, json) {
|
|
1869
|
+
function derivedProfile(base2, sources, json, force) {
|
|
1789
1870
|
const first = parseSources(sources, base2);
|
|
1790
1871
|
const colors = json?.appearance?.layerColors;
|
|
1791
|
-
const derived = deriveLayers(first, Array.isArray(colors) ? colors : []);
|
|
1872
|
+
const derived = deriveLayers(first, Array.isArray(colors) ? colors : [], force);
|
|
1792
1873
|
if (derived.layers.length < 2) return base2;
|
|
1793
1874
|
return defineProfile({ ...base2, layers: derived.layers, layerOf: (n) => derived.layerOf.get(n.id) ?? derived.layers[0].id });
|
|
1794
1875
|
}
|
|
@@ -2328,7 +2409,8 @@ var HELP = (schema) => `glassbrain: open, diff and validate a knowledge graph, w
|
|
|
2328
2409
|
share a number \u2014 a list is numbered, or it is a set. Values are floats, so 3.5
|
|
2329
2410
|
inserts between 3 and 4. The layout reads them clockwise from the top.
|
|
2330
2411
|
A root whose children are numbered opens the layer view: one floor per child.
|
|
2331
|
-
|
|
2412
|
+
Without order the layer button stays grey and can still force the floors
|
|
2413
|
+
open (document order, view only). There is no layer field.
|
|
2332
2414
|
|
|
2333
2415
|
SHAPE how a graph reads (validate measures each)
|
|
2334
2416
|
2\u20135 children per node; more than 10 is a wall (wide-node)
|
|
@@ -2356,9 +2438,11 @@ var HELP = (schema) => `glassbrain: open, diff and validate a knowledge graph, w
|
|
|
2356
2438
|
[ APPEARANCE ]
|
|
2357
2439
|
kg/_profile.json, shared by every pass. Everything in it is optional.
|
|
2358
2440
|
|
|
2359
|
-
COLORS one entry per kind you use
|
|
2441
|
+
COLORS one entry per kind you use. A kind without an entry is drawn as skeleton \u2014
|
|
2442
|
+
every uncoloured kind looks the same, so validate reports it as an error.
|
|
2360
2443
|
{ "nodePalette": { "file": "#6366f1", "folder": "#94a3b8" },
|
|
2361
2444
|
"edgePalette": { "uses": "#2563eb" } }
|
|
2445
|
+
Ten kinds is already a lot; one with no colour is invisible.
|
|
2362
2446
|
Colors closer than 10 in Lab distance read as one kind (validate notes it).
|
|
2363
2447
|
|
|
2364
2448
|
VIEW only the opening state; the page has the switches.
|
|
@@ -2376,9 +2460,9 @@ var HELP = (schema) => `glassbrain: open, diff and validate a knowledge graph, w
|
|
|
2376
2460
|
glassbrain validate <path> errors, warnings, info; exit 1 on errors
|
|
2377
2461
|
glassbrain tree <path> the containment tree as text
|
|
2378
2462
|
glassbrain restructure <path> raise the shape score: re-hang and renumber; writes a
|
|
2379
|
-
new
|
|
2380
|
-
|
|
2381
|
-
--dry-run prints the plan
|
|
2463
|
+
new folder with graph.json and _profile.json (a pass,
|
|
2464
|
+
or <name>.restructured/ for one file). It colours the
|
|
2465
|
+
kinds it invents. --dry-run prints the plan only.
|
|
2382
2466
|
glassbrain diff <old> <new> only what changed between two graphs
|
|
2383
2467
|
glassbrain diff <git-ref> <path> the same graph at an earlier commit (default HEAD)
|
|
2384
2468
|
glassbrain convert <path> [out-dir] write any supported format as glassbrain JSON
|
|
@@ -2674,17 +2758,23 @@ function runRestructure(a2) {
|
|
|
2674
2758
|
const abs = path2.resolve(a2.pos[0]);
|
|
2675
2759
|
const dir = fs2.existsSync(abs) && fs2.statSync(abs).isDirectory() ? abs : path2.dirname(abs);
|
|
2676
2760
|
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) : [];
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
if (
|
|
2761
|
+
const palette = {};
|
|
2762
|
+
const known = { folder: "#94a3b8", file: "#64748b", overview: "#a855f7", group: "#a855f7" };
|
|
2763
|
+
const wheel = ["#6366f1", "#f59e0b", "#10b981", "#ef4444", "#8b5cf6", "#06b6d4"];
|
|
2764
|
+
let wi = 0;
|
|
2765
|
+
for (const k of new Set(plan.nodes.map((n) => n.kind))) {
|
|
2766
|
+
if (k) palette[k] = known[k] ?? wheel[wi++ % wheel.length];
|
|
2767
|
+
}
|
|
2768
|
+
const srcProfile = l.profile ?? {};
|
|
2769
|
+
const outProfile = {
|
|
2770
|
+
...srcProfile,
|
|
2771
|
+
nodePalette: { ...palette, ...srcProfile.nodePalette ?? {} }
|
|
2772
|
+
};
|
|
2773
|
+
const passDir = l.versions.length > 1 || passes.length ? path2.join(dir, `${(passes.length ? Math.max(...passes) : 0) + 1}-restructured`) : path2.join(dir, `${path2.basename(abs, ".json") || "graph"}.restructured`);
|
|
2774
|
+
fs2.mkdirSync(passDir, { recursive: true });
|
|
2775
|
+
fs2.writeFileSync(path2.join(passDir, "_profile.json"), `${JSON.stringify(outProfile, null, 1)}
|
|
2683
2776
|
`);
|
|
2684
|
-
|
|
2685
|
-
} else {
|
|
2686
|
-
file = path2.join(dir, `${path2.basename(abs, ".json") || "graph"}.restructured.json`);
|
|
2687
|
-
}
|
|
2777
|
+
const file = path2.join(passDir, "graph.json");
|
|
2688
2778
|
fs2.writeFileSync(file, `${JSON.stringify(graph, null, 1)}
|
|
2689
2779
|
`);
|
|
2690
2780
|
console.log(`
|