5.4 KiB
Logseq CLI Show Output & Linked References Options Plan
Goal: Update the logseq show command to (1) render the ID column in human output with lighter styling (matching tree glyphs), (2) include :db/ident on block entities in JSON/EDN output when present, and (3) add an option to toggle Linked References (default enabled).
Architecture: Keep the existing logseq-cli → db-worker-node HTTP transport and thread-api calls; adjust show command selectors and output formatting only.
Tech Stack: ClojureScript, babashka.cli, db-worker-node transport, Logseq pull selectors, CLI styling helpers.
Related: Builds on logseq.cli.command.show tree rendering and linked references fetch; see docs/agent-guide/010-logseq-cli-show-linked-references.md and docs/agent-guide/023-logseq-cli-help-show-styling.md.
Problem Statement
The show command currently renders the ID column with the same styling as regular text, does not expose :db/ident in JSON/EDN output for blocks, and always fetches/prints Linked References. We need to make the ID column visually lighter, surface :db/ident when it exists, and add a switch to disable linked references (defaulting to true).
Non-Goals
- Changing db-worker-node APIs or transport protocols.
- Altering the show command’s existing tree structure or block ordering.
- Changing JSON/EDN output structure beyond adding
:db/identwhen present.
Current Behavior (Key Points)
- Human output is rendered by
tree->textinsrc/main/logseq/cli/command/show.cljs, with tree glyphs styled viastyle/dimbut IDs unstyled. - JSON/EDN output pulls specific selectors via
tree-block-selector/linked-ref-selectorand strips only:block/uuid. - Linked References are always fetched and rendered via
fetch-linked-references+tree->text-with-linked-refs.
Proposed Changes
-
Lighter ID column in human output
- Style the padded ID column with the same dim styling used for tree glyphs.
- Apply the change in
tree->textso both root and child rows render IDs dimmed.
-
Include
:db/identin JSON/EDN for blocks (when present)- Add
:db/identto block pull selectors:tree-block-selector(children)linked-ref-selector(linked references)- root entity pulls in
fetch-treefor:id,:uuid, and:page
- No post-processing is required because absent attributes will not appear in the pulled maps.
- Add
-
Optional Linked References (default true)
- Add a boolean option
--linked-referencestoshow-spec, defaulting to true. - Pass the option through
build-actionand intobuild-tree-data. - When disabled:
- Skip
fetch-linked-referencesentirely. - Omit the
Linked Referencessection from human output. - Omit
:linked-referencesfrom JSON/EDN output.
- Skip
- Add a boolean option
Implementation Plan
-
Add show option wiring
- Update
show-specinsrc/main/logseq/cli/command/show.cljswith a new boolean option (choose name + description, note default true). - Extend
build-actionto include the option in:action(e.g.,:linked-references?). - Update
invalid-options?if needed for any new validation.
- Update
-
Gate linked references fetching/rendering
- Update
build-tree-datato honor the new option:- If enabled, keep current logic.
- If disabled, skip
fetch-linked-references, avoid UUID label resolution based on linked refs, and avoidtree->text-with-linked-refs.
- Update
execute-showto selecttree->textvstree->text-with-linked-refsbased on the option. - Ensure JSON/EDN output omits
:linked-referenceswhen disabled.
- Update
-
Add
:db/identto selectors- Update
tree-block-selector,linked-ref-selector, and root entity pull vectors infetch-treeto include:db/ident. - Ensure this does not add nil values (pull should omit missing attributes).
- Update
-
Dim ID column in human output
- In
tree->text, applystyle/dimto the padded ID string (e.g.,pad-idoutput) for both root and child rows. - Keep existing branch/prefix dim styling unchanged.
- In
-
Help output updates
- Ensure
logseq show --helplists the new linked references option (covered automatically byshow-spec).
- Ensure
Testing Plan
- Update or add unit tests in:
src/test/logseq/cli/format_test.cljsto verify:- ANSI dim styling is applied to the ID column in human output when color is enabled.
- No regressions in strip-ansi output.
src/test/logseq/cli/commands_test.cljsto verify:logseq show --helpincludes the new linked references option.
- Add show-specific tests for JSON/EDN output:
- Ensure
:db/identappears when present (use a stubbed tree map or test fixtures if available). - Ensure
:linked-referencesis omitted when the option disables them.
- Ensure
Edge Cases
- Blocks with no
:db/identshould not gain a nil or empty key in output. - When linked refs are disabled, UUID label resolution should not depend on linked refs (ensure
collect-uuid-refshandles empty refs). - Multi-id output should still honor the linked references option per target and not render linked refs when disabled.
Files to Touch
src/main/logseq/cli/command/show.cljs(options, selectors, tree output, linked refs gating)src/test/logseq/cli/format_test.cljs(ID dim styling test)src/test/logseq/cli/commands_test.cljs(help output)- Possibly
src/test/logseq/cli/command_show_test.cljsor similar if a dedicated show test file exists
Open Questions
- None.