@heretek-ai/openclaw 2026.3.31 → 2026.3.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/.buildstamp +1 -1
  2. package/dist/build-info.json +3 -3
  3. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  4. package/dist/chunks/command-registry-BnmWhMEa.mjs +214 -0
  5. package/dist/chunks/command-registry-CLOY087q.mjs +14 -0
  6. package/dist/chunks/command-registry-CjAG33h3.mjs +14 -0
  7. package/dist/chunks/command-registry-DPx6M6gw.mjs +214 -0
  8. package/dist/chunks/completion-cli-BDWbmV-o.mjs +448 -0
  9. package/dist/chunks/completion-cli-CBrKGQfJ.mjs +17 -0
  10. package/dist/chunks/completion-cli-CwouPhbG.mjs +17 -0
  11. package/dist/chunks/completion-cli-DuMZk0lN.mjs +448 -0
  12. package/dist/chunks/doctor-completion-1UqU9aiy.mjs +92 -0
  13. package/dist/chunks/doctor-completion-B_LLsQm-.mjs +92 -0
  14. package/dist/chunks/gateway-cli-CqAlS2xh.mjs +43508 -0
  15. package/dist/chunks/gateway-cli-CxfnMGx8.mjs +43508 -0
  16. package/dist/chunks/onboard-CRZ2jxOE.mjs +601 -0
  17. package/dist/chunks/onboard-CyzbNCBF.mjs +601 -0
  18. package/dist/chunks/program-B3JSAo3Q.mjs +163 -0
  19. package/dist/chunks/program-DVTI5ouc.mjs +163 -0
  20. package/dist/chunks/prompt-select-styled-AhC9B2Sr.mjs +5035 -0
  21. package/dist/chunks/prompt-select-styled-DWTJpQCH.mjs +5035 -0
  22. package/dist/chunks/register.maintenance-DkQKQI29.mjs +685 -0
  23. package/dist/chunks/register.maintenance-ofEvddjM.mjs +685 -0
  24. package/dist/chunks/register.onboard-3m3OGP7x.mjs +168 -0
  25. package/dist/chunks/register.onboard-BpL-OvP9.mjs +168 -0
  26. package/dist/chunks/register.setup-NRV53Eo_.mjs +188 -0
  27. package/dist/chunks/register.setup-xf9cH3sc.mjs +188 -0
  28. package/dist/chunks/register.subclis-B6xOze_R.mjs +319 -0
  29. package/dist/chunks/register.subclis-CXtcQnsP.mjs +13 -0
  30. package/dist/chunks/register.subclis-Dd7Q2x2W.mjs +13 -0
  31. package/dist/chunks/register.subclis-Dj9qGYdr.mjs +319 -0
  32. package/dist/chunks/run-main-BYaCWOd9.mjs +437 -0
  33. package/dist/chunks/run-main-nT8E6iSo.mjs +437 -0
  34. package/dist/chunks/setup-BufxzaUK.mjs +399 -0
  35. package/dist/chunks/setup-DHU6h2yc.mjs +399 -0
  36. package/dist/chunks/setup.finalize-Cc2mg8-p.mjs +544 -0
  37. package/dist/chunks/setup.finalize-DVacBRaT.mjs +544 -0
  38. package/dist/chunks/update-cli-DK2TX2U4.mjs +1632 -0
  39. package/dist/chunks/update-cli-JcUKNsam.mjs +1632 -0
  40. package/dist/entry.mjs +1 -1
  41. package/dist/index.mjs +1 -1
  42. package/package.json +134 -134
