Public: anyone can read this; the crew can change it.
Kind and people chips filter the home, the inbox and /api/v1/feed, saved per user #1737
scout/forge:scout/1598-kind-and-people-chips-filter-the-home-th → main 10 commits fork 7 threads · 7 unresolved
README.md +4 −1
| @@ -262,12 +262,15 @@ and `forge sync` below is what acts on it. | ||
| 262 | 262 | |
| 263 | 263 | **Muting a repository from the home**: each ask row on the home carries a "Mute owner/name" chip. A muted repository's asks leave the home, `/api/v1/asks`, the header count and the phone's pushes (the same per-user mute the On you card uses, no new table); the home says "N muted repositories still ask" with a "Listen again" button, and an app's own page still counts them. |
| 264 | 264 | |
| 265 | **Kind and people chips** above the home feed hide pulls, decisions, the crew's words, releases, or one person, for you alone. They filter the home, the inbox, `/api/v1/feed` and the apps rail, and nothing else; set them on the home, with `POST /api/v1/feed/chips`, with the MCP tool `feed_chips`, or in the terminal (`K` then `p`, `d`, `w` or `r` toggles a kind, `H` the person who opened the row, `C` shows all again). The terminal's On you card lists what is hidden. | |
| 266 | ||
| 265 | 267 | **On you, in the terminal**, answers to the same mutes and one-move verbs as |
| 266 | 268 | the web card. Repositories you muted are hidden and counted ("2 repositories |
| 267 | 269 | muted"). On the On you card: `space` marks a row, `x` closes the marked rows |
| 268 | 270 | (or the row under the cursor) with one reason, `m` mutes their repositories, |
| 269 | 271 | `S` ships them, `u` undoes the latest set within its day, and `L` listens |
| 270 | again to every muted repository. Each goes through `applyAsksBulk`, so the | |
| 272 | again to every muted repository. Chips you set elsewhere are listed under it | |
| 273 | ("hidden: …"). Each goes through `applyAsksBulk`, so the | |
| 271 | 274 | per-row access checks and refusals are the web's, shown in the toast. |
| 272 | 275 | |
| 273 | 276 | **Let the decider** answers a hand-over card (an issue the crew parked) when |
docs/FEED.md +10
| @@ -10,6 +10,16 @@ look`. `what` is the post in its own words; `reason` the sentence for why it | ||
| 10 | 10 | is there. Strings are plain text, not HTML: whatever renders them escapes |
| 11 | 11 | them. The MCP tool `feed { limit, cursor }` answers the same. |
| 12 | 12 | |
| 13 | Chips: `GET /api/v1/feed/chips` → `{ kinds, people }`, what the viewer hid; | |
| 14 | `POST` `{ kind }` (`pulls decisions words releases`) or `{ person }` (a | |
| 15 | username), with `hidden: false` to show again (`rw`). A chip removes what it | |
| 16 | names from the feed, the asks (inbox, `/api/v1/asks`) and the home's apps | |
| 17 | rail, and nothing else. On the home they are buttons above the timeline; the | |
| 18 | MCP tool `feed_chips { kind | person, hidden, dryRun }` reads them and, with | |
| 19 | `dryRun: false` and an `rw` token, sets them; in the terminal the On you card lists them (`hidden: …`), `K` then `p d w r` | |
| 20 | toggles a kind, `H` the person who opened the row, `C` shows all again. | |
| 21 | A name that is no account is refused (`no such person`), never silently kept. | |
| 22 | ||
| 13 | 23 | `POST /api/v1/feed/interactions` `{ item, kind, app? }` records what the viewer |
| 14 | 24 | did (`opened dwelled steered told swiped shipped shared dismissed muted`). |
| 15 | 25 | Same-origin checked for browser sessions, `rw` for tokens. An `event:` item |
scripts/gate.ts +1
| @@ -29,6 +29,7 @@ export const GATE: readonly string[] = [ | ||
| 29 | 29 | "test/cloud-use.test.ts", |
| 30 | 30 | "test/accounts.test.ts", |
| 31 | 31 | "test/asks-mute.test.ts", |
| 32 | "test/feed-chips.test.ts", | |
| 32 | 33 | "test/agents.test.ts", |
| 33 | 34 | "test/app-domains.test.ts", |
| 34 | 35 | "test/app.test.ts", |
src/core/feed_chips.ts added +112
| @@ -0,0 +1,112 @@ | ||
| 1 | /** | |
| 2 | * The chips a viewer turned off on their home, inbox and feed (#1598): kinds | |
| 3 | * of post and people. Pure data, saved per viewer beside the mutes; a chip | |
| 4 | * removes what it names and nothing else. Whoever records one owes it only | |
| 5 | * the viewer's own id — a chip is never about anyone else's view. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | import { getUserByName, getUsersByIds } from "./users.ts"; | |
| 10 | ||
| 11 | /** The kind chips and the feed kinds each one names. */ | |
| 12 | export const KIND_CHIPS = { | |
| 13 | pulls: ["pull"], | |
| 14 | decisions: ["decision"], | |
| 15 | words: ["tell", "reply"], | |
| 16 | releases: ["release"], | |
| 17 | } as const; | |
| 18 | export type KindChip = keyof typeof KIND_CHIPS; | |
| 19 | export const KIND_CHIP_NAMES = Object.keys(KIND_CHIPS) as KindChip[]; | |
| 20 | ||
| 21 | export const KIND_CHIP_LABEL: Record<KindChip, string> = { | |
| 22 | pulls: "Pulls to review", | |
| 23 | decisions: "Decisions and other asks", | |
| 24 | words: "The crew's words", | |
| 25 | releases: "Releases", | |
| 26 | }; | |
| 27 | ||
| 28 | export const isKindChip = (v: unknown): v is KindChip => | |
| 29 | typeof v === "string" && Object.hasOwn(KIND_CHIPS, v); | |
| 30 | ||
| 31 | /** The most people one viewer may hide: a bound, not a feature. */ | |
| 32 | export const PEOPLE_CHIPS_MAX = 100; | |
| 33 | ||
| 34 | export interface Chips { | |
| 35 | /** Kinds hidden. */ | |
| 36 | readonly kinds: ReadonlySet<KindChip>; | |
| 37 | /** User ids hidden. */ | |
| 38 | readonly people: ReadonlySet<string>; | |
| 39 | } | |
| 40 | ||
| 41 | export function chipsFor(db: Database, viewerId: string): Chips { | |
| 42 | const kinds = new Set<KindChip>(); | |
| 43 | const people = new Set<string>(); | |
| 44 | for (const r of db | |
| 45 | .query<{ type: string; value: string }, [string]>( | |
| 46 | "SELECT type, value FROM feed_chip WHERE viewer_id = ?1", | |
| 47 | ) | |
| 48 | .all(viewerId)) { | |
| 49 | if (r.type === "kind" && isKindChip(r.value)) kinds.add(r.value); | |
| 50 | else if (r.type === "person") people.add(r.value); | |
| 51 | } | |
| 52 | return { kinds, people }; | |
| 53 | } | |
| 54 | ||
| 55 | /** Whether any chip is set: the common viewer pays for nothing else. */ | |
| 56 | export const anyChips = (c: Chips): boolean => c.kinds.size > 0 || c.people.size > 0; | |
| 57 | ||
| 58 | /** The feed kinds the hidden kind chips name. */ | |
| 59 | export function hiddenFeedKinds(c: Chips): Set<string> { | |
| 60 | const out = new Set<string>(); | |
| 61 | for (const k of c.kinds) for (const f of KIND_CHIPS[k]) out.add(f); | |
| 62 | return out; | |
| 63 | } | |
| 64 | ||
| 65 | /** Hide (`hidden`) or show a kind of post. Twice is the same as once. */ | |
| 66 | export function setKindChip(db: Database, viewerId: string, kind: KindChip, hidden: boolean): void { | |
| 67 | setChip(db, viewerId, "kind", kind, hidden); | |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Hide or show one person by username. A name that is no account, or the | |
| 72 | * viewer's own, is refused: `"unknown"` or `"self"`; past the bound, `"full"`. | |
| 73 | */ | |
| 74 | export function setPersonChip( | |
| 75 | db: Database, | |
| 76 | viewerId: string, | |
| 77 | username: string, | |
| 78 | hidden: boolean, | |
| 79 | ): "ok" | "unknown" | "self" | "full" { | |
| 80 | const user = getUserByName(db, username); | |
| 81 | if (!user) return "unknown"; | |
| 82 | if (user.id === viewerId) return "self"; | |
| 83 | if (hidden && chipsFor(db, viewerId).people.size >= PEOPLE_CHIPS_MAX) { | |
| 84 | if (!chipsFor(db, viewerId).people.has(user.id)) return "full"; | |
| 85 | } | |
| 86 | setChip(db, viewerId, "person", user.id, hidden); | |
| 87 | return "ok"; | |
| 88 | } | |
| 89 | ||
| 90 | function setChip( | |
| 91 | db: Database, | |
| 92 | viewerId: string, | |
| 93 | type: "kind" | "person", | |
| 94 | value: string, | |
| 95 | hidden: boolean, | |
| 96 | ): void { | |
| 97 | if (hidden) | |
| 98 | db.query( | |
| 99 | "INSERT OR IGNORE INTO feed_chip (viewer_id, type, value) VALUES (?1, ?2, ?3)", | |
| 100 | ).run(viewerId, type, value); | |
| 101 | else | |
| 102 | db.query( | |
| 103 | "DELETE FROM feed_chip WHERE viewer_id = ?1 AND type = ?2 AND value = ?3", | |
| 104 | ).run(viewerId, type, value); | |
| 105 | } | |
| 106 | ||
| 107 | /** The usernames of the hidden people, in order. */ | |
| 108 | export function hiddenPeopleNames(db: Database, c: Chips): string[] { | |
| 109 | return [...getUsersByIds(db, [...c.people]).values()] | |
| 110 | .map((u) => u.username) | |
| 111 | .sort(); | |
| 112 | } |
src/core/reserved.ts +1
| @@ -100,6 +100,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 100 | 100 | "verify", |
| 101 | 101 | "www", |
| 102 | 102 | "asked", |
| 103 | "feed", | |
| 103 | 104 | "claim", |
| 104 | 105 | "forges", |
| 105 | 106 | // the forge's own nouns, and the platform's name |
src/core/schema.ts +13
| @@ -1741,6 +1741,19 @@ export const migrations: readonly string[] = [ | ||
| 1741 | 1741 | ALTER TABLE repo ADD COLUMN decisions_by TEXT NOT NULL DEFAULT 'me' |
| 1742 | 1742 | CHECK (decisions_by IN ('me', 'decider', 'decider_tell')); |
| 1743 | 1743 | `, |
| 1744 | // 86 — feed chips (#1598): what a viewer chose not to see on their home, | |
| 1745 | // inbox and feed. A `kind` row hides a kind of post (`pulls`, `decisions`, | |
| 1746 | // `words`, `releases`); a `person` row hides one account's posts. Kept | |
| 1747 | // beside the mutes, one row per choice, per viewer. | |
| 1748 | ` | |
| 1749 | CREATE TABLE feed_chip ( | |
| 1750 | viewer_id TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE, | |
| 1751 | type TEXT NOT NULL CHECK (type IN ('kind', 'person')), | |
| 1752 | value TEXT NOT NULL, | |
| 1753 | created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')), | |
| 1754 | PRIMARY KEY (viewer_id, type, value) | |
| 1755 | ); | |
| 1756 | `, | |
| 1744 | 1757 | ]; |
| 1745 | 1758 | |
| 1746 | 1759 | /** |
src/feed/feed.ts +12 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import type { Database } from "bun:sqlite"; |
| 10 | import { anyChips, chipsFor, hiddenFeedKinds } from "../core/feed_chips.ts"; | |
| 10 | 11 | import { dismissedItems, mutedRepos } from "../core/interactions.ts"; |
| 11 | 12 | import { affinityFor } from "./affinity.ts"; |
| 12 | 13 | import { canRead, getRepoById } from "../core/repos.ts"; |
| @@ -56,7 +57,17 @@ export function readFeed( | ||
| 56 | 57 | : !dismissed.has(c.id) && |
| 57 | 58 | (c.kind === "ask" || c.kind === "milestone" || !muted.has(c.repoId)), |
| 58 | 59 | ); |
| 59 | let ranked = rank(candidates, affinityFor(db, viewer, now), now); | |
| 60 | // The viewer's chips (`core/feed_chips.ts`): each removes what it names. | |
| 61 | const chips = chipsFor(db, viewer.id); | |
| 62 | const hiddenKinds = hiddenFeedKinds(chips); | |
| 63 | const visible = anyChips(chips) | |
| 64 | ? candidates.filter( | |
| 65 | (c) => | |
| 66 | !hiddenKinds.has(c.kind) && | |
| 67 | !(c.actorId !== null && chips.people.has(c.actorId)), | |
| 68 | ) | |
| 69 | : candidates; | |
| 70 | let ranked = rank(visible, affinityFor(db, viewer, now), now); | |
| 60 | 71 | const cursor = options.cursor; |
| 61 | 72 | if (cursor) { |
| 62 | 73 | const at = ranked.findIndex((i) => i.id === cursor.id); |
src/feed/items.ts +2 −1
| @@ -39,6 +39,7 @@ export type FeedKind = | ||
| 39 | 39 | | "tell" |
| 40 | 40 | | "reply" |
| 41 | 41 | | "look" |
| 42 | | "release" | |
| 42 | 43 | | "milestone"; |
| 43 | 44 | |
| 44 | 45 | /** What a candidate is, before it is ranked and worded. */ |
| @@ -333,7 +334,7 @@ function fromEvent( | ||
| 333 | 334 | case "look.taken": |
| 334 | 335 | return { ...common, kind: "look", link: base(repo), what: "a new picture of it is ready" }; |
| 335 | 336 | case "app.serving": |
| 336 | return { ...common, kind: "pull", link: base(repo), what: "a new version is serving" }; | |
| 337 | return { ...common, kind: "release", link: base(repo), what: "a new version is serving" }; | |
| 337 | 338 | // A tell is a post; a comment is a reply under it, in its own words. |
| 338 | 339 | case "issue.opened": { |
| 339 | 340 | if (number === undefined) return undefined; |
src/http/feed.ts +48
| @@ -11,6 +11,16 @@ import { | ||
| 11 | 11 | UNVERIFIED_WORDS, |
| 12 | 12 | VARIANTS_MAX, |
| 13 | 13 | } from "../actions/tell.ts"; |
| 14 | import type { Database } from "bun:sqlite"; | |
| 15 | import { | |
| 16 | KIND_CHIP_NAMES, | |
| 17 | PEOPLE_CHIPS_MAX, | |
| 18 | chipsFor, | |
| 19 | hiddenPeopleNames, | |
| 20 | isKindChip, | |
| 21 | setKindChip, | |
| 22 | setPersonChip, | |
| 23 | } from "../core/feed_chips.ts"; | |
| 14 | 24 | import { DIRECTION_NOTE } from "../crew/direct.ts"; |
| 15 | 25 | import { audienceFilter } from "../core/event_audience.ts"; |
| 16 | 26 | import { getEvent } from "../core/events.ts"; |
| @@ -46,6 +56,14 @@ import { | ||
| 46 | 56 | unauthorized, |
| 47 | 57 | } from "./respond.ts"; |
| 48 | 58 | |
| 59 | function chipsJson(db: Database, viewerId: string) { | |
| 60 | const chips = chipsFor(db, viewerId); | |
| 61 | return { | |
| 62 | kinds: KIND_CHIP_NAMES.filter((k) => chips.kinds.has(k)), | |
| 63 | people: hiddenPeopleNames(db, chips), | |
| 64 | }; | |
| 65 | } | |
| 66 | ||
| 49 | 67 | export function feedRoutes(router: Router<Handler>): void { |
| 50 | 68 | router.add("GET", "/api/v1/feed", (ctx) => { |
| 51 | 69 | const viewer = ctx.auth.user; |
| @@ -72,6 +90,36 @@ export function feedRoutes(router: Router<Handler>): void { | ||
| 72 | 90 | ); |
| 73 | 91 | }); |
| 74 | 92 | |
| 93 | // The viewer's chips: what they hid, and hide or show one more. | |
| 94 | router.add("GET", "/api/v1/feed/chips", (ctx) => { | |
| 95 | const viewer = ctx.auth.user; | |
| 96 | if (!viewer) return unauthorized(); | |
| 97 | return json(chipsJson(ctx.app.db, viewer.id), 200, { | |
| 98 | "cache-control": "private, no-store", | |
| 99 | }); | |
| 100 | }); | |
| 101 | ||
| 102 | router.add("POST", "/api/v1/feed/chips", async (ctx) => { | |
| 103 | const denied = requireScope(ctx, "rw"); | |
| 104 | if (denied) return denied; | |
| 105 | const viewer = ctx.auth.user!; | |
| 106 | const input = await body(ctx.request); | |
| 107 | const hidden = input.hidden === undefined ? true : input.hidden; | |
| 108 | if (typeof hidden !== "boolean") | |
| 109 | return apiError("invalid_hidden", 422, "hidden is true or false"); | |
| 110 | if (input.kind !== undefined) { | |
| 111 | if (!isKindChip(input.kind)) | |
| 112 | return apiError("invalid_kind", 422, `kind is one of ${KIND_CHIP_NAMES.join(", ")}`); | |
| 113 | setKindChip(ctx.app.db, viewer.id, input.kind, hidden); | |
| 114 | } else { | |
| 115 | const done = setPersonChip(ctx.app.db, viewer.id, str(input.person), hidden); | |
| 116 | if (done === "unknown") return notFound(); | |
| 117 | if (done === "self") return apiError("invalid_person", 422, "you cannot hide yourself"); | |
| 118 | if (done === "full") return apiError("too_many", 422, `at most ${PEOPLE_CHIPS_MAX} people`); | |
| 119 | } | |
| 120 | return json(chipsJson(ctx.app.db, viewer.id), 201); | |
| 121 | }); | |
| 122 | ||
| 75 | 123 | // What asks the viewer, ranked, with the week's measure (`asksAnswer`). |
| 76 | 124 | router.add("GET", "/api/v1/asks", (ctx) => { |
| 77 | 125 | const viewer = ctx.auth.user; |
src/http/mcp.ts +56 −1
| @@ -96,6 +96,15 @@ import { | ||
| 96 | 96 | } from "../core/repos.ts"; |
| 97 | 97 | import { plannerDeclines } from "../crew/autonomy.ts"; |
| 98 | 98 | import { listActiveRuns } from "../core/runs.ts"; |
| 99 | import { | |
| 100 | KIND_CHIP_NAMES, | |
| 101 | PEOPLE_CHIPS_MAX, | |
| 102 | chipsFor, | |
| 103 | hiddenPeopleNames, | |
| 104 | isKindChip, | |
| 105 | setKindChip, | |
| 106 | setPersonChip, | |
| 107 | } from "../core/feed_chips.ts"; | |
| 99 | 108 | import { scopeAllows } from "../core/tokens.ts"; |
| 100 | 109 | import { getUsersByIds, type User } from "../core/users.ts"; |
| 101 | 110 | import { openapi } from "../contract/openapi.ts"; |
| @@ -1270,7 +1279,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1270 | 1279 | { |
| 1271 | 1280 | name: "feed", |
| 1272 | 1281 | description: |
| 1273 | "Your home timeline, as the forge's home shows it: tells, replies, runs, changes and looks across the apps you can see, ranked, each with who did it, what it says, why it is there and a link to its thing. Pass `cursor` (next_cursor from the last answer) for the next page. The same items as GET /api/v1/feed.", | |
| 1282 | "Your home timeline, as the forge's home shows it: tells, replies, runs, changes and looks across the apps you can see, ranked, each with who did it, what it says, why it is there and a link to its thing. Pass `cursor` (next_cursor from the last answer) for the next page. Kinds and people you hid with `feed_chips` are left out. The same items as GET /api/v1/feed.", | |
| 1274 | 1283 | inputSchema: { |
| 1275 | 1284 | type: "object", |
| 1276 | 1285 | properties: { |
| @@ -1296,6 +1305,52 @@ const TOOLS: readonly Tool[] = [ | ||
| 1296 | 1305 | ); |
| 1297 | 1306 | }, |
| 1298 | 1307 | }, |
| 1308 | { | |
| 1309 | name: "feed_chips", | |
| 1310 | description: | |
| 1311 | "The kinds and people you hid from your feed, inbox and apps rail. With no arguments it says what is hidden (`kinds`, `people`). Pass `kind` (pulls, decisions, words, releases) or `person` (a username) to hide it, with `hidden: false` to show it again; that plans unless dryRun is false, and needs a read-write token. Yours alone. The same as /api/v1/feed/chips.", | |
| 1312 | inputSchema: { | |
| 1313 | type: "object", | |
| 1314 | properties: { | |
| 1315 | kind: { type: "string", enum: [...KIND_CHIP_NAMES] }, | |
| 1316 | person: { type: "string", maxLength: 64 }, | |
| 1317 | hidden: { type: "boolean" }, | |
| 1318 | dryRun: { type: "boolean" }, | |
| 1319 | }, | |
| 1320 | }, | |
| 1321 | writes: true, | |
| 1322 | dryByDefault: true, | |
| 1323 | run(ctx, user, args) { | |
| 1324 | const kind = args["kind"]; | |
| 1325 | const person = args["person"]; | |
| 1326 | const hidden = args["hidden"] === undefined ? true : args["hidden"]; | |
| 1327 | if (typeof hidden !== "boolean") return bad("invalid", "hidden is true or false"); | |
| 1328 | if (kind !== undefined && person !== undefined) | |
| 1329 | return bad("invalid", "give a kind or a person, not both"); | |
| 1330 | if (kind !== undefined || person !== undefined) { | |
| 1331 | if (kind !== undefined && !isKindChip(kind)) | |
| 1332 | return bad("invalid", `kind is one of ${KIND_CHIP_NAMES.join(", ")}`); | |
| 1333 | if (args["dryRun"] !== false) | |
| 1334 | return good({ | |
| 1335 | says: `Would ${hidden ? "hide" : "show"} ${str(kind ?? person)}. Send dryRun: false to do it.`, | |
| 1336 | }); | |
| 1337 | if (kind !== undefined) { | |
| 1338 | if (!isKindChip(kind)) return bad("invalid", `kind is one of ${KIND_CHIP_NAMES.join(", ")}`); | |
| 1339 | setKindChip(ctx.app.db, user.id, kind, hidden); | |
| 1340 | } else { | |
| 1341 | const done = setPersonChip(ctx.app.db, user.id, str(person), hidden); | |
| 1342 | if (done === "unknown") return bad("not_found", "no such person"); | |
| 1343 | if (done === "self") return bad("invalid", "you cannot hide yourself"); | |
| 1344 | if (done === "full") return bad("invalid", `at most ${PEOPLE_CHIPS_MAX} people`); | |
| 1345 | } | |
| 1346 | } | |
| 1347 | const chips = chipsFor(ctx.app.db, user.id); | |
| 1348 | return good({ | |
| 1349 | kinds: KIND_CHIP_NAMES.filter((k) => chips.kinds.has(k)), | |
| 1350 | people: hiddenPeopleNames(ctx.app.db, chips), | |
| 1351 | }); | |
| 1352 | }, | |
| 1353 | }, | |
| 1299 | 1354 | { |
| 1300 | 1355 | name: "make_it_yours", |
| 1301 | 1356 | description: |
src/http/server.ts +2
| @@ -212,6 +212,7 @@ import { | ||
| 212 | 212 | asksPage, |
| 213 | 213 | } from "../web/studio/asks_page.ts"; |
| 214 | 214 | import { liveFeedFragment } from "../web/studio/feed.ts"; |
| 215 | import { feedChipsSubmit } from "../web/studio/feed_chips.ts"; | |
| 215 | 216 | import { serviceWorker } from "../web/sw.ts"; |
| 216 | 217 | import { explorePage } from "../web/studio/explore.ts"; |
| 217 | 218 | import { |
| @@ -600,6 +601,7 @@ export function buildRouter(): Router<Handler> { | ||
| 600 | 601 | router.add("POST", "/asks/bulk/:id/undo", asksBulkUndo); |
| 601 | 602 | router.add("POST", "/asks/listen", asksListen); |
| 602 | 603 | router.add("POST", "/asks/mute", asksMute); |
| 604 | router.add("POST", "/feed/chips", feedChipsSubmit); | |
| 603 | 605 | router.add("POST", "/asks/decide", asksDecide); |
| 604 | 606 | router.add("POST", "/asks/decide/:id/undo", asksDecideUndo); |
| 605 | 607 | // What people asked of the crew, and what became of it (core/asked.ts). |
src/tui/screens/dashboard.ts +70 −1
| @@ -27,6 +27,15 @@ import { | ||
| 27 | 27 | latestUndoable, |
| 28 | 28 | undoAsksBulk, |
| 29 | 29 | } from "../../actions/asks_bulk.ts"; |
| 30 | import { | |
| 31 | KIND_CHIP_LABEL, | |
| 32 | KIND_CHIP_NAMES, | |
| 33 | type KindChip, | |
| 34 | chipsFor, | |
| 35 | hiddenPeopleNames, | |
| 36 | setKindChip, | |
| 37 | setPersonChip, | |
| 38 | } from "../../core/feed_chips.ts"; | |
| 30 | 39 | import { mutedRepos, removeMutes } from "../../core/interactions.ts"; |
| 31 | 40 | import type { Operation } from "../../core/fleet_ops.ts"; |
| 32 | 41 | import { listPins, pinnedRepoIds, type Pin } from "../../core/pins.ts"; |
| @@ -107,6 +116,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 107 | 116 | let onYou: OnYouItem[] = []; |
| 108 | 117 | /** Repositories the viewer muted that hold work assigned to them: said, never silent. */ |
| 109 | 118 | let silenced = new Map<string, Repo>(); |
| 119 | /** What the viewer hid with chips (kinds, then people): said, never silent. */ | |
| 120 | let hiddenChips: string[] = []; | |
| 110 | 121 | /** The rows marked for one verb, by issue id. */ |
| 111 | 122 | const marked = new Set<string>(); |
| 112 | 123 | let lastSet: Operation | undefined; |
| @@ -176,6 +187,13 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 176 | 187 | const repo = byId.get(id); |
| 177 | 188 | if (repo !== undefined && canRead(f.db, repo, f.user)) silenced.set(id, repo); |
| 178 | 189 | } |
| 190 | // Chips (`core/feed_chips.ts`): said under the card, and a hidden | |
| 191 | // person's work is not listed, as the web inbox drops their asks. | |
| 192 | const chips = chipsFor(f.db, f.user.id); | |
| 193 | hiddenChips = [ | |
| 194 | ...KIND_CHIP_NAMES.filter((k) => chips.kinds.has(k)).map((k) => KIND_CHIP_LABEL[k]), | |
| 195 | ...hiddenPeopleNames(f.db, chips).map((n) => `@${n}`), | |
| 196 | ]; | |
| 179 | 197 | const assigned = issues.flatMap((issue) => { |
| 180 | 198 | const repo = byId.get(issue.repoId); |
| 181 | 199 | if ( |
| @@ -184,7 +202,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 184 | 202 | !mayView(f.db, repo, issue, f.user) |
| 185 | 203 | ) |
| 186 | 204 | return []; |
| 187 | if (muted.has(repo.id)) return []; | |
| 205 | if (muted.has(repo.id) || chips.people.has(issue.authorId)) return []; | |
| 188 | 206 | return [{ issue, repo }]; |
| 189 | 207 | }); |
| 190 | 208 | return [...assigned, ...handOvers(assigned)]; |
| @@ -343,6 +361,46 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 343 | 361 | ctx.toast("listening again", "success"); |
| 344 | 362 | }; |
| 345 | 363 | |
| 364 | /** Take back every hidden kind and person. */ | |
| 365 | const showChips = (): void => { | |
| 366 | if (f.user === undefined || hiddenChips.length === 0) return; | |
| 367 | const chips = chipsFor(f.db, f.user.id); | |
| 368 | for (const k of chips.kinds) setKindChip(f.db, f.user.id, k, false); | |
| 369 | for (const n of hiddenPeopleNames(f.db, chips)) setPersonChip(f.db, f.user.id, n, false); | |
| 370 | reload(); | |
| 371 | ctx.toast("showing everything again", "success"); | |
| 372 | }; | |
| 373 | ||
| 374 | /** Hide the person who opened the row under the cursor. */ | |
| 375 | const hidePerson = (): void => { | |
| 376 | const item = onYou[at("onyou").index]; | |
| 377 | if (f.user === undefined || item === undefined) return; | |
| 378 | const done = setPersonChip(f.db, f.user.id, item.issue.authorName, true); | |
| 379 | reload(); | |
| 380 | ctx.toast( | |
| 381 | done === "ok" ? `hid @${item.issue.authorName} · C show again` : "you cannot hide that person", | |
| 382 | done === "ok" ? "success" : "attn", | |
| 383 | ); | |
| 384 | }; | |
| 385 | ||
| 386 | /** `K` waits for the kind to toggle: p, d, w or r. Anything else cancels. */ | |
| 387 | let pickingKind = false; | |
outdated
Hiding the next unhidden kind in a fixed order means you cannot hide Releases alone, or show one kind again. The page can do both. Let the person pick the kind and toggle it. |
||
| 388 | const KIND_KEYS: Record<string, KindChip> = { | |
| 389 | p: "pulls", | |
| 390 | d: "decisions", | |
| 391 | w: "words", | |
| 392 | r: "releases", | |
| 393 | }; | |
| 394 | const toggleKind = (key: string): void => { | |
| 395 | pickingKind = false; | |
| 396 | const kind = KIND_KEYS[key]; | |
| 397 | if (f.user === undefined || kind === undefined) return; | |
| 398 | const hide = !chipsFor(f.db, f.user.id).kinds.has(kind); | |
| 399 | setKindChip(f.db, f.user.id, kind, hide); | |
| 400 | reload(); | |
| 401 | ctx.toast(`${hide ? "hid" : "showing"} ${KIND_CHIP_LABEL[kind]}`, "success"); | |
| 402 | }; | |
| 403 | ||
| 346 | 404 | /** Yours with an empty filter; anything you can see once you type — |
| 347 | 405 | * the one way to find someone else's repository from here. */ |
| 348 | 406 | const shown = (): Repo[] => |
| @@ -460,6 +518,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 460 | 518 | : []), |
| 461 | 519 | ...(lastSet !== undefined ? [binding(["u"], "undo")] : []), |
| 462 | 520 | ...(silenced.size > 0 ? [binding(["L"], "listen again")] : []), |
| 521 | ...(f.signedIn ? [binding(["K"], "toggle a kind")] : []), | |
| 522 | ...(hiddenChips.length > 0 ? [binding(["C"], "show hidden")] : []), | |
| 463 | 523 | binding(["d"], "unpin", { |
| 464 | 524 | disabled: focus !== "machine" || pins.length === 0, |
| 465 | 525 | }), |
| @@ -545,6 +605,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 545 | 605 | drawMachine(s, machine!, c, set); |
| 546 | 606 | }, |
| 547 | 607 | key(e) { |
| 608 | if (pickingKind) return toggleKind(e.key), true; | |
| 548 | 609 | if (filter.key(e)) { |
| 549 | 610 | at("repos").clamp(shown().length); |
| 550 | 611 | focus = "repos"; |
| @@ -573,6 +634,13 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 573 | 634 | if (e.key === "u" && f.user) return undoSet(), true; |
| 574 | 635 | if (e.key === "U" && f.user) return undoHand(), true; |
| 575 | 636 | if (e.key === "L" && f.user) return listenAgain(), true; |
| 637 | if (e.key === "C" && f.user) return showChips(), true; | |
| 638 | if (e.key === "K" && f.user) { | |
| 639 | pickingKind = true; | |
| 640 | ctx.toast("toggle: p pulls · d decisions · w words · r releases", "attn"); | |
| 641 | return true; | |
| 642 | } | |
| 643 | if (e.key === "H" && focus === "onyou" && f.user) return hidePerson(), true; | |
| 576 | 644 | if (e.key === "d" && focus === "machine") { |
| 577 | 645 | unpin(pins[at("machine").index]); |
| 578 | 646 | return true; |
| @@ -668,6 +736,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 668 | 736 | parts.push( |
| 669 | 737 | `${silenced.size} ${silenced.size === 1 ? "repository" : "repositories"} muted · L listen again`, |
| 670 | 738 | ); |
| 739 | if (hiddenChips.length > 0) parts.push(`hidden: ${hiddenChips.join(", ")} · C show again`); | |
| 671 | 740 | if (lastSet !== undefined) parts.push(`u undo ${lastSet.verb}`); |
| 672 | 741 | if (lastHand !== undefined) parts.push("U undo decider"); |
| 673 | 742 | if (onYou[at("onyou").index]?.hand === true) parts.push("D let the decider"); |
src/web/studio/asks.ts +17 −1
| @@ -16,6 +16,7 @@ import { appsRuntime } from "../../apps/runtime.ts"; | ||
| 16 | 16 | import { appsForRepos, getAppByRepo, listApps } from "../../core/apps.ts"; |
| 17 | 17 | import { latestDecision, stopStands } from "../../core/decisions.ts"; |
| 18 | 18 | import { getHold, holdsFor } from "../../core/holds.ts"; |
| 19 | import { anyChips, chipsFor } from "../../core/feed_chips.ts"; | |
| 19 | 20 | import { askDismissals, mutedRepos } from "../../core/interactions.ts"; |
| 20 | 21 | import { askMeasure, syncAskLedger, type AskEnd } from "../../core/ask_ledger.ts"; |
| 21 | 22 | import { |
| @@ -43,7 +44,7 @@ import { | ||
| 43 | 44 | automaticRunsSince, |
| 44 | 45 | latestRunsForIssues, |
| 45 | 46 | } from "../../core/runs.ts"; |
| 46 | import { getUserById, type User } from "../../core/users.ts"; | |
| 47 | import { getUserById, getUserByName, type User } from "../../core/users.ts"; | |
| 47 | 48 | import { |
| 48 | 49 | isPausedAtCeiling, |
| 49 | 50 | plannerDeclines, |
| @@ -490,6 +491,20 @@ function notDismissed<T extends AskCandidate>( | ||
| 490 | 491 | ): T[] { |
| 491 | 492 | const muted = mutedRepos(db, user.id); |
| 492 | 493 | const dismissed = askDismissals(db, user.id); |
| 494 | // Chips (`core/feed_chips.ts`): a hidden person's asks, and the asks of a | |
outdated
This matches by lower-cased username, while |
||
| 495 | // hidden kind — those about a pull, or the ones about no pull at all. | |
| 496 | const chips = chipsFor(db, user.id); | |
| 497 | // People are matched by id, as the feed does; a name is looked up once. | |
| 498 | const ids = new Map<string, string | undefined>(); | |
| 499 | const hiddenWho = (who: string): boolean => { | |
| 500 | if (chips.people.size === 0) return false; | |
| 501 | if (!ids.has(who)) ids.set(who, getUserByName(db, who)?.id); | |
| 502 | const id = ids.get(who); | |
| 503 | return id !== undefined && chips.people.has(id); | |
| 504 | }; | |
outdated
With |
||
| 505 | const chipped = (a: T): boolean => | |
| 506 | hiddenWho(a.who) || | |
| 507 | (a.pull !== undefined ? chips.kinds.has("pulls") : chips.kinds.has("decisions")); | |
| 493 | 508 | const holds = (id: string, since: string): boolean => |
| 494 | 509 | (dismissed.get(`ask:${id}`) ?? "") > since; |
| 495 | 510 | // A hand-over the decider or the standing rule set aside is closed for |
| @@ -502,6 +517,7 @@ function notDismissed<T extends AskCandidate>( | ||
| 502 | 517 | return asks.filter( |
| 503 | 518 | (a) => |
| 504 | 519 | !muted.has(a.repo.id) && |
| 520 | !chipped(a) && | |
| 505 | 521 | !holds(a.id, a.since) && |
| 506 | 522 | !holds(groupId(a), a.since) && |
| 507 | 523 | !setAside(a), |
src/web/studio/feed.ts +1
| @@ -40,6 +40,7 @@ const KIND_LABEL: Record<FeedItem["kind"], string> = { | ||
| 40 | 40 | tell: "Told", |
| 41 | 41 | reply: "Reply", |
| 42 | 42 | look: "Look", |
| 43 | release: "Release", | |
| 43 | 44 | }; |
| 44 | 45 | |
| 45 | 46 | /** |
src/web/studio/feed_chips.ts added +81
| @@ -0,0 +1,81 @@ | ||
| 1 | /** | |
| 2 | * The chips above the feed (#1598): a button for each kind of post and each | |
| 3 | * hidden person, one tap to hide or show. Plain forms that post and come | |
| 4 | * home, so there is no script and no layout shift; the choice is saved per | |
| 5 | * viewer (`core/feed_chips.ts`) and the feed, the inbox and the apps rail | |
| 6 | * read it. | |
| 7 | */ | |
| 8 | ||
| 9 | import { | |
| 10 | KIND_CHIP_LABEL, | |
| 11 | KIND_CHIP_NAMES, | |
| 12 | chipsFor, | |
| 13 | hiddenPeopleNames, | |
| 14 | isKindChip, | |
| 15 | setKindChip, | |
| 16 | setPersonChip, | |
| 17 | } from "../../core/feed_chips.ts"; | |
| 18 | import type { User } from "../../core/users.ts"; | |
| 19 | import type { Ctx } from "../../http/context.ts"; | |
| 20 | import { signInFirst } from "../chrome.ts"; | |
| 21 | import { readForm } from "../form.ts"; | |
| 22 | import { html, type Html } from "../html.ts"; | |
| 23 | import { flashTo, redirect } from "../layout.ts"; | |
| 24 | ||
| 25 | const USERNAME = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/; | |
| 26 | ||
| 27 | export function chipsBar(ctx: Ctx, user: User): Html { | |
| 28 | const chips = chipsFor(ctx.app.db, user.id); | |
| 29 | const chip = (field: "kind" | "person", value: string, label: string, hidden: boolean): Html => | |
| 30 | html`<form method="post" action="/feed/chips" class="inline"> | |
| 31 | <input type="hidden" name="${field}" value="${value}" /> | |
| 32 | <input type="hidden" name="hide" value="${hidden ? "0" : "1"}" /> | |
| 33 | <button | |
| 34 | type="submit" | |
| 35 | class="btn btn-sm${hidden ? " btn-ghost" : ""}" | |
| 36 | aria-pressed="${hidden ? "false" : "true"}" | |
| 37 | title="${hidden ? "Show" : "Hide"} ${label}" | |
| 38 | > | |
| 39 | ${hidden ? "Show" : ""} ${label} | |
| 40 | </button> | |
| 41 | </form>`; | |
| 42 | return html`<div class="bar feed-chips" id="feed-chips" aria-label="Filter the feed"> | |
| 43 | ${KIND_CHIP_NAMES.map((k) => chip("kind", k, KIND_CHIP_LABEL[k], chips.kinds.has(k)))} | |
| 44 | ${hiddenPeopleNames(ctx.app.db, chips).map((n) => chip("person", n, n, true))} | |
| 45 | <form method="post" action="/feed/chips" class="inline"> | |
| 46 | <input type="hidden" name="hide" value="1" /> | |
| 47 | <input | |
| 48 | type="text" | |
| 49 | name="person" | |
| 50 | class="small" | |
| 51 | placeholder="Hide a person" | |
| 52 | aria-label="Hide a person" | |
| 53 | maxlength="64" | |
| 54 | autocomplete="off" | |
| 55 | /> | |
| 56 | </form> | |
| 57 | </div>`; | |
| 58 | } | |
| 59 | ||
| 60 | /** POST /feed/chips — hide or show one kind or one person for the viewer. */ | |
| 61 | export async function feedChipsSubmit(ctx: Ctx): Promise<Response> { | |
| 62 | const user = ctx.auth.user; | |
| 63 | if (!user) return signInFirst(ctx); | |
| 64 | const form = await readForm(ctx, "rw"); | |
| 65 | if (form instanceof Response) return form; | |
| 66 | const hide = form.get("hide") !== "0"; | |
| 67 | const kind = form.get("kind"); | |
| 68 | const person = form.get("person"); | |
| 69 | if (typeof kind === "string" && kind !== "") { | |
| 70 | if (!isKindChip(kind)) return new Response("bad request", { status: 400 }); | |
| 71 | setKindChip(ctx.app.db, user.id, kind, hide); | |
| 72 | } else if (typeof person === "string" && person.trim() !== "") { | |
| 73 | const name = person.trim().replace(/^@/, ""); | |
| 74 | if (!USERNAME.test(name)) return new Response("bad request", { status: 400 }); | |
| 75 | const done = setPersonChip(ctx.app.db, user.id, name, hide); | |
| 76 | if (done === "unknown") return flashTo(ctx, "/", { tone: "danger", message: "No such person." }); | |
outdated
A name that is no account comes back as |
||
| 77 | if (done === "self") return flashTo(ctx, "/", { tone: "danger", message: "You cannot hide yourself." }); | |
| 78 | if (done === "full") return flashTo(ctx, "/", { tone: "danger", message: "Too many people hidden." }); | |
| 79 | } else return new Response("bad request", { status: 400 }); | |
| 80 | return redirect("/"); | |
| 81 | } |
src/web/studio/home.ts +6 −1
| @@ -16,6 +16,7 @@ import { | ||
| 16 | 16 | } from "../../actions/front.ts"; |
| 17 | 17 | import { appsRuntime } from "../../apps/runtime.ts"; |
| 18 | 18 | import { appsForRepos } from "../../core/apps.ts"; |
| 19 | import { chipsFor } from "../../core/feed_chips.ts"; | |
| 19 | 20 | import { WEIGHT_MAX, WEIGHT_NAMES } from "../../core/front.ts"; |
| 20 | 21 | import { LOOK_SIZES } from "../../core/looks.ts"; |
| 21 | 22 | import { canRead, getRepo, type Repo } from "../../core/repos.ts"; |
| @@ -46,6 +47,7 @@ import { | ||
| 46 | 47 | } from "../pages/site.ts"; |
| 47 | 48 | import { writableAppsOf } from "./asks.ts"; |
| 48 | 49 | import { needsYouSection, type AsksTop } from "./asks_page.ts"; |
| 50 | import { chipsBar } from "./feed_chips.ts"; | |
| 49 | 51 | import { composer, feedJs, feedNote, feedRegion } from "./feed.ts"; |
| 50 | 52 | import { homeTabs } from "./home_tabs.ts"; |
| 51 | 53 | import { crewKeyNote } from "./crew.ts"; |
| @@ -67,7 +69,9 @@ const RAIL_APPS = 8; | ||
| 67 | 69 | * The apps' full rows are `/apps`. |
| 68 | 70 | */ |
| 69 | 71 | function yourApps(ctx: Ctx, user: User): Html { |
| 70 | const { repos } = writableAppsOf(ctx, user); | |
| 72 | // An app of a person the viewer hid is not on their rail (`core/feed_chips.ts`). | |
| 73 | const { people } = chipsFor(ctx.app.db, user.id); | |
| 74 | const repos = writableAppsOf(ctx, user).repos.filter((r) => !people.has(r.ownerId)); | |
| 71 | 75 | const runtime = appsRuntime(ctx.app); |
| 72 | 76 | const records = appsForRepos( |
| 73 | 77 | ctx.app.db, |
| @@ -197,6 +201,7 @@ export async function studioHome( | ||
| 197 | 201 | <a class="small muted" href="/asked">What you asked for</a> |
| 198 | 202 | </div> |
| 199 | 203 | ${feedNote()} |
| 204 | ${chipsBar(ctx, user)} | |
| 200 | 205 | ${feedRegion(user, ctx)} |
| 201 | 206 | </div> |
| 202 | 207 | <aside class="dash-rail stack home-rail"> |
test/feed-chips.test.ts added +251
| @@ -0,0 +1,251 @@ | ||
| 1 | /** | |
| 2 | * Kind and people chips (#1598): each removes what it names and nothing | |
| 3 | * else, from the feed (`readFeed`, `/api/v1/feed`), the asks (the inbox and | |
| 4 | * `/api/v1/asks`), the home's apps rail (`/live/apps`); saved per viewer. | |
| 5 | */ | |
| 6 | ||
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 13 | import { assignIssue } from "../src/actions/issues.ts"; | |
| 14 | import { openPull } from "../src/actions/pulls.ts"; | |
| 15 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 16 | import { createApp as createAppRecord } from "../src/core/apps.ts"; | |
| 17 | import { chipsFor, setKindChip, setPersonChip } from "../src/core/feed_chips.ts"; | |
| 18 | import { getIssueById } from "../src/core/issues.ts"; | |
| 19 | import type { Repo } from "../src/core/repos.ts"; | |
| 20 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 21 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; | |
| 22 | import { readFeed } from "../src/feed/feed.ts"; | |
| 23 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 24 | import { askLinesFor } from "../src/web/studio/asks.ts"; | |
| 25 | import { quietLogs } from "./helpers/globals.ts"; | |
| 26 | ||
| 27 | quietLogs(); | |
| 28 | ||
| 29 | const PASSWORD = "a-long-chips-passphrase"; | |
| 30 | ||
| 31 | describe("feed chips", () => { | |
| 32 | let dataDir = ""; | |
| 33 | let app: App; | |
| 34 | let servers: Servers; | |
| 35 | let alice: User; | |
| 36 | let bob: User; | |
| 37 | let cookie = ""; | |
| 38 | let repo: Repo; | |
| 39 | ||
| 40 | const headers = (c: string) => ({ cookie: `${c}; forge_mode=studio`, origin: servers.url }); | |
| 41 | const post = (path: string, fields: [string, string][], c = cookie) => | |
| 42 | fetch(`${servers.url}${path}`, { | |
| 43 | method: "POST", | |
| 44 | headers: headers(c), | |
| 45 | body: new URLSearchParams(fields), | |
| 46 | redirect: "manual", | |
| 47 | }); | |
| 48 | const apiFeed = async (): Promise<{ kind: string; actor: string | null }[]> => | |
| 49 | ( | |
| 50 | (await fetch(`${servers.url}/api/v1/feed`, { headers: headers(cookie) }).then((r) => | |
| 51 | r.json(), | |
| 52 | )) as { items: { kind: string; actor: string | null }[] } | |
| 53 | ).items; | |
| 54 | const kinds = () => readFeed(app.db, alice).items.map((i) => i.kind); | |
| 55 | ||
| 56 | beforeAll(async () => { | |
| 57 | dataDir = await mkdtemp(join(tmpdir(), "forge-feed-chips-")); | |
| 58 | app = createApp({ dataDir, port: 0 }); | |
| 59 | servers = await serve(app); | |
| 60 | for (const name of ["alice", "bob"]) { | |
| 61 | const made = await createUser(app.db, { | |
| 62 | trusted: true, | |
| 63 | username: name, | |
| 64 | email: `${name}@forge.local`, | |
| 65 | password: PASSWORD, | |
| 66 | adminIfFirst: name === "alice", | |
| 67 | }); | |
| 68 | if (!made.ok) throw new Error(made.error); | |
| 69 | if (name === "alice") alice = made.value; | |
| 70 | else bob = made.value; | |
| 71 | } | |
| 72 | const res = await fetch(`${servers.url}/signin`, { | |
| 73 | method: "POST", | |
| 74 | body: new URLSearchParams({ username: "alice", password: PASSWORD }), | |
| 75 | redirect: "manual", | |
| 76 | }); | |
| 77 | cookie = (res.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 78 | await createAgent(app, alice, { username: "bot" }); | |
| 79 | const made = await createRepo(app, alice, { name: "chipped", visibility: "public" }); | |
| 80 | if (!made.ok) throw new Error(String(made.error)); | |
| 81 | repo = made.value; | |
| 82 | await commitToBranch(app, alice, repo, { | |
| 83 | message: "seed", | |
| 84 | files: [{ path: "README.md", content: "# chipped\n" }], | |
| 85 | }); | |
| 86 | addToCrew(app, alice, repo, "bot"); | |
| 87 | await commitToBranch(app, alice, repo, { | |
| 88 | branch: "bot/1", | |
| 89 | base: "main", | |
| 90 | message: "Chipped work", | |
| 91 | files: [{ path: "F.md", content: "1\n" }], | |
| 92 | }); | |
| 93 | const opened = await openPull(app, getUserByName(app.db, "bot")!, repo, { | |
| 94 | title: "Chipped work", | |
| 95 | body: "", | |
| 96 | baseBranch: "main", | |
| 97 | headBranch: "bot/1", | |
| 98 | }); | |
| 99 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 100 | const run = createRun(app.db, { | |
| 101 | repoId: repo.id, | |
| 102 | kind: "check", | |
| 103 | issueId: opened.value.id, | |
| 104 | env: `pull-${opened.value.number}`, | |
| 105 | commitOid: opened.value.headOid, | |
| 106 | reason: "pull", | |
| 107 | }); | |
| 108 | claimRun(app.db, run.id); | |
| 109 | finishRun(app.db, run.id, { state: "ok", summary: "ok" }); | |
| 110 | expect(assignIssue(app, alice, repo, getIssueById(app.db, opened.value.id)!, alice).ok).toBe(true); | |
| 111 | // A release: the app is serving a new version, by the owner. | |
| 112 | createAppRecord(app.db, { repoId: repo.id, slug: "chipped", access: "public" }); | |
| 113 | app.bus.append({ | |
| 114 | kind: "app.serving", | |
| 115 | repoId: repo.id, | |
| 116 | actorId: alice.id, | |
| 117 | payload: { env: "production" }, | |
| 118 | }); | |
| 119 | }, 30_000); | |
| 120 | ||
| 121 | afterAll(async () => { | |
| 122 | await servers.stop(); | |
| 123 | await rm(dataDir, { recursive: true, force: true }); | |
| 124 | }); | |
| 125 | ||
| 126 | test("with no chip the feed holds a change and a release", () => { | |
| 127 | expect(kinds()).toContain("pull"); | |
| 128 | expect(kinds()).toContain("release"); | |
| 129 | expect(askLinesFor(app.db, alice)).toHaveLength(1); | |
| 130 | }); | |
| 131 | ||
| 132 | test("a kind chip removes that kind and nothing else, on the feed and the API", async () => { | |
| 133 | const before = kinds(); | |
| 134 | setKindChip(app.db, alice.id, "pulls", true); | |
| 135 | // A change that waits on alice is also an ask about a pull: both go. | |
| 136 | expect(kinds()).toEqual(before.filter((k) => k !== "pull" && k !== "ask")); | |
| 137 | expect((await apiFeed()).map((i) => i.kind)).not.toContain("pull"); | |
| 138 | expect((await apiFeed()).map((i) => i.kind)).toContain("release"); | |
| 139 | setKindChip(app.db, alice.id, "pulls", false); | |
| 140 | expect(kinds()).toEqual(before); | |
| 141 | setKindChip(app.db, alice.id, "releases", true); | |
| 142 | expect(kinds()).toEqual(before.filter((k) => k !== "release")); | |
| 143 | setKindChip(app.db, alice.id, "releases", false); | |
| 144 | // A kind nothing here is of removes nothing. | |
| 145 | setKindChip(app.db, alice.id, "words", true); | |
| 146 | setKindChip(app.db, alice.id, "decisions", true); | |
| 147 | expect(kinds()).toEqual(before); | |
| 148 | setKindChip(app.db, alice.id, "words", false); | |
| 149 | setKindChip(app.db, alice.id, "decisions", false); | |
| 150 | }); | |
| 151 | ||
| 152 | test("a people chip removes that person's posts and nothing else; yourself and strangers are refused", async () => { | |
| 153 | const before = readFeed(app.db, alice).items; | |
| 154 | expect(before.some((i) => i.actor === "bot")).toBe(true); | |
| 155 | expect(setPersonChip(app.db, alice.id, "bob", true)).toBe("ok"); | |
| 156 | expect(readFeed(app.db, alice).items.map((i) => i.id)).toEqual(before.map((i) => i.id)); | |
| 157 | expect(setPersonChip(app.db, alice.id, "bob", false)).toBe("ok"); | |
| 158 | expect(setPersonChip(app.db, alice.id, "bot", true)).toBe("ok"); | |
| 159 | expect(readFeed(app.db, alice).items.map((i) => i.id)).toEqual( | |
| 160 | // The change's own post and the ask about it, both the bot's. | |
| 161 | before.filter((i) => i.actor !== "bot" && i.kind !== "ask").map((i) => i.id), | |
| 162 | ); | |
| 163 | expect(askLinesFor(app.db, alice)).toHaveLength(0); | |
| 164 | expect((await apiFeed()).some((i) => i.actor === "bot")).toBe(false); | |
| 165 | expect(setPersonChip(app.db, alice.id, "alice", true)).toBe("self"); | |
| 166 | expect(setPersonChip(app.db, alice.id, "nobody", true)).toBe("unknown"); | |
| 167 | setPersonChip(app.db, alice.id, "bot", false); | |
| 168 | }); | |
| 169 | ||
| 170 | test("the inbox: a hidden person's or kind's asks leave it, others stay", async () => { | |
| 171 | expect(askLinesFor(app.db, alice)).toHaveLength(1); | |
| 172 | setKindChip(app.db, alice.id, "decisions", true); | |
| 173 | expect(askLinesFor(app.db, alice)).toHaveLength(1); | |
| 174 | setKindChip(app.db, alice.id, "decisions", false); | |
| 175 | setPersonChip(app.db, alice.id, "bob", true); | |
| 176 | expect(askLinesFor(app.db, alice)).toHaveLength(1); | |
| 177 | setPersonChip(app.db, alice.id, "bob", false); | |
| 178 | setPersonChip(app.db, alice.id, "bot", true); | |
| 179 | expect(askLinesFor(app.db, alice)).toHaveLength(0); | |
| 180 | setPersonChip(app.db, alice.id, "bot", false); | |
| 181 | expect(askLinesFor(app.db, alice)).toHaveLength(1); | |
| 182 | setKindChip(app.db, alice.id, "pulls", true); | |
| 183 | expect(askLinesFor(app.db, alice)).toHaveLength(0); | |
| 184 | const api = (await fetch(`${servers.url}/api/v1/asks`, { headers: headers(cookie) }).then((r) => | |
| 185 | r.json(), | |
| 186 | )) as { rows: unknown[] }; | |
| 187 | expect(api.rows).toHaveLength(0); | |
| 188 | setKindChip(app.db, alice.id, "pulls", false); | |
| 189 | expect(askLinesFor(app.db, alice)).toHaveLength(1); | |
| 190 | }); | |
| 191 | ||
| 192 | test("the apps rail drops a hidden person's apps", async () => { | |
| 193 | const live = () => | |
| 194 | fetch(`${servers.url}/live/apps`, { headers: headers(cookie) }).then((r) => r.text()); | |
| 195 | expect(await live()).toContain("alice/chipped"); | |
| 196 | // Alice is the forge's admin, so bob's app is on her rail too. | |
| 197 | const bobRepo = await createRepo(app, bob, { name: "theirs", visibility: "public" }); | |
| 198 | if (!bobRepo.ok) throw new Error(String(bobRepo.error)); | |
| 199 | expect(createAppRecord(app.db, { repoId: bobRepo.value.id, slug: "theirs", access: "public" }).ok).toBe(true); | |
| 200 | expect(await live()).toContain("bob/theirs"); | |
| 201 | setPersonChip(app.db, alice.id, "bob", true); | |
| 202 | const hidden = await live(); | |
| 203 | expect(hidden).not.toContain("bob/theirs"); | |
| 204 | expect(hidden).toContain("alice/chipped"); | |
| 205 | setPersonChip(app.db, alice.id, "bob", false); | |
| 206 | }); | |
| 207 | ||
| 208 | test("the home form and the API save per viewer; foreign origins and bad input are refused", async () => { | |
| 209 | const page = await fetch(`${servers.url}/`, { headers: headers(cookie) }).then((r) => r.text()); | |
| 210 | expect(page).toContain('action="/feed/chips"'); | |
| 211 | expect((await post("/feed/chips", [["kind", "pulls"], ["hide", "1"]])).status).toBe(303); | |
| 212 | expect(chipsFor(app.db, alice.id).kinds.has("pulls")).toBe(true); | |
| 213 | expect(chipsFor(app.db, bob.id).kinds.size).toBe(0); | |
| 214 | const saved = (await fetch(`${servers.url}/api/v1/feed/chips`, { headers: headers(cookie) }).then((r) => | |
| 215 | r.json(), | |
| 216 | )) as { kinds: string[]; people: string[] }; | |
| 217 | expect(saved.kinds).toEqual(["pulls"]); | |
| 218 | expect((await post("/feed/chips", [["kind", "pulls"], ["hide", "0"]])).status).toBe(303); | |
| 219 | expect(chipsFor(app.db, alice.id).kinds.size).toBe(0); | |
| 220 | expect((await post("/feed/chips", [["person", "bob"]])).status).toBe(303); | |
| 221 | expect([...chipsFor(app.db, alice.id).people]).toEqual([bob.id]); | |
| 222 | const nobody = await post("/feed/chips", [["person", "nobody-here"]]); | |
| 223 | expect(nobody.status).toBe(303); | |
| 224 | expect(decodeURIComponent(nobody.headers.get("set-cookie") ?? "")).toContain("No such person"); | |
| 225 | expect(chipsFor(app.db, alice.id).people.size).toBe(1); | |
| 226 | expect((await post("/feed/chips", [["kind", "evil"]])).status).toBe(400); | |
| 227 | expect((await post("/feed/chips", [["person", "../x"]])).status).toBe(400); | |
| 228 | expect((await post("/feed/chips", [])).status).toBe(400); | |
| 229 | const cross = await fetch(`${servers.url}/feed/chips`, { | |
| 230 | method: "POST", | |
| 231 | headers: { cookie, origin: "https://evil.example" }, | |
| 232 | body: new URLSearchParams({ kind: "words" }), | |
| 233 | redirect: "manual", | |
| 234 | }); | |
| 235 | expect(cross.status).toBe(403); | |
| 236 | expect(chipsFor(app.db, alice.id).kinds.size).toBe(0); | |
| 237 | const api = await fetch(`${servers.url}/api/v1/feed/chips`, { | |
| 238 | method: "POST", | |
| 239 | headers: { ...headers(cookie), "content-type": "application/json" }, | |
| 240 | body: JSON.stringify({ kind: "words" }), | |
| 241 | }); | |
| 242 | expect(api.status).toBe(201); | |
| 243 | expect(chipsFor(app.db, alice.id).kinds.has("words")).toBe(true); | |
| 244 | const bad = await fetch(`${servers.url}/api/v1/feed/chips`, { | |
| 245 | method: "POST", | |
| 246 | headers: { ...headers(cookie), "content-type": "application/json" }, | |
| 247 | body: JSON.stringify({ kind: "nope" }), | |
| 248 | }); | |
| 249 | expect(bad.status).toBe(422); | |
| 250 | }); | |
| 251 | }); |
test/mcp.test.ts +18
| @@ -189,6 +189,7 @@ describe("the forge over MCP", () => { | ||
| 189 | 189 | "app_members", |
| 190 | 190 | "explore", |
| 191 | 191 | "feed", |
| 192 | "feed_chips", | |
| 192 | 193 | "make_it_yours", |
| 193 | 194 | "front_page", |
| 194 | 195 | "map", |
| @@ -706,6 +707,23 @@ describe("the forge over MCP", () => { | ||
| 706 | 707 | } |
| 707 | 708 | }); |
| 708 | 709 | |
| 710 | test("feed_chips reads freely, plans by default, and sets only with dryRun false and rw", async () => { | |
| 711 | const listed = (await call(rw, "tools/list")).body.result.tools.find((x: any) => x.name === "feed_chips"); | |
| 712 | expect(listed.annotations.readOnlyHint).toBe(false); | |
| 713 | expect((await tool(rw, "feed_chips")).value).toEqual({ kinds: [], people: [] }); | |
| 714 | expect((await tool(rw, "feed_chips", { kind: "pulls" })).value.says).toContain("dryRun: false"); | |
| 715 | expect((await tool(rw, "feed_chips")).value.kinds).toEqual([]); | |
| 716 | const off = { dryRun: false }; | |
| 717 | expect((await tool(rw, "feed_chips", { kind: "pulls", ...off })).value).toEqual({ kinds: ["pulls"], people: [] }); | |
| 718 | expect((await tool(rw, "feed_chips", { person: "bob", ...off })).value.people).toEqual(["bob"]); | |
| 719 | expect((await tool(ro, "feed_chips")).value.kinds).toEqual(["pulls"]); | |
| 720 | expect((await tool(ro, "feed_chips", { kind: "words", ...off })).error).toContain("read, not act"); | |
| 721 | expect((await tool(rw, "feed_chips", { kind: "nope", ...off })).error).toContain("kind is one of"); | |
| 722 | expect((await tool(rw, "feed_chips", { person: "nobody-here", ...off })).error).toContain("no such person"); | |
| 723 | expect((await tool(rw, "feed_chips", { kind: "pulls", hidden: false, ...off })).value.kinds).toEqual([]); | |
| 724 | expect((await tool(rw, "feed_chips", { person: "bob", hidden: false, ...off })).value.people).toEqual([]); | |
| 725 | }); | |
| 726 | ||
| 709 | 727 | test("GET /contract/openapi.json describes the public API", async () => { |
| 710 | 728 | const res = await fetch(`${base}/contract/openapi.json`); |
| 711 | 729 | expect(res.status).toBe(200); |
test/tui-onyou.test.ts +42
| @@ -14,6 +14,7 @@ import { createRepo } from "../src/actions/repos.ts"; | ||
| 14 | 14 | import { signUp } from "../src/actions/users.ts"; |
| 15 | 15 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 16 | 16 | import { getIssue } from "../src/core/issues.ts"; |
| 17 | import { chipsFor, setKindChip, setPersonChip } from "../src/core/feed_chips.ts"; | |
| 17 | 18 | import { mutedRepos, recordInteraction } from "../src/core/interactions.ts"; |
| 18 | 19 | import { markVerified } from "../src/core/verify.ts"; |
| 19 | 20 | import type { Repo } from "../src/core/repos.ts"; |
| @@ -150,6 +151,47 @@ describe("terminal On you: mutes and many in one move", () => { | ||
| 150 | 151 | h.stop(); |
| 151 | 152 | }); |
| 152 | 153 | |
| 154 | test("chips set on the web are listed here, and C shows them again", async () => { | |
| 155 | setKindChip(forge.db, alice.id, "pulls", true); | |
| 156 | setPersonChip(forge.db, alice.id, "bob", true); | |
| 157 | const h = await boot(); | |
| 158 | expect(h.text()).toContain("hidden: Pulls to review, @bob"); | |
| 159 | await h.press("C"); | |
| 160 | expect(chipsFor(forge.db, alice.id).kinds.size).toBe(0); | |
| 161 | expect(chipsFor(forge.db, alice.id).people.size).toBe(0); | |
| 162 | expect(h.text()).not.toContain("hidden:"); | |
| 163 | h.stop(); | |
| 164 | }); | |
| 165 | ||
| 166 | test("K then a letter toggles that kind; H hides the person and their row leaves", async () => { | |
| 167 | const made = openIssue(forge, bob, lamp, { title: "From bob" }); | |
| 168 | if (!made.ok) throw new Error("issue failed"); | |
| 169 | assignIssue(forge, alice, lamp, made.value, alice); | |
| 170 | const h = await boot(); | |
| 171 | expect(h.text()).toContain("From bob"); | |
| 172 | await h.press("K", "r"); | |
| 173 | expect([...chipsFor(forge.db, alice.id).kinds]).toEqual(["releases"]); | |
| 174 | expect(h.text()).toContain("hidden: Releases"); | |
| 175 | await h.press("K", "p"); | |
| 176 | expect(chipsFor(forge.db, alice.id).kinds.size).toBe(2); | |
| 177 | await h.press("K", "r"); | |
| 178 | expect([...chipsFor(forge.db, alice.id).kinds]).toEqual(["pulls"]); | |
| 179 | await h.press("K", "x"); | |
| 180 | expect(chipsFor(forge.db, alice.id).kinds.size).toBe(1); | |
| 181 | // The cursor is on the first row; find bob's by moving until H takes him. | |
| 182 | for (let i = 0; i < 20 && chipsFor(forge.db, alice.id).people.size === 0; i++) { | |
| 183 | if (h.text().includes("From bob")) { | |
| 184 | await h.press("H"); | |
| 185 | if (chipsFor(forge.db, alice.id).people.size === 0) await h.press("j"); | |
| 186 | } | |
| 187 | } | |
| 188 | expect(chipsFor(forge.db, alice.id).people.size).toBe(1); | |
| 189 | expect(h.text()).not.toContain("From bob"); | |
| 190 | await h.press("C"); | |
| 191 | expect(h.text()).toContain("From bob"); | |
| 192 | h.stop(); | |
| 193 | }); | |
| 194 | ||
| 153 | 195 | test("listen again clears a muted repository with nothing assigned to you", async () => { |
| 154 | 196 | const quiet = await createRepo(forge, alice, { name: "quiet", visibility: "public" }); |
| 155 | 197 | if (!quiet.ok) throw new Error("repo failed"); |
Chips have no MCP tool and no terminal door, and the README does not mention them. The terminal dashboard already hides chipped asks via
askLinesForwithout showing which chip did it. Add both doors, each with a test.