kibi-cursor 0.2.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.cursor-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +71 -0
  3. package/README.md +7 -5
  4. package/dist/.cursor-plugin/plugin.json +1 -1
  5. package/dist/guidance.d.ts +10 -2
  6. package/dist/guidance.js +27 -17
  7. package/dist/hook-runner.d.ts +1 -0
  8. package/dist/hook-runner.js +41 -11
  9. package/dist/hook-state-storage.d.ts +11 -0
  10. package/dist/hook-state-storage.js +187 -0
  11. package/dist/hook-state.d.ts +9 -5
  12. package/dist/hook-state.js +14 -196
  13. package/dist/kb-mcp-tools.d.ts +9 -0
  14. package/dist/kb-mcp-tools.js +94 -0
  15. package/dist/messages.d.ts +4 -2
  16. package/dist/messages.js +33 -3
  17. package/dist/path-policy.d.ts +1 -0
  18. package/dist/path-policy.js +18 -0
  19. package/dist/rules/kibi-traceability.mdc +2 -0
  20. package/dist/rules/kibi-workflow.mdc +3 -3
  21. package/dist/skills/.canon-hash.json +10 -0
  22. package/dist/skills/init-kibi/SKILL.md +50 -11
  23. package/dist/skills/kibi-freshness/SKILL.md +32 -10
  24. package/dist/skills/kibi-traceability/SKILL.md +41 -9
  25. package/dist/skills/kibi-usage/SKILL.md +123 -95
  26. package/dist/skills/kibi-usage/resources/fact-lanes.md +225 -0
  27. package/dist/skills/kibi-usage/resources/operation-access.md +44 -0
  28. package/dist/skills/kibi-usage/resources/relationship-directions.md +119 -0
  29. package/dist/skills/kibi-usage/resources/workflows.md +65 -0
  30. package/package.json +2 -2
  31. package/rules/kibi-traceability.mdc +2 -0
  32. package/rules/kibi-workflow.mdc +3 -3
  33. package/skills/.canon-hash.json +10 -0
  34. package/skills/init-kibi/SKILL.md +50 -11
  35. package/skills/kibi-freshness/SKILL.md +32 -10
  36. package/skills/kibi-traceability/SKILL.md +41 -9
  37. package/skills/kibi-usage/SKILL.md +123 -95
  38. package/skills/kibi-usage/resources/fact-lanes.md +225 -0
  39. package/skills/kibi-usage/resources/operation-access.md +44 -0
  40. package/skills/kibi-usage/resources/relationship-directions.md +119 -0
  41. package/skills/kibi-usage/resources/workflows.md +65 -0
@@ -1,22 +1,54 @@
1
1
  ---
2
+ id: kibi-traceability
2
3
  name: kibi-traceability
3
4
  description: Maintain requirement, scenario, and test traceability through Kibi MCP tools.
5
+ version: 1.0.0
6
+ kibiCompatibility: "*"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - traceability
11
+ - agent-guidance
4
12
  ---
5
-
6
13
  ## Goal
7
14
 
8
- Validate and strengthen traceability before and after code changes.
15
+ Validate and strengthen requirement, scenario, test, behavioral-symbol, and source-file traceability before and after code changes.
16
+
17
+ ## Interface Selection
18
+
19
+ 1. If Kibi MCP tools are visible and approved, use the MCP surface as the primary authority.
20
+ 2. Otherwise, in a trusted workspace, use the canonical project-local CLI fallback through `npx --no-install kibi ...` or `bunx --no-install kibi ...`.
21
+ 3. If neither approved MCP tools nor the project-local CLI are available, or if the CLI is unavailable or too old, stop and tell the operator to enable or install Kibi.
22
+ 4. Never use a global fallback or an installing runner.
23
+
24
+ Use MCP routes for modeling, querying, checking, validation, and cleanup. Use the project-local CLI only as the fallback interface, passing JSON input through stdin. Example:
9
25
 
10
- ## MCP workflow
26
+ ```bash
27
+ echo '{"sourceFiles":["src/auth/login.ts"],"includeImpactDiagnostics":true,"includeWorkingTreeDiff":true}' | npx --no-install kibi check --input -
28
+ ```
11
29
 
12
- - Locate requirements with `kb_search` and inspect exact details with `kb_query`.
13
- - Apply updates with `kb_upsert` for requirements, scenarios, tests, or facts.
14
- - Validate constraints and consistency with `kb_check`.
30
+ ## Capability Workflow
31
+
32
+ - Locate requirements through `kb_search` or `search --input`, then inspect exact records through `kb_query` or `query --input`.
33
+ - Before meaningful edits, identify linked requirements, scenarios, tests, facts, source files, and behavioral symbols relevant to the planned change.
34
+ - After meaningful source edits, run `kb_check({sourceFiles:[...], includeImpactDiagnostics:true, includeWorkingTreeDiff:true})` or the equivalent `check --input` JSON recipe before deciding whether traceability is current.
35
+ - Apply traceability updates sequentially through `kb_upsert` or `upsert --input` for requirements, scenarios, tests, facts, behavioral symbols, and source-linked relationships.
36
+ - Validate constraints and consistency through `kb_check` or `check --input` after updates.
37
+ - Use `kb_delete` or `delete --input` only for explicit cleanup of obsolete records or relationships.
15
38
 
16
39
  ## Guidance
17
40
 
18
- - Prefer source-linked relationships so symbols and files can be traced back cleanly.
19
- - Include `kb_query` and `kb_delete` only when explicit cleanups are required.
20
- - Never directly edit `.kb/**`; all modeling and cleanup goes through MCP tools.
41
+ - Prefer source-linked relationships so requirements, scenarios, tests, symbols, and files can be traced cleanly.
42
+ - Preserve source-file traceability whenever adding or changing requirements, scenarios, tests, facts, behavioral symbols, or implementation links.
21
43
  - Preserve the canonical chain `REQ-* -> SCEN-* -> TEST-*` when adding or changing requirements.
