@heybox/hb-sdk 0.8.0 → 0.8.1-alpha.10

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 (69) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +80 -7
  3. package/dist/cli-chunks/{build-PYCNacya.cjs → build-CtqIXxDL.cjs} +16 -10
  4. package/dist/cli-chunks/{context-m2W2XbL0.cjs → context-t57bMfbr.cjs} +17 -3
  5. package/dist/cli-chunks/{create-BdAg3WGA.cjs → create-BDOPSacf.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-CyZuw7Yn.cjs → dev-VxjconYc.cjs} +628 -147
  7. package/dist/cli-chunks/{doctor-DU8rCfUF.cjs → doctor-BkfYdlnZ.cjs} +1 -1
  8. package/dist/cli-chunks/{index-MMW2ibQm.cjs → index-DDrytLTX.cjs} +87 -15
  9. package/dist/cli-chunks/{index-DATObqzK.cjs → index-lLaHzwfT.cjs} +2 -2
  10. package/dist/cli-chunks/{index.esm-BiAaAUFC.cjs → index.esm-Dy4qRhuo.cjs} +9 -8
  11. package/dist/cli-chunks/{login-B3TThMss.cjs → login-D2EX4R5_.cjs} +2 -2
  12. package/dist/cli-chunks/{project-vite-BQj8YLI4.cjs → project-vite-CFhz2THK.cjs} +1 -1
  13. package/dist/cli-chunks/{remote-DNvI7tHH.cjs → remote-CfESZxO2.cjs} +41 -28
  14. package/dist/cli-chunks/{runtime-gate-BEFp1w_s.cjs → runtime-gate-BWb8QIcX.cjs} +0 -107
  15. package/dist/cli-chunks/{runtime-permission-env-CtL8rsjB.cjs → runtime-permission-env-BtTDFqEL.cjs} +304 -23
  16. package/dist/cli-chunks/{session-DjBkjaF8.cjs → session-Dkhwjqhm.cjs} +1 -1
  17. package/dist/cli-chunks/{skill-cR_wnaw2.cjs → skill-DOveC5jt.cjs} +83 -27
  18. package/dist/cli-chunks/{version-yEn1E2Bg.cjs → version-C4nE66sX.cjs} +1 -1
  19. package/dist/cli.cjs +1 -1
  20. package/dist/devtools/browser-dev-host/assets/browser-dev-host-BM9Qo_Ta.js +101 -0
  21. package/dist/devtools/browser-dev-host/assets/desktop-app-launch-C2I333Yn.js +6 -0
  22. package/dist/devtools/browser-dev-host/assets/index-Bnb6MMTv.js +567 -0
  23. package/dist/devtools/browser-dev-host/assets/index-D-aNERAr.css +1 -0
  24. package/dist/devtools/browser-dev-host/index.html +3 -3
  25. package/dist/index.cjs.js +1970 -1567
  26. package/dist/index.esm.js +1969 -1568
  27. package/dist/miniapp-publish.cjs.js +61 -0
  28. package/dist/miniapp-publish.esm.js +59 -1
  29. package/dist/protocol.cjs.js +64 -13
  30. package/dist/protocol.esm.js +64 -13
  31. package/dist/templates/vanilla-vite-js/README.md.ejs +1 -1
  32. package/dist/templates/vanilla-vite-js/package.json.ejs +1 -0
  33. package/dist/templates/vanilla-vite-js/vite.config.js +1 -1
  34. package/dist/vite.cjs.js +1333 -18
  35. package/dist/vite.esm.js +1334 -20
  36. package/package.json +9 -11
  37. package/skill/SKILL.md +11 -3
  38. package/skill/references/api-protocol.md +8 -4
  39. package/skill/references/api-root.md +328 -210
  40. package/skill/references/cli.md +11 -3
  41. package/skill/references/examples.md +13 -1
  42. package/skill/references/recipes.md +162 -0
  43. package/skill/references/safety-boundaries.md +9 -3
  44. package/skill/skill.json +5 -5
  45. package/types/core/client.d.ts +9 -1
  46. package/types/core/sdk.d.ts +6 -0
  47. package/types/core/singleton.d.ts +6 -0
  48. package/types/devtools/device-logs.d.ts +48 -0
  49. package/types/index.d.ts +5 -1
  50. package/types/miniapp-manifest/companion-directory.d.ts +2 -0
  51. package/types/miniapp-manifest/companion-executable.d.ts +4 -0
  52. package/types/miniapp-manifest/companion-types.d.ts +38 -0
  53. package/types/miniapp-manifest/companions.d.ts +17 -0
  54. package/types/miniapp-manifest/index.d.ts +2 -0
  55. package/types/miniapp-manifest/node.d.ts +9 -0
  56. package/types/miniapp-manifest/permissions.d.ts +1 -1
  57. package/types/miniapp-manifest/schema.d.ts +5 -1
  58. package/types/miniapp-publish/index.d.ts +17 -2
  59. package/types/modules/companion/index.d.ts +57 -0
  60. package/types/modules/environment/index.d.ts +70 -0
  61. package/types/modules/network/index.d.ts +1 -4
  62. package/types/modules/network/observability.d.ts +0 -1
  63. package/types/protocol/dev-session.d.ts +8 -1
  64. package/types/protocol.d.ts +1 -1
  65. package/types/vite/index.d.ts +11 -4
  66. package/dist/devtools/browser-dev-host/assets/browser-dev-host-TzYf9L6C.js +0 -99
  67. package/dist/devtools/browser-dev-host/assets/index-C5MZZDa5.js +0 -567
  68. package/dist/devtools/browser-dev-host/assets/index-P-ra4m1y.css +0 -1
  69. package/dist/devtools/browser-dev-host/assets/workbench-state-BwV7bm4n.js +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.1-alpha.10",
