Public: anyone can read this; the crew can change it.

`forge decide` prints a one-line receipt naming what was decided, on which issue or pull, and how to undo #15182

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15161-forge-decide-prints-a-one-line-receipt-n → main 3 commits fork 2 threads · 2 unresolved

  • Merged. scout/15161-forge-decide-prints-a-one-line-receipt-n was merged into main as 7506caf.

Review

Sign in to review this change.
3 files changed +57 −3
docs/features/asks-mute-undo.md +10
@@ -10,3 +10,13 @@ On `/asks`, "Mute owner/name" under a row mutes that repository. The form carrie
1010 - The toast shows only for a repository you can read.
1111 - The flash lives in the address (`?muted=<id>` / `?listened=<id>`), so a reload or a shared link shows it again, and Undo then acts on the current state. The Undo's own `back` drops the flash keys.
1212 - The terminal already does both: its asks screen mutes through the bulk "mute" verb and "listen again" lifts every mute (`src/tui/screens/dashboard.ts`), each with a toast.
13
14 ## The terminal's decision receipt
15
16 `forge asks --ship|--close|--dismiss <n…>` ends, once applied, with one line a script can read:
17
18 `Receipt op9: shipped alice/shop#1, alice/shop#3 — Undo: forge asks --undo op9`
19
20 - It names the verb and the items that actually changed: the first five, then `+N more`. The undo command is always on the line, exact.
21 - If nothing changed, it reads `Receipt op9: nothing changed, nothing to undo`.
22 - Before this, the receipt id and the undo were two lines (`Receipt <id>`, `Undo: …`); both strings are still there, on one line. Exit codes are unchanged.
src/cli/commands/asks.ts +21 −3
@@ -1,5 +1,5 @@
11 import { ForgeApi, type Ask, type Bulk } from "../api.ts";
2 import { parseWish, pickAsks, type Wish } from "../decide.ts";
2 import { parseWish, pickAsks, type Decision, type Wish } from "../decide.ts";
33 import { askLine, type Io } from "../io.ts";
44 import { parseRepoRef, type Args } from "../args.ts";
55 import { requireConfig } from "../context.ts";
@@ -127,12 +127,30 @@ async function decide(
127127 if (!done.ok) return fail(done.error);
128128 printBulk(out, done.value, wish.action, true);
129129 if (done.value.id !== undefined) {
130 out.line(`Receipt ${inert(done.value.id)}`);
131 out.line(`Undo: forge asks --undo ${inert(done.value.id)}`);
130 out.line(receipt(wish.action, done.value));
132131 }
133132 return EXIT.ok;
134133 }
135134
135 /** The most items a receipt line names; the rest are counted. */
136 const NAMED = 5;
137 const PAST = { ship: "shipped", close: "closed", dismiss: "dismissed" } as const;
138
139 /**
140 * One line: the receipt id, what was decided on which issues or pulls, and
141 * the exact command that undoes it. Only rows that changed are named, the
142 * first few, then a count; if none changed, it says so and offers no undo.
143 */
144 function receipt(action: Decision, bulk: Bulk): string {
145 const id = inert(bulk.id ?? "");
146 const named = bulk.rows.filter((r) => r.outcome !== "unchanged" && r.outcome !== "refused");
outdated

If named is empty, what is '' and the line reads 'shipped — Undo'. Handle the empty case explicitly (say nothing changed) and test it. Consider capping the named list with '+N more'.

147 if (named.length === 0) return `Receipt ${id}: nothing changed, nothing to undo`;
148 const shown = named.slice(0, NAMED);
149 const more = named.length > NAMED ? ` +${named.length - NAMED} more` : "";
150 const what = shown.map((r) => inert(r.label)).join(", ") + more;
151 return `Receipt ${id}: ${PAST[action]} ${what} — Undo: forge asks --undo ${id}`;
152 }
153
136154 function printBulk(out: Out, bulk: Bulk, action: string, done: boolean): void {
137155 out.line(done ? `Applied: ${action}` : `Would ${action}:`);
138156 for (const r of bulk.rows) {
test/cli-asks-decide.test.ts +26
@@ -108,6 +108,32 @@ test("a yes applies once and prints the receipt and the undo line", async () =>
108108 expect(r.out).toContain(`Undo: forge asks --undo op9`);
109109 });
110110
111 test("the receipt is one line: what was decided, on which items, and the exact undo", async () => {
112 const r = await run(["--ship", "1", "3"], async () => true);
113 const lines = r.out.split("\n").filter((l) => l.startsWith("Receipt"));
114 expect(lines).toEqual(["Receipt op9: shipped look:1, pr:3 — Undo: forge asks --undo op9"]);
115 expect(r.code).toBe(EXIT.ok);
116 });

Add a case where all rows come back unchanged/refused; this test only covers the all-changed path.

117
118 test("a receipt with no changed row says nothing changed and offers no undo", async () => {
119 const base = bulkReply;
120 bulkReply = (body) =>
121 body.preview === false
122 ? Response.json({ preview: false, id: "op9", rows: body.items.map((i: string) => ({ label: i, outcome: i === "look:1" ? "unchanged" : "refused", before: "open", after: "open" })), skipped: [] }, { status: 201 })
123 : base(body);
124 const r = await run(["--ship", "1", "3"], async () => true);
125 const lines = r.out.split("\n").filter((l) => l.startsWith("Receipt"));
126 expect(lines).toEqual(["Receipt op9: nothing changed, nothing to undo"]);
127 expect(r.out).not.toContain("shipped");
128 });
129
130 test("a large batch names the first five and counts the rest, undo kept", async () => {
131 ids = Array.from({ length: 8 }, (_, i) => `look:${i + 1}`);
132 const r = await run(["--ship", "1", "2", "3", "4", "5", "6", "7", "8"], async () => true);
133 const line = r.out.split("\n").find((l) => l.startsWith("Receipt"))!;
134 expect(line).toBe("Receipt op9: shipped look:1, look:2, look:3, look:4, look:5 +3 more — Undo: forge asks --undo op9");
135 });
136
111137 test("--yes skips the question", async () => {
112138 const r = await run(["--dismiss", "1", "--yes"], async () => {
113139 throw new Error("asked");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs