@rethinkingstudio/clawpilot 1.0.9 → 1.0.11

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.
@@ -46,8 +46,10 @@ export function readGatewayUrl(): string {
46
46
  }
47
47
 
48
48
  /**
49
- * Reads the gateway token or password from the clawai config first,
50
- * then falls back to reading directly from the OpenClaw config file.
49
+ * Reads the gateway token or password. Priority order:
50
+ * 1. ~/.clawai/config.json (gatewayToken / gatewayPassword)
51
+ * 2. ~/.openclaw/openclaw.json (gateway.token / gateway.auth.token)
52
+ * 3. Environment variables (OPENCLAW_GATEWAY_TOKEN / OPENCLAW_GATEWAY_PASSWORD)
51
53
  */
52
54
  export function readGatewayAuth(cfg: ClawaiConfig): { token?: string; password?: string } {
53
55
  if (cfg.gatewayToken || cfg.gatewayPassword) {
@@ -57,11 +59,17 @@ export function readGatewayAuth(cfg: ClawaiConfig): { token?: string; password?:
57
59
  try {
58
60
  const raw = readFileSync(OPENCLAW_CONFIG_PATH, "utf-8");
59
61
  const json = JSON.parse(raw) as { gateway?: { token?: string; password?: string; auth?: { token?: string; password?: string } } };
60
- return {
61
- token: json?.gateway?.token ?? json?.gateway?.auth?.token ?? undefined,
62
- password: json?.gateway?.password ?? json?.gateway?.auth?.password ?? undefined,
63
- };
62
+ const token = json?.gateway?.token ?? json?.gateway?.auth?.token ?? undefined;
63
+ const password = json?.gateway?.password ?? json?.gateway?.auth?.password ?? undefined;
64
+ if (token || password) return { token, password };
64
65
  } catch {
65
- return {};
66
+ // ignore
66
67
  }
68
+ // Fall back to environment variables (e.g. set via LaunchAgent)
69
+ const envToken = process.env.OPENCLAW_GATEWAY_TOKEN;
70
+ const envPassword = process.env.OPENCLAW_GATEWAY_PASSWORD;
71
+ if (envToken || envPassword) {
72
+ return { token: envToken, password: envPassword };
73
+ }
74
+ return {};
67
75
  }
@@ -0,0 +1,151 @@
1
+ type Locale = "en" | "zh";
2
+ type MsgFn = (...args: string[]) => string;
3
+ type MsgValue = string | MsgFn;
4
+
5
+ const en: Record<string, MsgValue> = {
6
+ // pair
7
+ "pair.alreadyRegistered": (id) => `Gateway already registered (id=${id}). Refreshing access code…`,
8
+ "pair.invalidCredentials": "Invalid credentials (401). The server doesn't recognize this gateway.\nRun `clawpilot reset` to clear config and re-register.",
9
+ "pair.refreshFailed": (status, body) => `Failed to refresh access code: ${status} ${body}`,
10
+ "pair.registering": "Registering with relay server…",
11
+ "pair.registrationFailed": (status, body) => `Registration failed: ${status} ${body}`,
12
+ "pair.registered": (id) => `Registered! Gateway ID: ${id}`,
13
+ "pair.scanQR": "\nScan this QR code with the Clawai iOS app:\n",
14
+ "pair.accessCode": (code) => `\nAccess code (one-time use): ${code}`,
15
+ "pair.installingService": "\nInstalling/updating relay background service…",
16
+
17
+ // run
18
+ "run.starting": "Starting ClawAI relay client…",
19
+ "run.gatewayId": (id) => ` Gateway ID: ${id}`,
20
+ "run.relayServer": (url) => ` Relay Server: ${url}`,
21
+ "run.gatewayUrl": (url) => ` Gateway URL: ${url}`,
22
+ "run.connected": "Relay connected.",
23
+ "run.disconnected": "Relay disconnected. Reconnecting…",
24
+ "run.retry": (attempt, delay) => `Retry attempt ${attempt}, waiting ${delay}ms…`,
25
+
26
+ // install
27
+ "install.serviceStarted": (label) => `Service installed and started: ${label}`,
28
+ "install.loadFailed": "Failed to load launchd service:",
29
+ "install.plistWritten": (path) => `Plist written to: ${path}`,
30
+ "install.loadManually": (path) => `Run manually: launchctl load -w "${path}"`,
31
+ "install.restarting": "Restarting relay service…",
32
+ "install.serviceStopped": (label) => `Service stopped: ${label}`,
33
+ "install.removePlistFailed": "Failed to remove plist:",
34
+ "install.plistRemoved": (path) => `Plist removed: ${path}`,
35
+ "install.stopped": (label) => `Stopped: ${label}`,
36
+ "install.stoppedAndRemoved": "Relay client stopped and removed from launchd.",
37
+ "install.noService": "No running relay service found.",
38
+ "install.configRemoved": (path) => `Config removed: ${path}`,
39
+ "install.removeConfigFailed": "Failed to remove config:",
40
+ "install.noConfig": "No config file found.",
41
+ "install.resetComplete": "\nReset complete. Run `clawpilot pair` to re-register.",
42
+
43
+ // status
44
+ "status.title": "── ClawPilot Relay Client Status ──\n",
45
+ "status.notPaired": "Config: ✗ Not paired — run 'clawpilot pair' first",
46
+ "status.paired": "Config: ✓ Paired",
47
+ "status.displayName": (name) => ` Display name : ${name}`,
48
+ "status.gatewayId": (id) => ` Gateway ID : ${id}`,
49
+ "status.relayServer": (url) => ` Relay server : ${url}`,
50
+ "status.configCorrupted": "Config: ✗ File exists but is corrupted",
51
+ "status.gateway": (url) => `\nGateway: ${url}`,
52
+ "status.serviceNotInstalled": "\nService: ✗ Not installed — run 'clawpilot install'",
53
+ "status.serviceRunning": "\nService: ✓ Running (launchd)",
54
+ "status.serviceLog": (path) => ` Log : ${path}`,
55
+ "status.serviceNotRunning": "\nService: ⚠ Installed but not running",
56
+ "status.servicePlist": (path) => ` Plist : ${path}`,
57
+ "status.serviceStart": (label) => ` Start : launchctl start ${label}`,
58
+
59
+ // set-token
60
+ "setToken.noPairing": "No pairing config found. Run 'clawpilot pair' first.",
61
+ "setToken.whereToFind": "\nWhere to find your Gateway Token:",
62
+ "setToken.option1": " Option 1 — OpenClaw desktop app: Settings → Advanced → Gateway Token",
63
+ "setToken.option2": " Option 2 — Terminal:",
64
+ "setToken.option2cmd": " cat ~/.openclaw/openclaw.json | grep -A2 'auth'",
65
+ "setToken.option3": " Option 3 — If set via environment variable: echo $OPENCLAW_GATEWAY_TOKEN\n",
66
+ "setToken.prompt": "Gateway Token (leave blank to clear): ",
67
+ "setToken.saved": "\nToken saved to ~/.clawai/config.json.",
68
+ "setToken.cleared": "\nToken cleared from ~/.clawai/config.json.",
69
+ "setToken.restart": "Run 'clawpilot restart' to apply the change.\n",
70
+ };
71
+
72
+ const zh: Record<string, MsgValue> = {
73
+ // pair
74
+ "pair.alreadyRegistered": (id) => `网关已注册 (id=${id}),正在刷新访问码…`,
75
+ "pair.invalidCredentials": "凭证无效 (401),服务器无法识别此网关。\n请运行 `clawpilot reset` 清除配置后重新注册。",
76
+ "pair.refreshFailed": (status, body) => `刷新访问码失败:${status} ${body}`,
77
+ "pair.registering": "正在向中继服务器注册…",
78
+ "pair.registrationFailed": (status, body) => `注册失败:${status} ${body}`,
79
+ "pair.registered": (id) => `注册成功!网关 ID:${id}`,
80
+ "pair.scanQR": "\n请用 Clawai iOS 应用扫描此二维码:\n",
81
+ "pair.accessCode": (code) => `\n访问码(一次性使用):${code}`,
82
+ "pair.installingService": "\n正在安装/更新中继后台服务…",
83
+
84
+ // run
85
+ "run.starting": "正在启动 ClawAI 中继客户端…",
86
+ "run.gatewayId": (id) => ` 网关 ID: ${id}`,
87
+ "run.relayServer": (url) => ` 中继服务器:${url}`,
88
+ "run.gatewayUrl": (url) => ` 网关地址: ${url}`,
89
+ "run.connected": "中继已连接。",
90
+ "run.disconnected": "中继已断开,正在重连…",
91
+ "run.retry": (attempt, delay) => `第 ${attempt} 次重试,等待 ${delay}ms…`,
92
+
93
+ // install
94
+ "install.serviceStarted": (label) => `服务已安装并启动:${label}`,
95
+ "install.loadFailed": "加载 launchd 服务失败:",
96
+ "install.plistWritten": (path) => `Plist 已写入:${path}`,
97
+ "install.loadManually": (path) => `请手动运行:launchctl load -w "${path}"`,
98
+ "install.restarting": "正在重启中继服务…",
99
+ "install.serviceStopped": (label) => `服务已停止:${label}`,
100
+ "install.removePlistFailed": "删除 Plist 失败:",
101
+ "install.plistRemoved": (path) => `Plist 已删除:${path}`,
102
+ "install.stopped": (label) => `已停止:${label}`,
103
+ "install.stoppedAndRemoved": "中继客户端已停止并从 launchd 移除。",
104
+ "install.noService": "未找到正在运行的中继服务。",
105
+ "install.configRemoved": (path) => `配置文件已删除:${path}`,
106
+ "install.removeConfigFailed": "删除配置文件失败:",
107
+ "install.noConfig": "未找到配置文件。",
108
+ "install.resetComplete": "\n重置完成。请运行 `clawpilot pair` 重新注册。",
109
+
110
+ // status
111
+ "status.title": "── ClawPilot 中继客户端状态 ──\n",
112
+ "status.notPaired": "配置:✗ 未配对 — 请先运行 'clawpilot pair'",
113
+ "status.paired": "配置:✓ 已配对",
114
+ "status.displayName": (name) => ` 显示名称:${name}`,
115
+ "status.gatewayId": (id) => ` 网关 ID: ${id}`,
116
+ "status.relayServer": (url) => ` 中继服务器:${url}`,
117
+ "status.configCorrupted": "配置:✗ 文件存在但已损坏",
118
+ "status.gateway": (url) => `\n网关地址:${url}`,
119
+ "status.serviceNotInstalled": "\n服务:✗ 未安装 — 请运行 'clawpilot install'",
120
+ "status.serviceRunning": "\n服务:✓ 运行中 (launchd)",
121
+ "status.serviceLog": (path) => ` 日志:${path}`,
122
+ "status.serviceNotRunning": "\n服务:⚠ 已安装但未运行",
123
+ "status.servicePlist": (path) => ` Plist:${path}`,
124
+ "status.serviceStart": (label) => ` 启动命令:launchctl start ${label}`,
125
+
126
+ // set-token
127
+ "setToken.noPairing": "未找到配对配置,请先运行 'clawpilot pair'。",
128
+ "setToken.whereToFind": "\n如何查找 Gateway Token:",
129
+ "setToken.option1": " 方式一 — OpenClaw 桌面应用:设置 → 高级 → Gateway Token",
130
+ "setToken.option2": " 方式二 — 终端:",
131
+ "setToken.option2cmd": " cat ~/.openclaw/openclaw.json | grep -A2 'auth'",
132
+ "setToken.option3": " 方式三 — 若通过环境变量设置:echo $OPENCLAW_GATEWAY_TOKEN\n",
133
+ "setToken.prompt": "Gateway Token(留空则清除):",
134
+ "setToken.saved": "\nToken 已保存到 ~/.clawai/config.json。",
135
+ "setToken.cleared": "\nToken 已从 ~/.clawai/config.json 清除。",
136
+ "setToken.restart": "请运行 'clawpilot restart' 使修改生效。\n",
137
+ };
138
+
139
+ function detectLocale(): Locale {
140
+ const lang = process.env.LANG ?? process.env.LC_ALL ?? process.env.LANGUAGE ?? "";
141
+ return lang.toLowerCase().startsWith("zh") ? "zh" : "en";
142
+ }
143
+
144
+ const locale: Locale = detectLocale();
145
+ const msgs = locale === "zh" ? zh : en;
146
+
147
+ export function t(key: string, ...args: string[]): string {
148
+ const val = msgs[key] ?? en[key] ?? key;
149
+ if (typeof val === "function") return (val as MsgFn)(...args);
150
+ return val as string;
151
+ }
package/src/index.ts CHANGED
@@ -4,8 +4,9 @@ import { pairCommand } from "./commands/pair.js";
4
4
  import { runCommand } from "./commands/run.js";
5
5
  import { installCommand, uninstallCommand, stopCommand, restartCommand, resetCommand } from "./commands/install.js";
6
6
  import { statusCommand } from "./commands/status.js";
7
+ import { setTokenCommand } from "./commands/set-token.js";
7
8
 
8
- const version = "1.0.9";
9
+ const version = "1.0.11";
9
10
 
10
11
  const program = new Command();
11
12
 
@@ -75,6 +76,18 @@ program
75
76
  uninstallCommand();
76
77
  });
77
78
 
79
+ program
80
+ .command("set-token")
81
+ .description("Set the local OpenClaw gateway token (needed when using token auth)")
82
+ .action(async () => {
83
+ try {
84
+ await setTokenCommand();
85
+ } catch (err) {
86
+ console.error("Error:", err instanceof Error ? err.message : err);
87
+ process.exit(1);
88
+ }
89
+ });
90
+
78
91
  program
79
92
  .command("reset")
80
93
  .description("Clear saved config and stop service — use when switching servers or on auth errors")