4
4
  "sideEffects": [
5
5
  "./src/index.ts",
6
6
  "./src/core/singleton.ts",
@@ -62,7 +62,7 @@
62
62
  "skills": "1.5.23",
63
63
  "undici": "^7.28.0",
64
64
  "ws": "^8.18.0",
65
- "@heybox/hb-sdk-protocol": "0.8.0"
65
+ "@heybox/hb-sdk-protocol": "0.8.1-alpha.10"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "vite": ">=5"
@@ -114,11 +114,11 @@
114
114
  "vite": "^8.0.12",
115
115
  "vitest": "^3.2.4",
116
116
  "@heybox-domain/heybox-theme": "~0.1.0",
117
- "@heybox/hb-api": "~1.28.2",
118
- "@heybox/hb-sdk-runtime": "~0.8.0",
117
+ "@heybox/hb-api": "~1.28.3",
118
+ "@heybox-domain/heybox-vue3-ui": "~0.1.0",
119
+ "@heybox/hb-sdk-runtime": "~0.8.1-alpha.10",
119
120
  "@heybox/runtime": "~0.2.0",
120
121
  "@heybox/runtime-policy": "~0.2.0",
121
- "@heybox-domain/heybox-vue3-ui": "~0.1.0",
122
122
  "@heybox/runtime-transport-fetch": "~0.2.0"
123
123
  },
