Skip to content
kode-0xPublic

About

AI-Powered Knowledge Vault Generator For Obsidian. Turn Any Topic Into A Fully Linked Markdown Knowledge Base Using Your Favorite LLM Through OpenRouter.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Mesh

AI-Powered Knowledge Vault Generator for Obsidian

Give Mesh a topic and it generates a structured, interlinked Obsidian vault: one Markdown note per concept, organized into folders, cross-linked with wiki-links, and validated as a knowledge graph. Runs on OpenRouter (hosted) or Ollama (local), and defaults to spending nothing.


TypeScript Node.js React Ink SQLite OpenRouter Ollama Vitest


Overview

Mesh is a command-line tool (a React app rendered to the terminal with Ink, plus a commander-based CLI) that turns a single topic into a complete Obsidian vault. It asks a model for a concept outline, recursively expands each node into subtopics, generates one Markdown note per leaf, and writes a folder-index note for every branch. After generation it builds a knowledge graph of the result and runs deterministic quality checks.

A topic like Machine Learning becomes a navigable vault with dedicated, cross-referenced notes across its subareas (supervised learning, neural networks, regression, and so on).

Inference runs through exactly two providers, both chosen to avoid mandatory paid services:

  • OpenRouter: hosted models, accessed with your API key.
  • Ollama: models running locally on your own machine, no API key.

Zero-Cost Policy

Mesh defaults to a hard $0 budget and enforces it before every request.

  • OpenRouter: only models whose prompt price and completion price and every other pricing field parse to exactly zero are eligible. Pricing is parsed strictly (a malformed or missing field is treated as unknown, not zero) and re-verified live immediately before generation. A model that turned paid, or whose price cannot be verified, is rejected rather than silently billed. Paid models require opting in explicitly with --allow-paid and --budget greater than zero.
  • Ollama: local inference has no model API fee, so it is always eligible under the default budget.

Local is not free. Ollama has no per-token API fee, but local inference still costs electricity, hardware wear, and bandwidth. Mesh reports Ollama usage as "no model API fee," never as "$0 total." No hosted free tier or public source is treated as unlimited.

Features

  • Recursive generation: expands a topic into a concept hierarchy and generates a dedicated note for every node.

  • Three depth tiers: pick breadth and nesting to match the goal.

    Depth Max nesting Root subtopics Children per node Est. notes
    Concise 1 6 4 ~30
    Standard 2 8 5 ~80
    Deep 3 10 6 ~150
  • Optional research with citations: enable Wikipedia enrichment and/or supply local documents or URLs. Evidence is injected into prompts, citations are validated, invented references are flagged, and unsupported factual claims are surfaced. Research is off by default; with it off, prompts are byte-for-byte unchanged.

  • Knowledge-graph validation: after generation, Mesh builds a graph of the vault and reports broken wiki-links, orphan notes, duplicate concepts, and missing prerequisites.

  • Vault navigation: generates an index, a Map of Content, and a learning path, with links resolving to real notes. Existing index files are never overwritten.

  • Resumable generation: job state and per-note checkpoints persist in node:sqlite. An interrupted run resumes where it left off: completed notes are skipped, pending notes regenerated, and usage is never double-counted.

  • Safe existing-vault updates: re-running against a populated vault generates only missing notes by default, preserves user-edited files, and requires explicit approval plus a roll-back backup before any overwrite or delete.

  • Deterministic quality checks: Markdown/frontmatter structure, required sections, wiki-link integrity, duplicate detection, and Mermaid-block structure, all local, no network. An optional LLM evaluator obeys the same provider and cost policy.

  • Obsidian-native output: every note ships with YAML frontmatter (title, topic, parent, type, depth, created, tags), wiki-links, a ## See Also section, and a navigation footer. How-it-works, comparison, and deep-dive notes include Mermaid diagrams.

  • Custom instructions: append your own instructions to every note prompt, or drop an INSTRUCTIONS.md in the target folder and Mesh picks it up automatically.

Tech Stack

