@heybox/hb-sdk 0.6.4-alpha.0 → 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/README.md +3 -3
- package/dist/cli-chunks/{context-BCwksd8H.cjs → context-DjepdCaa.cjs} +1 -1
- package/dist/cli-chunks/{create-BO8GHVi0.cjs → create-D3BBKay9.cjs} +1 -1
- package/dist/cli-chunks/{dev-DmgKnEC2.cjs → dev-C3u5FXIy.cjs} +9 -13
- package/dist/cli-chunks/{doctor-BlKB4f78.cjs → doctor-DEgZa2qC.cjs} +1 -1
- package/dist/cli-chunks/{index-PxkpQ5of.cjs → index-B5gEl9ow.cjs} +2 -2
- package/dist/cli-chunks/{index-Q0G1SsEs.cjs → index-CKat0ExC.cjs} +38 -13
- package/dist/cli-chunks/{login-Cxdo4B6Z.cjs → login-B6gERpSX.cjs} +2 -2
- package/dist/cli-chunks/{remote-C1Rsb1dx.cjs → remote-BfQiZzeJ.cjs} +4 -4
- package/dist/cli-chunks/{session-CC3Oz3Xc.cjs → session-DPEq__gB.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/mock-host/index.html +0 -19
- package/dist/devtools/mock-host/main.js +72 -91
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/protocol.cjs.js +54 -0
- package/dist/protocol.esm.js +53 -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-protocol.md +18 -17
- package/skill/references/api-root.md +3 -3
- package/skill/references/cli.md +65 -245
- package/skill/references/recipes.md +91 -50
- package/skill/scripts/sync-references.mjs +35 -53
- package/skill/skill.json +4 -4
- package/types/protocol/runtime-permissions.d.ts +41 -0
- package/types/protocol.d.ts +4 -2
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,145 +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
|
-
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
|
-
hb-sdk remote deploy --api-base-url https://api.test.xiaoheihe.cn --login-base-url https://login.test.xiaoheihe.cn --release-note "测试环境验证"
|
|
138
|
-
hb-sdk remote deploy --verbose --api-base-url https://api.test.xiaoheihe.cn --login-base-url https://login.test.xiaoheihe.cn --release-note "排查预检失败"
|
|
139
|
-
HB_SDK_ALLOW_UNSAFE_API_BASE_URL=1 hb-sdk remote deploy --api-base-url http://127.0.0.1:8080 --release-note "本地后台联调"
|
|
140
|
-
```
|
|
125
|
+
### 浏览器 Mock 的边界
|
|
141
126
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
9. 遍历 `dist/` 文件,过滤掉 `manifest.json`、`.DS_Store`、`*.map`;遇到 symbolic link 或 `node_modules` 路径直接报错。
|
|
153
|
-
10. 校验上传路径长度不超过 64,并在任何上传请求发生前限制实际上传产物总大小不超过 100MiB。错误提示中使用 `100MB`,方便开发者理解。
|
|
154
|
-
11. 上传信息、上传凭证和上传回调按批次执行,每批最多 50 个文件;批次串行,批内保持 4 并发上传到 CDN。CLI 会校验 CDN 上传信息接口返回的 key 与本地期望 key 完全一致,异常时停止后续批次且不提交审核。
|
|
155
|
-
12. 默认只展示上传阶段和文件总数,例如 `正在上传 137/244 个文件`;`--verbose` 会展示并发数、批次数、当前批次、bucket / region 和逐文件结果,但不会输出 keys、签名、cookie、pkey、token 或临时密钥。
|
|
156
|
-
13. 全部上传成功后调用提交审核接口;`--from-version` 路径会直接提交 `source_version`。CLI 输出提交审核成功、发布策略和可用的 preview URL。
|
|
157
|
-
|
|
158
|
-
`mini_program_id` 没有 CLI flag,必须落在 `package.json` 里:
|
|
159
|
-
|
|
160
|
-
```json
|
|
161
|
-
{
|
|
162
|
-
"heybox": {
|
|
163
|
-
"miniProgramId": "mp_xxxxxxxx"
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
```
|
|
127
|
+
浏览器 Mock 用于提高开发效率,不代表真实客户端环境。权限切换和用户状态只保存在本地;真实权限、客户端兼容性和最终交互以 Mac 或手机小黑盒 APP 为准。
|
|
128
|
+
|
|
129
|
+
### 常用参数
|
|
130
|
+
|
|
131
|
+
| 参数 | 用途 |
|
|
132
|
+
| --------------------- | -------------------------------- |
|
|
133
|
+
| `--port <port>` | 指定页面开发服务端口。 |
|
|
134
|
+
| `--mock-port <port>` | 指定本地调试端口。 |
|
|
135
|
+
| `--no-open` | 启动后不自动打开浏览器。 |
|
|
136
|
+
| `--verbose` | 出现问题时输出更详细的诊断信息。 |
|
|
167
137
|
|
|
168
|
-
`
|
|
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.
|
|
169
139
|
|
|
170
|
-
|
|
140
|
+
## Deploy and publish
|
|
171
141
|
|
|
172
|
-
|
|
142
|
+
## 部署发布
|
|
173
143
|
|
|
174
|
-
|
|
144
|
+
浏览器和真机验收通过后,首次提交前需要登录 CLI 并绑定小程序:
|
|
175
145
|
|
|
176
|
-
|
|
146
|
+
```bash
|
|
147
|
+
hb-sdk login
|
|
148
|
+
hb-sdk remote create
|
|
149
|
+
# 或绑定已有小程序
|
|
150
|
+
hb-sdk remote bind mp_xxxxxxxx
|
|
151
|
+
```
|
|
177
152
|
|
|
178
|
-
|
|
153
|
+
绑定完成后,`package.json` 中会记录 `heybox.miniProgramId`。提交审核使用:
|
|
179
154
|
|
|
180
155
|
```bash
|
|
181
|
-
|
|
182
|
-
# HB_SDK_API_BASE_URL=https://api.test.xiaoheihe.cn
|
|
183
|
-
# HB_SDK_LOGIN_BASE_URL=https://login.test.xiaoheihe.cn
|
|
184
|
-
# HB_SDK_SERVICE_TAG=my-test-tag
|
|
185
|
-
|
|
186
|
-
hb-sdk remote deploy --env test --release-note "测试环境验证"
|
|
187
|
-
hb-sdk remote info --env test
|
|
188
|
-
HB_SDK_ENV=test hb-sdk remote versions
|
|
189
|
-
hb-sdk remote deploy --env-file .env.local --release-note "本地联调"
|
|
190
|
-
hb-sdk remote deploy --env test --service-tag other-tag --release-note "灰度" # 单项 flag 覆盖预设
|
|
156
|
+
hb-sdk remote deploy --release-note "修复登录状态展示"
|
|
191
157
|
```
|
|
192
158
|
|
|
193
|
-
`--
|
|
159
|
+
这条命令会完成检查、构建、上传和提交审核。默认在审核通过后等待手动发布;普通低风险版本可以追加 `--auto-publish`。完整命令见 `hb-sdk remote --help`,提交要求见[小程序工坊上架规则](https://docs.xiaoheihe.cn/hb_sdk/guide/mini-program-publishing-rules)。
|
|
194
160
|
|
|
195
|
-
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.
|
|
196
162
|
|
|
197
163
|
Agent rules:
|
|
198
164
|
|
|
199
165
|
- Use `hb-sdk remote deploy --release-note <text>` for normal build, upload, and submit-audit flows.
|
|
200
166
|
- Use `hb-sdk remote deploy --from-version <version> --release-note <text>` to reuse a remote history artifact.
|
|
201
|
-
-
|
|
167
|
+
- If the bound mini-program does not belong to the current developer account, stop and ask the user to switch accounts.
|
|
202
168
|
- Never recommend top-level `hb-sdk deploy`; it has been removed rather than retained as a compatibility alias.
|
|
203
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.
|
|
204
170
|
- Use `hb-sdk remote allowlist add <heybox_id>` when preview access needs to be granted.
|
|
205
|
-
- Use `--api-base-url <url>` or `HB_SDK_API_BASE_URL` for remote platform backend APIs.
|
|
206
|
-
- 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.
|
|
207
|
-
- Use `--login-base-url <url>` or `HB_SDK_LOGIN_BASE_URL` for CLI browser login and remote command login-environment validation.
|
|
208
|
-
- 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.
|
|
209
|
-
- 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.
|
|
210
|
-
- Do not expect custom base URLs to affect `hb-sdk doctor`, npm latest checks, or mock-host `network.request()`.
|
|
211
171
|
|
|
212
|
-
##
|
|
172
|
+
## Developer account scope
|
|
213
173
|
|
|
214
|
-
Developer
|
|
174
|
+
Developer account selection lives under `hb-sdk remote entity`:
|
|
215
175
|
|
|
216
176
|
```bash
|
|
217
177
|
hb-sdk remote entity list
|
|
@@ -219,52 +179,18 @@ hb-sdk remote entity current
|
|
|
219
179
|
hb-sdk remote entity switch <entity-id>
|
|
220
180
|
```
|
|
221
181
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
`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.
|
|
225
183
|
|
|
226
184
|
Agent rules:
|
|
227
185
|
|
|
228
|
-
- Treat the
|
|
229
|
-
- 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.
|
|
230
187
|
- Use `hb-sdk remote entity current` when a user needs to confirm which entity create/deploy will use.
|
|
231
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.
|
|
232
189
|
- `hb-sdk remote list` lists mini-programs in the current entity scope only; do not promise cross-entity aggregation.
|
|
233
190
|
|
|
234
191
|
## Remote management commands
|
|
235
192
|
|
|
236
|
-
## 远端管理命令
|
|
237
|
-
|
|
238
|
-
远端平台操作统一放在 `hb-sdk remote` 命令组下,默认作用于当前项目绑定的小程序,也就是 `package.json.heybox.miniProgramId`。`remote list` 只用于发现可管理的小程序;会改变远端状态的命令仍然只操作当前绑定的小程序,不接受临时 `mini_program_id` 参数。
|
|
239
193
|
|
|
240
|
-
常用命令:
|
|
241
|
-
|
|
242
|
-
```bash
|
|
243
|
-
hb-sdk remote access
|
|
244
|
-
hb-sdk remote list
|
|
245
|
-
hb-sdk remote create
|
|
246
|
-
hb-sdk remote bind mp_xxxxxxxx
|
|
247
|
-
hb-sdk remote info
|
|
248
|
-
hb-sdk remote allowlist add 12345678
|
|
249
|
-
hb-sdk remote versions
|
|
250
|
-
hb-sdk remote preview 1.2.3
|
|
251
|
-
hb-sdk remote release 1.2.3
|
|
252
|
-
hb-sdk remote withdraw 1.2.3 --reason "需要修复说明"
|
|
253
|
-
hb-sdk remote take-down
|
|
254
|
-
hb-sdk remote reopen
|
|
255
|
-
hb-sdk remote square hide
|
|
256
|
-
hb-sdk remote square show
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
`hb-sdk remote create` 会创建远端工坊小程序并写入当前项目绑定;已有绑定时必须传 `--force-bind` 才能覆盖。`hb-sdk remote bind <mini-program-id>` 会先校验当前 CLI 用户可管理目标小程序,再写入本地配置;`--force` 只允许覆盖本地绑定,不跳过远端校验。
|
|
260
|
-
|
|
261
|
-
小程序名称、icon 和介绍图在开放平台「版本发布」中维护并随版本审核。CLI 项目配置只保留 `package.json.heybox.miniProgramId`;首次部署且没有历史审核资料时,服务端会使用默认名称「我的小程序」与平台默认图片。
|
|
262
|
-
|
|
263
|
-
`hb-sdk remote square hide` 会隐藏当前绑定小程序在普通用户侧的小程序工坊广场展示;白名单用户仍可在小程序工坊广场看到,直接链接访问已发布版本也不受影响。`hb-sdk remote square show` 会恢复普通用户侧的小程序工坊广场展示。
|
|
264
|
-
|
|
265
|
-
`hb-sdk remote release`、`hb-sdk remote withdraw`、`hb-sdk remote take-down`、`hb-sdk remote reopen` 和 `hb-sdk remote square hide` 会改变审核、发布或用户侧可见状态。交互式终端会展示小程序 id、名称、当前状态、目标版本和操作,再要求确认;非 TTY 环境必须传 `--yes`。
|
|
266
|
-
|
|
267
|
-
所有 `hb-sdk remote` 子命令都支持 `--json`。开启后 stdout 只输出一个 JSON 对象;进度、警告、版本提醒和 verbose 诊断不能污染 stdout。
|
|
268
194
|
|
|
269
195
|
Agent rules:
|
|
270
196
|
|
|
@@ -279,138 +205,32 @@ Agent rules:
|
|
|
279
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`.
|
|
280
206
|
- Use `--json` for script consumption and keep stdout as exactly one JSON object.
|
|
281
207
|
|
|
282
|
-
## CLI login
|
|
208
|
+
## CLI login
|
|
283
209
|
|
|
284
210
|
## CLI 登录态
|
|
285
211
|
|
|
212
|
+
CLI 登录态只用于开发工具和远端管理,不等同于小程序内的用户登录态,也不会改变 `auth.login()` 或 `user.getInfo()` 的结果。
|
|
213
|
+
|
|
286
214
|
```bash
|
|
287
|
-
hb-sdk login
|
|
288
|
-
hb-sdk login --login-base-url https://login.test.xiaoheihe.cn
|
|
289
215
|
hb-sdk login status
|
|
290
216
|
hb-sdk login clear
|
|
291
217
|
```
|
|
292
218
|
|
|
293
|
-
- `hb-sdk login` 会打开 `login.xiaoheihe.cn`,通过本地临时回调服务接收登录结果。
|
|
294
|
-
- `hb-sdk login --login-base-url <url>` 会打开指定登录 origin,并把该登录环境写入 CLI 登录态。
|
|
295
|
-
- `hb-sdk login status` 默认展示脱敏状态、`heyboxId`、`loginBaseUrl` 和登录时间;`--verbose` 额外展示 cache 路径。不输出 `pkey`、cookie 或完整请求头。
|
|
296
|
-
- `hb-sdk login clear` 只清理 `hb-sdk` 自己命名空间中的 Heybox 登录态。
|
|
297
|
-
|
|
298
|
-
这份 CLI 登录态不会注入 iframe SDK,也不会改变 `hb-sdk dev` 的 mock 用户、`auth.login()`、`user.getInfo()` 或 `network.request()` 行为。
|
|
299
|
-
|
|
300
219
|
Agent rules:
|
|
301
220
|
|
|
302
|
-
- Keep CLI
|
|
303
|
-
- 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.
|
|
304
222
|
- It is correct to say status output is redacted.
|
|
305
223
|
- Do not expose or template pkey, cookie, token, or private credential values.
|
|
306
224
|
- Use `hb-sdk login clear` only to clear the `hb-sdk` CLI namespace.
|
|
307
225
|
|
|
308
226
|
## Agent Skill doctor
|
|
309
227
|
|
|
310
|
-
## Agent Skill doctor
|
|
311
|
-
|
|
312
|
-
```bash
|
|
313
|
-
hb-sdk doctor
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
`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`。
|
|
317
|
-
|
|
318
|
-
`doctor` 只诊断,不修改本地文件。需要安装或刷新 skill 时,按输出提示手动执行 `npx skills add`。
|
|
319
|
-
|
|
320
|
-
| 状态 | 含义 |
|
|
321
|
-
| -------------------- | -------------------------------------------------------- |
|
|
322
|
-
| `OK` | SDK、远端 latest skill、本机 skill 全部匹配。 |
|
|
323
|
-
| `SKILL_MISSING` | 本机没有安装 `hb-sdk` skill。 |
|
|
324
|
-
| `SKILL_OUTDATED` | 本机 `skillVersion` 与远端 latest 不一致。 |
|
|
325
|
-
| `SDK_MISMATCH` | 当前 SDK 版本与远端 latest skill 声明的 SDK 版本不一致。 |
|
|
326
|
-
| `REMOTE_UNAVAILABLE` | 无法读取公开 manifest,诊断失败且不会修改本地文件。 |
|
|
327
228
|
|
|
328
|
-
手动安装或刷新 skill:
|
|
329
|
-
|
|
330
|
-
```bash
|
|
331
|
-
npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
如果状态是 `SDK_MISMATCH`,先升级 `@heybox/hb-sdk@latest`,再重新运行 `hb-sdk doctor` 并按提示安装 latest skill。当前只维护 latest skill,不维护历史 SDK 的 skill 快照。
|
|
335
229
|
|
|
336
230
|
Agent rules:
|
|
337
231
|
|
|
338
232
|
- Use `hb-sdk doctor` for read-only diagnosis of local SDK, remote latest skill metadata, and local skill metadata.
|
|
339
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`.
|
|
340
234
|
- If doctor reports `SDK_MISMATCH`, tell the user to upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
|
|
341
|
-
- The supported local skill path is `$CODEX_HOME/skills/hb-sdk/skill.json`, falling back to `~/.codex/skills/hb-sdk/skill.json`.
|
|
342
235
|
|
|
343
236
|
## Update reminders
|
|
344
|
-
|
|
345
|
-
## 版本提醒
|
|
346
|
-
|
|
347
|
-
`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` 禁用检查。
|
|
348
|
-
|
|
349
|
-
## Repository validation commands
|
|
350
|
-
|
|
351
|
-
## 本仓库开发
|
|
352
|
-
|
|
353
|
-
```bash
|
|
354
|
-
pnpm --filter @heybox/hb-sdk run test:unit
|
|
355
|
-
pnpm --filter @heybox/hb-sdk run build:package
|
|
356
|
-
pnpm --filter @heybox/hb-sdk run check:boundary
|
|
357
|
-
pnpm exec hbexec hb-sdk check
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
`check:boundary` 用于保护 SDK、CLI、mock host 与 runtime 之间的依赖边界。调整 CLI、mock 或协议导出时应一起运行。
|
|
361
|
-
|
|
362
|
-
`hbexec hb-sdk check` 只读校验 docs、skill references,并在临时目录生成与校验 `agent-skills` payload;不要求 canonical artifact 已存在,也不包含 changelog。维护清单见 `packages/hb-sdk/DOC_SYNC_CHECKLIST.md`。
|
|
363
|
-
|
|
364
|
-
## Generated template README
|
|
365
|
-
|
|
366
|
-
````md
|
|
367
|
-
# <%= projectName %>
|
|
368
|
-
|
|
369
|
-
这是通过 `hb-sdk create` 生成的黑盒外部小程序开发模板。项目使用 Vue 3、Vite、TypeScript 和 `@heybox/hb-sdk`。
|
|
370
|
-
|
|
371
|
-
## 使用命令
|
|
372
|
-
|
|
373
|
-
```bash
|
|
374
|
-
npm install
|
|
375
|
-
npm run dev
|
|
376
|
-
npm run typecheck
|
|
377
|
-
npm run test:unit
|
|
378
|
-
npm run build
|
|
379
|
-
npm run deploy
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
## 依赖说明
|
|
383
|
-
|
|
384
|
-
`@heybox/hb-sdk` 是小程序页面运行时会 import 的 SDK,因此模板把它放在 `dependencies`。Vite、TypeScript、Vitest 等只参与本地开发、测试或构建的工具放在 `devDependencies`。
|
|
385
|
-
|
|
386
|
-
## 开发模式
|
|
387
|
-
|
|
388
|
-
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面,也可以选择局域网网卡后用手机小黑盒 APP 扫码调试。手机需要与电脑处在同一局域网,并使用支持小程序调试壳的新版小黑盒 APP。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
|
|
389
|
-
- `npm run build`:先执行 TypeScript 检查,再构建生产产物。
|
|
390
|
-
- `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` 已删除,不再作为兼容别名保留。
|
|
391
|
-
|
|
392
|
-
## 更多能力
|
|
393
|
-
|
|
394
|
-
模板页面只保留最小接入示例。其他常用能力可以直接从 `@heybox/hb-sdk` 调用:
|
|
395
|
-
|
|
396
|
-
```ts
|
|
397
|
-
import hbSDK from '@heybox/hb-sdk';
|
|
398
|
-
|
|
399
|
-
await hbSDK.share.showShareMenu({
|
|
400
|
-
title: '<%= projectName %>',
|
|
401
|
-
desc: '分享描述',
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
await hbSDK.storage.setStorage({
|
|
405
|
-
key: 'settings',
|
|
406
|
-
data: { theme: 'dark' },
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const response = await hbSDK.network.request({
|
|
410
|
-
method: 'GET',
|
|
411
|
-
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
|
412
|
-
});
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
工坊小程序通常不要传 `url`;宿主 runtime 会自动生成当前小程序的通用分享页。只有确实要分享外部 HTTP(S) 页面时才显式传 `url`。
|
|
416
|
-
````
|