ai-agentmanager 1.56.2 → 1.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.57.1 (2026-11-18)
4
+
5
+ - **Screen: zoom.** **−** and **+** in the bar draw the screen at 150% to 400%, and the button between them goes back to **Fit**. Zoomed in, **Move** lets a drag move around the screen; with it off, a tap clicks in the computer as before.
6
+ - **Screen: show the password.** The sign-in has a **Show the password** box: typed blind on a phone, a password goes wrong easily, and the Mac only says it was refused.
7
+ - **Screen: a Mac with Remote Management on.** Such a Mac lets in only the users on its own list and refuses anyone else as if the password were wrong. When this computer's user is not on it, the Screen dialog says so before you sign in, with where to add the user and the command that does it.
8
+ - **Tried:** Screen now works past a real Mac's sign-in, from a real phone. Zoom, Move and the password box are tried in desktop Chrome only; the Remote Management note is not tried in a browser.
9
+
10
+ ## 1.57.0 (2026-11-17)
11
+
12
+ - **Screen: this computer's desktop in the page, from the phone too.** A pop-up that waits for an answer, another program you want to watch: **Screen** in the top bar shows the computer's whole screen, and your clicks, taps and typing go back to it. It works on the computer itself and on any device signed in through remote access. On a phone the bar has a **Type here** field for the keyboard, and **Esc**, **Tab** and **⏎**.
13
+ - **How.** It does not capture the screen: the computer's own screen sharing does (macOS: System Settings → General → Sharing → Screen Sharing; elsewhere a VNC server on port 5900 of `127.0.0.1`), and asks for its own sign-in every time (on a Mac, your Mac user name and password, which are not kept). AI Agent Manager relays that connection to signed-in pages and draws it with noVNC.
14
+ - **Off until you turn it on, on the computer itself.** Whoever uses it controls the whole computer, not only the agents. **Screen → Turn on** works only on the computer; a signed-in device cannot turn it on from the page. From a remote device, the **Terminal** button runs on the computer: `agentmgr screen --on` there turns it on.
15
+ - **Who is looking.** While another device views the screen, the Screen button shows a dot and names the device and its address, as does `agentmgr screen`. **Turn off** ends every view at once. The relay connects to this computer only.
16
+ - **Tried so far** against a stand-in screen sharing service in the tests, and against real macOS Screen Sharing up to its sign-in. Not yet tried: past a real Mac sign-in, on a real phone, and how fast it feels over remote access.
17
+ - **Tests:** the fakes' logs are read without parsing a line still being written, which failed a run now and then.
18
+
3
19
  ## 1.56.2 (2026-11-17)
4
20
 
5
21
  - **Terminal text size.** ☰ → **Terminal text** has A− / 13 / A+ (10 to 22 px, kept per browser). It applies to an agent's session, split-screen groups and Open Terminal; the Watch tiles keep their own size.
package/README.md CHANGED
@@ -206,6 +206,7 @@ agentmgr audit <agent> --start # security audit in its session (a
206
206
  agentmgr skills # Claude Code's skills here (look <repo>, add <repo> <names...>, check|update|rm <id>)
207
207
  agentmgr lanes # every agent's own ports and name ending (--off, --port off, --base, --size)
208
208
  agentmgr rounds [agent] # review rounds before a pull request: the settings, or an agent's rounds (--start, --again, --open, --stop)
209
+ agentmgr screen # this computer's screen in the page, from the phone too: on or off (--on, --off), who is viewing
209
210
  agentmgr models # models served on this computer (Ollama, LM Studio, llama.cpp, MLX), for --engine local
210
211
  agentmgr usage # each engine's plan limits: used, left, resets (--now, --lean on, --warn 80, --hold 95, --default codex)
211
212
  agentmgr runbook --ticket REL-42 # a support runbook from a release ticket (or --epic KEY, or --since 2026-10-01 -p <project>; -o file.md)
@@ -874,6 +875,25 @@ Or use **Remote access** in the header of the UI on this computer.
874
875
  - **Firewall.** If the macOS firewall is off, the port is open to your whole network while remote access is on. Turn it off when you don't need it.
875
876
  - **Streaming.** The phone UI streams with Server-Sent Events plus plain HTTPS requests. iOS Safari doesn't apply an accepted self-signed certificate to WebSockets.
876
877
 
878
+ ## Screen: this computer's desktop, from the phone too
879
+
880
+ A pop-up that waits for an answer, another program you want to watch: **Screen** in the top bar shows this computer's whole screen in the page, and your clicks, taps and typing go back to it. It works on the computer itself and on any device signed in through remote access.
881
+
882
+ It does not capture the screen itself. The computer's own screen sharing does, and AI Agent Manager relays that connection to signed-in pages and draws it with [noVNC](https://novnc.com):
883
+
884
+ 1. On the Mac: **System Settings → General → Sharing → Screen Sharing**, on. (On Linux: any VNC server listening on port 5900 of `127.0.0.1`.)
885
+ 2. On the computer itself: **Screen → Turn on** (or `agentmgr screen --on`).
886
+ 3. From any signed-in device: **Screen → Connect**, and sign in with your Mac user name and password when the Mac asks. They go to the Mac's screen sharing and are not kept.
887
+
888
+ On a phone, the bar has a **Type here** field for the keyboard, and **Esc**, **Tab** and **⏎**. **−** and **+** zoom in up to 400% (the button between them goes back to **Fit**); zoomed in, **Move** lets a drag move around the screen instead of clicking in it. The sign-in has **Show the password**, for a password typed on a phone.
889
+
890
+ A Mac with **Remote Management** on (instead of plain Screen Sharing) lets in only the users listed under **Sharing → Remote Management → ⓘ**, and refuses anyone else as if the password were wrong. The Screen dialog says so when this computer's user is not listed, with the command that adds it.
891
+
892
+ - **Whoever uses it controls the whole computer,** not only the agents. So it is off until you turn it on, it can be turned on only on the computer itself (not from a signed-in device), and the computer's screen sharing still asks for its own sign-in every time.
893
+ - **Who is looking:** while another device views the screen, the **Screen** button shows a dot, and its tooltip and `agentmgr screen` name the device and its address. **Turn off** ends every view at once.
894
+ - **Only this computer.** The relay connects to `127.0.0.1` and nothing else; `agentmgr screen --port <n>` picks another port there.
895
+ - **Limits:** a locked screen shows the lock screen, a sleeping computer shows nothing, and a company-managed Mac may have Screen Sharing disabled by policy. Up to 4 views at a time.
896
+
877
897
  ## Engines: Claude Code, Codex, Antigravity and Muse Code
