mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +00:00
020-logseq-cli-default-paths-move.md
This commit is contained in:
@@ -56,7 +56,7 @@ Global options apply to all subcommands and are parsed before subcommand options
|
||||
| --- | --- | --- |
|
||||
| --help | Show help | Available at top level and per subcommand. |
|
||||
| --version | Show version | Prints build time and revision. |
|
||||
| --config PATH | Config file path | Defaults to ~/.logseq/cli.edn. |
|
||||
| --config PATH | Config file path | Defaults to ~/logseq/cli.edn. |
|
||||
| --repo REPO | Graph name | Used as current repo. |
|
||||
| --timeout-ms MS | Request timeout | Integer milliseconds. |
|
||||
| --output FORMAT | Output format | One of human, json, edn. |
|
||||
|
||||
@@ -44,7 +44,7 @@ Key changes:
|
||||
- Reject `thread-api/create-or-open-db`, `thread-api/unsafe-unlink-db`, etc. when repo differs.
|
||||
- Return 409/400 with `:repo-mismatch` error shape.
|
||||
- **Lock file**:
|
||||
- Location: inside repo dir (e.g. `~/.logseq/cli-graphs/<graph>/db-worker.lock`).
|
||||
- Location: inside repo dir (e.g. `~/logseq/cli-graphs/<graph>/db-worker.lock`).
|
||||
- Content: JSON `{repo, pid, host, port, startedAt}`.
|
||||
- Creation: exclusive create (`fs.open` with `wx`) or atomic temp + rename. If exists, fail with “graph already locked”.
|
||||
- Cleanup: delete lock file on stop (`stop!`) and on SIGINT/SIGTERM.
|
||||
@@ -108,7 +108,7 @@ Implementation notes:
|
||||
- Answer: No --repo needed, using 'out-of-band access to data-dir' way
|
||||
2. Lock file format and location: confirm cross-platform expectations (Windows paths/permissions).
|
||||
- lockfile name:`db-worker.lock`,
|
||||
- Location: inside repo dir (e.g. `~/.logseq/cli-graphs/<graph>/db-worker.lock`).
|
||||
- Location: inside repo dir (e.g. `~/logseq/cli-graphs/<graph>/db-worker.lock`).
|
||||
- only consider linux/macos for now
|
||||
3. Who owns lock cleanup and stale lock handling: primarily db-worker-node; CLI only steps in for cases db-worker-node cannot handle.
|
||||
4. Add `/v1/shutdown` for graceful stop vs. SIGTERM from CLI?
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
## Context
|
||||
logseq-cli and db-worker-node currently store CLI-managed graphs under `~/.logseq/db-worker/` and use per-graph directories named like `.logseq-pool-<graph-name>/` (with partial encoding). This plan captures the non-functional updates requested:
|
||||
|
||||
1) Rename `~/.logseq/db-worker/` to `~/.logseq/cli-graphs/` for CLI-managed graphs.
|
||||
1) Rename `~/.logseq/db-worker/` to `~/logseq/cli-graphs/` for CLI-managed graphs.
|
||||
2) Rename per-graph directory format from `.logseq-pool-<graph-name>/` to `<graph-name>/`.
|
||||
3) Ensure graph names that are not valid directory names are encoded, and decoding is symmetric when reading/listing.
|
||||
|
||||
## Goals
|
||||
- Move CLI graph storage to `~/.logseq/cli-graphs` by default.
|
||||
- Move CLI graph storage to `~/logseq/cli-graphs` by default.
|
||||
- Use a clean per-graph directory name equal to the (encoded) graph name, without `.` prefix or `logseq-pool-` prefix.
|
||||
- Provide a reversible encode/decode for graph names so list/read operations reconstruct the original graph name.
|
||||
- CLI commands and outputs should hide the internal `logseq_db_` prefix; user-facing graph names strip that db prefix.
|
||||
@@ -29,7 +29,7 @@ logseq-cli and db-worker-node currently store CLI-managed graphs under `~/.logse
|
||||
|
||||
## Proposed Approach
|
||||
### 1) New default data dir
|
||||
- Change default data dir for CLI and db-worker-node from `~/.logseq/db-worker` to `~/.logseq/cli-graphs`.
|
||||
- Change default data dir for CLI and db-worker-node from `~/.logseq/db-worker` to `~/logseq/cli-graphs`.
|
||||
- Update help text and any user-facing docs mentioning the old default.
|
||||
|
||||
### 2) New per-graph directory naming
|
||||
@@ -51,7 +51,7 @@ logseq-cli and db-worker-node currently store CLI-managed graphs under `~/.logse
|
||||
- Files: `src/main/frontend/worker_common/util.cljc`, potentially `deps/cli/src/logseq/cli/common/graph.cljs`.
|
||||
|
||||
2) Update data dir defaults
|
||||
- Change defaults to `~/.logseq/cli-graphs` in:
|
||||
- Change defaults to `~/logseq/cli-graphs` in:
|
||||
- `src/main/logseq/cli/config.cljs`
|
||||
- `src/main/logseq/cli/server.cljs`
|
||||
- `src/main/frontend/worker/db_worker_node_lock.cljs`
|
||||
|
||||
@@ -12,7 +12,7 @@ Tech Stack: ClojureScript, Node.js fs APIs, promesa, logseq-cli, db-worker-node.
|
||||
|
||||
## Current behavior summary
|
||||
|
||||
- `logseq.cli.config/resolve-config` defaults `:data-dir` to `~/.logseq/cli-graphs`.
|
||||
- `logseq.cli.config/resolve-config` defaults `:data-dir` to `~/logseq/cli-graphs`.
|
||||
- `logseq.cli.server` resolves and uses `data-dir` for locks and server discovery.
|
||||
- `frontend.worker.db-worker-node` writes logs and lock files under `data-dir` and delegates storage to `frontend.worker.platform.node`, which creates directories as needed.
|
||||
- No explicit read/write permission checks exist; errors bubble up from fs operations.
|
||||
|
||||
77
docs/agent-guide/020-logseq-cli-default-paths-move.md
Normal file
77
docs/agent-guide/020-logseq-cli-default-paths-move.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Logseq CLI Default Paths Move Plan
|
||||
|
||||
Goal: Move the default `--data-dir` location to `~/logseq/cli-graphs` and the default `cli.edn` location to `~/logseq/cli.edn`, keeping logseq-cli and db-worker-node consistent.
|
||||
|
||||
Architecture: logseq-cli resolves defaults in `logseq.cli.config` and `logseq.cli.data-dir`, then hands `data-dir` into `logseq.cli.server` which spawns and manages db-worker-node. db-worker-node itself also resolves `data-dir` for logs, locks, and SQLite storage via `frontend.worker.platform.node` and `frontend.worker.db-worker-node-lock`.
|
||||
|
||||
Tech Stack: ClojureScript, Node.js fs/path, logseq-cli, db-worker-node.
|
||||
|
||||
## Problem statement
|
||||
|
||||
Defaults currently live under `~/.logseq/`, but CLI data is not the same as desktop app data and should live under `~/logseq/` for better discoverability and separation. We need to update the defaults in both logseq-cli and db-worker-node, and update docs/help text to match.
|
||||
|
||||
## Current behavior summary
|
||||
|
||||
- logseq-cli uses `~/logseq/cli-graphs` as the default data dir.
|
||||
- db-worker-node help text and internal resolution also default to `~/logseq/cli-graphs`.
|
||||
- logseq-cli defaults config path to `~/logseq/cli.edn`.
|
||||
- Docs reference `~/logseq/cli.edn` and `~/logseq/cli-graphs`.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Default `data-dir` becomes `~/logseq/cli-graphs` everywhere it is derived.
|
||||
- Default config path becomes `~/logseq/cli.edn`.
|
||||
- `--data-dir` and `--config` flags continue to override defaults.
|
||||
- `LOGSEQ_CLI_DATA_DIR` and `LOGSEQ_CLI_CONFIG` (if present) continue to override defaults.
|
||||
- Help text and docs must match the new defaults.
|
||||
|
||||
## Non-goals
|
||||
|
||||
- Do not migrate existing data automatically.
|
||||
- Do not change CLI flags, env var names, or db-worker-node storage layout.
|
||||
- Do not change runtime behavior beyond the default locations.
|
||||
|
||||
## Design decisions
|
||||
|
||||
- Keep default paths defined in a single place per subsystem (CLI vs db-worker-node), but ensure they resolve to the same new location.
|
||||
- Do not auto-detect the old location as a fallback to avoid surprises; users can pass `--data-dir` / `--config` explicitly if needed.
|
||||
- Document the change and provide a brief migration note in CLI docs.
|
||||
|
||||
## Implementation plan
|
||||
|
||||
### 1) Update default `data-dir` constants and resolution
|
||||
|
||||
- `src/main/logseq/cli/data_dir.cljs`
|
||||
- Change `default-data-dir` from `~/logseq/cli-graphs` to `~/logseq/cli-graphs`.
|
||||
- `src/main/logseq/cli/server.cljs`
|
||||
- Update `resolve-data-dir` default to `~/logseq/cli-graphs` (keeps server defaults aligned when config is absent).
|
||||
- `src/main/frontend/worker/db_worker_node_lock.cljs`
|
||||
- Update `resolve-data-dir` default to `~/logseq/cli-graphs`.
|
||||
- `src/main/frontend/worker/platform/node.cljs`
|
||||
- Update `node-platform` default for `data-dir` to `~/logseq/cli-graphs`.
|
||||
- `src/main/frontend/worker/db_worker_node.cljs`
|
||||
- Update the `--data-dir` help text default to `~/logseq/cli-graphs`.
|
||||
|
||||
### 2) Update default config path for CLI
|
||||
|
||||
- `src/main/logseq/cli/config.cljs`
|
||||
- Change `config-path` default from `~/logseq/cli.edn` to `~/logseq/cli.edn`.
|
||||
- Update any inline default map (`resolve-config` default options) to match if present.
|
||||
|
||||
### 3) Update docs and internal references
|
||||
|
||||
- `docs/cli/logseq-cli.md`
|
||||
- Replace references to `~/logseq/cli.edn` and `~/logseq/cli-graphs` with the new paths.
|
||||
- Add a short migration note: existing data/config can be used by passing `--data-dir` / `--config`.
|
||||
- `docs/agent-guide/*.md`
|
||||
- Update any references to the old defaults (notably `docs/agent-guide/002-logseq-cli-subcommands.md`, `docs/agent-guide/003-db-worker-node-cli-orchestration.md`, `docs/agent-guide/012-logseq-cli-graph-storage.md`, `docs/agent-guide/019-logseq-cli-data-dir-permissions.md`, and `docs/agent-guide/task--db-worker-nodejs-compatible.md`).
|
||||
|
||||
### 4) Tests
|
||||
|
||||
- Unit tests likely unaffected, but adjust any tests or snapshots that assert default path strings (search for `~/logseq/cli-graphs` or `~/logseq/cli.edn` in tests).
|
||||
- If tests assert CLI help output or default config path, update expected strings accordingly.
|
||||
|
||||
## Notes
|
||||
|
||||
- Do not add a one-time warning for the old `~/logseq/cli-graphs` location. If a config is needed, prefer `cli.edn` under the selected `data-dir`.
|
||||
- Do not add any fallback or compatibility for `~/logseq/cli.edn`. The old location is ignored.
|
||||
@@ -129,7 +129,7 @@ The db-worker should be runnable as a standalone process for Node.js environment
|
||||
- Provide a CLI entry (example: `bin/logseq-db-worker` or `./dist/db-worker-node.js`).
|
||||
- CLI flags (suggested):
|
||||
- Binds to localhost on a random port and records it in the repo lock file.
|
||||
- `--data-dir` (path for sqlite files, required or default to `~/.logseq/cli-graphs`)
|
||||
- `--data-dir` (path for sqlite files, required or default to `~/logseq/cli-graphs`)
|
||||
- `--repo` (optional: auto-open a repo on boot)
|
||||
- `--rtc-ws-url` (optional)
|
||||
- `--log-level` (default `info`)
|
||||
|
||||
@@ -30,7 +30,11 @@ logseq graph list
|
||||
|
||||
## Configuration
|
||||
|
||||
Optional configuration file: `~/.logseq/cli.edn`
|
||||
Optional configuration file: `~/logseq/cli.edn`
|
||||
|
||||
Default data dir: `~/logseq/cli-graphs`.
|
||||
|
||||
Migration note: If you previously used `~/.logseq/cli-graphs` or `~/.logseq/cli.edn`, pass `--data-dir` or `--config` to continue using those locations.
|
||||
|
||||
Supported keys include:
|
||||
- `:repo`
|
||||
|
||||
@@ -226,7 +226,7 @@
|
||||
(defn- show-help!
|
||||
[]
|
||||
(println "db-worker-node options:")
|
||||
(println " --data-dir <path> (default ~/.logseq/cli-graphs)")
|
||||
(println " --data-dir <path> (default ~/logseq/cli-graphs)")
|
||||
(println " --repo <name> (required)")
|
||||
(println " --rtc-ws-url <url> (optional)")
|
||||
(println " --log-level <level> (default info)")
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
(defn resolve-data-dir
|
||||
[data-dir]
|
||||
(expand-home (or data-dir "~/.logseq/cli-graphs")))
|
||||
(expand-home (or data-dir "~/logseq/cli-graphs")))
|
||||
|
||||
(defn repo-dir
|
||||
[data-dir repo]
|
||||
|
||||
@@ -186,7 +186,7 @@
|
||||
|
||||
(defn node-platform
|
||||
[{:keys [data-dir event-fn]}]
|
||||
(let [data-dir (expand-home (or data-dir "~/.logseq/cli-graphs"))
|
||||
(let [data-dir (expand-home (or data-dir "~/logseq/cli-graphs"))
|
||||
kv (kv-store data-dir)]
|
||||
(p/do!
|
||||
(ensure-dir! data-dir)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
:coerce :long}
|
||||
:target-uuid {:desc "Target block UUID"}
|
||||
:target-page-name {:desc "Target page name"}
|
||||
:pos {:desc "Position (first-child, last-child, sibling)"}
|
||||
:pos {:desc "Position (first-child, last-child, sibling). Default: last-child"}
|
||||
:status {:desc "Task status (todo, doing, done, etc.)"}})
|
||||
|
||||
(def ^:private add-page-spec
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
:coerce :boolean}
|
||||
:version {:desc "Show version"
|
||||
:coerce :boolean}
|
||||
:config {:desc "Path to cli.edn"}
|
||||
:config {:desc "Path to cli.edn (default ~/logseq/cli.edn)"}
|
||||
:repo {:desc "Graph name"}
|
||||
:data-dir {:desc "Path to db-worker data dir"}
|
||||
:timeout-ms {:desc "Request timeout in ms"
|
||||
:data-dir {:desc "Path to db-worker data dir (default ~/logseq/cli-graphs)"}
|
||||
:timeout-ms {:desc "Request timeout in ms (default 10000)"
|
||||
:coerce :long}
|
||||
:output {:desc "Output format (human, json, edn)"}})
|
||||
:output {:desc "Output format (human, json, edn). Default: human"}})
|
||||
|
||||
(defn global-spec
|
||||
[]
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
:offset {:desc "Offset results"
|
||||
:coerce :long}
|
||||
:sort {:desc "Sort field"}
|
||||
:order {:desc "Sort order (asc, desc)"}})
|
||||
:order {:desc "Sort order (asc, desc). Default: asc"}})
|
||||
|
||||
(def ^:private list-page-spec
|
||||
(merge list-common-spec
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
:coerce :long}
|
||||
:target-uuid {:desc "Target block UUID"}
|
||||
:target-page {:desc "Target page name"}
|
||||
:pos {:desc "Position (first-child, last-child, sibling)"}})
|
||||
:pos {:desc "Position (first-child, last-child, sibling). Default: first-child"}})
|
||||
|
||||
(def entries
|
||||
[(core/command-entry ["move"] :move-block "Move block" move-spec)])
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
{:id {:desc "Block db/id or EDN vector of ids"}
|
||||
:uuid {:desc "Block UUID"}
|
||||
:page {:desc "Page name"}
|
||||
:level {:desc "Limit tree depth"
|
||||
:level {:desc "Limit tree depth (default 10)"
|
||||
:coerce :long}})
|
||||
|
||||
(def entries
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
(defn- default-config-path
|
||||
[]
|
||||
(node-path/join (.homedir os) ".logseq" "cli.edn"))
|
||||
(node-path/join (.homedir os) "logseq" "cli.edn"))
|
||||
|
||||
(defn- read-config-file
|
||||
[config-path]
|
||||
@@ -75,7 +75,7 @@
|
||||
[opts]
|
||||
(let [defaults {:timeout-ms 10000
|
||||
:output-format nil
|
||||
:data-dir "~/.logseq/cli-graphs"
|
||||
:data-dir "~/logseq/cli-graphs"
|
||||
:config-path (default-config-path)}
|
||||
env (env-config)
|
||||
config-path (or (:config-path opts)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
["path" :as node-path]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(def ^:private default-data-dir "~/.logseq/cli-graphs")
|
||||
(def ^:private default-data-dir "~/logseq/cli-graphs")
|
||||
|
||||
(defn- expand-home
|
||||
[path]
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
(defn resolve-data-dir
|
||||
[config]
|
||||
(expand-home (or (:data-dir config) "~/.logseq/cli-graphs")))
|
||||
(expand-home (or (:data-dir config) "~/logseq/cli-graphs")))
|
||||
|
||||
(defn- repo-dir
|
||||
[data-dir repo]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[goog.object :as gobj]
|
||||
[logseq.cli.config :as config]
|
||||
["fs" :as fs]
|
||||
["os" :as os]
|
||||
["path" :as node-path]))
|
||||
|
||||
(defn- with-env
|
||||
@@ -77,6 +78,12 @@
|
||||
:output "json"})]
|
||||
(is (= :edn (:output-format result)))))
|
||||
|
||||
(deftest test-default-paths
|
||||
(let [result (config/resolve-config {})
|
||||
expected-config-path (node-path/join (.homedir os) "logseq" "cli.edn")]
|
||||
(is (= expected-config-path (:config-path result)))
|
||||
(is (= "~/logseq/cli-graphs" (:data-dir result)))))
|
||||
|
||||
(deftest test-update-config
|
||||
(let [dir (node-helper/create-tmp-dir "cli")
|
||||
cfg-path (node-path/join dir "cli.edn")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns logseq.cli.data-dir-test
|
||||
(:require ["fs" :as fs]
|
||||
["os" :as os]
|
||||
["path" :as node-path]
|
||||
[cljs.test :refer [deftest is testing]]
|
||||
[frontend.test.node-helper :as node-helper]
|
||||
@@ -39,3 +40,9 @@
|
||||
(let [data (ex-data e)]
|
||||
(is (= :data-dir-permission (:code data)))
|
||||
(is (= (node-path/resolve target) (:path data)))))))))
|
||||
|
||||
(deftest normalize-data-dir-default
|
||||
(testing "defaults to ~/logseq/cli-graphs"
|
||||
(let [expected (node-path/resolve (node-path/join (.homedir os) "logseq" "cli-graphs"))
|
||||
resolved (data-dir/normalize-data-dir nil)]
|
||||
(is (= expected resolved)))))
|
||||
|
||||
Reference in New Issue
Block a user