Technical Specification

CoMemor Architecture & Security Model

A comprehensive look at how CoMemor implements local-first persistence, deterministic and fuzzy lexical retrieval in under 50ms, multi-layer secret redaction, and strict non-executing safety policies.

Local-First Guarantee: CoMemor communicates exclusively over JSON-RPC via standard input/output (stdio) with your host IDE. All data stays inside your repository's .agent-memory/ directory. There are zero cloud databases, zero telemetry endpoints, and zero external network calls.

1. Design Philosophy: Deterministic vs. Semantic Retrieval

Many agent memory systems rely on vector databases and text embeddings. In software engineering error diagnostics, vector embeddings introduce subtle but critical failure modes:

  • Embedding Drift: Embeddings fluctuate across model versions and vendor APIs, causing previously matched errors to suddenly miss.
  • Syntactic Blindness: A subtle difference in a flag, path alias, or compiler error code (e.g., TS2307 vs TS2304) often has near-identical semantic cosine similarity, leading to inappropriate fix recommendations.
  • Latency & Cost: Generating vector embeddings for every command output burns API tokens and introduces 300–800ms of network overhead before every agent retry.

CoMemor takes a deterministic approach:

⚡ Tier 1: Exact SHA-256 Match

Normalizes command strings, exit codes, and sanitized error traces into a deterministic SHA-256 fingerprint. Exact recurring failures resolve in <5ms with 1.0 confidence.

🔍 Tier 2: SQLite FTS5 Lexical Match

For modified error traces, token-overlap BM25 matching ranks candidate fixes against the built-in SQLite index, scored with Wilson confidence intervals.

2. Storage Subsystem & Repository Layout

CoMemor stores all records in a dedicated .agent-memory/ folder inside the project workspace:

.agent-memory/
  records.jsonl           — Append-only fix records (safe to commit to Git after review)
  index.db                — SQLite FTS5 index (gitignored, rebuilt automatically on startup)
  logs.jsonl              — Operational logs written via Pino (gitignored)
  approvals-pending.jsonl — Fix commands validated by verify_fix (gitignored)
  approvals-resolved.jsonl — Operator decision audit log (gitignored)

Append-Only JSONL as Source of Truth

The human-readable records.jsonl file acts as the durable, git-friendly source of truth. Every verified failure resolution is appended as a single JSON line containing:

  • Original command and non-zero exit code
  • SHA-256 normalized error fingerprint
  • Redacted failure stdout/stderr excerpt
  • Verified fix command array and natural language explanation
  • Lockfile hash and normalizer version for staleness detection
  • Wilson score statistical confidence tracking (success count, trial count)

Automatic SQLite FTS5 Indexing

CoMemor leverages the native node:sqlite module built into Node.js (≥ 22.5.0), eliminating native binary compile steps. On startup, CoMemor verifies the SQLite index against records.jsonl line offsets and seamlessly rebuilds the full-text search index if missing or out of sync.

3. Multi-Layer Security & Redaction Pipeline

Persisting terminal output presents real security challenges. Failure logs frequently contain environment variables, authorization headers, database connection strings, or personal access tokens. CoMemor addresses this with a defense-in-depth pipeline:

Layer 1: Deterministic Pattern Redaction

Before any record is written to disk or indexed in SQLite, CoMemor executes deterministic regex replacement across all fields to scrub:

  • Bearer tokens and Authorization headers
  • GitHub, GitLab, and NPM personal access tokens (ghp_*, npm_*)
  • AWS, GCP, and Azure secret keys and credentials
  • Database connection URLs with embedded passwords (e.g. postgres://user:pass@host/db)
  • Private keys (RSA, SSH, PGP)

Layer 2: Shannon Entropy Analysis

Pattern matching alone fails against novel API key formats. CoMemor supplements regex with rolling Shannon entropy calculation. String tokens exceeding high-entropy thresholds (characteristic of random cryptographic secrets) are automatically sanitized and replaced with redaction placeholders before disk write.

Layer 3: Heuristic Prompt-Injection Detection

To prevent malicious repository actors from poisoning stored memories with prompt injections (e.g., hidden instructions embedded in mock test failures), CoMemor runs 7 heuristic detectors looking for instruction override markers (such as Ignore previous instructions or System prompt override). Flagged records are quarantined in .agent-memory/quarantine.jsonl and excluded from active retrieval.

Layer 4: Untrusted-Data Envelopes

When find_fix returns candidate fixes to the host LLM, all retrieved historical content is wrapped in explicit untrusted-data delimiters. This instructs the consuming model to treat historical context strictly as data, neutralizing secondary injection attacks.

4. Non-Executing Policy Contract (verify_fix)

A core architectural principle of CoMemor is that the server never executes commands.

Safety Invariant: The verify_fix tool returns executedByServer: false and requiresHostConfirmation: true under all circumstances. CoMemor evaluates policy safety but delegates 100% of execution decisions to the human developer or the host IDE's confirmation dialog.

When an agent requests command verification, CoMemor evaluates:

Safety Check Validation Rule Behavior on Violation
Binary Allowlist Command must invoke an approved development binary (e.g., npm, npx, git, cargo, pytest). Returns policy warning; flags command for operator review.
Shell Metacharacters Blocks command chaining (;, &&, ||), redirection (>, <), and shell escapes. Rejects proposal as high-risk execution pattern.
Path Containment Ensures target file arguments remain inside the repository workspace boundary. Blocks paths escaping root (e.g., ../../etc/passwd).

5. Memory Console Architecture (dashboard-bridge)

The CoMemor dashboard is designed as an isolated, read-only observability console:

  • Separate Process: Started via npx comemor-dashboard, the bridge runs as a standalone Fastify server on 127.0.0.1:4321. It never shares memory, stdio, or process space with the MCP server.
  • Read-Only Mode: Opens SQLite and JSONL files in read-only mode, guaranteeing that viewing or auditing records can never mutate stored memory.
  • Live Streaming: Uses Server-Sent Events (SSE) at /api/events to stream agent tool calls to the browser in real time without polling.
← Back to Homepage View IDE Setup Guides →