@iflow-ai/iflow-cli 0.4.7 → 0.4.8-beta-20251217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,237 +3,314 @@
3
3
 
4
4
  **English** | [中文](README_CN.md) | [日本語](README_JA.md) | [한국어](README_KO.md) | [Français](README_FR.md) | [Deutsch](README_DE.md) | [Español](README_ES.md) | [Русский](README_RU.md)
5
5
 
6
- iFlow CLI is a powerful AI assistant that runs directly in your terminal. It seamlessly analyzes code repositories, executes coding tasks, understands context-specific needs, and boosts productivity by automating everything from simple file operations to complex workflows.
6
+ iFlow CLI is a powerful AI assistant that runs directly in your terminal. This repository contains the source code for the iFlow CLI application, built as a monorepo with TypeScript, Node.js, and React (via Ink). This document is intended for developers who want to understand, contribute to, or extend the iFlow CLI codebase.
7
7
 
8
- ## Key Features
8
+ ## 📦 Project Overview
9
9
 
10
- 1. **Free AI Models**: Access powerful and free AI models through the [iFlow open platform](https://docs.iflow.cn/en/docs), including Kimi K2, Qwen3 Coder, DeepSeek v3, and more
11
- 2. **Flexible Integration**: Full support for OpenAI protocol model providers
12
- 3. **Intuitive Interface**: Streamlined terminal experience with context-aware assistance
13
- 4. **Ready-to-Use Assistant**: Pre-configured MCP servers and specialized agents that work together to solve complex problems right out of the box
10
+ iFlow CLI is structured as a monorepo using npm workspaces. It consists of three main packages:
14
11
 
15
- ## 📥 Installation
12
+ - **`packages/cli`**: The command-line interface entry point, handling user interactions, command parsing, and terminal UI.
13
+ - **`packages/core`**: The core engine providing AI agent orchestration, tool execution, context management, and integration with MCP (Model Context Protocol) servers.
14
+ - **`packages/vscode-ide-companion`**: A VS Code extension that integrates iFlow CLI capabilities into the editor.
16
15
 
17
- ### System requirements
18
- - Operating Systems: macOS 10.15+, Ubuntu 20.04+/Debian 10+, or Windows 10+ (with WSL 1, WSL 2, or Git for Windows)
19
- - Hardware: 4GB+ RAM
20
- - Software: Node.js 18+
21
- - Network: Internet connection required for authentication and AI processing
22
- - Shell: Works best in Bash, Zsh or Fish
16
+ The application is built with modern JavaScript/TypeScript tooling, featuring a plugin-based architecture for extensibility.
23
17
 
24
- ### Install Command
25
- ```shell
26
- bash -c "$(curl -fsSL https://cloud.iflow.cn/iflow-cli/install.sh)"
18
+ ## 📁 Project Structure
19
+
20
+ ```
21
+ iflow-cli/
22
+ ├── packages/ # Monorepo packages (detailed below)
23
+ ├── scripts/ # Build and utility scripts
24
+ ├── integration-tests/ # Integration test suites
25
+ ├── docs/ # Documentation
26
+ ├── assets/ # Images and static assets
27
+ ├── vendors/ # Bundled third‑party tools (ripgrep)
28
+ └── bundle/ # Final bundled CLI (generated)
27
29
  ```
28
30
 
29
- This command automatically installs all necessary dependencies for your terminal.
31
+ ### Detailed Package Structure
30
32
 
31
- **Windows Users**:
32
- 1. Go to https://nodejs.org/en/download to download the latest Node.js installer
33
- 2. Run the installer to install Node.js
34
- 3. Restart your terminal: CMD or PowerShell
35
- 4. Run `npm install -g @iflow-ai/iflow-cli` to install iFlow CLI
36
- 5. Run `iflow` to start iFlow CLI
33
+ #### `packages/cli` – Command‑Line Interface
34
+ ```
35
+ cli/
36
+ ├── src/
37
+ │ ├── commands/ # Command definitions
38
+ │ │ ├── agents/ # Agent‑related commands
39
+ │ │ ├── commands/ # Slash command implementations
40
+ │ │ ├── mcp/ # MCP command handlers
41
+ │ │ └── workflows/ # Workflow commands
42
+ │ ├── ui/ # React components for terminal UI
43
+ │ │ ├── components/ # Reusable UI components
44
+ │ │ ├── contexts/ # React contexts (theme, state)
45
+ │ │ ├── hooks/ # Custom React hooks
46
+ │ │ ├── editors/ # Text‑editing components
47
+ │ │ └── themes/ # UI theme definitions
48
+ │ ├── services/ # CLI‑specific services
49
+ │ ├── utils/ # Utility functions
50
+ │ ├── history/ # Conversation history management
51
+ │ └── config/ # Configuration handling
52
+ ├── dist/ # Compiled JavaScript (generated)
53
+ └── [tests]/ # Unit tests (alongside source files)
54
+ ```
37
55
 
38
- If you are in China Mainland, you can use the following command to install iFlow CLI:
39
- 1. Go to https://cloud.iflow.cn/iflow-cli/nvm-setup.exe to download the latest nvm installer
40
- 2. Run the installer to install nvm
41
- 3. **Restart your terminal: CMD or PowerShell**
42
- 4. Run `nvm node_mirror https://npmmirror.com/mirrors/node/` and `nvm npm_mirror https://npmmirror.com/mirrors/npm/`
43
- 5. Run `nvm install 22` to install Node.js 22
44
- 6. Run `nvm use 22` to use Node.js 22
45
- 7. Run `npm install -g @iflow-ai/iflow-cli` to install iFlow CLI
46
- 8. Run `iflow` to start iFlow CLI
56
+ #### `packages/core` Core Engine
57
+ ```
58
+ core/
59
+ ├── src/
60
+ │ ├── tools/ # Tool implementations
61
+ │ │ ├── task/ # Task tool & sub‑agent system
62
+ │ │ ├── *.ts # Individual tools (read‑file, shell, etc.)
63
+ │ │ └── *.test.ts # Tool unit tests
64
+ │ ├── core/ # Core AI client & orchestration
65
+ │ │ ├── client.ts # Gemini/iFlow API client
66
+ │ │ ├── contentGenerator.ts# Content generation logic
67
+ │ │ ├── coreToolScheduler.ts # Tool scheduling & concurrency
68
+ │ │ └── ...
69
+ │ ├── services/ # Background services
70
+ │ │ ├── fileDiscoveryService.ts
71
+ │ │ ├── gitService.ts
72
+ │ │ ├── shellExecutionService.ts
73
+ │ │ └── ...
74
+ │ ├── config/ # Configuration management
75
+ │ ├── mcp/ # Model Context Protocol integration
76
+ │ ├── telemetry/ # OpenTelemetry instrumentation
77
+ │ ├── utils/ # Shared utilities
78
+ │ └── ...
79
+ ├── dist/ # Compiled JavaScript (generated)
80
+ └── [tests]/ # Unit tests (alongside source files)
81
+ ```
47
82
 
48
- ## 🔑 Authentication
83
+ #### `packages/vscode‑ide‑companion` – VS Code Extension
84
+ ```
85
+ vscode-ide-companion/
86
+ ├── src/
87
+ │ ├── extension.ts # VS Code extension entry point
88
+ │ ├── ide‑server.ts # Communication with iFlow CLI
89
+ │ ├── diff‑manager.ts # File diff handling
90
+ │ └── open‑files‑manager.ts # Open files state management
91
+ ├── assets/ # Extension icons & assets
92
+ ├── .vscode/ # VS Code configuration
93
+ └── dist/ # Compiled extension (generated)
94
+ ```
49
95
 
50
- iFlow offers two authentication options:
96
+ ### Other Key Directories
51
97
 
52
- 1. **Recommended**: Use iFlow's native authentication
53
- 2. **Alternative**: Connect via OpenAI-compatible APIs
98
+ - **`scripts/`** Build, release, and maintenance scripts (e.g., `build.js`, `telemetry.js`).
99
+ - **`integration‑tests/`** End‑to‑end tests for tool interactions and sandbox behavior.
100
+ - **`docs/`** – Comprehensive documentation (architecture, CLI usage, troubleshooting).
101
+ - **`vendors/`** – Bundled third‑party binaries (ripgrep) used by tools.
102
+ - **`bundle/`** – Final bundled CLI artifact (created by `npm run bundle`).
54
103
 
55
- ![iFlow CLI Login](./assets/login.jpg)
104
+ ## 🏛️ Architecture Deep Dive
56
105
 
57
- To get your API key:
58
- 1. Register for an iFlow account
59
- 2. Go to your profile settings or click [this direct link](https://iflow.cn/?open=setting)
60
- 3. Click "Reset" in the pop-up dialog to generate a new API key
106
+ iFlow CLI follows a layered, event‑driven architecture designed for extensibility and security. The core components are:
61
107
 
62
- ![iFlow Profile Settings](./assets/profile-settings.jpg)
108
+ ### Core Layer (`packages/core`)
109
+ - **Tool System**: Registration, discovery, and execution of tools (file operations, shell, web, etc.). Tools are defined as classes extending `BaseTool` with parameter validation and permission control.
110
+ - **Agent System**: Orchestration of sub‑agents (`general‑purpose`, `plan‑agent`, `explore‑agent`) for parallel task execution. Each agent has isolated tool permissions and MCP access.
111
+ - **MCP Integration**: Native support for Model Context Protocol servers, allowing dynamic tool discovery from external processes.
112
+ - **Event System**: Asynchronous communication between components (tool calls, agent lifecycle, UI updates).
113
+ - **Configuration & Auth**: Centralized config management and multiple authentication providers (iFlow native, OpenAI‑compatible).
63
114
 
64
- After generating your key, paste it into the terminal prompt to complete setup.
115
+ ### CLI Layer (`packages/cli`)
116
+ - **React‑based UI**: Built with [Ink](https://github.com/vadimdemedes/ink) for terminal rendering, using hooks and components for interactive prompts, streaming output, and real‑time status.
117
+ - **Command Parser**: Handles slash commands (`/init`), direct agent calls (`$explore‑agent`), and natural‑language queries.
118
+ - **State Management**: React hooks manage conversation history, tool call status, and user preferences.
65
119
 
66
- ## 🚀 Getting Started
120
+ ### Integration Layer
121
+ - **Sandbox Environment**: Optional Docker/Podman isolation for risky tool executions.
122
+ - **Telemetry**: OpenTelemetry‑based metrics, traces, and logs for debugging and performance monitoring.
123
+ - **Git Integration**: Automatic detection of repositories, commit message generation, and diff viewing.
67
124
 
68
- To launch iFlow CLI, navigate to your workspace in the terminal and type:
125
+ For a comprehensive architecture overview, see [Architecture Documentation](./docs/architecture/overview.md).
69
126
 
70
- ```shell
71
- iflow
72
- ```
127
+ ## 🛠️ Technology Stack
73
128
 
74
- ### Starting New Projects
129
+ - **Runtime**: Node.js ≥20
130
+ - **Language**: TypeScript with strict mode
131
+ - **UI Framework**: React via [Ink](https://github.com/vadimdemedes/ink) for terminal rendering
132
+ - **Build Tool**: esbuild for bundling, tsc for type checking
133
+ - **Package Manager**: npm (workspaces)
134
+ - **Testing**: Vitest for unit tests, custom integration test runner
135
+ - **Linting/Formatting**: ESLint, Prettier
75
136
 
76
- For new projects, simply describe what you want to create:
137
+ ## 🏗️ Building the Project
77
138
 
78
- ```shell
79
- cd new-project/
80
- iflow
81
- > Create a web-based Minecraft game using HTML
139
+ ### Build All Packages
140
+
141
+ ```bash
142
+ npm install && npm run build
82
143
  ```
83
144
 
84
- ### Working with Existing Projects
145
+ This command runs the TypeScript compiler for each package and produces output in `packages/*/dist`.
85
146
 
86
- For existing codebases, begin with the `/init` command to help iFlow understand your project:
147
+ ### Build with Bundling (Beta)
87
148
 
88
- ```shell
89
- cd project1/
90
- iflow
91
- > /init
92
- > Analyze the requirements according to the PRD document in requirement.md file, and output a technical document, then implement the solution.
149
+ ```bash
150
+ npm run release:version [version]
151
+ npm pack
93
152
  ```
94
153
 
95
- The `/init` command scans your codebase, learns its structure, and creates an IFLOW.md file with comprehensive documentation.
154
+ The `bundle` script generates the final standalone CLI artifact in the `bundle/` directory, which is what gets published to npm.
96
155
 
97
- For a complete list of slash commands and usage instructions, see [here](./docs/cli/commands.md).
98
156
 
99
- ## 💡 Common Use Cases
100
157
 
101
- iFlow CLI extends beyond coding to handle a wide range of tasks:
158
+ ## 🧪 Testing
102
159
 
103
- ### 📊 Information & Planning
160
+ ### Unit Tests
104
161
 
105
- ```text
106
- > Help me find the best-rated restaurants in Los Angeles and create a 3-day food tour itinerary.
162
+ test packages/cli module:
163
+ ```bash
164
+ npm run build --workspaces && npm run typecheck --workspace=@iflow-ai/iflow-cli && npm run test:ci --workspace=@iflow-ai/iflow-cli
107
165
  ```
108
166
 
109
- ```text
110
- > Search for the latest iPhone price comparisons and find the most cost-effective purchase option.
167
+ test packages/core module:
168
+ ```bash
169
+ npm run build --workspaces && npm run typecheck --workspace=@iflow-ai/iflow-cli-core && npm run test:ci --workspace=@iflow-ai/iflow-cli-core
111
170
  ```
112
171
 
113
- ### 📁 File Management
172
+ Runs Vitest tests across all packages.
114
173
 
115
- ```text
116
- > Organize the files on my desktop by file type into separate folders.
117
- ```
174
+ ### Integration Tests
118
175
 
119
- ```text
120
- > Batch download all images from this webpage and rename them by date.
121
- ```
176
+ Integration tests verify tool interactions and sandbox behavior. They can run with different sandbox backends:
122
177
 
123
- ### 📈 Data Analysis
178
+ ```bash
179
+ # No sandbox
180
+ npm run test:integration:sandbox:none
124
181
 
125
- ```text
126
- > Analyze the sales data in this Excel spreadsheet and generate a simple chart.
127
- ```
182
+ # With Docker sandbox
183
+ npm run test:integration:sandbox:docker
128
184
 
129
- ```text
130
- > Extract customer information from these CSV files and merge them into a unified table.
185
+ # With Podman sandbox
186
+ npm run test:integration:sandbox:podman
131
187
  ```
132
188
 
133
- ### 👨‍💻 Development Support
189
+ ### End‑to‑End Tests
134
190
 
135
- ```text
136
- > Analyze the main architectural components and module dependencies of this system.
191
+ ```bash
192
+ npm run test:e2e
137
193
  ```
138
194
 
139
- ```text
140
- > I'm getting a null pointer exception after my request, please help me find the cause of the problem.
195
+ ### Linting and Formatting
196
+
197
+ ```bash
198
+ npm run lint # ESLint check
199
+ npm run lint:fix # ESLint auto‑fix
200
+ npm run format # Prettier formatting
201
+ npm run typecheck # TypeScript type checking
141
202
  ```
142
203
 
143
- ### ⚙️ Workflow Automation
204
+ ## 🔌 Extending iFlow CLI
144
205
 
145
- ```text
146
- > Create a script to periodically backup my important files to cloud storage.
147
- ```
206
+ ### Adding a New Tool
148
207
 
149
- ```text
150
- > Write a program that downloads stock prices daily and sends me email notifications.
151
- ```
208
+ 1. **Create a new tool file** in `packages/core/src/tools/` (e.g., `my-tool.ts`).
209
+ 2. **Extend `BaseTool`** and implement the required methods:
210
+ ```typescript
211
+ export class MyTool extends BaseTool<MyParams, ToolResult> {
212
+ constructor() {
213
+ super('my_tool', 'My Tool', 'Description for the AI', Icon.Hammer);
214
+ }
215
+ // Define parameter schema, validation, execution logic
216
+ }
217
+ ```
218
+ 3. **Register the tool** in `packages/core/src/tools/tools.ts` by adding it to the `coreTools` array.
219
+ 4. **Write tests** following existing patterns (e.g., `my-tool.test.ts`).
152
220
 
153
- *Note: Advanced automation tasks can leverage MCP servers to integrate your local system tools with enterprise collaboration suites.*
221
+ See [Tool System Design](./docs/architecture/tool-system-design.md) and [Tools API](./docs/core/tools-api.md) for detailed guidance.
154
222
 
155
- ## 🔧 Switch to Custom Model
223
+ ### Adding a New Agent Type
156
224
 
157
- iFlow CLI can connect to any OpenAI-compatible API. Edit the settings file in `~/.iflow/settings.json` to change the model you use.
225
+ 1. **Define agent metadata** in `packages/core/src/tools/task/agentRegistry.ts` under `AGENT_DEFINITIONS`.
226
+ 2. **Specify allowed tools**, MCP servers, and execution constraints.
227
+ 3. **The `task` tool** automatically handles agent lifecycle, parallel execution, and result aggregation.
158
228
 
159
- Here is a settings demo file:
160
- ```json
161
- {
162
- "theme": "Default",
163
- "selectedAuthType": "iflow",
164
- "apiKey": "your iflow key",
165
- "baseUrl": "https://apis.iflow.cn/v1",
166
- "modelName": "Qwen3-Coder",
167
- "searchApiKey": "your iflow key"
168
- }
169
- ```
229
+ ### Adding a New CLI Command
170
230
 
171
- ## 🐛 Crash Debugging
231
+ 1. **Add command definition** in `packages/cli/src/commands/` (e.g., create `my-command.ts`).
232
+ 2. **Register the command** in `packages/cli/src/commands/commands.ts`.
233
+ 3. **Implement command logic** using the existing CLI services and UI components.
172
234
 
173
- If you encounter runtime crashes, you can enable crash diagnostics to collect detailed information for debugging:
235
+ ### Integrating an MCP Server
174
236
 
175
- ### Enable Crash Diagnostics
237
+ 1. **Configure the server** in user or project settings (`~/.iflow/settings.json`):
238
+ ```json
239
+ "mcpServers": {
240
+ "my_server": {
241
+ "command": "npx",
242
+ "args": ["-y", "my-mcp-server"]
243
+ }
244
+ }
245
+ ```
246
+ 2. **Tools from the server** will be automatically discovered and prefixed with the server name (e.g., `my_server__tool_name`).
176
247
 
177
- ```bash
178
- # Enable crash debugging mode
179
- DEBUG=true iflow
248
+ ## 🔄 Development Workflow
180
249
 
181
- # Or with additional Node.js debugging flags
182
- DEBUG=true node --trace-warnings --trace-uncaught node_modules/.bin/iflow
183
- ```
250
+ ### Typical Feature Development
184
251
 
185
- ### System Configuration for Core Dumps
252
+ 1. **Explore existing code** using the built‑in `$explore‑agent`:
253
+ ```bash
254
+ $explore‑agent "How is the tool system organized?"
255
+ ```
256
+ 2. **Create a feature branch** from `main`.
257
+ 3. **Implement changes** following the coding standards and architectural patterns.
258
+ 4. **Run tests** locally (`npm test`, `npm run test:integration:sandbox:none`).
259
+ 5. **Update documentation** if the change affects user‑facing behavior or adds new APIs.
260
+ 6. **Submit a PR** with a clear description and link to any related issues.
186
261
 
187
- **macOS:**
188
- ```bash
189
- # Enable core dumps
190
- ulimit -c unlimited
191
- sudo sysctl -w kern.coredump=1
192
- ```
262
+ ### Code Review Checklist
193
263
 
194
- **Linux:**
195
- ```bash
196
- # Configure core dump pattern and enable unlimited core dumps
197
- echo 'core.%p.%t' | sudo tee /proc/sys/kernel/core_pattern
198
- ulimit -c unlimited
199
- ```
264
+ - [ ] TypeScript types are strict and accurate.
265
+ - [ ] New tools have proper parameter validation and user confirmation.
266
+ - [ ] Added tests cover positive and negative scenarios.
267
+ - [ ] No secrets or sensitive data are committed.
268
+ - [ ] Bundle size impact is considered for new dependencies.
269
+ - [ ] Documentation is updated (user guides, API docs, architecture notes).
270
+
271
+ ### Performance Profiling
200
272
 
201
- ### Crash Information Collection
273
+ - Use `DEBUG=true` to capture detailed timing logs.
274
+ - Monitor memory usage via crash reports (`crash-*.json`).
275
+ - For suspected bottlenecks, run the CLI with Node.js inspector and profile CPU/memory in Chrome DevTools.
202
276
 
203
- When `DEBUG=true` is enabled, the system will:
277
+ ## 🧩 Contributing
204
278
 
205
- 1. **Generate crash files** - Create `crash-[timestamp]-[pid].json` files containing:
206
- - Complete error stack trace
207
- - Memory usage information
208
- - Process information (PID, uptime, Node.js version)
209
- - Environment variables
210
- - Platform and architecture details
279
+ We welcome contributions! Please follow these steps:
211
280
 
212
- 2. **Create core dumps** - Generate system core dumps for advanced debugging
281
+ 1. **Fork** the repository and create a feature branch.
282
+ 2. **Ensure your changes pass** the existing tests and linting rules.
283
+ 3. **Add tests** for new functionality.
284
+ 4. **Update documentation** if needed.
285
+ 5. **Submit a pull request** with a clear description of the changes.
213
286
 
214
- 3. **Monitor warnings** - Log Node.js warnings and unhandled promise rejections
287
+ ### Code Style
215
288
 
216
- ### Analyzing Crash Files
289
+ - Use TypeScript with strict mode.
290
+ - Follow the existing ESLint and Prettier configuration.
291
+ - Write meaningful commit messages (conventional commits are appreciated but not required).
292
+ - Keep the bundle size in mind when adding dependencies.
217
293
 
218
- The generated crash files contain structured JSON data that can help identify:
219
- - The exact error that caused the crash
220
- - Memory usage patterns before the crash
221
- - System environment and configuration
222
- - Call stack at the time of crash
294
+ ### Commit Hooks
223
295
 
224
- Share these files when reporting crash issues for faster debugging assistance.
296
+ The project uses Husky to run lint‑staged checks on commit. This ensures code consistency before pushing.
225
297
 
226
- ## GitHub Actions
227
298
 
228
- You can also use iFlow CLI in your GitHub Actions workflows with the community-maintained action: [iflow-cli-action](https://github.com/vibe-ideas/iflow-cli-action)
299
+ ## 📚 Documentation
229
300
 
230
- ## Community Communication
231
- If you encounter problems during use, you can directly raise Issues on the GitHub page.
301
+ - **[Architecture](./docs/architecture/overview.md)**: High‑level design and component interactions.
302
+ - **[Tool System](./docs/architecture/tool-system-design.md)**: How tools are implemented and scheduled.
303
+ - **[MCP Integration](./docs/architecture/mcp-integration-guide.md)**: Integrating Model Context Protocol servers.
304
+ - **[CLI Commands](./docs/cli/commands.md)**: User‑facing command reference.
305
+ - **[Contributing Guide](./CONTRIBUTING.md)**: Detailed contribution instructions.
232
306
 
233
- You can also scan the following WeChat group to join the community group for communication and discussion.
307
+ ## 🤝 Community
308
+
309
+ - **Issues**: Report bugs or request features on [GitHub Issues](https://github.com/iflow-ai/iflow-cli/issues).
310
+ - **WeChat Group**: Join the community discussion via the QR code below.
234
311
 
235
- ### WeChat Group
236
312
  ![WeChat group](./assets/iflow-wechat.jpg)
237
313
 
238
- 1235
239
- 1235
314
+ ## 📄 License
315
+
316
+ iFlow CLI is open‑source under the [MIT License](./LICENSE).