PERUSE 1.0 · MACOS & WINDOWS
Your agent writes the code.
You read it here.
A native code & Markdown reader for the AI coding age. Three megabytes, opens in an instant, and shows only your file tree and your text — plus walkthroughs your agent can lead, and a timeline that catches every edit it makes.
Live miniature Peruse window showing an AI edit arriving in src/engine.ts, followed by an agent-led walkthrough spotlight with interactive branch signposts.
1import { LRUResultCache } from './cache';2import type { QueryOptions, SearchHit } from './types';34export function createQueryEngine(indexDocs: SearchHit[]) {5 const cache = new LRUResultCache(128);67 return async function runQuery(rawQuery: string, opts: QueryOptions = {}): Promise<SearchHit[]> {8 if (opts.signal?.aborted) return [];9 const query = rawQuery.trim().toLowerCase();10 if (!query) return [];1112 const cached = cache.get(query);13 if (cached) {14 return cached.slice(0, opts.limit ?? 25);15 }1617 if (opts.regex) {18 const pattern = new RegExp(rawQuery, 'i');19 return indexDocs.filter((doc) => pattern.test(doc.snippet)).slice(0, opts.limit ?? 25);20 }21runQuery — three-way dispatchSplits on abort signal, LRU cache hit and regex flag — click a signpost or press 1 to follow the fast path.22 const limit = opts.limit ?? 25;23 const matched = indexDocs24 .filter((doc) => doc.snippet.toLowerCase().includes(query))25 .sort((a, b) => b.score - a.score)26 .slice(0, limit);2728 cache.set(query, matched, opts.cacheTtlMs ?? 30_000);29 return matched;30 };31}
1import type { SearchHit } from './types';23export class LRUResultCache {4 private readonly store = new Map<string, { hits: SearchHit[]; expiresAt: number }>();5 constructor(private readonly maxEntries = 128) {}67 // Promote hit to tail; lazily evict expired keys8 get(key: string): SearchHit[] | undefined {9 const entry = this.store.get(key);10 if (!entry) return undefined;11 if (Date.now() > entry.expiresAt) {12 this.store.delete(key);13 return undefined;14 }15 this.store.delete(key);16 this.store.set(key, entry);17 return entry.hits;18 }LRU lazy expiry & tail reinsertionEvicts stale entries on read, then deletes and re-inserts the key at the tail of the Map for O(1) recency promotion.19 set(key: string, hits: SearchHit[], ttlMs: number) {20 if (this.store.size >= this.maxEntries) this.store.delete(this.store.keys().next().value!);21 this.store.set(key, { hits, expiresAt: Date.now() + ttlMs });22 }23}
1import { createQueryEngine } from './engine';2import type { QueryOptions, SearchHit } from './types';34export class SearchRouter {5 private readonly queryStandard: ReturnType<typeof createQueryEngine>;6 private readonly queryPinned: ReturnType<typeof createQueryEngine>;78 constructor(corpus: SearchHit[], pinned: SearchHit[]) {9 this.queryStandard = createQueryEngine(corpus);10 this.queryPinned = createQueryEngine(pinned);11 }1213 async dispatch(rawQuery: string, opts: QueryOptions = {}) {14 const [pinned, standard] = await Promise.all([15 this.queryPinned(rawQuery, opts),16 this.queryStandard(rawQuery, opts),17 ]);18 return [...pinned, ...standard].slice(0, opts.limit ?? 25);19 }20}
Lumina Architecture Overview
Lumina is a lightweight, zero-dependency local indexing engine designed for sub-10ms document retrieval and predictable memory bounds.
Core Design Principles
- Zero Background Bloat: Index segments stay compact in memory with deterministic LRU eviction.
- Cancellation First: Every query pipeline accepts a standard
AbortSignalso stale keystrokes cancel immediately. - Composable Routing: Pinned workspace documents and standard corpus results merge cleanly in
SearchRouter.
Query Pipeline Latency
| Stage | Target Budget | Implementation |
|---|---|---|
| Tokenize & Normalize | < 0.4 ms | runQuery() in src/engine.ts |
| LRU Cache Lookup | < 0.1 ms | LRUResultCache in src/cache.ts |
| Ranked Merge | < 2.5 ms | SearchRouter.dispatch() |
Quick Example
const runQuery = createQueryEngine(corpus); const results = await runQuery('abort signal', { limit: 10 });
This is real HTML, not a video — click around.
01 — WALKTHROUGH
Let your agent walk you through the code.
Ask your agent. Peruse opens with a route map of the logic, then walks you through the real code — step by step, fork by fork.
An AI agent is asked about the query pipeline, calls the viewer_walkthrough MCP tool, and Peruse opens on the route map before walking through the code.
-
Agent ready · MCP server "viewer" connectedcwd ~/work/lumina
- How does the query pipeline handle caching and branch routing?
- Thinking…
-
Read(src/engine.ts)31 lines
-
viewer · viewer_walkthrough (MCP)project: "lumina" · mode: review · 4 steps · 3 branchesDone · pushed to Peruse — lumina
- I've laid out this logic in Peruse — opening the walkthrough now.
1import { LRUResultCache } from './cache';2import type { QueryOptions, SearchHit } from './types';34export function createQueryEngine(indexDocs: SearchHit[]) {5 const cache = new LRUResultCache(128);createQueryEngine owns a 128-entry LRU cacheAllocates a bounded LRUResultCache(128) per engine instance so repeated queries skip full corpus scans.67 return async function runQuery(rawQuery: string, opts: QueryOptions = {}): Promise<SearchHit[]> {8 if (opts.signal?.aborted) return [];Guard before normalising the query stringChecking opts.signal?.aborted first short-circuits stale keystrokes at zero allocation cost.9 const query = rawQuery.trim().toLowerCase();10 if (!query) return [];1112 const cached = cache.get(query);13 if (cached) {14 return cached.slice(0, opts.limit ?? 25);15 }1617 if (opts.regex) {18 const pattern = new RegExp(rawQuery, 'i');19 return indexDocs.filter((doc) => pattern.test(doc.snippet)).slice(0, opts.limit ?? 25);20 }Unvalidated external regex input — ReDoS riskPassing rawQuery directly to new RegExp permits catastrophic backtracking; cap pattern length or validate before compiling.21runQuery — three-way dispatchExecution splits on abort state, cache hit and opts.regex. Choose a route:
22 const limit = opts.limit ?? 25;23 const matched = indexDocs24 .filter((doc) => doc.snippet.toLowerCase().includes(query))25 .sort((a, b) => b.score - a.score)26 .slice(0, limit);2728 cache.set(query, matched, opts.cacheTtlMs ?? 30_000);29 return matched;Scoring, sort & TTL backfillSorts the full match array before slicing to limit; a bounded top-K pass avoids O(n log n) spikes on large corpora.30 };31}
1import type { SearchHit } from './types';23export class LRUResultCache {4 private readonly store = new Map<string, { hits: SearchHit[]; expiresAt: number }>();5 constructor(private readonly maxEntries = 128) {}67 // Promote hit to tail; lazily evict expired keys8 get(key: string): SearchHit[] | undefined {9 const entry = this.store.get(key);10 if (!entry) return undefined;11 if (Date.now() > entry.expiresAt) {12 this.store.delete(key);13 return undefined;14 }15 this.store.delete(key);16 this.store.set(key, entry);17 return entry.hits;18 }LRU lazy expiry & tail reinsertionEvicts stale entries on read, then deletes and re-inserts the key at the tail of the Map for O(1) recency promotion.19 set(key: string, hits: SearchHit[], ttlMs: number) {20 if (this.store.size >= this.maxEntries) this.store.delete(this.store.keys().next().value!);21 this.store.set(key, { hits, expiresAt: Date.now() + ttlMs });22 }23}
02 — TIMELINE ⌘Y
Every AI edit, kept on file.
Every AI edit is kept as a local snapshot. ⌘Y shows what changed; ⌘↩ takes you back.
Interactive snapshot timeline showing automatic local snapshots, calm warm-green and terracotta diffs, draggable scrub handle, and lossless rollback.
1import { LRUResultCache } from './cache';2import type { QueryOptions, SearchHit } from './types';34export function createQueryEngine(indexDocs: SearchHit[]) {5 const cache = new LRUResultCache(128);67 return async function runQuery(rawQuery: string, opts: QueryOptions = {}): Promise<SearchHit[]> {8 if (opts.signal?.aborted) return [];9 const query = rawQuery.trim().toLowerCase();10 if (!query) return [];1112 const cached = cache.get(query);13 if (cached) {14 return cached.slice(0, opts.limit ?? 25);15 }1617 if (opts.regex) {18 const pattern = new RegExp(rawQuery, 'i');19 return indexDocs.filter((doc) => pattern.test(doc.snippet)).slice(0, opts.limit ?? 25);20 }2122 const limit = opts.limit ?? 25;23 const matched = indexDocs24 .filter((doc) => doc.snippet.toLowerCase().includes(query))25 .sort((a, b) => b.score - a.score)26 .slice(0, limit);2728 cache.set(query, matched, opts.cacheTtlMs ?? 30_000);29 return matched;30 };31}
··· 4 unchanged lines ···55 const cache = new LRUResultCache(128);6677 return async function runQuery(rawQuery: string, opts: QueryOptions = {}): Promise<SearchHit[]> {8+ if (opts.signal?.aborted) return [];89 const query = rawQuery.trim().toLowerCase();910 if (!query) return [];11+12+ const cached = cache.get(query);13+ if (cached) {14+ return cached.slice(0, opts.limit ?? 25);15+ }10161117 const limit = opts.limit ?? 25;··· 8 unchanged lines ···
··· 4 unchanged lines ···1616 if (opts.regex) {17− return indexDocs.slice(0, opts.limit ?? 10);17+ const pattern = new RegExp(rawQuery, 'i');18+ return indexDocs.filter((doc) => pattern.test(doc.snippet)).slice(0, opts.limit ?? 25);1819 }··· 8 unchanged lines ···
··· 4 unchanged lines ···8+ if (opts.signal?.aborted) return [];12+ const cached = cache.get(query);17− return indexDocs.slice(0, opts.limit ?? 10);18+ const pattern = new RegExp(rawQuery, 'i');28+ cache.set(query, matched, opts.cacheTtlMs ?? 30_000);
03 — READING ⌘E
Book-grade Markdown. Compiler-grade jumps.
Markdown set like a book. Hold ⌘ and click any symbol to land on its definition.
Interactive showcase switching between synchronized Markdown Reader/Split/Source view and ⌘-click cross-file definition jumps with References · 7 peek.
1# Lumina Architecture Overview23Lumina is a lightweight, zero-dependency local indexing engine4designed for sub-10ms document retrieval and memory bounds.56## Core Design Principles781. **Zero Background Bloat**: Index segments stay compact.92. **Cancellation First**: Accepts standard `AbortSignal`.103. **Composable Routing**: Pinned & corpus merge in `SearchRouter`.1112## Query Pipeline Latency1314| Stage | Target Budget | Implementation |15| --- | --- | --- |16| Tokenize & Normalize | `< 0.4 ms` | `runQuery()` |17| LRU Cache Lookup | `< 0.1 ms` | `LRUResultCache` |18| Ranked Merge | `< 2.5 ms` | `SearchRouter.dispatch()` |1920## Quick Example21```ts22const runQuery = createQueryEngine(corpus);23const results = await runQuery('abort signal', { limit: 10 });24```Lumina Architecture Overview
Lumina is a lightweight, zero-dependency local indexing engine designed for sub-10ms document retrieval and predictable memory bounds.
Core Design Principles
- Zero Background Bloat: Index segments stay compact in memory with deterministic LRU eviction.
- Cancellation First: Every query pipeline accepts a standard
AbortSignalso stale keystrokes cancel immediately. - Composable Routing: Pinned workspace documents and standard corpus results merge cleanly in
SearchRouter.
Query Pipeline Latency
| Stage | Target Budget | Implementation |
|---|---|---|
| Tokenize & Normalize | < 0.4 ms | runQuery() in src/engine.ts |
| LRU Cache Lookup | < 0.1 ms | LRUResultCache in src/cache.ts |
| Ranked Merge | < 2.5 ms | SearchRouter.dispatch() |
Quick Example
const runQuery = createQueryEngine(corpus); const results = await runQuery('abort signal', { limit: 10 });
1import { createQueryEngine } from './engine';2import type { QueryOptions, SearchHit } from './types';34export class SearchRouter {5 private readonly queryStandard: ReturnType<typeof createQueryEngine>;6 private readonly queryPinned: ReturnType<typeof createQueryEngine>;78 constructor(corpus: SearchHit[], pinned: SearchHit[]) {9 this.queryStandard = createQueryEngine(corpus);10 this.queryPinned = createQueryEngine(pinned);11 }1213 async dispatch(rawQuery: string, opts: QueryOptions = {}) {14 const [pinned, standard] = await Promise.all([15 this.queryPinned(rawQuery, opts),16 this.queryStandard(rawQuery, opts),17 ]);18 return [...pinned, ...standard].slice(0, opts.limit ?? 25);19 }20}1import { LRUResultCache } from './cache';2import type { QueryOptions, SearchHit } from './types';34export function createQueryEngine(indexDocs: SearchHit[]) {5 const cache = new LRUResultCache(128);67 return async function runQuery(rawQuery: string, opts: QueryOptions = {}): Promise<SearchHit[]> {8 if (opts.signal?.aborted) return [];9 const query = rawQuery.trim().toLowerCase();10 if (!query) return [];1112 const cached = cache.get(query);13 if (cached) {14 return cached.slice(0, opts.limit ?? 25);15 }1617 if (opts.regex) {18 const pattern = new RegExp(rawQuery, 'i');19 return indexDocs.filter((doc) => pattern.test(doc.snippet)).slice(0, opts.limit ?? 25);20 }2122 const limit = opts.limit ?? 25;23 const matched = indexDocs24 .filter((doc) => doc.snippet.toLowerCase().includes(query))25 .sort((a, b) => b.score - a.score)26 .slice(0, limit);2728 cache.set(query, matched, opts.cacheTtlMs ?? 30_000);29 return matched;30 };31}1import type { SearchHit } from './types';23export class LRUResultCache {4 private readonly store = new Map<string, { hits: SearchHit[]; expiresAt: number }>();5 constructor(private readonly maxEntries = 128) {}67 // Promote hit to tail; lazily evict expired keys8 get(key: string): SearchHit[] | undefined {9 const entry = this.store.get(key);10 if (!entry) return undefined;11 if (Date.now() > entry.expiresAt) {12 this.store.delete(key);13 return undefined;14 }15 this.store.delete(key);16 this.store.set(key, entry);17 return entry.hits;18 }19 set(key: string, hits: SearchHit[], ttlMs: number) {20 if (this.store.size >= this.maxEntries) this.store.delete(this.store.keys().next().value!);21 this.store.set(key, { hits, expiresAt: Date.now() + ttlMs });22 }23}Powered by language servers Peruse installs for you on first use — and puts to sleep when idle.
Get Peruse
Free for 14 days — every feature, no account.
One-time purchase · lifetime · Mac & Windows · core reading free forever