An open-source, faster Devin alternative
TypeScript
web: approvals in words and in full (the command, diff, plan or arguments they would run)
Igor Zalutski via Computerc90fb0f334cc
diff --git a/web/src/managed-agents/computer-sessions/ask-detail.tsx b/web/src/managed-agents/computer-sessions/ask-detail.tsxnew file mode 100644index 00000000..05e0f56e--- /dev/null+++ b/web/src/managed-agents/computer-sessions/ask-detail.tsx@@ -0,0 +1,150 @@+import type { ReactNode } from 'react'+import { cn } from '@/lib/utils'+import { AgentMarkdown } from '../AgentMarkdown'+import type { Ask } from '../computer-sessions-api'+import { mcpName, str, type Input } from './ask-line'++// What an approval asks to run, read from its payload: `approval.input` is+// the tool's own input (Claude Code's or Codex's), so each known tool is+// shown the way a person checks it before allowing it, and anything else as+// its arguments.++/** The label over the detail: the tool, then where it acts. */+function head(ask: Ask): { tool: string; target: string | null } {+ const a = ask.approval!+ const input = (a.input ?? {}) as Input+ const mcp = mcpName(a.toolName)+ switch (a.toolName) {+ case 'Bash':+ return { tool: 'Command', target: str(input.cwd) }+ case 'Edit':+ case 'MultiEdit':+ return { tool: 'Edit', target: str(input.file_path) }+ case 'NotebookEdit':+ return { tool: 'Edit', target: str(input.notebook_path) }+ case 'Write':+ return { tool: 'Write', target: str(input.file_path) }+ case 'ExitPlanMode':+ return { tool: 'Plan', target: null }+ }+ if (mcp) return { tool: mcp.tool, target: mcp.server }+ return { tool: a.toolName, target: null }+}++function Block({+ children,+ className,+}: {+ children: ReactNode+ className?: string+}) {+ return (+ <pre+ className={cn(+ 'bg-muted max-h-60 overflow-auto rounded-lg px-3 py-2 font-mono text-xs leading-5 break-words whitespace-pre-wrap [font-variant-ligatures:none]',+ className,+ )}+ >+ {children}+ </pre>+ )+}++function Diff({ lines }: { lines: string[] }) {+ return (+ <Block className="px-0">+ {lines.map((l, i) => (+ <span+ key={i}+ className={cn(+ 'block px-3',+ l.startsWith('+') &&+ 'bg-status-running-bg/70 text-status-running dark:bg-status-running-bg/40',+ l.startsWith('-') &&+ 'bg-status-error-bg/70 text-status-error dark:bg-status-error-bg/40',+ )}+ >+ {l || ' '}+ </span>+ ))}+ </Block>+ )+}++const lines = (s: string, mark: string) =>+ s ? s.split('\n').map((l) => mark + l) : []++function body(ask: Ask): ReactNode {+ const a = ask.approval!+ const input = (a.input ?? {}) as Input+ switch (a.toolName) {+ case 'Bash':+ return <Block>{str(input.command) ?? ''}</Block>+ case 'Edit':+ if (str(input.diff)) return <Diff lines={str(input.diff)!.split('\n')} />+ return (+ <Diff+ lines={[+ ...lines(str(input.old_string) ?? '', '- '),+ ...lines(str(input.new_string) ?? '', '+ '),+ ]}+ />+ )+ case 'MultiEdit': {+ const edits = Array.isArray(input.edits) ? (input.edits as Input[]) : []+ return (+ <Diff+ lines={edits.flatMap((e, i) => [+ ...(i ? [' ⋯'] : []),+ ...lines(str(e.old_string) ?? '', '- '),+ ...lines(str(e.new_string) ?? '', '+ '),+ ])}+ />+ )+ }+ case 'NotebookEdit':+ return <Block>{str(input.new_source) ?? ''}</Block>+ case 'Write':+ return <Block>{str(input.content) ?? ''}</Block>+ case 'ExitPlanMode':+ return (+ <div className="bg-muted max-h-72 overflow-auto rounded-lg px-4 py-3">+ <AgentMarkdown>{str(input.plan) ?? ''}</AgentMarkdown>+ </div>+ )+ }+ const entries = Object.entries(input)+ if (!entries.length) return null+ // Arguments as name and value; a value that is not text is shown as JSON.+ return (+ <Block className="grid grid-cols-[max-content_1fr] gap-x-4">+ {entries.map(([k, v]) => (+ <span key={k} className="contents">+ <span className="text-muted-foreground">{k}</span>+ <span>{typeof v === 'string' ? v : JSON.stringify(v, null, 2)}</span>+ </span>+ ))}+ </Block>+ )+}++/** The call an approval would make: what runs and where, in full. */+export function ApprovalDetail({ ask }: { ask: Ask }) {+ if (!ask.approval) return null+ const { tool, target } = head(ask)+ return (+ <div className="space-y-2">+ <p className="flex min-w-0 items-baseline gap-2 text-xs">+ <span className="text-muted-foreground shrink-0 font-medium">+ {tool}+ </span>+ {target ? (+ <span className="truncate font-mono" title={target}>+ {target}+ </span>+ ) : null}+ </p>+ {body(ask)}+ </div>+ )+}diff --git a/web/src/managed-agents/computer-sessions/ask-line.ts b/web/src/managed-agents/computer-sessions/ask-line.tsnew file mode 100644index 00000000..676aa936--- /dev/null+++ b/web/src/managed-agents/computer-sessions/ask-line.ts@@ -0,0 +1,84 @@+import type { Ask } from '../computer-sessions-api'++// An approval in words, read from its payload: `approval.input` is the tool's+// own input (Claude Code's or Codex's), `approval.title` Claude Code's+// permission title or "Claude wants to use X".++export type Input = Record<string, unknown>++export const str = (v: unknown) => (typeof v === 'string' ? v : null)++/** `mcp__server__tool` as its server and tool. */+export function mcpName(name: string) {+ const m = name.match(/^mcp__(.+?)__(.+)$/)+ return m ? { server: m[1], tool: m[2] } : null+}++export const basename = (p: string) => p.split('/').filter(Boolean).pop() ?? p++// Lines that set up a script rather than say what it runs.+const SETUP =+ /^(#|set\s|export\s|for\s|while\s|if\s|do$|then$|done|fi$|else$|\}|\{$|[A-Z_][A-Z0-9_]*=\S*$)/++/** The command's program, and its subcommand when it reads as one: "git push", "psql". */+function program(command: string) {+ const line = command+ .split('\n')+ .map((l) =>+ l+ .trim()+ .replace(/^(cd\s+\S+\s*(&&|;)\s*)+/, '')+ .replace(/^((sudo|env|time|nohup|exec)\s+)+/, '')+ .replace(/^([A-Z_][A-Z0-9_]*=\S+\s+)+/, ''),+ )+ .find((l) => l && !SETUP.test(l))+ if (!line) return null+ const [cmd, sub] = line.split(/\s+/)+ const name = basename(cmd)+ return sub && /^[a-z][a-z0-9:-]*$/.test(sub) ? `${name} ${sub}` : name+}++export const isPlan = (ask: Ask) => ask.approval?.toolName === 'ExitPlanMode'++/**+ * The approval in one line, a headline: the agent's own description of a+ * command when it gave one, else what the call does ("Run git push", "Edit+ * Billing.tsx"), else its title without the "Claude wants to" preamble.+ */+export function approvalLine(ask: Ask): string {+ const a = ask.approval+ if (!a) return 'Approve a tool call'+ const input = (a.input ?? {}) as Input+ const title = a.title?.trim() ?? ''+ const plain = title.replace(/^Claude wants to\s+/i, '')+ const own = title && plain === title ? title : null+ switch (a.toolName) {+ case 'Bash': {+ const desc = str(input.description)+ if (desc) return desc+ const prog = program(str(input.command) ?? '')+ return prog ? `Run ${prog}` : 'Run a command'+ }+ case 'Edit':+ case 'MultiEdit':+ case 'NotebookEdit': {+ const p = str(input.file_path) ?? str(input.notebook_path)+ return p ? `Edit ${basename(p)}` : 'Edit a file'+ }+ case 'Write': {+ const p = str(input.file_path)+ return p ? `Write ${basename(p)}` : 'Write a file'+ }+ case 'ExitPlanMode':+ return 'Review the plan'+ }+ if (own) return own+ if (plain && !/^use\s/i.test(plain))+ return plain[0].toUpperCase() + plain.slice(1)+ const mcp = mcpName(a.toolName)+ if (mcp) {+ const words = mcp.tool.replace(/_/g, ' ')+ return `${words[0].toUpperCase()}${words.slice(1)} · ${mcp.server}`+ }+ return `Use ${a.toolName}`+}diff --git a/web/src/managed-agents/computer-sessions/state.ts b/web/src/managed-agents/computer-sessions/state.tsindex 8c6da0d0..c4be37ac 100644--- a/web/src/managed-agents/computer-sessions/state.ts+++ b/web/src/managed-agents/computer-sessions/state.ts@@ -7,6 +7,7 @@ import {type ListSessionsQuery,type Session,} from '../computer-sessions-api'+import { approvalLine, isPlan } from './ask-line'export const NEEDS_YOU: ListSessionsQuery = { status: 'waiting', limit: 50 }export const WORKING: ListSessionsQuery = {@@ -33,8 +34,14 @@ export function statusLabel(status: string) {}export function askTitle(ask: Ask): string {- if (ask.kind === 'approval')- return `Approve ${ask.approval?.title || ask.approval?.toolName || 'a tool call'}`+ if (ask.kind === 'approval') {+ if (isPlan(ask)) return 'Has a plan to review'+ const line = approvalLine(ask)+ const lower = /^[A-Z][a-z]/.test(line)+ ? line[0].toLowerCase() + line.slice(1)+ : line+ return `Wants to ${lower}`+ }if (ask.kind === 'question') {const q = ask.question?.questions[0]return q?.text || q?.header || 'Has a question'