ai-agentmanager 1.22.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/cli.js CHANGED
@@ -8,6 +8,7 @@ import { api, BASE, ensureDaemon, health, isRunning, waitForExit } from './clien
8
8
  import { about, latestRelease } from './about.js';
9
9
  import { issuesMarkdown } from './issues.js';
10
10
  import { designsMarkdown } from './designs.js';
11
+ import { VERDICT_LABEL } from './reviews.js';
11
12
 
12
13
  const tty = process.stdout.isTTY;
13
14
  const c = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
@@ -673,16 +674,17 @@ export async function main(argv) {
673
674
  .action(async (opts) => {
674
675
  await daemon();
675
676
  const v = await api('GET', '/issues');
676
- const rows = opts.all ? v.rows : v.rows.filter((r) => r.group === 'you' || r.group === 'new');
677
+ const rows = opts.all ? v.rows.filter((r) => r.group !== 'removed') : v.rows.filter((r) => r.group === 'you' || r.group === 'new');
677
678
  if (opts.json) return console.log(JSON.stringify({ ...v, rows }, null, 2));
678
679
  if (opts.markdown) return console.log(issuesMarkdown(rows));
679
680
  if (!rows.length) return console.log(dim(opts.all ? 'No agents work on Jira or Linear issues.' : 'Nothing to start or review. --all shows the rest.'));
680
681
  for (const r of rows) {
681
682
  const pr = r.pr ? ` PR #${r.pr.number ?? '?'}` : '';
682
683
  console.log(`${bold(r.key.padEnd(10))} ${r.jira?.status ? dim(`[${r.jira.status}] `) : ''}${truncate(r.title ?? '', 60)}`);
684
+ if (r.synopsis) console.log(dim(` ${truncate(r.synopsis, 110)}`));
683
685
  console.log(` ${r.group === 'you' || r.group === 'new' ? yellow(r.note) : r.note}${pr} ${dim(r.agent ? `agent ${r.agent.name} (${r.agent.id})` : `start: agentmgr issues start ${r.key}`)}`);
684
686
  }
685
- const others = v.rows.length - rows.length;
687
+ const others = v.rows.filter((r) => r.group !== 'removed').length - rows.length;
686
688
  if (others) console.log(dim(`\n${others} more with agents still on them or finished: --all`));
687
689
  if (!v.jira.signedIn) console.log(dim('Jira status needs your site, email and API token: Settings → Jira.'));
688
690
  });
@@ -716,6 +718,18 @@ export async function main(argv) {
716
718
  const r = await api('POST', '/issues/dismiss', { keys });
717
719
  console.log(`${r.dismissed} dismissed`);
718
720
  });
721
+ issuesCmd
722
+ .command('set')
723
+ .description('Your action on issues, kept across restarts and updates: assign (start an agent), skip, done, remove, or clear')
724
+ .argument('<action>', 'assign | skip | done | remove | clear')
725
+ .argument('<keys...>', 'issue keys, e.g. OPS-7 OPS-9')
726
+ .action(async (action, keys) => {
727
+ await daemon();
728
+ const r = await api('POST', '/issues/action', { keys, action: action === 'clear' ? null : action });
729
+ for (const x of r.started) console.log(`${green('✓')} ${bold(x.key)} → agent ${x.agent.name} (${x.agent.id})`);
730
+ if (r.set.length) console.log(`${green('✓')} ${r.set.join(', ')}: ${action === 'clear' ? 'cleared' : action}`);
731
+ for (const x of r.failed) console.log(`${red('!')} ${bold(x.key)}: ${x.reason}`);
732
+ });
719
733
 
720
734
  program
721
735
  .command('designs')
@@ -738,6 +752,73 @@ export async function main(argv) {
738
752
  }
739
753
  });
740
754
 
