@agimon-ai/doompi-core 0.0.1-alpha.103 → 0.0.1-alpha.104

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.
@@ -146,13 +146,13 @@ function parseTranscriptRequest(url) {
146
146
  }
147
147
  return request;
148
148
  }
149
- async function sessionFile(session, relativePath) {
150
- if (!relativePath || relativePath.includes("\0") || node_path.default.isAbsolute(relativePath)) return Response.json({ error: "Invalid session file path." }, { status: 400 });
149
+ async function sessionFile(session, requestedPath) {
150
+ if (!requestedPath || requestedPath.includes("\0")) return Response.json({ error: "Invalid session file path." }, { status: 400 });
151
151
  let root;
152
152
  let filePath;
153
153
  try {
154
154
  root = await node_fs.default.promises.realpath(session.cwd);
155
- filePath = await node_fs.default.promises.realpath(node_path.default.resolve(root, relativePath));
155
+ filePath = await node_fs.default.promises.realpath(node_path.default.resolve(root, requestedPath));
156
156
  } catch {
157
157
  return Response.json({ error: "Session file not found." }, { status: 404 });
158
158
  }
@@ -1 +1 @@
1
- {"version":3,"file":"headlessServer.cjs","names":["path","fs","os","Readable","pipeline","WebSocketServer","createHeadlessProtocol","createSessionMcpRoutes","createSessionMcpActivityStore","createSessionMcpConversationStore","createSessionMcpRegistrationStore","createServer","harnessErrorMessage","isPublicSessionMcpRoute","isSessionMcpHostRoute","createContextApi","readContextDetail","DOOM_API_CALLER_HEADERS","DOOM_API_CALLER_LOCALITY_HEADER","DOOM_API_CALLER_STEP_UP_HEADER","BACKGROUND_CONTEXT","parseDoomSocketPath"],"sources":["../src/server/headlessServer.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { Context } from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { WebSocket } from 'ws';\nimport { WebSocketServer } from 'ws';\n\nimport { API_BASE_PATH as CONTEXT_API_BASE_PATH } from '../constants/contextApi';\nimport {\n DOOM_API_CALLER_HEADERS,\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n parseDoomSocketPath,\n type DoomApiMount,\n} from '../exports/packageApi';\nimport type { TranscriptPage, TranscriptPageRequest } from '../exports/sessionProtocol';\nimport type { DoomHubSessionReservations } from '../schemas/hubChannel';\nimport { readContextDetail } from '../services/contextDetailStore';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport { observe, type ServerTelemetry } from '../services/serverTelemetry';\nimport { createSessionMcpActivityStore } from '../services/sessionMcpActivity';\nimport { createSessionMcpConversationStore } from '../services/sessionMcpConversations';\nimport { createSessionMcpRegistrationStore } from '../services/sessionMcpRegistrationStore';\nimport type { SavedSession } from '../services/sqliteSessionHistory';\nimport { createContextApi } from './contextApi';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession, HeadlessWorkspaceAdmission } from './headlessHub';\nimport { createHeadlessProtocol } from './headlessProtocol';\nimport { createSessionMcpRoutes, isPublicSessionMcpRoute, isSessionMcpHostRoute } from './sessionMcpRoutes';\n\n/**\n * The canonical public shape of a package API request, as dispatch reads it.\n *\n * Groups: workspace id, session id, plugin base path, and the remainder handed\n * to the package. `settings` is the host's own API and sits beside `plugins`\n * rather than under it.\n *\n * Exported so the browser's URL construction can be pinned against it. The two\n * are written independently, in halves of this package that may not import each\n * other, and a disagreement between them is not a 404 from the route: the\n * service worker answers an unrecognised path out of the signed bundle cache,\n * so the symptom appears nowhere near the cause.\n */\nexport const DOOM_PACKAGE_API_PATH_PATTERN =\n /^\\/api(?:\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?)?\\/(?:plugins\\/([^/]+)|settings)(?:\\/(.*))?$/u;\n\nconst HEALTH_ROLE = 'hub';\nconst PROTOCOL_VERSION = 1;\nconst MAX_BODY_BYTES = 8 * 1024 * 1024;\nconst MAX_SESSION_FILE_BYTES = 25 * 1024 * 1024;\nconst DIRECTORY_SUGGESTION_LIMIT = 12;\nconst DIRECTORY_CHILDREN_LIMIT = 500;\nconst HOME_PREFIX = '~';\nconst WORKSPACE_NAME_MAX_LENGTH = 80;\nconst WORKSPACE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/u;\nconst SESSION_FILE_CONTENT_TYPES: Readonly<Record<string, string>> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.m4v': 'video/mp4',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.pdf': 'application/pdf',\n};\n\nexport interface HeadlessServerOptions {\n headlessHub: HeadlessHub;\n port: number;\n host?: string;\n /** Requests other than health require this bearer token when set. */\n token?: string;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n compositions?: () => unknown;\n requestAsset?: (request: Request) => Promise<Response | undefined>;\n sessionHistory?: (session: HeadlessHubSession) => Promise<SavedSession[]>;\n workspaceHistory?: (workspaceId: string) => Promise<SavedSession[]>;\n resumeWorkspaceSession?: (workspaceId: string, targetSessionId: string) => Promise<string>;\n readDormantTranscript?: (\n record: OpenSessionRecord,\n request: TranscriptPageRequest,\n context: Context,\n ) => Promise<TranscriptPage>;\n restartSession?: (session: HeadlessHubSession) => Promise<void>;\n resumeSession?: (session: HeadlessHubSession, targetSessionId: string) => Promise<string>;\n /** Recorded sessions this server has not reopened, surfaced so a client can ask for one. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n removeDormantSession?: (record: OpenSessionRecord) => void | Promise<void>;\n reviveSession?: (record: OpenSessionRecord) => Promise<void>;\n /** Trusted HTTPS origin advertised for public session MCP and OAuth endpoints. */\n sessionMcpPublicOrigin?: () => string | undefined;\n /** Durable state directory for verified Session MCP clients. */\n sessionMcpStateDir?: string;\n /** Monotonic exposure revision, including disable/re-enable cycles. */\n sessionMcpPublicOriginRevision?: () => number;\n isSessionPersisted?: (sessionId: string, cwd: string) => boolean;\n}\n\nexport interface HeadlessServer {\n readonly url: string;\n readonly sessionReservations: DoomHubSessionReservations;\n close(): Promise<void>;\n}\n\ntype ProtocolHandler = NonNullable<ReturnType<Awaited<ReturnType<typeof createHeadlessProtocol>>['accept']>>;\ntype Client = { socket: WebSocket; handler: ProtocolHandler };\n\nfunction sessionView(session: HeadlessHubSession): Record<string, unknown> {\n return {\n id: session.id,\n workspaceId: session.workspaceId,\n webComposition: session.webComposition,\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n ...(session.git === undefined ? {} : { git: { ...session.git } }),\n ...(session.profile === undefined ? {} : { profile: { ...session.profile } }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.pendingSetups === undefined ? {} : { pendingSetups: session.pendingSetups }),\n ...(session.activity === undefined ? {} : { activity: { ...session.activity } }),\n };\n}\n\n/** The dormant counterpart of `sessionView`; same shape, no runtime behind it. */\nfunction dormantView(record: OpenSessionRecord): Record<string, unknown> {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'detached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n };\n}\n\nfunction json(response: ServerResponse, status: number, value: unknown): void {\n const body = JSON.stringify(value);\n response.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'content-length': Buffer.byteLength(body),\n });\n response.end(body);\n}\n\nfunction authorized(request: IncomingMessage, token: string | undefined): boolean {\n if (token === undefined) return true;\n const authorization = request.headers.authorization;\n if (authorization?.startsWith('Bearer ') && authorization.slice('Bearer '.length) === token) return true;\n const header = request.headers['x-doompi-token'];\n if (typeof header === 'string' && header === token) return true;\n try {\n return new URL(request.url ?? '/', 'http://doompi.local').searchParams.get('token') === token;\n } catch {\n return false;\n }\n}\n\nfunction requestPath(request: IncomingMessage): URL {\n return new URL(request.url ?? '/', 'http://doompi.local');\n}\n\nfunction parseTranscriptRequest(url: URL): TranscriptPageRequest {\n const request: TranscriptPageRequest = {};\n const cursor = url.searchParams.get('cursor');\n const direction = url.searchParams.get('direction');\n const limit = url.searchParams.get('limit');\n if (cursor !== null) request.cursor = cursor;\n if (direction !== null) {\n if (direction !== 'older' && direction !== 'newer') throw new Error('Invalid transcript direction');\n request.direction = direction;\n }\n if (limit !== null) {\n if (!/^\\d+$/u.test(limit)) throw new Error('Invalid transcript page limit');\n const parsed = Number(limit);\n if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 100) throw new Error('Invalid transcript page limit');\n request.limit = parsed;\n }\n return request;\n}\n\nasync function sessionFile(session: HeadlessHubSession, relativePath: string | null): Promise<Response> {\n if (!relativePath || relativePath.includes('\\0') || path.isAbsolute(relativePath))\n return Response.json({ error: 'Invalid session file path.' }, { status: 400 });\n let root: string;\n let filePath: string;\n try {\n root = await fs.promises.realpath(session.cwd);\n filePath = await fs.promises.realpath(path.resolve(root, relativePath));\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n const contained = path.relative(root, filePath);\n if (contained === '..' || contained.startsWith(`..${path.sep}`) || path.isAbsolute(contained))\n return Response.json({ error: 'Session file is outside the working directory.' }, { status: 403 });\n let handle: fs.promises.FileHandle;\n try {\n handle = await fs.promises.open(filePath, 'r');\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n try {\n const stat = await handle.stat();\n if (!stat.isFile()) return Response.json({ error: 'Session file not found.' }, { status: 404 });\n if (stat.size > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n const bytes = await handle.readFile();\n if (bytes.byteLength > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n return new Response(bytes, {\n headers: {\n 'content-type': SESSION_FILE_CONTENT_TYPES[path.extname(filePath).toLowerCase()] ?? 'application/octet-stream',\n 'content-length': String(bytes.byteLength),\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n },\n });\n } finally {\n await handle.close();\n }\n}\n\n/** Expands a leading `~` the way a shell would, so typed paths match what the user sees in a terminal. */\nfunction expandHome(value: string): string {\n if (value === HOME_PREFIX) return os.homedir();\n return value.startsWith(`${HOME_PREFIX}${path.sep}`) ? path.join(os.homedir(), value.slice(2)) : value;\n}\n\n/**\n * Validates an add-workspace request. A name alone asks for a new default folder,\n * so it must be safe to use as one folder name.\n */\nfunction parseWorkspaceAdmission(body: unknown): HeadlessWorkspaceAdmission | { error: string } {\n if (typeof body !== 'object' || body === null) return { error: 'A workspace root or name is required.' };\n const record = body as Record<string, unknown>;\n if (record.root !== undefined && typeof record.root !== 'string')\n return { error: 'The workspace root must be text.' };\n if (record.name !== undefined && typeof record.name !== 'string')\n return { error: 'The workspace name must be text.' };\n const root =\n typeof record.root === 'string' && record.root.trim() !== '' ? expandHome(record.root.trim()) : undefined;\n const name = typeof record.name === 'string' && record.name.trim() !== '' ? record.name.trim() : undefined;\n if (root === undefined && name === undefined) return { error: 'A workspace root or name is required.' };\n if (\n name !== undefined &&\n (name.length > WORKSPACE_NAME_MAX_LENGTH || !WORKSPACE_NAME_PATTERN.test(name) || name.includes('..'))\n )\n return {\n error: `Workspace names use letters, numbers, spaces, dots, dashes, or underscores (up to ${String(WORKSPACE_NAME_MAX_LENGTH)} characters).`,\n };\n return { ...(root === undefined ? {} : { root }), ...(name === undefined ? {} : { name }) };\n}\n\nasync function directorySuggestions(query: string, sessions: readonly HeadlessHubSession[]): Promise<string[]> {\n const typed = expandHome(query.trim());\n if (typed === '') return [];\n const matches = (value: string): boolean => value.toLowerCase().includes(typed.toLowerCase());\n const known = [...new Set([process.cwd(), ...sessions.map((session) => session.cwd)])].filter(matches);\n const candidates = path.isAbsolute(typed)\n ? [typed]\n : typed.includes(path.sep)\n ? [path.resolve(process.cwd(), typed)]\n : [path.join(path.dirname(process.cwd()), typed), path.join(process.cwd(), typed)];\n const completed: string[] = [];\n for (const candidate of candidates) {\n const drilling = typed.endsWith(path.sep);\n const parent = drilling ? candidate : path.dirname(candidate);\n const partial = drilling ? '' : path.basename(candidate).toLowerCase();\n try {\n const entries = await fs.promises.readdir(parent, { withFileTypes: true });\n completed.push(\n ...entries\n .filter((entry) => entry.isDirectory() && entry.name.toLowerCase().includes(partial))\n .map((entry) => path.join(parent, entry.name)),\n );\n } catch {\n // A missing or unreadable parent simply has no completions.\n }\n }\n return [...new Set([...known, ...completed.sort((left, right) => left.localeCompare(right))])].slice(\n 0,\n DIRECTORY_SUGGESTION_LIMIT,\n );\n}\n\n/**\n * Lists the visible child directories of one folder for the workspace folder browser.\n * Resolves undefined for a relative, missing, or unreadable path.\n */\nasync function directoryChildren(\n requested: string | null,\n): Promise<{ path: string; parent?: string; directories: string[] } | undefined> {\n const directory = requested === null || requested.trim() === '' ? os.homedir() : expandHome(requested.trim());\n if (!path.isAbsolute(directory)) return undefined;\n const resolved = path.resolve(directory);\n let entries: fs.Dirent[];\n try {\n entries = await fs.promises.readdir(resolved, { withFileTypes: true });\n } catch {\n return undefined;\n }\n const directories = entries\n .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))\n .map((entry) => path.join(resolved, entry.name))\n .sort((left, right) => left.localeCompare(right))\n .slice(0, DIRECTORY_CHILDREN_LIMIT);\n const parent = path.dirname(resolved);\n return { path: resolved, ...(parent === resolved ? {} : { parent }), directories };\n}\n\nasync function readBody(request: IncomingMessage): Promise<Uint8Array> {\n const chunks: Buffer[] = [];\n let size = 0;\n for await (const chunk of request) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n size += buffer.byteLength;\n if (size > MAX_BODY_BYTES) throw new Error('Request body is too large.');\n chunks.push(buffer);\n }\n return Buffer.concat(chunks);\n}\n\nfunction parseJson(body: Uint8Array): unknown {\n if (body.byteLength === 0) return {};\n return JSON.parse(Buffer.from(body).toString('utf8')) as unknown;\n}\n\nfunction webRequest(request: IncomingMessage, url: URL, signal?: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined) headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n return new Request(url, {\n method: request.method,\n headers,\n signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : {\n body: Readable.toWeb(request) as never,\n duplex: 'half' as const,\n }),\n });\n}\n\nasync function writeResponse(response: ServerResponse, result: Response): Promise<void> {\n response.writeHead(result.status, Object.fromEntries(result.headers.entries()));\n if (result.body === null) {\n response.end();\n return;\n }\n await pipeline(Readable.fromWeb(result.body as import('node:stream/web').ReadableStream), response);\n}\n\nfunction eventFrame(event: HeadlessHubEvent): Record<string, unknown> {\n switch (event.kind) {\n case 'upsert':\n return { type: 'session_upsert', session: sessionView(event.session) };\n case 'removed':\n return { type: 'session_removed', sessionId: event.sessionId };\n case 'workspace_upsert':\n return { type: 'workspace_upsert', workspace: event.workspace };\n case 'workspace_removed':\n return { type: 'workspace_removed', workspaceId: event.workspaceId };\n case 'channel':\n return {\n type: 'channel_frame',\n frameType: event.frameType,\n sessionId: event.sessionId,\n payload: event.payload,\n ...(event.connectionId === undefined ? {} : { connectionId: event.connectionId }),\n };\n }\n}\n\nfunction writeSse(response: ServerResponse, event: string, value: unknown): void {\n response.write(`event: ${event}\\ndata: ${JSON.stringify(value)}\\n\\n`);\n}\n\n/**\n * Client-neutral HTTP and WebSocket boundary for the process-local headless hub.\n * It deliberately delegates every session operation to HeadlessHub, so transport\n * clients cannot create a second session backend or bypass its lifecycle.\n */\nexport async function serveHeadlessServer(options: HeadlessServerOptions): Promise<HeadlessServer> {\n const clients = new Set<Client>();\n const scopedProtocols = new Set<Awaited<ReturnType<typeof createHeadlessProtocol>>>();\n const sse = new Map<ServerResponse, () => boolean>();\n const desktopAuthorized = (request: IncomingMessage): boolean => {\n const proof = request.headers['x-doompi-desktop'];\n return (\n typeof proof === 'string' &&\n options.headlessHub.computerUse?.authorize?.(new Headers({ 'x-doompi-desktop': proof })) === true\n );\n };\n let closed = false;\n const webSockets = new WebSocketServer({ noServer: true });\n /**\n * A recorded session is dormant exactly while the hub has no session for its\n * id, so reviving one needs no bookkeeping beyond the hub itself.\n */\n const dormant = (): readonly OpenSessionRecord[] =>\n (options.dormantSessions?.() ?? []).filter((record) => options.headlessHub.session(record.sessionId) === undefined);\n const protocol = await createHeadlessProtocol({\n hub: options.headlessHub,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n });\n const sessionMcpStateDir =\n options.sessionMcpStateDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'doompi-session-mcp-'));\n const sessionMcp = createSessionMcpRoutes({\n headlessHub: options.headlessHub,\n publicOrigin: options.sessionMcpPublicOrigin ?? (() => undefined),\n publicOriginRevision: options.sessionMcpPublicOriginRevision,\n onNotice: options.onNotice,\n isSessionPersisted: options.isSessionPersisted,\n activityStore: createSessionMcpActivityStore(sessionMcpStateDir),\n conversationStore: createSessionMcpConversationStore(sessionMcpStateDir),\n registrationStore: createSessionMcpRegistrationStore({ stateDir: sessionMcpStateDir, onNotice: options.onNotice }),\n });\n /** Sessions being restarted, keyed by id, settled once the reopen succeeds or fails. */\n const restarting = new Map<string, Promise<void>>();\n const server = createServer((request, response) => {\n void handleRequest(request, response).catch((error: unknown) => {\n if (response.headersSent) {\n response.destroy();\n return;\n }\n options.onNotice?.(`Headless request failed: ${harnessErrorMessage(error)}`);\n json(response, 500, { error: 'Internal server error.' });\n });\n });\n\n const unsubscribe = options.headlessHub.onEvent((event) => {\n const frame = eventFrame(event);\n const sessionId = event.kind === 'upsert' ? event.session.id : 'sessionId' in event ? event.sessionId : undefined;\n for (const [response, native] of sse) {\n if (\n (sessionId !== undefined && options.headlessHub.computerUse?.ownsSession?.(sessionId)) ||\n frame.type === 'computer_use_state'\n ) {\n if (!native()) continue;\n }\n writeSse(response, String(frame.type), frame);\n }\n });\n\n async function handleRequest(request: IncomingMessage, response: ServerResponse): Promise<void> {\n const url = requestPath(request);\n if (url.pathname === '/api/health' && request.method === 'GET') {\n json(response, 200, {\n ok: true,\n role: HEALTH_ROLE,\n protocol: PROTOCOL_VERSION,\n sessions: options.headlessHub.snapshot().length,\n });\n return;\n }\n const scopedSession = /^\\/api\\/workspaces\\/[^/]+\\/sessions\\/([^/]+)(?:\\/|$)/u.exec(url.pathname)?.[1];\n if (\n scopedSession &&\n options.headlessHub.computerUse?.ownsSession?.(decodeURIComponent(scopedSession)) &&\n !desktopAuthorized(request)\n ) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n if (isPublicSessionMcpRoute(request.method ?? 'GET', url.pathname)) {\n const sessionMcpAbort = new AbortController();\n const abortSessionMcp = (): void => {\n if (!response.writableEnded) sessionMcpAbort.abort();\n };\n response.once('close', abortSessionMcp);\n const publicSessionMcp = await sessionMcp.handlePublic(webRequest(request, url, sessionMcpAbort.signal));\n if (publicSessionMcp !== undefined) {\n try {\n await writeResponse(response, publicSessionMcp);\n } finally {\n response.off('close', abortSessionMcp);\n }\n return;\n }\n response.off('close', abortSessionMcp);\n }\n if (!authorized(request, options.token)) {\n json(response, 401, { error: 'Unauthorized.' });\n return;\n }\n // A restart closes the session before reopening it under the same id. Any session-scoped\n // request that lands in that gap, such as a plugin's poll, waits for the reopened session.\n const reopening = scopedSession === undefined ? undefined : restarting.get(decodeURIComponent(scopedSession));\n if (reopening !== undefined && options.headlessHub.session(decodeURIComponent(scopedSession!)) === undefined)\n await reopening;\n if (isSessionMcpHostRoute(url.pathname)) {\n const hostSessionMcp = await sessionMcp.handleHost(webRequest(request, url));\n if (hostSessionMcp !== undefined) {\n await writeResponse(response, hostSessionMcp);\n return;\n }\n }\n if (url.pathname === '/api/remote' || url.pathname.startsWith('/api/remote/')) {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined && name !== 'authorization' && name !== 'x-doompi-token')\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n const result = await options.headlessHub.requestApi(\n { scope: 'global' },\n 'remote',\n new Request(`http://doompi.local${url.pathname.slice('/api/remote'.length)}${url.search}`, {\n method: request.method,\n headers,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n await writeResponse(response, result);\n return;\n }\n if (url.pathname === '/api/telemetry/browser' && request.method === 'POST') {\n const body = JSON.parse(new TextDecoder().decode(await readBody(request))) as { v?: unknown; events?: unknown };\n if (body.v !== 1 || !Array.isArray(body.events) || body.events.length > 10) {\n json(response, 400, { error: 'Invalid browser telemetry batch.' });\n return;\n }\n for (const event of body.events) {\n if (\n !event ||\n typeof event !== 'object' ||\n typeof event.name !== 'string' ||\n !/^web\\.browser\\.[a-z_]{1,40}$/u.test(event.name)\n )\n continue;\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent(event.name, {\n ...(typeof event.duration_ms === 'number' && Number.isFinite(event.duration_ms) && event.duration_ms >= 0\n ? { duration_ms: event.duration_ms }\n : {}),\n ...(typeof event.count === 'number' && Number.isFinite(event.count) && event.count >= 0\n ? { count: event.count }\n : {}),\n }),\n );\n }\n json(response, 200, { ok: true });\n return;\n }\n if (url.pathname === '/api/compositions' && request.method === 'GET') {\n json(response, 200, options.compositions?.() ?? { workspaces: [] });\n return;\n }\n if (\n (url.pathname.startsWith('/api/web-plugins/') ||\n url.pathname === '/bundle-manifest.json' ||\n url.pathname.startsWith('/bundle-assets/')) &&\n options.requestAsset\n ) {\n const result = await options.requestAsset(new Request(url, { method: request.method }));\n if (result) {\n await writeResponse(response, result);\n return;\n }\n }\n if (url.pathname === '/api/directories/children' && request.method === 'GET') {\n const listing = await directoryChildren(url.searchParams.get('path'));\n if (listing === undefined) json(response, 404, { error: 'That folder cannot be read.' });\n else json(response, 200, listing);\n return;\n }\n if (url.pathname === '/api/directories' && request.method === 'GET') {\n json(response, 200, {\n directories: await directorySuggestions(url.searchParams.get('q') ?? '', options.headlessHub.snapshot()),\n });\n return;\n }\n // Verified browser bundles can remain active across a server upgrade. Keep\n // their former create route working while they refresh to workspace routes.\n if (url.pathname === '/api/sessions' && request.method === 'POST') {\n const body = parseJson(await readBody(request));\n if (\n !body ||\n typeof body !== 'object' ||\n !('cwd' in body) ||\n typeof body.cwd !== 'string' ||\n !body.cwd.trim() ||\n ('name' in body && typeof body.name !== 'string')\n ) {\n json(response, 400, { error: 'A session needs a working directory and an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: body.cwd,\n name: 'name' in body ? String(body.name) : path.basename(body.cwd),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n const workspaceSessions = /^\\/api\\/workspaces\\/([^/]+)\\/sessions$/u.exec(url.pathname);\n if (workspaceSessions) {\n const workspaceId = decodeURIComponent(workspaceSessions[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (request.method === 'GET') {\n json(response, 200, {\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter((session) => session.workspaceId === workspaceId)\n .map(sessionView),\n ...dormant()\n .filter((record) => record.workspaceId === workspaceId)\n .map(dormantView),\n ],\n });\n return;\n }\n if (request.method === 'POST') {\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n if (!body || typeof body !== 'object' || ('name' in body && typeof body.name !== 'string')) {\n json(response, 400, { error: 'A session accepts an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: workspace.root,\n name: 'name' in body ? String(body.name) : path.basename(workspace.root),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n }\n if (url.pathname === '/api/events' && request.method === 'GET') {\n response.writeHead(200, {\n 'cache-control': 'no-cache',\n connection: 'keep-alive',\n 'content-type': 'text/event-stream; charset=utf-8',\n });\n sse.set(response, () => desktopAuthorized(request));\n response.on('close', () => sse.delete(response));\n writeSse(response, 'sessions_snapshot', {\n type: 'sessions_snapshot',\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter(\n (session) => !options.headlessHub.computerUse?.ownsSession?.(session.id) || desktopAuthorized(request),\n )\n .map(sessionView),\n ...dormant().map(dormantView),\n ],\n });\n writeSse(response, 'workspaces_snapshot', {\n type: 'workspaces_snapshot',\n workspaces: options.headlessHub.workspaces(),\n });\n return;\n }\n if (url.pathname === '/api/workspaces') {\n if (request.method === 'GET') {\n json(response, 200, { workspaces: options.headlessHub.workspaces() });\n return;\n }\n if (request.method === 'POST') {\n const admission = parseWorkspaceAdmission(parseJson(await readBody(request)));\n if ('error' in admission) {\n json(response, 400, admission);\n return;\n }\n let workspace: Awaited<ReturnType<HeadlessHub['admitWorkspace']>>;\n try {\n workspace = await options.headlessHub.admitWorkspace(admission);\n } catch (error) {\n json(response, 422, { error: error instanceof Error ? error.message : String(error) });\n return;\n }\n json(response, 201, { workspace });\n return;\n }\n }\n const workspaceHistoryMatch = /^\\/api\\/workspaces\\/([^/]+)\\/history$/u.exec(url.pathname);\n if (workspaceHistoryMatch && request.method === 'GET' && options.workspaceHistory) {\n const workspaceId = decodeURIComponent(workspaceHistoryMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n json(response, 200, { sessions: await options.workspaceHistory(workspaceId) });\n return;\n }\n const workspaceResumeMatch = /^\\/api\\/workspaces\\/([^/]+)\\/resume$/u.exec(url.pathname);\n if (workspaceResumeMatch && request.method === 'POST' && options.resumeWorkspaceSession) {\n const workspaceId = decodeURIComponent(workspaceResumeMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeWorkspaceSession(workspaceId, targetSessionId) });\n return;\n }\n const workspaceMatch = /^\\/api\\/workspaces\\/([^/]+)$/u.exec(url.pathname);\n if (workspaceMatch && request.method === 'GET') {\n const workspace = options.headlessHub\n .workspaces()\n .find((entry) => entry.id === decodeURIComponent(workspaceMatch[1]));\n json(response, workspace ? 200 : 404, workspace ? { workspace } : { error: 'Workspace not found.' });\n return;\n }\n if (workspaceMatch && request.method === 'DELETE') {\n const id = decodeURIComponent(workspaceMatch[1]);\n if (!options.headlessHub.workspaces().some((workspace) => workspace.id === id)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (\n options.headlessHub.snapshot().some((session) => session.workspaceId === id) ||\n dormant().some((session) => session.workspaceId === id)\n ) {\n json(response, 409, { error: 'Workspace still has sessions.' });\n return;\n }\n await options.headlessHub.removeWorkspace(id);\n json(response, 200, { ok: true });\n return;\n }\n const pluginMatch = DOOM_PACKAGE_API_PATH_PATTERN.exec(url.pathname);\n if (pluginMatch !== null && request.method !== 'CONNECT') {\n const workspaceId = pluginMatch[1] === undefined ? undefined : decodeURIComponent(pluginMatch[1]);\n const sessionId = pluginMatch[2] === undefined ? undefined : decodeURIComponent(pluginMatch[2]);\n if (workspaceId !== undefined && !options.headlessHub.workspaces().some((entry) => entry.id === workspaceId)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (sessionId !== undefined && options.headlessHub.session(sessionId)?.workspaceId !== workspaceId) {\n // A stopped session still shows the composition it last published, so its context detail\n // is served from the file it wrote. Nothing else answers until it is woken.\n const stopped = dormant().some(\n (record) => record.sessionId === sessionId && record.workspaceId === workspaceId,\n );\n if (stopped && pluginMatch[3] === CONTEXT_API_BASE_PATH && request.method === 'GET') {\n const detail = await createContextApi({ sessionId, environment: process.env }).fetch(\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`),\n );\n const body = (await detail.json()) as { error?: string };\n // The detail file is only kept while the session runs, so a stopped session usually has none.\n if (readContextDetail(sessionId, process.env) === undefined)\n json(response, 404, { error: 'This session is stopped. Wake it to read this item.' });\n else json(response, detail.status, body);\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n const mount: DoomApiMount =\n sessionId !== undefined\n ? { scope: 'session', sessionId }\n : workspaceId !== undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'global' };\n const basePath = pluginMatch[3] === undefined ? 'settings' : decodeURIComponent(pluginMatch[3]);\n if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(basePath)) {\n json(response, 400, { error: 'Invalid package API base path.' });\n return;\n }\n if (pluginMatch[3] === 'settings' || (sessionId !== undefined && basePath === 'settings')) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const headers = new Headers();\n // Only the authenticated loopback proxy knows the server token and may\n // forward caller stamps. Browser-supplied stamps remain untrusted.\n const trustedCaller = options.token !== undefined && authorized(request, options.token);\n for (const [name, value] of Object.entries(request.headers)) {\n if (\n value !== undefined &&\n !['host', 'authorization', 'x-doompi-token'].includes(name) &&\n (trustedCaller || !DOOM_API_CALLER_HEADERS.includes(name as (typeof DOOM_API_CALLER_HEADERS)[number]))\n )\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n if (!trustedCaller) {\n headers.set(DOOM_API_CALLER_LOCALITY_HEADER, 'local');\n headers.set(DOOM_API_CALLER_STEP_UP_HEADER, 'not-required');\n }\n const abort = new AbortController();\n const disconnected = (): void => {\n if (!response.writableEnded) abort.abort();\n };\n response.once('close', disconnected);\n try {\n const started = performance.now();\n const attributes = {\n scope: mount.scope,\n 'plugin.name': basePath,\n 'http.operation': request.method,\n ...(mount.scope === 'workspace' ? { 'workspace.id': mount.workspaceId } : {}),\n ...(mount.scope === 'session' ? { 'session.id': mount.sessionId } : {}),\n };\n const dispatch = async () =>\n options.headlessHub.requestApi(\n mount,\n basePath,\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`, {\n method: request.method,\n headers,\n signal: abort.signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n const result = options.telemetry\n ? await options.telemetry.runInSpan('doompi_server.plugin.request', attributes, dispatch)\n : await dispatch();\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent('doompi_server.plugin.response', {\n ...attributes,\n status: result.status,\n durationMs: performance.now() - started,\n }),\n options.onNotice,\n );\n await writeResponse(response, result);\n } finally {\n response.off('close', disconnected);\n }\n return;\n }\n const sessionMatch = /^\\/api\\/workspaces\\/([^/]+)\\/sessions\\/([^/]+)(?:\\/(.*))?$/u.exec(url.pathname);\n if (sessionMatch === null) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const sessionId = decodeURIComponent(sessionMatch[2]);\n const workspaceId = decodeURIComponent(sessionMatch[1]);\n const session = options.headlessHub.session(sessionId);\n const suffix = sessionMatch[3] === undefined ? '' : `/${sessionMatch[3]}`;\n if (suffix === '/transcript' && request.method === 'GET' && options.readDormantTranscript) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n let transcriptRequest: TranscriptPageRequest;\n try {\n transcriptRequest = parseTranscriptRequest(url);\n } catch (error) {\n json(response, 400, { error: error instanceof Error ? error.message : 'Invalid transcript request.' });\n return;\n }\n try {\n const page = await options.readDormantTranscript(record, transcriptRequest, BACKGROUND_CONTEXT);\n json(response, 200, page);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n const status = message === 'STALE_TRANSCRIPT_CURSOR' ? 409 : 422;\n json(response, status, {\n error: status === 409 ? 'STALE_TRANSCRIPT_CURSOR' : 'Saved transcript is unavailable.',\n });\n }\n return;\n }\n // Revive is the one session route that answers before a runtime exists: it\n // is what creates one.\n if (sessionMatch[3] === 'revive' && request.method === 'POST' && options.reviveSession) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n await options.reviveSession(record);\n json(response, 200, { ok: true });\n return;\n }\n if (session === undefined || session.workspaceId !== workspaceId) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (request.method === 'DELETE' && record !== undefined && options.removeDormantSession !== undefined) {\n sessionMcp.closeSessionBinding(record.sessionId);\n await options.removeDormantSession(record);\n options.headlessHub.notifySessionRemoved(record.sessionId);\n json(response, 200, { ok: true });\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n if (suffix === '' && request.method === 'GET') {\n json(response, 200, sessionView(session));\n return;\n }\n if (suffix === '' && request.method === 'DELETE') {\n sessionMcp.closeSessionBinding(sessionId);\n await options.headlessHub.closeSession(sessionId);\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/history' && request.method === 'GET' && options.sessionHistory) {\n json(response, 200, { sessions: await options.sessionHistory(session) });\n return;\n }\n if (suffix === '/avatar' && request.method === 'GET') {\n const avatar = options.headlessHub.sessionAvatar(sessionId);\n if (avatar === undefined) {\n json(response, 404, { error: 'This session has no avatar.' });\n return;\n }\n const current = url.searchParams.get('v') === session.profile?.iconVersion;\n response.writeHead(200, {\n 'content-type': avatar.mimeType,\n 'content-length': String(avatar.bytes.byteLength),\n 'cache-control': current ? 'private, max-age=31536000, immutable' : 'no-store',\n 'x-content-type-options': 'nosniff',\n });\n response.end(avatar.bytes);\n return;\n }\n if (suffix === '/file' && request.method === 'GET') {\n await writeResponse(response, await sessionFile(session, url.searchParams.get('path')));\n return;\n }\n if (suffix === '/restart' && request.method === 'POST' && options.restartSession) {\n const restart = options.restartSession(session);\n // Settled either way: a failed restart leaves the session dormant, and waiters then see that.\n const settled = restart.then(\n () => undefined,\n () => undefined,\n );\n restarting.set(sessionId, settled);\n try {\n await restart;\n } finally {\n if (restarting.get(sessionId) === settled) restarting.delete(sessionId);\n }\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/resume' && request.method === 'POST' && options.resumeSession) {\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n if (options.headlessHub.computerUse?.ownsSession?.(targetSessionId) && !desktopAuthorized(request)) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeSession(session, targetSessionId) });\n return;\n }\n if (suffix === '/channels' && request.method === 'GET') {\n json(response, 200, {\n channels: options.headlessHub\n .channelFrames(sessionId)\n .filter((frame) => frame.type !== 'computer_use_state' || desktopAuthorized(request)),\n });\n return;\n }\n const channelMatch = /^\\/channel\\/([^/]+)$/u.exec(suffix);\n if (channelMatch !== null && request.method === 'POST') {\n const frameType = decodeURIComponent(channelMatch[1]);\n const connectionId = request.headers['x-doompi-connection'];\n options.headlessHub.receiveChannel(\n sessionId,\n frameType,\n parseJson(await readBody(request)),\n typeof connectionId === 'string' ? connectionId : 'http',\n desktopAuthorized(request),\n );\n json(response, 202, { ok: true });\n return;\n }\n json(response, 404, { error: 'Not found.' });\n }\n\n server.on('upgrade', (request, socket, head) => {\n const url = requestPath(request);\n const mount = parseDoomSocketPath(url.pathname);\n if (!mount) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (!authorized(request, options.token)) {\n socket.write('HTTP/1.1 401 Unauthorized\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (\n mount.scope !== 'global' &&\n (!options.headlessHub.workspaces().some((entry) => entry.id === mount.workspaceId && entry.available !== false) ||\n (mount.scope === 'session' && options.headlessHub.session(mount.sessionId)?.workspaceId !== mount.workspaceId))\n ) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n const prepare =\n mount.scope === 'global' && options.headlessHub.computerUse === undefined\n ? Promise.resolve(protocol)\n : createHeadlessProtocol({\n hub: options.headlessHub,\n mount,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n authorizeSession: (id) => !options.headlessHub.computerUse?.ownsSession?.(id) || desktopAuthorized(request),\n authorizeDesktop: () => desktopAuthorized(request),\n });\n void prepare\n .then(async (selected) => {\n if (closed || socket.destroyed) {\n if (selected !== protocol) await selected.close();\n socket.destroy();\n return;\n }\n if (selected !== protocol) {\n scopedProtocols.add(selected);\n socket.once('close', () => {\n void selected.close().finally(() => scopedProtocols.delete(selected));\n });\n }\n webSockets.handleUpgrade(request, socket, head, (client) => {\n webSockets.emit('connection', client, selected);\n });\n })\n .catch(() => {\n socket.destroy();\n });\n });\n webSockets.on('connection', (socket, selected: typeof protocol) => {\n const handler = selected.accept(socket);\n if (!handler) return;\n const client: Client = { socket, handler };\n clients.add(client);\n socket.on('message', (data) => {\n if (Buffer.isBuffer(data)) handler.onData(data);\n else if (Array.isArray(data)) handler.onData(Buffer.concat(data));\n else handler.onData(new Uint8Array(data as ArrayBuffer));\n });\n socket.on('close', () => {\n clients.delete(client);\n handler.onClose();\n });\n socket.on('error', (error) => handler.onError(error));\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(options.port, options.host ?? '127.0.0.1', () => resolve());\n });\n const address = server.address();\n if (address === null || typeof address === 'string') {\n await new Promise<void>((resolve) => server.close(() => resolve()));\n throw new Error('The headless server did not expose a TCP address.');\n }\n const host = options.host ?? '127.0.0.1';\n const url = `http://${host}:${address.port}`;\n return {\n url,\n sessionReservations: sessionMcp.reservations,\n async close() {\n if (closed) return;\n closed = true;\n unsubscribe();\n for (const response of sse.keys()) response.end();\n sse.clear();\n for (const client of clients) client.socket.terminate();\n clients.clear();\n sessionMcp.close();\n if (options.sessionMcpStateDir === undefined)\n await fs.promises.rm(sessionMcpStateDir, { recursive: true, force: true });\n await Promise.all([protocol.close(), ...[...scopedProtocols].map((selected) => selected.close())]);\n webSockets.close();\n server.closeAllConnections();\n await new Promise<void>((resolve, reject) =>\n server.close((error) => (error === undefined ? resolve() : reject(error))),\n );\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,gCACX;AAEF,MAAM,cAAc;AACpB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAC/B,MAAM,6BAA6B;AACnC,MAAM,2BAA2B;AACjC,MAAM,cAAc;AACpB,MAAM,4BAA4B;AAClC,MAAM,yBAAyB;AAC/B,MAAM,6BAA+D;CACnE,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QA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EAC3C,OAAO,KAAK,SAAS,MAAM;EAC3B,OAAO,OAAO,QAAQ,MAAM,QAAQ,QAAQ,mBAAmB,QAAQ,CAAC;CAC1E,CAAC;CACD,MAAM,UAAU,OAAO,QAAQ;CAC/B,IAAI,YAAY,QAAQ,OAAO,YAAY,UAAU;EACnD,MAAM,IAAI,SAAe,YAAY,OAAO,YAAY,QAAQ,CAAC,CAAC;EAClE,MAAM,IAAI,MAAM,mDAAmD;CACrE;CAGA,OAAO;EACL,KAAA,UAHW,QAAQ,QAAQ,YACF,GAAG,QAAQ;EAGpC,qBAAqB,WAAW;EAChC,MAAM,QAAQ;GACZ,IAAI,QAAQ;GACZ,SAAS;GACT,YAAY;GACZ,KAAK,MAAM,YAAY,IAAI,KAAK,GAAG,SAAS,IAAI;GAChD,IAAI,MAAM;GACV,KAAK,MAAM,UAAU,SAAS,OAAO,OAAO,UAAU;GACtD,QAAQ,MAAM;GACd,WAAW,MAAM;GACjB,IAAI,QAAQ,uBAAuB,KAAA,GACjC,MAAML,QAAAA,QAAG,SAAS,GAAG,oBAAoB;IAAE,WAAW;IAAM,OAAO;GAAK,CAAC;GAC3E,MAAM,QAAQ,IAAI,CAAC,SAAS,MAAM,GAAG,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,KAAK,aAAa,SAAS,MAAM,CAAC,CAAC,CAAC;GACjG,WAAW,MAAM;GACjB,OAAO,oBAAoB;GAC3B,MAAM,IAAI,SAAe,SAAS,WAChC,OAAO,OAAO,UAAW,UAAU,KAAA,IAAY,QAAQ,IAAI,OAAO,KAAK,CAAE,CAC3E;EACF;CACF;AACF"}
1
+ {"version":3,"file":"headlessServer.cjs","names":["fs","path","os","Readable","pipeline","WebSocketServer","createHeadlessProtocol","createSessionMcpRoutes","createSessionMcpActivityStore","createSessionMcpConversationStore","createSessionMcpRegistrationStore","createServer","harnessErrorMessage","isPublicSessionMcpRoute","isSessionMcpHostRoute","createContextApi","readContextDetail","DOOM_API_CALLER_HEADERS","DOOM_API_CALLER_LOCALITY_HEADER","DOOM_API_CALLER_STEP_UP_HEADER","BACKGROUND_CONTEXT","parseDoomSocketPath"],"sources":["../src/server/headlessServer.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { Context } from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { WebSocket } from 'ws';\nimport { WebSocketServer } from 'ws';\n\nimport { API_BASE_PATH as CONTEXT_API_BASE_PATH } from '../constants/contextApi';\nimport {\n DOOM_API_CALLER_HEADERS,\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n parseDoomSocketPath,\n type DoomApiMount,\n} from '../exports/packageApi';\nimport type { TranscriptPage, TranscriptPageRequest } from '../exports/sessionProtocol';\nimport type { DoomHubSessionReservations } from '../schemas/hubChannel';\nimport { readContextDetail } from '../services/contextDetailStore';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport { observe, type ServerTelemetry } from '../services/serverTelemetry';\nimport { createSessionMcpActivityStore } from '../services/sessionMcpActivity';\nimport { createSessionMcpConversationStore } from '../services/sessionMcpConversations';\nimport { createSessionMcpRegistrationStore } from '../services/sessionMcpRegistrationStore';\nimport type { SavedSession } from '../services/sqliteSessionHistory';\nimport { createContextApi } from './contextApi';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession, HeadlessWorkspaceAdmission } from './headlessHub';\nimport { createHeadlessProtocol } from './headlessProtocol';\nimport { createSessionMcpRoutes, isPublicSessionMcpRoute, isSessionMcpHostRoute } from './sessionMcpRoutes';\n\n/**\n * The canonical public shape of a package API request, as dispatch reads it.\n *\n * Groups: workspace id, session id, plugin base path, and the remainder handed\n * to the package. `settings` is the host's own API and sits beside `plugins`\n * rather than under it.\n *\n * Exported so the browser's URL construction can be pinned against it. The two\n * are written independently, in halves of this package that may not import each\n * other, and a disagreement between them is not a 404 from the route: the\n * service worker answers an unrecognised path out of the signed bundle cache,\n * so the symptom appears nowhere near the cause.\n */\nexport const DOOM_PACKAGE_API_PATH_PATTERN =\n /^\\/api(?:\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?)?\\/(?:plugins\\/([^/]+)|settings)(?:\\/(.*))?$/u;\n\nconst HEALTH_ROLE = 'hub';\nconst PROTOCOL_VERSION = 1;\nconst MAX_BODY_BYTES = 8 * 1024 * 1024;\nconst MAX_SESSION_FILE_BYTES = 25 * 1024 * 1024;\nconst DIRECTORY_SUGGESTION_LIMIT = 12;\nconst DIRECTORY_CHILDREN_LIMIT = 500;\nconst HOME_PREFIX = '~';\nconst WORKSPACE_NAME_MAX_LENGTH = 80;\nconst WORKSPACE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/u;\nconst SESSION_FILE_CONTENT_TYPES: Readonly<Record<string, string>> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.m4v': 'video/mp4',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.pdf': 'application/pdf',\n};\n\nexport interface HeadlessServerOptions {\n headlessHub: HeadlessHub;\n port: number;\n host?: string;\n /** Requests other than health require this bearer token when set. */\n token?: string;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n compositions?: () => unknown;\n requestAsset?: (request: Request) => Promise<Response | undefined>;\n sessionHistory?: (session: HeadlessHubSession) => Promise<SavedSession[]>;\n workspaceHistory?: (workspaceId: string) => Promise<SavedSession[]>;\n resumeWorkspaceSession?: (workspaceId: string, targetSessionId: string) => Promise<string>;\n readDormantTranscript?: (\n record: OpenSessionRecord,\n request: TranscriptPageRequest,\n context: Context,\n ) => Promise<TranscriptPage>;\n restartSession?: (session: HeadlessHubSession) => Promise<void>;\n resumeSession?: (session: HeadlessHubSession, targetSessionId: string) => Promise<string>;\n /** Recorded sessions this server has not reopened, surfaced so a client can ask for one. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n removeDormantSession?: (record: OpenSessionRecord) => void | Promise<void>;\n reviveSession?: (record: OpenSessionRecord) => Promise<void>;\n /** Trusted HTTPS origin advertised for public session MCP and OAuth endpoints. */\n sessionMcpPublicOrigin?: () => string | undefined;\n /** Durable state directory for verified Session MCP clients. */\n sessionMcpStateDir?: string;\n /** Monotonic exposure revision, including disable/re-enable cycles. */\n sessionMcpPublicOriginRevision?: () => number;\n isSessionPersisted?: (sessionId: string, cwd: string) => boolean;\n}\n\nexport interface HeadlessServer {\n readonly url: string;\n readonly sessionReservations: DoomHubSessionReservations;\n close(): Promise<void>;\n}\n\ntype ProtocolHandler = NonNullable<ReturnType<Awaited<ReturnType<typeof createHeadlessProtocol>>['accept']>>;\ntype Client = { socket: WebSocket; handler: ProtocolHandler };\n\nfunction sessionView(session: HeadlessHubSession): Record<string, unknown> {\n return {\n id: session.id,\n workspaceId: session.workspaceId,\n webComposition: session.webComposition,\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n ...(session.git === undefined ? {} : { git: { ...session.git } }),\n ...(session.profile === undefined ? {} : { profile: { ...session.profile } }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.pendingSetups === undefined ? {} : { pendingSetups: session.pendingSetups }),\n ...(session.activity === undefined ? {} : { activity: { ...session.activity } }),\n };\n}\n\n/** The dormant counterpart of `sessionView`; same shape, no runtime behind it. */\nfunction dormantView(record: OpenSessionRecord): Record<string, unknown> {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'detached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n };\n}\n\nfunction json(response: ServerResponse, status: number, value: unknown): void {\n const body = JSON.stringify(value);\n response.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'content-length': Buffer.byteLength(body),\n });\n response.end(body);\n}\n\nfunction authorized(request: IncomingMessage, token: string | undefined): boolean {\n if (token === undefined) return true;\n const authorization = request.headers.authorization;\n if (authorization?.startsWith('Bearer ') && authorization.slice('Bearer '.length) === token) return true;\n const header = request.headers['x-doompi-token'];\n if (typeof header === 'string' && header === token) return true;\n try {\n return new URL(request.url ?? '/', 'http://doompi.local').searchParams.get('token') === token;\n } catch {\n return false;\n }\n}\n\nfunction requestPath(request: IncomingMessage): URL {\n return new URL(request.url ?? '/', 'http://doompi.local');\n}\n\nfunction parseTranscriptRequest(url: URL): TranscriptPageRequest {\n const request: TranscriptPageRequest = {};\n const cursor = url.searchParams.get('cursor');\n const direction = url.searchParams.get('direction');\n const limit = url.searchParams.get('limit');\n if (cursor !== null) request.cursor = cursor;\n if (direction !== null) {\n if (direction !== 'older' && direction !== 'newer') throw new Error('Invalid transcript direction');\n request.direction = direction;\n }\n if (limit !== null) {\n if (!/^\\d+$/u.test(limit)) throw new Error('Invalid transcript page limit');\n const parsed = Number(limit);\n if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 100) throw new Error('Invalid transcript page limit');\n request.limit = parsed;\n }\n return request;\n}\n\nasync function sessionFile(session: HeadlessHubSession, requestedPath: string | null): Promise<Response> {\n if (!requestedPath || requestedPath.includes('\\0'))\n return Response.json({ error: 'Invalid session file path.' }, { status: 400 });\n let root: string;\n let filePath: string;\n try {\n root = await fs.promises.realpath(session.cwd);\n filePath = await fs.promises.realpath(path.resolve(root, requestedPath));\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n const contained = path.relative(root, filePath);\n if (contained === '..' || contained.startsWith(`..${path.sep}`) || path.isAbsolute(contained))\n return Response.json({ error: 'Session file is outside the working directory.' }, { status: 403 });\n let handle: fs.promises.FileHandle;\n try {\n handle = await fs.promises.open(filePath, 'r');\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n try {\n const stat = await handle.stat();\n if (!stat.isFile()) return Response.json({ error: 'Session file not found.' }, { status: 404 });\n if (stat.size > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n const bytes = await handle.readFile();\n if (bytes.byteLength > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n return new Response(bytes, {\n headers: {\n 'content-type': SESSION_FILE_CONTENT_TYPES[path.extname(filePath).toLowerCase()] ?? 'application/octet-stream',\n 'content-length': String(bytes.byteLength),\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n },\n });\n } finally {\n await handle.close();\n }\n}\n\n/** Expands a leading `~` the way a shell would, so typed paths match what the user sees in a terminal. */\nfunction expandHome(value: string): string {\n if (value === HOME_PREFIX) return os.homedir();\n return value.startsWith(`${HOME_PREFIX}${path.sep}`) ? path.join(os.homedir(), value.slice(2)) : value;\n}\n\n/**\n * Validates an add-workspace request. A name alone asks for a new default folder,\n * so it must be safe to use as one folder name.\n */\nfunction parseWorkspaceAdmission(body: unknown): HeadlessWorkspaceAdmission | { error: string } {\n if (typeof body !== 'object' || body === null) return { error: 'A workspace root or name is required.' };\n const record = body as Record<string, unknown>;\n if (record.root !== undefined && typeof record.root !== 'string')\n return { error: 'The workspace root must be text.' };\n if (record.name !== undefined && typeof record.name !== 'string')\n return { error: 'The workspace name must be text.' };\n const root =\n typeof record.root === 'string' && record.root.trim() !== '' ? expandHome(record.root.trim()) : undefined;\n const name = typeof record.name === 'string' && record.name.trim() !== '' ? record.name.trim() : undefined;\n if (root === undefined && name === undefined) return { error: 'A workspace root or name is required.' };\n if (\n name !== undefined &&\n (name.length > WORKSPACE_NAME_MAX_LENGTH || !WORKSPACE_NAME_PATTERN.test(name) || name.includes('..'))\n )\n return {\n error: `Workspace names use letters, numbers, spaces, dots, dashes, or underscores (up to ${String(WORKSPACE_NAME_MAX_LENGTH)} characters).`,\n };\n return { ...(root === undefined ? {} : { root }), ...(name === undefined ? {} : { name }) };\n}\n\nasync function directorySuggestions(query: string, sessions: readonly HeadlessHubSession[]): Promise<string[]> {\n const typed = expandHome(query.trim());\n if (typed === '') return [];\n const matches = (value: string): boolean => value.toLowerCase().includes(typed.toLowerCase());\n const known = [...new Set([process.cwd(), ...sessions.map((session) => session.cwd)])].filter(matches);\n const candidates = path.isAbsolute(typed)\n ? [typed]\n : typed.includes(path.sep)\n ? [path.resolve(process.cwd(), typed)]\n : [path.join(path.dirname(process.cwd()), typed), path.join(process.cwd(), typed)];\n const completed: string[] = [];\n for (const candidate of candidates) {\n const drilling = typed.endsWith(path.sep);\n const parent = drilling ? candidate : path.dirname(candidate);\n const partial = drilling ? '' : path.basename(candidate).toLowerCase();\n try {\n const entries = await fs.promises.readdir(parent, { withFileTypes: true });\n completed.push(\n ...entries\n .filter((entry) => entry.isDirectory() && entry.name.toLowerCase().includes(partial))\n .map((entry) => path.join(parent, entry.name)),\n );\n } catch {\n // A missing or unreadable parent simply has no completions.\n }\n }\n return [...new Set([...known, ...completed.sort((left, right) => left.localeCompare(right))])].slice(\n 0,\n DIRECTORY_SUGGESTION_LIMIT,\n );\n}\n\n/**\n * Lists the visible child directories of one folder for the workspace folder browser.\n * Resolves undefined for a relative, missing, or unreadable path.\n */\nasync function directoryChildren(\n requested: string | null,\n): Promise<{ path: string; parent?: string; directories: string[] } | undefined> {\n const directory = requested === null || requested.trim() === '' ? os.homedir() : expandHome(requested.trim());\n if (!path.isAbsolute(directory)) return undefined;\n const resolved = path.resolve(directory);\n let entries: fs.Dirent[];\n try {\n entries = await fs.promises.readdir(resolved, { withFileTypes: true });\n } catch {\n return undefined;\n }\n const directories = entries\n .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))\n .map((entry) => path.join(resolved, entry.name))\n .sort((left, right) => left.localeCompare(right))\n .slice(0, DIRECTORY_CHILDREN_LIMIT);\n const parent = path.dirname(resolved);\n return { path: resolved, ...(parent === resolved ? {} : { parent }), directories };\n}\n\nasync function readBody(request: IncomingMessage): Promise<Uint8Array> {\n const chunks: Buffer[] = [];\n let size = 0;\n for await (const chunk of request) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n size += buffer.byteLength;\n if (size > MAX_BODY_BYTES) throw new Error('Request body is too large.');\n chunks.push(buffer);\n }\n return Buffer.concat(chunks);\n}\n\nfunction parseJson(body: Uint8Array): unknown {\n if (body.byteLength === 0) return {};\n return JSON.parse(Buffer.from(body).toString('utf8')) as unknown;\n}\n\nfunction webRequest(request: IncomingMessage, url: URL, signal?: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined) headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n return new Request(url, {\n method: request.method,\n headers,\n signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : {\n body: Readable.toWeb(request) as never,\n duplex: 'half' as const,\n }),\n });\n}\n\nasync function writeResponse(response: ServerResponse, result: Response): Promise<void> {\n response.writeHead(result.status, Object.fromEntries(result.headers.entries()));\n if (result.body === null) {\n response.end();\n return;\n }\n await pipeline(Readable.fromWeb(result.body as import('node:stream/web').ReadableStream), response);\n}\n\nfunction eventFrame(event: HeadlessHubEvent): Record<string, unknown> {\n switch (event.kind) {\n case 'upsert':\n return { type: 'session_upsert', session: sessionView(event.session) };\n case 'removed':\n return { type: 'session_removed', sessionId: event.sessionId };\n case 'workspace_upsert':\n return { type: 'workspace_upsert', workspace: event.workspace };\n case 'workspace_removed':\n return { type: 'workspace_removed', workspaceId: event.workspaceId };\n case 'channel':\n return {\n type: 'channel_frame',\n frameType: event.frameType,\n sessionId: event.sessionId,\n payload: event.payload,\n ...(event.connectionId === undefined ? {} : { connectionId: event.connectionId }),\n };\n }\n}\n\nfunction writeSse(response: ServerResponse, event: string, value: unknown): void {\n response.write(`event: ${event}\\ndata: ${JSON.stringify(value)}\\n\\n`);\n}\n\n/**\n * Client-neutral HTTP and WebSocket boundary for the process-local headless hub.\n * It deliberately delegates every session operation to HeadlessHub, so transport\n * clients cannot create a second session backend or bypass its lifecycle.\n */\nexport async function serveHeadlessServer(options: HeadlessServerOptions): Promise<HeadlessServer> {\n const clients = new Set<Client>();\n const scopedProtocols = new Set<Awaited<ReturnType<typeof createHeadlessProtocol>>>();\n const sse = new Map<ServerResponse, () => boolean>();\n const desktopAuthorized = (request: IncomingMessage): boolean => {\n const proof = request.headers['x-doompi-desktop'];\n return (\n typeof proof === 'string' &&\n options.headlessHub.computerUse?.authorize?.(new Headers({ 'x-doompi-desktop': proof })) === true\n );\n };\n let closed = false;\n const webSockets = new WebSocketServer({ noServer: true });\n /**\n * A recorded session is dormant exactly while the hub has no session for its\n * id, so reviving one needs no bookkeeping beyond the hub itself.\n */\n const dormant = (): readonly OpenSessionRecord[] =>\n (options.dormantSessions?.() ?? []).filter((record) => options.headlessHub.session(record.sessionId) === undefined);\n const protocol = await createHeadlessProtocol({\n hub: options.headlessHub,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n });\n const sessionMcpStateDir =\n options.sessionMcpStateDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'doompi-session-mcp-'));\n const sessionMcp = createSessionMcpRoutes({\n headlessHub: options.headlessHub,\n publicOrigin: options.sessionMcpPublicOrigin ?? (() => undefined),\n publicOriginRevision: options.sessionMcpPublicOriginRevision,\n onNotice: options.onNotice,\n isSessionPersisted: options.isSessionPersisted,\n activityStore: createSessionMcpActivityStore(sessionMcpStateDir),\n conversationStore: createSessionMcpConversationStore(sessionMcpStateDir),\n registrationStore: createSessionMcpRegistrationStore({ stateDir: sessionMcpStateDir, onNotice: options.onNotice }),\n });\n /** Sessions being restarted, keyed by id, settled once the reopen succeeds or fails. */\n const restarting = new Map<string, Promise<void>>();\n const server = createServer((request, response) => {\n void handleRequest(request, response).catch((error: unknown) => {\n if (response.headersSent) {\n response.destroy();\n return;\n }\n options.onNotice?.(`Headless request failed: ${harnessErrorMessage(error)}`);\n json(response, 500, { error: 'Internal server error.' });\n });\n });\n\n const unsubscribe = options.headlessHub.onEvent((event) => {\n const frame = eventFrame(event);\n const sessionId = event.kind === 'upsert' ? event.session.id : 'sessionId' in event ? event.sessionId : undefined;\n for (const [response, native] of sse) {\n if (\n (sessionId !== undefined && options.headlessHub.computerUse?.ownsSession?.(sessionId)) ||\n frame.type === 'computer_use_state'\n ) {\n if (!native()) continue;\n }\n writeSse(response, String(frame.type), frame);\n }\n });\n\n async function handleRequest(request: IncomingMessage, response: ServerResponse): Promise<void> {\n const url = requestPath(request);\n if (url.pathname === '/api/health' && request.method === 'GET') {\n json(response, 200, {\n ok: true,\n role: HEALTH_ROLE,\n protocol: PROTOCOL_VERSION,\n sessions: options.headlessHub.snapshot().length,\n });\n return;\n }\n const scopedSession = /^\\/api\\/workspaces\\/[^/]+\\/sessions\\/([^/]+)(?:\\/|$)/u.exec(url.pathname)?.[1];\n if (\n scopedSession &&\n options.headlessHub.computerUse?.ownsSession?.(decodeURIComponent(scopedSession)) &&\n !desktopAuthorized(request)\n ) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n if (isPublicSessionMcpRoute(request.method ?? 'GET', url.pathname)) {\n const sessionMcpAbort = new AbortController();\n const abortSessionMcp = (): void => {\n if (!response.writableEnded) sessionMcpAbort.abort();\n };\n response.once('close', abortSessionMcp);\n const publicSessionMcp = await sessionMcp.handlePublic(webRequest(request, url, sessionMcpAbort.signal));\n if (publicSessionMcp !== undefined) {\n try {\n await writeResponse(response, publicSessionMcp);\n } finally {\n response.off('close', abortSessionMcp);\n }\n return;\n }\n response.off('close', abortSessionMcp);\n }\n if (!authorized(request, options.token)) {\n json(response, 401, { error: 'Unauthorized.' });\n return;\n }\n // A restart closes the session before reopening it under the same id. Any session-scoped\n // request that lands in that gap, such as a plugin's poll, waits for the reopened session.\n const reopening = scopedSession === undefined ? undefined : restarting.get(decodeURIComponent(scopedSession));\n if (reopening !== undefined && options.headlessHub.session(decodeURIComponent(scopedSession!)) === undefined)\n await reopening;\n if (isSessionMcpHostRoute(url.pathname)) {\n const hostSessionMcp = await sessionMcp.handleHost(webRequest(request, url));\n if (hostSessionMcp !== undefined) {\n await writeResponse(response, hostSessionMcp);\n return;\n }\n }\n if (url.pathname === '/api/remote' || url.pathname.startsWith('/api/remote/')) {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined && name !== 'authorization' && name !== 'x-doompi-token')\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n const result = await options.headlessHub.requestApi(\n { scope: 'global' },\n 'remote',\n new Request(`http://doompi.local${url.pathname.slice('/api/remote'.length)}${url.search}`, {\n method: request.method,\n headers,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n await writeResponse(response, result);\n return;\n }\n if (url.pathname === '/api/telemetry/browser' && request.method === 'POST') {\n const body = JSON.parse(new TextDecoder().decode(await readBody(request))) as { v?: unknown; events?: unknown };\n if (body.v !== 1 || !Array.isArray(body.events) || body.events.length > 10) {\n json(response, 400, { error: 'Invalid browser telemetry batch.' });\n return;\n }\n for (const event of body.events) {\n if (\n !event ||\n typeof event !== 'object' ||\n typeof event.name !== 'string' ||\n !/^web\\.browser\\.[a-z_]{1,40}$/u.test(event.name)\n )\n continue;\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent(event.name, {\n ...(typeof event.duration_ms === 'number' && Number.isFinite(event.duration_ms) && event.duration_ms >= 0\n ? { duration_ms: event.duration_ms }\n : {}),\n ...(typeof event.count === 'number' && Number.isFinite(event.count) && event.count >= 0\n ? { count: event.count }\n : {}),\n }),\n );\n }\n json(response, 200, { ok: true });\n return;\n }\n if (url.pathname === '/api/compositions' && request.method === 'GET') {\n json(response, 200, options.compositions?.() ?? { workspaces: [] });\n return;\n }\n if (\n (url.pathname.startsWith('/api/web-plugins/') ||\n url.pathname === '/bundle-manifest.json' ||\n url.pathname.startsWith('/bundle-assets/')) &&\n options.requestAsset\n ) {\n const result = await options.requestAsset(new Request(url, { method: request.method }));\n if (result) {\n await writeResponse(response, result);\n return;\n }\n }\n if (url.pathname === '/api/directories/children' && request.method === 'GET') {\n const listing = await directoryChildren(url.searchParams.get('path'));\n if (listing === undefined) json(response, 404, { error: 'That folder cannot be read.' });\n else json(response, 200, listing);\n return;\n }\n if (url.pathname === '/api/directories' && request.method === 'GET') {\n json(response, 200, {\n directories: await directorySuggestions(url.searchParams.get('q') ?? '', options.headlessHub.snapshot()),\n });\n return;\n }\n // Verified browser bundles can remain active across a server upgrade. Keep\n // their former create route working while they refresh to workspace routes.\n if (url.pathname === '/api/sessions' && request.method === 'POST') {\n const body = parseJson(await readBody(request));\n if (\n !body ||\n typeof body !== 'object' ||\n !('cwd' in body) ||\n typeof body.cwd !== 'string' ||\n !body.cwd.trim() ||\n ('name' in body && typeof body.name !== 'string')\n ) {\n json(response, 400, { error: 'A session needs a working directory and an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: body.cwd,\n name: 'name' in body ? String(body.name) : path.basename(body.cwd),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n const workspaceSessions = /^\\/api\\/workspaces\\/([^/]+)\\/sessions$/u.exec(url.pathname);\n if (workspaceSessions) {\n const workspaceId = decodeURIComponent(workspaceSessions[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (request.method === 'GET') {\n json(response, 200, {\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter((session) => session.workspaceId === workspaceId)\n .map(sessionView),\n ...dormant()\n .filter((record) => record.workspaceId === workspaceId)\n .map(dormantView),\n ],\n });\n return;\n }\n if (request.method === 'POST') {\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n if (!body || typeof body !== 'object' || ('name' in body && typeof body.name !== 'string')) {\n json(response, 400, { error: 'A session accepts an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: workspace.root,\n name: 'name' in body ? String(body.name) : path.basename(workspace.root),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n }\n if (url.pathname === '/api/events' && request.method === 'GET') {\n response.writeHead(200, {\n 'cache-control': 'no-cache',\n connection: 'keep-alive',\n 'content-type': 'text/event-stream; charset=utf-8',\n });\n sse.set(response, () => desktopAuthorized(request));\n response.on('close', () => sse.delete(response));\n writeSse(response, 'sessions_snapshot', {\n type: 'sessions_snapshot',\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter(\n (session) => !options.headlessHub.computerUse?.ownsSession?.(session.id) || desktopAuthorized(request),\n )\n .map(sessionView),\n ...dormant().map(dormantView),\n ],\n });\n writeSse(response, 'workspaces_snapshot', {\n type: 'workspaces_snapshot',\n workspaces: options.headlessHub.workspaces(),\n });\n return;\n }\n if (url.pathname === '/api/workspaces') {\n if (request.method === 'GET') {\n json(response, 200, { workspaces: options.headlessHub.workspaces() });\n return;\n }\n if (request.method === 'POST') {\n const admission = parseWorkspaceAdmission(parseJson(await readBody(request)));\n if ('error' in admission) {\n json(response, 400, admission);\n return;\n }\n let workspace: Awaited<ReturnType<HeadlessHub['admitWorkspace']>>;\n try {\n workspace = await options.headlessHub.admitWorkspace(admission);\n } catch (error) {\n json(response, 422, { error: error instanceof Error ? error.message : String(error) });\n return;\n }\n json(response, 201, { workspace });\n return;\n }\n }\n const workspaceHistoryMatch = /^\\/api\\/workspaces\\/([^/]+)\\/history$/u.exec(url.pathname);\n if (workspaceHistoryMatch && request.method === 'GET' && options.workspaceHistory) {\n const workspaceId = decodeURIComponent(workspaceHistoryMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n json(response, 200, { sessions: await options.workspaceHistory(workspaceId) });\n return;\n }\n const workspaceResumeMatch = /^\\/api\\/workspaces\\/([^/]+)\\/resume$/u.exec(url.pathname);\n if (workspaceResumeMatch && request.method === 'POST' && options.resumeWorkspaceSession) {\n const workspaceId = decodeURIComponent(workspaceResumeMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeWorkspaceSession(workspaceId, targetSessionId) });\n return;\n }\n const workspaceMatch = /^\\/api\\/workspaces\\/([^/]+)$/u.exec(url.pathname);\n if (workspaceMatch && request.method === 'GET') {\n const workspace = options.headlessHub\n .workspaces()\n .find((entry) => entry.id === decodeURIComponent(workspaceMatch[1]));\n json(response, workspace ? 200 : 404, workspace ? { workspace } : { error: 'Workspace not found.' });\n return;\n }\n if (workspaceMatch && request.method === 'DELETE') {\n const id = decodeURIComponent(workspaceMatch[1]);\n if (!options.headlessHub.workspaces().some((workspace) => workspace.id === id)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (\n options.headlessHub.snapshot().some((session) => session.workspaceId === id) ||\n dormant().some((session) => session.workspaceId === id)\n ) {\n json(response, 409, { error: 'Workspace still has sessions.' });\n return;\n }\n await options.headlessHub.removeWorkspace(id);\n json(response, 200, { ok: true });\n return;\n }\n const pluginMatch = DOOM_PACKAGE_API_PATH_PATTERN.exec(url.pathname);\n if (pluginMatch !== null && request.method !== 'CONNECT') {\n const workspaceId = pluginMatch[1] === undefined ? undefined : decodeURIComponent(pluginMatch[1]);\n const sessionId = pluginMatch[2] === undefined ? undefined : decodeURIComponent(pluginMatch[2]);\n if (workspaceId !== undefined && !options.headlessHub.workspaces().some((entry) => entry.id === workspaceId)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (sessionId !== undefined && options.headlessHub.session(sessionId)?.workspaceId !== workspaceId) {\n // A stopped session still shows the composition it last published, so its context detail\n // is served from the file it wrote. Nothing else answers until it is woken.\n const stopped = dormant().some(\n (record) => record.sessionId === sessionId && record.workspaceId === workspaceId,\n );\n if (stopped && pluginMatch[3] === CONTEXT_API_BASE_PATH && request.method === 'GET') {\n const detail = await createContextApi({ sessionId, environment: process.env }).fetch(\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`),\n );\n const body = (await detail.json()) as { error?: string };\n // The detail file is only kept while the session runs, so a stopped session usually has none.\n if (readContextDetail(sessionId, process.env) === undefined)\n json(response, 404, { error: 'This session is stopped. Wake it to read this item.' });\n else json(response, detail.status, body);\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n const mount: DoomApiMount =\n sessionId !== undefined\n ? { scope: 'session', sessionId }\n : workspaceId !== undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'global' };\n const basePath = pluginMatch[3] === undefined ? 'settings' : decodeURIComponent(pluginMatch[3]);\n if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(basePath)) {\n json(response, 400, { error: 'Invalid package API base path.' });\n return;\n }\n if (pluginMatch[3] === 'settings' || (sessionId !== undefined && basePath === 'settings')) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const headers = new Headers();\n // Only the authenticated loopback proxy knows the server token and may\n // forward caller stamps. Browser-supplied stamps remain untrusted.\n const trustedCaller = options.token !== undefined && authorized(request, options.token);\n for (const [name, value] of Object.entries(request.headers)) {\n if (\n value !== undefined &&\n !['host', 'authorization', 'x-doompi-token'].includes(name) &&\n (trustedCaller || !DOOM_API_CALLER_HEADERS.includes(name as (typeof DOOM_API_CALLER_HEADERS)[number]))\n )\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n if (!trustedCaller) {\n headers.set(DOOM_API_CALLER_LOCALITY_HEADER, 'local');\n headers.set(DOOM_API_CALLER_STEP_UP_HEADER, 'not-required');\n }\n const abort = new AbortController();\n const disconnected = (): void => {\n if (!response.writableEnded) abort.abort();\n };\n response.once('close', disconnected);\n try {\n const started = performance.now();\n const attributes = {\n scope: mount.scope,\n 'plugin.name': basePath,\n 'http.operation': request.method,\n ...(mount.scope === 'workspace' ? { 'workspace.id': mount.workspaceId } : {}),\n ...(mount.scope === 'session' ? { 'session.id': mount.sessionId } : {}),\n };\n const dispatch = async () =>\n options.headlessHub.requestApi(\n mount,\n basePath,\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`, {\n method: request.method,\n headers,\n signal: abort.signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n const result = options.telemetry\n ? await options.telemetry.runInSpan('doompi_server.plugin.request', attributes, dispatch)\n : await dispatch();\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent('doompi_server.plugin.response', {\n ...attributes,\n status: result.status,\n durationMs: performance.now() - started,\n }),\n options.onNotice,\n );\n await writeResponse(response, result);\n } finally {\n response.off('close', disconnected);\n }\n return;\n }\n const sessionMatch = /^\\/api\\/workspaces\\/([^/]+)\\/sessions\\/([^/]+)(?:\\/(.*))?$/u.exec(url.pathname);\n if (sessionMatch === null) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const sessionId = decodeURIComponent(sessionMatch[2]);\n const workspaceId = decodeURIComponent(sessionMatch[1]);\n const session = options.headlessHub.session(sessionId);\n const suffix = sessionMatch[3] === undefined ? '' : `/${sessionMatch[3]}`;\n if (suffix === '/transcript' && request.method === 'GET' && options.readDormantTranscript) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n let transcriptRequest: TranscriptPageRequest;\n try {\n transcriptRequest = parseTranscriptRequest(url);\n } catch (error) {\n json(response, 400, { error: error instanceof Error ? error.message : 'Invalid transcript request.' });\n return;\n }\n try {\n const page = await options.readDormantTranscript(record, transcriptRequest, BACKGROUND_CONTEXT);\n json(response, 200, page);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n const status = message === 'STALE_TRANSCRIPT_CURSOR' ? 409 : 422;\n json(response, status, {\n error: status === 409 ? 'STALE_TRANSCRIPT_CURSOR' : 'Saved transcript is unavailable.',\n });\n }\n return;\n }\n // Revive is the one session route that answers before a runtime exists: it\n // is what creates one.\n if (sessionMatch[3] === 'revive' && request.method === 'POST' && options.reviveSession) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n await options.reviveSession(record);\n json(response, 200, { ok: true });\n return;\n }\n if (session === undefined || session.workspaceId !== workspaceId) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (request.method === 'DELETE' && record !== undefined && options.removeDormantSession !== undefined) {\n sessionMcp.closeSessionBinding(record.sessionId);\n await options.removeDormantSession(record);\n options.headlessHub.notifySessionRemoved(record.sessionId);\n json(response, 200, { ok: true });\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n if (suffix === '' && request.method === 'GET') {\n json(response, 200, sessionView(session));\n return;\n }\n if (suffix === '' && request.method === 'DELETE') {\n sessionMcp.closeSessionBinding(sessionId);\n await options.headlessHub.closeSession(sessionId);\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/history' && request.method === 'GET' && options.sessionHistory) {\n json(response, 200, { sessions: await options.sessionHistory(session) });\n return;\n }\n if (suffix === '/avatar' && request.method === 'GET') {\n const avatar = options.headlessHub.sessionAvatar(sessionId);\n if (avatar === undefined) {\n json(response, 404, { error: 'This session has no avatar.' });\n return;\n }\n const current = url.searchParams.get('v') === session.profile?.iconVersion;\n response.writeHead(200, {\n 'content-type': avatar.mimeType,\n 'content-length': String(avatar.bytes.byteLength),\n 'cache-control': current ? 'private, max-age=31536000, immutable' : 'no-store',\n 'x-content-type-options': 'nosniff',\n });\n response.end(avatar.bytes);\n return;\n }\n if (suffix === '/file' && request.method === 'GET') {\n await writeResponse(response, await sessionFile(session, url.searchParams.get('path')));\n return;\n }\n if (suffix === '/restart' && request.method === 'POST' && options.restartSession) {\n const restart = options.restartSession(session);\n // Settled either way: a failed restart leaves the session dormant, and waiters then see that.\n const settled = restart.then(\n () => undefined,\n () => undefined,\n );\n restarting.set(sessionId, settled);\n try {\n await restart;\n } finally {\n if (restarting.get(sessionId) === settled) restarting.delete(sessionId);\n }\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/resume' && request.method === 'POST' && options.resumeSession) {\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n if (options.headlessHub.computerUse?.ownsSession?.(targetSessionId) && !desktopAuthorized(request)) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeSession(session, targetSessionId) });\n return;\n }\n if (suffix === '/channels' && request.method === 'GET') {\n json(response, 200, {\n channels: options.headlessHub\n .channelFrames(sessionId)\n .filter((frame) => frame.type !== 'computer_use_state' || desktopAuthorized(request)),\n });\n return;\n }\n const channelMatch = /^\\/channel\\/([^/]+)$/u.exec(suffix);\n if (channelMatch !== null && request.method === 'POST') {\n const frameType = decodeURIComponent(channelMatch[1]);\n const connectionId = request.headers['x-doompi-connection'];\n options.headlessHub.receiveChannel(\n sessionId,\n frameType,\n parseJson(await readBody(request)),\n typeof connectionId === 'string' ? connectionId : 'http',\n desktopAuthorized(request),\n );\n json(response, 202, { ok: true });\n return;\n }\n json(response, 404, { error: 'Not found.' });\n }\n\n server.on('upgrade', (request, socket, head) => {\n const url = requestPath(request);\n const mount = parseDoomSocketPath(url.pathname);\n if (!mount) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (!authorized(request, options.token)) {\n socket.write('HTTP/1.1 401 Unauthorized\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (\n mount.scope !== 'global' &&\n (!options.headlessHub.workspaces().some((entry) => entry.id === mount.workspaceId && entry.available !== false) ||\n (mount.scope === 'session' && options.headlessHub.session(mount.sessionId)?.workspaceId !== mount.workspaceId))\n ) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n const prepare =\n mount.scope === 'global' && options.headlessHub.computerUse === undefined\n ? Promise.resolve(protocol)\n : createHeadlessProtocol({\n hub: options.headlessHub,\n mount,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n authorizeSession: (id) => !options.headlessHub.computerUse?.ownsSession?.(id) || desktopAuthorized(request),\n authorizeDesktop: () => desktopAuthorized(request),\n });\n void prepare\n .then(async (selected) => {\n if (closed || socket.destroyed) {\n if (selected !== protocol) await selected.close();\n socket.destroy();\n return;\n }\n if (selected !== protocol) {\n scopedProtocols.add(selected);\n socket.once('close', () => {\n void selected.close().finally(() => scopedProtocols.delete(selected));\n });\n }\n webSockets.handleUpgrade(request, socket, head, (client) => {\n webSockets.emit('connection', client, selected);\n });\n })\n .catch(() => {\n socket.destroy();\n });\n });\n webSockets.on('connection', (socket, selected: typeof protocol) => {\n const handler = selected.accept(socket);\n if (!handler) return;\n const client: Client = { socket, handler };\n clients.add(client);\n socket.on('message', (data) => {\n if (Buffer.isBuffer(data)) handler.onData(data);\n else if (Array.isArray(data)) handler.onData(Buffer.concat(data));\n else handler.onData(new Uint8Array(data as ArrayBuffer));\n });\n socket.on('close', () => {\n clients.delete(client);\n handler.onClose();\n });\n socket.on('error', (error) => handler.onError(error));\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(options.port, options.host ?? '127.0.0.1', () => resolve());\n });\n const address = server.address();\n if (address === null || typeof address === 'string') {\n await new Promise<void>((resolve) => server.close(() => resolve()));\n throw new Error('The headless server did not expose a TCP address.');\n }\n const host = options.host ?? '127.0.0.1';\n const url = `http://${host}:${address.port}`;\n return {\n url,\n sessionReservations: sessionMcp.reservations,\n async close() {\n if (closed) return;\n closed = true;\n unsubscribe();\n for (const response of sse.keys()) response.end();\n sse.clear();\n for (const client of clients) client.socket.terminate();\n clients.clear();\n sessionMcp.close();\n if (options.sessionMcpStateDir === undefined)\n await fs.promises.rm(sessionMcpStateDir, { recursive: true, force: true });\n await Promise.all([protocol.close(), ...[...scopedProtocols].map((selected) => selected.close())]);\n webSockets.close();\n server.closeAllConnections();\n await new Promise<void>((resolve, reject) =>\n server.close((error) => (error === undefined ? resolve() : reject(error))),\n );\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;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,OAAO,UAAW,UAAU,KAAA,IAAY,QAAQ,IAAI,OAAO,KAAK,CAAE,CAC3E;EACF;CACF;AACF"}
@@ -141,13 +141,13 @@ function parseTranscriptRequest(url) {
141
141
  }
142
142
  return request;
143
143
  }
144
- async function sessionFile(session, relativePath) {
145
- if (!relativePath || relativePath.includes("\0") || path.isAbsolute(relativePath)) return Response.json({ error: "Invalid session file path." }, { status: 400 });
144
+ async function sessionFile(session, requestedPath) {
145
+ if (!requestedPath || requestedPath.includes("\0")) return Response.json({ error: "Invalid session file path." }, { status: 400 });
146
146
  let root;
147
147
  let filePath;
148
148
  try {
149
149
  root = await fs.promises.realpath(session.cwd);
150
- filePath = await fs.promises.realpath(path.resolve(root, relativePath));
150
+ filePath = await fs.promises.realpath(path.resolve(root, requestedPath));
151
151
  } catch {
152
152
  return Response.json({ error: "Session file not found." }, { status: 404 });
153
153
  }
@@ -1 +1 @@
1
- {"version":3,"file":"headlessServer.mjs","names":[],"sources":["../src/server/headlessServer.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { Context } from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { WebSocket } from 'ws';\nimport { WebSocketServer } from 'ws';\n\nimport { API_BASE_PATH as CONTEXT_API_BASE_PATH } from '../constants/contextApi';\nimport {\n DOOM_API_CALLER_HEADERS,\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n parseDoomSocketPath,\n type DoomApiMount,\n} from '../exports/packageApi';\nimport type { TranscriptPage, TranscriptPageRequest } from '../exports/sessionProtocol';\nimport type { DoomHubSessionReservations } from '../schemas/hubChannel';\nimport { readContextDetail } from '../services/contextDetailStore';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport { observe, type ServerTelemetry } from '../services/serverTelemetry';\nimport { createSessionMcpActivityStore } from '../services/sessionMcpActivity';\nimport { createSessionMcpConversationStore } from '../services/sessionMcpConversations';\nimport { createSessionMcpRegistrationStore } from '../services/sessionMcpRegistrationStore';\nimport type { SavedSession } from '../services/sqliteSessionHistory';\nimport { createContextApi } from './contextApi';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession, HeadlessWorkspaceAdmission } from './headlessHub';\nimport { createHeadlessProtocol } from './headlessProtocol';\nimport { createSessionMcpRoutes, isPublicSessionMcpRoute, isSessionMcpHostRoute } from './sessionMcpRoutes';\n\n/**\n * The canonical public shape of a package API request, as dispatch reads it.\n *\n * Groups: workspace id, session id, plugin base path, and the remainder handed\n * to the package. `settings` is the host's own API and sits beside `plugins`\n * rather than under it.\n *\n * Exported so the browser's URL construction can be pinned against it. The two\n * are written independently, in halves of this package that may not import each\n * other, and a disagreement between them is not a 404 from the route: the\n * service worker answers an unrecognised path out of the signed bundle cache,\n * so the symptom appears nowhere near the cause.\n */\nexport const DOOM_PACKAGE_API_PATH_PATTERN =\n /^\\/api(?:\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?)?\\/(?:plugins\\/([^/]+)|settings)(?:\\/(.*))?$/u;\n\nconst HEALTH_ROLE = 'hub';\nconst PROTOCOL_VERSION = 1;\nconst MAX_BODY_BYTES = 8 * 1024 * 1024;\nconst MAX_SESSION_FILE_BYTES = 25 * 1024 * 1024;\nconst DIRECTORY_SUGGESTION_LIMIT = 12;\nconst DIRECTORY_CHILDREN_LIMIT = 500;\nconst HOME_PREFIX = '~';\nconst WORKSPACE_NAME_MAX_LENGTH = 80;\nconst WORKSPACE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/u;\nconst SESSION_FILE_CONTENT_TYPES: Readonly<Record<string, string>> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.m4v': 'video/mp4',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.pdf': 'application/pdf',\n};\n\nexport interface HeadlessServerOptions {\n headlessHub: HeadlessHub;\n port: number;\n host?: string;\n /** Requests other than health require this bearer token when set. */\n token?: string;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n compositions?: () => unknown;\n requestAsset?: (request: Request) => Promise<Response | undefined>;\n sessionHistory?: (session: HeadlessHubSession) => Promise<SavedSession[]>;\n workspaceHistory?: (workspaceId: string) => Promise<SavedSession[]>;\n resumeWorkspaceSession?: (workspaceId: string, targetSessionId: string) => Promise<string>;\n readDormantTranscript?: (\n record: OpenSessionRecord,\n request: TranscriptPageRequest,\n context: Context,\n ) => Promise<TranscriptPage>;\n restartSession?: (session: HeadlessHubSession) => Promise<void>;\n resumeSession?: (session: HeadlessHubSession, targetSessionId: string) => Promise<string>;\n /** Recorded sessions this server has not reopened, surfaced so a client can ask for one. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n removeDormantSession?: (record: OpenSessionRecord) => void | Promise<void>;\n reviveSession?: (record: OpenSessionRecord) => Promise<void>;\n /** Trusted HTTPS origin advertised for public session MCP and OAuth endpoints. */\n sessionMcpPublicOrigin?: () => string | undefined;\n /** Durable state directory for verified Session MCP clients. */\n sessionMcpStateDir?: string;\n /** Monotonic exposure revision, including disable/re-enable cycles. */\n sessionMcpPublicOriginRevision?: () => number;\n isSessionPersisted?: (sessionId: string, cwd: string) => boolean;\n}\n\nexport interface HeadlessServer {\n readonly url: string;\n readonly sessionReservations: DoomHubSessionReservations;\n close(): Promise<void>;\n}\n\ntype ProtocolHandler = NonNullable<ReturnType<Awaited<ReturnType<typeof createHeadlessProtocol>>['accept']>>;\ntype Client = { socket: WebSocket; handler: ProtocolHandler };\n\nfunction sessionView(session: HeadlessHubSession): Record<string, unknown> {\n return {\n id: session.id,\n workspaceId: session.workspaceId,\n webComposition: session.webComposition,\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n ...(session.git === undefined ? {} : { git: { ...session.git } }),\n ...(session.profile === undefined ? {} : { profile: { ...session.profile } }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.pendingSetups === undefined ? {} : { pendingSetups: session.pendingSetups }),\n ...(session.activity === undefined ? {} : { activity: { ...session.activity } }),\n };\n}\n\n/** The dormant counterpart of `sessionView`; same shape, no runtime behind it. */\nfunction dormantView(record: OpenSessionRecord): Record<string, unknown> {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'detached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n };\n}\n\nfunction json(response: ServerResponse, status: number, value: unknown): void {\n const body = JSON.stringify(value);\n response.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'content-length': Buffer.byteLength(body),\n });\n response.end(body);\n}\n\nfunction authorized(request: IncomingMessage, token: string | undefined): boolean {\n if (token === undefined) return true;\n const authorization = request.headers.authorization;\n if (authorization?.startsWith('Bearer ') && authorization.slice('Bearer '.length) === token) return true;\n const header = request.headers['x-doompi-token'];\n if (typeof header === 'string' && header === token) return true;\n try {\n return new URL(request.url ?? '/', 'http://doompi.local').searchParams.get('token') === token;\n } catch {\n return false;\n }\n}\n\nfunction requestPath(request: IncomingMessage): URL {\n return new URL(request.url ?? '/', 'http://doompi.local');\n}\n\nfunction parseTranscriptRequest(url: URL): TranscriptPageRequest {\n const request: TranscriptPageRequest = {};\n const cursor = url.searchParams.get('cursor');\n const direction = url.searchParams.get('direction');\n const limit = url.searchParams.get('limit');\n if (cursor !== null) request.cursor = cursor;\n if (direction !== null) {\n if (direction !== 'older' && direction !== 'newer') throw new Error('Invalid transcript direction');\n request.direction = direction;\n }\n if (limit !== null) {\n if (!/^\\d+$/u.test(limit)) throw new Error('Invalid transcript page limit');\n const parsed = Number(limit);\n if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 100) throw new Error('Invalid transcript page limit');\n request.limit = parsed;\n }\n return request;\n}\n\nasync function sessionFile(session: HeadlessHubSession, relativePath: string | null): Promise<Response> {\n if (!relativePath || relativePath.includes('\\0') || path.isAbsolute(relativePath))\n return Response.json({ error: 'Invalid session file path.' }, { status: 400 });\n let root: string;\n let filePath: string;\n try {\n root = await fs.promises.realpath(session.cwd);\n filePath = await fs.promises.realpath(path.resolve(root, relativePath));\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n const contained = path.relative(root, filePath);\n if (contained === '..' || contained.startsWith(`..${path.sep}`) || path.isAbsolute(contained))\n return Response.json({ error: 'Session file is outside the working directory.' }, { status: 403 });\n let handle: fs.promises.FileHandle;\n try {\n handle = await fs.promises.open(filePath, 'r');\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n try {\n const stat = await handle.stat();\n if (!stat.isFile()) return Response.json({ error: 'Session file not found.' }, { status: 404 });\n if (stat.size > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n const bytes = await handle.readFile();\n if (bytes.byteLength > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n return new Response(bytes, {\n headers: {\n 'content-type': SESSION_FILE_CONTENT_TYPES[path.extname(filePath).toLowerCase()] ?? 'application/octet-stream',\n 'content-length': String(bytes.byteLength),\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n },\n });\n } finally {\n await handle.close();\n }\n}\n\n/** Expands a leading `~` the way a shell would, so typed paths match what the user sees in a terminal. */\nfunction expandHome(value: string): string {\n if (value === HOME_PREFIX) return os.homedir();\n return value.startsWith(`${HOME_PREFIX}${path.sep}`) ? path.join(os.homedir(), value.slice(2)) : value;\n}\n\n/**\n * Validates an add-workspace request. A name alone asks for a new default folder,\n * so it must be safe to use as one folder name.\n */\nfunction parseWorkspaceAdmission(body: unknown): HeadlessWorkspaceAdmission | { error: string } {\n if (typeof body !== 'object' || body === null) return { error: 'A workspace root or name is required.' };\n const record = body as Record<string, unknown>;\n if (record.root !== undefined && typeof record.root !== 'string')\n return { error: 'The workspace root must be text.' };\n if (record.name !== undefined && typeof record.name !== 'string')\n return { error: 'The workspace name must be text.' };\n const root =\n typeof record.root === 'string' && record.root.trim() !== '' ? expandHome(record.root.trim()) : undefined;\n const name = typeof record.name === 'string' && record.name.trim() !== '' ? record.name.trim() : undefined;\n if (root === undefined && name === undefined) return { error: 'A workspace root or name is required.' };\n if (\n name !== undefined &&\n (name.length > WORKSPACE_NAME_MAX_LENGTH || !WORKSPACE_NAME_PATTERN.test(name) || name.includes('..'))\n )\n return {\n error: `Workspace names use letters, numbers, spaces, dots, dashes, or underscores (up to ${String(WORKSPACE_NAME_MAX_LENGTH)} characters).`,\n };\n return { ...(root === undefined ? {} : { root }), ...(name === undefined ? {} : { name }) };\n}\n\nasync function directorySuggestions(query: string, sessions: readonly HeadlessHubSession[]): Promise<string[]> {\n const typed = expandHome(query.trim());\n if (typed === '') return [];\n const matches = (value: string): boolean => value.toLowerCase().includes(typed.toLowerCase());\n const known = [...new Set([process.cwd(), ...sessions.map((session) => session.cwd)])].filter(matches);\n const candidates = path.isAbsolute(typed)\n ? [typed]\n : typed.includes(path.sep)\n ? [path.resolve(process.cwd(), typed)]\n : [path.join(path.dirname(process.cwd()), typed), path.join(process.cwd(), typed)];\n const completed: string[] = [];\n for (const candidate of candidates) {\n const drilling = typed.endsWith(path.sep);\n const parent = drilling ? candidate : path.dirname(candidate);\n const partial = drilling ? '' : path.basename(candidate).toLowerCase();\n try {\n const entries = await fs.promises.readdir(parent, { withFileTypes: true });\n completed.push(\n ...entries\n .filter((entry) => entry.isDirectory() && entry.name.toLowerCase().includes(partial))\n .map((entry) => path.join(parent, entry.name)),\n );\n } catch {\n // A missing or unreadable parent simply has no completions.\n }\n }\n return [...new Set([...known, ...completed.sort((left, right) => left.localeCompare(right))])].slice(\n 0,\n DIRECTORY_SUGGESTION_LIMIT,\n );\n}\n\n/**\n * Lists the visible child directories of one folder for the workspace folder browser.\n * Resolves undefined for a relative, missing, or unreadable path.\n */\nasync function directoryChildren(\n requested: string | null,\n): Promise<{ path: string; parent?: string; directories: string[] } | undefined> {\n const directory = requested === null || requested.trim() === '' ? os.homedir() : expandHome(requested.trim());\n if (!path.isAbsolute(directory)) return undefined;\n const resolved = path.resolve(directory);\n let entries: fs.Dirent[];\n try {\n entries = await fs.promises.readdir(resolved, { withFileTypes: true });\n } catch {\n return undefined;\n }\n const directories = entries\n .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))\n .map((entry) => path.join(resolved, entry.name))\n .sort((left, right) => left.localeCompare(right))\n .slice(0, DIRECTORY_CHILDREN_LIMIT);\n const parent = path.dirname(resolved);\n return { path: resolved, ...(parent === resolved ? {} : { parent }), directories };\n}\n\nasync function readBody(request: IncomingMessage): Promise<Uint8Array> {\n const chunks: Buffer[] = [];\n let size = 0;\n for await (const chunk of request) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n size += buffer.byteLength;\n if (size > MAX_BODY_BYTES) throw new Error('Request body is too large.');\n chunks.push(buffer);\n }\n return Buffer.concat(chunks);\n}\n\nfunction parseJson(body: Uint8Array): unknown {\n if (body.byteLength === 0) return {};\n return JSON.parse(Buffer.from(body).toString('utf8')) as unknown;\n}\n\nfunction webRequest(request: IncomingMessage, url: URL, signal?: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined) headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n return new Request(url, {\n method: request.method,\n headers,\n signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : {\n body: Readable.toWeb(request) as never,\n duplex: 'half' as const,\n }),\n });\n}\n\nasync function writeResponse(response: ServerResponse, result: Response): Promise<void> {\n response.writeHead(result.status, Object.fromEntries(result.headers.entries()));\n if (result.body === null) {\n response.end();\n return;\n }\n await pipeline(Readable.fromWeb(result.body as import('node:stream/web').ReadableStream), response);\n}\n\nfunction eventFrame(event: HeadlessHubEvent): Record<string, unknown> {\n switch (event.kind) {\n case 'upsert':\n return { type: 'session_upsert', session: sessionView(event.session) };\n case 'removed':\n return { type: 'session_removed', sessionId: event.sessionId };\n case 'workspace_upsert':\n return { type: 'workspace_upsert', workspace: event.workspace };\n case 'workspace_removed':\n return { type: 'workspace_removed', workspaceId: event.workspaceId };\n case 'channel':\n return {\n type: 'channel_frame',\n frameType: event.frameType,\n sessionId: event.sessionId,\n payload: event.payload,\n ...(event.connectionId === undefined ? {} : { connectionId: event.connectionId }),\n };\n }\n}\n\nfunction writeSse(response: ServerResponse, event: string, value: unknown): void {\n response.write(`event: ${event}\\ndata: ${JSON.stringify(value)}\\n\\n`);\n}\n\n/**\n * Client-neutral HTTP and WebSocket boundary for the process-local headless hub.\n * It deliberately delegates every session operation to HeadlessHub, so transport\n * clients cannot create a second session backend or bypass its lifecycle.\n */\nexport async function serveHeadlessServer(options: HeadlessServerOptions): Promise<HeadlessServer> {\n const clients = new Set<Client>();\n const scopedProtocols = new Set<Awaited<ReturnType<typeof createHeadlessProtocol>>>();\n const sse = new Map<ServerResponse, () => boolean>();\n const desktopAuthorized = (request: IncomingMessage): boolean => {\n const proof = request.headers['x-doompi-desktop'];\n return (\n typeof proof === 'string' &&\n options.headlessHub.computerUse?.authorize?.(new Headers({ 'x-doompi-desktop': proof })) === true\n );\n };\n let closed = false;\n const webSockets = new WebSocketServer({ noServer: true });\n /**\n * A recorded session is dormant exactly while the hub has no session for its\n * id, so reviving one needs no bookkeeping beyond the hub itself.\n */\n const dormant = (): readonly OpenSessionRecord[] =>\n (options.dormantSessions?.() ?? []).filter((record) => options.headlessHub.session(record.sessionId) === undefined);\n const protocol = await createHeadlessProtocol({\n hub: options.headlessHub,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n });\n const sessionMcpStateDir =\n options.sessionMcpStateDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'doompi-session-mcp-'));\n const sessionMcp = createSessionMcpRoutes({\n headlessHub: options.headlessHub,\n publicOrigin: options.sessionMcpPublicOrigin ?? (() => undefined),\n publicOriginRevision: options.sessionMcpPublicOriginRevision,\n onNotice: options.onNotice,\n isSessionPersisted: options.isSessionPersisted,\n activityStore: createSessionMcpActivityStore(sessionMcpStateDir),\n conversationStore: createSessionMcpConversationStore(sessionMcpStateDir),\n registrationStore: createSessionMcpRegistrationStore({ stateDir: sessionMcpStateDir, onNotice: options.onNotice }),\n });\n /** Sessions being restarted, keyed by id, settled once the reopen succeeds or fails. */\n const restarting = new Map<string, Promise<void>>();\n const server = createServer((request, response) => {\n void handleRequest(request, response).catch((error: unknown) => {\n if (response.headersSent) {\n response.destroy();\n return;\n }\n options.onNotice?.(`Headless request failed: ${harnessErrorMessage(error)}`);\n json(response, 500, { error: 'Internal server error.' });\n });\n });\n\n const unsubscribe = options.headlessHub.onEvent((event) => {\n const frame = eventFrame(event);\n const sessionId = event.kind === 'upsert' ? event.session.id : 'sessionId' in event ? event.sessionId : undefined;\n for (const [response, native] of sse) {\n if (\n (sessionId !== undefined && options.headlessHub.computerUse?.ownsSession?.(sessionId)) ||\n frame.type === 'computer_use_state'\n ) {\n if (!native()) continue;\n }\n writeSse(response, String(frame.type), frame);\n }\n });\n\n async function handleRequest(request: IncomingMessage, response: ServerResponse): Promise<void> {\n const url = requestPath(request);\n if (url.pathname === '/api/health' && request.method === 'GET') {\n json(response, 200, {\n ok: true,\n role: HEALTH_ROLE,\n protocol: PROTOCOL_VERSION,\n sessions: options.headlessHub.snapshot().length,\n });\n return;\n }\n const scopedSession = /^\\/api\\/workspaces\\/[^/]+\\/sessions\\/([^/]+)(?:\\/|$)/u.exec(url.pathname)?.[1];\n if (\n scopedSession &&\n options.headlessHub.computerUse?.ownsSession?.(decodeURIComponent(scopedSession)) &&\n !desktopAuthorized(request)\n ) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n if (isPublicSessionMcpRoute(request.method ?? 'GET', url.pathname)) {\n const sessionMcpAbort = new AbortController();\n const abortSessionMcp = (): void => {\n if (!response.writableEnded) sessionMcpAbort.abort();\n };\n response.once('close', abortSessionMcp);\n const publicSessionMcp = await sessionMcp.handlePublic(webRequest(request, url, sessionMcpAbort.signal));\n if (publicSessionMcp !== undefined) {\n try {\n await writeResponse(response, publicSessionMcp);\n } finally {\n response.off('close', abortSessionMcp);\n }\n return;\n }\n response.off('close', abortSessionMcp);\n }\n if (!authorized(request, options.token)) {\n json(response, 401, { error: 'Unauthorized.' });\n return;\n }\n // A restart closes the session before reopening it under the same id. Any session-scoped\n // request that lands in that gap, such as a plugin's poll, waits for the reopened session.\n const reopening = scopedSession === undefined ? undefined : restarting.get(decodeURIComponent(scopedSession));\n if (reopening !== undefined && options.headlessHub.session(decodeURIComponent(scopedSession!)) === undefined)\n await reopening;\n if (isSessionMcpHostRoute(url.pathname)) {\n const hostSessionMcp = await sessionMcp.handleHost(webRequest(request, url));\n if (hostSessionMcp !== undefined) {\n await writeResponse(response, hostSessionMcp);\n return;\n }\n }\n if (url.pathname === '/api/remote' || url.pathname.startsWith('/api/remote/')) {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined && name !== 'authorization' && name !== 'x-doompi-token')\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n const result = await options.headlessHub.requestApi(\n { scope: 'global' },\n 'remote',\n new Request(`http://doompi.local${url.pathname.slice('/api/remote'.length)}${url.search}`, {\n method: request.method,\n headers,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n await writeResponse(response, result);\n return;\n }\n if (url.pathname === '/api/telemetry/browser' && request.method === 'POST') {\n const body = JSON.parse(new TextDecoder().decode(await readBody(request))) as { v?: unknown; events?: unknown };\n if (body.v !== 1 || !Array.isArray(body.events) || body.events.length > 10) {\n json(response, 400, { error: 'Invalid browser telemetry batch.' });\n return;\n }\n for (const event of body.events) {\n if (\n !event ||\n typeof event !== 'object' ||\n typeof event.name !== 'string' ||\n !/^web\\.browser\\.[a-z_]{1,40}$/u.test(event.name)\n )\n continue;\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent(event.name, {\n ...(typeof event.duration_ms === 'number' && Number.isFinite(event.duration_ms) && event.duration_ms >= 0\n ? { duration_ms: event.duration_ms }\n : {}),\n ...(typeof event.count === 'number' && Number.isFinite(event.count) && event.count >= 0\n ? { count: event.count }\n : {}),\n }),\n );\n }\n json(response, 200, { ok: true });\n return;\n }\n if (url.pathname === '/api/compositions' && request.method === 'GET') {\n json(response, 200, options.compositions?.() ?? { workspaces: [] });\n return;\n }\n if (\n (url.pathname.startsWith('/api/web-plugins/') ||\n url.pathname === '/bundle-manifest.json' ||\n url.pathname.startsWith('/bundle-assets/')) &&\n options.requestAsset\n ) {\n const result = await options.requestAsset(new Request(url, { method: request.method }));\n if (result) {\n await writeResponse(response, result);\n return;\n }\n }\n if (url.pathname === '/api/directories/children' && request.method === 'GET') {\n const listing = await directoryChildren(url.searchParams.get('path'));\n if (listing === undefined) json(response, 404, { error: 'That folder cannot be read.' });\n else json(response, 200, listing);\n return;\n }\n if (url.pathname === '/api/directories' && request.method === 'GET') {\n json(response, 200, {\n directories: await directorySuggestions(url.searchParams.get('q') ?? '', options.headlessHub.snapshot()),\n });\n return;\n }\n // Verified browser bundles can remain active across a server upgrade. Keep\n // their former create route working while they refresh to workspace routes.\n if (url.pathname === '/api/sessions' && request.method === 'POST') {\n const body = parseJson(await readBody(request));\n if (\n !body ||\n typeof body !== 'object' ||\n !('cwd' in body) ||\n typeof body.cwd !== 'string' ||\n !body.cwd.trim() ||\n ('name' in body && typeof body.name !== 'string')\n ) {\n json(response, 400, { error: 'A session needs a working directory and an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: body.cwd,\n name: 'name' in body ? String(body.name) : path.basename(body.cwd),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n const workspaceSessions = /^\\/api\\/workspaces\\/([^/]+)\\/sessions$/u.exec(url.pathname);\n if (workspaceSessions) {\n const workspaceId = decodeURIComponent(workspaceSessions[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (request.method === 'GET') {\n json(response, 200, {\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter((session) => session.workspaceId === workspaceId)\n .map(sessionView),\n ...dormant()\n .filter((record) => record.workspaceId === workspaceId)\n .map(dormantView),\n ],\n });\n return;\n }\n if (request.method === 'POST') {\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n if (!body || typeof body !== 'object' || ('name' in body && typeof body.name !== 'string')) {\n json(response, 400, { error: 'A session accepts an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: workspace.root,\n name: 'name' in body ? String(body.name) : path.basename(workspace.root),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n }\n if (url.pathname === '/api/events' && request.method === 'GET') {\n response.writeHead(200, {\n 'cache-control': 'no-cache',\n connection: 'keep-alive',\n 'content-type': 'text/event-stream; charset=utf-8',\n });\n sse.set(response, () => desktopAuthorized(request));\n response.on('close', () => sse.delete(response));\n writeSse(response, 'sessions_snapshot', {\n type: 'sessions_snapshot',\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter(\n (session) => !options.headlessHub.computerUse?.ownsSession?.(session.id) || desktopAuthorized(request),\n )\n .map(sessionView),\n ...dormant().map(dormantView),\n ],\n });\n writeSse(response, 'workspaces_snapshot', {\n type: 'workspaces_snapshot',\n workspaces: options.headlessHub.workspaces(),\n });\n return;\n }\n if (url.pathname === '/api/workspaces') {\n if (request.method === 'GET') {\n json(response, 200, { workspaces: options.headlessHub.workspaces() });\n return;\n }\n if (request.method === 'POST') {\n const admission = parseWorkspaceAdmission(parseJson(await readBody(request)));\n if ('error' in admission) {\n json(response, 400, admission);\n return;\n }\n let workspace: Awaited<ReturnType<HeadlessHub['admitWorkspace']>>;\n try {\n workspace = await options.headlessHub.admitWorkspace(admission);\n } catch (error) {\n json(response, 422, { error: error instanceof Error ? error.message : String(error) });\n return;\n }\n json(response, 201, { workspace });\n return;\n }\n }\n const workspaceHistoryMatch = /^\\/api\\/workspaces\\/([^/]+)\\/history$/u.exec(url.pathname);\n if (workspaceHistoryMatch && request.method === 'GET' && options.workspaceHistory) {\n const workspaceId = decodeURIComponent(workspaceHistoryMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n json(response, 200, { sessions: await options.workspaceHistory(workspaceId) });\n return;\n }\n const workspaceResumeMatch = /^\\/api\\/workspaces\\/([^/]+)\\/resume$/u.exec(url.pathname);\n if (workspaceResumeMatch && request.method === 'POST' && options.resumeWorkspaceSession) {\n const workspaceId = decodeURIComponent(workspaceResumeMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeWorkspaceSession(workspaceId, targetSessionId) });\n return;\n }\n const workspaceMatch = /^\\/api\\/workspaces\\/([^/]+)$/u.exec(url.pathname);\n if (workspaceMatch && request.method === 'GET') {\n const workspace = options.headlessHub\n .workspaces()\n .find((entry) => entry.id === decodeURIComponent(workspaceMatch[1]));\n json(response, workspace ? 200 : 404, workspace ? { workspace } : { error: 'Workspace not found.' });\n return;\n }\n if (workspaceMatch && request.method === 'DELETE') {\n const id = decodeURIComponent(workspaceMatch[1]);\n if (!options.headlessHub.workspaces().some((workspace) => workspace.id === id)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (\n options.headlessHub.snapshot().some((session) => session.workspaceId === id) ||\n dormant().some((session) => session.workspaceId === id)\n ) {\n json(response, 409, { error: 'Workspace still has sessions.' });\n return;\n }\n await options.headlessHub.removeWorkspace(id);\n json(response, 200, { ok: true });\n return;\n }\n const pluginMatch = DOOM_PACKAGE_API_PATH_PATTERN.exec(url.pathname);\n if (pluginMatch !== null && request.method !== 'CONNECT') {\n const workspaceId = pluginMatch[1] === undefined ? undefined : decodeURIComponent(pluginMatch[1]);\n const sessionId = pluginMatch[2] === undefined ? undefined : decodeURIComponent(pluginMatch[2]);\n if (workspaceId !== undefined && !options.headlessHub.workspaces().some((entry) => entry.id === workspaceId)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (sessionId !== undefined && options.headlessHub.session(sessionId)?.workspaceId !== workspaceId) {\n // A stopped session still shows the composition it last published, so its context detail\n // is served from the file it wrote. Nothing else answers until it is woken.\n const stopped = dormant().some(\n (record) => record.sessionId === sessionId && record.workspaceId === workspaceId,\n );\n if (stopped && pluginMatch[3] === CONTEXT_API_BASE_PATH && request.method === 'GET') {\n const detail = await createContextApi({ sessionId, environment: process.env }).fetch(\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`),\n );\n const body = (await detail.json()) as { error?: string };\n // The detail file is only kept while the session runs, so a stopped session usually has none.\n if (readContextDetail(sessionId, process.env) === undefined)\n json(response, 404, { error: 'This session is stopped. Wake it to read this item.' });\n else json(response, detail.status, body);\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n const mount: DoomApiMount =\n sessionId !== undefined\n ? { scope: 'session', sessionId }\n : workspaceId !== undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'global' };\n const basePath = pluginMatch[3] === undefined ? 'settings' : decodeURIComponent(pluginMatch[3]);\n if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(basePath)) {\n json(response, 400, { error: 'Invalid package API base path.' });\n return;\n }\n if (pluginMatch[3] === 'settings' || (sessionId !== undefined && basePath === 'settings')) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const headers = new Headers();\n // Only the authenticated loopback proxy knows the server token and may\n // forward caller stamps. Browser-supplied stamps remain untrusted.\n const trustedCaller = options.token !== undefined && authorized(request, options.token);\n for (const [name, value] of Object.entries(request.headers)) {\n if (\n value !== undefined &&\n !['host', 'authorization', 'x-doompi-token'].includes(name) &&\n (trustedCaller || !DOOM_API_CALLER_HEADERS.includes(name as (typeof DOOM_API_CALLER_HEADERS)[number]))\n )\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n if (!trustedCaller) {\n headers.set(DOOM_API_CALLER_LOCALITY_HEADER, 'local');\n headers.set(DOOM_API_CALLER_STEP_UP_HEADER, 'not-required');\n }\n const abort = new AbortController();\n const disconnected = (): void => {\n if (!response.writableEnded) abort.abort();\n };\n response.once('close', disconnected);\n try {\n const started = performance.now();\n const attributes = {\n scope: mount.scope,\n 'plugin.name': basePath,\n 'http.operation': request.method,\n ...(mount.scope === 'workspace' ? { 'workspace.id': mount.workspaceId } : {}),\n ...(mount.scope === 'session' ? { 'session.id': mount.sessionId } : {}),\n };\n const dispatch = async () =>\n options.headlessHub.requestApi(\n mount,\n basePath,\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`, {\n method: request.method,\n headers,\n signal: abort.signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n const result = options.telemetry\n ? await options.telemetry.runInSpan('doompi_server.plugin.request', attributes, dispatch)\n : await dispatch();\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent('doompi_server.plugin.response', {\n ...attributes,\n status: result.status,\n durationMs: performance.now() - started,\n }),\n options.onNotice,\n );\n await writeResponse(response, result);\n } finally {\n response.off('close', disconnected);\n }\n return;\n }\n const sessionMatch = /^\\/api\\/workspaces\\/([^/]+)\\/sessions\\/([^/]+)(?:\\/(.*))?$/u.exec(url.pathname);\n if (sessionMatch === null) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const sessionId = decodeURIComponent(sessionMatch[2]);\n const workspaceId = decodeURIComponent(sessionMatch[1]);\n const session = options.headlessHub.session(sessionId);\n const suffix = sessionMatch[3] === undefined ? '' : `/${sessionMatch[3]}`;\n if (suffix === '/transcript' && request.method === 'GET' && options.readDormantTranscript) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n let transcriptRequest: TranscriptPageRequest;\n try {\n transcriptRequest = parseTranscriptRequest(url);\n } catch (error) {\n json(response, 400, { error: error instanceof Error ? error.message : 'Invalid transcript request.' });\n return;\n }\n try {\n const page = await options.readDormantTranscript(record, transcriptRequest, BACKGROUND_CONTEXT);\n json(response, 200, page);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n const status = message === 'STALE_TRANSCRIPT_CURSOR' ? 409 : 422;\n json(response, status, {\n error: status === 409 ? 'STALE_TRANSCRIPT_CURSOR' : 'Saved transcript is unavailable.',\n });\n }\n return;\n }\n // Revive is the one session route that answers before a runtime exists: it\n // is what creates one.\n if (sessionMatch[3] === 'revive' && request.method === 'POST' && options.reviveSession) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n await options.reviveSession(record);\n json(response, 200, { ok: true });\n return;\n }\n if (session === undefined || session.workspaceId !== workspaceId) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (request.method === 'DELETE' && record !== undefined && options.removeDormantSession !== undefined) {\n sessionMcp.closeSessionBinding(record.sessionId);\n await options.removeDormantSession(record);\n options.headlessHub.notifySessionRemoved(record.sessionId);\n json(response, 200, { ok: true });\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n if (suffix === '' && request.method === 'GET') {\n json(response, 200, sessionView(session));\n return;\n }\n if (suffix === '' && request.method === 'DELETE') {\n sessionMcp.closeSessionBinding(sessionId);\n await options.headlessHub.closeSession(sessionId);\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/history' && request.method === 'GET' && options.sessionHistory) {\n json(response, 200, { sessions: await options.sessionHistory(session) });\n return;\n }\n if (suffix === '/avatar' && request.method === 'GET') {\n const avatar = options.headlessHub.sessionAvatar(sessionId);\n if (avatar === undefined) {\n json(response, 404, { error: 'This session has no avatar.' });\n return;\n }\n const current = url.searchParams.get('v') === session.profile?.iconVersion;\n response.writeHead(200, {\n 'content-type': avatar.mimeType,\n 'content-length': String(avatar.bytes.byteLength),\n 'cache-control': current ? 'private, max-age=31536000, immutable' : 'no-store',\n 'x-content-type-options': 'nosniff',\n });\n response.end(avatar.bytes);\n return;\n }\n if (suffix === '/file' && request.method === 'GET') {\n await writeResponse(response, await sessionFile(session, url.searchParams.get('path')));\n return;\n }\n if (suffix === '/restart' && request.method === 'POST' && options.restartSession) {\n const restart = options.restartSession(session);\n // Settled either way: a failed restart leaves the session dormant, and waiters then see that.\n const settled = restart.then(\n () => undefined,\n () => undefined,\n );\n restarting.set(sessionId, settled);\n try {\n await restart;\n } finally {\n if (restarting.get(sessionId) === settled) restarting.delete(sessionId);\n }\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/resume' && request.method === 'POST' && options.resumeSession) {\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n if (options.headlessHub.computerUse?.ownsSession?.(targetSessionId) && !desktopAuthorized(request)) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeSession(session, targetSessionId) });\n return;\n }\n if (suffix === '/channels' && request.method === 'GET') {\n json(response, 200, {\n channels: options.headlessHub\n .channelFrames(sessionId)\n .filter((frame) => frame.type !== 'computer_use_state' || desktopAuthorized(request)),\n });\n return;\n }\n const channelMatch = /^\\/channel\\/([^/]+)$/u.exec(suffix);\n if (channelMatch !== null && request.method === 'POST') {\n const frameType = decodeURIComponent(channelMatch[1]);\n const connectionId = request.headers['x-doompi-connection'];\n options.headlessHub.receiveChannel(\n sessionId,\n frameType,\n parseJson(await readBody(request)),\n typeof connectionId === 'string' ? connectionId : 'http',\n desktopAuthorized(request),\n );\n json(response, 202, { ok: true });\n return;\n }\n json(response, 404, { error: 'Not found.' });\n }\n\n server.on('upgrade', (request, socket, head) => {\n const url = requestPath(request);\n const mount = parseDoomSocketPath(url.pathname);\n if (!mount) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (!authorized(request, options.token)) {\n socket.write('HTTP/1.1 401 Unauthorized\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (\n mount.scope !== 'global' &&\n (!options.headlessHub.workspaces().some((entry) => entry.id === mount.workspaceId && entry.available !== false) ||\n (mount.scope === 'session' && options.headlessHub.session(mount.sessionId)?.workspaceId !== mount.workspaceId))\n ) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n const prepare =\n mount.scope === 'global' && options.headlessHub.computerUse === undefined\n ? Promise.resolve(protocol)\n : createHeadlessProtocol({\n hub: options.headlessHub,\n mount,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n authorizeSession: (id) => !options.headlessHub.computerUse?.ownsSession?.(id) || desktopAuthorized(request),\n authorizeDesktop: () => desktopAuthorized(request),\n });\n void prepare\n .then(async (selected) => {\n if (closed || socket.destroyed) {\n if (selected !== protocol) await selected.close();\n socket.destroy();\n return;\n }\n if (selected !== protocol) {\n scopedProtocols.add(selected);\n socket.once('close', () => {\n void selected.close().finally(() => scopedProtocols.delete(selected));\n });\n }\n webSockets.handleUpgrade(request, socket, head, (client) => {\n webSockets.emit('connection', client, selected);\n });\n })\n .catch(() => {\n socket.destroy();\n });\n });\n webSockets.on('connection', (socket, selected: typeof protocol) => {\n const handler = selected.accept(socket);\n if (!handler) return;\n const client: Client = { socket, handler };\n clients.add(client);\n socket.on('message', (data) => {\n if (Buffer.isBuffer(data)) handler.onData(data);\n else if (Array.isArray(data)) handler.onData(Buffer.concat(data));\n else handler.onData(new Uint8Array(data as ArrayBuffer));\n });\n socket.on('close', () => {\n clients.delete(client);\n handler.onClose();\n });\n socket.on('error', (error) => handler.onError(error));\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(options.port, options.host ?? '127.0.0.1', () => resolve());\n });\n const address = server.address();\n if (address === null || typeof address === 'string') {\n await new Promise<void>((resolve) => server.close(() => resolve()));\n throw new Error('The headless server did not expose a TCP address.');\n }\n const host = options.host ?? '127.0.0.1';\n const url = `http://${host}:${address.port}`;\n return {\n url,\n sessionReservations: sessionMcp.reservations,\n async close() {\n if (closed) return;\n closed = true;\n unsubscribe();\n for (const response of sse.keys()) response.end();\n sse.clear();\n for (const client of clients) client.socket.terminate();\n clients.clear();\n sessionMcp.close();\n if (options.sessionMcpStateDir === undefined)\n await fs.promises.rm(sessionMcpStateDir, { recursive: true, force: true });\n await Promise.all([protocol.close(), ...[...scopedProtocols].map((selected) => selected.close())]);\n webSockets.close();\n server.closeAllConnections();\n await new Promise<void>((resolve, reject) =>\n server.close((error) => (error === undefined ? resolve() : reject(error))),\n );\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,gCACX;AAEF,MAAM,cAAc;AACpB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAC/B,MAAM,6BAA6B;AACnC,MAAM,2BAA2B;AACjC,MAAM,cAAc;AACpB,MAAM,4BAA4B;AAClC,MAAM,yBAAyB;AAC/B,MAAM,6BAA+D;CACnE,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;AACV;AA4CA,SAAS,YAAY,SAAsD;CACzE,OAAO;EACL,IAAI,QAAQ;EACZ,aAAa,QAAQ;EACrB,gBAAgB,QAAQ;EACxB,MAAM,QAAQ;EACd,KAAK,QAAQ;EACb,WAAW,QAAQ;EACnB,WAAW,QAAQ,aAAa,QAAQ;EACxC,OAAO,QAAQ,SAAS;EACxB,YAAY,QAAQ,cAAc,QAAQ;EAC1C,QAAQ;EACR,qBAAqB,QAAQ,uBAAuB;EACpD,cAAc,QAAQ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AI,SAAe,SAAS,WAChC,OAAO,OAAO,UAAW,UAAU,KAAA,IAAY,QAAQ,IAAI,OAAO,KAAK,CAAE,CAC3E;EACF;CACF;AACF"}
1
+ {"version":3,"file":"headlessServer.mjs","names":[],"sources":["../src/server/headlessServer.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { Context } from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { WebSocket } from 'ws';\nimport { WebSocketServer } from 'ws';\n\nimport { API_BASE_PATH as CONTEXT_API_BASE_PATH } from '../constants/contextApi';\nimport {\n DOOM_API_CALLER_HEADERS,\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n parseDoomSocketPath,\n type DoomApiMount,\n} from '../exports/packageApi';\nimport type { TranscriptPage, TranscriptPageRequest } from '../exports/sessionProtocol';\nimport type { DoomHubSessionReservations } from '../schemas/hubChannel';\nimport { readContextDetail } from '../services/contextDetailStore';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport { observe, type ServerTelemetry } from '../services/serverTelemetry';\nimport { createSessionMcpActivityStore } from '../services/sessionMcpActivity';\nimport { createSessionMcpConversationStore } from '../services/sessionMcpConversations';\nimport { createSessionMcpRegistrationStore } from '../services/sessionMcpRegistrationStore';\nimport type { SavedSession } from '../services/sqliteSessionHistory';\nimport { createContextApi } from './contextApi';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession, HeadlessWorkspaceAdmission } from './headlessHub';\nimport { createHeadlessProtocol } from './headlessProtocol';\nimport { createSessionMcpRoutes, isPublicSessionMcpRoute, isSessionMcpHostRoute } from './sessionMcpRoutes';\n\n/**\n * The canonical public shape of a package API request, as dispatch reads it.\n *\n * Groups: workspace id, session id, plugin base path, and the remainder handed\n * to the package. `settings` is the host's own API and sits beside `plugins`\n * rather than under it.\n *\n * Exported so the browser's URL construction can be pinned against it. The two\n * are written independently, in halves of this package that may not import each\n * other, and a disagreement between them is not a 404 from the route: the\n * service worker answers an unrecognised path out of the signed bundle cache,\n * so the symptom appears nowhere near the cause.\n */\nexport const DOOM_PACKAGE_API_PATH_PATTERN =\n /^\\/api(?:\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?)?\\/(?:plugins\\/([^/]+)|settings)(?:\\/(.*))?$/u;\n\nconst HEALTH_ROLE = 'hub';\nconst PROTOCOL_VERSION = 1;\nconst MAX_BODY_BYTES = 8 * 1024 * 1024;\nconst MAX_SESSION_FILE_BYTES = 25 * 1024 * 1024;\nconst DIRECTORY_SUGGESTION_LIMIT = 12;\nconst DIRECTORY_CHILDREN_LIMIT = 500;\nconst HOME_PREFIX = '~';\nconst WORKSPACE_NAME_MAX_LENGTH = 80;\nconst WORKSPACE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/u;\nconst SESSION_FILE_CONTENT_TYPES: Readonly<Record<string, string>> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.m4v': 'video/mp4',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.pdf': 'application/pdf',\n};\n\nexport interface HeadlessServerOptions {\n headlessHub: HeadlessHub;\n port: number;\n host?: string;\n /** Requests other than health require this bearer token when set. */\n token?: string;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n compositions?: () => unknown;\n requestAsset?: (request: Request) => Promise<Response | undefined>;\n sessionHistory?: (session: HeadlessHubSession) => Promise<SavedSession[]>;\n workspaceHistory?: (workspaceId: string) => Promise<SavedSession[]>;\n resumeWorkspaceSession?: (workspaceId: string, targetSessionId: string) => Promise<string>;\n readDormantTranscript?: (\n record: OpenSessionRecord,\n request: TranscriptPageRequest,\n context: Context,\n ) => Promise<TranscriptPage>;\n restartSession?: (session: HeadlessHubSession) => Promise<void>;\n resumeSession?: (session: HeadlessHubSession, targetSessionId: string) => Promise<string>;\n /** Recorded sessions this server has not reopened, surfaced so a client can ask for one. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n removeDormantSession?: (record: OpenSessionRecord) => void | Promise<void>;\n reviveSession?: (record: OpenSessionRecord) => Promise<void>;\n /** Trusted HTTPS origin advertised for public session MCP and OAuth endpoints. */\n sessionMcpPublicOrigin?: () => string | undefined;\n /** Durable state directory for verified Session MCP clients. */\n sessionMcpStateDir?: string;\n /** Monotonic exposure revision, including disable/re-enable cycles. */\n sessionMcpPublicOriginRevision?: () => number;\n isSessionPersisted?: (sessionId: string, cwd: string) => boolean;\n}\n\nexport interface HeadlessServer {\n readonly url: string;\n readonly sessionReservations: DoomHubSessionReservations;\n close(): Promise<void>;\n}\n\ntype ProtocolHandler = NonNullable<ReturnType<Awaited<ReturnType<typeof createHeadlessProtocol>>['accept']>>;\ntype Client = { socket: WebSocket; handler: ProtocolHandler };\n\nfunction sessionView(session: HeadlessHubSession): Record<string, unknown> {\n return {\n id: session.id,\n workspaceId: session.workspaceId,\n webComposition: session.webComposition,\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n ...(session.git === undefined ? {} : { git: { ...session.git } }),\n ...(session.profile === undefined ? {} : { profile: { ...session.profile } }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.pendingSetups === undefined ? {} : { pendingSetups: session.pendingSetups }),\n ...(session.activity === undefined ? {} : { activity: { ...session.activity } }),\n };\n}\n\n/** The dormant counterpart of `sessionView`; same shape, no runtime behind it. */\nfunction dormantView(record: OpenSessionRecord): Record<string, unknown> {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'detached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n };\n}\n\nfunction json(response: ServerResponse, status: number, value: unknown): void {\n const body = JSON.stringify(value);\n response.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'content-length': Buffer.byteLength(body),\n });\n response.end(body);\n}\n\nfunction authorized(request: IncomingMessage, token: string | undefined): boolean {\n if (token === undefined) return true;\n const authorization = request.headers.authorization;\n if (authorization?.startsWith('Bearer ') && authorization.slice('Bearer '.length) === token) return true;\n const header = request.headers['x-doompi-token'];\n if (typeof header === 'string' && header === token) return true;\n try {\n return new URL(request.url ?? '/', 'http://doompi.local').searchParams.get('token') === token;\n } catch {\n return false;\n }\n}\n\nfunction requestPath(request: IncomingMessage): URL {\n return new URL(request.url ?? '/', 'http://doompi.local');\n}\n\nfunction parseTranscriptRequest(url: URL): TranscriptPageRequest {\n const request: TranscriptPageRequest = {};\n const cursor = url.searchParams.get('cursor');\n const direction = url.searchParams.get('direction');\n const limit = url.searchParams.get('limit');\n if (cursor !== null) request.cursor = cursor;\n if (direction !== null) {\n if (direction !== 'older' && direction !== 'newer') throw new Error('Invalid transcript direction');\n request.direction = direction;\n }\n if (limit !== null) {\n if (!/^\\d+$/u.test(limit)) throw new Error('Invalid transcript page limit');\n const parsed = Number(limit);\n if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 100) throw new Error('Invalid transcript page limit');\n request.limit = parsed;\n }\n return request;\n}\n\nasync function sessionFile(session: HeadlessHubSession, requestedPath: string | null): Promise<Response> {\n if (!requestedPath || requestedPath.includes('\\0'))\n return Response.json({ error: 'Invalid session file path.' }, { status: 400 });\n let root: string;\n let filePath: string;\n try {\n root = await fs.promises.realpath(session.cwd);\n filePath = await fs.promises.realpath(path.resolve(root, requestedPath));\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n const contained = path.relative(root, filePath);\n if (contained === '..' || contained.startsWith(`..${path.sep}`) || path.isAbsolute(contained))\n return Response.json({ error: 'Session file is outside the working directory.' }, { status: 403 });\n let handle: fs.promises.FileHandle;\n try {\n handle = await fs.promises.open(filePath, 'r');\n } catch {\n return Response.json({ error: 'Session file not found.' }, { status: 404 });\n }\n try {\n const stat = await handle.stat();\n if (!stat.isFile()) return Response.json({ error: 'Session file not found.' }, { status: 404 });\n if (stat.size > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n const bytes = await handle.readFile();\n if (bytes.byteLength > MAX_SESSION_FILE_BYTES)\n return Response.json({ error: 'Session file is too large.' }, { status: 413 });\n return new Response(bytes, {\n headers: {\n 'content-type': SESSION_FILE_CONTENT_TYPES[path.extname(filePath).toLowerCase()] ?? 'application/octet-stream',\n 'content-length': String(bytes.byteLength),\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n },\n });\n } finally {\n await handle.close();\n }\n}\n\n/** Expands a leading `~` the way a shell would, so typed paths match what the user sees in a terminal. */\nfunction expandHome(value: string): string {\n if (value === HOME_PREFIX) return os.homedir();\n return value.startsWith(`${HOME_PREFIX}${path.sep}`) ? path.join(os.homedir(), value.slice(2)) : value;\n}\n\n/**\n * Validates an add-workspace request. A name alone asks for a new default folder,\n * so it must be safe to use as one folder name.\n */\nfunction parseWorkspaceAdmission(body: unknown): HeadlessWorkspaceAdmission | { error: string } {\n if (typeof body !== 'object' || body === null) return { error: 'A workspace root or name is required.' };\n const record = body as Record<string, unknown>;\n if (record.root !== undefined && typeof record.root !== 'string')\n return { error: 'The workspace root must be text.' };\n if (record.name !== undefined && typeof record.name !== 'string')\n return { error: 'The workspace name must be text.' };\n const root =\n typeof record.root === 'string' && record.root.trim() !== '' ? expandHome(record.root.trim()) : undefined;\n const name = typeof record.name === 'string' && record.name.trim() !== '' ? record.name.trim() : undefined;\n if (root === undefined && name === undefined) return { error: 'A workspace root or name is required.' };\n if (\n name !== undefined &&\n (name.length > WORKSPACE_NAME_MAX_LENGTH || !WORKSPACE_NAME_PATTERN.test(name) || name.includes('..'))\n )\n return {\n error: `Workspace names use letters, numbers, spaces, dots, dashes, or underscores (up to ${String(WORKSPACE_NAME_MAX_LENGTH)} characters).`,\n };\n return { ...(root === undefined ? {} : { root }), ...(name === undefined ? {} : { name }) };\n}\n\nasync function directorySuggestions(query: string, sessions: readonly HeadlessHubSession[]): Promise<string[]> {\n const typed = expandHome(query.trim());\n if (typed === '') return [];\n const matches = (value: string): boolean => value.toLowerCase().includes(typed.toLowerCase());\n const known = [...new Set([process.cwd(), ...sessions.map((session) => session.cwd)])].filter(matches);\n const candidates = path.isAbsolute(typed)\n ? [typed]\n : typed.includes(path.sep)\n ? [path.resolve(process.cwd(), typed)]\n : [path.join(path.dirname(process.cwd()), typed), path.join(process.cwd(), typed)];\n const completed: string[] = [];\n for (const candidate of candidates) {\n const drilling = typed.endsWith(path.sep);\n const parent = drilling ? candidate : path.dirname(candidate);\n const partial = drilling ? '' : path.basename(candidate).toLowerCase();\n try {\n const entries = await fs.promises.readdir(parent, { withFileTypes: true });\n completed.push(\n ...entries\n .filter((entry) => entry.isDirectory() && entry.name.toLowerCase().includes(partial))\n .map((entry) => path.join(parent, entry.name)),\n );\n } catch {\n // A missing or unreadable parent simply has no completions.\n }\n }\n return [...new Set([...known, ...completed.sort((left, right) => left.localeCompare(right))])].slice(\n 0,\n DIRECTORY_SUGGESTION_LIMIT,\n );\n}\n\n/**\n * Lists the visible child directories of one folder for the workspace folder browser.\n * Resolves undefined for a relative, missing, or unreadable path.\n */\nasync function directoryChildren(\n requested: string | null,\n): Promise<{ path: string; parent?: string; directories: string[] } | undefined> {\n const directory = requested === null || requested.trim() === '' ? os.homedir() : expandHome(requested.trim());\n if (!path.isAbsolute(directory)) return undefined;\n const resolved = path.resolve(directory);\n let entries: fs.Dirent[];\n try {\n entries = await fs.promises.readdir(resolved, { withFileTypes: true });\n } catch {\n return undefined;\n }\n const directories = entries\n .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))\n .map((entry) => path.join(resolved, entry.name))\n .sort((left, right) => left.localeCompare(right))\n .slice(0, DIRECTORY_CHILDREN_LIMIT);\n const parent = path.dirname(resolved);\n return { path: resolved, ...(parent === resolved ? {} : { parent }), directories };\n}\n\nasync function readBody(request: IncomingMessage): Promise<Uint8Array> {\n const chunks: Buffer[] = [];\n let size = 0;\n for await (const chunk of request) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n size += buffer.byteLength;\n if (size > MAX_BODY_BYTES) throw new Error('Request body is too large.');\n chunks.push(buffer);\n }\n return Buffer.concat(chunks);\n}\n\nfunction parseJson(body: Uint8Array): unknown {\n if (body.byteLength === 0) return {};\n return JSON.parse(Buffer.from(body).toString('utf8')) as unknown;\n}\n\nfunction webRequest(request: IncomingMessage, url: URL, signal?: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined) headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n return new Request(url, {\n method: request.method,\n headers,\n signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : {\n body: Readable.toWeb(request) as never,\n duplex: 'half' as const,\n }),\n });\n}\n\nasync function writeResponse(response: ServerResponse, result: Response): Promise<void> {\n response.writeHead(result.status, Object.fromEntries(result.headers.entries()));\n if (result.body === null) {\n response.end();\n return;\n }\n await pipeline(Readable.fromWeb(result.body as import('node:stream/web').ReadableStream), response);\n}\n\nfunction eventFrame(event: HeadlessHubEvent): Record<string, unknown> {\n switch (event.kind) {\n case 'upsert':\n return { type: 'session_upsert', session: sessionView(event.session) };\n case 'removed':\n return { type: 'session_removed', sessionId: event.sessionId };\n case 'workspace_upsert':\n return { type: 'workspace_upsert', workspace: event.workspace };\n case 'workspace_removed':\n return { type: 'workspace_removed', workspaceId: event.workspaceId };\n case 'channel':\n return {\n type: 'channel_frame',\n frameType: event.frameType,\n sessionId: event.sessionId,\n payload: event.payload,\n ...(event.connectionId === undefined ? {} : { connectionId: event.connectionId }),\n };\n }\n}\n\nfunction writeSse(response: ServerResponse, event: string, value: unknown): void {\n response.write(`event: ${event}\\ndata: ${JSON.stringify(value)}\\n\\n`);\n}\n\n/**\n * Client-neutral HTTP and WebSocket boundary for the process-local headless hub.\n * It deliberately delegates every session operation to HeadlessHub, so transport\n * clients cannot create a second session backend or bypass its lifecycle.\n */\nexport async function serveHeadlessServer(options: HeadlessServerOptions): Promise<HeadlessServer> {\n const clients = new Set<Client>();\n const scopedProtocols = new Set<Awaited<ReturnType<typeof createHeadlessProtocol>>>();\n const sse = new Map<ServerResponse, () => boolean>();\n const desktopAuthorized = (request: IncomingMessage): boolean => {\n const proof = request.headers['x-doompi-desktop'];\n return (\n typeof proof === 'string' &&\n options.headlessHub.computerUse?.authorize?.(new Headers({ 'x-doompi-desktop': proof })) === true\n );\n };\n let closed = false;\n const webSockets = new WebSocketServer({ noServer: true });\n /**\n * A recorded session is dormant exactly while the hub has no session for its\n * id, so reviving one needs no bookkeeping beyond the hub itself.\n */\n const dormant = (): readonly OpenSessionRecord[] =>\n (options.dormantSessions?.() ?? []).filter((record) => options.headlessHub.session(record.sessionId) === undefined);\n const protocol = await createHeadlessProtocol({\n hub: options.headlessHub,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n });\n const sessionMcpStateDir =\n options.sessionMcpStateDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'doompi-session-mcp-'));\n const sessionMcp = createSessionMcpRoutes({\n headlessHub: options.headlessHub,\n publicOrigin: options.sessionMcpPublicOrigin ?? (() => undefined),\n publicOriginRevision: options.sessionMcpPublicOriginRevision,\n onNotice: options.onNotice,\n isSessionPersisted: options.isSessionPersisted,\n activityStore: createSessionMcpActivityStore(sessionMcpStateDir),\n conversationStore: createSessionMcpConversationStore(sessionMcpStateDir),\n registrationStore: createSessionMcpRegistrationStore({ stateDir: sessionMcpStateDir, onNotice: options.onNotice }),\n });\n /** Sessions being restarted, keyed by id, settled once the reopen succeeds or fails. */\n const restarting = new Map<string, Promise<void>>();\n const server = createServer((request, response) => {\n void handleRequest(request, response).catch((error: unknown) => {\n if (response.headersSent) {\n response.destroy();\n return;\n }\n options.onNotice?.(`Headless request failed: ${harnessErrorMessage(error)}`);\n json(response, 500, { error: 'Internal server error.' });\n });\n });\n\n const unsubscribe = options.headlessHub.onEvent((event) => {\n const frame = eventFrame(event);\n const sessionId = event.kind === 'upsert' ? event.session.id : 'sessionId' in event ? event.sessionId : undefined;\n for (const [response, native] of sse) {\n if (\n (sessionId !== undefined && options.headlessHub.computerUse?.ownsSession?.(sessionId)) ||\n frame.type === 'computer_use_state'\n ) {\n if (!native()) continue;\n }\n writeSse(response, String(frame.type), frame);\n }\n });\n\n async function handleRequest(request: IncomingMessage, response: ServerResponse): Promise<void> {\n const url = requestPath(request);\n if (url.pathname === '/api/health' && request.method === 'GET') {\n json(response, 200, {\n ok: true,\n role: HEALTH_ROLE,\n protocol: PROTOCOL_VERSION,\n sessions: options.headlessHub.snapshot().length,\n });\n return;\n }\n const scopedSession = /^\\/api\\/workspaces\\/[^/]+\\/sessions\\/([^/]+)(?:\\/|$)/u.exec(url.pathname)?.[1];\n if (\n scopedSession &&\n options.headlessHub.computerUse?.ownsSession?.(decodeURIComponent(scopedSession)) &&\n !desktopAuthorized(request)\n ) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n if (isPublicSessionMcpRoute(request.method ?? 'GET', url.pathname)) {\n const sessionMcpAbort = new AbortController();\n const abortSessionMcp = (): void => {\n if (!response.writableEnded) sessionMcpAbort.abort();\n };\n response.once('close', abortSessionMcp);\n const publicSessionMcp = await sessionMcp.handlePublic(webRequest(request, url, sessionMcpAbort.signal));\n if (publicSessionMcp !== undefined) {\n try {\n await writeResponse(response, publicSessionMcp);\n } finally {\n response.off('close', abortSessionMcp);\n }\n return;\n }\n response.off('close', abortSessionMcp);\n }\n if (!authorized(request, options.token)) {\n json(response, 401, { error: 'Unauthorized.' });\n return;\n }\n // A restart closes the session before reopening it under the same id. Any session-scoped\n // request that lands in that gap, such as a plugin's poll, waits for the reopened session.\n const reopening = scopedSession === undefined ? undefined : restarting.get(decodeURIComponent(scopedSession));\n if (reopening !== undefined && options.headlessHub.session(decodeURIComponent(scopedSession!)) === undefined)\n await reopening;\n if (isSessionMcpHostRoute(url.pathname)) {\n const hostSessionMcp = await sessionMcp.handleHost(webRequest(request, url));\n if (hostSessionMcp !== undefined) {\n await writeResponse(response, hostSessionMcp);\n return;\n }\n }\n if (url.pathname === '/api/remote' || url.pathname.startsWith('/api/remote/')) {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (value !== undefined && name !== 'authorization' && name !== 'x-doompi-token')\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n const result = await options.headlessHub.requestApi(\n { scope: 'global' },\n 'remote',\n new Request(`http://doompi.local${url.pathname.slice('/api/remote'.length)}${url.search}`, {\n method: request.method,\n headers,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n await writeResponse(response, result);\n return;\n }\n if (url.pathname === '/api/telemetry/browser' && request.method === 'POST') {\n const body = JSON.parse(new TextDecoder().decode(await readBody(request))) as { v?: unknown; events?: unknown };\n if (body.v !== 1 || !Array.isArray(body.events) || body.events.length > 10) {\n json(response, 400, { error: 'Invalid browser telemetry batch.' });\n return;\n }\n for (const event of body.events) {\n if (\n !event ||\n typeof event !== 'object' ||\n typeof event.name !== 'string' ||\n !/^web\\.browser\\.[a-z_]{1,40}$/u.test(event.name)\n )\n continue;\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent(event.name, {\n ...(typeof event.duration_ms === 'number' && Number.isFinite(event.duration_ms) && event.duration_ms >= 0\n ? { duration_ms: event.duration_ms }\n : {}),\n ...(typeof event.count === 'number' && Number.isFinite(event.count) && event.count >= 0\n ? { count: event.count }\n : {}),\n }),\n );\n }\n json(response, 200, { ok: true });\n return;\n }\n if (url.pathname === '/api/compositions' && request.method === 'GET') {\n json(response, 200, options.compositions?.() ?? { workspaces: [] });\n return;\n }\n if (\n (url.pathname.startsWith('/api/web-plugins/') ||\n url.pathname === '/bundle-manifest.json' ||\n url.pathname.startsWith('/bundle-assets/')) &&\n options.requestAsset\n ) {\n const result = await options.requestAsset(new Request(url, { method: request.method }));\n if (result) {\n await writeResponse(response, result);\n return;\n }\n }\n if (url.pathname === '/api/directories/children' && request.method === 'GET') {\n const listing = await directoryChildren(url.searchParams.get('path'));\n if (listing === undefined) json(response, 404, { error: 'That folder cannot be read.' });\n else json(response, 200, listing);\n return;\n }\n if (url.pathname === '/api/directories' && request.method === 'GET') {\n json(response, 200, {\n directories: await directorySuggestions(url.searchParams.get('q') ?? '', options.headlessHub.snapshot()),\n });\n return;\n }\n // Verified browser bundles can remain active across a server upgrade. Keep\n // their former create route working while they refresh to workspace routes.\n if (url.pathname === '/api/sessions' && request.method === 'POST') {\n const body = parseJson(await readBody(request));\n if (\n !body ||\n typeof body !== 'object' ||\n !('cwd' in body) ||\n typeof body.cwd !== 'string' ||\n !body.cwd.trim() ||\n ('name' in body && typeof body.name !== 'string')\n ) {\n json(response, 400, { error: 'A session needs a working directory and an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: body.cwd,\n name: 'name' in body ? String(body.name) : path.basename(body.cwd),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n const workspaceSessions = /^\\/api\\/workspaces\\/([^/]+)\\/sessions$/u.exec(url.pathname);\n if (workspaceSessions) {\n const workspaceId = decodeURIComponent(workspaceSessions[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (request.method === 'GET') {\n json(response, 200, {\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter((session) => session.workspaceId === workspaceId)\n .map(sessionView),\n ...dormant()\n .filter((record) => record.workspaceId === workspaceId)\n .map(dormantView),\n ],\n });\n return;\n }\n if (request.method === 'POST') {\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n if (!body || typeof body !== 'object' || ('name' in body && typeof body.name !== 'string')) {\n json(response, 400, { error: 'A session accepts an optional name.' });\n return;\n }\n const created = await options.headlessHub.sessionService.create({\n cwd: workspace.root,\n name: 'name' in body ? String(body.name) : path.basename(workspace.root),\n });\n json(response, 201, { sessionId: created.sessionId });\n return;\n }\n }\n if (url.pathname === '/api/events' && request.method === 'GET') {\n response.writeHead(200, {\n 'cache-control': 'no-cache',\n connection: 'keep-alive',\n 'content-type': 'text/event-stream; charset=utf-8',\n });\n sse.set(response, () => desktopAuthorized(request));\n response.on('close', () => sse.delete(response));\n writeSse(response, 'sessions_snapshot', {\n type: 'sessions_snapshot',\n sessions: [\n ...options.headlessHub\n .snapshot()\n .filter(\n (session) => !options.headlessHub.computerUse?.ownsSession?.(session.id) || desktopAuthorized(request),\n )\n .map(sessionView),\n ...dormant().map(dormantView),\n ],\n });\n writeSse(response, 'workspaces_snapshot', {\n type: 'workspaces_snapshot',\n workspaces: options.headlessHub.workspaces(),\n });\n return;\n }\n if (url.pathname === '/api/workspaces') {\n if (request.method === 'GET') {\n json(response, 200, { workspaces: options.headlessHub.workspaces() });\n return;\n }\n if (request.method === 'POST') {\n const admission = parseWorkspaceAdmission(parseJson(await readBody(request)));\n if ('error' in admission) {\n json(response, 400, admission);\n return;\n }\n let workspace: Awaited<ReturnType<HeadlessHub['admitWorkspace']>>;\n try {\n workspace = await options.headlessHub.admitWorkspace(admission);\n } catch (error) {\n json(response, 422, { error: error instanceof Error ? error.message : String(error) });\n return;\n }\n json(response, 201, { workspace });\n return;\n }\n }\n const workspaceHistoryMatch = /^\\/api\\/workspaces\\/([^/]+)\\/history$/u.exec(url.pathname);\n if (workspaceHistoryMatch && request.method === 'GET' && options.workspaceHistory) {\n const workspaceId = decodeURIComponent(workspaceHistoryMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n json(response, 200, { sessions: await options.workspaceHistory(workspaceId) });\n return;\n }\n const workspaceResumeMatch = /^\\/api\\/workspaces\\/([^/]+)\\/resume$/u.exec(url.pathname);\n if (workspaceResumeMatch && request.method === 'POST' && options.resumeWorkspaceSession) {\n const workspaceId = decodeURIComponent(workspaceResumeMatch[1]);\n const workspace = options.headlessHub.workspaces().find((entry) => entry.id === workspaceId);\n if (!workspace) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (workspace.available === false) {\n json(response, 409, { error: 'Workspace is unavailable.' });\n return;\n }\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeWorkspaceSession(workspaceId, targetSessionId) });\n return;\n }\n const workspaceMatch = /^\\/api\\/workspaces\\/([^/]+)$/u.exec(url.pathname);\n if (workspaceMatch && request.method === 'GET') {\n const workspace = options.headlessHub\n .workspaces()\n .find((entry) => entry.id === decodeURIComponent(workspaceMatch[1]));\n json(response, workspace ? 200 : 404, workspace ? { workspace } : { error: 'Workspace not found.' });\n return;\n }\n if (workspaceMatch && request.method === 'DELETE') {\n const id = decodeURIComponent(workspaceMatch[1]);\n if (!options.headlessHub.workspaces().some((workspace) => workspace.id === id)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (\n options.headlessHub.snapshot().some((session) => session.workspaceId === id) ||\n dormant().some((session) => session.workspaceId === id)\n ) {\n json(response, 409, { error: 'Workspace still has sessions.' });\n return;\n }\n await options.headlessHub.removeWorkspace(id);\n json(response, 200, { ok: true });\n return;\n }\n const pluginMatch = DOOM_PACKAGE_API_PATH_PATTERN.exec(url.pathname);\n if (pluginMatch !== null && request.method !== 'CONNECT') {\n const workspaceId = pluginMatch[1] === undefined ? undefined : decodeURIComponent(pluginMatch[1]);\n const sessionId = pluginMatch[2] === undefined ? undefined : decodeURIComponent(pluginMatch[2]);\n if (workspaceId !== undefined && !options.headlessHub.workspaces().some((entry) => entry.id === workspaceId)) {\n json(response, 404, { error: 'Workspace not found.' });\n return;\n }\n if (sessionId !== undefined && options.headlessHub.session(sessionId)?.workspaceId !== workspaceId) {\n // A stopped session still shows the composition it last published, so its context detail\n // is served from the file it wrote. Nothing else answers until it is woken.\n const stopped = dormant().some(\n (record) => record.sessionId === sessionId && record.workspaceId === workspaceId,\n );\n if (stopped && pluginMatch[3] === CONTEXT_API_BASE_PATH && request.method === 'GET') {\n const detail = await createContextApi({ sessionId, environment: process.env }).fetch(\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`),\n );\n const body = (await detail.json()) as { error?: string };\n // The detail file is only kept while the session runs, so a stopped session usually has none.\n if (readContextDetail(sessionId, process.env) === undefined)\n json(response, 404, { error: 'This session is stopped. Wake it to read this item.' });\n else json(response, detail.status, body);\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n const mount: DoomApiMount =\n sessionId !== undefined\n ? { scope: 'session', sessionId }\n : workspaceId !== undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'global' };\n const basePath = pluginMatch[3] === undefined ? 'settings' : decodeURIComponent(pluginMatch[3]);\n if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(basePath)) {\n json(response, 400, { error: 'Invalid package API base path.' });\n return;\n }\n if (pluginMatch[3] === 'settings' || (sessionId !== undefined && basePath === 'settings')) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const headers = new Headers();\n // Only the authenticated loopback proxy knows the server token and may\n // forward caller stamps. Browser-supplied stamps remain untrusted.\n const trustedCaller = options.token !== undefined && authorized(request, options.token);\n for (const [name, value] of Object.entries(request.headers)) {\n if (\n value !== undefined &&\n !['host', 'authorization', 'x-doompi-token'].includes(name) &&\n (trustedCaller || !DOOM_API_CALLER_HEADERS.includes(name as (typeof DOOM_API_CALLER_HEADERS)[number]))\n )\n headers.set(name, Array.isArray(value) ? value.join(', ') : value);\n }\n if (!trustedCaller) {\n headers.set(DOOM_API_CALLER_LOCALITY_HEADER, 'local');\n headers.set(DOOM_API_CALLER_STEP_UP_HEADER, 'not-required');\n }\n const abort = new AbortController();\n const disconnected = (): void => {\n if (!response.writableEnded) abort.abort();\n };\n response.once('close', disconnected);\n try {\n const started = performance.now();\n const attributes = {\n scope: mount.scope,\n 'plugin.name': basePath,\n 'http.operation': request.method,\n ...(mount.scope === 'workspace' ? { 'workspace.id': mount.workspaceId } : {}),\n ...(mount.scope === 'session' ? { 'session.id': mount.sessionId } : {}),\n };\n const dispatch = async () =>\n options.headlessHub.requestApi(\n mount,\n basePath,\n new Request(`http://doompi.local/${pluginMatch[4] ?? ''}${url.search}`, {\n method: request.method,\n headers,\n signal: abort.signal,\n ...(request.method === 'GET' || request.method === 'HEAD'\n ? {}\n : { body: Buffer.from(await readBody(request)) }),\n }),\n );\n const result = options.telemetry\n ? await options.telemetry.runInSpan('doompi_server.plugin.request', attributes, dispatch)\n : await dispatch();\n if (options.telemetry)\n observe(\n options.telemetry.recordEvent('doompi_server.plugin.response', {\n ...attributes,\n status: result.status,\n durationMs: performance.now() - started,\n }),\n options.onNotice,\n );\n await writeResponse(response, result);\n } finally {\n response.off('close', disconnected);\n }\n return;\n }\n const sessionMatch = /^\\/api\\/workspaces\\/([^/]+)\\/sessions\\/([^/]+)(?:\\/(.*))?$/u.exec(url.pathname);\n if (sessionMatch === null) {\n json(response, 404, { error: 'Not found.' });\n return;\n }\n const sessionId = decodeURIComponent(sessionMatch[2]);\n const workspaceId = decodeURIComponent(sessionMatch[1]);\n const session = options.headlessHub.session(sessionId);\n const suffix = sessionMatch[3] === undefined ? '' : `/${sessionMatch[3]}`;\n if (suffix === '/transcript' && request.method === 'GET' && options.readDormantTranscript) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n let transcriptRequest: TranscriptPageRequest;\n try {\n transcriptRequest = parseTranscriptRequest(url);\n } catch (error) {\n json(response, 400, { error: error instanceof Error ? error.message : 'Invalid transcript request.' });\n return;\n }\n try {\n const page = await options.readDormantTranscript(record, transcriptRequest, BACKGROUND_CONTEXT);\n json(response, 200, page);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n const status = message === 'STALE_TRANSCRIPT_CURSOR' ? 409 : 422;\n json(response, status, {\n error: status === 409 ? 'STALE_TRANSCRIPT_CURSOR' : 'Saved transcript is unavailable.',\n });\n }\n return;\n }\n // Revive is the one session route that answers before a runtime exists: it\n // is what creates one.\n if (sessionMatch[3] === 'revive' && request.method === 'POST' && options.reviveSession) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (record === undefined) {\n json(response, 404, { error: 'Dormant session not found.' });\n return;\n }\n await options.reviveSession(record);\n json(response, 200, { ok: true });\n return;\n }\n if (session === undefined || session.workspaceId !== workspaceId) {\n const record = dormant().find(\n (candidate) => candidate.sessionId === sessionId && candidate.workspaceId === workspaceId,\n );\n if (request.method === 'DELETE' && record !== undefined && options.removeDormantSession !== undefined) {\n sessionMcp.closeSessionBinding(record.sessionId);\n await options.removeDormantSession(record);\n options.headlessHub.notifySessionRemoved(record.sessionId);\n json(response, 200, { ok: true });\n return;\n }\n json(response, 404, { error: 'Session not found.' });\n return;\n }\n if (suffix === '' && request.method === 'GET') {\n json(response, 200, sessionView(session));\n return;\n }\n if (suffix === '' && request.method === 'DELETE') {\n sessionMcp.closeSessionBinding(sessionId);\n await options.headlessHub.closeSession(sessionId);\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/history' && request.method === 'GET' && options.sessionHistory) {\n json(response, 200, { sessions: await options.sessionHistory(session) });\n return;\n }\n if (suffix === '/avatar' && request.method === 'GET') {\n const avatar = options.headlessHub.sessionAvatar(sessionId);\n if (avatar === undefined) {\n json(response, 404, { error: 'This session has no avatar.' });\n return;\n }\n const current = url.searchParams.get('v') === session.profile?.iconVersion;\n response.writeHead(200, {\n 'content-type': avatar.mimeType,\n 'content-length': String(avatar.bytes.byteLength),\n 'cache-control': current ? 'private, max-age=31536000, immutable' : 'no-store',\n 'x-content-type-options': 'nosniff',\n });\n response.end(avatar.bytes);\n return;\n }\n if (suffix === '/file' && request.method === 'GET') {\n await writeResponse(response, await sessionFile(session, url.searchParams.get('path')));\n return;\n }\n if (suffix === '/restart' && request.method === 'POST' && options.restartSession) {\n const restart = options.restartSession(session);\n // Settled either way: a failed restart leaves the session dormant, and waiters then see that.\n const settled = restart.then(\n () => undefined,\n () => undefined,\n );\n restarting.set(sessionId, settled);\n try {\n await restart;\n } finally {\n if (restarting.get(sessionId) === settled) restarting.delete(sessionId);\n }\n json(response, 200, { ok: true });\n return;\n }\n if (suffix === '/resume' && request.method === 'POST' && options.resumeSession) {\n const body = parseJson(await readBody(request));\n const targetSessionId =\n body && typeof body === 'object' && 'targetSessionId' in body ? body.targetSessionId : undefined;\n if (typeof targetSessionId !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(targetSessionId)) {\n json(response, 400, { error: 'Invalid target session id.' });\n return;\n }\n if (options.headlessHub.computerUse?.ownsSession?.(targetSessionId) && !desktopAuthorized(request)) {\n json(response, 404, { error: 'This session belongs to its Desktop instance.' });\n return;\n }\n json(response, 200, { sessionId: await options.resumeSession(session, targetSessionId) });\n return;\n }\n if (suffix === '/channels' && request.method === 'GET') {\n json(response, 200, {\n channels: options.headlessHub\n .channelFrames(sessionId)\n .filter((frame) => frame.type !== 'computer_use_state' || desktopAuthorized(request)),\n });\n return;\n }\n const channelMatch = /^\\/channel\\/([^/]+)$/u.exec(suffix);\n if (channelMatch !== null && request.method === 'POST') {\n const frameType = decodeURIComponent(channelMatch[1]);\n const connectionId = request.headers['x-doompi-connection'];\n options.headlessHub.receiveChannel(\n sessionId,\n frameType,\n parseJson(await readBody(request)),\n typeof connectionId === 'string' ? connectionId : 'http',\n desktopAuthorized(request),\n );\n json(response, 202, { ok: true });\n return;\n }\n json(response, 404, { error: 'Not found.' });\n }\n\n server.on('upgrade', (request, socket, head) => {\n const url = requestPath(request);\n const mount = parseDoomSocketPath(url.pathname);\n if (!mount) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (!authorized(request, options.token)) {\n socket.write('HTTP/1.1 401 Unauthorized\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n if (\n mount.scope !== 'global' &&\n (!options.headlessHub.workspaces().some((entry) => entry.id === mount.workspaceId && entry.available !== false) ||\n (mount.scope === 'session' && options.headlessHub.session(mount.sessionId)?.workspaceId !== mount.workspaceId))\n ) {\n socket.write('HTTP/1.1 404 Not Found\\r\\n\\r\\n');\n socket.destroy();\n return;\n }\n const prepare =\n mount.scope === 'global' && options.headlessHub.computerUse === undefined\n ? Promise.resolve(protocol)\n : createHeadlessProtocol({\n hub: options.headlessHub,\n mount,\n telemetry: options.telemetry,\n onNotice: options.onNotice,\n dormantSessions: dormant,\n authorizeSession: (id) => !options.headlessHub.computerUse?.ownsSession?.(id) || desktopAuthorized(request),\n authorizeDesktop: () => desktopAuthorized(request),\n });\n void prepare\n .then(async (selected) => {\n if (closed || socket.destroyed) {\n if (selected !== protocol) await selected.close();\n socket.destroy();\n return;\n }\n if (selected !== protocol) {\n scopedProtocols.add(selected);\n socket.once('close', () => {\n void selected.close().finally(() => scopedProtocols.delete(selected));\n });\n }\n webSockets.handleUpgrade(request, socket, head, (client) => {\n webSockets.emit('connection', client, selected);\n });\n })\n .catch(() => {\n socket.destroy();\n });\n });\n webSockets.on('connection', (socket, selected: typeof protocol) => {\n const handler = selected.accept(socket);\n if (!handler) return;\n const client: Client = { socket, handler };\n clients.add(client);\n socket.on('message', (data) => {\n if (Buffer.isBuffer(data)) handler.onData(data);\n else if (Array.isArray(data)) handler.onData(Buffer.concat(data));\n else handler.onData(new Uint8Array(data as ArrayBuffer));\n });\n socket.on('close', () => {\n clients.delete(client);\n handler.onClose();\n });\n socket.on('error', (error) => handler.onError(error));\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(options.port, options.host ?? '127.0.0.1', () => resolve());\n });\n const address = server.address();\n if (address === null || typeof address === 'string') {\n await new Promise<void>((resolve) => server.close(() => resolve()));\n throw new Error('The headless server did not expose a TCP address.');\n }\n const host = options.host ?? '127.0.0.1';\n const url = `http://${host}:${address.port}`;\n return {\n url,\n sessionReservations: sessionMcp.reservations,\n async close() {\n if (closed) return;\n closed = true;\n unsubscribe();\n for (const response of sse.keys()) response.end();\n sse.clear();\n for (const client of clients) client.socket.terminate();\n clients.clear();\n sessionMcp.close();\n if (options.sessionMcpStateDir === undefined)\n await fs.promises.rm(sessionMcpStateDir, { recursive: true, force: true });\n await Promise.all([protocol.close(), ...[...scopedProtocols].map((selected) => selected.close())]);\n webSockets.close();\n server.closeAllConnections();\n await new Promise<void>((resolve, reject) =>\n server.close((error) =>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AAO,QAAQ;CAC/B,IAAI,YAAY,QAAQ,OAAO,YAAY,UAAU;EACnD,MAAM,IAAI,SAAe,YAAY,OAAO,YAAY,QAAQ,CAAC,CAAC;EAClE,MAAM,IAAI,MAAM,mDAAmD;CACrE;CAGA,OAAO;EACL,KAAA,UAHW,QAAQ,QAAQ,YACF,GAAG,QAAQ;EAGpC,qBAAqB,WAAW;EAChC,MAAM,QAAQ;GACZ,IAAI,QAAQ;GACZ,SAAS;GACT,YAAY;GACZ,KAAK,MAAM,YAAY,IAAI,KAAK,GAAG,SAAS,IAAI;GAChD,IAAI,MAAM;GACV,KAAK,MAAM,UAAU,SAAS,OAAO,OAAO,UAAU;GACtD,QAAQ,MAAM;GACd,WAAW,MAAM;GACjB,IAAI,QAAQ,uBAAuB,KAAA,GACjC,MAAM,GAAG,SAAS,GAAG,oBAAoB;IAAE,WAAW;IAAM,OAAO;GAAK,CAAC;GAC3E,MAAM,QAAQ,IAAI,CAAC,SAAS,MAAM,GAAG,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,KAAK,aAAa,SAAS,MAAM,CAAC,CAAC,CAAC;GACjG,WAAW,MAAM;GACjB,OAAO,oBAAoB;GAC3B,MAAM,IAAI,SAAe,SAAS,WAChC,OAAO,OAAO,UAAW,UAAU,KAAA,IAAY,QAAQ,IAAI,OAAO,KAAK,CAAE,CAC3E;EACF;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/doompi-core",
3
- "version": "0.0.1-alpha.103",
3
+ "version": "0.0.1-alpha.104",
4
4
  "description": "Doompi runtime systems and reusable core services.",
5
5
  "keywords": [
6
6
  "ai",