cdk-local 0.81.1 → 0.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2 -2
- package/dist/internal.d.ts +26 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/{local-studio-DvNmnaF0.js → local-studio-8r3jr9nj.js} +282 -41
- package/dist/local-studio-8r3jr9nj.js.map +1 -0
- package/package.json +1 -1
- package/dist/local-studio-DvNmnaF0.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-studio-8r3jr9nj.js","names":["createServer","nodeSpawn","createServer","httpRequest","netConnect","nodeSpawn"],"sources":["../src/local/studio-events.ts","../src/local/studio-store.ts","../src/local/studio-ui.ts","../src/local/studio-server.ts","../src/local/studio-dispatch.ts","../src/local/studio-proxy.ts","../src/local/studio-serve-manager.ts","../src/cli/commands/local-studio.ts"],"sourcesContent":["import { EventEmitter } from 'node:events';\n\n/**\n * The kind of runnable target an invocation ran against. Mirrors the\n * categories `cdkl list` / the studio target list expose.\n */\nexport type StudioTargetKind = 'lambda' | 'api' | 'alb' | 'ecs' | 'agentcore';\n\n/**\n * One request observed by `cdkl studio` — a single-shot invoke or one\n * request to a served target. Emitted twice per request: once at start\n * (status/durationMs/response absent) and once at end (filled in). The\n * UI threads the two by {@link StudioInvocationEvent.id}.\n *\n * Slice A defines the shape; the dispatch layer that emits populated\n * events lands with the invoke / serve slices.\n */\nexport interface StudioInvocationEvent {\n /** Correlation id, unique per request. Stable across the start/end pair. */\n id: string;\n /** Wall-clock epoch ms when the request started. */\n ts: number;\n /** Target id the request ran against (stack-qualified or display path). */\n target: string;\n /** The target's kind, for the UI's per-kind affordances. */\n kind: StudioTargetKind;\n /** Short request label for the timeline row (e.g. `GET /orders`). */\n label: string;\n /** The request payload (Lambda event JSON or the HTTP request shape). */\n request?: unknown;\n /** Response payload, set on the end event. */\n response?: unknown;\n /** HTTP status / invoke outcome code, set on the end event. */\n status?: number;\n /** Wall-clock duration in ms, set on the end event. */\n durationMs?: number;\n /**\n * When this invocation is a re-run of an earlier one (Phase 3), the id\n * of the source invocation. The UI links the new row to its origin.\n */\n reinvokeOf?: string;\n}\n\n/**\n * One container stdout/stderr line, tagged with its emitting container\n * so the detail panel can scope logs at CloudWatch granularity (Lambda\n * per-invocation, ECS per-container).\n */\nexport interface StudioLogEvent {\n /** Wall-clock epoch ms when the line was observed. */\n ts: number;\n /** Container id that emitted the line. */\n containerId: string;\n /** Target id the container backs, for the UI grouping. */\n target: string;\n /** The raw log line (without trailing newline). */\n line: string;\n /** Parsed stream, when known. */\n stream?: 'stdout' | 'stderr';\n}\n\n/**\n * Lifecycle of a long-running served target (`api` / `alb` / `ecs`\n * service) the studio started. Unlike {@link StudioInvocationEvent}\n * (one per request), a serve emits one event per status TRANSITION:\n * `starting` when the child is spawned, `running` once it is listening\n * (with the served endpoints), `stopped` after a clean stop, `error`\n * when it failed to come up or crashed. The UI keys these by\n * {@link StudioServeEvent.target} to drive the per-target `running ●\n * :port [Stop]` affordance.\n */\nexport interface StudioServeEvent {\n /** Wall-clock epoch ms when the status was observed. */\n ts: number;\n /** Target id of the served target (stack-qualified or display path). */\n target: string;\n /** The served target's kind. */\n kind: StudioTargetKind;\n /** Lifecycle status this event reports. */\n status: 'starting' | 'running' | 'stopped' | 'error';\n /**\n * Served endpoint URLs, present on `running` (e.g.\n * `['http://127.0.0.1:51234']`). A single served target can expose\n * several (multiple APIs / WebSocket listeners), so this is a list.\n */\n endpoints?: string[];\n /** Child process id, present from `starting` onward. */\n pid?: number;\n /** Status / error detail (e.g. the failure reason on `error`). */\n message?: string;\n}\n\n/**\n * Map of event name -> listener argument, for the typed wrapper below.\n */\ninterface StudioEventMap {\n invocation: [StudioInvocationEvent];\n log: [StudioLogEvent];\n serve: [StudioServeEvent];\n}\n\n/**\n * In-process event bus that every studio observation flows through. The\n * studio HTTP server subscribes and forwards events to the browser over\n * SSE; the dispatch / log-streaming layers emit onto it.\n *\n * A thin typed wrapper over {@link EventEmitter} so producers and the\n * server agree on the event shapes without `any`. Re-exported from\n * `cdk-local/internal` so a host CLI embedding studio can subscribe.\n */\nexport class StudioEventBus {\n private readonly emitter = new EventEmitter();\n\n constructor() {\n // The bus can accumulate many SSE subscribers across a long session;\n // raise the cap so Node does not warn about a suspected leak.\n this.emitter.setMaxListeners(0);\n }\n\n emit<E extends keyof StudioEventMap>(event: E, ...args: StudioEventMap[E]): void {\n this.emitter.emit(event, ...args);\n }\n\n on<E extends keyof StudioEventMap>(\n event: E,\n listener: (...args: StudioEventMap[E]) => void\n ): this {\n this.emitter.on(event, listener as (...args: unknown[]) => void);\n return this;\n }\n\n off<E extends keyof StudioEventMap>(\n event: E,\n listener: (...args: StudioEventMap[E]) => void\n ): this {\n this.emitter.off(event, listener as (...args: unknown[]) => void);\n return this;\n }\n\n /**\n * Number of listeners currently subscribed to `event`. Exposed so the\n * SSE server's subscribe / unsubscribe symmetry can be asserted (a\n * dropped client must not leak a listener).\n */\n listenerCount<E extends keyof StudioEventMap>(event: E): number {\n return this.emitter.listenerCount(event);\n }\n}\n","import {\n StudioEventBus,\n type StudioInvocationEvent,\n type StudioLogEvent,\n} from './studio-events.js';\n\n/** Options for {@link createStudioStore}. */\nexport interface StudioStoreOptions {\n /** Max invocations retained (newest-wins eviction). Defaults to 200. */\n maxInvocations?: number;\n /** Max log lines retained (newest-wins eviction). Defaults to 5000. */\n maxLogs?: number;\n /**\n * Grace window (ms) added after an invocation's duration when binding\n * serve-request logs by time window — container lines often flush a beat\n * after the response. Defaults to 250.\n */\n bindGraceMs?: number;\n}\n\n/** A point-in-time snapshot of the retained events. */\nexport interface StudioHistory {\n /** Retained invocations, oldest first. */\n invocations: StudioInvocationEvent[];\n /** Retained log lines, oldest first. */\n logs: StudioLogEvent[];\n}\n\n/** Options for {@link StudioStore.searchLogs}. */\nexport interface StudioLogSearchOptions {\n /** Restrict to one target id. */\n target?: string;\n /** Max matches returned (newest first). Defaults to 200. */\n limit?: number;\n}\n\n/**\n * The in-memory event store behind `cdkl studio`. Subscribes to the event\n * bus and retains a bounded, newest-wins window of invocations + log\n * lines so the UI can render history on (re)connect, run a full-text log\n * search across the whole session, and bind a request's logs at\n * CloudWatch granularity (decision D5).\n */\nexport interface StudioStore {\n /** Snapshot of the retained invocations + logs (oldest first). */\n history: () => StudioHistory;\n /**\n * Full-text (case-insensitive substring) search over retained log\n * lines. Returns the newest matches first, capped by `opts.limit`.\n */\n searchLogs: (query: string, opts?: StudioLogSearchOptions) => StudioLogEvent[];\n /**\n * Logs bound to one invocation at CloudWatch granularity (decision D5):\n * a Lambda invocation binds STRICTLY by container id (the dispatcher\n * keys each line to the invocation); a captured serve request — whose\n * logs are keyed to the long-running serve, not the request — binds\n * best-effort by the request's `target` + time window.\n */\n logsForInvocation: (id: string) => StudioLogEvent[];\n /** The retained invocation with `id`, if still in the window. */\n invocation: (id: string) => StudioInvocationEvent | undefined;\n /** Stop subscribing to the bus (idempotent). */\n dispose: () => void;\n}\n\n/**\n * Build the studio store and subscribe it to `bus`. The store merges the\n * start/end pair of each invocation (keyed by id) and keeps a ring of log\n * lines; both windows evict oldest-first past their caps.\n */\nexport function createStudioStore(\n bus: StudioEventBus,\n options: StudioStoreOptions = {}\n): StudioStore {\n const maxInvocations = options.maxInvocations ?? 200;\n const maxLogs = options.maxLogs ?? 5000;\n const bindGraceMs = options.bindGraceMs ?? 250;\n\n // Insertion-ordered map: re-setting an existing id (the end event) keeps\n // its original position, so the start/end pair stays one entry.\n const invocations = new Map<string, StudioInvocationEvent>();\n const logs: StudioLogEvent[] = [];\n\n const onInvocation = (ev: StudioInvocationEvent): void => {\n invocations.set(ev.id, { ...invocations.get(ev.id), ...ev });\n if (invocations.size > maxInvocations) {\n // Evict the oldest (first-inserted) entry.\n const oldest = invocations.keys().next().value;\n if (oldest !== undefined) invocations.delete(oldest);\n }\n };\n\n const onLog = (ev: StudioLogEvent): void => {\n logs.push(ev);\n if (logs.length > maxLogs) logs.shift();\n };\n\n bus.on('invocation', onInvocation);\n bus.on('log', onLog);\n\n let disposed = false;\n\n return {\n history: (): StudioHistory => ({\n invocations: [...invocations.values()],\n logs: [...logs],\n }),\n\n searchLogs: (query, opts = {}): StudioLogEvent[] => {\n const needle = query.toLowerCase();\n const limit = opts.limit ?? 200;\n const matches: StudioLogEvent[] = [];\n // Walk newest-first so a tight limit keeps the most recent matches.\n for (let i = logs.length - 1; i >= 0 && matches.length < limit; i -= 1) {\n const log = logs[i];\n if (!log) continue;\n if (opts.target !== undefined && log.target !== opts.target) continue;\n if (needle === '' || log.line.toLowerCase().includes(needle)) matches.push(log);\n }\n return matches;\n },\n\n logsForInvocation: (id): StudioLogEvent[] => {\n const inv = invocations.get(id);\n if (!inv) return [];\n // Bind by KIND, not by \"did the strict filter match anything\". A\n // Lambda's lines are keyed to the invocation id, so bind STRICTLY by\n // container id — even when the invocation emitted none (an empty\n // result is correct; falling back to a time window would surface a\n // DIFFERENT invocation's logs of the same function).\n if (inv.kind === 'lambda') {\n return logs.filter((l) => l.containerId === id);\n }\n // A captured serve request's logs are keyed to the long-running serve\n // (not the request), so bind best-effort by target + the request's\n // time window (D5).\n const from = inv.ts;\n const to = inv.ts + (inv.durationMs ?? 0) + bindGraceMs;\n return logs.filter((l) => l.target === inv.target && l.ts >= from && l.ts <= to);\n },\n\n invocation: (id): StudioInvocationEvent | undefined => invocations.get(id),\n\n dispose: (): void => {\n if (disposed) return;\n disposed = true;\n bus.off('invocation', onInvocation);\n bus.off('log', onLog);\n },\n };\n}\n","/**\n * The studio web UI, embedded as a string so it ships inside the\n * `cdk-local` npm package (decision D9) with no asset-copy build step —\n * `tsdown` bundles this module like any other source file. Served by\n * the studio HTTP server (`startStudioServer`) at `GET /`.\n *\n * 3-pane shell (decision D6), framework-free vanilla JS (decision D7):\n * - left = target list (from `GET /api/targets`); each Lambda has an\n * [Invoke] button, each API a [Start] / [Stop] serve control with a\n * `running ● :port` indicator (slice C1), plus a selected-highlight.\n * - center = the WORKSPACE for the selected target: for a Lambda, an\n * event composer (textarea + Invoke button) with the latest run's\n * Request / Response / Logs shown below; for an API, a Start/Stop\n * control with the served endpoints + streaming logs.\n * - right = the timeline (history) of every invocation AND every\n * captured serve request (slice C2); clicking a Lambda row reloads\n * it into the composer, clicking a captured request row opens a\n * read-only Request / Response detail.\n *\n * The center workspace is deliberately adjacent to the left target list\n * (short eye-travel: pick a target -> compose right next to it), and is\n * the primary surface — the timeline is secondary history.\n */\n\nconst STUDIO_CSS = `\n * { box-sizing: border-box; }\n body {\n margin: 0; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;\n color: #e6e6e6; background: #1a1a1a; height: 100vh; overflow: hidden;\n }\n header {\n padding: 8px 14px; background: #111; border-bottom: 1px solid #333;\n display: flex; align-items: center; gap: 10px;\n }\n header .brand { font-weight: 700; color: #fff; }\n header .meta { color: #888; font-size: 12px; }\n main {\n display: grid; grid-template-columns: 280px 5px 1fr 5px 320px;\n height: calc(100vh - 38px);\n }\n .pane { overflow: auto; }\n .splitter { background: #2a2a2a; cursor: col-resize; }\n .splitter:hover, .splitter.dragging { background: #4ec97a; }\n .pane h2 {\n margin: 0; padding: 8px 12px; font-size: 11px; text-transform: uppercase;\n letter-spacing: 0.5px; color: #888; background: #151515;\n position: sticky; top: 0; border-bottom: 1px solid #2a2a2a; z-index: 1;\n }\n .group-title { padding: 8px 12px 2px; color: #6aa9ff; font-size: 11px; }\n .target {\n padding: 6px 12px; border-bottom: 1px solid #222; display: flex;\n align-items: center; gap: 8px;\n }\n .target.runnable { cursor: pointer; }\n .target.runnable:hover { background: #202020; }\n .target.sel { background: #2a3550; }\n .target .name { color: #ddd; flex: 1; overflow: hidden; text-overflow: ellipsis; }\n .target .kind { color: #777; font-size: 11px; }\n .target .invoke-btn {\n padding: 2px 10px; font: 11px ui-monospace, Menlo, monospace; font-weight: 700;\n color: #0d1f12; background: #4ec97a; border: 0; border-radius: 3px; cursor: pointer;\n }\n .target .invoke-btn:hover { background: #6fe097; }\n .target.sel .invoke-btn { background: #6fe097; }\n .target .stop-btn {\n padding: 2px 10px; font: 11px ui-monospace, Menlo, monospace; font-weight: 700;\n color: #2a0d0d; background: #e0707a; border: 0; border-radius: 3px; cursor: pointer;\n }\n .target .stop-btn:hover { background: #ec8a92; }\n .target .run-dot { color: #7bd88f; font-size: 11px; white-space: nowrap; }\n .target .run-dot.starting { color: #e0b54e; }\n .empty { padding: 16px 12px; color: #666; }\n .row {\n padding: 5px 12px; border-bottom: 1px solid #222; cursor: pointer;\n display: flex; gap: 8px; white-space: nowrap;\n }\n .row:hover { background: #222; }\n .row.sel { background: #2a3550; }\n .row .ts { color: #777; }\n .row .label { color: #ddd; flex: 1; overflow: hidden; text-overflow: ellipsis; }\n .row .status { color: #7bd88f; }\n .row .status.err { color: #e0707a; }\n #workspace { padding: 0 0 24px; }\n .composer { padding: 10px 12px; border-bottom: 1px solid #2a2a2a; }\n .composer .target-name { color: #fff; font-weight: 700; margin-bottom: 6px; }\n .composer textarea {\n width: 100%; min-height: 130px; resize: vertical; background: #111; color: #ddd;\n border: 1px solid #333; border-radius: 3px; padding: 6px;\n font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;\n }\n .composer button {\n margin-top: 8px; padding: 6px 18px; background: #2a7d46; color: #fff;\n border: 0; border-radius: 3px; cursor: pointer; font: inherit; font-weight: 700;\n }\n .composer button:hover { background: #339152; }\n .composer button:disabled { background: #333; color: #888; cursor: default; }\n .composer .err { color: #e0707a; margin-top: 6px; min-height: 18px; }\n .section { padding: 8px 12px; border-bottom: 1px solid #222; }\n .section h3 { margin: 0 0 6px; font-size: 11px; color: #888; text-transform: uppercase; }\n .section h3 .ok { color: #7bd88f; }\n .section h3 .bad { color: #e0707a; }\n .section pre { margin: 0; white-space: pre-wrap; word-break: break-word; color: #cfcfcf; }\n .endpoint { display: block; color: #6aa9ff; text-decoration: none; padding: 2px 0; }\n .endpoint:hover { text-decoration: underline; }\n .searchbar { padding: 6px 10px; border-bottom: 1px solid #2a2a2a; background: #151515;\n position: sticky; top: 28px; z-index: 1; }\n .searchbar input {\n width: 100%; background: #111; color: #ddd; border: 1px solid #333; border-radius: 3px;\n padding: 5px 8px; font: 12px ui-monospace, Menlo, monospace;\n }\n .searchbar input:focus { outline: none; border-color: #4ec97a; }\n #log-results { display: none; }\n #log-results.active { display: block; }\n .log-hit { padding: 4px 12px; border-bottom: 1px solid #222; white-space: pre-wrap;\n word-break: break-word; }\n .log-hit .lt { color: #777; }\n .log-hit .lg { color: #6aa9ff; }\n .log-hits-meta { padding: 6px 12px; color: #888; font-size: 11px; }\n #conn { font-size: 11px; }\n #conn.up { color: #7bd88f; }\n #conn.down { color: #e0707a; }\n`;\n\nconst STUDIO_SCRIPT = `\n const KIND_LABEL = { lambda: 'Lambda', api: 'API', alb: 'ALB', ecs: 'ECS', agentcore: 'AgentCore' };\n const SERVE_KINDS = ['api', 'alb', 'ecs']; // long-running serve targets\n const rowsById = new Map(); // invocationId -> timeline row element\n const invById = new Map(); // invocationId -> latest invocation event\n const logsById = new Map(); // invocationId / serve targetId -> [log lines]\n const targetEls = new Map(); // targetId -> left-pane element\n const serveMeta = new Map(); // serve targetId -> { dot, btnSlot } row controls\n const serveState = new Map(); // serve targetId -> { status, endpoints }\n let active = null; // { id, kind, ta, btn, msg, result }\n let shownInvId = null; // lambda invocation whose result is in the workspace\n let shownServeId = null; // serve target whose workspace is shown\n let shownDetailId = null; // captured request whose read-only detail is shown\n\n function el(tag, cls, text) {\n const e = document.createElement(tag);\n if (cls) e.className = cls;\n if (text != null) e.textContent = text;\n return e;\n }\n\n async function loadTargets() {\n const pane = document.getElementById('targets');\n try {\n const res = await fetch('/api/targets');\n const data = await res.json();\n pane.querySelectorAll('.group-title,.target,.empty').forEach((n) => n.remove());\n let total = 0;\n for (const group of data.groups) {\n if (!group.entries.length) continue;\n pane.appendChild(el('div', 'group-title', group.title));\n for (const entry of group.entries) {\n total += 1;\n // Lambda targets are single-shot invokes; api / alb / ecs are\n // long-running serves. Other kinds list but are not yet runnable.\n // Within ecs, only services are servable (task defs are run-task).\n const isServe = SERVE_KINDS.includes(group.kind) && (group.kind !== 'ecs' || entry.servable === true);\n const runnable = group.kind === 'lambda' || isServe;\n const t = el('div', runnable ? 'target runnable' : 'target');\n const name = el('span', 'name', entry.id);\n name.title = entry.id; // full path on hover even when truncated\n t.appendChild(name);\n t.appendChild(el('span', 'kind', '(' + (KIND_LABEL[group.kind] || group.kind) + ')'));\n if (group.kind === 'lambda') {\n const btn = el('button', 'invoke-btn', 'Invoke');\n btn.onclick = (e) => { e.stopPropagation(); selectTarget(entry.id, 'lambda'); };\n t.appendChild(btn);\n t.onclick = () => selectTarget(entry.id, 'lambda');\n targetEls.set(entry.id, t);\n } else if (isServe) {\n // A serve target: a running-state dot + a Start/Stop button\n // slot, both refreshed by updateServeRow on serve events.\n const dot = el('span', 'run-dot');\n const btnSlot = el('span', 'btn-slot');\n t.appendChild(dot);\n t.appendChild(btnSlot);\n t.onclick = () => selectTarget(entry.id, group.kind);\n targetEls.set(entry.id, t);\n serveMeta.set(entry.id, { dot, btnSlot, kind: group.kind });\n updateServeRow(entry.id);\n }\n pane.appendChild(t);\n }\n }\n if (!total) pane.appendChild(el('div', 'empty', 'No runnable targets found.'));\n } catch (err) {\n pane.appendChild(el('div', 'empty', 'Failed to load targets: ' + err));\n }\n }\n\n // Pull any already-running serves (e.g. after a UI reload) so the rows\n // and workspace reflect them without waiting for a fresh serve event.\n async function loadRunning() {\n try {\n const res = await fetch('/api/running');\n const data = await res.json();\n for (const s of (data.running || [])) {\n serveState.set(s.targetId, { status: s.status, endpoints: s.endpoints || [] });\n updateServeRow(s.targetId);\n }\n } catch (err) {\n /* best-effort; the serve SSE stream still drives live updates */\n }\n }\n\n function firstPort(endpoints) {\n const u = (endpoints || [])[0];\n if (!u) return '';\n const m = /:(\\\\d+)/.exec(u);\n return m ? ':' + m[1] : '';\n }\n\n function updateServeRow(id) {\n const meta = serveMeta.get(id);\n if (!meta) return;\n const st = serveState.get(id);\n const status = st ? st.status : 'stopped';\n const running = status === 'running';\n const starting = status === 'starting';\n // A serve with a host endpoint shows the dot + :port; a pure-compute\n // ecs service has no endpoint, so just the dot + running.\n const port = running ? firstPort(st.endpoints) : '';\n meta.dot.textContent = running ? (port ? '● ' + port : '● running') : starting ? '○ starting' : '';\n meta.dot.className = 'run-dot' + (starting ? ' starting' : '');\n meta.btnSlot.innerHTML = '';\n const btn = running || starting\n ? el('button', 'stop-btn', 'Stop')\n : el('button', 'invoke-btn', 'Start');\n btn.onclick = (e) => {\n e.stopPropagation();\n if (running || starting) stopServe(id); else startServe(id);\n };\n meta.btnSlot.appendChild(btn);\n // Refresh the workspace if it is showing this serve.\n if (shownServeId === id) renderServeWorkspace(id);\n }\n\n function highlightTarget(id) {\n document.querySelectorAll('.target.sel').forEach((n) => n.classList.remove('sel'));\n const t = targetEls.get(id);\n if (t) t.classList.add('sel');\n }\n\n function selectTarget(id, kind) {\n highlightTarget(id);\n shownDetailId = null;\n if (SERVE_KINDS.includes(kind)) {\n shownServeId = id;\n shownInvId = null;\n active = null;\n renderServeWorkspace(id);\n } else {\n shownServeId = null;\n renderComposer(id, kind, '{}');\n }\n }\n\n async function startServe(id) {\n // The serve kind (api / alb / ecs) drives which headless command the\n // server spawns; it is recorded on the row when the target list loads.\n const meta = serveMeta.get(id);\n const kind = meta ? meta.kind : 'api';\n serveState.set(id, { status: 'starting', endpoints: [] });\n updateServeRow(id);\n try {\n const res = await fetch('/api/run', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ targetId: id, kind }),\n });\n const data = await res.json();\n if (!res.ok) {\n // Roll back the optimistic 'starting' on a rejected start.\n serveState.set(id, { status: 'error', endpoints: [] });\n updateServeRow(id);\n if (shownServeId === id) renderServeWorkspace(id, data.error || ('HTTP ' + res.status));\n }\n // On success the serve SSE 'running' event fills in the endpoints.\n } catch (err) {\n serveState.set(id, { status: 'error', endpoints: [] });\n updateServeRow(id);\n if (shownServeId === id) renderServeWorkspace(id, String(err));\n }\n }\n\n async function stopServe(id) {\n try {\n await fetch('/api/stop', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ targetId: id }),\n });\n // The serve SSE 'stopped' event clears the running state.\n } catch (err) {\n /* the stop SSE event (or a later refresh) reconciles state */\n }\n }\n\n function renderServeWorkspace(id, errMsg) {\n const ws = document.getElementById('workspace');\n ws.innerHTML = '';\n const st = serveState.get(id) || { status: 'stopped', endpoints: [] };\n const running = st.status === 'running';\n const starting = st.status === 'starting';\n\n const head = el('div', 'composer');\n head.appendChild(el('div', 'target-name', 'Serve ' + id));\n const btn = running || starting\n ? el('button', null, 'Stop')\n : el('button', null, starting ? 'Starting…' : 'Start');\n btn.onclick = () => { if (running || starting) stopServe(id); else startServe(id); };\n head.appendChild(btn);\n if (errMsg) {\n const m = el('div', 'err', errMsg);\n head.appendChild(m);\n }\n ws.appendChild(head);\n\n const meta = serveMeta.get(id);\n const isEcs = meta && meta.kind === 'ecs';\n const epSec = el('div', 'section');\n epSec.appendChild(el('h3', null, 'Endpoints'));\n if (running && st.endpoints.length) {\n for (const url of st.endpoints) {\n const link = href(url);\n epSec.appendChild(link);\n }\n } else if (running && isEcs) {\n // A pure-compute ECS service has no host endpoint — it just runs the\n // replicas (reach them container-to-container via Cloud Map).\n epSec.appendChild(el('pre', null, '(running — pure compute service, no host endpoint)'));\n } else {\n epSec.appendChild(el('pre', null, starting ? '(starting…)' : '(not running)'));\n }\n ws.appendChild(epSec);\n\n const logs = logsById.get(id) || [];\n const logSec = el('div', 'section');\n logSec.appendChild(el('h3', null, 'Logs'));\n logSec.appendChild(el('pre', null, logs.length ? logs.join('\\\\n') : '(none)'));\n ws.appendChild(logSec);\n }\n\n // Build an <a> that opens an http(s) endpoint in a new tab; ws:// URLs\n // are shown as plain text (not navigable in a browser tab).\n function href(url) {\n if (/^https?:/.test(url)) {\n const a = el('a', 'endpoint', url);\n a.href = url;\n a.target = '_blank';\n a.rel = 'noopener';\n return a;\n }\n return el('div', 'endpoint', url);\n }\n\n function renderComposer(id, kind, eventText) {\n const ws = document.getElementById('workspace');\n ws.innerHTML = '';\n\n const composer = el('div', 'composer');\n composer.appendChild(el('div', 'target-name', 'Invoke ' + id));\n const ta = el('textarea');\n ta.value = eventText;\n ta.spellcheck = false;\n composer.appendChild(ta);\n composer.appendChild(document.createElement('br'));\n const btn = el('button', null, 'Invoke');\n const msg = el('div', 'err');\n composer.appendChild(btn);\n composer.appendChild(msg);\n\n const result = el('div', 'result');\n\n ws.appendChild(composer);\n ws.appendChild(result);\n\n active = { id, kind, ta, btn, msg, result };\n btn.onclick = () => runInvoke();\n shownInvId = null;\n shownDetailId = null;\n ta.focus();\n }\n\n async function runInvoke() {\n if (!active) return;\n const { id, kind, ta, btn, msg, result } = active;\n let event;\n try {\n event = ta.value.trim() === '' ? {} : JSON.parse(ta.value);\n } catch (err) {\n msg.textContent = 'Invalid JSON: ' + err.message;\n return;\n }\n msg.textContent = '';\n btn.disabled = true;\n btn.textContent = 'Invoking...';\n result.innerHTML = '';\n try {\n const res = await fetch('/api/run', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ targetId: id, kind, event }),\n });\n const data = await res.json();\n if (data.invocationId) {\n shownInvId = data.invocationId;\n renderResult(shownInvId);\n }\n if (!res.ok || data.ok === false) {\n msg.textContent = 'Invoke failed: ' + (data.error || ('HTTP ' + res.status));\n }\n } catch (err) {\n msg.textContent = 'Request failed: ' + err;\n } finally {\n btn.disabled = false;\n btn.textContent = 'Invoke';\n }\n }\n\n function fmt(body) {\n return typeof body === 'string' ? body : JSON.stringify(body, null, 2);\n }\n\n function renderResult(invId) {\n if (!active) return;\n const result = active.result;\n result.innerHTML = '';\n const ev = invById.get(invId);\n if (!ev) return;\n\n const reqSec = el('div', 'section');\n reqSec.appendChild(el('h3', null, 'Request'));\n reqSec.appendChild(el('pre', null, ev.request != null ? fmt(ev.request) : '(none)'));\n result.appendChild(reqSec);\n\n const respSec = el('div', 'section');\n const h = el('h3', null, 'Response');\n if (ev.status != null) {\n const cls = ev.status >= 200 && ev.status < 300 ? 'ok' : 'bad';\n const meta = el('span', cls, ' ' + ev.status + (ev.durationMs != null ? ' · ' + ev.durationMs + 'ms' : ''));\n h.appendChild(meta);\n }\n respSec.appendChild(h);\n respSec.appendChild(el('pre', null, ev.response != null ? fmt(ev.response) : '(pending…)'));\n result.appendChild(respSec);\n\n const logs = logsById.get(invId) || [];\n const logSec = el('div', 'section');\n logSec.appendChild(el('h3', null, 'Logs'));\n logSec.appendChild(el('pre', null, logs.length ? logs.join('\\\\n') : '(none)'));\n result.appendChild(logSec);\n }\n\n function addInvocation(ev) {\n invById.set(ev.id, Object.assign(invById.get(ev.id) || {}, ev));\n const timeline = document.getElementById('timeline-rows');\n const placeholder = timeline.querySelector('.empty');\n if (placeholder) placeholder.remove();\n\n let row = rowsById.get(ev.id);\n if (!row) {\n row = el('div', 'row');\n row.appendChild(el('span', 'ts'));\n row.appendChild(el('span', 'label'));\n row.appendChild(el('span', 'status'));\n row.onclick = () => loadInvocation(ev.id);\n rowsById.set(ev.id, row);\n timeline.insertBefore(row, timeline.querySelector('.row')); // newest on top\n }\n const merged = invById.get(ev.id);\n const d = new Date(merged.ts);\n row.querySelector('.ts').textContent = d.toLocaleTimeString();\n row.querySelector('.label').textContent = (merged.target || '') + ' ' + (merged.label || '');\n const statusEl = row.querySelector('.status');\n statusEl.textContent =\n merged.status != null\n ? merged.status + (merged.durationMs != null ? ' ' + merged.durationMs + 'ms' : '')\n : '…';\n statusEl.className = 'status' + (merged.status != null && (merged.status < 200 || merged.status >= 300) ? ' err' : '');\n\n // Live-refresh the workspace if it is showing this invocation.\n if (shownInvId === ev.id) renderResult(ev.id);\n if (shownDetailId === ev.id) renderCapturedDetail(ev.id);\n }\n\n function loadInvocation(id) {\n const ev = invById.get(id);\n if (!ev) return;\n document.querySelectorAll('.row.sel').forEach((n) => n.classList.remove('sel'));\n const row = rowsById.get(id);\n if (row) row.classList.add('sel');\n highlightTarget(ev.target);\n if (ev.kind === 'lambda') {\n // A Lambda invocation row reloads into the re-invokable composer.\n shownDetailId = null;\n shownServeId = null;\n renderComposer(ev.target, ev.kind, ev.request != null ? fmt(ev.request) : '{}');\n shownInvId = id;\n renderResult(id);\n } else {\n // A captured serve request (slice C2) opens a READ-ONLY detail —\n // re-invoking a captured request is Phase 3.\n shownInvId = null;\n shownServeId = null;\n active = null;\n renderCapturedDetail(id);\n }\n }\n\n // Read-only Request / Response detail for a captured serve request.\n function renderCapturedDetail(id) {\n shownDetailId = id;\n const ev = invById.get(id);\n const ws = document.getElementById('workspace');\n ws.innerHTML = '';\n if (!ev) return;\n\n const head = el('div', 'composer');\n head.appendChild(el('div', 'target-name', (ev.label || 'request') + ' — ' + (ev.target || '')));\n ws.appendChild(head);\n\n const reqSec = el('div', 'section');\n reqSec.appendChild(el('h3', null, 'Request'));\n reqSec.appendChild(el('pre', null, ev.request != null ? fmt(ev.request) : '(none)'));\n ws.appendChild(reqSec);\n\n const respSec = el('div', 'section');\n const h = el('h3', null, 'Response');\n if (ev.status != null) {\n const cls = ev.status >= 200 && ev.status < 300 ? 'ok' : 'bad';\n h.appendChild(el('span', cls, ' ' + ev.status + (ev.durationMs != null ? ' · ' + ev.durationMs + 'ms' : '')));\n }\n respSec.appendChild(h);\n respSec.appendChild(el('pre', null, ev.response != null ? fmt(ev.response) : '(pending…)'));\n ws.appendChild(respSec);\n\n // Logs bound to THIS request at CloudWatch granularity (D5), fetched\n // from the server store.\n const logSec = el('div', 'section');\n logSec.appendChild(el('h3', null, 'Logs'));\n const logPre = el('pre', null, '(loading…)');\n logSec.appendChild(logPre);\n ws.appendChild(logSec);\n fetchInvocationLogs(id, logPre);\n }\n\n async function fetchInvocationLogs(id, pre) {\n try {\n const res = await fetch('/api/invocations/' + encodeURIComponent(id) + '/logs');\n const data = await res.json();\n const lines = (data.logs || []).map((l) => l.line);\n if (shownDetailId === id) pre.textContent = lines.length ? lines.join('\\\\n') : '(none)';\n } catch (err) {\n if (shownDetailId === id) pre.textContent = '(failed to load logs)';\n }\n }\n\n // Full-text log search over the server store. A non-empty query shows\n // matching log lines INSTEAD of the timeline rows; clearing restores them.\n let searchTimer = null;\n function wireLogSearch() {\n const input = document.getElementById('log-search');\n const rows = document.getElementById('timeline-rows');\n const results = document.getElementById('log-results');\n input.addEventListener('input', () => {\n if (searchTimer) clearTimeout(searchTimer);\n searchTimer = setTimeout(() => runLogSearch(input.value.trim(), rows, results), 180);\n });\n }\n\n async function runLogSearch(query, rows, results) {\n if (query === '') {\n results.classList.remove('active');\n rows.style.display = '';\n results.innerHTML = '';\n return;\n }\n rows.style.display = 'none';\n results.classList.add('active');\n try {\n const res = await fetch('/api/logs?q=' + encodeURIComponent(query));\n const data = await res.json();\n const hits = data.logs || [];\n results.innerHTML = '';\n results.appendChild(el('div', 'log-hits-meta', hits.length + ' match' + (hits.length === 1 ? '' : 'es')));\n for (const h of hits) {\n const row = el('div', 'log-hit');\n row.appendChild(el('span', 'lt', new Date(h.ts).toLocaleTimeString() + ' '));\n row.appendChild(el('span', 'lg', (h.target || '') + ' '));\n row.appendChild(document.createTextNode(h.line));\n results.appendChild(row);\n }\n } catch (err) {\n results.innerHTML = '';\n results.appendChild(el('div', 'log-hits-meta', 'Search failed: ' + err));\n }\n }\n\n // Pull retained history on (re)connect so the timeline + logs reflect the\n // whole session, not just events since this page loaded.\n async function loadHistory() {\n try {\n const res = await fetch('/api/history');\n const data = await res.json();\n for (const log of (data.logs || [])) {\n const arr = logsById.get(log.containerId) || [];\n arr.push(log.line);\n logsById.set(log.containerId, arr);\n }\n for (const inv of (data.invocations || [])) addInvocation(inv);\n } catch (err) {\n /* live SSE still drives the timeline; history is best-effort */\n }\n }\n\n function connect() {\n const conn = document.getElementById('conn');\n const es = new EventSource('/api/events');\n es.addEventListener('open', () => { conn.textContent = '● live'; conn.className = 'up'; });\n es.addEventListener('error', () => { conn.textContent = '● disconnected'; conn.className = 'down'; });\n es.addEventListener('invocation', (e) => addInvocation(JSON.parse(e.data)));\n es.addEventListener('serve', (e) => onServeEvent(JSON.parse(e.data)));\n es.addEventListener('log', (e) => {\n const ev = JSON.parse(e.data);\n const arr = logsById.get(ev.containerId) || [];\n arr.push(ev.line);\n logsById.set(ev.containerId, arr);\n if (shownInvId === ev.containerId) renderResult(ev.containerId);\n if (shownServeId === ev.containerId) renderServeWorkspace(ev.containerId);\n });\n }\n\n function onServeEvent(ev) {\n // A 'stopped' / 'error' transition clears the running state; otherwise\n // record the latest status + endpoints for the row + workspace.\n if (ev.status === 'stopped' || ev.status === 'error') {\n serveState.set(ev.target, { status: ev.status, endpoints: [] });\n } else {\n serveState.set(ev.target, { status: ev.status, endpoints: ev.endpoints || [] });\n }\n updateServeRow(ev.target);\n }\n\n function initSplitters() {\n const main = document.querySelector('main');\n let left = 280, right = 320;\n const apply = () => {\n main.style.gridTemplateColumns = left + 'px 5px 1fr 5px ' + right + 'px';\n };\n const wire = (splitterId, onMove) => {\n const s = document.getElementById(splitterId);\n s.addEventListener('mousedown', (e) => {\n e.preventDefault();\n const startX = e.clientX;\n const l0 = left, r0 = right;\n s.classList.add('dragging');\n document.body.style.userSelect = 'none';\n const move = (ev) => { onMove(ev.clientX - startX, l0, r0); apply(); };\n const up = () => {\n s.classList.remove('dragging');\n document.body.style.userSelect = '';\n document.removeEventListener('mousemove', move);\n document.removeEventListener('mouseup', up);\n };\n document.addEventListener('mousemove', move);\n document.addEventListener('mouseup', up);\n });\n };\n const clamp = (v) => Math.max(160, Math.min(760, v));\n wire('split-left', (dx, l0) => { left = clamp(l0 + dx); });\n wire('split-right', (dx, l0, r0) => { right = clamp(r0 - dx); });\n }\n\n loadTargets().then(loadRunning);\n loadHistory();\n connect();\n initSplitters();\n wireLogSearch();\n`;\n\n/**\n * Render the full studio HTML document. `appLabel` is shown in the\n * header (the CDK app / stack context); `cliName` brands the title for\n * host CLIs that rebrand `cdkl`.\n */\nexport function renderStudioHtml(appLabel: string, cliName: string): string {\n const safeApp = escapeHtml(appLabel);\n const safeCli = escapeHtml(cliName);\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>${safeCli} studio</title>\n<style>${STUDIO_CSS}</style>\n</head>\n<body>\n<header>\n <span class=\"brand\">${safeCli} studio</span>\n <span class=\"meta\">${safeApp}</span>\n <span id=\"conn\" class=\"down\">● connecting</span>\n</header>\n<main>\n <section class=\"pane\" id=\"targets\"><h2>Targets</h2></section>\n <div class=\"splitter\" id=\"split-left\"></div>\n <section class=\"pane\" id=\"workspace\"><div class=\"empty\">Pick a Lambda to invoke, or an API to serve, on the left.</div></section>\n <div class=\"splitter\" id=\"split-right\"></div>\n <section class=\"pane\" id=\"timeline\">\n <h2>Timeline</h2>\n <div class=\"searchbar\"><input id=\"log-search\" type=\"search\" placeholder=\"Search logs…\" autocomplete=\"off\" spellcheck=\"false\" /></div>\n <div id=\"timeline-rows\"><div class=\"empty\">No requests yet.</div></div>\n <div id=\"log-results\"></div>\n </section>\n</main>\n<script>${STUDIO_SCRIPT}</script>\n</body>\n</html>`;\n}\n\n/** Minimal HTML-escape for the few interpolated text values. */\nfunction escapeHtml(s: string): string {\n return s\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n","import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport {\n StudioEventBus,\n type StudioInvocationEvent,\n type StudioLogEvent,\n type StudioServeEvent,\n} from './studio-events.js';\nimport { renderStudioHtml } from './studio-ui.js';\nimport type { StudioStore } from './studio-store.js';\nimport type { TargetListing } from './target-lister.js';\n\n/** One target as the studio UI consumes it (`GET /api/targets`). */\nexport interface StudioTarget {\n /** Stable target id — the display path when available, else qualified id. */\n id: string;\n /** Stack-qualified `<Stack>:<LogicalId>` for disambiguation. */\n qualifiedId: string;\n /** API surface kind (REST v1 / HTTP v2 / ...), only for `api` entries. */\n surface?: string;\n /**\n * Within a kind whose entries are not uniformly runnable, marks the ones\n * that are. Used for the `ecs` group, which folds servable ECS *services*\n * (`start-service`) together with ECS *task definitions* (run-task, not a\n * serve target): only services carry `servable: true`.\n */\n servable?: boolean;\n}\n\n/** A category of targets, grouped by the studio kind that runs them. */\nexport interface StudioTargetGroup {\n /** Studio kind discriminator shared with {@link StudioInvocationEvent}. */\n kind: 'lambda' | 'api' | 'alb' | 'ecs' | 'agentcore';\n /** Human-readable group heading. */\n title: string;\n entries: StudioTarget[];\n}\n\n/**\n * Project a {@link TargetListing} (the same enumeration `cdkl list`\n * prints) into the grouped shape the studio UI renders. ECS services and\n * task definitions are folded into one `ecs` group; everything else maps\n * one category to one group. Exported so a unit test can assert the\n * projection without booting the server.\n */\nexport function toStudioTargetGroups(listing: TargetListing): StudioTargetGroup[] {\n const map = (\n entries: TargetListing['lambdas'],\n opts: { servable?: boolean } = {}\n ): StudioTarget[] =>\n entries.map((e) => {\n const t: StudioTarget = { id: e.displayPath ?? e.qualifiedId, qualifiedId: e.qualifiedId };\n if (e.kind) t.surface = e.kind;\n if (opts.servable !== undefined) t.servable = opts.servable;\n return t;\n });\n return [\n { kind: 'lambda', title: 'Lambda Functions', entries: map(listing.lambdas) },\n { kind: 'api', title: 'APIs', entries: map(listing.apis) },\n {\n kind: 'ecs',\n title: 'ECS Services / Tasks',\n // ECS services are servable (`start-service`); task definitions are\n // run-task (single-shot), not a serve target.\n entries: [\n ...map(listing.ecsServices, { servable: true }),\n ...map(listing.ecsTaskDefinitions, { servable: false }),\n ],\n },\n { kind: 'agentcore', title: 'AgentCore Runtimes', entries: map(listing.agentCoreRuntimes) },\n { kind: 'alb', title: 'Load Balancers', entries: map(listing.loadBalancers) },\n ];\n}\n\n/** Inputs to {@link startStudioServer}. */\nexport interface StudioServerOptions {\n /** Preferred listen port; bumps on collision (decision: collision-safe). */\n port: number;\n /** Listen host. Defaults to `127.0.0.1` (localhost-only). */\n host?: string;\n /** The shared event bus the SSE stream forwards. */\n bus: StudioEventBus;\n /** Target groups to serve at `GET /api/targets`. */\n targetGroups: StudioTargetGroup[];\n /** Header label for the running app / stack context. */\n appLabel: string;\n /** CLI brand name (`cdkl`, or a host rebrand). */\n cliName: string;\n /**\n * Max consecutive ports to try on `EADDRINUSE` before giving up.\n * Defaults to 20.\n */\n maxPortBump?: number;\n /**\n * Handler for `POST /api/run` — runs a target (single-shot Lambda\n * invoke, or start a long-running serve target) and returns the\n * result. When omitted, `/api/run` answers 501 (the observe-only\n * shell). The body is the parsed JSON request; the handler emits its\n * own invocation / serve / log events onto the bus, so the UI's\n * timeline + running state update over SSE independently of the\n * response.\n */\n onRun?: (body: unknown) => Promise<unknown>;\n /**\n * Handler for `POST /api/stop` — stop a running serve target. When\n * omitted, `/api/stop` answers 501. The body identifies the target.\n */\n onStop?: (body: unknown) => Promise<unknown>;\n /**\n * Snapshot of the currently-running serve targets, served at\n * `GET /api/running`. When omitted, the endpoint returns an empty\n * list (the observe-only shell never runs anything).\n */\n getRunning?: () => unknown;\n /**\n * In-memory event/log store (slice C3) backing the history + log-search\n * + per-request-log endpoints (`GET /api/history`, `GET /api/logs`,\n * `GET /api/invocations/<id>/logs`). When omitted those endpoints return\n * empty results.\n */\n store?: StudioStore;\n}\n\n/** A running studio server. */\nexport interface RunningStudioServer {\n /** The URL the UI is served at, e.g. `http://127.0.0.1:9999`. */\n url: string;\n /** The actually-bound port (may differ from the requested one). */\n port: number;\n /** Stop the server and release the port. */\n close: () => Promise<void>;\n}\n\nconst SSE_HEARTBEAT_MS = 15_000;\n\n/**\n * Boot the studio HTTP server: serves the embedded UI at `/`, the target\n * list at `/api/targets`, and a Server-Sent-Events stream of the bus's\n * `invocation` / `log` events at `/api/events`. Localhost-only by\n * default. Resolves once the socket is listening.\n */\nexport async function startStudioServer(\n options: StudioServerOptions\n): Promise<RunningStudioServer> {\n const host = options.host ?? '127.0.0.1';\n const maxBump = options.maxPortBump ?? 20;\n const html = renderStudioHtml(options.appLabel, options.cliName);\n const targetsJson = JSON.stringify({ groups: options.targetGroups });\n\n const server = createServer((req, res) =>\n handleRequest(req, res, options.bus, html, targetsJson, options)\n );\n\n const boundPort = await listenWithBump(server, host, options.port, maxBump);\n\n return {\n url: `http://${host}:${boundPort}`,\n port: boundPort,\n close: () =>\n new Promise<void>((resolveClose, reject) => {\n server.close((err) => (err ? reject(err) : resolveClose()));\n // closeAllConnections exists on Node 18.2+; SSE keeps sockets open\n // so without this `close()` would hang on live EventSource clients.\n server.closeAllConnections?.();\n }),\n };\n}\n\nfunction handleRequest(\n req: IncomingMessage,\n res: ServerResponse,\n bus: StudioEventBus,\n html: string,\n targetsJson: string,\n options: StudioServerOptions\n): void {\n const url = req.url ?? '/';\n const path = url.split('?')[0];\n\n if (req.method === 'GET' && (path === '/' || path === '/index.html')) {\n res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });\n res.end(html);\n return;\n }\n if (req.method === 'GET' && path === '/api/targets') {\n res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });\n res.end(targetsJson);\n return;\n }\n if (req.method === 'GET' && path === '/api/running') {\n const running = options.getRunning ? options.getRunning() : { running: [] };\n res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });\n res.end(JSON.stringify(running));\n return;\n }\n if (req.method === 'GET' && path === '/api/history') {\n const history = options.store ? options.store.history() : { invocations: [], logs: [] };\n res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });\n res.end(JSON.stringify(history));\n return;\n }\n if (req.method === 'GET' && path === '/api/logs') {\n const params = new URLSearchParams(url.split('?')[1] ?? '');\n const query = params.get('q') ?? '';\n // `|| undefined`: a bare `target=` (empty) means \"no filter\", not\n // \"logs whose target is the empty string\".\n const target = params.get('target') || undefined;\n const logs = options.store\n ? options.store.searchLogs(query, target !== undefined ? { target } : {})\n : [];\n res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });\n res.end(JSON.stringify({ logs }));\n return;\n }\n // `GET /api/invocations/<id>/logs` — the request's logs at CloudWatch\n // granularity (decision D5).\n const invLogsMatch = /^\\/api\\/invocations\\/([^/]+)\\/logs$/.exec(path ?? '');\n if (req.method === 'GET' && invLogsMatch) {\n const id = decodeURIComponent(invLogsMatch[1] ?? '');\n const logs = options.store ? options.store.logsForInvocation(id) : [];\n res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });\n res.end(JSON.stringify({ logs }));\n return;\n }\n if (req.method === 'GET' && path === '/api/events') {\n serveSse(req, res, bus);\n return;\n }\n if (req.method === 'POST' && path === '/api/run') {\n void handleDispatch(req, res, options.onRun);\n return;\n }\n if (req.method === 'POST' && path === '/api/stop') {\n void handleDispatch(req, res, options.onStop);\n return;\n }\n res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });\n res.end('Not found');\n}\n\nconst MAX_RUN_BODY_BYTES = 5 * 1024 * 1024;\n\n/**\n * Reply to a JSON POST endpoint (`/api/run` / `/api/stop`): parse the\n * bounded JSON body and dispatch via `handler`. 501 when no handler is\n * wired (the observe-only shell), 400 on a malformed body, 500 when the\n * handler throws.\n */\nasync function handleDispatch(\n req: IncomingMessage,\n res: ServerResponse,\n handler?: (body: unknown) => Promise<unknown>\n): Promise<void> {\n const sendJson = (statusCode: number, payload: unknown): void => {\n res.writeHead(statusCode, { 'content-type': 'application/json; charset=utf-8' });\n res.end(JSON.stringify(payload));\n };\n\n if (!handler) {\n // The observe-only shell (no dispatcher wired) cannot run targets.\n sendJson(501, { error: 'Running targets is not supported by this studio server.' });\n return;\n }\n\n let body: unknown;\n try {\n body = await readJsonBody(req);\n } catch (err) {\n sendJson(400, { error: err instanceof Error ? err.message : String(err) });\n return;\n }\n\n try {\n const result = await handler(body);\n sendJson(200, result);\n } catch (err) {\n sendJson(500, { error: err instanceof Error ? err.message : String(err) });\n }\n}\n\n/** Read + JSON-parse a request body, bounded to {@link MAX_RUN_BODY_BYTES}. */\nfunction readJsonBody(req: IncomingMessage): Promise<unknown> {\n return new Promise<unknown>((resolveBody, reject) => {\n let raw = '';\n let bytes = 0;\n // Single-flight: once the promise settles (over-limit / end / error) the\n // handlers short-circuit so a late chunk or the destroy-triggered `error`\n // cannot re-settle it.\n let done = false;\n const settle = (fn: () => void): void => {\n if (done) return;\n done = true;\n fn();\n };\n req.setEncoding('utf8');\n req.on('data', (chunk: string) => {\n if (done) return;\n bytes += Buffer.byteLength(chunk);\n if (bytes > MAX_RUN_BODY_BYTES) {\n settle(() => reject(new Error('Request body too large.')));\n req.destroy();\n return;\n }\n raw += chunk;\n });\n req.on('end', () => {\n settle(() => {\n if (raw.trim() === '') {\n resolveBody(undefined);\n return;\n }\n try {\n resolveBody(JSON.parse(raw));\n } catch {\n reject(new Error('Invalid JSON body.'));\n }\n });\n });\n req.on('error', (err) => settle(() => reject(err)));\n });\n}\n\nfunction serveSse(req: IncomingMessage, res: ServerResponse, bus: StudioEventBus): void {\n res.writeHead(200, {\n 'content-type': 'text/event-stream; charset=utf-8',\n 'cache-control': 'no-cache, no-transform',\n connection: 'keep-alive',\n });\n\n let closed = false;\n const heartbeat = setInterval(() => safeWrite(':hb\\n\\n'), SSE_HEARTBEAT_MS);\n heartbeat.unref?.();\n\n const onInvocation = (ev: StudioInvocationEvent): void => {\n safeWrite(`event: invocation\\ndata: ${JSON.stringify(ev)}\\n\\n`);\n };\n const onLog = (ev: StudioLogEvent): void => {\n safeWrite(`event: log\\ndata: ${JSON.stringify(ev)}\\n\\n`);\n };\n const onServe = (ev: StudioServeEvent): void => {\n safeWrite(`event: serve\\ndata: ${JSON.stringify(ev)}\\n\\n`);\n };\n\n // Idempotent teardown: unsubscribe from the bus + stop the heartbeat so\n // a dropped EventSource client never leaks a listener.\n function cleanup(): void {\n if (closed) return;\n closed = true;\n clearInterval(heartbeat);\n bus.off('invocation', onInvocation);\n bus.off('log', onLog);\n bus.off('serve', onServe);\n }\n\n // Guard every write: on shutdown `close()` destroys live SSE sockets\n // (closeAllConnections), and a bus emit / heartbeat tick can race that\n // destroy. Writing to a destroyed socket emits an unhandled `error` on\n // the response — which, with no top-level uncaughtException handler on\n // the studio path, would crash the process on Ctrl-C. Drop the write\n // (and tear down) instead.\n function safeWrite(chunk: string): void {\n if (closed || res.writableEnded || res.destroyed) {\n cleanup();\n return;\n }\n res.write(chunk);\n }\n\n bus.on('invocation', onInvocation);\n bus.on('log', onLog);\n bus.on('serve', onServe);\n\n // `close` fires on client disconnect AND on server-side socket destroy;\n // `error` fires if a write loses the race with the destroy. All three\n // route through the idempotent cleanup so the bus listeners + heartbeat\n // never leak and a write error never propagates as uncaught.\n req.on('close', cleanup);\n res.on('close', cleanup);\n res.on('error', cleanup);\n\n // Open the stream so EventSource fires `open` immediately.\n safeWrite(':ok\\n\\n');\n}\n\n/**\n * Listen on `port`, retrying `port+1`, `port+2`, ... on `EADDRINUSE` up\n * to `maxBump` extra attempts. Resolves with the bound port.\n */\nfunction listenWithBump(\n server: Server,\n host: string,\n port: number,\n maxBump: number\n): Promise<number> {\n return new Promise<number>((resolveListen, reject) => {\n let attempt = 0;\n const tryListen = (p: number): void => {\n const onError = (err: NodeJS.ErrnoException): void => {\n if (err.code === 'EADDRINUSE' && attempt < maxBump) {\n attempt += 1;\n server.removeListener('error', onError);\n tryListen(p + 1);\n return;\n }\n reject(err);\n };\n server.once('error', onError);\n server.listen(p, host, () => {\n server.removeListener('error', onError);\n // Resolve with the ACTUAL bound port from the socket — when the\n // requested port is 0 the OS assigns a free one, which `p` does\n // not reflect.\n resolveListen((server.address() as AddressInfo).port);\n });\n };\n tryListen(port);\n });\n}\n","import { spawn as nodeSpawn, type ChildProcessWithoutNullStreams } from 'node:child_process';\nimport { mkdtempSync, rmSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { StudioEventBus, type StudioTargetKind } from './studio-events.js';\n\n/** A request to run a target, as the studio UI posts it to `/api/run`. */\nexport interface StudioRunRequest {\n /** Target id the user picked (display path or stack-qualified id). */\n targetId: string;\n /** Target kind. Slice B handles `'lambda'` (single-shot invoke) only. */\n kind: StudioTargetKind;\n /** The event payload to invoke with. */\n event: unknown;\n}\n\n/** The outcome of a single-shot run, returned from `/api/run`. */\nexport interface StudioRunResult {\n /** Correlation id shared with the emitted invocation events. */\n invocationId: string;\n /** Whether the underlying `cdkl invoke` exited 0. */\n ok: boolean;\n /**\n * Synthetic status for the timeline: 200 when the invoke succeeded,\n * 500 when it failed. A direct Lambda invoke has no HTTP status; this\n * is the UI's success/failure signal only.\n */\n status: number;\n /** Parsed Lambda response (JSON when parseable, else the raw string). */\n response?: unknown;\n /** Raw stdout payload from `cdkl invoke`. */\n raw?: string;\n /** Error summary when the invoke failed. */\n error?: string;\n /** Wall-clock duration in ms. */\n durationMs: number;\n}\n\n/** Config for {@link createStudioDispatcher}. */\nexport interface StudioDispatchConfig {\n /** Path to the `cdkl` CLI entry (`dist/cli.js`) — usually `process.argv[1]`. */\n cliEntry: string;\n /** The shared event bus; invocation + log events are emitted onto it. */\n bus: StudioEventBus;\n /** Working directory for the child invoke (defaults to `process.cwd()`). */\n cwd?: string;\n /** `--app` value to thread into the child invoke, if studio was given one. */\n app?: string;\n /** `-c key=value` context overrides to thread through. */\n context?: Record<string, string>;\n /** `--profile` to thread through. */\n profile?: string;\n /** `--region` to thread through. */\n region?: string;\n /** Node binary to spawn (defaults to `process.execPath`; injectable for tests). */\n nodeBin?: string;\n /** Spawn implementation (injectable for tests). */\n spawnFn?: typeof nodeSpawn;\n /** Clock (injectable for tests; defaults to `Date.now`). */\n clock?: () => number;\n /** Invocation-id factory (injectable for tests). */\n idFactory?: () => string;\n}\n\n/** A bound dispatcher exposing the `/api/run` handler. */\nexport interface StudioDispatcher {\n run: (req: StudioRunRequest) => Promise<StudioRunResult>;\n}\n\nlet idCounter = 0;\n\n/**\n * Build the studio run dispatcher. Slice B drives a single-shot Lambda\n * invoke by spawning the SAME `cdkl invoke` the headless command runs —\n * studio is a control plane over the CLI, so re-using the whole command\n * (rather than re-wiring its internals) guarantees byte-for-byte parity\n * and keeps all of `cdkl invoke`'s process-global behavior\n * (`process.exit`, env mutation, stdin) isolated in a child process.\n *\n * The child's stdout is the Lambda response payload; its stderr (status\n * + container logs) is streamed line-by-line onto the bus as `log`\n * events. An `invocation` start event is emitted before spawn and an end\n * event (with response + status + duration) after exit, both keyed by\n * the same correlation id so the UI threads them into one timeline row.\n */\nexport function createStudioDispatcher(config: StudioDispatchConfig): StudioDispatcher {\n const spawnFn = config.spawnFn ?? nodeSpawn;\n const nodeBin = config.nodeBin ?? process.execPath;\n const clock = config.clock ?? Date.now;\n const idFactory =\n config.idFactory ??\n (() => {\n idCounter += 1;\n return `inv-${clock()}-${idCounter}`;\n });\n\n async function run(req: StudioRunRequest): Promise<StudioRunResult> {\n const invocationId = idFactory();\n const startedAt = clock();\n\n if (req.kind !== 'lambda') {\n // Serve targets (API / ALB / ECS) arrive in slice C; reject clearly\n // rather than silently mis-dispatching.\n const error = `Running '${req.kind}' targets from studio is not supported yet (Lambda only).`;\n config.bus.emit('invocation', {\n id: invocationId,\n ts: startedAt,\n target: req.targetId,\n kind: req.kind,\n label: 'invoke',\n request: req.event,\n response: error,\n status: 501,\n durationMs: clock() - startedAt,\n });\n return { invocationId, ok: false, status: 501, error, durationMs: clock() - startedAt };\n }\n\n config.bus.emit('invocation', {\n id: invocationId,\n ts: startedAt,\n target: req.targetId,\n kind: req.kind,\n label: 'invoke',\n request: req.event,\n });\n\n // `dir` is created inside the try so a `writeFileSync` / `JSON.stringify`\n // throw still hits the finally that cleans it up.\n let dir: string | undefined;\n try {\n dir = mkdtempSync(join(tmpdir(), 'cdkl-studio-run-'));\n const eventFile = join(dir, 'event.json');\n writeFileSync(eventFile, JSON.stringify(req.event ?? {}));\n\n const args = ['invoke', req.targetId, '--event', eventFile];\n if (config.app) args.push('--app', config.app);\n if (config.profile) args.push('--profile', config.profile);\n if (config.region) args.push('--region', config.region);\n for (const [k, v] of Object.entries(config.context ?? {})) {\n args.push('-c', `${k}=${v}`);\n }\n\n const { code, stdout, stderr } = await runChild(\n spawnFn,\n nodeBin,\n [config.cliEntry, ...args],\n config.cwd ?? process.cwd(),\n invocationId,\n req.targetId,\n config.bus,\n clock\n );\n\n const durationMs = clock() - startedAt;\n const ok = code === 0;\n const failure = stderr.trim() || `cdkl invoke exited ${code}`;\n\n // `cdkl invoke` interleaves synth progress + streamed container logs on\n // stdout and writes the Lambda response there too. The RIE response is\n // always a single line of valid JSON (the serialized handler return\n // value or error object), whereas progress / container lines\n // (`Synthesizing…`, `Starting container…`, `START/END/REPORT`) are NOT\n // JSON — so the response is the LAST JSON-parseable stdout line, which is\n // robust against a container log line flushing AFTER the response. Every\n // other stdout line is surfaced as a log event. Falls back to the last\n // line when nothing parses (an unusual non-JSON / empty response).\n const stdoutLines = stdout\n .split('\\n')\n .map((l) => l.replace(/\\r$/, '').trimEnd())\n .filter((l) => l.trim().length > 0);\n\n let responseIdx = -1;\n let response: unknown;\n if (ok) {\n for (let i = stdoutLines.length - 1; i >= 0; i -= 1) {\n const parsed = tryParseJson(stdoutLines[i] ?? '');\n if (parsed.ok) {\n responseIdx = i;\n response = parsed.value;\n break;\n }\n }\n if (responseIdx === -1 && stdoutLines.length > 0) {\n responseIdx = stdoutLines.length - 1;\n response = stdoutLines[responseIdx];\n }\n } else {\n response = failure;\n }\n\n // Every stdout line that is not the response line is a log line.\n stdoutLines.forEach((line, i) => {\n if (i === responseIdx) return;\n config.bus.emit('log', {\n ts: clock(),\n containerId: invocationId,\n target: req.targetId,\n line,\n stream: 'stdout',\n });\n });\n\n const raw = responseIdx >= 0 ? (stdoutLines[responseIdx] ?? '') : '';\n const status = ok ? 200 : 500;\n\n config.bus.emit('invocation', {\n id: invocationId,\n ts: startedAt,\n target: req.targetId,\n kind: req.kind,\n label: 'invoke',\n request: req.event,\n response,\n status,\n durationMs,\n });\n\n const result: StudioRunResult = { invocationId, ok, status, durationMs };\n if (raw) result.raw = raw;\n if (response !== undefined) result.response = response;\n if (!ok) result.error = failure;\n return result;\n } finally {\n if (dir) rmSync(dir, { recursive: true, force: true });\n }\n }\n\n return { run };\n}\n\ninterface ChildOutcome {\n code: number | null;\n stdout: string;\n stderr: string;\n}\n\n/**\n * Spawn the child invoke, accumulate stdout, and stream stderr to the\n * bus line-by-line as `log` events. Resolves on process close.\n */\nfunction runChild(\n spawnFn: typeof nodeSpawn,\n nodeBin: string,\n argv: string[],\n cwd: string,\n invocationId: string,\n target: string,\n bus: StudioEventBus,\n clock: () => number\n): Promise<ChildOutcome> {\n return new Promise<ChildOutcome>((resolve, reject) => {\n let child: ChildProcessWithoutNullStreams;\n try {\n child = spawnFn(nodeBin, argv, { cwd });\n } catch (err) {\n reject(err instanceof Error ? err : new Error(String(err)));\n return;\n }\n\n let stdout = '';\n let stderr = '';\n let lineBuf = '';\n\n child.stdout.setEncoding('utf8');\n child.stderr.setEncoding('utf8');\n\n child.stdout.on('data', (chunk: string) => {\n stdout += chunk;\n });\n child.stderr.on('data', (chunk: string) => {\n stderr += chunk;\n lineBuf += chunk;\n let nl = lineBuf.indexOf('\\n');\n while (nl !== -1) {\n const line = lineBuf.slice(0, nl);\n lineBuf = lineBuf.slice(nl + 1);\n if (line.length > 0) {\n bus.emit('log', {\n ts: clock(),\n containerId: invocationId,\n target,\n line,\n stream: 'stderr',\n });\n }\n nl = lineBuf.indexOf('\\n');\n }\n });\n\n child.on('error', (err) => reject(err));\n child.on('close', (code) => {\n if (lineBuf.length > 0) {\n bus.emit('log', {\n ts: clock(),\n containerId: invocationId,\n target,\n line: lineBuf,\n stream: 'stderr',\n });\n }\n resolve({ code, stdout, stderr });\n });\n });\n}\n\n/** Try to JSON-parse `raw`; `ok` distinguishes a parsed value from a failure. */\nfunction tryParseJson(raw: string): { ok: boolean; value: unknown } {\n if (raw === '') return { ok: false, value: undefined };\n try {\n return { ok: true, value: JSON.parse(raw) };\n } catch {\n return { ok: false, value: undefined };\n }\n}\n","import { createServer, request as httpRequest, type IncomingMessage } from 'node:http';\nimport { connect as netConnect, type Socket } from 'node:net';\nimport type { AddressInfo } from 'node:net';\nimport { StudioEventBus, type StudioTargetKind } from './studio-events.js';\n\n/** Config for {@link startStudioProxy}. */\nexport interface StudioProxyConfig {\n /** The shared event bus; `invocation` start/end events are emitted onto it. */\n bus: StudioEventBus;\n /** Serve target id the proxied traffic belongs to. */\n target: string;\n /** The served target's kind (the timeline row's per-kind affordance). */\n kind: StudioTargetKind;\n /** Upstream base URL to forward to, e.g. `http://127.0.0.1:51234`. */\n upstream: string;\n /** Listen host. Defaults to `127.0.0.1` (localhost-only). */\n host?: string;\n /** Clock (injectable for tests; defaults to `Date.now`). */\n clock?: () => number;\n /** Per-request id factory (injectable for tests). */\n idFactory?: () => string;\n /**\n * Max bytes of each captured request / response body retained for the\n * timeline (the FULL body is still streamed through untouched — only\n * the captured copy is bounded). Defaults to 64 KiB.\n */\n maxCaptureBytes?: number;\n}\n\n/** A running studio capture proxy. */\nexport interface RunningStudioProxy {\n /** The URL the proxy listens on (hand this to the user instead of upstream). */\n url: string;\n /** The actually-bound port. */\n port: number;\n /** Stop the proxy and release the port. */\n close: () => Promise<void>;\n}\n\nlet proxyIdCounter = 0;\n\n/**\n * Start a capturing reverse proxy in front of a studio serve target\n * (decision D4a: because every request to the served port flows through\n * `cdkl studio`, the timeline observes them regardless of source —\n * browser, curl, or the in-UI pad alike).\n *\n * Each HTTP request is forwarded to `upstream` and, in parallel,\n * captured (method / path / headers / bounded body) and emitted as an\n * `invocation` start event; when the upstream response completes, an end\n * event carries the status / headers / bounded body / duration. The full\n * bodies stream through untouched — only the captured copies are bounded.\n * `Upgrade` (WebSocket) requests are bridged raw to the upstream without\n * capture so they keep working.\n *\n * Studio is a control plane over the CLI, so this proxy sits in front of\n * the long-running `cdkl start-api` child the serve manager spawned; it\n * does NOT re-implement any routing — it forwards verbatim.\n */\nexport function startStudioProxy(config: StudioProxyConfig): Promise<RunningStudioProxy> {\n const host = config.host ?? '127.0.0.1';\n const clock = config.clock ?? Date.now;\n const maxCapture = config.maxCaptureBytes ?? 64 * 1024;\n const idFactory =\n config.idFactory ??\n (() => {\n proxyIdCounter += 1;\n return `req-${clock()}-${proxyIdCounter}`;\n });\n\n const upstreamUrl = new URL(config.upstream);\n const upstreamHost = upstreamUrl.hostname;\n const upstreamPort = Number(upstreamUrl.port) || 80;\n\n const server = createServer((clientReq, clientRes) => {\n const id = idFactory();\n const startedAt = clock();\n const path = clientReq.url ?? '/';\n const method = clientReq.method ?? 'GET';\n const label = `${method} ${path.split('?')[0]}`;\n\n // Capture the request body (bounded) while it streams to the upstream.\n const reqBody = boundedCollector(maxCapture);\n\n config.bus.emit('invocation', {\n id,\n ts: startedAt,\n target: config.target,\n kind: config.kind,\n label,\n request: { method, path, headers: { ...clientReq.headers } },\n });\n\n // Exactly ONE end event per request — whether it ends via the upstream\n // response, an upstream error, or a client abort. A second terminal\n // event (e.g. upstream socket erroring AFTER the response started) would\n // overwrite the real status on the timeline.\n let ended = false;\n const emitEnd = (status: number, response: unknown): void => {\n if (ended) return;\n ended = true;\n config.bus.emit('invocation', {\n id,\n ts: startedAt,\n target: config.target,\n kind: config.kind,\n label,\n request: { method, path, headers: { ...clientReq.headers }, body: reqBody.text() },\n response,\n status,\n durationMs: clock() - startedAt,\n });\n };\n\n const upstreamReq = httpRequest(\n {\n host: upstreamHost,\n port: upstreamPort,\n method,\n path,\n headers: clientReq.headers,\n },\n (upstreamRes) => {\n const respBody = boundedCollector(maxCapture);\n // Strip hop-by-hop headers before forwarding: `transfer-encoding` /\n // `connection` describe THIS connection, not the entity, and Node's\n // client already decoded a chunked body — re-declaring it (or a\n // stale `content-length`) can hang the client. `content-length` is\n // end-to-end and kept.\n clientRes.writeHead(upstreamRes.statusCode ?? 502, stripHopByHop(upstreamRes.headers));\n upstreamRes.on('data', (chunk: Buffer) => respBody.push(chunk));\n upstreamRes.pipe(clientRes);\n upstreamRes.on('end', () =>\n emitEnd(upstreamRes.statusCode ?? 502, {\n status: upstreamRes.statusCode,\n headers: { ...upstreamRes.headers },\n body: respBody.text(),\n })\n );\n upstreamRes.on('error', () => {\n // The upstream died mid-response: terminate the client response so\n // it does not hang half-open (a dangling client socket that the\n // server's later closeAllConnections would destroy, surfacing as an\n // unhandled error). pipe() does not auto-close the destination on a\n // source error, so do it explicitly.\n if (!clientRes.writableEnded) clientRes.destroy();\n emitEnd(502, 'upstream response stream error');\n });\n }\n );\n\n upstreamReq.on('error', (err) => {\n if (!clientRes.headersSent) clientRes.writeHead(502, { 'content-type': 'text/plain' });\n clientRes.end(`studio proxy: upstream error: ${err.message}`);\n emitEnd(502, `upstream error: ${err.message}`);\n });\n\n clientReq.on('data', (chunk: Buffer) => reqBody.push(chunk));\n clientReq.on('error', () => {\n // The client hung up mid-flight — tear down the upstream and close the\n // timeline row (499, the \"client closed request\" convention) so it\n // does not dangle as pending forever.\n upstreamReq.destroy();\n emitEnd(499, 'client aborted the request');\n });\n clientReq.pipe(upstreamReq);\n });\n\n // WebSocket / other `Upgrade` requests: bridge the raw socket to the\n // upstream without capture so they keep working through the proxy.\n // Hijacked upgrade sockets are detached from the server's request flow,\n // so track them and destroy them on close() (otherwise a live WebSocket\n // keeps the server from closing).\n const upgradeSockets = new Set<Socket>();\n server.on('upgrade', (req, clientSocket, head) => {\n const sock = clientSocket as Socket;\n upgradeSockets.add(sock);\n sock.on('close', () => upgradeSockets.delete(sock));\n bridgeUpgrade(req, sock, head, upstreamHost, upstreamPort);\n });\n\n return new Promise<RunningStudioProxy>((resolve, reject) => {\n server.once('error', reject);\n server.listen(0, host, () => {\n server.removeListener('error', reject);\n const port = (server.address() as AddressInfo).port;\n resolve({\n url: `http://${host}:${port}`,\n port,\n close: () =>\n new Promise<void>((resolveClose, rejectClose) => {\n for (const sock of upgradeSockets) sock.destroy();\n upgradeSockets.clear();\n server.close((err) => (err ? rejectClose(err) : resolveClose()));\n server.closeAllConnections?.();\n }),\n });\n });\n });\n}\n\n/** RFC 7230 hop-by-hop headers — never forwarded across a proxy. */\nconst HOP_BY_HOP = new Set([\n 'connection',\n 'keep-alive',\n 'proxy-authenticate',\n 'proxy-authorization',\n 'te',\n 'trailer',\n 'transfer-encoding',\n 'upgrade',\n]);\n\n/** Copy `headers` without the hop-by-hop ones (which describe one connection). */\nfunction stripHopByHop(\n headers: Record<string, string | string[] | undefined>\n): Record<string, string | string[] | undefined> {\n const out: Record<string, string | string[] | undefined> = {};\n for (const [k, v] of Object.entries(headers)) {\n if (!HOP_BY_HOP.has(k.toLowerCase())) out[k] = v;\n }\n return out;\n}\n\n/** A bounded byte collector that decodes to a (possibly truncated) utf8 string. */\nfunction boundedCollector(maxBytes: number): { push: (c: Buffer) => void; text: () => string } {\n const chunks: Buffer[] = [];\n let size = 0;\n let truncated = false;\n return {\n push: (c: Buffer): void => {\n if (size >= maxBytes) {\n truncated = true;\n return;\n }\n const room = maxBytes - size;\n if (c.length > room) {\n chunks.push(c.subarray(0, room));\n size = maxBytes;\n truncated = true;\n } else {\n chunks.push(c);\n size += c.length;\n }\n },\n text: (): string => {\n const s = Buffer.concat(chunks).toString('utf8');\n return truncated ? `${s}… (truncated)` : s;\n },\n };\n}\n\n/** Raw-bridge an `Upgrade` request (e.g. WebSocket) to the upstream. */\nfunction bridgeUpgrade(\n req: IncomingMessage,\n clientSocket: Socket,\n head: Buffer,\n upstreamHost: string,\n upstreamPort: number\n): void {\n const upstream = netConnect(upstreamPort, upstreamHost, () => {\n let raw = `${req.method} ${req.url} HTTP/1.1\\r\\n`;\n for (let i = 0; i < req.rawHeaders.length; i += 2) {\n raw += `${req.rawHeaders[i]}: ${req.rawHeaders[i + 1]}\\r\\n`;\n }\n raw += '\\r\\n';\n upstream.write(raw);\n if (head && head.length > 0) upstream.write(head);\n clientSocket.pipe(upstream);\n upstream.pipe(clientSocket);\n });\n const teardown = (): void => {\n clientSocket.destroy();\n upstream.destroy();\n };\n // Tear down BOTH sockets when either errors OR closes — a clean half-open\n // close (FIN, no error) on one side must not leave the peer dangling.\n upstream.on('error', teardown);\n upstream.on('close', teardown);\n clientSocket.on('error', teardown);\n clientSocket.on('close', teardown);\n}\n","import { spawn as nodeSpawn, type ChildProcessWithoutNullStreams } from 'node:child_process';\nimport { StudioEventBus, type StudioServeEvent, type StudioTargetKind } from './studio-events.js';\nimport {\n startStudioProxy,\n type RunningStudioProxy,\n type StudioProxyConfig,\n} from './studio-proxy.js';\n\n/** A request to start serving a target, as the studio UI posts it. */\nexport interface StudioServeRequest {\n /** Target id the user picked (display path or stack-qualified id). */\n targetId: string;\n /** Target kind — a serve kind (`api` / `alb` / `ecs`); see SERVE_SPECS. */\n kind: StudioTargetKind;\n}\n\n/** A request to stop a running served target. */\nexport interface StudioStopRequest {\n /** Target id of the serve to stop. */\n targetId: string;\n}\n\n/** The public state of one running served target (returned to the UI). */\nexport interface StudioServeState {\n /** Target id of the served target. */\n targetId: string;\n /** The served target's kind. */\n kind: StudioTargetKind;\n /** Lifecycle status. */\n status: 'starting' | 'running' | 'stopped' | 'error';\n /** Served endpoint URLs, populated once running. */\n endpoints: string[];\n /** Child process id. */\n pid?: number;\n /** Wall-clock epoch ms when the serve started. */\n startedAt: number;\n}\n\n/** Config for {@link createStudioServeManager}. */\nexport interface StudioServeManagerConfig {\n /** Path to the `cdkl` CLI entry (`dist/cli.js`) — usually `process.argv[1]`. */\n cliEntry: string;\n /** The shared event bus; serve + log events are emitted onto it. */\n bus: StudioEventBus;\n /** Working directory for the child serve (defaults to `process.cwd()`). */\n cwd?: string;\n /** `--app` value to thread into the child serve, if studio was given one. */\n app?: string;\n /** `-c key=value` context overrides to thread through. */\n context?: Record<string, string>;\n /** `--profile` to thread through. */\n profile?: string;\n /** `--region` to thread through. */\n region?: string;\n /** Node binary to spawn (defaults to `process.execPath`; injectable for tests). */\n nodeBin?: string;\n /** Spawn implementation (injectable for tests). */\n spawnFn?: typeof nodeSpawn;\n /** Clock (injectable for tests; defaults to `Date.now`). */\n clock?: () => number;\n /**\n * Max ms to wait for the first `Server listening on ...` line before\n * giving up and killing the child. Generous by default to cover the\n * first-run base-image pull `start-api` triggers. Defaults to 120_000.\n */\n readyTimeoutMs?: number;\n /**\n * Ms to wait for a SIGTERM'd child to exit before sending SIGKILL.\n * Generous by default so a serve command running its OWN teardown\n * completes first — `start-alb` / `start-service` drain + remove their\n * ECS replicas + the shared docker network, which can take well over\n * 10s; a premature SIGKILL would orphan those containers/network.\n * Defaults to 45_000.\n */\n stopGraceMs?: number;\n /** `setTimeout` (injectable for tests). */\n setTimeoutFn?: typeof setTimeout;\n /** `clearTimeout` (injectable for tests). */\n clearTimeoutFn?: typeof clearTimeout;\n /**\n * Factory for the capture proxy fronting each HTTP serve endpoint\n * (slice C2). Injectable for tests; defaults to {@link startStudioProxy}.\n * When `captureRequests` is false this is never called.\n */\n proxyFactory?: (config: StudioProxyConfig) => Promise<RunningStudioProxy>;\n /**\n * Front each HTTP serve endpoint with a capture proxy so every request\n * to the served port lands on the studio timeline (decision D4a).\n * Defaults to true; set false to hand the child's port through\n * unproxied (the slice C1 behavior).\n */\n captureRequests?: boolean;\n}\n\n/** A bound serve manager exposing the start / stop / list surface. */\nexport interface StudioServeManager {\n /** Start serving a target; resolves once it is listening (or rejects). */\n start: (req: StudioServeRequest) => Promise<StudioServeState>;\n /** Stop a running served target; resolves once the child has exited. */\n stop: (req: StudioStopRequest) => Promise<void>;\n /** Snapshot of every running served target. */\n list: () => StudioServeState[];\n /** Stop every running served target (graceful shutdown). */\n stopAll: () => Promise<void>;\n}\n\n/** How the serve manager drives one long-running serve kind. */\ninterface ServeKindSpec {\n /** Headless subcommand spawned (e.g. `start-api`). */\n command: string;\n /** Port / host flags this command accepts (start-api binds an HTTP port). */\n portArgs: readonly string[];\n /**\n * The stdout line that signals readiness. Capture group 1, when present,\n * is the served endpoint URL (api / alb); a kind with no host endpoint\n * (ecs service — pure compute) matches with NO capture group.\n */\n readyRe: RegExp;\n /** Front each HTTP endpoint with a capture proxy (api / alb yes, ecs no). */\n capturesHttp: boolean;\n}\n\n/**\n * The serve lifecycle per kind. `api` + `alb` expose host HTTP endpoints\n * the studio capture proxy fronts; `ecs` (start-service) is pure compute\n * with no host port, so it has no endpoint and no capture — studio just\n * runs the replicas + streams their logs.\n */\nconst SERVE_SPECS: Partial<Record<StudioTargetKind, ServeKindSpec>> = {\n api: {\n command: 'start-api',\n portArgs: ['--port', '0', '--host', '127.0.0.1'],\n readyRe: /Server listening on (\\S+)/,\n capturesHttp: true,\n },\n alb: {\n // start-alb binds the deployed listener ports directly (no --port);\n // its front-door line carries the bound URL. Anchor the capture on a\n // URL scheme: under --tls start-alb also logs `ALB front-door:\n // generated self-signed cert at ...`, which a bare `(\\S+)` would match\n // (capturing `generated`) and flip the serve to running prematurely.\n command: 'start-alb',\n portArgs: [],\n readyRe: /ALB front-door: (https?:\\/\\/\\S+)/,\n capturesHttp: true,\n },\n ecs: {\n // start-service runs the service replicas only — no host port, no\n // capture. `Service(s) running:` is its stable ready marker.\n command: 'start-service',\n portArgs: [],\n readyRe: /Service\\(s\\) running:/,\n capturesHttp: false,\n },\n};\n\ninterface ServeEntry extends StudioServeState {\n child: ChildProcessWithoutNullStreams;\n /** Capture proxies fronting this serve's HTTP endpoints (slice C2). */\n proxies: RunningStudioProxy[];\n /**\n * Set by `stop()` when it tears the child down WHILE it is still\n * `starting` (the ready promise has not settled). The child's `close`\n * handler reads it so a user-initiated stop is not misreported as a\n * boot failure (no `error` event, no `start()` reject as a crash).\n */\n stopping?: boolean;\n}\n\n/**\n * Build the studio serve manager. Slice C1 drives a long-running\n * `cdkl start-api <target>` child — studio is a control plane over the\n * CLI (the same pattern as the single-shot invoke dispatcher), so it\n * spawns the SAME headless serve command rather than re-wiring its\n * internals. This preserves byte-for-byte parity and isolates the\n * server's process-global behavior in a child.\n *\n * `start()` spawns the child with `--port 0` (OS-assigned, collision\n * free), streams its stdout/stderr onto the bus as `log` events keyed by\n * the target id, and resolves once the child prints its first\n * `Server listening on <url>` line — emitting a `serve` `running` event\n * with the discovered endpoints. `stop()` SIGTERMs the child (SIGKILL\n * after a grace window) and emits `stopped`.\n *\n * Slice C2 fronts each HTTP serve endpoint with a capture proxy\n * ({@link startStudioProxy}) so every request to the served port lands\n * on the studio timeline (decision D4a); the `endpoints` the UI is\n * handed are the proxy URLs. The serve-kinds slice generalized this to a\n * per-kind {@link ServeKindSpec}: `api` (`start-api`) + `alb`\n * (`start-alb`) expose host HTTP endpoints the proxy captures, while\n * `ecs` (`start-service`) is pure compute — no host port, no capture,\n * just the running replicas + their streamed logs.\n */\nexport function createStudioServeManager(config: StudioServeManagerConfig): StudioServeManager {\n const spawnFn = config.spawnFn ?? nodeSpawn;\n const nodeBin = config.nodeBin ?? process.execPath;\n const clock = config.clock ?? Date.now;\n const readyTimeoutMs = config.readyTimeoutMs ?? 120_000;\n const stopGraceMs = config.stopGraceMs ?? 45_000;\n const setTimeoutFn = config.setTimeoutFn ?? setTimeout;\n const clearTimeoutFn = config.clearTimeoutFn ?? clearTimeout;\n const cwd = config.cwd ?? process.cwd();\n const proxyFactory = config.proxyFactory ?? startStudioProxy;\n const captureRequests = config.captureRequests ?? true;\n\n const entries = new Map<string, ServeEntry>();\n\n /** Close every capture proxy fronting `e` (best-effort; idempotent). */\n async function closeProxies(e: ServeEntry): Promise<void> {\n const proxies = e.proxies.splice(0);\n await Promise.all(proxies.map((p) => p.close().catch(() => undefined)));\n }\n\n function publicState(e: ServeEntry): StudioServeState {\n const s: StudioServeState = {\n targetId: e.targetId,\n kind: e.kind,\n status: e.status,\n endpoints: [...e.endpoints],\n startedAt: e.startedAt,\n };\n if (e.pid !== undefined) s.pid = e.pid;\n return s;\n }\n\n function emitServe(e: ServeEntry, message?: string): void {\n const ev: StudioServeEvent = {\n ts: clock(),\n target: e.targetId,\n kind: e.kind,\n status: e.status,\n endpoints: [...e.endpoints],\n };\n if (e.pid !== undefined) ev.pid = e.pid;\n if (message !== undefined) ev.message = message;\n config.bus.emit('serve', ev);\n }\n\n function buildArgs(targetId: string, spec: ServeKindSpec): string[] {\n const args = [spec.command, targetId, ...spec.portArgs];\n if (config.app) args.push('--app', config.app);\n if (config.profile) args.push('--profile', config.profile);\n if (config.region) args.push('--region', config.region);\n for (const [k, v] of Object.entries(config.context ?? {})) {\n args.push('-c', `${k}=${v}`);\n }\n return args;\n }\n\n async function start(req: StudioServeRequest): Promise<StudioServeState> {\n const spec = SERVE_SPECS[req.kind];\n if (!spec) {\n throw new Error(\n `Serving '${req.kind}' targets from studio is not supported (serve kinds: ${Object.keys(SERVE_SPECS).join(', ')}).`\n );\n }\n const existing = entries.get(req.targetId);\n if (existing && existing.status !== 'stopped' && existing.status !== 'error') {\n throw new Error(`'${req.targetId}' is already running.`);\n }\n\n const startedAt = clock();\n let child: ChildProcessWithoutNullStreams;\n try {\n child = spawnFn(nodeBin, [config.cliEntry, ...buildArgs(req.targetId, spec)], { cwd });\n } catch (err) {\n throw err instanceof Error ? err : new Error(String(err));\n }\n\n const entry: ServeEntry = {\n targetId: req.targetId,\n kind: req.kind,\n status: 'starting',\n endpoints: [],\n startedAt,\n child,\n proxies: [],\n };\n if (child.pid !== undefined) entry.pid = child.pid;\n entries.set(req.targetId, entry);\n emitServe(entry);\n\n return new Promise<StudioServeState>((resolve, reject) => {\n let settled = false;\n child.stdout.setEncoding('utf8');\n child.stderr.setEncoding('utf8');\n\n const timer = setTimeoutFn(() => {\n if (settled) return;\n settled = true;\n entry.status = 'error';\n emitServe(entry, `Timed out after ${readyTimeoutMs}ms waiting for the serve to be ready.`);\n // Graceful SIGTERM -> SIGKILL (NOT an immediate SIGKILL): the serve\n // commands trap SIGTERM to tear down their containers, so a hard kill\n // on a half-booted child would orphan those containers.\n void stopChild(child, stopGraceMs, setTimeoutFn, clearTimeoutFn);\n void closeProxies(entry);\n entries.delete(req.targetId);\n reject(new Error(`'${req.targetId}' did not start within ${readyTimeoutMs}ms.`));\n }, readyTimeoutMs);\n timer.unref?.();\n\n const becomeRunning = (): void => {\n if (settled) return;\n settled = true;\n clearTimeoutFn(timer);\n entry.status = 'running';\n emitServe(entry);\n resolve(publicState(entry));\n };\n\n // Handle a child ready line. `childUrl` (capture group 1) is the\n // served endpoint for api / alb — fronted with a capture proxy (slice\n // C2 / decision D4a) when `capturesHttp` so every request to it lands\n // on the timeline; ws:// (and capture-off) endpoints pass straight\n // through. An ecs service has NO endpoint (`childUrl` undefined): it\n // just flips to running with no endpoint + no proxy. The FIRST ready\n // line flips the serve to running; later ones append + re-emit.\n const onReady = async (childUrl?: string): Promise<void> => {\n let endpoint = childUrl;\n if (childUrl && spec.capturesHttp && captureRequests && /^https?:/i.test(childUrl)) {\n try {\n const proxy = await proxyFactory({\n bus: config.bus,\n target: req.targetId,\n kind: req.kind,\n upstream: childUrl,\n });\n entry.proxies.push(proxy);\n endpoint = proxy.url;\n } catch {\n // Proxy failed to bind — fall back to the direct child URL so\n // the serve is still usable (just uncaptured).\n endpoint = childUrl;\n }\n }\n // A stop() may have raced the async proxy startup; if so, drop the\n // now-orphan proxy and do not resurrect the torn-down serve.\n if (entry.stopping || (settled && !entries.has(req.targetId))) {\n await closeProxies(entry);\n return;\n }\n if (endpoint && !entry.endpoints.includes(endpoint)) entry.endpoints.push(endpoint);\n if (settled) emitServe(entry);\n else becomeRunning();\n };\n\n streamLines(child.stdout, (line) => {\n const m = spec.readyRe.exec(line);\n // m[1] is the endpoint URL for api / alb; undefined for ecs (no\n // capture group) — a ready line with no host endpoint.\n if (m) void onReady(m[1]);\n emitLog(config.bus, clock, req.targetId, line, 'stdout');\n });\n streamLines(child.stderr, (line) => {\n emitLog(config.bus, clock, req.targetId, line, 'stderr');\n });\n\n child.on('error', (err) => {\n if (settled) {\n // Post-ready spawn error: mark the entry errored for the UI.\n entry.status = 'error';\n emitServe(entry, err.message);\n void closeProxies(entry);\n entries.delete(req.targetId);\n return;\n }\n settled = true;\n clearTimeoutFn(timer);\n entry.status = 'error';\n emitServe(entry, err.message);\n void closeProxies(entry);\n entries.delete(req.targetId);\n reject(err);\n });\n\n child.on('close', (code) => {\n if (!settled) {\n settled = true;\n clearTimeoutFn(timer);\n if (entry.stopping) {\n // A user `stop()` raced the still-starting child: not a boot\n // failure. `stop()` emits the `stopped` event + resolves itself,\n // so here we only reject the pending `start()` (the /api/run POST)\n // with an honest \"cancelled\" message and emit nothing.\n reject(new Error(`'${req.targetId}' was stopped before it finished starting.`));\n return;\n }\n // Exited before ever listening — a boot failure.\n entry.status = 'error';\n const msg = `Server exited before listening (code ${code ?? 'null'}).`;\n emitServe(entry, msg);\n void closeProxies(entry);\n entries.delete(req.targetId);\n reject(new Error(msg));\n return;\n }\n // Exited while running (crash or our own stop()). If still tracked\n // as running, surface it as stopped; stop() removes the entry\n // itself before this fires in the graceful path.\n const tracked = entries.get(req.targetId);\n if (tracked === entry && entry.status === 'running') {\n entry.status = 'stopped';\n emitServe(entry, `Server process exited (code ${code ?? 'null'}).`);\n void closeProxies(entry);\n entries.delete(req.targetId);\n }\n });\n });\n }\n\n async function stop(req: StudioStopRequest): Promise<void> {\n const entry = entries.get(req.targetId);\n if (!entry) {\n throw new Error(`'${req.targetId}' is not running.`);\n }\n // Flag so the child's `close` handler treats this as a user stop, not a\n // boot failure, when the serve was still `starting` (#1).\n entry.stopping = true;\n entries.delete(req.targetId);\n // Tear down the capture proxies and SIGTERM the child concurrently —\n // both are initiated synchronously (stopChild attaches its `close`\n // listener + sends SIGTERM in the same tick) so neither races the\n // child's exit.\n await Promise.all([\n closeProxies(entry),\n stopChild(entry.child, stopGraceMs, setTimeoutFn, clearTimeoutFn),\n ]);\n entry.status = 'stopped';\n emitServe(entry);\n }\n\n function list(): StudioServeState[] {\n return [...entries.values()].map(publicState);\n }\n\n async function stopAll(): Promise<void> {\n const targets = [...entries.keys()];\n // `stop()` itself always resolves for a tracked target (stopChild\n // escalates SIGTERM -> SIGKILL and resolves on close); the only reject\n // path is the \"not running\" race if a sibling stop already evicted the\n // key. The catch keeps one such race from aborting the rest of the\n // shutdown sweep.\n await Promise.all(targets.map((targetId) => stop({ targetId }).catch(() => undefined)));\n }\n\n return { start, stop, list, stopAll };\n}\n\n/** Emit one container log line onto the bus, keyed by the serve target id. */\nfunction emitLog(\n bus: StudioEventBus,\n clock: () => number,\n target: string,\n line: string,\n stream: 'stdout' | 'stderr'\n): void {\n bus.emit('log', { ts: clock(), containerId: target, target, line, stream });\n}\n\n/**\n * Line-buffer a child stream and invoke `onLine` per complete line\n * (trailing newline stripped, blank lines dropped). Flushes any partial\n * final line on stream end.\n */\nfunction streamLines(stream: NodeJS.ReadableStream, onLine: (line: string) => void): void {\n let buf = '';\n stream.on('data', (chunk: string) => {\n buf += chunk;\n let nl = buf.indexOf('\\n');\n while (nl !== -1) {\n const line = buf.slice(0, nl).replace(/\\r$/, '');\n buf = buf.slice(nl + 1);\n if (line.length > 0) onLine(line);\n nl = buf.indexOf('\\n');\n }\n });\n stream.on('end', () => {\n const line = buf.replace(/\\r$/, '');\n if (line.length > 0) onLine(line);\n buf = '';\n });\n}\n\n/**\n * SIGTERM a child and resolve once it exits, escalating to SIGKILL after\n * `graceMs`. Resolves immediately if the child has already exited.\n */\nfunction stopChild(\n child: ChildProcessWithoutNullStreams,\n graceMs: number,\n setTimeoutFn: typeof setTimeout,\n clearTimeoutFn: typeof clearTimeout\n): Promise<void> {\n return new Promise<void>((resolve) => {\n let done = false;\n let kill: ReturnType<typeof setTimeout> | undefined;\n const finish = (): void => {\n if (done) return;\n done = true;\n if (kill) clearTimeoutFn(kill);\n resolve();\n };\n // Attach the `close` listener BEFORE the already-exited check so a child\n // that exits in the window between the check and the listener attach is\n // not missed (which would leave the promise pending forever). #4\n child.once('close', finish);\n if (child.exitCode !== null || child.signalCode !== null) {\n finish();\n return;\n }\n kill = setTimeoutFn(() => {\n if (!done) child.kill('SIGKILL');\n }, graceMs);\n kill.unref?.();\n child.kill('SIGTERM');\n });\n}\n","import { spawn } from 'node:child_process';\nimport { Command, Option } from 'commander';\nimport {\n appOptions,\n commonOptions,\n contextOptions,\n regionOption,\n parseContextOptions,\n} from '../options.js';\nimport { getLogger } from '../../utils/logger.js';\nimport { applyRoleArnIfSet } from '../../utils/role-arn.js';\nimport { withErrorHandling } from '../../utils/error-handler.js';\nimport { Synthesizer, type SynthesisOptions } from '../../synthesis/synthesizer.js';\nimport { resolveApp } from '../config-loader.js';\nimport {\n getEmbedConfig,\n setEmbedConfig,\n type CdkLocalEmbedConfig,\n} from '../../local/embed-config.js';\nimport { listTargets } from '../../local/target-lister.js';\nimport { StudioEventBus, type StudioTargetKind } from '../../local/studio-events.js';\nimport { createStudioStore, type StudioStore } from '../../local/studio-store.js';\nimport {\n startStudioServer,\n toStudioTargetGroups,\n type RunningStudioServer,\n} from '../../local/studio-server.js';\nimport { createStudioDispatcher, type StudioRunRequest } from '../../local/studio-dispatch.js';\nimport {\n createStudioServeManager,\n type StudioServeManager,\n type StudioStopRequest,\n} from '../../local/studio-serve-manager.js';\n\nconst STUDIO_TARGET_KINDS: readonly StudioTargetKind[] = [\n 'lambda',\n 'api',\n 'alb',\n 'ecs',\n 'agentcore',\n];\n\n/**\n * Validate + narrow the untyped `POST /api/run` body into a\n * {@link StudioRunRequest}. Throws (→ 400 from the server) on a malformed\n * body so a bad UI / curl payload fails loudly rather than spawning an\n * `invoke` for an empty target.\n */\nexport function coerceRunRequest(body: unknown): StudioRunRequest {\n if (typeof body !== 'object' || body === null) {\n throw new Error('Request body must be a JSON object.');\n }\n const { targetId, kind, event } = body as Record<string, unknown>;\n if (typeof targetId !== 'string' || targetId.trim() === '') {\n throw new Error('Request body must include a non-empty \"targetId\" string.');\n }\n if (typeof kind !== 'string' || !STUDIO_TARGET_KINDS.includes(kind as StudioTargetKind)) {\n throw new Error(`Request body \"kind\" must be one of: ${STUDIO_TARGET_KINDS.join(', ')}.`);\n }\n return { targetId, kind: kind as StudioTargetKind, event };\n}\n\n/**\n * Validate + narrow the untyped `POST /api/stop` body into a\n * {@link StudioStopRequest}. Throws (→ 400 from the server) on a missing\n * / empty target id.\n */\nexport function coerceStopRequest(body: unknown): StudioStopRequest {\n if (typeof body !== 'object' || body === null) {\n throw new Error('Request body must be a JSON object.');\n }\n const { targetId } = body as Record<string, unknown>;\n if (typeof targetId !== 'string' || targetId.trim() === '') {\n throw new Error('Request body must include a non-empty \"targetId\" string.');\n }\n return { targetId };\n}\n\nconst DEFAULT_STUDIO_PORT = 9999;\n\n/**\n * Parse + validate the `--studio-port` value. Accepts `0` (OS-assigned)\n * through `65535`. Exported so a unit test can assert the bounds without\n * driving the full command. Throws on anything out of range / non-numeric.\n */\nexport function parseStudioPort(raw: string): number {\n // `Number('')` / `Number(' ')` coerce to 0, which would pass the range\n // check; reject blank input explicitly.\n const port = raw.trim() === '' ? NaN : Number(raw);\n if (!Number.isInteger(port) || port < 0 || port > 65535) {\n throw new Error(`--studio-port must be 0..65535 (got ${raw}).`);\n }\n return port;\n}\n\ninterface LocalStudioOptions {\n app?: string;\n output: string;\n verbose: boolean;\n profile?: string;\n roleArn?: string;\n context?: string[];\n region?: string;\n /** `--studio-port`: preferred listen port (bumps on collision). */\n studioPort: string;\n /** `--no-open`: suppress auto-opening the browser (Commander sets `open`). */\n open: boolean;\n}\n\n/**\n * Factory options for {@link createLocalStudioCommand}.\n */\nexport interface CreateLocalStudioCommandOptions {\n /** Embed-time branding overrides for a host wrapping this factory. */\n embedConfig?: CdkLocalEmbedConfig;\n}\n\nasync function localStudioCommand(options: LocalStudioOptions): Promise<void> {\n const logger = getLogger();\n if (options.verbose) logger.setLevel('debug');\n\n const port = parseStudioPort(options.studioPort);\n\n await applyRoleArnIfSet({\n roleArn: options.roleArn,\n region: undefined,\n profile: options.profile,\n });\n\n const appCmd = resolveApp(options.app);\n if (!appCmd) {\n throw new Error(\n `No CDK app specified. Pass --app, set ${getEmbedConfig().envPrefix}_APP, or add \"app\" to cdk.json.`\n );\n }\n\n logger.info('Synthesizing CDK app...');\n const synthesizer = new Synthesizer();\n const context = parseContextOptions(options.context);\n const synthOpts: SynthesisOptions = {\n app: appCmd,\n output: options.output,\n ...(options.profile && { profile: options.profile }),\n ...(Object.keys(context).length > 0 && { context }),\n };\n const { stacks } = await synthesizer.synthesize(synthOpts);\n\n const listing = listTargets(stacks);\n const targetGroups = toStudioTargetGroups(listing);\n const appLabel = stacks.map((s) => s.stackName).join(', ') || appCmd;\n\n // ECS target ids that are actually servable (services, not task\n // definitions). The UI only wires servable rows, but a raw curl could\n // POST a task-def with kind:'ecs' — reject it at the boundary with a\n // clear message rather than spawning a doomed `start-service`.\n const servableEcs = new Set(\n targetGroups\n .filter((g) => g.kind === 'ecs')\n .flatMap((g) => g.entries.filter((e) => e.servable).map((e) => e.id))\n );\n\n const bus = new StudioEventBus();\n // `process.argv[1]` is the running CLI entry (`dist/cli.js` / the `cdkl`\n // bin); both the invoke dispatcher and the serve manager spawn it again\n // (`cdkl invoke <target>` / `cdkl start-api <target>`) — studio is a\n // control plane over the CLI.\n const cliEntry = process.argv[1] ?? '';\n const childConfig = {\n cliEntry,\n bus,\n cwd: process.cwd(),\n ...(appCmd ? { app: appCmd } : {}),\n ...(options.profile ? { profile: options.profile } : {}),\n ...(options.region ? { region: options.region } : {}),\n ...(Object.keys(context).length > 0 ? { context } : {}),\n };\n const dispatcher = createStudioDispatcher(childConfig);\n const serveManager = createStudioServeManager(childConfig);\n // Retain a bounded window of invocations + logs so the browser can render\n // history on (re)connect, search logs full-text, and bind a request's\n // logs at CloudWatch granularity (slice C3).\n const store = createStudioStore(bus);\n\n const server = await startStudioServer({\n port,\n bus,\n targetGroups,\n appLabel,\n cliName: getEmbedConfig().cliName,\n store,\n // `/api/run`: a Lambda is a single-shot invoke; api / alb / ecs are\n // long-running serve starts (the serve manager rejects any other kind).\n onRun: (body) => {\n const req = coerceRunRequest(body);\n if (req.kind === 'lambda') return dispatcher.run(req);\n if (req.kind === 'ecs' && !servableEcs.has(req.targetId)) {\n return Promise.reject(\n new Error(\n `'${req.targetId}' is not a servable ECS service (an ECS task definition runs via run-task, not start-service).`\n )\n );\n }\n return serveManager.start(req);\n },\n onStop: async (body) => {\n const req = coerceStopRequest(body);\n await serveManager.stop(req);\n return { stopped: req.targetId };\n },\n getRunning: () => ({ running: serveManager.list() }),\n });\n\n const cliName = getEmbedConfig().cliName;\n logger.info(`${cliName} studio is running at ${server.url}`);\n logger.info('Press Ctrl-C to stop.');\n\n // Auto-open the browser only in an interactive terminal (never in CI /\n // piped / integ runs) and unless --no-open was passed.\n if (options.open && process.stdout.isTTY) {\n openBrowser(server.url);\n }\n\n await blockUntilShutdown(server, serveManager, store, cliName);\n}\n\n/** Best-effort cross-platform browser open. Failures are non-fatal. */\nfunction openBrowser(url: string): void {\n const cmd =\n process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';\n try {\n const child = spawn(cmd, [url], {\n stdio: 'ignore',\n detached: true,\n shell: process.platform === 'win32',\n });\n child.on('error', () => undefined);\n child.unref();\n } catch {\n // Opening the browser is a convenience; ignore any failure.\n }\n}\n\n/**\n * Block until SIGINT / SIGTERM, then stop every running serve child,\n * close the studio server, and resolve. Mirrors the long-running serve\n * commands' graceful-shutdown contract — the serve children are killed\n * BEFORE the server closes so their RIE containers are torn down rather\n * than orphaned.\n */\nfunction blockUntilShutdown(\n server: RunningStudioServer,\n serveManager: StudioServeManager,\n store: StudioStore,\n cliName: string\n): Promise<void> {\n return new Promise<void>((resolveShutdown) => {\n let shuttingDown = false;\n const shutdown = (signal: string): void => {\n if (shuttingDown) return;\n shuttingDown = true;\n getLogger().info(`Received ${signal}; stopping ${cliName} studio...`);\n // Unsubscribe the store from the bus so a host CLI that restarts\n // studio in a long-lived process does not accumulate listeners.\n store.dispose();\n void serveManager\n .stopAll()\n .catch((err: unknown) => getLogger().warn(`Error stopping serve targets: ${String(err)}`))\n .then(() => server.close())\n .catch((err: unknown) => getLogger().warn(`Error stopping studio server: ${String(err)}`))\n .finally(() => resolveShutdown());\n };\n process.on('SIGINT', () => shutdown('SIGINT'));\n process.on('SIGTERM', () => shutdown('SIGTERM'));\n });\n}\n\nexport function createLocalStudioCommand(opts: CreateLocalStudioCommandOptions = {}): Command {\n setEmbedConfig(opts.embedConfig);\n const cmd = new Command('studio')\n .description(\n \"Open the local studio: a web console that lists the synthesized CDK app's runnable \" +\n 'targets and lets you invoke / serve them from the browser while watching all activity ' +\n 'in one timeline. The interactive counterpart to the headless invoke / start-* commands.'\n )\n .action(\n withErrorHandling(async (options: LocalStudioOptions) => {\n await localStudioCommand(options);\n })\n );\n\n addStudioSpecificOptions(cmd);\n [...commonOptions(), ...appOptions(), ...contextOptions].forEach((opt) => cmd.addOption(opt));\n cmd.addOption(regionOption);\n return cmd;\n}\n\n/**\n * Register the option block `cdkl studio` adds on top of the shared\n * common / app / context option helpers. Kept in a named helper (not\n * inline in {@link createLocalStudioCommand}) so a host CLI embedding\n * this factory inherits new studio flags without a duplicate\n * `.addOption(...)` block, matching every other `add<Cmd>SpecificOptions`\n * extraction. Chainable: returns `cmd`.\n */\nexport function addStudioSpecificOptions(cmd: Command): Command {\n cmd.addOption(\n new Option(\n '--studio-port <port>',\n 'Preferred port for the studio web server (bumps to the next free port on collision)'\n ).default(String(DEFAULT_STUDIO_PORT))\n );\n cmd.addOption(\n new Option('--no-open', 'Do not auto-open the browser when studio starts (TTY only)')\n );\n return cmd;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8GA,IAAa,iBAAb,MAA4B;CAC1B,AAAiB,UAAU,IAAI,cAAc;CAE7C,cAAc;EAGZ,KAAK,QAAQ,gBAAgB,EAAE;;CAGjC,KAAqC,OAAU,GAAG,MAA+B;EAC/E,KAAK,QAAQ,KAAK,OAAO,GAAG,KAAK;;CAGnC,GACE,OACA,UACM;EACN,KAAK,QAAQ,GAAG,OAAO,SAAyC;EAChE,OAAO;;CAGT,IACE,OACA,UACM;EACN,KAAK,QAAQ,IAAI,OAAO,SAAyC;EACjE,OAAO;;;;;;;CAQT,cAA8C,OAAkB;EAC9D,OAAO,KAAK,QAAQ,cAAc,MAAM;;;;;;;;;;;AC3E5C,SA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M,mBAAmB,QAAQ;GACjC,CACH;CAEH,yBAAyB,IAAI;CAC7B;EAAC,GAAG,eAAe;EAAE,GAAG,YAAY;EAAE,GAAG;EAAe,CAAC,SAAS,QAAQ,IAAI,UAAU,IAAI,CAAC;CAC7F,IAAI,UAAU,aAAa;CAC3B,OAAO;;;;;;;;;;AAWT,SAAgB,yBAAyB,KAAuB;CAC9D,IAAI,UACF,IAAI,OACF,wBACA,sFACD,CAAC,QAAQ,OAAO,oBAAoB,CAAC,CACvC;CACD,IAAI,UACF,IAAI,OAAO,aAAa,6DAA6D,CACtF;CACD,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cdk-local",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.83.0",
|
|
4
4
|
"description": "Run your CDK-built app locally — standalone, or against the real AWS resources and data it depends on. A CDK-native alternative to sam local.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|