From 6e1ffd1dff8f3c08ebe603f91b14a5f41d5d1160 Mon Sep 17 00:00:00 2001 From: Bartek Igielski Date: Mon, 7 Sep 2026 11:25:39 +0000 Subject: [PATCH] Rewrite README for users and contributors --- README.md | 305 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 191 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index 1f0ee44..5c4af30 100644 --- a/README.md +++ b/README.md @@ -1,152 +1,229 @@ # iglo.mem -Repository-local semantic search for Markdown. Prepare a snapshot when your -knowledge changes, then search it from an agent or a terminal. +`iglo.mem` is a repository-local semantic search CLI for Markdown. It is for +developers and AI coding agents that keep durable project knowledge in Git +worktrees, especially under `.agent/knowledge` and `.agent/decisions`. + +The workflow is explicit: prepare a snapshot after source changes, then search +that snapshot with a natural-language query. The CLI returns ranked Markdown +passages as JSON; it does not generate answers or modify the source files. + +## Is it a fit? + +Use it when you want a small, worktree-local search tool that can find related +text even when the query and the document use different words. It keeps its +derived index in the repository and does not need a database, daemon, watcher, +or local embedding model. + +The trade-offs are important: + +- Preparation uses OpenRouter embeddings when it has missing or changed inputs, + and search uses them for a non-empty snapshot. Document chunks and query text + are sent off the machine for those requests, and API usage can incur cost. +- Only `.agent/knowledge/**/*.md` and `.agent/decisions/**/*.md` are indexed. + It is not a general codebase or arbitrary-file indexer. +- Search never checks source freshness. Results describe the last successful + snapshot and can be stale after edits, moves, deletes, or a branch change. +- The index is stored as repository files and search linearly scans its active + vectors. The repository's benchmark observations are runner-specific, not a + general scale guarantee, and search returns snippets rather than full + documents. +- Linux x86_64 is the only supported build. Other platforms are unverified. + +It is not the right choice if the data must stay offline, if automatic updates +or a long-running service are required, if you need shared search across +worktrees, or if you need a UI, broad source connectors, generated answers, or +large-scale vector infrastructure. + +## Install + +There is currently no tagged release. To build the standalone executable on +Linux x86_64, from this repository's root: ```sh -iglo.mem init -iglo.mem prepare -iglo.mem search "How do refresh tokens work?" -iglo.mem status -iglo.mem gc +npx --yes bun@1.4.2 install --frozen-lockfile +sh scripts/build.sh ``` -Run commands from anywhere inside the target Git worktree. Every command emits -one JSON object to stdout; prompts and progress use stderr. Errors exit with -status 1. Initialization preserves existing configuration and Markdown. - -## Credentials - -Run `iglo.mem init` in a terminal. If no key is available, it asks for an -OpenRouter key with input hidden and saves it to -`~/.config/iglo.mem/credentials.json`. Create a key at -. - -This is one plaintext file shared by your repositories and worktrees. Its -permissions are private to your OS user. The key is never copied into the -repository. Cancellation or a failed save preserves the previous key. - -`OPENROUTER_API_KEY` overrides the saved key without changing it. Use -`iglo.mem init --reset-credentials` to replace the saved key interactively. -The tool trusts other processes running as your OS user; it is not a secret -vault. Keep your home and credentials directory outside Git repositories. - -Prepare and search never prompt. They need a key only when making an embedding -request. Empty prepared snapshots can be searched without a key or network. -Initialization does not test the key against OpenRouter. +The build needs a C compiler and Node-API headers. Linux builds look in +`/usr/include/node`; set `NODE_INCLUDE_DIR` to override that path. The resulting +`dist/iglo.mem` executable includes Bun and the native lock binding. It does +not need Bun, Node.js, npm, or Git at runtime, but it does need the target OS C +runtime. -## Sources and freshness +The GitHub Actions workflow also packages +`iglo.mem-linux-x64.tar.gz` for pushes and pull requests. Those artifacts are +workflow downloads that expire after 14 days, not releases. -Only `.agent/knowledge/**/*.md` and `.agent/decisions/**/*.md` are indexed. -`.agent/inbox`, dependencies, build output, dotenv files and the index are -excluded. Source symlinks are rejected. Markdown is never modified. +For source development, use the repository's launcher instead: -Every file uses the same Markdown heading and paragraph/code-block processing. -Complete blocks are grouped toward a soft size target for focused search -results. There is no local file/chunk length rejection or truncation; long -indivisible blocks stay intact. Provider input limits still apply. If a provider -rejects an input, preparation fails and the prior snapshot remains available. +```sh +sh /absolute/path/to/iglo.mem/scripts/run.sh init +``` -`prepare` sends missing or changed inputs to OpenRouter, in batches of up to 64. -Unchanged valid vectors are reused. The published snapshot lives at -`.agent/memory-index/snapshot.json`, with individual binary float32 vectors in -`vectors/`. Compatible valid orphans from failed preparation can be reused; -`gc` removes recognized artifacts not referenced by the current snapshot. +## Quick start -`search` embeds only the query and reads prepared data. It does not read Markdown, -check freshness, refresh, or repair the index. Results contain up to eight files, -ranked by cosine similarity plus fixed lexical bonuses, with headings, source -line ranges, scores, snippets and a preparation timestamp. Locations describe -the prepared content and can be stale. Search can continue after source files -are removed or made unreadable. Query failure is an error, never a lexical fallback. +Run the executable from anywhere inside the target Git worktree: -Run `prepare` after edits or when a new worktree needs a fresh snapshot. A valid -committed snapshot can also be searched as-is. Each worktree has its own index. -Concurrent preparation, loading and GC coordinate with a five-second lock wait; -a stopped process releases its lock through the OS. +```sh +cd /absolute/path/to/your-repository +/absolute/path/to/iglo.mem init +/absolute/path/to/iglo.mem prepare +/absolute/path/to/iglo.mem search "How do refresh tokens work?" +``` -`status` reports the snapshot schema, lexical and embedding profiles, prepared -counts and missing referenced vectors without reading -sources or calling OpenRouter. Corrupt present data is an error. `gc` requires -valid metadata and all referenced vectors before deleting anything. It does not -use Markdown changes to decide which vectors to keep. +`init` creates `.agent/memory.json` and the four `.agent` directories if they +are missing. Add or edit Markdown in the two indexed directories, then run +`prepare` again. A valid prepared snapshot can also be committed and searched +in a fresh worktree. + +Every command writes one JSON object to stdout. Prompts and progress use +stderr. Errors are JSON objects and exit with status 1. + +## Commands + +`iglo.mem init` initializes the worktree and sets up credentials. It does not +call OpenRouter or build an index. Existing configuration and Markdown are +preserved. + +`iglo.mem prepare` scans the two source trees, groups complete Markdown blocks, +builds the BM25 index, embeds missing or changed inputs, reuses compatible +vectors, and atomically publishes `.agent/memory-index/snapshot.json` plus +binary vector files. The default Qwen embedding batches contain at most 32 +inputs and 32,768 summed input tokens. If preparation fails, the previous +published snapshot remains available. + +`iglo.mem search ""` embeds the original query, expands it into additional +retrieval inputs, and reranks candidates against only the last published +snapshot. A result contains a source path, heading, line range, score, and a +snippet of at most 400 Unicode code points. It returns at most eight results. +The public score is an ordinal rank value (`1`, `0.5`, `0.333333`, …), not a +probability or calibrated relevance score. Search does not read current +Markdown or repair the index. + +`iglo.mem status` reports the snapshot schema, lexical and embedding profiles, +prepared counts, and missing referenced vectors without reading sources or +calling OpenRouter. It does not report source freshness. + +`iglo.mem gc` removes vector artifacts not referenced by the valid published +snapshot. It uses the snapshot as its deletion authority, not current Markdown. + +For a non-empty snapshot, search combines the original Qwen vector and BM25 +results with up to two lexical and two vector variants plus one optional HyDE +topic generated by the fixed Luna expansion model. It fuses up to 40 candidates, +then sends the original question and complete candidate passages to the fixed +`voyageai/rerank-2.5` reranker through OpenRouter. The 30-second deadline +includes lock acquisition, snapshot loading, provider calls, and output +preparation. Invalid provider output, a provider failure, or a deadline failure +fails the command; there is no partial or lexical-only fallback. + +## Credentials and network use + +Create an OpenRouter key at +. In an interactive terminal, `init` +prompts for it with hidden input and saves it as plaintext at +`~/.config/iglo.mem/credentials.json`, with owner-only directory and file +permissions. The saved key is shared by repositories and worktrees for the +same OS user; this is not a secret-management service. + +`OPENROUTER_API_KEY` takes precedence over the saved key and is never saved by +the CLI. Use `iglo.mem init --reset-credentials` interactively to replace the +saved key. `prepare` and `search` never prompt. Preparation needs a key only +when it has document inputs to embed; search needs one for a non-empty snapshot +because it embeds the query. An empty prepared snapshot can be searched without +a key or network. + +Preparation sends document chunks to OpenRouter's embeddings endpoint. A +non-empty search sends the question to OpenRouter for query embedding, Luna +expansion, generated-vector embedding, and Voyage reranking; the reranker also +receives complete candidate passages. OpenRouter and its serving provider +therefore receive question and indexed-document text. Do not put secrets in +indexed Markdown. + +## Sources, snapshots, and configuration + +Only these paths are scanned: + +```text +.agent/knowledge/**/*.md +.agent/decisions/**/*.md +``` -## Configuration and recovery +Markdown is never modified. Symlinked source entries are rejected. The current +worktree owns its own `.agent/memory-index`; sibling worktrees are not combined. +`search`, `status`, and `gc` operate on the last valid snapshot until a +successful `prepare` publishes a new one. Changing the configured project or +embedding model makes an existing snapshot incompatible and requires +preparation again. -`init` creates `.agent/memory.json`: +`init` creates this configuration when it does not already exist: ```json { "project": "your-repository", - "embedding": { "model": "openai/text-embedding-3-small" } + "embedding": { + "model": "qwen/qwen3-embedding-8b" + } } ``` -Only the OpenRouter embedding model is configurable; the endpoint and source -roots are fixed. Changing model, project or chunking/profile rules requires -`prepare` again. Rotating the key does not require re-embedding. - -- `INDEX_NOT_READY`, `INDEX_INVALID`, `INDEX_INCOMPATIBLE`: run `prepare`. -- `API_KEY_MISSING`: run interactive `init` or supply the environment override. -- `CREDENTIALS_INVALID`: repair the saved file/path/permissions, or use an override. -- `EMBEDDING_FAILED`: check the override/saved key, model, input limits and network. -- `INDEX_BUSY`: retry when the other command finishes. - -A failed refresh does not publish partial results. API retries cover temporary -network failures, HTTP 429 and 5xx, honor Retry-After, and are bounded to four -attempts and a two-minute request budget. Permanent errors do not retry. - -OpenRouter and its serving provider receive document chunks during preparation -and query text during search. Do not put secrets in the indexed Markdown. -The tool does not install schedules, hooks, watchers, or background services. -For cron, configure your own working directory and use the saved key: - -```cron -0 * * * * cd /absolute/path/to/worktree && /absolute/path/to/iglo.mem prepare -``` - -## Build and verification - -The supported build for this PR is Linux x86_64. Other platforms remain -unverified and are not advertised as supported. No tagged release is published -before PR approval/merge. - -The **Check and build Linux executable** GitHub Actions run attaches -`iglo.mem-linux-x64.tar.gz`, containing the single executable with its executable -permission preserved. Download it from the run's Artifacts section, then: - -```sh -tar -xzf iglo.mem-linux-x64.tar.gz -./iglo.mem init -``` - -PR artifacts expire after 14 days; rerunning the build creates a fresh download. -The native build needs a C compiler and Node-API headers; these are build-time -requirements. The executable embeds Bun and the small OS-lock binding. It does -not require Bun, Node.js, npm, Git or a lock executable at runtime. It still needs -the target OS C runtime. A missing Git executable does not prevent worktree discovery. +The default Qwen profile has 4096 dimensions. An explicitly configured +OpenRouter embedding model can change the profile; the endpoint and source roots +are fixed. The optional `retrieval.model` setting is supported only for +`voyageai/rerank-2.5`. The index records model, tokenizer, chunking, and +formatting settings so incompatible vectors are not compared. + +## Alternatives and trade-offs + +- Plain text search such as `grep` or `rg` is a better fit for exact matches, + arbitrary files, and no network dependency. `iglo.mem` adds semantic + retrieval, but requires a prepared snapshot and remote embeddings. +- An existing note or search application is a better fit when you need a UI, + automatic indexing, or many source types. `iglo.mem` is only a CLI over two + repository Markdown trees and does not replace that application. +- A hosted or database-backed vector index is a different operating model when + one index must serve many worktrees or a larger deployment. `iglo.mem` keeps + artifacts beside each repository and linearly scans active vectors, so it does + not provide a shared service or a scale guarantee. + +QMD is named in this repository's retrieval-v2 evaluation as an external +comparator, not as an `iglo.mem` backend. The evaluation is corpus-specific and +its release decision is `NO_ROLLOUT`; this README makes no quality, latency, +cost, or parity claim about either system. + +## Maturity and development + +The repository has automated tests, a Linux CI build, terminal checks, and a +clean-machine check. It currently has no tagged release; treat it as a source- +or CI-artifact project rather than a stable package. The retrieval-v2 evaluation +is explicitly `NO_ROLLOUT`; its limits are recorded in the [held-out report] +(docs/evaluation/retrieval-v2-heldout.md) and [release gates] +(docs/evaluation/retrieval-v2-release-gates.md). + +For the repository checks: ```sh -npm exec --yes --package=bun@1.4.2 -- bun install --frozen-lockfile sh scripts/check.sh sh scripts/build.sh python3 scripts/qa-terminal.py +python3 scripts/qa-clean.py +npx --yes bun@1.4.2 --no-env-file --no-install --config=/dev/null scripts/qa-cli.ts ``` Build and check scripts prepare the pinned tokenizer JSON in an ignored local cache. The first run downloads about 11.43 MB of tokenizer data from Hugging Face; later runs verify the cache and work offline. Downloads are hash-checked before publication. The standalone executable embeds this data and never downloads a -tokenizer at runtime. Before direct `bun test` or source development, run -`bun run tokenizers` once. Keep the generated cache for offline builds. +tokenizer at runtime. On Linux the default header location is `/usr/include/node`; override -`NODE_INCLUDE_DIR` if needed. Run the resulting `dist/iglo.mem` from your worktree. Distribute it with generated -`dist/THIRD_PARTY_NOTICES.txt`; see the [license record](docs/third-party.md). -Builds also need Git and the pinned notice-archive commit available. -For source development use the absolute path to `scripts/run.sh`. The supported -launcher and compiled build disable repository dotenv and Bun preload loading. -Do not use bare `bun src/cli.ts` from an untrusted repository. +`NODE_INCLUDE_DIR` if needed. Run the resulting `dist/iglo.mem` from your +worktree. Distribute it with generated `dist/THIRD_PARTY_NOTICES.txt`; see the +[license record](docs/third-party.md). Builds also need Git and the pinned +notice-archive commit available. For source development use the absolute path +to `scripts/run.sh`. The supported launcher and compiled build disable +repository dotenv and Bun preload loading. Do not use bare `bun src/cli.ts` +from an untrusted repository. Tests use disposable repositories, homes and dummy credentials. See [reproducing verification](docs/verification.md) for CLI, terminal, clean-machine,