1- # opencode-knowledge
1+ # opencode-knowledge < img src = " ./assets/opencode-knowledge-logo.png " align = " right " height = " 100 " />
22
3- A comprehensive knowledge management system for OpenCode that provides:
4- - ** Role-based AI personalities** - Customize OpenCode's communication style
5- - ** Knowledge vault** - Organize coding standards, patterns, and best practices
6- - ** Tag-based search** - Quickly find relevant knowledge packages
7- - ** Session management** - Track loaded packages and optimize token usage
3+ An OpenCode plugin that dynamically loads knowledge from your vault on-demand. Add any content you want, the AI figures out what to load using tags and descriptions.
84
95## Features
106
11- ### 🎭 Personality System
12- Choose from different AI personas (staff engineer, frontend specialist, cthulhu, etc.) that influence how OpenCode communicates and approaches problems.
13-
147### 📚 Knowledge Vault
15- Create a structured library of markdown-based knowledge packages with frontmatter metadata for easy discovery and loading.
8+
9+ Organize coding standards, patterns, and best practices in markdown files with frontmatter metadata.
1610
1711### 🔍 Smart Search
18- Tag-based search system finds relevant knowledge packages based on your current task.
12+
13+ Tag-based search finds relevant packages. The AI uses tags and descriptions to discover the right context.
1914
2015### 💾 Session Persistence
21- Tracks loaded packages across sessions and provides token-optimized context injection.
16+
17+ Automatically indexes your vault on session start and tracks loaded packages.
2218
2319---
2420
@@ -56,9 +52,9 @@ Create `.opencode/knowledge/settings.json` in your project:
5652}
5753```
5854
59- ### 2. Create Knowledge Vault (Optional)
55+ ### 2. Create Knowledge Vault
6056
61- If you want to use the knowledge management features, create a vault structure:
57+ Create the vault directory structure:
6258
6359``` bash
6460mkdir -p .opencode/knowledge/vault/standards
@@ -81,10 +77,12 @@ category: standards
8177# Code Conventions
8278
8379## Naming
80+
8481- Use camelCase for variables and functions
8582- Use PascalCase for classes and types
8683
8784## Formatting
85+
8886- Use single quotes for strings
8987- Line width: 100 characters
9088- Always use semicolons
@@ -93,27 +91,16 @@ category: standards
9391### 4. Start OpenCode Session
9492
9593The knowledge catalog is ** automatically built on session start** . Just start a new session and the plugin will:
94+
9695- Scan your vault for packages
9796- Build the searchable catalog
9897- Inject knowledge map on first message
9998
100- ### 5. Search and Load Knowledge
101-
102- Search for packages by tags:
103-
104- ```
105- knowledge_search [tags=typescript,conventions]
106- ```
107-
108- Load packages into your session:
109-
110- ```
111- knowledge_load [paths=standards/code-conventions.md]
112- ```
113-
11499---
115100
116- ## Available Personalities
101+ ## Personalities (Optional)
102+
103+ You can optionally configure OpenCode's communication style by setting a personality in your ` settings.json ` .
117104
118105### staff_engineer
119106
@@ -129,73 +116,6 @@ Ancient cosmic entity providing technical guidance with existential dread and co
129116
130117---
131118
132- ## Tools
133-
134- ### knowledge_search
135-
136- Search for knowledge packages by tags.
137-
138- ```
139- knowledge_search [tags=typescript,react,testing]
140- ```
141-
142- ** Parameters** : Comma-separated list of tags
143-
144- ** Output** : Ranked list of matching packages with relevance scores
145-
146- ** Example** :
147- ```
148- Found 5 packages matching [typescript, react]:
149-
150- - **frontend/react-patterns.md** (75%)
151- Tags: typescript, react, patterns
152- Common React patterns and best practices
153-
154- - **standards/typescript-conventions.md** (50%)
155- Tags: typescript, conventions
156- TypeScript coding standards
157- ```
158-
159- ---
160-
161- ### knowledge_load
162-
163- Load knowledge packages into the current session.
164-
165- ```
166- knowledge_load [paths=standards/code-conventions.md,frontend/react-patterns.md]
167- ```
168-
169- ** Parameters** : Comma-separated list of package paths (relative to vault/)
170-
171- ** Output** : Package content injected into context
172-
173- ** Features** :
174- - Deduplication (won't load same package twice)
175- - Session tracking (remembers what's loaded)
176- - Error handling (warns about missing packages)
177-
178- ---
179-
180- ### knowledge_index
181-
182- Manually rebuild the knowledge catalog from your vault.
183-
184- ```
185- knowledge_index
186- ```
187-
188- ** Output** : Summary of categories and packages indexed.
189-
190- ** Note** : The catalog is ** automatically built on session start** , so you rarely need this tool.
191-
192- ** When to use** :
193- - After adding packages mid-session
194- - If auto-build failed during session start
195- - To verify catalog contents
196-
197- ---
198-
199119## Knowledge Package Format
200120
201121Knowledge packages are markdown files with YAML frontmatter:
@@ -212,8 +132,8 @@ required_knowledge:
212132 - other-package-1
213133 - other-package-2
214134file_patterns:
215- - " * .tsx"
216- - " * .test.ts"
135+ - ' * .tsx'
136+ - ' * .test.ts'
217137---
218138
219139# Package Title
@@ -223,13 +143,13 @@ Your knowledge content here...
223143
224144### Frontmatter Fields
225145
226- | Field | Required | Description |
227- | -------| ----------| -------------|
228- | ` tags ` | Yes | Array of searchable tags |
229- | ` description ` | Yes | Brief summary (used in search results) |
230- | ` category ` | Yes | Category for organization (e.g., ` frontend ` , ` backend ` , ` standards ` ) |
231- | ` required_knowledge ` | No | Other packages that should be loaded first |
232- | ` file_patterns ` | No | File patterns where this knowledge applies |
146+ | Field | Required | Description |
147+ | -------------------- | -------- | -------------------------------------------------------------------- |
148+ | ` tags ` | Yes | Array of searchable tags |
149+ | ` description ` | Yes | Brief summary (used in search results) |
150+ | ` category ` | Yes | Category for organization (e.g., ` frontend ` , ` backend ` , ` standards ` ) |
151+ | ` required_knowledge ` | No | Other packages that should be loaded first |
152+ | ` file_patterns ` | No | File patterns where this knowledge applies |
233153
234154---
235155
@@ -239,9 +159,9 @@ Your knowledge content here...
239159your-project/
240160└── .opencode/
241161 └── knowledge/
242- ├── settings.json # Plugin configuration
243- ├── knowledge.json # Auto-generated catalog (gitignored)
244- ├── vault/ # Your knowledge packages
162+ ├── settings.json
163+ ├── knowledge.json
164+ ├── vault/
245165 │ ├── frontend/
246166 │ │ ├── react-patterns.md
247167 │ │ └── state-management.md
@@ -250,139 +170,13 @@ your-project/
250170 │ └── standards/
251171 │ ├── code-conventions.md
252172 │ └── testing-guide.md
253- └── tracker/ # Session state (gitignored)
173+ └── tracker/
254174 ├── session-state.jsonl
255175 └── knowledge-reads.jsonl
256176```
257177
258178---
259179
260- ## Token Optimization
261-
262- The plugin uses a single-phase approach for optimal token usage:
263-
264- ### First Message Only
265- - Shows full category-tag map (~ 500-1000 tokens depending on vault size)
266- - Injects personality
267- - Documents available tools with examples
268- - Creates session state
269-
270- ### Subsequent Messages
271- - No knowledge context injected
272- - LLM uses memory of first message
273- - ** 100% token savings** on subsequent messages
274-
275- This approach provides significant token savings while ensuring the LLM has all the context it needs from the initial session setup.
276-
277- ---
278-
279- ## Example Vault Structure
280-
281- Here's a recommended organization pattern:
282-
283- ```
284- vault/
285- ├── frontend/
286- │ ├── react-patterns.md # React best practices
287- │ ├── state-management.md # Redux, Context, etc.
288- │ ├── component-testing.md # Testing components
289- │ └── accessibility.md # A11y guidelines
290- ├── backend/
291- │ ├── api-design.md # REST/GraphQL patterns
292- │ ├── database-patterns.md # ORM, migrations
293- │ └── error-handling.md # Error handling strategies
294- ├── standards/
295- │ ├── code-conventions.md # General coding standards
296- │ ├── git-workflow.md # Branch strategy, commits
297- │ └── code-review.md # Review guidelines
298- └── infrastructure/
299- ├── docker-patterns.md # Container best practices
300- ├── ci-cd.md # Pipeline patterns
301- └── monitoring.md # Observability
302- ```
303-
304- ---
305-
306- ## Advanced Usage
307-
308- ### Creating Cross-Referenced Packages
309-
310- Use ` required_knowledge ` to create dependency chains:
311-
312- ``` markdown
313- ---
314- tags:
315- - react
316- - advanced
317- - performance
318- description: Advanced React performance optimization
319- category: frontend
320- required_knowledge:
321- - frontend/react-patterns
322- - standards/code-conventions
323- ---
324-
325- # Advanced React Performance
326-
327- This builds on basic patterns...
328- ```
329-
330- ### File Pattern Targeting
331-
332- Specify when knowledge applies:
333-
334- ``` markdown
335- ---
336- tags:
337- - testing
338- - jest
339- description: Jest testing patterns
340- category: frontend
341- file_patterns:
342- - "* .test.ts"
343- - "* .test.tsx"
344- - "* .spec.ts"
345- ---
346-
347- # Jest Testing Guide
348- ```
349-
350- ---
351-
352- ## Troubleshooting
353-
354- ### Settings file not found
355-
356- ** Error** : ` CONFIGURATION ERROR: Settings file not found `
357-
358- ** Solution** : Create ` .opencode/knowledge/settings.json ` with:
359- ``` json
360- {
361- "role" : " staff_engineer"
362- }
363- ```
364-
365- ### Personality not loading
366-
367- ** Error** : ` CONFIGURATION ERROR: Personality file not found `
368-
369- ** Solution** : Verify the role name in ` settings.json ` matches an available personality (` staff_engineer ` or ` cthulhu ` )
370-
371- ### Catalog not found
372-
373- ** Error** : ` Knowledge catalog not found. Run knowledge_index first. `
374-
375- ** Solution** : Run ` knowledge_index ` to build the catalog from your vault
376-
377- ### Search returns no results
378-
379- ** Possible causes** :
380- 1 . Catalog is outdated → Run ` knowledge_index `
381- 2 . Tags don't match → Check tag spelling
382- 3 . No packages with those tags → Add packages or adjust search
383-
384- ---
385-
386180## Development
387181
388182### Building
@@ -412,17 +206,6 @@ mise run format
412206
413207---
414208
415- ## Roadmap
416-
417- - [ ] Auto-load packages based on file patterns
418- - [ ] Knowledge package dependencies resolution
419- - [ ] Usage analytics and metrics
420- - [ ] Export/import vault bundles
421- - [ ] Knowledge package templates
422- - [ ] VSCode extension for vault management
423-
424- ---
425-
426209## Contributing
427210
428211Contributions welcome! Please:
0 commit comments