@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
@@ -32,6 +32,58 @@ function isMiniProgramBridgeMessage(value) {
32
32
  typeof message.type === 'string');
33
33
  }
34
34
 
35
+ const MANAGED_RUNTIME_PERMISSION_KEYS = new Set(['network.request']);
36
+ /**
37
+ * 判断 permission key 是否由 Runtime 权限快照管理。
38
+ *
39
+ * @param key 待判断的 permission key。
40
+ * @returns 该 key 需要读取 Runtime 权限快照时返回 `true`。
41
+ */
42
+ function isManagedMiniProgramRuntimePermissionKey(key) {
43
+ return MANAGED_RUNTIME_PERMISSION_KEYS.has(key);
44
+ }
45
+ /**
46
+ * 解析服务端权限快照;格式不完整时整份快照失效并 fail closed。
47
+ *
48
+ * @param snapshot 待校验的服务端权限快照。
49
+ * @returns 解析状态和通过校验的受管权限。
50
+ */
51
+ function parseMiniProgramRuntimePermissions(snapshot) {
52
+ if (!isRecord(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
53
+ return { valid: false, permissions: {} };
54
+ }
55
+ if (snapshot.revision !== undefined && (typeof snapshot.revision !== 'number' || !Number.isInteger(snapshot.revision) || snapshot.revision < 0)) {
56
+ return { valid: false, permissions: {} };
57
+ }
58
+ const seenKeys = new Set();
59
+ const permissions = {};
60
+ for (const rawEntry of snapshot.entries) {
61
+ if (!isRecord(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
62
+ return { valid: false, permissions: {} };
63
+ }
64
+ const key = rawEntry.key.trim();
65
+ if (seenKeys.has(key) || (rawEntry.status !== 'enabled' && rawEntry.status !== 'disabled') || !isRecord(rawEntry.config)) {
66
+ return { valid: false, permissions: {} };
67
+ }
68
+ seenKeys.add(key);
69
+ if (!isManagedMiniProgramRuntimePermissionKey(key)) {
70
+ continue;
71
+ }
72
+ if (key === 'network.request' && typeof rawEntry.config.useOfficialDomain !== 'boolean') {
73
+ return { valid: false, permissions: {} };
74
+ }
75
+ permissions[key] = {
76
+ key,
77
+ status: rawEntry.status,
78
+ config: { useOfficialDomain: rawEntry.config.useOfficialDomain },
79
+ };
80
+ }
81
+ return { valid: true, permissions };
82
+ }
83
+ function isRecord(value) {
84
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
85
+ }
86
+
35
87
  /**
36
88
  * 登录授权能力方法名。
37
89
  *
@@ -364,4 +416,6 @@ exports.USER_GET_PLATFORM_ACCOUNT_OVERVIEW_METHOD = USER_GET_PLATFORM_ACCOUNT_OV
364
416
  exports.USER_GET_STEAM_GAME_LIST_METHOD = USER_GET_STEAM_GAME_LIST_METHOD;
365
417
  exports.VIEWPORT_GET_WINDOW_INFO_METHOD = VIEWPORT_GET_WINDOW_INFO_METHOD;
366
418
  exports.VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD = VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD;
419
+ exports.isManagedMiniProgramRuntimePermissionKey = isManagedMiniProgramRuntimePermissionKey;
367
420
  exports.isMiniProgramBridgeMessage = isMiniProgramBridgeMessage;
421
+ exports.parseMiniProgramRuntimePermissions = parseMiniProgramRuntimePermissions;
@@ -30,6 +30,58 @@ function isMiniProgramBridgeMessage(value) {
30
30
  typeof message.type === 'string');
31
31
  }
32
32
 
33
+ const MANAGED_RUNTIME_PERMISSION_KEYS = new Set(['network.request']);
34
+ /**
35
+ * 判断 permission key 是否由 Runtime 权限快照管理。
36
+ *
37
+ * @param key 待判断的 permission key。
38
+ * @returns 该 key 需要读取 Runtime 权限快照时返回 `true`。
39
+ */
40
+ function isManagedMiniProgramRuntimePermissionKey(key) {
41
+ return MANAGED_RUNTIME_PERMISSION_KEYS.has(key);
42
+ }
43
+ /**
44
+ * 解析服务端权限快照;格式不完整时整份快照失效并 fail closed。
45
+ *
46
+ * @param snapshot 待校验的服务端权限快照。
47
+ * @returns 解析状态和通过校验的受管权限。
48
+ */
49
+ function parseMiniProgramRuntimePermissions(snapshot) {
50
+ if (!isRecord(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
51
+ return { valid: false, permissions: {} };
52
+ }
53
+ if (snapshot.revision !== undefined && (typeof snapshot.revision !== 'number' || !Number.isInteger(snapshot.revision) || snapshot.revision < 0)) {
54
+ return { valid: false, permissions: {} };
55
+ }
56
+ const seenKeys = new Set();
57
+ const permissions = {};
58
+ for (const rawEntry of snapshot.entries) {
59
+ if (!isRecord(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
60
+ return { valid: false, permissions: {} };
61
+ }
62
+ const key = rawEntry.key.trim();
63
+ if (seenKeys.has(key) || (rawEntry.status !== 'enabled' && rawEntry.status !== 'disabled') || !isRecord(rawEntry.config)) {
64
+ return { valid: false, permissions: {} };
65
+ }
66
+ seenKeys.add(key);
67
+ if (!isManagedMiniProgramRuntimePermissionKey(key)) {
68
+ continue;
69
+ }
70
+ if (key === 'network.request' && typeof rawEntry.config.useOfficialDomain !== 'boolean') {
71
+ return { valid: false, permissions: {} };
72
+ }
73
+ permissions[key] = {
74
+ key,
75
+ status: rawEntry.status,
76
+ config: { useOfficialDomain: rawEntry.config.useOfficialDomain },
77
+ };
78
+ }
79
+ return { valid: true, permissions };
80
+ }
81
+ function isRecord(value) {
82
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
83
+ }
84
+
33
85
  /**
34
86
  * 登录授权能力方法名。
35
87
  *
@@ -327,4 +379,4 @@ const MINI_PROGRAM_PROTOCOL_CAPABILITIES = [
327
379
  },
328
380
  ];
329
381
 
330
- 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_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_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, isMiniProgramBridgeMessage };
382
+ 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_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_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, isManagedMiniProgramRuntimePermissionKey, isMiniProgramBridgeMessage, parseMiniProgramRuntimePermissions };
@@ -1,6 +1,6 @@
1
1
  # <%= projectName %>
2
2
 
3
- 这是通过 `hb-sdk create` 生成的黑盒外部小程序开发模板。项目使用 Vue 3、Vite、TypeScript 和 `@heybox/hb-sdk`。
3
+ 这是通过 `hb-sdk create` 生成的小黑盒工坊小程序模板。项目使用 Vue 3、Vite、TypeScript 和 `@heybox/hb-sdk`。
4
4
 
5
5
  ## 使用命令
6
6
 
@@ -19,9 +19,9 @@ npm run deploy
19
19
 
20
20
  ## 开发模式
21
21
 
22
- - `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面,也可以选择局域网网卡后用手机小黑盒 APP 扫码调试。手机需要与电脑处在同一局域网,并使用支持小程序调试壳的新版小黑盒 APP。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
22
+ - `npm run dev`:打开本地调试页,可以使用浏览器 Mock,也可以在 Mac 版 APP 或手机小黑盒 APP 中验收。手机和电脑需要处于同一局域网。
23
23
  - `npm run build`:先执行 TypeScript 检查,再构建生产产物。
24
- - `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` 已删除,不再作为兼容别名保留。
24
+ - `npm run deploy -- --release-note "..."`:检查、构建、上传并提交审核。首次提交前先运行 `npx hb-sdk login`,再用 `npx hb-sdk remote create` 创建小程序,或用 `npx hb-sdk remote bind <mini-program-id>` 绑定已有小程序。审核通过后,用 `hb-sdk remote release <version>` 发布。
25
25
 
26
26
  ## 更多能力
27
27
 
@@ -40,10 +40,6 @@ await hbSDK.storage.setStorage({
40
40
  data: { theme: 'dark' },
41
41
  });
42
42
 
43
- const response = await hbSDK.network.request({
44
- method: 'GET',
45
- url: 'https://jsonplaceholder.typicode.com/todos/1',
46
- });
47
43
  ```
48
44
 
49
- 工坊小程序通常不要传 `url`;宿主 runtime 会自动生成当前小程序的通用分享页。只有确实要分享外部 HTTP(S) 页面时才显式传 `url`。
45
+ 工坊小程序默认不能进行网络请求,网络权限暂未开放申请。
package/dist/vite.cjs.js CHANGED
@@ -7,7 +7,7 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
7
7
  /** 构建时替换为当前发布包的实际版本。 */
8
8
  const HB_SDK_VERSION = typeof undefined === 'string'
9
9
  ? undefined
10
- : '0.6.4-alpha.0';
10
+ : '0.6.5';
11
11
 
12
12
  var re = {exports: {}};
13
13
 
package/dist/vite.esm.js CHANGED
@@ -4,7 +4,7 @@ import path from 'node:path';
4
4
  /** 构建时替换为当前发布包的实际版本。 */
5
5
  const HB_SDK_VERSION = typeof undefined === 'string'
6
6
  ? undefined
7
- : '0.6.4-alpha.0';
7
+ : '0.6.5';
8
8
 
9
9
  var re = {exports: {}};
10
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk",
3
- "version": "0.6.4-alpha.0",
3
+ "version": "0.6.5",
4
4
  "sideEffects": [
5
5
  "./src/index.ts",
6
6
  "./src/core/singleton.ts",
package/skill/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: hb-sdk
3
- description: Uses @heybox/hb-sdk and its hb-sdk CLI for Heybox external mini-program iframe pages, local mock development, template creation, skill version checks, host/runtime protocol integration, and mini-program listing/audit/compliance review. Use for ready/auth/user/share/viewport/storage/network APIs, lifecycle events, hb-sdk create/dev/login/doctor, mock runtime debugging, custom SDK instances, or @heybox/hb-sdk/protocol contracts. Don't use for raw postMessage bridge construction in app code, direct cookie/token access, internal Heybox client protocols, separate mock runtimes, or non-Heybox SDKs.
3
+ description: Uses @heybox/hb-sdk and its hb-sdk CLI to build, debug, review, and publish workshop mini-programs for the Heybox App. Use for public SDK APIs, lifecycle events, hb-sdk create/dev/login/doctor, browser Mock and device debugging, or publishing checks. Don't use for private credentials, internal Heybox client protocols, private package paths, or non-Heybox SDKs.
4
4
  ---
5
5
 
6
6
  # hb-sdk Agent Procedure
@@ -9,19 +9,19 @@ Apply these instructions when writing, reviewing, or debugging code that consume
9
9
 
10
10
  ## Step 1: Classify the task
11
11
 
12
- 1. If the task is iframe mini-program business code, use the root package import path `@heybox/hb-sdk`.
12
+ 1. If the task is workshop mini-program business code, use the root package import path `@heybox/hb-sdk`.
13
13
  2. If the task is parent-container runtime, bridge-server, protocol contract, or `@heybox/hb-sdk-runtime` work, use `@heybox/hb-sdk/protocol` only for shared constants and types.
14
- 3. If the task is project scaffolding, local Vite startup, browser mock runtime, CLI login cache, Agent Skill version diagnosis, or CLI troubleshooting, use the `hb-sdk` CLI workflow.
14
+ 3. If the task is project scaffolding, local startup, browser Mock, device debugging, CLI login, Agent Skill diagnosis, or CLI troubleshooting, use the `hb-sdk` CLI workflow.
15
15
  4. If the task is reviewing a mini-program for submission, listing, audit, publishing, content compliance, data/privacy compliance, runtime quality, or icon/cover design requirements, use the online publishing rules workflow.
16
16
  5. If the task asks for direct login-state extraction, cookies, tokens, raw Heybox client protocols, or internal hb-sdk package paths, refuse that approach and use the public SDK or CLI boundary instead.
17
- 6. If the task is not about Heybox external mini-program SDK usage, CLI usage, mock runtime, protocol contracts, or mini-program listing/audit/compliance review, do not apply this skill.
17
+ 6. If the task is not about Heybox workshop mini-program SDK usage, CLI usage, protocol contracts, or listing/audit/compliance review, do not apply this skill.
18
18
 
19
19
  ## Step 2: Load only the needed reference
20
20
 
21
21
  1. For root SDK imports, singleton usage, modules, and errors, read `references/api-root.md`.
22
- 2. For host/runtime protocol contracts only, read `references/api-protocol.md`. Do not use this reference to build iframe business-code bridge messages.
22
+ 2. For host/runtime protocol contracts only, read `references/api-protocol.md`. Do not use this reference for mini-program business code.
23
23
  3. For common business flows, read `references/recipes.md`.
24
- 4. For CLI commands, local mock runtime, generated templates, CLI login cache, Agent Skill doctor, and update reminders, read `references/cli.md`.
24
+ 4. For CLI commands, local debugging, device debugging, CLI login, Agent Skill doctor, and update reminders, read `references/cli.md`.
25
25
  5. For allowed/forbidden capabilities and security boundaries, read `references/safety-boundaries.md`.
26
26
  6. For Vite build manifest behavior, read `references/api-root.md` and `references/safety-boundaries.md`.
27
27
  7. For generated documentation provenance and deeper API lookup paths, read `references/llms-index.md`.
@@ -36,71 +36,57 @@ Apply these instructions when writing, reviewing, or debugging code that consume
36
36
  3. Never import from internal hb-sdk implementation paths; only use the documented package entrypoints.
37
37
  4. Prefer named imports for focused code and the default `hbSDK` singleton for compact page-level examples.
38
38
 
39
- ## Step 4: Implement iframe mini-program code
39
+ ## Step 4: Implement workshop mini-program code
40
40
 
41
41
  1. Call `await ready()` or `await hbSDK.ready()` near page startup when the page uses SDK capabilities.
42
42
  2. Use `user.getInfo()` to read current login state without triggering login.
43
43
  3. Use `auth.login()` only when the user action requires login.
44
- 4. Handle `HbMiniProgramSDKError` for bridge/runtime/protocol failures.
44
+ 4. Handle `HbMiniProgramSDKError` for SDK initialization and capability failures.
45
45
  5. Handle `HbMiniProgramNetworkError` separately when HTTP completed but `validateStatus` rejected the status.
46
46
  6. Cancel lifecycle/event subscriptions returned by `on()` when the page or component unmounts.
47
- 7. Import the root package eagerly; version 0.6 exposes only the unique default SDK instance and starts its handshake as a required import side effect.
47
+ 7. Use the default SDK instance exposed by the root package.
48
48
 
49
49
  ## Step 5: Use CLI workflows
50
50
 
51
- 1. Use `hb-sdk create <project-name>` to scaffold a standalone external mini-program template.
52
- 2. Use `hb-sdk dev` for local browser, Mac App, or mobile App debugging through the built-in mock runtime host. Vite and native dev-shell entrypoints only require the local `mini_url`: a missing project binding, CLI login, remote dev-context failure, or the 3-second context timeout must fall back to an anonymous local sandbox instead of blocking startup. Anonymous mode denies managed capabilities by default. When a verified remote dev context is available, the Mock Host uses its Runtime permission snapshot as the initial local simulation and reports local-versus-online permission differences.
53
- 3. Use `hb-sdk remote ...` for developer-owned remote mini-program management. Top-level `hb-sdk deploy` has been hard-cut and must not be recommended as a compatibility alias.
54
- 4. Use `hb-sdk remote entity list`, `hb-sdk remote entity current`, and `hb-sdk remote entity switch <entity-id>` to inspect or change the developer platform server-side current entity before remote management commands.
55
- 5. Use `hb-sdk remote create` to create a remote mini-program under the server-side current entity and bind the returned id into `package.json.heybox.miniProgramId`; use `hb-sdk remote bind <mini-program-id>` to bind an existing remote mini-program after current-entity manageability is verified. CLI project configuration contains only `package.json.heybox.miniProgramId`; mini-program name, icon, and cover images are maintained on the Open platform version-publish flow. On first submit without prior approved profile, the server injects a default name and default images.
56
- 6. Use `hb-sdk remote info`, `hb-sdk remote list`, `hb-sdk remote access`, `hb-sdk remote versions`, `hb-sdk remote preview <version>`, and `hb-sdk remote allowlist ...` for read/basic/preview management workflows. Mini-program name and image changes must go through version audit, so the CLI must not expose a basic-info update command.
57
- 7. Use `hb-sdk remote deploy --release-note <text>` to build, upload, and submit the current project for audit. It reads `package.json.heybox.miniProgramId`, validates that the bound mini-program belongs to the server-side current entity before precheck/build/upload, prechecks `package.json.version` before build, runs the project's `build` script via the package manager auto-detected by lockfile, uploads `dist/` to CDN (skipping `manifest.json`, `.DS_Store`, `.map`), then calls the submit-audit API. Deploy and `--from-version` do not fetch or compare the client-side `minimumSdkVersion`; Manifest validation and server-side precheck / submit-audit policy still apply. When `--env <name>` or `HB_SDK_ENV=<name>` selects an environment preset, deploy also passes the same name to the project build as its Vite mode. The deploy upload pipeline rejects actual upload artifacts over 100MiB before any upload request, processes CDN upload metadata and callback confirmation at 50 files per batch, keeps 4-way upload concurrency within each batch, and validates CDN-returned keys exactly against the local expected upload keys.
58
- 8. Use `hb-sdk remote deploy --from-version <version> --release-note <text>` to reuse a previously uploaded remote version artifact and submit a new audit version without reading local `dist`, building, or uploading.
59
- 9. Always provide a concise release note before deploy. Non-interactive environments must pass `--release-note`; interactive terminals may prompt for it. The default is manual release after approval with `hb-sdk remote release <version>`; use `--auto-publish` when the audited version should automatically release after approval.
60
- 10. Use `hb-sdk remote release <version>`, `hb-sdk remote withdraw <version>`, `hb-sdk remote take-down`, and `hb-sdk remote reopen` for dangerous remote changes. Interactive terminals should confirm after showing enough context; non-interactive environments must pass `--yes`.
61
- 11. For internal test/staging backend operations, use origin-only custom URLs: `HB_SDK_API_BASE_URL` or `hb-sdk remote ... --api-base-url <url>` for remote platform APIs, and `HB_SDK_LOGIN_BASE_URL` or `hb-sdk login --login-base-url <url>` for browser login. CLI flags override env vars. API base URLs must be Heybox trusted HTTPS origins by default; use `--allow-unsafe-api-base-url` or `HB_SDK_ALLOW_UNSAFE_API_BASE_URL=1` only for local backend debugging. Do not include path, query, or hash in these URLs.
62
- 12. For development routing or gray validation, use `HB_SDK_SERVICE_TAG` to attach `x-rylai-service-tag` and the matching `special_tag` query parameter to CLI backend requests. Repository-local path-specific routing can still be configured in `packages/hb-sdk/src/cli/config.ts` with `@heybox/hb-types` `RylaiServiceTagConfig` (`default_tag` / path-specific `special_tag`).
63
- 13. If a remote command targets a custom login environment, pass the same `--login-base-url` or `HB_SDK_LOGIN_BASE_URL` used for `hb-sdk login`; remote commands reject cached CLI login state from a different login origin.
64
- 14. Add `--verbose` / `-v` only when diagnosing failures; default CLI errors are intentionally concise, while verbose output includes backend envelope, HTTP status, trace fields, raw body, or original submit-audit failure details.
65
- 15. Use `--json` for script consumption of `hb-sdk remote` commands. With `--json`, stdout must contain exactly one JSON object; progress, warnings, update reminders, and verbose diagnostics must not pollute stdout.
66
- 16. Do not expect custom base URLs to affect `hb-sdk doctor`, npm latest checks, or mock-host `network.request()`.
67
- 17. 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; these entrypoints remain available in anonymous mode. The phone must be on the same LAN and use a Heybox App version that supports the mini-program dev shell.
68
- 18. Use `--port`, `--mock-port`, and `--no-open` when the default Vite/mock ports or browser opening behavior need to be controlled.
69
- 19. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for the CLI's own Heybox auth cache. Keep `hb-sdk login` top-level; it is not a remote mini-program command.
70
- 20. Treat `selectedEntity` in the CLI auth cache as a non-authoritative hint snapshot only. Every remote command must use the server-side current entity as the source of truth.
71
- 21. Use `hb-sdk doctor` to diagnose whether the local `hb-sdk` skill matches the installed SDK and remote latest skill metadata.
72
- 22. 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`.
73
- 23. If doctor reports `SDK_MISMATCH`, upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
74
- 24. Do not treat CLI login cache as iframe SDK login state; it does not change `auth.login()`, `user.getInfo()`, `network.request()`, or mock-user behavior.
75
- 25. Keep the CLI and mock runtime under `@heybox/hb-sdk`; do not create or revive a separate mock runtime package.
76
- 26. Do not pass `mini_program_id` or `entity_id` as general CLI flags or environment variables; the mini-program id must come from `package.json.heybox.miniProgramId`, and the entity must come from the server-side current entity.
77
- 27. Do not import deploy / upload internals from outside the CLI; the only externally consumable subpath for publish-pipeline helpers is `@heybox/hb-sdk/miniapp-publish`.
51
+ 1. Use `hb-sdk create <project-name>` to scaffold a workshop mini-program.
52
+ 2. Use `hb-sdk dev` for browser, Mac App, or mobile App debugging. These entries remain available without CLI login or project binding, but managed capabilities are denied by default.
53
+ 3. Use `--port`, `--mock-port`, and `--no-open` when the default local ports or browser opening behavior need to be controlled.
54
+ 4. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for development and publishing commands. This login does not change the mini-program user's login state.
55
+ 5. Use `hb-sdk remote entity current` to confirm the current developer account and `hb-sdk remote entity switch <entity-id>` to change it before remote operations.
56
+ 6. Use `hb-sdk remote create` to create and bind a mini-program; use `hb-sdk remote bind <mini-program-id>` to bind an existing manageable mini-program.
57
+ 7. Use `hb-sdk remote info`, `hb-sdk remote list`, `hb-sdk remote access`, `hb-sdk remote versions`, `hb-sdk remote preview <version>`, and `hb-sdk remote allowlist ...` for remote inspection and preview management.
58
+ 8. Use `hb-sdk remote deploy --release-note <text>` to check, build, upload, and submit the current project for audit. Do not recommend the removed top-level `hb-sdk deploy` alias.
59
+ 9. After approval, use `hb-sdk remote release <version>` for manual release or `--auto-publish` when an eligible low-risk version should release automatically.
60
+ 10. Treat approval, release, and public display as separate states. Do not promise square, search, or recommendation visibility after release.
61
+ 11. Use `hb-sdk remote withdraw`, `hb-sdk remote take-down`, `hb-sdk remote reopen`, and square visibility commands only after showing the target and obtaining required confirmation.
62
+ 12. Use `--json` for script consumption and `--verbose` only when concise output is insufficient for diagnosis.
63
+ 13. Use `hb-sdk doctor` to diagnose whether the local Skill matches the installed SDK; follow its output to install or refresh the Skill.
64
+ 14. Do not print or expose cookies, tokens, private headers, or other credentials.
78
65
 
79
66
  ## Step 6: Preserve capability boundaries
80
67
 
81
- For iframe mini-program business code:
68
+ For workshop mini-program business code:
82
69
 
83
70
  1. Do not read or request tokens, cookies, phone numbers, or private credentials from the SDK.
84
71
  2. Do not expose raw share protocol fields, JS callbacks, activity reporting, custom buttons, post publishing, or upload-only flows.
85
72
  3. Do not use unsupported storage operations such as delete, clear, info listing, or global client storage access.
86
- 4. Do not pass raw host protocol fields through `network.request`; use only the public axios-like request config.
87
- 5. Do not construct bridge envelopes, nonce logic, or raw `postMessage` calls.
73
+ 4. Use only the public `network.request` configuration.
74
+ 5. Do not use private package paths or client protocols.
88
75
  6. Build artifacts may include `dist/manifest.json`; business code should not fetch a deployed manifest directly because it is not a CDN asset.
89
76
 
90
77
  For CLI and local development:
91
78
 
92
79
  1. Do not print, persist in templates, or pass through pkey, cookies, tokens, or private credentials.
93
- 2. Do not use `hb-sdk login` as a workaround for iframe SDK authentication.
94
- 3. Do not bypass `hb-sdk dev` by adding a second browser mock host.
95
- 4. Keep the Vite `miniappManifest()` plugin enabled so builds only start in a compatible APP Runtime. Normal deploy always runs the project build.
96
- 5. Keep Mock Host permission overrides in devtools-only memory. They must not rebuild the iframe, interrupt Vite HMR, mutate online permissions, or be passed through URL query parameters.
97
- 6. Treat remote dev context as optional diagnostics and initialization data. Do not use a public mini-program detail request as a dev startup gate.
80
+ 2. Do not use `hb-sdk login` as a workaround for mini-program user authentication.
81
+ 3. Use the built-in local debugging page instead of creating another browser Mock.
82
+ 4. Keep the Vite `miniappManifest()` plugin enabled.
83
+ 5. Treat browser Mock settings as local-only; they must not be presented as online permissions.
98
84
 
99
85
  For host/runtime/protocol-maintenance code:
100
86
 
101
87
  1. Use `@heybox/hb-sdk/protocol` for shared constants and type contracts.
102
- 2. Keep raw protocol details inside the host/runtime boundary; do not leak them into app-facing SDK examples or iframe business code.
103
- 3. Keep bridge handshake and nonce behavior idempotent and compatible with existing SDK clients.
88
+ 2. Keep raw protocol details inside the host/runtime boundary; do not leak them into app-facing SDK examples or workshop mini-program business code.
89
+ 3. Preserve compatibility with existing SDK clients.
104
90
 
105
91
  ## Step 7: Validate changes
106
92
 
@@ -111,7 +97,7 @@ For host/runtime/protocol-maintenance code:
111
97
  3. When preparing a package release, run `pnpm --filter @heybox/hb-sdk run release:prepare -- --bump patch` or `pnpm --filter @heybox/hb-sdk run release:prepare -- --version <x.y.z>`. The release assistant updates both package versions, inserts `packages/hb-sdk/CHANGELOG.md`, and runs `check:changelog`. Use `--ai-command "<command>"` or `HB_SDK_CHANGELOG_AI_COMMAND` when an AI writer should rewrite the Conventional Commit draft. Review the entry for Mini-program developers and Host/Runtime integration maintainers, and do not expose Runtime internal adapter, state-machine, or security-policy details.
112
98
  4. When modifying this repo's source skill at `packages/hb-sdk/skill` and preparing distributable artifacts, also run:
113
99
  - `node packages/hb-sdk/skill/scripts/package-skill.mjs`
114
- 5. When modifying CLI, mock runtime, package exports, or package dependency direction, also run:
100
+ 5. When modifying CLI, local debugging, package exports, or package dependency direction, also run:
115
101
  - `pnpm --filter @heybox/hb-sdk run check:boundary`
116
102
  - `pnpm --filter @heybox/hb-sdk run test:unit`
117
103
  6. Inspect the generated zip before distribution:
@@ -31,6 +31,13 @@ export {
31
31
  SDK_LOCATION_REPORT_METHOD,
32
32
  } from './protocol/constants';
33
33
  export { isMiniProgramBridgeMessage } from './protocol/guards';
34
+ export { isManagedMiniProgramRuntimePermissionKey, parseMiniProgramRuntimePermissions } from './protocol/runtime-permissions';
35
+ export type {
36
+ MiniProgramRuntimePermissionEntry,
37
+ MiniProgramRuntimePermissionStatus,
38
+ MiniProgramRuntimePermissionsSnapshot,
39
+ ParsedMiniProgramRuntimePermissions,
40
+ } from './protocol/runtime-permissions';
34
41
  export type {
35
42
  MiniProgramBridgeError,
36
43
  MiniProgramBridgeMessage,
@@ -139,11 +146,7 @@ export type {
139
146
  MiniProgramShareChannel,
140
147
  MiniProgramShowShareMenuOptions,
141
148
  } from './modules/share';
142
- export type {
143
- GetStoragePayload,
144
- GetStorageResult,
145
- SetStoragePayload,
146
- } from './modules/storage';
149
+ export type { GetStoragePayload, GetStorageResult, SetStoragePayload } from './modules/storage';
147
150
  export type {
148
151
  GetWindowInfoPayload,
149
152
  GetWindowInfoResult,
@@ -173,13 +176,7 @@ export type {
173
176
  ShowToastPayload,
174
177
  ShowToastResult,
175
178
  } from './modules/ui';
176
- export type {
177
- MiniProgramVibrateIntensity,
178
- SetClipboardPayload,
179
- SetClipboardResult,
180
- VibratePayload,
181
- VibrateResult,
182
- } from './modules/device';
179
+ export type { MiniProgramVibrateIntensity, SetClipboardPayload, SetClipboardResult, VibratePayload, VibrateResult } from './modules/device';
183
180
  export type {
184
181
  ClosePayload,
185
182
  CloseResult,
@@ -210,18 +207,22 @@ Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不
210
207
 
211
208
  | 导出面 | 说明 |
212
209
  | --- | --- |
213
- | [Root API](api-root.md) | 来自 `src/index.ts` 的默认导出、命名导出与公开能力。 |
214
- | [Protocol API](#public-protocol-entrypoint) | 来自 `src/protocol.ts` 的协议常量、消息类型与 method 契约。 |
210
+ | [Root API](api-root.md) | `@heybox/hb-sdk` 的默认导出、命名导出与公开能力。 |
211
+ | [Protocol API](#public-protocol-entrypoint) | `@heybox/hb-sdk/protocol` 的协议常量、消息类型与 method 契约。 |
212
+ | [Miniapp Publish API](https://open.xiaoheihe.cn/docs/hb_sdk/reference/miniapp-publish/) | `@heybox/hb-sdk/miniapp-publish` 的构建产物发布前的公开校验工具。 |
213
+ | [Vite API](https://open.xiaoheihe.cn/docs/hb_sdk/reference/vite/) | `@heybox/hb-sdk/vite` 的Vite 工坊小程序插件。 |
215
214
 
216
215
  ## 查询建议
217
216
 
218
217
  - 想查业务接入路径:先看 [Guide](recipes.md)。
219
- - 想查导出符号:从 Root API 或 Protocol API 进入对应分类页。
218
+ - 想查导出符号:从上方对应公开入口进入分类页。
220
219
  - 想看场景化用法:优先看 Guide / Recipes 页面中的“进一步阅读”。
221
220
 
222
221
  ## 统计
223
222
 
224
223
  | 导出面 | Classes | Functions | Interfaces | Types | Constants |
225
224
  | --- | ---: | ---: | ---: | ---: | ---: |
226
- | Root API | 2 | 3 | 66 | 57 | 4 |
227
- | Protocol API | 0 | 1 | 43 | 68 | 35 |
225
+ | Root API | 2 | 3 | 66 | 57 | 0 |
226
+ | Protocol API | 0 | 3 | 43 | 67 | 32 |
227
+ | Miniapp Publish API | 0 | 5 | 2 | 0 | 0 |
228
+ | Vite API | 0 | 1 | 0 | 0 | 0 |
@@ -19,7 +19,7 @@
19
19
  ## Package metadata
20
20
 
21
21
  - Package: `@heybox/hb-sdk`
22
- - Version at generation time: `0.6.4-alpha.0`
22
+ - Version at generation time: `0.6.5`
23
23
  - Public root export: `@heybox/hb-sdk`
24
24
  - Protocol export: `@heybox/hb-sdk/protocol`
25
25
  - Vite plugin export: `@heybox/hb-sdk/vite`
@@ -450,9 +450,9 @@ SDK 需要在黑盒小程序 iframe 容器内运行。父容器会为页面注
450
450
  npm run dev
451
451
  ```
452
452
 
453
- 调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境。`hb-sdk dev` 的基础启动只依赖本地页面地址:即使项目未绑定、CLI 未登录或远端暂时不可用,浏览器 Mock、Mac 启动协议和手机二维码也会继续生成,真机 dev shell 以匿名本地沙箱加载 `mini_url`,不会把公开 `detail` 查询作为启动门禁。项目已绑定时会限时 3 秒读取远端 dev context;成功后 Mock Host 用真实 Runtime 权限快照初始化本地模拟,失败或超时则显示脱敏警告,并默认拒绝 `network.request` 等受管能力。
453
+ 调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境。`hb-sdk dev` 的基础启动只依赖本地页面地址:即使项目未绑定、CLI 未登录或远端暂时不可用,浏览器 Mock、Mac 启动协议和手机二维码也会继续生成,真机 dev shell 以匿名本地沙箱加载 `mini_url`,不会把公开 `detail` 查询作为启动门禁。项目已绑定时会限时 3 秒读取远端 dev context;成功后 Mock Host 用真实 Runtime 权限快照初始化本地模拟,失败或超时则显示脱敏警告,并默认拒绝 `network.request` 等受管能力。需要定位降级原因时可使用 `hb-sdk dev --verbose`;详细错误只写入本地调试日志,其中 URL 用户名、密码和敏感 query/hash 会被遮蔽,不会进入 LAN bootstrap。
454
454
 
455
- Mock Host 可以在内存中调整 devtools-only 权限模拟,不会重建 iframe,因此不影响 Vite HMR;本地设置不会修改线上权限。调试页会对比已读取的线上快照,提示本地放开但上线后会返回 `PERMISSION_DENIED` 的差异。权限快照只通过 mock host 的同源只读 bootstrap 接口传递,URL query 不能提供或覆盖权限。真实容器加载开发 `mini_url` 前会提示“即将打开未经验证的开发网页。该页面可能由本机或局域网服务提供,请确认来源可信后继续。”,用户确认后才继续加载。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
455
+ Mock Host 可以在内存中切换 devtools-only `network.request` 权限,不会重建 iframe,因此不影响 Vite HMR;官方域名权限只读取线上快照,本地设置不会修改线上权限。调试页会对比已读取的线上快照,提示本地放开但上线后会返回 `PERMISSION_DENIED` 的差异。权限快照只通过 mock host 的同源只读 bootstrap 接口传递,URL query 不能提供或覆盖权限。真实容器加载开发 `mini_url` 前会提示“即将打开未经验证的开发网页。该页面可能由本机或局域网服务提供,请确认来源可信后继续。”,用户确认后才继续加载。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
456
456
 
457
457
  在未使用脚手架的 Vite 项目中,可以把命令加到 `package.json`:
458
458