veltrixcode commited on
Commit
59292dd
·
verified ·
1 Parent(s): 4d3c484

Delete client

Browse files
client/.DS_Store DELETED
Binary file (6.15 kB)
 
client/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
- yarn-debug.log*
6
- yarn-error.log*
7
- pnpm-debug.log*
8
- lerna-debug.log*
9
-
10
- node_modules
11
- dist
12
- dist-ssr
13
- *.local
14
-
15
- # Editor directories and files
16
- .vscode/*
17
- !.vscode/extensions.json
18
- .idea
19
- .DS_Store
20
- *.suo
21
- *.ntvs*
22
- *.njsproj
23
- *.sln
24
- *.sw?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
client/public/index.html DELETED
@@ -1,187 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="utf-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1">
7
- <title>Python IDE</title>
8
- <link rel="stylesheet" href="/styles.css">
9
- <link rel="icon" href="data:,">
10
-
11
- <script>/* WARNING: Hardcoding secrets is unsafe. Use env vars in production. */</script>
12
- <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.min.js"></script>
13
- <script>
14
- window.MonacoEnvironment = { getWorkerUrl: () => proxy };
15
- let proxy = URL.createObjectURL(new Blob([`self.MonacoEnvironment={baseUrl:'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/'};importScripts('https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/base/worker/workerMain.min.js');`], { type: 'text/javascript' }));
16
- window.API_BASE = '';
17
- </script>
18
- <script defer src="/script.js"></script>
19
- </head>
20
-
21
- <body>
22
- <div class="app">
23
- <!-- Topbar -->
24
- <div class="topbar">
25
- <div class="brand">Antigravity IDE</div>
26
-
27
- <div class="topbar-actions">
28
- <button id="artBtn" class="btn btn-secondary">Artifacts</button>
29
- <button id="genBtn" class="btn btn-primary">
30
- <span>✨</span> Generate
31
- </button>
32
- <button id="editBtn" class="btn btn-secondary">
33
- <span>✎</span> Edit
34
- </button>
35
- <button id="runBtnTop" class="btn btn-success">
36
- <span>▶</span> Run
37
- </button>
38
- </div>
39
- </div>
40
-
41
- <!-- Main Workspace -->
42
- <div class="top">
43
- <!-- Sidebar -->
44
- <div class="sidebar">
45
- <div class="toolbar">
46
- <button id="newFileBtn" class="btn btn-ghost" title="New File">+ New</button>
47
- <button id="deleteFileBtn" class="btn btn-ghost" title="Delete File">🗑</button>
48
- <button id="runBtn" class="btn btn-ghost" title="Run Script">▶</button>
49
- </div>
50
- <ul id="files" class="file-list"></ul>
51
- </div>
52
-
53
- <!-- Editor -->
54
- <div class="editor">
55
- <div id="editor"></div>
56
-
57
- <!-- Floating AI Fix Action -->
58
- <div id="aiFix" class="hidden" style="position: absolute; bottom: 20px; right: 20px; z-index: 5;">
59
- <button class="btn btn-danger" style="box-shadow: 0 4px 12px rgba(239,68,68,0.4)">
60
- Fix Error with AI
61
- </button>
62
- </div>
63
- </div>
64
- </div>
65
-
66
- <!-- Terminal -->
67
- <div class="terminal">
68
- <div class="term-chrome" id="termChrome">
69
- <div class="traffic-lights">
70
- <div class="traffic-light red"></div>
71
- <div class="traffic-light yellow"></div>
72
- <div class="traffic-light green"></div>
73
- </div>
74
- <div class="term-title" id="termTitle">terminal — /workspace</div>
75
- </div>
76
- <div id="output"></div>
77
- </div>
78
- </div>
79
-
80
- <!-- Context Menu -->
81
- <div id="ctxMenu" class="hidden"></div>
82
-
83
- <!-- Loading Overlay -->
84
- <div id="loading" class="modal-overlay">
85
- <div class="loading-card">
86
- <div class="spinner spin"
87
- style="width:20px;height:20px;border:2px solid #3b82f6;border-top-color:transparent;border-radius:50%"></div>
88
- <div id="loadingMsg">Processing...</div>
89
- </div>
90
- </div>
91
-
92
- <!-- Auth Modal -->
93
- <div id="authModal" class="modal-overlay open">
94
- <div class="modal">
95
- <h3>Welcome Back</h3>
96
- <p>Sign in to access your workspace. Your data is secure.</p>
97
-
98
- <div id="signupFields" class="hidden">
99
- <div style="display:grid; grid-template-columns: 1fr 1fr; gap:12px; margin-bottom:12px">
100
- <input id="authName" class="input" placeholder="Full name" type="text" />
101
- <div style="display:flex; gap:8px">
102
- <input id="authClass" class="input" placeholder="Class" type="text" />
103
- <input id="authSection" class="input" placeholder="Sec" type="text" />
104
- </div>
105
- </div>
106
- </div>
107
- <div class="input-group">
108
- <input id="email" class="input" placeholder="Email address" type="email" />
109
- </div>
110
- <div class="input-group">
111
- <input id="password" class="input" placeholder="Password" type="password" />
112
- </div>
113
-
114
- <div class="modal-footer" style="flex-direction: column; gap: 10px;">
115
- <button id="authSubmit" class="btn btn-primary" style="width:100%">Sign In</button>
116
- <button id="authSwitch" class="btn btn-ghost" style="width:100%; font-size:12px">Need an account? Create
117
- one</button>
118
- </div>
119
- <small style="display:block; margin-top:16px; color:var(--text-muted); text-align:center; font-size:11px">
120
- Secure session established.
121
- </small>
122
- </div>
123
- </div>
124
-
125
- <!-- Diff Modal -->
126
- <div id="diffModal" class="modal-overlay">
127
- <div class="modal diff-modal">
128
- <h3>Review Changes</h3>
129
- <div id="aiReason" style="color:var(--text-muted); font-size:13px; margin-bottom:12px"></div>
130
- <div id="diffBody" class="diff-content" style="flex:1"></div>
131
- <div class="modal-footer">
132
- <button id="closeDiff" class="btn btn-secondary">Cancel</button>
133
- <button id="applyFix" class="btn btn-success">Apply Changes</button>
134
- </div>
135
- </div>
136
- </div>
137
-
138
- <!-- Generate Modal -->
139
- <div id="genModal" class="modal-overlay">
140
- <div class="modal" style="max-width: 600px;">
141
- <h3>Generate Code</h3>
142
- <p>Describe what you want to build. I'll create the files for you.</p>
143
- <input id="genTarget" class="input" placeholder="Target file (optional, e.g., utils.py)"
144
- style="margin-bottom:12px" />
145
- <textarea id="genPrompt" class="input" placeholder="Describe the functionality..."
146
- style="height:120px; resize:none"></textarea>
147
-
148
- <div class="modal-footer">
149
- <button id="genClose" class="btn btn-secondary">Cancel</button>
150
- <button id="genSubmit" class="btn btn-primary">Generate</button>
151
- </div>
152
- </div>
153
- </div>
154
-
155
- <!-- Edit Modal -->
156
- <div id="editModal" class="modal-overlay">
157
- <div class="modal" style="max-width: 600px;">
158
- <h3>Refactor Code</h3>
159
- <p>Describe how you want to modify the current codebase.</p>
160
- <textarea id="editInstruction" class="input" placeholder="e.g., Add error handling to all API calls..."
161
- style="height:140px; resize:none"></textarea>
162
-
163
- <div class="modal-footer">
164
- <button id="editClose" class="btn btn-secondary">Cancel</button>
165
- <button id="editSubmit" class="btn btn-primary">Apply Edits</button>
166
- </div>
167
- </div>
168
- </div>
169
-
170
- <!-- Artifacts Modal -->
171
- <div id="artModal" class="modal-overlay">
172
- <div class="modal" style="max-width: 700px; height:80vh">
173
- <h3>Artifacts</h3>
174
- <div id="artList"
175
- style="display:grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap:8px; margin-top:10px">
176
- </div>
177
- <div id="artPreview"
178
- style="margin-top:16px; border-top:1px solid var(--border); padding-top:16px; flex:1; overflow:auto"></div>
179
- <div class="modal-footer" style="margin-top:auto">
180
- <button id="artClose" class="btn btn-secondary">Close</button>
181
- </div>
182
- </div>
183
- </div>
184
-
185
- </body>
186
-
187
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
client/public/script.js DELETED
@@ -1,350 +0,0 @@
1
- let editor; let currentPath = 'main.py'; let files = []; let autosaveTimer; let lastCommand = ''; let openSeq = 0; let currentUser = null;
2
-
3
- async function api(path, opts = {}) {
4
- const base = window.API_BASE || '';
5
- const res = await fetch(base + path, { credentials: 'include', headers: { 'Content-Type': 'application/json' }, ...opts });
6
- if (!res.ok) throw new Error(await res.text());
7
- return res.json();
8
- }
9
-
10
- function setAuthModal(visible) {
11
- const el = document.getElementById('authModal');
12
- if (visible) el.classList.add('open');
13
- else el.classList.remove('open');
14
- }
15
-
16
- async function ensureAuth() {
17
- try {
18
- const me = await api('/api/auth/me');
19
- setAuthModal(false);
20
- currentUser = me?.user || null;
21
- updateTerminalTitle(currentUser);
22
- ensurePrompt();
23
- loadFiles();
24
- } catch { setAuthModal(true); }
25
- }
26
-
27
- function initMonaco() {
28
- require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs' } });
29
- require(['vs/editor/editor.main'], function () {
30
- editor = monaco.editor.create(document.getElementById('editor'), {
31
- value: '', language: 'python', theme: 'vs-dark', fontSize: 12
32
- });
33
- editor.onDidChangeModelContent(scheduleAutosave);
34
- });
35
- }
36
-
37
- async function loadFiles() {
38
- const data = await api('/api/files/list'); files = data.files || []; renderFileList();
39
- // Open main.py by default
40
- const hasMain = files.find(f => f.path === 'main.py'); openFile(hasMain ? 'main.py' : (files[0]?.path || 'main.py'));
41
- }
42
-
43
- function renderFileList() {
44
- const ul = document.getElementById('files'); ul.innerHTML = '';
45
- files.forEach(f => { const li = document.createElement('li'); li.className = 'file-item'; if (f.path === currentPath) li.style.background = '#1a2133'; li.textContent = f.path; li.onclick = () => openFile(f.path); li.oncontextmenu = (e) => showCtx(e, f.path); ul.appendChild(li); });
46
- }
47
-
48
- async function openFile(path) {
49
- currentPath = path; renderFileList();
50
- const seq = ++openSeq;
51
- try {
52
- const data = await api('/api/files/read?path=' + encodeURIComponent(path));
53
- if (seq !== openSeq || path !== currentPath) return; // stale response
54
- if (editor) {
55
- editor.setValue(data.content || '');
56
- // Ensure layout in case container size changed
57
- setTimeout(() => { try { editor.layout(); } catch { } }, 0);
58
- }
59
- } catch (e) {
60
- appendOutput('Failed to open ' + path, 'err');
61
- }
62
- }
63
-
64
- async function writeCurrentFile() {
65
- if (!editor) return; const content = editor.getValue();
66
- await api('/api/files/write', { method: 'POST', body: JSON.stringify({ path: currentPath, content }) });
67
- }
68
-
69
- function scheduleAutosave() { clearTimeout(autosaveTimer); autosaveTimer = setTimeout(writeCurrentFile, 2000); }
70
-
71
- function appendOutput(line, cls) {
72
- const out = document.getElementById('output');
73
- const div = document.createElement('div'); div.className = 'line';
74
- if (cls) div.classList.add(cls);
75
- // Basic ANSI colorization
76
- div.textContent = line;
77
- div.innerHTML = div.innerHTML
78
- .replace(/\x1b\[90m/g, '<span class="ansi-gray">')
79
- .replace(/\x1b\[91m/g, '<span class="ansi-red">')
80
- .replace(/\x1b\[92m/g, '<span class="ansi-green">')
81
- .replace(/\x1b\[93m/g, '<span class="ansi-yellow">')
82
- .replace(/\x1b\[94m/g, '<span class="ansi-blue">')
83
- .replace(/\x1b\[95m/g, '<span class="ansi-magenta">')
84
- .replace(/\x1b\[96m/g, '<span class="ansi-cyan">')
85
- .replace(/\x1b\[1m/g, '<span class="ansi-bold">')
86
- .replace(/\x1b\[0m/g, '</span>');
87
- out.appendChild(div); out.scrollTop = out.scrollHeight;
88
- }
89
-
90
- function ensurePrompt() {
91
- const out = document.getElementById('output');
92
- let p = document.getElementById('promptLine');
93
- if (!p) {
94
- p = document.createElement('div'); p.id = 'promptLine'; p.className = 'prompt';
95
- const ps1 = document.createElement('span'); ps1.className = 'ps1'; ps1.id = 'ps1'; ps1.textContent = getPromptText();
96
- const input = document.createElement('input'); input.id = 'cmdInline'; input.placeholder = 'Type commands like: python3 main.py';
97
- input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { const v = input.value.trim(); if (v) { runCommandSSE(v); input.value = ''; } } });
98
- p.appendChild(ps1); p.appendChild(input); out.appendChild(p);
99
- } else {
100
- const ps1 = document.getElementById('ps1'); if (ps1) ps1.textContent = getPromptText();
101
- out.appendChild(p);
102
- }
103
- out.scrollTop = out.scrollHeight;
104
- }
105
-
106
- function setAIFixVisible(v) { document.getElementById('aiFix').style.display = v ? 'block' : 'none'; }
107
-
108
- async function runCommand(cmd) {
109
- lastCommand = cmd; appendOutput('$ ' + cmd); setAIFixVisible(false);
110
- const res = await fetch(window.API_BASE + '/api/terminal/run', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ command: cmd }) });
111
- if (!res.ok) { appendOutput('Failed to start command', 'err'); return; }
112
- const es = new EventSource(window.API_BASE + '/api/terminal/run', { withCredentials: true });
113
- }
114
-
115
- async function runCommandSSE(cmd) {
116
- // Start SSE by posting first to initiate process and then listening via fetch stream endpoint. We instead reuse the POST endpoint that streams directly.
117
- const res = await fetch(window.API_BASE + '/api/terminal/run', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ command: cmd }) });
118
- if (!res.ok || !res.body) { appendOutput('Command not allowed', 'err'); return; }
119
- appendOutput(getPromptText() + ' ' + cmd, 'ansi-gray');
120
- const reader = res.body.getReader(); const decoder = new TextDecoder(); let buffer = ''; let hadError = false; let exitCode = 0;
121
- while (true) {
122
- const { value, done } = await reader.read(); if (done) break; buffer += decoder.decode(value, { stream: true });
123
- const parts = buffer.split('\n\n'); buffer = parts.pop();
124
- for (const part of parts) {
125
- const lines = part.split('\n'); const evt = lines.find(l => l.startsWith('event: '))?.slice(7).trim();
126
- const dataLine = lines.find(l => l.startsWith('data: ')); if (!evt || !dataLine) continue; const payload = JSON.parse(dataLine.slice(6));
127
- if (evt === 'stdout') appendOutput(payload.chunk);
128
- if (evt === 'stderr') { appendOutput(payload.chunk, 'err'); hadError = true; }
129
- if (evt === 'exit') { exitCode = payload.code; if (exitCode !== 0 || hadError) setAIFixVisible(true); }
130
- }
131
- }
132
- ensurePrompt();
133
- }
134
-
135
- async function proposeFix() {
136
- const out = document.getElementById('output').innerText;
137
- const btn = document.getElementById('aiFix');
138
- btn.style.pointerEvents = 'none';
139
- btn.querySelector('button').textContent = 'Thinking…';
140
- try {
141
- showLoading('Proposing AI fix…');
142
- const { id, proposed } = await api('/api/ai/propose-fix', { method: 'POST', body: JSON.stringify({ errorOutput: out }) });
143
- document.getElementById('aiReason').textContent = proposed.reason ? ('Reason: ' + proposed.reason) : '';
144
- const body = document.getElementById('diffBody'); body.innerHTML = '';
145
- (proposed.changes || []).forEach(ch => {
146
- const pre = document.createElement('pre'); pre.textContent = `# ${ch.path}\n` + (ch.newContent || ''); body.appendChild(pre);
147
- });
148
- document.getElementById('diffModal').classList.add('open');
149
- document.getElementById('applyFix').onclick = async () => {
150
- showLoading('Applying fix…');
151
- await api('/api/ai/apply-fix', { method: 'POST', body: JSON.stringify({ id }) });
152
- document.getElementById('diffModal').classList.remove('open');
153
- setAIFixVisible(false);
154
- await loadFiles();
155
- if (lastCommand) runCommandSSE(lastCommand);
156
- // hide button after accept
157
- document.getElementById('aiFix').style.display = 'none';
158
- hideLoading();
159
- };
160
- } catch (e) {
161
- alert('AI fix failed');
162
- } finally {
163
- hideLoading();
164
- btn.style.pointerEvents = '';
165
- btn.querySelector('button').textContent = 'GET FIX WITH AI';
166
- }
167
- }
168
-
169
- function initUI() {
170
- // Auth logic
171
- let isSignup = false;
172
- const toggleAuth = () => {
173
- isSignup = !isSignup;
174
- const fields = document.getElementById('signupFields');
175
- const btn = document.getElementById('authSubmit');
176
- const sw = document.getElementById('authSwitch');
177
- const title = document.querySelector('#authModal h3');
178
-
179
- if (isSignup) {
180
- fields.classList.remove('hidden');
181
- btn.textContent = 'Create Account';
182
- sw.textContent = 'Already have an account? Sign In';
183
- title.textContent = 'Create Account';
184
- } else {
185
- fields.classList.add('hidden');
186
- btn.textContent = 'Sign In';
187
- sw.textContent = 'Need an account? Create one';
188
- title.textContent = 'Welcome Back';
189
- }
190
- };
191
- document.getElementById('authSwitch').onclick = toggleAuth;
192
-
193
- document.getElementById('authSubmit').onclick = async () => {
194
- const emailVal = document.getElementById('email').value;
195
- const passVal = document.getElementById('password').value;
196
- if (!emailVal || !passVal) return alert('Email and Password required');
197
-
198
- try {
199
- if (isSignup) {
200
- const name = document.getElementById('authName').value.trim();
201
- const klass = document.getElementById('authClass').value.trim();
202
- const section = document.getElementById('authSection').value.trim();
203
- if (!name || !klass || !section) return alert('Please enter name, class, section');
204
- await api('/api/auth/signup', { method: 'POST', body: JSON.stringify({ email: emailVal, password: passVal, name, class: klass, section }) });
205
- } else {
206
- await api('/api/auth/signin', { method: 'POST', body: JSON.stringify({ email: emailVal, password: passVal }) });
207
- }
208
- setAuthModal(false);
209
- const me = await api('/api/auth/me');
210
- currentUser = me?.user || null;
211
- updateTerminalTitle(currentUser);
212
- ensurePrompt();
213
- await loadFiles();
214
- } catch (e) {
215
- alert((isSignup ? 'Signup' : 'Signin') + ' failed: ' + e.message);
216
- }
217
- };
218
- document.getElementById('runBtn').onclick = () => { runCommandSSE('python3 ' + currentPath); };
219
- const rtop = document.getElementById('runBtnTop'); if (rtop) rtop.onclick = () => { runCommandSSE('python3 main.py'); };
220
- // Buttons are bound in bindModals; ensure no duplicate handlers here
221
- document.getElementById('aiFix').onclick = proposeFix;
222
- document.getElementById('closeDiff').onclick = () => { document.getElementById('diffModal').classList.remove('open'); document.getElementById('aiFix').style.display = 'none'; };
223
- document.getElementById('newFileBtn').onclick = async () => { const p = prompt('New file path'); if (p) { await api('/api/files/write', { method: 'POST', body: JSON.stringify({ path: p, content: '' }) }); await loadFiles(); } };
224
- document.getElementById('deleteFileBtn').onclick = async () => { if (confirm('Delete ' + currentPath + '?')) { await api('/api/files/delete', { method: 'POST', body: JSON.stringify({ path: currentPath }) }); await loadFiles(); } };
225
- // Artifacts list open button and shortcut
226
- document.getElementById('artBtn').onclick = () => openArtifacts();
227
- document.addEventListener('keydown', async (e) => { if (e.ctrlKey && e.key.toLowerCase() === 'o') { e.preventDefault(); await openArtifacts(); } });
228
- }
229
-
230
- window.addEventListener('DOMContentLoaded', () => { patchModifierState(); initMonaco(); initUI(); bindModals(); ensureAuth(); ensurePrompt(); });
231
-
232
- // Context menu
233
- function hideCtx() { const c = document.getElementById('ctxMenu'); c.style.display = 'none'; }
234
- function showCtx(e, path) {
235
- e.preventDefault(); const c = document.getElementById('ctxMenu'); c.innerHTML = '';
236
- const mk = (label, fn) => { const b = document.createElement('button'); b.textContent = label; b.onclick = () => { hideCtx(); fn(); }; return b; };
237
- c.appendChild(mk('Open', () => openFile(path)));
238
- c.appendChild(mk('Rename', async () => { const np = prompt('Rename to', path); if (np && np !== path) { await api('/api/files/rename', { method: 'POST', body: JSON.stringify({ oldPath: path, newPath: np }) }); await loadFiles(); openFile(np); } }));
239
- c.appendChild(mk('New File', async () => { const p = prompt('New file path'); if (p) { await api('/api/files/write', { method: 'POST', body: JSON.stringify({ path: p, content: '' }) }); await loadFiles(); openFile(p); } }));
240
- c.appendChild(mk('New Folder (placeholder)', () => { }));
241
- c.appendChild(mk('Delete', async () => { if (confirm('Delete ' + path + '?')) { await api('/api/files/delete', { method: 'POST', body: JSON.stringify({ path }) }); await loadFiles(); } }));
242
- c.appendChild(mk('Refresh', () => loadFiles()));
243
- c.style.left = e.pageX + 'px'; c.style.top = e.pageY + 'px'; c.classList.add('open');
244
- }
245
- window.addEventListener('click', hideCtx);
246
-
247
- // AI generate modal (prompt → file)
248
- // Replaces showLoading/hideLoading
249
- function showLoading(msg) { const l = document.getElementById('loading'); document.getElementById('loadingMsg').textContent = msg || 'Working…'; l.classList.add('open'); }
250
- function hideLoading() { document.getElementById('loading').classList.remove('open'); }
251
-
252
- // Update bindModals to use classList
253
- function bindModals() {
254
- // Generate modal
255
- const gm = document.getElementById('genModal');
256
- document.getElementById('genBtn').onclick = () => { gm.classList.add('open'); };
257
- document.getElementById('genClose').onclick = () => { gm.classList.remove('open'); };
258
- document.getElementById('genSubmit').onclick = async () => {
259
- const target = document.getElementById('genTarget').value.trim();
260
- const promptText = document.getElementById('genPrompt').value.trim();
261
- if (!promptText) return alert('Prompt required');
262
- try {
263
- showLoading('Generating code…');
264
- await api('/api/ai/generate-code', { method: 'POST', body: JSON.stringify({ prompt: promptText, targetPath: target || undefined }) });
265
- gm.classList.remove('open');
266
- await loadFiles();
267
- if (target) openFile(target);
268
- } catch (e) { alert('Generate failed'); }
269
- finally { hideLoading(); }
270
- };
271
-
272
- // Edit modal
273
- const em = document.getElementById('editModal');
274
- document.getElementById('editBtn').onclick = () => { em.classList.add('open'); };
275
- document.getElementById('editClose').onclick = () => { em.classList.remove('open'); };
276
- document.getElementById('editSubmit').onclick = async () => {
277
- const instruction = document.getElementById('editInstruction').value.trim();
278
- if (!instruction) return alert('Instruction required');
279
- try {
280
- showLoading('Applying edits…');
281
- await api('/api/ai/edit-code', { method: 'POST', body: JSON.stringify({ instruction }) });
282
- em.classList.remove('open');
283
- await loadFiles();
284
- } catch (e) { alert('Edit failed'); }
285
- finally { hideLoading(); }
286
- };
287
-
288
- // Artifacts modal
289
- document.getElementById('artClose').onclick = () => { document.getElementById('artModal').classList.remove('open'); };
290
- }
291
-
292
- async function openArtifacts() {
293
- try {
294
- showLoading('Loading artifacts…');
295
- const { items } = await api('/api/root');
296
- const list = document.getElementById('artList'); list.innerHTML = '';
297
- const preview = document.getElementById('artPreview'); preview.innerHTML = '';
298
- items.forEach(it => {
299
- const name = document.createElement('div'); name.textContent = it.name + (it.isDir ? '/' : ''); name.style.fontSize = '13px'; name.style.color = '#e4e4e7';
300
- const view = document.createElement('div'); const actions = document.createElement('div');
301
- if (!it.isDir) {
302
- const viewBtn = document.createElement('button'); viewBtn.textContent = 'View';
303
- viewBtn.className = 'btn btn-secondary'; viewBtn.style.padding = '4px 8px'; viewBtn.style.fontSize = '11px'; viewBtn.style.marginRight = '4px';
304
- viewBtn.onclick = () => {
305
- const url = `${window.API_BASE}/api/root/get?path=${encodeURIComponent(it.name)}`;
306
- const ext = it.name.toLowerCase();
307
- if (/(png|jpg|jpeg|gif|svg|webp)$/.test(ext)) {
308
- preview.innerHTML = ''; const img = new Image(); img.src = url; img.style.maxWidth = '100%'; preview.appendChild(img);
309
- } else if (/(mp4|webm|ogg)$/.test(ext)) {
310
- preview.innerHTML = ''; const v = document.createElement('video'); v.controls = true; v.src = url; v.style.maxWidth = '100%'; preview.appendChild(v);
311
- } else if (/(txt|log|json|csv|md)$/.test(ext)) {
312
- preview.innerHTML = 'Loading…'; fetch(url, { credentials: 'include' }).then(r => r.text()).then(t => { const pre = document.createElement('pre'); pre.textContent = t; preview.innerHTML = ''; preview.appendChild(pre); });
313
- } else {
314
- preview.innerHTML = 'Preview not available.';
315
- }
316
- };
317
- const openBtn = document.createElement('button'); openBtn.textContent = 'Open';
318
- openBtn.className = 'btn btn-primary'; openBtn.style.padding = '4px 8px'; openBtn.style.fontSize = '11px';
319
- openBtn.onclick = () => { const url = `${window.API_BASE}/api/root/get?path=${encodeURIComponent(it.name)}`; window.open(url, '_blank'); };
320
- view.appendChild(viewBtn); actions.appendChild(openBtn);
321
- }
322
- list.appendChild(name); list.appendChild(view); list.appendChild(actions);
323
- });
324
- document.getElementById('artModal').classList.add('open');
325
- } finally { hideLoading(); }
326
- }
327
-
328
- // Patch for environments where KeyboardEvent.getModifierState may be missing on dispatched events
329
- function patchModifierState() {
330
- const types = ['keydown', 'keyup', 'mousedown', 'mouseup', 'mousemove'];
331
- const add = (e) => { if (typeof e.getModifierState !== 'function') { e.getModifierState = function () { return false; }; } };
332
- types.forEach(t => document.addEventListener(t, add, true));
333
- }
334
-
335
- function updateTerminalTitle(user) {
336
- if (!user) return;
337
- const title = document.getElementById('termTitle');
338
- if (user.name && user.class && user.section) {
339
- const display = `${user.name}@${user.class}-${user.section}`;
340
- title.textContent = `${display} — /workspace`;
341
- }
342
- }
343
-
344
- function getPromptText() {
345
- const u = currentUser;
346
- if (!u || !u.name || !u.class || !u.section) return '$';
347
- return `${u.name}@${u.class}-${u.section} %`;
348
- }
349
-
350
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
client/public/styles.css DELETED
@@ -1,459 +0,0 @@
1
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
2
-
3
- :root {
4
- --bg-dark: #09090b;
5
- --bg-card: #141419;
6
- /* #18181b; */
7
- --bg-sidebar: #0f1014;
8
- --bg-hover: #27272a;
9
-
10
- --border: #27272a;
11
- --border-light: #3f3f46;
12
-
13
- --text-main: #e4e4e7;
14
- --text-muted: #a1a1aa;
15
-
16
- --primary: #3b82f6;
17
- --primary-hover: #2563eb;
18
-
19
- --success: #22c55e;
20
- --danger: #ef4444;
21
- --warning: #f59e0b;
22
-
23
- --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
24
- --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
25
- --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
26
- --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);
27
-
28
- --radius-sm: 6px;
29
- --radius: 8px;
30
- --radius-lg: 12px;
31
-
32
- --font-sans: 'Inter', sans-serif;
33
- --font-mono: 'JetBrains Mono', monospace;
34
- }
35
-
36
- /* Reset & Base */
37
- *,
38
- *::before,
39
- *::after {
40
- box-sizing: border-box;
41
- }
42
-
43
- body {
44
- margin: 0;
45
- background-color: var(--bg-dark);
46
- color: var(--text-main);
47
- font-family: var(--font-sans);
48
- -webkit-font-smoothing: antialiased;
49
- height: 100vh;
50
- overflow: hidden;
51
- }
52
-
53
- /* Layout */
54
- .app {
55
- display: grid;
56
- grid-template-rows: 56px 1fr 240px;
57
- height: 100vh;
58
- }
59
-
60
- @media (max-width: 800px) {
61
- .app {
62
- grid-template-rows: 50px 1fr 35vh;
63
- }
64
-
65
- .top {
66
- grid-template-columns: 1fr !important;
67
- }
68
-
69
- .sidebar {
70
- display: none;
71
- }
72
-
73
- /* Hide sidebar on mobile for now or make it a drawer */
74
- }
75
-
76
- /* Topbar */
77
- .topbar {
78
- display: flex;
79
- align-items: center;
80
- gap: 16px;
81
- padding: 0 20px;
82
- background: var(--bg-sidebar);
83
- border-bottom: 1px solid var(--border);
84
- z-index: 10;
85
- }
86
-
87
- .brand {
88
- font-weight: 700;
89
- font-size: 18px;
90
- background: linear-gradient(135deg, #fff, #a1a1aa);
91
- background-clip: text;
92
- -webkit-background-clip: text;
93
- -webkit-text-fill-color: transparent;
94
- letter-spacing: -0.5px;
95
- }
96
-
97
- .topbar-actions {
98
- margin-left: auto;
99
- display: flex;
100
- gap: 10px;
101
- }
102
-
103
- /* Buttons */
104
- button {
105
- cursor: pointer;
106
- border: none;
107
- font-family: var(--font-sans);
108
- transition: all 0.2s ease;
109
- }
110
-
111
- .btn {
112
- padding: 8px 14px;
113
- border-radius: var(--radius);
114
- font-size: 13px;
115
- font-weight: 500;
116
- display: inline-flex;
117
- align-items: center;
118
- justify-content: center;
119
- gap: 6px;
120
- }
121
-
122
- .btn-primary {
123
- background: var(--primary);
124
- color: white;
125
- box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
126
- }
127
-
128
- .btn-primary:hover {
129
- background: var(--primary-hover);
130
- transform: translateY(-1px);
131
- }
132
-
133
- .btn-primary:active {
134
- transform: translateY(0);
135
- }
136
-
137
- .btn-secondary {
138
- background: var(--bg-hover);
139
- color: var(--text-main);
140
- border: 1px solid var(--border);
141
- }
142
-
143
- .btn-secondary:hover {
144
- background: var(--border-light);
145
- }
146
-
147
- .btn-success {
148
- background: var(--success);
149
- color: white;
150
- }
151
-
152
- .btn-success:hover {
153
- filter: brightness(1.1);
154
- }
155
-
156
- .btn-danger {
157
- background: var(--danger);
158
- color: white;
159
- }
160
-
161
- .btn-ghost {
162
- background: transparent;
163
- color: var(--text-muted);
164
- }
165
-
166
- .btn-ghost:hover {
167
- color: var(--text-main);
168
- background: rgba(255, 255, 255, 0.05);
169
- }
170
-
171
- /* Main Area */
172
- .top {
173
- display: grid;
174
- grid-template-columns: 260px 1fr;
175
- overflow: hidden;
176
- }
177
-
178
- /* Sidebar */
179
- .sidebar {
180
- background: var(--bg-sidebar);
181
- border-right: 1px solid var(--border);
182
- display: flex;
183
- flex-direction: column;
184
- }
185
-
186
- .toolbar {
187
- padding: 12px;
188
- border-bottom: 1px solid var(--border);
189
- display: flex;
190
- gap: 8px;
191
- }
192
-
193
- .toolbar .btn {
194
- flex: 1;
195
- padding: 6px;
196
- font-size: 12px;
197
- }
198
-
199
- .file-list {
200
- list-style: none;
201
- margin: 0;
202
- padding: 8px;
203
- overflow-y: auto;
204
- flex: 1;
205
- }
206
-
207
- .file-item {
208
- padding: 8px 12px;
209
- margin-bottom: 2px;
210
- border-radius: var(--radius);
211
- display: flex;
212
- align-items: center;
213
- gap: 10px;
214
- color: var(--text-muted);
215
- cursor: pointer;
216
- font-size: 13px;
217
- transition: background 0.15s;
218
- }
219
-
220
- .file-item:hover,
221
- .file-item.active {
222
- background: var(--bg-hover);
223
- color: var(--text-main);
224
- }
225
-
226
- .file-item.active {
227
- font-weight: 500;
228
- border-left: 2px solid var(--primary);
229
- border-top-left-radius: 2px;
230
- border-bottom-left-radius: 2px;
231
- }
232
-
233
- /* Editor */
234
- .editor {
235
- position: relative;
236
- background: var(--bg-card);
237
- }
238
-
239
- #editor {
240
- width: 100%;
241
- height: 100%;
242
- }
243
-
244
- /* Terminal */
245
- .terminal {
246
- background: var(--bg-dark);
247
- border-top: 1px solid var(--border);
248
- display: flex;
249
- flex-direction: column;
250
- box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2);
251
- }
252
-
253
- .term-chrome {
254
- height: 36px;
255
- display: flex;
256
- align-items: center;
257
- padding: 0 16px;
258
- background: var(--bg-sidebar);
259
- border-bottom: 1px solid var(--border);
260
- gap: 10px;
261
- }
262
-
263
- .traffic-lights {
264
- display: flex;
265
- gap: 6px;
266
- }
267
-
268
- .traffic-light {
269
- width: 10px;
270
- height: 10px;
271
- border-radius: 50%;
272
- }
273
-
274
- .traffic-light.red {
275
- background: #ff5f57;
276
- }
277
-
278
- .traffic-light.yellow {
279
- background: #febc2e;
280
- }
281
-
282
- .traffic-light.green {
283
- background: #28c840;
284
- }
285
-
286
- .term-title {
287
- font-size: 12px;
288
- color: var(--text-muted);
289
- font-family: var(--font-mono);
290
- opacity: 0.7;
291
- }
292
-
293
- #output {
294
- flex: 1;
295
- padding: 16px;
296
- /* increased padding */
297
- font-family: var(--font-mono);
298
- font-size: 13px;
299
- color: var(--text-main);
300
- overflow-y: auto;
301
- line-height: 1.5;
302
- }
303
-
304
- #output .line {
305
- min-height: 1.5em;
306
- }
307
-
308
- /* Components */
309
- .modal-overlay {
310
- position: fixed;
311
- inset: 0;
312
- background: rgba(0, 0, 0, 0.7);
313
- backdrop-filter: blur(4px);
314
- z-index: 100;
315
- display: flex;
316
- align-items: center;
317
- justify-content: center;
318
- opacity: 0;
319
- pointer-events: none;
320
- transition: opacity 0.2s;
321
- }
322
-
323
- .modal-overlay.open {
324
- opacity: 1;
325
- pointer-events: auto;
326
- }
327
-
328
- .modal {
329
- background: #18181b;
330
- border: 1px solid var(--border);
331
- border-radius: var(--radius-lg);
332
- padding: 24px;
333
- width: 90%;
334
- max-width: 420px;
335
- box-shadow: var(--shadow-lg);
336
- transform: scale(0.95);
337
- transition: transform 0.2s;
338
- }
339
-
340
- .modal-overlay.open .modal {
341
- transform: scale(1);
342
- }
343
-
344
- .modal h3 {
345
- margin-top: 0;
346
- font-size: 18px;
347
- font-weight: 600;
348
- margin-bottom: 8px;
349
- }
350
-
351
- .modal p {
352
- color: var(--text-muted);
353
- font-size: 14px;
354
- margin-bottom: 20px;
355
- line-height: 1.5;
356
- }
357
-
358
- .input-group {
359
- margin-bottom: 16px;
360
- }
361
-
362
- .input {
363
- width: 100%;
364
- padding: 10px 12px;
365
- background: var(--bg-hover);
366
- border: 1px solid var(--border);
367
- border-radius: var(--radius);
368
- color: var(--text-main);
369
- font-family: var(--font-sans);
370
- font-size: 14px;
371
- transition: border-color 0.2s, box-shadow 0.2s;
372
- }
373
-
374
- .input:focus {
375
- outline: none;
376
- border-color: var(--primary);
377
- box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
378
- }
379
-
380
- .modal-footer {
381
- display: flex;
382
- gap: 12px;
383
- margin-top: 24px;
384
- }
385
-
386
- .modal-footer .btn {
387
- flex: 1;
388
- }
389
-
390
- .diff-modal .modal {
391
- max-width: 800px;
392
- max-height: 85vh;
393
- display: flex;
394
- flex-direction: column;
395
- }
396
-
397
- .diff-content {
398
- overflow-y: auto;
399
- background: var(--bg-dark);
400
- border-radius: var(--radius);
401
- padding: 12px;
402
- font-family: var(--font-mono);
403
- font-size: 12px;
404
- border: 1px solid var(--border);
405
- }
406
-
407
- /* Utilities */
408
- .hidden {
409
- display: none !important;
410
- }
411
-
412
- .spin {
413
- animation: spin 1s linear infinite;
414
- }
415
-
416
- @keyframes spin {
417
- 100% {
418
- transform: rotate(360deg);
419
- }
420
- }
421
-
422
- /* Context Menu */
423
- #ctxMenu {
424
- background: var(--bg-card);
425
- border: 1px solid var(--border-light);
426
- border-radius: var(--radius);
427
- padding: 4px;
428
- box-shadow: var(--shadow-lg);
429
- position: fixed;
430
- z-index: 100;
431
- min-width: 160px;
432
- }
433
-
434
- #ctxMenu button {
435
- width: 100%;
436
- text-align: left;
437
- padding: 8px 12px;
438
- background: transparent;
439
- color: var(--text-main);
440
- font-size: 13px;
441
- border-radius: 4px;
442
- }
443
-
444
- #ctxMenu button:hover {
445
- background: var(--primary);
446
- color: white;
447
- }
448
-
449
- /* Loading */
450
- .loading-card {
451
- background: var(--bg-card);
452
- padding: 16px 24px;
453
- border-radius: var(--radius-lg);
454
- display: flex;
455
- align-items: center;
456
- gap: 16px;
457
- border: 1px solid var(--border);
458
- box-shadow: var(--shadow-glow);
459
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
client/public/vite.svg DELETED