ai-agentmanager 1.26.1 → 1.28.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/server.js CHANGED
@@ -26,7 +26,7 @@ import { Repeats } from './repeats.js';
26
26
  import { Updates } from './update.js';
27
27
  import { identity } from './identity.js';
28
28
  import { WorkLog, summaryMarkdown } from './worklog.js';
29
- import { todayItems, todaySpeech } from './today.js';
29
+ import { todayAside, todayItems, todaySpeech } from './today.js';
30
30
  import { Studio } from './studio.js';
31
31
  import { Memory } from './memory.js';
32
32
  import { doctor } from './doctor.js';
@@ -51,6 +51,8 @@ import { Standup } from './standup.js';
51
51
  import { Value, valueSlack } from './value.js';
52
52
  import { Store } from './store.js';
53
53
  import { about, latestRelease } from './about.js';
54
+ import { Support } from './support.js';
55
+ import { BugHunts } from './bughunt.js';
54
56
 
55
57
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
56
58
  const require = createRequire(import.meta.url);
@@ -96,6 +98,9 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
96
98
  const proposed = new ProposedIssues({ store, manager });
97
99
  const myActions = new MyActions({ store, manager });
98
100
  const reviews = new Reviews({ manager, store, log: (m) => console.log(`[agentmgr] ${m}`) });
101
+ // Bug hunts: the judge checks each finding when it's on (else only failing tests are kept).
102
+ const hunts = new BugHunts({ manager, store, judge: manager.judge, log: (m) => console.log(`[agentmgr] ${m}`) });
103
+ hunts.startTimer();
99
104
  const races = new Races({ manager, store });
100
105
  const review = new Review({ manager });
101
106
  // The walkthrough explains the same diff the review screen shows.
@@ -911,9 +916,40 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
911
916
  f.slack || f.gemini ? got('actions', () => myActions.rows()) : [],
912
917
  got('reviews', () => reviews.rows()),
913
918
  ]);
914
- const items = todayItems({ inbox, issues, actions, reviews: prs });
915
- return { items, speech: todaySpeech(items), features: f, errors };
919
+ const findings = hunts.list().findings.filter((x) => x.status === 'open');
920
+ const items = todayItems({ inbox, issues, actions, reviews: prs, findings });
921
+ return { items, aside: todayAside({ issues, actions }), speech: todaySpeech(items), features: f, errors };
916
922
  }));
923
+ // Support tickets: kept on this computer, each with a filled-in link to a new GitHub issue.
924
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
925
+ const support = new Support({
926
+ issuesUrl: pkg.bugs?.url ?? 'https://github.com/jdmunta/ai-agentmanager-core/issues',
927
+ about: () => ({ version: pkgVersion, features: featuresOf(config), agents: store.list().length }),
928
+ });
929
+ api.get('/support', wrap(() => ({ tickets: support.list() })));
930
+ api.post('/support', wrap((req) => support.create({ ...req.body, browser: req.headers['user-agent'] ?? null })));
931
+ // The screenshot comes as the image itself (not JSON): up to 10 MB.
932
+ api.put('/support/:id/screenshot', express.raw({ type: 'image/*', limit: '10mb' }), wrap((req) => support.addScreenshot(req.params.id, req.body, req.headers['content-type'])));
933
+ api.get('/support/:id/screenshot', (req, res) => {
934
+ try {
935
+ const { file, type } = support.screenshot(req.params.id);
936
+ res.type(type).sendFile(file);
937
+ } catch (e) {
938
+ res.status(e.status ?? 500).json({ error: e.message });
939
+ }
940
+ });
941
+ // Bug hunts and what they found.
942
+ api.get('/hunts', wrap(async () => {
943
+ await hunts.sweep();
944
+ return hunts.list();
945
+ }));
946
+ api.post('/hunts', wrap((req) => hunts.add(req.body ?? {})));
947
+ api.put('/hunts/:id', wrap((req) => hunts.update(req.params.id, req.body ?? {})));
948
+ api.delete('/hunts/:id', wrap((req) => hunts.remove(req.params.id)));
949
+ api.post('/hunts/:id/run', wrap((req) => hunts.run(req.params.id)));
950
+ api.post('/findings/set', wrap((req) => hunts.set(Array.isArray(req.body?.ids) ? req.body.ids.map(String) : [], req.body?.status, { until: req.body?.until ?? null })));
951
+ api.post('/findings/:id/fix', wrap((req) => hunts.fix(req.params.id)));
952
+ api.get('/findings/:id/issue', wrap((req) => hunts.issue(req.params.id)));
917
953
  api.get('/standup', wrap(() => standup.view()));
