@andrioid/paseo-attention-span 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/OVERVIEW.md +2 -0
  2. package/client/attention-screen.tsx +4 -0
  3. package/client/entity.tsx +15 -3
  4. package/client/icons.ts +2 -0
  5. package/client/item-actions.ts +24 -0
  6. package/client/item-row.tsx +5 -55
  7. package/client/next-up.tsx +49 -7
  8. package/client/stack.tsx +57 -0
  9. package/client/ui.tsx +4 -1
  10. package/client/wrap-up.tsx +181 -49
  11. package/docs/architecture.md +3 -2
  12. package/docs/screenshots/desktop-dark-doing-acknowledge.png +0 -0
  13. package/docs/screenshots/desktop-dark-doing-clear.png +0 -0
  14. package/docs/screenshots/desktop-dark-doing-issue-sheet.png +0 -0
  15. package/docs/screenshots/desktop-dark-doing-reviewers.png +0 -0
  16. package/docs/screenshots/desktop-dark-doing-sheet.png +0 -0
  17. package/docs/screenshots/desktop-dark-doing-wrap-dirty.png +0 -0
  18. package/docs/screenshots/desktop-dark-doing-wrap-multi.png +0 -0
  19. package/docs/screenshots/desktop-dark-doing-wrap.png +0 -0
  20. package/docs/screenshots/desktop-dark-doing.png +0 -0
  21. package/docs/screenshots/desktop-dark-history-filtered.png +0 -0
  22. package/docs/screenshots/desktop-dark-history-groups.png +0 -0
  23. package/docs/screenshots/desktop-dark-history.png +0 -0
  24. package/docs/screenshots/desktop-dark-next-up-code-repo.png +0 -0
  25. package/docs/screenshots/desktop-dark-next-up-setup.png +0 -0
  26. package/docs/screenshots/desktop-dark-next-up.png +0 -0
  27. package/docs/screenshots/desktop-dark-settings.png +0 -0
  28. package/docs/screenshots/desktop-dark-setup.png +0 -0
  29. package/docs/screenshots/desktop-dark-waiting.png +0 -0
  30. package/docs/screenshots/phone-dark-doing.png +0 -0
  31. package/docs/screenshots/phone-dark-history.png +0 -0
  32. package/docs/screenshots/phone-light-next-up-filtered.png +0 -0
  33. package/index.server.ts +2 -0
  34. package/package.json +1 -1
  35. package/requirements.yaml +2 -0
  36. package/server/classify.ts +29 -0
  37. package/server/fetch.ts +29 -3
  38. package/server/fixture.ts +16 -5
  39. package/server/github-types.ts +13 -0
  40. package/server/queries.ts +14 -0
  41. package/server/references.ts +12 -0
  42. package/server/service.ts +90 -11
  43. package/server/store.ts +17 -2
  44. package/server/view.ts +24 -4
  45. package/shared/attention.ts +26 -2
  46. package/shared/next-up-filter.ts +19 -0
  47. package/shared/rpc.ts +4 -0
  48. package/shared/wrap-up.ts +34 -9
package/server/fixture.ts CHANGED
@@ -128,7 +128,7 @@ export function builders(now: Date) {
128
128
  };
129
129
  }
130
130
 
131
- function search(parts: Partial<{ [K in Exclude<keyof SearchResult, "viewer">]: SearchResult[K]["nodes"] }>): SearchResult {
131
+ function search(parts: Partial<{ [K in Exclude<keyof SearchResult, "viewer" | "referenced">]: SearchResult[K]["nodes"] }>): SearchResult {
132
132
  const nodes = <K extends keyof typeof parts>(key: K) => ({ nodes: parts[key] ?? [] });
133
133
  return {
134
134
  viewer: { login: "me", id: "U_me" },
@@ -275,6 +275,8 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
275
275
  assigned: [
276
276
  { ...pickable(150, fields("🏔 P1 High", "🐇 Small (0.5-2d)", "🔙 Backend"), 20, "Bug", "Orders export times out for big shops"), ...onBoard(TODO_BOARD, "In progress") },
277
277
  { ...pickable(151, fields("🏕P2 Medium", "🐟 Tiny (< 4h)", "🔙 Backend"), 5, "Bug", "Price list import skips quoted rows", ISSUES_REPO), ...onBoard(TODO_BOARD, "Todo") },
278
+ // Its PRs, #194 and #195, merged into a feature branch, so GitHub left it open: Wrap up asks to close it [ATT-24].
279
+ { ...pickable(152, fields("🏕P2 Medium", "🐇 Small (0.5-2d)", "🖌 Frontend"), 12, "Feature", "Customer statements as PDF"), ...onBoard(TODO_BOARD, "In progress") },
278
280
  ],
279
281
  // Found by the preview config's Next up sources [NXT-09].
280
282
  unclaimed: [
@@ -287,10 +289,11 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
287
289
  sources: ["org:acme"],
288
290
  },
289
291
  { ...pickable(162, fields("🏝 P3 Low", "🐇 Small (0.5-2d)", "🔙 Backend"), 30, "Debt", "Merge the two import commands"), ...onBoard(TODO_BOARD, "Backlog"), sources: ["org:acme"] },
290
- { ...pickable(163, fields("🏝 P3 Low", "🐇 Small (0.5-2d)", "🖌 Frontend"), 8, "Bug", "Moving a task in the calendar loses its colour"), ...onBoard(TODO_BOARD, "Todo"), sources: ["org:acme"] },
292
+ // In another repository, so Unclaimed has some to group [NXT-14].
293
+ { ...pickable(163, fields("🏝 P3 Low", "🐇 Small (0.5-2d)", "🖌 Frontend"), 8, "Bug", "Moving a task in the calendar loses its colour", "acme/web"), ...onBoard(TODO_BOARD, "Todo"), sources: ["org:acme"] },
291
294
  { ...pickable(164, fields("🏝 P3 Low", "🦑 Large (1-2w)", "📱 Mobile app"), 60, "Feature", "Offline mode for time tracking"), ...onBoard(IDEAS_BOARD, "Exploring"), sources: ["org:acme"] },
292
295
  // On a board without a status yet.
293
- { ...pickable(166, { Effort: "🐂 Medium (2-5d)", Scope: "🖌 Frontend" }, 150, "Feature", "Dark mode for the planner"), ...onBoard(IDEAS_BOARD), sources: ["org:acme"] },
296
+ { ...pickable(166, { Effort: "🐂 Medium (2-5d)", Scope: "🖌 Frontend" }, 150, "Feature", "Dark mode for the planner", "acme/web"), ...onBoard(IDEAS_BOARD), sources: ["org:acme"] },
294
297
  // On no board.
295
298
  { ...pickable(165, {}, 3, "Task", "Devcontainers for pull requests", "me/tool"), projectItems: { nodes: [] }, sources: ["mine"] },
296
299
  ],
@@ -303,6 +306,8 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
303
306
  merged(179, "Move invoices to the new queue", 1),
304
307
  merged(173, "Speed up the order list", 9, 174),
305
308
  merged(175, "Remove the old importer", 16),
309
+ { ...merged(194, "Statement layout", 1), body: "First of two for #152" },
310
+ { ...merged(195, "Statement PDF download", 3 / 24), body: "Second of two for #152" },
306
311
  ],
307
312
  reviewed: [
308
313
  { number: 190, title: "Add the VAT export", url: `https://github.com/${REPO}/pull/190`, mergedAt: daysAgo(1), mergedBy: { login: "alice" }, repository, author: alice, labels: labels("feature") },
@@ -320,8 +325,10 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
320
325
  { id: "I_188", number: 188, title: "Export fails on empty months", url: `https://github.com/${REPO}/issues/188`, closedAt: daysAgo(6 / 24), stateReason: "COMPLETED", repository, timelineItems: { nodes: [{ actor: { login: "alice" } }] } },
321
326
  ],
322
327
  });
