kibi-cursor 0.3.1 → 0.5.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 (53) hide show
  1. package/.cursor-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +92 -0
  3. package/README.md +21 -4
  4. package/agent-plugin/mcp.json +10 -0
  5. package/agent-plugin/plugin.json +11 -0
  6. package/agent-plugin/skills/init-kibi/SKILL.md +62 -0
  7. package/agent-plugin/skills/kibi-freshness/SKILL.md +44 -0
  8. package/agent-plugin/skills/kibi-traceability/SKILL.md +54 -0
  9. package/agent-plugin/skills/kibi-usage/SKILL.md +270 -0
  10. package/agent-plugin/skills/kibi-usage/resources/fact-lanes.md +235 -0
  11. package/agent-plugin/skills/kibi-usage/resources/logic-ir.md +43 -0
  12. package/agent-plugin/skills/kibi-usage/resources/operation-access.md +44 -0
  13. package/agent-plugin/skills/kibi-usage/resources/relationship-directions.md +119 -0
  14. package/agent-plugin/skills/kibi-usage/resources/ui-requirements.md +96 -0
  15. package/agent-plugin/skills/kibi-usage/resources/workflows.md +80 -0
  16. package/dist/.cursor-plugin/plugin.json +1 -1
  17. package/dist/guidance.d.ts +10 -2
  18. package/dist/guidance.js +26 -17
  19. package/dist/hook-runner.d.ts +1 -0
  20. package/dist/hook-runner.js +34 -7
  21. package/dist/hook-state-storage.d.ts +11 -0
  22. package/dist/hook-state-storage.js +187 -0
  23. package/dist/hook-state.d.ts +3 -4
  24. package/dist/hook-state.js +6 -206
  25. package/dist/kb-mcp-tools.d.ts +3 -0
  26. package/dist/kb-mcp-tools.js +6 -0
  27. package/dist/messages.d.ts +4 -2
  28. package/dist/messages.js +14 -2
  29. package/dist/rules/kibi-workflow.mdc +3 -3
  30. package/dist/skills/.canon-hash.json +12 -0
  31. package/dist/skills/init-kibi/SKILL.md +50 -11
  32. package/dist/skills/kibi-freshness/SKILL.md +32 -10
  33. package/dist/skills/kibi-traceability/SKILL.md +41 -11
  34. package/dist/skills/kibi-usage/SKILL.md +149 -97
  35. package/dist/skills/kibi-usage/resources/fact-lanes.md +235 -0
  36. package/dist/skills/kibi-usage/resources/logic-ir.md +43 -0
  37. package/dist/skills/kibi-usage/resources/operation-access.md +44 -0
  38. package/dist/skills/kibi-usage/resources/relationship-directions.md +119 -0
  39. package/dist/skills/kibi-usage/resources/ui-requirements.md +96 -0
  40. package/dist/skills/kibi-usage/resources/workflows.md +80 -0
  41. package/package.json +3 -2
  42. package/rules/kibi-workflow.mdc +3 -3
  43. package/skills/.canon-hash.json +12 -0
  44. package/skills/init-kibi/SKILL.md +50 -11
  45. package/skills/kibi-freshness/SKILL.md +32 -10
  46. package/skills/kibi-traceability/SKILL.md +41 -11
  47. package/skills/kibi-usage/SKILL.md +149 -97
  48. package/skills/kibi-usage/resources/fact-lanes.md +235 -0
  49. package/skills/kibi-usage/resources/logic-ir.md +43 -0
  50. package/skills/kibi-usage/resources/operation-access.md +44 -0
  51. package/skills/kibi-usage/resources/relationship-directions.md +119 -0
  52. package/skills/kibi-usage/resources/ui-requirements.md +96 -0
  53. package/skills/kibi-usage/resources/workflows.md +80 -0
@@ -1,22 +1,44 @@
1
1
  ---
2
+ id: kibi-freshness
2
3
  name: kibi-freshness
3
4
  description: Check branch freshness and source linkage quality before decisions or risky writes.
5
+ version: 1.0.0
6
+ kibiCompatibility: "*"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - freshness
11
+ - agent-guidance
4
12
  ---
