@openweave/weave-graph 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/compression.d.ts +94 -0
  2. package/dist/cjs/compression.d.ts.map +1 -0
  3. package/dist/cjs/compression.js +215 -0
  4. package/dist/cjs/compression.js.map +1 -0
  5. package/dist/cjs/edge.d.ts +43 -0
  6. package/dist/cjs/edge.d.ts.map +1 -0
  7. package/dist/cjs/edge.js +83 -0
  8. package/dist/cjs/edge.js.map +1 -0
  9. package/dist/cjs/hebbian-weights.d.ts +100 -0
  10. package/dist/cjs/hebbian-weights.d.ts.map +1 -0
  11. package/dist/cjs/hebbian-weights.js +152 -0
  12. package/dist/cjs/hebbian-weights.js.map +1 -0
  13. package/dist/cjs/index.d.ts +193 -0
  14. package/dist/cjs/index.d.ts.map +1 -0
  15. package/dist/cjs/index.js +417 -0
  16. package/dist/cjs/index.js.map +1 -0
  17. package/dist/cjs/node.d.ts +43 -0
  18. package/dist/cjs/node.d.ts.map +1 -0
  19. package/dist/cjs/node.js +83 -0
  20. package/dist/cjs/node.js.map +1 -0
  21. package/dist/cjs/package.json +1 -0
  22. package/dist/cjs/persistence.d.ts +86 -0
  23. package/dist/cjs/persistence.d.ts.map +1 -0
  24. package/dist/cjs/persistence.js +215 -0
  25. package/dist/cjs/persistence.js.map +1 -0
  26. package/dist/cjs/synaptic-engine.d.ts +126 -0
  27. package/dist/cjs/synaptic-engine.d.ts.map +1 -0
  28. package/dist/cjs/synaptic-engine.js +243 -0
  29. package/dist/cjs/synaptic-engine.js.map +1 -0
  30. package/dist/cjs/types.d.ts +74 -0
  31. package/dist/cjs/types.d.ts.map +1 -0
  32. package/dist/cjs/types.js +30 -0
  33. package/dist/cjs/types.js.map +1 -0
  34. package/dist/hebbian-weights.d.ts +100 -0
  35. package/dist/hebbian-weights.d.ts.map +1 -0
  36. package/dist/hebbian-weights.js +148 -0
  37. package/dist/hebbian-weights.js.map +1 -0
  38. package/dist/index.d.ts +36 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +65 -3
  41. package/dist/index.js.map +1 -1
  42. package/dist/persistence.d.ts +43 -15
  43. package/dist/persistence.d.ts.map +1 -1
  44. package/dist/persistence.js +109 -119
  45. package/dist/persistence.js.map +1 -1
  46. package/dist/synaptic-engine.d.ts +126 -0
  47. package/dist/synaptic-engine.d.ts.map +1 -0
  48. package/dist/synaptic-engine.js +236 -0
  49. package/dist/synaptic-engine.js.map +1 -0
  50. package/package.json +6 -4
