按迁移审计 docs/migration/onetcli-to-navop-audit.md「可稍后整理的内部命名」 完成这批内部重构: - crate `crates/onetcli_runtime` → `crates/navop_runtime` - 文件 `main/src/onetcli_app.rs` → `main/src/navop_app.rs`; `crates/core/src/llm/onet_cli_provider.rs` → `navop_provider.rs` - 类型 `OnetCliApp` / `GlobalOnetCliApp` / `OnetCliLLMProvider` → `NavopApp` / `GlobalNavopApp` / `NavopLLMProvider` - `refresh_onetcli_models`、`spawn_onetcli_model_refresh`、 `ONETCLI_MODEL_REFRESH_*` → navop 命名 - 日志文件 `onetcli.log` → `navop.log` - Windows 集成脚本里的 `__OnetCli*` 全局名 → `__Navop*` - 同步 CLAUDE.md / AGENTS.md 的入口路径与类型名 有意保留的历史命名(审计结论):`ProviderType::OnetCli` 及其序列化值 `"onet_cli"`(已写入本地配置与云端)、升级兼容入口(`OnetCli.app`、 `onetcli.exe`、Linux Provides/Replaces/Conflicts)、公开 `ONETCLI_*` 环境变量、bundle id `com.onetcli.app`、历史文档。 验证:cargo check --workspace --all-targets 通过; cargo test -p navop_runtime 69+7+7 passed; cargo test -p one-core --lib llm:: 24 passed; cargo test -p main 628+1+1 passed; cargo clippy -p navop_runtime -p main --all-targets 无错误。
7.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Navop is a cross-platform desktop application built on GPUI that provides a unified interface for database management, SSH/SFTP, terminal, and AI tools. The project was migrated from OnetCli, so some compatibility-sensitive protocols, persisted identifiers (such as ProviderType::OnetCli and its onet_cli value), upgrade entries, and public environment variables still use the historical onetcli / OnetCli spelling.
Key capabilities:
- Multi-protocol database management (PostgreSQL, MySQL, SQLite, SQL Server, Oracle, ClickHouse)
- Redis and MongoDB views
- SSH terminal and SFTP file management
- Local terminal with multi-tab workflows
- Cloud sync and account system with encrypted key storage
- Built-in AI chat (Navop built-in provider via
llm-connector)
Common Commands
# Run the application
cargo run -p main
# Build
cargo build
# Run all tests
cargo test --all
# Run tests for a specific crate
cargo test -p gpui-component
cargo test -p db
cargo test -p one-core
# Run doc tests
cargo test -p gpui-component --doc
# Lint
cargo clippy -- --deny warnings
# Format check
cargo fmt --check
# Unused dependency check
cargo machete
# Run the component gallery/story showcase
cargo run # (default members include crates/story)
# Run a single example
cargo run --example table
# Performance profiling (macOS)
MTL_HUD_ENABLED=1 cargo run -p main
samply record cargo run -p main
# Install system dependencies (Linux/macOS)
script/bootstrap
# Install system dependencies (Windows PowerShell)
.\script\install-window.ps1
# Release (bump version in the dev → main PR, then tag on main; see .github/RELEASE.md)
script/release-tag.sh vx.y.z
Workspace Structure
The workspace uses an external gpui-component checkout plus main and the Navop application crates. Edition is 2024.
Application Layer
main/— Application entry point and main UI. Orchestrates all subsystems: auth, settings, licensing, updates, home page. Entry:main/src/main.rs→NavopApp.
The navop executable is GUI/update-only and does not embed database, SSH, SFTP, or tool business subcommands. A future standalone navop-cli should connect to the running application through Public MCP discovery and its authenticated tool interface instead of linking directly to main or application state.
Core Infrastructure
crates/core(one-core) — Core logic: connection management, cloud sync, AI integration, configuration, encryption (AES-GCM, Ed25519), tab container/persistence.- External
gpui-componentcheckout — Reusable UI components, macros, and bundled assets. crates/one_ui— Navop-owned composite components and product-specific UI.
Feature Crates (Backend + View Pairs)
| Domain | Backend Crate | View Crate |
|---|---|---|
| Database | crates/db |
crates/db_view |
| Terminal | crates/terminal |
crates/terminal_view |
| SSH/SFTP | crates/ssh, crates/sftp |
crates/sftp_view |
| Redis | — | crates/redis_view |
| MongoDB | — | crates/mongodb_view |
Utilities
reqwest_client— HTTP client wrapper around Zed's custom reqwest fork. Comes from thegpui-prefork as the packagegpui-pre-reqwest-client(lib namereqwest_client), patched in the rootCargo.toml; there is no longer a localcrates/reqwest_clientcopy.crates/webview(gpui-wry) — WebView integration via Wry.crates/license_tool— License key generation and management.crates/story— Component gallery/showcase app (runs withcargo runfrom default members).examples/— Standalone examples (hello_world,input,dialog_overlay,webview,system_monitor,focus_trap, etc.).
Application Initialization Flow
The startup sequence in main/src/main.rs and main/src/navop_app.rs is order-sensitive:
update::handle_update_command()— handle self-update CLI commandsload_env_files()— 仅开发构建从 CWD / 工作区加载.env.local/.envApplication::new().with_assets(Assets)— create app with bundled assetsnavop_app::init(cx)— tracing, HTTP client, then subsystem init:
gpui_component::init(cx)— must be called before any UI component usageone_core::init(cx),one_ui::init(cx)— core and UI subsystem initdb_view::chatdb::agents::init(cx)— chat DB agents- Auth init → license init → AI provider state setup
db::init_cache(cx)+ disk cache cleanup taskterminal_view::init(cx),redis_view::init(cx),mongodb_view::init(cx)- Key bindings (
shift-escape→ ToggleZoom,cmd-w/ctrl-d→ ClosePanel) TabContentRegistryglobal setup
setting_tab::init_settings(cx)— settings systemGlobalDbState::new()+ cleanup task →cx.set_global()db_view::init_ask_ai_notifier(cx)— Ask AI notifierDatabaseViewPluginRegistry→cx.set_global()- Open window with
Root::new(NavopApp, window, cx)— Root must be the outermost view
Architecture Patterns
Root View System
Every window's outermost view must be a Root. It manages sheets, dialogs, notifications, and keyboard navigation (Tab/Shift-Tab).
Dock System
Panel layout system with drag-and-drop, zoom, serialization:
DockArea→DockItemtree (Split|Tabs|Panel)- Panels implement
PanelViewtrait PanelRegistryhandles serialization/deserialization
Tab Container System
TabContainer (in one-core) manages multi-tab workflows with:
TabContentRegistryglobal for registering tab content typesTabContainerEventfor inter-tab communication- Tab state persistence via
one_core::tab_persistence(save/load)
Component Design
- Stateless preferred: Use
RenderOncetrait when possible - Size system:
xs,sm,md(default),lgviaSizabletrait - Cursor convention: Buttons use
defaultcursor (desktop convention), notpointer, unless link-style - Styling: CSS-like API via
Styledtrait andElementExt
Theme System
Themeglobal singleton, light/dark mode- Access via
ActiveThemetrait:cx.theme() - Covers colors (
ThemeColor), syntax highlighting, fonts, border radius, shadows, scrollbar mode
Input System
Text input based on Rope (ropey crate) with:
- LSP integration (diagnostics, completion, hover)
- Tree-sitter syntax highlighting
- Variants:
Input,NumberInput,OtpInput
Configuration
- Environment files: 仅开发构建加载
.env.local(优先)→.env(回退),搜索 CWD 与工作区根目录;Release 不读取环境文件 - Build-time config:
SUPABASE_URL,SUPABASE_ANON_KEYcan be baked in at compile time, overridden at runtime - Update URL: the implementation currently accepts the legacy
NAVOP_UPDATE_URLenv var for compatibility - Log level:
RUST_LOGenv var (default:info)
Language Convention
- 简体中文:AI 回复、代码注释、Git 提交信息、文档等一律使用简体中文
- 唯一例外:代码标识符(变量名、函数名、类名等)遵循项目既有英文命名约定
编码规约与开发准则
开始编码前必须先阅读 AGENTS.md,其中包含完整的编码规约、质量标准、工作流程、MCP 工具集成规则和验证机制。