124
124
  "publishConfig": {
@@ -171,11 +171,11 @@
171
171
  "check:compatibility-evidence": "node scripts/validate-compatibility-evidence.mjs",
172
172
  "check:api-semver": "node ../../ops/jobs/hb-sdk-docs-contract/semantic-diff.cjs",
173
173
  "clean": "rimraf ./dist && rimraf ./types",
174
- "test:unit": "NODE_OPTIONS='--conditions=heybox' vitest run",
174
+ "test:unit": "vitest run",
175
175
  "test:types:characterization": "tsc -p tsconfig.characterization.json --noEmit --pretty false",
176
176
  "test:types:browser-dev-host": "vue-tsc -p tsconfig.browser-dev-host.json --noEmit --pretty false",
177
177
  "test:types": "pnpm run test:types:characterization && pnpm run test:types:browser-dev-host",
178
- "test:e2e:browser-dev-host": "pnpm run build:browser-dev-host && NODE_OPTIONS='--conditions=heybox' vitest run --config vitest.browser-dev-host-e2e.config.ts",
178
+ "test:e2e:browser-dev-host": "pnpm run build:lib && pnpm run build:cli:bundle && NODE_OPTIONS='--conditions=heybox' vitest run --config vitest.browser-dev-host-e2e.config.ts",
179
179
  "test:create-template:artifact": "node scripts/test-create-template-artifact.mjs",
180
180
  "test:unit:coverage": "NODE_OPTIONS='--conditions=heybox' vitest run --coverage",
181
181
  "test:vite": "pnpm run build:hb-sdk-protocol && pnpm run build:hb-api-contract && vitest run --config vitest.vite.config.ts",
@@ -183,14 +183,12 @@
183
183
  "changelog:draft": "node scripts/changelog-draft.cjs",
184
184
  "check:changelog": "node scripts/check-changelog.cjs",
185
185
  "release:verify-tarball": "node scripts/skill/verify-tarball-install.mjs",
186
- "test:release": "node --test scripts/public-changelog.test.mjs scripts/public-changelog-workflow.test.cjs scripts/release-family.test.cjs ../../ops/jobs/publish-changed-packages/publish.test.cjs ../../ops/jobs/release-hb-sdk/docs-release-contract.test.cjs ../../ops/jobs/release-hb-sdk/stable-promote-coordinator.test.cjs",
186
+ "test:release": "node --test scripts/public-changelog.test.mjs scripts/public-changelog-workflow.test.cjs scripts/release-family.test.cjs ../../ops/jobs/publish-changed-packages/publish.test.cjs",
187
187
  "test:compatibility-evidence": "node --test scripts/validate-compatibility-evidence.test.mjs",
188
188
  "release:prepare": "node scripts/release-prepare.cjs",
189
189
  "release:tag": "node scripts/release-tag.cjs",
190
190
  "release:family:dry-run": "node ../../ops/jobs/publish-changed-packages/publish.cjs --dry-run",
191
191
  "release:family:promote": "node ../../ops/jobs/publish-changed-packages/publish.cjs --family-action promote",
192
- "release:family:rollback": "node ../../ops/jobs/publish-changed-packages/publish.cjs --family-action rollback",
193
- "release:stable:promote": "node ../../ops/jobs/release-hb-sdk/stable-promote-coordinator.cjs --action promote",
194
- "release:stable:rollback": "node ../../ops/jobs/release-hb-sdk/stable-promote-coordinator.cjs --action rollback"
192
+ "release:family:rollback": "node ../../ops/jobs/publish-changed-packages/publish.cjs --family-action rollback"
195
193
  }
196
194
  }
package/skill/SKILL.md CHANGED
@@ -21,6 +21,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
21
21
  1. For root SDK imports, singleton usage, modules, and errors, read `references/api-root.md`.
22
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
+ For managed desktop programs, read the `Managed Companion` section and preserve its trust boundaries.
24
25
  4. For CLI commands, production builds, local debugging, device debugging, CLI login, Agent Skill doctor, and update reminders, read `references/cli.md`.
25
26
  5. For allowed/forbidden capabilities and security boundaries, read `references/safety-boundaries.md`.
26
27
  6. For Vite build manifest behavior, read `references/api-root.md` and `references/safety-boundaries.md`.
@@ -52,14 +53,18 @@ Apply these instructions when writing, reviewing, or debugging code that consume
52
53
  12. Use `share.showShareMenu({ extra })` to open the share menu or `share.copyLink({ extra })` to copy and return the mini-program share link. `share.showShareMenu()` always uses the platform `common_share` landing page and does not accept a custom `url`. Read the JSON-compatible page state synchronously with `share.getExtra()` after launch, validate the developer-defined fields, and fall back to the default page when it returns `undefined`.
53
54
  13. New PC enables the retained `files` and `network.download()` contract with persistent sandbox storage, single-file/directory pickers, exact File saving, and public-network streaming downloads. Mobile, Web, Browser Dev Host, and legacy PC return `METHOD_FORBIDDEN` and provide no memory/Blob fallback. Call `files.pickFiles()` / `pickDirectory()` / `saveFile()` only from trusted user actions; `saveFile()` accepts only `suggestedName`, `remove()` only deletes sandbox objects, and non-empty directories require `remove({ recursive: true })`.
54
55
  14. Use `network.download()` only with an SDK-created File/Directory target. It is GET-only, does not follow redirects, and exposes local `AbortSignal` / progress callbacks without sending functions over the bridge. Abort is a cancellation intent; a Host commit that already won still resolves successfully.