5
-
6
13
  ## Goal
7
14
 
8
- Help agents decide whether KB context is current enough to support safe changes.
15
+ Help agents decide whether Kibi knowledge is current enough to support safe changes while preserving source-file traceability and approved interface boundaries.
16
+
17
+ ## Interface Selection
18
+
19
+ 1. If Kibi MCP tools are visible and approved for the workspace, use the MCP surface only.
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 the project-local 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 `kibi-usage/resources/operation-access.md` for exact dedicated routes. A project-local CLI freshness check is executable as:
25
+
26
+ ```bash
27
+ echo '{}' | npx --no-install kibi status --input -
28
+ ```
9
29
 
10
- ## MCP workflow
30
+ ## Capability Workflow
11
31
 
12
- - Use `kb_status` first to confirm branch attachment and freshness state.
13
- - Use `kb_query` with `sourceFile`/text refs for source-linked discovery.
14
- - Re-run `kb_search` after sync gaps are detected.
15
- - If knowledge must change, update it with `kb_upsert` or `kb_delete` and finish with `kb_check`.
32
+ - Use `kb_status`, or `status --input`, first to confirm branch attachment, freshness state, dirty-worktree evidence, and whether the knowledge snapshot is safe to rely on.
33
+ - Use `kb_query`, or `query --input`, with `sourceFile` and text references for source-linked discovery.
34
+ - Re-run `kb_search`, or `search --input`, after sync gaps or stale context are detected.
35
+ - If knowledge must change, use the selected interface's `kb_upsert`/`upsert` or `kb_delete`/`delete` operation sequentially, then finish with `kb_check`/`check`.
16
36
 
17
37
  ## Guidance
18
38
 
39
+ - Prefer the public Kibi MCP surface whenever it is available and approved.
19
40
  - Never proceed with broad changes when freshness is stale and unresolved.
20
- - If entities look stale, prefer refreshing context via MCP flows and then re-query.
21
- - Avoid direct `.kb` editing; use `kb_status` and other MCP checks instead.
22
- - Completion must state one freshness outcome: KB updated, no KB impact with rationale, or deferred/failed.
41
+ - If entities look stale, refresh context through an approved Kibi capability and then re-query.
42
+ - Preserve source-file traceability by carrying `sourceFile`, text references, and validation evidence through discovery, mutation, and completion.
43
+ - Do not read or edit files inside `.kb` directly; use the selected Kibi interface instead.
44
+ - Completion must state one freshness outcome: KB updated, no KB impact with rationale, or deferred/failed.
@@ -1,24 +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
- - After meaningful source edits, run `kb_check({sourceFiles:[...], includeImpactDiagnostics:true, includeWorkingTreeDiff:true})` before deciding whether traceability is current.
14
- - Apply updates with `kb_upsert` for requirements, scenarios, tests, or facts.
15
- - 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.
16
38
 
17
39
  ## Guidance
18
40
 
19
- - Prefer source-linked relationships so symbols and files can be traced back cleanly.
20
- - Treat `symbol_semantic_review_needed` as a prompt to inspect linked requirements/tests; Kibi reports graph links but does not prove prose semantics.
21
- - Include `kb_query` and `kb_delete` only when explicit cleanups are required.
22
- - 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.
23
43
  - Preserve the canonical chain `REQ-* -> SCEN-* -> TEST-*` when adding or changing requirements.
24
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.3.0
6
6
  kibiCompatibility: ">=0.11.0"
7
7
  tags:
8
8
  - kibi
@@ -14,29 +14,54 @@ resources:
14
14
  - resources/relationship-directions.md
15
15
  - resources/fact-lanes.md
16
16
  - resources/workflows.md
17
+ - resources/operation-access.md
18
+ - resources/ui-requirements.md
19
+ - resources/logic-ir.md
17
20
  ---
18
-
19
21
  # Kibi Usage
