@foxden-app/foxclaw 0.2.7 → 0.3.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,460 @@
1
+ # FoxClaw 用户手册
2
+
3
+ FoxClaw 把本机 Codex 包成一个可从手机控制的服务。Telegram 或微信负责聊天入口,FoxClaw 负责鉴权、线程绑定、审批、设置面板和账号切换,真正执行代码的是你电脑上的 `codex app-server`。
4
+
5
+ 典型链路:
6
+
7
+ ```text
8
+ 手机 Telegram/微信
9
+ -> FoxClaw bot
10
+ -> 本机 FoxClaw 服务
11
+ -> codex app-server
12
+ -> DEFAULT_CWD 或当前线程目录
13
+ ```
14
+
15
+ 代码、shell 权限、Codex 认证和运行数据都留在这台电脑上。第一次安装建议先跑通 Telegram 私聊,再考虑群组、话题或微信通道。
16
+
17
+ ## 1. 完整安装流程
18
+
19
+ ### 1.1 安装 Node.js 24
20
+
21
+ FoxClaw 需要 Node.js 24。先检查:
22
+
23
+ ```bash
24
+ node -v
25
+ ```
26
+
27
+ 如果不是 `v24...`,推荐用 `nvm`:
28
+
29
+ ```bash
30
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
31
+ export NVM_DIR="$HOME/.nvm"
32
+ [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
33
+ nvm install 24
34
+ nvm use 24
35
+ node -v
36
+ ```
37
+
38
+ ### 1.2 安装并登录 Codex
39
+
40
+ FoxClaw 不替你创建 Codex 账号,它使用这台机器上已经登录的 Codex CLI。
41
+
42
+ ```bash
43
+ npm install -g @openai/codex
44
+ codex login
45
+ codex --version
46
+ ```
47
+
48
+ `codex --version` 只能证明命令存在。真正的验证方式是启动 Codex 并让它完成一个小请求:
49
+
50
+ ```bash
51
+ codex
52
+ ```
53
+
54
+ 然后输入:
55
+
56
+ ```text
57
+ Say ready and exit.
58
+ ```
59
+
60
+ 如果 Codex 能正常回答,FoxClaw 才有可用的底层执行环境。
61
+
62
+ ### 1.3 创建 Telegram bot
63
+
64
+ 1. 打开 Telegram。
65
+ 2. 搜索 `@BotFather`。
66
+ 3. 发送 `/newbot`。
67
+ 4. 按提示设置 bot 名称和 username。
68
+ 5. 复制 bot token,格式类似 `123456789:AA...`。
69
+
70
+ 这个 token 等同于 bot 的控制权,不要发给不信任的人。
71
+
72
+ ### 1.4 获取 Telegram 数字用户 ID
73
+
74
+ FoxClaw 只响应 `TG_ALLOWED_USER_ID` 配置的用户。
75
+
76
+ 1. 打开 Telegram。
77
+ 2. 搜索 `@userinfobot`。
78
+ 3. 给它发任意消息或点击 Start。
79
+ 4. 复制返回里的数字 `Id`。
80
+
81
+ 请填数字 ID,不要填 `@username`。
82
+
83
+ ### 1.5 安装 FoxClaw
84
+
85
+ 如果你用 pnpm 管理全局包:
86
+
87
+ ```bash
88
+ pnpm add -g @foxden-app/foxclaw
89
+ foxclaw init
90
+ ```
91
+
92
+ 如果你用 npm:
93
+
94
+ ```bash
95
+ npm install -g @foxden-app/foxclaw
96
+ foxclaw init
97
+ ```
98
+
99
+ 两种方式都安装同一个 npm 发布包。建议一台机器上固定使用一种全局包管理器,避免 PATH 里出现多个版本。
100
+
101
+ ### 1.6 填写配置
102
+
103
+ 默认配置文件是 `~/.foxclaw/.env`:
104
+
105
+ ```bash
106
+ $EDITOR ~/.foxclaw/.env
107
+ ```
108
+
109
+ 第一次私聊模式的最小配置:
110
+
111
+ ```dotenv
112
+ TG_BOT_TOKEN=123456789:replace_with_your_bot_token
113
+ TG_ALLOWED_USER_ID=123456789
114
+ TG_ALLOWED_CHAT_ID=
115
+ TG_ALLOWED_TOPIC_ID=
116
+ DEFAULT_CWD=/absolute/path/to/workspace
117
+ DEFAULT_APPROVAL_POLICY=on-request
118
+ DEFAULT_SANDBOX_MODE=workspace-write
119
+ ```
120
+
121
+ 字段说明:
122
+
123
+ - `TG_BOT_TOKEN`:从 `@BotFather` 拿到的 bot token。
124
+ - `TG_ALLOWED_USER_ID`:你的 Telegram 数字用户 ID。
125
+ - `TG_ALLOWED_CHAT_ID`:第一次保持为空,表示私聊模式。
126
+ - `TG_ALLOWED_TOPIC_ID`:第一次保持为空,表示不绑定 Telegram 话题。
127
+ - `DEFAULT_CWD`:Codex 默认工作的目录,必须真实存在。
128
+ - `DEFAULT_APPROVAL_POLICY`:建议首次使用 `on-request`,需要时手机审批。
129
+ - `DEFAULT_SANDBOX_MODE`:建议首次使用 `workspace-write`。
130
+
131
+ ### 1.7 检查并启动
132
+
133
+ ```bash
134
+ foxclaw doctor
135
+ foxclaw start
136
+ foxclaw status
137
+ ```
138
+
139
+ Linux 查看服务日志:
140
+
141
+ ```bash
142
+ systemctl --user status foxclaw.service
143
+ journalctl --user -u foxclaw.service -f
144
+ ```
145
+
146
+ macOS 上 `foxclaw start` 会管理 launchd。前台排障时,先停后台服务,再运行:
147
+
148
+ ```bash
149
+ foxclaw serve
150
+ ```
151
+
152
+ ### 1.8 第一次 Telegram 验证
153
+
154
+ 打开你的 bot 私聊,依次发送:
155
+
156
+ ```text
157
+ /help
158
+ ```
159
+
160
+ ```text
161
+ /status
162
+ ```
163
+
164
+ ```text
165
+ /setup
166
+ ```
167
+
168
+ 然后发一个普通请求:
169
+
170
+ ```text
171
+ List files in DEFAULT_CWD.
172
+ ```
173
+
174
+ 如果能收到 Codex 返回,基础链路已经跑通。
175
+
176
+ ## 2. 群组和话题
177
+
178
+ 私聊最稳。确认私聊可用后,再配置群组或 topic。
179
+
180
+ ```dotenv
181
+ TG_ALLOWED_CHAT_ID=-1001234567890
182
+ TG_ALLOWED_TOPIC_ID=42
183
+ ```
184
+
185
+ - `TG_ALLOWED_CHAT_ID` 留空:只使用私聊。
186
+ - 只填 `TG_ALLOWED_CHAT_ID`:允许一个群作为默认会话范围。
187
+ - 两个都填:绑定到某个 topic。
188
+ - 配了群组后,`TG_ALLOWED_USER_ID` 的私聊仍然可用。
189
+
190
+ 获取群组或 topic ID:
191
+
192
+ 1. 停掉 FoxClaw。
193
+ 2. 在目标群组或 topic 里发一条消息。
194
+ 3. 浏览器打开:
195
+
196
+ ```text
197
+ https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
198
+ ```
199
+
200
+ 4. 用 `message.chat.id` 填 `TG_ALLOWED_CHAT_ID`。
201
+ 5. 用 `message.message_thread_id` 填 `TG_ALLOWED_TOPIC_ID`。
202
+
203
+ 如果 FoxClaw 还在运行,它可能已经消费掉这条 update,浏览器里就看不到。
204
+
205
+ 群组里还需要:
206
+
207
+ - 把 bot 加入群。
208
+ - 在 `@BotFather` 里关闭 privacy mode。
209
+ - 把 bot 设为群管理员。
210
+ - 用普通自然语言消息验证,不要只用 `/status@botname` 验证。
211
+
212
+ ## 3. 命令使用说明
213
+
214
+ ### 3.1 `/help`
215
+
216
+ `/help` 返回当前可用命令列表。顶部会固定显示最常用入口:
217
+
218
+ ```text
219
+ /help
220
+ /setup
221
+ /status
222
+ /threads [query]
223
+ /auth
224
+ ```
225
+
226
+ 后面的命令会按你最近使用情况排序。直接发送普通文本、图片或文件时,FoxClaw 会继续当前绑定线程;如果没有绑定线程,会自动新建线程。
227
+
228
+ ### 3.2 `/status`、`/account`、`/quota`
229
+
230
+ - `/status`:查看 FoxClaw、app-server、当前绑定线程、模型、权限和 Codex 用量摘要。
231
+ - `/account`:查看当前 Codex 登录账号。
232
+ - `/quota`:查看 Codex 用量和额度窗口。
233
+
234
+ ### 3.3 `/config`、`/requirements`、`/provider`
235
+
236
+ - `/config`:读取当前线程目录或 `DEFAULT_CWD` 下的 Codex 配置摘要,包含 `model`、`approval_policy`、`sandbox_mode`、`service_tier` 等关键项。
237
+ - `/requirements`:查看 app-server 暴露的配置约束,例如允许的 approval、sandbox、web search 模式。
238
+ - `/provider`:查看当前 Codex provider 配置摘要。
239
+
240
+ 这些命令适合排查“为什么手机上跑出来的权限、模型或 provider 和预期不同”。
241
+
242
+ ## 4. `/setup` 会话设置面板
243
+
244
+ `/setup` 是手机端最重要的面板之一。它按聊天范围保存设置,私聊、群组、topic 可以有不同设置。
245
+
246
+ 它能配置:
247
+
248
+ - 模型:使用服务端默认模型,或选择 app-server 返回的模型。
249
+ - reasoning effort:例如 `low`、`medium`、`high`、`xhigh`,取决于模型支持情况。
250
+ - Fast tier:模型支持时可开关 fast 服务档。
251
+ - Access:`read-only`、`default`、`full-access`。
252
+ - Mode:`Agent` 或 `Plan`。
253
+ - Active turn:新消息是 steer 当前 turn,还是 queue 到下一轮。
254
+
255
+ Telegram 会把 HTML 和按钮渲染出来。这里用等宽框模拟实际面板:
256
+
257
+ ```text
258
+ 会话偏好
259
+ 当前:gpt-5.5 · high · fast=off · default · Agent · Steer current turn
260
+ Focus: Model
261
+
262
+ Model: gpt-5.5
263
+ Effort: high
264
+ Fast: off
265
+ Access: Default (on-request / workspace-write)
266
+ Mode: Agent
267
+ Active turn: Steer current turn
268
+
269
+ [自动] [gpt-5.5]
270
+ [low] [medium] [high]
271
+ [⚡ Fast on] [Fast off]
272
+ [👁️ Read-only] [🛡️ Default] [🔓 Full access]
273
+ [Agent] [📝 Plan]
274
+ [Steer current turn] [Queue next turn]
275
+ ```
276
+
277
+ 常用命令别名:
278
+
279
+ - `/model <model|default>`:快速切模型。
280
+ - `/effort <effort|default>`:快速切 reasoning effort。
281
+ - `/permissions [read-only|default|full-access]`:快速切权限预设。
282
+ - `/mode [default|plan]`:切 Agent/Plan。
283
+ - `/active <steer|queue>`:控制当前 turn 有新消息时的处理方式。
284
+
285
+ ## 5. 线程和观察
286
+
287
+ FoxClaw 的聊天是“绑定线程”的。你在手机上打开某个 Codex 线程后,普通消息会继续发到这个线程。
288
+
289
+ 常用命令:
290
+
291
+ - `/threads [query]`:列出最近线程,可加关键词过滤。
292
+ - `/threads archived [query]`:列出已归档线程。
293
+ - `/open <n>`:打开最近一次 `/threads` 列表里的第 n 个线程,并绑定当前聊天。
294
+ - `/new [cwd]`:在指定目录或默认目录新建线程。
295
+ - `/where`:查看当前聊天绑定到哪个线程、目录和设置。
296
+ - `/rename <name>`:重命名当前线程。
297
+ - `/archive`:归档当前线程。
298
+ - `/interrupt`:中断当前正在跑的 turn。
299
+
300
+ 线程面板示意:
301
+
302
+ ```text
303
+ 最近线程
304
+ 点击下方按钮即可切换或管理线程。
305
+ 显示第 1-5 条
306
+ 当前:fix auth rotation
307
+ ~/Projects/foxclaw | 3 minutes ago | idle
308
+
309
+ [🧵 1. fix auth rotation]
310
+ [✏️] [👀] [🗑️] [➕]
311
+
312
+ [🧵 2. polish README copy]
313
+ [✏️] [👀] [🗑️] [➕]
314
+
315
+ [➕ 新建]
316
+ [➡️ 下一页]
317
+ [🗄️ 已归档]
318
+ ```
319
+
320
+ ### `/watch`
321
+
322
+ `/watch` 用来观察一个线程,不一定要从这个聊天发起任务。常见场景是你在电脑上的 Codex CLI 里启动了长任务,然后出门,用手机观察进展。
323
+
324
+ 用法:
325
+
326
+ - `/watch`:观察当前绑定线程。
327
+ - `/watch <n>`:观察最近一次 `/threads` 列表里的第 n 个线程。
328
+ - `/unwatch`:停止观察。
329
+
330
+ 观察模式会同步 live turn 进展和审批请求。观察中的聊天默认是只读的,普通 prompt 不会直接插入正在观察的 turn;需要发新任务时先 `/unwatch`,或等当前 turn 完成。
331
+
332
+ ## 6. Codex 登录和 auth 轮转
333
+
334
+ 这是 FoxClaw 的特色功能。Codex 的登录状态通常保存在 `~/.codex/auth.json`。FoxClaw 把多个账号保存成候选文件,并通过切换 `auth.json` 指向哪个候选来换号。
335
+
336
+ ### 6.1 文件格式
337
+
338
+ 候选文件放在 Codex auth 目录,默认是 `~/.codex/`。如果你设置了 `CODEX_AUTH_DIR`,则使用那个目录。
339
+
340
+ 推荐命名:
341
+
342
+ ```text
343
+ ~/.codex/
344
+ auth.json -> /home/alice/.codex/auth.json_personal
345
+ auth.json_personal
346
+ auth.json_team
347
+ auth.json_plus_trial
348
+ ```
349
+
350
+ FoxClaw 识别这些候选文件名:
351
+
352
+ - `auth.json_<name>`
353
+ - `auth.json.<name>`
354
+ - `auth.json-<name>`
355
+
356
+ `auth.json` 是 Codex 当前使用的文件。切换账号时,FoxClaw 会把 `auth.json` 指向某个候选文件。候选文件内容是 Codex CLI 生成的 JSON,FoxClaw 不依赖里面的私密字段,也不建议手写这些字段。
357
+
358
+ 如果你已经有一个可用的 `auth.json`,可以先备份成候选:
359
+
360
+ ```bash
361
+ cp -L ~/.codex/auth.json ~/.codex/auth.json_personal
362
+ ```
363
+
364
+ 更推荐用 `/auth add <name>` 从手机端添加新候选。
365
+
366
+ ### 6.2 登录命令
367
+
368
+ - `/login_device`:为当前 `auth.json` 发起 ChatGPT 设备码登录,FoxClaw 会返回登录 URL、短码、login id 和取消命令。
369
+ - `/login_cancel [id]`:取消一个进行中的设备码登录。
370
+ - `/logout confirm`:退出当前 Codex 登录。
371
+ - `/auth add <name>`:新增一个候选账号,例如 `/auth add work` 会创建 `auth.json_work` 并发起设备码登录。
372
+
373
+ `/auth add <name>` 的流程:
374
+
375
+ 1. FoxClaw 准备 `auth.json_<name>`。
376
+ 2. 临时把当前 `auth.json` 指向这个候选。
377
+ 3. 重启 app-server,让 Codex 写入新候选。
378
+ 4. 返回登录 URL 和短码。
379
+ 5. 你在浏览器里完成登录。
380
+ 6. 成功后,这个候选会出现在 `/auth` 面板里。
381
+
382
+ 如果取消或失败,FoxClaw 会尽量恢复之前的 auth 指向,并删除未完成的新候选。
383
+
384
+ ### 6.3 `/auth` 面板
385
+
386
+ `/auth` 会列出候选账号、当前账号和 auth 目录,并提供按钮切换、禁用、登录和重载。
387
+
388
+ 示意:
389
+
390
+ ```text
391
+ Codex auth
392
+ Current: auth.json_personal
393
+ Auth dir: /home/alice/.codex
394
+ Candidates: 2
395
+ 1. auth.json_personal * [enabled]
396
+ 2. auth.json_team [enabled]
397
+
398
+ [✅ auth.json_personal] [✅]
399
+ [🔐 auth.json_team] [✅]
400
+ [🛡️ Access] [🔑 设备登录]
401
+ [🔄 Reload auth]
402
+ ```
403
+
404
+ 右侧 `✅` / `⏸️` 表示当前状态。点一下会切换启用/禁用,列表刷新后图标会随状态变化。
405
+
406
+ 命令等价用法:
407
+
408
+ - `/auth` 或 `/auth list`:查看候选。
409
+ - `/auth use <n>`:切到第 n 个候选并重启 app-server。
410
+ - `/auth enable <n>`:让第 n 个候选参与自动轮转。
411
+ - `/auth disable <n>`:禁用第 n 个候选,自动轮转会跳过它。
412
+ - `/auth reload` 或 `/auth_reload`:重启 app-server,重新加载当前 `auth.json`。
413
+
414
+ 切换 auth 时,如果当前还有活跃 turn、待审批、待用户输入或 MCP elicitation,FoxClaw 会先拒绝切换,避免中途换号破坏正在进行的请求。
415
+
416
+ ### 6.4 自动轮转如何工作
417
+
418
+ 当 Codex 返回用量限制、未登录、认证失效或类似 auth 错误时,FoxClaw 会尝试自动轮转:
419
+
420
+ 1. 记录当前失败的候选。
421
+ 2. 从候选列表里选择下一个已启用、还没在本次重试中失败的账号。
422
+ 3. 把 `auth.json` 指向这个候选。
423
+ 4. 重启 `codex app-server`,让新认证生效。
424
+ 5. 用新账号重试刚才失败的请求。
425
+
426
+ 禁用的候选不会参与轮转。如果没有可用候选,FoxClaw 会把错误发回手机,并停止自动重试。
427
+
428
+ 适合的账号组织方式:
429
+
430
+ ```text
431
+ auth.json_personal # 主账号
432
+ auth.json_team # Team 或工作账号
433
+ auth.json_plus_trial # 试用账号
434
+ auth.json_backup # 备用账号,可按需 enable/disable
435
+ ```
436
+
437
+ ## 7. 一个典型日常流程
438
+
439
+ 1. 在电脑上进入项目目录,确保 Codex 能运行。
440
+ 2. 手机给 bot 发 `/new /home/alice/Projects/app`,或先 `/threads` 再打开已有线程。
441
+ 3. 用 `/setup` 选择模型、effort、权限和 Agent/Plan 模式。
442
+ 4. 发送任务,例如“修掉 failing test,并跑相关测试”。
443
+ 5. 离开电脑后,用手机看实时进展。
444
+ 6. 有命令或文件修改审批时,在手机上点批准、拒绝或本次会话允许。
445
+ 7. 需要观察电脑上 CLI 启动的任务时,用 `/threads` 找到线程,再点 `👀` 或发 `/watch <n>`。
446
+ 8. 额度到限制时,让 `/auth` 候选自动轮转,或手动 `/auth use <n>`。
447
+
448
+ ## 8. 安全建议
449
+
450
+ - 不要把 `TG_BOT_TOKEN`、`~/.codex/auth.json*` 或 `.env` 发给别人。
451
+ - 第一次不要把 `DEFAULT_CWD` 设成 `/`、`/home`、`/Users` 或整个 home。
452
+ - 不确定权限时,用 `/permissions read-only` 或 `/setup` 选 `Read-only`。
453
+ - 群组模式只允许配置的 `TG_ALLOWED_USER_ID` 操作,但仍建议只放进可信群。
454
+ - 多账号文件里是 Codex 登录凭据,备份和同步时按敏感文件处理。
455
+
456
+ ## 9. 后续阅读
457
+
458
+ - [新手安装指南](./install-for-beginners.md)
459
+ - [Agent 辅助安装](./agent-assisted-install.md)
460
+ - [故障排查](./troubleshooting.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxden-app/foxclaw",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "description": "Foxden local execution claw for controlling Codex from trusted chat interfaces.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: npm-publish
3
+ description: Publish npm packages safely, especially packages that require npm 2FA/web-auth confirmation. Use when Codex is asked to run npm publish, release a new package version, handle npm EOTP errors, generate an npm web-auth URL for the user, or verify an npm package version after publishing.
4
+ ---
5
+
6
+ # NPM Publish
7
+
8
+ Use this skill to publish an npm package from a repo while preserving the exact web-auth flow that works in this environment.
9
+
10
+ ## Release Checklist
11
+
12
+ 1. Sync first when the user asks for it:
13
+ ```bash
14
+ git pull
15
+ ```
16
+
17
+ 2. Confirm the package state:
18
+ ```bash
19
+ git status --short --branch
20
+ npm whoami
21
+ npm view <package-name> version
22
+ ```
23
+
24
+ 3. If the package version is already published, bump it before publishing:
25
+ ```bash
26
+ npm version patch --no-git-tag-version
27
+ ```
28
+
29
+ 4. Run the repo's normal verification before publishing. Prefer the package scripts that exist:
30
+ ```bash
31
+ npm run typecheck
32
+ npm run lint
33
+ npm test
34
+ npm pack --dry-run
35
+ ```
36
+
37
+ 5. Commit and push source changes before `npm publish` when the user asked to push or when this is a normal release:
38
+ ```bash
39
+ git add <changed-files>
40
+ git commit -m "<release message>"
41
+ git push
42
+ ```
43
+
44
+ ## 2FA Web Auth Publish Flow
45
+
46
+ Use this exact flow when npm returns `EOTP` or when the account uses web auth for publish:
47
+
48
+ 1. Start publish in a TTY and disable local browser opening:
49
+ ```bash
50
+ BROWSER=true npm publish
51
+ ```
52
+
53
+ 2. Wait for npm to print:
54
+ ```text
55
+ Authenticate your account at:
56
+ https://www.npmjs.com/auth/cli/<auth-id>
57
+ Press ENTER to open in the browser...
58
+ ```
59
+
60
+ 3. Send the URL to the user as a bare URL, not inside backticks or a code block. Bare URLs are easier to tap.
61
+
62
+ 4. Do not press Enter immediately. Wait until the user says they clicked/confirmed the npm page.
63
+
64
+ 5. After the user confirms, send Enter to the still-running TTY process. npm should retrieve the temporary token and finish:
65
+ ```text
66
+ + <package-name>@<version>
67
+ ```
68
+
69
+ 6. Verify the published version:
70
+ ```bash
71
+ npm view <package-name> version
72
+ git status --short --branch
73
+ ```
74
+
75
+ ## Failure Modes
76
+
77
+ - If `npm publish` is run without a TTY, npm may print an `EOTP` error with the auth URL redacted as `***`. Stop that attempt and rerun with a TTY.
78
+ - If `xdg-open` fails because the environment has no browser, rerun with `BROWSER=true npm publish`.
79
+ - If the auth link expires or the publish process exits, rerun `BROWSER=true npm publish` to generate a new link.
80
+ - If the user provides a classic authenticator OTP instead of using the web link, publish can be retried with `npm publish --otp <code>`, but prefer web auth when the user asks for a clickable confirmation link.
81
+ - Never print npm tokens or `.npmrc` auth values.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "NPM Publish"
3
+ short_description: "Publish npm packages with 2FA web auth"
4
+ default_prompt: "Publish this npm package using the recorded web-auth flow."