ai-agentmanager 1.28.0 → 1.30.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/today.js CHANGED
@@ -10,7 +10,7 @@ import { expandButton, expandable } from './expand.js';
10
10
  // Up to this score an item is pressing: it counts on the button.
11
11
  const PRESSING = 32;
12
12
 
13
- export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions, openIssues, openReviews, openBugs, toast }) {
13
+ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions, openIssues, openReviews, openBugs, openChanges, toast }) {
14
14
  const dialog = $('#today-dialog');
15
15
  const body = $('#today-body');
16
16
  let data = null;
@@ -19,6 +19,9 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
19
19
  let loadedAt = 0;
20
20
  let undo = null; // { label, run }: the last change made here, to take back (u)
21
21
  let asideOpen = false;
22
+ let editing = null; // the question whose draft answer is being edited
23
+ let replying = null; // the item a reply or send-back box is open on
24
+ const drafts = new Map(); // typed text per item, kept across redraws
22
25
 
23
26
  async function load({ quiet = false, fresh = false } = {}) {
24
27
  if (loading) return;
@@ -47,21 +50,43 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
47
50
  const link = (url, label) => (url ? `<a href="${esc(url)}" target="_blank" rel="noopener" class="small-link">${esc(label)} ↗</a>` : '');
48
51
  const btn = (act, label, title, primary = false) => `<button class="small ${primary ? 'primary' : ''}" data-today="${act}" title="${esc(title)}">${esc(label)}</button>`;
49
52
 
53
+ const snoozeBtn = btn('snooze', 'Snooze', 'Until tomorrow 9am (z)');
54
+
50
55
  /** The buttons for an item: the decision it asks for, then where to look. */
51
56
  function buttons(it) {
52
- 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(' ');
53
- 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(' ');
57
+ if (it.kind === 'ask') return [it.draft ? btn('copy', 'Copy answer', 'Copy the drafted answer, to paste in the thread', true) : btn('draft', 'Draft answer', 'A session reads the thread, finds the answer and drafts it for you', true), btn('done', 'Answered', 'You answered it: off the list (d)'), snoozeBtn, link(it.url, 'Thread')].join(' ');
58
+ if (it.kind === 'action') return [btn('done', 'Done', 'Handled: off the list (d)'), btn('skip', 'Skip', 'Not now (s)'), snoozeBtn, btn('discuss', 'Discuss', 'Talk it through with Claude (c)'), link(it.url, 'Source')].join(' ');
59
+ if (it.kind === 'issue-new') return [btn('assign', 'Assign', 'Start an agent on it (a)', true), btn('skip', 'Skip', 'Not now (s)'), snoozeBtn, link(it.url, 'Jira')].join(' ');
60
+ if (it.ship) return [btn('changes', 'See changes', 'The diff, to look over first'), btn('ship', 'Open PR', 'Commit what is left, push and open the pull request', true), btn('send-back', 'Send back', 'Tell the agent what is still missing'), btn('open', 'Open', "Open the agent's session (Enter)"), link(it.url, 'Jira')].join(' ');
54
61
  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(' ');
55
62
  if (it.kind === 'pr-ready') return [btn('open-reviews', 'Open review', 'Pick what to post (Enter)', true), link(it.url, 'PR')].join(' ');
56
63
  if (it.kind === 'rule') return btn('inbox', 'Inbox', 'Decide in the inbox (Enter)', true);
64
+ if (it.kind === 'bug-pr') return [link(it.url, 'Open PR'), btn('done', 'Done', 'You looked at it: off the list (d)'), btn('bugs', 'Details', 'The bug and how the fix was checked (Enter)')].join(' ');
57
65
  if (it.kind === 'bug') return [btn('fix', 'Fix', 'Start an agent on it, with the failing test (a)', true), btn('skip', 'Snooze', 'Until tomorrow 9am (s)'), btn('notbug', 'Not a bug', "It won't be reported again"), btn('bugs', 'Evidence', 'See it in Bugs (Enter)')].join(' ');
58
66
  return [it.agentId ? btn('open', 'Open', "Open the agent's session (Enter)", it.score < 20) : '', link(it.url, it.issueKey ? 'Jira' : 'Link')].join(' ');
59
67
  }
60
68
 
69
+ /** Under an item: the agent's choices and a reply box, a drafted answer, or a send-back box. */
70
+ function extra(it) {
71
+ const box = (placeholder, send) => `<form class="today-reply" data-today-form="${esc(it.id)}"><input data-today-text="${esc(it.id)}" placeholder="${esc(placeholder)}" value="${esc(drafts.get(it.id) ?? '')}" autocomplete="off" /><button class="small primary">${esc(send)}</button></form>`;
72
+ if (it.answer) {
73
+ const a = it.answer;
74
+ const choices = a.via === 'key' ? a.choices.map((c, i) => `<button class="small ${i === 0 ? 'primary' : ''}" data-today-pick="${i}" title="Press ${esc(c.key)}">${esc(c.key)}. ${esc(c.label)}</button>`) : a.choices.map((c, i) => `<button class="small" data-today-pick="${i}" title="Answer this (${i + 1})">${esc(c)}</button>`);
75
+ return `<div class="today-answer">${choices.join(' ')}${a.default ? ` <span class="hint">Going ahead with “${esc(String(a.default).replace(/[.!\s]+$/, ''))}” until you answer.</span>` : ''}${a.reply ? box('Or type an answer…', 'Send') : ''}</div>`;
76
+ }
77
+ if (it.kind === 'ask') {
78
+ if (editing === it.id) return `<form class="today-draft-edit" data-today-edit="${esc(it.id)}"><textarea rows="4" data-today-edit-text>${esc(it.draft?.text ?? '')}</textarea><div><button class="small primary">Save</button> <button type="button" class="small" data-today="cancel-edit">Cancel</button></div></form>`;
79
+ if (it.draft) return `<div class="today-draft"><div class="today-draft-text">${esc(it.draft.text)}</div><div class="hint">${it.draft.by === 'you' ? 'Your edit' : 'Drafted by the assistant'}${it.draft.sources ? ` · from ${esc(it.draft.sources)}` : ''} · <button class="link" data-today="edit">Edit</button> · <button class="link" data-today="draft">Draft again</button></div></div>`;
80
+ return '';
81
+ }
82
+ if (it.ship && replying === it.id) return box('What is still missing?', 'Send back');
83
+ return '';
84
+ }
85
+
61
86
  function row(it) {
62
87
  return `<tr data-row-id="${esc(it.id)}" class="today-${esc(it.kind)} ${it.score <= PRESSING ? 'pressing' : ''}">
63
88
  <td class="nowrap"><span class="today-label">${esc(it.label)}</span></td>
64
- <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>
89
+ <td><div class="today-title">${esc(it.title)}</div><div class="hint today-why">${esc(it.why ?? '')}${it.at ? ` · ${esc(ago(it.at))}` : ''}</div>${extra(it)}</td>
65
90
  <td class="nowrap today-acts">${buttons(it)}</td>
66
91
  </tr>`;
67
92
  }
@@ -89,7 +114,7 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
89
114
  ? `<div class="issues-scroll"><table class="issues today-table"><tbody>${items.map(row).join('')}</tbody></table></div>`
90
115
  : '<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>'}
91
116
  ${asideHtml()}
92
- <p class="hint">Keys: j/k move (or click a row), Enter opens, a assign or review, d done, s skip, c discuss, u undo, 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 === 'jira' ? 'Jira' : e.source} (${e.error})`).join('; '))}.` : ''}</p>`;
117
+ <p class="hint">Keys: j/k move (or click a row), Enter opens, 1–6 pick an answer, a assign or review, d done, s skip, z snooze, c discuss, u undo, 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 === 'jira' ? 'Jira' : e.source} (${e.error})`).join('; '))}.` : ''}</p>`;
93
118
  keys.redraw();