755
+ program
756
+ .command('review')
757
+ .description("Start a reviewer agent on someone else's pull request: it asks the critical questions and finds what blocks approval; nothing is posted")
758
+ .argument('<pr>', 'the pull request link')
759
+ .option('-p, --project <project>', 'the project to check it out in (default: the one whose repository it is)')
760
+ .option('--notes <text>', 'what to look at closely')
761
+ .action(async (url, o) => {
762
+ await daemon();
763
+ const a = await api('POST', '/reviews', { url, project: o.project, notes: o.notes });
764
+ console.log(`${green('✓')} reviewer ${bold(a.name)} (${a.id}) started; see it with agentmgr reviews show ${a.id}`);
765
+ });
766
+ const reviewsCmd = program.command('reviews').description('Pull requests you review: reviewer agents and their verdicts, and requests with no reviewer yet');
767
+ const verdictText = (r) => {
768
+ if (!r.agent) return yellow('requested, no reviewer');
769
+ if (!r.review?.verdict) return dim(r.status);
770
+ const label = VERDICT_LABEL[r.review.verdict];
771
+ const text = r.review.openBlockers ? `${label}: ${r.review.openBlockers} blocker${r.review.openBlockers === 1 ? '' : 's'}` : label;
772
+ return r.review.verdict === 'blocked' ? red(text) : green(text);
773
+ };
774
+ reviewsCmd
775
+ .command('ls', { isDefault: true })
776
+ .description('The list, stale and blocked ones first')
777
+ .option('--markdown', 'print every review as Markdown')
778
+ .option('--json', 'print JSON')
779
+ .action(async (opts) => {
780
+ await daemon();
781
+ if (opts.markdown) return console.log((await api('GET', '/reviews?format=markdown')).markdown);
782
+ const { rows } = await api('GET', '/reviews');
783
+ if (opts.json) return console.log(JSON.stringify(rows, null, 2));
784
+ if (!rows.length) return console.log(dim('No reviews, and no pull requests waiting for your review.'));
785
+ for (const r of rows) {
786
+ console.log(`${bold(`${r.pr.repo ?? ''}#${r.pr.number}`)} ${truncate(r.pr.title ?? '', 60)} ${verdictText(r)}${r.stale ? yellow(' (author pushed since)') : ''}${r.posted ? dim(' posted') : ''}`);
787
+ console.log(dim(` ${r.pr.url}${r.agent ? ` agent ${r.agent.name} (${r.agent.id})` : ''}`));
788
+ }
789
+ });
790
+ reviewsCmd
791
+ .command('show')
792
+ .description("A reviewer's review: verdict, blockers, questions for the author, risks")
793
+ .argument('<agent>')
794
+ .action(async (ref) => {
795
+ await daemon();
796
+ const a = await resolveAgent(ref);
797
+ const r = await api('GET', `/reviews/${a.id}`);
798
+ console.log(r.markdown);
799
+ if (r.review) console.log(dim(`\nIds to post: ${[...r.review.blockers.filter((b) => b.status === 'open'), ...r.review.questions, ...r.review.nits].map((x) => x.id).join(' ') || 'none'}`));
800
+ });
801
+ reviewsCmd
802
+ .command('post')
803
+ .description('Post a pending review on GitHub, under your name, with the picked items (default: open blockers and questions); you submit it there')
804
+ .argument('<agent>')
805
+ .argument('[ids...]', 'items to send, e.g. b1 q2 n1')
806
+ .action(async (ref, ids) => {
807
+ await daemon();
808
+ const a = await resolveAgent(ref);
809
+ const r = await api('POST', `/reviews/${a.id}/post`, { ids: ids.length ? ids : null });
810
+ console.log(`${green('✓')} pending review with ${r.ids.length} item${r.ids.length === 1 ? '' : 's'}: finish and submit it at ${r.url}${r.moved ? dim(`\n ${r.moved} line comment(s) went in the body: their lines aren't in the diff`) : ''}`);
811
+ });
812
+ reviewsCmd
813
+ .command('dismiss')
814
+ .description("Take requested pull requests off the list (you won't have an agent review them)")
815
+ .argument('<prs...>')
816
+ .action(async (urls) => {
817
+ await daemon();
818
+ const r = await api('POST', '/reviews/dismiss', { urls });
819
+ console.log(`${r.dismissed} dismissed`);
820
+ });
821
+
741
822
  const valueCmd = program.command('value').description('What the delivered work is worth (AI estimates you can correct), by day, week, month and quarter, with reports for management');
742
823
  const money = (n, cur = 'USD') => (n == null ? '—' : new Intl.NumberFormat('en-US', { style: 'currency', currency: cur, maximumFractionDigits: 0 }).format(n));
743
824
  valueCmd
package/src/issues.js CHANGED
@@ -9,6 +9,7 @@ import { needsOf } from './standup.js';
9
9
 
10
10
  const ISSUE_KEY = /^[A-Z][A-Z0-9_]+-\d+$/;
11
11
  const MAX_PROPOSED = 200;
12
+ const MAX_ACTIONS = 1000;
12
13
  const err = (status, message) => Object.assign(new Error(message), { status });
13
14
  const NEEDS = new Set(['prompt', 'waiting', 'plan', 'question']);
14
15
 
@@ -16,6 +17,7 @@ const NEEDS = new Set(['prompt', 'waiting', 'plan', 'question']);
16
17
  // In the order they're listed.
17
18
  export const GROUPS = {
18
19
  proposed: 'new',
20
+ assigned: 'new',
19
21
  needs: 'you',
20
22
  review: 'you',
21
23
  blocked: 'you',
@@ -26,6 +28,16 @@ export const GROUPS = {
26
28
  closed: 'done',
27
29
  };
28
30
 
31
+ /**
32
+ * What you decided for an issue, kept in state.json so a restart or an update doesn't ask again:
33
+ * assign (an agent works on it), skip (not now), done (handled, by you or elsewhere), remove (off
34
+ * the list). Any of them can be changed later; skipped, done and removed issues aren't proposed or
35
+ * started by the assistant.
36
+ */
37
+ export const ACTIONS = ['assign', 'skip', 'done', 'remove'];
38
+ const SET_ASIDE = { skip: 'skipped', done: 'done', remove: 'removed' };
39
+ const ACTION_NOTE = { skip: 'Skipped by you', done: 'Marked done by you', remove: 'Removed by you' };
40
+
29
41
  /** The issue an agent works on: { key, url }, from the link its request starts with or one in it. */
30
42
  export function issueOf(v) {
31
43
  const lead = leadingJiraKey(v.intent);
@@ -90,20 +102,23 @@ function designOf(v, read) {
90
102
  * The summary's rows from agent views, those waiting for you first.
91
103
  * `read(agentId, name)` gives one of the agent's documents ('plan'), or null.
92
104
  */
93
- export function issueRows(views, jira = new Map(), read = () => null, proposed = []) {
105
+ export function issueRows(views, jira = new Map(), read = () => null, proposed = [], actions = {}, assigned = []) {
94
106
  const rank = Object.fromEntries(Object.keys(GROUPS).map((k, i) => [k, i]));
95
107
  const rows = [];
96
108
  // Issues proposed for agents, not started yet: they wait for you to tick them.
97
109
  for (const p of proposed) {
98
110
  const j = jira.get(p.key) ?? null;
111
+ const action = actions[p.key]?.action ?? (p.status === 'dismissed' ? 'remove' : null);
99
112
  rows.push({
100
113
  key: p.key,
101
114
  url: p.url,
102
115
  title: j?.summary ?? p.title,
116
+ synopsis: synopsisFor(j, p.title, null, j?.summary ?? p.title),
103
117
  jira: j ? { status: j.status, category: j.category } : null,
118
+ action,
104
119
  stage: 'proposed',
105
- group: 'new',
106
- note: `Not started${p.project ? ` (@${p.project})` : ''}: tick it to start an agent`,
120
+ group: SET_ASIDE[action] ?? 'new',
121
+ note: ACTION_NOTE[action] ?? `Not started${p.project ? ` (@${p.project})` : ''}: tick it to start an agent`,
107
122
  agent: null,
108
123
  proposal: { project: p.project ?? null, repo: p.repo ?? null, by: p.by ?? null, intent: p.intent },
109
124
  pr: null,
@@ -117,27 +132,69 @@ export function issueRows(views, jira = new Map(), read = () => null, proposed =
117
132
  if (v.kind === 'assistant') continue;
118
133
  const issue = issueOf(v);
119
134
  if (!issue) continue;
120
- const { stage, note, pr } = stageOf(v);
135
+ const { stage, note: where, pr } = stageOf(v);
121
136
  const j = jira.get(issue.key) ?? null;
137
+ const action = actions[issue.key]?.action ?? 'assign';
138
+ const note = ACTION_NOTE[action] ? `${ACTION_NOTE[action]} (${where.charAt(0).toLowerCase()}${where.slice(1)})` : where;
139
+ const design = designOf(v, read);
122
140
  rows.push({
123
141
  key: issue.key,
124
142
  url: issue.url,
125
143
  title: j?.summary ?? issue.title,
144
+ synopsis: synopsisFor(j, wordsAfterLink(v.intent), design?.summary, j?.summary ?? issue.title),
126
145
  jira: j ? { status: j.status, category: j.category } : null,
146
+ action,
127
147
  stage,
128
- group: GROUPS[stage],
148
+ group: SET_ASIDE[action] ?? GROUPS[stage],
129
149
  note: note.length > 200 ? `${note.slice(0, 199)}…` : note,
130
150
  agent: { id: v.id, name: v.name, project: v.projectInfo?.name ?? null, running: Boolean(v.runtime?.running), busy: Boolean(v.runtime?.busy), from: v.startedBy ? 'assistant' : v.trigger?.source ?? null },
131
151
  pr: pr ? { url: pr.url, number: pr.number ?? null, title: pr.title ?? null, state: pr.state, checks: pr.checks?.state ?? null, review: pr.review ?? null } : null,
132
152
  aiReview: v.aiReview?.verdict ?? null,
133
153
  plan: planOf(v, read),
134
- design: designOf(v, read),
154
+ design,
135
155
  updatedAt: v.activeAt ?? v.createdAt ?? null,
136
156
  });
137
157
  }
158
+ // Open issues assigned to you in Jira (epics too) that no agent or proposal covers yet.
159
+ const listed = new Set(rows.map((r) => r.key));
160
+ for (const i of assigned) {
161
+ if (listed.has(i.key)) continue;
162
+ listed.add(i.key);
163
+ const action = actions[i.key]?.action ?? null;
164
+ rows.push({
165
+ key: i.key,
166
+ url: i.url,
167
+ title: i.summary,
168
+ synopsis: i.synopsis ?? null,
169
+ type: i.type ?? null,
170
+ jira: { status: i.status, category: i.category },
171
+ action,
172
+ stage: 'assigned',
173
+ group: SET_ASIDE[action] ?? 'new',
174
+ note: ACTION_NOTE[action] ?? 'Assigned to you in Jira; no agent yet',
175
+ agent: null,
176
+ proposal: null,
177
+ pr: null,
178
+ aiReview: null,
179
+ plan: null,
180
+ design: null,
181
+ updatedAt: i.updated,
182
+ });
183
+ }
138
184
  return rows.sort((a, b) => rank[a.stage] - rank[b.stage] || String(b.updatedAt ?? '').localeCompare(String(a.updatedAt ?? '')));
139
185
  }
140
186
 
187
+ /**
188
+ * What the issue is about in a sentence or two: from its Jira description, else the agent's
189
+ * design doc summary, else the words the request had after the link (when they say more than
190
+ * the title).
191
+ */
192
+ function synopsisFor(j, words, designSummary, title) {
193
+ if (j?.synopsis) return j.synopsis;
194
+ if (designSummary) return designSummary.length > 280 ? `${designSummary.slice(0, 279)}…` : designSummary;
195
+ return words && words !== title ? words : null;
196
+ }
197
+
141
198
  const REVIEW = { writing: 'being written', review: 'waiting for your approval', approved: 'approved', changes: 'changes asked' };
142
199
 
143
200
  /** A plan in a few words: "3/5 steps, approved". */
@@ -180,9 +237,82 @@ export class ProposedIssues {
180
237
  return (this.store.data.proposedIssues ??= []);
181
238
  }
182
239
 
240
+ /** Your action per issue key: { action, at }. */
241
+ get actions() {
242
+ return (this.store.data.issueActions ??= {});
243
+ }
244
+
245
+ /** Skip, done or remove when you set one; dismissed before actions existed counts as remove. */
246
+ setAside(key) {
247
+ const a = this.actions[key]?.action ?? (this.all.find((p) => p.key === key)?.status === 'dismissed' ? 'remove' : null);
248
+ return SET_ASIDE[a] ? a : null;
249
+ }
250
+
183
251
  /** The ones waiting for you, without those an agent has taken up meanwhile. */
184
252
  waiting() {
185
- return this.all.filter((p) => p.status === 'waiting' && !this.agentFor(p.key));
253
+ return this.all.filter((p) => p.status === 'waiting' && !this.setAside(p.key) && !this.agentFor(p.key));
254
+ }
255
+
256
+ /** Every proposal no agent works on: waiting, skipped, done or removed (for the table). */
257
+ listed() {
258
+ return this.all.filter((p) => p.status !== 'started' && !this.agentFor(p.key));
259
+ }
260
+
261
+ /** The assistant doesn't start agents for issues you skipped, marked done or removed. */
262
+ refuseSetAside(intents = []) {
263
+ for (const text of intents) {
264
+ const key = leadingJiraKey(text);
265
+ const a = key && this.setAside(key);
266
+ if (a) throw err(409, `${key}: ${ACTION_NOTE[a].toLowerCase()}; no agent is started for it unless they change that under Jira`);
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Set your action on issues (null clears it). Assign starts an agent from the proposal when none
272
+ * works on the issue yet. Returns { set: [keys], started: [{ key, agent }], failed: [{ key, reason }] }.
273
+ */
274
+ setAction(keys = [], action = null) {
275
+ if (action !== null && !ACTIONS.includes(action)) throw err(400, `The action is one of ${ACTIONS.join(', ')}, or none to clear it`);
276
+ const set = [];
277
+ const started = [];
278
+ const failed = [];
279
+ for (const key of new Set(keys)) {
280
+ let p = this.all.find((x) => x.key === key);
281
+ let agent = this.agentFor(key);
282
+ const mine = !p && !agent ? (this.manager.assignedNow ?? []).find((i) => i.key === key) : null;
283
+ if (!p && !agent && !mine) {
284
+ failed.push({ key, reason: 'not on the list' });
285
+ continue;
286
+ }
287
+ // An issue assigned to you in Jira: assigning it makes the request from its link and summary.
288
+ if (action === 'assign' && mine) {
289
+ p = { key, url: mine.url, title: mine.summary, intent: `${mine.url} ${mine.summary ?? ''}`.trim().slice(0, 4000), project: null, repo: null, by: 'jira', status: 'waiting', at: new Date().toISOString() };
290
+ this.all.push(p);
291
+ }
292
+ if (action === 'assign' && !agent) {
293
+ p.status = 'waiting';
294
+ delete this.actions[key];
295
+ const r = this.start([key]);
296
+ if (r.failed.length) {
297
+ failed.push(...r.failed);
298
+ continue;
299
+ }
300
+ started.push(...r.started);
301
+ agent = r.started[0].agent;
302
+ }
303
+ // Assign is what an agent on it means anyway; only the others are kept.
304
+ if (SET_ASIDE[action]) this.actions[key] = { action, at: new Date().toISOString() };
305
+ else delete this.actions[key];
306
+ if (p?.status === 'dismissed') p.status = 'waiting';
307
+ set.push(key);
308
+ }
309
+ // Old decisions go first when the list grows long.
310
+ const keys_ = Object.keys(this.actions);
311
+ if (keys_.length > MAX_ACTIONS) {
312
+ for (const k of keys_.sort((a, b) => this.actions[a].at.localeCompare(this.actions[b].at)).slice(0, keys_.length - MAX_ACTIONS)) delete this.actions[k];
313
+ }
314
+ this.store.save();
315
+ return { set, started, failed };
186
316
  }
187
317
 
188
318
  agentFor(key) {
@@ -198,7 +328,8 @@ export class ProposedIssues {
198
328
  const agent = this.agentFor(key);
199
329
  if (agent) throw err(409, `An agent for ${key} already exists: ${agent.name} (${agent.id})`);
200
330
  const prev = this.all.find((p) => p.key === key);
201
- if (prev?.status === 'dismissed') throw err(409, `${key} was dismissed; not proposed again`);
331
+ const aside = this.setAside(key);
332
+ if (aside) throw err(409, `${key}: ${ACTION_NOTE[aside].toLowerCase()}; not proposed again`);
202
333
  if (prev?.status === 'started') throw err(409, `${key} was started already`);
203
334
  project = project ? String(project).trim().replace(/^@/, '') || null : null;
204
335
  if (project && !this.manager.resolveProject(project)) throw err(400, `No project @${project}; see agentmgr project ls`);
@@ -255,18 +386,8 @@ export class ProposedIssues {
255
386
  return { started, failed };
256
387
  }
257
388
 
258
- /** Not for an agent: off the list, and not proposed again. */
389
+ /** Not for an agent: off the list, and not proposed again (the remove action). */
259
390
  dismiss(keys = []) {
260
- const want = new Set(keys);
261
- let n = 0;
262
- for (const p of this.all) {
263
- if (want.has(p.key) && p.status === 'waiting') {
264
- p.status = 'dismissed';
265
- p.dismissedAt = new Date().toISOString();
266
- n++;
267
- }
268
- }
269
- this.store.save();
270
- return { dismissed: n };
391
+ return { dismissed: this.setAction(keys, 'remove').set.length };
271
392
  }
272
393
  }
package/src/jira.js CHANGED
@@ -72,6 +72,78 @@ export function wordsAfterLink(text) {
72
72
  return rest.replace(/^[-:–—,\s]+/, '').split('\n')[0].trim().slice(0, 200) || null;
73
73
  }
74
74
 
75
+ // Statuses that mean the work is over, whatever category a workflow puts them in.
76
+ const FINISHED = /^(closed|done|resolved|integrated|cancell?ed|won'?t (do|fix)|duplicate|rejected)$/i;
77
+
78
+ /**
79
+ * Open issues assigned to you on your Jira site (epics too): [{ key, url, summary, status,
80
+ * category, type, synopsis, updated }]. Needs the site, email and API token from Settings → Jira;
81
+ * null without them or when Jira can't be reached. Closed and integrated ones are left out.
82
+ */
83
+ export async function assignedIssues({ jira = loadJira(), fetchImpl = fetch, timeoutMs = 10_000, max = 100 } = {}) {
84
+ if (!jira.site || !jira.email || !jira.token) return null;
85
+ const headers = { accept: 'application/json', 'content-type': 'application/json', authorization: `Basic ${Buffer.from(`${jira.email}:${jira.token}`).toString('base64')}` };
86
+ const body = JSON.stringify({ jql: 'assignee = currentUser() AND statusCategory != Done ORDER BY updated DESC', fields: ['summary', 'status', 'issuetype', 'description', 'updated'], maxResults: max });
87
+ try {
88
+ const res = await fetchImpl(`${jira.site}/rest/api/3/search/jql`, { method: 'POST', headers, body, redirect: 'error', signal: AbortSignal.timeout(timeoutMs) });
89
+ if (!res.ok) return null;
90
+ const out = [];
91
+ for (const i of (await res.json())?.issues ?? []) {
92
+ const f = i?.fields ?? {};
93
+ const status = typeof f.status?.name === 'string' ? f.status.name.slice(0, 60) : null;
94
+ if (typeof i.key !== 'string' || !/^[A-Z][A-Z0-9_]+-\d+$/.test(i.key) || (status && FINISHED.test(status))) continue;
95
+ const synopsis = synopsisOf(f.description);
96
+ out.push({
97
+ key: i.key,
98
+ url: `${jira.site}/browse/${i.key}`,
99
+ summary: typeof f.summary === 'string' ? f.summary.trim().slice(0, 300) : null,
100
+ status,
101
+ category: typeof f.status?.statusCategory?.key === 'string' ? f.status.statusCategory.key : null,
102
+ type: typeof f.issuetype?.name === 'string' ? f.issuetype.name.slice(0, 40) : null,
103
+ ...(synopsis ? { synopsis } : {}),
104
+ updated: typeof f.updated === 'string' ? f.updated : null,
105
+ });
106
+ }
107
+ return out;
108
+ } catch {
109
+ return null;
110
+ }
111
+ }
112
+
113
+ /** The text of a Jira description: Atlassian document format (API v3), or plain text. */
114
+ export function descriptionText(d) {
115
+ if (typeof d === 'string') return d;
116
+ const out = [];
117
+ const walk = (n) => {
118
+ if (!n || typeof n !== 'object') return;
119
+ if (n.type === 'text' && typeof n.text === 'string') out.push(n.text);
120
+ else if (n.type === 'hardBreak') out.push(' ');
121
+ // Code is how, not what: left out of the synopsis.
122
+ if (n.type === 'codeBlock') return;
123
+ for (const c of Array.isArray(n.content) ? n.content : []) walk(c);
124
+ if (/^(paragraph|heading|listItem|blockquote|tableCell)$/.test(n.type)) out.push('\n');
125
+ };
126
+ walk(d);
127
+ return out.join('');
128
+ }
129
+
130
+ /** What an issue is about in a sentence or two, from its description; null when it has none. */
131
+ export function synopsisOf(description, max = 280) {
132
+ const text = descriptionText(description)
133
+ .split('\n')
134
+ .map((l) => l.trim())
135
+ // Jira's wiki markup and template headings carry no meaning on their own.
136
+ .filter((l) => l && !/^(h\d\.|\{code|\*?(description|summary|acceptance criteria|steps to reproduce)\*?:?$)/i.test(l))
137
+ .join(' ')
138
+ .replace(/\s+/g, ' ')
139
+ .trim();
140
+ if (!text) return null;
141
+ if (text.length <= max) return text;
142
+ const cut = text.slice(0, max);
143
+ const end = Math.max(cut.lastIndexOf('. '), cut.lastIndexOf('? '), cut.lastIndexOf('! '));
144
+ return end > max / 3 ? cut.slice(0, end + 1) : `${cut.slice(0, cut.lastIndexOf(' ') > 0 ? cut.lastIndexOf(' ') : max).trim()}…`;
145
+ }
146
+
75
147
  /**
76
148
  * The issue's summary, or null when it can't be had (not a site we contact, no access, offline).
77
149
  * `fetchImpl` and `allow` are for tests.
@@ -98,13 +170,14 @@ export async function issueFields({ key, site }, { jira = loadJira(), fetchImpl
98
170
  const headers = { accept: 'application/json' };
99
171
  if (configured && jira.email && jira.token) headers.authorization = `Basic ${Buffer.from(`${jira.email}:${jira.token}`).toString('base64')}`;
100
172
  try {
101
- const res = await fetchImpl(`${site}/rest/api/3/issue/${encodeURIComponent(key)}?fields=summary,status`, { headers, redirect: 'error', signal: AbortSignal.timeout(timeoutMs) });
173
+ const res = await fetchImpl(`${site}/rest/api/3/issue/${encodeURIComponent(key)}?fields=summary,status,description`, { headers, redirect: 'error', signal: AbortSignal.timeout(timeoutMs) });
102
174
  if (!res.ok) return null;
103
175
  const f = (await res.json())?.fields ?? {};
104
176
  const summary = typeof f.summary === 'string' && f.summary.trim() ? f.summary.trim().slice(0, 300) : null;
105
177
  const status = typeof f.status?.name === 'string' ? f.status.name.slice(0, 60) : null;
106
178
  if (!summary && !status) return null;
107
- return { summary, status, category: typeof f.status?.statusCategory?.key === 'string' ? f.status.statusCategory.key : null };
179
+ const synopsis = synopsisOf(f.description);
180
+ return { summary, status, category: typeof f.status?.statusCategory?.key === 'string' ? f.status.statusCategory.key : null, ...(synopsis ? { synopsis } : {}) };
108
181
  } catch {
109
182
  return null;
110
183
  }
package/src/manager.js CHANGED
@@ -107,9 +107,10 @@ import { spawn } from 'node:child_process';
107
107
  import * as git from './git.js';
108
108
  import { buildMap, touchedFiles } from './codemap.js';
109
109
  import { parseDiff } from '../public/review.js';
110
- import { issueFields, issueSummary, leadingIssue, loadJira, wordsAfterLink } from './jira.js';
110
+ import { assignedIssues, issueFields, issueSummary, leadingIssue, loadJira, wordsAfterLink } from './jira.js';
111
111
  import { issueRows } from './issues.js';
112
112
  import { designRows } from './designs.js';
113
+ import { reviewPath, reviewerPrompt } from './reviews.js';
113
114
  import { reminderFor, reminderSettings } from './reminders.js';
114
115
  import { combine, facts as scoreFacts, improveMessage, scorecardMarkdown, scorecardPrompt } from './scorecard.js';
115
116
  import { CONTAINER_ENGINES, claudeToken, containerName, containerRunning, engineMounts, gitCommonDir, removeContainer, runArgs, stopContainer } from './container.js';
@@ -622,6 +623,7 @@ export class AgentManager extends EventEmitter {
622
623
  attachments,
623
624
  isolation,
624
625
  builds,
626
+ reviewing,
625
627
  }) {
626
628
  intent = (intent ?? '').trim();
627
629
  const staged = stagedFiles(attachments);
@@ -676,6 +678,8 @@ export class AgentManager extends EventEmitter {
676
678
  ...(isolation ? { isolation } : {}),
677
679
  // A session that develops an agent built here (builder.js): { name, engine }.
678
680
  ...(builds ? { builds: { name: String(builds.name), engine: String(builds.engine ?? 'claude') } } : {}),
681
+ // Reviews someone else's pull request (reviews.js): { url, slug, number, title }.
682
+ ...(!general && reviewing ? { reviewing } : {}),
679
683
  name: name?.trim() || jiraKey || slug,
680
684
  slug,
681
685
  intent,
@@ -692,11 +696,11 @@ export class AgentManager extends EventEmitter {
692
696
  model: model || null,
693
697
  // Review the implementation plan before the agent implements it: null = no review.
694
698
  // Team members get their review from the team instead.
695
- planReview: !general && !team && !builds && (planReview ?? this.config.planReview ?? false) ? { status: 'writing' } : null,
699
+ planReview: !general && !team && !builds && !reviewing && (planReview ?? this.config.planReview ?? false) ? { status: 'writing' } : null,
696
700
  // Write and publish a design doc (Google Doc + Artifact) after the plan, updated at the end.
697
- designDoc: !general && !team && !builds && Boolean(designDoc ?? this.config.designDoc ?? true),
698
- demoPage: !general && !team && !builds && Boolean(demoPage ?? this.config.demoPage ?? false),
699
- benchmarks: !general && !team && !builds && Boolean(benchmarks ?? this.config.benchmarks ?? false),
701
+ designDoc: !general && !team && !builds && !reviewing && Boolean(designDoc ?? this.config.designDoc ?? true),
702
+ demoPage: !general && !team && !builds && !reviewing && Boolean(demoPage ?? this.config.demoPage ?? false),
703
+ benchmarks: !general && !team && !builds && !reviewing && Boolean(benchmarks ?? this.config.benchmarks ?? false),
700
704
  status: 'preparing',
701
705
  desired: start ? 'running' : 'stopped',
702
706
  error: null,
@@ -717,7 +721,8 @@ export class AgentManager extends EventEmitter {
717
721
  ...(team ? { team } : {}),
718
722
  ...(imported ? { imported } : {}),
719
723
  };
720
- for (const pr of refs.prs) agent.prs[pr.url] = { ...pr, source: 'intent' };
724
+ // The PR a reviewer reviews isn't its own: it stays "mentioned", so landing and the rest leave it alone.
725
+ for (const pr of refs.prs) agent.prs[pr.url] = { ...pr, source: pr.url === agent.reviewing?.url ? 'mentioned' : 'intent' };
721
726
  for (const bug of refs.bugs) agent.bugs[bug.key] = { ...bug, source: 'intent' };
722
727
  // A request that starts with an issue link: describe it by the issue's summary (fetched below),
723
728
  // and until then by the words after the link.
@@ -823,10 +828,19 @@ export class AgentManager extends EventEmitter {
823
828
  * The issues agents work on, for the summary: one row per agent, with each issue's Jira status
824
829
  * (fetched a few at a time, kept five minutes).
825
830
  */
826
- async issues(proposed = []) {
831
+ async issues(proposed = [], actions = {}) {
827
832
  const views = this.store.list().map((a) => this.view(a));
828
- const rows = issueRows(views, new Map(), () => null, proposed);
829
833
  this.jiraCache ??= new Map();
834
+ // Open issues assigned to you (kept two minutes); their fields stand in for a fetch each.
835
+ if (!this.assignedAt || Date.now() - this.assignedAt > 2 * 60_000) {
836
+ const got = await (this.assignedFetch ?? assignedIssues)().catch(() => null);
837
+ this.assignedAt = Date.now();
838
+ if (got) this.assignedNow = got;
839
+ else if (!loadJira().token) this.assignedNow = [];
840
+ for (const i of got ?? []) this.jiraCache.set(i.key, { at: Date.now(), fields: { summary: i.summary, status: i.status, category: i.category, ...(i.synopsis ? { synopsis: i.synopsis } : {}) } });
841
+ }
842
+ const assigned = this.assignedNow ?? [];
843
+ const rows = issueRows(views, new Map(), () => null, proposed, actions, assigned);
830
844
  const jira = new Map();
831
845
  const want = [];
832
846
  for (const r of rows) {
@@ -854,7 +868,7 @@ export class AgentManager extends EventEmitter {
854
868
  }
855
869
  for (const [k, v] of jira) if (!v) jira.delete(k);
856
870
  const j = loadJira();
857
- return { rows: issueRows(views, jira, (id, name) => readSpecDoc(id, name)?.markdown ?? null, proposed), jira: { site: j.site, signedIn: Boolean(j.site && j.email && j.token) } };
871
+ return { rows: issueRows(views, jira, (id, name) => readSpecDoc(id, name)?.markdown ?? null, proposed, actions, assigned), jira: { site: j.site, signedIn: Boolean(j.site && j.email && j.token) } };
858
872
  }
859
873
 
860
874
  /** Every agent's design doc, for the Designs list. */
@@ -1178,7 +1192,7 @@ export class AgentManager extends EventEmitter {
1178
1192
  }
1179
1193
  // SPEC.md before changing code, and PLAN.md kept as it goes (unless the plan review asks for the plan).
1180
1194
  // A session building an agent keeps its analysis in the agent's folder instead.
1181
- if (task && this.config.specs !== false && !agent.builds) {
1195
+ if (task && this.config.specs !== false && !agent.builds && !agent.reviewing) {
1182
1196
  fs.mkdirSync(briefDir(agent.id), { recursive: true });
1183
1197
  const dir = fs.realpathSync(briefDir(agent.id));
1184
1198
  writableDir ??= dir;
@@ -1203,6 +1217,12 @@ export class AgentManager extends EventEmitter {
1203
1217
  if (agent.demoPage) prompts.push(demoPagePrompt(path.join(dir, path.basename(demoPath(agent.id)))));
1204
1218
  if (agent.benchmarks) prompts.push(benchmarksPrompt(path.join(dir, path.basename(benchPath(agent.id))), path.join(dir, 'bench')));
1205
1219
  }
1220
+ if (agent.reviewing && task) {
1221
+ fs.mkdirSync(briefDir(agent.id), { recursive: true });
1222
+ const file = path.join(fs.realpathSync(briefDir(agent.id)), path.basename(reviewPath(agent.id)));
1223
+ writableDir ??= path.dirname(file);
1224
+ prompts.push(reviewerPrompt(file, agent.reviewing));
1225
+ }
1206
1226
  if (planning) prompts.push(planningPrompt(agent));
1207
1227
  // What earlier agents learned in this repo, and the one command to add to it.
1208
1228
  let allowedTools = null;
@@ -2121,7 +2141,7 @@ export class AgentManager extends EventEmitter {
2121
2141
  if (k === 'source') continue;
2122
2142
  if (v != null && merged[k] !== v) merged[k] = v;
2123
2143
  }
2124
- if ((SOURCE_RANK[item.source] ?? 0) > (SOURCE_RANK[cur.source] ?? 0)) merged.source = item.source;
2144
+ if ((SOURCE_RANK[item.source] ?? 0) > (SOURCE_RANK[cur.source] ?? 0) && key !== agent.reviewing?.url) merged.source = item.source;
2125
2145
  if (JSON.stringify(merged) !== JSON.stringify(cur)) {
2126
2146
  bag[key] = merged;
2127
2147
  changed = true;