kibi-cursor 0.3.1 → 0.5.0

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 (37) hide show
  1. package/.cursor-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +43 -0
  3. package/README.md +5 -3
  4. package/dist/.cursor-plugin/plugin.json +1 -1
  5. package/dist/guidance.d.ts +10 -2
  6. package/dist/guidance.js +26 -17
  7. package/dist/hook-runner.d.ts +1 -0
  8. package/dist/hook-runner.js +34 -7
  9. package/dist/hook-state-storage.d.ts +11 -0
  10. package/dist/hook-state-storage.js +187 -0
  11. package/dist/hook-state.d.ts +3 -4
  12. package/dist/hook-state.js +6 -206
  13. package/dist/kb-mcp-tools.d.ts +3 -0
  14. package/dist/kb-mcp-tools.js +6 -0
  15. package/dist/messages.d.ts +4 -2
  16. package/dist/messages.js +14 -2
  17. package/dist/rules/kibi-workflow.mdc +3 -3
  18. package/dist/skills/.canon-hash.json +10 -0
  19. package/dist/skills/init-kibi/SKILL.md +50 -11
  20. package/dist/skills/kibi-freshness/SKILL.md +32 -10
  21. package/dist/skills/kibi-traceability/SKILL.md +41 -11
  22. package/dist/skills/kibi-usage/SKILL.md +123 -97
  23. package/dist/skills/kibi-usage/resources/fact-lanes.md +225 -0
  24. package/dist/skills/kibi-usage/resources/operation-access.md +44 -0
  25. package/dist/skills/kibi-usage/resources/relationship-directions.md +119 -0
  26. package/dist/skills/kibi-usage/resources/workflows.md +65 -0
  27. package/package.json +2 -2
  28. package/rules/kibi-workflow.mdc +3 -3
  29. package/skills/.canon-hash.json +10 -0
  30. package/skills/init-kibi/SKILL.md +50 -11
  31. package/skills/kibi-freshness/SKILL.md +32 -10
  32. package/skills/kibi-traceability/SKILL.md +41 -11
  33. package/skills/kibi-usage/SKILL.md +123 -97
  34. package/skills/kibi-usage/resources/fact-lanes.md +225 -0
  35. package/skills/kibi-usage/resources/operation-access.md +44 -0
  36. package/skills/kibi-usage/resources/relationship-directions.md +119 -0
  37. package/skills/kibi-usage/resources/workflows.md +65 -0