20
22
 
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.
23
+ 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.
24
+
25
+ ## Interface Selection
26
+
27
+ Kibi exposes two peer surfaces over the same 18 operations: visible MCP tools and the trusted project-local CLI. Both accept the same business input and effects (see `resources/operation-access.md`). Choose by what is visible and approved in the current environment — MCP and the CLI are equal choices, not a preference order:
28
+
29
+ 1. If Kibi MCP tools are visible and approved in the current environment, use MCP.
30
+ 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 ...`. The CLI is a peer interface, not a fallback.
31
+ 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.
32
+ 4. Never use a global fallback or an installing runner. Never probe or install packages as a side effect of interface selection.
22
33
 
23
- ## MCP-Only Rules
34
+ 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.
24
35
 
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.
36
+ CLI JSON mode accepts MCP-shaped business input at `--input <file|->`.
26
37
 
27
- ### Tool Name Prefixes
38
+ ```bash
39
+ echo '{"type":"req","id":"REQ-001","properties":{"title":"Test","status":"open"}}' | npx --no-install kibi upsert --input -
40
+ ```
41
+
42
+ ```bash
43
+ echo '{"query":"authentication","limit":10}' | bunx --no-install kibi search --input -
44
+ ```
28
45
 
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.
46
+ ## MCP Tool Names
30
47
 
31
- ## Discovery-First Workflow
48
+ 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.
32
49
 
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.
50
+ ## Discovery First
34
51
 
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.
52
+ 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.
53
+
54
+ 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.
55
+
56
+ ## Approval Boundaries
57
+
58
+ 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.
59
+
60
+ 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
61
 
37
62
  ## Relationship Directions
38
63
 
39
- Relationship direction is fixed and semantic. Getting it wrong breaks traceability queries and validation.
64
+ Relationship direction is fixed and semantic. Reversed links break traceability queries and validation.
40
65
 
41
66
  | Relationship | Direction | Meaning |
42
67
  |-------------|-----------|---------|
@@ -47,45 +72,55 @@ Relationship direction is fixed and semantic. Getting it wrong breaks traceabili
47
72
  | `executable_for` | symbol -> test | Symbol is executable test code for a test entity |
48
73
  | `constrains` | req -> fact(subject) | Requirement constrains a domain fact |
49
74
  | `requires_property` | req -> fact(property_value) | Requirement requires a property value |
75
+ | `requires_predicate` | req -> fact(predicate) | Requirement requires a ground ontology predicate |
50
76
  | `supersedes` | old-req -> new-req | Old requirement is replaced by new requirement |
51
77
  | `covered_by` | symbol -> test | Production symbol has coverage evidence from a test |
52
78
 
53
- See `resources/relationship-directions.md` for detailed payload examples.
79
+ Before/after for reversed direction:
80
+
81
+ - Wrong: `relationships: [{ type: "implements", from: "REQ-001", to: "SYM-001" }]`
82
+ - Right: `relationships: [{ type: "implements", from: "SYM-001", to: "REQ-001" }]`
54
83
 
55
84
  ## Symbol-First Traceability
56
85
 
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.
86
+ 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
87
 
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.
88
+ 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.
89
+
90
+ Preferred traceability model:
60
91
 
61
92
  ```yaml
62
- # Preferred traceability model
63
93
  symbol:
64
94
  id: SYM-admin-billing-policy
65
95
  title: Admin billing policy check
66
96
  status: active
97
+ sourceFile: src/admin/billing.ts
67
98
  relationships:
68
99
  - type: implements
69
100
  from: SYM-admin-billing-policy
70
101
  to: REQ-ADMIN-BILLING-POLICY
