Skip to content

Commit c3fd3e8

Browse files
committed
Update Cargo configuration and introduce gemini-ipc crate
- Added the `gemini-ipc` crate to facilitate Inter-Process Communication between components. - Updated `Cargo.toml` files across multiple modules to replace the `ipc` dependency with `gemini-ipc`. - Refactored code in the MCP and CLI modules to utilize the new `gemini-ipc` crate, enhancing code organization and maintainability. - Removed deprecated `HAPPE` and `IDA` modules and their associated files to streamline the project structure. - Improved overall code readability and organization by consolidating imports and removing unused modules.
1 parent 2674562 commit c3fd3e8

60 files changed

Lines changed: 3524 additions & 1627 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
description: Use this rule to get a high-level project overview, identify the core function of each crate, understand major subsystems, and find the entry-point documentation for components.
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Gemini Rust Suite: Project Overview and Core Crates
7+
8+
This project is a Cargo workspace providing a suite of Rust crates for interacting with Google Gemini models, featuring tool usage (MCP), persistent memory, and a CLI.
9+
10+
See the main [README.md](mdc:README.md) for a full overview.
11+
12+
## Core Crates:
13+
14+
* **`gemini-core` ([core/README.md](mdc:core/README.md))**: Foundational components. Includes the async `GeminiClient`, API types, configuration (`GeminiConfig`), error handling, and shared JSON-RPC types.
15+
* **`gemini-ipc` ([ipc/README.md](mdc:ipc/README.md))**: Centralizes Inter-Process Communication message definitions (structs/enums) used between daemons (`HAPPE`, `IDA`, `mcp-hostd`) and clients (`gemini-cli`).
16+
* **`gemini-mcp` ([mcp/README.md](mdc:mcp/README.md))**: Implements the Model Context Protocol (MCP) **host** side. Manages discovering, launching, and communicating with MCP **servers** (tools). Includes the `mcp-hostd` binary and built-in server implementations.
17+
* **`gemini-memory` ([memory/README.md](mdc:memory/README.md))**: Implements persistent semantic memory using LanceDB. Relies on an MCP host (`McpHostInterface`) for embedding generation.
18+
* **`gemini-cli` ([cli/README.md](mdc:cli/README.md))**: The main command-line interface. Integrates the other crates for user interaction, tool use, and memory.
19+
* **`HAPPE` ([HAPPE/README.md](mdc:HAPPE/README.md))**: Host Application Environment daemon. Manages interactions between user, LLM, `IDA`, and MCP servers. Intended as the primary execution environment.
20+
* **`IDA` ([IDA/README.md](mdc:IDA/README.md))**: Internal Dialogue App daemon. Manages persistent memory and background cognitive tasks, communicating with `HAPPE` via IPC.

.cursor/rules/02-cli.mdc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
description: Use this rule to understand CLI configuration (API key, model, prompts, history/memory flags), history persistence via the wrapper function, interaction modes, MCP/memory integration points, and where to configure tool servers.
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Gemini Rust Suite: Command Line Interface (CLI)
7+
8+
The primary user interface is provided by the `gemini-cli` crate ([cli/README.md](mdc:cli/README.md)).
9+
10+
## Key Components:
11+
12+
* **Binary:** `gemini-cli-bin` is the compiled executable.
13+
* **Wrapper:** The `gemini` command (usually installed via `install.sh` to `~/.bashrc` or `~/.zshrc`) is a crucial wrapper around `gemini-cli-bin` that manages session environment variables (`GEMINI_SESSION_ID`) for history persistence across separate command invocations. See the wrapper function definition in [README.md](mdc:README.md).
14+
* **Dependencies:** Leverages `gemini-core` for API communication, `gemini-mcp` for tool integration, and `gemini-memory` for memory features.
15+
* **Configuration:**
16+
* `~/.config/gemini-cli/config.toml`: Stores API key, default model, system prompt, feature flags (history, memory). Managed via `gemini --set-...` flags or manual editing. See [cli/README.md](mdc:cli/README.md) for details.
17+
* `~/.config/gemini-cli/mcp_servers.json`: Configures connections to MCP servers (used by the embedded MCP host or the `mcp-hostd` daemon). See [mcp/README.md](mdc:mcp/README.md).
18+
* **Interaction Modes:** Supports single-shot prompts (default), interactive chat (`-i`), task loops (`-t`), and combined interactive task mode (`-i -t`). These are detailed in [INTERACTIVE-TASKS.md](mdc:INTERACTIVE-TASKS.md).
19+
* **History:** Saved in `~/.local/share/gemini-cli/history/`. Requires the wrapper function for history across commands.
20+
* **Built-in Server Execution:** Can run built-in MCP servers directly via flags (`--filesystem-mcp`, `--command-mcp`, `--memory-store-mcp`).

