Skip to content

tadatuta/logseq-pi-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Logseq + Pi Coding Agent Integration

This project integrates @mariozechner/pi-coding-agent directly into Logseq, turning Logseq into the ultimate Local AI IDE and User Interface for Pi.

Architecture

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:

  1. 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.
  2. logseq-plugin: A Logseq plugin that registers a /pi slash 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.

🚀 Setup & Installation

Prerequisites

  • 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.json or ANTHROPIC_API_KEY in environment variables)

1. Enable Logseq Local HTTP Server

The pi-agent-server needs to write blocks directly to your Logseq graph.

  1. Open Logseq.
  2. Go to Settings > Features and enable Local HTTP Server.
  3. Go to Settings > Local HTTP Server.
  4. Set the host to 127.0.0.1 and port to 12315 (default).
  5. Generate an Authorization Token and save it (you will need it for the Pi server).

2. Setup the Pi Agent Server

The server acts as the bridge.

cd pi-agent-server
npm install

Create a .env file in pi-agent-server:

LOGSEQ_API_URL=http://127.0.0.1:12315/api
LOGSEQ_API_TOKEN=your_token_here
PORT=3000

Start the server:

npm run build
npm run start

3. Install the Logseq Plugin

The plugin adds the UI trigger to Logseq.

  1. Build the plugin:
cd logseq-plugin
npm install
npm run build
  1. Open Logseq > Settings > Advanced. Turn on Developer mode.
  2. Go to Plugins (Esc -> Plugins).
  3. Click Load unpacked plugin and select the logseq-plugin directory.

🛠 Usage

  1. Open Logseq and create a new page to act as your session (e.g., Pi Session 1).
  2. Write a prompt in any block, such as Напиши функцию Hello World на TypeScript.
  3. While your cursor is in the block, type /pi and select the command.
  4. The plugin will send the entire block tree (from the page root up to your current block) as context to the Pi Agent Server.
  5. Wait for the agent to process the request. Once done, the answer will magically appear as child blocks under your prompt.
  6. The generated assistant blocks will have a role:: assistant property block automatically added to them. You can reply by creating a new block under the assistant's response and typing /pi again. The context will be correctly maintained!

Development

  • 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.

About

Logseq plugin that connects to the Pi Coding Agent via slash command

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors