@heybox/hb-sdk 0.6.6-alpha.2 → 0.6.6-alpha.3

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 (36) hide show
  1. package/README.md +42 -7
  2. package/dist/cli-chunks/build-De-QADpA.cjs +137 -0
  3. package/dist/cli-chunks/context-CvZs9ZBf.cjs +311 -0
  4. package/dist/cli-chunks/{create-CxjB3oSo.cjs → create-B5gGBaSV.cjs} +1 -1
  5. package/dist/cli-chunks/{dev-Km0or0yY.cjs → dev-BcCWCeac.cjs} +11 -42
  6. package/dist/cli-chunks/{doctor-baVOqNSh.cjs → doctor-BhBM4cWH.cjs} +1 -1
  7. package/dist/cli-chunks/{context-CM46YbPT.cjs → index-BQm5XmMC.cjs} +19 -308
  8. package/dist/cli-chunks/{index-DCsEAuca.cjs → index-DyUo67lf.cjs} +3 -3
  9. package/dist/cli-chunks/{index-ByDy5HXi.cjs → index-QAkYgxPI.cjs} +32 -16
  10. package/dist/cli-chunks/{login-fNe0eDs_.cjs → login-BNLH13Zd.cjs} +2 -2
  11. package/dist/cli-chunks/project-vite-VcJMyz1l.cjs +45 -0
  12. package/dist/cli-chunks/remote-BE53wntR.cjs +1504 -0
  13. package/dist/cli-chunks/{remote-BRIlRrCG.cjs → runtime-gate-B2MQf1vc.cjs} +7 -1501
  14. package/dist/cli-chunks/{session-CTcelATz.cjs → session-YJ8xNESM.cjs} +1 -1
  15. package/dist/cli.cjs +1 -1
  16. package/dist/devtools/mock-host/main.js +149 -3
  17. package/dist/index.cjs.js +1 -1
  18. package/dist/index.esm.js +1 -1
  19. package/dist/templates/vue3-vite-ts/README.md.ejs +2 -2
  20. package/dist/templates/vue3-vite-ts/package.json.ejs +1 -1
  21. package/dist/vite.cjs.js +50 -3
  22. package/dist/vite.esm.js +50 -3
  23. package/package.json +1 -1
  24. package/skill/SKILL.md +19 -14
  25. package/skill/references/api-protocol.md +3 -2
  26. package/skill/references/api-root.md +49 -10
  27. package/skill/references/cli.md +33 -1
  28. package/skill/references/recipes.md +53 -0
  29. package/skill/references/safety-boundaries.md +1 -1
  30. package/skill/scripts/sync-references.mjs +23 -1
  31. package/skill/skill.json +4 -4
  32. package/types/index.d.ts +1 -1
  33. package/types/modules/share/types.d.ts +11 -0
  34. package/types/protocol.d.ts +1 -1
  35. package/types/vite/html-policy.d.ts +4 -1
  36. package/types/vite/index.d.ts +10 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-ByDy5HXi.cjs');
3
+ var index = require('./index-QAkYgxPI.cjs');
4
4
  var node_crypto = require('node:crypto');
5
5
  var path = require('node:path');
6
6
  var require$$0$2 = require('fs');
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./cli-chunks/index-ByDy5HXi.cjs');
3
+ var index = require('./cli-chunks/index-QAkYgxPI.cjs');
4
4
  require('node:module');
5
5
  require('node:fs');
6
6
  require('node:fs/promises');
@@ -4245,15 +4245,150 @@ function getPositiveNumber(value, fallback) {
4245
4245
  return numberValue;
4246
4246
  }
4247
4247
 