.cursor/rules/03-mcp.mdc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: Use this rule to learn how external tools are integrated via MCP, find the MCP host code and server configuration file, identify built-in and external (E5 embedding) servers, and trace how Gemini function calls are executed as MCP tool requests.
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Gemini Rust Suite: Model Context Protocol (MCP)
7+
8+
MCP allows Gemini to use external tools and services. This is primarily handled by the `gemini-mcp` crate ([mcp/README.md](mdc:mcp/README.md)).
9+
10+
## Key Components:
11+
12+
* **MCP Host:** The core logic resides in `McpHost` ([mcp/src/host.rs](mdc:mcp/src/host.rs)). It discovers, manages, and communicates with MCP servers.
13+
* Can run embedded within the CLI.
14+
* Can run as a standalone daemon: `mcp-hostd` ([mcp/src/bin/mcp-hostd.rs](mdc:mcp/src/bin/mcp-hostd.rs)).
15+
* **MCP Servers:** External processes providing tools (capabilities). The host connects to them based on configuration.
16+
* **Configuration:** Defined in `~/.config/gemini-cli/mcp_servers.json`. Specifies server name, transport (stdio, sse, websocket), command to launch (for stdio), etc. See [mcp/README.md](mdc:mcp/README.md) for format.
17+
* **Transports:** Supports `Stdio`, `SSE`, and `WebSocket`.
18+
* **Communication:** Uses JSON-RPC 2.0.
19+
* **Built-in Servers:** The source code for common servers is included within `gemini-mcp`:
20+
* `command` ([mcp/src/servers/command/mod.rs](mdc:mcp/src/servers/command/mod.rs)): Executes shell commands (requires user confirmation by default).
21+
* `filesystem` ([mcp/src/servers/filesystem/mod.rs](mdc:mcp/src/servers/filesystem/mod.rs)): Reads/writes files, lists directories.
22+
* `memory_store` ([mcp/src/servers/memory_store/mod.rs](mdc:mcp/src/servers/memory_store/mod.rs)): Simple key-value storage (distinct from the main `gemini-memory` LanceDB store). *Note: This server might be less relevant now with the dedicated E5 embedding server.*
23+
* These can be run via CLI flags (e.g., `gemini --filesystem-mcp`) or configured in `mcp_servers.json` to be launched by the host.
24+
* **External Python E5 Embedding Server:** A crucial server for semantic memory.
25+
* Located in [mcp_embedding_server/](mdc:mcp_embedding_server).
26+
* Provides the `embed` tool using E5 models.
27+
* Communicates via `stdio` JSON-RPC.
28+
* See [mcp_embedding_server/README.md](mdc:mcp_embedding_server/README.md) and the server script [mcp_embedding_server/server.py](mdc:mcp_embedding_server/server.py).
29+
* **Gemini Integration:**
30+
* The MCP host translates server capabilities into Gemini `FunctionDeclaration`s.
31+
* It dispatches Gemini `FunctionCall`s to the appropriate MCP server's tool.
32+
* Handles user confirmation for potentially sensitive tools.

