Files
desktop/api/router.ts
T
pastilhasandClaude Opus 5 b91d4df21d desktop, extracted from the platform
x11vnc against display :0 — the session the owner is actually logged into, not a second one Officer
installs. sidecar/, api/, web/ and the host setup script, moved out of src/ whole.

Dormant when it moved: the websocket was commented out in server.tsx and the router in hono.ts since
2026-08-13, and no officer-vnc process was running on any machine. Nothing regressed and nothing was
restored — this took switched-off code out of the platform.

The point of the move is what the platform stopped knowing. Its sidecar/protocol.ts carried a VNC
section — vnc:start, vnc:ensure-password, vnc:stop, four reply variants, VncStartParams,
VncSessionInfo — and sidecar-registry.ts carried startVnc, ensureVncPassword, stopVnc and
isVncConnected. That is the platform speaking a plugin's vocabulary, which CLAUDE.md names as a rule
and this was the clearest breach of. All of it is in sidecar/protocol.ts here now.

The permission made a round trip worth recording. It was kind: 'execution' — "runs as the server owner
and cannot be shared" — and a plugin permission has no kind, deliberately, because a permission nobody
can delegate is a contradiction. So the property is expressed as ownerOnly: ['/'] instead: every path
under this plugin refused to anyone but the owner. Same answer, reached from the paths rather than
from a kind, and the first real use of a mechanism that landed the same day. The property is real —
there is one physical screen and it is the owner's.

Not finished, and BLOCKERS.md says so rather than the commit implying otherwise: the websocket is
dormant because a plugin cannot claim a WebSocket provider, host setup needs a reboot and no manifest
can express that, and there is no artwork.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 00:41:24 +00:00

44 lines
2.2 KiB
TypeScript

import { createRouter } from '@@/create-router';
import { sendSidecarCommand, isSidecarConnected } from '@@/sidecar-registry';
import { DESKTOP_SIDECAR_KIND, type DesktopEvent } from '../sidecar/protocol';
export const router = createRouter();
// The desktop UI asks for the password before it can open the WebSocket — and that WebSocket is what
// starts the VNC session. So this cannot wait for a session to exist: on a fresh install nothing has
// ever written the password, and answering "not configured" deadlocked the page permanently.
//
// Officer does not read the password file itself. It lives in the owner's ~/.vnc, next to the rfbauth
// file x11vnc authenticates against, and the sidecar is the process that writes both — so it is the
// process that answers for them too. `vnc:ensure-password` is idempotent: it returns the existing
// pair when both files are already there, and provisions them when they are not.
router.get('/vnc-password', async (ctx) => {
const user = ctx.get('user');
if (!isSidecarConnected(DESKTOP_SIDECAR_KIND)) {
return ctx.json({ error: 'VNC sidecar is not connected' }, 503);
}
try {
// Addressed through the platform's GENERIC door: it matches the reply by id and knows nothing about
// what `vnc:ensure-password` means. The vocabulary is this plugin's — see sidecar/protocol.ts.
const reply = await sendSidecarCommand<DesktopEvent>(DESKTOP_SIDECAR_KIND, {
type: 'vnc:ensure-password',
id: crypto.randomUUID(),
email: user.email,
});
if (reply.type === 'vnc:error') throw new Error(reply.error);
if (reply.type !== 'vnc:password') throw new Error(`unexpected reply ${reply.type}`);
const password = reply.password;
return ctx.json({ password });
} catch (err) {
const message = err instanceof Error ? err.message : 'Could not provision the VNC password';
console.error('[desktop] VNC password provisioning failed:', message);
return ctx.json({ error: message }, 500);
}
});
// GET /vnc-status is gone. It was never called — DesktopView asks only for /vnc-password — and it was
// the sole reason the `vnc:status` command existed on the sidecar wire protocol at all. Noted as dead
// by docs/sidecar-audit-2026-07.md months ago.