From 5d3ad8b9305f669d95c22c796f105a634e95e957 Mon Sep 17 00:00:00 2001 From: tiye Date: Wed, 2 Dec 2026 03:14:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7=20Termina=20=E8=87=B3=20?= =?UTF-8?q?Calcit=200.53?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/upload.yaml | 2 +- README.md | 2 +- calcit.cirru | 123 ++++++++++++++++++++++------------ deps.cirru | 28 ++++---- package.json | 2 +- yarn.lock | 10 +-- 6 files changed, 102 insertions(+), 65 deletions(-) diff --git a/.github/workflows/upload.yaml b/.github/workflows/upload.yaml index 0df0211..43b73a3 100644 --- a/.github/workflows/upload.yaml +++ b/.github/workflows/upload.yaml @@ -32,7 +32,7 @@ jobs: with: tools: calcit,caps deps-file: deps.cirru - caps-version: "0.1.1" + caps-version: "0.1.2" - name: Install dependencies and verify toolchain run: | set -euo pipefail diff --git a/README.md b/README.md index 1590d2b..a7af545 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ TODO: new npm package. ### 迁移状态 -升级后请使用正式 Calcit / `@calcit/procs` 0.44.0 重新生成客户端与服务端 JS。依赖图配对 Respo 0.19.16、Alerts 0.14.11、Cumulo Reel 0.3.11、WS-EDN 0.2.11 和 Fuzzy Filter 0.0.23。命令的输入、执行协议和存档格式保持。 +升级后请使用正式 Calcit / `@calcit/procs` 0.53.0 重新生成客户端与服务端 JS。依赖图配对 Respo 0.20.5、Alerts 0.14.17、Cumulo Reel 0.3.17、WS-EDN 0.3.10 和 Fuzzy Filter 0.0.26。命令的输入、执行协议和存档格式保持。 命令解析使用具名的 `ParsedCommand`,命令编辑器和按钮回调传递应用的 `Op`。插件仍通过现有开放入口接收操作。 diff --git a/calcit.cirru b/calcit.cirru index 7a8b6f4..060d817 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -69,7 +69,10 @@ add-watch! *store :changes $ fn (s p) (render-app!) add-watch! *states :changes $ fn (s p) (render-app!) add-event-listener! |keydown $ fn (event) (on-window-keydown event) - on-page-touch $ fn () $ if (nil? @*store) (connect!) &unit + on-page-touch $ fn () $ if + .none? $ nil->option @*store + connect! + , &unit , &unit :examples $ [] :schema $ quote $ Fn (-> Unit) (:features :io :js-ffi :state) @@ -99,7 +102,7 @@ keyboard-event :meta-key? clear-current-route! decode-map-as - or @*store $ {} + app.schema/value-or @*store $ {} Map Tag Dynamic fn (op) ws-send! $ app.schema/op-to-wire op @@ -212,7 +215,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ decode-map-as - or (app.schema/field-or states :data nil) + app.schema/value-or (app.schema/field-or states :data nil) if (.some? base-command) select-keys (.unwrap base-command) ([] :code :path :title) {} (:title |) (:code |) (:path |./) @@ -283,8 +286,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ decode-map-as - either (app.schema/field-or states :data nil) - {} $ :pop? false + app.schema/field-or states :data $ {} $ :pop? false Map Tag Bool remove-plugin $ use-confirm (>> states :remove) ({}) div @@ -295,7 +297,7 @@ {} $ :style ui/row-middle <> decode-map-as - or (app.schema/field-or command :title nil) |Task + app.schema/value-or (app.schema/field-or command :title nil) |Task , 'String {} $ :font-size 20 space-x 8 @@ -433,7 +435,9 @@ :schema $ quote StructDef 'comp-container $ %{} 'CodeEntry (:doc |) :code $ quote $ defcomp comp-container (states store) - if (nil? store) (comp-offline) + if + .none? $ nil->option store + comp-offline let view $ decode-view store div @@ -564,7 +568,7 @@ .includes? (#{} :router :user :count :color) key , StoreView :examples $ [] - :schema $ quote $ Fn Input (-> StoreView) (:generics Input) + :schema $ quote $ Fn Input (-> StoreView) (:generics Input) (:open :decode) 'style-body $ %{} 'CodeEntry (:doc |) :code $ quote $ def style-body {} $ :padding "|8px 16px" @@ -624,7 +628,7 @@ decode-map-as css-date-text 'String <> decode-map-as - or (app.schema/field-or history :title nil) |Task + app.schema/value-or (app.schema/field-or history :title nil) |Task , 'String decode-map-as merge style/text $ {} $ :min-width 160 @@ -707,7 +711,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ let - raw-state $ or (app.schema/field-or states :data nil) + raw-state $ app.schema/value-or (app.schema/field-or states :data nil) {} (:query |) (:pop? false) decode-map-as if (struct? raw-state) (&struct:to-map raw-state) raw-state @@ -719,9 +723,7 @@ .unwrap-or (get router-data :processes) ({}) Map Number $ Map Tag Dynamic raw-enlarge-view $ app.schema/field-or router-data :enlarge-view nil - enlarge-view $ if - or (nil? raw-enlarge-view) (= raw-enlarge-view false) - , None $ Some (decode-map-as raw-enlarge-view 'Number) + enlarge-view $ app.schema/optional-process-id raw-enlarge-view div {} $ :class-name $ str-spaced css/expand css/column css-home space-y 8 @@ -888,7 +890,7 @@ fn (pid) [] pid $ comp-process $ .unwrap (get processes pid) :examples $ [] - :schema $ quote $ Fn (Map Tag Dynamic) (Map Tag Dynamic) (-> respo.schema/Component) (:features :io :state) + :schema $ quote $ Fn (Map Tag Dynamic) (Map Tag Dynamic) (-> respo.schema/Component) (:features :io :state) (:open :decode) 'css-filter $ %{} 'CodeEntry (:doc |) :code $ quote $ defstyle css-filter {} $ |& $ {} (:min-width 60) (:width 60) (:background-color :transparent) @@ -949,7 +951,7 @@ List app.schema/StateKey state $ decode-map-as match (get states :data) - (:some value) (if value value initial-state) + (:some value) (app.schema/value-or value initial-state) (:none) initial-state Map Tag String div @@ -1005,7 +1007,7 @@ :code $ quote $ defn on-submit (username password signup?) fn (e dispatch!) hint-fn $ Fn respo.schema/RespoEvent - Fn *dispatch-op $ -> Unit + Fn schema/Op $ -> Unit -> Unit dispatch! $ if signup? app.schema/Op :user/sign-up $ [] username password @@ -1016,7 +1018,7 @@ :examples $ [] :schema $ quote $ Fn String String Bool -> $ Fn respo.schema/RespoEvent - Fn *dispatch-op $ -> Unit + Fn schema/Op $ -> Unit -> Unit :ns $ %{} 'NsEntry (:doc |) :code $ quote $ ns app.comp.login @@ -1141,7 +1143,7 @@ {} $ :class-name css/row-middle <> decode-map-as - or (app.schema/field-or process :title nil) |Task + app.schema/value-or (app.schema/field-or process :title nil) |Task , 'String decode-map-as merge style/text $ {} $ :color :black @@ -1318,8 +1320,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ let - raw-state $ either (app.schema/field-or states :data nil) - {} (:filter |) (:filter? true) (:wrap? true) (:all-log? false) (:hide-thread-info? false) + raw-state $ app.schema/field-or states :data $ {} (:filter |) (:filter? true) (:wrap? true) (:all-log? false) (:hide-thread-info? false) decode-map-as if (struct? raw-state) (&struct:to-map raw-state) raw-state , DetailState @@ -1414,7 +1415,7 @@ {} $ :class-name css-toolbar span $ {} :inner-text $ decode-map-as - or (app.schema/field-or process :title nil) |Task + app.schema/value-or (app.schema/field-or process :title nil) |Task , 'String :class-name css/font-fancy :style $ merge style/text @@ -1549,7 +1550,7 @@ space-y 200 .render command-plugin :examples $ [] - :schema $ quote $ Fn (Map Tag Dynamic) (Map Tag Dynamic) (-> respo.schema/Component) (:features :io :state) + :schema $ quote $ Fn (Map Tag Dynamic) (Map Tag Dynamic) (-> respo.schema/Component) (:features :io :state) (:open :decode) 'css-down-icon $ %{} 'CodeEntry (:doc |) :code $ quote $ defstyle css-down-icon {} @@ -1613,7 +1614,7 @@ :examples $ [] :ffi $ {} (:backend :js) (:target :browser) :schema $ quote $ Fn respo.schema/RespoEvent - Fn *dispatch-op $ -> Unit + Fn app.schema/Op $ -> Unit -> Unit :features :js-ffi :ns $ %{} 'NsEntry (:doc |) @@ -1722,7 +1723,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ let - original-state $ or (app.schema/field-or states :data nil) + original-state $ app.schema/value-or (app.schema/field-or states :data nil) {} (:focused-id nil) (:base-workflow nil) (:pop? false) state-map $ dissoc decode-map-as @@ -1850,6 +1851,7 @@ Map String $ Map Tag Dynamic -> respo.schema/Component :features :io :state + :open :decode 'comp-workflow-detail $ %{} 'CodeEntry (:doc |) :code $ quote $ defcomp comp-workflow-detail (states workflow) let @@ -1857,8 +1859,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ decode-map-as - either (app.schema/field-or states :data nil) - {} (:pop? false) (:edit? false) + app.schema/field-or states :data $ {} (:pop? false) (:edit? false) Map Tag Bool remove-plugin $ use-confirm (>> states :remove) ({}) commands $ decode-map-as @@ -1985,7 +1986,7 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ decode-map-as - or (app.schema/field-or states :data nil) + app.schema/value-or (app.schema/field-or states :data nil) if (.some? base-workflow) select-keys (.unwrap base-workflow) ([] :name :base-dir) {} (:name |) (:base-dir |./) @@ -2477,7 +2478,7 @@ if (nil? value) fallback value (:none) fallback :examples $ [] - :schema $ quote $ Fn (Map K V) K V (-> V) (:generics K V) + :schema $ quote $ Fn (Map K V) K V (-> V) (:generics K V) (:open :decode) 'history $ %{} 'CodeEntry (:doc |) :code $ quote $ def history {} (:id nil) (:pid 0) (:started-at 0) (:cwd |) (:command |) @@ -2511,6 +2512,24 @@ assert= :: :process/error $ [] 42 "|日志🐈" op-to-wire $ Op :process/error event + 'optional-process-id $ %{} 'CodeEntry (:doc |) + :code $ quote $ defn optional-process-id (value) + if (nil? value) None $ if (bool? value) + if value + Some $ decode-map-as value 'Number + , None + Some $ decode-map-as value 'Number + :examples $ [] + :schema $ quote $ Fn T + -> $ Option Number + :generics T + :open :decode + :tests $ [] $ %{} 'TestEntry (:name |legacy-empty-and-zero) + :code $ quote $ do + assert= None $ optional-process-id nil + assert= None $ optional-process-id false + assert= (Some 0) (optional-process-id 0) + assert= (Some 12) (optional-process-id 12) 'page $ %{} 'CodeEntry (:doc |) :code $ quote $ def page {} (:id nil) (:title |) (:time nil) @@ -2537,6 +2556,7 @@ :schema $ quote $ Fn Input (List StateKey) -> $ Option Dynamic :generics Input + :open :decode 'router $ %{} 'CodeEntry (:doc |) :code $ quote $ def router {} (:name nil) (:title nil) @@ -2565,6 +2585,7 @@ :examples $ [] :schema $ quote $ Fn Dynamic -> $ Map Tag Dynamic + :open :decode :tests $ [] $ %{} 'TestEntry (:name |drops-stray-string-keys) :code $ quote $ assert= {} $ :pid 1 @@ -2575,6 +2596,21 @@ {} (:name nil) (:id nil) (:nickname nil) (:avatar nil) (:password nil) :examples $ [] :schema $ quote $ Map Tag Nil + 'value-or $ %{} 'CodeEntry (:doc |) + :code $ quote $ defn value-or (value fallback) + if (nil? value) fallback $ if (bool? value) (if value value fallback) value + :examples $ [] + :schema $ quote $ Fn A B (-> Dynamic) (:generics A B) (:open :decode) + :tests $ [] $ %{} 'TestEntry (:name |legacy-fallback) + :code $ quote $ do + assert= |fallback $ decode-map-as (value-or nil |fallback) 'String + assert= |fallback $ decode-map-as (value-or false |fallback) 'String + assert= | $ decode-map-as (value-or | |fallback) 'String + assert= ({}) + decode-map-as + value-or ({}) + {} $ :x 1 + Map Tag Number 'workflow $ %{} 'CodeEntry (:doc |) :code $ quote $ def workflow {} (:id nil) (:name nil) (:base-dir |~/) @@ -2898,6 +2934,7 @@ :schema $ quote $ Fn app.schema/Database (Map Tag Dynamic) Number -> $ Map Tag Dynamic :features :js-ffi + :open :decode 'twig-members $ %{} 'CodeEntry (:doc |) :code $ quote $ defn twig-members (sessions users) filter-map-kv sessions $ fn (sid session) @@ -2919,6 +2956,7 @@ Map String $ Map Tag Dynamic Map String $ Map Tag Dynamic -> $ Map String String + :open :decode :ns $ %{} 'NsEntry (:doc |) :code $ quote $ ns app.twig.container :require @@ -3035,7 +3073,7 @@ (:process/clear-history _) (process/clear-history db) _ $ do (println "|Unknown op:" op) db :examples $ [] - :schema $ quote $ Fn schema/Database Dynamic String String Number (-> schema/Database) (:features :io) + :schema $ quote $ Fn schema/Database Dynamic String String Number (-> schema/Database) (:features :io) (:open :decode) :ns $ %{} 'NsEntry (:doc |) :code $ quote $ ns app.updater :require (app.updater.session :as session) (app.updater.user :as user) (app.updater.router :as router) (app.schema :as schema) (app.updater.process :as process) (app.updater.workflow :as workflow) @@ -3105,9 +3143,11 @@ 'remove-dead $ %{} 'CodeEntry (:doc |) :code $ quote $ defn remove-dead (db op-data sid op-id op-time) if - not $ .unwrap-or - app.schema/read-path (:processes db) ([] op-data :alive?) - , false + not $ decode-map-as + .unwrap-or + app.schema/read-path (:processes db) ([] op-data :alive?) + , false + , 'Bool assoc db :processes $ dissoc (:processes db) op-data , db :examples $ [] @@ -3402,20 +3442,17 @@ .unwrap-or (get store :session) ({}) Map Tag Dynamic dispatch! $ app.schema/Op :process/clear - match (get session :enlarge-view) + match + app.schema/optional-process-id $ app.schema/field-or session :enlarge-view nil (:none) &unit (:some pid) - when - not $ or (nil? pid) (= pid false) - dispatch! $ app.schema/Op :process/shorten-content $ decode-map-as pid 'Number + dispatch! $ app.schema/Op :process/shorten-content pid :history $ dispatch! $ app.schema/Op :process/clear-history :process $ match - get-in router $ [] :params :id - (:err _error) &unit - (:ok pid) - when - not $ nil? pid - dispatch! $ app.schema/Op :process/shorten-content $ decode-map-as pid 'Number + app.schema/read-path router $ [] :params :id + (:none) &unit + (:some pid) + dispatch! $ app.schema/Op :process/shorten-content $ decode-map-as pid 'Number _ $ println "|no thing to clear in" router-name , &unit :examples $ [] @@ -3437,7 +3474,7 @@ if (js-nullish? value) | $ decode-map-as value 'String (:none) | :examples $ [] - :schema $ quote $ Fn TextInputEvent (-> String) (:features :js-ffi) + :schema $ quote $ Fn TextInputEvent (-> String) (:features :js-ffi) (:open :decode) 'join-path $ %{} 'CodeEntry (:doc |) :code $ quote $ defn join-path (xs ys) if diff --git a/deps.cirru b/deps.cirru index bd91ec7..f98bab1 100644 --- a/deps.cirru +++ b/deps.cirru @@ -1,16 +1,16 @@ -{} (:calcit-version |0.44.0) +{} (:calcit-version |0.53.0) :version |0.1.22 - :dependencies $ {} (|Cumulo/cumulo-reel.calcit |0.3.11) - |Cumulo/cumulo-util.calcit |0.0.50 - |Respo/alerts.calcit |0.14.11 - |Respo/reel.calcit |0.11.7 - |Respo/respo-feather.calcit |0.6.11 - |Respo/respo-message.calcit |0.4.7 - |Respo/respo-ui.calcit |0.16.3 - |Respo/respo-value.calcit |0.7.11 - |Respo/respo.calcit |0.19.16 - |calcit-lang/js-ffi |0.2.23 - |calcit-lang/recollect |0.3.12 - |mvc-works/fuzzy-filter |0.0.23 - |mvc-works/ws-edn.calcit |0.2.11 + :dependencies $ {} (|Cumulo/cumulo-reel.calcit |0.3.17) + |Cumulo/cumulo-util.calcit |0.0.58 + |Respo/alerts.calcit |0.14.17 + |Respo/reel.calcit |0.11.16 + |Respo/respo-feather.calcit |0.6.18 + |Respo/respo-message.calcit |0.4.15 + |Respo/respo-ui.calcit |0.16.11 + |Respo/respo-value.calcit |0.7.18 + |Respo/respo.calcit |0.20.5 + |calcit-lang/js-ffi |0.2.31 + |calcit-lang/recollect |0.3.18 + |mvc-works/fuzzy-filter |0.0.26 + |mvc-works/ws-edn.calcit |0.3.10 diff --git a/package.json b/package.json index 9a118ef..95201a2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "author": "jiyinyiyong", "license": "MIT", "dependencies": { - "@calcit/procs": "0.44.0", + "@calcit/procs": "0.53.0", "chalk": "^5.3.0", "dayjs": "^1.11.11", "latest-version": "^9.0.0", diff --git a/yarn.lock b/yarn.lock index 60a238b..9763afc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,15 +12,15 @@ __metadata: languageName: node linkType: hard -"@calcit/procs@npm:0.44.0": - version: 0.44.0 - resolution: "@calcit/procs@npm:0.44.0" +"@calcit/procs@npm:0.53.0": + version: 0.53.0 + resolution: "@calcit/procs@npm:0.53.0" dependencies: "@calcit/finger-vec": "npm:0.1.1" "@calcit/ternary-tree": "npm:0.0.26" "@cirru/parser.ts": "npm:0.0.10" "@cirru/writer.ts": "npm:^0.1.9" - checksum: 10c0/28f2dc888de84f14974a1499973503d5f98144502f99e4ec0cf53f4e0e6c4426d7d9a9a0013fd7fd4b5b0ab0b29af4e218377a388e5949520ab3ae4823b0c885 + checksum: 10c0/c4019ecb1e4bd5768404d70310d538d1c835df62641379ec3cdd1266b1cb37f0dea9558850bd5ce67b5109501467f36c04a4f0394d6c1a767374ec1453fbcdc5 languageName: node linkType: hard @@ -928,7 +928,7 @@ __metadata: version: 0.0.0-use.local resolution: "termina@workspace:." dependencies: - "@calcit/procs": "npm:0.44.0" + "@calcit/procs": "npm:0.53.0" bottom-tip: "npm:^0.1.5" chalk: "npm:^5.3.0" dayjs: "npm:^1.11.11" From 06266a1f4b68119f525736dc565c5c36ac6bb684 Mon Sep 17 00:00:00 2001 From: tiye Date: Wed, 2 Dec 2026 11:28:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=80=E5=87=BA?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calcit.cirru | 2 +- tests/state.test.mjs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/calcit.cirru b/calcit.cirru index 060d817..367ba25 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -2713,7 +2713,7 @@ run-server! port println |Server-started.-Open-UI-on- ui-url render-loop! *loop-trigger - js/process.on |SIGINT on-exit! + js/process.on |SIGINT $ fn (& _args) (on-exit!) set-interval! fn () $ persist-db! , 60000 diff --git a/tests/state.test.mjs b/tests/state.test.mjs index 9995c06..a98f73a 100644 --- a/tests/state.test.mjs +++ b/tests/state.test.mjs @@ -1,6 +1,10 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { spawnSync } from "node:child_process"; +import { spawn, spawnSync } from "node:child_process"; +import { once } from "node:events"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; import * as c from "../js-out/calcit.core.mjs"; import { database, decode_database, encode_database } from "../js-out/app.schema.mjs"; import { updater } from "../js-out/app.updater.mjs"; @@ -29,6 +33,40 @@ test("version reporting checks fulfilled text and preserves Promise rejection", } }); +test("SIGINT persists the database and exits cleanly", { timeout: 10000 }, async t => { + const dir = mkdtempSync(join(tmpdir(), "termina-signal-")); + const storage = join(dir, "database.cirru"); + const server = new URL("../js-out/app.server.mjs", import.meta.url).href; + const entry = `import { main_$x_ } from ${JSON.stringify(server)}; main_$x_(); console.log("SIGNAL-READY");`; + const child = spawn(process.execPath, ["--input-type=module", "-e", entry], { + cwd: dir, + env: { ...process.env, HOST: "127.0.0.1", port: "0", TERMINA_STORAGE_FILE: storage, NO_VERSION_CHECK: "1" }, + stdio: ["ignore", "pipe", "pipe"], + }); + t.after(() => { + if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL"); + rmSync(dir, { recursive: true, force: true }); + }); + let stderr = ""; + child.stderr.on("data", chunk => { stderr += chunk; }); + const exited = once(child, "exit"); + await new Promise((resolve, reject) => { + let stdout = ""; + child.stdout.on("data", chunk => { + stdout += chunk; + if (stdout.includes("SIGNAL-READY")) resolve(); + }); + child.once("error", reject); + child.once("exit", code => reject(new Error(`server exited before startup: ${code}: ${stderr}`))); + }); + child.kill("SIGINT"); + const [code, signal] = await exited; + assert.equal(code, 0, stderr); + assert.equal(signal, null); + const saved = c.parse_cirru_edn(readFileSync(storage, "utf8")); + assert.equal(c.option_$o_some_$q_(c.get(saved, c.init_tags(["users"]).users)), true); +}); + const tags = c.init_tags(["sessions", "users", "processes", "histories", "workflows", "user-id", "enlarge-view", "messages", "password", "commands", "code", "name", "content", "alive?", "command"]); const read = (value, key) => c.option_$o_unwrap(c.get(value, tags[key] ?? key)); const wire = encode_database;