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

@repocode/core

v0.4.0

Published

Core engine for RepoCode — repository analysis, ranking, token-budgeting, and AI-ready context assembly

Readme

@repocode/core

Core engine for RepoCode — repository analysis, ranking, token-budgeting, and AI-ready context assembly. Use this package to embed context packing in your own tools.

Developed by Nextbridge.

Why embed RepoCode?

When building your own AI tools, agents, or editor extensions, naive file-globbing and string concatenation quickly hit token limits or silently drop important context. @repocode/core provides a full, unopinionated pipeline to discover files, trace import graphs, rank files by structural importance, and squeeze the most useful context into a strict token budget. It handles the parsing, ranking, git diffs, caching, and token counting so your tool can focus on the AI experience.

Install

npm install @repocode/core

Quick Start

import { loadConfig, runPipeline } from '@repocode/core';

const config = await loadConfig('/path/to/repo', {
  budget: { maxTokens: 100000 },
  output: { format: 'xml' },
});

const result = await runPipeline(config);
console.log(result.output);           // packed context string
console.log(result.totalTokens);      // accurate token count of included files
console.log(result.outputTokens);     // estimated tokens of the full serialized output
console.log(result.included.length);  // number of files included

API

loadConfig(root, overrides, preset?, options?)

loadConfig(
  root: string,
  overrides: Partial<RepoCodeConfig>,
  preset?: string,
  options?: { allowJsConfig?: boolean }
): Promise<RepoCodeConfig>

Reads repocode.config.json from root, deep-merges with overrides, applies the optional named preset, and returns a fully resolved config.

  • root — absolute path to the repository root
  • overrides — any config fields to override after reading the file
  • preset — name of a language preset to apply (ts-library, py-service, go-service, rust-crate, java-maven)
  • options.allowJsConfig — if true, also accepts repocode.config.js / .mjs files (CLI mode); default is false — omit or set false in server/MCP contexts to block arbitrary code execution

runPipeline(config)

runPipeline(config: RepoCodeConfig): Promise<PackResult>

Runs the full pipeline: discover → rank → budget-fit → compress → assemble → format. Returns a PackResult.

startWatch(options)

startWatch(options: {
  config: RepoCodeConfig;
  debounceMs?: number;
  onRepack: (result: PackResult, changedPaths?: string[]) => void | Promise<void>;
  onError?: (err: Error) => void;
}): Promise<{ stop: () => Promise<void> }>

Starts a file watcher on config.root. Calls onRepack after each debounced change batch. Returns a handle with stop(), which waits for any in-flight repack to complete before closing the watcher.

  • debounceMs — milliseconds to wait after the last change before repacking (default: 2000)
  • onRepack — called with the new PackResult and the list of changed file paths
  • onError — optional; called if the watcher or pipeline throws

Key Types

PackResult

interface PackResult {
  output: string;           // the packed context string
  totalTokens: number;      // accurate token count of included files
  outputTokens: number;     // estimated tokens of the full serialized output
  included: BudgetFile[];   // files that made it in
  excluded: ExcludedFile[]; // files that were cut, with reason
  budget: TokenBudget | null; // null when --no-budget
  timingMs: number;         // pipeline wall time in milliseconds
}

outputTokens is a fast character-heuristic estimate of the serialized output size — useful for checking whether the output will fit in an LLM context window.

RepoCodeConfig (key fields)

interface RepoCodeConfig {
  root: string;
  budget: { maxTokens: number } | false;
  output: {
    format: 'xml' | 'markdown' | 'plain' | 'json';
    path?: string;
    preamble: boolean;
  };
  compress: 'none' | 'tier1-regex' | 'tier2-structural' | 'tier3-llm' | 'partial' | SelectiveCompressConfig;
  security: {
    enabled: boolean;
    mode: 'warn' | 'exclude' | 'redact' | 'fail';
  };
  include: string[];
  exclude: string[];
}

TypeScript

The package ships full .d.ts declarations. No @types/ install needed. Requires TypeScript 5+ and "moduleResolution": "bundler" or "node16".

Security Notes (MCP / server usage)

When embedding @repocode/core in a server or MCP context:

  • Pass allowJsConfig: false (the default) to loadConfig — this blocks .js/.mjs config files and prevents arbitrary code execution triggered by a malicious repository
  • Use security.mode: 'redact' to replace detected secrets (API keys, tokens, private key headers) with [REDACTED] before any LLM compression call or cache write

Links