Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/cad0p/pi-napkin/llms.txt

Use this file to discover all available pages before exploring further.

The napkin-context extension gives every pi session immediate awareness of your Obsidian-compatible knowledge vault. On each session start it resolves the vault from the current working directory, generates a vault overview, and injects that overview as a custom context entry into the session — so the agent always knows what your vault contains and how it’s organized before the first message. It also registers the kb_search and kb_read tools, which the agent can call at any point during a session to search for notes or read individual files.

Extension entry point

File: extensions/napkin-context/index.ts The module’s default export is a function that receives the pi extension API and uses it to register all handlers and tools:
export default function (pi: ExtensionAPI) {
  // registers message renderer, session_start handler, kb_search, kb_read
}

session_start handler

The handler fires once per session start (including session resume and fork). Its responsibilities are:
  1. Resolve the vault — calls new Napkin(ctx.cwd) to locate the vault from the current working directory. If vault resolution throws (no vault reachable from cwd), the handler returns early and no context is injected.
  2. Generate the vault overview — calls n.overview() internally to produce a multi-line text summary of the vault’s folder structure, keyword index, and note counts. Returns null when NAPKIN.md is absent or the vault is empty.
  3. Inject context (idempotent) — before injecting, scans the existing session entries for any entry where e.type === "custom_message" and customType === "napkin-context". If one already exists (resumed session), injection is skipped. Otherwise calls:
    sm.appendCustomMessageEntry("napkin-context", content, true);
    
    The third argument (true) sets display: true, marking the entry as visible in the TUI.
  4. Update the status bar — if the UI is available and showStatus is enabled (see Config), sets the "napkin" status key:
    • Vault found: 📜 napkin (the glyph is themed with theme.fg("dim", " napkin"))
    • No vault / no NAPKIN.md: napkin: no NAPKIN.md (themed dim)
ReadonlySessionManager cast — pi’s ExtensionContext narrows sessionManager to ReadonlySessionManager, which omits mutation methods. At runtime it’s always the full SessionManager, but if pi ever wraps the instance in a genuine readonly proxy the mutation method will either be absent or throw. The extension casts through Partial<SessionManager> before calling appendCustomMessageEntry:
const sm = ctx.sessionManager as Partial<SessionManager>;
if (typeof sm.appendCustomMessageEntry === "function") {
  sm.appendCustomMessageEntry("napkin-context", content, true);
}
If pi ever tightens the contract so the method is absent at runtime, the extension degrades gracefully to a session without the vault overview — a warning notify is surfaced once and the session continues normally. (See source comment: “pi’s ExtensionContext narrows sessionManager to ReadonlySessionManager, which omits mutation methods. At runtime it’s always the full SessionManager, but if pi ever wraps the instance in a genuine readonly proxy the mutation method will either be absent or throw.”)

Custom message renderer

Registered with:
pi.registerMessageRenderer("napkin-context", (message, { expanded }, theme) => { ... });
StateRendered output
Collapsed📜 napkin vault context — Ctrl+O to expand — label styled with theme.fg("customMessageLabel", "📜 napkin vault context"), hint styled with theme.fg("dim", " — Ctrl+O to expand")
ExpandedFull vault overview rendered as Markdown using pi-tui’s Markdown component, with all standard heading, link, code, blockquote, list, and inline-style tokens themed from the active color palette
The renderer handles both string content and TextContent[] arrays (narrowing to text-only entries) so it is forward-compatible if pi ever stores image-bearing content in custom messages.

Registered tools

Searches the knowledge base for notes matching a free-text query.
PropertyValue
Namekb_search
LabelKB Search
DescriptionSearch the knowledge base for notes matching a query
Prompt snippetSearch the napkin vault for notes by keyword or topic
Parameters schema:
Type.Object({
  query: Type.String({ description: "Search query" })
})
query
string
required
Free-text search query. Passed to napkin.search(query) which performs keyword and topic matching across all vault notes.
Returns: A formatted list of matching notes. Each result includes the file name in bold and any matching snippets indented below it. Returns "No results found." when there are no matches. The result renderer uses a collapsed view of up to 15 lines (maxCollapsedLines = 15) with a ... (N more lines, <key> to expand) hint when the result exceeds that.

kb_read

Reads a single file from the knowledge base by name or path.
PropertyValue
Namekb_read
LabelKB Read
DescriptionRead a file from the knowledge base
Prompt snippetRead a note from the napkin vault by name or path
Parameters schema:
Type.Object({
  file: Type.String({ description: "File name or path to read" })
})
file
string
required
File name or relative path to the note. Passed to napkin.read(file), which resolves the note within the vault.
Returns: The full text content of the note. The result renderer uses a collapsed view of up to 10 lines (maxCollapsedLines = 10) with the same expand hint as kb_search.

Config key: showStatus

The status bar glyph is controlled by the showStatus key in the vault’s config file:
<vault.configPath>/config.json
For a subdir-layout vault (the standard layout), this is typically .napkin/config.json relative to the vault root.
{
  "showStatus": true
}
ValueBehavior
true (default, also when file is absent)Status bar entry is displayed
falseStatus bar entry is suppressed entirely
The config is read at session_start time via loadShowStatus(vault.configPath). Missing file or missing key both default to true.

Peer dependencies

From package.json:
PackageVersion constraintRole
@earendil-works/pi-coding-agent>=0.74.0ExtensionAPI, SessionManager, Theme, tool/renderer registration
@earendil-works/pi-tui>=0.74.0Markdown, Text TUI components for rendering
@sinclair/typebox^0.34.49TypeBox Type.Object / Type.String for tool parameter schemas

Build docs developers (and LLMs) love