An open-source, faster Devin alternative
TypeScript
Drive the agent cards from the computer's harnesses
Igor Zalutski via Computer741c0a1a08b7
diff --git a/cloudflare-workers/api-edge/src/computer.ts b/cloudflare-workers/api-edge/src/computer.tsindex 692f8ee2..5ae65573 100644--- a/cloudflare-workers/api-edge/src/computer.ts+++ b/cloudflare-workers/api-edge/src/computer.ts@@ -46,7 +46,8 @@ export const COMPUTER_ERROR_MESSAGES: Record<string, string> = {"That's not a ChatGPT login. Paste the auth.json that codex login wrote.",computer_connect_code_invalid:"That connect code is not valid. Get a new one from the dashboard.",- computer_codex_unavailable: "Codex isn't available on this computer yet.",+ computer_harness_unavailable:+ "That agent isn't available on this computer yet.",invalid_request: "That choice isn't valid.",};@@ -160,6 +161,18 @@ function publicSubscription(* backend sends none or one that breaks the contract: the dashboard then* skips the agent step rather than guessing.*/+const HARNESS = /^[a-z][a-z0-9-]{0,31}$/;+const MAX_HARNESSES = 16;++/** Known-safe harness names, once each, in blue's order. */+function publicHarnesses(values: unknown[]): string[] {+ const names = values.filter(+ (value): value is string =>+ typeof value === "string" && HARNESS.test(value),+ );+ return [...new Set(names)].slice(0, MAX_HARNESSES);+}+export function publicComputerAgent(value: unknown,): Record<string, unknown> | null {@@ -184,9 +197,12 @@ export function publicComputerAgent(...(linkedSlackUser ? { linkedSlackUser } : {}),subscription,managedModel: agent.managedModel,- // Rollout gate and kill switch (work 082): an older blue that does not- // send it keeps Codex hidden.- codexAvailable: agent.codexAvailable === true,+ // The harnesses this computer can run (work 082): the rollout gate and+ // kill switch. Absent from an older blue, so absent here too, and the+ // web keeps today's Claude-only cards.+ ...(Array.isArray(agent.harnesses)+ ? { harnesses: publicHarnesses(agent.harnesses) }+ : {}),};}@@ -352,6 +368,14 @@ function computerRoute(method: string, suffix: string) {);}+/**+ * Codes whose backend message is written for people and names the agent+ * ("Codex isn't available on this computer yet."): it passes through when+ * it reads as one plain line, else the fixed copy above stands in.+ */+const BACKEND_WORDED_CODES = new Set(["computer_harness_unavailable"]);+const PERSON_READABLE = /^[^\p{Cc}<>]{1,200}$/u;+export const computerFamily: RouteFamily = {owns: (suffix) => COMPUTER_ROUTE.test(suffix),allows: (method, suffix) => computerRoute(method, suffix) !== undefined,@@ -369,10 +393,12 @@ export const computerFamily: RouteFamily = {headers,});},- errorMessage: (code, status, suffix) =>- Object.hasOwn(COMPUTER_ERROR_MESSAGES, code)- ? COMPUTER_ERROR_MESSAGES[code]- : computerFallbackMessage(status, suffix),+ errorMessage: (code, status, suffix, backendMessage) =>+ BACKEND_WORDED_CODES.has(code) && PERSON_READABLE.test(backendMessage)+ ? backendMessage+ : Object.hasOwn(COMPUTER_ERROR_MESSAGES, code)+ ? COMPUTER_ERROR_MESSAGES[code]+ : computerFallbackMessage(status, suffix),};/**diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex 00aad394..6694d4cb 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -6693,7 +6693,7 @@ describe("organization computer (work 052)", () => {setAt: "2026-10-22T10:00:00.000Z",},managedModel: "Claude Opus 5.5",- codexAvailable: false,+ harnesses: ["claude", "codex"],};it("passes the agent block of GET /computer field by field", async () => {@@ -6729,31 +6729,49 @@ describe("organization computer (work 052)", () => {"/computer",Response.json({ ...computerStatus, agent: minimal }),);- // An older blue sends no codexAvailable: Codex stays hidden.+ // An older blue sends no harnesses: none here either, so the web keeps+ // today's Claude-only cards.await expect(response.json()).resolves.toEqual({...computerStatus,- agent: { ...minimal, codexAvailable: false },+ agent: minimal,});});it.each([- [true, true],- [false, false],- ["true", false],- [1, false],- ])("passes codexAvailable %j as %j", async (value, expected) => {+ ["the names blue sends", ["claude", "codex"], ["claude", "codex"]],+ ["none", [], []],+ [+ "only known-safe names, once each",+ ["codex", "Codex", "gemini-2", "<b>", "a".repeat(33), 7, null, "codex"],+ ["codex", "gemini-2"],+ ],+ ["at most 16", Array.from({ length: 20 }, (_, i) => `h${i}`), Array.from({ length: 16 }, (_, i) => `h${i}`)],+ ])("passes harnesses: %s", async (_, value, expected) => {const { response } = await call("GET","/computer",Response.json({...computerStatus,- agent: { ...agent, codexAvailable: value },+ agent: { ...agent, harnesses: value },}),);- const body = (await response.json()) as { agent: { codexAvailable: unknown } };- expect(body.agent.codexAvailable).toBe(expected);+ const body = (await response.json()) as { agent: { harnesses: unknown } };+ expect(body.agent.harnesses).toEqual(expected);});+ it.each([["a string", "claude,codex"], ["null", null], ["an object", { codex: true }]])(+ "omits harnesses that are %s",+ async (_, value) => {+ const { response } = await call(+ "GET",+ "/computer",+ Response.json({ ...computerStatus, agent: { ...agent, harnesses: value } }),+ );+ const body = (await response.json()) as { agent: Record<string, unknown> };+ expect(body.agent).not.toHaveProperty("harnesses");+ },+ );+it.each([["an unknown choice", { ...agent, choice: "gemini" }],["an unknown health", { ...agent, subscription: { ...agent.subscription, health: "great" } }],@@ -6996,7 +7014,6 @@ describe("organization computer (work 052)", () => {[403, "computer_agent_not_member", "You're not a member of this organization's Slack workspace."],[422, "computer_agent_codex_auth", "That's not a ChatGPT login. Paste the auth.json that codex login wrote."],[401, "computer_connect_code_invalid", "That connect code is not valid. Get a new one from the dashboard."],- [409, "computer_codex_unavailable", "Codex isn't available on this computer yet."],])("maps %s %s to fixed copy", async (status, code, message) => {const { response } = await call("PUT",@@ -7010,6 +7027,27 @@ describe("organization computer (work 052)", () => {await expect(response.json()).resolves.toEqual({ error: { code, message } });});+ it.each([+ ["its own words", "Codex isn't available on this computer yet.", "Codex isn't available on this computer yet."],+ ["fallback copy for an empty message", "", "That agent isn't available on this computer yet."],+ ["fallback copy for markup", "<b>Codex</b> is off", "That agent isn't available on this computer yet."],+ ["fallback copy for several lines", "Codex\nstack trace", "That agent isn't available on this computer yet."],+ ["fallback copy for a long message", "x".repeat(201), "That agent isn't available on this computer yet."],+ ])("says an unavailable harness in %s", async (_, upstreamMessage, message) => {+ const { response } = await call(+ "POST",+ "/computer/agent/connect-code",+ Response.json(+ { error: { code: "computer_harness_unavailable", message: upstreamMessage } },+ { status: 409 },+ ),+ );+ expect(response.status).toBe(409);+ await expect(response.json()).resolves.toEqual({+ error: { code: "computer_harness_unavailable", message },+ });+ });+it("tells a bad choice apart from a missing computer", async () => {const { response } = await call("PUT",diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex ee24621e..43b8fd80 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -298,6 +298,7 @@ async function publicErrorResponse(backendCode,upstream.status,suffix,+ backendMessage,): undefined;if (familyMessage) {diff --git a/cloudflare-workers/api-edge/src/route_family.ts b/cloudflare-workers/api-edge/src/route_family.tsindex 593b31ad..184442b2 100644--- a/cloudflare-workers/api-edge/src/route_family.ts+++ b/cloudflare-workers/api-edge/src/route_family.ts@@ -28,6 +28,14 @@ export interface RouteFamily {suffix: string,upstream: Response,): Promise<Response>;- /** Fixed copy for an upstream refusal; no backend detail passes through. */- errorMessage(code: string, status: number, suffix: string): string;+ /**+ * Copy for an upstream refusal: fixed copy, unless the family vouches for+ * a code whose backend message is written for people (`backendMessage`).+ */+ errorMessage(+ code: string,+ status: number,+ suffix: string,+ backendMessage: string,+ ): string;}diff --git a/web/src/api/mock.ts b/web/src/api/mock.tsindex f6b93d78..2fbf623c 100644--- a/web/src/api/mock.ts+++ b/web/src/api/mock.ts@@ -1300,10 +1300,11 @@ let previewBootSince: number | null = null// `?agent=codex` is a connected ChatGPT plan. The one-command connect (work// 082) mints a placeholder code; with `?connect=auto` the preview plays the// person running it: about six seconds later the card's subscription (Codex-// when Codex is chosen, else Claude) is connected. Codex shows as coming-// unless `?codex=available` (or `?agent=codex`) says the computer can run it.+// when Codex is chosen, else Claude) is connected. `?harnesses=claude,codex`+// names the harnesses the computer can run (`?agent=codex` implies both);+// without it the agent names none, as an older backend: Claude only.type PreviewAgent = {- codexAvailable: boolean+ harnesses?: string[]choice: 'claude' | 'codex' | 'credits' | nulllinked: booleanlinkedSlackUser?: { id: string; name: string; teamName: string }@@ -1333,11 +1334,15 @@ function previewAgent(): PreviewAgent | null {: {}),setAt: new Date(BASE).toISOString(),})+ const harnesses =+ new URLSearchParams(window.location.search)+ .get('harnesses')+ ?.split(',')+ .map((name) => name.trim())+ .filter(Boolean) ?? (param === 'codex' ? ['claude', 'codex'] : undefined)const base = {managedModel: 'Claude Opus 5.5',- codexAvailable:- param === 'codex' ||- new URLSearchParams(window.location.search).get('codex') === 'available',+ ...(harnesses ? { harnesses } : {}),}// The seat binds to a Slack user through the install: before it, nobody// is linked and no Slack user is named.diff --git a/web/src/managed-agents/AgentStep.test.tsx b/web/src/managed-agents/AgentStep.test.tsxindex f3f9c9b6..257a7b85 100644--- a/web/src/managed-agents/AgentStep.test.tsx+++ b/web/src/managed-agents/AgentStep.test.tsx@@ -50,8 +50,8 @@ const fresh: ComputerAgent = {subscription: null,managedModel: 'Claude Opus 5.5',}-// The rollout gate: blue says this computer can run Codex.-const withCodex: ComputerAgent = { ...fresh, codexAvailable: true }+// The rollout gate: blue names the harnesses this computer can run.+const withCodex: ComputerAgent = { ...fresh, harnesses: ['claude', 'codex'] }const subscription = (health: NonNullable<ComputerAgent['subscription']>['health'],) => ({ provider: 'claude' as const, health, setAt: '2026-10-22T10:00:00Z' })@@ -641,8 +641,8 @@ describe('choosing the coding agent', () => {describe('where this computer cannot run Codex yet', () => {it.each([- ['an older backend that does not say', fresh],- ['the gate switched off', { ...fresh, codexAvailable: false }],+ ['an older backend that names none', fresh],+ ['a computer that runs Claude only', { ...fresh, harnesses: ['claude'] }],])('only records Codex on %s', async (_, agent: ComputerAgent) => {await show({ ...empty, agent }, 'Choose your coding agent')await settle(() => command() !== undefined, 'claude command')@@ -686,6 +686,23 @@ describe('choosing the coding agent', () => {})})+ it('drives the cards from the harnesses, Claude included', async () => {+ await show(+ { ...empty, agent: { ...fresh, harnesses: ['codex'] } },+ "Claude Code is coming. We'll let you know.",+ )+ expect(computerApi.createConnectCode).not.toHaveBeenCalled()+ expect(button('Or paste a token')).toBeUndefined()+ computerApi.setAgentChoice.mockResolvedValue({+ ...fresh,+ harnesses: ['codex'],+ choice: 'codex',+ })+ act(() => codexCard().click())+ await settle(() => command()?.includes(' codex ') === true, 'codex command')+ expect(text()).not.toContain('is coming')+ })+it('offers Codex on the agent card where this computer can run it', async () => {await show({diff --git a/web/src/managed-agents/AgentStep.tsx b/web/src/managed-agents/AgentStep.tsxindex b0e6d58a..3a98b7a9 100644--- a/web/src/managed-agents/AgentStep.tsx+++ b/web/src/managed-agents/AgentStep.tsx@@ -45,8 +45,10 @@ import {disconnectClaudeSubscription,disconnectCodexSubscription,getComputer,+ isHarnessAvailable,resumeClaudeSubscription,setAgentChoice,+ subscriptionProviderSchema,type AgentChoice,type ComputerAgent,type ComputerConnectCode,@@ -172,8 +174,9 @@ function useAgentCache() {}/**- * The three ways to go: the two cards, the selected card's panel (the paste- * form, or Codex's coming line) and free credits. Step 1 of setup, and the+ * The three ways to go: the two cards, the selected card's panel (its+ * command and, for Claude, the paste form; or the coming line of a harness+ * this computer cannot run yet) and free credits. Step 1 of setup, and the* Change dialog of its done row, where `onDone` closes the dialog once the* server has the change. Free credits replace a connected subscription:* routing decides from the subscription row, so it is disconnected first.@@ -249,11 +252,11 @@ export function AgentSetup({mark={<span className="bg-foreground text-background">◎</span>}/></div>- {selected === 'codex' && !agent.codexAvailable ? (+ {!isHarnessAvailable(agent, selected) ? (// Not rolled out to this computer (or switched off): the card only// records the interest, no code is minted.<p className="bg-muted/60 text-foreground rounded-lg px-4 py-3">- Codex is coming. We'll let you know.+ {PROVIDER_NAME[selected]} is coming. We'll let you know.</p>) : (<SubscriptionConnect@@ -874,13 +877,15 @@ export function AgentManage({const { setAgent, reread } = useAgentCache()const [replacing, setReplacing] = useState(false)const [confirmDisconnect, setConfirmDisconnect] = useState(false)- // Which subscription to connect when there is none.- const codex = agent.codexAvailable === true+ // Which subscription to connect when there is none: only the harnesses+ // this computer can run (the rollout gate), the chosen one first.const [picked, setConnecting] = useState<SubscriptionProvider>(agent.choice === 'codex' ? 'codex' : 'claude',)- // Codex only where this computer can run it (the rollout gate).- const connecting: SubscriptionProvider = codex ? picked : 'claude'+ const available = subscriptionProviderSchema.options.filter((provider) =>+ isHarnessAvailable(agent, provider),+ )+ const connecting = available.includes(picked) ? picked : available[0]const resume = useMutation({mutationFn: resumeClaudeSubscription,onSuccess: async (next) => {@@ -917,19 +922,21 @@ export function AgentManage({</div>)}- const other: SubscriptionProvider =- connecting === 'claude' ? 'codex' : 'claude'+ const others = available.filter((provider) => provider !== connecting)return (<div className="text-muted-foreground space-y-4 text-sm"><p className="text-foreground font-medium">{agentSummary(agent)}</p>{linkedLine}- <SubscriptionConnect- key={connecting}- provider={connecting}- mintOnShow={false}- />- {codex ? (+ {connecting ? (+ <SubscriptionConnect+ key={connecting}+ provider={connecting}+ mintOnShow={false}+ />+ ) : null}+ {others.map((other) => (<Button+ key={other}variant="link"size="sm"className="text-muted-foreground h-auto px-0"@@ -937,7 +944,7 @@ export function AgentManage({>Use {PROVIDER_NAME[other]} instead</Button>- ) : null}+ ))}</div>)}@@ -981,8 +988,8 @@ export function AgentManage({Resume</Button>) : null}- {subscription.provider === 'claude' || codex ? (- // A Codex login switched off by the gate can still be+ {isHarnessAvailable(agent, subscription.provider) ? (+ // A login whose harness the gate switched off can still be// disconnected, not signed in again.<Buttonsize="sm"diff --git a/web/src/managed-agents/computer-api.ts b/web/src/managed-agents/computer-api.tsindex 17b1e02c..9583ab72 100644--- a/web/src/managed-agents/computer-api.ts+++ b/web/src/managed-agents/computer-api.ts@@ -62,10 +62,10 @@ export const computerAgentSchema = z.object({/** The model free credits run, e.g. "Claude Opus 5.5". */managedModel: z.string(),/**- * This computer can run Codex (work 082 rollout gate and kill switch).- * Absent reads as false: Codex stays "coming".+ * The harnesses this computer can run, e.g. ["claude", "codex"] (work 082+ * rollout gate and kill switch). Absent from an older backend: Claude only.*/- codexAvailable: z.boolean().optional(),+ harnesses: z.array(z.string()).optional(),})export const computerStatusSchema = z.object({@@ -243,6 +243,20 @@ export function createConnectCode() {}/** The one command a person runs to connect a subscription with a code. */+/** What an older backend that names no harnesses can run: today's Claude. */+const DEFAULT_HARNESSES: readonly string[] = ['claude']++/**+ * Whether this computer can run a harness; a card for one it cannot shows+ * as coming.+ */+export function isHarnessAvailable(+ agent: Pick<ComputerAgent, 'harnesses'>,+ harness: SubscriptionProvider,+): boolean {+ return (agent.harnesses ?? DEFAULT_HARNESSES).includes(harness)+}+export function connectCommand(provider: SubscriptionProvider, code: string) {return `npx -y @opencomputer/cli model connect ${provider} --code ${code}`}