### Quick start setup commands Source: https://github.com/ashlesh-t/cognirepo/blob/main/CONTRIBUTING.md Clone the repository, create a feature branch from development, install with dev/security/languages extras, initialize, and run tests. Use pipx instead of pip if preferred. ```bash git clone https://github.com/ashlesh-t/cognirepo cd cognirepo git checkout development && git checkout -b your-feature-branch pip install -e ".[dev,security,languages]" # or: pipx install -e ".[dev,security,languages]" cognirepo init pytest tests/ -v --tb=short ``` -------------------------------- ### Dev Setup: Clone, Install, Init, Test, Lint Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Clone the repository and install with pipx (recommended) or a local venv. Initialize the project with `cognirepo init`, run tests with pytest, and lint with pylint. On Arch Linux / Debian 12+ / Ubuntu 24.04+, avoid system Python due to PEP 668; use pipx or a venv. ```bash # Clone the repo git clone https://github.com/ashlesh-t/cognirepo cd cognirepo # Option A — pipx (recommended: global binary, isolated venv, no PEP 668 issues) pipx install -e ".[dev,security,languages]" # Option B — local venv python -m venv venv && source venv/bin/activate pip install -e ".[dev,security,languages]" # Initialize the project cognirepo init # Run tests pytest tests/ -v --tb=short # Lint pylint $(git ls-files '*.py' | grep -v '_pb2') --disable=C,R,import-error --fail-under=8.0 ``` -------------------------------- ### Install cognirepo inside a virtual environment Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Alternative installation method using a Python virtual environment. Extras are installed automatically by the setup wizard. ```bash python -m venv .venv && source .venv/bin/activate pip install cognirepo # extras are installed by the setup wizard automatically ``` -------------------------------- ### Install tree-sitter grammar package Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Install the tree-sitter grammar package for a new language. The example shows installing tree-sitter-kotlin. ```bash pip install tree-sitter- # e.g. pip install tree-sitter-kotlin ``` -------------------------------- ### Install cognirepo with pipx Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Recommended global installation using pipx, which creates an isolated virtual environment and works on all distributions. The cognirepo setup command handles optional extras automatically. ```bash pipx install cognirepo ``` -------------------------------- ### Install CogniRepo from source Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Clone the repository and install using either pipx (global, isolated, recommended) or a virtual environment. Includes one-time setup with cognirepo init. ```bash git clone https://github.com/ashlesh-t/cognirepo && cd cognirepo # Option A — pipx (global, isolated, recommended): pipx install -e '.[dev,languages]' # Option B — inside a venv: python -m venv venv && source venv/bin/activate # Windows: venv\Scripts\activate pip install -e ".[dev,languages]" # One-time setup cognirepo init ``` -------------------------------- ### Write tests Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Create a test file for the new language. The example shows a test for Kotlin function extraction. ```python # tests/test_indexer_kotlin.py def test_kotlin_function_extracted(tmp_path): ... ``` -------------------------------- ### Development install from source Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Install cognirepo from source with development, security, and language extras. Use pipx or a virtual environment. ```bash pipx install -e '.[dev,security,languages]' # or inside a venv: pip install -e '.[dev,security,languages]' ``` -------------------------------- ### cognirepo setup command Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md One-command onboarding that runs init, index-repo, and MCP config generation. Installs optional extras interactively. Use --no-index to skip indexing and --targets to specify MCP targets (claude, cursor, vscode). ```bash cognirepo setup [--no-index] [--targets claude cursor vscode] ``` -------------------------------- ### Enable encryption with cognirepo[security] Source: https://github.com/ashlesh-t/cognirepo/blob/main/SECURITY.md Install the security extra to get cryptography and keyring, then set storage.encrypt to true in .cognirepo/config.json. The key is generated on cognirepo init and stored in the OS keychain. ```bash pip install 'cognirepo[security]' # installs cryptography + keyring # Set in .cognirepo/config.json: # "storage": { "encrypt": true } ``` -------------------------------- ### Install prometheus-client and start CogniRepo server Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Install the dev-only prometheus-client package and run the CogniRepo server. The metrics counters are in-process only and no /metrics endpoint is exposed. ```bash pip install prometheus-client # dev only cognirepo serve ``` -------------------------------- ### Clone, install, and run cognirepo benchmark Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/METRICS.md Reproduces the main benchmark workflow. Requires Python and pip; installs the package with dev dependencies, initializes cognirepo, indexes the current repository, and runs the benchmark. ```bash git clone https://github.com/ashlesh-t/cognirepo cd cognirepo pip install -e ".[dev]" cognirepo init cognirepo index-repo . cognirepo benchmark ``` -------------------------------- ### Run full setup again (cognirepo setup) Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md Run the full setup again to reconfigure MCP and other settings. ```bash cognirepo setup ``` -------------------------------- ### Install CogniRepo with pip inside a virtual environment Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Installation method for users who prefer pip within a virtual environment. The setup wizard installs optional extras (languages, security, providers). ```bash python -m venv .venv && source .venv/bin/activate pip install cognirepo # extras (languages, security, providers) are installed by the setup wizard ``` -------------------------------- ### cognirepo ask command examples Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Shows how to use the `cognirepo ask` command with different query types. The first two examples trigger QUICK (local) and EXPERT (Claude) tiers respectively, while the third uses `--verbose` to display tier, score, and signals. ```bash cognirepo ask "where is verify_token defined?" # → QUICK, answered locally ``` ```bash cognirepo ask "why is auth slow?" # → EXPERT, Claude with full context ``` ```bash cognirepo ask --verbose "explain the circuit breaker" # show tier/score/signals ``` -------------------------------- ### Docker MCP server startup Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Copies the environment template and starts the MCP stdio server via Docker Compose. Requires API keys in `.env`. ```bash cp .env.example .env # add your API keys docker compose up mcp # MCP stdio server ``` -------------------------------- ### Init Wizard and MCP Connector Setup Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/architecture/SPECIFICATION.md ASCII diagram of the `cognirepo init` interactive TTY wizard. Shows the 5-step powerlevel10k-style prompt, project scaffolding, and generation of config.json plus MCP connector files for Claude and Gemini. The wizard writes .claude/CLAUDE.md, .claude/settings.json, .gemini/COGNIREPO.md, and .gemini/settings.json. ```text cognirepo init (interactive TTY) │ ▼ cli/wizard.py — 5-step powerlevel10k-style prompt │ project name, encrypt, languages, MCP targets, org/project ▼ cli/init_project.py — scaffold dirs, write config.json │ ├── .cognirepo/config.json — project_name, model{provider/model}, │ storage.encrypt, storage.vector_backend, org, project ├── .claude/CLAUDE.md — project instructions (from STD_PROMPTS/claude_mcp.md) ├── .claude/settings.json — MCP connector: cognirepo- → cognirepo serve --project-dir ├── .gemini/COGNIREPO.md — Gemini instructions (from STD_PROMPTS/gemini_mcp.md) └── .gemini/settings.json — MCP connector: cognirepo- → cognirepo serve --project-dir ``` -------------------------------- ### Write Tests for the New Tool in tests/test_my_tools.py Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Add a test that imports the tool and verifies it returns a list for a sample query. ```python # tests/test_my_tools.py def test_my_new_tool_returns_list(): from interface.tools.my_tools import my_new_tool result = my_new_tool("test query") assert isinstance(result, list) ``` -------------------------------- ### Copy example MCP config Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Copies the example MCP configuration file to the active location for VS Code MCP support. ```bash cp .vscode/mcp.json.example .vscode/mcp.json ``` -------------------------------- ### CLI config file example Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI.md Example ~/.cognirepo/cli_config.toml showing UI, model, and session settings. ```toml [ui] color = true show_tier_label = true [model] prefer = "" # e.g. "claude-opus-4-6" to always use this model [session] persist = true max_exchanges = 20 ``` -------------------------------- ### Cursor / Copilot MCP configuration setup Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Exports the Cursor MCP config and copies it to `.cursor/mcp.json`. Restart Cursor to load the CogniRepo tools. ```bash cognirepo export-spec cp adapters/cursor_mcp_config.json .cursor/mcp.json # Restart Cursor — CogniRepo tools appear in the tool selector ``` -------------------------------- ### cognirepo org example commands Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md Example commands for the `cognirepo org` workflow: creating an organization named `my-team`, linking the current directory to it, listing organizations, and declaring a `CALLS_API` dependency edge between `./api` and `./auth`. These commands are used together to set up and inspect a local organization. ```bash cognirepo org create my-team cognirepo org link my-team . cognirepo org list cognirepo org link-repos ./api ./auth --type CALLS_API ``` -------------------------------- ### Create language_grammars/.py Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Create a Python module that defines the language object using the tree-sitter Language class. The example shows kotlin.py. ```python # language_grammars/kotlin.py from tree_sitter import Language import tree_sitter_kotlin KOTLIN_LANGUAGE = Language(tree_sitter_kotlin.language()) ``` -------------------------------- ### Full reset (nuclear option) Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md Wipes all CogniRepo state and starts fresh by removing .cognirepo/ and running setup. ```bash rm -rf .cognirepo/ cognirepo setup ``` -------------------------------- ### Install pipx on various platforms Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Commands to install pipx on Arch Linux, Debian/Ubuntu, macOS, or as a fallback using pip. Required before installing cognirepo with pipx. ```bash # Arch Linux sudo pacman -S python-pipx ``` ```bash # Debian / Ubuntu sudo apt install pipx ``` ```bash # macOS brew install pipx ``` ```bash # Any platform (fallback) pip install pipx --user ``` -------------------------------- ### Re-run cognirepo setup to add missing hooks Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Re-running `cognirepo setup` is idempotent and only adds missing hook entries. Use this if the setup was run before the hooks feature was added. ```bash cognirepo setup # re-run — idempotent, only adds missing entries ``` -------------------------------- ### Start the CogniRepo REPL Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI.md Launch the interactive REPL, optionally forcing a specific model for all queries with --model. ```bash cognirepo # start interactive REPL cognirepo --model claude-opus-4-6 # force a specific model for all queries ``` -------------------------------- ### Re-run MCP setup wizard (cognirepo mcp-setup) Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md Re-run the MCP setup wizard to configure MCP for the AI tool when tools are not visible. ```bash cognirepo mcp-setup # re-run MCP setup wizard ``` -------------------------------- ### Install from TestPyPI and run smoke test Source: https://github.com/ashlesh-t/cognirepo/blob/main/scripts/release_checklist.md Installs the RC from TestPyPI in a fresh venv and runs smoke tests including a CLI query. ```bash pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple cognirepo[cli] cognirepo --help cognirepo doctor echo "how do I install cognirepo" | cognirepo # should answer from docs index ``` -------------------------------- ### Install additional language grammars with cognirepo[languages] Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/architecture/SPECIFICATION.md Installs grammar packages for Python, JS, TS, Java, C#, Go, Rust, Ruby, C++, Swift, Kotlin, and PHP. Python indexing works without this via a stdlib ast fallback; other languages require their grammar package. ```bash pip install cognirepo[languages] # Python, JS, TS, Java, C#, Go, Rust, Ruby, C++, Swift, Kotlin, PHP ``` -------------------------------- ### Register the Tool in interface/server/mcp_server.py Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Register the tool with the MCP server by importing it and adding a `@server.call_tool()` handler. Also add the tool definition to `@server.list_tools()`. ```python from interface.tools.my_tools import my_new_tool @server.call_tool() async def handle_my_new_tool(name: str, arguments: dict) -> list[TextContent]: if name == "my_new_tool": result = my_new_tool(**arguments) return [TextContent(type="text", text=json.dumps(result))] ``` -------------------------------- ### Project Isolation: Multi-project / Multi-team Setup Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/architecture/SPECIFICATION.md ASCII diagram showing how separate teams open different project directories, each with their own .claude/settings.json MCP connector and `cognirepo serve --project-dir` process. Each AI tool connection is a separate OS process locked to one project directory, and data never crosses project boundaries. ```text Team A opens /projects/alpha/ Team B opens /projects/beta/ │ │ ├── .claude/settings.json ├── .claude/settings.json │ cognirepo-alpha │ cognirepo-beta │ --project-dir /projects/alpha --project-dir /projects/beta │ │ ▼ ▼ cognirepo serve cognirepo serve --project-dir /projects/alpha --project-dir /projects/beta │ │ ▼ ▼ /projects/alpha/.cognirepo/ /projects/beta/.cognirepo/ vector_db/ graph/ index/ vector_db/ graph/ index/ (alpha's memories only) (beta's memories only) ``` -------------------------------- ### Example Graph Queries using KnowledgeGraph Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/architecture/graph.md Shows how to query the knowledge graph for callers, symbols defined in a file, and co-edited files. Uses get_neighbours with specific edge types and directions. ```python from graph.knowledge_graph import KnowledgeGraph, EdgeType kg = KnowledgeGraph() # All callers of hybrid_retrieve callers = kg.get_neighbours("hybrid_retrieve", edge_types=[EdgeType.CALLED_BY], direction="out") # All symbols defined in retrieval/hybrid.py syms = kg.get_neighbours("FILE:retrieval/hybrid.py", edge_types=[EdgeType.DEFINED_IN], direction="in") # Files that co-occur with memory/semantic_memory.py coedits = kg.get_neighbours("memory/semantic_memory.py", edge_types=[EdgeType.CO_OCCURS], direction="out") ``` -------------------------------- ### Cognirepo CLI commands Source: https://github.com/ashlesh-t/cognirepo/blob/main/CLAUDE.md Lists all available cognirepo CLI commands with their purposes, including setup, init, indexing, memory operations, search, health check, benchmarking, and session priming. ```bash cognirepo setup # one-command onboarding (init + index + MCP config) cognirepo init # scaffold .cognirepo/ and config cognirepo index-repo [path] # AST-index a codebase cognirepo store-memory # save a semantic memory cognirepo retrieve-memory # similarity search cognirepo search-docs # search indexed docs cognirepo doctor # health check cognirepo benchmark # measure token reduction cognirepo prime # bootstrap session context (CLI version of get_session_brief) cognirepo org rewire # repair cross-service CALLS_API edges (run after indexing all services) ``` -------------------------------- ### Install fastembed and run pytest Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md Install fastembed in the same environment as pytest to fix collection failure caused by ASTIndexer importing get_model at module level. ```bash pip install fastembed pytest tests/ ``` -------------------------------- ### Install CogniRepo with pip Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/LANGUAGES.md Install CogniRepo for Python-only support or with all supported language grammars. The Python-only install requires no extras; the [languages] extra installs grammar packages for all other supported languages. ```bash pip install cognirepo # Python only (built-in, no extras needed) ``` ```bash pip install cognirepo[languages] # all supported languages ``` -------------------------------- ### Implement a New MCP Tool in interface/tools/my_tools.py Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Create or extend a file in `interface/tools/` with a plain Python function. All storage access must go through `interface/tools/`; tools must not call each other and must be stateless across calls. ```python # interface/tools/my_tools.py def my_new_tool(query: str, top_k: int = 5) -> list[dict]: """ Brief description of what this tool does. Args: query: Natural language query. top_k: Number of results. Returns: List of result dicts. """ # implement here — use FAISS, graph, or episodic as needed ... ``` -------------------------------- ### context_pack Input JSON Example Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/MCP_TOOLS.md Example input for the context_pack tool, specifying the query and max_tokens parameters. ```json { "query": "how does hybrid retrieval work", "max_tokens": 2000 } ``` -------------------------------- ### get_agent_bootstrap() Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Single-call session start that returns brief, last context, profile, and errors in one call (~300 tokens vs ~900). Preferred first call, replaces the 4-call sequence. ```APIDOC ## get_agent_bootstrap() ### Description Single-call session start that returns brief, last context, profile, and errors in one call (~300 tokens vs ~900). Preferred first call, replaces the 4-call sequence. ### Returns Bootstrap data containing session brief, last context, user profile, and error patterns. ``` -------------------------------- ### Example user profile output Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Shows the JSON structure returned by the profile access methods, including depth preference, question type distribution, terminology, code focus percentage, framing hints, and total queries tracked. ```json { "depth_preference": "detailed", "top_question_type": "how", "question_type_distribution": {"how": 12, "why": 8, "fix": 5}, "top_terminology": ["auth", "token", "session", "middleware", "validate"], "code_focus_percent": 73, "framing_hints": "prefers detailed responses; often asks 'how' questions; domain vocabulary: auth, token, session", "total_queries_tracked": 47 } ``` -------------------------------- ### Check installed language support with cognirepo doctor Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/LANGUAGES.md Run `cognirepo doctor --verbose` to display the list of supported languages. If `cognirepo[languages]` is not installed, only "Python (built-in)" is shown. ```bash cognirepo doctor --verbose # Shows: Language support — Python, JS, TS, Java, C#, Go, Rust, Ruby, C++, Swift, Kotlin, PHP # (or only "Python (built-in)" if cognirepo[languages] not installed) ``` -------------------------------- ### Install dev dependencies and run doctor (cognirepo doctor --verbose) Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md Install development dependencies and run the doctor with verbose output to diagnose missing dependencies causing MCP tool registration failures. ```bash pip install -e ".[dev]" cognirepo doctor --verbose ``` -------------------------------- ### Reproduce external repo validation table Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/METRICS.md Fully offline and automated; no API key needed. Installs the optional [languages] extra for non-Python repos, clones flask/fastapi/celery/ansible, then runs init, index-repo, and benchmark --json for each. Numbers vary slightly run-to-run but should land in the same range. ```bash pip install "cognirepo[languages]" # [languages] only needed for non-Python repos (moby, k8s) for repo in flask fastapi celery ansible; do git clone https://github.com/pallets/flask flask 2>/dev/null || true git clone https://github.com/fastapi/fastapi fastapi 2>/dev/null || true git clone https://github.com/celery/celery celery 2>/dev/null || true git clone https://github.com/ansible/ansible ansible 2>/dev/null || true done for repo in flask fastapi celery ansible; do (cd "$repo" && cognirepo init && cognirepo index-repo . --no-watch && cognirepo benchmark --json) done ``` -------------------------------- ### cognirepo serve command usage Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md Starts the MCP stdio server for Claude Desktop, Gemini CLI, or Cursor. Use --project-dir to lock the server to a specific project root. ```bash cognirepo serve [OPTIONS] ``` -------------------------------- ### context_pack delegation_hints JSON Example Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/MCP_TOOLS.md Example of the optional delegation_hints field, present only when the packed code spans at least two structurally-independent groups. It is counted last against max_tokens and dropped first on overflow. ```json { "delegation_hints": [ { "group": "g0", "files": ["retrieval/hybrid.py"], "reason": "no shared import/call path", "todos": [{"file": "retrieval/hybrid.py", "line": 88, "text": "# TODO: cache this"}] }, {"group": "g1", "files": ["cli/daemon.py"], "reason": "no shared import/call path"} ] } ``` -------------------------------- ### Re-run MCP integration setup Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md Run `cognirepo mcp-setup [OPTIONS]` to re-run MCP integration for Claude Code / Gemini CLI / Cursor / VS Code without repeating the full `cognirepo init` wizard. Options include `--target {claude,gemini,cursor,vscode}` (repeatable, default `claude`) and `--global` (default `False`). ```bash cognirepo mcp-setup [OPTIONS] ``` -------------------------------- ### Run CogniRepo MCP server with Docker Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Copy the environment file, fill in API keys, and start the pure MCP server via stdio using Docker Compose. ```bash cp .env.example .env # fill in API keys docker compose up mcp # Pure MCP server via stdio ``` -------------------------------- ### context_pack Output JSON Example Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/MCP_TOOLS.md Example output from context_pack, showing status, token_count, sections, and truncated fields. The status field can be "ok", "no_confident_match", or "index_empty". ```json { "query": "how does hybrid retrieval work", "status": "ok", "token_count": 1840, "sections": [ {"type": "code", "source": "retrieval/hybrid.py", "score": 0.91, "content": "...", "bucket": "HIGH"} ], "truncated": false } ``` -------------------------------- ### config.json full configuration example Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CONFIGURATION.md Complete configuration file for CogniRepo, read from `.cognirepo/config.json` in the project root. Defines project name, port, storage settings, model tiers, retrieval weights, idle TTL, episodic event limit, indexing options, and behaviour decay. The `models` section uses a four-tier registry (QUICK, STANDARD, COMPLEX, EXPERT) with provider and model names. ```json { "project_name": "my-project", "port": 8000, "storage": { "encrypt": false, "vector_backend": "chroma" }, "models": { "QUICK": {"provider": "local", "model": "local-resolver"}, "STANDARD": {"provider": "anthropic", "model": "claude-haiku-4-5"}, "COMPLEX": {"provider": "anthropic", "model": "claude-sonnet-4-6"}, "EXPERT": {"provider": "anthropic", "model": "claude-opus-4-6"} }, "retrieval_weights": { "vector": 0.5, "graph": 0.3, "behaviour": 0.2 }, "idle_ttl_seconds": 600, "episodic_max_events": 10000, "indexing": { "skip_dirs": [], "unskip_dirs": [], "debounce_ms": 500 }, "behaviour_decay": { "half_life_days": 30 } } ``` -------------------------------- ### get_session_brief(repo_path: str = None) → dict Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/MCP_TOOLS.md Returns an architecture summary, hot symbols, index health, and recent decisions. This should always be called at the start of a session. ```APIDOC ## get_session_brief(repo_path: str = None) → dict ### Description Returns an architecture summary, hot symbols, index health, and recent decisions. This should always be called at the start of a session. ### Method get_session_brief ### Parameters #### Input Parameters - **repo_path** (str) - Optional - The repository path to get the brief for. ### Response #### Success Response - **architecture** (str) - Architecture summary. - **hot_symbols** (array) - List of hot symbols. - **index_health** (object) - Index health information. - **recent_decisions** (array) - List of recent decisions. #### Response Example {"architecture": "...", "hot_symbols": [...], "index_health": {...}, "recent_decisions": [...]} ``` -------------------------------- ### CMake configuration for building _bm25_ext with pybind11 Source: https://github.com/ashlesh-t/cognirepo/blob/main/core/_bm25/CMakeLists.txt CMakeLists.txt for the cognirepo BM25 C++ extension. BUILD_EXT defaults to OFF so a plain pip install never requires cmake; enable it with the documented cmake commands. Requires pybind11 (provided by scikit-build-core/pip) and builds the _bm25_ext module from bm25.cpp and bindings.cpp. Applies optimization flags in Release mode and installs the compiled library to the repo root. ```cmake cmake_minimum_required(VERSION 3.18) project(cognirepo_bm25 CXX) # ── guard ───────────────────────────────────────────────────────────────────── # Default OFF so that a plain pip install cognirepo never needs cmake. # Enable with: # cmake -S cognirepo/_bm25 -B build/bm25 -DBUILD_EXT=ON # cmake --build build/bm25 --target _bm25_ext option(BUILD_EXT "Build the C++ pybind11 extension (_bm25_ext)" OFF) if(NOT BUILD_EXT) message(STATUS "[cognirepo] BUILD_EXT=OFF — skipping C++ BM25 extension.") message(STATUS " To compile: cmake ... -DBUILD_EXT=ON") return() endif() # ── C++ standard ────────────────────────────────────────────────────────────── set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # ── pybind11 ────────────────────────────────────────────────────────────────── # scikit-build-core / pip provides pybind11 when listed in [build-system].requires find_package(pybind11 REQUIRED) # ── target ──────────────────────────────────────────────────────────────────── pybind11_add_module(_bm25_ext bm25.cpp bindings.cpp ) target_include_directories(_bm25_ext PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) # Optimisation flags (release mode) if(CMAKE_BUILD_TYPE STREQUAL "Release") target_compile_options(_bm25_ext PRIVATE $<$:-O3 -march=native> $<$:/O2> ) endif() # ── install ─────────────────────────────────────────────────────────────────── # Place the compiled .so next to the _bm25 Python package so the import # in __init__.py can find it as a top-level module. install(TARGETS _bm25_ext LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/../../ # repo root RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/../../ ) ``` -------------------------------- ### Add to LANGUAGE_DISPLAY Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Add an entry to the LANGUAGE_DISPLAY dict in interface/cli/main.py with the package name and install command. ```python LANGUAGE_DISPLAY = { ... "kotlin": ("tree-sitter-kotlin", "pip install tree-sitter-kotlin"), } ``` -------------------------------- ### Example output of get_error_patterns Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Shows the JSON structure returned by get_error_patterns, including error_type, count, files, last_seen, prevention_hint, and recent_context. ```json [ { "error_type": "TypeError", "count": 7, "files": ["config/parser.py", "api/handlers.py"], "last_seen": "2026-04-22T10:30:00Z", "prevention_hint": "Wrong type — validate inputs at function boundary.", "recent_context": "expected str got int in parse_config" } ] ``` -------------------------------- ### Add loader function Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Define a loader function that imports and returns the language object. The example shows _load_kotlin. ```python def _load_kotlin(): from language_grammars.kotlin import KOTLIN_LANGUAGE # noqa: F401 return KOTLIN_LANGUAGE ``` -------------------------------- ### Enable systemd user unit for CogniRepo watcher Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CONFIGURATION.md Generate the systemd unit via cognirepo init or manually enable and start the user service. The unit runs 'cognirepo watch --path --foreground' and logs to stderr. ```bash cognirepo init # answer "y" to systemd prompt # or systemctl --user enable ~/.config/systemd/user/cognirepo-watcher.service systemctl --user start cognirepo-watcher ``` -------------------------------- ### Install git post-commit hook: cognirepo install-hooks Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md Writes the git post-commit hook that runs `cognirepo index-repo --files --no-watch --no-embed` in the background after each commit. Idempotent; replaces an outdated cognirepo block in place and preserves your own hook lines. The extension filter is generated from the language registry, so re-run after upgrading. Output and run outcome go to `.cognirepo/hook.log` and `.cognirepo/hook.last`; `cognirepo doctor` warns about failed runs or outdated blocks. Exits `1` outside a git repository. ```bash cognirepo install-hooks ``` -------------------------------- ### cognirepo watch command syntax Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md Shows the CLI syntax for the watch command, which manages the background file-watcher. Use --status to check daemon status, --ensure-running to start it if not running or heartbeat is stale, --foreground to run under a crash guard (as generated systemd/launchd units do), and --path to set the repo root. Only one watcher runs per repo; other processes stand by or print the holder. ```bash cognirepo watch [--status | --ensure-running | --foreground] [--path DIR] ``` -------------------------------- ### Add subparser for new CLI command Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Add a subparser for a new CLI command in interface/cli/main.py. The example shows 'mycommand' with an --option argument. ```python p_mycommand = sub.add_parser("mycommand", help="What it does") p_mycommand.add_argument("--option", default="default", help="...") ``` -------------------------------- ### Add extension mapping in _GRAMMAR_MAP Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/LANGUAGES.md Add a new file extension to the `_GRAMMAR_MAP` dict in `indexer/language_registry.py` to map it to the corresponding tree-sitter grammar package. ```python ".ext": "tree_sitter_", ``` -------------------------------- ### Access user profile via MCP tool and CLI Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md Use get_user_profile() as an MCP tool that Claude calls automatically at session start, or run the cognirepo user-prefs CLI command to access the user profile. ```bash # MCP tool (Claude calls automatically at session start): get_user_profile() # CLI: cognirepo user-prefs ``` -------------------------------- ### Enable encryption with cognirepo[security] Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CONFIGURATION.md Install the security extra and re-run cognirepo init to generate and store the AES-256 GCM key in the OS keychain. Requires storage.encrypt: true in .cognirepo/config.json. ```bash pip install cognirepo[security] # Edit .cognirepo/config.json: # "storage": { "encrypt": true } cognirepo init # re-run to generate and store the key ``` -------------------------------- ### Run cognirepo commands Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md One-command onboarding and step-by-step commands for initialization, indexing, hooks, status checks, queries, and watcher management. Indexing must complete before MCP tools return data. ```bash # One-command onboarding (init + index + auto-configure MCP for Claude/Cursor/VS Code): cognirepo setup ``` ```bash # Or step by step: cognirepo init --no-index # scaffold .cognirepo/ cognirepo index-repo . # index your codebase (required before MCP tools work) cognirepo index-repo . --daemon # index and run watcher in background ``` ```bash # Keep the index fresh after every commit (indexes just the changed files, in the background): cognirepo install-hooks ``` ```bash # Check everything is working: cognirepo status # shows symbol count, graph nodes, signal warmth cognirepo doctor # full health check (exit 0 healthy / 1 warnings / 2 errors) cognirepo doctor --resources # where memory and disk go: processes, store sizes, leftovers ``` ```bash # Query through multi-model orchestrator: cognirepo ask "why is auth slow?" ``` ```bash # Manage background watchers (one per repo, however many sessions run): cognirepo watch --ensure-running # start it if it is not running cognirepo list # show all running watcher daemons cognirepo list -n --view # tail the log of a specific watcher cognirepo list -n --stop # stop a watcher ``` -------------------------------- ### Fix missing keyring/cryptography for encrypted storage Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md When storage.encrypt is true, every interpreter touching .cognirepo/ needs keyring and cryptography. This injects them into the pipx environment (or installs the security extra) and runs cognirepo doctor to flag missing packages. ```bash pipx inject cognirepo keyring cryptography # or: pip install 'cognirepo[security]' cognirepo doctor # flags the missing packages ``` -------------------------------- ### cognirepo index-repo - index codebase Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Walks a codebase, extracts AST symbols (functions, classes), embeds them, and stores in FAISS + knowledge graph. Use --daemon to run the file watcher in the background, and --no-watch for CI. Indexes all supported file types automatically; install cognirepo[languages] for extended language support. ```bash cognirepo index-repo . cognirepo index-repo /path/to/other/project # Run the file watcher in the background (returns immediately): cognirepo index-repo . --daemon # Index only, no watcher (useful in CI): cognirepo index-repo . --no-watch ``` -------------------------------- ### Session bootstrap with cognirepo prime Source: https://github.com/ashlesh-t/cognirepo/blob/main/STD_PROMPTS/claude_mcp.md Bootstrap a session with the repository memory. ```bash cognirepo prime ``` -------------------------------- ### Add handler in main() Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Add a handler in main() that calls the command's run function when the command is invoked. ```python if args.command == "mycommand": from cli.mycommand import run_mycommand run_mycommand(args.option) return ``` -------------------------------- ### get_agent_bootstrap(repo_path: str = None) → dict Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/MCP_TOOLS.md Call once at session start to retrieve a consolidated agent bootstrap payload, replacing the previous 4-call sequence. Returns ~300 tokens of context including repo architecture, hot symbols, recent focus, framing, mood, error patterns, index health, recent timeline, decision nudges, and consolidation candidates. ```APIDOC ## get_agent_bootstrap(repo_path: str = None) → dict ### Description Call ONCE at session start instead of the 4-call sequence (get_session_brief → get_last_context → get_user_profile → get_error_patterns). Returns ~300 tokens vs ~900 tokens. ### Signature `get_agent_bootstrap(repo_path: str = None) → dict` ### Parameters - **repo_path** (str) - Optional - Path to the repository. Defaults to None. ### Input Example ```json {} ``` ### Output Example ```json { "repo": "cognirepo", "architecture": "CogniRepo: FAISS + graph + AST + MCP. Tools in tools/, retrieval via retrieval/hybrid.py...", "hot_symbols": ["hybrid_retrieve:retrieval/hybrid.py:45", "context_pack:tools/context_pack.py:12"], "last_focus": {"files": ["retrieval/hybrid.py"], "query": "how does scoring work", "agent": "claude"}, "framing": {"depth": "detailed", "vocabulary": ["retrieval", "faiss", "hybrid"], "hints": "prefers detailed responses; often asks 'how' questions; domain vocabulary: retrieval, faiss, hybrid"}, "mood": {"state": "neutral", "evidence": [], "suggested_adaptation": ""}, "error_patterns": [{"type": "OOM", "count": 2, "prevention_hint": "Check RSS before loading large index"}], "index_health": {"symbols": 1240, "files": 92, "status": "ok"}, "recent_timeline": [ {"ts": "2026-08-08T09:00:00+00:00", "kind": "decision", "summary": "use FAISS for vector search", "ref": "e_42"}, {"ts": "2026-08-07T14:00:00+00:00", "kind": "error", "summary": "ImportError (x3)", "ref": "ImportError"}, {"ts": "2026-08-06T11:00:00+00:00", "kind": "session", "summary": "how does scoring work", "ref": "sess_abc123"} ], "decision_nudge": "2 recurring topic(s) never promoted to a decision — see consolidation_candidates", "consolidation_candidates": [ { "group_summary": "cache invalidation keeps breaking on concurrent writes", "episode_ids": ["e_101", "e_107", "e_115"], "suggested_decision_draft": "record_decision(summary=..., rationale=...) — recurring pattern seen 3x: cache invalidation keeps breaking on concurrent writes" } ] } ``` ### Notes - **recent_timeline** (COGNIREPO-204): last 5 entries from the past 7 days, merged chronologically across sessions, episodes, decisions, and errors — replaces the `get_session_history` + `episodic_search` + `get_error_patterns` 3-call stitch. For the full query surface (`since`/`include_archived`/`limit`, plus the deterministic `rollup()`), call `data.memory.timeline.merge()`/`rollup()` directly, or use the `generate_insights` tool (COGNIREPO-303). - **decision_nudge** (COGNIREPO-205): present only when the last 30 days have ≥5 episodes but 0 decisions — a hint to use `record_decision`. Omitted entirely when there's nothing to nudge about. - **consolidation_candidates** (COGNIREPO-702): computed alongside `decision_nudge` when that gap is detected — clusters recurring/near-duplicate episodic events (≥3 within 30 days, same topic, reused BM25 similarity from `search_episodes()`) that were never promoted to a decision. Each candidate cites the actual `episode_ids` as evidence and a `suggested_decision_draft`; **never calls `record_decision` automatically** — promotion stays a human/agent judgment call. Omitted entirely when there's nothing to consolidate. - **Episodic events also include `index_event`-typed entries** (COGNIREPO-205): `cognirepo index-repo` and `cognirepo org rewire` completions are logged automatically (metadata `{"type": "index_event", ...}` with symbol/file or edge/repo counts), so infrastructure activity shows up in `recent_timeline` / `data.memory.timeline.merge()` even when no agent called `log_episode`. ``` -------------------------------- ### Manage file watcher with cognirepo watch and list Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Commands to start, check status, and list watchers. One background watcher per repo; `cognirepo serve` also runs a watcher thread but only the first session holds the lease. Set COGNIREPO_NO_WATCHER=1 to disable. ```bash cognirepo watch --ensure-running # start it if it is not running (a separate ~100 MB process) ``` ```bash cognirepo watch --status # PID, heartbeat age, last reindex ``` ```bash cognirepo list # all watchers; `cognirepo list -n --stop` stops one ``` -------------------------------- ### Register in LANGUAGE_MAP Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/DEVELOPER_GUIDE.md Add entries to the LANGUAGE_MAP dict in ast_indexer.py to map file extensions to language and loader function. ```python LANGUAGE_MAP = { ... ".kt": ("kotlin", _load_kotlin), ".kts": ("kotlin", _load_kotlin), } ``` -------------------------------- ### cognirepo setup-env command Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/CLI_REFERENCE.md Interactive wizard to set and verify model-provider API keys. Use --skip-verify to write keys without the API verification call (useful in CI with real keys), or --non-interactive to skip the wizard entirely for scripted environments. ```bash cognirepo setup-env [OPTIONS] ``` -------------------------------- ### cognirepo init - interactive wizard and options Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/USAGE.md Scaffolds the .cognirepo/ directory structure and writes config.json. Interactive mode launches a wizard asking for project name, model routing, encryption, language parsers, and MCP integration. Use --no-index to skip automatic post-init indexing, --non-interactive to skip the wizard, and --daemon to run the file watcher in the background. Safe to re-run; only backfills missing keys. ```bash cognirepo init # interactive wizard (default when TTY) cognirepo init --no-index # skip automatic post-init indexing cognirepo init --non-interactive # skip wizard entirely (uses defaults) cognirepo init --daemon # run post-init file watcher in background ``` -------------------------------- ### Get session history via MCP tool get_session_history Source: https://github.com/ashlesh-t/cognirepo/blob/main/README.md MCP tool that Claude calls at session start to resume context. Accepts a limit parameter (e.g., 5) and returns session details. ```python get_session_history(limit=5) ``` -------------------------------- ### Run CogniRepo benchmark commands Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/METRICS.md Run the benchmark on your own codebase. Use --compare for delta vs last run and --json for machine-readable output suitable for CI. ```bash cognirepo benchmark # full report cognirepo benchmark --compare # delta vs last run cognirepo benchmark --json # machine-readable for CI ``` -------------------------------- ### Run full test suite at HEAD Source: https://github.com/ashlesh-t/cognirepo/blob/main/JIRA/EPIC-ReliabilityGate-100/COGNIREPO-100-Discovery.md Executes the entire test suite from the repository root using the virtual environment's Python interpreter. The command reports 1203 passed, 5 skipped, and 0 failed in 100.42 seconds. ```bash venv/bin/python -m pytest tests/ -q ``` -------------------------------- ### Fix fastembed in venv Source: https://github.com/ashlesh-t/cognirepo/blob/main/docs/TROUBLESHOOTING.md Activate the virtual environment and install fastembed to resolve ModuleNotFoundError when installed into the wrong Python environment. ```bash source venv/bin/activate pip install fastembed ```