No description
  • TypeScript 90%
  • CSS 9.6%
  • JavaScript 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-03 16:40:43 -08:00
.github Initial commit 2026-10-22 06:38:42 +00:00
src feat/computer: add direct AutoHotkey execution and screenshots (#12) 2026-11-04 00:40:20 +00:00
tests feat/computer: add direct AutoHotkey execution and screenshots (#12) 2026-11-04 00:40:20 +00:00
.gitignore feat: edit prompts and retry responses 2026-10-23 05:37:23 -07:00
bun.lock fix: render reasoning at full sidebar width with Markdown (#7) 2026-10-30 09:13:53 +00:00
CONTRIBUTING.md Initial commit 2026-10-22 06:38:42 +00:00
esbuild.config.mjs feat: add Pi chat sidebar plugin 2026-10-23 00:49:04 -07:00
LICENSE.md Initial commit 2026-10-22 06:38:42 +00:00
manifest.json chore: release 0.5.0 2026-11-03 16:40:43 -08:00
package.json chore: release 0.5.0 2026-11-03 16:40:43 -08:00
README.md feat/computer: add direct AutoHotkey execution and screenshots (#12) 2026-11-04 00:40:20 +00:00
styles.css feat/computer: add direct AutoHotkey execution and screenshots (#12) 2026-11-04 00:40:20 +00:00
tsconfig.json feat: add Pi chat sidebar plugin 2026-10-23 00:49:04 -07:00
versions.json chore: release 0.5.0 2026-11-03 16:40:43 -08:00

Pi Chat for Obsidian

Chat with the Pi coding agent inside your vault, in Obsidian's right sidebar.

Overview

Pi Chat is an Obsidian desktop plugin that runs your installed pi CLI against the current vault. It is a native chat client for Pi's RPC mode: the plugin does not ship a second agent runtime or model credentials, so it uses your normal Pi configuration, packages, skills, extensions, MCP servers, and providers.

The interface follows the chat layout of T3 Chat and the author's Pi web workspace, restyled with Obsidian theme variables so it inherits the active light, dark, or community theme.

Features

  • Right-sidebar chat view opened from the ribbon or command palette
  • Streaming Markdown with syntax highlighting and copy buttons
  • Collapsible reasoning and tool activity, with running/error states
  • Edit a sent prompt or retry a Pi response, branching the session in place
  • Model and reasoning-level selectors
  • Provider API keys and OpenAI/Anthropic-compatible endpoints in settings
  • Steering ("Next step") and follow-up ("After task") messages while Pi works
  • Stop, restart, new chat, and manual context compaction
  • Pi extension dialogs rendered as Obsidian modals
  • Persistent Pi sessions stored inside the plugin folder
  • Draft preservation and an "insert active note path" composer action
  • Theme-aware styling using only Obsidian CSS variables
  • Automatic Pi CLI discovery (PATH, mise, ~/.local/bin, npm installs)
  • Automatic Exa web search and page fetching via pi-exa, no Exa API key required
  • Opt-in native Windows computer use: write/run AutoHotkey v2 scripts and take screenshots with inline previews

Software Stack / Technologies Used

  • TypeScript
  • Obsidian plugin API
  • Pi CLI in --mode rpc (JSONL over stdin/stdout)
  • esbuild, Bun, tsc

Requirements

  • Obsidian 1.5+ on desktop (the plugin spawns a local process; mobile is not supported)
  • Pi 0.80.8+ installed and signed in to at least one provider (the bundled launch configuration loads pi-exa, which requires 0.80.8+)
  • A vault opened in Obsidian

Quickstart

  1. Build the plugin:

    bun install
    bun run build
    
  2. Copy main.js, manifest.json, and styles.css into <vault>/.obsidian/plugins/pi-obsidian/.

  3. Enable Pi Chat in Obsidian → Settings → Community plugins.

  4. Click the message icon in the ribbon, or run Pi Chat: Open chat from the command palette.

  5. Pick a model in the chat header and send a message.

For development, symlink this directory into your vault's plugin folder and run bun run dev for a watching build.

How it works

The plugin spawns a long-lived child process:

pi --mode rpc --extension <plugin>/pi-obsidian-tree.ts --session-dir <plugin>/sessions --session-id <id>

The child runs with the vault root as its working directory. Pi streams JSONL events for assistant text, reasoning, tool calls, tool output, queues, compaction, retries, and extension dialogs. The plugin renders those events and sends commands (prompt, steer, follow_up, abort, set_model, set_thinking_level, compact, …) back over stdin.

For Edit and Retry, the plugin writes a small private pi-obsidian-tree.ts extension into its own folder and loads it with --extension. Pi exposes session-tree navigation only through an extension command context; RPC fork exits the child process. Navigation moves the active branch in the existing session file, so the old branch remains available to Pi and the chat keeps its session ID.

Sessions live in .obsidian/plugins/pi-obsidian/sessions, not as vault notes, and are not synced by Obsidian Sync. The Pi session ID is remembered per vault.

Web search with Exa

The plugin first starts Pi with your normal extensions and checks its loaded commands for pi-exa. If already loaded, it reuses that adapter instead of registering duplicate tools. Otherwise, it restarts the same session with --extension npm:pi-exa@0.6.1, making web_search_exa and web_fetch_exa available automatically. You do not need to run pi install, configure an MCP server, or supply an Exa API key. Pi downloads and caches the fallback adapter on first use, so the first launch needs internet access and may take longer. Search and fetch use Exa's hosted MCP service and are subject to its free-tier limits; queries and requested URLs are sent to Exa.

The fallback is loaded for the Obsidian process only; the plugin does not add a package to your global or vault Pi settings. Existing pi-exa preferences still apply (use /exa-enable if you previously disabled it). Optional deep search requires an Exa API key and is not needed for ordinary search or page fetching. The default MCP mode is keyless; /exa-mcp-use-api-key on explicitly opts into paid MCP usage if you have a key. To return an existing paid configuration to keyless mode, send /exa-mcp-use-api-key off.

Windows computer use (AutoHotkey + screenshots)

This feature requires Obsidian and Pi running natively on Windows. It does not run through WSL, and is disabled on other platforms.

  1. Install AutoHotkey v2. Screenshots use the Windows PowerShell/.NET components already included in Windows; no separate screenshot application is needed.
  2. In Settings → Pi Chat → Computer use (Windows), turn on Enable computer tools. This grants screen-capture access to the agent. Screenshots are sent to the selected model provider and retained in Pi session history.
  3. Leave AutoHotkey v2 executable blank for detection in standard installation folders or PATH, or supply the full path to the v2 interpreter, for example C:\\Program Files\\AutoHotkey\\v2\\AutoHotkey64.exe.
  4. Run Pi Chat: Restart Pi, and select an image-capable model for visual work.

The Pi process receives two tools:

  • ahk — execute AutoHotkey v2 code directly, like bash executes shell commands. Pass code in command and an optional timeout in seconds. No separate write step or confirmation dialog is required. The working directory is the vault root. Output written with FileAppend(text, "*", "UTF-8") and interpreter errors appear in the tool result. The default runtime limit is 30 seconds, configurable per call up to 120 seconds. Output is limited to the last 32,768 characters. The temporary script is removed after execution.
  • computer_screenshot — capture the primary monitor, or the entire virtual desktop with target: "desktop". Returns a PNG plus native pixel dimensions and screen origin, which may be negative on secondary monitors. Expand the tool result to see the screenshot. Temporary capture files are removed after the result is read; session history still contains the image. Captures over 20 MiB are rejected rather than silently rescaled.

For a reusable script, use Pi's existing write/edit tools to create a normal .ahk file anywhere appropriate, then run it through bash using the installed AutoHotkey v2 executable. There is no special script folder or file-writing tool. For example, in a Bash shell:

"C:/Program Files/AutoHotkey/v2/AutoHotkey64.exe" /ErrorStdOut=UTF-8 "scripts/task.ahk"

For example, ask: “Take a screenshot, then use ahk to open Notepad and type a greeting. Explicitly activate Notepad before sending input, and take another screenshot to verify.”

Desktop tools run serially. Stop cancels pending work and requests termination of a running helper's process tree; session shutdown also requests termination. Persistent scripts will hit their runtime limit. Scripts should explicitly activate and wait for the intended window, and use explicit screen-coordinate/DPI handling when clicking based on screenshots. Scripts launched through bash use bash's execution behavior instead of the ahk tool's limits and serialization.

These are not sandboxed scripts. Like shell commands, they execute without additional approval and have your full user permissions: they can change files, send input, or start programs. Applications started by a completed script, detached processes, and prior side effects are not undone by Stop. Changing computer-use settings takes effect when you restart Pi.

Finding the Pi CLI

The plugin first uses the path in settings, then PI_OBSIDIAN_PI, then pi on an augmented PATH. The augmentation finds mise-managed Node and Pi binaries directly, including versioned npm installs whose shims are not activated in the GUI session. It also adds mise shims and common install locations, and falls back to mise exec -- pi. Settings → Pi Chat shows the detected Pi and Node executables.

Usage notes

  • Enter sends; Shift+Enter inserts a newline.
  • While Pi is running, the composer offers Next step (steering) and After task (follow-up) modes. Escape stops the run.
  • Hover a sent message to reveal its action: Edit on your message opens an editor and resends the edited prompt; Retry on a Pi reply regenerates it from the preceding prompt. Both branch the Pi session in place: later replies stay in the session file but leave the active branch. Actions are hidden while Pi is working.
  • Tool output and reasoning are collapsed by default. Change that in settings.
  • The file button in the composer inserts the active note's vault-relative path, so you can ask Pi to read or edit it directly.
  • Pi's extension dialogs (select, confirm, input, editor) appear as Obsidian modals. Fire-and-forget widgets from extensions are not rendered.

Provider configuration

Settings → Pi Chat → Providers manages the same Pi configuration files the CLI uses:

  • Add or replace an API key for any provider ID (for example anthropic, openai, openrouter, or ollama). Keys are written to Pi's auth.json with mode 0600 and are never shown back in full.
  • Add, edit, or update an OpenAI-, Anthropic-, or Google-compatible endpoint in Pi's models.json: provider ID, base URL, API type, and optional key. Models are fetched from the provider's /models endpoint rather than typed as a comma-separated list.
  • See the providers and models Pi actually reports, including extension-provided providers such as proxy.
  • Remove a provider credential or custom endpoint.
  • Restart Pi so the new credentials and model catalog are loaded.

OAuth and subscription sign-in (ChatGPT, Copilot, and similar) still uses Pi's interactive /login flow; this panel covers API keys and compatible endpoints. Pi extension providers (for example proxy) are shown read-only because the extension owns their credentials and model catalog. The agent directory shown in settings is derived from PI_CODING_AGENT_DIR or defaults to ~/.pi/agent.

Security

Pi can read, create, edit, and delete files in the vault and run shell commands. Treat it like any other coding agent with access to your notes. The plugin does not read or store provider credentials; Pi resolves them from its own config. Review the vault and Pi project-trust settings before running the agent on untrusted content.

Development

bun install
bunx playwright install chromium  # once, for browser regression tests
bun run typecheck   # tsc, no emit
bun test            # state, launcher, provider, and browser rendering tests
bun run check       # typecheck + tests
bun run build       # typecheck + production bundle

The chat transcript reducer in src/chat-state.ts is deliberately independent of Obsidian so it can be tested with synthetic Pi events. The chat-view tests run in headless Chromium with a minimal Obsidian API stub; they check real CSS layout and Markdown-renderer handoff, not Obsidian's Markdown implementation. Set CHROMIUM_PATH to use a system Chromium instead of Playwright's download.

License

AGPL-3.0. See LICENSE.md.