SwarmVault Documentation

repository·main·Indexed 20 days ago

https://github.com/swarmclawai/swarmvault

A local-first LLM Wiki, knowledge graph builder, and RAG knowledge base that transforms code, documents, and transcripts into structured markdown wikis and queryable knowledge graphs for AI agents. Includes the @swarmvaultai/cli for managing sources, initializing workspaces, compiling vaults, and exporting AI handoff packs.

Tokens
98.1K
Snippets
322
Records
419
Agent score
70%

What's inside SwarmVault

  1. Overview of SwarmVault Packages

    main

    The SwarmVault ecosystem is divided into several core packages:

    • @swarmvaultai/cli: Provides the global swarmvault and vault command-line interfaces.
    • @swarmvaultai/engine: The core runtime library responsible for ingest, compile, query, lint, watch, and MCP functionality.
    • @swarmvaultai/viewer: A graph viewer used to visualize data. It is included with the CLI and does not require a separate installation.
  2. What @swarmvaultai/viewer does

    main

    @swarmvaultai/viewer is the graph UI package for SwarmVault. It is responsible for rendering state/graph.json as an interactive graph visualization.

    Key features include:

    • Node Rendering: Visualizes source nodes, concept nodes, entity nodes, agent tasks, and decisions.
    • Edge State Visualization: Displays extracted, inferred, conflicted, and stale edge states.
    • Workflow Rail: Provides visibility into approvals, candidates, refresh state, lint findings, activity, and the Memory dashboard.
    • Vault Workbench: Supports prioritized doctor recommendations, full doctor checks, suggested commands, safe repair, title/tag capture mode selection, budgeted context-pack creation, and task starts.

    Note: If you are using the SwarmVault CLI, you do not need to install this package separately; the CLI and engine bundle the viewer assets automatically.

  3. Use @swarmvaultai/engine for programmatic vault operations

    main

    The @swarmvaultai/engine package is the core runtime library for SwarmVault. It is intended for developers who want to build custom interfaces, integrate vault operations into existing Node.js applications, or embed specific behaviors like MCP (Model Context Protocol) or watch cycles directly into their code without using the CLI.

    When to use the engine vs the CLI:

    • Use @swarmvaultai/engine if you are building a custom application or need fine-grained programmatic control.
    • Use @swarmvaultai/cli if you only want to use SwarmVault as a standalone tool via the terminal.
  4. Analyze Benchmark Results by Source Class

    main

    SwarmVault provides a detailed breakdown of benchmark performance categorized by source class. This data is useful for understanding how different types of code (e.g., first-party vs. third-party) impact the vault's graph and analysis.

    Data Locations

    • JSON Data: The byClass payload is stored in state/benchmark.json.
    • Markdown Report: A rendered table titled "Benchmark By Source Class" is available in wiki/graph/report.md.

    Output Format

    When running benchmarks, you can expect a summary output similar to this:

    first_party   sources=3  pages=... nodes=... guided=... naive=... reduction=...
    third_party   sources=1  pages=... nodes=... guided=... naive=... reduction=...
    resource      sources=1  pages=... nodes=... guided=... naive=... reduction=...
    generated     sources=1  pages=... nodes=... guided=... naive=... reduction=...
  5. Use swarmvault next for guided workflows

    main
    The swarmvault next command is a read-only utility that detects the current state of your folder. It determines if you need to perform initialization, ingestion, compilation, graph refreshing, review, or query work, and then prints the safest next commands to execute.
    swarmvault next
  6. Understand SwarmVault Privacy and Data Flow

    main

    SwarmVault is designed with a privacy-first approach, processing most data locally:

    • Code Files: Analyzed locally using TypeScript compiler API, tree-sitter, or SQL parsers. Source code content is never sent to external APIs.
    • Documents and Text: Sent to the configured provider for semantic extraction. If using the heuristic provider, this remains entirely local.
    • Images: Only sent to providers if a vision-capable provider is explicitly configured.
    • Graph/Reports: All graph construction, community detection, and report generation are performed locally.

    When using LLM providers (OpenAI, Anthropic, etc.), only non-code content (documents/text) is transmitted for analysis.

  7. Understand the SwarmVault file structure and artifacts

    main

    SwarmVault follows a 'save-first' philosophy where the files on disk constitute the primary product. The vault is organized into three functional categories: Canonical Inputs (the raw data and instructions), Compiled Knowledge (the processed, human/AI-readable wiki and exports), and State and Review (the internal indices, session states, and review bundles).

    Core Mental Model

    • Inputs: Your source of truth (e.g., raw/sources/, swarmvault.schema.md).
    • Compiled Knowledge: The output of the compile process (e.g., wiki/, wiki/exports/ai/).
    • State: The engine's working memory and indices (e.g., state/retrieval/, state/memory/tasks/).

    Best Practices for Usage

    • Avoid direct edits to provenance: Instead of editing generated files, prefer updating your swarmvault.schema.md or adding new sources.
    • Use Context Packs for handoffs: When passing information to another agent or reviewer, use the JSON context-pack artifacts in state/context-packs/ to provide bounded evidence and token accounting.
    • Use AI Export Packs for portability: If you need to move your compiled wiki to a static tool without a running server, use the contents of wiki/exports/ai/ (includes llms.txt, graph.jsonld, etc.).
    • Use Tasks for workflows: For multi-step agent workflows that need to survive handoffs or branch switches, utilize the task ledger in state/memory/tasks/.
  8. Understand the SwarmVault CI and Smoke Testing Workflow

    main

    SwarmVault uses a multi-tiered testing strategy to catch regressions:

    • Live Smoke Workflow: Triggered via workflow_dispatch (manual) or release.published (automated on package publication). This workflow includes a packaged smoke lane (installed via tarball) to catch regressions related to installed paths.
    • Nightly Runs: Scheduled heuristic smoke tests run nightly.
    • OSS Corpus Runner: An extended validation lane used before release candidate signoff and after any changes to repo ingest, graph quality, or query/report behavior. It should be run against the live published npm package.
    • Tiny Fixture Matrix: A fast, controlled, and low-cost gate that catches regressions across the core code-language baseline and specific local file types.

    Debugging: If a smoke test fails, artifacts are stored in the .live-smoke-artifacts/ directory.

  9. Follow LLM Wiki conventions and page structures

    main

    To maintain consistency, adhere to these rules:

    General Conventions

    • Immutability: Never modify files in raw/.
    • Linking: Use wiki-style links: [[path/to/page|Display Title]].
    • Metadata: Add YAML frontmatter to every wiki page (minimum: title, tags, source_ids).
    • Logging: Use the prefix ## [YYYY-MM-DD] operation | Title in wiki/log.md.
    • Grounding: Cite source filenames for all claims. If raw/ material disagrees with the wiki, the raw/ material is the truth.

    Page Types

    • Source pages (wiki/sources/): Grounded in original material; note key claims, entities, and how they relate to existing content.
    • Concept pages (wiki/concepts/): Aggregate source-backed claims and track how understanding evolves.
    • Entity pages (wiki/entities/): For named people, organizations, or tools; cross-reference all mentioning sources and note relationships.
  10. Configure PDF and Image extraction in the engine

    main

    The engine supports structured extraction for non-markdown sources:

    • PDFs: Undergo a local text-extraction pass before being sent for analysis.
    • Images: Use the configured visionProvider for structured OCR or diagram extraction.

    Error Handling: If image extraction is unavailable (e.g., no multimodal provider configured), SwarmVault does not silently ignore the file. Instead, it records an explicit warning in the extraction sidecar and carries that warning into the analysis phase.

  11. Improve vault synthesis quality

    main

    If the vault compiles but the output quality is low, you may be using the built-in heuristic provider. This provider is a lightweight, offline default that does not support advanced capabilities like embeddings, vision, or image generation.

    To get richer synthesis, add a model provider in swarmvault.config.json. For local semantic graph queries, the embeddingProvider must point to an embedding-capable backend like ollama or an OpenAI-compatible service.

  12. Understand SwarmVault artifact locations and structure

    main

    SwarmVault organizes data into specific directories. You can relocate these using the SWARMVAULT_OUT environment variable, but they will remain relative to the project root.

    Core Directories:

    • raw/: Contains sources/ (canonical input) and assets/.
    • wiki/: The primary output, including outputs/ (briefs, sessions, reviews, guides), dashboards/, context/ (markdown companions), memory/ (task ledger), and candidates/ (staged pages).
    • state/: Internal state, including graph.json, context-packs/, chat-sessions/, memory/tasks/, retrieval/ (index), sources.json, and approvals/.
    • wiki/exports/ai/: Static AI handoff packs containing llms.txt, JSON-LD graph data, and manifests.