kibi-cli 2.21.2 → 2.22.1

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 (113) hide show
  1. package/dist/cli-register-foundation.d.ts.map +1 -1
  2. package/dist/cli-register-foundation.js +1 -0
  3. package/dist/commands/check.d.ts +0 -1
  4. package/dist/commands/check.d.ts.map +1 -1
  5. package/dist/commands/check.js +47 -111
  6. package/dist/commands/doctor.d.ts.map +1 -1
  7. package/dist/commands/doctor.js +108 -6
  8. package/dist/commands/init-helpers.d.ts +16 -2
  9. package/dist/commands/init-helpers.d.ts.map +1 -1
  10. package/dist/commands/init-helpers.js +52 -10
  11. package/dist/commands/init.d.ts +1 -0
  12. package/dist/commands/init.d.ts.map +1 -1
  13. package/dist/commands/init.js +12 -1
  14. package/dist/commands/legacy-storage-migration.d.ts +46 -1
  15. package/dist/commands/legacy-storage-migration.d.ts.map +1 -1
  16. package/dist/commands/legacy-storage-migration.js +219 -9
  17. package/dist/commands/migrate.d.ts +37 -0
  18. package/dist/commands/migrate.d.ts.map +1 -1
  19. package/dist/commands/migrate.js +72 -188
  20. package/dist/commands/sync/manifest.d.ts.map +1 -1
  21. package/dist/commands/sync/manifest.js +9 -0
  22. package/dist/extractors/symbols-coordinator.js +1 -0
  23. package/dist/intent-search.d.ts.map +1 -1
  24. package/dist/intent-search.js +28 -6
  25. package/dist/operations/migration/inventory-rederive.d.ts +40 -1
  26. package/dist/operations/migration/inventory-rederive.d.ts.map +1 -1
  27. package/dist/operations/migration/inventory-rederive.js +99 -8
  28. package/dist/operations/migration/requirement-status.d.ts +25 -0
  29. package/dist/operations/migration/requirement-status.d.ts.map +1 -0
  30. package/dist/operations/migration/requirement-status.js +105 -0
  31. package/dist/operations/migration/schema6.d.ts +25 -0
  32. package/dist/operations/migration/schema6.d.ts.map +1 -1
  33. package/dist/operations/migration/schema6.js +265 -7
  34. package/dist/operations/migration/symbol-legacy-links.d.ts +51 -0
  35. package/dist/operations/migration/symbol-legacy-links.d.ts.map +1 -0
  36. package/dist/operations/migration/symbol-legacy-links.js +319 -0
  37. package/dist/operations/mutation/context-warning.d.ts +12 -2
  38. package/dist/operations/mutation/context-warning.d.ts.map +1 -1
  39. package/dist/operations/mutation/context-warning.js +6 -6
  40. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  41. package/dist/operations/mutation/source-authoring.js +130 -35
  42. package/dist/operations/mutation/types.d.ts +2 -1
  43. package/dist/operations/mutation/types.d.ts.map +1 -1
  44. package/dist/operations/mutation/upsert.d.ts +17 -2
  45. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  46. package/dist/operations/mutation/upsert.js +28 -11
  47. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  48. package/dist/operations/mutation/validate-upsert.js +40 -8
  49. package/dist/operations/mutation/validation.d.ts.map +1 -1
  50. package/dist/operations/mutation/validation.js +43 -1
  51. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  52. package/dist/operations/planning/apply-plan.js +34 -10
  53. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -1
  54. package/dist/operations/semantic-advisor/ingestion-boundary.js +25 -1
  55. package/dist/operations/semantic-advisor/stored-ledger-drift.d.ts +19 -0
  56. package/dist/operations/semantic-advisor/stored-ledger-drift.d.ts.map +1 -0
  57. package/dist/operations/semantic-advisor/stored-ledger-drift.js +78 -0
  58. package/dist/public/impact/diagnostics.d.ts.map +1 -1
  59. package/dist/public/impact/diagnostics.js +24 -14
  60. package/dist/public/operations/catalog.d.ts +3 -3
  61. package/dist/public/operations/check-executor.d.ts.map +1 -1
  62. package/dist/public/operations/check-executor.js +3 -0
  63. package/dist/public/operations/contracts.d.ts.map +1 -1
  64. package/dist/public/operations/contracts.js +6 -1
  65. package/dist/public/operations/decision-firmness.d.ts +3 -1
  66. package/dist/public/operations/decision-firmness.d.ts.map +1 -1
  67. package/dist/public/operations/decision-firmness.js +13 -3
  68. package/dist/public/operations/discovery-executors.d.ts +2 -0
  69. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  70. package/dist/public/operations/discovery-executors.js +24 -2
  71. package/dist/public/operations/migration-plan.d.ts +15 -0
  72. package/dist/public/operations/migration-plan.d.ts.map +1 -1
  73. package/dist/public/operations/migration-plan.js +130 -17
  74. package/dist/public/operations/result-envelope.d.ts.map +1 -1
  75. package/dist/public/operations/result-envelope.js +27 -1
  76. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  77. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  78. package/dist/public/operations/specs/check-rules.generated.js +2 -1
  79. package/dist/public/operations/specs/check.d.ts +1 -1
  80. package/dist/public/operations/specs/planning.d.ts +2 -2
  81. package/dist/public/operations/specs/planning.js +2 -2
  82. package/dist/public/operations/specs/semantic.d.ts.map +1 -1
  83. package/dist/public/operations/specs/semantic.js +26 -1
  84. package/dist/public/operations/symbol-granularity-check.d.ts +18 -0
  85. package/dist/public/operations/symbol-granularity-check.d.ts.map +1 -0
  86. package/dist/public/operations/symbol-granularity-check.js +175 -0
  87. package/dist/public/skills/kibi-usage/SKILL.md +8 -3
  88. package/dist/public/symbol-granularity.d.ts +17 -0
  89. package/dist/public/symbol-granularity.d.ts.map +1 -1
  90. package/dist/public/symbol-granularity.js +21 -0
  91. package/dist/traceability/evidence-model.d.ts +7 -3
  92. package/dist/traceability/evidence-model.d.ts.map +1 -1
  93. package/dist/traceability/staged-symbols-manifest.js +6 -5
  94. package/dist/traceability/validate.d.ts +14 -1
  95. package/dist/traceability/validate.d.ts.map +1 -1
  96. package/dist/traceability/validate.js +41 -0
  97. package/dist/utils/rule-registry.generated.d.ts +5 -0
  98. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  99. package/dist/utils/rule-registry.generated.js +6 -0
  100. package/package.json +3 -3
  101. package/src/public/impact/diagnostics.ts +29 -17
  102. package/src/public/operations/check-executor.ts +7 -0
  103. package/src/public/operations/contracts.ts +6 -1
  104. package/src/public/operations/decision-firmness.ts +18 -2
  105. package/src/public/operations/discovery-executors.ts +28 -2
  106. package/src/public/operations/migration-plan.ts +147 -20
  107. package/src/public/operations/result-envelope.ts +34 -1
  108. package/src/public/operations/specs/check-rules.generated.ts +2 -1
  109. package/src/public/operations/specs/planning.ts +2 -2
  110. package/src/public/operations/specs/semantic.ts +37 -2
  111. package/src/public/operations/symbol-granularity-check.ts +233 -0
  112. package/src/public/skills/kibi-usage/SKILL.md +8 -3
  113. package/src/public/symbol-granularity.ts +37 -0
