mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 23:19:38 +00:00
7.8 KiB
7.8 KiB
060 — CLI graph list: mark legacy graph-dir and provide rename command
Summary
logseq-cli graph list currently filters out graph directories that cannot be decoded by the current canonical graph-dir encoding. This behavior makes legacy graph directories invisible to users.
This plan proposes to:
- Detect non-canonical (legacy) graph directories during graph listing.
- Mark them as
legacyingraph listoutput. - Show a warning when legacy entries exist.
- Print a suggested shell rename command from legacy dir name to current canonical encoded dir name (only when graph-name can be derived reliably).
Product decisions (locked)
- Scope is
graph listonly. - Human output must show:
- regular graph items (existing behavior),
- legacy marker per legacy item,
- a warning section when at least one legacy graph is found,
- one rename command suggestion per legacy graph when derivation is reliable.
- Structured outputs (
json/edn) must include legacy metadata (not human-only text). - Suggested command target is POSIX shell (
mv) with safe quoting. - If target encoded dir already exists, output should include conflict guidance instead of a blind rename suggestion.
- If a legacy dir cannot be decoded to a reliable graph-name, show
legacymarker and warning only; do not output a rename command.
Goals
- Make legacy graph dirs visible in
logseq-cli graph list. - Provide actionable migration guidance with minimal user effort.
- Keep current canonical graph listing behavior unchanged for non-legacy entries.
Non-goals
- Automatic rename/migration execution.
- Reworking graph storage layout.
- Adding new CLI subcommands in this iteration.
Current behavior (based on code)
src/main/logseq/cli/server.cljslist-graphsscans graph data dirs and decodes names via canonical decode.- Entries that fail canonical decode are dropped.
src/main/logseq/cli/command/graph.cljsexecute-graph-listpasses graph names to formatter.src/main/logseq/cli/format.cljsformat-graph-listrenders graph names but has no legacy path.
Related encoding utilities:
- Canonical encode/decode logic:
deps/common/src/logseq/common/graph_dir.cljssrc/main/frontend/worker/db_worker_node_lock.cljs
- Legacy token hints still exist in browser-side logic (
+3A+,++) and can be used to define migration decoding behavior.
Design
1) Data model for graph list results
Introduce a richer graph-list item shape from CLI server layer:
- Canonical item:
{:kind :canonical :graph-name <decoded-graph-name> :graph-dir <encoded-dir-name>}
- Legacy item:
{:kind :legacy :legacy-dir <raw-dir-name> :legacy-graph-name <decoded-or-derived-name> :target-graph-dir <canonical-encoded-dir-name> :conflict? <bool>}
- Undecodable non-canonical item:
{:kind :legacy-undecodable :legacy-dir <raw-dir-name> :reason <keyword-or-string>}
Notes:
legacy-graph-nameshould be derived using a dedicated legacy decode path (fallbacks allowed).target-graph-dirshould always be computed fromlegacy-graph-namethrough current canonical encoding.:legacy-undecodableentries must never produce rename commands.
2) Legacy detection and derivation
At graph discovery stage (src/main/logseq/cli/server.cljs):
- Keep current canonical decode attempt.
- If canonical decode succeeds -> canonical item.
- If canonical decode fails -> try legacy derivation:
- legacy token replacement decode path (e.g.
+3A+ -> :,++ -> /) as compatibility rule, - URI decode fallback if applicable.
- legacy token replacement decode path (e.g.
- If derivation yields a reliable name, classify as
:legacy. - If no reliable derivation is possible, classify as
:legacy-undecodableand include warning-only entry (no rename command).
3) Command layer contract
In src/main/logseq/cli/command/graph.cljs:
execute-graph-listshould return::datacontaining canonical + legacy + undecodable legacy metadata,:humanwarning payload when any legacy entries exist.
This keeps formatter logic deterministic while preserving structured output for json and edn.
4) Human formatter behavior
In src/main/logseq/cli/format.cljs:
- Extend graph list rendering to show legacy marker, for example:
- my/old/graph [legacy]- unknown-legacy-dir [legacy]
- Add warning block when legacy entries are present.
- For each renameable legacy item, print a shell suggestion:
mv '<data-dir>/<legacy-dir>' '<data-dir>/<target-graph-dir>'
- For conflict entries (
target already exists), print explicit conflict note and no directmvcommand. - For undecodable legacy entries, print explicit warning and no
mvcommand.
5) Shell quoting
Current CLI arg quoting helper is not sufficient for robust shell copy/paste.
Plan:
- Add a dedicated POSIX single-quote escaping helper for rendered shell suggestions.
- Use it only in human formatting layer.
Output examples (human)
Example list section:
my/new/graphmy/old/graph [legacy]strange-dir-name [legacy]
Warning section example:
Warning: 2 legacy graph directories detected.Rename suggestion:mv '/path/to/data/my++old++graph' '/path/to/data/my~2Fold~2Fgraph'Warning: cannot derive graph name for legacy dir 'strange-dir-name'; rename command is not available.
Conflict example:
Warning: target directory already exists for legacy graph 'my/old/graph'.Please rename manually after resolving the conflict.
Test plan
Unit tests
src/test/logseq/cli/commands_test.cljs- verify
graph listcommand data includes legacy and undecodable legacy entries.
- verify
src/test/logseq/cli/format_test.cljs- verify human output marker
[legacy]. - verify warning block appears only when legacy exists.
- verify rename command rendering and shell quoting.
- verify undecodable legacy outputs warning only and no rename command.
- verify human output marker
src/test/frontend/worker/graph_dir_test.cljs- extend coverage for canonical encode/decode + legacy derivation helper behavior.
Integration tests
src/test/logseq/cli/integration_test.cljs- seed canonical + legacy dirs in test data dir.
- assert
graph listbehavior for human/json/edn outputs. - assert conflict message when target encoded dir already exists.
- assert undecodable legacy case emits warning without rename command.
Edge cases
- Legacy dir cannot be decoded to a graph name.
- Canonical target dir already exists.
- Graph names containing shell-sensitive characters.
- Mixed directories that are not graph dirs (must avoid false positives).
Implementation plan
- Add legacy classification utilities and detailed graph list payload in CLI server layer.
- Adapt
graph listcommand contract to pass structured legacy information to formatter and machine outputs. - Extend human formatter with legacy marker, warning block, and safe rename suggestions.
- Add/adjust tests for unit + integration coverage.
- Validate no regression for all existing
graph listoutput formats.
Acceptance criteria
graph listshows legacy entries instead of silently hiding them.- Human output includes explicit legacy marker and warning.
- Human output includes safe rename command for renameable entries.
- Undecodable legacy entries are clearly reported with warning only (no rename command).
- Conflict scenarios are surfaced without unsafe rename suggestions.
- JSON/EDN outputs expose legacy metadata for automation.
- Existing canonical-only behavior remains stable when no legacy entries exist.
Affected files (planned)
Would modify:
src/main/logseq/cli/server.cljssrc/main/logseq/cli/command/graph.cljssrc/main/logseq/cli/format.cljssrc/test/logseq/cli/commands_test.cljssrc/test/logseq/cli/format_test.cljssrc/test/logseq/cli/integration_test.cljssrc/test/frontend/worker/graph_dir_test.cljs
Would create:
docs/agent-guide/060-cli-graph-list-legacy-graph-dir-rename-command.md