94
119
  }
95
120
  const render = holdWhilePicking(body, draw);
@@ -99,7 +124,7 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
99
124
  const aside = data?.aside ?? [];
100
125
  if (!aside.length) return '';
101
126
  const rows = aside
102
- .map((a) => `<tr data-aside-id="${esc(a.id)}"><td class="nowrap"><span class="today-label">${esc(a.label)}</span></td><td><div class="today-title">${esc(a.title)}</div>${a.at ? `<div class="hint">${esc(ago(a.at))}</div>` : ''}</td><td class="nowrap today-acts"><button class="small" data-today-back="${esc(a.id)}" title="Back on the list, undecided">Bring back</button></td></tr>`)
127
+ .map((a) => `<tr data-aside-id="${esc(a.id)}"><td class="nowrap"><span class="today-label">${esc(a.label)}</span></td><td><div class="today-title">${esc(a.title)}</div><div class="hint">${a.until ? `until ${esc(new Date(a.until).toLocaleString([], { weekday: 'short', hour: 'numeric', minute: '2-digit' }))}` : a.at ? esc(ago(a.at)) : ''}</div></td><td class="nowrap today-acts"><button class="small" data-today-back="${esc(a.id)}" title="Back on the list, undecided">Bring back</button></td></tr>`)
103
128
  .join('');
