Hi Logseq Team,
Following the workflow outlined in `CONTRIBUTING.md` for proposing enhancements, I am opening this discussion thread to present a fully implemented, production-ready contribution before submitting a formal Pull Request.
I have verified that no conflicting PRs or identical proposals exist in the issue tracker, and I am fully prepared to sign the individual **Contributor License Agreement (CLA)** immediately upon consensus.
You can inspect the fully working implementation, production-ready codebase, and our extensive test suite directly in our open-source repository here: GitHub - MarcoPorcellato/matryca-logseq-llm-wiki: Bringing Andrej Karpathy's LLM Wiki to the Outliner Paradigm. Turn any AI Agent into a spatial Knowledge Architect using Logseq's atomic nodes. · GitHub
The Vision: Keeping Logseq OG Supreme for the AI Era
With the explosion of local AI execution frameworks, coding agents (Cursor, Copilot), and the Model Context Protocol (MCP), a massive segment of Logseq power users are leveraging their local Markdown graphs as external corporate or personal knowledge bases.
However, the classic Electron UI/Clojure layer faces inherent bottlenecks when exposed to relentless out-of-process automated tools:
- **UI Coupling:** Reading/writing via the local HTTP JSON-RPC network layer requires the heavy Desktop application to be constantly open and running, creating port fragility and latency.
- **The Concurrent Multi-Writer Footgun:** When background agents or terminal scripts mutate `.md` files directly while the Logseq Desktop UI is open, the lack of cross-process locking creates classic *Lost Update* race conditions. The last process to save silently overwrites the other.
- **Severe Token Bloat:** Feeding long 36-character block UUIDs (`id:: …`) and layout properties to LLM context windows exponentially scales up token consumption, driving up inference costs and response latency.
Our Proposed Contribution: An Official Python Companion CLI/Engine
To solve this without adding weight or breaking changes to Logseq’s core Clojure runtime, we want to upstream a fully completed, self-contained **Headless Data Plane** companion.
This can be integrated cleanly into an isolated repository directory (e.g., `tools/headless-agent/` or `cli/matryca/`). This sidecar tool is engineered with an ironclad safety bar, backed by **152 passing strict integration and concurrency tests**, strict MyPy compliance, and Ruff formatting.
It brings four major superpowers to the Logseq ecosystem:
- **AST-Native Headless Mutations:** Executes complex graph operations (deep nested outline writes, semantic property edits, task scans) directly at the raw Markdown layer via an independent Abstract Syntax Tree (AST) engine—operating with microsecond filesystem latency, completely network-free and application-closed.
- **Cross-Process File Locking (`fcntl.flock`):** A dual-layer locking mechanism. Before performing any read-modify-write loop, the companion tool safely acquires an OS-level lock on a sidecar `.{filename}.matryca.lock` file. Mutations are transactional (written to a hidden temp file, hardware-flushed via `os.fsync`, and swapped atomically via `os.replace`). Logseq’s built-in file-watcher automatically detects the atomic update on disk and hot-reloads the state seamlessly without any race conditions.
- **X-Ray Token Optimization Mode:** An automated stateless session registry mapping (`.matryca_xray_state.json`). It temporarily compresses raw 36-character block UUIDs into hyper-dense, positional index shortcuts (`[0]`, `[1]`, `[2]`) when communicating with LLMs, dropping context window token overhead by up to 35x.
- **Native Namespace Candidate Resolution:** Perfectly implements native Logseq filesystem rules, automatically mapping standard hierarchical forward slashes (`progetti/Name`) to triple-underscore disk files (`progetti___Name.md`) behind the scenes.
Because this is a zero-install, globally distributed engine (already live on PyPI as `matryca-logseq`), external tools like Claude Desktop can interface with any local Logseq graph instantly via a completely stateless configuration block:
{
"mcpServers": {
"matryca-logseq": {
"command": "uvx",
"args": ["--from", "matryca-logseq", "matryca-logseq-llm-wiki"],
"env": {
"LOGSEQ_GRAPH_PATH": "/absolute/path/to/your/Logseq/graph"
}
}
}
}
Why this Contribution is 100% Maintainer-Friendly
As per your explicit PR Guidelines, this contribution guarantees:
-
ZERO Heavy Refactoring: It is entirely additive and modular. Not a single line of your core Clojure/ClojureScript codebase, Clojure layout rendering, or Datascript state management is modified.
-
ZERO Dependency Churn: It introduces no risk to your core
package.jsonor existing build targets. It isolates its own environment (uv/ Python 3.12+ aligned). -
High Reliability: It includes its own independent, robust testing pyramid ensuring absolute regression safety.
We believe that providing an official, headless companion CLI will secure Logseq OG’s position as the premier, local-first database infrastructure for the AI era. We would love to open up a dialogue with the core maintainers on the best directory placement for this contribution!
Thank you for your incredible work on Logseq.
Best regards,
Marco Porcellato - Matryca.ai