4248
+ const MINI_PROGRAM_DEV_SHELL_PROTOCOL = 'heybox-mini-dev:';
4249
+ function isMiniProgramDevShellHref(href) {
4250
+ try {
4251
+ return isMiniProgramDevShellUrl(new URL(href));
4252
+ }
4253
+ catch {
4254
+ return false;
4255
+ }
4256
+ }
4257
+ function isMiniProgramDevShellUrl(url) {
4258
+ return url.protocol === MINI_PROGRAM_DEV_SHELL_PROTOCOL;
4259
+ }
4260
+
4261
+ function readMiniProgramRuntimeSharePostOptions(value, options) {
4262
+ if (value === undefined || value === null) {
4263
+ return {};
4264
+ }
4265
+ if (!isMiniProgramRuntimeRecord(value)) {
4266
+ return invalidSharePostResult(`${options.method} post 必须是对象或 null`);
4267
+ }
4268
+ const topicIds = readTopicIds(value.topicIds);
4269
+ const topics = readTopics(value.topics);
4270
+ const invalidMessages = [...topicIds.invalidMessages, ...topics.invalidMessages];
4271
+ let normalizedTopicIds = topicIds.values;
4272
+ if (options.maxTopicIds !== undefined && normalizedTopicIds.length > options.maxTopicIds) {
4273
+ invalidMessages.push(`${options.method} post.topicIds 最多允许 ${options.maxTopicIds} 项`);
4274
+ normalizedTopicIds = normalizedTopicIds.slice(0, options.maxTopicIds);
4275
+ }
4276
+ const post = createNormalizedPostOptions(normalizedTopicIds, topics.values);
4277
+ if (!post) {
4278
+ invalidMessages.push(`${options.method} post 至少需要一个有效的 topicIds 或 topics`);
4279
+ }
4280
+ return {
4281
+ post,
4282
+ invalidMessage: invalidMessages[0],
4283
+ };
4284
+ }
4285
+ function handleMiniProgramRuntimeSharePostValidation(result, platformAdapter, invoke) {
4286
+ if (!result.invalidMessage) {
4287
+ return invoke(result.post);
4288
+ }
4289
+ const invalidMessage = result.invalidMessage;
4290
+ return isMiniProgramShareDevelopmentRuntime(platformAdapter).then((isDevelopment) => {
4291
+ if (isDevelopment) {
4292
+ throw createMiniProgramRuntimeBridgeError('INVALID_PARAMS', invalidMessage);
4293
+ }
4294
+ return invoke(result.post);
4295
+ });
4296
+ }
4297
+ function readTopicIds(value) {
4298
+ if (value === undefined) {
4299
+ return { values: [], invalidMessages: [] };
4300
+ }
4301
+ if (!Array.isArray(value)) {
4302
+ return { values: [], invalidMessages: ['post.topicIds 必须是数组'] };
4303
+ }
4304
+ const values = [];
4305
+ const seen = new Set();
4306
+ const invalidMessages = [];
4307
+ for (const item of value) {
4308
+ const normalized = normalizeTopicId(item);
4309
+ if (!normalized) {
4310
+ invalidMessages.push('post.topicIds 每项必须是正整数或非空字符串');
4311
+ continue;
4312
+ }
4313
+ if (!seen.has(normalized)) {
4314
+ seen.add(normalized);
4315
+ values.push(normalized);
4316
+ }
4317
+ }
4318
+ return { values, invalidMessages };
4319
+ }
4320
+ function readTopics(value) {
4321
+ if (value === undefined) {
4322
+ return { values: [], invalidMessages: [] };
4323
+ }
4324
+ if (!Array.isArray(value)) {
4325
+ return { values: [], invalidMessages: ['post.topics 必须是数组'] };
4326
+ }
4327
+ const values = [];
4328
+ const seen = new Set();
4329
+ const invalidMessages = [];
4330
+ for (const item of value) {
4331
+ const normalized = typeof item === 'string' ? item.trim() : '';
4332
+ if (!normalized || normalized.startsWith('#') || normalized.endsWith('#')) {
4333
+ invalidMessages.push('post.topics 每项必须是不含首尾 # 的非空字符串');
4334
+ continue;
4335
+ }
4336
+ if (!seen.has(normalized)) {
4337
+ seen.add(normalized);
4338
+ values.push(normalized);
4339
+ }
4340
+ }
4341
+ return { values, invalidMessages };
4342
+ }
4343
+ function normalizeTopicId(value) {
4344
+ if (typeof value === 'number') {
4345
+ return Number.isSafeInteger(value) && value > 0 ? String(value) : undefined;
4346
+ }
4347
+ if (typeof value === 'string') {
4348
+ return value.trim() || undefined;
4349
+ }
4350
+ return undefined;
4351
+ }
4352
+ function createNormalizedPostOptions(topicIds, topics) {
4353
+ if (topicIds.length === 0 && topics.length === 0) {
4354
+ return undefined;
4355
+ }
4356
+ return {
4357
+ ...(topicIds.length > 0 ? { topicIds } : {}),
4358
+ ...(topics.length > 0 ? { topics } : {}),
4359
+ };
4360
+ }
4361
+ function invalidSharePostResult(message) {
4362
+ return { invalidMessage: message };
4363
+ }
4364
+ async function isMiniProgramShareDevelopmentRuntime(platformAdapter) {
4365
+ try {
4366
+ if (isMiniProgramDevShellHref(platformAdapter.app.getCurrentHref())) {
4367
+ return true;
4368
+ }
4369
+ }
4370
+ catch {
4371
+ // 环境读取失败时继续使用宿主的显式开发态判断。
4372
+ }
4373
+ try {
4374
+ return Boolean(await platformAdapter.app.isDevRuntime?.());
4375
+ }
4376
+ catch {
4377
+ return false;
4378
+ }
4379
+ }
4380
+
4248
4381
  /** 截图并唤起分享。 */
