ai-agentmanager 1.62.0 → 1.64.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.
@@ -0,0 +1,144 @@
1
+ // Autonomy on the page: how far an agent goes without you, and what was done for you meanwhile
2
+ // (questions answered from what is already decided, nudges sent, a merge made or held). An answer
3
+ // given for you shows in the inbox until you say OK or give your own.
4
+
5
+ export const LEVELS = ['ask', 'run', 'pr', 'merge'];
6
+ export const LEVEL_LABEL = { ask: 'Ask me', run: 'Agree, then run', pr: 'Run to pull request', merge: 'Run to merge' };
7
+ export const LEVEL_HINT = {
8
+ ask: 'Questions, stuck findings and follow-ups wait for you in the inbox.',
9
+ run: 'You agree on what done means. After that, its questions and its plan are decided for you when the answer is sure and easy to undo, a nudge the judge is sure of is sent, and a quiet agent is told to carry on.',
10
+ pr: 'The same, and its pull request is opened when the review approves the work.',
11
+ merge: 'The same, and the pull request is merged when its checks pass, the scorecard says ready and no high-risk path is touched.',
12
+ };
13
+ const KIND = { answer: 'Answered', left: 'Left for you', nudge: 'Nudged', followup: 'Told to carry on', plan: 'Plan decided', merge: 'Merged' };
14
+
15
+ /** Whether to say that permission prompts still stop it: past "Ask me", in a mode that asks for each one. */
16
+ export const needsPermissionHint = (level, mode) => ['run', 'pr', 'merge'].includes(level) && !['auto', 'bypassPermissions'].includes(mode || '');
17
+
18
+ export const levelOf = (a) => (LEVELS.includes(a.autonomy?.level) ? a.autonomy.level : 'ask');
19
+
20
+ /** "2 answered, 1 nudge, 1 left for you". */
21
+ export function logLine(log = []) {
22
+ const n = (k) => log.filter((e) => e.kind === k).length;
23
+ return [n('answer') ? `${n('answer')} answered` : '', n('nudge') ? `${n('nudge')} nudge${n('nudge') === 1 ? '' : 's'}` : '', n('followup') ? `${n('followup')} follow-up${n('followup') === 1 ? '' : 's'}` : '', n('merge') ? 'merged' : '', n('left') ? `${n('left')} left for you` : '']
24
+ .filter(Boolean)
25
+ .join(', ');
26
+ }
27
+
28
+ /** What was decided for you on an agent and you have not seen: inbox items. */
29
+ export function autonomyNeeds(a) {
30
+ const st = a.autonomy;
31
+ if (!st) return [];
32
+ const items = (st.log ?? []).filter((e) => e.kind === 'answer' && !e.ack).map((e) => ({ a, kind: 'auto', key: `auto:${a.id}:${e.id}`, e }));
33
+ if (st.hold && !st.hold.ack && st.level === 'merge') items.push({ a, kind: 'auto', key: `auto:${a.id}:hold`, e: { id: 'hold', kind: 'hold', ...st.hold } });
34
+ return items;
35
+ }
36
+
37
+ /** The inbox card of one such item. */
38
+ export function autoNeedHtml(it, { esc, ago }) {
39
+ const e = it.e;
40
+ if (e.kind === 'hold') {
41
+ return `<p class="need-title">Not merged: ${esc(e.note)}</p>
42
+ <p class="hint">Held ${ago(e.at)}. Its pull request stays open; merging it is yours.</p>
43
+ <div class="need-actions"><button class="small primary" data-ib="ap-review">Review changes</button><button class="small" data-ib="auto-ok" data-entry="hold">OK</button></div>`;
44
+ }
45
+ return `<p class="need-title">${esc(e.question)}</p>
46
+ <p class="auto-answer"><b>Answered for you:</b> ${esc(e.answer)}</p>
47
+ <p class="hint">${e.basis ? `From: ${esc(e.basis)} · ` : ''}${esc(e.model ?? (e.via === 'decide' ? 'Decide' : 'a model'))}, ${Math.round((e.confidence ?? 0) * 100)}% sure · ${ago(e.at)}.</p>
48
+ <div class="need-actions"><button class="small primary" data-ib="auto-ok" data-entry="${esc(e.id)}">OK</button><button class="small" data-ib="auto-change" data-entry="${esc(e.id)}" title="Give your own answer; the agent is told to apply it and undo what differs">Change answer…</button></div>`;
49
+ }
50
+
51
+ /** The row in the brief card: the level, what was done, and the way in. */
52
+ export function autonomyRow(a, esc) {
53
+ const st = a.autonomy;
54
+ if (a.team || a.reviewing || a.hunting || a.fixing || a.builds || a.raceId) return '';
55
+ if (!st || levelOf(a) === 'ask') {
56
+ return `<div class="plan-row"><button class="small ghost" data-act="auto-open" title="Let it go on without you: routine questions answered from what is already decided, nudges sent, and if you choose, its pull request opened or merged">${st?.log?.length ? 'Without you: off' : 'Run without me…'}</button></div>`;
57
+ }
58
+ const line = logLine(st.log);
59
+ const held = st.hold && !st.hold.ack && st.level === 'merge';
60
+ return `<div class="plan-row auto-row"><b>Without you</b> <span class="tag auto-on">${esc(LEVEL_LABEL[st.level])}</span>${line ? ` <span class="hint">${esc(line)}</span>` : ''}${held ? ' <span class="tag acc-bad">merge held</span>' : ''}
61
+ <button class="small" data-act="auto-open">Open</button></div>`;
62
+ }
63
+
64
+ export function initAutonomy({ dialog, api, esc, toast, ago, agentOf, upsert }) {
65
+ let id = null;
66
+
67
+ function render() {
68
+ const a = id && agentOf(id);
69
+ if (!a) return;
70
+ const st = a.autonomy ?? { level: 'ask', log: [] };
71
+ const level = levelOf(a);
72
+ dialog.querySelector('#auto-title').textContent = `Without you: ${a.name}`;
73
+ const log = (st.log ?? []).slice().reverse();
74
+ const entry = (e) => {
75
+ const head = `<b>${KIND[e.kind] ?? esc(e.kind)}</b> <span class="hint">${ago(e.at)}</span>`;
76
+ if (e.kind === 'answer') {
77
+ return `<li>${head}<div>${esc(e.question)}</div>
78
+ <div class="auto-answer">→ ${e.corrected ? `<s>${esc(e.answer)}</s> yours: ${esc(e.corrected)}` : esc(e.answer)}</div>
79
+ <div class="hint">${e.basis ? `From: ${esc(e.basis)} · ` : ''}${esc(e.model ?? (e.via === 'decide' ? 'Decide' : 'a model'))}, ${Math.round((e.confidence ?? 0) * 100)}% sure</div>
80
+ ${e.corrected ? '' : `<div class="need-actions">${e.ack ? '' : `<button type="button" class="small" data-auto="ok" data-entry="${esc(e.id)}">OK</button>`}<button type="button" class="small ghost" data-auto="change" data-entry="${esc(e.id)}">Change answer…</button></div>`}</li>`;
81
+ }
82
+ if (e.kind === 'left') return `<li>${head}<div>${esc(e.question)}</div>${e.why ? `<div class="hint">${esc(e.why)}</div>` : ''}</li>`;
83
+ return `<li>${head}<div>${esc(e.title ?? '')}</div>${e.text ? `<div class="hint">${esc(e.text)}</div>` : ''}</li>`;
84
+ };
85
+ dialog.querySelector('#auto-body').innerHTML = `
86
+ <label>How far it goes
87
+ <select data-auto="level">${LEVELS.map((l) => `<option value="${l}" ${l === level ? 'selected' : ''}>${LEVEL_LABEL[l]}</option>`).join('')}</select>
88
+ </label>
89
+ <p class="hint">${LEVEL_HINT[level]}</p>
90
+ <p class="hint">Never done for you: answering a permission prompt, or a question about deleting, publishing, money, credentials or the scope of the task.</p>
91
+ ${needsPermissionHint(level, a.permissionMode) ? '<p class="hint auto-perm">It still stops at each permission prompt, and waits for you in the inbox. To be stopped less, set its Permission mode to Auto (Edit agent; from its next launch), where Claude Code approves what it judges safe.</p>' : ''}
92
+ ${st.hold && !st.hold.ack && level === 'merge' ? `<p class="auto-hold"><b>Not merged:</b> ${esc(st.hold.note)} <button type="button" class="small" data-auto="ok" data-entry="hold">OK</button></p>` : ''}
93
+ ${log.length ? `<h4>Done for you</h4><ul class="auto-log">${log.map(entry).join('')}</ul>` : level === 'ask' ? '' : '<p class="hint">Nothing was done for you yet.</p>'}`;
94
+ }
95
+
96
+ const run = async (fn, ok) => {
97
+ try {
98
+ const a = await fn();
99
+ if (a?.id) upsert(a);
100
+ if (ok) toast(ok);
101
+ } catch (e) {
102
+ toast(`Error: ${e.message}`, 5000);
103
+ }
104
+ render();
105
+ };
106
+
107
+ /** Your own answer to a question that was answered for you. */
108
+ function change(agentId, entryId) {
109
+ const e = agentOf(agentId)?.autonomy?.log?.find((x) => x.id === entryId);
110
+ if (!e) return;
111
+ const text = prompt(`${e.question}\n\nAnswered for you: ${e.answer}\n\nYour answer:`, '');
112
+ if (!text?.trim()) return;
113
+ return run(() => api('POST', `/agents/${agentId}/autonomy/correct`, { entry: entryId, text: text.trim() }), 'Your answer was sent; the agent applies it');
114
+ }
115
+ const ok = (agentId, entryId) => run(() => api('POST', `/agents/${agentId}/autonomy/ack`, { entry: entryId }));
116
+
117
+ dialog.addEventListener('change', (e) => {
118
+ if (e.target.dataset.auto !== 'level' || !id) return;
119
+ const level = e.target.value;
120
+ run(() => api('POST', `/agents/${id}/autonomy`, { level }), level === 'ask' ? 'It asks you again' : `${LEVEL_LABEL[level]}: it goes on without you`);
121
+ });
122
+ dialog.addEventListener('click', (e) => {
123
+ const el = e.target.closest('[data-auto]');
124
+ if (!el || !id) return;
125
+ if (el.dataset.auto === 'close') return dialog.close();
126
+ if (el.dataset.auto === 'ok') return ok(id, el.dataset.entry);
127
+ if (el.dataset.auto === 'change') return change(id, el.dataset.entry);
128
+ });
129
+ dialog.addEventListener('close', () => (id = null));
130
+
131
+ return {
132
+ open(agentId) {
133
+ id = agentId;
134
+ render();
135
+ if (!dialog.open) dialog.showModal();
136
+ },
137
+ ok,
138
+ change,
139
+ /** The agent changed (a new answer, a new level): show it, unless the level menu is open. */
140
+ agentChanged(a) {
141
+ if (id === a.id && document.activeElement?.dataset?.auto !== 'level') render();
142
+ },
143
+ };
144
+ }
@@ -20,6 +20,7 @@ export function needOf(a) {
20
20
  if (a.status === 'error') return 'an error';
21
21
  if (rt.limited) return 'stopped at a limit';
22
22
  if (a.planReview?.status === 'review') return 'a plan to approve';
23
+ if (a.acceptance?.status === 'review' && a.acceptance.wait) return 'what done means, to agree';
23
24
  const q = (a.questions ?? []).filter((x) => !x.answer).length;
24
25
  if (q) return q === 1 ? 'a question' : `${q} questions`;
25
26
  if (rt.waiting) return rt.waiting.kind === 'error' ? 'an error on its screen' : 'a question on its screen';
@@ -0,0 +1,203 @@
1
+ // Drop to start: tickets, requirements, designs and files dragged onto the page (or onto the New
2
+ // agents form) fill the form in. A ticket link becomes the request (the agent is named after the
3
+ // issue and tracks it), a repository link fills the repository, requirement and design links are
4
+ // listed as context, text becomes the request, and files are attached. Nothing starts until you
5
+ // press the button: what was understood is shown first.
6
+
7
+ const IMAGE = /\.(png|jpe?g|gif|webp|svg|fig|sketch|xd|psd)(\?|#|$)/i;
8
+ const DOCUMENT = /\.(pdf|md|markdown|docx?|txt|rtf|pptx?|xlsx?|csv)(\?|#|$)/i;
9
+
10
+ /** What a link is: { kind: 'ticket' | 'repo' | 'design' | 'doc' | 'link', url, label, repo? }. */
11
+ export function classifyUrl(raw) {
12
+ let u;
13
+ try {
14
+ u = new URL(String(raw).trim());
15
+ } catch {
16
+ return null;
17
+ }
18
+ if (!/^https?:$/.test(u.protocol)) return null;
19
+ const url = u.href;
20
+ const host = u.hostname.replace(/^www\./, '').toLowerCase();
21
+ const parts = u.pathname.split('/').filter(Boolean);
22
+ const jira = u.pathname.match(/\/browse\/([A-Z][A-Z0-9_]+-\d+)/i)?.[1] ?? u.searchParams.get('selectedIssue');
23
+ if (jira && /^[A-Z][A-Z0-9_]+-\d+$/i.test(jira)) return { kind: 'ticket', url, label: jira.toUpperCase() };
24
+ if (['github.com', 'gitlab.com', 'bitbucket.org'].includes(host) && parts.length >= 2) {
25
+ const repo = `https://${host}/${parts[0]}/${parts[1].replace(/\.git$/, '')}.git`;
26
+ const issue = u.pathname.match(/\/(?:-\/)?issues\/(\d+)/);
27
+ if (issue) return { kind: 'ticket', url, label: `${parts[1]}#${issue[1]}`, repo };
28
+ if (parts.length === 2) return { kind: 'repo', url: repo, label: `${parts[0]}/${parts[1].replace(/\.git$/, '')}` };
29
+ }
30
+ if (/\.git$/.test(u.pathname)) return { kind: 'repo', url, label: parts.slice(-2).join('/').replace(/\.git$/, '') };
31
+ if (host === 'linear.app' && /\/issue\//.test(u.pathname)) return { kind: 'ticket', url, label: u.pathname.match(/\/issue\/([^/]+)/)?.[1] ?? 'issue' };
32
+ if (/(^|\.)(figma\.com|sketch\.com|zeplin\.io|miro\.com|whimsical\.com|excalidraw\.com|invisionapp\.com|framer\.com|canva\.com)$/.test(host) || IMAGE.test(u.pathname)) return { kind: 'design', url, label: host };
33
+ if (/(^|\.)(docs\.google\.com|drive\.google\.com|notion\.so|notion\.site|paper\.dropbox\.com|coda\.io|sharepoint\.com|quip\.com)$/.test(host) || /(^|\.)atlassian\.net$/.test(host) || /\/(wiki|confluence)\//.test(u.pathname) || DOCUMENT.test(u.pathname)) return { kind: 'doc', url, label: host };
34
+ return { kind: 'link', url, label: host };
35
+ }
36
+
37
+ /**
38
+ * What was dropped or pasted, sorted: `uris` (the text/uri-list of a drag) and `text` (its
39
+ * text/plain). Text that is only links counts as links; any other text is kept as the request.
40
+ * Returns { tickets, repo, designs, docs, links, text }.
41
+ */
42
+ export function readDrop({ uris = '', text = '' } = {}) {
43
+ const out = { tickets: [], repo: null, designs: [], docs: [], links: [], text: '' };
44
+ const seen = new Set();
45
+ const take = (raw) => {
46
+ const c = classifyUrl(raw);
47
+ if (!c || seen.has(c.url)) return Boolean(c);
48
+ seen.add(c.url);
49
+ if (c.kind === 'ticket') out.tickets.push(c);
50
+ else if (c.kind === 'repo') out.repo ??= c;
51
+ else out[`${c.kind}s`].push(c);
52
+ if (c.repo && !out.repo) out.repo = { kind: 'repo', url: c.repo, label: c.repo.replace(/^https:\/\/[^/]+\//, '').replace(/\.git$/, ''), implied: true };
53
+ return true;
54
+ };
55
+ for (const line of String(uris).split(/\r?\n/)) if (line.trim() && !line.startsWith('#')) take(line);
56
+ const words = String(text).trim().split(/\s+/).filter(Boolean);
57
+ if (words.length && words.every((w) => classifyUrl(w))) words.forEach(take);
58
+ else if (String(text).trim() && !seen.has(classifyUrl(String(text).trim())?.url)) out.text = String(text).trim();
59
+ return out;
60
+ }
61
+
62
+ export const isEmptyDrop = (d) => !d.tickets.length && !d.repo && !d.designs.length && !d.docs.length && !d.links.length && !d.text;
63
+
64
+ const contextLines = (d) => [...d.docs.map((x) => `- Requirements: ${x.url}`), ...d.designs.map((x) => `- Design: ${x.url}`), ...d.links.map((x) => `- Link: ${x.url}`)];
65
+
66
+ /**
67
+ * The request text after a drop. `current` is what the form holds and `split` its mode ("lines":
68
+ * one agent per line; "one": the whole text is one request). Several tickets become one line each;
69
+ * one ticket (or none) with context becomes one request with the context listed under it.
70
+ * Returns { text, split }.
71
+ */
72
+ export function composeIntents(current, d, split = 'lines') {
73
+ const cur = String(current ?? '').replace(/\s+$/, '');
74
+ const ctx = contextLines(d);
75
+ const flat = [...d.docs, ...d.designs, ...d.links].map((x) => x.url).join(' ');
76
+ // Lines that are each their own agent stay that way: context rides on the ticket's line.
77
+ if (d.tickets.length > 1 || (cur && split === 'lines')) {
78
+ const lines = d.tickets.map((t) => `${t.url}${flat ? ` (context: ${flat})` : ''}`);
79
+ if (!lines.length && (flat || d.text)) lines.push([d.text.replace(/\s*\n\s*/g, ' '), flat ? `(context: ${flat})` : ''].filter(Boolean).join(' '));
80
+ else if (d.text) lines.push(d.text.replace(/\s*\n\s*/g, ' '));
81
+ return { text: [cur, ...lines].filter(Boolean).join('\n'), split: 'lines' };
82
+ }
83
+ const whole = Boolean(ctx.length || /\n/.test(d.text) || (d.tickets.length && d.text) || split === 'one');
84
+ const body = [d.tickets[0]?.url, d.text, ctx.length ? `Context:\n${ctx.join('\n')}` : ''].filter(Boolean).join('\n\n');
85
+ return { text: [cur, body].filter(Boolean).join('\n\n'), split: whole ? 'one' : split };
86
+ }
87
+
88
+ /** "2 tickets, 1 requirements link, 1 design, the repository, 2 files". */
89
+ export function dropSummary(d, files = 0) {
90
+ const n = (k, one, many) => (k ? `${k} ${k === 1 ? one : many}` : '');
91
+ return [n(d.tickets.length, 'ticket', 'tickets'), n(d.docs.length, 'requirements link', 'requirements links'), n(d.designs.length, 'design', 'designs'), n(d.links.length, 'link', 'links'), d.repo ? 'the repository' : '', d.text ? 'the text' : '', n(files, 'file', 'files')].filter(Boolean).join(', ');
92
+ }
93
+
94
+ const has = (e, type) => [...(e.dataTransfer?.types ?? [])].includes(type);
95
+ const droppable = (e) => has(e, 'Files') || has(e, 'text/uri-list') || has(e, 'text/plain');
96
+
97
+ /**
98
+ * `form`: the New agents form (fields intents, split, repo, dir). `zone`: the box inside it.
99
+ * `overlay`: the page-wide "drop to start" frame. `attach.add(files)` attaches files. `open()`
100
+ * opens the form; `isOpen()` says whether it is. `sync()` after the text or the mode changed.
101
+ */
102
+ export function initDropZone({ form, zone, overlay, attach, open, isOpen, sync, toast }) {
103
+ const added = zone.querySelector('.drop-added');
104
+ let internal = false; // a drag that started on this page (reordering agents, moving text) is not ours
105
+
106
+ function apply(d, files = []) {
107
+ if (isEmptyDrop(d) && !files.length) return false;
108
+ if (!isEmptyDrop(d)) {
109
+ const next = composeIntents(form.intents.value, d, form.split.value);
110
+ form.intents.value = next.text;
111
+ if (next.split !== form.split.value) form.split.value = next.split;
112
+ if (d.repo && !form.repo.value.trim() && !form.dir.value.trim() && !form.project?.value.trim()) form.repo.value = d.repo.url;
113
+ }
114
+ if (files.length) attach.add(files);
115
+ sync();
116
+ const what = dropSummary(d, files.length);
117
+ added.textContent = what ? `Added: ${what}. Check the request below, then start.` : '';
118
+ zone.classList.toggle('filled', Boolean(what));
119
+ return true;
120
+ }
121
+
122
+ const take = (e) => {
123
+ const files = [...(e.dataTransfer?.files ?? [])];
124
+ // A picture dragged from a web page comes as a file and as its link: the file is enough.
125
+ const d = files.length ? readDrop({}) : readDrop({ uris: e.dataTransfer?.getData('text/uri-list') ?? '', text: e.dataTransfer?.getData('text/plain') ?? '' });
126
+ return { d, files };
127
+ };
128
+
129
+ document.addEventListener('dragstart', () => (internal = true));
130
+ document.addEventListener('dragend', () => (internal = false));
131
+ // A drag whose element was redrawn under it ends without "dragend": the next press starts clean.
132
+ document.addEventListener('pointerdown', () => (internal = false), true);
133
+
134
+ // On the form: links and text (files are taken by the attachments box, which listens there too).
135
+ form.addEventListener('dragover', (e) => {
136
+ if (internal || !droppable(e)) return;
137
+ e.preventDefault();
138
+ zone.classList.add('over');
139
+ });
140
+ form.addEventListener('dragleave', (e) => {
141
+ if (!form.contains(e.relatedTarget)) zone.classList.remove('over');
142
+ });
143
+ form.addEventListener('drop', (e) => {
144
+ zone.classList.remove('over');
145
+ if (internal) return;
146
+ const { d, files } = take(e);
147
+ if (files.length) {
148
+ // The attachments box adds them; here only the summary.
149
+ added.textContent = `Added: ${dropSummary(d, files.length)}. Check the request below, then start.`;
150
+ zone.classList.add('filled');
151
+ return;
152
+ }
153
+ if (isEmptyDrop(d)) return;
154
+ e.preventDefault();
155
+ apply(d);
156
+ });
157
+
158
+ // Anywhere on the page, when nothing else takes the drop and no dialog is open: start a new agent.
159
+ const busy = () => internal || Boolean(document.querySelector('dialog[open]'));
160
+ const hide = () => (overlay.hidden = true);
161
+ document.addEventListener('dragover', (e) => {
162
+ if (busy() || e.defaultPrevented || !droppable(e)) return hide();
163
+ e.preventDefault();
164
+ e.dataTransfer.dropEffect = 'copy';
165
+ overlay.hidden = false;
166
+ });
167
+ document.addEventListener('dragleave', (e) => {
168
+ if (!e.relatedTarget) hide();
169
+ });
170
+ document.addEventListener('drop', (e) => {
171
+ const shown = !overlay.hidden;
172
+ hide();
173
+ if (!shown || busy() || e.defaultPrevented) return;
174
+ const { d, files } = take(e);
175
+ if (isEmptyDrop(d) && !files.length) return;
176
+ e.preventDefault();
177
+ if (!isOpen()) open();
178
+ apply(d, files);
179
+ });
180
+
181
+ // Without a mouse (a phone): paste what was copied, or pick files.
182
+ zone.addEventListener('click', async (e) => {
183
+ const act = e.target.closest('[data-drop-act]')?.dataset.dropAct;
184
+ if (act === 'pick') return attach.pick();
185
+ if (act !== 'paste') return;
186
+ try {
187
+ const text = await navigator.clipboard.readText();
188
+ if (!apply(readDrop({ text }))) toast('Nothing to paste: copy a ticket or document link first', 4000);
189
+ } catch {
190
+ toast('The browser did not allow reading the clipboard: paste into the text box instead', 5000);
191
+ }
192
+ });
193
+ if (!navigator.clipboard?.readText) zone.querySelector('[data-drop-act="paste"]')?.remove();
194
+
195
+ return {
196
+ apply,
197
+ /** A new form: nothing added yet. */
198
+ reset() {
199
+ added.textContent = '';
200
+ zone.classList.remove('filled', 'over');
201
+ },
202
+ };
203
+ }
package/public/groups.js CHANGED
@@ -7,6 +7,7 @@
7
7
  // The layout and what each group shows are kept per browser.
8
8
 
9
9
  import { termFont } from '/termfont.js';
10
+ import { touchScroll } from '/touchscroll.js';
10
11
 
11
12
  const SAVED = 'agentmgr.groups';
12
13
  const MAX_GROUPS = 6;
@@ -157,6 +158,7 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
157
158
  if (!p.el.isConnected) return;
158
159
  if (!p.opened) {
159
160
  p.xterm.open(p.el.querySelector('.gterm'));
161
+ touchScroll(p.el.querySelector('.gterm'), p.xterm);
160
162
  p.opened = true;
161
163
  }
162
164
  p.failed = false;
package/public/index.html CHANGED
@@ -257,6 +257,13 @@
257
257
  <label class="check" title="The whole text goes to one agent: a long description, a spec, pasted notes"><input type="radio" name="split" value="one" /> One agent for all of it</label>
258
258
  <span class="spacer"></span><span class="hint" id="intent-count"></span>
259
259
  </div>
260
+ <div id="new-drop" class="drop-zone">
261
+ <span class="drop-icon" aria-hidden="true">⤓</span>
262
+ <span class="drop-text"><b>Drop tickets, requirements and designs here</b>
263
+ <span class="hint">Jira or GitHub issue links, a PRD or design link, screenshots, documents: the form is filled in for you. <button type="button" class="link" data-drop-act="paste">Paste what you copied</button> · <button type="button" class="link" data-drop-act="pick">Choose files</button></span>
264
+ <span class="drop-added" role="status"></span>
265
+ </span>
266
+ </div>
260
267
  <label>
261
268
  <span class="sr-only">Intents</span>
262
269
  <textarea name="intents" rows="6" required placeholder="Add a dark mode toggle that remembers the user's choice&#10;Make search results show up as you type&#10;Find out why the dashboard takes 5 seconds to load and speed it up&#10;Add a one-click CSV export to the reports page"></textarea>
@@ -314,6 +321,21 @@
314
321
  <input type="checkbox" name="plan" checked />
315
322
  Plan with Claude while the repo clones <span class="hint">(repo URLs only; the session moves into the repo when it's ready)</span>
316
323
  </label>
324
+ <label class="check">
325
+ <input type="checkbox" name="acceptance" />
326
+ Agree on what done means first <span class="hint">(the agent writes three to six points you can check and waits; you change them and agree, and its work is checked against them)</span>
327
+ </label>
328
+ <label>
329
+ Without you <span class="hint">how far each agent goes before it needs you; routine questions are answered from what is already decided, and each answer shows in your inbox</span>
330
+ <select name="autonomy" id="new-autonomy">
331
+ <option value="">The default</option>
332
+ <option value="ask">Ask me</option>
333
+ <option value="run">Agree, then run</option>
334
+ <option value="pr">Run to pull request</option>
335
+ <option value="merge">Run to merge</option>
336
+ </select>
337
+ </label>
338
+ <p class="hint auto-perm" id="new-autonomy-perm" hidden>It still stops at each permission prompt (running a command, reading outside the project): those are never answered for you. To be stopped less, choose Permission mode <b>Auto</b> under More options, where Claude Code approves what it judges safe. <button type="button" class="small" id="new-autonomy-auto">Use Auto</button></p>
317
339
  <label class="check">
318
340
  <input type="checkbox" name="planReview" />
319
341
  Review the implementation plan first <span class="hint">(the agent writes a plan and waits for your approval before changing anything)</span>
@@ -913,6 +935,28 @@
913
935
  </div>
914
936
  </dialog>
915
937
 
938
+ <dialog id="accept-dialog" class="update-dialog accept-dialog" aria-label="What done means">
939
+ <h2 id="acc-title">What done means</h2>
940
+ <div id="acc-body"></div>
941
+ <div class="dialog-actions" id="acc-actions"></div>
942
+ </dialog>
943
+
944
+ <div id="drop-overlay" class="drop-overlay" hidden aria-hidden="true">
945
+ <div class="drop-frame"><span class="drop-icon">⤓</span><b>Drop to start a new agent</b><span>Tickets, requirements, designs, screenshots or files: the form is filled in, and you start it.</span></div>
946
+ </div>
947
+
948
+ <dialog id="auto-dialog" class="update-dialog auto-dialog" aria-label="Without you">
949
+ <h2 id="auto-title">Without you</h2>
950
+ <div id="auto-body"></div>
951
+ <div class="dialog-actions"><button type="button" class="small primary" data-auto="close">Close</button></div>
952
+ </dialog>
953
+
954
+ <dialog id="proof-dialog" class="update-dialog proof-dialog" aria-label="Proof">
955
+ <h2 id="proof-title">Proof</h2>
956
+ <div id="proof-body"></div>
957
+ <div class="dialog-actions"><button type="button" class="small" data-proof="run" hidden>Run again here</button><span class="spacer"></span><button type="button" class="small primary" data-proof="close">Close</button></div>
958
+ </dialog>
959
+
916
960
  <dialog id="update-dialog" class="update-dialog" aria-label="Update">
917
961
  <h2 id="update-title">Update</h2>
918
962
  <div id="update-body"></div>
@@ -978,6 +1022,25 @@
978
1022
  <label class="check"><input type="checkbox" name="judgeOn" /> AI judge: checks stuck agents, idle screens, finished work, overlaps, backlog order and alerts</label>
979
1023
  <p class="hint">On your own Claude or Codex plan; without it, fixed rules only. <span id="settings-judge-state"></span></p>
980
1024
  </fieldset>
1025
+ <fieldset id="settings-ground">
1026
+ <legend>Ground rules</legend>
1027
+ <p class="hint">Your own rules for every agent, in every repository, one per line. Agents get them with their instructions, next to what is in the repository's memory and its standards, and are told to stop and say so when a task cannot be done without breaking one.</p>
1028
+ <textarea name="groundRules" rows="5" placeholder="Ask before adding a dependency&#10;Never force-push or rewrite history&#10;Say how sure you are of anything you build, and why" aria-label="Ground rules, one per line"></textarea>
1029
+ <label class="check"><input type="checkbox" name="groundTell" /> Also tell the agents running now <span class="hint">(others get them when they start)</span></label>
1030
+ </fieldset>
1031
+ <fieldset id="settings-autonomy">
1032
+ <legend>Without you</legend>
1033
+ <label>New agents
1034
+ <select name="autoLevel">
1035
+ <option value="ask">Ask me</option>
1036
+ <option value="run">Agree, then run</option>
1037
+ <option value="pr">Run to pull request</option>
1038
+ <option value="merge">Run to merge</option>
1039
+ </select>
1040
+ </label>
1041
+ <label>Models, best first <input name="autoModels" placeholder="fable, opus, sonnet" autocomplete="off" autocapitalize="off" spellcheck="false" /></label>
1042
+ <p class="hint">How far an agent goes when you name no level. Past "Ask me", routine questions are answered from what is already decided (your request, the agreed points, your ground rules, the repository's lessons), nudges are sent and quiet agents told to carry on. The first model answers; the next one is used when a call fails. Never answered for you: permission prompts, and questions about deleting, publishing, money, credentials or scope. <span id="settings-autonomy-state"></span></p>
1043
+ </fieldset>
981
1044
  <fieldset class="local-only" id="settings-service">
982
1045
  <legend>Start at login</legend>
983
1046
  <label class="check"><input type="checkbox" name="startAtLogin" /> Start AI Agent Manager when I log in</label>
package/public/machine.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { openStream } from '/transport.js';
5
5
  import { openCopy, pasteInto } from '/termclip.js';
6
6
  import { termFont } from '/termfont.js';
7
+ import { touchScroll } from '/touchscroll.js';
7
8
 
8
9
  const MACHINE = '__machine__';
9
10
 
@@ -22,6 +23,7 @@ export function initMachine({ api, esc, toast, $, Terminal, FitAddon }) {
22
23
  fit = new FitAddon();
23
24
  xterm.loadAddon(fit);
24
25
  xterm.open($('#machine-term'));
26
+ touchScroll($('#machine-term'), xterm);
25
27
  // Answers xterm gives to queries in the replayed backlog are stale; don't send them as typing.
26
28
  xterm.onData((d) => !replaying && conn?.send({ t: 'i', d }));
27
29
  xterm.onResize(({ cols, rows }) => conn?.send({ t: 'r', cols, rows }));
package/public/menu.js CHANGED
@@ -61,6 +61,9 @@ export function initMenu({ api, esc, toast, $ }) {
61
61
  let features = null; // what you use, and who you are, as the dialog opened
62
62
  let rounds = null; // review rounds as the dialog opened
63
63
  let judge = null; // the AI judge as the dialog opened
64
+ let ground = null; // your ground rules as the dialog opened
65
+ let autonomy = null; // the autonomy settings as the dialog opened
66
+ const modelList = (a) => (a?.models ?? []).map((m) => (typeof m === 'string' ? m : m.model)).join(', ');
64
67
  const FEATURE_KEYS = ['jira', 'slack', 'gemini'];
65
68
  function showContainers() {
66
69
  const c = containers;
@@ -118,6 +121,15 @@ export function initMenu({ api, esc, toast, $ }) {
118
121
  form.judgeOn.closest('label').hidden = !judge;
119
122
  form.judgeOn.checked = Boolean(judge?.enabled);
120
123
  $('#settings-judge-state').textContent = judge?.enabled ? `${judge.calls} of ${judge.cap} calls today.` : '';
124
+ ground = await api('GET', '/ground-rules').catch(() => null);
125
+ $('#settings-ground').hidden = !ground;
126
+ form.groundRules.value = ground?.text ?? '';
127
+ form.groundTell.checked = false;
128
+ autonomy = await api('GET', '/autonomy').catch(() => null);
129
+ $('#settings-autonomy').hidden = !autonomy;
130
+ form.autoLevel.value = autonomy?.level ?? 'ask';
131
+ form.autoModels.value = modelList(autonomy);
132
+ $('#settings-autonomy-state').textContent = autonomy ? `${autonomy.agents} agent${autonomy.agents === 1 ? '' : 's'} running without you now; ${autonomy.calls} of ${autonomy.dailyCalls} calls today${autonomy.lastModel ? `, last answered by ${autonomy.lastModel}` : ''}.` : '';
121
133
  const u = await api('GET', '/update').catch(() => null);
122
134
  form.updateCheck.checked = u?.check !== false;
123
135
  if (!remote()) {
@@ -209,6 +221,14 @@ export function initMenu({ api, esc, toast, $ }) {
209
221
  if (Object.keys(changed).length) rounds = await api('PUT', '/prereview', changed);
210
222
  }
211
223
  if (judge && form.judgeOn.checked !== Boolean(judge.enabled)) judge = await api('PUT', '/judge', { enabled: form.judgeOn.checked });
224
+ if (ground && form.groundRules.value.trim() !== ground.text.trim()) {
225
+ const g = await api('PUT', '/ground-rules', { text: form.groundRules.value, tell: form.groundTell.checked });
226
+ toast(`${g.rules.length} ground rule${g.rules.length === 1 ? '' : 's'}: agents get them when they start${g.told ? `, and ${g.told} running now ${g.told === 1 ? 'was' : 'were'} told` : ''}`, 5000);
227
+ }
228
+ if (autonomy) {
229
+ const want = { ...(form.autoLevel.value !== autonomy.level ? { level: form.autoLevel.value } : {}), ...(form.autoModels.value.trim() && form.autoModels.value.trim() !== modelList(autonomy) ? { models: form.autoModels.value } : {}) };
230
+ if (Object.keys(want).length) autonomy = await api('PUT', '/autonomy', want);
231
+ }
212
232
  document.dispatchEvent(new CustomEvent('agentmgr:review-settings'));
213
233
  if (!remote() && jira && (form.jiraSite.value.trim() !== (jira.site ?? '') || form.jiraEmail.value.trim() !== (jira.email ?? '') || form.jiraToken.value.trim())) {
214
234
  const j = await api('PUT', '/jira', { site: form.jiraSite.value.trim(), email: form.jiraEmail.value.trim(), token: form.jiraToken.value.trim() || undefined });
@@ -0,0 +1,114 @@
1
+ // Proof on the page: what the agent recorded of its checks (the command, its exit code, the last
2
+ // lines of output), what it says it did not do, and the commands run again here when you ask.
3
+
4
+ /** "3 recorded runs, 1 by reading" for the results card. */
5
+ export function proofLine(doc) {
6
+ if (!doc?.entries) return '';
7
+ return `${doc.commands} recorded run${doc.commands === 1 ? '' : 's'}${doc.entries > doc.commands ? `, ${doc.entries - doc.commands} by reading` : ''}`;
8
+ }
9
+
10
+ /** The last run by the app, when it still speaks for the proof as it is now. */
11
+ export function rerunOf(a) {
12
+ const r = a.proof;
13
+ if (!r?.results?.length || r.proofAt !== (a.proofDoc?.updatedAt ?? null)) return null;
14
+ const n = (s) => r.results.filter((x) => x.status === s).length;
15
+ return { at: r.at, same: n('same'), differs: n('differs'), skipped: n('skipped') };
16
+ }
17
+
18
+ /** The rows in the results card: what was left out, and the proof with the way in. */
19
+ export function proofRows(a, esc) {
20
+ const r = a.results;
21
+ if (!r?.fromAgent) return '';
22
+ const finished = ['done', 'partial'].includes(r.outcome);
23
+ const passed = (a.brief?.checks ?? []).filter((c) => c.state === 'passed').length;
24
+ const doc = a.proofDoc;
25
+ const rr = rerunOf(a);
26
+ const notDone = r.notDone?.length
27
+ ? `<div class="not-done"><b>Not done, as the agent says</b><ul>${r.notDone.map((t) => `<li>${esc(t)}</li>`).join('')}</ul></div>`
28
+ : finished && !r.notDoneSaid
29
+ ? '<p class="hint not-done-none">The agent has not said what it left out.</p>'
30
+ : '';
31
+ const proof = doc?.entries
32
+ ? `<p class="proof-row"><b>Proof</b> <span class="hint">${esc(proofLine(doc))}</span>${rr ? ` <span class="tag ${rr.differs ? 'proof-bad' : 'proof-ok'}" title="The recorded commands, run again on this computer">${rr.differs ? `${rr.differs} different when run again` : `${rr.same} same when run again`}</span>` : ''} <button class="small" data-act="proof-open">Open</button></p>`
33
+ : finished && passed
34
+ ? `<p class="hint proof-row">No proof recorded for its ${passed} passed check${passed === 1 ? '' : 's'}: they are its word.</p>`
35
+ : '';
36
+ return notDone + proof;
37
+ }
38
+
39
+ export function initProof({ dialog, api, esc, toast, ago, agentOf }) {
40
+ let id = null;
41
+ let view = null;
42
+ let stamp = '';
43
+ const stampOf = (a) => `${a.proofDoc?.updatedAt ?? ''}|${a.proof?.at ?? ''}`;
44
+
45
+ function render() {
46
+ const a = id && agentOf(id);
47
+ if (!a || !view) return;
48
+ dialog.querySelector('#proof-title').textContent = `Proof: ${a.name}`;
49
+ const mark = { same: ['proof-ok', 'Same result'], differs: ['proof-bad', 'Different result'], skipped: ['', 'Not run again'] };
50
+ const entry = (e) => `<li>
51
+ <div class="proof-title">${esc(e.title)}${e.rerun ? ` <span class="tag ${mark[e.rerun.status][0]}">${mark[e.rerun.status][1]}</span>` : ''}</div>
52
+ ${e.command ? `<code class="proof-cmd">${esc(e.command)}</code>${e.exit === null ? '' : ` <span class="hint">exit ${e.exit}</span>`}` : `<span class="hint">Verified by reading${e.note ? `: ${esc(e.note)}` : ''}</span>`}
53
+ ${e.output ? `<pre class="proof-out">${esc(e.output)}</pre>` : ''}
54
+ ${e.rerun?.status === 'differs' ? `<p class="hint">Run again: exit ${e.rerun.code ?? 'none (stopped)'}${e.rerun.output === 'differs' ? ', and its last recorded line was not printed' : ''}</p><pre class="proof-out bad">${esc(e.rerun.tail ?? '')}</pre>` : ''}
55
+ ${e.rerun?.status === 'same' && e.rerun.output === 'differs' ? '<p class="hint">The same exit code; its last recorded line was not printed this time (durations and dates differ between runs).</p>' : ''}
56
+ ${e.command && !e.runnable ? `<p class="hint">Not run again by the app: ${esc(e.why)}.</p>` : ''}
57
+ </li>`;
58
+ const n = view.entries.filter((e) => e.runnable).length;
59
+ dialog.querySelector('#proof-body').innerHTML = `
60
+ <p class="hint">The agent's own record of what it ran. ${view.passed ? `Its brief ticks ${view.passed} check${view.passed === 1 ? '' : 's'} as passed; ` : ''}${view.counts.commands} ${view.counts.commands === 1 ? 'has' : 'have'} a command and output here.</p>
61
+ ${view.notDone.length ? `<div class="not-done"><b>Not done, as the agent says</b><ul>${view.notDone.map((t) => `<li>${esc(t)}</li>`).join('')}</ul></div>` : ''}
62
+ ${view.entries.length ? `<ul class="proof-list">${view.entries.map(entry).join('')}</ul>` : '<p class="hint">Nothing recorded yet.</p>'}
63
+ ${view.rerun ? `<p class="hint">${view.rerun.stale ? 'The last run here was before the agent changed its proof.' : `Run again here ${ago(view.rerun.at)}: ${view.rerun.same} same, ${view.rerun.differs} different${view.rerun.skipped ? `, ${view.rerun.skipped} not run` : ''}.`}</p>` : ''}
64
+ ${!view.canRun && view.counts.commands ? `<p class="hint">${esc(view.whyNot)}</p>` : ''}`;
65
+ const btn = dialog.querySelector('[data-proof="run"]');
66
+ btn.hidden = !view.canRun || !n;
67
+ btn.disabled = view.running;
68
+ btn.textContent = view.running ? 'Running…' : `Run ${n === 1 ? 'it' : `these ${n}`} again here`;
69
+ btn.title = 'Runs the commands above in the agent\'s folder on this computer, without its permission prompts. Read them first.';
70
+ }
71
+
72
+ async function load() {
73
+ stamp = stampOf(agentOf(id) ?? {});
74
+ try {
75
+ view = await api('GET', `/agents/${id}/proof`);
76
+ } catch (e) {
77
+ toast(`Error: ${e.message}`, 5000);
78
+ }
79
+ render();
80
+ }
81
+
82
+ dialog.addEventListener('click', async (e) => {
83
+ const act = e.target.closest('[data-proof]')?.dataset.proof;
84
+ if (act === 'close') return dialog.close();
85
+ if (act !== 'run' || !id || !view) return;
86
+ view.running = true;
87
+ render();
88
+ try {
89
+ view = await api('POST', `/agents/${id}/proof/run`);
90
+ toast(view.rerun.differs ? `${view.rerun.differs} gave a different result` : 'All gave the same result');
91
+ } catch (err) {
92
+ view.running = false;
93
+ toast(`Error: ${err.message}`, 5000);
94
+ }
95
+ render();
96
+ });
97
+ dialog.addEventListener('close', () => ((id = null), (view = null)));
98
+
99
+ return {
100
+ open(agentId) {
101
+ id = agentId;
102
+ view = null;
103
+ dialog.querySelector('#proof-title').textContent = 'Proof';
104
+ dialog.querySelector('#proof-body').innerHTML = '<p class="hint">Loading…</p>';
105
+ dialog.querySelector('[data-proof="run"]').hidden = true;
106
+ if (!dialog.open) dialog.showModal();
107
+ return load();
108
+ },
109
+ /** The agent changed its proof while the dialog is open. */
110
+ agentChanged(a) {
111
+ if (id === a.id && view && !view.running && stampOf(a) !== stamp) load();
112
+ },
113
+ };
114
+ }