kibi-opencode 0.5.0 → 0.5.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.
- package/README.md +19 -9
- package/dist/config.js +0 -4
- package/dist/index.js +1 -1
- package/dist/prompt.js +40 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,10 +29,10 @@ The plugin provides context-aware prompt guidance based on recent edits and work
|
|
|
29
29
|
|
|
30
30
|
### Targeted Validation Checks
|
|
31
31
|
|
|
32
|
-
After KB-document edits, the plugin queues targeted
|
|
32
|
+
After KB-document edits, the plugin queues targeted validation rules to run via background sync operations:
|
|
33
33
|
|
|
34
|
-
- **Must-priority requirement edits**:
|
|
35
|
-
- **Other requirement/scenario/test/ADR/fact edits**:
|
|
34
|
+
- **Must-priority requirement edits**: elevated validation including coverage checks
|
|
35
|
+
- **Other requirement/scenario/test/ADR/fact edits**: standard validation for required fields and dangling references
|
|
36
36
|
|
|
37
37
|
The plugin inspects requirement frontmatter to detect `priority: must` and schedules elevated validation for critical requirements. Runs in background after sync completes, non-blocking. Can be disabled via `guidance.targetedChecks.enabled: false`.
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ When `guidance.warnOnKbEdits` is enabled (default: `true`), manual edits to file
|
|
|
42
42
|
|
|
43
43
|
- Logs warning immediately
|
|
44
44
|
- Injects prompt guidance discouraging manual `.kb` edits
|
|
45
|
-
- Directs agents toward MCP
|
|
45
|
+
- Directs agents toward public MCP tools (`kb_upsert`, `kb_query`, etc.)
|
|
46
46
|
|
|
47
47
|
### Session Tracking and Pattern Detection
|
|
48
48
|
|
|
@@ -96,9 +96,18 @@ The plugin injects guidance into OpenCode sessions to improve agent grounding. U
|
|
|
96
96
|
|
|
97
97
|
OpenCode exposes Kibi MCP prompts as slash commands. The `/init-kibi` command runs the retroactive bootstrap workflow using only public MCP tools.
|
|
98
98
|
|
|
99
|
-
###
|
|
99
|
+
### Discovery-first MCP guidance
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
Agent-visible guidance is intentionally limited to the curated public MCP surface:
|
|
102
|
+
|
|
103
|
+
- Discovery/reporting: `kb_search`, `kb_query`, `kb_status`, `kb_find_gaps`, `kb_coverage`, `kb_graph`
|
|
104
|
+
- Mutation/validation: `kb_upsert`, `kb_delete`, `kb_check`
|
|
105
|
+
|
|
106
|
+
The plugin guidance prefers `kb_search` for broad discovery, then `kb_query` for exact/source-linked follow-up.
|
|
107
|
+
|
|
108
|
+
### Background Sync Operations
|
|
109
|
+
|
|
110
|
+
Internal maintenance automatically syncs the knowledge base after relevant file edits:
|
|
102
111
|
|
|
103
112
|
- Single-flight scheduler (no overlapping syncs)
|
|
104
113
|
- Debounce window (default: 2000ms)
|
|
@@ -183,10 +192,11 @@ This repository's OpenCode setup dogfoods local built artifacts. `opencode.json`
|
|
|
183
192
|
|
|
184
193
|
## Architecture
|
|
185
194
|
|
|
186
|
-
This is a thin bridge layer:
|
|
195
|
+
This is a thin bridge layer per ADR-016:
|
|
187
196
|
|
|
188
|
-
-
|
|
189
|
-
-
|
|
197
|
+
- **Agent-visible guidance**: Public MCP tools (`kb_query`, `kb_upsert`, `kb_check`, etc.) and sanctioned slash commands (`/init-kibi`)
|
|
198
|
+
- **Discovery-first workflow**: Agents are guided to use `kb_search` first, then `kb_query`, then reporting tools like `kb_status`, `kb_find_gaps`, `kb_coverage`, and `kb_graph` when needed
|
|
199
|
+
- **Internal maintenance**: Background sync operations handle KB synchronization; agents do NOT run sync commands directly
|
|
190
200
|
- Does NOT own KB storage, parsing, or validation
|
|
191
201
|
|
|
192
202
|
### Future: File-Context Virtual Injection
|
package/dist/config.js
CHANGED
|
@@ -132,10 +132,6 @@ export function loadConfig(projectDir = process.cwd()) {
|
|
|
132
132
|
if (projectObj)
|
|
133
133
|
merged = { ...merged, ...projectObj };
|
|
134
134
|
const validated = validateAndMerge(merged);
|
|
135
|
-
if (!validated) {
|
|
136
|
-
logger.warn("Configuration invalid, falling back to defaults");
|
|
137
|
-
return DEFAULTS;
|
|
138
|
-
}
|
|
139
135
|
return validated;
|
|
140
136
|
}
|
|
141
137
|
// implements REQ-opencode-kibi-plugin-v1
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
1
2
|
import { analyzeCodeFile, } from "./comment-analysis.js";
|
|
2
3
|
import * as config from "./config.js";
|
|
3
4
|
import * as fileFilter from "./file-filter.js";
|
|
4
5
|
import * as logger from "./logger.js";
|
|
5
|
-
import * as path from "node:path";
|
|
6
6
|
import { analyzePath } from "./path-kind.js";
|
|
7
7
|
import { injectPrompt } from "./prompt.js";
|
|
8
8
|
import { isMustPriorityRequirement } from "./requirement-doc.js";
|
package/dist/prompt.js
CHANGED
|
@@ -3,18 +3,19 @@ const SENTINEL = "<!-- kibi-opencode -->";
|
|
|
3
3
|
/**
|
|
4
4
|
* Build prompt guidance block based on path kind.
|
|
5
5
|
*/
|
|
6
|
-
// implements REQ-opencode-kibi-plugin-v1
|
|
6
|
+
// implements REQ-opencode-kibi-plugin-v1, REQ-opencode-agent-mcp-only
|
|
7
7
|
function buildContextualGuidance(context) {
|
|
8
8
|
const parts = [SENTINEL];
|
|
9
9
|
if (context.hasRecentKbEdit) {
|
|
10
10
|
parts.push(`
|
|
11
11
|
⚠️ **WARNING: Do not edit .kb/** files manually.**
|
|
12
12
|
|
|
13
|
-
The Kibi knowledge base is managed through MCP and
|
|
13
|
+
The Kibi knowledge base is managed through public MCP tools and internal maintenance flows. Direct manual edits to files under .kb/** can cause inconsistencies and should be avoided.
|
|
14
14
|
|
|
15
15
|
Instead:
|
|
16
|
+
- Use kb_search to discover relevant entities
|
|
16
17
|
- Use kb_upsert to create/update entities
|
|
17
|
-
- Use kb_query
|
|
18
|
+
- Use kb_query for exact lookup and source-linked follow-up
|
|
18
19
|
- Use kb_check to validate consistency
|
|
19
20
|
`);
|
|
20
21
|
}
|
|
@@ -22,10 +23,11 @@ Instead:
|
|
|
22
23
|
parts.push(`
|
|
23
24
|
🔧 **Bootstrap required**
|
|
24
25
|
|
|
25
|
-
This repository does not appear to have Kibi initialized.
|
|
26
|
-
- \`/init-kibi\` for retroactive bootstrap of existing repos
|
|
27
|
-
-
|
|
28
|
-
|
|
26
|
+
This repository does not appear to have Kibi initialized. Agents should:
|
|
27
|
+
- Use \`/init-kibi\` for retroactive bootstrap of existing repos (preferred MCP command)
|
|
28
|
+
- Ask the user/operator to run setup or repair outside this session if \`/init-kibi\` is insufficient
|
|
29
|
+
|
|
30
|
+
Do not run \`kibi\` CLI commands directly; use the public MCP tools (kb_search, kb_query, kb_status, kb_find_gaps, kb_coverage, kb_graph, kb_upsert, kb_delete, kb_check).
|
|
29
31
|
`);
|
|
30
32
|
}
|
|
31
33
|
const codeEdits = context.recentEdits.filter((e) => e.kind === "code");
|
|
@@ -76,9 +78,11 @@ This ensures behavior is documented and traceable.`;
|
|
|
76
78
|
routingMessage = `📝 **Code changes detected**
|
|
77
79
|
|
|
78
80
|
Before implementing or explaining code:
|
|
79
|
-
1. **
|
|
80
|
-
2. **
|
|
81
|
-
3. **
|
|
81
|
+
1. **Discover first** - Run kb_search to find related requirements, ADRs, tests, facts, and symbols.
|
|
82
|
+
2. **Follow up exactly** - Run kb_query by sourceFile, id, type, or tags once you know what you need.
|
|
83
|
+
3. **Check freshness when needed** - Run kb_status if you need branch or stale-state confirmation.
|
|
84
|
+
4. **Prefer Kibi over comments** - Store durable knowledge in KB entities instead of inline comments.
|
|
85
|
+
5. **Add traceability** - Add traceability comments to new or modified functions/classes so the pre-commit hook can verify coverage (e.g., \`// implements REQ-xxx\` in JS/TS or docstring references in Python).`;
|
|
82
86
|
}
|
|
83
87
|
parts.push(routingMessage);
|
|
84
88
|
}
|
|
@@ -87,9 +91,11 @@ Before implementing or explaining code:
|
|
|
87
91
|
📝 **Code changes detected**
|
|
88
92
|
|
|
89
93
|
Before implementing or explaining code:
|
|
90
|
-
1. **
|
|
91
|
-
2. **
|
|
92
|
-
3. **
|
|
94
|
+
1. **Discover first** - Run kb_search to find related requirements, ADRs, tests, facts, and symbols.
|
|
95
|
+
2. **Follow up exactly** - Run kb_query by sourceFile, id, type, or tags once you know what you need.
|
|
96
|
+
3. **Check freshness when needed** - Run kb_status if you need branch or stale-state confirmation.
|
|
97
|
+
4. **Prefer Kibi over comments** - Store durable knowledge in KB entities instead of inline comments.
|
|
98
|
+
5. **Add traceability** - Add traceability comments to new or modified functions/classes (e.g., \`// implements REQ-xxx\` in JS/TS or docstring references in Python) so the pre-commit hook can verify coverage.
|
|
93
99
|
|
|
94
100
|
If you're adding long explanatory comments, consider routing that knowledge to:
|
|
95
101
|
- \`FACT\` for domain invariants, properties, limits, cardinalities
|
|
@@ -121,14 +127,14 @@ Preferred structure:
|
|
|
121
127
|
|
|
122
128
|
When editing KB documentation:
|
|
123
129
|
1. **Maintain traceability** - Link entities using relationships: specified_by (req→scenario), verified_by (req→test), etc.
|
|
124
|
-
2. **Validate** -
|
|
130
|
+
2. **Validate** - Use \`kb_check\` after making changes to catch integrity issues.
|
|
125
131
|
3. **Follow entity patterns** - Ensure each entity has proper frontmatter with required fields.
|
|
126
132
|
`);
|
|
127
133
|
}
|
|
128
134
|
if (parts.length === 1) {
|
|
129
135
|
parts.push(`This project uses Kibi (via MCP). Prefer storing durable knowledge in Kibi over code comments.
|
|
130
136
|
|
|
131
|
-
Before changing behavior:
|
|
137
|
+
Before changing behavior: use kb_search for discovery, then kb_query by sourceFile, id, type, or tags for exact follow-up; do not rely on undocumented tools.
|
|
132
138
|
|
|
133
139
|
Keep changed symbols traceable: add \`// implements REQ-xxx\` to every new or modified function/class so the pre-commit hook can verify coverage.
|
|
134
140
|
|
|
@@ -137,12 +143,16 @@ Run kb_check after KB mutations.
|
|
|
137
143
|
Dogfood note for this repo: OpenCode here uses local built \`kibi-mcp\` and \`kibi-opencode\` artifacts. If you change package versions or local package wiring, run \`bun run build\` before relying on OpenCode in this workspace.
|
|
138
144
|
|
|
139
145
|
**Kibi-first workflow:**
|
|
140
|
-
1. **Discover**: Run
|
|
141
|
-
2. **
|
|
142
|
-
3. **
|
|
143
|
-
4. **
|
|
146
|
+
1. **Discover**: Run kb_search to find relevant requirements, ADRs, tests, facts, and symbols.
|
|
147
|
+
2. **Confirm**: Run kb_query with sourceFile, id, type, or tags once you know the exact follow-up target.
|
|
148
|
+
3. **Inspect freshness**: Run kb_status when branch or stale-state confidence matters.
|
|
149
|
+
4. **Document intent**: If you are about to explain code, STOP. Route that explanation to kb_upsert instead of inline comments.
|
|
150
|
+
5. **Link during work**: When creating KB entities, include relationship rows: specified_by (req→scenario), verified_by (req→test), implements (symbol→req), covered_by (symbol→test).
|
|
151
|
+
6. **Validate**: Run kb_check after KB mutations to catch violations early.
|
|
152
|
+
|
|
153
|
+
**Public Kibi tools only:** kb_search, kb_query, kb_status, kb_find_gaps, kb_coverage, kb_graph, kb_upsert, kb_delete, kb_check.
|
|
144
154
|
|
|
145
|
-
|
|
155
|
+
Do not invoke Kibi CLI commands directly from the agent.
|
|
146
156
|
|
|
147
157
|
Bootstrap existing repos: use \`/init-kibi\` to run the retroactive initialization workflow.`);
|
|
148
158
|
}
|
|
@@ -154,7 +164,7 @@ Bootstrap existing repos: use \`/init-kibi\` to run the retroactive initializati
|
|
|
154
164
|
const BASE_GUIDANCE = `${SENTINEL}
|
|
155
165
|
This project uses Kibi (via MCP). Prefer storing durable knowledge in Kibi over code comments.
|
|
156
166
|
|
|
157
|
-
Before changing behavior:
|
|
167
|
+
Before changing behavior: use kb_search for discovery, then kb_query by sourceFile, id, type, or tags for exact follow-up; do not rely on undocumented tools.
|
|
158
168
|
|
|
159
169
|
Keep changed symbols traceable: add \`// implements REQ-xxx\` to every new or modified function/class so the pre-commit hook can verify coverage.
|
|
160
170
|
|
|
@@ -163,12 +173,16 @@ Run kb_check after KB mutations.
|
|
|
163
173
|
Dogfood note for this repo: OpenCode here uses local built \`kibi-mcp\` and \`kibi-opencode\` artifacts. If you change package versions or local package wiring, run \`bun run build\` before relying on OpenCode in this workspace.
|
|
164
174
|
|
|
165
175
|
**Kibi-first workflow:**
|
|
166
|
-
1. **Discover**: Run
|
|
167
|
-
2. **
|
|
168
|
-
3. **
|
|
169
|
-
4. **
|
|
176
|
+
1. **Discover**: Run kb_search to find relevant requirements, ADRs, tests, facts, and symbols.
|
|
177
|
+
2. **Confirm**: Run kb_query with sourceFile, id, type, or tags once you know the exact follow-up target.
|
|
178
|
+
3. **Inspect freshness**: Run kb_status when branch or stale-state confidence matters.
|
|
179
|
+
4. **Document intent**: If you are about to explain code, STOP. Route that explanation to kb_upsert instead of inline comments.
|
|
180
|
+
5. **Link during work**: When creating KB entities, include relationship rows: specified_by (req→scenario), verified_by (req→test), implements (symbol→req), covered_by (symbol→test).
|
|
181
|
+
6. **Validate**: Run kb_check after KB mutations to catch violations early.
|
|
182
|
+
|
|
183
|
+
**Public Kibi tools only:** kb_search, kb_query, kb_status, kb_find_gaps, kb_coverage, kb_graph, kb_upsert, kb_delete, kb_check.
|
|
170
184
|
|
|
171
|
-
|
|
185
|
+
Do not invoke Kibi CLI commands directly from the agent.
|
|
172
186
|
|
|
173
187
|
Bootstrap existing repos: use \`/init-kibi\` to run the retroactive initialization workflow.`;
|
|
174
188
|
/**
|