@@ -1 +1 @@
1
- {"version":3,"file":"cli-register-foundation.d.ts","sourceRoot":"","sources":["../src/cli-register-foundation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAezC,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqJjE"}
1
+ {"version":3,"file":"cli-register-foundation.d.ts","sourceRoot":"","sources":["../src/cli-register-foundation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAezC,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyJjE"}
@@ -12,6 +12,7 @@ export function registerFoundationCommands(program) {
12
12
  .option("--no-hooks", "Do not install git hooks (hooks installed by default)")
13
13
  .option("--github", "Scaffold the GitHub Pages badge + requirement-health report workflow")
14
14
  .option("--badge-only", "With --github, publish only the badge (opt out of the full report)")
15
+ .option("--print-hook <hook>", "Print a snippet that delegates an existing hook (pre-commit, post-checkout, post-merge, post-rewrite) to kibi, and write nothing")
15
16
  .action(withExitCode(async (options) => (await import("./commands/init.js")).initCommand(options)));
16
17
  program
17
18
  .command("migrate")
@@ -25,5 +25,4 @@ export declare function checkDomainContradictions(prolog: PrologProcess): Promis
25
25
  export declare function checkStrictFactShape(prolog: PrologProcess): Promise<Violation[]>;
26
26
  export declare function checkStrictReqFactPairing(prolog: PrologProcess): Promise<Violation[]>;
27
27
  export declare function checkStrictReadiness(prolog: PrologProcess): Promise<Violation[]>;
28
- export declare function checkSymbolCoverage(prolog: PrologProcess): Promise<Violation[]>;
29
28
  //# sourceMappingURL=check.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA8E7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AA8gBD,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,CAAC,EACtC,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC5B,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAC3B,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAMpB;AAGD,wBAAsB,YAAY,CAChC,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA8nB/B;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAoDtB;AAID,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC,CAgBnB;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,IAAI,CAAC,EAAE,MAAM,GACZ,OAA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,CAAC,SAAS,EAAE,CAAC,CA0BtB;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB"}
@@ -41,7 +41,7 @@ import { classifyKibiImpactEvidence, isBehaviorSourceEdit, parseKibiImpactOverri
41
41
  import { assessStagedSymbolsManifest, collectStagedAuthoredSymbolsManifestEvidence, } from "../traceability/staged-symbols-manifest.js";
42
42
  import { createManifestLookupSentinelKey, extractSymbolsFromStagedFileAsync, } from "../traceability/symbol-extract.js";
43
43
  import { cleanupTempKb, consultOverlay, createOverlayFacts, createTempKb, projectStagedEntities, } from "../traceability/temp-kb.js";
44
- import { formatViolations as formatStagedViolations, validateStagedSymbols, } from "../traceability/validate.js";
44
+ import { formatCoverageViolations, formatViolations as formatStagedViolations, validateStagedSymbolCoverage, validateStagedSymbols, } from "../traceability/validate.js";
45
45
  import { resolveReadBranchAttachment } from "../utils/branch-resolver.js";
46
46
  import { CANONICAL_ENTITY_PATHS, isEntityLanePath } from "../utils/kb-paths.js";
47
47
  import { safeCleanupProlog } from "../utils/prolog-cleanup.js";
@@ -708,122 +708,82 @@ export async function checkCommand(options) {
708
708
  : {}),
709
709
  symbolsByFile,
710
710
  }), ...createSemanticReviewDiagnostics({ symbolsByFile }), ...createStagedEntityIdStyleDiagnostics(markdownFiles));
711
- if (allSymbols.length === 0 && stagedEntityResults.length === 0) {
712
- if (stagedKibiDiagnostics.length > 0) {
713
- const blocking = hasBlockingImpactDiagnostics(stagedKibiDiagnostics);
714
- printStagedResult({
715
- format: options.format,
716
- coverage: stagedCoverage,
717
- qualityDiagnostics: stagedKibiDiagnostics,
718
- messages: [
719
- formatStagedKibiDiagnostics(stagedKibiDiagnostics),
720
- // Advisory-only findings still pass; say so explicitly.
721
- ...(!blocking
722
- ? ["✓ No violations found in staged files."]
723
- : []),
724
- ],
725
- });
726
- if (options.dryRun) {
727
- return { exitCode: 0 };
728
- }
729
- return { exitCode: blocking ? 1 : 0 };
730
- }
731
- printSnapshotResult({
732
- format: options.format,
733
- coverage: stagedCoverage,
734
- messages: [noValidatedSymbolsMessage(sourceAnalysis)],
711
+ // Run the Prolog rules over the staged knowledge: the minLinks
712
+ // ownership gate for changed source symbols, and full-check
713
+ // symbol-coverage for every changed symbol (changed source symbols
714
+ // plus symbols whose staged manifest entry changed).
715
+ let violationsRaw = [];
716
+ let coverageViolations = [];
717
+ if (allSymbols.length > 0 || activeStagedSymbolEntityIds.size > 0) {
718
+ tempCtx = await createTempKb();
719
+ await projectStagedEntities(tempCtx.prolog, snapshotEntities);
720
+ const overlayFacts = createOverlayFacts(allSymbols);
721
+ const fs = await import("node:fs/promises");
722
+ await fs.writeFile(tempCtx.overlayPath, overlayFacts, "utf8");
723
+ await fs.cp(tempCtx.overlayPath, path.join(tempCtx.kbPath, "changed_symbols.pl"));
724
+ await consultOverlay(tempCtx);
725
+ violationsRaw = await validateStagedSymbols({
726
+ minLinks,
727
+ prolog: tempCtx.prolog,
735
728
  });
736
- return { exitCode: 0 };
737
- }
738
- if (allSymbols.length === 0) {
739
- if (stagedKibiDiagnostics.length > 0) {
740
- const blocking = hasBlockingImpactDiagnostics(stagedKibiDiagnostics);
741
- printStagedResult({
742
- format: options.format,
743
- coverage: stagedCoverage,
744
- qualityDiagnostics: stagedKibiDiagnostics,
745
- messages: [
746
- formatStagedKibiDiagnostics(stagedKibiDiagnostics),
747
- // Advisory-only findings still pass; say so explicitly.
748
- ...(!blocking
749
- ? ["✓ No violations found in staged files."]
750
- : []),
751
- ],
752
- });
753
- if (options.dryRun) {
754
- return { exitCode: 0 };
755
- }
756
- return { exitCode: blocking ? 1 : 0 };
757
- }
758
- printSnapshotResult({
759
- format: options.format,
760
- coverage: stagedCoverage,
761
- messages: ["✓ No violations found in staged files."],
729
+ coverageViolations = await validateStagedSymbolCoverage({
730
+ prolog: tempCtx.prolog,
731
+ extraSymbolIds: [...activeStagedSymbolEntityIds],
762
732
  });
763
- return { exitCode: 0 };
733
+ await cleanupTempKb(tempCtx.tempDir);
764
734
  }
765
- // Create temp KB
766
- tempCtx = await createTempKb();
767
- await projectStagedEntities(tempCtx.prolog, snapshotEntities);
768
- const overlayFacts = createOverlayFacts(allSymbols);
769
- const fs = await import("node:fs/promises");
770
- await fs.writeFile(tempCtx.overlayPath, overlayFacts, "utf8");
771
- await fs.cp(tempCtx.overlayPath, path.join(tempCtx.kbPath, "changed_symbols.pl"));
772
- await consultOverlay(tempCtx);
773
- const violationsRaw = await validateStagedSymbols({
774
- minLinks,
775
- prolog: tempCtx.prolog,
776
- });
777
- const violationsFormatted = formatStagedViolations(violationsRaw);
778
- if (violationsRaw && violationsRaw.length > 0) {
779
- printSnapshotResult({
735
+ // Without changed source symbols the result was historically printed
736
+ // without re-asserting the snapshot; keep that behavior.
737
+ const print = allSymbols.length === 0 ? printStagedResult : printSnapshotResult;
738
+ const passMessage = allSymbols.length === 0
739
+ ? "✓ No violations found in staged files."
740
+ : "✓ No violations found in staged symbols.";
741
+ if (violationsRaw.length > 0 || coverageViolations.length > 0) {
742
+ print({
780
743
  format: options.format,
781
744
  coverage: stagedCoverage,
782
- violations: violationsRaw,
745
+ violations: [...violationsRaw, ...coverageViolations],
783
746
  qualityDiagnostics: stagedKibiDiagnostics,
784
747
  messages: [
785
748
  ...(stagedKibiDiagnostics.length > 0
786
749
  ? [formatStagedKibiDiagnostics(stagedKibiDiagnostics)]
787
750
  : []),
788
- violationsFormatted,
751
+ ...(coverageViolations.length > 0
752
+ ? [formatCoverageViolations(coverageViolations)]
753
+ : []),
754
+ ...(violationsRaw.length > 0
755
+ ? [formatStagedViolations(violationsRaw)]
756
+ : []),
789
757
  ],
790
758
  });
791
- await cleanupTempKb(tempCtx.tempDir);
792
- if (options.dryRun) {
793
- return { exitCode: 0 };
794
- }
795
- return { exitCode: 1 };
759
+ return { exitCode: options.dryRun ? 0 : 1 };
796
760
  }
797
761
  if (stagedKibiDiagnostics.length > 0) {
798
- await cleanupTempKb(tempCtx.tempDir);
799
762
  const blocking = hasBlockingImpactDiagnostics(stagedKibiDiagnostics);
800
- printSnapshotResult({
763
+ print({
801
764
  format: options.format,
802
765
  coverage: stagedCoverage,
803
766
  qualityDiagnostics: stagedKibiDiagnostics,
804
767
  messages: [
805
768
  formatStagedKibiDiagnostics(stagedKibiDiagnostics),
806
- ...(!blocking
807
- ? ["✓ No violations found in staged symbols."]
808
- : []),
769
+ // Advisory-only findings still pass; say so explicitly.
770
+ ...(!blocking ? [passMessage] : []),
809
771
  ],
810
772
  });
811
773
  if (options.dryRun) {
812
774
  return { exitCode: 0 };
813
775
  }
814
- if (!blocking) {
815
- return { exitCode: 0 };
816
- }
817
- return {
818
- exitCode: 1,
819
- };
776
+ return { exitCode: blocking ? 1 : 0 };
820
777
  }
821
778
  printSnapshotResult({
822
779
  format: options.format,
823
780
  coverage: stagedCoverage,
824
- messages: ["✓ No violations found in staged symbols."],
781
+ messages: [
782
+ allSymbols.length === 0 && stagedEntityResults.length === 0
783
+ ? noValidatedSymbolsMessage(sourceAnalysis)
784
+ : passMessage,
785
+ ],
825
786
  });
826
- await cleanupTempKb(tempCtx.tempDir);
827
787
  return { exitCode: 0 };
828
788
  }
829
789
  catch (err) {
@@ -1293,27 +1253,3 @@ export async function checkStrictReadiness(prolog) {
1293
1253
  }
1294
1254
  return violations;
1295
1255
  }
1296
- export async function checkSymbolCoverage(prolog) {
1297
- const violations = [];
1298
- const uncoveredResult = await prolog.query("setof(Symbol, symbol_no_req_coverage(Symbol, _), Symbols)");
1299
- if (uncoveredResult.success && uncoveredResult.bindings.Symbols) {
1300
- const symbolsStr = uncoveredResult.bindings.Symbols;
1301
- const match = symbolsStr.match(/\[(.*)\]/);
1302
- const content = getMatchGroup(match)?.trim();
1303
- if (content) {
1304
- const symbolMatches = content.matchAll(/'([^']+)'/g);
1305
- for (const symbolMatch of symbolMatches) {
1306
- const symbolId = getMatchGroup(symbolMatch);
1307
- if (!symbolId)
1308
- continue;
1309
- violations.push({
1310
- rule: "symbol-coverage",
1311
- entityId: symbolId,
1312
- description: "Code symbol is not traceable to any functional requirement.",
1313
- suggestion: "Update symbols.yaml to link this symbol to a related requirement.",
1314
- });
1315
- }
1316
- }
1317
- }
1318
- return violations;
1319
- }
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AA4FA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B;AAGD,wBAAsB,aAAa,CACjC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAmH/B;AAED,wBAAsB,4BAA4B,CAChD,IAAI,GAAE,MAAM,OAAO,CAAC;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,CACT,GACxC,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;;;;;;;;;;;;;;;;MAkE3C;AAkGD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGzE;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAepB"}
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAiGA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B;AAGD,wBAAsB,aAAa,CACjC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAmH/B;AAED,wBAAsB,4BAA4B,CAChD,IAAI,GAAE,MAAM,OAAO,CAAC;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,CACT,GACxC,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;;;;;;;;;;;;;;;;MAkE3C;AAkGD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGzE;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAepB"}
@@ -29,7 +29,8 @@ import { resolveBranchAttachment, resolveReadBranchAttachment, } from "../utils/
29
29
  import { branchStoreCompilation, inspectBranchStore, storeLockTakeoverReason, uncompiledBranchStoreReason, } from "../utils/branch-store.js";
30
30
  import { resolveGitRepository, } from "../utils/git-repository-context.js";
31
31
  import { readKbManifestStatus } from "../utils/kb-manifest.js";
32
- import { hasManagedHooks, outdatedManagedHooks } from "./init-helpers.js";
32
+ import { LATEST_KB_SCHEMA_VERSION } from "../utils/schema-version.js";
33
+ import { KIBI_HOOK_BEGIN, hasManagedHooks, outdatedManagedHooks, } from "./init-helpers.js";
33
34
  import { planLegacyStorageMigration } from "./legacy-storage-migration.js";
34
35
  /**
35
36
  * First-party plugin diagnostics known without importing the package.
@@ -616,6 +617,17 @@ function checkKbManifest() {
616
617
  remediation: `Repair .kb/manifest.json: ${status.warning}`,
617
618
  };
618
619
  }
620
+ // A knowledge base written by an older Kibi keeps reading and checking
621
+ // until migrated, but the current CLI expects its own schema: say so here,
622
+ // where the operator looks first, instead of leaving it to the next
623
+ // failing check. The migration plan below names the actions.
624
+ if (status.manifest.schemaVersion < LATEST_KB_SCHEMA_VERSION) {
625
+ return {
626
+ passed: false,
627
+ message: `schemaVersion ${status.manifest.schemaVersion} (this Kibi expects ${LATEST_KB_SCHEMA_VERSION})`,
628
+ remediation: "Run: kibi migrate (previews the plan), then kibi migrate --yes to apply it, or kibi migrate --apply-safe --approved-plan-hash <planHash> --approved-action <id> for selected actions",
629
+ };
630
+ }
619
631
  return {
620
632
  passed: true,
621
633
  message: `schemaVersion ${status.manifest.schemaVersion}`,
@@ -634,15 +646,18 @@ function checkLegacyStorage() {
634
646
  if (plan.blockers.length > 0) {
635
647
  return {
636
648
  passed: false,
637
- message: `${plan.moves.length} legacy knowledge file(s) outside .kb/ cannot be moved automatically`,
638
- remediation: `${plan.blockers.join(" ")} Compare each legacy copy with its .kb/ copy and keep the current one: replace the .kb/ copy when the legacy one is newer, or remove (git rm) the legacy copy when it is a stale duplicate. Then run: kibi migrate --yes`,
649
+ message: `${plan.blockers.length} legacy knowledge file(s) outside .kb/ cannot be moved automatically`,
650
+ remediation: `${plan.blockers.join(" ")} Then run: kibi migrate --yes`,
639
651
  };
640
652
  }
641
- if (plan.legacyConfig === "present" || plan.moves.length > 0) {
653
+ if (plan.legacyConfig === "present" ||
654
+ plan.moves.length > 0 ||
655
+ plan.removals.length > 0) {
656
+ const outside = plan.moves.length + plan.removals.length;
642
657
  return {
643
658
  passed: false,
644
- message: plan.moves.length > 0
645
- ? `${plan.moves.length} legacy knowledge file(s) still outside .kb/`
659
+ message: outside > 0
660
+ ? `${outside} legacy knowledge file(s) still outside .kb/${plan.removals.length > 0 ? ` (${plan.removals.length} identical to the .kb/ copy, which kibi migrate removes)` : ""}`
646
661
  : "Legacy .kb/config.json still present",
647
662
  remediation: "Run: kibi migrate --yes",
648
663
  };
@@ -860,6 +875,66 @@ function checkGitHooks() {
860
875
  remediation: "Run: kibi init",
861
876
  };
862
877
  }
878
+ /**
879
+ * Individual shell commands of a hook script, ignoring comments. Lines are
880
+ * split on command separators so `a && b` counts as two commands.
881
+ */
882
+ // implements REQ-git-hook-effective-install
883
+ function hookCommands(content) {
884
+ return content
885
+ .split("\n")
886
+ .filter((line) => !line.trimStart().startsWith("#"))
887
+ .flatMap((line) => line.split(/&&|\|\||;|\|/))
888
+ .map((command) => command.trim())
889
+ .filter((command) => command.length > 0);
890
+ }
891
+ // Matches `kibi <sub>`, `npx kibi <sub>`, `node_modules/.bin/kibi <sub>` and
892
+ // the template's `"$KIBI_BIN" <sub>`.
893
+ // implements REQ-git-hook-effective-install
894
+ function invokesKibi(command, subcommand) {
895
+ return new RegExp(`(?:\\bkibi|\\bKIBI_BIN)["'}]*\\s+${subcommand}(?=\\s|$)`).test(command);
896
+ }
897
+ /** The pre-commit gate the managed template runs, as a custom hook must. */
898
+ const PRE_COMMIT_DELEGATIONS = [
899
+ {
900
+ label: "kibi check-generated --staged --changed-only",
901
+ matches: (command) => invokesKibi(command, "check-generated") &&
902
+ /\s--staged(?=\s|$)/.test(command) &&
903
+ /\s--changed-only(?=\s|$)/.test(command),
904
+ },
905
+ {
906
+ label: "kibi check --staged",
907
+ matches: (command) => invokesKibi(command, "check") && /\s--staged(?=\s|$)/.test(command),
908
+ },
909
+ ];
910
+ // implements REQ-git-hook-effective-install
911
+ function checkCustomPreCommitHook(content, executable) {
912
+ const commands = hookCommands(content);
913
+ const missing = PRE_COMMIT_DELEGATIONS.filter((delegation) => !commands.some(delegation.matches)).map((delegation) => `'${delegation.label}'`);
914
+ if (missing.length > 0) {
915
+ // An unmarked file that still carries the old template header is a Kibi
916
+ // hook from before managed sections; removing it lets init reinstall it.
917
+ const oldTemplate = content.includes("# pre-commit hook for kibi")
918
+ ? " If this file is an old Kibi template, delete it and run 'kibi init' instead."
919
+ : "";
920
+ return {
921
+ passed: false,
922
+ message: `Custom pre-commit hook (no kibi-managed section) does not run ${missing.join(" or ")}; commits skip Kibi enforcement${hooksPathSuffix()}`,
923
+ remediation: `Delegate from your hook to both 'kibi check-generated --staged --changed-only' and 'kibi check --staged'. Print a copy-paste snippet that resolves a project-local kibi with: kibi init --print-hook pre-commit (kibi init never edits a custom hook).${oldTemplate}`,
924
+ };
925
+ }
926
+ if (!executable) {
927
+ return {
928
+ passed: false,
929
+ message: `Installed but not executable${hooksPathSuffix()}`,
930
+ remediation: remediationHookPaths("pre-commit"),
931
+ };
932
+ }
933
+ return {
934
+ passed: true,
935
+ message: `Custom hook delegates to 'kibi check-generated --staged --changed-only' and 'kibi check --staged'${hooksPathSuffix()}`,
936
+ };
937
+ }
863
938
  function checkPreCommitHook() {
864
939
  const postCheckoutPath = path.join(effectiveHooksDir(), "post-checkout");
865
940
  const postMergePath = path.join(effectiveHooksDir(), "post-merge");
@@ -885,6 +960,12 @@ function checkPreCommitHook() {
885
960
  const preCommitExecutable = (preCommitStats.mode & 0o111) !== 0;
886
961
  // Read hook content to determine whether it's using the new staged check
887
962
  const content = readFileSync(preCommitPath, "utf-8");
963
+ // A hook without a kibi-managed section is the user's own (hand-written,
964
+ // husky, lefthook, ...). `kibi init` never edits it, so the only useful
965
+ // check is whether it delegates to the gate the managed template runs.
966
+ if (!content.includes(KIBI_HOOK_BEGIN)) {
967
+ return checkCustomPreCommitHook(content, preCommitExecutable);
968
+ }
888
969
  // Current templates resolve the kibi binary into KIBI_BIN before invoking
889
970
  // it (git hooks do not get node_modules/.bin on PATH); legacy templates
890
971
  // invoked bare `kibi`.
@@ -963,6 +1044,27 @@ function checkPostRewriteHook() {
963
1044
  // Read hook content to verify it invokes kibi. Current templates invoke
964
1045
  // the resolved KIBI_BIN; legacy templates invoked bare `kibi sync`.
965
1046
  const content = readFileSync(postRewritePath, "utf-8");
1047
+ // A custom hook (no kibi-managed section) is never edited by init.
1048
+ // implements REQ-git-hook-effective-install
1049
+ if (!content.includes(KIBI_HOOK_BEGIN)) {
1050
+ if (!hookCommands(content).some((cmd) => invokesKibi(cmd, "sync"))) {
1051
+ return {
1052
+ passed: false,
1053
+ message: `Custom post-rewrite hook (no kibi-managed section) does not run 'kibi sync'${hooksPathSuffix()}`,
1054
+ remediation: "Delegate from your hook to 'kibi sync' after rebases. Print a copy-paste snippet that resolves a project-local kibi with: kibi init --print-hook post-rewrite (kibi init never edits a custom hook).",
1055
+ };
1056
+ }
1057
+ return postRewriteExecutable
1058
+ ? {
1059
+ passed: true,
1060
+ message: `Custom hook delegates to 'kibi sync'${hooksPathSuffix()}`,
1061
+ }
1062
+ : {
1063
+ passed: false,
1064
+ message: `Installed but not executable${hooksPathSuffix()}`,
1065
+ remediation: remediationHookPaths("post-rewrite"),
1066
+ };
1067
+ }
966
1068
  const usesKibi = content.includes('"$KIBI_BIN" sync') || content.includes("kibi sync");
967
1069
  const resolvesKibi = content.includes("KIBI_BIN=");
968
1070
  if (!usesKibi) {
@@ -1,13 +1,27 @@
1
1
  export declare function getCurrentBranch(cwd?: string): Promise<string>;
2
2
  export declare function createKbDirectoryStructure(kbDir: string, currentBranch: string): void;
3
3
  export declare function createManifestFile(kbDir: string): void;
4
- export declare function updateGitIgnore(cwd: string): void;
4
+ /** Adds the canonical derived entries to .gitignore; true when it changed the file. */
5
+ export declare function updateGitIgnore(cwd: string): boolean;
5
6
  export declare function ensureSymbolsManifestFile(cwd: string): void;
6
7
  export declare function copySchemaFiles(kbDir: string, schemaSourceDir: string): Promise<void>;
8
+ export declare const KIBI_HOOK_BEGIN = "# BEGIN kibi-managed";
7
9
  export type InstallHookResult = "installed" | "updated" | "skipped-foreign" | "skipped-symlink" | "skipped-unsupported";
10
+ /** Hook names `kibi init` manages, in install order. */
11
+ export declare const MANAGED_HOOK_NAMES: readonly ["post-checkout", "post-merge", "post-rewrite", "pre-commit"];
12
+ export type ManagedHookName = (typeof MANAGED_HOOK_NAMES)[number];
13
+ export declare function isManagedHookName(value: string): value is ManagedHookName;
14
+ /**
15
+ * A copy-paste snippet for wiring Kibi into a hook that Kibi does not own
16
+ * (hand-written, husky, lefthook, ...). It reuses the managed template's
17
+ * KIBI_BIN resolution, so a project-local kibi CLI is found even though git
18
+ * does not put node_modules/.bin on PATH, and every command propagates its
19
+ * failure so the delegation is never weaker than the template it replaces.
20
+ */
21
+ export declare function hookDelegationSnippet(hook: ManagedHookName): string;
8
22
  export declare function installHook(hookPath: string, content: string): InstallHookResult;
9
23
  export interface GitHookInstallResult {
10
- hook: "pre-commit" | "post-checkout" | "post-merge" | "post-rewrite";
24
+ hook: ManagedHookName;
11
25
  result: InstallHookResult;
12
26
  }
13
27
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"init-helpers.d.ts","sourceRoot":"","sources":["../../src/commands/init-helpers.ts"],"names":[],"mappings":"AA6IA,wBAAsB,gBAAgB,CACpC,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GACpB,IAAI,CA0BN;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGtD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CA6BjD;AAkDD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAU3D;AAED,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAuBf;AASD,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,iBAAiB,GACjB,qBAAqB,CAAC;AAoB1B,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,iBAAiB,CAwEnB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,YAAY,GAAG,eAAe,GAAG,YAAY,GAAG,cAAc,CAAC;IACrE,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAiBD;;;;GAIG;AAEH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EA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M,CAqBnE;AAkBD,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,iBAAiB,CAwEnB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAiBD;;;;GAIG;AAEH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAU/D;AAED,wEAAwE;AAExE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQzD;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GAChD,oBAAoB,EAAE,CA8CxB"}
@@ -155,6 +155,7 @@ export function createManifestFile(kbDir) {
155
155
  writeKbManifest(path.dirname(kbDir), defaultKbManifest());
156
156
  console.log("✓ Created Kibi lifecycle manifest at .kb/manifest.json");
157
157
  }
158
+ /** Adds the canonical derived entries to .gitignore; true when it changed the file. */
158
159
  export function updateGitIgnore(cwd) {
159
160
  // implements REQ-cli-init-canonical
160
161
  const gitignorePath = path.join(cwd, ".gitignore");
@@ -179,7 +180,9 @@ export function updateGitIgnore(cwd) {
179
180
  if (updatedContent !== gitignoreContent) {
180
181
  writeFileSync(gitignorePath, updatedContent);
181
182
  console.log("✓ Configured .gitignore for the canonical .kb/ layout");
183
+ return true;
182
184
  }
185
+ return false;
183
186
  }
184
187
  /** Exact derived-runtime entries owned by current Kibi init/migrate. */
185
188
  const CANONICAL_DERIVED_GITIGNORE_ENTRIES = [
@@ -258,26 +261,65 @@ export async function copySchemaFiles(kbDir, schemaSourceDir) {
258
261
  }
259
262
  console.log(`✓ Ensured ${schemaFiles.length} schema files`);
260
263
  }
261
- const KIBI_HOOK_BEGIN = "# BEGIN kibi-managed";
264
+ export const KIBI_HOOK_BEGIN = "# BEGIN kibi-managed";
262
265
  const KIBI_HOOK_END = "# END kibi-managed";
263
266
  function escapeRegex(s) {
264
267
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
265
268
  }
269
+ /** Hook names `kibi init` manages, in install order. */
270
+ export const MANAGED_HOOK_NAMES = [
271
+ "post-checkout",
272
+ "post-merge",
273
+ "post-rewrite",
274
+ "pre-commit",
275
+ ];
276
+ // implements REQ-git-hook-effective-install
277
+ export function isManagedHookName(value) {
278
+ return MANAGED_HOOK_NAMES.includes(value);
279
+ }
280
+ /**
281
+ * A copy-paste snippet for wiring Kibi into a hook that Kibi does not own
282
+ * (hand-written, husky, lefthook, ...). It reuses the managed template's
283
+ * KIBI_BIN resolution, so a project-local kibi CLI is found even though git
284
+ * does not put node_modules/.bin on PATH, and every command propagates its
285
+ * failure so the delegation is never weaker than the template it replaces.
286
+ */
287
+ // implements REQ-git-hook-effective-install
288
+ export function hookDelegationSnippet(hook) {
289
+ const header = [
290
+ `# Kibi ${hook} delegation (printed by 'kibi init --print-hook ${hook}').`,
291
+ `# Paste into your existing ${hook} hook; it runs the same Kibi commands`,
292
+ "# as the Kibi-managed template.",
293
+ ].join("\n");
294
+ const guarded = (condition, commands) => {
295
+ const body = `${KIBI_BIN_RESOLVER}\n${commands}`.replace(/^(?=.)/gm, " ");
296
+ return `${header}\nif ${condition}; then\n${body}\nfi\n`;
297
+ };
298
+ switch (hook) {
299
+ case "pre-commit":
300
+ return `${header}\n${KIBI_BIN_RESOLVER}\n"$KIBI_BIN" check-generated --staged --changed-only || exit $?\n"$KIBI_BIN" check --staged || exit $?\n`;
301
+ case "post-checkout":
302
+ // Only branch checkouts refresh the KB; file checkouts are skipped.
303
+ return guarded('[ "$3" = "1" ]', '"$KIBI_BIN" sync');
304
+ case "post-merge":
305
+ return `${header}\n${KIBI_BIN_RESOLVER}\n"$KIBI_BIN" sync\n`;
306
+ case "post-rewrite":
307
+ return guarded('[ "$1" = "rebase" ]', '"$KIBI_BIN" sync');
308
+ }
309
+ }
266
310
  function hookIntegrationRecipe(hook) {
267
- // Recipes must reproduce the exact checks the Kibi template runs for that
268
- // hook, with failure propagation, or the delegation is weaker than the
269
- // template it replaces.
311
+ // Recipes must name the exact checks the Kibi template runs for that hook;
312
+ // the printed snippet adds CLI resolution and failure propagation.
313
+ const printHook = `print a copy-paste snippet that resolves a project-local kibi with 'kibi init --print-hook ${hook}'`;
270
314
  switch (hook) {
271
315
  case "pre-commit":
272
- return "delegate from that hook with 'kibi check-generated --staged --changed-only && kibi check --staged' (both commands must succeed; '&&' propagates the first failure)";
316
+ return `delegate from that hook to both 'kibi check-generated --staged --changed-only' and 'kibi check --staged' (both must succeed); ${printHook}`;
273
317
  case "post-checkout":
274
- return "delegate from that hook to 'kibi sync' on branch checkouts (the template skips file checkouts)";
318
+ return `delegate from that hook to 'kibi sync' on branch checkouts (the template skips file checkouts); ${printHook}`;
275
319
  case "post-merge":
276
- return "delegate from that hook to 'kibi sync'";
320
+ return `delegate from that hook to 'kibi sync'; ${printHook}`;
277
321
  case "post-rewrite":
278
- return "delegate from that hook to 'kibi sync' after rebase/amend rewrites";
279
- default:
280
- return "delegate to the matching Kibi template command";
322
+ return `delegate from that hook to 'kibi sync' after rebase rewrites; ${printHook}`;
281
323
  }
282
324
  }
283
325
  export function installHook(hookPath, content) {
@@ -2,6 +2,7 @@ interface InitOptions {
2
2
  hooks?: boolean;
3
3
  github?: boolean;
4
4
  badgeOnly?: boolean;
5
+ printHook?: string;
5
6
  }
6
7
  export declare function initCommand(options: InitOptions): Promise<{
7
8
  exitCode: number;
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAoGA,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAoDD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAkJ/B"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAuGA,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoDD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAgK/B"}
@@ -24,7 +24,7 @@ import { resolveBranchAttachment } from "../utils/branch-resolver.js";
24
24
  import { readLegacyKbConfig } from "../utils/config.js";
25
25
  import { resolveGitRepository, } from "../utils/git-repository-context.js";
26
26
  import { scaffoldGitHubIntegration } from "./github-init.js";
27
- import { copySchemaFiles, createKbDirectoryStructure, createManifestFile, ensureSymbolsManifestFile, installGitHooks, updateGitIgnore, } from "./init-helpers.js";
27
+ import { MANAGED_HOOK_NAMES, copySchemaFiles, createKbDirectoryStructure, createManifestFile, ensureSymbolsManifestFile, hookDelegationSnippet, installGitHooks, isManagedHookName, updateGitIgnore, } from "./init-helpers.js";
28
28
  const __filename = fileURLToPath(import.meta.url);
29
29
  const __dirname = path.dirname(__filename);
30
30
  /**
@@ -121,6 +121,17 @@ async function initNextAction(projectRoot) {
121
121
  // implements REQ-cli-init
122
122
  // implements REQ-kibi-github-report-integration
123
123
  export async function initCommand(options) {
124
+ if (options.printHook !== undefined) {
125
+ // Print-only mode: emit a delegation snippet for a hook Kibi does not
126
+ // own and touch nothing, not even the repository context.
127
+ // implements REQ-git-hook-effective-install
128
+ if (!isManagedHookName(options.printHook)) {
129
+ console.error(`Error: unknown hook '${options.printHook}' for --print-hook. Expected one of: ${MANAGED_HOOK_NAMES.join(", ")}.`);
130
+ return { exitCode: 1 };
131
+ }
132
+ process.stdout.write(hookDelegationSnippet(options.printHook));
133
+ return { exitCode: 0 };
134
+ }
124
135
  if (options.badgeOnly === true && options.github !== true) {
125
136
  console.error("Error: --badge-only requires --github. The recommended integration is `kibi init --github` (badge + full report).");
126
137
  return { exitCode: 1 };