Skip to content

Commit 1d39484

Browse files
committed
Updated proxy contract (Release v0.6.1)
1 parent c83972a commit 1d39484

File tree

3 files changed

+145
-45
lines changed

3 files changed

+145
-45
lines changed

examples/Crush.md

Lines changed: 116 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,50 @@
11
# tinyMem Crush/Rush Integration Guide
22

3-
[Crush](https://github.com/charmbracelet/crush) (and its CLI `rush`) supports the **Model Context Protocol (MCP)**, making integration with tinyMem native and powerful.
3+
[Crush](https://github.com/charmbracelet/crush) (and its CLI `rush`) supports both **Model Context Protocol (MCP)** and standard **OpenAI-compatible APIs**, giving you two flexible ways to integrate with tinyMem.
44

5-
## Configuration
5+
## Option A: MCP Mode (Recommended)
6+
7+
This mode allows Rush to natively use tinyMem's tools (like `memory_query`, `memory_write`, `memory_health`) to actively manage context during your chat.
8+
9+
### 1. Configuration
610

711
Crush looks for a configuration file at `.crush.json` (project local) or `~/.config/crush/crush.json` (global).
812

9-
1. **Install tinyMem** and ensure it's in your PATH.
10-
2. **Create/Edit `.crush.json`:**
11-
12-
```json
13-
{
14-
"mcp": {
15-
"tinymem": {
16-
"type": "stdio",
17-
"command": "tinymem",
18-
"args": ["mcp"],
19-
"timeout": 120,
20-
"env": {
21-
"TINYMEM_METRICS_ENABLED": "true"
22-
}
23-
}
13+
**Create/Edit `.crush.json`:**
14+
15+
```json
16+
{
17+
"mcp": {
18+
"tinymem": {
19+
"type": "stdio",
20+
"command": "tinymem",
21+
"args": ["mcp"],
22+
"timeout": 120,
23+
"env": {
24+
"TINYMEM_METRICS_ENABLED": "true"
2425
}
2526
}
26-
```
27+
}
28+
}
29+
```
2730

28-
*If `tinymem` is not in PATH, replace `"command": "tinymem"` with `"command": "/absolute/path/to/tinymem"`.*
31+
*If `tinymem` is not in PATH, replace `"command": "tinymem"` with `"command": "/absolute/path/to/tinymem"`.*
2932

30-
## Usage
33+
### 2. Usage (MCP)
3134

3235
Start Rush:
3336
```bash
3437
rush
3538
```
3639

37-
### Querying Memory
38-
You can ask Rush natural language questions about the project:
39-
> "What decisions did we make about the API structure?"
40+
Rush will now have access to tinyMem tools:
41+
- **Querying:** "What decisions did we make about the API structure?" (Rush calls `memory_query`)
42+
- **Writing:** "Remember that we decided to use Postgres for production." (Rush calls `memory_write`)
43+
- **Health:** "Check if the memory system is working." (Rush calls `memory_health`)
4044

41-
Rush will automatically call `memory_query` to fetch context before answering.
45+
### 3. Advanced MCP Config
4246

43-
### Writing Memory
44-
> "Remember that we decided to use Postgres for production."
45-
46-
Rush will call `memory_write` to store this decision.
47-
48-
### Health Check
49-
> "Check if the memory system is working."
50-
51-
Rush will call `memory_health`.
52-
53-
## Advanced Crush Config
54-
55-
You can tune the integration in `.crush.json`:
47+
You can tune the MCP integration in `.crush.json`:
5648

5749
```json
5850
{
@@ -65,18 +57,102 @@ You can tune the integration in `.crush.json`:
6557
"TINYMEM_LOG_LEVEL": "debug",
6658
"TINYMEM_RECALL_MAX_ITEMS": "20"
6759
},
68-
"disabled_tools": [] // You can explicitly disable tools if needed
60+
"disabled_tools": []
6961
}
7062
},
7163
"system_prompt_suffix": "\n\nUse tinyMem to check context before answering code questions."
7264
}
7365
```
7466

67+
---
68+
69+
## Option B: Proxy Mode
70+
71+
Use this mode if you want tinyMem to act as a transparent "middle-man," automatically injecting relevant memory context into every prompt before it reaches your LLM.
72+
73+
### 1. Configure tinyMem
74+
75+
Create a `config.toml` file (e.g., in your project root or home directory) to tell tinyMem where your actual LLM is running (e.g., Ollama, LM Studio, vLLM).
76+
77+
```toml
78+
[agent]
79+
contract = 'small'
80+
81+
[proxy]
82+
port = 8080
83+
base_url = "http://127.0.0.1:1234" # Your actual LLM backend (e.g., LM Studio, Ollama)
84+
85+
[llm]
86+
model = "unsloth/rnj-1-instruct" # The model name your backend expects
87+
timeout = 5000
88+
89+
[recall]
90+
max_items = 10
91+
92+
[cove]
93+
enabled = true
94+
confidence_threshold = 0.6
95+
96+
[logging]
97+
level = "info"
98+
file = "tinymem.log"
99+
```
100+
101+
### 2. Start tinyMem Proxy
102+
103+
Open a terminal and run:
104+
105+
```bash
106+
tinymem proxy
107+
```
108+
*You should see logs indicating the proxy is listening on port 8080.*
109+
110+
### 3. Configure Crush
111+
112+
Edit your `.crush.json` to treat tinyMem as an OpenAI-compatible provider.
113+
114+
```json
115+
{
116+
"providers": {
117+
"Ollama": {
118+
"name": "Ollama",
119+
"base_url": "http://localhost:8080/v1",
120+
"type": "openai-compat",
121+
"models": [
122+
{
123+
"name": "rnj",
124+
"id": "unsloth/rnj-1-instruct",
125+
"context_window": 256000,
126+
"default_max_tokens": 20000
127+
}
128+
]
129+
}
130+
}
131+
}
132+
```
133+
134+
* **`base_url`**: Must point to tinyMem (`http://localhost:8080/v1`).
135+
* **`id`**: Should match the model name configured in `config.toml` (or be compatible with your backend).
136+
137+
### 4. Usage (Proxy)
138+
139+
Start Rush:
140+
```bash
141+
rush
142+
```
143+
144+
In this mode, interaction is implicit:
145+
- **Context Injection:** When you ask a question, tinyMem automatically searches its database and prepends relevant memories to your prompt.
146+
- **Transparency:** Crush thinks it's talking directly to the LLM, but tinyMem is enriching the conversation in the background.
147+
148+
---
149+
75150
## Configuration Reference
76151

77152
For full configuration options, see [Configuration.md](Configuration.md).
78153

79154
## Troubleshooting
80155

81-
- **Tools Not Available:** Check `rush --version` to ensure you have a version with MCP support.
82-
- **Execution Errors:** Run `rush` with debug flags or check `.tinyMem/logs/` to see if tinyMem is crashing or erroring.
156+
- **Tools Not Available (MCP):** Check `rush --version` to ensure you have a version with MCP support.
157+
- **Connection Refused (Proxy):** Ensure `tinymem proxy` is running and the port matches your `.crush.json` configuration.
158+
- **Logs:** Check `.tinyMem/logs/` or the terminal where you ran `tinymem proxy` to see if requests are being processed.

internal/memory/contract.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func EnsureProjectContracts(projectRoot string, contractType ContractType) error
4949
if err := os.MkdirAll(agentsDir, 0755); err != nil {
5050
return fmt.Errorf("error creating directory %s: %w", agentsDir, err)
5151
}
52+
if err := ensureAgentContractFiles(projectRoot); err != nil {
53+
return fmt.Errorf("error ensuring agent contract files: %w", err)
54+
}
5255

5356
files := []string{"AGENTS.md", "QWEN.md", "GEMINI.md", "CLAUDE.md", "CODEX.md"}
5457
locations := []string{projectRoot, agentsDir}
@@ -80,10 +83,6 @@ func EnsureProjectContracts(projectRoot string, contractType ContractType) error
8083
}
8184
}
8285

83-
if err := updateReadme(projectRoot, contractType); err != nil {
84-
return fmt.Errorf("error updating README.md: %w", err)
85-
}
86-
8786
fmt.Println("Agent contracts synchronized.")
8887
return nil
8988
}
@@ -191,6 +190,31 @@ func createFileWithContract(filename, contractContent string) error {
191190
return nil
192191
}
193192

193+
func ensureAgentContractFiles(projectRoot string) error {
194+
agentsDir := filepath.Join(projectRoot, "docs", "agents")
195+
contractTypes := []ContractType{ContractTypeLarge, ContractTypeSmall}
196+
for _, cType := range contractTypes {
197+
contractPath := filepath.Join(agentsDir, cType.fileName())
198+
if _, err := os.Stat(contractPath); err == nil {
199+
continue
200+
} else if !os.IsNotExist(err) {
201+
return fmt.Errorf("error checking %s: %w", contractPath, err)
202+
}
203+
204+
fmt.Printf("Downloading missing %s contract to %s...\n", cType, contractPath)
205+
content, err := getContractContent(projectRoot, cType)
206+
if err != nil {
207+
return fmt.Errorf("error fetching %s contract: %w", cType, err)
208+
}
209+
210+
if err := createFileWithContract(contractPath, content); err != nil {
211+
return fmt.Errorf("error creating %s: %w", contractPath, err)
212+
}
213+
}
214+
215+
return nil
216+
}
217+
194218
func updateReadme(projectRoot string, contractType ContractType) error {
195219
readmePath := filepath.Join(projectRoot, "README.md")
196220
content, err := os.ReadFile(readmePath)

internal/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package version
22

33
// Version is the current version of tinyMem
44
// This can be overridden at build time using -ldflags "-X github.com/daverage/tinymem/internal/version.Version=vX.Y.Z"
5-
var Version = "v0.6.0"
5+
var Version = "v0.6.1"

0 commit comments

Comments
 (0)