.cursor/rules/04-memory.mdc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: Use this rule to locate the persistent memory storage code (MemoryStore), understand the LanceDB backend and embedding generation via MCP, see how prompts are enhanced with context, and find semantic search/filtering logic.
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Gemini Rust Suite: Persistent Memory and Embeddings
7+
8+
Persistent, semantic memory is managed by the `gemini-memory` crate ([memory/README.md](mdc:memory/README.md)).
9+
10+
## Key Components:
11+
12+
* **`MemoryStore` ([memory/src/store.rs](mdc:memory/src/store.rs))**: Main struct for interacting with the memory database.
13+
* **`Memory` Struct ([memory/src/memory.rs](mdc:memory/src/memory.rs))**: Represents a single memory item (key, value, timestamp, tags, metadata, vector embedding).
14+
* **LanceDB Integration:**
15+
* Uses LanceDB ([https://lancedb.com/](mdc:https:/lancedb.com)) as the vector database for efficient storage and semantic search.
16+
* Database typically located at `~/.local/share/gemini-cli/memory.db` ([memory/src/config.rs](mdc:memory/src/config.rs)).
17+
* Schema defined using Apache Arrow ([memory/src/schema.rs](mdc:memory/src/schema.rs)), including a vector column.
18+
* CRUD operations and vector search are implemented using the LanceDB Rust SDK.
19+
* **Embeddings via MCP:**
20+
* Generating vector embeddings (numerical representations of text meaning) is required for semantic search.
21+
* This is **delegated** to an external MCP server providing an `embed` tool.
22+
* The `MemoryStore` requires an implementation of the `McpHostInterface` trait ([memory/src/broker.rs](mdc:memory/src/broker.rs)) to call this external tool.
23+
* The primary embedding server used is the Python E5 server ([mcp_embedding_server/README.md](mdc:mcp_embedding_server/README.md)).
24+
* **Semantic Search:**
25+
* The `get_semantically_similar` method ([memory/src/store.rs](mdc:memory/src/store.rs)) takes query text, calls the MCP `embed` tool to get the query vector, and then performs a vector similarity search in LanceDB.
26+
* More advanced search combining semantic, keyword, tag, and time filters is available via `search_memories` ([memory/src/store.rs](mdc:memory/src/store.rs)).
27+
* **Prompt Enhancement:**
28+
* The `enhance_prompt` function ([memory/src/broker.rs](mdc:memory/src/broker.rs)) automatically retrieves relevant memories based on a user prompt (using semantic search) and prepends them as context.
29+
* Configurable via the `enable_memory_broker` flag/setting.
30+
* **Auto Memory:**
31+
* Automatically extracts and saves key information from conversations.
32+
* Configurable via the `enable_auto_memory` flag/setting. Requires analysis logic (potentially involving LLM calls) and uses the `add_memory` function.

.cursor/rules/05-daemons-ipc.mdc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: Use this rule to understand the roles of the HAPPE/IDA/mcp-hostd daemons, how HAPPE and IDA communicate via IPC, find the IPC message structure definitions, trace the memory retrieval flow, and identify daemon responsibilities.
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Gemini Rust Suite: Daemons and IPC
7+
8+
For more complex, persistent scenarios, the system uses background daemons communicating via Inter-Process Communication (IPC).
9+
10+
* **`HAPPE` Daemon ([HAPPE/README.md](mdc:HAPPE/README.md))**: The Host Application Environment. Orchestrates user interactions, LLM calls, MCP tool execution, and communication with `IDA`.
11+
* **`IDA` Daemon ([IDA/README.md](mdc:IDA/README.md))**: Internal Dialogue App. Manages persistent memory interactions (retrieval/storage via Memory MCP Server) and other background cognitive tasks.
12+
* **`mcp-hostd` Daemon ([mcp/README.md](mdc:mcp/README.md))**: Standalone MCP host process. Manages connections to MCP tool servers.
13+
* **IPC Definitions (`gemini-ipc`)**: The `gemini-ipc` crate ([ipc/README.md](mdc:ipc/README.md)) centralizes message structures for communication between these components.
14+
* `internal_messages.rs` ([ipc/src/internal_messages.rs](mdc:ipc/src/internal_messages.rs)): Defines messages between `HAPPE` and `IDA`.
15+
* `daemon_messages.rs` ([ipc/src/daemon_messages.rs](mdc:ipc/src/daemon_messages.rs)): Defines messages between clients (like `gemini-cli`) and `mcp-hostd`.
16+
* **Communication Flow:**
17+
* `User/Client` -> `HAPPE`
18+
* `HAPPE` <-> `IDA` (via IPC, using `internal_messages`)
19+
* `IDA` -> `Memory MCP Server` (via MCP)
20+
* `HAPPE` -> `Main LLM`
21+
* `HAPPE` -> `Other MCP Servers` (via MCP, potentially through `mcp-hostd`)
22+
* `gemini-cli` -> `mcp-hostd` (optional, via IPC, using `daemon_messages`)

.cursor/rules/coding-style.mdc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Coding Style Guidelines
7+
8+
This project follows standard Rust coding conventions.
9+
10+
## Formatting
11+
12+
* Code formatting is enforced using `rustfmt`. Ensure `rustfmt` is run before committing changes.
13+
* Configuration for `rustfmt` might be present in `rustfmt.toml` or within [`Cargo.toml`](mdc:Cargo.toml) files (though none was found in the root `Cargo.toml`). Assume default settings if no explicit configuration is found.
14+
15+
## Linting
16+
17+
* Code linting is performed using `clippy`.
18+
* Run `cargo clippy` regularly to catch potential issues and improve code quality.
19+
* Clippy configuration (e.g., allowed lints) might be present in `clippy.toml` or via attributes in the source code.
20+
21+
## General Conventions
22+
23+
* Follow the guidelines outlined in the official [Rust API Guidelines](mdc:https:/rust-lang.github.io/api-guidelines).
24+
* Use descriptive names for variables, functions, structs, enums, and traits.
25+
* Write documentation comments for public APIs.

Cargo.lock

Lines changed: 96 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ members = [
55
"core", # Core Gemini API interaction, structs, errors
66
"mcp", # MCP/Tool calling client logic
77
"memory", # Persistent memory storage logic
8+
"ipc", # Inter-process communication definitions
9+
"ida", # Internal Dialogue App daemon
10+
"happe", # Host Application Environment daemon (Placeholder)
811
]
912

13+
[workspace.lints]
14+
# Define workspace-wide lint settings here if needed
15+
1016
[workspace.dependencies]
1117
# Define shared dependencies here
1218
tokio = { version = "1", features = ["full"] }

HAPPE/Cargo.toml

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)