71
102
  ```
72
103
 
104
+ ## Typed Logic IR Lane
105
+
106
+ Readable prose is retained for people, while every assertive proposition is inventoried and either grounded in a strict fact, a predicate fact, or a safe typed rule. Use the required extraction pass followed by an adversarial coverage audit; do not let a high-confidence single suggestion stand in for the rest of a compound requirement. Load `resources/logic-ir.md` for the IR grammar, proposition ledger, safety boundary, and proof semantics.
107
+
108
+ Use `kb_semantic_advisor` with up to three typed `interpretations` for ambiguous clauses. Kibi canonicalizes alternatives and keeps materially different meanings unresolved. Create `fact_kind: rule_schema` and `fact_kind: rule` endpoints from `kb_model_requirement`'s validated plan, then link `req -> rule` with `requires_rule`. Run `rule-safety`, `rule-verifiability`, `semantic-completeness`, `logic-coverage`, and `domain-contradictions`; unresolved, incomplete, or timed-out reasoning is not evidence of consistency.
109
+
110
+ The portable skill body must carry the core contract even when its detailed resources are unavailable: `kb_semantic_advisor` returns a `propositions[]` ledger and `semantic_inventory`; submit typed `interpretations` when wording has more than one plausible logical reading; validate modeled conditions through `kibi.logic.v1`; and preserve unresolved propositions as explicit gaps. Do not read or edit files inside `.kb` directly.
111
+
73
112
  ## Strict Fact Lane
74
113
 
75
114
  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
115
 
77
116
  ```yaml
78
- # Fact entity
79
117
  id: FACT-USER-ROLE
80
- title: User Role Assignment
81
- status: active
82
118
  fact_kind: subject
83
119
  subject_key: user.role_assignment
120
+ ```
84
121
 
85
- # Requirement entity
122
+ ```yaml
86
123
  id: REQ-019
87
- title: Users can have up to 3 roles
88
- status: open
89
124
  relationships:
90
125
  - type: constrains
91
126
  from: REQ-019
@@ -95,106 +130,126 @@ relationships:
95
130
  to: FACT-LIMIT-3
96
131
  ```
97
132
 
98
- See `resources/fact-lanes.md` for the full strict vs observation lane comparison.
133
+ 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.
134
+
135
+ 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.
136
+
137
+ 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.
138
+
139
+ ## UI / Visual Requirement Modeling
140
+
141
+ Optional, per-project lane for recording what the screen should look like so UI edits cannot silently drift from the spec. Non-UI projects skip it; no check rule requires it.
99
142
 
100
- ### Granular fact examples for coherence checks
143
+ Use three layers: a prose `req` as the searchable anchor, strict `property_value` facts for checkable positions/alignment/order (linked `constrains` / `requires_property`, so incompatible values on the same subject/property are rejected on write unless `supersedes`), and relational predicates linked with `requires_predicate` (built-in `visual_layout_rule(subject, relation, target)` for "X must remain visually aligned with Y"). Model UI components as `symbol` entities with `sourceFile` and `symbol_role: behavioral`, linked `implements` to the requirement, so component edits surface the visual spec in impact diagnostics. Full payloads and workflow: `resources/ui-requirements.md`.
101
144
 
102
- Model one semantic claim per strict `property_value` fact. Reusing the same `subject_key` and `property_key` lets `domain-contradictions` compare requirements mechanically.
145
+ ## Complete Logical Coverage
103
146
 
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.
147
+ 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.
148
+
149
+ 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.
150
+ 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.
151
+ 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.
152
+ 4. Ground each key through exactly one suitable logical lane: `requires_property` to one strict `property_value` fact, `requires_predicate` to one ground `predicate` fact, or `requires_rule` to one safe `rule` 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.
153
+ 5. Run `kb_check` with `logic-coverage`, `rule-safety`, `rule-verifiability`, `semantic-completeness`, `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.
154
+
155
+ 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.
156
+
157
+ 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`, `requires_predicate`, or `requires_rule` grounding slot per assertive 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.
158
+
159
+ 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.
160
+
161
+ For a compound requirement, the manifest and linked facts form a clause-completeness contract:
105
162
 
106
163
  ```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 }
