kibi-cli 2.5.2 → 2.6.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 (138) hide show
  1. package/dist/cli-operation-metadata.d.ts +1 -1
  2. package/dist/cli-operation-metadata.js +1 -1
  3. package/dist/commands/check.d.ts.map +1 -1
  4. package/dist/commands/check.js +15 -0
  5. package/dist/commands/init-helpers.js +1 -1
  6. package/dist/commands/migrate.d.ts.map +1 -1
  7. package/dist/commands/migrate.js +43 -0
  8. package/dist/entity-body-context.d.ts +132 -0
  9. package/dist/entity-body-context.d.ts.map +1 -0
  10. package/dist/entity-body-context.js +382 -0
  11. package/dist/extractors/markdown.d.ts +13 -0
  12. package/dist/extractors/markdown.d.ts.map +1 -1
  13. package/dist/extractors/markdown.js +19 -2
  14. package/dist/intent-search.d.ts.map +1 -1
  15. package/dist/intent-search.js +4 -4
  16. package/dist/operations/bootstrap/candidate-helpers.d.ts +18 -0
  17. package/dist/operations/bootstrap/candidate-helpers.d.ts.map +1 -1
  18. package/dist/operations/bootstrap/candidate-helpers.js +35 -0
  19. package/dist/operations/bootstrap/candidates.d.ts.map +1 -1
  20. package/dist/operations/bootstrap/candidates.js +4 -2
  21. package/dist/operations/bootstrap/generate.d.ts.map +1 -1
  22. package/dist/operations/bootstrap/generate.js +24 -15
  23. package/dist/operations/bootstrap/intent-claims.d.ts.map +1 -1
  24. package/dist/operations/bootstrap/intent-claims.js +210 -5
  25. package/dist/operations/bootstrap/markdown-candidates.d.ts.map +1 -1
  26. package/dist/operations/bootstrap/markdown-candidates.js +7 -3
  27. package/dist/operations/bootstrap/presentation.d.ts +8 -0
  28. package/dist/operations/bootstrap/presentation.d.ts.map +1 -1
  29. package/dist/operations/bootstrap/presentation.js +66 -8
  30. package/dist/operations/bootstrap/types.d.ts +21 -0
  31. package/dist/operations/bootstrap/types.d.ts.map +1 -1
  32. package/dist/operations/bootstrap/types.js +10 -0
  33. package/dist/operations/migration/entity-body-context.d.ts +57 -0
  34. package/dist/operations/migration/entity-body-context.d.ts.map +1 -0
  35. package/dist/operations/migration/entity-body-context.js +261 -0
  36. package/dist/operations/migration/polarity-values.d.ts.map +1 -1
  37. package/dist/operations/migration/polarity-values.js +5 -2
  38. package/dist/operations/migration/schema6.d.ts +2 -0
  39. package/dist/operations/migration/schema6.d.ts.map +1 -1
  40. package/dist/operations/migration/schema6.js +69 -0
  41. package/dist/operations/modeling/logic-modeling.d.ts.map +1 -1
  42. package/dist/operations/modeling/logic-modeling.js +3 -1
  43. package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
  44. package/dist/operations/modeling/model-requirement.js +7 -9
  45. package/dist/operations/mutation/context-warning.d.ts +13 -0
  46. package/dist/operations/mutation/context-warning.d.ts.map +1 -0
  47. package/dist/operations/mutation/context-warning.js +59 -0
  48. package/dist/operations/mutation/origin.d.ts +2 -1
  49. package/dist/operations/mutation/origin.d.ts.map +1 -1
  50. package/dist/operations/mutation/origin.js +7 -18
  51. package/dist/operations/mutation/requirement-semantics.d.ts +16 -0
  52. package/dist/operations/mutation/requirement-semantics.d.ts.map +1 -0
  53. package/dist/operations/mutation/requirement-semantics.js +64 -0
  54. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  55. package/dist/operations/mutation/source-authoring.js +10 -0
  56. package/dist/operations/mutation/stored-entity.d.ts +20 -0
  57. package/dist/operations/mutation/stored-entity.d.ts.map +1 -0
  58. package/dist/operations/mutation/stored-entity.js +51 -0
  59. package/dist/operations/mutation/upsert.d.ts +3 -2
  60. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  61. package/dist/operations/mutation/upsert.js +19 -10
  62. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  63. package/dist/operations/mutation/validate-upsert.js +6 -1
  64. package/dist/operations/planning/compile-intent.d.ts +9 -0
  65. package/dist/operations/planning/compile-intent.d.ts.map +1 -1
  66. package/dist/operations/planning/compile-intent.js +49 -2
  67. package/dist/operations/semantic-advisor/analyze-prose.d.ts +3 -2
  68. package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
  69. package/dist/operations/semantic-advisor/analyze-prose.js +3 -41
  70. package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -1
  71. package/dist/operations/semantic-advisor/ingestion-boundary.js +10 -1
  72. package/dist/operations/semantic-advisor/proposition-role.d.ts +6 -0
  73. package/dist/operations/semantic-advisor/proposition-role.d.ts.map +1 -0
  74. package/dist/operations/semantic-advisor/proposition-role.js +76 -0
  75. package/dist/public/operations/catalog.d.ts +78 -9
  76. package/dist/public/operations/catalog.d.ts.map +1 -1
  77. package/dist/public/operations/check-executor.d.ts.map +1 -1
  78. package/dist/public/operations/check-executor.js +3 -0
  79. package/dist/public/operations/entity-context.d.ts +51 -0
  80. package/dist/public/operations/entity-context.d.ts.map +1 -0
  81. package/dist/public/operations/entity-context.js +235 -0
  82. package/dist/public/operations/origin-review.d.ts +1 -1
  83. package/dist/public/operations/origin-review.js +2 -2
  84. package/dist/public/operations/specs/bootstrap.d.ts +59 -5
  85. package/dist/public/operations/specs/bootstrap.d.ts.map +1 -1
  86. package/dist/public/operations/specs/bootstrap.js +48 -6
  87. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  88. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  89. package/dist/public/operations/specs/check-rules.generated.js +3 -1
  90. package/dist/public/operations/specs/check.d.ts +1 -1
  91. package/dist/public/operations/specs/mutation-schemas.d.ts +1 -1
  92. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  93. package/dist/public/operations/specs/mutation-schemas.js +10 -2
  94. package/dist/public/operations/specs/planning.d.ts +15 -0
  95. package/dist/public/operations/specs/planning.d.ts.map +1 -1
  96. package/dist/public/operations/specs/planning.js +15 -0
  97. package/dist/public/operations/specs/upsert.d.ts +3 -3
  98. package/dist/public/operations/specs/upsert.js +2 -2
  99. package/dist/public/schemas/entity.d.ts.map +1 -1
  100. package/dist/public/schemas/entity.js +7 -1
  101. package/dist/public/skills/kibi-bootstrap/SKILL.md +13 -7
  102. package/dist/public/skills/kibi-bootstrap/resources/bootstrap.md +9 -2
  103. package/dist/public/skills/kibi-usage/SKILL.md +56 -3
  104. package/dist/public/skills/kibi-usage/resources/source-authoring.md +5 -1
  105. package/dist/schemas/entity.schema.json +14 -1
  106. package/dist/search-ranking.d.ts.map +1 -1
  107. package/dist/search-ranking.js +7 -4
  108. package/dist/traceability/staged-consistency.d.ts +25 -0
  109. package/dist/traceability/staged-consistency.d.ts.map +1 -0
  110. package/dist/traceability/staged-consistency.js +92 -0
  111. package/dist/traceability/temp-kb.d.ts.map +1 -1
  112. package/dist/traceability/temp-kb.js +5 -0
  113. package/dist/utils/kb-manifest.d.ts +5 -0
  114. package/dist/utils/kb-manifest.d.ts.map +1 -1
  115. package/dist/utils/kb-manifest.js +6 -0
  116. package/dist/utils/rule-registry.generated.d.ts +11 -0
  117. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  118. package/dist/utils/rule-registry.generated.js +13 -0
  119. package/dist/utils/schema-version.d.ts +1 -1
  120. package/dist/utils/schema-version.d.ts.map +1 -1
  121. package/dist/utils/schema-version.js +3 -2
  122. package/package.json +2 -2
  123. package/schema/manifest.json +5 -0
  124. package/schema/validation.pl +14 -2
  125. package/src/public/operations/check-executor.ts +6 -0
  126. package/src/public/operations/entity-context.ts +304 -0
  127. package/src/public/operations/origin-review.ts +2 -2
  128. package/src/public/operations/specs/bootstrap.ts +52 -5
  129. package/src/public/operations/specs/check-rules.generated.ts +3 -1
  130. package/src/public/operations/specs/mutation-schemas.ts +10 -2
  131. package/src/public/operations/specs/planning.ts +18 -0
  132. package/src/public/operations/specs/upsert.ts +2 -2
  133. package/src/public/schemas/entity.ts +7 -1
  134. package/src/public/skills/kibi-bootstrap/SKILL.md +13 -7
  135. package/src/public/skills/kibi-bootstrap/resources/bootstrap.md +9 -2
  136. package/src/public/skills/kibi-usage/SKILL.md +56 -3
  137. package/src/public/skills/kibi-usage/resources/source-authoring.md +5 -1
  138. package/src/schemas/entity.schema.json +14 -1
