min-agent 0.1.4 → 0.1.5

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
@@ -1,85 +1,144 @@
1
1
  # min-agent
2
2
 
3
- 轻量级 AI Agent,支持工具调用(读写文件、Shell、搜索)、MCP Skill。
4
- 兼容 OpenAI 风格 API(OpenAI、Ollama、vLLM、MiniMax、DeepSeek 等)。
3
+ Minimal yet powerful AI coding agent for the terminal. Supports any OpenAI-compatible API, MCP servers, skills, memory, and multi-agent parallel execution.
5
4
 
6
- ## 安装
7
-
8
- 需要 **Node.js 20+**。入口为 **`bin/min-agent.js`**(含 `#!/usr/bin/env node`),由 npm/npx 生成 `.cmd` 时用 **`node` 执行**,避免 Windows 把无 shebang 的 `dist/cli.js` 当成「用默认应用打开」。发布包内含 **`tsc` 编译后的 `dist/`**(多文件 ESM),安装时会随 **`dependencies`** 安装 `ai`、`glob` 等;npm 会与同级包 **dedupe**。
5
+ ## Install
9
6
 
10
7
  ```bash
11
8
  npm install -g min-agent
12
- # 或
13
- npx -y min-agent --help
14
9
  ```
15
10
 
16
- ## 快速开始
11
+ ## Quick Start
17
12
 