878
898
 
879
899
  Agents run Claude Code by default. With OpenAI's Codex CLI installed (`npm i -g @openai/codex`, signed in), an agent can run Codex instead: `agentmgr add --engine codex …`, or the **Engine** picker in New agent (shown once a second engine is installed). Everything else works the same way: worktrees, the brief and questions, the inbox (Codex's approval menus included), token usage, stuck detection, PR tracking, Explain, the backlog and the hub. Codex records no cost, and planning while a repo clones and forks are Claude-only for now. Set `"engine": "codex"` in config.json to make it the default; `engines.codex.bin` points at another binary. On the hub, each machine reports the engines it has (`engine:codex`), so shared backlog work can ask for one. See [docs/engines.md](docs/engines.md).
@@ -1469,6 +1489,7 @@ State lives in `~/.agentmanager/` (`state.json`, `daemon.log`, `repos/` for shar
1469
1489
  "stuck": { "repeatFailures": 3, "thrashReverts": 2, "thrashEdits": 10, "driftMinutes": 20, "driftActions": 25 },
1470
1490
  "judge": { "enabled": true, "model": "haiku", "dailyCalls": 300 },
1471
1491
  "preReview": { "enabled": true, "rounds": 4, "critics": 2, "openPr": true },
1492
+ "screen": { "enabled": false, "port": 5900 },
1472
1493
  "cleanup": { "strategy": "close", "closeAfterDays": 14, "deleteAfterDays": 14 },
1473
1494
  "hub": { "allow": ["view"], "projects": ["*"] }
1474
1495
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.56.2",
3
+ "version": "1.57.1",
4
4
  "description": "Run background coding agents (Claude Code, Codex) per intent, and keep track of them from a web UI, your phone or the CLI",
5
5
  "keywords": [
6
6
  "claude",
@@ -48,6 +48,7 @@
48
48
  "node": ">=20"
49
49
  },
50
50
  "dependencies": {
51
+ "@novnc/novnc": "1.7.0",
51
52
  "@xterm/addon-fit": "^0.11.0",
52
53
  "@xterm/xterm": "^6.0.0",
53
54
  "commander": "^15.0.0",
package/public/app.js CHANGED
@@ -22,6 +22,7 @@ import { initPlaybooks } from '/playbooks.js';
22
22
  import { initSetup } from '/setup.js';
23
23
  import { initUpdate } from '/update.js';
24
24
  import { initMenu } from '/menu.js';
25
+ import { initScreen } from '/screen.js';
25
26
  import { initSupport } from '/support.js';
26
27
  import { initCode } from '/code.js';
27
28
  import { initMachine } from '/machine.js';
@@ -192,6 +193,7 @@ initMenu({ api, esc, toast, $ });
192
193
  const supportUi = initSupport({ api, $, esc, toast });
193
194
  $('#support-btn').onclick = () => supportUi.open();
194
195
  initMachine({ api, esc, toast, $, Terminal, FitAddon });
196
+ const screenUi = initScreen({ api, esc, toast, $ });
195
197
  let sidePane = null; // the split view's right pane (set up once the terminal is)
196
198
  const codeUi = initCode({ api, esc, toast, $, agents, isOpen: () => term.kind === 'code' || Boolean(sidePane?.showing('code')) });
197
199
  const playbooksUi = initPlaybooks({ api, esc, toast, $, select: (id) => (showTab('agents'), select(id)) });
@@ -4693,6 +4695,8 @@ function handleEvent(msg) {
4693
4695
  } else if (msg.t === 'plan') {
4694
4696
  planUi.changed();
4695
4697
  todayUi.changed();
4698
+ } else if (msg.t === 'screen') {
4699
+ screenUi.viewers(msg.viewers);
4696
4700
  } else if (msg.t === 'standup') {
4697
4701
  standupUi.set(msg.latest);
4698
4702
  if (msg.latest?.reason === 'scheduled' && msg.latest.items.length) toast('Standup ready: press Standup (or p) to play it', 8000);
package/public/index.html CHANGED
@@ -50,6 +50,7 @@
50
50
  <button id="mcp-btn" title="MCP: the MCP servers Claude Code has (yours, projects', claude.ai connectors and plugins), their tools, and running one in an agent's session or workspace">MCP</button>
51
51
  <button id="os-btn" title="OS: this computer and how loaded it is right now: processor, memory, disks, what each open agent session takes, and the busiest processes">OS</button>
52
52
  <button id="machine-btn" title="A terminal on this computer (your home folder), from any device you're signed in on">Terminal</button>
53
+ <button id="screen-btn" title="This computer's screen, to answer a pop-up or watch another program, from any device you're signed in on">Screen <span id="screen-dot" class="assistant-dot" hidden></span></button>
53
54
  <button id="ask-btn" title="A general session with no repo or folder, on Claude Code or another engine you have (Codex, Muse Code, …)">Ask Agent</button>
54
55
  <div class="menu-wrap top-more" id="top-more" hidden>
55
56
  <button id="top-more-btn" type="button" aria-haspopup="menu" aria-expanded="false">More ▾</button>
@@ -1013,6 +1014,28 @@
1013
1014
  </form>
1014
1015
  </dialog>
1015
1016
 
1017
+ <dialog id="screen-dialog" class="machine-dialog screen-dialog">
1018
+ <div class="term-bar">
1019
+ <b class="screen-title">Screen</b>
1020
+ <span id="screen-state" class="hint"></span>
1021
+ <span id="screen-name" class="hint"></span>
1022
+ <span class="spacer"></span>
1023
+ <span id="screen-keys" class="screen-keys" hidden>
1024
+ <input id="screen-type" class="screen-type" placeholder="Type here" aria-label="Type into the screen" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" />
1025
+ <button class="ghost small" data-screen-key="esc" title="Escape">Esc</button>
1026
+ <button class="ghost small" data-screen-key="tab" title="Tab">Tab</button>
1027
+ <button class="ghost small" data-screen-key="enter" title="Return">⏎</button>
1028
+ <button class="ghost small" data-screen-zoom="-1" title="Zoom out" aria-label="Zoom out">−</button>
1029
+ <button class="ghost small" id="screen-zoom-now" data-screen-zoom="0" title="Fit the whole screen">Fit</button>
1030
+ <button class="ghost small" data-screen-zoom="1" title="Zoom in" aria-label="Zoom in">+</button>
1031
+ <button class="ghost small" id="screen-move" data-screen="move" title="Drag to move around the zoomed screen instead of clicking in it" aria-pressed="false" hidden>Move</button>
1032
+ </span>
1033
+ <button id="screen-off" class="ghost small" data-screen="off" title="No device can reach this computer's screen until you turn it on again here" hidden>Turn off</button>
1034
+ <button class="ghost small" data-screen="close" title="Close (ends your connection to the screen)">Close</button>
1035
+ </div>
1036
+ <div id="screen-body" class="screen-body"></div>
1037
+ <div id="screen-view" class="screen-view" hidden></div>
1038
+ </dialog>
1016
1039
  <dialog id="machine-dialog" class="machine-dialog">
1017
1040
  <div class="term-bar">
1018
1041
  <div class="term-tabs" id="machine-tabs" role="tablist"></div>
@@ -0,0 +1,343 @@
1
+ // Screen: this computer's screen in the page, to answer a pop-up or watch another program, from
2
+ // the phone too. The computer's own screen sharing draws it and asks for its own sign-in (macOS:
3
+ // your Mac user name and password); the daemon relays the connection (src/screen.js) and noVNC
4
+ // shows it. Off until turned on, on the computer itself.
5
+ import { REMOTE, post } from '/transport.js';
6
+
7
+ const b64 = (bytes) => {
8
+ let s = '';
9
+ for (let i = 0; i < bytes.length; i += 0x8000) s += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
10
+ return btoa(s);
11
+ };
12
+ const unb64 = (text) => Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
13
+
14
+ /**
15
+ * What noVNC needs of a WebSocket, over a stream out and POSTs in: the phone has no WebSocket to
16
+ * the daemon (transport.js). What is sent goes strictly in order, one request at a time.
17
+ */
18
+ export class StreamChannel {
19
+ constructor() {
20
+ this.binaryType = 'arraybuffer';
21
+ this.protocol = '';
22
+ this.readyState = 'connecting';
23
+ this.onopen = this.onmessage = this.onclose = this.onerror = null;
24
+ this.id = null;
25
+ this.queue = [];
26
+ this.sending = false;
27
+ this.es = new EventSource('/api/screen/stream');
28
+ this.es.onmessage = (ev) => {
29
+ const msg = JSON.parse(ev.data);
30
+ if (msg.t === 'open') {
31
+ this.id = msg.id;
32
+ this.readyState = 'open';
33
+ this.onopen?.();
34
+ } else if (msg.t === 'd') this.onmessage?.({ data: unb64(msg.d).buffer });
35
+ else if (msg.t === 'end') this.finish(msg.reason);
36
+ };
37
+ // The stream does not come back by itself: a new one would be a new connection to the screen.
38
+ this.es.onerror = () => this.finish(this.id ? 'The connection was lost' : 'Screen access is off, or you are signed out');
39
+ }
40
+
41
+ send(data) {
42
+ if (this.readyState !== 'open') return;
43
+ this.queue.push(new Uint8Array(data).slice()); // noVNC reuses its buffer
44
+ this.pump();
45
+ }
46
+
47
+ async pump() {
48
+ if (this.sending) return;
49
+ this.sending = true;
50
+ while (this.queue.length && this.readyState === 'open') {
51
+ const all = new Uint8Array(this.queue.reduce((n, q) => n + q.length, 0));
52
+ let at = 0;
53
+ for (const q of this.queue.splice(0)) {
54
+ all.set(q, at);
55
+ at += q.length;
56
+ }
57
+ let ok = false;
58
+ for (let attempt = 0; attempt < 4 && !ok && this.readyState === 'open'; attempt++) {
59
+ try {
60
+ const res = await post('/api/screen/input', { id: this.id, d: b64(all) });
61
+ if (res.ok) ok = true;
62
+ else if (res.status >= 400 && res.status < 500) break; // ended or signed out: a retry won't change it
63
+ } catch {
64
+ await new Promise((r) => setTimeout(r, 200 * 2 ** attempt));
65
+ }
66
+ }
67
+ // A gap in what the screen sharing service receives can't be repaired: end it.
68
+ if (!ok) this.finish('The connection was lost');
69
+ }
70
+ this.sending = false;
71
+ }
72
+
73
+ finish(reason) {
74
+ if (this.readyState === 'closed') return;
75
+ this.readyState = 'closed';
76
+ this.es.close();
77
+ this.onclose?.({ code: 1000, reason, wasClean: true });
78
+ }
79
+
80
+ close() {
81
+ this.finish('Closed');
82
+ }
83
+ }
84
+
85
+ // Keys a phone's keyboard does not have (X11 keysyms).
86
+ const KEYS = { esc: 0xff1b, tab: 0xff09, enter: 0xff0d, back: 0xff08, up: 0xff52, down: 0xff54, left: 0xff51, right: 0xff53 };
87
+ const keysymOf = (ch) => {
88
+ const cp = ch.codePointAt(0);
89
+ if (ch === '\n') return KEYS.enter;
90
+ return cp < 0x100 ? cp : 0x01000000 + cp;
91
+ };
92
+
93
+ export function initScreen({ api, esc, toast, $ }) {
94
+ const dialog = $('#screen-dialog');
95
+ const body = $('#screen-body');
96
+ const view = $('#screen-view');
97
+ const state = $('#screen-state');
98
+ let status = null;
99
+ let rfb = null;
100
+ let ended = null; // why the last connection ended
101
+
102
+ const remote = () => document.body.classList.contains('remote');
103
+
104
+ // Zoom: the screen is drawn larger than the dialog and scrolled. A finger on it clicks in the
105
+ // computer, so moving around is its own mode (Move), which puts a sheet over the screen.
106
+ const ZOOMS = [1, 1.5, 2, 3, 4];
107
+ let zoom = 1;
108
+ let moving = false;
109
+ let stage = null;
110
+ function layout(keep = true) {
111
+ if (!stage) return;
112
+ const cx = keep && view.scrollWidth ? (view.scrollLeft + view.clientWidth / 2) / view.scrollWidth : 0.5;
113
+ const cy = keep && view.scrollHeight ? (view.scrollTop + view.clientHeight / 2) / view.scrollHeight : 0.5;
114
+ if (zoom === 1) moving = false;
115
+ view.classList.toggle('zoomed', zoom > 1);
116
+ // The outer size: scrollbars that take room must not make the screen smaller than the zoom says.
117
+ const w = view.offsetWidth;
118
+ const h = view.offsetHeight;
119
+ stage.style.width = `${Math.round(w * zoom)}px`;
120
+ stage.style.height = `${Math.round(h * zoom)}px`;
121
+ view.scrollLeft = cx * w * zoom - w / 2;
122
+ view.scrollTop = cy * h * zoom - h / 2;
123
+ stage.querySelector('.screen-pan').hidden = !moving;
124
+ $('#screen-zoom-now').textContent = zoom === 1 ? 'Fit' : `${Math.round(zoom * 100)}%`;
125
+ const move = $('#screen-move');
126
+ move.hidden = zoom === 1;
127
+ move.setAttribute('aria-pressed', String(moving));
128
+ move.classList.toggle('on', moving);
129
+ }
130
+ function setZoom(step) {
131
+ const at = ZOOMS.indexOf(zoom);
132
+ zoom = step === 0 ? 1 : ZOOMS[Math.max(0, Math.min(ZOOMS.length - 1, at + step))];
133
+ layout();
134
+ }
135
+ new ResizeObserver(() => layout()).observe(view);
136
+ const others = (v = status?.viewers ?? []) => v.filter((x) => x.who !== 'this computer');
137
+
138
+ /** The dot on the button: someone on another device is looking at this computer's screen. */
139
+ function showViewers(viewers) {
140
+ if (status) status.viewers = viewers;
141
+ const far = others(viewers);
142
+ $('#screen-dot').hidden = !far.length;
143
+ $('#screen-btn').title = far.length ? `Screen: viewed now from ${far.map((x) => x.who).join(', ')}` : "This computer's screen, to answer a pop-up or watch another program, from any device you're signed in on";
144
+ if (dialog.open && !rfb) render();
145
+ }
146
+
147
+ /** A Mac with Remote Management on refuses a user it does not list, whatever the password. */
148
+ function notListed() {
149
+ const m = status?.mac;
150
+ if (!m || m.allowed) return '';
151
+ return `<div class="screen-note"><p><b>This Mac will refuse ${esc(m.user)}, even with the right password.</b> It has Remote Management on, which lets in only the users listed there, and ${esc(m.user)} is not one of them.</p>
152
+ <p>On the Mac: <b>System Settings → General → Sharing → Remote Management → ⓘ</b>, add your user with Observe and Control. Or in a terminal on it (the Terminal button here will do):</p>
153
+ <p><code>${esc(m.fix)}</code></p></div>`;
154
+ }
155
+
156
+ function render() {
157
+ const s = status;
158
+ const connected = Boolean(rfb);
159
+ view.hidden = !connected;
160
+ body.hidden = connected;
161
+ $('#screen-keys').hidden = !connected;
162
+ $('#screen-off').hidden = remote() || !s?.enabled;
163
+ if (connected || !s) return;
164
+ const far = others();
165
+ const viewed = far.length ? `<p class="hint">Viewed now from ${far.map((x) => esc(x.who)).join(', ')}.</p>` : '';
166
+ if (!s.enabled) {
167
+ state.textContent = 'Off';
168
+ body.innerHTML = `<h3>This computer's screen, here and on your phone</h3>
169
+ <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>
170
+ <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>
171
+ ${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>'}`;
172
+ return;
173
+ }
174
+ if (!s.listening) {
175
+ state.textContent = 'Screen sharing is off';
176
+ body.innerHTML = `<h3>Turn on screen sharing on this computer</h3>
177
+ ${s.platform === 'darwin' ? '<p>On the Mac: <b>System Settings → General → Sharing → Screen Sharing</b>, on. Leave "Allow access for" on your own user.</p>' : `<p>Start a VNC server on this computer that listens on port ${s.port} of 127.0.0.1 only.</p>`}
178
+ <p class="hint">AI Agent Manager does not capture the screen itself: it relays the computer's own screen sharing (port ${s.port}) to pages that are signed in.</p>
179
+ <p><button class="primary" data-screen="check">Check again</button></p>${viewed}`;
180
+ return;
181
+ }
182
+ state.textContent = ended ? 'Ended' : 'Ready';
183
+ body.innerHTML = `${ended ? `<p><b>Ended:</b> ${esc(ended)}</p>` : '<h3>Ready</h3>'}${notListed()}
184
+ <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>
185
+ <p><button class="primary" data-screen="connect">${ended ? 'Connect again' : 'Connect'}</button></p>${viewed}`;
186
+ }
187
+
188
+ async function refresh() {
189
+ try {
190
+ status = await api('GET', '/screen');
191
+ } catch (err) {
192
+ status = null;
193
+ body.hidden = false;
194
+ body.innerHTML = `<p class="error">${esc(err.message)}</p>`;
195
+ }
196
+ showViewers(status?.viewers ?? []);
197
+ render();
198
+ }
199
+
200
+ function drop(reason) {
201
+ const was = rfb;
202
+ rfb = null;
203
+ ended = reason;
204
+ try {
205
+ was?.disconnect();
206
+ } catch {}
207
+ view.replaceChildren();
208
+ if (dialog.open) refresh();
209
+ }
210
+
211
+ /** The sign-in the screen sharing service asks for: on a Mac, user name and password. */
212
+ function askCredentials(types) {
213
+ view.hidden = true;
214
+ body.hidden = false;
215
+ state.textContent = 'Sign in';
216
+ const mac = status?.platform === 'darwin';
217
+ body.innerHTML = `<form id="screen-login" class="screen-login" autocomplete="off">
218
+ <h3>${mac ? 'Sign in to this Mac' : 'Screen sharing password'}</h3>
219
+ ${types.includes('username') ? `<label>${mac ? 'Mac user name' : 'User name'} <input name="username" autocapitalize="none" autocorrect="off" spellcheck="false" required /></label>` : ''}
220
+ ${types.includes('password') ? '<label>Password <input name="password" type="password" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false" required /></label><label class="screen-show"><input type="checkbox" data-screen-show /> Show the password</label>' : ''}
221
+ <p class="hint">Sent to the computer's screen sharing and not kept anywhere.</p>
222
+ <p><button class="primary" type="submit">Sign in</button> <button type="button" class="ghost" data-screen="cancel">Cancel</button></p>
223
+ </form>`;
224
+ body.querySelector('input')?.focus();
225
+ }
226
+
227
+ async function connect() {
228
+ ended = null;
229
+ state.textContent = 'Connecting…';
230
+ body.innerHTML = '<p class="hint">Connecting to this computer\'s screen…</p>';
231
+ let RFB;
232
+ try {
233
+ ({ default: RFB } = await import('/vendor/novnc/core/rfb.js'));
234
+ } catch (err) {
235
+ return drop(`The viewer could not be loaded (${err.message})`);
236
+ }
237
+ stage = document.createElement('div');
238
+ stage.className = 'screen-stage';
239
+ stage.innerHTML = '<div class="screen-pan" hidden></div>';
240
+ view.replaceChildren(stage);
241
+ zoom = 1;
242
+ const mine = new RFB(stage, REMOTE ? new StreamChannel() : `ws://${location.host}/ws/screen`);
243
+ rfb = mine;
244
+ mine.scaleViewport = true;
245
+ mine.background = '#0f1117';
246
+ mine.addEventListener('credentialsrequired', (e) => rfb === mine && askCredentials(e.detail?.types ?? ['password']));
247
+ mine.addEventListener('securityfailure', (e) => rfb === mine && drop(e.detail?.reason ? `Sign-in refused: ${e.detail.reason}` : 'Sign-in refused: check the user name and password'));
248
+ mine.addEventListener('connect', () => {
249
+ if (rfb !== mine) return;
250
+ state.textContent = 'Connected';
251
+ render();
252
+ layout(false);
253
+ mine.focus();
254
+ });
255
+ mine.addEventListener('disconnect', (e) => rfb === mine && drop(e.detail?.clean ? 'The connection was closed' : 'The connection was lost, or screen access is off'));
256
+ mine.addEventListener('desktopname', (e) => rfb === mine && e.detail?.name && ($('#screen-name').textContent = e.detail.name));
257
+ render();
258
+ // Until the screen arrives the page shows why it waits.
259
+ view.hidden = true;
260
+ body.hidden = false;
261
+ }
262
+
263
+ dialog.addEventListener('submit', (e) => {
264
+ if (e.target.id !== 'screen-login') return;
265
+ e.preventDefault();
266
+ const f = e.target;
267
+ const creds = {};
268
+ if (f.username) creds.username = f.username.value;
269
+ if (f.password) creds.password = f.password.value;
270
+ state.textContent = 'Signing in…';
271
+ body.innerHTML = '<p class="hint">Signing in…</p>';
272
+ rfb?.sendCredentials(creds);
273
+ });
274
+
275
+ // Typed blind on a phone, a password goes wrong easily: let it be seen.
276
+ dialog.addEventListener('change', (e) => {
277
+ if (e.target.matches('[data-screen-show]')) e.target.form.password.type = e.target.checked ? 'text' : 'password';
278
+ });
279
+
280
+ dialog.addEventListener('click', async (e) => {
281
+ const key = e.target.closest('[data-screen-key]');
282
+ if (key && rfb) return rfb.sendKey(KEYS[key.dataset.screenKey], null);
283
+ const z = e.target.closest('[data-screen-zoom]');
284
+ if (z) return setZoom(Number(z.dataset.screenZoom));
285
+ const b = e.target.closest('[data-screen]');
286
+ if (!b) return;
287
+ const what = b.dataset.screen;
288
+ try {
289
+ if (what === 'on' || what === 'off') {
290
+ status = await api('PUT', '/screen/settings', { enabled: what === 'on' });
291
+ if (what === 'off') drop(null);
292
+ toast(what === 'on' ? 'Screen access on: signed-in devices can reach this computer\'s screen' : 'Screen access off');
293
+ ended = null;
294
+ render();
295
+ } else if (what === 'check') await refresh();
296
+ else if (what === 'connect') await connect();
297
+ else if (what === 'move') {
298
+ moving = !moving;
299
+ layout();
300
+ } else if (what === 'cancel') drop('You cancelled the sign-in');
301
+ else if (what === 'close') dialog.close();
302
+ } catch (err) {
303
+ toast(`Error: ${err.message}`, 6000);
304
+ }
305
+ });
306
+
307
+ // A phone has no keyboard until a field is focused: what is typed here is sent key by key.
308
+ const typed = $('#screen-type');
309
+ typed.addEventListener('input', () => {
310
+ if (rfb) for (const ch of typed.value) rfb.sendKey(keysymOf(ch), null);
311
+ typed.value = '';
312
+ });
313
+ typed.addEventListener('keydown', (e) => {
314
+ const k = { Enter: 'enter', Backspace: 'back', Tab: 'tab', Escape: 'esc' }[e.key];
315
+ if (!k || !rfb) return;
316
+ e.preventDefault();
317
+ e.stopPropagation();
318
+ rfb.sendKey(KEYS[k], null);
319
+ });
320
+
321
+ // Esc belongs to the screen while it is shown, not to the dialog.
322
+ dialog.addEventListener('cancel', (e) => rfb && e.preventDefault());
323
+ dialog.addEventListener('close', () => {
324
+ const was = rfb;
325
+ rfb = null;
326
+ ended = null;
327
+ try {
328
+ was?.disconnect();
329
+ } catch {}
330
+ view.replaceChildren();
331
+ });
332
+
333
+ $('#screen-btn').onclick = async () => {
334
+ $('#screen-name').textContent = '';
335
+ if (!dialog.open) dialog.showModal();
336
+ await refresh();
337
+ };
338
+
339
+ // The dot is right from the start, not only after someone connects.
340
+ api('GET', '/screen').then((s) => showViewers(s.viewers)).catch(() => {});
341
+
342
+ return { viewers: showViewers };
343
+ }
package/public/style.css CHANGED
@@ -957,6 +957,27 @@ input.inline { display: inline-block; width: 80px; padding: 1px 4px; }
957
957
  .machine-dialog[open] { display: flex; flex-direction: column; }
958
958
  .machine-dialog .terminal { flex: 1; min-height: 0; }
959
959
  .machine-dialog #machine-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #8b93a7; margin-left: 8px; }
960
+ /* Screen: this computer's screen (screen.js). */
961
+ .screen-dialog { width: min(1500px, calc(100vw - 16px)); height: calc(100vh - 16px); padding: 0; }
962
+ .screen-dialog .screen-title { margin: 0 8px; }
963
+ .screen-dialog #screen-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: 8px; }
964
+ .screen-body { flex: 1; min-height: 0; overflow: auto; padding: 18px 20px; max-width: 640px; line-height: 1.5; }
965
+ .screen-body h3 { margin: 0 0 8px; }
966
+ .screen-view { flex: 1; min-height: 0; overflow: hidden; background: #0f1117; }
967
+ .screen-view.zoomed { overflow: auto; }
968
+ .screen-stage { position: relative; width: 100%; height: 100%; }
969
+ .screen-stage > div:not(.screen-pan) { touch-action: none; }
970
+ .screen-pan { position: absolute; inset: 0; z-index: 2; cursor: grab; touch-action: pan-x pan-y; }
971
+ .screen-dialog .term-bar { flex-wrap: wrap; row-gap: 4px; }
972
+ .screen-keys button.on { background: var(--accent, #4c8dff); color: #fff; }
973
+ .screen-keys { display: inline-flex; gap: 4px; align-items: center; }
974
+ .screen-type { width: 110px; padding: 2px 6px; font-size: 16px; } /* 16px: iOS zooms the page for less */
975
+ .screen-login label { display: block; margin: 8px 0; }
976
+ .screen-login input { display: block; width: min(320px, 100%); margin-top: 3px; font-size: 16px; }
977
+ @media (max-width: 760px) {
978
+ .screen-dialog { width: 100vw; height: 100dvh; max-width: none; border: 0; border-radius: 0; margin: 0; }
979
+ .screen-dialog #screen-name { display: none; }
980
+ }
960
981
 
961
982
  /* Diagrams: big pictures, one under another, for a quick grasp. */
962
983
  #doc-body.diagrams-view h2 { margin: 26px 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
@@ -1794,3 +1815,6 @@ table.eval-items tr.eval-na td { color: var(--muted); }
1794
1815
  }
1795
1816
  .os-local td:first-child { white-space: normal; overflow-wrap: anywhere; }
1796
1817
  .os-local-no code { opacity: 0.6; }
1818
+ .screen-note { border-left: 3px solid var(--warn, #d9a441); padding: 2px 10px; margin: 10px 0; }
1819
+ .screen-note code { display: block; overflow-wrap: anywhere; user-select: all; }
1820
+ .screen-login .screen-show input { display: inline; width: auto; margin: 0 4px 0 0; }
package/src/cli.js CHANGED
@@ -1767,6 +1767,22 @@ export async function main(argv) {
1767
1767
  console.log(`${green('✓')} answer queued for ${a.name}; it is typed into the session when the agent is idle`);
1768
1768
  });
1769
1769
 
1770
+ program
1771
+ .command('screen')
1772
+ .description("Screen: this computer's screen in the page, from your phone too, through the computer's own screen sharing. Whoever uses it controls the whole computer; off until turned on here")
1773
+ .option('--on', 'let signed-in devices reach this computer\'s screen')
1774
+ .option('--off', 'no device can; ends whoever is viewing now')
1775
+ .option('--port <n>', "the screen sharing service's port on this computer (5900)")
1776
+ .option('--json', 'print JSON')
1777
+ .action(async (opts) => {
1778
+ const patch = { ...(opts.on ? { enabled: true } : opts.off ? { enabled: false } : {}), ...(opts.port !== undefined ? { port: Number(opts.port) } : {}) };
1779
+ const v = Object.keys(patch).length ? await api('PUT', '/screen/settings', patch) : await api('GET', '/screen');
1780
+ if (opts.json) return console.log(JSON.stringify(v, null, 2));
1781
+ console.log(`Screen access ${v.enabled ? green('on') : `${dim('off')} ${dim('(agentmgr screen --on)')}`}`);
1782
+ console.log(v.listening ? dim(`Screen sharing answers on port ${v.port}`) : yellow(`Nothing answers on port ${v.port}: turn on screen sharing on this computer${v.platform === 'darwin' ? ' (System Settings → General → Sharing → Screen Sharing)' : ''}`));
1783
+ for (const w of v.viewers) console.log(` viewed from ${w.who} since ${new Date(w.since).toLocaleTimeString()}`);
1784
+ });
1785
+
1770
1786
  program
1771
1787
  .command('rounds')
1772
1788
  .description("Review rounds before a pull request: critics on other models read an agent's changes when it says it is done, the agent fixes what they find, and the pull request is opened when they approve")
package/src/config.js CHANGED
@@ -87,6 +87,8 @@ const DEFAULTS = {
87
87
  localModels: { enabled: true, context: 32768 },
88
88
  // Review rounds before a pull request (prereview.js): critics on other models, until they approve.
89
89
  preReview: { enabled: true, rounds: 4, critics: 2, openPr: true },
90
+ // Screen (screen.js): this computer's screen in the page, through its own screen sharing on this port.
91
+ screen: { enabled: false, port: 5900 },
90
92
  // AI News: the frontier labs' latest releases, summarized; see NEWS_DEFAULTS in news.js for every field.
91
93
  news: { enabled: true },
92
94
  demoPage: false,
package/src/screen.js ADDED
@@ -0,0 +1,149 @@
1
+ // Screen: this computer's screen, shown and controlled from the page (a pop-up to answer, another
2
+ // program to watch), from the phone too. It does not capture the screen itself: the computer's own
3
+ // screen sharing does (macOS: System Settings → General → Sharing → Screen Sharing; elsewhere any
4
+ // VNC server on this computer), and asks for its own sign-in. This relays that connection to
5
+ // signed-in pages: bytes in, bytes out, to a port on this computer only.
6
+ //
7
+ // Whoever uses it controls the whole computer, so it is off until turned on, and only from the
8
+ // computer itself.
9
+ import net from 'node:net';
10
+ import fs from 'node:fs';
11
+ import os from 'node:os';
12
+ import crypto from 'node:crypto';
13
+ import { execFile } from 'node:child_process';
14
+
15
+ export const SCREEN_DEFAULTS = { enabled: false, port: 5900 };
16
+ const HOST = '127.0.0.1'; // never another computer: this is not a way into the network
17
+ const MAX_VIEWERS = 4;
18
+ const QUIET_MS = 60_000; // a stream whose page went away without closing it
19
+
20
+ const fail = (status, message) => Object.assign(new Error(message), { status });
21
+
22
+ export function screenSettings(config) {
23
+ const d = { ...SCREEN_DEFAULTS, ...(config.screen ?? {}) };
24
+ const port = Number(d.port);
25
+ return { enabled: d.enabled === true, port: Number.isInteger(port) && port > 0 && port < 65536 ? port : SCREEN_DEFAULTS.port };
26
+ }
27
+
28
+ /** Whether something listens on the port (the screen sharing service is on). */
29
+ export function listening(port, ms = 800) {
30
+ return new Promise((resolve) => {
31
+ const s = net.connect({ host: HOST, port });
32
+ const done = (ok) => {
33
+ s.destroy();
34
+ resolve(ok);
35
+ };
36
+ s.setTimeout(ms, () => done(false));
37
+ s.once('connect', () => done(true));
38
+ s.once('error', () => done(false));
39
+ });
40
+ }
41
+
42
+ const out = (cmd, args) => new Promise((resolve) => execFile(cmd, args, { timeout: 3000 }, (err, stdout) => resolve(err ? null : String(stdout).trim())));
43
+ const KICKSTART = '/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart';
44
+
45
+ /**
46
+ * A Mac with Remote Management on (instead of plain Screen Sharing) lets in only the users listed
47
+ * there, and refuses everyone else as if the password were wrong. Whether this computer's user is
48
+ * let in: `{ user, allowed, fix }`, or null where that does not apply.
49
+ */
50
+ export async function macAccess() {
51
+ if (process.platform !== 'darwin' || !fs.existsSync('/Library/Application Support/Apple/Remote Desktop/RemoteManagement.launchd')) return null;
52
+ const user = os.userInfo().username;
53
+ const everyone = (await out('/usr/bin/defaults', ['read', '/Library/Preferences/com.apple.RemoteManagement', 'ARD_AllLocalUsers'])) === '1';
54
+ const listed = /naprivs:\s*-?\d/.test((await out('/usr/bin/dscl', ['.', '-read', `/Users/${user}`, 'naprivs'])) ?? '');
55
+ return { user, allowed: everyone || listed, fix: `sudo ${KICKSTART} -configure -users ${user} -access -on -privs -ControlObserve` };
56
+ }
57
+
58
+ export class Screen {
59
+ /** `onChange(viewers)` is called when someone connects or leaves. `mac` stands in for macAccess in tests. */
60
+ constructor({ config, onChange = () => {}, log = () => {}, mac = macAccess }) {
61
+ this.mac = mac;
62
+ this.config = config;
63
+ this.onChange = onChange;
64
+ this.log = log;
65
+ this.links = new Map(); // id -> { socket, who, since, last, timer }
66
+ }
67
+
68
+ get settings() {
69
+ return screenSettings(this.config);
70
+ }
71
+
72
+ viewers() {
73
+ return [...this.links.values()].map((l) => ({ who: l.who, since: l.since }));
74
+ }
75
+
76
+ async status() {
77
+ const s = this.settings;
78
+ const [on, mac] = await Promise.all([listening(s.port), s.enabled ? this.mac() : null]);
79
+ return { ...s, platform: process.platform, listening: on, mac, viewers: this.viewers() };
80
+ }
81
+
82
+ /** From the computer itself only (the route is local-only). Turning it off ends every viewer. */
83
+ change(b = {}) {
84
+ const next = { ...this.settings };
85
+ if ('enabled' in b) next.enabled = b.enabled === true || b.enabled === 'on';
86
+ if ('port' in b) {
87
+ const port = Number(b.port);
88
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw fail(400, 'port is a number from 1 to 65535');
89
+ next.port = port;
90
+ }
91
+ this.config.screen = next;
92
+ if (!next.enabled) for (const id of [...this.links.keys()]) this.close(id, 'Screen access was turned off');
93
+ return next;
94
+ }
95
+
96
+ /**
97
+ * A connection to the screen sharing service for one page. `sink.data(buffer)` gets what it
98
+ * sends, `sink.end(reason)` is called once when it is over. Returns the link's id.
99
+ */
100
+ open(sink, who = 'this computer') {
101
+ const s = this.settings;
102
+ if (!s.enabled) throw fail(403, 'Screen access is off. Turn it on on the computer itself: the Screen button.');
103
+ if (this.links.size >= MAX_VIEWERS) throw fail(429, `${MAX_VIEWERS} devices are viewing the screen already`);
104
+ const id = crypto.randomBytes(12).toString('hex');
105
+ const socket = net.connect({ host: HOST, port: s.port });
106
+ socket.setNoDelay(true);
107
+ const link = { socket, sink, who, since: new Date().toISOString(), last: Date.now(), timer: null, ended: false };
108
+ this.links.set(id, link);
109
+ socket.on('data', (buf) => sink.data(buf));
110
+ socket.on('error', (err) => this.close(id, err.code === 'ECONNREFUSED' ? 'Screen sharing is not on on this computer' : err.message));
111
+ socket.on('close', () => this.close(id, 'The screen sharing service closed the connection'));
112
+ this.log(`screen: ${who} connected`);
113
+ this.onChange(this.viewers());
114
+ return id;
115
+ }
116
+
117
+ /** A link fed by POSTs (the phone): it ends when its page stops sending and listening. */
118
+ watch(id, alive) {
119
+ const link = this.links.get(id);
120
+ if (!link) return;
121
+ link.timer = setInterval(() => !alive() && Date.now() - link.last > QUIET_MS && this.close(id, 'The page went away'), 15_000);
122
+ link.timer.unref?.();
123
+ }
124
+
125
+ write(id, buf) {
126
+ const link = this.links.get(id);
127
+ if (!link) throw fail(410, 'This screen connection has ended');
128
+ link.last = Date.now();
129
+ link.socket.write(buf);
130
+ }
131
+
132
+ close(id, reason = 'Closed') {
133
+ const link = this.links.get(id);
134
+ if (!link || link.ended) return;
135
+ link.ended = true;
136
+ this.links.delete(id);
137
+ clearInterval(link.timer);
138
+ link.socket.destroy();
139
+ try {
140
+ link.sink.end(reason);
141
+ } catch {}
142
+ this.log(`screen: ${link.who} left (${reason})`);
143
+ this.onChange(this.viewers());
144
+ }
145
+
146
+ closeAll(reason) {
147
+ for (const id of [...this.links.keys()]) this.close(id, reason);
148
+ }
149
+ }
package/src/server.js CHANGED
@@ -18,6 +18,7 @@ import { Assistant, FEATURES, featuresOf } from './assistant.js';
18
18
  import { Cleanup } from './cleanup.js';
19
19
  import { Landing } from './landing.js';
20
20
  import { PreReview } from './prereview.js';
21
+ import { Screen } from './screen.js';
21
22
  import { Autopilot } from './autopilot.js';
22
23
  import { Goals, goalMarkdown } from './goals.js';
23
24
  import { Budgets } from './budgets.js';
@@ -104,7 +105,7 @@ function isAllowedOrigin(origin, port) {
104
105
  const PUBLIC_REMOTE_API = new Set(['POST /api/login', 'GET /api/session']);
105
106
  // Updates are not here: a signed-in device (a phone) can install the newest release too. It only
106
107
  // ever installs an official release from where this copy came from (git tag or npm) and restarts.
107
- const LOCAL_ONLY_API = /^\/api\/(remote(\/|$)|notify(\/|$)|hub(\/|$)|triggers(\/|$)|service$|jira(\/check)?$|isolation\/|editors$|agentkit\/connect$|agents\/[\w-]+\/open-in$|local-models\/settings$|shutdown$)/;
108
+ const LOCAL_ONLY_API = /^\/api\/(remote(\/|$)|notify(\/|$)|hub(\/|$)|triggers(\/|$)|service$|jira(\/check)?$|isolation\/|screen\/settings$|editors$|agentkit\/connect$|agents\/[\w-]+\/open-in$|local-models\/settings$|shutdown$)/;
108
109
  const HOOK_PATH = '/api/hooks/agents';
109
110
  const REPORT_PATH = '/api/agentkit/report';
110
111
  const NO_REPO_KINDS = new Set(['general', 'assistant']);
@@ -252,6 +253,15 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
252
253
  });
253
254
  // A daily standup: each agent's news, worded for listening; the page plays it (standup.js).
254
255
  let pushStandup = () => {};
256
+ // This computer's screen, relayed to signed-in pages (screen.js); off until turned on here.
257
+ let pushScreen = () => {};
258
+ /** Who looks at the screen, for the note on the computer: the kind of device and its address. */
259
+ const viewer = (req) => {
260
+ if (!req.remote) return 'this computer';
261
+ const kind = /iPhone|iPad|Android|Macintosh|Windows|Linux/.exec(req.device?.ua ?? '')?.[0].replace('Macintosh', 'Mac');
262
+ return `${kind ? (/^[AEIOU]/i.test(kind) ? `an ${kind}` : `a ${kind}`) : 'a signed-in device'}${req.device?.ip ? ` (${String(req.device.ip).replace(/^::ffff:/, '')})` : ''}`;
263
+ };
264
+ const screen = new Screen({ config, onChange: (viewers) => pushScreen(viewers), log: (m) => console.log(`[agentmgr] ${m}`) });
255
265
  const standup = new Standup({
256
266
  manager,
257
267
  store,
@@ -520,6 +530,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
520
530
  app.use('/vendor/marked', express.static(path.join(pkgDir('marked'), 'lib')));
521
531
  app.use('/vendor/dompurify', express.static(path.join(pkgDir('dompurify'), 'dist')));
522
532
  app.use('/vendor/mermaid', express.static(path.join(pkgDir('mermaid'), 'dist')));
533
+ app.use('/vendor/novnc', express.static(pkgDir('@novnc/novnc')));
523
534
  app.use(express.static(path.join(__dirname, '..', 'public')));
524
535
 
525
536
  const api = express.Router();
@@ -1637,6 +1648,44 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
1637
1648
  return { ok: true };
1638
1649
  }),
1639
1650
  );
1651
+ // Screen (screen.js): this computer's screen through its own screen sharing, relayed to
1652
+ // signed-in pages. The phone has no WebSocket here (see above): a stream out, POSTs in.
1653
+ api.get('/screen', wrap(() => screen.status()));
1654
+ api.put('/screen/settings', wrap((req) => {
1655
+ saveConfig({ screen: screen.change(req.body ?? {}) });
1656
+ return screen.status();
1657
+ }));
1658
+ api.get('/screen/stream', (req, res) => {
1659
+ let send = null;
1660
+ let id;
1661
+ try {
1662
+ id = screen.open(
1663
+ {
1664
+ data: (buf) => send?.({ t: 'd', d: buf.toString('base64') }),
1665
+ end: (reason) => {
1666
+ send?.({ t: 'end', reason });
1667
+ res.end();
1668
+ },
1669
+ },
1670
+ viewer(req),
1671
+ );
1672
+ } catch (err) {
1673
+ return res.status(err.status || 500).json({ error: err.message });
1674
+ }
1675
+ send = sse(req, res);
1676
+ send({ t: 'open', id });
1677
+ let open = true;
1678
+ screen.watch(id, () => open);
1679
+ req.on('close', () => {
1680
+ open = false;
1681
+ screen.close(id, 'The page closed it');
1682
+ });
1683
+ });
1684
+ api.post('/screen/input', wrap((req) => {
1685
+ if (typeof req.body?.id !== 'string' || typeof req.body?.d !== 'string') throw fail(400, 'id and d (base64) are required');
1686
+ screen.write(req.body.id, Buffer.from(req.body.d, 'base64'));
1687
+ return { ok: true };
1688
+ }));
1640
1689
  plugins.mount(api, express); // /api/ext/<plugin>, behind the same checks
1641
1690
  app.use('/api', api);
1642
1691
 
@@ -1659,6 +1708,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
1659
1708
  for (const send of eventSinks) send(msg);
1660
1709
  };
1661
1710
  manager.on('change', (agent) => broadcast({ t: 'agent', agent }));
1711
+ pushScreen = (viewers) => broadcast({ t: 'screen', viewers });
1662
1712
  pushStandup = (latest) => broadcast({ t: 'standup', latest });
1663
1713
  pushValue = () => broadcast({ t: 'value' });
1664
1714
  pushNews = () => broadcast({ t: 'news' });
@@ -1722,6 +1772,28 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
1722
1772
  return;
1723
1773
  }
1724
1774
 
1775
+ if (url.pathname === '/ws/screen') {
1776
+ let id;
1777
+ try {
1778
+ id = screen.open(
1779
+ {
1780
+ data: (buf) => ws.readyState === ws.OPEN && ws.send(buf),
1781
+ end: (reason) => ws.close(1000, reason.slice(0, 120)),
1782
+ },
1783
+ viewer(req),
1784
+ );
1785
+ } catch (err) {
1786
+ return ws.close(1008, err.message.slice(0, 120));
1787
+ }
1788
+ ws.on('message', (raw) => {
1789
+ try {
1790
+ screen.write(id, raw);
1791
+ } catch {}
1792
+ });
1793
+ ws.on('close', () => screen.close(id, 'The page closed it'));
1794
+ return;
1795
+ }
1796
+
1725
1797
  const m = url.pathname.match(/^\/ws\/term\/([\w-]+)$/);
1726
1798
  if (!m) return ws.close(1008, 'unknown endpoint');
1727
1799
  let session;
@@ -1822,6 +1894,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
1822
1894
  updates.close();
1823
1895
  mcp.close();
1824
1896
  assistant.close();
1897
+ screen.closeAll('AI Agent Manager is shutting down');
1825
1898
  console.log(`[agentmgr] shutting down (${reason}); closing agents so their sessions are saved`);
1826
1899
  builder.stopAll();
1827
1900
  await manager.stopAll({ final: true });