workbuddy-switch 0.1.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 +98 -0
- package/bin/wb-switch-darwin-arm64 +0 -0
- package/bin/wb-switch.js +32 -0
- package/package.json +26 -0
- package/scripts/install.js +94 -0
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# wb-switch
|
|
2
|
+
|
|
3
|
+
WorkBuddy(腾讯 AI 编程助手)账号切换工具。两种形态:
|
|
4
|
+
|
|
5
|
+
- **桌面 App**:下载 `.app` 双击运行(Tauri,推荐日常使用)
|
|
6
|
+
- **npm / webui**:`npm i -g wb-switch` 后运行 `wb-switch`,浏览器打开操作界面
|
|
7
|
+
|
|
8
|
+
多账号共享登录态(`workbuddy-desktop.info`),一键切换 WorkBuddy 登录账号,并支持将当前账号的会话复制给目标账号(云端归属目标)。
|
|
9
|
+
|
|
10
|
+
## 快速开始
|
|
11
|
+
|
|
12
|
+
### npm 安装(webui)
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i -g wb-switch
|
|
16
|
+
wb-switch # 启动本地服务 + 自动打开浏览器
|
|
17
|
+
wb-switch status # 终端查看当前账号
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
webui 界面与桌面 App 一致:账号管理、切换、会话复制、自动签到、token 保活、更新检查。
|
|
21
|
+
|
|
22
|
+
### 桌面 App
|
|
23
|
+
|
|
24
|
+
从 GitHub Releases 下载对应平台 `.app`(macOS)双击运行。
|
|
25
|
+
|
|
26
|
+
## 功能
|
|
27
|
+
|
|
28
|
+
| 模块 | 说明 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 账号管理 | OAuth 扫码登录、从本机导入、手动添加 token、删除账号 |
|
|
31
|
+
| 账号切换 | 备份认证文件 → 关闭 WorkBuddy → 写入目标账号 → 重启,切换过程实时进度反馈 |
|
|
32
|
+
| 会话复制 | 将当前账号勾选的会话以新 id 复制给目标账号(jsonl 正文 + `workbuddy.db` 索引 + edge-sync 注册) |
|
|
33
|
+
| 自动签到 | 每日在配置时间段内随机时刻签到;一键全部签到;30 天签到日志 |
|
|
34
|
+
| Token 保活 | 惰性刷新(操作前不足阈值刷新)+ 每日保活(不足阈值天数刷新),避免 refresh token 过期 |
|
|
35
|
+
| 自动更新 | 配置 GitHub Releases 源检查新版本;整包更新经签名校验(tauri-updater) |
|
|
36
|
+
| 权限检测 | macOS 授权引导(App 管理 / 完全磁盘访问拖拽授权 + 自动检测) |
|
|
37
|
+
|
|
38
|
+
## 使用
|
|
39
|
+
|
|
40
|
+
1. **添加账号**:账号页 →「扫码登录」(OAuth device flow)或「从本机导入」「手动添加」
|
|
41
|
+
2. **切换账号**:账号卡片 →「切换」,可勾选复制当前会话
|
|
42
|
+
3. **自动签到**:设置 → 自动签到,开启并配置时间段
|
|
43
|
+
4. **更新**:设置 → 自动更新,填写 GitHub owner/repo/token 后检查更新
|
|
44
|
+
|
|
45
|
+
### macOS 权限说明
|
|
46
|
+
|
|
47
|
+
切换账号需要写入 WorkBuddy 认证文件,macOS 要求授权「App 管理」(或「完全磁盘访问」):
|
|
48
|
+
|
|
49
|
+
1. 首次切换报「无权限」时,点「打开系统设置」
|
|
50
|
+
2. 优先在 **App 管理** 里打开 wb-switch 开关;若没有,则去 **完全磁盘访问** 把 wb-switch 拖进带箭头的框
|
|
51
|
+
3. 授权后重启本应用生效;设置页「权限检测」可随时验证
|
|
52
|
+
|
|
53
|
+
> webui 模式:由启动服务的终端进程权限决定;若终端已授权完全磁盘访问则无需额外操作。
|
|
54
|
+
|
|
55
|
+
## 开发
|
|
56
|
+
|
|
57
|
+
环境要求:Node.js ≥ 20、Rust stable、macOS(或 Windows/Linux)。
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install
|
|
61
|
+
npm run tauri dev # 开发模式
|
|
62
|
+
npm run build:app # 构建 debug .app(含前端资源补丁)
|
|
63
|
+
npm run build:app:release # 构建 release .app + 签名更新包
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
签名密钥(自动更新用)存放于 `~/.wb-switch/wb-switch-updater.key`,构建脚本通过
|
|
67
|
+
`TAURI_SIGNING_PRIVATE_KEY` 注入。发布新版本时:
|
|
68
|
+
|
|
69
|
+
1. `npm run build:app:release` 生成 `.app.tar.gz` + `.sig`
|
|
70
|
+
2. `sh scripts/gen-update-json.sh <owner> <repo>` 生成 `latest-macos-aarch64.json`
|
|
71
|
+
3. 将 `.app.tar.gz`、`.sig`、`latest-*.json` 一并上传到 GitHub Release
|
|
72
|
+
|
|
73
|
+
## 目录结构
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
src-tauri/
|
|
77
|
+
src/
|
|
78
|
+
commands.rs # Tauri command 薄包装(对应 Python 版 HTTP API)
|
|
79
|
+
modules/
|
|
80
|
+
account.rs # 账号库 ~/.wb-switch/accounts.json
|
|
81
|
+
auth_file.rs # workbuddy-desktop.info 读写/备份
|
|
82
|
+
oauth.rs # OAuth 登录
|
|
83
|
+
process.rs # WorkBuddy 进程控制
|
|
84
|
+
switch.rs # 切换流程(备份→关→复制会话→写认证→启动)
|
|
85
|
+
session.rs # 会话列表 / 复制
|
|
86
|
+
checkin.rs # 签到
|
|
87
|
+
refresh.rs # token 刷新/保活
|
|
88
|
+
update.rs # 更新检查
|
|
89
|
+
config.rs # 常量/路径/工具
|
|
90
|
+
src/
|
|
91
|
+
components/ # React 组件
|
|
92
|
+
pages/ # 账号页/设置页
|
|
93
|
+
lib/ # API 封装/类型
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 许可
|
|
97
|
+
|
|
98
|
+
[MIT](./LICENSE)
|
|
Binary file
|
package/bin/wb-switch.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// wb-switch npm 入口:spawn 平台二进制(postinstall 下载,见 scripts/install.js)。
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
8
|
+
|
|
9
|
+
// 平台 → 二进制文件名(与 install.js 保持一致)
|
|
10
|
+
const FILE = {
|
|
11
|
+
"darwin-arm64": "wb-switch-darwin-arm64",
|
|
12
|
+
"darwin-x64": "wb-switch-darwin-x64",
|
|
13
|
+
"win32-x64": "wb-switch-win32-x64.exe",
|
|
14
|
+
"linux-x64": "wb-switch-linux-x64",
|
|
15
|
+
"linux-arm64": "wb-switch-linux-arm64",
|
|
16
|
+
}[`${process.platform}-${process.arch}`];
|
|
17
|
+
|
|
18
|
+
if (!FILE) {
|
|
19
|
+
console.error(`wb-switch: 不支持平台 ${process.platform}-${process.arch}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const binPath = path.join(binDir, FILE);
|
|
24
|
+
if (!fs.existsSync(binPath)) {
|
|
25
|
+
console.error(
|
|
26
|
+
"wb-switch: 未找到平台二进制,请重新安装(npm install -g wb-switch 触发下载)",
|
|
27
|
+
);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
32
|
+
process.exit(result.status ?? 1);
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "workbuddy-switch",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "WorkBuddy 账号切换工具:本地 webui(浏览器操作)+ 桌面 App(安装后运行 wb-switch)",
|
|
5
|
+
"bin": {
|
|
6
|
+
"wb-switch": "bin/wb-switch.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin",
|
|
10
|
+
"scripts"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"postinstall": "node scripts/install.js"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=16"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"workbuddy",
|
|
20
|
+
"codebuddy",
|
|
21
|
+
"account",
|
|
22
|
+
"switch",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT"
|
|
26
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// 下载源:GitHub Releases(changexbc/wb-switch-rust),可用环境变量覆盖:
|
|
2
|
+
// WB_SWITCH_BINARY=<本地二进制路径> 本地开发/离线安装(直接复制,不联网)
|
|
3
|
+
// WB_SWITCH_DOWNLOAD_BASE=<URL 前缀> 自定义下载源(默认 GitHub latest release)
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const https = require("https");
|
|
8
|
+
|
|
9
|
+
const OWNER = "changexbc"; // 发布二进制到 Release 的 GitHub 仓库
|
|
10
|
+
const REPO = "wb-switch";
|
|
11
|
+
|
|
12
|
+
const FILE = {
|
|
13
|
+
"darwin-arm64": "wb-switch-darwin-arm64",
|
|
14
|
+
"darwin-x64": "wb-switch-darwin-x64",
|
|
15
|
+
"win32-x64": "wb-switch-win32-x64.exe",
|
|
16
|
+
"linux-x64": "wb-switch-linux-x64",
|
|
17
|
+
"linux-arm64": "wb-switch-linux-arm64",
|
|
18
|
+
}[`${process.platform}-${process.arch}`];
|
|
19
|
+
|
|
20
|
+
if (!FILE) {
|
|
21
|
+
console.warn(
|
|
22
|
+
`wb-switch: 跳过平台 ${process.platform}-${process.arch}(当前不支持),` +
|
|
23
|
+
`可手动下载二进制后放置到 bin/ 目录`,
|
|
24
|
+
);
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
29
|
+
const target = path.join(binDir, FILE);
|
|
30
|
+
|
|
31
|
+
function fail(msg) {
|
|
32
|
+
console.error(`wb-switch install: ${msg}`);
|
|
33
|
+
console.error("安装失败,可手动下载二进制放到 npm 包的 bin/ 目录。");
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function copyLocal(src) {
|
|
38
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
39
|
+
fs.copyFileSync(src, target);
|
|
40
|
+
if (process.platform !== "win32") fs.chmodSync(target, 0o755);
|
|
41
|
+
console.log(`wb-switch: 已从 ${src} 复制二进制`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function download(url) {
|
|
45
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
46
|
+
console.log(`wb-switch: 正在下载 ${url}`);
|
|
47
|
+
const file = fs.createWriteStream(target);
|
|
48
|
+
https
|
|
49
|
+
.get(url, (res) => {
|
|
50
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
51
|
+
file.close();
|
|
52
|
+
return download(res.headers.location);
|
|
53
|
+
}
|
|
54
|
+
if (res.statusCode !== 200) {
|
|
55
|
+
file.close();
|
|
56
|
+
fs.unlinkSync(target);
|
|
57
|
+
return fail(`下载失败 (HTTP ${res.statusCode})`);
|
|
58
|
+
}
|
|
59
|
+
res.pipe(file);
|
|
60
|
+
file.on("finish", () => {
|
|
61
|
+
file.close();
|
|
62
|
+
if (process.platform !== "win32") fs.chmodSync(target, 0o755);
|
|
63
|
+
console.log(`wb-switch: 二进制就绪 → ${target}`);
|
|
64
|
+
});
|
|
65
|
+
})
|
|
66
|
+
.on("error", (e) => {
|
|
67
|
+
file.close();
|
|
68
|
+
fs.unlinkSync(target);
|
|
69
|
+
fail(`网络错误: ${e.message}`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function main() {
|
|
74
|
+
// 1) 本地二进制覆盖(开发/离线)
|
|
75
|
+
if (process.env.WB_SWITCH_BINARY) {
|
|
76
|
+
const local = path.resolve(process.env.WB_SWITCH_BINARY);
|
|
77
|
+
if (fs.existsSync(local)) return copyLocal(local);
|
|
78
|
+
return fail(`WB_SWITCH_BINARY 指向的文件不存在: ${local}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 2) 已存在则跳过
|
|
82
|
+
if (fs.existsSync(target)) {
|
|
83
|
+
console.log(`wb-switch: 二进制已存在,跳过下载`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 3) 从 GitHub Releases 下载
|
|
88
|
+
const base =
|
|
89
|
+
process.env.WB_SWITCH_DOWNLOAD_BASE ||
|
|
90
|
+
`https://github.com/${OWNER}/${REPO}/releases/latest/download`;
|
|
91
|
+
download(`${base}/${FILE}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main();
|