
CogZ
io.github.balaianuv0.5.8更新於 Oct 5, 2026
Local-first engineering cognition for AI coding agents — persistent memory over your codebase.
概覽
CogZ 為編碼代理提供本機、程式碼感知的儲存庫記憶,保存觀察、規則與知識,並依需求產生脈絡包。
- 功能
- CogZ 維護專案專屬的知識層,把觀察、規則與結構化知識以帶 YAML frontmatter 的 Markdown 檔案保存,並與程式碼實體互相連結。它能產生受 token 預算限制、依相關性排序、可沿程式碼圖追溯的脈絡包,並定期整併知識:去重、偵測矛盾、把觀察提升為規則、標記過期項目。它以 stdio 上的無狀態 MCP 伺服器執行,提供 15 個工具,包括 create_entity、update_knowledge、query_entities、search、get_context、consolidate、get_callers 與 get_impact。鉤子可擷取生命週期事件並把脈絡包注入代理工作階段。
- 適用情境
- 當編碼代理需要反覆處理同一個儲存庫,並希望跨工作階段記住決策、規範與架構,而不是每次重新發現時,適合安裝。也適合希望專案知識可版本控制、可手動編輯,而非存放在不透明向量庫中的團隊。
- 執行需求
- 在使用者機器上以本機程序執行,以 OCI 映像(ghcr.io/balaianu/cogz:0.5.8)散布,並透過 shell 或 PowerShell 指令碼安裝;單一 Rust 二進位檔,除選用的 ONNX 模型外沒有執行階段相依性。僅 FTS 模式最低需要 256 MB 記憶體與 50 MB 磁碟;混合檢索約需 2 GB 記憶體與 550 MB 磁碟,模型在首次使用時自動下載。不支援 macOS Intel。未宣告帳號、API 金鑰或環境變數。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 CogZ,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
CogZ
[CI] [License: MIT] [Rust] [Version] [OpenSSF Scorecard] [OpenSSF Best Practices] [Buy Me A Coffee]
Local-first, code-aware engineering cognition for AI coding agents.
CogZ gives a coding agent persistent memory, contextual retrieval, and continuous cognition about a software repository — all running locally on your machine, no cloud services required.
Works with Claude Code, Cursor, Codex, Gemini CLI, GitHub Copilot, Devin, and any MCP-compatible agent.
What it looks like
Real output from CogZ running on its own codebase:
That's not a text chunk from a vector search. The pack leads with validated rules — one learned from a release failure on this very project — plus the identity baseline and the actual source file, all ranked, traceable, and budgeted.
This repository already contains real dogfooding knowledge — CogZ has been used on its own codebase throughout development. You can clone it, install CogZ, and try the commands above against it directly.
What it does
CogZ maintains a project-specific knowledge layer that connects what an agent learns to the code it is working with.
Memory
CogZ stores three kinds of project knowledge:
- Observations — things an agent has learned or noticed. Raw, unvalidated experience: bugs found, decisions made, patterns noticed.
- Rules — validated knowledge that should influence future work. Coding standards, design decisions, confirmed patterns.
- Knowledge — structured information about the codebase. Architecture explanations, module responsibilities, trade-off rationale.
These are stored as Markdown files with YAML frontmatter, linked to each other and to code entities in the repository. The files are the canonical source of truth — SQLite is a derived index, disposable and rebuildable. Your knowledge is portable, version-controlled, and editable by hand.
Context
Instead of giving an agent everything it knows, CogZ builds scoped context packs for the current situation. A context pack combines relevant rules, observations, knowledge, and code structures — ranked by relevance, traceable through the code graph, and limited by a token budget so the agent gets what matters for the task rather than the entire project history.
Cognition
CogZ periodically consolidates what has been learned: deduplicates entries, detects contradictions, promotes well-supported observations to rules, merges superseded entries, and flags knowledge as stale when the code it references changes.
Quick start
Linux / macOS / Windows (Git Bash):
Windows (PowerShell):
See Getting Started for the mental model and a complete walkthrough.
MCP integration
CogZ runs as a stateless MCP server over stdio. Every tool call specifies which repo it targets via a required repo parameter — no Roots, no session state, no fallbacks.
The server exposes 15 tools: create_entity, update_knowledge, verify_knowledge, reject_entity, query_entities, search, get_context, get_status, list_entities, consolidate, capture_event, get_callers, get_impact, find_orphans, suggest_observations.
See MCP Tools for full parameter reference and example responses. See Agent Setup for per-agent config files, hook formats, and verified capability notes for all six supported agents — or just run cogz configure auto.
Hook integration
Hooks capture lifecycle events and inject context packs into agent sessions. CogZ's binary is the hook handler — no wrapper scripts needed.
See Hooks for all 7 event types and per-agent wiring guides.
CLI commands
Normal operation is automatic: hooks fire on lifecycle events, the agent drives CogZ through MCP. The CLI is not needed for day-to-day use — it's available for setup, manual exploration, and automation if you want or need it.
See CLI Reference for all flags and options.
Requirements
Minimum (FTS-only mode)
Works without ONNX Runtime or model downloads. All hooks, FTS search, context packs, consolidation, doctor, and prune are functional. Vector search, embedding-based dedup, and contradiction detection are not available.
Recommended (hybrid search mode)
Full functionality including vector search, semantic dedup, and NLI contradiction detection. Models auto-download on first use and auto-unload after 5 min idle (RAM drops back to ~11 MB). See Evaluations for the full resource consumption profile.
Benchmarks
CogZ ships a reproducible suite (benchmark/) run on pinned public corpora — httpx, cobra, clap, each injected with memory seeds mined from its real git history — plus this repository's own .cogz corpus. Seeded ground truth:
Channel ablations on commit queries: removing graph expansion costs 10–16pt recall@20 on every corpus; FTS-only mode retains ~75–85% of hybrid recall with ~745 MB less RSS. Context packs keep 0.70–0.90 expected-entity recall at the default 8K budget. Reruns are byte-identical. Full methodology, per-phase numbers, and the raw artifacts: benchmark/README.md.
What using it buys (measured): in a 14-task agent replay, the seeded-knowledge arm finished ~2x faster than bare (871s vs 1748s average) and completed more runs (14/14 vs 10/14) at equal correctness. Consolidation machinery is precise: dedup precision/recall 1.0, NLI contradiction detection 4/4 with zero false alarms, drift marking exact.
Honest limits: top-5 precision is weak on mixed corpora (P@5 <= 0.20; code entities outrank knowledge at the top of the ranking), commit-intent queries reach 0.36–0.56 recall@20, adjacent-domain negative queries leak confident hits (silence-gate clean rate 0–0.4 across corpora), and at n=14 tasks there is no measurable task-correctness lift yet.
Architecture
- Single Rust binary — no runtime dependencies except optional ONNX models for vector search.
- Files are canonical — all entities are Markdown files. The SQLite DB is a derived index, disposable and rebuildable.
- Code-aware — tree-sitter indexes source code as first-class graph entities. Supported languages: Rust, Python, Go, JavaScript, TypeScript, TSX, Bash.
- Graceful degradation — works without ML models in FTS-only mode.
- Local-first — no cloud, no telemetry, no accounts. The only network access is optional model downloads.
See Architecture for the full system design.
Compatibility
macOS Intel is not supported because Microsoft dropped ONNX Runtime macOS Intel binaries after v1.22. Intel Mac users can run the arm64 binary under Rosetta 2 (with a compatible ORT build) or use cargo install cogz for FTS-only mode.
Windows 10+ is required (bsdtar is bundled since build 17063, needed for ONNX Runtime auto-extraction).
Cross-platform team collaboration is supported: code entity UUIDs use forward-slash path normalization so the same source file produces the same entity ID on all platforms.
Documentation
User guides:
- Getting Started — mental model and walkthrough
- Configuration — full
config.tomlreference - CLI Reference — every command and flag
Integration:
- MCP Tools — all 15 tool signatures and response shapes
- Hooks — lifecycle events and output format
- Agent Setup — all six agents + generic MCP, with per-agent effect coverage
Design:
- Architecture — system overview and module map
- Entity Model — entity types, frontmatter, state machine
- Search — hybrid FTS + vector, RRF, graph expansion
- Consolidation — dedup, contradiction, promotion, merge
- Degradation — FTS-only mode and fallback behavior
Contributing:
- Building — build, release, cross-compile
- Testing — test categories and mock models
- Conventions — code patterns and invariants
- Dependencies — pinned versions and supply-chain policy
- Schema — DB schema and migrations
Contributing
See CONTRIBUTING.md for build, test, and PR guidelines.
License
MIT — see LICENSE.
Support
If you find this tool useful, consider buying me a coffee:
來源:README.md,提交 fc92754
工具
0版本歷史
1- v0.5.8最新Oct 5, 2026
