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 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 `kibi check` rules to run after sync:
32
+ After KB-document edits, the plugin queues targeted validation rules to run via background sync operations:
33
33
 
34
- - **Must-priority requirement edits**: `kibi check --rules required-fields,no-dangling-refs,must-priority-coverage`
35
- - **Other requirement/scenario/test/ADR/fact edits**: `kibi check --rules required-fields,no-dangling-refs`
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/CLI tools (`kb_upsert`, `kb_query`, etc.)
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
- ### Debounced Sync
99
+ ### Discovery-first MCP guidance
100
100
 
101
- Automatically runs `kibi sync` after relevant file edits:
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
- - Reuses `kibi` CLI for sync operations
189
- - Reuses existing MCP tools (`kb_query`, `kb_check`, etc.)
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 CLI tools. Direct manual edits to files under .kb/** can cause inconsistencies and should be avoided.
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 to inspect the KB
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. Consider running:
26
- - \`/init-kibi\` for retroactive bootstrap of existing repos
27
- - \`kibi init\` for new repos
28
- - \`kibi doctor\` to verify your environment
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. **Query Kibi first** - Run kb_query by sourceFile to find related requirements, ADRs, tests, and symbols.
80
- 2. **Prefer Kibi over comments** - Store durable knowledge in KB entities instead of inline comments.
81
- 3. **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).`;
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. **Query Kibi first** - Run kb_query by sourceFile to find related requirements, ADRs, tests, and symbols.
91
- 2. **Prefer Kibi over comments** - Store durable knowledge in KB entities instead of inline comments.
92
- 3. **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.
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** - Run \`kibi check\` after making changes to catch integrity issues.
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: query Kibi by sourceFile, id, type, or tags; do not rely on undocumented tools.
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 kb_query with filters (sourceFile, type, tags) to find related requirements, ADRs, tests, and symbols.
141
- 2. **Document intent**: If you are about to explain code, STOP. Route that explanation to kb_upsert instead of inline comments.
142
- 3. **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).
143
- 4. **Validate**: Run kb_check after KB mutations to catch violations early.
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
- **Public Kibi tools only:** kb_query, kb_upsert, kb_delete, kb_check.
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: query Kibi by sourceFile, id, type, or tags; do not rely on undocumented tools.
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 kb_query with filters (sourceFile, type, tags) to find related requirements, ADRs, tests, and symbols.
167
- 2. **Document intent**: If you are about to explain code, STOP. Route that explanation to kb_upsert instead of inline comments.
168
- 3. **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).
169
- 4. **Validate**: Run kb_check after KB mutations to catch violations early.
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
- **Public Kibi tools only:** kb_query, kb_upsert, kb_delete, kb_check.
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-opencode",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Kibi OpenCode plugin - thin adapter to integrate Kibi with OpenCode sessions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",