@andrioid/paseo-attention-span 0.4.13 → 0.5.0
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/OVERVIEW.md +10 -4
- package/README.md +2 -2
- package/client/attention-screen.tsx +142 -123
- package/client/card.tsx +4 -2
- package/client/history.tsx +184 -0
- package/client/icons.ts +7 -0
- package/client/mark.ts +19 -0
- package/client/sessions.ts +50 -3
- package/client/ui.tsx +18 -3
- package/client/wrap-up.tsx +197 -0
- package/docs/architecture.md +19 -7
- package/docs/screenshots/desktop-dark-doing-acknowledge.png +0 -0
- package/docs/screenshots/desktop-dark-doing-clear.png +0 -0
- package/docs/screenshots/desktop-dark-doing-issue-sheet.png +0 -0
- package/docs/screenshots/desktop-dark-doing-reviewers.png +0 -0
- package/docs/screenshots/desktop-dark-doing-sheet.png +0 -0
- package/docs/screenshots/desktop-dark-doing-wrap-dirty.png +0 -0
- package/docs/screenshots/desktop-dark-doing-wrap-multi.png +0 -0
- package/docs/screenshots/desktop-dark-doing-wrap.png +0 -0
- package/docs/screenshots/desktop-dark-doing.png +0 -0
- package/docs/screenshots/desktop-dark-history-filtered.png +0 -0
- package/docs/screenshots/desktop-dark-history-groups.png +0 -0
- package/docs/screenshots/desktop-dark-history.png +0 -0
- package/docs/screenshots/desktop-dark-next-up.png +0 -0
- package/docs/screenshots/desktop-dark-settings.png +0 -0
- package/docs/screenshots/desktop-dark-setup.png +0 -0
- package/docs/screenshots/desktop-dark-waiting.png +0 -0
- package/docs/screenshots/phone-dark-doing.png +0 -0
- package/docs/screenshots/phone-dark-history.png +0 -0
- package/docs/screenshots/phone-light-next-up-filtered.png +0 -0
- package/index.client.tsx +6 -1
- package/index.server.ts +21 -1
- package/package.json +8 -3
- package/requirements.yaml +11 -7
- package/server/archive.ts +132 -0
- package/server/archived.ts +120 -0
- package/server/changes.ts +355 -0
- package/server/classify.ts +15 -4
- package/server/fixture.ts +85 -8
- package/server/gh.ts +16 -4
- package/server/github-types.ts +67 -3
- package/server/queries.ts +62 -8
- package/server/service.ts +131 -11
- package/server/store.ts +20 -1
- package/server/view.ts +25 -6
- package/shared/archive.ts +37 -0
- package/shared/attention.ts +93 -3
- package/shared/changes.ts +66 -0
- package/shared/got-it.ts +23 -0
- package/shared/history-report.ts +61 -0
- package/shared/rpc.ts +23 -2
- package/shared/still.ts +4 -3
- package/shared/wrap-up.ts +126 -0
- package/docs/screenshots/desktop-dark-history-reviewed.png +0 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { isFinishedChange, isHandover, type OthersChange } from "../shared/changes";
|
|
2
|
+
import type { Item } from "../shared/attention";
|
|
3
|
+
import type { AssignmentEvent, AssignmentSubject, ClosedIssue, EndedPullRequest, LiveResult, ReopenSubject } from "./github-types";
|
|
4
|
+
import { prKey } from "./queries";
|
|
5
|
+
|
|
6
|
+
// Changed by others: what someone else did to my work, kept between refreshes so a note stays until Got it or an archive
|
|
7
|
+
// acknowledges it, and so History can list work that left my hands [HIS-06, HIS-07, ATT-22]. Pure, so every rule is
|
|
8
|
+
// testable; service.ts does the fetching.
|
|
9
|
+
|
|
10
|
+
// A PR of mine closed and waiting to be seen reopened [HIS-07].
|
|
11
|
+
export interface TrackedPr {
|
|
12
|
+
key: string;
|
|
13
|
+
number: number;
|
|
14
|
+
title: string;
|
|
15
|
+
url: string;
|
|
16
|
+
repo: string;
|
|
17
|
+
closedAt: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ChangeLedger {
|
|
21
|
+
events: OthersChange[];
|
|
22
|
+
// Events I've tapped Got it on, or an archive acknowledged.
|
|
23
|
+
gotIt: string[];
|
|
24
|
+
// Issue node id -> key, from the last assigned search that worked. Null until the first, so nothing counts as gone then:
|
|
25
|
+
// only issues seen assigned to me can be noticed leaving.
|
|
26
|
+
assigned: Record<string, string> | null;
|
|
27
|
+
// PR node id -> its assignees when last looked up, so each change of hands costs one lookup [GH-01].
|
|
28
|
+
handed: Record<string, string>;
|
|
29
|
+
// PR node id -> what Attention Span saw closed, so a reopen by someone else is noticed [HIS-07].
|
|
30
|
+
tracked: Record<string, TrackedPr>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const EMPTY_LEDGER: ChangeLedger = { events: [], gotIt: [], assigned: null, handed: {}, tracked: {} };
|
|
34
|
+
|
|
35
|
+
type Data = Pick<LiveResult, "mine" | "assigned" | "ended"> & Partial<Pick<LiveResult, "closedIssues">>;
|
|
36
|
+
// A lookup's answer per node id: the subject, null when it's gone or hidden, missing when the lookup failed.
|
|
37
|
+
export type Lookups = Map<string, AssignmentSubject | null>;
|
|
38
|
+
// Reopen lookups: the PR as it is now, null when it's gone or hidden, missing when the lookup failed.
|
|
39
|
+
export type ReopenLookups = Map<string, ReopenSubject | null>;
|
|
40
|
+
|
|
41
|
+
const same = (a: string | null | undefined, b: string | null | undefined) => !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
42
|
+
const present = <T>(nodes: (T | null | undefined)[]) => nodes.filter((node): node is T => !!node && Object.keys(node).length > 0);
|
|
43
|
+
const logins = (subject: { assignees: { nodes: { login: string }[] } }) => subject.assignees.nodes.map((node) => node.login);
|
|
44
|
+
// Assigned to someone, and not to me: out of my hands [PRS-08]. A PR of mine with nobody assigned is still mine.
|
|
45
|
+
const handedOver = (subject: { assignees: { nodes: { login: string }[] } }, me: string) => {
|
|
46
|
+
const assignees = logins(subject);
|
|
47
|
+
return assignees.length > 0 && !assignees.some((login) => same(login, me));
|
|
48
|
+
};
|
|
49
|
+
const signature = (subject: { assignees: { nodes: { login: string }[] } }) =>
|
|
50
|
+
logins(subject)
|
|
51
|
+
.map((login) => login.toLowerCase())
|
|
52
|
+
.sort()
|
|
53
|
+
.join(",");
|
|
54
|
+
|
|
55
|
+
// My PRs, open or closed lately, that someone else has: each looked up once per change of hands.
|
|
56
|
+
function handedPrs(data: Data, me: string): { id: string; signature: string }[] {
|
|
57
|
+
const prs = [...present(data.mine.nodes), ...present(data.ended.nodes)].filter((pr) => pr.id && handedOver(pr, me));
|
|
58
|
+
return [...new Map(prs.map((pr) => [pr.id, { id: pr.id, signature: signature(pr) }])).values()];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const assignedNow = (data: Data): Record<string, string> =>
|
|
62
|
+
Object.fromEntries(present(data.assigned.nodes).flatMap((issue) => (issue.id ? [[issue.id, prKey(issue)]] : [])));
|
|
63
|
+
|
|
64
|
+
// What to look up: PRs whose hands changed since last looked, and issues no longer in my assigned search. An issue can leave
|
|
65
|
+
// the search for many reasons (search lag, a coverage change, its 50 results), so each is checked before anything is said.
|
|
66
|
+
export function changeCandidates(ledger: ChangeLedger, data: Data, me: string): string[] {
|
|
67
|
+
const prs = handedPrs(data, me)
|
|
68
|
+
.filter((pr) => ledger.handed[pr.id] !== pr.signature)
|
|
69
|
+
.map((pr) => pr.id);
|
|
70
|
+
const now = assignedNow(data);
|
|
71
|
+
const gone = ledger.assigned ? Object.keys(ledger.assigned).filter((id) => !(id in now)) : [];
|
|
72
|
+
return [...new Set([...prs, ...gone])];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Tracked PRs worth asking about: ones Attention Span saw closed that the closed search no longer shows, as a reopen takes
|
|
76
|
+
// them out of it [HIS-07, GH-01]. One still listed is still closed, so it costs nothing; past the search's 50 results it's
|
|
77
|
+
// asked about too.
|
|
78
|
+
export function reopenCandidates(ledger: ChangeLedger, data?: Pick<LiveResult, "ended">): string[] {
|
|
79
|
+
const listed = new Set(present(data?.ended.nodes ?? []).flatMap((pr) => (pr.id ? [pr.id] : [])));
|
|
80
|
+
return Object.keys(ledger.tracked).filter((id) => !listed.has(id));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const isAssignment = (node: AssignmentEvent | Record<string, never>): node is AssignmentEvent => "__typename" in node && "createdAt" in node;
|
|
84
|
+
|
|
85
|
+
// Who took it out of my hands, from GitHub's assign and unassign events [HIS-07]. Null when it's still mine, it was my own
|
|
86
|
+
// doing, or the events don't show it. An issue closed by now stays silent: its close has its own note and this one would
|
|
87
|
+
// say the same thing twice.
|
|
88
|
+
// The new owner is the latest of the current assignees to be assigned. It left my hands with whichever came last of my
|
|
89
|
+
// removal and the new owner's assignment, and whoever did that is named: "phil took over" when that's the new owner, else
|
|
90
|
+
// "dave handed it to carol". So a PR I unassigned myself from is still mine until someone else takes it.
|
|
91
|
+
export function handover(subject: AssignmentSubject, me: string): OthersChange | null {
|
|
92
|
+
const assignees = logins(subject);
|
|
93
|
+
if (assignees.some((login) => same(login, me))) return null;
|
|
94
|
+
if (subject.__typename === "Issue" && subject.state !== "OPEN") return null;
|
|
95
|
+
const events = present(subject.timelineItems.nodes)
|
|
96
|
+
.filter(isAssignment)
|
|
97
|
+
.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
98
|
+
const removal = events.findLast((event) => event.__typename === "UnassignedEvent" && same(event.assignee?.login, me));
|
|
99
|
+
const given = events.findLast((event) => event.__typename === "AssignedEvent" && assignees.some((login) => same(login, event.assignee?.login)));
|
|
100
|
+
const to = given?.assignee?.login ?? assignees[0];
|
|
101
|
+
// A PR of mine with nobody on it is mine; an issue needs proof I was taken off it.
|
|
102
|
+
if (subject.__typename === "PullRequest" ? !to : !removal) return null;
|
|
103
|
+
const by = removal && given && to ? (given.createdAt > removal.createdAt ? given : removal) : (removal ?? given);
|
|
104
|
+
if (!by || same(by.actor?.login, me)) return null;
|
|
105
|
+
const actor = by.actor?.login;
|
|
106
|
+
const kind = !to ? "unassigned" : same(actor, to) ? "took_over" : "handed";
|
|
107
|
+
return change(subject, subject.__typename === "PullRequest" ? "pr" : "issue", kind, by.createdAt, actor, to);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A PR of mine someone else merged or closed unmerged [HIS-07]. Whether it left my hands before it ended is up to nextLedger,
|
|
111
|
+
// which knows when that happened.
|
|
112
|
+
export function ended(pr: EndedPullRequest, me: string): OthersChange | null {
|
|
113
|
+
if (pr.merged) return same(pr.mergedBy?.login, me) || !pr.mergedAt ? null : change(pr, "pr", "merged", pr.mergedAt, pr.mergedBy?.login);
|
|
114
|
+
const closer = pr.timelineItems.nodes.at(-1)?.actor?.login;
|
|
115
|
+
return same(closer, me) ? null : change(pr, "pr", "closed", pr.closedAt, closer);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// My PRs I closed without merging, from the closed search: finished work whose sessions Wrap up puts away, though no note
|
|
119
|
+
// and no week lists them [ATT-22].
|
|
120
|
+
export function ownClosed(data: Pick<LiveResult, "ended">, me: string): Item[] {
|
|
121
|
+
return present(data.ended.nodes)
|
|
122
|
+
.filter((pr) => !pr.merged && same(pr.timelineItems.nodes.at(-1)?.actor?.login, me))
|
|
123
|
+
.map((pr) => ({
|
|
124
|
+
key: prKey(pr),
|
|
125
|
+
kind: "pr" as const,
|
|
126
|
+
section: "done" as const,
|
|
127
|
+
draft: false,
|
|
128
|
+
repo: pr.repository.nameWithOwner,
|
|
129
|
+
number: pr.number,
|
|
130
|
+
title: pr.title,
|
|
131
|
+
url: pr.url,
|
|
132
|
+
chips: [],
|
|
133
|
+
actions: [],
|
|
134
|
+
children: [],
|
|
135
|
+
target: { kind: "pr" as const, repo: pr.repository.nameWithOwner, number: pr.number, title: pr.title, url: pr.url },
|
|
136
|
+
othersActivityAt: pr.closedAt,
|
|
137
|
+
closedAt: pr.closedAt,
|
|
138
|
+
closedUnmerged: true as const,
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// An issue assigned to me someone else closed, as completed or not planned [HIS-07]. My own closes are mine.
|
|
143
|
+
export function closedByOther(issue: ClosedIssue, me: string): OthersChange | null {
|
|
144
|
+
const closer = issue.timelineItems.nodes.at(-1)?.actor?.login;
|
|
145
|
+
if (same(closer, me)) return null;
|
|
146
|
+
const reason = issue.stateReason === "NOT_PLANNED" ? "not_planned" : issue.stateReason === "COMPLETED" ? "completed" : undefined;
|
|
147
|
+
return { ...change(issue, "issue", "issue_closed", issue.closedAt, closer), ...(reason ? { reason } : {}) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// A PR Attention Span saw closed, now open again by someone else [HIS-07]. Only PRs already tracked count, so a first run
|
|
151
|
+
// doesn't announce every old reopen, and issues don't come here: they surface in Next up.
|
|
152
|
+
export function reopened(tracked: TrackedPr, subject: ReopenSubject, me: string): OthersChange | null {
|
|
153
|
+
if (subject.state !== "OPEN") return null;
|
|
154
|
+
const event = subject.timelineItems.nodes.at(-1);
|
|
155
|
+
const actor = event?.actor?.login;
|
|
156
|
+
if (!actor || same(actor, me)) return null;
|
|
157
|
+
return {
|
|
158
|
+
id: `reopened:${subject.id}:${event?.createdAt ?? tracked.closedAt}`,
|
|
159
|
+
kind: "reopened",
|
|
160
|
+
subjectId: subject.id,
|
|
161
|
+
subject: "pr",
|
|
162
|
+
key: tracked.key,
|
|
163
|
+
repo: tracked.repo,
|
|
164
|
+
number: tracked.number,
|
|
165
|
+
title: subject.title || tracked.title,
|
|
166
|
+
url: tracked.url,
|
|
167
|
+
actor,
|
|
168
|
+
at: event?.createdAt ?? new Date().toISOString(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function change(
|
|
173
|
+
subject: { id: string; number: number; title: string; url: string; repository: { nameWithOwner: string } },
|
|
174
|
+
kind: "pr" | "issue",
|
|
175
|
+
what: OthersChange["kind"],
|
|
176
|
+
at: string,
|
|
177
|
+
actor?: string,
|
|
178
|
+
to?: string,
|
|
179
|
+
): OthersChange {
|
|
180
|
+
return {
|
|
181
|
+
id: `${what}:${subject.id}:${at}`,
|
|
182
|
+
kind: what,
|
|
183
|
+
subjectId: subject.id,
|
|
184
|
+
subject: kind,
|
|
185
|
+
key: prKey(subject),
|
|
186
|
+
repo: subject.repository.nameWithOwner,
|
|
187
|
+
number: subject.number,
|
|
188
|
+
title: subject.title,
|
|
189
|
+
url: subject.url,
|
|
190
|
+
...(actor ? { actor } : {}),
|
|
191
|
+
...(to ? { to } : {}),
|
|
192
|
+
at,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// The ledger after a refresh. New events count only within `windowDays` (mentionDays), so a first run catches up that far
|
|
197
|
+
// and no further; kept for `keepDays`, long enough for History. Work back in my hands drops its handover unless it was
|
|
198
|
+
// cleared, which stays in its week. What couldn't be looked up is left to retry next time.
|
|
199
|
+
export function nextLedger(
|
|
200
|
+
ledger: ChangeLedger,
|
|
201
|
+
data: Data,
|
|
202
|
+
me: string,
|
|
203
|
+
lookups: Lookups,
|
|
204
|
+
now: Date,
|
|
205
|
+
windowDays: number,
|
|
206
|
+
keepDays: number,
|
|
207
|
+
reopens: ReopenLookups = new Map(),
|
|
208
|
+
): ChangeLedger {
|
|
209
|
+
const since = (days: number) => new Date(now.getTime() - days * 86_400_000).toISOString();
|
|
210
|
+
const found: OthersChange[] = [];
|
|
211
|
+
const endedAt = new Map(present(data.ended.nodes).map((pr) => [pr.id, pr.mergedAt ?? pr.closedAt]));
|
|
212
|
+
// Assigning a PR once it's merged or closed hands nothing over.
|
|
213
|
+
const handovers = [...lookups.values()]
|
|
214
|
+
.map((subject) => (subject ? handover(subject, me) : null))
|
|
215
|
+
.filter((event): event is OthersChange => !!event && !(endedAt.has(event.subjectId) && event.at > endedAt.get(event.subjectId)!));
|
|
216
|
+
found.push(...handovers);
|
|
217
|
+
// A handover whose work came back to me no longer makes a later merge someone else's [HIS-06].
|
|
218
|
+
const handedAt = (id: string) => [...ledger.events, ...handovers].filter((event) => isHandover(event) && !event.returned && event.subjectId === id).map((event) => event.at);
|
|
219
|
+
for (const pr of present(data.ended.nodes)) {
|
|
220
|
+
// A PR someone else has whose hands aren't looked up yet waits a refresh, so a handover isn't reported as a merge.
|
|
221
|
+
if (handedOver(pr, me) && !lookups.has(pr.id) && ledger.handed[pr.id] !== signature(pr)) continue;
|
|
222
|
+
const event = ended(pr, me);
|
|
223
|
+
// One that left my hands before it ended was a handover, not my work merged or closed.
|
|
224
|
+
if (event && !handedAt(pr.id).some((at) => at <= event.at)) found.push(event);
|
|
225
|
+
}
|
|
226
|
+
for (const issue of present(data.closedIssues?.nodes ?? [])) {
|
|
227
|
+
const event = closedByOther(issue, me);
|
|
228
|
+
if (event) found.push(event);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Track what Attention Span sees closed, so a later reopen by someone else is a change [HIS-07]. A merged PR can't reopen.
|
|
232
|
+
const tracked: Record<string, TrackedPr> = { ...ledger.tracked };
|
|
233
|
+
for (const pr of present(data.ended.nodes)) {
|
|
234
|
+
if (pr.merged || !pr.id) continue;
|
|
235
|
+
tracked[pr.id] = { key: prKey(pr), number: pr.number, title: pr.title, url: pr.url, repo: pr.repository.nameWithOwner, closedAt: pr.closedAt };
|
|
236
|
+
}
|
|
237
|
+
// A reopen takes the old close out of History's week and adds a note. A lookup that failed keeps the PR tracked.
|
|
238
|
+
const reopenedIds = new Set<string>();
|
|
239
|
+
for (const [id, subject] of reopens) {
|
|
240
|
+
const before = tracked[id];
|
|
241
|
+
if (!subject) {
|
|
242
|
+
delete tracked[id];
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
// Merged: it can't reopen any more. Still closed: keep watching it.
|
|
246
|
+
if (subject.state === "MERGED") {
|
|
247
|
+
delete tracked[id];
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (subject.state !== "OPEN") continue;
|
|
251
|
+
// Open again: the old close leaves its week whoever reopened it; only someone else's reopen is a note.
|
|
252
|
+
delete tracked[id];
|
|
253
|
+
reopenedIds.add(id);
|
|
254
|
+
const event = before ? reopened(before, subject, me) : null;
|
|
255
|
+
if (event) found.push(event);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Mine again: my PRs with nobody else on them, and issues assigned to me.
|
|
259
|
+
const mineNow = new Set([...present(data.mine.nodes).filter((pr) => !handedOver(pr, me)).map((pr) => pr.id), ...Object.keys(assignedNow(data))]);
|
|
260
|
+
const known = new Set(ledger.events.map((event) => event.id));
|
|
261
|
+
const fresh = found.filter((event) => !known.has(event.id) && event.at >= since(windowDays));
|
|
262
|
+
const cleared = new Set(ledger.gotIt);
|
|
263
|
+
const events = [...ledger.events, ...fresh]
|
|
264
|
+
// A reopen leaves the closed PR's week; its note takes its place.
|
|
265
|
+
.filter((event) => !(event.kind === "closed" && reopenedIds.has(event.subjectId)))
|
|
266
|
+
.flatMap((event) => {
|
|
267
|
+
if (!isHandover(event) || !mineNow.has(event.subjectId)) return [event];
|
|
268
|
+
// Back in my hands: an uncleared handover goes; a cleared one stays in its week, marked so my later work is mine.
|
|
269
|
+
return cleared.has(event.id) ? [{ ...event, returned: true as const }] : [];
|
|
270
|
+
})
|
|
271
|
+
.filter((event) => event.at >= since(keepDays))
|
|
272
|
+
.sort((a, b) => b.at.localeCompare(a.at));
|
|
273
|
+
const ids = new Set(events.map((event) => event.id));
|
|
274
|
+
// Nothing older than the window is worth tracking, whether or not its lookup worked [GH-01].
|
|
275
|
+
for (const [id, pr] of Object.entries(tracked)) if (pr.closedAt < since(keepDays)) delete tracked[id];
|
|
276
|
+
|
|
277
|
+
// Issues that left my search and couldn't be looked up stay, so they're checked again.
|
|
278
|
+
const assigned = assignedNow(data);
|
|
279
|
+
if (ledger.assigned) for (const [id, key] of Object.entries(ledger.assigned)) if (!(id in assigned) && !lookups.has(id)) assigned[id] = key;
|
|
280
|
+
// A PR's hands are settled once looked up; one that failed keeps its old signature, so it's asked again.
|
|
281
|
+
const handed: Record<string, string> = {};
|
|
282
|
+
for (const pr of handedPrs(data, me)) {
|
|
283
|
+
const before = ledger.handed[pr.id];
|
|
284
|
+
if (before !== undefined || lookups.has(pr.id)) handed[pr.id] = lookups.has(pr.id) ? pr.signature : before;
|
|
285
|
+
}
|
|
286
|
+
return { events, gotIt: ledger.gotIt.filter((id) => ids.has(id)), assigned, handed, tracked };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// An archive acknowledges exactly the events on its work at that moment, keyed by "owner/name#number" [ATT-22].
|
|
290
|
+
// `upTo` keeps what others did after then unread: a session archived in Paseo acknowledges only what came before it.
|
|
291
|
+
export function acknowledge(ledger: ChangeLedger, keys: string[], upTo?: string): ChangeLedger {
|
|
292
|
+
const wanted = new Set(keys.map((key) => key.toLowerCase()));
|
|
293
|
+
const before = (at: string) => !upTo || Date.parse(at) <= Date.parse(upTo);
|
|
294
|
+
const ids = ledger.events.filter((event) => wanted.has(event.key.toLowerCase()) && before(event.at)).map((event) => event.id);
|
|
295
|
+
return { ...ledger, gotIt: [...new Set([...ledger.gotIt, ...ids])] };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// What a refresh found, with the Got its, and archives, tapped while it ran, as those changed the ledger after the refresh
|
|
299
|
+
// read it [HIS-07, ATT-22].
|
|
300
|
+
export function withGotIt(next: ChangeLedger, gotIt: string[]): ChangeLedger {
|
|
301
|
+
const ids = new Set(next.events.map((event) => event.id));
|
|
302
|
+
return { ...next, gotIt: gotIt.filter((id) => ids.has(id)) };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// The ledger as cards: History's unread notes, newest first, what was cleared into each week, and the finished work a live
|
|
306
|
+
// refresh saw before History's daily fetch did [HIS-07]. Unread notes expire after `windowDays`; cleared ones stay
|
|
307
|
+
// `historySince`, out of the week's copy [HIS-06, HIS-07].
|
|
308
|
+
export function changeItems(ledger: ChangeLedger, now: Date, windowDays: number, historySince: string): { notes: Item[]; history: Item[]; finished: Item[] } {
|
|
309
|
+
const since = new Date(now.getTime() - windowDays * 86_400_000).toISOString();
|
|
310
|
+
const gotIt = new Set(ledger.gotIt);
|
|
311
|
+
const base = (change: OthersChange): Omit<Item, "key" | "section"> => ({
|
|
312
|
+
kind: change.subject,
|
|
313
|
+
draft: false,
|
|
314
|
+
repo: change.repo,
|
|
315
|
+
number: change.number,
|
|
316
|
+
title: change.title,
|
|
317
|
+
url: change.url,
|
|
318
|
+
chips: [],
|
|
319
|
+
actions: [],
|
|
320
|
+
children: [],
|
|
321
|
+
target: { kind: change.subject, repo: change.repo, number: change.number, title: change.title, url: change.url },
|
|
322
|
+
othersActivityAt: change.at,
|
|
323
|
+
closedAt: change.at,
|
|
324
|
+
change,
|
|
325
|
+
});
|
|
326
|
+
const notes = ledger.events
|
|
327
|
+
.filter((change) => !gotIt.has(change.id) && change.at >= since)
|
|
328
|
+
.map((change): Item => ({ ...base(change), key: `change:${change.id}`, section: "changed", actions: ["got_it"] }));
|
|
329
|
+
const history = ledger.events
|
|
330
|
+
// A merge or an issue close is the week's Finished, not a change repeated under it [HIS-07].
|
|
331
|
+
.filter((change) => gotIt.has(change.id) && !isFinishedChange(change) && change.at >= historySince)
|
|
332
|
+
.map((change): Item => ({ ...base(change), key: `handed:${change.id}`, section: "handed_off", actions: [] }));
|
|
333
|
+
// A merge or close someone else did is finished work at once, not only when History's daily fetch catches up [HIS-07].
|
|
334
|
+
const finished = ledger.events
|
|
335
|
+
.filter((change) => isFinishedChange(change) && change.at >= historySince)
|
|
336
|
+
.map(
|
|
337
|
+
(change): Item => ({
|
|
338
|
+
...base(change),
|
|
339
|
+
key: change.key,
|
|
340
|
+
section: "done",
|
|
341
|
+
// The week's cards say it in the finished wording, not the note's: "merged 2h ago by dave" [HIS-05, HIS-07].
|
|
342
|
+
change: undefined,
|
|
343
|
+
...(change.kind === "merged" && change.actor ? { mergedBy: change.actor } : {}),
|
|
344
|
+
...(change.kind === "issue_closed" && change.actor ? { closedBy: change.actor } : {}),
|
|
345
|
+
...(change.reason === "not_planned" ? { notPlanned: true as const, chips: [{ text: "not planned", tone: "neutral" as const }] } : {}),
|
|
346
|
+
}),
|
|
347
|
+
);
|
|
348
|
+
return { notes, history, finished };
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Keys of my PRs and issues still out of my hands: a merge by their new owner isn't my finished work [HIS-06]. A cleared
|
|
352
|
+
// handover whose work came back to me doesn't hide what I later finish.
|
|
353
|
+
export function handedKeys(ledger: ChangeLedger): Set<string> {
|
|
354
|
+
return new Set(ledger.events.filter((event) => isHandover(event) && !event.returned).map((event) => event.key));
|
|
355
|
+
}
|
package/server/classify.ts
CHANGED
|
@@ -426,6 +426,7 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
426
426
|
// My merged PRs under the closed issues they worked on, closed issues, and reviews [HIS-01, HIS-02, ATT-03].
|
|
427
427
|
export function classifyHistory(data: HistoryResult): Item[] {
|
|
428
428
|
const items: Item[] = [];
|
|
429
|
+
const me = data.viewer?.login.toLowerCase();
|
|
429
430
|
const closed = new Map<string, Item>();
|
|
430
431
|
// What kind of work it was, on the card and its copied line [HIS-04].
|
|
431
432
|
const kinded = (item: Item, node: { title: string; labels?: { nodes: { name: string }[] }; issueType?: { name: string } | null }): Item => {
|
|
@@ -434,7 +435,10 @@ export function classifyHistory(data: HistoryResult): Item[] {
|
|
|
434
435
|
};
|
|
435
436
|
for (const issue of compact(data.closed.nodes)) {
|
|
436
437
|
const notPlanned = issue.stateReason === "NOT_PLANNED";
|
|
437
|
-
|
|
438
|
+
// Who closed it, when it wasn't me [HIS-07].
|
|
439
|
+
const closer = issue.timelineItems?.nodes.at(-1)?.actor?.login;
|
|
440
|
+
const closedBy = closer && me && closer.toLowerCase() !== me ? { closedBy: closer } : {};
|
|
441
|
+
const item = kinded({ ...plain(issue, "issue", "done"), closedAt: issue.closedAt, chips: notPlanned ? [chip("not planned")] : [], ...closedBy, ...(notPlanned ? { notPlanned: true as const } : {}) }, issue);
|
|
438
442
|
// Not planned issues get no PRs under them: the PRs were still done, so they're listed on their own [HIS-03].
|
|
439
443
|
if (!notPlanned) closed.set(prKey(issue), item);
|
|
440
444
|
items.push(item);
|
|
@@ -443,10 +447,17 @@ export function classifyHistory(data: HistoryResult): Item[] {
|
|
|
443
447
|
// Each merged PR on its own: its branches are gone, so it can't be put back in its stack [ATT-03].
|
|
444
448
|
const linked = { repo: pr.repository.nameWithOwner, body: pr.body, linked: pr.closingIssuesReferences.nodes.map(prKey) };
|
|
445
449
|
const issue = closed.get(issueFor([linked], (key) => closed.has(key)) ?? "");
|
|
446
|
-
|
|
447
|
-
|
|
450
|
+
// Who merged it, when it wasn't me, alone or under its issue [HIS-05].
|
|
451
|
+
const by = pr.mergedBy?.login;
|
|
452
|
+
const mergedBy = by && me && by.toLowerCase() !== me ? { mergedBy: by } : {};
|
|
453
|
+
if (issue) issue.children.push({ key: prKey(pr), number: pr.number, title: pr.title, url: pr.url, draft: false, chips: [], attention: false, ...mergedBy });
|
|
454
|
+
else items.push(kinded({ ...plain(pr, "pr", "done"), closedAt: pr.mergedAt, ...mergedBy }, pr));
|
|
455
|
+
}
|
|
456
|
+
for (const pr of compact(data.reviewed.nodes)) {
|
|
457
|
+
const by = pr.mergedBy?.login;
|
|
458
|
+
const mergedBy = by && me && by.toLowerCase() !== me ? { mergedBy: by } : {};
|
|
459
|
+
items.push(kinded({ ...plain(pr, "pr", "reviewed"), closedAt: pr.mergedAt, person: author(pr.author, pr.mergedAt), ...mergedBy }, pr));
|
|
448
460
|
}
|
|
449
|
-
for (const pr of compact(data.reviewed.nodes)) items.push(kinded({ ...plain(pr, "pr", "reviewed"), closedAt: pr.mergedAt, person: author(pr.author, pr.mergedAt) }, pr));
|
|
450
461
|
return items.sort(order);
|
|
451
462
|
}
|
|
452
463
|
|
package/server/fixture.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentSummary, GithubColor, ItemDetails, Reviewer, ReviewerChoices, Target } from "../shared/attention";
|
|
2
|
+
import type { OthersChange } from "../shared/changes";
|
|
2
3
|
import type { SessionKind } from "../shared/config";
|
|
3
4
|
import type { IssueField } from "../shared/setup";
|
|
4
5
|
import type { Actor, Comment, Details, IssueNode, MentionNode, PickableNode, PullRequestNode, SearchResult } from "./github-types";
|
|
@@ -134,6 +135,8 @@ export function builders(now: Date) {
|
|
|
134
135
|
merged: nodes("merged") as SearchResult["merged"],
|
|
135
136
|
reviewed: nodes("reviewed") as SearchResult["reviewed"],
|
|
136
137
|
closed: nodes("closed") as SearchResult["closed"],
|
|
138
|
+
ended: nodes("ended") as SearchResult["ended"],
|
|
139
|
+
closedIssues: nodes("closedIssues") as SearchResult["closedIssues"],
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
142
|
|
|
@@ -152,6 +155,8 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
152
155
|
title,
|
|
153
156
|
url: `https://github.com/${REPO}/pull/${number}`,
|
|
154
157
|
mergedAt: daysAgo(days),
|
|
158
|
+
// Someone else merged one of them [HIS-05].
|
|
159
|
+
mergedBy: { login: number === 177 || number === 183 ? "dave" : number === 179 ? "carol" : "me" },
|
|
155
160
|
repository,
|
|
156
161
|
labels: labels(...names),
|
|
157
162
|
closingIssuesReferences: { nodes: closesIssue ? [{ number: closesIssue, repository }] : [] },
|
|
@@ -165,6 +170,8 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
165
170
|
repository,
|
|
166
171
|
issueType: type ? { name: type } : null,
|
|
167
172
|
labels: labels(...names),
|
|
173
|
+
// #188 was closed by someone else [HIS-07].
|
|
174
|
+
timelineItems: { nodes: [{ actor: { login: number === 188 ? "alice" : "me" } }] },
|
|
168
175
|
});
|
|
169
176
|
|
|
170
177
|
const data = search({
|
|
@@ -278,23 +285,30 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
278
285
|
{ ...pickable(165, {}, 3, "Task", "Devcontainers for pull requests", "me/tool"), projectItems: { nodes: [] }, sources: ["mine"] },
|
|
279
286
|
],
|
|
280
287
|
merged: [
|
|
281
|
-
merged(
|
|
288
|
+
merged(183, "Retry failed webhooks", 2 / 24, undefined, "feature"),
|
|
282
289
|
merged(172, "Fix VAT on credit notes", 3, undefined, "bug"),
|
|
283
290
|
merged(177, "chore: bump the build image", 4),
|
|
284
|
-
merged(
|
|
291
|
+
merged(170, "Nightly backup check", 1, 171),
|
|
292
|
+
// Handed over to carol before she merged it, so it isn't listed as mine [HIS-06].
|
|
293
|
+
merged(179, "Move invoices to the new queue", 1),
|
|
285
294
|
merged(173, "Speed up the order list", 9, 174),
|
|
286
295
|
merged(175, "Remove the old importer", 16),
|
|
287
296
|
],
|
|
288
297
|
reviewed: [
|
|
289
|
-
{ number:
|
|
290
|
-
{ number:
|
|
291
|
-
{ number: 182, title: "Sentry release tracking", url: `https://github.com/${REPO}/pull/182`, mergedAt: daysAgo(11), repository, author: alice },
|
|
298
|
+
{ 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") },
|
|
299
|
+
{ number: 191, title: "Speed up the search index", url: `https://github.com/${REPO}/pull/191`, mergedAt: daysAgo(3), mergedBy: { login: "bob" }, repository, author: bob },
|
|
300
|
+
{ number: 182, title: "Sentry release tracking", url: `https://github.com/${REPO}/pull/182`, mergedAt: daysAgo(11), mergedBy: { login: "alice" }, repository, author: alice },
|
|
292
301
|
],
|
|
293
302
|
closed: [
|
|
303
|
+
closed(188, "Export fails on empty months", 6 / 24, "COMPLETED", "Bug"),
|
|
294
304
|
closed(171, "Backups are never verified", 1, "COMPLETED", "Feature"),
|
|
295
305
|
closed(174, "Order list takes 8 seconds", 9, "COMPLETED", undefined, "type: bug"),
|
|
296
306
|
closed(176, "Dark mode for the admin", 10, "NOT_PLANNED", undefined, "enhancement"),
|
|
297
307
|
],
|
|
308
|
+
// The live close search sees the same issue, so its close is a note too [HIS-07].
|
|
309
|
+
closedIssues: [
|
|
310
|
+
{ 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" } }] } },
|
|
311
|
+
],
|
|
298
312
|
});
|
|
299
313
|
return {
|
|
300
314
|
data,
|
|
@@ -310,20 +324,77 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
310
324
|
};
|
|
311
325
|
}
|
|
312
326
|
|
|
327
|
+
// What others did to my work, one of each kind, as the ledger keeps them [HIS-07, HIS-06]. #179 was handed over, then merged
|
|
328
|
+
// by its new owner, so History doesn't count it as mine.
|
|
329
|
+
export function fixtureChanges(now: Date): OthersChange[] {
|
|
330
|
+
const hoursAgo = (hours: number) => new Date(now.getTime() - hours * 3_600_000).toISOString();
|
|
331
|
+
const event = (kind: OthersChange["kind"], subject: "pr" | "issue", number: number, title: string, hours: number, actor?: string, to?: string): OthersChange => ({
|
|
332
|
+
id: `${kind}:F_${number}:${hoursAgo(hours)}`,
|
|
333
|
+
kind,
|
|
334
|
+
subjectId: `F_${number}`,
|
|
335
|
+
subject,
|
|
336
|
+
key: `${REPO}#${number}`,
|
|
337
|
+
repo: REPO,
|
|
338
|
+
number,
|
|
339
|
+
title,
|
|
340
|
+
url: `https://github.com/${REPO}/${subject === "pr" ? "pull" : "issues"}/${number}`,
|
|
341
|
+
...(actor ? { actor } : {}),
|
|
342
|
+
...(to ? { to } : {}),
|
|
343
|
+
at: hoursAgo(hours),
|
|
344
|
+
});
|
|
345
|
+
return [
|
|
346
|
+
{ ...event("reopened", "pr", 181, "Paginate the order export", 1, "bob") },
|
|
347
|
+
event("merged", "pr", 183, "Retry failed webhooks", 2, "dave"),
|
|
348
|
+
event("took_over", "pr", 186, "Split the invoice PDF job", 5, "phil", "phil"),
|
|
349
|
+
{ ...event("issue_closed", "issue", 188, "Export fails on empty months", 6, "alice"), reason: "completed" as const },
|
|
350
|
+
event("closed", "pr", 169, "Cache exchange rates", 26, "alice"),
|
|
351
|
+
event("handed", "pr", 179, "Move invoices to the new queue", 96, "dave", "carol"),
|
|
352
|
+
event("unassigned", "issue", 160, "Refunds skip the ledger", 192, "bob"),
|
|
353
|
+
event("closed", "pr", 170, "Drop the legacy CSV import", 216, "bob"),
|
|
354
|
+
];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// The notes History already shows as cleared in the preview: their week's Changed by others has them [HIS-07].
|
|
358
|
+
export function fixtureGotIt(now: Date): string[] {
|
|
359
|
+
return fixtureChanges(now)
|
|
360
|
+
.filter((change) => (change.number === 179 || change.number === 170) && change.kind !== "merged")
|
|
361
|
+
.map((change) => change.id);
|
|
362
|
+
}
|
|
363
|
+
|
|
313
364
|
// Sessions the preview shows as started from items: working, needs me, failed, idle.
|
|
314
365
|
// Each sits in its action's line in the sheet. Issue 90 has two: an old one with no kind, which leads, and Rebase stack on its PR.
|
|
315
366
|
// #113 waits on CI while its Fix CI session works, though Fix CI isn't one of its actions any more.
|
|
316
367
|
// #120's was started outside Attention Span, in a workspace Paseo linked to the PR, so it has no kind [SES-08].
|
|
317
368
|
// #197's too, so it shows on its stack, led by #196 [ATT-04].
|
|
318
|
-
const agent = (
|
|
369
|
+
const agent = (
|
|
370
|
+
id: string,
|
|
371
|
+
itemKey: string,
|
|
372
|
+
kind: SessionKind | undefined,
|
|
373
|
+
status: string,
|
|
374
|
+
minutesAgo: number,
|
|
375
|
+
requiresAttention = false,
|
|
376
|
+
workspace?: AgentSummary["workspace"],
|
|
377
|
+
title = `Fixture session ${id}`,
|
|
378
|
+
): AgentSummary => ({
|
|
319
379
|
id,
|
|
320
380
|
itemKey,
|
|
321
381
|
kind,
|
|
322
382
|
status,
|
|
323
383
|
requiresAttention,
|
|
324
|
-
title
|
|
325
|
-
workspaceId: null,
|
|
384
|
+
title,
|
|
385
|
+
workspaceId: workspace ? `WS_${id}` : null,
|
|
326
386
|
lastActivityAt: new Date(Date.now() - minutesAgo * 60_000).toISOString(),
|
|
387
|
+
...(workspace ? { workspace } : {}),
|
|
388
|
+
});
|
|
389
|
+
// A worktree Paseo made, clean or with uncommitted or unpushed work [ATT-22].
|
|
390
|
+
const sessionWorkspace = (branch: string, dirty: boolean | undefined, ahead: number | undefined, worktree = true, dirtyFiles?: number): AgentSummary["workspace"] => ({
|
|
391
|
+
kind: worktree ? "worktree" : "local_checkout",
|
|
392
|
+
name: `Workspace for ${branch}`,
|
|
393
|
+
directory: `/tmp/attention-span/${branch}`,
|
|
394
|
+
branch,
|
|
395
|
+
...(dirty === undefined ? {} : { dirty }),
|
|
396
|
+
...(ahead === undefined ? {} : { ahead }),
|
|
397
|
+
...(dirtyFiles === undefined ? {} : { dirtyFiles }),
|
|
327
398
|
});
|
|
328
399
|
export const FIXTURE_AGENTS: AgentSummary[] = [
|
|
329
400
|
agent("agent-101", `${REPO}#101`, "fix", "running", 4),
|
|
@@ -335,6 +406,12 @@ export const FIXTURE_AGENTS: AgentSummary[] = [
|
|
|
335
406
|
agent("agent-113", `${REPO}#113`, "fix", "running", 2),
|
|
336
407
|
agent("agent-120", `${REPO}#120`, undefined, "running", 3),
|
|
337
408
|
agent("agent-197", `${REPO}#197`, undefined, "idle", 15),
|
|
409
|
+
// Wrap up: finished work whose sessions are all idle [ATT-22].
|
|
410
|
+
agent("agent-183", `${REPO}#183`, "fix", "idle", 20, false, sessionWorkspace("retry-webhooks", false, 0), "Retry webhooks"),
|
|
411
|
+
agent("agent-186", `${REPO}#186`, "fix", "idle", 40, false, sessionWorkspace("split-invoice-pdf", true, 1, true, 2), "Split invoice PDF"),
|
|
412
|
+
agent("agent-190", `${REPO}#190`, "review", "idle", 60, false, sessionWorkspace("add-vat-export", false, 0), "Review PR 190: Add the VAT export"),
|
|
413
|
+
agent("agent-172", `${REPO}#172`, "fix", "idle", 240, false, sessionWorkspace("fix-vat-credit-notes", false, 0), "Fix VAT on credit notes"),
|
|
414
|
+
agent("agent-172b", `${REPO}#172`, "address", "idle", 250, false, sessionWorkspace("credit-note-tests", undefined, undefined), "Credit note tests"),
|
|
338
415
|
];
|
|
339
416
|
|
|
340
417
|
export const FIXTURE_CONTEXT = "Context from GitHub would go here (fixture mode).";
|
package/server/gh.ts
CHANGED
|
@@ -34,16 +34,28 @@ export function runGh(args: string[], input?: string, { timeoutMs }: { timeoutMs
|
|
|
34
34
|
|
|
35
35
|
// GitHub's answer with its errors kept beside whatever data resolved, for callers that must tell a partial answer from a
|
|
36
36
|
// whole one. Throws only when nothing came back at all.
|
|
37
|
-
|
|
37
|
+
// `failures` says where each error was and what kind, for callers that tell a node GitHub can't find from one it failed on.
|
|
38
|
+
export interface GraphqlFailure {
|
|
39
|
+
message: string;
|
|
40
|
+
type?: string;
|
|
41
|
+
path?: (string | number)[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function graphqlResult<T>(
|
|
45
|
+
query: string,
|
|
46
|
+
variables: Record<string, unknown> = {},
|
|
47
|
+
options: { timeoutMs?: number } = {},
|
|
48
|
+
): Promise<{ data: T | null; errors: string[]; failures: GraphqlFailure[] }> {
|
|
38
49
|
const { code, stdout, stderr } = await runGh(["api", "graphql", "--input", "-"], JSON.stringify({ query, variables }), options);
|
|
39
|
-
let parsed: { data?: T | null; errors?:
|
|
50
|
+
let parsed: { data?: T | null; errors?: GraphqlFailure[] } | undefined;
|
|
40
51
|
try {
|
|
41
52
|
parsed = JSON.parse(stdout);
|
|
42
53
|
} catch {
|
|
43
54
|
// Not JSON: an auth or network failure.
|
|
44
55
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
56
|
+
const failures = parsed?.errors ?? [];
|
|
57
|
+
const errors = failures.map((error) => error.message);
|
|
58
|
+
if (parsed?.data) return { data: parsed.data, errors, failures };
|
|
47
59
|
throw new Error(errors.join("; ") || stderr.trim() || `gh exited with ${code}`);
|
|
48
60
|
}
|
|
49
61
|
|