@@ -12,22 +12,29 @@ Blade is a modern TypeScript project with flattened, modular architecture:
1212Root (blade-code)
1313├── src/
1414│ ├── agent/ # Agent核心逻辑和控制器
15+ │ ├── cli/ # CLI配置和中间件
1516│ ├── commands/ # CLI命令定义和处理
1617│ ├── config/ # 统一配置管理
1718│ ├── context/ # 上下文管理和压缩
1819│ ├── error/ # 错误处理和恢复
1920│ ├── ide/ # IDE集成和扩展
2021│ ├── logging/ # 日志系统
2122│ ├── mcp/ # MCP协议实现
23+ │ ├── prompts/ # 提示模板管理
2224│ ├── security/ # 安全管理
2325│ ├── services/ # 共享服务层
26+ │ ├── slash-commands/ # 内置斜杠命令
2427│ ├── telemetry/ # 遥测和监控
2528│ ├── tools/ # 工具系统
26- │ ├── ui/ # UI组件和界面
29+ │ ├── ui/ # UI组件和界面(基于Ink)
2730│ ├── utils/ # 工具函数
2831│ ├── index.ts # 公共API导出
2932│ └── blade.tsx # CLI应用入口
3033├── tests/ # 测试文件(独立)
34+ │ ├── unit/ # 组件级测试
35+ │ ├── integration/ # 多组件工作流测试
36+ │ ├── e2e/ # 端到端CLI测试
37+ │ └── security/ # 安全测试
3138├── dist/blade.js # 构建后的CLI可执行文件
3239└── package.json # 项目配置
3340```
@@ -41,109 +48,162 @@ Root (blade-code)
4148## Core Components Architecture
4249
4350### Agent System
44- - ** Agent** : Main orchestrator for LLM interactions with context/memory management and enhanced steering control
45- - ** ToolManager** : Centralized tool registration/execution system with validation and security controls
46- - ** IDE Integration** : Multi-IDE detection and extension installation via IdeContext/IdeInstaller
47- - ** MCP Support** : Model Context Protocol server/client integration for external tools
48- - ** ChatService** : Unified LLM interface supporting multiple providers (Qwen, VolcEngine, OpenAI, Anthropic)
51+ - ** Agent** ([ src/agent/Agent.ts] ( src/agent/Agent.ts ) ): 主要协调器,管理LLM交互、上下文/记忆和执行控制
52+ - 静态工厂方法 ` Agent.create() ` 用于创建和初始化实例
53+ - 通过 ` ExecutionEngine ` 处理工具执行流程
54+ - 通过 ` LoopDetectionService ` 防止无限循环
55+ - ** ToolRegistry** ([ src/tools/registry/ToolRegistry.ts] ( src/tools/registry/ToolRegistry.ts ) ): 中心化工具注册/执行系统,提供验证和安全控制
56+ - ** ChatService** ([ src/services/ChatService.ts] ( src/services/ChatService.ts ) ): 统一LLM接口,支持多提供商(基于OpenAI客户端)
57+ - 支持流式和非流式响应
58+ - 内置重试机制和错误处理
59+ - 工具调用集成
4960
5061### Key Services
51- - ** FileSystemService** : File operations with atomic transactions and security validation
52- - ** GitService** : Git repository operations and analysis
53- - ** TelemetrySDK** : Metrics collection and error tracking
54- - ** ProxyService** : HTTP client with retry/batch capabilities and security controls
55- - ** ConfigManager** : Hierarchical configuration management with encryption support
62+ - ** ConfigManager** ([ src/config/config-manager.ts] ( src/config/config-manager.ts ) ): 分层配置管理,支持加密
63+ - 配置优先级:命令行参数 > 环境变量 > 用户配置 > 全局配置 > 默认值
64+ - ** PromptBuilder** ([ src/prompts/] ( src/prompts/ ) ): 提示模板管理和构建
5665
5766## Build & Development Commands
5867
5968### Quick Commands
60- - ** Develop** : ` npm run dev ` - Bun watch mode for live development
61- - ** Build** : ` npm run build ` - Build CLI executable (0.99MB minified)
62- - ** Start** : ` npm run start ` - Run built CLI executable
63- - ** Clean** : Automatic cleanup before each build
69+
70+ - ** 开发模式** : ` npm run dev ` - Bun watch 模式,实时开发
71+ - ** 构建** : ` npm run build ` - 构建 CLI 可执行文件(~ 1MB minified)
72+ - ** 运行** : ` npm run start ` - 运行构建后的 CLI
73+ - ** 清理** : ` npm run clean ` - 清理构建产物和缓存
6474
6575### Code Quality
66- - ** Type Check** : ` npm run type-check ` - TypeScript strict checking
67- - ** Lint** : ` npm run lint ` - Biome linting across TypeScript files
68- - ** Format** : ` npm run format ` - Biome formatting (单引号、分号、88字符行宽)
69- - ** Check** : ` npm run check ` - Combined Biome linting and formatting check
76+
77+ - ** 类型检查** : ` npm run type-check ` - TypeScript 严格类型检查
78+ - ** Lint** : ` npm run lint ` - Biome 代码检查
79+ - ** 格式化** : ` npm run format ` - Biome 格式化(单引号、分号、88字符行宽)
80+ - ** 综合检查** : ` npm run check ` - Biome lint + format 检查
81+ - ** 自动修复** : ` npm run check:fix ` - 自动修复 lint 和格式问题
7082
7183### Testing
72- - ** Test** : ` npm run test ` - Vitest with Jest-like API
73- - ** Watch** : ` npm run test:watch ` - File-watching test runner
74- - ** Coverage** : ` npm run test:coverage ` - With V8 coverage
75- - ** Unit** : ` npm run test:unit ` - Unit tests only
76- - ** Integration** : ` npm run test:integration ` - Integration test suite
77- - ** E2E** : ` npm run test:e2e ` - End-to-end CLI testing
78- - ** Core Only** : ` npm run test:core ` - Test core package only
79- - ** Debug** : ` npm run test:debug ` - Verbose test output
84+
85+ - ** 运行测试** : ` npm test ` - 使用 Vitest 运行所有测试
86+ - ** 监视模式** : ` npm run test:watch ` - 文件变化时自动运行测试
87+ - ** 覆盖率** : ` npm run test:coverage ` - 生成 V8 覆盖率报告
88+ - ** 单元测试** : ` npm run test:unit ` - 仅运行单元测试
89+ - ** 集成测试** : ` npm run test:integration ` - 仅运行集成测试
90+ - ** 端到端测试** : ` npm run test:e2e ` - 仅运行 E2E 测试
91+ - ** 性能测试** : ` npm run test:performance ` - 运行性能测试
92+ - ** 调试模式** : ` npm run test:debug ` - 详细输出模式
93+
94+ ### Release Commands
95+
96+ - ** 版本发布** : ` npm run release ` - 自动发布新版本
97+ - ** 预发布检查** : ` npm run preflight ` - 发布前完整检查(清理、安装、格式化、lint、构建、类型检查、测试)
8098
8199## Package Management
82100
83- ** Uses pnpm** for dependency management:
84- - Single package structure
85- - Direct imports using relative paths
86- - All dependencies managed in root package.json
101+ 使用 ** pnpm** 进行依赖管理:
102+
103+ - 单包结构
104+ - 使用相对路径直接导入
105+ - 所有依赖在根 package.json 管理
87106
88107## Test Structure
89108
90- ```
109+ ``` text
91110tests/
92- ├── unit/ # Component-level tests
93- ├── integration/ # Multi-component workflows
94- ├── e2e/ # Full CLI user journeys
95- └── security/ # Security-focused test scenarios
111+ ├── unit/ # 组件级测试
112+ ├── integration/ # 多组件工作流测试
113+ ├── e2e/ # 完整 CLI 用户旅程测试
114+ ├── security/ # 安全测试
115+ ├── fixtures/ # 测试固定数据
116+ ├── helpers/ # 测试辅助函数
117+ └── mocks/ # 测试模拟对象
96118```
97119
98120## Key Entry Points
99121
100- - ** CLI Entry** : ` dist/blade.js ` (构建后的CLI可执行文件)
101- - ** CLI Source** : ` src/blade.tsx ` (CLI应用入口)
102- - ** Core API** : ` src/index.ts ` (公共API导出)
103- - ** Build System** : Bun native bundling
104- - ** Agent Core** : ` src/agent/Agent.ts ` (Agent核心实现)
105- - ** Tool System** : ` src/tools/ToolManager.ts ` (工具注册/执行)
106- - ** UI Components** : ` src/ui/App.tsx ` (主UI组件)
107- - ** Config Management** : ` src/config/ConfigManager.ts ` (配置管理)
108- - ** Services** : ` src/services/ChatService.ts ` (核心服务)
122+ - ** CLI 入口** : [ src/blade.tsx] ( src/blade.tsx ) - CLI 应用主入口
123+ - ** 核心 API** : [ src/index.ts] ( src/index.ts ) - 公共 API 导出
124+ - ** 构建产物** : ` dist/blade.js ` - 构建后的可执行文件
125+ - ** UI 根组件** : [ src/ui/App.tsx] ( src/ui/App.tsx ) - Ink UI 主组件
126+ - ** CLI 配置** : [ src/cli/config.ts] ( src/cli/config.ts ) - yargs CLI 配置
127+ - ** 命令处理** : [ src/commands/] ( src/commands/ ) - 各命令处理器
109128
110129## Environment Variables
111130
112- - ` QWEN_API_KEY ` - Alibaba Cloud Qwen API key
113- - ` VOLCENGINE_API_KEY ` - VolcEngine API key
114- - ` BLADE_DEBUG ` - Debug mode toggles verbose logging
115- - ` BLADE_VERSION ` - Set by build system from package.json
131+ - ` BLADE_API_KEY ` / ` QWEN_API_KEY ` - API 密钥(千问等)
132+ - ` VOLCENGINE_API_KEY ` - 火山引擎 API 密钥
133+ - ` BLADE_BASE_URL ` - API 基础 URL
134+ - ` BLADE_MODEL ` - 默认模型名称
135+ - ` BLADE_DEBUG ` - 调试模式开关(启用详细日志)
136+ - ` BLADE_VERSION ` - 构建系统自动设置的版本号
116137
117138## Development Workflow
118139
119- 1 . ** Start dev mode ** : ` npm run dev ` (Bun watch mode for live development)
120- 2 . ** Make changes ** :
121- - CLI changes: Edit ` src/blade.tsx `
122- - UI changes: Edit ` src/ui/ `
123- - Agent changes: Edit ` src/agent/ `
124- - Add new tools: ` src/tools/ `
125- - Config changes: ` src/config/ `
126- - Service changes: ` src/services/ `
127- 3 . ** Test ** : ` npm test ` for all tests
128- 4 . ** Build ** : ` npm run build ` for production bundling (minified)
129- 5 . ** Type check ** : ` npm run type-check ` for TypeScript validation
130- 6 . ** Lint ** : ` npm run check:fix ` for code quality
131-
132- ## Build System Details
140+ 1 . ** 启动开发模式 ** : ` npm run dev `
141+ 2 . ** 修改代码 ** :
142+ - CLI 入口: [ src/blade.tsx] ( src/blade.tsx )
143+ - UI 组件: [ src/ui/] ( src/ui/ )
144+ - Agent 逻辑: [ src/agent/] ( src/agent/ )
145+ - 工具开发: [ src/tools/] ( src/tools/ )
146+ - 配置管理: [ src/config/] ( src/config/ )
147+ - 服务层: [ src/services/] ( src/services/ )
148+ 3 . ** 运行测试 ** : ` npm test ` 或特定测试套件
149+ 4 . ** 代码检查 ** : ` npm run check:fix ` 自动修复问题
150+ 5 . ** 类型检查 ** : ` npm run type-check ` 验证 TypeScript
151+ 6 . ** 构建 ** : ` npm run build ` 生产构建
152+
153+ ## Build System
133154
134155### Bun Configuration
135- - ** Target** : Node.js ESM format
136- - ** Minification** : Enabled for production builds
137- - ** External dependencies** : React ecosystem, CLI tools excluded from bundle
138- - ** Output** : Optimized single-file executables
156+
157+ - ** 构建工具** : Bun 原生构建(极速构建性能)
158+ - ** 目标格式** : Node.js ESM
159+ - ** 代码压缩** : 生产构建启用 minification
160+ - ** 外部依赖** : React、Ink、CLI 工具库排除在 bundle 外
161+ - ** 输出** : 单文件可执行程序
139162
140163### Build Process
164+
141165``` bash
142- # Single unified build
166+ # 构建命令
143167npm run build
144- # Equivalent to:
145- rm -rf dist && bun build src/blade.tsx --external react-devtools-core --external react --external react-dom --external ink --external yargs --external chalk --external inquirer --minify --outfile dist/blade.js --target=node
168+
169+ # 等价于:
170+ rm -rf dist && bun build src/blade.tsx \
171+ --external react-devtools-core \
172+ --external react \
173+ --external react-dom \
174+ --external ink \
175+ --external ink-* \
176+ --external yargs \
177+ --external chalk \
178+ --external inquirer \
179+ --minify \
180+ --outfile dist/blade.js \
181+ --target=node
146182```
147183
148184### Build Output
149- - ` dist/blade.js ` : 0.99MB (Unified CLI executable)
185+
186+ - ` dist/blade.js ` : ~ 1MB (包含所有核心逻辑的可执行文件)
187+
188+ ## UI Framework
189+
190+ 项目使用 ** Ink** 构建 CLI UI(React for CLI):
191+
192+ - 基于 React 组件模型
193+ - 支持 hooks 和现代 React 特性
194+ - 丰富的 Ink 生态组件:
195+ - ` ink-text-input ` - 文本输入
196+ - ` ink-select-input ` - 选择列表
197+ - ` ink-spinner ` - 加载动画
198+ - ` ink-progress-bar ` - 进度条
199+ - ` ink-gradient ` / ` ink-big-text ` - 视觉效果
200+
201+ ## Code Style Guidelines
202+
203+ 遵循 Biome 配置的代码风格:
204+
205+ - ** 单引号** : 字符串使用单引号
206+ - ** 分号** : 语句结尾必须有分号
207+ - ** 行宽** : 最大 88 字符
208+ - ** 缩进** : 2 空格
209+ - ** TypeScript** : 尽量避免 ` any ` ,测试文件除外
0 commit comments