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

codelapse-core

v0.9.5

Published

Shared core functionality for CodeLapse CLI and VS Code extension

Readme

codelapse-core

Shared core functionality for CodeLapse CLI and VS Code extension.

Overview

This package contains all the core snapshot management logic that's shared between the CLI and VS Code extension. It has no VS Code dependencies and can be used standalone.

Installation

npm install codelapse-core

For local development:

npm install file:../shared

Features

  • Snapshot Management: Create, restore, delete, compare snapshots
  • Configuration: Unified config system with multiple sources
  • Git Integration: Read-only Git operations
  • Diff Operations: Efficient diff-based storage
  • Gitignore Support: Respects .gitignore and .snapshotignore

Quick Start

import { SnapshotManager, ConfigManager } from 'codelapse-core';

// Initialize managers
const workspaceRoot = '/path/to/workspace';
const config = new ConfigManager(workspaceRoot);
const manager = new SnapshotManager(workspaceRoot);

// Take a snapshot
const snapshot = await manager.takeSnapshot({
  description: 'My snapshot',
  tags: ['feature', 'backup'],
});

// List snapshots
const snapshots = manager.getSnapshots();

// Filter snapshots
const favorites = manager.getSnapshots({ favorite: true });
const tagged = manager.getSnapshots({ tag: 'feature' });

// Restore a snapshot
await manager.restoreSnapshot(snapshot.id, {
  backup: true, // Create backup before restore
});

// Compare snapshots
const comparison = await manager.compareSnapshots(id1, id2);
console.log('Modified files:', comparison.modifiedFiles);

// Delete a snapshot
await manager.deleteSnapshot(snapshot.id);

API Reference

SnapshotManager

Main class for snapshot operations.

class SnapshotManager {
  constructor(workspaceRoot: string);

  // Snapshot operations
  takeSnapshot(options: SnapshotOptions): Promise<Snapshot>;
  getSnapshots(filter?: SnapshotFilter): Snapshot[];
  getSnapshot(snapshotId: string): Promise<Snapshot | null>;
  restoreSnapshot(snapshotId: string, options?: RestoreOptions): Promise<void>;
  deleteSnapshot(snapshotId: string): Promise<void>;
  compareSnapshots(id1: string, id2: string): Promise<SnapshotComparison>;

  // Metadata operations
  updateSnapshotMetadata(snapshotId: string, updates: Partial<Snapshot>): Promise<void>;

  // File operations
  getSnapshotFileContent(snapshotId: string, filePath: string): Promise<string | null>;

  // Utility
  getStorageStats(): Promise<StorageStats>;
  reload(): Promise<void>;
}

ConfigManager

Manages configuration with fallback chain.

class ConfigManager {
  constructor(workspaceRoot: string);

  // Get/Set config
  getConfig(): CodelapseConfig;
  get<K extends keyof CodelapseConfig>(key: K): CodelapseConfig[K];
  set<K extends keyof CodelapseConfig>(key: K, value: CodelapseConfig[K]): Promise<void>;
  getNested(keyPath: string): any;
  setNested(keyPath: string, value: any): Promise<void>;

  // Import/Export
  exportConfig(): string;
  importConfig(json: string): Promise<void>;

  // Utility
  validate(): { valid: boolean; errors: string[] };
  reset(): Promise<void>;
  clearCache(): void;
}

GitIntegration

Read-only Git operations.

class GitIntegration {
  constructor(workspaceRoot: string);

  isGitRepository(): boolean;
  getGitInfo(): GitInfo | null;
  getCurrentBranch(): string | undefined;
  getCurrentCommit(): string | undefined;
  hasUncommittedChanges(): boolean;
  getRemoteUrl(): string | undefined;
  getChangedFiles(): string[];
  getCommitHistory(limit?: number): Array<CommitInfo>;
}

GitignoreParser

Parse and apply gitignore rules.

class GitignoreParser {
  constructor(workspaceRoot: string, snapshotLocation?: string);

  shouldIgnore(filePath: string): boolean;
  getExcludeGlobPattern(): string;
  getNegatedGlobs(): string[];
  getPatterns(): string[];
}

