ai-agentmanager 1.21.0 → 1.23.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 +12 -0
- package/README.md +84 -2
- package/package.json +1 -1
- package/public/app.js +64 -2
- package/public/designs.js +172 -0
- package/public/index.html +18 -0
- package/public/issues.js +255 -0
- package/public/keys.js +6 -2
- package/public/land.js +2 -0
- package/public/prvoice.js +103 -0
- package/public/reviews.js +318 -0
- package/public/speak.js +7 -2
- package/public/style.css +144 -0
- package/public/value.js +299 -0
- package/src/assistant.js +20 -5
- package/src/cli.js +252 -1
- package/src/designs.js +72 -0
- package/src/issues.js +272 -0
- package/src/jira.js +15 -4
- package/src/manager.js +78 -8
- package/src/notify.js +1 -0
- package/src/reviews.js +359 -0
- package/src/server.js +89 -0
- package/src/value.js +609 -0
package/public/issues.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// Jira: every issue an agent works on in one table, the ones waiting for your review first: the
|
|
2
|
+
// issue and its Jira status, where the work stands, its plan, design doc and pull request, and a
|
|
3
|
+
// link to the agent. Issues proposed for agents (when you pick) come first, with a box to tick:
|
|
4
|
+
// agents start only for the ticked ones.
|
|
5
|
+
|
|
6
|
+
import { listenHtml } from './speak.js';
|
|
7
|
+
|
|
8
|
+
const SAVED = 'agentmgr.issuesFilter';
|
|
9
|
+
const FILTERS = [
|
|
10
|
+
['new', 'Not started'],
|
|
11
|
+
['you', 'Waiting for you'],
|
|
12
|
+
['agent', 'Agents on it'],
|
|
13
|
+
['done', 'Done'],
|
|
14
|
+
['all', 'All'],
|
|
15
|
+
];
|
|
16
|
+
const CHECKS = { passed: ['✓', 'Checks pass'], failed: ['✗', 'Checks failing'], running: ['●', 'Checks running'] };
|
|
17
|
+
|
|
18
|
+
export function initIssues({ api, $, esc, ago, openAgent, openDoc, toast }) {
|
|
19
|
+
const dialog = $('#issues-dialog');
|
|
20
|
+
const ext = (label, url, title = '') => `<a href="${esc(url)}" target="_blank" rel="noopener" title="${esc(title)}">${esc(label)} ↗</a>`;
|
|
21
|
+
const body = $('#issues-body');
|
|
22
|
+
let data = null;
|
|
23
|
+
let loading = false;
|
|
24
|
+
let again = null;
|
|
25
|
+
let filter = 'you';
|
|
26
|
+
// Proposed issues ticked to start, by key.
|
|
27
|
+
const ticked = new Set();
|
|
28
|
+
let starting = false;
|
|
29
|
+
try {
|
|
30
|
+
filter = localStorage.getItem(SAVED) || 'you';
|
|
31
|
+
} catch {}
|
|
32
|
+
|
|
33
|
+
let loadedAt = 0;
|
|
34
|
+
|
|
35
|
+
async function load({ quiet = false } = {}) {
|
|
36
|
+
if (loading) return;
|
|
37
|
+
loading = true;
|
|
38
|
+
try {
|
|
39
|
+
data = await api('GET', '/issues');
|
|
40
|
+
loadedAt = Date.now();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (!quiet) toast?.(e.message, 5000);
|
|
43
|
+
} finally {
|
|
44
|
+
loading = false;
|
|
45
|
+
}
|
|
46
|
+
badge();
|
|
47
|
+
render();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The button's count: issues to start or waiting for your review. */
|
|
51
|
+
function badge() {
|
|
52
|
+
const fresh = data ? data.rows.filter((r) => r.group === 'new').length : 0;
|
|
53
|
+
const n = (data ? data.rows.filter((r) => r.group === 'you').length : 0) + fresh;
|
|
54
|
+
const el = $('#issues-count');
|
|
55
|
+
if (el) {
|
|
56
|
+
el.textContent = n ? String(n) : '';
|
|
57
|
+
el.title = [fresh && `${fresh} not started`, n - fresh && `${n - fresh} waiting for your review`].filter(Boolean).join(', ');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function row(r, boxes) {
|
|
62
|
+
const box = !boxes ? '' : r.group === 'new' ? `<td class="pick"><input type="checkbox" data-issue-pick="${esc(r.key)}" ${ticked.has(r.key) ? 'checked' : ''} aria-label="Start an agent for ${esc(r.key)}" /></td>` : '<td></td>';
|
|
63
|
+
const issue = r.url ? `<a href="${esc(r.url)}" target="_blank" rel="noopener" class="issue-key">${esc(r.key)}</a>` : `<span class="issue-key">${esc(r.key)}</span>`;
|
|
64
|
+
const status = r.jira?.status ? `<span class="jira-status ${esc(r.jira.category ?? '')}">${esc(r.jira.status)}</span>` : '<span class="hint">—</span>';
|
|
65
|
+
const check = r.pr?.checks && CHECKS[r.pr.checks] ? ` <span class="checks ${esc(r.pr.checks)}" title="${CHECKS[r.pr.checks][1]}">${CHECKS[r.pr.checks][0]}</span>` : '';
|
|
66
|
+
const pr = r.pr?.url
|
|
67
|
+
? `<a href="${esc(r.pr.url)}" target="_blank" rel="noopener" title="${esc(r.pr.title ?? '')}">#${esc(r.pr.number ?? '?')}</a>${check}${r.aiReview ? `<div class="hint" title="AI review">AI: ${esc(r.aiReview)}</div>` : ''}<div>${listenHtml(`prvoice:${r.agent.id}`, { title: 'Explain the review aloud: the PR, its checks, the AI review, the riskiest changes and what is left', label: 'Explain' })}</div>`
|
|
68
|
+
: '<span class="hint">—</span>';
|
|
69
|
+
if (!r.agent) {
|
|
70
|
+
const by = r.proposal?.by === 'assistant' ? 'proposed by the assistant' : 'proposed';
|
|
71
|
+
return `<tr class="stage-proposed ${ticked.has(r.key) ? 'ticked' : ''}">${box}
|
|
72
|
+
<td>${issue}${r.title ? `<div class="issue-title">${esc(r.title)}</div>` : ''}</td>
|
|
73
|
+
<td>${status}</td>
|
|
74
|
+
<td class="issue-note">${esc(r.note)}</td>
|
|
75
|
+
<td class="hint">—</td>
|
|
76
|
+
<td class="hint">—</td>
|
|
77
|
+
<td class="hint">—</td>
|
|
78
|
+
<td><span class="hint">${esc(by)}</span>${r.proposal?.project ? `<div class="hint">@${esc(r.proposal.project)}</div>` : ''}</td>
|
|
79
|
+
<td class="hint col-active">${esc(ago(r.updatedAt))}</td>
|
|
80
|
+
</tr>`;
|
|
81
|
+
}
|
|
82
|
+
const dot = r.agent.busy ? '<span class="dot busy" title="Working"></span>' : r.agent.running ? '<span class="dot idle" title="Session open"></span>' : '';
|
|
83
|
+
const agent = `<button class="link" data-issue-open="${esc(r.agent.id)}" title="Open the agent's session">${dot}${esc(r.agent.name)}</button>${r.agent.project ? `<div class="hint">${esc(r.agent.project)}${r.agent.from ? ` · by ${esc(r.agent.from)}` : ''}</div>` : ''}`;
|
|
84
|
+
const read = (kind, label, title) => `<button class="link" data-issue-doc="${esc(kind)}" data-agent="${esc(r.agent.id)}" title="${esc(title)}">${label}</button>`;
|
|
85
|
+
const REVIEW = { writing: 'being written', review: 'waiting for your approval', approved: 'approved', changes: 'changes asked' };
|
|
86
|
+
const p = r.plan;
|
|
87
|
+
const plan = p
|
|
88
|
+
? `${p.written ? read('plan', 'Read', 'Read the plan here') : '<span class="hint">not yet</span>'}${p.total ? ` <span class="steps" title="Steps done">${p.done}/${p.total}</span>` : ''}${p.review ? `<div class="hint plan-${esc(p.review)}">${esc(REVIEW[p.review] ?? p.review)}</div>` : ''}`
|
|
89
|
+
: '<span class="hint">—</span>';
|
|
90
|
+
const d = r.design;
|
|
91
|
+
const design = d
|
|
92
|
+
? [d.written ? read('designdoc', 'Read', 'Read the design doc here') : '<span class="hint">not yet</span>', d.page && ext('Page', d.page, 'The design page the agent published'), d.google && ext('Doc', d.google, 'Google Doc')].filter(Boolean).join(' · ')
|
|
93
|
+
: '<span class="hint">—</span>';
|
|
94
|
+
return `<tr class="stage-${esc(r.stage)}">${box}
|
|
95
|
+
<td>${issue}${r.title ? `<div class="issue-title">${esc(r.title)}</div>` : ''}</td>
|
|
96
|
+
<td>${status}</td>
|
|
97
|
+
<td class="issue-note">${esc(r.note)}</td>
|
|
98
|
+
<td class="nowrap">${plan}</td>
|
|
99
|
+
<td class="nowrap">${design}</td>
|
|
100
|
+
<td>${pr}</td>
|
|
101
|
+
<td>${agent}</td>
|
|
102
|
+
<td class="hint col-active">${esc(ago(r.updatedAt))}</td>
|
|
103
|
+
</tr>`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function render() {
|
|
107
|
+
if (!dialog.open) return;
|
|
108
|
+
if (!data) {
|
|
109
|
+
body.innerHTML = '<p class="hint">Loading…</p>';
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const count = (g) => (g === 'all' ? data.rows.length : data.rows.filter((r) => r.group === g).length);
|
|
113
|
+
const rows = filter === 'all' ? data.rows : data.rows.filter((r) => r.group === filter);
|
|
114
|
+
// Ticks only for issues still on the list.
|
|
115
|
+
const fresh = new Set(data.rows.filter((r) => r.group === 'new').map((r) => r.key));
|
|
116
|
+
for (const k of ticked) if (!fresh.has(k)) ticked.delete(k);
|
|
117
|
+
const shownNew = rows.filter((r) => r.group === 'new');
|
|
118
|
+
const boxes = shownNew.length > 0;
|
|
119
|
+
const allTicked = boxes && shownNew.every((r) => ticked.has(r.key));
|
|
120
|
+
const n = ticked.size;
|
|
121
|
+
const empty = !data.rows.length
|
|
122
|
+
? 'No agent works on a Jira or Linear issue yet. Start one with the issue link first ("https://…/browse/OPS-7 fix the timeout"), or let the assistant start them for issues assigned to you.'
|
|
123
|
+
: filter === 'you'
|
|
124
|
+
? 'Nothing is waiting for your review.'
|
|
125
|
+
: filter === 'new'
|
|
126
|
+
? 'No issues waiting to be started. With "Let me pick" on in Assistant, new Jira and Linear issues assigned to you come here instead of getting agents right away (or: agentmgr issues propose).'
|
|
127
|
+
: 'None here.';
|
|
128
|
+
body.innerHTML = `
|
|
129
|
+
<div class="issues-head">
|
|
130
|
+
<h2>Jira</h2>
|
|
131
|
+
<div class="chips" role="tablist">${FILTERS.map(([k, label]) => `<button class="chip ${k === filter ? 'active' : ''}" role="tab" aria-selected="${k === filter}" data-issues-filter="${k}">${label} <span class="count">${count(k)}</span></button>`).join('')}</div>
|
|
132
|
+
<span class="spacer"></span>
|
|
133
|
+
<button class="small" data-issues="copy" title="Copy this list as a Markdown table, to paste into Slack, Jira or a doc" ${rows.length ? '' : 'disabled'}>Copy</button>
|
|
134
|
+
<button class="small" data-issues="refresh" title="Look again now">↻</button>
|
|
135
|
+
<button class="small" data-issues="close" title="Close (Esc)">Close</button>
|
|
136
|
+
</div>
|
|
137
|
+
${boxes
|
|
138
|
+
? `<div class="issues-pickbar">
|
|
139
|
+
<button class="primary small" data-issues="start" ${n && !starting ? '' : 'disabled'} title="Start an agent for each ticked issue">${starting ? 'Starting…' : `Start ${n || ''} agent${n === 1 ? '' : 's'}`.replace(' ', ' ')}</button>
|
|
140
|
+
<button class="small" data-issues="dismiss" ${n && !starting ? '' : 'disabled'} title="Take the ticked issues off the list; they won't be proposed again">Dismiss</button>
|
|
141
|
+
<span class="hint">Tick the issues to start agents for; the rest stay here.</span>
|
|
142
|
+
</div>`
|
|
143
|
+
: ''}
|
|
144
|
+
${rows.length
|
|
145
|
+
? `<div class="issues-scroll"><table class="issues">
|
|
146
|
+
<thead><tr>${boxes ? `<th class="pick"><input type="checkbox" data-issue-pick-all ${allTicked ? 'checked' : ''} aria-label="Tick all" title="Tick all" /></th>` : ''}<th>Issue</th><th>Jira status</th><th>Where it stands</th><th>Plan</th><th>Design</th><th>Pull request</th><th>Agent</th><th class="col-active">Active</th></tr></thead>
|
|
147
|
+
<tbody>${rows.map((r) => row(r, boxes)).join('')}</tbody>
|
|
148
|
+
</table></div>`
|
|
149
|
+
: `<p class="hint issues-empty">${esc(empty)}</p>`}
|
|
150
|
+
${data.jira.signedIn || !data.rows.length ? '' : '<p class="hint">Jira status shows for public issues only until you add your Jira site, email and API token in Settings → Jira.</p>'}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
body.addEventListener('change', (e) => {
|
|
154
|
+
const one = e.target.dataset.issuePick;
|
|
155
|
+
if (one) {
|
|
156
|
+
if (e.target.checked) ticked.add(one);
|
|
157
|
+
else ticked.delete(one);
|
|
158
|
+
return render();
|
|
159
|
+
}
|
|
160
|
+
if (e.target.dataset.issuePickAll !== undefined) {
|
|
161
|
+
const shown = data.rows.filter((r) => r.group === 'new' && (filter === 'all' || filter === 'new'));
|
|
162
|
+
for (const r of shown) e.target.checked ? ticked.add(r.key) : ticked.delete(r.key);
|
|
163
|
+
render();
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
async function startTicked() {
|
|
168
|
+
const keys = [...ticked];
|
|
169
|
+
starting = true;
|
|
170
|
+
render();
|
|
171
|
+
try {
|
|
172
|
+
const r = await api('POST', '/issues/start', { keys });
|
|
173
|
+
for (const x of r.started) ticked.delete(x.key);
|
|
174
|
+
const bad = r.failed.map((x) => `${x.key}: ${x.reason}`).join('; ');
|
|
175
|
+
toast?.(`${r.started.length ? `Started ${r.started.length} agent${r.started.length === 1 ? '' : 's'}: ${r.started.map((x) => x.key).join(', ')}` : 'No agents started'}${bad ? `. Not started: ${bad}` : ''}`, bad ? 8000 : 4000);
|
|
176
|
+
} catch (err) {
|
|
177
|
+
toast?.(err.message, 6000);
|
|
178
|
+
} finally {
|
|
179
|
+
starting = false;
|
|
180
|
+
}
|
|
181
|
+
load();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
body.addEventListener('click', async (e) => {
|
|
185
|
+
const o = e.target.closest('[data-issue-open]');
|
|
186
|
+
if (o) {
|
|
187
|
+
dialog.close();
|
|
188
|
+
return openAgent(o.dataset.issueOpen);
|
|
189
|
+
}
|
|
190
|
+
const doc = e.target.closest('[data-issue-doc]');
|
|
191
|
+
if (doc) {
|
|
192
|
+
dialog.close();
|
|
193
|
+
return openDoc(doc.dataset.agent, doc.dataset.issueDoc);
|
|
194
|
+
}
|
|
195
|
+
const f = e.target.closest('[data-issues-filter]');
|
|
196
|
+
if (f) {
|
|
197
|
+
filter = f.dataset.issuesFilter;
|
|
198
|
+
try {
|
|
199
|
+
localStorage.setItem(SAVED, filter);
|
|
200
|
+
} catch {}
|
|
201
|
+
return render();
|
|
202
|
+
}
|
|
203
|
+
const b = e.target.closest('[data-issues]')?.dataset.issues;
|
|
204
|
+
if (b === 'close') return dialog.close();
|
|
205
|
+
if (b === 'refresh') return load();
|
|
206
|
+
if (b === 'start') return startTicked();
|
|
207
|
+
if (b === 'dismiss') {
|
|
208
|
+
try {
|
|
209
|
+
const r = await api('POST', '/issues/dismiss', { keys: [...ticked] });
|
|
210
|
+
ticked.clear();
|
|
211
|
+
toast?.(`${r.dismissed} dismissed`);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
toast?.(err.message, 6000);
|
|
214
|
+
}
|
|
215
|
+
return load();
|
|
216
|
+
}
|
|
217
|
+
if (b === 'copy') {
|
|
218
|
+
try {
|
|
219
|
+
const { markdown } = await api('GET', `/issues?group=${encodeURIComponent(filter)}&format=markdown`);
|
|
220
|
+
await navigator.clipboard.writeText(markdown);
|
|
221
|
+
toast?.('Copied as a Markdown table');
|
|
222
|
+
} catch (err) {
|
|
223
|
+
toast?.(`Couldn't copy: ${err.message}`, 5000);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
function open() {
|
|
229
|
+
if (dialog.open) return dialog.close();
|
|
230
|
+
dialog.showModal();
|
|
231
|
+
render();
|
|
232
|
+
load();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** An agent changed: look again shortly while open, and now and then for the count. */
|
|
236
|
+
function changed() {
|
|
237
|
+
// Closed: one look at most every half minute, however busy the agents are.
|
|
238
|
+
if (!dialog.open && again) return;
|
|
239
|
+
clearTimeout(again);
|
|
240
|
+
const wait = dialog.open ? 1500 : Math.max(5000, 30_000 - (Date.now() - loadedAt));
|
|
241
|
+
again = setTimeout(() => {
|
|
242
|
+
again = null;
|
|
243
|
+
load({ quiet: true });
|
|
244
|
+
}, wait);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
load({ quiet: true });
|
|
248
|
+
/** What the table knows about an agent's issue: its key and design doc summary. */
|
|
249
|
+
const about = (agentId) => {
|
|
250
|
+
const r = data?.rows.find((x) => x.agent?.id === agentId);
|
|
251
|
+
return r ? { issueKey: r.key, designSummary: r.design?.summary ?? null } : {};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return { open, changed, about, isOpen: () => dialog.open };
|
|
255
|
+
}
|
package/public/keys.js
CHANGED
|
@@ -18,6 +18,10 @@ export const SHORTCUTS = [
|
|
|
18
18
|
[['w'], 'Watch: agents side by side', 'watch'],
|
|
19
19
|
[['p'], 'Play the standup', 'standup'],
|
|
20
20
|
[['m'], 'Map: where agents are in the code', 'map'],
|
|
21
|
+
[['i'], 'Jira: issues waiting for your review', 'issues'],
|
|
22
|
+
[['d'], 'Designs: agents\' design docs', 'designs'],
|
|
23
|
+
[['g'], 'Reviews: pull requests you review', 'reviews'],
|
|
24
|
+
[['v'], 'Value: what the work is worth', 'value'],
|
|
21
25
|
[['1'], 'Agents tab', 'tab:agents'],
|
|
22
26
|
[['2'], 'Inbox: what needs you', 'tab:inbox'],
|
|
23
27
|
[['3'], 'Backlog', 'tab:backlog'],
|
|
@@ -36,11 +40,11 @@ export const SHORTCUTS = [
|
|
|
36
40
|
// A single key, as an event names it, to its action.
|
|
37
41
|
export const SINGLE = {
|
|
38
42
|
j: 'next', k: 'prev', Enter: 'terminal', t: 'terminal',
|
|
39
|
-
r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', '?': 'help',
|
|
43
|
+
r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', d: 'designs', g: 'reviews', v: 'value', '?': 'help',
|
|
40
44
|
1: 'tab:agents', 2: 'tab:inbox', 3: 'tab:backlog', 4: 'tab:land', 5: 'tab:built',
|
|
41
45
|
};
|
|
42
46
|
// While Watch is open: only what makes sense there.
|
|
43
|
-
const ON_WATCH = new Set(['new', 'ask', 'watch', 'standup', 'map', 'help']);
|
|
47
|
+
const ON_WATCH = new Set(['new', 'ask', 'watch', 'standup', 'map', 'issues', 'designs', 'reviews', 'value', 'help']);
|
|
44
48
|
|
|
45
49
|
/** Typing somewhere: a field, an editor or a terminal (xterm types through a textarea). */
|
|
46
50
|
const typing = (el) => Boolean(el?.closest?.('input, textarea, select, [contenteditable=""], [contenteditable="true"], .xterm, .cm-editor'));
|
package/public/land.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Land tab: every agent's open pull request, grouped by what it needs to get merged, with
|
|
2
2
|
// Review, Update, Ask to fix and Merge. Settings for sending failures back to agents at the bottom.
|
|
3
3
|
|
|
4
|
+
import { listenHtml } from './speak.js';
|
|
4
5
|
const SHORT = { ready: 'ready', fix: 'to fix', behind: 'behind', waiting: 'waiting', draft: 'draft' };
|
|
5
6
|
const GROUPS = [
|
|
6
7
|
['ready', 'Ready to merge'],
|
|
@@ -55,6 +56,7 @@ export function initLand({ api, esc, toast, agents, $, scoreBadge = () => '', se
|
|
|
55
56
|
<div class="land-chips">${scoreBadge(a.docs?.scorecard, esc)} ${prChips(pr, esc)}</div>
|
|
56
57
|
<div class="bl-actions">
|
|
57
58
|
<button class="small" data-land="review" title="Its diff, line comments for the agent, commit and push">Review</button>
|
|
59
|
+
${listenHtml(`prvoice:${a.id}`, { title: 'Explain the review aloud: the PR, its checks, the AI review, the riskiest changes and what is left', label: 'Explain' })}
|
|
58
60
|
${land === 'behind' || pr.mergeable === 'CONFLICTING' ? '<button class="small" data-land="update" title="Merge the base branch in here (when the agent is idle and its work is committed) and push; otherwise, or on conflicts, ask the agent">Update</button>' : ''}
|
|
59
61
|
${canFix ? '<button class="small" data-land="fix" title="Send the failures, requested changes or conflicts to the agent">Ask to fix</button>' : ''}
|
|
60
62
|
${land === 'ready' ? '<button class="small primary" data-land="merge">Merge</button>' : ''}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Explain the review, by voice: a short spoken briefing on an agent's pull request for the person
|
|
2
|
+
// about to review it. What the work is, the PR and its checks, what the AI review found, the
|
|
3
|
+
// riskiest changes, and what's left before it can merge. Built from what the page already has,
|
|
4
|
+
// so it starts at once; the change-by-change walkthrough in Review goes deeper.
|
|
5
|
+
|
|
6
|
+
import { speakable } from './speak.js';
|
|
7
|
+
|
|
8
|
+
const VERDICT = { complete: 'complete', partial: 'partly done', not_done: 'not done' };
|
|
9
|
+
const list = (xs, n = 3) => {
|
|
10
|
+
const items = xs.filter(Boolean).slice(0, n);
|
|
11
|
+
if (items.length <= 1) return items.join('');
|
|
12
|
+
if (items.length === 2) return items.join(' and ');
|
|
13
|
+
return `${items.slice(0, -1).join('; ')}; and ${items.at(-1)}`;
|
|
14
|
+
};
|
|
15
|
+
/** "a, b and c": for short items inside a sentence. */
|
|
16
|
+
const and = (xs) => (xs.length <= 1 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}`);
|
|
17
|
+
const said = (s) => speakable(String(s ?? '')).replace(/\s+/g, ' ').trim();
|
|
18
|
+
// One stop at the end, and none after a question mark.
|
|
19
|
+
const sentence = (s) => {
|
|
20
|
+
const t = said(s);
|
|
21
|
+
return !t ? '' : /[.?!]$/.test(t) ? t : `${t}.`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** The pull request a review is about: the agent's newest open one, else its newest. */
|
|
25
|
+
export function reviewedPr(a) {
|
|
26
|
+
const prs = (a.prs ?? []).filter((p) => p.source !== 'mentioned' && p.state);
|
|
27
|
+
return prs.filter((p) => p.state === 'OPEN').at(-1) ?? prs.at(-1) ?? null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The PR's state in words: "is open, checks pass, no review yet". */
|
|
31
|
+
function prState(p) {
|
|
32
|
+
if (p.state === 'MERGED') return 'is merged';
|
|
33
|
+
if (p.state === 'CLOSED') return 'was closed without merging';
|
|
34
|
+
const out = [p.isDraft ? 'is a draft' : 'is open'];
|
|
35
|
+
const checks = p.checks?.state;
|
|
36
|
+
if (checks === 'passed') out.push('checks pass');
|
|
37
|
+
else if (checks === 'failed') out.push(`checks fail${p.checks.failed?.length ? ` (${and(p.checks.failed.slice(0, 3).map((c) => c.name ?? c))})` : ''}`);
|
|
38
|
+
else if (checks === 'running') out.push('checks are still running');
|
|
39
|
+
if (p.mergeable === 'CONFLICTING' || p.mergeState === 'DIRTY') out.push('it has merge conflicts');
|
|
40
|
+
else if (p.mergeState === 'BEHIND') out.push("it's behind its base branch");
|
|
41
|
+
if (p.review === 'APPROVED') out.push("it's approved");
|
|
42
|
+
else if (p.review === 'CHANGES_REQUESTED') out.push('changes were requested');
|
|
43
|
+
else out.push('no review yet');
|
|
44
|
+
return out.length <= 1 ? out.join('') : `${out.slice(0, -1).join(', ')}, and ${out.at(-1)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** What's left before it can merge, as one sentence. */
|
|
48
|
+
function nextStep(a, p) {
|
|
49
|
+
if (!p) return a.results?.outcome === 'done' ? 'There is no pull request: the agent says it is done, so review its changes in the session.' : 'There is no pull request yet.';
|
|
50
|
+
if (p.state === 'MERGED') return 'Nothing left: it is merged.';
|
|
51
|
+
if (p.state === 'CLOSED') return 'Nothing left on this pull request.';
|
|
52
|
+
if (p.isDraft) return 'It is still a draft: the agent is working on it.';
|
|
53
|
+
if (p.checks?.state === 'failed') return 'Next: the failing checks need fixing; ask the agent to fix them from Land.';
|
|
54
|
+
if (p.mergeable === 'CONFLICTING' || p.mergeState === 'DIRTY') return 'Next: the merge conflicts need resolving; Update in Land, or ask the agent.';
|
|
55
|
+
if (p.review === 'CHANGES_REQUESTED') return a.runtime?.busy ? 'The agent is working on the requested changes.' : 'Changes were requested and the agent is idle: send them to it.';
|
|
56
|
+
if (p.review === 'APPROVED') return 'Next: merge it when you are ready.';
|
|
57
|
+
return 'Next: your review. Open Review to go through each change, then approve or ask for changes.';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The briefing as parts to speak. `designSummary` is the summary from the agent's design doc, when
|
|
62
|
+
* the page has it; `issueKey` names the issue.
|
|
63
|
+
*/
|
|
64
|
+
export function reviewSpeech(a, { designSummary = null, issueKey = null } = {}) {
|
|
65
|
+
if (!a) return [];
|
|
66
|
+
const p = reviewedPr(a);
|
|
67
|
+
const key = issueKey ?? a.synopsis?.key ?? null;
|
|
68
|
+
const what = a.synopsis?.text ?? String(a.intent ?? '').split('\n')[0].replace(/^<?https?:\/\/\S+>?\s*/, '');
|
|
69
|
+
const parts = [];
|
|
70
|
+
parts.push(sentence(`Review of ${key ? `${key}, ` : ''}${what || a.name}`));
|
|
71
|
+
if (p) parts.push(sentence(`Pull request ${p.number ?? ''}${p.title ? `, ${p.title},` : ''} ${prState(p)}`));
|
|
72
|
+
// What it does: the design doc's summary, else the walkthrough's, else the agent's own words.
|
|
73
|
+
const walk = a.docs?.walkthrough?.data;
|
|
74
|
+
// (Only what the agent wrote: the tracked PR is said above.)
|
|
75
|
+
const does = designSummary || walk?.summary || (a.results?.delivered ?? []).filter((d) => d.source === 'agent').slice(0, 2).map((d) => d.text).join('. ');
|
|
76
|
+
if (does) parts.push(sentence(`What it does: ${does}`));
|
|
77
|
+
const r = a.aiReview;
|
|
78
|
+
if (r?.verdict) {
|
|
79
|
+
parts.push(sentence(`The AI review says it is ${VERDICT[r.verdict] ?? r.verdict}. ${r.summary ?? ''}`));
|
|
80
|
+
if (r.met?.length) parts.push(sentence(`Met: ${list(r.met)}`));
|
|
81
|
+
if (r.missing?.length) parts.push(sentence(`Missing: ${list(r.missing)}`));
|
|
82
|
+
if (r.risks?.length) parts.push(sentence(`Risks: ${list(r.risks)}`));
|
|
83
|
+
} else {
|
|
84
|
+
parts.push('There is no AI review yet; Review with AI checks the work against the request.');
|
|
85
|
+
}
|
|
86
|
+
if (walk?.changes?.length) {
|
|
87
|
+
const high = walk.changes.filter((c) => c.risk === 'high');
|
|
88
|
+
const n = walk.changes.length;
|
|
89
|
+
parts.push(
|
|
90
|
+
sentence(
|
|
91
|
+
high.length
|
|
92
|
+
? `The walkthrough has ${n} change${n === 1 ? '' : 's'}; ${high.length} ${high.length === 1 ? 'is' : 'are'} high risk: ${list(high.map((c) => `${c.title}, in ${String(c.file).split('/').pop()}`))}`
|
|
93
|
+
: `The walkthrough has ${n} change${n === 1 ? '' : 's'}, none high risk`,
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const blockers = (a.results?.blockers ?? []).filter((b) => b.source === 'agent').map((b) => b.text);
|
|
98
|
+
if (blockers.length) parts.push(sentence(`The agent is blocked: ${list(blockers, 2)}`));
|
|
99
|
+
const open = (a.questions ?? []).filter((q) => !q.answer).map((q) => q.question);
|
|
100
|
+
if (open.length) parts.push(sentence(`It asks you: ${list(open, 2)}`));
|
|
101
|
+
parts.push(nextStep(a, p));
|
|
102
|
+
return parts.filter(Boolean);
|
|
103
|
+
}
|