How autoloops/greplica works
Purpose and Entry Points
Greplica is a Node.js (22–26) CLI that gives coding agents persistent, searchable repository memory. It stores repo structure, decisions, workflows, and session-derived claims locally, then retrieves a focused Markdown context packet for later tasks.
Primary entry point: apps/cli/main.ts. Repository context discovery is in apps/cli/repo-context.ts. The published CLI drives installation, graph operations, proposal validation/application, transcript bundling, and diagnostics.
Installation and Agent Integration
Installation prepares per-repo state and wires Greplica into supported coding-agent platforms. libs/install/install.ts coordinates platform-specific skills, hooks, and paths; adapters live under libs/install/platforms/, including libs/install/platforms/codex.ts, libs/install/platforms/cursor.ts, and libs/install/platforms/openhands.ts.
This is a boundary between Greplica’s local graph/store and external agent environments. Hook placement varies: some platforms use user-home configuration, while OpenHands is repo-local.
Session Hooks and Memory Maintenance
Hooks inject retrieval guidance when a task starts, track session state, and can launch background working-memory updates after sessions. The core hook worker is libs/hooks/worker.ts, with protocol/state in libs/hooks/hook-input.ts and libs/hooks/session-state.ts.
Skills define the agent-facing workflows for initial repository bootstrap, fast transcript bootstrap, and incremental updates: skills/greplica-bootstrap/SKILL.md, skills/greplica-fast-session-bootstrap/SKILL.md, and skills/greplica-update-working-memory/SKILL.md.
Knowledge Graph Domain and Proposal Boundary
The durable memory model consists of components, flows, claims, source commits/scopes, and typed edges. Its core schema/domain modules are libs/knowledge-graph/schema.ts, libs/knowledge-graph/claim.ts, libs/knowledge-graph/edge.ts, and libs/knowledge-graph/service.ts.
Agents or memory-building processes produce proposal JSON. libs/knowledge-graph/validate-proposal.ts validates it before libs/knowledge-graph/proposal.ts applies it, creating an explicit integrity boundary between generated content and persisted graph state. Similar-claim detection is handled by libs/knowledge-graph/dedupe/find-similar-claims.ts.
Local Persistence and Source Integrity
SQLite is the primary local persistence layer, implemented by libs/storage/sqlite/db.ts, libs/storage/sqlite/schema.ts, and libs/storage/sqlite/repository.ts; migrations are managed in libs/storage/sqlite/migrate.ts.
Claims can cite code anchors. Anchor fingerprints, resolution, and drift audits are separated in libs/knowledge-graph/code-anchors/fingerprint.ts, libs/knowledge-graph/code-anchors/resolver.ts, and libs/knowledge-graph/code-anchors/audit.ts. This permits stored knowledge to be checked against an evolving working tree.
Retrieval and Graph Consumption
greplica graph context converts a natural-language query into an actionable Markdown context packet. The retrieval pipeline in libs/knowledge-graph/graph-context/ combines document construction, lexical BM25, vector similarity, graph ranking, packet ranking, and rendering: context-builder.ts, bm25.ts, vector.ts, graph-rank.ts, and render.ts.
Embeddings are a replaceable boundary: local models are supported through local-embedder.ts and model locking, while OpenAI is supported through openai-embedder.ts. The graph can also be rendered/exported via libs/knowledge-graph/graph-view/build-graph-view.ts and libs/knowledge-graph/folder-export.ts.
Memory-Build and Evaluation Workflows
Offline memory construction scripts collect repository snapshots and GitHub material, extract symbols, generate/apply proposals, audit anchors, and prepare task-specific context. The orchestrating stages are under scripts/memory-build/, notably prepare-task.ts, collect-repo-snapshot.ts, generate-bootstrap-proposal.ts, and apply-proposals.ts.
Agent runners abstract Codex, OpenCode, and OpenHands execution in libs/agent-runner/. Evaluation cases and ranking experiments under evals/ exercise retrieval, proposal integrity, session backfill, and SWE-chat planning performance rather than serving runtime users.
Main entry points: main.ts Published CLI · worker.ts Session Hook Worker · context-builder.ts Context Builder · codex.ts Platform Adapters
Components 20
CLI & Agent Integration
- Published CLI · Drives installation, graph operations, proposals, bundles, and diagnostics.
apps/cli/main.ts - Repository Discovery
apps/cli/repo-context.ts - Installer
libs/install/install.ts - Platform Adapters · Installs skills, hooks, and platform-specific paths.
libs/install/platforms/codex.ts - Agent Skills · Bootstrap, fast-session bootstrap, and working-memory update guidance.
skills/greplica-bootstrap/SKILL.md - Session Hook Worker · Injects retrieval guidance and triggers background memory maintenance.
libs/hooks/worker.ts - Hook Session State
libs/hooks/hook-input.ts
Knowledge Memory
- Knowledge Graph Domain · Models components, flows, claims, sources, and typed edges.
libs/knowledge-graph/service.ts - Proposal Validation · Validates generated proposal JSON before mutation.
libs/knowledge-graph/validate-proposal.ts - Proposal Application
libs/knowledge-graph/proposal.ts - Similar-Claim Detection
libs/knowledge-graph/dedupe/find-similar-claims.ts - SQLite Repository · Persists durable graph state and migrations.
libs/storage/sqlite/repository.ts
Retrieval & Integrity
- Code Anchor Audits · Fingerprints, resolves, and audits claim anchors against the working tree.
libs/knowledge-graph/code-anchors/audit.ts - Context Builder · Builds query documents and coordinates context retrieval.
libs/knowledge-graph/graph-context/context-builder.ts - Hybrid Ranking · Combines lexical, embedding, graph, and packet ranking.
libs/knowledge-graph/graph-context/graph-rank.ts - Embedding Providers · Supports local models and OpenAI embeddings.
libs/knowledge-graph/graph-context/local-embedder.ts - Markdown Packet Renderer
libs/knowledge-graph/graph-context/render.ts - Graph View & Export
libs/knowledge-graph/graph-view/build-graph-view.ts
Build Workflows
- Memory-Build Pipeline · Collects snapshots, generates proposals, applies them, and prepares task context.
scripts/memory-build/prepare-task.ts - Agent Runners · Abstracts Codex, OpenCode, and OpenHands execution.
libs/agent-runner/codex.ts
Connections 22
- Published CLI → Repository Discovery: discovers repository
- Published CLI → Installer: installs
- Published CLI → Context Builder: graph context
- Published CLI → Proposal Validation: validates proposals
- Installer → Platform Adapters: configures
- Platform Adapters → Agent Skills: installs workflows
- Platform Adapters → Session Hook Worker: registers hooks
- Session Hook Worker → Hook Session State: tracks sessions
- Session Hook Worker → Context Builder: requests guidance
- Session Hook Worker → Memory-Build Pipeline: updates after session
- Memory-Build Pipeline → Agent Runners: runs agents
- Memory-Build Pipeline → Proposal Validation: generates proposals
- Proposal Validation → Proposal Application: accepted proposals
- Proposal Application → Similar-Claim Detection: checks duplicates
- Proposal Application → Knowledge Graph Domain: mutates
- Knowledge Graph Domain → SQLite Repository: persists
- Code Anchor Audits → SQLite Repository: audits stored anchors
- Context Builder → SQLite Repository: loads graph
- Context Builder → Hybrid Ranking: ranks evidence
- Embedding Providers → Hybrid Ranking: vector similarity
- Hybrid Ranking → Markdown Packet Renderer: selected context
- Knowledge Graph Domain → Graph View & Export: renders graph