@skillbuilder/miniapp-simulator 0.0.0-beta-20261023084421

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 (220) hide show
  1. package/README.md +214 -0
  2. package/assets/phones/Nexus-5X.png +0 -0
  3. package/assets/phones/iPhone-14ProMax.png +0 -0
  4. package/assets/rednote-preview/cover/homebar-1439.jpg +0 -0
  5. package/assets/rednote-preview/cover/homebar-1679.jpg +0 -0
  6. package/assets/rednote-preview/cover/homebar-1919.jpg +0 -0
  7. package/assets/rednote-preview/cover/homebar-2284.jpg +0 -0
  8. package/assets/rednote-preview/cover/homebar-2285.jpg +0 -0
  9. package/assets/rednote-preview/cover/like.png +0 -0
  10. package/assets/rednote-preview/cover/play.png +0 -0
  11. package/assets/rednote-preview/cover/topbar-1439.jpg +0 -0
  12. package/assets/rednote-preview/cover/topbar-1679.jpg +0 -0
  13. package/assets/rednote-preview/cover/topbar-1919.jpg +0 -0
  14. package/assets/rednote-preview/cover/topbar-2284.jpg +0 -0
  15. package/assets/rednote-preview/cover/topbar-2285.jpg +0 -0
  16. package/assets/workbench/index.html +77 -0
  17. package/dist/sw/miniapp-simulator-service-worker.js +855 -0
  18. package/dist/sw/miniapp-simulator-service-worker.min.js +1 -0
  19. package/docs/consumer-guide.md +143 -0
  20. package/docs/electron-review.md +21 -0
  21. package/docs/external-cli-workbench.md +197 -0
  22. package/docs/file-system-design.md +334 -0
  23. package/docs/host-external-api.md +235 -0
  24. package/docs/iframe-service-worker.md +190 -0
  25. package/docs/local-dev.md +106 -0
  26. package/docs/npm-integration-verification.md +45 -0
  27. package/docs/remote-architecture.md +403 -0
  28. package/docs/remote-load-observability.md +268 -0
  29. package/docs/remote-usage.md +371 -0
  30. package/docs/request-design.md +247 -0
  31. package/docs/sdk-usage.md +260 -0
  32. package/docs/server-playground-https-debugging.md +150 -0
  33. package/docs/storage-api-design.md +275 -0
  34. package/docs/tracker.md +339 -0
  35. package/lib/business-line-CMb3ehRn.mjs +15 -0
  36. package/lib/client-BZtD2VtP.mjs +772 -0
  37. package/lib/index-BW85h7kT.mjs +505 -0
  38. package/lib/index.js +10686 -0
  39. package/lib/preload/webview-preload.js +37 -0
  40. package/lib/remote-client.js +11 -0
  41. package/lib/types/business-line.d.ts +7 -0
  42. package/lib/types/capabilities/constants.d.ts +28 -0
  43. package/lib/types/capabilities/csp-snippet.d.ts +32 -0
  44. package/lib/types/capabilities/launch-options.d.ts +7 -0
  45. package/lib/types/capabilities/performance-policy.d.ts +5 -0
  46. package/lib/types/capabilities/security-head-snippet.d.ts +20 -0
  47. package/lib/types/capabilities/security.d.ts +25 -0
  48. package/lib/types/capabilities/style-snippet.d.ts +2 -0
  49. package/lib/types/core/controllers/game-playtest.d.ts +9 -0
  50. package/lib/types/core/controllers/gesture.d.ts +8 -0
  51. package/lib/types/core/controllers/host-api.d.ts +19 -0
  52. package/lib/types/core/controllers/index.d.ts +11 -0
  53. package/lib/types/core/controllers/inspector.d.ts +20 -0
  54. package/lib/types/core/controllers/note-preview.d.ts +9 -0
  55. package/lib/types/core/controllers/permission-sheet.d.ts +7 -0
  56. package/lib/types/core/controllers/widget-cover.d.ts +12 -0
  57. package/lib/types/core/lifecycle.d.ts +7 -0
  58. package/lib/types/core/options.d.ts +33 -0
  59. package/lib/types/core/simulator.d.ts +9 -0
  60. package/lib/types/errors.d.ts +11 -0
  61. package/lib/types/event-bus.d.ts +15 -0
  62. package/lib/types/gesture/host-bus.d.ts +113 -0
  63. package/lib/types/gesture/index.d.ts +27 -0
  64. package/lib/types/gesture/plugins/double-tap.d.ts +10 -0
  65. package/lib/types/gesture/plugins/index.d.ts +27 -0
  66. package/lib/types/gesture/plugins/long-press.d.ts +13 -0
  67. package/lib/types/gesture/plugins/multi-touch-hint.d.ts +11 -0
  68. package/lib/types/gesture/plugins/multi-touch-switch.d.ts +18 -0
  69. package/lib/types/gesture/plugins/selection-disabler.d.ts +11 -0
  70. package/lib/types/gesture/plugins/tap.d.ts +11 -0
  71. package/lib/types/gesture/plugins/touch-emitter.d.ts +11 -0
  72. package/lib/types/gesture/plugins/wheel-scroll.d.ts +11 -0
  73. package/lib/types/gesture/receiver-runtime.d.ts +10 -0
  74. package/lib/types/gesture/receiver-runtime.impl.d.ts +6 -0
  75. package/lib/types/gesture/touch-cursor.d.ts +78 -0
  76. package/lib/types/gesture/touch-dot.d.ts +12 -0
  77. package/lib/types/gesture/types.d.ts +206 -0
  78. package/lib/types/host/shadow-host.d.ts +40 -0
  79. package/lib/types/index.d.ts +49 -0
  80. package/lib/types/injection/guest-log-mark.d.ts +7 -0
  81. package/lib/types/injection/head-builder.d.ts +4 -0
  82. package/lib/types/injection/index.d.ts +19 -0
  83. package/lib/types/injection/modules/console-forward.d.ts +2 -0
  84. package/lib/types/injection/modules/gesture.d.ts +6 -0
  85. package/lib/types/injection/modules/inspector-guest-runtime.d.ts +5 -0
  86. package/lib/types/injection/modules/inspector-pause-runtime.d.ts +6 -0
  87. package/lib/types/injection/modules/inspector.d.ts +8 -0
  88. package/lib/types/injection/modules/jsapi-channel.d.ts +9 -0
  89. package/lib/types/injection/modules/jsapi.d.ts +22 -0
  90. package/lib/types/injection/modules/render-done.d.ts +2 -0
  91. package/lib/types/injection/modules/resource-guard.d.ts +7 -0
  92. package/lib/types/injection/modules/scroll-containment.d.ts +3 -0
  93. package/lib/types/injection/modules/security.d.ts +3 -0
  94. package/lib/types/injection/modules/widget-snapshot.d.ts +13 -0
  95. package/lib/types/injection/preload-builder.d.ts +41 -0
  96. package/lib/types/injection/registry.d.ts +20 -0
  97. package/lib/types/injection/types.d.ts +43 -0
  98. package/lib/types/inspector/host-inspector.d.ts +108 -0
  99. package/lib/types/inspector/index.d.ts +8 -0
  100. package/lib/types/inspector/selector.d.ts +18 -0
  101. package/lib/types/native-ui/devtools/CapabilitiesView.d.ts +18 -0
  102. package/lib/types/native-ui/devtools/DevtoolsPanel.d.ts +24 -0
  103. package/lib/types/native-ui/devtools/LogsView.d.ts +17 -0
  104. package/lib/types/native-ui/devtools/dom.d.ts +40 -0
  105. package/lib/types/native-ui/devtools/index.d.ts +19 -0
  106. package/lib/types/native-ui/devtools/log-entry.d.ts +8 -0
  107. package/lib/types/native-ui/devtools/shortcut.d.ts +12 -0
  108. package/lib/types/native-ui/devtools/tokens.d.ts +14 -0
  109. package/lib/types/native-ui/devtools/types.d.ts +51 -0
  110. package/lib/types/native-ui/index.d.ts +17 -0
  111. package/lib/types/native-ui/note-publish/defaults.d.ts +40 -0
  112. package/lib/types/native-ui/note-publish/index.d.ts +2 -0
  113. package/lib/types/native-ui/note-publish/miniapp-note-publish.d.ts +15 -0
  114. package/lib/types/native-ui/note-publish/note-publish-host.d.ts +15 -0
  115. package/lib/types/native-ui/note-publish/view-data.d.ts +21 -0
  116. package/lib/types/native-ui/permission-sheet/defaults.d.ts +12 -0
  117. package/lib/types/native-ui/permission-sheet/index.d.ts +4 -0
  118. package/lib/types/native-ui/permission-sheet/miniapp-permission-sheet.d.ts +19 -0
  119. package/lib/types/native-ui/permission-sheet/permission-sheet-host.d.ts +23 -0
  120. package/lib/types/native-ui/permission-sheet/types.d.ts +8 -0
  121. package/lib/types/native-ui/rednote-preview/chrome-tone.d.ts +44 -0
  122. package/lib/types/native-ui/rednote-preview/defaults.d.ts +30 -0
  123. package/lib/types/native-ui/rednote-preview/half-sheet-drag.d.ts +61 -0
  124. package/lib/types/native-ui/rednote-preview/index.d.ts +2 -0
  125. package/lib/types/native-ui/rednote-preview/register.d.ts +7 -0
  126. package/lib/types/native-ui/rednote-preview/styles.d.ts +4 -0
  127. package/lib/types/native-ui/rednote-preview/xhs-note-detail-shell.d.ts +70 -0
  128. package/lib/types/native-ui/rednote-preview/xhs-note-half-sheet.d.ts +100 -0
  129. package/lib/types/native-ui/rednote-preview/xhs-profile-shell.d.ts +31 -0
  130. package/lib/types/native-ui/toast/frame-toast-host.d.ts +18 -0
  131. package/lib/types/native-ui/toast/index.d.ts +19 -0
  132. package/lib/types/presets.d.ts +11 -0
  133. package/lib/types/remote/client.d.ts +89 -0
  134. package/lib/types/remote/jsapi-config.d.ts +9 -0
  135. package/lib/types/remote/load-timing.d.ts +46 -0
  136. package/lib/types/remote/protocol.d.ts +160 -0
  137. package/lib/types/remote/review-launch.d.ts +6 -0
  138. package/lib/types/remote/runtime-entry.d.ts +1 -0
  139. package/lib/types/remote/runtime.d.ts +14 -0
  140. package/lib/types/remote/simulator-prompt.d.ts +9 -0
  141. package/lib/types/remote/widget-snapshot-guest-runtime.d.ts +1 -0
  142. package/lib/types/remote-client.d.ts +5 -0
  143. package/lib/types/renderer/base.d.ts +8 -0
  144. package/lib/types/renderer/content-host/iframe-content-host.d.ts +83 -0
  145. package/lib/types/renderer/content-host/index.d.ts +3 -0
  146. package/lib/types/renderer/content-host/types.d.ts +89 -0
  147. package/lib/types/renderer/content-host/webview-content-host.d.ts +53 -0
  148. package/lib/types/renderer/iframe.d.ts +93 -0
  149. package/lib/types/renderer/index.d.ts +2 -0
  150. package/lib/types/renderer/rednote-shell.d.ts +73 -0
  151. package/lib/types/renderer/webview.d.ts +59 -0
  152. package/lib/types/runtime/context.d.ts +31 -0
  153. package/lib/types/runtime/jsapi-modules/context.d.ts +19 -0
  154. package/lib/types/runtime/jsapi-modules/filesystem.d.ts +19 -0
  155. package/lib/types/runtime/jsapi-modules/index.d.ts +9 -0
  156. package/lib/types/runtime/jsapi-modules/interaction.d.ts +4 -0
  157. package/lib/types/runtime/jsapi-modules/location.d.ts +3 -0
  158. package/lib/types/runtime/jsapi-modules/media.d.ts +13 -0
  159. package/lib/types/runtime/jsapi-modules/network.d.ts +3 -0
  160. package/lib/types/runtime/jsapi-modules/storage.d.ts +26 -0
  161. package/lib/types/runtime/jsapi-modules/system.d.ts +4 -0
  162. package/lib/types/runtime/jsapi-modules/types.d.ts +21 -0
  163. package/lib/types/runtime/jsapi-modules/window-info.d.ts +43 -0
  164. package/lib/types/runtime/request/host-request.d.ts +13 -0
  165. package/lib/types/runtime/request/request-manager-frame.d.ts +29 -0
  166. package/lib/types/runtime/request/request-runtime.d.ts +26 -0
  167. package/lib/types/runtime/request/request-types.d.ts +26 -0
  168. package/lib/types/runtime/request/sse-text-framer.d.ts +16 -0
  169. package/lib/types/seal-config.d.ts +134 -0
  170. package/lib/types/sw/index.d.ts +9 -0
  171. package/lib/types/sw/parse-raw.d.ts +34 -0
  172. package/lib/types/sw/protocol.d.ts +17 -0
  173. package/lib/types/sw/served-entry.d.ts +9 -0
  174. package/lib/types/sw/service-worker-content-host.d.ts +11 -0
  175. package/lib/types/sw/service-worker-host.d.ts +73 -0
  176. package/lib/types/sw/service-worker-renderer.d.ts +10 -0
  177. package/lib/types/sw/worker/fs-codec.d.ts +23 -0
  178. package/lib/types/sw/worker/fs-ops.d.ts +22 -0
  179. package/lib/types/sw/worker/fs-store.d.ts +29 -0
  180. package/lib/types/sw/worker/globals.d.ts +49 -0
  181. package/lib/types/sw/worker/main.d.ts +6 -0
  182. package/lib/types/sw/worker/mime.d.ts +2 -0
  183. package/lib/types/sw/worker/mount-store.d.ts +43 -0
  184. package/lib/types/sw/worker/paths.d.ts +4 -0
  185. package/lib/types/sw/worker/serve.d.ts +13 -0
  186. package/lib/types/tracker/constants.d.ts +14 -0
  187. package/lib/types/tracker/default-tracker.d.ts +19 -0
  188. package/lib/types/tracker/index.d.ts +70 -0
  189. package/lib/types/transport/bridge-protocol.d.ts +78 -0
  190. package/lib/types/transport/iframe-transport.d.ts +39 -0
  191. package/lib/types/transport/index.d.ts +14 -0
  192. package/lib/types/transport/jsapi-bridge-messages.d.ts +36 -0
  193. package/lib/types/transport/types.d.ts +48 -0
  194. package/lib/types/transport/webview-transport.d.ts +52 -0
  195. package/lib/types/types/events.d.ts +130 -0
  196. package/lib/types/types/index.d.ts +11 -0
  197. package/lib/types/types/inspector.d.ts +172 -0
  198. package/lib/types/types/jsapi.d.ts +18 -0
  199. package/lib/types/types/options.d.ts +844 -0
  200. package/lib/types/types/renderer.d.ts +145 -0
  201. package/lib/types/utils/ancestor-scroll.d.ts +11 -0
  202. package/lib/types/utils/error-svg.d.ts +12 -0
  203. package/lib/types/utils/frameless-shell.d.ts +114 -0
  204. package/lib/types/utils/miniapp-chrome-svg.d.ts +47 -0
  205. package/lib/types/utils/package-constants.d.ts +8 -0
  206. package/lib/types/utils/screenshot.d.ts +14 -0
  207. package/lib/types/utils/simulator-pc-guard.d.ts +10 -0
  208. package/lib/types/utils/stage-fit.d.ts +6 -0
  209. package/lib/types/utils/touch-emulate.d.ts +26 -0
  210. package/lib/types/utils/zip-entry.d.ts +13 -0
  211. package/lib/types/workbench/index.d.ts +63 -0
  212. package/lib/types/workbench/preview-transition.d.ts +8 -0
  213. package/lib/types/workbench/server/artifact.d.ts +8 -0
  214. package/lib/types/workbench/server/index.d.ts +19 -0
  215. package/lib/types/workbench/server/watch.d.ts +6 -0
  216. package/lib/types/workbench/view.d.ts +36 -0
  217. package/lib/workbench-server.mjs +183 -0
  218. package/lib/workbench.js +1404 -0
  219. package/package.json +63 -0
  220. package/scripts/mock-cli-dev.mjs +52 -0
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # @skillbuilder/miniapp-simulator
2
+
3
+ 技术栈无关的小应用 PC 模拟器 SDK,支持 iframe 预览和 Electron webview 审核场景。
4
+ 模拟器默认**无贴图外壳**(`phoneFrame: false`),保留创作发布标准深色圆角设备边框;需要 iPhone / Nexus 贴图壳时显式传 `phoneFrame`。默认开启 `stageFit` 自适应撑满挂载区域;手动拖拽缩放需传 `stageFit: { resizeHandle: true }`。
5
+
6
+ ```bash
7
+ pnpm --filter @skillbuilder/miniapp-simulator run playground
8
+ ```
9
+
10
+ Smoke 联调:`testsuits/miniapp-simulator-sdk-smoke` 以 ESM `import` 引用本包 `lib/`;改源码后 `pnpm --filter @skillbuilder/miniapp-simulator run build:npm`,再 `pnpm --filter miniapp-simulator-sdk-smoke dev` 即可。
11
+
12
+ **设备能力封印**由本包自维护:封印 IIFE 以本地文件形式存放在
13
+ `src/injection/modules/device-capabilities-seal.iife.min.js`,注入时以 `?raw` 引入(更新封印时替换该文件即可)。
14
+
15
+ 兼容性基线:iOS WKWebView (iOS 13+) / Android WebView (Chrome 49+) / 现代 PC 浏览器。
16
+
17
+ **按业务灵活放开能力**(白名单语义):
18
+
19
+ ```ts
20
+ import { createMiniAppSimulator, MiniAppCapability } from "@skillbuilder/miniapp-simulator";
21
+
22
+ createMiniAppSimulator({
23
+ deviceCapabilities: {
24
+ sealAllow: [
25
+ MiniAppCapability.Camera,
26
+ MiniAppCapability.Microphone,
27
+ MiniAppCapability.PhotoLibrary,
28
+ // 后续要放开定位时只追加这一行:
29
+ // MiniAppCapability.Geolocation,
30
+ ],
31
+ },
32
+ });
33
+ ```
34
+
35
+ `sealAllow` 不传 → 等价于 `[Camera, Microphone, PhotoLibrary]`;`sealAllow: []` → 严格模式全封禁。Android / iOS 注入路径见 `docs/local-dev.md`。
36
+
37
+ **支持的能力已枚举化对外**,可直接用于配置面板 / 校验(由本包自维护,`src/seal-config.ts`):
38
+
39
+ ```ts
40
+ import {
41
+ MINI_APP_CAPABILITIES, // 全量能力元数据(value / controlledBy / description / permissionNames)
42
+ SEAL_CONTROLLED_CAPABILITIES, // 受 sealAllow 白名单实际控制的能力
43
+ isMiniAppCapability,
44
+ sanitizeCapabilityList,
45
+ } from "@skillbuilder/miniapp-simulator";
46
+ ```
47
+
48
+ ## 快速接入
49
+
50
+ ```ts
51
+ import { createMiniAppSimulator } from "@skillbuilder/miniapp-simulator";
52
+
53
+ // 1) 创建实例(mount 为 CSS 选择器或 HTMLElement;create 只管配置,不传入口)
54
+ const simulator = createMiniAppSimulator({
55
+ mount: "#preview",
56
+ viewport: { width: 390, height: 844 },
57
+ });
58
+
59
+ // 2) 加载入口(三选一):远程 URL / .zip 包 / 目录文件表
60
+ await simulator.loadApp("https://cdn.../index.html", { query: { versionId: "v2" } });
61
+ ```
62
+
63
+ ## DOM / Canvas 场景对象 Visual Inspector
64
+
65
+ Visual Inspector 统一输出 DOM 与 PixiJS、Three.js、自定义 Canvas 场景对象。DOM 继续兼容
66
+ `elementSelected`;新消费方应订阅 `visualSelected` / `visualSelectionChange`,并通过
67
+ `getSceneTree()` 与 `selectByRef()` 实现 Viewport、Hierarchy、Inspector 双向联动:
68
+
69
+ ```ts
70
+ simulator.on("visualSelected", (selection) => {
71
+ if (selection.kind === "scene") {
72
+ console.log(selection.engine, selection.nodePath, selection.properties, selection.source);
73
+ }
74
+ });
75
+
76
+ const tree = await simulator.inspector.getSceneTree();
77
+ const firstSceneNode = tree.providers[0]?.roots[0]?.children[0];
78
+ if (firstSceneNode) await simulator.inspector.selectByRef(firstSceneNode.ref);
79
+ ```
80
+
81
+ 场景 Provider 由小应用模板主动注册;Provider 缺失或失败时仍会降级为普通 canvas DOM
82
+ 选择。普通预览默认不代理页面调度器;明确的 2D / 3D 游戏由上游传入
83
+ `visualInspector: { pauseRuntime: true }`。此时进入选取模式会冻结 RAF、timer、CSS 动画与媒体,
84
+ 并调用 Provider 可选的 `pause()`;退出时按原状态恢复,因此运动对象可以稳定命中。
85
+ 完整职责、协议和分期见
86
+ [`design/mini-app/mini-app-visual-inspector-design.md`](./design/mini-app/mini-app-visual-inspector-design.md)。
87
+
88
+ 独立验证 2D / 3D 场景圈选:
89
+
90
+ ```bash
91
+ pnpm --filter @skillbuilder/miniapp-simulator demo:inspector
92
+ ```
93
+
94
+ 打开 `http://127.0.0.1:5181`,可手动点击运动元素,也可运行层级读取和反向选择 Case。
95
+
96
+ 独立验证 AI 对话 Bridge(非流式完整消息与流式增量渲染):
97
+
98
+ ```bash
99
+ pnpm --filter @skillbuilder/miniapp-simulator demo:ai
100
+ ```
101
+
102
+ 打开 `http://127.0.0.1:5182`,两个 Case 会自动运行并展示业务层最终渲染结果。
103
+
104
+ ## 加载 .zip 应用包
105
+
106
+ 实例方法 `loadZip` 自动完成「解压 → 解析 `manifest.json` → 内联相对资源 → 建 blob URL 加载」,
107
+ 入参支持 `Blob | File | ArrayBuffer | Uint8Array`:
108
+
109
+ ```ts
110
+ import { createMiniAppSimulator } from "@skillbuilder/miniapp-simulator";
111
+ import JSZip from "jszip"; // 或在全局挂载 window.JSZip(CDN / UMD)
112
+
113
+ const simulator = createMiniAppSimulator({ mount: "#preview" });
114
+ await simulator.load();
115
+
116
+ // 拖拽 / 选择得到的 .zip File 直接喂入;返回包元信息(文件清单 + manifest 解析结果)
117
+ const result = await simulator.loadZip(zipFile, { jszip: JSZip });
118
+ console.log(result.files, result.manifest.window, result.manifest.warnings);
119
+ ```
120
+
121
+ > 本包**技术栈无关**、不强依赖 JSZip:通过 `loadZip(source, { jszip })` 传入 JSZip 兼容对象,
122
+ > 或在全局挂载 `window.JSZip`(不传时自动回退);二者皆缺失会抛出 `ZIP_LOAD_FAILED`。
123
+
124
+ 更多说明见:
125
+
126
+ - [`docs/remote-architecture.md`](./docs/remote-architecture.md):远程模式架构、版本发布、动态更新与隔离边界
127
+ - [`docs/remote-usage.md`](./docs/remote-usage.md):远程模式接入、实例 API、Host API 与多实例用法
128
+ - [`docs/server-playground-https-debugging.md`](./docs/server-playground-https-debugging.md):Server Playground 本地 HTTPS、证书信任与 Creator AI 独立泳道联调
129
+ - [`docs/external-cli-workbench.md`](./docs/external-cli-workbench.md):外部 CLI 的 `xxx dev` 参数与本地托管契约
130
+ - `docs/sdk-usage.md`
131
+ - `docs/local-dev.md`
132
+ - `docs/electron-review.md`
133
+
134
+ ## 外部 AI 调试工作台
135
+
136
+ `@skillbuilder/miniapp-simulator/workbench` 在现有 Simulator 外增加一层轻量工作台壳,面向
137
+ Codex、CodeBuddy 和本地 CLI 展示运行状态、诊断事件、重新加载与截图入口。它不会改变 Simulator
138
+ 的加载、渲染或调试协议:调用方仍可通过 `workbench.simulator` 使用完整 SDK 能力。
139
+
140
+ ```ts
141
+ import { createMiniAppWorkbench } from "@skillbuilder/miniapp-simulator/workbench";
142
+ import { BusinessLine } from "@skillbuilder/miniapp-simulator/remote";
143
+
144
+ const workbench = createMiniAppWorkbench({
145
+ mount: "#app",
146
+ projectName: "demo-minitool",
147
+ viewport: { width: 393, height: 852 },
148
+ remote: {
149
+ serviceUrl: "https://miniapp-sandbox.beta.xiaohongshu.com/simulator/",
150
+ appId: "demo-minitool",
151
+ businessLine: BusinessLine.skillDesignable,
152
+ },
153
+ });
154
+
155
+ // 本地 Agent 调试使用目录文件表,不需要 ZIP。
156
+ await workbench.loadFiles({
157
+ "index.html": htmlText,
158
+ "main.js": scriptText,
159
+ "logo.png": pngBytes,
160
+ }, { entry: "index.html" });
161
+ ```
162
+
163
+ 工作台使用宿主侧薄 SDK 连接 Simulator Server:薄 SDK 通过 `runtime-manifest` 动态选择远端 Runtime,
164
+ Runtime 再注册同源、版本化的 Service Worker。CLI 不复制或托管 Runtime / SW,也不直接执行小工具代码。
165
+
166
+ 包内同时提供 `@skillbuilder/miniapp-simulator/workbench.html` 静态入口,供 CLI 等本地服务直接托管;
167
+ 页面结构、样式和 Simulator 编排均由本包维护。
168
+
169
+ CLI 可直接调用独立的 Node 服务入口,传入调试根目录即可启动完整工作台:
170
+
171
+ ```ts
172
+ import { startWorkbenchServer } from "@skillbuilder/miniapp-simulator/workbench/server";
173
+
174
+ const server = await startWorkbenchServer({ rootDir: "./dist" });
175
+ console.log(server.url);
176
+ // CLI 退出时调用 await server.close()。
177
+ ```
178
+
179
+ Node 入口统一负责 HTML 入口识别、文件清单与原始资源托管,工作台通过 `loadFiles()` 加载目录文件,
180
+ 继续经 Remote SDK 连接远端 Runtime / SW。根目录及子目录中的 HTML、JS、CSS 变化会自动重载小工具,
181
+ 无需重启服务或手动刷新;“重新运行”仍可手动触发。连续写入会合并,重载期间的新变更会串行处理。
182
+
183
+ 工作台固定使用 SDK 的 `rednote` 壳层,保留状态栏、返回等原生控件。支持全屏小工具、半屏小工具、笔记页、个人页四种场景,设备尺寸独立切换。
184
+ 可通过工作台控件或 `workbench.setScene("half")` 切换;文件更新后保持当前选定场景。
185
+
186
+ 仓库内可用 Mock 脚本模拟另一套 CLI 的调用:
187
+
188
+ ```shell
189
+ pnpm --filter @skillbuilder/miniapp-simulator mock:cli-dev -- \
190
+ --dir /absolute/path/to/minitool/dist
191
+ ```
192
+
193
+ 外部 CLI 只需直接安装本包:`--dir` 对应 Node 入口的 `rootDir`,`--no-open` 由 CLI 自己控制打开浏览器,`-h` / `--help` 输出帮助。
194
+ 设备、场景、入口识别和文件监听由工作台处理;完整参数与职责见 [`external-cli-workbench.md`](./docs/external-cli-workbench.md)。
195
+
196
+ 发布前运行 `pnpm --filter @skillbuilder/miniapp-simulator test:package`,会真实打包并在仓库外从 tarball 安装,验证导出、类型和本地服务。
197
+ `prepack` 自动执行本地构建;不执行上传或发布。Runtime / SW 仍从远程服务动态加载,外网可达性需单独验收。
198
+ 当前验证范围及外发门禁见 [`npm-integration-verification.md`](./docs/npm-integration-verification.md)。
199
+
200
+ ### 仅发布模拟器 npm(仓库根目录执行)
201
+
202
+ ```shell
203
+ pnpm release:simulator snapshot --registry public --dry-run # 构建、打包、检查,不发布
204
+ pnpm release:simulator snapshot --registry public # beta 快照,仅发布本包
205
+ pnpm release:simulator stable --registry public # 当前版本 → latest
206
+ pnpm release:simulator snapshot --registry internal # 同样支持内部源
207
+ ```
208
+
209
+ 默认源为 `public`,也支持 `--registry <url>`。真实发布需最终确认,CI 显式传 `--yes`。
210
+ 正式版沿用本包版本,且只允许在 `release/release_*` 分支发布;快照版本仅写入临时目录,不修改仓库版本、lockfile 或 changeset。
211
+ 构建依赖 `endpoints` 不发布;脚本不执行全仓构建或 CDN 上传,外部运行依赖出现内部包时会阻断发布。
212
+ 真实发布成功后向现有两个机器人发送版本与安装命令;dry-run 不发送通知,通知失败只告警、不重试发布。
213
+ 发布归档会移除开发依赖、构建/发布脚本与源覆盖配置;dry-run 产物及清单保留在打印的临时目录中。
214
+ 该脚本不替代包内文档/资源的外发审查、npm scope 发布权限或远程 Runtime / SW 外网可达性验收。
Binary file
@@ -0,0 +1,77 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>小红书小工具 · 本地调试工作台</title>
7
+ <style>
8
+ html,
9
+ body,
10
+ #workbench {
11
+ width: 100%;
12
+ height: 100%;
13
+ margin: 0;
14
+ overflow: hidden;
15
+ }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div id="workbench"></div>
20
+ <script type="module">
21
+ async function fetchResource(url, init) {
22
+ const response = await fetch(url, { cache: "no-store", ...init });
23
+ if (!response.ok) throw new Error(`${url} 加载失败:HTTP ${response.status}`);
24
+ return response;
25
+ }
26
+
27
+ async function start() {
28
+ const config = await fetchResource("/__miniapp_workbench__/config.json").then((response) =>
29
+ response.json(),
30
+ );
31
+ if (config.artifact.type !== "files") {
32
+ throw new Error(`不支持的产物类型:${config.artifact.type}`);
33
+ }
34
+ const loadLocalFiles = async () => {
35
+ const { entry, files } = await fetchResource(config.artifact.url).then((response) =>
36
+ response.json(),
37
+ );
38
+ const entries = await Promise.all(
39
+ files.map(async (file) => {
40
+ const url =
41
+ config.artifact.baseUrl + file.split("/").map(encodeURIComponent).join("/");
42
+ const content = await fetchResource(url).then((response) => response.arrayBuffer());
43
+ return [file, content];
44
+ }),
45
+ );
46
+ await workbench.loadFiles(Object.fromEntries(entries), { entry });
47
+ };
48
+ const { createMiniAppWorkbench } = await import(config.sdkUrl);
49
+ const workbench = createMiniAppWorkbench({
50
+ mount: "#workbench",
51
+ projectName: config.projectName,
52
+ viewport: config.viewport,
53
+ remote: config.remote,
54
+ onReload: loadLocalFiles,
55
+ });
56
+ window.__MINIAPP_WORKBENCH__ = workbench;
57
+
58
+ const changes = new EventSource(config.artifact.eventsUrl);
59
+ changes.addEventListener("reload", () => void workbench.reload());
60
+ changes.addEventListener("watch-error", (event) =>
61
+ console.error("[miniapp-workbench]", event.data),
62
+ );
63
+ window.addEventListener("beforeunload", () => changes.close(), { once: true });
64
+ }
65
+
66
+ start().catch((error) => {
67
+ console.error("[miniapp-workbench]", error);
68
+ if (window.__MINIAPP_WORKBENCH__) return;
69
+ const mount = document.querySelector("#workbench");
70
+ if (!mount) return;
71
+ mount.style.cssText =
72
+ "display:grid;place-items:center;padding:24px;box-sizing:border-box;background:#f5f6f8;color:#34353a;font:13px/1.6 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif";
73
+ mount.textContent = `工作台启动失败:${error instanceof Error ? error.message : String(error)}`;
74
+ });
75
+ </script>
76
+ </body>
77
+ </html>