Skip to main content

Python translation of OpenCode - AI-powered coding assistant

Project description

Hotaru Code

Hotaru Code 是一个运行在终端里的 AI 编码助手。

它提供 TUI、交互式 Chat、一次性 Run 三种模式,并支持工具调用、权限控制、会话持久化、MCP 扩展、Skill 与 Agent 配置。

功能介绍

1. 多种交互模式

  • hotaru:默认进入 TUI(Textual)
  • hotaru chat:交互式终端聊天
  • hotaru run "你的需求":一次性执行
  • 支持内置 /init 命令:自动生成/更新 AGENTS.md

2. Agent + 权限体系

  • 内置 Agent:buildplangeneralexplore(以及内部隐藏 agent)
  • 支持通过 hotaru agent create 生成 Markdown Agent 配置
  • 支持加载 .opencode/agents/.hotaru/agents/ 等路径下的 Markdown Agent
  • 权限规则支持 allow / ask / deny
  • 对敏感能力(如 bashedit、外部目录访问等)可细粒度控制
  • 内置重复调用保护(doom loop)

3. 工具调用能力

内置工具(按功能分组):

  • 文件与代码:listglobgrepreadeditwritemultieditapply_patch
  • 执行与编排:bashtasktodoreadtodowritequestion
  • 外部信息:webfetch
  • 扩展能力:skilllsp(实验开关)
  • 实验工具:websearchcodesearchbatchplan_enterplan_exit

说明:

  • websearch / codesearch 需要 experimental.enable_exa = true
  • lsp 需要 experimental.lsp_tool = true
  • batch 需要 experimental.batch_tool = true
  • plan_enter / plan_exit 需要 experimental.plan_mode = true
  • 不同模型下会自动调整编辑工具(如 apply_patchedit/write 的切换)

4. Provider / MCP / Skill 扩展

  • Provider:支持 OpenAI、Anthropic 与 OpenAI-compatible 自定义服务
  • MCP:支持本地(stdio)和远程(HTTP/SSE)MCP,支持 OAuth 场景
  • Skill:支持本地目录发现,也支持远程技能索引拉取
  • 会话持久化:会话/消息存储为本地 JSON,可恢复历史上下文

安装与启动

1. 在本仓库源码使用(开发场景)

uv sync
uv run hotaru --help
uv run hotaru

2. 作为命令行工具安装(已发布场景)

uv tool install hotaru-code
uv tool update-shell
hotaru --help

可选:

uvx --from hotaru-code hotaru --help

3. 配置 API Key

至少配置一个可用 Provider 的密钥(或使用/connect命令连接自定义API):

# macOS/Linux
export OPENAI_API_KEY="your-key"
# 或
export ANTHROPIC_API_KEY="your-key"
# Windows PowerShell
$env:OPENAI_API_KEY = "your-key"
# 或
$env:ANTHROPIC_API_KEY = "your-key"

使用方法

1. TUI 模式

# 默认进入 TUI
hotaru

# 指定模型/agent
hotaru --model openai/gpt-5 --agent build

# 切换工作目录并带初始 prompt
hotaru --directory ../another-repo --prompt "先阅读项目结构并总结"

# 显式使用 tui 子命令
hotaru tui --continue

2. Chat 模式

hotaru chat --model openai/gpt-5 --agent build

