npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ai-agent-context/core

v0.3.7

Published

Core of ai-agent-context: repository knowledge graph, architecture detection, incremental scanning, deterministic .agent/ serialization. Local-first, zero runtime dependencies, no LLM required.

Readme

@ai-agent-context/core

Core analysis engine for ai-agent-context.

This package provides the repository analysis capabilities without any CLI or MCP dependencies. It's designed to be:

  • Local-first: 100% local execution, no external API calls
  • Deterministic: Same repository state → identical context
  • Extensible: Pluggable language adapters, detectors, and analyzers
  • Zero runtime dependencies: Works with only Node.js built-ins

Installation

npm install @ai-agent-context/core

Usage

import { AgentContext } from '@ai-agent-context/core';

const context = await AgentContext.load({ root: process.cwd() });

// Scan repository
await context.scan();

// Explain a module
const module = await context.explain('src/payments');

// Get architecture
const architecture = await context.getArchitecture();

// Get dependencies
const dependencies = await context.getDependencies();

// Search context
const results = await context.search('payment idempotency');

API

AgentContext

Main entry point for repository analysis.

class AgentContext {
  static async load(options?: AgentContextOptions): Promise<AgentContext>
  async scan(options?: ScanOptions): Promise<ScanReport>
  async getRepositoryContext(options?: RepositoryContextOptions): Promise<RepositoryContext>
  async getTaskContext(task: string, options?: { target?: string; maxModules?: number }): Promise<TaskContext>
  async getChangeImpact(target: string, options?: { maxFiles?: number }): Promise<ChangeImpact>
  async getModuleHistory(target: string, options?: { limit?: number }): Promise<ModuleHistoryEntry[]>
  async getRevisionDiff(revision: string, base?: string): Promise<RevisionDiff>
  async getRevisionSnapshot(revision: string): Promise<RevisionSnapshot>
  async explain(target: string): Promise<ModuleExplanation | null>
  async diff(): Promise<ContextDiff>
  async status(): Promise<StatusReport>
  async getRepository(): Promise<Repository>
  async getArchitecture(): Promise<ArchitectureDocument>
  async getDependencies(): Promise<DependenciesDocument>
  async getConventions(): Promise<Convention[]>
  async getDecisions(): Promise<Decision[]>
  async search(query: string, options?: SearchOptions): Promise<SearchResult[]>
  async init(options?: { force?: boolean }): Promise<InitResult>
}

Scanner

Repository scanner and file classification.

import { scanRepository, classifyFile } from '@ai-agent-context/core';

const output = await scanRepository(root, options);
const classification = classifyFile(filePath, language);

Knowledge Graph

Builds a repository knowledge graph from parsed files.

import { buildKnowledgeGraph, buildModules } from '@ai-agent-context/core';

const graph = buildKnowledgeGraph(input);
const modules = buildModules(files, basePath);

Architecture Detection

Detects module roles, entry points, and responsibilities.

import {
  detectEntryPoints,
  detectModuleRoles,
  detectResponsibilities,
  applyArchitectureDetection
} from '@ai-agent-context/core';

const entryPoints = detectEntryPoints(input);
const roles = detectModuleRoles(module);
const responsibilities = detectResponsibilities(module);
const enhanced = applyArchitectureDetection(graph);

Convention Detection

Detects observable coding conventions.

import { detectConventions, renderConventionsMarkdown } from '@ai-agent-context/core';

const conventions = detectConventions(input);
const markdown = renderConventionsMarkdown(conventions, repositoryName);

Decision Detection

Extracts architectural decisions from ADRs and configuration.

import { detectDecisions, parseAdrDocument } from '@ai-agent-context/core';

const decisions = detectDecisions(input);
const adr = parseAdrDocument(content, path);

Architecture Analysis

getArchitecture() includes summary.layeringViolations and layeringViolations with from, to, kind, confidence and evidence.

getModuleHistory(target, { limit }) returns bounded Git history for a module. getRevisionDiff(revision, base) returns changed paths and statuses, including renames.

import { GitAdapter, computeGitActivity } from '@ai-agent-context/core';

const adapter = new GitAdapter(root);
const availability = await adapter.checkAvailability();
const commits = await adapter.getRecentCommits(limit);
const activity = computeGitActivity(input);

Search

Deterministic lexical search over repository context.

import { SearchService, Bm25Index } from '@ai-agent-context/core';

const service = SearchService.fromGraph({ graph, parsed });
const results = service.search(query, options);

Serialization

Reads and writes .agent/ context files.

import {
  readPersistedContext,
  writeContext,
  serializeContextDocuments
} from '@ai-agent-context/core';

const persisted = await readPersistedContext(root);
await writeContext(root, documents, options);

Language Adapters

TypeScript/JavaScript

import { TsJsAdapter } from '@ai-agent-context/core';

const adapter = new TsJsAdapter();
const parsed = await adapter.parse(filePath, content, language);

JSON

import { JsonAdapter } from '@ai-agent-context/core';

const adapter = new JsonAdapter();
const parsed = await adapter.parse(filePath, content, language);

Markdown

import { MarkdownAdapter } from '@ai-agent-context/core';

const adapter = new MarkdownAdapter();
const parsed = await adapter.parse(filePath, content, language);

Package.json

import { PackageJsonAdapter } from '@ai-agent-context/core';

const adapter = new PackageJsonAdapter();
const parsed = await adapter.parse(filePath, content, language);

tsconfig.json

import { TsConfigAdapter } from '@ai-agent-context/core';

const adapter = new TsConfigAdapter();
const parsed = await adapter.parse(filePath, content, language);

Utilities

Path Utilities

import {
  toPosix,
  normalizeRelative,
  dirname,
  basename,
  extname,
  join,
  isInside,
  ancestors,
  relativeTo
} from '@ai-agent-context/core';

Text Utilities

import {
  classifyIdentifierCase,
  splitIdentifier,
  truncate,
  formatDate,
  ratio,
  pluralize
} from '@ai-agent-context/core';

Pattern Matching

import { PatternSet, compileGlob, compileRule } from '@ai-agent-context/core';

Configuration

import {
  loadConfig,
  DEFAULT_CONFIG,
  DEFAULT_INCLUDE,
  DEFAULT_EXCLUDE
} from '@ai-agent-context/core';

const config = await loadConfig({ root: process.cwd() });

Error Handling

import {
  AgentContextError,
  ConfigError,
  AnalysisError,
  ContextStateError,
  isAgentContextError
} from '@ai-agent-context/core';

try {
  await context.scan();
} catch (error) {
  if (isAgentContextError(error)) {
    console.error(error.message);
    console.error(error.suggestions);
  }
}

Security

See the repository SECURITY.md. The core performs no network calls, excludes sensitive files by default, redacts secret-like excerpts, and does not follow symlinks unless explicitly configured.

License

MIT