kibi-runtime 1.0.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 (44) hide show
  1. package/dist/engine-daemon.js +2402 -0
  2. package/dist/engine.d.ts +65 -0
  3. package/dist/engine.js +1 -0
  4. package/dist/index.d.ts +49 -0
  5. package/dist/index.js +279965 -0
  6. package/dist/skill-operations.d.ts +69 -0
  7. package/dist/skill-operations.js +105 -0
  8. package/dist/skill-system/errors.d.ts +18 -0
  9. package/dist/skill-system/errors.js +36 -0
  10. package/dist/skill-system/loader.d.ts +8 -0
  11. package/dist/skill-system/loader.js +81 -0
  12. package/dist/skill-system/paths.d.ts +5 -0
  13. package/dist/skill-system/paths.js +25 -0
  14. package/dist/skill-system/types.d.ts +14 -0
  15. package/dist/skill-system/types.js +1 -0
  16. package/dist/skill-system/validation.d.ts +9 -0
  17. package/dist/skill-system/validation.js +119 -0
  18. package/dist/skills/kibi-bootstrap/SKILL.md +58 -0
  19. package/dist/skills/kibi-bootstrap/resources/bootstrap.md +11 -0
  20. package/dist/skills/kibi-bootstrap/resources/branch-lifecycle.md +7 -0
  21. package/dist/skills/kibi-bootstrap/resources/operation-access.md +5 -0
  22. package/dist/skills/kibi-bootstrap/resources/source-authoring.md +8 -0
  23. package/dist/skills/kibi-freshness/SKILL.md +74 -0
  24. package/dist/skills/kibi-freshness/resources/branch-lifecycle.md +7 -0
  25. package/dist/skills/kibi-freshness/resources/operation-access.md +6 -0
  26. package/dist/skills/kibi-freshness/resources/source-authoring.md +7 -0
  27. package/dist/skills/kibi-traceability/SKILL.md +60 -0
  28. package/dist/skills/kibi-traceability/resources/branch-lifecycle.md +7 -0
  29. package/dist/skills/kibi-traceability/resources/operation-access.md +5 -0
  30. package/dist/skills/kibi-traceability/resources/source-authoring.md +6 -0
  31. package/dist/skills/kibi-traceability/resources/traceability.md +8 -0
  32. package/dist/skills/kibi-usage/SKILL.md +152 -0
  33. package/dist/skills/kibi-usage/resources/branch-lifecycle.md +31 -0
  34. package/dist/skills/kibi-usage/resources/fact-lanes.md +235 -0
  35. package/dist/skills/kibi-usage/resources/kb-improvement.md +38 -0
  36. package/dist/skills/kibi-usage/resources/logic-ir.md +43 -0
  37. package/dist/skills/kibi-usage/resources/operation-access.md +42 -0
  38. package/dist/skills/kibi-usage/resources/relationship-directions.md +119 -0
  39. package/dist/skills/kibi-usage/resources/source-authoring.md +31 -0
  40. package/dist/skills/kibi-usage/resources/ui-requirements.md +96 -0
  41. package/dist/skills/kibi-usage/resources/workflows.md +150 -0
  42. package/dist/skills.d.ts +3 -0
  43. package/dist/skills.js +2 -0
  44. package/package.json +37 -0