4249
4382
  function shareMiniProgramRuntimeScreenshot(payload, platformAdapter) {
4250
4383
  const options = readMiniProgramScreenshotOptions(payload);
4251
4384
  const rect = options.rect || getMiniProgramRuntimeViewportRect(platformAdapter);
4252
- return platformAdapter.share.shareScreenshot({
4385
+ const postResult = readMiniProgramRuntimeSharePostOptions(payload && typeof payload === 'object' ? payload.post : undefined, { method: 'share.screenshot' });
4386
+ return handleMiniProgramRuntimeSharePostValidation(postResult, platformAdapter, (post) => platformAdapter.share.shareScreenshot({
4253
4387
  rect,
4254
4388
  delay: options.delay,
4255
4389
  saveToAlbum: options.saveToAlbum,
4256
- });
4390
+ post,
4391
+ }));
4257
4392
  }
4258
4393
  function readMiniProgramScreenshotOptions(payload) {
4259
4394
  if (payload === undefined || payload === null) {
@@ -4288,7 +4423,17 @@ function readScreenshotRect(value) {
4288
4423
 
4289
4424
  /** 展示基础分享面板。 */
4290
4425
  function showMiniProgramRuntimeShareMenu(payload, platformAdapter, context = {}) {
4291
- return platformAdapter.share.showShareMenu(readMiniProgramShareMenuOptions(payload, platformAdapter, context));
4426
+ const options = readMiniProgramShareMenuOptions(payload, platformAdapter, context);
4427
+ let postResult = readMiniProgramRuntimeSharePostOptions(payload.post, {
4428
+ maxTopicIds: 1,
4429
+ method: 'share.showShareMenu',
4430
+ });
4431
+ if (options.channel && postResult.post) {
4432
+ postResult = {
4433
+ invalidMessage: postResult.invalidMessage || 'share.showShareMenu channel 与 post 不能同时使用',
4434
+ };
4435
+ }
4436
+ return handleMiniProgramRuntimeSharePostValidation(postResult, platformAdapter, (post) => platformAdapter.share.showShareMenu({ ...options, post }));
4292
4437
  }
4293
4438
  function readMiniProgramShareMenuOptions(payload, platformAdapter, context) {
4294
4439
  assertMiniProgramRuntimeRecord(payload, 'share.showShareMenu 参数必须是对象');
@@ -5201,6 +5346,7 @@ function createBrowserMockRuntimePlatformAdapter(options) {
5201
5346
  return {
5202
5347
  app: {
5203
5348
  getCurrentHref: options.getCurrentHref,
5349
+ isDevRuntime: () => true,
5204
5350
  },
5205
5351
  launch: {
5206
5352
  async getMiniProgramInfo() {
package/dist/index.cjs.js CHANGED
@@ -325,7 +325,7 @@ function createMessageId() {
325
325
  /** 构建时替换为当前发布包的实际版本。 */
326
326
  const HB_SDK_VERSION = typeof undefined === 'string'
327
327
  ? undefined
328
- : '0.6.6-alpha.2';
328
+ : '0.6.6-alpha.3';
329
329
 
330
330
  /**
331
331
  * 判断未知数据是否符合小程序 bridge 消息信封。
package/dist/index.esm.js CHANGED
@@ -321,7 +321,7 @@ function createMessageId() {
321
321
  /** 构建时替换为当前发布包的实际版本。 */
322
322
  const HB_SDK_VERSION = typeof undefined === 'string'
323
323
  ? undefined
324
- : '0.6.6-alpha.2';
324
+ : '0.6.6-alpha.3';
325
325
 
326
326
  /**
327
327
  * 判断未知数据是否符合小程序 bridge 消息信封。
@@ -20,8 +20,8 @@ npm run deploy
20
20
  ## 开发模式
21
21
 
22
22
  - `npm run dev`:打开本地调试页,可以使用浏览器 Mock,也可以在 Mac 版 APP 或手机小黑盒 APP 中验收。手机和电脑需要处于同一局域网。
23
- - `npm run build`:先执行 TypeScript 检查,再构建生产产物。
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>` 发布。
23
+ - `npm run build`:先执行 TypeScript 检查,再通过 `hb-sdk build` 构建生产产物。
24
+ - `npm run deploy -- --release-note "..."`:检查、执行项目的 `scripts.build`、上传并提交审核。首次提交前先运行 `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
 
@@ -10,7 +10,7 @@
10
10
  "hb-sdk": "hb-sdk",
11
11
  "dev": "hb-sdk dev",
12
12
  "deploy": "hb-sdk remote deploy",
13
- "build": "vue-tsc --noEmit && vite build",
13
+ "build": "vue-tsc --noEmit && hb-sdk build",
14
14
  "preview": "vite preview",
15
15
  "typecheck": "vue-tsc --noEmit",
16
16
  "test:unit": "vitest run",
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.6-alpha.2';
10
+ : '0.6.6-alpha.3';
11
11
 
12
12
  var re = {exports: {}};
13
13
 
@@ -11445,7 +11445,23 @@ const URL_ATTRIBUTES = {
11445
11445
  track: ['src'],
11446
11446
  video: ['src', 'poster'],
11447
11447
  };
11448
- function enforceMiniappHtmlPolicy(html) {
11448
+ const PRODUCTION_CSP = [
11449
+ "default-src 'none'",
11450
+ "connect-src 'none'",
11451
+ "script-src 'self' 'unsafe-inline'",
11452
+ "style-src 'self' 'unsafe-inline'",
11453
+ "img-src 'self' data: blob:",
11454
+ "font-src 'self' data:",
11455
+ "media-src 'self' blob:",
11456
+ "manifest-src 'self'",
11457
+ "frame-src 'none'",
11458
+ "child-src 'none'",
11459
+ "worker-src 'none'",
11460
+ "object-src 'none'",
11461
+ "form-action 'none'",
11462
+ "base-uri 'none'",
11463
+ ].join('; ');
11464
+ function enforceMiniappHtmlPolicy(html, options = {}) {
11449
11465
  const document = parse(html);
11450
11466
  const htmlElement = findElement(document, 'html');
11451
11467
  const head = findElement(htmlElement ?? document, 'head');
@@ -11455,6 +11471,22 @@ function enforceMiniappHtmlPolicy(html) {
11455
11471
  removePlatformCspMarkers(document);
11456
11472
  walk(document, element => validateElement(element));
11457
11473
  injectMiniappRuntimeGate(document);
11474
+ const content = options.hmrWebSocketUrl
11475
+ ? PRODUCTION_CSP.replace("connect-src 'none'", `connect-src ${options.hmrWebSocketUrl}`)
11476
+ : PRODUCTION_CSP;
11477
+ head.childNodes.unshift({
11478
+ nodeName: 'meta',
11479
+ tagName: 'meta',
11480
+ attrs: [
11481
+ { name: 'http-equiv', value: 'Content-Security-Policy' },
11482
+ { name: 'content', value: content },
11483
+ { name: 'data-heybox-platform-csp', value: '' },
11484
+ ],
11485
+ namespaceURI: 'http://www.w3.org/1999/xhtml',
11486
+ childNodes: [],
11487
+ parentNode: head,
11488
+ sourceCodeLocation: undefined,
11489
+ });
11458
11490
  return serialize(document);
11459
11491
  }
11460
11492
  function validateElement(element) {
@@ -11553,6 +11585,8 @@ const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
11553
11585
  function miniappManifest() {
11554
11586
  let root = process.cwd();
11555
11587
  let outDir = 'dist';
11588
+ let command = 'build';
11589
+ let hmrWebSocketUrl;
11556
11590
  /** 构建链路中更早的失败原因;closeBundle 不得再用产物校验覆盖它。 */
11557
11591
  let priorBuildError;
11558
11592
  return {
@@ -11569,6 +11603,8 @@ function miniappManifest() {
11569
11603
  configResolved(resolved) {
11570
11604
  root = resolved.root;
11571
11605
  outDir = resolved.build.outDir;
11606
+ command = resolved.command;
11607
+ hmrWebSocketUrl = resolveHmrWebSocketUrl(resolved);
11572
11608
  },
11573
11609
  buildEnd(error) {
11574
11610
  if (error) {
@@ -11576,7 +11612,7 @@ function miniappManifest() {
11576
11612
  }
11577
11613
  },
11578
11614
  transformIndexHtml(html) {
11579
- return enforceMiniappHtmlPolicy(html);
11615
+ return enforceMiniappHtmlPolicy(html, command === 'serve' ? { hmrWebSocketUrl } : undefined);
11580
11616
  },
11581
11617
  async closeBundle() {
11582
11618
  // Rollup 在 buildStart/transform 失败后仍会调用 closeBundle。
@@ -11635,5 +11671,16 @@ function resolveSdkVersion() {
11635
11671
  }
11636
11672
  return packageJson.version;
11637
11673
  }
11674
+ function resolveHmrWebSocketUrl(resolved) {
11675
+ const hmr = resolved.server.hmr;
11676
+ if (hmr === false)
11677
+ return undefined;
11678
+ const options = typeof hmr === 'object' ? hmr : {};
11679
+ const protocol = options.protocol ?? 'ws';
11680
+ const configuredHost = options.host ?? resolved.server.host;
11681
+ const host = typeof configuredHost === 'string' && configuredHost !== '0.0.0.0' ? configuredHost : '127.0.0.1';
11682
+ const port = options.clientPort ?? options.port ?? resolved.server.port;
11683
+ return `${protocol}://${host}${port ? `:${port}` : ''}`;
11684
+ }
11638
11685
 
11639
11686
  exports.miniappManifest = miniappManifest;
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.6-alpha.2';
7
+ : '0.6.6-alpha.3';
8
8
 
9
9
  var re = {exports: {}};
10
10
 
@@ -11442,7 +11442,23 @@ const URL_ATTRIBUTES = {
11442
11442
  track: ['src'],
11443
11443
  video: ['src', 'poster'],
11444
11444
  };
11445
- function enforceMiniappHtmlPolicy(html) {
11445
+ const PRODUCTION_CSP = [
11446
+ "default-src 'none'",
11447
+ "connect-src 'none'",
11448
+ "script-src 'self' 'unsafe-inline'",
11449
+ "style-src 'self' 'unsafe-inline'",
11450
+ "img-src 'self' data: blob:",
11451
+ "font-src 'self' data:",
11452
+ "media-src 'self' blob:",
11453
+ "manifest-src 'self'",
11454
+ "frame-src 'none'",
11455
+ "child-src 'none'",
11456
+ "worker-src 'none'",
11457
+ "object-src 'none'",
11458
+ "form-action 'none'",
11459
+ "base-uri 'none'",
11460
+ ].join('; ');
11461
+ function enforceMiniappHtmlPolicy(html, options = {}) {
11446
11462
  const document = parse(html);
11447
11463
  const htmlElement = findElement(document, 'html');
11448
11464
  const head = findElement(htmlElement ?? document, 'head');
@@ -11452,6 +11468,22 @@ function enforceMiniappHtmlPolicy(html) {
11452
11468
  removePlatformCspMarkers(document);
11453
11469
  walk(document, element => validateElement(element));
11454
11470
  injectMiniappRuntimeGate(document);
11471
+ const content = options.hmrWebSocketUrl
11472
+ ? PRODUCTION_CSP.replace("connect-src 'none'", `connect-src ${options.hmrWebSocketUrl}`)
11473
+ : PRODUCTION_CSP;
11474
+ head.childNodes.unshift({
11475
+ nodeName: 'meta',
11476
+ tagName: 'meta',
11477
+ attrs: [
11478
+ { name: 'http-equiv', value: 'Content-Security-Policy' },
11479
+ { name: 'content', value: content },
11480
+ { name: 'data-heybox-platform-csp', value: '' },
11481
+ ],
11482
+ namespaceURI: 'http://www.w3.org/1999/xhtml',
11483
+ childNodes: [],
11484
+ parentNode: head,
11485
+ sourceCodeLocation: undefined,
11486
+ });
11455
11487
  return serialize(document);
11456
11488
  }
11457
11489
  function validateElement(element) {
@@ -11550,6 +11582,8 @@ const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
11550
11582
  function miniappManifest() {
11551
11583
  let root = process.cwd();
11552
11584
  let outDir = 'dist';
11585
+ let command = 'build';
11586
+ let hmrWebSocketUrl;
11553
11587
  /** 构建链路中更早的失败原因;closeBundle 不得再用产物校验覆盖它。 */
11554
11588
  let priorBuildError;
11555
11589
  return {
@@ -11566,6 +11600,8 @@ function miniappManifest() {
11566
11600
  configResolved(resolved) {
11567
11601
  root = resolved.root;
11568
11602
  outDir = resolved.build.outDir;
11603
+ command = resolved.command;
11604
+ hmrWebSocketUrl = resolveHmrWebSocketUrl(resolved);
11569
11605
  },
11570
11606
  buildEnd(error) {
11571
11607
  if (error) {
@@ -11573,7 +11609,7 @@ function miniappManifest() {
11573
11609
  }
11574
11610
  },
11575
11611
  transformIndexHtml(html) {
11576
- return enforceMiniappHtmlPolicy(html);
11612
+ return enforceMiniappHtmlPolicy(html, command === 'serve' ? { hmrWebSocketUrl } : undefined);
11577
11613
  },
11578
11614
  async closeBundle() {
11579
11615
  // Rollup 在 buildStart/transform 失败后仍会调用 closeBundle。
@@ -11632,5 +11668,16 @@ function resolveSdkVersion() {
11632
11668
  }
11633
11669
  return packageJson.version;
11634
11670
  }
11671
+ function resolveHmrWebSocketUrl(resolved) {
11672
+ const hmr = resolved.server.hmr;
11673
+ if (hmr === false)
11674
+ return undefined;
11675
+ const options = typeof hmr === 'object' ? hmr : {};
11676
+ const protocol = options.protocol ?? 'ws';
11677
+ const configuredHost = options.host ?? resolved.server.host;
11678
+ const host = typeof configuredHost === 'string' && configuredHost !== '0.0.0.0' ? configuredHost : '127.0.0.1';
11679
+ const port = options.clientPort ?? options.port ?? resolved.server.port;
11680
+ return `${protocol}://${host}${port ? `:${port}` : ''}`;
11681
+ }
11635
11682
 
11636
11683
  export { miniappManifest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk",
3
- "version": "0.6.6-alpha.2",
3
+ "version": "0.6.6-alpha.3",
4
4
  "sideEffects": [
5
5
  "./src/index.ts",
6
6
  "./src/core/singleton.ts",
package/skill/SKILL.md CHANGED
@@ -11,7 +11,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
11
11
 
12
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 startup, browser Mock, device debugging, CLI login, Agent Skill diagnosis, or CLI troubleshooting, use the `hb-sdk` CLI workflow.
14
+ 3. 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-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
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.
@@ -21,7 +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
- 4. For CLI commands, local debugging, device debugging, CLI login, Agent Skill doctor, and update reminders, read `references/cli.md`.
24
+ 4. For CLI commands, production builds, 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`.
@@ -45,30 +45,35 @@ Apply these instructions when writing, reviewing, or debugging code that consume
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
47
  7. Use the default SDK instance exposed by the root package.
48
+ 8. Use `share.showShareMenu({ post })` or `share.screenshot({ post })` to preset editable community destinations and topics. Pass partition IDs through `topicIds` and topic text without surrounding `#` through `topics`; do not construct the underlying client post protocol.
48
49
 
49
50
  ## Step 5: Use CLI workflows
50
51
 
51
52
  1. Use `hb-sdk create <project-name>` to scaffold a workshop mini-program.
52
53
  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
54
  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.
55
+ 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.
56
+ 5. Keep `miniappManifest()` explicitly enabled in `vite.config.ts`; `hb-sdk build` must fail when the required Manifest or Runtime gate output is missing.
57
+ 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.
58
+ 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`.
59
+ 8. 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.
60
+ 9. 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.
61
+ 10. 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.
62
+ 11. 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.
63
+ 12. Use `hb-sdk remote deploy --release-note <text>` to run the project's `scripts.build`, upload, and submit the current project for audit. Do not recommend the removed top-level `hb-sdk deploy` alias.
64
+ 13. After approval, use `hb-sdk remote release <version>` for manual release or `--auto-publish` when an eligible low-risk version should release automatically.
65
+ 14. Treat approval, release, and public display as separate states. Do not promise square, search, or recommendation visibility after release.
66
+ 15. 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.
67
+ 16. Use `--json` for remote script consumption and `--verbose` only when concise output is insufficient for diagnosis.
68
+ 17. Use `hb-sdk doctor` to diagnose whether the local Skill matches the installed SDK; follow its output to install or refresh the Skill.
69
+ 18. Do not print or expose cookies, tokens, private headers, or other credentials.
65
70
 
66
71
  ## Step 6: Preserve capability boundaries
67
72
 
68
73
  For workshop mini-program business code:
69
74
 
70
75
  1. Do not read or request tokens, cookies, phone numbers, or private credentials from the SDK.
71
- 2. Do not expose raw share protocol fields, JS callbacks, activity reporting, custom buttons, post publishing, or upload-only flows.
76
+ 2. 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.
72
77
  3. Do not use unsupported storage operations such as delete, clear, info listing, or global client storage access.
73
78
  4. Use only the public `network.request` configuration.
74
79
  5. Do not use private package paths or client protocols.
@@ -144,6 +144,7 @@ export type {
144
144
  MiniProgramScreenshotOptions,
145
145
  MiniProgramScreenshotRect,
146
146
  MiniProgramShareChannel,
147
+ MiniProgramSharePostOptions,
147
148
  MiniProgramShowShareMenuOptions,
148
149
  } from './modules/share';
149
150
  export type { GetStoragePayload, GetStorageResult, SetStoragePayload } from './modules/storage';
@@ -222,7 +223,7 @@ Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不
222
223
 
223
224
  | 导出面 | Classes | Functions | Interfaces | Types | Constants |
224
225
  | --- | ---: | ---: | ---: | ---: | ---: |
225
- | Root API | 2 | 3 | 66 | 57 | 0 |
226
- | Protocol API | 0 | 3 | 43 | 67 | 32 |
226
+ | Root API | 2 | 3 | 67 | 57 | 0 |
227
+ | Protocol API | 0 | 3 | 44 | 67 | 32 |
227
228
  | Miniapp Publish API | 0 | 5 | 2 | 0 | 0 |
228
229
  | Vite API | 0 | 1 | 0 | 0 | 0 |