@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.
- package/README.md +307 -2
- package/README_en.md +284 -0
- package/bin/cli.js +602 -0
- package/bin/manifest-gen.js +458 -0
- package/bin/manifest-validate.js +494 -0
- package/bin/permission-vocabulary.json +5 -0
- package/bin/plugin-watch.js +331 -0
- package/bin/wasm-hash.js +124 -0
- package/dev-shell/README.md +122 -0
- package/dev-shell/index.html +12 -0
- package/dev-shell/package.json +28 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/components/LogPanel.vue +90 -0
- package/dev-shell/src/loader.ts +104 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales.ts +50 -0
- package/dev-shell/src/main.ts +46 -0
- package/dev-shell/src/mock/app-env.ts +102 -0
- package/dev-shell/src/mock/commands.ts +54 -0
- package/dev-shell/src/mock/domain-context.ts +46 -0
- package/dev-shell/src/mock/events.ts +16 -0
- package/dev-shell/src/mock/file-transfer.ts +512 -0
- package/dev-shell/src/mock/tauri-ipc.ts +109 -0
- package/dev-shell/src/registry.ts +90 -0
- package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
- package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
- package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
- package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
- package/dev-shell/src/shell/mount/appSession.ts +45 -0
- package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
- package/dev-shell/src/shell/types.ts +121 -0
- package/dev-shell/src/styles/dev.css +27 -0
- package/dev-shell/src/styles/shell.css +752 -0
- package/dev-shell/src/styles/style.css +1178 -0
- package/dev-shell/src/theme.ts +140 -0
- package/dev-shell/src/vite-env.d.ts +24 -0
- package/dev-shell/tailwind.config.js +98 -0
- package/dev-shell/vite.config.ts +174 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +238 -0
- package/dist/types.d.ts +632 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +25 -0
- package/dist/vite-plugin.js +80 -0
- package/go/.gitignore +5 -0
- package/go/README.md +80 -0
- package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
- package/go/gen/wasmnest/app/host-app/empty.s +3 -0
- package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
- package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
- package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
- package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
- package/go/gen/wasmnest/http/host-http/abi.go +14 -0
- package/go/gen/wasmnest/http/host-http/empty.s +3 -0
- package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
- package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
- package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
- package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
- package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
- package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
- package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
- package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
- package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
- package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
- package/go/gen/wasmnest/plugin/command/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
- package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
- package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
- package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
- package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
- package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
- package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
- package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
- package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
- package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
- package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
- package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
- package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
- package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
- package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
- package/go/gen/wasmnest/process/host-process/empty.s +3 -0
- package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
- package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
- package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
- package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
- package/go/gen/wasmnest/task/host-task/abi.go +14 -0
- package/go/gen/wasmnest/task/host-task/empty.s +3 -0
- package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
- package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
- package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
- package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
- package/go/go.mod +14 -0
- package/go/go.sum +2 -0
- package/go/sdk/dispatch.go +49 -0
- package/go/sdk/dispatch_test.go +81 -0
- package/go/sdk/entry_native.go +13 -0
- package/go/sdk/entry_wasip2.go +188 -0
- package/go/sdk/host_http_wasip2.go +42 -0
- package/go/sdk/host_wasip2.go +251 -0
- package/go/sdk/plugin.go +103 -0
- package/go/testplugin/index.js +1 -0
- package/go/testplugin/main.go +67 -0
- package/go/testplugin/plugin.json +24 -0
- package/go/tools/assemble-wit.mjs +152 -0
- package/go/tools/gen-bindings.mjs +51 -0
- package/go/wit/core.wit +273 -0
- package/go/wit/deps/api-call/cap-api-call.wit +20 -0
- package/go/wit/deps/app/cap-app.wit +54 -0
- package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
- package/go/wit/deps/clipboard/clipboard.wit +48 -0
- package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
- package/go/wit/deps/clocks/wall-clock.wit +42 -0
- package/go/wit/deps/clocks/world.wit +6 -0
- package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
- package/go/wit/deps/crypto/cap-crypto.wit +68 -0
- package/go/wit/deps/filesystem/preopens.wit +8 -0
- package/go/wit/deps/filesystem/types.wit +634 -0
- package/go/wit/deps/filesystem/world.wit +6 -0
- package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
- package/go/wit/deps/http/http.wit +28 -0
- package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
- package/go/wit/deps/io/error.wit +34 -0
- package/go/wit/deps/io/poll.wit +41 -0
- package/go/wit/deps/io/streams.wit +262 -0
- package/go/wit/deps/io/world.wit +6 -0
- package/go/wit/deps/mdns/mdns.wit +45 -0
- package/go/wit/deps/notify/notify.wit +51 -0
- package/go/wit/deps/peer/peer.wit +126 -0
- package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
- package/go/wit/deps/process/cap-process.wit +25 -0
- package/go/wit/deps/pty/pty.wit +80 -0
- package/go/wit/deps/random/insecure-seed.wit +25 -0
- package/go/wit/deps/random/insecure.wit +22 -0
- package/go/wit/deps/random/random.wit +26 -0
- package/go/wit/deps/random/world.wit +7 -0
- package/go/wit/deps/sockets/instance-network.wit +9 -0
- package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
- package/go/wit/deps/sockets/network.wit +145 -0
- package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/tcp.wit +353 -0
- package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/udp.wit +266 -0
- package/go/wit/deps/sockets/world.wit +11 -0
- package/go/wit/deps/task/cap-task.wit +56 -0
- package/go/wit/deps/timer/cap-timer.wit +14 -0
- package/go/wit/deps/wasi-cli/command.wit +7 -0
- package/go/wit/deps/wasi-cli/environment.wit +18 -0
- package/go/wit/deps/wasi-cli/exit.wit +4 -0
- package/go/wit/deps/wasi-cli/imports.wit +20 -0
- package/go/wit/deps/wasi-cli/run.wit +4 -0
- package/go/wit/deps/wasi-cli/stdio.wit +17 -0
- package/go/wit/deps/wasi-cli/terminal.wit +49 -0
- package/go/wit/deps/ws/ws.wit +50 -0
- package/go/wit/deps/ws-server/cap-ws.wit +99 -0
- package/go/wit/go-plugin.wit +28 -0
- package/go/wit/plugin-face.wit +355 -0
- package/go/wit/wasmnest.wit +25 -0
- package/package.json +100 -3
- package/src/config.ts +49 -0
- package/src/global-dialog.ts +169 -0
- package/src/index.ts +88 -0
- package/src/runtime.ts +54 -0
- package/src/types.ts +681 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/MarkdownEditor.vue +520 -0
- package/src/ui/NumberField.d.ts +49 -0
- package/src/ui/NumberField.vue +390 -0
- package/src/ui/PluginGlobalDialog.vue +401 -0
- package/src/ui/Select.d.ts +36 -0
- package/src/ui/Select.vue +220 -0
- package/src/ui/TerminalInputRail.vue +184 -0
- package/src/ui/apply-select-position.ts +65 -0
- package/src/ui/markdown-editor-syntax.ts +234 -0
- package/src/ui/markdown-editor.d.ts +36 -0
- package/src/ui/plugin-global-dialog.d.ts +12 -0
- package/src/ui/select-position.ts +79 -0
- package/src/ui/terminal-input-rail.d.ts +30 -0
- package/src/ui/zoom-compensation.d.ts +9 -0
- package/src/ui/zoom-compensation.ts +52 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +124 -0
- package/template/README.md +39 -0
- package/template/package.json +23 -0
- package/template/plugin.json +14 -0
- package/template/rust/Cargo.toml +21 -0
- package/template/rust/src/lib.rs +39 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
- package/tools/componentize/Cargo.lock +299 -0
- package/tools/componentize/Cargo.toml +18 -0
- package/tools/componentize/src/main.rs +197 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Go 组件构建的 wit 包组装(issue #21「应用后端 Go 语言支持」)
|
|
4
|
+
*
|
|
5
|
+
* 把三路输入组装成 TinyGo/wasm-tools 可消费的 wit 包(`--out` 指定目录,派生产物
|
|
6
|
+
* 不入库)。两个消费方:
|
|
7
|
+
* - `gen-bindings.mjs`:组装进 `go/wit/` 后跑 wit-bindgen-go 生成绑定;
|
|
8
|
+
* - 应用 Go 工程的 build 脚本:组装进 app 构建区,作 `tinygo build
|
|
9
|
+
* -wit-package` 输入(应用不重生成绑定,gen/ 随 SDK 模块分发)。
|
|
10
|
+
*
|
|
11
|
+
* 三路输入(契约真源仍在能力仓 WIT / wit-src,本脚本不重复拼装):
|
|
12
|
+
* 1. 拼装产物 `../rust/wit/**`(compose-wit.mjs 维护——ADR 0061 拆包后布局为
|
|
13
|
+
* 顶层 `core.wit` / `plugin-face.wit` / `wasmnest.wit` + `deps/<pkg>/…`,
|
|
14
|
+
* 本脚本把顶层与 `deps/` 一并带出);
|
|
15
|
+
* 2. 本端 world 真源 `../rust/wit-src/go-plugin.wit`(world go-plugin = plugin +
|
|
16
|
+
* wasi:cli/command,见文件头注);
|
|
17
|
+
* 3. TinyGo 发行版自带 wasi-cli WIT(`lib/wasi-cli/wit/`)——按 wasm-tools
|
|
18
|
+
* `deps/` 单层约定平铺:包根文件进 `deps/wasi-cli/`,其 deps/<名>/ 进
|
|
19
|
+
* `deps/<名>/`(嵌套 deps 不被发现,Phase 0 spike 实证)。
|
|
20
|
+
*
|
|
21
|
+
* 依赖外部工具(PATH 或环境变量定位;工具链版本见 go/README.md):
|
|
22
|
+
* - TinyGo(`TINYGO_ROOT` 或 PATH 反查;spike 实证 0.43.0)
|
|
23
|
+
*
|
|
24
|
+
* 用法:node tools/assemble-wit.mjs --out <dir>(幂等,全量重建)
|
|
25
|
+
*/
|
|
26
|
+
import { execFileSync } from "node:child_process";
|
|
27
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
28
|
+
import { dirname, join, resolve } from "node:path";
|
|
29
|
+
import { fileURLToPath } from "node:url";
|
|
30
|
+
|
|
31
|
+
const GO_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
32
|
+
const SDK_DIR = resolve(GO_DIR, "..");
|
|
33
|
+
|
|
34
|
+
/** fail-visible 定位可执行文件:环境变量 > PATH;缺失即抛(不猜默认值) */
|
|
35
|
+
export function requireTool(envVar, name) {
|
|
36
|
+
const fromEnv = process.env[envVar];
|
|
37
|
+
if (fromEnv && existsSync(fromEnv)) return fromEnv;
|
|
38
|
+
try {
|
|
39
|
+
return execFileSync("which", [name], { encoding: "utf8" }).trim();
|
|
40
|
+
} catch {
|
|
41
|
+
throw new Error(`未找到 ${name}:安装后加入 PATH,或经 ${envVar} 指定路径(工具链版本见 go/README.md)`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** TinyGo 根目录(lib/wasi-cli/wit 的容器):TINYGO_ROOT > tinygo 可执行文件上一级 */
|
|
46
|
+
export function tinyGoRoot() {
|
|
47
|
+
if (process.env.TINYGO_ROOT) {
|
|
48
|
+
if (!existsSync(join(process.env.TINYGO_ROOT, "lib", "wasi-cli", "wit"))) {
|
|
49
|
+
throw new Error(`TINYGO_ROOT=${process.env.TINYGO_ROOT} 下无 lib/wasi-cli/wit`);
|
|
50
|
+
}
|
|
51
|
+
return process.env.TINYGO_ROOT;
|
|
52
|
+
}
|
|
53
|
+
const tinygo = requireTool("TINYGO_BIN", "tinygo");
|
|
54
|
+
// bin/tinygo → 根目录(源码树与发行包同构)
|
|
55
|
+
const root = resolve(dirname(tinygo), "..");
|
|
56
|
+
if (!existsSync(join(root, "lib", "wasi-cli", "wit"))) {
|
|
57
|
+
throw new Error(`TinyGo ${tinygo} 的 lib/wasi-cli/wit 不存在(预期随发行版携带)`);
|
|
58
|
+
}
|
|
59
|
+
return root;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 组装 wit 包到 outDir(全量重建,幂等)。outDir 必填(目标位置由消费方决定)。
|
|
64
|
+
* 返回 outDir 绝对路径。
|
|
65
|
+
*/
|
|
66
|
+
export function assembleWit(outDir) {
|
|
67
|
+
if (!outDir) throw new Error("assemble-wit: 缺 --out <dir>");
|
|
68
|
+
const out = resolve(outDir);
|
|
69
|
+
|
|
70
|
+
rmSync(out, { recursive: true, force: true });
|
|
71
|
+
mkdirSync(out, { recursive: true });
|
|
72
|
+
|
|
73
|
+
const composedDir = join(SDK_DIR, "rust", "wit");
|
|
74
|
+
const composed = readdirSync(composedDir).filter((f) => f.endsWith(".wit"));
|
|
75
|
+
if (!composed.includes("core.wit") || !composed.includes("wasmnest.wit") || !composed.includes("plugin-face.wit")) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`拼装产物不完整 ${composedDir}:缺 core.wit / plugin-face.wit / wasmnest.wit(先跑 compose-wit.mjs --all)`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
for (const f of composed) cpSync(join(composedDir, f), join(out, f));
|
|
81
|
+
// ADR 0061 拆包后的能力域包(`deps/<pkg>/`)随顶层一并带出;WASI 包稍后并入
|
|
82
|
+
// 同一 `deps/`(目录名不冲突:能力域包名 vs wasi 包名)。
|
|
83
|
+
const composedDeps = join(composedDir, "deps");
|
|
84
|
+
if (existsSync(composedDeps)) {
|
|
85
|
+
for (const name of readdirSync(composedDeps)) {
|
|
86
|
+
const src = join(composedDeps, name);
|
|
87
|
+
if (!statSync(src).isDirectory()) continue;
|
|
88
|
+
const dst = join(out, "deps", name);
|
|
89
|
+
mkdirSync(dst, { recursive: true });
|
|
90
|
+
for (const f of readdirSync(src).filter((f) => f.endsWith(".wit"))) {
|
|
91
|
+
cpSync(join(src, f), join(dst, f));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const goWorld = join(SDK_DIR, "rust", "wit-src", "go-plugin.wit");
|
|
97
|
+
if (!existsSync(goWorld)) throw new Error(`world 真源缺失 ${goWorld}`);
|
|
98
|
+
// 包版本对齐(ADR 0051:版本只有一处手写):world 文件与拼装产物必须同包同版,
|
|
99
|
+
// `include plugin` 才能解析——同包双版本声明会让 wasm-tools 解析直接失败。
|
|
100
|
+
// 版本真源在能力仓 wasmnest-contract,此处从拼装产物 wasmnest.wit 读出后回写,
|
|
101
|
+
// go-plugin.wit 的 package 行是待对齐占位、不持版本字面量(契约升版本文件零改动)。
|
|
102
|
+
const composedPkg = readFileSync(join(out, "wasmnest.wit"), "utf8").match(
|
|
103
|
+
/^package\s+(wasmnest:plugin@\d+\.\d+\.\d+);/m,
|
|
104
|
+
);
|
|
105
|
+
if (!composedPkg) {
|
|
106
|
+
throw new Error("wasmnest.wit 缺 `package wasmnest:plugin@x.y.z;` 行(拼装产物形状漂移)");
|
|
107
|
+
}
|
|
108
|
+
let goWorldSrc = readFileSync(goWorld, "utf8");
|
|
109
|
+
if (!/^package\s+wasmnest:plugin@\d+\.\d+\.\d+;/m.test(goWorldSrc)) {
|
|
110
|
+
throw new Error("go-plugin.wit 缺 `package wasmnest:plugin@x.y.z;` 行(对齐锚点缺失)");
|
|
111
|
+
}
|
|
112
|
+
goWorldSrc = goWorldSrc.replace(
|
|
113
|
+
/^package\s+wasmnest:plugin@\d+\.\d+\.\d+;/m,
|
|
114
|
+
`package ${composedPkg[1]};`,
|
|
115
|
+
);
|
|
116
|
+
writeFileSync(join(out, "go-plugin.wit"), goWorldSrc);
|
|
117
|
+
|
|
118
|
+
// wasi-cli deps 平铺:包根 → deps/wasi-cli/,deps/<名>/ → deps/<名>/
|
|
119
|
+
const wasiCliWit = join(tinyGoRoot(), "lib", "wasi-cli", "wit");
|
|
120
|
+
const depsOut = join(out, "deps");
|
|
121
|
+
mkdirSync(join(depsOut, "wasi-cli"), { recursive: true });
|
|
122
|
+
for (const f of readdirSync(wasiCliWit).filter((f) => f.endsWith(".wit"))) {
|
|
123
|
+
cpSync(join(wasiCliWit, f), join(depsOut, "wasi-cli", f));
|
|
124
|
+
}
|
|
125
|
+
for (const name of readdirSync(join(wasiCliWit, "deps"))) {
|
|
126
|
+
const src = join(wasiCliWit, "deps", name);
|
|
127
|
+
const dst = join(depsOut, name);
|
|
128
|
+
mkdirSync(dst, { recursive: true });
|
|
129
|
+
for (const f of readdirSync(src).filter((f) => f.endsWith(".wit"))) {
|
|
130
|
+
cpSync(join(src, f), join(dst, f));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ==================== CLI(仅直接执行时运行;被 import 只取 assembleWit) ====================
|
|
137
|
+
|
|
138
|
+
const isMain = process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
139
|
+
if (isMain) {
|
|
140
|
+
const argv = process.argv.slice(2);
|
|
141
|
+
function flagValue(flag) {
|
|
142
|
+
const i = argv.indexOf(flag);
|
|
143
|
+
return i !== -1 && argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : null;
|
|
144
|
+
}
|
|
145
|
+
const out = flagValue("--out");
|
|
146
|
+
if (!out) {
|
|
147
|
+
console.error("用法:node tools/assemble-wit.mjs --out <dir>");
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
const dir = assembleWit(out);
|
|
151
|
+
console.log(`assemble-wit: wit 包已组装 → ${dir}`);
|
|
152
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Go SDK 壳绑定生成(issue #21「应用后端 Go 语言支持」Phase 1)
|
|
4
|
+
*
|
|
5
|
+
* 组装 wit 包到 `go/wit/`(三路输入与规则见 assemble-wit.mjs 头注;派生产物不入库),
|
|
6
|
+
* 再经 wit-bindgen-go 生成 Go 绑定到 `go/gen/`(入库,消费方零工具链即可引用)。
|
|
7
|
+
*
|
|
8
|
+
* 依赖外部工具(PATH 或环境变量定位;工具链版本见 go/README.md):
|
|
9
|
+
* - wit-bindgen-go(`WIT_BINDGEN_GO` 或 PATH;spike 实证 v0.7.0)
|
|
10
|
+
* - TinyGo(`TINYGO_ROOT` 或 PATH 反查;spike 实证 0.43.0)
|
|
11
|
+
*
|
|
12
|
+
* 用法(本目录执行):node tools/gen-bindings.mjs
|
|
13
|
+
* 幂等:连续两次运行 gen/ 输出 diff 为空;改契约后重跑本脚本 + TinyGo 重建产物。
|
|
14
|
+
*/
|
|
15
|
+
import { execFileSync } from "node:child_process";
|
|
16
|
+
import { existsSync, rmSync } from "node:fs";
|
|
17
|
+
import { join, resolve, dirname } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { assembleWit, requireTool } from "./assemble-wit.mjs";
|
|
20
|
+
|
|
21
|
+
const GO_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
22
|
+
const WIT_OUT = join(GO_DIR, "wit");
|
|
23
|
+
const GEN_OUT = join(GO_DIR, "gen");
|
|
24
|
+
const MODULE = "github.com/7zai/wasmnest-plugin-sdk-go";
|
|
25
|
+
// 绑定只对 world plugin(纯 wasmnest:plugin 面)生成:wasi:cli/command 的标准
|
|
26
|
+
// 导入由 TinyGo 运行时自带实现,再生成一份 gen/wasi/* 会与其重复(spike 实证
|
|
27
|
+
// 无需生成)。TinyGo 构建仍以 -wit-world go-plugin 组件化(wasi include 只进
|
|
28
|
+
// 构建期 world,不进绑定面)。
|
|
29
|
+
const BINDGEN_WORLD = "plugin";
|
|
30
|
+
const BUILD_WORLD = "go-plugin";
|
|
31
|
+
|
|
32
|
+
// ==================== 1. 组装 wit 包(全量重建,幂等) ====================
|
|
33
|
+
|
|
34
|
+
assembleWit(WIT_OUT);
|
|
35
|
+
|
|
36
|
+
// ==================== 2. wit-bindgen-go 生成绑定 ====================
|
|
37
|
+
|
|
38
|
+
const bindgen = requireTool("WIT_BINDGEN_GO", "wit-bindgen-go");
|
|
39
|
+
rmSync(GEN_OUT, { recursive: true, force: true });
|
|
40
|
+
execFileSync(
|
|
41
|
+
bindgen,
|
|
42
|
+
["generate", "--world", BINDGEN_WORLD, "--package-root", `${MODULE}/gen`, "--out", GEN_OUT, WIT_OUT],
|
|
43
|
+
{ stdio: "inherit", cwd: GO_DIR },
|
|
44
|
+
);
|
|
45
|
+
if (!existsSync(join(GEN_OUT, "wasmnest", "plugin"))) {
|
|
46
|
+
throw new Error(`生成物缺 gen/wasmnest/plugin(world ${BINDGEN_WORLD} 生成异常)`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(
|
|
50
|
+
`gen-bindings: world ${BINDGEN_WORLD} → ${GEN_OUT}(wasmnest:plugin 绑定已生成;TinyGo 构建用 -wit-world ${BUILD_WORLD})`,
|
|
51
|
+
);
|
package/go/wit/core.wit
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/// WasmNest 插件 Component Model 契约——**内核机制能力(single source of truth)**
|
|
2
|
+
///
|
|
3
|
+
/// 本文件是 wasm-core 单一 crate 的核心 WIT 真源(ADR 0037 / ADR 0052 D1):
|
|
4
|
+
/// **core 只收内核自己实现、双端同源、且为内核机制必需 / 全部插件共同需要的
|
|
5
|
+
/// interface**(storage / plugin-database / log / config / events / bus / fs /
|
|
6
|
+
/// platform / metrics / worker + 三个导出 + events-binary / events-worker)。
|
|
7
|
+
///
|
|
8
|
+
/// 业务能力契约(设备发现 / 对等网络 / 出站 HTTP / WS 客户端 / 通知 / 终端流…)
|
|
9
|
+
/// **不落 core**:双端功能级交集住能力域 crate 的 `wit/<domain>.wit`(契约与实现
|
|
10
|
+
/// 同处,ADR 0052 D2/D3),只有一端有的功能住该端 `cap-*.wit`(ADR 0052 D4)。
|
|
11
|
+
/// 端生成物由 `scripts/compose-wit.mjs` 按 `compose.json` 将 core 与各 cap 分片
|
|
12
|
+
/// 同 package **同版本**拼装(版本不一致即拼装失败——wasmtime 的 `include` 要求
|
|
13
|
+
/// package 同名同版本)。
|
|
14
|
+
///
|
|
15
|
+
/// 迁移约定(与桌面端原 wasmnest.wit 头注释一致):
|
|
16
|
+
/// - `serde_json` 载荷保留:结构化参数/结果一律用 `string` 承载 JSON
|
|
17
|
+
/// - 错误一律 `result<T, string>`,错误内容为宿主侧可读的 UTF-8 消息
|
|
18
|
+
/// - 宿主能力 import 接口前缀 `host-`,插件导出接口为普通名字
|
|
19
|
+
/// - 端内版本演进历史不在此复制(复制即漂移源):逐版语义台账在
|
|
20
|
+
/// `CHANGELOG.md` / `CHANGELOG_zh.md`「契约演进台账(整数 ABI)」节
|
|
21
|
+
/// (记账去处 = ADR 0051 D5;整数 ABI 已随 wit 包版本化退役,
|
|
22
|
+
/// 台账自此为**只读历史**,不再随契约变更追加),各端 `cap-*.wit` 头注释保全迁移说明
|
|
23
|
+
///
|
|
24
|
+
/// 组合方式(端生成物 `wit/` 目录,由 `scripts/compose-wit.mjs` 拼装):
|
|
25
|
+
/// `world plugin { include core; include cap-…; }` —— **import** 名带版本
|
|
26
|
+
/// (`wasmnest:plugin@<version>/<interface>`,版本取自 `wasmnest-contract` crate 的
|
|
27
|
+
/// `PACKAGE_VERSION`/`PACKAGE`);
|
|
28
|
+
/// **导出**实例的键同样带版本(`ns:pkg/<iface>@<version>`,实例内函数名按平名),
|
|
29
|
+
/// 故运行期探测导出必须用 `contract::export_item` / `interface_path` 派生带版本的
|
|
30
|
+
/// 名字——平名或漏版本的写法对版本化产物恒不命中。
|
|
31
|
+
package wasmnest:plugin@0.1.0;
|
|
32
|
+
/// 插件 KV 存储(原 storage.rs:storage_get/set/delete)
|
|
33
|
+
interface host-storage {
|
|
34
|
+
get: func(key: string) -> result<option<string>, string>;
|
|
35
|
+
set: func(key: string, value: string) -> result<_, string>;
|
|
36
|
+
delete: func(key: string) -> result<_, string>;
|
|
37
|
+
}
|
|
38
|
+
/// 事件(原 events.rs:emit_event;broadcast-sync 随 websocket 业务下沉
|
|
39
|
+
/// 退役——插件事件走 bus/emit,宿主不再持同步广播面)
|
|
40
|
+
///
|
|
41
|
+
/// 双端交集切片:原桌面独有 `notify` 已按功能级交集统一进共享域契约
|
|
42
|
+
/// `host-notify`(真源 `packages/wasmnest-notify-engine/wit/notify.wit`,ADR 0052 D3;
|
|
43
|
+
/// 桌面 `host-events-desktop` 随之退役),本接口只剩双端交集 `emit`。
|
|
44
|
+
interface host-events {
|
|
45
|
+
emit: func(event-name: string, payload-json: string);
|
|
46
|
+
}
|
|
47
|
+
/// 消息总线(原 bus.rs:bus_publish/subscribe/unsubscribe)
|
|
48
|
+
///
|
|
49
|
+
/// ## topic 命名空间(总线是强制边界,不只是约定)
|
|
50
|
+
///
|
|
51
|
+
/// - **私有命名空间** `<plugin-id>::<name>`:某插件的收件箱。宿主按属主定向投递
|
|
52
|
+
/// 生命周期事件(`<owner>::pty:exit`、`<owner>::ws:*`、`<owner>::mdns:found|lost`)。
|
|
53
|
+
/// **只有属主能订阅、只有属主与宿主能发布**——跨命名空间的订阅/伪发布在 Rust 端
|
|
54
|
+
/// 显式拒绝(错误透传给 guest,不静默丢弃)。分隔符 `::` 为保留字:插件 id 字符集
|
|
55
|
+
/// 是 `[a-z0-9-]` 分段,`:` 不可能出现,故属主判定无歧义且不依赖激活态/安装态。
|
|
56
|
+
/// 边界由**串形态**决定(机制 B),而非「解析 owner 段 + 查插件表」(机制 A)——
|
|
57
|
+
/// 后者的判定会随属主是否已激活/是否已安装而漏。
|
|
58
|
+
/// - **公开 topic**(不含 `::`):插件间广播道(`task:*` / `peer:*` /
|
|
59
|
+
/// `wasmnest.api.*`),任何已激活插件可订阅可发布。
|
|
60
|
+
/// - **互调回复道** `wasmnest.api.reply.<caller>.<request-id>`:caller 的收件箱但
|
|
61
|
+
/// 刻意留在公开道形态(响应者是他人,必须能发布进来)。窃听由「订阅面 host-only」
|
|
62
|
+
/// 堵(回复订阅由宿主在 `host-api-call` 内静态注册),抢答由「宿主校验回复 `sender`
|
|
63
|
+
/// == api 声明属主」堵(`sender` 由宿主按 Caller state 落章,guest 不可自报)。
|
|
64
|
+
///
|
|
65
|
+
/// 载荷格式:
|
|
66
|
+
/// - `publish`(JSON 文本,v1 起):结构化载荷,现有订阅方零回归;
|
|
67
|
+
/// - `publish-binary`(字节列,v11 起):零 JSON 编解码,可传非 UTF-8
|
|
68
|
+
/// 与大载荷(MB 级)。订阅方以 `subscribe-binary` 声明二进制格式偏好,
|
|
69
|
+
/// 格式不匹配的投递被宿主拒绝(不进入订阅者队列)并告警
|
|
70
|
+
interface host-bus {
|
|
71
|
+
publish: func(topic: string, payload-json: string) -> result<_, string>;
|
|
72
|
+
/// 二进制载荷发布(字节列原样透传,零 JSON 编解码,可传非 UTF-8 与大载荷)
|
|
73
|
+
publish-binary: func(topic: string, payload: list<u8>) -> result<_, string>;
|
|
74
|
+
subscribe: func(topic: string) -> result<_, string>;
|
|
75
|
+
/// 以二进制格式偏好订阅——只接收 publish-binary 投递,
|
|
76
|
+
/// JSON 消息对其按格式不匹配拒绝
|
|
77
|
+
subscribe-binary: func(topic: string) -> result<_, string>;
|
|
78
|
+
unsubscribe: func(topic: string) -> result<_, string>;
|
|
79
|
+
}
|
|
80
|
+
/// 通用平台能力域(ADR 0022 v2):系统对话框/授权等与领域无关的平台交互
|
|
81
|
+
///
|
|
82
|
+
/// 双端交集切片:桌面独有 `wsl-distros` / `local-ipv4-addresses` /
|
|
83
|
+
/// `reveal-in-dir` 拆入 [`host-platform-desktop`](cap-desktop 分片),
|
|
84
|
+
/// 本接口承载双端交集的 `pick-files` / `pick-folders`,外加双端全等的
|
|
85
|
+
/// `platform`(宿主平台标识探测)。
|
|
86
|
+
///
|
|
87
|
+
/// **目录选择已按功能级统一**(2026-10-13,ADR 0052 D3):原 `pick-folder`
|
|
88
|
+
/// (单目录字符串,双端)与桌面 `host-platform-desktop.pick-folders`
|
|
89
|
+
/// (多目录 JSON)是同一功能的两种形状 → 统一为本接口的 `pick-folders`
|
|
90
|
+
/// (`string[]` JSON;移动 SAF 目录树选择器为单选语义,返回 0/1 项)。
|
|
91
|
+
interface host-platform {
|
|
92
|
+
/// 系统多文件选择器 → string[] JSON(用户取消为空数组)。
|
|
93
|
+
///
|
|
94
|
+
/// **权限 `fs:pick`(manifest 必须单独声明)**:未声明即 `Err`,且**不弹对话框**
|
|
95
|
+
/// ——「能调起选择器」与「能读写任意路径」是两种权力,合成一位会让只想让用户
|
|
96
|
+
/// 挑一个文件的插件被动获得全盘读取面(权限位判据见 SDK `PERMISSION_FS_PICK`)。
|
|
97
|
+
///
|
|
98
|
+
/// **浏览面不设限、结果面设门**:系统原生对话框(Windows IFileDialog /
|
|
99
|
+
/// Linux xdg-desktop-portal)允许用户浏览**任意**位置——浏览由用户在系统
|
|
100
|
+
/// 对话框里驱动,宿主不读任何数据;选择结束后宿主才对**选中的路径**做
|
|
101
|
+
/// `fs_auth` 授权校验(见下)。
|
|
102
|
+
///
|
|
103
|
+
/// **选择后的授权校验**(本原语契约的另一半,缺一不可):
|
|
104
|
+
/// - 选中路径命中**已授权目录**前缀(或第一方归属目录)→ 静默放行,不再弹框;
|
|
105
|
+
/// - 存在未授权路径 → 就未授权部分弹**一次**授权框(多路径合并一次询问);
|
|
106
|
+
/// - 用户拒绝 / 超时 / 无弹窗通道(无头上下文)→ `Err`,**不回传任何路径**
|
|
107
|
+
/// (fail-visible:不得把「弹了框被拒」降级成空数组)。
|
|
108
|
+
/// 「记住」按**所在目录**落账(文件 → 父目录,目录 → 自身),使同目录下的
|
|
109
|
+
/// 后续选择免弹。
|
|
110
|
+
///
|
|
111
|
+
/// 授权只交付「可访问用户亲手选中的路径」这一层;实际读 / 写仍分别要
|
|
112
|
+
/// `fs:read` / `fs:write`(`pick-*` 不隐含读写位)。
|
|
113
|
+
pick-files: func() -> result<string, string>;
|
|
114
|
+
/// 系统文件夹选择器(多选)→ string[] JSON;用户取消返回空数组。
|
|
115
|
+
/// 权限 `fs:pick` + 选择后授权校验(授权落账到所选目录本身),口径同
|
|
116
|
+
/// `pick-files`。移动端为 SAF 目录树选择器(单选语义),返回 0/1 个
|
|
117
|
+
/// 树 URI。
|
|
118
|
+
pick-folders: func() -> result<string, string>;
|
|
119
|
+
/// 宿主平台标识探测(双端全等;**无权限门**——平台事实不是能力,ADR 0022 裁剪线)。
|
|
120
|
+
///
|
|
121
|
+
/// 取值由各端宿主定义(当前约定:桌面 `desktop` / 移动 `mobile`);guest 用于
|
|
122
|
+
/// 运行期平台分支——双端共享 wasm 产物(如 file-transfer 单产物,规格
|
|
123
|
+
/// `.scratch/2026-10-13-file-transfer-single-wasm/spec.md`)据此在同一 trait
|
|
124
|
+
/// 的双实现间选择,无需双份产物。空/未知取值时 guest 侧按 fail-visible
|
|
125
|
+
/// 处理(显性报错,不猜默认平台——猜错会把桌面分支静默跑在移动宿主上)。
|
|
126
|
+
platform: func() -> string;
|
|
127
|
+
}
|
|
128
|
+
/// 文件系统访问(原 fs.rs:fs_read/write/copy/delete/exists;双端交集 6 函数)
|
|
129
|
+
///
|
|
130
|
+
/// 双端交集切片:桌面独有 `read-dir` / `canonicalize` / `stat`
|
|
131
|
+
/// (文件浏览域)拆入 [`host-fs-desktop`](cap-desktop 分片),移动端独有
|
|
132
|
+
/// `save-to-document` / `write-media-downloads` 拆入 [`host-fs-mobile`]
|
|
133
|
+
/// (cap-mobile 分片),本接口只剩双端交集。
|
|
134
|
+
interface host-fs {
|
|
135
|
+
read: func(path: string) -> result<option<string>, string>;
|
|
136
|
+
write: func(path: string, data: string) -> result<_, string>;
|
|
137
|
+
copy: func(src: string, dst: string) -> result<_, string>;
|
|
138
|
+
delete: func(path: string) -> result<_, string>;
|
|
139
|
+
exists: func(path: string) -> result<bool, string>;
|
|
140
|
+
/// 批量请求目录授权:未授权路径合并为一次用户弹窗,阻塞等待答复
|
|
141
|
+
/// (paths-json 为 JSON 字符串数组;返回是否全部同意)
|
|
142
|
+
request-auth: func(paths-json: string) -> result<bool, string>;
|
|
143
|
+
}
|
|
144
|
+
/// 宿主日志与插件状态上报(原 log.rs + status.rs)
|
|
145
|
+
interface host-log {
|
|
146
|
+
info: func(message: string);
|
|
147
|
+
debug: func(message: string);
|
|
148
|
+
warn: func(message: string);
|
|
149
|
+
error: func(message: string);
|
|
150
|
+
mark-plugin-error: func(error: string);
|
|
151
|
+
}
|
|
152
|
+
/// 宿主配置读取(原 config.rs:config_get,key 为 ConfigKey::as_str 的字符串)
|
|
153
|
+
interface host-config {
|
|
154
|
+
get: func(key: string) -> result<option<string>, string>;
|
|
155
|
+
}
|
|
156
|
+
/// 运行监控(core-monitor):只读运行时指标快照
|
|
157
|
+
///
|
|
158
|
+
/// **权限 `metrics:read`(manifest 必须单独声明)**:未声明即 `Err`。
|
|
159
|
+
/// 返回 JSON 字符串,形状与内核 `MetricsRegistry::snapshot()` 逐字一致:
|
|
160
|
+
/// `{ "plugins": { "<plugin_id>": {...} }, "<source>": {...} }`——每插件段含
|
|
161
|
+
/// 内存 current/peak、调用次数/在飞数、燃料总量、耗时 total/max/直方图、
|
|
162
|
+
/// trap 原因分布、生命周期计数与最近时间、授权决策、总线背压、配额上限。
|
|
163
|
+
///
|
|
164
|
+
/// 语义边界:
|
|
165
|
+
/// - **只读**:不重置任何计数器,不影响被观测插件;
|
|
166
|
+
/// - **无业务内容**:只有数值计数与 plugin_id / 枚举键,不含会话文本、文件内容、
|
|
167
|
+
/// 凭据或任何应用数据;
|
|
168
|
+
/// - **全局可见**:授权一次即可读**所有已加载插件**的聚合指标(监控用途所需),
|
|
169
|
+
/// 因此可据此推断其他应用的活跃度(侧信道)——权限描述已写明;
|
|
170
|
+
/// - 快照源未装配(无头 / 测试上下文)时 `Err`(fail-visible,不返回空对象冒充)。
|
|
171
|
+
interface host-metrics {
|
|
172
|
+
snapshot: func() -> result<string, string>;
|
|
173
|
+
}
|
|
174
|
+
/// 插件独立数据库(原 database.rs:plugin_db_*)
|
|
175
|
+
interface host-plugin-database {
|
|
176
|
+
execute: func(sql: string) -> result<u32, string>;
|
|
177
|
+
query: func(sql: string) -> result<option<string>, string>;
|
|
178
|
+
execute-params: func(sql: string, params-json: string) -> result<u32, string>;
|
|
179
|
+
query-params: func(sql: string, params-json: string) -> result<option<string>, string>;
|
|
180
|
+
/// 事务内顺序执行多语句(sqls-json 为 SQL 字符串数组),返回受影响行数合计
|
|
181
|
+
execute-batch: func(sqls-json: string) -> result<u32, string>;
|
|
182
|
+
}
|
|
183
|
+
/// 命令入口(原 invoke_command,JSON 载荷保留)
|
|
184
|
+
interface command {
|
|
185
|
+
invoke: func(name: string, args-json: string) -> string;
|
|
186
|
+
}
|
|
187
|
+
/// 生命周期(原 activate/deactivate/on_startup/on_shutdown)
|
|
188
|
+
///
|
|
189
|
+
/// 四个导出均携带结果(v8):启动初始化/清理的成败由导出返回值如实上抛,
|
|
190
|
+
/// 宿主据此区分 Activated / Degraded,不再依赖「调用没抛错」推断成功
|
|
191
|
+
interface lifecycle {
|
|
192
|
+
activate: func() -> result<_, string>;
|
|
193
|
+
deactivate: func() -> result<_, string>;
|
|
194
|
+
on-startup: func() -> result<_, string>; // 补全:携带启动初始化结果
|
|
195
|
+
on-shutdown: func() -> result<_, string>; // 补全:携带清理结果(可观测性)
|
|
196
|
+
}
|
|
197
|
+
/// 二进制消息接收(可选导出,**不进 `plugin` world 的必选导出列表**)
|
|
198
|
+
///
|
|
199
|
+
/// 宿主在实例化后动态探测 `events-binary#on-message-binary`:
|
|
200
|
+
/// - 未导出本接口的插件 → 探测为 None,只接收 JSON 消息;二进制消息对其
|
|
201
|
+
/// 按「格式不匹配」拒绝,不影响加载;
|
|
202
|
+
/// - 导出者由 `wasm_entry!` 宏无条件导出(默认空实现),订阅方以
|
|
203
|
+
/// `host-bus.subscribe-binary` 声明偏好后即可接收二进制投递
|
|
204
|
+
///
|
|
205
|
+
/// 无返回值(观察型回调,语义同 terminal-hooks):guest 内部处理失败经
|
|
206
|
+
/// host-log 记录,不打断宿主投递链;host 侧仅 trap 会上抛
|
|
207
|
+
interface events-binary {
|
|
208
|
+
on-message-binary: func(topic: string, sender: string, payload: list<u8>);
|
|
209
|
+
}
|
|
210
|
+
/// 插件 manifest(原 __wasmnest_manifest,JSON 字符串)
|
|
211
|
+
interface manifest {
|
|
212
|
+
get: func() -> string;
|
|
213
|
+
}
|
|
214
|
+
/// worker 调度(主插件经宿主中介调用内嵌 worker 子资源,ADR 0059)
|
|
215
|
+
///
|
|
216
|
+
/// **权限 `worker:run`(manifest 必须单独声明)**:未声明即 `Err`——「占用宿主
|
|
217
|
+
/// 并行资源」的准入门(一线程一 worker,per-plugin 并发 4 / 全局 8),与
|
|
218
|
+
/// `task:run` 同款判据(并发能力与数据访问解耦授权)。
|
|
219
|
+
///
|
|
220
|
+
/// worker 本体是声明插件的**私属**子资源:插件包 `worker/` 目录 + manifest
|
|
221
|
+
/// `workers` 块声明(`[{name, file, wasmHash?, resourceOverrides?}]`),world
|
|
222
|
+
/// 本体在 `wit/worker.wit`(零宿主 import,仅 WASI 内建)。每次运行 = 全新
|
|
223
|
+
/// Store,零共享状态;worker 间通信只能走主插件编排。
|
|
224
|
+
///
|
|
225
|
+
/// - `submit` 受理语义:同步校验(worker 名不存在 / 输入超限 / 队列满)→ `Err`;
|
|
226
|
+
/// 受理成功返回 job id(1 submit = 1 run,fan-out = 连发 N 个 submit)。
|
|
227
|
+
/// 运行期失败(实例化 / trap / 燃料耗尽)→ [`events-worker`] 终态事件。
|
|
228
|
+
/// - `cancel` 语义 = 标记取消(非强杀):燃料自然终结、结果丢弃,不承诺强杀
|
|
229
|
+
/// (与 task 审计票 09 裁决同立场)。
|
|
230
|
+
/// - 传参 JSON string(输入 / 输出上限 1 MiB,真源 server-base constants);
|
|
231
|
+
/// 超大输入显性报错,文件路径留给 preopen 阶段。
|
|
232
|
+
interface host-worker {
|
|
233
|
+
submit: func(worker: string, input: string) -> result<string, string>;
|
|
234
|
+
cancel: func(job-id: string) -> result<_, string>;
|
|
235
|
+
}
|
|
236
|
+
/// worker 终态事件(可选导出,**不进 `plugin` world 的必选导出列表**,探测范式同
|
|
237
|
+
/// `events-binary`)
|
|
238
|
+
///
|
|
239
|
+
/// 宿主在实例化后动态探测 `events-worker#on-worker-event`:未导出本接口的插件
|
|
240
|
+
/// 照常 submit(事件无消费方);导出者每 job 只收**终态**一条(无 queued/running
|
|
241
|
+
/// 过程事件),事件 JSON 直载输出(无结果暂存仓库):
|
|
242
|
+
///
|
|
243
|
+
/// `{ "jobId": "...", "state": "succeeded|failed|canceled", "output"?: "<json>", "error"?: "<仅 failed>" }`
|
|
244
|
+
///
|
|
245
|
+
/// 回调队列满载 = 背压阻塞(完成线程等待,消费即放行;**不走 task 式丢弃**——
|
|
246
|
+
/// 事件直载输出无 status 快照可回退,丢弃 = 结果永久丢失,ADR 0059)。
|
|
247
|
+
/// 无返回值(观察型回调,语义同 events-binary):guest 内部处理失败经
|
|
248
|
+
/// host-log 记录,不打断宿主投递链。
|
|
249
|
+
interface events-worker {
|
|
250
|
+
on-worker-event: func(event: string);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 核心 world:只含内核机制能力(10 import + 3 必选导出;events-binary /
|
|
254
|
+
// events-worker 是可选导出面,不在 world 内)。合成 package 的每端 world plugin
|
|
255
|
+
// 由 include core 并入这些成员,其余端成员由各端 cap-*.wit 的 world 并入;业务
|
|
256
|
+
// 能力交集由双端 compose.json 直接消费能力域 crate 的 `wit/<domain>.wit`
|
|
257
|
+
//(ADR 0052 D2)。
|
|
258
|
+
world core {
|
|
259
|
+
import host-storage;
|
|
260
|
+
import host-events;
|
|
261
|
+
import host-bus;
|
|
262
|
+
import host-platform;
|
|
263
|
+
import host-fs;
|
|
264
|
+
import host-log;
|
|
265
|
+
import host-config;
|
|
266
|
+
import host-plugin-database;
|
|
267
|
+
import host-metrics;
|
|
268
|
+
import host-worker;
|
|
269
|
+
|
|
270
|
+
export command;
|
|
271
|
+
export lifecycle;
|
|
272
|
+
export manifest;
|
|
273
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package wasmnest:api-call@0.0.1;
|
|
2
|
+
|
|
3
|
+
// 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
|
|
4
|
+
// 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
|
|
5
|
+
// 端 `plugin` world 经 `include wasmnest:api-call/cap-api-call@0.0.1;` 并入本接口。
|
|
6
|
+
|
|
7
|
+
/// 插件互调(ADR-0017):发布 JSON-RPC 请求 + 同步等待回复
|
|
8
|
+
interface host-api-call {
|
|
9
|
+
/// 发布请求到 request-topic(宿主按 `wasmnest.api.*` 门禁校验目标 api
|
|
10
|
+
/// 已被某激活插件声明,未声明拒绝),并按调用方插件 ID + 请求载荷中的
|
|
11
|
+
/// 字符串 `id` 构造响应 topic(`wasmnest.api.reply.<caller-id>.<request-id>`),
|
|
12
|
+
/// 宿主侧注册静态回复订阅 + 阻塞等待(调用方 wasm 实例阻塞期间无法接收
|
|
13
|
+
/// on_message,回复必须宿主侧消费,见 SDK api_call 模块注释)。
|
|
14
|
+
/// 返回回复 JSON 字符串(result | error 对象);超时/门禁拒绝返回错误。
|
|
15
|
+
call: func(request-topic: string, payload-json: string, timeout-ms: u64) -> result<string, string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
world cap-api-call {
|
|
19
|
+
import host-api-call;
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package wasmnest:app@0.0.1;
|
|
2
|
+
|
|
3
|
+
// 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
|
|
4
|
+
// 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
|
|
5
|
+
// 端 `plugin` world 经 `include wasmnest:app/cap-app@0.0.1;` 并入本接口。
|
|
6
|
+
|
|
7
|
+
/// 插件随包 CLI 生命周期(v8:host-app)——安装/卸载到用户 bin 目录并注册 PATH
|
|
8
|
+
///
|
|
9
|
+
/// WASM 插件无注册表/文件系统写权限的直接通道,PATH 操作由宿主侧实现:
|
|
10
|
+
/// 插件在 activate 时安装自身随包的 cli/ 产物(如 bedtask),停用时卸载。
|
|
11
|
+
/// 幂等:重复安装不产生重复条目,升级覆盖;卸载仅移除本插件条目。
|
|
12
|
+
interface host-app {
|
|
13
|
+
/// 安装 CLI(幂等):源 = 插件包目录 `cli/<file-name>`(Windows 自动补 .exe),
|
|
14
|
+
/// 复制到用户 bin 目录并注册 PATH;`bin-dir` 为空用平台默认
|
|
15
|
+
/// (Windows `%LOCALAPPDATA%/com.wasmnest.app/bin`;unix `~/.wasmnest/bin`)。
|
|
16
|
+
/// 返回安装后的 bin 目录绝对路径。
|
|
17
|
+
install-cli: func(payload-json: string) -> result<string, string>;
|
|
18
|
+
/// 卸载 CLI(幂等):删除文件 + 移除仅本插件添加的 PATH 条目
|
|
19
|
+
/// (保留用户原有项);应用关闭流程中调用时自动跳过(CLI 随下次激活重建)
|
|
20
|
+
uninstall-cli: func(payload-json: string) -> result<_, string>;
|
|
21
|
+
/// 插件自身资源目录(v25 函数级追加,**不 bump**):返回本插件安装目录的
|
|
22
|
+
/// 绝对路径(宿主 `extension_path` 剥离 verbatim 前缀后的形态,插件侧正斜杠
|
|
23
|
+
/// 拼接可用),与 `on-session-lifecycle` payload 的 `resource_dir` 同值。
|
|
24
|
+
///
|
|
25
|
+
/// 裁剪线判据(ADR 0022):宿主本来就持有插件加载路径,返回的是**调用方
|
|
26
|
+
/// 自己的**目录、不含任何跨插件信息,零业务语义。**不设权限门**(同
|
|
27
|
+
/// `host-platform` 口径)——没有可授予的权力,加门只会造出一个恒过的死门。
|
|
28
|
+
///
|
|
29
|
+
/// 存在理由:会话创建编排整体移交插件后(session-engine-downsink P1-b),
|
|
30
|
+
/// 宿主不再产生 `Creating` 生命周期事件,插件失去获取自身资源目录的唯一
|
|
31
|
+
/// 途径(Agent 集成 hook 脚本源在该目录下,见插件 `task/hooks`)。
|
|
32
|
+
/// 插件未加载 / 宿主服务不可用 → `Err`(不静默返回空串)。
|
|
33
|
+
plugin-resource-dir: func() -> result<string, string>;
|
|
34
|
+
/// 把某个目录登记进**用户级 PATH**(幂等):payload `{ "dir": "<绝对路径>" }`
|
|
35
|
+
/// (`scope` 只接受 `"user"`,缺省即 user;出现其他值即拒绝——本原语不做
|
|
36
|
+
/// 机器级 PATH,也就没有提权面)。
|
|
37
|
+
///
|
|
38
|
+
/// Windows:把目录追加进 `HKCU\Environment\Path`(保留 `REG_EXPAND_SZ`
|
|
39
|
+
/// 类型与用户原有项,写后广播 `WM_SETTINGCHANGE`,新开终端立即生效);
|
|
40
|
+
/// unix:为目录下每个可执行文件建 `~/.local/bin` 符号链接。
|
|
41
|
+
///
|
|
42
|
+
/// **安全闸门(机制级)**:目录必须落在 allowlist 根之内(应用数据根
|
|
43
|
+
/// `~/.wasmnest` / `%LOCALAPPDATA%/com.wasmnest.app` / `~/.local`)、必须是
|
|
44
|
+
/// 绝对路径且已存在、无控制字符——PATH 是**持久化**用户环境面,越界目录
|
|
45
|
+
/// 一律拒绝并点名实际路径。权限 `app:path`(与 `app:cli` 分域)。
|
|
46
|
+
register-path: func(payload-json: string) -> result<_, string>;
|
|
47
|
+
/// 从用户级 PATH 精确摘除该目录(幂等):payload 同 `register-path`。
|
|
48
|
+
/// 只摘本目录的条目/链接,用户原有项与其他目录不动;条目不存在即成功。
|
|
49
|
+
unregister-path: func(payload-json: string) -> result<_, string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
world cap-app {
|
|
53
|
+
import host-app;
|
|
54
|
+
}
|