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

Parked opened this
Closed without merging

scout/forge:scout/2454-archive-part-2a-an-archived-repository-l → main 5 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
14 files changed +135 −6
README.md +8
@@ -316,11 +316,18 @@ An admin puts a repository away from **Settings → Archive**, with
316316 else gets 403), or in the terminal with `a` on the About card (`I`). The
317317 repository page and the card then say when it was archived, and an admin gets
318318 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.
319322 An archived repository starts no new crew run. Assigning an issue to an agent,
320323 queueing a run again, asking the crew to propose a resolution, redirecting a
321324 wave and converging a fork each answer "This repository is archived; wake it to
322325 start a run."; the API answers 409 `archived`, and the terminal and MCP show
323326 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 =======
324331 Wake undoes all of it. Clone, push and links keep working, and the repository
325332 page still answers.
326333
@@ -329,6 +336,7 @@ you there included, and the terminal's and MCP's asks), the stalled-steps
329336 reader and the explorer's default view; `/explore` shows it with `archived:yes`
330337 (the **Show archived** toggle). It stays in `/apps`, search, the palette and
331338 the repository API (`GET /api/v1/repos`).
339 >>>>>>> origin/main
332340
333341 ## Health
334342
src/actions/explore.ts +11 −1
@@ -2,7 +2,8 @@
22 * Explore (#607): the apps, people and forges a viewer can see, ranked by
33 * the same real signals the front page uses (`core/front.ts`: forks by
44 * 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,
67 * `/api/v1/explore` and the MCP tool `explore` all answer from here.
78 *
89 * - Only what the viewer may read: repositories by `listReposVisibleTo`; an
@@ -42,7 +43,11 @@ export interface ExploreQuery {
4243 readonly sort: ExploreSort;
4344 /** Words a row's name, owner or description must contain. */
4445 readonly text: string;
46 <<<<<<< HEAD
47 /** Show repositories that are put away too (`archived:yes`). */
48 =======
4549 /** `archived:yes` — put-away repositories are in the list; off, they are not. */
50 >>>>>>> origin/main
4651 readonly archived: boolean;
4752 }
4853
@@ -89,8 +94,13 @@ export function parseExploreQuery(line: string): ExploreQuery {
8994 (SORTS as readonly string[]).includes(value.toLowerCase())
9095 )
9196 sort = value.toLowerCase() as ExploreSort;
97 <<<<<<< HEAD
98 else if (k === "archived" && value !== "")
99 archived = ["yes", "true", "1", "show"].includes(value.toLowerCase());
100 =======
92101 else if (k === "archived" && ["yes", "no"].includes(value.toLowerCase()))
93102 archived = value.toLowerCase() === "yes";
103 >>>>>>> origin/main
94104 else if (k === "q" && value !== "") words.push(value);
95105 else words.push(word);
96106 }
src/core/asked.ts +4
@@ -117,10 +117,14 @@ export function askedRepos(
117117 viewer: User | undefined,
118118 repoSpec: string | null | undefined,
119119 ): readonly Repo[] {
120 <<<<<<< HEAD
121 const writable = listReposWritableTo(db, viewer, { limit: 200, withoutArchived: true });
122 =======
120123 const writable = listReposWritableTo(db, viewer, {
121124 limit: 200,
122125 withoutArchived: true,
123126 });
127 >>>>>>> origin/main
124128 if (repoSpec === null || repoSpec === undefined || repoSpec === "")
125129 return writable;
126130 const [owner, name, ...rest] = repoSpec.split("/");
src/core/repos.ts +8
@@ -649,10 +649,16 @@ export interface ListReposOptions {
649649 cursor?: string;
650650 /** Repositories that run an app first, each half newest first (not with `cursor`). */
651651 appsFirst?: boolean;
652 <<<<<<< HEAD
653 /** Leave out repositories that are put away (`archived_at` set). */
654 =======
652655 /** Leave archived repositories out. @default false */
656 >>>>>>> origin/main
653657 withoutArchived?: boolean;
654658 }
655659
660 const NOT_ARCHIVED = " AND repo.archived_at IS NULL";
661
656662 // Visibility in SQL: public, owned, or owned by an org the viewer is on a
657663 // team of. Site admins see everything. The same rule canRead applies, so a
658664 // listing never shows a repo whose page would 404.
@@ -677,6 +683,7 @@ export function listReposVisibleTo(
677683 where += ` AND (repo.name LIKE ?${p} ESCAPE '\\' COLLATE NOCASE
678684 OR user.username LIKE ?${p} ESCAPE '\\' COLLATE NOCASE)`;
679685 }
686 if (options.withoutArchived === true) where += NOT_ARCHIVED;
680687 if (options.cursor !== undefined) {
681688 params.push(options.cursor);
682689 where += ` AND repo.id < ?${params.length}`;
@@ -712,6 +719,7 @@ export function listReposWritableTo(
712719 where += ` AND (repo.name LIKE ?${p} ESCAPE '\\' COLLATE NOCASE
713720 OR user.username LIKE ?${p} ESCAPE '\\' COLLATE NOCASE)`;
714721 }
722 if (options.withoutArchived === true) where += NOT_ARCHIVED;
715723 if (options.cursor !== undefined) {
716724 params.push(options.cursor);
717725 where += ` AND repo.id < ?${params.length}`;
src/flow/stalled.ts +4
@@ -49,10 +49,14 @@ interface RunRow {
4949 }
5050
5151 export function readStalled(db: Database, viewer: User, now: Date): StalledStep[] {
52 <<<<<<< HEAD
53 const repos = listReposWritableTo(db, viewer, { limit: REPOS_MAX, withoutArchived: true });
54 =======
5255 const repos = listReposWritableTo(db, viewer, {
5356 limit: REPOS_MAX,
5457 withoutArchived: true,
5558 });
59 >>>>>>> origin/main
5660 if (repos.length === 0) return [];
5761 const byId = new Map(repos.map((r) => [r.id, r]));
5862 const ids = [...byId.keys()];
src/http/mcp.ts +1 −1
@@ -1695,7 +1695,7 @@ const TOOLS: readonly Tool[] = [
16951695 {
16961696 name: "explore",
16971697 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.",
16991699 inputSchema: {
17001700 type: "object",
17011701 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 {
180180 holds = new Map(
181181 all.flatMap((repo) => {
182182 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;
184184 return hold === null ? [] : [[repo.id, holdWords(hold)] as const];
185185 }),
186186 );
@@ -197,16 +197,17 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
197197 lane = forgeLane(f.app, f.user);
198198 decider = deciderLine(f.app, f.user);
199199 // "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.
201201 const orgs = f.user
202202 ? listOrgsForUser(f.db, f.user.id).map((o) => o.username)
203203 : [];
204204 repos = f.user
205205 ? all.filter(
206206 (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)),
208209 )
209 : all;
210 : all.filter((repo) => repo.archivedAt === null);
210211 ctx.invalidate();
211212 };
212213
src/web/studio/asks.ts +4
@@ -101,10 +101,14 @@ export function appsOf(ctx: Ctx, user: User | undefined) {
101101 export function writableAppsOf(ctx: Ctx, user: User | undefined) {
102102 return appsFiltered(
103103 ctx,
104 <<<<<<< HEAD
105 listReposWritableTo(ctx.app.db, user, { limit: 200, withoutArchived: true }),
106 =======
104107 listReposWritableTo(ctx.app.db, user, {
105108 limit: 200,
106109 withoutArchived: true,
107110 }),
111 >>>>>>> origin/main
108112 );
109113 }
110114
src/web/studio/explore.ts +10
@@ -110,12 +110,22 @@ export async function explorePage(ctx: Ctx): Promise<Response> {
110110 current: query.sort === s.sort,
111111 })),
112112 )}
113 <<<<<<< HEAD
114 ${seg([
115 {
116 label: "Show archived",
117 href: href({ ...query, archived: !query.archived }),
118 current: query.archived,
119 },
120 ])}
121 =======
113122 <a
114123 class="btn btn-sm"
115124 href="${href({ ...query, archived: !query.archived })}"
116125 aria-pressed="${query.archived ? "true" : "false"}"
117126 >Show archived</a
118127 >
128 >>>>>>> origin/main
119129 </div>
120130 ${rows.length === 0
121131 ? empty({
test/asked.test.ts +9
@@ -240,6 +240,15 @@ describe("what you asked for", () => {
240240 expect(rows.get("Plant tomatoes")!.lastCrewAt).toBeNull();
241241 });
242242
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
243252 test("a person who cannot write the repository reads nothing about it", () => {
244253 expect(askedRepos(app.db, bob, null)).toEqual([]);
245254 expect(askedRepos(app.db, bob, "alice/garden")).toEqual([]);
test/asks.test.ts +13
@@ -168,6 +168,19 @@ describe("the asks page", () => {
168168 expect(sentence(await get(bob, "/"))).toBe("All fine");
169169 });
170170
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
171184 test("a forge health problem is a card for an admin and for no one else", async () => {
172185 createRun(app.db, { repoId: repo.id, kind: "check", env: "main" });
173186 app.db
test/explore.test.ts +17
@@ -17,6 +17,8 @@ import { createIssue } from "../src/core/issues.ts";
1717 import type { Repo } from "../src/core/repos.ts";
1818 import { createToken } from "../src/core/tokens.ts";
1919 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";
2022 import { serve, type Servers } from "../src/http/server.ts";
2123 import { quietLogs } from "./helpers/globals.ts";
2224 import { proveAll } from "./helpers/verified.ts";
@@ -195,6 +197,21 @@ describe("explore", () => {
195197 expect((await api("busy")).items.map((r) => r.name)).toEqual(["bob/busy"]);
196198 });
197199
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
198215 test("a private app's hours in use are told only to those who may enter it", async () => {
199216 const stranger = (await api("gated")).items.find((r) => r.name === "alice/gated");
200217 expect(stranger.numbers.awakeHours).toBe(0);
test/flow-card.test.ts +11
@@ -145,6 +145,17 @@ describe("stalled steps on the home", () => {
145145 expect(stalled().find((s) => s.pull === old.number)).toBeUndefined();
146146 });
147147
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
148159 test("only those who can write to the repository see the card", async () => {
149160 const pull = await pullOn();
150161 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", () => {
111111 h.app.stop();
112112 }
113113 });
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 });
114144 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs