@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.
Files changed (30) hide show
  1. package/README.md +3 -3
  2. package/dist/cli-chunks/{context-BCwksd8H.cjs → context-DjepdCaa.cjs} +1 -1
  3. package/dist/cli-chunks/{create-BO8GHVi0.cjs → create-D3BBKay9.cjs} +1 -1
  4. package/dist/cli-chunks/{dev-DmgKnEC2.cjs → dev-C3u5FXIy.cjs} +9 -13
  5. package/dist/cli-chunks/{doctor-BlKB4f78.cjs → doctor-DEgZa2qC.cjs} +1 -1
  6. package/dist/cli-chunks/{index-PxkpQ5of.cjs → index-B5gEl9ow.cjs} +2 -2
  7. package/dist/cli-chunks/{index-Q0G1SsEs.cjs → index-CKat0ExC.cjs} +38 -13
  8. package/dist/cli-chunks/{login-Cxdo4B6Z.cjs → login-B6gERpSX.cjs} +2 -2
  9. package/dist/cli-chunks/{remote-C1Rsb1dx.cjs → remote-BfQiZzeJ.cjs} +4 -4
  10. package/dist/cli-chunks/{session-CC3Oz3Xc.cjs → session-DPEq__gB.cjs} +1 -1
  11. package/dist/cli.cjs +1 -1
  12. package/dist/devtools/mock-host/index.html +0 -19
  13. package/dist/devtools/mock-host/main.js +72 -91
  14. package/dist/index.cjs.js +1 -1
  15. package/dist/index.esm.js +1 -1
  16. package/dist/protocol.cjs.js +54 -0
  17. package/dist/protocol.esm.js +53 -1
  18. package/dist/templates/vue3-vite-ts/README.md.ejs +4 -8
  19. package/dist/vite.cjs.js +1 -1
  20. package/dist/vite.esm.js +1 -1
  21. package/package.json +1 -1
  22. package/skill/SKILL.md +33 -47
  23. package/skill/references/api-protocol.md +18 -17
  24. package/skill/references/api-root.md +3 -3
  25. package/skill/references/cli.md +65 -245
  26. package/skill/references/recipes.md +91 -50
  27. package/skill/scripts/sync-references.mjs +35 -53
  28. package/skill/skill.json +4 -4
  29. package/types/protocol/runtime-permissions.d.ts +41 -0
  30. package/types/protocol.d.ts +4 -2
@@ -24,7 +24,7 @@
24
24
 
25
25
  # 快速开始
26
26
 
27
- 如果页面不需要黑盒开放能力,可以不接入 SDK。这是一条需要用户能力时的最短接入路径:等待 SDK 完成握手,然后读取当前用户登录态。
27
+ 如果页面不需要小黑盒开放能力,可以不接入 SDK。这是最短接入路径:等待 SDK 就绪,然后读取当前用户登录态。
28
28
 
29
29
  ```ts
30
30
  import hbSDK from '@heybox/hb-sdk'
@@ -46,9 +46,10 @@ bootstrap()
46
46
 
47
47
  ## 推荐业务写法
48
48
 
49
- 业务页通常还需要监听登录态变化:
49
+ 业务页通常还需要监听登录态变化。下面以 Vue 3 为例:初始化只读取状态,登录必须由按钮等明确的用户操作触发,监听在组件卸载时清理。
50
50
 
51
51
  ```ts
52
+ import { onUnmounted } from 'vue'
52
53
  import hbSDK from '@heybox/hb-sdk'
53
54
 
