Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/usr/bin/env node
2// wait-for-bios.mjs - Wait for bios to load and then interact
3
4import { withCDP } from './cdp.mjs';
5
6await withCDP(async (cdp) => {
7 console.log('⏳ Waiting for bios to load...\n');
8
9 // Wait for bios
10 const startTime = Date.now();
11 let attempts = 0;
12 const maxAttempts = 50; // 10 seconds max
13
14 while (attempts < maxAttempts) {
15 const hasBios = await cdp.eval('typeof window.bios !== "undefined"');
16
17 if (hasBios) {
18 const elapsed = Date.now() - startTime;
19 console.log(`✅ Bios loaded after ${elapsed}ms (${attempts} attempts)\n`);
20 break;
21 }
22
23 attempts++;
24 await new Promise(r => setTimeout(r, 200));
25
26 if (attempts % 5 === 0) {
27 process.stdout.write('.');
28 }
29 }
30
31 if (attempts >= maxAttempts) {
32 console.log('\n❌ Timeout waiting for bios');
33 process.exit(1);
34 }
35
36 // Now check what we have access to
37 const biosInfo = await cdp.eval(`
38 ({
39 hasBios: typeof window.bios !== 'undefined',
40 hasStore: typeof window.store !== 'undefined',
41 hasNoPaint: typeof window.nopaint !== 'undefined',
42 currentPiece: window.location.pathname,
43 canvasCount: document.querySelectorAll('canvas').length,
44 bootComplete: window.bootComplete || false
45 })
46 `);
47
48 console.log('🎨 Bios State:');
49 Object.entries(biosInfo).forEach(([key, value]) => {
50 console.log(` ${key}: ${value}`);
51 });
52
53 // Try to get prompt-specific info
54 console.log('\n📝 Prompt Info:');
55 const promptInfo = await cdp.eval(`
56 ({
57 typeBuffer: window.store?.prompt?.typeBuffer || 'N/A',
58 cursorPosition: window.store?.prompt?.cursor || 'N/A',
59 hasTypeBuffer: typeof window.store?.prompt?.typeBuffer !== 'undefined'
60 })
61 `);
62
63 Object.entries(promptInfo).forEach(([key, value]) => {
64 console.log(` ${key}: ${value}`);
65 });
66
67 // Try to send a command by manipulating the store
68 if (promptInfo.hasTypeBuffer) {
69 console.log('\n💬 Sending text to prompt...');
70 await cdp.eval(`
71 if (window.store && window.store.prompt) {
72 window.store.prompt.typeBuffer = 'hello from cdp! 👋';
73 window.store.prompt.cursor = window.store.prompt.typeBuffer.length;
74 }
75 `);
76
77 const newBuffer = await cdp.eval('window.store?.prompt?.typeBuffer || "failed"');
78 console.log(`✅ Type buffer set to: "${newBuffer}"`);
79 } else {
80 console.log('\n⚠️ Type buffer not accessible yet');
81 }
82
83}, {
84 targetUrl: 'https://localhost:8888/prompt',
85 verbose: true
86});