ai-agentmanager 1.23.0 → 1.25.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/assistant.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // it starts agents for that work through agentmgr, or passes news to the agent already on it.
5
5
  // The daemon keeps the limits: a daily cap, a cap on its agents running at once, and no second
6
6
  // agent for the same issue.
7
+ import crypto from 'node:crypto';
7
8
  import fs from 'node:fs';
8
9
  import path from 'node:path';
9
10
  import { fileURLToPath } from 'node:url';
@@ -17,7 +18,32 @@ export const SOURCES = {
17
18
  comments: 'new comments and mentions on Jira issues the person owns',
18
19
  slack: 'Slack messages to the person (direct messages and mentions) that ask for work',
19
20
  linear: 'Linear issues newly assigned to the person',
21
+ actions: 'things asked of the person in Slack and in meeting notes (Notes by Gemini), for their Actions list',
20
22
  };
23
+
24
+ /**
25
+ * The parts of AI Agent Manager you use (config.json "features"); all on unless turned off in
26
+ * Settings. Off, its list is hidden and the assistant doesn't look there.
27
+ */
28
+ export const FEATURES = {
29
+ jira: 'Jira: the issues assigned to you and the agents on them',
30
+ slack: 'Slack: work and action items from your messages',
31
+ gemini: 'Meeting notes: action items from Google Meet\'s Notes by Gemini',
32
+ };
33
+ export function featuresOf(config = {}) {
34
+ const f = config.features ?? {};
35
+ return Object.fromEntries(Object.keys(FEATURES).map((k) => [k, f[k] !== false]));
36
+ }
37
+
38
+ /** The sources the assistant checks with these features on. */
39
+ export function activeSources(sources, features) {
40
+ return sources.filter((k) => {
41
+ if (k === 'jira' || k === 'comments') return features.jira;
42
+ if (k === 'slack') return features.slack;
43
+ if (k === 'actions') return features.slack || features.gemini;
44
+ return true;
45
+ });
46
+ }
21
47
  export const ASSISTANT_DEFAULTS = {
22
48
  everyMin: 15,
23
49
  // Linear only when chosen: most people use Jira or Linear, not both.
@@ -41,7 +67,9 @@ export const assistantDir = () => path.join(paths.home, 'assistant');
41
67
  export function assistantSettings(config = {}) {
42
68
  const c = { ...ASSISTANT_DEFAULTS, ...config.assistant };
43
69
  const n = (v, d, lo, hi) => (Number.isFinite(Number(v)) && Number(v) >= lo ? Math.min(hi, Math.floor(Number(v))) : d);
44
- const sources = Array.isArray(c.sources) ? c.sources.filter((s) => SOURCES[s]) : ASSISTANT_DEFAULTS.sources;
70
+ let sources = Array.isArray(c.sources) ? c.sources.filter((s) => SOURCES[s]) : ASSISTANT_DEFAULTS.sources;
71
+ // Lists saved before "actions" existed get it once; after that, what you chose stays.
72
+ if (Array.isArray(c.sources) && c.sourcesV2 !== true && !sources.includes('actions')) sources = [...sources, 'actions'];
45
73
  return {
46
74
  everyMin: n(c.everyMin, ASSISTANT_DEFAULTS.everyMin, 1, 1440),
47
75
  sources,
@@ -51,11 +79,15 @@ export function assistantSettings(config = {}) {
51
79
  model: typeof c.model === 'string' && c.model ? c.model : null,
52
80
  notes: typeof c.notes === 'string' ? c.notes.slice(0, 4000) : '',
53
81
  pickIssues: c.pickIssues === true,
82
+ // Who "the person" is, to find what's asked of them: name and email(s). Empty: from git config.
83
+ me: typeof c.me === 'string' ? c.me.slice(0, 300) : '',
84
+ sourcesV2: true,
54
85
  };
55
86
  }
56
87
 
57
88
  /** The assistant's standing instructions (appended to its system prompt on every launch). */
58
- export function assistantPrompt(s, dir, bin = `node ${BIN}`) {
89
+ export function assistantPrompt(s, dir, bin = `node ${BIN}`, features = featuresOf()) {
90
+ s = { ...s, sources: activeSources(s.sources, features) };
59
91
  const am = bin;
60
92
  const watch = s.sources.map((k) => `- ${SOURCES[k]}`).join('\n');
61
93
  const how = [];
@@ -63,14 +95,14 @@ export function assistantPrompt(s, dir, bin = `node ${BIN}`) {
63
95
  const pick =
64
96
  `Don't start agents for new issues: the person picks which ones get agents. Propose each one you haven't handled instead: ${am} issues propose @<project> "<the issue link> <a one-line summary of what to do>". ` +
65
97
  `It is listed for them under Jira, Not started, and an agent starts only if they tick it. Record it as "proposed". ` +
66
- `A proposal for an issue they dismissed, or one that already has an agent, is refused: record it as skipped and don't propose it again.`;
98
+ `A proposal for an issue they skipped, marked done or removed, or one that already has an agent, is refused: record it as skipped and don't propose it again.`;
67
99
  if (s.sources.includes('jira')) {
68
100
  how.push(
69
101
  `Jira, new assignments: with your Jira / Atlassian tools, find unresolved issues assigned to the person that were created or assigned since your last check (on the first check, the last 2 days). ` +
70
102
  (s.pickIssues
71
103
  ? pick
72
104
  : `For each one you haven't handled, start an agent: ${am} add @<project> "<the issue link> <a one-line summary of what to do>". ` +
73
- `Start the request with the issue link: the agent is then named after the issue key, and the daemon refuses a second agent for the same key.`),
105
+ `Start the request with the issue link: the agent is then named after the issue key, and the daemon refuses a second agent for the same key, or one for an issue the person skipped, marked done or removed under Jira (record those as skipped).`),
74
106
  );
75
107
  }
76
108
  if (s.sources.includes('linear')) {
@@ -106,6 +138,19 @@ export function assistantPrompt(s, dir, bin = `node ${BIN}`) {
106
138
  `Otherwise start one: ${am} add @<project> "Checks fail on <PR link>: find out why and fix it on that branch."`,
107
139
  );
108
140
  }
141
+ if (s.sources.includes('actions')) {
142
+ const where = [
143
+ features.slack && 'in Slack, direct messages to the person, messages that mention them and threads they take part in',
144
+ features.gemini && 'in meeting notes: the Google Docs named "Notes by Gemini" for their meetings (in Google Drive, or linked from the calendar event or the email Gemini sends)',
145
+ ].filter(Boolean);
146
+ const who = s.me ? `the person (${s.me})` : 'the person (their name and email: git config --global user.name and user.email)';
147
+ how.push(
148
+ `My action items: with your ${[features.slack && 'Slack', features.gemini && 'Google Drive, Calendar and Gmail'].filter(Boolean).join(' and ')} tools, read what's new since your last check ${where.join(', and ')}. ` +
149
+ `Find what is asked of ${who}, or what they agreed to do: in Gemini's notes, the action items and suggested next steps that name them. ` +
150
+ `For each one, add it to their list: ${am} actions add --source <${[features.slack && 'slack', features.gemini && 'gemini'].filter(Boolean).join('|')}> --link "<the message or doc link>" --from "<who asked>" [--due "<when, if said>"] --context "<one or two sentences of background>" "<the action in one line, starting with a verb>". ` +
151
+ `Adding the same one twice is harmless. Don't act on them, start agents for them or reply: the person decides under Actions.`,
152
+ );
153
+ }
109
154
  if (s.sources.includes('slack')) {
110
155
  how.push(
111
156
  `Slack: with your Slack tools, read direct messages to the person and messages that mention them, since your last check. ` +
@@ -129,6 +174,13 @@ export function assistantPrompt(s, dir, bin = `node ${BIN}`) {
129
174
  .join('\n\n');
130
175
  }
131
176
 
177
+ /** The instructions for the assistant as the settings stand now, and a short hash of them. */
178
+ export function currentPrompt(config = {}) {
179
+ fs.mkdirSync(assistantDir(), { recursive: true });
180
+ const text = assistantPrompt(assistantSettings(config), fs.realpathSync(assistantDir()), undefined, featuresOf(config));
181
+ return { text, hash: crypto.createHash('sha256').update(text).digest('hex').slice(0, 16) };
182
+ }
183
+
132
184
  export class Assistant {
133
185
  constructor({ manager, store, config = {}, log = (m) => console.log(`[agentmgr] ${m}`) }) {
134
186
  this.manager = manager;
@@ -207,7 +259,14 @@ export class Assistant {
207
259
  if (!a) throw err(409, 'The assistant is not set up yet: start it first');
208
260
  const last = this.state.lastCheckAt;
209
261
  const n = (this.state.checks ?? 0) + 1;
210
- const text = `Check now (check ${n}, ${new Date().toISOString()}${last ? `; last check ${last}` : '; first check'}${by === 'person' ? ', asked by the person' : ''}).`;
262
+ let text = `Check now (check ${n}, ${new Date().toISOString()}${last ? `; last check ${last}` : '; first check'}${by === 'person' ? ', asked by the person' : ''}).`;
263
+ // Settings changed since the session started (sources, features, notes): the new instructions
264
+ // come with this check, so they apply without restarting it.
265
+ const now = currentPrompt(this.config);
266
+ if (this.state.promptHash && now.hash !== this.state.promptHash) {
267
+ text += `\n\nThe person changed your settings. From now on follow these instructions instead of the ones you started with:\n\n${now.text}`;
268
+ }
269
+ this.state.promptHash = now.hash;
211
270
  this.manager.tell(a.id, text, { source: 'assistant' });
212
271
  this.state.checks = n;
213
272
  this.state.lastCheckAt = new Date().toISOString();
package/src/cli.js CHANGED
@@ -674,16 +674,17 @@ export async function main(argv) {
674
674
  .action(async (opts) => {
675
675
  await daemon();
676
676
  const v = await api('GET', '/issues');
677
- 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');
678
678
  if (opts.json) return console.log(JSON.stringify({ ...v, rows }, null, 2));
679
679
  if (opts.markdown) return console.log(issuesMarkdown(rows));
680
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.'));
681
681
  for (const r of rows) {
682
682
  const pr = r.pr ? ` PR #${r.pr.number ?? '?'}` : '';
683
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)}`));
684
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}`)}`);
685
686
  }
686
- const others = v.rows.length - rows.length;
687
+ const others = v.rows.filter((r) => r.group !== 'removed').length - rows.length;
687
688
  if (others) console.log(dim(`\n${others} more with agents still on them or finished: --all`));
688
689
  if (!v.jira.signedIn) console.log(dim('Jira status needs your site, email and API token: Settings → Jira.'));
689
690
  });
@@ -717,6 +718,72 @@ export async function main(argv) {
717
718
  const r = await api('POST', '/issues/dismiss', { keys });
718
719
  console.log(`${r.dismissed} dismissed`);
719
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
+ });
733
+
734
+ const actionsCmd = program.command('actions').description("Your action items from Slack and meeting notes (the assistant finds them): decide on each one");
735
+ actionsCmd
736
+ .command('ls', { isDefault: true })
737
+ .description('The open ones (--all for the decided ones too)')
738
+ .option('--all', 'also assigned, skipped, done and removed')
739
+ .option('--json', 'print JSON')
740
+ .action(async (opts) => {
741
+ await daemon();
742
+ const v = await api('GET', '/actions');
743
+ const rows = opts.all ? v.rows : v.rows.filter((r) => r.group === 'open');
744
+ if (opts.json) return console.log(JSON.stringify({ ...v, rows }, null, 2));
745
+ if (!rows.length) return console.log(dim(opts.all ? 'No action items yet.' : 'Nothing open. --all shows the decided ones.'));
746
+ for (const r of rows) {
747
+ console.log(`${bold(r.id)} ${r.group === 'open' ? yellow(r.text) : r.text}${r.group === 'open' ? '' : dim(` [${r.status}]`)}`);
748
+ console.log(dim(` ${[r.sourceLabel, r.from && `from ${r.from}`, r.due && `due ${r.due}`, r.link].filter(Boolean).join(' · ')}`));
749
+ }
750
+ });
751
+ actionsCmd
752
+ .command('add')
753
+ .description('Add an action item (the assistant does this on its checks)')
754
+ .argument('<text...>', 'the action, in one line')
755
+ .option('--source <source>', 'slack | gemini | other', 'other')
756
+ .option('--link <url>', 'the message or document it comes from')
757
+ .option('--from <who>', 'who asked')
758
+ .option('--due <when>', 'when it is due, if said')
759
+ .option('--context <text>', 'a sentence or two of background')
760
+ .action(async (words, opts) => {
761
+ await daemon();
762
+ const a = await api('POST', '/actions', { text: words.join(' '), source: opts.source, link: opts.link, from: opts.from, due: opts.due, context: opts.context });
763
+ console.log(a.duplicate ? dim(`Already listed: ${a.id}`) : `${green('+')} ${bold(a.id)} ${a.text}`);
764
+ });
765
+ actionsCmd
766
+ .command('set')
767
+ .description('Your decision: assign (an agent does it), skip, done, remove, or open again')
768
+ .argument('<state>', 'assign | skip | done | remove | open')
769
+ .argument('<ids...>')
770
+ .option('-p, --project <project>', 'with assign: the project the agent works in')
771
+ .action(async (state, ids, opts) => {
772
+ await daemon();
773
+ const r = await api('POST', '/actions/set', { ids, state, project: opts.project });
774
+ for (const x of r.started) console.log(`${green('✓')} ${bold(x.id)} → agent ${x.agent.name} (${x.agent.id})`);
775
+ if (r.set.length) console.log(`${green('✓')} ${r.set.join(', ')}: ${state}`);
776
+ for (const x of r.failed) console.log(`${red('!')} ${bold(x.id)}: ${x.reason}`);
777
+ });
778
+ actionsCmd
779
+ .command('discuss')
780
+ .description('Talk an action item through with Claude, in a session of its own')
781
+ .argument('<id>')
782
+ .action(async (id) => {
783
+ await daemon();
784
+ const r = await api('POST', `/actions/${id}/discuss`, {});
785
+ console.log(`${r.existing ? 'Already talking about it' : 'Started'}: ${bold(r.agent.name)} (${r.agent.id}); open it with agentmgr attach ${r.agent.id}`);
786
+ });
720
787
 
721
788
  program
722
789
  .command('designs')
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,7 +107,7 @@ 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
113
  import { reviewPath, reviewerPrompt } from './reviews.js';
@@ -121,7 +121,7 @@ import { Judge, clashPrompt, finishMessage, hash, reviewPrompt, screenPrompt, st
121
121
  import { findLocalUrls, findSignInLinks, parseCallback, parseUrl } from './preview.js';
122
122
  import { Plugins } from './plugins.js';
123
123
  import { leadPrompt, subagents, teamDir, teamPrompt } from './teams.js';
124
- import { assistantDir, assistantPrompt, assistantSettings } from './assistant.js';
124
+ import { assistantDir, currentPrompt } from './assistant.js';
125
125
  import { learnCommand, memoryKey, memoryPrompt, memoryText } from './memory.js';
126
126
  import { Rules, describeTool } from './rules.js';
127
127
  import { runningClaude, scanClaudeSessions } from './sessions.js';
@@ -828,10 +828,20 @@ export class AgentManager extends EventEmitter {
828
828
  * The issues agents work on, for the summary: one row per agent, with each issue's Jira status
829
829
  * (fetched a few at a time, kept five minutes).
830
830
  */
831
- async issues(proposed = []) {
831
+ async issues(proposed = [], actions = {}) {
832
832
  const views = this.store.list().map((a) => this.view(a));
833
- const rows = issueRows(views, new Map(), () => null, proposed);
834
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.jiraOff) this.assignedNow = [];
836
+ else if (!this.assignedAt || Date.now() - this.assignedAt > 2 * 60_000) {
837
+ const got = await (this.assignedFetch ?? assignedIssues)().catch(() => null);
838
+ this.assignedAt = Date.now();
839
+ if (got) this.assignedNow = got;
840
+ else if (!loadJira().token) this.assignedNow = [];
841
+ 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 } : {}) } });
842
+ }
843
+ const assigned = this.assignedNow ?? [];
844
+ const rows = issueRows(views, new Map(), () => null, proposed, actions, assigned);
835
845
  const jira = new Map();
836
846
  const want = [];
837
847
  for (const r of rows) {
@@ -859,7 +869,7 @@ export class AgentManager extends EventEmitter {
859
869
  }
860
870
  for (const [k, v] of jira) if (!v) jira.delete(k);
861
871
  const j = loadJira();
862
- 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) } };
872
+ 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) } };
863
873
  }
864
874
 
865
875
  /** Every agent's design doc, for the Designs list. */
@@ -1230,10 +1240,11 @@ export class AgentManager extends EventEmitter {
1230
1240
  allowedTools = [...(allowedTools ?? []), ...builderAllowedTools(agent.workdir)];
1231
1241
  }
1232
1242
  if (agent.kind === 'assistant') {
1233
- fs.mkdirSync(assistantDir(), { recursive: true });
1234
- const dir = fs.realpathSync(assistantDir());
1235
- writableDir = dir;
1236
- prompts.push(assistantPrompt(assistantSettings(this.config), dir));
1243
+ writableDir = fs.realpathSync((fs.mkdirSync(assistantDir(), { recursive: true }), assistantDir()));
1244
+ const p = currentPrompt(this.config);
1245
+ prompts.push(p.text);
1246
+ // What it started with: a check after a settings change brings the new instructions.
1247
+ (this.store.data.assistant ??= {}).promptHash = p.hash;
1237
1248
  }
1238
1249
  if (agent.team) {
1239
1250
  // Team members write their handoff files in the team's folder.