diff --git a/src/core/KGDebugger.ts b/src/core/KGDebugger.ts index 40027c4..6fc188a 100644 --- a/src/core/KGDebugger.ts +++ b/src/core/KGDebugger.ts @@ -30,6 +30,7 @@ export class KGDebugger { 'testToolCall(jsonInput)', 'inputChatBox(content, interval?)', 'opfs(command)', + 'startShell()', ]); } @@ -346,6 +347,7 @@ export class KGDebugger { console.log(" testToolCall(input) - Execute tool call(s) from JSON and show results"); console.log(" inputChatBox(content, interval?) - Type into ChatBox textarea and submit with Enter"); console.log(" opfs(command) - OPFS file browser (pwd, ls, cd, cat, dl, rm)"); + console.log(" startShell() - Start interactive OPFS shell (prompt-based loop)"); console.log(" help() - Show this help"); console.log(""); console.log("💡 Usage tips:"); @@ -449,6 +451,57 @@ export class KGDebugger { } } + /** + * Start an interactive OPFS shell using browser prompt() dialogs. + * Each prompt shows the current working directory. Type commands and click OK. + * Click Cancel or type 'exit'/'quit' to end the session. + */ + public async startShell(): Promise { + console.log('📟 OPFS Interactive Shell'); + console.log(' Commands: pwd, ls, cd , cat , dl , rm '); + console.log(' Type "exit" or click Cancel to quit.\n'); + + let lastOutput = ''; + + while (true) { + const cwd = '/' + this.opfsCwd.join('/'); + const promptText = lastOutput + ? `${lastOutput}\n\nopfs:${cwd}$ ` + : `opfs:${cwd}$ `; + const input = prompt(promptText); + + if (input === null) break; + + const trimmed = input.trim(); + if (trimmed === '') continue; + if (trimmed === 'exit' || trimmed === 'quit') break; + + // Capture console output during command execution + const captured: string[] = []; + const origLog = console.log; + const origError = console.error; + console.log = (...args: unknown[]) => { + origLog(...args); + captured.push(args.map(String).join(' ')); + }; + console.error = (...args: unknown[]) => { + origError(...args); + captured.push(args.map(String).join(' ')); + }; + + try { + await this.opfs(trimmed); + } finally { + console.log = origLog; + console.error = origError; + } + + lastOutput = captured.join('\n'); + } + + console.log('📟 Shell exited.'); + } + // --- OPFS Shell --- /** Current working directory path segments (relative to OPFS root) */ diff --git a/src/main.tsx b/src/main.tsx index 13b6272..c3caa3c 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -17,8 +17,10 @@ await KGMidiInput.instance().initialize(); // Attach debugger to global window in development mode if (import.meta.env.DEV) { - (window as unknown as { KGDebugger: KGDebugger }).KGDebugger = KGDebugger.instance(); - console.log('🔧 KGDebugger attached to window - try: KGDebugger.help()'); + const dbg = KGDebugger.instance(); + (window as unknown as { KGDebugger: KGDebugger; sh: () => Promise }).KGDebugger = dbg; + (window as unknown as { sh: () => Promise }).sh = () => dbg.startShell(); + console.log('🔧 KGDebugger attached to window - try: KGDebugger.help() or sh()'); } // Start audio context on first user interaction