@andrioid/paseo-attention-span 0.5.0 → 0.6.1
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 +7 -1
- package/client/attention-screen.tsx +74 -1176
- package/client/coverage-settings.tsx +5 -4
- package/client/data.ts +4 -2
- package/client/feedback.tsx +21 -25
- package/client/history.tsx +17 -50
- package/client/item-actions.ts +363 -0
- package/client/item-row.tsx +450 -0
- package/client/new-issue.tsx +244 -0
- package/client/next-up.tsx +36 -183
- package/client/pickers.tsx +237 -0
- package/client/session-menu.ts +3 -11
- package/client/sessions.ts +58 -57
- package/client/setup.tsx +2 -1
- package/client/sheet.tsx +92 -15
- package/client/still.tsx +70 -27
- package/client/ui.tsx +23 -14
- package/client/wrap-up.tsx +151 -85
- package/docs/architecture.md +22 -11
- 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-next-up-setup.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/phone-dark-doing.png +0 -0
- package/docs/screenshots/phone-light-next-up-filtered.png +0 -0
- package/index.client.tsx +19 -0
- package/index.server.ts +43 -26
- package/package.json +3 -1
- package/requirements.yaml +11 -3
- package/server/actions.ts +2 -1
- package/server/archive.ts +146 -67
- package/server/archived.ts +12 -16
- package/server/changes.ts +34 -54
- package/server/classify.ts +142 -136
- package/server/feedback.ts +2 -6
- package/server/fetch.ts +262 -0
- package/server/fixture.ts +91 -7
- package/server/github-types.ts +3 -1
- package/server/markdown.ts +3 -1
- package/server/port.ts +46 -0
- package/server/queries.ts +33 -23
- package/server/service.ts +155 -272
- package/server/setup.ts +15 -14
- package/server/store.ts +94 -80
- package/server/update.ts +34 -13
- package/server/view.ts +16 -15
- package/shared/archive.ts +116 -13
- package/shared/attention.ts +50 -18
- package/shared/changes.ts +2 -1
- package/shared/config.ts +2 -6
- package/shared/drafting.ts +17 -0
- package/shared/feedback.ts +6 -5
- package/shared/format.ts +2 -1
- package/shared/history-report.ts +2 -1
- package/shared/item-sessions.ts +76 -0
- package/shared/item-view.ts +223 -0
- package/shared/linked-sessions.ts +59 -8
- package/shared/names.ts +17 -0
- package/shared/new-issue.ts +129 -0
- package/shared/next-up-filter.ts +137 -0
- package/shared/paging.ts +16 -0
- package/shared/rpc.ts +23 -10
- package/shared/setup.ts +3 -1
- package/shared/still.ts +28 -7
- package/shared/wrap-up.ts +20 -23
package/server/archive.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
2
2
|
import { execFile } from "node:child_process";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
|
-
import { isIdle } from "../shared/attention";
|
|
5
|
-
import type
|
|
4
|
+
import { busyWords, isIdle, subAgentBusy } from "../shared/attention";
|
|
5
|
+
import { type ArchiveResult, type KeptWorktree, type UnsavedSession, unsavedOf } from "../shared/archive";
|
|
6
|
+
import { subAgentsOf } from "../shared/linked-sessions";
|
|
7
|
+
import { listAll } from "./archived";
|
|
6
8
|
|
|
7
9
|
// Archiving finished work's sessions, safely [ATT-22]. Paseo's SDK has no restore, so an archive has no Undo here; instead
|
|
8
|
-
// nothing with unsaved work leaves without a confirmation. A
|
|
9
|
-
//
|
|
10
|
+
// nothing with unsaved work or open terminals leaves without a confirmation. A session's sub-agents go with it. A worktree
|
|
11
|
+
// goes only when no other session lives in it, through Paseo's own workspace archive, which archives everything in it; so
|
|
12
|
+
// every check here runs first. Which sessions to archive, and what that acknowledges, is the service's business.
|
|
10
13
|
|
|
11
14
|
const run = promisify(execFile);
|
|
12
15
|
|
|
13
|
-
// A session as Paseo's snapshot describes it; null where Paseo couldn't say.
|
|
16
|
+
// A session as Paseo's snapshot describes it; null where Paseo couldn't say. A worktree tried again on its own stands in as
|
|
17
|
+
// a session of its own, with no agent to archive.
|
|
14
18
|
export interface ArchiveSession {
|
|
15
19
|
agentId: string;
|
|
16
20
|
workspaceId: string | null;
|
|
@@ -18,6 +22,7 @@ export interface ArchiveSession {
|
|
|
18
22
|
branch?: string;
|
|
19
23
|
dirty: boolean | null;
|
|
20
24
|
ahead: number | null;
|
|
25
|
+
worktreeOnly?: true;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
type Paseo = PluginHandlerContext["paseo"];
|
|
@@ -26,17 +31,12 @@ type ListedWorkspace = Awaited<ReturnType<Paseo["workspaces"]["list"]>>["entries
|
|
|
26
31
|
|
|
27
32
|
const base = (session: ArchiveSession): UnsavedSession => ({ agentId: session.agentId, title: session.title, ...(session.branch ? { branch: session.branch } : {}) });
|
|
28
33
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
export function unsaved(session: ArchiveSession): UnsavedSession | null {
|
|
32
|
-
if (session.dirty === false && session.ahead === 0) return null;
|
|
33
|
-
if (session.dirty === null || session.ahead === null) return { ...base(session), unknown: true };
|
|
34
|
-
return { ...base(session), ...(session.ahead ? { commits: session.ahead } : {}) };
|
|
35
|
-
}
|
|
34
|
+
// A workspace as Paseo's sidebar names it [ATT-22].
|
|
35
|
+
const nameOf = (workspace: ListedWorkspace | undefined): string => workspace?.title ?? workspace?.gitRuntime?.currentBranch ?? workspace?.name ?? "its worktree";
|
|
36
36
|
|
|
37
|
-
// How many files are uncommitted and commits unpushed, from git itself, since Paseo's
|
|
38
|
-
// Commits are those ahead of the upstream, or, with no upstream, those no remote has.
|
|
39
|
-
// couldn't give makes the whole answer unknown, never zero [ATT-22].
|
|
37
|
+
// How many files are uncommitted, with the lines added and deleted, and commits unpushed, from git itself, since Paseo's
|
|
38
|
+
// snapshot counts neither and can lag. Commits are those ahead of the upstream, or, with no upstream, those no remote has.
|
|
39
|
+
// Clean needs both answers: one git couldn't give makes the whole answer unknown, never zero [ATT-22].
|
|
40
40
|
export async function gitUnsaved(session: ArchiveSession, directory: string): Promise<UnsavedSession> {
|
|
41
41
|
const git = (args: string[]) => run("git", ["-C", directory, ...args], { timeout: 5000 }).then(({ stdout }) => stdout);
|
|
42
42
|
const count = (args: string[]) =>
|
|
@@ -51,82 +51,161 @@ export async function gitUnsaved(session: ArchiveSession, directory: string): Pr
|
|
|
51
51
|
const commits = await count(["@{upstream}..HEAD"])
|
|
52
52
|
.catch(() => count(["HEAD", "--not", "--remotes"]))
|
|
53
53
|
.catch(() => undefined);
|
|
54
|
-
|
|
54
|
+
// "2 files changed, 12 insertions(+), 3 deletions(-)"; only a nicety, so a failure just leaves the lines out.
|
|
55
|
+
const lines = files
|
|
56
|
+
? await git(["diff", "--shortstat", "HEAD"])
|
|
57
|
+
.then((stdout) => ({ added: Number(/(\d+) insertion/.exec(stdout)?.[1] ?? 0), deleted: Number(/(\d+) deletion/.exec(stdout)?.[1] ?? 0) }))
|
|
58
|
+
.catch(() => null)
|
|
59
|
+
: null;
|
|
60
|
+
const known = {
|
|
61
|
+
...(files ? { files } : {}),
|
|
62
|
+
...(lines && (lines.added || lines.deleted) ? lines : {}),
|
|
63
|
+
...(commits ? { commits } : {}),
|
|
64
|
+
};
|
|
55
65
|
return files === undefined || commits === undefined ? { ...base(session), unknown: true, ...known } : { ...base(session), ...known };
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
// What archiving would lose in a session: git's answer where there's a directory to ask, else Paseo's. Null when clean.
|
|
59
69
|
async function unsavedWork(session: ArchiveSession, workspace: ListedWorkspace | undefined): Promise<UnsavedSession | null> {
|
|
60
70
|
const directory = workspace?.workspaceDirectory ?? workspace?.projectRootPath;
|
|
61
|
-
if (!directory) return
|
|
71
|
+
if (!directory) return unsavedOf(session, session);
|
|
62
72
|
const found = await gitUnsaved(session, directory);
|
|
63
73
|
return found.unknown || found.files || found.commits ? found : null;
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
// Archives the given sessions, and the worktree behind each when
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
// Archives the given sessions with their sub-agents, and the worktree behind each when no other session lives in it
|
|
77
|
+
// [ATT-22]. `worktrees` are kept worktrees tried again on their own. `confirm` is the sheet that named unsaved work and open
|
|
78
|
+
// terminals; `seen` are the terminals it named, the only ones archiving may close.
|
|
79
|
+
export async function archiveSessions(paseo: Paseo, agentIds: string[], confirm: boolean, seen: string[] = [], worktrees: string[] = []): Promise<ArchiveResult> {
|
|
80
|
+
// Every agent, archived ones too, on every page: a sub-agent under an archived one, or a session on a later page, counts.
|
|
81
|
+
const everyAgent = () => listAll(paseo, { filter: { includeArchived: true } });
|
|
82
|
+
const [agentList, workspaceList] = await Promise.all([everyAgent(), paseo.workspaces.list()]);
|
|
83
|
+
const agents = new Map(agentList.map((agent) => [agent.id, agent]));
|
|
71
84
|
const workspaces = new Map<string, ListedWorkspace>(workspaceList.entries.map((workspace) => [workspace.id, workspace]));
|
|
72
85
|
const wanted = [...new Set(agentIds)];
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
const sessionOf = (workspace: ListedWorkspace, fields: Pick<ArchiveSession, "agentId" | "title"> & { worktreeOnly?: true }): ArchiveSession => {
|
|
87
|
+
const git = workspace.gitRuntime;
|
|
88
|
+
return {
|
|
89
|
+
...fields,
|
|
90
|
+
workspaceId: workspace.id,
|
|
91
|
+
...(git?.currentBranch ? { branch: git.currentBranch } : {}),
|
|
92
|
+
dirty: git?.isDirty ?? null,
|
|
93
|
+
ahead: git?.aheadOfOrigin ?? null,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const sessions: ArchiveSession[] = [
|
|
97
|
+
...wanted.flatMap((id) => {
|
|
98
|
+
const agent = agents.get(id);
|
|
99
|
+
if (!agent) return [];
|
|
100
|
+
const workspace = agent.workspaceId ? workspaces.get(agent.workspaceId) : undefined;
|
|
101
|
+
const fields = { agentId: id, title: agent.title ?? null };
|
|
102
|
+
return [workspace ? sessionOf(workspace, fields) : { ...fields, workspaceId: agent.workspaceId ?? null, dirty: null, ahead: null }];
|
|
103
|
+
}),
|
|
104
|
+
...worktrees.flatMap((id) => {
|
|
105
|
+
const workspace = workspaces.get(id);
|
|
106
|
+
// One that's also a session's own is checked as that session's.
|
|
107
|
+
const own = wanted.some((agentId) => agents.get(agentId)?.workspaceId === id);
|
|
108
|
+
return workspace && !own ? [sessionOf(workspace, { agentId: `worktree:${id}`, title: nameOf(workspace), worktreeOnly: true })] : [];
|
|
109
|
+
}),
|
|
110
|
+
];
|
|
111
|
+
// A session, or one of its sub-agents, still busy stops the archive. A session that needs me counts as busy; a sub-agent
|
|
112
|
+
// while it runs or needs me, not once it's finished or failed (subAgentBusy).
|
|
113
|
+
const working = (all: ListedAgent[]) =>
|
|
114
|
+
all.find((agent) => wanted.includes(agent.id) && !agent.archivedAt && !isIdle(agent)) ?? subAgentsOf(all, wanted).find((agent) => !agent.archivedAt && subAgentBusy(agent));
|
|
115
|
+
const busy = working(agentList);
|
|
116
|
+
if (busy) return { ok: false, reason: "working", message: busyWords(busy) };
|
|
117
|
+
const unsaved = async () => {
|
|
118
|
+
const dirty = new Map<string, UnsavedSession>();
|
|
97
119
|
for (const session of sessions) {
|
|
98
120
|
const found = await unsavedWork(session, session.workspaceId ? workspaces.get(session.workspaceId) : undefined);
|
|
99
|
-
if (found) dirty.
|
|
121
|
+
if (found) dirty.set(session.agentId, found);
|
|
100
122
|
}
|
|
101
|
-
|
|
102
|
-
}
|
|
123
|
+
return dirty;
|
|
124
|
+
};
|
|
125
|
+
const dirty = confirm ? new Map<string, UnsavedSession>() : await unsaved();
|
|
103
126
|
|
|
104
127
|
// The checks above can take a while: look again right before archiving, so a session that started working, or a session
|
|
105
128
|
// that moved into one of these worktrees meanwhile, is seen [ATT-22].
|
|
106
|
-
const latest = await
|
|
107
|
-
const resumed = working(latest
|
|
108
|
-
if (resumed) return { ok: false, reason: "working", message:
|
|
129
|
+
const latest = await everyAgent();
|
|
130
|
+
const resumed = working(latest);
|
|
131
|
+
if (resumed) return { ok: false, reason: "working", message: busyWords(resumed, true) };
|
|
132
|
+
const subAgents = subAgentsOf(latest, wanted);
|
|
133
|
+
const ours = new Set([...wanted, ...subAgents.map((agent) => agent.id)]);
|
|
109
134
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
135
|
+
// Which worktrees go: Paseo's, with no unarchived session in them but these and their sub-agents. One that holds another
|
|
136
|
+
// session stays, saying which one kept it.
|
|
137
|
+
// Paseo closes a worktree's terminals when it goes, so the sheet names them first. Terminals that can't be listed don't
|
|
138
|
+
// keep it: Paseo would close them all the same.
|
|
139
|
+
const terminalsOf = (workspaceId: string) =>
|
|
140
|
+
paseo.terminals
|
|
141
|
+
.list({ workspaceId })
|
|
142
|
+
.then((result) => result.entries.map(({ id, name }) => ({ id, name })))
|
|
143
|
+
.catch(() => []);
|
|
144
|
+
const leaving: { workspace: ListedWorkspace; session: ArchiveSession; terminals: { id: string; name: string }[] }[] = [];
|
|
145
|
+
const kept: KeptWorktree[] = [];
|
|
146
|
+
const keep = (workspace: ListedWorkspace, fields: Omit<KeptWorktree, "workspaceId" | "name" | "sessionIds">) =>
|
|
147
|
+
kept.push({ workspaceId: workspace.id, name: nameOf(workspace), ...fields, sessionIds: wanted.filter((id) => agents.get(id)?.workspaceId === workspace.id) });
|
|
118
148
|
for (const workspaceId of new Set(sessions.flatMap((session) => (session.workspaceId ? [session.workspaceId] : [])))) {
|
|
119
149
|
const workspace = workspaces.get(workspaceId);
|
|
120
150
|
if (!workspace || workspace.workspaceKind !== "worktree") continue;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
151
|
+
const other = latest.find((agent) => agent.workspaceId === workspaceId && !agent.archivedAt && !ours.has(agent.id));
|
|
152
|
+
if (other) {
|
|
153
|
+
keep(workspace, { reason: "session", detail: other.title ?? "another session", agentId: other.id });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
leaving.push({ workspace, session: sessions.find((session) => session.workspaceId === workspaceId)!, terminals: await terminalsOf(workspaceId) });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Unsaved work, or a terminal the sheet didn't name, asks first; a terminal that opened after the sheet asks again, with
|
|
160
|
+
// whatever else is unsaved by then [ATT-22].
|
|
161
|
+
const unseen = leaving.some(({ terminals }) => terminals.some((terminal) => !seen.includes(terminal.id)));
|
|
162
|
+
if (dirty.size || unseen) {
|
|
163
|
+
const found = confirm ? await unsaved() : dirty;
|
|
164
|
+
for (const { session, terminals } of leaving) {
|
|
165
|
+
if (!terminals.length) continue;
|
|
166
|
+
found.set(session.agentId, { ...(found.get(session.agentId) ?? base(session)), terminals: terminals.map(({ name }) => name) });
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
ok: false,
|
|
170
|
+
reason: "unsaved",
|
|
171
|
+
sessions: sessions.flatMap((session) => found.get(session.agentId) ?? []),
|
|
172
|
+
terminals: leaving.flatMap(({ terminals }) => terminals.map(({ id }) => id)),
|
|
173
|
+
leaving: leaving.map(({ workspace }) => nameOf(workspace)),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Archive the sub-agents, deepest first, then the sessions; an already archived one counts as done. A sub-agent that
|
|
178
|
+
// wouldn't go and is still open stops the archive before its session goes, so nothing is acknowledged with it left open.
|
|
179
|
+
const failed: { agent: ListedAgent; message: string }[] = [];
|
|
180
|
+
for (const agent of [...subAgents].reverse()) {
|
|
181
|
+
await paseo.agents
|
|
182
|
+
.ref(agent.id)
|
|
183
|
+
.archive()
|
|
184
|
+
.catch((error: Error) => failed.push({ agent, message: error.message }));
|
|
185
|
+
}
|
|
186
|
+
if (failed.length) {
|
|
187
|
+
const open = new Set((await everyAgent()).filter((agent) => !agent.archivedAt).map((agent) => agent.id));
|
|
188
|
+
const stuck = failed.find(({ agent }) => open.has(agent.id));
|
|
189
|
+
if (stuck) throw new Error(`Couldn't archive ${stuck.agent.title ?? "a sub-agent"}: ${stuck.message}`);
|
|
190
|
+
}
|
|
191
|
+
for (const session of sessions) {
|
|
192
|
+
if (session.worktreeOnly || agents.get(session.agentId)?.archivedAt) continue;
|
|
193
|
+
await paseo.agents.ref(session.agentId).archive();
|
|
194
|
+
}
|
|
195
|
+
// The sessions are put away either way; a worktree that wouldn't go stays, saying why. Its terminals are listed once more
|
|
196
|
+
// right before it goes: one that opened while the sessions were archived wasn't on the sheet, so the worktree stays.
|
|
197
|
+
for (const { workspace } of leaving) {
|
|
198
|
+
const late = (await terminalsOf(workspace.id)).filter((terminal) => !seen.includes(terminal.id));
|
|
199
|
+
if (late.length) {
|
|
200
|
+
keep(workspace, { reason: "terminal", detail: late.map(({ name }) => name).join(", ") });
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
125
203
|
const failed = await paseo.workspaces
|
|
126
|
-
.archive(
|
|
204
|
+
.archive(workspace.id)
|
|
127
205
|
.then((result) => (result.error ? String(result.error) : null))
|
|
128
206
|
.catch((error: Error) => error.message);
|
|
129
|
-
if (failed)
|
|
207
|
+
if (failed) keep(workspace, { reason: "refused", detail: failed });
|
|
130
208
|
}
|
|
131
|
-
return
|
|
209
|
+
return { ok: true, kept };
|
|
132
210
|
}
|
|
211
|
+
|
package/server/archived.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
2
|
+
import { keySet } from "../shared/names";
|
|
3
|
+
import { SESSION_LABELS } from "../shared/item-sessions";
|
|
4
|
+
import { everyPage } from "../shared/paging";
|
|
2
5
|
|
|
3
6
|
// A session Attention Span started, archived in Paseo itself: once no session it started is left open on any part of the
|
|
4
7
|
// item's stack or issue group, what others did to that work up to the archive is acknowledged, so it doesn't come back as
|
|
@@ -11,7 +14,7 @@ type ListedAgent = Awaited<ReturnType<Paseo["agents"]["list"]>>["entries"][numbe
|
|
|
11
14
|
type ListOptions = NonNullable<Parameters<Paseo["agents"]["list"]>[0]>;
|
|
12
15
|
|
|
13
16
|
// The markers and item labels of sessions Attention Span started, under its current and earlier names [ATT-07, SES-03].
|
|
14
|
-
const MARKERS =
|
|
17
|
+
const MARKERS = SESSION_LABELS;
|
|
15
18
|
const ITEM_LABELS = MARKERS.map((marker) => `${marker}-item`);
|
|
16
19
|
// Agents another agent started belong to that agent's session.
|
|
17
20
|
const PARENT_AGENT_LABEL = "paseo.parent-agent-id";
|
|
@@ -25,13 +28,13 @@ export interface ArchiveEvent {
|
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
// What Paseo says of the archived session now; null when it couldn't be found.
|
|
28
|
-
|
|
31
|
+
type FoundSession = Pick<ListedAgent, "labels" | "archivedAt"> | null;
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
const itemKeyOf = (labels: Record<string, string> | undefined | null): string | undefined =>
|
|
31
34
|
ITEM_LABELS.map((label) => labels?.[label]).find(Boolean);
|
|
32
35
|
|
|
33
36
|
// The item whose notes the archive may acknowledge; "drop" when it acknowledges nothing, "wait" when it can't tell yet.
|
|
34
|
-
|
|
37
|
+
function archivedItem(event: ArchiveEvent, found: FoundSession): { itemKey: string } | "drop" | "wait" {
|
|
35
38
|
if (event.parentAgentId) return "drop";
|
|
36
39
|
if (!found) return "wait";
|
|
37
40
|
if (found.labels?.[PARENT_AGENT_LABEL]) return "drop";
|
|
@@ -43,8 +46,8 @@ export function archivedItem(event: ArchiveEvent, found: FoundSession): { itemKe
|
|
|
43
46
|
|
|
44
47
|
// Whether an open session Attention Span started is on any of the keys, which are compared ignoring case. The archived
|
|
45
48
|
// session itself counts too: if it's listed open, it was restored while this was being decided.
|
|
46
|
-
|
|
47
|
-
const wanted =
|
|
49
|
+
function stillOpen(keys: string[], open: Pick<ListedAgent, "labels" | "archivedAt">[]): boolean {
|
|
50
|
+
const wanted = keySet(keys);
|
|
48
51
|
return open.some((agent) => {
|
|
49
52
|
if (agent.archivedAt) return false;
|
|
50
53
|
const itemKey = itemKeyOf(agent.labels);
|
|
@@ -53,15 +56,8 @@ export function stillOpen(keys: string[], open: Pick<ListedAgent, "labels" | "ar
|
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
// Every page of a list; a failed page fails the whole list, so it's never mistaken for an empty one.
|
|
56
|
-
async function listAll(paseo: Paseo, options: ListOptions): Promise<ListedAgent[]> {
|
|
57
|
-
|
|
58
|
-
let cursor: string | undefined;
|
|
59
|
-
for (;;) {
|
|
60
|
-
const result = await paseo.agents.list({ ...options, page: { limit: 200, ...(cursor ? { cursor } : {}) } });
|
|
61
|
-
agents.push(...result.entries.map((entry) => entry.agent));
|
|
62
|
-
if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) return agents;
|
|
63
|
-
cursor = result.pageInfo.nextCursor;
|
|
64
|
-
}
|
|
59
|
+
export async function listAll(paseo: Paseo, options: ListOptions): Promise<ListedAgent[]> {
|
|
60
|
+
return (await everyPage((page) => paseo.agents.list({ ...options, page }))).map((entry) => entry.agent);
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
// The archived session as Paseo has it now: its own snapshot, or else the list with archived sessions in it.
|
|
@@ -71,7 +67,7 @@ async function findSession(paseo: Paseo, agentId: string): Promise<FoundSession>
|
|
|
71
67
|
return (await listAll(paseo, { filter: { includeArchived: true } })).find((agent) => agent.id === agentId) ?? null;
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
interface ArchiveDeps {
|
|
75
71
|
groupKeysOf(itemKey: string): string[];
|
|
76
72
|
acknowledge(keys: string[], upTo: string): Promise<unknown>;
|
|
77
73
|
}
|
package/server/changes.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isFinishedChange, isHandover, type OthersChange } from "../shared/changes";
|
|
2
|
-
import type
|
|
2
|
+
import { baseItem, type Item, type SectionId } from "../shared/attention";
|
|
3
3
|
import type { AssignmentEvent, AssignmentSubject, ClosedIssue, EndedPullRequest, LiveResult, ReopenSubject } from "./github-types";
|
|
4
4
|
import { prKey } from "./queries";
|
|
5
|
+
import { keySet, sameName } from "../shared/names";
|
|
5
6
|
|
|
6
7
|
// Changed by others: what someone else did to my work, kept between refreshes so a note stays until Got it or an archive
|
|
7
8
|
// acknowledges it, and so History can list work that left my hands [HIS-06, HIS-07, ATT-22]. Pure, so every rule is
|
|
@@ -38,13 +39,12 @@ export type Lookups = Map<string, AssignmentSubject | null>;
|
|
|
38
39
|
// Reopen lookups: the PR as it is now, null when it's gone or hidden, missing when the lookup failed.
|
|
39
40
|
export type ReopenLookups = Map<string, ReopenSubject | null>;
|
|
40
41
|
|
|
41
|
-
const same = (a: string | null | undefined, b: string | null | undefined) => !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
42
42
|
const present = <T>(nodes: (T | null | undefined)[]) => nodes.filter((node): node is T => !!node && Object.keys(node).length > 0);
|
|
43
43
|
const logins = (subject: { assignees: { nodes: { login: string }[] } }) => subject.assignees.nodes.map((node) => node.login);
|
|
44
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
45
|
const handedOver = (subject: { assignees: { nodes: { login: string }[] } }, me: string) => {
|
|
46
46
|
const assignees = logins(subject);
|
|
47
|
-
return assignees.length > 0 && !assignees.some((login) =>
|
|
47
|
+
return assignees.length > 0 && !assignees.some((login) => sameName(login, me));
|
|
48
48
|
};
|
|
49
49
|
const signature = (subject: { assignees: { nodes: { login: string }[] } }) =>
|
|
50
50
|
logins(subject)
|
|
@@ -88,72 +88,64 @@ const isAssignment = (node: AssignmentEvent | Record<string, never>): node is As
|
|
|
88
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
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
90
|
// "dave handed it to carol". So a PR I unassigned myself from is still mine until someone else takes it.
|
|
91
|
-
|
|
91
|
+
function handover(subject: AssignmentSubject, me: string): OthersChange | null {
|
|
92
92
|
const assignees = logins(subject);
|
|
93
|
-
if (assignees.some((login) =>
|
|
93
|
+
if (assignees.some((login) => sameName(login, me))) return null;
|
|
94
94
|
if (subject.__typename === "Issue" && subject.state !== "OPEN") return null;
|
|
95
95
|
const events = present(subject.timelineItems.nodes)
|
|
96
96
|
.filter(isAssignment)
|
|
97
97
|
.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
98
|
-
const removal = events.findLast((event) => event.__typename === "UnassignedEvent" &&
|
|
99
|
-
const given = events.findLast((event) => event.__typename === "AssignedEvent" && assignees.some((login) =>
|
|
98
|
+
const removal = events.findLast((event) => event.__typename === "UnassignedEvent" && sameName(event.assignee?.login, me));
|
|
99
|
+
const given = events.findLast((event) => event.__typename === "AssignedEvent" && assignees.some((login) => sameName(login, event.assignee?.login)));
|
|
100
100
|
const to = given?.assignee?.login ?? assignees[0];
|
|
101
101
|
// A PR of mine with nobody on it is mine; an issue needs proof I was taken off it.
|
|
102
102
|
if (subject.__typename === "PullRequest" ? !to : !removal) return null;
|
|
103
103
|
const by = removal && given && to ? (given.createdAt > removal.createdAt ? given : removal) : (removal ?? given);
|
|
104
|
-
if (!by ||
|
|
104
|
+
if (!by || sameName(by.actor?.login, me)) return null;
|
|
105
105
|
const actor = by.actor?.login;
|
|
106
|
-
const kind = !to ? "unassigned" :
|
|
106
|
+
const kind = !to ? "unassigned" : sameName(actor, to) ? "took_over" : "handed";
|
|
107
107
|
return change(subject, subject.__typename === "PullRequest" ? "pr" : "issue", kind, by.createdAt, actor, to);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
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
111
|
// which knows when that happened.
|
|
112
|
-
|
|
113
|
-
if (pr.merged) return
|
|
112
|
+
function ended(pr: EndedPullRequest, me: string): OthersChange | null {
|
|
113
|
+
if (pr.merged) return sameName(pr.mergedBy?.login, me) || !pr.mergedAt ? null : change(pr, "pr", "merged", pr.mergedAt, pr.mergedBy?.login);
|
|
114
114
|
const closer = pr.timelineItems.nodes.at(-1)?.actor?.login;
|
|
115
|
-
return
|
|
115
|
+
return sameName(closer, me) ? null : change(pr, "pr", "closed", pr.closedAt, closer);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
// My PRs
|
|
119
|
-
// and no week lists
|
|
118
|
+
// My PRs that ended lately, from the closed search, as finished work whose sessions Wrap up puts away [ATT-22]: those I
|
|
119
|
+
// closed without merging, which no note and no week lists, and merged ones, which stand in for History's entry until its
|
|
120
|
+
// next fetch has them [FRESH-03]. A merge by someone else says who.
|
|
120
121
|
export function ownClosed(data: Pick<LiveResult, "ended">, me: string): Item[] {
|
|
121
122
|
return present(data.ended.nodes)
|
|
122
|
-
.filter((pr) =>
|
|
123
|
-
.map((pr) =>
|
|
124
|
-
key: prKey(pr),
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
}));
|
|
123
|
+
.filter((pr) => pr.merged || sameName(pr.timelineItems.nodes.at(-1)?.actor?.login, me))
|
|
124
|
+
.map((pr) => {
|
|
125
|
+
const item = baseItem({ key: prKey(pr), section: "done", kind: "pr", repo: pr.repository.nameWithOwner, number: pr.number, title: pr.title, url: pr.url }, pr.closedAt);
|
|
126
|
+
// Its branch, so a session left on it finds its row in Wrap up [ATT-22].
|
|
127
|
+
const target = { ...item.target, ...(pr.headRefName ? { headRefName: pr.headRefName } : {}) };
|
|
128
|
+
if (!pr.merged) return { ...item, target, closedAt: pr.closedAt, closedUnmerged: true as const };
|
|
129
|
+
const by = pr.mergedBy?.login;
|
|
130
|
+
return { ...item, target, closedAt: pr.mergedAt ?? pr.closedAt, ...(by && !sameName(by, me) ? { mergedBy: by } : {}) };
|
|
131
|
+
});
|
|
140
132
|
}
|
|
141
133
|
|
|
142
134
|
// An issue assigned to me someone else closed, as completed or not planned [HIS-07]. My own closes are mine.
|
|
143
|
-
|
|
135
|
+
function closedByOther(issue: ClosedIssue, me: string): OthersChange | null {
|
|
144
136
|
const closer = issue.timelineItems.nodes.at(-1)?.actor?.login;
|
|
145
|
-
if (
|
|
137
|
+
if (sameName(closer, me)) return null;
|
|
146
138
|
const reason = issue.stateReason === "NOT_PLANNED" ? "not_planned" : issue.stateReason === "COMPLETED" ? "completed" : undefined;
|
|
147
139
|
return { ...change(issue, "issue", "issue_closed", issue.closedAt, closer), ...(reason ? { reason } : {}) };
|
|
148
140
|
}
|
|
149
141
|
|
|
150
142
|
// A PR Attention Span saw closed, now open again by someone else [HIS-07]. Only PRs already tracked count, so a first run
|
|
151
143
|
// doesn't announce every old reopen, and issues don't come here: they surface in Next up.
|
|
152
|
-
|
|
144
|
+
function reopened(tracked: TrackedPr, subject: ReopenSubject, me: string): OthersChange | null {
|
|
153
145
|
if (subject.state !== "OPEN") return null;
|
|
154
146
|
const event = subject.timelineItems.nodes.at(-1);
|
|
155
147
|
const actor = event?.actor?.login;
|
|
156
|
-
if (!actor ||
|
|
148
|
+
if (!actor || sameName(actor, me)) return null;
|
|
157
149
|
return {
|
|
158
150
|
id: `reopened:${subject.id}:${event?.createdAt ?? tracked.closedAt}`,
|
|
159
151
|
kind: "reopened",
|
|
@@ -289,7 +281,7 @@ export function nextLedger(
|
|
|
289
281
|
// An archive acknowledges exactly the events on its work at that moment, keyed by "owner/name#number" [ATT-22].
|
|
290
282
|
// `upTo` keeps what others did after then unread: a session archived in Paseo acknowledges only what came before it.
|
|
291
283
|
export function acknowledge(ledger: ChangeLedger, keys: string[], upTo?: string): ChangeLedger {
|
|
292
|
-
const wanted =
|
|
284
|
+
const wanted = keySet(keys);
|
|
293
285
|
const before = (at: string) => !upTo || Date.parse(at) <= Date.parse(upTo);
|
|
294
286
|
const ids = ledger.events.filter((event) => wanted.has(event.key.toLowerCase()) && before(event.at)).map((event) => event.id);
|
|
295
287
|
return { ...ledger, gotIt: [...new Set([...ledger.gotIt, ...ids])] };
|
|
@@ -308,36 +300,24 @@ export function withGotIt(next: ChangeLedger, gotIt: string[]): ChangeLedger {
|
|
|
308
300
|
export function changeItems(ledger: ChangeLedger, now: Date, windowDays: number, historySince: string): { notes: Item[]; history: Item[]; finished: Item[] } {
|
|
309
301
|
const since = new Date(now.getTime() - windowDays * 86_400_000).toISOString();
|
|
310
302
|
const gotIt = new Set(ledger.gotIt);
|
|
311
|
-
const base = (change: OthersChange
|
|
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,
|
|
303
|
+
const base = (change: OthersChange, key: string, section: SectionId): Item => ({
|
|
304
|
+
...baseItem({ key, section, kind: change.subject, repo: change.repo, number: change.number, title: change.title, url: change.url }, change.at),
|
|
323
305
|
closedAt: change.at,
|
|
324
306
|
change,
|
|
325
307
|
});
|
|
326
308
|
const notes = ledger.events
|
|
327
309
|
.filter((change) => !gotIt.has(change.id) && change.at >= since)
|
|
328
|
-
.map((change): Item => ({ ...base(change
|
|
310
|
+
.map((change): Item => ({ ...base(change, `change:${change.id}`, "changed"), actions: ["got_it"] }));
|
|
329
311
|
const history = ledger.events
|
|
330
312
|
// A merge or an issue close is the week's Finished, not a change repeated under it [HIS-07].
|
|
331
313
|
.filter((change) => gotIt.has(change.id) && !isFinishedChange(change) && change.at >= historySince)
|
|
332
|
-
.map((change)
|
|
314
|
+
.map((change) => base(change, `handed:${change.id}`, "handed_off"));
|
|
333
315
|
// A merge or close someone else did is finished work at once, not only when History's daily fetch catches up [HIS-07].
|
|
334
316
|
const finished = ledger.events
|
|
335
317
|
.filter((change) => isFinishedChange(change) && change.at >= historySince)
|
|
336
318
|
.map(
|
|
337
319
|
(change): Item => ({
|
|
338
|
-
...base(change),
|
|
339
|
-
key: change.key,
|
|
340
|
-
section: "done",
|
|
320
|
+
...base(change, change.key, "done"),
|
|
341
321
|
// The week's cards say it in the finished wording, not the note's: "merged 2h ago by dave" [HIS-05, HIS-07].
|
|
342
322
|
change: undefined,
|
|
343
323
|
...(change.kind === "merged" && change.actor ? { mergedBy: change.actor } : {}),
|