Layer Technology
Language TypeScript 5.6 (strict, ES2022, NodeNext modules)
Runtime Node.js ≥ 22 (ESM)
Terminal UI React 18 via Ink 5 + @inkjs/ui 2
CLI commander
Persistence Built-in node:sqlite (no native dependency)
Providers OpenRouter + Ollama, via the global fetch (no HTTP client dependency)
Tooling Vitest, ESLint (type-checked), Prettier

Dependencies are minimal and MIT-compatible. See docs/DEPENDENCIES.md for every package, version, and license, and for why better-sqlite3 is deliberately excluded in favor of node:sqlite.

Architecture

flowchart TD
    CLI["cli.tsx<br/>commander (7 subcommands)"] -->|TTY| Wizard["Ink wizard (App.tsx)"]
    CLI -->|--yes / non-TTY| Headless["headless renderer"]
    Wizard --> ORCH["orchestrator.runGenerationJob"]
    Headless --> ORCH

    ORCH --> PROV["LLMProvider seam"]
    PROV --> OR["OpenRouterProvider"]
    PROV --> OL["OllamaProvider"]
    ORCH --> COST["CostPolicy + UsageTracker<br/>($0 budget gate)"]
    ORCH --> IDX["indexer<br/>build topic tree"]
    ORCH --> NW["noteWriter<br/>generate note"]
    ORCH --> RES["research (optional)<br/>Wikipedia + user docs"]
    ORCH --> DB[("node:sqlite<br/>.mesh/mesh.db<br/>jobs + checkpoints + usage")]
    ORCH --> VAULT["vault<br/>atomic note writes"]

    ORCH --> POST["post-generation"]
    POST --> GRAPH["graph<br/>integrity report"]
    POST --> QUAL["quality<br/>deterministic checks"]
    POST --> NAV["navigation<br/>index / MOC / learning path"]
    VAULT --> DISK[("Obsidian vault on disk")]
Loading
Area Modules
Entry / CLI src/cli.tsx, src/cli/ (commands, context, headless renderer), src/App.tsx, src/main.tsx
Providers src/providers/ (LLMProvider interface, OpenRouter, Ollama, errors)
Cost policy src/cost/ (pricing classification, eligibility, budget gate, usage tracker)
Generation src/services/ (orchestrator, indexer, note writer, vault I/O)
Prompts src/prompts/ (note-type classifier, templates, shared frontmatter/footer)
Research src/research/ (Wikipedia, user docs, normalize/dedupe, citations)
Graph & quality src/graph/, src/quality/
Persistence src/persistence/ (node:sqlite schema, db, job store)
Vault management src/vaultmgr/ (scan, change plan, apply/rollback)

Generation workflow

sequenceDiagram
    participant U as User
    participant O as Orchestrator
    participant C as CostPolicy
    participant P as Provider
    participant DB as node:sqlite
    participant FS as Vault

    U->>O: generate (topic, provider, model)
    O->>P: getModel(fresh), re-verify pricing
    P-->>O: pricing
    O->>C: eligible under $0 budget?
    C-->>O: ok / reject (paid or unknown)
    O->>P: outline + per-node expansion
    P-->>O: topic tree
    O->>DB: create job + note rows
    loop each note (pre-order)
        O->>C: assertCanSpend
        O->>P: chat()
        P-->>O: note Markdown + usage
        O->>FS: atomic write (tmp → fsync → rename)
        O->>DB: markNoteDone + usage (one tx)
    end
    O->>FS: graph report, quality report, navigation
    O-->>U: summary (notes, tokens, cost)
Loading

On resume, the committed job state decides each note: done notes are skipped, pending or failed notes are regenerated, and usage is never double-counted.

Prerequisites

  • Node.js 22 or later (Mesh uses the built-in node:sqlite module and global fetch).
  • One provider:
    • an OpenRouter API key for hosted models, or
    • Ollama installed and running locally for local models.
  • Obsidian to open the generated vault (optional; the output is designed for it).

Installation

git clone https://github.com/your-username/mesh.git
cd mesh
npm install
npm run build

To run mesh as a global command, link the built binary:

npm link

The mesh bin resolves to dist/cli.js, so a build must exist before linking.

Quick Start

