feat: remove obsolete design documents for clipboard OSC52, diff view, file mention, context compaction, and add development guide

This commit is contained in:
asepharyana
2026-07-20 14:47:55 +07:00
parent 44c3dd1239
commit 66ac4dbf02
23 changed files with 775 additions and 13170 deletions
+108 -47
View File
@@ -1,68 +1,129 @@
# Backend Architecture
# Backend & Infrastructure
## Provider Layer
Semua implementasi I/O ada di `apps/infrastructure/src/`. Layer ini mengimplementasikan port/trait yang didefinisikan di `apps/domain/`.
The provider abstraction in `dto/provider/` and `service/provider.rs` wraps LLM API calls:
## LLM Client (`infrastructure/src/llm/`)
- **Configuration**: `model/app_config.rs` loads Anthropic/OpenAI-compatible endpoint settings
- **Authentication**: `service/oauth/` handles OAuth 2.0 with PKCE flow and token management
- **Requests**: `dto/provider/request.rs` builds provider-agnostic request structs
- **Responses**: `dto/provider/response.rs` parses streaming and non-streaming responses
- **Token tracking**: `dto/provider/usage.rs` tracks token consumption
Wrapper di atas provider OpenAI-compatible:
## IPC (Inter-Process Communication)
- **`provider/`** — `LlmClient`: HTTP client dengan `reqwest::blocking` (sync) untuk agent turn, dan async streaming untuk preview
- **Request/Response** — `ChatMessage`, `ChatCompletionRequest`, `ChatCompletionResponse` dengan support tool calls
- **Streaming** — SSE event parser untuk streaming response
- **Usage tracking** — `tokens_in`, `tokens_out`, `last_tokens_in`, `last_tokens_out` per panggilan
- **Provider defaults** — DeepSeek v4 flash free via OpenCode AI proxy (default)
The daemon-client protocol in `src/ipc/`:
- **Transport**: Unix domain sockets
- **Framing**: Length-prefixed frames with `serde_json` serialization (`ipc/frame.rs`)
- **State Sync**: Full state push from daemon after each action (`ipc/snapshot.rs`); diff-based updates for efficiency (`ipc/diff.rs`)
- **Protocol**: `ipc/protocol.rs` defines message types (Action, StateSnapshot, etc.)
Flow:
```
Client ──Action──▶ Daemon ──apply_action()──▶ State mutated
└──StatePayload──▶ Client (render)
```rust
// Contoh penggunaan di turn.rs
let result = client.chat_with_tools_non_streaming(
&mut messages,
Some(tool_defs),
Some(4096), // max_tokens
Some(0.7), // temperature
None, // abort flag
);
```
## Workflow Engine
## Tool System (`infrastructure/src/tools/`)
Located in `src/app/workflow/`:
37 tool yang mengimplementasikan trait `Tool` dari domain:
- **Script DSL** (`engine.rs`): Executes the workflow script language (agent/parallel/pipeline/phase). Supports subagent spawning with schema-validated output, concurrency limiting, and budget tracking.
- **Hive Mind** (`hive_mind.rs`): Core Intelligence spawns a CognitiveCyclePlan — ordered cycles of parallel processing nodes. Each node has a directive and access tier (`read`/`write`/`full`). Node outputs merge into a shared collective state in real time. Final consensus synthesis completes the convergence.
- **Docs** (`docs.rs`): Deterministic (not LLM) convergence writer — records every node's output + final consensus to `docs/runs/`.
```rust
pub trait Tool: Send + Sync {
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn parameters(&self) -> Value; // JSON Schema
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String>;
}
```
## MCP (Model Context Protocol)
### Kategori Tool
`src/app/mcp/manager.rs` manages MCP client connections:
| Kategori | Tools |
|----------|-------|
| **File System** | `read`, `write`, `edit`, `delete`, `dir_list`, `dir_cache_update` |
| **Shell** | `bash`, `bash_interactive`, `bash_kill`, `bash_output` |
| **Git** | `git_operator`, `git_cred`, `git_worktree` |
| **Search** | `search`, `grep`, `glob`, `semantic_search` |
| **LSP** | `lsp_connect`, `lsp_hover`, `lsp_completion`, `lsp_definition`, `lsp_references`, `lsp_diagnostics`, `lsp_disconnect` |
| **Memory** | `remember`, `recall`, `forget` |
| **Workflow** | `spawn_agents`, `spawn_pipeline`, `plan`, `sequential_think`, `hive_mind` |
| **Utility** | `todo_write`, `todo_finish`, `pong`, `cd` |
| **Background** | `bash_bg_cancel`, `bash_bg_status`, `bash_bg_list` |
- Uses the `rmcp` crate for the MCP protocol
- Supports stdio-based transport (child process) and streamable HTTP
- Tool discovery via `list_tools()` and dynamic tool registration
`ToolCtx` berisi:
- `session_dir: PathBuf` — direktori sesi aktif
- `workspaces: Vec<PathBuf>` — root workspace yang dibuka
## LSP Integration
## Background Shell Jobs (`infrastructure/src/bgbash/`)
`src/app/lsp/` provides Language Server Protocol support:
Manajemen proses shell jangka panjang:
- **Spawn** dengan Unix process groups (untuk kill seluruh tree)
- **Output buffering** — collect stdout/stderr secara async
- **Cancel/status/list** — kontrol via tool calls
- **Progress monitoring** — track state: `Running`, `Completed`, `Failed`
- **Auto-provisioner** (`provisioner.rs`): Detects and starts LSP servers for Rust, TypeScript, Python, Go, and other languages
- **Client** (`client.rs`): JSON-RPC-based LSP client with typed notifications
- **Tools** (`tool/lsp/mod.rs`): 7 LSP tools (connect, hover, completion, definition, references, diagnostics, disconnect)
## MCP Manager (`infrastructure/src/mcp/`)
## Background Bash
Integrasi **Model Context Protocol**:
- Menggunakan crate `rmcp` (v2.2)
- Transport: **stdio** (child process) dan **streamable HTTP**
- `list_tools()` → tool discovery otomatis → registrasi ke tool harness
- Persistent connection management
`src/app/bgbash/` manages long-running shell jobs:
## LSP Integration (`infrastructure/src/lsp/`)
- **Control** (`control.rs`): Job lifecycle management (spawn, signal, terminate) using Unix process groups
- **Job** (`job.rs`): Individual job state tracking with output buffering and progress monitoring
Integrasi **Language Server Protocol**:
- **Auto-provisioner** — deteksi bahasa dari file extension, start LSP server yang sesuai
- Mendukung: `rust-analyzer`, `typescript-language-server`, `pyright`, `gopls`, dan lainnya
- **JSON-RPC client** — typed notifications + request/response
- 7 tools LSP yang diekspose ke LLM
## Review System
## Persistence (`infrastructure/src/persistence/`)
`src/app/subagent/auto.rs` spawns background reviews:
### SQLite Message Log
- Quick review after every edit
- Background test generation
- Architecture review
- Security review
- All retry once on failure, escalate to blocking error if retry also fails
Session database dengan `rusqlite` (bundled):
- Per-session isolation
- Table: `messages`, `sessions`
- CRUD, query/filter, blob storage
### Settings Repository
`JsonSettingsRepository` — simpan/load `Settings` dari `settings.json`:
- `provider`: nama provider LLM
- `model`: model ID
- `max_tokens`: override context window (default: 256k jika tidak diset)
- `temperature`, `concise_output`, dll
### Memory Files
File-based memory di `~/.local/share/zesdex/memories/`:
- Setiap memory = satu `.md` dengan frontmatter YAML
- Fields: `name`, `description`, `type` (`user`/`feedback`/`project`/`reference`)
- Index di `MEMORY.md`
## Session Management (`infrastructure/src/session/`)
- Setiap sesi memiliki UUID, direktori sendiri di `sessions/<uuid>/`
- `.lock` file untuk cegah concurrent access
- `session.json` — metadata (waktu mulai, workspace, model yang dipakai)
## Utils
| Util | Fungsi |
|------|--------|
| `utils::write_osc52` | Tulis teks ke clipboard via OSC52 escape sequence |
| `Toast` / `ToastKind` | Notifikasi sementara (Success/Warning/Error/Info/Lesson) |
| `TurnEvent` | Event dari background agent ke TUI (queue-based) |
| `DirCache` | Cache async listing direktori untuk `@mention` autocomplete |
| `MentionIndex` | Index file workspace untuk fuzzy autocomplete |
| `SessionRuntime` | Runtime state: messages history, usage stats, session start time |
## OAuth 2.0
Flow PKCE untuk provider LLM:
1. Generate code verifier + challenge
2. Open browser ke authorization URL
3. Start localhost HTTP server untuk tangkap redirect
4. Exchange code → access + refresh token
5. Simpan token di settings