mirror of
https://github.com/nyakang/nyaterm.git
synced 2026-09-22 00:01:30 +00:00
- Updated documentation to include the new `src/i18n/locales/zh-TW.json` file for Traditional Chinese localization, ensuring comprehensive guidance for user-facing UI text updates.
9.7 KiB
9.7 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development commands
Root app
pnpm install— install JS dependenciespnpm dev— run the Vite frontend onlypnpm tauri dev— run the full desktop app in Tauri dev modepnpm build— runtscand build the frontend with Vitepnpm tauri build— build the production desktop bundlepnpm lint— run Biome checks forsrc/**/*.tsandsrc/**/*.tsxpnpm format— apply Biome formatting tosrc/**/*.tsandsrc/**/*.tsxpnpm format:check— check Biome formatting without writing changespnpm i18n:check— check locale JSON formattingpnpm i18n:fix— rewrite locale JSON formattingpnpm version-sync— sync version numbers across app filespnpm release— version sync + frontend build + Tauri build
Rust / Tauri backend
cargo fmt --manifest-path src-tauri/Cargo.toml— format Rust codecargo clippy --manifest-path src-tauri/Cargo.toml --all-targets— lint Rust codecargo test --manifest-path src-tauri/Cargo.toml— run backend Rust testscargo test --manifest-path src-tauri/Cargo.toml <test_name>— run a single backend Rust testcargo test --manifest-path src-tauri/crates/otp/Cargo.toml— run OTP crate testscargo test --manifest-path src-tauri/crates/otp/Cargo.toml <test_name>— run a single OTP crate test
Example single-test command:
cargo test --manifest-path src-tauri/Cargo.toml normalizes_trailing_slashes_without_breaking_roots
Docs site
pnpm --dir docs-site start— build and serve the docs site locally for all locales (/and/en/)pnpm --dir docs-site start:zh— run the zh-CN docs dev server with hot reloadpnpm --dir docs-site start:en— run the English docs dev server with hot reloadpnpm --dir docs-site start:ko— run the Korean docs dev server with hot reloadpnpm --dir docs-site build— build the docs site
Big-picture architecture
- This is a Tauri 2 desktop app: React/TypeScript frontend in
src/, Rust backend insrc-tauri/src/, and IPC between them via Tauri commands/events. - The frontend should call Rust through the typed wrapper in
src/lib/invoke.ts, not raw scatteredinvoke()calls where a shared wrapper already exists. - Tauri commands are registered centrally in
src-tauri/src/lib.rsand grouped by concern undersrc-tauri/src/cmd/(session,sftp,connection,credential,settings,watcher,translate,stats,tunnel,proxy,otp,importer, plusapp,backup,clipboard,cloud_sync,log, andai).
Window model
src/main.tsxdecides between two boot paths:- main window:
AppProvider+App.tsx - child windows:
ChildAppProvider+ChildWindowRouter
- main window:
- Child windows are opened from
src/lib/windowManager.tsusing?window=query params. Current child-window flows include settings, new-session, quick-command, and per-file auto-upload dialogs. - Modal child-window focus/enable state is managed in
windowManager.tsplussrc/ChildWindowRouter.tsx; changes here affect cross-window UX.
Frontend state model
src/context/AppContext.tsxis the main state container. It owns:- tab/session workspace state
- persisted UI/app settings
- saved connections/groups loading and refresh
- startup session restoration from persisted
ui.open_tabs
src/context/ChildAppProvider.tsxis a lightweight provider for child windows. It only loads/saves settings and emits cross-window events; it does not manage the full tab/session workspace.src/context/TransferContext.tsxseparately tracks file transfer progress from backendtransfer-eventnotifications.
Workspace / terminal model
- The terminal workspace has two distinct layers that are easy to confuse:
src/lib/workspaceTabs.tsmanages the persistent logical tab model. Each tab owns a recursive pane tree (leafsession panes andsplitpanes). This is what gets serialized intoui.open_tabsfor startup restore.src/lib/tabWindows.tsmanages the runtime terminal window layout: which tabs live in each split window leaf, active tab per leaf, and window split ratios for the multi-tab/multi-split UI.
src/App.tsxis the shell that composes activity bars, left/right panels, the terminal workspace, quick command / serial send bottom panels, OTP dialogs, transfer UI, recording, and lock screen.src/components/terminal/XTerminal.tsxis the xterm.js integration point. It wires Fit/Search/WebLinks addons, shell integration, command suggestions, reconnect hooks, and listens to per-session backend events.
Backend runtime model
src-tauri/src/lib.rsconstructs and stores the shared backend managers in Tauri state:SessionManagerTunnelManagerRecordingManagerPendingAuthManagerHostKeyVerifyManagerQuickCommandsStoreCloudSyncManagerAgentApprovalManager(gates AI agent command execution)
- Tauri commands are registered centrally in
src-tauri/src/lib.rs; newer backend capability areas now include app, backup, clipboard, cloud sync, logging, and AI in addition to sessions/SFTP/settings/importers. src-tauri/src/core/session.rscontainsSessionManager, which is the central registry for active sessions, command routing, command history, fuzzy history search, and session lifecycle events.- Session implementations live under
src-tauri/src/core/:ssh/for SSH transport, auth, OSC/CWD tracking, tunnels, and SFTPpty.rsfor local terminal sessionstelnet.rsfor Telnet sessionsserial.rsfor serial sessionsrecording.rsfor terminal recordingwatcher.rsfor file-watch driven flowsimporter.rsfor Xshell / MobaXterm / WindTerm importcloud_sync.rsfor sync/backup runtime and conflict eventsportable_snapshot.rsfor defining what sync/backup payloads includeai/for provider calls, streaming responses, structured command cards, agent execution/approval, prompt redaction, and audit/history storage
- Backend session I/O is event-driven. The Rust side emits session-specific and app-wide events such as
terminal-output-{id},cwd-changed-{id},session-closed-{id},sessions-changed,connections-changed,command-history-changed,transfer-event,otp-request,cloud-sync-status-changed,cloud-sync-history-changed, andcloud-sync-conflict.
SSH / auth / transfer details
- SSH logic is split across
src-tauri/src/core/ssh/:client.rshandles russh client setup, keepalive config, proxy-aware connection setup, and TOFU-styleknown_hostsverification (host-key prompts are coordinated throughHostKeyVerifyManager)auth.rshandles saved auth loading plus keyboard-interactive / OTP flows throughPendingAuthManagerand theotp-requesteventio.rsstreams terminal output and emits CWD updatessftp.rsimplements remote file operations and emits transfer progress events consumed byTransferContexttunnel.rsmanages local / remote / dynamic SSH tunnel behavior
- SFTP commands exposed to the frontend are in
src-tauri/src/cmd/sftp.rs; the file explorer and transfer UI sit on top of these commands and events. - File watcher / auto-upload flows bridge backend and child windows: remote files are downloaded locally, watched by
src-tauri/src/core/watcher.rs, then uploaded back through the auto-upload UI flow.
Persistence model
- App data lives under
~/.nyaterm/, but the primary store is now~/.nyaterm/nyaterm.redbrather than a set of standalone JSON files. - Important redb JSON documents include
settings,sessions,keys,passwords,otp,quick-command,tunnels,proxies,history,cloud-sync,cloud-sync-state,ai-history, andai-audit. - Important text documents stored through the same layer include
known_hostsandmaster.key. - Sensitive values are encrypted before being written; cloud-sync credentials and other secret-bearing config need to stay within the existing crypto/storage helpers.
- When changing settings or workspace persistence, update both the frontend defaults (
AppContext/ChildAppProvider) and the Rust persistence/migration code (src-tauri/src/config/settings/mod.rs,src-tauri/src/config/ui.rs, and relatedsrc-tauri/src/storage.rs/ cloud-sync snapshot code when applicable). - The app also contains legacy Dragonfly migration paths; if you change persistence formats, check that import/migration behavior still makes sense for
~/.dragonfly/data.
Project-specific guidance
- If a task touches UI, prefer shadcn/ui patterns and components. The repo has an explicit Cursor rule for this in
.cursor/rules/ui.mdc. - shadcn is configured in
components.json, and shared UI components live insrc/components/ui/. - When changing user-facing UI text, update both locale files:
src/i18n/locales/en.jsonsrc/i18n/locales/zh-CN.jsonsrc/i18n/locales/zh-TW.jsonsrc/i18n/locales/ko.json
- The root app currently has no dedicated frontend unit test runner configured in
package.json; the automated tests in this repo are Rust tests undersrc-tauri/andsrc-tauri/crates/otp/. - Frontend linting includes a no-
consolecheck before Biome (pnpm lintrunsscripts/check-no-console.mjsandbiome check src/). - Vite uses the
@alias forsrc/. - Tauri dev/build behavior is configured in
src-tauri/tauri.conf.json; the dev server runs on port1420with HMR on1421. - There is a separate Docusaurus docs app in
docs-site/. The most useful repo docs for implementation context are indocs-site/docs/development/(architecture.md,frontend.md,backend.md,setup.md,contributing.md). - Repo docs and recent history use Conventional Commits (
feat:,fix:,perf:,chore:).