mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Add the desktop app loop driver with commit, notify, report and tools modules, and update the quit prompt, task dialog and meter
AI Assisted
This commit is contained in:
1 parent
8db8df5791
commit
1f80fa6a7c
24 files changed
+9850
-64
No files matched your search
+273
-5
@@ -2,7 +2,7 @@
|
||||
// agent's terminal panel docked at the bottom with a drag handle.
|
||||
|
||||
import { mountTerminal } from './terminal.js';
|
||||
import { attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor } from './meter.js';
|
||||
import { attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopLocks, loopStopLabels, loopWindowTitle } from './meter.js';
|
||||
|
||||
const { invoke, Channel } = window.__TAURI__.core;
|
||||
|
||||
@@ -20,6 +20,27 @@ const agentBypassEl = document.getElementById('agent-bypass');
|
||||
const agentNoneEl = document.getElementById('agent-none');
|
||||
const agentStatusEl = document.getElementById('agent-status');
|
||||
const restartBtn = document.getElementById('agent-restart');
|
||||
const loopBannerEl = document.getElementById('loop-banner');
|
||||
const loopTitleEl = document.getElementById('loop-title');
|
||||
const loopDetailEl = document.getElementById('loop-detail');
|
||||
const loopPipsEl = document.getElementById('loop-pips');
|
||||
const loopHintEl = document.getElementById('loop-hint');
|
||||
const loopSpecEl = document.getElementById('loop-spec');
|
||||
const loopElapsedEl = document.getElementById('loop-elapsed');
|
||||
const loopRetriesEl = document.getElementById('loop-retries');
|
||||
const loopStopAfterBtn = document.getElementById('loop-stop-after');
|
||||
const loopStopNowBtn = document.getElementById('loop-stop-now');
|
||||
const loopErrorEl = document.getElementById('loop-error');
|
||||
const loopRetryBtn = document.getElementById('loop-retry');
|
||||
// Whether Stop after this phase is on, as the last state said; a press asks for the opposite.
|
||||
let loopStopAfterOn = false;
|
||||
// True while an Implementation Loop runs: New Session stays hidden meanwhile.
|
||||
let loopRunning = false;
|
||||
let loopStep = '';
|
||||
// Whether this loop's one-time typing note was shown; a new loop resets it.
|
||||
let loopTypingNoted = false;
|
||||
const LOOP_TYPING_NOTE = 'A loop is running. Typing here can derail the phase it is working on.';
|
||||
const LOOP_TYPING_NOTE_MS = 8000;
|
||||
const changeAgentBtn = document.getElementById('change-agent');
|
||||
const changeProjectBtn = document.getElementById('change-project');
|
||||
const barRowEl = document.getElementById('bar-row');
|
||||
@@ -82,7 +103,10 @@ const agentActive = () => agent.state === 'running';
|
||||
|
||||
const terminal = await mountTerminal(document.getElementById('term'), {
|
||||
onInput: (data) => {
|
||||
if (agentActive()) invoke('agent_input', { data });
|
||||
if (agentActive()) {
|
||||
noteTypingDuringLoop();
|
||||
invoke('agent_input', { data });
|
||||
}
|
||||
},
|
||||
onResize: (cols, rows) => {
|
||||
if (agentActive()) invoke('agent_resize', { cols, rows });
|
||||
@@ -129,7 +153,7 @@ function applyAgentState(next, { skipReset } = {}) {
|
||||
// ended (New Session keeps the previous agent, model, effort and mode);
|
||||
// Change agent, in that menu, only once ended, when there is a real choice
|
||||
// to make again.
|
||||
restartBtn.hidden = !(active || ended);
|
||||
restartBtn.hidden = loopRunning || !(active || ended);
|
||||
changeAgentBtn.hidden = !ended;
|
||||
// Checked mode needs no marker; bypass always gets the "checks off" badge
|
||||
// on the agent, for exactly as long as that agent runs.
|
||||
@@ -171,6 +195,17 @@ function setAgentStatus(text, { error = false } = {}) {
|
||||
agentStatusEl.classList.toggle('is-error', error && Boolean(text));
|
||||
}
|
||||
|
||||
// The first key typed in the terminal while a loop runs: a note beside the agent,
|
||||
// once per loop, gone after a few seconds. The key itself is always delivered.
|
||||
function noteTypingDuringLoop() {
|
||||
if (!loopRunning || loopTypingNoted) return;
|
||||
loopTypingNoted = true;
|
||||
setAgentStatus(LOOP_TYPING_NOTE);
|
||||
setTimeout(() => {
|
||||
if (agentStatusEl.textContent === LOOP_TYPING_NOTE) setAgentStatus('');
|
||||
}, LOOP_TYPING_NOTE_MS);
|
||||
}
|
||||
|
||||
// The agent menu's first lines: what the agent is doing and, while it runs,
|
||||
// which permission mode it started with.
|
||||
function renderAgentMenuHead(label, { active, ended, bypassActive }) {
|
||||
@@ -638,6 +673,8 @@ function loadFrame(url) {
|
||||
frameReady = false;
|
||||
// The page going away takes its taskbar dot with it; the new one tells its own.
|
||||
clearAttention();
|
||||
// And a game it had in full screen.
|
||||
setGameFull(false);
|
||||
clearTimeout(helloTimer);
|
||||
helloTimer = setTimeout(onNoHello, HELLO_WAIT_MS);
|
||||
frame.src = url;
|
||||
@@ -668,6 +705,9 @@ window.addEventListener('message', (event) => {
|
||||
if (on === null) return;
|
||||
if (appState) appState.taskbarSignal = on;
|
||||
invoke('set_taskbar_signal', { on }).catch(() => {});
|
||||
} else if (kind === 'activities-full') {
|
||||
const on = taskbarSwitch(event.data);
|
||||
if (on !== null) setGameFull(on);
|
||||
} else if (kind === 'agent-continue') {
|
||||
typeContinue();
|
||||
} else if (kind === 'new-session') {
|
||||
@@ -675,9 +715,66 @@ window.addEventListener('message', (event) => {
|
||||
if (!restartBtn.hidden) restartBtn.click();
|
||||
} else if (kind === 'looks') {
|
||||
applyAccent(event.data.accent, { save: true });
|
||||
} else if (kind === 'loop-facts') {
|
||||
// The setup screen asks what agent a loop would use. The answer is facts
|
||||
// only; the page never sends the app any setup value.
|
||||
const source = event.source;
|
||||
invoke('loop_facts')
|
||||
.then((facts) => source.postMessage({ plan2code: 'loop-facts', facts }, '*'))
|
||||
.catch(() => {});
|
||||
} else if (kind === 'loop-resume' || kind === 'loop-fix' || kind === 'loop-finalize') {
|
||||
// Fixed requests, no free text: the page answers with ok or the error.
|
||||
const source = event.source;
|
||||
const command = { 'loop-resume': 'loop_resume', 'loop-fix': 'loop_fix', 'loop-finalize': 'loop_finalize' }[kind];
|
||||
invoke(command)
|
||||
.then(() => source.postMessage({ plan2code: `${kind}-result`, ok: true, error: null }, '*'))
|
||||
.catch((error) => source.postMessage({ plan2code: `${kind}-result`, ok: false, error: String(error) }, '*'));
|
||||
} else if (kind === 'loop-notify-test') {
|
||||
// Send a test: no values at all. The app reads the saved setup itself and
|
||||
// asks the person to confirm in its own dialog.
|
||||
const source = event.source;
|
||||
invoke('loop_notify_test')
|
||||
.then((sent) => source.postMessage({ plan2code: 'loop-notify-test-result', ok: true, sent, error: null }, '*'))
|
||||
.catch((error) =>
|
||||
source.postMessage({ plan2code: 'loop-notify-test-result', ok: false, sent: false, error: String(error) }, '*')
|
||||
);
|
||||
} else if (kind === 'loop-start') {
|
||||
// Start: a spec folder name only. The app validates it, reads the saved
|
||||
// setup itself and asks the person to confirm in its own dialog.
|
||||
const source = event.source;
|
||||
const spec = typeof event.data.spec === 'string' ? event.data.spec : '';
|
||||
invoke('loop_start', { spec })
|
||||
.then((started) => source.postMessage({ plan2code: 'loop-start-result', ok: true, started, error: null }, '*'))
|
||||
.catch((error) =>
|
||||
source.postMessage({ plan2code: 'loop-start-result', ok: false, error: String(error) }, '*')
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// An Activities game in full screen: the console's frame is laid over the
|
||||
// bar and the terminal (over, not instead of, so the terminal keeps its size
|
||||
// and the agent sees no resize), and the window goes full screen. Off, both
|
||||
// go back; the window leaves full screen only if this put it there.
|
||||
let fullByGame = false;
|
||||
|
||||
function setGameFull(on) {
|
||||
document.body.classList.toggle('console-full', on);
|
||||
const win = window.__TAURI__.window.getCurrentWindow();
|
||||
if (on) {
|
||||
win
|
||||
.isFullscreen()
|
||||
.then((already) => {
|
||||
if (already) return;
|
||||
fullByGame = true;
|
||||
return win.setFullscreen(true);
|
||||
})
|
||||
.catch(() => {});
|
||||
} else if (fullByGame) {
|
||||
fullByGame = false;
|
||||
win.setFullscreen(false).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
// Its "Not running... type continue" line, pressed: the keystrokes
|
||||
// continueKeys names, each on its own a moment after the last, so an agent
|
||||
// that treats one burst of input as a paste still reads the Enter as a submit.
|
||||
@@ -727,6 +824,8 @@ async function onNoHello() {
|
||||
if (frameReady || !consoleKnown || restarting) return;
|
||||
// A page that does not answer cannot say it is done needing the person.
|
||||
clearAttention();
|
||||
// The next phase's console is on its way; the poll says so instead.
|
||||
if (loopRunning && loopStep === 'Starting') return;
|
||||
let status = null;
|
||||
try {
|
||||
status = await invoke('console_status');
|
||||
@@ -794,12 +893,19 @@ async function pollConsole() {
|
||||
markConsoleAlive();
|
||||
return;
|
||||
}
|
||||
const action = deadConsoleAction({ loopRunning, loopStep, frameReady, reconnects, limit: RECONNECT_LIMIT });
|
||||
if (action === 'wait-for-phase') {
|
||||
// Covers the old phase's page and its "Lost contact" until the new one
|
||||
// says hello. Never over a question the box is already asking.
|
||||
if (stateCancelEl.hidden) showState(loopDetailEl.textContent);
|
||||
return;
|
||||
}
|
||||
markConsoleDead();
|
||||
if (frameReady && reconnects < RECONNECT_LIMIT) {
|
||||
if (action === 'reconnect') {
|
||||
reconnects += 1;
|
||||
showState('The console stopped. Reconnecting');
|
||||
await reconnectConsole();
|
||||
} else if (!frameReady) {
|
||||
} else if (action === 'no-hello') {
|
||||
onNoHello();
|
||||
}
|
||||
} catch {
|
||||
@@ -856,6 +962,8 @@ async function restartConsole() {
|
||||
// not repeated here.
|
||||
function showAnnounced(notice) {
|
||||
restarting = false;
|
||||
// A new page is a new start: the budget is per run of trouble, not per launch.
|
||||
reconnects = 0;
|
||||
if (!consoleKnown) {
|
||||
consoleKnown = true;
|
||||
if (!pollTimer) pollTimer = setInterval(pollConsole, STATUS_POLL_MS);
|
||||
@@ -869,6 +977,164 @@ function showAnnounced(notice) {
|
||||
|
||||
window.__TAURI__.event.listen('console-page', (event) => showAnnounced(event.payload));
|
||||
|
||||
// "45s", "12m", "1h 12m": whole units, the largest two at most.
|
||||
function formatElapsed(ms) {
|
||||
const total = Math.max(0, Math.floor((Number(ms) || 0) / 1000));
|
||||
if (total < 60) return `${total}s`;
|
||||
const minutes = Math.floor(total / 60);
|
||||
if (minutes < 60) return `${minutes}m`;
|
||||
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
||||
}
|
||||
|
||||
// The Implementation Loop's banner across the window, drawn from the app's
|
||||
// loop-state. It lives here and not in the console page because a loop runs
|
||||
// across many sessions: the page changes under it, and this does not.
|
||||
let loopTimer = null;
|
||||
let loopStartedAt = 0;
|
||||
|
||||
function tickLoopElapsed() {
|
||||
loopElapsedEl.textContent = formatElapsed(Date.now() - loopStartedAt);
|
||||
}
|
||||
|
||||
function setLoopTitle(title) {
|
||||
window.__TAURI__.window.getCurrentWindow().setTitle(title).catch(() => {});
|
||||
}
|
||||
|
||||
// The app ending the loop's last agent ended that agent's console too, so the
|
||||
// page holding the stop or finish card has to be brought back, at once and
|
||||
// whatever the budget says: it is the one thing the person came back to read.
|
||||
async function showLoopEnd() {
|
||||
reconnects = 0;
|
||||
try {
|
||||
const status = await invoke('console_status');
|
||||
if (status.state === 'dead') await reconnectConsole();
|
||||
} catch {
|
||||
// The poll looks again on its next tick.
|
||||
}
|
||||
}
|
||||
|
||||
// Change project and Change agent are off while a loop runs, with the reason on
|
||||
// them; the app refuses them too.
|
||||
function applyLoopLocks(state) {
|
||||
const { locked, reason } = loopLocks(state);
|
||||
for (const button of [changeProjectBtn, changeAgentBtn]) {
|
||||
button.disabled = locked;
|
||||
button.title = locked ? reason : '';
|
||||
}
|
||||
}
|
||||
|
||||
// Asks the app what the loop is doing: a reloaded window has missed every
|
||||
// loop-state event so far, and one sent between the first ask and the listener
|
||||
// is caught by asking again once it listens.
|
||||
async function syncLoopState() {
|
||||
// The reply and the loop-state event travel apart: an event that landed while
|
||||
// the question was out is newer than the answer, which then is dropped.
|
||||
const seen = loopEventSeq;
|
||||
try {
|
||||
const state = await invoke('loop_state');
|
||||
if (seen !== loopEventSeq) return;
|
||||
// No loop and none drawn: nothing to redraw. One drawn that is gone: it ended.
|
||||
if (state) applyLoopState(state);
|
||||
else if (loopRunning) applyLoopState({ running: false });
|
||||
} catch {
|
||||
// The next loop-state event tells it.
|
||||
}
|
||||
}
|
||||
|
||||
function applyLoopState(state) {
|
||||
if (!state || !state.running) {
|
||||
const wasRunning = loopRunning;
|
||||
loopRunning = false;
|
||||
loopStep = '';
|
||||
if (wasRunning) showLoopEnd();
|
||||
clearInterval(loopTimer);
|
||||
loopTimer = null;
|
||||
loopBannerEl.hidden = true;
|
||||
applyLoopLocks({ running: false });
|
||||
setLoopTitle(windowTitleFor(projectPathEl.textContent));
|
||||
// New Session's visibility is applyAgentState's rule alone.
|
||||
applyAgentState(agent, { skipReset: true });
|
||||
return;
|
||||
}
|
||||
if (!loopRunning) loopTypingNoted = false;
|
||||
loopRunning = true;
|
||||
loopStep = state.step || '';
|
||||
restartBtn.hidden = true;
|
||||
applyLoopLocks(state);
|
||||
const banner = loopBanner(state);
|
||||
loopBannerEl.hidden = false;
|
||||
loopBannerEl.dataset.tone = banner.tone;
|
||||
// Only a change of words: this is a live region, and screen readers read it out.
|
||||
if (loopTitleEl.textContent !== banner.title) loopTitleEl.textContent = banner.title;
|
||||
if (loopDetailEl.textContent !== banner.detail) loopDetailEl.textContent = banner.detail;
|
||||
loopHintEl.textContent = banner.hint;
|
||||
loopSpecEl.textContent = state.specName || '';
|
||||
loopPipsEl.replaceChildren(
|
||||
...banner.pips.map((kind, i) => {
|
||||
const pip = document.createElement('span');
|
||||
pip.className = `loop-pip ${kind}`;
|
||||
pip.title = `Phase ${i + 1}`;
|
||||
return pip;
|
||||
})
|
||||
);
|
||||
setLoopTitle(loopWindowTitle(projectPathEl.textContent, state));
|
||||
const stopLabels = loopStopLabels(state);
|
||||
loopStopAfterOn = !!state.stopAfterPhase;
|
||||
loopStopAfterBtn.disabled = stopLabels.afterDisabled;
|
||||
loopStopAfterBtn.textContent = stopLabels.afterText;
|
||||
loopStopNowBtn.disabled = stopLabels.nowDisabled;
|
||||
// A good state means the last press went through.
|
||||
hideLoopError();
|
||||
const retries = Number(state.retriesUsed) || 0;
|
||||
loopRetriesEl.hidden = retries <= 0;
|
||||
loopRetriesEl.textContent = retries === 1 ? '1 retry' : `${retries} retries`;
|
||||
loopStartedAt = Number(state.startedAtMs) || Date.now();
|
||||
tickLoopElapsed();
|
||||
if (!loopTimer) loopTimer = setInterval(tickLoopElapsed, 1000);
|
||||
}
|
||||
|
||||
let loopEventSeq = 0;
|
||||
window.__TAURI__.event
|
||||
.listen('loop-state', (event) => {
|
||||
loopEventSeq += 1;
|
||||
applyLoopState(event.payload);
|
||||
})
|
||||
.then(syncLoopState, () => {});
|
||||
|
||||
// A press that fails shows why next to the buttons, with a Retry for the same press.
|
||||
let loopRetryAction = null;
|
||||
function hideLoopError() {
|
||||
loopErrorEl.hidden = true;
|
||||
loopErrorEl.textContent = '';
|
||||
loopRetryBtn.hidden = true;
|
||||
loopRetryAction = null;
|
||||
}
|
||||
function pressLoop(command, args) {
|
||||
const press = () =>
|
||||
invoke(command, args).then(hideLoopError, (e) => {
|
||||
loopErrorEl.textContent = `Could not do that: ${String(e && e.message ? e.message : e)}`;
|
||||
loopErrorEl.hidden = false;
|
||||
loopRetryBtn.hidden = false;
|
||||
loopRetryAction = press;
|
||||
});
|
||||
return press();
|
||||
}
|
||||
loopRetryBtn.onclick = () => {
|
||||
if (loopRetryAction) loopRetryAction();
|
||||
};
|
||||
loopStopAfterBtn.onclick = () => pressLoop('loop_stop_after_phase', { on: !loopStopAfterOn });
|
||||
loopStopNowBtn.onclick = () =>
|
||||
showState(
|
||||
"End the agent now? This phase's changes stay uncommitted.",
|
||||
'Stop now',
|
||||
() => {
|
||||
frameReady ? hideState() : showState('No dashboard has loaded yet.');
|
||||
pressLoop('loop_stop_now');
|
||||
},
|
||||
() => (frameReady ? hideState() : showState('No dashboard has loaded yet.')),
|
||||
{ tired: true }
|
||||
);
|
||||
|
||||
// The right end of the bar: whether the console stopped answering and where
|
||||
// the skills stand against this app, drawn as one next step (meter.js
|
||||
// barNextSteps decides which, and its button), with the rest as "+N more".
|
||||
@@ -1081,6 +1347,8 @@ async function main() {
|
||||
} catch {
|
||||
// Nothing to reattach to is not fatal: carry on as a plain first paint.
|
||||
}
|
||||
// A reloaded window learns of a running loop before it draws the agent.
|
||||
await syncLoopState();
|
||||
if (reattach && reattach.state !== 'idle') {
|
||||
if (state.projectDir) setProjectDir(state.projectDir);
|
||||
await recoverAfterReload(reattach);
|
||||
|
||||
@@ -50,6 +50,46 @@
|
||||
#agent-none { color: var(--ink-3); }
|
||||
#agent-status { color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 320px; }
|
||||
#agent-status.is-error { color: #f48771; }
|
||||
/* The Implementation Loop, for as long as one runs: the loudest thing in the
|
||||
window on purpose. The accent says it is working; amber says it needs you. */
|
||||
#loop-banner {
|
||||
--banner-color: var(--accent); --banner-bg: var(--accent-soft); --banner-line: var(--accent-line);
|
||||
flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
|
||||
padding: 10px 14px 10px 16px; font-size: 13px; color: var(--ink);
|
||||
background: var(--banner-bg); border-bottom: 1px solid var(--banner-line); box-shadow: inset 4px 0 0 var(--banner-color);
|
||||
}
|
||||
#loop-banner[hidden] { display: none; }
|
||||
#loop-banner[data-tone="waiting"] { --banner-color: #e5a93c; --banner-bg: #3a2b10; --banner-line: #7a5a1e; }
|
||||
#loop-now { flex: 1 1 320px; min-width: 0; display: grid; gap: 3px; }
|
||||
#loop-headline { display: flex; align-items: center; gap: 9px; }
|
||||
#loop-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--banner-color); animation: loop-pulse 1.8s ease-in-out infinite; }
|
||||
#loop-banner[data-tone="waiting"] #loop-dot { animation-duration: 0.9s; }
|
||||
@keyframes loop-pulse { 0%, 100% { box-shadow: 0 0 0 0 transparent; opacity: 1; } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--banner-color) 30%, transparent); opacity: 0.75; } }
|
||||
#loop-title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.25; }
|
||||
#loop-detail { margin: 0; color: var(--ink-2); overflow-wrap: anywhere; }
|
||||
#loop-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; color: var(--ink-3); font-size: 12px; }
|
||||
#loop-pips { display: flex; flex-wrap: wrap; gap: 3px; }
|
||||
.loop-pip { width: 16px; height: 5px; border-radius: 3px; background: var(--rule-2); }
|
||||
.loop-pip.done { background: var(--banner-color); }
|
||||
.loop-pip.current { background: var(--banner-color); animation: loop-pip 1.8s ease-in-out infinite; }
|
||||
@keyframes loop-pip { 50% { opacity: 0.4; } }
|
||||
#loop-spec { color: var(--ink-2); font-weight: 600; }
|
||||
#loop-elapsed { font-variant-numeric: tabular-nums; }
|
||||
#loop-retries { color: #f48771; }
|
||||
#loop-actions { flex: none; display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
#loop-actions button {
|
||||
appearance: none; font: inherit; font-size: 12.5px; font-weight: 600; line-height: 1.2;
|
||||
padding: 6px 12px; border-radius: 8px; cursor: pointer;
|
||||
border: 1px solid var(--banner-line); background: var(--panel); color: var(--ink);
|
||||
}
|
||||
#loop-actions button:hover:not(:disabled) { border-color: var(--banner-color); background: var(--panel-2); }
|
||||
#loop-actions button:disabled { cursor: default; opacity: 0.65; }
|
||||
#loop-actions button:focus-visible { outline: 2px solid var(--banner-color); outline-offset: 2px; }
|
||||
#loop-actions #loop-error { align-self: center; max-width: 320px; color: #f48771; font-size: 12.5px; overflow-wrap: anywhere; }
|
||||
#loop-actions [hidden] { display: none; }
|
||||
#loop-actions #loop-stop-now { color: #f48771; }
|
||||
#loop-actions #loop-stop-now:hover:not(:disabled) { border-color: #f48771; }
|
||||
@media (prefers-reduced-motion: reduce) { #loop-dot, .loop-pip.current { animation: none; } }
|
||||
#bar-grow { flex: 1; min-width: 0; }
|
||||
/* The one next step for the console or the skills, at the right end. */
|
||||
#next-step { display: flex; align-items: center; gap: 8px; flex: none; }
|
||||
@@ -84,6 +124,9 @@
|
||||
#workspace.dock-right { flex-direction: row; }
|
||||
|
||||
#dashboard { flex: 1; min-height: 0; min-width: 0; position: relative; }
|
||||
/* An Activities game in full screen: the console's frame over the whole
|
||||
window, the bar and the terminal left as they are underneath. */
|
||||
body.console-full #console-frame { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 1000; }
|
||||
#console-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #1e1e1e; }
|
||||
#dashboard-state { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: #1e1e1e; text-align: center; padding: 16px; box-sizing: border-box; }
|
||||
#dashboard-state[hidden] { display: none; }
|
||||
@@ -253,6 +296,28 @@
|
||||
<button id="change-agent" role="menuitem" hidden>Change agent...</button>
|
||||
</div>
|
||||
</header>
|
||||
<!-- The Implementation Loop, while one runs (app.js loop-state, meter.js loopBanner). -->
|
||||
<section id="loop-banner" aria-label="Implementation Loop" hidden>
|
||||
<div id="loop-now">
|
||||
<div role="status" aria-live="polite">
|
||||
<div id="loop-headline"><span id="loop-dot" aria-hidden="true"></span><p id="loop-title"></p></div>
|
||||
<p id="loop-detail"></p>
|
||||
</div>
|
||||
<div id="loop-progress">
|
||||
<span id="loop-pips" aria-hidden="true"></span>
|
||||
<span id="loop-spec"></span>
|
||||
<span id="loop-elapsed"></span>
|
||||
<span id="loop-retries" hidden></span>
|
||||
<span id="loop-hint"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loop-actions">
|
||||
<button id="loop-stop-after" type="button">Stop after this phase</button>
|
||||
<button id="loop-stop-now" type="button">Stop now</button>
|
||||
<span id="loop-error" role="alert" hidden></span>
|
||||
<button id="loop-retry" type="button" hidden>Retry</button>
|
||||
</div>
|
||||
</section>
|
||||
<div id="workspace">
|
||||
<main id="dashboard">
|
||||
<iframe id="console-frame" title="Plan2Code console dashboard" allow="clipboard-write"></iframe>
|
||||
|
||||
@@ -128,6 +128,83 @@ export function windowTitleFor(dir) {
|
||||
return name ? `Plan2Code - ${name}` : "Plan2Code";
|
||||
}
|
||||
|
||||
/**
|
||||
* The window title while a loop runs, so its state shows in the taskbar too.
|
||||
*/
|
||||
export function loopWindowTitle(dir, state) {
|
||||
const name = lastSegment(dir);
|
||||
const what = state.step === "Waiting on you" ? `Loop needs you: Phase ${state.phase}` : `Loop: Phase ${state.phase} of ${state.phases}`;
|
||||
return name ? `${what} - ${name}` : what;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the loop banner says, from the app's `loop-state`: the one clear word on
|
||||
* what the loop is doing right now. `tone` is "running" or "waiting", `hint` the
|
||||
* line beside the phase pips and `pips` one "done", "current" or "todo" per phase
|
||||
* of the spec up to the last this run builds.
|
||||
*/
|
||||
export function loopBanner(state) {
|
||||
const { phase, phases, phaseName, step } = state;
|
||||
const named = phaseName ? `Phase ${phase} of ${phases}: ${phaseName}` : `Phase ${phase} of ${phases}`;
|
||||
const pips = Array.from({ length: Math.max(phases, 0) }, (_, i) => (i + 1 < phase ? "done" : i + 1 === phase ? "current" : "todo"));
|
||||
const base = { tone: "running", pips, hint: "Working on its own. You can walk away." };
|
||||
if (state.stopping) {
|
||||
return { ...base, title: "Stopping", detail: "The agent is ending. Nothing more will be committed.", hint: "The stop screen follows in a moment." };
|
||||
}
|
||||
if (step === "Waiting on you") {
|
||||
return { ...base, tone: "waiting", title: "The loop needs your answer", detail: `${named} is waiting on the question below.`, hint: "Nothing is lost while it waits." };
|
||||
}
|
||||
if (state.stopAfterPhase) {
|
||||
return { ...base, title: "Stopping after this phase", detail: `${named} finishes its checks and commit, then the loop stops.`, hint: "Stop now ends the agent at once." };
|
||||
}
|
||||
if (step === "Starting") {
|
||||
if (state.phaseRetried) return { ...base, title: `Retrying Phase ${phase}`, detail: `The agent crashed or went quiet, so a fresh one is picking up ${named}.` };
|
||||
if (state.previousPhase) {
|
||||
const how = state.previousCommitted ? "done and committed" : "done";
|
||||
return { ...base, title: `Phase ${state.previousPhase} ${how}`, detail: `Opening a fresh agent for ${named}.` };
|
||||
}
|
||||
return { ...base, title: "Starting the loop", detail: `Opening a fresh agent for ${named}.` };
|
||||
}
|
||||
return { ...base, title: "Implementation loop running", detail: step ? `${named} \u00b7 ${step}` : named };
|
||||
}
|
||||
|
||||
/**
|
||||
* The two stop buttons from the app's `loop-state`: "Stop after this phase" is
|
||||
* a toggle (its label says what a press does), off on the last phase, and both
|
||||
* buttons are off once Stop now was pressed.
|
||||
*/
|
||||
export function loopStopLabels(state) {
|
||||
const stopping = Boolean(state.stopping);
|
||||
const on = Boolean(state.stopAfterPhase);
|
||||
return {
|
||||
afterText: on ? "Cancel stop after this phase" : "Stop after this phase",
|
||||
afterDisabled: stopping || (!on && state.canStopAfter === false),
|
||||
nowDisabled: stopping,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The bar's Change project and Change agent controls while a loop runs: off,
|
||||
* with one short reason on them. The app refuses both commands too.
|
||||
*/
|
||||
export function loopLocks(state) {
|
||||
const locked = Boolean(state && state.running);
|
||||
return { locked, reason: locked ? "A loop is running. Stop it before you change the project or agent." : "" };
|
||||
}
|
||||
|
||||
/**
|
||||
* What the window does about a console that stopped answering. On Windows the
|
||||
* agent's console dies with the agent (the app ends the agent's whole Job
|
||||
* Object), so between a loop's phases a dead console is expected: the next
|
||||
* phase opens its own, and the loop itself stops if it never does. The budget
|
||||
* guards against a console that keeps dying, not against a long session.
|
||||
*/
|
||||
export function deadConsoleAction({ loopRunning, loopStep, frameReady, reconnects, limit }) {
|
||||
if (loopRunning && loopStep === "Starting") return "wait-for-phase";
|
||||
if (!frameReady) return "no-hello";
|
||||
return reconnects < limit ? "reconnect" : "offer-button";
|
||||
}
|
||||
|
||||
/**
|
||||
* A project folder's own name, for the bar's project menu: the same last
|
||||
* segment the window title uses, or the whole path when there is none (a
|
||||
@@ -150,7 +227,9 @@ function lastSegment(dir) {
|
||||
* The console page's taskbar messages, checked here before anything reaches
|
||||
* the app (attention.rs decides what they mean). `attention` carries one of
|
||||
* the four states the page's favicon has; `taskbar` carries the Desktop app
|
||||
* switch as a boolean. Anything else is null, and nothing is forwarded.
|
||||
* switch as a boolean, and `activities-full` an Activities game going in or
|
||||
* out of full screen the same way (taskbarSwitch checks both). Anything else
|
||||
* is null, and nothing is forwarded.
|
||||
*/
|
||||
export const ATTENTION_STATES = Object.freeze(['busy', 'ready', 'attention', 'plain']);
|
||||
|
||||
|
||||
Reference in new issue
Block a user