@heretek-ai/openclaw 2026.3.27 → 2026.3.29

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.
@@ -0,0 +1,685 @@
1
+ import "./chunk-CQFkT1cY.mjs";
2
+ import "./redact-CtGOTRBK.mjs";
3
+ import "./errors-CbvpN2RP.mjs";
4
+ import "./logger-vRSRu9wD.mjs";
5
+ import { _ as resolveStateDir, h as resolveOAuthDir, i as isNixMode, o as resolveConfigPath, 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 { _ as resolveHomeDir } from "./utils-Dc9DiBqf.mjs";
15
+ import { t as formatDocsLink } from "./links-BNNF54ea.mjs";
16
+ import "./paths-B5L5nZjW.mjs";
17
+ import "./auth-profiles-DZOU8QNa.mjs";
18
+ import "./agent-scope-CnAwGoC2.mjs";
19
+ import "./boundary-path-DnlNnNbU.mjs";
20
+ import "./boundary-file-read-BB4JbZzx.mjs";
21
+ import "./logger-DWOgrQoS.mjs";
22
+ import { n as runCommandWithTimeout } from "./exec-DX0zVVG7.mjs";
23
+ import "./openclaw-root-CSfnLaqO.mjs";
24
+ import "./workspace-CoFl73GV.mjs";
25
+ import "./model-selection-BJk_hQeE.mjs";
26
+ import { d as readConfigFileSnapshot, s as loadConfig } from "./io-CDQGJKjg.mjs";
27
+ import "./shell-env-CP5vTYhw.mjs";
28
+ import "./safe-text-Bsdm3bQS.mjs";
29
+ import "./version-Ckv-IbvB.mjs";
30
+ import "./env-substitution-DGlYO8jV.mjs";
31
+ import "./scan-paths-ahOy4FCQ.mjs";
32
+ import "./includes-DcO1JxKG.mjs";
33
+ import "./zod-schema.providers-core-CjdAU1TY.mjs";
34
+ import "./legacy-web-search-B1O8hiGy.mjs";
35
+ import "./schema-validator-BOH34EXk.mjs";
36
+ import "./registry-DBJv0dvl.mjs";
37
+ import "./config-state-kmbzTT63.mjs";
38
+ import "./min-host-version-EA11e8I5.mjs";
39
+ import "./manifest-registry-dO1qi1iI.mjs";
40
+ import "./runtime-guard-CWHkkioa.mjs";
41
+ import "./avatar-policy-uRVtZ7lJ.mjs";
42
+ import "./ip-BtMd9ssR.mjs";
43
+ import "./zod-schema.agent-runtime-BtGT59eP.mjs";
44
+ import "./zod-schema.core-CMT7g7UX.mjs";
45
+ import "./zod-schema.channels-BAG3dUtC.mjs";
46
+ import "./zod-schema.providers-whatsapp-qnpQepaf.mjs";
47
+ import "./config-Bhjk4Vel.mjs";
48
+ import "./process-scoped-map-BmLEe6nP.mjs";
49
+ import "./file-lock-hqfE8fCo.mjs";
50
+ import "./file-lock-CjVc7LJY.mjs";
51
+ import "./audit-fs-kb-rv_ZT.mjs";
52
+ import "./shared-VxKfp8Uy.mjs";
53
+ import "./resolve-DI6cKS4v.mjs";
54
+ import "./chutes-oauth-BLrDl-qw.mjs";
55
+ import "./json-file-ZNWqd95a.mjs";
56
+ import "./profiles-CqdEUxnl.mjs";
57
+ import "./redact-identifier-DTBisVz0.mjs";
58
+ import "./cli-name-lEyorNIN.mjs";
59
+ import { t as formatCliCommand } from "./command-format-D1DrcTDP.mjs";
60
+ import "./daemon-install-plan.shared-MtLyPLVq.mjs";
61
+ import "./runtime-paths-qezFSLu3.mjs";
62
+ import "./gateway-install-token-3hijf3Zd.mjs";
63
+ import "./prompt-hGCcgj-D.mjs";
64
+ import "./tailscale-DZJRdd6v.mjs";
65
+ import "./secret-equal-DcNDdUBf.mjs";
66
+ import "./tailnet-Bc7IPWjH.mjs";
67
+ import "./net-OJiOmwY1.mjs";
68
+ import "./auth-C5eSR-m1.mjs";
69
+ import { d as readGatewayTokenEnv } from "./credentials-DTsHVnAc.mjs";
70
+ import "./message-channel-DCt8BIP7.mjs";
71
+ import "./store-B0V1qm_-.mjs";
72
+ import "./runtime-a4e8n7tq.mjs";
73
+ import "./registry-9YpVWxKb.mjs";
74
+ import "./plugins-D8oapapr.mjs";
75
+ import "./sessions-CYgBPqrc.mjs";
76
+ import "./paths-CGxgQvpf.mjs";
77
+ import "./types-DoAKcnWC.mjs";
78
+ import "./session-write-lock-DE8KASyZ.mjs";
79
+ import "./json-files-BcpXnc9i.mjs";
80
+ import "./delivery-info-CGNfeMd6.mjs";
81
+ import "./method-scopes-hu-4urbi.mjs";
82
+ import "./call-CcXWxOVG.mjs";
83
+ import "./ws-Dv5Afaxu.mjs";
84
+ import "./control-ui-shared-Dhzx9It_.mjs";
85
+ import { d as openUrl, g as resolveControlUiLinks, i as detectBrowserOpenSupport, o as formatControlUiSshHint } from "./onboard-helpers-C5GCWoDO.mjs";
86
+ import "./wsl-BW8_A9_i.mjs";
87
+ import { n as stylePromptMessage, r as stylePromptTitle, t as stylePromptHint } from "./prompt-style-Dua6SIJh.mjs";
88
+ import "./ports-lsof-D1pMGdtZ.mjs";
89
+ import "./restart-stale-pids-DpJ5KhNO.mjs";
90
+ import "./runtime-parse-Dv1L_ID-.mjs";
91
+ import "./launchd-CFtZl6rs.mjs";
92
+ import { n as resolveGatewayService } from "./service-eLNsotU2.mjs";
93
+ import "./kill-tree-C7sbsfc4.mjs";
94
+ import "./ports-0KspCIU9.mjs";
95
+ import "./ports-probe-CW8QePv6.mjs";
96
+ import "./systemd-B1Tl3zeB.mjs";
97
+ import "./systemd-hints-CLxWQM3C.mjs";
98
+ import "./logging-CO6W9Zis.mjs";
99
+ import "./issue-format-C5C4zFWv.mjs";
100
+ import "./diagnostics-CXwZ82ru.mjs";
101
+ import "./inspect-CBu749pN.mjs";
102
+ import "./progress-BxDdsPK3.mjs";
103
+ import "./tokens-CIQuw4-h.mjs";
104
+ import "./heartbeat-B3sryw3e.mjs";
105
+ import "./registry-CFSnIRx_.mjs";
106
+ import "./internal-hooks-VOrTrqjW.mjs";
107
+ import "./secure-random-Cta_A2w5.mjs";
108
+ import "./multimodal-B5--YVtx.mjs";
109
+ import "./memory-search-CI34ggcG.mjs";
110
+ import "./embeddings-CwDz1Jy9.mjs";
111
+ import "./api-key-rotation-CuLnDVwp.mjs";
112
+ import "./provider-runtime-D7FpDXts.mjs";
113
+ import "./providers.runtime-ReQb49ui.mjs";
114
+ import "./accounts-DFOEzDJ7.mjs";
115
+ import "./loader-BIAV9Iig.mjs";
116
+ import "./config-presence-DzY-U322.mjs";
117
+ import "./types-BaXbwBIP.mjs";
118
+ import "./hook-runner-global-z_Icpwvo.mjs";
119
+ import "./session-binding-service-Bmkk4TGJ.mjs";
120
+ import "./conversation-binding-elBCYjlA.mjs";
121
+ import "./sdk-alias-C5qDxQv2.mjs";
122
+ import "./anthropic-vertex-provider-Davkw2Ua.mjs";
123
+ import "./provider-env-vars-BvHq384O.mjs";
124
+ import "./model-auth-markers-D9P0hXHx.mjs";
125
+ import "./model-auth-env-D5wfS1i-.mjs";
126
+ import "./model-auth-CitpD6LX.mjs";
127
+ import "./ssrf-DfOlyZAO.mjs";
128
+ import "./fetch-guard-BNr7RxWd.mjs";
129
+ import "./provider-model-allowlist-Bz7SYU4G.mjs";
130
+ import "./provider-model-defaults-CPQyoqIg.mjs";
131
+ import "./mime-CbiZRMeN.mjs";
132
+ import "./backend-config-DaJEmaVa.mjs";
133
+ import "./config-schema-BBMwxQY-.mjs";
134
+ import "./helpers-DxddeIS7.mjs";
135
+ import "./channel-plugin-common-DFFE5uzd.mjs";
136
+ import "./path-safety-CTs-ZpWF.mjs";
137
+ import "./fs-safe-DvWloqcG.mjs";
138
+ import "./path-alias-guards-Dq2I3ITG.mjs";
139
+ import "./status-helpers-BmYd-e9Q.mjs";
140
+ import "./accounts-BI2OGfP5.mjs";
141
+ import "./format-VDvpfVJp.mjs";
142
+ import "./api-Ciu0IVWd.mjs";
143
+ import "./telegram-DZaimX0b.mjs";
144
+ import "./poll-params-DWHBuRx9.mjs";
145
+ import "./token-BNIxZjju.mjs";
146
+ import "./sticker-cache-DJkSXsnY.mjs";
147
+ import "./status-issues-BnLYwoca.mjs";
148
+ import "./fetch-BI0FMqrI.mjs";
149
+ import "./update-offset-store-3hPuz7sI.mjs";
150
+ import "./api-CE6hZv7r.mjs";
151
+ import "./audit-BkbWkLoN.mjs";
152
+ import "./runtime-api-CLv8kHRq.mjs";
153
+ import "./bootstrap-budget-B-IQwkE2.mjs";
154
+ import "./pi-embedded-helpers-DTWSmIk7.mjs";
155
+ import "./tool-catalog-DblrqUGw.mjs";
156
+ import "./config-BT5BZCwj.mjs";
157
+ import "./runtime-status-BCn1Ito_.mjs";
158
+ import "./tool-images-DMUfrdai.mjs";
159
+ import "./image-ops-CabelrfU.mjs";
160
+ import "./thinking-DvqE1iCX.mjs";
161
+ import "./models-config-CSUHhxgP.mjs";
162
+ import "./provider-catalog-BDbid2d6.mjs";
163
+ import "./models-config.providers-BGCDFJHy.mjs";
164
+ import "./models-config.providers.discovery-BjIw3Rrd.mjs";
165
+ import "./bundle-lsp-DyU7-zol.mjs";
166
+ import "./exec-approvals-allowlist-DinDB1Z8.mjs";
167
+ import "./exec-safe-bin-runtime-policy-CyPJcb_7.mjs";
168
+ import "./local-file-access-Cloywpfb.mjs";
169
+ import "./sandbox-paths-BltFttSo.mjs";
170
+ import "./path-prepend-B3TwK2p2.mjs";
171
+ import "./sandbox-B1Fh0xU6.mjs";
172
+ import "./target-registry-B8jHfrX7.mjs";
173
+ import "./runtime-web-tools-C1rIl936.mjs";
174
+ import "./web-search-providers.runtime-4epgumbu.mjs";
175
+ import "./image-generation-provider-6Bn9TpiN.mjs";
176
+ import "./web-search-providers-QuPYL01Y.mjs";
177
+ import "./client-fetch-BLpjnLN8.mjs";
178
+ import { n as resolveConfiguredSecretInputWithFallback } from "./resolve-configured-secret-input-string-BG1RVESA.mjs";
179
+ import "./config-BBc-AI9Q.mjs";
180
+ import "./store-CgM2S6uo.mjs";
181
+ import "./stagger-DL_NciFx.mjs";
182
+ import "./restart-sentinel-BkRzS474.mjs";
183
+ import "./model-catalog-BQE3APtu.mjs";
184
+ import "./command-secret-gateway-Uq9_F22I.mjs";
185
+ import "./command-secret-targets-DskfH4zj.mjs";
186
+ import "./bindings-B0u6nL3P.mjs";
187
+ import "./plugin-auto-enable-z42_IiV3.mjs";
188
+ import "./accounts-BuIAUa8N.mjs";
189
+ import "./account-inspect-MeUCOkS_.mjs";
190
+ import "./runtime-api-C0iKN3es.mjs";
191
+ import "./send-BKtMg4M2.mjs";
192
+ import "./mentions-zhy7pfW_.mjs";
193
+ import "./api-DXEplirz.mjs";
194
+ import "./allow-list-BmsN9jdO.mjs";
195
+ import "./handle-action-QiVBVVNQ.mjs";
196
+ import "./status-issues-BwaBWQvq.mjs";
197
+ import "./normalize-Bnt1XiaY.mjs";
198
+ import "./pluralkit-BrMYZvsn.mjs";
199
+ import "./api-BcbhfW_y.mjs";
200
+ import "./send-DFvZt_SI.mjs";
201
+ import "./threading-tool-context-AJ99m0j4.mjs";
202
+ import "./sent-thread-cache-CS98UTLj.mjs";
203
+ import "./targets-XG-6x8Dr.mjs";
204
+ import "./api-s9vnTb6r.mjs";
205
+ import "./pairing-store-CZ8m5dqj.mjs";
206
+ import "./json-store-79zyIPBO.mjs";
207
+ import "./config-eval-BRFipjhU.mjs";
208
+ import "./frontmatter-DtyHHNb1.mjs";
209
+ import "./env-overrides-CiAKRDlo.mjs";
210
+ import "./skills-B94iGCMk.mjs";
211
+ import "./windows-spawn-BIgkarI-.mjs";
212
+ import "./docker-RHNUruWe.mjs";
213
+ import "./ssh-tunnel-rTW1iTuR.mjs";
214
+ import "./server-middleware-CgGy22IV.mjs";
215
+ import "./parse-json-compat-C8iu7A7C.mjs";
216
+ import "./logging-CcQ-gmqC.mjs";
217
+ import "./store-BoqljpMQ.mjs";
218
+ import "./read-only-account-inspect-Duuceu1W.mjs";
219
+ import "./dm-policy-shared-CnmKIKQO.mjs";
220
+ import { a as removePath, i as listAgentSessionDirs, o as removeStateAndLinkedPaths, r as buildCleanupPlan, s as removeWorkspaceDirs } from "./backup-create-CRi_Wc9K.mjs";
221
+ import "./thread-bindings-runtime-DZHuPlAx.mjs";
222
+ import "./matrix-migration-snapshot-ChWL_Ldz.mjs";
223
+ import "./account-resolution-B5v6WlRC.mjs";
224
+ import "./skills-status-DjVDxLj2.mjs";
225
+ import "./status-Baz1y8H2.mjs";
226
+ import "./auth-health-BcpqSZL0.mjs";
227
+ import { n as runCommandWithRuntime } from "./cli-utils-DA6vWpDg.mjs";
228
+ import "./note-CaQ2HD-A.mjs";
229
+ import "./completion-cli-B8M--XTS.mjs";
230
+ import "./register.subclis-CVkk-8A3.mjs";
231
+ import "./command-registry-B9Orjysx.mjs";
232
+ import "./program-context-9v4H9od4.mjs";
233
+ import "./heartbeat-summary-CUbo9b9F.mjs";
234
+ import "./health-MT8VazgK.mjs";
235
+ import "./control-ui-assets-CW49D85b.mjs";
236
+ import "./server-startup-matrix-migration-BYVP8K4t.mjs";
237
+ import "./update-check-CinGDRx-.mjs";
238
+ import "./channels-status-issues-DxKcDmEl.mjs";
239
+ import "./provider-auth-guidance-CQF0XUYa.mjs";
240
+ import "./systemd-linger-CMHj3APL.mjs";
241
+ import "./health-format-DnRUP-NJ.mjs";
242
+ import { n as doctorCommand, t as selectStyled } from "./prompt-select-styled-CxHtgKpu.mjs";
243
+ import "./doctor-completion-CyOOf-GM.mjs";
244
+ import "./doctor-config-preflight-BgQMWEcI.mjs";
245
+ import "./channel-account-context-M7MFNDNz.mjs";
246
+ import "./doctor-state-migrations-Bbyafdyk.mjs";
247
+ import "./provider-openai-codex-oauth-tls-CVsiK51M.mjs";
248
+ import path from "node:path";
249
+ import { cancel, confirm, isCancel, multiselect } from "@clack/prompts";
250
+
251
+ //#region src/infra/clipboard.ts
252
+ async function copyToClipboard(value) {
253
+ for (const attempt of [
254
+ { argv: ["pbcopy"] },
255
+ { argv: [
256
+ "xclip",
257
+ "-selection",
258
+ "clipboard"
259
+ ] },
260
+ { argv: ["wl-copy"] },
261
+ { argv: ["clip.exe"] },
262
+ { argv: [
263
+ "powershell",
264
+ "-NoProfile",
265
+ "-Command",
266
+ "Set-Clipboard"
267
+ ] }
268
+ ]) try {
269
+ const result = await runCommandWithTimeout(attempt.argv, {
270
+ timeoutMs: 3e3,
271
+ input: value
272
+ });
273
+ if (result.code === 0 && !result.killed) return true;
274
+ } catch {}
275
+ return false;
276
+ }
277
+
278
+ //#endregion
279
+ //#region src/commands/dashboard.ts
280
+ async function resolveDashboardToken(cfg, env = process.env) {
281
+ const resolved = await resolveConfiguredSecretInputWithFallback({
282
+ config: cfg,
283
+ env,
284
+ value: cfg.gateway?.auth?.token,
285
+ path: "gateway.auth.token",
286
+ readFallback: () => readGatewayTokenEnv(env)
287
+ });
288
+ return {
289
+ token: resolved.value,
290
+ source: resolved.source === "config" ? "config" : resolved.source === "secretRef" ? "secretRef" : resolved.source === "fallback" ? "env" : void 0,
291
+ unresolvedRefReason: resolved.unresolvedRefReason,
292
+ tokenSecretRefConfigured: resolved.secretRefConfigured
293
+ };
294
+ }
295
+ async function dashboardCommand(runtime = defaultRuntime, options = {}) {
296
+ const snapshot = await readConfigFileSnapshot();
297
+ const cfg = snapshot.valid ? snapshot.config : {};
298
+ const port = resolveGatewayPort(cfg);
299
+ const bind = cfg.gateway?.bind ?? "loopback";
300
+ const basePath = cfg.gateway?.controlUi?.basePath;
301
+ const customBindHost = cfg.gateway?.customBindHost;
302
+ const resolvedToken = await resolveDashboardToken(cfg, process.env);
303
+ const token = resolvedToken.token ?? "";
304
+ const links = resolveControlUiLinks({
305
+ port,
306
+ bind: bind === "lan" ? "loopback" : bind,
307
+ customBindHost,
308
+ basePath
309
+ });
310
+ const includeTokenInUrl = token.length > 0 && !resolvedToken.tokenSecretRefConfigured;
311
+ const dashboardUrl = includeTokenInUrl ? `${links.httpUrl}#token=${encodeURIComponent(token)}` : links.httpUrl;
312
+ runtime.log(`Dashboard URL: ${dashboardUrl}`);
313
+ if (resolvedToken.tokenSecretRefConfigured && token) runtime.log("Token auto-auth is disabled for SecretRef-managed gateway.auth.token; use your external token source if prompted.");
314
+ if (resolvedToken.unresolvedRefReason) {
315
+ runtime.log(`Token auto-auth unavailable: ${resolvedToken.unresolvedRefReason}`);
316
+ runtime.log("Set OPENCLAW_GATEWAY_TOKEN in this shell or resolve your secret provider, then rerun `openclaw dashboard`.");
317
+ }
318
+ const copied = await copyToClipboard(dashboardUrl).catch(() => false);
319
+ runtime.log(copied ? "Copied to clipboard." : "Copy to clipboard unavailable.");
320
+ let opened = false;
321
+ let hint;
322
+ if (!options.noOpen) {
323
+ if ((await detectBrowserOpenSupport()).ok) opened = await openUrl(dashboardUrl);
324
+ if (!opened) hint = formatControlUiSshHint({
325
+ port,
326
+ basePath,
327
+ token: includeTokenInUrl ? token || void 0 : void 0
328
+ });
329
+ } else hint = "Browser launch disabled (--no-open). Use the URL above.";
330
+ if (opened) runtime.log("Opened in your browser. Keep that tab to control OpenClaw.");
331
+ else if (hint) runtime.log(hint);
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/commands/cleanup-plan.ts
336
+ function resolveCleanupPlanFromDisk() {
337
+ const cfg = loadConfig();
338
+ const stateDir = resolveStateDir();
339
+ const configPath = resolveConfigPath();
340
+ const oauthDir = resolveOAuthDir();
341
+ return {
342
+ cfg,
343
+ stateDir,
344
+ configPath,
345
+ oauthDir,
346
+ ...buildCleanupPlan({
347
+ cfg,
348
+ stateDir,
349
+ configPath,
350
+ oauthDir
351
+ })
352
+ };
353
+ }
354
+
355
+ //#endregion
356
+ //#region src/commands/reset.ts
357
+ async function stopGatewayIfRunning(runtime) {
358
+ if (isNixMode) return;
359
+ const service = resolveGatewayService();
360
+ let loaded = false;
361
+ try {
362
+ loaded = await service.isLoaded({ env: process.env });
363
+ } catch (err) {
364
+ runtime.error(`Gateway service check failed: ${String(err)}`);
365
+ return;
366
+ }
367
+ if (!loaded) return;
368
+ try {
369
+ await service.stop({
370
+ env: process.env,
371
+ stdout: process.stdout
372
+ });
373
+ } catch (err) {
374
+ runtime.error(`Gateway stop failed: ${String(err)}`);
375
+ }
376
+ }
377
+ function logBackupRecommendation$1(runtime) {
378
+ runtime.log(`Recommended first: ${formatCliCommand("openclaw backup create")}`);
379
+ }
380
+ async function resetCommand(runtime, opts) {
381
+ const interactive = !opts.nonInteractive;
382
+ if (!interactive && !opts.yes) {
383
+ runtime.error("Non-interactive mode requires --yes.");
384
+ runtime.exit(1);
385
+ return;
386
+ }
387
+ let scope = opts.scope;
388
+ if (!scope) {
389
+ if (!interactive) {
390
+ runtime.error("Non-interactive mode requires --scope.");
391
+ runtime.exit(1);
392
+ return;
393
+ }
394
+ const selection = await selectStyled({
395
+ message: "Reset scope",
396
+ options: [
397
+ {
398
+ value: "config",
399
+ label: "Config only",
400
+ hint: "openclaw.json"
401
+ },
402
+ {
403
+ value: "config+creds+sessions",
404
+ label: "Config + credentials + sessions",
405
+ hint: "keeps workspace + auth profiles"
406
+ },
407
+ {
408
+ value: "full",
409
+ label: "Full reset",
410
+ hint: "state dir + workspace"
411
+ }
412
+ ],
413
+ initialValue: "config+creds+sessions"
414
+ });
415
+ if (isCancel(selection)) {
416
+ cancel(stylePromptTitle("Reset cancelled.") ?? "Reset cancelled.");
417
+ runtime.exit(0);
418
+ return;
419
+ }
420
+ scope = selection;
421
+ }
422
+ if (![
423
+ "config",
424
+ "config+creds+sessions",
425
+ "full"
426
+ ].includes(scope)) {
427
+ runtime.error("Invalid --scope. Expected \"config\", \"config+creds+sessions\", or \"full\".");
428
+ runtime.exit(1);
429
+ return;
430
+ }
431
+ if (interactive && !opts.yes) {
432
+ const ok = await confirm({ message: stylePromptMessage(`Proceed with ${scope} reset?`) });
433
+ if (isCancel(ok) || !ok) {
434
+ cancel(stylePromptTitle("Reset cancelled.") ?? "Reset cancelled.");
435
+ runtime.exit(0);
436
+ return;
437
+ }
438
+ }
439
+ const dryRun = Boolean(opts.dryRun);
440
+ const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } = resolveCleanupPlanFromDisk();
441
+ if (scope !== "config") {
442
+ logBackupRecommendation$1(runtime);
443
+ if (dryRun) runtime.log("[dry-run] stop gateway service");
444
+ else await stopGatewayIfRunning(runtime);
445
+ }
446
+ if (scope === "config") {
447
+ await removePath(configPath, runtime, {
448
+ dryRun,
449
+ label: configPath
450
+ });
451
+ return;
452
+ }
453
+ if (scope === "config+creds+sessions") {
454
+ await removePath(configPath, runtime, {
455
+ dryRun,
456
+ label: configPath
457
+ });
458
+ await removePath(oauthDir, runtime, {
459
+ dryRun,
460
+ label: oauthDir
461
+ });
462
+ const sessionDirs = await listAgentSessionDirs(stateDir);
463
+ for (const dir of sessionDirs) await removePath(dir, runtime, {
464
+ dryRun,
465
+ label: dir
466
+ });
467
+ runtime.log(`Next: ${formatCliCommand("openclaw onboard --install-daemon")}`);
468
+ return;
469
+ }
470
+ if (scope === "full") {
471
+ await removeStateAndLinkedPaths({
472
+ stateDir,
473
+ configPath,
474
+ oauthDir,
475
+ configInsideState,
476
+ oauthInsideState
477
+ }, runtime, { dryRun });
478
+ await removeWorkspaceDirs(workspaceDirs, runtime, { dryRun });
479
+ runtime.log(`Next: ${formatCliCommand("openclaw onboard --install-daemon")}`);
480
+ return;
481
+ }
482
+ }
483
+
484
+ //#endregion
485
+ //#region src/commands/uninstall.ts
486
+ const multiselectStyled = (params) => multiselect({
487
+ ...params,
488
+ message: stylePromptMessage(params.message),
489
+ options: params.options.map((opt) => opt.hint === void 0 ? opt : {
490
+ ...opt,
491
+ hint: stylePromptHint(opt.hint)
492
+ })
493
+ });
494
+ function buildScopeSelection(opts) {
495
+ const hadExplicit = Boolean(opts.all || opts.service || opts.state || opts.workspace || opts.app);
496
+ const scopes = /* @__PURE__ */ new Set();
497
+ if (opts.all || opts.service) scopes.add("service");
498
+ if (opts.all || opts.state) scopes.add("state");
499
+ if (opts.all || opts.workspace) scopes.add("workspace");
500
+ if (opts.all || opts.app) scopes.add("app");
501
+ return {
502
+ scopes,
503
+ hadExplicit
504
+ };
505
+ }
506
+ async function stopAndUninstallService(runtime) {
507
+ if (isNixMode) {
508
+ runtime.error("Nix mode detected; service uninstall is disabled.");
509
+ return false;
510
+ }
511
+ const service = resolveGatewayService();
512
+ let loaded = false;
513
+ try {
514
+ loaded = await service.isLoaded({ env: process.env });
515
+ } catch (err) {
516
+ runtime.error(`Gateway service check failed: ${String(err)}`);
517
+ return false;
518
+ }
519
+ if (!loaded) {
520
+ runtime.log(`Gateway service ${service.notLoadedText}.`);
521
+ return true;
522
+ }
523
+ try {
524
+ await service.stop({
525
+ env: process.env,
526
+ stdout: process.stdout
527
+ });
528
+ } catch (err) {
529
+ runtime.error(`Gateway stop failed: ${String(err)}`);
530
+ }
531
+ try {
532
+ await service.uninstall({
533
+ env: process.env,
534
+ stdout: process.stdout
535
+ });
536
+ return true;
537
+ } catch (err) {
538
+ runtime.error(`Gateway uninstall failed: ${String(err)}`);
539
+ return false;
540
+ }
541
+ }
542
+ async function removeMacApp(runtime, dryRun) {
543
+ if (process.platform !== "darwin") return;
544
+ await removePath("/Applications/OpenClaw.app", runtime, {
545
+ dryRun,
546
+ label: "/Applications/OpenClaw.app"
547
+ });
548
+ }
549
+ function logBackupRecommendation(runtime) {
550
+ runtime.log(`Recommended first: ${formatCliCommand("openclaw backup create")}`);
551
+ }
552
+ async function uninstallCommand(runtime, opts) {
553
+ const { scopes, hadExplicit } = buildScopeSelection(opts);
554
+ const interactive = !opts.nonInteractive;
555
+ if (!interactive && !opts.yes) {
556
+ runtime.error("Non-interactive mode requires --yes.");
557
+ runtime.exit(1);
558
+ return;
559
+ }
560
+ if (!hadExplicit) {
561
+ if (!interactive) {
562
+ runtime.error("Non-interactive mode requires explicit scopes (use --all).");
563
+ runtime.exit(1);
564
+ return;
565
+ }
566
+ const selection = await multiselectStyled({
567
+ message: "Uninstall which components?",
568
+ options: [
569
+ {
570
+ value: "service",
571
+ label: "Gateway service",
572
+ hint: "launchd / systemd / schtasks"
573
+ },
574
+ {
575
+ value: "state",
576
+ label: "State + config",
577
+ hint: "~/.openclaw"
578
+ },
579
+ {
580
+ value: "workspace",
581
+ label: "Workspace",
582
+ hint: "agent files"
583
+ },
584
+ {
585
+ value: "app",
586
+ label: "macOS app",
587
+ hint: "/Applications/OpenClaw.app"
588
+ }
589
+ ],
590
+ initialValues: [
591
+ "service",
592
+ "state",
593
+ "workspace"
594
+ ]
595
+ });
596
+ if (isCancel(selection)) {
597
+ cancel(stylePromptTitle("Uninstall cancelled.") ?? "Uninstall cancelled.");
598
+ runtime.exit(0);
599
+ return;
600
+ }
601
+ for (const value of selection) scopes.add(value);
602
+ }
603
+ if (scopes.size === 0) {
604
+ runtime.log("Nothing selected.");
605
+ return;
606
+ }
607
+ if (interactive && !opts.yes) {
608
+ const ok = await confirm({ message: stylePromptMessage("Proceed with uninstall?") });
609
+ if (isCancel(ok) || !ok) {
610
+ cancel(stylePromptTitle("Uninstall cancelled.") ?? "Uninstall cancelled.");
611
+ runtime.exit(0);
612
+ return;
613
+ }
614
+ }
615
+ const dryRun = Boolean(opts.dryRun);
616
+ const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } = resolveCleanupPlanFromDisk();
617
+ if (scopes.has("state") || scopes.has("workspace")) logBackupRecommendation(runtime);
618
+ if (scopes.has("service")) if (dryRun) runtime.log("[dry-run] remove gateway service");
619
+ else await stopAndUninstallService(runtime);
620
+ if (scopes.has("state")) await removeStateAndLinkedPaths({
621
+ stateDir,
622
+ configPath,
623
+ oauthDir,
624
+ configInsideState,
625
+ oauthInsideState
626
+ }, runtime, { dryRun });
627
+ if (scopes.has("workspace")) await removeWorkspaceDirs(workspaceDirs, runtime, { dryRun });
628
+ if (scopes.has("app")) await removeMacApp(runtime, dryRun);
629
+ runtime.log("CLI still installed. Remove via npm/pnpm if desired.");
630
+ if (scopes.has("state") && !scopes.has("workspace")) {
631
+ const home = resolveHomeDir();
632
+ if (home && workspaceDirs.some((dir) => dir.startsWith(path.resolve(home)))) runtime.log("Tip: workspaces were preserved. Re-run with --workspace to remove them.");
633
+ }
634
+ }
635
+
636
+ //#endregion
637
+ //#region src/cli/program/register.maintenance.ts
638
+ function registerMaintenanceCommands(program) {
639
+ program.command("doctor").description("Health checks + quick fixes for the gateway and channels").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/doctor", "docs.openclaw.ai/cli/doctor")}\n`).option("--no-workspace-suggestions", "Disable workspace memory system suggestions", false).option("--yes", "Accept defaults without prompting", false).option("--repair", "Apply recommended repairs without prompting", false).option("--fix", "Apply recommended repairs (alias for --repair)", false).option("--force", "Apply aggressive repairs (overwrites custom service config)", false).option("--non-interactive", "Run without prompts (safe migrations only)", false).option("--generate-gateway-token", "Generate and configure a gateway token", false).option("--deep", "Scan system services for extra gateway installs", false).action(async (opts) => {
640
+ await runCommandWithRuntime(defaultRuntime, async () => {
641
+ await doctorCommand(defaultRuntime, {
642
+ workspaceSuggestions: opts.workspaceSuggestions,
643
+ yes: Boolean(opts.yes),
644
+ repair: Boolean(opts.repair) || Boolean(opts.fix),
645
+ force: Boolean(opts.force),
646
+ nonInteractive: Boolean(opts.nonInteractive),
647
+ generateGatewayToken: Boolean(opts.generateGatewayToken),
648
+ deep: Boolean(opts.deep)
649
+ });
650
+ defaultRuntime.exit(0);
651
+ });
652
+ });
653
+ program.command("dashboard").description("Open the Control UI with your current token").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/dashboard", "docs.openclaw.ai/cli/dashboard")}\n`).option("--no-open", "Print URL but do not launch a browser").action(async (opts) => {
654
+ await runCommandWithRuntime(defaultRuntime, async () => {
655
+ await dashboardCommand(defaultRuntime, { noOpen: opts.open === false });
656
+ });
657
+ });
658
+ program.command("reset").description("Reset local config/state (keeps the CLI installed)").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/reset", "docs.openclaw.ai/cli/reset")}\n`).option("--scope <scope>", "config|config+creds+sessions|full (default: interactive prompt)").option("--yes", "Skip confirmation prompts", false).option("--non-interactive", "Disable prompts (requires --scope + --yes)", false).option("--dry-run", "Print actions without removing files", false).action(async (opts) => {
659
+ await runCommandWithRuntime(defaultRuntime, async () => {
660
+ await resetCommand(defaultRuntime, {
661
+ scope: opts.scope,
662
+ yes: Boolean(opts.yes),
663
+ nonInteractive: Boolean(opts.nonInteractive),
664
+ dryRun: Boolean(opts.dryRun)
665
+ });
666
+ });
667
+ });
668
+ program.command("uninstall").description("Uninstall the gateway service + local data (CLI remains)").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/uninstall", "docs.openclaw.ai/cli/uninstall")}\n`).option("--service", "Remove the gateway service", false).option("--state", "Remove state + config", false).option("--workspace", "Remove workspace dirs", false).option("--app", "Remove the macOS app", false).option("--all", "Remove service + state + workspace + app", false).option("--yes", "Skip confirmation prompts", false).option("--non-interactive", "Disable prompts (requires --yes)", false).option("--dry-run", "Print actions without removing files", false).action(async (opts) => {
669
+ await runCommandWithRuntime(defaultRuntime, async () => {
670
+ await uninstallCommand(defaultRuntime, {
671
+ service: Boolean(opts.service),
672
+ state: Boolean(opts.state),
673
+ workspace: Boolean(opts.workspace),
674
+ app: Boolean(opts.app),
675
+ all: Boolean(opts.all),
676
+ yes: Boolean(opts.yes),
677
+ nonInteractive: Boolean(opts.nonInteractive),
678
+ dryRun: Boolean(opts.dryRun)
679
+ });
680
+ });
681
+ });
682
+ }
683
+
684
+ //#endregion
685
+ export { registerMaintenanceCommands };