opencode-knowledge 0.4.1-next.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.
Files changed (3) hide show
  1. package/README.md +44 -253
  2. package/dist/index.js +18 -23
  3. 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
- 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.
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
- 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.
16
10
 
17
11
  ### 🔍 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.
19
14
 
20
15
  ### 💾 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.
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 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)
45
+ ### 1. Create Knowledge Vault
60
46
 
61
- If you want to use the knowledge management features, create a vault structure:
47
+ Create the vault directory structure:
62
48
 
63
49
  ```bash
64
50
  mkdir -p .opencode/knowledge/vault/standards
65
51
  ```
66
52
 
67
- ### 3. Create Your First Knowledge Package
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
- ### 4. Start OpenCode Session
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
- ### 5. Search and Load Knowledge
89
+ ### 4. Configure Personality (Optional)
101
90
 
102
- Search for packages by tags:
91
+ Optionally configure OpenCode's communication style by creating `.opencode/knowledge/settings.json`:
103
92
 
104
- ```
105
- knowledge_search [tags=typescript,conventions]
93
+ ```json
94
+ {
95
+ "role": "staff_engineer"
96
+ }
106
97
  ```
107
98
 
108
- Load packages into your session:
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
- ## Available Personalities
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
- - "*.tsx"
216
- - "*.test.ts"
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 | 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 |
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 # Plugin configuration
243
- ├── knowledge.json # Auto-generated catalog (gitignored)
244
- ├── vault/ # Your knowledge packages
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/ # Session state (gitignored)
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.
package/dist/index.js CHANGED
@@ -90,22 +90,15 @@ async function createSessionState(sessionId) {
90
90
  return;
91
91
  }
92
92
  const settingsPath = ".opencode/knowledge/settings.json";
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;
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}`);
107
101
  }
108
- throw new Error(`Error reading settings.json: ${error}`);
109
102
  }
110
103
  const state = {
111
104
  role,
@@ -12813,7 +12806,6 @@ var opencodeKnowledge = async () => {
12813
12806
  try {
12814
12807
  const state = getSessionState(input.sessionID);
12815
12808
  if (state.isFirstPrompt) {
12816
- const personality = await loadPersonality(state.role);
12817
12809
  const vaultExists = existsSync6(".opencode/knowledge/vault");
12818
12810
  if (vaultExists) {
12819
12811
  const categoryTagMap = buildCategoryTagMap();
@@ -12835,15 +12827,18 @@ var opencodeKnowledge = async () => {
12835
12827
  messageID: input.messageID || ""
12836
12828
  });
12837
12829
  }
12838
- output.parts.push({
12839
- type: "text",
12840
- text: `## Role Context
12830
+ if (state.role) {
12831
+ const personality = await loadPersonality(state.role);
12832
+ output.parts.push({
12833
+ type: "text",
12834
+ text: `## Role Context
12841
12835
 
12842
12836
  ${personality}`,
12843
- id: `personality-${Date.now()}`,
12844
- sessionID: input.sessionID,
12845
- messageID: input.messageID || ""
12846
- });
12837
+ id: `personality-${Date.now()}`,
12838
+ sessionID: input.sessionID,
12839
+ messageID: input.messageID || ""
12840
+ });
12841
+ }
12847
12842
  updateSessionState(input.sessionID, {
12848
12843
  isFirstPrompt: false,
12849
12844
  categoriesShown: vaultExists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-knowledge",
3
- "version": "0.4.1-next.1",
3
+ "version": "0.4.2-next.1",
4
4
  "description": "An OpenCode plugin",
5
5
  "author": {
6
6
  "name": "msegoviadev",