diff --git a/coderunner/server/web/app/app.css b/coderunner/server/web/app/app.css index f9cc0c7..1840761 100644 --- a/coderunner/server/web/app/app.css +++ b/coderunner/server/web/app/app.css @@ -454,15 +454,16 @@ a.att-file:hover { border-color: var(--accent); } /* In the side panel the VNC screen hugs the top cleanly at its native aspect ratio (default 16:10), and the Workspace Companion Deck fills the space directly below it with live activity, pages, and files. Expanded, the screen takes the full window centered and the deck hides. */ -#shell:not(.expanded) #screenWrap:not(.terminal):not(.browsing):not(.mac-on) { background: var(--panel-bg); } -#shell:not(.expanded) #screenWrap:not(.terminal):not(.browsing):not(.mac-on) .screen-stage { +#shell:not(.expanded) #screenWrap:not(.terminal):not(.browsing):not(.mac-on):not(.code-on) { background: var(--panel-bg); } +#shell:not(.expanded) #screenWrap:not(.terminal):not(.browsing):not(.mac-on):not(.code-on) .screen-stage { flex: none; aspect-ratio: var(--vnc-ratio, 16 / 10); max-height: 54%; border-bottom: 1px solid var(--line); } #shell:not(.expanded) #screen canvas { margin-top: 0 !important; margin-bottom: auto !important; } #shell.expanded .screen-deck, #screenWrap.terminal .screen-stage, #screenWrap.terminal .screen-deck, #screenWrap.browsing .screen-stage, #screenWrap.browsing .screen-deck, -#screenWrap.mac-on .screen-stage, #screenWrap.mac-on .screen-deck { display: none; } +#screenWrap.mac-on .screen-stage, #screenWrap.mac-on .screen-deck, +#screenWrap.code-on .screen-stage, #screenWrap.code-on .screen-deck { display: none; } .screen-note { position: absolute; inset: 0; display: grid; place-items: center; color: #bdbab1; font-size: 13px; padding: 20px; text-align: center; pointer-events: none; z-index: 3; } .screen-note:empty { display: none; } @@ -604,6 +605,28 @@ a.att-file:hover { border-color: var(--accent); } #screenWrap.mac-on { background: var(--rail); } #screenWrap.mac-on #screen, #screenWrap.mac-on .screen-note { display: none; } /* The terminal fills the same box; unlike the screen (a desktop, always dark) it follows light and dark. */ +/* ---- Code: the files the assistant writes on its computer, read-only, the latest change marked ---- */ +#screenWrap.code-on { background: var(--surface); } +.code-pane { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--surface); } +.code-pane[hidden] { display: none; } +.code-files { display: flex; gap: 2px; overflow-x: auto; padding: 6px 8px 0; border-bottom: 1px solid var(--line); flex: none; scrollbar-width: none; } +.code-tab { flex: none; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 6px 10px; border: 0; + border-radius: 7px 7px 0 0; background: none; color: var(--muted); font: 12.5px var(--display); cursor: pointer; } +.code-tab:hover { background: var(--surface-hover); color: var(--text); } +.code-tab.on { background: var(--surface-2); color: var(--text); font-weight: 560; } +.code-tab.made { font-style: italic; } +.code-tab.fresh::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; + background: var(--accent); vertical-align: middle; } +.code-path { flex: none; padding: 7px 12px; font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); + border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.code-path:empty { display: none; } +.code-view { flex: 1; min-height: 0; overflow: auto; padding: 6px 0 24px; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; } +.code-line { display: flex; white-space: pre; min-width: max-content; } +.code-line .n { flex: none; width: 4.5em; padding-right: 1.2em; text-align: right; color: var(--faint); user-select: none; } +.code-line .t { padding-right: 16px; color: var(--text); } +.code-line.changed { background: var(--accent-soft); } +.code-line.changed .n { color: var(--accent); } +.code-note { padding: 18px 14px; color: var(--muted); font: 13px var(--display); } #term { position: absolute; inset: 0; background: var(--surface); } #term[hidden] { display: none; } #term .xterm { height: 100%; padding: 8px 4px 4px 10px; } diff --git a/coderunner/server/web/app/app.js b/coderunner/server/web/app/app.js index fafc448..74feefe 100644 --- a/coderunner/server/web/app/app.js +++ b/coderunner/server/web/app/app.js @@ -127,6 +127,7 @@ function codeSummaryLine(code) { function toolSurface(name) { if (name === "run_python" || name === "run_shell" || name === "shell_job") return "terminal"; + if (name === "write_file" || name === "edit_file") return "code"; if (String(name || "").startsWith("browser_") || name === "web_read") return "screen"; if (name === "files_search" || String(name || "").startsWith("file_")) return "files"; if (String(name || "").startsWith("memory_") || name === "profile_update") return "memory"; @@ -136,6 +137,7 @@ function toolSurface(name) { function toolBadge(name) { if (name === "run_python") return {label: "Python", cls: "terminal"}; if (name === "run_shell" || name === "shell_job") return {label: "Terminal", cls: "terminal"}; + if (name === "write_file" || name === "edit_file") return {label: "Code", cls: "terminal"}; if (name === "web_read") return {label: "Reader", cls: ""}; if (String(name || "").startsWith("browser_")) return {label: "Browser", cls: ""}; if (name === "files_search" || String(name || "").startsWith("file_")) return {label: "Files", cls: ""}; @@ -148,6 +150,8 @@ function describeTool(name, raw) { const said = typeof a.say === "string" && a.say.trim() ? trunc(a.say.trim(), 72) : ""; switch (name) { case "browser_open": case "browser_navigate": return `Opening ${host(a.url)}`; + case "write_file": return `Writing ${trunc(String(a.path || "a file").split("/").pop(), 60)}`; + case "edit_file": return `Editing ${trunc(String(a.path || "a file").split("/").pop(), 60)}`; case "browser_search": return `Searching the web for “${String(a.query || "").slice(0, 60)}”`; case "browser_snapshot": return said || "Reading the page"; case "browser_list": return said || "Reading the results on the page"; @@ -423,6 +427,7 @@ class TaskView { this.items = this.say(itemCards(this.shown, picture)); break; case "plan": this.showPlan(e.steps); break; + case "file": case "files_changed": codeSaw(e, state.running.has(this.id), this.id); break; case "routine": this.say(routineLine(e)); break; case "tool": { if (e.name === "plan_update" || e.name === "tell_owner" || e.name === "show_items") break; @@ -430,6 +435,7 @@ class TaskView { const label = describeTool(e.name, e.arguments); const surf = toolSurface(e.name); if (this.status === "running") state.activeSurface = surf || "thinking"; + if (this.status === "running" && state.running.has(this.id)) followTo(e.name, this.id); this.setNow(label); const a = args(e.arguments); if (a.url && (e.name === "browser_open" || e.name === "browser_navigate")) this.recordPage(a.url, "", "ok", false, true); @@ -1039,6 +1045,7 @@ async function openConversation(id, title, again) { // The task being read comes to the front on the assistant's computer and goes first at the model. const focusPromise = api("/api/focus", {method: "POST", body: JSON.stringify({conversation: id || ""})}).catch(() => null); state.views.clear(); + codeReset(id); refreshThreadFiles(); $("thread").replaceChildren(); $("title").textContent = id ? trunc(title || "Task", 90) : "New task"; @@ -1953,6 +1960,103 @@ function showSidebar(on, remember = true) { placeBrowser(); } +// ---- following the task: the panel shows where it works ------------------------------ +// While a task of the open thread works, the panel turns to where it is: its terminal for a command, its screen +// for the browser, its code for a file it writes. A tab the owner picks holds for the rest of that task. +const follow = {paused: ""}; + +function ownerPicked() { + const mine = [...state.running.entries()].find(([, run]) => run.conversation === state.conversation); + if (mine) follow.paused = mine[0]; +} + +function followTo(tool, task) { + if (follow.paused === task || control || $("shell").classList.contains("no-computer")) return; + const surface = toolSurface(tool); + const macActive = shellBrowser && (browserState.tabs || []).some((t) => t.assistant); + const next = surface === "terminal" ? "terminal" + : surface === "code" ? "code" + : String(tool).startsWith("browser_") ? (macActive ? "browser" : "screen") + : ""; + if (next && next !== view) setView(next, false); +} + +// ---- Code: the files the task writes on its computer ------------------------------ +// Each write_file and edit_file arrives with the file as it now is; files a command made are named, and read from +// the sandbox when opened. Shown as text, read-only: nothing here runs or renders what the assistant wrote. +const code = {conversation: "", files: new Map(), open: "", picked: false}; + +function codeReset(conversation) { + if (code.conversation === conversation) return; + Object.assign(code, {conversation, files: new Map(), open: "", picked: false}); + $("viewCode").hidden = true; + if (view === "code") setView("screen", false); +} + +function codeSaw(e, live, task) { + if (e.conversation && e.conversation !== code.conversation) codeReset(e.conversation); + const paths = e.type === "file" ? [e.path] : (e.paths || []); + for (const path of paths) { + const known = code.files.get(path) || {}; + code.files.delete(path); // the latest goes last, as the newest tab + code.files.set(path, e.type === "file" + ? {body: e.body || "", lines: e.lines || 0, cut: !!e.cut, line: e.line || 0, until: e.until || 0, op: e.op, made: false, fresh: live} + : {...known, body: null, made: !known.op, op: known.op, fresh: live, line: 0, until: 0}); + } + while (code.files.size > 30) code.files.delete(code.files.keys().next().value); + $("viewCode").hidden = false; + if (e.type === "file" && (!code.picked || !live)) code.open = e.path; + else if (!code.open && paths.length) code.open = paths[0]; + if (view === "code") drawCode(); + else if (e.type === "file" && live) followTo("write_file", task); // its tool event came first, with nothing to show yet +} + +async function drawCode() { + const strip = $("codeFiles"); + strip.replaceChildren(...[...code.files.entries()].reverse().map(([path, file]) => { + const tab = el("button", "code-tab" + (path === code.open ? " on" : "") + (file.made ? " made" : "") + (file.fresh && path !== code.open ? " fresh" : "")); + tab.type = "button"; + tab.setAttribute("role", "tab"); + tab.textContent = path.split("/").pop(); + tab.title = file.made ? `${path} (made by a command)` : path; + tab.onclick = () => { code.open = path; code.picked = true; drawCode(); }; + return tab; + })); + const file = code.files.get(code.open); + $("codePath").textContent = code.open || ""; + const box = $("codeView"); + if (!file) { box.replaceChildren(); return; } + file.fresh = false; + if (file.body === null) { + box.replaceChildren(el("div", "code-note", "Reading…")); + const wanted = code.open; + try { + const got = await api(`/api/sandbox/file?path=${encodeURIComponent(wanted)}`); + if (code.files.get(wanted) !== file) return; // a newer write of the file came while it was read + Object.assign(file, {body: got.body, lines: got.lines, cut: got.cut}); + } catch (err) { + if (code.open === wanted && code.files.get(wanted) === file) box.replaceChildren(el("div", "code-note", err.message)); + return; + } + if (code.open !== wanted) return; + } + const rows = file.body.split("\n"); + if (rows.length > 1 && rows[rows.length - 1] === "") rows.pop(); + const from = file.line || 0, to = file.until || from; + const frag = document.createDocumentFragment(); + rows.forEach((text, i) => { + const row = el("div", "code-line" + (from && i + 1 >= from && i + 1 <= to ? " changed" : "")); + row.append(el("span", "n", String(i + 1)), el("span", "t", text || " ")); + frag.appendChild(row); + }); + if (file.cut) frag.appendChild(el("div", "code-note", `Only the start is shown: the file has ${file.lines} lines.`)); + box.replaceChildren(frag); + const mark = box.querySelector(".code-line.changed"); + if (mark) box.scrollTop = Math.max(0, mark.offsetTop - box.clientHeight / 3); + else box.scrollTop = 0; + strip.querySelector(".code-tab.on")?.scrollIntoView({block: "nearest", inline: "nearest"}); +} + // ---- the computer's terminal: a tab beside the screen ------------------------------ // A shell on the assistant's computer (the VM's own PTY, kept running between visits), with the assistant's commands // shown in it, dim, as they run. xterm.js is loaded and the socket opened only when the tab is first opened; the @@ -1968,17 +2072,21 @@ function setView(next, remember = true) { view = next === "terminal" ? "terminal" : next === "browser" && shellBrowser ? "browser" : next === "mac" ? "mac" + : next === "code" && code.files.size ? "code" : "screen"; const terminal = view === "terminal", browsing = view === "browser", mac = view === "mac", screen = view === "screen"; + const coding = view === "code"; if (!screen && control) setControl(false); // the screen is handed back: nothing waits on the owner - for (const [id, name] of [["viewScreen", "screen"], ["viewTerminal", "terminal"], ["viewBrowser", "browser"], ["viewMac", "mac"]]) { + for (const [id, name] of [["viewScreen", "screen"], ["viewTerminal", "terminal"], ["viewCode", "code"], ["viewBrowser", "browser"], ["viewMac", "mac"]]) { $(id)?.classList.toggle("on", view === name); $(id)?.setAttribute("aria-selected", String(view === name)); } $("screenWrap").classList.toggle("terminal", terminal); $("screenWrap").classList.toggle("browsing", browsing); $("screenWrap").classList.toggle("mac-on", mac); - $("computer").classList.toggle("terminal-on", terminal || browsing || mac); // light or dark like the app, not the desktop + $("screenWrap").classList.toggle("code-on", coding); + $("computer").classList.toggle("terminal-on", terminal || browsing || mac || coding); // light or dark like the app, not the desktop + $("codePane").hidden = !coding; $("term").hidden = !terminal; if ($("browser")) $("browser").hidden = !browsing; if ($("macPane")) $("macPane").hidden = !mac; @@ -1990,7 +2098,8 @@ function setView(next, remember = true) { if ($("addressPill")) $("addressPill").hidden = browsing; if ($("control")) $("control").hidden = !screen || !Boolean(rfb?.connected); if ($("macState")) $("macState").hidden = !browsing; - if (remember && !mac) { try { localStorage.setItem(VIEW_KEY, view); } catch { /* private window: not remembered */ } } + if (remember && !mac && !coding) { try { localStorage.setItem(VIEW_KEY, view); } catch { /* private window: not remembered */ } } + if (coding) drawCode(); setPanelWidth(); if (terminal) openTerminal(); if (mac) refreshMacPane(); @@ -2139,9 +2248,10 @@ function connectTerminal() { }; } -$("viewScreen").onclick = () => setView("screen"); -$("viewTerminal").onclick = () => setView("terminal"); -$("viewBrowser").onclick = () => setView("browser"); +$("viewScreen").onclick = () => { ownerPicked(); setView("screen"); }; +$("viewTerminal").onclick = () => { ownerPicked(); setView("terminal"); }; +$("viewCode").onclick = () => { ownerPicked(); setView("code", false); }; +$("viewBrowser").onclick = () => { ownerPicked(); setView("browser"); }; try { if (localStorage.getItem(VIEW_KEY) === "terminal") setView("terminal", false); } catch { /* not remembered */ } setPanelWidth(); // the width the owner left it at window.addEventListener("resize", () => { if (savedWidths()[view]) setPanelWidth(); }); @@ -2163,6 +2273,7 @@ function refreshNow() { const surface = !busy ? "" : macActive && state.activeSurface === "screen" ? "browser" : (state.activeSurface || "thinking"); $("viewScreen")?.classList.toggle("working", busy && surface === "screen"); $("viewTerminal")?.classList.toggle("working", busy && surface === "terminal"); + $("viewCode")?.classList.toggle("working", busy && surface === "code"); $("viewBrowser")?.classList.toggle("working", busy && surface === "browser"); const whereLabel = surface === "terminal" ? "In terminal" : surface === "browser" ? `In ${hostBrowser()}` @@ -2576,6 +2687,7 @@ const NAV_ICONS = { globe: "M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18 M3 12h18 M12 3a14 14 0 0 1 0 18 M12 3a14 14 0 0 0 0 18", monitor: "M3 5h18v12H3z M8 21h8 M12 17v4", term: "M5 8l4 4-4 4 M12 16h7", + code: "M8 7l-5 5 5 5 M16 7l5 5-5 5", chip: "M9 3v2M15 3v2M9 19v2M15 19v2M3 9h2M3 15h2M19 9h2M19 15h2 M7 7h10v10H7z", chevRight: "M9 6l6 6l-6 6", }; @@ -3861,7 +3973,8 @@ function toolDetail(name, a, title = "") { case "run_python": sub = codeSummaryLine(a.code); break; case "run_shell": sub = codeSummaryLine(a.command); break; case "files_search": sub = trunc(String(a.query || ""), 60); break; - case "file_read": case "file_view": case "file_listen": sub = trunc(String(a.path || ""), 68); break; + case "file_read": case "file_view": case "file_listen": case "write_file": case "edit_file": + sub = trunc(String(a.path || ""), 68); break; case "browser_task": sub = trunc(String(a.goal || ""), 72); break; default: sub = a.say ? trunc(String(a.say), 72) : ""; break; } diff --git a/coderunner/server/web/app/index.html b/coderunner/server/web/app/index.html index 670360e..3a4628b 100644 --- a/coderunner/server/web/app/index.html +++ b/coderunner/server/web/app/index.html @@ -115,6 +115,10 @@