Launch the interactive wizard:

mesh generate

The wizard walks through: topic → provider → API key (OpenRouter only; held in memory, never written to disk; skipped for Ollama) → model (eligible models selectable by default) → output path, depth, and optional custom instructions → cost estimate → live generation.

Or run headlessly with explicit flags:

mesh generate "Quantum Computing" \
  --yes \
  --provider ollama \
  --model llama3.1:8b \
  --output ./quantum-vault \
  --depth standard \
  --ollama-host http://127.0.0.1:11434

When it finishes, open the output folder as a vault in Obsidian.

CLI Commands

mesh ships seven subcommands. Every command supports --help and exits non-zero on failure.

Command Description
mesh generate Generate a vault. Interactive wizard by default; headless with --yes plus required flags.
mesh validate Run deterministic quality checks on an existing vault (no network/LLM). Non-zero on any error.
mesh models List eligible models for a provider. --all shows ineligible ones with the reason.
mesh doctor Diagnose Node version, node:sqlite, provider reachability, key presence, config, and output path.
mesh resume Resume an interrupted job from .mesh/mesh.db.
mesh cost Report per-model tokens, requests, retries, and cost (estimated vs. actual).
mesh config Show the effective configuration and the source of each value.

Interactive vs. headless

  • No --yes, interactive terminal: the Ink wizard launches, pre-seeded from any flags you supplied.
  • No --yes, non-interactive (CI / piped): Mesh exits non-zero and asks for --yes plus required flags. It never mounts the wizard in a non-TTY context.
  • --yes with --provider, --model, and --output: fully headless generation with plain-text progress.
  • --yes with a required flag missing: Mesh exits non-zero naming the missing flag; it never falls back to the wizard.

Environment Variables

Configuration precedence, highest first: flags → environment → config file → built-in defaults.

Copy .env.example and adjust:

Variable Default Description
MESH_PROVIDER openrouter Default provider: openrouter or ollama
OLLAMA_HOST http://127.0.0.1:11434 Ollama endpoint (used when provider is ollama)
MESH_BUDGET 0 Default budget in USD (0 enforces strict zero-cost)
OPENROUTER_API_KEY (unset) Optional. If set, seeds the key in memory for the run only

The OpenRouter key is never written to disk or job state: not to the config file, not to .mesh/mesh.db. If unset, the wizard prompts for it. A config file (mesh.config.json in the working directory, or ~/.config/mesh/config.json) may set only non-secret values; a config file containing a secret is rejected.

INSTRUCTIONS.md

If an INSTRUCTIONS.md file exists in the target vault folder, Mesh uses its contents as custom instructions automatically, useful for re-running generation on an existing vault with a consistent style.

Development

Command Description
npm run dev Run the wizard from source with tsx (no build step)
npm run build Compile TypeScript to dist/
npm start Run the compiled wizard entry (node dist/main.js)
npm test Run the Vitest suite (offline; all HTTP mocked)
npm run typecheck Type-check without emitting (tsc --noEmit)
npm run lint ESLint (type-checked rules)
npm run format:check Prettier check

Tests are fully offline: a global guard installs a fetch that rejects, so any un-mocked network call fails the test rather than reaching the network. CI (GitHub Actions) runs lint, format check, tests, and build on Node 22 and 24.

Deployment

Mesh is distributed and run as a local CLI; there is no server or hosted component.

  1. Build the project: npm run build produces dist/, with dist/cli.js as the mesh entry point.

  2. Install the command, either globally from the repo (npm link) or by invoking the built file directly:

    node dist/cli.js generate --help
  3. Provide a provider at runtime: an OpenRouter key (via prompt or OPENROUTER_API_KEY), or a reachable Ollama host. Run mesh doctor to confirm the environment, provider reachability, and output-path writability before a first run.

The only persistent state is the per-vault .mesh/mesh.db SQLite file and the generated Markdown; both live under the chosen output path.

License

MIT.

About

AI-Powered Knowledge Vault Generator For Obsidian. Turn Any Topic Into A Fully Linked Markdown Knowledge Base Using Your Favorite LLM Through OpenRouter.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages