An open-source, faster Devin alternative
TypeScript
computer: short connect code, command on one line (work 082)
Igor Zalutski via Computer7826caacc9b0
diff --git a/cloudflare-workers/api-edge/src/index.test.ts b/cloudflare-workers/api-edge/src/index.test.tsindex 3bd41394..7efa5a14 100644--- a/cloudflare-workers/api-edge/src/index.test.ts+++ b/cloudflare-workers/api-edge/src/index.test.ts@@ -646,7 +646,7 @@ describe("/api/managed-agents/computer/agent/connect — public CLI connect", ()});const url = "https://app.opencomputer.dev/api/managed-agents/computer/agent/connect";- const code = "occ_b3JnX3Rlc3Q.0123456789abcdefghijkl";+ const code = "oc_7KQM2XP94HTRWN3F";const target = { ...env, MANAGED_AGENTS_API_URL: "https://managedagents.test" };const stub = (upstream: Response) => {const fetchSpy = vi.fn(@@ -713,6 +713,21 @@ describe("/api/managed-agents/computer/agent/connect — public CLI connect", ()await expect(resp.json()).resolves.toEqual(refusal);});+ it("accepts a retyped code in lower case", async () => {+ const fetchSpy = stub(Response.json({ connected: true }, { status: 200 }));+ const resp = await worker.fetch(+ new Request(url, {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ code: code.toLowerCase(), provider: "claude", token: "t" }),+ }),+ target,+ ctx,+ );+ expect(resp.status).toBe(200);+ expect(fetchSpy).toHaveBeenCalledTimes(1);+ });+it.each([["GET", undefined, undefined, 405],["PUT", "application/json", JSON.stringify({ code }), 405],@@ -720,7 +735,10 @@ describe("/api/managed-agents/computer/agent/connect — public CLI connect", ()["POST", "application/x-www-form-urlencoded", `code=${code}`, 415],["POST", "application/json", "{not json", 400],["POST", "application/json", JSON.stringify({ provider: "claude" }), 401],- ["POST", "application/json", JSON.stringify({ code: "occ_x" }), 401],+ ["POST", "application/json", JSON.stringify({ code: "occ_b3JnX3Rlc3Q.0123456789abcdefghijkl" }), 401],+ ["POST", "application/json", JSON.stringify({ code: "oc_7KQM2XP94HTRWN3" }), 401],+ ["POST", "application/json", JSON.stringify({ code: "oc_7KQM2XP94HTRWN3F0" }), 401],+ ["POST", "application/json", JSON.stringify({ code: "oc_7KQM2XP94HTRWN3-" }), 401],["POST", "application/json", JSON.stringify({ code: "osb_0123456789abcdefghijkl" }), 401],])("refuses %s %s %s at the edge", async (method, contentType, body, status) => {const fetchSpy = stub(new Response(null, { status: 200 }));diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex 7ea2c668..8106be79 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -6798,7 +6798,7 @@ describe("organization computer (work 052)", () => {});it("mints a connect code and returns only its contract", async () => {- const code = "occ_b3JnX3Rlc3Q.0123456789abcdefghijkl";+ const code = "oc_7KQM2XP94HTRWN3F";const { response, fetchMock } = await call("POST","/computer/agent/connect-code",diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex d866ef3d..ee24621e 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -3234,12 +3234,13 @@ export async function handleComputerSlackWebhook(// Work 082: the backend bounds the body the same way (CODEX_BODY_MAX_BYTES:// twice the 64 KiB auth.json cap, plus room for the code and provider).-export // Blue verifies the subscription with its provider before answering.+// Blue verifies the subscription with its provider before answering.const COMPUTER_AGENT_CONNECT_TIMEOUT_MS = 30_000;-const COMPUTER_AGENT_CONNECT_MAX_BYTES = 2 * 64 * 1024 + 1024;-// `occ_<base64url(accountId)>.<base64url nonce>`; anything else is refused here-// so garbage never reaches the backend.-const CONNECT_CODE = /^occ_[A-Za-z0-9_-]{1,200}\.[A-Za-z0-9_-]{16,200}$/;+export const COMPUTER_AGENT_CONNECT_MAX_BYTES = 2 * 64 * 1024 + 1024;+// `oc_` + 16 Crockford base32 characters (short enough to keep the command+// on one line); anything else is refused here so garbage never reaches the+// backend. Case-insensitive: people retype codes.+const CONNECT_CODE = /^oc_[0-9a-z]{16}$/i;function connectProblem(status: number, code: string, message: string) {return Response.json(diff --git a/web/src/api/mock.ts b/web/src/api/mock.tsindex f67dd454..bcd91727 100644--- a/web/src/api/mock.ts+++ b/web/src/api/mock.ts@@ -1399,7 +1399,7 @@ function previewAgentRequest(path: string, method: string, body: unknown) {}, 6_000)return {// A placeholder in the real shape; it connects nothing.- code: 'occ_cHJldmlldw.preview-code-not-real-0000',+ code: 'oc_PREVIEW00000000',expiresAt: new Date(Date.now() + 10 * 60_000).toISOString(),}}diff --git a/web/src/components/copy-row.tsx b/web/src/components/copy-row.tsxindex 5b2ea805..82b6fb73 100644--- a/web/src/components/copy-row.tsx+++ b/web/src/components/copy-row.tsx@@ -1,4 +1,4 @@-import { useState } from 'react'+import { useState, type ReactNode } from 'react'import { Check, Copy, Eye, EyeOff } from 'lucide-react'import { Button } from '@/components/ui/button'import { useTransientFlag } from '@/lib/use-transient-flag'@@ -24,25 +24,13 @@ export function CopyRow({/** Called once the value is on the clipboard. */onCopy?: () => void}) {- const [copied, markCopied] = useTransientFlag(1500)const [revealed, setRevealed] = useState(!maskable)const shown =maskable && !revealed ? '•'.repeat(Math.min(value.length, 32)) : valueconst displayText = transform ? transform(shown) : shownconst copyText = transform ? transform(value) : value-- const copy = () => {- // Only show "Copied" if the write actually succeeds (clipboard can be- // blocked by permissions / insecure context).- void navigator.clipboard.writeText(copyText).then(- () => {- markCopied()- onCopy?.()- },- (e: unknown) => notifyError("Couldn't copy to clipboard.", e),- )- }+ const [copied, copy] = useCopy(copyText, onCopy)return (<div@@ -69,13 +57,65 @@ export function CopyRow({</Button>) : null}<Button variant="ghost" size="xs" onClick={copy}>- {copied ? (- <Check className="size-3.5" />- ) : (- <Copy className="size-3.5" />- )}- {copied ? 'Copied' : 'Copy'}+ <CopyLabel copied={copied} /></Button></div>)}++/**+ * A command people copy and run, on one line however long: the lead line+ * carries the Copy button so the command gets the row's full width, and a+ * screen too narrow for it scrolls sideways rather than break it mid-word.+ */+export function CopyCommand({+ value,+ lead,+ onCopy,+}: {+ value: string+ /** What to do with it, beside the Copy button. */+ lead: ReactNode+ /** Called once the value is on the clipboard. */+ onCopy?: () => void+}) {+ const [copied, copy] = useCopy(value, onCopy)+ return (+ <div className="space-y-2">+ <div className="flex items-center justify-between gap-2">+ <p>{lead}</p>+ <Button variant="ghost" size="xs" onClick={copy}>+ <CopyLabel copied={copied} />+ </Button>+ </div>+ <code className="bg-panel-2 text-foreground block overflow-x-auto rounded-md border px-3 py-2 font-mono text-[11.5px] whitespace-nowrap [font-variant-ligatures:none]">+ {value}+ </code>+ </div>+ )+}++function CopyLabel({ copied }: { copied: boolean }) {+ return (+ <>+ {copied ? <Check className="size-3.5" /> : <Copy className="size-3.5" />}+ {copied ? 'Copied' : 'Copy'}+ </>+ )+}++/** Copy to the clipboard; "Copied" only once the write succeeds (the+ * clipboard can be blocked by permissions or an insecure context). */+function useCopy(text: string, onCopy?: () => void) {+ const [copied, markCopied] = useTransientFlag(1500)+ const copy = () => {+ void navigator.clipboard.writeText(text).then(+ () => {+ markCopied()+ onCopy?.()+ },+ (e: unknown) => notifyError("Couldn't copy to clipboard.", e),+ )+ }+ return [copied, copy] as const+}diff --git a/web/src/managed-agents/AgentStep.test.tsx b/web/src/managed-agents/AgentStep.test.tsxindex 43f8556b..34ca44da 100644--- a/web/src/managed-agents/AgentStep.test.tsx+++ b/web/src/managed-agents/AgentStep.test.tsx@@ -41,8 +41,8 @@ vi.mock('@/lib/errors', () => notify)const { default: ComputerPage } = await import('./Computer')const TOKEN = `sk-ant-oat01-${'a'.repeat(40)}`-const CODE = 'occ_b3JnX3Rlc3Q.0123456789abcdefghijkl'-const CODE_2 = 'occ_b3JnX3Rlc3Q.mnopqrstuvwxyz012345'+const CODE = 'oc_7KQM2XP94HTRWN3F'+const CODE_2 = 'oc_0J5V8D1ZGB6CY4AE'const inTenMinutes = () => new Date(Date.now() + 10 * 60_000).toISOString()const fresh: ComputerAgent = {choice: null,@@ -392,6 +392,12 @@ describe('choosing the coding agent', () => {expect(command()).toBe(`npx -y @opencomputer/cli model connect claude --code ${CODE}`,)+ // One line, scrolled sideways when narrow, never broken mid-word.+ const row = [...document.body.querySelectorAll('code')].find((c) =>+ c.textContent?.startsWith('npx '),+ )!+ expect(row.className).toContain('whitespace-nowrap')+ expect(row.className).not.toContain('break-all')expect(text()).toContain('Run this in a terminal; it opens Claude to sign in.',)@@ -567,7 +573,7 @@ describe('choosing the coding agent', () => {window.localStorage.setItem('opencomputer.computer.connect-code::',JSON.stringify({- code: 'occ_c3BlbnQ.spent-code-0000000000',+ code: 'oc_SPENT00000000000',expiresAt: inTenMinutes(),mintedAt: Date.parse('2026-10-22T09:59:00Z'),}),@@ -582,7 +588,7 @@ describe('choosing the coding agent', () => {act(() => button('Change')!.click())await settle(() => command() !== undefined, 'command')expect(command()).toContain(CODE)- expect(command()).not.toContain('spent')+ expect(command()).not.toContain('SPENT')expect(computerApi.createConnectCode).toHaveBeenCalledTimes(1)})diff --git a/web/src/managed-agents/AgentStep.tsx b/web/src/managed-agents/AgentStep.tsxindex 89e28311..4c60bcab 100644--- a/web/src/managed-agents/AgentStep.tsx+++ b/web/src/managed-agents/AgentStep.tsx@@ -16,7 +16,7 @@ import {import { Loader2 } from 'lucide-react'import { ApiError } from '@/api/errors'import { ConfirmDialog } from '@/components/confirm-dialog'-import { CopyRow } from '@/components/copy-row'+import { CopyCommand, CopyRow } from '@/components/copy-row'import { Button } from '@/components/ui/button'import {Dialog,@@ -622,22 +622,28 @@ function CommandConnect({</div>)}+ const lead = (+ <>Run this in a terminal; it opens {SIGN_IN_AT[provider]} to sign in.</>+ )return (<div className="bg-muted/60 text-foreground space-y-3 rounded-lg p-4">- <p>Run this in a terminal; it opens {SIGN_IN_AT[provider]} to sign in.</p>{codeValue ? (- <CopyRow+ <CopyCommandvalue={connectCommand(provider, codeValue)}+ lead={lead}onCopy={() => setActedAt(Date.now())}/>) : (- <div- className="bg-panel-2 text-muted-foreground flex items-center gap-2 rounded-md border px-3 py-2 text-[13px]"- aria-busy- >- <Loader2 className="size-3.5 animate-spin" aria-hidden />- Getting your command…- </div>+ <>+ <p>{lead}</p>+ <div+ className="bg-panel-2 text-muted-foreground flex items-center gap-2 rounded-md border px-3 py-2 text-[13px]"+ aria-busy+ >+ <Loader2 className="size-3.5 animate-spin" aria-hidden />+ Getting your command…+ </div>+ </>)}<div className="text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">{connected ? (