ai-agentmanager 1.20.0 → 1.22.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/CHANGELOG.md +13 -0
- package/README.md +64 -2
- package/package.json +1 -1
- package/public/app.js +89 -3
- package/public/codemap.js +209 -0
- package/public/designs.js +172 -0
- package/public/index.html +26 -0
- package/public/issues.js +255 -0
- package/public/keys.js +8 -3
- package/public/land.js +2 -0
- package/public/prvoice.js +103 -0
- package/public/speak.js +11 -4
- package/public/standup.js +348 -0
- package/public/style.css +168 -0
- package/public/value.js +299 -0
- package/public/voice.js +16 -0
- package/src/assistant.js +16 -4
- package/src/cli.js +184 -1
- package/src/codemap.js +115 -0
- package/src/config.js +2 -0
- package/src/designs.js +72 -0
- package/src/issues.js +272 -0
- package/src/jira.js +15 -4
- package/src/manager.js +106 -1
- package/src/notify.js +2 -0
- package/src/server.js +98 -0
- package/src/standup.js +209 -0
- package/src/value.js +609 -0
package/src/codemap.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Codebase map: a repository's folders, sized by how many files they hold, with each agent in that
|
|
2
|
+
// repository on the folders it is changing or reading right now. Two agents that changed the same
|
|
3
|
+
// file are about to conflict; one reading a file another has changed is heading that way, which is
|
|
4
|
+
// the earlier warning. Changes come from the conflict radar's diffs, reading from the last half
|
|
5
|
+
// hour of the agent's transcript.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const RECENT_MS = 30 * 60_000;
|
|
11
|
+
const MAX_FILES = 20_000;
|
|
12
|
+
const TAIL_BYTES = 768 * 1024;
|
|
13
|
+
const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
|
|
14
|
+
const READ_TOOLS = new Set(['Read', 'Grep', 'Glob', 'NotebookRead']);
|
|
15
|
+
|
|
16
|
+
/** The folder a file belongs to on the map: its first `depth` directories ("." for top-level files). */
|
|
17
|
+
export function moduleOf(file, depth = 2) {
|
|
18
|
+
const parts = file.split('/').slice(0, -1);
|
|
19
|
+
return parts.length ? parts.slice(0, depth).join('/') : '.';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Files the agent's tools touched since `since`, from its transcript: { file: { kind, at } }, kind 'edit' or 'read'. */
|
|
23
|
+
export function touchedFiles(transcript, workdir, since = Date.now() - RECENT_MS) {
|
|
24
|
+
const out = {};
|
|
25
|
+
let text = '';
|
|
26
|
+
try {
|
|
27
|
+
const st = fs.statSync(transcript);
|
|
28
|
+
const fd = fs.openSync(transcript, 'r');
|
|
29
|
+
try {
|
|
30
|
+
const len = Math.min(st.size, TAIL_BYTES);
|
|
31
|
+
const buf = Buffer.alloc(len);
|
|
32
|
+
fs.readSync(fd, buf, 0, len, st.size - len);
|
|
33
|
+
text = buf.toString('utf8');
|
|
34
|
+
} finally {
|
|
35
|
+
fs.closeSync(fd);
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const root = workdir.endsWith('/') ? workdir : `${workdir}/`;
|
|
41
|
+
for (const line of text.split('\n')) {
|
|
42
|
+
if (!line.includes('"tool_use"')) continue;
|
|
43
|
+
let entry;
|
|
44
|
+
try {
|
|
45
|
+
entry = JSON.parse(line);
|
|
46
|
+
} catch {
|
|
47
|
+
continue; // the first line may be cut
|
|
48
|
+
}
|
|
49
|
+
const at = Date.parse(entry.timestamp ?? 0);
|
|
50
|
+
if (!(at >= since)) continue;
|
|
51
|
+
for (const c of entry.message?.content ?? []) {
|
|
52
|
+
if (c?.type !== 'tool_use') continue;
|
|
53
|
+
const kind = EDIT_TOOLS.has(c.name) ? 'edit' : READ_TOOLS.has(c.name) ? 'read' : null;
|
|
54
|
+
const p = c.input?.file_path ?? c.input?.notebook_path ?? c.input?.path;
|
|
55
|
+
if (!kind || typeof p !== 'string') continue;
|
|
56
|
+
const abs = path.isAbsolute(p) ? p : path.join(workdir, p);
|
|
57
|
+
if (!abs.startsWith(root)) continue;
|
|
58
|
+
const rel = abs.slice(root.length);
|
|
59
|
+
if (!rel || rel.startsWith('.git/')) continue;
|
|
60
|
+
const prev = out[rel];
|
|
61
|
+
// An edit outranks a read; otherwise the latest time wins.
|
|
62
|
+
if (!prev || (kind === 'edit' && prev.kind === 'read') || (kind === prev.kind && at > prev.at)) out[rel] = { kind, at };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The map: { modules: [{ key, files, agents: [{ id, changed, reading }] }], agents, links }.
|
|
70
|
+
* agents: [{ id, name, busy, attention, changed: { file: {added, removed} }, touched: { file: {kind, at} } }].
|
|
71
|
+
* links: [{ a, b, kind: 'collide' | 'heading' | 'near', files }], 'heading' from `a` (reading) to `b` (changed it).
|
|
72
|
+
*/
|
|
73
|
+
export function buildMap({ files = [], agents = [], depth = 2 }) {
|
|
74
|
+
const modules = new Map();
|
|
75
|
+
const mod = (key) => modules.get(key) ?? modules.set(key, { key, files: 0, agents: new Map() }).get(key);
|
|
76
|
+
for (const f of files.slice(0, MAX_FILES)) mod(moduleOf(f, depth)).files += 1;
|
|
77
|
+
const touch = (id, file, what) => {
|
|
78
|
+
const m = mod(moduleOf(file, depth));
|
|
79
|
+
const x = m.agents.get(id) ?? m.agents.set(id, { id, changed: 0, reading: 0 }).get(id);
|
|
80
|
+
x[what] += 1;
|
|
81
|
+
};
|
|
82
|
+
for (const a of agents) {
|
|
83
|
+
for (const f of Object.keys(a.changed ?? {})) touch(a.id, f, 'changed');
|
|
84
|
+
for (const [f, t] of Object.entries(a.touched ?? {})) if (!a.changed?.[f] && t.kind === 'read') touch(a.id, f, 'reading');
|
|
85
|
+
}
|
|
86
|
+
const links = [];
|
|
87
|
+
for (let i = 0; i < agents.length; i++) {
|
|
88
|
+
for (let j = i + 1; j < agents.length; j++) {
|
|
89
|
+
const x = agents[i];
|
|
90
|
+
const y = agents[j];
|
|
91
|
+
const cx = Object.keys(x.changed ?? {});
|
|
92
|
+
const cy = new Set(Object.keys(y.changed ?? {}));
|
|
93
|
+
const both = cx.filter((f) => cy.has(f));
|
|
94
|
+
if (both.length) {
|
|
95
|
+
links.push({ a: x.id, b: y.id, kind: 'collide', files: both.slice(0, 10) });
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// Reading what the other changed: the next step is often an edit there.
|
|
99
|
+
const heading = (r, c) => Object.entries(r.touched ?? {}).filter(([f, t]) => t.kind === 'read' && !r.changed?.[f] && c.changed?.[f]).map(([f]) => f);
|
|
100
|
+
const xy = heading(x, y);
|
|
101
|
+
const yx = heading(y, x);
|
|
102
|
+
if (xy.length) links.push({ a: x.id, b: y.id, kind: 'heading', files: xy.slice(0, 10) });
|
|
103
|
+
if (yx.length) links.push({ a: y.id, b: x.id, kind: 'heading', files: yx.slice(0, 10) });
|
|
104
|
+
if (xy.length || yx.length) continue;
|
|
105
|
+
const mx = new Set([...cx, ...Object.keys(x.touched ?? {})].map((f) => moduleOf(f, depth)));
|
|
106
|
+
const near = [...new Set([...cy, ...Object.keys(y.touched ?? {})].map((f) => moduleOf(f, depth)))].filter((m) => mx.has(m));
|
|
107
|
+
if (near.length) links.push({ a: x.id, b: y.id, kind: 'near', files: near.slice(0, 5) });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
modules: [...modules.values()].map((m) => ({ key: m.key, files: m.files, agents: [...m.agents.values()] })).sort((a, b) => b.files - a.files || a.key.localeCompare(b.key)),
|
|
112
|
+
agents: agents.map(({ id, name, busy, attention, changed, touched }) => ({ id, name, busy: Boolean(busy), attention: Boolean(attention), changed: Object.keys(changed ?? {}).length, reading: Object.values(touched ?? {}).filter((t) => t.kind === 'read').length })),
|
|
113
|
+
links,
|
|
114
|
+
};
|
|
115
|
+
}
|
package/src/config.js
CHANGED
|
@@ -70,6 +70,8 @@ const DEFAULTS = {
|
|
|
70
70
|
designDoc: true,
|
|
71
71
|
// Off unless asked, per agent too: a sample demo page of the change (published as an Artifact)
|
|
72
72
|
// and micro benchmarks of the code it changed, before and after. Per agent: demoPage, benchmarks.
|
|
73
|
+
// Each morning (weekdays), a spoken standup of the agents' news; see standup.js.
|
|
74
|
+
standup: { enabled: true, at: '09:00', weekends: false, ai: true, notify: true },
|
|
73
75
|
demoPage: false,
|
|
74
76
|
benchmarks: false,
|
|
75
77
|
// The AI judge (stuck, idle screens, reviews); see JUDGE_DEFAULTS in judge.js for every field.
|
package/src/designs.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Designs: every agent's design doc in one list: its name and summary from DESIGN.md, where it's
|
|
2
|
+
// published (the agent's Artifact, the Google Doc), the specs it builds on, and where the work
|
|
3
|
+
// stands for you, so design docs waiting for review are easy to find and read.
|
|
4
|
+
|
|
5
|
+
import { issueOf, stageOf, GROUPS } from './issues.js';
|
|
6
|
+
|
|
7
|
+
const clip = (s, n) => {
|
|
8
|
+
const t = String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
9
|
+
return t.length > n ? `${t.slice(0, n - 1)}…` : t;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** The name ("# Design: <name>") and the Summary section's text from DESIGN.md. */
|
|
13
|
+
export function designOutline(markdown) {
|
|
14
|
+
const md = String(markdown ?? '');
|
|
15
|
+
const title = md.match(/^#\s+(?:Design:\s*)?(.+)$/m)?.[1]?.trim() ?? null;
|
|
16
|
+
const summary = md.match(/^##\s+Summary\s*\n+([\s\S]*?)(?=\n#{1,3}\s|(?![\s\S]))/m)?.[1] ?? '';
|
|
17
|
+
// Plain text: no Markdown emphasis, links or code fences.
|
|
18
|
+
const plain = summary
|
|
19
|
+
.replace(/```[\s\S]*?```/g, '')
|
|
20
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
|
|
21
|
+
.replace(/[*_`]/g, '');
|
|
22
|
+
return { title: title ? clip(title, 120) : null, summary: clip(plain, 400) || null };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The list's rows: one per agent with a design doc (written, published or asked for).
|
|
27
|
+
* `read(agentId)` gives the agent's DESIGN.md text, or null.
|
|
28
|
+
*/
|
|
29
|
+
export function designRows(views, read) {
|
|
30
|
+
const rank = Object.fromEntries(Object.keys(GROUPS).map((k, i) => [k, i]));
|
|
31
|
+
const rows = [];
|
|
32
|
+
for (const v of views) {
|
|
33
|
+
if (v.kind === 'assistant' || v.kind === 'general') continue;
|
|
34
|
+
const refs = v.brief?.references ?? [];
|
|
35
|
+
const pageRef = refs.find((r) => /design page/i.test(r.label));
|
|
36
|
+
const google = v.drive?.files?.designdoc?.url ?? null;
|
|
37
|
+
const written = v.specDocs?.designdoc ?? null;
|
|
38
|
+
if (!written && !pageRef && !google) continue;
|
|
39
|
+
const outline = written ? designOutline(read(v.id)) : { title: null, summary: null };
|
|
40
|
+
const issue = issueOf(v);
|
|
41
|
+
const { stage, note } = stageOf(v);
|
|
42
|
+
rows.push({
|
|
43
|
+
agent: { id: v.id, name: v.name, project: v.projectInfo?.name ?? null, running: Boolean(v.runtime?.running), busy: Boolean(v.runtime?.busy) },
|
|
44
|
+
title: outline.title ?? v.synopsis?.text ?? v.name,
|
|
45
|
+
summary: outline.summary,
|
|
46
|
+
written: Boolean(written),
|
|
47
|
+
updatedAt: written ?? v.drive?.files?.designdoc?.at ?? v.activeAt ?? null,
|
|
48
|
+
page: pageRef?.url ? { url: pageRef.url } : pageRef?.highlight ? { note: clip(pageRef.highlight, 160) } : null,
|
|
49
|
+
google,
|
|
50
|
+
// The specs it builds on: PRDs, tech specs and other key documents in the brief.
|
|
51
|
+
specs: refs.filter((r) => r.key && r.url && r !== pageRef).slice(0, 4).map((r) => ({ label: r.label, title: r.title, url: r.url })),
|
|
52
|
+
issue: issue ? { key: issue.key, url: issue.url } : null,
|
|
53
|
+
stage,
|
|
54
|
+
group: GROUPS[stage],
|
|
55
|
+
note: clip(note, 200),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return rows.sort((a, b) => rank[a.stage] - rank[b.stage] || String(b.updatedAt ?? '').localeCompare(String(a.updatedAt ?? '')));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The rows as a Markdown list, to paste. */
|
|
62
|
+
export function designsMarkdown(rows) {
|
|
63
|
+
if (!rows.length) return 'No design docs.';
|
|
64
|
+
const link = (label, url) => (url ? `[${label}](${url})` : null);
|
|
65
|
+
return rows
|
|
66
|
+
.map((r) => {
|
|
67
|
+
const head = `- **${r.title}**${r.issue ? ` (${link(r.issue.key, r.issue.url) ?? r.issue.key})` : ''}: ${r.note}`;
|
|
68
|
+
const links = [link('Design page', r.page?.url), link('Google Doc', r.google), ...r.specs.map((s) => link(s.label, s.url))].filter(Boolean);
|
|
69
|
+
return [head, r.summary ? ` ${r.summary}` : null, links.length ? ` ${links.join(' · ')}` : null].filter(Boolean).join('\n');
|
|
70
|
+
})
|
|
71
|
+
.join('\n');
|
|
72
|
+
}
|
package/src/issues.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// Issues: every Jira (or Linear) issue an agent works on, one row per agent, with where it stands
|
|
2
|
+
// for you: waiting for your review (an open pull request, a finished agent, a question), with the
|
|
3
|
+
// agent still on it, or done. The issue's own workflow status comes from Jira when it can be had.
|
|
4
|
+
|
|
5
|
+
import { leadingJiraKey, landState } from './tracker.js';
|
|
6
|
+
import { wordsAfterLink } from './jira.js';
|
|
7
|
+
import { designOutline } from './designs.js';
|
|
8
|
+
import { needsOf } from './standup.js';
|
|
9
|
+
|
|
10
|
+
const ISSUE_KEY = /^[A-Z][A-Z0-9_]+-\d+$/;
|
|
11
|
+
const MAX_PROPOSED = 200;
|
|
12
|
+
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
13
|
+
const NEEDS = new Set(['prompt', 'waiting', 'plan', 'question']);
|
|
14
|
+
|
|
15
|
+
/** Where each stage goes in the summary's filters. */
|
|
16
|
+
// In the order they're listed.
|
|
17
|
+
export const GROUPS = {
|
|
18
|
+
proposed: 'new',
|
|
19
|
+
needs: 'you',
|
|
20
|
+
review: 'you',
|
|
21
|
+
blocked: 'you',
|
|
22
|
+
approved: 'you',
|
|
23
|
+
working: 'agent',
|
|
24
|
+
fixing: 'agent',
|
|
25
|
+
merged: 'done',
|
|
26
|
+
closed: 'done',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The issue an agent works on: { key, url }, from the link its request starts with or one in it. */
|
|
30
|
+
export function issueOf(v) {
|
|
31
|
+
const lead = leadingJiraKey(v.intent);
|
|
32
|
+
const bugs = (v.bugs ?? []).filter((b) => b.source === 'intent' && ISSUE_KEY.test(b.key));
|
|
33
|
+
const key = v.synopsis?.key ?? lead ?? bugs[0]?.key ?? null;
|
|
34
|
+
if (!key) return null;
|
|
35
|
+
const bug = bugs.find((b) => b.key === key) ?? (v.bugs ?? []).find((b) => b.key === key);
|
|
36
|
+
const url = bug?.url ?? String(v.intent ?? '').trimStart().match(/^<?(https?:\/\/\S+)/)?.[1]?.replace(/>$/, '') ?? null;
|
|
37
|
+
return { key, url, title: (v.synopsis?.key === key ? v.synopsis.text : null) ?? bug?.title ?? null };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Where the work stands for you: { stage, note, pr }. */
|
|
41
|
+
export function stageOf(v) {
|
|
42
|
+
const prs = (v.prs ?? []).filter((p) => p.source !== 'mentioned' && p.state);
|
|
43
|
+
const open = prs.filter((p) => p.state === 'OPEN');
|
|
44
|
+
// The newest PR the agent is on.
|
|
45
|
+
const pr = open.at(-1) ?? prs.at(-1) ?? null;
|
|
46
|
+
const needs = needsOf(v).filter((n) => NEEDS.has(n.kind));
|
|
47
|
+
if (needs.length) return { stage: 'needs', note: `Needs your answer: ${needs[0].text}`, pr };
|
|
48
|
+
if (open.length) {
|
|
49
|
+
const land = landState(pr);
|
|
50
|
+
if (pr.isDraft) return { stage: 'working', note: 'Draft pull request', pr };
|
|
51
|
+
if (pr.review === 'APPROVED') return { stage: 'approved', note: 'Approved, not merged yet', pr };
|
|
52
|
+
if (pr.review === 'CHANGES_REQUESTED') return { stage: 'fixing', note: v.runtime?.busy ? 'Working on your review comments' : 'Changes requested', pr };
|
|
53
|
+
if (land === 'fix') return { stage: 'fixing', note: pr.checks?.state === 'failed' ? 'Checks failing' : 'Merge conflict', pr };
|
|
54
|
+
return { stage: 'review', note: pr.checks?.state === 'running' ? 'Ready for your review (checks running)' : 'Ready for your review', pr };
|
|
55
|
+
}
|
|
56
|
+
if (prs.some((p) => p.state === 'MERGED')) return { stage: 'merged', note: 'Merged', pr };
|
|
57
|
+
if (prs.length) return { stage: 'closed', note: 'Pull request closed', pr };
|
|
58
|
+
const outcome = v.results?.outcome;
|
|
59
|
+
if (outcome === 'blocked') return { stage: 'blocked', note: `Blocked${v.results.blockers?.[0]?.text ? `: ${v.results.blockers[0].text}` : ''}`, pr };
|
|
60
|
+
if (outcome === 'done') return { stage: 'review', note: 'Done, no pull request: review it in the session', pr };
|
|
61
|
+
return { stage: 'working', note: v.runtime?.busy ? 'Agent working' : v.runtime?.running ? 'Agent idle' : 'Agent not running', pr };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A plan's steps: { done, total } from its "- [x]" and "- [ ]" items. */
|
|
65
|
+
export function planSteps(markdown) {
|
|
66
|
+
const items = String(markdown ?? '').match(/^\s*[-*]\s+\[[ xX]\]/gm) ?? [];
|
|
67
|
+
return { done: items.filter((i) => /\[[xX]\]/.test(i)).length, total: items.length };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The agent's plan: written or not, its steps, and its review when plans are reviewed. */
|
|
71
|
+
function planOf(v, read) {
|
|
72
|
+
const written = Boolean(v.specDocs?.plan);
|
|
73
|
+
const review = v.planReview?.status ?? null;
|
|
74
|
+
if (!written && !review) return null;
|
|
75
|
+
const steps = written ? planSteps(read(v.id, 'plan')) : { done: 0, total: 0 };
|
|
76
|
+
return { written, review, ...steps };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The agent's design doc: written or not, its summary, and where it's published. */
|
|
80
|
+
function designOf(v, read) {
|
|
81
|
+
const written = Boolean(v.specDocs?.designdoc);
|
|
82
|
+
const ref = (v.brief?.references ?? []).find((r) => /design page/i.test(r.label));
|
|
83
|
+
const google = v.drive?.files?.designdoc?.url ?? null;
|
|
84
|
+
if (!written && !ref && !google && !v.designDoc) return null;
|
|
85
|
+
const summary = written ? designOutline(read(v.id, 'designdoc')).summary : null;
|
|
86
|
+
return { written, page: ref?.url ?? null, google, ...(summary ? { summary } : {}) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The summary's rows from agent views, those waiting for you first.
|
|
91
|
+
* `read(agentId, name)` gives one of the agent's documents ('plan'), or null.
|
|
92
|
+
*/
|
|
93
|
+
export function issueRows(views, jira = new Map(), read = () => null, proposed = []) {
|
|
94
|
+
const rank = Object.fromEntries(Object.keys(GROUPS).map((k, i) => [k, i]));
|
|
95
|
+
const rows = [];
|
|
96
|
+
// Issues proposed for agents, not started yet: they wait for you to tick them.
|
|
97
|
+
for (const p of proposed) {
|
|
98
|
+
const j = jira.get(p.key) ?? null;
|
|
99
|
+
rows.push({
|
|
100
|
+
key: p.key,
|
|
101
|
+
url: p.url,
|
|
102
|
+
title: j?.summary ?? p.title,
|
|
103
|
+
jira: j ? { status: j.status, category: j.category } : null,
|
|
104
|
+
stage: 'proposed',
|
|
105
|
+
group: 'new',
|
|
106
|
+
note: `Not started${p.project ? ` (@${p.project})` : ''}: tick it to start an agent`,
|
|
107
|
+
agent: null,
|
|
108
|
+
proposal: { project: p.project ?? null, repo: p.repo ?? null, by: p.by ?? null, intent: p.intent },
|
|
109
|
+
pr: null,
|
|
110
|
+
aiReview: null,
|
|
111
|
+
plan: null,
|
|
112
|
+
design: null,
|
|
113
|
+
updatedAt: p.at,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
for (const v of views) {
|
|
117
|
+
if (v.kind === 'assistant') continue;
|
|
118
|
+
const issue = issueOf(v);
|
|
119
|
+
if (!issue) continue;
|
|
120
|
+
const { stage, note, pr } = stageOf(v);
|
|
121
|
+
const j = jira.get(issue.key) ?? null;
|
|
122
|
+
rows.push({
|
|
123
|
+
key: issue.key,
|
|
124
|
+
url: issue.url,
|
|
125
|
+
title: j?.summary ?? issue.title,
|
|
126
|
+
jira: j ? { status: j.status, category: j.category } : null,
|
|
127
|
+
stage,
|
|
128
|
+
group: GROUPS[stage],
|
|
129
|
+
note: note.length > 200 ? `${note.slice(0, 199)}…` : note,
|
|
130
|
+
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
|
+
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
|
+
aiReview: v.aiReview?.verdict ?? null,
|
|
133
|
+
plan: planOf(v, read),
|
|
134
|
+
design: designOf(v, read),
|
|
135
|
+
updatedAt: v.activeAt ?? v.createdAt ?? null,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return rows.sort((a, b) => rank[a.stage] - rank[b.stage] || String(b.updatedAt ?? '').localeCompare(String(a.updatedAt ?? '')));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const REVIEW = { writing: 'being written', review: 'waiting for your approval', approved: 'approved', changes: 'changes asked' };
|
|
142
|
+
|
|
143
|
+
/** A plan in a few words: "3/5 steps, approved". */
|
|
144
|
+
export function planText(p) {
|
|
145
|
+
if (!p) return '';
|
|
146
|
+
const steps = p.total ? `${p.done}/${p.total} steps` : p.written ? 'written' : '';
|
|
147
|
+
return [steps, p.review ? REVIEW[p.review] ?? p.review : null].filter(Boolean).join(', ');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A design doc in a few words, with its links. */
|
|
151
|
+
function designText(d) {
|
|
152
|
+
if (!d) return '';
|
|
153
|
+
const links = [d.page && `[page](${d.page})`, d.google && `[doc](${d.google})`].filter(Boolean);
|
|
154
|
+
return links.length ? links.join(' ') : d.written ? 'written' : 'not yet';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The rows as a Markdown table, to paste into Slack, Jira or a doc. */
|
|
158
|
+
export function issuesMarkdown(rows) {
|
|
159
|
+
const cell = (s) => String(s ?? '').replace(/\|/g, '\\|').replace(/\s+/g, ' ').trim();
|
|
160
|
+
const lines = ['| Issue | Jira status | Where it stands | Plan | Design | Pull request | Agent |', '|---|---|---|---|---|---|---|'];
|
|
161
|
+
for (const r of rows) {
|
|
162
|
+
const issue = r.url ? `[${r.key}](${r.url})` : r.key;
|
|
163
|
+
const pr = r.pr ? (r.pr.url ? `[#${r.pr.number ?? '?'}](${r.pr.url})` : `#${r.pr.number}`) : '';
|
|
164
|
+
lines.push(`| ${issue}${r.title ? ` ${cell(r.title)}` : ''} | ${cell(r.jira?.status ?? '')} | ${cell(r.note)} | ${planText(r.plan)} | ${designText(r.design)} | ${pr} | ${cell(r.agent?.name ?? '')} |`);
|
|
165
|
+
}
|
|
166
|
+
return lines.join('\n');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Issues proposed for agents (by the assistant, when you pick), waiting for you to tick the ones
|
|
171
|
+
* to start. Kept in state.json; dismissed ones are remembered so they aren't proposed again.
|
|
172
|
+
*/
|
|
173
|
+
export class ProposedIssues {
|
|
174
|
+
constructor({ store, manager }) {
|
|
175
|
+
this.store = store;
|
|
176
|
+
this.manager = manager;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get all() {
|
|
180
|
+
return (this.store.data.proposedIssues ??= []);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The ones waiting for you, without those an agent has taken up meanwhile. */
|
|
184
|
+
waiting() {
|
|
185
|
+
return this.all.filter((p) => p.status === 'waiting' && !this.agentFor(p.key));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
agentFor(key) {
|
|
189
|
+
const k = key.toLowerCase();
|
|
190
|
+
return this.store.list().find((a) => a.kind === 'task' && (a.name.toLowerCase() === k || leadingJiraKey(a.intent)?.toLowerCase() === k)) ?? null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Propose an issue: the request starts with its link. */
|
|
194
|
+
add({ intent, project = null, repo = null, by = null } = {}) {
|
|
195
|
+
const text = String(intent ?? '').trim();
|
|
196
|
+
const key = leadingJiraKey(text);
|
|
197
|
+
if (!key) throw err(400, 'Start the request with the issue link (a Jira /browse/KEY-1 or Linear /issue/KEY-1 link)');
|
|
198
|
+
const agent = this.agentFor(key);
|
|
199
|
+
if (agent) throw err(409, `An agent for ${key} already exists: ${agent.name} (${agent.id})`);
|
|
200
|
+
const prev = this.all.find((p) => p.key === key);
|
|
201
|
+
if (prev?.status === 'dismissed') throw err(409, `${key} was dismissed; not proposed again`);
|
|
202
|
+
if (prev?.status === 'started') throw err(409, `${key} was started already`);
|
|
203
|
+
project = project ? String(project).trim().replace(/^@/, '') || null : null;
|
|
204
|
+
if (project && !this.manager.resolveProject(project)) throw err(400, `No project @${project}; see agentmgr project ls`);
|
|
205
|
+
const item = {
|
|
206
|
+
key,
|
|
207
|
+
url: text.match(/^<?(https?:\/\/\S+)/)[1].replace(/>$/, ''),
|
|
208
|
+
title: wordsAfterLink(text),
|
|
209
|
+
intent: text.slice(0, 4000),
|
|
210
|
+
project,
|
|
211
|
+
repo: repo || null,
|
|
212
|
+
by: by || null,
|
|
213
|
+
status: 'waiting',
|
|
214
|
+
at: prev?.at ?? new Date().toISOString(),
|
|
215
|
+
};
|
|
216
|
+
if (prev) Object.assign(prev, item);
|
|
217
|
+
else this.all.push(item);
|
|
218
|
+
// Old decisions go first when the list grows long.
|
|
219
|
+
while (this.all.length > MAX_PROPOSED) {
|
|
220
|
+
const i = this.all.findIndex((p) => p.status !== 'waiting');
|
|
221
|
+
this.all.splice(i < 0 ? 0 : i, 1);
|
|
222
|
+
}
|
|
223
|
+
this.store.save();
|
|
224
|
+
return item;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Start agents for the ticked issues: { started: [{ key, agent }], failed: [{ key, reason }] }. */
|
|
228
|
+
start(keys = []) {
|
|
229
|
+
const started = [];
|
|
230
|
+
const failed = [];
|
|
231
|
+
for (const key of new Set(keys)) {
|
|
232
|
+
const p = this.all.find((x) => x.key === key && x.status === 'waiting');
|
|
233
|
+
if (!p) {
|
|
234
|
+
failed.push({ key, reason: 'not waiting to be started' });
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const agent = this.agentFor(key);
|
|
238
|
+
if (agent) {
|
|
239
|
+
p.status = 'started';
|
|
240
|
+
p.agentId = agent.id;
|
|
241
|
+
failed.push({ key, reason: `${agent.name} (${agent.id}) already works on it` });
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
const [a] = this.manager.createMany([p.intent], { ...(p.project ? { project: p.project } : {}), ...(p.repo ? { repo: p.repo } : {}) });
|
|
246
|
+
p.status = 'started';
|
|
247
|
+
p.agentId = a.id;
|
|
248
|
+
p.startedAt = new Date().toISOString();
|
|
249
|
+
started.push({ key, agent: { id: a.id, name: a.name } });
|
|
250
|
+
} catch (e) {
|
|
251
|
+
failed.push({ key, reason: e.message });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
this.store.save();
|
|
255
|
+
return { started, failed };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Not for an agent: off the list, and not proposed again. */
|
|
259
|
+
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 };
|
|
271
|
+
}
|
|
272
|
+
}
|
package/src/jira.js
CHANGED
|
@@ -76,7 +76,15 @@ export function wordsAfterLink(text) {
|
|
|
76
76
|
* The issue's summary, or null when it can't be had (not a site we contact, no access, offline).
|
|
77
77
|
* `fetchImpl` and `allow` are for tests.
|
|
78
78
|
*/
|
|
79
|
-
export async function issueSummary(
|
|
79
|
+
export async function issueSummary(issue, opts = {}) {
|
|
80
|
+
return (await issueFields(issue, opts))?.summary ?? null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The issue's summary and workflow status ({ summary, status, category }: category is Jira's
|
|
85
|
+
* "new", "indeterminate" or "done"), or null when it can't be had.
|
|
86
|
+
*/
|
|
87
|
+
export async function issueFields({ key, site }, { jira = loadJira(), fetchImpl = fetch, timeoutMs = 6000, allow = null } = {}) {
|
|
80
88
|
const host = (() => {
|
|
81
89
|
try {
|
|
82
90
|
return new URL(site).host;
|
|
@@ -90,10 +98,13 @@ export async function issueSummary({ key, site }, { jira = loadJira(), fetchImpl
|
|
|
90
98
|
const headers = { accept: 'application/json' };
|
|
91
99
|
if (configured && jira.email && jira.token) headers.authorization = `Basic ${Buffer.from(`${jira.email}:${jira.token}`).toString('base64')}`;
|
|
92
100
|
try {
|
|
93
|
-
const res = await fetchImpl(`${site}/rest/api/3/issue/${encodeURIComponent(key)}?fields=summary`, { headers, redirect: 'error', signal: AbortSignal.timeout(timeoutMs) });
|
|
101
|
+
const res = await fetchImpl(`${site}/rest/api/3/issue/${encodeURIComponent(key)}?fields=summary,status`, { headers, redirect: 'error', signal: AbortSignal.timeout(timeoutMs) });
|
|
94
102
|
if (!res.ok) return null;
|
|
95
|
-
const
|
|
96
|
-
|
|
103
|
+
const f = (await res.json())?.fields ?? {};
|
|
104
|
+
const summary = typeof f.summary === 'string' && f.summary.trim() ? f.summary.trim().slice(0, 300) : null;
|
|
105
|
+
const status = typeof f.status?.name === 'string' ? f.status.name.slice(0, 60) : null;
|
|
106
|
+
if (!summary && !status) return null;
|
|
107
|
+
return { summary, status, category: typeof f.status?.statusCategory?.key === 'string' ? f.status.statusCategory.key : null };
|
|
97
108
|
} catch {
|
|
98
109
|
return null;
|
|
99
110
|
}
|
package/src/manager.js
CHANGED
|
@@ -105,8 +105,11 @@ async function repoLayout(dir) {
|
|
|
105
105
|
}
|
|
106
106
|
import { spawn } from 'node:child_process';
|
|
107
107
|
import * as git from './git.js';
|
|
108
|
+
import { buildMap, touchedFiles } from './codemap.js';
|
|
108
109
|
import { parseDiff } from '../public/review.js';
|
|
109
|
-
import { issueSummary, leadingIssue, wordsAfterLink } from './jira.js';
|
|
110
|
+
import { issueFields, issueSummary, leadingIssue, loadJira, wordsAfterLink } from './jira.js';
|
|
111
|
+
import { issueRows } from './issues.js';
|
|
112
|
+
import { designRows } from './designs.js';
|
|
110
113
|
import { reminderFor, reminderSettings } from './reminders.js';
|
|
111
114
|
import { combine, facts as scoreFacts, improveMessage, scorecardMarkdown, scorecardPrompt } from './scorecard.js';
|
|
112
115
|
import { CONTAINER_ENGINES, claudeToken, containerName, containerRunning, engineMounts, gitCommonDir, removeContainer, runArgs, stopContainer } from './container.js';
|
|
@@ -783,8 +786,98 @@ export class AgentManager extends EventEmitter {
|
|
|
783
786
|
return html;
|
|
784
787
|
}
|
|
785
788
|
|
|
789
|
+
/**
|
|
790
|
+
* The codebase map of one project (its key, else the one with the most running agents): its
|
|
791
|
+
* folders, and where each of its agents is changing and reading code now (codemap.js).
|
|
792
|
+
*/
|
|
793
|
+
async codeMap(projectKey) {
|
|
794
|
+
const withCode = this.store.list().filter((a) => a.workdir && !NO_REPO.has(a.kind) && fs.existsSync(a.workdir));
|
|
795
|
+
const groups = new Map();
|
|
796
|
+
for (const a of withCode) {
|
|
797
|
+
const p = this.projectInfo(a);
|
|
798
|
+
if (!p) continue;
|
|
799
|
+
const g = groups.get(p.key) ?? groups.set(p.key, { key: p.key, name: p.name, agents: [] }).get(p.key);
|
|
800
|
+
g.agents.push(a);
|
|
801
|
+
}
|
|
802
|
+
const running = (g) => g.agents.filter((a) => this.runtimes.get(a.id)?.pty).length;
|
|
803
|
+
const projects = [...groups.values()].sort((x, y) => running(y) - running(x) || y.agents.length - x.agents.length);
|
|
804
|
+
const g = (projectKey && groups.get(projectKey)) || projects[0];
|
|
805
|
+
const list = projects.map((p) => ({ key: p.key, name: p.name, agents: p.agents.length, running: running(p) }));
|
|
806
|
+
if (!g) return { project: null, projects: list, map: buildMap({}) };
|
|
807
|
+
// Running agents, and closed ones with changes not yet merged.
|
|
808
|
+
const shown = g.agents.filter((a) => this.runtimes.get(a.id)?.pty || Object.keys(this.changeSets.get(a.id)?.files ?? {}).length);
|
|
809
|
+
const root = shown.find((a) => a.sourceDir && fs.existsSync(a.sourceDir))?.sourceDir ?? (shown[0] ?? g.agents[0]).workdir;
|
|
810
|
+
const files = await this.repoFiles(root);
|
|
811
|
+
const agents = shown.map((a) => {
|
|
812
|
+
const rt = this.runtimes.get(a.id);
|
|
813
|
+
let touched = {};
|
|
814
|
+
try {
|
|
815
|
+
touched = rt?.pty ? touchedFiles(engineOf(a).sessionFile(a.workdir, a.sessionId), a.workdir) : {};
|
|
816
|
+
} catch {}
|
|
817
|
+
return { id: a.id, name: a.name, busy: rt?.busy, attention: rt?.attention, changed: this.changeSets.get(a.id)?.files ?? {}, touched };
|
|
818
|
+
});
|
|
819
|
+
return { project: { key: g.key, name: g.name }, projects: list, map: buildMap({ files, agents }) };
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* The issues agents work on, for the summary: one row per agent, with each issue's Jira status
|
|
824
|
+
* (fetched a few at a time, kept five minutes).
|
|
825
|
+
*/
|
|
826
|
+
async issues(proposed = []) {
|
|
827
|
+
const views = this.store.list().map((a) => this.view(a));
|
|
828
|
+
const rows = issueRows(views, new Map(), () => null, proposed);
|
|
829
|
+
this.jiraCache ??= new Map();
|
|
830
|
+
const jira = new Map();
|
|
831
|
+
const want = [];
|
|
832
|
+
for (const r of rows) {
|
|
833
|
+
if (jira.has(r.key)) continue;
|
|
834
|
+
const hit = this.jiraCache.get(r.key);
|
|
835
|
+
if (hit && Date.now() - hit.at < 5 * 60_000) jira.set(r.key, hit.fields);
|
|
836
|
+
else if (r.url && want.length < 40) {
|
|
837
|
+
let site = null;
|
|
838
|
+
try {
|
|
839
|
+
site = new URL(r.url).origin;
|
|
840
|
+
} catch {}
|
|
841
|
+
if (site) want.push({ key: r.key, site });
|
|
842
|
+
jira.set(r.key, null);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const opts = { ...this.jiraOptions };
|
|
846
|
+
for (let i = 0; i < want.length; i += 4) {
|
|
847
|
+
await Promise.all(
|
|
848
|
+
want.slice(i, i + 4).map(async (w) => {
|
|
849
|
+
const fields = await issueFields(w, opts).catch(() => null);
|
|
850
|
+
this.jiraCache.set(w.key, { at: Date.now(), fields });
|
|
851
|
+
jira.set(w.key, fields);
|
|
852
|
+
}),
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
for (const [k, v] of jira) if (!v) jira.delete(k);
|
|
856
|
+
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) } };
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/** Every agent's design doc, for the Designs list. */
|
|
861
|
+
designs() {
|
|
862
|
+
const views = this.store.list().map((a) => this.view(a));
|
|
863
|
+
return { rows: designRows(views, (id) => readSpecDoc(id, 'designdoc')?.markdown ?? null) };
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** A repository's tracked files, for the map (kept a few minutes). */
|
|
867
|
+
async repoFiles(dir) {
|
|
868
|
+
this.fileLists ??= new Map();
|
|
869
|
+
const hit = this.fileLists.get(dir);
|
|
870
|
+
if (hit && Date.now() - hit.at < 5 * 60_000) return hit.files;
|
|
871
|
+
// From the commit, not the index: the shared clone agents branch from may have no working copy.
|
|
872
|
+
const out = await git.run('git', ['ls-tree', '-r', '--name-only', 'HEAD'], { cwd: dir, timeout: 30_000 }).catch(() => '');
|
|
873
|
+
const files = out.split('\n').filter(Boolean);
|
|
874
|
+
this.fileLists.set(dir, { at: Date.now(), files });
|
|
875
|
+
return files;
|
|
876
|
+
}
|
|
877
|
+
|
|
786
878
|
/** Fill in summaries still missing (after Jira settings change); returns how many it found. */
|
|
787
879
|
async refreshSynopses() {
|
|
880
|
+
this.jiraCache?.clear();
|
|
788
881
|
let found = 0;
|
|
789
882
|
for (const a of this.store.list()) {
|
|
790
883
|
if (a.synopsis?.source === 'jira' || !leadingIssue(a.intent)) continue;
|
|
@@ -2444,6 +2537,18 @@ export class AgentManager extends EventEmitter {
|
|
|
2444
2537
|
return this.view(this.store.get(agent.id));
|
|
2445
2538
|
}
|
|
2446
2539
|
|
|
2540
|
+
/**
|
|
2541
|
+
* One Google Doc in a Drive folder (created the first time, `folderId` after that), through the
|
|
2542
|
+
* Google Drive connector of the Claude account: { folderId, id, url }.
|
|
2543
|
+
*/
|
|
2544
|
+
async publishDriveDoc({ folderTitle, folderId = null, title, markdown }) {
|
|
2545
|
+
const sent = [{ key: 'doc', title, html: driveHtml(title, markdown) }];
|
|
2546
|
+
const reply = await this.oneShot({ id: 'drive' }, drivePrompt({ folderTitle, folderId, docs: sent, trash: [] }), { engine: engineOf('claude'), tools: DRIVE_TOOLS, timeoutMs: 600_000 });
|
|
2547
|
+
const r = parseDrive(reply, ['doc']);
|
|
2548
|
+
if (!r.files.doc) throw new Error(r.errors[0] ?? 'Google Drive returned no document (is the Google Drive connector linked to your Claude account?)');
|
|
2549
|
+
return { folderId: r.folderId, id: r.files.doc, url: docUrl(r.files.doc) };
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2447
2552
|
/** Diagrams only: the problem and its solution drawn from the documents already written and the live context. */
|
|
2448
2553
|
async runDiagrams(agent, ctx) {
|
|
2449
2554
|
const cur0 = this.store.get(agent.id) ?? agent;
|
package/src/notify.js
CHANGED
|
@@ -18,6 +18,8 @@ export const EVENT_DEFAULTS = {
|
|
|
18
18
|
question: true, // asked a question in the decision inbox
|
|
19
19
|
assistant: true, // an agent was started for new work (assistant, GitHub label, webhook)
|
|
20
20
|
budget: true, // an agent neared or reached its budget, or today's spend reached the daily limit
|
|
21
|
+
standup: true, // the daily standup is ready to play
|
|
22
|
+
value: true, // a scheduled value report (week, month, quarter)
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
// Alerts the AI judge may hold for the digest or drop; the rest are always sent at once.
|