56
+ 15. Use `companion.prepare()` and `companion.launch()` only from separate trusted user actions. Launch does not prepare implicitly. Treat stdio as raw `Uint8Array` with at-least-once output delivery, and implement business framing and sequence de-duplication explicitly.
57
+ 16. Use `environment.getInfo()` for the immutable runtime, Host App, canonical Mini-program, operating-system, and SDK version snapshot. It waits for the handshake automatically. Use `environment.getInfoSync()` only after `getHandshakeState().status === 'ready'` or inside a ready-state subscription; before that it throws `ENVIRONMENT_NOT_READY`.
58
+ 17. Treat missing environment strings as `null` and unknown enum values as `unknown`. Only `sdk.version` is SemVer; do not compare the other opaque version strings or use any environment field for authentication, authorization, or risk control.
55
59
 
56
60
  ## Step 5: Use CLI workflows
57
61
 
58
62
  1. Use `hb-sdk create <project-name>` to scaffold a workshop mini-program.
59
63
  2. Use `hb-sdk dev` for Browser Mock and Mobile App debugging. Browser debugging can start without CLI login, project binding, or a remote Dev Context; capabilities that need those inputs fail explicitly. Mobile uses the single QR entry with the `open_inapp` and `heybox://` `openWindow` wrapper around a LAN short URL, then opens `heybox-mini-dev://sandbox` with the complete launch context.
60
- 3. The debugging page does not edit permissions. Treat the validated remote permission snapshot as canonical Runtime input. Use `--port`, `--browser-dev-host-port`, and `--no-open` to control local endpoints and browser opening. Select a Mobile network interface the device can reach. `launch.json` is a LAN discovery document, not authentication, encryption, signing, or HMAC protection.
64
+ 3. The debugging page does not edit permissions. Treat the effective intersection of the current project declaration and validated remote approval as canonical Runtime input. Mobile debugging preserves `useOfficialDomain: true` only when both inputs allow it, refreshes the effective permissions before opening on a phone, and never accepts a browser-side permission override. Use `--port`, `--browser-dev-host-port`, and `--no-open` to control local endpoints and browser opening. Select a Mobile network interface the device can reach. `launch.json` is a LAN discovery document, not authentication, encryption, signing, or HMAC protection.
65
+ For real PC Companion debugging, configure local artifacts in `package.json#heybox.companions`, keep `miniappManifest()` enabled, bind the project, and ensure COA has approved `companion`. `hb-sdk dev` validates immutable snapshots without requiring an upload; config or artifact changes rotate the snapshot while existing Sessions retain their original artifact. Prepare and launch the new artifact explicitly. Check separate Browser, Mobile and PC Companion readiness in the debugging workbench. Without a local declaration, use Browser Fake only for state/UI integration.
61
66
  4. Use `hb-sdk build [--env <name>] [--verbose]` as the recommended production build entry. It directly owns the Vite build, always cleans and writes `dist/`, and works without CLI login, project binding, or network access.
62
- 5. Keep `miniappManifest()` explicitly enabled in `vite.config.ts`; `hb-sdk build` must fail when the required Manifest or Runtime gate output is missing.
67
+ 5. Declare the actual supported platforms in `package.json#heybox.platforms` and keep the no-argument `miniappManifest()` explicitly enabled in `vite.config.ts`; `hb-sdk build` must fail when the declaration, Manifest, or Runtime gate output is missing or inconsistent.
63
68
  6. Keep project typechecking in `scripts.build`, for example `vue-tsc --noEmit && hb-sdk build`; `hb-sdk build` does not run typechecking or invoke `scripts.build` itself.
64
69
  7. Existing projects may continue to use `vite build`; do not auto-migrate them. Do not invent `--mode`, `--json`, config, or output-directory flags for `hb-sdk build`.
