@andrioid/paseo-attention-span 0.2.1 → 0.3.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 +11 -7
- package/client/attention-screen.tsx +182 -79
- package/client/card.tsx +5 -15
- package/client/coverage-settings.tsx +35 -4
- package/client/feedback.tsx +173 -0
- package/client/host.ts +8 -0
- package/client/icons.ts +3 -2
- package/client/next-up.tsx +29 -45
- package/client/session-menu.ts +18 -26
- package/client/sessions.ts +5 -2
- package/client/sheet.tsx +17 -72
- package/client/ui.tsx +0 -49
- package/docs/architecture.md +188 -0
- package/docs/screenshots/desktop-dark-doing-acknowledge.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-too-long.png +0 -0
- package/docs/screenshots/desktop-dark-doing.png +0 -0
- package/docs/screenshots/desktop-dark-history-reviewed.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-light-next-up-filtered.png +0 -0
- package/index.client.tsx +17 -6
- package/index.server.ts +28 -2
- package/package.json +5 -2
- package/requirements.yaml +128 -0
- package/server/actions.ts +31 -1
- package/server/classify.ts +150 -52
- package/server/feedback.ts +53 -0
- package/server/fixture.ts +48 -16
- package/server/github-types.ts +15 -2
- package/server/queries.ts +15 -4
- package/server/rules.ts +119 -0
- package/server/service.ts +15 -3
- package/server/setup.ts +3 -3
- package/server/store.ts +5 -0
- package/shared/attention.ts +36 -2
- package/shared/config.ts +3 -0
- package/shared/feedback.ts +92 -0
- package/shared/rpc.ts +12 -1
- package/shared/setup.ts +2 -0
- package/docs/screenshots/desktop-dark-doing-session-menu.png +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# requirements-yaml — one line per requirement, edit by hand.
|
|
2
|
+
# line: <ID>: observable capability; so that value.
|
|
3
|
+
# groups: functional(area -> "As a <role>, I can:" -> ID) · non_functional & domain sections(group -> ID) · deferred(area -> "[deferred] ID")
|
|
4
|
+
# ids: PREFIX-NN, uppercase, stable, never reused.
|
|
5
|
+
# docs: optional map (kept at the file's end) of <filename> -> description of what it is and when to read it.
|
|
6
|
+
# goals/non_goals: optional lists, kept first, set only by the human — one distilled line each, not requirements: no IDs, no clauses.
|
|
7
|
+
# roles: optional map (kept before functional) of <role> -> who they are; names match the "As a <role>" headings.
|
|
8
|
+
# yaml-language-server: $schema=./requirements.schema.json
|
|
9
|
+
goals:
|
|
10
|
+
- stay in the flow with github and paseo
|
|
11
|
+
functional:
|
|
12
|
+
sources:
|
|
13
|
+
As a developer, I can:
|
|
14
|
+
SRC-01: choose which GitHub organizations and repositories Attention Span covers; so that it works for any project.
|
|
15
|
+
SRC-02: choose those organizations and repositories in the app, each checked on GitHub as I add it; so that I don't edit files on the daemon's machine and a typo shows right away.
|
|
16
|
+
setup:
|
|
17
|
+
As a developer, I can:
|
|
18
|
+
SET-01: see what's missing and how to fix it when Attention Span can't load, along with what it covers and which projects and agent it will use; so that getting started doesn't end at an error.
|
|
19
|
+
attention:
|
|
20
|
+
As a developer, I can:
|
|
21
|
+
ATT-01: see in one place the open issues and pull requests that need me; so that I don't depend on noisy GitHub notifications.
|
|
22
|
+
ATT-02: see why each item needs me, with items grouped by that reason; so that I know what to do about an item at a glance.
|
|
23
|
+
ATT-03: see an issue and the pull requests that resolve it as one item, led by the issue; so that related work isn't scattered across the list.
|
|
24
|
+
ATT-04: see a stack of dependent pull requests as one item; so that a stack is handled as the single change it is.
|
|
25
|
+
ATT-05: judge an item from the list without opening it; so that triage is quick and I'm not visually overloaded.
|
|
26
|
+
ATT-06: open an item for more detail and every action, each saying what it will do; so that the list stays minimal by default and pressing a button makes sense.
|
|
27
|
+
ATT-07: see whether an item already has a Paseo session and what its agent is doing; so that I don't start duplicate work.
|
|
28
|
+
ATT-08: dismiss an item until something new happens on it; so that FYIs stop taking up space.
|
|
29
|
+
ATT-09: notice how many items need me from anywhere in Paseo; so that I don't have to open Attention Span to check.
|
|
30
|
+
ATT-11: see work that has waited on others for too long, and on my own issues however long ago that was; so that stalled work gets nudged.
|
|
31
|
+
ATT-12: open any item on GitHub; so that I can do what Attention Span doesn't cover.
|
|
32
|
+
ATT-13: tell at a glance which actions start an agent session and which change GitHub right away; so that I know what a tap will do.
|
|
33
|
+
ATT-14: undo a change on GitHub right after making it, where GitHub allows; so that a mis-tap costs nothing without confirming every action.
|
|
34
|
+
ATT-15: copy any item's GitHub link; so that I can share it without opening GitHub.
|
|
35
|
+
ATT-16: see recent comments without a mention on issues and pull requests I opened, until I reply, react or dismiss them; so that answers to my questions don't get lost, while other people's threads stay out unless someone tags me.
|
|
36
|
+
ATT-17: choose to follow threads I've commented on, so recent replies after mine there show without a tag, off by default; so that surfacing other people's threads is my choice, and the list stays signal, not noise.
|
|
37
|
+
mentions:
|
|
38
|
+
As a developer, I can:
|
|
39
|
+
MEN-01: see open threads where a person mentioned me and is still waiting for my response; so that I only hear about mentions when someone is waiting for me.
|
|
40
|
+
MEN-02: clear a mention, or an answer to my question, by either replying or reacting; so that acknowledging is enough.
|
|
41
|
+
MEN-03: see mentions in other people's drafts; so that I can respond when someone asks me for an early look.
|
|
42
|
+
MEN-04: have mentions of my teams left out; so that only mentions aimed at me personally count.
|
|
43
|
+
MEN-05: see threads a bot opened that I need to resolve; so that bot findings that need me are included.
|
|
44
|
+
MEN-06: tell at a glance when a bot is the one waiting; so that bots are highlighted.
|
|
45
|
+
MEN-07: react 👍 to the comments waiting on me from Attention Span, after reading them in full and picking which; so that acknowledging doesn't need a trip to GitHub.
|
|
46
|
+
reviews:
|
|
47
|
+
As a developer, I can:
|
|
48
|
+
REV-01: see pull requests where my review is requested by name; so that I don't hold up others.
|
|
49
|
+
own_pull_requests:
|
|
50
|
+
As a developer, I can:
|
|
51
|
+
PRS-01: see my pull requests whose checks fail; so that I fix them before they block review or merge.
|
|
52
|
+
PRS-02: see my pull requests with requested changes or unresolved review comments; so that I finish ongoing work, since I can only handle so many tasks at once.
|
|
53
|
+
PRS-03: see my pull requests that are ready to merge; so that finished work ships.
|
|
54
|
+
PRS-04: merge a ready pull request once its checks pass against its current base; so that what merges was tested against what it merges into.
|
|
55
|
+
PRS-05: see my drafts after everything that isn't a draft; so that I finish or close my drafts before picking up new work.
|
|
56
|
+
PRS-06: see only my own drafts as work items; so that other people's unfinished work stays out of my list.
|
|
57
|
+
PRS-07: refresh or close a draft that has gone stale; so that old drafts don't linger.
|
|
58
|
+
PRS-08: have my pull requests that are assigned to someone else left out; so that pull requests I've handed over don't count as mine.
|
|
59
|
+
PRS-09: rerun the failed checks of a pull request without an agent, after seeing which failed and whether they were rerun before; so that flaky checks don't cost a session.
|
|
60
|
+
PRS-10: turn on auto-merge for an approved pull request whose checks are still running; so that it ships without me waiting for CI.
|
|
61
|
+
PRS-11: mark a healthy draft ready for review and pick its reviewers in one step; so that finished drafts reach reviewers.
|
|
62
|
+
PRS-12: see my pull requests that nobody has been asked to review, and ask people or teams from there, or merge where nobody reviews; so that work doesn't sit as "waiting" when nobody has the next move.
|
|
63
|
+
upstream:
|
|
64
|
+
As a developer, I can:
|
|
65
|
+
UPS-01: see my pull requests that conflict with their base; so that pull requests needing updates from upstream are easy to fix.
|
|
66
|
+
UPS-02: see when a pull request in a stack no longer builds on its parent's latest version; so that pull requests needing updates from upstream are easy to fix.
|
|
67
|
+
UPS-03: bring a conflict-free pull request up to date with its base in one step; so that pull requests needing updates from upstream are easy to fix.
|
|
68
|
+
UPS-04: have an agent bring a pull request or a whole stack up to date, resolving conflicts; so that pull requests needing updates from upstream are easy to fix.
|
|
69
|
+
UPS-05: approve an agent's conflict resolution before it is pushed; so that I stay in control of changes I didn't write.
|
|
70
|
+
UPS-06: have an update without conflicts pushed without waiting for me; so that routine updates take no attention.
|
|
71
|
+
UPS-07: see that a pull request is behind its base only when that blocks or risks its merge; so that the list isn't flooded by a base that moves every day.
|
|
72
|
+
sessions:
|
|
73
|
+
As a developer, I can:
|
|
74
|
+
SES-01: start a Paseo session for an item in one step, with defaults suited to why it needs me; so that acting on an item takes no setup.
|
|
75
|
+
SES-02: choose the workspace, agent profile, and prompt before a session starts; so that I can adjust when the defaults don't fit.
|
|
76
|
+
SES-03: open an item's existing session from the item whatever state it is in, including one started on any of its pull requests, and start another only on purpose; so that work on an item stays in one place.
|
|
77
|
+
SES-04: start a session that already has the item's context, such as failing checks or unresolved comments; so that the agent starts informed.
|
|
78
|
+
SES-05: start sessions in my local checkout of the item's repository without configuring paths; so that new repositories work without setup.
|
|
79
|
+
SES-06: start sessions even when no agent profiles are configured; so that Attention Span works before I've set anything up.
|
|
80
|
+
SES-07: start a session on an issue in the repository its code lives in, chosen right there the first time; so that issues kept in a separate repository work without editing files.
|
|
81
|
+
next_up:
|
|
82
|
+
As a developer, I can:
|
|
83
|
+
NXT-01: see open issues nobody is assigned to, apart from the work that needs me; so that I can get an idea of what to do next.
|
|
84
|
+
NXT-02: see unclaimed issues ordered by priority, then effort, then age; so that the most important quick wins come first.
|
|
85
|
+
NXT-03: filter unclaimed issues by scope, and have my choice remembered; so that I only see work I'd pick up.
|
|
86
|
+
NXT-04: choose in the app where unclaimed issues come from (my own repositories, organizations I belong to, or single repositories) and choose which issue fields the list uses; so that the plugin can be used elsewhere without editing files.
|
|
87
|
+
NXT-05: claim an issue and start a session on it in one step; so that teammates see it's taken and I can start right away.
|
|
88
|
+
NXT-06: see issues assigned to me before unclaimed ones; so that I finish what I've taken before picking more.
|
|
89
|
+
NXT-07: claim an issue without starting a session, and give back one assigned to me; so that what I've taken matches what I'll do.
|
|
90
|
+
NXT-08: see unclaimed issues from the repositories of my Paseo projects when I haven't chosen any; so that Next up is useful without setup and never fills with strangers' issues.
|
|
91
|
+
NXT-09: filter unclaimed issues by where they came from, and have my choice remembered; so that I can focus on one source at a time.
|
|
92
|
+
NXT-10: see on each issue its repository, priority, effort and scope at a glance, and whether an open pull request already closes it and by whom; so that I can judge whether to pick it up without opening it.
|
|
93
|
+
NXT-11: close an issue from Next up as completed or not planned, with an optional comment, and undo it; so that work that's done or won't be done stops being suggested.
|
|
94
|
+
waiting:
|
|
95
|
+
As a developer, I can:
|
|
96
|
+
WAI-01: see my work that is waiting on others, grouped by what it waits for, where a pull request waits for review only once someone has been asked; so that I know that work is tracked.
|
|
97
|
+
history:
|
|
98
|
+
As a developer, I can:
|
|
99
|
+
HIS-01: see the issues and pull requests I finished, grouped by week; so that I can tell others what I got done.
|
|
100
|
+
HIS-02: see pull requests I reviewed that merged, apart from my own work; so that I can tell others what I got done.
|
|
101
|
+
HIS-03: copy a week's finished work as a Markdown list of links; so that reporting progress is one paste.
|
|
102
|
+
feedback:
|
|
103
|
+
As a developer, I can:
|
|
104
|
+
FB-01: tell the Attention Span project what to improve from the bottom of any tab, picking a problem, an idea or that I like it, with an agent that asks until it's clear, checks it against what's planned and already reported, and files it as an issue or a discussion, saying which and why, only once I approve the draft; so that feedback costs a minute and lands where it can be acted on or talked through.
|
|
105
|
+
|
|
106
|
+
non_functional:
|
|
107
|
+
github_usage:
|
|
108
|
+
GH-01: keeps its load on GitHub's API light; so that we don't bombard GitHub's API.
|
|
109
|
+
safety:
|
|
110
|
+
SAFE-01: changes nothing on GitHub unless I asked for that change; so that nothing is published in my name by surprise.
|
|
111
|
+
security:
|
|
112
|
+
SEC-01: uses the GitHub sign-in already on its host and stores no GitHub credentials of its own; so that there is no extra secret to protect.
|
|
113
|
+
privacy:
|
|
114
|
+
PRIV-01: may keep a local copy of the GitHub data it shows; so that Attention Span shows instantly after a restart.
|
|
115
|
+
reach:
|
|
116
|
+
REACH-01: works in Paseo on both phone and desktop; so that I can triage from anywhere.
|
|
117
|
+
REACH-02: names its host in the sidebar and in settings when Paseo knows more than one host; so that I can tell which host's list and config.json I'm looking at.
|
|
118
|
+
freshness:
|
|
119
|
+
FRESH-01: stays current without me refreshing it; so that its count can be trusted.
|
|
120
|
+
FRESH-02: shows what I just did on GitHub right away, and keeps showing it until GitHub's search catches up; so that I never refresh to see it.
|
|
121
|
+
|
|
122
|
+
deferred:
|
|
123
|
+
feedback:
|
|
124
|
+
"[deferred] FB-02": see replies to discussions I started, the way I see replies on my own issues; so that an answer in a discussion doesn't get lost.
|
|
125
|
+
|
|
126
|
+
docs:
|
|
127
|
+
CONTRIBUTING.md: how to check, preview the screens in isolation, and install — read before changing UI or tooling.
|
|
128
|
+
docs/architecture.md: how Attention Span meets these requirements (sections, rules, actions, GitHub requests) — read before changing behaviour or adding a requirement.
|
package/server/actions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IssueCloseReason, Target } from "../shared/attention";
|
|
1
|
+
import type { IssueCloseReason, Reviewer, ReviewerChoices, Target } from "../shared/attention";
|
|
2
2
|
import { graphql, runGh } from "./gh";
|
|
3
3
|
|
|
4
4
|
// Each action runs only from an explicit tap in Attention Span [SAFE-01].
|
|
@@ -102,3 +102,33 @@ export async function rerunFailed(repo: string, runIds: number[]): Promise<void>
|
|
|
102
102
|
if (code !== 0) throw new Error(stderr.trim() || `Rerunning run ${id} failed`);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
// Who the reviewer picker suggests: GitHub's picks for the PR and the repo's teams; recent reviewers come from the last fetch [PRS-12].
|
|
107
|
+
// Fetched when the picker opens, not in every refresh [GH-01]. My own repos have no teams, so they aren't asked for.
|
|
108
|
+
export async function reviewerChoices(target: Target, recent: Reviewer[], login: string | null): Promise<ReviewerChoices> {
|
|
109
|
+
const isMe = (name: string) => !!login && name.toLowerCase() === login.toLowerCase();
|
|
110
|
+
const [owner] = target.repo.split("/");
|
|
111
|
+
const [suggested, teams] = await Promise.all([
|
|
112
|
+
graphql<{ node: { suggestedReviewers: { reviewer: { login: string; avatarUrl?: string } }[] } | null }>(
|
|
113
|
+
`query($id: ID!) { node(id: $id) { ... on PullRequest { suggestedReviewers { reviewer { login avatarUrl(size: 64) } } } } }`,
|
|
114
|
+
{ id: pullRequestId(target) },
|
|
115
|
+
),
|
|
116
|
+
isMe(owner) ? Promise.resolve({ code: 0, stdout: "[]", stderr: "" }) : runGh(["api", `repos/${target.repo}/teams?per_page=100`]),
|
|
117
|
+
]);
|
|
118
|
+
const people = (suggested.node?.suggestedReviewers ?? []).map(({ reviewer }) => ({ login: reviewer.login, avatarUrl: reviewer.avatarUrl, team: false })).filter((r) => !isMe(r.login));
|
|
119
|
+
if (teams.code !== 0) return { suggested: people, recent, teams: [], teamsNote: "Teams need the read:org scope (gh auth refresh -s read:org)" };
|
|
120
|
+
const list = JSON.parse(teams.stdout) as { slug: string }[];
|
|
121
|
+
return { suggested: people, recent, teams: list.map((team) => ({ login: `${owner}/${team.slug}`, team: true })) };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Ask people and teams ("org/slug") to review, keeping who's already asked; or withdraw them for Undo [PRS-12, ATT-14].
|
|
125
|
+
export async function requestReviewers(target: Target, reviewers: string[], on: boolean): Promise<void> {
|
|
126
|
+
if (reviewers.length === 0) return;
|
|
127
|
+
const body = {
|
|
128
|
+
reviewers: reviewers.filter((name) => !name.includes("/")),
|
|
129
|
+
team_reviewers: reviewers.filter((name) => name.includes("/")).map((name) => name.split("/")[1]),
|
|
130
|
+
};
|
|
131
|
+
const path = `repos/${target.repo}/pulls/${target.number}/requested_reviewers`;
|
|
132
|
+
const { code, stderr } = await runGh(["api", "--method", on ? "POST" : "DELETE", path, "--input", "-"], JSON.stringify(body));
|
|
133
|
+
if (code !== 0) throw new Error(stderr.trim() || (on ? "Requesting reviewers failed" : "Withdrawing the request failed"));
|
|
134
|
+
}
|
package/server/classify.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Attention, type Chip, type Item, type NextUpIssue, type Person, type Reviewer, SECTION_ORDER, SECTIONS, type SectionId, type SubRow, type Target } from "../shared/attention";
|
|
2
2
|
import type { AttentionConfig, MergeMethod } from "../shared/config";
|
|
3
3
|
import { ago, daysSince } from "../shared/format";
|
|
4
|
-
import type { Actor, Comment, Details, HistoryResult, LiveResult, MentionNode, PickableNode, PullRequestNode } from "./github-types";
|
|
4
|
+
import type { Actor, Comment, Details, HistoryResult, IssueNode, LiveResult, MentionNode, PickableNode, PullRequestNode, RequestedReviewer } from "./github-types";
|
|
5
5
|
import { excerpt, plainText } from "./markdown";
|
|
6
6
|
import { prKey } from "./queries";
|
|
7
|
+
import { ISSUE_RULES, type IssueState, pick, PR_RULES, type PrState, replyActions } from "./rules";
|
|
7
8
|
|
|
8
9
|
// Turns one refresh worth of GitHub data into what needs me. Pure, so every rule is testable.
|
|
9
10
|
|
|
@@ -39,6 +40,20 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
39
40
|
if (waiting) mentions.set(prKey(node), waiting);
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// What each thread I'm in is waiting for: an answer, or me [ATT-16]. Both searches can find one; it's the same thread.
|
|
44
|
+
const threads = new Map<string, IssueNode>();
|
|
45
|
+
for (const node of [...compact(data.involved.nodes), ...compact(data.asked.nodes)]) threads.set(prKey(node), node);
|
|
46
|
+
const answers = new Map<string, { flags: IssueState; person?: Person; mine: string }>();
|
|
47
|
+
for (const [key, node] of threads) {
|
|
48
|
+
const found = threadState(node, me, now, config);
|
|
49
|
+
if (found) answers.set(key, found);
|
|
50
|
+
}
|
|
51
|
+
// Who answered, when the rule says that's on me [ATT-16, ATT-17].
|
|
52
|
+
const answerOn = (key: string) => {
|
|
53
|
+
const found = answers.get(key);
|
|
54
|
+
return found && ISSUE_RULES.answered?.when(found.flags) ? found.person : undefined;
|
|
55
|
+
};
|
|
56
|
+
|
|
42
57
|
// My PRs, minus those handed over to someone else [PRS-08].
|
|
43
58
|
const mine = compact(data.mine.nodes).filter((pr) => pr.assignees.nodes.length === 0 || pr.assignees.nodes.some(isMe));
|
|
44
59
|
|
|
@@ -74,6 +89,12 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
74
89
|
ciPending: ci === "PENDING" || ci === "EXPECTED",
|
|
75
90
|
conflicts: pr.mergeable === "CONFLICTING",
|
|
76
91
|
approved: pr.reviewDecision === "APPROVED",
|
|
92
|
+
// A request counts even when its reviewer can't be seen, like a team I can't read; so does any review [PRS-12].
|
|
93
|
+
asked:
|
|
94
|
+
pr.reviewRequests.nodes.length > 0 ||
|
|
95
|
+
pr.latestReviews.nodes.some((review) => isOther(review.author)) ||
|
|
96
|
+
pr.reviewDecision === "APPROVED" ||
|
|
97
|
+
pr.reviewDecision === "CHANGES_REQUESTED",
|
|
77
98
|
autoMerge: !!pr.autoMergeRequest,
|
|
78
99
|
threadsOnMe: onMe.length,
|
|
79
100
|
botThreadsOnly: onMe.length > 0 && onMe.every((thread) => (thread.opener?.nodes[0] ?? last(thread))?.author?.__typename === "Bot"),
|
|
@@ -102,45 +123,42 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
102
123
|
const s = state(bottom);
|
|
103
124
|
const outOfSync = stack.slice(1).some((pr) => state(pr).outOfSync || state(pr).conflicts);
|
|
104
125
|
const waiting = stack.map((pr) => mentions.get(prKey(pr))).find(Boolean);
|
|
126
|
+
// A conversation comment after mine on any PR in the stack [ATT-16].
|
|
127
|
+
const answer = stack.map((pr) => answerOn(prKey(pr))).find(Boolean);
|
|
105
128
|
const base = bottom.baseRefName;
|
|
106
|
-
|
|
107
|
-
const reasons: SectionId[] = [];
|
|
108
|
-
if (waiting) reasons.push("reply");
|
|
109
|
-
if (bottom.isDraft) reasons.push("drafts");
|
|
110
|
-
else {
|
|
111
|
-
if (s.ciFailing) reasons.push("ci");
|
|
112
|
-
if (s.changes) reasons.push("changes");
|
|
113
|
-
// Auto-merge waiting on CI leaves nothing for me to do.
|
|
114
|
-
if (s.approved && !s.conflicts && !s.ciFailing && !s.changes && !(s.autoMerge && s.ciPending)) reasons.push("ready");
|
|
115
|
-
if (s.conflicts || outOfSync) reasons.push("upstream");
|
|
116
|
-
}
|
|
117
|
-
// Otherwise it waits on others: CI, the reviewer after my reply, or a review [WAI-01].
|
|
118
129
|
const waitingSince = latest(s.lastCommitAt, s.repliedAt);
|
|
119
130
|
const replied = s.repliedAt > EPOCH || bottom.reviewDecision === "CHANGES_REQUESTED";
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
const flags: PrState = {
|
|
132
|
+
draft: bottom.isDraft,
|
|
133
|
+
waiting,
|
|
134
|
+
answer,
|
|
135
|
+
ciFailing: s.ciFailing,
|
|
136
|
+
ciPending: s.ciPending,
|
|
137
|
+
changes: s.changes,
|
|
138
|
+
approved: s.approved,
|
|
139
|
+
conflicts: s.conflicts,
|
|
140
|
+
blocked: s.conflicts || outOfSync,
|
|
141
|
+
autoMerge: s.autoMerge,
|
|
142
|
+
autoMergeAllowed: !!bottom.repository.autoMergeAllowed,
|
|
143
|
+
behindBy: s.behindBy,
|
|
144
|
+
stacked: stack.length > 1,
|
|
145
|
+
stale: s.stale,
|
|
146
|
+
asked: s.asked,
|
|
147
|
+
replied,
|
|
148
|
+
tooLong: daysSince(waitingSince, now) >= config.waitingTooLongDays,
|
|
149
|
+
};
|
|
150
|
+
// Every PR of mine has a section; the tests check that a rule always holds.
|
|
151
|
+
const section = pick(PR_RULES, flags) ?? "wait_review";
|
|
152
|
+
const rule = PR_RULES[section];
|
|
153
|
+
const actions = rule?.actions?.(flags) ?? [];
|
|
154
|
+
// Who it waits on: the reviewer who asked for changes, else who's requested, else who reviewed.
|
|
125
155
|
const reviewer = replied
|
|
126
156
|
? bottom.latestReviews.nodes.find((review) => review.state === "CHANGES_REQUESTED")?.author
|
|
127
|
-
: bottom.reviewRequests.nodes.
|
|
128
|
-
|
|
129
|
-
const actions: ActionId[] = [];
|
|
130
|
-
if (section === "reply") actions.push(...replyActions(waiting));
|
|
131
|
-
// Rerun is for flaky checks, without an agent [PRS-09].
|
|
132
|
-
if (section === "ci") actions.push("fix", "rerun");
|
|
133
|
-
if (section === "changes") actions.push("address");
|
|
134
|
-
// Merge only once CI passed against the current base [PRS-04, UPS-07]. Until then, auto-merge if the repo allows it [PRS-10].
|
|
135
|
-
if (section === "ready")
|
|
136
|
-
actions.push(...(s.behindBy > 0 ? [stack.length === 1 ? "update" : "rebase"] : s.ciPending ? (bottom.repository.autoMergeAllowed ? ["automerge"] : []) : ["merge"]) as ActionId[]);
|
|
137
|
-
if (section === "upstream") actions.push("rebase");
|
|
138
|
-
// A stale draft offers Refresh and Close instead of Rebase [PRS-07]; a healthy one, Ready for review [PRS-11].
|
|
139
|
-
if (section === "drafts")
|
|
140
|
-
actions.push(...(s.stale ? ["refresh", "close"] : s.conflicts || outOfSync ? ["rebase"] : s.ciFailing ? ["fix", "rerun"] : ["ready"]) as ActionId[]);
|
|
157
|
+
: (bottom.reviewRequests.nodes.map((request) => requested(request.requestedReviewer)).find(Boolean) ??
|
|
158
|
+
bottom.latestReviews.nodes.find((review) => isOther(review.author))?.author);
|
|
141
159
|
|
|
142
160
|
const chips: Chip[] = [];
|
|
143
|
-
if (section === "too_long") chips.push(chip(`${
|
|
161
|
+
if (section === "too_long") chips.push(chip(`${rule?.label?.(flags)} · ${ago(waitingSince, now)}`, "warn"));
|
|
144
162
|
if (bottom.isDraft && s.stale) chips.push(chip(`untouched ${ago(bottom.updatedAt, now)}`, "warn"));
|
|
145
163
|
if (s.approved && !bottom.isDraft) chips.push(chip("approved", "good"));
|
|
146
164
|
if (s.autoMerge) chips.push(chip("auto-merge on", "good"));
|
|
@@ -159,12 +177,13 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
159
177
|
actions,
|
|
160
178
|
chips,
|
|
161
179
|
// How long it has waited, shown only while it sits in a Waiting section.
|
|
162
|
-
waited: section.
|
|
180
|
+
waited: SECTIONS[section].tab === "waiting" ? chip(ago(waitingSince, now)) : undefined,
|
|
163
181
|
person:
|
|
164
182
|
waiting ??
|
|
183
|
+
(section === "answered" ? answer : undefined) ??
|
|
165
184
|
(section === "changes" && s.botThreadsOnly ? { login: "review bot", bot: true, since: s.lastCommitAt } : undefined) ??
|
|
166
|
-
(section === "too_long" || section.
|
|
167
|
-
othersActivityAt: latest(...stack.map((pr) => state(pr).othersActivityAt), waiting?.since),
|
|
185
|
+
(section === "too_long" || SECTIONS[section].tab === "waiting" ? person(reviewer, waitingSince) : undefined),
|
|
186
|
+
othersActivityAt: latest(...stack.map((pr) => state(pr).othersActivityAt), waiting?.since, answer?.since),
|
|
168
187
|
};
|
|
169
188
|
});
|
|
170
189
|
type Unit = (typeof units)[number];
|
|
@@ -175,6 +194,7 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
175
194
|
const chips: Chip[] = [];
|
|
176
195
|
if (stack.length > 1) chips.push(chip(`${index + 1}/${stack.length}`));
|
|
177
196
|
if (s.approved) chips.push(chip("approved", "good"));
|
|
197
|
+
if (!pr.isDraft && !s.asked) chips.push(chip("no reviewer", "warn"));
|
|
178
198
|
if (s.ciFailing) chips.push(chip("CI failing", "bad"));
|
|
179
199
|
if (s.conflicts) chips.push(chip("conflicts", "bad"));
|
|
180
200
|
if (s.behindBy > 0) chips.push(behindChip(s.behindBy, parent ? `#${parent.number}` : pr.baseRefName));
|
|
@@ -206,9 +226,10 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
206
226
|
for (const [key, { lead, units: grouped }] of groups) {
|
|
207
227
|
for (const unit of grouped) for (const pr of unit.stack) listed.add(prKey(pr));
|
|
208
228
|
listed.add(key);
|
|
209
|
-
|
|
229
|
+
// From the issue itself only what's on me counts: a mention, or an answer to my question. Its PRs say how the work goes [ATT-16].
|
|
230
|
+
const issueWaiting = lead ? (mentions.get(key) ?? answerOn(key)) : undefined;
|
|
210
231
|
const sections = grouped.map((unit) => unit.section);
|
|
211
|
-
if (issueWaiting) sections.push("reply");
|
|
232
|
+
if (issueWaiting) sections.push(mentions.has(key) ? "reply" : "answered");
|
|
212
233
|
const section = sections.sort((a, b) => rank(a) - rank(b))[0];
|
|
213
234
|
const unit = grouped.find((candidate) => candidate.section === section) ?? grouped[0];
|
|
214
235
|
const bottom = unit.stack[0];
|
|
@@ -281,16 +302,25 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
281
302
|
});
|
|
282
303
|
}
|
|
283
304
|
|
|
284
|
-
// Issues
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
305
|
+
// Issues and others' PRs I'm in: answered, or waiting on others and then mine to nudge [WAI-01, ATT-11, ATT-16].
|
|
306
|
+
// My own PRs are listed above, or handed over and left out [PRS-08].
|
|
307
|
+
for (const [key, issue] of threads) {
|
|
308
|
+
const found = answers.get(key);
|
|
309
|
+
const kind = issue.__typename === "PullRequest" ? "pr" : "issue";
|
|
310
|
+
if (listed.has(key) || !found || (kind === "pr" && found.flags.authored)) continue;
|
|
311
|
+
const { flags, person, mine } = found;
|
|
312
|
+
const section = pick(ISSUE_RULES, flags);
|
|
313
|
+
if (!section) continue;
|
|
289
314
|
listed.add(key);
|
|
290
|
-
const
|
|
315
|
+
const label = ISSUE_RULES[section]?.label?.(flags);
|
|
316
|
+
const since = person?.since ?? mine;
|
|
291
317
|
items.push({
|
|
292
|
-
...plain(issue,
|
|
293
|
-
chips:
|
|
318
|
+
...plain(issue, kind, section),
|
|
319
|
+
chips: section === "answered" ? [] : [label ? chip(`${label} · ${ago(since, now)}`, "warn") : chip(ago(since, now))],
|
|
320
|
+
person,
|
|
321
|
+
actions: section === "answered" ? replyActions(person) : [],
|
|
322
|
+
// A new answer brings back a dismissed one [ATT-08].
|
|
323
|
+
othersActivityAt: person ? latest(...(person.comments ?? []).map((c) => c.createdAt)) : EPOCH,
|
|
294
324
|
});
|
|
295
325
|
}
|
|
296
326
|
|
|
@@ -298,6 +328,7 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
298
328
|
return {
|
|
299
329
|
login: data.viewer.login,
|
|
300
330
|
items,
|
|
331
|
+
reviewers: recentReviewers(mine, isOther),
|
|
301
332
|
// Assigned issues not already in progress come before unclaimed ones [NXT-06].
|
|
302
333
|
assigned: rankIssues(compact(data.assigned.nodes).filter((issue) => !listed.has(prKey(issue))), details, config),
|
|
303
334
|
unclaimed: rankIssues(compact(data.unclaimed.nodes), details, config),
|
|
@@ -323,6 +354,78 @@ export function classifyHistory(data: HistoryResult): Item[] {
|
|
|
323
354
|
return items.sort(order);
|
|
324
355
|
}
|
|
325
356
|
|
|
357
|
+
// Whether my last comment on an issue is the last one from a person, and if not, the answers since that I haven't 👍'd.
|
|
358
|
+
// Bots don't count [MEN-05]. Only the last comments are fetched: once mine is out of them the conversation has moved on.
|
|
359
|
+
// Whether my last comment on a thread is the last one from a person, and if not, the recent comments since that I haven't 👍'd.
|
|
360
|
+
// On a thread I opened, my opening counts as my last word until I comment. Bots don't count [MEN-05]. Only the last comments
|
|
361
|
+
// are fetched: on someone else's thread, once mine is out of them the conversation has moved on.
|
|
362
|
+
export function threadState(
|
|
363
|
+
thread: IssueNode,
|
|
364
|
+
me: string,
|
|
365
|
+
now: Date,
|
|
366
|
+
config: Pick<AttentionConfig, "mentionDays" | "waitingTooLongDays" | "followThreads">,
|
|
367
|
+
): { flags: IssueState; person?: Person; mine: string } | null {
|
|
368
|
+
const authored = thread.author?.login.toLowerCase() === me;
|
|
369
|
+
const people = thread.comments.nodes.filter((c) => c.author && c.author.__typename !== "Bot");
|
|
370
|
+
const index = people.findLastIndex((c) => c.author?.login.toLowerCase() === me);
|
|
371
|
+
if (index < 0 && !authored) return null;
|
|
372
|
+
const mine = index < 0 ? thread.createdAt : people[index].createdAt;
|
|
373
|
+
const after = people.slice(index + 1);
|
|
374
|
+
const recent = (at: string) => daysSince(at, now) < config.mentionDays;
|
|
375
|
+
const unread = after.filter((c) => recent(c.createdAt) && !c.reactionGroups?.some((group) => group.viewerHasReacted));
|
|
376
|
+
const flags: IssueState = {
|
|
377
|
+
authored,
|
|
378
|
+
follow: config.followThreads,
|
|
379
|
+
// Opening a thread isn't asking a question; a comment is.
|
|
380
|
+
mineLast: index >= 0 && after.length === 0,
|
|
381
|
+
answered: unread.length > 0,
|
|
382
|
+
fresh: recent(mine),
|
|
383
|
+
tooLong: daysSince(mine, now) >= config.waitingTooLongDays,
|
|
384
|
+
};
|
|
385
|
+
const last = unread.at(-1);
|
|
386
|
+
if (!last?.author) return { flags, mine };
|
|
387
|
+
return {
|
|
388
|
+
flags,
|
|
389
|
+
mine,
|
|
390
|
+
person: {
|
|
391
|
+
login: last.author.login,
|
|
392
|
+
avatarUrl: last.author.avatarUrl,
|
|
393
|
+
bot: false,
|
|
394
|
+
since: last.createdAt,
|
|
395
|
+
snippet: snippetAround(plainText(last.body ?? ""), 0),
|
|
396
|
+
url: last.url ?? thread.url,
|
|
397
|
+
comments: unread.filter((c) => c.id).map((c) => ({ id: c.id!, author: c.author!.login, body: excerpt(c.body, 4000) ?? "", createdAt: c.createdAt, url: c.url })),
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// A requested person, or a team by its "org/slug".
|
|
403
|
+
function requested(reviewer: RequestedReviewer | null | undefined): Actor | undefined {
|
|
404
|
+
const login = reviewer?.login ?? reviewer?.combinedSlug;
|
|
405
|
+
return login ? { __typename: reviewer!.__typename, login, avatarUrl: reviewer!.avatarUrl } : undefined;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Who reviewed or was asked on my PRs, per repo, latest review first, for the reviewer picker [PRS-12]. Bots aren't offered.
|
|
409
|
+
function recentReviewers(mine: PullRequestNode[], isOther: (actor: Actor | null | undefined) => boolean): Record<string, Reviewer[]> {
|
|
410
|
+
const byRepo: Record<string, (Reviewer & { at: string })[]> = {};
|
|
411
|
+
for (const pr of mine) {
|
|
412
|
+
const list = (byRepo[pr.repository.nameWithOwner] ??= []);
|
|
413
|
+
const add = (actor: Actor | undefined, at: string) => {
|
|
414
|
+
if (!actor || !isOther(actor) || actor.__typename === "Bot") return;
|
|
415
|
+
const seen = list.find((reviewer) => reviewer.login === actor.login);
|
|
416
|
+
if (seen) seen.at = seen.at > at ? seen.at : at;
|
|
417
|
+
else list.push({ login: actor.login, avatarUrl: actor.avatarUrl, team: actor.__typename === "Team", at });
|
|
418
|
+
};
|
|
419
|
+
for (const review of pr.latestReviews.nodes) add(review.author ?? undefined, review.submittedAt ?? EPOCH);
|
|
420
|
+
for (const request of pr.reviewRequests.nodes) add(requested(request.requestedReviewer), EPOCH);
|
|
421
|
+
}
|
|
422
|
+
return Object.fromEntries(
|
|
423
|
+
Object.entries(byRepo)
|
|
424
|
+
.filter(([, list]) => list.length > 0)
|
|
425
|
+
.map(([repo, list]) => [repo, list.sort((a, b) => b.at.localeCompare(a.at)).map(({ at: _, ...reviewer }) => reviewer)]),
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
326
429
|
// An item with nothing to act on: waiting, history.
|
|
327
430
|
function plain(node: { repository: { nameWithOwner: string }; number: number; title: string; url: string }, kind: "pr" | "issue", section: SectionId): Item {
|
|
328
431
|
const repo = node.repository.nameWithOwner;
|
|
@@ -393,11 +496,6 @@ function rankIssues(nodes: PickableNode[], details: Details, config: AttentionCo
|
|
|
393
496
|
|
|
394
497
|
// ---- Mentions still waiting on me [MEN-01..06] ----
|
|
395
498
|
|
|
396
|
-
// Reply on GitHub, or 👍 the waiting comments, which clears them too [MEN-02].
|
|
397
|
-
function replyActions(waiting: Person | undefined): ActionId[] {
|
|
398
|
-
return waiting?.comments?.length ? ["reply", "acknowledge"] : ["reply"];
|
|
399
|
-
}
|
|
400
|
-
|
|
401
499
|
function mentionsMe(body: string | undefined, me: string): number {
|
|
402
500
|
if (!body) return -1;
|
|
403
501
|
// Ignore quoted replies; a team mention (@org/team) never matches a login [MEN-04].
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import type { FeedbackInfo } from "../shared/feedback";
|
|
7
|
+
|
|
8
|
+
const run = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
// A scratch directory for the session, where this plugin is installed and which version it is [FB-01].
|
|
11
|
+
export async function feedbackInfo(): Promise<FeedbackInfo> {
|
|
12
|
+
const cwd = mkdtempSync(join(tmpdir(), "attention-span-feedback-"));
|
|
13
|
+
const source = pluginDir();
|
|
14
|
+
return { cwd, source, version: source ? await version(source) : null };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Paseo evaluates the server as a bundle, so it has no file location of its own (import.meta.url is undefined).
|
|
18
|
+
// Paseo's config.json records where each plugin's source is: take this plugin's, by its manifest's ID.
|
|
19
|
+
export function pluginDir(paseoHome = process.env.PASEO_HOME || join(homedir(), ".paseo")): string | null {
|
|
20
|
+
try {
|
|
21
|
+
const { plugins = {} } = JSON.parse(readFileSync(join(paseoHome, "config.json"), "utf8")) as { plugins?: Record<string, { path?: string }> };
|
|
22
|
+
const ours = Object.entries(plugins)
|
|
23
|
+
.filter(([, source]) => source.path && manifestId(source.path) === PLUGIN_ID)
|
|
24
|
+
.sort(([a], [b]) => Number(b === PLUGIN_ID) - Number(a === PLUGIN_ID));
|
|
25
|
+
return ours[0]?.[1].path ?? null;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const PLUGIN_ID = "attention-span";
|
|
32
|
+
|
|
33
|
+
function manifestId(dir: string): string | null {
|
|
34
|
+
try {
|
|
35
|
+
return (JSON.parse(readFileSync(join(dir, "paseo-plugin.json"), "utf8")) as { id?: string }).id ?? null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// package.json's version, which is a placeholder in a checkout: then the commit.
|
|
42
|
+
async function version(dir: string): Promise<string | null> {
|
|
43
|
+
try {
|
|
44
|
+
const { version } = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")) as { version?: string };
|
|
45
|
+
if (version && !version.startsWith("0.0.0")) return version;
|
|
46
|
+
} catch {}
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await run("git", ["-C", dir, "describe", "--always", "--dirty", "--tags"]);
|
|
49
|
+
return `commit ${stdout.trim()}`;
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|