Help us shape the future of Go! Take the 2026 Go Developer Survey

kaguya

command module
v0.0.0-...-539246a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 6 Imported by: 0

README

Kaguya

A personal desktop AI Agent for everyday conversations and local projects

English | 简体中文 · Wiki | Wiki(中文)

Kaguya

Kaguya is my personal desktop AI Agent: everyday conversations, local project work, model and MCP configuration, history, and token usage in one application. The backend uses Go, the React interface ships inside the binary, and data is stored locally in a SQLCipher-encrypted database.

The project targets a cross-platform Desktop application. The native desktop host and packaging implemented in this repository support macOS 14 and later; the interface is currently in Chinese.

Kaguya chat interface with conversation history, streaming answers, and tool cards

Features

  • Conversations: streaming Markdown answers, Mermaid diagrams, expandable reasoning and tool cards, per-turn tokens / duration / tool-call counts, paginated history, and concurrent sessions that keep running while you switch; titles come from a persistent FIFO queue and merge by revision through events and reconnect snapshots, with an explicit action to generate a missing title.
  • Local projects: work inside a home-directory project with seven built-in tools (read, bash, edit, write, grep, find, ls), @ file, directory, and project-root references with a paged typed candidate list, reference details showing preparation state and actual excerpt ranges, and a code browser with file tree and unified / split Git diffs. Failed turns can restore reference selections after checking the conversation's current project association; restoring does not send a message.
  • Permissions and approvals: three per-conversation modes (full approval, auto approval, full access). All Bash and MCP calls require approval in restricted modes; auto approval exempts only trusted read-only tools. The wait window is 10 minutes, and structured denials let the model continue. Audits retain associations, hashes, and separate execution results rather than arguments; unconfirmed results stay unknown and are never replayed automatically.
  • Models and providers: OpenAI Chat, OpenAI Responses, and Anthropic protocols on a per-model basis, catalog prefill from models.dev, request-path overrides, a mandatory model test before saving, and refreshed model choices after provider/model changes.
  • MCP tools: stdio, streamable-http, and sse services with dynamic enable / disable, runtime status and failure count, per-service timeouts, automatic reconnection with exponential backoff after a dropped connection, and a circuit breaker after five consecutive failures with manual reconnect; recovery-state storage failures stop automatic retries and are shown separately.
  • Instructions: globally watched AGENTS.md files loaded in the background with a visible publication status and served from one snapshot per turn, project instructions frozen on the first successful turn, and explicit upgrade for merged legacy snapshots.
  • Context management: context-occupancy ring, automatic compaction at a configurable threshold, continuation of unfinished turns, and separate preparation-usage audits for failed turns.
  • Usage analytics: token totals and peaks, a one-year activity heatmap, and composition by model or provider.
  • Local-first data: SQLCipher database, AES-256-GCM encrypted API keys, no listening port in Desktop mode.

Getting started

  1. Open Kaguya.app (from a DMG, drag it into Applications first).
  2. Open 偏好与配置 → AI 配置 → 提供商与模型, add a provider — you can prefill name and Base URL from the provider catalog — and enter the API key. Under a provider's 模型管理, add a model and pass the 测试 before saving.
  3. In 系统配置, pick a default chat model and a background-task model (used for conversation titles), and sync the catalogs if needed.
  4. Return to 对话管理 to chat, or switch to the 项目 tab and add a local directory for project work.

An installed application needs neither Go, Bun, nor a separate database service. Model requests use your configured providers and credentials; project commands and local MCP services use tools installed on the host.

Documentation

The full, page-by-page documentation of the interface, limits, and runtime behavior lives in the wiki:

Language Wiki
English docs/wiki.md
简体中文 docs/wiki.zh.md

Building

Source builds require the Go version in go.mod, Bun, Make, Git, Xcode Command Line Tools, Tcl, pkg-config, curl, and Perl (brew install pkgconf tcl-tk on macOS). Build natively for the target architecture; the C dependencies and the application default to a minimum system version of 14.0.

git clone https://github.com/lyonmu/kaguya.git
cd kaguya
make package-macos      # assemble target/Kaguya.app
make dmg-macos          # package target/Kaguya-<version>.dmg
Command Description
make build Build and embed the frontend, output target/<repo directory name>
make backend / make frontend Backend-only build / prepare embedded assets
make native Download and build pinned OpenSSL + SQLCipher static libraries
make install Install the CLI entry at ~/.local/bin/<repo directory name>
make test go test -race -count=1 ./...

Distribution signing and notarization use CODESIGN_IDENTITY and NOTARY_PROFILE with make sign-macos / make notarize-macos; ordinary packaging applies an ad-hoc signature only.

Run modes

./target/kaguya          # macOS desktop window (default)
./target/kaguya --web    # optional Web mode on http://127.0.0.1:9024

