@binblink/wasmnest-plugin-sdk-desktop 0.0.0-stage → 0.0.2

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 (271) hide show
  1. package/README.md +307 -2
  2. package/README_en.md +284 -0
  3. package/bin/cli.js +602 -0
  4. package/bin/manifest-gen.js +458 -0
  5. package/bin/manifest-validate.js +494 -0
  6. package/bin/permission-vocabulary.json +5 -0
  7. package/bin/plugin-watch.js +331 -0
  8. package/bin/wasm-hash.js +124 -0
  9. package/dev-shell/README.md +122 -0
  10. package/dev-shell/index.html +12 -0
  11. package/dev-shell/package.json +28 -0
  12. package/dev-shell/pnpm-workspace.yaml +9 -0
  13. package/dev-shell/postcss.config.js +6 -0
  14. package/dev-shell/src/App.vue +90 -0
  15. package/dev-shell/src/components/LogPanel.vue +90 -0
  16. package/dev-shell/src/loader.ts +104 -0
  17. package/dev-shell/src/locale.ts +29 -0
  18. package/dev-shell/src/locales.ts +50 -0
  19. package/dev-shell/src/main.ts +46 -0
  20. package/dev-shell/src/mock/app-env.ts +102 -0
  21. package/dev-shell/src/mock/commands.ts +54 -0
  22. package/dev-shell/src/mock/domain-context.ts +46 -0
  23. package/dev-shell/src/mock/events.ts +16 -0
  24. package/dev-shell/src/mock/file-transfer.ts +512 -0
  25. package/dev-shell/src/mock/tauri-ipc.ts +109 -0
  26. package/dev-shell/src/registry.ts +90 -0
  27. package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
  28. package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
  29. package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
  30. package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
  31. package/dev-shell/src/shell/mount/appSession.ts +45 -0
  32. package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
  33. package/dev-shell/src/shell/types.ts +121 -0
  34. package/dev-shell/src/styles/dev.css +27 -0
  35. package/dev-shell/src/styles/shell.css +752 -0
  36. package/dev-shell/src/styles/style.css +1178 -0
  37. package/dev-shell/src/theme.ts +140 -0
  38. package/dev-shell/src/vite-env.d.ts +24 -0
  39. package/dev-shell/tailwind.config.js +98 -0
  40. package/dev-shell/vite.config.ts +174 -0
  41. package/dist/index.d.ts +150 -0
  42. package/dist/index.js +238 -0
  43. package/dist/types.d.ts +632 -0
  44. package/dist/types.js +0 -0
  45. package/dist/vite-plugin.d.ts +25 -0
  46. package/dist/vite-plugin.js +80 -0
  47. package/go/.gitignore +5 -0
  48. package/go/README.md +80 -0
  49. package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
  50. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
  51. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
  52. package/go/gen/wasmnest/app/host-app/empty.s +3 -0
  53. package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
  54. package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
  55. package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
  56. package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
  57. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
  58. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
  59. package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
  60. package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
  61. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
  62. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
  63. package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
  64. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
  65. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
  66. package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
  67. package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
  68. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
  69. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
  70. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
  71. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
  72. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
  73. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
  74. package/go/gen/wasmnest/http/host-http/abi.go +14 -0
  75. package/go/gen/wasmnest/http/host-http/empty.s +3 -0
  76. package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
  77. package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
  78. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
  79. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
  80. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
  81. package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
  82. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
  83. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
  84. package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
  85. package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
  86. package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
  87. package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
  88. package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
  89. package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
  90. package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
  91. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
  92. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
  93. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
  94. package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
  95. package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
  96. package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
  97. package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
  98. package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
  99. package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
  100. package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
  101. package/go/gen/wasmnest/plugin/command/empty.s +3 -0
  102. package/go/gen/wasmnest/plugin/events/empty.s +3 -0
  103. package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
  104. package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
  105. package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
  106. package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
  107. package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
  108. package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
  109. package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
  110. package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
  111. package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
  112. package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
  113. package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
  114. package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
  115. package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
  116. package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
  117. package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
  118. package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
  119. package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
  120. package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
  121. package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
  122. package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
  123. package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
  124. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
  125. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
  126. package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
  127. package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
  128. package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
  129. package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
  130. package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
  131. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
  132. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
  133. package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
  134. package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
  135. package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
  136. package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
  137. package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
  138. package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
  139. package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
  140. package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
  141. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
  142. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
  143. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
  144. package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
  145. package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
  146. package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
  147. package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
  148. package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
  149. package/go/gen/wasmnest/process/host-process/empty.s +3 -0
  150. package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
  151. package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
  152. package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
  153. package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
  154. package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
  155. package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
  156. package/go/gen/wasmnest/task/host-task/abi.go +14 -0
  157. package/go/gen/wasmnest/task/host-task/empty.s +3 -0
  158. package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
  159. package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
  160. package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
  161. package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
  162. package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
  163. package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
  164. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
  165. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
  166. package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
  167. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
  168. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
  169. package/go/go.mod +14 -0
  170. package/go/go.sum +2 -0
  171. package/go/sdk/dispatch.go +49 -0
  172. package/go/sdk/dispatch_test.go +81 -0
  173. package/go/sdk/entry_native.go +13 -0
  174. package/go/sdk/entry_wasip2.go +188 -0
  175. package/go/sdk/host_http_wasip2.go +42 -0
  176. package/go/sdk/host_wasip2.go +251 -0
  177. package/go/sdk/plugin.go +103 -0
  178. package/go/testplugin/index.js +1 -0
  179. package/go/testplugin/main.go +67 -0
  180. package/go/testplugin/plugin.json +24 -0
  181. package/go/tools/assemble-wit.mjs +152 -0
  182. package/go/tools/gen-bindings.mjs +51 -0
  183. package/go/wit/core.wit +273 -0
  184. package/go/wit/deps/api-call/cap-api-call.wit +20 -0
  185. package/go/wit/deps/app/cap-app.wit +54 -0
  186. package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
  187. package/go/wit/deps/clipboard/clipboard.wit +48 -0
  188. package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
  189. package/go/wit/deps/clocks/wall-clock.wit +42 -0
  190. package/go/wit/deps/clocks/world.wit +6 -0
  191. package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
  192. package/go/wit/deps/crypto/cap-crypto.wit +68 -0
  193. package/go/wit/deps/filesystem/preopens.wit +8 -0
  194. package/go/wit/deps/filesystem/types.wit +634 -0
  195. package/go/wit/deps/filesystem/world.wit +6 -0
  196. package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
  197. package/go/wit/deps/http/http.wit +28 -0
  198. package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
  199. package/go/wit/deps/io/error.wit +34 -0
  200. package/go/wit/deps/io/poll.wit +41 -0
  201. package/go/wit/deps/io/streams.wit +262 -0
  202. package/go/wit/deps/io/world.wit +6 -0
  203. package/go/wit/deps/mdns/mdns.wit +45 -0
  204. package/go/wit/deps/notify/notify.wit +51 -0
  205. package/go/wit/deps/peer/peer.wit +126 -0
  206. package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
  207. package/go/wit/deps/process/cap-process.wit +25 -0
  208. package/go/wit/deps/pty/pty.wit +80 -0
  209. package/go/wit/deps/random/insecure-seed.wit +25 -0
  210. package/go/wit/deps/random/insecure.wit +22 -0
  211. package/go/wit/deps/random/random.wit +26 -0
  212. package/go/wit/deps/random/world.wit +7 -0
  213. package/go/wit/deps/sockets/instance-network.wit +9 -0
  214. package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
  215. package/go/wit/deps/sockets/network.wit +145 -0
  216. package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
  217. package/go/wit/deps/sockets/tcp.wit +353 -0
  218. package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
  219. package/go/wit/deps/sockets/udp.wit +266 -0
  220. package/go/wit/deps/sockets/world.wit +11 -0
  221. package/go/wit/deps/task/cap-task.wit +56 -0
  222. package/go/wit/deps/timer/cap-timer.wit +14 -0
  223. package/go/wit/deps/wasi-cli/command.wit +7 -0
  224. package/go/wit/deps/wasi-cli/environment.wit +18 -0
  225. package/go/wit/deps/wasi-cli/exit.wit +4 -0
  226. package/go/wit/deps/wasi-cli/imports.wit +20 -0
  227. package/go/wit/deps/wasi-cli/run.wit +4 -0
  228. package/go/wit/deps/wasi-cli/stdio.wit +17 -0
  229. package/go/wit/deps/wasi-cli/terminal.wit +49 -0
  230. package/go/wit/deps/ws/ws.wit +50 -0
  231. package/go/wit/deps/ws-server/cap-ws.wit +99 -0
  232. package/go/wit/go-plugin.wit +28 -0
  233. package/go/wit/plugin-face.wit +355 -0
  234. package/go/wit/wasmnest.wit +25 -0
  235. package/package.json +100 -3
  236. package/src/config.ts +49 -0
  237. package/src/global-dialog.ts +169 -0
  238. package/src/index.ts +88 -0
  239. package/src/runtime.ts +54 -0
  240. package/src/types.ts +681 -0
  241. package/src/ui/AppUpdateSection.d.ts +44 -0
  242. package/src/ui/AppUpdateSection.vue +253 -0
  243. package/src/ui/MarkdownEditor.vue +520 -0
  244. package/src/ui/NumberField.d.ts +49 -0
  245. package/src/ui/NumberField.vue +390 -0
  246. package/src/ui/PluginGlobalDialog.vue +401 -0
  247. package/src/ui/Select.d.ts +36 -0
  248. package/src/ui/Select.vue +220 -0
  249. package/src/ui/TerminalInputRail.vue +184 -0
  250. package/src/ui/apply-select-position.ts +65 -0
  251. package/src/ui/markdown-editor-syntax.ts +234 -0
  252. package/src/ui/markdown-editor.d.ts +36 -0
  253. package/src/ui/plugin-global-dialog.d.ts +12 -0
  254. package/src/ui/select-position.ts +79 -0
  255. package/src/ui/terminal-input-rail.d.ts +30 -0
  256. package/src/ui/zoom-compensation.d.ts +9 -0
  257. package/src/ui/zoom-compensation.ts +52 -0
  258. package/src/update.ts +123 -0
  259. package/src/vite-plugin.ts +124 -0
  260. package/template/README.md +39 -0
  261. package/template/package.json +23 -0
  262. package/template/plugin.json +14 -0
  263. package/template/rust/Cargo.toml +21 -0
  264. package/template/rust/src/lib.rs +39 -0
  265. package/template/src/env.d.ts +24 -0
  266. package/template/src/index.ts +37 -0
  267. package/template/tsconfig.json +17 -0
  268. package/template/vite.config.ts +21 -0
  269. package/tools/componentize/Cargo.lock +299 -0
  270. package/tools/componentize/Cargo.toml +18 -0
  271. package/tools/componentize/src/main.rs +197 -0
@@ -0,0 +1,80 @@
1
+ // src/vite-plugin.ts
2
+ import MagicString from "magic-string";
3
+ var SHARED_MODULES = {
4
+ vue: 'window.__WASMNEST_SHARED__["vue"]',
5
+ "vue-i18n": 'window.__WASMNEST_SHARED__["vue-i18n"]',
6
+ pinia: 'window.__WASMNEST_SHARED__["pinia"]',
7
+ "vue-sonner": 'window.__WASMNEST_SHARED__["vue-sonner"]'
8
+ };
9
+ function wasmnestPlugin() {
10
+ const externalModules = Object.keys(SHARED_MODULES);
11
+ return {
12
+ name: "wasmnest-shared-modules",
13
+ enforce: "pre",
14
+ // 注入 rollup external 配置
15
+ config(config) {
16
+ const existingExternal = config.build?.rollupOptions?.external;
17
+ const externalArray = Array.isArray(existingExternal) ? existingExternal : typeof existingExternal === "string" ? [existingExternal] : [];
18
+ return {
19
+ build: {
20
+ rollupOptions: {
21
+ external: [...externalArray, ...externalModules]
22
+ }
23
+ }
24
+ };
25
+ },
26
+ // 构建后替换 import 为全局变量读取
27
+ renderChunk(code, chunk) {
28
+ let modified = false;
29
+ const s = new MagicString(code);
30
+ for (const [modName, globalExpr] of Object.entries(SHARED_MODULES)) {
31
+ const escapedName = modName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
32
+ const defaultRe = new RegExp(`import\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`, "gm");
33
+ let match;
34
+ while ((match = defaultRe.exec(code)) !== null) {
35
+ const varName = match[1];
36
+ s.overwrite(
37
+ match.index,
38
+ match.index + match[0].length,
39
+ `const ${varName} = ${globalExpr}`
40
+ );
41
+ modified = true;
42
+ }
43
+ const namedRe = new RegExp(
44
+ `import\\s*\\{([^}]+)\\}\\s*from\\s+['"]${escapedName}['"]`,
45
+ "gm"
46
+ );
47
+ while ((match = namedRe.exec(code)) !== null) {
48
+ const imports = match[1];
49
+ s.overwrite(
50
+ match.index,
51
+ match.index + match[0].length,
52
+ `const { ${imports} } = ${globalExpr}`
53
+ );
54
+ modified = true;
55
+ }
56
+ const namespaceRe = new RegExp(
57
+ `import\\s+\\*\\s+as\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`,
58
+ "gm"
59
+ );
60
+ while ((match = namespaceRe.exec(code)) !== null) {
61
+ const varName = match[1];
62
+ s.overwrite(
63
+ match.index,
64
+ match.index + match[0].length,
65
+ `const ${varName} = ${globalExpr}`
66
+ );
67
+ modified = true;
68
+ }
69
+ }
70
+ if (!modified) return null;
71
+ return {
72
+ code: s.toString(),
73
+ map: s.generateMap({ hires: true })
74
+ };
75
+ }
76
+ };
77
+ }
78
+ export {
79
+ wasmnestPlugin
80
+ };
package/go/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ # 派生产物(gen-bindings.mjs 组装:rust/wit 拼装件 + wit-src/go-plugin.wit + TinyGo wasi-cli deps)
2
+ wit/
3
+
4
+ # 验证组件构建产物(重构建见 README)
5
+ testplugin/*.wasm
package/go/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # WasmNest 插件 SDK — Go 壳
2
+
3
+ Rust 侧 `wasmnest-plugin-api`(`WasmPlugin` trait + `wasm_entry!` 宏)的 Go 对等物:
4
+ 应用后端实现 `sdk.Plugin` 接口并在 `init()` 调用 `sdk.Entry`,即完成组件全部
5
+ 必选导出(command / lifecycle / manifest / events / abi-form)的接线。规格与
6
+ 判据见应用仓 issue #21(Go 语言支持,Phase 1)。
7
+
8
+ ## 布局
9
+
10
+ | 路径 | 内容 | 归属 |
11
+ | --- | --- | --- |
12
+ | `sdk/` | 壳包:`Plugin` 接口 + 可选回调接口(可移植,原生可测)/`Entry` 接线 + 宿主能力包装(`//go:build wasip2`,组件目标;core 九接口见 `host_wasip2.go`,能力域首件 http 见 `host_http_wasip2.go`) | 手写真源 |
13
+ | `gen/` | wit-bindgen-go 绑定(world `plugin` 全接口面) | 生成物(提交;改契约后重跑脚本) |
14
+ | `wit/` | 组装用 wit 包(拼装件 + go-plugin world + TinyGo wasi-cli deps) | 派生(gitignore,`tools/assemble-wit.mjs --out` 组装;应用构建复用同一脚本) |
15
+ | `tools/gen-bindings.mjs` | 绑定重生成脚本 | 手写 |
16
+ | `testplugin/` | 验证组件(SDK 自消费:TinyGo 构建 + 真实宿主冒烟) | 手写 |
17
+
18
+ ## 工具链(Phase 0 spike 实证组合,2026-10-25)
19
+
20
+ | 工具 | 版本 | 说明 |
21
+ | --- | --- | --- |
22
+ | Go | 1.27.3 | 原生单测 / vet / gofmt |
23
+ | TinyGo | 0.43.0 | `-target=wasip2` 组件构建(lib/wasi-cli wit 是脚本输入之一) |
24
+ | wit-bindgen-go | v0.7.0 | 绑定生成(依赖 `go.bytecodealliance.org/cm v0.3.0`) |
25
+ | wasm-tools | 1.240.0 | TinyGo 组件化外部依赖(缺失报 `component embed failed`) |
26
+
27
+ ## 常用命令(本目录)
28
+
29
+ ```bash
30
+ # 绑定重生成(改契约 / WIT 后必跑;幂等)
31
+ node tools/gen-bindings.mjs && go mod tidy
32
+
33
+ # 壳可移植面单测 + 格式检查(原生)
34
+ go test ./sdk/ && gofmt -l sdk/ && go vet ./sdk/
35
+
36
+ # 验证组件构建(组件验证判据:产出组件才算验证)
37
+ cd testplugin && tinygo build -target=wasip2 -wit-package ../wit -wit-world go-plugin -o go_sdk_probe.wasm .
38
+ wasm-tools validate go_sdk_probe.wasm # 组件合法性
39
+ ```
40
+
41
+ ## 应用工程接入(首期源码取用,不发布)
42
+
43
+ ```toml
44
+ # 应用 Go 工程的 go.mod(路径按仓布局调整)
45
+ replace github.com/7zai/wasmnest-plugin-sdk-go => <平台仓>/wasmnest-desktop/packages/plugin-sdk-desktop/go
46
+ ```
47
+
48
+ 应用侧最小形态(`testplugin/main.go` 是可运行范例):
49
+
50
+ ```go
51
+ type myApp struct{}
52
+
53
+ func (myApp) Manifest() string { return manifestJSON }
54
+ func (myApp) Activate() error { return nil }
55
+ func (myApp) Deactivate() error { return nil }
56
+ func (p myApp) InvokeCommand(name string, args json.RawMessage) (any, error) {
57
+ return commands.Invoke(name, args) // sdk.CommandTable:未知命令显性报错
58
+ }
59
+
60
+ func init() { sdk.Entry(myApp{}) }
61
+ func main() {}
62
+ ```
63
+
64
+ 可选回调(`OnStartup` / `OnMessage` / `OnProcessDone` / 移动词汇 5 回调等)经
65
+ 接口升级按需实现,见 `sdk/plugin.go`。宿主能力经 `sdk.Host*` 包装调用
66
+ (core.wit 九个内核机制接口 + 能力域首件 `HostHTTPFetch`;其余能力域接口经
67
+ `gen/wasmnest/plugin/host-*` 直用)。
68
+
69
+ ## 设计要点(踩坑记录)
70
+
71
+ - **绑定只对 world `plugin` 生成**:wasi:cli/command 的标准导入由 TinyGo 运行时
72
+ 自带,再生成一份会重复;构建期 world 用 `go-plugin`(多一个 wasi include)。
73
+ - **组件目标文件用 `//go:build wasip2` 且文件名后缀避开 `_wasm`**:`_wasm` 是
74
+ GOARCH 隐式约束(与 `//go:build` AND 组合),在非 wasm GOARCH 下会把文件
75
+ 无条件排除——Phase 1 实证。
76
+ - **导入面天然最小化**:TinyGo 链接器剪除未引用的 wasmimport 包装,产物 import
77
+ 集合 = 代码实际引用面(Phase 1 实证:全 9 个 core 包装在案,产物只 import
78
+ host-log / host-config 两个)。
79
+ - **wasi-cli deps 平铺**:TinyGo 的 `lib/wasi-cli/wit/deps/` 必须按 wasm-tools
80
+ `deps/` 单层约定拷入(嵌套 deps 不被发现,Phase 0 spike 实证)。
@@ -0,0 +1,3 @@
1
+ // This file exists for testing this package without WebAssembly,
2
+ // allowing empty function bodies with a //go:wasmimport directive.
3
+ // See https://pkg.go.dev/cmd/compile for more information.
@@ -0,0 +1,13 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ package hostapicall
4
+
5
+ import (
6
+ "go.bytecodealliance.org/cm"
7
+ )
8
+
9
+ // This file contains wasmimport and wasmexport declarations for "wasmnest:api-call@0.0.1".
10
+
11
+ //go:wasmimport wasmnest:api-call/host-api-call@0.0.1 call
12
+ //go:noescape
13
+ func wasmimport_Call(requestTopic0 *uint8, requestTopic1 uint32, payloadJson0 *uint8, payloadJson1 uint32, timeoutMs0 uint64, result *cm.Result[string, string, string])
@@ -0,0 +1,34 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ // Package hostapicall represents the imported interface "wasmnest:api-call/host-api-call@0.0.1".
4
+ //
5
+ // 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
6
+ // 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
7
+ // 端 `plugin` world 经 `include wasmnest:api-call/cap-api-call@0.0.1;` 并入本接口。
8
+ // 插件互调(ADR-0017):发布 JSON-RPC 请求 + 同步等待回复
9
+ package hostapicall
10
+
11
+ import (
12
+ "go.bytecodealliance.org/cm"
13
+ )
14
+
15
+ // Call represents the imported function "call".
16
+ //
17
+ // 发布请求到 request-topic(宿主按 `wasmnest.api.*` 门禁校验目标 api
18
+ // 已被某激活插件声明,未声明拒绝),并按调用方插件 ID + 请求载荷中的
19
+ // 字符串 `id` 构造响应 topic(`wasmnest.api.reply.<caller-id>.<request-id>`),
20
+ // 宿主侧注册静态回复订阅 + 阻塞等待(调用方 wasm 实例阻塞期间无法接收
21
+ // on_message,回复必须宿主侧消费,见 SDK api_call 模块注释)。
22
+ // 返回回复 JSON 字符串(result | error 对象);超时/门禁拒绝返回错误。
23
+ //
24
+ // call: func(request-topic: string, payload-json: string, timeout-ms: u64) -> result<string,
25
+ // string>
26
+ //
27
+ //go:nosplit
28
+ func Call(requestTopic string, payloadJSON string, timeoutMs uint64) (result cm.Result[string, string, string]) {
29
+ requestTopic0, requestTopic1 := cm.LowerString(requestTopic)
30
+ payloadJson0, payloadJson1 := cm.LowerString(payloadJSON)
31
+ timeoutMs0 := (uint64)(timeoutMs)
32
+ wasmimport_Call((*uint8)(requestTopic0), (uint32)(requestTopic1), (*uint8)(payloadJson0), (uint32)(payloadJson1), (uint64)(timeoutMs0), &result)
33
+ return
34
+ }
@@ -0,0 +1,3 @@
1
+ // This file exists for testing this package without WebAssembly,
2
+ // allowing empty function bodies with a //go:wasmimport directive.
3
+ // See https://pkg.go.dev/cmd/compile for more information.
@@ -0,0 +1,29 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ package hostapp
4
+
5
+ import (
6
+ "go.bytecodealliance.org/cm"
7
+ )
8
+
9
+ // This file contains wasmimport and wasmexport declarations for "wasmnest:app@0.0.1".
10
+
11
+ //go:wasmimport wasmnest:app/host-app@0.0.1 install-cli
12
+ //go:noescape
13
+ func wasmimport_InstallCli(payloadJson0 *uint8, payloadJson1 uint32, result *cm.Result[string, string, string])
14
+
15
+ //go:wasmimport wasmnest:app/host-app@0.0.1 uninstall-cli
16
+ //go:noescape
17
+ func wasmimport_UninstallCli(payloadJson0 *uint8, payloadJson1 uint32, result *cm.Result[string, struct{}, string])
18
+
19
+ //go:wasmimport wasmnest:app/host-app@0.0.1 plugin-resource-dir
20
+ //go:noescape
21
+ func wasmimport_PluginResourceDir(result *cm.Result[string, string, string])
22
+
23
+ //go:wasmimport wasmnest:app/host-app@0.0.1 register-path
24
+ //go:noescape
25
+ func wasmimport_RegisterPath(payloadJson0 *uint8, payloadJson1 uint32, result *cm.Result[string, struct{}, string])
26
+
27
+ //go:wasmimport wasmnest:app/host-app@0.0.1 unregister-path
28
+ //go:noescape
29
+ func wasmimport_UnregisterPath(payloadJson0 *uint8, payloadJson1 uint32, result *cm.Result[string, struct{}, string])
@@ -0,0 +1,108 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ // Package hostapp represents the imported interface "wasmnest:app/host-app@0.0.1".
4
+ //
5
+ // 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
6
+ // 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
7
+ // 端 `plugin` world 经 `include wasmnest:app/cap-app@0.0.1;` 并入本接口。
8
+ // 插件随包 CLI 生命周期(v8:host-app)——安装/卸载到用户 bin 目录并注册 PATH
9
+ //
10
+ // WASM 插件无注册表/文件系统写权限的直接通道,PATH 操作由宿主侧实现:
11
+ // 插件在 activate 时安装自身随包的 cli/ 产物(如 bedtask),停用时卸载。
12
+ // 幂等:重复安装不产生重复条目,升级覆盖;卸载仅移除本插件条目。
13
+ package hostapp
14
+
15
+ import (
16
+ "go.bytecodealliance.org/cm"
17
+ )
18
+
19
+ // InstallCli represents the imported function "install-cli".
20
+ //
21
+ // 安装 CLI(幂等):源 = 插件包目录 `cli/<file-name>`(Windows 自动补 .exe),
22
+ // 复制到用户 bin 目录并注册 PATH;`bin-dir` 为空用平台默认
23
+ // (Windows `%LOCALAPPDATA%/com.wasmnest.app/bin`;unix `~/.wasmnest/bin`)。
24
+ // 返回安装后的 bin 目录绝对路径。
25
+ //
26
+ // install-cli: func(payload-json: string) -> result<string, string>
27
+ //
28
+ //go:nosplit
29
+ func InstallCli(payloadJSON string) (result cm.Result[string, string, string]) {
30
+ payloadJson0, payloadJson1 := cm.LowerString(payloadJSON)
31
+ wasmimport_InstallCli((*uint8)(payloadJson0), (uint32)(payloadJson1), &result)
32
+ return
33
+ }
34
+
35
+ // UninstallCli represents the imported function "uninstall-cli".
36
+ //
37
+ // 卸载 CLI(幂等):删除文件 + 移除仅本插件添加的 PATH 条目
38
+ // (保留用户原有项);应用关闭流程中调用时自动跳过(CLI 随下次激活重建)
39
+ //
40
+ // uninstall-cli: func(payload-json: string) -> result<_, string>
41
+ //
42
+ //go:nosplit
43
+ func UninstallCli(payloadJSON string) (result cm.Result[string, struct{}, string]) {
44
+ payloadJson0, payloadJson1 := cm.LowerString(payloadJSON)
45
+ wasmimport_UninstallCli((*uint8)(payloadJson0), (uint32)(payloadJson1), &result)
46
+ return
47
+ }
48
+
49
+ // PluginResourceDir represents the imported function "plugin-resource-dir".
50
+ //
51
+ // 插件自身资源目录(v25 函数级追加,**不 bump**):返回本插件安装目录的
52
+ // 绝对路径(宿主 `extension_path` 剥离 verbatim 前缀后的形态,插件侧正斜杠
53
+ // 拼接可用),与 `on-session-lifecycle` payload 的 `resource_dir` 同值。
54
+ //
55
+ // 裁剪线判据(ADR 0022):宿主本来就持有插件加载路径,返回的是**调用方
56
+ // 自己的**目录、不含任何跨插件信息,零业务语义。**不设权限门**(同
57
+ // `host-platform` 口径)——没有可授予的权力,加门只会造出一个恒过的死门。
58
+ //
59
+ // 存在理由:会话创建编排整体移交插件后(session-engine-downsink P1-b),
60
+ // 宿主不再产生 `Creating` 生命周期事件,插件失去获取自身资源目录的唯一
61
+ // 途径(Agent 集成 hook 脚本源在该目录下,见插件 `task/hooks`)。
62
+ // 插件未加载 / 宿主服务不可用 → `Err`(不静默返回空串)。
63
+ //
64
+ // plugin-resource-dir: func() -> result<string, string>
65
+ //
66
+ //go:nosplit
67
+ func PluginResourceDir() (result cm.Result[string, string, string]) {
68
+ wasmimport_PluginResourceDir(&result)
69
+ return
70
+ }
71
+
72
+ // RegisterPath represents the imported function "register-path".
73
+ //
74
+ // 把某个目录登记进**用户级 PATH**(幂等):payload `{ "dir": "<绝对路径>" }`
75
+ // (`scope` 只接受 `"user"`,缺省即 user;出现其他值即拒绝——本原语不做
76
+ // 机器级 PATH,也就没有提权面)。
77
+ //
78
+ // Windows:把目录追加进 `HKCU\Environment\Path`(保留 `REG_EXPAND_SZ`
79
+ // 类型与用户原有项,写后广播 `WM_SETTINGCHANGE`,新开终端立即生效);
80
+ // unix:为目录下每个可执行文件建 `~/.local/bin` 符号链接。
81
+ //
82
+ // **安全闸门(机制级)**:目录必须落在 allowlist 根之内(应用数据根
83
+ // `~/.wasmnest` / `%LOCALAPPDATA%/com.wasmnest.app` / `~/.local`)、必须是
84
+ // 绝对路径且已存在、无控制字符——PATH 是**持久化**用户环境面,越界目录
85
+ // 一律拒绝并点名实际路径。权限 `app:path`(与 `app:cli` 分域)。
86
+ //
87
+ // register-path: func(payload-json: string) -> result<_, string>
88
+ //
89
+ //go:nosplit
90
+ func RegisterPath(payloadJSON string) (result cm.Result[string, struct{}, string]) {
91
+ payloadJson0, payloadJson1 := cm.LowerString(payloadJSON)
92
+ wasmimport_RegisterPath((*uint8)(payloadJson0), (uint32)(payloadJson1), &result)
93
+ return
94
+ }
95
+
96
+ // UnregisterPath represents the imported function "unregister-path".
97
+ //
98
+ // 从用户级 PATH 精确摘除该目录(幂等):payload 同 `register-path`。
99
+ // 只摘本目录的条目/链接,用户原有项与其他目录不动;条目不存在即成功。
100
+ //
101
+ // unregister-path: func(payload-json: string) -> result<_, string>
102
+ //
103
+ //go:nosplit
104
+ func UnregisterPath(payloadJSON string) (result cm.Result[string, struct{}, string]) {
105
+ payloadJson0, payloadJson1 := cm.LowerString(payloadJSON)
106
+ wasmimport_UnregisterPath((*uint8)(payloadJson0), (uint32)(payloadJson1), &result)
107
+ return
108
+ }
@@ -0,0 +1,14 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ package hostauthcenter
4
+
5
+ import (
6
+ "go.bytecodealliance.org/cm"
7
+ "unsafe"
8
+ )
9
+
10
+ // OptionStringShape is used for storage in variant or result types.
11
+ type OptionStringShape struct {
12
+ _ cm.HostLayout
13
+ shape [unsafe.Sizeof(cm.Option[string]{})]byte
14
+ }
@@ -0,0 +1,3 @@
1
+ // This file exists for testing this package without WebAssembly,
2
+ // allowing empty function bodies with a //go:wasmimport directive.
3
+ // See https://pkg.go.dev/cmd/compile for more information.
@@ -0,0 +1,49 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ package hostauthcenter
4
+
5
+ import (
6
+ "go.bytecodealliance.org/cm"
7
+ )
8
+
9
+ // This file contains wasmimport and wasmexport declarations for "wasmnest:auth-center@0.0.1".
10
+
11
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 secret-get
12
+ //go:noescape
13
+ func wasmimport_SecretGet(key0 *uint8, key1 uint32, result *cm.Result[OptionStringShape, cm.Option[string], string])
14
+
15
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 secret-set
16
+ //go:noescape
17
+ func wasmimport_SecretSet(key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[string, struct{}, string])
18
+
19
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 secret-delete
20
+ //go:noescape
21
+ func wasmimport_SecretDelete(key0 *uint8, key1 uint32, result *cm.Result[string, struct{}, string])
22
+
23
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 secret-keys
24
+ //go:noescape
25
+ func wasmimport_SecretKeys(result *cm.Result[cm.List[string], cm.List[string], string])
26
+
27
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 auth-setting-set
28
+ //go:noescape
29
+ func wasmimport_AuthSettingSet(key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[string, struct{}, string])
30
+
31
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 link-identity-parts
32
+ //go:noescape
33
+ func wasmimport_LinkIdentityParts(result *cm.Result[OptionStringShape, cm.Option[string], string])
34
+
35
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 auth-center-register
36
+ //go:noescape
37
+ func wasmimport_AuthCenterRegister(methods0 *string, methods1 uint32, result *cm.Result[string, string, string])
38
+
39
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 auth-center-unregister
40
+ //go:noescape
41
+ func wasmimport_AuthCenterUnregister(result *cm.Result[string, struct{}, string])
42
+
43
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 auth-methods-list
44
+ //go:noescape
45
+ func wasmimport_AuthMethodsList(result *cm.Result[cm.List[string], cm.List[string], string])
46
+
47
+ //go:wasmimport wasmnest:auth-center/host-auth-center@0.0.1 auth-method-invoke
48
+ //go:noescape
49
+ func wasmimport_AuthMethodInvoke(method0 *uint8, method1 uint32, params0 *uint8, params1 uint32, result *cm.Result[string, string, string])
@@ -0,0 +1,225 @@
1
+ // Code generated by wit-bindgen-go. DO NOT EDIT.
2
+
3
+ // Package hostauthcenter represents the imported interface "wasmnest:auth-center/host-auth-center@0.0.1".
4
+ //
5
+ // 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
6
+ // 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
7
+ // 端 `plugin` world 经 `include wasmnest:auth-center/cap-auth-center@0.0.1;` 并入本接口。
8
+ // 密钥托管(secret-store,v15)+ 认证编排桥接面(v17 起,desktop 独有)
9
+ //
10
+ // **本 interface 是编排桥接面,不是记录面**:宿主不持有任何认证记录或设备入场
11
+ // 密码学。真源归属(逐条对应本 interface 现有 10 条原语):
12
+ // - `secret-get/set/delete/keys`(4 条,secret-store):属主密钥托管。约定与红线:
13
+ // * **属主隔离**:属主 = 调用方插件实例的 plugin_id(宿主自 store state 派生,
14
+ // guest 无法伪造/旁路);A 不能读/改/删 B 命名空间的密钥,越权由命名空间
15
+ // 隔离天然拒绝(权限门之外的第二道闸)
16
+ // * **明文不落日志**:宿主日志/告警只记密钥长度(`value.len()` 模式),
17
+ // 禁止打印值本身
18
+ // * 持久化:真源 = 宿主主库 `plugin_secrets` 表(schema.sql);set 覆盖写、
19
+ // delete 幂等,重启后密钥稳定
20
+ // - `auth-setting-set`(1 条):认证域设置项写入(键白名单 `pairing_code_ttl` /
21
+ // `qr_token_ttl`,十进制秒数)。真源 = 宿主主库 `settings` 表;读取走 `host-config`
22
+ // / 宿主命令面,白名单外键一律拒绝
23
+ // - `link-identity-parts`(1 条):链路身份 Kd 公钥材料(只含公开材料),
24
+ // 来自 `link_crypto::identity_parts`
25
+ // - `auth-center-register` / `auth-center-unregister`(2 条):认证中心显式注册与
26
+ // 注销(ADR 0031)。真实认证执行在认证中心插件(`com.wasmnest.bedcode`),
27
+ // 本组只是宿主进程内的发现协议与唯一性仲裁
28
+ // - `auth-methods-list` / `auth-method-invoke`(2 条):组合式认证方法(ADR 0031)
29
+ //
30
+ // **已退役、不得回接**(历史注释见下方 v24 / v33 / v34 条目):v18/v19 的记录面
31
+ // 七函数(`trusted-devices-*` / `connection-history-*`)、v33 的设备入场 JWT
32
+ // 签发验签两函数、v34 的生物凭证面三函数。旧产物仍 import 它们时在实例化期被拒,
33
+ // 由 `stale_artifact_rebuild_hint` 点名「按对应 ABI 重建」。
34
+ // **为什么叫 center**:移动分片曾声明同名 `host-auth`,但两者函数集**零交集**——
35
+ // 移动侧是「设备入场客户端」(配对 / QR / 生物凭证 / 凭据事实),本 interface 是
36
+ // 「认证中心角色」(密钥托管 + 中心注册 + 组合式认证发现)。同名不同角色会在统一
37
+ // 契约(并集 world)里撞 duplicate definition,故按角色定名:本侧 `-center`,
38
+ // 移动那侧 `host-auth-client`;两端各自注册自己承担的角色,Core 不做端点判定。
39
+ package hostauthcenter
40
+
41
+ import (
42
+ "go.bytecodealliance.org/cm"
43
+ )
44
+
45
+ // SecretGet represents the imported function "secret-get".
46
+ //
47
+ // 读取属主密钥;键不存在返回 `ok(none)`
48
+ //
49
+ // secret-get: func(key: string) -> result<option<string>, string>
50
+ //
51
+ //go:nosplit
52
+ func SecretGet(key string) (result cm.Result[OptionStringShape, cm.Option[string], string]) {
53
+ key0, key1 := cm.LowerString(key)
54
+ wasmimport_SecretGet((*uint8)(key0), (uint32)(key1), &result)
55
+ return
56
+ }
57
+
58
+ // SecretSet represents the imported function "secret-set".
59
+ //
60
+ // 写入/覆盖属主密钥
61
+ //
62
+ // secret-set: func(key: string, value: string) -> result<_, string>
63
+ //
64
+ //go:nosplit
65
+ func SecretSet(key string, value string) (result cm.Result[string, struct{}, string]) {
66
+ key0, key1 := cm.LowerString(key)
67
+ value0, value1 := cm.LowerString(value)
68
+ wasmimport_SecretSet((*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result)
69
+ return
70
+ }
71
+
72
+ // SecretDelete represents the imported function "secret-delete".
73
+ //
74
+ // 删除属主密钥(键不存在也视为成功)
75
+ //
76
+ // secret-delete: func(key: string) -> result<_, string>
77
+ //
78
+ //go:nosplit
79
+ func SecretDelete(key string) (result cm.Result[string, struct{}, string]) {
80
+ key0, key1 := cm.LowerString(key)
81
+ wasmimport_SecretDelete((*uint8)(key0), (uint32)(key1), &result)
82
+ return
83
+ }
84
+
85
+ // SecretKeys represents the imported function "secret-keys".
86
+ //
87
+ // 列举属主密钥名(供诊断/清理;不返回值本身)
88
+ //
89
+ // secret-keys: func() -> result<list<string>, string>
90
+ //
91
+ //go:nosplit
92
+ func SecretKeys() (result cm.Result[cm.List[string], cm.List[string], string]) {
93
+ wasmimport_SecretKeys(&result)
94
+ return
95
+ }
96
+
97
+ // AuthSettingSet represents the imported function "auth-setting-set".
98
+ //
99
+ // ==================== v18:认证域设置写入 ====================
100
+ // 认证域设置项写入(内核 `settings` 表,键白名单:`pairing_code_ttl` /
101
+ // `qr_token_ttl`,值为十进制秒数)。读取走宿主配置面(`host-config` / 宿主命令面);
102
+ // 白名单外键一律拒绝——设置表是宿主真源,不接受插件写入任意键。
103
+ //
104
+ // auth-setting-set: func(key: string, value: string) -> result<_, string>
105
+ //
106
+ //go:nosplit
107
+ func AuthSettingSet(key string, value string) (result cm.Result[string, struct{}, string]) {
108
+ key0, key1 := cm.LowerString(key)
109
+ value0, value1 := cm.LowerString(value)
110
+ wasmimport_AuthSettingSet((*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result)
111
+ return
112
+ }
113
+
114
+ // LinkIdentityParts represents the imported function "link-identity-parts".
115
+ //
116
+ // ==================== v24:认证记录下沉(2026-09-22 用户裁定) ====================
117
+ // 用户裁定:`pairings` / `connection_history` 不再留宿主主库(§8「留宿主」
118
+ // 口径撤销),认证记录归认证中心(`com.wasmnest.bedcode`)私有库,
119
+ // 经其互调 api(`auth-records-import` / `devices-list` / `history-list`)服务。
120
+ // 宿主 host-auth 记录面原语(v18/v19 七函数:trusted-devices-list /
121
+ // trusted-device-revoke / connection-history-list / connection-history-clear /
122
+ // trusted-device-upsert / trusted-device-touch / connection-history-record)
123
+ // 随之**退役删除**。旧产物(v23 SDK 构建)在 activate 期拿到点明新形态的
124
+ // 错误,须按 v24 SDK 重建。
125
+ //
126
+ // 保留面(凭据与密码学归属见 **v33 / v34 条目**,ADR 0033):secret-store 密钥托管、
127
+ // 链路身份(link-identity-parts)。**设备入场 JWT 签发/验签已于 v33 从本 interface 退役**
128
+ // (原先的 `device-token-issue` / `device-token-verify`);**生物凭证面(原先的
129
+ // `biometric-credential-bound` / `biometric-verify-signature` /
130
+ // `biometric-credential-bind`)已于 v34 退役**——公钥托管与验签执行下沉认证中心
131
+ // 插件私有库(B-downsink),宿主不再持有任何设备侧凭证材料。
132
+ // 链路身份 Kd 公钥材料读取(`link_crypto::identity_parts` 语义):
133
+ // `ok(none)` = 身份未就绪。JSON:`{ publicB64, fingerprint }`。
134
+ // 响应字段 `kdPublicB64` / `kdFingerprint` 的数据源;只含公开材料。
135
+ //
136
+ // link-identity-parts: func() -> result<option<string>, string>
137
+ //
138
+ //go:nosplit
139
+ func LinkIdentityParts() (result cm.Result[OptionStringShape, cm.Option[string], string]) {
140
+ wasmimport_LinkIdentityParts(&result)
141
+ return
142
+ }
143
+
144
+ // AuthCenterRegister represents the imported function "auth-center-register".
145
+ //
146
+ // ==================== v34:生物凭证面退役(B-downsink,2026-09-30) ====================
147
+ // 原 `biometric-credential-bound` / `biometric-verify-signature` /
148
+ // `biometric-credential-bind` 三函数**删除**(破坏性):认证中心
149
+ // (`com.wasmnest.bedcode`)自持生物公钥(本插件私有库 `auth_biometric_keys`)
150
+ // 并在 WASM 内用 p256 验签,宿主不再托管任何生物凭证材料(宿主
151
+ // `utils/auth/biometric.rs` 与 `host_secrets` 的生物键同批退役)。旧产物
152
+ // (v33 SDK 构建)仍 import 这三函数 → **实例化期**即被拒,
153
+ // `stale_artifact_rebuild_hint` 点名「按 v34 SDK 重建」,不是 trap 也不是静默降级。
154
+ // wire 格式与挑战-应答流程逐字节不变(移动端仍走 HTTP /api/auth/biometric-*,零改动)。
155
+ // ==================== v33:设备入场 JWT 签发/验签退役(ADR 0033) ====================
156
+ // 原 `device-token-issue` / `device-token-verify` 两函数**删除**(破坏性):
157
+ // 认证中心(`com.wasmnest.bedcode`)自持入场密钥并自签自验,宿主不再
158
+ // 持有任何设备 JWT 密码学,`utils/auth/jwt.rs` 整个退役。旧产物(v32 SDK
159
+ // 构建)仍 import 这两个函数 → **实例化期**即被拒,`stale_artifact_rebuild_hint`
160
+ // 点名「按 v33 SDK 重建」,不是 trap 也不是静默降级。
161
+ // token wire 格式逐字节不变(移动端把 token 当不透明串,零改动)。
162
+ // ==================== v32:认证中心显式注册 + 组合式认证原语(ADR 0031) ====================
163
+ // 用户裁定 2026-09-29:认证中心与微服务 auth server 概念一致,只不过这里没有也
164
+ // 不需要服务发现——注册表就是宿主进程内的发现协议(激活时注册 + 唯一性仲裁)。
165
+ // 本组 4 函数为**桌面独有**(双端偏离,ADR 0022):移动端是客户端,不承载服务端
166
+ // 网关与认证中心角色,不跟演不投影,mobile ABI 保持 11。
167
+ //
168
+ // 权限门:4 函数全部 `auth`(复用既有 PERMISSION_AUTH,不新增词汇位)。
169
+ // 注册本插件为**认证中心**(单中心角色,K4)。入参 = 本中心提供的认证方式标识
170
+ // 列表(**声明式**,宿主不解释每个 method 的业务语义);成功返回中心句柄
171
+ // `authc-<uuid>`。已有中心在册 → `err`(点名在册属主);无 `auth` 权限位 →
172
+ // `err("permission denied")`。停用后宿主 `purge_for_plugin` 兜底回收。
173
+ //
174
+ // auth-center-register: func(methods: list<string>) -> result<string, string>
175
+ //
176
+ //go:nosplit
177
+ func AuthCenterRegister(methods cm.List[string]) (result cm.Result[string, string, string]) {
178
+ methods0, methods1 := cm.LowerList(methods)
179
+ wasmimport_AuthCenterRegister((*string)(methods0), (uint32)(methods1), &result)
180
+ return
181
+ }
182
+
183
+ // AuthCenterUnregister represents the imported function "auth-center-unregister".
184
+ //
185
+ // 注销本插件的认证中心角色(仅属主本人可调;非属主 → `err`)。无中心在册也
186
+ // 视为成功(幂等)。
187
+ //
188
+ // auth-center-unregister: func() -> result<_, string>
189
+ //
190
+ //go:nosplit
191
+ func AuthCenterUnregister() (result cm.Result[string, struct{}, string]) {
192
+ wasmimport_AuthCenterUnregister(&result)
193
+ return
194
+ }
195
+
196
+ // AuthMethodsList represents the imported function "auth-methods-list".
197
+ //
198
+ // 列取当前认证中心注册时声明的认证方式(无中心在册 → `err`)。其他插件据此
199
+ // 发现可用的认证方式(组合式认证的发现端,K6)。权限 `auth`。
200
+ //
201
+ // auth-methods-list: func() -> result<list<string>, string>
202
+ //
203
+ //go:nosplit
204
+ func AuthMethodsList() (result cm.Result[cm.List[string], cm.List[string], string]) {
205
+ wasmimport_AuthMethodsList(&result)
206
+ return
207
+ }
208
+
209
+ // AuthMethodInvoke represents the imported function "auth-method-invoke".
210
+ //
211
+ // 经认证中心执行一次认证方式调用(**零解析窄转发**:`params` 原样透传给中心,
212
+ // 返回值原样透回)。`method` 必须在中心注册的 methods 内(安全闸门判据,非
213
+ // 语义解释),否则 `err`(点名 method 与在册列表)。无中心 → `err(no auth center
214
+ // registered)`(fail-closed);中心调用失败 → `err(auth center unavailable: …)`;
215
+ // 中心返回业务错误 → 原样透传(不吞成宿主错误)。权限 `auth`。
216
+ //
217
+ // auth-method-invoke: func(method: string, params: string) -> result<string, string>
218
+ //
219
+ //go:nosplit
220
+ func AuthMethodInvoke(method string, params string) (result cm.Result[string, string, string]) {
221
+ method0, method1 := cm.LowerString(method)
222
+ params0, params1 := cm.LowerString(params)
223
+ wasmimport_AuthMethodInvoke((*uint8)(method0), (uint32)(method1), (*uint8)(params0), (uint32)(params1), &result)
224
+ return
225
+ }