Chat 常用命令:

  • /help
  • /clear
  • /exit(或 /quit/q
  • /init [额外要求]

3. Run 模式(一次性)

# 基础
hotaru run "请分析这个仓库的结构"

# 指定模型/agent/自动通过权限
hotaru run "修复 tests 失败" --model openai/gpt-5 --agent build --yes

# 附加文件(可重复 -f)
hotaru run "根据附件生成发布说明" -f CHANGELOG.md -f docs/release.md

# 输出 JSON 事件流
hotaru run "总结这段日志" --json

# 触发内置 /init
hotaru run "/init 请补充 monorepo 规范"

# 从 stdin 追加输入
cat error.log | hotaru run "总结错误并给修复建议"

4. 会话与配置管理

hotaru providers            # 列出已可用 provider/model
hotaru agents               # 列出可见 agent
hotaru sessions -n 20       # 列出最近会话
hotaru config --show        # 展示合并后的配置
hotaru config --path        # 展示配置目录

hotaru run "继续处理上次任务" -c
hotaru run "继续指定会话" -s <session_id>

hotaru agent list
hotaru agent create --description "Review Python code and propose safe refactors" --mode primary

配置说明

Hotaru 会合并多来源配置(后者覆盖前者):

  1. 全局配置目录(可用 hotaru config --path 查看)
  2. 当前目录向上查找的 hotaru.json / hotaru.jsonc
  3. 当前目录向上查找的 .hotaru/hotaru.json / .hotaru/hotaru.jsonc(含 ~/.hotaru
  4. 环境变量 HOTARU_CONFIG_CONTENT
  5. 托管配置目录(最高优先级)

最小 hotaru.json 示例

{
  "model": "openai/gpt-5",
  "default_agent": "build",
  "provider": {
    "openai": {
      "options": {
        "apiKey": "{env:OPENAI_API_KEY}"
      }
    }
  },
  "permission": {
    "bash": "ask",
    "edit": "ask",
    "read": {
      "*.env": "deny",
      "*.env.example": "allow"
    }
  }
}

实验功能开关示例

{
  "experimental": {
    "plan_mode": true,
    "enable_exa": false,
    "lsp_tool": false,
    "batch_tool": false
  }
}

自定义 OpenAI-compatible Provider 示例

{
  "provider": {
    "my-provider": {
      "type": "openai",
      "name": "My Provider",
      "options": {
        "baseURL": "https://api.example.com/v1",
        "apiKey": "{env:MY_PROVIDER_API_KEY}"
      },
      "models": {
        "my-model": {
          "name": "My Model"
        }
      }
    }
  }
}

MCP 示例(本地服务)

{
  "mcp": {
    "filesystem": {
      "type": "local",
      "command": [
        "npx",
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "."
      ],
      "enabled": true,
      "timeout": 30
    }
  }
}

Markdown Agent 示例(.opencode/agents/reviewer.md

---
description: Use this agent when you need strict code review.
mode: primary
model: openai/gpt-5
tools:
  bash: false
  edit: false
---
You are a reviewer agent. Focus on correctness, regression risk, and test gaps.

项目结构

  • src/hotaru/cli/:CLI 入口与子命令
  • src/hotaru/tui/:Textual TUI
  • src/hotaru/session/:会话、消息、处理循环
  • src/hotaru/tool/:内置工具与注册中心
  • src/hotaru/provider/:Provider 与模型抽象
  • src/hotaru/mcp/:MCP 客户端与认证
  • src/hotaru/permission/:权限规则与交互
  • src/hotaru/skill/:Skill 发现与加载
  • src/hotaru/lsp/:LSP 客户端与服务管理

开发

# 运行测试
uv run pytest tests

# 构建包
uv build

说明

  • Python 版本要求:>=3.12
  • 包名:hotaru-code
  • 命令行入口:hotaru

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hotaru_code-0.1.1.tar.gz (265.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hotaru_code-0.1.1-py3-none-any.whl (256.6 kB view details)

Uploaded Python 3

File details

Details for the file hotaru_code-0.1.1.tar.gz.

File metadata

  • Download URL: hotaru_code-0.1.1.tar.gz
  • Upload date:
  • Size: 265.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hotaru_code-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9c1a313be30d9eff53c77c6e1cb90f235899000ac7d4d31d5a8d0bb2e028de1d
MD5 7261e083f41495199dd6c8ed51b86d36
BLAKE2b-256 9b168dfce2e55fd470a2744474ac30901a2282da03aea89626ebfcefbc444f5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hotaru_code-0.1.1.tar.gz:

Publisher: publish-pypi.yml on Tsukumi233/hotaru-code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hotaru_code-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hotaru_code-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 256.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hotaru_code-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 923921dad9059a582ffbd186ca37da35bbb86c6b16178c22895f3ebe4e36476c
MD5 1a8d98dd7db935da4d72eb9858a3ca55
BLAKE2b-256 4b2a874bc63f2c8fb9a7f4c2e064ba9b0d4f687759b8f12a3d506a94ae99ddb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hotaru_code-0.1.1-py3-none-any.whl:

Publisher: publish-pypi.yml on Tsukumi233/hotaru-code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page