AGENTS.md · git:20260214.c3fa928 · 2026-02-14 · sha256 5c68511a23a52b3d
AGENTS.md git:20260214.c3fa928A
Immutable. This exact content never changes and is served at /api/v1/blob/5c68511a23a52b3d.
# Repository Guidelines
本文档面向贡献者,概述本仓库的模块结构、开发流程与提交规范,便于快速上手并保持一致的协作质量。
## Build, Test, and Development Commands
使用 Android Studio 或命令行 Gradle:
```bash
./gradlew assembleDebug # 构建 Debug APK
./gradlew test # 运行所有模块的 JVM 单元测试
./gradlew connectedDebugAndroidTest # 运行设备/模拟器上的仪器测试
./gradlew lint # 运行 Android Lint
```
构建应用需要在 `app/` 下提供 `google-services.json`(用于 Firebase)。
## Coding Style & Naming Conventions
本仓库使用 `.editorconfig` 统一格式:
- Kotlin/Gradle 脚本:4 空格缩进,最大行长 120。
- XML/JSON:2 空格缩进。
- Markdown/YAML:2 空格缩进,允许尾随空格(用于对齐)。
命名习惯:模块名为小写目录(如 `ai/`、`tts/`),Kotlin 类遵循 PascalCase,测试类以 `*Test` 结尾。
## Testing Guidelines
测试框架以 JUnit/AndroidX Test 为主。未设定强制覆盖率门槛,但新逻辑应配套新增/更新测试。测试文件命名建议:
- 单元测试:`FooTest.kt`
- 仪器测试:`FooInstrumentedTest.kt` 或 `*Test.kt`
## Module Structure
- **app**: Main application module with UI, ViewModels, and core logic
- **ai**: AI SDK abstraction layer for different providers (OpenAI, Google, Anthropic)
- **common**: Common utilities and extensions
- **document**: Document parsing module for handling PDF, DOCX, and PPTX files
- **highlight**: Code syntax highlighting implementation
- **search**: Search functionality SDK (Exa, Tavily, Zhipu)
- **tts**: Text-to-speech implementation for different providers
- **web**: Embedded web server module that provides Ktor server startup function and hosts static frontend build files (
built from web-ui/ React project)
## Concepts
- **Assistant**: An assistant configuration with system prompts, model parameters, and conversation isolation. Each
assistant maintains its own settings including temperature, context size, custom headers, tools, memory options, regex
transformations, and prompt injections (mode/lorebook). Assistants provide isolated chat environments with specific
behaviors and capabilities. (app/src/main/java/me/rerere/rikkahub/data/model/Assistant.kt)
- **Conversation**: A persistent conversation thread between the user and an assistant. Each conversation maintains a
list of MessageNodes in a tree structure to support message branching, along with metadata like title, creation time,
and pin status. Conversations can be truncated at a specific index and maintain chat suggestions. (
app/src/main/java/me/rerere/rikkahub/data/model/Conversation.kt)
- **UIMessage**: A platform-agnostic message abstraction that encapsulates chat messages with different types of content
parts (text, images, documents, reasoning, tool calls/results, etc.). Each message has a role (USER, ASSISTANT,
SYSTEM, TOOL), creation timestamp, model ID, token usage information, and optional annotations. UIMessages support
streaming updates through chunk merging. (ai/src/main/java/me/rerere/ai/ui/Message.kt)
- **MessageNode**: A container holding one or more UIMessages to implement message branching functionality. Each node
maintains a list of alternative messages and tracks which message is currently selected (selectIndex). This enables
users to regenerate responses and switch between different conversation branches, creating a tree-like conversation
structure. (app/src/main/java/me/rerere/rikkahub/data/model/Conversation.kt)
- **Message Transformer**: A pipeline mechanism for transforming messages before sending to AI providers (
InputMessageTransformer) or after receiving responses (OutputMessageTransformer). Transformers can modify message
content, add metadata, apply templates, handle special tags, convert formats, and perform OCR. Common transformers
include:
- TemplateTransformer: Apply Pebble templates to user messages with variables like time/date
- ThinkTagTransformer: Extract `<think>` tags and convert to reasoning parts
- RegexOutputTransformer: Apply regex replacements to assistant responses
- DocumentAsPromptTransformer: Convert document attachments to text prompts
- Base64ImageToLocalFileTransformer: Convert base64 images to local file references
- OcrTransformer: Perform OCR on images to extract text
Output transformers support `visualTransform()` for UI display during streaming and `onGenerationFinish()` for final
processing after generation completes.
(app/src/main/java/me/rerere/rikkahub/data/ai/transformers/Transformer.kt)
## Internationalization
- String resources located in `app/src/main/res/values-*/strings.xml`
- Use `stringResource(R.string.key_name)` in Compose
- Page-specific strings should use page prefix (e.g., `setting_page_`)
- If the user does not explicitly request localization, prioritize implementing functionality without considering
localization. (e.g `Text("Hello world")`)
- If the user explicitly requests localization, all languages should be supported.
- Use `locale-tui` tool for managing translations.
The `locale-tui` tool provides CLI and TUI interfaces for managing string resources with AI-powered translation.
```bash
# Add a new string resource with automatic translation
uv run --directory locale-tui src/main.py add <key> <value> [OPTIONS]
# Examples:
uv run --directory locale-tui src/main.py add hello_world "Hello, World!" # Add and auto-translate
uv run --directory locale-tui src/main.py add greeting "Welcome" -m app # Specify module
uv run --directory locale-tui src/main.py add test_key "Test" --skip-translate # Skip translation
```
**Options:**
- `--module, -m`: Specify module name (defaults to first module in config)
- `--skip-translate`: Skip automatic translation, only add to source language
**Behavior:**
1. Adds key-value pair to source language `strings.xml` (values/strings.xml)
2. By default, automatically translates to all configured target languages using OpenAI API
3. Saves translations to respective language directories (values-zh, values-ja, etc.)
4. Displays translation progress and results for each language
5. The input value should only be English
## Security & Configuration Tips
- 请勿提交密钥或生产凭据;如需本地配置,使用 `local.properties` 或环境变量。
- 若涉及网络请求或第三方服务,请同步更新文档与示例配置。