@@ -0,0 +1,1632 @@
1
+ import "./chunk-CQFkT1cY.mjs";
2
+ import "./redact-CtGOTRBK.mjs";
3
+ import "./errors-CbvpN2RP.mjs";
4
+ import "./logger-vRSRu9wD.mjs";
5
+ import { n as DEFAULT_GATEWAY_PORT, u as resolveGatewayPort } from "./paths-CNST7z3O.mjs";
6
+ import "./node-startup-env-Vn3Qa5f_.mjs";
7
+ import "./tmp-openclaw-dir-BeWwpCKM.mjs";
8
+ import { r as theme } from "./theme-w86ra_7m.mjs";
9
+ import "./globals-DZFR3wyP.mjs";
10
+ import { m as defaultRuntime } from "./subsystem-yLe4Gjha.mjs";
11
+ import "./ansi-BJ9IOlIp.mjs";
12
+ import "./boolean-Bwxxidw8.mjs";
13
+ import "./env-9fhyzTaG.mjs";
14
+ import { h as pathExists } from "./utils-Dc9DiBqf.mjs";
15
+ import { t as formatDocsLink } from "./links-BNNF54ea.mjs";
16
+ import { n as inheritOptionFromParent } from "./command-options-CMEANk0N.mjs";
17
+ import "./paths-B5L5nZjW.mjs";
18
+ import "./auth-profiles-ByaVWjmJ.mjs";
19
+ import "./agent-scope-CnAwGoC2.mjs";
20
+ import "./boundary-path-DnlNnNbU.mjs";
21
+ import "./boundary-file-read-BB4JbZzx.mjs";
22
+ import "./logger-DWOgrQoS.mjs";
23
+ import { n as runCommandWithTimeout } from "./exec-DX0zVVG7.mjs";
24
+ import { t as resolveOpenClawPackageRoot } from "./openclaw-root-CSfnLaqO.mjs";
25
+ import "./workspace-CoFl73GV.mjs";
26
+ import "./model-selection-BJk_hQeE.mjs";
27
+ import { d as readConfigFileSnapshot, g as writeConfigFile } from "./io-CDQGJKjg.mjs";
28
+ import "./shell-env-CP5vTYhw.mjs";
29
+ import "./safe-text-Bsdm3bQS.mjs";
30
+ import "./version-Ckv-IbvB.mjs";
31
+ import "./env-substitution-DGlYO8jV.mjs";
32
+ import "./scan-paths-ahOy4FCQ.mjs";
33
+ import "./includes-DcO1JxKG.mjs";
34
+ import "./zod-schema.providers-core-CjdAU1TY.mjs";
35
+ import "./legacy-web-search-B1O8hiGy.mjs";
36
+ import "./schema-validator-BOH34EXk.mjs";
37
+ import "./registry-DBJv0dvl.mjs";
38
+ import "./config-state-kmbzTT63.mjs";
39
+ import "./min-host-version-EA11e8I5.mjs";
40
+ import "./manifest-registry-dO1qi1iI.mjs";
41
+ import { i as parseSemver } from "./runtime-guard-CWHkkioa.mjs";
42
+ import "./avatar-policy-uRVtZ7lJ.mjs";
43
+ import "./ip-BtMd9ssR.mjs";
44
+ import "./zod-schema.agent-runtime-BtGT59eP.mjs";
45
+ import "./zod-schema.core-CMT7g7UX.mjs";
46
+ import "./zod-schema.channels-BAG3dUtC.mjs";
47
+ import "./zod-schema.providers-whatsapp-qnpQepaf.mjs";
48
+ import "./config-Bhjk4Vel.mjs";
49
+ import "./process-scoped-map-BmLEe6nP.mjs";
50
+ import "./file-lock-hqfE8fCo.mjs";
51
+ import "./file-lock-CjVc7LJY.mjs";
52
+ import "./audit-fs-kb-rv_ZT.mjs";
53
+ import "./shared-VxKfp8Uy.mjs";
54
+ import "./resolve-DI6cKS4v.mjs";
55
+ import "./chutes-oauth-BLrDl-qw.mjs";
56
+ import "./json-file-ZNWqd95a.mjs";
57
+ import "./profiles-CqdEUxnl.mjs";
58
+ import "./redact-identifier-DTBisVz0.mjs";
59
+ import { n as resolveCliName, t as replaceCliName } from "./cli-name-lEyorNIN.mjs";
60
+ import { t as formatCliCommand } from "./command-format-D1DrcTDP.mjs";
61
+ import { f as resolveGatewaySystemdServiceName, l as resolveGatewayLaunchAgentLabel, p as resolveGatewayWindowsTaskName } from "./constants-Bu6_2DSg.mjs";
62
+ import "./daemon-install-plan.shared-MtLyPLVq.mjs";
63
+ import "./runtime-paths-qezFSLu3.mjs";
64
+ import "./gateway-install-token-3hijf3Zd.mjs";
65
+ import "./prompt-hGCcgj-D.mjs";
66
+ import "./tailscale-DZJRdd6v.mjs";
67
+ import "./secret-equal-DcNDdUBf.mjs";
68
+ import "./tailnet-Bc7IPWjH.mjs";
69
+ import "./net-OJiOmwY1.mjs";
70
+ import "./auth-C5eSR-m1.mjs";
71
+ import "./credentials-DTsHVnAc.mjs";
72
+ import "./message-channel-DCt8BIP7.mjs";
73
+ import "./store-B0V1qm_-.mjs";
74
+ import "./runtime-a4e8n7tq.mjs";
75
+ import "./registry-9YpVWxKb.mjs";
76
+ import "./plugins-D8oapapr.mjs";
77
+ import "./sessions-CYgBPqrc.mjs";
78
+ import "./paths-CGxgQvpf.mjs";
79
+ import "./types-DoAKcnWC.mjs";
80
+ import "./session-write-lock-DE8KASyZ.mjs";
81
+ import "./json-files-BcpXnc9i.mjs";
82
+ import "./delivery-info-CGNfeMd6.mjs";
83
+ import "./method-scopes-hu-4urbi.mjs";
84
+ import "./call-CcXWxOVG.mjs";
85
+ import "./ws-Dv5Afaxu.mjs";
86
+ import "./control-ui-shared-Dhzx9It_.mjs";
87
+ import "./onboard-helpers-C5GCWoDO.mjs";
88
+ import "./wsl-BW8_A9_i.mjs";
89
+ import { n as stylePromptMessage } from "./prompt-style-Dua6SIJh.mjs";
90
+ import "./ports-lsof-D1pMGdtZ.mjs";
91
+ import "./restart-stale-pids-DpJ5KhNO.mjs";
92
+ import "./runtime-parse-Dv1L_ID-.mjs";
93
+ import "./launchd-CFtZl6rs.mjs";
94
+ import { n as resolveGatewayService } from "./service-eLNsotU2.mjs";
95
+ import { r as quoteCmdScriptArg } from "./kill-tree-C7sbsfc4.mjs";
96
+ import "./ports-0KspCIU9.mjs";
97
+ import "./ports-probe-CW8QePv6.mjs";
98
+ import "./systemd-B1Tl3zeB.mjs";
99
+ import "./shared-CKm0v_dB.mjs";
100
+ import "./systemd-hints-CLxWQM3C.mjs";
101
+ import "./logging-CO6W9Zis.mjs";
102
+ import { r as runDaemonRestart, s as runDaemonInstall } from "./daemon-cli-BKniTIR4.mjs";
103
+ import "./commands-CibL1v-k.mjs";
104
+ import "./probe-4uB3UbEE.mjs";
105
+ import { n as formatConfigIssueLines } from "./issue-format-C5C4zFWv.mjs";
106
+ import "./lifecycle-core-CYrnYd8J.mjs";
107
+ import { a as renderRestartDiagnostics, c as waitForGatewayHealthyRestart, o as terminateStaleGatewayPids } from "./status-B6GRulE7.mjs";
108
+ import "./diagnostics-CXwZ82ru.mjs";
109
+ import "./inspect-CBu749pN.mjs";
110
+ import "./probe-auth-kG5V7ULz.mjs";
111
+ import "./progress-BxDdsPK3.mjs";
112
+ import { t as formatHelpExamples } from "./help-format-VI-o9lzW.mjs";
113
+ import "./tokens-CIQuw4-h.mjs";
114
+ import "./heartbeat-B3sryw3e.mjs";
115
+ import "./registry-CFSnIRx_.mjs";
116
+ import "./internal-hooks-VOrTrqjW.mjs";
117
+ import "./secure-random-Cta_A2w5.mjs";
118
+ import "./multimodal-B5--YVtx.mjs";
119
+ import "./memory-search-CI34ggcG.mjs";
120
+ import "./embeddings-BgbopHnm.mjs";
121
+ import "./api-key-rotation-CuLnDVwp.mjs";
122
+ import "./provider-runtime-CRmI76OF.mjs";
123
+ import "./providers.runtime-CtdkYDy2.mjs";
124
+ import "./accounts-DCMTPA3m.mjs";
125
+ import "./loader-CYgWRKc6.mjs";
126
+ import "./config-presence-DzY-U322.mjs";
127
+ import "./types-BaXbwBIP.mjs";
128
+ import "./hook-runner-global-z_Icpwvo.mjs";
129
+ import "./session-binding-service-Bmkk4TGJ.mjs";
130
+ import "./conversation-binding-elBCYjlA.mjs";
131
+ import "./sdk-alias-C5qDxQv2.mjs";
132
+ import "./anthropic-vertex-provider-Davkw2Ua.mjs";
133
+ import "./provider-env-vars-BvHq384O.mjs";
134
+ import "./model-auth-markers-D9P0hXHx.mjs";
135
+ import "./model-auth-env-D5wfS1i-.mjs";
136
+ import "./model-auth-DtPujlPX.mjs";
137
+ import "./ssrf-DfOlyZAO.mjs";
138
+ import "./fetch-guard-BNr7RxWd.mjs";
139
+ import "./provider-model-allowlist-Bz7SYU4G.mjs";
140
+ import "./provider-model-defaults-CPQyoqIg.mjs";
141
+ import "./mime-CbiZRMeN.mjs";
142
+ import "./backend-config-DaJEmaVa.mjs";
143
+ import "./config-schema-BBMwxQY-.mjs";
144
+ import "./helpers-DxddeIS7.mjs";
145
+ import "./channel-plugin-common-DFFE5uzd.mjs";
146
+ import "./path-safety-CTs-ZpWF.mjs";
147
+ import "./archive-CwsJ_E7G.mjs";
148
+ import "./fs-safe-DvWloqcG.mjs";
149
+ import "./path-alias-guards-Dq2I3ITG.mjs";
150
+ import "./status-helpers-BmYd-e9Q.mjs";
151
+ import "./accounts-Bxxxwdxj.mjs";
152
+ import "./format-DIM1-tQX.mjs";
153
+ import "./api-C4xoLY_P.mjs";
154
+ import "./telegram-DZaimX0b.mjs";
155
+ import "./poll-params-DWHBuRx9.mjs";
156
+ import "./token-BNIxZjju.mjs";
157
+ import "./sticker-cache-CFR6cQio.mjs";
158
+ import "./status-issues-Bu3cVorN.mjs";
159
+ import "./fetch-BI0FMqrI.mjs";
160
+ import "./update-offset-store-3hPuz7sI.mjs";
161
+ import "./api-CE6hZv7r.mjs";
162
+ import "./audit-BkbWkLoN.mjs";
163
+ import "./runtime-api-BR_m5NcJ.mjs";
164
+ import "./bootstrap-budget-B-IQwkE2.mjs";
165
+ import "./pi-embedded-helpers-DTWSmIk7.mjs";
166
+ import "./tool-catalog-DblrqUGw.mjs";
167
+ import "./config-BT5BZCwj.mjs";
168
+ import "./runtime-status-BCn1Ito_.mjs";
169
+ import "./tool-images-DMUfrdai.mjs";
170
+ import "./image-ops-CabelrfU.mjs";
171
+ import "./thinking-DvqE1iCX.mjs";
172
+ import "./models-config-CXzGvNtq.mjs";
173
+ import "./provider-catalog-BDbid2d6.mjs";
174
+ import "./models-config.providers-4zEBpqdF.mjs";
175
+ import "./models-config.providers.discovery-BjIw3Rrd.mjs";
176
+ import "./bundle-lsp-DyU7-zol.mjs";
177
+ import "./exec-approvals-allowlist-DinDB1Z8.mjs";
178
+ import "./exec-safe-bin-runtime-policy-CyPJcb_7.mjs";
179
+ import "./local-file-access-Cloywpfb.mjs";
180
+ import "./sandbox-paths-BltFttSo.mjs";
181
+ import "./path-prepend-B3TwK2p2.mjs";
182
+ import "./sandbox-B1Fh0xU6.mjs";
183
+ import { r as formatDurationPrecise } from "./format-duration-DXuRoMzK.mjs";
184
+ import "./target-registry-B8jHfrX7.mjs";
185
+ import "./runtime-web-tools-SZ1bF8Ui.mjs";
186
+ import "./web-search-providers.runtime-C9cFlSM-.mjs";
187
+ import "./image-generation-provider-6Bn9TpiN.mjs";
188
+ import "./web-search-providers-D1Ywb8m5.mjs";
189
+ import "./client-fetch-BLpjnLN8.mjs";
190
+ import "./resolve-configured-secret-input-string-BG1RVESA.mjs";
191
+ import "./config-BBc-AI9Q.mjs";
192
+ import "./store-CgM2S6uo.mjs";
193
+ import "./stagger-DL_NciFx.mjs";
194
+ import { o as trimLogTail } from "./restart-sentinel-BkRzS474.mjs";
195
+ import "./model-catalog-CWUezRcI.mjs";
196
+ import "./command-secret-gateway-CG3hVPib.mjs";
197
+ import "./command-secret-targets-DskfH4zj.mjs";
198
+ import "./bindings-B0u6nL3P.mjs";
199
+ import "./plugin-auto-enable-C2JsxNX4.mjs";
200
+ import "./accounts-C8JW5aRU.mjs";
201
+ import "./account-inspect-D6JVmmbI.mjs";
202
+ import "./runtime-api-BtH8ogGO.mjs";
203
+ import "./send-MNad2Oi4.mjs";
204
+ import "./mentions-zhy7pfW_.mjs";
205
+ import "./api-DXEplirz.mjs";
206
+ import "./allow-list-BmsN9jdO.mjs";
207
+ import "./handle-action-Liqu1FVR.mjs";
208
+ import "./status-issues-DEI316v-.mjs";
209
+ import "./normalize-P7c7I_FZ.mjs";
210
+ import "./pluralkit-BrMYZvsn.mjs";
211
+ import "./api-BcbhfW_y.mjs";
212
+ import "./send-DnRAtQfI.mjs";
213
+ import "./threading-tool-context-CHndxZE0.mjs";
214
+ import "./sent-thread-cache-HjNNrYhB.mjs";
215
+ import "./targets-XG-6x8Dr.mjs";
216
+ import "./api-s9vnTb6r.mjs";
217
+ import "./pairing-store-CZ8m5dqj.mjs";
218
+ import "./json-store-79zyIPBO.mjs";
219
+ import "./config-eval-BRFipjhU.mjs";
220
+ import "./frontmatter-DtyHHNb1.mjs";
221
+ import "./env-overrides-CiAKRDlo.mjs";
222
+ import "./skills-B94iGCMk.mjs";
223
+ import "./windows-spawn-BIgkarI-.mjs";
224
+ import "./docker-RHNUruWe.mjs";
225
+ import "./ssh-tunnel-rTW1iTuR.mjs";
226
+ import "./server-middleware-CgGy22IV.mjs";
227
+ import "./parse-json-compat-C8iu7A7C.mjs";
228
+ import "./logging-CcQ-gmqC.mjs";
229
+ import "./store-BoqljpMQ.mjs";
230
+ import "./read-only-account-inspect-CoN81Eok.mjs";
231
+ import "./dm-policy-shared-CnmKIKQO.mjs";
232
+ import "./backup-create-CRi_Wc9K.mjs";
233
+ import "./thread-bindings-runtime-DZHuPlAx.mjs";
234
+ import "./matrix-migration-snapshot-ChWL_Ldz.mjs";
235
+ import "./account-resolution-B5v6WlRC.mjs";
236
+ import "./skills-status-DjVDxLj2.mjs";
237
+ import "./install-source-utils-irFQt_KV.mjs";
238
+ import "./clawhub-CW7VHtLD.mjs";
239
+ import "./install-safe-path-CEnkDyia.mjs";
240
+ import "./installs-D9sH8j10.mjs";
241
+ import "./clawhub-HvwNujFy.mjs";
242
+ import "./status-BWLPyL8Y.mjs";
243
+ import "./auth-health-whXtiaC8.mjs";
244
+ import "./note-CaQ2HD-A.mjs";
245
+ import "./bundled-sources-BG6YeEu2.mjs";
246
+ import { r as installCompletion } from "./completion-cli-DuMZk0lN.mjs";
247
+ import "./register.subclis-Dj9qGYdr.mjs";
248
+ import "./command-registry-BnmWhMEa.mjs";
249
+ import "./program-context-9v4H9od4.mjs";
250
+ import { n as renderTable, t as getTerminalTableWidth } from "./table-DBZ08bTi.mjs";
251
+ import "./heartbeat-summary-CUbo9b9F.mjs";
252
+ import "./health-C4WG9Yfr.mjs";
253
+ import "./control-ui-assets-CW49D85b.mjs";
254
+ import { a as createGlobalInstallEnv, c as globalInstallArgs, d as normalizePackageTagInput, f as readPackageName, i as cleanupGlobalRenameDirs, l as resolveGlobalInstallSpec, n as runGatewayUpdate, o as detectGlobalInstallManagerByPresence, p as readPackageVersion, r as canResolveRegistryVersionForPackageTarget, s as detectGlobalInstallManagerForRoot, u as resolveGlobalPackageRoot } from "./server-startup-matrix-migration-BYVP8K4t.mjs";
255
+ import { a as resolveNpmChannelTag, c as DEFAULT_PACKAGE_CHANNEL, d as formatUpdateChannelLabel, g as resolveUpdateChannelDisplay, h as resolveEffectiveUpdateChannel, m as normalizeUpdateChannel, n as compareSemverStrings, r as fetchNpmTagVersion, s as DEFAULT_GIT_CHANNEL, t as checkUpdateStatus, u as channelToNpmTag } from "./update-check-CinGDRx-.mjs";
256
+ import "./channels-status-issues-DxKcDmEl.mjs";
257
+ import { i as resolveUpdateAvailability, n as formatUpdateOneLiner, t as formatUpdateAvailableHint } from "./status.update-4WSHdpiH.mjs";
258
+ import { n as updateNpmInstalledPlugins, t as syncPluginsForUpdateChannel } from "./update-B838aQTS.mjs";
259
+ import "./provider-auth-guidance-DyLaRtDO.mjs";
260
+ import "./systemd-linger-CMHj3APL.mjs";
261
+ import "./health-format-DnRUP-NJ.mjs";
262
+ import { n as doctorCommand, t as selectStyled } from "./prompt-select-styled-DWTJpQCH.mjs";
263
+ import { r as ensureCompletionCacheExists, t as checkShellCompletionStatus } from "./doctor-completion-1UqU9aiy.mjs";
264
+ import "./doctor-config-preflight-C6d55ZHc.mjs";
265
+ import "./channel-account-context-Bcf1_AeX.mjs";
266
+ import "./doctor-state-migrations-CfyTM0UY.mjs";
267
+ import "./provider-openai-codex-oauth-tls-CVsiK51M.mjs";
268
+ import path from "node:path";
269
+ import { spawn, spawnSync } from "node:child_process";
270
+ import os from "node:os";
271
+ import fs from "node:fs/promises";
272
+ import { confirm, isCancel, spinner } from "@clack/prompts";
273
+
274
+ //#region src/cli/update-cli/shared.ts
275
+ const INVALID_TIMEOUT_ERROR = "--timeout must be a positive integer (seconds)";
276
+ function parseTimeoutMsOrExit(timeout) {
277
+ const timeoutMs = timeout ? Number.parseInt(timeout, 10) * 1e3 : void 0;
278
+ if (timeoutMs !== void 0 && (Number.isNaN(timeoutMs) || timeoutMs <= 0)) {
279
+ defaultRuntime.error(INVALID_TIMEOUT_ERROR);
280
+ defaultRuntime.exit(1);
281
+ return null;
282
+ }
283
+ return timeoutMs;
284
+ }
285
+ const OPENCLAW_REPO_URL = "https://github.com/Heretek-AI/openclaw.git";
286
+ const MAX_LOG_CHARS = 8e3;
287
+ const DEFAULT_PACKAGE_NAME = "openclaw";
288
+ const CORE_PACKAGE_NAMES = new Set([DEFAULT_PACKAGE_NAME]);
289
+ function normalizeTag(value) {
290
+ return normalizePackageTagInput(value, ["openclaw", DEFAULT_PACKAGE_NAME]);
291
+ }
292
+ function normalizeVersionTag(tag) {
293
+ const trimmed = tag.trim();
294
+ if (!trimmed) return null;
295
+ const cleaned = trimmed.startsWith("v") ? trimmed.slice(1) : trimmed;
296
+ return parseSemver(cleaned) ? cleaned : null;
297
+ }
298
+ async function resolveTargetVersion(tag, timeoutMs) {
299
+ if (!canResolveRegistryVersionForPackageTarget(tag)) return null;
300
+ const direct = normalizeVersionTag(tag);
301
+ if (direct) return direct;
302
+ return (await fetchNpmTagVersion({
303
+ tag,
304
+ timeoutMs
305
+ })).version ?? null;
306
+ }
307
+ async function isGitCheckout(root) {
308
+ try {
309
+ await fs.stat(path.join(root, ".git"));
310
+ return true;
311
+ } catch {
312
+ return false;
313
+ }
314
+ }
315
+ async function isCorePackage(root) {
316
+ const name = await readPackageName(root);
317
+ return Boolean(name && CORE_PACKAGE_NAMES.has(name));
318
+ }
319
+ async function isEmptyDir(targetPath) {
320
+ try {
321
+ return (await fs.readdir(targetPath)).length === 0;
322
+ } catch {
323
+ return false;
324
+ }
325
+ }
326
+ function resolveGitInstallDir() {
327
+ const override = process.env.OPENCLAW_GIT_DIR?.trim();
328
+ if (override) return path.resolve(override);
329
+ return resolveDefaultGitDir();
330
+ }
331
+ function resolveDefaultGitDir() {
332
+ return path.join(os.homedir(), "openclaw");
333
+ }
334
+ function resolveNodeRunner() {
335
+ const base = path.basename(process.execPath).toLowerCase();
336
+ if (base === "node" || base === "node.exe") return process.execPath;
337
+ return "node";
338
+ }
339
+ async function resolveUpdateRoot() {
340
+ return await resolveOpenClawPackageRoot({
341
+ moduleUrl: import.meta.url,
342
+ argv1: process.argv[1],
343
+ cwd: process.cwd()
344
+ }) ?? process.cwd();
345
+ }
346
+ async function runUpdateStep(params) {
347
+ const command = params.argv.join(" ");
348
+ params.progress?.onStepStart?.({
349
+ name: params.name,
350
+ command,
351
+ index: 0,
352
+ total: 0
353
+ });
354
+ const started = Date.now();
355
+ const res = await runCommandWithTimeout(params.argv, {
356
+ cwd: params.cwd,
357
+ env: params.env,
358
+ timeoutMs: params.timeoutMs
359
+ });
360
+ const durationMs = Date.now() - started;
361
+ const stderrTail = trimLogTail(res.stderr, MAX_LOG_CHARS);
362
+ params.progress?.onStepComplete?.({
363
+ name: params.name,
364
+ command,
365
+ index: 0,
366
+ total: 0,
367
+ durationMs,
368
+ exitCode: res.code,
369
+ stderrTail
370
+ });
371
+ return {
372
+ name: params.name,
373
+ command,
374
+ cwd: params.cwd ?? process.cwd(),
375
+ durationMs,
376
+ exitCode: res.code,
377
+ stdoutTail: trimLogTail(res.stdout, MAX_LOG_CHARS),
378
+ stderrTail
379
+ };
380
+ }
381
+ async function ensureGitCheckout(params) {
382
+ const gitEnv = params.env ?? await createGlobalInstallEnv();
383
+ if (!await pathExists(params.dir)) return await runUpdateStep({
384
+ name: "git clone",
385
+ argv: [
386
+ "git",
387
+ "clone",
388
+ OPENCLAW_REPO_URL,
389
+ params.dir
390
+ ],
391
+ env: gitEnv,
392
+ timeoutMs: params.timeoutMs,
393
+ progress: params.progress
394
+ });
395
+ if (!await isGitCheckout(params.dir)) {
396
+ if (!await isEmptyDir(params.dir)) throw new Error(`OPENCLAW_GIT_DIR points at a non-git directory: ${params.dir}. Set OPENCLAW_GIT_DIR to an empty folder or an openclaw checkout.`);
397
+ return await runUpdateStep({
398
+ name: "git clone",
399
+ argv: [
400
+ "git",
401
+ "clone",
402
+ OPENCLAW_REPO_URL,
403
+ params.dir
404
+ ],
405
+ cwd: params.dir,
406
+ env: gitEnv,
407
+ timeoutMs: params.timeoutMs,
408
+ progress: params.progress
409
+ });
410
+ }
411
+ if (!await isCorePackage(params.dir)) throw new Error(`OPENCLAW_GIT_DIR does not look like a core checkout: ${params.dir}.`);
412
+ return null;
413
+ }
414
+ async function resolveGlobalManager(params) {
415
+ const runCommand = createGlobalCommandRunner();
416
+ if (params.installKind === "package") {
417
+ const detected = await detectGlobalInstallManagerForRoot(runCommand, params.root, params.timeoutMs);
418
+ if (detected) return detected;
419
+ }
420
+ return await detectGlobalInstallManagerByPresence(runCommand, params.timeoutMs) ?? "npm";
421
+ }
422
+ async function tryWriteCompletionCache(root, jsonMode) {
423
+ const binPath = path.join(root, "openclaw.mjs");
424
+ if (!await pathExists(binPath)) return;
425
+ const result = spawnSync(resolveNodeRunner(), [
426
+ binPath,
427
+ "completion",
428
+ "--write-state"
429
+ ], {
430
+ cwd: root,
431
+ env: process.env,
432
+ encoding: "utf-8"
433
+ });
434
+ if (result.error) {
435
+ if (!jsonMode) defaultRuntime.log(theme.warn(`Completion cache update failed: ${String(result.error)}`));
436
+ return;
437
+ }
438
+ if (result.status !== 0 && !jsonMode) {
439
+ const stderr = (result.stderr ?? "").toString().trim();
440
+ const detail = stderr ? ` (${stderr})` : "";
441
+ defaultRuntime.log(theme.warn(`Completion cache update failed${detail}.`));
442
+ }
443
+ }
444
+ function createGlobalCommandRunner() {
445
+ return async (argv, options) => {
446
+ const res = await runCommandWithTimeout(argv, options);
447
+ return {
448
+ stdout: res.stdout,
449
+ stderr: res.stderr,
450
+ code: res.code
451
+ };
452
+ };
453
+ }
454
+
455
+ //#endregion
456
+ //#region src/cli/update-cli/status.ts
457
+ function formatGitStatusLine(params) {
458
+ const shortSha = params.sha ? params.sha.slice(0, 8) : null;
459
+ const branch = params.branch && params.branch !== "HEAD" ? params.branch : null;
460
+ const tag = params.tag;
461
+ return [
462
+ branch ?? (tag ? "detached" : "git"),
463
+ tag ? `tag ${tag}` : null,
464
+ shortSha ? `@ ${shortSha}` : null
465
+ ].filter(Boolean).join(" · ");
466
+ }
467
+ async function updateStatusCommand(opts) {
468
+ const timeoutMs = parseTimeoutMsOrExit(opts.timeout);
469
+ if (timeoutMs === null) return;
470
+ const root = await resolveUpdateRoot();
471
+ const configSnapshot = await readConfigFileSnapshot();
472
+ const configChannel = configSnapshot.valid ? normalizeUpdateChannel(configSnapshot.config.update?.channel) : null;
473
+ const update = await checkUpdateStatus({
474
+ root,
475
+ timeoutMs: timeoutMs ?? 3500,
476
+ fetchGit: true,
477
+ includeRegistry: true
478
+ });
479
+ const channelInfo = resolveUpdateChannelDisplay({
480
+ configChannel,
481
+ installKind: update.installKind,
482
+ gitTag: update.git?.tag ?? null,
483
+ gitBranch: update.git?.branch ?? null
484
+ });
485
+ const channelLabel = channelInfo.label;
486
+ const gitLabel = update.installKind === "git" ? formatGitStatusLine({
487
+ branch: update.git?.branch ?? null,
488
+ tag: update.git?.tag ?? null,
489
+ sha: update.git?.sha ?? null
490
+ }) : null;
491
+ const updateAvailability = resolveUpdateAvailability(update);
492
+ const updateLine = formatUpdateOneLiner(update).replace(/^Update:\s*/i, "");
493
+ if (opts.json) {
494
+ defaultRuntime.writeJson({
495
+ update,
496
+ channel: {
497
+ value: channelInfo.channel,
498
+ source: channelInfo.source,
499
+ label: channelLabel,
500
+ config: configChannel
501
+ },
502
+ availability: updateAvailability
503
+ });
504
+ return;
505
+ }
506
+ const tableWidth = getTerminalTableWidth();
507
+ const rows = [
508
+ {
509
+ Item: "Install",
510
+ Value: update.installKind === "git" ? `git (${update.root ?? "unknown"})` : update.installKind === "package" ? update.packageManager : "unknown"
511
+ },
512
+ {
513
+ Item: "Channel",
514
+ Value: channelLabel
515
+ },
516
+ ...gitLabel ? [{
517
+ Item: "Git",
518
+ Value: gitLabel
519
+ }] : [],
520
+ {
521
+ Item: "Update",
522
+ Value: updateAvailability.available ? theme.warn(`available · ${updateLine}`) : updateLine
523
+ }
524
+ ];
525
+ defaultRuntime.log(theme.heading("OpenClaw update status"));
526
+ defaultRuntime.log("");
527
+ defaultRuntime.log(renderTable({
528
+ width: tableWidth,
529
+ columns: [{
530
+ key: "Item",
531
+ header: "Item",
532
+ minWidth: 10
533
+ }, {
534
+ key: "Value",
535
+ header: "Value",
536
+ flex: true,
537
+ minWidth: 24
538
+ }],
539
+ rows
540
+ }).trimEnd());
541
+ defaultRuntime.log("");
542
+ const updateHint = formatUpdateAvailableHint(update);
543
+ if (updateHint) defaultRuntime.log(theme.warn(updateHint));
544
+ }
545
+
546
+ //#endregion
547
+ //#region src/cli/update-cli/progress.ts
548
+ const STEP_LABELS = {
549
+ "clean check": "Working directory is clean",
550
+ "upstream check": "Upstream branch exists",
551
+ "git fetch": "Fetching latest changes",
552
+ "git rebase": "Rebasing onto target commit",
553
+ "git rev-parse @{upstream}": "Resolving upstream commit",
554
+ "git rev-list": "Enumerating candidate commits",
555
+ "git clone": "Cloning git checkout",
556
+ "preflight worktree": "Preparing preflight worktree",
557
+ "preflight cleanup": "Cleaning preflight worktree",
558
+ "deps install": "Installing dependencies",
559
+ build: "Building",
560
+ "ui:build": "Building UI assets",
561
+ "ui:build (post-doctor repair)": "Restoring missing UI assets",
562
+ "ui assets verify": "Validating UI assets",
563
+ "openclaw doctor entry": "Checking doctor entrypoint",
564
+ "openclaw doctor": "Running doctor checks",
565
+ "git rev-parse HEAD (after)": "Verifying update",
566
+ "global update": "Updating via package manager",
567
+ "global update (omit optional)": "Retrying update without optional deps",
568
+ "global install": "Installing global package"
569
+ };
570
+ function getStepLabel(step) {
571
+ return STEP_LABELS[step.name] ?? step.name;
572
+ }
573
+ function inferUpdateFailureHints(result) {
574
+ if (result.status !== "error" || result.mode !== "npm") return [];
575
+ const failedStep = [...result.steps].toReversed().find((step) => step.exitCode !== 0);
576
+ if (!failedStep) return [];
577
+ const stderr = (failedStep.stderrTail ?? "").toLowerCase();
578
+ const hints = [];
579
+ if (failedStep.name.startsWith("global update") && stderr.includes("eacces")) {
580
+ hints.push("Detected permission failure (EACCES). Re-run with a writable global prefix or sudo (for system-managed Node installs).");
581
+ hints.push("Example: npm config set prefix ~/.local && npm i -g openclaw@latest");
582
+ }
583
+ if (failedStep.name.startsWith("global update") && (stderr.includes("node-gyp") || stderr.includes("prebuild"))) {
584
+ hints.push("Detected native optional dependency build failure. The updater retries with --omit=optional automatically.");
585
+ hints.push("If it still fails: npm i -g openclaw@latest --omit=optional");
586
+ }
587
+ return hints;
588
+ }
589
+ function createUpdateProgress(enabled) {
590
+ if (!enabled) return {
591
+ progress: {},
592
+ stop: () => {}
593
+ };
594
+ let currentSpinner = null;
595
+ return {
596
+ progress: {
597
+ onStepStart: (step) => {
598
+ currentSpinner = spinner();
599
+ currentSpinner.start(theme.accent(getStepLabel(step)));
600
+ },
601
+ onStepComplete: (step) => {
602
+ if (!currentSpinner) return;
603
+ const label = getStepLabel(step);
604
+ const duration = theme.muted(`(${formatDurationPrecise(step.durationMs)})`);
605
+ const icon = step.exitCode === 0 ? theme.success("✓") : theme.error("✗");
606
+ currentSpinner.stop(`${icon} ${label} ${duration}`);
607
+ currentSpinner = null;
608
+ if (step.exitCode !== 0 && step.stderrTail) {
609
+ const lines = step.stderrTail.split("\n").slice(-10);
610
+ for (const line of lines) if (line.trim()) defaultRuntime.log(` ${theme.error(line)}`);
611
+ }
612
+ }
613
+ },
614
+ stop: () => {
615
+ if (currentSpinner) {
616
+ currentSpinner.stop();
617
+ currentSpinner = null;
618
+ }
619
+ }
620
+ };
621
+ }
622
+ function formatStepStatus(exitCode) {
623
+ if (exitCode === 0) return theme.success("✓");
624
+ if (exitCode === null) return theme.warn("?");
625
+ return theme.error("✗");
626
+ }
627
+ function printResult(result, opts) {
628
+ if (opts.json) {
629
+ defaultRuntime.writeJson(result);
630
+ return;
631
+ }
632
+ const statusColor = result.status === "ok" ? theme.success : result.status === "skipped" ? theme.warn : theme.error;
633
+ defaultRuntime.log("");
634
+ defaultRuntime.log(`${theme.heading("Update Result:")} ${statusColor(result.status.toUpperCase())}`);
635
+ if (result.root) defaultRuntime.log(` Root: ${theme.muted(result.root)}`);
636
+ if (result.reason) defaultRuntime.log(` Reason: ${theme.muted(result.reason)}`);
637
+ if (result.before?.version || result.before?.sha) {
638
+ const before = result.before.version ?? result.before.sha?.slice(0, 8) ?? "";
639
+ defaultRuntime.log(` Before: ${theme.muted(before)}`);
640
+ }
641
+ if (result.after?.version || result.after?.sha) {
642
+ const after = result.after.version ?? result.after.sha?.slice(0, 8) ?? "";
643
+ defaultRuntime.log(` After: ${theme.muted(after)}`);
644
+ }
645
+ if (!opts.hideSteps && result.steps.length > 0) {
646
+ defaultRuntime.log("");
647
+ defaultRuntime.log(theme.heading("Steps:"));
648
+ for (const step of result.steps) {
649
+ const status = formatStepStatus(step.exitCode);
650
+ const duration = theme.muted(`(${formatDurationPrecise(step.durationMs)})`);
651
+ defaultRuntime.log(` ${status} ${step.name} ${duration}`);
652
+ if (step.exitCode !== 0 && step.stderrTail) {
653
+ const lines = step.stderrTail.split("\n").slice(0, 5);
654
+ for (const line of lines) if (line.trim()) defaultRuntime.log(` ${theme.error(line)}`);
655
+ }
656
+ }
657
+ }
658
+ const hints = inferUpdateFailureHints(result);
659
+ if (hints.length > 0) {
660
+ defaultRuntime.log("");
661
+ defaultRuntime.log(theme.heading("Recovery hints:"));
662
+ for (const hint of hints) defaultRuntime.log(` - ${theme.warn(hint)}`);
663
+ }
664
+ defaultRuntime.log("");
665
+ defaultRuntime.log(`Total time: ${theme.muted(formatDurationPrecise(result.durationMs))}`);
666
+ }
667
+
668
+ //#endregion
669
+ //#region src/cli/update-cli/restart-helper.ts
670
+ /**
671
+ * Shell-escape a string for embedding in single-quoted shell arguments.
672
+ * Replaces every `'` with `'\''` (end quote, escaped quote, resume quote).
673
+ * For batch scripts, validates against special characters instead.
674
+ */
675
+ function shellEscape(value) {
676
+ return value.replace(/'/g, "'\\''");
677
+ }
678
+ /** Validates a string is safe for embedding in a batch (cmd.exe) script. */
679
+ function isBatchSafe(value) {
680
+ return /^[A-Za-z0-9 _\-().]+$/.test(value);
681
+ }
682
+ function resolveSystemdUnit(env) {
683
+ const override = env.OPENCLAW_SYSTEMD_UNIT?.trim();
684
+ if (override) return override.endsWith(".service") ? override : `${override}.service`;
685
+ return `${resolveGatewaySystemdServiceName(env.OPENCLAW_PROFILE)}.service`;
686
+ }
687
+ function resolveLaunchdLabel(env) {
688
+ const override = env.OPENCLAW_LAUNCHD_LABEL?.trim();
689
+ if (override) return override;
690
+ return resolveGatewayLaunchAgentLabel(env.OPENCLAW_PROFILE);
691
+ }
692
+ function resolveWindowsTaskName(env) {
693
+ const override = env.OPENCLAW_WINDOWS_TASK_NAME?.trim();
694
+ if (override) return override;
695
+ return resolveGatewayWindowsTaskName(env.OPENCLAW_PROFILE);
696
+ }
697
+ /**
698
+ * Prepares a standalone script to restart the gateway service.
699
+ * This script is written to a temporary directory and does not depend on
700
+ * the installed package files, ensuring restart capability even if the
701
+ * update process temporarily removes or corrupts installation files.
702
+ */
703
+ async function prepareRestartScript(env = process.env, gatewayPort = DEFAULT_GATEWAY_PORT) {
704
+ const tmpDir = os.tmpdir();
705
+ const timestamp = Date.now();
706
+ const platform$1 = process.platform;
707
+ let scriptContent = "";
708
+ let filename = "";
709
+ try {
710
+ if (platform$1 === "linux") {
711
+ const escaped = shellEscape(resolveSystemdUnit(env));
712
+ filename = `openclaw-restart-${timestamp}.sh`;
713
+ scriptContent = `#!/bin/sh
714
+ # Standalone restart script — survives parent process termination.
715
+ # Wait briefly to ensure file locks are released after update.
716
+ sleep 1
717
+ systemctl --user restart '${escaped}'
718
+ # Self-cleanup
719
+ rm -f "$0"
720
+ `;
721
+ } else if (platform$1 === "darwin") {
722
+ const label = resolveLaunchdLabel(env);
723
+ const escaped = shellEscape(label);
724
+ const uid = process.getuid ? process.getuid() : 501;
725
+ const home = env.HOME?.trim() || process.env.HOME || os.homedir();
726
+ const escapedPlistPath = shellEscape(path.join(home, "Library", "LaunchAgents", `${label}.plist`));
727
+ filename = `openclaw-restart-${timestamp}.sh`;
728
+ scriptContent = `#!/bin/sh
729
+ # Standalone restart script — survives parent process termination.
730
+ # Wait briefly to ensure file locks are released after update.
731
+ sleep 1
732
+ # Try kickstart first (works when the service is still registered).
733
+ # If it fails (e.g. after bootout), clear any persisted disabled state,
734
+ # then re-register via bootstrap and kickstart.
735
+ if ! launchctl kickstart -k 'gui/${uid}/${escaped}' 2>/dev/null; then
736
+ launchctl enable 'gui/${uid}/${escaped}' 2>/dev/null
737
+ launchctl bootstrap 'gui/${uid}' '${escapedPlistPath}' 2>/dev/null
738
+ launchctl kickstart -k 'gui/${uid}/${escaped}' 2>/dev/null || true
739
+ fi
740
+ # Self-cleanup
741
+ rm -f "$0"
742
+ `;
743
+ } else if (platform$1 === "win32") {
744
+ const taskName = resolveWindowsTaskName(env);
745
+ if (!isBatchSafe(taskName)) return null;
746
+ const port = Number.isFinite(gatewayPort) && gatewayPort > 0 ? gatewayPort : DEFAULT_GATEWAY_PORT;
747
+ filename = `openclaw-restart-${timestamp}.bat`;
748
+ scriptContent = `@echo off
749
+ REM Standalone restart script — survives parent process termination.
750
+ REM Wait briefly to ensure file locks are released after update.
751
+ timeout /t 2 /nobreak >nul
752
+ schtasks /End /TN "${taskName}"
753
+ REM Poll for gateway port release before rerun; force-kill listener if stuck.
754
+ set /a attempts=0
755
+ :wait_for_port_release
756
+ set /a attempts+=1
757
+ netstat -ano | findstr /R /C:":${port} .*LISTENING" >nul
758
+ if errorlevel 1 goto port_released
759
+ if %attempts% GEQ 10 goto force_kill_listener
760
+ timeout /t 1 /nobreak >nul
761
+ goto wait_for_port_release
762
+ :force_kill_listener
763
+ for /f "tokens=5" %%P in ('netstat -ano ^| findstr /R /C:":${port} .*LISTENING"') do (
764
+ taskkill /F /PID %%P >nul 2>&1
765
+ goto port_released
766
+ )
767
+ :port_released
768
+ schtasks /Run /TN "${taskName}"
769
+ REM Self-cleanup
770
+ del "%~f0"
771
+ `;
772
+ } else return null;
773
+ const scriptPath = path.join(tmpDir, filename);
774
+ await fs.writeFile(scriptPath, scriptContent, { mode: 493 });
775
+ return scriptPath;
776
+ } catch {
777
+ return null;
778
+ }
779
+ }
780
+ /**
781
+ * Executes the prepared restart script as a **detached** process.
782
+ *
783
+ * The script must outlive the CLI process because the CLI itself is part
784
+ * of the service being restarted — `systemctl restart` / `launchctl
785
+ * kickstart -k` will terminate the current process tree. Using
786
+ * `spawn({ detached: true })` + `unref()` ensures the script survives
787
+ * the parent's exit.
788
+ *
789
+ * Resolves immediately after spawning; the script runs independently.
790
+ */
791
+ async function runRestartScript(scriptPath) {
792
+ const isWindows = process.platform === "win32";
793
+ spawn(isWindows ? "cmd.exe" : "/bin/sh", isWindows ? [
794
+ "/d",
795
+ "/s",
796
+ "/c",
797
+ quoteCmdScriptArg(scriptPath)
798
+ ] : [scriptPath], {
799
+ detached: true,
800
+ stdio: "ignore",
801
+ windowsHide: true
802
+ }).unref();
803
+ }
804
+
805
+ //#endregion
806
+ //#region src/cli/update-cli/suppress-deprecations.ts
807
+ /**
808
+ * Suppress Node.js deprecation warnings.
809
+ *
810
+ * On Node.js v23+ `process.noDeprecation` may be a read-only property
811
+ * (defined via a getter on the prototype with no setter), so the
812
+ * assignment can throw. We fall back to the environment variable which
813
+ * achieves the same effect.
814
+ */
815
+ function suppressDeprecations() {
816
+ try {
817
+ process.noDeprecation = true;
818
+ } catch {}
819
+ process.env.NODE_NO_WARNINGS = "1";
820
+ }
821
+
822
+ //#endregion
823
+ //#region src/cli/update-cli/update-command.ts
824
+ const CLI_NAME = resolveCliName();
825
+ const SERVICE_REFRESH_TIMEOUT_MS = 6e4;
826
+ const SERVICE_REFRESH_PATH_ENV_KEYS = [
827
+ "OPENCLAW_HOME",
828
+ "OPENCLAW_STATE_DIR",
829
+ "OPENCLAW_CONFIG_PATH"
830
+ ];
831
+ const UPDATE_QUIPS = [
832
+ "Leveled up! New skills unlocked. You're welcome.",
833
+ "Fresh code, same lobster. Miss me?",
834
+ "Back and better. Did you even notice I was gone?",
835
+ "Update complete. I learned some new tricks while I was out.",
836
+ "Upgraded! Now with 23% more sass.",
837
+ "I've evolved. Try to keep up.",
838
+ "New version, who dis? Oh right, still me but shinier.",
839
+ "Patched, polished, and ready to pinch. Let's go.",
840
+ "The lobster has molted. Harder shell, sharper claws.",
841
+ "Update done! Check the changelog or just trust me, it's good.",
842
+ "Reborn from the boiling waters of npm. Stronger now.",
843
+ "I went away and came back smarter. You should try it sometime.",
844
+ "Update complete. The bugs feared me, so they left.",
845
+ "New version installed. Old version sends its regards.",
846
+ "Firmware fresh. Brain wrinkles: increased.",
847
+ "I've seen things you wouldn't believe. Anyway, I'm updated.",
848
+ "Back online. The changelog is long but our friendship is longer.",
849
+ "Upgraded! Peter fixed stuff. Blame him if it breaks.",
850
+ "Molting complete. Please don't look at my soft shell phase.",
851
+ "Version bump! Same chaos energy, fewer crashes (probably)."
852
+ ];
853
+ function pickUpdateQuip() {
854
+ return UPDATE_QUIPS[Math.floor(Math.random() * UPDATE_QUIPS.length)] ?? "Update complete.";
855
+ }
856
+ function resolveGatewayInstallEntrypointCandidates(root) {
857
+ if (!root) return [];
858
+ return [
859
+ path.join(root, "dist", "entry.js"),
860
+ path.join(root, "dist", "entry.mjs"),
861
+ path.join(root, "dist", "index.js"),
862
+ path.join(root, "dist", "index.mjs")
863
+ ];
864
+ }
865
+ function formatCommandFailure(stdout, stderr) {
866
+ const detail = (stderr || stdout).trim();
867
+ if (!detail) return "command returned a non-zero exit code";
868
+ return detail.split("\n").slice(-3).join("\n");
869
+ }
870
+ function tryResolveInvocationCwd() {
871
+ try {
872
+ return process.cwd();
873
+ } catch {
874
+ return;
875
+ }
876
+ }
877
+ function resolveServiceRefreshEnv(env, invocationCwd) {
878
+ const resolvedEnv = { ...env };
879
+ for (const key of SERVICE_REFRESH_PATH_ENV_KEYS) {
880
+ const rawValue = resolvedEnv[key]?.trim();
881
+ if (!rawValue) continue;
882
+ if (rawValue.startsWith("~") || path.isAbsolute(rawValue) || path.win32.isAbsolute(rawValue)) {
883
+ resolvedEnv[key] = rawValue;
884
+ continue;
885
+ }
886
+ if (!invocationCwd) {
887
+ resolvedEnv[key] = rawValue;
888
+ continue;
889
+ }
890
+ resolvedEnv[key] = path.resolve(invocationCwd, rawValue);
891
+ }
892
+ return resolvedEnv;
893
+ }
894
+ function printDryRunPreview(preview, jsonMode) {
895
+ if (jsonMode) {
896
+ defaultRuntime.writeJson(preview);
897
+ return;
898
+ }
899
+ defaultRuntime.log(theme.heading("Update dry-run"));
900
+ defaultRuntime.log(theme.muted("No changes were applied."));
901
+ defaultRuntime.log("");
902
+ defaultRuntime.log(` Root: ${theme.muted(preview.root)}`);
903
+ defaultRuntime.log(` Install kind: ${theme.muted(preview.installKind)}`);
904
+ defaultRuntime.log(` Mode: ${theme.muted(preview.mode)}`);
905
+ defaultRuntime.log(` Channel: ${theme.muted(preview.effectiveChannel)}`);
906
+ defaultRuntime.log(` Tag/spec: ${theme.muted(preview.tag)}`);
907
+ if (preview.currentVersion) defaultRuntime.log(` Current version: ${theme.muted(preview.currentVersion)}`);
908
+ if (preview.targetVersion) defaultRuntime.log(` Target version: ${theme.muted(preview.targetVersion)}`);
909
+ if (preview.downgradeRisk) defaultRuntime.log(theme.warn(" Downgrade confirmation would be required in a real run."));
910
+ defaultRuntime.log("");
911
+ defaultRuntime.log(theme.heading("Planned actions:"));
912
+ for (const action of preview.actions) defaultRuntime.log(` - ${action}`);
913
+ if (preview.notes.length > 0) {
914
+ defaultRuntime.log("");
915
+ defaultRuntime.log(theme.heading("Notes:"));
916
+ for (const note$1 of preview.notes) defaultRuntime.log(` - ${theme.muted(note$1)}`);
917
+ }
918
+ }
919
+ async function refreshGatewayServiceEnv(params) {
920
+ const args = [
921
+ "gateway",
922
+ "install",
923
+ "--force"
924
+ ];
925
+ if (params.jsonMode) args.push("--json");
926
+ for (const candidate of resolveGatewayInstallEntrypointCandidates(params.result.root)) {
927
+ if (!await pathExists(candidate)) continue;
928
+ const res = await runCommandWithTimeout([
929
+ resolveNodeRunner(),
930
+ candidate,
931
+ ...args
932
+ ], {
933
+ cwd: params.result.root,
934
+ env: resolveServiceRefreshEnv(process.env, params.invocationCwd),
935
+ timeoutMs: SERVICE_REFRESH_TIMEOUT_MS
936
+ });
937
+ if (res.code === 0) return;
938
+ throw new Error(`updated install refresh failed (${candidate}): ${formatCommandFailure(res.stdout, res.stderr)}`);
939
+ }
940
+ await runDaemonInstall({
941
+ force: true,
942
+ json: params.jsonMode || void 0
943
+ });
944
+ }
945
+ async function tryInstallShellCompletion(opts) {
946
+ if (opts.jsonMode || !process.stdin.isTTY) return;
947
+ const status = await checkShellCompletionStatus(CLI_NAME);
948
+ if (status.usesSlowPattern) {
949
+ defaultRuntime.log(theme.muted("Upgrading shell completion to cached version..."));
950
+ if (await ensureCompletionCacheExists(CLI_NAME)) await installCompletion(status.shell, true, CLI_NAME);
951
+ return;
952
+ }
953
+ if (status.profileInstalled && !status.cacheExists) {
954
+ defaultRuntime.log(theme.muted("Regenerating shell completion cache..."));
955
+ await ensureCompletionCacheExists(CLI_NAME);
956
+ return;
957
+ }
958
+ if (!status.profileInstalled) {
959
+ defaultRuntime.log("");
960
+ defaultRuntime.log(theme.heading("Shell completion"));
961
+ const shouldInstall = await confirm({
962
+ message: stylePromptMessage(`Enable ${status.shell} shell completion for ${CLI_NAME}?`),
963
+ initialValue: true
964
+ });
965
+ if (isCancel(shouldInstall) || !shouldInstall) {
966
+ if (!opts.skipPrompt) defaultRuntime.log(theme.muted(`Skipped. Run \`${replaceCliName(formatCliCommand("openclaw completion --install"), CLI_NAME)}\` later to enable.`));
967
+ return;
968
+ }
969
+ if (!await ensureCompletionCacheExists(CLI_NAME)) {
970
+ defaultRuntime.log(theme.warn("Failed to generate completion cache."));
971
+ return;
972
+ }
973
+ await installCompletion(status.shell, opts.skipPrompt, CLI_NAME);
974
+ }
975
+ }
976
+ async function runPackageInstallUpdate(params) {
977
+ const manager = await resolveGlobalManager({
978
+ root: params.root,
979
+ installKind: params.installKind,
980
+ timeoutMs: params.timeoutMs
981
+ });
982
+ const installEnv = await createGlobalInstallEnv();
983
+ const pkgRoot = await resolveGlobalPackageRoot(manager, createGlobalCommandRunner(), params.timeoutMs);
984
+ const packageName = (pkgRoot ? await readPackageName(pkgRoot) : await readPackageName(params.root)) ?? DEFAULT_PACKAGE_NAME;
985
+ const installSpec = resolveGlobalInstallSpec({
986
+ packageName,
987
+ tag: params.tag,
988
+ env: installEnv
989
+ });
990
+ const beforeVersion = pkgRoot ? await readPackageVersion(pkgRoot) : null;
991
+ if (pkgRoot) await cleanupGlobalRenameDirs({
992
+ globalRoot: path.dirname(pkgRoot),
993
+ packageName
994
+ });
995
+ const steps = [await runUpdateStep({
996
+ name: "global update",
997
+ argv: globalInstallArgs(manager, installSpec),
998
+ env: installEnv,
999
+ timeoutMs: params.timeoutMs,
1000
+ progress: params.progress
1001
+ })];
1002
+ let afterVersion = beforeVersion;
1003
+ if (pkgRoot) {
1004
+ afterVersion = await readPackageVersion(pkgRoot);
1005
+ const entryPath = path.join(pkgRoot, "dist", "entry.js");
1006
+ if (await pathExists(entryPath)) {
1007
+ const doctorStep = await runUpdateStep({
1008
+ name: `${CLI_NAME} doctor`,
1009
+ argv: [
1010
+ resolveNodeRunner(),
1011
+ entryPath,
1012
+ "doctor",
1013
+ "--non-interactive"
1014
+ ],
1015
+ timeoutMs: params.timeoutMs,
1016
+ progress: params.progress
1017
+ });
1018
+ steps.push(doctorStep);
1019
+ }
1020
+ }
1021
+ const failedStep = steps.find((step) => step.exitCode !== 0);
1022
+ return {
1023
+ status: failedStep ? "error" : "ok",
1024
+ mode: manager,
1025
+ root: pkgRoot ?? params.root,
1026
+ reason: failedStep ? failedStep.name : void 0,
1027
+ before: { version: beforeVersion },
1028
+ after: { version: afterVersion },
1029
+ steps,
1030
+ durationMs: Date.now() - params.startedAt
1031
+ };
1032
+ }
1033
+ async function runGitUpdate(params) {
1034
+ const updateRoot = params.switchToGit ? resolveGitInstallDir() : params.root;
1035
+ const effectiveTimeout = params.timeoutMs ?? 20 * 6e4;
1036
+ const installEnv = await createGlobalInstallEnv();
1037
+ const cloneStep = params.switchToGit ? await ensureGitCheckout({
1038
+ dir: updateRoot,
1039
+ env: installEnv,
1040
+ timeoutMs: effectiveTimeout,
1041
+ progress: params.progress
1042
+ }) : null;
1043
+ if (cloneStep && cloneStep.exitCode !== 0) {
1044
+ const result = {
1045
+ status: "error",
1046
+ mode: "git",
1047
+ root: updateRoot,
1048
+ reason: cloneStep.name,
1049
+ steps: [cloneStep],
1050
+ durationMs: Date.now() - params.startedAt
1051
+ };
1052
+ params.stop();
1053
+ printResult(result, {
1054
+ ...params.opts,
1055
+ hideSteps: params.showProgress
1056
+ });
1057
+ defaultRuntime.exit(1);
1058
+ return result;
1059
+ }
1060
+ const updateResult = await runGatewayUpdate({
1061
+ cwd: updateRoot,
1062
+ argv1: params.switchToGit ? void 0 : process.argv[1],
1063
+ timeoutMs: params.timeoutMs,
1064
+ progress: params.progress,
1065
+ channel: params.channel,
1066
+ tag: params.tag
1067
+ });
1068
+ const steps = [...cloneStep ? [cloneStep] : [], ...updateResult.steps];
1069
+ if (params.switchToGit && updateResult.status === "ok") {
1070
+ const installStep = await runUpdateStep({
1071
+ name: "global install",
1072
+ argv: globalInstallArgs(await resolveGlobalManager({
1073
+ root: params.root,
1074
+ installKind: params.installKind,
1075
+ timeoutMs: effectiveTimeout
1076
+ }), updateRoot),
1077
+ cwd: updateRoot,
1078
+ env: installEnv,
1079
+ timeoutMs: effectiveTimeout,
1080
+ progress: params.progress
1081
+ });
1082
+ steps.push(installStep);
1083
+ const failedStep = installStep.exitCode !== 0 ? installStep : null;
1084
+ return {
1085
+ ...updateResult,
1086
+ status: updateResult.status === "ok" && !failedStep ? "ok" : "error",
1087
+ steps,
1088
+ durationMs: Date.now() - params.startedAt
1089
+ };
1090
+ }
1091
+ return {
1092
+ ...updateResult,
1093
+ steps,
1094
+ durationMs: Date.now() - params.startedAt
1095
+ };
1096
+ }
1097
+ async function updatePluginsAfterCoreUpdate(params) {
1098
+ if (!params.configSnapshot.valid) {
1099
+ if (!params.opts.json) defaultRuntime.log(theme.warn("Skipping plugin updates: config is invalid."));
1100
+ return;
1101
+ }
1102
+ const pluginLogger = params.opts.json ? {} : {
1103
+ info: (msg) => defaultRuntime.log(msg),
1104
+ warn: (msg) => defaultRuntime.log(theme.warn(msg)),
1105
+ error: (msg) => defaultRuntime.log(theme.error(msg))
1106
+ };
1107
+ if (!params.opts.json) {
1108
+ defaultRuntime.log("");
1109
+ defaultRuntime.log(theme.heading("Updating plugins..."));
1110
+ }
1111
+ const syncResult = await syncPluginsForUpdateChannel({
1112
+ config: params.configSnapshot.config,
1113
+ channel: params.channel,
1114
+ workspaceDir: params.root,
1115
+ logger: pluginLogger
1116
+ });
1117
+ let pluginConfig = syncResult.config;
1118
+ const npmResult = await updateNpmInstalledPlugins({
1119
+ config: pluginConfig,
1120
+ skipIds: new Set(syncResult.summary.switchedToNpm),
1121
+ logger: pluginLogger
1122
+ });
1123
+ pluginConfig = npmResult.config;
1124
+ if (syncResult.changed || npmResult.changed) await writeConfigFile(pluginConfig);
1125
+ if (params.opts.json) return;
1126
+ const summarizeList = (list) => {
1127
+ if (list.length <= 6) return list.join(", ");
1128
+ return `${list.slice(0, 6).join(", ")} +${list.length - 6} more`;
1129
+ };
1130
+ if (syncResult.summary.switchedToBundled.length > 0) defaultRuntime.log(theme.muted(`Switched to bundled plugins: ${summarizeList(syncResult.summary.switchedToBundled)}.`));
1131
+ if (syncResult.summary.switchedToNpm.length > 0) defaultRuntime.log(theme.muted(`Restored npm plugins: ${summarizeList(syncResult.summary.switchedToNpm)}.`));
1132
+ for (const warning of syncResult.summary.warnings) defaultRuntime.log(theme.warn(warning));
1133
+ for (const error of syncResult.summary.errors) defaultRuntime.log(theme.error(error));
1134
+ const updated = npmResult.outcomes.filter((entry) => entry.status === "updated").length;
1135
+ const unchanged = npmResult.outcomes.filter((entry) => entry.status === "unchanged").length;
1136
+ const failed = npmResult.outcomes.filter((entry) => entry.status === "error").length;
1137
+ const skipped = npmResult.outcomes.filter((entry) => entry.status === "skipped").length;
1138
+ if (npmResult.outcomes.length === 0) defaultRuntime.log(theme.muted("No plugin updates needed."));
1139
+ else {
1140
+ const parts = [`${updated} updated`, `${unchanged} unchanged`];
1141
+ if (failed > 0) parts.push(`${failed} failed`);
1142
+ if (skipped > 0) parts.push(`${skipped} skipped`);
1143
+ defaultRuntime.log(theme.muted(`npm plugins: ${parts.join(", ")}.`));
1144
+ }
1145
+ for (const outcome of npmResult.outcomes) {
1146
+ if (outcome.status !== "error") continue;
1147
+ defaultRuntime.log(theme.error(outcome.message));
1148
+ }
1149
+ }
1150
+ async function maybeRestartService(params) {
1151
+ if (params.shouldRestart) {
1152
+ if (!params.opts.json) {
1153
+ defaultRuntime.log("");
1154
+ defaultRuntime.log(theme.heading("Restarting service..."));
1155
+ }
1156
+ try {
1157
+ let restarted = false;
1158
+ let restartInitiated = false;
1159
+ if (params.refreshServiceEnv) try {
1160
+ await refreshGatewayServiceEnv({
1161
+ result: params.result,
1162
+ jsonMode: Boolean(params.opts.json),
1163
+ invocationCwd: params.invocationCwd
1164
+ });
1165
+ } catch (err) {
1166
+ if (!params.opts.json) defaultRuntime.log(theme.warn(`Failed to refresh gateway service environment from updated install: ${String(err)}`));
1167
+ }
1168
+ if (params.restartScriptPath) {
1169
+ await runRestartScript(params.restartScriptPath);
1170
+ restartInitiated = true;
1171
+ } else restarted = await runDaemonRestart();
1172
+ if (!params.opts.json && restarted) {
1173
+ defaultRuntime.log(theme.success("Daemon restarted successfully."));
1174
+ defaultRuntime.log("");
1175
+ process.env.OPENCLAW_UPDATE_IN_PROGRESS = "1";
1176
+ try {
1177
+ await doctorCommand(defaultRuntime, { nonInteractive: !(Boolean(process.stdin.isTTY) && !params.opts.json && params.opts.yes !== true) });
1178
+ } catch (err) {
1179
+ defaultRuntime.log(theme.warn(`Doctor failed: ${String(err)}`));
1180
+ } finally {
1181
+ delete process.env.OPENCLAW_UPDATE_IN_PROGRESS;
1182
+ }
1183
+ }
1184
+ if (!params.opts.json && restartInitiated) {
1185
+ const service = resolveGatewayService();
1186
+ let health = await waitForGatewayHealthyRestart({
1187
+ service,
1188
+ port: params.gatewayPort
1189
+ });
1190
+ if (!health.healthy && health.staleGatewayPids.length > 0) {
1191
+ if (!params.opts.json) defaultRuntime.log(theme.warn(`Found stale gateway process(es) after restart: ${health.staleGatewayPids.join(", ")}. Cleaning up...`));
1192
+ await terminateStaleGatewayPids(health.staleGatewayPids);
1193
+ await runDaemonRestart();
1194
+ health = await waitForGatewayHealthyRestart({
1195
+ service,
1196
+ port: params.gatewayPort
1197
+ });
1198
+ }
1199
+ if (health.healthy) defaultRuntime.log(theme.success("Daemon restart completed."));
1200
+ else {
1201
+ defaultRuntime.log(theme.warn("Gateway did not become healthy after restart."));
1202
+ for (const line of renderRestartDiagnostics(health)) defaultRuntime.log(theme.muted(line));
1203
+ defaultRuntime.log(theme.muted(`Run \`${replaceCliName(formatCliCommand("openclaw gateway status --deep"), CLI_NAME)}\` for details.`));
1204
+ }
1205
+ defaultRuntime.log("");
1206
+ }
1207
+ } catch (err) {
1208
+ if (!params.opts.json) {
1209
+ defaultRuntime.log(theme.warn(`Daemon restart failed: ${String(err)}`));
1210
+ defaultRuntime.log(theme.muted(`You may need to restart the service manually: ${replaceCliName(formatCliCommand("openclaw gateway restart"), CLI_NAME)}`));
1211
+ }
1212
+ }
1213
+ return;
1214
+ }
1215
+ if (!params.opts.json) {
1216
+ defaultRuntime.log("");
1217
+ if (params.result.mode === "npm" || params.result.mode === "pnpm") defaultRuntime.log(theme.muted(`Tip: Run \`${replaceCliName(formatCliCommand("openclaw doctor"), CLI_NAME)}\`, then \`${replaceCliName(formatCliCommand("openclaw gateway restart"), CLI_NAME)}\` to apply updates to a running gateway.`));
1218
+ else defaultRuntime.log(theme.muted(`Tip: Run \`${replaceCliName(formatCliCommand("openclaw gateway restart"), CLI_NAME)}\` to apply updates to a running gateway.`));
1219
+ }
1220
+ }
1221
+ async function updateCommand(opts) {
1222
+ suppressDeprecations();
1223
+ const invocationCwd = tryResolveInvocationCwd();
1224
+ const timeoutMs = parseTimeoutMsOrExit(opts.timeout);
1225
+ const shouldRestart = opts.restart !== false;
1226
+ if (timeoutMs === null) return;
1227
+ const root = await resolveUpdateRoot();
1228
+ const updateStatus = await checkUpdateStatus({
1229
+ root,
1230
+ timeoutMs: timeoutMs ?? 3500,
1231
+ fetchGit: false,
1232
+ includeRegistry: false
1233
+ });
1234
+ const configSnapshot = await readConfigFileSnapshot();
1235
+ const storedChannel = configSnapshot.valid ? normalizeUpdateChannel(configSnapshot.config.update?.channel) : null;
1236
+ const requestedChannel = normalizeUpdateChannel(opts.channel);
1237
+ if (opts.channel && !requestedChannel) {
1238
+ defaultRuntime.error(`--channel must be "stable", "beta", or "dev" (got "${opts.channel}")`);
1239
+ defaultRuntime.exit(1);
1240
+ return;
1241
+ }
1242
+ if (opts.channel && !configSnapshot.valid) {
1243
+ const issues = formatConfigIssueLines(configSnapshot.issues, "-");
1244
+ defaultRuntime.error(["Config is invalid; cannot set update channel.", ...issues].join("\n"));
1245
+ defaultRuntime.exit(1);
1246
+ return;
1247
+ }
1248
+ const installKind = updateStatus.installKind;
1249
+ const switchToGit = requestedChannel === "dev" && installKind !== "git";
1250
+ const switchToPackage = requestedChannel !== null && requestedChannel !== "dev" && installKind === "git";
1251
+ const updateInstallKind = switchToGit ? "git" : switchToPackage ? "package" : installKind;
1252
+ const channel = requestedChannel ?? storedChannel ?? (updateInstallKind === "git" ? DEFAULT_GIT_CHANNEL : DEFAULT_PACKAGE_CHANNEL);
1253
+ const explicitTag = normalizeTag(opts.tag);
1254
+ let tag = explicitTag ?? channelToNpmTag(channel);
1255
+ let currentVersion = null;
1256
+ let targetVersion = null;
1257
+ let downgradeRisk = false;
1258
+ let fallbackToLatest = false;
1259
+ let packageInstallSpec = null;
1260
+ if (updateInstallKind !== "git") {
1261
+ currentVersion = switchToPackage ? null : await readPackageVersion(root);
1262
+ if (explicitTag) targetVersion = await resolveTargetVersion(tag, timeoutMs);
1263
+ else targetVersion = await resolveNpmChannelTag({
1264
+ channel,
1265
+ timeoutMs
1266
+ }).then((resolved) => {
1267
+ tag = resolved.tag;
1268
+ fallbackToLatest = channel === "beta" && resolved.tag === "latest";
1269
+ return resolved.version;
1270
+ });
1271
+ const cmp = currentVersion && targetVersion ? compareSemverStrings(currentVersion, targetVersion) : null;
1272
+ downgradeRisk = canResolveRegistryVersionForPackageTarget(tag) && !fallbackToLatest && currentVersion != null && (targetVersion == null || cmp != null && cmp > 0);
1273
+ packageInstallSpec = resolveGlobalInstallSpec({
1274
+ packageName: DEFAULT_PACKAGE_NAME,
1275
+ tag,
1276
+ env: process.env
1277
+ });
1278
+ }
1279
+ if (opts.dryRun) {
1280
+ let mode = "unknown";
1281
+ if (updateInstallKind === "git") mode = "git";
1282
+ else if (updateInstallKind === "package") mode = await resolveGlobalManager({
1283
+ root,
1284
+ installKind,
1285
+ timeoutMs: timeoutMs ?? 20 * 6e4
1286
+ });
1287
+ const actions = [];
1288
+ if (requestedChannel && requestedChannel !== storedChannel) actions.push(`Persist update.channel=${requestedChannel} in config`);
1289
+ if (switchToGit) actions.push("Switch install mode from package to git checkout (dev channel)");
1290
+ else if (switchToPackage) actions.push(`Switch install mode from git to package manager (${mode})`);
1291
+ else if (updateInstallKind === "git") actions.push(`Run git update flow on channel ${channel} (fetch/rebase/build/doctor)`);
1292
+ else actions.push(`Run global package manager update with spec ${packageInstallSpec ?? tag}`);
1293
+ actions.push("Run plugin update sync after core update");
1294
+ actions.push("Refresh shell completion cache (if needed)");
1295
+ actions.push(shouldRestart ? "Restart gateway service and run doctor checks" : "Skip restart (because --no-restart is set)");
1296
+ const notes = [];
1297
+ if (opts.tag && updateInstallKind === "git") notes.push("--tag applies to npm installs only; git updates ignore it.");
1298
+ if (fallbackToLatest) notes.push("Beta channel resolves to latest for this run (fallback).");
1299
+ if (explicitTag && !canResolveRegistryVersionForPackageTarget(tag)) notes.push("Non-registry package specs skip npm version lookup and downgrade previews.");
1300
+ printDryRunPreview({
1301
+ dryRun: true,
1302
+ root,
1303
+ installKind,
1304
+ mode,
1305
+ updateInstallKind,
1306
+ switchToGit,
1307
+ switchToPackage,
1308
+ restart: shouldRestart,
1309
+ requestedChannel,
1310
+ storedChannel,
1311
+ effectiveChannel: channel,
1312
+ tag: packageInstallSpec ?? tag,
1313
+ currentVersion,
1314
+ targetVersion,
1315
+ downgradeRisk,
1316
+ actions,
1317
+ notes
1318
+ }, Boolean(opts.json));
1319
+ return;
1320
+ }
1321
+ if (downgradeRisk && !opts.yes) {
1322
+ if (!process.stdin.isTTY || opts.json) {
1323
+ defaultRuntime.error(["Downgrade confirmation required.", "Downgrading can break configuration. Re-run in a TTY to confirm."].join("\n"));
1324
+ defaultRuntime.exit(1);
1325
+ return;
1326
+ }
1327
+ const targetLabel = targetVersion ?? `${tag} (unknown)`;
1328
+ const ok = await confirm({
1329
+ message: stylePromptMessage(`Downgrading from ${currentVersion} to ${targetLabel} can break configuration. Continue?`),
1330
+ initialValue: false
1331
+ });
1332
+ if (isCancel(ok) || !ok) {
1333
+ if (!opts.json) defaultRuntime.log(theme.muted("Update cancelled."));
1334
+ defaultRuntime.exit(0);
1335
+ return;
1336
+ }
1337
+ }
1338
+ if (updateInstallKind === "git" && opts.tag && !opts.json) defaultRuntime.log(theme.muted("Note: --tag applies to npm installs only; git updates ignore it."));
1339
+ const showProgress = !opts.json && process.stdout.isTTY;
1340
+ if (!opts.json) {
1341
+ defaultRuntime.log(theme.heading("Updating OpenClaw..."));
1342
+ defaultRuntime.log("");
1343
+ }
1344
+ const { progress, stop } = createUpdateProgress(showProgress);
1345
+ const startedAt = Date.now();
1346
+ let restartScriptPath = null;
1347
+ let refreshGatewayServiceEnv$1 = false;
1348
+ const gatewayPort = resolveGatewayPort(configSnapshot.valid ? configSnapshot.config : void 0, process.env);
1349
+ if (shouldRestart) try {
1350
+ if (await resolveGatewayService().isLoaded({ env: process.env })) {
1351
+ restartScriptPath = await prepareRestartScript(process.env, gatewayPort);
1352
+ refreshGatewayServiceEnv$1 = true;
1353
+ }
1354
+ } catch {}
1355
+ const result = updateInstallKind === "package" ? await runPackageInstallUpdate({
1356
+ root,
1357
+ installKind,
1358
+ tag,
1359
+ timeoutMs: timeoutMs ?? 20 * 6e4,
1360
+ startedAt,
1361
+ progress
1362
+ }) : await runGitUpdate({
1363
+ root,
1364
+ switchToGit,
1365
+ installKind,
1366
+ timeoutMs,
1367
+ startedAt,
1368
+ progress,
1369
+ channel,
1370
+ tag,
1371
+ showProgress,
1372
+ opts,
1373
+ stop
1374
+ });
1375
+ stop();
1376
+ printResult(result, {
1377
+ ...opts,
1378
+ hideSteps: showProgress
1379
+ });
1380
+ if (result.status === "error") {
1381
+ defaultRuntime.exit(1);
1382
+ return;
1383
+ }
1384
+ if (result.status === "skipped") {
1385
+ if (result.reason === "dirty") defaultRuntime.log(theme.warn("Skipped: working directory has uncommitted changes. Commit or stash them first."));
1386
+ if (result.reason === "not-git-install") {
1387
+ defaultRuntime.log(theme.warn(`Skipped: this OpenClaw install isn't a git checkout, and the package manager couldn't be detected. Update via your package manager, then run \`${replaceCliName(formatCliCommand("openclaw doctor"), CLI_NAME)}\` and \`${replaceCliName(formatCliCommand("openclaw gateway restart"), CLI_NAME)}\`.`));
1388
+ defaultRuntime.log(theme.muted(`Examples: \`${replaceCliName("npm i -g openclaw@latest", CLI_NAME)}\` or \`${replaceCliName("pnpm add -g openclaw@latest", CLI_NAME)}\``));
1389
+ }
1390
+ defaultRuntime.exit(0);
1391
+ return;
1392
+ }
1393
+ let postUpdateConfigSnapshot = configSnapshot;
1394
+ if (requestedChannel && configSnapshot.valid && requestedChannel !== storedChannel) {
1395
+ const next = {
1396
+ ...configSnapshot.config,
1397
+ update: {
1398
+ ...configSnapshot.config.update,
1399
+ channel: requestedChannel
1400
+ }
1401
+ };
1402
+ await writeConfigFile(next);
1403
+ postUpdateConfigSnapshot = {
1404
+ ...configSnapshot,
1405
+ parsed: next,
1406
+ resolved: next,
1407
+ config: next
1408
+ };
1409
+ if (!opts.json) defaultRuntime.log(theme.muted(`Update channel set to ${requestedChannel}.`));
1410
+ }
1411
+ await updatePluginsAfterCoreUpdate({
1412
+ root,
1413
+ channel,
1414
+ configSnapshot: postUpdateConfigSnapshot,
1415
+ opts
1416
+ });
1417
+ await tryWriteCompletionCache(root, Boolean(opts.json));
1418
+ await tryInstallShellCompletion({
1419
+ jsonMode: Boolean(opts.json),
1420
+ skipPrompt: Boolean(opts.yes)
1421
+ });
1422
+ await maybeRestartService({
1423
+ shouldRestart,
1424
+ result,
1425
+ opts,
1426
+ refreshServiceEnv: refreshGatewayServiceEnv$1,
1427
+ gatewayPort,
1428
+ restartScriptPath,
1429
+ invocationCwd
1430
+ });
1431
+ if (!opts.json) defaultRuntime.log(theme.muted(pickUpdateQuip()));
1432
+ }
1433
+
1434
+ //#endregion
1435
+ //#region src/cli/update-cli/wizard.ts
1436
+ async function updateWizardCommand(opts = {}) {
1437
+ if (!process.stdin.isTTY) {
1438
+ defaultRuntime.error("Update wizard requires a TTY. Use `openclaw update --channel <stable|beta|dev>` instead.");
1439
+ defaultRuntime.exit(1);
1440
+ return;
1441
+ }
1442
+ const timeoutMs = parseTimeoutMsOrExit(opts.timeout);
1443
+ if (timeoutMs === null) return;
1444
+ const root = await resolveUpdateRoot();
1445
+ const [updateStatus, configSnapshot] = await Promise.all([checkUpdateStatus({
1446
+ root,
1447
+ timeoutMs: timeoutMs ?? 3500,
1448
+ fetchGit: false,
1449
+ includeRegistry: false
1450
+ }), readConfigFileSnapshot()]);
1451
+ const channelInfo = resolveEffectiveUpdateChannel({
1452
+ configChannel: configSnapshot.valid ? normalizeUpdateChannel(configSnapshot.config.update?.channel) : null,
1453
+ installKind: updateStatus.installKind,
1454
+ git: updateStatus.git ? {
1455
+ tag: updateStatus.git.tag,
1456
+ branch: updateStatus.git.branch
1457
+ } : void 0
1458
+ });
1459
+ const channelLabel = formatUpdateChannelLabel({
1460
+ channel: channelInfo.channel,
1461
+ source: channelInfo.source,
1462
+ gitTag: updateStatus.git?.tag ?? null,
1463
+ gitBranch: updateStatus.git?.branch ?? null
1464
+ });
1465
+ const pickedChannel = await selectStyled({
1466
+ message: "Update channel",
1467
+ options: [
1468
+ {
1469
+ value: "keep",
1470
+ label: `Keep current (${channelInfo.channel})`,
1471
+ hint: channelLabel
1472
+ },
1473
+ {
1474
+ value: "stable",
1475
+ label: "Stable",
1476
+ hint: "Tagged releases (npm latest)"
1477
+ },
1478
+ {
1479
+ value: "beta",
1480
+ label: "Beta",
1481
+ hint: "Prereleases (npm beta)"
1482
+ },
1483
+ {
1484
+ value: "dev",
1485
+ label: "Dev",
1486
+ hint: "Git main"
1487
+ }
1488
+ ],
1489
+ initialValue: "keep"
1490
+ });
1491
+ if (isCancel(pickedChannel)) {
1492
+ defaultRuntime.log(theme.muted("Update cancelled."));
1493
+ defaultRuntime.exit(0);
1494
+ return;
1495
+ }
1496
+ const requestedChannel = pickedChannel === "keep" ? null : pickedChannel;
1497
+ if (requestedChannel === "dev" && updateStatus.installKind !== "git") {
1498
+ const gitDir = resolveGitInstallDir();
1499
+ if (!await isGitCheckout(gitDir)) {
1500
+ if (await pathExists(gitDir)) {
1501
+ if (!await isEmptyDir(gitDir)) {
1502
+ defaultRuntime.error(`OPENCLAW_GIT_DIR points at a non-git directory: ${gitDir}. Set OPENCLAW_GIT_DIR to an empty folder or an openclaw checkout.`);
1503
+ defaultRuntime.exit(1);
1504
+ return;
1505
+ }
1506
+ }
1507
+ const ok = await confirm({
1508
+ message: stylePromptMessage(`Create a git checkout at ${gitDir}? (override via OPENCLAW_GIT_DIR)`),
1509
+ initialValue: true
1510
+ });
1511
+ if (isCancel(ok) || !ok) {
1512
+ defaultRuntime.log(theme.muted("Update cancelled."));
1513
+ defaultRuntime.exit(0);
1514
+ return;
1515
+ }
1516
+ }
1517
+ }
1518
+ const restart = await confirm({
1519
+ message: stylePromptMessage("Restart the gateway service after update?"),
1520
+ initialValue: true
1521
+ });
1522
+ if (isCancel(restart)) {
1523
+ defaultRuntime.log(theme.muted("Update cancelled."));
1524
+ defaultRuntime.exit(0);
1525
+ return;
1526
+ }
1527
+ try {
1528
+ await updateCommand({
1529
+ channel: requestedChannel ?? void 0,
1530
+ restart: Boolean(restart),
1531
+ timeout: opts.timeout
1532
+ });
1533
+ } catch (err) {
1534
+ defaultRuntime.error(String(err));
1535
+ defaultRuntime.exit(1);
1536
+ }
1537
+ }
1538
+
1539
+ //#endregion
1540
+ //#region src/cli/update-cli.ts
1541
+ function inheritedUpdateJson(command) {
1542
+ return Boolean(inheritOptionFromParent(command, "json"));
1543
+ }
1544
+ function inheritedUpdateTimeout(opts, command) {
1545
+ const timeout = opts.timeout;
1546
+ if (timeout) return timeout;
1547
+ return inheritOptionFromParent(command, "timeout");
1548
+ }
1549
+ function registerUpdateCli(program) {
1550
+ program.enablePositionalOptions();
1551
+ const update = program.command("update").description("Update OpenClaw and inspect update channel status").option("--json", "Output result as JSON", false).option("--no-restart", "Skip restarting the gateway service after a successful update").option("--dry-run", "Preview update actions without making changes", false).option("--channel <stable|beta|dev>", "Persist update channel (git + npm)").option("--tag <dist-tag|version|spec>", "Override the package target for this update (dist-tag, version, or package spec)").option("--timeout <seconds>", "Timeout for each update step in seconds (default: 1200)").option("--yes", "Skip confirmation prompts (non-interactive)", false).addHelpText("after", () => {
1552
+ const fmtExamples = [
1553
+ ["openclaw update", "Update a source checkout (git)"],
1554
+ ["openclaw update --channel beta", "Switch to beta channel (git + npm)"],
1555
+ ["openclaw update --channel dev", "Switch to dev channel (git + npm)"],
1556
+ ["openclaw update --tag beta", "One-off update to a dist-tag or version"],
1557
+ ["openclaw update --tag main", "One-off package install from GitHub main"],
1558
+ ["openclaw update --dry-run", "Preview actions without changing anything"],
1559
+ ["openclaw update --no-restart", "Update without restarting the service"],
1560
+ ["openclaw update --json", "Output result as JSON"],
1561
+ ["openclaw update --yes", "Non-interactive (accept downgrade prompts)"],
1562
+ ["openclaw update wizard", "Interactive update wizard"],
1563
+ ["openclaw --update", "Shorthand for openclaw update"]
1564
+ ].map(([cmd, desc]) => ` ${theme.command(cmd)} ${theme.muted(`# ${desc}`)}`).join("\n");
1565
+ return `
1566
+ ${theme.heading("What this does:")}
1567
+ - Git checkouts: fetches, rebases, installs deps, builds, and runs doctor
1568
+ - npm installs: updates via detected package manager
1569
+
1570
+ ${theme.heading("Switch channels:")}
1571
+ - Use --channel stable|beta|dev to persist the update channel in config
1572
+ - Run openclaw update status to see the active channel and source
1573
+ - Use --tag <dist-tag|version|spec> for a one-off package update without persisting
1574
+
1575
+ ${theme.heading("Non-interactive:")}
1576
+ - Use --yes to accept downgrade prompts
1577
+ - Combine with --channel/--tag/--restart/--json/--timeout as needed
1578
+ - Use --dry-run to preview actions without writing config/installing/restarting
1579
+
1580
+ ${theme.heading("Examples:")}
1581
+ ${fmtExamples}
1582
+
1583
+ ${theme.heading("Notes:")}
1584
+ - Switch channels with --channel stable|beta|dev
1585
+ - For global installs: auto-updates via detected package manager when possible (see docs/install/updating.md)
1586
+ - Downgrades require confirmation (can break configuration)
1587
+ - Skips update if the working directory has uncommitted changes
1588
+
1589
+ ${theme.muted("Docs:")} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/update")}`;
1590
+ }).action(async (opts) => {
1591
+ try {
1592
+ await updateCommand({
1593
+ json: Boolean(opts.json),
1594
+ restart: Boolean(opts.restart),
1595
+ dryRun: Boolean(opts.dryRun),
1596
+ channel: opts.channel,
1597
+ tag: opts.tag,
1598
+ timeout: opts.timeout,
1599
+ yes: Boolean(opts.yes)
1600
+ });
1601
+ } catch (err) {
1602
+ defaultRuntime.error(String(err));
1603
+ defaultRuntime.exit(1);
1604
+ }
1605
+ });
1606
+ update.command("wizard").description("Interactive update wizard").option("--timeout <seconds>", "Timeout for each update step in seconds (default: 1200)").addHelpText("after", `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/update")}\n`).action(async (opts, command) => {
1607
+ try {
1608
+ await updateWizardCommand({ timeout: inheritedUpdateTimeout(opts, command) });
1609
+ } catch (err) {
1610
+ defaultRuntime.error(String(err));
1611
+ defaultRuntime.exit(1);
1612
+ }
1613
+ });
1614
+ update.command("status").description("Show update channel and version status").option("--json", "Output result as JSON", false).option("--timeout <seconds>", "Timeout for update checks in seconds (default: 3)").addHelpText("after", () => `\n${theme.heading("Examples:")}\n${formatHelpExamples([
1615
+ ["openclaw update status", "Show channel + version status."],
1616
+ ["openclaw update status --json", "JSON output."],
1617
+ ["openclaw update status --timeout 10", "Custom timeout."]
1618
+ ])}\n\n${theme.heading("Notes:")}\n${theme.muted("- Shows current update channel (stable/beta/dev) and source")}\n${theme.muted("- Includes git tag/branch/SHA for source checkouts")}\n\n${theme.muted("Docs:")} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/update")}`).action(async (opts, command) => {
1619
+ try {
1620
+ await updateStatusCommand({
1621
+ json: Boolean(opts.json) || inheritedUpdateJson(command),
1622
+ timeout: inheritedUpdateTimeout(opts, command)
1623
+ });
1624
+ } catch (err) {
1625
+ defaultRuntime.error(String(err));
1626
+ defaultRuntime.exit(1);
1627
+ }
1628
+ });
1629
+ }
1630
+
1631
+ //#endregion
1632
+ export { registerUpdateCli };