glassbrain 0.2.0-alpha.5 → 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/core.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './edit.js';
9
9
  export * from './strings.js';
10
10
  export { DEFAULT_ANIMATE, type AnimateSpec, type TransitionReport } from './animate.js';
11
11
  export { DEFAULT_DIFF_LAYOUT, type DiffLayoutSpec, type DiffLayoutResult } from './layout/diff-layout.js';
12
+ export { kindDistribution, kindHeading, kindSummary, type KindDistribution } from './kinds.js';
package/dist/core.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  childrenMap,
3
3
  deriveLayers,
4
+ kindDistribution,
5
+ kindHeading,
6
+ kindSummary,
4
7
  layerIndexOf,
5
8
  orderedChildren
6
- } from "./chunks/chunk-G7XWVKHN.js";
9
+ } from "./chunks/chunk-LK77SYCN.js";
7
10
  import {
8
11
  CONTENT_SCALE,
9
12
  DARK_THEME,
@@ -45,13 +48,13 @@ import {
45
48
  diffStyle,
46
49
  edgeKindClass,
47
50
  edgesOf,
48
- encodeParent,
49
51
  graphStyle,
50
52
  hasChanges,
51
53
  indexModel,
52
54
  isFiltering,
53
55
  isNarrowing,
54
56
  isNodeEl,
57
+ kindTable,
55
58
  mergeSlices,
56
59
  mixHex,
57
60
  nodeClasses,
@@ -73,15 +76,16 @@ import {
73
76
  skeletonColor,
74
77
  stepUnion,
75
78
  themeColor,
79
+ toBundle,
76
80
  toPhysical,
77
81
  unionSides,
78
82
  untheme,
79
83
  validateModel,
80
84
  validateStructure
81
- } from "./chunks/chunk-F4HDKER4.js";
85
+ } from "./chunks/chunk-FNTYI7VP.js";
82
86
  import {
83
87
  EN
84
- } from "./chunks/chunk-ISWKAU5G.js";
88
+ } from "./chunks/chunk-Q35ZKWKF.js";
85
89
  import "./chunks/chunk-ZA47FP7C.js";
