Goal: Build a new Logseq CLI in ClojureScript that runs on Node.js and connects to the db-worker-node server.
Architecture: The CLI is a Node-targeted ClojureScript program built via shadow-cljs and packaged with a small JavaScript launcher. The CLI speaks a simple request and response protocol to the existing db-worker-node HTTP or WebSocket API and exposes high-level subcommands for users.
Tech Stack: ClojureScript, shadow-cljs :node-script target, Node.js runtime, existing db-worker-node server.
Related: Relates to docs/agent-guide/task--basic-logseq-cli.md and docs/agent-guide/task--db-worker-nodejs-compatible.md.
We need a new Logseq CLI that is independent of any existing CLI code in the repo. The CLI must run in Node.js, be written in ClojureScript, and connect to the db-worker-node server started from static/db-worker-node.js. The CLI should provide a stable interface for scripting and troubleshooting, and it should be easy to extend with new commands.
I will add an integration test that starts db-worker-node on a test port and verifies the CLI can connect and run a simple graph/content request. I will add unit tests for command parsing, configuration precedence, and error formatting. I will add unit tests for the client transport layer to ensure timeouts and retries behave correctly. I will add unit tests for new graph/content commands (parsing, validation, and request mapping). I will add integration tests for graph lifecycle commands and content commands against a real db-worker-node. I will follow @test-driven-development for all behavior changes. NOTE: I will write all tests before I add any implementation behavior.
The CLI is a Node program that parses flags, loads config, and sends requests to db-worker-node. The db-worker-node server is already built from the :db-worker-node shadow-cljs target and listens on a TCP port.
ASCII diagram:
+--------------+ HTTP or WS +---------------------+ | logseq-cli | -----------------------> | db-worker-node | | node script | <----------------------- | server on port 9101 | +--------------+ +---------------------+
The db-worker-node server exposes a stable API for a small set of requests needed by the CLI. The CLI will default to localhost:9101 unless configured otherwise. The CLI will use JSON for request and response bodies for ease of scripting.
Implemented:
docs/cli/logseq-cli.md and linked from README.Not fully aligned with plan:
search currently queries :block/title only (no page name/content search).Open follow-ups (optional):
search to include page name/content and update tests.graph-info beyond :logseq.kv/graph-created-at and :logseq.kv/schema-version.| Command | Input | Output | Errors |
|---|---|---|---|
| graph-list | none | list of graphs | server unavailable, timeout |
| graph-create | graph name | created graph + set current graph | invalid name, server unavailable |
| graph-switch | graph name | switched graph + set current graph | missing graph, server unavailable |
| graph-remove | graph name | removal confirmation | missing graph, server unavailable |
| graph-validate | graph name or current graph | validation result | missing graph, server unavailable |
| graph-info | graph name or current graph | graph metadata/info | missing graph, server unavailable |
| add | block/page payload | created block IDs | invalid input, server unavailable |
| remove | block/page id or name | removal confirmation | invalid input, server unavailable |
| search | text query | matched blocks/pages | invalid input, server unavailable |
| tree | block/page id or name | hierarchical tree output | invalid input, server unavailable |
The db-worker-node server is not running or is listening on a different port. The response payload is invalid JSON or missing fields. The request times out or the server closes the connection early. The user passes incompatible flags or unknown commands. The CLI is run on Windows where path and quoting rules differ. Graph commands are invoked without a current graph configured. Content commands are invoked without specifying a graph and no current graph is set. Content commands refer to missing pages/blocks. Graph removal is attempted while a graph is open.
Run a single unit test in red phase.
bb dev:test -v logseq.cli.config-test/test-config-precedence
Expected output includes a failing assertion and ends with a non-zero exit code.
Run the full unit test suite in green phase.
bb dev:test -v logseq.cli.*
Expected output includes 0 failures and 0 errors.
Run lint and unit tests when all work is complete.
bb dev:lint-and-test
Expected output includes successful linting and tests with exit code 0.
I will add behavior-driven tests that verify the CLI connects to a real db-worker-node process and that each command returns the expected output for valid input. I will keep unit tests focused on pure functions like parsing, formatting, and config resolution, and avoid mocking internal implementation details.
Which exact db-worker-node endpoints and request schemas should the CLI use for graph/content commands.
Do we want WebSocket or HTTP as the default transport for the CLI.
Can I consult the clojure-expert and research-agent agents for architecture and reference implementations as required by the planning guidelines.