Spaces:
Configuration error
Configuration error
Commit Β·
921b162
1
Parent(s): eb69de5
commit initial 09-12-2025 018
Browse files31 unmodified lines323334353637383940414243444519 unmodified lines65666768697071104 unmodified lines1761771781791801811826 unmodified lines189190191192193194195196197198199200201202203204205206207208118 unmodified lines32732832933033133233333433533633733833934034134234334434529 unmodified lines3753763773783793803813823833843858 unmodified lines39439539639739839940040140240340440540640740840941041131 unmodified linesconst RUNNABLE_LANGS = ["python", "javascript", "java"];// =================== APP ===================function App() {const [tree, setTree] = useState(loadTree());const [activePath, setActivePath] = useState("main.py"); // selected file or folder pathconst [output, setOutput] = useState("");const [prompt, setPrompt] = useState("");const [explanation, setExplanation] = useState("");const [stdin, setStdin] = useState("");const [problems, setProblems] = useState([]);const [theme, setTheme] = useState("vs-dark");const [searchOpen, setSearchOpen] = useState(false);19 unmodified linesLANGUAGE_OPTIONS.find((l) => currentNode?.name?.endsWith(l.ext)) ||LANGUAGE_OPTIONS[0];// ---------- Tree utilities ----------const collectFolderPaths = (node, acc = []) => {if (!node) return acc;if (node.type === "folder") acc.push(node.path || "");104 unmodified linese.target.value = "";};// ---------- Run & Agent (with progress flags) ----------const handleRun = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {6 unmodified linesreturn;}setIsRunning(true);setOutput(""); // clear previoussetProblems([]);try {const res = await runCode(node.content, selectedLang, stdin);setOutput(res.output || "");setProblems(res.error ? parseProblems(res.output) : []);} catch (err) {setOutput(String(err));} finally {setIsRunning(false);}};const handleAskFix = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {118 unmodified lines<div className="ide-menubar-right"><button onClick={handleSearchToggle} disabled={anyLoading}>π Search</button><button onClick={handleRun} disabled={isRunning || anyLoading}>{isRunning ? "β³ Running..." : "βΆ Run"}</button><button onClick={handleAskFix} disabled={isFixing || anyLoading}>{isFixing ? "β³ Fixing..." : "π€ Fix"}</button><button onClick={handleExplainSelection} disabled={isExplaining || anyLoading}>{isExplaining ? "β³ Explaining..." : "π Explain"}</button><button onClick={() => setTheme((t) => (t === "vs-dark" ? "light" : "vs-dark"))} disabled={anyLoading}>{theme === "vs-dark" ? "βοΈ" : "π"}</button>29 unmodified linesonChange={updateActiveFileContent}onMount={(editor) => (editorRef.current = editor)}onBlur={() => fetchAiSuggestions(currentNode?.content)}options={{minimap: { enabled: true },fontSize: 14,scrollBeyondLastLine: false,}}/></div>8 unmodified lines{/* Bottom panels */}<div className="ide-panels"><pre className="ide-output">{output}</pre><input className="ide-input-box" placeholder="Program input..." value={stdin} onChange={(e) => setStdin(e.target.value)} />{problems.length > 0 && (<div className="ide-problems-panel"><div>π¨ Problems ({problems.length})</div>{problems.map((p, i) => (<div key={i}>{p.path}:{p.line} β {p.message}</div>))}</div>)}</div>31 unmodified lines323334353637383940414243444546474849505152535455565758596061626364656667686919 unmodified lines89909192939495104 unmodified lines2002012022032042052062072082092102112122132142152162172182192202212226 unmodified lines229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311118 unmodified lines43043143243343443543643743829 unmodified lines4684694704714724734748 unmodified lines48348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252331 unmodified linesconst RUNNABLE_LANGS = ["python", "javascript", "java"];// Utility: detect whether output likely requests inputfunction outputLooksForInput(output) {if (!output) return false;const o = output.toString();// common prompt words / patterns and trailing prompt charconst patterns = [/enter.*:/i,/input.*:/i,/please enter/i,/scanner/i, // java Scanner exceptions or prompts/press enter/i,/: $/, // ends with colon + space (e.g. "Enter number: ")/:\n$/, // ends with colon + newline/> $/, // trailing >];return patterns.some((p) => p.test(o));}// =================== APP ===================function App() {const [tree, setTree] = useState(loadTree());const [activePath, setActivePath] = useState("main.py"); // selected file or folder path// Terminal-ish stateconst [terminalLines, setTerminalLines] = useState([]); // array of strings shown in terminalconst [terminalInput, setTerminalInput] = useState(""); // current typed input in terminal promptconst [accumStdin, setAccumStdin] = useState(""); // accumulated stdin passed to backendconst [awaitingInput, setAwaitingInput] = useState(false); // true if program waiting for inputconst [output, setOutput] = useState(""); // last raw output (kept for compatibility)const [prompt, setPrompt] = useState("");const [explanation, setExplanation] = useState("");// other statesconst [stdin, setStdin] = useState(""); // legacy single-run input (kept for compatibility)const [problems, setProblems] = useState([]);const [theme, setTheme] = useState("vs-dark");const [searchOpen, setSearchOpen] = useState(false);19 unmodified linesLANGUAGE_OPTIONS.find((l) => currentNode?.name?.endsWith(l.ext)) ||LANGUAGE_OPTIONS[0];// ---------- TREE helpers ----------const collectFolderPaths = (node, acc = []) => {if (!node) return acc;if (node.type === "folder") acc.push(node.path || "");104 unmodified linese.target.value = "";};// ---------- Terminal/Run logic (interactive) ----------// We will accumulate stdin in `accumStdin`. On initial run we clear it.// When backend returns output containing cues that input is requested, set awaitingInput=true.// When user types into terminal prompt and presses Enter, append that input to accumStdin + "\n",// then re-run the program with updated accumStdin. Repeat until no input cues.const resetTerminal = () => {setTerminalLines([]);setTerminalInput("");setAccumStdin("");setAwaitingInput(false);};const appendTerminal = (text) => {setTerminalLines((prev) => [...prev, text]);};const handleRun = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {6 unmodified linesreturn;}// clear terminal state and start a fresh runresetTerminal();setIsRunning(true);setProblems([]);setOutput("");try {// call backend with current accumStdin (empty on first run)const res = await runCode(node.content, selectedLang, accumStdin || stdin || "");const out = res.output ?? "";setOutput(out);appendTerminal(out);setProblems(res.error ? parseProblems(res.output) : []);if (outputLooksForInput(out)) {// program likely wants input: show promptsetAwaitingInput(true);} else {setAwaitingInput(false);}} catch (err) {const e = String(err);setOutput(e);appendTerminal(e);setAwaitingInput(false);} finally {setIsRunning(false);}};// Called when user types input into terminal and presses Enterconst sendTerminalInput = async () => {if (!awaitingInput) return;const userText = terminalInput;// echo user input in terminalappendTerminal(`> ${userText}`);const newAccum = (accumStdin || "") + userText + "\n";setAccumStdin(newAccum);setTerminalInput("");setIsRunning(true);try {// re-run program with updated stdinconst node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {appendTerminal("No file selected.");setAwaitingInput(false);return;}const selectedLang = LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id;const res = await runCode(node.content, selectedLang, newAccum);const out = res.output ?? "";setOutput(out);appendTerminal(out);setProblems(res.error ? parseProblems(res.output) : []);// detect if program still waitingif (outputLooksForInput(out)) {setAwaitingInput(true);} else {setAwaitingInput(false);}} catch (err) {appendTerminal(String(err));setAwaitingInput(false);} finally {setIsRunning(false);}};// Allow pressing Enter to send inputconst onTerminalKeyDown = (e) => {if (e.key === "Enter") {e.preventDefault();if (!awaitingInput) return;sendTerminalInput();}};// ---------- Agent functions ----------const handleAskFix = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {118 unmodified lines<div className="ide-menubar-right"><button onClick={handleSearchToggle} disabled={anyLoading}>π Search</button><button onClick={handleRun} disabled={isRunning || anyLoading}>{isRunning ? "β³ Running..." : "βΆ Run"}</button><button onClick={handleAskFix} disabled={isFixing || anyLoading}>{isFixing ? "β³ Fixing..." : "π€ Fix"}</button><button onClick={handleExplainSelection} disabled={isExplaining || anyLoading}>{isExplaining ? "β³ Explaining..." : "π Explain"}</button><button onClick={() => setTheme((t) => (t === "vs-dark" ? "light" : "vs-dark"))} disabled={anyLoading}>{theme === "vs-dark" ? "βοΈ" : "π"}</button>29 unmodified linesonChange={updateActiveFileContent}onMount={(editor) => (editorRef.current = editor)}onBlur={() => fetchAiSuggestions(currentNode?.content)}options={{ minimap: { enabled: true }, fontSize: 14, scrollBeyondLastLine: false }}/></div>8 unmodified lines{/* Bottom panels */}<div className="ide-panels">{/* Terminal output */}<div className="ide-output-terminal" style={{ marginBottom: 8 }}><div style={{ fontSize: 12, color: "#ccc", marginBottom: 6 }}>Terminal</div><div className="terminal-content" style={{ background: "#000", color: "#0f0", padding: 8, borderRadius: 6, maxHeight: 220, overflowY: "auto", whiteSpace: "pre-wrap", fontFamily: "Consolas, monospace" }}>{terminalLines.length === 0 ? <div style={{ color: "#999" }}>[Program output will appear here]</div> : terminalLines.map((ln, i) => <div key={i}>{ln}</div>)}{awaitingInput && <div style={{ color: "#fff" }}> </div>}</div>{/* Terminal input (shown only when program asks input) */}{awaitingInput ? (<div style={{ display: "flex", gap: 6, marginTop: 6 }}><inputclassName="ide-input-box"placeholder="Type input and press Enter..."value={terminalInput}onChange={(e) => setTerminalInput(e.target.value)}onKeyDown={onTerminalKeyDown}disabled={!awaitingInput || isRunning}/><button onClick={sendTerminalInput} disabled={!awaitingInput || isRunning} className="ide-button">Send</button></div>) : (// If not awaiting input, show legacy single-run input + hint to run for interactive programs<div style={{ display: "flex", gap: 6, marginTop: 6 }}><input className="ide-input-box" placeholder="(Optional) Program input for single-run" value={stdin} onChange={(e) => setStdin(e.target.value)} /><div style={{ alignSelf: "center", color: "#999", fontSize: 12 }}>Press Run β to execute</div></div>)}</div>{/* Problems */}{problems.length > 0 && (<div className="ide-problems-panel"><div>π¨ Problems ({problems.length})</div>{problems.map((p, i) => <div key={i}>{p.path}:{p.line} β {p.message}</div>)}</div>)}</div>
src/App.js+145-33