mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Sync upstream web console updates into v2.5.0: a Subagents switch that tells the agent to use helpers (per project and skill, sent as a standing instruction only when it changes), a Subagents tab listing the helpers the agent reports, a standalone review that asks what to review instead of assuming the branch diff, a refusal for doc patches that move a version backwards, and the project name in the footer and browser tab title
This commit is contained in:
1 parent
57134cf36e
commit
977e462e76
179 files changed
+14955
-466
No files matched your search
@@ -208,6 +208,26 @@ body {
|
||||
.stop-btn:hover:not(:disabled) { color: var(--warn); border-color: var(--warn); }
|
||||
.brief-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent-line); }
|
||||
|
||||
/* Subagents: an orchestrator and its helpers. Unlit is a hollow outline in
|
||||
the quiet ink; lit fills the nodes with the highlight color. */
|
||||
.subagents-btn { border-color: var(--rule-2); color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; }
|
||||
.btn.subagents-btn { padding: 0 6px; align-self: stretch; }
|
||||
.subagents-btn[hidden] { display: none; }
|
||||
.subagents-btn svg { width: 16px; height: 16px; display: block; }
|
||||
.subagents-btn .sa-link { fill: none; stroke: var(--ink-2); stroke-width: 1.2; stroke-linecap: round; }
|
||||
.subagents-btn .sa-hub { fill: none; stroke: var(--ink-2); stroke-width: 1.4; }
|
||||
.subagents-btn .sa-node { fill: none; stroke: var(--ink-2); stroke-width: 1.2; }
|
||||
.subagents-btn[aria-pressed="true"] .sa-hub,
|
||||
.subagents-btn[aria-pressed="true"] .sa-node { fill: var(--accent); stroke: var(--accent); }
|
||||
.subagents-btn[aria-pressed="true"] .sa-link { stroke: var(--accent); }
|
||||
.subagents-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent-line); }
|
||||
.subagents-btn:hover:not(:disabled) .sa-link,
|
||||
.subagents-btn:hover:not(:disabled) .sa-hub,
|
||||
.subagents-btn:hover:not(:disabled) .sa-node { stroke: var(--accent); }
|
||||
.subagents-btn:disabled .sa-link,
|
||||
.subagents-btn:disabled .sa-hub,
|
||||
.subagents-btn:disabled .sa-node { stroke: var(--ink-3); fill: none; }
|
||||
|
||||
.ident { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
|
||||
|
||||
/* The session meter: a ring that fills with the points and a few words, in
|
||||
@@ -1430,6 +1450,30 @@ h1 {
|
||||
.pill.done { background: var(--ok-soft); color: var(--ok); }
|
||||
.pill.staged { background: var(--stage-soft); color: var(--stage); }
|
||||
|
||||
/* The Subagents tab: one row per reported helper, newest state in a pill. */
|
||||
.sa-card h2 { margin: 0 0 6px; }
|
||||
.sa-card > .help { margin: 0 0 16px; }
|
||||
.sa-alone { margin: 0; color: var(--ink-2); }
|
||||
.sa-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
|
||||
.sa-row { border: 1px solid var(--rule); border-radius: 8px; background: var(--panel-2); padding: 12px 14px; }
|
||||
.sa-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
|
||||
.sa-title { min-width: 0; overflow-wrap: anywhere; }
|
||||
.sa-ask {
|
||||
margin: 4px 0 0; color: var(--ink-2); font-size: 13.5px;
|
||||
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
|
||||
}
|
||||
.sa-result { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--rule); font-size: 13.5px; }
|
||||
.sa-pill { display: inline-flex; align-items: center; gap: 6px; flex: none; }
|
||||
.sa-pill.is-running { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
|
||||
.sa-pill.is-done { background: var(--ok-soft); color: var(--ok); }
|
||||
.sa-pill.is-failed { background: var(--warn-soft); color: var(--warn); }
|
||||
.sa-pill .spinner.tiny { width: 10px; height: 10px; }
|
||||
/* The dialog's number box, themed like the page's other inputs. */
|
||||
.subagents input[type="number"] {
|
||||
width: 5em; font: inherit; color: var(--ink); background: var(--panel-2);
|
||||
border: 1px solid var(--rule-2); border-radius: 6px; padding: 4px 8px;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------ settled answer */
|
||||
|
||||
.answered {
|
||||
@@ -1971,6 +2015,8 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
|
||||
cursor: pointer;
|
||||
}
|
||||
.footer-where:hover { text-decoration: underline; }
|
||||
/* The project name, in the person's highlight color. */
|
||||
.where-project { color: var(--accent); font-weight: 600; }
|
||||
/* A folder is missing or the agent could not read one: the dialog says which. */
|
||||
.where-alert {
|
||||
display: inline-block; width: 7px; height: 7px; margin-left: 6px;
|
||||
|
||||
@@ -103,6 +103,15 @@ import { FOOTER_TIERS, footerLabel, nameProblem } from "./workspace.js";
|
||||
import { RED_BANNER } from "./meter.js";
|
||||
import { applyMention, matchNames, mentionAt } from "./mentions.js";
|
||||
import { faviconState, setFavicon } from "./favicon.js";
|
||||
import {
|
||||
CHECKIN_LINE,
|
||||
PATHFINDER_RESEARCH_LINE,
|
||||
defaultInstruction,
|
||||
helperRows,
|
||||
showSwitch,
|
||||
showTab,
|
||||
switchLabel,
|
||||
} from "./subagents.js";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
@@ -530,6 +539,9 @@ let meterFrame = null;
|
||||
// The frame's update ({ installed, latest }), present only when a newer
|
||||
// release is out; null otherwise.
|
||||
let updateFrame = null;
|
||||
// The frame's Subagents switch ({ offered, supported, on, instruction, max,
|
||||
// revision }), or null before a server that sends it.
|
||||
let subagentsFrame = null;
|
||||
let chatDot = false;
|
||||
let chatSending = false;
|
||||
let chatResetting = false;
|
||||
@@ -880,6 +892,8 @@ function adopt(body) {
|
||||
if (body.meter) meterFrame = body.meter;
|
||||
// Always replaced: an absent key means no update.
|
||||
updateFrame = body.update || null;
|
||||
// Always replaced too: an older server sends none, and then there is no switch.
|
||||
subagentsFrame = body.subagents || null;
|
||||
lastContact = Date.now();
|
||||
if (gone) {
|
||||
gone = false;
|
||||
@@ -1301,6 +1315,7 @@ function render() {
|
||||
renderChrome();
|
||||
renderStatus();
|
||||
renderBriefButton();
|
||||
renderSubagentsButton();
|
||||
renderStopButton();
|
||||
renderHomeButton();
|
||||
tabAdded = renderViews();
|
||||
@@ -1566,7 +1581,7 @@ function renderChrome() {
|
||||
renderMeter();
|
||||
$("title").textContent = S.title || "Session";
|
||||
$("badge").textContent = workflowLabel(S.workflow);
|
||||
document.title = (S.title || "Session") + " · #" + String(S.sid || "").slice(-6) + " · Plan2Code";
|
||||
renderTabTitle();
|
||||
|
||||
const h = S.headline || {};
|
||||
// On a finished session an open item is frozen: the send on it counts as
|
||||
@@ -1835,6 +1850,69 @@ function renderBriefButton() {
|
||||
if (offer) btn.disabled = gone || pendingResult;
|
||||
}
|
||||
|
||||
// Shown only where the skill opts in and the agent's console copy can deliver
|
||||
// it. Lit while helpers are on; a click opens the dialog, never toggles.
|
||||
function renderSubagentsButton() {
|
||||
const btn = $("btn-subagents");
|
||||
const offer = showSwitch(subagentsFrame);
|
||||
btn.hidden = !offer;
|
||||
if (!offer) return;
|
||||
const label = switchLabel(subagentsFrame);
|
||||
btn.setAttribute("aria-pressed", String(Boolean(subagentsFrame.on)));
|
||||
btn.title = label;
|
||||
btn.setAttribute("aria-label", label);
|
||||
btn.disabled = gone;
|
||||
}
|
||||
|
||||
// The Subagents dialog, filled from the frame each time it opens. A null
|
||||
// instruction is the shipped default, shown as its text so it can be edited.
|
||||
function openSubagents() {
|
||||
if (!showSwitch(subagentsFrame)) return;
|
||||
const on = Boolean(subagentsFrame.on);
|
||||
for (const radio of document.querySelectorAll('input[name="subagents-on"]')) {
|
||||
radio.checked = radio.value === (on ? "on" : "off");
|
||||
}
|
||||
$("subagents-instruction").value = subagentsFrame.instruction ?? defaultInstruction(S.workflow);
|
||||
$("subagents-max").value = String(subagentsFrame.max);
|
||||
$("subagents-checkin").textContent = CHECKIN_LINE;
|
||||
const research = $("subagents-research");
|
||||
research.textContent = PATHFINDER_RESEARCH_LINE;
|
||||
research.hidden = S.workflow !== "pathfinder";
|
||||
$("subagents-status").textContent = "";
|
||||
$("subagents-save").disabled = false;
|
||||
$("subagents-modal").showModal();
|
||||
const checked = document.querySelector('input[name="subagents-on"]:checked');
|
||||
if (checked) checked.focus();
|
||||
}
|
||||
|
||||
const SUBAGENTS_ERRORS = {
|
||||
max: "Pick a number from 1 to 20.",
|
||||
"too-long": "The instruction is over 2,000 characters.",
|
||||
"not-offered": "This skill doesn't use helpers.",
|
||||
bad: "That didn't save. Try again.",
|
||||
};
|
||||
const SUBAGENTS_LOST = "Lost contact with Plan2Code. Try again once it's back.";
|
||||
|
||||
async function saveSubagents() {
|
||||
const save = $("subagents-save");
|
||||
const status = $("subagents-status");
|
||||
const picked = document.querySelector('input[name="subagents-on"]:checked');
|
||||
const text = $("subagents-instruction").value.trim();
|
||||
// The shipped default is stored as null, so a later release's wording
|
||||
// reaches everyone who never changed it.
|
||||
const instruction = text === defaultInstruction(S.workflow) ? null : text;
|
||||
const body = { on: Boolean(picked && picked.value === "on"), instruction, max: Number($("subagents-max").value) };
|
||||
save.disabled = true;
|
||||
status.textContent = "";
|
||||
const res = await postJson("/subagents", body);
|
||||
save.disabled = false;
|
||||
// The next state frame redraws the button.
|
||||
if (res.status === 200) return $("subagents-modal").close();
|
||||
if (res.status === 400) status.textContent = SUBAGENTS_ERRORS[res.body && res.body.error] || SUBAGENTS_ERRORS.bad;
|
||||
else if (res.status === 403 || res.status === 0) status.textContent = SUBAGENTS_LOST;
|
||||
else status.textContent = SUBAGENTS_ERRORS.bad;
|
||||
}
|
||||
|
||||
function renderViews() {
|
||||
const nav = $("views");
|
||||
nav.replaceChildren();
|
||||
@@ -1850,6 +1928,14 @@ function renderViews() {
|
||||
if (hasOverview) tabs.push({ id: "overview", label: "Overview", count: 0 });
|
||||
else if (view === "overview") view = "questions";
|
||||
for (const d of docs()) tabs.push({ id: "doc:" + d.id, label: d.title || "Document", count: 0 });
|
||||
// The helpers the agent reported, from the first one on; cleared by a
|
||||
// dashboard hop, which sends the person home like the Overview tab does.
|
||||
if (showTab(subagentsFrame, S.helpers)) {
|
||||
// From the rows the tab draws, so the badge never counts helpers the
|
||||
// working-alone note hides.
|
||||
const running = helperRows(S.helpers).rows.filter((r) => r.state === "running").length;
|
||||
tabs.push({ id: "subagents", label: "Subagents", count: running });
|
||||
} else if (view === "subagents") view = "questions";
|
||||
// Always last, on every workflow and after a finish: the Quick question chat.
|
||||
// The ring left of "Ask" shows exactly when the conversation's own ring does:
|
||||
// a question the agent picked up and has not answered yet.
|
||||
@@ -2130,6 +2216,7 @@ function paintMain(main) {
|
||||
if (view.startsWith("doc:")) return renderDoc(main, view.slice(4));
|
||||
if (view === "overview") return renderOverview(main);
|
||||
if (view === "ask") return renderAsk(main);
|
||||
if (view === "subagents") return renderSubagents(main);
|
||||
|
||||
// The session's own page, reached from the PAUSED / SESSION ENDED item at
|
||||
// the top of the rail. The hand-off lives here alone now, rather than
|
||||
@@ -4774,6 +4861,42 @@ function renderOverview(main) {
|
||||
main.appendChild(box);
|
||||
}
|
||||
|
||||
// The helpers the agent reported, as it last posted them. Everything here is
|
||||
// the agent's text, so it goes in as text, never as markup.
|
||||
function renderSubagents(main) {
|
||||
const card = el("section", "card sa-card");
|
||||
card.appendChild(el("h2", null, "Subagents"));
|
||||
card.appendChild(el("p", "help", CHECKIN_LINE));
|
||||
const { alone, rows } = helperRows(S.helpers);
|
||||
if (alone) {
|
||||
card.appendChild(
|
||||
el("p", "sa-alone", "Working alone: your agent has no way to start helpers here, so it is doing this skill's work itself.")
|
||||
);
|
||||
main.appendChild(card);
|
||||
return;
|
||||
}
|
||||
const list = el("ul", "sa-list");
|
||||
for (const row of rows) {
|
||||
const item = el("li", "sa-row");
|
||||
const head = el("div", "sa-head");
|
||||
head.appendChild(el("strong", "sa-title", row.title));
|
||||
const pill = el("span", "pill sa-pill is-" + row.state);
|
||||
if (row.state === "running") {
|
||||
const spin = el("span", "spinner tiny");
|
||||
spin.setAttribute("aria-hidden", "true");
|
||||
pill.appendChild(spin);
|
||||
}
|
||||
pill.appendChild(document.createTextNode(row.stateLabel));
|
||||
head.appendChild(pill);
|
||||
item.appendChild(head);
|
||||
item.appendChild(el("p", "sa-ask", row.ask));
|
||||
if (row.result) item.appendChild(el("p", "sa-result", row.result));
|
||||
list.appendChild(item);
|
||||
}
|
||||
card.appendChild(list);
|
||||
main.appendChild(card);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- ask */
|
||||
|
||||
// The frame's chat block, with `offline` worked out now rather than when the
|
||||
@@ -5956,10 +6079,30 @@ const workspaceFolders = () => (wsFrame && Array.isArray(wsFrame.folders) ? wsFr
|
||||
// session opened before the server wrote `worktree` has nothing to show, so
|
||||
// the slot stays hidden. The footer renders on every tick, so the DOM is only
|
||||
// touched when the labels change, or when a resize clears the key.
|
||||
// The project's name: the workspace's original folder, or the session's
|
||||
// worktree folder before a frame carries the workspace.
|
||||
function projectName() {
|
||||
const folders = workspaceFolders();
|
||||
if (folders.length && folders[0].name) return folders[0].name;
|
||||
const path = (S && S.worktree) || "";
|
||||
return path ? path.split(/[\\/]/).filter(Boolean).pop() || path : "";
|
||||
}
|
||||
|
||||
// The browser tab's title, led by the project so tabs from different
|
||||
// projects are told apart. Called from the chrome and the footer, since the
|
||||
// workspace frame can arrive after either.
|
||||
function renderTabTitle() {
|
||||
if (!S) return;
|
||||
const name = projectName();
|
||||
document.title =
|
||||
(name ? name + " · " : "") + (S.title || "Session") + " · #" + String(S.sid || "").slice(-6) + " · Plan2Code";
|
||||
}
|
||||
|
||||
function renderWhere() {
|
||||
const b = $("footer-where");
|
||||
const folders = workspaceFolders();
|
||||
const path = S.worktree || "";
|
||||
renderTabTitle();
|
||||
const alert = Boolean(folders.length && ((wsFrame.missing || []).length || (wsFrame.issues || []).length));
|
||||
const labels = folders.length
|
||||
? Array.from({ length: FOOTER_TIERS }, (_, tier) => footerLabel({ folders, branch: S.branch }, tier))
|
||||
@@ -5972,7 +6115,16 @@ function renderWhere() {
|
||||
let label = labels[0];
|
||||
for (const text of labels) {
|
||||
label = text;
|
||||
b.textContent = text;
|
||||
// The project name takes the highlight color, so several consoles side by
|
||||
// side tell apart at a glance; the rest of the label stays quiet.
|
||||
const name = projectName();
|
||||
b.textContent = "";
|
||||
if (name && text.startsWith(name)) {
|
||||
b.appendChild(el("span", "where-project", name));
|
||||
b.appendChild(document.createTextNode(text.slice(name.length)));
|
||||
} else {
|
||||
b.textContent = text;
|
||||
}
|
||||
if (alert) {
|
||||
const dot = el("span", "where-alert");
|
||||
dot.setAttribute("aria-hidden", "true");
|
||||
@@ -7197,6 +7349,7 @@ function lightDismiss(dlg) {
|
||||
});
|
||||
}
|
||||
lightDismiss($("looks-modal"));
|
||||
lightDismiss($("subagents-modal"));
|
||||
lightDismiss($("help-modal"));
|
||||
lightDismiss($("workspace-modal"));
|
||||
lightDismiss($("welcome-modal"));
|
||||
@@ -7499,6 +7652,13 @@ $("cleanup-scan").addEventListener("click", scanCleanup);
|
||||
$("cleanup-delete").addEventListener("click", deleteCleanup);
|
||||
|
||||
$("btn-brief").addEventListener("click", openBrief);
|
||||
$("btn-subagents").addEventListener("click", openSubagents);
|
||||
$("subagents-default").addEventListener("click", () => {
|
||||
$("subagents-instruction").value = defaultInstruction(S.workflow);
|
||||
});
|
||||
$("subagents-save").addEventListener("click", saveSubagents);
|
||||
$("subagents-cancel").addEventListener("click", () => $("subagents-modal").close());
|
||||
$("subagents-modal").addEventListener("close", () => $("btn-subagents").focus());
|
||||
$("brief-cancel").addEventListener("click", () => $("brief-modal").close());
|
||||
$("brief-go").addEventListener("click", sendBrief);
|
||||
for (const radio of document.querySelectorAll('input[name="brief-range"]')) {
|
||||
|
||||
@@ -19,6 +19,7 @@ export const HELP_TABS = Object.freeze([
|
||||
tab("dashboard", "The dashboard", true),
|
||||
tab("meter", "Session meter", false),
|
||||
tab("build", "Watching a build", false),
|
||||
tab("subagents", "Helpers (subagents)", false),
|
||||
tab("ask", "Ask a quick question", false),
|
||||
tab("finishing", "Stopping and finishing", false),
|
||||
tab("stuck", "When something looks stuck", true),
|
||||
@@ -39,6 +40,7 @@ export function helpTabFor({ view, dashboard, gone, adrift, finished, workflow,
|
||||
if (gone || adrift) return "stuck";
|
||||
if (workspace) return "workspace";
|
||||
if (v === "ask") return "ask";
|
||||
if (v === "subagents") return "subagents";
|
||||
if (dashboard && meterRed) return "meter";
|
||||
if (dashboard) return "dashboard";
|
||||
if (v === "overview" || v.startsWith("doc:")) return "docs";
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<link rel="modulepreload" href="/starters.js" />
|
||||
<link rel="modulepreload" href="/workspace.js" />
|
||||
<link rel="modulepreload" href="/meter.js" />
|
||||
<link rel="modulepreload" href="/subagents.js" />
|
||||
<link rel="modulepreload" href="/mentions.js" />
|
||||
<link rel="modulepreload" href="/favicon.js" />
|
||||
<link rel="modulepreload" href="/vendor/marked.esm.js" />
|
||||
@@ -172,6 +173,18 @@
|
||||
<button type="button" class="btn ghost small brief-btn" id="btn-brief" hidden>
|
||||
Write a brief
|
||||
</button>
|
||||
<!-- Subagents: opted-in skills only. Lit while helpers are on; a click
|
||||
opens the Subagents dialog and never toggles them itself. -->
|
||||
<button type="button" class="btn ghost small subagents-btn" id="btn-subagents" aria-pressed="false" hidden>
|
||||
<!-- An orchestrator and its helpers: one larger node linked to three smaller ones. -->
|
||||
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
||||
<path class="sa-link" d="M6.9 6.6L10.9 3.9M7.4 8h3.5M6.9 9.4l4 2.7" />
|
||||
<circle cx="4.6" cy="8" r="2.6" class="sa-hub" />
|
||||
<circle cx="12.4" cy="3" r="1.5" class="sa-node" />
|
||||
<circle cx="12.4" cy="8" r="1.5" class="sa-node" />
|
||||
<circle cx="12.4" cy="13" r="1.5" class="sa-node" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="views-group">
|
||||
<span class="views-arrow" aria-hidden="true">
|
||||
@@ -580,6 +593,13 @@
|
||||
<rect x="3" y="9" width="18" height="6" rx="3" />
|
||||
<path d="M6 12h7" />
|
||||
</symbol>
|
||||
<symbol id="hi-subagents" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="7" cy="12" r="3.5" />
|
||||
<circle cx="18" cy="5" r="2" />
|
||||
<circle cx="18" cy="12" r="2" />
|
||||
<circle cx="18" cy="19" r="2" />
|
||||
<path d="M10 10l6-4M10.5 12H16M10 14l6 4" />
|
||||
</symbol>
|
||||
<symbol id="hi-ask" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M4 5h16v11H10l-4 4v-4H4z" />
|
||||
<path d="M8 9.5h8M8 12.5h5" />
|
||||
@@ -1477,7 +1497,61 @@
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<!-- Tab 12: Ask a quick question -->
|
||||
<!-- Tab 12: Helpers (subagents) -->
|
||||
<section class="help-panel" data-tab="subagents">
|
||||
<h3>Helpers (subagents)</h3>
|
||||
<p>
|
||||
On a build, a review and Pathfinder, Plan2Code can hand independent
|
||||
pieces of work to helpers (subagents) while it keeps the conversation
|
||||
with you. The <strong>Subagents</strong> button in the top bar, after
|
||||
Stop session, is lit while helpers are on.
|
||||
</p>
|
||||
<h4>The switch</h4>
|
||||
<ul>
|
||||
<li>
|
||||
Clicking the button opens the <strong>Subagents</strong> dialog; it
|
||||
never switches helpers on or off by itself. Pick <strong>Use
|
||||
helpers</strong> or <strong>Work alone</strong>, edit the instruction
|
||||
Plan2Code follows (<strong>Reset to default</strong> puts the
|
||||
shipped one back), and say how many may run at once.
|
||||
</li>
|
||||
<li>
|
||||
It is off by default and saved for this project and this skill, so
|
||||
the next session of the same skill here starts the same way.
|
||||
</li>
|
||||
<li>
|
||||
The change reaches Plan2Code at its next check-in, as a setting,
|
||||
not as something you typed. How many helpers it can really start is
|
||||
up to your agent; some have no helpers at all.
|
||||
</li>
|
||||
<li>The button only appears on skills that use helpers, and only when Plan2Code can pass the setting on.</li>
|
||||
</ul>
|
||||
<h4>The Subagents tab</h4>
|
||||
<ul>
|
||||
<li>
|
||||
With the first helper, a <strong>Subagents</strong> tab appears before
|
||||
Ask: one row each, with what it was asked, whether it is running, done
|
||||
or failed, and a one-line result at the end. The number on the tab is
|
||||
how many are still running.
|
||||
</li>
|
||||
<li>
|
||||
Helpers report through Plan2Code, so the rows change at its
|
||||
check-ins, not live. The page cannot stop a helper; ask Plan2Code
|
||||
on the Ask tab if one should stop.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Working alone</strong> means your agent has no way to start
|
||||
helpers here, so it is doing the work itself.
|
||||
</li>
|
||||
<li>
|
||||
Pathfinder always uses helpers for its research questions, whatever
|
||||
the switch says, and they show here too.
|
||||
</li>
|
||||
<li>The tab clears when you go back to the dashboard.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- Tab 13: Ask a quick question -->
|
||||
<section class="help-panel" data-tab="ask">
|
||||
<h3>Ask a quick question</h3>
|
||||
<p class="help-lead">
|
||||
@@ -1568,7 +1642,7 @@
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<!-- Tab 13: Stopping and finishing -->
|
||||
<!-- Tab 14: Stopping and finishing -->
|
||||
<section class="help-panel" data-tab="finishing">
|
||||
<h3>Stopping and finishing</h3>
|
||||
<p class="help-lead">
|
||||
@@ -1650,7 +1724,7 @@
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<!-- Tab 14: When something looks stuck -->
|
||||
<!-- Tab 15: When something looks stuck -->
|
||||
<section class="help-panel" data-tab="stuck">
|
||||
<h3>When something looks stuck</h3>
|
||||
<p class="help-lead">
|
||||
@@ -1772,7 +1846,7 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Tab 15: Keyboard and preferences -->
|
||||
<!-- Tab 16: Keyboard and preferences -->
|
||||
<section class="help-panel" data-tab="prefs">
|
||||
<h3>Keyboard and preferences</h3>
|
||||
<p class="help-lead">
|
||||
@@ -1888,7 +1962,7 @@
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- Tab 16: Privacy and where things are saved -->
|
||||
<!-- Tab 17: Privacy and where things are saved -->
|
||||
<section class="help-panel" data-tab="privacy">
|
||||
<h3>Privacy and where things are saved</h3>
|
||||
<p class="help-lead">
|
||||
@@ -1925,7 +1999,11 @@
|
||||
</li>
|
||||
<li>
|
||||
your role, theme, colors, card width and sounds, in
|
||||
<code>looks.json</code>.
|
||||
<code>looks.json</code>;
|
||||
</li>
|
||||
<li>
|
||||
your Subagents switch for each project and skill, in
|
||||
<code>subagents.json</code>.
|
||||
</li>
|
||||
</ul>
|
||||
<p>
|
||||
@@ -2039,6 +2117,46 @@
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- Subagents: the switch for this skill, filled from the frame's
|
||||
`subagents` by app.js and saved through POST /subagents. It borrows
|
||||
the User Preferences dialog's classes, so it needs no dialog styles of
|
||||
its own, only a themed number box. -->
|
||||
<dialog class="modal looks subagents" id="subagents-modal" aria-labelledby="subagents-title">
|
||||
<h2 id="subagents-title">Subagents</h2>
|
||||
<p class="modal-blurb">
|
||||
Let Plan2Code hand independent work to helpers in this skill. Saved for this
|
||||
project and this skill.
|
||||
</p>
|
||||
<fieldset class="modal-ranges looks-row">
|
||||
<legend>Helpers</legend>
|
||||
<label><input type="radio" name="subagents-on" value="on" /> <span>Use helpers</span></label>
|
||||
<label><input type="radio" name="subagents-on" value="off" checked /> <span>Work alone</span></label>
|
||||
</fieldset>
|
||||
<fieldset class="modal-ranges">
|
||||
<legend>Instruction</legend>
|
||||
<textarea id="subagents-instruction" rows="4" maxlength="2000" aria-label="Instruction"></textarea>
|
||||
<div class="models-actions">
|
||||
<button type="button" class="btn small ghost" id="subagents-default">Reset to default</button>
|
||||
<span class="help">Passed to the agent as written, at its next check-in.</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset class="modal-ranges">
|
||||
<legend>At most</legend>
|
||||
<label>
|
||||
<input type="number" id="subagents-max" min="1" max="20" step="1" aria-label="At most this many helpers at once" />
|
||||
<span>helpers at once</span>
|
||||
</label>
|
||||
<p class="help">Advisory: your agent's own limit still applies.</p>
|
||||
</fieldset>
|
||||
<p class="help" id="subagents-checkin"></p>
|
||||
<p class="help" id="subagents-research" hidden></p>
|
||||
<p class="help" id="subagents-status" role="status"></p>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn ghost" id="subagents-cancel">Cancel</button>
|
||||
<button type="button" class="btn primary" id="subagents-save">Save</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- The Workspace: the folder this session started in plus any added as
|
||||
context. The list is drawn by app.js from the frame's `workspace`;
|
||||
every change goes through the server's /workspace routes. -->
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
// Plan2Code Web Console - the Subagents switch's opt-in table, wording and checks.
|
||||
//
|
||||
// The source of truth for which workflows offer the switch, the instruction
|
||||
// each one ships with, the fixed frame every "on" block carries, the exact
|
||||
// lines the agent reads at a pickup (blockFor()), and the house rules for the
|
||||
// helpers an agent reports back (checkHelper()). No DOM access at module scope
|
||||
// and no imports: the server, console.mjs, the page and `node --test` all
|
||||
// import this file.
|
||||
|
||||
// The one place a skill opts in (FR-1). Wording is behaviour-level and names
|
||||
// no harness tool, so any agent can follow it or harmlessly ignore it.
|
||||
export const SUBAGENT_WORKFLOWS = Object.freeze({
|
||||
implement: Object.freeze({
|
||||
instruction:
|
||||
"Hand independent tasks in a phase to helpers: tasks that touch different files and do not depend on each other. Keep tasks that share files, the phase's tests and the sign-off with you.",
|
||||
}),
|
||||
"implement-review": Object.freeze({
|
||||
instruction:
|
||||
"Hand independent tasks in a phase to helpers: tasks that touch different files and do not depend on each other. Keep tasks that share files, the phase's tests and the sign-off with you.",
|
||||
}),
|
||||
"quick-task": Object.freeze({
|
||||
instruction:
|
||||
"Use helpers for side lookups, such as reading unfamiliar code or checking documentation, while you make the change yourself.",
|
||||
}),
|
||||
review: Object.freeze({
|
||||
instruction:
|
||||
"Split the review across helpers by area (for example correctness, tests and security), then merge and de-duplicate their findings yourself before you report.",
|
||||
}),
|
||||
pathfinder: Object.freeze({
|
||||
instruction:
|
||||
"Use helpers for codebase recon, sketches and lookups beside the conversation. Keep every question for the person with you.",
|
||||
}),
|
||||
});
|
||||
|
||||
export function offered(workflow) {
|
||||
return typeof workflow === "string" && Object.prototype.hasOwnProperty.call(SUBAGENT_WORKFLOWS, workflow);
|
||||
}
|
||||
|
||||
export const MAX_MIN = 1;
|
||||
export const MAX_MAX = 20;
|
||||
export const DEFAULT_MAX = 3;
|
||||
export const INSTRUCTION_MAX_CHARS = 2000;
|
||||
export const HELPER_TITLE_MAX = 80;
|
||||
export const HELPER_ASK_MAX = 400;
|
||||
export const HELPER_RESULT_MAX = 200;
|
||||
export const HELPER_STATES = Object.freeze(["running", "done", "failed"]);
|
||||
|
||||
/* ------------------------------------------------------------- settings */
|
||||
|
||||
export function defaultInstruction(workflow) {
|
||||
return offered(workflow) ? SUBAGENT_WORKFLOWS[workflow].instruction : "";
|
||||
}
|
||||
|
||||
// The person's own text when they wrote some, else the workflow's default.
|
||||
export function effectiveInstruction(setting) {
|
||||
const own = setting && typeof setting.instruction === "string" ? setting.instruction.trim() : "";
|
||||
return own || defaultInstruction(setting && setting.workflow);
|
||||
}
|
||||
|
||||
export function defaultSetting(workflow) {
|
||||
return { workflow, on: false, instruction: null, max: DEFAULT_MAX };
|
||||
}
|
||||
|
||||
/**
|
||||
* `{ on, instruction, max }` from untrusted input, or `{ error }` naming the
|
||||
* field that failed: "bad" (wrong type), "too-long" (instruction) or "max".
|
||||
* Returns an error object rather than throwing, so the route and the store
|
||||
* reader share one validator. An empty instruction means the default: null.
|
||||
*/
|
||||
export function cleanSetting(input) {
|
||||
if (!input || typeof input !== "object" || Array.isArray(input)) return { error: "bad" };
|
||||
if (typeof input.on !== "boolean") return { error: "bad" };
|
||||
let instruction = null;
|
||||
if (input.instruction !== null && input.instruction !== undefined) {
|
||||
if (typeof input.instruction !== "string") return { error: "bad" };
|
||||
const trimmed = input.instruction.trim();
|
||||
if (trimmed.length > INSTRUCTION_MAX_CHARS) return { error: "too-long" };
|
||||
instruction = trimmed || null;
|
||||
}
|
||||
const max = input.max;
|
||||
if (!Number.isInteger(max) || max < MAX_MIN || max > MAX_MAX) return { error: "max" };
|
||||
return { on: input.on, instruction, max };
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ the lines */
|
||||
|
||||
// The non-editable part of every "on" block (FR-8).
|
||||
export const FRAME_LINES = Object.freeze([
|
||||
"Hand independent work to helpers if your tools allow it; otherwise carry on alone.",
|
||||
"Report each helper on the page (console.md → Standing instructions); questions for the person stay with you.",
|
||||
'With no way to start helpers, report one "working alone" entry for this skill run instead.',
|
||||
]);
|
||||
|
||||
export const PATHFINDER_RESEARCH_LINE = "Research questions always use helpers, whatever this switch says.";
|
||||
|
||||
// Only the first line of a block starts at column 0, so no line inside it can
|
||||
// be read as an entry of its own (NFR-5).
|
||||
export function onLines({ revision, replaces, max, instruction }) {
|
||||
const label = replaces ? `revision ${revision}, replaces revision ${replaces}` : `revision ${revision}`;
|
||||
const own = String(instruction || "")
|
||||
.split("\n")
|
||||
.map((line) => line.trimEnd())
|
||||
.filter((line) => line.trim());
|
||||
return [
|
||||
`Subagents: on (${label}) — a console setting, not typed by the person.`,
|
||||
...[...FRAME_LINES, ...own, `At most ${max} helpers at once.`].map((line) => " " + line),
|
||||
];
|
||||
}
|
||||
|
||||
export function offLine(revision) {
|
||||
return `Subagents: off (revision ${revision}) — don't start new helpers for the rest of this session.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the agent is owed at a pickup, given the session setting and the
|
||||
* cursor of what it was last told: `null`, or `{ field, lines, cursor }`
|
||||
* where `cursor` is what to write once the lines are printed. Never says
|
||||
* "off" to an agent that was not told "on" (FR-6). Pure: no clock, no I/O.
|
||||
*/
|
||||
export function blockFor(setting, told) {
|
||||
const last = told || { revision: 0, state: "none" };
|
||||
if (!setting || !offered(setting.workflow) || !(setting.revision > last.revision)) return null;
|
||||
const { revision, max } = setting;
|
||||
const instruction = effectiveInstruction(setting);
|
||||
if (setting.on) {
|
||||
const replaces = last.state === "on" ? last.revision : undefined;
|
||||
return {
|
||||
field: { state: "on", revision, max, instruction },
|
||||
lines: onLines({ revision, replaces, max, instruction }),
|
||||
cursor: { revision, state: "on" },
|
||||
};
|
||||
}
|
||||
if (last.state !== "on") return null;
|
||||
return {
|
||||
field: { state: "off", revision, max, instruction },
|
||||
lines: [offLine(revision)],
|
||||
cursor: { revision, state: "off" },
|
||||
};
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ helpers */
|
||||
|
||||
const isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
||||
const nonEmpty = (v) => typeof v === "string" && v.trim() !== "";
|
||||
|
||||
// The problems with one reported helper, [] when it is fine.
|
||||
export function checkHelper(entry) {
|
||||
if (!isPlainObject(entry)) return ["helper: each entry must be an object"];
|
||||
if (!nonEmpty(entry.id)) return ["helper: id must be a non-empty string"];
|
||||
const who = `helper "${entry.id}"`;
|
||||
if (entry.alone === true) return entry.id === "alone" ? [] : [`${who}: the working-alone entry must have id "alone"`];
|
||||
const problems = [];
|
||||
if (!nonEmpty(entry.title)) problems.push(`${who}: title must be a non-empty string`);
|
||||
else if (entry.title.length > HELPER_TITLE_MAX) problems.push(`${who}: title must be at most ${HELPER_TITLE_MAX} characters`);
|
||||
if (!nonEmpty(entry.ask)) problems.push(`${who}: ask must be a non-empty string`);
|
||||
else if (entry.ask.length > HELPER_ASK_MAX) problems.push(`${who}: ask must be at most ${HELPER_ASK_MAX} characters`);
|
||||
if (!HELPER_STATES.includes(entry.state)) problems.push(`${who}: state must be running, done or failed`);
|
||||
if (entry.result !== undefined) {
|
||||
if (typeof entry.result !== "string") problems.push(`${who}: result must be a string`);
|
||||
else if (entry.result.length > HELPER_RESULT_MAX) problems.push(`${who}: result must be at most ${HELPER_RESULT_MAX} characters`);
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
// The problems with a whole merged list.
|
||||
export function checkHelpers(list) {
|
||||
if (!Array.isArray(list)) return ["helpers must be an array"];
|
||||
const problems = [];
|
||||
const seen = new Set();
|
||||
let alone = 0;
|
||||
for (const entry of list) {
|
||||
if (isPlainObject(entry) && nonEmpty(entry.id)) {
|
||||
if (seen.has(entry.id)) problems.push(`helper "${entry.id}": duplicate id`);
|
||||
seen.add(entry.id);
|
||||
if (entry.alone === true && ++alone === 2) problems.push(`helper "${entry.id}": only one working-alone entry is allowed`);
|
||||
}
|
||||
problems.push(...checkHelper(entry));
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ the page */
|
||||
|
||||
// The page's rules for the button, the modal and the tab, kept here so they
|
||||
// are tested without a browser. `frame` is the state frame's `subagents`
|
||||
// block; app.js only renders what these say.
|
||||
|
||||
export const CHECKIN_LINE = "Helpers report through Plan2Code, so their progress shows here at its check-ins, not live.";
|
||||
|
||||
const STATE_LABELS = Object.freeze({ running: "Running", done: "Done", failed: "Failed" });
|
||||
|
||||
// The switch shows only where the skill opts in AND the agent's console copy
|
||||
// said it can deliver it (FR-3).
|
||||
export function showSwitch(frame) {
|
||||
return Boolean(frame && frame.offered && frame.supported);
|
||||
}
|
||||
|
||||
// The button's tooltip and accessible name (FR-2).
|
||||
export function switchLabel(frame) {
|
||||
return frame && frame.on ? "Subagents: on" : "Subagents: off";
|
||||
}
|
||||
|
||||
// What the Subagents tab draws: the working-alone note, or one row per helper
|
||||
// in the order the agent reported them. A result shows once the helper ended.
|
||||
export function helperRows(helpers) {
|
||||
const list = Array.isArray(helpers) ? helpers.filter(isPlainObject) : [];
|
||||
if (list.some((h) => h.alone === true)) return { alone: true, rows: [] };
|
||||
const rows = list.map(({ id, title, ask, state, result }) => ({
|
||||
id,
|
||||
title,
|
||||
ask,
|
||||
state,
|
||||
stateLabel: STATE_LABELS[state] || STATE_LABELS.running,
|
||||
...((state === "done" || state === "failed") && typeof result === "string" && result ? { result } : {}),
|
||||
}));
|
||||
return { alone: false, rows };
|
||||
}
|
||||
|
||||
// Never an empty tab. Independent of on / off, so Pathfinder's research
|
||||
// helpers show even with the switch off (FR-11, FR-12).
|
||||
export function showTab(frame, helpers) {
|
||||
return showSwitch(frame) && Array.isArray(helpers) && helpers.length > 0;
|
||||
}
|
||||
Reference in new issue
Block a user