Diff Utilities

// Create a diff between two strings
function createDiff(fileName: string, oldContent: string, newContent: string): string;

// Apply a diff patch
function applyDiff(baseContent: string, patchStr: string, fileName: string): string | null;

// Generate diff summary
function generateDiffSummary(oldContent: string, newContent: string): {
  additions: number;
  deletions: number;
  changes: number;
};

// Format diff for terminal
function formatDiffForTerminal(diffString: string): string;

Types

Snapshot

interface Snapshot {
  id: string;
  timestamp: number;
  description: string;
  gitBranch?: string;
  gitCommitHash?: string;
  tags?: string[];
  notes?: string;
  taskReference?: string;
  isFavorite?: boolean;
  isSelective?: boolean;
  selectedFiles?: string[];
  files: {
    [relativePath: string]: {
      content?: string | null;
      diff?: string;
      baseSnapshotId?: string;
      deleted?: boolean;
      isBinary?: boolean;
    };
  };
}

SnapshotOptions

interface SnapshotOptions {
  description?: string;
  tags?: string[];
  notes?: string;
  taskReference?: string;
  isFavorite?: boolean;
  isSelective?: boolean;
  selectedFiles?: string[];
}

SnapshotFilter

interface SnapshotFilter {
  tag?: string;
  favorite?: boolean;
  startDate?: number;
  endDate?: number;
  search?: string;
  filePath?: string;
}

CodelapseConfig

interface CodelapseConfig {
  snapshotLocation: string;
  maxSnapshots: number;
  git: {
    addCommitInfo: boolean;
    autoSnapshotBeforeOperation: boolean;
  };
  semanticSearch?: {
    enabled: boolean;
    provider?: string;
    apiKey?: string;
    chunkSize?: number;
    autoIndex?: boolean;
  };
}

Configuration

The package reads configuration from multiple sources:

  1. File: .vscode/codelapse.json in workspace root
  2. Environment Variables: CODELAPSE_* variables
  3. Defaults: Built-in default values

Configuration File Example

{
  "snapshotLocation": ".snapshots",
  "maxSnapshots": 50,
  "git": {
    "addCommitInfo": true,
    "autoSnapshotBeforeOperation": false
  }
}

Environment Variables

export CODELAPSE_SNAPSHOT_LOCATION=".my-snapshots"
export CODELAPSE_MAX_SNAPSHOTS=100
export GEMINI_API_KEY="your-api-key"

Storage

Snapshots are stored in the .snapshots/ directory (configurable):

.snapshots/
├── index.json                    # Snapshot index
├── snapshot-123-abc.json        # Snapshot metadata + files
├── snapshot-456-def.json        # Another snapshot
└── ...

Index Format

{
  "snapshots": [
    {
      "id": "snapshot-123-abc",
      "timestamp": 1234567890,
      "description": "My snapshot"
    }
  ],
  "currentIndex": 0
}

Snapshot Format

Each snapshot file contains:

  • Metadata (id, timestamp, description, tags, etc.)
  • File data (content or diff from base snapshot)
  • Git information (branch, commit)

Performance

  • Diff-based storage: Only stores changes between snapshots
  • Content caching: LRU cache for file content retrieval
  • Gitignore support: Efficiently filters files
  • Binary detection: Skips binary files

Error Handling

All async operations may throw errors. Wrap in try-catch:

try {
  const snapshot = await manager.takeSnapshot({ description: 'Test' });
} catch (error) {
  console.error('Failed to take snapshot:', error);
}

Development

Build

npm run build

Watch Mode

npm run watch

Clean

npm run clean

Dependencies

  • minimatch - Glob pattern matching
  • diff - Diff generation and application
  • uuid - Unique ID generation

License

MIT

Related Packages

  • codelapse-cli: Command-line interface
  • vscode-snapshots: VS Code extension

Support

For issues and questions:

  • GitHub Issues: https://github.com/YukioTheSage/code-snapshots/issues
  • Documentation: https://github.com/YukioTheSage/code-snapshots