|
| 1 | +// DEV-ONLY preview harness for tool cards. Not part of the prod bundle — vite's |
| 2 | +// build input is pinned to index.html, so this page exists only under |
| 3 | +// `vite dev` (served at /preview-toolcards.html) for visual iteration. |
| 4 | +// |
| 5 | +// Renders one card per render intent so the three layouts can be compared side |
| 6 | +// by side without running an agent. |
| 7 | + |
| 8 | +import type { JSX } from 'react'; |
| 9 | +import { createRoot } from 'react-dom/client'; |
| 10 | +import { presentToolCall } from '@deepcode/core/dist/tools/presentation.js'; |
| 11 | +import { ToolBody } from './components/ToolBody.js'; |
| 12 | +import { ToolCard } from './components/ToolCard.js'; |
| 13 | +import './index.css'; |
| 14 | + |
| 15 | +const CALLS: Array<{ |
| 16 | + name: string; |
| 17 | + input: Record<string, unknown>; |
| 18 | + result?: string; |
| 19 | + status: 'ok' | 'err' | 'running'; |
| 20 | +}> = [ |
| 21 | + { |
| 22 | + name: 'Edit', |
| 23 | + input: { |
| 24 | + file_path: 'packages/core/src/tools/bash.ts', |
| 25 | + old_string: |
| 26 | + 'const MAX_OUTPUT_BYTES = 30_000;\n\nfunction capStream(s: string, label: string): string {\n return s.slice(0, MAX_OUTPUT_BYTES);\n}', |
| 27 | + new_string: |
| 28 | + 'const CAPTURE_HEAD_CHARS = 1_000_000;\nconst CAPTURE_TAIL_CHARS = 3_000_000;\n\nfunction newCapture(): BoundedCapture {\n return new BoundedCapture(CAPTURE_HEAD_CHARS, CAPTURE_TAIL_CHARS);\n}', |
| 29 | + }, |
| 30 | + result: 'Edited packages/core/src/tools/bash.ts', |
| 31 | + status: 'ok', |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'Write', |
| 35 | + input: { |
| 36 | + file_path: 'packages/core/src/spill/types.ts', |
| 37 | + content: |
| 38 | + 'export interface SpillRef {\n locator: string;\n bytes: number;\n retrievalHint: string;\n}', |
| 39 | + }, |
| 40 | + result: 'Wrote 5 lines', |
| 41 | + status: 'ok', |
| 42 | + }, |
| 43 | + { |
| 44 | + name: 'Bash', |
| 45 | + input: { command: 'pnpm --filter @deepcode/core test -- src/spill' }, |
| 46 | + result: |
| 47 | + '<stdout>\n RUN v4.1.10\n\n Test Files 2 passed (2)\n Tests 19 passed (19)\n</stdout>\nexit: 0', |
| 48 | + status: 'ok', |
| 49 | + }, |
| 50 | + { |
| 51 | + name: 'Bash', |
| 52 | + input: { command: 'cargo test --manifest-path apps/desktop/src-tauri/Cargo.toml' }, |
| 53 | + result: '<stderr>\nerror: could not compile `deepcode-desktop`\n</stderr>\nexit: 101', |
| 54 | + status: 'err', |
| 55 | + }, |
| 56 | + { |
| 57 | + name: 'Grep', |
| 58 | + input: { pattern: 'applySpillPolicy', path: 'packages/core/src' }, |
| 59 | + result: |
| 60 | + 'packages/core/src/agent.ts:16\npackages/core/src/spill/policy.ts:71\npackages/core/src/index.ts:213', |
| 61 | + status: 'ok', |
| 62 | + }, |
| 63 | + { |
| 64 | + name: 'Bash', |
| 65 | + input: { command: 'pnpm build' }, |
| 66 | + status: 'running', |
| 67 | + }, |
| 68 | +]; |
| 69 | + |
| 70 | +function Preview(): JSX.Element { |
| 71 | + return ( |
| 72 | + <div style={{ padding: 24, maxWidth: 860, margin: '0 auto' }}> |
| 73 | + <h2 style={{ font: '600 15px/1.4 system-ui', color: 'var(--text-1)', marginBottom: 16 }}> |
| 74 | + Tool cards by render intent |
| 75 | + </h2> |
| 76 | + {CALLS.map((call, i) => { |
| 77 | + const presentation = presentToolCall(call.name, call.input); |
| 78 | + return ( |
| 79 | + <div key={i} style={{ marginBottom: 14 }}> |
| 80 | + <div style={{ font: '11px/1.6 system-ui', color: 'var(--text-3)', marginBottom: 4 }}> |
| 81 | + {call.name} → {presentation.kind} |
| 82 | + </div> |
| 83 | + <ToolCard |
| 84 | + name={call.name} |
| 85 | + target={presentation.kind === 'terminal' ? undefined : presentation.target} |
| 86 | + layout={presentation.kind} |
| 87 | + status={{ |
| 88 | + kind: call.status === 'running' ? 'info' : call.status === 'ok' ? 'ok' : 'err', |
| 89 | + label: |
| 90 | + call.status === 'running' |
| 91 | + ? '… running' |
| 92 | + : call.status === 'ok' |
| 93 | + ? '✓ done' |
| 94 | + : '✕ error', |
| 95 | + }} |
| 96 | + body={<ToolBody presentation={presentation} resultText={call.result} />} |
| 97 | + /> |
| 98 | + </div> |
| 99 | + ); |
| 100 | + })} |
| 101 | + </div> |
| 102 | + ); |
| 103 | +} |
| 104 | + |
| 105 | +createRoot(document.getElementById('root') as HTMLElement).render(<Preview />); |
0 commit comments