CogZ

io.github.balaianuv0.5.8更新于 Oct 5, 2026

Local-first engineering cognition for AI coding agents — persistent memory over your codebase.

已验证STDIO仅桌面Developer ToolsKnowledge & Memory

概览

AI 生成的概览

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 密钥或环境变量。
安装前请注意
它会写入仓库:cogz init 创建 .cogz 目录,索引会建立 SQLite 索引,整合过程可能提升、合并或拒绝知识条目,因此依赖前应检查变更。安装脚本通过管道直接交给 shell 执行。网络访问用于可选的模型下载和自更新。README 声明无云端、无遥测、无账号,但知识文件和索引位于项目中,可能被提交到版本库。

安装

在 SourceWeft 中

  1. 打开 控制台中的 CogZ,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

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:

$ cogz context --mode task "token budget estimation and context pack compression"
Context pack (mode: task)Query: token budget estimation and context pack compressionSearch mode: hybridSections: 91Token estimate: 8188
Dropped: 6 sections over token budget
---
## 1. [rule] New expansion channels: emit early, filter before seen-mark, sort deterministically, never displace directs (relevance: 0.5148)
Conventions proven across the sibling and co-change channels:
1. Emit before the generic expansion loops — candidates emitted   later get claimed-and-floored by graph traversal …2. Apply entity-type/test filters BEFORE `seen.insert` ……
## 2. [rule] cfg-gated code must be typechecked per-target before release (relevance: 0.4690)
Code behind #[cfg(unix)]/cfg(target_os = ...) is invisible to hostbuilds, tests, and clippy — a compile error in a cfg'd branch shipssilently until a real target build sees it. The v0.5.0 Windows legfailure is the canonical example.
## 3. [rule] Degradation must be loud, never silent (relevance: 0.3680)
Every degraded or failed code path must surface a signal …
## 4. [identity] CogZ (relevance: —)
Project: CogZ
## 5. [file] assemble.rs (relevance: 0.6993)
//! Context pack assembly — the tiered-push pipeline.//! Tier 0 (baseline: identity + top rules) always ships for task and//! escalation packs …
… 86 more sections …

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):

bash
# Installcurl -fsSL https://raw.githubusercontent.com/balaianu/CogZ/master/install.sh | bash
# Initialize in a repo (add --configure auto to wire MCP + hooks for detected agents)cd ~/your-projectcogz init
# Index (downloads models on first run, or use --no-download for FTS-only)cogz index
# Verify it's working — entity counts, model status, DB statscogz status

Windows (PowerShell):

powershell
# Installirm https://raw.githubusercontent.com/balaianu/CogZ/master/install.ps1 | iex
# Initialize in a repocd your-projectcogz initcogz index

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.

json
{  "mcpServers": {    "cogz": {      "command": "cogz",      "args": ["mcp-stdio"]    }  }}

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.

json
{  "hooks": {    "SessionStart": [{      "matcher": "",      "hooks": [{        "type": "command",        "command": "cogz capture-event session_start --hook-json",        "timeout": 15      }]    }]  }}

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.

CommandDescription
cogz initInitialize .cogz/ in a repository
cogz configure <harnesses>Write agent MCP + hook config (auto detects installed agents)
cogz index [--no-download]Sync files to DB + index source code
cogz reindexIncremental reindex (changed files only)
cogz search <query>Hybrid FTS + vector + graph search
cogz context --mode <mode> [query]Assemble context pack
cogz statusDB stats, entity counts, model status
cogz consolidate [--dry-run]Run promotion and merge
cogz suggest [--days N]List mined observation candidates
cogz verify <entity-id>Re-stamp a drifted entity's provenance
cogz reject <entity-id>Mark an entity rejected (--reason stored)
cogz capture-event <type>Capture lifecycle event from hooks
cogz models <download|list|clean>Model management
cogz doctor [--prune-observations]Health check, policy violations, usage metrics
cogz update [--check]Self-update from GitHub releases
cogz reset [--purge]Drop DB (optionally purge observations)
cogz mcp-stdioRun MCP server over stdio

See CLI Reference for all flags and options.

Requirements

Minimum (FTS-only mode)

ResourceRequirement
RAM256 MB free
Disk50 MB (binary + DB, no models)
CPUany x86_64 or ARM64

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)

ResourceRequirement
RAM2 GB free
Disk550 MB (binary + ONNX Runtime + 3 models + DB)
CPUany x86_64 or ARM64, 4+ cores speeds up batch embedding

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:

CorpusP@5MRRRecall@20
cobra0.2000.5310.967
httpx0.1730.3580.917
clap0.1850.2780.839

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

PlatformSupportEmbeddingsFTS-onlyInstall
Linux x86_64FullAuto-downloadYesinstall.sh
Linux aarch64FullAuto-downloadYesinstall.sh
macOS arm64 (Apple Silicon)FullAuto-downloadYesinstall.sh
macOS x86_64 (Intel)Not supported———
Windows x86_64FullAuto-downloadYesinstall.ps1 or install.sh (Git Bash)

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:

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:

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:

[Buy Me A Coffee]

来源:README.md,提交 fc92754

工具

0
工具元数据尚未被收录。

版本历史

1
  1. v0.5.8最新Oct 5, 2026