@heybox/hb-sdk 0.6.4 → 0.6.5
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/dist/cli-chunks/{context-BEgbP7mM.cjs → context-DjepdCaa.cjs} +1 -1
- package/dist/cli-chunks/{create-BHsWWo3V.cjs → create-D3BBKay9.cjs} +1 -1
- package/dist/cli-chunks/{dev-CSjs2OYB.cjs → dev-C3u5FXIy.cjs} +4 -4
- package/dist/cli-chunks/{doctor-B3AOQgyN.cjs → doctor-DEgZa2qC.cjs} +1 -1
- package/dist/cli-chunks/{index-BGFf6g7V.cjs → index-B5gEl9ow.cjs} +2 -2
- package/dist/cli-chunks/{index-B0zGksOA.cjs → index-CKat0ExC.cjs} +13 -13
- package/dist/cli-chunks/{login-ClQuL2r6.cjs → login-B6gERpSX.cjs} +2 -2
- package/dist/cli-chunks/{remote-ib5THDbw.cjs → remote-BfQiZzeJ.cjs} +4 -4
- package/dist/cli-chunks/{session-D7nmqMiy.cjs → session-DPEq__gB.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/templates/vue3-vite-ts/README.md.ejs +4 -8
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.esm.js +1 -1
- package/package.json +1 -1
- package/skill/SKILL.md +33 -47
- package/skill/references/api-root.md +1 -1
- package/skill/references/cli.md +66 -237
- package/skill/references/recipes.md +20 -28
- package/skill/scripts/sync-references.mjs +33 -53
- package/skill/skill.json +4 -4
package/skill/references/cli.md
CHANGED
|
@@ -9,38 +9,32 @@
|
|
|
9
9
|
- packages/hb-sdk/src/cli/commands/create.ts
|
|
10
10
|
- packages/hb-sdk/src/cli/commands/dev.ts
|
|
11
11
|
- packages/hb-sdk/src/cli/commands/login.ts
|
|
12
|
-
- packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs
|
|
13
12
|
- apps/docs/hb-sdk/guide/cli.md
|
|
14
|
-
- packages/hb-sdk/README.md
|
|
15
13
|
|
|
16
14
|
## Contents
|
|
17
15
|
|
|
18
16
|
- [When to use the CLI](#when-to-use-the-cli)
|
|
19
17
|
- [Command surface](#command-surface)
|
|
20
18
|
- [Create a mini-program template](#create-a-mini-program-template)
|
|
21
|
-
- [Local
|
|
22
|
-
- [Deploy and
|
|
23
|
-
- [
|
|
19
|
+
- [Local debugging](#local-debugging)
|
|
20
|
+
- [Deploy and publish](#deploy-and-publish)
|
|
21
|
+
- [Developer account scope](#developer-account-scope)
|
|
24
22
|
- [Remote management commands](#remote-management-commands)
|
|
25
|
-
- [CLI login
|
|
23
|
+
- [CLI login](#cli-login)
|
|
26
24
|
- [Agent Skill doctor](#agent-skill-doctor)
|
|
27
25
|
- [Update reminders](#update-reminders)
|
|
28
|
-
- [Repository validation commands](#repository-validation-commands)
|
|
29
|
-
- [Generated template README](#generated-template-readme)
|
|
30
26
|
## When to use the CLI
|
|
31
27
|
|
|
32
|
-
Use the bundled `hb-sdk` CLI
|
|
28
|
+
Use the bundled `hb-sdk` CLI to create a workshop mini-program, open the local debugging page, test in the Heybox Mac or mobile App, or manage and publish a remote mini-program.
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
The CLI, templates, and mock host are owned by `@heybox/hb-sdk`. Do not create a second mock runtime package or move CLI guidance outside this package unless the package boundary changes.
|
|
30
|
+
`hb-sdk login` is for development and publishing commands only. It does not change `auth.login()`, `user.getInfo()`, or `network.request()` inside a mini-program.
|
|
37
31
|
|
|
38
32
|
## Command surface
|
|
39
33
|
|
|
40
34
|
```text
|
|
41
35
|
hb-sdk create <project-name>
|
|
42
|
-
hb-sdk dev [--port <port>] [--mock-port <port>] [--
|
|
43
|
-
hb-sdk login
|
|
36
|
+
hb-sdk dev [--port <port>] [--mock-port <port>] [--no-open]
|
|
37
|
+
hb-sdk login
|
|
44
38
|
hb-sdk login status
|
|
45
39
|
hb-sdk login clear
|
|
46
40
|
hb-sdk doctor
|
|
@@ -73,134 +67,111 @@ Top-level `hb-sdk deploy` has been hard-cut and must not be documented as a vali
|
|
|
73
67
|
|
|
74
68
|
## Create a mini-program template
|
|
75
69
|
|
|
76
|
-
##
|
|
70
|
+
## 创建工坊小程序
|
|
71
|
+
|
|
72
|
+
新项目可以直接从模板开始:
|
|
77
73
|
|
|
78
74
|
```bash
|
|
79
|
-
npx @heybox/hb-sdk create my-miniapp
|
|
75
|
+
npx @heybox/hb-sdk@latest create my-miniapp
|
|
80
76
|
cd my-miniapp
|
|
81
77
|
npm install
|
|
82
78
|
npm run dev
|
|
83
79
|
```
|
|
84
80
|
|
|
85
|
-
`
|
|
86
|
-
|
|
87
|
-
CLI 只生成文件,不会自动安装依赖、初始化 git 或打开编辑器。生成模板后优先运行 `npm run dev`,它会启动 Vite 服务和内置 mock runtime host。
|
|
81
|
+
已有项目则在项目目录运行 `npm run dev` 或 `hb-sdk dev`。
|
|
88
82
|
|
|
89
83
|
Agent rules:
|
|
90
84
|
|
|
91
|
-
- Prefer `hb-sdk create <project-name>` for a new
|
|
85
|
+
- Prefer `hb-sdk create <project-name>` for a new workshop mini-program.
|
|
92
86
|
- After creation, the expected next steps are `npm install` and `npm run dev`.
|
|
93
87
|
- Do not claim the CLI installs dependencies, initializes git, opens an editor, or overwrites non-empty directories.
|
|
94
88
|
- Treat `project-name` as an unscoped npm package name and project directory.
|
|
95
89
|
|
|
96
|
-
## Local
|
|
90
|
+
## Local debugging
|
|
97
91
|
|
|
98
|
-
##
|
|
92
|
+
## 推荐调试流程
|
|
99
93
|
|
|
100
|
-
|
|
94
|
+
### 1. 启动调试页
|
|
101
95
|
|
|
102
96
|
```bash
|
|
103
97
|
hb-sdk dev
|
|
104
98
|
```
|
|
105
99
|
|
|
106
|
-
|
|
100
|
+
CLI 会启动页面服务并自动打开本地调试页。调试页会展示小程序、浏览器 Mock、Mac 启动入口和手机二维码。
|
|
107
101
|
|
|
108
|
-
|
|
102
|
+
<img src="https://static.max-c.com/static/heybox/webapp/heybox-docs/docs-hb_sdk/assets/local-preview-debug-page.png" alt="hb-sdk 本地调试页、浏览器 Mock 和真机调试入口" style="width: 100%; max-width: 860px;" />
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
| --------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
112
|
-
| `--port <port>` | 指定小程序 Vite dev server 端口,默认从 `5173` 开始。 |
|
|
113
|
-
| `--mock-port <port>` | 指定 mock host 端口,默认从 `5174` 开始。 |
|
|
114
|
-
| `--runtime-url <url>` | 真实客户端调试时传给 dev shell 的自定义 runtime 地址;手机扫码时 loopback host 会自动改写为所选局域网 IP。 |
|
|
115
|
-
| `--no-open` | 不自动打开浏览器调试页。 |
|
|
104
|
+
未登录或未绑定小程序时,浏览器、Mac 和手机调试入口仍然可用,但受管能力会默认拒绝。登录并绑定后,调试页才能根据当前小程序的线上配置提示差异。
|
|
116
105
|
|
|
117
|
-
|
|
106
|
+
### 2. 先用浏览器 Mock 验收
|
|
118
107
|
|
|
119
|
-
|
|
108
|
+
浏览器 Mock 支持热更新,适合快速检查:
|
|
120
109
|
|
|
121
|
-
|
|
110
|
+
- 页面布局和主要交互
|
|
111
|
+
- SDK 初始化、用户状态与登录流程
|
|
112
|
+
- 生命周期、Storage 和排行榜等能力
|
|
122
113
|
|
|
123
|
-
|
|
114
|
+
Mock 中临时调整的权限只影响本地调试,不会修改线上配置。工坊小程序默认不能进行网络请求,网络权限暂未开放申请;不要把 Mock 中的结果当成线上能力。
|
|
124
115
|
|
|
125
|
-
|
|
116
|
+
### 3. 再用 Mac 或手机真机验收
|
|
126
117
|
|
|
127
|
-
|
|
118
|
+
需要确认真实客户端表现时,从调试页选择一种方式:
|
|
128
119
|
|
|
129
|
-
|
|
120
|
+
- 点击「在 Mac 版 APP 中启动」。
|
|
121
|
+
- 在「Mobile App」区域选择局域网网卡,再用手机小黑盒 APP 扫码。
|
|
130
122
|
|
|
131
|
-
|
|
123
|
+
手机与电脑需要处于同一局域网。二维码无法访问时,先确认选择了正确的 **Network** 网卡。发布前至少完成一次真实客户端验收。
|
|
132
124
|
|
|
133
|
-
|
|
134
|
-
hb-sdk remote deploy --release-note "修复登录状态展示,补充异常提示"
|
|
135
|
-
hb-sdk remote deploy --release-note "审核通过后自动发布" --auto-publish
|
|
136
|
-
hb-sdk remote deploy --from-version 1.2.3 --release-note "复用 1.2.3 历史产物"
|
|
137
|
-
```
|
|
125
|
+
### 浏览器 Mock 的边界
|
|
138
126
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
2. 校验登录态,需先 `hb-sdk login`。
|
|
143
|
-
3. 运行 `hb-sdk remote access` 确认当前主体具备开发者资格;未开通时按开放平台的小程序工坊申请入口提交申请。
|
|
144
|
-
4. 读取并校验 `--release-note`;TTY 环境缺失时会提示输入,CI / 非 TTY 环境缺失时直接失败。建议让 AI 生成 1-5 条简短发布日志。
|
|
145
|
-
5. 普通 remote deploy 先读取 `package.json.version`,登录后、build 前调用版本预检接口;预检通过后才执行 `<pm> run build`。
|
|
146
|
-
6. `--from-version <version>` 跳过本地构建、`dist/` 读取和上传,复用指定历史版本产物提交审核。
|
|
147
|
-
7. 解析 `dist/manifest.json`,自动剥离 BOM,并校验 `version` 是合法 SemVer:允许 prerelease,例如 `1.2.3-rc.1`;拒绝 build metadata,例如 `1.2.3+build.1`;拒绝 `0.0.0`。
|
|
148
|
-
8. 普通 remote deploy 的 `dist/manifest.json.version` 必须与预检使用的 `package.json.version` 一致,否则失败且不上传。
|
|
149
|
-
9. 遍历 `dist/` 文件,过滤掉 `manifest.json`、`.DS_Store`、`*.map`;遇到 symbolic link 或 `node_modules` 路径直接报错。
|
|
150
|
-
10. 校验上传路径长度不超过 64,并在任何上传请求发生前限制实际上传产物总大小不超过 100MiB。错误提示中使用 `100MB`,方便开发者理解。
|
|
151
|
-
11. CLI 会分批上传构建产物并校验平台返回的文件集合;任何批次异常都会停止后续上传且不会提交审核。
|
|
152
|
-
12. 默认只展示上传阶段和文件总数,例如 `正在上传 137/244 个文件`;`--verbose` 会补充逐文件诊断,但不会输出 keys、签名、cookie、pkey、token 或临时密钥。
|
|
153
|
-
13. 全部上传成功后调用提交审核接口;`--from-version` 路径会直接提交 `source_version`。CLI 输出提交审核成功、发布策略和可用的 preview URL。
|
|
154
|
-
|
|
155
|
-
`mini_program_id` 没有 CLI flag,必须落在 `package.json` 里:
|
|
156
|
-
|
|
157
|
-
```json
|
|
158
|
-
{
|
|
159
|
-
"heybox": {
|
|
160
|
-
"miniProgramId": "mp_xxxxxxxx"
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
```
|
|
127
|
+
浏览器 Mock 用于提高开发效率,不代表真实客户端环境。权限切换和用户状态只保存在本地;真实权限、客户端兼容性和最终交互以 Mac 或手机小黑盒 APP 为准。
|
|
128
|
+
|
|
129
|
+
### 常用参数
|
|
164
130
|
|
|
165
|
-
|
|
131
|
+
| 参数 | 用途 |
|
|
132
|
+
| --------------------- | -------------------------------- |
|
|
133
|
+
| `--port <port>` | 指定页面开发服务端口。 |
|
|
134
|
+
| `--mock-port <port>` | 指定本地调试端口。 |
|
|
135
|
+
| `--no-open` | 启动后不自动打开浏览器。 |
|
|
136
|
+
| `--verbose` | 出现问题时输出更详细的诊断信息。 |
|
|
166
137
|
|
|
167
|
-
|
|
138
|
+
Use `hb-sdk dev` to open the local debugging page. The "在 Mac 版 APP 中启动" button opens the page in the Mac App; the "Mobile App" QR code opens it in the phone App after a LAN interface is selected. These entries remain available without CLI login or project binding, but managed capabilities are denied by default. The phone and computer must be on the same LAN. If an embedded browser cannot open the App, use the system browser.
|
|
168
139
|
|
|
169
|
-
|
|
140
|
+
## Deploy and publish
|
|
141
|
+
|
|
142
|
+
## 部署发布
|
|
170
143
|
|
|
171
|
-
|
|
144
|
+
浏览器和真机验收通过后,首次提交前需要登录 CLI 并绑定小程序:
|
|
172
145
|
|
|
173
146
|
```bash
|
|
174
|
-
|
|
175
|
-
|
|
147
|
+
hb-sdk login
|
|
148
|
+
hb-sdk remote create
|
|
149
|
+
# 或绑定已有小程序
|
|
150
|
+
hb-sdk remote bind mp_xxxxxxxx
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
绑定完成后,`package.json` 中会记录 `heybox.miniProgramId`。提交审核使用:
|
|
176
154
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
hb-sdk remote deploy --env-file .env.local --release-note "本地配置构建"
|
|
155
|
+
```bash
|
|
156
|
+
hb-sdk remote deploy --release-note "修复登录状态展示"
|
|
180
157
|
```
|
|
181
158
|
|
|
182
|
-
|
|
159
|
+
这条命令会完成检查、构建、上传和提交审核。默认在审核通过后等待手动发布;普通低风险版本可以追加 `--auto-publish`。完整命令见 `hb-sdk remote --help`,提交要求见[小程序工坊上架规则](https://docs.xiaoheihe.cn/hb_sdk/guide/mini-program-publishing-rules)。
|
|
183
160
|
|
|
184
|
-
Before
|
|
161
|
+
Before publishing, `hb-sdk remote deploy` verifies that the bound mini-program belongs to the current developer account. If it does not, the command stops and asks the user to switch accounts.
|
|
185
162
|
|
|
186
163
|
Agent rules:
|
|
187
164
|
|
|
188
165
|
- Use `hb-sdk remote deploy --release-note <text>` for normal build, upload, and submit-audit flows.
|
|
189
166
|
- Use `hb-sdk remote deploy --from-version <version> --release-note <text>` to reuse a remote history artifact.
|
|
190
|
-
-
|
|
167
|
+
- If the bound mini-program does not belong to the current developer account, stop and ask the user to switch accounts.
|
|
191
168
|
- Never recommend top-level `hb-sdk deploy`; it has been removed rather than retained as a compatibility alias.
|
|
192
169
|
- After non-auto deploy succeeds, suggest `hb-sdk remote versions` and then `hb-sdk remote release <version>` after approval. Do not send the user to Open for manual publish when the CLI command exists.
|
|
193
170
|
- Use `hb-sdk remote allowlist add <heybox_id>` when preview access needs to be granted.
|
|
194
|
-
- Use `--api-base-url <url>` or `HB_SDK_API_BASE_URL` for remote platform backend APIs.
|
|
195
|
-
- Use `--allow-unsafe-api-base-url` or `HB_SDK_ALLOW_UNSAFE_API_BASE_URL=1` only for local backend debugging against non-Heybox or non-HTTPS API origins.
|
|
196
|
-
- Use `--login-base-url <url>` or `HB_SDK_LOGIN_BASE_URL` for CLI browser login and remote command login-environment validation.
|
|
197
|
-
- Use `packages/hb-sdk/src/cli/config.ts` with `RylaiServiceTagConfig` only when Heybox backend API requests need the development-only `x-rylai-service-tag` header and matching `special_tag` query parameter.
|
|
198
|
-
- Custom base URLs must be origin-only; API origins must be Heybox trusted HTTPS unless the unsafe debug switch is explicit. Do not include path, query, or hash.
|
|
199
|
-
- Do not expect custom base URLs to affect `hb-sdk doctor`, npm latest checks, or mock-host `network.request()`.
|
|
200
171
|
|
|
201
|
-
##
|
|
172
|
+
## Developer account scope
|
|
202
173
|
|
|
203
|
-
Developer
|
|
174
|
+
Developer account selection lives under `hb-sdk remote entity`:
|
|
204
175
|
|
|
205
176
|
```bash
|
|
206
177
|
hb-sdk remote entity list
|
|
@@ -208,55 +179,18 @@ hb-sdk remote entity current
|
|
|
208
179
|
hb-sdk remote entity switch <entity-id>
|
|
209
180
|
```
|
|
210
181
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`hb-sdk login` tries to make the server-side current entity explicit after browser login. Zero entities leaves login successful and prints a guidance message. One entity is displayed and, when needed, switched to current. Multiple entities in a TTY prompt for a choice; multiple entities in non-interactive mode do not block login but tell the user to run `hb-sdk remote entity switch <entity-id>`. Passing `--no-select-entity` writes only the login state and does not modify the server-side current entity.
|
|
182
|
+
Remote management commands use the current developer account. Use `current` to confirm it and `switch` to change it before creating, binding, or publishing a mini-program.
|
|
214
183
|
|
|
215
184
|
Agent rules:
|
|
216
185
|
|
|
217
|
-
- Treat the
|
|
218
|
-
- Treat CLI `selectedEntity` as a display/debug snapshot only; it can drift from the server-side current entity and must not be used as a permission source.
|
|
186
|
+
- Treat the current developer account as the scope for remote create, bind, deploy, list, access, versions, preview, release, withdraw, take-down, reopen, and square-display workflows.
|
|
219
187
|
- Use `hb-sdk remote entity current` when a user needs to confirm which entity create/deploy will use.
|
|
220
188
|
- Use `hb-sdk remote entity switch <entity-id>` to change entity scope. Do not recommend `--entity-id` or an environment variable as a remote command override.
|
|
221
189
|
- `hb-sdk remote list` lists mini-programs in the current entity scope only; do not promise cross-entity aggregation.
|
|
222
190
|
|
|
223
191
|
## Remote management commands
|
|
224
192
|
|
|
225
|
-
## 远端管理命令
|
|
226
|
-
|
|
227
|
-
远端平台操作统一放在 `hb-sdk remote` 命令组下,默认作用于当前项目绑定的小程序,也就是 `package.json.heybox.miniProgramId`。`remote list` 只用于发现可管理的小程序;会改变远端状态的命令仍然只操作当前绑定的小程序,不接受临时 `mini_program_id` 参数。
|
|
228
193
|
|
|
229
|
-
常用命令:
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
hb-sdk remote access
|
|
233
|
-
hb-sdk remote entity list
|
|
234
|
-
hb-sdk remote entity current
|
|
235
|
-
hb-sdk remote entity switch <entity-id>
|
|
236
|
-
hb-sdk remote list
|
|
237
|
-
hb-sdk remote create
|
|
238
|
-
hb-sdk remote bind mp_xxxxxxxx
|
|
239
|
-
hb-sdk remote info
|
|
240
|
-
hb-sdk remote allowlist add 12345678
|
|
241
|
-
hb-sdk remote versions
|
|
242
|
-
hb-sdk remote preview 1.2.3
|
|
243
|
-
hb-sdk remote release 1.2.3
|
|
244
|
-
hb-sdk remote withdraw 1.2.3 --reason "需要修复说明"
|
|
245
|
-
hb-sdk remote take-down
|
|
246
|
-
hb-sdk remote reopen
|
|
247
|
-
hb-sdk remote square hide
|
|
248
|
-
hb-sdk remote square show
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
`hb-sdk remote create` 会创建远端工坊小程序并写入当前项目绑定;已有绑定时必须传 `--force-bind` 才能覆盖。`hb-sdk remote bind <mini-program-id>` 会先校验当前 CLI 用户可管理目标小程序,再写入本地配置;`--force` 只允许覆盖本地绑定,不跳过远端校验。
|
|
252
|
-
|
|
253
|
-
小程序名称、icon 和介绍图在开放平台「版本发布」中维护并随版本审核。CLI 项目配置只保留 `package.json.heybox.miniProgramId`;首次部署且没有历史审核资料时,服务端会使用默认名称「我的小程序」与平台默认图片。
|
|
254
|
-
|
|
255
|
-
`hb-sdk remote square hide` 会隐藏当前绑定小程序在普通用户侧的小程序工坊广场展示;白名单用户仍可在小程序工坊广场看到,直接链接访问已发布版本也不受影响。`hb-sdk remote square show` 会恢复普通用户侧的小程序工坊广场展示。
|
|
256
|
-
|
|
257
|
-
`hb-sdk remote release`、`withdraw`、`take-down`、`reopen` 和 `square hide` 会改变审核、发布或用户侧可见状态。交互式终端会展示目标和变更内容后要求确认;非 TTY 环境必须传 `--yes`。`entity switch`、`square show` 和 allowlist 写操作当前不会进行这层 CLI 确认,自动化脚本不要为它们假设存在确认保护。
|
|
258
|
-
|
|
259
|
-
所有 `hb-sdk remote` 子命令都支持 `--json`。开启后 stdout 只输出一个 JSON 对象;进度、警告、版本提醒和 verbose 诊断不能污染 stdout。`remote deploy --json` 不进行交互式 release note 提示,必须显式传 `--release-note`。
|
|
260
194
|
|
|
261
195
|
Agent rules:
|
|
262
196
|
|
|
@@ -271,137 +205,32 @@ Agent rules:
|
|
|
271
205
|
- Require confirmation or `--yes` for `hb-sdk remote release`, `hb-sdk remote withdraw`, `hb-sdk remote take-down`, `hb-sdk remote reopen`, and `hb-sdk remote square hide`.
|
|
272
206
|
- Use `--json` for script consumption and keep stdout as exactly one JSON object.
|
|
273
207
|
|
|
274
|
-
## CLI login
|
|
208
|
+
## CLI login
|
|
275
209
|
|
|
276
210
|
## CLI 登录态
|
|
277
211
|
|
|
212
|
+
CLI 登录态只用于开发工具和远端管理,不等同于小程序内的用户登录态,也不会改变 `auth.login()` 或 `user.getInfo()` 的结果。
|
|
213
|
+
|
|
278
214
|
```bash
|
|
279
|
-
hb-sdk login
|
|
280
215
|
hb-sdk login status
|
|
281
216
|
hb-sdk login clear
|
|
282
217
|
```
|
|
283
218
|
|
|
284
|
-
- `hb-sdk login` 会打开 `login.xiaoheihe.cn`,通过本地临时回调服务接收登录结果。
|
|
285
|
-
- 登录成功后默认还会查询开发者主体;`--no-select-entity` 会跳过登录后的主体选择。
|
|
286
|
-
- `hb-sdk login status` 默认展示脱敏状态、`heyboxId`、`loginBaseUrl` 和登录时间;`--verbose` 额外展示 cache 路径。不输出 `pkey`、cookie 或完整请求头。
|
|
287
|
-
- `hb-sdk login clear` 只清理 `hb-sdk` 自己命名空间中的 Heybox 登录态。
|
|
288
|
-
|
|
289
|
-
这份 CLI 登录态不会注入 iframe SDK,也不会改变 `hb-sdk dev` 的 mock 用户、`auth.login()`、`user.getInfo()` 或 `network.request()` 行为。
|
|
290
|
-
|
|
291
219
|
Agent rules:
|
|
292
220
|
|
|
293
|
-
- Keep CLI
|
|
294
|
-
- Keep `selectedEntity` guidance explicit: it is only a hint snapshot, while every remote command uses the server-side current entity.
|
|
221
|
+
- Keep CLI login separate from the mini-program user login state.
|
|
295
222
|
- It is correct to say status output is redacted.
|
|
296
223
|
- Do not expose or template pkey, cookie, token, or private credential values.
|
|
297
224
|
- Use `hb-sdk login clear` only to clear the `hb-sdk` CLI namespace.
|
|
298
225
|
|
|
299
226
|
## Agent Skill doctor
|
|
300
227
|
|
|
301
|
-
## Agent Skill doctor
|
|
302
|
-
|
|
303
|
-
```bash
|
|
304
|
-
hb-sdk doctor
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
`hb-sdk doctor` 用来诊断本机 `hb-sdk` Agent Skill 是否匹配当前 SDK。它会对比当前 `@heybox/hb-sdk` 版本、远端 latest skill 元数据,以及本机 `$CODEX_HOME/skills/hb-sdk/skill.json`;没有 `CODEX_HOME` 时读取 `~/.codex/skills/hb-sdk/skill.json`。
|
|
308
|
-
|
|
309
|
-
`doctor` 只诊断,不修改本地文件。需要安装或刷新 skill 时,按输出提示手动执行 `npx skills add`。
|
|
310
|
-
|
|
311
|
-
| 状态 | 含义 |
|
|
312
|
-
| -------------------- | -------------------------------------------------------- |
|
|
313
|
-
| `OK` | SDK、远端 latest skill、本机 skill 全部匹配。 |
|
|
314
|
-
| `SKILL_MISSING` | 本机没有安装 `hb-sdk` skill。 |
|
|
315
|
-
| `SKILL_OUTDATED` | 本机 `skillVersion` 与远端 latest 不一致。 |
|
|
316
|
-
| `SDK_MISMATCH` | 当前 SDK 版本与远端 latest skill 声明的 SDK 版本不一致。 |
|
|
317
|
-
| `REMOTE_UNAVAILABLE` | 无法读取公开 manifest,诊断失败且不会修改本地文件。 |
|
|
318
|
-
|
|
319
|
-
手动安装或刷新 skill:
|
|
320
|
-
|
|
321
|
-
```bash
|
|
322
|
-
npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk
|
|
323
|
-
```
|
|
324
228
|
|
|
325
|
-
如果状态是 `SDK_MISMATCH`,先升级 `@heybox/hb-sdk@latest`,再重新运行 `hb-sdk doctor` 并按提示安装 latest skill。当前只维护 latest skill,不维护历史 SDK 的 skill 快照。
|
|
326
229
|
|
|
327
230
|
Agent rules:
|
|
328
231
|
|
|
329
232
|
- Use `hb-sdk doctor` for read-only diagnosis of local SDK, remote latest skill metadata, and local skill metadata.
|
|
330
233
|
- Do not use `hb-sdk doctor` to auto-install skills; when installation or refresh is needed, tell the user to run `npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk`.
|
|
331
234
|
- If doctor reports `SDK_MISMATCH`, tell the user to upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
|
|
332
|
-
- The supported local skill path is `$CODEX_HOME/skills/hb-sdk/skill.json`, falling back to `~/.codex/skills/hb-sdk/skill.json`.
|
|
333
235
|
|
|
334
236
|
## Update reminders
|
|
335
|
-
|
|
336
|
-
## 版本提醒
|
|
337
|
-
|
|
338
|
-
`hb-sdk create`、`hb-sdk dev`、`hb-sdk remote ...`、`hb-sdk login`、`hb-sdk login status`、`hb-sdk login clear`、`hb-sdk doctor` 会在命令成功执行后检查 npm registry 上 `@heybox/hb-sdk` 的 `latest` 版本。普通命令的检查结果会缓存 24 小时;检查失败会静默跳过;`CI=true` 时会跳过检查,避免污染 CI 日志。`hb-sdk doctor` 已经诊断出 `SDK_MISMATCH` 时不会再追加统一提醒,避免同一次输出里重复提示升级 SDK。`hb-sdk --version` / `hb-sdk -V` 会直接请求 npm registry 获取 latest,不读取本地缓存;stdout 只输出版本号,升级提醒继续按 warn 级别写到 stderr。本地可通过 `HB_SDK_NO_UPDATE_CHECK=1` 禁用检查。
|
|
339
|
-
|
|
340
|
-
## Repository validation commands
|
|
341
|
-
|
|
342
|
-
## 本仓库开发
|
|
343
|
-
|
|
344
|
-
```bash
|
|
345
|
-
pnpm --filter @heybox/hb-sdk run test:unit
|
|
346
|
-
pnpm --filter @heybox/hb-sdk run build:package
|
|
347
|
-
pnpm --filter @heybox/hb-sdk run check:boundary
|
|
348
|
-
pnpm exec hbexec hb-sdk check
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
`check:boundary` 用于保护 SDK、CLI、mock host 与 runtime 之间的依赖边界。调整 CLI、mock 或协议导出时应一起运行。
|
|
352
|
-
|
|
353
|
-
`hbexec hb-sdk check` 只读校验 docs、skill references,并在临时目录生成与校验 `agent-skills` payload;不要求 canonical artifact 已存在,也不包含 changelog。维护清单见 `packages/hb-sdk/DOC_SYNC_CHECKLIST.md`。
|
|
354
|
-
|
|
355
|
-
## Generated template README
|
|
356
|
-
|
|
357
|
-
````md
|
|
358
|
-
# <%= projectName %>
|
|
359
|
-
|
|
360
|
-
这是通过 `hb-sdk create` 生成的黑盒外部小程序开发模板。项目使用 Vue 3、Vite、TypeScript 和 `@heybox/hb-sdk`。
|
|
361
|
-
|
|
362
|
-
## 使用命令
|
|
363
|
-
|
|
364
|
-
```bash
|
|
365
|
-
npm install
|
|
366
|
-
npm run dev
|
|
367
|
-
npm run typecheck
|
|
368
|
-
npm run test:unit
|
|
369
|
-
npm run build
|
|
370
|
-
npm run deploy
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
## 依赖说明
|
|
374
|
-
|
|
375
|
-
`@heybox/hb-sdk` 是小程序页面运行时会 import 的 SDK,因此模板把它放在 `dependencies`。Vite、TypeScript、Vitest 等只参与本地开发、测试或构建的工具放在 `devDependencies`。
|
|
376
|
-
|
|
377
|
-
## 开发模式
|
|
378
|
-
|
|
379
|
-
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面,也可以选择局域网网卡后用手机小黑盒 APP 扫码调试。手机需要与电脑处在同一局域网,并使用支持小程序调试壳的新版小黑盒 APP。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
|
|
380
|
-
- `npm run build`:先执行 TypeScript 检查,再构建生产产物。
|
|
381
|
-
- `npm run deploy -- --release-note "..."`:运行 `hb-sdk remote deploy`,构建、上传并提交当前小程序版本审核。部署前需要先执行过 `npx hb-sdk login`;多主体账号还应通过 `npx hb-sdk remote entity current` 确认服务端 current entity。远端小程序可通过 `npx hb-sdk remote create` 在 current entity 下创建并绑定,或用 `npx hb-sdk remote bind <mini-program-id>` 绑定 current entity 可管理的已有小程序。小程序名称、icon 和介绍图在开放平台版本发布中维护;CLI 项目配置只保留 `heybox.miniProgramId`,首次部署服务端会使用默认名与默认图。`selectedEntity` 只是 CLI 登录缓存中的提示快照,实际 deploy/create/bind 以服务端 current entity 为准。默认审核通过后用 `hb-sdk remote versions` 查看状态,再用 `hb-sdk remote release <version>` 发布,如需审核通过后自动发布可追加 `--auto-publish`。顶层 `hb-sdk deploy` 已删除,不再作为兼容别名保留。
|
|
382
|
-
|
|
383
|
-
## 更多能力
|
|
384
|
-
|
|
385
|
-
模板页面只保留最小接入示例。其他常用能力可以直接从 `@heybox/hb-sdk` 调用:
|
|
386
|
-
|
|
387
|
-
```ts
|
|
388
|
-
import hbSDK from '@heybox/hb-sdk';
|
|
389
|
-
|
|
390
|
-
await hbSDK.share.showShareMenu({
|
|
391
|
-
title: '<%= projectName %>',
|
|
392
|
-
desc: '分享描述',
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
await hbSDK.storage.setStorage({
|
|
396
|
-
key: 'settings',
|
|
397
|
-
data: { theme: 'dark' },
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
const response = await hbSDK.network.request({
|
|
401
|
-
method: 'GET',
|
|
402
|
-
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
|
403
|
-
});
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
工坊小程序通常不要传 `url`;宿主 runtime 会自动生成当前小程序的通用分享页。只有确实要分享外部 HTTP(S) 页面时才显式传 `url`。
|
|
407
|
-
````
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
# 快速开始
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
如果页面不需要小黑盒开放能力,可以不接入 SDK。这是最短接入路径:等待 SDK 就绪,然后读取当前用户登录态。
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
30
|
import hbSDK from '@heybox/hb-sdk'
|
|
@@ -78,13 +78,11 @@ onUnmounted(stopAuthChange)
|
|
|
78
78
|
|
|
79
79
|
## ready 的含义
|
|
80
80
|
|
|
81
|
-
`ready()` 表示 SDK
|
|
81
|
+
`ready()` 表示 SDK 已就绪,可以安全调用开放能力。如果当前不在可用的小程序运行环境中,它会抛出公开错误。`ready()` 不等价于“用户已登录”,用户状态需要通过 `user.getInfo()` 或 `authChange` 判断。
|
|
82
82
|
|
|
83
83
|
## 默认单例适合什么场景
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
0.6 起根入口只提供唯一默认实例并在导入时立即握手,不再允许业务创建独立实例。测试需要隔离 bridge 时应在应用边界替换公开模块。
|
|
85
|
+
大多数小程序页面都应该使用默认实例。0.6 起不再对业务代码提供独立实例工厂。
|
|
88
86
|
|
|
89
87
|
## User and login
|
|
90
88
|
|
|
@@ -96,7 +94,7 @@ onUnmounted(stopAuthChange)
|
|
|
96
94
|
- `user.getInfo()`:静默读取当前登录态与公开基础资料。
|
|
97
95
|
- `auth.login()`:唤起黑盒登录流程,并返回登录后的最新公开用户资料。
|
|
98
96
|
- `user.getCurrentUserDetail()`:读取当前用户展示详情。
|
|
99
|
-
- `user.getCurrentUserProfile()
|
|
97
|
+
- `user.getCurrentUserProfile()`:读取当前用户敏感资料,需要对应平台权限。
|
|
100
98
|
- `user.getPlatformAccountOverview()` / `getPlatformAccountInfo()`:读取平台账号概览或指定平台详情。
|
|
101
99
|
- `user.getSteamGameList()`:读取当前用户 Steam 游戏库。
|
|
102
100
|
|
|
@@ -147,7 +145,7 @@ async function ensureLogin() {
|
|
|
147
145
|
|
|
148
146
|
不会暴露 token、cookie、手机号或任何可用于调用主站私有接口的凭据。
|
|
149
147
|
|
|
150
|
-
current-user scoped API 返回独立的 `UserScopedResult<T>`。未登录时是 `{ isLogin: false, data: null }`;已登录时才有 `data`。其中 `getCurrentUserProfile()`
|
|
148
|
+
current-user scoped API 返回独立的 `UserScopedResult<T>`。未登录时是 `{ isLogin: false, data: null }`;已登录时才有 `data`。其中 `getCurrentUserProfile()` 可能返回生日、邮箱、教育和职业等敏感资料,必须按最小必要原则使用,并以平台权限结果为准;不要把这些字段理解为 `getInfo()` 的默认返回值。
|
|
151
149
|
|
|
152
150
|
```ts
|
|
153
151
|
const profile = await user.getCurrentUserProfile()
|
|
@@ -183,7 +181,7 @@ onUnmounted(stopAuthChange)
|
|
|
183
181
|
|
|
184
182
|
# 事件与生命周期
|
|
185
183
|
|
|
186
|
-
SDK 通过 `on`
|
|
184
|
+
SDK 通过 `on` 监听小程序生命周期和业务事件。
|
|
187
185
|
|
|
188
186
|
```ts
|
|
189
187
|
import { onUnmounted } from 'vue'
|
|
@@ -212,12 +210,12 @@ onUnmounted(stopLifecycleEvents)
|
|
|
212
210
|
|
|
213
211
|
| 事件 | 触发时机 | 典型用途 |
|
|
214
212
|
| ------------ | ------------------------ | ------------------ |
|
|
215
|
-
| `launch` |
|
|
216
|
-
| `ready` | SDK 可安全调用开放能力
|
|
213
|
+
| `launch` | 小程序首次启动 | 初始化一次性数据 |
|
|
214
|
+
| `ready` | SDK 可安全调用开放能力 | 标记 SDK 可用 |
|
|
217
215
|
| `show` | 小程序页面展示 | 刷新可见态数据 |
|
|
218
216
|
| `hide` | 小程序页面隐藏 | 暂停轮询、暂停播放 |
|
|
219
|
-
| `unload` |
|
|
220
|
-
| `error` |
|
|
217
|
+
| `unload` | 当前小程序运行环境终止 | 清理资源并停止请求 |
|
|
218
|
+
| `error` | 小程序或开放能力运行异常 | 统一错误上报 |
|
|
221
219
|
| `authChange` | 登录状态变化 | 刷新用户信息和权限 |
|
|
222
220
|
|
|
223
221
|
完整载荷与事件名见:
|
|
@@ -239,7 +237,10 @@ onUnmounted(stopLifecycleEvents)
|
|
|
239
237
|
|
|
240
238
|
# 错误处理
|
|
241
239
|
|
|
242
|
-
SDK
|
|
240
|
+
SDK 公开两类标准错误:
|
|
241
|
+
|
|
242
|
+
- `HbMiniProgramSDKError`:SDK 初始化或开放能力调用失败。
|
|
243
|
+
- `HbMiniProgramNetworkError`:网络请求已返回,但 HTTP 状态未通过 `validateStatus`。
|
|
243
244
|
|
|
244
245
|
```ts
|
|
245
246
|
import {
|
|
@@ -265,19 +266,14 @@ try {
|
|
|
265
266
|
}
|
|
266
267
|
```
|
|
267
268
|
|
|
268
|
-
##
|
|
269
|
+
## 处理原则
|
|
269
270
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
| `READY_TIMEOUT` | SDK 握手超时 | 检查父容器是否幂等响应重试的 `sdk.handshake` |
|
|
275
|
-
| `HANDSHAKE_FAILED` | 握手消息发送失败 | 检查 iframe、nonce 与 Host 消息通道 |
|
|
276
|
-
| `RUNTIME_UNAVAILABLE` | Runtime 已执行 `unload` | 停止当前上下文请求并结束页面工作 |
|
|
277
|
-
| `REQUEST_TIMEOUT` | 开放能力调用超时 | 提示重试,并上报 method |
|
|
278
|
-
| `INVALID_NETWORK_RESPONSE` | Host 返回的网络响应结构无效 | 上报 Host/Runtime 协议问题 |
|
|
271
|
+
- 根据 `error.code` 区分运行环境、权限、超时和业务失败,不要只比对错误文案。
|
|
272
|
+
- 权限失败时给出可理解的提示,不要将它当成未登录。
|
|
273
|
+
- 超时或运行环境不可用时,允许用户重试或退出当前流程。
|
|
274
|
+
- 上报 `code`、`message` 和必要的业务上下文,不要上报用户凭据或敏感数据。
|
|
279
275
|
|
|
280
|
-
|
|
276
|
+
完整错误码和字段见 [HbMiniProgramSDKError](api-root.md) 与 [HbMiniProgramNetworkError](api-root.md)。
|
|
281
277
|
|
|
282
278
|
## 业务层建议
|
|
283
279
|
|
|
@@ -307,10 +303,6 @@ function reportSDKError(code: string, message: string, data?: unknown) {
|
|
|
307
303
|
}
|
|
308
304
|
```
|
|
309
305
|
|
|
310
|
-
## 超时时间
|
|
311
|
-
|
|
312
|
-
默认握手超时时间是 10000ms。0.6 起业务不能通过独立实例修改该值;超时应作为 Host/Runtime 启动异常处理。
|
|
313
|
-
|
|
314
306
|
## Login gate recipe
|
|
315
307
|
|
|
316
308
|
|