@@ -0,0 +1,94 @@
1
+ import { Node, Edge } from "./types";
2
+ /**
3
+ * CompressionStats tracks metrics about graph compression
4
+ */
5
+ export interface CompressionStats {
6
+ originalNodeCount: number;
7
+ originalEdgeCount: number;
8
+ compressedNodeCount: number;
9
+ compressedEdgeCount: number;
10
+ archivedNodeCount: number;
11
+ compressionRatio: number;
12
+ estimatedContextSize: number;
13
+ }
14
+ /**
15
+ * CompressionManager handles graph compression and context optimization
16
+ * Keeps high-value nodes in active memory, archives low-frequency nodes
17
+ */
18
+ export declare class CompressionManager {
19
+ private archivedNodes;
20
+ private archivedEdges;
21
+ /**
22
+ * Calculate approximate size of a node in bytes (for context window estimation)
23
+ */
24
+ static estimateNodeSize(node: Node): number;
25
+ /**
26
+ * Calculate approximate size of an edge in bytes
27
+ */
28
+ static estimateEdgeSize(edge: Edge): number;
29
+ /**
30
+ * Calculate total estimated context window usage
31
+ */
32
+ static calculateContextSize(nodes: Node[], edges: Edge[]): number;
33
+ /**
34
+ * Calculate context window usage as a percentage (0-1)
35
+ * Assumes ~100KB max context for graph data (typical LLM context budget)
36
+ */
37
+ static calculateContextUsagePercentage(contextSize: number): number;
38
+ /**
39
+ * Identify nodes that should be archived (low frequency, old, not critical)
40
+ * Returns nodeIds sorted by priority for archival
41
+ */
42
+ static identifyArchiveCandidates(nodes: Node[], edges: Edge[], targetReductionPercentage?: number): string[];
43
+ /**
44
+ * Archive nodes and their dependent edges
45
+ */
46
+ archiveNodes(nodeIds: string[], nodes: Map<string, Node>, edges: Map<string, Edge>): void;
47
+ /**
48
+ * Restore archived nodes back to active graph
49
+ */
50
+ restoreNodes(nodeIds: string[]): Map<string, Node>;
51
+ /**
52
+ * Get archive statistics
53
+ */
54
+ getArchiveStats(): {
55
+ archivedNodeCount: number;
56
+ archivedEdgeCount: number;
57
+ };
58
+ /**
59
+ * Clear all archives
60
+ */
61
+ clearArchives(): void;
62
+ }
63
+ /**
64
+ * ErrorSuppression handles marking errors and their corrections
65
+ */
66
+ export declare class ErrorSuppression {
67
+ /**
68
+ * Mark a node as suppressed (contains an error)
69
+ */
70
+ static suppressNode(node: Node): Node;
71
+ /**
72
+ * Check if a node is suppressed
73
+ */
74
+ static isSuppressed(node: Node): boolean;
75
+ /**
76
+ * Create a correction node linked to an error node
77
+ */
78
+ static createCorrection(errorNodeId: string, correctionLabel: string, correctionDescription?: string): {
79
+ correctionNode: Node;
80
+ correctionEdge: Edge;
81
+ };
82
+ /**
83
+ * Get all error nodes that have corrections
84
+ */
85
+ static findCorrectedErrors(nodes: Map<string, Node>, edges: Map<string, Edge>): Map<string, {
86
+ error: Node;
87
+ corrections: Node[];
88
+ }>;
89
+ /**
90
+ * Get uncorrected error nodes
91
+ */
92
+ static findUncorrectedErrors(nodes: Map<string, Node>, edges: Map<string, Edge>): Node[];
93
+ }
94
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/compression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAsB,MAAM,SAAS,CAAC;AAIzD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,E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AAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAIxC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CACrB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,qBAAqB,CAAC,EAAE,MAAM,GAC7B;QAAE,cAAc,EAAE,IAAI,CAAC;QAAC,cAAc,EAAE,IAAI,CAAA;KAAE;IAUjD;;OAEG;IACH,MAAM,CAAC,mBAAmB,CACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,GACvB,GAAG,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,IAAI,CAAC;QAAC,WAAW,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC;IAuBpD;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE;CAYzF"}
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorSuppression = exports.CompressionManager = void 0;
4
+ const types_1 = require("./types");
5
+ const node_1 = require("./node");
6
+ const edge_1 = require("./edge");
7
+ /**
8
+ * CompressionManager handles graph compression and context optimization
9
+ * Keeps high-value nodes in active memory, archives low-frequency nodes
10
+ */
11
+ class CompressionManager {
12
+ archivedNodes = new Map();
13
+ archivedEdges = new Map();
14
+ /**
15
+ * Calculate approximate size of a node in bytes (for context window estimation)
16
+ */
17
+ static estimateNodeSize(node) {
18
+ // Rough estimation: labels ~50 bytes + metadata ~100 bytes
19
+ const labelSize = node.label.length * 2;
20
+ const descSize = (node.description || "").length * 2;
21
+ const metadataSize = JSON.stringify(node.metadata || {}).length;
22
+ return 50 + labelSize + descSize + metadataSize;
23
+ }
24
+ /**
25
+ * Calculate approximate size of an edge in bytes
26
+ */
27
+ static estimateEdgeSize(edge) {
28
+ // Edge size: sourceId ~ 36 bytes + targetId ~ 36 bytes + type ~ 20 bytes + metadata
29
+ const metadataSize = JSON.stringify(edge.metadata || {}).length;
30
+ return 100 + metadataSize;
31
+ }
32
+ /**
33
+ * Calculate total estimated context window usage
34
+ */
35
+ static calculateContextSize(nodes, edges) {
36
+ const nodesSize = nodes.reduce((sum, node) => sum + this.estimateNodeSize(node), 0);
37
+ const edgesSize = edges.reduce((sum, edge) => sum + this.estimateEdgeSize(edge), 0);
38
+ return nodesSize + edgesSize;
39
+ }
40
+ /**
41
+ * Calculate context window usage as a percentage (0-1)
42
+ * Assumes ~100KB max context for graph data (typical LLM context budget)
43
+ */
44
+ static calculateContextUsagePercentage(contextSize) {
45
+ const MAX_CONTEXT_BYTES = 100_000; // ~100KB for graph data
46
+ return Math.min(contextSize / MAX_CONTEXT_BYTES, 1);
47
+ }
48
+ /**
49
+ * Identify nodes that should be archived (low frequency, old, not critical)
50
+ * Returns nodeIds sorted by priority for archival
51
+ */
52
+ static identifyArchiveCandidates(nodes, edges, targetReductionPercentage = 0.3) {
53
+ // Build a map of node importance
54
+ const nodeImportance = new Map();
55
+ // Initialize with frequency
56
+ for (const node of nodes) {
57
+ nodeImportance.set(node.id, node.frequency ?? 1);
58
+ }
59
+ // Increase importance of nodes with many connections
60
+ const connectionCount = new Map();
61
+ for (const edge of edges) {
62
+ connectionCount.set(edge.sourceId, (connectionCount.get(edge.sourceId) ?? 0) + 1);
63
+ connectionCount.set(edge.targetId, (connectionCount.get(edge.targetId) ?? 0) + 1);
64
+ }
65
+ for (const [nodeId, count] of connectionCount) {
66
+ const current = nodeImportance.get(nodeId) ?? 1;
67
+ nodeImportance.set(nodeId, current + count * 2);
68
+ }
69
+ // Mark ERROR nodes as candidates (they can be archived after corrections exist)
70
+ for (const node of nodes) {
71
+ if (node.type === types_1.NodeType.ERROR) {
72
+ nodeImportance.set(node.id, Math.max(0.1, (nodeImportance.get(node.id) ?? 1) - 5));
73
+ }
74
+ }
75
+ // Mark old nodes with low frequency as less important
76
+ const now = new Date();
77
+ for (const node of nodes) {
78
+ const ageHours = (now.getTime() - node.updatedAt.getTime()) / (1000 * 60 * 60);
79
+ if (ageHours > 24 && (node.frequency ?? 1) < 3) {
80
+ nodeImportance.set(node.id, (nodeImportance.get(node.id) ?? 1) * 0.5);
81
+ }
82
+ }
83
+ // Sort by importance and select bottom candidates
84
+ const sorted = Array.from(nodeImportance.entries())
85
+ .sort((a, b) => a[1] - b[1])
86
+ .map(([id]) => id);
87
+ const targetCount = Math.ceil(nodes.length * targetReductionPercentage);
88
+ return sorted.slice(0, targetCount);
89
+ }
90
+ /**
91
+ * Archive nodes and their dependent edges
92
+ */
93
+ archiveNodes(nodeIds, nodes, edges) {
94
+ const nodeIdSet = new Set(nodeIds);
95
+ // Archive nodes
96
+ for (const nodeId of nodeIds) {
97
+ const node = nodes.get(nodeId);
98
+ if (node) {
99
+ this.archivedNodes.set(nodeId, node);
100
+ }
101
+ }
102
+ // Archive edges connected to archived nodes
103
+ for (const [edgeId, edge] of edges) {
104
+ if (nodeIdSet.has(edge.sourceId) || nodeIdSet.has(edge.targetId)) {
105
+ this.archivedEdges.set(edgeId, edge);
106
+ }
107
+ }
108
+ }
109
+ /**
110
+ * Restore archived nodes back to active graph
111
+ */
112
+ restoreNodes(nodeIds) {
113
+ const restored = new Map();
114
+ for (const nodeId of nodeIds) {
115
+ const node = this.archivedNodes.get(nodeId);
116
+ if (node) {
117
+ restored.set(nodeId, node);
118
+ this.archivedNodes.delete(nodeId);
119
+ }
120
+ }
121
+ return restored;
122
+ }
123
+ /**
124
+ * Get archive statistics
125
+ */
126
+ getArchiveStats() {
127
+ return {
128
+ archivedNodeCount: this.archivedNodes.size,
129
+ archivedEdgeCount: this.archivedEdges.size,
130
+ };
131
+ }
132
+ /**
133
+ * Clear all archives
134
+ */
135
+ clearArchives() {
136
+ this.archivedNodes.clear();
137
+ this.archivedEdges.clear();
138
+ }
139
+ }
140
+ exports.CompressionManager = CompressionManager;
141
+ /**
142
+ * ErrorSuppression handles marking errors and their corrections
143
+ */
144
+ class ErrorSuppression {
145
+ /**
146
+ * Mark a node as suppressed (contains an error)
147
+ */
148
+ static suppressNode(node) {
149
+ if (node.type !== types_1.NodeType.ERROR) {
150
+ throw new Error("Only ERROR type nodes can be suppressed");
151
+ }
152
+ return {
153
+ ...node,
154
+ metadata: {
155
+ ...node.metadata,
156
+ suppressed: true,
157
+ suppressedAt: new Date().toISOString(),
158
+ },
159
+ };
160
+ }
161
+ /**
162
+ * Check if a node is suppressed
163
+ */
164
+ static isSuppressed(node) {
165
+ return node.metadata?.suppressed ?? false;
166
+ }
167
+ /**
168
+ * Create a correction node linked to an error node
169
+ */
170
+ static createCorrection(errorNodeId, correctionLabel, correctionDescription) {
171
+ const correctionNode = node_1.NodeBuilder.correction(correctionLabel, correctionDescription);
172
+ const correctionEdge = edge_1.EdgeBuilder.corrects(correctionNode.id, errorNodeId);
173
+ return {
174
+ correctionNode,
175
+ correctionEdge,
176
+ };
177
+ }
178
+ /**
179
+ * Get all error nodes that have corrections
180
+ */
181
+ static findCorrectedErrors(nodes, edges) {
182
+ const correctedErrors = new Map();
183
+ for (const [, edge] of edges) {
184
+ if (edge.type === types_1.EdgeType.CORRECTS) {
185
+ const correctionNode = nodes.get(edge.sourceId);
186
+ const errorNode = nodes.get(edge.targetId);
187
+ if (correctionNode && errorNode && errorNode.type === types_1.NodeType.ERROR) {
188
+ if (!correctedErrors.has(errorNode.id)) {
189
+ correctedErrors.set(errorNode.id, {
190
+ error: errorNode,
191
+ corrections: [],
192
+ });
193
+ }
194
+ correctedErrors.get(errorNode.id).corrections.push(correctionNode);
195
+ }
196
+ }
197
+ }
198
+ return correctedErrors;
199
+ }
200
+ /**
201
+ * Get uncorrected error nodes
202
+ */
203
+ static findUncorrectedErrors(nodes, edges) {
204
+ const errorNodes = Array.from(nodes.values()).filter((n) => n.type === types_1.NodeType.ERROR);
205
+ const correctedErrorIds = new Set();
206
+ for (const [, edge] of edges) {
207
+ if (edge.type === types_1.EdgeType.CORRECTS) {
208
+ correctedErrorIds.add(edge.targetId);
209
+ }
210
+ }
211
+ return errorNodes.filter((n) => !correctedErrorIds.has(n.id));
212
+ }
213
+ }
214
+ exports.ErrorSuppression = ErrorSuppression;
215
+ //# sourceMappingURL=compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.js","sourceRoot":"","sources":["../../src/compression.ts"],"names":[],"mappings":";;;AAAA,mCAAyD;AACzD,iCAAqC;AACrC,iCAAqC;AAerC;;;GAGG;AACH,MAAa,kBAAkB;IACrB,aAAa,GAAsB,IAAI,GAAG,EAAE,CAAC;IAC7C,aAAa,GAAsB,IAAI,GAAG,EAAE,CAAC;IAErD;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAU;QAChC,2DAA2D;QAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QACrD,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAChE,OAAO,EAAE,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAU;QAChC,oFAAoF;QACpF,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAChE,OAAO,GAAG,GAAG,YAAY,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,KAAa,EAAE,KAAa;QACtD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAA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K,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAQ,CAAC,KAAK,CAAC,CAAC;QACvF,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;QAE5C,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAQ,CAAC,QAAQ,EAAE,CAAC;gBACpC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC;CACF;AAtFD,4CAsFC"}
@@ -0,0 +1,43 @@
1
+ import { Edge, EdgeType } from "./types";
2
+ /**
3
+ * EdgeBuilder utility for creating and managing graph edges
4
+ */
5
+ export declare class EdgeBuilder {
6
+ /**
7
+ * Create a new edge between two nodes
8
+ */
9
+ static create(sourceId: string, targetId: string, type: EdgeType, weight?: number, metadata?: Record<string, unknown>): Edge;
10
+ /**
11
+ * Create a RELATES edge
12
+ */
13
+ static relates(sourceId: string, targetId: string, weight?: number): Edge;
14
+ /**
15
+ * Create a CAUSES edge
16
+ */
17
+ static causes(sourceId: string, targetId: string, weight?: number): Edge;
18
+ /**
19
+ * Create a CORRECTS edge (links CORRECTION to ERROR)
20
+ */
21
+ static corrects(correctionId: string, errorId: string, weight?: number): Edge;
22
+ /**
23
+ * Create an IMPLEMENTS edge (code → decision)
24
+ */
25
+ static implements(codeEntityId: string, decisionId: string, weight?: number): Edge;
26
+ /**
27
+ * Create a DEPENDS_ON edge
28
+ */
29
+ static dependsOn(sourceId: string, targetId: string, weight?: number): Edge;
30
+ /**
31
+ * Create a BLOCKS edge
32
+ */
33
+ static blocks(blockerId: string, blockedId: string, weight?: number): Edge;
34
+ /**
35
+ * Clone an edge with updated values
36
+ */
37
+ static clone(edge: Edge, updates?: Partial<Edge>): Edge;
38
+ /**
39
+ * Increase the weight (confidence) of an edge
40
+ */
41
+ static reinforceWeight(edge: Edge, factor?: number): Edge;
42
+ }
43
+ //# sourceMappingURL=edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../src/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGzC;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,QAAQ,EACd,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,IAAI;IAaP;;OAEG;IACH,MAAM,CAAC,OAAO,CACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACH,MAAM,CAAC,QAAQ,CACb,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACH,MAAM,CAAC,UAAU,CACf,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACH,MAAM,CAAC,SAAS,CACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACH,MAAM,CAAC,KAAK,CACV,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GACtB,IAAI;IAQP;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,MAAY,GAAG,IAAI;CAO/D"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdgeBuilder = void 0;
4
+ const types_1 = require("./types");
5
+ const crypto_1 = require("crypto");
6
+ /**
7
+ * EdgeBuilder utility for creating and managing graph edges
8
+ */
9
+ class EdgeBuilder {
10
+ /**
11
+ * Create a new edge between two nodes
12
+ */
13
+ static create(sourceId, targetId, type, weight, metadata) {
14
+ return {
15
+ id: (0, crypto_1.randomUUID)(),
16
+ sourceId,
17
+ targetId,
18
+ type,
19
+ weight: weight ?? 1.0,
20
+ metadata: metadata ?? {},
21
+ createdAt: new Date(),
22
+ updatedAt: new Date(),
23
+ };
24
+ }
25
+ /**
26
+ * Create a RELATES edge
27
+ */
28
+ static relates(sourceId, targetId, weight) {
29
+ return this.create(sourceId, targetId, types_1.EdgeType.RELATES, weight);
30
+ }
31
+ /**
32
+ * Create a CAUSES edge
33
+ */
34
+ static causes(sourceId, targetId, weight) {
35
+ return this.create(sourceId, targetId, types_1.EdgeType.CAUSES, weight);
36
+ }
37
+ /**
38
+ * Create a CORRECTS edge (links CORRECTION to ERROR)
39
+ */
40
+ static corrects(correctionId, errorId, weight) {
41
+ return this.create(correctionId, errorId, types_1.EdgeType.CORRECTS, weight);
42
+ }
43
+ /**
44
+ * Create an IMPLEMENTS edge (code → decision)
45
+ */
46
+ static implements(codeEntityId, decisionId, weight) {
47
+ return this.create(codeEntityId, decisionId, types_1.EdgeType.IMPLEMENTS, weight);
48
+ }
49
+ /**
50
+ * Create a DEPENDS_ON edge
51
+ */
52
+ static dependsOn(sourceId, targetId, weight) {
53
+ return this.create(sourceId, targetId, types_1.EdgeType.DEPENDS_ON, weight);
54
+ }
55
+ /**
56
+ * Create a BLOCKS edge
57
+ */
58
+ static blocks(blockerId, blockedId, weight) {
59
+ return this.create(blockerId, blockedId, types_1.EdgeType.BLOCKS, weight);
60
+ }
61
+ /**
62
+ * Clone an edge with updated values
63
+ */
64
+ static clone(edge, updates) {
65
+ return {
66
+ ...edge,
67
+ updatedAt: new Date(),
68
+ ...updates,
69
+ };
70
+ }
71
+ /**
72
+ * Increase the weight (confidence) of an edge
73
+ */
74
+ static reinforceWeight(edge, factor = 1.1) {
75
+ return {
76
+ ...edge,
77
+ weight: (edge.weight ?? 1.0) * factor,
78
+ updatedAt: new Date(),
79
+ };
80
+ }
81
+ }
82
+ exports.EdgeBuilder = EdgeBuilder;
83
+ //# sourceMappingURL=edge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge.js","sourceRoot":"","sources":["../../src/edge.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AACzC,mCAAoC;AAEpC;;GAEG;AACH,MAAa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,QAAgB,EAChB,QAAgB,EAChB,IAAc,EACd,MAAe,EACf,QAAkC;QAElC,OAAO;YACL,EAAE,EAAE,IAAA,mBAAU,GAAE;YAChB,QAAQ;YACR,QAAQ;YACR,IAAI;YACJ,MAAM,EAAE,MAAM,IAAI,GAAG;YACrB,QAAQ,EAAE,QAAQ,IAAI,EAAE;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CACZ,QAAgB,EAChB,QAAgB,EAChB,MAAe;QAEf,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;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,IAAU,EAAE,SAAiB,GAAG;QACrD,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM;YACrC,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;IACJ,CAAC;CACF;AAjHD,kCAiHC"}
@@ -0,0 +1,100 @@
1
+ import { Edge } from "./types.js";
2
+ export interface HebbianOptions {
3
+ /** Amount added to edge.weight on co-activation. Default: 0.1 */
4
+ hebbianStrength?: number;
5
+ /** Multiplicative factor applied to all weights per decay cycle. Default: 0.99 */
6
+ decayRate?: number;
7
+ /** Edges whose weight falls below this are pruned. Default: 0.05 */
8
+ pruneThreshold?: number;
9
+ /** Hard ceiling on edge.weight after strengthening. Default: 5.0 */
10
+ maxWeight?: number;
11
+ }
12
+ /**
13
+ * Minimal structural interface that ContextGraphManager satisfies.
14
+ * HebbianWeights only needs these methods — no import of the full class.
15
+ */
16
+ export interface HebbianGraph {
17
+ getEdge(edgeId: string): Edge | undefined;
18
+ updateEdge(edgeId: string, updates: Partial<Edge>): Edge | undefined;
19
+ getAllEdges(): Edge[];
20
+ deleteEdge(edgeId: string): boolean;
21
+ }
22
+ /**
23
+ * HebbianWeights — Hebbian learning + temporal decay for graph edges.
24
+ *
25
+ * Models three neuronal behaviours:
26
+ *
27
+ * 1. **Strengthen** (`strengthen`): When two nodes are co-activated (both
28
+ * appear in the same query result), every edge connecting them gains
29
+ * `hebbianStrength` weight — "neurons that fire together, wire together."
30
+ *
31
+ * 2. **Decay** (`decay`): Every edge weight is multiplied by `decayRate`
32
+ * each cycle. Edges not reinforced by co-activation gradually weaken.
33
+ *
34
+ * 3. **Prune** (`prune`): Edges whose weight drops below `pruneThreshold`
35
+ * are deleted, keeping the graph clean and preventing stale connections
36
+ * from accumulating indefinitely.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const hebb = new HebbianWeights({ hebbianStrength: 0.1, decayRate: 0.99 });
41
+ * graph.setHebbianWeights(hebb);
42
+ *
43
+ * // queryNodesByLabel() auto-strengthens edges between co-activated nodes
44
+ * graph.queryNodesByLabel("TypeScript");
45
+ *
46
+ * // Run decay once per session cycle
47
+ * hebb.decay(graph);
48
+ *
49
+ * // Prune weak edges
50
+ * hebb.prune(graph);
51
+ * ```
52
+ */
53
+ export declare class HebbianWeights {
54
+ private readonly hebbianStrength;
55
+ private readonly decayRate;
56
+ private readonly pruneThreshold;
57
+ private readonly maxWeight;
58
+ constructor(options?: HebbianOptions);
59
+ /** Read-only view of the resolved configuration. */
60
+ get config(): Required<HebbianOptions>;
61
+ /**
62
+ * Strengthen a single edge by `hebbianStrength`, capped at `maxWeight`.
63
+ *
64
+ * Intended to be called for every edge that connects two nodes that were
65
+ * co-activated (both appeared in the same query result).
66
+ *
67
+ * @returns The updated edge, or `undefined` if the edge was not found.
68
+ */
69
+ strengthen(edgeId: string, graph: HebbianGraph): Edge | undefined;
70
+ /**
71
+ * Strengthen all edges that connect pairs of nodes within `nodeIds`.
72
+ *
73
+ * This is the batch form used by `ContextGraphManager` after a query:
74
+ * every edge whose `sourceId` AND `targetId` both appear in the result
75
+ * set gets strengthened once.
76
+ *
77
+ * @returns The list of edge ids that were strengthened.
78
+ */
79
+ strengthenCoActivated(nodeIds: string[], graph: HebbianGraph): string[];
80
+ /**
81
+ * Apply temporal decay to every edge in the graph.
82
+ *
83
+ * Each edge weight is multiplied by `decayRate` (< 1.0).
84
+ * Edges reinforced by recent co-activation decay slower relative
85
+ * to their higher baseline weight.
86
+ *
87
+ * @returns The number of edges decayed.
88
+ */
89
+ decay(graph: HebbianGraph): number;
90
+ /**
91
+ * Delete all edges whose weight has fallen below `pruneThreshold`.
92
+ *
93
+ * Can be called after `decay()` to clean up stale connections.
94
+ *
95
+ * @param minWeight Override the instance's `pruneThreshold` for this call.
96
+ * @returns The number of edges deleted.
97
+ */
98
+ prune(graph: HebbianGraph, minWeight?: number): number;
99
+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