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

An archived app can be brought back in one tap from a list of archived apps #14227

Merged opened this

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

Merged

scout/forge:scout/14108-an-archived-app-can-be-brought-back-in-o → main 7 commits fork 1 thread · 1 unresolved

  • Merged. scout/14108-an-archived-app-can-be-brought-back-in-o was merged into main as c70cd9a.

Review

Sign in to review this change.
7 files changed +104 −26
docs/MCP.md +1 −1
@@ -64,7 +64,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`;
6464 | `app_env` | `list`, `set`, `unset`, `variable`, `secret` | An app's environment variables: list, set or unset by scope; a secret is write-only, a variable is shown | 474 |
6565 | `app_members` | — | People a private app names, who may enter it and its previews | 297 |
6666 | `app_notes` | `hide`, `ban`, `unban` | Notes from an app's forge button and banned senders; hide a note, ban or unban its sender | 306 |
67 | `apps` | — | Apps you can see: live or not, where served, how each runs, what works | 384 |
67 | `apps` | — | Apps you can see: live or not, where served, how each runs, what works | 375 |
6868 | `archive` | — | Archive or wake a repository (`archived`) | 421 |
6969 | `asked` | — | What people asked the crew for: unmerged by default, oldest first | 415 |
7070 | `asks` | `stopped`, `look`, `review`, `paused`, `parked`, `declined`, `handover`, `waiting`, `assigned`, `proposal` | What waits on you, most important first; saved filter applies; `filter` sets or clears one | 749 |
docs/features/app-archive.md +4 −1
@@ -7,6 +7,9 @@ Receipt: the next page says the app is stopped, hidden from home and `/apps`, an
77 - **Stops:** production and every preview spin down (`moveArchive`, `src/actions/repos.ts`).
88 - **Hidden:** home and `/apps` leave it out; `/apps?archived=1` lists it, and `/apps` says how many are archived.
99 - **Reachable:** its URL, clone and push keep working. The page carries an "Archived on <date>" banner (`archivedLine`, `src/web/pages/following.ts`), with Restore for an admin.
10 - **Restore:** every web door is a link to the confirm page, which previews it and posts to `/:owner/:name/restore`; the receipt lands where the door was. Settings and the banner come back to settings; the archived list (`/apps?archived=1`) and the standing bar's "Turn it back on" (`/apps?off=<id>`) carry `next=` and come back to their list. The app is listed again and wakes on its next visit. `/:owner/:name/settings/archive` with `archived=0|1` still answers, but no page posts to it any more.
10 - **Bring back:** the archived list (`/apps?archived=1`) has a Bring back button under each app you administer: one same-origin post to `/:owner/:name/restore`, no confirm page, and the receipt lands on the list.
11 - **Restore:** every web door but one is a link to the confirm page, which previews it and posts to `/:owner/:name/restore`; the receipt lands where the door was. Settings and the banner come back to settings; the standing bar's "Turn it back on" (`/apps?off=<id>`) carry `next=` and come back to their list. The app is listed again and wakes on its next visit. `/:owner/:name/settings/archive` with `archived=0|1` still answers, but no page posts to it any more.
12
13 MCP `apps` with `{ action: "restore", repo }` (admin token) does the same as Restore.
1114
1215 Terminal: the Archived repositories screen (`src/tui/screens/archived.ts`); MCP: the `archive` tool. Test: `test/app-archive.test.ts`.
src/http/mcp/tools/apps.ts +21 −2
@@ -8,11 +8,15 @@ import { getAppByRepo } from "../../../core/apps.ts";
88 import { migrationsOf, originFor, readProgress, progressWords } from "../../../apps/migration_mode.ts";
99 import { repoDir } from "../../../git/repos.ts";
1010 import { requireWriter } from "../../../actions/access.ts";
11 import { scopeAllows } from "../../../core/tokens.ts";
12 import { getRepo } from "../../../core/repos.ts";
13 import { setArchived } from "../../../actions/repos.ts";
14 import { RESTORED_RECEIPT } from "../../../core/archive-words.ts";
1115 import { bad, good, isAnswer, repoArg, type Tool } from "../shared.ts";
1216
1317 export const tool: Tool = {
1418 name: "apps",
15 doc: "`{ archived? }`: your apps (`ui://forge/app` card): live or not, what is working, running `previews`, `crew` with a run now, and in migration mode `mode` and `migration {origin, done, total, state}` (`origin` is null to someone who may not see a private source). `{ repo, pulls: true, limit? }`: an adapter's pull runs, as `GET …/app/pulls` (`limit`); a reader's",
19 doc: "`{ action: \"restore\", repo? }` brings an archived app back (admin token); `{ archived? }`: your apps (`ui://forge/app` card): live or not, what is working, running `previews`, `crew` with a run now, and in migration mode `mode` and `migration {origin, done, total, state}` (`origin` is null to someone who may not see a private source). `{ repo, pulls: true, limit? }`: an adapter's pull runs, as `GET …/app/pulls` (`limit`); a reader's",
1620 description:
1721 "Apps you can see: live or not, where served, how each runs, what works.",
1822 inputSchema: {
@@ -22,10 +26,25 @@ export const tool: Tool = {
2226 repo: { type: "string" },
2327 pulls: { type: "boolean" },
2428 limit: { type: "integer" },
29 action: { type: "string" },
2530 },
2631 },
27 writes: false,
32 writes: true,
33 readsWithout: "action",
2834 async run(ctx, user, args) {
35 if (args["action"] !== undefined) {
36 if (args["action"] !== "restore") return bad("invalid", "`action` is restore");
37 const repo = repoArg(ctx, user, args);
38 if (isAnswer(repo)) return repo;
39 if (!scopeAllows(ctx.auth.scope ?? "ro", "admin"))
40 return bad("forbidden", "restoring needs an admin token");
41 const name = `${repo.ownerName}/${repo.name}`;
42 if (repo.archivedAt === null) return good({ app: name, archived: false, says: "Already awake." });
43 const set = await setArchived(ctx.app, user, repo, false, false);
44 if (!set.ok) return bad("forbidden", "only an admin of this repository restores it");
45 const stored = getRepo(ctx.app.db, repo.ownerName, repo.name) ?? repo;
46 return good({ app: name, archived: stored.archivedAt !== null, says: RESTORED_RECEIPT });
47 }
2948 if (args["pulls"] !== undefined) {
3049 if (args["pulls"] !== true) return bad("invalid", "`pulls` is true");
3150 const repo = repoArg(ctx, user, args);
src/web/pages/apps.ts +6 −6
@@ -12,7 +12,6 @@
1212 * 404 for everyone.
1313 */
1414
15 import { archiveConfirmHref } from "./following.ts";
1615 import { appsStanding } from "../studio/standing.ts";
1716 import { stepsOf } from "../../core/review_steps.ts";
1817 import { USERNAME_PATTERN } from "../username_pattern.ts";
@@ -160,8 +159,8 @@ export function archivedAppCount(ctx: Ctx): number {
160159 }
161160
162161 /**
163 * The archived list's Restore: a link through the confirm page under each row the viewer
164 * administers.
162 * The archived list's Bring back: one tap, a same-origin form post (restoring is undone by
163 * archiving) that lands back on the list with the receipt, under each row the viewer administers.
165164 */
166165 function restoreForms(ctx: Ctx, repos: readonly Repo[]): Map<string, Html> {
167166 const out = new Map<string, Html>();
@@ -170,9 +169,10 @@ function restoreForms(ctx: Ctx, repos: readonly Repo[]): Map<string, Html> {
170169 out.set(
171170 repo.id,
172171 html`<li>
173 ${btn(html`Restore<span class="sr-only"> ${repo.ownerName}/${repo.name}</span>`, {
174 href: archiveConfirmHref(repo, "restore", "/apps?archived=1"),
175 })}
172 <form method="post" action="${repoBase(repo)}/restore">
173 <input type="hidden" name="next" value="/apps?archived=1" />
174 ${btn(html`Bring back<span class="sr-only"> ${repo.ownerName}/${repo.name}</span>`)}
175 </form>
176176 </li>`,
177177 );
178178 }
test/apps-archived.test.ts +15 −15
@@ -57,8 +57,8 @@ afterAll(() => {
5757
5858 const ROW_KEEPER = '<a href="/alice/keeper" class="row"';
5959 const ROW_SHELVED = '<a href="/alice/shelved" class="row"';
60 const get = async (path: string) => {
61 const res = await fetch(`${servers.url}${path}`, { headers: { cookie } });
60 const get = async (path: string, extra = "") => {
61 const res = await fetch(`${servers.url}${path}`, { headers: { cookie: cookie + extra } });
6262 return { status: res.status, body: await res.text() };
6363 };
6464
@@ -133,20 +133,17 @@ test("the stylesheet carries no merge-conflict markers", async () => {
133133 expect(content).not.toContain(".filters");
134134 });
135135
136 test("the archived list's Restore previews, then wakes the app in place, and ignores a return address off this origin", async () => {
136 test("the archived list's Bring back wakes the app in one tap, with a receipt,, and ignores a return address off this origin", async () => {
137137 await updateRepoSettings(app, alice, getRepo(app.db, "alice", "shelved")!, { archived: true });
138138 const list = (await get("/apps?archived=1")).body;
139 // A link to the confirm page, carrying the list as the way back; no post from the list itself.
140 const href = "/-/confirm?to=%2Falice%2Fshelved%2Frestore&amp;next=%2Fapps%3Farchived%3D1";
141 expect(list).toContain(`href="${href}"`);
142 expect(list).not.toContain("settings/archive");
143 const confirm = await get(href.replace("&amp;", "&"));
144 expect(confirm.body).toContain("Restore alice/shelved?");
145 expect(confirm.body).toContain('action="/alice/shelved/restore"');
146 expect(confirm.body).toContain('name="next" value="/apps?archived=1"');
139 // One tap: a same-origin form post from the list itself, no confirm page, and the list as the way
140 // back.
141 expect(list).toContain('action="/alice/shelved/restore"');
142 expect(list).toContain('name="next" value="/apps?archived=1"');
143 expect(list).not.toContain("/-/confirm?to=%2Falice%2Fshelved");
147144 expect(getRepo(app.db, "alice", "shelved")!.archivedAt).not.toBeNull();
148 // Each button names its app, so a screen reader can tell the Wakes apart.
149 expect(list).toMatch(/Restore<span class="sr-only"> alice\/shelved<\/span>/);
145 // Each button names its app, so a screen reader can tell them apart.
146 expect(list).toMatch(/Bring back<span class="sr-only"> alice\/shelved<\/span>/);
150147 const post = (to: string, headers: Record<string, string> = { origin: servers.url }) =>
151148 fetch(`${servers.url}/alice/shelved/restore`, {
152149 method: "POST",
@@ -162,7 +159,10 @@ test("the archived list's Restore previews, then wakes the app in place, and ign
162159 expect(woke.status).toBe(303);
163160 const back = new URL(woke.headers.get("location")!, servers.url);
164161 expect(back.pathname + back.search).toBe("/apps?archived=1");
165 expect((await get("/apps?archived=1")).body).not.toContain(ROW_SHELVED);
162 const flash = woke.headers.getSetCookie().map((c) => `; ${c.split(";")[0]!}`).join("");
163 const landed = await get("/apps?archived=1", flash);
164 expect(landed.body).toContain("Restored. It is back on home and the apps list.");
165 expect(landed.body).not.toContain(ROW_SHELVED);
166166 expect((await get("/apps")).body).toContain(ROW_SHELVED);
167167 for (const bad of ["https://evil.example/", "//evil.example", "/\\evil.example"]) {
168168 await updateRepoSettings(app, alice, getRepo(app.db, "alice", "shelved")!, { archived: true });
@@ -181,7 +181,7 @@ test("a viewer who does not administer an archived app gets no Wake button", asy
181181 const anon = await (await fetch(`${servers.url}/apps?archived=1`)).text();
182182 expect(anon).toContain('<a href="/alice/openshelf" class="row"');
183183 expect(anon).not.toContain("openshelf%2Frestore");
184 expect((await get("/apps?archived=1")).body).toContain("/-/confirm?to=%2Falice%2Fopenshelf%2Frestore");
184 expect((await get("/apps?archived=1")).body).toContain("/alice/openshelf/restore");
185185 });
186186
187187 test("one tap: the app's page offers Archive through the confirm page, which archives and Restore undoes", async () => {
test/conversation-confirm.test.ts +1 −1
@@ -121,7 +121,7 @@ describe("the one list of what asks first", () => {
121121 // settings and can be put back (`system` previews and does only on its own `confirm:true`). A new
122122 // `writes: true` tool is on neither list until someone decides.
123123 const NOT_ASKED = new Set([
124 "access", "account_requests", "account_verify", "app_members", "app_notes", "asks_act", "asks_decide", "asks_proposal", "asks_undecide", "atlas",
124 "access", "account_requests", "apps", "account_verify", "app_members", "app_notes", "asks_act", "asks_decide", "asks_proposal", "asks_undecide", "atlas",
125125 "asks", "assign", "attach_look", "bet", "board_pins", "board_write", "branches", "capacity", "valves", "cloud_accounts", "close", "confirm_wait",
126126 "crew", "decisions_by", "desk", "detach", "economics", "edit", "email_verify", "estimate", "feed_chips", "feed_dismiss", "feed_like", "flag_set", "flag_winner",
127127 "follow_mode", "forge", "fork", "front_page", "hold", "issue_teams", "keep_plan", "knobs", "labels", "lift", "limb", "maintenance", "make_it_yours", "map", "merge", "new_app",
test/mcp-apps-archived.test.ts +56
@@ -5,6 +5,7 @@ import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 import { createApp, type App } from "../src/app.ts";
77 import { newApp } from "../src/actions/apps.ts";
8 import { setArchived } from "../src/actions/repos.ts";
89 import { getRepo } from "../src/core/repos.ts";
910 import { createUser, getUserByName } from "../src/core/users.ts";
1011 import { serve, type Servers } from "../src/http/server.ts";
@@ -89,3 +90,58 @@ describe("MCP apps archived", () => {
8990 }
9091 });
9192 });
93
94 describe("MCP apps action restore", () => {
95 let dataDir: string;
96 let app: App;
97 let servers: Servers;
98 let alice: string;
99 let aliceRw: string;
100 let bob: string;
101 let id = 1;
102 const call = async (token: string, args: unknown) => {
103 const res = await fetch(`${servers.url}/mcp`, {
104 method: "POST",
105 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` },
106 body: JSON.stringify({ jsonrpc: "2.0", id: id++, method: "tools/call", params: { name: "apps", arguments: args } }),
107 });
108 const body: any = await res.json();
109 const text: string = body.result.content[0].text;
110 return body.result.isError === true ? { error: text } : { value: JSON.parse(text) as any };
111 };
112 beforeAll(async () => {
113 dataDir = await mkdtemp(join(tmpdir(), "forge-mcp-apps-restore-"));
114 app = createApp({ dataDir, port: 0 });
115 servers = await serve(app);
116 await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" });
117 const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" });
118 if (!b.ok) throw new Error(b.error);
119 promote(app.db, b.value);
120 const made = await newApp(app, getUserByName(app.db, "alice")!, { name: "shelf", visibility: "public" });
121 if (!made.ok) throw new Error(String(made.error));
122 alice = tokenFor(app, "alice", "admin");
123 aliceRw = tokenFor(app, "alice", "rw");
124 bob = tokenFor(app, "bob", "admin");
125 }, 30_000);
126 afterAll(async () => {
127 servers.stop();
128 app.close();
outdated

Archive through the real action instead of a raw SQL update, so the test covers the round trip.

129 await rm(dataDir, { recursive: true, force: true });
130 });
131
132 test("archives, refuses a non-owner, restores with a receipt", async () => {
133 const put = await setArchived(app, getUserByName(app.db, "alice")!, getRepo(app.db, "alice", "shelf")!, true, false);
134 expect(put.ok).toBe(true);
135 expect((await call(alice, { archived: true })).value.map((a: any) => a.app)).toEqual(["alice/shelf"]);
136 const no = await call(bob, { action: "restore", repo: "alice/shelf" });
137 expect(no.error).toBeDefined();
138 expect(getRepo(app.db, "alice", "shelf")!.archivedAt).not.toBeNull();
139 expect((await call(aliceRw, { action: "restore", repo: "alice/shelf" })).error).toMatch(/admin token/);
140 expect((await call(alice, { action: "bury", repo: "alice/shelf" })).error).toMatch(/restore/);
141 const done = await call(alice, { action: "restore", repo: "alice/shelf" });
142 expect(done.value.says).toBe("Restored. It is back on home and the apps list.");
143 expect(getRepo(app.db, "alice", "shelf")!.archivedAt).toBeNull();
144 expect((await call(alice, {})).value.map((a: any) => a.app)).toEqual(["alice/shelf"]);
145 expect((await call(alice, { archived: true })).value).toEqual([]);
146 });
147 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs