Public: anyone can read this; the crew can change it.
Archive, part 2a: an archived repository leaves the home's apps, the explorer's default view and the inbox #2499
scout/forge:scout/2454-archive-part-2a-an-archived-repository-l → main 5 commits fork
14 files
changed +135
−6
README.md +8
| @@ -316,11 +316,18 @@ An admin puts a repository away from **Settings → Archive**, with | ||
| 316 | 316 | else gets 403), or in the terminal with `a` on the About card (`I`). The |
| 317 | 317 | repository page and the card then say when it was archived, and an admin gets |
| 318 | 318 | a Wake button or the same key to undo it. Archiving twice keeps the first date. |
| 319 | An archived repository leaves the home, the explore list and the asks; its page still answers by its link. | |
| 320 | In explore, `archived:yes` (or the Show archived toggle) brings archived repositories back. | |
| 321 | The terminal home hides archived repositories too, though its typed filter still finds them. | |
| 319 | 322 | An archived repository starts no new crew run. Assigning an issue to an agent, |
| 320 | 323 | queueing a run again, asking the crew to propose a resolution, redirecting a |
| 321 | 324 | wave and converging a fork each answer "This repository is archived; wake it to |
| 322 | 325 | start a run."; the API answers 409 `archived`, and the terminal and MCP show |
| 323 | 326 | the same line. The autonomy tick skips it. A run already going finishes, and |
| 327 | <<<<<<< HEAD | |
| 328 | Wake undoes all of it. Clone, push and links keep working, and the | |
| 329 | repository still appears in `/apps`, search, the palette and the repository API. | |
| 330 | ======= | |
| 324 | 331 | Wake undoes all of it. Clone, push and links keep working, and the repository |
| 325 | 332 | page still answers. |
| 326 | 333 | |
| @@ -329,6 +336,7 @@ you there included, and the terminal's and MCP's asks), the stalled-steps | ||
| 329 | 336 | reader and the explorer's default view; `/explore` shows it with `archived:yes` |
| 330 | 337 | (the **Show archived** toggle). It stays in `/apps`, search, the palette and |
| 331 | 338 | the repository API (`GET /api/v1/repos`). |
| 339 | >>>>>>> origin/main | |
| 332 | 340 | |
| 333 | 341 | ## Health |
| 334 | 342 |
src/actions/explore.ts +11 −1
| @@ -2,7 +2,8 @@ | ||
| 2 | 2 | * Explore (#607): the apps, people and forges a viewer can see, ranked by |
| 3 | 3 | * the same real signals the front page uses (`core/front.ts`: forks by |
| 4 | 4 | * people, pulls merged, hours awake, the last merge), each row with its |
| 5 | * numbers, narrowed in one line: `kind:app sort:forks garden`. The page, | |
| 5 | * numbers, narrowed in one line: `kind:app sort:forks garden`. Repositories put away | |
| 6 | * (archived) are left out unless the line says `archived:yes`. The page, | |
| 6 | 7 | * `/api/v1/explore` and the MCP tool `explore` all answer from here. |
| 7 | 8 | * |
| 8 | 9 | * - Only what the viewer may read: repositories by `listReposVisibleTo`; an |
| @@ -42,7 +43,11 @@ export interface ExploreQuery { | ||
| 42 | 43 | readonly sort: ExploreSort; |
| 43 | 44 | /** Words a row's name, owner or description must contain. */ |
| 44 | 45 | readonly text: string; |
| 46 | <<<<<<< HEAD | |
| 47 | /** Show repositories that are put away too (`archived:yes`). */ | |
| 48 | ======= | |
| 45 | 49 | /** `archived:yes` — put-away repositories are in the list; off, they are not. */ |
| 50 | >>>>>>> origin/main | |
| 46 | 51 | readonly archived: boolean; |
| 47 | 52 | } |
| 48 | 53 | |
| @@ -89,8 +94,13 @@ export function parseExploreQuery(line: string): ExploreQuery { | ||
| 89 | 94 | (SORTS as readonly string[]).includes(value.toLowerCase()) |
| 90 | 95 | ) |
| 91 | 96 | sort = value.toLowerCase() as ExploreSort; |
| 97 | <<<<<<< HEAD | |
| 98 | else if (k === "archived" && value !== "") | |
| 99 | archived = ["yes", "true", "1", "show"].includes(value.toLowerCase()); | |
| 100 | ======= | |
| 92 | 101 | else if (k === "archived" && ["yes", "no"].includes(value.toLowerCase())) |
| 93 | 102 | archived = value.toLowerCase() === "yes"; |
| 103 | >>>>>>> origin/main | |
| 94 | 104 | else if (k === "q" && value !== "") words.push(value); |
| 95 | 105 | else words.push(word); |
| 96 | 106 | } |
src/core/asked.ts +4
| @@ -117,10 +117,14 @@ export function askedRepos( | ||
| 117 | 117 | viewer: User | undefined, |
| 118 | 118 | repoSpec: string | null | undefined, |
| 119 | 119 | ): readonly Repo[] { |
| 120 | <<<<<<< HEAD | |
| 121 | const writable = listReposWritableTo(db, viewer, { limit: 200, withoutArchived: true }); | |
| 122 | ======= | |
| 120 | 123 | const writable = listReposWritableTo(db, viewer, { |
| 121 | 124 | limit: 200, |
| 122 | 125 | withoutArchived: true, |
| 123 | 126 | }); |
| 127 | >>>>>>> origin/main | |
| 124 | 128 | if (repoSpec === null || repoSpec === undefined || repoSpec === "") |
| 125 | 129 | return writable; |
| 126 | 130 | const [owner, name, ...rest] = repoSpec.split("/"); |
src/core/repos.ts +8
| @@ -649,10 +649,16 @@ export interface ListReposOptions { | ||
| 649 | 649 | cursor?: string; |
| 650 | 650 | /** Repositories that run an app first, each half newest first (not with `cursor`). */ |
| 651 | 651 | appsFirst?: boolean; |
| 652 | <<<<<<< HEAD | |
| 653 | /** Leave out repositories that are put away (`archived_at` set). */ | |
| 654 | ======= | |
| 652 | 655 | /** Leave archived repositories out. @default false */ |
| 656 | >>>>>>> origin/main | |
| 653 | 657 | withoutArchived?: boolean; |
| 654 | 658 | } |
| 655 | 659 | |
| 660 | const NOT_ARCHIVED = " AND repo.archived_at IS NULL"; | |
| 661 | ||
| 656 | 662 | // Visibility in SQL: public, owned, or owned by an org the viewer is on a |
| 657 | 663 | // team of. Site admins see everything. The same rule canRead applies, so a |
| 658 | 664 | // listing never shows a repo whose page would 404. |
| @@ -677,6 +683,7 @@ export function listReposVisibleTo( | ||
| 677 | 683 | where += ` AND (repo.name LIKE ?${p} ESCAPE '\\' COLLATE NOCASE |
| 678 | 684 | OR user.username LIKE ?${p} ESCAPE '\\' COLLATE NOCASE)`; |
| 679 | 685 | } |
| 686 | if (options.withoutArchived === true) where += NOT_ARCHIVED; | |
| 680 | 687 | if (options.cursor !== undefined) { |
| 681 | 688 | params.push(options.cursor); |
| 682 | 689 | where += ` AND repo.id < ?${params.length}`; |
| @@ -712,6 +719,7 @@ export function listReposWritableTo( | ||
| 712 | 719 | where += ` AND (repo.name LIKE ?${p} ESCAPE '\\' COLLATE NOCASE |
| 713 | 720 | OR user.username LIKE ?${p} ESCAPE '\\' COLLATE NOCASE)`; |
| 714 | 721 | } |
| 722 | if (options.withoutArchived === true) where += NOT_ARCHIVED; | |
| 715 | 723 | if (options.cursor !== undefined) { |
| 716 | 724 | params.push(options.cursor); |
| 717 | 725 | where += ` AND repo.id < ?${params.length}`; |
src/flow/stalled.ts +4
| @@ -49,10 +49,14 @@ interface RunRow { | ||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | export function readStalled(db: Database, viewer: User, now: Date): StalledStep[] { |
| 52 | <<<<<<< HEAD | |
| 53 | const repos = listReposWritableTo(db, viewer, { limit: REPOS_MAX, withoutArchived: true }); | |
| 54 | ======= | |
| 52 | 55 | const repos = listReposWritableTo(db, viewer, { |
| 53 | 56 | limit: REPOS_MAX, |
| 54 | 57 | withoutArchived: true, |
| 55 | 58 | }); |
| 59 | >>>>>>> origin/main | |
| 56 | 60 | if (repos.length === 0) return []; |
| 57 | 61 | const byId = new Map(repos.map((r) => [r.id, r])); |
| 58 | 62 | const ids = [...byId.keys()]; |
src/http/mcp.ts +1 −1
| @@ -1695,7 +1695,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1695 | 1695 | { |
| 1696 | 1696 | name: "explore", |
| 1697 | 1697 | description: |
| 1698 | "The apps, people (and, for a site admin, spawned forges) you can see, ranked by forks by people, pulls merged this month, hours in use and how lately they shipped, each with its numbers. `query` is one line: `kind:app|person|forge`, `sort:score|forks|ships|use|fresh|name`, and words to match. The same rows as /explore and /api/v1/explore.", | |
| 1698 | "The apps, people (and, for a site admin, spawned forges) you can see, ranked by forks by people, pulls merged this month, hours in use and how lately they shipped, each with its numbers. `query` is one line: `kind:app|person|forge`, `sort:score|forks|ships|use|fresh|name`, `archived:yes` to include archived repositories (left out otherwise), and words to match. The same rows as /explore and /api/v1/explore.", | |
| 1699 | 1699 | inputSchema: { |
| 1700 | 1700 | type: "object", |
| 1701 | 1701 | properties: { query: { type: "string", maxLength: 200 } }, |
src/tui/screens/dashboard.ts +5 −4
| @@ -180,7 +180,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 180 | 180 | holds = new Map( |
| 181 | 181 | all.flatMap((repo) => { |
| 182 | 182 | const hold = |
| 183 | repo.autonomy === "autonomous" ? plannerHold(f.app, repo, now) : null; | |
| 183 | repo.autonomy === "autonomous" && repo.archivedAt === null ? plannerHold(f.app, repo, now) : null; | |
| 184 | 184 | return hold === null ? [] : [[repo.id, holdWords(hold)] as const]; |
| 185 | 185 | }), |
| 186 | 186 | ); |
| @@ -197,16 +197,17 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 197 | 197 | lane = forgeLane(f.app, f.user); |
| 198 | 198 | decider = deciderLine(f.app, f.user); |
| 199 | 199 | // "Yours" is ownership plus the orgs you are on a team of; typing in the |
| 200 | // filter reaches every repository you can see. | |
| 200 | // filter reaches every repository you can see, archived ones too. | |
| 201 | 201 | const orgs = f.user |
| 202 | 202 | ? listOrgsForUser(f.db, f.user.id).map((o) => o.username) |
| 203 | 203 | : []; |
| 204 | 204 | repos = f.user |
| 205 | 205 | ? all.filter( |
| 206 | 206 | (repo) => |
| 207 | repo.ownerId === f.user?.id || orgs.includes(repo.ownerName), | |
| 207 | repo.archivedAt === null && | |
| 208 | (repo.ownerId === f.user?.id || orgs.includes(repo.ownerName)), | |
| 208 | 209 | ) |
| 209 | : all; | |
| 210 | : all.filter((repo) => repo.archivedAt === null); | |
| 210 | 211 | ctx.invalidate(); |
| 211 | 212 | }; |
| 212 | 213 |
src/web/studio/asks.ts +4
| @@ -101,10 +101,14 @@ export function appsOf(ctx: Ctx, user: User | undefined) { | ||
| 101 | 101 | export function writableAppsOf(ctx: Ctx, user: User | undefined) { |
| 102 | 102 | return appsFiltered( |
| 103 | 103 | ctx, |
| 104 | <<<<<<< HEAD | |
| 105 | listReposWritableTo(ctx.app.db, user, { limit: 200, withoutArchived: true }), | |
| 106 | ======= | |
| 104 | 107 | listReposWritableTo(ctx.app.db, user, { |
| 105 | 108 | limit: 200, |
| 106 | 109 | withoutArchived: true, |
| 107 | 110 | }), |
| 111 | >>>>>>> origin/main | |
| 108 | 112 | ); |
| 109 | 113 | } |
| 110 | 114 |
src/web/studio/explore.ts +10
| @@ -110,12 +110,22 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 110 | 110 | current: query.sort === s.sort, |
| 111 | 111 | })), |
| 112 | 112 | )} |
| 113 | <<<<<<< HEAD | |
| 114 | ${seg([ | |
| 115 | { | |
| 116 | label: "Show archived", | |
| 117 | href: href({ ...query, archived: !query.archived }), | |
| 118 | current: query.archived, | |
| 119 | }, | |
| 120 | ])} | |
| 121 | ======= | |
| 113 | 122 | <a |
| 114 | 123 | class="btn btn-sm" |
| 115 | 124 | href="${href({ ...query, archived: !query.archived })}" |
| 116 | 125 | aria-pressed="${query.archived ? "true" : "false"}" |
| 117 | 126 | >Show archived</a |
| 118 | 127 | > |
| 128 | >>>>>>> origin/main | |
| 119 | 129 | </div> |
| 120 | 130 | ${rows.length === 0 |
| 121 | 131 | ? empty({ |
test/asked.test.ts +9
| @@ -240,6 +240,15 @@ describe("what you asked for", () => { | ||
| 240 | 240 | expect(rows.get("Plant tomatoes")!.lastCrewAt).toBeNull(); |
| 241 | 241 | }); |
| 242 | 242 | |
| 243 | test("an archived repository is not asked about, until it is woken", () => { | |
| 244 | const put = (at: string | null) => | |
| 245 | app.db.query("UPDATE repo SET archived_at = ?1 WHERE id = ?2").run(at, repo.id); | |
| 246 | put(new Date().toISOString()); | |
| 247 | expect(askedRepos(app.db, alice, null)).toEqual([]); | |
| 248 | put(null); | |
| 249 | expect(askedRepos(app.db, alice, null).map((r) => r.name)).toEqual(["garden"]); | |
| 250 | }); | |
| 251 | ||
| 243 | 252 | test("a person who cannot write the repository reads nothing about it", () => { |
| 244 | 253 | expect(askedRepos(app.db, bob, null)).toEqual([]); |
| 245 | 254 | expect(askedRepos(app.db, bob, "alice/garden")).toEqual([]); |
test/asks.test.ts +13
| @@ -168,6 +168,19 @@ describe("the asks page", () => { | ||
| 168 | 168 | expect(sentence(await get(bob, "/"))).toBe("All fine"); |
| 169 | 169 | }); |
| 170 | 170 | |
| 171 | test("an archived repository's ask leaves the inbox, and its page still answers", async () => { | |
| 172 | const archive = (at: string | null) => | |
| 173 | app.db.query("UPDATE repo SET archived_at = ?1 WHERE id = ?2").run(at, repo.id); | |
| 174 | archive(new Date().toISOString()); | |
| 175 | const home = await get(alice, "/"); | |
| 176 | expect(sentence(home)).toBe("All fine"); | |
| 177 | expect(headerCount(home)).toBe(0); | |
| 178 | const page = await fetch(`${servers.url}/alice/garden`, { headers: { cookie: alice } }); | |
| 179 | expect(page.status).toBe(200); | |
| 180 | archive(null); | |
| 181 | expect(sentence(await get(alice, "/"))).toBe("1 thing needs you"); | |
| 182 | }); | |
| 183 | ||
| 171 | 184 | test("a forge health problem is a card for an admin and for no one else", async () => { |
| 172 | 185 | createRun(app.db, { repoId: repo.id, kind: "check", env: "main" }); |
| 173 | 186 | app.db |
test/explore.test.ts +17
| @@ -17,6 +17,8 @@ import { createIssue } from "../src/core/issues.ts"; | ||
| 17 | 17 | import type { Repo } from "../src/core/repos.ts"; |
| 18 | 18 | import { createToken } from "../src/core/tokens.ts"; |
| 19 | 19 | import { createUser, type User } from "../src/core/users.ts"; |
| 20 | import type { Ctx } from "../src/http/context.ts"; | |
| 21 | import { writableAppsOf } from "../src/web/studio/asks.ts"; | |
| 20 | 22 | import { serve, type Servers } from "../src/http/server.ts"; |
| 21 | 23 | import { quietLogs } from "./helpers/globals.ts"; |
| 22 | 24 | import { proveAll } from "./helpers/verified.ts"; |
| @@ -195,6 +197,21 @@ describe("explore", () => { | ||
| 195 | 197 | expect((await api("busy")).items.map((r) => r.name)).toEqual(["bob/busy"]); |
| 196 | 198 | }); |
| 197 | 199 | |
| 200 | test("an archived app leaves explore and the home's apps, shows with archived:yes, and its page answers", async () => { | |
| 201 | const attic = await appOf(alice, "attic"); | |
| 202 | const mine = () => | |
| 203 | writableAppsOf({ app } as unknown as Ctx, alice).repos.map((r) => r.name); | |
| 204 | expect(names((await api("attic")).items)).toContain("alice/attic"); | |
| 205 | expect(mine()).toContain("attic"); | |
| 206 | app.db.query("UPDATE repo SET archived_at = ?1 WHERE id = ?2").run(new Date().toISOString(), attic.id); | |
| 207 | expect(names((await api("attic")).items)).toEqual([]); | |
| 208 | expect(mine()).not.toContain("attic"); | |
| 209 | const shown = await api("archived:yes attic"); | |
| 210 | expect(shown.query).toBe("archived:yes attic"); | |
| 211 | expect(names(shown.items)).toContain("alice/attic"); | |
| 212 | expect((await fetch(`${base}/alice/attic`)).status).toBe(200); | |
| 213 | }); | |
| 214 | ||
| 198 | 215 | test("a private app's hours in use are told only to those who may enter it", async () => { |
| 199 | 216 | const stranger = (await api("gated")).items.find((r) => r.name === "alice/gated"); |
| 200 | 217 | expect(stranger.numbers.awakeHours).toBe(0); |
test/flow-card.test.ts +11
| @@ -145,6 +145,17 @@ describe("stalled steps on the home", () => { | ||
| 145 | 145 | expect(stalled().find((s) => s.pull === old.number)).toBeUndefined(); |
| 146 | 146 | }); |
| 147 | 147 | |
| 148 | test("a stalled pull in an archived repository is no card", async () => { | |
| 149 | const old = await pullOn(); | |
| 150 | const put = (at: string | null) => | |
| 151 | app.db.query("UPDATE repo SET archived_at = ?1 WHERE id = ?2").run(at, old.repoId); | |
| 152 | expect(stalled().find((s) => s.pull === old.number)).toBeDefined(); | |
| 153 | put(new Date().toISOString()); | |
| 154 | expect(stalled().find((s) => s.pull === old.number)).toBeUndefined(); | |
| 155 | put(null); | |
| 156 | expect(stalled().find((s) => s.pull === old.number)).toBeDefined(); | |
| 157 | }); | |
| 158 | ||
| 148 | 159 | test("only those who can write to the repository see the card", async () => { |
| 149 | 160 | const pull = await pullOn(); |
| 150 | 161 | expect(stalled(alice).some((s) => s.pull === pull.number)).toBe(true); |
test/tui-archive.test.ts +30
| @@ -111,4 +111,34 @@ describe("archive in the terminal", () => { | ||
| 111 | 111 | h.app.stop(); |
| 112 | 112 | } |
| 113 | 113 | }); |
| 114 | ||
| 115 | test("the home's list leaves an archived repository out until it wakes", async () => { | |
| 116 | const identity = { | |
| 117 | sshUsername: "alice", | |
| 118 | remoteAddress: "127.0.0.1", | |
| 119 | fingerprint: "SHA256:test", | |
| 120 | user: alice, | |
| 121 | }; | |
| 122 | const archived = await updateRepoSettings(forge, alice, repo, { archived: true }); | |
| 123 | expect(archived.ok).toBe(true); | |
| 124 | const away = boot(identity); | |
| 125 | try { | |
| 126 | await settleApp(away.app); | |
| 127 | expect(away.text()).not.toContain("beacon"); | |
| 128 | await away.press("/"); | |
| 129 | for (const ch of "beacon") await away.press(ch); | |
| 130 | expect(away.text()).toContain("beacon"); | |
| 131 | } finally { | |
| 132 | away.app.stop(); | |
| 133 | } | |
| 134 | const woke = await updateRepoSettings(forge, alice, repo, { archived: false }); | |
| 135 | expect(woke.ok).toBe(true); | |
| 136 | const back = boot(identity); | |
| 137 | try { | |
| 138 | await settleApp(back.app); | |
| 139 | expect(back.text()).toContain("beacon"); | |
| 140 | } finally { | |
| 141 | back.app.stop(); | |
| 142 | } | |
| 143 | }); | |
| 114 | 144 | }); |
new above
offline