|
| 1 | +# 🏗️ Architecture Guide |
| 2 | + |
| 3 | +GhostCoder operates as a decentralized, event-driven assistant running entirely locally. It bridges the gap between your workspace (IDE/Editor), your terminal (Shell), and local Large Language Models (via Ollama) without requiring any cloud APIs or external telemetry. |
| 4 | + |
| 5 | +```mermaid |
| 6 | +graph TD |
| 7 | + subgraph Client / Environment |
| 8 | + Shell[Shell Hooks: Bash/Zsh] |
| 9 | + Editor[Editor Plugins: Neovim/VSCode] |
| 10 | + end |
| 11 | +
|
| 12 | + subgraph GhostCoder Daemon |
| 13 | + IPC[IPC Server: Unix Socket / TCP] |
| 14 | + Observer[Workspace Watcher: Watchdog] |
| 15 | + Session[Session Tracker: JSON DB] |
| 16 | + Brain[Ghost Brain Router] |
| 17 | + Skeptic[Ghost Skeptic Validator] |
| 18 | + ModelMgr[Model Manager] |
| 19 | + end |
| 20 | +
|
| 21 | + subgraph Local LLM Provider |
| 22 | + Ollama[Ollama API] |
| 23 | + end |
| 24 | +
|
| 25 | + Shell -->|Command Pre/Post Events| IPC |
| 26 | + Editor -->|Cursor/Editor Changes| IPC |
| 27 | + Observer -->|File Write Events| Session |
| 28 | + IPC -->|Trigger Action| Brain |
| 29 | + Brain -->|Route to Specialist Agent| ModelMgr |
| 30 | + ModelMgr -->|classification/generation| Ollama |
| 31 | + ModelMgr -->|adversarial check| Skeptic |
| 32 | + Skeptic -->|JSON challenge| Ollama |
| 33 | + Brain -->|Return approved hint/fix| IPC |
| 34 | + IPC -->|Push Inline Hint| Editor |
| 35 | +``` |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## 📡 The Daemon & IPC Protocol |
| 40 | +The background daemon (`ghostcoder start`) starts an asynchronous server. By default, it attempts to bind to a Unix Domain Socket at `~/.ghostcoder/ghostcoder.sock`. If running on an unsupported platform or environment, it falls back to a local loopback TCP port (`48673`). |
| 41 | + |
| 42 | +### Core IPC Message Schema |
| 43 | +Clients (IDE plugins, shell wrappers) exchange JSON payloads terminated by newlines (`\n`): |
| 44 | + |
| 45 | +* **`editor_change`**: Sent by the IDE on cursor movement or document modification. Contains file paths, active lines, and raw buffer contents. |
| 46 | +* **`command_pre` / `command_post`**: Sent by shell hook scripts when a terminal command is run and when it finishes (capturing status codes and stderr output). |
| 47 | +* **`status_request`**: Queried by the CLI to retrieve active VRAM consumption, GPU tier metrics, loaded models, and stack definitions. |
| 48 | +* **`reload_config`**: Used by the CLI client to notify a running daemon of configuration changes, triggering hot-swapping of models. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## 🧠 Ghost Brain Routing |
| 53 | +When an event (like a command failure or code edit matching a structural vulnerability) is sent to the daemon, the **Ghost Brain Router** resolves the context: |
| 54 | + |
| 55 | +1. **Tech Stack Detection**: It inspects file extensions and manifests to identify project technologies (e.g., Node.js, Python, Rust). |
| 56 | +2. **Specialist Agent Selection**: The classification model routes the situation to the most relevant engineering specialist (e.g., `agency-application-security-engineer`, `agency-devops-automator`, or `agency-senior-developer`). |
| 57 | +3. **Prompt Assembly**: The system prompt is dynamically assembled from the selected agent's instructions. |
| 58 | +4. **Generation & Skeptic Validation**: The suggestion is produced by the Coder model and validated by the Ghost Skeptic before being returned to the IDE. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 💾 Session Tracker & Replay DB |
| 63 | +All events, raw error messages, model prompts, and user interactions (apply, dismiss) are logged to a local JSON database at `~/.ghostcoder/sessions/`. This transaction log serves as the single source of truth for replay automation and explanation commands. |
0 commit comments