86
90
  export {
87
91
  CONTENT_SCALE,
@@ -127,13 +131,16 @@ export {
127
131
  diffStyle,
128
132
  edgeKindClass,
129
133
  edgesOf,
130
- encodeParent,
131
134
  graphStyle,
132
135
  hasChanges,
133
136
  indexModel,
134
137
  isFiltering,
135
138
  isNarrowing,
136
139
  isNodeEl,
140
+ kindDistribution,
141
+ kindHeading,
142
+ kindSummary,
143
+ kindTable,
137
144
  layerIndexOf,
138
145
  mergeSlices,
139
146
  mixHex,
@@ -157,6 +164,7 @@ export {
157
164
  skeletonColor,
158
165
  stepUnion,
159
166
  themeColor,
167
+ toBundle,
160
168
  toPhysical,
161
169
  unionSides,
162
170
  untheme,
package/dist/edit.d.ts CHANGED
@@ -2,6 +2,8 @@ import { type GraphEdge, type GraphModel } from './model.js';
2
2
  import type { GraphProfile } from './profile.js';
3
3
  /** What can be changed on a node. `parent: null` = move to the top level. */
4
4
  export interface NodeFields {
5
+ /** Insert before this sibling; null appends. Native UI uses this instead of numeric order. */
6
+ before?: string | null;
5
7
  label?: string;
6
8
  kind?: string;
7
9
  parent?: string | null;
@@ -38,7 +40,7 @@ export type EditOp =
38
40
  op: 'removeEdge';
39
41
  edge: EdgeRef;
40
42
  };
41
- export type EditError = 'id-format' | 'multiple-roots' | 'order-mixed' | 'order-invalid' | 'id-empty' | 'id-taken' | 'no-node' | 'no-parent' | 'cycle' | 'has-children' | 'no-endpoint' | 'self-loop' | 'edge-exists' | 'no-edge';
43
+ export type EditError = 'invalid-position' | 'order-invalid' | 'id-empty' | 'id-taken' | 'no-node' | 'no-parent' | 'cycle' | 'has-children' | 'no-endpoint' | 'self-loop' | 'edge-exists' | 'no-edge';
42
44
  /** Whether this op can be applied. null = yes; otherwise the reason (the UI looks it up in `strings.error`). */
43
45
  export declare function checkEdit(model: GraphModel, op: EditOp): EditError | null;
44
46
  /** How many edges hang on a node (the ones that go with it when it is deleted). */
@@ -57,5 +59,5 @@ export declare function applyEdits(model: GraphModel, ops: EditOp[], profile?: G
57
59
  error: EditError;
58
60
  }[];
59
61
  };
60
- /** Native CLI edits must remain exportable under the parent/order contract. */
61
- export declare function checkNativeEdit(model: GraphModel, op: EditOp): EditError | null;
62
+ /** Native CLI edits keep stable ids and valid forest placements. */
63
+ export declare const checkNativeEdit: typeof checkEdit;
package/dist/index.js CHANGED
@@ -3,9 +3,12 @@ import "./chunks/chunk-SA6RSWZP.js";
3
3
  import {
4
4
  childrenMap,
5
5
  deriveLayers,
6
+ kindDistribution,
7
+ kindHeading,
8
+ kindSummary,
6
9
  layerIndexOf,
7
10
  orderedChildren
8
- } from "./chunks/chunk-G7XWVKHN.js";
11
+ } from "./chunks/chunk-LK77SYCN.js";
9
12
  import {
10
13
  ALL_CONTROLS,
11
14
  DEFAULT_PLANES,
@@ -14,7 +17,7 @@ import {
14
17
  clearLayoutCache,
15
18
  computeLayout,
16
19
  projectPlanes
17
- } from "./chunks/chunk-WUBELTBU.js";
20
+ } from "./chunks/chunk-GZSWZSSE.js";
18
21
  import {
19
22
  CONTENT_SCALE,
20
23
  DARK_THEME,
@@ -56,13 +59,13 @@ import {
56
59
  diffStyle,
57
60
  edgeKindClass,
58
61
  edgesOf,
59
- encodeParent,
60
62
  graphStyle,
61
63
  hasChanges,
62
64
  indexModel,
63
65
  isFiltering,
64
66
  isNarrowing,
65
67
  isNodeEl,
68
+ kindTable,
66
69
  mergeSlices,
67
70
  mixHex,
68
71
  nodeClasses,
@@ -84,20 +87,21 @@ import {
84
87
  skeletonColor,
85
88
  stepUnion,
86
89
  themeColor,
90
+ toBundle,
87
91
  toPhysical,
88
92
  unionSides,
89
93
  untheme,
90
94
  validateModel,
91
95
  validateStructure
92
- } from "./chunks/chunk-F4HDKER4.js";
96
+ } from "./chunks/chunk-FNTYI7VP.js";
93
97
  import {
94
98
  DetailPanel,
95
99
  renderInline,
96
100
  renderMarkdown
97
- } from "./chunks/chunk-3JGZ27DC.js";
101
+ } from "./chunks/chunk-3KUNYSJE.js";
98
102
  import {
99
103
  EN
100
- } from "./chunks/chunk-ISWKAU5G.js";
104
+ } from "./chunks/chunk-Q35ZKWKF.js";
101
105
  import "./chunks/chunk-OE5IRKWZ.js";
102
106
  import "./chunks/chunk-ZA47FP7C.js";