The desktop window calls the shared Go services through Wails' native asset channel and does not listen on a local port. Web mode shares the same interface, services, and data; --host, --port, and --trusted-host apply only to this mode, and remote access should sit behind an authenticated HTTPS gateway.

Local data and backups

Item Location
Database ~/.kaguya/kaguya.db (SQLCipher, WAL)
Database key ~/.kaguya/kaguya.key
Overrides --db.path / DB_PATH, --db.key-file / DB_KEY_FILE, --secret-key / KAGUYA_SECRET_KEY

Quit the application, then copy the database plus any remaining WAL/SHM files and keep the key separately and securely. Losing the key makes the data unreadable; never open the same database in Desktop and Web modes simultaneously. API keys use AES-256-GCM (enc:v2:), and legacy credentials require the offline migration tool in cmd/migrate-provider-secrets.

Database lock waits are limited to 1 second; writes within the process use a single connection. A competing writer returns a database error instead of blocking shutdown for 5 seconds. This does not permit multiple application instances to share a database.

Development

make test                  # Go race tests
cd web
bun install --frozen-lockfile
bun run test && bun run lint && bun run build

Frontend development runs against ./target/kaguya --web with bun run dev inside web/; Desktop loads embedded assets. After changing schemas in internal/ent/schema/, run go generate ./internal/ent. See AGENTS.md for collaboration and validation conventions, and docs/ for the generated Swagger documentation.

Name and license

Kaguya takes its name from Kaguya-hime (辉夜姬), also echoing the Japanese branch's AI system in Dragon Raja (《龙族》).

MIT.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
migrate-provider-secrets command
Command migrate-provider-secrets 把旧格式的提供商 API Key 离线转换为 enc:v2:。
Command migrate-provider-secrets 把旧格式的提供商 API Key 离线转换为 enc:v2:。
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
agent/instructions
Package instructions 加载并监听全局 Agent Markdown(AGENTS.md),以不可变 快照向聊天轮次提供“每轮固定版本”的全局指令。
Package instructions 加载并监听全局 Agent Markdown(AGENTS.md),以不可变 快照向聊天轮次提供“每轮固定版本”的全局指令。
agent/memorytools
Package memorytools 提供聊天内的只读记忆工具 memory_search / memory_read。
Package memorytools 提供聊天内的只读记忆工具 memory_search / memory_read。
agent/permission
Package permission 定义会话工具权限模式与工具效应分类的稳定枚举。
Package permission 定义会话工具权限模式与工具效应分类的稳定枚举。
agent/runtime
Package agent 组装并运行完整的 Agent 运行时(模型/提供商、system prompt、工具), 并在每次回答后记录运行信息(token 用量、耗时、思考时长、工具调用次数等)。
Package agent 组装并运行完整的 Agent 运行时(模型/提供商、system prompt、工具), 并在每次回答后记录运行信息(token 用量、耗时、思考时长、工具调用次数等)。
agent/token
Package agent 提供 Agent 运行信息记录模型:token 用量、耗时、思考时长、工具调用次数等。
Package agent 提供 Agent 运行信息记录模型:token 用量、耗时、思考时长、工具调用次数等。
agent/toolcontract
Package toolcontract 统一内置工具与记忆工具的 JSON schema 校验装饰: Info 返回防御性拷贝的参数字典,Run 在执行前拒绝未知字段与越界值。
Package toolcontract 统一内置工具与记忆工具的 JSON schema 校验装饰: Info 返回防御性拷贝的参数字典,Run 在执行前拒绝未知字段与越界值。
agent/tools
Package tools ports pi's small coding toolset to fantasy.
Package tools ports pi's small coding toolset to fantasy.
agent/workspace
Package workspace 提供 agent 文件工具与项目浏览共享的安全文件原语: 路径规范化、非阻塞 regular-file 打开、有界文本窗口读取与 ignore 匹配。
Package workspace 提供 agent 文件工具与项目浏览共享的安全文件原语: 路径规范化、非阻塞 regular-file 打开、有界文本窗口读取与 ignore 匹配。
cmd
db
desktop
Package desktop 把既有的 Gin Handler 接到 Wails 原生 WebView 通道上。
Package desktop 把既有的 Gin Handler 接到 Wails 原生 WebView 通道上。
ent
init
Package initialize 显式初始化启动资源和数据库基础数据,不使用 Go init() 隐式写库。
Package initialize 显式初始化启动资源和数据库基础数据,不使用 Go init() 隐式写库。
secret
Package secret 为提供商 API Key 等敏感配置提供静态加密。
Package secret 为提供商 API Key 等敏感配置提供静态加密。
service/memory
Package memory 实现可溯源的长期记忆:来源 outbox、后台任务模型增量编译的 Wiki 页面、FTS5 本地召回与预算内上下文注入。
Package memory 实现可溯源的长期记忆:来源 outbox、后台任务模型增量编译的 Wiki 页面、FTS5 本地召回与预算内上下文注入。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL