@andrioid/paseo-attention-span 0.4.14 → 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.
Files changed (53) hide show
  1. package/OVERVIEW.md +9 -5
  2. package/README.md +2 -2
  3. package/client/attention-screen.tsx +127 -141
  4. package/client/card.tsx +4 -2
  5. package/client/history.tsx +184 -0
  6. package/client/icons.ts +3 -1
  7. package/client/mark.ts +19 -0
  8. package/client/sessions.ts +50 -3
  9. package/client/ui.tsx +3 -3
  10. package/client/wrap-up.tsx +197 -0
  11. package/docs/architecture.md +17 -10
  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.png +0 -0
  25. package/docs/screenshots/desktop-dark-settings.png +0 -0
  26. package/docs/screenshots/desktop-dark-setup.png +0 -0
  27. package/docs/screenshots/desktop-dark-waiting.png +0 -0
  28. package/docs/screenshots/phone-dark-doing.png +0 -0
  29. package/docs/screenshots/phone-dark-history.png +0 -0
  30. package/docs/screenshots/phone-light-next-up-filtered.png +0 -0
  31. package/index.client.tsx +6 -1
  32. package/index.server.ts +21 -2
  33. package/package.json +8 -3
  34. package/requirements.yaml +10 -9
  35. package/server/archive.ts +132 -0
  36. package/server/archived.ts +120 -0
  37. package/server/changes.ts +184 -26
  38. package/server/classify.ts +9 -2
  39. package/server/fixture.ts +56 -12
  40. package/server/github-types.ts +29 -5
  41. package/server/queries.ts +33 -7
  42. package/server/service.ts +88 -17
  43. package/server/store.ts +10 -3
  44. package/server/view.ts +14 -5
  45. package/shared/archive.ts +37 -0
  46. package/shared/attention.ts +85 -8
  47. package/shared/changes.ts +26 -11
  48. package/shared/got-it.ts +23 -0
  49. package/shared/history-report.ts +61 -0
  50. package/shared/rpc.ts +23 -4
  51. package/shared/still.ts +4 -3
  52. package/shared/wrap-up.ts +126 -0
  53. package/docs/screenshots/desktop-dark-history-reviewed.png +0 -0
package/shared/rpc.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { defineRpc } from "@getpaseo/plugin";
2
2
  import { z } from "zod";
3
3
  import type { AttentionView, ItemDetails, ProjectsAccess, ReviewerChoices, Target } from "./attention";
4
+ import type { ArchiveOutcome } from "./archive";
4
5
  import { SessionKind } from "./config";
5
6
  import type { ConfigStatus, CoverageCheck, IssueField, SetupStatus } from "./setup";
6
7
  import type { FeedbackInfo } from "./feedback";
@@ -12,13 +13,31 @@ const view = z.custom<AttentionView>();
12
13
  const target = z.custom<Target>();
13
14
  const done = z.object({ ok: z.literal(true) });
14
15
 
15
- // The cached view. Feeds older than their schedule are refreshed from GitHub first; `refresh` fetches that feed now (⟳).
16
- export const getAttention = defineRpc({ name: "attention.get", input: z.object({ refresh: z.enum(["live", "history"]).optional() }), output: view });
16
+ // The cached view. Feeds older than their schedule are refreshed from GitHub first; `refresh` fetches that feed now (⟳);
17
+ // `cached` skips GitHub altogether, for a view that only needs what the server already knows.
18
+ export const getAttention = defineRpc({
19
+ name: "attention.get",
20
+ input: z
21
+ .object({ refresh: z.enum(["live", "history"]).optional(), cached: z.boolean().optional() })
22
+ .refine((input) => !(input.refresh && input.cached), "refresh and cached don't go together"),
23
+ output: view,
24
+ });
17
25
  export const dismissItem = defineRpc({ name: "attention.dismiss", input: z.object({ key: z.string() }), output: view });
18
26
  // Undo one dismissal [ATT-08].
19
27
  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 });
28
+ // Clears Changed by others notes, one or all of them; `on: false` brings them back for Undo. Nothing changes on GitHub [HIS-07].
29
+ export const gotIt = defineRpc({ name: "attention.got-it", input: z.object({ ids: z.array(z.string()), on: z.boolean() }), output: view });
30
+ // Reviewed and Changed by others in History's weeks; remembered in state.json [HIS-07].
31
+ export const setHistoryFilter = defineRpc({ name: "history.filter", input: z.object({ filter: z.array(z.enum(["reviewed", "changed"])) }), output: view });
32
+ // Archives a Wrap up row's sessions, acknowledging what others did to the work [ATT-22]. `confirm` is the unsaved-work sheet.
33
+ export const archiveSessions = defineRpc({
34
+ name: "attention.archive",
35
+ input: z.object({
36
+ targets: z.array(z.object({ itemKey: z.string(), agentIds: z.array(z.string()), keys: z.array(z.string()) })),
37
+ confirm: z.boolean(),
38
+ }),
39
+ output: z.custom<ArchiveOutcome>(),
40
+ });
22
41
  export const restoreDismissed = defineRpc({ name: "attention.restore-dismissed", input: z.object({}), output: view });