18
13
  ```bash
19
- # 1) 交互式配置 provider / api key / 默认模型
14
+ # 1. Configure your LLM provider
20
15
  min-agent setup
21
16
 
22
- # 2) 单轮问答
23
- min-agent chat "hello"
24
- min-agent chat "read package.json and tell me the version"
25
- min-agent chat "帮我搜索一下最新的 AI 新闻"
17
+ # 2. Chat mode (general assistant)
18
+ min-agent chat "what files are in this directory?"
19
+
20
+ # 3. Code mode (project-aware AI coding)
21
+ min-agent code
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Commands
27
+
28
+ ### Chat
29
+
30
+ ```bash
31
+ min-agent chat <message> # Single-shot message
32
+ min-agent chat # Interactive multi-turn session
33
+ min-agent chat --resume <id> # Resume a previous session
34
+ min-agent chat -m <model> "msg" # Use a specific model
35
+ min-agent chat -i img.png "what's this?" # Attach image
36
+ ```
37
+
38
+ ### Code (AI Coding Mode)
26
39
 
27
- # 3) 进入多轮对话
28
- min-agent chat
40
+ ```bash
41
+ min-agent code # Project-aware coding session
42
+ min-agent code --resume <id> # Resume coding session
29
43
  ```
30
44
 
31
- ## 首次运行会自动初始化
45
+ Code mode automatically:
46
+ - Scans the project (language, framework, git status, structure)
47
+ - Uses a coding-optimized system prompt
48
+ - Includes the `explore` tool for deep codebase analysis
49
+ - Follows project conventions (no comments, match existing style)
50
+
51
+ ### Configuration
32
52
 
33
- 在当前项目目录自动确保以下结构存在:
53
+ ```bash
54
+ min-agent setup # Interactive provider setup
55
+ min-agent models # List available models
56
+ min-agent rules # Show loaded instruction rules
57
+ min-agent rules edit # Edit global rules file
58
+ ```
34
59
 
35
- - `.min-agent/skills/`
36
- - `.min-agent/mcp.json`(默认 `{ "mcpServers": {} }`)
60
+ ### Memory
37
61
 
38
- 用户全局技能目录 `~/.agents/skills/` 不会自动创建;若你自行创建并放入 `SKILL.md`,启动时会被扫描加载(见下文「Skill 安装」)。
62
+ ```bash
63
+ min-agent memory # List all memories
64
+ min-agent memory add "text" # Add manually
65
+ min-agent memory search "query" # Search
66
+ min-agent memory delete <n> # Delete by number
67
+ ```
68
+
69
+ The agent also saves memories automatically during conversations when you share preferences or important context.
70
+
71
+ ### Sessions
72
+
73
+ ```bash
74
+ min-agent history # List saved sessions
75
+ min-agent chat --resume <id> # Resume a session
76
+ ```
39
77
 
40
- ## CLI 命令
78
+ Sessions are auto-saved when you exit interactive chat/code mode, with LLM-generated titles.
79
+
80
+ ### MCP (Model Context Protocol)
81
+
82
+ ```bash
83
+ min-agent mcp add <name> <cmd...> # Add local stdio server
84
+ min-agent mcp add <name> --url <url> [--token <t>] # Add remote HTTP server
85
+ min-agent mcp remove <name> # Remove server
86
+ min-agent mcp list # List servers
87
+ min-agent mcp check # Check connectivity
88
+ ```
89
+
90
+ ### Skills
91
+
92
+ ```bash
93
+ min-agent skills list # List available skills
94
+ ```
95
+
96
+ ### HTTP API
97
+
98
+ ```bash
99
+ min-agent serve # Start HTTP server (default :8787)
100
+ min-agent serve --port 3000 # Custom port
101
+ ```
102
+
103
+ See [docs/API.md](docs/API.md) for full API reference.
104
+
105
+ ---
106
+
107
+ ## Interactive Commands
108
+
109
+ In chat/code mode, use slash commands:
41
110
 
42
111
  | Command | Description |
43
112
  |---------|-------------|
44
- | `min-agent setup` | 交互配置 API URL、Key、默认模型 |
45
- | `min-agent chat <message>` | 单轮消息 |
46
- | `min-agent chat` | 多轮交互聊天 |
47
- | `min-agent chat -m <model> <message>` | 指定模型发送消息 |
48
- | `min-agent models` | 拉取并列出可用模型 |
49
- | `min-agent mcp add <name> <cmd...>` | 添加本地 MCP(stdio,默认先验证) |
50
- | `min-agent mcp add <name> --url <url> [--sse] [--token …]` | 添加远程 MCP(HTTP) |
51
- | `min-agent mcp remove <name>` | 删除 MCP 服务 |
52
- | `min-agent mcp list` | 列出 MCP 服务 |
53
- | `min-agent mcp check` | 检查所有 MCP 服务可用性 |
54
- | `min-agent skills list` | 列出已发现 skills |
55
- | `min-agent rules` | 查看已加载规则来源 |
56
- | `min-agent rules edit` | 编辑全局规则文件 |
57
- | `min-agent history` | 查看会话历史 |
58
- | `min-agent memory` | 查看记忆 |
59
- | `min-agent memory add <text>` | 新增记忆 |
60
- | `min-agent memory search <query>` | 检索记忆 |
61
- | `min-agent memory delete <index>` | 删除记忆 |
62
-
63
- ## 交互聊天 Slash 命令(`min-agent chat` 内)
64
-
65
- | Slash Command | Description |
66
- |---------------|-------------|
67
- | `/clear` | 清空当前会话消息 |
68
- | `/compact` | 强制压缩上下文 |
69
- | `/model [name]` | 查看或设置默认模型 |
70
- | `/models` | 拉取并列出 provider 模型 |
71
- | `/memory [text]` | 查看记忆或保存记忆 |
72
- | `/skills` | 列出当前已发现 skills |
73
- | `/mcp` | 查看 MCP 服务与连接状态 |
74
- | `/tokens` | 显示上下文 token 估算 |
75
- | `/help` | 显示帮助 |
76
- | `/exit` | 退出聊天 |
77
-
78
- ## 配置文件与加载规则
79
-
80
- ### Provider 配置
81
-
82
- 保存在 `~/.min-agent/config.json`:
113
+ | `/clear` | Clear conversation history |
114
+ | `/compact` | Force context compaction |
115
+ | `/model [name]` | Show or change model |
116
+ | `/memory [text]` | List or save memory |
117
+ | `/tokens` | Show context window usage |
118
+ | `/path` | Show working directory |
119
+ | `/help` | Show all commands |
120
+ | `/exit` | Exit session |
121
+
122
+ **Ctrl+C** interrupts the current generation without exiting.
123
+
124
+ ---
125
+
126
+ ## Configuration
127
+
128
+ All config lives in `~/.min-agent/`:
129
+
130
+ ```
131
+ ~/.min-agent/
132
+ ├── config.json # Provider, model, instructions
133
+ ├── rules.md # Global rules (always injected)
134
+ ├── mcp.json # MCP server definitions
135
+ ├── memory.json # Persistent memories
136
+ ├── models-cache.json # Model list cache (fallback)
137
+ ├── context-window-cache.json # Context window cache
138
+ └── sessions/ # Saved conversation sessions
139
+ ```
140
+
141
+ ### config.json
83
142
 
84
143
  ```json
