@andrioid/paseo-attention-span 0.4.12 → 0.4.14

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.
package/server/view.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { type Attention, type AttentionView, type Chip, type FeedId, type FeedStatus, 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 { workChip, workKind } from "../shared/work";
4
+ import { type ChangeLedger, changeItems, EMPTY_LEDGER, handedKeys } from "./changes";
5
+ import { historySince } from "./queries";
4
6
  import type { State } from "./store";
5
7
 
6
8
  export interface ViewMeta {
@@ -126,25 +128,33 @@ export function waitingGroups(items: Item[]): WaitingGroup[] {
126
128
  // Waiting's work: its own sections, and my PRs in Doing while they wait on someone I asked [WAI-01, PRS-15].
127
129
  const inWaiting = (item: Item) => SECTIONS[item.section].tab === "waiting" || (SECTIONS[item.section].tab === "doing" && !!item.wait && !!item.waitingOn?.length);
128
130
 
129
- export function buildView(attention: Attention | null, history: Item[], dismissed: State["dismissed"], meta: ViewMeta): AttentionView {
131
+ export function buildView(attention: Attention | null, history: Item[], dismissed: State["dismissed"], meta: ViewMeta, ledger: ChangeLedger = EMPTY_LEDGER, now = new Date()): AttentionView {
130
132
  const items = [...(attention?.items ?? []), ...history];
131
- const visible = items.filter((item) => !isDismissed(item, dismissed));
133
+ // A PR that left my hands isn't my finished work, even once its new owner merges it [HIS-06].
134
+ const handed = handedKeys(ledger);
135
+ const visible = items
136
+ .filter((item) => !isDismissed(item, dismissed) && !(item.section === "done" && handed.has(item.key)))
137
+ .map((item) => (item.section === "done" && item.children.some((child) => handed.has(child.key)) ? { ...item, children: item.children.filter((child) => !handed.has(child.key)) } : item));
138
+ // Notes on what others did, and work that left my hands; never dismissed, only cleared with Got it [ATT-21, HIS-06].
139
+ const changes = changeItems(ledger, now, meta.config.mentionDays, historySince(now, meta.config.historyWeeks));
140
+ const shown = [...visible, ...changes.doing, ...changes.history];
132
141
  const sections = (tab: TabId): Section[] =>
133
142
  SECTION_ORDER.filter((id) => SECTIONS[id].tab === tab)
134
- .map((id) => ({ id, title: SECTIONS[id].title, items: visible.filter((item) => item.section === id) }))
143
+ .map((id) => ({ id, title: SECTIONS[id].title, items: shown.filter((item) => item.section === id) }))
135
144
  .filter((section) => section.items.length > 0);
136
145
  const doing = sections("doing");
137
146
  return {
138
147
  ...meta,
139
148
  login: attention?.login ?? null,
140
- count: doing.reduce((sum, section) => sum + section.items.length, 0),
149
+ // What needs me; notes on others' doings don't [ATT-09, ATT-21].
150
+ count: doing.reduce((sum, section) => sum + (section.id === "changed" ? 0 : section.items.length), 0),
141
151
  doing,
142
152
  waiting: waitingGroups(visible.filter(inWaiting)),
143
- history: visible.filter((item) => SECTIONS[item.section].tab === "history"),
153
+ history: shown.filter((item) => SECTIONS[item.section].tab === "history"),
144
154
  assigned: attention?.assigned ?? [],
145
155
  unclaimed: attention?.unclaimed ?? [],
146
156
  unclaimedFrom: attention?.unclaimedFrom ?? "config",
147
157
  projects: attention?.projects ?? [],
148
- dismissedCount: items.length - visible.length,
158
+ dismissedCount: items.filter((item) => isDismissed(item, dismissed)).length,
149
159
  };
150
160
  }
@@ -1,3 +1,4 @@
1
+ import type { OthersChange } from "./changes";
1
2
  import type { AttentionConfig, MergeMethod, SessionKind } from "./config";
2
3
  import type { WorkKind } from "./work";
3
4
 
@@ -22,6 +23,8 @@ export const SECTIONS = {
22
23
  // Nobody has the next move until I ask someone [PRS-12].
23
24
  needs_reviewer: { tab: "doing", title: "Needs a reviewer" },
24
25
  drafts: { tab: "doing", title: "My drafts" },
26
+ // What someone else did to my work: a note until Got it, never counted as needing me [ATT-21].
27
+ changed: { tab: "doing", title: "Changed by others" },
25
28
  // Waiting groups these by who they wait on, not by section [WAI-01].
26
29
  wait_review: { tab: "waiting", title: "Waiting for review" },
27
30
  wait_reviewer: { tab: "waiting", title: "Waiting for the reviewer" },
@@ -30,6 +33,8 @@ export const SECTIONS = {
30
33
  // [HIS-01, HIS-02]
31
34
  done: { tab: "history", title: "Done" },
32
35
  reviewed: { tab: "history", title: "Reviewed" },
36
+ // My PRs closed unmerged by others, and work taken out of my hands, out of the week's copy [HIS-06].
37
+ handed_off: { tab: "history", title: "Closed or handed off" },
33
38
  } as const satisfies Record<string, { tab: TabId; title: string }>;
34
39
  export type SectionId = keyof typeof SECTIONS;
35
40
  export const SECTION_ORDER = Object.keys(SECTIONS) as SectionId[];
@@ -50,7 +55,9 @@ export type ActionId =
50
55
  | "automerge"
51
56
  | "merge"
52
57
  | "close"
53
- | "start";
58
+ | "start"
59
+ // Clears a Changed by others note; nothing changes on GitHub [ATT-21].
60
+ | "got_it";
54
61
 
55
62
  // A short state label on a row [ATT-05]; tone picks its color.
56
63
  export interface Chip {
@@ -190,6 +197,8 @@ export interface SubRow {
190
197
  chips: Chip[];
191
198
  // Behind its parent, conflicting or failing CI: shown even when the stack is collapsed.
192
199
  attention: boolean;
200
+ // History only: who merged it, when it wasn't me [HIS-05].
201
+ mergedBy?: string;
193
202
  }
194
203
 
195
204
  export interface Item {
@@ -218,6 +227,10 @@ export interface Item {
218
227
  work?: WorkKind;
219
228
  // History only: an issue closed as not planned, kept out of the copied week [HIS-03].
220
229
  notPlanned?: true;
230
+ // History only: who merged my PR, when it wasn't me [HIS-05].
231
+ mergedBy?: string;
232
+ // Changed by others and Closed or handed off: what someone else did [ATT-21, HIS-06].
233
+ change?: OthersChange;
221
234
  }
222
235
 
223
236
  // The colors GitHub lets an org give issue field options and a project its Status options. GRAY is what nothing chosen looks
@@ -371,7 +384,7 @@ export interface FeedStatus {
371
384
  export interface AttentionView {
372
385
  feeds: Record<FeedId, FeedStatus>;
373
386
  login: string | null;
374
- // Items in Doing; the sidebar shows it [ATT-09].
387
+ // Items in Doing that need me; the sidebar shows it. Changed by others notes don't count [ATT-09, ATT-21].
375
388
  count: number;
376
389
  doing: Section[];
377
390
  waiting: WaitingGroup[];
@@ -0,0 +1,51 @@
1
+ import { ago } from "./format";
2
+
3
+ // What someone else did to my work without asking me: merged or closed my PR, took it over or handed it on, or unassigned me
4
+ // from an issue [ATT-21]. Issue closes, others' pushes and my own doings aren't here.
5
+ // merged someone else merged my PR
6
+ // closed someone else closed my PR without merging it
7
+ // took_over someone assigned themselves my PR or issue, and I'm off it
8
+ // handed someone assigned my PR or issue to a third person, and I'm off it
9
+ // unassigned someone took me off an issue and nobody has it now
10
+ export type OthersChangeKind = "merged" | "closed" | "took_over" | "handed" | "unassigned";
11
+
12
+ export interface OthersChange {
13
+ // Stable across refreshes, so Got it sticks to this event and no other on the same item.
14
+ id: string;
15
+ kind: OthersChangeKind;
16
+ // The PR's or issue's node id, which survives a transfer; key is "owner/name#number" as last seen.
17
+ subjectId: string;
18
+ subject: "pr" | "issue";
19
+ key: string;
20
+ repo: string;
21
+ number: number;
22
+ title: string;
23
+ url: string;
24
+ // Who did it; missing when GitHub doesn't say (a deleted account).
25
+ actor?: string;
26
+ // The new assignee, for took_over and handed.
27
+ to?: string;
28
+ at: string;
29
+ }
30
+
31
+ // Handovers take the work out of my hands; merges and closes end it.
32
+ export const HANDOVER_KINDS: readonly OthersChangeKind[] = ["took_over", "handed", "unassigned"];
33
+ export const isHandover = (change: Pick<OthersChange, "kind">) => HANDOVER_KINDS.includes(change.kind);
34
+
35
+ // The words on the card, so the tile's color is never the only way to tell [ATT-21]: "merged by dave 2h ago".
36
+ export function changeText(change: Pick<OthersChange, "kind" | "actor" | "to" | "at">, now = new Date()): string {
37
+ const age = `${ago(change.at, now)} ago`;
38
+ const { actor, to } = change;
39
+ switch (change.kind) {
40
+ case "merged":
41
+ return actor ? `merged by ${actor} ${age}` : `merged ${age}`;
42
+ case "closed":
43
+ return actor ? `closed by ${actor} ${age}, not merged` : `closed ${age}, not merged`;
44
+ case "took_over":
45
+ return actor ? `${actor} took over ${age}` : `taken over ${age}`;
46
+ case "handed":
47
+ return actor ? `${actor} handed it to ${to} ${age}` : `handed to ${to} ${age}`;
48
+ case "unassigned":
49
+ return actor ? `${actor} unassigned you ${age}` : `unassigned you ${age}`;
50
+ }
51
+ }
package/shared/rpc.ts CHANGED
@@ -17,6 +17,8 @@ export const getAttention = defineRpc({ name: "attention.get", input: z.object({
17
17
  export const dismissItem = defineRpc({ name: "attention.dismiss", input: z.object({ key: z.string() }), output: view });
18
18
  // Undo one dismissal [ATT-08].
19
19
  export const undismissItem = defineRpc({ name: "attention.undismiss", input: z.object({ key: z.string() }), output: view });
20
+ // Clears a Changed by others note; `on: false` brings it back for Undo. Nothing changes on GitHub [ATT-21].
21
+ export const gotIt = defineRpc({ name: "attention.got-it", input: z.object({ id: z.string(), on: z.boolean() }), output: view });
20
22
  export const restoreDismissed = defineRpc({ name: "attention.restore-dismissed", input: z.object({}), output: view });
21
23
  // Adds one entry to codeRepos in config.json [SES-07].
22
24
  export const setCodeRepo = defineRpc({ name: "config.set-code-repo", input: z.object({ issueRepo: z.string(), codeRepo: z.string() }), output: view });