shieldcortex 2.1.1 → 2.1.2
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 +1 -1
- package/hooks/clawdbot/cortex-memory/HOOK.md +2 -2
- package/package.json +13 -9
- package/dashboard/components.json +0 -22
- package/dashboard/eslint.config.mjs +0 -42
- package/dashboard/next.config.ts +0 -7
- package/dashboard/package-lock.json +0 -8053
- package/dashboard/package.json +0 -44
- package/dashboard/postcss.config.mjs +0 -7
- package/dashboard/public/file.svg +0 -1
- package/dashboard/public/globe.svg +0 -1
- package/dashboard/public/next.svg +0 -1
- package/dashboard/public/vercel.svg +0 -1
- package/dashboard/public/window.svg +0 -1
- package/dashboard/scripts/ensure-api.mjs +0 -76
- package/dashboard/src/app/error.tsx +0 -49
- package/dashboard/src/app/favicon.ico +0 -0
- package/dashboard/src/app/globals.css +0 -130
- package/dashboard/src/app/layout.tsx +0 -35
- package/dashboard/src/app/page.tsx +0 -364
- package/dashboard/src/components/Providers.tsx +0 -27
- package/dashboard/src/components/brain/ActivityPulseSystem.tsx +0 -229
- package/dashboard/src/components/brain/BrainMesh.tsx +0 -133
- package/dashboard/src/components/brain/BrainRegions.tsx +0 -254
- package/dashboard/src/components/brain/BrainScene.tsx +0 -255
- package/dashboard/src/components/brain/CategoryLabels.tsx +0 -103
- package/dashboard/src/components/brain/CoreSphere.tsx +0 -215
- package/dashboard/src/components/brain/DataFlowParticles.tsx +0 -123
- package/dashboard/src/components/brain/DataStreamRings.tsx +0 -161
- package/dashboard/src/components/brain/ElectronFlow.tsx +0 -323
- package/dashboard/src/components/brain/HolographicGrid.tsx +0 -235
- package/dashboard/src/components/brain/MemoryLinks.tsx +0 -271
- package/dashboard/src/components/brain/MemoryNode.tsx +0 -245
- package/dashboard/src/components/brain/NeuralPathways.tsx +0 -441
- package/dashboard/src/components/brain/SynapseNodes.tsx +0 -312
- package/dashboard/src/components/brain/TimelineControls.tsx +0 -205
- package/dashboard/src/components/chip/ChipScene.tsx +0 -497
- package/dashboard/src/components/chip/ChipSubstrate.tsx +0 -238
- package/dashboard/src/components/chip/CortexCore.tsx +0 -210
- package/dashboard/src/components/chip/DataBus.tsx +0 -416
- package/dashboard/src/components/chip/MemoryCell.tsx +0 -225
- package/dashboard/src/components/chip/MemoryGrid.tsx +0 -328
- package/dashboard/src/components/chip/QuantumCell.tsx +0 -316
- package/dashboard/src/components/chip/SectionLabel.tsx +0 -113
- package/dashboard/src/components/chip/index.ts +0 -14
- package/dashboard/src/components/controls/ControlPanel.tsx +0 -106
- package/dashboard/src/components/controls/VersionPanel.tsx +0 -185
- package/dashboard/src/components/dashboard/StatsPanel.tsx +0 -164
- package/dashboard/src/components/debug/ActivityLog.tsx +0 -250
- package/dashboard/src/components/debug/DebugPanel.tsx +0 -101
- package/dashboard/src/components/debug/QueryTester.tsx +0 -192
- package/dashboard/src/components/debug/RelationshipGraph.tsx +0 -403
- package/dashboard/src/components/debug/SqlConsole.tsx +0 -319
- package/dashboard/src/components/graph/KnowledgeGraph.tsx +0 -230
- package/dashboard/src/components/graph/OntologyGraph.tsx +0 -631
- package/dashboard/src/components/insights/ActivityHeatmap.tsx +0 -131
- package/dashboard/src/components/insights/InsightsView.tsx +0 -46
- package/dashboard/src/components/insights/KnowledgeMapPanel.tsx +0 -80
- package/dashboard/src/components/insights/QualityPanel.tsx +0 -116
- package/dashboard/src/components/memories/MemoriesView.tsx +0 -150
- package/dashboard/src/components/memories/MemoryCard.tsx +0 -103
- package/dashboard/src/components/memory/MemoryDetail.tsx +0 -325
- package/dashboard/src/components/nav/NavRail.tsx +0 -54
- package/dashboard/src/components/ui/button.tsx +0 -62
- package/dashboard/src/components/ui/card.tsx +0 -92
- package/dashboard/src/components/ui/input.tsx +0 -21
- package/dashboard/src/hooks/useDebouncedValue.ts +0 -24
- package/dashboard/src/hooks/useMemories.ts +0 -458
- package/dashboard/src/hooks/useSuggestions.ts +0 -46
- package/dashboard/src/lib/category-colors.ts +0 -84
- package/dashboard/src/lib/position-algorithm.ts +0 -177
- package/dashboard/src/lib/simplex-noise.ts +0 -217
- package/dashboard/src/lib/store.ts +0 -88
- package/dashboard/src/lib/utils.ts +0 -6
- package/dashboard/src/lib/websocket.ts +0 -249
- package/dashboard/src/types/memory.ts +0 -73
- package/dashboard/tsconfig.json +0 -34
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WebSocket client for real-time memory updates
|
|
3
|
-
*
|
|
4
|
-
* Connects to the visualization server's WebSocket endpoint
|
|
5
|
-
* and dispatches events to React Query for cache invalidation.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { useEffect, useRef, useCallback, useState } from 'react';
|
|
9
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
10
|
-
|
|
11
|
-
const WS_URL = process.env.NEXT_PUBLIC_WS_URL || 'ws://localhost:3001/ws/events';
|
|
12
|
-
|
|
13
|
-
export type WebSocketEventType =
|
|
14
|
-
| 'initial_state'
|
|
15
|
-
| 'memory_created'
|
|
16
|
-
| 'memory_accessed'
|
|
17
|
-
| 'memory_updated'
|
|
18
|
-
| 'memory_deleted'
|
|
19
|
-
| 'consolidation_complete'
|
|
20
|
-
| 'decay_tick'
|
|
21
|
-
// Phase 4: Worker events
|
|
22
|
-
| 'worker_light_tick'
|
|
23
|
-
| 'worker_medium_tick'
|
|
24
|
-
| 'link_discovered'
|
|
25
|
-
| 'predictive_consolidation'
|
|
26
|
-
// Version/Update events
|
|
27
|
-
| 'update_started'
|
|
28
|
-
| 'update_complete'
|
|
29
|
-
| 'update_failed'
|
|
30
|
-
| 'server_restarting';
|
|
31
|
-
|
|
32
|
-
// Alias for backwards compatibility
|
|
33
|
-
export type MemoryEventType = WebSocketEventType;
|
|
34
|
-
|
|
35
|
-
interface WebSocketMessage {
|
|
36
|
-
type: WebSocketEventType;
|
|
37
|
-
data?: unknown;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface UseMemoryWebSocketOptions {
|
|
41
|
-
enabled?: boolean;
|
|
42
|
-
onMessage?: (event: WebSocketMessage) => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Reconnection configuration
|
|
46
|
-
const INITIAL_RECONNECT_DELAY = 1000; // 1 second
|
|
47
|
-
const MAX_RECONNECT_DELAY = 30000; // 30 seconds max
|
|
48
|
-
const MAX_RECONNECT_ATTEMPTS = 10;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Hook to connect to memory WebSocket and handle real-time updates
|
|
52
|
-
*/
|
|
53
|
-
export function useMemoryWebSocket(options: UseMemoryWebSocketOptions = {}) {
|
|
54
|
-
const { enabled = true, onMessage } = options;
|
|
55
|
-
const queryClient = useQueryClient();
|
|
56
|
-
const wsRef = useRef<WebSocket | null>(null);
|
|
57
|
-
const reconnectTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
58
|
-
const reconnectAttemptsRef = useRef(0);
|
|
59
|
-
const reconnectDelayRef = useRef(INITIAL_RECONNECT_DELAY);
|
|
60
|
-
const connectRef = useRef<() => void>(() => {});
|
|
61
|
-
const [isConnected, setIsConnected] = useState(false);
|
|
62
|
-
const [lastEvent, setLastEvent] = useState<{
|
|
63
|
-
type: WebSocketEventType;
|
|
64
|
-
data?: unknown;
|
|
65
|
-
timestamp: string;
|
|
66
|
-
} | null>(null);
|
|
67
|
-
|
|
68
|
-
// Use ref for onMessage to avoid recreating connect callback when callback changes
|
|
69
|
-
// This prevents WebSocket reconnections on every render
|
|
70
|
-
const onMessageRef = useRef(onMessage);
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
onMessageRef.current = onMessage;
|
|
73
|
-
}, [onMessage]);
|
|
74
|
-
|
|
75
|
-
const connect = useCallback(() => {
|
|
76
|
-
if (!enabled || wsRef.current?.readyState === WebSocket.OPEN) return;
|
|
77
|
-
|
|
78
|
-
// Clear any pending reconnect timeout
|
|
79
|
-
if (reconnectTimeoutRef.current) {
|
|
80
|
-
clearTimeout(reconnectTimeoutRef.current);
|
|
81
|
-
reconnectTimeoutRef.current = null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
const ws = new WebSocket(WS_URL);
|
|
86
|
-
wsRef.current = ws;
|
|
87
|
-
|
|
88
|
-
ws.onopen = () => {
|
|
89
|
-
setIsConnected(true);
|
|
90
|
-
// Reset reconnect state on successful connection
|
|
91
|
-
reconnectAttemptsRef.current = 0;
|
|
92
|
-
reconnectDelayRef.current = INITIAL_RECONNECT_DELAY;
|
|
93
|
-
console.log('[WebSocket] Connected to memory server');
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
ws.onmessage = (event) => {
|
|
97
|
-
try {
|
|
98
|
-
const message = JSON.parse(event.data) as WebSocketMessage & { timestamp?: string };
|
|
99
|
-
setLastEvent({
|
|
100
|
-
type: message.type,
|
|
101
|
-
data: message.data,
|
|
102
|
-
timestamp: message.timestamp || new Date().toISOString(),
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Notify external handler (use ref to avoid stale closure)
|
|
106
|
-
onMessageRef.current?.(message);
|
|
107
|
-
|
|
108
|
-
// Invalidate relevant queries based on event type
|
|
109
|
-
switch (message.type) {
|
|
110
|
-
case 'initial_state':
|
|
111
|
-
// Full state received, refresh everything
|
|
112
|
-
queryClient.invalidateQueries({ queryKey: ['memories'] });
|
|
113
|
-
queryClient.invalidateQueries({ queryKey: ['stats'] });
|
|
114
|
-
queryClient.invalidateQueries({ queryKey: ['links'] });
|
|
115
|
-
break;
|
|
116
|
-
|
|
117
|
-
case 'memory_created':
|
|
118
|
-
case 'memory_updated':
|
|
119
|
-
case 'memory_deleted':
|
|
120
|
-
// Memory changed, refresh memories list
|
|
121
|
-
queryClient.invalidateQueries({ queryKey: ['memories'] });
|
|
122
|
-
queryClient.invalidateQueries({ queryKey: ['stats'] });
|
|
123
|
-
break;
|
|
124
|
-
|
|
125
|
-
case 'consolidation_complete':
|
|
126
|
-
// Major changes, refresh everything
|
|
127
|
-
queryClient.invalidateQueries({ queryKey: ['memories'] });
|
|
128
|
-
queryClient.invalidateQueries({ queryKey: ['stats'] });
|
|
129
|
-
queryClient.invalidateQueries({ queryKey: ['links'] });
|
|
130
|
-
break;
|
|
131
|
-
|
|
132
|
-
case 'decay_tick':
|
|
133
|
-
// Just decay scores updated, soft refresh
|
|
134
|
-
// We don't invalidate here to avoid constant refetches
|
|
135
|
-
// The dashboard can handle this via the onMessage callback
|
|
136
|
-
break;
|
|
137
|
-
|
|
138
|
-
// Phase 4: Worker events
|
|
139
|
-
case 'link_discovered':
|
|
140
|
-
// New link created, refresh links
|
|
141
|
-
queryClient.invalidateQueries({ queryKey: ['links'] });
|
|
142
|
-
break;
|
|
143
|
-
|
|
144
|
-
case 'predictive_consolidation':
|
|
145
|
-
// Predictive consolidation ran, refresh everything
|
|
146
|
-
queryClient.invalidateQueries({ queryKey: ['memories'] });
|
|
147
|
-
queryClient.invalidateQueries({ queryKey: ['stats'] });
|
|
148
|
-
queryClient.invalidateQueries({ queryKey: ['links'] });
|
|
149
|
-
break;
|
|
150
|
-
|
|
151
|
-
case 'worker_light_tick':
|
|
152
|
-
case 'worker_medium_tick':
|
|
153
|
-
// Worker ticks don't require cache invalidation
|
|
154
|
-
// Dashboard can track via onMessage callback if needed
|
|
155
|
-
break;
|
|
156
|
-
|
|
157
|
-
// Version/Update events
|
|
158
|
-
case 'update_started':
|
|
159
|
-
case 'update_complete':
|
|
160
|
-
case 'update_failed':
|
|
161
|
-
// Let VersionPanel handle via onMessage callback
|
|
162
|
-
// Invalidate version queries on completion
|
|
163
|
-
if (message.type === 'update_complete') {
|
|
164
|
-
queryClient.invalidateQueries({ queryKey: ['version'] });
|
|
165
|
-
queryClient.invalidateQueries({ queryKey: ['version-check'] });
|
|
166
|
-
}
|
|
167
|
-
break;
|
|
168
|
-
|
|
169
|
-
case 'server_restarting':
|
|
170
|
-
// Server is restarting - let onMessage callback handle UI
|
|
171
|
-
console.log('[WebSocket] Server restarting, will reconnect shortly...');
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
} catch (err) {
|
|
175
|
-
console.error('[WebSocket] Failed to parse message:', err);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
ws.onerror = () => {
|
|
180
|
-
// Use warn instead of error to avoid Next.js error overlay in dev mode
|
|
181
|
-
// WebSocket connection failures are expected when API server isn't running
|
|
182
|
-
console.warn('[WebSocket] Connection failed - is the API server running?');
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
ws.onclose = () => {
|
|
186
|
-
setIsConnected(false);
|
|
187
|
-
console.log('[WebSocket] Disconnected');
|
|
188
|
-
|
|
189
|
-
// Attempt to reconnect with exponential backoff
|
|
190
|
-
if (enabled && reconnectAttemptsRef.current < MAX_RECONNECT_ATTEMPTS) {
|
|
191
|
-
const delay = reconnectDelayRef.current;
|
|
192
|
-
reconnectAttemptsRef.current++;
|
|
193
|
-
|
|
194
|
-
// Exponential backoff: double the delay each time, up to max
|
|
195
|
-
reconnectDelayRef.current = Math.min(
|
|
196
|
-
reconnectDelayRef.current * 2,
|
|
197
|
-
MAX_RECONNECT_DELAY
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
console.log(
|
|
201
|
-
`[WebSocket] Reconnecting in ${delay}ms (attempt ${reconnectAttemptsRef.current}/${MAX_RECONNECT_ATTEMPTS})...`
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
reconnectTimeoutRef.current = setTimeout(() => {
|
|
205
|
-
connectRef.current();
|
|
206
|
-
}, delay);
|
|
207
|
-
} else if (reconnectAttemptsRef.current >= MAX_RECONNECT_ATTEMPTS) {
|
|
208
|
-
console.error('[WebSocket] Max reconnection attempts reached. Use reconnect() to try again.');
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
} catch (err) {
|
|
212
|
-
console.error('[WebSocket] Failed to connect:', err);
|
|
213
|
-
}
|
|
214
|
-
}, [enabled, queryClient]); // onMessage accessed via ref to prevent reconnection loops
|
|
215
|
-
|
|
216
|
-
useEffect(() => {
|
|
217
|
-
connectRef.current = connect;
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Connect on mount
|
|
221
|
-
useEffect(() => {
|
|
222
|
-
if (enabled) {
|
|
223
|
-
connect();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return () => {
|
|
227
|
-
if (reconnectTimeoutRef.current) {
|
|
228
|
-
clearTimeout(reconnectTimeoutRef.current);
|
|
229
|
-
}
|
|
230
|
-
if (wsRef.current) {
|
|
231
|
-
wsRef.current.close();
|
|
232
|
-
wsRef.current = null;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}, [enabled, connect]);
|
|
236
|
-
|
|
237
|
-
// Manual reconnect that resets backoff state
|
|
238
|
-
const manualReconnect = useCallback(() => {
|
|
239
|
-
reconnectAttemptsRef.current = 0;
|
|
240
|
-
reconnectDelayRef.current = INITIAL_RECONNECT_DELAY;
|
|
241
|
-
connect();
|
|
242
|
-
}, [connect]);
|
|
243
|
-
|
|
244
|
-
return {
|
|
245
|
-
isConnected,
|
|
246
|
-
lastEvent,
|
|
247
|
-
reconnect: manualReconnect,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Types
|
|
3
|
-
* Shared type definitions for the dashboard
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type MemoryType = 'short_term' | 'long_term' | 'episodic';
|
|
7
|
-
|
|
8
|
-
export type MemoryCategory =
|
|
9
|
-
| 'architecture'
|
|
10
|
-
| 'pattern'
|
|
11
|
-
| 'preference'
|
|
12
|
-
| 'error'
|
|
13
|
-
| 'context'
|
|
14
|
-
| 'learning'
|
|
15
|
-
| 'todo'
|
|
16
|
-
| 'note'
|
|
17
|
-
| 'relationship'
|
|
18
|
-
| 'custom';
|
|
19
|
-
|
|
20
|
-
export interface Memory {
|
|
21
|
-
id: number;
|
|
22
|
-
type: MemoryType;
|
|
23
|
-
category: MemoryCategory;
|
|
24
|
-
title: string;
|
|
25
|
-
content: string;
|
|
26
|
-
project?: string;
|
|
27
|
-
tags: string[];
|
|
28
|
-
salience: number;
|
|
29
|
-
accessCount: number;
|
|
30
|
-
lastAccessed: string;
|
|
31
|
-
createdAt: string;
|
|
32
|
-
decayedScore?: number;
|
|
33
|
-
metadata?: Record<string, unknown>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface MemoryLink {
|
|
37
|
-
id: number;
|
|
38
|
-
source_id: number;
|
|
39
|
-
target_id: number;
|
|
40
|
-
relationship: string;
|
|
41
|
-
strength: number;
|
|
42
|
-
created_at: string;
|
|
43
|
-
source_title?: string;
|
|
44
|
-
target_title?: string;
|
|
45
|
-
source_category?: MemoryCategory;
|
|
46
|
-
target_category?: MemoryCategory;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface MemoryStats {
|
|
50
|
-
total: number;
|
|
51
|
-
shortTerm: number;
|
|
52
|
-
longTerm: number;
|
|
53
|
-
episodic: number;
|
|
54
|
-
byCategory: Record<string, number>;
|
|
55
|
-
averageSalience: number;
|
|
56
|
-
decayDistribution?: {
|
|
57
|
-
healthy: number;
|
|
58
|
-
fading: number;
|
|
59
|
-
critical: number;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface MemoryEvent {
|
|
64
|
-
type: 'memory_created' | 'memory_accessed' | 'memory_updated' | 'memory_deleted' | 'consolidation_complete' | 'decay_tick';
|
|
65
|
-
timestamp: string;
|
|
66
|
-
data: unknown;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface Memory3DPosition {
|
|
70
|
-
x: number;
|
|
71
|
-
y: number;
|
|
72
|
-
z: number;
|
|
73
|
-
}
|
package/dashboard/tsconfig.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2017",
|
|
4
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noEmit": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"module": "esnext",
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"jsx": "react-jsx",
|
|
15
|
-
"incremental": true,
|
|
16
|
-
"plugins": [
|
|
17
|
-
{
|
|
18
|
-
"name": "next"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"paths": {
|
|
22
|
-
"@/*": ["./src/*"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"include": [
|
|
26
|
-
"next-env.d.ts",
|
|
27
|
-
"**/*.ts",
|
|
28
|
-
"**/*.tsx",
|
|
29
|
-
".next/types/**/*.ts",
|
|
30
|
-
".next/dev/types/**/*.ts",
|
|
31
|
-
"**/*.mts"
|
|
32
|
-
],
|
|
33
|
-
"exclude": ["node_modules"]
|
|
34
|
-
}
|