Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
rename: Context Graph Engine → Graft (@nanonets/graft on npm)
Shrish Dwivedi3406809ff4ad
diff --git a/.env.example b/.env.exampleindex 6401b6c8..4763dd3d 100644--- a/.env.example+++ b/.env.example@@ -1,6 +1,6 @@-# Context Graph Engine — configuration+# Graft — configuration#-# The engine calls OpenRouter for extraction and summaries, so an API key is+# Graft calls OpenRouter for extraction and summaries, so an API key is# required for any LLM-backed step (`init`, `graph --llm`). Get one at:# https://openrouter.ai/keys#@@ -10,10 +10,10 @@# --- OpenRouter (required for LLM steps) --------------------------------------# OPENROUTER_API_KEY=sk-or-...# Optional: override the model (default: openai/gpt-4o-mini)-# CONTEXT_GRAPH_OPENROUTER_MODEL=openai/gpt-4o-mini+# GRAFT_OPENROUTER_MODEL=openai/gpt-4o-mini# Optional: override the API base URL (default: https://openrouter.ai/api/v1)# OPENROUTER_BASE_URL=https://openrouter.ai/api/v1# --- Graph location -----------------------------------------------------------# Where the graph lives (default: <repo>/.context)-# CONTEXT_GRAPH_DIR=.context+# GRAFT_DIR=.contextdiff --git a/README.md b/README.mdindex 11b1c42d..6f2b5b37 100644--- a/README.md+++ b/README.md@@ -9,9 +9,9 @@**Graft gives it the map it should have read first.**<p>- <a href="https://www.npmjs.com/package/graft"><img src="https://img.shields.io/npm/v/graft?style=for-the-badge&logo=npm&logoColor=white&label=npm" /></a>- <a href="https://www.npmjs.com/package/graft"><img src="https://img.shields.io/npm/dm/graft?style=for-the-badge&logo=npm&logoColor=white&label=downloads" /></a>- <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/graft?style=for-the-badge&logo=nodedotjs&logoColor=white" /></a>+ <a href="https://www.npmjs.com/package/@nanonets/graft"><img src="https://img.shields.io/npm/v/%40nanonets%2Fgraft?style=for-the-badge&logo=npm&logoColor=white&label=npm" /></a>+ <a href="https://www.npmjs.com/package/@nanonets/graft"><img src="https://img.shields.io/npm/dm/%40nanonets%2Fgraft?style=for-the-badge&logo=npm&logoColor=white&label=downloads" /></a>+ <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/%40nanonets%2Fgraft?style=for-the-badge&logo=nodedotjs&logoColor=white" /></a><img src="https://img.shields.io/badge/TypeScript-strict-3178C6?style=for-the-badge&logo=typescript&logoColor=white" /><img src="https://img.shields.io/badge/License-MIT-20C997?style=for-the-badge" /><img src="https://img.shields.io/badge/runs-100%25%20local-546FFF?style=for-the-badge&logo=ollama&logoColor=white" />@@ -37,14 +37,19 @@ flowchart LR## Quick start```bash-npx graft init+npx @nanonets/graft init# builds .context/ from your code, one node per system, API, or conceptgit add .context && git commit -m "add context graph"# commit it so everyone who clones the repo (and their agents) gets the graph```-<!-- placeholder: package publish + `graft` rename pending; until then the bin is `context-graph` -->+Or install it once and get the `graft` command everywhere:++```bash+npm install -g @nanonets/graft+graft init+```That is it. Point your agent at `.context/` and it reads the graph before it starts working.diff --git a/bench/run.ts b/bench/run.tsindex ec676c72..2119294a 100644--- a/bench/run.ts+++ b/bench/run.ts@@ -15,7 +15,7 @@ import { mkdtempSync, mkdirSync, writeFileSync, copyFileSync, readdirSync, rmSynimport { tmpdir } from "node:os";import { join, dirname, resolve, basename } from "node:path";import { fileURLToPath } from "node:url";-import { ContextGraphEngine } from "../src/index.js";+import { Graft } from "../src/index.js";import { DOC_EXTENSIONS } from "../src/ingest/fs.js";import { extractPdfText, isPdfPath } from "../src/ingest/pdf.js";import { CORPORA, type Corpus } from "./tasks.js";@@ -105,7 +105,7 @@ async function main() {// Fresh temp-backed engine; ingest once and reuse for the whole corpus.const dbDir = mkdtempSync(join(tmpdir(), "cge-bench-db-"));tmpDbDirs.push(dbDir);- const engine = new ContextGraphEngine({ dbPath: join(dbDir, "graph.db") });+ const engine = new Graft({ dbPath: join(dbDir, "graph.db") });let agentRoot = corpus.path;let docsWorkdir: string | undefined;diff --git a/install.sh b/install.shindex c3b262e5..da117a97 100755--- a/install.sh+++ b/install.sh@@ -1,22 +1,22 @@#!/usr/bin/env sh-# Context Graph Engine — one-line installer.+# Graft — one-line installer.## Two ways to use it:# 1. From a checkout: ./install.sh (builds THIS directory — no re-clone)# 2. Over the network: curl -fsSL https://raw.githubusercontent.com/NanoNets/context-graph-engine/main/install.sh | sh#-# Either way it builds the project and puts the `context-graph` command on your+# Either way it builds the project and puts the `graft` command on your# PATH. Requires git, Node >= 20, and npm.## Environment overrides:-# CGE_REPO git URL to clone from (default: the NanoNets repo below)-# CGE_REF branch/tag/commit to fetch (default: main)-# CGE_HOME where to clone into (default: ~/.context-graph-engine)+# GRAFT_REPO git URL to clone from (default: the NanoNets repo below)+# GRAFT_REF branch/tag/commit to fetch (default: main)+# GRAFT_HOME where to clone into (default: ~/.graft)set -eu-REPO_URL="${CGE_REPO:-https://github.com/NanoNets/context-graph-engine.git}"-REF="${CGE_REF:-main}"-INSTALL_DIR="${CGE_HOME:-$HOME/.context-graph-engine}"+REPO_URL="${GRAFT_REPO:-https://github.com/NanoNets/context-graph-engine.git}"+REF="${GRAFT_REF:-main}"+INSTALL_DIR="${GRAFT_HOME:-$HOME/.graft}"info() { printf '\033[1;36m›\033[0m %s\n' "$1"; }err() { printf '\033[1;31m✗ %s\033[0m\n' "$1" >&2; }@@ -44,7 +44,7 @@ case "${0:-}" in*/*) SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" 2>/dev/null && pwd) || SCRIPT_DIR="" ;;esac-if [ -n "$SCRIPT_DIR" ] && grep -q '"context-graph-engine"' "$SCRIPT_DIR/package.json" 2>/dev/null; then+if [ -n "$SCRIPT_DIR" ] && grep -q '"@nanonets/graft"' "$SCRIPT_DIR/package.json" 2>/dev/null; thenINSTALL_DIR="$SCRIPT_DIR"info "Installing from local checkout at $INSTALL_DIR"else@@ -66,7 +66,7 @@ info "Installing dependencies"info "Building"( cd "$INSTALL_DIR" && npm run build --silent )-info "Linking the 'context-graph' command"+info "Linking the 'graft' command"( cd "$INSTALL_DIR" && npm link >/dev/null 2>&1 )echo@@ -75,11 +75,11 @@ cat <<'NEXT'Build the graph, then commit it:cd your-repo- context-graph init # writes .context/*.md from your code+ graft init # writes .context/*.md from your codegit add .context && git commit -m "add context graph"Keep it honest in CI:- context-graph check # exits non-zero if the graph is stale+ graft check # exits non-zero if the graph is staleRuns locally out of the box:• Extraction/summaries default to a local Ollama model. Install Ollama anddiff --git a/src/ai/providers.ts b/src/ai/providers.tsindex d269cd83..5dc6019d 100644--- a/src/ai/providers.ts+++ b/src/ai/providers.ts@@ -7,12 +7,12 @@ import type { Synthesizer } from "./synthesize.js";* API key is required for any LLM-backed operation.*/export interface EngineConfig {- /** Where the graph lives. Env: CONTEXT_GRAPH_DIR. Default: `<repo>/.context`. */+ /** Where the graph lives. Env: GRAFT_DIR. Default: `<repo>/.context`. */contextDir?: string;/** OpenRouter key for extraction + summarization. Env: OPENROUTER_API_KEY. */openrouterApiKey?: string;- /** OpenRouter model id. Env: CONTEXT_GRAPH_OPENROUTER_MODEL. Default: openai/gpt-4o-mini */+ /** OpenRouter model id. Env: GRAFT_OPENROUTER_MODEL. Default: openai/gpt-4o-mini */openrouterModel?: string;/** OpenRouter API base URL. Env: OPENROUTER_BASE_URL. Default: https://openrouter.ai/api/v1 */openrouterBaseUrl?: string;@@ -43,10 +43,10 @@ export const DEFAULTS = {export function resolveConfig(config: EngineConfig = {}): ResolvedConfig {const env = process.env;return {- contextDir: config.contextDir ?? env.CONTEXT_GRAPH_DIR,+ contextDir: config.contextDir ?? env.GRAFT_DIR,openrouterApiKey: config.openrouterApiKey ?? env.OPENROUTER_API_KEY,openrouterModel:- config.openrouterModel ?? env.CONTEXT_GRAPH_OPENROUTER_MODEL ?? DEFAULTS.openrouterModel,+ config.openrouterModel ?? env.GRAFT_OPENROUTER_MODEL ?? DEFAULTS.openrouterModel,openrouterBaseUrl:config.openrouterBaseUrl ?? env.OPENROUTER_BASE_URL ?? DEFAULTS.openrouterBaseUrl,synthesizer: config.synthesizer,diff --git a/src/context/check.ts b/src/context/check.tsindex ee0f6775..2f53bed8 100644--- a/src/context/check.ts+++ b/src/context/check.ts@@ -4,7 +4,7 @@* Pure I/O + hashing: no LLM, no network, milliseconds. It re-hashes the source* files the manifest recorded and compares. Meant to run in CI: exit 0 when the* graph is fresh, 1 when it has drifted (so a PR that changed code but not the- * graph fails until `context-graph init` is re-run and committed).+ * graph fails until `graft init` is re-run and committed).** Drift categories:* content a recorded source file's bytes changed@@ -109,11 +109,11 @@ export function checkContext(dir: string, opts: CheckOptions = {}): CheckResult/** Render a check result as a human-readable report. */export function formatCheckReport(r: CheckResult): string {if (r.missing) {- return "context-graph check: NO GRAPH\n\nNo .context/manifest.json found. Run `context-graph init` first.";+ return "graft check: NO GRAPH\n\nNo .context/manifest.json found. Run `graft init` first.";}- if (r.ok) return "context-graph check: OK — the graph is in sync with the code.";+ if (r.ok) return "graft check: OK — the graph is in sync with the code.";- const lines: string[] = ["context-graph check: STALE", ""];+ const lines: string[] = ["graft check: STALE", ""];if (r.contentDrift.length) {lines.push(`changed (${r.contentDrift.length}):`);for (const c of r.contentDrift) lines.push(` ~ ${c.path} (${c.from} → ${c.to})`);@@ -130,7 +130,7 @@ export function formatCheckReport(r: CheckResult): string {lines.push(`index mismatch (${r.indexDrift.length}):`);for (const s of r.indexDrift) lines.push(` ! ${s}`);}- lines.push("", "Run `context-graph init` to regenerate, then commit .context/.");+ lines.push("", "Run `graft init` to regenerate, then commit .context/.");return lines.join("\n");}diff --git a/src/engine.ts b/src/engine.tsindex ce80315c..135221dd 100644--- a/src/engine.ts+++ b/src/engine.ts@@ -2,8 +2,8 @@* The Context Graph Engine.** Two operations, no database:- * - {@link ContextGraphEngine.init} build `.context/` from a code repo.- * - {@link ContextGraphEngine.check} report whether `.context/` is still in+ * - {@link Graft.init} build `.context/` from a code repo.+ * - {@link Graft.check} report whether `.context/` is still in* sync with the code (for CI).** The graph is a folder of linked markdown files committed to the repo; git is@@ -39,7 +39,7 @@ export interface GraphRunOptions {onProgress?: GraphBuildOptions["onProgress"];}-export class ContextGraphEngine {+export class Graft {private cfg: ResolvedConfig;constructor(config: EngineConfig = {}) {diff --git a/src/graph/check.ts b/src/graph/check.tsindex 0e6ae7aa..5f35f96a 100644--- a/src/graph/check.ts+++ b/src/graph/check.ts@@ -103,7 +103,7 @@ export function checkGraph(dir: string, opts: GraphCheckOptions = {}): GraphChec/** Render a graph-check result as a human-readable report. */export function formatGraphCheckReport(r: GraphCheckResult): string {if (r.missing) {- return "graph check: NO GRAPH\n\nNo .context/graph.json found. Run `context-graph graph` first.";+ return "graph check: NO GRAPH\n\nNo .context/graph.json found. Run `graft graph` first.";}if (r.ok) {const note = r.pending ? ` (${r.pending} node(s) not yet summarized — run \`graph --llm\`)` : "";@@ -129,7 +129,7 @@ export function formatGraphCheckReport(r: GraphCheckResult): string {for (const id of r.stale) lines.push(` ! ${id}`);}lines.push("");- if (structural) lines.push("Run `context-graph graph` to rebuild the structure, then commit .context/.");- if (r.stale.length) lines.push("Run `context-graph graph --llm` to refresh stale summaries.");+ if (structural) lines.push("Run `graft graph` to rebuild the structure, then commit .context/.");+ if (r.stale.length) lines.push("Run `graft graph --llm` to refresh stale summaries.");return lines.join("\n");}diff --git a/src/index.ts b/src/index.tsindex f3303c58..34ce34c8 100644--- a/src/index.ts+++ b/src/index.ts@@ -1,21 +1,21 @@/**- * Context Graph Engine — public API.+ * Graft — public API.** The graph is a folder of linked markdown files (`.context/`) committed to the* repo. Build it from code, then check it stays in sync.** @example* ```ts- * import { ContextGraphEngine } from "context-graph-engine";+ * import { Graft } from "@nanonets/graft";*- * const engine = new ContextGraphEngine();+ * const engine = new Graft();* await engine.init("."); // writes .context/*.md + manifest.json** const result = engine.check("."); // { ok: boolean, ...drift }* if (!result.ok) process.exitCode = 1;* ```*/-export { ContextGraphEngine, CODE_EXTENSIONS } from "./engine.js";+export { Graft, CODE_EXTENSIONS } from "./engine.js";export type { InitOptions, CheckRunOptions, BuildResult, BuildProgress, CheckResult } from "./engine.js";export { buildContext } from "./context/build.js";