164
+ requirement:
165
+ id: REQ-CHECKOUT-RETENTION
166
+ logic_claims: [CLAIM-A1B2C3D4E5F60718, CLAIM-18273645AABBCCDD]
167
+ facts:
168
+ - fact_kind: predicate
169
+ claim_key: CLAIM-A1B2C3D4E5F60718
170
+ claim_text: Checkout requires payment authorization before submission.
171
+ - fact_kind: property_value
172
+ claim_key: CLAIM-18273645AABBCCDD
173
+ claim_text: Customer data must be retained for 7 years.
137
174
  ```
138
175
 
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.
176
+ The example keys are illustrative; use only keys returned for the exact clause text.
177
+
178
+ ## Predicate Ontology Decision Tree
179
+
180
+ 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.
181
+
182
+ 1. Call `kb_semantic_advisor` on the complete prose, verify its atomic clause inventory, and choose one lane per clause.
183
+ 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.
184
+ 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.
185
+ 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.
186
+ 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`.
187
+ 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, apply its returned `relates_to` review anchor when present, and report the requirement as logically incomplete. Use `review:ambiguity` for unresolved scope or interpretation and `review:keyword-false-positive` when a vocabulary match is not a domain assertion.
188
+ 7. Validate every payload, create endpoints first, apply `kb_upsert` calls sequentially, read back all affected IDs, and run targeted `rule-safety`, `rule-verifiability`, `semantic-completeness`, `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.
189
+
190
+ ### Schema-aware proposition boundary
191
+
192
+ A declared project-local predicate schema can encode one complete relation whose ordered arguments name several facets of the same claim. Do not split those arguments into separate propositions, invent one predicate per noun, or pass an explicit `clauses` array merely to enumerate the schema arguments. First ask `kb_semantic_advisor` about the complete sentence; add clauses only for independently asserted propositions that are not represented by the selected relation. For a schema-backed relation, preserve the one claim key for the complete relation, create the supporting `predicate_schema` with its minimal declared signature (supporting schemas do not carry `claim_key` or `logic_claims`), call `kb_suggest_predicates` on the complete claim, and apply its exact plan to create one ground predicate fact with the ordered schema arguments and that claim key. If `kb_model_requirement` returns an apply plan, execute that plan sequentially; do not fall back to observation facts when an explicitly declared schema fits. If a schema write is rejected, use `kb_validate_upsert` to reduce it to the supported signature, then retry once before considering an ontology gap.
193
+
194
+ ### Hard lane gates for unresolved prose and supplied schemas
195
+
196
+ The advisor's proposition `status` is a safety gate, not a confidence hint. A `nonlogical` proposition (including `subjective`, rationale, example, heading, or commentary) never receives a `logic_claims` entry and never goes through `kb_suggest_predicates` or `kb_model_requirement`; preserve the complete prose as one `fact_kind: observation` only when an auditable record is useful. Do not manufacture atomic clauses from a subjective sentence merely because it contains `when`, a domain noun, or the word `predicate`. An `ambiguous` proposition remains an ambiguity observation until the operator supplies a typed interpretation. An `ontology_gap` remains unresolved unless an approved schema or validated IR is actually available.
197
+
198
+ When authorized task input contains `projectLocalSchemas`, those declarations are the schema authority even if the first advisor or predicate lookup calls them an ontology gap. Do not treat an empty candidate list as final: create the minimal declared `predicate_schema` endpoint first, then call `kb_suggest_predicates` again on the one complete claim (with the current `existingLogicClaims`) and apply the resulting ground predicate plan. Preserve the single claim key for that relation; do not add keys for schema arguments. If the lookup still cannot return a plan after the declared schema exists, validate the exact schema-backed predicate payload once and report the remaining blocker rather than inventing a different predicate. For prohibition cues (`must not`, `never`, `cannot`, `forbidden`), use the positive schema with `polarity: deny`; never silently change it to `assert` or encode the negation in a new predicate name.
199
+
200
+ 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
201
 
141
202
  ```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