@@ -71,7 +71,7 @@ export declare const CLI_OPERATION_METADATA: readonly [{
71
71
  }, {
72
72
  readonly name: "kb_upsert";
73
73
  readonly cliName: "upsert";
74
- readonly description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer a dryRun:true call first because it validates without writing and returns semantic advisor receipts for prose-heavy requirements. Use kb_model (mode requirement) before hand-writing strict property facts from prose, and kb_model (mode predicates) before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request, then upsert the old requirement with status closed (kb_check blocks a superseded requirement that is not closed). Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates; dryRun:true writes nothing.";
74
+ readonly description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer a dryRun:true call first because it validates without writing and returns semantic advisor receipts for prose-heavy requirements. Use kb_model (mode requirement) before hand-writing strict property facts from prose, and kb_model (mode predicates) before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request, then upsert the old requirement with status closed (kb_check blocks a superseded requirement that is not closed). Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Pass a sectioned `document.body` when creating a requirement (the statement, then `## Context` stating why it exists, who asked and the source, then `## Source` with the verbatim excerpt) and a prose body for scenarios, tests, ADRs and observation facts; a result warning reports an entity whose body lacks context, and kb_check blocks it under entity-context-missing. Never invent a reason the requester did not give: write 'Reason not stated'. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates; dryRun:true writes nothing.";
75
75
  }, {
76
76
  readonly name: "kb_delete";
77
77
  readonly cliName: "delete";
@@ -85,7 +85,7 @@ export const CLI_OPERATION_METADATA = [
85
85
  {
86
86
  name: "kb_upsert",
87
87
  cliName: "upsert",
88
- description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer a dryRun:true call first because it validates without writing and returns semantic advisor receipts for prose-heavy requirements. Use kb_model (mode requirement) before hand-writing strict property facts from prose, and kb_model (mode predicates) before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request, then upsert the old requirement with status closed (kb_check blocks a superseded requirement that is not closed). Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates; dryRun:true writes nothing.",
88
+ description: "Create or update one entity and optional relationships. Use for KB mutations after validating intent; prefer a dryRun:true call first because it validates without writing and returns semantic advisor receipts for prose-heavy requirements. Use kb_model (mode requirement) before hand-writing strict property facts from prose, and kb_model (mode predicates) before hand-writing ontology predicate facts. Use the `relationships` array for batch creation of multiple links in a single call (e.g., linking a requirement to multiple tests or facts). Prefer modeling requirements as reusable fact links (`constrains`, `requires_property`, or `requires_predicate`) so consistency and contradiction checks remain queryable. Relationship endpoints must already exist in KB. For requirements, the write will be rejected if it contradicts existing current requirements that constrain the same subject with incompatible properties. To replace a conflicting requirement, include a `supersedes` relationship from the new requirement to the old one in the same request, then upsert the old requirement with status closed (kb_check blocks a superseded requirement that is not closed). Successful writes may return non-blocking semantic advisor warnings; inspect and repair those warnings before treating prose as contradiction-checkable. Pass a sectioned `document.body` when creating a requirement (the statement, then `## Context` stating why it exists, who asked and the source, then `## Source` with the verbatim excerpt) and a prose body for scenarios, tests, ADRs and observation facts; a result warning reports an entity whose body lacks context, and kb_check blocks it under entity-context-missing. Never invent a reason the requester did not give: write 'Reason not stated'. Do not use for read-only inspection. Side effects: writes KB, may refresh symbol coordinates; dryRun:true writes nothing.",
89
89
  },
90
90
  {
91
91
  name: "kb_delete",
@@ -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;AAyE7C,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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AAO,CAAC,SAAS,EAAE,CAAC,CAmGtB;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,aAAa,EACrB,YAAY,EAAE,MAAM,EAAE,GACrB,OAAO,CAAC,SAAS,EAAE,CAAC,CAyCtB;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CAgDtB;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,aAAa,GACpB,OAAO,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;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC,CA+BtB"}
@@ -33,6 +33,7 @@ import { evaluateImpactReview, fingerprintImpactEvaluator, hasValidBaseImpactPol
33
33
  import { IMPACT_REVIEW_PATH } from "../traceability/impact-review.js";
34
34
  import { validateStagedMarkdown } from "../traceability/markdown-validate.js";
35
35
  import { readSnapshotKnowledge } from "../traceability/snapshot-knowledge.js";
36
+ import { collectIntroducedConsistencyViolations, formatConsistencyViolations, stagesKnowledge, } from "../traceability/staged-consistency.js";
36
37
  import { collectStagedKibiDiagnostics, } from "../traceability/staged-diagnostics.js";
37
38
  import { createStagedEntityIdStyleDiagnostics } from "../traceability/staged-entity-id-style.js";
38
39
  import { analyzeStagedFileCoverage, } from "../traceability/staged-file-coverage.js";
@@ -560,6 +561,20 @@ export async function checkCommand(options) {
560
561
  return { exitCode: 1 };
561
562
  }
562
563
  const snapshotEntities = readSnapshotKnowledge(snapshot.readGit, snapshot.headTree, snapshot.readBlobs);
564
+ // A commit must not introduce a contradiction or an infeasible
565
+ // scenario that full `kibi check` would report on the same tree.
566
+ if (stagesKnowledge(stagedInventory.map((file) => file.path))) {
567
+ const consistency = await collectIntroducedConsistencyViolations(snapshot, snapshotEntities);
568
+ if (consistency.length > 0) {
569
+ printSnapshotResult({
570
+ format: options.format,
571
+ coverage: stagedCoverage,
572
+ violations: consistency,
573
+ messages: formatConsistencyViolations(consistency),
574
+ });
575
+ return { exitCode: options.dryRun ? 0 : 1 };
576
+ }
577
+ }
563
578
  const snapshotRequirementIds = new Set(snapshotEntities
564
579
  .filter((row) => row.entity.type === "req")
565
580
  .map((row) => row.entity.id));
@@ -15,7 +15,7 @@
15
15
  You should have received a copy of the GNU Affero General Public License
16
16
  along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
- import { chmodSync, constants, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
18
+ import { constants, chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
19
19
  import * as path from "node:path";
20
20
  import fg from "fast-glob";
21
21
  import { getBranchDiagnostic, resolveActiveBranch, } from "../utils/branch-resolver.js";
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAiEA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAgKD,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,OAAO,EACzB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,CAUR;AAsXD,wBAAgB,+BAA+B,IAAI;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAKtE;AAGD,wBAAsB,cAAc,CAClC,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAuS/B"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAiEA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAuKD,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,OAAO,EACzB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,CAUR;AAsXD,wBAAgB,+BAA+B,IAAI;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAKtE;AAGD,wBAAsB,cAAc,CAClC,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAiW/B"}
@@ -73,6 +73,12 @@ const SCHEMA_MIGRATION_STEPS = [
73
73
  to: 7,
74
74
  description: "Encode legacy polarity-only property facts as eq boolean true with require/forbid polarity; strict fact shapes are blocking.",
75
75
  },
76
+ {
77
+ id: "entity-body-context-v8",
78
+ from: 7,
79
+ to: 8,
80
+ description: "Pin semantic_text on requirements that lack it (computed from the body before context sections stop counting), and tag current entities without body context review:context-missing; front matter only, bodies are preserved.",
81
+ },
76
82
  ];
77
83
  function migrationStepsFor(fromVersion) {
78
84
  const start = Math.max(0, fromVersion ?? 0);
@@ -496,9 +502,23 @@ export async function migrateCommand(options = {}) {
496
502
  const originBackfillStep = migrationSteps.some((step) => step.id === "entity-origin-v6");
497
503
  const { planPolarityValueBackfill, applyPolarityValueBackfill } = await import("../operations/migration/polarity-values.js");
498
504
  const polarityBackfill = planPolarityValueBackfill(cwd);
505
+ const bodyContextStep = migrationSteps.some((step) => step.id === "entity-body-context-v8");
506
+ const { acknowledgedContextIds, applyContextMissingTags, applySemanticTextPins, countByType, planContextMissingTags, planSemanticTextPins, } = await import("../operations/migration/entity-body-context.js");
499
507
  if (options.dryRun) {
500
508
  if (polarityBackfill.length > 0)
501
509
  console.log(`dry run: would encode ${polarityBackfill.length} legacy polarity-only fact(s) as typed booleans.`);
510
+ if (bodyContextStep) {
511
+ const pins = planSemanticTextPins(cwd);
512
+ if (pins.targets.length > 0)
513
+ console.log(`dry run: would pin semantic_text on ${pins.targets.length} requirement(s) that lack it (front matter only; bodies are preserved).`);
514
+ const tags = planContextMissingTags(cwd);
515
+ if (tags.targets.length > 0)
516
+ console.log(`dry run: would tag ${tags.targets.length} current entit(ies) without body context review:context-missing (${Object.entries(countByType(tags.targets))
517
+ .map(([type, count]) => `${count} ${type}`)
518
+ .join(", ")}); no prose is written.`);
519
+ for (const skip of [...pins.skipped, ...tags.skipped])
520
+ printWarning(`Cannot edit ${skip.path}: ${skip.reason}.`);
521
+ }
502
522
  if (storagePlan.moves.length > 0) {
503
523
  console.log(`dry run: would move ${storagePlan.moves.length} legacy knowledge file(s) into .kb/:`);
504
524
  for (const move of storagePlan.moves) {
@@ -558,6 +578,19 @@ export async function migrateCommand(options = {}) {
558
578
  const polarityValuesRewritten = applyPolarityValueBackfill(cwd);
559
579
  if (polarityValuesRewritten > 0)
560
580
  console.log(`Encoded ${polarityValuesRewritten} legacy polarity-only fact(s) as typed booleans.`);
581
+ // Pin before tagging: the pin reads the body as the old derivation did, and
582
+ // tagging then judges context against the statement-only derivation.
583
+ const semanticTextPinned = bodyContextStep ? applySemanticTextPins(cwd) : 0;
584
+ if (semanticTextPinned > 0)
585
+ console.log(`Pinned semantic_text on ${semanticTextPinned} requirement(s) that lacked it.`);
586
+ const contextPlan = bodyContextStep ? planContextMissingTags(cwd) : null;
587
+ const contextTagged = bodyContextStep ? applyContextMissingTags(cwd) : 0;
588
+ if (contextPlan !== null && contextTagged > 0)
589
+ console.log(`Tagged ${contextTagged} current entit(ies) without body context review:context-missing (${Object.entries(countByType(contextPlan.targets))
590
+ .map(([type, count]) => `${count} ${type}`)
591
+ .join(", ")}); no prose was written.`);
592
+ for (const skip of contextPlan?.skipped ?? [])
593
+ printWarning(`Cannot tag ${skip.path}: ${skip.reason}.`);
561
594
  // Source rewrites run before the manifest records the new schema, so an
562
595
  // interrupted run is retried by the next 'kibi migrate --yes'; both are
563
596
  // idempotent.
@@ -571,6 +604,16 @@ export async function migrateCommand(options = {}) {
571
604
  ...existingManifest,
572
605
  schemaVersion: LATEST_KB_SCHEMA_VERSION,
573
606
  semanticAdvisorBackfill,
607
+ ...(contextPlan !== null
608
+ ? {
609
+ contextAcknowledged: [
610
+ ...new Set([
611
+ ...(existingManifest.contextAcknowledged ?? []),
612
+ ...acknowledgedContextIds(contextPlan),
613
+ ]),
614
+ ].sort(),
615
+ }
616
+ : {}),
574
617
  });
575
618
  writeJsonAtomically(auditPath, buildMigrationAuditRecord({
576
619
  branch,
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Entity Markdown bodies carry human and agent context next to, not inside,
3
+ * the checked meaning. This module is the one place that knows which body
4
+ * text is context, so the extractor, the strict check, compile-intent,
5
+ * bootstrap, the migration and search all agree.
6
+ */
7
+ /** Heading words whose sections hold context rather than normative text. */
8
+ export declare const CONTEXT_HEADING_WORDS: readonly ["context", "rationale", "why", "background", "source", "notes", "evidence"];
9
+ /** A context section needs at least this many words of prose. */
10
+ export declare const MIN_CONTEXT_WORDS = 12;
11
+ /** Token-set Jaccard at or above this value counts as a restatement. */
12
+ export declare const RESTATEMENT_JACCARD = 0.8;
13
+ /** Tag that marks legacy entities acknowledged as lacking context. */
14
+ export declare const CONTEXT_MISSING_TAG = "review:context-missing";
15
+ /** One body section; the preamble before the first heading has level 0. */
16
+ export type BodySection = Readonly<{
17
+ level: number;
18
+ heading: string;
19
+ /** Prose lines under the heading, up to the next heading. */
20
+ text: string;
21
+ isContext: boolean;
22
+ }>;
23
+ /** True when a heading's text starts with a context heading word. */
24
+ export declare function isContextHeading(heading: string): boolean;
25
+ /** Split a Markdown body (front matter removed) into sections by ATX headings. */
26
+ export declare function parseBodySections(body: string): BodySection[];
27
+ /**
28
+ * The body with every line of its context sections removed (other lines are
29
+ * untouched), for deriving the checked meaning.
30
+ */
31
+ export declare function withoutContextSections(body: string): string;
32
+ /** Text of the context sections of a body, headings excluded. */
33
+ export declare function contextSectionText(body: string): string;
34
+ /** The entity fields the context rules read. */
35
+ export type ContextEntity = Readonly<{
36
+ title?: unknown;
37
+ semantic_text?: unknown;
38
+ fact_kind?: unknown;
39
+ }>;
40
+ /** Types whose entities must carry body context. */
41
+ export declare const CONTEXT_REQUIRED_TYPES: readonly ["req", "scenario", "test", "adr", "fact"];
42
+ /**
43
+ * True when the type needs no body context: symbols, flags and events, and
44
+ * facts of any fact_kind other than observation or meta (their front matter
45
+ * is the content).
46
+ */
47
+ export declare function isContextExempt(type: string, entity: ContextEntity): boolean;
48
+ /**
49
+ * The body prose that counts as context. Requirements: only text under
50
+ * context headings. Scenarios, tests, ADRs and observation or meta facts:
51
+ * all body prose outside headings.
52
+ */
53
+ export declare function contextProse(type: string, body: string, _entity?: ContextEntity): string;
54
+ /** Normalized token-set Jaccard similarity of two texts (0 when both empty). */
55
+ export declare function tokenSetJaccard(left: string, right: string): number;
56
+ export type ContextAssessment = Readonly<{
57
+ ok: boolean;
58
+ /** Why the context does not count; absent when it does. */
59
+ reason?: "none" | "too_short" | "restatement";
60
+ words: number;
61
+ }>;
62
+ /**
63
+ * Judge an entity's body context: at least MIN_CONTEXT_WORDS words of
64
+ * context prose that do not restate the title (or, for requirements, the
65
+ * semantic text). Exempt types always pass.
66
+ */
67
+ export declare function assessContext(type: string, body: string, entity: ContextEntity): ContextAssessment;
68
+ /** True when the entity's body states context that is not a restatement. */
69
+ export declare function hasContext(type: string, body: string, entity: ContextEntity): boolean;
70
+ export type ContextFinding = Readonly<{
71
+ type: string;
72
+ id: string;
73
+ reason: NonNullable<ContextAssessment["reason"]>;
74
+ words: number;
75
+ description: string;
76
+ suggestion: string;
77
+ }>;
78
+ /**
79
+ * The finding for an entity whose body lacks context, or null when it has
80
+ * context, is exempt, or is acknowledged by the schema 8 migration
81
+ * (`acknowledged`, true only for ids the migration recorded in the manifest;
82
+ * the tag alone never exempts). The strict check and the kb_upsert warning
83
+ * share it.
84
+ */
85
+ export declare function contextFinding(type: string, id: string, body: string, entity: ContextEntity, acknowledged?: boolean): ContextFinding | null;
86
+ /** True when the entity's tags acknowledge missing context as legacy. */
87
+ export declare function isContextAcknowledged(tags: unknown): boolean;
88
+ /** What is missing for a type, in the words the check and warnings use. */
89
+ export declare function missingContextDescription(type: string, reason: ContextAssessment["reason"]): string;
90
+ /** Hint shared by the check finding and the kb_upsert warning. */
91
+ export declare const CONTEXT_MISSING_HINT = "Add a '## Context' section (requirements) or a prose body (scenarios, tests, ADRs, observation facts) stating why this exists, who asked, the source and anything that does not fit the front matter. Never invent a reason the requester did not give: write who asked, the source and 'Reason not stated' in the Context section instead.";
92
+ /** Suggestion for a review:context-missing tag the schema 8 migration did not set. */
93
+ export declare const RESERVED_TAG_HINT = "review:context-missing is reserved for entities acknowledged by the schema 8 migration; add context instead: write who asked, the source and 'Reason not stated' in the Context section, and remove the tag.";
94
+ /** Where an entity's statement came from, for the `## Source` section. */
95
+ export type BodySource = Readonly<{
96
+ /** Verbatim text from the source; rendered as a blockquote. */
97
+ excerpt?: string | undefined;
98
+ /** Human title of the source (a ticket, page or document). */
99
+ title?: string | undefined;
100
+ /** Locator of the source (URL, ticket id, path). */
101
+ reference?: string | undefined;
102
+ }>;
103
+ /**
104
+ * Render a requirement body: the statement, then `## Context` and
105
+ * `## Source` when given. The statement stays the first, heading-free block
106
+ * so it remains the derived meaning when no `semantic_text` is pinned.
107
+ */
108
+ export declare function renderRequirementBody(input: {
109
+ statement: string;
110
+ context?: string | undefined;
111
+ source?: BodySource | undefined;
112
+ }): string;
113
+ /**
114
+ * Revise a requirement body for a changed statement. The non-context part is
115
+ * replaced by the new statement; every context section is kept byte for byte,
116
+ * except that a supplied `context` replaces the `## Context` section and a
117
+ * supplied source replaces the `## Source` section (each is appended when the
118
+ * body had none).
119
+ */
120
+ export declare function reviseRequirementBody(input: {
121
+ existingBody: string;
122
+ statement: string;
123
+ context?: string | undefined;
124
+ source?: BodySource | undefined;
125
+ }): string;
126
+ /**
127
+ * The line a search row shows for a body: the first line of the context
128
+ * prose when the body has any, else the first non-blank body line. With a
129
+ * statement-only body the first line would repeat the title.
130
+ */
131
+ export declare function bodySnippetLine(type: string, body: string, entity?: ContextEntity): string | undefined;
132
+ //# sourceMappingURL=entity-body-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-body-context.d.ts","sourceRoot":"","sources":["../src/entity-body-context.ts"],"names":[],"mappings":"AAkBA;;;;;GAKG;AAEH,4EAA4E;AAE5E,eAAO,MAAM,qBAAqB,uFAQxB,CAAC;AAEX,iEAAiE;AAEjE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,wEAAwE;AAExE,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,sEAAsE;AAEtE,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAQ5D,2EAA2E;AAE3E,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IA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