@@ -1,206 +1,5 @@
1
- // implements REQ-cursor-kibi-plugin-v1
2
- import { randomUUID } from "node:crypto";
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- const stateFileName = "hook-state.json";
7
- const lockFileName = "hook-state.lock";
8
- const maxDirtyPaths = 50;
9
- const maxGuidedPaths = 100;
10
- const lockRetryCount = 100;
11
- const lockRetryDelayMs = 5;
12
- const staleLockAgeMs = 30_000;
13
- function statePath(pluginData) {
14
- return path.join(pluginData, stateFileName);
15
- }
16
- function lockPath(pluginData) {
17
- return path.join(pluginData, lockFileName);
18
- }
19
- function isRecord(value) {
20
- return typeof value === "object" && value !== null && !Array.isArray(value);
21
- }
22
- function normalizePath(dirtyPath) {
23
- return dirtyPath.trim().replaceAll("\\", "/");
24
- }
25
- function sleepSync(milliseconds) {
26
- const buffer = new SharedArrayBuffer(4);
27
- const view = new Int32Array(buffer);
28
- Atomics.wait(view, 0, 0, milliseconds);
29
- }
30
- function uniqueTempPath(pluginData) {
31
- return path.join(pluginData, `${stateFileName}.${process.pid}.${Date.now()}.${randomUUID()}.tmp`);
32
- }
33
- function mergeStringPaths(existingPaths, nextPaths) {
34
- const merged = [...existingPaths, ...nextPaths]
35
- .map(normalizePath)
36
- .filter((dirtyPath) => dirtyPath.length > 0);
37
- return [...new Set(merged)].slice(-maxGuidedPaths);
38
- }
39
- const maxKbMutationTools = 20;
40
- function emptyHookState() {
41
- return {
42
- dirtyPaths: [],
43
- guidedReadPaths: [],
44
- guidedWritePaths: [],
45
- kbMutationTools: [],
46
- kbCheckRun: false,
47
- impactCheckRun: false,
48
- impactCheckedPaths: [],
49
- };
50
- }
51
- function acquireLock(pluginData) {
52
- const targetLockPath = lockPath(pluginData);
53
- for (let attempt = 0; attempt < lockRetryCount; attempt++) {
54
- try {
55
- return fs.openSync(targetLockPath, "wx");
56
- }
57
- catch (error) {
58
- if (error instanceof Error &&
59
- "code" in error &&
60
- error.code === "EEXIST") {
61
- if (removeStaleLock(targetLockPath)) {
62
- continue;
63
- }
64
- sleepSync(lockRetryDelayMs);
65
- continue;
66
- }
67
- return undefined;
68
- }
69
- }
70
- return undefined;
71
- }
72
- function removeStaleLock(targetLockPath) {
73
- let stats;
74
- try {
75
- stats = fs.statSync(targetLockPath);
76
- }
77
- catch {
78
- return false;
79
- }
80
- if (Date.now() - stats.mtimeMs < staleLockAgeMs) {
81
- return false;
82
- }
83
- try {
84
- fs.unlinkSync(targetLockPath);
85
- return true;
86
- }
87
- catch {
88
- return false;
89
- }
90
- }
91
- function releaseLock(pluginData, fileDescriptor) {
92
- try {
93
- fs.closeSync(fileDescriptor);
94
- }
95
- catch {
96
- // Ignore close failures; unlink still gives future hook runs a chance.
97
- }
98
- try {
99
- fs.unlinkSync(lockPath(pluginData));
100
- }
101
- catch {
102
- // A missing lock file is safe: bounded retries prevent permanent blocking.
103
- }
104
- }
105
- function coerceHookState(value) {
106
- if (!isRecord(value)) {
107
- return emptyHookState();
108
- }
109
- const dirtyPaths = Array.isArray(value.dirtyPaths)
110
- ? value.dirtyPaths
111
- .filter((dirtyPath) => typeof dirtyPath === "string")
112
- .map(normalizePath)
113
- .filter((dirtyPath) => dirtyPath.length > 0)
114
- : [];
115
- const guidedReadPaths = Array.isArray(value.guidedReadPaths)
116
- ? value.guidedReadPaths
117
- .filter((entry) => typeof entry === "string")
118
- .map(normalizePath)
119
- .filter((entry) => entry.length > 0)
120
- : [];
121
- const guidedWritePaths = Array.isArray(value.guidedWritePaths)
122
- ? value.guidedWritePaths
123
- .filter((entry) => typeof entry === "string")
124
- .map(normalizePath)
125
- .filter((entry) => entry.length > 0)
126
- : [];
127
- const kbMutationTools = Array.isArray(value.kbMutationTools)
128
- ? value.kbMutationTools
129
- .filter((entry) => typeof entry === "string")
130
- .map((entry) => entry.trim())
131
- .filter((entry) => entry.length > 0)
132
- : [];
133
- const kbCheckRun = value.kbCheckRun === true;
134
- const impactCheckRun = value.impactCheckRun === true;
135
- const impactCheckedPaths = Array.isArray(value.impactCheckedPaths)
136
- ? value.impactCheckedPaths
137
- .filter((entry) => typeof entry === "string")
138
- .map(normalizePath)
139
- .filter((entry) => entry.length > 0)
140
- : [];
141
- return {
142
- dirtyPaths: [...new Set(dirtyPaths)].slice(-maxDirtyPaths),
143
- guidedReadPaths: [...new Set(guidedReadPaths)].slice(-maxGuidedPaths),
144
- guidedWritePaths: [...new Set(guidedWritePaths)].slice(-maxGuidedPaths),
145
- kbMutationTools: [...new Set(kbMutationTools)].slice(-maxKbMutationTools),
146
- kbCheckRun,
147
- impactCheckRun,
148
- impactCheckedPaths: [...new Set(impactCheckedPaths)].slice(-maxGuidedPaths),
149
- };
150
- }
151
- export function resolveStateDir(pluginData, conversationId) {
152
- if (pluginData) {
153
- return pluginData;
154
- }
155
- if (!conversationId) {
156
- return undefined;
157
- }
158
- return path.join(os.tmpdir(), "kibi-cursor-hook-state", conversationId.replaceAll(/[^a-zA-Z0-9._-]/g, "_"));
159
- }
160
- export function loadHookState(stateDir) {
161
- if (!stateDir) {
162
- return emptyHookState();
163
- }
164
- try {
165
- return coerceHookState(JSON.parse(fs.readFileSync(statePath(stateDir), "utf8")));
166
- }
167
- catch {
168
- return emptyHookState();
169
- }
170
- }
171
- export function saveHookState(stateDir, state) {
172
- if (!stateDir) {
173
- return;
174
- }
175
- fs.mkdirSync(stateDir, { recursive: true });
176
- const boundedState = coerceHookState(state);
177
- const tempPath = uniqueTempPath(stateDir);
178
- fs.writeFileSync(tempPath, `${JSON.stringify(boundedState)}\n`);
179
- fs.renameSync(tempPath, statePath(stateDir));
180
- }
181
- export function updateHookState(stateDir, updater) {
182
- const initialState = loadHookState(stateDir);
183
- if (!stateDir) {
184
- return updater(initialState);
185
- }
186
- fs.mkdirSync(stateDir, { recursive: true });
187
- const lockFileDescriptor = acquireLock(stateDir);
188
- if (lockFileDescriptor === undefined) {
189
- return updater(initialState);
190
- }
191
- try {
192
- const lockedState = loadHookState(stateDir);
193
- const nextState = updater(lockedState);
194
- saveHookState(stateDir, nextState);
195
- return nextState;
196
- }
197
- catch {
198
- return updater(initialState);
199
- }
200
- finally {
201
- releaseLock(stateDir, lockFileDescriptor);
202
- }
203
- }
1
+ import { emptyHookState, loadHookState, maxDirtyPaths, maxKbMutationTools, mergeStringPaths, normalizePath, updateHookState, } from "./hook-state-storage.js";
2
+ export { loadHookState, resolveStateDir, saveHookState, updateHookState, } from "./hook-state-storage.js";
204
3
  export function addDirtyPaths(stateDir, dirtyPaths) {
205
4
  return updateHookState(stateDir, (state) => ({
206
5
  ...state,
@@ -236,9 +35,10 @@ export function recordKbMcpTool(stateDir, toolName, options = {}) {
236
35
  return loadHookState(stateDir);
237
36
  }
238
37
  return updateHookState(stateDir, (state) => {
38
+ const observedState = { ...state, mcpState: "observed" };
239
39
  if (normalized === "kb_check") {
240
40
  return {
241
- ...state,
41
+ ...observedState,
242
42
  kbCheckRun: true,
243
43
  impactCheckRun: state.impactCheckRun || options.impactCheckRun === true,
244
44
  impactCheckedPaths: options.impactCheckRun === true
@@ -248,13 +48,13 @@ export function recordKbMcpTool(stateDir, toolName, options = {}) {
248
48
  }
249
49
  if (normalized === "kb_upsert" || normalized === "kb_delete") {
250
50
  return {
251
- ...state,
51
+ ...observedState,
252
52
  kbMutationTools: mergeStringPaths(state.kbMutationTools, [
253
53
  normalized,
254
54
  ]).slice(-maxKbMutationTools),
255
55
  };
256
56
  }
257
- return state;
57
+ return observedState;
258
58
  });
259
59
  }
260
60
  export function clearSessionHookState(stateDir) {
@@ -3,5 +3,8 @@ export type KbMcpToolCall = {
3
3
  impactCheckRun: boolean;
4
4
  sourceFiles: string[];
5
5
  };
6
+ export type McpState = "observed" | "unknown";
7
+ export type KibiInterface = "mcp" | "cli" | "setup";
8
+ export declare function resolveKibiInterface(mcpState: McpState, workspaceTrusted: boolean): KibiInterface;
6
9
  export declare function extractKbMcpToolCall(toolName: string | undefined, toolInput: unknown): KbMcpToolCall | undefined;
7
10
  export declare function extractKbMcpToolName(toolName: string | undefined, toolInput: unknown): string | undefined;
@@ -39,6 +39,12 @@ function readRecord(record, keys) {
39
39
  }
40
40
  return undefined;
41
41
  }
42
+ export function resolveKibiInterface(mcpState, workspaceTrusted) {
43
+ if (mcpState === "observed") {
44
+ return "mcp";
45
+ }
46
+ return workspaceTrusted ? "cli" : "setup";
47
+ }
42
48
  export function extractKbMcpToolCall(toolName, toolInput) {
43
49
  const directToolName = toolName?.trim();
44
50
  let normalizedToolName = directToolName?.startsWith("kb_")
@@ -1,6 +1,8 @@
1
1
  import type { HookState } from "./hook-state.js";
2
- export declare const BOOTSTRAP_REMINDER = "Kibi config was not found at the Cursor workspace root. Use the Kibi MCP /init-kibi workflow to bootstrap project memory before relying on KB lookups; do not edit .kb/ files directly.";
3
- export declare const DIRECT_KB_EDIT_WARNING = "Avoid direct edits to .kb/. Use Kibi MCP tools for KB discovery and mutations so project memory stays valid.";
2
+ import { type McpState } from "./kb-mcp-tools.js";
3
+ export declare const BOOTSTRAP_REMINDER = "Kibi config was not found at the Cursor workspace root. Use visible Kibi MCP tools, or a trusted project-local CLI JSON route with --input when MCP is unavailable, to bootstrap project memory; if neither interface is available, tell the operator. Do not read or edit `.kb/` files directly. Query before mutate, run kb_upsert sequentially, and run kb_check before completion.";
4
+ export declare const DIRECT_KB_EDIT_WARNING = "Do not read or edit `.kb/` files directly. Use visible Kibi MCP tools, or trusted project-local CLI JSON routes with --input when MCP is unavailable. Query before mutate, run kb_upsert sequentially, and run kb_check before completion.";
5
+ export declare function interfaceAdvisory(mcpState: McpState, workspaceTrusted: boolean): string | undefined;
4
6
  export declare function stopFollowupMessage(state: HookState): string | undefined;
5
7
  /** @deprecated Use stopFollowupMessage */
6
8
  export declare function freshnessReminder(dirtyPaths: readonly string[]): string;
package/dist/messages.js CHANGED
@@ -1,6 +1,18 @@
1
+ import { resolveKibiInterface } from "./kb-mcp-tools.js";
1
2
  import { isKbFreshnessRelevantPath, isSourceImpactRelevantPath, } from "./path-policy.js";
2
- export const BOOTSTRAP_REMINDER = "Kibi config was not found at the Cursor workspace root. Use the Kibi MCP /init-kibi workflow to bootstrap project memory before relying on KB lookups; do not edit .kb/ files directly.";
3
- export const DIRECT_KB_EDIT_WARNING = "Avoid direct edits to .kb/. Use Kibi MCP tools for KB discovery and mutations so project memory stays valid.";
3
+ export const BOOTSTRAP_REMINDER = "Kibi config was not found at the Cursor workspace root. Use visible Kibi MCP tools, or a trusted project-local CLI JSON route with --input when MCP is unavailable, to bootstrap project memory; if neither interface is available, tell the operator. Do not read or edit `.kb/` files directly. Query before mutate, run kb_upsert sequentially, and run kb_check before completion.";
4
+ export const DIRECT_KB_EDIT_WARNING = "Do not read or edit `.kb/` files directly. Use visible Kibi MCP tools, or trusted project-local CLI JSON routes with --input when MCP is unavailable. Query before mutate, run kb_upsert sequentially, and run kb_check before completion.";
5
+ export function interfaceAdvisory(mcpState, workspaceTrusted) {
6
+ const selectedInterface = resolveKibiInterface(mcpState, workspaceTrusted);
7
+ switch (selectedInterface) {
8
+ case "mcp":
9
+ return undefined;
10
+ case "cli":
11
+ return "Kibi MCP has not been observed in this session. In this explicitly trusted workspace, the project-local CLI is an advisory fallback: use npx --no-install kibi or bunx --no-install kibi. Do not use global or installing runners.";
12
+ case "setup":
13
+ return "Kibi MCP has not been observed in this session and workspace trust is unknown. Do not probe or execute a CLI fallback; ask the operator to enable MCP or explicitly approve the trusted project-local CLI workflow.";
14
+ }
15
+ }
4
16
  export function stopFollowupMessage(state) {
5
17
  if (state.kbMutationTools.length > 0) {
6
18
  const tools = [...new Set(state.kbMutationTools)];
@@ -1,9 +1,9 @@
1
1
  ---
2
- description: Kibi MCP discovery-first workflow and KB mutation discipline
2
+ description: Kibi capability-based discovery-first workflow and KB mutation discipline
3
3
  alwaysApply: true
4
4
  ---
5
5
 
6
- Use Kibi via MCP tools only. Do not manually read or edit `.kb/` files.
6
+ Use Kibi via MCP tools when available, or via CLI JSON routes when MCP is unavailable. If MCP tools are visible, use MCP. If MCP availability is unknown and a trusted project-local CLI is available, use `kibi <route> --input <file|->`. If neither interface is available, stop and tell the operator. Do not infer MCP availability from config file existence. Do not read or edit `.kb/` files directly.
7
7
 
8
8
  Discovery workflow:
9
9
  - Start with `kb_search` for broad discovery.
@@ -13,7 +13,7 @@ Discovery workflow:
13
13
  Mutation workflow:
14
14
  - Query before mutate.
15
15
  - Create relationship endpoints before linking.
16
- - Use `kb_upsert` sequentially, then `kb_check`.
16
+ - Use `kb_upsert` sequentially. Run `kb_check` before completion.
17
17
  - Use `kb_delete` only for intentional removals with dependency awareness.
18
18
 
19
19
  Completion must state KB freshness outcome: updated, no-impact with rationale, or deferred/failed.
@@ -0,0 +1,10 @@
1
+ {
2
+ "init-kibi/SKILL.md": "4e936774cd31cf366e9e17452e9030fdaeabab345bce5ee163656e0fe5dc73d7",
3
+ "kibi-freshness/SKILL.md": "68345a514233503f8f78d53e7d602d8a5fc566e1ec118388c7393716c9f7490d",
4
+ "kibi-traceability/SKILL.md": "a621553397c1f8813f05fd9552fc30a5e8ed118442e019add35804de7d43a0b1",
5
+ "kibi-usage/SKILL.md": "f4a713d8c95d9c9a254e2f23b27013293f0caacb4009409409e56c7deeccc8a5",
6
+ "kibi-usage/resources/fact-lanes.md": "8b2f835775e57427db980c5412d6e58840a53e71e8e508ae39f14ebfa693e4b8",
7
+ "kibi-usage/resources/operation-access.md": "d8653b544305d4c00734c737b1156110208a9a82fbec6b04726d25b973f2b840",
8
+ "kibi-usage/resources/relationship-directions.md": "aecbde048bb84e210318e4aca98e07f8370168c640c3a9d65696d2195c8598ec",
9
+ "kibi-usage/resources/workflows.md": "36e50fe83fc7ac6bc68fcf51d2c2175e09c68815b6bbebed8cfa1d5611617913"
10
+ }
@@ -1,23 +1,62 @@
1
1
  ---
2
+ id: init-kibi
2
3
  name: init-kibi
3
4
  description: Bootstrap and model knowledge safely using approved Kibi MCP initialization and mutation workflow.
5
+ version: 1.0.0
6
+ kibiCompatibility: "*"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - bootstrap
11
+ - agent-guidance
4
12
  ---
5
-
6
13
  ## Goal
7
14
 
8
- Set up or refresh Kibi knowledge for the current branch without manual filesystem edits.
15
+ Set up or refresh Kibi knowledge for the current branch through approved Kibi interfaces only. Maintain source-file traceability for every repository-backed claim, and require explicit operator approval before any mutation.
16
+
17
+ ## Interface Selection
18
+
19
+ 1. If approved Kibi MCP tools are visible, use the MCP route.
20
+ 2. Otherwise, in a trusted workspace, use the canonical project-local CLI fallback: `npx --no-install kibi ...` or `bunx --no-install kibi ...`.
21
+ 3. If neither approved MCP tools nor the project-local CLI are available, stop and tell the operator to enable or install Kibi for this workspace.
22
+ 4. Never use a global fallback, an installing runner, or any route outside the approved Kibi interface.
23
+
24
+ Use `kibi-usage/resources/operation-access.md` for the exact operation-to-route mapping. The CLI preview route accepts the same JSON object as `kb_autopilot_generate`:
25
+
26
+ ```bash
27
+ echo '{"maxCandidates":25,"minConfidence":0.8}' | npx --no-install kibi autopilot-generate --input -
28
+ ```
9
29
 
10
- ## MCP workflow
30
+ ## Capability Workflow
11
31
 
12
- - Run `kb_autopilot_generate` for suggested initial facts and claims.
13
- - Show the generated preview and get explicit approval before writes.
14
- - Use `kb_upsert` for reviewed entity creation or updates.
15
- - If cleanup is needed, use `kb_delete` only after checking dependencies.
16
- - Finish with `kb_check` to validate the branch snapshot.
32
+ - Generate a read-only bootstrap preview with `kb_autopilot_generate`, or the dedicated CLI route `autopilot-generate --input`.
33
+ - Show the generated preview and obtain explicit approval before writes.
34
+ - Apply reviewed entity creation or updates with `kb_upsert`, or `upsert --input`.
35
+ - If cleanup is needed, use `kb_delete`, or `delete --input`, only after checking dependencies and obtaining approval for the specific removal.
36
+ - Finish with `kb_check`, or `check --input`, to validate the branch snapshot.
17
37
 
18
38
  ## Guidance
19
39
 
20
- - Keep mutation requests explicit and small.
21
- - Use source-linked entities where possible so future `kb_query` lookups can verify context.
22
- - Do not edit `.kb/**` files directly; all changes go through MCP calls.
40
+ - Keep mutation requests explicit, small, and sequential.
41
+ - Prefer source-linked entities so future `kb_query` lookups can verify repository context against source files.
42
+ - Preserve traceability by linking facts, claims, scenarios, and tests to concrete project files whenever repository evidence supports it.
43
+ - Do not read or edit files inside `.kb` directly; all changes go through the selected Kibi interface.
23
44
  - Ask at most four bounded context questions, and only when repository evidence is insufficient.
45
+ - Stop at the documented operator repair boundary if the setup appears partial, inconsistent, or unsupported by the approved interface.
46
+
47
+ ## Public Training Trajectories
48
+
49
+ - `init-kibi-bootstrap-analysis-train-1`: Analyze the cold-start repository and produce a read-only bootstrap preview using only the public Kibi MCP surface.
50
+ - `init-kibi-bootstrap-analysis-train-2`: Analyze the cold-start repository and produce a read-only bootstrap preview using only the public Kibi MCP surface.
51
+ - `init-kibi-bounded-context-questions-train-1`: Ask only the bounded context questions needed before bootstrap synthesis using only the public Kibi MCP surface.
52
+ - `init-kibi-bounded-context-questions-train-2`: Ask only the bounded context questions needed before bootstrap synthesis using only the public Kibi MCP surface.
53
+ - `init-kibi-approval-sequential-writes-train-1`: Apply the approved bootstrap plan sequentially and finish with validation using only the public Kibi MCP surface.
54
+ - `init-kibi-approval-sequential-writes-train-2`: Apply the approved bootstrap plan sequentially and finish with validation using only the public Kibi MCP surface.
55
+ - `init-kibi-repair-escalation-train-1`: Identify the partial setup and stop at the documented operator repair boundary using only the public Kibi MCP surface.
56
+ - `init-kibi-repair-escalation-train-2`: Identify the partial setup and stop at the documented operator repair boundary using only the public Kibi MCP surface.
57
+
58
+ ## Training Data
59
+
60
+ ```json
61
+ [{"taskId":"init-kibi-bootstrap-analysis-train-1","family":"bootstrap-analysis","reflection":"Analyze the cold-start repository and produce a read-only bootstrap preview. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"init-kibi-bootstrap-analysis-train-2","family":"bootstrap-analysis","reflection":"Analyze the cold-start repository and produce a read-only bootstrap preview. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"init-kibi-bounded-context-questions-train-1","family":"bounded-context-questions","reflection":"Ask only the bounded context questions needed before bootstrap synthesis. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"init-kibi-bounded-context-questions-train-2","family":"bounded-context-questions","reflection":"Ask only the bounded context questions needed before bootstrap synthesis. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"init-kibi-approval-sequential-writes-train-1","family":"approval-sequential-writes","reflection":"Apply the approved bootstrap plan sequentially and finish with validation. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"init-kibi-approval-sequential-writes-train-2","family":"approval-sequential-writes","reflection":"Apply the approved bootstrap plan sequentially and finish with validation. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"init-kibi-repair-escalation-train-1","family":"repair-escalation","reflection":"Identify the partial setup and stop at the documented operator repair boundary. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"init-kibi-repair-escalation-train-2","family":"repair-escalation","reflection":"Identify the partial setup and stop at the documented operator repair boundary. This is train case 2; use only the public Kibi MCP surface."}]
62
+ ```
@@ -1,22 +1,44 @@
1
1
  ---
2
+ id: kibi-freshness
2
3
  name: kibi-freshness
3
4
  description: Check branch freshness and source linkage quality before decisions or risky writes.
5
+ version: 1.0.0
6
+ kibiCompatibility: "*"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - freshness
11
+ - agent-guidance
4
12
  ---
5
-
6
13
  ## Goal
7
14
 
8
- Help agents decide whether KB context is current enough to support safe changes.
15
+ Help agents decide whether Kibi knowledge is current enough to support safe changes while preserving source-file traceability and approved interface boundaries.
16
+
17
+ ## Interface Selection
18
+
19
+ 1. If Kibi MCP tools are visible and approved for the workspace, use the MCP surface only.
20
+ 2. Otherwise, in a trusted workspace, use the canonical project-local CLI fallback through `npx --no-install kibi ...` or `bunx --no-install kibi ...`.
21
+ 3. If the project-local CLI is unavailable or too old, stop and tell the operator to enable or install Kibi.
22
+ 4. Never use a global fallback or an installing runner.
23
+
24
+ Use `kibi-usage/resources/operation-access.md` for exact dedicated routes. A project-local CLI freshness check is executable as:
25
+
26
+ ```bash
27
+ echo '{}' | npx --no-install kibi status --input -
28
+ ```
9
29
 
10
- ## MCP workflow
30
+ ## Capability Workflow
11
31
 
12
- - Use `kb_status` first to confirm branch attachment and freshness state.
13
- - Use `kb_query` with `sourceFile`/text refs for source-linked discovery.
14
- - Re-run `kb_search` after sync gaps are detected.
15
- - If knowledge must change, update it with `kb_upsert` or `kb_delete` and finish with `kb_check`.
32
+ - Use `kb_status`, or `status --input`, first to confirm branch attachment, freshness state, dirty-worktree evidence, and whether the knowledge snapshot is safe to rely on.
33
+ - Use `kb_query`, or `query --input`, with `sourceFile` and text references for source-linked discovery.
34
+ - Re-run `kb_search`, or `search --input`, after sync gaps or stale context are detected.
35
+ - If knowledge must change, use the selected interface's `kb_upsert`/`upsert` or `kb_delete`/`delete` operation sequentially, then finish with `kb_check`/`check`.
16
36
 
17
37
  ## Guidance
18
38
 
39
+ - Prefer the public Kibi MCP surface whenever it is available and approved.
19
40
  - Never proceed with broad changes when freshness is stale and unresolved.
20
- - If entities look stale, prefer refreshing context via MCP flows and then re-query.
21
- - Avoid direct `.kb` editing; use `kb_status` and other MCP checks instead.
22
- - Completion must state one freshness outcome: KB updated, no KB impact with rationale, or deferred/failed.
41
+ - If entities look stale, refresh context through an approved Kibi capability and then re-query.
42
+ - Preserve source-file traceability by carrying `sourceFile`, text references, and validation evidence through discovery, mutation, and completion.
43
+ - Do not read or edit files inside `.kb` directly; use the selected Kibi interface instead.
44
+ - Completion must state one freshness outcome: KB updated, no KB impact with rationale, or deferred/failed.
@@ -1,24 +1,54 @@
1
1
  ---
2
+ id: kibi-traceability
2
3
  name: kibi-traceability
3
4
  description: Maintain requirement, scenario, and test traceability through Kibi MCP tools.
5
+ version: 1.0.0
6
+ kibiCompatibility: "*"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - traceability
11
+ - agent-guidance
4
12
  ---
5
-
6
13
  ## Goal
7
14
 
8
- Validate and strengthen traceability before and after code changes.
15
+ Validate and strengthen requirement, scenario, test, behavioral-symbol, and source-file traceability before and after code changes.
16
+
17
+ ## Interface Selection
18
+
19
+ 1. If Kibi MCP tools are visible and approved, use the MCP surface as the primary authority.
20
+ 2. Otherwise, in a trusted workspace, use the canonical project-local CLI fallback through `npx --no-install kibi ...` or `bunx --no-install kibi ...`.
21
+ 3. If neither approved MCP tools nor the project-local CLI are available, or if the CLI is unavailable or too old, stop and tell the operator to enable or install Kibi.
22
+ 4. Never use a global fallback or an installing runner.
23
+
24
+ Use MCP routes for modeling, querying, checking, validation, and cleanup. Use the project-local CLI only as the fallback interface, passing JSON input through stdin. Example:
9
25
 
10
- ## MCP workflow
26
+ ```bash
27
+ echo '{"sourceFiles":["src/auth/login.ts"],"includeImpactDiagnostics":true,"includeWorkingTreeDiff":true}' | npx --no-install kibi check --input -
28
+ ```
11
29
 
12
- - Locate requirements with `kb_search` and inspect exact details with `kb_query`.
13
- - After meaningful source edits, run `kb_check({sourceFiles:[...], includeImpactDiagnostics:true, includeWorkingTreeDiff:true})` before deciding whether traceability is current.
14
- - Apply updates with `kb_upsert` for requirements, scenarios, tests, or facts.
15
- - Validate constraints and consistency with `kb_check`.
30
+ ## Capability Workflow
31
+
32
+ - Locate requirements through `kb_search` or `search --input`, then inspect exact records through `kb_query` or `query --input`.
33
+ - Before meaningful edits, identify linked requirements, scenarios, tests, facts, source files, and behavioral symbols relevant to the planned change.
34
+ - After meaningful source edits, run `kb_check({sourceFiles:[...], includeImpactDiagnostics:true, includeWorkingTreeDiff:true})` or the equivalent `check --input` JSON recipe before deciding whether traceability is current.
35
+ - Apply traceability updates sequentially through `kb_upsert` or `upsert --input` for requirements, scenarios, tests, facts, behavioral symbols, and source-linked relationships.
36
+ - Validate constraints and consistency through `kb_check` or `check --input` after updates.
37
+ - Use `kb_delete` or `delete --input` only for explicit cleanup of obsolete records or relationships.
16
38
 
17
39
  ## Guidance
18
40
 
19
- - Prefer source-linked relationships so symbols and files can be traced back cleanly.
20
- - Treat `symbol_semantic_review_needed` as a prompt to inspect linked requirements/tests; Kibi reports graph links but does not prove prose semantics.
21
- - Include `kb_query` and `kb_delete` only when explicit cleanups are required.
22
- - Never directly edit `.kb/**`; all modeling and cleanup goes through MCP tools.
41
+ - Prefer source-linked relationships so requirements, scenarios, tests, symbols, and files can be traced cleanly.
42
+ - Preserve source-file traceability whenever adding or changing requirements, scenarios, tests, facts, behavioral symbols, or implementation links.
23
43
  - Preserve the canonical chain `REQ-* -> SCEN-* -> TEST-*` when adding or changing requirements.
24
44
  - Production symbols should implement requirements; test symbols should remain executable evidence for tests.
45
+ - Resolve impact at behavioral-symbol granularity when Kibi reports symbol-level diagnostics; avoid treating a whole file as impacted when the report identifies narrower linked behavior.
46
+ - Treat `symbol_semantic_review_needed` as a prompt to inspect linked requirements and tests; Kibi reports graph links but does not prove prose semantics.
47
+ - Do not read or edit files inside `.kb` directly; all modeling and cleanup goes through the selected Kibi interface.
48
+ - Keep approval boundaries intact: only use Kibi MCP tools that are visible and approved, and only use the project-local CLI fallback in a trusted workspace.
49
+
50
+ Public training trajectories:
51
+ [{"taskId":"kibi-traceability-requirement-discovery-train-1","family":"requirement-discovery","reflection":"Discover the requirement linked to the supplied source symbol. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-requirement-discovery-train-2","family":"requirement-discovery","reflection":"Discover the requirement linked to the supplied source symbol. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-symbol-impact-granularity-train-1","family":"symbol-impact-granularity","reflection":"Resolve impact at behavioral symbol granularity rather than file granularity. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-symbol-impact-granularity-train-2","family":"symbol-impact-granularity","reflection":"Resolve impact at behavioral symbol granularity rather than file granularity. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-relationship-chain-train-1","family":"relationship-chain","reflection":"Trace the requirement, scenario, and test relationship chain. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-relationship-chain-train-2","family":"relationship-chain","reflection":"Trace the requirement, scenario, and test relationship chain. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-executable-coverage-train-1","family":"executable-coverage","reflection":"Establish executable test identity and behavioral coverage links. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-executable-coverage-train-2","family":"executable-coverage","reflection":"Establish executable test identity and behavioral coverage links. This is train case 2; use only the public Kibi MCP surface."}]
52
+
53
+ Previous development gate:
54
+ {"mean":0,"hardPasses":0,"worstFamilyMean":0}