918
954
  api.post('/standup', wrap(async () => ({ ...standup.view(), latest: await standup.make({ reason: 'asked' }) })));
919
955
  api.put('/standup', wrap((req) => {
@@ -1323,6 +1359,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
1323
1359
  standup.close();
1324
1360
  value.close();
1325
1361
  reviews.close();
1362
+ hunts.close();
1326
1363
  autopilot.close();
1327
1364
  goals.close();
1328
1365
  worklog.close();
@@ -1371,6 +1408,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
1371
1408
  .catch((err) => console.error(`[agentmgr] could not join the hub ${process.env.AGENTMGR_HUB_URL}: ${err.message}`));
1372
1409
  }
1373
1410
  return {
1411
+ hunts,
1374
1412
  hubLink,
1375
1413
  server,
1376
1414
  manager,
package/src/support.js ADDED
@@ -0,0 +1,156 @@
1
+ // Support tickets: a problem or an idea, in your words, with a screenshot when one helps. Each is
2
+ // kept on this computer (support/<id>/ in the home folder: ticket.md, ticket.json, screenshot) and
3
+ // comes with a link to a new GitHub issue filled in with it. Nothing is sent from here: you look
4
+ // it over on GitHub, paste the screenshot (it's put on your clipboard) and submit it yourself.
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import { paths } from './config.js';
9
+
10
+ export const KINDS = { bug: 'Something is wrong', idea: 'An improvement' };
11
+ const LABELS = { bug: 'bug', idea: 'enhancement' };
12
+ const IMAGE = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp' };
13
+ const MAX_KEPT = 100;
14
+ // GitHub refuses very long new-issue links; the body is cut to fit.
15
+ const MAX_URL = 7500;
16
+ const err = (status, message) => Object.assign(new Error(message), { status });
17
+
18
+ const dir = () => path.join(paths.home, 'support');
19
+ const ticketDir = (id) => {
20
+ if (!/^[\w-]{1,80}$/.test(String(id))) throw err(400, 'No such ticket');
21
+ return path.join(dir(), id);
22
+ };
23
+
24
+ /** What's useful to know about this setup, without names, folders, hosts or tokens. */
25
+ export function aboutThis({ version, browser = null, features = {}, agents = null } = {}) {
26
+ return {
27
+ version: version ?? null,
28
+ os: `${os.type()} ${os.release()} (${process.arch})`,
29
+ node: process.version,
30
+ ...(browser ? { browser: String(browser).slice(0, 200) } : {}),
31
+ on: Object.entries(features)
32
+ .filter(([, v]) => v)
33
+ .map(([k]) => k),
34
+ ...(agents === null ? {} : { agents }),
35
+ };
36
+ }
37
+
38
+ /** The issue's text, in Markdown. */
39
+ export function ticketMarkdown(t) {
40
+ const info = t.info ?? {};
41
+ const lines = [
42
+ t.details.trim(),
43
+ '',
44
+ ...(t.screenshot ? ['**Screenshot:** _(pasted below)_', '', ''] : []),
45
+ '<details><summary>About this setup</summary>',
46
+ '',
47
+ `- AI Agent Manager ${info.version ?? '?'}`,
48
+ `- ${info.os ?? '?'}, Node ${info.node ?? '?'}`,
49
+ ...(info.browser ? [`- Browser: ${info.browser}`] : []),
50
+ ...(info.on?.length ? [`- Turned on: ${info.on.join(', ')}`] : []),
51
+ ...(info.agents !== undefined ? [`- Agents: ${info.agents}`] : []),
52
+ '',
53
+ '</details>',
54
+ ];
55
+ return lines.join('\n');
56
+ }
57
+
58
+ /** A link to a new issue on `issuesUrl` (…/issues) with the title, text and label filled in. */
59
+ export function issueLink(issuesUrl, t) {
60
+ const base = `${String(issuesUrl).replace(/\/+$/, '')}/new`;
61
+ const q = (body) => `${base}?${new URLSearchParams({ title: t.title, labels: LABELS[t.kind] ?? '', body })}`;
62
+ let link = q(ticketMarkdown(t));
63
+ // Cut the details, not the setup: the whole text stays in the ticket on this computer.
64
+ for (let room = t.details.length; link.length > MAX_URL && room > 0; ) {
65
+ room = Math.floor(room * Math.min(0.9, MAX_URL / link.length));
66
+ link = q(ticketMarkdown({ ...t, details: `${t.details.slice(0, room).trim()}\n\n_(cut short to fit the link; paste the rest)_` }));
67
+ }
68
+ return link;
69
+ }
70
+
71
+ export class Support {
72
+ constructor({ issuesUrl, about = () => ({}) }) {
73
+ this.issuesUrl = issuesUrl;
74
+ this.about = about;
75
+ }
76
+
77
+ /** Keep a ticket: { kind, title, details, browser } → the ticket with its id and issue link. */
78
+ create({ kind = 'bug', title, details, browser = null } = {}) {
79
+ if (!KINDS[kind]) throw err(400, `The kind is ${Object.keys(KINDS).join(' or ')}`);
80
+ title = String(title ?? '').trim().replace(/\s+/g, ' ').slice(0, 200);
81
+ details = String(details ?? '').trim().slice(0, 20_000);
82
+ if (!title) throw err(400, 'Give it a short title');
83
+ if (!details) throw err(400, 'Say what happened, or what would help');
84
+ const at = new Date();
85
+ const id = `${at.toISOString().slice(0, 19).replace(/[-:T]/g, '')}-${Math.random().toString(36).slice(2, 6)}`;
86
+ const t = { id, kind, title, details, at: at.toISOString(), screenshot: null, info: aboutThis({ ...this.about(), browser }) };
87
+ fs.mkdirSync(ticketDir(id), { recursive: true });
88
+ this.write(t);
89
+ this.prune();
90
+ return this.view(t);
91
+ }
92
+
93
+ /** The screenshot for a ticket (PNG, JPEG or WebP, as sent). */
94
+ addScreenshot(id, buf, type) {
95
+ const t = this.read(id);
96
+ const ext = IMAGE[String(type ?? '').split(';')[0]];
97
+ if (!ext) throw err(415, 'The screenshot is a PNG, JPEG or WebP image');
98
+ if (!buf?.length) throw err(400, 'The screenshot is empty');
99
+ const name = `screenshot.${ext}`;
100
+ fs.writeFileSync(path.join(ticketDir(id), name), buf);
101
+ t.screenshot = name;
102
+ this.write(t);
103
+ return this.view(t);
104
+ }
105
+
106
+ /** The screenshot's file: { file, type }. */
107
+ screenshot(id) {
108
+ const t = this.read(id);
109
+ if (!t.screenshot) throw err(404, 'No screenshot');
110
+ const ext = t.screenshot.split('.').pop();
111
+ return { file: path.join(ticketDir(id), t.screenshot), type: Object.keys(IMAGE).find((k) => IMAGE[k] === ext) };
112
+ }
113
+
114
+ /** Your tickets, newest first. */
115
+ list(max = 20) {
116
+ let ids = [];
117
+ try {
118
+ ids = fs.readdirSync(dir()).sort().reverse();
119
+ } catch {}
120
+ const out = [];
121
+ for (const id of ids) {
122
+ if (out.length >= max) break;
123
+ try {
124
+ out.push(this.view(this.read(id)));
125
+ } catch {}
126
+ }
127
+ return out;
128
+ }
129
+
130
+ view(t) {
131
+ return { ...t, folder: ticketDir(t.id), issueUrl: issueLink(this.issuesUrl, t) };
132
+ }
133
+
134
+ read(id) {
135
+ const file = path.join(ticketDir(id), 'ticket.json');
136
+ try {
137
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
138
+ } catch {
139
+ throw err(404, 'No such ticket');
140
+ }
141
+ }
142
+
143
+ write(t) {
144
+ fs.writeFileSync(path.join(ticketDir(t.id), 'ticket.json'), JSON.stringify(t, null, 2) + '\n');
145
+ fs.writeFileSync(path.join(ticketDir(t.id), 'ticket.md'), `# ${t.title}\n\n_${KINDS[t.kind]} · ${t.at}_\n\n${ticketMarkdown(t)}\n${t.screenshot ? `\n![Screenshot](${t.screenshot})\n` : ''}`);
146
+ }
147
+
148
+ /** The oldest go when there are many. */
149
+ prune() {
150
+ let ids = [];
151
+ try {
152
+ ids = fs.readdirSync(dir()).sort();
153
+ } catch {}
154
+ for (const id of ids.slice(0, Math.max(0, ids.length - MAX_KEPT))) fs.rmSync(ticketDir(id), { recursive: true, force: true });
155
+ }
156
+ }
package/src/today.js CHANGED
@@ -59,7 +59,7 @@ const INBOX = {
59
59
  * The list: [{ id, kind, label, title, why, score, at, agentId?, url?, actionId?, issueKey?, reviewUrl? }],
60
60
  * most pressing first. Each source may be missing (turned off, or it couldn't be had).
61
61
  */
62
- export function todayItems({ inbox = [], issues = [], actions = [], reviews = [], now = new Date() } = {}) {
62
+ export function todayItems({ inbox = [], issues = [], actions = [], reviews = [], findings = [], now = new Date() } = {}) {
63
63
  const items = [];
64
64
  // The issue each agent works on: named on its questions, and not listed twice.
65
65
  const issueOfAgent = new Map(issues.filter((r) => r.agent?.id).map((r) => [r.agent.id, r]));
@@ -100,6 +100,11 @@ export function todayItems({ inbox = [], issues = [], actions = [], reviews = []
100
100
  items.push({ id: `pr:${r.pr.url}`, kind: 'pr-ready', label: 'Review', title, why: `${r.agent.name}'s review is ready to post: ${verdict}${r.stale ? ' (the author pushed since)' : ''}`, score: 32, at: r.updatedAt ?? null, agentId: r.agent.id, url: r.pr.url, reviewUrl: r.pr.url });
101
101
  }
102
102
  }
103
+ // Bugs a hunt found and the check confirmed: the serious ones (the rest wait in the Bugs list).
104
+ for (const f of findings) {
105
+ if (f.status !== 'open' || !['critical', 'high'].includes(f.severity)) continue;
106
+ items.push({ id: `bug:${f.id}`, kind: 'bug', label: 'Bug', title: f.title, why: `${f.severity === 'critical' ? 'Critical' : 'High'}: found by the ${f.hunt ?? 'bug'} hunt${f.file ? ` in ${f.file}${f.line ? `:${f.line}` : ''}` : ''}${f.evidence?.type === 'test' ? ' · a test fails' : ''}`, score: f.severity === 'critical' ? 28 : 38, at: f.at ?? null, findingId: f.id });
107
+ }
103
108
  return items.sort((x, y) => x.score - y.score || String(y.at ?? '').localeCompare(String(x.at ?? '')));
104
109
  }
105
110
 
@@ -112,3 +117,22 @@ export function todaySpeech(items, max = 8) {
112
117
  items.slice(0, max).forEach((it, i) => parts.push(`${i + 1}. ${it.label}. ${say(it.title)} ${say(it.why)}`));
113
118
  return parts;
114
119
  }
120
+
121
+ const ASIDE = { skip: 'Skipped', done: 'Done', remove: 'Removed' };
122
+
123
+ /**
124
+ * What you set aside from Today's lists (skipped, done, removed), newest first, so any of it can be
125
+ * brought back: [{ id, kind: 'issue' | 'action', state, label, title, at, issueKey?, actionId? }].
126
+ */
127
+ export function todayAside({ issues = [], actions = [], max = 50 } = {}) {
128
+ const out = [];
129
+ for (const r of issues) {
130
+ if (!ASIDE[r.action]) continue;
131
+ out.push({ id: `issue:${r.key}`, kind: 'issue', state: r.action, label: ASIDE[r.action], title: r.title ? `${r.key}: ${r.title}` : r.key, at: r.actionAt ?? r.updatedAt ?? null, issueKey: r.key });
132
+ }
133
+ for (const a of actions) {
134
+ if (!ASIDE[a.status]) continue;
135
+ out.push({ id: `action:${a.id}`, kind: 'action', state: a.status, label: ASIDE[a.status], title: a.text, at: a.updatedAt ?? null, actionId: a.id });
136
+ }
137
+ return out.sort((x, y) => String(y.at ?? '').localeCompare(String(x.at ?? ''))).slice(0, max);
138
+ }