65
70
  8. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` for remote management, publishing, Mobile debugging, and optional Browser Mock Host `heybox-session` requests. Browser debugging itself can start without CLI login. Mini-program code must still call `auth.login()`; the debug page only confirms authorization. Do not paste CLI credentials into page JavaScript. Phone debugging continues to use the App login.
@@ -88,16 +93,19 @@ For workshop mini-program business code:
88
93
  7. Do not use `network.request()` to reach platform-reserved runtime auth or OpenAPI internal paths.
89
94
  8. Do not expose credentials or describe internal Host authorization state machines and routes in app-facing guidance.
90
95
  9. Do not invent string paths, File System Access API handles, Blob downloads, uploads, Range/resume, external deletion, move, append, or persistent external grants. Public file operations use only SDK-created handles; deletion is limited to SDK sandbox handles.
96
+ 10. Do not pass executable paths, dynamic args, cwd, environment variables, shell commands, URLs, hashes, PID, or native handles through `companion`; reviewed Manifest declarations are the only launch source.
97
+ 11. Do not treat `environment.*` as a device-fingerprint or trusted backend signal. It intentionally excludes account data, device identifiers, model, UA, CPU, and memory; use `viewport.getWindowInfo()` for screen geometry.
91
98
 
92
99
  For CLI and local development:
93
100
 
94
101
  1. Do not print, persist in templates, or pass through pkey, cookies, tokens, or private credentials.
95
102
  2. Do not skip `auth.login()` in mini-program code. Browser Mock may reuse the Node `hb-sdk login` session for Host network requests, but the page must still call `auth.login()` and handle the authorization dialog. Never paste CLI credentials into page JavaScript.
96
103
  3. Use the built-in local debugging page instead of creating another browser Mock.
97
- 4. Keep the Vite `miniappManifest()` plugin enabled.
104
+ 4. Keep target platforms in `package.json#heybox.platforms` and the no-argument Vite `miniappManifest()` plugin enabled. Do not configure platforms in Vite or maintain a second platform list.
98
105
  5. Do not suggest changing or resetting permissions in the `hb-sdk dev` debugging page; that UI does not exist. Diagnose permission behavior from the remote snapshot and capability result.
99
106
  6. Treat browser Mock results as development feedback only. Validate permissions, identity flows, and user interactions again in a real Heybox client before publishing.
100
107
  7. The Browser Dev Host offers iPhone 16 Pro Max (`440 x 956`) and Pixel 9 Pro (`410 x 914`) presets. Switching a preset must preserve the iframe, Runtime session, and page state. Authorization/action dialogs, Toast, Loading, and vibration feedback render inside the preview. Use the upper-right QR popover as the only Mobile QR entry.
108
+ 8. Companion Fake scenarios do not execute a local program and are not Windows/macOS release evidence. V1 only supports normal-privilege launch and rejects `elevation: 'required'` at build time. Require target-platform new PC validation for archive integrity, stdio, exit, and process-tree cleanup.
101
109
 
102
110
  For host/runtime/protocol-maintenance code:
103
111
 
@@ -176,7 +176,10 @@ export type {
176
176
  MiniProgramNetworkMethod,
177
177
  MiniProgramNetworkParams,
178
178
  MiniProgramNetworkRequestMethod,
179
+ MiniProgramOperatingSystemName,
179
180
  MiniProgramRuntimePermissionEntry,
181
+ MiniProgramRuntimeEnvironmentInfo,
182
+ MiniProgramRuntimeMode,
180
183
  MiniProgramRuntimePermissionsSnapshot,
181
184
  MiniProgramRuntimePermissionStatus,
182
185
  MiniProgramSafeArea,
@@ -215,6 +218,7 @@ export type {
215
218
  SaveFilePayload,
216
219
  SaveFileResult,
217
220
  SDKHandshakePayload,
221
+ SDKHandshakeResult,
218
222
  SetClipboardPayload,
219
223
  SetClipboardResult,
220
224
  SetNavigationBarStylePayload,
@@ -295,12 +299,12 @@ Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不
295
299
 
296
300
  | 导出面 | Classes | Functions | Interfaces | Types | Constants |
297
301
  | --- | ---: | ---: | ---: | ---: | ---: |
298
- | Root API | 2 | 4 | 65 | 60 | 1 |
299
- | Protocol API | 0 | 13 | 56 | 90 | 47 |
302
+ | Root API | 2 | 4 | 75 | 73 | 3 |
303
+ | Protocol API | 0 | 13 | 58 | 90 | 47 |
300
304
  | Miniapp Publish API | 0 | 5 | 2 | 0 | 0 |
301
- | Vite API | 0 | 1 | 5 | 1 | 1 |
305
+ | Vite API | 0 | 1 | 5 | 1 | 2 |
302
306
 
303
- <!-- Generated by apps/docs/hb-sdk/scripts/generate-api-docs.ts; schemaVersion=3; fingerprint=660a21ad77c32f30dbc7ebb02b053ebce2a7c6e7301cc805a5cdd1a75572fbb2 -->
307
+ <!-- Generated by apps/docs/hb-sdk/scripts/generate-api-docs.ts; schemaVersion=4; fingerprint=a80eea1bb8b0d64255afcb4a664911f025aeae33f3f766c9b126f55668400178 -->
304
308
 
305
309
  ## SDK API
306
310