@dsh-mobile/mobile-remote 0.0.0-stage → 3.2.4
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/CHANGELOG.md +1069 -0
- package/CONTRIBUTING.md +59 -0
- package/FAQ.md +111 -0
- package/LICENSE +21 -0
- package/README.md +286 -2
- package/cordis.patch.yml +22 -0
- package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +121 -0
- package/docs/01-PRD.md +148 -0
- package/docs/02-architecture.md +249 -0
- package/docs/03-api.md +834 -0
- package/docs/04-security.md +109 -0
- package/docs/05-test-cases.md +376 -0
- package/docs/06-install-run.md +336 -0
- package/docs/07-user-manual.md +70 -0
- package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +86 -0
- package/docs/09-compatibility.md +201 -0
- package/docs/ARCHITECTURE-CURRENT.md +229 -0
- package/docs/BUILD-ENVIRONMENT.md +169 -0
- package/docs/FEATURE-PARITY.md +195 -0
- package/docs/PRIVACY-POLICY.md +65 -0
- package/docs/REA-UNDERSTANDING.md +246 -0
- package/docs/STORE-LAUNCH.md +130 -0
- package/docs/SUPPORT.md +42 -0
- package/docs/screenshots/01-home.png +0 -0
- package/docs/screenshots/02-notifications.png +0 -0
- package/docs/screenshots/03-sessions.png +0 -0
- package/docs/screenshots/04-chat.png +0 -0
- package/docs/screenshots/05-settings.png +0 -0
- package/docs/screenshots/06-new-session.png +0 -0
- package/docs/screenshots/pgy-appstore.jpg +0 -0
- package/docs/screenshots/pgy-mobile-app.jpg +0 -0
- package/docs/screenshots/pgy-pc-client.jpg +0 -0
- package/lib/account-usage.js +145 -0
- package/lib/auto-config.js +107 -0
- package/lib/client.js +303 -0
- package/lib/git-read-bundled-provider.js +255 -0
- package/lib/git-read-service.js +322 -0
- package/lib/index.js +7559 -0
- package/lib/session-title-cache.js +123 -0
- package/lib/session-title-refresh.js +261 -0
- package/package.json +62 -4
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# DSH Mobile 商店上架准备
|
|
2
|
+
|
|
3
|
+
> 记录时间:2026-11-01(Asia/Shanghai)
|
|
4
|
+
> 当前版本:App `3.2.4+31`,插件 `3.2.4`
|
|
5
|
+
|
|
6
|
+
这份清单把可由仓库准备的商店素材和必须由发布者在 Apple/Google 控制台完成的事项分开。构建产物、签名、商店上传和公开发布不是同一件事;没有账号、证书和最终网址时,仓库只能完成可复核的准备,不能声称已经提交或上架。
|
|
7
|
+
|
|
8
|
+
## 1. 产品资料
|
|
9
|
+
|
|
10
|
+
| 字段 | 内容 / 状态 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| 应用名称 | `DSH Mobile` |
|
|
13
|
+
| Apple App Store 副标题 | `DeepSeek Harness from anywhere` |
|
|
14
|
+
| 简短定位 | `A mobile companion for DeepSeek Harness. View tasks, continue conversations, approve actions, and receive notifications.` |
|
|
15
|
+
| 关系声明 | `DSH Mobile is an independent mobile companion for DeepSeek Harness. It is not affiliated with or endorsed by DeepSeek.` |
|
|
16
|
+
| Android applicationId | `com.mrdayone.dshmobile` |
|
|
17
|
+
| iOS Bundle Identifier | `com.mrdayone.dshmobile` |
|
|
18
|
+
| iOS 最低版本 | `15.0` |
|
|
19
|
+
| 版本 | `3.2.4` |
|
|
20
|
+
| Android build number | `31` |
|
|
21
|
+
| 默认显示名 | `DSH Mobile` |
|
|
22
|
+
| 许可证 | MIT,保留根目录 `LICENSE` 和第三方版权声明 |
|
|
23
|
+
|
|
24
|
+
## 2. 建议商店描述
|
|
25
|
+
|
|
26
|
+
### 中文
|
|
27
|
+
|
|
28
|
+
DSH Mobile 是 DeepSeek Harness 的独立移动伴侣。连接你自己的电脑端 Harness 后,你可以查看会话和任务进度、继续对话、接收流式回复、处理问询与工具审批、浏览工作区文件、查看通知和用量,并在网络恢复后继续同步状态。
|
|
29
|
+
|
|
30
|
+
DSH Mobile 不托管或代理 DeepSeek 服务。它连接的是用户自己配置的 DSH Harness 电脑端服务。使用局域网或用户自行配置的可信组网方式连接,并为移动端服务设置访问口令。
|
|
31
|
+
|
|
32
|
+
### English
|
|
33
|
+
|
|
34
|
+
DSH Mobile is an independent mobile companion for DeepSeek Harness. Connect it to your own DSH Harness service to view sessions and task progress, continue conversations, receive streaming replies, answer questions, approve tool actions, browse workspace files, and receive notifications.
|
|
35
|
+
|
|
36
|
+
DSH Mobile does not host or proxy DeepSeek services. It connects to the DSH Harness service configured by the user. Use a trusted local network or user-managed private network and configure an access token for the mobile service.
|
|
37
|
+
|
|
38
|
+
## 3. 权限说明
|
|
39
|
+
|
|
40
|
+
### Android
|
|
41
|
+
|
|
42
|
+
- Internet:连接用户自己的 DSH Harness 服务。
|
|
43
|
+
- Camera:扫描桌面端连接二维码。
|
|
44
|
+
- POST_NOTIFICATIONS:显示问询、审批和后台提醒。
|
|
45
|
+
- SYSTEM_ALERT_WINDOW:仅用于用户主动开启的 Android 桌面宠物。
|
|
46
|
+
- FOREGROUND_SERVICE / FOREGROUND_SERVICE_SPECIAL_USE:仅用于用户主动开启的 Android 后台提醒或桌面宠物。
|
|
47
|
+
|
|
48
|
+
### iOS
|
|
49
|
+
|
|
50
|
+
- Camera:扫描桌面端连接二维码。
|
|
51
|
+
- Photo Library:用户选择图片发送给自己的会话。
|
|
52
|
+
- Local Network:访问用户局域网内的 DSH Harness 服务。
|
|
53
|
+
- Notifications:显示任务、问询和审批提醒。
|
|
54
|
+
|
|
55
|
+
iOS 不申请 Android 悬浮窗或前台服务权限。iOS 使用系统通知和回到 App 后的服务端状态补拉作为等价路径。
|
|
56
|
+
|
|
57
|
+
## 4. 隐私与数据流
|
|
58
|
+
|
|
59
|
+
- 会话内容、任务状态、审批回答和工作区文件请求发送到用户自己配置的 DSH Harness 服务。
|
|
60
|
+
- 连接地址和普通界面偏好保存在设备本地;访问口令使用 Android Keystore / iOS Keychain 封装保存。
|
|
61
|
+
- App 不内置用户账号体系,不上传广告标识符,不内置第三方分析 SDK。
|
|
62
|
+
- 用户配置的推送桥可能把事件提醒发送到用户自己选择的第三方通道;推送内容由电脑端插件配置决定,默认使用脱敏摘要。
|
|
63
|
+
- App 日志用于本地诊断,不应包含访问口令;用户可在设备上清除 App 数据以删除本地配置。
|
|
64
|
+
|
|
65
|
+
完整文本见 `docs/PRIVACY-POLICY.md`。发布前必须把该文本发布到一个可公开访问的 HTTPS URL,并在两个商店的隐私政策字段填写该 URL。
|
|
66
|
+
|
|
67
|
+
## 5. 支持资料
|
|
68
|
+
|
|
69
|
+
支持页内容见 `docs/SUPPORT.md`。发布前必须提供一个稳定的 HTTPS 支持 URL 和联系邮箱;仓库不填写不存在的域名或邮箱。
|
|
70
|
+
|
|
71
|
+
## 6. 截图清单
|
|
72
|
+
|
|
73
|
+
需要使用真实构建和真实界面截图,不使用原型截图冒充商店素材:
|
|
74
|
+
|
|
75
|
+
1. 连接页:扫码连接和手动地址/访问口令。
|
|
76
|
+
2. 首页:最近会话、工作区和新建会话入口。
|
|
77
|
+
3. 对话页:流式回复、Markdown、工具状态和审批卡。
|
|
78
|
+
4. 会话工具:任务、子代理和目标。
|
|
79
|
+
5. 通知中心:未读状态和通知跳转。
|
|
80
|
+
6. 设置页:模型、权限、用量、诊断和主题。
|
|
81
|
+
7. 文件/Git:工作区浏览和只读 Git 详情。
|
|
82
|
+
|
|
83
|
+
Android 至少准备手机尺寸和平板/大屏尺寸;iOS 至少准备 iPhone 和 iPad 尺寸。截图必须去掉真实地址、token、真实会话内容、个人信息和内部文件名。
|
|
84
|
+
|
|
85
|
+
## 7. 提交前必须由发布者完成
|
|
86
|
+
|
|
87
|
+
- [ ] Apple Developer 账号和 App Store Connect 应用记录。
|
|
88
|
+
- [ ] Google Play Console 应用记录。
|
|
89
|
+
- [ ] 确认两个商店都接受并冻结 `com.mrdayone.dshmobile`;首次创建后不要随意更换。
|
|
90
|
+
- [ ] Android release keystore 安全保管,并以 GitHub Secret 或本地安全路径提供给构建。
|
|
91
|
+
- [ ] Apple 证书、provisioning profile 和 App Store Connect API key/权限。Workflow 使用 Variables `APPSTORE_ISSUER_ID`、`APPSTORE_API_KEY_ID`,Secret `APPSTORE_API_PRIVATE_KEY`。
|
|
92
|
+
- [ ] Google Play 服务账号和内部测试轨道权限。Workflow 使用 Secret `GOOGLE_PLAY_SERVICE_ACCOUNT_JSON`。
|
|
93
|
+
- [ ] GitHub repository Variable `ANDROID_SDK_LICENSES_ACCEPTED=true`。仅在发布者已接受 Android SDK License 后设置;Android workflow 不会在变量缺失时自动代替接受条款。
|
|
94
|
+
- [ ] Android 签名 Secrets:`ANDROID_KEYSTORE_BASE64`、`ANDROID_KEY_ALIAS`、`ANDROID_KEY_PASSWORD`、`ANDROID_KEYSTORE_PASSWORD`。
|
|
95
|
+
- [ ] iOS 签名 Secrets:`APPLE_CERTIFICATE_BASE64`、`APPLE_CERTIFICATE_PASSWORD`、`APPLE_PROVISIONING_PROFILE_BASE64`、`APPLE_KEYCHAIN_PASSWORD`、`APPLE_SIGNING_IDENTITY`、`APPLE_TEAM_ID`、`APPLE_PROVISIONING_PROFILE_NAME`。
|
|
96
|
+
- [ ] 隐私政策 HTTPS URL、支持 HTTPS URL、支持邮箱。
|
|
97
|
+
- [ ] 真实 Android AAB 和 iOS TestFlight IPA 经过设备冒烟。
|
|
98
|
+
- [ ] 填写内容分级、数据安全、出口合规和第三方品牌声明。
|
|
99
|
+
- [ ] 发布者人工确认公开发布;CI 不自动把未确认构建发布到公开轨道。
|
|
100
|
+
|
|
101
|
+
## 8. 当前明确未完成项
|
|
102
|
+
|
|
103
|
+
本轮没有 Apple/Google 账号、签名证书、keystore、商店记录或公开 HTTPS 页面,因此没有执行商店上传,也没有声称已经通过审核。GitHub Actions 会在没有这些 Secrets 时保留可验证的 unsigned iOS Runner.app 和 debug-signed Android AAB candidate,并明确标注它们不能直接提交商店;只有配置正式签名 Secrets 后才生成可提交的 IPA/AAB。
|
|
104
|
+
|
|
105
|
+
预发布检查:
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
scripts/release-check.ps1 -AllowUnsigned
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
正式提交检查:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
scripts/release-check.ps1 -StoreSubmission -AndroidAabPath <signed-aab> -IosIpaPath <signed-ipa>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
正式提交模式会拒绝缺少 release keystore、真实 HTTPS 隐私/支持 URL、支持邮箱或签名 AAB/IPA 的状态。
|
|
118
|
+
|
|
119
|
+
> 提醒:无签名的 iOS `Runner.app` 不能运行(没有 entitlements,Keychain 报 -34018),只用于编译检查;详见 `docs/09-compatibility.md` §4。
|
|
120
|
+
|
|
121
|
+
## 9. 自动上传条件
|
|
122
|
+
|
|
123
|
+
> ⚠ `release.yml` 与 `android-build.yml` **不在本仓库**:本节是设计说明,尚无实现,也没有验证过。现有的是 `ci.yml` 与手动触发的 `ios-build.yml`。
|
|
124
|
+
|
|
125
|
+
`release.yml` 的上传 job 只在以下条件同时满足时运行:
|
|
126
|
+
|
|
127
|
+
- Google Play:正式签名 AAB、`GOOGLE_PLAY_SERVICE_ACCOUNT_JSON`、Android 签名 Secrets、已创建的 Play Console 应用和 internal track 权限。
|
|
128
|
+
- TestFlight:正式签名 IPA、Apple 证书/profile、`APPSTORE_ISSUER_ID`、`APPSTORE_API_KEY_ID`、`APPSTORE_API_PRIVATE_KEY`、App Store Connect 应用记录和上传权限。
|
|
129
|
+
|
|
130
|
+
缺少任一项时,job 只输出跳过原因,不会上传 unsigned/debug candidate。当前仓库没有这些外部凭据和商店记录,因此本轮没有执行上传。
|
package/docs/SUPPORT.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# DSH Mobile 支持页
|
|
2
|
+
|
|
3
|
+
> 应用名称:DSH Mobile
|
|
4
|
+
> 支持邮箱:发布前由运营方填写
|
|
5
|
+
|
|
6
|
+
## 使用前
|
|
7
|
+
|
|
8
|
+
DSH Mobile 连接的是你自己的电脑端 DSH Harness 服务,不是公共云端账号。请先在电脑端安装并启用 `dsh-mobile-remote` 插件,配置移动端路径和访问口令,再使用二维码或手动地址连接。
|
|
9
|
+
|
|
10
|
+
## 常见问题
|
|
11
|
+
|
|
12
|
+
### 扫码后无法连接
|
|
13
|
+
|
|
14
|
+
确认电脑端服务正在运行、手机和电脑在同一可信局域网或同一私有组网中,并确认访问口令没有过期。桌面版通常需要启用插件 LAN bridge;修改配置后需要重启 DSH。
|
|
15
|
+
|
|
16
|
+
### 地址能打开但 App 提示认证失败
|
|
17
|
+
|
|
18
|
+
重新从电脑端设置页获取二维码,或重新输入访问口令。不要把口令写进截图、日志或聊天消息。每台电脑建议使用不同的强口令。
|
|
19
|
+
|
|
20
|
+
### 出门后连接断开
|
|
21
|
+
|
|
22
|
+
确认手机和电脑都仍在线于同一个私有组网。回到 App 前台后,App 会重新拉取服务端状态并尝试候选地址。Android 用户还需要按系统提示允许必要的后台行为;iOS 使用系统通知和回前台同步,不提供 Android 常驻前台服务。
|
|
23
|
+
|
|
24
|
+
### 没收到审批或问询提醒
|
|
25
|
+
|
|
26
|
+
先打开 App 的通知权限,再确认电脑端推送桥或 App 在线通知已经配置。进入对应会话后,审批卡会在 App 内显示;如果另一端已经回答,当前卡片会被结算。
|
|
27
|
+
|
|
28
|
+
### 文件无法打开或导出
|
|
29
|
+
|
|
30
|
+
Android 使用系统文件能力保存或打开文件;iOS 使用 Files/分享面板。请确认设备上有可处理该文件类型的应用,并检查 App 的文件访问权限。
|
|
31
|
+
|
|
32
|
+
### 如何报告问题
|
|
33
|
+
|
|
34
|
+
提交问题时请附上:App 版本、电脑端插件版本、手机系统版本、连接方式、复现步骤和脱敏后的错误信息。请勿附访问口令、二维码、真实会话内容、个人邮箱或工作区秘密文件。
|
|
35
|
+
|
|
36
|
+
## 品牌关系
|
|
37
|
+
|
|
38
|
+
DSH Mobile is an independent mobile companion for DeepSeek Harness. It is not affiliated with or endorsed by DeepSeek.
|
|
39
|
+
|
|
40
|
+
## 发布前需要填写
|
|
41
|
+
|
|
42
|
+
运营方需要把支持邮箱替换为真实联系方式,并将本页发布到稳定的 HTTPS URL,随后填入 App Store Connect 和 Google Play 的支持页面字段。当前仓库没有伪造域名或邮箱。
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// 用量与额度领域归一化:保持无运行时依赖,便于服务端单测与其它宿主复用。
|
|
2
|
+
|
|
3
|
+
/** 额度窗口标签:优先使用 provider 约定名称,未知窗口保持稳定可读。 */
|
|
4
|
+
export function usageWindowLabel(seconds) {
|
|
5
|
+
const value = Number(seconds);
|
|
6
|
+
if (!Number.isFinite(value) || value <= 0) return null;
|
|
7
|
+
if (value === 18_000) return '5h';
|
|
8
|
+
if (value === 604_800) return 'weekly';
|
|
9
|
+
if (value === 2_592_000) return 'monthly';
|
|
10
|
+
if (value % 604_800 === 0) return `${value / 604_800}w`;
|
|
11
|
+
if (value % 3_600 === 0) return `${value / 3_600}h`;
|
|
12
|
+
if (value % 60 === 0) return `${value / 60}m`;
|
|
13
|
+
return `${value}s`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function finiteNumber(value) {
|
|
17
|
+
if (value === null || value === undefined || value === '' || typeof value === 'boolean') return undefined;
|
|
18
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
19
|
+
return Number.isFinite(number) ? number : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function clampPercent(value) {
|
|
23
|
+
const number = finiteNumber(value);
|
|
24
|
+
return number === undefined || number < 0 || number > 100 ? undefined : number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isoFromUnixSeconds(value) {
|
|
28
|
+
const seconds = finiteNumber(value);
|
|
29
|
+
if (seconds === undefined || seconds <= 0) return undefined;
|
|
30
|
+
const date = new Date(seconds * 1000);
|
|
31
|
+
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isoFromDate(value) {
|
|
35
|
+
if (typeof value !== 'string' || value.trim() === '') return undefined;
|
|
36
|
+
const date = new Date(value);
|
|
37
|
+
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** DeepSeek /user/balance 的顶层投影;优先选择 CNY 余额项。 */
|
|
41
|
+
export function normalizeDeepSeekBalance(data) {
|
|
42
|
+
const infos = data && typeof data === 'object' && !Array.isArray(data) ? data.balance_infos : undefined;
|
|
43
|
+
const validInfos = Array.isArray(infos) ? infos.filter((item) => item && typeof item === 'object' && !Array.isArray(item)) : [];
|
|
44
|
+
const first = validInfos.find((item) => item.currency === 'CNY') ?? validInfos[0];
|
|
45
|
+
const amount = first ? finiteNumber(first.total_balance) : undefined;
|
|
46
|
+
if (!first || amount === undefined) throw new Error('invalid deepseek balance');
|
|
47
|
+
return {
|
|
48
|
+
amount: String(first.total_balance),
|
|
49
|
+
currency: typeof first.currency === 'string' && first.currency !== '' ? first.currency : 'CNY',
|
|
50
|
+
available: data.is_available !== false && first.is_available !== false,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* dsh-codex-connect 的无密钥投影 → 手机额度领域模型。
|
|
56
|
+
* 保留主 bucket 与 additional_rate_limits 的全部有效窗口,仅返回百分比/金额/窗口,不接触 OAuth token。
|
|
57
|
+
*/
|
|
58
|
+
export function normalizeCodexUsage(usage) {
|
|
59
|
+
if (!usage || typeof usage !== 'object' || Array.isArray(usage)) throw new Error('invalid codex usage');
|
|
60
|
+
if (usage.rateLimits !== undefined && !Array.isArray(usage.rateLimits)) throw new Error('invalid codex rate limits');
|
|
61
|
+
const rateLimits = (usage.rateLimits ?? []).filter((bucket) => bucket && typeof bucket === 'object' && !Array.isArray(bucket));
|
|
62
|
+
const primaryIndex = rateLimits.findIndex((bucket) => bucket.id === 'codex');
|
|
63
|
+
const orderedBuckets = primaryIndex >= 0
|
|
64
|
+
? [rateLimits[primaryIndex], ...rateLimits.filter((_, index) => index !== primaryIndex)]
|
|
65
|
+
: rateLimits;
|
|
66
|
+
const windows = [];
|
|
67
|
+
for (const [bucketIndex, bucket] of orderedBuckets.entries()) {
|
|
68
|
+
if (!Array.isArray(bucket.windows)) continue;
|
|
69
|
+
const bucketName = typeof bucket.name === 'string' && bucket.name.trim() !== ''
|
|
70
|
+
? bucket.name.trim().slice(0, 80)
|
|
71
|
+
: typeof bucket.id === 'string' && bucket.id.trim() !== '' ? bucket.id.trim().slice(0, 80) : undefined;
|
|
72
|
+
const seenInBucket = new Set();
|
|
73
|
+
for (const item of bucket.windows) {
|
|
74
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) continue;
|
|
75
|
+
const baseWindow = usageWindowLabel(item.windowSeconds);
|
|
76
|
+
const remainingPercent = clampPercent(item.remainingPercent);
|
|
77
|
+
const resetAt = isoFromUnixSeconds(item.resetAt);
|
|
78
|
+
if (!baseWindow || seenInBucket.has(baseWindow) || remainingPercent === undefined) continue;
|
|
79
|
+
seenInBucket.add(baseWindow);
|
|
80
|
+
const window = bucketIndex === 0 || !bucketName ? baseWindow : `${bucketName} · ${baseWindow}`;
|
|
81
|
+
windows.push({ window, remainingPercent, ...(resetAt ? { resetAt } : {}) });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const individual = usage.individualLimit;
|
|
85
|
+
let individualLimit;
|
|
86
|
+
if (individual && typeof individual === 'object' && !Array.isArray(individual)) {
|
|
87
|
+
const limit = finiteNumber(individual.limit);
|
|
88
|
+
const used = finiteNumber(individual.used);
|
|
89
|
+
const remaining = finiteNumber(individual.remaining);
|
|
90
|
+
const remainingPercent = clampPercent(individual.remainingPercent ?? (limit > 0 && remaining !== undefined ? remaining / limit * 100 : undefined));
|
|
91
|
+
if (limit !== undefined && used !== undefined && remaining !== undefined && limit > 0 && remainingPercent !== undefined) {
|
|
92
|
+
individualLimit = {
|
|
93
|
+
limit: String(individual.limit),
|
|
94
|
+
used: String(individual.used),
|
|
95
|
+
remaining: String(individual.remaining),
|
|
96
|
+
remainingPercent,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const credits = usage.credits;
|
|
101
|
+
let codexCredits;
|
|
102
|
+
if (credits && typeof credits === 'object' && !Array.isArray(credits) && typeof credits.unlimited === 'boolean') {
|
|
103
|
+
if (credits.unlimited) {
|
|
104
|
+
codexCredits = { unlimited: true };
|
|
105
|
+
} else if (typeof credits.balance === 'string' && credits.balance.trim() !== '') {
|
|
106
|
+
codexCredits = { unlimited: false, balance: credits.balance };
|
|
107
|
+
} else if (finiteNumber(credits.balance) !== undefined) {
|
|
108
|
+
codexCredits = { unlimited: false, balance: String(credits.balance) };
|
|
109
|
+
} else {
|
|
110
|
+
// balance 是可选字段,但 unlimited=false 仍是一个有效、可展示的 Credits 状态。
|
|
111
|
+
codexCredits = { unlimited: false };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (windows.length === 0 && individualLimit === undefined && codexCredits === undefined) throw new Error('codex usage has no usable allowance');
|
|
115
|
+
return {
|
|
116
|
+
windows,
|
|
117
|
+
...(individualLimit ? { individualLimit } : {}),
|
|
118
|
+
...(codexCredits ? { credits: codexCredits } : {}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** OpenCode Go usage payload → 剩余百分比窗口;无效窗口单独跳过,限流窗口保留。 */
|
|
123
|
+
export function normalizeOpenCodeUsage(payload) {
|
|
124
|
+
const usage = payload && typeof payload === 'object' && !Array.isArray(payload) ? (payload.usage ?? payload) : undefined;
|
|
125
|
+
if (!usage || typeof usage !== 'object' || Array.isArray(usage)) throw new Error('invalid opencode usage');
|
|
126
|
+
const windows = [];
|
|
127
|
+
for (const [key, label] of [['rolling', '5h'], ['weekly', 'weekly'], ['monthly', 'monthly']]) {
|
|
128
|
+
const detail = usage[key];
|
|
129
|
+
if (!detail || typeof detail !== 'object' || Array.isArray(detail)) continue;
|
|
130
|
+
const status = detail.status;
|
|
131
|
+
if (status !== undefined && status !== null && status !== 'ok' && status !== 'rate-limited') continue;
|
|
132
|
+
const usedPercent = clampPercent(detail.percent);
|
|
133
|
+
if (usedPercent === undefined) continue;
|
|
134
|
+
// percent=0 时 OpenCode 返回的是 now+window 占位值,不是可展示的 resetAt。
|
|
135
|
+
const resetAt = usedPercent === 0 ? undefined : isoFromDate(detail.resetsAt);
|
|
136
|
+
windows.push({
|
|
137
|
+
window: label,
|
|
138
|
+
remainingPercent: 100 - usedPercent,
|
|
139
|
+
...(status === 'rate-limited' ? { limited: true } : {}),
|
|
140
|
+
...(resetAt ? { resetAt } : {}),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (windows.length === 0) throw new Error('opencode usage has no usable windows');
|
|
144
|
+
return { windows };
|
|
145
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 零配置接入(装上插件就能用)。
|
|
3
|
+
*
|
|
4
|
+
* 以前要让手机连上,用户得:手写 `cordis.patch.yml` 启用插件 → 自己生成口令 → 桌面版还要手写 lanBridge →
|
|
5
|
+
* 自己去查 IP。这里把「必须由人决定」之外的部分全部自动化,且都是**纯函数 + 显式输入**,便于单测:
|
|
6
|
+
*
|
|
7
|
+
* - `authToken: "@auto"` 首次启动随机生成强口令并持久化,之后复用(手机只需配对一次)。
|
|
8
|
+
* - `lanBridge.enabled: "auto"` 仅在需要时开桥(桌面版 webserver 只听回环)。
|
|
9
|
+
* - `formatConnectionBanner` 启动时把手机 App 需要填的两项(地址 + 口令)打印出来。
|
|
10
|
+
*
|
|
11
|
+
* 向后兼容:`authToken` 为空仍然表示「关闭认证」、`lanBridge.enabled` 仍可写 true/false;
|
|
12
|
+
* 这些「自动」值只会出现在插件自带的 `cordis.patch.yml` 里,已有手写配置的用户行为不变。
|
|
13
|
+
*/
|
|
14
|
+
import { randomBytes } from "node:crypto";
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
|
|
19
|
+
/** 配置里写这个值 = 「请自动生成并持久化口令」。刻意带 `@`:不会和人手写的口令撞车。 */
|
|
20
|
+
export const AUTO = "@auto";
|
|
21
|
+
|
|
22
|
+
/** 自动口令的合法形态:24 字节 base64url = 32 字符;读回时按此校验,损坏的文件视为不存在。 */
|
|
23
|
+
const SAVED_TOKEN_RE = /^[A-Za-z0-9_-]{24,128}$/;
|
|
24
|
+
|
|
25
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
26
|
+
|
|
27
|
+
/** 插件的状态目录。与宿主同一个 `DSH_HOME` 约定(隔离测试/多实例时口令不串)。 */
|
|
28
|
+
export function mobileRemoteStateDir(env = process.env, home = homedir()) {
|
|
29
|
+
const base = typeof env.DSH_HOME === "string" && env.DSH_HOME.trim() !== "" ? env.DSH_HOME : join(home, ".dsh");
|
|
30
|
+
return join(base, "mobile-remote");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 解析 `authToken`。
|
|
35
|
+
* - 不是 `@auto`:原样返回(空串 = 关闭认证,保持旧语义)。
|
|
36
|
+
* - `@auto`:读 `<stateDir>/auth-token`;没有或损坏就生成新的并原子写入(0600)。
|
|
37
|
+
* 写盘失败不阻断启动:本次进程内用内存口令,但会返回 `persistError`,调用方应提示
|
|
38
|
+
* 「重启后口令会变,手机需要重新配对」。
|
|
39
|
+
*/
|
|
40
|
+
export function resolveAuthToken(configured, { dir = mobileRemoteStateDir(), generate = () => randomBytes(24).toString("base64url") } = {}) {
|
|
41
|
+
if (configured !== AUTO) return { token: configured ?? "", auto: false };
|
|
42
|
+
const file = join(dir, "auth-token");
|
|
43
|
+
try {
|
|
44
|
+
if (existsSync(file)) {
|
|
45
|
+
const saved = readFileSync(file, "utf8").trim();
|
|
46
|
+
if (SAVED_TOKEN_RE.test(saved)) return { token: saved, auto: true, generated: false, file };
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
// 读失败 → 当作没有,走下面的重新生成
|
|
50
|
+
}
|
|
51
|
+
const token = generate();
|
|
52
|
+
try {
|
|
53
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
54
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
55
|
+
writeFileSync(tmp, `${token}\n`, { mode: 0o600 });
|
|
56
|
+
renameSync(tmp, file);
|
|
57
|
+
return { token, auto: true, generated: true, file };
|
|
58
|
+
} catch (persistError) {
|
|
59
|
+
return { token, auto: true, generated: true, file: undefined, persistError };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 解析 `lanBridge.enabled`:true/false 原样;`"auto"` = 需要才开。
|
|
65
|
+
* 「需要」= webserver 只听回环(桌面版强制如此,手机直连不了)。web 版 webserver 已经听 0.0.0.0,
|
|
66
|
+
* 再开桥反而会和它抢同一个端口。宿主地址拿不到时按桌面版处理,但桥端口与 webserver 端口相同则不开。
|
|
67
|
+
*/
|
|
68
|
+
export function resolveLanBridgeEnabled(setting, { webHost, webPort, bridgePort } = {}) {
|
|
69
|
+
if (setting !== "auto") return Boolean(setting);
|
|
70
|
+
if (typeof webHost === "string" && webHost !== "") return LOOPBACK_HOSTS.has(webHost.toLowerCase());
|
|
71
|
+
return !(webPort !== undefined && bridgePort === webPort);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 自动开桥时选桥端口。桥默认端口 3080 与 `dsh web` 自己的 webserver 端口(回环 3080)相同:
|
|
76
|
+
* macOS/BSD 允许「回环 3080」与「通配 3080」并存,Linux 却会 EADDRINUSE(Windows 行为也不可依赖)。
|
|
77
|
+
* 所以 `auto` 模式下撞端口就让到下一个;用户**显式**写 true/false 时一律尊重其端口,不替人改。
|
|
78
|
+
*/
|
|
79
|
+
export function resolveLanBridgePort(setting, port, webPort) {
|
|
80
|
+
if (setting === "auto" && webPort !== undefined && port === webPort) return port < 65535 ? port + 1 : port - 1;
|
|
81
|
+
return port;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 启动时打印给人看的「手机 App 要填的两项」。
|
|
86
|
+
* 口令只在**自动生成**时打印——那是用户唯一能第一时间拿到它的地方;用户自己写进配置的口令不进日志。
|
|
87
|
+
*/
|
|
88
|
+
export function formatConnectionBanner({ addresses, token, tokenIsAuto, tokenFile, persistError, authEnabled = true }) {
|
|
89
|
+
const [first, ...rest] = addresses;
|
|
90
|
+
const lines = ["mobile-remote ▶ 手机 App 连接信息 / Phone app connection"];
|
|
91
|
+
lines.push(` 电脑地址 Address : ${first}`);
|
|
92
|
+
for (const extra of rest) lines.push(` ${extra} (备用 alternative)`);
|
|
93
|
+
if (!authEnabled) {
|
|
94
|
+
lines.push(" 访问口令 Token : (未启用认证 / authentication is OFF)");
|
|
95
|
+
} else if (tokenIsAuto) {
|
|
96
|
+
lines.push(` 访问口令 Token : ${token}`);
|
|
97
|
+
if (persistError) {
|
|
98
|
+
lines.push(" ⚠ 口令无法写入磁盘:重启后会变化,手机需要重新配对 / token could not be saved and changes on restart");
|
|
99
|
+
} else if (tokenFile) {
|
|
100
|
+
lines.push(` (口令保存在 ${tokenFile},重启不变 / persisted across restarts)`);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
lines.push(" 访问口令 Token : (你在配置里设置的 authToken / the authToken you configured)");
|
|
104
|
+
}
|
|
105
|
+
lines.push(" App:设置 → 重新配置连接,填入上面两项;或在 DSH 设置页「连接移动端设备」扫二维码 / scan the QR in DSH settings");
|
|
106
|
+
return lines.join("\n");
|
|
107
|
+
}
|