A reuse-first guard for AI coding agents.
Stop AI tools from writing code that already exists.
Stop AI tools from writing code that already exists.
When you prompt an AI coding agent, it starts writing new code immediately. It doesn't
check whether a reusable function already exists, whether the change fits your patterns,
or whether it's adding duplication. Ask it to "add pagination" and it happily writes a
second paginate() next to the one already in your repo.
Priora inserts a mandatory "check before you code" step. Before new code is written it searches your codebase for an existing implementation and decides:
- REUSE — a matching unit already exists → import it, don't rewrite it.
- EXTEND — something related exists → extend it instead of forking a parallel version.
- GENERATE — nothing fits → safe to write new code (following your conventions).
This is harness engineering, not another chatbot: Priora is an agent-agnostic guard that sits on top of whatever agent you already use (Cursor, Copilot, Claude Code, Continue…).
- AI-generated code introduces measurably more duplication than human code — new functions instead of reuse, the same rule implemented inconsistently across a repo.
- Every existing solution (Cursor Rules,
AGENTS.md,CLAUDE.md) is advisory — a suggestion the model can ignore. There's no verification. - Priora makes reuse an enforced gate, configurable from a soft nudge to a hard block.
npm install
npm run build
# 1. Index a repo's reusable units
node dist/cli.js index examples/sample-project
# 2. Check an intent before coding
node dist/cli.js find "add pagination to a list of records" examples/sample-projectOutput:
intent: add pagination to a list of records
verdict: REUSE (enforcement: warn)
Reuse recommended: `paginate` already exists at src/utils/pagination.ts:6.
Import and use it instead of writing new code.
Top matches:
64% function paginate src/utils/pagination.ts:6
One-liner demo: npm run demo.
find supports --json and returns an exit code, so it can gate a coding agent or a
pipeline:
node dist/cli.js find "build a paginate helper" . --json
# exit 0 → safe to proceed
# exit 2 → blocked (enforcement="block" and a duplicate was found)The JSON payload (decision, matches, message, blocked) is exactly what an agent
tool call (find_reusable) will consume.
{
"enforcement": "warn", // off | warn | block
"thresholds": { "reuse": 0.62, "extend": 0.42 },
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["**/node_modules/**", "**/dist/**", "**/*.d.ts", "**/*.test.ts"]
}Default is warn — strong nudges with easy override, because hard blocks frustrate
developers and kill adoption. Turn on block for shared repos / CI.
Fully local, no external model required:
- Index — the TypeScript compiler API parses each file and extracts units (functions, methods, arrow functions, classes) with name, params, doc comments and location.
- Match — hybrid scoring per unit:
- name match (high precision) — does the intent hit the symbol's name?
- TF-IDF cosine (semantic-ish recall) — so "pagination" matches
paginate. - term overlap + an export bonus (exported symbols are likelier meant for reuse).
- Decide — top score vs.
reuse/extendthresholds → REUSE / EXTEND / GENERATE.
A pluggable embedding provider can replace the TF-IDF stage for stronger recall later.
extension/ — indexes the workspace on startup and on every save, and puts a
warning squiggle on any function you just wrote that duplicates existing code:
Possible duplicate:
paginatealready exists at src/utils/pagination.ts:6 (83% match). Reuse it instead of writing new code.
Commands: Priora: Re-index workspace, Priora: Find existing implementation
(uses your selection or a prompt, then jumps to the match), Priora: Explain
conventions here. Enforcement (off/warn/block) is a VS Code setting;
block shows Errors instead of Warnings.
cd extension && npm install && npm run build # then press F5 in VS Code to runmcp-server/ is a spec-compliant MCP stdio server exposing two tools to any
agent (Claude Code, Cursor, Continue…):
index_repo({ root })find_reusable({ intent, root, enforcement? })→ REUSE / EXTEND / GENERATE + matches
cd mcp-server && npm install && npm run buildRegister it with your agent using skill/mcp.example.json, then drop
skill/AGENTS.md (or install skill/SKILL.md) into your repo. The skill makes
the agent call find_reusable before writing any new unit and obey the
verdict — turning reuse from a suggestion into an enforced step. When enforcement
is block, a duplicate returns blocked: true and the agent must reuse.
MCP tools: index_repo, find_reusable, verify_output, get_conventions,
recommend_stack, get_stats.
The pre-flight check can be ignored, so Priora closes the loop after generation:
priora verify path/to/generated.ts # flags new code that duplicates the repo
priora stats # how much duplication was preventedverify re-parses the generated code and rejects units that re-implement
indexed ones (verify_output MCP tool does the same for agents). Every check
and violation is recorded to .priora/metrics.json so teams can see the guard's
value. This is the full harness: tool orchestration → verification → guardrails
→ observability.
priora conventions # inferred from .editorconfig / eslint / tsconfig / prettier / package.json
priora recommend "realtime chat backend for many connections"When the verdict is GENERATE, Priora appends the detected conventions so new
code matches the codebase. recommend consults an updatable external
knowledge base (knowledge-base/frameworks.json) — change stack guidance by
editing that file, no model retraining. Today Rust, tomorrow "Rust++": just edit
the JSON. (get_conventions / recommend_stack MCP tools expose both to agents.)
src/ shared core engine (CLI + extension + MCP all use it)
tokenize.ts identifier splitting + stemming (pagination ~ paginate ~ paginated)
indexer.ts TS compiler API → CodeUnit[]
policy.ts hybrid scoring + reuse/extend/generate decision ← the differentiator
verify.ts Phase 3 — post-generation duplication check
metrics.ts Phase 3 — observability (duplication prevented)
conventions.ts Phase 4 — infer repo conventions
kb.ts Phase 4 — updatable framework-selection knowledge base
store.ts config loading + .priora/index.json persistence
cli.ts index / find / verify / stats / conventions / recommend
index.ts public API
extension/ Phase 1 — VS Code extension
mcp-server/ Phase 2–4 — MCP server (6 tools)
skill/ Phase 2 — SKILL.md + AGENTS.md + mcp.example.json
knowledge-base/ Phase 4 — frameworks.json (editable, no retraining)
examples/
sample-project/ demo repo with an existing paginate() to reuse
Phase 0 — Proof of concept. ✅
TS indexer + find_reusable policy engine + CLI, with configurable enforcement.
Phase 1 — VS Code extension. ✅ Startup + on-save indexing, inline duplicate-detection diagnostics, find/explain commands.
Phase 2 — Agent skill / MCP server. ✅
find_reusable + index_repo MCP tools + an auto-activating Skill (AGENTS.md-compatible)
so any agent must check before it writes.
Phase 3 — Harness / verification loop. ✅
Post-generation duplication check (verify / verify_output) that rejects output
re-implementing indexed code; observability (stats) for "duplication prevented."
Phase 4 — Knowledge base. ✅
Repo-scoped convention detection injected into GENERATE guidance, plus an updatable
external KB (knowledge-base/frameworks.json) for framework/language selection —
upgrade guidance without retraining the model.
Next — Multi-language: swap the TS-compiler indexer for tree-sitter to cover
more languages; the policy engine is already language-agnostic. Also: local embeddings
to replace TF-IDF for stronger recall, and a .plugin bundle of the skill.
MIT.