328
+ // The open issue #194 and #195 refer to, looked up after History's search [ATT-24].
329
+ const statements = { number: 152, title: "Customer statements as PDF", url: `https://github.com/${REPO}/issues/152`, state: "OPEN", repository, closedByPullRequestsReferences: { nodes: [] } };
323
330
  return {
324
- data,
331
+ data: { ...data, referenced: { [key(152)]: statements } },
325
332
  details: {
326
333
  behind: { [key(103)]: 1, [key(106)]: 12, [key(108)]: 139, [key(110)]: 2307, [key(114)]: 3, [key(115)]: 40 },
327
334
  fieldOptions: { acme: { Priority: ["🌋 P0 Urgent", "🏔 P1 High", "🏕P2 Medium", "🏝 P3 Low"] } },
@@ -338,7 +345,7 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
338
345
  function fixtureNow(now: Date, quiet: boolean): ReturnType<typeof fixture> {
339
346
  const { data, details } = fixture(now);
340
347
  if (!quiet) return { data, details };
341
- const empty = Object.fromEntries(Object.entries(data).map(([key, value]) => [key, key === "viewer" ? value : { nodes: [] }]));
348
+ const empty = Object.fromEntries(Object.entries(data).map(([key, value]) => [key, key === "viewer" ? value : key === "referenced" ? {} : { nodes: [] }]));
342
349
  return { data: empty as unknown as SearchResult, details };
343
350
  }
344
351
 
@@ -431,6 +438,8 @@ export const FIXTURE_AGENTS: AgentSummary[] = [
431
438
  // Its sheet counts lines and names the terminals archiving closes, as Paseo's own sheet would.
432
439
  agent("agent-186", `${REPO}#186`, "fix", "idle", 40, false, { ...sessionWorkspace("split-invoice-pdf", true, 1, true, 2)!, dirtyLines: { added: 12, deleted: 3 }, terminals: ["dev", "shell"] }, "Split invoice PDF"),
433
440
  agent("agent-190", `${REPO}#190`, "review", "idle", 60, false, sessionWorkspace("add-vat-export", false, 0), "Review PR 190: Add the VAT export"),
441
+ // On a PR under an issue Wrap up asks to close: it joins that row [ATT-24].
442
+ agent("agent-195", `${REPO}#195`, "fix", "idle", 10, false, sessionWorkspace("statement-pdf-download", false, 0), "Statement PDF download"),
434
443
  // With a review sub-agent it started, archived along with it.
435
444
  { ...agent("agent-172", `${REPO}#172`, "fix", "idle", 240, false, sessionWorkspace("fix-vat-credit-notes", false, 0), "Fix VAT on credit notes"), subAgents: { count: 1, working: false } },
436
445
  agent("agent-172b", `${REPO}#172`, "address", "idle", 250, false, sessionWorkspace("credit-note-tests", undefined, undefined), "Credit note tests"),
@@ -489,6 +498,8 @@ export function fixturePort(store: Store, dir: string): Port {
489
498
  changes: async (ledger, _data, now) => ({ ...ledger, events: quiet() ? [] : fixtureChanges(now), gotIt: fixtureGotIt(now) }),
490
499
  history: async (_config, now) => fixtureNow(now, quiet()).data,
491
500
  issueFields: async () => FIXTURE_ISSUE_FIELDS,
501
+ // Asked issues are as History found them [ATT-24].
502
+ issues: async () => (quiet() ? {} : (fixture(new Date()).data.referenced ?? {})),
492
503
  },
493
504
  // Previews have no Paseo agents, but archiving still acknowledges, so their screenshots can show the cleanup.
494
505
  paseo: { projectRepos: async () => [], archive: async () => ({ ok: true, kept: [] }) },
@@ -205,6 +205,19 @@ export interface HistoryResult {
205
205
  merged: Nodes<{ number: number; title: string; url: string; headRefName?: string; body?: string; mergedAt: string; mergedBy?: { login: string } | null; repository: Repo; closingIssuesReferences: Nodes<{ number: number; repository: Repo }> } & Labels>;
206
206
  reviewed: Nodes<{ number: number; title: string; url: string; mergedAt: string; mergedBy?: { login: string } | null; repository: Repo; author: Actor | null } & Labels>;
207
207
  closed: Nodes<{ number: number; title: string; url: string; closedAt: string; stateReason: string | null; repository: Repo; issueType?: { name: string } | null; timelineItems?: Nodes<{ actor?: { login: string } | null }> } & Labels>;
208
+ // Looked up after the search: "owner/name#number" -> an issue my merged PRs refer to, open or closed; PRs are left out
209
+ // [ATT-24]. Missing when nothing was looked up.
210
+ referenced?: Record<string, ReferencedIssue>;
211
+ }
212
+
213
+ export interface ReferencedIssue {
214
+ number: number;
215
+ title: string;
216
+ url: string;
217
+ state: string;
218
+ repository: Repo;
219
+ // Anyone's open PRs GitHub links to it.
220
+ closedByPullRequestsReferences?: Nodes<{ state: string }>;
208
221
  }
209
222
 
210
223
  export type SearchResult = LiveResult & HistoryResult;
package/server/queries.ts CHANGED
@@ -257,6 +257,20 @@ export function reopenQuery(ids: string[]): string {
257
257
  return `query Reopened {\n${fields.join("\n")}\n}`;
258
258
  }
259
259
 
260
+ // The issues my merged PRs refer to, a batch per request: whether each is still open, and the open PRs GitHub links to
261
+ // it, anyone's, as a PR still open means the work isn't done [ATT-24, GH-01]. PRs answer nothing.
262
+ export const REFERENCED_BATCH = 50;
263
+ export function referencedIssuesQuery(refs: IssueRef[]): string {
264
+ const fields = refs.map(
265
+ (ref, index) => `i${index}: ${repository(ref.repo)} {
266
+ issueOrPullRequest(number: ${ref.number}) { ... on Issue { number title url state repository { nameWithOwner }
267
+ closedByPullRequestsReferences(first: 5, includeClosedPrs: false) { nodes { state } }
268
+ } }
269
+ }`,
270
+ );
271
+ return `query Referenced {\n${fields.join("\n")}\n}`;
272
+ }
273
+
260
274
  export function prKey(node: { repository: { nameWithOwner: string }; number: number }): string {
261
275
  return `${node.repository.nameWithOwner}#${node.number}`;
262
276
  }
@@ -68,3 +68,15 @@ export function toLookUp(prs: (Node & { body?: string; closingIssuesReferences:
68
68
  for (const pr of prs) for (const ref of mentionedRefs(pr.body, pr.repository.nameWithOwner)) if (!known.has(refKey(ref))) wanted.set(refKey(ref), ref);
69
69
  return [...wanted.values()].slice(0, max);
70
70
  }
71
+
72
+ // The issues my merged PRs refer to that History doesn't know closed, at most `max`, to ask whether they're still open
73
+ // [ATT-24]. My merged PRs themselves are known to be PRs.
74
+ export function mergedToLookUp(merged: { number: number; body?: string; repository: { nameWithOwner: string }; closingIssuesReferences: { nodes: Node[] } }[], closed: Node[], max = 100): IssueRef[] {
75
+ const known = new Set([...merged, ...closed].map(nodeKey));
76
+ const wanted = new Map<string, IssueRef>();
77
+ for (const pr of merged) {
78
+ const linked = pr.closingIssuesReferences.nodes.map((node) => ({ repo: node.repository.nameWithOwner, number: node.number }));
79
+ for (const ref of [...linked, ...mentionedRefs(pr.body, pr.repository.nameWithOwner)]) if (!known.has(refKey(ref))) wanted.set(refKey(ref), ref);
80
+ }
81
+ return [...wanted.values()].slice(0, max);
82
+ }
package/server/service.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Attention, type AttentionView, type FeedId, type FeedStatus, type HistoryFilter, type Item, memberKeys, type ProjectsAccess, type Reviewer } from "../shared/attention";
1
+ import { type Attention, type AttentionView, baseItem, type CloseAsk, type FeedId, type FeedStatus, type HistoryFilter, type Item, memberKeys, type ProjectsAccess, type Reviewer } from "../shared/attention";
2
2
  import type { PluginHandlerContext } from "@getpaseo/plugin/server";
3
3
  import { AttentionConfig, type FieldRole } from "../shared/config";
4
4
  import { newIssueRepos } from "../shared/new-issue";
@@ -6,13 +6,13 @@ import type { IssueField } from "../shared/setup";
6
6
  import type { ArchiveOutcome, ArchiveTarget, KeptRow, KeptWorktree } from "../shared/archive";
7
7
  import { rememberGroups } from "../shared/wrap-up";
8
8
  import { acknowledge, ownClosed } from "./changes";
9
- import { classify, classifyHistory } from "./classify";
9
+ import { classify, classifyCloseAsks, classifyHistory } from "./classify";
10
10
  import { probeAnswer, projectsFailure, projectsWarning } from "./projects";
11
11
  import type { Port } from "./port";
12
- import { isTimeZone, type UnclaimedSearch, unclaimedSearches } from "./queries";
13
- import type { Details, LiveResult } from "./github-types";
12
+ import { historySince, isTimeZone, type UnclaimedSearch, unclaimedSearches } from "./queries";
13
+ import type { Details, LiveResult, ReferencedIssue } from "./github-types";
14
14
  import { State } from "./store";
15
- import { applyPending, buildView, doneItem, type Effect, isPending, SETTLE_MS } from "./view";
15
+ import { applyPending, buildView, doneItem, type Effect, isPending, type Pending, SETTLE_MS } from "./view";
16
16
  import { keySet, uniqueKeys } from "../shared/names";
17
17
 
18
18
  // History changes only when I finish something, so it's fetched daily, on ⟳ in its tab and after a merge.
@@ -114,6 +114,16 @@ export class AttentionService {
114
114
  return this.view();
115
115
  }
116
116
 
117
+ // Keep open: Wrap up stops asking to close the issue until another PR of mine merges under it; `on: false` is its Undo.
118
+ // Nothing changes on GitHub [ATT-24].
119
+ async keepOpen(key: string, on: boolean): Promise<AttentionView> {
120
+ const ask = this.state.history?.asks.find((candidate) => candidate.key === key);
121
+ if (on && ask) this.state.keptOpen[key] = ask.mergedAt;
122
+ if (!on) delete this.state.keptOpen[key];
123
+ await this.save();
124
+ return this.view();
125
+ }
126
+
117
127
  // Clears Changed by others notes, or brings them back for Undo; nothing changes on GitHub [HIS-07].
118
128
  async gotIt(ids: string[], on: boolean): Promise<AttentionView> {
119
129
  const gotIt = this.state.changes.gotIt.filter((other) => !ids.includes(other));
@@ -265,6 +275,13 @@ export class AttentionService {
265
275
  await this.save();
266
276
  }
267
277
 
278
+ // Not a filter, so Clear leaves it [NXT-14]. Answered with the view, so a refresh that read the old choice can't undo it.
279
+ async setUnclaimedByRepo(on: boolean): Promise<AttentionView> {
280
+ this.state.unclaimedByRepo = on;
281
+ await this.save();
282
+ return this.view();
283
+ }
284
+
268
285
  // "Not now" on an update notice holds until a newer one [UPD-01].
269
286
  get skippedUpdate(): string | null {
270
287
  return this.state.skippedUpdate;
@@ -286,11 +303,18 @@ export class AttentionService {
286
303
  async act(key: string, work: () => Promise<void>, change: Change): Promise<AttentionView> {
287
304
  await work();
288
305
  const before = this.state.pending[key];
306
+ const wasClosed = key in this.state.closedAsks;
289
307
  const at = new Date(this.port.now()).toISOString();
290
308
  if (change) this.state.pending[key] = { at, effect: change.kind === "finished" ? this.finished(key, at, change.notPlanned) : change };
291
309
  else delete this.state.pending[key];
310
+ // History's search only finds closed issues assigned to me, so one Wrap up asked to close is kept here, its merged PRs
311
+ // under it, for its week and its sessions' row; Undo forgets it [ATT-24, HIS-01].
312
+ const effect = this.state.pending[key]?.effect;
313
+ if (effect?.kind === "done" && this.state.history?.asks.some((ask) => ask.key === key)) this.state.closedAsks[key] = effect.item;
314
+ else if (!change) delete this.state.closedAsks[key];
292
315
  await this.save();
293
- const history = change?.kind === "finished" || before?.effect.kind === "done";
316
+ // Undo of a close brings back its ask once History is fetched, even after the close stopped pending [ATT-24].
317
+ const history = change?.kind === "finished" || before?.effect.kind === "done" || (!change && wasClosed);
294
318
  this.followUp("live");
295
319
  if (history) this.followUp("history");
296
320
  return this.view();
@@ -300,9 +324,17 @@ export class AttentionService {
300
324
  private finished(key: string, at: string, notPlanned?: boolean): Effect {
301
325
  const live = this.state.live?.attention;
302
326
  const source = live?.items.find((item) => item.key === key) ?? live?.assigned.find((issue) => issue.key === key);
327
+ const ask = this.state.history?.asks.find((candidate) => candidate.key === key);
328
+ // An issue Wrap up asked to close keeps my merged PRs under it, assigned to me or not [ATT-24, HIS-01].
329
+ if (ask) return { kind: "done", item: { ...doneItem(source ?? this.askItem(ask), at, notPlanned), children: notPlanned ? [] : ask.prs } };
303
330
  return source ? { kind: "done", item: doneItem(source, at, notPlanned) } : { kind: "gone" };
304
331
  }
305
332
 
333
+ // An issue Wrap up asked to close, not in the live feed's lists [ATT-24].
334
+ private askItem(ask: CloseAsk): Item {
335
+ return baseItem({ key: ask.key, section: "done", kind: "issue", repo: ask.repo, number: ask.number, title: ask.title, url: ask.url });
336
+ }
337
+
306
338
  // A PR of mine the live feed saw merged, which History doesn't list yet, perhaps merged on GitHub: History is fetched
307
339
  // once its search has caught up, once per PR [FRESH-03]. Until then the live feed's own entry stands in (ownClosed).
308
340
  private followMerges(): void {
@@ -350,7 +382,17 @@ export class AttentionService {
350
382
  this.state.groups = rememberGroups(this.state.groups, this.state.live.attention.items, now, Math.max(this.config.mentionDays, this.config.historyWeeks * 7 + 7));
351
383
  this.followMerges();
352
384
  }
353
- else this.state.history = { fetchedAt, items: await this.fetchHistory(now) };
385
+ else {
386
+ const { open, ...history } = await this.fetchHistory(now);
387
+ this.state.history = { fetchedAt, ...history };
388
+ // Keep open, and an issue closed when asked, last as long as History's weeks: an ask missing from one fetch, while
389
+ // someone's PR is open or a lookup failed, may come back. A closed one History lists itself needs no keeping [ATT-24].
390
+ const since = historySince(now, this.config.historyWeeks, this.timeZone);
391
+ for (const [key, mergedAt] of Object.entries(this.state.keptOpen)) if (mergedAt < since) delete this.state.keptOpen[key];
392
+ const listed = new Set(this.state.history.items.map((item) => item.key));
393
+ // Reopened on GitHub, it's open again: only a lookup that answered says so, so a failed one keeps it.
394
+ for (const [key, item] of Object.entries(this.state.closedAsks)) if (listed.has(key) || open.has(key) || (item.closedAt ?? "") < since) delete this.state.closedAsks[key];
395
+ }
354
396
  // Forget dismissals of items that are gone.
355
397
  const keys = new Set(this.items().map((item) => item.key));
356
398
  for (const key of Object.keys(this.state.dismissed)) if (!keys.has(key)) delete this.state.dismissed[key];
@@ -372,7 +414,23 @@ export class AttentionService {
372
414
  const { data, details } = await this.searchLive(now, unclaimed.searches);
373
415
  this.state.changes = await this.port.github.changes(this.state.changes, data, now, this.config, () => this.state.changes.gotIt);
374
416
  const own = ownClosed(data, data.viewer.login);
375
- return { ...classify({ data, details, config: this.config, now }), unclaimedFrom: unclaimed.from, ...(own.length ? { ownClosed: own } : {}) };
417
+ const askOff = await this.askOff();
418
+ return { ...classify({ data, details, config: this.config, now }), unclaimedFrom: unclaimed.from, ...(own.length ? { ownClosed: own } : {}), ...(askOff.length ? { askOff } : {}) };
419
+ }
420
+
421
+ // History is fetched daily, so the issues it asks about are looked up again with each live refresh: one closed since,
422
+ // or with anyone's PR open for it, stops asking until History says otherwise [ATT-24, GH-01]. One that can't be looked
423
+ // up keeps asking.
424
+ private async askOff(): Promise<string[]> {
425
+ const asks = this.state.history?.asks ?? [];
426
+ if (asks.length === 0) return [];
427
+ const found = await this.port.github.issues(asks.map((ask) => ({ repo: ask.repo, number: ask.number }))).catch(() => ({}) as Record<string, ReferencedIssue>);
428
+ return asks
429
+ .filter((ask) => {
430
+ const issue = Object.entries(found).find(([key]) => key.toLowerCase() === ask.key.toLowerCase())?.[1];
431
+ return issue && (issue.state !== "OPEN" || (issue.closedByPullRequestsReferences?.nodes ?? []).some((pr) => pr.state === "OPEN"));
432
+ })
433
+ .map((ask) => ask.key);
376
434
  }
377
435
 
378
436
  // The account gh is signed in as, for My repos [NXT-04]. Asked once, unless the last fetch already says.
@@ -393,8 +451,11 @@ export class AttentionService {
393
451
  return this.state.projectRepos;
394
452
  }
395
453
 
396
- private async fetchHistory(now: Date): Promise<Item[]> {
397
- return classifyHistory(await this.port.github.history(this.config, now, this.timeZone));
454
+ // History, the issues to ask about closing, and which issues my merged PRs refer to were found open [ATT-24].
455
+ private async fetchHistory(now: Date): Promise<{ items: Item[]; asks: CloseAsk[]; open: Set<string> }> {
456
+ const data = await this.port.github.history(this.config, now, this.timeZone);
457
+ const open = new Set(Object.entries(data.referenced ?? {}).flatMap(([key, issue]) => (issue.state === "OPEN" ? [key] : [])));
458
+ return { items: classifyHistory(data), asks: classifyCloseAsks(data), open };
398
459
  }
399
460
 
400
461
  // Whether the gh login may read projects, asked at most hourly, or now when Settings asks [NXT-12]. On only when GitHub
@@ -490,6 +551,22 @@ export class AttentionService {
490
551
  return newIssueRepos(this.config, this.state.projectRepos, [...shown, ...issues], attention?.login ?? null);
491
552
  }
492
553
 
554
+ // History's asks, less those kept open since their latest merge, and an issue I just closed until History shows it [ATT-24].
555
+ private closeAsks(pending: Record<string, Pending>): CloseAsk[] {
556
+ const off = (key: string) => ["done", "gone"].includes(pending[key]?.effect.kind ?? "");
557
+ return (this.state.history?.asks ?? []).filter((ask) => !off(ask.key) && !((this.state.keptOpen[ask.key] ?? "") >= ask.mergedAt));
558
+ }
559
+
560
+ // History as fetched, with the issues closed when Wrap up asked, which its search can't find, and their PRs under them
561
+ // rather than alone [ATT-24, HIS-01].
562
+ private historyItems(): Item[] {
563
+ const items = this.state.history?.items ?? [];
564
+ const listed = new Set(items.map((item) => item.key));
565
+ const closed = Object.values(this.state.closedAsks).filter((item) => !listed.has(item.key));
566
+ const under = new Set(closed.flatMap((item) => item.children.map((child) => child.key)));
567
+ return [...closed, ...items.filter((item) => !under.has(item.key))];
568
+ }
569
+
493
570
  private view(): AttentionView {
494
571
  const status = (id: FeedId): FeedStatus => ({
495
572
  fetchedAt: this.state[id]?.fetchedAt ?? null,
@@ -498,7 +575,7 @@ export class AttentionService {
498
575
  });
499
576
  const now = this.port.now();
500
577
  const pending = Object.fromEntries(Object.entries(this.state.pending).filter(([, entry]) => isPending(entry, this.fetchedAt(), now)));
501
- const shown = applyPending(this.state.live?.attention ?? null, this.state.history?.items ?? [], pending);
578
+ const shown = applyPending(this.state.live?.attention ?? null, this.historyItems(), pending);
502
579
  return buildView(
503
580
  shown.attention,
504
581
  shown.history,
@@ -508,12 +585,14 @@ export class AttentionService {
508
585
  scopes: this.state.scopes,
509
586
  sources: this.state.sources,
510
587
  projectFilter: this.state.projectFilter,
588
+ unclaimedByRepo: this.state.unclaimedByRepo,
511
589
  historyFilter: this.state.historyFilter,
512
590
  groups: Object.fromEntries(Object.entries(this.state.groups).map(([key, group]) => [key, group.keys])),
513
591
  config: this.config,
514
592
  pending: Object.keys(pending).length,
515
593
  newIssue: { repos: this.newIssueRepos(shown.attention), ...this.state.newIssue },
516
594
  kept: this.state.kept,
595
+ closeAsks: this.closeAsks(pending),
517
596
  },
518
597
  this.state.changes,
519
598
  new Date(now),
package/server/store.ts CHANGED
@@ -2,7 +2,7 @@ import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { z } from "zod";
5
- import { type Attention, type HistoryFilter, type Item, type RememberedGroups, type SectionId, SECTIONS } from "../shared/attention";
5
+ import { type Attention, type CloseAsk, type HistoryFilter, type Item, type RememberedGroups, type SectionId, SECTIONS } from "../shared/attention";
6
6
  import { AttentionConfig, FIELD_ROLES, type FieldRole } from "../shared/config";
7
7
  import type { KeptRow } from "../shared/archive";
8
8
  import type { OthersChange } from "../shared/changes";
@@ -29,6 +29,8 @@ export const State = z.object({
29
29
  sources: z.array(z.string()).default([]),
30
30
  // Project statuses ticked in Next up's filter; none means all [NXT-03].
31
31
  projectFilter: z.array(z.string()).default([]),
32
+ // Unclaimed grouped by repository rather than one list by priority [NXT-14].
33
+ unclaimedByRepo: z.boolean().default(false).catch(false),
32
34
  // Reviewed and Changed by others shown in each of History's weeks; none means finished only [HIS-07].
33
35
  historyFilter: z.array(z.enum(["reviewed", "changed"])).default([]).catch([] as HistoryFilter[]),
34
36
  // The device's IANA time zone, which History's weeks follow; the last device to send one wins. UTC until then [HIS-01].
@@ -50,6 +52,11 @@ export const State = z.object({
50
52
  // Key -> the keys of the stack or issue group it was last seen in, and when, so Wrap up still knows a merged PR's open
51
53
  // siblings after History lists it on its own [ATT-22, ATT-04].
52
54
  groups: z.record(z.string(), z.object({ keys: z.array(z.string()), at: z.string() })).default({}).catch({}) satisfies z.ZodType<RememberedGroups>,
55
+ // Issue key -> the latest merge under it when I chose Keep open; a later merge asks again [ATT-24].
56
+ keptOpen: z.record(z.string(), z.string()).default({}).catch({}),
57
+ // Issue key -> an issue closed when Wrap up asked, with my merged PRs under it, as History's search can't find one not
58
+ // assigned to me; kept for History's weeks [ATT-24].
59
+ closedAsks: z.record(z.string(), z.custom<Item>((value) => typeof (value as Item)?.key === "string" && Array.isArray((value as Item)?.children))).default({}).catch({}),
53
60
  // Wrap up rows whose sessions were archived but whose worktree stayed, until it goes or is dismissed [ATT-22].
54
61
  kept: z.array(z.custom<KeptRow>((value) => typeof (value as KeptRow)?.workspaceId === "string" && typeof (value as KeptRow)?.itemKey === "string")).default([]).catch([]),
55
62
  // The repository and agent profile the New issue sheet last started with [ISS-01].
@@ -68,7 +75,15 @@ export const State = z.object({
68
75
  })
69
76
  .nullable()
70
77
  .catch(null),
71
- history: z.object({ fetchedAt: z.string(), items: z.custom<Item[]>(knownSections) }).nullable().catch(null),
78
+ history: z
79
+ .object({
80
+ fetchedAt: z.string(),
81
+ items: z.custom<Item[]>(knownSections),
82
+ // Open issues whose PRs of mine have all merged, to ask about closing [ATT-24].
83
+ asks: z.array(z.custom<CloseAsk>((value) => typeof (value as CloseAsk)?.key === "string" && Array.isArray((value as CloseAsk)?.prs))).default([]).catch([]),
84
+ })
85
+ .nullable()
86
+ .catch(null),
72
87
  });
73
88
  export type State = z.infer<typeof State>;
74
89
 
package/server/view.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { type Attention, type AttentionView, baseItem, type Chip, type FeedId, type FeedStatus, type HistoryFilter, type Item, type NextUpIssue, type Section, SECTION_ORDER, SECTIONS, type TabId, type WaitingGroup } from "../shared/attention";
1
+ import { type Attention, type AttentionView, baseItem, type Chip, type CloseAsk, type FeedId, type FeedStatus, type HistoryFilter, type Item, type NextUpIssue, type Section, SECTION_ORDER, SECTIONS, type TabId, type WaitingGroup } from "../shared/attention";
2
2
  import type { AttentionConfig } from "../shared/config";
3
3
  import type { KeptRow } from "../shared/archive";
4
4
  import type { NewIssueInfo } from "../shared/new-issue";
5
+ import { keySet } from "../shared/names";
5
6
  import { workChip, workKind } from "../shared/work";
6
7
  import { type ChangeLedger, changeItems, EMPTY_LEDGER, handedKeys } from "./changes";
7
8
  import { historySince } from "./queries";
@@ -12,12 +13,15 @@ export interface ViewMeta {
12
13
  scopes: string[];
13
14
  sources: string[];
14
15
  projectFilter: string[];
16
+ unclaimedByRepo: boolean;
15
17
  historyFilter: HistoryFilter[];
16
18
  groups?: Record<string, string[]>;
17
19
  config: AttentionConfig;
18
20
  pending: number;
19
21
  newIssue: NewIssueInfo;
20
22
  kept?: KeptRow[];
23
+ // History's asks, less those kept open or just closed [ATT-24].
24
+ closeAsks?: CloseAsk[];
21
25
  }
22
26
 
23
27
  // What a tap on GitHub changed, shown until a fetch can show it for itself [FRESH-02].
@@ -150,6 +154,21 @@ export function buildView(attention: Attention | null, fetched: Item[], dismisse
150
154
  .map((id) => ({ id, title: SECTIONS[id].title, items: shown.filter((item) => item.section === id) }))
151
155
  .filter((section) => section.items.length > 0);
152
156
  const doing = sections("doing");
157
+ const activeKeys = (attention?.items ?? []).flatMap((item) => [item.key, ...item.children.map((child) => child.key)]);
158
+ // Not done while a PR is open for it: one of mine grouped under it in the live feed (a mention on the issue alone doesn't
159
+ // count), anyone's Next up knows of, or what the live refresh found when it looked again; and not once it closed since.
160
+ // Only what merged within History's weeks counts, as History shows it, until it's fetched again [ATT-24, HIS-01].
161
+ const off = keySet([
162
+ ...(attention?.items ?? []).filter((item) => item.kind === "issue" && item.children.length > 0).map((item) => item.key),
163
+ ...[...(attention?.assigned ?? []), ...(attention?.unclaimed ?? [])].filter((issue) => issue.openPrs.length > 0).map((issue) => issue.key),
164
+ ...(attention?.askOff ?? []),
165
+ ]);
166
+ const closeAsks = (meta.closeAsks ?? [])
167
+ .filter((ask) => !off.has(ask.key.toLowerCase()) && Date.parse(ask.mergedAt) >= Date.parse(since))
168
+ .map((ask) => ({ ...ask, prs: ask.prs.filter((pr) => Date.parse(pr.mergedAt ?? ask.mergedAt) >= Date.parse(since)) }));
169
+ // Next up keeps an issue it asks about, saying its PRs merged [ATT-24].
170
+ const asked = keySet(closeAsks.map((ask) => ask.key));
171
+ const marked = (issues: NextUpIssue[]) => issues.map((issue) => (asked.has(issue.key.toLowerCase()) ? { ...issue, prsMerged: true as const } : issue));
153
172
  return {
154
173
  ...meta,
155
174
  login: attention?.login ?? null,
@@ -160,9 +179,10 @@ export function buildView(attention: Attention | null, fetched: Item[], dismisse
160
179
  history: shown.filter((item) => SECTIONS[item.section].tab === "history"),
161
180
  // Dismissed or not, these are still open; Wrap up must not call their sessions finished [ATT-22].
162
181
  ownClosed: attention?.ownClosed ?? [],
163
- activeKeys: (attention?.items ?? []).flatMap((item) => [item.key, ...item.children.map((child) => child.key)]),
164
- assigned: attention?.assigned ?? [],
165
- unclaimed: attention?.unclaimed ?? [],
182
+ activeKeys,
183
+ closeAsks,
184
+ assigned: marked(attention?.assigned ?? []),
185
+ unclaimed: marked(attention?.unclaimed ?? []),
166
186
  unclaimedFrom: attention?.unclaimedFrom ?? "config",
167
187
  projects: attention?.projects ?? [],
168
188
  dismissedCount: items.filter((item) => isDismissed(item, dismissed)).length,
@@ -272,7 +272,20 @@ export function baseItem({ key, section, kind, repo, number, title, url }: Pick<
272
272
  return { key, section, kind, draft: false, repo, number, title, url, chips: [], actions: [], children: [], target: { kind, repo, number, title, url }, othersActivityAt };
273
273
  }
274
274
 
275
- // A Wrap up row's sessions: all idle, or it wouldn't be there [ATT-22].
275
+ // An open issue whose PRs of mine, grouped under it, have all merged, with none open for it: Wrap up asks "Close #12?" [ATT-24].
276
+ export interface CloseAsk {
277
+ key: string;
278
+ repo: string;
279
+ number: number;
280
+ title: string;
281
+ url: string;
282
+ // My merged PRs under it, oldest merge first, each with its mergedAt.
283
+ prs: SubRow[];
284
+ // The latest of their merges: Keep open lasts until a later one.
285
+ mergedAt: string;
286
+ }
287
+
288
+ // A Wrap up row's sessions: all idle, or it wouldn't be there [ATT-22, ATT-24].
276
289
  export interface WrapInfo {
277
290
  sessions: AgentSummary[];
278
291
  // The finished item's own key; the row's is prefixed with "wrap:" so it never collides with it.
@@ -283,9 +296,12 @@ export interface WrapInfo {
283
296
  finish: string;
284
297
  // A session on someone else's PR that merged: its card says "review session" in words.
285
298
  review?: true;
299
+ // An open issue whose PRs of mine all merged: the row asks "Close #12?", and has sessions only when one is open on that
300
+ // work. Closing leaves its sessions to the usual row [ATT-24].
301
+ ask?: true;
286
302
  }
287
303
 
288
- // A Wrap up row: always with its sessions and keys [ATT-22].
304
+ // A Wrap up row: with its sessions and keys; one asking to close an issue may have no session [ATT-22, ATT-24].
289
305
  export type WrapItem = Item & { section: "wrap"; wrap: WrapInfo };
290
306
 
291
307
  // The GitHub work an item stands for: itself, the PRs under it, and the work a change note is about, spelled as GitHub
@@ -354,6 +370,8 @@ export interface NextUpIssue {
354
370
  projects?: IssueProject[];
355
371
  // Open PRs that close it: someone may already be on it [NXT-10].
356
372
  openPrs: { number: number; url: string; author: string | null }[];
373
+ // My PRs under it have all merged and Wrap up asks whether to close it [ATT-24].
374
+ prsMerged?: true;
357
375
  }
358
376
 
359
377
  // More about an item, fetched when its sheet opens rather than in every refresh [GH-01].
@@ -389,6 +407,8 @@ export interface Attention {
389
407
  // My PRs that ended lately, closed by me unmerged or merged: finished work for Wrap up, never shown in History; a merged
390
408
  // one stands in until History has it [ATT-22, FRESH-03].
391
409
  ownClosed?: Item[];
410
+ // Issues Wrap up asks to close that the live refresh found closed since, or with a PR open for them [ATT-24].
411
+ askOff?: string[];
392
412
  }
393
413
 
394
414
  export interface Section {
@@ -505,6 +525,8 @@ export interface AttentionView {
505
525
  ownClosed?: Item[];
506
526
  // Key -> the keys of the stack or issue group it was last seen open in, lower case [ATT-22, ATT-04].
507
527
  groups?: Record<string, string[]>;
528
+ // Open issues whose PRs of mine have all merged, not kept open since: Wrap up asks "Close #12?" [ATT-24].
529
+ closeAsks?: CloseAsk[];
508
530
  assigned: NextUpIssue[];
509
531
  unclaimed: NextUpIssue[];
510
532
  unclaimedFrom: UnclaimedSource;
@@ -517,6 +539,8 @@ export interface AttentionView {
517
539
  sources: string[];
518
540
  // Project statuses ticked in Next up's filter, as projectFilterId makes them; none means all [NXT-03].
519
541
  projectFilter: string[];
542
+ // Unclaimed grouped by repository rather than one list by priority [NXT-14].
543
+ unclaimedByRepo: boolean;
520
544
  // Reviewed and Changed by others shown in each of History's weeks; none means finished only [HIS-07].
521
545
  historyFilter: HistoryFilter[];
522
546
  config: AttentionConfig;
@@ -135,3 +135,22 @@ function projectTree(unclaimed: NextUpIssue[], projects: ProjectInfo[]): Project
135
135
  const noProject = projectFilterId(null);
136
136
  return loose ? [...nodes, { id: noProject, title: "No project", children: [{ id: noProject, label: "No project" }] }] : nodes;
137
137
  }
138
+
139
+ // Unclaimed by repo [NXT-14]: a group per repository, led by the one with the top issue, each keeping NXT-02's order. Null
140
+ // with fewer than two repositories shown, so there's nothing to group and no switch to offer. Repositories match whatever
141
+ // their case, so one never splits in two.
142
+ export interface RepoGroup {
143
+ repo: string;
144
+ issues: NextUpIssue[];
145
+ }
146
+
147
+ export function repoGroups(shown: NextUpIssue[]): RepoGroup[] | null {
148
+ const groups = new Map<string, RepoGroup>();
149
+ for (const issue of shown) {
150
+ const id = issue.repo.toLowerCase();
151
+ const group = groups.get(id);
152
+ if (group) group.issues.push(issue);
153
+ else groups.set(id, { repo: issue.repo, issues: [issue] });
154
+ }
155
+ return groups.size > 1 ? [...groups.values()] : null;
156
+ }
package/shared/rpc.ts CHANGED
@@ -26,6 +26,8 @@ export const getAttention = defineRpc({
26
26
  export const dismissItem = defineRpc({ name: "attention.dismiss", input: z.object({ key: z.string() }), output: view });
27
27
  // Undo one dismissal [ATT-08].
28
28
  export const undismissItem = defineRpc({ name: "attention.undismiss", input: z.object({ key: z.string() }), output: view });
29
+ // Keep open: Wrap up stops asking "Close #12?" until another PR merges under it; `on: false` is its Undo [ATT-24].
30
+ export const keepOpen = defineRpc({ name: "issue.keep-open", input: z.object({ key: z.string(), on: z.boolean() }), output: view });
29
31
  // Clears Changed by others notes, one or all of them; `on: false` brings them back for Undo. Nothing changes on GitHub [HIS-07].
30
32
  export const gotIt = defineRpc({ name: "attention.got-it", input: z.object({ ids: z.array(z.string()), on: z.boolean() }), output: view });
31
33
  // Reviewed and Changed by others in History's weeks; remembered in state.json [HIS-07].
@@ -72,6 +74,8 @@ export const setScopes = defineRpc({ name: "next-up.scopes", input: z.object({ s
72
74
  export const setSources = defineRpc({ name: "next-up.sources", input: z.object({ sources: z.array(z.string()) }), output: done });
73
75
  // And the project statuses [NXT-03].
74
76
  export const setProjectFilter = defineRpc({ name: "next-up.projects", input: z.object({ projects: z.array(z.string()) }), output: done });
77
+ // Unclaimed grouped by repository, or not [NXT-14].
78
+ export const setUnclaimedByRepo = defineRpc({ name: "next-up.by-repo", input: z.object({ on: z.boolean() }), output: view });
75
79
  // Whether the gh login may read projects, asked again now, for Settings [NXT-12].
76
80
  export const projectsAccess = defineRpc({ name: "config.projects-access", input: z.object({}), output: z.custom<ProjectsAccess>() });
77
81