A desktop coding agent with free access to frontier models.
TypeScript
import { browserScript } from "@omnirush/testkit";
import { expect } from "vitest";
import {
control,
createAndSelectWorkspace,
evalIn,
selectModel,
waitFor,
writeComposerText,
} from "@omnirush/behaviors";
import { screenshot, validate } from "@omnirush/test-evidence";
import {
app,
eventually,
localMysqlIsRunning,
localRedisIsRunning,
mcpMock,
needs,
server,
test,
} from "@omnirush/testkit";
import type { App } from "@omnirush/testkit";
const providerId = "todo-progress-mock";
const modelId = "todo-progress-model";
const modelName = "Todo progress model";
const e2eTestsEnabled = process.env.OMNIRUSH_EVAL_E2E_TESTS === "1";
const daytonaEnabled = process.env.OMNIRUSH_EVAL_DAYTONA === "1";
const configuredDen = Boolean(process.env.OMNIRUSH_EVAL_DEN_API_URL?.trim());
const localServicesRequired = !daytonaEnabled && !configuredDen;
const mysqlOpen = await localMysqlIsRunning();
const redisOpen = await localRedisIsRunning();
const runnable = e2eTestsEnabled && (!localServicesRequired || (mysqlOpen && redisOpen));
const skipSuffix = !e2eTestsEnabled
? " skipped — needs: set OMNIRUSH_EVAL_E2E_TESTS=1"
: localServicesRequired && !mysqlOpen
? " skipped — needs MySQL on 127.0.0.1:3306"
: localServicesRequired && !redisOpen
? " skipped — needs Redis on 127.0.0.1:6379"
: "";
// TanStack Query used to garbage-collect the zero-observer todo cache entry
// 15s after the first todowrite, which hid the panel mid-run. Sample well
// past that window.
const gcWindowMs = 15_000;
const observeForMs = 22_000;
const sampleIntervalMs = 500;
interface PanelFact {
currentSessionId: string;
found: boolean;
visible: boolean;
completed: number;
total: number;
label: string;
}
interface SessionFacts {
sessionId: string;
runningBash: boolean;
todoCount: number;
finalReplyVisible: boolean;
idle: boolean;
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function parsePanelFact(value: unknown): PanelFact {
if (!isRecord(value)) throw new Error(`Invalid panel fact: ${JSON.stringify(value)}`);
return {
currentSessionId: typeof value.currentSessionId === "string" ? value.currentSessionId : "",
found: value.found === true,
visible: value.visible === true,
completed: typeof value.completed === "number" ? value.completed : -1,
total: typeof value.total === "number" ? value.total : -1,
label: typeof value.label === "string" ? value.label : "",
};
}
function parseSessionFacts(value: unknown): SessionFacts {
if (!isRecord(value) || typeof value.sessionId !== "string") {
throw new Error(`Invalid session facts: ${JSON.stringify(value)}`);
}
return {
sessionId: value.sessionId,
runningBash: value.runningBash === true,
todoCount: typeof value.todoCount === "number" ? value.todoCount : 0,
finalReplyVisible: value.finalReplyVisible === true,
idle: value.idle === true,
};
}
async function configureWorkspace(appSurface: App, workspaceId: string, baseUrl: string): Promise<void> {
const result = await evalIn(appSurface, browserScript(async (workspaceId, providerId, modelName, value, modelId, inputModelName, inputWorkspaceId, inputProviderId, inputModelId, inputValue) => {
const info = await window.__OMNIRUSH_ELECTRON__?.invokeDesktop?.("omnirushServerInfo");
if (!info?.running || !info.baseUrl) return "local_server_unavailable";
const root = String(info.baseUrl).replace(/\/+$/, "");
const headers = {
Authorization: "Bearer " + String(info.ownerToken ?? info.clientToken ?? ""),
"Content-Type": "application/json",
};
const configured = await fetch(root + "/workspace/" + encodeURIComponent(workspaceId) + "/config", {
method: "PATCH",
headers,
body: JSON.stringify({
opencode: {
permission: { bash: "allow", todowrite: "allow" },
provider: {
[providerId]: {
npm: "@ai-sdk/openai-compatible",
name: modelName,
options: { baseURL: value, apiKey: "sk-todo-progress" },
models: {
[modelId]: { name: inputModelName, tool_call: true },
},
},
},
},
}),
signal: AbortSignal.timeout(30000),
});
if (!configured.ok) return "config:" + configured.status + ":" + (await configured.text()).slice(0, 300);
const reloaded = await fetch(root + "/workspace/" + encodeURIComponent(inputWorkspaceId) + "/engine/reload", {
method: "POST",
headers,
signal: AbortSignal.timeout(60000),
});
if (!reloaded.ok) return "reload:" + reloaded.status + ":" + (await reloaded.text()).slice(0, 300);
const raw = localStorage.getItem("omnirush.preferences");
let preferences: Record<string, unknown> = {};
try { preferences = raw ? JSON.parse(raw) : {}; } catch { preferences = {}; }
if (!preferences || typeof preferences !== "object" || Array.isArray(preferences)) preferences = {};
localStorage.setItem("omnirush.preferences", JSON.stringify({
...preferences,
defaultModel: { providerID: inputProviderId, modelID: inputModelId },
modelVariant: null,
providerStepCompleted: true,
}));
localStorage.setItem("omnirush.defaultModel", inputValue);
return "ok";
}, [workspaceId, providerId, modelName, `${baseUrl}/v1`, modelId, modelName, workspaceId, providerId, modelId, `${providerId}/${modelId}`]), { awaitPromise: true, timeoutMs: 120_000 });
expect(result).toBe("ok");
await evalIn(appSurface, () => { location.reload(); return true; });
await waitFor(appSurface, () => (Boolean(window.__omnirushControl)), {
timeoutMs: 60_000,
label: "desktop restored after mock provider configuration",
});
}
async function createSession(appSurface: App): Promise<string> {
const deadline = Date.now() + 60_000;
let lastError: unknown = null;
while (Date.now() < deadline) {
try {
const created = await control(appSurface, "session.create_task", undefined, { timeoutMs: 30_000 });
if (typeof created === "string" && created.startsWith("ses_")) return created;
lastError = new Error(`session.create_task returned ${JSON.stringify(created)}`);
} catch (error) {
lastError = error;
}
await new Promise((resolve) => setTimeout(resolve, 500));
}
throw new Error(`session.create_task did not return a session id: ${lastError instanceof Error ? lastError.message : String(lastError)}`);
}
async function approvePendingPermission(appSurface: App, workspaceId: string, sessionId: string): Promise<number> {
const value = await evalIn(appSurface, browserScript(async (workspaceId, inputSessionId) => {
const info = await window.__OMNIRUSH_ELECTRON__?.invokeDesktop?.("omnirushServerInfo");
if (!info?.running || !info.baseUrl) return [];
const root = String(info.baseUrl).replace(/\/+$/, "")
+ "/workspace/" + encodeURIComponent(workspaceId) + "/opencode";
const headers = {
Authorization: "Bearer " + String(info.ownerToken ?? info.clientToken ?? ""),
"Content-Type": "application/json",
};
const sessionId = inputSessionId;
const pending = await fetch(root + "/api/session/" + encodeURIComponent(sessionId) + "/permission", {
headers,
signal: AbortSignal.timeout(10000),
});
if (!pending.ok) return [];
const requests = await pending.json();
const statuses = [];
for (const request of Array.isArray(requests) ? requests : []) {
if (typeof request?.id !== "string") continue;
const response = await fetch(
root + "/api/session/" + encodeURIComponent(sessionId) + "/permission/" + encodeURIComponent(request.id) + "/reply",
{ method: "POST", headers, body: JSON.stringify({ reply: "once" }), signal: AbortSignal.timeout(10000) },
);
statuses.push(response.status);
}
return statuses;
}, [workspaceId, sessionId]), { awaitPromise: true, timeoutMs: 30_000 });
if (!Array.isArray(value) || value.some((status) => typeof status !== "number" || status < 200 || status >= 300)) {
throw new Error(`Permission approval failed: ${JSON.stringify(value)}`);
}
return value.length;
}
async function readSessionFacts(
appSurface: App,
workspaceId: string,
sessionId: string,
command: string,
completionMarker: string,
): Promise<SessionFacts> {
const value = await evalIn(appSurface, browserScript(async (workspaceId, inputSessionId, inputCommand, completionMarker, inputSessionId2, inputSessionId3) => {
const empty = { sessionId: "", runningBash: false, todoCount: 0, finalReplyVisible: false, idle: false };
const info = await window.__OMNIRUSH_ELECTRON__?.invokeDesktop?.("omnirushServerInfo");
if (!info?.running || !info.baseUrl) return empty;
const root = String(info.baseUrl).replace(/\/+$/, "") + "/workspace/" + encodeURIComponent(workspaceId)
+ "/opencode/session";
const base = root + "/" + encodeURIComponent(inputSessionId);
const options = {
headers: { Authorization: "Bearer " + String(info.ownerToken ?? info.clientToken ?? "") },
signal: AbortSignal.timeout(15000),
};
const [messagesResponse, todosResponse, statusResponse] = await Promise.all([
fetch(base + "/message?limit=50", options),
fetch(base + "/todo", options),
fetch(root + "/status", options),
]);
if (!messagesResponse.ok || !todosResponse.ok || !statusResponse.ok) return empty;
const [messages, todos, statuses] = await Promise.all([messagesResponse.json(), todosResponse.json(), statusResponse.json()]);
const list = Array.isArray(messages) ? messages : [];
const parts = list.flatMap((message) => Array.isArray(message?.parts) ? message.parts : []);
const runningBash = parts.some((part) => part?.tool === "bash"
&& part?.state?.status === "running"
&& part?.state?.input?.command === inputCommand);
const finalReplyVisible = list.some((message) => message?.info?.role === "assistant"
&& (Array.isArray(message.parts) ? message.parts : []).some((part: { type?: string; text?: string }) => part?.type === "text"
&& typeof part.text === "string" && part.text.includes(completionMarker)));
const status = statuses?.[inputSessionId2];
return {
sessionId: inputSessionId3,
runningBash,
todoCount: Array.isArray(todos) ? todos.length : 0,
finalReplyVisible,
idle: !status || status.type === "idle",
};
}, [workspaceId, sessionId, command, completionMarker, sessionId, sessionId]), { awaitPromise: true, timeoutMs: 20_000 });
return parseSessionFacts(value);
}
async function expandTodoPanel(appSurface: App, sessionId: string, expectedItems: string[]): Promise<void> {
const clicked = await evalIn(appSurface, browserScript((value) => {
const surface = document.querySelector<HTMLElement>(value);
const button = surface?.querySelector<HTMLElement>("[data-todo-progress-panel] button");
if (!(button instanceof HTMLElement)) return false;
button.click();
return true;
}, [`[data-session-surface-id="${sessionId}"]`]));
expect(clicked, "todo panel toggle button present").toBe(true);
await waitFor(appSurface, browserScript((value, expectedItems) => {
const panel = document.querySelector<HTMLElement>(value);
const text = panel instanceof HTMLElement ? panel.innerText : "";
return expectedItems.every((item) => text.includes(item));
}, [`[data-session-surface-id="${sessionId}"] [data-todo-progress-panel]`, expectedItems]), { timeoutMs: 10_000, label: "todo panel expanded with every item listed" });
}
async function readTodoPanel(appSurface: App, sessionId: string): Promise<PanelFact> {
const value = await evalIn(appSurface, browserScript((value) => {
const currentSessionId = document.querySelector<HTMLElement>("[data-session-surface-id]")?.getAttribute("data-session-surface-id") ?? "";
const surface = document.querySelector<HTMLElement>(value);
if (!(surface instanceof HTMLElement)) return { currentSessionId, found: false, visible: false, completed: -1, total: -1, label: "" };
const panel = surface.querySelector<HTMLElement>("[data-todo-progress-panel]");
if (!(panel instanceof HTMLElement)) return { currentSessionId, found: false, visible: false, completed: -1, total: -1, label: "" };
const style = getComputedStyle(panel);
const rect = panel.getBoundingClientRect();
const visible = panel.isConnected
&& rect.width > 0
&& rect.height > 0
&& style.display !== "none"
&& style.visibility !== "hidden"
&& style.opacity !== "0";
return {
currentSessionId,
found: true,
visible,
completed: Number(panel.getAttribute("data-todo-progress-completed")),
total: Number(panel.getAttribute("data-todo-progress-total")),
label: panel.querySelector("button")?.innerText ?? "",
};
}, [`[data-session-surface-id="${sessionId}"]`]));
return parsePanelFact(value);
}
test.skipIf(!runnable)(
`the todo progress panel stays above the composer for the whole run${skipSuffix}`,
{ timeout: 10 * 60_000 },
async ({ evidence, place }) => {
needs({ optIn: ["OMNIRUSH_EVAL_E2E_TESTS"] });
const runId = `${Date.now().toString(36)}-${process.pid}`;
const promptMarker = `TODO-PROGRESS-${runId}`;
const completionMarker = `DONE-${promptMarker}`;
const holdSeconds = Math.ceil((observeForMs + 15_000) / 1000);
const command = `sleep ${holdSeconds} && printf '%s\\n' '${completionMarker}'`;
const todos = [
{ id: "todo-1", content: `Plan the work for ${promptMarker}`, status: "completed", priority: "high" },
{ id: "todo-2", content: `Run the long step for ${promptMarker}`, status: "in_progress", priority: "high" },
{ id: "todo-3", content: `Report back for ${promptMarker}`, status: "pending", priority: "medium" },
];
await using den = await server({
place,
mocks: {
agent: mcpMock({
agentWorkloads: [{
promptMarker,
finalReply: completionMarker,
steps: [
{ tool: "todowrite", arguments: { todos } },
{ tool: "bash", arguments: { command, timeout: 120_000, description: `Hold the run — ${promptMarker}` } },
],
}],
}),
},
org: {
name: "Todo Progress",
admin: { name: "Todo Admin" },
members: { member: { name: "Todo Member" } },
},
});
await using desktopApp = await app({ den, as: "member", place });
const workspace = await createAndSelectWorkspace(desktopApp, {
path: `/tmp/omnirush-todo-progress-${runId}`,
});
await configureWorkspace(desktopApp, workspace.workspaceId, den.mocks.agent.url);
const chat = await createSession(desktopApp);
const selected = await selectModel(desktopApp, modelId);
expect(selected.id).toBe(modelId);
const beforeSend = await readTodoPanel(desktopApp, chat);
expect(beforeSend.found, "no todo panel before the agent writes todos").toBe(false);
await writeComposerText(desktopApp, `Run the deterministic plan identified by ${promptMarker}.`);
await control(desktopApp, "composer.send", undefined, { timeoutMs: 120_000 });
const appeared = await eventually(async () => {
await approvePendingPermission(desktopApp, workspace.workspaceId, chat);
const panel = await readTodoPanel(desktopApp, chat);
const facts = await readSessionFacts(desktopApp, workspace.workspaceId, chat, command, completionMarker);
return { panel, facts };
}, {
within: 120_000,
intervalMs: 500,
label: "todo panel visible while the held bash tool runs",
until: ({ panel, facts }) => panel.currentSessionId === chat
&& panel.found
&& panel.visible
&& panel.total === todos.length
&& facts.runningBash,
});
expect(appeared.panel.completed).toBe(1);
expect(appeared.panel.total).toBe(todos.length);
expect(appeared.panel.label).toContain(`1/${todos.length}`);
expect(appeared.facts.todoCount).toBe(todos.length);
await expandTodoPanel(desktopApp, chat, todos.map((todo) => todo.content));
const midRunShot = await screenshot(desktopApp);
const midRunValidation = await validate(midRunShot, [
"A chat session is open with a message composer at the bottom",
"A Progress panel above the composer lists three todo items",
"Exactly one todo item is shown as completed (checked) and the other two are not completed",
"One todo item is shown as in progress and one as pending",
"The agent is visibly still working, e.g. a running bash tool or Thinking indicator",
"No error, sign-in, or crash screen is visible",
]);
expect(midRunValidation.ok, midRunValidation.why).toBe(true);
// Sample continuously past the old 15s GC window while the run is still
// busy. Every sample must show the panel with unchanged counts; the run
// must still be holding so a disappearance cannot be explained by
// completion.
const startedAt = Date.now();
const samples: Array<{ elapsedMs: number; panel: PanelFact }> = [];
while (Date.now() - startedAt < observeForMs) {
const panel = await readTodoPanel(desktopApp, chat);
samples.push({ elapsedMs: Date.now() - startedAt, panel });
await new Promise((resolve) => setTimeout(resolve, sampleIntervalMs));
}
const stillHolding = await readSessionFacts(desktopApp, workspace.workspaceId, chat, command, completionMarker);
expect(stillHolding.runningBash, "the held bash tool must still be running after the observation window").toBe(true);
const missing = samples.filter(({ panel }) => !(panel.found && panel.visible && panel.completed === 1 && panel.total === todos.length));
const lastSample = samples[samples.length - 1];
expect(lastSample?.elapsedMs ?? 0).toBeGreaterThan(gcWindowMs);
expect(missing, `todo panel disappeared or changed at ${JSON.stringify(missing.map((sample) => ({ at: sample.elapsedMs, ...sample.panel })))}`).toEqual([]);
evidence.recordAssertionEvidence(
"The todo progress panel does not disappear during a running turn",
`Sampled the panel ${samples.length} times over ${lastSample?.elapsedMs ?? 0}ms (past the ${gcWindowMs}ms GC window) while bash was still running; every sample showed a visible panel at 1/${todos.length}.`,
true,
);
const completed = await eventually(async () => {
const facts = await readSessionFacts(desktopApp, workspace.workspaceId, chat, command, completionMarker);
const panel = await readTodoPanel(desktopApp, chat);
return { facts, panel };
}, {
within: 120_000,
intervalMs: 500,
label: "agent finishes with its final reply and the todo panel still shown",
until: ({ facts }) => !facts.runningBash && facts.finalReplyVisible && facts.idle,
});
expect(completed.panel.found, "todo panel remains after the run finishes").toBe(true);
expect(completed.panel.visible).toBe(true);
expect(completed.panel.total).toBe(todos.length);
await waitFor(desktopApp, browserScript((value) => {
const surface = document.querySelector<HTMLElement>(value);
return surface instanceof HTMLElement && !surface.innerText.includes("Running command");
}, [`[data-session-surface-id="${chat}"]`]), { timeoutMs: 30_000, label: "no tool still rendered as running after the final reply" });
const afterRunShot = await screenshot(desktopApp);
const afterRunValidation = await validate(afterRunShot, [
"A Progress panel above the composer still lists three todo items after the agent finished",
"Exactly one todo item is shown as completed and the other two are not completed",
"The agent's final reply is visible in the chat and no tool is still running",
]);
expect(afterRunValidation.ok, afterRunValidation.why).toBe(true);
},
);