New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

anydocs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anydocs

Documentation search CLI using SQLite FTS5 full-text search with Porter stemming and BM25 ranking

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

anydocs

Markdown documentation search CLI using SQLite FTS5 full-text search.

Features

  • Full-text search with SQLite FTS5 and Porter stemming
  • Fast local indexing with better-sqlite3
  • Simple CLI with docs and search commands
  • WAL mode enabled for better concurrency
  • BM25 ranking for search results

Installation

pnpm install
pnpm run build

Quick Start

# 1. Install globally
npm install -g anydocs
# or
pnpm install -g anydocs

# 2. Initialize anydocs
anydocs init

# 3. Edit config file at ~/.config/anydocs/anydocs.json
cat > ~/.config/anydocs/anydocs.json << 'EOF'
{
  "projects": [
    { "repo": "vercel/next.js" }
  ]
}
EOF

# 4. Install (clone and index) projects
anydocs install

# 5. Search for content
anydocs search "routing" -n 5

# 6. Retrieve a specific document
anydocs docs /docs/app/getting-started.md --project next.js

Usage

Configure Projects

Edit ~/.config/anydocs/anydocs.json to define projects:

{
  "projects": [
    { "repo": "vercel/next.js" },
    { "repo": "facebook/react" },
    {
      "repo": "github.com/vuejs/core",
      "name": "vue3",
      "ref": "v3.4.0",
      "path": "packages/*/README.md"
    }
  ]
}

Configuration fields:

  • repo (required): Repository in owner/repo or host/owner/repo format
  • name (optional): Project name, defaults to repo name (e.g., "next.js")
  • ref (optional): Git branch or tag, defaults to repository's default branch
  • path (optional): Glob pattern for indexing, defaults to **/*.{md,mdx}
  • sparse-checkout (optional): Array of paths for sparse checkout
  • options (optional): Additional CLI options

Install Projects

Install (clone and index) all configured projects:

# Install all projects
anydocs install

# Install specific project only
anydocs install --project next.js

What install does:

  • Clones repositories to ~/.local/share/anydocs/repos/host/owner/repo
  • Creates symlinks under ~/.local/share/anydocs/docs/
  • Indexes Markdown files matching the glob pattern
  • Updates lockfile at ~/.local/share/anydocs/anydocs-lock.yaml
  • Idempotent: re-running updates existing installations

Search Documents

# Basic search
anydocs search "hello"

# Limit number of results
anydocs search "world" -n 5

# Search with FTS5 query syntax
anydocs search "hello AND world"
anydocs search '"exact phrase"'
anydocs search "run*"  # Prefix search
anydocs search "hello OR world"
anydocs search "hello NOT world"

Search output (JSON):

[
  {
    "path": "/guide/intro.md",
    "title": "Getting Started",
    "snippet": "Welcome to the <b>documentation</b> system!",
    "score": -0.0000015
  }
]

Retrieve Document

Retrieve the raw Markdown content:

anydocs docs /guide/intro.md --project next.js

Output is the original Markdown with front-matter removed.

Complete Example

# Initialize anydocs
anydocs init

# Configure projects
cat > ~/.config/anydocs/anydocs.json << 'EOF'
{
  "projects": [
    { "repo": "vercel/next.js" },
    { "repo": "facebook/react" }
  ]
}
EOF

# Install all projects
anydocs install

# Search across all projects
anydocs search "hooks" -n 5

# Search specific project
anydocs search "routing" --project next.js

# Get specific document
anydocs docs /docs/app/routing.md --project next.js

# Re-install (updates existing entries)
anydocs install

Architecture

  • Config: ~/.config/anydocs/anydocs.json (user-editable project list)
  • Lockfile: ~/.local/share/anydocs/anydocs-lock.yaml (auto-generated)
  • Repositories: ~/.local/share/anydocs/repos/host/owner/repo
  • Symlinks: ~/.local/share/anydocs/docs/project-name
  • Database: ~/.local/share/anydocs/db/default.db (SQLite FTS5)
  • Schema: pages(path UNINDEXED, project UNINDEXED, title, body) USING fts5(tokenize='porter')
  • Output:
    • docs: Raw Markdown to stdout
    • search: JSON array with {path, project, title, snippet, score}

Search Features

  • Porter stemming: run matches running
  • FTS5 syntax: AND/OR/NOT, phrases, NEAR, prefix search with *
  • Highlighting: Search snippets with <b>...</b> tags
  • BM25 scoring: Relevance-ranked results

TODO

  • Implement index <root> [pattern] command to recursively index Markdown files
  • Parse and extract front-matter
  • Extract first heading as title
  • Normalize paths (relative from root, starting with /)
  • Make indexing idempotent (replace existing paths)
  • Add transactional batch indexing
  • Add init command for directory setup
  • Add install command with anydocs.json config
  • Support ghq-style repository paths (owner/repo or host/owner/repo)
  • Auto-detect repository default branch
  • Generate lockfile (anydocs-lock.yaml)
  • Support differential re-indexing with mtime tracking
  • Implement export-llms command for llms.txt generation
  • Add CLI package installation (npm/pnpm global install)
  • Add progress indicator for large indexing jobs

Specification

  • Configuration: ~/.config/anydocs/anydocs.json defines projects with minimal required fields
  • Repository format: Supports owner/repo (implies GitHub) or host/owner/repo
  • Default values: Only repo required; name, ref, path have smart defaults
  • Lockfile: Auto-generated anydocs-lock.yaml tracks cloned refs and timestamps
  • Storage: Repositories at $XDG_DATA_HOME/anydocs/repos/host/owner/repo
  • Database: Single FTS5 database at $XDG_DATA_HOME/anydocs/db/default.db
  • Schema: pages(path UNINDEXED, project UNINDEXED, title, body) USING fts5(tokenize='porter')
  • Commands:
    • init: Create directory structure and empty config
    • install [--project name]: Clone repos and index docs
    • search <query> [-n N] [--project name]: Full-text search
    • docs <path> [--project name]: Retrieve document
  • Indexing: Strip front-matter, extract first # ... as title
  • Idempotent: Re-running install updates existing installations
  • Path normalization: Relative from repo root, /-separated, starts with /
  • Search: BM25 ranking, Porter stemming, FTS5 syntax (AND/OR/NOT/NEAR/*)
  • Output: JSON with fixed key order, snippets with <b>...</b> highlighting
  • Error handling: Exit non-zero on errors, empty array for no results
  • Runtime: Node.js with better-sqlite3, TypeScript, works with pnpm

Development

# Install dependencies
pnpm install

# Build TypeScript to JavaScript
pnpm run build

# Run tests
pnpm test:run          # Run all tests once
pnpm test              # Run tests in watch mode
pnpm test:ui           # Open Vitest UI

# Linting and formatting
pnpm run lint          # Check code
pnpm run lint:fix      # Auto-fix issues
pnpm run format        # Format code

# Development with tsx (no build needed)
pnpm run dev init
pnpm run dev install
pnpm run dev search "query"

# Run built CLI
node dist/index.js init
node dist/index.js search "query"

Database Schema

CREATE VIRTUAL TABLE pages USING fts5(
  path UNINDEXED,
  title,
  body,
  tokenize='porter'
);

FTS5 creates auxiliary tables: pages_content, pages_data, pages_idx, pages_docsize, pages_config.

Keywords

documentation

FAQs

Package last updated on 03 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts