shubhjn commited on
Commit
b0457c6
·
1 Parent(s): 161b919
components/dashboard/Dashboard.tsx CHANGED
@@ -77,7 +77,7 @@ export default function Dashboard() {
77
  body: JSON.stringify({ action: "prewarm", id: latest.id })
78
  }).catch(console.error);
79
  }
80
- }, [fetchProjects]);
81
 
82
 
83
  const checkContainerStatuses = async () => {
@@ -226,10 +226,6 @@ export default function Dashboard() {
226
 
227
  {/* Body */}
228
  <div className="flex-1 overflow-hidden dashboard-grid">
229
- {/* Dashboard Vitals (Strategic Integration) */}
230
- <div className="col-span-full px-8 pt-6">
231
- <DashboardVitals />
232
- </div>
233
 
234
  {/* Left Panel */}
235
  <div className="border-r border-(--border-subtle) flex flex-col overflow-y-auto p-6 gap-6">
@@ -281,6 +277,14 @@ export default function Dashboard() {
281
 
282
  {/* Right Panel */}
283
  <div className="flex flex-col overflow-hidden">
 
 
 
 
 
 
 
 
284
  {/* Search + Filter */}
285
  <div className="p-4 border-b border-(--border-subtle) flex items-center gap-3">
286
  <div className="relative flex-1 px-2 input">
@@ -326,9 +330,6 @@ export default function Dashboard() {
326
  </DropdownMenu.Portal>
327
  </DropdownMenu.Root>
328
  </div>
329
-
330
- {/* Project List */}
331
- <div className="flex-1 overflow-y-auto p-2">
332
  {loading ? (
333
  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 p-2">
334
  {[...Array(8)].map((_, i) => (
 
77
  body: JSON.stringify({ action: "prewarm", id: latest.id })
78
  }).catch(console.error);
79
  }
80
+ }, [fetchProjects, projects]);
81
 
82
 
83
  const checkContainerStatuses = async () => {
 
226
 
227
  {/* Body */}
228
  <div className="flex-1 overflow-hidden dashboard-grid">
 
 
 
 
229
 
230
  {/* Left Panel */}
231
  <div className="border-r border-(--border-subtle) flex flex-col overflow-y-auto p-6 gap-6">
 
277
 
278
  {/* Right Panel */}
279
  <div className="flex flex-col overflow-hidden">
280
+
281
+ {/* Project List */}
282
+ <div className="flex-1 overflow-y-auto p-2">
283
+ {/* Dashboard Vitals (Strategic Integration) */}
284
+ <div className="col-span-full px-8 pt-6">
285
+ <DashboardVitals />
286
+ </div>
287
+
288
  {/* Search + Filter */}
289
  <div className="p-4 border-b border-(--border-subtle) flex items-center gap-3">
290
  <div className="relative flex-1 px-2 input">
 
330
  </DropdownMenu.Portal>
331
  </DropdownMenu.Root>
332
  </div>
 
 
 
333
  {loading ? (
334
  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 p-2">
335
  {[...Array(8)].map((_, i) => (
lib/docker/manager.ts CHANGED
@@ -182,11 +182,16 @@ async function performProvisioning(config: WorkspaceConfig): Promise<WorkspaceOp
182
  provisioningBus.emit(`log:${config.id}`, msg);
183
  };
184
 
185
- log(`Provisioning hermetic environment for '${config.projectName}'...`);
186
-
187
- // 0. HF PERSISTENCE: Restore profile from Dataset if available
188
- await HFStorage.syncFromDataset((msg) => log(msg));
189
- HFStorage.startAutoSave(300000); // 5m auto-save
 
 
 
 
 
190
 
191
  // 1. Prepare Workspace Directory
192
  const workspaceRoot = process.env.WORKSPACE_ROOT || path.join(/*turbopackIgnore: true*/ '/home/node/w');
@@ -215,93 +220,100 @@ async function performProvisioning(config: WorkspaceConfig): Promise<WorkspaceOp
215
  fs.writeFileSync(flagPath, new Date().toISOString());
216
  }
217
 
218
- // 4. Identify Target Port
219
- const port = findAvailablePort();
220
 
221
- // 5. Spawn code-server
222
- const shellCommand = process.platform === 'win32' ? 'npx' : 'code-server';
223
- const args = process.platform === 'win32' ? ['code-server'] : [];
224
-
225
- const baseArgs = [
226
- '--auth', 'none',
227
- '--bind-addr', `127.0.0.1:${port}`,
228
- '--user-data-dir', userDataPath,
229
- '--disable-telemetry',
230
- '--disable-update-check',
231
- workspacePath
232
- ];
233
-
234
- const spawnEnv: NodeJS.ProcessEnv = { ...process.env, HOME: workspacePath };
235
- delete spawnEnv.PORT;
236
- delete spawnEnv.SERVER_PORT;
237
-
238
- const child = spawn(shellCommand, [...args, ...baseArgs], {
239
- env: spawnEnv,
240
- cwd: workspacePath,
241
- shell: process.platform === 'win32'
242
- });
243
-
244
- log(`Spawning VS Code Orchestrator (PID: ${child.pid})...`);
245
-
246
- child.on('error', (err) => log(`[FATAL] IDE binary failure: ${err.message}`));
247
- child.stdout.on('data', (data) => {
248
- const out = data.toString().trim();
249
- if (out.includes('listening on')) log(`[IDX:UP] ${out}`);
250
- else if (out.length > 0) log(`[IDE:CORE] ${out}`);
251
- });
252
-
253
- child.stderr.on('data', (data) => {
254
- const err = data.toString().trim();
255
- if (err.length > 0) log(`[IDE:ERR] ${err}`);
256
- });
257
-
258
- child.on('close', (code, signal) => {
259
- log(`[IDE:EXIT] IDE process died with code ${code} (Signal: ${signal})`);
260
- });
261
-
262
- // 6. Register in active pool
263
- nativeProcesses.set(config.id, { pid: child.pid!, port, process: child });
264
-
265
- // 7. Handshake Loop
266
- let attempts = 0;
267
- while (attempts < 60) {
268
- try {
269
- const res = await fetch(`http://127.0.0.1:${port}`);
270
- if (res.ok) {
271
- log(`Handshake verified. Studio Engine Online.`);
272
 
273
- if (idxConfig.onStart) {
274
- log(`Executing background onStart lifecycle hooks...`);
275
- IdxEngine.runHook(workspacePath, 'onStart', idxConfig.onStart, (msg) => log(msg), true);
276
- }
 
 
 
 
277
 
278
- const finalResult = {
279
- success: true,
280
- containerId: `native-${config.id}`,
281
- androidPort: config.withAndroidEmulator ? 6080 : undefined,
282
- port: port
283
- };
284
- provisioningBus.emit(`ready:${config.id}`, finalResult);
285
- return finalResult;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  }
287
- } catch {
288
- if (attempts % 5 === 0) log(`[INFO] Scanning for IDE heartbeat... (Attempt ${attempts}/60)`);
289
- if (attempts === 15) log(`[INFO] Nix evaluation in progress. Cold boot detected.`);
290
- if (attempts === 45) log(`[WARN] Handshake threshold approaching. IDE core high load.`);
291
- await delay(1000);
292
- attempts++;
293
  }
294
- }
295
 
296
- log(`[FATAL] Handshake timeout on 127.0.0.1:${port}.`);
297
- const entry = nativeProcesses.get(config.id);
298
- if (entry) {
299
- entry.process.kill();
300
- nativeProcesses.delete(config.id);
 
 
 
 
 
 
 
 
 
 
301
  }
302
- const errResult = { success: false, error: "IDE_HANDSHAKE_TIMEOUT" };
303
- provisioningBus.emit(`error:${config.id}`, errResult);
304
- return errResult;
305
  }
306
 
307
  /**
 
182
  provisioningBus.emit(`log:${config.id}`, msg);
183
  };
184
 
185
+ try {
186
+ log(`Provisioning hermetic environment for '${config.projectName}'...`);
187
+
188
+ // 0. HF PERSISTENCE: Restore profile from Dataset if available
189
+ try {
190
+ await HFStorage.syncFromDataset((msg) => log(msg));
191
+ } catch (e) {
192
+ log(`[WARN] Persistent profile restoration failed: ${e instanceof Error ? e.message : String(e)}. Proceeding with clean environment.`);
193
+ }
194
+ HFStorage.startAutoSave(300000); // 5m auto-save
195
 
196
  // 1. Prepare Workspace Directory
197
  const workspaceRoot = process.env.WORKSPACE_ROOT || path.join(/*turbopackIgnore: true*/ '/home/node/w');
 
220
  fs.writeFileSync(flagPath, new Date().toISOString());
221
  }
222
 
223
+ // 4. Identify Target Port
224
+ const port = findAvailablePort();
225
 
226
+ // 5. Spawn code-server
227
+ const shellCommand = process.platform === 'win32' ? 'npx' : 'code-server';
228
+ const args = process.platform === 'win32' ? ['code-server'] : [];
229
+
230
+ const baseArgs = [
231
+ '--auth', 'none',
232
+ '--bind-addr', `127.0.0.1:${port}`,
233
+ '--user-data-dir', userDataPath,
234
+ '--disable-telemetry',
235
+ '--disable-update-check',
236
+ workspacePath
237
+ ];
238
+
239
+ const spawnEnv: NodeJS.ProcessEnv = { ...process.env, HOME: workspacePath };
240
+ delete spawnEnv.PORT;
241
+ delete spawnEnv.SERVER_PORT;
242
+
243
+ const child = spawn(shellCommand, [...args, ...baseArgs], {
244
+ env: spawnEnv,
245
+ cwd: workspacePath,
246
+ shell: process.platform === 'win32'
247
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
+ log(`Spawning VS Code Orchestrator (PID: ${child.pid})...`);
250
+
251
+ child.on('error', (err) => log(`[FATAL] IDE binary failure: ${err.message}`));
252
+ child.stdout.on('data', (data) => {
253
+ const out = data.toString().trim();
254
+ if (out.includes('listening on')) log(`[IDX:UP] ${out}`);
255
+ else if (out.length > 0) log(`[IDE:CORE] ${out}`);
256
+ });
257
 
258
+ child.stderr.on('data', (data) => {
259
+ const err = data.toString().trim();
260
+ if (err.length > 0) log(`[IDE:ERR] ${err}`);
261
+ });
262
+
263
+ child.on('close', (code, signal) => {
264
+ log(`[IDE:EXIT] IDE process died with code ${code} (Signal: ${signal})`);
265
+ });
266
+
267
+ // 6. Register in active pool
268
+ nativeProcesses.set(config.id, { pid: child.pid!, port, process: child });
269
+
270
+ // 7. Handshake Loop
271
+ let attempts = 0;
272
+ while (attempts < 60) {
273
+ try {
274
+ const res = await fetch(`http://127.0.0.1:${port}`);
275
+ if (res.ok) {
276
+ log(`Handshake verified. Studio Engine Online.`);
277
+
278
+ if (idxConfig.onStart) {
279
+ log(`Executing background onStart lifecycle hooks...`);
280
+ IdxEngine.runHook(workspacePath, 'onStart', idxConfig.onStart, (msg) => log(msg), true);
281
+ }
282
+
283
+ const finalResult: WorkspaceOperationResult = {
284
+ success: true,
285
+ containerId: `native-${config.id}`,
286
+ androidPort: config.withAndroidEmulator ? 6080 : undefined,
287
+ port: port
288
+ };
289
+ provisioningBus.emit(`ready:${config.id}`, finalResult);
290
+ return finalResult;
291
+ }
292
+ } catch {
293
+ if (attempts % 5 === 0) log(`[INFO] Scanning for IDE heartbeat... (Attempt ${attempts}/60)`);
294
+ if (attempts === 15) log(`[INFO] Nix evaluation in progress. Cold boot detected.`);
295
+ if (attempts === 45) log(`[WARN] Handshake threshold approaching. IDE core high load.`);
296
+ await delay(1000);
297
+ attempts++;
298
  }
 
 
 
 
 
 
299
  }
 
300
 
301
+ log(`[FATAL] Handshake timeout on 127.0.0.1:${port}.`);
302
+ const entry = nativeProcesses.get(config.id);
303
+ if (entry) {
304
+ entry.process.kill();
305
+ nativeProcesses.delete(config.id);
306
+ }
307
+ const errResult = { success: false, error: "IDE_HANDSHAKE_TIMEOUT" };
308
+ provisioningBus.emit(`error:${config.id}`, errResult);
309
+ return errResult;
310
+ } catch (e) {
311
+ const error = e instanceof Error ? e.message : String(e);
312
+ log(`[FATAL] Provisioning pipeline collapsed: ${error}`);
313
+ const errResult = { success: false, error: "PROVISIONING_FAILED" };
314
+ provisioningBus.emit(`error:${config.id}`, errResult);
315
+ return errResult;
316
  }
 
 
 
317
  }
318
 
319
  /**
server.ts CHANGED
@@ -163,6 +163,7 @@ app.prepare()
163
  const id = workspaceHostMatch ? workspaceHostMatch[1] : (pathname?.startsWith("/workspace/") ? pathname.split("/")[2] : null);
164
 
165
  if (id) {
 
166
  const isReady = isNativeWorkspaceRunning(id);
167
  if (isReady) {
168
  const port = getNativeWorkspacePort(id) || 8080;
@@ -189,7 +190,7 @@ app.prepare()
189
  <style>
190
  body { background: #09090b; color: #71717a; font-family: sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; overflow: hidden; }
191
  .container { text-align: center; border: 1px solid #27272a; padding: 2rem; rounded: 1rem; background: #111113; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
192
- .spinner { width: 40px; height: 40px; border: 3px solid #3f3f46; border-top-color: #3b82f6; border-radius: 50%; animate: spin 1s linear infinite; margin: 0 auto 1.5rem; }
193
  h1 { color: #f4f4f5; font-size: 1.25rem; margin: 0 0 0.5rem; }
194
  p { font-size: 0.875rem; }
195
  .id-info { font-family: monospace; color: #3b82f6; margin-top: 1rem; font-size: 0.75rem; opacity: 0.5; }
 
163
  const id = workspaceHostMatch ? workspaceHostMatch[1] : (pathname?.startsWith("/workspace/") ? pathname.split("/")[2] : null);
164
 
165
  if (id) {
166
+ console.log("nativeProcessesId", id);
167
  const isReady = isNativeWorkspaceRunning(id);
168
  if (isReady) {
169
  const port = getNativeWorkspacePort(id) || 8080;
 
190
  <style>
191
  body { background: #09090b; color: #71717a; font-family: sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; overflow: hidden; }
192
  .container { text-align: center; border: 1px solid #27272a; padding: 2rem; rounded: 1rem; background: #111113; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
193
+ .spinner { width: 40px; height: 40px; border: 3px solid #3f3f46; border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 1.5rem; }
194
  h1 { color: #f4f4f5; font-size: 1.25rem; margin: 0 0 0.5rem; }
195
  p { font-size: 0.875rem; }
196
  .id-info { font-family: monospace; color: #3b82f6; margin-top: 1rem; font-size: 0.75rem; opacity: 0.5; }