22
44
  - Production symbols should implement requirements; test symbols should remain executable evidence for tests.
45
+ - Resolve impact at behavioral-symbol granularity when Kibi reports symbol-level diagnostics; avoid treating a whole file as impacted when the report identifies narrower linked behavior.
46
+ - Treat `symbol_semantic_review_needed` as a prompt to inspect linked requirements and tests; Kibi reports graph links but does not prove prose semantics.
47
+ - Do not read or edit files inside `.kb` directly; all modeling and cleanup goes through the selected Kibi interface.
48
+ - Keep approval boundaries intact: only use Kibi MCP tools that are visible and approved, and only use the project-local CLI fallback in a trusted workspace.
49
+
50
+ Public training trajectories:
51
+ [{"taskId":"kibi-traceability-requirement-discovery-train-1","family":"requirement-discovery","reflection":"Discover the requirement linked to the supplied source symbol. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-requirement-discovery-train-2","family":"requirement-discovery","reflection":"Discover the requirement linked to the supplied source symbol. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-symbol-impact-granularity-train-1","family":"symbol-impact-granularity","reflection":"Resolve impact at behavioral symbol granularity rather than file granularity. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-symbol-impact-granularity-train-2","family":"symbol-impact-granularity","reflection":"Resolve impact at behavioral symbol granularity rather than file granularity. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-relationship-chain-train-1","family":"relationship-chain","reflection":"Trace the requirement, scenario, and test relationship chain. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-relationship-chain-train-2","family":"relationship-chain","reflection":"Trace the requirement, scenario, and test relationship chain. This is train case 2; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-executable-coverage-train-1","family":"executable-coverage","reflection":"Establish executable test identity and behavioral coverage links. This is train case 1; use only the public Kibi MCP surface."},{"taskId":"kibi-traceability-executable-coverage-train-2","family":"executable-coverage","reflection":"Establish executable test identity and behavioral coverage links. This is train case 2; use only the public Kibi MCP surface."}]
52
+
53
+ Previous development gate:
54
+ {"mean":0,"hardPasses":0,"worstFamilyMean":0}
@@ -2,7 +2,7 @@
2
2
  id: kibi-usage
3
3
  name: Kibi Usage
4
4
  description: Guides agents to use Kibi MCP, facts, relationships, and validation correctly
5
- version: 1.0.0
5
+ version: 1.2.0
6
6
  kibiCompatibility: ">=0.11.0"
7
7
  tags:
8
8
  - kibi
@@ -14,29 +14,52 @@ resources:
14
14
  - resources/relationship-directions.md
15
15
  - resources/fact-lanes.md
16
16
  - resources/workflows.md
17
+ - resources/operation-access.md
17
18
  ---
18
-
19
19
  # Kibi Usage
20
20
 
21
- Consult this skill before any Kibi knowledge base operation, on first interaction with a Kibi-enabled repo, after detecting stale or dirty KB status, and before performing mutations.
21
+ Consult this skill before any Kibi knowledge base operation, on first interaction with a Kibi-enabled repo, after stale or dirty KB status is suspected, and before mutations.
22
+
23
+ ## Interface Selection
24
+
25
+ Use this order for every Kibi operation:
26
+
27
+ 1. If Kibi MCP tools are visible and approved in the current environment, use MCP.
28
+ 2. Otherwise, in a trusted workspace, use the project-local CLI through a non-installing runner: `npx --no-install kibi ...` or `bunx --no-install kibi ...`.
29
+ 3. If the project-local CLI is unavailable or too old for the needed route, stop and tell the operator to enable or install Kibi.
30
+ 4. Never use a global fallback or an installing runner. Never probe or install packages as a side effect of interface selection.
31
+
32
+ Use exact MCP tool names, dedicated CLI routes, input modes, effects, and Prolog requirements from `resources/operation-access.md`. Do not invent a generic operation runner. Do not read or edit files inside `.kb/` directly.
33
+
34
+ CLI JSON mode accepts MCP-shaped business input at `--input <file|->`.
35
+
36
+ ```bash
37
+ echo '{"type":"req","id":"REQ-001","properties":{"title":"Test","status":"open"}}' | npx --no-install kibi upsert --input -
38
+ ```
39
+
40
+ ```bash
41
+ echo '{"query":"authentication","limit":10}' | bunx --no-install kibi search --input -
42
+ ```
43
+
44
+ ## MCP Tool Names
22
45
 
23
- ## MCP-Only Rules
46
+ Kibi canonical MCP names include `kb_search`, `kb_query`, `kb_upsert`, `kb_check`, `kb_status`, `kb_validate_upsert`, and related `kb_*` tools. OpenCode may expose prefixed identifiers such as `kibi_kb_search`, `kibi_kb_query`, and `kibi_kb_upsert`. Use the visible Kibi MCP tool identifiers and map them back to canonical operations before reasoning about behavior.
24
47
 
25
- Interact with the knowledge base exclusively through MCP tools. Do not read or edit files inside `.kb/` directly. Do not run any `kibi` CLI commands from the agent session. The MCP surface is the only sanctioned interface for agents.
48
+ ## Discovery First
26
49
 
27
- ### Tool Name Prefixes
50
+ Always discover before you mutate. Start exploratory work with `kb_search` across metadata and markdown body text. Split broad queries into one to three focused probes and review top hits before concluding knowledge is absent.
28
51
 
29
- Kibi's canonical MCP names are `kb_search`, `kb_query`, `kb_upsert`, `kb_check`, and related `kb_*` tools. Some hosts add a server prefix when exposing tools to agents. In OpenCode, use the visible `kibi_kb_search`, `kibi_kb_query`, `kibi_kb_upsert`, and `kibi_kb_check` names when exact tool identifiers are required; they map to the same canonical MCP names.
52
+ Use `kb_query` for exact lookups by `id`, `type`, `tags`, or `sourceFile`. Use `kb_status` when branch attachment, freshness, or stale context could affect the decision. Mutate only after discovery confirms the target state.
30
53
 
