ai-agentmanager 1.20.0 → 1.21.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 +5 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/public/app.js +39 -2
- package/public/codemap.js +209 -0
- package/public/index.html +12 -0
- package/public/keys.js +5 -3
- package/public/speak.js +4 -2
- package/public/standup.js +348 -0
- package/public/style.css +62 -0
- package/public/voice.js +16 -0
- package/src/codemap.js +115 -0
- package/src/config.js +2 -0
- package/src/manager.js +46 -0
- package/src/notify.js +1 -0
- package/src/server.js +28 -0
- package/src/standup.js +209 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// The standup player: the day's standup read aloud, one agent at a time, each in its own voice.
|
|
2
|
+
// When an agent needs you it stops on it with its questions beside it, answered by tap (the
|
|
3
|
+
// inbox's own cards) or, when turned on, by voice: what you say is read back and sent on "send".
|
|
4
|
+
|
|
5
|
+
import { canSpeak, cycleRate, pause, play, rateLabel, resume, stop, now as speaking } from '/speak.js';
|
|
6
|
+
import { choiceFor } from '/voice.js';
|
|
7
|
+
|
|
8
|
+
const VOICE_KEY = 'agentmgr.standupVoice';
|
|
9
|
+
const PLAY_ID = 'standup';
|
|
10
|
+
const Recognition = typeof window !== 'undefined' ? window.SpeechRecognition || window.webkitSpeechRecognition : null;
|
|
11
|
+
|
|
12
|
+
// macOS's joke and singing voices: not for a standup.
|
|
13
|
+
const NOVELTY = /^(Albert|Bad News|Bahh|Bells|Boing|Bubbles|Cellos|Deranged|Good News|Hysterical|Jester|Organ|Pipe Organ|Superstar|Trinoids|Whisper|Wobble|Zarvox)\b/i;
|
|
14
|
+
const hash = (s) => [...String(s)].reduce((h, c) => (h * 31 + c.charCodeAt(0)) >>> 0, 7);
|
|
15
|
+
export function initStandup({ api, $, esc, agents, needsFor, needCard, onNeed, toast, openAgent }) {
|
|
16
|
+
const dialog = $('#standup-dialog');
|
|
17
|
+
const body = $('#standup-body');
|
|
18
|
+
let latest = null;
|
|
19
|
+
let settings = null;
|
|
20
|
+
let idx = -1; // -1: the intro
|
|
21
|
+
let state = 'stopped'; // playing | paused | waiting | stopped | done
|
|
22
|
+
let heard = null; // { text, action: { label, run } } waiting for "send"
|
|
23
|
+
let listening = null;
|
|
24
|
+
let voiceOn = false;
|
|
25
|
+
try {
|
|
26
|
+
voiceOn = localStorage.getItem(VOICE_KEY) === '1';
|
|
27
|
+
} catch {}
|
|
28
|
+
|
|
29
|
+
// Each agent keeps one voice of the page's language; the intro uses the default.
|
|
30
|
+
let voices = [];
|
|
31
|
+
const loadVoices = () => {
|
|
32
|
+
if (!canSpeak()) return;
|
|
33
|
+
const lang = (navigator.language || 'en').slice(0, 2);
|
|
34
|
+
voices = speechSynthesis.getVoices().filter((v) => v.lang?.startsWith(lang) && !NOVELTY.test(v.name));
|
|
35
|
+
};
|
|
36
|
+
if (canSpeak()) {
|
|
37
|
+
loadVoices();
|
|
38
|
+
speechSynthesis.addEventListener?.('voiceschanged', loadVoices);
|
|
39
|
+
}
|
|
40
|
+
const voiceFor = (id) => (voices.length > 1 ? voices[hash(id) % voices.length] : null);
|
|
41
|
+
|
|
42
|
+
const items = () => latest?.items ?? [];
|
|
43
|
+
const current = () => items()[idx] ?? null;
|
|
44
|
+
const needsNow = (it) => {
|
|
45
|
+
const a = it && agents.get(it.agentId);
|
|
46
|
+
return a ? needsFor(a) : [];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function set(next) {
|
|
50
|
+
latest = next;
|
|
51
|
+
$('#standup-dot').hidden = !latest?.items?.length || seenAt() === latest.at;
|
|
52
|
+
if (dialog.open) render();
|
|
53
|
+
}
|
|
54
|
+
const seenAt = () => {
|
|
55
|
+
try {
|
|
56
|
+
return localStorage.getItem('agentmgr.standupSeen');
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const markSeen = () => {
|
|
62
|
+
try {
|
|
63
|
+
localStorage.setItem('agentmgr.standupSeen', latest?.at ?? '');
|
|
64
|
+
} catch {}
|
|
65
|
+
$('#standup-dot').hidden = true;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
async function load() {
|
|
69
|
+
const v = await api('GET', '/standup');
|
|
70
|
+
settings = v.settings;
|
|
71
|
+
set(v.latest);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function open({ fresh = false } = {}) {
|
|
75
|
+
if (!dialog.open) dialog.showModal();
|
|
76
|
+
try {
|
|
77
|
+
if (!latest || fresh) {
|
|
78
|
+
body.innerHTML = '<p class="hint standup-making">Putting the standup together…</p>';
|
|
79
|
+
const v = await api(fresh || !latest ? 'POST' : 'GET', '/standup');
|
|
80
|
+
settings = v.settings;
|
|
81
|
+
set(v.latest);
|
|
82
|
+
} else if (!settings) await load();
|
|
83
|
+
} catch (e) {
|
|
84
|
+
body.innerHTML = `<p class="hint error">${esc(e.message)}</p>`;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
markSeen();
|
|
88
|
+
playFrom(-1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function close() {
|
|
92
|
+
stop(false);
|
|
93
|
+
stopListening();
|
|
94
|
+
state = 'stopped';
|
|
95
|
+
if (dialog.open) dialog.close();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Read item `i` (-1: the intro), then go on, or stop on an agent that needs you. */
|
|
99
|
+
function playFrom(i) {
|
|
100
|
+
idx = Math.max(-1, Math.min(i, items().length));
|
|
101
|
+
heard = null;
|
|
102
|
+
stopListening();
|
|
103
|
+
if (idx >= items().length) {
|
|
104
|
+
state = 'done';
|
|
105
|
+
render();
|
|
106
|
+
return play(PLAY_ID, ["That's everything."], {});
|
|
107
|
+
}
|
|
108
|
+
const it = current();
|
|
109
|
+
const text = it ? `${it.name}. ${it.text}` : latest?.intro ?? '';
|
|
110
|
+
state = 'playing';
|
|
111
|
+
render();
|
|
112
|
+
const started = play(PLAY_ID, [{ text, voice: it ? voiceFor(it.agentId) : null }], {
|
|
113
|
+
onEnd: () => {
|
|
114
|
+
if (!dialog.open) return;
|
|
115
|
+
if (it && needsNow(it).length) {
|
|
116
|
+
state = 'waiting';
|
|
117
|
+
render();
|
|
118
|
+
if (voiceOn) listen();
|
|
119
|
+
} else setTimeout(() => dialog.open && state === 'playing' && idx === i && playFrom(i + 1), 500);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
// No speech here: show it, and let the arrows move on.
|
|
123
|
+
if (!started) {
|
|
124
|
+
state = it && needsNow(it).length ? 'waiting' : 'paused';
|
|
125
|
+
render();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function toggle() {
|
|
130
|
+
const s = speaking();
|
|
131
|
+
if (s?.id === PLAY_ID && !s.paused) {
|
|
132
|
+
pause();
|
|
133
|
+
state = 'paused';
|
|
134
|
+
} else if (s?.id === PLAY_ID && s.paused) {
|
|
135
|
+
resume();
|
|
136
|
+
state = 'playing';
|
|
137
|
+
} else return playFrom(state === 'done' ? -1 : idx);
|
|
138
|
+
render();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ------------------------------------------------------------ answering by voice
|
|
142
|
+
|
|
143
|
+
/** What saying `text` does for this agent's first need: { label, run } or null. */
|
|
144
|
+
function actionFor(it, text) {
|
|
145
|
+
const a = agents.get(it.agentId);
|
|
146
|
+
const need = needsNow(it)[0];
|
|
147
|
+
if (!a || !need) return null;
|
|
148
|
+
const t = text.trim();
|
|
149
|
+
if (need.kind === 'prompt') {
|
|
150
|
+
const choices = a.runtime.prompt?.choices ?? [];
|
|
151
|
+
const key = choiceFor(t, choices);
|
|
152
|
+
const c = choices.find((x) => x.key === key);
|
|
153
|
+
return c ? { label: `choose “${c.label}”`, run: () => api('POST', `/agents/${a.id}/prompt-key`, { key }) } : null;
|
|
154
|
+
}
|
|
155
|
+
if (need.kind === 'question') return { label: `answer “${t}”`, run: () => api('POST', `/agents/${a.id}/answer`, { question: need.q.id, text: t }) };
|
|
156
|
+
if (need.kind === 'waiting') return { label: `reply “${t}”`, run: () => api('POST', `/agents/${a.id}/waiting/answer`, { text: t }) };
|
|
157
|
+
if (need.kind === 'plan' && /\b(approve|looks good|go ahead|ship it)\b/i.test(t)) return { label: 'approve its plan', run: () => api('POST', `/agents/${a.id}/plan/approve`, {}) };
|
|
158
|
+
return { label: `tell it “${t}”`, run: () => api('POST', `/agents/${a.id}/tell`, { text: t }) };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function stopListening() {
|
|
162
|
+
try {
|
|
163
|
+
listening?.abort();
|
|
164
|
+
} catch {}
|
|
165
|
+
listening = null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Listen once: an answer, or, with one read back, "send" or "cancel". */
|
|
169
|
+
function listen() {
|
|
170
|
+
if (!Recognition || listening) return;
|
|
171
|
+
stop(false);
|
|
172
|
+
const it = current();
|
|
173
|
+
const r = new Recognition();
|
|
174
|
+
r.lang = navigator.language || 'en-US';
|
|
175
|
+
r.interimResults = true;
|
|
176
|
+
r.maxAlternatives = 1;
|
|
177
|
+
let text = '';
|
|
178
|
+
r.onresult = (e) => {
|
|
179
|
+
text = [...e.results].map((x) => x[0].transcript).join(' ');
|
|
180
|
+
const live = $('#standup-heard-live');
|
|
181
|
+
if (live) live.textContent = text;
|
|
182
|
+
};
|
|
183
|
+
r.onerror = (e) => {
|
|
184
|
+
if (e.error === 'not-allowed' || e.error === 'service-not-allowed') toast('Microphone blocked: allow it for this page, or answer with the buttons', 6000);
|
|
185
|
+
};
|
|
186
|
+
r.onend = () => {
|
|
187
|
+
listening = null;
|
|
188
|
+
if (!dialog.open || current() !== it) return render();
|
|
189
|
+
text = text.trim();
|
|
190
|
+
if (heard && text) {
|
|
191
|
+
if (/\b(send|yes|confirm|do it|go)\b/i.test(text)) return send();
|
|
192
|
+
if (/\b(cancel|no|stop|wait)\b/i.test(text)) {
|
|
193
|
+
heard = null;
|
|
194
|
+
return render();
|
|
195
|
+
}
|
|
196
|
+
} else if (text) {
|
|
197
|
+
const action = actionFor(it, text);
|
|
198
|
+
if (!action) {
|
|
199
|
+
play(PLAY_ID, ["Sorry, I didn't catch a choice. Say yes, no, or the option's number."], {});
|
|
200
|
+
return render();
|
|
201
|
+
}
|
|
202
|
+
heard = { text, action };
|
|
203
|
+
render();
|
|
204
|
+
// Read it back, then listen for "send".
|
|
205
|
+
return play(PLAY_ID, [`I'll ${action.label} for ${it.name}. Say send, or cancel.`], { onEnd: () => dialog.open && heard && listen() });
|
|
206
|
+
}
|
|
207
|
+
render();
|
|
208
|
+
};
|
|
209
|
+
listening = r;
|
|
210
|
+
try {
|
|
211
|
+
r.start();
|
|
212
|
+
} catch {
|
|
213
|
+
listening = null;
|
|
214
|
+
}
|
|
215
|
+
render();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function send() {
|
|
219
|
+
const it = current();
|
|
220
|
+
const h = heard;
|
|
221
|
+
heard = null;
|
|
222
|
+
if (!h || !it) return render();
|
|
223
|
+
try {
|
|
224
|
+
await h.action.run();
|
|
225
|
+
toast(`Sent to ${it.name}`);
|
|
226
|
+
play(PLAY_ID, ['Sent.'], { onEnd: () => dialog.open && playFrom(idx + 1) });
|
|
227
|
+
} catch (e) {
|
|
228
|
+
toast(e.message, 6000);
|
|
229
|
+
}
|
|
230
|
+
render();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ------------------------------------------------------------ drawing
|
|
234
|
+
|
|
235
|
+
function render() {
|
|
236
|
+
if (!dialog.open) return;
|
|
237
|
+
if (!latest) return;
|
|
238
|
+
const list = items();
|
|
239
|
+
const it = current();
|
|
240
|
+
const when = new Date(latest.at).toLocaleString([], { weekday: 'short', hour: '2-digit', minute: '2-digit' });
|
|
241
|
+
const chips = [`<button class="standup-chip ${idx === -1 ? 'on' : ''}" data-su="go" data-i="-1">Intro</button>`, ...list.map((x, i) => `<button class="standup-chip ${i === idx ? 'on' : ''} ${needsNow(x).length ? 'needs' : ''}" data-su="go" data-i="${i}" title="${esc(x.text)}">${esc(x.name)}</button>`)].join('');
|
|
242
|
+
const needs = it ? needsNow(it) : [];
|
|
243
|
+
const card = it
|
|
244
|
+
? `<div class="standup-card">
|
|
245
|
+
<h3><button class="link" data-su="open" title="Open this agent">${esc(it.name)}</button>${it.project ? ` <span class="hint">${esc(it.project)}</span>` : ''}</h3>
|
|
246
|
+
<p class="standup-text">${esc(it.text)}</p>
|
|
247
|
+
${needs.length ? `<div class="standup-needs">${needs.map((n) => needCard(n, { inDetail: true })).join('')}</div>` : '<p class="hint">Nothing needed from you.</p>'}
|
|
248
|
+
${needs.length && Recognition && voiceOn
|
|
249
|
+
? `<div class="standup-voice">
|
|
250
|
+
<button class="${listening ? 'primary listening' : ''}" data-su="mic" title="Say your answer: yes, no, an option's number, or a reply">${listening ? '● Listening…' : '🎤 Answer by voice'}</button>
|
|
251
|
+
<span id="standup-heard-live" class="hint"></span>
|
|
252
|
+
${heard ? `<div class="standup-heard">I'll ${esc(heard.action.label)} for <b>${esc(it.name)}</b>. <button class="small primary" data-su="send">Send</button> <button class="small" data-su="cancel">Cancel</button></div>` : ''}
|
|
253
|
+
</div>`
|
|
254
|
+
: ''}
|
|
255
|
+
</div>`
|
|
256
|
+
: idx >= list.length
|
|
257
|
+
? `<div class="standup-card"><p class="standup-text">That's everything.</p><p class="hint">${list.filter((x) => needsNow(x).length).length ? 'Some agents still need you: pick one above.' : 'Nothing is waiting on you.'}</p></div>`
|
|
258
|
+
: `<div class="standup-card"><p class="standup-text">${esc(latest.intro)}</p><p class="hint">Since ${esc(new Date(latest.since).toLocaleString([], { weekday: 'short', hour: '2-digit', minute: '2-digit' }))}${latest.ai ? '' : ' · plain wording'}</p></div>`;
|
|
259
|
+
const playingNow = speaking()?.id === PLAY_ID && !speaking()?.paused;
|
|
260
|
+
body.innerHTML = `
|
|
261
|
+
<div class="standup-top"><b>Standup</b> <span class="hint">${esc(when)} · ${list.length} agent${list.length === 1 ? '' : 's'}</span><span class="spacer"></span>
|
|
262
|
+
<button class="small" data-su="fresh" title="A new standup with what's happened since this one">↻ New</button>
|
|
263
|
+
<button class="small" data-su="close">Close</button></div>
|
|
264
|
+
<div class="standup-chips">${chips}</div>
|
|
265
|
+
${card}
|
|
266
|
+
<div class="standup-controls">
|
|
267
|
+
<button data-su="prev" title="Previous" ${idx <= -1 ? 'disabled' : ''}>⏮</button>
|
|
268
|
+
<button class="primary" data-su="play" title="${playingNow ? 'Pause' : 'Play'}" ${canSpeak() ? '' : 'disabled'}>${playingNow ? '⏸' : '▶'}</button>
|
|
269
|
+
<button data-su="next" title="Next" ${idx >= list.length ? 'disabled' : ''}>⏭</button>
|
|
270
|
+
<button class="small" data-su="rate" title="Speed">${esc(rateLabel())}</button>
|
|
271
|
+
<span class="spacer"></span>
|
|
272
|
+
${Recognition ? `<label class="check" title="Answer agents by speaking. Your browser may send the audio to its maker to turn it into text."><input type="checkbox" data-su="voice" ${voiceOn ? 'checked' : ''}> Answer by voice</label>` : ''}
|
|
273
|
+
</div>
|
|
274
|
+
${settings ? `<details class="standup-settings"><summary>Daily at ${esc(settings.at)}${settings.enabled ? '' : ' (off)'}</summary>
|
|
275
|
+
<label class="check"><input type="checkbox" data-su-set="enabled" ${settings.enabled ? 'checked' : ''}> A standup every ${settings.weekends ? 'day' : 'weekday'} at <input type="time" data-su-set="at" value="${esc(settings.at)}"></label>
|
|
276
|
+
<label class="check"><input type="checkbox" data-su-set="weekends" ${settings.weekends ? 'checked' : ''}> Weekends too</label>
|
|
277
|
+
<label class="check"><input type="checkbox" data-su-set="ai" ${settings.ai ? 'checked' : ''}> Worded by AI (one short call; off: plain wording)</label>
|
|
278
|
+
<label class="check"><input type="checkbox" data-su-set="notify" ${settings.notify ? 'checked' : ''}> Alert me when it's ready (Slack, with Alerts on)</label>
|
|
279
|
+
</details>` : ''}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
body.addEventListener('click', (e) => {
|
|
283
|
+
if (e.target.closest('[data-need]')) return onNeed(e);
|
|
284
|
+
const el = e.target.closest('[data-su]');
|
|
285
|
+
if (!el) return;
|
|
286
|
+
const what = el.dataset.su;
|
|
287
|
+
if (what === 'voice') return;
|
|
288
|
+
e.preventDefault();
|
|
289
|
+
if (what === 'close') return close();
|
|
290
|
+
if (what === 'fresh') return open({ fresh: true });
|
|
291
|
+
if (what === 'play') return toggle();
|
|
292
|
+
if (what === 'prev') return playFrom(idx - 1);
|
|
293
|
+
if (what === 'next') return playFrom(idx + 1);
|
|
294
|
+
if (what === 'go') return playFrom(Number(el.dataset.i));
|
|
295
|
+
if (what === 'rate') {
|
|
296
|
+
cycleRate();
|
|
297
|
+
return render();
|
|
298
|
+
}
|
|
299
|
+
if (what === 'open') {
|
|
300
|
+
const id = current()?.agentId;
|
|
301
|
+
close();
|
|
302
|
+
return id && openAgent(id);
|
|
303
|
+
}
|
|
304
|
+
if (what === 'mic') return listening ? stopListening() || render() : listen();
|
|
305
|
+
if (what === 'send') return send();
|
|
306
|
+
if (what === 'cancel') {
|
|
307
|
+
heard = null;
|
|
308
|
+
return render();
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
body.addEventListener('change', async (e) => {
|
|
312
|
+
if (e.target.dataset.su === 'voice') {
|
|
313
|
+
voiceOn = e.target.checked;
|
|
314
|
+
try {
|
|
315
|
+
localStorage.setItem(VOICE_KEY, voiceOn ? '1' : '0');
|
|
316
|
+
} catch {}
|
|
317
|
+
if (voiceOn) toast('Voice answers on. Your browser may send what you say to its maker to turn it into text', 6000);
|
|
318
|
+
return render();
|
|
319
|
+
}
|
|
320
|
+
const key = e.target.dataset.suSet;
|
|
321
|
+
if (!key) return;
|
|
322
|
+
try {
|
|
323
|
+
settings = (await api('PUT', '/standup', { [key]: e.target.type === 'checkbox' ? e.target.checked : e.target.value })).settings;
|
|
324
|
+
} catch (err) {
|
|
325
|
+
toast(err.message, 5000);
|
|
326
|
+
}
|
|
327
|
+
render();
|
|
328
|
+
});
|
|
329
|
+
dialog.addEventListener('close', () => {
|
|
330
|
+
stop(false);
|
|
331
|
+
stopListening();
|
|
332
|
+
state = 'stopped';
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Answering on another device (or here) clears the need: an agent you were stopped on moves on.
|
|
336
|
+
function agentChanged() {
|
|
337
|
+
if (!dialog.open) return;
|
|
338
|
+
const it = current();
|
|
339
|
+
if (state === 'waiting' && it && !needsNow(it).length && !heard) return playFrom(idx + 1);
|
|
340
|
+
// Typing a reply in one of its cards: don't redraw under it.
|
|
341
|
+
if (body.contains(document.activeElement) && document.activeElement.matches('input, textarea')) return;
|
|
342
|
+
render();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
$('#standup-btn').onclick = () => open();
|
|
346
|
+
load().catch(() => {});
|
|
347
|
+
return { open, set, render: agentChanged, isOpen: () => dialog.open };
|
|
348
|
+
}
|
package/public/style.css
CHANGED
|
@@ -1062,3 +1062,65 @@ kbd { display: inline-block; min-width: 1.6em; padding: 1px 5px; border: 1px sol
|
|
|
1062
1062
|
.keys-dialog td { padding: 3px 0; vertical-align: top; }
|
|
1063
1063
|
.keys-dialog td.keys { width: 42%; white-space: nowrap; padding-right: 12px; }
|
|
1064
1064
|
#keys-btn kbd { margin-left: 6px; }
|
|
1065
|
+
|
|
1066
|
+
/* ---------- standup player */
|
|
1067
|
+
.standup-dialog { width: min(720px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 16px; }
|
|
1068
|
+
.standup-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
|
|
1069
|
+
.standup-top .spacer, .standup-controls .spacer { flex: 1; }
|
|
1070
|
+
.standup-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
|
|
1071
|
+
.standup-chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1072
|
+
.standup-chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
|
|
1073
|
+
.standup-chip.needs::after { content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--red); vertical-align: middle; }
|
|
1074
|
+
.standup-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: var(--panel); min-height: 120px; }
|
|
1075
|
+
.standup-card h3 { margin: 0 0 6px; font-size: 16px; }
|
|
1076
|
+
.standup-text { font-size: 17px; line-height: 1.5; margin: 0 0 10px; }
|
|
1077
|
+
.standup-needs { display: flex; flex-direction: column; gap: 8px; }
|
|
1078
|
+
.standup-voice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
|
|
1079
|
+
.standup-voice .listening { animation: pulse 1s infinite; }
|
|
1080
|
+
.standup-heard { flex-basis: 100%; padding: 8px 10px; border-radius: 8px; background: var(--bg); }
|
|
1081
|
+
.standup-controls { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
|
|
1082
|
+
.standup-controls button { min-width: 44px; }
|
|
1083
|
+
.standup-settings { margin-top: 12px; font-size: 13px; }
|
|
1084
|
+
.standup-settings label { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
|
|
1085
|
+
.standup-settings input[type="time"] { width: auto; }
|
|
1086
|
+
@media (max-width: 640px) {
|
|
1087
|
+
.standup-dialog { width: calc(100% - 32px); padding: 12px; }
|
|
1088
|
+
.standup-text { font-size: 16px; }
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/* ---------- Map: where agents are in the code */
|
|
1092
|
+
body.mapping .layout, body.mapping .watch-view { display: none; }
|
|
1093
|
+
.map-view { flex: 1; min-height: 0; overflow: auto; padding: 10px 16px 16px; background: var(--bg); display: flex; flex-direction: column; }
|
|
1094
|
+
.map-legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--muted); }
|
|
1095
|
+
.map-key { display: inline-block; width: 14px; height: 10px; margin-left: 6px; border-radius: 3px; }
|
|
1096
|
+
.map-key.solid { background: var(--accent); }
|
|
1097
|
+
.map-key.ring { border: 2px solid var(--accent); }
|
|
1098
|
+
.map-key.red { height: 0; border-top: 3px solid var(--red); }
|
|
1099
|
+
.map-key.dash { height: 0; border-top: 3px dashed var(--yellow); }
|
|
1100
|
+
.map-warn ul { margin: 0 0 8px; padding: 0; list-style: none; font-size: 13px; }
|
|
1101
|
+
.map-warn li { padding: 5px 10px; margin-bottom: 4px; border-radius: 6px; border-left: 3px solid; background: var(--panel); }
|
|
1102
|
+
.map-warn li.collide { border-color: var(--red); }
|
|
1103
|
+
.map-warn li.heading { border-color: var(--yellow); }
|
|
1104
|
+
.map-warn .hint { margin: 0 0 8px; }
|
|
1105
|
+
.map-box { position: relative; flex: 1; min-height: 320px; border-radius: 8px; overflow: hidden; background: var(--panel); }
|
|
1106
|
+
.map-empty { margin: 40px auto; text-align: center; }
|
|
1107
|
+
.map-tile { position: absolute; box-sizing: border-box; border: 1px solid var(--bg); background: color-mix(in srgb, var(--border) 45%, var(--panel)); padding: 3px 5px; overflow: hidden; font-size: 11px; }
|
|
1108
|
+
.map-tile.active { background: color-mix(in srgb, var(--accent) 16%, var(--panel)); }
|
|
1109
|
+
.map-tile.more { background: var(--bg); }
|
|
1110
|
+
.map-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
1111
|
+
.map-count { color: var(--muted); }
|
|
1112
|
+
.map-badges { position: relative; z-index: 2; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
|
|
1113
|
+
.map-badge { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; font-size: 9.5px; font-weight: 700; box-sizing: border-box; }
|
|
1114
|
+
.map-badge.solid { background: var(--c); color: #fff; }
|
|
1115
|
+
.map-badge.ring { border: 2px solid var(--c); color: var(--c); background: var(--panel); }
|
|
1116
|
+
.map-badge.busy { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); animation: pulse 1.4s infinite; }
|
|
1117
|
+
.map-badge.needs { outline: 2px solid var(--red); outline-offset: 1px; }
|
|
1118
|
+
.map-links { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
|
|
1119
|
+
.map-badge.collide { outline: 2px solid var(--red); outline-offset: 2px; }
|
|
1120
|
+
.map-badge.heading { outline: 2px dashed var(--yellow); outline-offset: 2px; }
|
|
1121
|
+
.map-links line { stroke-width: 3; stroke-linecap: round; }
|
|
1122
|
+
.map-links line.collide { stroke: var(--red); }
|
|
1123
|
+
.map-links line.heading { stroke: var(--yellow); stroke-dasharray: 6 5; }
|
|
1124
|
+
.map-agents { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; }
|
|
1125
|
+
.map-agent { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; padding: 2px 0; cursor: pointer; font-size: 13px; color: inherit; }
|
|
1126
|
+
#map-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
|
package/public/voice.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// What a spoken answer means: shared by the standup player (and testable without a browser).
|
|
2
|
+
|
|
3
|
+
const WORDS = { one: '1', first: '1', two: '2', second: '2', three: '3', third: '3', four: '4', fourth: '4' };
|
|
4
|
+
|
|
5
|
+
/** What a spoken answer means for a prompt's menu: the choice's key, or null. */
|
|
6
|
+
export function choiceFor(text, choices = []) {
|
|
7
|
+
const t = String(text).toLowerCase().trim();
|
|
8
|
+
const n = t.match(/\b(?:option|number|choice)?\s*(\d|one|two|three|four|first|second|third|fourth)\b/)?.[1];
|
|
9
|
+
const key = n ? WORDS[n] ?? n : null;
|
|
10
|
+
if (key && choices.some((c) => c.key === key)) return key;
|
|
11
|
+
const yes = /\b(yes|yeah|yep|allow|approve|go ahead|sure|ok(ay)?)\b/.test(t);
|
|
12
|
+
const no = /\b(no|nope|deny|don't|do not|stop)\b/.test(t);
|
|
13
|
+
if (yes && !no) return choices.find((c) => /^yes\b/i.test(c.label))?.key ?? null;
|
|
14
|
+
if (no && !yes) return choices.find((c) => /^no\b/i.test(c.label))?.key ?? null;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
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/manager.js
CHANGED
|
@@ -105,6 +105,7 @@ 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
110
|
import { issueSummary, leadingIssue, wordsAfterLink } from './jira.js';
|
|
110
111
|
import { reminderFor, reminderSettings } from './reminders.js';
|
|
@@ -783,6 +784,51 @@ export class AgentManager extends EventEmitter {
|
|
|
783
784
|
return html;
|
|
784
785
|
}
|
|
785
786
|
|
|
787
|
+
/**
|
|
788
|
+
* The codebase map of one project (its key, else the one with the most running agents): its
|
|
789
|
+
* folders, and where each of its agents is changing and reading code now (codemap.js).
|
|
790
|
+
*/
|
|
791
|
+
async codeMap(projectKey) {
|
|
792
|
+
const withCode = this.store.list().filter((a) => a.workdir && !NO_REPO.has(a.kind) && fs.existsSync(a.workdir));
|
|
793
|
+
const groups = new Map();
|
|
794
|
+
for (const a of withCode) {
|
|
795
|
+
const p = this.projectInfo(a);
|
|
796
|
+
if (!p) continue;
|
|
797
|
+
const g = groups.get(p.key) ?? groups.set(p.key, { key: p.key, name: p.name, agents: [] }).get(p.key);
|
|
798
|
+
g.agents.push(a);
|
|
799
|
+
}
|
|
800
|
+
const running = (g) => g.agents.filter((a) => this.runtimes.get(a.id)?.pty).length;
|
|
801
|
+
const projects = [...groups.values()].sort((x, y) => running(y) - running(x) || y.agents.length - x.agents.length);
|
|
802
|
+
const g = (projectKey && groups.get(projectKey)) || projects[0];
|
|
803
|
+
const list = projects.map((p) => ({ key: p.key, name: p.name, agents: p.agents.length, running: running(p) }));
|
|
804
|
+
if (!g) return { project: null, projects: list, map: buildMap({}) };
|
|
805
|
+
// Running agents, and closed ones with changes not yet merged.
|
|
806
|
+
const shown = g.agents.filter((a) => this.runtimes.get(a.id)?.pty || Object.keys(this.changeSets.get(a.id)?.files ?? {}).length);
|
|
807
|
+
const root = shown.find((a) => a.sourceDir && fs.existsSync(a.sourceDir))?.sourceDir ?? (shown[0] ?? g.agents[0]).workdir;
|
|
808
|
+
const files = await this.repoFiles(root);
|
|
809
|
+
const agents = shown.map((a) => {
|
|
810
|
+
const rt = this.runtimes.get(a.id);
|
|
811
|
+
let touched = {};
|
|
812
|
+
try {
|
|
813
|
+
touched = rt?.pty ? touchedFiles(engineOf(a).sessionFile(a.workdir, a.sessionId), a.workdir) : {};
|
|
814
|
+
} catch {}
|
|
815
|
+
return { id: a.id, name: a.name, busy: rt?.busy, attention: rt?.attention, changed: this.changeSets.get(a.id)?.files ?? {}, touched };
|
|
816
|
+
});
|
|
817
|
+
return { project: { key: g.key, name: g.name }, projects: list, map: buildMap({ files, agents }) };
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/** A repository's tracked files, for the map (kept a few minutes). */
|
|
821
|
+
async repoFiles(dir) {
|
|
822
|
+
this.fileLists ??= new Map();
|
|
823
|
+
const hit = this.fileLists.get(dir);
|
|
824
|
+
if (hit && Date.now() - hit.at < 5 * 60_000) return hit.files;
|
|
825
|
+
// From the commit, not the index: the shared clone agents branch from may have no working copy.
|
|
826
|
+
const out = await git.run('git', ['ls-tree', '-r', '--name-only', 'HEAD'], { cwd: dir, timeout: 30_000 }).catch(() => '');
|
|
827
|
+
const files = out.split('\n').filter(Boolean);
|
|
828
|
+
this.fileLists.set(dir, { at: Date.now(), files });
|
|
829
|
+
return files;
|
|
830
|
+
}
|
|
831
|
+
|
|
786
832
|
/** Fill in summaries still missing (after Jira settings change); returns how many it found. */
|
|
787
833
|
async refreshSynopses() {
|
|
788
834
|
let found = 0;
|
package/src/notify.js
CHANGED
|
@@ -18,6 +18,7 @@ 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
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
// Alerts the AI judge may hold for the digest or drop; the rest are always sent at once.
|