feat: enhanced emulated bash terminal (by using browser's input box pop-up loop)
This commit is contained in:
@@ -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<void> {
|
||||
console.log('📟 OPFS Interactive Shell');
|
||||
console.log(' Commands: pwd, ls, cd <path>, cat <file>, dl <file>, rm <name>');
|
||||
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) */
|
||||
|
||||
+4
-2
@@ -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<void> }).KGDebugger = dbg;
|
||||
(window as unknown as { sh: () => Promise<void> }).sh = () => dbg.startShell();
|
||||
console.log('🔧 KGDebugger attached to window - try: KGDebugger.help() or sh()');
|
||||
}
|
||||
|
||||
// Start audio context on first user interaction
|
||||
|
||||
Reference in New Issue
Block a user