85
144
  {
@@ -87,70 +146,121 @@ min-agent chat
87
146
  "type": "openai-compatible",
88
147
  "baseURL": "https://api.openai.com/v1",
89
148
  "apiKey": "sk-...",
90
- "defaultModel": "gpt-4o"
91
- }
149
+ "defaultModel": "gpt-4o",
150
+ "contextWindow": 128000
151
+ },
152
+ "instructions": [
153
+ "./docs/CODING_RULES.md",
154
+ "https://example.com/team-rules.md"
155
+ ]
92
156
  }
93
157
  ```
94
158
 
95
- 说明:
159
+ ### Provider Types
96
160
 
97
- - `setup` 时根据填写信息自动拉取模型列表。
98
- - Ollama 支持填 `http://host:11434` 或 `http://host:11434/v1`,会自动兼容。
161
+ | Type | Description |
162
+ |------|-------------|
163
+ | `openai-compatible` | Any OpenAI-compatible API (MiniMax, DeepSeek, vLLM, etc.) |
164
+ | `openai` | OpenAI official |
165
+ | `ollama` | Local Ollama (`http://localhost:11434/v1`) |
99
166
 
100
- ### MCP 配置
167
+ ### Context Window Auto-Detection
101
168
 
102
- 项目级配置:`.min-agent/mcp.json`
169
+ The context window size is automatically detected from:
170
+ 1. `config.provider.contextWindow` (manual override)
171
+ 2. OpenRouter API (`context_length`)
172
+ 3. Ollama API (`/api/show`)
173
+ 4. vLLM API (`max_model_len`)
174
+ 5. [models.dev](https://models.dev) database
175
+ 6. Fallback: 128,000 tokens
103
176
 
104
- ### 规则(Instructions)加载顺序
177
+ ---
105
178
 
106
- 1. 全局规则:`~/.min-agent/rules.md`
107
- 2. 项目规则(从当前目录向上查找首个命中):
108
- - `./AGENTS.md`
109
- - `./RULES.md`
110
- - `./CLAUDE.md`
111
- - `./.min-agent/AGENTS.md`
112
- 3. `~/.min-agent/config.json` 的 `instructions` 字段中声明的本地文件与远程 URL
179
+ ## Tools
113
180
 
114
- ## Built-in Tools
181
+ ### Built-in
115
182
 
116
183
  | Tool | Description |
117
184
  |------|-------------|
118
- | `bash` | 执行 shell 命令 |
119
- | `read` | 读取文件 |
120
- | `write` | 写入/创建文件 |
121
- | `edit` | 文本替换编辑 |
122
- | `glob` | 按模式查找文件 |
123
- | `grep` | 按内容搜索 |
124
- | `web_search` | 联网搜索(SearXNG |
125
- | `web_fetch` | 抓取网页内容(含 Firecrawl SPA 兜底) |
185
+ | `bash` | Shell commands (async, timeout, Ctrl+C killable) |
186
+ | `read` | Read files (with context-aware instruction discovery) |
187
+ | `write` | Write/create files (with overwrite confirmation) |
188
+ | `edit` | Search/replace precise editing |
189
+ | `glob` | Find files by pattern |
190
+ | `grep` | Search file contents with regex |
191
+ | `web_search` | Web search via SearXNG |
192
+ | `web_fetch` | Fetch URLs (with Firecrawl fallback for SPAs) |
193
+ | `todo` | Task tracking with progress visibility |
194
+ | `question` | Ask user for clarification |
195
+ | `task` | Spawn parallel sub-agents |
196
+ | `explore` | Deep codebase exploration (read-only sub-agent) |
197
+ | `skill` | Load domain-specific instructions |
198
+ | `memory_save` | Save information for future sessions |
199
+ | `memory_search` | Search saved memories |
200
+ | `memory_delete` | Remove a memory |
201
+ | `codesearch` | Semantic code search via Exa (requires `EXA_API_KEY`) |
202
+
203
+ ### Sub-Agent System
204
+
205
+ The `task` tool spawns independent sub-agents that:
206
+ - Have their own context and tool access
207
+ - Can run in parallel (call multiple tasks at once)
208
+ - Are limited to 15 steps with doom loop detection
209
+ - Cannot spawn further sub-agents (no recursion)
210
+
211
+ The `explore` tool is a specialized read-only sub-agent for codebase exploration with configurable thoroughness (quick/medium/thorough).
212
+
213
+ ### Plugins
214
+
215
+ Custom tools can be loaded from:
216
+ - `.min-agent/tools/*.ts` (project-level)
217
+ - `~/.min-agent/tools/*.ts` (global)
218
+
219
+ ```typescript
220
+ // .min-agent/tools/deploy.ts
221
+ export const deploy = {
222
+ description: "Deploy the application",
223
+ parameters: { env: { type: "string", description: "Target environment" } },
224
+ execute: async ({ env }) => {
225
+ // your logic
226
+ return `Deployed to ${env}`
227
+ }
228
+ }
229
+ ```
126
230
 
127
- ## 工具输出与截断
231
+ ---
232
+
233
+ ## MCP (Model Context Protocol)
234
+
235
+ Connect external tool servers:
128
236
 
129
- 内置工具与 MCP 返回的文本若超过约 **2000 行**或 **50KB(UTF-8)**,会将**全文**保存到 `~/.min-agent/tool-output/tool-*.txt`,并在返回内容中给出**预览 + 文件路径**;请用 `read`(`startLine`/`endLine`)或 `grep` 分段查看。
237
+ ```bash
238
+ # Local stdio servers
239
+ min-agent mcp add filesystem npx -y @modelcontextprotocol/server-filesystem /tmp
240
+ min-agent mcp add fetch npx -y @modelcontextprotocol/server-fetch
130
241
 
131
- - **`bash`**:使用流式收集;内存中累计超过 **16MB** 会终止进程并提示改用重定向到文件。预览默认保留**输出尾部**(便于看日志)。
132
- - **其它文本类工具**(`read`、`grep`、`web_fetch`、`web_search`、`glob`、MCP):超长时预览默认保留**开头**(`head`),全文仍在上述目录。
242
+ # Remote HTTP servers
243
+ min-agent mcp add remote-api --url https://mcp.example.com --token $TOKEN
244
+ ```
133
245
 
134
- 该目录下旧文件会按修改时间做简单清理(约保留 7 天)。
246
+ MCP tools are automatically namespaced (`servername_toolname`) and available in all modes.
135
247
 
136
- ## Skill 安装
248
+ Supports:
249
+ - Stdio transport (local processes)
250
+ - Streamable HTTP transport
251
+ - SSE transport (legacy)
252
+ - OAuth authentication detection
253
+ - Auto-reconnect on failure
137
254
 
138
- 会在以下目录递归查找 `**/SKILL.md`(**靠后的路径覆盖同名 skill**,即项目内优先于全局):
255
+ ---
139
256
 
140
- 1. `~/.agents/skills/`(用户全局,跨项目共享)
141
- 2. `<cwd>/.min-agent/skills/`
142
- 3. `<cwd>/.agent-demo/skills/`
143
- 4. `<cwd>/.opencode/skills/`
144
- 5. `<cwd>/.claude/skills/`
257
+ ## Skills
145
258
 
146
- 创建目录与文件示例:
259
+ Skills provide domain-specific instructions loaded on demand.
147
260
 
148
- ```text
149
- ~/.agents/skills/<your-skill>/SKILL.md
150
- .min-agent/skills/<your-skill>/SKILL.md
151
261
  ```
152
-
153
- `SKILL.md` 最小格式:
262
+ .min-agent/skills/my-skill/SKILL.md
263
+ ```
154
264
 
155
265
  ```markdown
156
266
  ---
@@ -161,94 +271,89 @@ description: What this skill does
161
271
  # Instructions for the agent...
162
272
  ```
163
273
 
164
- 可用命令:
274
+ Discovery locations:
275
+ - `.min-agent/skills/` (project)
276
+ - `.opencode/skills/` (project)
277
+ - `.claude/skills/` (project, compatibility)
165
278
 
166
- ```bash
167
- min-agent skills list
168
- ```
279
+ ---
169
280
 
170
- ## MCP 安装
281
+ ## Rules (Instructions)
171
282
 
172
- 配置在项目目录 `.min-agent/mcp.json`。
283
+ Rules are injected into every conversation as system instructions.
173
284
 
174
- ### 本地 MCP(stdio)
285
+ | Source | Priority |
286
+ |--------|----------|
287
+ | `~/.min-agent/rules.md` | Global (always loaded) |
288
+ | `./AGENTS.md` or `./RULES.md` | Project-level |
289
+ | `.min-agent/AGENTS.md` | Project-level |
290
+ | `config.instructions[]` | Paths or URLs |
175
291
 
176
- ```bash
177
- min-agent mcp add filesystem npx -y @modelcontextprotocol/server-filesystem /tmp
178
- min-agent mcp add memory npx -y @modelcontextprotocol/server-memory
179
- min-agent mcp add custom --skip-check node ./my-mcp-server.js
180
- ```
292
+ **Context-aware**: When the agent reads a file, nearby `AGENTS.md`/`RULES.md` files are automatically discovered and injected.
181
293
 
182
- ### 远程 MCP(HTTP)
294
+ ---
183
295
 
184
- 通过 `url` 连接远端 MCP,使用 `@modelcontextprotocol/sdk` 的 **Streamable HTTP**;默认 `remoteTransport` 为 `auto`:先尝试 Streamable HTTP,失败再回退 **SSE**(兼容旧版 HTTP+SSE)。
296
+ ## Memory
297
+
298
+ The agent remembers things across sessions:
185
299
 
186
300
  ```bash
187
- min-agent mcp add myremote --url https://api.example.com/mcp
188
- min-agent mcp add myremote --url https://api.example.com/mcp --token "$YOUR_BEARER_TOKEN"
189
- min-agent mcp add legacy --url https://old.example.com/sse --sse
190
- min-agent mcp add legacy --url https://old.example.com/sse --ext/event-stream
191
- min-agent mcp list
192
- min-agent mcp check
301
+ min-agent memory add "I prefer functional style"
302
+ min-agent memory add "Project uses PostgreSQL"
193
303
  ```
194
304
 
195
- 手写配置示例:
305
+ Or just tell the agent: "记住:我喜欢用中文回复" — it will automatically save the memory.
196
306
 
197
- ```json
198
- {
199
- "mcpServers": {
200
- "remote-demo": {
201
- "url": "https://example.com/mcp",
202
- "remoteTransport": "auto",
203
- "token": "optional-bearer-token",
204
- "headers": { "X-Custom-Header": "value" },
205
- "enabled": true
206
- }
207
- }
208
- }
209
- ```
307
+ Memories are injected into the system prompt so the agent always has access to them.
210
308
 
211
- - `token`:可选;若未设置 `Authorization`,会自动添加 `Bearer <token>`。
212
- - `remoteTransport`:`auto` | `streamable-http` | `sse`;CLI 中 `--sse` 等价于 `sse`。
309
+ ---
213
310
 
214
- 说明:
311
+ ## Safety Features
215
312
 
216
- - `mcp add` 默认会先验证连通性;验证失败不会写入配置。
217
- - 离线或私有场景可使用 `--skip-check` 跳过添加时验证。
218
- - `mcp check` 会检查配置中所有服务(含远程),若有失败会返回非零退出码。
313
+ - **Dangerous command confirmation**: `rm -rf`, `sudo`, `git push --force` etc. require approval
314
+ - **File overwrite confirmation**: Existing files prompt before overwriting
315
+ - **Doom loop detection**: Breaks infinite tool call loops (3 identical calls)
316
+ - **Auto-compaction**: Prevents context overflow with structured summarization
317
+ - **`--yes` / `-y` flag**: Skip all confirmations (for automation)
219
318
 
220
- 聊天内可用:
319
+ ---
221
320
 
222
- ```text
223
- /mcp
224
- ```
321
+ ## Context Management
225
322
 
226
- ## 常见问题(Troubleshooting)
323
+ - **Real token tracking**: Uses API response usage data (not estimation)
324
+ - **Auto-compaction**: Triggers at 75% of context window
325
+ - **Structured summaries**: Goal/Progress/Decisions/Files format
326
+ - **Incremental updates**: Updates existing summary instead of rewriting
327
+ - **Tool output pruning**: Trims old tool outputs to save space
328
+ - **Auto-continue**: After compaction, agent continues working automatically
227
329
 
228
- ### 1) `AI_APICallError: Not Found`
330
+ ---
229
331
 
230
- 常见原因是 provider `baseURL` 不匹配(例如 Ollama 未使用 `/v1` 路径)。
231
- 建议先执行:
332
+ ## HTTP API
232
333
 
233
- ```bash
234
- min-agent setup
235
- min-agent models
236
- ```
334
+ Start with `min-agent serve`. Full reference: [docs/API.md](docs/API.md)
237
335
 
238
- 确认可以正常拉取模型列表。
336
+ Key endpoints:
337
+ - `POST /v1/chat` — Chat (streaming SSE or JSON)
338
+ - `GET /v1/sessions` — List sessions
339
+ - `GET /v1/memory` — List memories
340
+ - `GET /v1/mcp` — MCP status
341
+ - `GET /v1/project` — Project scan
342
+ - `POST /v1/chat/compact` — Manual compaction
239
343
 
240
- ### 2) `models` 拉取为空
344
+ ---
241
345
 
242
- - 检查 `apiKey`、`baseURL` 是否正确
243
- - 检查网络或服务端是否可达
244
- - 检查服务是否实现 `/models`(Ollama 已做 `/v1/models` 兼容重试)
346
+ ## Environment Variables
245
347
 
246
- ### 3) MCP 添加后不可用
348
+ | Variable | Description |
349
+ |----------|-------------|
350
+ | `AGENT_MODEL` | Override default model |
351
+ | `EXA_API_KEY` | Enable Exa code search tool |
352
+ | `MIN_AGENT_SHOW_THINKING` | Set to `0` to hide thinking output |
353
+ | `MIN_AGENT_SERVE_TOKEN` | API auth token for serve mode |
354
+ | `MIN_AGENT_SERVE_CORS` | Enable CORS for serve mode |
247
355
 
248
- - 先 `min-agent mcp list` 看是否已配置
249
- - 在聊天内 `/mcp` 看连接状态(connected/disconnected/disabled)
250
- - **本地 stdio**:检查命令是否可执行(如 `npx` 是否可用)
251
- - **远程 URL**:确认地址为 `http(s)://`,必要时加 `--sse` 强制使用旧版 SSE 传输,或用 `mcp check` 查看具体错误信息
356
+ ---
252
357
 
253
358
  ## License
254
359
 
package/bin/min-agent.js CHANGED
File without changes