This project integrates @mariozechner/pi-coding-agent directly into Logseq, turning Logseq into the ultimate Local AI IDE and User Interface for Pi.
The integration utilizes a Logseq-First Architecture:
- Logseq UI & Markdown: Acts as the sole source of truth. It stores all messages (prompts and answers) in Logseq's native Markdown blocks and graph database.
- Stateless Agent Server: The server creates a fresh, in-memory Pi session for every request. It reconstructs the conversation history on-the-fly by reading the Logseq block tree from the page root down to the user's current block.
It consists of two main components:
pi-agent-server: An HTTP server that listens for triggers from Logseq, reconstructs the Pi conversation context from Logseq blocks, invokes the Pi Agent SDK, and syncs answers back to Logseq via the Logseq Local HTTP API.logseq-plugin: A Logseq plugin that registers a/pislash command. When triggered, it grabs the full block tree (from the root of the page to the current block) and sends it to the server.
- Node.js (v18+)
- Logseq Desktop App
- An API key for your preferred LLM (configured via Pi's standard authentication mechanisms, e.g.
~/.pi/agent/auth.jsonorANTHROPIC_API_KEYin environment variables)
The pi-agent-server needs to write blocks directly to your Logseq graph.
- Open Logseq.
- Go to Settings > Features and enable Local HTTP Server.
- Go to Settings > Local HTTP Server.
- Set the host to
127.0.0.1and port to12315(default). - Generate an Authorization Token and save it (you will need it for the Pi server).
The server acts as the bridge.
cd pi-agent-server
npm installCreate a .env file in pi-agent-server:
LOGSEQ_API_URL=http://127.0.0.1:12315/api
LOGSEQ_API_TOKEN=your_token_here
PORT=3000Start the server:
npm run build
npm run startThe plugin adds the UI trigger to Logseq.
- Build the plugin:
cd logseq-plugin
npm install
npm run build- Open Logseq > Settings > Advanced. Turn on Developer mode.
- Go to Plugins (
Esc->Plugins). - Click Load unpacked plugin and select the
logseq-plugindirectory.
- Open Logseq and create a new page to act as your session (e.g.,
Pi Session 1). - Write a prompt in any block, such as
Напиши функцию Hello World на TypeScript. - While your cursor is in the block, type
/piand select the command. - The plugin will send the entire block tree (from the page root up to your current block) as context to the Pi Agent Server.
- Wait for the agent to process the request. Once done, the answer will magically appear as child blocks under your prompt.
- The generated assistant blocks will have a
role:: assistantproperty block automatically added to them. You can reply by creating a new block under the assistant's response and typing/piagain. The context will be correctly maintained!
pi-agent-server/src/server.ts: The HTTP gateway and core logic that translates Logseq block trees into Pi Session messages.logseq-plugin/index.ts: The Logseq plugin logic that extracts the block tree backwards up to the root.