9ff2934089
- 添加读写锁机制防止并发写入冲突 - 实现数据迁移框架支持版本化升级 - 分层存储结构:项目/会话/消息独立存储 - 使用 Git root commit hash 作为稳定项目 ID - 增量消息同步避免重复写入 - 每条消息独立文件,按序号命名 (0001.json, 0002.json)
4.9 KiB
4.9 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Important Rules
- ai-open directory: When I mention "ai-open" or "open source project", it refers to the
ai-open/directory under the current project root. This directory contains reference implementations from open source projects. - No backward compatibility: This is a new project. Do not add any backward-compatible code, deprecated APIs, migration shims, or legacy support. Remove old code entirely when refactoring instead of keeping it around "just in case".
- Git commits: When asked to commit, only create the commit (no push). Commit messages must not contain any Claude-related information (no "Co-Authored-By", no "Generated with Claude", etc.).
- Documentation: All documentation must be stored under
docs/. When implementing features based on design documents, update the corresponding document after coding is complete to reflect the current implementation status. - Selective builds: Do not run
pnpm buildto build all packages. Only build the packages you need. Usepnpm --filter <package> buildfor selective building. The desktop (Tauri) build is especially slow, so avoid building it unless specifically working on desktop features.
Project Overview
AI Terminal Assistant is a terminal-based AI coding assistant built with Claude API. It's structured as a pnpm monorepo with four packages:
- @ai-assistant/core - Agent engine, tools, LSP integration, checkpoint system
- @ai-assistant/server - HTTP Server (Hono + Bun) with REST API, WebSocket, SSE
- @ai-assistant/cli - Command-line interface with
serveandattachcommands - @ai-assistant/web - React frontend (Vite + Tailwind CSS)
Build & Development Commands
# Install dependencies (use pnpm, not npm)
pnpm install
# Build all packages
pnpm build
# Run tests
pnpm test # All packages
pnpm --filter @ai-assistant/core test # Single package
pnpm --filter @ai-assistant/core test:watch # Watch mode
# Start development
pnpm server:dev # Start HTTP server (port 3000)
cd packages/web && pnpm dev # Start web UI (port 5173)
# CLI commands
cd packages/cli && bun run src/index.ts serve --port 3000
cd packages/cli && bun run src/index.ts attach http://localhost:3000
# Type checking
cd packages/web && pnpm typecheck
cd packages/server && pnpm build
Architecture
Package Dependencies
web / cli
↓
server → REST API + WebSocket + SSE
↓
core → Agent / Tools / LSP / Checkpoint / Hooks / MCP
Core Package (packages/core/src/)
Key modules:
core/agent.ts- Main Agent class using AI SDK'sstreamTexttools/- Tool registry with bash, file operations, search, etc.editors/- Unified edit mode system (whole/diff/search-replace)lsp/- Language Server Protocol integrationcheckpoint/- Shadow Git checkpoint systemhooks/- Pre/post execution hooksmcp/- Model Context Protocol clientrepomap/- Repository map generation with tree-sitter
Server Package (packages/server/src/)
index.ts- Hono app setup with CORS, auth middlewareroutes/- REST endpoints (sessions, tools, config)ws.ts- WebSocket handler for real-time chatsse.ts- Server-Sent Events for status updatesagent/adapter.ts- Bridges core Agent to server (dynamic import to avoid build dependency)auth/token.ts- Token-based authentication (auto-enabled for non-localhost)
Communication Flow
- Client connects via WebSocket to
/api/ws/:sessionId - Client sends
{ type: 'message', payload: { content } } - Server calls
processMessage()→ Agent.chat() with streaming callback - Server pushes
chunkevents back via WebSocket - On completion, server sends
doneevent with full response
Key Design Patterns
Dynamic Core Module Loading
Server uses dynamic import to avoid build-time dependency on core:
const corePath = '@ai-assistant/core';
const core = await import(corePath) as CoreModule;
Tool Registration
Tools are registered in toolRegistry with Zod schemas:
toolRegistry.register({
name: 'read_file',
description: '...',
parameters: z.object({ path: z.string() }),
execute: async (params) => { ... }
});
Session Management
Each WebSocket connection binds to a session. Sessions hold:
- Message history
- Status (idle/busy)
- Agent instance (cached per session)
Configuration
- Environment:
ANTHROPIC_API_KEYrequired in.env - Default model:
claude-sonnet-4-20250514 - Server auth: Auto-generates token when host is not localhost
Design Documentation
Architecture details are in docs/design/architecture/gui-server-client.md, including:
- Implementation roadmap with completion status
- API endpoint specifications
- Communication protocol definitions