From 9ca17fd398eb63a807c1b252d03f68ae37b7b1c4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 22:34:36 +0000 Subject: [PATCH] Add runtime app.health API and smoke-test health check Co-authored-by: Theo Browne --- README.md | 5 ++++ apps/renderer/src/wsNativeApi.ts | 3 +++ apps/t3/scripts/smoke-test.mjs | 9 +++++-- apps/t3/src/runtimeApiServer.test.ts | 35 ++++++++++++++++++++++++++++ apps/t3/src/runtimeApiServer.ts | 11 +++++++++ packages/contracts/src/ipc.ts | 8 +++++++ 6 files changed, 69 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f8d0c82c07..4ae57ecede 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,8 @@ The renderer depends on `nativeApi.providers.*`: 7. `onEvent` Codex is the only implemented provider right now. `claudeCode` is reserved in contracts/UI but currently returns a not-implemented runtime error. + +Runtime app utilities exposed via `nativeApi.app.*`: + +1. `bootstrap` +2. `health` diff --git a/apps/renderer/src/wsNativeApi.ts b/apps/renderer/src/wsNativeApi.ts index ec0757eafc..280db34e08 100644 --- a/apps/renderer/src/wsNativeApi.ts +++ b/apps/renderer/src/wsNativeApi.ts @@ -1,5 +1,6 @@ import type { AppBootstrapResult, + AppHealthResult, NativeApi, ProviderEvent, WsClientMessage, @@ -182,6 +183,8 @@ class WsNativeApiClient { app: { bootstrap: async () => this.request("app.bootstrap").then((value) => value as AppBootstrapResult), + health: async () => + this.request("app.health").then((value) => value as AppHealthResult), }, todos: { list: async () => diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index e1eef5d465..e995211e22 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -86,13 +86,18 @@ async function main() { JSON.stringify({ type: "request", id: "smoke", - method: "todos.list", + method: "app.health", }), ); }); ws.addEventListener("message", (event) => { const message = JSON.parse(String(event.data)); - if (message.type === "response" && message.id === "smoke" && message.ok === true) { + if ( + message.type === "response" && + message.id === "smoke" && + message.ok === true && + message.result?.status === "ok" + ) { clearTimeout(timer); resolve(); } diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 5321e948d7..b5c9d5a12f 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -224,4 +224,39 @@ describe("runtimeApiServer", () => { client.socket.close(); }); + + it("reports runtime health metadata", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + }); + servers.push(server); + + const client = await connectClient(server.wsUrl); + await client.nextMessage(); + + const response = await sendRequest( + client.socket, + client.nextMessage, + "health-1", + "app.health", + ); + expect(response.ok).toBe(true); + if (!response.ok) { + throw new Error("Expected health response to succeed."); + } + + const payload = response.result as { + status: string; + launchCwd: string; + sessionCount: number; + activeClientConnected: boolean; + }; + expect(payload.status).toBe("ok"); + expect(payload.launchCwd).toBe(process.cwd()); + expect(typeof payload.sessionCount).toBe("number"); + expect(payload.activeClientConnected).toBe(true); + + client.socket.close(); + }); }); diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 07d142800c..16a0d4800a 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -8,6 +8,7 @@ import { EDITORS, DEFAULT_MODEL, type AppBootstrapResult, + type AppHealthResult, type ProviderSession, type WsClientMessage, type WsResponseMessage, @@ -359,6 +360,16 @@ export async function startRuntimeApiServer( return payload; } + if (method === "app.health") { + const payload: AppHealthResult = { + status: "ok", + launchCwd, + sessionCount: providerManager.listSessions().length, + activeClientConnected: activeClient !== null, + }; + return payload; + } + if (method === "todos.list") return todoStore.list(); if (method === "todos.add") return todoStore.add(newTodoInputSchema.parse(params)); if (method === "todos.toggle") return todoStore.toggle(todoIdSchema.parse(params)); diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index dc3bd16222..5b1b75def0 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -29,9 +29,17 @@ export interface AppBootstrapResult { bootstrapError?: string; } +export interface AppHealthResult { + status: "ok"; + launchCwd: string; + sessionCount: number; + activeClientConnected: boolean; +} + export interface NativeApi { app: { bootstrap: () => Promise; + health: () => Promise; }; todos: { list: () => Promise;