Show on the desktop app's taskbar when Plan2Code needs you

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-26 06:36:45 -07:00
1 parent 765d2b3536
commit c602dfed57
25 files changed
+1038 -112

No files matched your search

+37 -7
View File
@@ -2,7 +2,7 @@
// agent's terminal panel docked at the bottom with a drag handle.
import { mountTerminal } from './terminal.js';
import { barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, windowTitleFor } from './meter.js';
import { attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor } from './meter.js';
const { invoke, Channel } = window.__TAURI__.core;
@@ -26,6 +26,7 @@ const barRowEl = document.getElementById('bar-row');
const launchCard = document.getElementById('launch-card');
const launchAgentEl = document.getElementById('launch-agent');
const launchMissingEl = document.getElementById('launch-missing');
const launchWarningEl = document.getElementById('launch-agents-warning');
const launchModelEl = document.getElementById('launch-model');
const launchModelListEl = document.getElementById('launch-model-list');
const launchEffortRow = document.getElementById('launch-effort-row');
@@ -267,14 +268,21 @@ function confirmRestart(onYes) {
// keeps the order Rust sent (built-ins, then custom agents); the map is by id.
let agentList = [];
let agentAvailability = {};
// What was skipped in agents.json, shown under the picker.
let agentWarnings = [];
async function loadAgentAvailability() {
// `refresh` (Check again) also has the app work its PATH out again, so a CLI
// whose installer added a new folder is found without a restart.
async function loadAgentAvailability(refresh = false) {
try {
agentList = await invoke('agent_availability');
const result = await invoke('agent_availability', { refresh });
agentList = result.agents || [];
agentWarnings = result.warnings || [];
agentAvailability = Object.fromEntries(agentList.map((entry) => [entry.id, entry]));
} catch {
// Nothing to show is not a reason to block the card: Start just tries it.
agentList = [];
agentWarnings = [];
agentAvailability = {};
}
}
@@ -346,7 +354,7 @@ function noAgentExplainer() {
// Re-read the agents from disk (a CLI installed or a custom agent added since),
// then redraw whatever shows them and pick the default again.
async function checkAgentsAgain() {
await loadAgentAvailability();
await loadAgentAvailability(true);
applyDefaultAgent((appState && appState.lastAgent) || launchAgentEl.value);
if (!firstRunEl.hidden && appState) renderFirstRun(appState);
}
@@ -371,6 +379,8 @@ function refreshLaunchCard() {
}
}
}
launchWarningEl.hidden = agentWarnings.length === 0;
launchWarningEl.textContent = agentWarnings.map((warning) => `agents.json: ${warning}`).join('\n');
// A custom agent has no separate effort, and offers its models as
// suggestions in the (still free-text) model field.
launchModelListEl.replaceChildren();
@@ -626,13 +636,20 @@ let consoleKnown = false;
function loadFrame(url) {
currentUrl = url;
frameReady = false;
// The page going away takes its taskbar dot with it; the new one tells its own.
clearAttention();
clearTimeout(helloTimer);
helloTimer = setTimeout(onNoHello, HELLO_WAIT_MS);
frame.src = url;
}
function clearAttention() {
invoke('clear_attention_cmd').catch(() => {});
}
// 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".
// no free text, so the page can never type anything but "continue", and the
// taskbar's two take only their fixed words and a boolean (meter.js).
window.addEventListener('message', (event) => {
if (event.source !== frame.contentWindow) return;
const kind = event.data && event.data.plan2code;
@@ -640,6 +657,17 @@ window.addEventListener('message', (event) => {
frameReady = true;
clearTimeout(helloTimer);
hideState();
// The Desktop app switch in its User Preferences shows what app.json holds.
const on = !appState || appState.taskbarSignal !== false;
event.source.postMessage({ plan2code: 'taskbar-state', on }, '*');
} else if (kind === 'attention') {
const signal = attentionSignal(event.data);
if (signal) invoke('set_attention', { signal }).catch(() => {});
} else if (kind === 'taskbar') {
const on = taskbarSwitch(event.data);
if (on === null) return;
if (appState) appState.taskbarSignal = on;
invoke('set_taskbar_signal', { on }).catch(() => {});
} else if (kind === 'agent-continue') {
typeContinue();
} else if (kind === 'new-session') {
@@ -697,6 +725,8 @@ try {
// No hello in time: ask the console why, and say so with a way forward.
async function onNoHello() {
if (frameReady || !consoleKnown || restarting) return;
// A page that does not answer cannot say it is done needing the person.
clearAttention();
let status = null;
try {
status = await invoke('console_status');
@@ -901,7 +931,7 @@ function setProjectDir(dir) {
// checklist both need it once a folder lands, after the fact.
let appState = null;
// Opens the OS folder picker. A cancelled pick (or a failed one) lands on the
// Opens the OS folder picker. A canceled pick (or a failed one) lands on the
// "No project folder chosen" state with a button that tries again.
async function pickFolder() {
try {
@@ -930,7 +960,7 @@ function afterProjectKnown() {
// Switches to a folder picked fresh: the Rust side tears the old project's
// agent and console down before the new one is remembered, so nothing from
// it carries over. Picking nothing (cancelled) leaves the current project as
// it carries over. Picking nothing (canceled) leaves the current project as
// it was.
async function doChangeProject() {
showState('Choose the new project folder...');
+4 -1
View File
@@ -89,7 +89,7 @@
#dashboard-state[hidden] { display: none; }
#dashboard-state-text { margin: 0; max-width: 60ch; overflow-wrap: anywhere; color: #bbb; }
#dashboard-state-planny[hidden] { display: none; }
/* Drawn and coloured like the console's own Planny (styles/planny.css):
/* Drawn and colored like the console's own Planny (styles/planny.css):
an outlined shell, the star eye, a lip of a smile, round hands. */
#dashboard-state-planny { width: 104px; height: auto; overflow: visible; }
#dashboard-state-planny :is(.ps-shell, .ps-smile, .ps-arm path, .ps-mug, .ps-handle) {
@@ -146,6 +146,8 @@
}
#launch-missing { margin: 0; font-size: 12px; color: #d7ba7d; }
#launch-missing code { color: #ddd; }
#launch-agents-warning { margin: 0; font-size: 12px; color: #d7ba7d; white-space: pre-line; }
#launch-agents-warning[hidden] { display: none; }
.agent-explainer { margin: 0; font-size: 12px; line-height: 1.5; }
.agent-explainer ul { margin: 4px 0; padding-left: 18px; }
.agent-explainer code { color: #ddd; }
@@ -296,6 +298,7 @@
<option value="codex">Codex</option>
</select>
<p id="launch-missing" hidden></p>
<p id="launch-agents-warning" hidden></p>
<label for="launch-model">Model</label>
<input id="launch-model" type="text" placeholder="Default (your account setting)" autocomplete="off" list="launch-model-list">
<datalist id="launch-model-list"></datalist>
+22 -2
View File
@@ -31,7 +31,9 @@ export function continueKeys(kind) {
* (built-ins first, then custom agents): the remembered id when it is
* installed, else the first installed built-in, else the first installed
* custom agent, else the remembered id or the first entry, so the card's
* missing-agent line explains what is wrong instead of picking silently.
* missing-agent line explains what is wrong instead of picking silently. A
* remembered id the list no longer has (a custom agent deleted since) is not
* kept, since the picker could not show it; with no list at all it is.
*/
export function pickDefaultAgent(availability, remembered) {
const list = Array.isArray(availability) ? availability : [];
@@ -41,7 +43,7 @@ export function pickDefaultAgent(availability, remembered) {
if (builtIn) return builtIn.id;
const custom = list.find((a) => a.installed && a.custom);
if (custom) return custom.id;
if (remembered) return remembered;
if (remembered && (rememberedEntry || list.length === 0)) return remembered;
return list.length > 0 ? list[0].id : null;
}
@@ -143,3 +145,21 @@ function lastSegment(dir) {
.filter(Boolean)
.pop();
}
/**
* 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.
*/
export const ATTENTION_STATES = Object.freeze(['busy', 'ready', 'attention', 'plain']);
export function attentionSignal(data) {
const state = data && data.state;
return ATTENTION_STATES.includes(state) ? state : null;
}
export function taskbarSwitch(data) {
const on = data && data.on;
return typeof on === 'boolean' ? on : null;
}