23
42
  // Adds one entry to codeRepos in config.json [SES-07].
24
43
  export const setCodeRepo = defineRpc({ name: "config.set-code-repo", input: z.object({ issueRepo: z.string(), codeRepo: z.string() }), output: view });
package/shared/still.ts CHANGED
@@ -13,8 +13,9 @@ export function sceneAt(date: Date): Scene {
13
13
  }
14
14
 
15
15
  // Calm only when it's true: Doing is empty after a refresh that worked. Dismissed items don't count;
16
- // they're not on me until something new happens [ATT-08]. Loading, a failed refresh or none yet show plainly.
17
- export function isClear(view: Pick<AttentionView, "doing" | "feeds">, failed = false): boolean {
16
+ // they're not on me until something new happens [ATT-08]. Wrap up's rows do: the horizon waits for them [ATT-18, ATT-22].
17
+ // Loading, a failed refresh or none yet show plainly.
18
+ export function isClear(view: Pick<AttentionView, "doing" | "feeds">, failed = false, wrap = 0): boolean {
18
19
  const live = view.feeds.live;
19
- return view.doing.length === 0 && !!live.fetchedAt && !live.error && !failed;
20
+ return view.doing.length === 0 && wrap === 0 && !!live.fetchedAt && !live.error && !failed;
20
21
  }
@@ -0,0 +1,126 @@
1
+ import { type AgentSummary, type AttentionView, isIdle, type Item, keySet, matchSessions, memberKeys, type RememberedGroups, type SessionWorkspace, type WrapItem } from "./attention";
2
+ import { ago } from "./format";
3
+ import { changeText } from "./changes";
4
+
5
+ // Wrap up: finished or out-of-my-hands work whose unarchived Paseo sessions are all idle [ATT-22]. Pure, so the rules are
6
+ // testable. It's assembled on the client, which already polls Paseo's sessions for the screen and the sidebar's count; the
7
+ // server archives and acknowledges.
8
+
9
+ export type SessionCleanliness = "clean" | "dirty" | "unknown";
10
+
11
+ // What archiving would lose in a session's worktree, from Paseo's snapshot: clean only when it says both that nothing is
12
+ // uncommitted and that nothing is ahead. The server asks git again before archiving [ATT-22].
13
+ export function sessionCleanliness(agent: AgentSummary): SessionCleanliness {
14
+ const workspace = agent.workspace;
15
+ if (!workspace) return "unknown";
16
+ if (workspace.dirty === true || (workspace.ahead ?? 0) > 0) return "dirty";
17
+ if (workspace.dirty === false && workspace.ahead === 0) return "clean";
18
+ return "unknown";
19
+ }
20
+
21
+ // "uncommitted changes and 1 unpushed commit on branch": what the multi-session sheet says about a session, from Paseo's
22
+ // snapshot, which doesn't count files.
23
+ export function unsavedText(agent: AgentSummary): string {
24
+ const workspace: SessionWorkspace | undefined = agent.workspace;
25
+ if (sessionCleanliness(agent) === "unknown") return "Couldn't check for unsaved changes";
26
+ const parts: string[] = [];
27
+ if (workspace?.dirty) parts.push("uncommitted changes");
28
+ const ahead = workspace?.ahead ?? 0;
29
+ if (ahead > 0) parts.push(`${ahead} unpushed commit${ahead === 1 ? "" : "s"}`);
30
+ const what = parts.join(" and ") || "unsaved changes";
31
+ return workspace?.branch ? `${what} on ${workspace.branch}` : what;
32
+ }
33
+
34
+ // A row with one session, clean: Archive session archives it at once, whatever happened on GitHub [ATT-22].
35
+ export function cleanSingle(item: WrapItem): boolean {
36
+ return item.wrap.sessions.length === 1 && sessionCleanliness(item.wrap.sessions[0]) === "clean";
37
+ }
38
+
39
+ // What finishing looked like, in the same words the cards use [HIS-05, HIS-07].
40
+ function finishText(item: Item, now: Date): string {
41
+ if (item.change) return changeText(item.change, now);
42
+ const at = item.closedAt ?? item.othersActivityAt;
43
+ const age = `${ago(at, now)} ago`;
44
+ if (item.section === "reviewed") return `merged ${age}${item.mergedBy ? ` by ${item.mergedBy}` : ""}`;
45
+ if (item.closedUnmerged) return `closed ${age}, not merged`;
46
+ if (item.kind === "pr") return `merged ${age}${item.mergedBy ? ` by ${item.mergedBy}` : ""}`;
47
+ return `closed ${age}${item.closedBy ? ` by ${item.closedBy}` : ""}${item.notPlanned ? " as not planned" : ""}`;
48
+ }
49
+
50
+ // Remembers each open stack's and issue group's member keys under every member, so a member that merges or closes still
51
+ // knows its open siblings: History lists a merged PR alone, as its branches are gone [ATT-22, ATT-04]. Forgotten after
52
+ // keepDays.
53
+ export function rememberGroups(groups: RememberedGroups, items: Pick<Item, "key" | "children">[], now: Date, keepDays: number): RememberedGroups {
54
+ const at = now.toISOString();
55
+ const since = new Date(now.getTime() - keepDays * 86_400_000).toISOString();
56
+ const next = Object.fromEntries(Object.entries(groups).filter(([, group]) => group.at >= since));
57
+ for (const item of items) {
58
+ if (item.children.length === 0) continue;
59
+ const keys = [...keySet(memberKeys(item))];
60
+ for (const key of keys) next[key] = { keys, at };
61
+ }
62
+ return next;
63
+ }
64
+
65
+ // The finished work and changes that could appear in Wrap up: my done and reviewed items, my own unmerged closes, work that
66
+ // left my hands, and a change on finished work that History hasn't fetched yet [ATT-22, HIS-01, HIS-07]. A done item beats
67
+ // the note about it.
68
+ function candidates(view: WrapView): Item[] {
69
+ const seen = new Set<string>();
70
+ const ordered = [...view.history, ...(view.ownClosed ?? [])].sort((a, b) => Number(a.section === "changed") - Number(b.section === "changed"));
71
+ return ordered.filter((item) => {
72
+ // A reopened PR is open again, not work to wrap up.
73
+ if (item.section === "changed" && (!item.change || item.change.kind === "reopened")) return false;
74
+ const key = item.key.toLowerCase();
75
+ if (seen.has(key)) return false;
76
+ seen.add(key);
77
+ return true;
78
+ });
79
+ }
80
+
81
+ // What Wrap up reads from the view.
82
+ export type WrapView = Pick<AttentionView, "history" | "doing" | "waiting"> & Partial<Pick<AttentionView, "activeKeys" | "groups" | "ownClosed">>;
83
+
84
+ // What Doing's Wrap up shows, newest finish first. A row needs at least one open session, all idle. A stack or issue group
85
+ // enters once, and only when everything its sessions serve is done: a key still open in Doing or Waiting, or a remembered
86
+ // sibling of one, keeps the group out [ATT-22].
87
+ export function wrapItems(view: WrapView, agents: AgentSummary[], now = new Date()): WrapItem[] {
88
+ if (agents.length === 0) return [];
89
+ const active = keySet([...(view.activeKeys ?? []), ...[...view.doing.flatMap((section) => section.items), ...view.waiting.flatMap((group) => group.items)].flatMap(memberKeys)]);
90
+ const groups = view.groups ?? {};
91
+ const serving = (key: string) => [key.toLowerCase(), ...(groups[key.toLowerCase()] ?? [])].some((other) => active.has(other));
92
+ const rows: { item: WrapItem; at: string }[] = [];
93
+ const used = new Set<string>();
94
+ for (const item of candidates(view)) {
95
+ const keys = memberKeys(item);
96
+ const sessions = matchSessions(agents, keys);
97
+ if (sessions.length === 0) continue;
98
+ // The group's sessions must all be idle, none may serve work that's still active, and a session belongs to one row only.
99
+ if (sessions.some((agent) => !isIdle(agent) || serving(agent.itemKey) || used.has(agent.id)) || keys.some(serving)) continue;
100
+ for (const agent of sessions) used.add(agent.id);
101
+ rows.push({
102
+ item: {
103
+ ...item,
104
+ key: `wrap:${item.key}`,
105
+ section: "wrap",
106
+ actions: [],
107
+ chips: [],
108
+ wrap: { sessions, itemKey: item.key, keys, finish: finishText(item, now), ...(item.section === "reviewed" ? { review: true as const } : {}) },
109
+ },
110
+ at: item.closedAt ?? item.change?.at ?? item.othersActivityAt,
111
+ });
112
+ }
113
+ return rows.sort((a, b) => b.at.localeCompare(a.at)).map(({ item }) => item);
114
+ }
115
+
116
+ // The unread changes History shows: every note except the ones already in Wrap up, where archiving is the acknowledgement
117
+ // [HIS-07, ATT-22]. A note whose work has no session left, or whose sessions are busy, stays unread.
118
+ export function unreadChanges(notes: Item[], wrap: WrapItem[]): Item[] {
119
+ const inWrap = keySet(wrap.flatMap((item) => item.wrap.keys));
120
+ return notes.filter((note) => !memberKeys(note).some((key) => inWrap.has(key.toLowerCase())));
121
+ }
122
+
123
+ // Doing's and the sidebar's count: what needs me, plus the rows Wrap up asks me to clean up [ATT-09, ATT-22].
124
+ export function doingCount(view: Pick<AttentionView, "count">, wrap: WrapItem[]): number {
125
+ return view.count + wrap.length;
126
+ }