opencode-knowledge 0.4.2-next.1 → 0.4.2

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.
Files changed (3) hide show
  1. package/README.md +253 -44
  2. package/dist/index.js +23 -18
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,24 @@
1
- # opencode-knowledge <img src="./assets/opencode-knowledge-logo.png" align="right" height="100"/>
1
+ # opencode-knowledge
2
2
 
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.
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
4
8
 
5
9
  ## Features
6
10
 
7
- ### 📚 Knowledge Vault
11
+ ### 🎭 Personality System
12
+ Choose from different AI personas (staff engineer, frontend specialist, cthulhu, etc.) that influence how OpenCode communicates and approaches problems.
8
13
 
9
- Organize coding standards, patterns, and best practices in markdown files with frontmatter metadata.
14
+ ### 📚 Knowledge Vault
15
+ Create a structured library of markdown-based knowledge packages with frontmatter metadata for easy discovery and loading.
10
16
 
11
17
  ### 🔍 Smart Search
12
-
13
- Tag-based search finds relevant packages. The AI uses tags and descriptions to discover the right context.
18
+ Tag-based search system finds relevant knowledge packages based on your current task.
14
19
 
15
20
  ### 💾 Session Persistence
16
-
17
- Automatically indexes your vault on session start and tracks loaded packages.
21
+ Tracks loaded packages across sessions and provides token-optimized context injection.
18
22
 
19
23
  ---
20
24
 
@@ -42,15 +46,25 @@ Add the plugin to your OpenCode config:
42
46
 
43
47
  ## Quick Start
44
48
 
45
- ### 1. Create Knowledge Vault
49
+ ### 1. Create Settings File
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)
46
60
 
47
- Create the vault directory structure:
61
+ If you want to use the knowledge management features, create a vault structure:
48
62
 
49
63
  ```bash
50
64
  mkdir -p .opencode/knowledge/vault/standards
51
65
  ```
52
66
 
53
- ### 2. Create Your First Knowledge Package
67
+ ### 3. Create Your First Knowledge Package
54
68
 
55
69
  Create `.opencode/knowledge/vault/standards/code-conventions.md`:
56
70
 
@@ -67,42 +81,39 @@ category: standards
67
81
  # Code Conventions
68
82
 
69
83
  ## Naming
70
-
71
84
  - Use camelCase for variables and functions
72
85
  - Use PascalCase for classes and types
73
86
 
74
87
  ## Formatting
75
-
76
88
  - Use single quotes for strings
77
89
  - Line width: 100 characters
78
90
  - Always use semicolons
79
91
  ```
80
92
 
81
- ### 3. Start OpenCode Session
93
+ ### 4. Start OpenCode Session
82
94
 
83
95
  The knowledge catalog is **automatically built on session start**. Just start a new session and the plugin will:
84
-
85
96
  - Scan your vault for packages
86
97
  - Build the searchable catalog
87
98
  - Inject knowledge map on first message
88
99
 
89
- ### 4. Configure Personality (Optional)
100
+ ### 5. Search and Load Knowledge
90
101
 
91
- Optionally configure OpenCode's communication style by creating `.opencode/knowledge/settings.json`:
102
+ Search for packages by tags:
92
103
 
93
- ```json
94
- {
95
- "role": "staff_engineer"
96
- }
104
+ ```
105
+ knowledge_search [tags=typescript,conventions]
97
106
  ```
98
107
 
