visualknowledge 0.1.6 → 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.
- package/bin/visualknowledge.js +41 -3
- package/frontend/src/App.jsx +1 -0
- package/frontend/src/main.js +47 -1
- package/package.json +2 -2
package/bin/visualknowledge.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
const { spawn, exec } = require('child_process');
|
|
6
|
+
const fs = require('fs');
|
|
6
7
|
const net = require('net');
|
|
7
8
|
const os = require('os');
|
|
8
9
|
const path = require('path');
|
|
@@ -238,14 +239,37 @@ function openBrowser(url) {
|
|
|
238
239
|
});
|
|
239
240
|
}
|
|
240
241
|
|
|
242
|
+
// ─── Claude Code Config Loader ─────────────────────────────────
|
|
243
|
+
function loadClaudeEnv() {
|
|
244
|
+
const home = process.env.HOME || process.env.USERPROFILE || os.homedir();
|
|
245
|
+
if (!home) return null;
|
|
246
|
+
|
|
247
|
+
const candidates = [
|
|
248
|
+
path.join(home, '.claude', 'settings.json'),
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
for (const configPath of candidates) {
|
|
252
|
+
try {
|
|
253
|
+
const raw = fs.readFileSync(configPath, 'utf8');
|
|
254
|
+
const data = JSON.parse(raw);
|
|
255
|
+
if (data && typeof data.env === 'object' && data.env !== null) {
|
|
256
|
+
return { env: data.env, source: configPath };
|
|
257
|
+
}
|
|
258
|
+
} catch (_) {
|
|
259
|
+
// File not found or parse error — skip silently
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
|
|
241
265
|
// ─── T008: Python Flask Subprocess Launch ────────────────────
|
|
242
|
-
function startServer(pythonCmd, port) {
|
|
266
|
+
function startServer(pythonCmd, port, mergedEnv) {
|
|
243
267
|
const serverDir = path.resolve(__dirname, '..');
|
|
244
268
|
|
|
245
269
|
const child = spawn(pythonCmd, ['server.py', '--port', String(port)], {
|
|
246
270
|
cwd: serverDir,
|
|
247
271
|
stdio: 'inherit',
|
|
248
|
-
env:
|
|
272
|
+
env: mergedEnv,
|
|
249
273
|
detached: false,
|
|
250
274
|
});
|
|
251
275
|
|
|
@@ -327,6 +351,20 @@ async function main() {
|
|
|
327
351
|
// Banner
|
|
328
352
|
banner();
|
|
329
353
|
|
|
354
|
+
// Load Claude Code config (if available)
|
|
355
|
+
const claudeConfig = loadClaudeEnv();
|
|
356
|
+
// Claude config as base defaults, process.env always takes precedence
|
|
357
|
+
const mergedEnv = { ...(claudeConfig ? claudeConfig.env : {}), ...process.env };
|
|
358
|
+
if (claudeConfig) {
|
|
359
|
+
const hasKey = mergedEnv.ANTHROPIC_AUTH_TOKEN || mergedEnv.ANTHROPIC_API_KEY;
|
|
360
|
+
console.log(`${OK} Claude Code config loaded${hasKey ? '' : ' (no API key found)'}`);
|
|
361
|
+
} else {
|
|
362
|
+
const hasKey = process.env.ANTHROPIC_AUTH_TOKEN || process.env.ANTHROPIC_API_KEY;
|
|
363
|
+
if (!hasKey) {
|
|
364
|
+
console.log(`${WARN} No API key found (set ANTHROPIC_API_KEY or install Claude Code)`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
330
368
|
// Environment checks (T003-T005)
|
|
331
369
|
checkNodeVersion();
|
|
332
370
|
const pythonCmd = await checkPython();
|
|
@@ -349,7 +387,7 @@ async function main() {
|
|
|
349
387
|
|
|
350
388
|
// Start Python server (T008)
|
|
351
389
|
console.log('\n Starting server...');
|
|
352
|
-
const child = startServer(pythonCmd, actualPort);
|
|
390
|
+
const child = startServer(pythonCmd, actualPort, mergedEnv);
|
|
353
391
|
|
|
354
392
|
// Setup graceful shutdown (T016-T018)
|
|
355
393
|
setupShutdownHandlers(child);
|
package/frontend/src/App.jsx
CHANGED
package/frontend/src/main.js
CHANGED
|
@@ -9,9 +9,55 @@ import { createRoot } from 'react-dom/client';
|
|
|
9
9
|
import { App } from './App.jsx';
|
|
10
10
|
import { AppProvider } from './context/AppContext.jsx';
|
|
11
11
|
|
|
12
|
+
// ====== Error Boundary ======
|
|
13
|
+
|
|
14
|
+
class ErrorBoundary extends React.Component {
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
this.state = { error: null, errorInfo: null };
|
|
18
|
+
}
|
|
19
|
+
static getDerivedStateFromError(error) {
|
|
20
|
+
return { error };
|
|
21
|
+
}
|
|
22
|
+
componentDidCatch(error, errorInfo) {
|
|
23
|
+
console.error('[ErrorBoundary] React render error:', error, errorInfo);
|
|
24
|
+
this.setState({ error, errorInfo });
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
if (this.state.error) {
|
|
28
|
+
return React.createElement('div', {
|
|
29
|
+
style: {
|
|
30
|
+
padding: '24px', color: '#f87171', fontFamily: 'monospace',
|
|
31
|
+
fontSize: '14px', lineHeight: '1.6', whiteSpace: 'pre-wrap',
|
|
32
|
+
overflow: 'auto', height: '100vh', background: '#1c1917',
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
React.createElement('h2', null, 'React Rendering Error'),
|
|
36
|
+
React.createElement('p', null, this.state.error.toString()),
|
|
37
|
+
React.createElement('pre', null, this.state.errorInfo?.componentStack || ''),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return this.props.children;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ====== Bootstrap ======
|
|
45
|
+
|
|
46
|
+
console.log('[main] Loading app...');
|
|
47
|
+
|
|
12
48
|
const rootEl = document.getElementById('root');
|
|
13
49
|
if (!rootEl) {
|
|
14
50
|
throw new Error('Root element #root not found in DOM');
|
|
15
51
|
}
|
|
16
52
|
|
|
17
|
-
|
|
53
|
+
console.log('[main] Root element found, mounting React...');
|
|
54
|
+
|
|
55
|
+
createRoot(rootEl).render(
|
|
56
|
+
React.createElement(ErrorBoundary, null,
|
|
57
|
+
React.createElement(AppProvider, null,
|
|
58
|
+
React.createElement(App)
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
console.log('[main] App mounted successfully.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "visualknowledge",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Interactive AI Chat with Visualization - one-click launch via npx",
|
|
5
5
|
"bin": {
|
|
6
6
|
"visualknowledge": "./bin/visualknowledge.js"
|
|
@@ -26,4 +26,4 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "https://github.com/user/VisualKnowledge"
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|