hb-sdk
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, persistent handshake state, 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.
How do I install this agent skill?
npx skills add https://open.xiaoheihe.cn --skill hb-sdkIs this agent skill safe to install?
No partner audit is available yet. Read the source before installing.
What does this agent skill do?
hb-sdk Agent Procedure
Apply these instructions when writing, reviewing, or debugging code that consumes @heybox/hb-sdk or uses the companion hb-sdk CLI.
Step 1: Classify the task
- If the task is workshop mini-program business code, use the root package import path
@heybox/hb-sdk. - If the task is parent-container runtime, bridge-server, protocol contract, or
@heybox/hb-sdk-runtimework, use@heybox/hb-sdk/protocolonly for shared constants and types. - If the task is project scaffolding, local startup, production build, browser Mock, device debugging, CLI login, Agent Skill diagnosis, or CLI troubleshooting, use the
hb-sdkCLI workflow. - 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.
- 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.
- 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.
Step 2: Load only the needed reference
- For root SDK imports, singleton usage, modules, and errors, read
references/api-root.md. - For host/runtime protocol contracts only, read
references/api-protocol.md. Do not use this reference for mini-program business code. - For common business flows, read
references/recipes.md. - For CLI commands, production builds, local debugging, device debugging, CLI login, Agent Skill doctor, and update reminders, read
references/cli.md. - For allowed/forbidden capabilities and security boundaries, read
references/safety-boundaries.md. - For Vite build manifest behavior, read
references/api-root.mdandreferences/safety-boundaries.md. - For generated documentation provenance and deeper API lookup paths, read
references/llms-index.md. - For smoke-test expectations, positive examples, and anti-examples, read
references/examples.md. - For evaluating whether another agent followed this skill, read
references/smoke-evaluation.md. - For mini-program listing/audit/compliance review, fetch the online rules Markdown from
https://open.xiaoheihe.cn/docs/hb_sdk/llms/guide/mini-program-publishing-rules.md. Do not rely on a bundledreferences/copy of this document; if the URL is unavailable or returns the docs app shell instead of Markdown, report that the online rules are unavailable and do not complete the review from stale local text.
Step 3: Follow import rules
- Import app-facing SDK APIs from
@heybox/hb-sdk. - Import protocol contracts from
@heybox/hb-sdk/protocolonly in host/runtime/protocol-maintenance code. - Never import from internal hb-sdk implementation paths; only use the documented package entrypoints.
- Prefer named imports for focused code and the default
hbSDKsingleton for compact page-level examples.
Step 4: Implement workshop mini-program code
- Import the root package eagerly; the SDK starts its handshake automatically and capability calls wait for it internally.
- For a network-enabled mini-program, use
auth.login({ scopes? })to obtain{ code, expiresIn: 300, scopes }. Identity is always implicit; request only optional scopes the business actually needs. - Send the code only to the developer's backend. That backend follows the backend OpenAPI documentation to exchange it for a token; mini-program code must never exchange application credentials itself.
- For a network-disabled mini-program, call
user.getInfo()to read the current login state anduserInfo.app_user_id. This read is silent and does not require a trusted user action. It cannot obtain a code or call OpenAPI. - Handle
HbMiniProgramSDKErrorfor SDK initialization and capability failures. - Handle
HbMiniProgramNetworkErrorseparately when HTTP completed butvalidateStatusrejected the status. - Use
getHandshakeState()for the current persistent handshake state andonHandshakeStateChange()for an immediate replay plus future changes. Cancel the returned subscription when the page or component unmounts. - Treat the non-replayed
readylifecycle event only as an edge notification. After a duplicate handshake it may repeat, so never use it as state or as the source for enabling a late-mounted control. - Use the default SDK instance exposed by the root package. For gesture-gated controls, initialize from the current handshake state, subscribe to changes, and enable the control only when
status === 'ready'. Keep calls such asauth.login()in the original user-action callback; do not wait for handshake inside that callback. - When authorization UI is required, call
auth.login()from a trusted user action. Missing gesture returnsUSER_GESTURE_REQUIRED; cancelling, rejecting, or closing returnsAUTHORIZATION_CANCELLEDand does not confirm or change authorization. An already-authorizedauth.login()request may return a new code silently. user.getSteamGameList()is available only to network-disabled mini-programs. In a network-enabled mini-program it returnsSERVER_API_REQUIRED, and there is no Steam library authorization scope or OpenAPI resource. Treatuser.getInfo()returningSERVER_API_REQUIREDas a server-boundary signal, not as logged-out state.- Use
share.showShareMenu({ post })orshare.screenshot({ post })to preset editable community destinations and topics. Pass partition IDs throughtopicIdsand topic text without surrounding#throughtopics; do not construct the underlying client post protocol.
Step 5: Use CLI workflows
- Use
hb-sdk create <project-name>to scaffold a workshop mini-program. - Use
hb-sdk devfor browser, Mac App, or mobile App debugging. These entries remain available without CLI login or project binding, but managed capabilities are denied by default. - Use
--port,--mock-port, and--no-openwhen the default local ports or browser opening behavior need to be controlled. - Use
hb-sdk build [--env <name>] [--verbose]as the recommended production build entry. It directly owns the Vite build, always cleans and writesdist/, and works without CLI login, project binding, or network access. - Keep
miniappManifest()explicitly enabled invite.config.ts;hb-sdk buildmust fail when the required Manifest or Runtime gate output is missing. - Keep project typechecking in
scripts.build, for examplevue-tsc --noEmit && hb-sdk build;hb-sdk builddoes not run typechecking or invokescripts.builditself. - Existing projects may continue to use
vite build; do not auto-migrate them. Do not invent--mode,--json, config, or output-directory flags forhb-sdk build. - Use
hb-sdk login,hb-sdk login status, andhb-sdk login clearonly for development and publishing commands. This login does not changeauth.login(),user.getInfo(), or the mini-program user's authorization state. - Use
hb-sdk remote entity currentto confirm the current developer account andhb-sdk remote entity switch <entity-id>to change it before remote operations. - Use
hb-sdk remote createto create and bind a mini-program; usehb-sdk remote bind <mini-program-id>to bind an existing manageable mini-program. - Use
hb-sdk remote info,hb-sdk remote list,hb-sdk remote access,hb-sdk remote versions,hb-sdk remote preview <version>, andhb-sdk remote allowlist ...for remote inspection and preview management. - Use
hb-sdk remote deploy --release-note <text>to run the project'sscripts.build, upload, and submit the current project for audit. Do not recommend the removed top-levelhb-sdk deployalias. hb-sdk devandhb-sdk remote deployskip the platform CSP only when the validated remote permission snapshot hasnetwork.request.status=enabled.useOfficialDomaindoes not participate in CSP skip decisions. Directhb-sdk build, direct Vite build, anonymous or invalid snapshots, and local Dev Context overrides must keep the platform CSP. Runtime Gate, Manifest, and HTML validation always remain active.- After approval, use
hb-sdk remote release <version>for manual release or--auto-publishwhen an eligible low-risk version should release automatically. - Treat approval, release, and public display as separate states. Do not promise square, search, or recommendation visibility after release.
- 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. - Use
--jsonfor remote script consumption and--verboseonly when concise output is insufficient for diagnosis. - Use
hb-sdk doctorto diagnose whether the local Skill matches the installed SDK; follow its output to install or refresh the Skill. - Do not print or expose cookies, tokens, private headers, or other credentials.
Step 6: Preserve capability boundaries
For workshop mini-program business code:
- Do not read or request tokens, cookies, phone numbers, or private credentials from the SDK.
- Do not expose raw share protocol fields, JS callbacks, activity reporting, custom buttons, direct post publishing, or upload-only flows. Public
share.*({ post })options only preset an editable client post flow and never publish automatically. - Do not use unsupported storage operations such as delete, clear, info listing, or global client storage access.
- Use only the public
network.requestconfiguration. - Do not use private package paths or client protocols.
- Build artifacts may include
dist/manifest.json; business code should not fetch a deployed manifest directly because it is not a CDN asset. - Do not use
network.request()to reach platform-reserved runtime auth or OpenAPI internal paths. - Do not expose credentials or describe internal Host authorization state machines and routes in app-facing guidance.
For CLI and local development:
- Do not print, persist in templates, or pass through pkey, cookies, tokens, or private credentials.
- Do not use
hb-sdk loginas a workaround forauth.login()or mini-program user authorization. - Use the built-in local debugging page instead of creating another browser Mock.
- Keep the Vite
miniappManifest()plugin enabled. - Treat permission changes made in the
hb-sdk devdebugging page as local debugging overrides, not online configuration changes. Use the page's reset action to return to the remote baseline. - Treat browser Mock results as development feedback only. Validate permissions, identity flows, and user interactions again in a real Heybox client before publishing.
For host/runtime/protocol-maintenance code:
- Use
@heybox/hb-sdk/protocolfor shared constants and type contracts. - Keep raw protocol details inside the host/runtime boundary; do not leak them into app-facing SDK examples or workshop mini-program business code.
- Preserve compatibility with existing SDK clients.
Step 7: Validate changes
- Run the nearest package tests and builds with repo-native commands when editing this repository.
- When modifying docs, skill instructions, CLI guidance, or public agent-skill sync points, start with:
pnpm --filter @heybox/hb-sdk run check:docs-synccat packages/hb-sdk/DOC_SYNC_CHECKLIST.md
- When preparing a package release, run
pnpm --filter @heybox/hb-sdk run release:prepare -- --bump patchorpnpm --filter @heybox/hb-sdk run release:prepare -- --version <x.y.z>. The release assistant updates both package versions, insertspackages/hb-sdk/CHANGELOG.md, and runscheck:changelog. Use--ai-command "<command>"orHB_SDK_CHANGELOG_AI_COMMANDwhen 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. - When modifying this repo's source skill at
packages/hb-sdk/skilland preparing distributable artifacts, also run:node packages/hb-sdk/skill/scripts/package-skill.mjs
- When modifying CLI, local debugging, package exports, or package dependency direction, also run:
pnpm --filter @heybox/hb-sdk run check:boundarypnpm --filter @heybox/hb-sdk run test:unit
- Inspect the generated zip before distribution:
unzip -l packages/hb-sdk/hb-sdk.zip | sed -n '1,120p'
- When adding or modifying the deploy command or its upload pipeline, also run:
pnpm --filter @heybox/hb-sdk run check:boundarypnpm --filter @heybox/hb-sdk run test:unit- Verify
dist/cli.cjsdoes not have anyrequire('cos-nodejs-sdk-v5')left afterbuild:cli; the boundary check enforces this automatically.
- Verify the canonical payload before publishing:
pnpm exec hbexec hb-sdk syncpnpm exec hbexec hb-sdk check- For a release artifact, run
pnpm exec hbexec hb-sdk sync --out-dir <payload-dir>and thenpnpm exec hbexec hb-sdk check-artifact --artifact-dir <payload-dir>.
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/open.xiaoheihe.cn/hb-sdk">View hb-sdk on skillZs</a>