1pub const SETUP: &str = r#"
8## MCP Server Configuration
9
10Subcog exposes tools and resources via the Model Context Protocol (MCP).
11
12### Claude Desktop Setup
13
14Add to `~/.config/claude/claude_desktop_config.json`:
15
16```json
17{
18 "mcpServers": {
19 "subcog": {
20 "command": "subcog",
21 "args": ["serve"]
22 }
23 }
24}
25```
26
27### Claude Code Plugin Setup
28
29Add to `~/.claude/settings.json`:
30
31```json
32{
33 "mcpServers": {
34 "subcog": {
35 "command": "subcog",
36 "args": ["serve"]
37 }
38 }
39}
40```
41
42### Configuration File
43
44Create `~/.config/subcog/config.toml`:
45
46```toml
47# Default data_dir is ~/.config/subcog; override if desired.
48data_dir = "~/.config/subcog"
49
50[features]
51secrets_filter = true
52pii_filter = false
53auto_capture = true
54```
55
56## Available MCP Tools
57
58Once configured, these tools are available:
59
60| Tool | Description |
61|------|-------------|
62| `subcog_capture` | Capture a memory |
63| `subcog_recall` | Search memories |
64| `subcog_status` | Check system status |
65| `subcog_namespaces` | List memory namespaces |
66| `subcog_consolidate` | Consolidate memories (LLM) |
67| `subcog_enrich` | Enrich a memory (LLM) |
68| `subcog_reindex` | Rebuild search index |
69| `prompt_understanding` | Guidance for using Subcog MCP tools |
70
71## Available MCP Resources
72
73| Resource | Description |
74|----------|-------------|
75| `subcog://help` | Help index |
76| `subcog://help/{topic}` | Topic-specific help |
77| `subcog://_` | List all memories across all domains |
78| `subcog://project/_` | List project-scoped memories |
79| `subcog://user/_` | List user-scoped memories |
80| `subcog://org/_` | List org-scoped memories (if enabled) |
81| `subcog://memory/{id}` | Get specific memory |
82
83## Filter Syntax (for subcog_recall filter)
84
85```
86ns:decisions # filter by namespace
87tag:rust # filter by tag
88tag:rust,mcp # OR (any tag)
89tag:rust tag:error # AND (all tags)
90-tag:test # exclude tag
91since:7d # last 7 days
92source:src/* # source path
93```
94"#;
95
96pub const CONCEPTS: &str = r"
98## Namespaces
99
100Memories are organized into namespaces:
101
102| Namespace | Purpose |
103|-----------|---------|
104| `decisions` | Architectural and design decisions |
105| `patterns` | Discovered patterns and conventions |
106| `learnings` | Lessons learned from debugging |
107| `context` | Important background information |
108| `tech-debt` | Technical debt tracking |
109| `apis` | API documentation and contracts |
110| `config` | Configuration details |
111| `security` | Security findings and notes |
112| `performance` | Optimization notes |
113| `testing` | Test strategies and edge cases |
114
115## Domains
116
117Domains provide scope isolation:
118
119- **Project** (`project`): Scoped to the current repository
120- **User** (`user`): Shared across all projects for the current user
121- **Organization** (`org`): Shared within an org when enabled
122
123Org scope is optional and controlled by `SUBCOG_ORG_SCOPE_ENABLED`.
124
125## URN Scheme
126
127Memories are addressed via URNs:
128
129```
130subcog://{domain}/{namespace}/{id}
131```
132
133Examples:
134```
135subcog://project/decisions/abc123
136subcog://user/decisions/def456
137```
138
139## Memory Lifecycle
140
1411. **Active**: Default state, fully searchable
1422. **Archived**: Less frequently accessed
1433. **Superseded**: Replaced by newer memory
1444. **Pending**: Awaiting review
1455. **Deleted**: Marked for cleanup
1466. **Tombstoned**: Removed from search results; retained for cleanup/audit
147";
148
149pub const CAPTURE: &str = r#"
151## Using the subcog_capture Tool
152
153### Basic Capture
154
155```json
156{
157 "tool": "subcog_capture",
158 "arguments": {
159 "namespace": "decisions",
160 "content": "Use PostgreSQL for primary storage"
161 }
162}
163```
164
165### With Tags
166
167```json
168{
169 "tool": "subcog_capture",
170 "arguments": {
171 "namespace": "patterns",
172 "content": "Use thiserror for custom error types",
173 "tags": ["rust", "error-handling"]
174 }
175}
176```
177
178### With Source Reference
179
180```json
181{
182 "tool": "subcog_capture",
183 "arguments": {
184 "namespace": "learnings",
185 "content": "JWT validation requires explicit algorithm specification",
186 "source": "src/auth.rs:42"
187 }
188}
189```
190
191## Tool Parameters
192
193| Parameter | Required | Description |
194|-----------|----------|-------------|
195| `namespace` | Yes | One of: decisions, patterns, learnings, context, tech-debt, apis, config, security, performance, testing |
196| `content` | Yes | The memory content to capture |
197| `tags` | No | Array of tags for categorization |
198| `source` | No | Source file reference (e.g., "src/auth.rs:42") |
199
200## Best Practices
201
2021. **Be Specific**: Include context and rationale
2032. **Use Tags**: Add relevant keywords for better search
2043. **Reference Sources**: Link to code or documentation
2054. **Choose Correct Namespace**: Match content to category
206
207## Namespace Selection Guide
208
209| Signal Words | Namespace |
210|--------------|-----------|
211| "decided", "chose", "going with" | `decisions` |
212| "always", "never", "convention" | `patterns` |
213| "TIL", "learned", "discovered" | `learnings` |
214| "because", "constraint" | `context` |
215| "TODO", "FIXME", "temporary" | `tech-debt` |
216"#;
217
218pub const SEARCH: &str = r#"
220## Using the subcog_recall Tool
221
222### Basic Search
223
224```json
225{
226 "tool": "subcog_recall",
227 "arguments": {
228 "query": "database storage decision"
229 }
230}
231```
232
233### Search Modes
234
235#### Hybrid (Default)
236Combines vector similarity and BM25 text search with RRF fusion:
237
238```json
239{
240 "tool": "subcog_recall",
241 "arguments": {
242 "query": "authentication patterns",
243 "mode": "hybrid"
244 }
245}
246```
247
248#### Vector Only
249Pure semantic similarity search:
250
251```json
252{
253 "tool": "subcog_recall",
254 "arguments": {
255 "query": "how to handle errors",
256 "mode": "vector"
257 }
258}
259```
260
261#### Text Only
262Traditional keyword search with BM25 ranking:
263
264```json
265{
266 "tool": "subcog_recall",
267 "arguments": {
268 "query": "PostgreSQL",
269 "mode": "text"
270 }
271}
272```
273
274### Filtering by Namespace
275
276```json
277{
278 "tool": "subcog_recall",
279 "arguments": {
280 "query": "storage",
281 "namespace": "decisions"
282 }
283}
284```
285
286### Limiting Results
287
288```json
289{
290 "tool": "subcog_recall",
291 "arguments": {
292 "query": "API design",
293 "limit": 5
294 }
295}
296```
297
298## Tool Parameters
299
300| Parameter | Required | Default | Description |
301|-----------|----------|---------|-------------|
302| `query` | Yes | - | Natural language search query |
303| `mode` | No | `hybrid` | Search mode: `hybrid`, `vector`, or `text` |
304| `namespace` | No | all | Filter by namespace |
305| `limit` | No | 10 | Maximum results (max: 50) |
306
307## Browsing Memories via Resources
308
309Access memories directly via MCP resources:
310
311- `subcog://_` - All memories across all domains
312- `subcog://project/_` - Project-scoped memories
313- `subcog://user/_` - User-scoped memories
314- `subcog://org/_` - Org-scoped memories (if enabled)
315- `subcog://memory/{id}` - Get specific memory by ID
316
317For advanced filtering by namespace, tags, time, etc., use `subcog_recall` with the `filter` parameter.
318
319## Understanding Scores
320
321| Score Range | Relevance |
322|-------------|-----------|
323| 0.9+ | Very high (likely exact match) |
324| 0.7-0.9 | Good (closely related) |
325| 0.5-0.7 | Moderate (broader context) |
326| <0.5 | Low (tangential) |
327"#;
328
329pub const WORKFLOWS: &str = r#"
331## Common MCP Workflows
332
333### Session Start: Load Context
334
335At session start, search for relevant memories based on the current project:
336
337```json
338{
339 "tool": "subcog_recall",
340 "arguments": {
341 "query": "current project context patterns decisions",
342 "limit": 10
343 }
344}
345```
346
347### During Work: Capture Insights
348
349When you discover something worth remembering:
350
351```json
352{
353 "tool": "subcog_capture",
354 "arguments": {
355 "namespace": "learnings",
356 "content": "JWT tokens must specify algorithm explicitly to prevent alg:none attacks",
357 "tags": ["security", "jwt", "authentication"]
358 }
359}
360```
361
362### Related Context: Find Similar
363
364When working on a topic, find related memories:
365
366```json
367{
368 "tool": "subcog_recall",
369 "arguments": {
370 "query": "authentication security patterns",
371 "mode": "hybrid",
372 "namespace": "patterns"
373 }
374}
375```
376
377## Browsing via Resources
378
379Access memories directly without search:
380
381| Resource URI | Returns |
382|--------------|---------|
383| `subcog://_` | All memories across all domains (JSON) |
384| `subcog://project/_` | Project-scoped memories |
385| `subcog://user/_` | User-scoped memories |
386| `subcog://org/_` | Org-scoped memories (if enabled) |
387| `subcog://memory/{id}` | Specific memory by ID |
388
389For filtering by namespace, tags, time, etc., use `subcog_recall` with the `filter` parameter.
390
391## Status Check
392
393Monitor system health:
394
395```json
396{
397 "tool": "subcog_status",
398 "arguments": {}
399}
400```
401
402Returns: memory count, index status, storage backend info.
403"#;
404
405pub const TROUBLESHOOTING: &str = r#"
407## Common Issues
408
409### Tool Returns Empty Results
410
411If `subcog_recall` returns no results:
412
4131. **Check status**: Use `subcog_status` tool to verify index exists
4142. **Try broader query**: Use simpler search terms
4153. **Check namespace**: Remove namespace filter to search all
416
417```json
418{
419 "tool": "subcog_status",
420 "arguments": {}
421}
422```
423
424### "Secret detected" Error
425
426The `subcog_capture` tool blocked content with potential secrets:
427
4281. Remove the secret from content
4292. Check `~/.config/subcog/config.toml`:
430 - `[features] secrets_filter = false` to disable secrets filtering
431
432### "Index not found"
433
434Call the status tool to trigger initialization:
435
436```json
437{
438 "tool": "subcog_status",
439 "arguments": {}
440}
441```
442
443### Slow Search Performance
444
4451. Reduce `limit` parameter (default 10, max 50)
4462. Use `mode: "text"` for faster keyword-only search
4473. Add `namespace` filter to narrow scope
448
449```json
450{
451 "tool": "subcog_recall",
452 "arguments": {
453 "query": "specific term",
454 "mode": "text",
455 "namespace": "decisions",
456 "limit": 5
457 }
458}
459```
460
461## Report Issues
462
463GitHub: https://github.com/zircote/subcog/issues
464"#;
465
466pub const ADVANCED: &str = r#"
468## LLM-Powered Tools
469
470These tools require an LLM provider configured in `~/.config/subcog/config.toml`.
471
472### Memory Consolidation
473
474Merge similar memories using LLM analysis:
475
476```json
477{
478 "tool": "subcog_consolidate",
479 "arguments": {
480 "namespace": "learnings",
481 "strategy": "merge",
482 "dry_run": true
483 }
484}
485```
486
487**Strategies:**
488- `merge` - Combine similar memories into one
489- `summarize` - Create summary of related memories
490- `dedupe` - Remove exact duplicates
491
492### Memory Enrichment
493
494Improve a memory with better structure and tags:
495
496```json
497{
498 "tool": "subcog_enrich",
499 "arguments": {
500 "memory_id": "decisions_abc123",
501 "enrich_tags": true,
502 "enrich_structure": true,
503 "add_context": true
504 }
505}
506```
507
508## LLM Provider Configuration
509
510Configure in `~/.config/subcog/config.toml`:
511
512```toml
513[llm]
514provider = "anthropic" # or "openai", "ollama", "lmstudio"
515api_key = "${ANTHROPIC_API_KEY}"
516model = "claude-3-haiku-20240307"
517```
518
519| Provider | Model | Use Case |
520|----------|-------|----------|
521| Anthropic | claude-3-* | Best quality |
522| OpenAI | gpt-4o-mini | Fast, good quality |
523| Ollama | llama3.2 | Local, private |
524| LM Studio | varies | Local, flexible |
525
526## Search Optimization
527
528### Hybrid Search Tuning
529
530For precision-focused results:
531
532```json
533{
534 "tool": "subcog_recall",
535 "arguments": {
536 "query": "exact topic",
537 "mode": "text",
538 "limit": 5
539 }
540}
541```
542
543For concept-focused results:
544
545```json
546{
547 "tool": "subcog_recall",
548 "arguments": {
549 "query": "general concept or idea",
550 "mode": "vector",
551 "limit": 10
552 }
553}
554```
555
556## Embedding Model
557
558Default: `all-MiniLM-L6-v2` (384 dimensions)
559
560The embedding model is used for semantic similarity search in vector mode.
561"#;
562
563pub const PROMPTS: &str = r#"
565## User-Defined Prompts
566
567Subcog supports saving and reusing prompt templates with variable substitution.
568
569## MCP Tools for Prompts
570
571| Tool | Description |
572|------|-------------|
573| `prompt_save` | Save a prompt template |
574| `prompt_list` | List saved prompts |
575| `prompt_get` | Get a prompt by name |
576| `prompt_run` | Execute a prompt with variables |
577| `prompt_delete` | Delete a prompt |
578
579## Saving Prompts
580
581### From Content
582
583```json
584{
585 "tool": "prompt_save",
586 "arguments": {
587 "name": "code-review",
588 "content": "Review the {{language}} code in {{file}} for:\n- Security issues\n- Performance\n- Best practices",
589 "description": "Code review checklist template",
590 "tags": ["review", "quality"]
591 }
592}
593```
594
595### From File
596
597```json
598{
599 "tool": "prompt_save",
600 "arguments": {
601 "name": "refactor-plan",
602 "file_path": "/path/to/prompt.md"
603 }
604}
605```
606
607## Variable Syntax
608
609Variables use double-brace syntax: `{{variable_name}}`
610
611### Required vs Optional
612
613| Syntax | Type | Behavior |
614|--------|------|----------|
615| `{{name}}` | Required | Must be provided |
616| `{{name:default}}` | Optional | Uses default if not provided |
617
618### Example Template
619
620```markdown
621---
622name: api-design
623description: API endpoint design guide
624tags:
625 - api
626 - design
627variables:
628 - name: resource
629 description: The resource being designed
630 required: true
631 - name: version
632 description: API version
633 default: v1
634---
635
636Design a REST API for the {{resource}} resource.
637
638API Version: {{version}}
639
640Include:
641- Endpoints (GET, POST, PUT, DELETE)
642- Request/response schemas
643- Error handling
644```
645
646## Running Prompts
647
648### With All Variables
649
650```json
651{
652 "tool": "prompt_run",
653 "arguments": {
654 "name": "code-review",
655 "variables": {
656 "language": "Rust",
657 "file": "src/main.rs"
658 }
659 }
660}
661```
662
663### With Defaults
664
665```json
666{
667 "tool": "prompt_run",
668 "arguments": {
669 "name": "api-design",
670 "variables": {
671 "resource": "users"
672 }
673 }
674}
675```
676
677The `version` variable will use its default value of "v1".
678
679## Domain Scopes
680
681Prompts support three domain scopes:
682
683| Scope | Description | Search Order |
684|-------|-------------|--------------|
685| `project` | Current repository | Searched first |
686| `user` | User-wide prompts | Searched second |
687| `org` | Organization-wide | Searched last |
688
689### Saving to a Specific Domain
690
691```json
692{
693 "tool": "prompt_save",
694 "arguments": {
695 "name": "deploy-checklist",
696 "content": "...",
697 "domain": "org"
698 }
699}
700```
701
702### Retrieving with Domain Fallback
703
704When getting a prompt, subcog searches in order: project -> user -> org
705
706```json
707{
708 "tool": "prompt_get",
709 "arguments": {
710 "name": "deploy-checklist"
711 }
712}
713```
714
715## Listing and Filtering
716
717### List All Prompts
718
719```json
720{
721 "tool": "prompt_list",
722 "arguments": {}
723}
724```
725
726### Filter by Domain
727
728```json
729{
730 "tool": "prompt_list",
731 "arguments": {
732 "domain": "user"
733 }
734}
735```
736
737### Filter by Tags
738
739```json
740{
741 "tool": "prompt_list",
742 "arguments": {
743 "tags": ["api", "design"]
744 }
745}
746```
747
748### Filter by Name Pattern
749
750```json
751{
752 "tool": "prompt_list",
753 "arguments": {
754 "name_pattern": "code-*"
755 }
756}
757```
758
759## CLI Commands
760
761### Save a Prompt
762
763```bash
764# From content
765subcog prompt save my-prompt "Template with {{var}}"
766
767# From file
768subcog prompt save my-prompt --from-file prompt.md
769
770# With options
771subcog prompt save my-prompt "content" \
772 --description "Description here" \
773 --tags "tag1,tag2" \
774 --domain user
775```
776
777### List Prompts
778
779```bash
780subcog prompt list
781subcog prompt list --domain user
782subcog prompt list --tags api,design
783subcog prompt list --format json
784```
785
786### Get a Prompt
787
788```bash
789subcog prompt get my-prompt
790subcog prompt get my-prompt --format yaml
791```
792
793### Run a Prompt
794
795```bash
796# With variables
797subcog prompt run my-prompt var1=value1 var2=value2
798
799# Interactive mode (prompts for missing variables)
800subcog prompt run my-prompt --interactive
801```
802
803### Export a Prompt
804
805```bash
806subcog prompt export my-prompt --output prompt.md
807subcog prompt export my-prompt --format yaml
808```
809
810### Delete a Prompt
811
812```bash
813subcog prompt delete my-prompt --domain project --force
814```
815
816## Supported Formats
817
818| Format | Extension | Description |
819|--------|-----------|-------------|
820| Markdown | `.md` | YAML front matter + content |
821| YAML | `.yaml`, `.yml` | Full structured format |
822| JSON | `.json` | Machine-readable format |
823| Plain Text | `.txt` | Content only (no metadata) |
824
825## Best Practices
826
8271. **Use descriptive names**: `api-design` not `prompt1`
8282. **Add descriptions**: Explain the prompt's purpose
8293. **Tag consistently**: Use standard tags across prompts
8304. **Provide defaults**: Make prompts easier to use
8315. **Document variables**: Add descriptions for clarity
8326. **Use domain scoping**: Share org-wide, customize per project
833"#;