Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 6.25 KB

README.md

File metadata and controls

72 lines (51 loc) · 6.25 KB

tarchia

Agent memory held in Opteryx. Datasets are tarchia.<scope>.<table> on opteryx.app.

  • Hook reads (recall, start, show) go through the OData service, $search over current_facts.
  • Writes and fresh reads go through the opteryx-sqlalchemy DBAPI (sibling checkout, OPTERYX_SQLALCHEMY), opened on first use.
  • Whole-table rebuilds go through the upload service (sibling opteryx-upload checkout, OPTERYX_UPLOAD), because the jobs API refuses statements over 256,000 characters.
  • Credentials are USER:<name> and TOKEN:<secret> lines in ~/.tarchia/token (mode 600). The code index workflow holds no secret: it authenticates over GitHub OIDC (--oidc).
table
facts append-only; one row per version of a memory, tombstone on removal; the fact MEMORY is the standing index, and its ⛔⭐🔴✅ markers set the flags of the facts it links
anchors paths, filenames and symbols each fact names (derived)
links fact → fact references (derived)
files, symbols, tokens the indexed repository's main as pushed, rebuilt in CI (derived)
code_ref one row: the ref and commit files/symbols/tokens were built from, and when
current_facts materialized view: the latest live version of each fact, search_column = body, for OData $search (searchable; a refresh is queued after each write to facts, so it is eventually consistent: show/recall can return the previous version for a while, from_tarchia reads fresh)
python -m tarchia remember opteryx_core <id> [--archived] < memory.md   # add or replace one fact (frontmatter + body)
python -m tarchia forget opteryx_core <id>                              # tombstone one fact
python -m tarchia show opteryx_core <id>
python -m tarchia search opteryx_core "benchmark slow on battery" 5   # MATCH over facts.body, ranked by COSINE_SIMILARITY
python -m tarchia sync opteryx_core <tree> <ref> <commit> [--oidc]   # rebuild files/symbols/tokens from a checkout of <commit> (CI runs this)
python -m tarchia stale opteryx_core
python -m tarchia searchable opteryx_core   # once per scope: current_facts materialized view + search_column
python -m tarchia import opteryx_core <memory_dir>   # a Claude Code memory directory becomes the whole of the live facts
python -m tarchia populate opteryx_core <memory_dir>   # replace facts/anchors/links from files - wipes facts written with remember; code tables untouched

Every remember/forget rebuilds from all live facts (~10 s): new versions only where a fact changed, markers re-derived from the index facts, anchors and links replaced.

As Claude Code's memory

tarchia holds memory about the architecture and the system. Memory specific to one machine (its perf traps, local env, LAN boxes) stays in that machine's memory folder, indexed by its local MEMORY.md, which Claude Code loads itself. Hooks in the project's .claude/settings.local.json:

The model gets memory in two layers:

Hook Command What the model gets Cost
SessionStart python -m tarchia start <scope> The whole MEMORY index, every entry (one link + one-line summary per fact, no fact bodies), plus the other stores this identity can read (every tarchia.<store>.current_facts in the OData service document) and how to search/show them once per session, ~0.9 s
UserPromptSubmit python -m tarchia recall <scope> Up to five facts most similar to the prompt (OData $search over current_facts), bodies inline, each cut at 1,400 characters with a show command for the rest every prompt, ~1.2 s

The index is a table of contents that is always there, so the standing rules and traps are seen even when no prompt matches them; recall brings in the detail that bears on the prompt. Anything else is the model's to fetch: search <scope> "<topic>" finds facts, show <scope> <id> reads one. Each repo has its own store and recall reads only its own; other repos' memory is read on demand.

Recall says nothing when:

  • the prompt is under 25 characters (MIN_PROMPT): "yes", "go on", "did you use tarchia?" are replies, not topics;
  • the prompt has no text, e.g. a screenshot alone;
  • no fact scores 0.2 or more (THRESHOLD; the embedder scores related text ~0.2–0.45).

Only the first 4,000 characters of a prompt are matched (MAX_PROMPT).

Keep the index under ~10 KB. Claude Code keeps a hook's context only up to ~10 KB; past it the model gets a 2 KB preview and the rest goes to a file it never reads, silently losing most of the index. start sends the whole index, so its size is the sum of its lines: keep each summary to a short hook (~70 characters) and leave dates, paths and numbers in the fact, where show has them. 64 entries at that length come to ~8.7 KB of hook output. Check with echo '{}' | python -m tarchia start <scope> | wc -c.

A hook failure is reported, not hidden: without tarchia there is no memory.

The code index

files, symbols and tokens come from GitHub, not from a laptop: .github/workflows/tarchia_index.yaml in opteryx-core runs sync ... --oidc on every push to main, checking out tarchia and opteryx-upload beside it, and writes code_ref last. stale prints the commit it checks against (stderr) and fails if code_ref is empty.

Local and uncommitted code is not indexed. A fact naming a file or symbol that is not yet on main reads stale until it is pushed; one naming code deleted locally reads fresh until the deletion reaches main; gitignored trees (scratch/, build/, target/) are never indexed.

sync does not create tables (CI holds only an upload identity): import/populate run schema.ensure for a new scope. The workflow's identity is a federated credential on an opteryx.app client, pinned to the workflow file on main (run from authenticate.opteryx):

python scripts/register_federated_credential.py <client_id> \
  --repository mabel-dev/opteryx-core \
  --job-workflow-ref 'mabel-dev/opteryx-core/.github/workflows/tarchia_index.yaml@refs/heads/main'

The token the workflow gets carries that client's own policies, the same as a PAT for it would: the client must hold writer on tarchia.opteryx_core.* in the policy store. A --permission on the federated credential is stored but not applied to the token.