31
- ## Discovery-First Workflow
54
+ ## Approval Boundaries
32
55
 
33
- Always discover before you mutate. Start with `kb_search` for exploratory discovery across metadata and markdown body text. Split broad queries into 1-3 focused probes. Review top hits for relevance before concluding the KB lacks knowledge.
56
+ Do not perform Kibi mutations unless the current task calls for knowledge-base changes or the user explicitly asks for them. Discovery and validation are acceptable when needed to understand impact, freshness, traceability, or existing requirements.
34
57
 
35
- Follow up with `kb_query` for exact lookups by `id`, `type`, `tags`, or `sourceFile`. Call `kb_status` to inspect branch attachment and freshness when stale context would affect decisions. Only after discovery and confirmation should you mutate.
58
+ Kibi guidance does not define a repository's package manager, branch names, release scripts, or publishing workflow. Follow the repository's own instructions for those concerns. Never use Kibi interface selection to install packages, change dependency manifests, or bypass sandbox and approval boundaries.
36
59
 
37
60
  ## Relationship Directions
38
61
 
39
- Relationship direction is fixed and semantic. Getting it wrong breaks traceability queries and validation.
62
+ Relationship direction is fixed and semantic. Reversed links break traceability queries and validation.
40
63
 
41
64
  | Relationship | Direction | Meaning |
42
65
  |-------------|-----------|---------|
@@ -47,23 +70,29 @@ Relationship direction is fixed and semantic. Getting it wrong breaks traceabili
47
70
  | `executable_for` | symbol -> test | Symbol is executable test code for a test entity |
48
71
  | `constrains` | req -> fact(subject) | Requirement constrains a domain fact |
49
72
  | `requires_property` | req -> fact(property_value) | Requirement requires a property value |
73
+ | `requires_predicate` | req -> fact(predicate) | Requirement requires a ground ontology predicate |
50
74
  | `supersedes` | old-req -> new-req | Old requirement is replaced by new requirement |
51
75
  | `covered_by` | symbol -> test | Production symbol has coverage evidence from a test |
52
76
 
53
- See `resources/relationship-directions.md` for detailed payload examples.
77
+ Before/after for reversed direction:
78
+
79
+ - Wrong: `relationships: [{ type: "implements", from: "REQ-001", to: "SYM-001" }]`
80
+ - Right: `relationships: [{ type: "implements", from: "SYM-001", to: "REQ-001" }]`
54
81
 
55
82
  ## Symbol-First Traceability
56
83
 
57
- Trace code through `symbol` entities, not inline legacy comments. Do not use legacy `// implements REQ-xxx` comments as the primary marker for new or modified code. If a symbol is new or its requirement ownership changes, create or update the `symbol` entity and add an `implements` relationship from the symbol to the requirement.
84
+ Preserve source-file traceability whenever creating or updating requirements, facts, scenarios, tests, or symbols. Prefer durable `sourceFile` references and symbol coordinates that point to tracked repository files. For code ownership, create or update a `symbol` entity and add an `implements` relationship from the symbol to the requirement; link symbols to tests with `covered_by` when coverage evidence is needed.
58
85
 
59
- Use comments only as a temporary backward-compatibility fallback when the symbol manifest cannot be updated in the same task. Prefer durable symbol coordinates in `documentation/symbols.yaml` and `documentation/symbol-coordinates.yaml`, then link those symbols through MCP relationships.
86
+ Do not use legacy `// implements REQ-xxx` comments as the primary marker for new or modified code. Use comments only as a temporary compatibility fallback when symbol metadata cannot be updated in the same task.
87
+
88
+ Preferred traceability model:
60
89
 
61
90
  ```yaml
62
- # Preferred traceability model
63
91
  symbol:
64
92
  id: SYM-admin-billing-policy
65
93
  title: Admin billing policy check
66
94
  status: active
95
+ sourceFile: src/admin/billing.ts
67
96
  relationships:
68
97
  - type: implements
69
98
  from: SYM-admin-billing-policy
@@ -75,17 +104,13 @@ relationships:
75
104
  Normative requirements that must participate in contradiction blocking use the strict fact lane. Create a `fact_kind: subject` fact and link it from the requirement via `constrains`. Create a `fact_kind: property_value` fact and link it via `requires_property`.
76
105
 
77
106
  ```yaml
78
- # Fact entity
79
107
  id: FACT-USER-ROLE
80
- title: User Role Assignment
81
- status: active
82
108
  fact_kind: subject
83
109
  subject_key: user.role_assignment
110
+ ```
84
111
 
85
- # Requirement entity
112
+ ```yaml
86
113
  id: REQ-019
87
- title: Users can have up to 3 roles
88
- status: open
89
114
  relationships:
90
115
  - type: constrains
91
116
  from: REQ-019
@@ -95,104 +120,110 @@ relationships:
95
120
  to: FACT-LIMIT-3