99
- See the [Personalities](#personalities-optional) section for available options.
108
+ Load packages into your session:
100
109
 
101
- ---
110
+ ```
111
+ knowledge_load [paths=standards/code-conventions.md]
112
+ ```
102
113
 
103
- ## Personalities (Optional)
114
+ ---
104
115
 
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`.
116
+ ## Available Personalities
106
117
 
107
118
  ### staff_engineer
108
119
 
@@ -118,6 +129,73 @@ Ancient cosmic entity providing technical guidance with existential dread and co
118
129
 
119
130
  ---
120
131
 
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
+
121
199
  ## Knowledge Package Format
122
200
 
123
201
  Knowledge packages are markdown files with YAML frontmatter:
@@ -134,8 +212,8 @@ required_knowledge:
134
212
  - other-package-1
135
213
  - other-package-2
136
214
  file_patterns:
137
- - '*.tsx'
138
- - '*.test.ts'
215
+ - "*.tsx"
216
+ - "*.test.ts"
139
217
  ---
140
218
 
141
219
  # Package Title
@@ -145,13 +223,13 @@ Your knowledge content here...
145
223
 
146
224
  ### Frontmatter Fields
147
225
 
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) |
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 |
155
233
 
156
234
  ---
157
235
 
@@ -161,9 +239,9 @@ Your knowledge content here...
161
239
  your-project/
162
240
  └── .opencode/
163
241
  └── knowledge/
164
- ├── settings.json
165
- ├── knowledge.json
166
- ├── vault/
242
+ ├── settings.json # Plugin configuration
243
+ ├── knowledge.json # Auto-generated catalog (gitignored)
244
+ ├── vault/ # Your knowledge packages
167
245
  │ ├── frontend/
168
246
  │ │ ├── react-patterns.md
169
247
  │ │ └── state-management.md
@@ -172,13 +250,139 @@ your-project/
172
250
  │ └── standards/
173
251
  │ ├── code-conventions.md
174
252
  │ └── testing-guide.md
175
- └── tracker/
253
+ └── tracker/ # Session state (gitignored)
176
254
  ├── session-state.jsonl
177
255
  └── knowledge-reads.jsonl
178
256
  ```
179
257
 
180
258
  ---
181
259
 
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
+
182
386
  ## Development
183
387
 
184
388
  ### Building
@@ -208,6 +412,17 @@ mise run format
208
412
 
209
413
  ---
210
414
 
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
+
211
426
  ## Contributing
212
427
 
213
428
  Contributions welcome! Please:
@@ -219,12 +434,6 @@ Contributions welcome! Please:
219
434
 
220
435
  ---
221
436
 
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
-
228
437
  ## License
229
438
 
230
439
  MIT License. See the [LICENSE](LICENSE) file for details.
package/dist/index.js CHANGED
@@ -90,15 +90,22 @@ async function createSessionState(sessionId) {
90
90
  return;
91
91
  }
92
92
  const settingsPath = ".opencode/knowledge/settings.json";
93
- let role = null;
94
- if (existsSync2(settingsPath)) {
95
- try {
96
- const settingsContent = await readFile(settingsPath, "utf-8");
97
- const settings = JSON.parse(settingsContent);
98
- role = settings.role || null;
99
- } catch (error) {
100
- throw new Error(`Error reading settings.json: ${error}`);
93
+ if (!existsSync2(settingsPath)) {
94
+ throw new Error(`CONFIGURATION ERROR: Cannot create session state - settings file not found at ${settingsPath}`);
95
+ }
96
+ let role;
97
+ try {
98
+ const settingsContent = await readFile(settingsPath, "utf-8");
99
+ const settings = JSON.parse(settingsContent);
100
+ if (!settings.role) {
101
+ throw new Error(`CONFIGURATION ERROR: Cannot create session state - missing 'role' field in ${settingsPath}`);
102
+ }
103
+ role = settings.role;
104
+ } catch (error) {
105
+ if (error instanceof Error && error.message.includes("CONFIGURATION ERROR")) {
106
+ throw error;
101
107
  }
108
+ throw new Error(`Error reading settings.json: ${error}`);
102
109
  }
103
110
  const state = {
104
111
  role,
@@ -12806,6 +12813,7 @@ var opencodeKnowledge = async () => {
12806
12813
  try {
12807
12814
  const state = getSessionState(input.sessionID);
12808
12815
  if (state.isFirstPrompt) {
12816
+ const personality = await loadPersonality(state.role);
12809
12817
  const vaultExists = existsSync6(".opencode/knowledge/vault");
12810
12818
  if (vaultExists) {
12811
12819
  const categoryTagMap = buildCategoryTagMap();
@@ -12827,18 +12835,15 @@ var opencodeKnowledge = async () => {
12827
12835
  messageID: input.messageID || ""
12828
12836
  });
12829
12837
  }
12830
- if (state.role) {
12831
- const personality = await loadPersonality(state.role);
12832
- output.parts.push({
12833
- type: "text",
12834
- text: `## Role Context
12838
+ output.parts.push({
12839
+ type: "text",
12840
+ text: `## Role Context
12835
12841
 
12836
12842
  ${personality}`,
12837
- id: `personality-${Date.now()}`,
12838
- sessionID: input.sessionID,
12839
- messageID: input.messageID || ""
12840
- });
12841
- }
12843
+ id: `personality-${Date.now()}`,
12844
+ sessionID: input.sessionID,
12845
+ messageID: input.messageID || ""
12846
+ });
12842
12847
  updateSessionState(input.sessionID, {
12843
12848
  isFirstPrompt: false,
12844
12849
  categoriesShown: vaultExists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-knowledge",
3
- "version": "0.4.2-next.1",
3
+ "version": "0.4.2",
4
4
  "description": "An OpenCode plugin",
5
5
  "author": {
6
6
  "name": "msegoviadev",