Sync upstream into v2.8.0: the git board splits into Changes, Branches and Sync tabs that open on the next step (ticket-free)

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-14 20:03:09 -07:00
1 parent 7e2c824d4f
commit fdf43b197f
22 files changed
+2556 -803

No files matched your search

+1 -1
View File
@@ -686,7 +686,7 @@ export const SKILL_CATALOG = [
group: "extra",
chip: "Utility",
title: "Handoff",
blurb: "Pack this conversation into a document a fresh session can pick up cold.",
blurb: "Pack the current session into a document a fresh session can pick up cold.",
about:
"Writes down everything a new session would need, as a single document: what was decided, what is done, what is left. Use it when a conversation got long, a machine changed, or tomorrow-you deserves the context today-you has.",
},
+113 -29
View File
@@ -959,8 +959,8 @@ h1 {
}
/* The column itself never scrolls; the card does. The git board is the one
exception, below: it stacks a card over the board, so the column takes the
scroll there and both flow through it at natural height. */
exception, below: its card sits in the board's card slot, so the column
takes the scroll there and card and board flow through it at natural height. */
.main > .card:not(.is-primary) { flex-shrink: 100; min-height: 104px; }
.main > .card.is-primary { flex-shrink: 1; min-height: 0; }
/* A card with a growing answer box takes the column's full height above the
@@ -3652,9 +3652,9 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
/* ------------------------------------------------------------ git board */
/* The git workflow's main column stacks two things where every other view
holds one: the agent's card on top and the board under it. Stacked children
that each scrolled would put a scrollbar inside a scrollbar, so here the
/* The git workflow's main column holds the board, and the agent's card sits
inside it, in the card slot under the tab strip. A card that scrolled inside
a scrolling board would put a scrollbar inside a scrollbar, so here the
column takes the one scroll and both flow through it at natural height. */
.main:has(> .git-board) {
overflow-y: auto;
@@ -3664,17 +3664,17 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
/* Listed with .is-primary.has-grow too: that rule (a card with a growing note
box takes the column's height and shrinks into it) outranks a plain .card
here, and a card shrunk under the board spilled its buttons beneath it. */
.main:has(> .git-board) > .card,
.main:has(> .git-board) > .card.is-primary.has-grow,
.git-cards > .card,
.git-cards > .card.is-primary.has-grow,
.main:has(> .git-board) > .git-board {
flex: none;
overflow-y: visible;
min-height: 0;
}
/* Over the board a card's boxes cannot fill the column (it flows, it does not
stretch), so a note box grows with what is typed instead, where the browser
can, rather than scrolling inside a 96px box. */
.main:has(> .git-board) > .card textarea { field-sizing: content; max-height: 50vh; }
/* In the board's card slot a card's boxes cannot fill the column (it flows,
it does not stretch), so a note box grows with what is typed instead, where
the browser can, rather than scrolling inside a 96px box. */
.git-cards > .card textarea { field-sizing: content; max-height: 50vh; }
.main > .git-board {
padding-right: 32px;
display: grid;
@@ -3684,8 +3684,98 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
gap: 14px;
max-width: var(--card-width);
}
/* The board's header is a section lead, not a second card: the agent's card
above is the column's only framed element. */
/* The board is sized by its column, not the window: the narrow layout keys
off the board's own width. */
.git-board { container-type: inline-size; container-name: git-board; }
/* Plan2Code's card, between the tab strip and the tab's content. */
.git-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.git-cards:empty { display: none; }
/* The tab strip: three tabs, Done with git on the right. */
.git-tab-bar {
display: flex;
align-items: flex-end;
gap: 8px;
border-bottom: 1px solid var(--rule);
}
.git-tabs { display: flex; gap: 2px; }
.git-tab {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 8px 14px;
border: 0;
border-bottom: 3px solid transparent;
border-radius: 6px 6px 0 0;
background: transparent;
color: var(--ink-2);
font: inherit;
font-size: 14px;
cursor: pointer;
}
.git-tab:hover { background: var(--panel-2); color: var(--ink); }
.git-tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.git-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.git-tab-badge {
min-width: 18px;
padding: 0 6px;
border: 1px solid var(--rule-2);
border-radius: 999px;
font-family: var(--mono);
font-size: 11.5px;
line-height: 17px;
text-align: center;
color: var(--ink-2);
}
.git-tab-badge.is-dot { min-width: 0; font-weight: 700; }
.git-tab-badge.is-warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn); }
.git-tab-badge.is-next { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.git-tab-badge.is-warn.is-next { color: var(--accent-ink); background: var(--warn); border-color: var(--warn); }
.git-done { margin: 0 0 6px auto; }
/* The next step: one primary button, at most one quieter one. */
.git-step {
display: grid;
gap: 6px;
padding: 14px 18px;
background: var(--panel);
border: 1px solid var(--accent-line);
border-left-width: 4px;
border-radius: var(--radius);
}
.git-step.is-warn { border-color: var(--stage); background: var(--stage-soft); }
.git-step.is-calm { border-color: var(--ok); background: var(--ok-soft); }
.git-step-kicker { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }
.git-step.is-calm .git-step-kicker { color: var(--ok); }
.git-step-title, .git-op-title { margin: 0; font: 600 18px/1.25 var(--serif); }
.git-step-why, .git-step-label { margin: 0; font-size: 14px; color: var(--ink-2); }
.git-step-label { font-weight: 600; color: var(--ink); }
.git-step-actions, .git-sync-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.git-hint {
justify-self: start;
padding: 8px 12px;
border: 1px dashed var(--accent-line);
border-radius: var(--radius);
background: transparent;
color: var(--accent);
font: inherit;
font-size: 14px;
cursor: pointer;
}
.git-hint:hover { background: var(--accent-soft); }
.git-hint:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.git-stale { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; font-size: 13.5px; color: var(--stage); }
.git-held { font-size: 13.5px; color: var(--ink-2); }
.git-held .md-p { margin: 0; }
.git-wait { margin: 0; font-size: 13.5px; color: var(--stage); }
.git-fresh { margin: 0; font-size: 13px; color: var(--ink-3); }
.git-fresh.is-stale { color: var(--stage); }
.git-panel-tab { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.git-changes, .git-sync { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.git-sweep-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; font-size: 14px; color: var(--ink-2); }
.git-pr-open.is-disabled { opacity: 0.5; cursor: not-allowed; }
/* The board's header is a section lead, not a card: the framed elements are
the agent's card in the slot and the next step under it. */
.git-head {
display: grid;
gap: 6px;
@@ -3735,22 +3825,6 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
.git-result-body .md-p { margin: 4px 0 0; }
/* The result box is the line length here: git's stderr runs the full width. */
.git-result-body.md { max-width: none; }
/* Pinned to the pane's bottom while the board scrolls past: the column is
the scroller on this view, and the bar is the board's last child, so
bottom: 0 holds it on screen until the board's end comes up to dock it.
Opaque so the table slips underneath, bordered so the seam reads. */
.git-bar {
position: sticky;
bottom: 0;
z-index: 6;
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 10px 0 8px;
background: var(--bg);
border-top: 1px solid var(--rule);
}
.git-done { margin-left: auto; }
.git-panel {
display: grid;
gap: 10px;
@@ -3811,3 +3885,13 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
.git-cell-actions .btn + .btn { margin-left: 6px; }
.git-remote-only summary { cursor: pointer; font-weight: 600; color: var(--ink-2); padding: 4px 0; }
.git-empty { margin: 0; font-size: 13.5px; color: var(--ink-3); }
/* Last on purpose: the narrow layout overrides the board rules above it. */
@container git-board (max-width: 720px) {
.git-tab-bar { flex-wrap: wrap; }
.git-tabs { flex-wrap: wrap; }
.git-done { margin: 0 0 6px; }
.git-head-meta { flex-direction: column; align-items: flex-start; }
.git-step-actions, .git-sync-actions, .git-op-actions, .git-panel-actions { flex-wrap: wrap; }
.git-step-actions .btn, .git-op-actions .btn { flex: 1 1 auto; }
}
File diff suppressed because it is too large. Load diff
+902
View File
@@ -0,0 +1,902 @@
// Plan2Code Web Console - the tabbed git board's drawing.
//
// drawGitBoard(ctx) builds the whole board -- header, tab strip, card slot,
// step strip and the Changes, Branches and Sync bodies -- from what
// git-board.js decides and what the host hands it. It decides nothing new:
// a rule belongs in git-board.js, a click goes out through ctx.on.
//
// No DOM access: every node comes from `ctx.h` (el, md, copyButton); the page
// and `node --test` both import this file. On what h.el returns, the view uses
// only: appendChild, append, replaceChildren, setAttribute, removeAttribute,
// addEventListener, classList.add/remove/toggle, and the properties
// className, id, type, value, checked, disabled, textContent, placeholder,
// title, open, href, target, rel, tabIndex. Text runs are h.el("span", null, text).
//
// Every button, input and select is made through control(), which greys it
// out whenever controlAllowed(mode, role) says no and stamps data-gate with
// its role; one disabled for a reason of the view's own also carries
// data-own. The guard test in scripts/test-web-console-git-board.mjs holds
// every control to that.
import {
BRANCH_TYPES,
GIT_TABS,
PR_HOST_LABELS,
boardActions,
boardPrLink,
cleanupGroups,
commitTicks,
composeBranchName,
controlAllowed,
createSources,
currentRow,
filterBranches,
foldRemote,
nameStatus,
orderBranches,
refreshedLine,
relativeAge,
} from "./git-board.js";
const OP_WORDS = { rebase: "A rebase", am: "A git am", merge: "A merge", "cherry-pick": "A cherry-pick", revert: "A revert" };
const TAB_IDS = new Set(GIT_TABS.map((t) => t.id));
const list = (v) => (Array.isArray(v) ? v : []);
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
const opName = (op) => (op === "am" ? "git am" : op || "operation");
/* ------------------------------------------------------------ the gate */
// The one way the view makes an interactive control. `disabled` is the view's
// own reason (mid-operation, nothing ticked, a name that is taken); the busy
// gate is applied on top of it, always.
function control(ctx, tag, className, label, { role = "action", onClick, onInput, onChange, disabled = false, title } = {}) {
const node = ctx.h.el(tag, className, label);
if (tag === "button") node.type = "button";
node.disabled = Boolean(disabled) || !controlAllowed(ctx.mode, role);
node.setAttribute("data-gate", role);
if (disabled) node.setAttribute("data-own", "true");
if (title) node.title = title;
if (onClick) node.addEventListener("click", onClick);
if (onInput) node.addEventListener("input", onInput);
if (onChange) node.addEventListener("change", onChange);
return node;
}
// A copy button is a control like any other: greyed while busy.
function copy(ctx, text, cls, codeEl) {
const b = ctx.h.copyButton(text, cls, codeEl);
b.setAttribute("data-gate", "action");
b.disabled = !controlAllowed(ctx.mode, "action");
return b;
}
// "Open pull request": a link while it can open, an inert look-alike while busy.
function prLink(ctx, url, cls = "btn small primary") {
const label = "Open pull request";
if (!controlAllowed(ctx.mode, "action")) {
const span = ctx.h.el("span", `${cls} git-pr-open is-disabled`, label);
span.setAttribute("aria-disabled", "true");
span.setAttribute("data-gate", "action");
return span;
}
const a = ctx.h.el("a", `${cls} git-pr-open`, label);
if (typeof url === "string" && /^https:\/\//i.test(url)) a.href = url;
a.target = "_blank";
a.rel = "noopener";
a.setAttribute("data-gate", "action");
return a;
}
/* ------------------------------------------------------------ the board */
/** The tab to draw: the remembered one when it is a real tab, else the one owning the next step. */
export function activeTab(ctx) {
const tab = ctx.board && ctx.board.tab;
return TAB_IDS.has(tab) ? tab : ctx.step.tab;
}
/**
* The whole board: `{ node, cardSlot }`. `node` is div.git-board holding the
* header, the result line, the tab strip, `cardSlot` (empty, for the host's
* cards) and the active tab's panel.
*/
export function drawGitBoard(ctx) {
const { git, h } = ctx;
const node = h.el("div", "git-board");
const cardSlot = h.el("div", "git-cards");
if (git.error) {
node.appendChild(cardSlot);
const warn = h.el("div", "git-warn", git.error);
warn.setAttribute("role", "alert");
node.appendChild(warn);
return { node, cardSlot };
}
if (git.repo === false) {
// "Above" only once there is a card above: before the agent's first post
// the slot is empty, and the note would point at nothing.
node.appendChild(cardSlot);
node.appendChild(
h.el(
"p",
"git-note",
ctx.hasCard
? "This folder is not a git repository yet, so there is no board. Plan2Code asks above what to do."
: "This folder is not a git repository yet, so there is no board. Plan2Code will ask what to do here in a moment."
)
);
return { node, cardSlot };
}
const tab = activeTab(ctx);
node.appendChild(header(ctx));
if (ctx.notice) node.appendChild(resultLine(ctx, ctx.notice));
node.appendChild(tabStrip(ctx, tab));
node.appendChild(cardSlot);
node.appendChild(tabPanel(ctx, tab));
return { node, cardSlot };
}
/* -------------------------------------------------------------- header */
function header(ctx) {
const { git, h } = ctx;
const head = git.head || {};
const remotes = list(git.remotes);
const cur = currentRow(git);
const box = h.el("header", "git-head");
const row = h.el("div", "git-head-row");
// Mid-rebase HEAD is detached, but the person is still on their branch.
const title = head.branch || (head.rebasing ? `${head.rebasing} · rebasing` : `Not on a branch (at ${head.detached || "an unknown commit"})`);
row.appendChild(h.el("h2", "git-branch", title));
if (head.branch) {
row.appendChild(
h.el("span", "git-track", head.upstream && head.gone ? "remote copy deleted" : head.upstream ? `↑${head.ahead || 0} ↓${head.behind || 0}` : "not published")
);
if (remotes.length > 1 && cur && cur.upstreamRemote) row.appendChild(h.el("span", "badge", cur.upstreamRemote));
}
box.appendChild(row);
const meta = h.el("div", "git-head-meta");
if (!remotes.length) {
meta.appendChild(h.el("span", "git-noremote", "No remote"));
const cmd = "git remote add origin <url>";
const code = h.el("code", "md-code", cmd);
meta.appendChild(code);
meta.appendChild(copy(ctx, cmd, "btn small", code));
} else meta.appendChild(h.el("span", "git-refreshed", refreshedLine(git, ctx.now)));
if (ctx.mode === "running" && ctx.activity) meta.appendChild(h.el("span", "git-activity", ctx.activity));
box.appendChild(meta);
return box;
}
function resultLine(ctx, notice) {
const box = ctx.h.el("div", "git-result");
box.setAttribute("role", "status");
if (notice.title) box.appendChild(ctx.h.el("strong", "git-result-title", notice.title));
if (notice.body) box.appendChild(ctx.h.md(notice.body, "md git-result-body"));
return box;
}
/* ----------------------------------------------------------- tab strip */
function tabStrip(ctx, active) {
const { h } = ctx;
const bar = h.el("div", "git-tab-bar");
const strip = h.el("div", "git-tabs");
strip.setAttribute("role", "tablist");
strip.setAttribute("aria-label", "Git board");
for (const t of GIT_TABS) {
const on = t.id === active;
const b = control(ctx, "button", "git-tab" + (on ? " is-active" : ""), null, { role: "nav", onClick: () => ctx.on.pickTab(t.id) });
b.setAttribute("role", "tab");
b.id = `git-tab-${t.id}`;
b.setAttribute("aria-controls", `git-panel-${t.id}`);
b.setAttribute("aria-selected", on ? "true" : "false");
b.tabIndex = on ? 0 : -1;
b.appendChild(h.el("span", "git-tab-label", t.label));
const badge = ctx.badges && ctx.badges[t.id];
if (badge) {
b.appendChild(h.el("span", `git-tab-badge is-${badge.kind}${badge.next ? " is-next" : ""}`, badge.text));
if (badge.label) b.setAttribute("aria-label", `${t.label}, ${badge.label}`);
}
strip.appendChild(b);
}
bar.appendChild(strip);
const done = control(ctx, "button", "btn small git-done", "Done with git", { role: "done", onClick: () => ctx.on.send("done") });
if (ctx.mode === "offline") done.title = ctx.offlineReason === "pending" ? "Your last click is still being picked up." : "Not connected right now.";
bar.appendChild(done);
return bar;
}
/* ---------------------------------------------------------- tab panels */
function tabPanel(ctx, id) {
const panel = ctx.h.el("section", "git-panel-tab");
panel.setAttribute("role", "tabpanel");
panel.id = `git-panel-${id}`;
panel.setAttribute("aria-labelledby", `git-tab-${id}`);
const strip = stepStrip(ctx, id);
if (strip) panel.appendChild(strip);
panel.appendChild(id === "changes" ? changesBody(ctx) : id === "branches" ? branchesBody(ctx) : syncBody(ctx));
return panel;
}
/* ---------------------------------------------------------- step strip */
// One step's click, as the board offers it.
function runStep(ctx, s) {
const { git, on } = ctx;
switch (s.op) {
case "commit":
return on.openPanel("commit");
case "create-commit":
return on.openPanel("create", { commit: true });
case "create":
return on.openPanel("create");
case "cleanup":
return on.openPanel("cleanup");
// No ignore op exists: the commit panel opens with nothing ticked and the
// held-back paths set to Add to .gitignore, and its button sends `commit`.
case "ignore":
return on.openPanel("commit", { ignore: list(s.files), ticks: [] });
case "fix":
return on.pickTab("sync");
case "publish": {
// Named only when there is one to name: with two or more, the agent's
// `plan publish` asks which.
const remotes = list(git.remotes);
return on.send("publish", remotes.length === 1 && remotes[0].name ? { remote: remotes[0].name } : {});
}
default:
return on.send(s.op, {}, { operation: git.inProgress });
}
}
function stepButton(ctx, s, cls) {
if (s.op === "pr") return prLink(ctx, s.url, cls);
return control(ctx, "button", cls, s.label, { onClick: () => runStep(ctx, s) });
}
function stepStrip(ctx, id) {
const { git, h, step } = ctx;
const p = step.primary;
if (id !== step.tab) {
if (!p) return null;
const where = GIT_TABS.find((t) => t.id === step.tab);
return control(ctx, "button", "git-hint", `Next step is on ${where ? where.label : step.tab}: ${p.label} →`, {
role: "nav",
onClick: () => ctx.on.pickTab(step.tab),
});
}
// Mid-operation, Sync's own block is the step (syncBody).
if (id === "sync" && git.inProgress) return null;
const box = h.el("div", "git-step" + (git.inProgress ? " is-warn" : "") + (p ? "" : " is-calm"));
box.appendChild(h.el("div", "git-step-kicker", p ? "Next step" : "Nothing to do"));
box.appendChild(h.el("h3", "git-step-title", p ? p.label : step.line));
if (p && p.why) box.appendChild(h.el("p", "git-step-why", p.why));
if (step.stale) box.appendChild(staleLine(ctx, step.stale));
if (step.held) {
const held = h.el("div", "git-held");
held.appendChild(h.md(step.held, "md git-held-body"));
box.appendChild(held);
}
if (ctx.mode === "running") {
box.appendChild(h.el("p", "git-activity", ctx.activity || "Plan2Code is working on it."));
return box;
}
const actions = h.el("div", "git-step-actions");
if (p) {
actions.appendChild(stepButton(ctx, p, "btn primary"));
const second = step.secondary[0];
if (second) actions.appendChild(stepButton(ctx, second, "btn ghost"));
} else {
for (const s of step.secondary) actions.appendChild(stepButton(ctx, s, "btn small"));
}
box.appendChild(actions);
return box;
}
// "Checked 3 hr. ago — Refresh?", its Refresh word a button.
function staleLine(ctx, text) {
const line = ctx.h.el("p", "git-stale");
const word = "Refresh?";
line.appendChild(ctx.h.el("span", null, text.endsWith(word) ? text.slice(0, -word.length) : `${text} `));
line.appendChild(control(ctx, "button", "btn small ghost git-stale-refresh", word, { onClick: () => ctx.on.send("refresh") }));
return line;
}
/* -------------------------------------------------------------- panels */
function panelFrame(ctx, title, { closable = true, disabled = false } = {}) {
const p = ctx.h.el("section", "git-panel");
const head = ctx.h.el("div", "git-panel-head");
head.appendChild(ctx.h.el("h3", "git-panel-title", title));
if (closable) head.appendChild(control(ctx, "button", "btn small ghost", "Close", { disabled, onClick: () => ctx.on.closePanel() }));
p.appendChild(head);
return p;
}
// Mid-operation, Changes and Branches only show what is there.
const waitLine = (ctx) => ctx.h.el("p", "git-wait", `Everything here waits until the ${opName(ctx.git.inProgress)} is finished or aborted.`);
/* ------------------------------------------------------------- Changes */
function changesBody(ctx) {
const { git, board, h } = ctx;
const body = h.el("div", "git-changes");
const frozen = Boolean(git.inProgress);
if (frozen) body.appendChild(waitLine(ctx));
if (board.panel === "create" && board.create && board.create.commit) {
body.appendChild(createPanel(ctx, frozen));
return body;
}
const ch = git.changes || {};
const any = list(ch.files).length || list(ch.untrackedDirs).length;
if (!any) {
body.appendChild(h.el("p", "git-empty", `No changes. Nothing to commit on ${(git.head || {}).branch || "this commit"}.`));
return body;
}
body.appendChild(commitPanel(ctx, frozen));
return body;
}
function commitPanel(ctx, frozen) {
const { git, board, h, on } = ctx;
const ch = git.changes || {};
const first = git.hasCommits === false;
const opened = board.panel === "commit";
const p = panelFrame(ctx, first ? "Make the first commit" : "Commit", { closable: opened, disabled: frozen });
const ticks = board.ticks || (board.ticks = commitTicks(ch));
const ignored = board.ignore || (board.ignore = new Set());
const table = h.el("table", "git-table git-files");
const thead = h.el("thead");
const hr = h.el("tr");
for (const label of ["", "File", "State"]) hr.appendChild(h.el("th", null, label));
thead.appendChild(hr);
table.appendChild(thead);
const tbody = h.el("tbody");
const tickBox = (id, path) => {
const box = control(ctx, "input", null, null, {
disabled: frozen,
onChange: () => {
if (box.checked) {
ticks.add(path);
ignored.delete(path);
} else ticks.delete(path);
on.redraw();
},
});
box.type = "checkbox";
box.id = id;
box.checked = ticks.has(path);
box.setAttribute("aria-label", `Commit ${path}`);
return box;
};
const ignoreToggle = (id, path) => {
const label = h.el("label", "git-ignore");
const box = control(ctx, "input", null, null, {
disabled: frozen,
onChange: () => {
if (box.checked) {
ignored.add(path);
ticks.delete(path);
} else ignored.delete(path);
on.redraw();
},
});
box.type = "checkbox";
box.id = id;
box.checked = ignored.has(path);
label.append(box, h.el("span", null, " Add to .gitignore"));
return label;
};
list(ch.files).forEach((f, i) => {
const tr = h.el("tr", f.risky ? "is-held" : null);
const cell = h.el("td");
cell.appendChild(tickBox(`git-tick-f${i}`, f.path));
tr.appendChild(cell);
tr.appendChild(h.el("td", "git-path", f.path));
const state = h.el("td", "git-state", f.state || "");
if (f.risky) {
state.appendChild(h.el("span", "badge git-badge is-held", "held back"));
state.appendChild(ignoreToggle(`git-ignore-f${i}`, f.path));
}
tr.appendChild(state);
tbody.appendChild(tr);
});
list(ch.untrackedDirs).forEach((d, i) => {
const tr = h.el("tr");
const cell = h.el("td");
cell.appendChild(tickBox(`git-tick-d${i}`, d.path));
tr.appendChild(cell);
tr.appendChild(h.el("td", "git-path", d.path));
const state = h.el("td", "git-state", `untracked folder · ${plural(d.files, "file", "files")} `);
state.appendChild(ignoreToggle(`git-ignore-d${i}`, d.path));
tr.appendChild(state);
tbody.appendChild(tr);
});
table.appendChild(tbody);
p.appendChild(table);
const known = new Set([...list(ch.files), ...list(ch.untrackedDirs)].map((f) => f.path));
const files = [...ticks].filter((path) => known.has(path));
const ignore = [...ignored].filter((path) => known.has(path));
const send = () => on.send("commit", { files, ignore });
const actions = h.el("div", "git-panel-actions");
const head = git.head || {};
const detached = !first && !head.branch;
if (detached) {
// No branch to commit on: the commit makes one, .gitignore-only picks included.
actions.appendChild(
control(ctx, "button", "btn small primary", "Create branch", {
disabled: frozen || (!files.length && !ignore.length),
onClick: () => on.openPanel("create", { commit: true, files, ignore }),
})
);
} else if (!files.length && ignore.length) {
// Only .gitignore picks: the commit takes .gitignore alone.
actions.appendChild(control(ctx, "button", "btn small primary", `Add ${ignore.length} to .gitignore`, { disabled: frozen, onClick: send }));
} else if (!first && head.branch && head.branch === git.defaultBranch) {
actions.appendChild(h.el("p", "git-offer", `You're on ${head.branch}. Make a branch for this?`));
actions.appendChild(
control(ctx, "button", "btn small primary", "Create branch", {
disabled: frozen || !files.length,
onClick: () => on.openPanel("create", { commit: true, files, ignore }),
})
);
actions.appendChild(control(ctx, "button", "btn small", `Commit on ${head.branch}`, { disabled: frozen || !files.length, onClick: send }));
} else {
actions.appendChild(
control(ctx, "button", "btn small primary", `Commit ${plural(files.length, "file", "files")}`, { disabled: frozen || !files.length, onClick: send })
);
}
if (opened) actions.appendChild(control(ctx, "button", "btn small ghost", "Cancel", { disabled: frozen, onClick: () => on.closePanel() }));
p.appendChild(actions);
return p;
}
/* ------------------------------------------------------------ Branches */
function branchesBody(ctx) {
const { git, board, h, on } = ctx;
const body = h.el("section", "git-branches");
const frozen = Boolean(git.inProgress);
if (frozen) body.appendChild(waitLine(ctx));
const tools = h.el("div", "git-tools");
const search = control(ctx, "input", "git-search", null, {
role: "nav",
disabled: frozen,
onInput: () => {
board.query = search.value;
on.redraw();
},
});
search.type = "search";
search.id = "git-search";
search.placeholder = "Search branches";
search.setAttribute("aria-label", "Search branches");
search.value = board.query || "";
tools.appendChild(search);
// Not mid-operation, and not before the first commit, when there is nothing to branch from.
const first = git.hasCommits === false;
const nb = control(ctx, "button", "btn small", "New branch", {
disabled: frozen || first,
title: first ? "Make the first commit, then you can branch from it." : frozen ? "Finish or abort what is in progress first." : undefined,
onClick: () => on.openPanel("create"),
});
tools.appendChild(nb);
body.appendChild(tools);
if (board.panel === "create" && board.create && !board.create.commit) body.appendChild(createPanel(ctx, frozen));
const { merged, gone } = cleanupGroups(git);
const sweep = git.defaultBranch ? merged.length + gone.length : 0;
if (board.panel === "cleanup" && sweep) body.appendChild(cleanupPanel(ctx, frozen));
else if (sweep) {
const offer = h.el("p", "git-sweep-offer");
offer.appendChild(h.el("span", null, `${plural(sweep, "branch", "branches")} merged or gone on the remote. `));
offer.appendChild(control(ctx, "button", "btn small ghost", "Choose which to clean up…", { disabled: frozen, onClick: () => on.openPanel("cleanup") }));
body.appendChild(offer);
}
// Mid-rebase HEAD is detached, but the branch being rebased is still the
// one they are on: it keeps its current badge, and never offers Delete.
const rebasing = git.head && git.head.rebasing;
const rows = list(git.branches).map((b) => (rebasing && !b.remote && b.name === rebasing ? { ...b, current: true } : b));
const { top, remoteOnly } = orderBranches(rows);
const locals = filterBranches(top, board.query);
if (locals.length) body.appendChild(branchTable(ctx, locals, frozen));
else body.appendChild(h.el("p", "git-empty", board.query ? "No local branch matches." : "No local branches yet."));
if (remoteOnly.length) {
const fold = foldRemote(remoteOnly, { showAll: board.showAll, query: board.query });
const det = h.el("details", "git-remote-only");
det.setAttribute("data-gate", "nav");
// null remoteOpen takes the fold's default (open under a search); a
// manual toggle wins over it. The toggle event fires for the programmatic
// open too, so only a change away from what was drawn counts as theirs.
const drawnOpen = board.remoteOpen ?? Boolean(fold.open);
det.open = drawnOpen;
det.addEventListener("toggle", () => {
if (det.open !== drawnOpen) board.remoteOpen = det.open;
});
det.appendChild(h.el("summary", null, `Remote only (${board.query ? fold.shown.length : remoteOnly.length})`));
if (fold.shown.length) det.appendChild(branchTable(ctx, fold.shown, frozen));
else det.appendChild(h.el("p", "git-empty", "No remote branch matches."));
if (fold.hidden) {
det.appendChild(
control(ctx, "button", "btn small ghost", `Show all ${remoteOnly.length}`, {
role: "nav",
disabled: frozen,
onClick: () => {
board.showAll = true;
on.redraw();
},
})
);
}
body.appendChild(det);
}
return body;
}
function branchTable(ctx, rows, frozen) {
const { h, on } = ctx;
const table = h.el("table", "git-table");
const thead = h.el("thead");
const hr = h.el("tr");
for (const label of ["Branch", "Ahead / behind", "Last commit", ""]) hr.appendChild(h.el("th", null, label));
thead.appendChild(hr);
table.appendChild(thead);
const tbody = h.el("tbody");
for (const b of rows) {
const tr = h.el("tr", b.current ? "is-current" : null);
const name = h.el("td", "git-cell-name");
name.appendChild(h.el("span", "git-name", b.remote ? `${b.remote}/${b.name}` : b.name));
const badges = [
[b.current, "current", "is-current"],
[b.default, "default", "is-default"],
[b.merged, "Merged", "is-merged"],
[b.gone, "Remote copy deleted", "is-gone"],
];
for (const [shown, label, cls] of badges) if (shown) name.appendChild(h.el("span", `badge git-badge ${cls}`, label));
tr.appendChild(name);
let track = "not published";
if (b.remote) track = "remote only";
else if (b.gone) track = "—";
else if (b.upstream) track = `↑${b.ahead || 0} ↓${b.behind || 0}`;
tr.appendChild(h.el("td", "git-cell-track", track));
const last = h.el("td", "git-cell-last");
const l = b.last || {};
last.appendChild(h.el("span", "git-subject", l.subject || ""));
const by = [l.author, relativeAge(l.at, ctx.now)].filter(Boolean).join(" · ");
if (by) last.appendChild(h.el("span", "git-by", by));
tr.appendChild(last);
const acts = h.el("td", "git-cell-actions");
const branch = b.remote ? `${b.remote}/${b.name}` : b.name;
// Mid-operation a row's Switch or Delete would ask for a second git op on top of the first.
if (!b.current) acts.appendChild(control(ctx, "button", "btn small", "Switch", { disabled: frozen, onClick: () => on.send("switch", { branch }) }));
if (!b.remote && !b.current && !b.default) {
acts.appendChild(control(ctx, "button", "btn small danger", "Delete", { disabled: frozen, onClick: () => on.send("delete", { branch: b.name }) }));
}
tr.appendChild(acts);
tbody.appendChild(tr);
}
table.appendChild(tbody);
// The table scrolls sideways on its own when the column is narrower than
// its no-wrap cells, so the search row and the buttons above it stay put.
const wrap = h.el("div", "git-table-wrap");
wrap.appendChild(table);
return wrap;
}
function createPanel(ctx, frozen) {
const { git, board, h, on } = ctx;
const c = board.create;
const p = panelFrame(ctx, c.commit ? "New branch for this commit" : "New branch", { disabled: frozen });
const src = createSources(git, c.commit);
const option = (value) => {
const o = h.el("option", null, value);
o.value = value;
return o;
};
const fromRow = h.el("div", "git-field-row");
const fromLabel = h.el("label", "git-field", "From ");
const from = control(ctx, "select", null, null, {
disabled: frozen,
onChange: () => {
c.from = from.value;
on.redraw();
},
});
from.id = "git-new-from";
for (const o of src.options) from.appendChild(option(o));
from.value = c.from;
fromLabel.appendChild(from);
fromRow.appendChild(fromLabel);
if (src.here && c.from !== src.here) {
fromRow.appendChild(
control(ctx, "button", "btn small ghost", `From ${src.here}`, {
disabled: frozen,
onClick: () => {
c.from = src.here;
on.redraw();
},
})
);
}
p.appendChild(fromRow);
const parts = h.el("div", "git-field-row");
const typeLabel = h.el("label", "git-field", "Type ");
const type = control(ctx, "select", null, null, {
disabled: frozen,
onChange: () => {
c.type = type.value;
refresh();
},
});
type.id = "git-new-type";
for (const t of BRANCH_TYPES) type.appendChild(option(t));
type.value = c.type;
typeLabel.appendChild(type);
const descLabel = h.el("label", "git-field is-wide", "Short description ");
const desc = control(ctx, "input", null, null, {
disabled: frozen,
onInput: () => {
c.description = desc.value;
refresh();
},
});
desc.id = "git-new-desc";
desc.placeholder = "export csv";
desc.value = c.description || "";
descLabel.appendChild(desc);
parts.append(typeLabel, descLabel);
p.appendChild(parts);
const nameLabel = h.el("label", "git-field is-wide", "Branch name ");
const name = control(ctx, "input", "git-new-name", null, {
disabled: frozen,
onInput: () => {
c.name = name.value;
refresh();
},
});
name.id = "git-new-name";
nameLabel.appendChild(name);
p.appendChild(nameLabel);
const status = h.el("p", "git-name-status");
status.setAttribute("aria-live", "polite");
p.appendChild(status);
// The name mirrors the two fields until it is edited directly.
const currentName = () => (c.name == null ? composeBranchName(c) : c.name);
const actions = h.el("div", "git-panel-actions");
const go = control(ctx, "button", "btn small primary", "Create", {
disabled: true,
onClick: () => {
const fields = { name: currentName(), from: c.from };
if (c.commit) Object.assign(fields, { then: "commit", files: c.files || [] });
if (c.commit && c.ignore && c.ignore.length) fields.ignore = c.ignore;
on.send("create", fields);
},
});
actions.appendChild(go);
actions.appendChild(control(ctx, "button", "btn small ghost", "Cancel", { disabled: frozen, onClick: () => on.closePanel() }));
p.appendChild(actions);
// Typing updates the name box, the status line and Create in place, never a redraw.
const noFiles = c.commit && !list(c.files).length && !list(c.ignore).length;
const refresh = () => {
const value = currentName();
if (name.value !== value) name.value = value;
const st = nameStatus(value, git);
nameLine(ctx, status, st, frozen);
if (noFiles) status.appendChild(h.el("span", null, " Nothing is ticked to commit."));
const own = frozen || st.kind !== "free" || noFiles;
go.disabled = own || !controlAllowed(ctx.mode, "action");
if (own) go.setAttribute("data-own", "true");
else go.removeAttribute("data-own");
};
refresh();
return p;
}
function nameLine(ctx, line, st, frozen) {
const { h, on } = ctx;
line.replaceChildren();
line.className = "git-name-status is-" + st.kind;
const say = (text) => line.appendChild(h.el("span", null, text));
const switchTo = (branch) =>
line.appendChild(control(ctx, "button", "btn small", "Switch to it", { disabled: frozen, onClick: () => on.send("switch", { branch }) }));
if (st.kind === "empty") say("Fill in the fields above, or type a name.");
else if (st.kind === "invalid") say(st.reason);
else if (st.kind === "free") say("That name is free.");
else if (st.kind === "local") {
say(`${st.branch} already exists here. `);
switchTo(st.branch);
} else if (st.kind === "remote") {
say(`${st.remote}/${st.branch} already exists on ${st.remote}. `);
switchTo(`${st.remote}/${st.branch}`);
} else if (st.kind === "nested") say(`It clashes with ${st.clash}: one branch cannot be a folder of another.`);
}
function cleanupPanel(ctx, frozen) {
const { git, board, h, on } = ctx;
const p = panelFrame(ctx, "Clean up branches", { disabled: frozen });
const { merged, gone } = cleanupGroups(git);
const sweep = board.sweep || (board.sweep = new Set([...merged, ...gone].map((b) => b.name)));
const group = (title, rows, key) => {
if (!rows.length) return;
p.appendChild(h.el("h4", "git-group-title", title));
const ul = h.el("ul", "git-sweep");
rows.forEach((b, i) => {
const li = h.el("li");
const label = h.el("label");
const box = control(ctx, "input", null, null, {
disabled: frozen,
onChange: () => {
if (box.checked) sweep.add(b.name);
else sweep.delete(b.name);
on.redraw();
},
});
box.type = "checkbox";
box.id = `git-sweep-${key}${i}`;
box.checked = sweep.has(b.name);
label.append(box, h.el("span", null, " " + b.name));
li.appendChild(label);
ul.appendChild(li);
});
p.appendChild(ul);
};
group(`Merged into ${git.defaultBranch}`, merged, "m");
group("Remote copy deleted", gone, "g");
const known = new Set([...merged, ...gone].map((b) => b.name));
const branches = [...sweep].filter((n) => known.has(n));
const actions = h.el("div", "git-panel-actions");
actions.appendChild(
control(ctx, "button", "btn small danger", `Delete ${plural(branches.length, "branch", "branches")}`, {
disabled: frozen || !branches.length,
onClick: () => on.send("cleanup", { branches }),
})
);
actions.appendChild(control(ctx, "button", "btn small ghost", "Cancel", { disabled: frozen, onClick: () => on.closePanel() }));
p.appendChild(actions);
return p;
}
/* ---------------------------------------------------------------- Sync */
function syncBody(ctx) {
const { git, h } = ctx;
const body = h.el("div", "git-sync");
if (git.inProgress) {
body.appendChild(opBlock(ctx));
return body;
}
const pr = prBlock(ctx);
if (pr) body.appendChild(pr);
const acts = boardActions(git, { busy: ctx.mode !== "idle" });
const row = h.el("div", "git-sync-actions");
const primaryOp = ctx.step.primary && ctx.step.primary.op;
for (const key of ["refresh", "pull", "push", "publish"]) {
const a = acts[key];
if (!a.shown) continue;
row.appendChild(
control(ctx, "button", "btn small" + (key === primaryOp ? " primary" : ""), a.label, {
disabled: ctx.mode === "idle" && !a.enabled,
title: a.title,
onClick: () => runStep(ctx, { op: key }),
})
);
}
body.appendChild(row);
if (list(git.remotes).length) {
body.appendChild(h.el("p", "git-fresh" + (ctx.step.stale ? " is-stale" : ""), ctx.step.stale || refreshedLine(git, ctx.now)));
} else body.appendChild(h.el("p", "git-fresh", "No remote yet, so nothing to sync. Add one with the line at the top."));
return body;
}
// Mid-operation: one block that is the step, its files and its two buttons.
function opBlock(ctx) {
const { git, h, on, step } = ctx;
const box = h.el("div", "git-op git-step is-warn");
box.setAttribute("role", "alert");
box.appendChild(h.el("div", "git-step-kicker", "Next step"));
box.appendChild(h.el("h3", "git-op-title", `${OP_WORDS[git.inProgress] || "An operation"} is in progress`));
if (step.primary) {
box.appendChild(h.el("p", "git-step-label", step.primary.label));
if (step.primary.why) box.appendChild(h.el("p", "git-step-why", step.primary.why));
}
const conflicted = list(git.conflicted);
if (conflicted.length) {
const ul = h.el("ul", "git-op-files");
for (const c of conflicted) {
const li = h.el("li");
li.appendChild(h.el("code", "md-code", c.path));
li.appendChild(h.el("span", c.markers ? "git-op-left" : "git-op-clear", c.markers ? " · markers left" : " · resolved"));
ul.appendChild(li);
}
box.appendChild(ul);
}
const actions = h.el("div", "git-op-actions");
const wording = { operation: git.inProgress };
// Always offered: the file states are a snapshot from the agent's last
// look, and someone who fixed a file in their editor has no other way to
// say so. `plan continue` checks the files on disk itself.
const clean = conflicted.every((c) => c.markers === false);
actions.appendChild(
control(ctx, "button", clean ? "btn primary" : "btn", "Continue", {
title: clean ? undefined : "Fixed them in your editor? Plan2Code checks the files again before it continues.",
onClick: () => on.send("continue", {}, wording),
})
);
const abort = step.secondary.find((s) => s.op === "abort");
actions.appendChild(
control(ctx, "button", "btn danger", abort ? abort.label : `Abort the ${opName(git.inProgress)}`, {
onClick: () => on.send("abort", {}, wording),
})
);
box.appendChild(actions);
return box;
}
function prBlock(ctx) {
const { git, board, h, on } = ctx;
const cur = currentRow(git);
const bases = list(git.branches)
.filter((b) => b && !b.remote && (!cur || b.name !== cur.name))
.map((b) => b.name);
// One base for both the link and the picker, so they can never disagree: a
// pick that has since gone falls back to the default, and a default that is
// only on the remote is still offered.
const base = bases.includes(board.base) ? board.base : git.defaultBranch;
if (base && !bases.includes(base)) bases.unshift(base);
const link = boardPrLink(git, base);
if (!link) return null;
const box = h.el("div", "git-pr");
if (link.needsKind) {
if (!link.host) return null;
box.appendChild(h.el("span", "git-pr-ask", `Which host is ${link.host}?`));
for (const [kind, label] of Object.entries(PR_HOST_LABELS)) {
box.appendChild(control(ctx, "button", "btn small", label, { onClick: () => on.pickPrHost(link.host, kind) }));
}
return box;
}
if (!link.url || !/^https:\/\//i.test(link.url)) return null;
box.appendChild(prLink(ctx, link.url));
box.appendChild(copy(ctx, link.url, "btn small"));
if (bases.length) {
const label = h.el("label", "git-pr-base", "into ");
const sel = control(ctx, "select", null, null, {
onChange: () => {
board.base = sel.value;
on.redraw();
},
});
sel.id = "git-pr-base";
for (const name of bases) {
const o = h.el("option", null, name);
o.value = name;
sel.appendChild(o);
}
sel.value = base;
label.appendChild(sel);
box.appendChild(label);
}
return box;
}
+274 -5
View File
@@ -1,13 +1,16 @@
// Plan2Code Web Console - the git board's rules: branch order, names, buttons and replies.
// Plan2Code Web Console - the git board's rules: branch order, names, buttons, replies, next step and tabs.
//
// Everything the board decides from a state.git snapshot (git-repo.mjs ->
// snapshot()) lives here so it is tested without a browser: how the branch
// list is ordered and folded, whether a new branch name is free, which action
// list is ordered and folded, whether a new branch name is free and where a
// new branch can start, which branches the clean-up offers, which action
// buttons show and which are enabled, the plain sentence each button sends
// the agent, the "Last refreshed" line, which files start ticked in the
// commit dialog and the pull-request link. app.js only renders what these
// say. No DOM access at module scope and only one import: the page and
// `node --test` both import this file.
// commit dialog, the pull-request link, the suggested next step and the tab
// that owns it, each tab's badge, and how busy the board is and which
// controls that allows. app.js only renders what these say. No DOM access at
// module scope and only one import: the page and `node --test` both import
// this file.
import { prUrl } from "./pr-url.js";
@@ -148,6 +151,40 @@ export function nameStatus(name, git) {
return { kind: "free" };
}
/**
* Where a new branch can start: `{ preset, here, options }`. origin/<default>
* when that remote branch exists, else the local default, else the current
* branch (or, detached, the commit). A commit from a detached HEAD belongs on
* the commit it was made at.
*/
export function createSources(git, commit = false) {
const g = git || {};
const def = g.defaultBranch;
const rows = list(g.branches).filter(Boolean);
const h = g.head || {};
const originDef =
def && rows.some((b) => (b.remote === "origin" && b.name === def) || (!b.remote && b.upstream === `origin/${def}`))
? `origin/${def}`
: null;
const localDef = def && rows.some((b) => !b.remote && b.name === def) ? def : null;
const here = h.branch || h.detached || null;
const preset = (commit && h.detached) || originDef || localDef || here || "HEAD";
return { preset, here, options: [...new Set([originDef, localDef, here, preset].filter(Boolean))] };
}
/* ------------------------------------------------------------- cleanup */
/**
* The clean-up panel's groups, `{ merged, gone }`: local branches merged into
* the default, and those whose remote copy is deleted. Never the current or
* the default branch; a branch in both shows once, under gone, the way the
* confirm that follows (cleanup-list) names it.
*/
export function cleanupGroups(git) {
const locals = list(git && git.branches).filter((b) => b && !b.remote && !b.current && !b.default);
return { merged: locals.filter((b) => b.merged && !b.gone), gone: locals.filter((b) => b.gone) };
}
/* ------------------------------------------------------------- buttons */
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
@@ -259,6 +296,9 @@ function filePhrase(files, count) {
return n === 1 ? `this file${shown}` : `these ${n} files${shown}`;
}
// Nothing ticked, only .gitignore picks: the commit takes .gitignore alone.
const ignoreOnly = (f) => !names(f.files).length && !Number(f.count) && names(f.ignore).length > 0;
/** The plain instruction a board button sends the agent, one sentence per op. */
export function gitReply(op, fields = {}) {
const f = fields || {};
@@ -278,6 +318,7 @@ export function gitReply(op, fields = {}) {
const start = `Create ${f.name} from ${f.from}.`;
if (f.then !== "commit") return start;
const ignore = names(f.ignore);
if (ignoreOnly(f)) return `${start} Then add ${ignore.join(", ")} to .gitignore and commit just .gitignore.`;
const tail = ignore.length ? ` Add ${ignore.join(", ")} to .gitignore.` : "";
return `${start} Then commit ${filePhrase(names(f.files), f.count)}.${tail}`;
}
@@ -290,6 +331,7 @@ export function gitReply(op, fields = {}) {
}
case "commit": {
const ignore = names(f.ignore);
if (ignoreOnly(f)) return `Add ${ignore.join(", ")} to .gitignore and commit just .gitignore.`;
const tail = ignore.length ? ` Add ${ignore.join(", ")} to .gitignore.` : "";
return `Commit ${filePhrase(names(f.files), f.count)}.${tail}`;
}
@@ -380,3 +422,230 @@ export function boardPrLink(git, base) {
host: remote.host || null,
};
}
/* ----------------------------------------------------------- next step */
export const GIT_TABS = Object.freeze([
Object.freeze({ id: "changes", label: "Changes" }),
Object.freeze({ id: "branches", label: "Branches" }),
Object.freeze({ id: "sync", label: "Sync" }),
]);
const TAB_IDS = new Set(GIT_TABS.map((t) => t.id));
// The tab each suggested step lives on. Anything not listed is Sync's.
const STEP_TAB = Object.freeze({
commit: "changes",
"create-commit": "changes",
ignore: "changes",
create: "branches",
cleanup: "branches",
});
const tabOf = (step) => (step && STEP_TAB[step.op]) || "sync";
const STALE_MS = 60 * 60 * 1000;
const files = (n) => plural(n, "file", "files");
const branchCount = (n) => plural(n, "branch", "branches");
// Held-back (risky) paths: secrets and big files, never counted toward Commit.
const heldPaths = (git) => list(git.changes && git.changes.files).filter((f) => f && f.risky && typeof f.path === "string").map((f) => f.path);
// Local branches merged into the default or gone upstream, never the current or default one.
// None without a default branch: boardActions() offers no Clean up then.
const sweepable = (git) =>
git.defaultBranch ? list(git.branches).filter((b) => b && !b.remote && !b.current && !b.default && (b.merged || b.gone)) : [];
// Every step whose rule matches, in rule order (first match wins).
function matches(git) {
const head = git.head || {};
const held = heldPaths(git).length;
const count = Math.max(0, (Number(git.changes && git.changes.count) || 0) - held);
const cur = currentRow(git);
const onDefault = Boolean(head.branch) && head.branch === git.defaultBranch;
const hasRemote = list(git.remotes).length > 0;
const live = Boolean(head.upstream) && !head.gone;
const remoteName = (cur && cur.upstreamRemote) || "the remote";
const out = [];
// 1. An operation stopped part-way.
if (git.inProgress) {
const left = list(git.conflicted).filter((c) => c && c.markers).length;
out.push(
left
? { op: "fix", label: "Fix the files", why: `${files(left)} still ${left === 1 ? "has" : "have"} conflict markers.` }
: { op: "continue", label: "Continue", why: "Every conflict is resolved." }
);
out.push({ op: "abort", label: `Abort the ${git.inProgress === "am" ? "git am" : git.inProgress}`, why: "Put everything back as it was." });
return out;
}
// 2. Nothing committed yet.
if (git.hasCommits === false) {
out.push({ op: "commit", label: "Make the first commit", why: `Nothing saved yet. ${files(count)} ready.` });
return out;
}
// 3. Detached HEAD.
if (!head.branch) out.push({ op: "create", label: "Make a branch here", why: `You're on commit ${head.detached || "an unknown commit"}, not a branch.` });
// 4. Uncommitted changes, held-back files left out.
if (count > 0) {
if (onDefault) {
out.push({ op: "create-commit", label: `Start a branch for ${files(count)}`, why: `You're on ${head.branch}. Work usually goes on its own branch.` });
out.push({ op: "commit", label: `Commit on ${head.branch}`, why: "Commit straight to the default branch.", forced: true });
} else {
out.push({ op: "commit", label: `Commit ${files(count)}`, why: `${files(count)} changed on ${head.branch || "this commit"}.` });
}
}
// 5. Behind, 6. ahead.
const behind = Number(head.behind) || 0;
const ahead = Number(head.ahead) || 0;
if (live && behind > 0) out.push({ op: "pull", label: "Pull", why: `${remoteName === "the remote" ? "The remote" : remoteName} has ${plural(behind, "commit", "commits")} you don't.` });
if (live && ahead > 0) out.push({ op: "push", label: `Push ${ahead}`, why: `${plural(ahead, "commit", "commits")} not on ${remoteName} yet.` });
// 7. Never published, or its remote copy was deleted.
if (head.branch && hasRemote && !live) {
out.push({ op: "publish", label: "Publish", why: head.gone ? `${head.branch}'s remote copy was deleted.` : `${head.branch} isn't on the remote yet.` });
}
// 8. Pushed, not the default branch, and a link that can open.
if (live && !onDefault) {
const link = boardPrLink(git, git.defaultBranch);
if (link && link.url) out.push({ op: "pr", label: "Open pull request", why: "Pushed. Ready for review?", url: link.url });
}
// 9. Branches to clean up.
const sweep = sweepable(git).length;
if (sweep) out.push({ op: "cleanup", label: `Clean up ${branchCount(sweep)}`, why: `${branchCount(sweep)} already merged or deleted on the remote.` });
return out;
}
// The held-back line and the .gitignore offer that fills an empty secondary slot.
function heldOut(git) {
const held = heldPaths(git);
if (!held.length) return { held: null, ignore: null };
const what = held.length === 1 ? "`" + held[0] + "`" : `${held.length} held-back files`;
return {
held: held.length === 1 ? `${what} held back` : `${held.length} files held back`,
ignore: { op: "ignore", label: `Add ${what} to .gitignore`, why: `Keep ${held.length === 1 ? "it" : "them"} out of every commit.`, files: held },
};
}
// "Checked 3 hr. ago — Refresh?" when a remote exists and the last fetch is over an hour old or unknown.
function staleLine(git, now) {
if (!list(git.remotes).length) return null;
const at = Date.parse(git.lastFetch);
if (!Number.isNaN(at) && now - at <= STALE_MS) return null;
const age = git.lastFetch ? relativeAge(git.lastFetch, now) : "";
return age ? `Checked ${age} — Refresh?` : "Never checked — Refresh?";
}
const withTab = (step) => (step ? { ...step, tab: tabOf(step) } : step);
/**
* The board's suggested next step: `{ primary, secondary, stale, held, line,
* tab }`. `primary` is the first matching rule or null; `secondary` an array
* with at most one quieter step (the default-branch commit, else the next
* match, else the held-back .gitignore offer), or the two quiet actions when
* there is no primary. `stale` never changes the step. Every step carries the
* `tab` it lives on, and `tab` is the one that owns the suggestion.
*/
export function nextStep(git, { now = Date.now() } = {}) {
const g = git || {};
const all = matches(g);
const { held, ignore } = heldOut(g);
const head = g.head || {};
const stale = staleLine(g, now);
if (!all.length) {
const branch = head.branch || "this commit";
const checked = g.lastFetch ? relativeAge(g.lastFetch, now) : "";
const line = list(g.remotes).length
? `All caught up on ${branch}${checked ? ` · checked ${checked}` : ""}`
: `Nothing to commit on ${branch} · no remote yet`;
const secondary = [ignore || { op: "create", label: "New branch" }, { op: "refresh", label: "Refresh" }].map(withTab);
return { primary: null, secondary, stale, held, line, tab: ignore ? "changes" : "sync" };
}
const [first, ...rest] = all;
const primary = withTab(first);
const second = rest.find((s) => s.forced) || rest[0] || ignore;
return { primary, secondary: second ? [withTab(second)] : [], stale, held, line: primary.why, tab: primary.tab };
}
/* -------------------------------------------------------------- badges */
/**
* What each tab has waiting: `{ changes, branches, sync }`, each null or
* `{ kind, text, label, next }` (kind "count", "dot" or "warn"; `label` is
* for the tab's accessible name). `next` marks the tab owning the next step
* when there is a primary; that tab always carries a badge. Mid-operation
* only Sync is badged, with a warning.
*/
export function tabBadges(git, { now = Date.now(), stepTab = null } = {}) {
const g = git || {};
const head = g.head || {};
const out = { changes: null, branches: null, sync: null };
if (g.inProgress) {
out.sync = { kind: "warn", text: "!", label: "operation in progress", next: false };
} else {
const held = heldPaths(g).length;
const count = Math.max(0, (Number(g.changes && g.changes.count) || 0) - held);
if (count) out.changes = { kind: "count", text: String(count), label: `${count} waiting`, next: false };
else if (held) out.changes = { kind: "dot", text: "·", label: "held-back files", next: false };
const sweep = sweepable(g).length;
if (sweep) out.branches = { kind: "count", text: String(sweep), label: `${sweep} to clean up`, next: false };
const live = Boolean(head.upstream) && !head.gone;
const ahead = Number(head.ahead) || 0;
const behind = Number(head.behind) || 0;
if (live && (ahead || behind)) {
const text = [ahead ? `↑${ahead}` : null, behind ? `↓${behind}` : null].filter(Boolean).join(" ");
const label = [ahead ? `${ahead} to push` : null, behind ? `${behind} to pull` : null].filter(Boolean).join(", ");
out.sync = { kind: "count", text, label, next: false };
} else if (list(g.remotes).length && head.branch && !live && g.hasCommits !== false) {
out.sync = { kind: "count", text: "↑", label: "not published", next: false };
} else if (staleLine(g, now)) {
out.sync = { kind: "count", text: "?", label: "not checked lately", next: false };
}
}
const step = nextStep(g, { now });
const owner = TAB_IDS.has(stepTab) ? stepTab : step.tab;
if (step.primary && TAB_IDS.has(owner)) {
const b = out[owner] || { kind: "dot", text: "·", label: "" };
out[owner] = { ...b, next: true, label: b.label ? `${b.label}, next step` : "next step" };
}
return out;
}
/* ---------------------------------------------------------------- busy */
/**
* How busy the board is, most restrictive first: "offline" (the server is
* gone, or the last click is not picked up yet), "running" (a git command or
* the agent's turn), "card" (a question of Plan2Code's waits), "idle".
*/
export function busyMode({ running = false, cardWaiting = false, gone = false, pending = false } = {}) {
if (gone || pending) return "offline";
if (running) return "running";
if (cardWaiting) return "card";
return "idle";
}
/**
* Whether a control of `role` works in `mode`: "nav" (switching tabs, search,
* folds) always; "action" (anything that sends, ticks, picks, copies or opens
* a panel) only when idle; "done" (Done with git) when idle or a card waits.
*/
export function controlAllowed(mode, role) {
if (role === "nav") return true;
if (role === "action") return mode === "idle";
if (role === "done") return mode === "idle" || mode === "card";
return false;
}
/**
* The tab to show. A click of theirs that landed, and arriving at the board,
* go to the next step's tab; a reload and a change they did not click for
* keep the tab they had.
*/
export function pickTab({ current = null, stepTab, reason } = {}) {
const step = TAB_IDS.has(stepTab) ? stepTab : "sync";
if (reason === "landed" || reason === "arrival") return step;
return TAB_IDS.has(current) ? current : step;
}
+93 -55
View File
@@ -25,6 +25,7 @@
<link rel="modulepreload" href="/mentions.js" />
<link rel="modulepreload" href="/favicon.js" />
<link rel="modulepreload" href="/git-board.js" />
<link rel="modulepreload" href="/git-board-view.js" />
<link rel="modulepreload" href="/pr-url.js" />
<link rel="modulepreload" href="/vendor/marked.esm.js" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
@@ -1570,7 +1571,7 @@
<ul>
<li><strong>Quick task.</strong> Too small for the full process? A quick plan, then it just builds it.</li>
<li><strong>Review.</strong> A second opinion on the changes. Problems ranked, and you pick what gets fixed.</li>
<li><strong>Handoff.</strong> Pack this conversation into a document a fresh session can pick up cold.</li>
<li><strong>Handoff.</strong> Pack the current session into a document a fresh session can pick up cold.</li>
<li><strong>Changelog.</strong> Checks the CHANGELOG version against the main branch and suggests entries for what is new.</li>
<li><strong>Git.</strong> Branches, pull, push and commits on one board, asking before anything leaves your machine. See "The git board".</li>
</ul>
@@ -1733,86 +1734,123 @@
<section class="help-panel" data-tab="git">
<h3>The git board</h3>
<p class="help-lead">
The Git card opens one board for your repository: branches, pull,
push and commits in one place. Every button is a request to
Plan2Code, which runs the git commands and says what each one did.
The Git card opens a board for your repository: three tabs — Changes,
Branches and Sync — and the next step on top. Every button is a request
to Plan2Code, which runs the git commands and says what each one did.
</p>
<h4>The header</h4>
<ul>
<li>The branch you are on, and how far it is ahead of or behind its remote copy.</li>
<li>
The branch you are on, and how far it is ahead of (↑) or behind (↓)
its remote copy, or that it is not published yet.
</li>
<li>With more than one remote, a badge names the one your branch follows.</li>
<li>
With no remote at all, a <strong>No remote</strong> line shows the
command that adds one, with a copy button.
</li>
<li>
<strong>Last refreshed</strong> says when the remotes were last
fetched. <strong>Refresh</strong> fetches again; if that fails, the
line says so.
</li>
<li>
Once your branch is pushed, <strong>Open pull request</strong> opens
your host's new pull request page, into the default branch or the
one you pick beside it. The first time a host is unknown, the board
asks which kind it is and remembers the answer.
fetched. If a refresh fails, the line says so.
</li>
</ul>
<h4>The branch table</h4>
<h4>The tabs</h4>
<ul>
<li>
The branch you are on and the default branch come first, then the
rest, newest commit first, each with <strong>Switch</strong> and
<strong>Delete</strong>.
<strong>Changes</strong> lists your uncommitted files, ready to
commit. Its badge counts them, or shows a dot when the only files
left are held back (secrets and very large files).
</li>
<li>
<strong>Merged</strong> marks a branch already merged into the
default branch, and <strong>Remote copy deleted</strong> one whose
remote copy is gone. <strong>Clean up</strong> offers to delete those
local branches in one go.
<strong>Branches</strong> lists your branches with Switch and Delete,
plus new branch and clean-up. Its badge counts branches already
merged, or whose remote copy is gone, that can be cleaned up.
Branches that exist only on the remote sit under <strong>Remote
only</strong>, showing the first
<span data-fact="remoteFold">50</span>; <strong>Search
branches</strong> filters both lists.
</li>
<li>
Branches that exist only on the remote sit under
<strong>Remote only</strong>, showing the first
<span data-fact="remoteFold">50</span>; <strong>Show all</strong>
lists the rest.
<strong>Sync</strong> holds pull, push and publish. Its badge shows
↑ and ↓ counts, ↑ alone when the branch is unpublished, or ? when the
remotes have not been checked lately. During a rebase or merge it
shows <strong>!</strong> instead. Once your branch is pushed, Sync
also offers <strong>Open pull request</strong>, into the default
branch or the one you pick beside it; the first time a host is
unknown, it asks which kind it is and remembers the answer.
</li>
<li><strong>Search branches</strong> filters both lists by name or last commit.</li>
<li>A filled badge marks the tab where the next step is.</li>
</ul>
<h4>What asks first</h4>
<h4>The next step</h4>
<ul>
<li>
<strong>Push</strong>, <strong>Publish</strong>,
<strong>Delete</strong> and <strong>Clean up</strong> always show
exactly what will happen and wait for your yes. Deleting a branch
that is not merged is a red confirm.
The tab that holds it opens with one main button and, at most, one
quieter one beside it: Commit, Push, Publish, Open pull request, and
so on.
</li>
<li>
Switching with uncommitted changes asks first: <strong>Switch and
bring them</strong>, <strong>Commit first</strong> or
<strong>Cancel</strong>. A pull that would touch your changes asks
the same way.
On the other tabs, a line reads <strong>Next step is on
‹tab›</strong>; click it to go there.
</li>
<li>
<strong>Commit</strong> opens a list of your changed files to tick,
and you approve the message before anything is committed.
Held-back files never count toward the next step. The board offers
to add them to <code>.gitignore</code> instead.
</li>
<li>
When the remotes were last checked over an hour ago, it says
<strong>Checked … — Refresh?</strong>.
</li>
<li>
With nothing to do it says <strong>All caught up</strong>, or
<strong>Nothing to commit … no remote yet</strong> when there is no
remote.
</li>
<li>
Push, Publish, Delete and Clean up always show exactly what will
happen and wait for your yes. Nothing is ever force-pushed, and a
remote branch is never deleted.
</li>
<li>A remote branch is never deleted, and nothing is ever force-pushed.</li>
</ul>
<h4>One action at a time</h4>
<h4>Moving between tabs</h4>
<ul>
<li>
Once a click of yours has landed, the board moves to the tab of the
next step. Anything else that changes leaves you where you are.
</li>
<li>Reloading the page keeps the tab you were on.</li>
<li>The arrow keys move between tabs, and Home and End jump to the first and last.</li>
</ul>
<h4>While something is running</h4>
<ul>
<li>
Everything greys 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>
<li>Plan2Code's questions appear under the tab strip.</li>
<li>
When it is done, a result line says what happened, with the commit
hashes, and the board redraws from the repository as it now stands.
</li>
</ul>
<h4>Mid-rebase or merge</h4>
<p>
While Planny works on a click, the bar is locked, so nothing queues
up behind it. When it is done, a result line says what happened, with
the commit hashes, and the board redraws from the repository as it now
stands.
A rebase or merge that stopped on conflicts shows one block on Sync,
with the files still to fix. <strong>Continue</strong> becomes the main
button once no conflict markers are left; a single <strong>Abort</strong>
puts everything back as it was. The other tabs wait until it is
finished or aborted.
</p>
<h4>Done</h4>
<h4>Done with git</h4>
<p>
<strong>Done</strong> ends the session. 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.
</p>
<h4>In the terminal</h4>
<p>
The same skill takes plain instructions, such as
<code>/plan2code-git switch to main</code> or
<code>/plan2code-git commit and push</code>, and asks the same
questions before every push, publish and delete.
<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
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
finishes.
</p>
</section>