ai-agentmanager 1.19.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/public/keys.js ADDED
@@ -0,0 +1,93 @@
1
+ // Keyboard shortcuts: one key for the common actions, never while you type (a field or a
2
+ // terminal has the keys then), plus Ctrl+Shift ones that work from inside a terminal. ? lists them.
3
+
4
+ export const SHORTCUTS = [
5
+ ['Agents', [
6
+ [['j'], 'Next agent', 'next'],
7
+ [['k'], 'Previous agent', 'prev'],
8
+ [['Enter', 't'], 'Open its terminal', 'terminal'],
9
+ [['r'], 'Review its changes', 'changes'],
10
+ [['s'], 'Resume it in the background', 'start'],
11
+ [['Shift+X'], 'Close its session (it can be resumed)', 'stop'],
12
+ [['e'], 'Edit it', 'edit'],
13
+ ]],
14
+ ['Anywhere', [
15
+ [['n'], 'New agents', 'new'],
16
+ [['a'], 'Ask Agent (a general session)', 'ask'],
17
+ [['/'], 'Filter agents', 'filter'],
18
+ [['w'], 'Watch: agents side by side', 'watch'],
19
+ [['p'], 'Play the standup', 'standup'],
20
+ [['m'], 'Map: where agents are in the code', 'map'],
21
+ [['1'], 'Agents tab', 'tab:agents'],
22
+ [['2'], 'Inbox: what needs you', 'tab:inbox'],
23
+ [['3'], 'Backlog', 'tab:backlog'],
24
+ [['4'], 'Land: pull requests', 'tab:land'],
25
+ [['5'], 'Built agents', 'tab:built'],
26
+ [['?'], 'These shortcuts', 'help'],
27
+ ]],
28
+ ['In a terminal', [
29
+ [['Ctrl+Shift+↓'], "Next agent's terminal", 'next-term'],
30
+ [['Ctrl+Shift+↑'], "Previous agent's terminal", 'prev-term'],
31
+ [['Ctrl+Shift+L'], 'Leave the terminal (then the keys above work)', 'leave'],
32
+ [['Ctrl+Shift+E'], 'Expand or shrink the terminal', null],
33
+ ]],
34
+ ];
35
+
36
+ // A single key, as an event names it, to its action.
37
+ export const SINGLE = {
38
+ 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',
40
+ 1: 'tab:agents', 2: 'tab:inbox', 3: 'tab:backlog', 4: 'tab:land', 5: 'tab:built',
41
+ };
42
+ // While Watch is open: only what makes sense there.
43
+ const ON_WATCH = new Set(['new', 'ask', 'watch', 'standup', 'map', 'help']);
44
+
45
+ /** Typing somewhere: a field, an editor or a terminal (xterm types through a textarea). */
46
+ const typing = (el) => Boolean(el?.closest?.('input, textarea, select, [contenteditable=""], [contenteditable="true"], .xterm, .cm-editor'));
47
+
48
+ export function initKeys({ $, esc, run }) {
49
+ const dialog = document.createElement('dialog');
50
+ dialog.id = 'keys-dialog';
51
+ dialog.className = 'keys-dialog';
52
+ const kbd = (k) => k.split('+').map((p) => `<kbd>${esc(p)}</kbd>`).join('+');
53
+ dialog.innerHTML = `<form method="dialog">
54
+ <h3>Keyboard shortcuts</h3>
55
+ ${SHORTCUTS.map(([group, rows]) => `<h4>${esc(group)}</h4><table>${rows.map(([keys, what]) => `<tr><td class="keys">${keys.map(kbd).join(' <span class="hint">or</span> ')}</td><td>${esc(what)}</td></tr>`).join('')}</table>`).join('')}
56
+ <p class="hint">Single keys work when you're not typing in a field or a terminal.</p>
57
+ <div class="actions"><button class="primary" value="close">Close</button></div>
58
+ </form>`;
59
+ document.body.appendChild(dialog);
60
+ const help = () => (dialog.open ? dialog.close() : dialog.showModal());
61
+
62
+ // Ctrl+Shift ones, first, so a focused terminal doesn't take them.
63
+ document.addEventListener('keydown', (e) => {
64
+ if (!e.ctrlKey || !e.shiftKey || e.altKey || e.metaKey) return;
65
+ const act = e.code === 'ArrowDown' ? 'next-term' : e.code === 'ArrowUp' ? 'prev-term' : e.code === 'KeyL' ? 'leave' : null;
66
+ if (!act) return;
67
+ e.preventDefault();
68
+ e.stopPropagation();
69
+ run(act);
70
+ }, true);
71
+
72
+ document.addEventListener('keydown', (e) => {
73
+ if (e.defaultPrevented || e.isComposing || e.metaKey || e.ctrlKey || e.altKey) return;
74
+ if (e.key === 'Escape' && document.activeElement === $('#filter')) {
75
+ $('#filter').blur();
76
+ return;
77
+ }
78
+ if (typing(e.target) || typing(document.activeElement)) return;
79
+ // An open dialog has the keyboard; ? still closes the shortcuts one.
80
+ if (document.querySelector('dialog[open]') && !(dialog.open && e.key === '?')) return;
81
+ const act = SINGLE[e.key];
82
+ if (!act || (document.body.classList.contains('watching') || document.body.classList.contains('mapping')) && !ON_WATCH.has(act)) return;
83
+ if (act === 'help') {
84
+ e.preventDefault();
85
+ return help();
86
+ }
87
+ // Enter on a focused button or link is that button's.
88
+ if (e.key === 'Enter' && e.target.closest?.('button, a, summary')) return;
89
+ if (run(act) !== false) e.preventDefault();
90
+ });
91
+
92
+ return { help };
93
+ }
package/public/land.js CHANGED
@@ -40,12 +40,18 @@ export function initLand({ api, esc, toast, agents, $, scoreBadge = () => '', se
40
40
  return out.sort((x, y) => (x.a.priority ?? 2) - (y.a.priority ?? 2));
41
41
  };
42
42
 
43
+ // Review comments sent to the agent so far, and when last.
44
+ function commentsHint(c) {
45
+ if (!c?.count) return '';
46
+ return ` <span class="hint" title="Last sent ${esc(new Date(c.lastAt).toLocaleString())}">${c.count} review comment${c.count === 1 ? '' : 's'} sent</span>`;
47
+ }
48
+
43
49
  function rowHtml({ a, pr, land }) {
44
50
  const canFix = land === 'fix' || land === 'behind';
45
51
  return `<li class="agent land-row" data-agent="${a.id}" data-url="${esc(pr.url)}">
46
52
  <div class="line1"><span class="prio p${a.priority ?? 2}">P${a.priority ?? 2}</span>
47
53
  <a class="name" href="${esc(pr.url)}" target="_blank" rel="noopener" title="${esc(pr.title ?? pr.url)}">#${esc(pr.number ?? '')} ${esc(pr.title ?? pr.url)}</a></div>
48
- <div class="line2"><button class="link" data-land="goto">${esc(a.name)}</button>${a.runtime?.busy ? ' <span class="hint">working</span>' : ''}</div>
54
+ <div class="line2"><button class="link" data-land="goto">${esc(a.name)}</button>${a.runtime?.busy ? ' <span class="hint">working</span>' : ''}${commentsHint(a.landing?.comments?.[pr.url])}</div>
49
55
  <div class="land-chips">${scoreBadge(a.docs?.scorecard, esc)} ${prChips(pr, esc)}</div>
50
56
  <div class="bl-actions">
51
57
  <button class="small" data-land="review" title="Its diff, line comments for the agent, commit and push">Review</button>
@@ -76,9 +82,10 @@ export function initLand({ api, esc, toast, agents, $, scoreBadge = () => '', se
76
82
  return g.length ? `<li class="project open"><div class="project-head bl-head"><span class="pname">${label}</span><span class="pcount">${g.length}</span></div><ul>${g.map(rowHtml).join('')}</ul></li>` : '';
77
83
  }).join('')}</ul>`
78
84
  : '<p class="hint land-empty">No open pull requests from agents. Open one from <b>Review changes</b> on an agent, or let the agent open it.</p>'}
79
- ${s ? `<details class="land-settings"><summary>When checks fail or changes are requested</summary>
85
+ ${s ? `<details class="land-settings"><summary>When checks fail or reviewers comment</summary>
80
86
  <label class="check"><input type="checkbox" data-set="fixChecks" ${s.fixChecks ? 'checked' : ''}> Send failing checks to the agent</label>
81
87
  <label class="check"><input type="checkbox" data-set="fixReviews" ${s.fixReviews ? 'checked' : ''}> Send requested changes to the agent</label>
88
+ <label class="check"><input type="checkbox" data-set="fixComments" ${s.fixComments ? 'checked' : ''}> Send new review comments to the agent while the pull request is open (from the repo's members and review bots)</label>
82
89
  <label>At most <input type="number" min="0" max="20" data-set="maxFixes" value="${s.maxFixes}"> times per pull request</label>
83
90
  <label>Merge with <select data-set="mergeMethod">${['squash', 'merge', 'rebase'].map((m) => `<option ${m === s.mergeMethod ? 'selected' : ''}>${m}</option>`).join('')}</select></label>
84
91
  <label class="check"><input type="checkbox" data-set="deleteBranch" ${s.deleteBranch ? 'checked' : ''}> Delete the branch on GitHub after merging</label>
package/public/speak.js CHANGED
@@ -60,6 +60,7 @@ function playNext() {
60
60
  const part = s.parts[s.i];
61
61
  const u = new SpeechSynthesisUtterance(part.text);
62
62
  u.rate = rate();
63
+ if (part.voice) u.voice = part.voice;
63
64
  u.onstart = () => part.onStart?.();
64
65
  u.onend = () => {
65
66
  if (session !== s || s.paused) return;
@@ -74,7 +75,8 @@ function playNext() {
74
75
  }
75
76
 
76
77
  /**
77
- * Play `parts` (strings, or { text, onStart } to follow along, e.g. highlight a change) under `id`.
78
+ * Play `parts` (strings, or { text, onStart, voice } to follow along, e.g. highlight a change, and
79
+ * to speak in a given voice) under `id`.
78
80
  * `onState(state)` hears 'playing' | 'paused' | 'stopped'.
79
81
  */
80
82
  export function play(id, parts, { onState, onEnd } = {}) {
@@ -83,7 +85,7 @@ export function play(id, parts, { onState, onEnd } = {}) {
83
85
  const list = parts.flatMap((p) => {
84
86
  const text = typeof p === 'string' ? p : p.text;
85
87
  const chunks = pieces(text);
86
- return chunks.map((c, k) => ({ text: c, onStart: k === 0 && typeof p !== 'string' ? p.onStart : null }));
88
+ return chunks.map((c, k) => ({ text: c, onStart: k === 0 && typeof p !== 'string' ? p.onStart : null, voice: typeof p === 'string' ? null : p.voice ?? null }));
87
89
  });
88
90
  if (!list.length) return false;
89
91
  session = { id, parts: list, i: 0, paused: false, onState, onEnd };
@@ -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
@@ -1028,3 +1028,99 @@ body.remote .settings-links .local-only { display: none; }
1028
1028
  .goal-projects { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 4px 0 8px; }
1029
1029
  .goal-proj { display: inline-flex; align-items: center; gap: 4px; font-weight: normal; }
1030
1030
  .goal-proj input { width: auto; margin: 0; }
1031
+
1032
+ /* ---------- Watch: agents' sessions side by side */
1033
+ body.watching .layout { display: none; }
1034
+ .watch-view { flex: 1; min-height: 0; overflow: auto; padding: 10px 16px 16px; background: var(--bg); }
1035
+ .watch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 10px; font-size: 13px; }
1036
+ .watch-bar select { width: auto; }
1037
+ .watch-bar .spacer { flex: 1; }
1038
+ .watch-empty { margin: 40px auto; text-align: center; }
1039
+ .watch-grid { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); align-items: start; }
1040
+ /* Fit: every tile on screen; the newest lines stay in view when the session is taller than its tile. */
1041
+ .watch-grid.fit .watch-term { height: var(--watch-term-h, 300px); display: flex; flex-direction: column; justify-content: flex-end; }
1042
+ .watch-tile { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); overflow: hidden; }
1043
+ .watch-tile.attention { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
1044
+ .watch-tile:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
1045
+ .watch-head { display: flex; align-items: center; gap: 8px; padding: 5px 8px; font-size: 12.5px; border-bottom: 1px solid var(--border); min-width: 0; }
1046
+ .watch-head .spacer { flex: 1; }
1047
+ .watch-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
1048
+ .watch-what { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
1049
+ .watch-x { font-size: 16px; line-height: 1; color: var(--muted); }
1050
+ .watch-term { background: #0f1117; padding: 4px; overflow: hidden; cursor: text; }
1051
+ .watch-term .xterm-viewport { overflow-y: hidden; }
1052
+ #watch-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
1053
+ @media (max-width: 640px) {
1054
+ .watch-view { padding: 8px 16px; }
1055
+ .watch-grid:not(.fit) { grid-template-columns: minmax(0, 1fr) !important; }
1056
+ }
1057
+ /* ---------- keyboard shortcuts */
1058
+ kbd { display: inline-block; min-width: 1.6em; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--bg); font: 11.5px var(--mono); text-align: center; line-height: 1.4; }
1059
+ .keys-dialog { max-width: 520px; width: calc(100% - 32px); }
1060
+ .keys-dialog h4 { margin: 14px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
1061
+ .keys-dialog table { width: 100%; border-collapse: collapse; font-size: 13px; }
1062
+ .keys-dialog td { padding: 3px 0; vertical-align: top; }
1063
+ .keys-dialog td.keys { width: 42%; white-space: nowrap; padding-right: 12px; }
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); }
@@ -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
+ }