203
+ fact_kind: predicate
204
+ predicate_name: dependency_rule
205
+ predicate_args: [checkout, payment_authorization, order_submission]
206
+ canonical_key: dependency_rule(checkout,payment_authorization,order_submission)
207
+ polarity: assert
208
+ claim_key: <claim key returned by kb_semantic_advisor>
209
+ claim_text: Checkout requires payment authorization before order submission.
157
210
  ```
158
211
 
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.
212
+ 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.
213
+
214
+ 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
215
 
161
216
  ## Fact vs Flag
162
217
 
163
- Use `flag` for runtime or config gates only. Feature flags, kill-switches, and deferred capabilities are valid `flag` entities.
218
+ Use `flag` for runtime or config gates only, such as feature flags, kill-switches, and deferred capabilities.
164
219
 
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.
220
+ 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
221
 
167
- Anti-example: do not create a `flag` named `BUG-123` to track a defect. Create a `fact` with `fact_kind: observation` instead.
222
+ ## Create Before Link
168
223
 
169
- ## Create-Before-Link
224
+ 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
225
 
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.
226
+ 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
227
 
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.
228
+ 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
229
 
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.
230
+ 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
231
 
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.
232
+ ## Small Behavior Fix Impact Evidence
178
233
 
179
- ## Sequential Upserts
234
+ 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
235
 
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.
236
+ 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
237
 
183
- ## Targeted and Final Checks
238
+ 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
239
 
185
- Run `kb_check` with specific rules during iteration for fast feedback. For example, use `rules: ["required-fields", "no-dangling-refs"]` after small changes. Supplying `rules` preserves that scoped validation and skips the full-KB advisory scan. Run a full `kb_check` without rule filters before declaring work complete so `qualityDiagnostics[]` includes the full-KB audit-quality review.
240
+ ## Sequential Upserts
186
241
 
187
- For meaningful source edits, run impact diagnostics while the edit context is fresh: `kb_check({sourceFiles:["src/changed-file.ts"], includeImpactDiagnostics:true, includeWorkingTreeDiff:true})`. Review `symbol_granularity_violation` as a hard ownership-shape problem and `symbol_semantic_review_needed` as an advisory prompt to inspect whether linked requirements, scenarios, and tests still match the changed behavior or UI copy.
242
+ 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
243
 
189
- ## Domain Contradictions and Evolution
244
+ ## Checks
190
245
 
191
- 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.
246
+ Run `kb_check` with specific rules during iteration for fast feedback. For normative requirement modeling, include `rules: ["rule-safety", "rule-verifiability", "semantic-completeness", "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.
192
247
 
193
- 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.
248
+ 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.
194
249
 
195
250
  ## Stale or Dirty KB Handling
196
251
 
197
- 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.
252
+ 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.
198
253
 
199
254
  ## Anti-Patterns and Remediation
200
255
 
@@ -205,14 +260,11 @@ Call `kb_status` when you suspect the branch KB is stale or when switching conte
205
260
  | Bug-as-flag | `flag` misused for defect tracking | Use `fact` with `fact_kind: observation` or `meta` |
206
261
  | Parallel upserts | Lock contention and nondeterminism | Execute `kb_upsert` calls sequentially |
207
262
  | Embedded scenarios in reqs | Violates canonical traceability chain | Create separate `req`, `scen`, and `test` entities |
208
- | Missing `kb_check` | Undetected dangling refs, violations, and full-KB quality diagnostics | Run targeted checks during work, full unfiltered check at completion |
263
+ | Missing `kb_check` | Undetected dangling refs and violations | Run targeted checks during work, full check at completion |
209
264
  | Tags as multi-ID lookup | Tags are metadata, not identifiers | Use `kb_query` with explicit `id` values |
210
265
  | `relates_to` for strict modeling | Loses contradiction safety | Use `constrains` and `requires_property` instead |
266
+ | 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` |
267
+ | Replacing `logic_claims` on each call | Discards previously grounded clauses | Pass existing keys and merge the returned manifest |
268
+ | Observation counted as coverage | Ambiguity or ontology gaps appear machine-checkable | Keep the claim unresolved until a strict or predicate ground fact exists |
269
+ | 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 |
211
270
  | `status: implemented` on requirements | Not a valid lifecycle status | Use a valid status such as `closed`, add an `implemented` tag, and link evidence instead |
212
-
213
- Before/after for reversed direction:
214
-
215
- - Wrong: `relationships: [{ type: "implements", from: "REQ-001", to: "SYM-001" }]`
216
- - Right: `relationships: [{ type: "implements", from: "SYM-001", to: "REQ-001" }]`
217
-
218
- See `resources/workflows.md` for the golden-path discovery to validation sequence.