mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Show on the desktop app's taskbar when Plan2Code needs you
AI Assisted
This commit is contained in:
1 parent
765d2b3536
commit
c602dfed57
25 files changed
+1038
-112
No files matched your search
+31
-12
@@ -632,13 +632,10 @@ function announceCli(cli) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose the CLI from those installed: the `--cli` pick, the only one installed, or a numbered
|
||||
* menu defaulting to the last pick. Returns `{ cli }` with its resolved `path`, or `{ code }` (the
|
||||
* exit code) after printing why none can be used.
|
||||
* The CLIs that can run, in menu order (the built-ins found on PATH, then the custom agents whose
|
||||
* command resolves), and the custom agents left out because theirs does not.
|
||||
*/
|
||||
async function chooseCli(requested) {
|
||||
const customs = customClis();
|
||||
const all = [...CLIS, ...customs];
|
||||
function runnableClis(customs) {
|
||||
const installed = CLIS.map((cli) => ({ ...cli, path: findOnPath(cli.id) })).filter((cli) => cli.path);
|
||||
// A custom agent whose command does not resolve is left out of the menu and named when nothing can run.
|
||||
const missing = [];
|
||||
@@ -647,6 +644,18 @@ async function chooseCli(requested) {
|
||||
if (found) installed.push({ ...cli, ...found });
|
||||
else missing.push(cli);
|
||||
}
|
||||
return { installed, missing };
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose the CLI from those installed: the `--cli` pick, the only one installed, or a numbered
|
||||
* menu defaulting to the last pick. Returns `{ cli }` with its resolved `path`, or `{ code }` (the
|
||||
* exit code) after printing why none can be used.
|
||||
*/
|
||||
async function chooseCli(requested) {
|
||||
const customs = customClis();
|
||||
const all = [...CLIS, ...customs];
|
||||
const { installed, missing } = runnableClis(customs);
|
||||
|
||||
if (requested !== undefined) {
|
||||
const known = all.find((cli) => cli.id === requested);
|
||||
@@ -743,13 +752,20 @@ function listModels(cli) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask which model to run: a numbered list with Enter keeping the model the CLI last used.
|
||||
* Ask which model to run: a numbered list with Enter keeping the model the CLI last used (a
|
||||
* custom agent: its own default).
|
||||
* A pick appends `--model <id>` to `extraArgs`. Without an interactive terminal there is
|
||||
* nobody to ask, so it just says which model will be used, as it always has.
|
||||
*/
|
||||
async function chooseModel(cli, extraArgs) {
|
||||
if (cli.custom && !listModels(cli).length) return;
|
||||
// A custom agent has no last-used model to keep: left alone it starts on its own default.
|
||||
const keep = cli.custom ? 'its own default model' : 'the last-used model';
|
||||
if (!process.stdin.isTTY) {
|
||||
if (cli.custom) {
|
||||
console.log(`${cli.label} will start with its own default model. To pick one, run \`plan2code --model <id>\`.`);
|
||||
return;
|
||||
}
|
||||
console.log(`${cli.label} will use the model you last used in it. To use a different model, open`);
|
||||
console.log(`\`${cli.id}\` on its own and switch model there, or run \`plan2code --model <name>\`.`);
|
||||
return;
|
||||
@@ -773,7 +789,7 @@ async function chooseModel(cli, extraArgs) {
|
||||
models.forEach((model, i) => console.log(!model.label ? ` ${c.cyan(`${i + 1})`)} ${model.id}` : ` ${c.cyan(`${i + 1})`)} ${model.id} — ${model.label}`));
|
||||
}
|
||||
for (;;) {
|
||||
const answer = (await ask(`Choice ${c.green('[keep last used]')}: `)).trim().toLowerCase();
|
||||
const answer = (await ask(`Choice ${c.green(cli.custom ? '[default]' : '[keep last used]')}: `)).trim().toLowerCase();
|
||||
if (!answer) return;
|
||||
const byNumber = models[Number(answer) - 1];
|
||||
const byName = models.find((model) => model.id === answer || model.label.toLowerCase() === answer);
|
||||
@@ -782,7 +798,7 @@ async function chooseModel(cli, extraArgs) {
|
||||
extraArgs.push('--model', model.id);
|
||||
return;
|
||||
}
|
||||
console.log(c.yellow(`Type a number from 1 to ${models.length}, a model name, or press Enter to keep the last-used model.`));
|
||||
console.log(c.yellow(`Type a number from 1 to ${models.length}, a model name, or press Enter to keep ${keep}.`));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -946,7 +962,7 @@ async function confirmProject(cwd) {
|
||||
|
||||
/**
|
||||
* Ask for the project folder: the native picker when there is one, a typed path otherwise.
|
||||
* Returns the folder, or null when the person cancelled.
|
||||
* Returns the folder, or null when the person canceled.
|
||||
*/
|
||||
async function pickFolder() {
|
||||
const start = readLastFolder();
|
||||
@@ -962,7 +978,7 @@ async function pickFolder() {
|
||||
windowsHide: true,
|
||||
});
|
||||
const folder = (result.stdout || '').trim();
|
||||
// Pickers exit 0 or 1 with nothing printed when cancelled; anything else means the picker
|
||||
// Pickers exit 0 or 1 with nothing printed when canceled; anything else means the picker
|
||||
// itself failed, so fall through to the typed prompt rather than giving up.
|
||||
if (!result.error && folder && result.status === 0) return path.resolve(folder);
|
||||
if (!result.error && !folder && (result.status === 0 || result.status === 1)) return null;
|
||||
@@ -1013,6 +1029,9 @@ function spawnCommand(file, args, options) {
|
||||
// Windows env names are case-insensitive and the copy keeps the original spelling (Path).
|
||||
const pathKey = Object.keys(env).find((key) => key.toUpperCase() === 'PATH') || 'PATH';
|
||||
env[pathKey] = path.dirname(file) + path.delimiter + (env[pathKey] || '');
|
||||
// cmd looks in the current folder (the project) before PATH: a same-named
|
||||
// file there must not run in the agent's place.
|
||||
env.NoDefaultCurrentDirectoryInExePath = '1';
|
||||
return spawn(shell, ['/d', '/s', '/c', `"${[path.basename(file), ...args].map(quoteForCmd).join(' ')}"`], {
|
||||
...spawnOptions,
|
||||
env,
|
||||
@@ -1161,4 +1180,4 @@ async function launch() {
|
||||
// Run only when invoked directly; requiring the file (the tests do) is load-only.
|
||||
if (require.main === module) launch();
|
||||
|
||||
module.exports = { normalizeAgents, buildArgs, customClis, resolveCustomCommand, listModels, mergeModels, modelEntries, renderBanner, paint, hasModelFlag, compareVersions, modelFrom, hasDisplay, looksLikeProject };
|
||||
module.exports = { normalizeAgents, buildArgs, customClis, resolveCustomCommand, runnableClis, listModels, mergeModels, modelEntries, renderBanner, paint, hasModelFlag, compareVersions, modelFrom, hasDisplay, looksLikeProject };
|
||||
@@ -23,6 +23,19 @@ export function linkLeavesPage(href, origin) {
|
||||
return (url.protocol === "http:" || url.protocol === "https:") && url.origin !== origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call `handler(data)` for each `{ plan2code: kind, ... }` message the frame's
|
||||
* parent sends, and for nothing from anywhere else (another frame, the page
|
||||
* itself). The app's only answer today is `taskbar-state`.
|
||||
*/
|
||||
export function onAppMessage(kind, handler) {
|
||||
window.addEventListener("message", (event) => {
|
||||
if (!framed() || event.source !== window.parent) return;
|
||||
const data = event.data;
|
||||
if (data && typeof data === "object" && data.plan2code === kind) handler(data);
|
||||
});
|
||||
}
|
||||
|
||||
/** Post `message` to the frame's parent, as `{ plan2code: kind, ...extra }`; nothing outside a frame. */
|
||||
export function tellApp(kind, extra = {}) {
|
||||
if (!framed()) return;
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<div id="banner" class="banner" role="status" hidden></div>
|
||||
|
||||
<!-- Planny's wake-up on a freshly opened dashboard: a large copy of the
|
||||
rail drawing that powers on centre stage, then glides into the rail.
|
||||
rail drawing that powers on center stage, then glides into the rail.
|
||||
Hidden unless boot.js is playing it; placed entirely by app.css,
|
||||
because the CSP refuses style attributes. -->
|
||||
<div class="wake" id="wake" hidden>
|
||||
@@ -97,7 +97,7 @@
|
||||
<span class="badge" id="badge">Pathfinder</span>
|
||||
<h1 id="title">Plan2Code Console</h1>
|
||||
<!-- The session meter: how much this console session has done. The
|
||||
ring fills with the points (full at 15); the colour is the
|
||||
ring fills with the points (full at 15); the color is the
|
||||
level. Hidden until a frame carries `meter`. -->
|
||||
<span class="meter-slot">
|
||||
<button
|
||||
@@ -812,7 +812,7 @@
|
||||
Four boxes in a row, each talking both ways with the next: you in
|
||||
your browser, this page, a small program on 127.0.0.1, and
|
||||
Plan2Code in your terminal. A dashed outline around all four is
|
||||
labelled "Your machine only".
|
||||
labeled "Your machine only".
|
||||
</desc>
|
||||
<defs>
|
||||
<marker id="hd-about-arrow" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="5" markerHeight="5" orient="auto-start-reverse">
|
||||
@@ -930,7 +930,7 @@
|
||||
</li>
|
||||
<li class="help-row">
|
||||
<dl>
|
||||
<dt>You see</dt><dd><strong>Not running</strong> (Planny grey and still).</dd>
|
||||
<dt>You see</dt><dd><strong>Not running</strong> (Planny gray and still).</dd>
|
||||
<dt>Likely cause</dt><dd>Plan2Code has not checked in for a few minutes.</dd>
|
||||
<dt>Do this</dt><dd class="for-browser">Look at the terminal. If it is idle, type <code>continue</code> there.</dd><dd class="for-app">Look at the terminal panel. If it is idle, press <strong>continue</strong> in the line beside Planny, which types it there for you.</dd>
|
||||
</dl>
|
||||
@@ -998,7 +998,7 @@
|
||||
<h4>Not running, or not connected?</h4>
|
||||
<ul>
|
||||
<li>
|
||||
<strong>Not running</strong> (Planny grey and still): this page is
|
||||
<strong>Not running</strong> (Planny gray and still): this page is
|
||||
fine, but Plan2Code in the terminal has not checked in for
|
||||
<span data-fact="adriftMinutes">3</span> minutes. It may have finished
|
||||
its turn, hit an error, or be waiting on you there.
|
||||
@@ -1386,7 +1386,7 @@
|
||||
<p id="help-planny-done-text">A green star and both arms up. The session is finished. You can close the tab.</p>
|
||||
<h4>Not running</h4>
|
||||
<p>
|
||||
Grey, still, arms down out of sight. This page is fine, but Plan2Code has not checked in
|
||||
Gray, still, arms down out of sight. This page is fine, but Plan2Code has not checked in
|
||||
for <span data-fact="adriftMinutes">3</span> minutes. Anything you answer
|
||||
is still saved.
|
||||
</p>
|
||||
@@ -1762,7 +1762,7 @@
|
||||
<strong>Start from scratch</strong> for a new idea. The one you pick is
|
||||
what a step works on, and it decides which cards make sense: a spec
|
||||
that is half built has no use for Pathfinder, and a new idea cannot be
|
||||
implemented yet. Cards that do not fit are greyed out with the reason
|
||||
implemented yet. Cards that do not fit are grayed out with the reason
|
||||
why.
|
||||
</p>
|
||||
<p>
|
||||
@@ -2026,7 +2026,7 @@
|
||||
<h4>While something is running</h4>
|
||||
<ul>
|
||||
<li>
|
||||
Everything greys out except switching tabs, searching and opening
|
||||
Everything grays out except switching tabs, searching and opening
|
||||
folds, so nothing queues up behind the running command.
|
||||
</li>
|
||||
<li>What is running shows where the next step usually sits.</li>
|
||||
@@ -2049,7 +2049,7 @@
|
||||
<strong>Done with git</strong> ends the board. If anything happened, the
|
||||
last screen lists the commits, pushes and branches created or deleted,
|
||||
with <strong>Back to the dashboard</strong>; if nothing did, the page
|
||||
goes straight back to the dashboard. It greys while a command runs and
|
||||
goes straight back to the dashboard. It grays while a command runs and
|
||||
comes back when it is done; if Plan2Code stops checking in,
|
||||
<strong>Stop session</strong> in the top bar ends the session instead.
|
||||
While a question of Plan2Code's waits, it cancels that question and
|
||||
@@ -2423,7 +2423,7 @@
|
||||
</li>
|
||||
<li>
|
||||
<strong>Highlight color</strong>: one of
|
||||
<span data-fact="accentCount">32</span>, ocean blue to begin with. It marks
|
||||
<span data-fact="accentCount">38</span>, ocean blue to begin with. It marks
|
||||
what is yours to do, and Planny's star uses it while he works.
|
||||
</li>
|
||||
<li>
|
||||
@@ -2664,6 +2664,16 @@
|
||||
<span class="help" id="agents-status" role="status"></span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<!-- Only inside the desktop app (framed()): the app saves the switch in its own app.json. -->
|
||||
<fieldset class="modal-ranges looks-desktop" id="looks-desktop" hidden>
|
||||
<legend>Desktop app</legend>
|
||||
<label><input type="checkbox" id="looks-taskbar" checked /> <span>Show on the taskbar when Plan2Code needs me</span></label>
|
||||
<p class="help">
|
||||
Windows: a colored dot on the taskbar button (green on your move, red when it
|
||||
needs you) and a short burst of flashes. macOS: a red badge on the dock icon when it needs
|
||||
you, and a bounce. Linux: depends on your desktop.
|
||||
</p>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn ghost" id="looks-reset">Back to default</button>
|
||||
|
||||
@@ -1044,6 +1044,16 @@ function continueButton() {
|
||||
return btn;
|
||||
}
|
||||
|
||||
// The favicon state last told to the app (attention.rs turns it into the
|
||||
// taskbar's dot). Told only when it changes, never on every status redraw.
|
||||
let lastAttention = null;
|
||||
|
||||
function tellAttention(state) {
|
||||
if (state === lastAttention) return;
|
||||
lastAttention = state;
|
||||
tellApp("attention", { state });
|
||||
}
|
||||
|
||||
export function renderStatus() {
|
||||
if (!page.S) return;
|
||||
const bot = $("planny");
|
||||
@@ -1089,8 +1099,11 @@ export function renderStatus() {
|
||||
tick.textContent = count || "";
|
||||
$("agent-spin").hidden = !spin;
|
||||
$("dock").classList.toggle("is-flying", Boolean(spin));
|
||||
// The tab icon's bar says the same thing from another tab (favicon.js).
|
||||
setFavicon(faviconState({ mood, spin, finished: Boolean(finish()) }));
|
||||
// The tab icon's bar says the same thing from another tab (favicon.js),
|
||||
// and the app's taskbar entry from another window.
|
||||
const icon = faviconState({ mood, spin, finished: Boolean(finish()) });
|
||||
setFavicon(icon);
|
||||
tellAttention(icon);
|
||||
};
|
||||
|
||||
// Before `gone`, deliberately. Once a session has finished, no server is the
|
||||
@@ -1311,7 +1324,7 @@ export function renderSidebar() {
|
||||
box.appendChild(head);
|
||||
for (const e of SKILL_CATALOG.filter((x) => x.group === g.id)) {
|
||||
const av = cardPresentation(e, scan(), selSpec(), menu);
|
||||
// Unavailable for the selected spec fades hard; the brief greying
|
||||
// Unavailable for the selected spec fades hard; the brief graying
|
||||
// while a launch is in flight or the server is away does not.
|
||||
const b = el(
|
||||
"button",
|
||||
@@ -1439,7 +1452,7 @@ function paintMain(main) {
|
||||
if (isDashboard() && !finish()) {
|
||||
if (page.local.launching) renderLaunching(main);
|
||||
else if (page.dashPick) {
|
||||
// A spec-switch under an open confirm can grey the pick out. Rather
|
||||
// A spec-switch under an open confirm can gray the pick out. Rather
|
||||
// than offer START on a card that cannot launch, drop back to the
|
||||
// menu — the picker's new selection speaks for itself there.
|
||||
if (cardAvailability(page.dashPick, scan(), selSpec()).on) renderConfirm(main, page.dashPick);
|
||||
@@ -1620,7 +1633,7 @@ export function renderFooter() {
|
||||
const hint = $("send-hint");
|
||||
hint.replaceChildren();
|
||||
hint.title = state.why;
|
||||
// Something is turning while the turn is not theirs. A line of grey text
|
||||
// Something is turning while the turn is not theirs. A line of gray text
|
||||
// saying "one moment" reads the same whether the agent is working on it or
|
||||
// has quietly died; a spinner is the difference between the two at a glance.
|
||||
// A spinner says "something is happening". Nothing is, once the other end
|
||||
@@ -1932,6 +1945,8 @@ export function wireChrome() {
|
||||
try {
|
||||
navigator.sendBeacon("/bye");
|
||||
} catch {}
|
||||
// A page that goes away leaves no dot on the app's taskbar behind it.
|
||||
tellAttention("plain");
|
||||
});
|
||||
|
||||
// Under the app, a link off the page goes to the default browser through
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ROLES, ROLE_NOT_SET, ROLE_NOT_SET_LABEL, needsRoleNudge, normalizeRole
|
||||
import { isDashboard } from "../selectors.js";
|
||||
import { el, lightDismiss } from "../render.js";
|
||||
import { page, redraw } from "../state.js";
|
||||
import { framed, onAppMessage, tellApp } from "../app-bridge.js";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
@@ -552,4 +553,14 @@ export function wireLooks() {
|
||||
saveModels();
|
||||
renderModels();
|
||||
});
|
||||
|
||||
// Desktop app: the taskbar switch, kept by the app in its own app.json. The
|
||||
// app says what it holds once the page is up; checked until it does.
|
||||
if (framed()) {
|
||||
$("looks-desktop").hidden = false;
|
||||
onAppMessage("taskbar-state", (data) => {
|
||||
if (typeof data.on === "boolean") $("looks-taskbar").checked = data.on;
|
||||
});
|
||||
$("looks-taskbar").addEventListener("change", (e) => tellApp("taskbar", { on: e.target.checked }));
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@
|
||||
}
|
||||
|
||||
/* Folded-in sections. A page holds one card; what used to be cards of their
|
||||
own (the "all caught up" lull, the session notes) is a labelled section
|
||||
own (the "all caught up" lull, the session notes) is a labeled section
|
||||
inside it instead. */
|
||||
.card-lead { margin: 0 0 16px; }
|
||||
.card-extra { margin: 18px 0 0; }
|
||||
@@ -162,7 +162,7 @@
|
||||
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
|
||||
}
|
||||
.sa-strength { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
/* A helper's strength and effort, coloured by rank: calm teal, amber, violet. */
|
||||
/* A helper's strength and effort, colored by rank: calm teal, amber, violet. */
|
||||
.sa-badge {
|
||||
--b: var(--ink-2);
|
||||
--b-soft: var(--panel);
|
||||
@@ -755,7 +755,10 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
|
||||
.modal.looks .modal-ranges + .modal-ranges { margin-top: 18px; }
|
||||
.looks-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.looks-row .help { grid-column: 1 / -1; }
|
||||
/* The per-cue boxes sit under the master switch, greyed and locked while it
|
||||
/* The Desktop app group exists only inside the app; elsewhere it stays hidden
|
||||
in spite of the grid above. */
|
||||
.looks-desktop[hidden] { display: none; }
|
||||
/* The per-cue boxes sit under the master switch, grayed and locked while it
|
||||
is off rather than hidden, so the picks stay visible. */
|
||||
.looks-sound-events { display: grid; gap: 8px; }
|
||||
.looks-sound-events.is-off { opacity: 0.45; }
|
||||
|
||||
Reference in new issue
Block a user