104
129
  return `<details class="today-aside" ${asideOpen ? 'open' : ''}><summary>Set aside: skipped, done or removed (${aside.length})</summary>
105
130
  <div class="today-aside-head"><span class="hint">Brought back, an item is undecided again and shows in Today and its own list.</span><button class="small" data-today-back="all" title="Bring every one back">Bring all ${aside.length} back</button></div>
@@ -117,12 +142,38 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
117
142
  const same = list.filter((a) => a.state === state);
118
143
  const keys = same.filter((a) => a.kind === 'issue').map((a) => a.issueKey);
119
144
  const ids = same.filter((a) => a.kind === 'action').map((a) => a.actionId);
120
- if (keys.length) await api('POST', '/issues/action', { keys, action: state });
121
- if (ids.length) await api('POST', '/actions/set', { ids, state });
145
+ // A snooze goes back to its own time, or tomorrow when that has passed.
146
+ const until = state === 'snooze' ? (same.map((a) => a.until).find((u) => Date.parse(u) > Date.now()) ?? tomorrow9()) : undefined;
147
+ if (keys.length) await api('POST', '/issues/action', { keys, action: state, until });
148
+ if (ids.length) await api('POST', '/actions/set', { ids, state, until });
122
149
  }
123
150
  };
124
151
  }
125
152
 
153
+ /** Tomorrow at 9 in the morning. */
154
+ function tomorrow9() {
155
+ const t = new Date();
156
+ t.setDate(t.getDate() + 1);
157
+ t.setHours(9, 0, 0, 0);
158
+ return t.toISOString();
159
+ }
160
+
161
+ /** Answer an agent's question: a choice (by its index) or typed text. */
162
+ async function answer(it, { pick = null, text = null }) {
163
+ const a = it.answer;
164
+ if (a.via === 'key') {
165
+ const c = a.choices[pick];
166
+ if (!c) return;
167
+ await api('POST', `/agents/${it.agentId}/prompt-key`, { key: c.key });
168
+ return `Pressed ${c.key}. ${c.label}`;
169
+ }
170
+ const t = text ?? a.choices[pick];
171
+ if (!t) return;
172
+ if (a.via === 'waiting') await api('POST', `/agents/${it.agentId}/waiting/answer`, { text: t });
173
+ else await api('POST', `/agents/${it.agentId}/answer`, { question: a.qid, text: t });
174
+ return `Answered: ${t.length > 60 ? `${t.slice(0, 59)}…` : t}`;
175
+ }
176
+
126
177
  /** Remember how to take back a change, and offer it on the toast. */
127
178
  function changedWith(msg, label, run) {
128
179
  undo = { label, run };
@@ -162,9 +213,9 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
162
213
  dialog.close();
163
214
  return openReviews();
164
215
  }
165
- if (what === 'bugs' || (what === 'enter' && it.kind === 'bug')) {
216
+ if (what === 'bugs' || (what === 'enter' && (it.kind === 'bug' || it.kind === 'bug-pr'))) {
166
217
  dialog.close();
167
- return openBugs?.();
218
+ return openBugs?.(it.kind === 'bug-pr' ? 'pr' : undefined);
168
219
  }
169
220
  if (what === 'enter') {
170
221
  if (it.kind === 'action') {
@@ -178,7 +229,38 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
178
229
  if (it.url) window.open(it.url, '_blank', 'noopener');
179
230
  return;
180
231
  }
181
- if (it.kind === 'action' && ['done', 'skip'].includes(what)) {
232
+ if (what === 'snooze' && ['action', 'ask', 'issue-new'].includes(it.kind)) {
233
+ const until = tomorrow9();
234
+ if (it.kind === 'issue-new') await api('POST', '/issues/action', { keys: [it.issueKey], action: 'snooze', until });
235
+ else await api('POST', '/actions/set', { ids: [it.actionId], state: 'snooze', until });
236
+ changedWith('Snoozed until tomorrow 9am', 'snoozed', () => (it.kind === 'issue-new' ? api('POST', '/issues/action', { keys: [it.issueKey], action: null }) : api('POST', '/actions/set', { ids: [it.actionId], state: 'open' })));
237
+ } else if (it.kind === 'ask' && what === 'copy' && it.draft) {
238
+ const ok = await navigator.clipboard?.writeText(it.draft.text).then(() => true, () => false);
239
+ return toast?.(ok ? `Copied${it.url ? ': paste it in the thread' : ''}` : "Couldn't copy: select the text instead", 3000, it.url ? { label: 'Open thread', run: () => window.open(it.url, '_blank', 'noopener') } : undefined);
240
+ } else if (it.kind === 'ask' && what === 'draft') {
241
+ const r = await api('POST', `/actions/${it.actionId}/draft`, {});
242
+ toast?.(r.existing ? 'A session is drafting it already' : 'Drafting: a session reads the thread and finds the answer', 5000, { label: 'Watch', run: () => (dialog.close(), openAgent(r.agent.id)) });
243
+ } else if (it.kind === 'ask' && what === 'edit') {
244
+ editing = it.id;
245
+ return render();
246
+ } else if (what === 'cancel-edit') {
247
+ editing = null;
248
+ return render();
249
+ } else if (it.kind === 'ask' && what === 'done') {
250
+ await api('POST', '/actions/set', { ids: [it.actionId], state: 'done' });
251
+ changedWith('Answered: off the list', 'answered', () => api('POST', '/actions/set', { ids: [it.actionId], state: 'open' }));
252
+ } else if (it.ship && what === 'changes') {
253
+ dialog.close();
254
+ return openChanges?.(it.agentId);
255
+ } else if (it.ship && what === 'ship') {
256
+ toast?.('Opening its pull request…', 3000);
257
+ const r = await api('POST', `/agents/${it.agentId}/ship`, {});
258
+ toast?.(r.url ? 'Pull request opened' : 'Pushed', 6000, r.url ? { label: 'Open it', run: () => window.open(r.url, '_blank', 'noopener') } : undefined);
259
+ } else if (it.ship && what === 'send-back') {
260
+ replying = replying === it.id ? null : it.id;
261
+ render();
262
+ return body.querySelector(`[data-today-text="${CSS.escape(it.id)}"]`)?.focus();
263
+ } else if (it.kind === 'action' && ['done', 'skip'].includes(what)) {
182
264
  const r = await api('POST', '/actions/set', { ids: [it.actionId], state: what });
183
265
  if (r.failed.length) toast?.(`Not changed: ${r.failed.map((x) => x.reason).join('; ')}`, 6000);
184
266
  else changedWith(what === 'done' ? 'Done' : 'Skipped', `${what === 'done' ? 'done' : 'skipped'} "${it.title}"`, () => api('POST', '/actions/set', { ids: [it.actionId], state: 'open' }));
@@ -200,6 +282,9 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
200
282
  t.setHours(9, 0, 0, 0);
201
283
  await api('POST', '/findings/set', { ids: [it.findingId], status: what === 'skip' ? 'snoozed' : 'notbug', until: what === 'skip' ? t.toISOString() : null });
202
284
  changedWith(what === 'skip' ? 'Snoozed until tomorrow 9am' : "Not a bug: it won't be reported again", what === 'skip' ? 'snoozed' : 'not a bug', () => api('POST', '/findings/set', { ids: [it.findingId], status: 'open' }));
285
+ } else if (it.kind === 'bug-pr' && what === 'done') {
286
+ await api('POST', '/findings/set', { ids: [it.findingId], status: 'done' });
287
+ changedWith('Done: off the list', 'done', () => api('POST', '/findings/set', { ids: [it.findingId], status: 'pr' }));
203
288
  } else if (it.kind === 'pr-requested' && (what === 'review' || what === 'assign')) {
204
289
  const a = await api('POST', '/reviews', { url: it.reviewUrl });
205
290
  toast?.(`Reviewer ${a.name ?? 'agent'} started`, 3000);
@@ -220,9 +305,56 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
220
305
  c: (r) => act(itemOf(r.dataset.rowId), 'discuss'),
221
306
  r: Object.assign(() => load({ fresh: true }), { needsRow: false }),
222
307
  u: Object.assign(() => takeBack(), { needsRow: false }),
308
+ z: (r) => act(itemOf(r.dataset.rowId), 'snooze'),
309
+ ...Object.fromEntries([1, 2, 3, 4, 5, 6].map((n) => [String(n), (r) => pickAt(itemOf(r.dataset.rowId), n - 1)])),
223
310
  },
224
311
  });
225
312
 
313
+ /** A choice by its place: keys 1–6 on the selected row. */
314
+ async function pickAt(it, i) {
315
+ if (!it?.answer) return;
316
+ try {
317
+ const done = await answer(it, { pick: it.answer.via === 'key' ? i : i });
318
+ if (done) toast?.(done, 3000);
319
+ } catch (e) {
320
+ toast?.(e.message, 6000);
321
+ }
322
+ load();
323
+ }
324
+
325
+ body.addEventListener('input', (e) => {
326
+ const id = e.target.dataset?.todayText;
327
+ if (id) drafts.set(id, e.target.value);
328
+ });
329
+ body.addEventListener('submit', async (e) => {
330
+ e.preventDefault();
331
+ // Done typing: the list may be drawn again.
332
+ document.activeElement?.blur?.();
333
+ const f = e.target.closest('[data-today-form]');
334
+ const ed = e.target.closest('[data-today-edit]');
335
+ try {
336
+ if (ed) {
337
+ const it = itemOf(ed.dataset.todayEdit);
338
+ await api('PUT', `/actions/${it.actionId}/answer`, { text: ed.querySelector('[data-today-edit-text]').value });
339
+ editing = null;
340
+ toast?.('Draft saved', 2000);
341
+ } else if (f) {
342
+ const it = itemOf(f.dataset.todayForm);
343
+ const text = f.querySelector('input').value.trim();
344
+ if (!it || !text) return;
345
+ if (it.answer) toast?.(await answer(it, { text }), 3000);
346
+ else if (it.ship) {
347
+ await api('POST', `/agents/${it.agentId}/tell`, { text });
348
+ replying = null;
349
+ toast?.('Sent back to the agent', 3000);
350
+ }
351
+ drafts.delete(it.id);
352
+ }
353
+ } catch (err) {
354
+ return toast?.(err.message, 6000);
355
+ }
356
+ load();
357
+ });
226
358
  body.addEventListener('toggle', (e) => {
227
359
  if (e.target.matches?.('.today-aside')) asideOpen = e.target.open;
228
360
  }, true);
@@ -239,6 +371,8 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
239
371
  }
240
372
  return load();
241
373
  }
374
+ const pick = e.target.closest('[data-today-pick]');
375
+ if (pick) return pickAt(itemOf(e.target.closest('tr[data-row-id]')?.dataset.rowId), Number(pick.dataset.todayPick));
242
376
  const b = e.target.closest('[data-today]')?.dataset.today;
243
377
  if (!b) return;
244
378
  if (b === 'close') return dialog.close();
package/src/actions.js CHANGED
@@ -2,13 +2,15 @@
2
2
  // found by the assistant on its checks and kept in one list, so nothing is missed or has to be
3
3
  // remembered. Each one has your decision on it, as for Jira issues: assign (an agent does it),
4
4
  // skip, done or remove, kept in state.json and changeable any time; Discuss opens a conversation
5
- // about it. Nothing is ever sent to Slack or anywhere else from here.
5
+ // about it. Questions put to you (or that you're CC'd on) come with an answer the assistant drafted
6
+ // from your code, Jira and docs, to edit and send yourself; Snooze hides one until a time. Nothing
7
+ // is ever sent to Slack or anywhere else from here.
6
8
 
7
9
  import crypto from 'node:crypto';
8
10
 
9
11
  export const ACTION_SOURCES = { slack: 'Slack', gemini: 'Meeting notes', other: 'Other' };
10
- export const ACTION_STATES = ['open', 'assign', 'skip', 'done', 'remove'];
11
- const GROUP = { open: 'open', assign: 'assigned', skip: 'skipped', done: 'done', remove: 'removed' };
12
+ export const ACTION_STATES = ['open', 'assign', 'skip', 'snooze', 'done', 'remove'];
13
+ const GROUP = { open: 'open', assign: 'assigned', snooze: 'snoozed', skip: 'skipped', done: 'done', remove: 'removed' };
12
14
  const MAX = 500;
13
15
  const err = (status, message) => Object.assign(new Error(message), { status });
14
16
  const clip = (s, n) => {
@@ -30,6 +32,25 @@ export function actionIntent(a) {
30
32
  .trim();
31
33
  }
32
34
 
35
+ /** What "Draft an answer" starts with: research the question, record a draft, never send it. */
36
+ export function draftPrompt(a, bin = 'agentmgr', projects = []) {
37
+ return [
38
+ `Prepare an answer for me to a question I was ${a.cc ? 'copied on' : 'asked'}. Don't send anything: I'll edit and send it myself.`,
39
+ '',
40
+ `The question: ${a.question || a.text}`,
41
+ a.from ? `Asked by: ${a.from}` : '',
42
+ a.link ? `Where: ${ACTION_SOURCES[a.source] ?? a.source}, ${a.link}` : '',
43
+ a.context ? `Context: ${a.context}` : '',
44
+ '',
45
+ 'Read the thread first (your Slack, Gmail or Google Drive tools) for the whole picture. Then find the answer from the sources: ' +
46
+ `${projects.length ? `the code in my projects (${projects.map((p) => `${p.name} at ${p.dir ?? p.repo}`).join('; ')}), ` : ''}Jira, docs and earlier messages. ` +
47
+ 'Check facts against the code or docs rather than guessing, and say how sure you are. When something can only be answered by someone else, say who and what to ask.',
48
+ `Record the draft, in my voice, short and ready to paste: ${bin} actions answer ${a.id} --sources "<links or files you used>" "<the answer>". Then tell me here what you found and anything I should check before sending.`,
49
+ ]
50
+ .filter((l) => l !== '')
51
+ .join('\n');
52
+ }
53
+
33
54
  /** What Discuss starts with: a conversation to decide what to do about the action. */
34
55
  export function discussPrompt(a, bin = 'agentmgr') {
35
56
  return [
@@ -65,7 +86,7 @@ export class MyActions {
65
86
  }
66
87
 
67
88
  /** Add one (the assistant does, on its checks). The same action from the same place is kept once. */
68
- add({ text, source = 'other', link = null, from = null, when = null, due = null, context = null, by = null } = {}) {
89
+ add({ text, source = 'other', link = null, from = null, when = null, due = null, context = null, by = null, question = null, cc = false, answer = null, sources = null } = {}) {
69
90
  const t = clip(text, 400);
70
91
  if (t.length < 3) throw err(400, 'Say what the action is');
71
92
  if (!ACTION_SOURCES[source]) throw err(400, `The source is one of ${Object.keys(ACTION_SOURCES).join(', ')}`);
@@ -84,6 +105,9 @@ export class MyActions {
84
105
  when: when && !Number.isNaN(Date.parse(when)) ? new Date(when).toISOString() : new Date().toISOString(),
85
106
  due: due ? clip(due, 40) : null,
86
107
  context: context ? clip(context, 1000) : null,
108
+ // A question put to you (cc: you're copied or mentioned, not asked): its words, and a draft answer.
109
+ ...(question || cc ? { kind: 'question', question: question ? clip(question, 1000) : t, cc: Boolean(cc) } : {}),
110
+ ...(answer ? { answer: { text: String(answer).trim().slice(0, 4000), sources: sources ? clip(sources, 600) : null, by: by ?? 'you', at: new Date().toISOString() } } : {}),
87
111
  by: by ?? null,
88
112
  status: 'open',
89
113
  at: new Date().toISOString(),
@@ -101,6 +125,7 @@ export class MyActions {
101
125
  /** The list, open ones first, newest first within: rows with their group and agents. */
102
126
  rows() {
103
127
  const order = Object.fromEntries(Object.values(GROUP).map((g, i) => [g, i]));
128
+ this.wake();
104
129
  return this.all
105
130
  .map((a) => {
106
131
  const agent = a.agentId ? this.manager.store?.get?.(a.agentId) ?? null : null;
@@ -117,6 +142,11 @@ export class MyActions {
117
142
  context: a.context,
118
143
  status: a.status,
119
144
  group: GROUP[a.status] ?? 'open',
145
+ kind: a.kind ?? 'task',
146
+ question: a.question ?? null,
147
+ cc: Boolean(a.cc),
148
+ answer: a.answer ?? null,
149
+ snoozeUntil: a.status === 'snooze' ? a.snoozeUntil ?? null : null,
120
150
  agent: agent ? { id: agent.id, name: agent.name } : null,
121
151
  discussion: talk ? { id: talk.id, name: talk.name } : null,
122
152
  updatedAt: a.updatedAt ?? a.at,
@@ -129,8 +159,10 @@ export class MyActions {
129
159
  * Your decision on actions: open (undecided again), assign (starts an agent; `project` picks
130
160
  * where), skip, done or remove. { set: [ids], started: [{ id, agent }], failed: [{ id, reason }] }.
131
161
  */
132
- set(ids = [], state, { project = null } = {}) {
162
+ set(ids = [], state, { project = null, until = null } = {}) {
133
163
  if (!ACTION_STATES.includes(state)) throw err(400, `The decision is one of ${ACTION_STATES.join(', ')}`);
164
+ const wakeAt = state === 'snooze' ? Date.parse(until ?? '') : null;
165
+ if (state === 'snooze' && !(Number.isFinite(wakeAt) && wakeAt > Date.now())) throw err(400, 'Snooze until a time to come');
134
166
  const set = [];
135
167
  const started = [];
136
168
  const failed = [];
@@ -152,6 +184,7 @@ export class MyActions {
152
184
  }
153
185
  }
154
186
  a.status = state;
187
+ a.snoozeUntil = state === 'snooze' ? new Date(wakeAt).toISOString() : null;
155
188
  a.updatedAt = new Date().toISOString();
156
189
  set.push(id);
157
190
  }
@@ -159,6 +192,44 @@ export class MyActions {
159
192
  return { set, started, failed };
160
193
  }
161
194
 
195
+ /** Snoozed ones whose time has come are open again. */
196
+ wake(t = Date.now()) {
197
+ let n = 0;
198
+ for (const a of this.all) {
199
+ if (a.status === 'snooze' && (!a.snoozeUntil || Date.parse(a.snoozeUntil) <= t)) {
200
+ a.status = 'open';
201
+ a.snoozeUntil = null;
202
+ n += 1;
203
+ }
204
+ }
205
+ if (n) this.store.save();
206
+ return n;
207
+ }
208
+
209
+ /** The draft answer to a question (the assistant's, or yours edited); empty text clears it. */
210
+ answer(id, { text, sources = null, by = 'you' } = {}) {
211
+ const a = this.find(id);
212
+ const t = String(text ?? '').trim().slice(0, 4000);
213
+ if (!t) delete a.answer;
214
+ else a.answer = { text: t, sources: sources ? clip(sources, 600) : a.answer?.sources ?? null, by, at: new Date().toISOString() };
215
+ // An answer makes it a question, if it wasn't one.
216
+ if (t && !a.kind) Object.assign(a, { kind: 'question', question: a.text, cc: false });
217
+ a.updatedAt = new Date().toISOString();
218
+ this.store.save();
219
+ return a;
220
+ }
221
+
222
+ /** A session that researches the question and records a draft answer (or the one already started). */
223
+ draft(id, bin, projects = []) {
224
+ const a = this.find(id);
225
+ const prev = a.draftId ? this.manager.store?.get?.(a.draftId) : null;
226
+ if (prev) return { agent: { id: prev.id, name: prev.name }, existing: true };
227
+ const agent = this.manager.createGeneral({ question: draftPrompt(a, bin, projects), name: `Answer: ${clip(a.question || a.text, 40)}` });
228
+ a.draftId = agent.id;
229
+ this.store.save();
230
+ return { agent: { id: agent.id, name: agent.name }, existing: false };
231
+ }
232
+
162
233
  /** A conversation about the action (a general session), or the one already started. */
163
234
  discuss(id, bin) {
164
235
  const a = this.find(id);
package/src/assistant.js CHANGED
@@ -18,7 +18,7 @@ export const SOURCES = {
18
18
  comments: 'new comments and mentions on Jira issues the person owns',
19
19
  slack: 'Slack messages to the person (direct messages and mentions) that ask for work',
20
20
  linear: 'Linear issues newly assigned to the person',
21
- actions: 'things asked of the person in Slack and in meeting notes (Notes by Gemini), for their Actions list',
21
+ actions: 'things asked of the person in Slack and in meeting notes (Notes by Gemini), and questions put to them or that they are copied on, with draft answers, for their Actions list',
22
22
  };
23
23
 
24
24
  /**
@@ -149,6 +149,10 @@ export function assistantPrompt(s, dir, bin = `node ${BIN}`, features = features
149
149
  `Find what is asked of ${who}, or what they agreed to do: in Gemini's notes, the action items and suggested next steps that name them. ` +
