@andrioid/paseo-attention-span 0.3.0 → 0.3.2
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/client/feedback.tsx +31 -9
- package/docs/architecture.md +4 -4
- package/index.client.tsx +2 -1
- package/package.json +1 -1
- package/server/classify.ts +14 -8
- package/server/feedback.ts +28 -13
- package/server/fixture.ts +11 -3
- package/server/github-types.ts +7 -2
- package/server/queries.ts +17 -6
- package/server/references.ts +70 -0
- package/server/service.ts +15 -6
- package/shared/feedback.ts +9 -8
package/client/feedback.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { openExternalUrl, usePaseo, useRpc } from "@getpaseo/plugin/client";
|
|
1
|
+
import { openExternalUrl, type PluginClientContext, usePaseo, useRpc } from "@getpaseo/plugin/client";
|
|
2
2
|
import { Modal, TextInput, useToast } from "@getpaseo/plugin/client/ui";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { Pressable, Text, View } from "react-native";
|
|
@@ -97,11 +97,11 @@ export function FeedbackAsk({
|
|
|
97
97
|
setStarting(true);
|
|
98
98
|
try {
|
|
99
99
|
const info = await fetchInfo({});
|
|
100
|
-
const prompt = feedbackPrompt(kind, { ...screen, message, dir: info.
|
|
100
|
+
const prompt = feedbackPrompt(kind, { ...screen, message, dir: info.source, version: info.version });
|
|
101
101
|
const { agent } = await resolveAgentConfig(paseo, "start", config);
|
|
102
102
|
const workspace = await paseo.workspaces.open({ cwd: info.cwd });
|
|
103
103
|
const created = await workspace.agents.create({
|
|
104
|
-
config:
|
|
104
|
+
config: agent,
|
|
105
105
|
title: `Feedback: ${KINDS[kind].label}`,
|
|
106
106
|
prompt,
|
|
107
107
|
labels: { [LABEL]: "1", [ITEM_LABEL]: feedbackItemKey(kind), [KIND_LABEL]: `feedback-${kind}` },
|
|
@@ -142,10 +142,32 @@ export function FeedbackAsk({
|
|
|
142
142
|
);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
const isFeedbackDir = (dir: string | undefined) => !!dir && /attention-span-feedback-[^/]*$/.test(dir);
|
|
146
|
+
|
|
147
|
+
// Once a feedback session posts, it archives its scratch workspace; that would leave "workspace unavailable"
|
|
148
|
+
// on screen, so open Attention Span instead [FB-01]. A removed workspace comes with only its ID,
|
|
149
|
+
// so the feedback ones are remembered as they're seen.
|
|
150
|
+
export function returnFromFeedback(client: Pick<PluginClientContext, "paseo" | "openScreen">): () => void {
|
|
151
|
+
const feedback = new Set<string>();
|
|
152
|
+
const remember = (workspace: { id: string; workspaceDirectory?: string; projectRootPath?: string }) => {
|
|
153
|
+
if (isFeedbackDir(workspace.workspaceDirectory ?? workspace.projectRootPath)) feedback.add(workspace.id);
|
|
154
|
+
};
|
|
155
|
+
let stop = () => {};
|
|
156
|
+
try {
|
|
157
|
+
stop = client.paseo.workspaces.subscribe((update) => {
|
|
158
|
+
if (update.kind === "upsert") remember(update.workspace);
|
|
159
|
+
else if (update.kind === "remove" && feedback.delete(update.id)) client.openScreen({ screenId: "attention" });
|
|
160
|
+
});
|
|
161
|
+
} catch {
|
|
162
|
+
// An older host without workspace updates: the screen just stays where it is.
|
|
163
|
+
}
|
|
164
|
+
// Listing with a subscription is what makes the daemon stream workspace updates.
|
|
165
|
+
const listing = Promise.resolve().then(() => client.paseo.workspaces.list({ subscribe: {} })).then(
|
|
166
|
+
(result) => (result.entries.forEach(remember), result.subscription),
|
|
167
|
+
() => null,
|
|
168
|
+
);
|
|
169
|
+
return () => {
|
|
170
|
+
stop();
|
|
171
|
+
void listing.then((subscription) => subscription?.release());
|
|
172
|
+
};
|
|
151
173
|
}
|
package/docs/architecture.md
CHANGED
|
@@ -80,7 +80,7 @@ Top to bottom. Each item appears once, under its most urgent reason [ATT-02]. `s
|
|
|
80
80
|
|
|
81
81
|
## Rules
|
|
82
82
|
|
|
83
|
-
- **One item per issue** [ATT-03]: PRs are grouped under the
|
|
83
|
+
- **One item per issue** [ATT-03]: PRs are grouped under the issue they work on, across repos. GitHub links (`closingIssuesReferences`) only PRs into the default branch, so a stack's upper PRs are read too. For a stack, strongest evidence first: what GitHub links on any of its PRs, bottom first; then a closing keyword ("Closes #N") in any PR's description; then the one issue the bottom PR's description mentions ("First of three for #N"), and none when it mentions several. Code, quotes and template comments don't count. References from descriptions are looked up in the details request, and only open issues count, so a reference to a PR doesn't group. A PR without an issue is its own item. History does the same per merged PR, against the closed issues it lists.
|
|
84
84
|
- **One item per stack** [ATT-04]: a stack is followed through base/head branch names. Its section is decided by the bottom PR; the PRs above it are listed beneath.
|
|
85
85
|
- **Answers** [ATT-16]: on an issue a PR of mine closes, an answer leads the item like a mention does. From the issue itself only what's on me counts; its PRs say how the work is going.
|
|
86
86
|
- **Mentions** [MEN-01..06]: a thread counts when a person @-mentioned me after my last comment, review or reaction there. Team mentions are ignored. A bot counts only when it opened a thread I need to resolve, and is marked with 🤖. The quote on a card is cut around the mention, so it's shown as plain text: links keep their text, Markdown marks and quoted replies go.
|
|
@@ -142,9 +142,9 @@ While an item has an open session, its main action is **Open session** instead,
|
|
|
142
142
|
- **Something's wrong…** and **I have an idea…** *(agent)* ask for the first words in the sheet, then start a session with them in the prompt (`shared/feedback.ts`), so the agent's first message is already a follow-up. While one runs, its line becomes Continue, like an item's [SES-03]; the session is labelled with the item key `feedback:problem` or `feedback:idea`.
|
|
143
143
|
- **I'll star it on GitHub** opens the repo on GitHub. No agent.
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
Each session gets its own workspace on an empty scratch directory, so archiving that workspace closes it cleanly and nothing is written into the plugin. The agent reads the plugin's installed source by its path, which is why the npm package ships `requirements.yaml` and this file. Paseo evaluates the server as a bundle with no file location, so the source is the path Paseo's `config.json` records for the plugin whose manifest ID is `attention-span`, preferring the install under that ID. It uses the default profile and its mode, like other sessions: a plan mode would ask before nearly every step. Without the source it reads the repo through `gh api`. The prompt carries the version (`package.json`, or the commit in a checkout), phone or desktop, theme, tab and a failed refresh's error.
|
|
146
146
|
|
|
147
|
-
The agent asks one question at a time from its kind's checklist, and checks the report against the requirements and docs, `config.json` and `state.json`, and open issues and discussions. A match gets its link and nothing else. It files an issue if a maintainer could finish and close it, otherwise a discussion in Q&A or Ideas, and says which and why. Posts are short up front, with the rest in collapsed `<details>` blocks, in English, in the user's voice, with nothing from their own setup they didn't write. It posts only after Post it in its question tool, or the reply "post" [SAFE-01], then archives
|
|
147
|
+
The agent asks one question at a time from its kind's checklist, and checks the report against the requirements and docs, `config.json` and `state.json`, and open issues and discussions. A match gets its link and nothing else. It files an issue if a maintainer could finish and close it, otherwise a discussion in Q&A or Ideas, and says which and why. Posts are short up front, with the rest in collapsed `<details>` blocks, in English, in the user's voice, with nothing from their own setup they didn't write. It posts only after Post it in its question tool, or the reply "post" [SAFE-01], then archives its workspace (`archive_workspace`, or `archive_agent` without it). The client watches workspace updates, remembers the scratch ones by their directory, and opens Attention Span when one is removed, instead of leaving "workspace unavailable" on screen. The prompts are built in: `config.json` can't replace them, since they carry those rules.
|
|
148
148
|
|
|
149
149
|
## GitHub requests
|
|
150
150
|
|
|
@@ -165,7 +165,7 @@ One GraphQL request per search, sent in parallel. GitHub runs the searches in on
|
|
|
165
165
|
- `is:issue is:open author:@me commenter:@me sort:updated-desc`, 50 at most, no date limit, the same fields (questions on my own issues nobody answered, however old) [ATT-11]
|
|
166
166
|
- `is:issue is:open no:assignee` (Next up, with issue type and field values; one request per source [NXT-09], skipped when there's nowhere to look [NXT-08]). "My repos" needs my login, taken from the last fetch or asked once with `viewer { login }`
|
|
167
167
|
|
|
168
|
-
Once my PRs and both issue searches are back, one batched **details** request asks for `Ref.compare` behind counts for my PRs, and the option order of org issue fields when Next up needs it. The other searches carry on meanwhile.
|
|
168
|
+
Once my PRs and both issue searches are back, one batched **details** request asks for `Ref.compare` behind counts for my PRs, the open issues their descriptions refer to (at most 100), and the option order of org issue fields when Next up needs it. The other searches carry on meanwhile.
|
|
169
169
|
|
|
170
170
|
A live refresh is 8 requests and about 85 points, of the 5,000 GitHub allows per hour. Points depend on how much a query asks for, not how many requests carry it; my PRs (34) and review requests (20) cost the most.
|
|
171
171
|
|
package/index.client.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { Text, View } from "react-native";
|
|
|
4
4
|
import { AttentionScreen } from "./client/attention-screen";
|
|
5
5
|
import { CoverageSettings } from "./client/coverage-settings";
|
|
6
6
|
import { useAttention } from "./client/data";
|
|
7
|
+
import { returnFromFeedback } from "./client/feedback";
|
|
7
8
|
import { useHostLabel } from "./client/host";
|
|
8
9
|
import { ICONS } from "./client/icons";
|
|
9
10
|
|
|
@@ -42,5 +43,5 @@ export default function contribute(client: PluginClientContext) {
|
|
|
42
43
|
const Screen = (props: PluginScreenProps) => <AttentionScreen {...props} openSettings={() => client.openSettings("coverage")} />;
|
|
43
44
|
client.addScreen({ id: "attention", title: "Attention Span", Component: Screen });
|
|
44
45
|
client.addSidebarHeaderItem({ id: "attention", title: "Attention Span", Component: SidebarItem });
|
|
45
|
-
return ()
|
|
46
|
+
return returnFromFeedback(client);
|
|
46
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrioid/paseo-attention-span",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "For when your attention is spread thin: the GitHub issues and pull requests waiting on you, grouped by why, with one-tap Paseo sessions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/server/classify.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
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, IssueNode, LiveResult, MentionNode, PickableNode, PullRequestNode, RequestedReviewer } from "./github-types";
|
|
4
|
+
import type { Actor, Comment, Details, HistoryResult, IssueNode, LinkedIssue, LiveResult, MentionNode, PickableNode, PullRequestNode, RequestedReviewer } from "./github-types";
|
|
5
5
|
import { excerpt, plainText } from "./markdown";
|
|
6
6
|
import { prKey } from "./queries";
|
|
7
|
+
import { issueFor } from "./references";
|
|
7
8
|
import { ISSUE_RULES, type IssueState, pick, PR_RULES, type PrState, replyActions } from "./rules";
|
|
8
9
|
|
|
9
10
|
// Turns one refresh worth of GitHub data into what needs me. Pure, so every rule is testable.
|
|
@@ -216,12 +217,15 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
216
217
|
stack: stack.map((p) => ({ number: p.number, head: p.headRefName, base: p.baseRefName })),
|
|
217
218
|
});
|
|
218
219
|
|
|
219
|
-
// One item per issue: PRs grouped under the issue they
|
|
220
|
-
const
|
|
220
|
+
// One item per issue: PRs grouped under the issue they work on [ATT-03]. Otherwise one per unit.
|
|
221
|
+
const issues = new Map(Object.entries(details.issues));
|
|
222
|
+
for (const pr of mine) for (const issue of pr.closingIssuesReferences.nodes) issues.set(prKey(issue), issue);
|
|
223
|
+
const groups = new Map<string, { lead?: LinkedIssue; units: Unit[] }>();
|
|
221
224
|
for (const unit of units) {
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
+
const prs = unit.stack.map((pr) => ({ repo: pr.repository.nameWithOwner, body: pr.body, linked: pr.closingIssuesReferences.nodes.map(prKey) }));
|
|
226
|
+
const issue = issueFor(prs, (key) => issues.has(key));
|
|
227
|
+
const key = issue ?? prKey(unit.stack[0]);
|
|
228
|
+
groups.set(key, { lead: issue ? issues.get(issue) : undefined, units: [...(groups.get(key)?.units ?? []), unit] });
|
|
225
229
|
}
|
|
226
230
|
for (const [key, { lead, units: grouped }] of groups) {
|
|
227
231
|
for (const unit of grouped) for (const pr of unit.stack) listed.add(prKey(pr));
|
|
@@ -335,7 +339,7 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
335
339
|
};
|
|
336
340
|
}
|
|
337
341
|
|
|
338
|
-
// My merged PRs under the issues they
|
|
342
|
+
// My merged PRs under the closed issues they worked on, closed issues, and reviews [HIS-01, HIS-02, ATT-03].
|
|
339
343
|
export function classifyHistory(data: HistoryResult): Item[] {
|
|
340
344
|
const items: Item[] = [];
|
|
341
345
|
const closed = new Map<string, Item>();
|
|
@@ -346,7 +350,9 @@ export function classifyHistory(data: HistoryResult): Item[] {
|
|
|
346
350
|
items.push(item);
|
|
347
351
|
}
|
|
348
352
|
for (const pr of compact(data.merged.nodes)) {
|
|
349
|
-
|
|
353
|
+
// Each merged PR on its own: its branches are gone, so it can't be put back in its stack [ATT-03].
|
|
354
|
+
const linked = { repo: pr.repository.nameWithOwner, body: pr.body, linked: pr.closingIssuesReferences.nodes.map(prKey) };
|
|
355
|
+
const issue = closed.get(issueFor([linked], (key) => closed.has(key)) ?? "");
|
|
350
356
|
if (issue) issue.children.push({ key: prKey(pr), number: pr.number, title: pr.title, url: pr.url, draft: false, chips: [], attention: false });
|
|
351
357
|
else items.push({ ...plain(pr, "pr", "done"), closedAt: pr.mergedAt });
|
|
352
358
|
}
|
package/server/feedback.ts
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import {
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { mkdtempSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
6
5
|
import { promisify } from "node:util";
|
|
7
6
|
import type { FeedbackInfo } from "../shared/feedback";
|
|
8
7
|
|
|
9
8
|
const run = promisify(execFile);
|
|
10
9
|
|
|
11
|
-
//
|
|
10
|
+
// A scratch directory for the session, where this plugin is installed and which version it is [FB-01].
|
|
12
11
|
export async function feedbackInfo(): Promise<FeedbackInfo> {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
return { cwd
|
|
12
|
+
const cwd = mkdtempSync(join(tmpdir(), "attention-span-feedback-"));
|
|
13
|
+
const source = pluginDir();
|
|
14
|
+
return { cwd, source, version: source ? await version(source) : null };
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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;
|
|
22
38
|
}
|
|
23
|
-
return null;
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
// package.json's version, which is a placeholder in a checkout: then the commit.
|
package/server/fixture.ts
CHANGED
|
@@ -140,9 +140,10 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
140
140
|
pr(102, { title: "Retry webhook deliveries with backoff", reviewThreads: { nodes: [thread(alice, 1), thread(bot, 2)] } }),
|
|
141
141
|
pr(103, { title: "Fetch supplier price files nightly", reviewDecision: "APPROVED", closingIssuesReferences: closes(90, "Supplier prices are a week out of date") }),
|
|
142
142
|
pr(104, { title: "Move price-file login into a service", isDraft: true, baseRefName: "branch-103", headRefName: "branch-104" }),
|
|
143
|
-
|
|
143
|
+
// A stack GitHub links to no issue: its descriptions say which [ATT-03].
|
|
144
|
+
pr(105, { title: "Dialog focus returns to the trigger", body: "First of three stacked PRs for #132.", reviewDecision: "APPROVED", headRefName: "a11y-1" }),
|
|
144
145
|
pr(106, { title: "Keyboard navigation for calendar cards", isDraft: true, baseRefName: "a11y-1", headRefName: "a11y-2", reviewDecision: "APPROVED" }),
|
|
145
|
-
pr(107, { title: "Calendar: jump between weeks with keys", isDraft: true, baseRefName: "a11y-2", headRefName: "a11y-3" }, "FAILURE"),
|
|
146
|
+
pr(107, { title: "Calendar: jump between weeks with keys", body: "Closes #132", isDraft: true, baseRefName: "a11y-2", headRefName: "a11y-3" }, "FAILURE"),
|
|
146
147
|
pr(108, { title: "Company-scoped database layer", mergeable: "CONFLICTING" }),
|
|
147
148
|
// Asked a team, and nobody has looked for 6 days [ATT-11, PRS-12].
|
|
148
149
|
pr(109, { title: "Store uploads locally in development", reviewRequests: { nodes: [{ requestedReviewer: frontend }] }, commits: commit("SUCCESS", 6) }),
|
|
@@ -224,7 +225,14 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
224
225
|
],
|
|
225
226
|
closed: [closed(171, "Backups are never verified", 1), closed(174, "Order list takes 8 seconds", 9), closed(176, "Dark mode for the admin", 10, "NOT_PLANNED")],
|
|
226
227
|
});
|
|
227
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
data,
|
|
230
|
+
details: {
|
|
231
|
+
behind: { [key(103)]: 1, [key(106)]: 12, [key(108)]: 139, [key(110)]: 2307, [key(114)]: 3, [key(115)]: 40 },
|
|
232
|
+
fieldOptions: { Priority: ["🌋 P0 Urgent", "🏔 P1 High", "🏕P2 Medium", "🏝 P3 Low"] },
|
|
233
|
+
issues: { [key(132)]: { number: 132, title: "The calendar can't be used with a keyboard", url: `https://github.com/${REPO}/issues/132`, repository } },
|
|
234
|
+
},
|
|
235
|
+
};
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
// Sessions the preview shows as started from items: working, needs me, failed, idle.
|
package/server/github-types.ts
CHANGED
|
@@ -36,6 +36,7 @@ export interface PullRequestNode {
|
|
|
36
36
|
number: number;
|
|
37
37
|
title: string;
|
|
38
38
|
url: string;
|
|
39
|
+
body?: string;
|
|
39
40
|
isDraft: boolean;
|
|
40
41
|
createdAt: string;
|
|
41
42
|
updatedAt: string;
|
|
@@ -49,7 +50,7 @@ export interface PullRequestNode {
|
|
|
49
50
|
reviewDecision: "APPROVED" | "CHANGES_REQUESTED" | "REVIEW_REQUIRED" | null;
|
|
50
51
|
autoMergeRequest?: { enabledAt: string } | null;
|
|
51
52
|
assignees: Nodes<{ login: string }>;
|
|
52
|
-
closingIssuesReferences: Nodes<
|
|
53
|
+
closingIssuesReferences: Nodes<LinkedIssue>;
|
|
53
54
|
commits: Nodes<{ commit: { committedDate: string; statusCheckRollup: { state: string } | null } }>;
|
|
54
55
|
// A person, or a team by its "org/slug"; null when it can't be seen.
|
|
55
56
|
reviewRequests: Nodes<{ requestedReviewer: RequestedReviewer | null }>;
|
|
@@ -115,7 +116,7 @@ export interface LiveResult {
|
|
|
115
116
|
|
|
116
117
|
// One request for all three [HIS-01, HIS-02].
|
|
117
118
|
export interface HistoryResult {
|
|
118
|
-
merged: Nodes<{ number: number; title: string; url: string; mergedAt: string; repository: Repo; closingIssuesReferences: Nodes<{ number: number; repository: Repo }> }>;
|
|
119
|
+
merged: Nodes<{ number: number; title: string; url: string; body?: string; mergedAt: string; repository: Repo; closingIssuesReferences: Nodes<{ number: number; repository: Repo }> }>;
|
|
119
120
|
reviewed: Nodes<{ number: number; title: string; url: string; mergedAt: string; repository: Repo; author: Actor | null }>;
|
|
120
121
|
closed: Nodes<{ number: number; title: string; url: string; closedAt: string; stateReason: string | null; repository: Repo }>;
|
|
121
122
|
}
|
|
@@ -128,4 +129,8 @@ export interface Details {
|
|
|
128
129
|
behind: Record<string, number>;
|
|
129
130
|
// Issue field name -> its options in order.
|
|
130
131
|
fieldOptions: Record<string, string[]>;
|
|
132
|
+
// "owner/name#number" -> the open issue my PRs' descriptions refer to; PRs and closed issues are left out [ATT-03].
|
|
133
|
+
issues: Record<string, LinkedIssue>;
|
|
131
134
|
}
|
|
135
|
+
|
|
136
|
+
export type LinkedIssue = { number: number; title: string; url: string; repository: Repo };
|
package/server/queries.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UnclaimedSource } from "../shared/attention";
|
|
2
2
|
import type { AttentionConfig } from "../shared/config";
|
|
3
3
|
import type { PickableNode, PullRequestNode } from "./github-types";
|
|
4
|
+
import type { IssueRef } from "./references";
|
|
4
5
|
|
|
5
6
|
// An issue or PR with its last conversation comments [ATT-16].
|
|
6
7
|
const THREAD = `__typename
|
|
@@ -29,7 +30,7 @@ const SEARCHES = {
|
|
|
29
30
|
unclaimed: { first: 100, nodes: "...pickable" },
|
|
30
31
|
merged: {
|
|
31
32
|
first: 100,
|
|
32
|
-
nodes: "... on PullRequest { number title url mergedAt repository { nameWithOwner } closingIssuesReferences(first: 3) { nodes { number repository { nameWithOwner } } } }",
|
|
33
|
+
nodes: "... on PullRequest { number title url body mergedAt repository { nameWithOwner } closingIssuesReferences(first: 3) { nodes { number repository { nameWithOwner } } } }",
|
|
33
34
|
},
|
|
34
35
|
reviewed: { first: 100, nodes: "... on PullRequest { number title url mergedAt repository { nameWithOwner } author { ...author } }" },
|
|
35
36
|
closed: { first: 100, nodes: "... on Issue { number title url closedAt stateReason repository { nameWithOwner } }" },
|
|
@@ -56,7 +57,7 @@ const FRAGMENTS: Record<string, string> = {
|
|
|
56
57
|
closedByPullRequestsReferences(first: 5, includeClosedPrs: false) { nodes { number url state author { login } } }
|
|
57
58
|
}`,
|
|
58
59
|
pr: `fragment pr on PullRequest {
|
|
59
|
-
id number title url isDraft createdAt updatedAt
|
|
60
|
+
id number title url body isDraft createdAt updatedAt
|
|
60
61
|
author { ...author }
|
|
61
62
|
repository { nameWithOwner squashMergeAllowed mergeCommitAllowed autoMergeAllowed defaultBranchRef { name } }
|
|
62
63
|
baseRefName headRefName headRefOid isCrossRepository mergeable reviewDecision
|
|
@@ -175,16 +176,26 @@ export function prKey(node: { repository: { nameWithOwner: string }; number: num
|
|
|
175
176
|
return `${node.repository.nameWithOwner}#${node.number}`;
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
const repository = (repo: string) => {
|
|
180
|
+
const [owner, name] = repo.split("/");
|
|
181
|
+
return `repository(owner: ${JSON.stringify(owner)}, name: ${JSON.stringify(name)})`;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// After my PRs and Next up's issues: how far my PRs are behind their bases, the option order of org issue fields, and
|
|
185
|
+
// what the issues my PRs' descriptions refer to are [GH-01, ATT-03].
|
|
186
|
+
export function detailsQuery(prs: PullRequestNode[], orgs: string[], refs: IssueRef[] = []): { query: string; compares: Record<string, string> } {
|
|
180
187
|
const compares: Record<string, string> = {};
|
|
181
188
|
const fields = prs.map((pr, index) => {
|
|
182
189
|
compares[`c${index}`] = prKey(pr);
|
|
183
|
-
|
|
184
|
-
return `c${index}: repository(owner: ${JSON.stringify(owner)}, name: ${JSON.stringify(name)}) {
|
|
190
|
+
return `c${index}: ${repository(pr.repository.nameWithOwner)} {
|
|
185
191
|
ref(qualifiedName: ${JSON.stringify(`refs/heads/${pr.baseRefName}`)}) { compare(headRef: ${JSON.stringify(pr.headRefName)}) { behindBy } }
|
|
186
192
|
}`;
|
|
187
193
|
});
|
|
194
|
+
refs.forEach((ref, index) =>
|
|
195
|
+
fields.push(`i${index}: ${repository(ref.repo)} {
|
|
196
|
+
issueOrPullRequest(number: ${ref.number}) { ... on Issue { number title url state repository { nameWithOwner } } }
|
|
197
|
+
}`),
|
|
198
|
+
);
|
|
188
199
|
orgs.forEach((org, index) =>
|
|
189
200
|
fields.push(`o${index}: organization(login: ${JSON.stringify(org)}) {
|
|
190
201
|
issueFields(first: 50) { nodes { ... on IssueFieldSingleSelect { name options { name } } } }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Which issue a PR or stack works on, from what GitHub links and what its descriptions say [ATT-03, HIS-01].
|
|
2
|
+
|
|
3
|
+
export interface IssueRef {
|
|
4
|
+
repo: string;
|
|
5
|
+
number: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// "#12", "acme/shop#12" or a link to an issue; links to PRs are left out.
|
|
9
|
+
const REF = String.raw`(?:https://github\.com/([\w.-]+/[\w.-]+)/issues/(\d+)|(?<![\w/#&])(?:([\w.-]+/[\w.-]+))?#(\d+))(?![\w-])`;
|
|
10
|
+
// GitHub's closing keywords [docs: linking a pull request to an issue].
|
|
11
|
+
const CLOSING = new RegExp(String.raw`\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\b:?\s+${REF}`, "gi");
|
|
12
|
+
const ANY = new RegExp(REF, "gi");
|
|
13
|
+
|
|
14
|
+
// What counts as said: not code, quoted replies or template comments.
|
|
15
|
+
function prose(body: string): string {
|
|
16
|
+
return body
|
|
17
|
+
.replace(/\r/g, "")
|
|
18
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
19
|
+
.replace(/^\s*(```|~~~)[\s\S]*?^\s*\1.*$/gm, "")
|
|
20
|
+
.replace(/`[^`\n]*`/g, "")
|
|
21
|
+
.replace(/^\s*>.*$/gm, "");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function refs(body: string | undefined, repo: string, pattern: RegExp): IssueRef[] {
|
|
25
|
+
const found = new Map<string, IssueRef>();
|
|
26
|
+
for (const match of prose(body ?? "").matchAll(pattern)) {
|
|
27
|
+
const ref = { repo: match[1] ?? match[3] ?? repo, number: Number(match[2] ?? match[4]) };
|
|
28
|
+
found.set(refKey(ref), ref);
|
|
29
|
+
}
|
|
30
|
+
return [...found.values()];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const refKey = (ref: IssueRef) => `${ref.repo}#${ref.number}`;
|
|
34
|
+
export const closingRefs = (body: string | undefined, repo: string) => refs(body, repo, CLOSING);
|
|
35
|
+
export const mentionedRefs = (body: string | undefined, repo: string) => refs(body, repo, ANY);
|
|
36
|
+
|
|
37
|
+
export interface LinkedPr {
|
|
38
|
+
repo: string;
|
|
39
|
+
body?: string;
|
|
40
|
+
// Issues GitHub links it to with a closing keyword, as "owner/name#number".
|
|
41
|
+
linked: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The issue for PRs listed bottom first, strongest evidence first: what GitHub links, then a closing keyword in a
|
|
45
|
+
// description, then the one issue the bottom PR's description mentions. GitHub links only PRs into the default branch,
|
|
46
|
+
// so a stack's upper PRs need their descriptions read. `isIssue` says whether a reference is an issue that counts, which
|
|
47
|
+
// rules out PRs and closed issues; several mentioned issues are too ambiguous to pick from.
|
|
48
|
+
export function issueFor(prs: LinkedPr[], isIssue: (key: string) => boolean): string | undefined {
|
|
49
|
+
for (const pr of prs) {
|
|
50
|
+
const linked = pr.linked.find(isIssue);
|
|
51
|
+
if (linked) return linked;
|
|
52
|
+
}
|
|
53
|
+
for (const pr of prs) {
|
|
54
|
+
const closing = closingRefs(pr.body, pr.repo).map(refKey).find(isIssue);
|
|
55
|
+
if (closing) return closing;
|
|
56
|
+
}
|
|
57
|
+
const mentioned = prs[0] ? mentionedRefs(prs[0].body, prs[0].repo).map(refKey).filter(isIssue) : [];
|
|
58
|
+
return mentioned.length === 1 ? mentioned[0] : undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The references in my PRs' descriptions to look up, at most `max`: my PRs themselves and what GitHub links are known.
|
|
62
|
+
type Node = { number: number; repository: { nameWithOwner: string } };
|
|
63
|
+
const nodeKey = (node: Node) => `${node.repository.nameWithOwner}#${node.number}`;
|
|
64
|
+
|
|
65
|
+
export function toLookUp(prs: (Node & { body?: string; closingIssuesReferences: { nodes: Node[] } })[], max = 100): IssueRef[] {
|
|
66
|
+
const known = new Set(prs.flatMap((pr) => [pr, ...pr.closingIssuesReferences.nodes].map(nodeKey)));
|
|
67
|
+
const wanted = new Map<string, IssueRef>();
|
|
68
|
+
for (const pr of prs) for (const ref of mentionedRefs(pr.body, pr.repository.nameWithOwner)) if (!known.has(refKey(ref))) wanted.set(refKey(ref), ref);
|
|
69
|
+
return [...wanted.values()].slice(0, max);
|
|
70
|
+
}
|
package/server/service.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { AttentionConfig, githubRepoOf } from "../shared/config";
|
|
|
4
4
|
import { classify, classifyHistory } from "./classify";
|
|
5
5
|
import { FIXTURE, graphql } from "./gh";
|
|
6
6
|
import { fixture, FIXTURE_AGENTS } from "./fixture";
|
|
7
|
-
import type { Details, HistoryResult, LiveResult } from "./github-types";
|
|
8
|
-
import { detailsQuery, HISTORY_SEARCHES, mergeUnclaimed, type SearchName, searchQuery, searchVariables, type UnclaimedSearch, unclaimedSearches } from "./queries";
|
|
7
|
+
import type { Details, HistoryResult, LinkedIssue, LiveResult } from "./github-types";
|
|
8
|
+
import { detailsQuery, HISTORY_SEARCHES, mergeUnclaimed, prKey, type SearchName, searchQuery, searchVariables, type UnclaimedSearch, unclaimedSearches } from "./queries";
|
|
9
|
+
import { toLookUp } from "./references";
|
|
9
10
|
import { loadConfig, loadState, moveOldFiles, saveCodeRepo, saveCoverage, saveFollowThreads, saveNextUpSources, saveState, State } from "./store";
|
|
10
11
|
import { applyPending, buildView, doneItem, type Effect, isPending, SETTLE_MS } from "./view";
|
|
11
12
|
|
|
@@ -258,15 +259,23 @@ export class AttentionService {
|
|
|
258
259
|
const needsOptions = [priority, effort].some((field) => field && !field.order);
|
|
259
260
|
const issues = [...data.unclaimed.nodes, ...data.assigned.nodes];
|
|
260
261
|
const orgs = needsOptions ? [...new Set(issues.map((issue) => issue?.repository?.nameWithOwner.split("/")[0]).filter(Boolean))] : [];
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
const refs = toLookUp(data.mine.nodes.filter((pr) => pr?.repository));
|
|
263
|
+
const details: Details = { behind: {}, fieldOptions: {}, issues: {} };
|
|
264
|
+
if (prs.length === 0 && orgs.length === 0 && refs.length === 0) return details;
|
|
265
|
+
const { query, compares } = detailsQuery(prs, orgs as string[], refs);
|
|
266
|
+
type Result = {
|
|
267
|
+
ref?: { compare: { behindBy: number } | null } | null;
|
|
268
|
+
issueFields?: { nodes: { name?: string; options?: { name: string }[] }[] };
|
|
269
|
+
issueOrPullRequest?: (LinkedIssue & { state?: string }) | null;
|
|
270
|
+
} | null;
|
|
271
|
+
// A reference to a repo I can't see fails only its own field.
|
|
265
272
|
const result = await graphql<Record<string, Result>>(query);
|
|
266
273
|
for (const [alias, value] of Object.entries(result)) {
|
|
267
274
|
const behindBy = value?.ref?.compare?.behindBy;
|
|
268
275
|
if (typeof behindBy === "number") details.behind[compares[alias]] = behindBy;
|
|
269
276
|
for (const field of value?.issueFields?.nodes ?? []) if (field.name && field.options) details.fieldOptions[field.name] ??= field.options.map((o) => o.name);
|
|
277
|
+
const issue = value?.issueOrPullRequest; // empty for a PR
|
|
278
|
+
if (issue?.state === "OPEN") details.issues[prKey(issue)] = { number: issue.number, title: issue.title, url: issue.url, repository: issue.repository };
|
|
270
279
|
}
|
|
271
280
|
return details;
|
|
272
281
|
}
|
package/shared/feedback.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
export const FEEDBACK_REPO = "andrioid/paseo-attention-span";
|
|
6
6
|
|
|
7
7
|
export interface FeedbackInfo {
|
|
8
|
-
//
|
|
8
|
+
// An empty directory made for the session, so archiving its workspace closes it and nothing lands in the source.
|
|
9
9
|
cwd: string;
|
|
10
|
-
|
|
10
|
+
// The plugin's own source, which the agent reads; null when it can't be found.
|
|
11
|
+
source: string | null;
|
|
11
12
|
version: string | null;
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -18,7 +19,7 @@ export const feedbackItemKey = (kind: FeedbackKind) => `feedback:${kind}`;
|
|
|
18
19
|
|
|
19
20
|
export interface FeedbackContext {
|
|
20
21
|
message: string;
|
|
21
|
-
// The plugin's source on this host,
|
|
22
|
+
// The plugin's source on this host, and its version.
|
|
22
23
|
dir: string | null;
|
|
23
24
|
version: string | null;
|
|
24
25
|
device: "phone" | "desktop";
|
|
@@ -37,7 +38,7 @@ They wrote:
|
|
|
37
38
|
Context: {{context}}
|
|
38
39
|
|
|
39
40
|
How to work:
|
|
40
|
-
-
|
|
41
|
+
- You are in an empty scratch directory made for this session: put temporary files here. {{where}}
|
|
41
42
|
- Reply in the language they write in. Write the post in English, in their voice ("I …").
|
|
42
43
|
- Ask one question at a time, and only what the checklist below still needs. Offer likely answers when you can. After about five questions, draft with what you have and say what's missing.
|
|
43
44
|
- Read requirements.yaml, docs/architecture.md and the code to understand what they describe. Find the Paseo version with \`paseo --version\`.
|
|
@@ -48,11 +49,11 @@ Where it goes: an issue if a maintainer could finish it and close it. Otherwise
|
|
|
48
49
|
|
|
49
50
|
Keep posts skimmable: a few short lines up front, and anything longer (environment, logs, error text, likely cause, background) in a collapsed \`<details><summary>…</summary>\` block.
|
|
50
51
|
|
|
51
|
-
Show the whole draft, title included, then ask with your question tool: Post it / Change something / Cancel. Without a question tool, ask in plain text and post only after they reply "post".
|
|
52
|
-
- Issue: \`gh issue create --repo ${FEEDBACK_REPO} --title … --body-file …\`, with the body in a
|
|
52
|
+
Show the whole draft, title included, then ask with your question tool: Post it / Change something / Cancel. Without a question tool, ask in plain text and post only after they reply "post".
|
|
53
|
+
- Issue: \`gh issue create --repo ${FEEDBACK_REPO} --title … --body-file …\`, with the body in a file in the scratch directory.
|
|
53
54
|
- Discussion: look up the repository ID and the category by its slug (\`ideas\` or \`q-a\`) with \`gh api graphql\` (\`repository { id discussionCategories { nodes { id slug } } }\`), then call the \`createDiscussion\` mutation.
|
|
54
55
|
|
|
55
|
-
Reply with the link, then
|
|
56
|
+
Reply with the link, then close this session: archive its workspace with Paseo's archive_workspace tool (find its ID with list_workspaces by the scratch directory). It was made only for this session. Without that tool, use archive_agent.`;
|
|
56
57
|
|
|
57
58
|
const PROBLEM = `This is a problem. Work out which kind it is, then cover its checklist:
|
|
58
59
|
- Broken: what they did, step by step; what they expected; what happened, with any error text; every time or only sometimes.
|
|
@@ -75,7 +76,7 @@ export function feedbackPrompt(kind: FeedbackKind, input: FeedbackContext): stri
|
|
|
75
76
|
input.refreshError ? `the last refresh failed: ${input.refreshError}` : null,
|
|
76
77
|
].filter(Boolean);
|
|
77
78
|
const where = input.dir
|
|
78
|
-
? `
|
|
79
|
+
? `The plugin's installed source is at ${input.dir}: read it there, and don't change anything in it.`
|
|
79
80
|
: `The plugin's source isn't on this host: read it from GitHub with \`gh api repos/${FEEDBACK_REPO}/contents/<path>\`.`;
|
|
80
81
|
const values: Record<string, string> = { message: input.message.trim().replace(/\n/g, "\n> "), context: `${facts.join(", ")}.`, where };
|
|
81
82
|
const shared = SHARED.replace(/\{\{(\w+)\}\}/g, (match, name: string) => values[name] ?? match);
|