@@ -0,0 +1,74 @@
1
+ ---
2
+ id: kibi-freshness
3
+ name: kibi-freshness
4
+ description: Check exact Git attachment, branch migration/quarantine, compiled-store freshness, source linkage, and repair state before decisions or writes.
5
+ version: 2.0.0
6
+ kibiCompatibility: ">=1.0.0"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - freshness
11
+ - agent-guidance
12
+ resources:
13
+ - resources/branch-lifecycle.md
14
+ - resources/source-authoring.md
15
+ - resources/operation-access.md
16
+ ---
17
+ ## Goal
18
+
19
+ Help agents decide whether Kibi knowledge is current enough to support safe changes while preserving source-file traceability and approved interface boundaries.
20
+
21
+ ## Interface Selection
22
+
23
+ 1. Use whichever approved peer is visible: MCP or the trusted project-local CLI.
24
+ 2. They have the same operation semantics and machine envelope; neither is preferred.
25
+ 3. If neither surface is available, stop and tell the operator which capability must be enabled.
26
+ 4. Never install packages, choose a package manager, or use a global fallback as part of freshness inspection.
27
+
28
+ Use `kibi-usage/resources/operation-access.md` for exact dedicated routes. A project-local CLI freshness check is executable as:
29
+
30
+ ```bash
31
+ echo '{}' | npx --no-install kibi status --input -
32
+ ```
33
+
34
+ ## Capability Workflow
35
+
36
+ - 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.
37
+ - Treat `branchAttachment.gitBranch`, `branchAttachment.kbBranch`, and
38
+ `branchAttachment.storePath` as exact identities. Hashed stores require a
39
+ matching `branch.json`; a `legacy_compat` attachment is read-only until an
40
+ explicit old/new migration is approved.
41
+ - Inspect bounded `staleReasons` (indexed source missing/newer or documentation
42
+ source newer) and `verificationSnapshotChanges`. Kibi deliberately reports
43
+ editor/config paths such as editor dot-directories; do not silently ignore them.
44
+ - Use `kb_query`, or `query --input`, with `sourceFile` and text references for source-linked discovery.
45
+ - Re-run `kb_search`, or `search --input`, after sync gaps or stale context are detected.
46
+ - If knowledge must change, use the selected interface's `kb_upsert`/`upsert` or `kb_delete`/`delete` operation sequentially, then finish with `kb_check`/`check`.
47
+ - If status returns `migrationPlan.version: kibi.migration-plan.v2`, inspect its
48
+ hash, scope, dependencies, and safety classes. Apply only ready automatic
49
+ actions with explicit hash/action approval through `kb_apply_plan` or
50
+ `kibi migrate --apply-safe`; escalate operator actions and never infer a
51
+ migration from prose suggestions.
52
+ - Parse the outer `kibiProtocol`/`resultVersion` envelope. If a mutation returns
53
+ `committed_with_repairs`, follow required typed `nextActions`; never retry the
54
+ original operation.
55
+
56
+ ## Guidance
57
+
58
+ - Treat MCP and the trusted project-local CLI as equal peer surfaces.
59
+ - Report task outcome separately from KB, verification, proof, and limitation
60
+ state. A maintenance task can be complete with stale KB state or unresolved
61
+ proof only when its scoped objective is complete and the status is named
62
+ accurately; never call the KB clean/fresh in that case.
63
+ - A legacy attachment blocks mutation, and a dirty verification snapshot blocks
64
+ evidence-dependent closeout. Name the exact paths/symbol IDs and whether the
65
+ result is fixed, accepted, or deferred.
66
+ - If entities look stale, refresh context through an approved Kibi capability and then re-query.
67
+ - Preserve source-file traceability by carrying `sourceFile`, text references, and validation evidence through discovery, mutation, and completion.
68
+ - Do not read or edit files inside `.kb` directly; use the selected Kibi interface instead.
69
+ - Kibi authors tracked files but never Git-stages or commits them; ordinary Git workflows remain responsible for review and commit.
70
+ - Completion must state one freshness outcome: KB updated, no KB impact with rationale, or deferred/failed.
71
+
72
+ For exact branch lifecycle, quarantine, restore, and source-first writes, read
73
+ the shared `kibi-usage/resources/branch-lifecycle.md` and
74
+ `source-authoring.md` resources.
@@ -0,0 +1,7 @@
1
+ # Branch lifecycle
2
+
3
+ Use the exact `KIBI_BRANCH` value or Git symbolic HEAD. Hashed stores carry a
4
+ matching `branch.json`; missing stores are rebuilt from tracked sources by
5
+ `kibi sync`. Legacy literal stores require explicit migration. Kibi never copies
6
+ stores between branches or resolves Git conflicts.
7
+
@@ -0,0 +1,6 @@
1
+ # Operation access
2
+
3
+ Use visible approved MCP or the trusted project-local CLI. `kb_status`/`status`
4
+ is read-only and returns the shared versioned result envelope with exact branch,
5
+ store, freshness, effects, diagnostics, and typed next actions.
6
+
@@ -0,0 +1,7 @@
1
+ # Source authoring
2
+
3
+ Tracked documents and relationship shards are authoritative. Kibi may write
4
+ them transactionally but does not stage or commit them. Inspect `effects` and
5
+ typed `nextActions`; after `committed_with_repairs`, repair without retrying the
6
+ original mutation.
7
+
@@ -0,0 +1,60 @@
1
+ ---
2
+ id: kibi-traceability
3
+ name: kibi-traceability
4
+ description: Maintain source-first requirement, scenario, test, symbol, and proof traceability through Kibi's peer interfaces.
5
+ version: 2.0.0
6
+ kibiCompatibility: ">=1.0.0"
7
+ tags:
8
+ - kibi
9
+ - traceability
10
+ - source-first
11
+ - proof
12
+ - agent-guidance
13
+ resources:
14
+ - resources/traceability.md
15
+ - resources/branch-lifecycle.md
16
+ - resources/source-authoring.md
17
+ - resources/operation-access.md
18
+ ---
19
+ ## Goal
20
+
21
+ Keep product intent connected to implementation without a parallel ticket
22
+ bureaucracy. Requirements own symbols, requirements have clause-complete
23
+ semantics, scenarios have tests, and proof-bearing tests have fresh evidence.
24
+
25
+ ## Interface Selection
26
+
27
+ Use the visible approved MCP tools or trusted project-local CLI as equal peer
28
+ interfaces. Select the surface by capability; neither is semantically preferred.
29
+ For CLI JSON, use a dedicated route such as
30
+ `printf '%s\n' '{}' | kibi status --input -`.
31
+
32
+ ## Workflow
33
+
34
+ Use the visible approved MCP tools or trusted project-local CLI as equal peer
35
+ interfaces. Discover with `kb_search`, exact-filter with `kb_query`, and inspect
36
+ `kb_status` before branch-sensitive work. Preserve `REQ-* -> SCEN-* -> TEST-*`;
37
+ link production symbols with `implements` and qualifying tests with
38
+ `executable_for`/`covered_by`.
39
+
40
+ After source edits, run targeted `kb_check` with impact diagnostics, update
41
+ tracked Markdown/YAML/manifests and canonical relationship shards through
42
+ sequential `kb_upsert`, then run final check and coverage. Kibi authors tracked
43
+ files transactionally but never Git-stages or commits them. Do not read or edit
44
+ `.kb` directly.
45
+
46
+ Use `kb_delete` only for intentional cleanup. Authored entity deletion returns a
47
+ hash-bound approval plan; requirements normally evolve through a new
48
+ requirement linked with `supersedes`. Relationship deletes patch shards while
49
+ preserving unrelated records.
50
+
51
+ ## Typed recovery and proof
52
+
53
+ Parse `kibiProtocol`, `resultVersion`, `status`, `effects`, diagnostics, and
54
+ typed `nextActions`. On `committed_with_repairs`, execute the required repair
55
+ action and never retry the original mutation. Keep ontology gaps, ambiguity,
56
+ stale snapshots, unavailable receipts, and incomplete grounding explicit.
57
+
58
+ Fresh proof requires a current verification snapshot, the exact contracted E2E
59
+ command, an append-only receipt, and current symbol coordinates. Structural
60
+ coverage and a green check are not proof by themselves.
@@ -0,0 +1,7 @@
1
+ # Branch lifecycle
2
+
3
+ The exact Git ref is the branch identity. Hashed stores are rebuildable
4
+ artifacts, missing stores compile from this checkout, and Git remains the sole
5
+ merge/conflict authority. Explicitly migrate legacy literal stores; do not copy
6
+ another branch's compiled state.
7
+
@@ -0,0 +1,5 @@
1
+ # Operation access
2
+
3
+ Use the shared operation contracts through approved MCP or the trusted project-local
4
+ CLI. Parse `kibiProtocol`, `resultVersion`, `status`, `effects`, diagnostics,
5
+ and typed `nextActions`; do not retry a mutation after authoritative commit.
@@ -0,0 +1,6 @@
1
+ # Source authoring
2
+
3
+ Use `document.path`/`document.body` for source-first writes. Preserve existing
4
+ body bytes when body is omitted, patch relationship shards without dropping
5
+ unrelated records, and follow typed repair actions after partial completion.
6
+
@@ -0,0 +1,8 @@
1
+ # Traceability detail
2
+
3
+ Model one requirement clause at a time. Use strict fact lanes for contradiction
4
+ checks, predicate schemas for project ontology, and observation/meta facts for
5
+ bugs and workarounds. Query all relationship endpoints before writing; a graph
6
+ link is not proof until the scenario, test, symbol, and fresh receipt are
7
+ readable at the current snapshot.
8
+
@@ -0,0 +1,152 @@
1
+ ---
2
+ id: kibi-usage
3
+ name: Kibi Usage
4
+ description: Use Kibi's source-first, exact-Git, migration-aware, proof-aware operations safely across MCP or the trusted local CLI, including partial completion repair.
5
+ version: 2.1.0
6
+ kibiCompatibility: ">=1.0.0"
7
+ tags:
8
+ - kibi
9
+ - mcp
10
+ - cli
11
+ - source-first
12
+ - branching
13
+ - traceability
14
+ - recovery
15
+ resources:
16
+ - resources/operation-access.md
17
+ - resources/branch-lifecycle.md
18
+ - resources/source-authoring.md
19
+ - resources/relationship-directions.md
20
+ - resources/fact-lanes.md
21
+ - resources/workflows.md
22
+ - resources/ui-requirements.md
23
+ - resources/logic-ir.md
24
+ - resources/kb-improvement.md
25
+ ---
26
+ # Kibi Usage
27
+
28
+ Consult this skill before any Kibi knowledge base operation, on first
29
+ interaction with a Kibi-enabled repo, after stale or dirty status is suspected,
30
+ and before mutations.
31
+
32
+ Kibi is an agent-native requirements compiler. Use it to retain product intent,
33
+ compile branch-local requirements and scenarios, link symbols to ownership,
34
+ and prove implementation with fresh evidence.
35
+
36
+ ## Interface Selection
37
+
38
+ Use whichever capability is visible and approved. The surfaces are equal peers:
39
+
40
+ 1. If approved Kibi MCP tools are visible, use them.
41
+ 2. Otherwise use `npx --no-install kibi ...` from the trusted project-local CLI.
42
+ 3. If the operator capability is unavailable or too old for the needed route,
43
+ stop and identify the missing capability.
44
+ 4. Never use a global fallback, an installing runner, or an unapproved route.
45
+
46
+ Hosts may expose prefixed identifiers such as `kibi_kb_search`,
47
+ `kibi_kb_query`, and `kibi_kb_upsert`; map them to the canonical MCP names.
48
+
49
+ The CLI JSON route accepts the same business object as MCP:
50
+
51
+ ```bash
52
+ printf '%s\n' '{"query":"checkout","limit":10}' | npx --no-install kibi search --input -
53
+ ```
54
+
55
+ Read `resources/operation-access.md` for the route, result version, effects,
56
+ mutability, and Prolog requirements of each operation.
57
+
58
+ ## Safe workflow
59
+
60
+ 1. Always discover before you mutate: start with `kb_search`, then exact-filter with `kb_query`. Use
61
+ `kb_status` when branch or freshness confidence matters.
62
+ 2. Resolve genuine ambiguity with the human; use semantic advisor/modeling
63
+ operations for deterministic interpretation and typed facts.
64
+ 3. Create endpoints before relationships and upsert small batches sequentially.
65
+ Keep the canonical `REQ-* -> SCEN-* -> TEST-*` chain.
66
+ 4. Author tracked Markdown/YAML/manifests and relationship shards through Kibi;
67
+ Kibi never Git-stages or commits those files. Do not read or edit `.kb`
68
+ directly.
69
+ 5. Finish with targeted and final `kb_check`, then read status/coverage and
70
+ state freshness, verification, proof, and limitations separately.
71
+
72
+ Run `kb_check` with specific rules during iteration and the unfiltered final
73
+ check. Never fire `kb_upsert` calls in parallel; create or confirm endpoint
74
+ entities before linking them. The canonical MCP names are `kb_search`,
75
+ `kb_query`, `kb_upsert`, and `kb_check`.
76
+
77
+ ## Exact Git attachment
78
+
79
+ The active ref is the exact KB identity. `KIBI_BRANCH` is used verbatim; Git's
80
+ symbolic HEAD is used otherwise. Slash, `@`, Unicode, `main`, `master`, and
81
+ detached states are not normalized or merged. Hashed stores and their
82
+ `branch.json` identity fence are compiled artifacts. A missing exact store is
83
+ created by `kibi sync` from this checkout's tracked sources. Kibi never copies
84
+ stores across branches and never selects merge winners; unresolved authored Git
85
+ conflicts block compilation. See `resources/branch-lifecycle.md` for legacy
86
+ migration, worktrees, quarantine, restore, and purge.
87
+
88
+ ## Typed results and recovery
89
+
90
+ Every CLI JSON/MCP result has `kibiProtocol`, `operation`, `resultVersion`,
91
+ `status`, `data`, `effects`, `diagnostics`, and typed `nextActions`. Treat
92
+ `status: error` as a failed pre-commit operation. If the status is
93
+ `committed_with_repairs`, the mutation already committed: inspect failed effects,
94
+ execute each required repair action in order, and never retry the original
95
+ operation. Record effect failures, followed actions, and unsafe retries in
96
+ diagnostic telemetry.
97
+
98
+ ## Source-first mutation
99
+
100
+ Use `document.path` when a new entity has no single configured writable target.
101
+ Existing entities preserve body bytes when `document.body` is omitted; new
102
+ requirements default their body to `semantic_text`. Relationship mutations
103
+ patch canonical shards while preserving unrelated records. Authored entity
104
+ deletion returns a hash-bound approval plan; requirements normally evolve via a
105
+ new entity linked with `supersedes`. Read `resources/source-authoring.md` before
106
+ source writes, deletion approval, or recovery.
107
+
108
+ ## Semantic and proof guardrails
109
+
110
+ Prolog proves only encoded facts. Keep ambiguity, ontology gaps, incomplete
111
+ grounding, stale snapshots, and failed or unavailable evidence explicit. Use
112
+ `fact_kind: subject` plus `property_value`/`predicate` lanes for contradiction-
113
+ safe normative claims; use `observation` or `meta` for bug/workaround notes and
114
+ `flag` only for actual runtime/config gates. Requirements require scenarios,
115
+ tests, symbol ownership, and fresh proof-bearing receipts before claiming proof.
116
+ For an existing product KB that needs semantic backfill, read
117
+ `resources/kb-improvement.md`.
118
+
119
+ ## Predicate Ontology Decision Tree
120
+
121
+ Call `kb_semantic_advisor`, `kb_model_requirement`, or `kb_suggest_predicates`
122
+ before encoding a normative clause. Use `fact_kind: predicate` with
123
+ `requires_predicate` when a suitable schema exists; use `fact_kind: observation`
124
+ for an ontology gap. Keep the `REQ -> TEST` chain and use `verified_by` for
125
+ proof-bearing links. Relationship direction is fixed, and every `from` in a
126
+ relationship batch must equal the upserted entity ID.
127
+
128
+ ## Symbol-First Traceability
129
+
130
+ Represent implementation ownership with a `symbol` entity and an `implements`
131
+ relationship from the symbol to the requirement. Do not rely on legacy
132
+ `// implements REQ-xxx` comments as the traceability record.
133
+
134
+ ## Complete Logical Coverage
135
+
136
+ Decompose all atomic normative clauses into `claim_key`/`claim_text` entries in
137
+ `logic_claims`; human or agent review still confirms that the atomic clauses
138
+ exhaust the prose. Run `logic-coverage` and `domain-contradictions` after
139
+ modeling. Use `status: implemented` only as historical input; use a valid status
140
+ such as `closed`, add an `implemented` tag, and link evidence instead.
141
+
142
+ ## Anti-Patterns and Remediation
143
+
144
+ Reject reversed relationship direction, a Bug-as-flag record without a runtime
145
+ gate, direct KB-store edits, and a generic `strict kb_upsert.properties` field.
146
+ Keep symbol payloads minimal. When a generic `Query failed` appears, do not keep
147
+ retrying the same payload; inspect the typed error and `nextActions`.
148
+
149
+ Kibi may now author tracked Markdown/YAML evidence transactionally. The former
150
+ statement “Kibi operation writes do not automatically stage markdown evidence”
151
+ means Kibi writes do not Git-stage it: review and commit remain ordinary Git
152
+ workflows.
@@ -0,0 +1,31 @@
1
+ # Branch lifecycle
2
+
3
+ Kibi attaches to the exact Git ref: `KIBI_BRANCH` when set, otherwise Git's
4
+ symbolic HEAD. Names are not normalized, and `main`, `master`, detached HEAD,
5
+ slash names, `@`, and Unicode refs remain distinct identities.
6
+
7
+ Compiled state lives under `.kb/branches/<sha256-hash>/branch.json`. The
8
+ manifest records the exact ref and hash; a mismatch is a hard attachment
9
+ failure. A missing store is compiled by `kibi sync` from the current checkout's
10
+ tracked sources. `branch ensure` may create only the empty identity fence; use
11
+ `kibi sync` before relying on compiled state. Kibi never copies another
12
+ branch's store and never chooses merge winners. Git owns merges; unresolved
13
+ conflicts in authored files block compilation.
14
+
15
+ Legacy literal-path stores are read-only compatibility attachments. Preview an
16
+ explicit migration with both identities, then apply it only with the exact
17
+ preview hash (`kibi branch migrate --from <old> --to <new> --apply
18
+ --approval-hash <preview-hash>`) while attached to the exact new ref. The
19
+ approval is mandatory and binds the source bytes and identities; do not infer a
20
+ rename from commits. For a legacy literal store on the current branch, `<old>`
21
+ and `<new>` must be the same exact identity. Every cross-identity pair is
22
+ refused, including `main` to `master`; migration changes only the storage
23
+ format from literal to hashed for the active exact branch. Deleted local branches may be quarantined for the
24
+ configured retention period; `branch restore --branch <exact-ref> --apply` is
25
+ reversible during retention and purge is explicit. Remote-only refs do not keep
26
+ a local compiled store alive.
27
+
28
+ If migration is interrupted, use the journal's exact recovery action:
29
+ `kibi branch migrate --recover-journal <id>` previews the deterministic
30
+ roll-forward or verified-backup restore, and `--apply` performs it. Do not
31
+ resolve the live branch attachment while the migration journal is ambiguous.
@@ -0,0 +1,235 @@
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 exact current `logic_claims` set, removing only stale keys whose propositions no longer exist in the source;
11
+ - link it through exactly one `requires_property` for `property_value`, one `requires_predicate` for `predicate`, or one `requires_rule` for a safe `rule` fact;
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
+ ### Lane gates before a predicate lookup
80
+
81
+ Treat the advisor's proposition status as a hard routing decision. `nonlogical`/`subjective` prose is not a logical claim: keep it as one observation when needed and do not add its key to `logic_claims`. `ambiguous` prose stays an ambiguity observation. `ontology_gap` prose stays unresolved unless an approved schema or validated Logic IR is available. Never split a subjective or commentary sentence into synthetic clauses just because it contains conditional words or domain vocabulary.
82
+
83
+ If authorized input supplies `projectLocalSchemas`, use those signatures as the authority. Create the minimal `predicate_schema` endpoint before lookup, then rerun `kb_suggest_predicates` on the complete relation if the first lookup had no candidate. Apply exactly one ground predicate and one claim key for that relation. For `must not`, `never`, `cannot`, or `forbidden` wording, preserve the positive schema and set `polarity: deny`; do not turn the result into an asserted predicate or invent a negative name. An empty lookup before the declared schema exists is a retry condition, not proof of an ontology gap.
84
+
85
+ ## Typed rule lane
86
+
87
+ Use a validated `kibi.logic.v1` object for a proposition whose meaning includes a condition, exception, obligation, prohibition, permission, quantifier, cardinality bound, or bounded temporal relation. `kb_model_requirement` returns the `rule_schema` and `rule` facts plus a `requires_rule` edge. The rule stores canonical JSON and a deterministic hash; any rendered Prolog is an audit view and is never executed. Reject raw goals, function symbols, cuts, meta-calls, dynamic predicates, I/O, unsafe variables, unstratified negation, and unbounded aggregation. Keep the exact proposition in `claim_text`, its advisor key in `claim_key`, and its byte span in the semantic ledger. Run `rule-safety` and `rule-verifiability` before treating the rule as modeled.
88
+
89
+ ### Strict scalar
90
+
91
+ 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`.
92
+
93
+ ### Ambiguous claim
94
+
95
+ 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.
96
+
97
+ ### False-positive trap
98
+
99
+ 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.
100
+
101
+ ### Ontology gap
102
+
103
+ 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:
104
+
105
+ ```yaml
106
+ id: FACT-ONTOLOGY-GAP-ANNOTATION-ANCHOR
107
+ status: active
108
+ fact_kind: observation
109
+ tags: [review:ontology-gap]
110
+ text_ref: docs/requirements/annotation-anchor.md
111
+ ```
112
+
113
+ An ontology-gap observation records review work; it does not make the requirement machine-checkable.
114
+
115
+ ## Strict Lane (Contradiction-Safe)
116
+
117
+ ### fact_kind: subject
118
+ ```yaml
119
+ id: FACT-USER-ROLE
120
+ title: User Role Assignment
121
+ status: active
122
+ fact_kind: subject
123
+ subject_key: user.role_assignment
124
+ ```
125
+
126
+ ### fact_kind: property_value
127
+ ```yaml
128
+ id: FACT-LIMIT-3
129
+ title: Maximum of Three Roles
130
+ status: active
131
+ fact_kind: property_value
132
+ subject_key: user.role_assignment
133
+ property_key: max_roles
134
+ operator: lte
135
+ value_type: int
136
+ value_int: 3
137
+ ```
138
+
139
+ ## Granular Facts for Coherence Checks
140
+
141
+ 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.
142
+
143
+ ### Role set conflict
144
+
145
+ `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.
146
+
147
+ ```yaml
148
+ subject:
149
+ id: FACT-USER-ROLES
150
+ title: User roles
151
+ status: active
152
+ fact_kind: subject
153
+ subject_key: user.roles
154
+
155
+ property_values:
156
+ - id: FACT-USER-ROLES-ALLOWED-2
157
+ title: User and admin roles only
158
+ status: active
159
+ fact_kind: property_value
160
+ subject_key: user.roles
161
+ property_key: user.roles.allowed_set
162
+ operator: eq
163
+ value_type: string
164
+ value_string: user,admin
165
+ - id: FACT-USER-ROLES-ALLOWED-3
166
+ title: User, admin, and superadmin roles
167
+ status: active
168
+ fact_kind: property_value
169
+ subject_key: user.roles
170
+ property_key: user.roles.allowed_set
171
+ operator: eq
172
+ value_type: string
173
+ value_string: user,admin,superadmin
174
+
175
+ relationships:
176
+ - { type: constrains, from: REQ-ROLE-SET-2, to: FACT-USER-ROLES }
177
+ - { type: requires_property, from: REQ-ROLE-SET-2, to: FACT-USER-ROLES-ALLOWED-2 }
178
+ - { type: constrains, from: REQ-ROLE-SET-3, to: FACT-USER-ROLES }
179
+ - { type: requires_property, from: REQ-ROLE-SET-3, to: FACT-USER-ROLES-ALLOWED-3 }
180
+ ```
181
+
182
+ ### Permission actor conflict
183
+
184
+ `REQ-ADMIN-CAN-MANAGE-BILLING` and `REQ-ONLY-SUPERADMIN-MANAGES-BILLING` conflict when both define the exact allowed actor for the same permission.
185
+
186
+ ```yaml
187
+ subject:
188
+ id: FACT-BILLING-MANAGE
189
+ title: Billing management permission
190
+ status: active
191
+ fact_kind: subject
192
+ subject_key: billing.manage
193
+
194
+ property_values:
195
+ - id: FACT-BILLING-MANAGE-ACTOR-ADMIN
196
+ title: Admin can manage billing
197
+ status: active
198
+ fact_kind: property_value
199
+ subject_key: billing.manage
200
+ property_key: billing.manage.allowed_actor
201
+ operator: eq
202
+ value_type: string
203
+ value_string: admin
204
+ - id: FACT-BILLING-MANAGE-ACTOR-SUPERADMIN
205
+ title: Only superadmin can manage billing
206
+ status: active
207
+ fact_kind: property_value
208
+ subject_key: billing.manage
209
+ property_key: billing.manage.allowed_actor
210
+ operator: eq
211
+ value_type: string
212
+ value_string: superadmin
213
+ ```
214
+
215
+ When a contradiction is intentional evolution rather than a real conflict, link the replaced requirement to the replacement requirement with `supersedes`.
216
+
217
+ ## Context Lane (Non-Blocking)
218
+
219
+ ### fact_kind: observation
220
+ For bug records, incident notes, and observed behavior.
221
+ ```yaml
222
+ id: FACT-BUG-123
223
+ title: Login fails on Safari 17
224
+ status: active
225
+ fact_kind: observation
226
+ ```
227
+
228
+ ### fact_kind: meta
229
+ For governance notes, process commentary, and workaround documentation.
230
+ ```yaml
231
+ id: FACT-WORKAROUND-456
232
+ title: Temporary cache bypass for v2 migration
233
+ status: active
234
+ fact_kind: meta
235
+ ```
@@ -0,0 +1,38 @@
1
+ # Existing Product KB Improvement
2
+
3
+ Use this resource when an existing product KB already has REQ → SCEN → TEST →
4
+ symbol traceability and the task is to add typed facts so normative claims are
5
+ queryable and contradiction-checkable.
6
+
7
+ Keep the original requirement prose readable. Facts add semantics; they do not
8
+ replace the requirement body. Lane choice, field names, and predicate routing
9
+ are in `resources/fact-lanes.md` and the Predicate-First workflow in
10
+ `resources/workflows.md`.
11
+
12
+ ## Claim routing
13
+
14
+ | Claim type | Model as | Relationship |
15
+ | --- | --- | --- |
16
+ | Measurable normative property | `subject` + `property_value` | `constrains` + `requires_property` |
17
+ | Domain invariant or behavior relation | `predicate` | `requires_predicate` |
18
+ | Bug, workaround, or observed evidence | `observation` | usually `relates_to` |
19
+ | Process or governance note | `meta` | usually `relates_to` |
20
+ | Runtime or config gate | `flag` | `guards` |
21
+
22
+ Call `kb_semantic_advisor` on the complete requirement body before encoding a
23
+ clause. Apply a predicate only when a returned schema fits; otherwise leave an
24
+ ontology-gap observation.
25
+
26
+ ## Source and RDF reconciliation
27
+
28
+ After each approved write:
29
+
30
+ 1. Query the exact fact IDs.
31
+ 2. Confirm `fact_kind`, `predicate_name` or `property_key`, and `canonical_key`
32
+ appear through Kibi tools, not only in authored Markdown.
33
+ 3. Graph from the requirement with `requires_predicate` and `requires_property`.
34
+ 4. If Markdown has predicate or property fields but queries do not, report a
35
+ sync or import issue before creating duplicates.
36
+
37
+ Treat active tool query results as operational truth. Authored Markdown is
38
+ evidence of intent, not proof of active KB state.