103
107
  export {
@@ -151,13 +155,16 @@ export {
151
155
  diffStyle,
152
156
  edgeKindClass,
153
157
  edgesOf,
154
- encodeParent,
155
158
  graphStyle,
156
159
  hasChanges,
157
160
  indexModel,
158
161
  isFiltering,
159
162
  isNarrowing,
160
163
  isNodeEl,
164
+ kindDistribution,
165
+ kindHeading,
166
+ kindSummary,
167
+ kindTable,
161
168
  layerIndexOf,
162
169
  mergeSlices,
163
170
  mixHex,
@@ -184,6 +191,7 @@ export {
184
191
  skeletonColor,
185
192
  stepUnion,
186
193
  themeColor,
194
+ toBundle,
187
195
  toPhysical,
188
196
  unionSides,
189
197
  untheme,
package/dist/internal.js CHANGED
@@ -3,9 +3,12 @@ import "./chunks/chunk-SA6RSWZP.js";
3
3
  import {
4
4
  childrenMap,
5
5
  deriveLayers,
6
+ kindDistribution,
7
+ kindHeading,
8
+ kindSummary,
6
9
  layerIndexOf,
7
10
  orderedChildren
8
- } from "./chunks/chunk-G7XWVKHN.js";
11
+ } from "./chunks/chunk-LK77SYCN.js";
9
12
  import {
10
13
  ALL_CONTROLS,
11
14
  DEFAULT_PLANES,
@@ -48,7 +51,7 @@ import {
48
51
  shapeOf,
49
52
  skeletonLineOf,
50
53
  touchGestures
51
- } from "./chunks/chunk-WUBELTBU.js";
54
+ } from "./chunks/chunk-GZSWZSSE.js";
52
55
  import {
53
56
  CONTENT_SCALE,
54
57
  DARK_THEME,
@@ -104,7 +107,6 @@ import {
104
107
  edgeKindClass,
105
108
  edgeTraffic,
106
109
  edgesOf,
107
- encodeParent,
108
110
  fadeAt,
109
111
  graphStyle,
110
112
  hasChanges,
@@ -112,6 +114,7 @@ import {
112
114
  isFiltering,
113
115
  isNarrowing,
114
116
  isNodeEl,
117
+ kindTable,
115
118
  leavingOf,
116
119
  makeScore,
117
120
  mergeSlices,
@@ -141,6 +144,7 @@ import {
141
144
  solveDiffLayout,
142
145
  stepUnion,
143
146
  themeColor,
147
+ toBundle,
144
148
  toPhysical,
145
149
  trackAt,
146
150
  trackLin,
@@ -148,15 +152,15 @@ import {
148
152
  untheme,
149
153
  validateModel,
150
154
  validateStructure
151
- } from "./chunks/chunk-F4HDKER4.js";
155
+ } from "./chunks/chunk-FNTYI7VP.js";
152
156
  import {
153
157
  DetailPanel,
154
158
  renderInline,
155
159
  renderMarkdown
156
- } from "./chunks/chunk-3JGZ27DC.js";
160
+ } from "./chunks/chunk-3KUNYSJE.js";
157
161
  import {
158
162
  EN
159
- } from "./chunks/chunk-ISWKAU5G.js";
163
+ } from "./chunks/chunk-Q35ZKWKF.js";
160
164
  import "./chunks/chunk-OE5IRKWZ.js";
161
165
  import "./chunks/chunk-ZA47FP7C.js";
162
166
  export {
@@ -243,7 +247,6 @@ export {
243
247
  edgeKindHidden,
244
248
  edgeTraffic,
245
249
  edgesOf,
246
- encodeParent,
247
250
  fadeAt,
248
251
  focusAlphaOf,
249
252
  gapOf,
@@ -256,6 +259,10 @@ export {
256
259
  isFiltering,
257
260
  isNarrowing,
258
261
  isNodeEl,
262
+ kindDistribution,
263
+ kindHeading,
264
+ kindSummary,
265
+ kindTable,
259
266
  labelBox,
260
267
  layerIndexOf,
261
268
  leavingOf,
@@ -299,6 +306,7 @@ export {
299
306
  solveDiffLayout,
300
307
  stepUnion,
301
308
  themeColor,
309
+ toBundle,
302
310
  toPhysical,
303
311
  touchGestures,
304
312
  trackAt,
@@ -0,0 +1,23 @@
1
+ /** Vocabulary fragmentation, measured independently for nodes and semantic edges.
2
+ * Hill diversity at q=1/2 gives sparse categories more weight than Shannon diversity.
3
+ * Logarithmic growth avoids allowing thousands of categories in a large graph.
4
+ * This is a readability heuristic, not a test of semantic correctness.
5
+ */
6
+ export declare function kindDistribution(items: readonly {
7
+ kind?: string;
8
+ }[]): {
9
+ total: number;
10
+ typed: number;
11
+ missing: number;
12
+ count: number;
13
+ sizes: {
14
+ kind: string;
15
+ count: number;
16
+ }[];
17
+ effective: number;
18
+ fragmentation: number;
19
+ reason: string | null;
20
+ };
21
+ export type KindDistribution = ReturnType<typeof kindDistribution>;
22
+ export declare function kindHeading(space: 'node' | 'edge', d: KindDistribution): string;
23
+ export declare function kindSummary(space: 'node' | 'edge', d: KindDistribution, labels?: Record<string, string>): string;
package/dist/layers.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface DerivedLayers {
9
9
  anchor?: string;
10
10
  }
11
11
  /** Ordered children of `id`, or null when that run is not ordered (all of them carry a distinct order, or none does). */
12
- export declare function orderedChildren(children: Gy, id: string): GraphNode[] | null;
12
+ export declare function orderedChildren(children: Gy, id: string, unordered?: boolean): GraphNode[] | null;
13
13
  type Gy = Map<string, GraphNode[]>;
14
14
  export declare function childrenMap(model: GraphModel): Gy;
15
15
  export declare function deriveLayers(model: GraphModel, colors?: string[], force?: boolean): DerivedLayers;
package/dist/model.d.ts CHANGED
@@ -7,8 +7,9 @@ export interface GraphNode {
7
7
  /** Compound parent node id: expresses "nested inside", the only source of structural hierarchy. */
8
8
  parent?: string;
9
9
  /** Position among its siblings: every child of a parent carries one, or none does. **The file format writes it as the
10
- * `@<order>` tail of `parent`** (`"<id>@<order>"`; `@-1` means explicitly unordered and parses to undefined). The layout
11
- * reads it clockwise, and a run of ordered siblings is what opens the layer view. */
10
+ * position in `children`** (1-based; retained only in the runtime model). The layout
11
+ * reads it clockwise, unless the parent has data.unordered === true. Unordered groups retain
12
+ * these positions for editing/export, but do not use them for layout, floors or positional diffs. */
12
13
  order?: number;
13
14
  /** **Where it hung in the previous version** (filled by `diffModels`, only `moved` nodes in a union have it).
14
15
  *
@@ -49,7 +50,16 @@ export interface GraphEdge {
49
50
  data?: Record<string, unknown>;
50
51
  }
51
52
  /** A fragment parsed from one piece of raw data. One file = one slice. */
53
+ export interface NodeDeclaration {
54
+ id: string;
55
+ fields: Record<string, unknown>;
56
+ children?: string[];
57
+ path: string;
58
+ }
52
59
  export interface GraphSlice {
60
+ /** Native tree declarations, before defaults and field composition. */
61
+ declarations?: NodeDeclaration[];
62
+ rootIds?: string[];
53
63
  origin: string;
54
64
  title: string;
55
65
  nodes: GraphNode[];
@@ -67,6 +77,8 @@ export interface GraphModel {
67
77
  errors: {
68
78
  origin: string;
69
79
  message: string;
80
+ code?: 'schema' | 'field-conflict' | 'children-conflict' | 'parent-error';
81
+ node?: string;
70
82
  }[];
71
83
  /** id → node (built at construction; do not build your own). */
72
84
  index: Map<string, GraphNode>;
@@ -76,7 +88,7 @@ export interface GraphModel {
76
88
  export declare const EMPTY_MODEL: GraphModel;
77
89
  /** Build a model from bare nodes/edges (builds the index). profile.merge implementations nearly all end with it. */
78
90
  export declare function buildModel(nodes: GraphNode[], edges: GraphEdge[], errors?: GraphModel['errors']): GraphModel;
79
- /** Default merge: same id, first seen wins; all edges kept; errors collected. Used when the profile writes no merge. */
91
+ /** Native trees compose explicit fields by id; custom profile parsers can supply runtime slices. */
80
92
  export declare function mergeSlices(slices: GraphSlice[]): GraphModel;
81
93
  /** Add one to a source list (order kept, deduplicated). Needed all over the merge stage. */
82
94
  export declare function addOrigin(list: string[] | undefined, origin: string | undefined): string[];
@@ -95,5 +107,3 @@ export interface GraphIndex {
95
107
  export declare function indexModel(model: GraphModel): GraphIndex;
96
108
  /** The sources that appear in the model (data for the subgraph / view dropdown). */
97
109
  export declare function originsOf(model: GraphModel): string[];
98
- /** Canonical decimal encoding: Number.toString uses exponents for tiny/large orders. */
99
- export declare function encodeParent(parent: string | null | undefined, order?: number): string | null;
package/dist/profile.d.ts CHANGED
@@ -30,7 +30,9 @@ export interface DetailSpec {
30
30
  }
31
31
  export interface GraphIssue {
32
32
  kind: string;
33
- level: 'error' | 'warn';
33
+ level: 'error' | 'warn' | 'info';
34
+ where?: string;
35
+ fix?: string;
34
36
  /** What this category is called (the issues panel groups by it, e.g. "dangling edge"). Defaults to kind. */
35
37
  group?: string;
36
38
  message: string;
@@ -44,7 +46,7 @@ export interface GraphProfile {
44
46
  id: string;
45
47
  /** Parse one piece of raw data. Return null = not recognized (silently skipped, not counted as broken). */
46
48
  parse(origin: string, text: string): GraphSlice | null;
47
- /** Slices → model. Default mergeSlices (same id: first seen wins). */
49
+ /** Slices → model. Default mergeSlices (native declarations compose by id). */
48
50
  merge(slices: GraphSlice[]): GraphModel;
49
51
  layers: LayerSpec[];
50
52
  /** Which layer a node belongs to. Defaults to node.layer, then to the first layer. */
@@ -111,11 +113,21 @@ export declare function toPhysical(model: GraphModel): {
111
113
  nodes: Record<string, unknown>[];
112
114
  edges: Record<string, unknown>[];
113
115
  };
116
+ /** Portable page export: preserve the profile and include colours for every depth of the tree. */
117
+ export declare function toBundle(model: GraphModel, profile?: Record<string, unknown> | null): {
118
+ nodes: Record<string, unknown>[];
119
+ edges: Record<string, unknown>[];
120
+ profile: {
121
+ nodePalette: Record<string, string>;
122
+ };
123
+ };
114
124
  /** Generic validation: the few things true of any graph (dangling edges, duplicate ids, duplicate edges). Domain checks are added separately.
115
125
  *
116
126
  * **An edge is defined by its two ends + kind** (compare and edit both use this; `id` is only the name of the primitive on screen).
117
127
  * So two edges with the same ends and kind are one edge written twice: only one is drawn, and deleting removes both. */
118
128
  export declare function validateStructure(model: GraphModel): GraphIssue[];
129
+ /** Kind ids are user data, including ordinary strings such as "constructor". */
130
+ export declare function kindTable<T>(...entries: (Record<string, T> | undefined)[]): Record<string, T>;
119
131
  /** Complete a (possibly very sparse) input into a full profile. The defaults are the "generic graph" behavior. */
120
132
  export declare function defineProfile(input: ProfileInput): GraphProfile;
121
133
  /** Zero-configuration profile: reads `{nodes, edges}` directly. */
@@ -2,8 +2,8 @@
2
2
  "use client";
3
3
  import {
4
4
  DetailPanel
5
- } from "../chunks/chunk-3JGZ27DC.js";
6
- import "../chunks/chunk-ISWKAU5G.js";
5
+ } from "../chunks/chunk-3KUNYSJE.js";
6
+ import "../chunks/chunk-Q35ZKWKF.js";
7
7
  import "../chunks/chunk-ZA47FP7C.js";
8
8
  export {
9
9
  DetailPanel as default
@@ -0,0 +1,11 @@
1
+ import type { Plate } from '../layout/planes.js';
2
+ import { type GraphTheme } from '../style.js';
3
+ import type { Viewport } from './camera.js';
4
+ /** Frost lives below the graph canvases: nodes and text are never blurred. */
5
+ export default function GlassPlanes({ plates, viewport, theme, alpha, hot }: {
6
+ plates: Plate[];
7
+ viewport: Viewport;
8
+ theme: GraphTheme;
9
+ alpha: number;
10
+ hot: string | null;
11
+ }): import("react").JSX.Element;
@@ -88,6 +88,8 @@ export interface GraphCanvasProps {
88
88
  onSelect?: (node: SelectedNode | null) => void;
89
89
  /** Receives the cytoscape instance (for debugging / custom interaction). Called again when the instance is rebuilt. */
90
90
  onReady?: (cy: any) => void;
91
+ /** Complete diagnostics supplied by the host, independent of view filtering. */
92
+ issues?: GraphIssue[];
91
93
  /** Validation results go out; turn showIssues off when the host shows them itself. */
92
94
  onIssues?: (issues: GraphIssue[]) => void;
93
95
  showIssues?: boolean;
@@ -2,10 +2,10 @@
2
2
  "use client";
3
3
  import {
4
4
  GraphCanvas
5
- } from "../chunks/chunk-WUBELTBU.js";
6
- import "../chunks/chunk-F4HDKER4.js";
7
- import "../chunks/chunk-3JGZ27DC.js";
8
- import "../chunks/chunk-ISWKAU5G.js";
5
+ } from "../chunks/chunk-GZSWZSSE.js";
6
+ import "../chunks/chunk-FNTYI7VP.js";
7
+ import "../chunks/chunk-3KUNYSJE.js";
8
+ import "../chunks/chunk-Q35ZKWKF.js";
9
9
  import "../chunks/chunk-OE5IRKWZ.js";
10
10
  import "../chunks/chunk-ZA47FP7C.js";
11
11
  export {
@@ -10,6 +10,8 @@ export declare const I: {
10
10
  fit: string;
11
11
  more: string;
12
12
  warn: string;
13
+ error: string;
14
+ info: string;
13
15
  arrow: string;
14
16
  stack: string;
15
17
  edit: string;
package/dist/strings.d.ts CHANGED
@@ -30,8 +30,8 @@ export interface GraphStrings {
30
30
  more: string;
31
31
  origins: string;
32
32
  allOrigins: string;
33
- issuesTip: (errors: number, warns: number) => string;
34
- issuesTitle: (errors: number, warns: number) => string;
33
+ issuesTip: (errors: number, warns: number, infos?: number) => string;
34
+ issuesTitle: (errors: number, warns: number, infos?: number) => string;
35
35
  moreItems: (n: number) => string;
36
36
  cameraTip: string;
37
37
  zoomIn: string;
package/dist/tree.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /** Native ordered tree fragments. Collect facts by id before materializing a forest. */
2
+ import { type GraphModel, type GraphNode, type GraphSlice, type NodeDeclaration } from './model.js';
3
+ export declare function treeDeclarations(raw: unknown, origin: string): Pick<GraphSlice, 'declarations' | 'rootIds' | 'error'>;
4
+ /** Own fields only: descendants must never be copied into an ancestor's diff payload. */
5
+ export declare function treeNodes(declarations?: NodeDeclaration[]): GraphNode[];
6
+ export declare function composeTrees(input: GraphSlice[]): GraphModel;
7
+ /** Complete snapshots only. Never export a conflict's diagnostic first value as accepted knowledge. */
8
+ export declare function serializeTree(model: GraphModel): {
9
+ nodes: Record<string, unknown>[];
10
+ edges: Record<string, unknown>[];
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glassbrain",
3
- "version": "0.2.0-alpha.5",
3
+ "version": "0.2.0-alpha.7",
4
4
  "description": "Know what your agent knows: open, diff and review the knowledge graphs agents write. Plain JSON in, one html file out.",
5
5
  "keywords": [
6
6
  "knowledge-graph",