Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 0 additions & 125 deletions AXON.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,128 +128,3 @@ This is an educational reverse-engineering project that recreates @anthropic-ai/
- **用户视角审查**:以用户身份体验自己的产品,发现 UX 问题
- **操作流程**:Browser start → goto Web UI → 创建新对话 → 输入任务 → 克隆体独立工作 → 回来检查结果
- 这比 CLI 克隆(`node dist/cli.js -p "..."`)更优,因为可视化、可管理、可追踪
## Development Commands

```bash
# Development mode (live TypeScript execution)
npm run dev

# Build TypeScript to dist/
npm run build

# Run compiled version
npm run start # or: node dist/cli.js

# Type checking without compiling
npx tsc --noEmit
```

### Testing

```bash
npm test # Run all tests (vitest)
npm run test:unit # Unit tests only (src/)
npm run test:integration # Integration tests (tests/integration/)
npm run test:e2e # End-to-end CLI tests
npm run test:coverage # Run with coverage report
npm run test:watch # Watch mode
npm run test:ui # Vitest UI
```

### CLI Usage

```bash
node dist/cli.js # Interactive mode
node dist/cli.js "Analyze this code" # With initial prompt
node dist/cli.js -p "Explain this" # Print mode (non-interactive)
node dist/cli.js -m opus "Complex task" # Specify model (opus/sonnet/haiku)
node dist/cli.js --resume # Resume last session
```

## Architecture Overview

### Core Three-Layer Design

1. **Entry Layer** (`src/cli.ts`, `src/index.ts`)
- CLI argument parsing with Commander.js
- Main export barrel file

2. **Core Engine** (`src/core/`)
- `client.ts` - Anthropic API wrapper with retry logic, token counting, cost calculation
- `session.ts` - Session state management, message history, cost tracking
- `loop.ts` - Main conversation orchestrator, handles tool filtering and multi-turn dialogues

3. **Tool System** (`src/tools/`)
- All tools extend `BaseTool` and register in `ToolRegistry`
- 25+ tools: Bash, Read, Write, Edit, MultiEdit, Glob, Grep, WebFetch, WebSearch, TodoWrite, Task, NotebookEdit, MCP, Tmux, Skills, etc.

### Key Data Flow

```
CLI Input → ConversationLoop → ClaudeClient (Anthropic API)
↓ ↓
ToolRegistry Session State
↓ ↓
Tool Execution Session Persistence (~/.axon/sessions/)
```

### Important Subsystems

- **Session Management** (`src/session/`) - Persists conversations to `~/.axon/sessions/` with 30-day expiry
- **Configuration** (`src/config/`) - Loads from `~/.axon/settings.json` and environment variables
- **Context Management** (`src/context/`) - Token estimation, auto-summarization when hitting limits
- **Hooks System** (`src/hooks/`) - Pre/post tool execution hooks for customization
- **Plugin System** (`src/plugins/`) - Extensible plugin architecture
- **UI Components** (`src/ui/`) - React + Ink terminal UI framework
- **Code Parser** (`src/parser/`) - Tree-sitter WASM for multi-language parsing
- **Ripgrep** (`src/search/ripgrep.ts`) - Vendored ripgrep binary support
- **Streaming I/O** (`src/streaming/`) - JSON message streaming for Claude API

## Tool System Architecture

Tools are the core of the application. Each tool:
1. Extends `BaseTool` class
2. Defines input schema with Zod
3. Implements `execute()` method
4. Registers in `ToolRegistry`
5. Can be filtered via allow/disallow lists

Tools communicate results back to the conversation loop, which feeds them to the Claude API for the next turn.

## Configuration

### Locations (Linux/macOS: `~/.axon/`, Windows: `%USERPROFILE%\.axon\`)

- **API Key:** `ANTHROPIC_API_KEY` or `AXON_API_KEY` env var, or `settings.json`
- **Sessions:** `sessions/` directory (JSON files, 30-day expiry)
- **MCP Servers:** Defined in `settings.json`
- **Skills:** `~/.axon/skills/` and `./.axon/commands/`
- **Plugins:** `~/.axon/plugins/` and `./.axon/plugins/`

### Key Environment Variables

- `ANTHROPIC_API_KEY` / `AXON_API_KEY` - API key for Claude
- `USE_BUILTIN_RIPGREP` - Set to `1`/`true` to use system ripgrep instead of vendored
- `BASH_MAX_OUTPUT_LENGTH` - Max Bash output length (default: 30000)
- `AXON_MAX_OUTPUT_TOKENS` - Max output tokens (default: 32000)

### Windows-Specific Notes

- Bubblewrap sandbox: Linux-only (Windows needs WSL)
- Tmux: Linux/macOS only (use Windows Terminal tabs/panes)
- Hook scripts: Use `.bat` or `.ps1` instead of `.sh`
- JSON paths: Use double backslashes (e.g., `"C:\\Users\\user\\projects"`)

## Key Design Patterns

- **Registry Pattern** - `ToolRegistry` for dynamic tool management
- **Plugin Pattern** - `PluginManager` with lifecycle hooks
- **Strategy Pattern** - Multiple permission modes (acceptEdits, bypassPermissions, plan)
- **Observer Pattern** - Event-driven hook system

## TypeScript Configuration

- **Target:** ES2022, **Module:** NodeNext (ES Modules)
- **JSX:** React (for Ink UI components)
- **Output:** `dist/` with source maps and declarations
- **Strict:** Disabled (`"strict": false`)
4 changes: 2 additions & 2 deletions Dockerfile.railway
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ============================================
# Stage 1: Build
# ============================================
FROM node:18-slim AS builder
FROM node:20-slim AS builder

RUN apt-get update && apt-get install -y --fix-missing \
python3 \
Expand All @@ -26,7 +26,7 @@ RUN npm --prefix src/web/client ci && \
# ============================================
# Stage 2: Production
# ============================================
FROM node:18-slim
FROM node:20-slim

RUN apt-get update && apt-get install -y --fix-missing \
git \
Expand Down
Loading
Loading