### Quick start commands for hello-agent Source: https://github.com/hexbee/hello-agent/blob/main/README.md Install dependencies, run type checking and build, execute acceptance probes, and start the desktop app with a DeepSeek API key. The probe command automatically skips e2e tests when DEEPSEEK_API_KEY is not set. ```bash pnpm install pnpm typecheck && pnpm build # 类型检查 + 三端产物 pnpm probe:all # §10 自动化验收探针(无 DEEPSEEK_API_KEY 时 e2e 自动 SKIP) DEEPSEEK_API_KEY=sk-... pnpm dev # 启动桌面应用(模型 deepseek-v4-flash / v4-pro) ``` -------------------------------- ### Install Prompt Input Source: https://github.com/hexbee/hello-agent/blob/main/docs/prompt-input.md Use the shadcn CLI to add the component to your project. ```bash npx shadcn@latest add @beui/prompt-input ``` -------------------------------- ### Install Tool Result component Source: https://github.com/hexbee/hello-agent/blob/main/docs/tool-result.md Use the shadcn CLI to add the component to your project. ```bash npx shadcn@latest add @beui/tool-result ``` -------------------------------- ### Install Message component Source: https://github.com/hexbee/hello-agent/blob/main/docs/message.md Use the shadcn CLI to add the Message component to your project. ```bash npx shadcn@latest add @beui/message ``` -------------------------------- ### Install AI Sidebar Source: https://github.com/hexbee/hello-agent/blob/main/docs/ai-sidebar.md Use the shadcn CLI to add the AI Sidebar component to your project. ```bash npx shadcn@latest add @beui/ai-sidebar ``` -------------------------------- ### Install Approval Card via CLI Source: https://github.com/hexbee/hello-agent/blob/main/docs/approval-card.md Use the shadcn CLI to add the Approval Card component to your project. ```bash npx shadcn@latest add @beui/approval-card ``` -------------------------------- ### Implement AI Sidebar Source: https://github.com/hexbee/hello-agent/blob/main/docs/ai-sidebar.md A complete implementation example showing the resource structure, action menu, and the AISidebar component within an AnimatedSidebarProvider. ```tsx "use client"; import { Clock3, GitPullRequest, LayoutGrid, PanelLeft, Plug, SquarePen, } from "lucide-react"; import { useState } from "react"; import { AnimatedSidebar, AnimatedSidebarContent, AnimatedSidebarGroup, AnimatedSidebarGroupContent, AnimatedSidebarGroupLabel, AnimatedSidebarInset, AnimatedSidebarMenu, AnimatedSidebarMenuButton, AnimatedSidebarMenuItem, AnimatedSidebarProvider, AnimatedSidebarRail, AnimatedSidebarTrigger, } from "@/components/motion/animated-sidebar"; import { AISidebar, type SidebarResource, type SidebarResourceMove, } from "@/components/agents/ai-sidebar"; const resources: SidebarResource[] = [ { id: "design-system", label: "Design system", kind: "project", }, { id: "client-portal", label: "Client portal", kind: "project", }, { id: "marketing-site", label: "Marketing website", kind: "project", }, { id: "platform", label: "Platform", kind: "project", children: [ { id: "api", label: "API migration", kind: "file" }, { id: "billing", label: "Billing states", kind: "file" }, { id: "docs", label: "Read platform docs", kind: "bookmark" }, ], }, { id: "mobile-app", label: "Mobile app", kind: "project", }, { id: "research-lab", label: "Research lab", kind: "folder", }, { id: "agent-workspace", label: "Agent workspace", kind: "project", children: [ { id: "resource-review", label: "Review resource sidebar interaction details", kind: "file", }, { id: "release-offer", label: "Prepare release announcement", kind: "file", }, { id: "haptics", label: "Explore interaction feedback", kind: "bookmark", }, { id: "promotion", label: "Plan launch distribution", kind: "file", }, { id: "motion-research", label: "Research motion implementation patterns", kind: "bookmark", }, ], }, { id: "release-notes", label: "Release notes", kind: "file", }, ]; const actions = [ { label: "New workspace", icon: SquarePen }, { label: "Pull requests", icon: GitPullRequest }, { label: "Sites", icon: LayoutGrid }, { label: "Scheduled", icon: Clock3 }, { label: "Extensions", icon: Plug }, ] as const; function findLabel(items: SidebarResource[], id: string): string | undefined { for (const item of items) { if (item.id === id) return item.label; const child = item.children ? findLabel(item.children, id) : undefined; if (child) return child; } } export function AISidebarPreview() { const [active, setActive] = useState("resource-review"); const [items, setItems] = useState(resources); const activeLabel = findLabel(items, active) ?? active; const move = async (_event: SidebarResourceMove) => { await new Promise((resolve) => window.setTimeout(resolve, 450)); }; return (
{actions.map(({ label, icon: Icon }) => ( } onSelect={() => {}} className="font-normal text-foreground" > {label} ))} ``` -------------------------------- ### Usage of ChatPreview component Source: https://github.com/hexbee/hello-agent/blob/main/docs/message.md Example implementation of the ChatPreview component with avatars, metadata, and a ghost assistant variant. ```tsx "use client"; import { ChatPreview } from "@/components/previews/agents/chat-preview"; export function MessagePreview() { return ( ); } ``` -------------------------------- ### createAgentSessionServices isolation and bindCurrentSession/switchSession binding flow Source: https://github.com/hexbee/hello-agent/blob/main/docs/desktop-agent-tech-stack.md The first block shows the required factory call for creating isolated AgentSessionServices, explicitly injecting all isolation items (agentDir, in-memory settings, modelRuntime, and resourceLoaderOptions with empty overrides). The second block implements the async atomic binding flow: unsubscribe old subscription, get runtime.session, await bindExtensions(actualBindings), then subscribe to events; switchSession re-binds after switching. ```ts const services = await createAgentSessionServices({ cwd, agentDir: appPrivateAgentDir, // 指向应用私有目录,控断全局扩展/skills/settings 扫描 settingsManager: SettingsManager.inMemory(), modelRuntime, // 已注入应用 CredentialStore + modelsPath resourceLoaderOptions: { /* overrides 返回空数组,压掉项目资源发现 */ }, }); ``` ```ts private async bindCurrentSession() { this.unsubscribe?.(); const session = this.runtime.session; await session.bindExtensions(this.extensionBindings); this.unsubscribe = session.subscribe((event) => this.emitNormalized(event)); } async switchSession(path: string) { await this.runtime.switchSession(path); await this.bindCurrentSession(); } ``` -------------------------------- ### ApprovalCard Review Flow Implementation Source: https://github.com/hexbee/hello-agent/blob/main/docs/approval-card.md This example demonstrates how to integrate the ApprovalCard component into a React workflow, managing state transitions between pending, approved, changes-requested, and rejected statuses. ```tsx "use client"; import { RotateCcw } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { ApprovalCard, type ApprovalCardStatus, } from "@/components/agents/approval-card"; function ReviewFlow() { const [status, setStatus] = useState("pending"); const timer = useRef(undefined); useEffect( () => () => { if (timer.current) window.clearTimeout(timer.current); }, [], ); const finish = (next: ApprovalCardStatus) => { setStatus("submitting"); timer.current = window.setTimeout(() => setStatus(next), 700); }; return ( finish("approved")} onRequestChanges={() => finish("changes-requested")} onReject={() => finish("rejected")} result={ status === "approved" ? "Publishing was approved." : status === "changes-requested" ? "The agent will wait for revision notes." : "Publishing was declined." } >
Release
approval-card
Checks
4 passed
Visibility
Public registry
); } export function ApprovalCardReviewPreview() { const [run, setRun] = useState(0); return (
); } ``` -------------------------------- ### Electron BrowserWindow 安全默认配置 Source: https://github.com/hexbee/hello-agent/blob/main/docs/desktop-agent-tech-stack.md 定义所有 BrowserWindow 必须采用的安全默认值:启用 contextIsolation 与 sandbox,关闭 nodeIntegration,并指定 preload 路径。此配置是架构决策,Spike 验证其实际生效。 ```ts new BrowserWindow({ webPreferences: { preload: preloadPath, contextIsolation: true, sandbox: true, nodeIntegration: false, }, }); ``` -------------------------------- ### Project structure overview Source: https://github.com/hexbee/hello-agent/blob/main/README.md Directory layout showing the main components: Electron app, shared IPC contracts, probes, and documentation. ```text apps/desktop # Electron 应用(main 直嵌 pi SDK + 受限 preload + renderer) packages/shared # IPC 契约单一事实来源(事件/命令/运行时校验器) spikes/probes # 技术文档 §10 验收探针 docs # 架构决策、Spike 报告 ``` -------------------------------- ### Web Search Activity Preview Source: https://github.com/hexbee/hello-agent/blob/main/docs/agent-activity.md Demonstrates the implementation of the AgentActivity component for search results, including custom SVG icons and a simulated progressive rendering effect. ```tsx "use client"; import { RotateCcw } from "lucide-react"; import { useReducedMotion } from "motion/react"; import { useEffect, useState } from "react"; import { AgentActivity, type AgentSearchResult, } from "@/components/agents/agent-activity"; function GoogleMark() { return ( ); } function GitHubMark() { return ( ); } function WikipediaMark() { return ( ); } function VercelMark() { return ( ); } const SEARCH_RESULTS: AgentSearchResult[] = [ { id: "google", title: "Google for Developers", domain: "developers.google.com", icon: , }, { id: "github", title: "GitHub", domain: "github.com", icon: , }, { id: "wikipedia", title: "Wikipedia", domain: "wikipedia.org", icon: , }, { id: "vercel", title: "Vercel Docs", domain: "vercel.com/docs", icon: , }, ]; function SearchDemo() { const reduce = useReducedMotion() ?? false; const [visible, setVisible] = useState(0); const [complete, setComplete] = useState(false); useEffect(() => { if (reduce) { setVisible(SEARCH_RESULTS.length); setComplete(true); return; } const resultTimers = SEARCH_RESULTS.map((_, index) => window.setTimeout(() => setVisible(index + 1), 650 + index * 650), ); const completeTimer = window.setTimeout(() => setComplete(true), 3900); return () => { resultTimers.forEach(window.clearTimeout); window.clearTimeout(completeTimer); }; }, [reduce]); return ( ); } export function AgentActivitySearchPreview() { const [run, setRun] = useState(0); return (
); } ``` -------------------------------- ### 工作区打开状态机(Mermaid) Source: https://github.com/hexbee/hello-agent/blob/main/docs/desktop-agent-tech-stack.md 展示工作区从选择文件夹到就绪的状态转换,包括 canonicalize cwd、Trust 检查、认证配置、runtime 创建与会话恢复。任何路径必须经由 realpath 后才可使用。 ```mermaid stateDiagram-v2 [*] --> SelectFolder SelectFolder --> CanonicalizeCwd: 用户选择目录 CanonicalizeCwd --> TrustCheck: realpath / 边界校验通过 CanonicalizeCwd --> Failed: 不可访问或路径无效 TrustCheck --> ConfigureAuth: 已有 Trust 记录 TrustCheck --> RequestTrust: 无记录或记录失效 RequestTrust --> ConfigureAuth: 用户确认级别 ConfigureAuth --> CreateRuntime: provider 可用 ConfigureAuth --> NeedsAuth: 无凭据/认证失败 NeedsAuth --> ConfigureAuth: 认证完成 CreateRuntime --> RestoreSession: runtime 已绑定 extensions RestoreSession --> Ready Ready --> [*]: 关闭 / 切换 cwd / 故障恢复 ``` -------------------------------- ### Implement Prompt Input Source: https://github.com/hexbee/hello-agent/blob/main/docs/prompt-input.md Integrate the PromptInput component with model and action configurations, handling submission and stop events. ```tsx "use client"; import { Bot, FileText, ImagePlus, Puzzle, } from "lucide-react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { useEffect, useRef, useState } from "react"; import { PromptInput } from "@/components/agents/prompt-input"; import { EASE_OUT } from "@/lib/ease"; import { useFavicon } from "@/lib/hooks/use-favicon"; function ModelLogo({ url }: { url: string }) { const favicon = useFavicon(url); if (!favicon.src) return ; return ( // biome-ignore lint/performance/noImgElement: Remote provider favicons keep the registry preview framework-agnostic. ); } const MODELS = [ { value: "gpt-5.2", label: "GPT-5.2", icon: , }, { value: "claude-sonnet-4", label: "Claude Sonnet 4", icon: , }, { value: "gemini-3.6-flash", label: "Gemini 3.6 Flash", // gemini.google.com has no /favicon.ico; Google DeepMind ships Gemini. icon: , }, { value: "grok-4.5", label: "Grok 4.5", icon: , }, { value: "mistral-large-3", label: "Mistral Large 3", icon: , }, ]; const ACTIONS = [ { value: "image", label: "Attach image", description: "Add a screenshot or visual reference.", icon: , }, { value: "skill", label: "Use a skill", description: "Give the agent a specialized workflow.", icon: , }, { value: "context", label: "Add context", description: "Include a file with supporting details.", icon: , }, ]; export function PromptInputPreview() { const reduce = useReducedMotion() ?? false; const timer = useRef(undefined); const [loading, setLoading] = useState(false); const [sent, setSent] = useState(); const [notice, setNotice] = useState(); useEffect( () => () => { if (timer.current) window.clearTimeout(timer.current); }, [], ); const submit = (prompt: string) => { setSent(undefined); setNotice(undefined); setLoading(true); timer.current = window.setTimeout(() => { setLoading(false); setSent(prompt); }, 900); }; const stop = () => { if (timer.current) window.clearTimeout(timer.current); setLoading(false); }; return (
{ const selected = ACTIONS.find((item) => item.value === action); setNotice(selected ? `${selected.label} selected.` : undefined); }} />
{sent || notice ? ( {sent ? "Prompt sent to the selected model." : notice} ) : null}
); } ``` -------------------------------- ### Implement Terminal Output usage Source: https://github.com/hexbee/hello-agent/blob/main/docs/tool-result.md Streams command output into a bounded viewport and collapses upon completion. Requires the ToolResult and ToolResultOutput components. ```tsx "use client"; import { RotateCcw } from "lucide-react"; import { useState } from "react"; import { ToolResult, ToolResultOutput, } from "@/components/agents/tool-result"; import { useToolResultDemo } from "./use-tool-result-demo"; const OUTPUT = [ "$ bun test tests/a11y.test.tsx", "bun test v1.3.14", "✓ StreamingResponse complete", "✓ ToolApproval pending", "✓ Citations expanded", "49 pass · 0 fail", ] as const; function TerminalRun({ onReplay }: { onReplay: () => void }) { const { visible, status } = useToolResultDemo(OUTPUT.length); const output = OUTPUT.slice(0, visible).join("\n"); return ( {output} ); } export function ToolResultTerminalPreview() { const [run, setRun] = useState(0); const replay = () => setRun((value) => value + 1); return (
); } ``` -------------------------------- ### 事件类型定义 (TypeScript) Source: https://github.com/hexbee/hello-agent/blob/main/docs/desktop-agent-tech-stack.md 定义所有 Main → Renderer 事件的基础类型和联合类型,以及 SafePreview 类型。事件包含 version、sequence、sessionId、timestamp,消息事件有 messageId,工具事件有 toolCallId。 ```typescript type EventBase = { version: 1; sequence: number; sessionId: string; timestamp: number; }; type AgentEvent = | (EventBase & { type: "message.started"; messageId: string; role: "assistant" }) | (EventBase & { type: "message.delta"; messageId: string; delta: string }) | (EventBase & { type: "message.finished"; messageId: string }) | (EventBase & { type: "thinking.delta"; messageId: string; delta: string }) | (EventBase & { type: "tool.started"; toolCallId: string; toolName: string; inputPreview: SafePreview }) | (EventBase & { type: "tool.updated"; toolCallId: string; outputPreview: SafePreview }) | (EventBase & { type: "tool.finished"; toolCallId: string; isError: boolean; resultPreview: SafePreview; patch?: SafePreview }) | (EventBase & { type: "agent.state"; state: "running" | "idle" | "aborted" | "failed" }) | (EventBase & { type: "agent.failed"; kind: "llm" | "tool" | "permission" | "network" | "runtime"; message: string }) | (EventBase & { type: "context.compaction"; phase: "started" | "finished" }) | (EventBase & { type: "approval.requested"; requestId: string; toolCallId: string; toolName: string; displayInput: SafePreview }) | (EventBase & { type: "approval.resolved"; requestId: string; decision: "allow" | "deny" | "cancelled" | "expired" }); type SafePreview = { text: string; truncated: boolean; redacted: boolean; }; ``` -------------------------------- ### Implement Request Result usage Source: https://github.com/hexbee/hello-agent/blob/main/docs/tool-result.md Displays an in-flight request and its highlighted response payload. Uses AgentCode for syntax highlighting of the response. ```tsx "use client"; import { RotateCcw } from "lucide-react"; import { useState } from "react"; import { AgentCode } from "@/components/agents/agent-code"; import { ToolResult, ToolResultOutput, } from "@/components/agents/tool-result"; import { useToolResultDemo } from "./use-tool-result-demo"; const RESPONSE = `{ "error": "rate_limit_exceeded", "retryAfter": 30, "requestId": "req_8f21" }`; function RequestRun({ onReplay }: { onReplay: () => void }) { const { visible, status } = useToolResultDemo(3, 600, "error"); return ( {visible < 3 ? ( {visible === 0 ? "Preparing request…" : visible === 1 ? "GET /v1/activity\nConnecting…" : "GET /v1/activity\nWaiting for response…"} ) : ( )} ); } export function ToolResultRequestPreview() { const [run, setRun] = useState(0); const replay = () => setRun((value) => value + 1); return (
); } ``` -------------------------------- ### PendingApproval 类型定义 Source: https://github.com/hexbee/hello-agent/blob/main/docs/desktop-agent-tech-stack.md 定义待审批请求的数据结构,包含请求 ID、会话 ID、工具调用 ID、工具名、输入、创建时间和状态。状态包括 pending、resolved、cancelled 和 expired。 ```typescript type PendingApproval = { requestId: string; sessionId: string; toolCallId: string; toolName: string; input: unknown; createdAt: number; status: "pending" | "resolved" | "cancelled" | "expired"; }; ``` -------------------------------- ### Implement Approval Card Question Flow Source: https://github.com/hexbee/hello-agent/blob/main/docs/approval-card.md Define a set of questions using the ApprovalCardQuestion type and manage the submission lifecycle with the ApprovalCard component. ```tsx "use client"; import { RotateCcw } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { ApprovalCard, type ApprovalCardAnswers, type ApprovalCardQuestion, type ApprovalCardStatus, } from "@/components/agents/approval-card"; const QUESTIONS: ApprovalCardQuestion[] = [ { id: "scope", title: "How focused should the first release be?", options: [ { value: "focused", label: "A focused starter set" }, { value: "broad", label: "A broader collection" }, { value: "flagship", label: "One flagship experience" }, ], allowCustom: true, customPlaceholder: "Describe another scope…", }, { id: "checks", title: "Which checks should block publishing?", description: "Select every check the agent must pass before it can continue.", multiple: true, options: [ { value: "types", label: "Type safety" }, { value: "accessibility", label: "Accessibility" }, { value: "registry", label: "Registry validation" }, ], }, { id: "preserve", title: "Anything the agent should preserve?", allowCustom: true, customPlaceholder: "Add a final constraint…", }, ]; function QuestionFlow() { const [status, setStatus] = useState("pending"); const timer = useRef(undefined); useEffect( () => () => { if (timer.current) window.clearTimeout(timer.current); }, [], ); const submit = (_answers: ApprovalCardAnswers) => { setStatus("submitting"); timer.current = window.setTimeout(() => setStatus("answered"), 750); }; return ( ); } export function ApprovalCardQuestionPreview() { const [run, setRun] = useState(0); return (
); } ``` -------------------------------- ### AISidebar Component Source: https://github.com/hexbee/hello-agent/blob/main/docs/ai-sidebar.md The AISidebar component renders a sidebar navigation tree. It accepts props for managing the state of items, active selection, and movement operations. ```APIDOC ## AISidebar Component ### Description A React component that renders a sidebar navigation tree for managing resources like projects, folders, and files. ### Props - **items** (SidebarResource[]) - Required - The list of resources to display in the sidebar. - **activeId** (string) - Optional - The ID of the currently selected resource. - **defaultExpandedIds** (string[]) - Optional - A list of resource IDs that should be expanded by default. - **onActiveChange** (function) - Optional - Callback triggered when the active selection changes. - **onItemsChange** (function) - Optional - Callback triggered when the items list is updated. - **onMove** (function) - Optional - Callback triggered when a resource is moved within the tree. ### SidebarResource Interface - **id** (string) - Required - Stable resource identifier. - **label** (string) - Required - Visible resource label. - **kind** ("folder" | "project" | "file" | "bookmark") - Required - Resource type and containment behavior. - **children** (SidebarResource[]) - Optional - Nested resources for folders and projects. - **disabled** (boolean) - Optional - Disables selection and interaction for the row. - **busy** (boolean) - Optional - Marks a row as active so the host can render a progress indicator. ``` -------------------------------- ### AISidebar Component Props Source: https://github.com/hexbee/hello-agent/blob/main/docs/ai-sidebar.md The AISidebar component accepts various props to manage sidebar state, user interactions, and custom rendering logic. ```APIDOC ## AISidebar Component ### Description A configurable sidebar component for managing hierarchical resources. ### Props - **items** (SidebarResource[]) - Optional - List of sidebar items. - **defaultItems** (SidebarResource[]) - Optional - Default list of sidebar items (default: []). - **onItemsChange** ((items: SidebarResource[]) => void) - Optional - Callback when items change. - **onMove** ((move: SidebarResourceMove) => void | Promise) - Optional - Callback for moving items; reject the promise to roll back. - **onMoveError** ((error: unknown, move: SidebarResourceMove) => void) - Optional - Callback for move errors. - **onRename** ((item: SidebarResource, label: string) => void | Promise) - Optional - Callback for renaming items. - **activeId** (string | null) - Optional - Controlled active item ID. - **defaultActiveId** (string | null) - Optional - Default active item ID (default: null). - **onActiveChange** ((id: string) => void) - Optional - Callback when active item changes. - **defaultExpandedIds** (string[]) - Optional - Default expanded container IDs (default: []). - **expandedIds** (Set) - Optional - Controlled set of expanded container IDs. - **onExpandedChange** ((ids: Set) => void) - Optional - Callback when expansion state changes. - **visibleChildren** (number | ((item: SidebarResource) => number | undefined)) - Optional - Limits initially visible children. - **showMoreLabel** (string) - Optional - Label for the 'show more' row (default: '展开更多'). - **renderIcon** ((item: SidebarResource) => ReactNode) - Optional - Custom icon renderer. - **renderMenu** ((item: SidebarResource, controls: SidebarResourceMenuControls) => ReactNode) - Optional - Custom menu renderer. - **renderTrailingAction** ((item: SidebarResource) => ReactNode) - Optional - Custom trailing action renderer. - **ariaLabel** (string) - Optional - ARIA label for the sidebar (default: 'Resources'). - **className** (string) - Optional - CSS class name. ``` -------------------------------- ### AISidebar Component Implementation Source: https://github.com/hexbee/hello-agent/blob/main/docs/ai-sidebar.md The AISidebar component is used within an AnimatedSidebarGroup to manage resource navigation, supporting item selection, expansion, and movement. ```tsx Projects
); } ```