robo-cortex 0.4.0__tar.gz

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 (85) hide show
  1. robo_cortex-0.4.0/.gitignore +16 -0
  2. robo_cortex-0.4.0/CHANGELOG.md +93 -0
  3. robo_cortex-0.4.0/LICENSE +21 -0
  4. robo_cortex-0.4.0/PKG-INFO +367 -0
  5. robo_cortex-0.4.0/README.md +338 -0
  6. robo_cortex-0.4.0/pyproject.toml +67 -0
  7. robo_cortex-0.4.0/schema.sql +111 -0
  8. robo_cortex-0.4.0/src/robo_cortex/__init__.py +5 -0
  9. robo_cortex-0.4.0/src/robo_cortex/cli/__init__.py +5 -0
  10. robo_cortex-0.4.0/src/robo_cortex/cli/__main__.py +6 -0
  11. robo_cortex-0.4.0/src/robo_cortex/cli/_common.py +72 -0
  12. robo_cortex-0.4.0/src/robo_cortex/cli/_output.py +76 -0
  13. robo_cortex-0.4.0/src/robo_cortex/cli/app.py +74 -0
  14. robo_cortex-0.4.0/src/robo_cortex/cli/commands/__init__.py +36 -0
  15. robo_cortex-0.4.0/src/robo_cortex/cli/commands/affected.py +40 -0
  16. robo_cortex-0.4.0/src/robo_cortex/cli/commands/completion.py +94 -0
  17. robo_cortex-0.4.0/src/robo_cortex/cli/commands/evidence.py +110 -0
  18. robo_cortex-0.4.0/src/robo_cortex/cli/commands/hooks.py +149 -0
  19. robo_cortex-0.4.0/src/robo_cortex/cli/commands/init.py +76 -0
  20. robo_cortex-0.4.0/src/robo_cortex/cli/commands/link.py +47 -0
  21. robo_cortex-0.4.0/src/robo_cortex/cli/commands/list_cmd.py +57 -0
  22. robo_cortex-0.4.0/src/robo_cortex/cli/commands/mcp.py +37 -0
  23. robo_cortex-0.4.0/src/robo_cortex/cli/commands/record.py +156 -0
  24. robo_cortex-0.4.0/src/robo_cortex/cli/commands/retrieve.py +88 -0
  25. robo_cortex-0.4.0/src/robo_cortex/cli/commands/search.py +48 -0
  26. robo_cortex-0.4.0/src/robo_cortex/cli/commands/show.py +62 -0
  27. robo_cortex-0.4.0/src/robo_cortex/cli/commands/status.py +83 -0
  28. robo_cortex-0.4.0/src/robo_cortex/cli/commands/transfer.py +140 -0
  29. robo_cortex-0.4.0/src/robo_cortex/core/__init__.py +0 -0
  30. robo_cortex-0.4.0/src/robo_cortex/core/assumptions.py +39 -0
  31. robo_cortex-0.4.0/src/robo_cortex/core/db.py +67 -0
  32. robo_cortex-0.4.0/src/robo_cortex/core/errors.py +32 -0
  33. robo_cortex-0.4.0/src/robo_cortex/core/evidence.py +166 -0
  34. robo_cortex-0.4.0/src/robo_cortex/core/git.py +162 -0
  35. robo_cortex-0.4.0/src/robo_cortex/core/hooks.py +214 -0
  36. robo_cortex-0.4.0/src/robo_cortex/core/init.py +75 -0
  37. robo_cortex-0.4.0/src/robo_cortex/core/invalidate.py +436 -0
  38. robo_cortex-0.4.0/src/robo_cortex/core/lifecycle.py +165 -0
  39. robo_cortex-0.4.0/src/robo_cortex/core/memory.py +394 -0
  40. robo_cortex-0.4.0/src/robo_cortex/core/retrieve.py +429 -0
  41. robo_cortex-0.4.0/src/robo_cortex/core/semantic.py +48 -0
  42. robo_cortex-0.4.0/src/robo_cortex/core/store.py +72 -0
  43. robo_cortex-0.4.0/src/robo_cortex/core/text.py +27 -0
  44. robo_cortex-0.4.0/src/robo_cortex/core/transfer.py +246 -0
  45. robo_cortex-0.4.0/src/robo_cortex/gitea.py +140 -0
  46. robo_cortex-0.4.0/src/robo_cortex/mcp_server.py +263 -0
  47. robo_cortex-0.4.0/src/robo_cortex/migrations/0001_init.sql +101 -0
  48. robo_cortex-0.4.0/src/robo_cortex/migrations/0002_add_usage_tracking.sql +2 -0
  49. robo_cortex-0.4.0/src/robo_cortex/migrations/0003_add_meta_table.sql +4 -0
  50. robo_cortex-0.4.0/src/robo_cortex/sdk.py +196 -0
  51. robo_cortex-0.4.0/tests/__init__.py +0 -0
  52. robo_cortex-0.4.0/tests/conftest.py +11 -0
  53. robo_cortex-0.4.0/tests/fixtures.py +121 -0
  54. robo_cortex-0.4.0/tests/test_add_path.py +95 -0
  55. robo_cortex-0.4.0/tests/test_affected.py +121 -0
  56. robo_cortex-0.4.0/tests/test_assumptions.py +61 -0
  57. robo_cortex-0.4.0/tests/test_cli_affected.py +71 -0
  58. robo_cortex-0.4.0/tests/test_cli_init.py +110 -0
  59. robo_cortex-0.4.0/tests/test_cli_lifecycle.py +242 -0
  60. robo_cortex-0.4.0/tests/test_cli_record.py +128 -0
  61. robo_cortex-0.4.0/tests/test_cli_retrieve.py +59 -0
  62. robo_cortex-0.4.0/tests/test_cli_scope_b.py +161 -0
  63. robo_cortex-0.4.0/tests/test_completion.py +95 -0
  64. robo_cortex-0.4.0/tests/test_curation.py +124 -0
  65. robo_cortex-0.4.0/tests/test_db.py +78 -0
  66. robo_cortex-0.4.0/tests/test_evidence.py +133 -0
  67. robo_cortex-0.4.0/tests/test_gitea.py +168 -0
  68. robo_cortex-0.4.0/tests/test_hooks.py +352 -0
  69. robo_cortex-0.4.0/tests/test_init.py +79 -0
  70. robo_cortex-0.4.0/tests/test_invalidate.py +427 -0
  71. robo_cortex-0.4.0/tests/test_lifecycle.py +189 -0
  72. robo_cortex-0.4.0/tests/test_mcp_contracts.py +331 -0
  73. robo_cortex-0.4.0/tests/test_mcp_stdio.py +88 -0
  74. robo_cortex-0.4.0/tests/test_memory.py +138 -0
  75. robo_cortex-0.4.0/tests/test_output.py +75 -0
  76. robo_cortex-0.4.0/tests/test_record_batch.py +109 -0
  77. robo_cortex-0.4.0/tests/test_retrieve.py +276 -0
  78. robo_cortex-0.4.0/tests/test_reverify.py +151 -0
  79. robo_cortex-0.4.0/tests/test_scope_b.py +271 -0
  80. robo_cortex-0.4.0/tests/test_sdk.py +171 -0
  81. robo_cortex-0.4.0/tests/test_search.py +70 -0
  82. robo_cortex-0.4.0/tests/test_semantic.py +68 -0
  83. robo_cortex-0.4.0/tests/test_smoke.py +5 -0
  84. robo_cortex-0.4.0/tests/test_transfer.py +381 -0
  85. robo_cortex-0.4.0/tests/test_update_path.py +69 -0
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .eggs/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+ .pytest_cache/
10
+ .coverage
11
+ htmlcov/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ .cortex/
15
+ .claude/
16
+ .commandcode/
@@ -0,0 +1,93 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. Format loosely follows [Keep a Changelog](https://keepachangelog.com/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.4.0] — 2026-07-15
8
+
9
+ First public PyPI release. All changes below were already complete in the unpublished `0.3.1` local build — this version bump exists solely to mark the public debut, not to introduce new behavior.
10
+
11
+ ## [0.3.1] — 2026-07-15
12
+
13
+ Fixes driven by a second internal self-audit, done before the first PyPI publish, plus a round of follow-ups from an independent Ubuntu evaluation. Still unpublished — `0.3.0` never shipped to PyPI, so this is a local version bump only, to make a freshly-built checkout distinguishable when testing.
14
+
15
+ ### Fixed
16
+
17
+ - **`git hash-object`** crashed on any linked path whose name starts with `-` (interpreted as a flag) — every `affected` call, and therefore the pre-commit hook, would fail on such a file. Fixed with a `--` separator; `affected` also now looks up linked memories *before* hashing touched paths, and batches remaining hashes through a single `git hash-object --stdin-paths` call instead of one subprocess per file.
18
+ - **Pre-commit hook** bound the first `roco`/`robo-cortex` found on `PATH` at install time without checking it was actually robo-cortex — a name collision with an unrelated `roco` package (see README's PyPI name-collision note), or the bound binary later disappearing (venv removed, `pipx uninstall`), silently broke every future commit. Install now verifies the candidate binary with `--version` before binding it; the installed hook itself checks the binary still exists at commit time and fails open (with a clear stderr message and the bypass instructions) instead of blocking every commit with a bare "not found."
19
+ - **`retrieve`/`search`/`affected`** crashed with a raw `sqlite3.OperationalError: attempt to write a readonly database` on a read-only `.cortex/memory.db` (read-only checkouts, some CI setups) — these are read paths that also do incidental writes (staleness refresh, usage tracking). They now degrade gracefully: writes are skipped, the read still returns its result, and a `warnings` entry in `meta` says so.
20
+ - **`ROBO_CORTEX_GITEA_TOKEN`** was sent to any configured Gitea URL regardless of scheme. `http://` URLs (except localhost) now refuse to send the token and degrade evidence to `unverifiable: gitea_insecure_url`, unless `ROBO_CORTEX_GITEA_ALLOW_HTTP=1` is set.
21
+ - **Comment-only and whitespace-only Python edits** spuriously flipped linked memories to `needs_review` (EVALUATION.md §8 measured a 100% rate on its sample). `.py` paths now get a token-stream equivalence check (stdlib `tokenize`, comments and blank lines ignored, indentation still significant) before falling back to the exact-hash flag; a cosmetic-only change silently re-anchors the stored blob hash instead of flagging. See EVALUATION.md §8a for the re-measured rate and ARCHITECTURE.md §5.3.1 for the mechanism. Any tokenization failure (syntax error, non-UTF8 content) still falls back to the original flag-on-any-change behavior — fail-safe, not fail-silent.
22
+ - **`record --path <not-yet-committed-file>`** error message now names the actual remedies (commit the file first, or record without `--path` and attach it later with `--add-path`) instead of just stating the refusal.
23
+
24
+ ### Added
25
+
26
+ - **`ROBO_CORTEX_NO_GLOBAL`**: opt out of the cross-project global store entirely (CLI and MCP both skip opening `~/.cortex/global.db`) — for anyone who wants `retrieve`/`search` scoped strictly to the current repo, with no implicit cross-project channel.
27
+ - **`roco record <id> --add-path <path>`**: attach a path to a memory after the fact. `--update-path` only relinked a path already attached; there was no way to attach one to a memory that had none — the workaround (record without `--path`, commit the file, attach it) was blocked. Closes the gap; found during an independent Ubuntu evaluation.
28
+ - **`roco init --global`**: explicitly create/open the scope-B store (`~/.cortex/global.db`) instead of leaving it to be created implicitly by the first `record --scope global` call.
29
+ - **`roco completion bash`**: static, zero-dependency shell completion, generated by introspecting the real argparse tree. Completes subcommand names and each subcommand's own flags; nested sub-subcommands (`hooks install`, `evidence add`) and flag values aren't completed yet (documented KISS limit).
30
+ - **Colored status output**: `list`/`show`/`retrieve` color-code memory status (green=active, yellow=provisional/needs_review, red=terminal statuses) on an interactive terminal. Respects `NO_COLOR`; `--json` output is unaffected.
31
+ - **`roco hooks install --post-commit`**: optional, informational-only hook (runs `affected --diff-range HEAD~1..HEAD` after each commit, never blocks) — `--post-commit` also works with `uninstall`/`status`, independently of the pre-commit hook.
32
+
33
+ ### Performance
34
+
35
+ - `refresh_staleness` now caches the last-checked HEAD SHA (`meta` table, migration `0003`) and skips the `git ls-tree -r HEAD` walk entirely when HEAD hasn't moved since the last call — the common case for consecutive `retrieve`/`search` calls between commits.
36
+ - FTS candidate scoring is now capped (`FTS_CANDIDATE_LIMIT = 200`, ordered by relevance) — bounds the per-candidate `get_memory` cost on stores with a very large number of matching memories.
37
+
38
+ ## [0.3.0] — 2026-07-14
39
+
40
+ Release-readiness pass, driven by a critical internal self-audit done before the first public release. Every change below fixes something the audit found; nothing here is speculative.
41
+
42
+ ### Fixed
43
+
44
+ - **`roco import --repo <path>`** (repo-scoped memories) crashed with `AttributeError: 'tuple' object has no attribute 'execute'`. The connection-selection logic was rewritten so the two stores (repo, global) are passed as two explicit connection factories instead of one scope-keyed selector — the class of bug is now structurally impossible, not just fixed once.
45
+ - **`roco import`** with a JSONL line missing `created_at`/`last_verified_at` crashed with a raw `sqlite3.IntegrityError`. Missing timestamps now default sensibly.
46
+ - **`roco import`** bypassed all of `record`'s validation — a `scope=global` line with no `assumptions`, or an invalid `type`/`confidence`, was either silently inserted or crashed on a raw `CHECK` constraint. Import now runs every line through the same validator `record` uses; invalid lines are skipped with a clear warning.
47
+ - **`retrieve`/`search`/`affected`** on a git repository with zero commits crashed with a raw `subprocess.CalledProcessError` (exit 128 from `git ls-tree HEAD`). Now raises a clear "this repository has no commits yet" error; `roco init` also warns proactively at init time.
48
+ - **`roco merge`** with a missing input file printed a raw Python traceback. `cli/app.py`'s `main()` now has a last-resort handler: any exception not already a clean `RoboCortexError` prints a one-line message instead of a stack trace (`ROBO_CORTEX_DEBUG=1` still gets the full traceback when you want it).
49
+ - **`roco merge`**'s conflict messages didn't match the format documented in `EXPORT_IMPORT.md`. Aligned (`"picked high over medium"`, `"confidence tie, picked new"`).
50
+ - **`--type` help text** in `roco record --help` listed `bug` and `insight` as example types — neither was ever a valid `--type` value.
51
+
52
+ ### Changed — Python SDK rewritten (breaking)
53
+
54
+ The pre-0.3.0 SDK (`robo_cortex.sdk`) was a subprocess wrapper around the CLI that didn't actually work: `search()` sent its argument in the wrong shape, `record()` had no `assumptions` parameter so `scope="global"` was unreachable, and every exception was swallowed into an `{"error": ...}` dict nothing checked for.
55
+
56
+ It's rewritten from scratch to call `robo_cortex.core` directly — the same pattern the MCP server already used — with no subprocess involved:
57
+ - `RoboCortex.retrieve/record/search/list_memories/get_memory` call core functions in-process.
58
+ - `record()` gained the missing `assumptions` parameter.
59
+ - Real exceptions (`RoboCortexError` subclasses) now propagate to the caller.
60
+
61
+ This is a breaking change to the SDK's error-handling contract, accepted deliberately: the old SDK had no working callers to protect. See [PYTHON_SDK.md](PYTHON_SDK.md).
62
+
63
+ ### Added — real enforcement: `roco hooks`
64
+
65
+ Earlier README drafts described three enforcement layers (git hooks, a code decorator, a CI/CD gate) before any of them existed in code. The first one now exists for real:
66
+
67
+ - `roco hooks install` writes a pre-commit hook that blocks a commit touching paths linked to a non-terminal memory, with a clear review prompt. `roco hooks uninstall` / `roco hooks status` complete the set.
68
+ - A pre-existing, non-robo-cortex pre-commit hook is never silently overwritten — install refuses without `--force`, and `--force` chains the existing hook rather than replacing it.
69
+ - The bypass (`git commit --no-verify`) is explicit and documented, not hidden.
70
+ - The code decorator and a first-class CI-gate subcommand are **not** built yet — see `ROADMAP.md`'s "Enforcement layers not yet built" for why, and [docs/ci-example.yml](docs/ci-example.yml) for a copy-paste GitHub Actions job covering the CI use case today with the existing `roco affected` command.
71
+
72
+ ### Changed — documentation
73
+
74
+ - **README.md** rewritten around the differentiators the project actually has (git-aware staleness detection, evidence-based confidence, zero dependencies, lifecycle audit trail) instead of the three fictional enforcement layers, an unrelated `urlshort` reference, and an unqualified "It can't [forget]" claim. Cites the real, modest token-savings numbers from `EVALUATION.md` (2.7–10.6%) instead of an invented "~1,500 tokens saved" figure.
75
+ - Every command in the README's Quick Start was run by hand, in sequence, on a clean repository before being written down (including catching that the *previous* README's own Quick Start commands didn't pass `--assumptions`/`--confidence` and would have failed validation).
76
+ - **PYTHON_SDK.md** rewritten to match the new SDK: real `TYPES` values, `why_it_matters` instead of `why`, no more phantom "subprocess timeout" troubleshooting section.
77
+
78
+ ### Test coverage
79
+
80
+ - `tests/test_transfer.py` (new): pins every bug fixed above as a regression test, plus baselines for behavior that was already correct.
81
+ - `tests/test_sdk.py` (new): round-trip coverage for the rewritten SDK, including the `scope=global` + `assumptions` path that was previously unreachable.
82
+ - `tests/test_hooks.py` (new): installs a real pre-commit hook and runs actual `git commit` against it — confirms it blocks, that `--no-verify` bypasses it, and that an unrelated commit isn't blocked.
83
+
84
+ ## [0.2.0]
85
+
86
+ - Added `roco export` / `roco import` / `roco merge` for cross-project knowledge sharing (JSONL format).
87
+ - Added the (later found non-functional — see 0.3.0) Python SDK.
88
+ - Added `roco` as a shorthand alias for `robo-cortex` (same binary, two entry points).
89
+ - Added usage tracking (`last_used_at`, `use_count`) to the memory schema, laying groundwork for a future `prune` command (see ROADMAP.md).
90
+
91
+ ## [0.1.0]
92
+
93
+ Initial release. Core memory lifecycle (record/retrieve/search/status/evidence/link), git-anchored staleness detection, scope A (repo) and scope B (global) stores, MCP server, optional Gitea evidence verification. See `EVALUATION.md` for the release-gate evaluation this version shipped against.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robotel Limited UK (https://robotel.top)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,367 @@
1
+ Metadata-Version: 2.4
2
+ Name: robo-cortex
3
+ Version: 0.4.0
4
+ Summary: Long-term memory system for LLM coding agents working inside a Git repository
5
+ Project-URL: Homepage, https://robotel.top
6
+ Project-URL: Repository, https://github.com/robotel-limited/robo-cortex
7
+ Project-URL: Issues, https://github.com/robotel-limited/robo-cortex/issues
8
+ Project-URL: Changelog, https://github.com/robotel-limited/robo-cortex/blob/main/CHANGELOG.md
9
+ Author-email: Robotel Limited UK <tech@robotel.top>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,developer-tools,git,llm,mcp,memory,sqlite
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Requires-Python: >=3.11
23
+ Provides-Extra: dev
24
+ Requires-Dist: mcp>=1.28; extra == 'dev'
25
+ Requires-Dist: pytest; extra == 'dev'
26
+ Provides-Extra: mcp
27
+ Requires-Dist: mcp>=1.28; extra == 'mcp'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # robo-cortex
31
+
32
+ **A git-aware, evidence-based memory store for AI coding agents.**
33
+
34
+ Your AI agent debugs a bug, learns the lesson, and forgets it by next week — or worse, keeps citing a "lesson" that the code has since made false. robo-cortex is a local knowledge base built for that specific failure mode: memories are anchored to git blob hashes, so when the code they're about changes, the memory is automatically flagged for review instead of being silently trusted or silently lost.
35
+
36
+ ---
37
+
38
+ ## Why robo-cortex, not another memory tool
39
+
40
+ Most agent-memory tools are embeddings + a vector database + a cloud dependency. robo-cortex is deliberately none of that. Four things it does that a generic key-value memory store doesn't:
41
+
42
+ 1. **Git-aware staleness detection.** Every memory can link to specific file paths, captured by git blob hash at record time. When the linked code changes, the memory is automatically flagged `needs_review` on the next `retrieve`/`search`/`affected` call — and a committed revert automatically heals it back. The healing requires three conditions: (a) the revert must be **committed** (git blob hash must match HEAD again), (b) the memory must have been flagged by the system (not manually via `change_status`), and (c) you must run a lazy trigger (`retrieve`/`search`/`affected`) after the revert to scan for changes. No other memory tool ties itself to your actual code's history this way.
43
+ 2. **Evidence, not vibes.** Memories can carry attached evidence (test output, a commit, a re-runnable command) with a mechanically computed strength — not a judgment call. A `provisional` memory only becomes `active` once real evidence backs it, or a human explicitly promotes it.
44
+ 3. **Zero dependencies, fully local.** Pure stdlib + SQLite (FTS5 for search). No embeddings, no API keys, no network calls unless you explicitly configure Gitea evidence verification. `.cortex/memory.db` is just a file — inspect it with `sqlite3` any time.
45
+ 4. **A real lifecycle with an audit trail.** Every status change (`active` → `superseded` → `archived`, etc.) requires a `--reason`, permanently recorded. Nothing disappears silently; wrong lessons are marked `invalidated`, not deleted.
46
+
47
+ ## Pilot measurement (informative, not definitive)
48
+
49
+ A small, real evaluation pilot (3 runs per arm, **one task only**) measured **2.7% fewer tokens and 10.6% less wall-clock time** with robo-cortex versus without, at equal fix quality. This is a real but modest signal from a limited sample — see [EVALUATION.md](https://github.com/robotel-limited/robo-cortex/blob/main/EVALUATION.md) §9 for full methodology and caveats. Key limitations: n=3/arm (too small to generalize), one task type (may not represent typical workloads), and token-accounting asymmetry (doesn't credit avoided re-debugging when a stale lesson is caught before being retried, which is the real value proposition). We'd rather publish a modest number we measured than a dramatic one we didn't. **Not a benchmark** — a proof of concept that robo-cortex doesn't hurt wall-clock time in a realistic scenario, and may help on tokens. Definitive performance claims await a larger study across more task types.
50
+
51
+ ---
52
+
53
+ ## Quick Start
54
+
55
+ **Prerequisite:** robo-cortex requires a git repository (staleness detection needs git history to compare against):
56
+ ```bash
57
+ git init && git add -A && git commit -m "initial commit"
58
+ ```
59
+
60
+ ### Installation
61
+
62
+ ```bash
63
+ pip install robo-cortex
64
+ ```
65
+
66
+ If `pip install` refuses with `error: externally-managed-environment` (common on recent Debian/Ubuntu), use a virtual environment or `pipx`:
67
+ ```bash
68
+ python3 -m venv .venv && source .venv/bin/activate && pip install robo-cortex
69
+ # or: pipx install robo-cortex
70
+ ```
71
+
72
+ If you plan to use robo-cortex with an MCP-capable agent (Claude Desktop/Code, etc.), install the MCP extra instead:
73
+ ```bash
74
+ pip install 'robo-cortex[mcp]'
75
+ ```
76
+
77
+ ### Usage
78
+
79
+ ```bash
80
+ cd /path/to/your/project
81
+ roco init
82
+
83
+ # Record a project-specific lesson (scope=repo: no extra fields needed)
84
+ roco record --type lesson --scope repo \
85
+ --statement "Copy-to-clipboard fails on HTTP; use a textarea+execCommand fallback." \
86
+ --confidence high
87
+
88
+ # Retrieve it later
89
+ roco retrieve --task "copy to clipboard http"
90
+ ```
91
+
92
+ ```
93
+ matched=1 returned=1 needs_review=0 contradicted=0
94
+ [1] score=0.650 repo lesson Copy-to-clipboard fails on HTTP; use a textarea+execCommand fallback.
95
+ ```
96
+
97
+ `--path` links a memory to a file, but only accepts a path that already exists at HEAD (no memory is ever born pointing at a dead link). For code you just wrote but haven't committed yet: record the memory without `--path` now, commit, then attach the path afterward:
98
+
99
+ ```bash
100
+ roco record --type decision --scope repo --statement "..." --confidence high
101
+ # id=7, no linked path yet
102
+
103
+ git add new_module.py && git commit -m "add new_module.py"
104
+ roco record 7 --add-path new_module.py
105
+ ```
106
+
107
+ Reusable lessons (not specific to this project) use `scope=global` and require `--assumptions` — the conditions under which the lesson applies, so it doesn't get suggested everywhere by accident:
108
+
109
+ ```bash
110
+ roco record --type lesson --scope global \
111
+ --statement "Safari 14 breaks CSS grid+gap. Use flexbox+margin instead." \
112
+ --confidence high \
113
+ --assumptions "css grid gap safari"
114
+ ```
115
+
116
+ ### Enable enforcement (recommended)
117
+
118
+ ```bash
119
+ roco hooks install
120
+ ```
121
+
122
+ Installs a git pre-commit hook: if the commit touches code linked to a memory that's `active`/`provisional`/`needs_review`, the commit is blocked with the memory's id and a review prompt, until you've reviewed it or bypassed explicitly. Example, for a memory linked to `src/scanner.py` when that file is part of the commit:
123
+
124
+ ```
125
+ robo-cortex: this commit touches code linked to memories that need review:
126
+ [1] path_changed:src/scanner.py@working_tree scanner batches at 50 items deliberately
127
+
128
+ Review with: roco show <id>
129
+ Then either re-verify (roco status <id> activate --reason "...") or supersede it, and commit again.
130
+ To bypass this check: git commit --no-verify
131
+ ```
132
+
133
+ The bypass is real and documented — `git commit --no-verify` skips it, same as any git hook. This is "enforcement by default, bypass explicit," not "impossible to skip." See `roco hooks --help` for `uninstall`/`status`. For a CI-level check on pull requests instead of (or in addition to) local commits, see [docs/ci-example.yml](https://github.com/robotel-limited/robo-cortex/blob/main/docs/ci-example.yml).
134
+
135
+ There's also an optional post-commit hook, purely informational (it never blocks — the commit it reports on already happened by the time it runs):
136
+
137
+ ```bash
138
+ roco hooks install --post-commit
139
+ ```
140
+
141
+ It runs `roco affected --diff-range HEAD~1..HEAD` after each commit and reports anything at risk, so a flag shows up immediately instead of waiting for the next `retrieve`/`search`/`affected` call. `--post-commit` also works with `uninstall`/`status`, independently of the pre-commit hook.
142
+
143
+ ---
144
+
145
+ ## Shorthand: `roco`
146
+
147
+ Both `robo-cortex` and `roco` are identical commands (same binary, two script entry points). Use whichever fits your fingers:
148
+ ```bash
149
+ roco retrieve --task "..." # Shorter alias
150
+ robo-cortex retrieve --task "..." # Full name, backwards compatible
151
+ ```
152
+
153
+ **Name collision note:** PyPI already has an unrelated package named `roco` ("Runtime Config Generator"). If that package is also installed in the same environment, whichever was installed last wins the `roco` command — use the full `robo-cortex` name to be unambiguous, or check `roco --version` to confirm which one you're actually running.
154
+
155
+ ### Shell completion
156
+
157
+ ```bash
158
+ roco completion bash >> ~/.bashrc
159
+ ```
160
+
161
+ Completes subcommand names and each subcommand's own flags (not flag values, and not nested sub-subcommands like `hooks install`). It's a static script generated from the installed version — re-run the command after upgrading to pick up new commands or flags.
162
+
163
+ ---
164
+
165
+ ## Three ways to use it
166
+
167
+ | Scenario | Best method | Why |
168
+ |----------|-------------|-----|
169
+ | One-off CLI commands (shell, scripts, manual testing) | CLI: `roco retrieve --task "..."` | Simplest, no dependencies, immediate |
170
+ | Python agent or script running your own code | Python SDK: `from robo_cortex import retrieve, record` | In-process (no subprocess), real exceptions, not string-parsed errors |
171
+ | LLM agent (Claude Code, or any MCP client) with tool-calling | MCP server: add to your MCP config | Agent decides when to call; tool descriptions ship with the package |
172
+
173
+ All three call the same underlying `robo_cortex.core` functions — pick based on what the calling code already uses.
174
+
175
+ ### MCP configuration
176
+
177
+ ```json
178
+ {
179
+ "mcpServers": {
180
+ "robo-cortex": {
181
+ "command": "roco",
182
+ "args": ["mcp", "--repo", "/path/to/project"]
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ Available tools: `retrieve_context`, `record_memory`, `search_memory`, `attach_evidence`, `verify_evidence`, `change_status`, `get_memory`, `list_affected`. Full contract in [MCP_TOOLS.md](https://github.com/robotel-limited/robo-cortex/blob/main/MCP_TOOLS.md).
189
+
190
+ ### Python SDK
191
+
192
+ ```python
193
+ from robo_cortex import retrieve, record
194
+
195
+ memories = retrieve("feature description", repo_path="/srv/project")
196
+ if memories["data"]:
197
+ print(f"Found solution: {memories['data'][0]['statement']}")
198
+
199
+ record(
200
+ type="lesson",
201
+ statement="What you learned",
202
+ confidence="high",
203
+ repo_path="/srv/project",
204
+ )
205
+ ```
206
+
207
+ Full API, including the `RoboCortex` class for multiple calls against the same repo, in [PYTHON_SDK.md](https://github.com/robotel-limited/robo-cortex/blob/main/PYTHON_SDK.md).
208
+
209
+ ---
210
+
211
+ ## Memory Lifecycle: Status Transitions
212
+
213
+ Every memory has a status that reflects its confidence and applicability. New memories start `provisional`; manual review or evidence changes their status:
214
+
215
+ | Status | Meaning | Can transition to |
216
+ |--------|---------|-------------------|
217
+ | **provisional** | New memory, not yet validated | active, needs_review, abandoned |
218
+ | **active** | Confident, applicable to future work | needs_review, superseded, invalidated, archived, abandoned |
219
+ | **needs_review** | Suspect or context-dependent; needs human judgment | active, superseded, invalidated |
220
+ | **superseded** | Replaced by a better solution (must link to replacement ID) | archived |
221
+ | **invalidated** | Proven false or no longer applicable | archived |
222
+ | **abandoned** | Lesson that went nowhere; dead-end exploration | archived |
223
+ | **archived** | Terminal state (read-only) | — |
224
+
225
+ ### Automatic Transitions
226
+
227
+ - `provisional` → `active`: happens automatically when you attach evidence to a memory (`roco evidence add`) — the first supporting data promotes the memory to trusted.
228
+
229
+ ### Manual Transitions
230
+
231
+ Use `roco status <id> <verb> --reason "..."` to change status manually:
232
+
233
+ ```bash
234
+ # Promote a provisional memory (no evidence yet)
235
+ roco status 5 activate --reason "Tested and validated on three projects"
236
+
237
+ # Mark a memory as superseded by a better lesson
238
+ roco status 7 supersede --supersedes 12 --reason "Version 2 of this pattern handles edge cases better"
239
+
240
+ # Mark as proven false
241
+ roco status 9 invalidate --reason "Benchmark shows this optimization actually makes things slower"
242
+
243
+ # Archive old/resolved items
244
+ roco status 3 archive --reason "No longer applicable after database migration"
245
+ ```
246
+
247
+ `--reason` is mandatory and permanent — it becomes part of the memory's audit history and cannot be edited.
248
+
249
+ ---
250
+
251
+ ## Deciding Scope (Global vs Repo)
252
+
253
+ **Use `scope=repo`** for project-specific learnings:
254
+ - This codebase's chosen patterns (we use FastAPI + SQLAlchemy)
255
+ - Project-specific decisions (batch size tuned for our infrastructure)
256
+ - **Test:** "Does this reference our code, infra, or team decision?"
257
+
258
+ **Use `scope=global`** for reusable lessons:
259
+ - Browser/library bugs (Safari CSS, Node.js async patterns)
260
+ - Language/framework patterns
261
+ - Best practices (SQL injection prevention)
262
+
263
+ `scope=global` requires `assumptions` — the preconditions under which the lesson applies:
264
+
265
+ ```json
266
+ {
267
+ "type": "lesson",
268
+ "scope": "global",
269
+ "statement": "Copy-to-clipboard fails on HTTP. Use textarea + execCommand() fallback.",
270
+ "assumptions": "Web app with clipboard feature, needs to work on HTTP",
271
+ "confidence": "high"
272
+ }
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Sharing knowledge across projects
278
+
279
+ ```bash
280
+ roco export --scope global --output kb.jsonl
281
+ # In another project:
282
+ roco import kb.jsonl
283
+ ```
284
+
285
+ Import is idempotent (re-importing the same file skips duplicates by id+scope) and validated exactly like `record` — a `scope=global` line missing `assumptions`, or an invalid `type`/`confidence`, is skipped with a warning, not silently inserted or a raw database error.
286
+
287
+ Two projects that learned independently can converge with `roco merge`:
288
+ ```bash
289
+ roco merge kb_a.jsonl kb_b.jsonl --output kb_merged.jsonl
290
+ # Both projects then: roco import kb_merged.jsonl
291
+ ```
292
+ De-duplicates by ID+scope; conflicts resolved by confidence (higher wins), tie-broken by timestamp. See [EXPORT_IMPORT.md](https://github.com/robotel-limited/robo-cortex/blob/main/EXPORT_IMPORT.md) for the full workflow, including team-KB and backup use cases.
293
+
294
+ **Do not point `ROBO_CORTEX_GLOBAL_DB` at a network filesystem (NFS/SMB) for "shared team memory."** SQLite is not safe for concurrent writers over a network mount and can corrupt the database. Share via export/import through git instead — it's versioned and auditable, which a live-shared file isn't.
295
+
296
+ ---
297
+
298
+ ## FAQ
299
+
300
+ **Q: Do I need a git repository?**
301
+ A: Yes. Staleness detection, path linking, and `affected` all compare against git history. Without git, you can still use export/import/merge to move knowledge between machines, but the git-aware features won't work.
302
+
303
+ **Q: What if I (or my agent) forget to check memory?**
304
+ A: `roco hooks install` blocks a commit that touches code linked to an unreviewed memory — but the bypass (`git commit --no-verify`) is real and always available, same as any git hook. This is enforcement-by-default with an explicit escape hatch, not an unconditional guarantee.
305
+
306
+ **Q: Stale notes are dangerous.**
307
+ A: Memories auto-flag `needs_review` when their linked code changes. You review before trusting, or mark as superseded. Nothing silently misleads.
308
+
309
+ **Q: Sharing memory across teams?**
310
+ A: Two approaches:
311
+ - **Snapshot sharing** (versioned, audited): export from one project, commit the JSONL to git, team members import.
312
+ - **Live shared database**: set `ROBO_CORTEX_GLOBAL_DB=/path/to/shared/global.db` on a *local* path all `roco` invocations can reach — not a network mount (see warning above).
313
+
314
+ **Q: Offline?**
315
+ A: Yes. Everything is local SQLite. Zero network calls unless you explicitly configure Gitea evidence verification (`ROBO_CORTEX_GITEA_URL`).
316
+
317
+ **Q: Wrong lesson?**
318
+ A: Mark as `invalidated` with a reason. Preserved in history, never suggested going forward.
319
+
320
+ **Q: Read-only database?**
321
+ A: `retrieve`/`search`/`affected` degrade gracefully on a read-only `.cortex/memory.db` (read-only checkouts, some CI setups). Reads return their result, writes (staleness refresh, usage tracking) are skipped, and `meta` includes a warning. The memory core still works, just without incidental writes that don't affect correctness.
322
+
323
+ **Q: How do I opt out of the global store?**
324
+ A: Set `ROBO_CORTEX_NO_GLOBAL=1`. CLI and MCP both skip opening `~/.cortex/global.db` entirely — `retrieve`/`search` scopes strictly to the current repo, with no cross-project knowledge channel. Useful if you want strict per-project isolation.
325
+
326
+ **Q: What's the expected scale?**
327
+ A: robo-cortex is designed and tested for thousands of memories per store (repo-scoped and global combined). Performance degrades gracefully beyond that — scoring stays O(n) per candidate, and FTS candidate set is capped at 200 for each store. If you have significantly more memories than that, consider splitting into multiple projects or archiving old memories. See ARCHITECTURE.md for details.
328
+
329
+ ---
330
+
331
+ ## Architecture
332
+
333
+ ```
334
+ Codebase
335
+
336
+ git pre-commit hook (roco hooks install) -- blocks commits touching unreviewed memories
337
+
338
+ robo-cortex Memory (SQLite + FTS5)
339
+
340
+ .cortex/memory.db (repo) + ~/.cortex/global.db (shared)
341
+
342
+ retrieve_context() → ranked memories with evidence, gated by staleness + assumptions
343
+ ```
344
+
345
+ No embeddings. No cloud. Just SQLite, git awareness, and an explicit enforcement layer you can inspect (`.git/hooks/pre-commit` is plain shell, readable in five seconds).
346
+
347
+ ---
348
+
349
+ ## Learn More
350
+
351
+ - [ARCHITECTURE.md](https://github.com/robotel-limited/robo-cortex/blob/main/ARCHITECTURE.md) — Design and data model
352
+ - [MCP_TOOLS.md](https://github.com/robotel-limited/robo-cortex/blob/main/MCP_TOOLS.md) — Tool contracts for agents
353
+ - [PYTHON_SDK.md](https://github.com/robotel-limited/robo-cortex/blob/main/PYTHON_SDK.md) — In-process Python API
354
+ - [EXPORT_IMPORT.md](https://github.com/robotel-limited/robo-cortex/blob/main/EXPORT_IMPORT.md) — Sharing knowledge across projects
355
+ - [EVALUATION.md](https://github.com/robotel-limited/robo-cortex/blob/main/EVALUATION.md) — Test results and benchmarks, including the honest token-economy numbers cited above
356
+ - [ROADMAP.md](https://github.com/robotel-limited/robo-cortex/blob/main/ROADMAP.md) — What's deliberately not built yet, and why
357
+ - [CHANGELOG.md](https://github.com/robotel-limited/robo-cortex/blob/main/CHANGELOG.md) — Release history
358
+
359
+ ---
360
+
361
+ ## Made By
362
+
363
+ **Free to use.** Made available by **Robotel Limited UK** ([https://robotel.top](https://robotel.top)).
364
+
365
+ The architecture was designed with Anthropic's Claude (Fable) on July 2026 as an AI development agent, applying the expertise of Robotel Limited’s developers, who bring over three years of hands-on experience building and operating AI coding agents in production.
366
+
367
+ MIT License. Open source. No telemetry. No vendor lock-in.