kibi-opencode 0.5.3 → 0.6.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,10 @@
1
1
  import fs from "node:fs";
2
2
  // implements REQ-opencode-kibi-plugin-v1
3
3
  import path from "node:path";
4
+ import { getKbExistenceTargets } from "./file-filter.js";
5
+ import { detectPosture } from "./repo-posture.js";
4
6
  const KB_CONFIG_FILE = ".kb/config.json";
7
+ // Fallback defaults used when .kb/config.json does not exist
5
8
  const KIBI_DOC_DIRS = [
6
9
  "documentation/requirements",
7
10
  "documentation/scenarios",
@@ -12,24 +15,66 @@ const KIBI_DOC_DIRS = [
12
15
  "documentation/facts",
13
16
  "documentation/symbols.yaml",
14
17
  ];
18
+ // implements REQ-opencode-kibi-plugin-v1
15
19
  /**
16
20
  * Analyze workspace health for Kibi bootstrap and initialization.
21
+ * Uses detectPosture() for root-scoped classification and delegates
22
+ * bootstrap-needs to the posture result.
17
23
  */
18
24
  export function checkWorkspaceHealth(cwd) {
25
+ // Use posture detection for root-scoped classification
26
+ const posture = detectPosture(cwd);
19
27
  const configPath = path.join(cwd, KB_CONFIG_FILE);
20
28
  const missingConfig = !fs.existsSync(configPath);
21
29
  const missingDocDirs = [];
22
- for (const docDir of KIBI_DOC_DIRS) {
23
- const fullPath = path.join(cwd, docDir);
24
- if (!fs.existsSync(fullPath)) {
25
- missingDocDirs.push(docDir);
30
+ if (missingConfig) {
31
+ // No config file: fall back to hardcoded defaults
32
+ for (const docDir of KIBI_DOC_DIRS) {
33
+ const fullPath = path.join(cwd, docDir);
34
+ if (!fs.existsSync(fullPath)) {
35
+ missingDocDirs.push(docDir);
36
+ }
37
+ }
38
+ }
39
+ else {
40
+ // Config exists: check if user specified custom paths
41
+ let hasUserPaths = false;
42
+ try {
43
+ const raw = JSON.parse(fs.readFileSync(configPath, "utf8"));
44
+ hasUserPaths = Boolean(raw?.paths);
45
+ }
46
+ catch {
47
+ hasUserPaths = false;
48
+ }
49
+ if (hasUserPaths) {
50
+ // User has custom paths: resolve targets dynamically
51
+ const targets = getKbExistenceTargets(cwd);
52
+ for (const target of targets) {
53
+ const fullPath = path.join(cwd, target.relativePath);
54
+ if (!fs.existsSync(fullPath)) {
55
+ missingDocDirs.push(target.relativePath);
56
+ }
57
+ }
58
+ }
59
+ else {
60
+ // Config exists but no custom paths: use hardcoded defaults
61
+ for (const docDir of KIBI_DOC_DIRS) {
62
+ const fullPath = path.join(cwd, docDir);
63
+ if (!fs.existsSync(fullPath)) {
64
+ missingDocDirs.push(docDir);
65
+ }
66
+ }
26
67
  }
27
68
  }
28
69
  // Check for any evidence of Kibi usage
29
70
  const kbDir = path.join(cwd, ".kb");
30
71
  const hasKbEvidence = fs.existsSync(kbDir) && fs.readdirSync(kbDir).length > 0;
31
- // If missing config or more than 2 doc dirs are missing, suggest bootstrap
32
- const needsBootstrap = missingConfig || missingDocDirs.length > 2;
72
+ // Delegate needsBootstrap entirely to posture detection:
73
+ // - root_uninitialized true
74
+ // - root_partial → true
75
+ // - vendored_only → false (nested tree handles its own KB)
76
+ // - root_active / hybrid_root_plus_vendored → false
77
+ const needsBootstrap = posture.needsBootstrap;
33
78
  return {
34
79
  needsBootstrap,
35
80
  missingConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-opencode",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "Kibi OpenCode plugin - thin adapter to integrate Kibi with OpenCode sessions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",