Skip to content

Commit 0774782

Browse files
leifericfclaude
andcommitted
fix(launcher): auto-update stale JAR when launcher version advances
jar/ensure! now compares the launcher version against version.edn inside the installed JAR. On mismatch it stops the daemon, downloads the matching release, and lets daemon/ensure! restart fresh. Also bounces the daemon after `noum upgrade` so the new JAR is actually loaded, and moves the version def to paths.clj so both main.clj and api.clj can reference it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ba92c47 commit 0774782

5 files changed

Lines changed: 41 additions & 23 deletions

File tree

launcher/src/noum/api.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
(if-let [host (:host effective)]
201201
{:host host :token (:token effective) :insecure (:insecure effective)}
202202
(let [jre-path (jre/ensure!)
203-
jar-path (jar/ensure!)]
203+
jar-path (jar/ensure! paths/version)]
204204
(daemon/ensure! (merge {:jre-path jre-path :jar-path jar-path}
205205
(select-keys effective [:db-dir :provider :model :token])))))))
206206

launcher/src/noum/jar.clj

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(:require [babashka.fs :as fs]
44
[babashka.http-client :as http]
55
[cheshire.core :as json]
6+
[clojure.edn :as edn]
67
[clojure.java.io :as io]
78
[noum.daemon :as daemon]
89
[noum.paths :as paths]
@@ -63,15 +64,14 @@
6364
{:expected expected :actual actual})))))
6465
(tui/eprintln " Warning: no .sha256 sidecar in release, skipping checksum verification.")))
6566

66-
(defn- current-version
67-
"Read the installed JAR's version from the running daemon, or nil."
67+
(defn- jar-version
68+
"Read version.edn from the installed JAR, or nil."
6869
[]
69-
(when-let [{:keys [port]} (daemon/connection)]
70+
(when (installed?)
7071
(try
71-
(let [resp (http/get (str "http://127.0.0.1:" port "/health")
72-
{:timeout 2000 :throw false})]
73-
(when (= 200 (:status resp))
74-
(-> (json/parse-string (:body resp) true) :data :version)))
72+
(let [jar-url (java.net.URL. (str "jar:file:" paths/jar-path "!/version.edn"))]
73+
(with-open [in (.openStream jar-url)]
74+
(:version (edn/read-string (slurp in)))))
7575
(catch Exception _ nil))))
7676

7777
(defn download!
@@ -84,7 +84,7 @@
8484
((:stop s) "No JAR found in release")
8585
(throw (ex-info (str "No JAR asset found in release " (:tag release)) {})))
8686
(let [remote-ver (:tag release)
87-
local-ver (current-version)]
87+
local-ver (jar-version)]
8888
(if (and local-ver (= (str "v" local-ver) remote-ver))
8989
(do ((:stop s) (str "Already at latest version (" remote-ver ").")) nil)
9090
(do ((:stop s) (str "Found " remote-ver (when local-ver (str " (current: v" local-ver ")"))))
@@ -98,10 +98,24 @@
9898
(verify-checksum! paths/jar-path (:assets release) (:name asset))
9999
paths/jar-path)))))
100100

101+
(defn- stale?
102+
"True when the installed JAR version doesn't match the launcher version."
103+
[launcher-version]
104+
(when launcher-version
105+
(let [jar-ver (jar-version)]
106+
(and jar-ver (not= jar-ver launcher-version)))))
107+
101108
(defn ensure!
102-
"Ensure noumenon.jar is installed. Download if not. Returns jar path."
103-
[]
104-
(if (installed?)
105-
paths/jar-path
106-
(do (tui/eprintln "First run: downloading noumenon.jar (~50MB) to ~/.noumenon/")
107-
(download!))))
109+
"Ensure noumenon.jar is installed and up to date. Returns jar path.
110+
When launcher-version is supplied, triggers download if the running
111+
JAR version differs."
112+
([] (ensure! nil))
113+
([launcher-version]
114+
(if (installed?)
115+
(if (stale? launcher-version)
116+
(do (daemon/stop!)
117+
(download!)
118+
paths/jar-path)
119+
paths/jar-path)
120+
(do (tui/eprintln "First run: downloading noumenon.jar (~50MB) to ~/.noumenon/")
121+
(download!)))))

launcher/src/noum/main.clj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[babashka.http-client :as http]
55
[babashka.process :as proc]
66
[cheshire.core :as json]
7-
[clojure.edn :as edn]
87
[clojure.java.io :as io]
98
[clojure.string :as str]
109
[noum.api :as api]
@@ -23,10 +22,7 @@
2322
[noum.tui.spinner :as spinner]
2423
[noum.tui.style :as style]))
2524

26-
(def ^:private version
27-
(or (try (:version (edn/read-string (slurp (io/resource "version.edn"))))
28-
(catch Exception _ nil))
29-
"dev"))
25+
(def ^:private version paths/version)
3026

3127
;; --- Output ---
3228

@@ -240,7 +236,8 @@
240236
(let [s (spinner/start "Downloading latest version...")]
241237
(try
242238
(if (jar/download!)
243-
(do ((:stop s) "Noumenon updated.")
239+
(do (when (daemon/running?) (daemon/stop!))
240+
((:stop s) "Noumenon updated.")
244241
(tui/eprintln "To update the noum launcher itself, re-run the installer.")
245242
0)
246243
(do ((:stop s) "Already at latest version.")
@@ -252,7 +249,7 @@
252249

253250
(defn- do-serve [{:keys [flags]}]
254251
(let [jre-path (jre/ensure!)
255-
jar-path (jar/ensure!)
252+
jar-path (jar/ensure! version)
256253
java-bin (str (fs/path jre-path "bin" "java"))
257254
args (cond-> [java-bin "-jar" jar-path "serve"]
258255
(:db-dir flags) (into ["--db-dir" (:db-dir flags)])

launcher/src/noum/paths.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(ns noum.paths
22
"Shared path constants for ~/.noumenon/."
33
(:require [babashka.fs :as fs]
4+
[clojure.edn :as edn]
5+
[clojure.java.io :as io]
46
[clojure.string :as str]))
57

68
(defn ensure-private!
@@ -12,6 +14,11 @@
1214
(fs/set-posix-file-permissions path "rw-------")
1315
(catch UnsupportedOperationException _))))
1416

17+
(def version
18+
(or (try (:version (edn/read-string (slurp (io/resource "version.edn"))))
19+
(catch Exception _ nil))
20+
"dev"))
21+
1522
(def noum-dir (str (fs/path (fs/home) ".noumenon")))
1623
(def jre-dir (str (fs/path noum-dir "jre")))
1724
(def lib-dir (str (fs/path noum-dir "lib")))

resources/version.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{:version "0.5.2"}
1+
{:version "0.5.3"}

0 commit comments

Comments
 (0)