# modiCode **Repository Path**: gaenanwray/modi-code ## Basic Information - **Project Name**: modiCode - **Description**: 用rust来实现的类似opencode的cli工具 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-15 - **Last Updated**: 2026-04-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # opencode-rust 全 Rust 实现的 OpenCode 核心 CLI,默认内置阿里 `bailian-coding-plan`,默认模型: - `bailian-coding-plan/qwen3.6-plus` CLI 命令名:`modicode` ## 已实现能力 - `opencode.json` / `opencode.jsonc` 读取与合并(无配置时自动使用内置默认) - 默认 Provider 与模型内置(与你给出的配置一致) - 按 provider `npm` 自动选择协议:`@ai-sdk/anthropic` 走 `/messages`,其余走 `/chat/completions` - API Key 读取:优先 `options.apiKey`,支持 `{env:...}`,并自动回退: - `BAILINA_API_KEY` - `BAILIAN_API_KEY` - `ALIBABA_CODING_PLAN_API_KEY` - **流式输出**:支持 `--stream` 实时显示模型回复 - **CLI Flag 增强**:`--quiet`, `--debug`, `--format json/text` - **多 Provider 内置**:OpenAI, Anthropic, Google Gemini, DeepSeek - **会话管理**:SQLite 持久化,支持多轮对话上下文 - `session new`: 创建新会话 - `session list`: 列出会话 - `session show `: 查看会话详情 - `session delete `: 删除会话 - `session clear`: 清空所有会话 - **交互式 TUI**:使用 `modicode tui` 或直接运行 `modicode` 进入交互式界面 - 支持实时对话、会话切换、消息历史浏览 - 快捷键:i/Enter=输入, Ctrl+N=新会话, Ctrl+S=会话列表, Ctrl+L=清屏, Ctrl+C/Q=退出 - **内置工具系统**:Agent 可调用工具完成任务 - `bash`: 执行 shell 命令 - `read_file`: 读取文件内容 - `write_file`: 写入/追加文件内容 - `list_dir`: 列出目录内容 - `search`: 代码搜索(支持正则) - 命令: - `tui`:交互式 TUI 模式 - `models`:列出模型 - `agents`:列出内置 Agent - `agent-show `:查看内置 Agent 的系统提示词 - `show-config`:打印最终生效配置 - `run`:调用模型(支持 `--agent` 注入内置 Agent,支持 `--session` 继续会话) ## 快速开始 ```bash cd /Users/gaenanwray/code_prj/ai_code_prj/opencode-rust export BAILINA_API_KEY="你的key" cargo run -- models cargo run -- agents cargo run -- agent-show oracle cargo run -- run "用一句话介绍你自己" # 安装到本机后可直接执行 cargo install --path . modicode models modicode agents modicode agent-show explore modicode run "用一句话介绍你自己" ``` ## 命令示例 ```bash # 交互式 TUI 模式(默认) cargo run -- tui # 或安装后直接运行 modicode # 打印合并后的配置 cargo run -- show-config # 指定模型运行 cargo run -- run "写一个 Rust 函数" --model bailian-coding-plan/qwen3-coder-plus # 带系统提示词 cargo run -- run "解释下面代码" --system "你是资深 Rust 审查者" # 使用内置 Agent(参考 oh-my-openagent) cargo run -- run "帮我评估这个架构方案" --agent oracle # 流式输出 cargo run -- run "讲个故事" --stream # JSON 格式输出 cargo run -- run "1+1=?" --format json # 调试模式(打印请求/响应) cargo run -- run "hello" --debug # 使用 OpenAI cargo run -- run "hello" --model openai/gpt-4o # 会话管理 # 创建新会话 cargo run -- session new "我的项目" # 列出所有会话 cargo run -- session list # 查看会话详情 cargo run -- session show # 继续会话对话 cargo run -- run "继续刚才的话题" --session # 删除会话 cargo run -- session delete # 清空所有会话 cargo run -- session clear # 启用工具调用(Agent 可以使用工具) cargo run -- run "查看当前目录的文件列表" --agent hephaestus --tools ``` ## 配置示例 可参考 [opencode.example.jsonc](./opencode.example.jsonc)。 默认会优先读取: 1. `OPENCODE_CONFIG` 指定路径 2. 当前目录 `opencode.jsonc` 3. 当前目录 `opencode.json` ## 内置 Agent - `sisyphus` - `hephaestus` - `prometheus` - `atlas` - `sisyphus-junior` - `metis` - `momus` - `oracle` - `librarian` - `explore` - `multimodal-looker`