shellward 0.3.4 → 0.5.0

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,58 @@
1
+ // src/commands/upgrade-openclaw.ts — 一键升级 OpenClaw,减少手动操作
2
+
3
+ import { execSync } from 'child_process'
4
+ import type { ShellWardConfig } from '../types'
5
+ import { resolveLocale } from '../types'
6
+
7
+ export function registerUpgradeOpenClawCommand(api: any, config: ShellWardConfig) {
8
+ const locale = resolveLocale(config)
9
+
10
+ api.registerCommand({
11
+ name: 'upgrade-openclaw',
12
+ description: locale === 'zh'
13
+ ? '⬆️ 升级 OpenClaw 到最新版本(一键执行)'
14
+ : '⬆️ Upgrade OpenClaw to latest (one-click)',
15
+ acceptsArgs: true,
16
+ handler: (ctx: any) => {
17
+ const zh = locale === 'zh'
18
+ const args = (ctx.args || '').trim().toLowerCase()
19
+ const doUpgrade = args === 'yes' || args === 'y' || args === '--yes'
20
+
21
+ let currentVer = 'unknown'
22
+ try {
23
+ const out = execSync('openclaw --version 2>&1', { timeout: 5000 }).toString()
24
+ const m = out.match(/(\d{4}\.\d+\.\d+|\d+\.\d+\.\d+)/)
25
+ if (m) currentVer = m[1]
26
+ } catch { /* skip */ }
27
+
28
+ const cmd = 'npm update -g openclaw'
29
+ const lines: string[] = []
30
+
31
+ if (doUpgrade) {
32
+ try {
33
+ execSync(cmd, { stdio: 'inherit', timeout: 120000 })
34
+ const newOut = execSync('openclaw --version 2>&1', { timeout: 5000 }).toString()
35
+ const newM = newOut.match(/(\d{4}\.\d+\.\d+|\d+\.\d+\.\d+)/)
36
+ const newVer = newM ? newM[1] : 'unknown'
37
+ lines.push(zh ? `✅ 升级完成!当前版本: ${newVer}` : `✅ Upgrade done! Current version: ${newVer}`)
38
+ } catch (e: any) {
39
+ lines.push(zh ? `❌ 升级失败: ${e?.message || e}` : `❌ Upgrade failed: ${e?.message || e}`)
40
+ lines.push(zh ? `请手动执行: \`${cmd}\`` : `Run manually: \`${cmd}\``)
41
+ }
42
+ } else {
43
+ lines.push(zh ? `当前版本: ${currentVer}` : `Current version: ${currentVer}`)
44
+ lines.push('')
45
+ lines.push(zh ? '**一键升级**(复制执行):' : '**One-click upgrade** (copy & run):')
46
+ lines.push('```bash')
47
+ lines.push(cmd)
48
+ lines.push('```')
49
+ lines.push('')
50
+ lines.push(zh
51
+ ? '或在 OpenClaw 中执行: `/upgrade-openclaw yes` 自动升级'
52
+ : 'Or run in OpenClaw: `/upgrade-openclaw yes` to auto-upgrade')
53
+ }
54
+
55
+ return { text: lines.join('\n') }
56
+ },
57
+ })
58
+ }