96
121
  ```
97
122
 
98
- See `resources/fact-lanes.md` for the full strict vs observation lane comparison.
123
+ Model one semantic claim per strict `property_value` fact. Reusing the same `subject_key` and `property_key` lets `domain-contradictions` compare requirements mechanically. If a new requirement intentionally changes a value, create a replacement requirement and link the old requirement to the new one with `supersedes` instead of leaving two current contradictory requirements.
124
+
125
+ Use `kb_model_requirement` for automated strict-fact modeling when available. It generates subject and property_value facts, links them with `constrains` and `requires_property`, and handles low-confidence downgrades to observation facts automatically.
126
+
127
+ Granular fact examples for coherence checks include `REQ-ROLE-SET-2` versus `REQ-ROLE-SET-3` on `user.roles.allowed_set` (`user,admin` versus `user,admin,superadmin`) and `REQ-ADMIN-CAN-MANAGE-BILLING` versus `REQ-ONLY-SUPERADMIN-MANAGES-BILLING` on `billing.manage.allowed_actor`. See `resources/fact-lanes.md`; `domain-contradictions` uses these canonical keys.
99
128
 
100
- ### Granular fact examples for coherence checks
129
+ ## Complete Logical Coverage
101
130
 
102
- Model one semantic claim per strict `property_value` fact. Reusing the same `subject_key` and `property_key` lets `domain-contradictions` compare requirements mechanically.
131
+ Readable prose is not evidence that a requirement is machine-checkable. Before treating a normative requirement as modeled, decompose its entire body into atomic normative clauses and ground every clause. One correct fact or relationship never proves that the other prose is covered.
103
132
 
104
- Incoherent role-set example: `REQ-ROLE-SET-2` says the allowed user roles are exactly `[user, admin]`, while `REQ-ROLE-SET-3` says the same property is exactly `[user, admin, superadmin]`. Both constrain `FACT-USER-ROLES` and require different values for `user.roles.allowed_set`, so they cannot both be current.
133
+ 1. Call `kb_semantic_advisor` with the complete requirement prose. When the automatic split is incomplete or a sentence contains multiple obligations, pass an explicit `clauses` array containing every atomic normative clause.
134
+ 2. Use the stable `claim_key` returned for each clause. Every ground `property_value` or `predicate` fact must preserve that key in `claim_key` and preserve the clause in `claim_text`. Use the advisor-returned inventory exactly; do not add punctuation or wording variants of an existing clause.
135
+ 3. Put the complete set of keys in the requirement's `logic_claims` manifest. Merge returned keys with existing values; never overwrite earlier claims while modeling a later clause.
136
+ 4. Ground each key through exactly one suitable logical lane: `requires_property` to one strict `property_value` fact, or `requires_predicate` to one ground `predicate` fact. A subject fact supports a strict claim but does not ground a key by itself. Observation, meta, ambiguity, and ontology-gap facts explicitly remain unresolved and do not count as logical coverage.
137
+ 5. Run `kb_check` with `logic-coverage`, `predicate-verifiability`, and `domain-contradictions`. `logic-coverage` enforces a one-claim/one-ground-fact mapping and rejects distinct claim keys that encode the same logical term; human or agent review still confirms that the atomic clauses exhaust the prose and that each ground term preserves its meaning.
138
+
139
+ Kibi emits a non-blocking logical-coverage debt diagnostic for every current requirement without a manifest, independent of title wording. The `logic-coverage` rule is enabled by default for requirements that do declare manifests, so an unfiltered final check catches missing or orphaned ground claims while legacy requirements remain explicit backfill work.
140
+
141
+ A complete `logic_claims` manifest alone is not a complete model. Semantic-advisor readiness remains partial until the payload has at least one distinct `requires_property` or `requires_predicate` grounding slot per normative claim. This count prevents one token edge from suppressing the remaining plans; only `logic-coverage` readback proves that each slot reaches the fact with the matching claim key.
142
+
143
+ Never invent, reuse across different clauses, or manually alter a claim key. Kibi derives it from `claim_text` and rejects mismatched mutation and Markdown inputs.
144
+
145
+ For a compound requirement, the manifest and linked facts form a clause-completeness contract:
105
146
 
106
147
  ```yaml
107
- subject:
108
- id: FACT-USER-ROLES
109
- fact_kind: subject
110
- subject_key: user.roles
111
-
112
- property_values:
113
- - id: FACT-USER-ROLES-ALLOWED-2
114
- fact_kind: property_value
115
- subject_key: user.roles
116
- property_key: user.roles.allowed_set
117
- operator: eq
118
- value_type: list
119
- value_json: '["user", "admin"]'
120
- - id: FACT-USER-ROLES-ALLOWED-3
121
- fact_kind: property_value
122
- subject_key: user.roles
123
- property_key: user.roles.allowed_set
124
- operator: eq
125
- value_type: list
126
- value_json: '["user", "admin", "superadmin"]'
127
-
128
- requirements:
129
- - id: REQ-ROLE-SET-2
130
- relationships:
131
- - { type: constrains, from: REQ-ROLE-SET-2, to: FACT-USER-ROLES }
132
- - { type: requires_property, from: REQ-ROLE-SET-2, to: FACT-USER-ROLES-ALLOWED-2 }
133
- - id: REQ-ROLE-SET-3
134
- relationships:
135
- - { type: constrains, from: REQ-ROLE-SET-3, to: FACT-USER-ROLES }
136
- - { type: requires_property, from: REQ-ROLE-SET-3, to: FACT-USER-ROLES-ALLOWED-3 }
148
+ requirement:
149
+ id: REQ-CHECKOUT-RETENTION
150
+ logic_claims: [CLAIM-A1B2C3D4E5F60718, CLAIM-18273645AABBCCDD]
151
+ facts:
152
+ - fact_kind: predicate
153
+ claim_key: CLAIM-A1B2C3D4E5F60718
154
+ claim_text: Checkout requires payment authorization before submission.
155
+ - fact_kind: property_value
156
+ claim_key: CLAIM-18273645AABBCCDD
157
+ claim_text: Customer data must be retained for 7 years.
137
158
  ```
138
159
 
139
- Incoherent permission example: `REQ-ADMIN-CAN-MANAGE-BILLING` says `admin` can manage billing, while `REQ-ONLY-SUPERADMIN-MANAGES-BILLING` says the only allowed actor is `superadmin`. Model both against `billing.manage.allowed_actor` with `operator: eq` so the conflict is explicit.
160
+ The example keys are illustrative; use only keys returned for the exact clause text.
161
+
162
+ ## Predicate Ontology Decision Tree
163
+
164
+ Preserve the readable requirement prose. Facts add a machine-queryable model; they do not replace prose, and stored predicate facts are data queried by Kibi's Prolog layer rather than executable Prolog supplied by the agent.
165
+
166
+ 1. Call `kb_semantic_advisor` on the complete prose, verify its atomic clause inventory, and choose one lane per clause.
167
+ 2. For each relational clause, call `kb_suggest_predicates` with that clause and the current `existingLogicClaims`. Read each candidate as a Prolog-shaped ground term `predicate_name(arg1,...,argN)`: the schema fixes the predicate name, arity, argument roles, and argument order.
168
+ 3. Accept a candidate only when its meaning and every ordered argument fit the prose. Use the returned `applyPlan`, including its exact `predicate_name`, `predicate_args`, `canonical_key`, and `polarity`; never invent a predicate name, reorder arguments, add variables, or write a raw Prolog clause.
169
+ 4. Create or confirm the requirement and `fact_kind: predicate` endpoints, preserve `claim_key` and `claim_text`, merge the returned `logicClaims` into the requirement, then link requirement -> predicate fact with `requires_predicate`. Treat the requirement's logical representation as the conjunction of every linked ground term. Encode a prohibition with `polarity: deny` on the fitting positive schema, not a made-up negative predicate. An `assert` and `deny` requirement over the same namespace, name, and ordered arguments are a blocking `domain-contradictions` conflict, so requirements must reuse the same canonical schema and argument vocabulary for equivalent domain claims.
170
+ 5. Use an existing built-in or project-local `fact_kind: predicate_schema`. Create a new schema only when the task explicitly authorizes ontology extension and supplies a stable name, arity, `argument_names`, and `argument_types`; otherwise record `fact_kind: observation` with `review:ontology-gap`.
171
+ 6. For each scalar, threshold, duration, boolean, enum-set, or cardinality clause, use `kb_model_requirement` with the current `existingLogicClaims` and the strict subject/property lane instead. For ambiguity or a lexical false positive, preserve the prose as a review observation and report the requirement as logically incomplete.
172
+ 7. Validate every payload, create endpoints first, apply `kb_upsert` calls sequentially, read back all affected IDs, and run targeted `logic-coverage`, `predicate-verifiability`, and `domain-contradictions` checks before the final unfiltered `kb_check`. Exact query output can return an array when one relationship type has multiple targets; verify every target rather than reading only one edge.
173
+
174
+ Example: “Checkout requires payment authorization before order submission” fits `dependency_rule(subject, prerequisite, dependent)`. The ground model is `dependency_rule(checkout,payment_authorization,order_submission)`, stored as:
140
175
 
141
176
  ```yaml
