kibi-cursor 1.0.1 → 2.0.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kibi-cursor",
3
3
  "displayName": "Kibi",
4
- "version": "1.0.1",
4
+ "version": "2.0.0",
5
5
  "description": "Optional Cursor adapter for Kibi. Requires SWI-Prolog 9+ and project-local kibi-cli, kibi-mcp, and kibi-core before the bundled MCP server can start.",
6
6
  "license": "AGPL-3.0-or-later",
7
7
  "author": {
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # kibi-cursor
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 812c201: Kibi's proof layer is now runner-neutral: any test runner, script, or harness can prove requirements, and Playwright is no longer built into the proof model.
8
+
9
+ - `kibi prove` replaces `kibi verify` as the single command to run configured proof producers and record evidence. Proof contracts (`kibi.proof-contract.v1`) declare explicit obligations (`symbol_id` + `target`) executed by a configured integration in `.kb/proof/integrations.json`; `kibi proof inspect` discovers test infrastructure deterministically; one producer run can satisfy many test contracts, and re-ingestion is idempotent.
10
+ - Evidence moves to the `kibi.proof-run.v1` artifact (typed environment, run-level outcome, factual attempt history with `native_case`/`aggregate_run` provenance) evaluated into `kibi.proof-receipt.v1` receipts bound to the live snapshot, contract hash, and effective execution fingerprint. Command proof is the universal fallback, so every project can prove requirements without a first-party framework adapter; strict first-attempt policy never upgrades unknown attempt history into passing evidence.
11
+ - Breaking removals: `kibi verify`, `kb_ingest_verification`, `kibi.playwright-run.v1`, `verification_contract`/`verification_receipts` entity fields (replaced by `proof_contract`/`proof_bindings`/`proof_receipts`), the `required_case_symbols`×`required_projects` Cartesian contract, and `retries` fields. Migrate by re-running `kibi prove` after bootstrap configures proof for your repository.
12
+
13
+ DRY: hard cutover to the proof-evidence protocol across CLI, MCP, runtime skills, Prolog proof evaluation, coverage/repair/report surfaces, agent skills, and repository self-proof (packed e2e steps now execute through `kibi prove --all`).
14
+
15
+ ### Patch Changes
16
+
17
+ - b0271ac: Cursor now starts the bundled Kibi MCP server reliably when it launches plugin processes from a home directory or another unrelated working directory. Consumer workspaces with spaces continue to resolve their project-local `kibi-mcp` installation, while the portable Agent Plugin keeps its separate `npx --no-install` configuration.
18
+
19
+ - Fix `kibi-cursor` MCP launcher arguments to use Cursor's `${CURSOR_PLUGIN_ROOT}` expansion.
20
+ - Add source-install manifest regression coverage for consumer-local resolution from unrelated host directories.
21
+
22
+ - b1682f1: Agents receive clearer guidance for repairing the actual supplied mutation request and preserving approved predicate bindings. The scoped additions retain the existing workflow while separating payload recovery from conditional relational modeling.
23
+
24
+ - Update `kibi-usage` to 2.1.2 in CLI/runtime sources and the generated Codex/Cursor distributions.
25
+ - Preserve the other three skills and all existing resource content.
26
+ - Retain production-adoption safeguards; development comparisons are not held-out evidence.
27
+
28
+ - ee0dc49: Plugin hooks, the Cursor MCP launcher, and skill validation now expose the
29
+ same entry paths tests already spawn as processes. In-process coverage can
30
+ exercise stdin, CLI guards, and realpath failures instead of leaving those
31
+ lines invisible to Codecov.
32
+
33
+ - Export hook CLI helpers and Agent Plugin / launcher internals for tests.
34
+ - Use a namespace `fs` import in skill validation so realpath errors are testable.
35
+
36
+ - 5999143: Agent-facing skill docs now use the current status field names, so agents following the freshness and E2E receipt workflows look for fields that actually exist in `kb_status` output instead of stale ones.
37
+
38
+ - Bundled `kibi-freshness` and `kibi-usage` skills (all agent mirrors) now reference `proofSnapshotChanges` and `proofSnapshot` (previously `verificationSnapshotChanges`/`verificationSnapshot` from the pre-proof-architecture status schema).
39
+ - The skillopt-eval harness reads `proofSnapshot*` status fields and its held-out eval prompts name the current fields, so "dirty editor path" evidence gathering works against live status output again.
40
+
41
+ Dry: completes the `verificationSnapshot*` → `proofSnapshot*` rename from the proof architecture change in the surfaces that earlier commit missed.
42
+
3
43
  ## 1.0.1
4
44
 
5
45
  ### Patch Changes
package/README.md CHANGED
@@ -56,16 +56,19 @@ cp -r "$(npm root)/kibi-cursor" ~/.cursor/plugins/local/kibi-cursor
56
56
  ## MCP configuration
57
57
 
58
58
  The plugin bundles `mcp.json` with a thin launcher that locates and starts the
59
- `kibi-mcp` package installed in the opened project. The launcher runs from the
60
- consumer workspace and sets `KIBI_WORKSPACE` to that root; it never downloads,
61
- bundles, or falls back to a global Kibi runtime:
59
+ `kibi-mcp` package installed in the opened project. The launcher starts the
60
+ resolved child from the consumer workspace and sets `KIBI_WORKSPACE` to that
61
+ root; it never downloads, bundles, or falls back to a global Kibi runtime:
62
62
 
63
63
  ```json
64
64
  {
65
65
  "mcpServers": {
66
66
  "kibi": {
67
67
  "command": "node",
68
- "args": ["bin/launch-kibi-mcp.mjs", "${workspaceFolder}"]
68
+ "args": [
69
+ "${CURSOR_PLUGIN_ROOT}/bin/launch-kibi-mcp.mjs",
70
+ "${workspaceFolder}"
71
+ ]
69
72
  }
70
73
  }
71
74
  }
@@ -73,6 +76,9 @@ bundles, or falls back to a global Kibi runtime:
73
76
 
74
77
  Toggle the bundled MCP server from **Settings → Features → Model Context Protocol** after installing the plugin.
75
78
 
79
+ Cursor expands `${CURSOR_PLUGIN_ROOT}` to the installed plugin directory and
80
+ `${workspaceFolder}` to the opened workspace before starting the command.
81
+
76
82
  Manual MCP fallback (no plugin install required):
77
83
 
78
84
  ```json
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "kibi",
4
- "version": "1.0.1",
4
+ "version": "2.0.0",
5
5
  "description": "Repo-local, per-branch, queryable knowledge base. Portable Agent Plugin packaging Kibi's Agent Skills and MCP server.",
6
6
  "author": { "name": "Kibi" },
7
7
  "homepage": "https://github.com/Looted/kibi/blob/develop/docs/install.md",
@@ -2,7 +2,7 @@
2
2
  id: kibi-usage
3
3
  name: Kibi Usage
4
4
  description: Use Kibi's source-first, exact-Git, migration-aware, proof-aware operations safely across MCP or the trusted local CLI, including partial completion repair.
5
- version: 2.1.1
5
+ version: 2.1.2
6
6
  kibiCompatibility: ">=1.0.0"
7
7
  tags:
8
8
  - kibi
@@ -75,6 +75,8 @@ check. Never fire `kb_upsert` calls in parallel; create or confirm endpoint
75
75
  entities before linking them. The canonical MCP names are `kb_search`,
76
76
  `kb_query`, `kb_upsert`, and `kb_check`.
77
77
 
78
+ For a task that explicitly supplies a malformed concrete mutation payload, locate and read that public request artifact before choosing an entity, preserving its exact entity ID, type, requested changes, and every intended relationship and endpoint. Do not substitute a seeded or convenient entity for the requested target. Start with kb_search, then exact-filter those targets with kb_query, and run kb_validate_upsert on that same payload; validation is not completion. Correct only diagnosed pre-commit errors and revalidate the corrected payload. Once authorized, apply the identical corrected and authorized payload with kb_upsert. If it returns committed_with_repairs, treat the mutation as committed, follow only the required repair actions, and neither retry it nor trigger unrelated semantic backfill for a schema-only repair. Exact-read every changed entity and relationship endpoint with kb_query, then finish with an unfiltered kb_check followed by a final kb_status.
79
+
78
80
  ## Closeout fields
79
81
 
80
82
  End every task with these five independent fields:
@@ -147,6 +149,8 @@ grounding: run `logic-coverage` so each key binds to one ground fact.
147
149
  Relationship direction is fixed, and every `from` in a relationship batch
148
150
  must equal the upserted entity ID.
149
151
 
152
+ For conditional relational claims, after the initial `kb_suggest_predicates` and before any `kb_upsert`—including one needed for a missing schema—call read-only `kb_model_requirement` to preview suitable scalar or typed-rule modeling. Treat the preview as advisory: do not apply an irrelevant result or create unrequested facts, and retain an approved ground-predicate plan when it captures the whole claim. Preserve supplied arity, ordered argument roles, polarity, bound values, and one claim key per actual assertion; never split arguments across clauses or schemas or alter values to force uniqueness.
153
+
150
154
  ## Symbol-First Traceability
151
155
 
152
156
  Represent implementation ownership with a `symbol` entity that has
@@ -1,5 +1,23 @@
1
1
  export function parseWorkspaceFolderPaths(value: unknown): string[];
2
2
 
3
+ export function nextAncestorDirectory(current: string): string | undefined;
4
+
5
+ export function packageJsonForResolvedFile(startPath: string): {
6
+ packageJsonPath: string;
7
+ packageRoot: string;
8
+ packageJson: Record<string, unknown>;
9
+ } | null;
10
+
11
+ export function hasConsumerNodeModulesLink(
12
+ workspaceRoot: string,
13
+ packageRoot: string,
14
+ ): boolean;
15
+
16
+ export function isProjectScopedPackage(
17
+ workspaceRoot: string,
18
+ packageRoot: string,
19
+ ): boolean;
20
+
3
21
  export function resolveProjectLocalMcp(workspaceRoot: string): {
4
22
  packageRoot: string;
5
23
  packageJsonPath: string;
@@ -7,12 +25,32 @@ export function resolveProjectLocalMcp(workspaceRoot: string): {
7
25
  binPath: string;
8
26
  };
9
27
 
28
+ export function hasDeclaredProjectDependency(workspaceRoot: string): boolean;
29
+
10
30
  export function resolveWorkspaceRoot(
11
31
  explicitWorkspace?: string,
12
32
  options?: { cwd?: string; env?: NodeJS.ProcessEnv },
13
33
  ): string;
14
34
 
35
+ export function signalExitCode(signal: NodeJS.Signals | string): number;
36
+
37
+ export function isLaunchEntrypoint(
38
+ argv1: string | undefined,
39
+ moduleUrl: string,
40
+ ): boolean;
41
+
42
+ export function runLaunchEntrypoint(
43
+ argv?: string[],
44
+ env?: NodeJS.ProcessEnv,
45
+ ): Promise<number>;
46
+
15
47
  export function launchKibiMcp(
16
48
  argv?: string[],
17
49
  env?: NodeJS.ProcessEnv,
50
+ spawnImpl?: typeof import("node:child_process").spawn,
18
51
  ): Promise<number>;
52
+
53
+ export function runLaunchIfEntrypoint(
54
+ isEntrypoint?: boolean,
55
+ start?: () => Promise<number> | Promise<void>,
56
+ ): Promise<void>;
@@ -7,14 +7,17 @@
7
7
  /**
8
8
  * Launch the kibi-mcp package installed by the consumer project.
9
9
  *
10
- * Cursor starts plugin MCP commands with the plugin directory as their cwd.
11
- * This adapter deliberately knows nothing about the Kibi source tree: it only
12
- * resolves a consumer workspace, finds that workspace's kibi-mcp package, and
13
- * runs its declared bin with the consumer as both cwd and KIBI_WORKSPACE.
10
+ * Cursor resolves this command from the plugin-root manifest, but the process
11
+ * cwd is host-controlled and is not a reliable consumer workspace (it may be
12
+ * the plugin directory or another host directory). This adapter deliberately
13
+ * knows nothing about the Kibi source tree: it resolves the unrelated consumer
14
+ * workspace from Cursor's workspace-folder data or explicit environment,
15
+ * finds that workspace's kibi-mcp package, and runs its declared bin with the
16
+ * consumer as both cwd and KIBI_WORKSPACE.
14
17
  */
15
18
 
16
19
  import { spawn } from "node:child_process";
17
- import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
20
+ import * as fs from "node:fs";
18
21
  import { createRequire } from "node:module";
19
22
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
20
23
  import { fileURLToPath } from "node:url";
@@ -29,12 +32,12 @@ const SIGNAL_EXIT_CODES = {
29
32
  };
30
33
 
31
34
  function readJson(path) {
32
- return JSON.parse(readFileSync(path, "utf8"));
35
+ return JSON.parse(fs.readFileSync(path, "utf8"));
33
36
  }
34
37
 
35
38
  function isDirectory(path) {
36
39
  try {
37
- return statSync(path).isDirectory();
40
+ return fs.statSync(path).isDirectory();
38
41
  } catch {
39
42
  return false;
40
43
  }
@@ -86,17 +89,22 @@ export function parseWorkspaceFolderPaths(value) {
86
89
  .filter(Boolean);
87
90
  }
88
91
 
89
- function packageJsonForResolvedFile(startPath) {
92
+ export function nextAncestorDirectory(current) {
93
+ const parent = dirname(current);
94
+ return parent === current ? undefined : parent;
95
+ }
96
+
97
+ export function packageJsonForResolvedFile(startPath) {
90
98
  let current = resolve(startPath);
91
99
  try {
92
- if (!statSync(current).isDirectory()) current = dirname(current);
100
+ if (!fs.statSync(current).isDirectory()) current = dirname(current);
93
101
  } catch {
94
102
  current = dirname(current);
95
103
  }
96
104
 
97
- while (true) {
105
+ while (current !== undefined) {
98
106
  const packageJsonPath = join(current, "package.json");
99
- if (existsSync(packageJsonPath)) {
107
+ if (fs.existsSync(packageJsonPath)) {
100
108
  try {
101
109
  const packageJson = readJson(packageJsonPath);
102
110
  if (packageJson.name === PACKAGE_NAME) {
@@ -106,10 +114,9 @@ function packageJsonForResolvedFile(startPath) {
106
114
  // Keep walking if a parent package manifest is malformed.
107
115
  }
108
116
  }
109
- const parent = dirname(current);
110
- if (parent === current) return null;
111
- current = parent;
117
+ current = nextAncestorDirectory(current);
112
118
  }
119
+ return null;
113
120
  }
114
121
 
115
122
  function isWithinRoot(rootPath, candidatePath) {
@@ -120,10 +127,10 @@ function isWithinRoot(rootPath, candidatePath) {
120
127
  );
121
128
  }
122
129
 
123
- function hasConsumerNodeModulesLink(workspaceRoot, packageRoot) {
130
+ export function hasConsumerNodeModulesLink(workspaceRoot, packageRoot) {
124
131
  try {
125
132
  const linkPath = join(workspaceRoot, "node_modules", PACKAGE_NAME);
126
- const linkedRoot = realpathSync(linkPath);
133
+ const linkedRoot = fs.realpathSync(linkPath);
127
134
  return (
128
135
  isWithinRoot(linkedRoot, packageRoot) ||
129
136
  isWithinRoot(packageRoot, linkedRoot)
@@ -133,7 +140,7 @@ function hasConsumerNodeModulesLink(workspaceRoot, packageRoot) {
133
140
  }
134
141
  }
135
142
 
136
- function isProjectScopedPackage(workspaceRoot, packageRoot) {
143
+ export function isProjectScopedPackage(workspaceRoot, packageRoot) {
137
144
  if (isWithinRoot(workspaceRoot, packageRoot)) return true;
138
145
 
139
146
  // pnpm can expose a package through a symlink whose realpath is outside the
@@ -197,7 +204,7 @@ export function resolveProjectLocalMcp(workspaceRoot) {
197
204
  }
198
205
 
199
206
  const binPath = resolve(packageInfo.packageRoot, binEntry);
200
- if (!existsSync(binPath)) {
207
+ if (!fs.existsSync(binPath)) {
201
208
  throw new Error(
202
209
  `[KIBI-CURSOR] Project-local ${PACKAGE_NAME} declares a missing executable: ${binPath}. Reinstall the workspace dependency and reload Cursor.`,
203
210
  );
@@ -211,9 +218,9 @@ export function resolveProjectLocalMcp(workspaceRoot) {
211
218
  };
212
219
  }
213
220
 
214
- function hasDeclaredProjectDependency(workspaceRoot) {
221
+ export function hasDeclaredProjectDependency(workspaceRoot) {
215
222
  const packageJsonPath = join(workspaceRoot, "package.json");
216
- if (!existsSync(packageJsonPath)) return false;
223
+ if (!fs.existsSync(packageJsonPath)) return false;
217
224
  try {
218
225
  const packageJson = readJson(packageJsonPath);
219
226
  return [
@@ -235,8 +242,8 @@ function hasDeclaredProjectDependency(workspaceRoot) {
235
242
 
236
243
  function isDemonstrablyProjectWorkspace(workspaceRoot) {
237
244
  return (
238
- existsSync(join(workspaceRoot, ".git")) ||
239
- existsSync(join(workspaceRoot, ".kb")) ||
245
+ fs.existsSync(join(workspaceRoot, ".git")) ||
246
+ fs.existsSync(join(workspaceRoot, ".kb")) ||
240
247
  hasDeclaredProjectDependency(workspaceRoot)
241
248
  );
242
249
  }
@@ -311,12 +318,30 @@ export function resolveWorkspaceRoot(explicitWorkspace, options = {}) {
311
318
  );
312
319
  }
313
320
 
314
- function signalExitCode(signal) {
321
+ export function signalExitCode(signal) {
315
322
  return SIGNAL_EXIT_CODES[signal] ?? 1;
316
323
  }
317
324
 
325
+ export function isLaunchEntrypoint(argv1, moduleUrl) {
326
+ const entrypoint = argv1 ? resolve(argv1) : undefined;
327
+ return entrypoint === resolve(fileURLToPath(moduleUrl));
328
+ }
329
+
330
+ export async function runLaunchEntrypoint(
331
+ argv = process.argv.slice(2),
332
+ env = process.env,
333
+ ) {
334
+ const exitCode = await launchKibiMcp(argv, env);
335
+ process.exitCode = exitCode;
336
+ return exitCode;
337
+ }
338
+
318
339
  /** Spawn the project-local MCP server and mirror its transport and exit state. */
319
- export function launchKibiMcp(argv = process.argv.slice(2), env = process.env) {
340
+ export function launchKibiMcp(
341
+ argv = process.argv.slice(2),
342
+ env = process.env,
343
+ spawnImpl = spawn,
344
+ ) {
320
345
  const [explicitWorkspace, ...childArgs] = argv;
321
346
  let workspaceRoot;
322
347
  let projectLocal;
@@ -332,11 +357,15 @@ export function launchKibiMcp(argv = process.argv.slice(2), env = process.env) {
332
357
  return Promise.resolve(1);
333
358
  }
334
359
 
335
- const child = spawn(process.execPath, [projectLocal.binPath, ...childArgs], {
336
- cwd: workspaceRoot,
337
- env: { ...env, KIBI_WORKSPACE: workspaceRoot },
338
- stdio: ["inherit", "inherit", "inherit"],
339
- });
360
+ const child = spawnImpl(
361
+ process.execPath,
362
+ [projectLocal.binPath, ...childArgs],
363
+ {
364
+ cwd: workspaceRoot,
365
+ env: { ...env, KIBI_WORKSPACE: workspaceRoot },
366
+ stdio: ["inherit", "inherit", "inherit"],
367
+ },
368
+ );
340
369
 
341
370
  return new Promise((resolveExit) => {
342
371
  let finished = false;
@@ -371,8 +400,12 @@ export function launchKibiMcp(argv = process.argv.slice(2), env = process.env) {
371
400
  });
372
401
  }
373
402
 
374
- const entrypoint = process.argv[1] ? resolve(process.argv[1]) : undefined;
375
- if (entrypoint === resolve(fileURLToPath(import.meta.url))) {
376
- const exitCode = await launchKibiMcp(process.argv.slice(2));
377
- process.exitCode = exitCode;
403
+ export async function runLaunchIfEntrypoint(
404
+ isEntrypoint = isLaunchEntrypoint(process.argv[1], import.meta.url),
405
+ start = runLaunchEntrypoint,
406
+ ) {
407
+ if (!isEntrypoint) return;
408
+ await start();
378
409
  }
410
+
411
+ await runLaunchIfEntrypoint();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kibi-cursor",
3
3
  "displayName": "Kibi",
4
- "version": "1.0.1",
4
+ "version": "2.0.0",
5
5
  "description": "Optional Cursor adapter for Kibi. Requires SWI-Prolog 9+ and project-local kibi-cli, kibi-mcp, and kibi-core before the bundled MCP server can start.",
6
6
  "license": "AGPL-3.0-or-later",
7
7
  "author": {
@@ -1,5 +1,23 @@
1
1
  export function parseWorkspaceFolderPaths(value: unknown): string[];
2
2
 
3
+ export function nextAncestorDirectory(current: string): string | undefined;
4
+
5
+ export function packageJsonForResolvedFile(startPath: string): {
6
+ packageJsonPath: string;
7
+ packageRoot: string;
8
+ packageJson: Record<string, unknown>;
9
+ } | null;
10
+
11
+ export function hasConsumerNodeModulesLink(
12
+ workspaceRoot: string,
13
+ packageRoot: string,
14
+ ): boolean;
15
+
16
+ export function isProjectScopedPackage(
17
+ workspaceRoot: string,
18
+ packageRoot: string,
19
+ ): boolean;
20
+
3
21
  export function resolveProjectLocalMcp(workspaceRoot: string): {
4
22
  packageRoot: string;
5
23
  packageJsonPath: string;
@@ -7,12 +25,32 @@ export function resolveProjectLocalMcp(workspaceRoot: string): {
7
25
  binPath: string;
8
26
  };
9
27
 
28
+ export function hasDeclaredProjectDependency(workspaceRoot: string): boolean;
29
+
10
30
  export function resolveWorkspaceRoot(
11
31
  explicitWorkspace?: string,
12
32
  options?: { cwd?: string; env?: NodeJS.ProcessEnv },
13
33
  ): string;
14
34
 
35
+ export function signalExitCode(signal: NodeJS.Signals | string): number;
36
+
37
+ export function isLaunchEntrypoint(
38
+ argv1: string | undefined,
39
+ moduleUrl: string,
40
+ ): boolean;
41
+
42
+ export function runLaunchEntrypoint(
43
+ argv?: string[],
44
+ env?: NodeJS.ProcessEnv,
45
+ ): Promise<number>;
46
+
15
47
  export function launchKibiMcp(
16
48
  argv?: string[],
17
49
  env?: NodeJS.ProcessEnv,
50
+ spawnImpl?: typeof import("node:child_process").spawn,
18
51
  ): Promise<number>;
52
+
53
+ export function runLaunchIfEntrypoint(
54
+ isEntrypoint?: boolean,
55
+ start?: () => Promise<number> | Promise<void>,
56
+ ): Promise<void>;
@@ -7,14 +7,17 @@
7
7
  /**
8
8
  * Launch the kibi-mcp package installed by the consumer project.
9
9
  *
10
- * Cursor starts plugin MCP commands with the plugin directory as their cwd.
11
- * This adapter deliberately knows nothing about the Kibi source tree: it only
12
- * resolves a consumer workspace, finds that workspace's kibi-mcp package, and
13
- * runs its declared bin with the consumer as both cwd and KIBI_WORKSPACE.
10
+ * Cursor resolves this command from the plugin-root manifest, but the process
11
+ * cwd is host-controlled and is not a reliable consumer workspace (it may be
12
+ * the plugin directory or another host directory). This adapter deliberately
13
+ * knows nothing about the Kibi source tree: it resolves the unrelated consumer
14
+ * workspace from Cursor's workspace-folder data or explicit environment,
15
+ * finds that workspace's kibi-mcp package, and runs its declared bin with the
16
+ * consumer as both cwd and KIBI_WORKSPACE.
14
17
  */
15
18
 
16
19
  import { spawn } from "node:child_process";
17
- import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
20
+ import * as fs from "node:fs";
18
21
  import { createRequire } from "node:module";
19
22
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
20
23
  import { fileURLToPath } from "node:url";
@@ -29,12 +32,12 @@ const SIGNAL_EXIT_CODES = {
29
32
  };
30
33
 
31
34
  function readJson(path) {
32
- return JSON.parse(readFileSync(path, "utf8"));
35
+ return JSON.parse(fs.readFileSync(path, "utf8"));
33
36
  }
34
37
 
35
38
  function isDirectory(path) {
36
39
  try {
37
- return statSync(path).isDirectory();
40
+ return fs.statSync(path).isDirectory();
38
41
  } catch {
39
42
  return false;
40
43
  }
@@ -86,17 +89,22 @@ export function parseWorkspaceFolderPaths(value) {
86
89
  .filter(Boolean);
87
90
  }
88
91
 
89
- function packageJsonForResolvedFile(startPath) {
92
+ export function nextAncestorDirectory(current) {
93
+ const parent = dirname(current);
94
+ return parent === current ? undefined : parent;
95
+ }
96
+
97
+ export function packageJsonForResolvedFile(startPath) {
90
98
  let current = resolve(startPath);
91
99
  try {
92
- if (!statSync(current).isDirectory()) current = dirname(current);
100
+ if (!fs.statSync(current).isDirectory()) current = dirname(current);
93
101
  } catch {
94
102
  current = dirname(current);
95
103
  }
96
104
 
97
- while (true) {
105
+ while (current !== undefined) {
98
106
  const packageJsonPath = join(current, "package.json");
99
- if (existsSync(packageJsonPath)) {
107
+ if (fs.existsSync(packageJsonPath)) {
100
108
  try {
101
109
  const packageJson = readJson(packageJsonPath);
102
110
  if (packageJson.name === PACKAGE_NAME) {
@@ -106,10 +114,9 @@ function packageJsonForResolvedFile(startPath) {
106
114
  // Keep walking if a parent package manifest is malformed.
107
115
  }
108
116
  }
109
- const parent = dirname(current);
110
- if (parent === current) return null;
111
- current = parent;
117
+ current = nextAncestorDirectory(current);
112
118
  }
119
+ return null;
113
120
  }
114
121
 
115
122
  function isWithinRoot(rootPath, candidatePath) {
@@ -120,10 +127,10 @@ function isWithinRoot(rootPath, candidatePath) {
120
127
  );
121
128
  }
122
129
 
123
- function hasConsumerNodeModulesLink(workspaceRoot, packageRoot) {
130
+ export function hasConsumerNodeModulesLink(workspaceRoot, packageRoot) {
124
131
  try {
125
132
  const linkPath = join(workspaceRoot, "node_modules", PACKAGE_NAME);
126
- const linkedRoot = realpathSync(linkPath);
133
+ const linkedRoot = fs.realpathSync(linkPath);
127
134
  return (
128
135
  isWithinRoot(linkedRoot, packageRoot) ||
129
136
  isWithinRoot(packageRoot, linkedRoot)
@@ -133,7 +140,7 @@ function hasConsumerNodeModulesLink(workspaceRoot, packageRoot) {
133
140
  }
134
141
  }
135
142
 
136
- function isProjectScopedPackage(workspaceRoot, packageRoot) {
143
+ export function isProjectScopedPackage(workspaceRoot, packageRoot) {
137
144
  if (isWithinRoot(workspaceRoot, packageRoot)) return true;
138
145
 
139
146
  // pnpm can expose a package through a symlink whose realpath is outside the
@@ -197,7 +204,7 @@ export function resolveProjectLocalMcp(workspaceRoot) {
197
204
  }
198
205
 
199
206
  const binPath = resolve(packageInfo.packageRoot, binEntry);
200
- if (!existsSync(binPath)) {
207
+ if (!fs.existsSync(binPath)) {
201
208
  throw new Error(
202
209
  `[KIBI-CURSOR] Project-local ${PACKAGE_NAME} declares a missing executable: ${binPath}. Reinstall the workspace dependency and reload Cursor.`,
203
210
  );
@@ -211,9 +218,9 @@ export function resolveProjectLocalMcp(workspaceRoot) {
211
218
  };
212
219
  }
213
220
 
214
- function hasDeclaredProjectDependency(workspaceRoot) {
221
+ export function hasDeclaredProjectDependency(workspaceRoot) {
215
222
  const packageJsonPath = join(workspaceRoot, "package.json");
216
- if (!existsSync(packageJsonPath)) return false;
223
+ if (!fs.existsSync(packageJsonPath)) return false;
217
224
  try {
218
225
  const packageJson = readJson(packageJsonPath);
219
226
  return [
@@ -235,8 +242,8 @@ function hasDeclaredProjectDependency(workspaceRoot) {
235
242
 
236
243
  function isDemonstrablyProjectWorkspace(workspaceRoot) {
237
244
  return (
238
- existsSync(join(workspaceRoot, ".git")) ||
239
- existsSync(join(workspaceRoot, ".kb")) ||
245
+ fs.existsSync(join(workspaceRoot, ".git")) ||
246
+ fs.existsSync(join(workspaceRoot, ".kb")) ||
240
247
  hasDeclaredProjectDependency(workspaceRoot)
241
248
  );
242
249
  }
@@ -311,12 +318,30 @@ export function resolveWorkspaceRoot(explicitWorkspace, options = {}) {
311
318
  );
312
319
  }
313
320
 
314
- function signalExitCode(signal) {
321
+ export function signalExitCode(signal) {
315
322
  return SIGNAL_EXIT_CODES[signal] ?? 1;
316
323
  }
317
324
 
325
+ export function isLaunchEntrypoint(argv1, moduleUrl) {
326
+ const entrypoint = argv1 ? resolve(argv1) : undefined;
327
+ return entrypoint === resolve(fileURLToPath(moduleUrl));
328
+ }
329
+
330
+ export async function runLaunchEntrypoint(
331
+ argv = process.argv.slice(2),
332
+ env = process.env,
333
+ ) {
334
+ const exitCode = await launchKibiMcp(argv, env);
335
+ process.exitCode = exitCode;
336
+ return exitCode;
337
+ }
338
+
318
339
  /** Spawn the project-local MCP server and mirror its transport and exit state. */
319
- export function launchKibiMcp(argv = process.argv.slice(2), env = process.env) {
340
+ export function launchKibiMcp(
341
+ argv = process.argv.slice(2),
342
+ env = process.env,
343
+ spawnImpl = spawn,
344
+ ) {
320
345
  const [explicitWorkspace, ...childArgs] = argv;
321
346
  let workspaceRoot;
322
347
  let projectLocal;
@@ -332,11 +357,15 @@ export function launchKibiMcp(argv = process.argv.slice(2), env = process.env) {
332
357
  return Promise.resolve(1);
333
358
  }
334
359
 
335
- const child = spawn(process.execPath, [projectLocal.binPath, ...childArgs], {
336
- cwd: workspaceRoot,
337
- env: { ...env, KIBI_WORKSPACE: workspaceRoot },
338
- stdio: ["inherit", "inherit", "inherit"],
339
- });
360
+ const child = spawnImpl(
361
+ process.execPath,
362
+ [projectLocal.binPath, ...childArgs],
363
+ {
364
+ cwd: workspaceRoot,
365
+ env: { ...env, KIBI_WORKSPACE: workspaceRoot },
366
+ stdio: ["inherit", "inherit", "inherit"],
367
+ },
368
+ );
340
369
 
341
370
  return new Promise((resolveExit) => {
342
371
  let finished = false;
@@ -371,8 +400,12 @@ export function launchKibiMcp(argv = process.argv.slice(2), env = process.env) {
371
400
  });
372
401
  }
373
402
 
374
- const entrypoint = process.argv[1] ? resolve(process.argv[1]) : undefined;
375
- if (entrypoint === resolve(fileURLToPath(import.meta.url))) {
376
- const exitCode = await launchKibiMcp(process.argv.slice(2));
377
- process.exitCode = exitCode;
403
+ export async function runLaunchIfEntrypoint(
404
+ isEntrypoint = isLaunchEntrypoint(process.argv[1], import.meta.url),
405
+ start = runLaunchEntrypoint,
406
+ ) {
407
+ if (!isEntrypoint) return;
408
+ await start();
378
409
  }
410
+
411
+ await runLaunchIfEntrypoint();
@@ -11,4 +11,8 @@ export type HookEnvironment = {
11
11
  workspaceTrusted?: boolean;
12
12
  };
13
13
  export declare function runHook(rawInput: unknown, environment?: HookEnvironment): Promise<CursorHookResult>;
14
+ export declare function main(): Promise<void>;
15
+ export declare function isInvokedAsCli(argv1: string | undefined, moduleUrl: string): boolean;
16
+ export declare function runHookCli(): Promise<void>;
17
+ export declare function runHookCliIfMain(isMain?: boolean, start?: typeof runHookCli): Promise<void>;
14
18
  export declare const hookRunnerPath: string;
@@ -195,21 +195,33 @@ export async function runHook(rawInput, environment = {}) {
195
195
  return emptyResult();
196
196
  }
197
197
  }
198
- async function main() {
198
+ export async function main() {
199
199
  const result = await runHook(parseStdinJson(await readStdin()), {
200
200
  workspaceTrusted: process.argv.includes("--trusted-workspace"),
201
201
  });
202
202
  process.stdout.write(`${JSON.stringify(result)}\n`);
203
203
  }
204
- const invokedPath = process.argv[1]
205
- ? pathToFileURL(path.resolve(process.argv[1])).href
206
- : "";
207
- if (import.meta.url === invokedPath) {
208
- main().catch((error) => {
204
+ // implements REQ-cursor-kibi-plugin-v1
205
+ // covered_by TEST-cursor-kibi-plugin-v1
206
+ export function isInvokedAsCli(argv1, moduleUrl) {
207
+ const invokedPath = argv1 ? pathToFileURL(path.resolve(argv1)).href : "";
208
+ return moduleUrl === invokedPath;
209
+ }
210
+ export async function runHookCli() {
211
+ try {
212
+ await main();
213
+ }
214
+ catch (error) {
209
215
  const message = error instanceof Error ? error.message : "Unknown hook error";
210
216
  process.stdout.write(`${JSON.stringify({
211
217
  additional_context: `Kibi hook runner error: ${message}`,
212
218
  })}\n`);
213
- });
219
+ }
220
+ }
221
+ export async function runHookCliIfMain(isMain = isInvokedAsCli(process.argv[1], import.meta.url), start = runHookCli) {
222
+ if (!isMain)
223
+ return;
224
+ await start();
214
225
  }
226
+ void runHookCliIfMain();
215
227
  export const hookRunnerPath = fileURLToPath(import.meta.url);
package/dist/mcp.json CHANGED
@@ -2,7 +2,10 @@
2
2
  "mcpServers": {
3
3
  "kibi": {
4
4
  "command": "node",
5
- "args": ["bin/launch-kibi-mcp.mjs", "${workspaceFolder}"]
5
+ "args": [
6
+ "${CURSOR_PLUGIN_ROOT}/bin/launch-kibi-mcp.mjs",
7
+ "${workspaceFolder}"
8
+ ]
6
9
  }
7
10
  }
8
11
  }
@@ -1,3 +1,4 @@
1
+ export declare function isFreshnessLane(lane: string | undefined): boolean;
1
2
  export declare function extractExplicitPathFields(input: unknown): string[];
2
3
  export declare function isDirectKbPath(candidate: string): boolean;
3
4
  export declare function isMeaningfulTrackedPath(candidate: string): boolean;
@@ -1,3 +1,14 @@
1
+ export function isFreshnessLane(lane) {
2
+ return (lane === "requirements" ||
3
+ lane === "scenarios" ||
4
+ lane === "tests" ||
5
+ lane === "facts" ||
6
+ lane === "adr" ||
7
+ lane === "flags" ||
8
+ lane === "events" ||
9
+ lane === "symbols.yaml" ||
10
+ lane === "symbol-coordinates.yaml");
11
+ }
1
12
  // implements REQ-cursor-kibi-plugin-v1
2
13
  const explicitPathKeys = new Set([
3
14
  "absolute_path",
@@ -145,17 +156,8 @@ export function isKbFreshnessRelevantPath(candidate) {
145
156
  const segments = pathSegments(normalizePath(candidate));
146
157
  if (segments[0] === ".kb") {
147
158
  const lane = segments[1];
148
- if (lane === "requirements" ||
149
- lane === "scenarios" ||
150
- lane === "tests" ||
151
- lane === "facts" ||
152
- lane === "adr" ||
153
- lane === "flags" ||
154
- lane === "events" ||
155
- lane === "symbols.yaml" ||
156
- lane === "symbol-coordinates.yaml") {
159
+ if (isFreshnessLane(lane))
157
160
  return true;
158
- }
159
161
  }
160
162
  // Legacy layout during migration
161
163
  if (segments.includes("documentation")) {
@@ -13,7 +13,7 @@
13
13
  "kibi-traceability/resources/operation-access.md": "39f7972ab7f4ae7479e78f7072bb50e8e6c4cdf4f857425f69d2522d37db437c",
14
14
  "kibi-traceability/resources/source-authoring.md": "408c6ee2bef1b84e0194c0538ef929c26a0a617e631b2234247388140dbbdd08",
15
15
  "kibi-traceability/resources/traceability.md": "38c290a0bc71bd1692e115f22694743946e2f69630e134acfd43cee5f613fb88",
16
- "kibi-usage/SKILL.md": "ed42d8f6caf8048b81c05f670018c5f341e0667e3fa4aff2bf11277e9deb3c2f",
16
+ "kibi-usage/SKILL.md": "47a76e74fa1439e3745afe4c883b9cb1383df7696b1a0d695c02fe4e34e3205d",
17
17
  "kibi-usage/resources/branch-lifecycle.md": "f1bf359e9826e83c548f3cd0287f8175a62456527b0132b06b3f9f74aa59b7d6",
18
18
  "kibi-usage/resources/fact-lanes.md": "41b28023a57593009867ea0ebc8e9f3f05c3bd837144772d12844423f922e763",
19
19
  "kibi-usage/resources/kb-improvement.md": "17e8b6cf6a0dd43b443a2bfd92e7205d099647a5f1c75fe85413a6cea63d86c6",
@@ -2,7 +2,7 @@
2
2
  id: kibi-usage
3
3
  name: Kibi Usage
4
4
  description: Use Kibi's source-first, exact-Git, migration-aware, proof-aware operations safely across MCP or the trusted local CLI, including partial completion repair.
5
- version: 2.1.1
5
+ version: 2.1.2
6
6
  kibiCompatibility: ">=1.0.0"
7
7
  tags:
8
8
  - kibi
@@ -75,6 +75,8 @@ check. Never fire `kb_upsert` calls in parallel; create or confirm endpoint
75
75
  entities before linking them. The canonical MCP names are `kb_search`,
76
76
  `kb_query`, `kb_upsert`, and `kb_check`.
77
77
 
78
+ For a task that explicitly supplies a malformed concrete mutation payload, locate and read that public request artifact before choosing an entity, preserving its exact entity ID, type, requested changes, and every intended relationship and endpoint. Do not substitute a seeded or convenient entity for the requested target. Start with kb_search, then exact-filter those targets with kb_query, and run kb_validate_upsert on that same payload; validation is not completion. Correct only diagnosed pre-commit errors and revalidate the corrected payload. Once authorized, apply the identical corrected and authorized payload with kb_upsert. If it returns committed_with_repairs, treat the mutation as committed, follow only the required repair actions, and neither retry it nor trigger unrelated semantic backfill for a schema-only repair. Exact-read every changed entity and relationship endpoint with kb_query, then finish with an unfiltered kb_check followed by a final kb_status.
79
+
78
80
  ## Closeout fields
79
81
 
80
82
  End every task with these five independent fields:
@@ -147,6 +149,8 @@ grounding: run `logic-coverage` so each key binds to one ground fact.
147
149
  Relationship direction is fixed, and every `from` in a relationship batch
148
150
  must equal the upserted entity ID.
149
151
 
152
+ For conditional relational claims, after the initial `kb_suggest_predicates` and before any `kb_upsert`—including one needed for a missing schema—call read-only `kb_model_requirement` to preview suitable scalar or typed-rule modeling. Treat the preview as advisory: do not apply an irrelevant result or create unrequested facts, and retain an approved ground-predicate plan when it captures the whole claim. Preserve supplied arity, ordered argument roles, polarity, bound values, and one claim key per actual assertion; never split arguments across clauses or schemas or alter values to force uniqueness.
153
+
150
154
  ## Symbol-First Traceability
151
155
 
152
156
  Represent implementation ownership with a `symbol` entity that has
package/mcp.json CHANGED
@@ -2,7 +2,10 @@
2
2
  "mcpServers": {
3
3
  "kibi": {
4
4
  "command": "node",
5
- "args": ["bin/launch-kibi-mcp.mjs", "${workspaceFolder}"]
5
+ "args": [
6
+ "${CURSOR_PLUGIN_ROOT}/bin/launch-kibi-mcp.mjs",
7
+ "${workspaceFolder}"
8
+ ]
6
9
  }
7
10
  }
8
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-cursor",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Kibi Cursor plugin - thin adapter for Cursor MCP integration and editor hooks",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,7 +13,7 @@
13
13
  "kibi-traceability/resources/operation-access.md": "39f7972ab7f4ae7479e78f7072bb50e8e6c4cdf4f857425f69d2522d37db437c",
14
14
  "kibi-traceability/resources/source-authoring.md": "408c6ee2bef1b84e0194c0538ef929c26a0a617e631b2234247388140dbbdd08",
15
15
  "kibi-traceability/resources/traceability.md": "38c290a0bc71bd1692e115f22694743946e2f69630e134acfd43cee5f613fb88",
16
- "kibi-usage/SKILL.md": "ed42d8f6caf8048b81c05f670018c5f341e0667e3fa4aff2bf11277e9deb3c2f",
16
+ "kibi-usage/SKILL.md": "47a76e74fa1439e3745afe4c883b9cb1383df7696b1a0d695c02fe4e34e3205d",
17
17
  "kibi-usage/resources/branch-lifecycle.md": "f1bf359e9826e83c548f3cd0287f8175a62456527b0132b06b3f9f74aa59b7d6",
18
18
  "kibi-usage/resources/fact-lanes.md": "41b28023a57593009867ea0ebc8e9f3f05c3bd837144772d12844423f922e763",
19
19
  "kibi-usage/resources/kb-improvement.md": "17e8b6cf6a0dd43b443a2bfd92e7205d099647a5f1c75fe85413a6cea63d86c6",
@@ -2,7 +2,7 @@
2
2
  id: kibi-usage
3
3
  name: Kibi Usage
4
4
  description: Use Kibi's source-first, exact-Git, migration-aware, proof-aware operations safely across MCP or the trusted local CLI, including partial completion repair.
5
- version: 2.1.1
5
+ version: 2.1.2
6
6
  kibiCompatibility: ">=1.0.0"
7
7
  tags:
8
8
  - kibi
@@ -75,6 +75,8 @@ check. Never fire `kb_upsert` calls in parallel; create or confirm endpoint
75
75
  entities before linking them. The canonical MCP names are `kb_search`,
76
76
  `kb_query`, `kb_upsert`, and `kb_check`.
77
77
 
78
+ For a task that explicitly supplies a malformed concrete mutation payload, locate and read that public request artifact before choosing an entity, preserving its exact entity ID, type, requested changes, and every intended relationship and endpoint. Do not substitute a seeded or convenient entity for the requested target. Start with kb_search, then exact-filter those targets with kb_query, and run kb_validate_upsert on that same payload; validation is not completion. Correct only diagnosed pre-commit errors and revalidate the corrected payload. Once authorized, apply the identical corrected and authorized payload with kb_upsert. If it returns committed_with_repairs, treat the mutation as committed, follow only the required repair actions, and neither retry it nor trigger unrelated semantic backfill for a schema-only repair. Exact-read every changed entity and relationship endpoint with kb_query, then finish with an unfiltered kb_check followed by a final kb_status.
79
+
78
80
  ## Closeout fields
79
81
 
80
82
  End every task with these five independent fields:
@@ -147,6 +149,8 @@ grounding: run `logic-coverage` so each key binds to one ground fact.
147
149
  Relationship direction is fixed, and every `from` in a relationship batch
148
150
  must equal the upserted entity ID.
149
151
 
152
+ For conditional relational claims, after the initial `kb_suggest_predicates` and before any `kb_upsert`—including one needed for a missing schema—call read-only `kb_model_requirement` to preview suitable scalar or typed-rule modeling. Treat the preview as advisory: do not apply an irrelevant result or create unrequested facts, and retain an approved ground-predicate plan when it captures the whole claim. Preserve supplied arity, ordered argument roles, polarity, bound values, and one claim key per actual assertion; never split arguments across clauses or schemas or alter values to force uniqueness.
153
+
150
154
  ## Symbol-First Traceability
151
155
 
152
156
  Represent implementation ownership with a `symbol` entity that has