From 83d3f8da13947b6ec078a088a3993b05e3e6e1a8 Mon Sep 17 00:00:00 2001 From: Simos Date: Fri, 4 Jul 2025 20:18:25 +0200 Subject: [PATCH] Add environment configuration example, update .gitignore for additional files, and refactor Vite config to load environment variables. Remove obsolete settings and backup files. --- .claude/settings.local.json | 17 --- .env.example | 12 ++ .gitignore | 81 +++++++++-- server/claude-cli.js.backup.1750077611635 | 162 ---------------------- server/index.js | 4 +- src/components/MicButton.jsx | 1 - vite.config.js | 32 +++-- 7 files changed, 100 insertions(+), 209 deletions(-) delete mode 100755 .claude/settings.local.json create mode 100755 .env.example delete mode 100755 server/claude-cli.js.backup.1750077611635 diff --git a/.claude/settings.local.json b/.claude/settings.local.json deleted file mode 100755 index 63ff59d..0000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "permissions": { - "allow": [ - "Bash(git init:*)", - "Bash(mkdir:*)", - "Bash(git commit:*)", - "Bash(git push:*)", - "Bash(rg:*)", - "Bash(sed:*)", - "Bash(grep:*)", - "Bash(timeout:*)", - "Bash(curl:*)", - "Bash(npm install:*)" - ], - "deny": [] - } -} \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100755 index 0000000..7cd2dd5 --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +# Claude Code UI Environment Configuration +# Only includes variables that are actually used in the code + +# ============================================================================= +# SERVER CONFIGURATION +# ============================================================================= + +# Backend server port (Express API + WebSocket server) +#API server +PORT=3008 +#Frontend port +VITE_PORT=3009 \ No newline at end of file diff --git a/.gitignore b/.gitignore index cbe24f0..dd12aab 100755 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,14 @@ node_modules/ npm-debug.log* yarn-debug.log* yarn-error.log* +pnpm-debug.log* +lerna-debug.log* # Build outputs dist/ +dist-ssr/ build/ -*.tsbuildinfo +out/ # Environment variables .env @@ -16,17 +19,7 @@ build/ .env.test.local .env.production.local -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Coverage directory used by tools like istanbul -coverage/ -.nyc_output - -# IDE/Editor files +# IDE and editor files .vscode/ .idea/ *.swp @@ -43,9 +36,71 @@ ehthumbs.db Thumbs.db # Logs -logs *.log +logs/ + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage/ +*.lcov + +# nyc test coverage +.nyc_output + +# Dependency directories +jspm_packages/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt + +# Storybook build outputs +.out +.storybook-out # Temporary folders tmp/ temp/ + +# Vite +.vite/ + +# Local Netlify folder +.netlify + +# Claude specific +.claude/ + +# Database files +*.db +*.sqlite +*.sqlite3 \ No newline at end of file diff --git a/server/claude-cli.js.backup.1750077611635 b/server/claude-cli.js.backup.1750077611635 deleted file mode 100755 index 5e8ac87..0000000 --- a/server/claude-cli.js.backup.1750077611635 +++ /dev/null @@ -1,162 +0,0 @@ -const { spawn } = require('child_process'); - -async function spawnClaude(command, options = {}, ws) { - return new Promise(async (resolve, reject) => { - const { sessionId, projectPath, cwd, resume, toolsSettings } = options; - let capturedSessionId = sessionId; // Track session ID throughout the process - let sessionCreatedSent = false; // Track if we've already sent session-created event - - // Use tools settings passed from frontend, or defaults - const settings = toolsSettings || { - allowedTools: [], - disallowedTools: [], - skipPermissions: false - }; - - console.log('🔧 Using tools settings:', settings); - - // Build Claude CLI command - start with basic flags - const args = ['--output-format', 'stream-json', '--verbose']; - - // Add tools settings flags - if (settings.skipPermissions) { - args.push('--dangerously-skip-permissions'); - console.log('⚠️ Using --dangerously-skip-permissions'); - } - - // Add print flag if we have a command - if (command && command.trim()) { - args.push('--print'); - } - - // Add resume flag if resuming (after --print) - if (resume && sessionId) { - args.push('--resume', sessionId); - } - - // Add allowed tools - if (settings.allowedTools && settings.allowedTools.length > 0) { - for (const tool of settings.allowedTools) { - args.push('--allowedTools', tool); - console.log('✅ Allowing tool:', tool); - } - } - - // Add disallowed tools - if (settings.disallowedTools && settings.disallowedTools.length > 0) { - for (const tool of settings.disallowedTools) { - args.push('--disallowedTools', tool); - console.log('❌ Disallowing tool:', tool); - } - } - - // Add the command as the final argument - if (command && command.trim()) { - args.push(command); - } - - const workingDir = projectPath || cwd || process.cwd(); - console.log('Spawning Claude CLI:', 'claude', args.join(' ')); - console.log('Working directory:', workingDir); - console.log('Session info - Input sessionId:', sessionId, 'Resume:', resume); - - const claudeProcess = spawn('claude', args, { - cwd: workingDir, - stdio: ['pipe', 'pipe', 'pipe'] - }); - - // Handle stdout (streaming JSON responses) - claudeProcess.stdout.on('data', (data) => { - const lines = data.toString().split('\n').filter(line => line.trim()); - - for (const line of lines) { - try { - const response = JSON.parse(line); - - // Capture session ID if it's in the response - if (response.session_id && !capturedSessionId) { - capturedSessionId = response.session_id; - console.log('📝 Captured session ID:', capturedSessionId); - - // Send session-created event only once for new sessions - if (!sessionId && !sessionCreatedSent) { - sessionCreatedSent = true; - ws.send(JSON.stringify({ - type: 'session-created', - sessionId: capturedSessionId - })); - } - } - - // Send parsed response to WebSocket - ws.send(JSON.stringify({ - type: 'claude-response', - data: response - })); - } catch (parseError) { - // If not JSON, send as raw text - ws.send(JSON.stringify({ - type: 'claude-output', - data: line - })); - } - } - }); - - // Handle stderr - claudeProcess.stderr.on('data', (data) => { - console.error('Claude CLI stderr:', data.toString()); - ws.send(JSON.stringify({ - type: 'claude-error', - error: data.toString() - })); - }); - - // Handle process completion - claudeProcess.on('close', (code) => { - console.log(`Claude CLI process exited with code ${code}`); - - ws.send(JSON.stringify({ - type: 'claude-complete', - exitCode: code, - isNewSession: !sessionId && !!command // Flag to indicate this was a new session - })); - - if (code === 0) { - resolve(); - } else { - reject(new Error(`Claude CLI exited with code ${code}`)); - } - }); - - // Handle process errors - claudeProcess.on('error', (error) => { - console.error('Claude CLI process error:', error); - - ws.send(JSON.stringify({ - type: 'claude-error', - error: error.message - })); - - reject(error); - }); - - // Handle stdin for interactive mode - if (command) { - // For --print mode with arguments, we don't need to write to stdin - claudeProcess.stdin.end(); - } else { - // For interactive mode, we need to write the command to stdin if provided later - // Keep stdin open for interactive session - if (command !== undefined) { - claudeProcess.stdin.write(command + '\n'); - claudeProcess.stdin.end(); - } - // If no command provided, stdin stays open for interactive use - } - }); -} - -module.exports = { - spawnClaude -}; \ No newline at end of file diff --git a/server/index.js b/server/index.js index e87ad76..77a9ffa 100755 --- a/server/index.js +++ b/server/index.js @@ -822,9 +822,7 @@ async function getFileTree(dirPath, maxDepth = 3, currentDepth = 0, showHidden = for (const entry of entries) { // Debug: log all entries including hidden files - if (entry.name.startsWith('.')) { - console.log('📁 Found hidden file/folder:', entry.name, 'at depth:', currentDepth); - } + // Skip only heavy build directories if (entry.name === 'node_modules' || diff --git a/src/components/MicButton.jsx b/src/components/MicButton.jsx index a199e8b..38df817 100755 --- a/src/components/MicButton.jsx +++ b/src/components/MicButton.jsx @@ -12,7 +12,6 @@ export function MicButton({ onTranscript, className = '' }) { const lastTapRef = useRef(0); // Version indicator to verify updates - console.log('MicButton v2.0 loaded'); // Start recording const startRecording = async () => { diff --git a/vite.config.js b/vite.config.js index 0c1dad1..4d3971b 100755 --- a/vite.config.js +++ b/vite.config.js @@ -1,19 +1,25 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' -export default defineConfig({ - plugins: [react()], - server: { - port: process.env.VITE_PORT || 3001, - proxy: { - '/api': `http://localhost:${process.env.PORT || 3002}`, - '/ws': { - target: `ws://localhost:${process.env.PORT || 3002}`, - ws: true +export default defineConfig(({ command, mode }) => { + // Load env file based on `mode` in the current working directory. + const env = loadEnv(mode, process.cwd(), '') + + + return { + plugins: [react()], + server: { + port: parseInt(env.VITE_PORT) || 3001, + proxy: { + '/api': `http://localhost:${env.PORT || 3002}`, + '/ws': { + target: `ws://localhost:${env.PORT || 3002}`, + ws: true + } } + }, + build: { + outDir: 'dist' } - }, - build: { - outDir: 'dist' } }) \ No newline at end of file