Rebuild the desktop app's top bar and drop its context meter

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-25 12:50:11 -07:00
1 parent 442904e6f2
commit efc96e91c2
15 files changed
+606 -1247

No files matched your search

+254 -147
View File
@@ -2,16 +2,27 @@
// agent's terminal panel docked at the bottom with a drag handle.
import { mountTerminal } from './terminal.js';
import { nudgeDue } from './meter.js';
import { barNextSteps, folderName, windowTitleFor } from './meter.js';
const { invoke, Channel } = window.__TAURI__.core;
const projectDirEl = document.getElementById('project-dir');
const projectMenuBtn = document.getElementById('project-menu-button');
const projectNameEl = document.getElementById('project-name');
const projectPathEl = document.getElementById('project-path');
const projectMenu = document.getElementById('project-menu');
const agentMenuBtn = document.getElementById('agent-menu-button');
const agentMenu = document.getElementById('agent-menu');
const agentMenuHeadEl = document.getElementById('agent-menu-head');
const agentDotEl = document.getElementById('agent-dot');
const agentNameEl = document.getElementById('agent-name');
const agentEndedEl = document.getElementById('agent-ended');
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 changeAgentBtn = document.getElementById('change-agent');
const changeProjectBtn = document.getElementById('change-project');
const barRowEl = document.getElementById('bar-row');
const launchCard = document.getElementById('launch-card');
const launchAgentEl = document.getElementById('launch-agent');
const launchMissingEl = document.getElementById('launch-missing');
@@ -24,16 +35,10 @@ const launchStartBtn = document.getElementById('launch-start');
const firstRunEl = document.getElementById('first-run');
const firstRunListEl = document.getElementById('first-run-list');
const firstRunStartBtn = document.getElementById('first-run-start');
const meterSlot = document.getElementById('bar-slot-meter');
const nudgeEl = document.getElementById('context-nudge');
const nudgeRestartBtn = document.getElementById('context-restart');
const versionEl = document.getElementById('version-update');
const versionTextEl = document.getElementById('version-update-text');
const versionBtn = document.getElementById('version-update-button');
const versionRestartBtn = document.getElementById('version-update-restart');
const consoleStatusEl = document.getElementById('console-status');
const permissionsNoteEl = document.getElementById('permissions-note');
const consoleAgainBtn = document.getElementById('console-again');
const nextStepEl = document.getElementById('next-step');
const nextStepTextEl = document.getElementById('next-step-text');
const nextStepBtn = document.getElementById('next-step-button');
const nextStepMoreEl = document.getElementById('next-step-more');
const frame = document.getElementById('console-frame');
const stateBox = document.getElementById('dashboard-state');
const stateText = document.getElementById('dashboard-state-text');
@@ -46,10 +51,8 @@ const termDockBtn = document.getElementById('term-dock');
const termMaximizeBtn = document.getElementById('term-maximize');
const termCollapseBtn = document.getElementById('term-collapse');
const termBadgeEl = document.getElementById('term-badge');
const currentPageEl = document.getElementById('current-page');
const STATUS_POLL_MS = 5000;
const METER_POLL_MS = 2000;
const BADGE_POLL_MS = 2000;
const MIN_PANE = 0.10;
const MAX_PANE = 0.60;
@@ -71,12 +74,6 @@ const EFFORT_OPTIONS = {
let agent = { state: 'idle', kind: null, generation: 0 };
const agentActive = () => agent.state === 'running';
// The context percent that triggers the Restart suggestion, from the app's
// settings (main() reads it), and the agent run the suggestion was shown for:
// it appears once per run, not again after it is dismissed by a Restart.
let nudgePercent = 70;
let nudgeShownFor = null;
const terminal = await mountTerminal(document.getElementById('term'), {
onInput: (data) => {
if (agentActive()) invoke('agent_input', { data });
@@ -114,7 +111,7 @@ function applyAgentState(next, { skipReset } = {}) {
const label = AGENT_LABELS[agent.kind] || '';
const active = agentActive();
agentNameEl.textContent = active ? label : '';
const ended = agent.state === 'ended';
if (active) {
// Only ever auto-*hides* the card (the agent just started); it must
// never auto-*show* it on 'ended' or 'idle' — that is Change agent's
@@ -122,39 +119,118 @@ function applyAgentState(next, { skipReset } = {}) {
launchCard.hidden = true;
hideFirstRun();
}
// One rule throughout: Restart while running or ended (it keeps the
// previous agent, model, effort and mode); Change agent only once ended,
// when there is a real choice to make again.
restartBtn.hidden = !(active || agent.state === 'ended');
changeAgentBtn.hidden = agent.state !== 'ended';
// Checked mode needs no banner; bypass always gets one, naming the agent it
// applies to, for exactly as long as that agent runs.
// One rule throughout: New Session and the agent menu while running or
// 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);
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.
const bypassActive = active && agent.mode === 'bypass';
permissionsNoteEl.hidden = !bypassActive;
permissionsNoteEl.textContent = bypassActive ? `Permission checks are off for ${label || 'the running agent'}` : '';
restartBtn.title = agent.state === 'ended' ? 'Start a fresh agent on the same brief' : 'Replace the agent with a fresh one, on a fresh context window';
if (freshScreen || agent.state !== 'running') nudgeEl.hidden = true;
if (!agentActive()) renderMeter({ kind: 'unknown' });
agentMenuBtn.hidden = !(active || ended);
agentNoneEl.hidden = active || ended;
agentNameEl.textContent = active || ended ? label || 'The agent' : '';
agentDotEl.className = `agent-dot${active ? (bypassActive ? ' is-warn' : ' is-ok') : ''}`;
agentEndedEl.hidden = !ended;
agentBypassEl.hidden = !bypassActive;
renderAgentMenuHead(label || 'The agent', { active, ended, bypassActive });
if (agentMenu.hidden === false && agentMenuBtn.hidden) closeBarMenus();
restartBtn.title = ended ? 'Start a fresh agent on the same brief' : 'Replace the agent with a fresh one, on a fresh context window';
// The agent is back (a fresh generation, running): the restart message stays
// on screen (restarting() below) until its dashboard page is announced.
if (restarting && freshScreen && agent.state === 'running') {
terminal.write('\r\n\r\n[Fresh agent started. Waiting for the dashboard...]\r\n\r\n');
}
if (agent.state === 'ended') {
agentStatusEl.textContent = `${label || 'The agent'} ended: ${agent.reason}. Nothing starts until you press Restart.`;
if (ended) {
// The why sits beside the agent's menu; the menu says the rest.
setAgentStatus(agent.reason);
// A failed Restart clears the screen too, so it says so again.
if (!wasEnded || freshScreen) {
terminal.write(`\r\n[${label || 'The agent'} ended: ${agent.reason}. Press Restart in the bar to start a fresh one.]\r\n`);
terminal.write(`\r\n[${label || 'The agent'} ended: ${agent.reason}. Press New Session in the bar to start a fresh one.]\r\n`);
}
} else {
// After a Restart the bar says what it left for the dashboard, if anything.
agentStatusEl.textContent = agent.briefNote || '';
setAgentStatus(agent.briefNote || '');
}
agentStatusEl.title = agentStatusEl.textContent;
updateBadge();
}
// The short line after the agent's menu: an ended agent's reason or a
// Restart's brief note (quiet), or something that went wrong (in red).
function setAgentStatus(text, { error = false } = {}) {
agentStatusEl.textContent = text;
agentStatusEl.title = text;
agentStatusEl.classList.toggle('is-error', error && Boolean(text));
}
// 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 }) {
const name = document.createElement('b');
name.textContent = label;
if (active) {
const mode = document.createElement('span');
if (bypassActive) {
mode.className = 'is-warn';
mode.textContent = 'off';
} else {
mode.textContent = 'on';
}
agentMenuHeadEl.replaceChildren(name, ' is running', document.createElement('br'), 'Permission checks are ', mode);
if (bypassActive) agentMenuHeadEl.append(': it runs commands and changes files without asking');
} else if (ended) {
agentMenuHeadEl.replaceChildren(name, ` ended: ${agent.reason}`, document.createElement('br'), 'Nothing starts until you press New Session.');
} else {
agentMenuHeadEl.replaceChildren();
}
}
// The bar's two menus (project, agent). They hang outside the scrolling bar
// row, fixed under their trigger, so the row's overflow never clips them.
// Clicking anywhere else (the console frame and the terminal too), Escape,
// a resize or a scroll of the row all close them.
let openBarMenu = null;
function closeBarMenus() {
for (const [button, menu] of [[projectMenuBtn, projectMenu], [agentMenuBtn, agentMenu]]) {
menu.hidden = true;
button.setAttribute('aria-expanded', 'false');
}
openBarMenu = null;
}
function toggleBarMenu(button, menu) {
const wasOpen = openBarMenu === menu;
closeBarMenus();
if (wasOpen) return;
menu.hidden = false;
const at = button.getBoundingClientRect();
const left = Math.max(8, Math.min(at.left, window.innerWidth - menu.offsetWidth - 8));
menu.style.left = `${left}px`;
menu.style.top = `${at.bottom + 4}px`;
button.setAttribute('aria-expanded', 'true');
openBarMenu = menu;
}
projectMenuBtn.onclick = () => toggleBarMenu(projectMenuBtn, projectMenu);
agentMenuBtn.onclick = () => toggleBarMenu(agentMenuBtn, agentMenu);
document.addEventListener('pointerdown', (event) => {
if (!openBarMenu) return;
if (openBarMenu.contains(event.target) || projectMenuBtn.contains(event.target) || agentMenuBtn.contains(event.target)) return;
closeBarMenus();
});
document.addEventListener('keydown', (event) => {
if (event.key !== 'Escape' || !openBarMenu) return;
const trigger = openBarMenu === projectMenu ? projectMenuBtn : agentMenuBtn;
closeBarMenus();
trigger.focus();
});
window.addEventListener('blur', closeBarMenus);
window.addEventListener('resize', closeBarMenus);
barRowEl.addEventListener('scroll', closeBarMenus);
// True from a confirmed Restart until the fresh agent's dashboard page is
// announced (showAnnounced below): the frame stays blanked with a message the
// whole time, since the restarted agent must boot and run the skill again
@@ -167,13 +243,12 @@ function confirmRestart(onYes) {
return;
}
showState(
'Restart the agent on a fresh context window? What it was doing is not saved.',
'Restart',
'Restart the agent on a fresh context window?',
'New Session',
() => {
restarting = true;
currentUrl = null;
frameReady = false;
currentPageEl.textContent = '';
showState('The agent is restarting on a fresh context window. Please wait for the dashboard to load.');
onYes();
},
@@ -322,14 +397,14 @@ async function startAgent(event) {
const model = launchModelEl.value.trim() || null;
const effort = (EFFORT_OPTIONS[kind] || []).length > 0 ? launchEffortEl.value || null : null;
const mode = launchBypassEl.checked ? 'bypass' : 'checked';
agentStatusEl.textContent = '';
setAgentStatus('');
showState('Waiting for the agent to open the dashboard');
const { cols, rows } = terminal.size();
try {
await invoke('agent_start', { kind, model, effort, mode, cols, rows });
terminal.focus();
} catch (error) {
agentStatusEl.textContent = `Could not start the agent: ${error}`;
setAgentStatus(`Could not start the agent: ${error}`, { error: true });
showLaunchCard();
}
}
@@ -339,15 +414,17 @@ async function agentAction(command) {
await invoke(command);
terminal.focus();
} catch (error) {
agentStatusEl.textContent = String(error);
setAgentStatus(String(error), { error: true });
}
}
launchCard.addEventListener('submit', startAgent);
restartBtn.onclick = () => confirmRestart(() => agentAction('agent_restart'));
nudgeRestartBtn.onclick = () => confirmRestart(() => agentAction('agent_restart'));
// Only ever enabled once the agent has ended: nothing active to lose, so no confirm.
changeAgentBtn.onclick = () => showLaunchCard();
changeAgentBtn.onclick = () => {
closeBarMenus();
showLaunchCard();
};
// The pane's shape: which edge it docks to, its share of the window when it
// is neither collapsed nor maximized (dragging and the settings file both
@@ -455,14 +532,64 @@ function loadFrame(url) {
frame.src = url;
}
// What the console page may ask of this window. Each is a named request with
// no free text, so the page can never type anything but "continue".
window.addEventListener('message', (event) => {
if (event.source !== frame.contentWindow) return;
if (!event.data || event.data.plan2code !== 'console-ready') return;
frameReady = true;
clearTimeout(helloTimer);
hideState();
const kind = event.data && event.data.plan2code;
if (kind === 'console-ready') {
frameReady = true;
clearTimeout(helloTimer);
hideState();
} else if (kind === 'agent-continue') {
typeContinue();
} else if (kind === 'new-session') {
// The bar's own button, so the press is confirmed exactly the same way.
if (!restartBtn.hidden) restartBtn.click();
} else if (kind === 'looks') {
applyAccent(event.data.accent, { save: true });
}
});
// Its "Not running... type continue" line, pressed: the word, then Enter on
// its own a moment later, so an agent that treats one burst of input as a
// paste still reads the Enter as a submit.
const ENTER_AFTER_MS = 120;
function typeContinue() {
if (!agentActive()) return;
invoke('agent_input', { data: 'continue' })
.then(() => new Promise((resolve) => setTimeout(resolve, ENTER_AFTER_MS)))
.then(() => invoke('agent_input', { data: '\r' }))
.catch((error) => {
setAgentStatus(`Could not type continue: ${error}`, { error: true });
});
}
// The person's highlight color, as the console page last sent it (its dark
// shades: fill, soft, ink, line), so the bar's buttons light in it too. Kept
// here for the next launch, which paints the bar before any page has loaded.
const ACCENT_KEY = 'p2c-app:accent';
const ACCENT_VARS = ['--accent', '--accent-soft', '--accent-ink', '--accent-line'];
function applyAccent(shades, { save = false } = {}) {
if (!Array.isArray(shades) || shades.length !== ACCENT_VARS.length) return;
if (!shades.every((c) => typeof c === 'string' && /^#[0-9a-f]{6}$/i.test(c))) return;
ACCENT_VARS.forEach((name, i) => document.documentElement.style.setProperty(name, shades[i]));
if (!save) return;
try {
localStorage.setItem(ACCENT_KEY, JSON.stringify(shades));
} catch {
// Not remembered is fine: the stylesheet's default shows until a page loads.
}
}
try {
applyAccent(JSON.parse(localStorage.getItem(ACCENT_KEY)));
} catch {
// Nothing saved, or storage is blocked: the stylesheet's default stands.
}
// No hello in time: ask the console why, and say so with a way forward.
async function onNoHello() {
if (frameReady || !consoleKnown || restarting) return;
@@ -473,7 +600,7 @@ async function onNoHello() {
// The status check itself failed; treat it as a console that is not answering.
}
if (!status || status.state !== 'running') {
showState('The console stopped, so the page could not show.', 'Restart the console', reconnectConsole);
showState('The console stopped, so the page could not show.', 'Reconnect the console', reconnectConsole);
} else {
showState('The console is running but its page did not show in this window.', 'Reload the page', () => {
showState('Reloading the page');
@@ -512,10 +639,7 @@ async function reconnectConsole() {
} catch (error) {
showState(`The console could not be reached: ${error}`, 'Retry', reconnectConsole);
// An old console cannot be framed: the fix is the skills update, so offer it.
if (String(error).includes('too old')) {
versionTextEl.textContent = 'The installed console is too old for the app';
versionEl.hidden = false;
}
if (String(error).includes('too old')) setVersionState({ kind: 'too-old' });
}
}
@@ -545,113 +669,55 @@ async function pollConsole() {
}
}
// The meter: a bar and a percent for a real or best-effort reading, a dashed
// bar with "about N%" and an "estimate" tag for an estimate, "unknown" when
// nothing is available. Built with DOM calls, never innerHTML.
function renderMeter(reading) {
meterSlot.replaceChildren();
// Left empty, not even an "unknown" label: #bar-slot-meter:empty hides it,
// so the bar carries nothing until the reading means something.
if (reading.kind === 'unknown') return;
const label = document.createElement('span');
const track = document.createElement('span');
track.className = `meter-track ${reading.kind}`;
const fill = document.createElement('span');
fill.className = 'meter-fill';
fill.style.width = `${reading.percent}%`;
track.append(fill);
label.textContent = reading.kind === 'estimate' ? `about ${reading.percent}%` : `${reading.percent}%`;
meterSlot.append(track, label);
if (reading.kind === 'estimate') {
const tag = document.createElement('span');
tag.className = 'meter-tag';
tag.textContent = 'estimate';
meterSlot.append(tag);
meterSlot.title = 'Estimated from the text so far: the agent does not report its context size';
} else if (reading.kind === 'besteffort') {
meterSlot.title = 'Read from the agent\'s session log: undocumented, so it may stop working after an update';
} else {
meterSlot.title = 'How full the agent context is, as the agent reports it';
}
}
// Every two seconds while an agent runs: draw the meter and, once per run,
// suggest a Restart when the context reaches the nudge percent.
async function pollMeter() {
if (!agentActive()) return;
try {
// The reading may land after a Restart: only a reading for the same run counts.
const { generation, state } = agent;
const reading = await invoke('agent_context');
if (agent.generation !== generation || agent.state !== state) return;
renderMeter(reading);
if (nudgeDue(reading, nudgePercent) && state === 'running' && nudgeShownFor !== generation) {
nudgeShownFor = generation;
nudgeEl.hidden = false;
}
} catch {
// A failed read is not a reading: look again on the next tick.
}
}
// Once, at start: when the app and the installed skills are on different versions the bar
// says so and offers Update skills. Nothing runs until that button is pressed.
async function checkVersions() {
try {
const status = await invoke('version_status');
if (!status.mismatch) return;
if (status.skills_ahead) {
// The skills are ahead of this app: another Update skills run cannot help.
versionTextEl.textContent = `The installed skills are v${status.skills}, newer than this app (v${status.app}). Get the new app.`;
versionBtn.hidden = true;
} else {
versionTextEl.textContent = `Skills are v${status.skills}, this app is v${status.app}`;
versionBtn.hidden = false;
}
versionEl.hidden = false;
// Skills ahead of this app: another Update skills run cannot help, so
// that state offers no button.
setVersionState({ kind: status.skills_ahead ? 'ahead' : 'mismatch', skills: status.skills, app: status.app });
} catch {
// No version to compare is no reason to nag.
}
}
versionBtn.onclick = async () => {
versionBtn.disabled = true;
versionRestartBtn.hidden = true;
versionTextEl.textContent = 'Updating Plan2Code...';
async function updateSkills() {
setVersionState({ kind: 'updating', line: 'Updating Plan2Code...' });
const progress = new Channel();
progress.onmessage = (line) => {
if (line) versionTextEl.textContent = line;
if (line && versionState && versionState.kind === 'updating') setVersionState({ kind: 'updating', line });
};
try {
const outcome = await invoke('update_skills', { progress });
versionTextEl.textContent = outcome.status.mismatch
? `Updated, but the mismatch remains (skills v${outcome.status.skills}, app v${outcome.status.app}).`
: 'Updated. Restart the console to use the new version.';
versionBtn.hidden = true;
versionRestartBtn.hidden = outcome.status.mismatch;
setVersionState(
outcome.status.mismatch
? { kind: 'remains', skills: outcome.status.skills, app: outcome.status.app }
: { kind: 'updated' }
);
} catch (error) {
versionTextEl.textContent = String(error);
versionBtn.disabled = false;
setVersionState({ kind: 'failed', error: String(error) });
}
};
}
versionRestartBtn.onclick = async () => {
versionRestartBtn.disabled = true;
// After an update: stop the old console first, so the new skills are really
// picked up, then bring a fresh one back on the same session.
async function restartConsole() {
try {
await invoke('console_stop');
} catch {
// Nothing to stop is fine: reconnectConsole starts a fresh one either way.
}
versionEl.hidden = true;
setVersionState(null);
await reconnectConsole();
};
// A page the agent's `console.mjs open` asked this window to show.
const pageLabel = (workflow) => (workflow || '').replace(/-/g, ' ').replace(/^./, (c) => c.toUpperCase());
}
// A page the agent's `console.mjs open` asked this window to show. Which page
// it is shows inside the frame itself (the console's own badge and title),
// not repeated here.
function showAnnounced(notice) {
restarting = false;
currentPageEl.textContent = pageLabel(notice.workflow);
if (!consoleKnown) {
consoleKnown = true;
if (!pollTimer) pollTimer = setInterval(pollConsole, STATUS_POLL_MS);
@@ -665,21 +731,62 @@ function showAnnounced(notice) {
window.__TAURI__.event.listen('console-page', (event) => showAnnounced(event.payload));
// 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".
let consoleDead = false;
let versionState = null;
const NEXT_STEP_ACTIONS = { reconnect: reconnectConsole, 'restart-console': restartConsole, update: updateSkills };
let nextStepAction = null;
function renderNextStep() {
const steps = barNextSteps({ consoleDead, version: versionState });
nextStepEl.hidden = steps.length === 0;
const [first, ...rest] = steps;
nextStepTextEl.textContent = first ? first.text : '';
nextStepTextEl.title = first ? first.title : '';
nextStepTextEl.className = first ? `is-${first.tone}${first.busy ? ' is-busy' : ''}` : '';
nextStepAction = first && first.action ? NEXT_STEP_ACTIONS[first.action] : null;
nextStepBtn.hidden = !nextStepAction;
nextStepBtn.disabled = false;
nextStepBtn.textContent = first && first.label ? first.label : '';
nextStepMoreEl.hidden = rest.length === 0;
nextStepMoreEl.textContent = `+${rest.length} more`;
nextStepMoreEl.title = rest.map((step) => step.title).join('\n');
}
function setVersionState(next) {
versionState = next;
renderNextStep();
}
function markConsoleAlive() {
consoleStatusEl.textContent = '';
consoleAgainBtn.hidden = true;
consoleDead = false;
renderNextStep();
}
function markConsoleDead() {
consoleStatusEl.textContent = 'The console stopped.';
consoleAgainBtn.hidden = false;
consoleDead = true;
renderNextStep();
}
consoleAgainBtn.onclick = () => reconnectConsole();
nextStepBtn.onclick = () => {
if (!nextStepAction) return;
// Pressed once per step: whatever it starts draws the next state itself.
nextStepBtn.disabled = true;
nextStepAction();
};
function setProjectDir(dir) {
projectDirEl.textContent = dir;
projectDirEl.title = dir;
// The bar names the folder; its menu holds the full path.
projectNameEl.textContent = folderName(dir);
projectMenuBtn.title = dir;
projectPathEl.textContent = dir;
projectMenuBtn.hidden = !dir;
// So two or more windows read apart in the taskbar without opening each
// one: a setTitle that fails (an old Tauri runtime, say) just leaves the
// static "Plan2Code" title from tauri.conf.json, never breaks the start.
window.__TAURI__.window.getCurrentWindow().setTitle(windowTitleFor(dir)).catch(() => {});
}
// The state `main()` read at startup: `pickFolder()` and the first-run
@@ -731,7 +838,6 @@ async function doChangeProject() {
restarting = false;
currentUrl = null;
frameReady = false;
currentPageEl.textContent = '';
afterProjectKnown();
} catch (error) {
showState(`Could not switch project: ${error}`, 'Try again', doChangeProject);
@@ -751,7 +857,10 @@ function changeProject() {
doChangeProject();
}
changeProjectBtn.onclick = changeProject;
changeProjectBtn.onclick = () => {
closeBarMenus();
changeProject();
};
// The launcher passed `--agent`: start it at once, on its model, with the
// same bypass flags the terminal launcher itself always runs that agent with
@@ -759,7 +868,7 @@ changeProjectBtn.onclick = changeProject;
async function autoStartAgent(state) {
launchAgentEl.value = state.autoStart;
if (typeof state.launchModel === 'string' && state.launchModel) launchModelEl.value = state.launchModel;
agentStatusEl.textContent = '';
setAgentStatus('');
showState('Starting the agent...');
const { cols, rows } = terminal.size();
try {
@@ -773,7 +882,7 @@ async function autoStartAgent(state) {
});
terminal.focus();
} catch (error) {
agentStatusEl.textContent = `Could not start the agent: ${error}`;
setAgentStatus(`Could not start the agent: ${error}`, { error: true });
showLaunchCard();
}
}
@@ -811,7 +920,6 @@ async function main() {
appState = state;
if (AGENT_LABELS[state.lastAgent]) launchAgentEl.value = state.lastAgent;
if (typeof state.launchModel === 'string' && state.launchModel) launchModelEl.value = state.launchModel;
if (Number.isInteger(state.contextNudgePercent)) nudgePercent = state.contextNudgePercent;
if (state.termPanel) {
paneDock = state.termPanel.dock === 'right' ? 'right' : 'bottom';
paneFraction = state.termPanel.fraction;
@@ -820,7 +928,6 @@ async function main() {
applyPaneLayout();
await loadAgentAvailability();
refreshLaunchCard();
setInterval(pollMeter, METER_POLL_MS);
setInterval(updateBadge, BADGE_POLL_MS);
checkVersions();
+86 -44
View File
@@ -10,30 +10,75 @@
html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; background: #1e1e1e; color: #ddd; }
body { display: flex; flex-direction: column; overflow: hidden; }
/* The console's dark tokens and its default highlight (Ocean). app.js sets
the four accent ones to the person's own highlight once the console page
says which it is, and keeps them for the next launch. */
:root {
--panel: #201d1a; --panel-2: #262220; --ink: #f0ece5; --ink-2: #b6afa3; --ink-3: #8b8376; --rule-2: #46403a;
--accent: #619fe5; --accent-soft: #1a2533; --accent-ink: #0c1117; --accent-line: #3d5978;
}
#bar { flex: none; border-bottom: 1px solid #444; }
/* The console's top bar buttons (.btn small ghost), sized to this bar:
quiet until hovered, then in the highlight color. New Session is the
one that is often the next step, so it wears the highlight outline at
rest, like the console's standby buttons. */
#bar button {
appearance: none; font: inherit; font-size: 12px; font-weight: 600; line-height: 1.2;
padding: 4px 10px; border-radius: 8px; cursor: pointer;
border: 1px solid var(--rule-2); background: var(--panel); color: var(--ink-2);
transition: background 0.12s, border-color 0.12s, color 0.12s;
}
#bar button:hover:not(:disabled) { color: var(--accent); border-color: var(--accent-line); background: var(--panel-2); }
#bar button:disabled { opacity: 0.45; cursor: not-allowed; }
#bar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#bar #agent-restart { background: transparent; border-color: var(--accent-line); color: var(--accent); }
#bar #agent-restart:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
#bar-row { height: 34px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 10px; font-size: 12px; white-space: nowrap; overflow-x: auto; overflow-y: hidden; }
#bar-sep { flex: none; align-self: stretch; width: 1px; margin: 8px 0; background: #3a3a3a; }
#title { font-weight: 600; font-size: 13px; }
#project-dir { color: #9ab; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 220px; }
#current-page { color: #8c8; }
#current-page:not(:empty)::before { content: "page: "; color: #666; }
#agent-name { color: #9ab; }
#agent-name:not(:empty)::before { content: "agent: "; color: #666; }
#console-status, #agent-status { color: #d7ba7d; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 260px; }
#agent-restart[hidden], #change-agent[hidden] { display: none; }
.bar-slot { flex: none; }
#permissions-note { color: #888; }
#context-nudge { display: flex; align-items: center; gap: 6px; color: #d7ba7d; }
#context-nudge[hidden] { display: none; }
#version-update { display: flex; align-items: center; gap: 6px; color: #d7ba7d; }
#version-update[hidden], #version-update-button[hidden] { display: none; }
#bar-slot-meter { display: flex; align-items: center; gap: 6px; color: #9ab; }
#bar-slot-meter:empty { display: none; }
.meter-track { display: inline-block; width: 64px; height: 8px; border: 1px solid #666; border-radius: 2px; overflow: hidden; background: #2a2a2a; }
.meter-track.estimate { border-style: dashed; }
.meter-fill { display: block; height: 100%; background: #6a9955; }
.meter-track.estimate .meter-fill { background: repeating-linear-gradient(45deg, #6a9955 0 4px, transparent 4px 8px); }
.meter-tag { color: #d7ba7d; font-style: italic; }
#bar [hidden] { display: none !important; }
/* The project and agent menus' triggers: plain text until hovered, a
caret saying there is more behind them. */
#bar .bar-menu { display: inline-flex; align-items: center; gap: 6px; flex: none; border-color: transparent; background: transparent; color: var(--ink); padding: 4px 8px; }
#bar .bar-menu:hover:not(:disabled), #bar .bar-menu[aria-expanded="true"] { background: var(--panel-2); border-color: transparent; color: var(--ink); }
.bar-caret { color: var(--ink-3); font-size: 10px; }
#project-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.agent-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #666; }
.agent-dot.is-ok { background: #6a9955; }
.agent-dot.is-warn { background: #d7ba7d; }
#agent-ended { color: var(--ink-3); font-weight: 400; }
#agent-bypass { flex: none; font-size: 11px; font-weight: 600; line-height: 1.3; padding: 0 7px; border-radius: 999px; border: 1px solid #d7ba7d; color: #d7ba7d; }
#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; }
#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; }
#next-step-text { overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
#next-step-text.is-ok { color: #6a9955; }
#next-step-text.is-warn { color: #d7ba7d; }
#next-step-text.is-err { color: #f48771; }
#next-step-text.is-busy::before {
content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; vertical-align: -1px;
border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: bar-spin 0.8s linear infinite;
}
@keyframes bar-spin { to { transform: rotate(360deg); } }
#bar #next-step-button { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#bar #next-step-button:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); filter: brightness(1.12); }
#next-step-more { color: var(--ink-3); font-size: 11px; border-bottom: 1px dotted var(--ink-3); cursor: help; }
/* The menus sit outside the scrolling row (fixed, placed under their
trigger by app.js), so the row's overflow never clips them. */
.bar-dropdown {
position: fixed; z-index: 20; min-width: 240px; max-width: 380px; padding: 6px; box-sizing: border-box;
font-size: 12px; background: var(--panel); border: 1px solid var(--rule-2); border-radius: 8px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.bar-dropdown-head { margin: 0; padding: 4px 8px 8px; color: var(--ink-3); line-height: 1.45; overflow-wrap: anywhere; }
.bar-dropdown-head b { color: var(--ink); font-weight: 600; }
.bar-dropdown-head .is-warn { color: #d7ba7d; }
#bar .bar-dropdown button {
display: block; width: 100%; text-align: left; font-weight: 400; padding: 6px 8px; border: 0; border-radius: 6px;
background: transparent; color: var(--ink);
}
#bar .bar-dropdown button:hover:not(:disabled), #bar .bar-dropdown button:focus-visible { background: var(--panel-2); color: var(--accent); }
#workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#workspace.dock-right { flex-direction: row; }
@@ -128,30 +173,27 @@
<body>
<header id="bar">
<div id="bar-row">
<span id="title">Plan2Code</span>
<span id="project-dir"></span>
<span id="bar-slot-restart" class="bar-slot"><button id="agent-restart" hidden>Restart</button></span>
<span id="bar-slot-change-agent" class="bar-slot"><button id="change-agent" hidden>Change agent</button></span>
<span id="bar-slot-change-project" class="bar-slot"><button id="change-project">Change project</button></span>
<span id="bar-sep" aria-hidden="true"></span>
<span id="current-page" title="The page the agent opened"></span>
<span id="agent-name"></span>
<button id="project-menu-button" class="bar-menu" aria-haspopup="menu" aria-expanded="false" aria-controls="project-menu" hidden><span id="project-name"></span><span class="bar-caret" aria-hidden="true">&#9662;</span></button>
<!-- Whenever an agent exists, running or ended, just left of its menu. -->
<button id="agent-restart" hidden>New Session</button>
<button id="agent-menu-button" class="bar-menu" aria-haspopup="menu" aria-expanded="false" aria-controls="agent-menu" hidden><span id="agent-dot" class="agent-dot" aria-hidden="true"></span><span id="agent-name"></span><span id="agent-ended" hidden>ended</span><span id="agent-bypass" title="Permission checks are off: the agent runs commands and changes files without asking" hidden>checks off</span><span class="bar-caret" aria-hidden="true">&#9662;</span></button>
<span id="agent-none">No agent</span>
<span id="agent-status" role="status"></span>
<span id="console-status"></span>
<button id="console-again" hidden>Start it again</button>
<span id="context-nudge" class="bar-slot" hidden>
<span>Context is getting full: consider Restart</span>
<button id="context-restart">Restart</button>
<span id="bar-grow"></span>
<!-- The console's or the skills' one next step (meter.js barNextSteps), when there is one. -->
<span id="next-step" role="status" hidden>
<span id="next-step-text"></span>
<button id="next-step-button" hidden></button>
<span id="next-step-more" hidden></span>
</span>
<!-- Shown only when the app and the installed skills are on different versions. -->
<span id="version-update" class="bar-slot" hidden>
<span id="version-update-text"></span>
<button id="version-update-button">Update skills</button>
<button id="version-update-restart" hidden>Restart the console</button>
</span>
<span id="bar-slot-meter" class="bar-slot"></span>
<!-- Shown only while an agent is running, naming the real mode it started with. -->
<span id="permissions-note" hidden></span>
</div>
<div id="project-menu" class="bar-dropdown" role="menu" aria-label="Project" hidden>
<p class="bar-dropdown-head">Project<br><b id="project-path"></b></p>
<button id="change-project" role="menuitem">Change project...</button>
</div>
<div id="agent-menu" class="bar-dropdown" role="menu" aria-label="Agent" hidden>
<p id="agent-menu-head" class="bar-dropdown-head"></p>
<button id="change-agent" role="menuitem" hidden>Change agent...</button>
</div>
</header>
<div id="workspace">
+86 -11
View File
@@ -1,15 +1,90 @@
// The context meter's pure decisions, kept out of app.js so they can be
// imported and tested without a DOM or `window.__TAURI__` (app.js touches
// both at module scope, the same reason the web console keeps its own pure
// logic in answers.js rather than app.js).
// The bar's pure decisions, kept out of app.js so they can be imported and
// tested without a DOM or `window.__TAURI__` (app.js touches both at module
// scope, the same reason the web console keeps its own pure logic in
// answers.js rather than app.js).
// The button label for each next-step action. Both ways of reconnecting the
// console read the same, wherever they come from.
export const NEXT_STEP_LABELS = {
reconnect: 'Reconnect the console',
'restart-console': 'Reconnect the console',
update: 'Update skills',
};
/**
* Whether `reading` (what the `agent_context` command returns) should fire
* the Restart nudge at `nudgePercent`. Only a real or best-effort number
* counts, per the context policy (pathfinder Question 11): an estimate is
* not precise enough for "about 70%" to mean the window really is close to
* full, so an estimate-only agent gets the meter but never the nudge.
* What the right end of the bar offers, most pressing first: the bar shows
* the first step (short text plus its one button) and counts the rest as
* "+N more". `consoleDead` is whether the console stopped answering;
* `version` is the skills/app version state, or null when they agree:
* `{ kind: 'mismatch' | 'ahead' | 'remains', skills, app }`,
* `{ kind: 'updating', line }`, `{ kind: 'updated' }`, `{ kind: 'too-old' }`
* or `{ kind: 'failed', error }`.
*
* Only one control for "reconnect the console" is ever offered: after an
* update, its Reconnect (which stops the old console first, so the new skills
* are really picked up) covers a console that has also stopped.
*/
export function nudgeDue(reading, nudgePercent) {
return (reading.kind === 'real' || reading.kind === 'besteffort') && reading.percent >= nudgePercent;
export function barNextSteps({ consoleDead = false, version = null } = {}) {
const v = version || {};
const steps = [];
if (v.kind === 'updated') {
steps.push({ id: 'updated', text: 'Skills updated', title: 'Updated. Reconnect the console to use the new version.', tone: 'ok', action: 'restart-console' });
} else if (consoleDead) {
steps.push({ id: 'console-dead', text: 'Console stopped', title: 'The console stopped, so the dashboard cannot show.', tone: 'err', action: 'reconnect' });
}
switch (v.kind) {
case 'too-old':
steps.push({ id: 'too-old', text: 'Console too old for this app', title: 'The installed console is too old for the app. Update skills to fix it.', tone: 'warn', action: 'update' });
break;
case 'mismatch':
steps.push({ id: 'mismatch', text: `Skills v${v.skills}, app v${v.app}`, title: `The installed skills are v${v.skills}, this app is v${v.app}.`, tone: 'warn', action: 'update' });
break;
case 'updating': {
const line = v.line || 'Updating Plan2Code...';
steps.push({ id: 'updating', text: line, title: line, tone: 'warn', busy: true, action: null });
break;
}
case 'remains':
steps.push({ id: 'remains', text: `Still mismatched: skills v${v.skills}, app v${v.app}`, title: `Updated, but the mismatch remains (skills v${v.skills}, app v${v.app}).`, tone: 'warn', action: null });
break;
case 'failed':
steps.push({ id: 'failed', text: 'Update failed', title: String(v.error || 'The update did not finish.'), tone: 'err', action: 'update' });
break;
case 'ahead':
steps.push({ id: 'ahead', text: `Skills v${v.skills} are newer than this app`, title: `The installed skills are v${v.skills}, newer than this app (v${v.app}). Get the new app.`, tone: 'warn', action: null });
break;
default:
break;
}
return steps.map((step) => ({ ...step, label: step.action ? NEXT_STEP_LABELS[step.action] : null }));
}
/**
* The OS window title for a project folder: its own name (the repo's, most
* of the time) after "Plan2Code - ", so two or more windows read apart in a
* taskbar without opening each to see which project is which. Trailing
* slashes and a drive root (`C:\`, `/`) leave nothing to show, so that falls
* back to the plain title rather than a trailing "Plan2Code - ".
*/
export function windowTitleFor(dir) {
const name = lastSegment(dir);
return name ? `Plan2Code - ${name}` : "Plan2Code";
}
/**
* 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
* root such as `/`), so the menu never shows an empty name.
*/
export function folderName(dir) {
return lastSegment(dir) || String(dir || "").trim();
}
function lastSegment(dir) {
return String(dir || "")
.trim()
.replace(/[\\/]+$/, "")
.split(/[\\/]/)
.filter(Boolean)
.pop();
}