Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/workstreams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,6 @@ npm run build

After editing the plugin, run `bb plugin reload workstreams`. The build creates
the distributable files in `dist/` for git or npm installs.


Effort cards include an expandable **Threads** section with status counts and last activity. It lists all linked threads, including PR workers, with exact PR references and per-thread activity times. **Archive** accepts idle threads after checking their current status and descendants; **Undo** or **Archived threads…** restores them without starting the agent. Threads with subthreads are managed from BB. This uses cached thread facts, without fetching extra event logs for the card.
28 changes: 27 additions & 1 deletion plugins/workstreams/deck-nav-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useInventory } from "./inventory-screen";
import { useNotesConfirm } from "./notes-flow";
import { EASE, FLIP_MS, flipMotion, flipper, focusNamesCard, ghostOf, playFlip, settleFlip, type FlipMotion } from "./deck-flip";
import { MergePreviewDialog } from "./merge-preview-dialog";
import { ArchivedThreadsDialog } from "./archivedthreads";
import type { SeedProposal } from "./linear-seed";
import { deckLinkStep } from "./view-preference";

Expand Down Expand Up @@ -105,6 +106,9 @@ export function DeckNavView({ onView, openCard = null }: { onView(target: Header
const [busy, setBusy] = useState(false);
const [dialogError, setDialogError] = useState<string | null>(null);
const [merging, setMerging] = useState<{ target: string; n: null }[] | null>(null);
const [archivingThread, setArchivingThread] = useState<string | null>(null);
const archivingRef = useRef(false);
const [archivedOpen, setArchivedOpen] = useState(false);
const [pile, setPile] = useState<"hold" | "done" | null>(null);
const [flash, setFlash] = useState<{ text: string; undo: boolean } | null>(null);
const [seenNote, setSeenNote] = useState<string | null>(null);
Expand Down Expand Up @@ -699,6 +703,25 @@ export function DeckNavView({ onView, openCard = null }: { onView(target: Header
const runRef = useRef(runAction);
runRef.current = runAction;

const archiveThread = async (command: Extract<DeckCommand, { kind: "archive-thread" }>) => {
if (archivingRef.current) return;
archivingRef.current = true; setArchivingThread(command.id);
try {
const result = await rpc.call("thread_archive", { threadId: command.id, cardId: command.cardId });
if (!result.ok) { say(result.error); return; }
let used = false;
setUndo({ label: `Archive ${command.title}`, live: () => !used, run: async () => {
used = true;
try {
const restored = await rpc.call("thread_restore", { threadId: command.id });
say(restored.ok ? `Restored ${command.title}.` : restored.error); load();
} catch { say("Couldn't restore the thread. Try Archived threads."); }
} });
say(`Archived ${command.title}.`, true, 15_000); load();
} catch (cause) { say(`Couldn't confirm the archive. Check Archived threads before retrying. ${message(cause)}`); }
finally { archivingRef.current = false; setArchivingThread(null); }
};

const run = (command: DeckCommand) => {
switch (command.kind) {
case "action": runAction(command.id, command.line); return;
Expand All @@ -722,6 +745,8 @@ export function DeckNavView({ onView, openCard = null }: { onView(target: Header
case "undo-batch": void rpc.call("deck_batch_undo", { batchId: command.batchId }).then((result) => { say(result.ok ? "Undone. Nothing was sent." : result.error); load(); },
(cause: unknown) => say(message(cause))); return;
case "thread": navigate.toThread(command.id); return;
case "archive-thread": void archiveThread(command); return;
case "archived-threads": setArchivedOpen(true); return;
case "jump": navigate.toPluginPanel("board", { subPath: inventoryPrPath(command.prUrl) }); return;
case "resume": { const item = view?.held.find((entry) => entry.id === command.id); if (item) void movePile("resume", item); return; }
case "reopen": { const item = view?.done.find((entry) => entry.id === command.id); if (item) void movePile("reopen", item); return; }
Expand Down Expand Up @@ -792,11 +817,12 @@ export function DeckNavView({ onView, openCard = null }: { onView(target: Header
open: item.card.stats.open }] : []; })];

return <>
<ArchivedThreadsDialog open={archivedOpen} onOpenChange={(open) => { setArchivedOpen(open); if (!open) load(); }} />
<DeckPane chips={chips} cur={cur} card={card} overview={cur === "overview" && view ? overview : null} rules={rules} held={pileItems.held} done={pileItems.done} pile={pile} announce={announce}
read={{ text: view ? readText(view, now) : "Reading…", error, busy: !!view?.refreshing, onRefresh: view ? refresh.all : undefined }}
seen={{ changed: changedHere, available: context.seenAvailable, note: seenNote }}
kit={{ lines: rowLines, picked: new Set(selected.map((line) => line.prUrl)), live: batch.live, left: batch.details, working: batch.working?.prUrls,
reading: new Set([...refreshing.keys(), ...refresh.reading]), refusal: batch.refusal }}
reading: new Set([...refreshing.keys(), ...refresh.reading]), refusal: batch.refusal, archivingThread }}
open={new Set(here.open)} panel={here.panel as Panel | null} on={on} hints={hintKeys(context, on)}
flash={flash ?? (refresh.progress ? { text: refresh.progress, undo: false, busy: true } : batch.sending ? { text: batch.sending, undo: false, busy: true } : null)}
run={run} onPalette={() => runAction("palette")} onHelp={() => runAction("help")}
Expand Down
32 changes: 31 additions & 1 deletion plugins/workstreams/deck-screen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("the effort deck's markup", () => {
expect(text(html)).toContain("Wait for the store launch");
expect(text(html)).toContain("Work on folio #330");
expect(text(html)).toContain("Idle");
expect(html.match(/data-deck-thread="thr_folio_330"/gu)).toHaveLength(1);
expect(html.match(/data-deck-thread="thr_folio_330"/gu)).toHaveLength(2);
expect(html.match(/data-deck-pr-link=/gu)).toHaveLength(5);
expect(html).not.toMatch(/data-deck-pr-action|data-deck-moves|data-deck-advance|type="checkbox"/u);
});
Expand Down Expand Up @@ -402,3 +402,33 @@ describe("queued work on read cards", () => {
expect(html).not.toMatch(/data-deck-pr-action|data-inventory-action|type="checkbox"/u);
});
});


describe("thread insights on effort cards", () => {
it("shows a compact activity summary and every thread, including PR-linked workers, with archive controls", () => {
const view = inkwellDeck(inkwellThreads());
const card = view.active.find((c) => c.id === SHELF)!;
const html = pane(view, SHELF);
expect(html).toContain("data-deck-thread-summary");
expect(text(html)).toContain("Last activity");
const all = html.slice(html.indexOf("data-deck-threads"));
for (const t of card.threads) {
expect(all).toContain(`data-deck-thread="${t.id}"`);
const control = new RegExp(`data-deck-thread-archive="${t.id}"([^>]*)>`, "u").exec(all)!;
expect(control).not.toBeNull();
expect(control[1]!.includes('disabled=""')).toBe(t.status !== "idle");
}
expect(text(all)).toContain("Archived threads…");
expect(html).not.toMatch(/data-deck-pr-action/u);
});

it("keeps history reachable without live threads and disables duplicate archives while starting", () => {
const view = inkwellDeck(inkwellThreads());
const card = view.active.find((c) => c.id === SHELF)!;
const busy = pane(view, SHELF, { kit: { lines: LINES, picked: new Set(), archivingThread: card.threads[0]!.id } });
expect(text(busy)).toContain("Archiving…");
for (const m of busy.matchAll(/data-deck-thread-archive="[^"]+"([^>]*)>/gu)) expect(m[1]).toContain('disabled=""');
card.threads = [];
expect(text(pane(view, SHELF))).toContain("Archived threads…");
});
});
44 changes: 29 additions & 15 deletions plugins/workstreams/deck-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ACTION, KEY_GROUPS, type DeckActionId } from "./deck-keys";
import type { Availability, CardScreen, Chip, DeckLine, Finish, Mismatch, Move, NotesScreen, OverviewScreen, PaletteItem, Strength, SuggestGroup, TicketChip, Tone }
from "./deck-view-model";
import { SEND_DELAY_MS } from "./deck-shared";
import { effortReadSummary, prReadState, prStatuses, threadRefs, threadStatus, type PrStatus, type StatusLabel } from "./deck-status";
import { effortReadSummary, prReadState, prStatuses, threadRefs, threadStatus, threadReadSummary, type PrStatus, type StatusLabel } from "./deck-status";
import { inventoryPrPath, inventoryRoute } from "./view-preference";
import { NOTES_MAX } from "./effort-notes";
import { behind as cardsBehind, LAYERS, layerTransform } from "./deck-flip";
Expand All @@ -37,6 +37,7 @@ export type DeckCommand =
| { kind: "fold"; key: string } | { kind: "panel"; key: Panel }
| { kind: "group"; key: string } | { kind: "undo-group"; key: string } | { kind: "undo-batch"; batchId: string }
| { kind: "thread"; id: string } | { kind: "jump"; prUrl: string }
| { kind: "archive-thread"; id: string; cardId: string; title: string } | { kind: "archived-threads" }
| { kind: "resume"; id: string } | { kind: "reopen"; id: string }
| { kind: "rule-remove"; id: string } | { kind: "pile"; pile: "hold" | "done" | null }
/** The Notes panel's editor: what you typed, save (⌘↵), or cancel (esc). */
Expand Down Expand Up @@ -234,7 +235,7 @@ function Stack({ behind, run, children }: { behind: readonly Chip[]; run: Run; c
* why the last Address left a PR out; the rows a batch is planning; and the rows a Refresh is reading.
*/
export type RowKit = { lines: ReadonlyMap<string, InventoryLine>; picked: ReadonlySet<string>; live?: LiveItems; left?: ReadonlyMap<string, string>;
working?: ReadonlySet<string>; reading?: ReadonlySet<string>;
working?: ReadonlySet<string>; reading?: ReadonlySet<string>; archivingThread?: string | null;
/** Each row's ticket chip, which the card fills in from its screen. */
tickets?: ReadonlyMap<string, TicketChip>;
/** Why the last Address started nothing. */
Expand Down Expand Up @@ -308,15 +309,24 @@ function FinishLine({ finish, open, run }: { finish: Finish; open: boolean; run:
</div>;
}

function ThreadList({ threads, run, screen }: { threads: CardScreen["threads"]; run: Run; screen?: CardScreen }) {
return threads.length ? <div className="grid">{threads.map((thread) => <button key={thread.id} type="button" onClick={() => run({ kind: "thread", id: thread.id })}
data-deck-thread={thread.id} title={`Open "${thread.title}"`}
className={cn("grid min-h-9 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 rounded px-1.5 py-1 text-left text-[12px] hover:bg-foreground/[0.04]", RING)}>
<span className="min-w-0"><span className="block truncate">{thread.dot ? <><Changed title="Changed since you looked" /> </> : null}{thread.title}</span>
<small className="block truncate text-[11px] text-muted-foreground" title={screen ? threadRefs(screen, thread) : thread.ref}>
{(screen ? threadRefs(screen, thread) : thread.ref) || "Linked thread"}{thread.age ? ` · ${thread.age} ago` : ""}</small></span>
<span className={cn("text-[11.5px]", TONE[threadStatus(thread).tone].text)}>{threadStatus(thread).text}</span>
</button>)}</div> : <p className="text-[12px] text-muted-foreground">No threads yet.</p>;
function ThreadList({ threads, run, screen, archiving }: { threads: CardScreen["threads"]; run: Run; screen?: CardScreen; archiving?: string | null }) {
return threads.length ? <ul className="grid list-none">{threads.map((thread) => {
const refs = screen ? threadRefs(screen, thread) : thread.ref;
const at = screen?.card.threads.find((t) => t.id === thread.id)?.lastActivityAt;
return <li key={thread.id} className="flex min-w-0 items-center gap-1.5">
<button type="button" onClick={() => run({ kind: "thread", id: thread.id })} data-deck-thread={thread.id} title={`Open "${thread.title}"`}
className={cn("grid min-h-9 min-w-0 flex-1 grid-cols-[minmax(0,1fr)] items-center gap-x-3 gap-y-0.5 rounded px-1.5 py-1 text-left text-[12px] hover:bg-foreground/[0.04] @min-[480px]:grid-cols-[minmax(0,1fr)_auto]", RING)}>
<span className="min-w-0"><span className="block break-words @min-[480px]:truncate">{thread.dot ? <><Changed title="Changed since you looked" /> </> : null}{thread.title}</span>
<small className="block break-words text-[11px] text-muted-foreground @min-[480px]:truncate" title={`${refs || "Linked thread"}${at != null ? ` · Last activity ${new Date(at).toLocaleString()}` : ""}`}>
{refs === "parent" ? "Effort thread" : refs || "Linked thread"} · {thread.age ? `Last activity ${thread.age} ago` : "Activity unknown"}</small></span>
<span className={cn("text-[11.5px]", TONE[threadStatus(thread).tone].text)}>{threadStatus(thread).text}</span>
</button>
{screen ? <button type="button" data-deck-thread-archive={thread.id} disabled={!!archiving || thread.status !== "idle"}
aria-label={`Archive ${thread.title}`} aria-busy={archiving === thread.id || undefined}
title={thread.status === "idle" ? "Archive this idle thread. Threads with subthreads must be archived from BB." : "Only idle threads can be archived here."}
onClick={() => run({ kind: "archive-thread", id: thread.id, cardId: screen.card.id, title: thread.title })} className={cn(GHOST, "shrink-0 px-1 text-[11px]")}>{archiving === thread.id ? "Archiving…" : "Archive"}</button> : null}
</li>;
})}</ul> : <p className="text-[12px] text-muted-foreground">No threads yet.</p>;
}

function StatusBadge({ status }: { status: StatusLabel }) {
Expand Down Expand Up @@ -416,15 +426,14 @@ export function Card({ screen, kit, open, panel, run, on, notes, markdown }: { s
run: Run; on: Availability; notes?: NotesEdit | null; markdown?: (body: string) => ReactNode }) {
const { card } = screen;
const statuses = prStatuses(screen, kit.live);
const linked = new Set(statuses.flatMap((pr) => pr.thread ? [pr.thread.id] : []));
const unlinked = screen.threads.filter((thread) => !linked.has(thread.id));
const toggles = ([["notes", screen.notes ? "Notes" : null], ["linear", card.linear.known ? "Linear details" : null]] as [Panel, string | null][]).filter(([, label]) => label);
return <section data-deck-card={card.id} aria-label={card.name} className="@container min-w-0 rounded-[10px] border border-border/60 bg-background p-4">
<div className="flex min-w-0 items-start justify-between gap-3">
<div className="min-w-0"><h1 tabIndex={-1} data-deck-focus="heading" className="truncate rounded text-[20px] font-semibold tracking-tight outline-none">{card.name}</h1>
{card.goal ? <p className="mt-1 break-words text-[12.5px] text-muted-foreground">{card.goal}</p> : null}</div>
<details className="shrink-0 text-[11.5px] text-muted-foreground"><summary className={cn("cursor-pointer rounded-sm", RING)}>Manage effort</summary>
<div className="mt-2 grid gap-1">
<button type="button" onClick={() => run({ kind: "archived-threads" })} className={GHOST}>Archived threads…</button>
{card.pile === "held" ? <button type="button" onClick={() => run({ kind: "resume", id: card.id })} className={GHOST}>Resume</button>
: card.kind === "service" ? <ActionButton id="promote" on={on} run={run} label="Promote to effort…" />
: card.kind === "effort" && !card.oneOff ? <><ActionButton id="hold" on={on} run={run} label="Hold effort…" /><ActionButton id="complete" on={on} run={run} label="Complete effort…" /></> : <span>No effort changes</span>}
Expand All @@ -436,8 +445,13 @@ export function Card({ screen, kit, open, panel, run, on, notes, markdown }: { s
<PrStatusList prs={statuses} run={run} kit={kit} />
<p className="mt-2 text-[11px] text-muted-foreground">{plural(statuses.length, "open PR")} · Open a PR to advance it in All PRs.</p>
</section> : <p data-deck-empty className="py-3 text-[12px] text-muted-foreground">No open PRs.</p>}
{unlinked.length ? <section aria-label="Thread status" className="mt-3 border-t border-border/50 pt-2">
<h2 className="mb-1 text-[12px] font-medium">Threads</h2><ThreadList threads={unlinked} screen={screen} run={run} />
{screen.threads.length ? <section aria-label="Thread status" className="mt-3 border-t border-border/50 pt-2">
<details data-deck-threads open={!statuses.length || undefined}>
<summary className={cn("cursor-pointer rounded-sm text-[12px] font-medium", RING)}>Threads <span className="text-muted-foreground">{screen.threads.length}</span>
<span data-deck-thread-summary className="mt-0.5 block text-[11.5px] font-normal text-muted-foreground">{threadReadSummary(screen)}</span></summary>
<div className="mt-2"><ThreadList threads={screen.threads} screen={screen} run={run} archiving={kit.archivingThread} /></div>
<button type="button" onClick={() => run({ kind: "archived-threads" })} className={cn(GHOST, "mt-1")}>Archived threads…</button>
</details>
</section> : null}
{screen.finish || toggles.length ? <div data-deck-toggles className="mt-4 border-t border-border/50 pt-2">
{screen.finish ? <FinishLine finish={screen.finish} open={open.has("progress")} run={run} /> : null}
Expand Down
21 changes: 20 additions & 1 deletion plugins/workstreams/deck-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { inkwellDeck, INVENTORY_EFFORTS, INVENTORY_NOW } from "./inkwell-fixtures.js";
import { cardScreen } from "./deck-view-model.js";
import { prStatuses, threadRefs, threadStatus } from "./deck-status.js";
import { prStatuses, threadRefs, threadStatus, threadReadSummary } from "./deck-status.js";

const url = (repo: string, number: number) => `https://github.com/inkwell/${repo}/pull/${number}`;
const screen = () => cardScreen(inkwellDeck().active.find((card) => card.oneOff)!, { rows: {} }, { now: INVENTORY_NOW });
Expand Down Expand Up @@ -53,3 +53,22 @@ describe("visible PR and thread status", () => {
expect(threadRefs(card, thread)).toBe(card.lines.slice(0, 2).map((line) => line.ref).join(" · "));
});
});


it("summarizes needs-you and working threads and selects the newest activity even when the parent is listed first", () => {
const view = inkwellDeck();
const card = view.active[0]!;
const HOUR = 3_600_000;
card.threads = [
{ id: "parent", title: "Effort", role: "parent", prUrl: null, status: "idle", lastActivityAt: INVENTORY_NOW - 48 * HOUR },
{ id: "answer", title: "Question", role: "linked", prUrl: null, status: "idle", waiting: true, lastActivityAt: INVENTORY_NOW - 2 * HOUR },
{ id: "work", title: "Fix", role: "linked", prUrl: null, status: "active", lastActivityAt: null },
];
let s = cardScreen(card, { rows: {} }, { now: INVENTORY_NOW });
expect(threadReadSummary(s)).toContain("1 needs you");
expect(threadReadSummary(s)).toContain("1 working");
expect(threadReadSummary(s)).toContain("Last activity 2h ago");
card.threads.forEach((t) => { t.lastActivityAt = null; });
s = cardScreen(card, { rows: {} }, { now: INVENTORY_NOW });
expect(threadReadSummary(s)).not.toContain("Last activity");
});
15 changes: 15 additions & 0 deletions plugins/workstreams/deck-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,18 @@ export function effortReadSummary(screen: CardScreen, prs: readonly PrStatus[]):
if (working) return `${working} ${working === 1 ? "worker is" : "workers are"} working.`;
return prs.length ? `${prs.length} open ${prs.length === 1 ? "PR" : "PRs"}. ${screen.blocked.length ? "Waiting on dependencies or review." : "No feedback waiting on you."}` : screen.threads.length ? "No open PRs. Linked threads below." : "No open work.";
}


/** Cached thread facts only; activity is BB's last update, not another event-log fetch. */
export function threadReadSummary(screen: CardScreen): string {
const counts = new Map<string, number>();
for (const thread of screen.threads) {
const label = threadStatus(thread).text;
counts.set(label, (counts.get(label) ?? 0) + 1);
}
const parts = [...counts].map(([label, n]) => `${n} ${label === "Needs you" ? n === 1 ? "needs you" : "need you" : label.toLowerCase()}`);
const latest = screen.card.threads.filter((t) => t.lastActivityAt !== null).sort((a, b) => b.lastActivityAt! - a.lastActivityAt!)[0];
const last = latest && screen.threads.find((t) => t.id === latest.id)?.age;
if (last) parts.push(`Last activity ${last} ago`);
return parts.join(" · ");
}
Loading
Loading