@andrioid/paseo-attention-span 0.4.11 → 0.4.12

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.
@@ -144,7 +144,7 @@ While an item has an open session, its main action is **Open session** instead,
144
144
  - **Issues kept apart from the code** [SES-07]: an issue starts in the repo `codeRepos` maps its repo to, from that repo's default branch (one `gh repo view`). When neither has a project, Start asks which project holds the code, saves the answer to `codeRepos` and carries on. Claim waits until then, so a start that can't go anywhere doesn't leave the issue taken. The prompt and Claim keep using the issue's own repo.
145
145
  - **Workspace**: a worktree with `checkout-pr` for PRs, or `branch-off` from the default branch for issues.
146
146
  - **Profile**: looked up per reason in `config.json`, then materialised into `create_agent` from `list_profiles`. A missing `review` profile falls back to `default`; a missing `default` starts the agent with Paseo's defaults: the first ready provider and its default model. The plugin's server reads the provider list (`providers.ready`), because the app's own snapshot can arrive compact, with no entries. Options ▾ still offers provider and model [SES-06].
147
- - **Prompt**: a built-in template per session type, filled with the item's context. A template in `config.json` replaces the built-in one [SES-04]. The context is fetched when the session starts, mostly from `gh`'s JSON output: `gh pr checks` and `gh run view --log-failed` for Fix, `gh pr view`/`gh issue view` for Review and Start, one GraphQL query for unresolved threads for Address. Rebase uses the stack already in the item.
147
+ - **Prompt**: a built-in template per session type, filled with the item's context. A template in `config.json` replaces the built-in one [SES-04]. The context is fetched when the session starts, mostly from `gh`'s JSON output: `gh pr checks` and `gh run view --log-failed` for Fix, `gh pr view`/`gh issue view` for Review and Start, one GraphQL query for unresolved threads for Address. Rebase uses the stack already in the item. Descriptions go in whole; Review of a stack links each PR asking for review instead. Comments and review threads are cut, but a cut keeps the links from the part it drops, and the prompt says how many comments, reviews or threads it left out, with the item's URL.
148
148
 
149
149
  ## Feedback
150
150
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrioid/paseo-attention-span",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
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/context.ts CHANGED
@@ -4,10 +4,32 @@ import { graphql, runGh } from "./gh";
4
4
 
5
5
  // Context for a session prompt, fetched deterministically when a session starts [SES-04].
6
6
 