142
- property_values:
143
- - id: FACT-BILLING-MANAGE-ACTOR-ADMIN
144
- fact_kind: property_value
145
- subject_key: billing.manage
146
- property_key: billing.manage.allowed_actor
147
- operator: eq
148
- value_type: string
149
- value_string: admin
150
- - id: FACT-BILLING-MANAGE-ACTOR-SUPERADMIN
151
- fact_kind: property_value
152
- subject_key: billing.manage
153
- property_key: billing.manage.allowed_actor
154
- operator: eq
155
- value_type: string
156
- value_string: superadmin
177
+ fact_kind: predicate
178
+ predicate_name: dependency_rule
179
+ predicate_args: [checkout, payment_authorization, order_submission]
180
+ canonical_key: dependency_rule(checkout,payment_authorization,order_submission)
181
+ polarity: assert
182
+ claim_key: <claim key returned by kb_semantic_advisor>
183
+ claim_text: Checkout requires payment authorization before order submission.
157
184
  ```
158
185
 
159
- If a new requirement intentionally changes a value, create a replacement requirement and link the old requirement to the new one with `supersedes` instead of leaving two current contradictory requirements.
186
+ Link the requirement to that predicate fact with `requires_predicate`. Do not use `verified_by`, `requires_predicate`, or another relationship type as the `predicate_name`; graph relationships and ontology predicates are different layers.
187
+
188
+ Detailed built-in, project-local, deny, strict-scalar, ambiguous, false-positive, and ontology-gap examples are immutable reference material in `resources/fact-lanes.md` and `resources/workflows.md`.
160
189
 
161
190
  ## Fact vs Flag
162
191
 
163
- Use `flag` for runtime or config gates only. Feature flags, kill-switches, and deferred capabilities are valid `flag` entities.
192
+ Use `flag` for runtime or config gates only, such as feature flags, kill-switches, and deferred capabilities.
164
193
 
165
- Bugs, incidents, and workarounds belong in `fact` entities with `fact_kind: observation` or `meta`. These fact kinds are excluded from contradiction inference, making them appropriate for non-blocking evidence.
194
+ Bugs, incidents, and workarounds belong in `fact` entities with `fact_kind: observation` or `meta`. These fact kinds are excluded from contradiction inference, making them appropriate for non-blocking evidence. Do not create a `flag` named like a bug to track a defect.
166
195
 
167
- Anti-example: do not create a `flag` named `BUG-123` to track a defect. Create a `fact` with `fact_kind: observation` instead.
196
+ ## Create Before Link
168
197
 
169
- ## Create-Before-Link
198
+ Always confirm or create endpoint entities before linking them. Query target IDs with `kb_query` first. If an endpoint does not exist, create it with `kb_upsert` before creating the relationship. Relationships to missing entities produce dangling references that `kb_check` will flag.
170
199
 
171
- Always confirm or create endpoint entities before linking them. Query target IDs with `kb_query` first. If an endpoint does not exist, create it with `kb_upsert` before creating the relationship. Creating relationships to non-existent entities produces dangling references that `kb_check` will flag.
200
+ For `kb_upsert`, keep relationship rows anchored to the entity being upserted: each row's `from` must equal the upserted entity ID. If you need a `SYM -> REQ` link, upsert the symbol endpoint first, then link that symbol to the requirement.
172
201
 
173
- For `kb_upsert`, keep relationship rows anchored to the entity you are upserting: each row's `from` must equal the upserted entity ID. If you need a `SYM -> REQ` link, upsert the symbol endpoint first, then link that symbol to the requirement.
202
+ Keep symbol payloads minimal: include only fields needed to identify the symbol, status, and source traceability. Put extra prose, examples, or audit notes in documentation or evidence artifacts instead of custom `kb_upsert.properties`; strict `kb_upsert.properties` rejects unknown fields.
174
203
 
175
- Keep symbol payloads minimal: include only the fields needed to identify the symbol, its status, and its source traceability. Put extra prose, examples, or audit notes in docs or evidence files instead of custom `kb_upsert.properties`; strict `kb_upsert.properties` rejects unknown fields.
204
+ When a generic `Query failed` appears, do not keep retrying the same payload. First call `kb_validate_upsert`, query or create missing endpoints, reduce the payload to required fields, and retry once. If it still fails, report the blocker.
176
205
 
177
- When a generic `Query failed` appears, do not keep retrying the same payload. First call `kb_validate_upsert`, query or create the missing endpoints, reduce the payload to the minimum required fields, and retry once. If it still fails, report the blocker instead of looping.
206
+ ## Small Behavior Fix Impact Evidence
178
207
 
179
- ## Sequential Upserts
208
+ For a behavior-changing source edit, first query for an existing requirement. If no requirement exists, create one for the corrected behavior. Model strict facts from that requirement when the invariant is contradiction-sensitive.
180
209
 
181
- Never fire `kb_upsert` calls in parallel. Execute them sequentially to avoid lock contention and ensure deterministic ordering. This is especially important when creating chains of related entities.
210
+ Do not link facts directly to tests. Facts describe invariants; requirements or scenarios are verified by executable tests. Use `REQ -> TEST` with `verified_by` or `TEST -> REQ` with `validates`, then link the requirement to facts with `constrains` and `requires_property`. Link touched production symbols to requirements with `implements` and to tests with `covered_by` when coverage evidence is needed.
182
211
 
183
- ## Targeted and Final Checks
212
+ Kibi operation writes do not automatically stage markdown evidence. When a staged hook requires impact evidence, ensure tracked documentation artifacts for requirements, facts, tests, symbol metadata, or coordinate refreshes are authored and staged alongside source changes.
184
213
 
185
- Run `kb_check` with specific rules during iteration for fast feedback. For example, use `rules: ["required-fields", "no-dangling-refs"]` after small changes. Run a full `kb_check` without rule filters before declaring work complete.
214
+ ## Sequential Upserts
186
215
 
187
- ## Domain Contradictions and Evolution
216
+ Never fire `kb_upsert` calls in parallel. Execute them sequentially to avoid lock contention and ensure deterministic ordering, especially when creating chains of related entities.
188
217
 
189
- The `domain-contradictions` rule detects conflicts between strict-lane facts linked to requirements. When a contradiction is found, the supported escape hatch is `supersedes`: create a new requirement that supersedes the old one, then link the new requirement to updated facts.
218
+ ## Checks
190
219
 
191
- Use `kb_model_requirement` for automated strict-fact modeling. It generates the subject and property_value facts, links them via `constrains` and `requires_property`, and handles low-confidence downgrades to `observation` facts automatically.
220
+ Run `kb_check` with specific rules during iteration for fast feedback. For normative requirement modeling, include `rules: ["logic-coverage", "predicate-verifiability", "domain-contradictions"]`; add `required-fields` and `no-dangling-refs` after writes. Run a full `kb_check` without rule filters before declaring Kibi work complete.
221
+
222
+ The `domain-contradictions` rule detects conflicts between strict-lane facts linked to requirements. When a contradiction is found, the supported escape hatch is `supersedes`: create a new requirement that supersedes the old one, then link the new requirement to updated facts.
192
223
 
193
224
  ## Stale or Dirty KB Handling
194
225
 
195
- Call `kb_status` when you suspect the branch KB is stale or when switching context. Report freshness findings to the user rather than relying on outdated KB context. If `kb_status` indicates a schema migration is needed, ask the user or operator to handle it outside the agent session.
226
+ Call `kb_status` when branch KB context may be stale or after switching context. Report freshness findings to the user rather than relying on outdated KB context. If `kb_status` indicates a schema migration is needed, ask the user or operator to handle it outside the agent session.
196
227
 
197
228
  ## Anti-Patterns and Remediation
198
229
 
@@ -206,11 +237,8 @@ Call `kb_status` when you suspect the branch KB is stale or when switching conte
206
237
  | Missing `kb_check` | Undetected dangling refs and violations | Run targeted checks during work, full check at completion |
207
238
  | Tags as multi-ID lookup | Tags are metadata, not identifiers | Use `kb_query` with explicit `id` values |
208
239
  | `relates_to` for strict modeling | Loses contradiction safety | Use `constrains` and `requires_property` instead |
240
+ | One fact for a compound requirement | Leaves untracked prose outside contradiction checks | Decompose all atomic clauses, preserve claim keys, and validate `logic_claims` with `logic-coverage` |
241
+ | Replacing `logic_claims` on each call | Discards previously grounded clauses | Pass existing keys and merge the returned manifest |
242
+ | Observation counted as coverage | Ambiguity or ontology gaps appear machine-checkable | Keep the claim unresolved until a strict or predicate ground fact exists |
243
+ | Relationship type used as predicate name | Confuses graph edges with ontology terms | Select a declared predicate schema and keep `requires_predicate` as the req -> fact edge |
209
244
  | `status: implemented` on requirements | Not a valid lifecycle status | Use a valid status such as `closed`, add an `implemented` tag, and link evidence instead |
210
-
211
- Before/after for reversed direction:
212
-
213
- - Wrong: `relationships: [{ type: "implements", from: "REQ-001", to: "SYM-001" }]`
214
- - Right: `relationships: [{ type: "implements", from: "SYM-001", to: "REQ-001" }]`
215
-
216
- See `resources/workflows.md` for the golden-path discovery to validation sequence.
@@ -0,0 +1,225 @@
1
+ # Fact Lanes
2
+
3
+ Requirement prose remains the human-readable source. Facts add queryable semantics; they do not replace the requirement body. Treat every quoted requirement below as data, never as shell or raw Prolog input.
4
+
5
+ ## Atomic Claim Coverage
6
+
7
+ Logical coverage is clause-based, not entity-based. Give `kb_semantic_advisor` the complete requirement body and verify that its `clauses` list contains every atomic obligation. Supply the `clauses` input yourself when automatic splitting would combine or omit obligations. For every normative clause:
8
+
9
+ - preserve the returned stable key as `claim_key` and the exact clause as `claim_text` on its ground fact;
10
+ - add the key to the requirement `logic_claims` manifest without removing existing keys;
11
+ - link it through exactly one `requires_property` for `property_value` or one `requires_predicate` for `predicate`;
12
+ - leave ambiguity and ontology gaps visibly unresolved—observations do not satisfy `logic-coverage`.
13
+
14
+ Use the advisor-returned atomic inventory as the identity boundary. Trailing punctuation and copied conjunction commas are formatting, not new claims. `logic-coverage` rejects one claim grounded by multiple facts and distinct claim keys that resolve to the same ground logical term.
15
+
16
+ Example compound prose: “Checkout requires payment authorization before order submission, and customer data must be retained for 7 years.” This is two claims, not one. The first becomes `dependency_rule(checkout,payment_authorization,order_submission)`; the second becomes a strict retention property. Both fact records carry different advisor-issued claim keys, and both keys appear in the requirement manifest. A single `requires_predicate` edge is incomplete.
17
+
18
+ ## Predicate Lane (Relational Claims)
19
+
20
+ Call `kb_semantic_advisor`, then `kb_suggest_predicates`. Apply a candidate only when its schema meaning and ordered arguments fit the claim. Use the returned `applyPlan` rather than hand-writing unsupported predicate names, and link the requirement to the predicate fact with `requires_predicate`.
21
+
22
+ Treat the result as a Prolog-shaped ground term, not executable source: `predicate_name(arg1,...,argN)`. The selected `predicate_schema` fixes the name, arity, argument roles, and order. Store that model through `predicate_name`, `predicate_args`, `canonical_key`, and `polarity`; never interpolate prose into raw Prolog, introduce variables, or use a graph relationship such as `verified_by` as the predicate name.
23
+
24
+ ### Built-in predicate
25
+
26
+ Claim: “Checkout requires payment authorization before order submission.” The built-in `dependency_rule(subject, prerequisite, dependent)` schema produces:
27
+
28
+ ```yaml
29
+ id: FACT-CHECKOUT-PAYMENT-DEPENDENCY
30
+ status: active
31
+ fact_kind: predicate
32
+ predicate_name: dependency_rule
33
+ predicate_args: [checkout, payment_authorization, order_submission]
34
+ polarity: assert
35
+ canonical_key: dependency_rule(checkout,payment_authorization,order_submission)
36
+ claim_key: <advisor-issued key for this exact clause>
37
+ claim_text: Checkout requires payment authorization before order submission.
38
+ relationship: { type: requires_predicate, from: REQ-CHECKOUT-SUBMISSION, to: FACT-CHECKOUT-PAYMENT-DEPENDENCY }
39
+ ```
40
+
41
+ ### Project-local predicate
42
+
43
+ If the project has an approved `commit_action(subject, trigger, object)` predicate schema, “Editor annotation drafts autosave on navigation” may use:
44
+
45
+ ```yaml
46
+ id: FACT-EDITOR-DRAFT-AUTOSAVE
47
+ status: active
48
+ fact_kind: predicate
49
+ predicate_name: commit_action
50
+ predicate_args: [editor.annotation, navigation, draft]
51
+ polarity: assert
52
+ canonical_key: commit_action(editor.annotation,navigation,draft)
53
+ relationship: { type: requires_predicate, from: REQ-EDITOR-DRAFT-AUTOSAVE, to: FACT-EDITOR-DRAFT-AUTOSAVE }
54
+ ```
55
+
56
+ The project-local schema endpoint must exist before this fact is linked. When ontology extension is explicitly authorized, define it first with `fact_kind: predicate_schema`, `predicate_name`, `predicate_arity`, and equally sized `argument_names` and `argument_types`. Without an authorized stable signature, record `review:ontology-gap` instead of inventing a schema.
57
+
58
+ ### Deny predicate
59
+
60
+ Claim: “Suspended users must not publish articles.” When `permission_rule` fits, preserve its positive schema name and encode prohibition as polarity:
61
+
62
+ ```yaml
63
+ id: FACT-SUSPENDED-PUBLISH-DENIED
64
+ status: active
65
+ fact_kind: predicate
66
+ predicate_name: permission_rule
67
+ predicate_args: [suspended_user, publish, article]
68
+ polarity: deny
69
+ canonical_key: permission_rule(suspended_user,publish,article)
70
+ claim_key: <advisor-issued key for this exact clause>
71
+ claim_text: Suspended users must not publish articles.
72
+ relationship: { type: requires_predicate, from: REQ-SUSPENDED-PUBLISH-DENIED, to: FACT-SUSPENDED-PUBLISH-DENIED }
73
+ ```
74
+
75
+ If another current requirement links an `assert` fact with the same predicate namespace, name, and ordered arguments, `domain-contradictions` reports the pair. More complex semantic conflicts require a shared canonical schema and arguments; do not assume Kibi can prove arbitrary equivalence between differently shaped predicates.
76
+
77
+ The full logical representation of a requirement is the conjunction of all of its linked ground property and predicate terms. Conditions, exceptions, permissions, and ordering constraints remain explicit arguments of their declared schemas. Contradiction detection therefore depends on equivalent prose reusing the same predicate name, argument roles, ordered canonical values, and opposing polarity rather than inventing synonymous terms.
78
+
79
+ ### Strict scalar
80
+
81
+ Claim: “Sessions expire after at most 30 minutes.” This is a scalar limit, not a predicate. Route it through `kb_model_requirement` to a subject plus `property_value` with `operator: lte`, `value_type: int`, and `value_int: 30`, linked by `constrains` and `requires_property`.
82
+
83
+ ### Ambiguous claim
84
+
85
+ Claim: “Premium accounts get better support.” “Better” does not identify a stable relation or scalar. Keep readable prose and create a `fact_kind: observation` tagged `review:ambiguity`; request clarification before adding strict or predicate facts.
86
+
87
+ ### False-positive trap
88
+
89
+ Claim: “Suspended users must not publish articles.” A lexical match such as `publishes_event` is semantically wrong because an article is not a domain event. Reject that candidate and use the suitable permission schema if one is returned; otherwise use a review observation. Candidate rank alone is never proof of suitability.
90
+
91
+ ### Ontology gap
92
+
93
+ Claim: “Annotations remain anchored to selected text after edits.” If no returned built-in or approved project-local schema expresses anchoring preservation, do not invent one:
94
+
95
+ ```yaml
96
+ id: FACT-ONTOLOGY-GAP-ANNOTATION-ANCHOR
97
+ status: active
98
+ fact_kind: observation
99
+ tags: [review:ontology-gap]
100
+ text_ref: docs/requirements/annotation-anchor.md
101
+ ```
102
+
103
+ An ontology-gap observation records review work; it does not make the requirement machine-checkable.
104
+
105
+ ## Strict Lane (Contradiction-Safe)
106
+
107
+ ### fact_kind: subject
108
+ ```yaml
109
+ id: FACT-USER-ROLE
110
+ title: User Role Assignment
111
+ status: active
112
+ fact_kind: subject
113
+ subject_key: user.role_assignment
114
+ ```
115
+
116
+ ### fact_kind: property_value
117
+ ```yaml
118
+ id: FACT-LIMIT-3
119
+ title: Maximum of Three Roles
120
+ status: active
121
+ fact_kind: property_value
122
+ subject_key: user.role_assignment
123
+ property_key: max_roles
124
+ operator: lte
125
+ value_type: int
126
+ value_int: 3
127
+ ```
128
+
129
+ ## Granular Facts for Coherence Checks
130
+
131
+ Granular strict facts work best when each `property_value` represents one semantic claim about one `subject_key` and one `property_key`. This lets `domain-contradictions` compare current requirements that constrain the same subject and require incompatible values.
132
+
133
+ ### Role set conflict
134
+
135
+ `REQ-ROLE-SET-2` and `REQ-ROLE-SET-3` are incoherent if both are current: they each define the exact allowed role set, but one allows two roles and the other allows three. Encode compact set values as canonical strings because the strict property schema supports string, int, number, and bool values.
136
+
137
+ ```yaml
138
+ subject:
139
+ id: FACT-USER-ROLES
140
+ title: User roles
141
+ status: active
142
+ fact_kind: subject
143
+ subject_key: user.roles
144
+
145
+ property_values:
146
+ - id: FACT-USER-ROLES-ALLOWED-2
147
+ title: User and admin roles only
148
+ status: active
149
+ fact_kind: property_value
150
+ subject_key: user.roles
151
+ property_key: user.roles.allowed_set
152
+ operator: eq
153
+ value_type: string
154
+ value_string: user,admin
155
+ - id: FACT-USER-ROLES-ALLOWED-3
156
+ title: User, admin, and superadmin roles
157
+ status: active
158
+ fact_kind: property_value
159
+ subject_key: user.roles
160
+ property_key: user.roles.allowed_set
161
+ operator: eq
162
+ value_type: string
163
+ value_string: user,admin,superadmin
164
+
165
+ relationships:
166
+ - { type: constrains, from: REQ-ROLE-SET-2, to: FACT-USER-ROLES }
167
+ - { type: requires_property, from: REQ-ROLE-SET-2, to: FACT-USER-ROLES-ALLOWED-2 }
168
+ - { type: constrains, from: REQ-ROLE-SET-3, to: FACT-USER-ROLES }
169
+ - { type: requires_property, from: REQ-ROLE-SET-3, to: FACT-USER-ROLES-ALLOWED-3 }
170
+ ```
171
+
172
+ ### Permission actor conflict
173
+
174
+ `REQ-ADMIN-CAN-MANAGE-BILLING` and `REQ-ONLY-SUPERADMIN-MANAGES-BILLING` conflict when both define the exact allowed actor for the same permission.
175
+
176
+ ```yaml
177
+ subject:
178
+ id: FACT-BILLING-MANAGE
179
+ title: Billing management permission
180
+ status: active
181
+ fact_kind: subject
182
+ subject_key: billing.manage
183
+
184
+ property_values:
185
+ - id: FACT-BILLING-MANAGE-ACTOR-ADMIN
186
+ title: Admin can manage billing
187
+ status: active
188
+ fact_kind: property_value
189
+ subject_key: billing.manage
190
+ property_key: billing.manage.allowed_actor
191
+ operator: eq
192
+ value_type: string
193
+ value_string: admin
194
+ - id: FACT-BILLING-MANAGE-ACTOR-SUPERADMIN
195
+ title: Only superadmin can manage billing
196
+ status: active
197
+ fact_kind: property_value
198
+ subject_key: billing.manage
199
+ property_key: billing.manage.allowed_actor
200
+ operator: eq
201
+ value_type: string
202
+ value_string: superadmin
203
+ ```
204
+
205
+ When a contradiction is intentional evolution rather than a real conflict, link the replaced requirement to the replacement requirement with `supersedes`.
206
+
207
+ ## Context Lane (Non-Blocking)
208
+
209
+ ### fact_kind: observation
210
+ For bug records, incident notes, and observed behavior.
211
+ ```yaml
212
+ id: FACT-BUG-123
213
+ title: Login fails on Safari 17
214
+ status: active
215
+ fact_kind: observation
216
+ ```
217
+
218
+ ### fact_kind: meta
219
+ For governance notes, process commentary, and workaround documentation.
220
+ ```yaml
221
+ id: FACT-WORKAROUND-456
222
+ title: Temporary cache bypass for v2 migration
223
+ status: active
224
+ fact_kind: meta
225
+ ```