ai-agentmanager 1.57.3 → 1.58.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 +12 -0
- package/README.md +33 -4
- package/docs/architecture.md +3 -1
- package/package.json +1 -1
- package/public/app.js +76 -6
- package/public/files.js +105 -0
- package/public/index.html +44 -3
- package/public/keys.js +1 -0
- package/public/palette.js +122 -0
- package/public/screen.js +231 -13
- package/public/setup.js +1 -1
- package/public/style.css +37 -0
- package/src/awake.js +75 -0
- package/src/cli.js +33 -2
- package/src/files.js +80 -0
- package/src/notify.js +77 -7
- package/src/screen.js +60 -3
- package/src/server.js +62 -11
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Go to: one box that finds a view, an agent or a setting by name, instead of looking for its
|
|
2
|
+
// button (on a phone most of them are in the More menu) or remembering its key. Ctrl+K or ⌘K.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The items that match what was typed, best first: every word must be in the name or its
|
|
6
|
+
* description; a name that starts with it comes before one that contains it, and that before a
|
|
7
|
+
* match in the description only. With nothing typed, all of them in their own order.
|
|
8
|
+
*/
|
|
9
|
+
export function findMatches(items, query) {
|
|
10
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
11
|
+
if (!words.length) return items;
|
|
12
|
+
const q = words.join(' ');
|
|
13
|
+
return items
|
|
14
|
+
.map((item, at) => {
|
|
15
|
+
const label = item.label.toLowerCase();
|
|
16
|
+
const all = `${label} ${(item.hint ?? '').toLowerCase()}`;
|
|
17
|
+
if (!words.every((w) => all.includes(w))) return null;
|
|
18
|
+
const rank = label.startsWith(q) ? 0 : label.split(/[\s/:-]+/).some((part) => part.startsWith(words[0])) ? 1 : words.every((w) => label.includes(w)) ? 2 : 3;
|
|
19
|
+
return { item, rank, at };
|
|
20
|
+
})
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.sort((a, b) => a.rank - b.rank || a.at - b.at)
|
|
23
|
+
.map((m) => m.item);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const MAX = 60;
|
|
27
|
+
|
|
28
|
+
export function initPalette({ $, esc, agents, select }) {
|
|
29
|
+
const dialog = document.createElement('dialog');
|
|
30
|
+
dialog.id = 'go-dialog';
|
|
31
|
+
dialog.className = 'go-dialog';
|
|
32
|
+
dialog.innerHTML = `<input id="go-input" type="search" placeholder="Go to a view, an agent or a setting…" aria-label="Go to" aria-controls="go-list" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false" />
|
|
33
|
+
<ul id="go-list" class="go-list" role="listbox"></ul>
|
|
34
|
+
<p id="go-none" class="hint" hidden>Nothing by that name.</p>`;
|
|
35
|
+
document.body.appendChild(dialog);
|
|
36
|
+
const input = dialog.querySelector('#go-input');
|
|
37
|
+
const list = dialog.querySelector('#go-list');
|
|
38
|
+
let shown = [];
|
|
39
|
+
let at = 0;
|
|
40
|
+
|
|
41
|
+
/** A button as an item: its own words as the name, its tooltip as the description. */
|
|
42
|
+
function ofButton(b, kind) {
|
|
43
|
+
if (b.hidden || getComputedStyle(b).display === 'none') return null;
|
|
44
|
+
const label = [...b.childNodes].filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent).join(' ').replace(/[…▾]/g, '').replace(/^\+\s*/, '').trim();
|
|
45
|
+
if (!label) return null;
|
|
46
|
+
const count = b.querySelector('.badge')?.textContent.trim();
|
|
47
|
+
return { label, hint: b.title || '', kind, count, run: () => b.click() };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function collect() {
|
|
51
|
+
const views = [...document.querySelectorAll('#top-nav button:not(#top-more-btn), #new-btn')].map((b) => ofButton(b, 'View'));
|
|
52
|
+
const tabs = [...document.querySelectorAll('.side-tab')].map((b) => ofButton(b, 'List'));
|
|
53
|
+
const menu = [...document.querySelectorAll('#menu [role="menuitem"]')].map((b) => ofButton(b, 'Menu'));
|
|
54
|
+
const mine = agents().map((a) => ({ label: a.label, hint: a.hint, kind: 'Agent', run: () => select(a.id) }));
|
|
55
|
+
return [...views, ...tabs, ...menu, ...mine].filter(Boolean);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let items = [];
|
|
59
|
+
function render() {
|
|
60
|
+
shown = findMatches(items, input.value).slice(0, MAX);
|
|
61
|
+
at = Math.max(0, Math.min(at, shown.length - 1));
|
|
62
|
+
list.innerHTML = shown
|
|
63
|
+
.map((it, i) => `<li role="option" data-go="${i}" aria-selected="${i === at}"${i === at ? ' class="sel"' : ''}><span class="go-name">${esc(it.label)}${it.count ? ` <span class="badge">${esc(it.count)}</span>` : ''}</span><span class="go-hint">${esc(it.hint)}</span><span class="go-kind">${it.kind}</span></li>`)
|
|
64
|
+
.join('');
|
|
65
|
+
dialog.querySelector('#go-none').hidden = shown.length > 0;
|
|
66
|
+
list.querySelector('.sel')?.scrollIntoView({ block: 'nearest' });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function open() {
|
|
70
|
+
if (dialog.open) return dialog.close();
|
|
71
|
+
// Under another dialog it could not be used; that dialog has the page.
|
|
72
|
+
if (document.querySelector('dialog[open]')) return false;
|
|
73
|
+
items = collect();
|
|
74
|
+
input.value = '';
|
|
75
|
+
at = 0;
|
|
76
|
+
render();
|
|
77
|
+
dialog.showModal();
|
|
78
|
+
input.focus();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function go(i) {
|
|
82
|
+
const it = shown[i];
|
|
83
|
+
if (!it) return;
|
|
84
|
+
dialog.close();
|
|
85
|
+
// After the dialog is gone: what it opens may be a dialog of its own.
|
|
86
|
+
setTimeout(it.run);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
input.addEventListener('input', () => {
|
|
90
|
+
at = 0;
|
|
91
|
+
render();
|
|
92
|
+
});
|
|
93
|
+
input.addEventListener('keydown', (e) => {
|
|
94
|
+
const step = { ArrowDown: 1, ArrowUp: -1 }[e.key];
|
|
95
|
+
if (step) {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
at = (at + step + shown.length) % Math.max(1, shown.length);
|
|
98
|
+
render();
|
|
99
|
+
} else if (e.key === 'Enter') {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
go(at);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
list.addEventListener('click', (e) => {
|
|
105
|
+
const li = e.target.closest('[data-go]');
|
|
106
|
+
if (li) go(Number(li.dataset.go));
|
|
107
|
+
});
|
|
108
|
+
// A click beside the box closes it.
|
|
109
|
+
dialog.addEventListener('click', (e) => e.target === dialog && dialog.close());
|
|
110
|
+
|
|
111
|
+
// ⌘K anywhere; Ctrl+K too, except in a terminal, where it is the shell's (cut to the end of the line).
|
|
112
|
+
document.addEventListener('keydown', (e) => {
|
|
113
|
+
if (e.key.toLowerCase() !== 'k' || e.altKey || e.shiftKey || !(e.metaKey || e.ctrlKey)) return;
|
|
114
|
+
if (!e.metaKey && e.target.closest?.('.xterm')) return;
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
open();
|
|
118
|
+
}, true);
|
|
119
|
+
$('#go-btn').onclick = () => open();
|
|
120
|
+
|
|
121
|
+
return { open };
|
|
122
|
+
}
|
package/public/screen.js
CHANGED
|
@@ -122,8 +122,13 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
122
122
|
const view = $('#screen-view');
|
|
123
123
|
const state = $('#screen-state');
|
|
124
124
|
let status = null;
|
|
125
|
+
let awake = null; // whether the computer is kept from sleeping (src/awake.js)
|
|
125
126
|
let rfb = null;
|
|
126
127
|
let ended = null; // why the last connection ended
|
|
128
|
+
// While a mouse button is down noVNC lays a sheet over the page to follow the mouse, and takes
|
|
129
|
+
// it away when the button comes up on that sheet. Under this dialog the sheet never gets that,
|
|
130
|
+
// and would stay over the page after the dialog closes, taking the next click. Taken away here.
|
|
131
|
+
let release = () => {};
|
|
127
132
|
|
|
128
133
|
const remote = () => document.body.classList.contains('remote');
|
|
129
134
|
|
|
@@ -137,7 +142,7 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
137
142
|
if (!stage) return;
|
|
138
143
|
const cx = keep && view.scrollWidth ? (view.scrollLeft + view.clientWidth / 2) / view.scrollWidth : 0.5;
|
|
139
144
|
const cy = keep && view.scrollHeight ? (view.scrollTop + view.clientHeight / 2) / view.scrollHeight : 0.5;
|
|
140
|
-
if (zoom === 1) moving = false;
|
|
145
|
+
if (zoom === 1 || pad) moving = false;
|
|
141
146
|
view.classList.toggle('zoomed', zoom > 1);
|
|
142
147
|
// The outer size: scrollbars that take room must not make the screen smaller than the zoom says.
|
|
143
148
|
const w = view.offsetWidth;
|
|
@@ -149,9 +154,16 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
149
154
|
stage.querySelector('.screen-pan').hidden = !moving;
|
|
150
155
|
$('#screen-zoom-now').textContent = zoom === 1 ? 'Fit' : `${Math.round(zoom * 100)}%`;
|
|
151
156
|
const move = $('#screen-move');
|
|
152
|
-
move.hidden = zoom === 1;
|
|
157
|
+
move.hidden = zoom === 1 || pad; // as a trackpad the screen follows the pointer
|
|
153
158
|
move.setAttribute('aria-pressed', String(moving));
|
|
154
159
|
move.classList.toggle('on', moving);
|
|
160
|
+
const sheet = stage.querySelector('.screen-pad');
|
|
161
|
+
sheet.hidden = !pad;
|
|
162
|
+
stage.querySelector('.screen-pointer').hidden = !pad;
|
|
163
|
+
const padBtn = $('#screen-pad');
|
|
164
|
+
padBtn.setAttribute('aria-pressed', String(pad));
|
|
165
|
+
padBtn.classList.toggle('on', pad);
|
|
166
|
+
if (pad) point(false);
|
|
155
167
|
}
|
|
156
168
|
function setZoom(step) {
|
|
157
169
|
const at = ZOOMS.indexOf(zoom);
|
|
@@ -159,6 +171,156 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
159
171
|
layout();
|
|
160
172
|
}
|
|
161
173
|
new ResizeObserver(() => layout()).observe(view);
|
|
174
|
+
|
|
175
|
+
// Trackpad: a fingertip covers the button it aims at, so the screen can be a trackpad instead.
|
|
176
|
+
// A drag anywhere moves a pointer drawn here (slowly for a slow finger), a tap clicks where it
|
|
177
|
+
// is, two fingers scroll or, tapped, right-click, and a finger held down first drags.
|
|
178
|
+
let pad = false;
|
|
179
|
+
try {
|
|
180
|
+
pad = localStorage.getItem('screen-pad') === '1';
|
|
181
|
+
} catch {}
|
|
182
|
+
let at = null; // the pointer, in the computer's screen pixels
|
|
183
|
+
/** Where the pointer is: in the drawn screen (what noVNC counts in), in the stage and in the page. */
|
|
184
|
+
function spot() {
|
|
185
|
+
const c = stage?.querySelector('canvas');
|
|
186
|
+
if (!c?.width || !rfb?._handleMouseMove) return null;
|
|
187
|
+
at ??= { x: c.width / 2, y: c.height / 2 };
|
|
188
|
+
at.x = Math.max(0, Math.min(c.width - 1, at.x));
|
|
189
|
+
at.y = Math.max(0, Math.min(c.height - 1, at.y));
|
|
190
|
+
const r = c.getBoundingClientRect();
|
|
191
|
+
const s = stage.getBoundingClientRect();
|
|
192
|
+
// The middle of the pixel, so that it is the same pixel again when noVNC counts back.
|
|
193
|
+
const x = ((Math.floor(at.x) + 0.5) / c.width) * r.width;
|
|
194
|
+
const y = ((Math.floor(at.y) + 0.5) / c.height) * r.height;
|
|
195
|
+
return { x, y, left: r.left - s.left + x, top: r.top - s.top + y, pageX: r.left + x, pageY: r.top + y, per: c.width / (r.width || 1) };
|
|
196
|
+
}
|
|
197
|
+
/** Draw the pointer where it is, keep it in view when zoomed in, and tell the computer. */
|
|
198
|
+
function point(send = true) {
|
|
199
|
+
const p = spot();
|
|
200
|
+
if (!p) return null;
|
|
201
|
+
const arrow = stage.querySelector('.screen-pointer');
|
|
202
|
+
arrow.style.left = `${p.left}px`;
|
|
203
|
+
arrow.style.top = `${p.top}px`;
|
|
204
|
+
const edge = 36;
|
|
205
|
+
if (p.left < view.scrollLeft + edge) view.scrollLeft = p.left - edge;
|
|
206
|
+
else if (p.left > view.scrollLeft + view.clientWidth - edge) view.scrollLeft = p.left - view.clientWidth + edge;
|
|
207
|
+
if (p.top < view.scrollTop + edge) view.scrollTop = p.top - edge;
|
|
208
|
+
else if (p.top > view.scrollTop + view.clientHeight - edge) view.scrollTop = p.top - view.clientHeight + edge;
|
|
209
|
+
if (send) rfb._handleMouseMove(p.x, p.y);
|
|
210
|
+
return p;
|
|
211
|
+
}
|
|
212
|
+
/** The ring that shows the page took a tap. */
|
|
213
|
+
function ring(x, y) {
|
|
214
|
+
const el = document.createElement('div');
|
|
215
|
+
el.className = 'screen-tap';
|
|
216
|
+
el.style.left = `${x}px`;
|
|
217
|
+
el.style.top = `${y}px`;
|
|
218
|
+
dialog.append(el);
|
|
219
|
+
setTimeout(() => el.remove(), 450);
|
|
220
|
+
}
|
|
221
|
+
/** The trackpad's gestures, on the sheet that covers the screen while it is on. */
|
|
222
|
+
function trackpad(sheet, mine) {
|
|
223
|
+
const HOLD = 450; // ms a finger rests before it holds the button down
|
|
224
|
+
const STEP = 28; // px two fingers move for one notch of the wheel
|
|
225
|
+
let g = null; // the gesture under way
|
|
226
|
+
const mid = (ts) => ({ x: [...ts].reduce((n, t) => n + t.clientX, 0) / ts.length, y: [...ts].reduce((n, t) => n + t.clientY, 0) / ts.length });
|
|
227
|
+
const button = (mask) => {
|
|
228
|
+
const p = rfb === mine && spot();
|
|
229
|
+
if (p) mine._handleMouseButton(p.x, p.y, mask);
|
|
230
|
+
return p;
|
|
231
|
+
};
|
|
232
|
+
const down = () => (g?.held ? 0x1 : 0);
|
|
233
|
+
const arrow = () => stage?.querySelector('.screen-pointer');
|
|
234
|
+
sheet.addEventListener('touchstart', (e) => {
|
|
235
|
+
e.preventDefault(); // no focus change (the phone's keyboard stays open) and no made-up mouse
|
|
236
|
+
const m = mid(e.touches);
|
|
237
|
+
if (!g) {
|
|
238
|
+
g = { fingers: 0, moved: false, held: false, far: 0, sx: 0, sy: 0, since: e.timeStamp, timer: null };
|
|
239
|
+
g.timer = setTimeout(() => {
|
|
240
|
+
if (!g || g.moved || g.fingers !== 1 || !button(0x1)) return;
|
|
241
|
+
g.held = true;
|
|
242
|
+
arrow()?.classList.add('held');
|
|
243
|
+
}, HOLD);
|
|
244
|
+
}
|
|
245
|
+
g.fingers = Math.max(g.fingers, e.touches.length);
|
|
246
|
+
if (e.touches.length > 1) clearTimeout(g.timer);
|
|
247
|
+
Object.assign(g, { x: m.x, y: m.y, last: e.timeStamp });
|
|
248
|
+
}, { passive: false });
|
|
249
|
+
sheet.addEventListener('touchmove', (e) => {
|
|
250
|
+
e.preventDefault();
|
|
251
|
+
if (!g) return;
|
|
252
|
+
const m = mid(e.touches);
|
|
253
|
+
const dx = m.x - g.x;
|
|
254
|
+
const dy = m.y - g.y;
|
|
255
|
+
const ms = Math.max(1, e.timeStamp - g.last);
|
|
256
|
+
Object.assign(g, { x: m.x, y: m.y, last: e.timeStamp });
|
|
257
|
+
g.far += Math.hypot(dx, dy);
|
|
258
|
+
// A finger is never quite still: only past this is it a move, not a tap.
|
|
259
|
+
if (!g.moved && g.far < 8 && !g.held) return;
|
|
260
|
+
g.moved = true;
|
|
261
|
+
if (!g.held) clearTimeout(g.timer);
|
|
262
|
+
if (e.touches.length > 1) {
|
|
263
|
+
// As on the phone itself: what is under the fingers goes where they go.
|
|
264
|
+
g.sx += dx;
|
|
265
|
+
g.sy += dy;
|
|
266
|
+
for (const [axis, back, on] of [['sy', 0x8, 0x10], ['sx', 0x20, 0x40]]) {
|
|
267
|
+
while (Math.abs(g[axis]) >= STEP) {
|
|
268
|
+
const notch = g[axis] > 0 ? back : on;
|
|
269
|
+
g[axis] -= Math.sign(g[axis]) * STEP;
|
|
270
|
+
button(down() | notch);
|
|
271
|
+
button(down());
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const p = spot();
|
|
277
|
+
if (!p) return;
|
|
278
|
+
// A slow finger moves the pointer less than its own way, for small targets; a quick one crosses the screen.
|
|
279
|
+
const gain = p.per * Math.max(0.35, Math.min(2.5, 0.35 + 1.5 * (Math.hypot(dx, dy) / ms)));
|
|
280
|
+
at.x += dx * gain;
|
|
281
|
+
at.y += dy * gain;
|
|
282
|
+
point();
|
|
283
|
+
}, { passive: false });
|
|
284
|
+
const end = (e) => {
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
if (!g) return;
|
|
287
|
+
if (e.touches.length) {
|
|
288
|
+
// One finger of several lifted: the rest carry on from where they are.
|
|
289
|
+
const m = mid(e.touches);
|
|
290
|
+
Object.assign(g, { x: m.x, y: m.y, last: e.timeStamp });
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const was = g;
|
|
294
|
+
g = null;
|
|
295
|
+
clearTimeout(was.timer);
|
|
296
|
+
if (was.held) {
|
|
297
|
+
button(0);
|
|
298
|
+
arrow()?.classList.remove('held');
|
|
299
|
+
} else if (!was.moved && e.type === 'touchend' && e.timeStamp - was.since < HOLD) {
|
|
300
|
+
// Press and release apart, as a hand on a mouse: a Mac does not take them in one instant.
|
|
301
|
+
const p = button(was.fingers > 1 ? 0x4 : 0x1);
|
|
302
|
+
if (p) ring(p.pageX, p.pageY);
|
|
303
|
+
setTimeout(() => button(0), 100);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
sheet.addEventListener('touchend', end, { passive: false });
|
|
307
|
+
sheet.addEventListener('touchcancel', end, { passive: false });
|
|
308
|
+
}
|
|
309
|
+
function setPad(on) {
|
|
310
|
+
pad = on;
|
|
311
|
+
try {
|
|
312
|
+
localStorage.setItem('screen-pad', on ? '1' : '0');
|
|
313
|
+
} catch {}
|
|
314
|
+
layout();
|
|
315
|
+
if (on) {
|
|
316
|
+
point();
|
|
317
|
+
toast('Trackpad: drag to move the pointer, tap to click. Two fingers scroll, or tapped, right-click. Hold, then drag, to drag.', 7000);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// The button is for fingers: it shows once the page has been touched.
|
|
321
|
+
const showPad = () => ($('#screen-pad').hidden = false);
|
|
322
|
+
if (navigator.maxTouchPoints > 0 || pad) showPad(); // on already: there must be a way to turn it off
|
|
323
|
+
else dialog.addEventListener('touchstart', showPad, { once: true, passive: true, capture: true });
|
|
162
324
|
const others = (v = status?.viewers ?? []) => v.filter((x) => x.who !== 'this computer');
|
|
163
325
|
|
|
164
326
|
/** The dot on the button: someone on another device is looking at this computer's screen. */
|
|
@@ -179,12 +341,21 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
179
341
|
<p><code>${esc(m.fix)}</code></p></div>`;
|
|
180
342
|
}
|
|
181
343
|
|
|
344
|
+
/** A sleeping computer shows nothing and runs nothing: it can be kept awake, from here too. */
|
|
345
|
+
function keepAwake() {
|
|
346
|
+
if (!awake?.supported) return '';
|
|
347
|
+
const opt = (v, label) => `<option value="${v}"${awake.mode === v ? ' selected' : ''}>${label}</option>`;
|
|
348
|
+
return `<p class="screen-awake"><label>Keep this computer awake <select data-screen-awake>${opt('off', 'No')}${opt('working', 'While an agent works')}${opt('always', 'Always')}</select></label>
|
|
349
|
+
<span class="hint">${awake.mode === 'off' ? 'Asleep, it cannot be reached from here and its agents stop.' : 'It will not go to sleep by itself. The display may still sleep and lock; a closed lid still puts a laptop to sleep.'}</span></p>`;
|
|
350
|
+
}
|
|
351
|
+
|
|
182
352
|
function render() {
|
|
183
353
|
const s = status;
|
|
184
354
|
const connected = Boolean(rfb);
|
|
185
355
|
view.hidden = !connected;
|
|
186
356
|
body.hidden = connected;
|
|
187
357
|
$('#screen-keys').hidden = !connected;
|
|
358
|
+
if (!connected) showClip(false);
|
|
188
359
|
$('#screen-off').hidden = remote() || !s?.enabled;
|
|
189
360
|
if (connected || !s) return;
|
|
190
361
|
const far = others();
|
|
@@ -194,7 +365,7 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
194
365
|
body.innerHTML = `<h3>This computer's screen, here and on your phone</h3>
|
|
195
366
|
<p>See the whole screen and click or type in it: a pop-up that needs an answer, another program you want to watch.</p>
|
|
196
367
|
<p class="hint">Whoever uses this controls the whole computer, not only the agents. It is off until you turn it on, and it can only be turned on here, on the computer itself. The computer's own screen sharing still asks for its sign-in every time.</p>
|
|
197
|
-
${remote() ? '<p><b>Off.</b> Turn it on on the computer: the Screen button, or <code>agentmgr screen --on</code>.</p>' : '<p><button class="primary" data-screen="on">Turn on</button></p>'}`;
|
|
368
|
+
${remote() ? '<p><b>Off.</b> Turn it on on the computer: the Screen button, or <code>agentmgr screen --on</code>.</p>' : '<p><button class="primary" data-screen="on">Turn on</button></p>'}${keepAwake()}`;
|
|
198
369
|
return;
|
|
199
370
|
}
|
|
200
371
|
if (!s.listening) {
|
|
@@ -208,10 +379,11 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
208
379
|
state.textContent = ended ? 'Ended' : 'Ready';
|
|
209
380
|
body.innerHTML = `${ended ? `<p><b>Ended:</b> ${esc(ended)}</p>` : '<h3>Ready</h3>'}${notListed()}
|
|
210
381
|
<p class="hint">${s.platform === 'darwin' ? 'The Mac asks for your Mac user name and password next. They go to the Mac and are not kept.' : 'The computer asks for its screen sharing password next. It is not kept.'}</p>
|
|
211
|
-
<p><button class="primary" data-screen="connect">${ended ? 'Connect again' : 'Connect'}</button></p>${viewed}`;
|
|
382
|
+
<p><button class="primary" data-screen="connect">${ended ? 'Connect again' : 'Connect'}</button></p>${viewed}${keepAwake()}`;
|
|
212
383
|
}
|
|
213
384
|
|
|
214
385
|
async function refresh() {
|
|
386
|
+
awake = await api('GET', '/awake').catch(() => null);
|
|
215
387
|
try {
|
|
216
388
|
status = await api('GET', '/screen');
|
|
217
389
|
} catch (err) {
|
|
@@ -227,6 +399,7 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
227
399
|
const was = rfb;
|
|
228
400
|
rfb = null;
|
|
229
401
|
ended = reason;
|
|
402
|
+
release();
|
|
230
403
|
try {
|
|
231
404
|
was?.disconnect();
|
|
232
405
|
} catch {}
|
|
@@ -257,14 +430,16 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
257
430
|
let RFB;
|
|
258
431
|
try {
|
|
259
432
|
({ default: RFB } = await import('/vendor/novnc/core/rfb.js'));
|
|
433
|
+
({ releaseCapture: release } = await import('/vendor/novnc/core/util/events.js'));
|
|
260
434
|
} catch (err) {
|
|
261
435
|
return drop(`The viewer could not be loaded (${err.message})`);
|
|
262
436
|
}
|
|
263
437
|
stage = document.createElement('div');
|
|
264
438
|
stage.className = 'screen-stage';
|
|
265
|
-
stage.innerHTML = '<div class="screen-pan" hidden></div>';
|
|
439
|
+
stage.innerHTML = '<div class="screen-pan" hidden></div><div class="screen-pad" hidden></div><div class="screen-pointer" hidden></div>';
|
|
266
440
|
view.replaceChildren(stage);
|
|
267
441
|
zoom = 1;
|
|
442
|
+
at = null;
|
|
268
443
|
const mine = new RFB(stage, REMOTE ? new StreamChannel() : `ws://${location.host}/ws/screen`);
|
|
269
444
|
rfb = mine;
|
|
270
445
|
mine.scaleViewport = true;
|
|
@@ -285,14 +460,11 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
285
460
|
mine._handleMouseButton = button;
|
|
286
461
|
}
|
|
287
462
|
calls.forEach((args, i) => setTimeout(() => rfb === mine && button.apply(mine, args), 50 + i * 100));
|
|
288
|
-
|
|
289
|
-
ring.className = 'screen-tap';
|
|
290
|
-
ring.style.left = `${ev.detail.clientX}px`;
|
|
291
|
-
ring.style.top = `${ev.detail.clientY}px`;
|
|
292
|
-
dialog.append(ring);
|
|
293
|
-
setTimeout(() => ring.remove(), 450);
|
|
463
|
+
ring(ev.detail.clientX, ev.detail.clientY);
|
|
294
464
|
};
|
|
295
465
|
}
|
|
466
|
+
trackpad(stage.querySelector('.screen-pad'), mine);
|
|
467
|
+
stage.addEventListener('mouseup', () => setTimeout(release), true); // after noVNC has had it
|
|
296
468
|
// A mouse still gives the screen the focus, for the computer's own keyboard.
|
|
297
469
|
let touched = 0;
|
|
298
470
|
stage.addEventListener('touchstart', () => {
|
|
@@ -335,10 +507,53 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
335
507
|
});
|
|
336
508
|
|
|
337
509
|
// Typed blind on a phone, a password goes wrong easily: let it be seen.
|
|
338
|
-
dialog.addEventListener('change', (e) => {
|
|
510
|
+
dialog.addEventListener('change', async (e) => {
|
|
339
511
|
if (e.target.matches('[data-screen-show]')) e.target.form.password.type = e.target.checked ? 'text' : 'password';
|
|
512
|
+
if (e.target.matches('[data-screen-awake]')) {
|
|
513
|
+
try {
|
|
514
|
+
awake = await api('PUT', '/awake', { mode: e.target.value });
|
|
515
|
+
toast(awake.mode === 'off' ? 'This computer may go to sleep by itself again' : awake.mode === 'always' ? 'This computer is kept awake' : 'This computer is kept awake while an agent works');
|
|
516
|
+
} catch (err) {
|
|
517
|
+
toast(`Error: ${err.message}`, 6000);
|
|
518
|
+
}
|
|
519
|
+
if (!rfb) render();
|
|
520
|
+
}
|
|
340
521
|
});
|
|
341
522
|
|
|
523
|
+
// The computer's clipboard. Its screen sharing does not share it with a browser (a Mac's only
|
|
524
|
+
// with Apple's own viewer), so the daemon reads and sets it: text typed or pasted here goes
|
|
525
|
+
// there, and what was copied there comes here.
|
|
526
|
+
const clipText = $('#screen-clip-text');
|
|
527
|
+
function showClip(on) {
|
|
528
|
+
$('#screen-clip').hidden = !on;
|
|
529
|
+
$('#screen-clip-btn').setAttribute('aria-pressed', String(on));
|
|
530
|
+
$('#screen-clip-btn').classList.toggle('on', on);
|
|
531
|
+
if (on) clipText.focus();
|
|
532
|
+
}
|
|
533
|
+
async function clip(what) {
|
|
534
|
+
if (what === 'clip-get') {
|
|
535
|
+
const got = await api('GET', '/screen/clipboard');
|
|
536
|
+
clipText.value = got.text;
|
|
537
|
+
clipText.select();
|
|
538
|
+
if (!got.text) return toast("The computer's clipboard has no text");
|
|
539
|
+
// The page may put it on this device's clipboard only where the browser lets it.
|
|
540
|
+
const here = await navigator.clipboard?.writeText(got.text).then(() => true, () => false);
|
|
541
|
+
return toast(`${got.cut ? 'The first part of what' : 'What'} was copied on the computer${here ? ' is on this device\'s clipboard now' : ': copy it from the box'}`);
|
|
542
|
+
}
|
|
543
|
+
const text = clipText.value;
|
|
544
|
+
if (!text) return toast('Type or paste the text first');
|
|
545
|
+
await api('PUT', '/screen/clipboard', { text });
|
|
546
|
+
if (what === 'clip-paste' && rfb) {
|
|
547
|
+
const mod = MOD[status?.platform === 'darwin' ? 'cmd' : 'ctrl'];
|
|
548
|
+
rfb.sendKey(mod, null, true);
|
|
549
|
+
rfb.sendKey(key('v'), null);
|
|
550
|
+
rfb.sendKey(mod, null, false);
|
|
551
|
+
clipText.value = '';
|
|
552
|
+
return toast('Pasted on the computer');
|
|
553
|
+
}
|
|
554
|
+
toast("On the computer's clipboard");
|
|
555
|
+
}
|
|
556
|
+
|
|
342
557
|
dialog.addEventListener('click', async (e) => {
|
|
343
558
|
const key = e.target.closest('[data-screen-key]');
|
|
344
559
|
if (key && rfb) return rfb.sendKey(KEYS[key.dataset.screenKey], null);
|
|
@@ -359,7 +574,9 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
359
574
|
else if (what === 'move') {
|
|
360
575
|
moving = !moving;
|
|
361
576
|
layout();
|
|
362
|
-
} else if (what === '
|
|
577
|
+
} else if (what === 'pad') setPad(!pad);
|
|
578
|
+
else if (what === 'clip') showClip($('#screen-clip').hidden);
|
|
579
|
+
else if (what.startsWith('clip-')) await clip(what); else if (what === 'cancel') drop('You cancelled the sign-in');
|
|
363
580
|
else if (what === 'close') dialog.close();
|
|
364
581
|
} catch (err) {
|
|
365
582
|
toast(`Error: ${err.message}`, 6000);
|
|
@@ -421,6 +638,7 @@ export function initScreen({ api, esc, toast, $ }) {
|
|
|
421
638
|
const was = rfb;
|
|
422
639
|
rfb = null;
|
|
423
640
|
ended = null;
|
|
641
|
+
release();
|
|
424
642
|
try {
|
|
425
643
|
was?.disconnect();
|
|
426
644
|
} catch {}
|
package/public/setup.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const STEPS = [
|
|
5
5
|
['agent', 'Start your first agent', 'Give it a request and a repo or folder; it works in its own branch.', '#new-btn', 'New agents'],
|
|
6
6
|
['service', 'Start at login', 'So AI Agent Manager and your agents come back by themselves after a restart.', '#settings-btn', 'Settings'],
|
|
7
|
-
['alerts', 'Get
|
|
7
|
+
['alerts', 'Get alerts', 'Hear in Slack or on your phone when an agent needs you, is stuck or finished.', '#alerts-btn', 'Alerts'],
|
|
8
8
|
['assistant', 'Let work come to you', 'The assistant, or triggers (a GitHub label, a webhook), start agents for new work.', '#assistant-btn', 'Assistant'],
|
|
9
9
|
['remote', 'Use it from your phone', 'Answer agents from anywhere on your network.', '#remote-btn', 'Remote access'],
|
|
10
10
|
['budget', 'Set a budget', 'An alert at 80% of an agent budget, and a daily limit.', '#spend-btn', 'Results'],
|
package/public/style.css
CHANGED
|
@@ -572,6 +572,14 @@ dialog::backdrop { background: rgba(0, 0, 0, .45); }
|
|
|
572
572
|
|
|
573
573
|
.needs { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
|
|
574
574
|
.needs.inbox { margin: 8px 10px 16px; }
|
|
575
|
+
.needs.inbox.one > .need:not(.now) { display: none; }
|
|
576
|
+
/* A sideways swipe on the card is ours (the next card): not the browser's, which on Android goes back a page. */
|
|
577
|
+
.needs.inbox.one { touch-action: pan-y; }
|
|
578
|
+
.needs.inbox.one > .need.now { min-height: 40vh; }
|
|
579
|
+
.inbox-counts { align-items: center; }
|
|
580
|
+
.inbox-counts .spacer { flex: 1; }
|
|
581
|
+
.inbox-step { display: inline-flex; gap: 6px; align-items: center; }
|
|
582
|
+
.inbox-step button { min-width: 34px; font-size: 16px; }
|
|
575
583
|
.need { border: 1px solid var(--border); border-left-width: 3px; border-radius: 6px; padding: 9px 11px; background: var(--panel); font-size: 13px; }
|
|
576
584
|
.need.prompt { border-left-color: var(--red); }
|
|
577
585
|
.need.question { border-left-color: var(--accent); }
|
|
@@ -968,6 +976,15 @@ input.inline { display: inline-block; width: 80px; padding: 1px 4px; }
|
|
|
968
976
|
.screen-view.zoomed { overflow: auto; }
|
|
969
977
|
.screen-stage { position: relative; width: 100%; height: 100%; }
|
|
970
978
|
.screen-stage > div:not(.screen-pan) { touch-action: none; }
|
|
979
|
+
.screen-clip { display: flex; gap: 6px; align-items: flex-start; padding: 6px 8px; border-bottom: 1px solid #30363d; }
|
|
980
|
+
.screen-clip[hidden] { display: none; }
|
|
981
|
+
.screen-clip textarea { flex: 1; min-width: 0; font-size: 16px; background: #161a22; color: #c9d1d9; border: 1px solid #30363d; border-radius: 6px; padding: 4px 6px; resize: vertical; }
|
|
982
|
+
.screen-clip-acts { display: flex; flex-wrap: wrap; gap: 4px; max-width: 45%; }
|
|
983
|
+
.screen-awake select { margin-left: 6px; }
|
|
984
|
+
.screen-pad { position: absolute; inset: 0; z-index: 2; }
|
|
985
|
+
.screen-pointer { position: absolute; z-index: 3; width: 0; height: 0; pointer-events: none; }
|
|
986
|
+
.screen-pointer::after { content: ''; position: absolute; left: -2px; top: -1px; width: 15px; height: 22px; background: no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 22'%3E%3Cpath d='M2 1v17l4.2-4 2.9 6.6 2.6-1.1-2.9-6.5H14z' fill='%23000' stroke='%23fff' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E"); filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6)); }
|
|
987
|
+
.screen-pointer.held::after { filter: drop-shadow(0 0 4px #4c8dff) drop-shadow(0 0 2px #4c8dff); }
|
|
971
988
|
.screen-pan { position: absolute; inset: 0; z-index: 2; cursor: grab; touch-action: pan-x pan-y; }
|
|
972
989
|
.screen-dialog .term-bar { flex-wrap: wrap; row-gap: 4px; }
|
|
973
990
|
.screen-keys button.on { background: var(--accent, #4c8dff); color: #fff; }
|
|
@@ -1209,6 +1226,25 @@ body.watching .layout { display: none; }
|
|
|
1209
1226
|
}
|
|
1210
1227
|
/* ---------- keyboard shortcuts */
|
|
1211
1228
|
kbd { display: inline-block; min-width: 1.6em; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--bg); font: 11.5px var(--mono); text-align: center; line-height: 1.4; }
|
|
1229
|
+
.files-dialog { width: min(680px, calc(100vw - 16px)); height: min(720px, calc(100dvh - 16px)); max-width: none; padding: 10px; }
|
|
1230
|
+
.files-dialog[open] { display: flex; flex-direction: column; gap: 6px; }
|
|
1231
|
+
.files-head, .files-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
1232
|
+
.files-bar input:not([type]) { flex: 1; min-width: 120px; font-size: 16px; font-family: var(--mono); }
|
|
1233
|
+
.files-list { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--border); border-radius: var(--radius); }
|
|
1234
|
+
.files-row { display: flex; gap: 8px; align-items: baseline; width: 100%; padding: 9px 10px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: none; color: var(--text); text-align: left; text-decoration: none; font: inherit; cursor: pointer; }
|
|
1235
|
+
.files-row:hover { background: var(--panel-2); }
|
|
1236
|
+
.files-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
1237
|
+
.files-row .hint { flex: none; font-size: 12px; }
|
|
1238
|
+
.files-empty { padding: 12px; }
|
|
1239
|
+
.files-foot { margin: 0; }
|
|
1240
|
+
.go-dialog { width: min(600px, calc(100vw - 16px)); max-width: none; margin-top: 8vh; padding: 8px; }
|
|
1241
|
+
.go-dialog input { width: 100%; font-size: 16px; padding: 8px 10px; }
|
|
1242
|
+
.go-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: min(60vh, 520px); overflow-y: auto; overscroll-behavior: contain; }
|
|
1243
|
+
.go-list li { display: flex; gap: 8px; align-items: baseline; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
|
|
1244
|
+
.go-list li.sel, .go-list li:hover { background: var(--panel-2); }
|
|
1245
|
+
.go-name { flex: none; font-weight: 600; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1246
|
+
.go-hint { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1247
|
+
.go-kind { flex: none; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
1212
1248
|
.keys-dialog { max-width: 520px; width: calc(100% - 32px); }
|
|
1213
1249
|
.keys-dialog h4 { margin: 14px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
|
|
1214
1250
|
.keys-dialog table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
@@ -1822,3 +1858,4 @@ table.eval-items tr.eval-na td { color: var(--muted); }
|
|
|
1822
1858
|
.screen-combo { width: 74px; padding: 2px 4px; font-size: 13px; background: #161a22; color: #c9d1d9; border: 1px solid #30363d; border-radius: 6px; }
|
|
1823
1859
|
.screen-tap { position: fixed; width: 28px; height: 28px; margin: -14px 0 0 -14px; border: 2px solid #4c8dff; border-radius: 50%; pointer-events: none; z-index: 5; animation: screen-tap 0.45s ease-out forwards; }
|
|
1824
1860
|
@keyframes screen-tap { from { transform: scale(0.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
|
|
1861
|
+
@media (max-width: 800px) { .needs.inbox.one .need-actions button { padding: 10px 14px; font-size: 15px; } }
|
package/src/awake.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Awake: a sleeping computer runs no agents and cannot be reached from the phone. While this is
|
|
2
|
+
// on, the computer is kept from going to sleep by itself: always, or only while an agent works.
|
|
3
|
+
// The display may still sleep and lock, and closing a laptop's lid still puts it to sleep.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
export const AWAKE_MODES = ['off', 'working', 'always'];
|
|
8
|
+
const GRACE_MS = 5 * 60_000; // after the last agent stops working: its next turn is often minutes away
|
|
9
|
+
|
|
10
|
+
const fail = (status, message) => Object.assign(new Error(message), { status });
|
|
11
|
+
|
|
12
|
+
export const awakeSettings = (config) => ({ mode: AWAKE_MODES.includes(config.awake?.mode) ? config.awake.mode : 'off' });
|
|
13
|
+
|
|
14
|
+
/** What keeps this computer awake for as long as it runs, and ends with this process: [command, args], or null. */
|
|
15
|
+
export function keeper(platform = process.platform, exists = fs.existsSync) {
|
|
16
|
+
// -i: no idle sleep. -w: until this process is gone, so nothing is left behind.
|
|
17
|
+
if (platform === 'darwin' && exists('/usr/bin/caffeinate')) return ['/usr/bin/caffeinate', ['-i', '-w', String(process.pid)]];
|
|
18
|
+
const inhibit = ['/usr/bin/systemd-inhibit', '/bin/systemd-inhibit'].find((p) => exists(p));
|
|
19
|
+
if (platform === 'linux' && inhibit) return [inhibit, ['--what=idle:sleep', '--who=AI Agent Manager', '--why=Agents are working, or the computer is reached from a phone', 'tail', '--pid', String(process.pid), '-f', '/dev/null']];
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Awake {
|
|
24
|
+
/** `working()` says whether an agent is working now. `run` and `how` stand in for the system's in tests. */
|
|
25
|
+
constructor({ config, working = () => false, how = keeper(), run = (cmd, args) => spawn(cmd, args, { stdio: 'ignore' }), now = () => Date.now(), log = () => {}, timer = true }) {
|
|
26
|
+
Object.assign(this, { config, working, how, run, now, log });
|
|
27
|
+
this.child = null;
|
|
28
|
+
this.workedAt = 0;
|
|
29
|
+
if (timer) {
|
|
30
|
+
this.timer = setInterval(() => this.tick(), 20_000);
|
|
31
|
+
this.timer.unref();
|
|
32
|
+
}
|
|
33
|
+
this.tick();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get settings() {
|
|
37
|
+
return awakeSettings(this.config);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
status() {
|
|
41
|
+
return { ...this.settings, supported: Boolean(this.how), holding: Boolean(this.child) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
change(b = {}) {
|
|
45
|
+
if (!AWAKE_MODES.includes(b.mode)) throw fail(400, `mode is one of: ${AWAKE_MODES.join(', ')}`);
|
|
46
|
+
if (b.mode !== 'off' && !this.how) throw fail(400, 'This computer has nothing here to keep it awake with (macOS: caffeinate; Linux: systemd-inhibit)');
|
|
47
|
+
this.config.awake = { mode: b.mode };
|
|
48
|
+
this.tick();
|
|
49
|
+
return this.config.awake;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Hold the computer awake, or let go, as the mode and the agents say. */
|
|
53
|
+
tick() {
|
|
54
|
+
const { mode } = this.settings;
|
|
55
|
+
if (mode === 'working' && this.working()) this.workedAt = this.now();
|
|
56
|
+
const want = Boolean(this.how) && (mode === 'always' || (mode === 'working' && this.workedAt > 0 && this.now() - this.workedAt < GRACE_MS));
|
|
57
|
+
if (want && !this.child) {
|
|
58
|
+
const child = this.run(...this.how);
|
|
59
|
+
this.child = child;
|
|
60
|
+
child.on?.('error', () => this.child === child && (this.child = null));
|
|
61
|
+
child.on?.('exit', () => this.child === child && (this.child = null));
|
|
62
|
+
this.log('awake: keeping this computer from sleeping');
|
|
63
|
+
} else if (!want && this.child) this.stop();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
stop() {
|
|
67
|
+
const child = this.child;
|
|
68
|
+
this.child = null;
|
|
69
|
+
if (!child) return;
|
|
70
|
+
try {
|
|
71
|
+
child.kill();
|
|
72
|
+
} catch {}
|
|
73
|
+
this.log('awake: the computer may sleep again');
|
|
74
|
+
}
|
|
75
|
+
}
|