opencode-knowledge 0.4.1 → 0.4.2-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -253
- package/dist/index.js +12876 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
# opencode-knowledge
|
|
1
|
+
# opencode-knowledge <img src="./assets/opencode-knowledge-logo.png" align="right" height="100"/>
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
8
4
|
|
|
9
5
|
## Features
|
|
10
6
|
|
|
11
|
-
### 🎭 Personality System
|
|
12
|
-
Choose from different AI personas (staff engineer, frontend specialist, cthulhu, etc.) that influence how OpenCode communicates and approaches problems.
|
|
13
|
-
|
|
14
7
|
### 📚 Knowledge Vault
|
|
15
|
-
|
|
8
|
+
|
|
9
|
+
Organize coding standards, patterns, and best practices in markdown files with frontmatter metadata.
|
|
16
10
|
|
|
17
11
|
### 🔍 Smart Search
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
Tag-based search finds relevant packages. The AI uses tags and descriptions to discover the right context.
|
|
19
14
|
|
|
20
15
|
### 💾 Session Persistence
|
|
21
|
-
|
|
16
|
+
|
|
17
|
+
Automatically indexes your vault on session start and tracks loaded packages.
|
|
22
18
|
|
|
23
19
|
---
|
|
24
20
|
|
|
@@ -46,25 +42,15 @@ Add the plugin to your OpenCode config:
|
|
|
46
42
|
|
|
47
43
|
## Quick Start
|
|
48
44
|
|
|
49
|
-
### 1. Create
|
|
50
|
-
|
|
51
|
-
Create `.opencode/knowledge/settings.json` in your project:
|
|
52
|
-
|
|
53
|
-
```json
|
|
54
|
-
{
|
|
55
|
-
"role": "staff_engineer"
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### 2. Create Knowledge Vault (Optional)
|
|
45
|
+
### 1. Create Knowledge Vault
|
|
60
46
|
|
|
61
|
-
|
|
47
|
+
Create the vault directory structure:
|
|
62
48
|
|
|
63
49
|
```bash
|
|
64
50
|
mkdir -p .opencode/knowledge/vault/standards
|
|
65
51
|
```
|
|
66
52
|
|
|
67
|
-
###
|
|
53
|
+
### 2. Create Your First Knowledge Package
|
|
68
54
|
|
|
69
55
|
Create `.opencode/knowledge/vault/standards/code-conventions.md`:
|
|
70
56
|
|
|
@@ -81,39 +67,42 @@ category: standards
|
|
|
81
67
|
# Code Conventions
|
|
82
68
|
|
|
83
69
|
## Naming
|
|
70
|
+
|
|
84
71
|
- Use camelCase for variables and functions
|
|
85
72
|
- Use PascalCase for classes and types
|
|
86
73
|
|
|
87
74
|
## Formatting
|
|
75
|
+
|
|
88
76
|
- Use single quotes for strings
|
|
89
77
|
- Line width: 100 characters
|
|
90
78
|
- Always use semicolons
|
|
91
79
|
```
|
|
92
80
|
|
|
93
|
-
###
|
|
81
|
+
### 3. Start OpenCode Session
|
|
94
82
|
|
|
95
83
|
The knowledge catalog is **automatically built on session start**. Just start a new session and the plugin will:
|
|
84
|
+
|
|
96
85
|
- Scan your vault for packages
|
|
97
86
|
- Build the searchable catalog
|
|
98
87
|
- Inject knowledge map on first message
|
|
99
88
|
|
|
100
|
-
###
|
|
89
|
+
### 4. Configure Personality (Optional)
|
|
101
90
|
|
|
102
|
-
|
|
91
|
+
Optionally configure OpenCode's communication style by creating `.opencode/knowledge/settings.json`:
|
|
103
92
|
|
|
104
|
-
```
|
|
105
|
-
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"role": "staff_engineer"
|
|
96
|
+
}
|
|
106
97
|
```
|
|
107
98
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
knowledge_load [paths=standards/code-conventions.md]
|
|
112
|
-
```
|
|
99
|
+
See the [Personalities](#personalities-optional) section for available options.
|
|
113
100
|
|
|
114
101
|
---
|
|
115
102
|
|
|
116
|
-
##
|
|
103
|
+
## Personalities (Optional)
|
|
104
|
+
|
|
105
|
+
The plugin works perfectly fine without any personality configuration. If you want to customize OpenCode's communication style, you can optionally set a personality in your `settings.json`.
|
|
117
106
|
|
|
118
107
|
### staff_engineer
|
|
119
108
|
|
|
@@ -129,73 +118,6 @@ Ancient cosmic entity providing technical guidance with existential dread and co
|
|
|
129
118
|
|
|
130
119
|
---
|
|
131
120
|
|
|
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
|
-
|
|
199
121
|
## Knowledge Package Format
|
|
200
122
|
|
|
201
123
|
Knowledge packages are markdown files with YAML frontmatter:
|
|
@@ -212,8 +134,8 @@ required_knowledge:
|
|
|
212
134
|
- other-package-1
|
|
213
135
|
- other-package-2
|
|
214
136
|
file_patterns:
|
|
215
|
-
-
|
|
216
|
-
-
|
|
137
|
+
- '*.tsx'
|
|
138
|
+
- '*.test.ts'
|
|
217
139
|
---
|
|
218
140
|
|
|
219
141
|
# Package Title
|
|
@@ -223,13 +145,13 @@ Your knowledge content here...
|
|
|
223
145
|
|
|
224
146
|
### Frontmatter Fields
|
|
225
147
|
|
|
226
|
-
| Field
|
|
227
|
-
|
|
228
|
-
| `tags`
|
|
229
|
-
| `description`
|
|
230
|
-
| `category`
|
|
231
|
-
| `required_knowledge` | No
|
|
232
|
-
| `file_patterns`
|
|
148
|
+
| Field | Required | Description |
|
|
149
|
+
| -------------------- | -------- | -------------------------------------------------------------------- |
|
|
150
|
+
| `tags` | Yes | Array of searchable tags |
|
|
151
|
+
| `description` | Yes | Brief summary (used in search results) |
|
|
152
|
+
| `category` | Yes | Category for organization (e.g., `frontend`, `backend`, `standards`) |
|
|
153
|
+
| `required_knowledge` | No | Other packages that should be loaded first |
|
|
154
|
+
| `file_patterns` | No | File patterns where this knowledge applies (not yet implemented) |
|
|
233
155
|
|
|
234
156
|
---
|
|
235
157
|
|
|
@@ -239,9 +161,9 @@ Your knowledge content here...
|
|
|
239
161
|
your-project/
|
|
240
162
|
└── .opencode/
|
|
241
163
|
└── knowledge/
|
|
242
|
-
├── settings.json
|
|
243
|
-
├── knowledge.json
|
|
244
|
-
├── vault/
|
|
164
|
+
├── settings.json
|
|
165
|
+
├── knowledge.json
|
|
166
|
+
├── vault/
|
|
245
167
|
│ ├── frontend/
|
|
246
168
|
│ │ ├── react-patterns.md
|
|
247
169
|
│ │ └── state-management.md
|
|
@@ -250,139 +172,13 @@ your-project/
|
|
|
250
172
|
│ └── standards/
|
|
251
173
|
│ ├── code-conventions.md
|
|
252
174
|
│ └── testing-guide.md
|
|
253
|
-
└── tracker/
|
|
175
|
+
└── tracker/
|
|
254
176
|
├── session-state.jsonl
|
|
255
177
|
└── knowledge-reads.jsonl
|
|
256
178
|
```
|
|
257
179
|
|
|
258
180
|
---
|
|
259
181
|
|
|
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
|
-
|
|
386
182
|
## Development
|
|
387
183
|
|
|
388
184
|
### Building
|
|
@@ -412,17 +208,6 @@ mise run format
|
|
|
412
208
|
|
|
413
209
|
---
|
|
414
210
|
|
|
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
|
-
|
|
426
211
|
## Contributing
|
|
427
212
|
|
|
428
213
|
Contributions welcome! Please:
|
|
@@ -434,6 +219,12 @@ Contributions welcome! Please:
|
|
|
434
219
|
|
|
435
220
|
---
|
|
436
221
|
|
|
222
|
+
## Credits
|
|
223
|
+
|
|
224
|
+
Special thanks to [@canyavall](https://github.com/canyavall) for being the creative mind that came up with the idea and initial working solution. He continues to improve this in the shadows to this day.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
437
228
|
## License
|
|
438
229
|
|
|
439
230
|
MIT License. See the [LICENSE](LICENSE) file for details.
|