7
- const clip = (text: string | null | undefined, max = 4000) => {
7
+ // Cuts long text, but lists every link from the cut part so the agent can still open them, like a Jam recording at the
8
+ // bottom of a support issue.
9
+ export function clip(text: string | null | undefined, max: number): string {
8
10
  const value = (text ?? "").trim();
9
- return value.length > max ? `${value.slice(0, max)}\n…(truncated)` : value;
10
- };
11
+ if (value.length <= max) return value;
12
+ const links = (part: string) => [...part.matchAll(/(.?)(https?:\/\/[^\s<>"'`\[\]]+)/gi)].map(([, before, url]) => trimLink(url, before));
13
+ const kept = new Set(links(value.slice(0, max)));
14
+ // A link the cut splits in half is listed whole.
15
+ const cut = [...new Set(links(value))].filter((url) => !kept.has(url));
16
+ const listed = cut.length ? `\nLinks in the cut part:\n${cut.map((url) => `- ${url}`).join("\n")}` : "";
17
+ return `${value.slice(0, max)}\n…(truncated)${listed}`;
18
+ }
19
+
20
+ // A link runs to the first space, quote or square bracket. Trailing punctuation belongs to the sentence, a closing
21
+ // parenthesis only when the link has no opening one (Markdown's [text](url)), and * or _ only when they also open it
22
+ // (**url**, _url_).
23
+ function trimLink(url: string, before: string): string {
24
+ let link = url;
25
+ for (let previous = ""; previous !== link; ) {
26
+ previous = link;
27
+ link = link.replace(/[.,;:!?]+$/, "");
28
+ if (link.endsWith(")") && (link.match(/\(/g)?.length ?? 0) < (link.match(/\)/g)?.length ?? 0)) link = link.slice(0, -1);
29
+ if ((before === "*" || before === "_") && link.endsWith(before)) link = link.replace(before === "*" ? /\*+$/ : /_+$/, "");
30
+ }
31
+ return link;
32
+ }
11
33
 
12
34
  async function ghJson<T>(args: string[]): Promise<T> {
13
35
  // `gh pr checks` exits non-zero when checks fail but still prints the JSON.
@@ -26,26 +48,30 @@ export async function sessionContext(kind: SessionKind, target: Target): Promise
26
48
  if (kind === "fix") return failingChecks(ref, target.repo);
27
49
  if (kind === "address") return reviewFeedback(target);
28
50
 
29
- // Review of a stack: every branch, and the description and latest comments of each PR asking for my review [ATT-04].
51
+ // Review of a stack: every branch, with a link to each PR asking for my review; the agent reads what it needs [ATT-04].
30
52
  const stack = target.stack ?? [];
31
53
  if (kind === "review" && stack.length > 1) {
32
- const asking = stack.filter((pr) => pr.review);
33
- const lines = stack.map((pr) => `${branchLine(pr)}${pr.review ? ", review requested" : ", mine"}`);
34
- const prs = await Promise.all(asking.map(async (pr) => `#${pr.number}\n${await conversation([String(pr.number), "--repo", target.repo], "pr")}`));
35
- return [`Stack, bottom first:\n${lines.join("\n")}`, ...prs].join("\n\n");
54
+ const lines = stack.map((pr) => `${branchLine(pr)}${pr.review ? `, review requested: https://github.com/${target.repo}/pull/${pr.number}` : ", mine"}`);
55
+ return `Stack, bottom first:\n${lines.join("\n")}`;
36
56
  }
37
57
 
38
- // review, start: the description and the latest comments.
39
- return conversation(ref, target.kind);
58
+ // review, start: the whole description and the latest comments.
59
+ return conversation(ref, target);
40
60
  }
41
61
 
42
62
  const branchLine = (pr: StackPr) => `- #${pr.number}: ${pr.head} (on ${pr.base})`;
43
63
 
44
- async function conversation(ref: string[], kind: Target["kind"]): Promise<string> {
45
- type View = { body: string; comments: { author: { login: string }; body: string }[] };
46
- const view = await ghJson<View>([kind === "pr" ? "pr" : "issue", "view", ...ref, "--json", "body,comments"]);
47
- const comments = view.comments.slice(-5).map((c) => `@${c.author.login}: ${clip(c.body, 800)}`);
48
- return [`Description:\n${clip(view.body) || "(empty)"}`, comments.length ? `Recent comments:\n${comments.join("\n\n")}` : ""].filter(Boolean).join("\n\n");
64
+ const RECENT_COMMENTS = 5;
65
+
66
+ async function conversation(ref: string[], target: Target): Promise<string> {
67
+ type View = { body: string; comments: { author: { login: string } | null; body: string }[] };
68
+ const view = await ghJson<View>([target.kind === "pr" ? "pr" : "issue", "view", ...ref, "--json", "body,comments"]);
69
+ const comments = view.comments.slice(-RECENT_COMMENTS).map((c) => `@${c.author?.login ?? "ghost"}: ${clip(c.body, 800)}`);
70
+ const older = view.comments.length > RECENT_COMMENTS ? `Showing the last ${RECENT_COMMENTS} of ${view.comments.length} comments; the rest are at ${target.url}` : "";
71
+ // The description goes in whole: GitHub caps it at 65,536 characters, and its links are often at the bottom.
72
+ return [`Description:\n${(view.body ?? "").trim() || "(empty)"}`, comments.length ? `Recent comments:\n${[older, ...comments].filter(Boolean).join("\n\n")}` : ""]
73
+ .filter(Boolean)
74
+ .join("\n\n");
49
75
  }
50
76
 
51
77
  export async function defaultBranch(repo: string): Promise<string | null> {
@@ -66,6 +92,13 @@ async function failingChecks(ref: string[], repo: string): Promise<string> {
66
92
  return [`Failing checks:\n${failed.map((check) => `- ${check.name} ${check.link}`).join("\n")}`, ...logs].join("\n\n");
67
93
  }
68
94
 
95
+ // What one page of a review query leaves out, with where to read the rest.
96
+ const notShown = (count: number, what: string, url: string) => (count > 0 ? `${count} ${what} not shown, see ${url}` : "");
97
+
98
+ const THREADS = 100;
99
+ const THREAD_COMMENTS = 20;
100
+ const REVIEWS = 20;
101
+
69
102
  // gh has no command for unresolved review threads, so this one is GraphQL.
70
103
  async function reviewFeedback(target: Target): Promise<string> {
71
104
  type Author = { login: string } | null;
@@ -73,16 +106,19 @@ async function reviewFeedback(target: Target): Promise<string> {
73
106
  const data = await graphql<{
74
107
  repository: {
75
108
  pullRequest: {
76
- reviews: { nodes: { author: Author; state: string; body: string }[] };
77
- reviewThreads: { nodes: { isResolved: boolean; path: string; line: number | null; comments: { nodes: { author: Author; body: string }[] } }[] };
109
+ reviews: { totalCount: number; nodes: { author: Author; state: string; body: string }[] };
110
+ reviewThreads: {
111
+ totalCount: number;
112
+ nodes: { isResolved: boolean; path: string; line: number | null; comments: { totalCount: number; nodes: { author: Author; body: string }[] } }[];
113
+ };
78
114
  };
79
115
  };
80
116
  }>(
81
117
  `query($owner: String!, $name: String!, $number: Int!) {
82
118
  repository(owner: $owner, name: $name) {
83
119
  pullRequest(number: $number) {
84
- reviews(last: 20, states: [CHANGES_REQUESTED, COMMENTED]) { nodes { author { login } state body } }
85
- reviewThreads(first: 100) { nodes { isResolved path line comments(first: 20) { nodes { author { login } body } } } }
120
+ reviews(last: ${REVIEWS}, states: [CHANGES_REQUESTED, COMMENTED]) { totalCount nodes { author { login } state body } }
121
+ reviewThreads(first: ${THREADS}) { totalCount nodes { isResolved path line comments(first: ${THREAD_COMMENTS}) { totalCount nodes { author { login } body } } } }
86
122
  }
87
123
  }
88
124
  }`,
@@ -93,8 +129,20 @@ async function reviewFeedback(target: Target): Promise<string> {
93
129
  const summaries = reviews.nodes.filter((r) => r.body.trim()).map((r) => `- ${who(r.author)} (${r.state.toLowerCase()}): ${clip(r.body, 1500)}`);
94
130
  const threads = reviewThreads.nodes
95
131
  .filter((t) => !t.isResolved)
96
- .map((t) => `- ${t.path}${t.line ? `:${t.line}` : ""}\n${t.comments.nodes.map((c) => ` ${who(c.author)}: ${clip(c.body, 1500).replace(/\n/g, "\n ")}`).join("\n")}`);
97
- return [summaries.length ? `Review summaries:\n${summaries.join("\n")}` : "", threads.length ? `Unresolved review threads:\n${threads.join("\n")}` : "No unresolved review threads."]
132
+ .map((t) => {
133
+ const comments = t.comments.nodes.map((c) => ` ${who(c.author)}: ${clip(c.body, 1500).replace(/\n/g, "\n ")}`);
134
+ const more = notShown(t.comments.totalCount - t.comments.nodes.length, "more comments", target.url);
135
+ return [`- ${t.path}${t.line ? `:${t.line}` : ""}`, ...comments, more && ` ${more}`].filter(Boolean).join("\n");
136
+ });
137
+ // Older reviews and later threads past one page are left out; say so, since some of those threads may be unresolved.
138
+ const olderReviews = notShown(reviews.totalCount - reviews.nodes.length, "older reviews", target.url);
139
+ const laterThreads = notShown(reviewThreads.totalCount - reviewThreads.nodes.length, "more review threads (resolved or not)", target.url);
140
+ return [
141
+ summaries.length ? `Review summaries:\n${summaries.join("\n")}` : "",
142
+ threads.length ? `Unresolved review threads:\n${threads.join("\n")}` : laterThreads ? "" : "No unresolved review threads.",
143
+ olderReviews,
144
+ laterThreads,
145
+ ]
98
146
  .filter(Boolean)
99
147
  .join("\n\n");
100
148
  }
package/shared/prompts.ts CHANGED
@@ -65,7 +65,7 @@ Read the issue and the code it touches, then propose a plan before changing anyt
65
65
  // Review of a stack, while config.json doesn't replace the review template: one session for every PR asking for my review [ATT-04].
66
66
  export const REVIEW_STACK_TEMPLATE = `Review the pull requests {{review}} in {{repo}}, part of the stack {{stack}} (bottom first). You are in a checkout of the top branch, {{head}}, which has every PR's changes.
67
67
 
68
- 1. Review: for each of {{review}}, read its description and its diff against its own base (\`git diff origin/<base>...origin/<head>\`, branches below). Review only those; the rest of the stack is context.
68
+ 1. Review: for each of {{review}}, read its description (linked below) and its diff against its own base (\`git diff origin/<base>...origin/<head>\`, branches below). Review only those; the rest of the stack is context.
69
69
  2. Investigate: dig into anything risky or unclear in the code they touch.
70
70
  3. ${SWEEP}
71
71
  4. Report back, for each PR: