openclawsetup 1.0.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.
- package/README.md +198 -0
- package/bin/cli.mjs +537 -0
- package/package.json +31 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +264 -0
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# openclawsetup
|
|
2
|
+
|
|
3
|
+
一键安装 OpenClaw - 自动完成基础部署,无需交互。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 自动安装 OpenClaw CLI
|
|
8
|
+
- 自动创建配置文件和 workspace
|
|
9
|
+
- 自动配置服务持久化(开机自启动)
|
|
10
|
+
- 支持 macOS、Linux、Windows 三系统
|
|
11
|
+
- 无需任何交互,全自动完成
|
|
12
|
+
|
|
13
|
+
## 快速开始
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx openclawsetup
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 安装选项
|
|
20
|
+
|
|
21
|
+
### 环境变量
|
|
22
|
+
|
|
23
|
+
| 变量 | 说明 | 默认值 |
|
|
24
|
+
|------|------|--------|
|
|
25
|
+
| `OPENCLAW_PORT` | Gateway 端口 | 18789 |
|
|
26
|
+
| `GATEWAY_TOKEN` | 自定义 Token | 自动生成 |
|
|
27
|
+
| `SKIP_DAEMON` | 跳过服务持久化 | false |
|
|
28
|
+
|
|
29
|
+
### 命令行参数
|
|
30
|
+
|
|
31
|
+
| 参数 | 说明 |
|
|
32
|
+
|------|------|
|
|
33
|
+
| `--port <port>` | 指定 Gateway 端口 |
|
|
34
|
+
| `--token <token>` | 指定 Gateway Token |
|
|
35
|
+
| `--skip-daemon` | 跳过服务持久化配置 |
|
|
36
|
+
| `--skip-start` | 安装后不启动服务 |
|
|
37
|
+
| `--help, -h` | 显示帮助信息 |
|
|
38
|
+
|
|
39
|
+
## 使用示例
|
|
40
|
+
|
|
41
|
+
### 默认安装(推荐)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx openclawsetup
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 指定端口
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# macOS/Linux
|
|
51
|
+
OPENCLAW_PORT=8080 npx openclawsetup
|
|
52
|
+
|
|
53
|
+
# Windows PowerShell
|
|
54
|
+
$env:OPENCLAW_PORT=8080; npx openclawsetup
|
|
55
|
+
|
|
56
|
+
# Windows CMD
|
|
57
|
+
set OPENCLAW_PORT=8080 && npx openclawsetup
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 指定 Token
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# macOS/Linux
|
|
64
|
+
GATEWAY_TOKEN="my-secret-token" npx openclawsetup
|
|
65
|
+
|
|
66
|
+
# Windows PowerShell
|
|
67
|
+
$env:GATEWAY_TOKEN="my-secret-token"; npx openclawsetup
|
|
68
|
+
|
|
69
|
+
# Windows CMD
|
|
70
|
+
set GATEWAY_TOKEN=my-secret-token && npx openclawsetup
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 命令行参数方式
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npx openclawsetup --port 8080 --token my-secret-token
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 仅安装不启动
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx openclawsetup --skip-start
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 安装后
|
|
86
|
+
|
|
87
|
+
安装完成后,你需要配置 AI 模型才能使用:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# 配置 Claude 模型(推荐)
|
|
91
|
+
npx openclawapi@latest preset-claude
|
|
92
|
+
|
|
93
|
+
# 或配置其他模型
|
|
94
|
+
npx openclawapi@latest
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 配置聊天渠道
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Discord
|
|
101
|
+
npx openclawdc
|
|
102
|
+
|
|
103
|
+
# 飞书
|
|
104
|
+
npx openclawfs
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 常用命令
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 查看状态
|
|
111
|
+
openclaw status
|
|
112
|
+
|
|
113
|
+
# 查看日志
|
|
114
|
+
openclaw gateway logs
|
|
115
|
+
|
|
116
|
+
# 重启服务
|
|
117
|
+
openclaw gateway restart
|
|
118
|
+
|
|
119
|
+
# 诊断问题
|
|
120
|
+
openclaw doctor
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 服务持久化
|
|
124
|
+
|
|
125
|
+
安装时会自动配置开机自启动:
|
|
126
|
+
|
|
127
|
+
- **macOS**: launchd (`~/Library/LaunchAgents/com.openclaw.gateway.plist`)
|
|
128
|
+
- **Linux**: systemd --user (`~/.config/systemd/user/openclaw.service`)
|
|
129
|
+
- **Windows**: 计划任务 (OpenClaw)
|
|
130
|
+
|
|
131
|
+
### 手动管理服务
|
|
132
|
+
|
|
133
|
+
**macOS:**
|
|
134
|
+
```bash
|
|
135
|
+
# 启动
|
|
136
|
+
launchctl start com.openclaw.gateway
|
|
137
|
+
|
|
138
|
+
# 停止
|
|
139
|
+
launchctl stop com.openclaw.gateway
|
|
140
|
+
|
|
141
|
+
# 卸载
|
|
142
|
+
launchctl unload ~/Library/LaunchAgents/com.openclaw.gateway.plist
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Linux:**
|
|
146
|
+
```bash
|
|
147
|
+
# 启动
|
|
148
|
+
systemctl --user start openclaw
|
|
149
|
+
|
|
150
|
+
# 停止
|
|
151
|
+
systemctl --user stop openclaw
|
|
152
|
+
|
|
153
|
+
# 查看状态
|
|
154
|
+
systemctl --user status openclaw
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Windows (PowerShell):**
|
|
158
|
+
```powershell
|
|
159
|
+
# 启动
|
|
160
|
+
Start-ScheduledTask -TaskName "OpenClaw"
|
|
161
|
+
|
|
162
|
+
# 停止
|
|
163
|
+
Stop-ScheduledTask -TaskName "OpenClaw"
|
|
164
|
+
|
|
165
|
+
# 删除
|
|
166
|
+
Unregister-ScheduledTask -TaskName "OpenClaw" -Confirm:$false
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 卸载
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# 1. 停止服务
|
|
173
|
+
openclaw gateway stop
|
|
174
|
+
|
|
175
|
+
# 2. 卸载 CLI
|
|
176
|
+
npm uninstall -g openclaw
|
|
177
|
+
|
|
178
|
+
# 3. 删除配置
|
|
179
|
+
rm -rf ~/.openclaw
|
|
180
|
+
|
|
181
|
+
# 4. 删除服务配置
|
|
182
|
+
# macOS
|
|
183
|
+
rm ~/Library/LaunchAgents/com.openclaw.gateway.plist
|
|
184
|
+
|
|
185
|
+
# Linux
|
|
186
|
+
rm ~/.config/systemd/user/openclaw.service
|
|
187
|
+
systemctl --user daemon-reload
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 系统要求
|
|
191
|
+
|
|
192
|
+
- Node.js 18+
|
|
193
|
+
- npm 或 npx
|
|
194
|
+
- macOS / Linux / Windows (WSL2 推荐)
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OpenClaw 一键安装 CLI
|
|
4
|
+
*
|
|
5
|
+
* 基本用法:
|
|
6
|
+
* npx openclawsetup
|
|
7
|
+
*
|
|
8
|
+
* 环境变量:
|
|
9
|
+
* OPENCLAW_PORT - Gateway 端口 (默认: 18789)
|
|
10
|
+
* GATEWAY_TOKEN - 自定义 Token (默认: 自动生成)
|
|
11
|
+
* SKIP_DAEMON - 跳过服务持久化 (默认: false)
|
|
12
|
+
*
|
|
13
|
+
* 命令行参数:
|
|
14
|
+
* --port <port> - 指定 Gateway 端口
|
|
15
|
+
* --token <token> - 指定 Gateway Token
|
|
16
|
+
* --skip-daemon - 跳过服务持久化配置
|
|
17
|
+
* --skip-start - 安装后不启动服务
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { execSync, spawn } from 'child_process';
|
|
21
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
22
|
+
import { homedir, platform } from 'os';
|
|
23
|
+
import { join } from 'path';
|
|
24
|
+
import { randomBytes } from 'crypto';
|
|
25
|
+
|
|
26
|
+
// 解析命令行参数
|
|
27
|
+
function parseArgs() {
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const result = {
|
|
30
|
+
port: parseInt(process.env.OPENCLAW_PORT, 10) || 18789,
|
|
31
|
+
token: process.env.GATEWAY_TOKEN || '',
|
|
32
|
+
skipDaemon: process.env.SKIP_DAEMON === 'true' || process.env.SKIP_DAEMON === '1',
|
|
33
|
+
skipStart: false,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < args.length; i++) {
|
|
37
|
+
switch (args[i]) {
|
|
38
|
+
case '--port':
|
|
39
|
+
result.port = parseInt(args[++i], 10) || 18789;
|
|
40
|
+
break;
|
|
41
|
+
case '--token':
|
|
42
|
+
result.token = args[++i] || '';
|
|
43
|
+
break;
|
|
44
|
+
case '--skip-daemon':
|
|
45
|
+
result.skipDaemon = true;
|
|
46
|
+
break;
|
|
47
|
+
case '--skip-start':
|
|
48
|
+
result.skipStart = true;
|
|
49
|
+
break;
|
|
50
|
+
case '--help':
|
|
51
|
+
case '-h':
|
|
52
|
+
showHelp();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function showHelp() {
|
|
61
|
+
console.log(`
|
|
62
|
+
OpenClaw 一键安装工具
|
|
63
|
+
|
|
64
|
+
用法:
|
|
65
|
+
npx openclawsetup [选项]
|
|
66
|
+
|
|
67
|
+
选项:
|
|
68
|
+
--port <port> 指定 Gateway 端口 (默认: 18789)
|
|
69
|
+
--token <token> 指定 Gateway Token (默认: 自动生成)
|
|
70
|
+
--skip-daemon 跳过服务持久化配置
|
|
71
|
+
--skip-start 安装后不启动服务
|
|
72
|
+
--help, -h 显示帮助信息
|
|
73
|
+
|
|
74
|
+
环境变量:
|
|
75
|
+
OPENCLAW_PORT Gateway 端口
|
|
76
|
+
GATEWAY_TOKEN 自定义 Token
|
|
77
|
+
SKIP_DAEMON 跳过服务持久化 (true/1)
|
|
78
|
+
|
|
79
|
+
示例:
|
|
80
|
+
# 默认安装
|
|
81
|
+
npx openclawsetup
|
|
82
|
+
|
|
83
|
+
# 指定端口和 Token
|
|
84
|
+
npx openclawsetup --port 8080 --token mytoken123
|
|
85
|
+
|
|
86
|
+
# macOS/Linux 环境变量方式
|
|
87
|
+
OPENCLAW_PORT=8080 npx openclawsetup
|
|
88
|
+
|
|
89
|
+
# Windows PowerShell
|
|
90
|
+
$env:OPENCLAW_PORT=8080; npx openclawsetup
|
|
91
|
+
`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 颜色
|
|
95
|
+
const colors = {
|
|
96
|
+
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
97
|
+
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
98
|
+
yellow: (s) => `\x1b[33m${s}\x1b[0m`,
|
|
99
|
+
cyan: (s) => `\x1b[36m${s}\x1b[0m`,
|
|
100
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
101
|
+
gray: (s) => `\x1b[90m${s}\x1b[0m`,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const log = {
|
|
105
|
+
info: (msg) => console.log(colors.cyan(msg)),
|
|
106
|
+
success: (msg) => console.log(colors.green(`✓ ${msg}`)),
|
|
107
|
+
warn: (msg) => console.log(colors.yellow(`⚠ ${msg}`)),
|
|
108
|
+
error: (msg) => console.log(colors.red(`✗ ${msg}`)),
|
|
109
|
+
hint: (msg) => console.log(colors.gray(` 提示: ${msg}`)),
|
|
110
|
+
detail: (msg) => console.log(colors.gray(` ${msg}`)),
|
|
111
|
+
step: (n, msg) => console.log(colors.cyan(`[${n}] ${msg}`)),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// 错误码定义
|
|
115
|
+
const ERROR_CODES = {
|
|
116
|
+
NODE_VERSION: { code: 1, message: 'Node.js 版本过低' },
|
|
117
|
+
ALREADY_INSTALLED: { code: 2, message: 'OpenClaw 已安装' },
|
|
118
|
+
NPM_INSTALL_FAILED: { code: 3, message: 'npm 安装失败' },
|
|
119
|
+
CONFIG_FAILED: { code: 4, message: '配置文件创建失败' },
|
|
120
|
+
DAEMON_SETUP_FAILED: { code: 5, message: '服务持久化配置失败' },
|
|
121
|
+
START_FAILED: { code: 6, message: '服务启动失败' },
|
|
122
|
+
PERMISSION_DENIED: { code: 7, message: '权限不足' },
|
|
123
|
+
UNSUPPORTED_PLATFORM: { code: 8, message: '不支持的操作系统' },
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// 退出并显示错误
|
|
127
|
+
function exitWithError(errorType, details = '', solutions = []) {
|
|
128
|
+
const err = ERROR_CODES[errorType] || { code: 99, message: '未知错误' };
|
|
129
|
+
console.log(colors.bold(colors.red('\n========================================')));
|
|
130
|
+
console.log(colors.bold(colors.red(`❌ 错误: ${err.message}`)));
|
|
131
|
+
console.log(colors.bold(colors.red('========================================')));
|
|
132
|
+
if (details) log.detail(details);
|
|
133
|
+
if (solutions.length > 0) {
|
|
134
|
+
console.log(colors.cyan('\n解决方案:'));
|
|
135
|
+
solutions.forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
136
|
+
}
|
|
137
|
+
console.log(colors.gray(`\n错误码: ${err.code}`));
|
|
138
|
+
process.exit(err.code);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 安全执行命令
|
|
142
|
+
function safeExec(cmd, options = {}) {
|
|
143
|
+
try {
|
|
144
|
+
const output = execSync(cmd, { encoding: 'utf8', stdio: 'pipe', ...options });
|
|
145
|
+
return { ok: true, output: output.trim() };
|
|
146
|
+
} catch (e) {
|
|
147
|
+
return {
|
|
148
|
+
ok: false,
|
|
149
|
+
error: e.message,
|
|
150
|
+
stderr: e.stderr?.toString() || '',
|
|
151
|
+
stdout: e.stdout?.toString() || '',
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 检查 Node.js 版本
|
|
157
|
+
function checkNodeVersion() {
|
|
158
|
+
const version = process.version;
|
|
159
|
+
const major = parseInt(version.slice(1).split('.')[0], 10);
|
|
160
|
+
if (major < 18) {
|
|
161
|
+
exitWithError('NODE_VERSION', `当前版本: ${version},需要 Node.js 18+`, [
|
|
162
|
+
'升级 Node.js 到 18 或更高版本',
|
|
163
|
+
'访问 https://nodejs.org/ 下载最新版本',
|
|
164
|
+
'使用 nvm 管理 Node.js 版本: nvm install 22',
|
|
165
|
+
]);
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 检测现有安装
|
|
171
|
+
function detectExistingInstall() {
|
|
172
|
+
const home = homedir();
|
|
173
|
+
const openclawDir = join(home, '.openclaw');
|
|
174
|
+
const clawdbotDir = join(home, '.clawdbot');
|
|
175
|
+
|
|
176
|
+
if (existsSync(openclawDir) || existsSync(clawdbotDir)) {
|
|
177
|
+
return {
|
|
178
|
+
installed: true,
|
|
179
|
+
configDir: existsSync(openclawDir) ? openclawDir : clawdbotDir,
|
|
180
|
+
name: existsSync(openclawDir) ? 'openclaw' : 'clawdbot',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 检查命令是否存在
|
|
185
|
+
const openclawResult = safeExec('openclaw --version');
|
|
186
|
+
if (openclawResult.ok) {
|
|
187
|
+
return { installed: true, name: 'openclaw', version: openclawResult.output };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const clawdbotResult = safeExec('clawdbot --version');
|
|
191
|
+
if (clawdbotResult.ok) {
|
|
192
|
+
return { installed: true, name: 'clawdbot', version: clawdbotResult.output };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return { installed: false };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 安装 OpenClaw CLI
|
|
199
|
+
function installOpenClaw() {
|
|
200
|
+
log.step(1, '安装 OpenClaw CLI...');
|
|
201
|
+
|
|
202
|
+
const result = safeExec('npm install -g openclaw@latest', { timeout: 300000 });
|
|
203
|
+
if (!result.ok) {
|
|
204
|
+
// 尝试 clawdbot 作为备选
|
|
205
|
+
log.warn('openclaw 安装失败,尝试 clawdbot...');
|
|
206
|
+
const fallback = safeExec('npm install -g clawdbot@latest', { timeout: 300000 });
|
|
207
|
+
if (!fallback.ok) {
|
|
208
|
+
exitWithError('NPM_INSTALL_FAILED', result.stderr || result.error, [
|
|
209
|
+
'检查网络连接',
|
|
210
|
+
'尝试使用代理: npm config set proxy http://proxy:port',
|
|
211
|
+
'手动安装: npm install -g openclaw@latest',
|
|
212
|
+
'检查 npm 权限,可能需要 sudo (Linux/macOS)',
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
return 'clawdbot';
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
log.success('OpenClaw CLI 安装完成');
|
|
219
|
+
return 'openclaw';
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 生成 Token
|
|
223
|
+
function generateToken() {
|
|
224
|
+
return randomBytes(32).toString('hex');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 创建配置文件
|
|
228
|
+
function createConfig(options) {
|
|
229
|
+
log.step(2, '创建配置文件...');
|
|
230
|
+
|
|
231
|
+
const home = homedir();
|
|
232
|
+
const configDir = join(home, '.openclaw');
|
|
233
|
+
const workspaceDir = join(configDir, 'workspace');
|
|
234
|
+
const configPath = join(configDir, 'openclaw.json');
|
|
235
|
+
|
|
236
|
+
// 创建目录
|
|
237
|
+
if (!existsSync(configDir)) {
|
|
238
|
+
mkdirSync(configDir, { recursive: true });
|
|
239
|
+
}
|
|
240
|
+
if (!existsSync(workspaceDir)) {
|
|
241
|
+
mkdirSync(workspaceDir, { recursive: true });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 生成 Token
|
|
245
|
+
const token = options.token || generateToken();
|
|
246
|
+
|
|
247
|
+
// 配置内容
|
|
248
|
+
const config = {
|
|
249
|
+
agents: {
|
|
250
|
+
defaults: {
|
|
251
|
+
workspace: workspaceDir,
|
|
252
|
+
model: { primary: 'anthropic/claude-sonnet-4-20250514' },
|
|
253
|
+
models: ['anthropic/claude-sonnet-4-20250514', 'anthropic/claude-opus-4-5-20251101'],
|
|
254
|
+
maxConcurrent: 4,
|
|
255
|
+
sandbox: { mode: 'non-main', scope: 'agent', workspaceAccess: 'rw' },
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
gateway: {
|
|
259
|
+
port: options.port,
|
|
260
|
+
mode: 'local',
|
|
261
|
+
bind: 'loopback',
|
|
262
|
+
auth: { mode: 'token', token: token },
|
|
263
|
+
},
|
|
264
|
+
session: { dmScope: 'per-channel-peer' },
|
|
265
|
+
models: {
|
|
266
|
+
providers: {},
|
|
267
|
+
},
|
|
268
|
+
tools: { profile: 'coding', allow: ['fs', 'shell', 'browser'], deny: [] },
|
|
269
|
+
skills: { load: { watch: true, watchDebounceMs: 250 } },
|
|
270
|
+
channels: {},
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
275
|
+
log.success(`配置文件已创建: ${configPath}`);
|
|
276
|
+
} catch (e) {
|
|
277
|
+
exitWithError('CONFIG_FAILED', e.message, [
|
|
278
|
+
`检查目录权限: ${configDir}`,
|
|
279
|
+
'尝试手动创建目录: mkdir -p ~/.openclaw',
|
|
280
|
+
]);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// 创建 workspace 文件
|
|
284
|
+
const workspaceFiles = ['AGENTS.md', 'SOUL.md', 'USER.md', 'IDENTITY.md', 'TOOLS.md', 'MEMORY.md'];
|
|
285
|
+
for (const file of workspaceFiles) {
|
|
286
|
+
const filePath = join(workspaceDir, file);
|
|
287
|
+
if (!existsSync(filePath)) {
|
|
288
|
+
writeFileSync(filePath, `# ${file.replace('.md', '')}\n`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
log.success('Workspace 文件已初始化');
|
|
292
|
+
|
|
293
|
+
return { configDir, configPath, token, port: options.port };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// 配置服务持久化 - macOS
|
|
297
|
+
function setupDaemonMacOS(cliName) {
|
|
298
|
+
const plistPath = join(homedir(), 'Library', 'LaunchAgents', 'com.openclaw.gateway.plist');
|
|
299
|
+
const plistDir = join(homedir(), 'Library', 'LaunchAgents');
|
|
300
|
+
|
|
301
|
+
if (!existsSync(plistDir)) {
|
|
302
|
+
mkdirSync(plistDir, { recursive: true });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// 获取 CLI 路径
|
|
306
|
+
const cliPathResult = safeExec(`which ${cliName}`);
|
|
307
|
+
const cliPath = cliPathResult.ok ? cliPathResult.output : `/usr/local/bin/${cliName}`;
|
|
308
|
+
|
|
309
|
+
const plistContent = `<?xml version="1.0" encoding="UTF-8"?>
|
|
310
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
311
|
+
<plist version="1.0">
|
|
312
|
+
<dict>
|
|
313
|
+
<key>Label</key>
|
|
314
|
+
<string>com.openclaw.gateway</string>
|
|
315
|
+
<key>ProgramArguments</key>
|
|
316
|
+
<array>
|
|
317
|
+
<string>${cliPath}</string>
|
|
318
|
+
<string>gateway</string>
|
|
319
|
+
</array>
|
|
320
|
+
<key>RunAtLoad</key>
|
|
321
|
+
<true/>
|
|
322
|
+
<key>KeepAlive</key>
|
|
323
|
+
<true/>
|
|
324
|
+
<key>StandardOutPath</key>
|
|
325
|
+
<string>/tmp/openclaw.log</string>
|
|
326
|
+
<key>StandardErrorPath</key>
|
|
327
|
+
<string>/tmp/openclaw.err</string>
|
|
328
|
+
</dict>
|
|
329
|
+
</plist>`;
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
writeFileSync(plistPath, plistContent);
|
|
333
|
+
safeExec(`launchctl load "${plistPath}"`);
|
|
334
|
+
log.success('macOS 服务持久化已配置 (launchd)');
|
|
335
|
+
return true;
|
|
336
|
+
} catch (e) {
|
|
337
|
+
log.warn(`服务持久化配置失败: ${e.message}`);
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 配置服务持久化 - Linux
|
|
343
|
+
function setupDaemonLinux(cliName) {
|
|
344
|
+
const serviceDir = join(homedir(), '.config', 'systemd', 'user');
|
|
345
|
+
const servicePath = join(serviceDir, 'openclaw.service');
|
|
346
|
+
|
|
347
|
+
if (!existsSync(serviceDir)) {
|
|
348
|
+
mkdirSync(serviceDir, { recursive: true });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 获取 CLI 路径
|
|
352
|
+
const cliPathResult = safeExec(`which ${cliName}`);
|
|
353
|
+
const cliPath = cliPathResult.ok ? cliPathResult.output : `/usr/local/bin/${cliName}`;
|
|
354
|
+
|
|
355
|
+
const serviceContent = `[Unit]
|
|
356
|
+
Description=OpenClaw Gateway Service
|
|
357
|
+
After=network.target
|
|
358
|
+
|
|
359
|
+
[Service]
|
|
360
|
+
Type=simple
|
|
361
|
+
ExecStart=${cliPath} gateway
|
|
362
|
+
Restart=always
|
|
363
|
+
RestartSec=10
|
|
364
|
+
|
|
365
|
+
[Install]
|
|
366
|
+
WantedBy=default.target
|
|
367
|
+
`;
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
writeFileSync(servicePath, serviceContent);
|
|
371
|
+
safeExec('systemctl --user daemon-reload');
|
|
372
|
+
safeExec('systemctl --user enable openclaw');
|
|
373
|
+
// 允许用户服务在登出后继续运行
|
|
374
|
+
safeExec(`loginctl enable-linger ${process.env.USER || 'root'}`);
|
|
375
|
+
log.success('Linux 服务持久化已配置 (systemd --user)');
|
|
376
|
+
return true;
|
|
377
|
+
} catch (e) {
|
|
378
|
+
log.warn(`服务持久化配置失败: ${e.message}`);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// 配置服务持久化 - Windows
|
|
384
|
+
function setupDaemonWindows(cliName) {
|
|
385
|
+
// Windows 使用计划任务
|
|
386
|
+
const taskName = 'OpenClaw';
|
|
387
|
+
const result = safeExec(
|
|
388
|
+
`schtasks /create /tn "${taskName}" /tr "${cliName} gateway" /sc onlogon /rl limited /f`,
|
|
389
|
+
{ shell: 'cmd.exe' }
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
if (result.ok) {
|
|
393
|
+
log.success('Windows 服务持久化已配置 (计划任务)');
|
|
394
|
+
return true;
|
|
395
|
+
} else {
|
|
396
|
+
log.warn(`服务持久化配置失败: ${result.stderr || result.error}`);
|
|
397
|
+
log.hint('可以手动创建计划任务或使用 NSSM 工具');
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// 配置服务持久化
|
|
403
|
+
function setupDaemon(cliName) {
|
|
404
|
+
log.step(3, '配置服务持久化...');
|
|
405
|
+
|
|
406
|
+
const os = platform();
|
|
407
|
+
switch (os) {
|
|
408
|
+
case 'darwin':
|
|
409
|
+
return setupDaemonMacOS(cliName);
|
|
410
|
+
case 'linux':
|
|
411
|
+
return setupDaemonLinux(cliName);
|
|
412
|
+
case 'win32':
|
|
413
|
+
return setupDaemonWindows(cliName);
|
|
414
|
+
default:
|
|
415
|
+
log.warn(`不支持的操作系统: ${os},跳过服务持久化`);
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 启动服务
|
|
421
|
+
function startService(cliName) {
|
|
422
|
+
log.step(4, '启动 OpenClaw Gateway...');
|
|
423
|
+
|
|
424
|
+
const os = platform();
|
|
425
|
+
|
|
426
|
+
// 根据系统使用不同的启动方式
|
|
427
|
+
if (os === 'darwin') {
|
|
428
|
+
const result = safeExec('launchctl start com.openclaw.gateway');
|
|
429
|
+
if (result.ok) {
|
|
430
|
+
log.success('Gateway 已启动 (launchd)');
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
} else if (os === 'linux') {
|
|
434
|
+
const result = safeExec('systemctl --user start openclaw');
|
|
435
|
+
if (result.ok) {
|
|
436
|
+
log.success('Gateway 已启动 (systemd)');
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// 备选:直接启动
|
|
442
|
+
log.info('尝试直接启动 Gateway...');
|
|
443
|
+
const startResult = safeExec(`${cliName} gateway &`, { timeout: 5000 });
|
|
444
|
+
if (startResult.ok || startResult.error?.includes('timeout')) {
|
|
445
|
+
log.success('Gateway 已启动');
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
log.warn('Gateway 启动可能失败,请手动检查');
|
|
450
|
+
log.hint(`手动启动: ${cliName} gateway`);
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// 主函数
|
|
455
|
+
async function main() {
|
|
456
|
+
const options = parseArgs();
|
|
457
|
+
|
|
458
|
+
console.log(colors.bold(colors.cyan('\n🦞 OpenClaw 一键安装\n')));
|
|
459
|
+
console.log(colors.gray('自动完成 OpenClaw 基础部署,无需交互\n'));
|
|
460
|
+
|
|
461
|
+
// 前置检查
|
|
462
|
+
checkNodeVersion();
|
|
463
|
+
log.success(`Node.js 版本: ${process.version}`);
|
|
464
|
+
|
|
465
|
+
// 检测现有安装
|
|
466
|
+
const existing = detectExistingInstall();
|
|
467
|
+
if (existing.installed) {
|
|
468
|
+
console.log(colors.yellow('\n检测到已有安装:'));
|
|
469
|
+
if (existing.configDir) {
|
|
470
|
+
log.detail(`配置目录: ${existing.configDir}`);
|
|
471
|
+
}
|
|
472
|
+
if (existing.version) {
|
|
473
|
+
log.detail(`版本: ${existing.version}`);
|
|
474
|
+
}
|
|
475
|
+
console.log(colors.cyan('\n如需重新安装,请先卸载:'));
|
|
476
|
+
console.log(` npm uninstall -g ${existing.name}`);
|
|
477
|
+
console.log(` rm -rf ~/.openclaw ~/.clawdbot`);
|
|
478
|
+
console.log('');
|
|
479
|
+
process.exit(0);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// 安装 CLI
|
|
483
|
+
const cliName = installOpenClaw();
|
|
484
|
+
|
|
485
|
+
// 创建配置
|
|
486
|
+
const config = createConfig(options);
|
|
487
|
+
|
|
488
|
+
// 配置服务持久化
|
|
489
|
+
if (!options.skipDaemon) {
|
|
490
|
+
setupDaemon(cliName);
|
|
491
|
+
} else {
|
|
492
|
+
log.info('跳过服务持久化配置 (--skip-daemon)');
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// 启动服务
|
|
496
|
+
if (!options.skipStart) {
|
|
497
|
+
startService(cliName);
|
|
498
|
+
} else {
|
|
499
|
+
log.info('跳过服务启动 (--skip-start)');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// 完成
|
|
503
|
+
console.log(colors.bold(colors.green('\n========================================')));
|
|
504
|
+
console.log(colors.bold(colors.green('✅ OpenClaw 安装完成!')));
|
|
505
|
+
console.log(colors.bold(colors.green('========================================')));
|
|
506
|
+
|
|
507
|
+
console.log(colors.cyan('\n配置信息:'));
|
|
508
|
+
console.log(` 配置目录: ${colors.yellow(config.configDir)}`);
|
|
509
|
+
console.log(` Gateway 端口: ${colors.yellow(config.port)}`);
|
|
510
|
+
console.log(` Gateway Token: ${colors.yellow(config.token)}`);
|
|
511
|
+
|
|
512
|
+
console.log(colors.cyan('\nDashboard 访问:'));
|
|
513
|
+
console.log(` ${colors.yellow(`http://127.0.0.1:${config.port}/?token=${config.token}`)}`);
|
|
514
|
+
|
|
515
|
+
console.log(colors.cyan('\n下一步 - 配置 AI 模型:'));
|
|
516
|
+
console.log(` ${colors.yellow('npx openclawapi@latest preset-claude')}`);
|
|
517
|
+
|
|
518
|
+
console.log(colors.cyan('\n常用命令:'));
|
|
519
|
+
console.log(` 查看状态: ${colors.yellow(`${cliName} status`)}`);
|
|
520
|
+
console.log(` 查看日志: ${colors.yellow(`${cliName} gateway logs`)}`);
|
|
521
|
+
console.log(` 重启服务: ${colors.yellow(`${cliName} gateway restart`)}`);
|
|
522
|
+
console.log(` 诊断问题: ${colors.yellow(`${cliName} doctor`)}`);
|
|
523
|
+
|
|
524
|
+
console.log(colors.cyan('\n配置聊天渠道:'));
|
|
525
|
+
console.log(` Discord: ${colors.yellow('npx openclawdc')}`);
|
|
526
|
+
console.log(` 飞书: ${colors.yellow('npx openclawfs')}`);
|
|
527
|
+
|
|
528
|
+
console.log('');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
main().catch((e) => {
|
|
532
|
+
exitWithError('CONFIG_FAILED', e.message, [
|
|
533
|
+
'检查网络连接',
|
|
534
|
+
'确保有足够的磁盘空间',
|
|
535
|
+
'查看详细错误信息并重试',
|
|
536
|
+
]);
|
|
537
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openclawsetup",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "一键安装 OpenClaw - 自动完成基础部署,无需交互",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"openclawsetup": "./bin/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node bin/cli.mjs"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/",
|
|
14
|
+
"README.md",
|
|
15
|
+
"使用说明.md"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"openclaw",
|
|
22
|
+
"clawdbot",
|
|
23
|
+
"moltbot",
|
|
24
|
+
"ai",
|
|
25
|
+
"assistant",
|
|
26
|
+
"setup",
|
|
27
|
+
"install"
|
|
28
|
+
],
|
|
29
|
+
"author": "OpenClaw Community",
|
|
30
|
+
"license": "MIT"
|
|
31
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# OpenClaw 一键安装 使用说明
|
|
2
|
+
|
|
3
|
+
## 快速开始
|
|
4
|
+
|
|
5
|
+
**方式一:默认安装(推荐)**
|
|
6
|
+
```bash
|
|
7
|
+
npx openclawsetup
|
|
8
|
+
```
|
|
9
|
+
自动完成所有配置,无需输入任何内容。
|
|
10
|
+
|
|
11
|
+
**方式二:指定端口**
|
|
12
|
+
```bash
|
|
13
|
+
# macOS/Linux
|
|
14
|
+
OPENCLAW_PORT=8080 npx openclawsetup
|
|
15
|
+
|
|
16
|
+
# Windows PowerShell
|
|
17
|
+
$env:OPENCLAW_PORT=8080; npx openclawsetup
|
|
18
|
+
|
|
19
|
+
# Windows CMD
|
|
20
|
+
set OPENCLAW_PORT=8080 && npx openclawsetup
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 安装完成后
|
|
24
|
+
|
|
25
|
+
1. **配置 AI 模型(必须)**
|
|
26
|
+
```bash
|
|
27
|
+
npx openclawapi@latest preset-claude
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. **访问 Dashboard**
|
|
31
|
+
```
|
|
32
|
+
http://127.0.0.1:18789/?token=<你的token>
|
|
33
|
+
```
|
|
34
|
+
Token 在安装完成时会显示。
|
|
35
|
+
|
|
36
|
+
3. **配置聊天渠道(可选)**
|
|
37
|
+
```bash
|
|
38
|
+
npx openclawdc # Discord
|
|
39
|
+
npx openclawfs # 飞书
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 常见问题
|
|
43
|
+
|
|
44
|
+
### 错误:Node.js 版本过低
|
|
45
|
+
**现象**:提示 "Node.js 版本过低"
|
|
46
|
+
**解决**:
|
|
47
|
+
1. 升级 Node.js 到 18 或更高版本
|
|
48
|
+
2. 访问 https://nodejs.org/ 下载最新版本
|
|
49
|
+
3. 或使用 nvm: `nvm install 22`
|
|
50
|
+
|
|
51
|
+
错误码: 1
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 错误:检测到已有安装
|
|
56
|
+
**现象**:提示 "检测到已有安装"
|
|
57
|
+
**解决**:
|
|
58
|
+
1. 如果想保留现有安装,无需操作
|
|
59
|
+
2. 如果想重新安装:
|
|
60
|
+
```bash
|
|
61
|
+
npm uninstall -g openclaw
|
|
62
|
+
rm -rf ~/.openclaw ~/.clawdbot
|
|
63
|
+
npx openclawsetup
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
错误码: 2
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### 错误:npm 安装失败
|
|
71
|
+
**现象**:提示 "npm 安装失败"
|
|
72
|
+
**解决**:
|
|
73
|
+
1. 检查网络连接
|
|
74
|
+
2. 尝试使用代理:
|
|
75
|
+
```bash
|
|
76
|
+
npm config set proxy http://proxy:port
|
|
77
|
+
```
|
|
78
|
+
3. 手动安装:
|
|
79
|
+
```bash
|
|
80
|
+
npm install -g openclaw@latest
|
|
81
|
+
```
|
|
82
|
+
4. Linux/macOS 可能需要 sudo:
|
|
83
|
+
```bash
|
|
84
|
+
sudo npm install -g openclaw@latest
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
错误码: 3
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### 错误:配置文件创建失败
|
|
92
|
+
**现象**:提示 "配置文件创建失败"
|
|
93
|
+
**解决**:
|
|
94
|
+
1. 检查目录权限:
|
|
95
|
+
```bash
|
|
96
|
+
ls -la ~/
|
|
97
|
+
```
|
|
98
|
+
2. 手动创建目录:
|
|
99
|
+
```bash
|
|
100
|
+
mkdir -p ~/.openclaw
|
|
101
|
+
```
|
|
102
|
+
3. 检查磁盘空间:
|
|
103
|
+
```bash
|
|
104
|
+
df -h
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
错误码: 4
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### 错误:服务持久化配置失败
|
|
112
|
+
**现象**:提示 "服务持久化配置失败"
|
|
113
|
+
**解决**:
|
|
114
|
+
1. 这不是致命错误,OpenClaw 仍可手动启动
|
|
115
|
+
2. 手动启动:
|
|
116
|
+
```bash
|
|
117
|
+
openclaw gateway
|
|
118
|
+
```
|
|
119
|
+
3. macOS 手动配置 launchd:
|
|
120
|
+
```bash
|
|
121
|
+
launchctl load ~/Library/LaunchAgents/com.openclaw.gateway.plist
|
|
122
|
+
```
|
|
123
|
+
4. Linux 手动配置 systemd:
|
|
124
|
+
```bash
|
|
125
|
+
systemctl --user daemon-reload
|
|
126
|
+
systemctl --user enable openclaw
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
错误码: 5
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### 错误:服务启动失败
|
|
134
|
+
**现象**:提示 "服务启动失败" 或 Gateway 无法访问
|
|
135
|
+
**解决**:
|
|
136
|
+
1. 手动启动:
|
|
137
|
+
```bash
|
|
138
|
+
openclaw gateway
|
|
139
|
+
```
|
|
140
|
+
2. 查看日志:
|
|
141
|
+
```bash
|
|
142
|
+
openclaw gateway logs
|
|
143
|
+
```
|
|
144
|
+
3. 检查端口占用:
|
|
145
|
+
```bash
|
|
146
|
+
# macOS/Linux
|
|
147
|
+
lsof -i :18789
|
|
148
|
+
|
|
149
|
+
# Windows
|
|
150
|
+
netstat -ano | findstr 18789
|
|
151
|
+
```
|
|
152
|
+
4. 运行诊断:
|
|
153
|
+
```bash
|
|
154
|
+
openclaw doctor
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
错误码: 6
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
### 错误:权限不足
|
|
162
|
+
**现象**:提示 "权限不足" 或 EACCES 错误
|
|
163
|
+
**解决**:
|
|
164
|
+
1. Linux/macOS 使用 sudo:
|
|
165
|
+
```bash
|
|
166
|
+
sudo npm install -g openclaw@latest
|
|
167
|
+
```
|
|
168
|
+
2. 或修复 npm 权限:
|
|
169
|
+
```bash
|
|
170
|
+
mkdir ~/.npm-global
|
|
171
|
+
npm config set prefix '~/.npm-global'
|
|
172
|
+
export PATH=~/.npm-global/bin:$PATH
|
|
173
|
+
```
|
|
174
|
+
3. 将上面的 export 添加到 `~/.bashrc` 或 `~/.zshrc`
|
|
175
|
+
|
|
176
|
+
错误码: 7
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 错误:不支持的操作系统
|
|
181
|
+
**现象**:提示 "不支持的操作系统"
|
|
182
|
+
**解决**:
|
|
183
|
+
1. 目前支持 macOS、Linux、Windows
|
|
184
|
+
2. Windows 建议使用 WSL2:
|
|
185
|
+
```powershell
|
|
186
|
+
wsl --install
|
|
187
|
+
```
|
|
188
|
+
3. 在 WSL2 中运行安装命令
|
|
189
|
+
|
|
190
|
+
错误码: 8
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### Dashboard 无法访问
|
|
195
|
+
**现象**:浏览器打开 Dashboard 显示无法连接
|
|
196
|
+
**解决**:
|
|
197
|
+
1. 确认 Gateway 正在运行:
|
|
198
|
+
```bash
|
|
199
|
+
openclaw status
|
|
200
|
+
```
|
|
201
|
+
2. 检查端口:
|
|
202
|
+
```bash
|
|
203
|
+
curl http://127.0.0.1:18789/health
|
|
204
|
+
```
|
|
205
|
+
3. 确认 Token 正确(在 `~/.openclaw/openclaw.json` 中查看)
|
|
206
|
+
4. 重启 Gateway:
|
|
207
|
+
```bash
|
|
208
|
+
openclaw gateway restart
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### 忘记 Token
|
|
214
|
+
**现象**:忘记了 Gateway Token
|
|
215
|
+
**解决**:
|
|
216
|
+
查看配置文件:
|
|
217
|
+
```bash
|
|
218
|
+
# macOS/Linux
|
|
219
|
+
cat ~/.openclaw/openclaw.json | grep token
|
|
220
|
+
|
|
221
|
+
# Windows PowerShell
|
|
222
|
+
Get-Content ~/.openclaw/openclaw.json | Select-String token
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
### 如何完全卸载
|
|
228
|
+
**步骤**:
|
|
229
|
+
```bash
|
|
230
|
+
# 1. 停止服务
|
|
231
|
+
openclaw gateway stop
|
|
232
|
+
|
|
233
|
+
# 2. 卸载 CLI
|
|
234
|
+
npm uninstall -g openclaw
|
|
235
|
+
|
|
236
|
+
# 3. 删除配置
|
|
237
|
+
rm -rf ~/.openclaw
|
|
238
|
+
|
|
239
|
+
# 4. 删除服务配置
|
|
240
|
+
# macOS
|
|
241
|
+
launchctl unload ~/Library/LaunchAgents/com.openclaw.gateway.plist
|
|
242
|
+
rm ~/Library/LaunchAgents/com.openclaw.gateway.plist
|
|
243
|
+
|
|
244
|
+
# Linux
|
|
245
|
+
systemctl --user stop openclaw
|
|
246
|
+
systemctl --user disable openclaw
|
|
247
|
+
rm ~/.config/systemd/user/openclaw.service
|
|
248
|
+
systemctl --user daemon-reload
|
|
249
|
+
|
|
250
|
+
# Windows PowerShell
|
|
251
|
+
Unregister-ScheduledTask -TaskName "OpenClaw" -Confirm:$false
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## 获取帮助
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npx openclawsetup --help
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
如有其他问题,请查看日志或运行诊断:
|
|
261
|
+
```bash
|
|
262
|
+
openclaw gateway logs
|
|
263
|
+
openclaw doctor
|
|
264
|
+
```
|