150
150
  `For each one, add it to their list: ${am} actions add --source <${[features.slack && 'slack', features.gemini && 'gemini'].filter(Boolean).join('|')}> --link "<the message or doc link>" --from "<who asked>" [--due "<when, if said>"] --context "<one or two sentences of background>" "<the action in one line, starting with a verb>". ` +
151
151
  `Adding the same one twice is harmless. Don't act on them, start agents for them or reply: the person decides under Actions.`,
152
+ `Questions for them: also find questions put to ${who} that are still unanswered: asked of them directly, or in a thread, email or document where they are mentioned, copied (CC) or tagged. ` +
153
+ `Add each one with its exact words: ${am} actions add --source <${[features.slack && 'slack', features.gemini && 'gemini'].filter(Boolean).join('|')}> --link "<link>" --from "<who asked>" --question "<the question, in their words>" [--cc when they are only copied or mentioned] "Answer <who>: <the question in a few words>". ` +
154
+ `Then prepare an answer they can send: read the whole thread, and find the answer in the code of their projects, Jira, docs and earlier messages, checking facts rather than guessing. ` +
155
+ `Record it, short, in their voice and ready to paste: ${am} actions answer <id> --sources "<links or files you used>" "<the answer>". When only someone else can answer, say so in the draft (who, and what to ask). Never send it yourself.`,
152
156
  );
153
157
  }
154
158
  if (s.sources.includes('slack')) {