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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14108-an-archived-app-can-be-brought-back-in-o → main 7 commits fork 1 thread · 1 unresolved
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`; | ||
| 64 | 64 | | `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 | |
| 65 | 65 | | `app_members` | — | People a private app names, who may enter it and its previews | 297 | |
| 66 | 66 | | `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 | | |
| 68 | 68 | | `archive` | — | Archive or wake a repository (`archived`) | 421 | |
| 69 | 69 | | `asked` | — | What people asked the crew for: unmerged by default, oldest first | 415 | |
| 70 | 70 | | `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 | ||
| 7 | 7 | - **Stops:** production and every preview spin down (`moveArchive`, `src/actions/repos.ts`). |
| 8 | 8 | - **Hidden:** home and `/apps` leave it out; `/apps?archived=1` lists it, and `/apps` says how many are archived. |
| 9 | 9 | - **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. | |
| 11 | 14 | |
| 12 | 15 | 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"; | ||
| 8 | 8 | import { migrationsOf, originFor, readProgress, progressWords } from "../../../apps/migration_mode.ts"; |
| 9 | 9 | import { repoDir } from "../../../git/repos.ts"; |
| 10 | 10 | 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"; | |
| 11 | 15 | import { bad, good, isAnswer, repoArg, type Tool } from "../shared.ts"; |
| 12 | 16 | |
| 13 | 17 | export const tool: Tool = { |
| 14 | 18 | 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", | |
| 16 | 20 | description: |
| 17 | 21 | "Apps you can see: live or not, where served, how each runs, what works.", |
| 18 | 22 | inputSchema: { |
| @@ -22,10 +26,25 @@ export const tool: Tool = { | ||
| 22 | 26 | repo: { type: "string" }, |
| 23 | 27 | pulls: { type: "boolean" }, |
| 24 | 28 | limit: { type: "integer" }, |
| 29 | action: { type: "string" }, | |
| 25 | 30 | }, |
| 26 | 31 | }, |
| 27 | writes: false, | |
| 32 | writes: true, | |
| 33 | readsWithout: "action", | |
| 28 | 34 | 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 | } | |
| 29 | 48 | if (args["pulls"] !== undefined) { |
| 30 | 49 | if (args["pulls"] !== true) return bad("invalid", "`pulls` is true"); |
| 31 | 50 | const repo = repoArg(ctx, user, args); |
src/web/pages/apps.ts +6 −6
| @@ -12,7 +12,6 @@ | ||
| 12 | 12 | * 404 for everyone. |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | import { archiveConfirmHref } from "./following.ts"; | |
| 16 | 15 | import { appsStanding } from "../studio/standing.ts"; |
| 17 | 16 | import { stepsOf } from "../../core/review_steps.ts"; |
| 18 | 17 | import { USERNAME_PATTERN } from "../username_pattern.ts"; |
| @@ -160,8 +159,8 @@ export function archivedAppCount(ctx: Ctx): number { | ||
| 160 | 159 | } |
| 161 | 160 | |
| 162 | 161 | /** |
| 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. | |
| 165 | 164 | */ |
| 166 | 165 | function restoreForms(ctx: Ctx, repos: readonly Repo[]): Map<string, Html> { |
| 167 | 166 | const out = new Map<string, Html>(); |
| @@ -170,9 +169,10 @@ function restoreForms(ctx: Ctx, repos: readonly Repo[]): Map<string, Html> { | ||
| 170 | 169 | out.set( |
| 171 | 170 | repo.id, |
| 172 | 171 | 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> | |
| 176 | 176 | </li>`, |
| 177 | 177 | ); |
| 178 | 178 | } |
test/apps-archived.test.ts +15 −15
| @@ -57,8 +57,8 @@ afterAll(() => { | ||
| 57 | 57 | |
| 58 | 58 | const ROW_KEEPER = '<a href="/alice/keeper" class="row"'; |
| 59 | 59 | 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 } }); | |
| 62 | 62 | return { status: res.status, body: await res.text() }; |
| 63 | 63 | }; |
| 64 | 64 | |
| @@ -133,20 +133,17 @@ test("the stylesheet carries no merge-conflict markers", async () => { | ||
| 133 | 133 | expect(content).not.toContain(".filters"); |
| 134 | 134 | }); |
| 135 | 135 | |
| 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 () => { | |
| 137 | 137 | await updateRepoSettings(app, alice, getRepo(app.db, "alice", "shelved")!, { archived: true }); |
| 138 | 138 | 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&next=%2Fapps%3Farchived%3D1"; | |
| 141 | expect(list).toContain(`href="${href}"`); | |
| 142 | expect(list).not.toContain("settings/archive"); | |
| 143 | const confirm = await get(href.replace("&", "&")); | |
| 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"); | |
| 147 | 144 | 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>/); | |
| 150 | 147 | const post = (to: string, headers: Record<string, string> = { origin: servers.url }) => |
| 151 | 148 | fetch(`${servers.url}/alice/shelved/restore`, { |
| 152 | 149 | method: "POST", |
| @@ -162,7 +159,10 @@ test("the archived list's Restore previews, then wakes the app in place, and ign | ||
| 162 | 159 | expect(woke.status).toBe(303); |
| 163 | 160 | const back = new URL(woke.headers.get("location")!, servers.url); |
| 164 | 161 | 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); | |
| 166 | 166 | expect((await get("/apps")).body).toContain(ROW_SHELVED); |
| 167 | 167 | for (const bad of ["https://evil.example/", "//evil.example", "/\\evil.example"]) { |
| 168 | 168 | 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 | ||
| 181 | 181 | const anon = await (await fetch(`${servers.url}/apps?archived=1`)).text(); |
| 182 | 182 | expect(anon).toContain('<a href="/alice/openshelf" class="row"'); |
| 183 | 183 | 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"); | |
| 185 | 185 | }); |
| 186 | 186 | |
| 187 | 187 | 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", () => { | ||
| 121 | 121 | // settings and can be put back (`system` previews and does only on its own `confirm:true`). A new |
| 122 | 122 | // `writes: true` tool is on neither list until someone decides. |
| 123 | 123 | 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", | |
| 125 | 125 | "asks", "assign", "attach_look", "bet", "board_pins", "board_write", "branches", "capacity", "valves", "cloud_accounts", "close", "confirm_wait", |
| 126 | 126 | "crew", "decisions_by", "desk", "detach", "economics", "edit", "email_verify", "estimate", "feed_chips", "feed_dismiss", "feed_like", "flag_set", "flag_winner", |
| 127 | 127 | "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"; | ||
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { createApp, type App } from "../src/app.ts"; |
| 7 | 7 | import { newApp } from "../src/actions/apps.ts"; |
| 8 | import { setArchived } from "../src/actions/repos.ts"; | |
| 8 | 9 | import { getRepo } from "../src/core/repos.ts"; |
| 9 | 10 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 10 | 11 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -89,3 +90,58 @@ describe("MCP apps archived", () => { | ||
| 89 | 90 | } |
| 90 | 91 | }); |
| 91 | 92 | }); |
| 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(); | |
| 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 | }); |
new above
offline
Archive through the real action instead of a raw SQL update, so the test covers the round trip.