graph TD
subgraph Git Repository
D[Markdown/YAML Documents]
end
D -->|Extract| E[Extractors]
E -->|Entities/Relationships| KB[Prolog KB (per branch)]
KB -->|Query| CLI[CLI]
KB -->|Query| MCP[MCP Server]
MCP -->|Tooling| VSCode[VS Code Extension]
CLI -->|Git Hooks| GH[Git Hooks]
GH -->|post-checkout/post-merge| KB
KB -->|Persist| RDF[RDF Persistence]
- Detailed analysis of package boundaries and simplification roadmap: OpenCode monorepo simplification review
- Located at
packages/core/src/kb.pl - Implements RDF persistence using SWI-Prolog's
rdf_persistency - Stores entities and relationships as RDF triples
- Enforces validation rules
- All operations mutex-protected for concurrency safety
- Located at
packages/cli/ - Node.js/Bun wrapper around Prolog
- Spawns SWI-Prolog subprocess
- Commands: init, sync, query, check, gc, branch, doctor
- Runs extractors for Markdown/YAML
- Handles schema validation and audit logging
- Located at
packages/mcp/ - Provides stdio JSON-RPC transport (newline-delimited, no embedded newlines)
- Tools: query, upsert, delete, check, branch.ensure, branch.gc
- Branch-aware: all tools accept branch parameter
- Keeps Prolog process alive for stateful operations
Entity Modeling:
flagentities represent runtime/config gates. Bug and workaround notes belong infactentities withfact_kind: observationormeta. Strict facts drive contradiction checks; observation/meta are non-blocking notes. See Entity Schema.domain-contradictionsapplies to strict lane;strict-fact-shapeis a default-off migration check.
- Located at
packages/vscode/ - TreeView scaffolding for KB navigation
- MCP integration for queries and updates
- Minimal functionality in v0
- Installed in
$GIT_DIR/hooksor viacore.hooksPath post-checkout: ensures branch KB exists, runs syncpost-merge: runs synckb gc: deletes stale branch KBs
sequenceDiagram
participant Dev as Developer
participant CLI as CLI
participant Ext as Extractors
participant KB as Prolog KB
participant RDF as RDF Persistence
Dev->>CLI: kibi sync
CLI->>Ext: Run extractors
Ext->>KB: Generate entities/relationships
KB->>RDF: Persist triples
KB->>KB: Validate, append audit log
sequenceDiagram
participant User as User
participant CLI as CLI/MCP
participant KB as Prolog KB
participant RDF as RDF Persistence
User->>CLI: kibi query / MCP query
CLI->>KB: Send query
KB->>RDF: Query RDF store
KB->>CLI: Serialize results to JSON
CLI->>User: Return results
- Each git branch has its own KB directory
- On new branch creation: KB is copied from main branch snapshot
- After creation, branch KBs evolve independently (no ongoing sync)
- Branch KB isolation prevents cross-branch contamination
- Git hooks automate KB creation and sync on branch events
- Uses SWI-Prolog
library(semweb/rdf_persistency) - Directory layout: base snapshot (binary
.trp) + journal (.jrnProlog terms) - File locking: lock file with timestamp, PID, hostname prevents concurrent access
- Multi-step updates guarded with
with_mutex/2for atomicity - Journals are not auto-merged; explicit maintenance required
- Also uses
library(persistency)for record-like predicates - Provides ACID properties (isolation, durability) for KB operations
- JSON-RPC messages sent via stdio (newline-delimited)
- No embedded newlines in messages
- Only valid MCP messages on stdout; logs sent to stderr
post-checkout: ensures branch KB exists, runs syncpost-merge: runs synckb gc: deletes stale branch KBs
- See README.md for
.kb/directory layout and file details
This document covers the technical architecture, component interactions, data flow, per-branch KB isolation, RDF persistence, MCP transport, and git hook automation for Kibi. For directory structure details, refer to README.md.