fix: old cli unable to start

Looks like agent confused old cli w/ new cli
This commit is contained in:
Gabriel Horner
2026-02-12 20:57:37 -05:00
committed by rcmerci
parent 39f7006559
commit 6a8e35344b
2 changed files with 71 additions and 134 deletions

View File

@@ -6,35 +6,17 @@
[clojure.string :as string]
[logseq.cli.common.graph :as cli-common-graph]
[logseq.cli.spec :as cli-spec]
[logseq.cli.style :as style]
[logseq.cli.text-util :as cli-text-util]
[nbb.error]
[promesa.core :as p]))
(defn- escape-regex
[value]
(string/replace value #"[\\.^$|?*+()\\[\\]{}]" "\\\\$&"))
(defn- bold-command-names
[value commands]
(reduce (fn [acc command]
(let [pattern (re-pattern (str "(?m)^(\\s*)" (escape-regex command) "(\\s+)"))]
(string/replace acc pattern (fn [[_ prefix spacing]]
(str prefix (style/bold command) spacing)))))
value
commands))
(defn- format-commands [{:keys [table]}]
(let [entries (->> table
(filter (comp seq :cmds)))
rows (mapv (fn [{:keys [cmds desc spec]}]
(cond-> [(str (string/join " " cmds)
(when spec " [options]"))]
desc (conj desc)))
entries)
commands (map (comp #(string/join " " %) :cmds) entries)]
(-> (cli/format-table {:rows rows})
(bold-command-names commands))))
(let [table (mapv (fn [{:keys [cmds desc spec]}]
(cond-> [(str (string/join " " cmds)
(when spec " [options]"))]
desc (conj desc)))
(filter (comp seq :cmds) table))]
(cli/format-table {:rows table})))
(def ^:private default-spec
{:version {:coerce :boolean
@@ -43,10 +25,9 @@
(declare table)
(defn- print-general-help [_m]
(println (str "Usage: logseq [command] [options]\n\n"
(style/bold "Options") ":\n"
(style/bold-options (cli/format-opts {:spec default-spec}))))
(println (str "\n" (style/bold "Commands") ":\n" (format-commands {:table table}))))
(println (str "Usage: logseq [command] [options]\n\nOptions:\n"
(cli/format-opts {:spec default-spec})))
(println (str "\nCommands:\n" (format-commands {:table table}))))
(defn- default-command
[{{:keys [version]} :opts :as m}]
@@ -64,11 +45,10 @@
(str " " (string/join " "
(map #(str "[" (name %) "]") (:args->opts cmd-map)))))
(when (:spec cmd-map)
(str " [options]\n\n" (style/bold "Options") ":\n"
(style/bold-options (cli/format-opts {:spec (:spec cmd-map)}))))
(str " [options]\n\nOptions:\n"
(cli/format-opts {:spec (:spec cmd-map)})))
(when (:description cmd-map)
(str "\n\n" (style/bold "Description") ":\n"
(cli-text-util/wrap-text (:description cmd-map) 80))))))
(str "\n\nDescription:\n" (cli-text-util/wrap-text (:description cmd-map) 80))))))
(defn- help-command [{{:keys [command help]} :opts}]
(if-let [cmd-map (and command (some #(when (= command (first (:cmds %))) %) table))]
@@ -76,7 +56,7 @@
;; handle help --help
(if-let [cmd-map (and help (some #(when (= "help" (first (:cmds %))) %) table))]
(print-command-help "help" cmd-map)
(println (style/bold "Command") (pr-str command) "does not exist"))))
(println "Command" (pr-str command) "does not exist"))))
(defn- lazy-load-fn
"Lazy load fn to speed up start time. After nbb requires ~30 namespaces, start time gets close to 1s.
@@ -129,7 +109,7 @@
:args->opts [:args] :require [:args] :coerce {:args []}
:spec cli-spec/append}
{:cmds ["mcp-server"] :desc "Run a MCP server"
:description "Run a MCP server against a local graph if --repo is given or against the current in-app graph. For the in-app graph, the API server must be on in the app. By default the MCP server runs as a HTTP Streamable server. Use --stdio to run it as a stdio server."
:description "Run a MCP server against a local graph if --graph is given or against the current in-app graph. For the in-app graph, the API server must be on in the app. By default the MCP server runs as a HTTP Streamable server. Use --stdio to run it as a stdio server."
:fn (lazy-load-fn 'logseq.cli.commands.mcp-server/start)
:spec cli-spec/mcp-server}
{:cmds ["validate"] :desc "Validate DB graph"
@@ -166,12 +146,9 @@
(if (and (= :org.babashka/cli type')
(= :require cause))
(do
(println (style/bold-keywords
(str "Error: Command missing required "
(if (get-in data [:spec option]) "option" "argument")
" "
(style/bold (pr-str (name option))))
["command" "option" "argument"]))
(println "Error: Command missing required"
(if (get-in data [:spec option]) "option" "argument")
(pr-str (name option)))
(when-let [cmd-m (some #(when (= {:spec (:spec %)
:require (:require %)}
(select-keys data [:spec :require])) %) table)]
@@ -182,4 +159,4 @@
(nbb.error/print-error-report e)
(js/process.exit 1))))
#js {:main -main}
#js {:main -main}

View File

@@ -16,64 +16,50 @@
[malli.core :as m]
[malli.error :as me]))
(defn- minimal-list-item
[e]
(cond-> {:db/id (:db/id e)
:block/title (:block/title e)
:block/created-at (:block/created-at e)
:block/updated-at (:block/updated-at e)}
(:db/ident e) (assoc :db/ident (:db/ident e))))
(defn list-properties
"Main fn for ListProperties tool"
[db {:keys [expand include-built-in] :as options}]
(let [include-built-in? (if (contains? options :include-built-in) include-built-in true)]
(->> (d/datoms db :avet :block/tags :logseq.class/Property)
(map #(d/entity db (:e %)))
(remove (fn [e]
(and (not include-built-in?)
(ldb/built-in? e))))
#_((fn [x] (prn :prop-keys (distinct (mapcat keys x))) x))
(map (fn [e]
(if expand
(cond-> (into {} e)
true
(dissoc e :block/tags :block/order :block/refs :block/name :db/index
:logseq.property.embedding/hnsw-label-updated-at :logseq.property/default-value)
true
(update :block/uuid str)
(:logseq.property/classes e)
(update :logseq.property/classes #(mapv :db/ident %))
(:logseq.property/description e)
(update :logseq.property/description db-property/property-value-content))
(minimal-list-item e)))))))
[db {:keys [expand]}]
(->> (d/datoms db :avet :block/tags :logseq.class/Property)
(map #(d/entity db (:e %)))
#_((fn [x] (prn :prop-keys (distinct (mapcat keys x))) x))
(map (fn [e]
(if expand
(cond-> (into {} e)
true
(dissoc e :block/tags :block/order :block/refs :block/name :db/index
:logseq.property.embedding/hnsw-label-updated-at :logseq.property/default-value)
true
(update :block/uuid str)
(:logseq.property/classes e)
(update :logseq.property/classes #(mapv :db/ident %))
(:logseq.property/description e)
(update :logseq.property/description db-property/property-value-content))
{:block/title (:block/title e)
:block/uuid (str (:block/uuid e))})))))
(defn list-tags
"Main fn for ListTags tool"
[db {:keys [expand include-built-in] :as options}]
(let [include-built-in? (if (contains? options :include-built-in) include-built-in true)]
(->> (d/datoms db :avet :block/tags :logseq.class/Tag)
(map #(d/entity db (:e %)))
(remove (fn [e]
(and (not include-built-in?)
(ldb/built-in? e))))
(map (fn [e]
(if expand
(cond-> (into {} e)
true
(dissoc e :block/tags :block/order :block/refs :block/name
:logseq.property.embedding/hnsw-label-updated-at)
true
(update :block/uuid str)
(:logseq.property.class/extends e)
(update :logseq.property.class/extends #(mapv :db/ident %))
(:logseq.property.class/properties e)
(update :logseq.property.class/properties #(mapv :db/ident %))
(:logseq.property.view/type e)
(assoc :logseq.property.view/type (:db/ident (:logseq.property.view/type e)))
(:logseq.property/description e)
(update :logseq.property/description db-property/property-value-content))
(minimal-list-item e)))))))
[db {:keys [expand]}]
(->> (d/datoms db :avet :block/tags :logseq.class/Tag)
(map #(d/entity db (:e %)))
(map (fn [e]
(if expand
(cond-> (into {} e)
true
(dissoc e :block/tags :block/order :block/refs :block/name
:logseq.property.embedding/hnsw-label-updated-at)
true
(update :block/uuid str)
(:logseq.property.class/extends e)
(update :logseq.property.class/extends #(mapv :db/ident %))
(:logseq.property.class/properties e)
(update :logseq.property.class/properties #(mapv :db/ident %))
(:logseq.property.view/type e)
(assoc :logseq.property.view/type (:db/ident (:logseq.property.view/type e)))
(:logseq.property/description e)
(update :logseq.property/description db-property/property-value-content))
{:block/title (:block/title e)
:block/uuid (str (:block/uuid e))})))))
(defn- get-page-blocks
[db page-id]
@@ -105,47 +91,21 @@
(dissoc :block/children :block/page))
(get-page-blocks db (:db/id page)))}))
(defn- parse-time
[value]
(cond
(number? value) value
(string? value) (let [ms (js/Date.parse value)]
(when-not (js/isNaN ms) ms))
:else nil))
(defn list-pages
"Main fn for ListPages tool"
[db {:keys [expand include-hidden include-journal journal-only created-after updated-after] :as options}]
(let [include-hidden? (boolean include-hidden)
include-journal? (if (contains? options :include-journal) include-journal true)
journal-only? (boolean journal-only)
created-after-ms (parse-time created-after)
updated-after-ms (parse-time updated-after)]
(->> (d/datoms db :avet :block/name)
(map #(d/entity db (:e %)))
(remove (fn [e]
(and (not include-hidden?)
(entity-util/hidden? e))))
(remove (fn [e]
(let [is-journal? (ldb/journal? e)]
(cond
journal-only? (not is-journal?)
(false? include-journal?) is-journal?
:else false))))
(remove (fn [e]
(and created-after-ms
(<= (:block/created-at e 0) created-after-ms))))
(remove (fn [e]
(and updated-after-ms
(<= (:block/updated-at e 0) updated-after-ms))))
(map (fn [e]
(if expand
(-> e
;; Until there are options to limit pages, return minimal info to avoid
;; exceeding max payload size
(select-keys [:db/id :db/ident :block/uuid :block/title :block/created-at :block/updated-at])
(update :block/uuid str))
(minimal-list-item e)))))))
[db {:keys [expand]}]
(->> (d/datoms db :avet :block/name)
(map #(d/entity db (:e %)))
(remove entity-util/hidden?)
(map (fn [e]
(if expand
(-> e
;; Until there are options to limit pages, return minimal info to avoid
;; exceeding max payload size
(select-keys [:block/uuid :block/title :block/created-at :block/updated-at])
(update :block/uuid str))
{:block/title (:block/title e)
:block/uuid (str (:block/uuid e))})))))
;; upsert-nodes tool
;; =================
@@ -435,4 +395,4 @@
[conn operations* {:keys [dry-run] :as opts}]
(let [import-edn (build-upsert-nodes-edn @conn operations*)]
(when-not dry-run (import-edn-data conn import-edn))
(summarize-upsert-operations operations* opts)))
(summarize-upsert-operations operations* opts)))