54
55
  const stopAuthChange = hbSDK.on('authChange', result => {
@@ -59,24 +60,29 @@ const stopAuthChange = hbSDK.on('authChange', result => {
59
60
 
60
61
  await hbSDK.ready()
61
62
 
62
- const result = await hbSDK.user.getInfo()
63
- if (!result.isLogin) {
64
- await hbSDK.auth.login()
63
+ const initialUser = await hbSDK.user.getInfo()
64
+
65
+ async function loginFromUserAction() {
66
+ const result = await hbSDK.auth.login()
67
+ if (!result.isLogin || !result.userInfo) {
68
+ return
69
+ }
70
+
71
+ console.log('用户已登录', result.userInfo.heybox_id)
65
72
  }
66
73
 
67
- // 页面卸载时清理监听
68
- stopAuthChange()
74
+ onUnmounted(stopAuthChange)
69
75
  ```
70
76
 
77
+ 把 `loginFromUserAction` 绑定到登录按钮;不要在页面 bootstrap 阶段自动调用 `auth.login()`。
78
+
71
79
  ## ready 的含义
72
80
 
73
- `ready()` 表示 SDK 已完成与父容器的握手,可以安全调用开放能力。SDK 在收到 `ready` 前会自动重试握手;如果超过总超时时间仍未成功,会抛出 `READY_TIMEOUT`。它不等价于“用户已登录”,用户状态需要通过 `user.getInfo()` 或 `authChange` 判断。
81
+ `ready()` 表示 SDK 已就绪,可以安全调用开放能力。如果当前不在可用的小程序运行环境中,它会抛出公开错误。`ready()` 不等价于“用户已登录”,用户状态需要通过 `user.getInfo()` 或 `authChange` 判断。
74
82
 
75
83
  ## 默认单例适合什么场景
76
84
 
77
- 默认单例适合一个页面只有一个 SDK 上下文的情况。大多数小程序页面都应该使用默认单例,因为它可以避免重复握手和重复维护事件监听。
78
-
79
- 0.6 起根入口只提供唯一默认实例并在导入时立即握手,不再允许业务创建独立实例。测试需要隔离 bridge 时应在应用边界替换公开模块。
85
+ 大多数小程序页面都应该使用默认实例。0.6 起不再对业务代码提供独立实例工厂。
80
86
 
81
87
  ## User and login
82
88
 
@@ -87,6 +93,10 @@ stopAuthChange()
87
93
 
88
94
  - `user.getInfo()`:静默读取当前登录态与公开基础资料。
89
95
  - `auth.login()`:唤起黑盒登录流程,并返回登录后的最新公开用户资料。
96
+ - `user.getCurrentUserDetail()`:读取当前用户展示详情。
97
+ - `user.getCurrentUserProfile()`:读取当前用户敏感资料,需要对应平台权限。
98
+ - `user.getPlatformAccountOverview()` / `getPlatformAccountInfo()`:读取平台账号概览或指定平台详情。
99
+ - `user.getSteamGameList()`:读取当前用户 Steam 游戏库。
90
100
 
91
101
  ## 静默读取用户信息
92
102
 
@@ -123,9 +133,9 @@ async function ensureLogin() {
123
133
  }
124
134
  ```
125
135
 
126
- ## 暴露字段
136
+ ## 基础资料与扩展资料
127
137
 
128
- SDK 只暴露允许给外部小程序读取的公开字段:
138
+ `user.getInfo()` 和 `auth.login()` 的 `userInfo` 只包含三项公开基础字段:
129
139
 
130
140
  | 字段 | 类型 | 说明 |
131
141
  | ----------- | -------- | ------------ |
@@ -135,18 +145,35 @@ SDK 只暴露允许给外部小程序读取的公开字段:
135
145
 
136
146
  不会暴露 token、cookie、手机号或任何可用于调用主站私有接口的凭据。
137
147
 
148
+ current-user scoped API 返回独立的 `UserScopedResult<T>`。未登录时是 `{ isLogin: false, data: null }`;已登录时才有 `data`。其中 `getCurrentUserProfile()` 可能返回生日、邮箱、教育和职业等敏感资料,必须按最小必要原则使用,并以平台权限结果为准;不要把这些字段理解为 `getInfo()` 的默认返回值。
149
+
150
+ ```ts
151
+ const profile = await user.getCurrentUserProfile()
152
+ if (profile.isLogin) {
153
+ console.log(profile.data.email)
154
+ }
155
+
156
+ const platforms = await user.getPlatformAccountOverview()
157
+ if (platforms.isLogin) {
158
+ console.log(platforms.data)
159
+ }
160
+ ```
161
+
138
162
  ## 监听登录态变化
139
163
 
140
164
  如果页面上同时存在登录按钮、权限态 UI 和业务数据,建议监听 `authChange`。
141
165
 
142
166
  ```ts
167
+ import { onUnmounted } from 'vue'
143
168
  import { on } from '@heybox/hb-sdk'
144
169
 
145
- const stop = on('authChange', result => {
170
+ const stopAuthChange = on('authChange', result => {
146
171
  if (result.isLogin) {
147
172
  console.log('登录态更新', result.userInfo?.heybox_id)
148
173
  }
149
174
  })
175
+
176
+ onUnmounted(stopAuthChange)
150
177
  ```
151
178
 
152
179
  ## Lifecycle events
@@ -154,41 +181,41 @@ const stop = on('authChange', result => {
154
181
 
155
182
  # 事件与生命周期
156
183
 
157
- SDK 通过 `on` 监听父容器派发的小程序生命周期和业务事件。
184
+ SDK 通过 `on` 监听小程序生命周期和业务事件。
158
185
 
159
186
  ```ts
160
- import { on, off } from '@heybox/hb-sdk'
187
+ import { onUnmounted } from 'vue'
188
+ import { on } from '@heybox/hb-sdk'
161
189
 
162
190
  function handleShow(payload: { timestamp: number; source?: string }) {
163
191
  console.log('show from', payload.source)
164
192
  }
165
193
 
166
- on('show', handleShow)
167
- off('show', handleShow)
168
- ```
169
-
170
- `on` 也会返回取消监听函数,推荐在组件卸载时调用:
171
-
172
- ```ts
173
- import { on } from '@heybox/hb-sdk'
174
-
175
- const stop = on('hide', () => {
194
+ const stopShow = on('show', handleShow)
195
+ const stopHide = on('hide', () => {
176
196
  console.log('小程序页面隐藏')
177
197
  })
178
198
 
179
- stop()
199
+ function stopLifecycleEvents() {
200
+ stopShow()
201
+ stopHide()
202
+ }
203
+
204
+ onUnmounted(stopLifecycleEvents)
180
205
  ```
181
206
 
207
+ 框架外也可以保存 `on()` 返回的取消函数,在页面或业务模块真正销毁时调用。需要按 handler 精确移除时再使用 `off(event, handler)`;不要在注册后的同一执行流里立即取消。
208
+
182
209
  ## 事件列表
183
210
 
184
211
  | 事件 | 触发时机 | 典型用途 |
185
212
  | ------------ | ------------------------ | ------------------ |
186
- | `launch` | 小程序首次完成握手并启动 | 初始化一次性数据 |
187
- | `ready` | SDK 可安全调用开放能力 | 标记 bridge 可用 |
213
+ | `launch` | 小程序首次启动 | 初始化一次性数据 |
214
+ | `ready` | SDK 可安全调用开放能力 | 标记 SDK 可用 |
188
215
  | `show` | 小程序页面展示 | 刷新可见态数据 |
189
216
  | `hide` | 小程序页面隐藏 | 暂停轮询、暂停播放 |
190
- | `unload` | 小程序页面即将卸载 | 清理资源 |
191
- | `error` | 父容器或开放能力运行异常 | 统一错误上报 |
217
+ | `unload` | 当前小程序运行环境终止 | 清理资源并停止请求 |
218
+ | `error` | 小程序或开放能力运行异常 | 统一错误上报 |
192
219
  | `authChange` | 登录状态变化 | 刷新用户信息和权限 |
193
220
 
194
221
  完整载荷与事件名见:
@@ -202,51 +229,69 @@ stop()
202
229
  - UI 可见性相关逻辑放在 `show`、`hide`。
203
230
  - 用户状态不要只在页面加载时读一次,登录入口附近要监听 `authChange`。
204
231
  - 组件或页面销毁时清理 `on` 注册的监听,避免重复响应。
232
+ - 事件只派发给注册当时存在的监听器,不会重放;一次性 `launch`/`ready` 状态应以 `ready()` Promise 为准。
233
+ - 收到 `unload` 后,当前 SDK 上下文不可恢复,未完成请求会失败;不要在同一页面上下文继续重试能力调用。
205
234
 
206
235
  ## Error handling
207
236
 
208
237
 
209
238
  # 错误处理
210
239
 
211
- SDK 对外抛出的标准错误类型是 `HbMiniProgramSDKError`。
240
+ SDK 公开两类标准错误:
241
+
242
+ - `HbMiniProgramSDKError`:SDK 初始化或开放能力调用失败。
243
+ - `HbMiniProgramNetworkError`:网络请求已返回,但 HTTP 状态未通过 `validateStatus`。
212
244
 
213
245
  ```ts
214
- import { HbMiniProgramSDKError, ready } from '@heybox/hb-sdk'
246
+ import {
247
+ HbMiniProgramNetworkError,
248
+ HbMiniProgramSDKError,
249
+ network,
250
+ } from '@heybox/hb-sdk'
215
251
 
216
252
  try {
217
- await ready()
253
+ await network.request({ url: 'https://api.example.com/data' })
218
254
  } catch (error) {
255
+ if (error instanceof HbMiniProgramNetworkError) {
256
+ console.log(error.status, error.data, error.headers)
257
+ return
258
+ }
259
+
219
260
  if (error instanceof HbMiniProgramSDKError) {
220
261
  console.log(error.code, error.message, error.data)
262
+ return
221
263
  }
264
+
265
+ throw error
222
266
  }
223
267
  ```
224
268
 
225
- ## SDK 内置错误
269
+ ## 处理原则
226
270
 
227
- | code | 场景 | 建议处理 |
228
- | ----------------- | --------------------------------- | ---------------------------------- |
229
- | `NOT_IN_IFRAME` | 当前页面不在小程序沙盒 iframe 中 | 提示运行环境错误,检查父容器接入 |
230
- | `MISSING_NONCE` | URL 中缺少 `hb_mini_bridge_nonce` | 检查父容器 URL 注入逻辑 |
231
- | `READY_TIMEOUT` | SDK 握手超时 | 检查父容器是否幂等响应重试的 `sdk.handshake` |
232
- | `REQUEST_TIMEOUT` | 开放能力调用超时 | 提示重试,并上报 method |
233
- | `SDK_DESTROYED` | SDK 已销毁但仍有请求未完成 | 检查销毁时机和并发请求 |
271
+ - 根据 `error.code` 区分运行环境、权限、超时和业务失败,不要只比对错误文案。
272
+ - 权限失败时给出可理解的提示,不要将它当成未登录。
273
+ - 超时或运行环境不可用时,允许用户重试或退出当前流程。
274
+ - 上报 `code`、`message` 和必要的业务上下文,不要上报用户凭据或敏感数据。
234
275
 
235
- 父容器返回失败响应时,SDK 也会包装成 `HbMiniProgramSDKError`,此时 `code` 由父容器开放能力定义。
276
+ 完整错误码和字段见 [HbMiniProgramSDKError](api-root.md) [HbMiniProgramNetworkError](api-root.md)。
236
277
 
237
278
  ## 业务层建议
238
279
 
239
280
  ```ts
240
281
  import hbSDK, { HbMiniProgramSDKError } from '@heybox/hb-sdk'
241
282
 
242
- async function loadUser() {
283
+ type UserViewState =
284
+ | { status: 'ready'; user: Awaited<ReturnType<typeof hbSDK.user.getInfo>> }
285
+ | { status: 'failed'; error: HbMiniProgramSDKError }
286
+
287
+ async function loadUser(): Promise<UserViewState> {
243
288
  try {
244
289
  await hbSDK.ready()
245
- return await hbSDK.user.getInfo()
290
+ return { status: 'ready', user: await hbSDK.user.getInfo() }
246
291
  } catch (error) {
247
292
  if (error instanceof HbMiniProgramSDKError) {
248
293
  reportSDKError(error.code, error.message, error.data)
249
- return { isLogin: false, userInfo: null }
294
+ return { status: 'failed', error }
250
295
  }
251
296
 
252
297
  throw error
@@ -258,10 +303,6 @@ function reportSDKError(code: string, message: string, data?: unknown) {
258
303
  }
259
304
  ```
260
305
 
261
- ## 超时时间
262
-
263
- 默认握手超时时间是 10000ms。0.6 起业务不能通过独立实例修改该值;超时应作为 Host/Runtime 启动异常处理。
264
-
265
306
  ## Login gate recipe
266
307
 
267
308
 
@@ -93,13 +93,24 @@ function rewriteBundledRecipeLinks(markdown) {
93
93
  return markdown
94
94
  .replaceAll('(../recipes/custom-instance)', '(#custom-instance-recipe)')
95
95
  .replaceAll('(../reference/protocol/interfaces/MiniProgramEventPayloadMap)', '(api-root.md)')
96
- .replaceAll('(../reference/protocol/types/#miniprogrameventname)', '(api-root.md)');
96
+ .replaceAll('(../reference/protocol/types/#miniprogrameventname)', '(api-root.md)')
97
+ .replaceAll('(../reference/root/classes/HbMiniProgramSDKError)', '(api-root.md)')
98
+ .replaceAll('(../reference/root/classes/HbMiniProgramNetworkError)', '(api-root.md)');
99
+ }
100
+
101
+ function rewriteBundledCliLinks(markdown) {
102
+ return markdown.replaceAll(
103
+ '(./mini-program-publishing-rules)',
104
+ '(https://docs.xiaoheihe.cn/hb_sdk/guide/mini-program-publishing-rules)',
105
+ );
97
106
  }
98
107
 
99
108
  function rewriteBundledProtocolIndexLinks(markdown) {
100
109
  return markdown
101
110
  .replaceAll('(./root/)', '(api-root.md)')
102
111
  .replaceAll('(./protocol/)', '(#public-protocol-entrypoint)')
112
+ .replaceAll('(./miniapp-publish/)', '(https://open.xiaoheihe.cn/docs/hb_sdk/reference/miniapp-publish/)')
113
+ .replaceAll('(./vite/)', '(https://open.xiaoheihe.cn/docs/hb_sdk/reference/vite/)')
103
114
  .replaceAll('(../guide/)', '(recipes.md)');
104
115
  }
105
116
 
@@ -189,7 +200,6 @@ const rootEntry = read('packages/hb-sdk/src/index.ts');
189
200
  const protocolEntry = read('packages/hb-sdk/src/protocol.ts');
190
201
  const viteEntry = read('packages/hb-sdk/src/vite/index.ts');
191
202
  const cliEntry = read('packages/hb-sdk/src/cli/index.ts');
192
- const cliTemplateReadme = read('packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs');
193
203
  const readme = read('packages/hb-sdk/README.md');
194
204
  const cliGuide = frontmatterless(read('apps/docs/hb-sdk/guide/cli.md'));
195
205
  const quickStart = frontmatterless(read('apps/docs/hb-sdk/guide/quick-start.md'));
@@ -208,20 +218,16 @@ const sdkRuntimeRelation = extractSection(readme, '## SDK 与 Runtime');
208
218
  const capabilityBoundaries = extractSection(readme, '## 能力边界');
209
219
  const manifestSection = extractSection(readme, '## Manifest');
210
220
  const cliSummarySection = extractSection(readme, '## CLI');
211
- const repositoryDevelopment = extractSection(readme, '## 本仓库开发');
212
- const cliCreateSection = extractSection(cliGuide, '## 创建外部小程序模板');
213
- const cliDevSection = [
214
- extractSection(cliGuide, '## 本地开发模式'),
215
- extractSection(cliGuide, '## Mock runtime 边界'),
216
- ].filter(Boolean).join('\n\n');
221
+ const cliCreateSection = extractSection(cliGuide, '## 创建工坊小程序');
222
+ const cliDevSection = extractSection(cliGuide, '## 推荐调试流程');
217
223
  const cliDeploySection = extractSection(cliGuide, '## 部署发布');
218
224
  const cliRemoteSection = extractSection(cliGuide, '## 远端管理命令');
219
225
  const cliLoginSection = extractSection(cliGuide, '## CLI 登录态');
220
226
  const cliDoctorSection = extractSection(cliGuide, '## Agent Skill doctor');
221
227
  const cliUpdateSection = extractSection(cliGuide, '## 版本提醒');
222
228
  const cliCommandSurface = `hb-sdk create <project-name>
223
- hb-sdk dev [--port <port>] [--mock-port <port>] [--runtime-url <url>] [--no-open]
224
- hb-sdk login [--login-base-url <url>] [--no-select-entity]
229
+ hb-sdk dev [--port <port>] [--mock-port <port>] [--no-open]
230
+ hb-sdk login
225
231
  hb-sdk login status
226
232
  hb-sdk login clear
227
233
  hb-sdk doctor
@@ -249,17 +255,15 @@ hb-sdk remote square show
249
255
 
250
256
  Removed: hb-sdk deploy`;
251
257
 
252
- const cliRemoteEntitySection = `Developer entity selection lives under \`hb-sdk remote entity\`:
258
+ const cliRemoteEntitySection = `Developer account selection lives under \`hb-sdk remote entity\`:
253
259
 
254
260
  ${fenced('bash', `hb-sdk remote entity list
255
261
  hb-sdk remote entity current
256
262
  hb-sdk remote entity switch <entity-id>`)}
257
263
 
258
- The authoritative current entity is the developer platform server-side current entity. The CLI auth cache may contain a \`selectedEntity\` value, but that value is only a hint snapshot for \`hb-sdk login status\` display and drift troubleshooting. Do not use \`selectedEntity\` as the source of truth for permissions, ownership, create, bind, deploy, or release decisions.
264
+ 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.`;
259
265
 
260
- \`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.`;
261
-
262
- const cliRemoteEntityDeploySection = `Before precheck, build, upload, or submit audit, \`hb-sdk remote deploy\` must verify that the current project's bound mini-program belongs to the server-side current entity. If \`detail.entity_id\` differs from the current entity, the command fails with both entity ids/names and suggests \`hb-sdk remote entity switch <entity-id>\`. It must not auto-switch entities and must not continue into precheck/build/upload/submit on mismatch.`;
266
+ const cliRemoteEntityDeploySection = `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.`;
263
267
 
264
268
  const files = new Map();
265
269
 
@@ -341,29 +345,23 @@ files.set('cli.md', `${header('CLI reference', [
341
345
  'packages/hb-sdk/src/cli/commands/create.ts',
342
346
  'packages/hb-sdk/src/cli/commands/dev.ts',
343
347
  'packages/hb-sdk/src/cli/commands/login.ts',
344
- 'packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs',
345
348
  'apps/docs/hb-sdk/guide/cli.md',
346
- 'packages/hb-sdk/README.md',
347
349
  ])}${contents([
348
350
  ['When to use the CLI', 'when-to-use-the-cli'],
349
351
  ['Command surface', 'command-surface'],
350
352
  ['Create a mini-program template', 'create-a-mini-program-template'],
351
- ['Local dev and mock runtime', 'local-dev-and-mock-runtime'],
352
- ['Deploy and backend operations', 'deploy-and-backend-operations'],
353
- ['Remote entity scope', 'remote-entity-scope'],
353
+ ['Local debugging', 'local-debugging'],
354
+ ['Deploy and publish', 'deploy-and-publish'],
355
+ ['Developer account scope', 'developer-account-scope'],
354
356
  ['Remote management commands', 'remote-management-commands'],
355
- ['CLI login cache', 'cli-login-cache'],
357
+ ['CLI login', 'cli-login'],
356
358
  ['Agent Skill doctor', 'agent-skill-doctor'],
357
359
  ['Update reminders', 'update-reminders'],
358
- ['Repository validation commands', 'repository-validation-commands'],
359
- ['Generated template README', 'generated-template-readme'],
360
360
  ])}## When to use the CLI
361
361
 
362
- Use the bundled \`hb-sdk\` CLI when the task is about creating an external mini-program project, starting local Vite development, debugging SDK calls in a browser mock runtime host, managing the CLI's own Heybox auth cache, or inspecting/switching the developer platform current entity for remote mini-program management.
362
+ 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.
363
363
 
364
- Do not use the CLI to replace iframe SDK calls. \`hb-sdk login\` is for CLI commands only and does not change \`auth.login()\`, \`user.getInfo()\`, \`network.request()\`, or mock-host user state.
365
-
366
- The CLI, templates, and mock host are owned by \`${packageJson.name}\`. Do not create a second mock runtime package or move CLI guidance outside this package unless the package boundary changes.
364
+ \`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.
367
365
 
368
366
  ## Command surface
369
367
 
@@ -377,20 +375,20 @@ ${cliCreateSection}
377
375
 
378
376
  Agent rules:
379
377
 
380
- - Prefer \`hb-sdk create <project-name>\` for a new standalone external mini-program template.
378
+ - Prefer \`hb-sdk create <project-name>\` for a new workshop mini-program.
381
379
  - After creation, the expected next steps are \`npm install\` and \`npm run dev\`.
382
380
  - Do not claim the CLI installs dependencies, initializes git, opens an editor, or overwrites non-empty directories.
383
381
  - Treat \`project-name\` as an unscoped npm package name and project directory.
384
382
 
385
- ## Local dev and mock runtime
383
+ ## Local debugging
386
384
 
387
385
  ${cliDevSection}
388
386
 
389
- Use \`hb-sdk dev\` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button for Mac App debugging, or the "Mobile App" QR code after selecting a LAN interface for phone App debugging. The phone must be on the same LAN and use a Heybox App version that supports the mini-program dev shell. If the mock host is open inside Codex, VSCode, or another embedded browser, ask the user to open the same debug page in the system browser before retrying because embedded browsers may block the \`heybox://\` protocol handoff.
387
+ 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.
390
388
 
391
- ## Deploy and backend operations
389
+ ## Deploy and publish
392
390
 
393
- ${cliDeploySection}
391
+ ${rewriteBundledCliLinks(cliDeploySection)}
394
392
 
395
393
  ${cliRemoteEntityDeploySection}
396
394
 
@@ -398,25 +396,18 @@ Agent rules:
398
396
 
399
397
  - Use \`hb-sdk remote deploy --release-note <text>\` for normal build, upload, and submit-audit flows.
400
398
  - Use \`hb-sdk remote deploy --from-version <version> --release-note <text>\` to reuse a remote history artifact.
401
- - Verify remote deploy guidance says current-entity mismatch fails before precheck/build/upload/submit and never auto-switches the developer entity.
399
+ - If the bound mini-program does not belong to the current developer account, stop and ask the user to switch accounts.
402
400
  - Never recommend top-level \`hb-sdk deploy\`; it has been removed rather than retained as a compatibility alias.
403
401
  - 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.
404
402
  - Use \`hb-sdk remote allowlist add <heybox_id>\` when preview access needs to be granted.
405
- - Use \`--api-base-url <url>\` or \`HB_SDK_API_BASE_URL\` for remote platform backend APIs.
406
- - 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.
407
- - Use \`--login-base-url <url>\` or \`HB_SDK_LOGIN_BASE_URL\` for CLI browser login and remote command login-environment validation.
408
- - 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.
409
- - 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.
410
- - Do not expect custom base URLs to affect \`hb-sdk doctor\`, npm latest checks, or mock-host \`network.request()\`.
411
403
 
412
- ## Remote entity scope
404
+ ## Developer account scope
413
405
 
414
406
  ${cliRemoteEntitySection}
415
407
 
416
408
  Agent rules:
417
409
 
418
- - Treat the server-side current entity as the authority for remote create, bind, deploy, list, access, versions, preview, release, withdraw, take-down, reopen, and square-display workflows.
419
- - 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.
410
+ - 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.
420
411
  - Use \`hb-sdk remote entity current\` when a user needs to confirm which entity create/deploy will use.
421
412
  - 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.
422
413
  - \`hb-sdk remote list\` lists mini-programs in the current entity scope only; do not promise cross-entity aggregation.
@@ -438,14 +429,13 @@ Agent rules:
438
429
  - 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\`.
439
430
  - Use \`--json\` for script consumption and keep stdout as exactly one JSON object.
440
431
 
441
- ## CLI login cache
432
+ ## CLI login
442
433
 
443
434
  ${cliLoginSection}
444
435
 
445
436
  Agent rules:
446
437
 
447
- - Keep CLI auth cache separate from iframe SDK login state.
448
- - Keep \`selectedEntity\` guidance explicit: it is only a hint snapshot, while every remote command uses the server-side current entity.
438
+ - Keep CLI login separate from the mini-program user login state.
449
439
  - It is correct to say status output is redacted.
450
440
  - Do not expose or template pkey, cookie, token, or private credential values.
451
441
  - Use \`hb-sdk login clear\` only to clear the \`hb-sdk\` CLI namespace.
@@ -459,19 +449,11 @@ Agent rules:
459
449
  - Use \`hb-sdk doctor\` for read-only diagnosis of local SDK, remote latest skill metadata, and local skill metadata.
460
450
  - 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\`.
461
451
  - If doctor reports \`SDK_MISMATCH\`, tell the user to upgrade \`${packageJson.name}@latest\` before reinstalling the skill.
462
- - The supported local skill path is \`$CODEX_HOME/skills/hb-sdk/skill.json\`, falling back to \`~/.codex/skills/hb-sdk/skill.json\`.
463
452
 
464
453
  ## Update reminders
465
454
 
466
455
  ${cliUpdateSection}
467
456
 
468
- ## Repository validation commands
469
-
470
- ${repositoryDevelopment}
471
-
472
- ## Generated template README
473
-
474
- ${fenced('md', cliTemplateReadme)}
475
457
  `);
476
458
 
477
459
  files.set('recipes.md', `${header('Recipes', [
package/skill/skill.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hb-sdk",
3
- "skillVersion": "0.6.4-alpha.0+skill.20921fb44039",
3
+ "skillVersion": "0.6.5+skill.648cee8ae511",
4
4
  "sdk": {
5
5
  "package": "@heybox/hb-sdk",
6
- "version": "0.6.4-alpha.0",
7
- "compatibility": "0.6.4-alpha.0"
6
+ "version": "0.6.5",
7
+ "compatibility": "0.6.5"
8
8
  },
9
9
  "source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
10
- "integrity": "sha256-20921fb44039d21908fb692fc7d593c1dbc3b4f5dfa8f36f24aa0258ce150d13"
10
+ "integrity": "sha256-648cee8ae5111e01f8e69264187b9501c9167eca7c53693079e2a487ef230106"
11
11
  }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 判断 permission key 是否由 Runtime 权限快照管理。
3
+ *
4
+ * @param key 待判断的 permission key。
5
+ * @returns 该 key 需要读取 Runtime 权限快照时返回 `true`。
6
+ */
7
+ export declare function isManagedMiniProgramRuntimePermissionKey(key: string): boolean;
8
+ /** Runtime 权限项的启用状态。 */
9
+ export type MiniProgramRuntimePermissionStatus = 'enabled' | 'disabled';
10
+ /** Runtime 权限快照中的单项权限配置。 */
11
+ export interface MiniProgramRuntimePermissionEntry {
12
+ /** permission key。 */
13
+ key: string;
14
+ /** 当前权限状态。 */
15
+ status: MiniProgramRuntimePermissionStatus;
16
+ /** 由具体 permission key 定义的配置。 */
17
+ config: Record<string, unknown>;
18
+ }
19
+ /** 服务端下发的 Runtime schema v1 权限快照。 */
20
+ export interface MiniProgramRuntimePermissionsSnapshot {
21
+ /** 权限快照 schema 版本,当前固定为 `1`。 */
22
+ schema_version: 1;
23
+ /** 可选的非负整数修订号。 */
24
+ revision?: number;
25
+ /** 权限配置列表。 */
26
+ entries: MiniProgramRuntimePermissionEntry[];
27
+ }
28
+ /** Runtime 权限快照的 fail-closed 解析结果。 */
29
+ export interface ParsedMiniProgramRuntimePermissions {
30
+ /** 整份快照是否通过格式校验。 */
31
+ valid: boolean;
32
+ /** 通过校验的受管权限,以 permission key 索引。 */
33
+ permissions: Record<string, MiniProgramRuntimePermissionEntry>;
34
+ }
35
+ /**
36
+ * 解析服务端权限快照;格式不完整时整份快照失效并 fail closed。
37
+ *
38
+ * @param snapshot 待校验的服务端权限快照。
39
+ * @returns 解析状态和通过校验的受管权限。
40
+ */
41
+ export declare function parseMiniProgramRuntimePermissions(snapshot: unknown): ParsedMiniProgramRuntimePermissions;
@@ -1,5 +1,7 @@
1
1
  export { MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, } from './protocol/constants';
2
2
  export { isMiniProgramBridgeMessage } from './protocol/guards';
3
+ export { isManagedMiniProgramRuntimePermissionKey, parseMiniProgramRuntimePermissions } from './protocol/runtime-permissions';
4
+ export type { MiniProgramRuntimePermissionEntry, MiniProgramRuntimePermissionStatus, MiniProgramRuntimePermissionsSnapshot, ParsedMiniProgramRuntimePermissions, } from './protocol/runtime-permissions';
3
5
  export type { MiniProgramBridgeError, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramEventHandler, MiniProgramEventName, MiniProgramEventPayloadMap, RuntimeLocationProbePayload, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKLocationReportPayload, SDKLocationReportTrigger, } from './protocol/types';
4
6
  export { AUTH_LOGIN_METHOD, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_GET_CURRENT_USER_DETAIL_METHOD, USER_GET_CURRENT_USER_PROFILE_METHOD, USER_GET_INFO_METHOD, USER_GET_PLATFORM_ACCOUNT_INFO_METHOD, USER_GET_PLATFORM_ACCOUNT_OVERVIEW_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, } from './protocol/capabilities';
5
7
  export type { MiniProgramDeviceMethod, MiniProgramAuthMethod, MiniProgramBridgeMethod, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramNavigationMethod, MiniProgramNetworkMethod, MiniProgramShareMethod, MiniProgramStorageMethod, MiniProgramUiMethod, MiniProgramUserMethod, MiniProgramViewportMethod, } from './protocol/capabilities';
@@ -9,9 +11,9 @@ export type { GetCurrentUserDetailPayload, GetCurrentUserDetailResult, GetCurren
9
11
  export type { ScreenshotPayload, ScreenshotResult } from './modules/share/screenshot';
10
12
  export type { ShowShareMenuPayload, ShowShareMenuResult } from './modules/share/show-share-menu';
11
13
  export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShowShareMenuOptions, } from './modules/share';
12
- export type { GetStoragePayload, GetStorageResult, SetStoragePayload, } from './modules/storage';
14
+ export type { GetStoragePayload, GetStorageResult, SetStoragePayload } from './modules/storage';
13
15
  export type { GetWindowInfoPayload, GetWindowInfoResult, MiniProgramNavigationBarForegroundStyle, MiniProgramSafeArea, MiniProgramSetNavigationBarStyleOptions, MiniProgramWindowInfoResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, } from './modules/viewport';
14
16
  export type { MiniProgramNetworkHeaders, MiniProgramNetworkParams, MiniProgramNetworkRequestConfig, MiniProgramNetworkRequestMethod, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, NetworkRequestPayload, NetworkResponsePayload, } from './modules/network';
15
17
  export type { HideLoadingPayload, HideLoadingResult, MiniProgramToastStatus, ShowLoadingPayload, ShowLoadingResult, ShowToastPayload, ShowToastResult, } from './modules/ui';
16
- export type { MiniProgramVibrateIntensity, SetClipboardPayload, SetClipboardResult, VibratePayload, VibrateResult, } from './modules/device';
18
+ export type { MiniProgramVibrateIntensity, SetClipboardPayload, SetClipboardResult, VibratePayload, VibrateResult } from './modules/device';
17
19
  export type { ClosePayload, CloseResult, OpenAppPagePayload, OpenAppPageResult, OpenGameDetailAppPagePayload, OpenPostDetailAppPagePayload, OpenUserDetailAppPagePayload, ReloadPayload, ReloadResult, } from './modules/navigation';