ai-agentmanager 1.25.2 → 1.26.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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.26.0 (2026-11-07)
4
+
5
+ - **Today: what needs you, in one list.** The Today button (or `y`) gathers what the other lists know and puts the most pressing first: agents stopped at a prompt or waiting for your answer, overdue and due-today action items, issues and pull requests ready for your review, review requests, then the rest (actions due later, new Jira issues, stuck agents, follow-ups). Each says why it's there ("due today · asked by Pat · in Slack", "Blocked: staging credentials"), and the usual decision is a click or a key away: Done, Skip and Discuss for actions, Assign for new issues, Review it for a requested pull request, Open for the rest. Listen reads the top of it aloud. Lists turned off in Settings are left out. The button's count is the pressing ones.
6
+
3
7
  ## 1.25.2 (2026-11-07)
4
8
 
5
9
  - **Designs, Reviews and Value: bigger too.** Drag the corner to any size, or fill the window with ⤢ (or `f`), as in the Jira and Actions lists.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.25.2",
3
+ "version": "1.26.0",
4
4
  "description": "Run background coding agents (Claude Code, Codex) per intent, and keep track of them from a web UI, your phone or the CLI",
5
5
  "keywords": [
6
6
  "claude",
package/public/app.js CHANGED
@@ -27,6 +27,7 @@ import { initWatch } from '/watch.js';
27
27
  import { initStandup } from '/standup.js';
28
28
  import { initIssues } from '/issues.js';
29
29
  import { initActions } from '/actions.js';
30
+ import { initToday } from '/today.js';
30
31
  import { reviewSpeech } from '/prvoice.js';
31
32
  import { initDesigns } from '/designs.js';
32
33
  import { initReviews } from '/reviews.js';
@@ -243,7 +244,22 @@ api('GET', '/features').then((r) => applyFeatures(r.features)).catch(() => {});
243
244
  document.addEventListener('agentmgr:features', (e) => {
244
245
  applyFeatures(e.detail);
245
246
  actionsUi.load();
247
+ todayUi.load();
246
248
  });
249
+ // Today: what needs you, from every list, most pressing first.
250
+ const todayUi = initToday({
251
+ api,
252
+ $,
253
+ esc,
254
+ ago,
255
+ toast: (m, ms) => toast(m, ms),
256
+ openAgent: (id) => (showTab('agents'), select(id)),
257
+ showInbox: () => showTab('inbox'),
258
+ openActions: () => actionsUi.open(),
259
+ openIssues: () => issuesUi.open(),
260
+ openReviews: () => reviewsUi.open(),
261
+ });
262
+ $('#today-btn').onclick = () => todayUi.open();
247
263
  // Designs: every agent's design doc, the ones waiting for your review first.
248
264
  const designsUi = initDesigns({
249
265
  api,
@@ -310,6 +326,7 @@ function shortcut(act) {
310
326
  if (act === 'designs') return designsUi.open();
311
327
  if (act === 'reviews') return reviewsUi.open();
312
328
  if (act === 'value') return valueUi.open();
329
+ if (act === 'today') return todayUi.open();
313
330
  if (act.startsWith('tab:')) return showTab(act.slice(4));
314
331
  return false;
315
332
  }
@@ -765,6 +782,7 @@ bindListen((id) => {
765
782
  else if (what === 'sidewalk') parts = sidePane?.listenParts();
766
783
  else if (what === 'prvoice') parts = reviewSpeech(a, issuesUi.about(agentId));
767
784
  else if (what === 'reviewer') parts = reviewsUi.speech(agentId);
785
+ else if (what === 'today') parts = todayUi.speech();
768
786
  if (!parts?.length || !play(id, parts)) toast('Nothing to read aloud here (or this browser has no speech)');
769
787
  });
770
788
 
@@ -4213,6 +4231,7 @@ function handleEvent(msg) {
4213
4231
  agentChanged(msg.agent);
4214
4232
  if (msg.agent.builds) builtUi.sessionChanged(msg.agent);
4215
4233
  issuesUi.changed();
4234
+ todayUi.changed();
4216
4235
  designsUi.changed();
4217
4236
  if (msg.agent.reviewing) reviewsUi.changed();
4218
4237
  // The detail, terminal and document views show one agent; another agent's update leaves them be.
package/public/index.html CHANGED
@@ -29,6 +29,7 @@
29
29
  </div>
30
30
  <div class="top-actions">
31
31
  <input id="filter" type="search" placeholder="Filter agents" aria-label="Filter agents" />
32
+ <button id="today-btn" title="Today: what needs you, from every list, most pressing first, and why (y)">Today <span id="today-count" class="badge ready"></span></button>
32
33
  <button id="assistant-btn" title="An always-on session that finds new work and starts agents for it">Assistant <span id="assistant-dot" class="assistant-dot" hidden></span></button>
33
34
  <button id="spend-btn" title="Results across agents (merge rate, time to PR, cost per merged PR), what they cost, and spending limits">Results <span id="spend-today" class="spend-today"></span></button>
34
35
  <button id="standup-btn" title="Today's standup: each agent's news read aloud, and what they need from you">Standup <span id="standup-dot" class="assistant-dot" hidden></span></button>
@@ -381,6 +382,9 @@
381
382
  </form>
382
383
  </dialog>
383
384
 
385
+ <dialog id="today-dialog" class="issues-dialog" aria-label="Today">
386
+ <div id="today-body"></div>
387
+ </dialog>
384
388
  <dialog id="actions-dialog" class="issues-dialog" aria-label="Your action items">
385
389
  <div id="actions-body"></div>
386
390
  </dialog>
package/public/keys.js CHANGED
@@ -12,6 +12,7 @@ export const SHORTCUTS = [
12
12
  [['e'], 'Edit it', 'edit'],
13
13
  ]],
14
14
  ['Anywhere', [
15
+ [['y'], 'Today: what needs you, most pressing first', 'today'],
15
16
  [['n'], 'New agents', 'new'],
16
17
  [['a'], 'Ask Agent (a general session)', 'ask'],
17
18
  [['/'], 'Filter agents', 'filter'],
@@ -32,7 +33,7 @@ export const SHORTCUTS = [
32
33
  [['5'], 'Built agents', 'tab:built'],
33
34
  [['?'], 'These shortcuts', 'help'],
34
35
  ]],
35
- ['In the Jira and Actions lists', [
36
+ ['In the Today, Jira and Actions lists', [
36
37
  [['j', 'k'], 'Next / previous row', null],
37
38
  [['[', ']'], 'Previous / next filter', null],
38
39
  [['a'], 'Assign (starts an agent)', null],
@@ -59,11 +60,11 @@ export const SHORTCUTS = [
59
60
  // A single key, as an event names it, to its action.
60
61
  export const SINGLE = {
61
62
  j: 'next', k: 'prev', Enter: 'terminal', t: 'terminal',
62
- r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', o: 'actions', h: 'assistant', ',': 'settings', d: 'designs', g: 'reviews', v: 'value', '?': 'help',
63
+ r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', o: 'actions', h: 'assistant', ',': 'settings', d: 'designs', g: 'reviews', v: 'value', y: 'today', '?': 'help',
63
64
  1: 'tab:agents', 2: 'tab:inbox', 3: 'tab:backlog', 4: 'tab:land', 5: 'tab:built',
64
65
  };
65
66
  // While Watch is open: only what makes sense there.
66
- const ON_WATCH = new Set(['new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'help']);
67
+ const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'help']);
67
68
 
68
69
  /** Typing somewhere: a field, an editor or a terminal (xterm types through a textarea). */
69
70
  const typing = (el) => Boolean(el?.closest?.('input, textarea, select, [contenteditable=""], [contenteditable="true"], .xterm, .cm-editor'));
package/public/style.css CHANGED
@@ -1181,6 +1181,20 @@ table.issues .dot.idle { background: var(--muted); }
1181
1181
  table.issues .issue-title, table.issues .issue-synopsis { max-width: 200px; }
1182
1182
  }
1183
1183
 
1184
+ /* ---------- Today: what needs you */
1185
+ #today-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
1186
+ #today-btn { font-weight: 600; }
1187
+ table.today-table .today-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; padding: 2px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted); }
1188
+ table.today-table tr.pressing .today-label { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
1189
+ table.today-table tr.today-prompt .today-label, table.today-table tr.today-waiting .today-label, table.today-table tr.today-question .today-label { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
1190
+ table.today-table .today-title { color: var(--text); }
1191
+ table.today-table .today-why { margin-top: 2px; }
1192
+ table.today-table .today-acts { width: 1%; text-align: right; }
1193
+ table.today-table .small-link { font-size: 12px; margin-left: 4px; }
1194
+ @media (max-width: 640px) {
1195
+ table.today-table .today-acts { white-space: normal; }
1196
+ }
1197
+
1184
1198
  /* ---------- Designs: agents' design docs */
1185
1199
  .designs-search { width: 180px; }
1186
1200
  .designs-list { overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
@@ -0,0 +1,186 @@
1
+ // Today: what needs you, from every list, most pressing first: agents stopped at a prompt or
2
+ // waiting for an answer, issues and pull requests ready for your review, what's asked of you
3
+ // (by due date), new Jira issues, and the rest. Each says why it's here, and the common
4
+ // decisions are a click (or a key) away. Listen reads the top of it aloud.
5
+
6
+ import { listenHtml } from './speak.js';
7
+ import { holdWhilePicking, rowKeys } from './rowkeys.js';
8
+ import { expandButton, expandable } from './expand.js';
9
+
10
+ // Up to this score an item is pressing: it counts on the button.
11
+ const PRESSING = 32;
12
+
13
+ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions, openIssues, openReviews, toast }) {
14
+ const dialog = $('#today-dialog');
15
+ const body = $('#today-body');
16
+ let data = null;
17
+ let loading = false;
18
+ let again = null;
19
+ let loadedAt = 0;
20
+
21
+ async function load({ quiet = false } = {}) {
22
+ if (loading) return;
23
+ loading = true;
24
+ try {
25
+ data = await api('GET', '/today');
26
+ loadedAt = Date.now();
27
+ } catch (e) {
28
+ if (!quiet) toast?.(e.message, 5000);
29
+ } finally {
30
+ loading = false;
31
+ }
32
+ badge();
33
+ render();
34
+ }
35
+
36
+ function badge() {
37
+ const n = data ? data.items.filter((i) => i.score <= PRESSING).length : 0;
38
+ const el = $('#today-count');
39
+ if (el) {
40
+ el.textContent = n ? String(n) : '';
41
+ el.title = n ? `${n} pressing: agents waiting on you, overdue or due-today actions, reviews` : '';
42
+ }
43
+ }
44
+
45
+ const link = (url, label) => (url ? `<a href="${esc(url)}" target="_blank" rel="noopener" class="small-link">${esc(label)} ↗</a>` : '');
46
+ const btn = (act, label, title, primary = false) => `<button class="small ${primary ? 'primary' : ''}" data-today="${act}" title="${esc(title)}">${esc(label)}</button>`;
47
+
48
+ /** The buttons for an item: the decision it asks for, then where to look. */
49
+ function buttons(it) {
50
+ if (it.kind === 'action') return [btn('done', 'Done', 'Handled: off the list (d)'), btn('skip', 'Skip', 'Not now (s)'), btn('discuss', 'Discuss', 'Talk it through with Claude (c)'), link(it.url, 'Source')].join(' ');
51
+ if (it.kind === 'issue-new') return [btn('assign', 'Assign', 'Start an agent on it (a)', true), btn('skip', 'Skip', 'Not now (s)'), link(it.url, 'Jira')].join(' ');
52
+ if (it.kind === 'pr-requested') return [btn('review', 'Review it', 'A reviewer agent reads it and finds what blocks approval (a)', true), link(it.url, 'PR')].join(' ');
53
+ if (it.kind === 'pr-ready') return [btn('open-reviews', 'Open review', 'Pick what to post (Enter)', true), link(it.url, 'PR')].join(' ');
54
+ if (it.kind === 'rule') return btn('inbox', 'Inbox', 'Decide in the inbox (Enter)', true);
55
+ return [it.agentId ? btn('open', 'Open', "Open the agent's session (Enter)", it.score < 20) : '', link(it.url, it.issueKey ? 'Jira' : 'Link')].join(' ');
56
+ }
57
+
58
+ function row(it) {
59
+ return `<tr data-row-id="${esc(it.id)}" class="today-${esc(it.kind)} ${it.score <= PRESSING ? 'pressing' : ''}">
60
+ <td class="nowrap"><span class="today-label">${esc(it.label)}</span></td>
61
+ <td><div class="today-title">${esc(it.title)}</div><div class="hint today-why">${esc(it.why ?? '')}${it.at ? ` · ${esc(ago(it.at))}` : ''}</div></td>
62
+ <td class="nowrap today-acts">${buttons(it)}</td>
63
+ </tr>`;
64
+ }
65
+
66
+ function draw() {
67
+ if (!dialog.open) return;
68
+ if (!data) {
69
+ body.innerHTML = '<p class="hint">Loading…</p>';
70
+ return;
71
+ }
72
+ const items = data.items;
73
+ const pressing = items.filter((i) => i.score <= PRESSING).length;
74
+ const off = [!data.features?.jira && 'Jira', !data.features?.slack && !data.features?.gemini && 'Actions'].filter(Boolean);
75
+ body.innerHTML = `
76
+ <div class="issues-head">
77
+ <h2>Today</h2>
78
+ <span class="hint">${items.length ? `${pressing} pressing · ${items.length} in all` : ''}</span>
79
+ <span class="spacer"></span>
80
+ ${listenHtml('today', { title: 'Read the top of the list aloud', label: 'Listen' })}
81
+ <button class="small" data-today="refresh" title="Look again (r)">↻</button>
82
+ ${expandButton(dialog)}
83
+ <button class="small" data-today="close" title="Close (Esc)">Close</button>
84
+ </div>
85
+ ${items.length
86
+ ? `<div class="issues-scroll"><table class="issues today-table"><tbody>${items.map(row).join('')}</tbody></table></div>`
87
+ : '<p class="hint issues-empty">Nothing needs you right now: no agent is waiting on you, nothing is due, and no review is waiting.</p>'}
88
+ <p class="hint">Keys: j/k move (or click a row), Enter opens, a assign or review, d done, s skip, c discuss, r look again, f bigger.${off.length ? ` Not included (off in Settings → What you use): ${esc(off.join(', '))}.` : ''}${data.errors?.length ? ` Couldn't get: ${esc(data.errors.map((e) => e.source).join(', '))}.` : ''}</p>`;
89
+ keys.redraw();
90
+ }
91
+ const render = holdWhilePicking(body, draw);
92
+ expandable(dialog, draw);
93
+
94
+ const itemOf = (id) => data?.items.find((i) => i.id === id) ?? null;
95
+
96
+ /** Do `act` for the item; the list is looked at again after anything that changes it. */
97
+ async function act(it, what) {
98
+ if (!it) return;
99
+ try {
100
+ if (what === 'open' || (what === 'enter' && it.agentId && !['pr-ready', 'rule'].includes(it.kind))) {
101
+ if (!it.agentId) return;
102
+ dialog.close();
103
+ return openAgent(it.agentId);
104
+ }
105
+ if (what === 'inbox' || (what === 'enter' && it.kind === 'rule')) {
106
+ dialog.close();
107
+ return showInbox();
108
+ }
109
+ if (what === 'open-reviews' || (what === 'enter' && it.kind.startsWith('pr-'))) {
110
+ dialog.close();
111
+ return openReviews();
112
+ }
113
+ if (what === 'enter') {
114
+ if (it.kind === 'action') {
115
+ dialog.close();
116
+ return openActions();
117
+ }
118
+ if (it.kind === 'issue-new') {
119
+ dialog.close();
120
+ return openIssues();
121
+ }
122
+ if (it.url) window.open(it.url, '_blank', 'noopener');
123
+ return;
124
+ }
125
+ if (it.kind === 'action' && ['done', 'skip'].includes(what)) {
126
+ const r = await api('POST', '/actions/set', { ids: [it.actionId], state: what });
127
+ toast?.(r.failed.length ? `Not changed: ${r.failed.map((x) => x.reason).join('; ')}` : what === 'done' ? 'Done' : 'Skipped', 2500);
128
+ } else if (it.kind === 'action' && what === 'discuss') {
129
+ const r = await api('POST', `/actions/${it.actionId}/discuss`, {});
130
+ dialog.close();
131
+ return openAgent(r.agent.id);
132
+ } else if (it.kind === 'issue-new' && ['assign', 'skip'].includes(what)) {
133
+ const r = await api('POST', '/issues/action', { keys: [it.issueKey], action: what });
134
+ const bad = r.failed.map((x) => x.reason).join('; ');
135
+ toast?.(bad ? `Not changed: ${bad}` : r.started.length ? `Started an agent on ${it.title}` : `${it.title}: skipped`, bad ? 6000 : 3000);
136
+ } else if (it.kind === 'pr-requested' && (what === 'review' || what === 'assign')) {
137
+ const a = await api('POST', '/reviews', { url: it.reviewUrl });
138
+ toast?.(`Reviewer ${a.name ?? 'agent'} started`, 3000);
139
+ } else return;
140
+ } catch (err) {
141
+ return toast?.(err.message, 6000);
142
+ }
143
+ load();
144
+ }
145
+
146
+ const keys = rowKeys(dialog, {
147
+ rows: () => [...body.querySelectorAll('tbody tr[data-row-id]')],
148
+ keys: {
149
+ Enter: (r) => act(itemOf(r.dataset.rowId), 'enter'),
150
+ a: (r) => act(itemOf(r.dataset.rowId), 'assign'),
151
+ d: (r) => act(itemOf(r.dataset.rowId), 'done'),
152
+ s: (r) => act(itemOf(r.dataset.rowId), 'skip'),
153
+ c: (r) => act(itemOf(r.dataset.rowId), 'discuss'),
154
+ r: Object.assign(() => load(), { needsRow: false }),
155
+ },
156
+ });
157
+
158
+ body.addEventListener('click', (e) => {
159
+ const b = e.target.closest('[data-today]')?.dataset.today;
160
+ if (!b) return;
161
+ if (b === 'close') return dialog.close();
162
+ if (b === 'refresh') return load();
163
+ act(itemOf(e.target.closest('tr[data-row-id]')?.dataset.rowId), b);
164
+ });
165
+
166
+ function open() {
167
+ if (dialog.open) return dialog.close();
168
+ dialog.showModal();
169
+ render();
170
+ load();
171
+ }
172
+
173
+ /** Something changed (an agent, an action): look again shortly while open, now and then for the count. */
174
+ function changed() {
175
+ if (!dialog.open && again) return;
176
+ clearTimeout(again);
177
+ const wait = dialog.open ? 1500 : Math.max(5000, 30_000 - (Date.now() - loadedAt));
178
+ again = setTimeout(() => {
179
+ again = null;
180
+ load({ quiet: true });
181
+ }, wait);
182
+ }
183
+
184
+ load({ quiet: true });
185
+ return { open, changed, load, isOpen: () => dialog.open, speech: () => data?.speech ?? null };
186
+ }
package/src/server.js CHANGED
@@ -26,6 +26,7 @@ import { Repeats } from './repeats.js';
26
26
  import { Updates } from './update.js';
27
27
  import { identity } from './identity.js';
28
28
  import { WorkLog, summaryMarkdown } from './worklog.js';
29
+ import { todayItems, todaySpeech } from './today.js';
29
30
  import { Studio } from './studio.js';
30
31
  import { Memory } from './memory.js';
31
32
  import { doctor } from './doctor.js';
@@ -864,6 +865,29 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
864
865
  res.status(500).json({ error: e.message });
865
866
  }
866
867
  });
868
+ // Today: what needs you, from every list, most pressing first (today.js). A list that's off or
869
+ // can't be had right now is left out, and said so.
870
+ api.get('/today', wrap(async () => {
871
+ const f = featuresOf(config);
872
+ manager.jiraOff = !f.jira;
873
+ const errors = [];
874
+ const got = async (name, fn) => {
875
+ try {
876
+ return await fn();
877
+ } catch (e) {
878
+ errors.push({ source: name, error: e.message });
879
+ return [];
880
+ }
881
+ };
882
+ const [inbox, issues, actions, prs] = await Promise.all([
883
+ got('inbox', () => manager.inbox()),
884
+ f.jira ? got('jira', async () => (await manager.issues(proposed.listed(), proposed.actions)).rows) : [],
885
+ f.slack || f.gemini ? got('actions', () => myActions.rows()) : [],
886
+ got('reviews', () => reviews.rows()),
887
+ ]);
888
+ const items = todayItems({ inbox, issues, actions, reviews: prs });
889
+ return { items, speech: todaySpeech(items), features: f, errors };
890
+ }));
867
891
  api.get('/standup', wrap(() => standup.view()));
868
892
  api.post('/standup', wrap(async () => ({ ...standup.view(), latest: await standup.make({ reason: 'asked' }) })));
869
893
  api.put('/standup', wrap((req) => {
package/src/today.js ADDED
@@ -0,0 +1,114 @@
1
+ // Today: what needs you, in one list, most pressing first. It gathers what the other lists already
2
+ // know (agents' questions and prompts from the inbox, issues waiting for your review or not started
3
+ // in Jira, what's asked of you in Slack and meeting notes, pull requests to review) and says, for
4
+ // each, why it's here: "blocks OPS-7", "due today", "assigned to you".
5
+
6
+ const DAY = 86_400_000;
7
+ const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
8
+
9
+ /**
10
+ * When a due date said in words falls ("today", "EOD", "tomorrow", "Friday", "2026-11-09",
11
+ * "Nov 9"): the end of that day, or null when it can't be told. `now` is a Date.
12
+ */
13
+ export function dueAt(due, now = new Date()) {
14
+ const s = String(due ?? '').trim().toLowerCase().replace(/(\d)(st|nd|rd|th)\b/g, '$1');
15
+ if (!s) return null;
16
+ const endOf = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59);
17
+ if (/\b(today|tonight|eod|end of (the )?day|asap|now|urgent)\b/.test(s)) return endOf(now);
18
+ if (/\btomorrow\b/.test(s)) return endOf(new Date(now.getTime() + DAY));
19
+ if (/\b(eow|end of (the )?week|this week)\b/.test(s)) return endOf(new Date(now.getTime() + ((5 - now.getDay() + 7) % 7) * DAY));
20
+ if (/\bnext week\b/.test(s)) return endOf(new Date(now.getTime() + ((8 - now.getDay()) % 7 || 7) * DAY + 4 * DAY));
21
+ const wd = WEEKDAYS.findIndex((w) => new RegExp(`\\b${w.slice(0, 3)}(${w.slice(3)})?\\b`).test(s));
22
+ if (wd >= 0) return endOf(new Date(now.getTime() + ((wd - now.getDay() + 7) % 7) * DAY));
23
+ // A date: ISO, or a month and day (this year; next year when that's long past).
24
+ const iso = s.match(/\b(\d{4})-(\d{2})-(\d{2})\b/);
25
+ if (iso) return endOf(new Date(Number(iso[1]), Number(iso[2]) - 1, Number(iso[3])));
26
+ if (!/\b(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?\s+\d{1,2}\b|\b\d{1,2}\s+(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/.test(s)) return null;
27
+ const t = Date.parse(`${s.replace(/\b(by|on|before|due)\b/g, '').trim()} ${now.getFullYear()}`);
28
+ if (Number.isFinite(t)) {
29
+ const d = new Date(t);
30
+ return endOf(d.getTime() < now.getTime() - 180 * DAY ? new Date(d.getFullYear() + 1, d.getMonth(), d.getDate()) : d);
31
+ }
32
+ return null;
33
+ }
34
+
35
+ /** "overdue 2 days", "due today", "due tomorrow", "due Friday", or null. */
36
+ export function dueWords(at, now = new Date()) {
37
+ if (!at) return null;
38
+ const day = (d) => Math.floor(new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime() / DAY);
39
+ const n = day(at) - day(now);
40
+ if (n < 0) return `overdue ${-n === 1 ? 'a day' : `${-n} days`}`;
41
+ if (n === 0) return 'due today';
42
+ if (n === 1) return 'due tomorrow';
43
+ if (n < 7) return `due ${WEEKDAYS[at.getDay()].replace(/^./, (c) => c.toUpperCase())}`;
44
+ return `due ${at.getFullYear()}-${String(at.getMonth() + 1).padStart(2, '0')}-${String(at.getDate()).padStart(2, '0')}`;
45
+ }
46
+
47
+ const INBOX = {
48
+ prompt: { score: 0, label: 'Prompt', why: (i) => `${i.agentName} is stopped until you answer` },
49
+ waiting: { score: 10, label: 'Question', why: (i) => `${i.agentName} waits for your answer` },
50
+ question: { score: 10, label: 'Question', why: (i) => `${i.agentName} asked` },
51
+ review: { score: 35, label: 'AI review', why: (i) => `The AI review of ${i.agentName}'s work is in` },
52
+ stuck: { score: 55, label: 'Stuck', why: (i) => `${i.agentName} looks stuck` },
53
+ conflict: { score: 60, label: 'Overlap', why: (i) => `${i.agentName} and another agent change the same code` },
54
+ rule: { score: 65, label: 'Rule', why: () => 'You keep allowing this' },
55
+ reminder: { score: 70, label: 'Follow-up', why: (i) => `${i.agentName} finished and wasn't looked at` },
56
+ };
57
+
58
+ /**
59
+ * The list: [{ id, kind, label, title, why, score, at, agentId?, url?, actionId?, issueKey?, reviewUrl? }],
60
+ * most pressing first. Each source may be missing (turned off, or it couldn't be had).
61
+ */
62
+ export function todayItems({ inbox = [], issues = [], actions = [], reviews = [], now = new Date() } = {}) {
63
+ const items = [];
64
+ // The issue each agent works on: named on its questions, and not listed twice.
65
+ const issueOfAgent = new Map(issues.filter((r) => r.agent?.id).map((r) => [r.agent.id, r]));
66
+ const asking = new Set();
67
+ for (const i of inbox) {
68
+ const k = INBOX[i.kind];
69
+ if (!k) continue;
70
+ const r = i.agentId ? issueOfAgent.get(i.agentId) : null;
71
+ if (r && ['prompt', 'waiting', 'question'].includes(i.kind)) asking.add(r.key);
72
+ const about = !r?.title ? '' : i.agentName === r.key ? ` · ${r.title}` : ` · ${r.key}: ${r.title}`;
73
+ items.push({ id: i.key, kind: i.kind, label: k.label, title: String(i.title ?? '').slice(0, 300), why: k.why(i) + about, score: k.score + (i.priority ?? 2) / 10, at: i.at ?? null, agentId: i.agentId ?? null, ...(r ? { url: r.url ?? null, issueKey: r.key } : {}) });
74
+ }
75
+ for (const r of issues) {
76
+ if (asking.has(r.key)) continue;
77
+ const title = r.title ? `${r.key}: ${r.title}` : r.key;
78
+ if (r.group === 'you') {
79
+ items.push({ id: `issue:${r.key}`, kind: 'issue-review', label: 'Jira', title, why: r.note, score: 25, at: r.updatedAt ?? null, agentId: r.agent?.id ?? null, url: r.url ?? null, issueKey: r.key });
80
+ } else if (r.group === 'new') {
81
+ items.push({ id: `issue:${r.key}`, kind: 'issue-new', label: r.type && !/^(story|task|bug|sub-?task)$/i.test(r.type) ? r.type : 'Jira', title, why: r.stage === 'assigned' ? 'Assigned to you in Jira, not started' : 'Proposed for an agent, not started', score: 50, at: r.updatedAt ?? null, url: r.url ?? null, issueKey: r.key });
82
+ }
83
+ }
84
+ for (const a of actions) {
85
+ if (a.group !== 'open') continue;
86
+ const at = dueAt(a.due, now);
87
+ const words = dueWords(at, now);
88
+ const late = at && at.getTime() < now.getTime();
89
+ const soon = at && !late && at.getTime() - now.getTime() < DAY;
90
+ const score = late ? 15 : soon ? 20 : at ? 40 + Math.min(9, (at.getTime() - now.getTime()) / DAY) : 45;
91
+ const why = [words ?? (a.due ? `due ${a.due}` : null), a.from && `asked by ${a.from}`, a.sourceLabel && `in ${a.sourceLabel}`].filter(Boolean).join(' · ');
92
+ items.push({ id: `action:${a.id}`, kind: 'action', label: 'Action', title: a.text, why: why || 'Asked of you', score, at: a.when ?? null, url: a.link ?? null, actionId: a.id, due: at?.toISOString() ?? null });
93
+ }
94
+ for (const r of reviews) {
95
+ const title = `${r.pr.repo ?? ''}#${r.pr.number ?? '?'} ${r.pr.title ?? ''}`.trim();
96
+ if (r.status === 'requested') {
97
+ items.push({ id: `pr:${r.pr.url}`, kind: 'pr-requested', label: 'Review', title, why: `Your review was requested${r.pr.author ? ` by ${r.pr.author}` : ''}`, score: 30, at: r.updatedAt ?? null, url: r.pr.url, reviewUrl: r.pr.url });
98
+ } else if (r.agent && r.review && !r.posted && r.pr.state !== 'MERGED' && r.pr.state !== 'CLOSED') {
99
+ const verdict = { blocked: 'blocks approval', approve_with_nits: 'approve with nits', approve: 'approve' }[r.status] ?? r.status;
100
+ items.push({ id: `pr:${r.pr.url}`, kind: 'pr-ready', label: 'Review', title, why: `${r.agent.name}'s review is ready to post: ${verdict}${r.stale ? ' (the author pushed since)' : ''}`, score: 32, at: r.updatedAt ?? null, agentId: r.agent.id, url: r.pr.url, reviewUrl: r.pr.url });
101
+ }
102
+ }
103
+ return items.sort((x, y) => x.score - y.score || String(y.at ?? '').localeCompare(String(x.at ?? '')));
104
+ }
105
+
106
+ /** What the list says aloud: a count, then the first `max` items one by one. */
107
+ export function todaySpeech(items, max = 8) {
108
+ if (!items.length) return ['Nothing needs you right now.'];
109
+ const parts = [`${items.length} thing${items.length === 1 ? '' : 's'} for you today.${items.length > max ? ` The first ${max}:` : ''}`];
110
+ // Read as sentences: a link is "a link", "·" a comma, and no doubled stops ("?.").
111
+ const say = (t) => String(t ?? '').replace(/https?:\/\/\S+/g, 'a link').replace(/\s+·\s+/g, ', ').trim().replace(/[.?!:;,]*$/, (m) => m || '.');
112
+ items.slice(0, max).forEach((it, i) => parts.push(`${i + 1}. ${it.label}. ${say(it.title)} ${say(it.why)}`));
113
+ return parts;
114
+ }