tauri-cordis 0.0.0-stage → 0.2.0

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 (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/examples/hello/host.mjs +16 -0
  4. package/examples/hello/island.js +33 -0
  5. package/examples/minimal-app/builtins/builtins.json +11 -0
  6. package/examples/minimal-app/builtins/notes/host.mjs +18 -0
  7. package/examples/minimal-app/plugins/word-count/host.mjs +26 -0
  8. package/examples/minimal-app/plugins/word-count/package.json +37 -0
  9. package/examples/minimal-app/plugins/word-count/window.mjs +11 -0
  10. package/examples/minimal-app/run.mjs +173 -0
  11. package/examples/minimal-app/services.mjs +11 -0
  12. package/package.json +83 -3
  13. package/src/client/bridge.mjs +37 -0
  14. package/src/client/connection.mjs +139 -0
  15. package/src/client/index.d.mts +94 -0
  16. package/src/client/index.mjs +7 -0
  17. package/src/client/loader.mjs +73 -0
  18. package/src/client/react.d.mts +24 -0
  19. package/src/client/react.mjs +40 -0
  20. package/src/client/services.d.mts +27 -0
  21. package/src/client/services.mjs +87 -0
  22. package/src/client/shims/react-jsx-runtime.js +1 -0
  23. package/src/client/shims/react.js +8 -0
  24. package/src/client/slot-service.mjs +13 -0
  25. package/src/client/slots.d.mts +50 -0
  26. package/src/client/slots.mjs +132 -0
  27. package/src/client/window-services.d.mts +28 -0
  28. package/src/client/window-services.mjs +251 -0
  29. package/src/host/blame.mjs +25 -0
  30. package/src/host/builtins.mjs +143 -0
  31. package/src/host/client-only.mjs +3 -0
  32. package/src/host/clients.mjs +149 -0
  33. package/src/host/commands.mjs +322 -0
  34. package/src/host/data.mjs +22 -0
  35. package/src/host/gate.mjs +140 -0
  36. package/src/host/http.mjs +85 -0
  37. package/src/host/index.d.mts +246 -0
  38. package/src/host/index.mjs +13 -0
  39. package/src/host/kernel.mjs +147 -0
  40. package/src/host/logs.mjs +25 -0
  41. package/src/host/main.mjs +125 -0
  42. package/src/host/owner.mjs +23 -0
  43. package/src/host/plugin-config.mjs +215 -0
  44. package/src/host/plugins-file.mjs +13 -0
  45. package/src/host/reload.mjs +39 -0
  46. package/src/host/rpc.mjs +117 -0
  47. package/src/host/rust.mjs +120 -0
  48. package/src/host/services.mjs +256 -0
  49. package/src/host/share.mjs +21 -0
  50. package/src/host/sockets.mjs +86 -0
  51. package/src/host/sources.mjs +150 -0
  52. package/src/host/status.mjs +134 -0
  53. package/src/host/timer.mjs +89 -0
  54. package/src/host/usage.mjs +129 -0
  55. package/src/host/windows.mjs +384 -0
  56. package/src/index.d.mts +120 -0
  57. package/src/index.mjs +1 -0
  58. package/src/protocol.d.mts +45 -0
  59. package/src/protocol.mjs +57 -0
  60. package/src/services.d.mts +219 -0
  61. package/src/services.mjs +63 -0
  62. package/vendor/README.md +32 -0
  63. package/vendor/cordis/LICENSE +21 -0
  64. package/vendor/cordis/core/LICENSE +21 -0
  65. package/vendor/cordis/core/README.md +10 -0
  66. package/vendor/cordis/core/lib/context.d.ts +32 -0
  67. package/vendor/cordis/core/lib/events.d.ts +64 -0
  68. package/vendor/cordis/core/lib/fiber.d.ts +91 -0
  69. package/vendor/cordis/core/lib/index.d.ts +7 -0
  70. package/vendor/cordis/core/lib/index.js +1691 -0
  71. package/vendor/cordis/core/lib/logger.d.ts +69 -0
  72. package/vendor/cordis/core/lib/reflect.d.ts +58 -0
  73. package/vendor/cordis/core/lib/registry.d.ts +86 -0
  74. package/vendor/cordis/core/lib/service.d.ts +21 -0
  75. package/vendor/cordis/core/lib/utils.d.ts +58 -0
  76. package/vendor/cordis/core/package.json +56 -0
  77. package/vendor/cordis/fs/LICENSE +21 -0
  78. package/vendor/cordis/fs/README.md +1 -0
  79. package/vendor/cordis/fs/lib/error.d.ts +13 -0
  80. package/vendor/cordis/fs/lib/index.d.ts +64 -0
  81. package/vendor/cordis/fs/lib/index.js +231 -0
  82. package/vendor/cordis/fs/lib/watcher.d.ts +45 -0
  83. package/vendor/cordis/fs/package.json +43 -0
  84. package/vendor/cordis/fs-node/LICENSE +21 -0
  85. package/vendor/cordis/fs-node/README.md +1 -0
  86. package/vendor/cordis/fs-node/lib/index.d.ts +7 -0
  87. package/vendor/cordis/fs-node/lib/index.js +108 -0
  88. package/vendor/cordis/fs-node/lib/watcher.d.ts +3 -0
  89. package/vendor/cordis/fs-node/package.json +51 -0
  90. package/vendor/cordis/hmr/LICENSE +21 -0
  91. package/vendor/cordis/hmr/README.md +86 -0
  92. package/vendor/cordis/hmr/lib/error.d.ts +2 -0
  93. package/vendor/cordis/hmr/lib/index.d.ts +189 -0
  94. package/vendor/cordis/hmr/lib/index.js +1305 -0
  95. package/vendor/cordis/hmr/lib/runtime/index.d.ts +4 -0
  96. package/vendor/cordis/hmr/lib/runtime/internal.d.ts +115 -0
  97. package/vendor/cordis/hmr/lib/runtime/modules.d.ts +69 -0
  98. package/vendor/cordis/hmr/lib/runtime/patches.d.ts +22 -0
  99. package/vendor/cordis/hmr/lib/runtime/resolution.d.ts +55 -0
  100. package/vendor/cordis/hmr/package.json +58 -0
  101. package/vendor/cordis/include/LICENSE +21 -0
  102. package/vendor/cordis/include/README.md +1 -0
  103. package/vendor/cordis/include/lib/index.d.ts +83 -0
  104. package/vendor/cordis/include/lib/index.js +972 -0
  105. package/vendor/cordis/include/lib/journal.d.ts +68 -0
  106. package/vendor/cordis/include/lib/patch.d.ts +68 -0
  107. package/vendor/cordis/include/package.json +31 -0
  108. package/vendor/cordis/loader/LICENSE +21 -0
  109. package/vendor/cordis/loader/README.md +1 -0
  110. package/vendor/cordis/loader/lib/config/entry.d.ts +64 -0
  111. package/vendor/cordis/loader/lib/config/group.d.ts +26 -0
  112. package/vendor/cordis/loader/lib/config/isolate.d.ts +29 -0
  113. package/vendor/cordis/loader/lib/config/tree.d.ts +56 -0
  114. package/vendor/cordis/loader/lib/config/utils.d.ts +33 -0
  115. package/vendor/cordis/loader/lib/index.d.ts +49 -0
  116. package/vendor/cordis/loader/lib/index.js +1179 -0
  117. package/vendor/cordis/loader/lib/internal.d.ts +12 -0
  118. package/vendor/cordis/loader/lib/resolve.d.ts +2 -0
  119. package/vendor/cordis/loader/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TixXin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,87 @@
1
- # Temporary Holding Version
1
+ # `tauri-cordis`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Everything-is-a-plugin** runtime base for **Tauri + Node.js + React** applications, powered by [Cordis](https://github.com/cordiverse/cordis) (MIT).
4
+
5
+ Built-in features and third-party extensions run as equal-privilege Cordis plugins with managed, disposable side effects:
6
+ - **Headless Node.js Host** supervised by Rust (stdio JSON-RPC, heartbeats, exponential backoff restarts, Job Object / process group containment, Node discovery & SHA-256 verified fallback download).
7
+ - **Direct Window WebSocket** (`127.0.0.1` with per-launch random token & `Origin` check — zero Tauri `emit` / `Channel` WebView memory leak).
8
+ - **Versioned Services & Seams** (`defineService("notes/v1", ...)`, `ctx.services.provide`, `ctx.services.get`, `createWindowServices`, conflict reporting & `replaces` handoff).
9
+ - **Typed Window Slots** (`createSlots`, `SlotItems` with per-item React `ErrorBoundary` + `Suspense`, deterministic ordering & replacement rollback).
10
+ - **End-to-End Plugin Supply Chain** (`@tauri-cordis/manifest`, `@tauri-cordis/market`, `@tauri-cordis/review`, `@tauri-cordis/cli`, `create-tauri-cordis-plugin`).
11
+ - **62 Tested Runtime Guarantees** — see [`docs/guarantees.md`](https://github.com/TixXin/tauri-cordis/blob/main/docs/guarantees.md).
12
+
13
+ ---
14
+
15
+ ## Architecture
16
+
17
+ ```text
18
+ ┌─────────────────────────────┐ stdio JSON-RPC ┌─────────────────────────────────┐
19
+ │ Native Shell (Rust / Tauri)│ <-----------------------> │ Node.js Plugin Host (headless) │
20
+ │ - Supervisor & heartbeats │ │ - Cordis root context & loader │
21
+ │ - #[host_service] methods │ │ - Versioned service registry │
22
+ │ - Allowlisted protocol │ │ - Managed timers / fault gate │
23
+ └─────────────────────────────┘ └─────────────────────────────────┘
24
+ ^ ^
25
+ │ invoke (window geometry / OS ops) │ 127.0.0.1 WebSocket (token + Origin check)
26
+ v v
27
+ ┌───────────────────────────────────────────────────────────────────────────────────────────┐
28
+ │ WebView Windows (React Clients) │
29
+ │ - Slot registry (createSlots / SlotItems, isolated ErrorBoundary per contributed item) │
30
+ │ - Window services (createWindowServices: local window provider -> host fallback) │
31
+ │ - Client module loader (createLoader with shared React shims) │
32
+ └───────────────────────────────────────────────────────────────────────────────────────────┘
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Packages & Crates
38
+
39
+ | Package / Crate | Registry | Description |
40
+ |---|---|---|
41
+ | `tauri-cordis` | npm | Core plugin API (`Context`, `Service`), Node host (`tauri-cordis/host`), window client & React slots (`tauri-cordis/client`, `tauri-cordis/client/react`), versioned services (`tauri-cordis/services`), protocol constants |
42
+ | `@tauri-cordis/manifest` | npm | `package.json` plugin manifest validator, deterministic zip packager, Ed25519 signatures |
43
+ | `@tauri-cordis/market` | npm | Signed market index & revocation list verification, serial monotonicity, expiry & cooldown version selector |
44
+ | `@tauri-cordis/review` | npm | Version-to-version source & bundle diff risk analyzer (green / yellow / red tiers) |
45
+ | `@tauri-cordis/cli` | npm | `tauri-cordis-plugin` CLI (`build`, `pack`, `check`, `dev`, `review`, `keygen`, `sign`) |
46
+ | `create-tauri-cordis-plugin` | npm | Project scaffolder (`npm create tauri-cordis-plugin@latest`) |
47
+ | `tauri-cordis` | crates.io | Rust host supervisor, Node locator/downloader, stdio JSON-RPC bridge, custom-protocol static asset server |
48
+ | `tauri-cordis-macros` | crates.io | `#[host_service]` procedural macro with `ts-rs` TypeScript declaration export |
49
+
50
+ ---
51
+
52
+ ## Quick Start & Minimal Example
53
+
54
+ Run the standalone 4-layer minimal application (shell JSON-RPC pipe + Node host subprocess + built-in `notes` service plugin + `@demo/word-count` window slot plugin):
55
+
56
+ ```bash
57
+ pnpm install
58
+ node packages/tauri-cordis/examples/minimal-app/run.mjs
59
+ ```
60
+
61
+ Run all JavaScript/TypeScript and Rust guarantee test suites:
62
+
63
+ ```bash
64
+ pnpm check
65
+ cargo test
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Host Application Customization
71
+
72
+ `tauri-cordis` decouples host-app naming from the runtime core:
73
+
74
+ - **Manifest key & scope**: `validateManifest(pkg, { appKey: "myApp", officialScope: "my-app", categories })`
75
+ - **Package extension & signature**: `packDirectory(dir, { namespace: "my-app", extension: ".myapp" })`
76
+ - **Slot schema**: `createSlots(mySlotRules)`
77
+ - **Built-in catalog**: `startHost({ dir, builtins: "builtins/builtins.json", apiNames: ["my-app-plugin"] })`
78
+
79
+ ---
80
+
81
+ ## Publishing Releases
82
+
83
+ Releases are automated via [`.github/workflows/release.yml`](https://github.com/TixXin/tauri-cordis/blob/main/.github/workflows/release.yml) when pushing a `v*` tag (or running workflow dispatch), publishing crates in dependency order (`tauri-cordis-macros` -> `tauri-cordis`) and npm packages (`@tauri-cordis/manifest`, `@tauri-cordis/market`, `@tauri-cordis/review`, `tauri-cordis`, `@tauri-cordis/cli`, `create-tauri-cordis-plugin`) with `CARGO_REGISTRY_TOKEN` and `NPM_TOKEN`.
84
+
85
+ ## License
86
+
87
+ [MIT](https://github.com/TixXin/tauri-cordis/blob/main/LICENSE)
@@ -0,0 +1,16 @@
1
+ import { Service } from "tauri-cordis";
2
+
3
+ export default class Hello extends Service {
4
+ static inject = ["clients"];
5
+
6
+ constructor(ctx) {
7
+ super(ctx, "hello");
8
+ this.count = 0;
9
+ ctx.clients.add("island", new URL("./island.js", import.meta.url).href);
10
+ ctx.clients.handle("greet", (params) => `hello ${params?.who ?? "there"}, from the plugin host (pid ${process.pid})`);
11
+ ctx.setInterval(() => {
12
+ this.count += 1;
13
+ ctx.clients.publish("tick", this.count);
14
+ }, 1000);
15
+ }
16
+ }
@@ -0,0 +1,33 @@
1
+ import React, { useEffect, useState } from "../__shared/react.js";
2
+
3
+ const style = {
4
+ display: "flex",
5
+ justifyContent: "space-between",
6
+ gap: 8,
7
+ margin: "4px 8px",
8
+ padding: "4px 8px",
9
+ borderRadius: "var(--fuyu-plugin-radius)",
10
+ font: "12px ui-monospace, monospace",
11
+ color: "var(--fuyu-plugin-text-secondary)",
12
+ background: "var(--fuyu-plugin-surface)",
13
+ minWidth: 0,
14
+ whiteSpace: "nowrap",
15
+ };
16
+ const greetingStyle = { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis" };
17
+ const countStyle = { flexShrink: 0, color: "var(--fuyu-plugin-text-muted)" };
18
+
19
+ export default function apply(ctx) {
20
+ function Hello() {
21
+ const [count, setCount] = useState(null);
22
+ const [greeting, setGreeting] = useState("");
23
+ useEffect(() => {
24
+ const off = ctx.host.on("tick", setCount);
25
+ ctx.host.call("greet", { who: "island" }).then(setGreeting, (error) => setGreeting(String(error.message)));
26
+ return () => {
27
+ void off();
28
+ };
29
+ }, []);
30
+ return React.createElement("div", { style, "data-plugin": "hello" }, React.createElement("span", { style: greetingStyle }, greeting || "…"), React.createElement("span", { style: countStyle }, count === null ? "" : `#${count}`));
31
+ }
32
+ ctx.slots.add("island.dev/v1", { id: "hello", component: Hello });
33
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "format": 1,
3
+ "plugins": [
4
+ {
5
+ "id": "notes",
6
+ "kind": "builtin",
7
+ "root": "notes",
8
+ "host": "host.mjs"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,18 @@
1
+ import { notesV1 } from "../../services.mjs";
2
+
3
+ export const name = "notes";
4
+
5
+ export function apply(ctx) {
6
+ const provider = ctx.services.provide(notesV1, {
7
+ list: () => ctx.rust.call("storage.read"),
8
+ add: async (params) => {
9
+ const text = String(params?.text ?? "").trim();
10
+ const note = await ctx.rust.call("storage.write", { text });
11
+ provider.emit("added", note);
12
+ return note;
13
+ },
14
+ });
15
+ ctx.rust.on("storage.seeded", (note) => {
16
+ provider.emit("added", note);
17
+ });
18
+ }
@@ -0,0 +1,26 @@
1
+ import { notesV1 } from "../../services.mjs";
2
+
3
+ export const name = "word-count";
4
+ export const inject = ["clients", "notes/v1"];
5
+
6
+ function wordsOf(text) {
7
+ return String(text ?? "")
8
+ .trim()
9
+ .split(/\s+/)
10
+ .filter(Boolean).length;
11
+ }
12
+
13
+ export async function apply(ctx) {
14
+ const notes = ctx.services.get(notesV1);
15
+ const initial = await notes.list({});
16
+ const state = {
17
+ notes: initial.length,
18
+ words: initial.reduce((sum, item) => sum + wordsOf(item.text), 0),
19
+ };
20
+ ctx.clients.handle("summary", () => ({ ...state }));
21
+ notes.on("added", (note) => {
22
+ state.notes += 1;
23
+ state.words += wordsOf(note.text);
24
+ ctx.clients.publish("updated", { ...state });
25
+ });
26
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@demo/word-count",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": "github:demo/word-count",
7
+ "engines": {
8
+ "fuyu": ">=0.1.0"
9
+ },
10
+ "fuyu": {
11
+ "manifest": 1,
12
+ "displayName": {
13
+ "zh-CN": "字数统计",
14
+ "en": "Word Count"
15
+ },
16
+ "description": {
17
+ "zh-CN": "统计笔记条数与总词数",
18
+ "en": "Counts notes and words across notes"
19
+ },
20
+ "icon": "icon.svg",
21
+ "categories": [
22
+ "utilities"
23
+ ],
24
+ "host": "host.mjs",
25
+ "client": {
26
+ "main": "window.mjs"
27
+ },
28
+ "inject": {
29
+ "required": [
30
+ "notes/v1"
31
+ ]
32
+ },
33
+ "slots": [
34
+ "main.panel/v1"
35
+ ]
36
+ }
37
+ }
@@ -0,0 +1,11 @@
1
+ export default function apply(ctx) {
2
+ async function renderPanel() {
3
+ const summary = await ctx.host.call("summary");
4
+ return `${summary.notes} notes, ${summary.words} words`;
5
+ }
6
+ ctx.slots.add("main.panel/v1", {
7
+ id: "word-count",
8
+ order: 10,
9
+ component: renderPanel,
10
+ });
11
+ }
@@ -0,0 +1,173 @@
1
+ import { spawn } from "node:child_process";
2
+ import { mkdtempSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { createInterface } from "node:readline";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import WebSocket from "ws";
8
+ import { connectHost, createBridge, createLoader, createServiceProxy, createSlots, createWindowServices } from "tauri-cordis/client";
9
+ import { notesV1 } from "./services.mjs";
10
+
11
+ const HERE = fileURLToPath(new URL(".", import.meta.url));
12
+ const HOST_MAIN = fileURLToPath(new URL("../../src/host/main.mjs", import.meta.url));
13
+ const BUILTINS_DIR = join(HERE, "builtins");
14
+ const WORD_COUNT_DIR = join(HERE, "plugins", "word-count");
15
+ const ORIGIN = "tauri://localhost";
16
+
17
+ function waitFor(predicate, timeoutMs = 8000) {
18
+ const deadline = Date.now() + timeoutMs;
19
+ return new Promise((resolve, reject) => {
20
+ const step = () => {
21
+ try {
22
+ const value = predicate();
23
+ if (value) return resolve(value);
24
+ } catch (error) {
25
+ return reject(error);
26
+ }
27
+ if (Date.now() >= deadline) return reject(new Error("timed out waiting for condition"));
28
+ setTimeout(step, 20);
29
+ };
30
+ step();
31
+ });
32
+ }
33
+
34
+ function startShellAndHost(dataDir) {
35
+ const store = [{ id: 1, text: "hello world" }];
36
+ const child = spawn(
37
+ process.execPath,
38
+ ["--disallow-code-generation-from-strings", HOST_MAIN, "--dir", dataDir, "--builtins", BUILTINS_DIR, "--watch"],
39
+ { stdio: ["pipe", "pipe", "pipe"] },
40
+ );
41
+ const messages = [];
42
+ const send = (payload) => child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...payload })}\n`);
43
+ createInterface({ input: child.stdout }).on("line", (line) => {
44
+ const message = JSON.parse(line);
45
+ messages.push(message);
46
+ if (message.id === undefined) return;
47
+ if (message.method === "storage.read") {
48
+ send({ id: message.id, result: store });
49
+ return;
50
+ }
51
+ if (message.method === "storage.write") {
52
+ const note = { id: store.length + 1, text: String(message.params?.text ?? "") };
53
+ store.push(note);
54
+ send({ id: message.id, result: note });
55
+ return;
56
+ }
57
+ send({ id: message.id, error: { code: "no-method", message: `no shell method ${message.method}` } });
58
+ });
59
+ let stderr = "";
60
+ child.stderr.on("data", (chunk) => {
61
+ stderr += chunk;
62
+ });
63
+ const exited = new Promise((resolve) => child.on("exit", (code) => resolve(code)));
64
+ return { child, messages, send, exited, store, stderr: () => stderr };
65
+ }
66
+
67
+ function resolveClientFile(url) {
68
+ const path = new URL(url).pathname.replace(/^\/+/, "");
69
+ if (path.startsWith("dev/word-count/")) {
70
+ return join(WORD_COUNT_DIR, path.slice("dev/word-count/".length));
71
+ }
72
+ throw new Error(`unmapped client asset: ${path}`);
73
+ }
74
+
75
+ export async function runMinimalApp() {
76
+ const dataDir = mkdtempSync(join(tmpdir(), "plugin-base-minimal-app-"));
77
+ const writeConfig = (disabled = false) => {
78
+ const lines = [
79
+ "- id: word-count",
80
+ " source: dev",
81
+ ` path: ${JSON.stringify(WORD_COUNT_DIR)}`,
82
+ ...(disabled ? [" disabled: true"] : []),
83
+ "",
84
+ ];
85
+ writeFileSync(join(dataDir, "plugins.yml"), lines.join("\n"));
86
+ };
87
+ writeConfig(false);
88
+ const shell = startShellAndHost(dataDir);
89
+ let connection = null;
90
+ let loader = null;
91
+ try {
92
+ const ready = await waitFor(() => shell.messages.find((item) => item.method === "ready"));
93
+ const target = ready.params.windows;
94
+ const registry = createSlots({ "main.panel/v1": { kind: "list", perPlugin: 2 } });
95
+ const bridge = createBridge((method, params) => connection.call(method, params));
96
+ const proxy = createServiceProxy((method, params, options) => connection.call(method, params, options));
97
+ const windowServices = createWindowServices({ remote: proxy });
98
+ loader = createLoader({
99
+ registry,
100
+ bridge,
101
+ base: "app-plugin://localhost",
102
+ checkFile: async (url) => {
103
+ statSync(resolveClientFile(url));
104
+ },
105
+ importModule: (url) => import(pathToFileURL(resolveClientFile(url)).href),
106
+ });
107
+ const pluginMessages = [];
108
+ bridge.subscribe((message) => pluginMessages.push(message));
109
+ let latestClients = [];
110
+ let latestPlugins = ready.params.plugins;
111
+ connection = connectHost({
112
+ resolve: async () => target,
113
+ window: "main",
114
+ open: (url) => new WebSocket(url, { origin: ORIGIN }),
115
+ onSnapshot: (snapshot) => {
116
+ latestPlugins = snapshot.plugins;
117
+ latestClients = snapshot.clients.filter((entry) => entry.window === "main");
118
+ proxy.update(snapshot.services);
119
+ void proxy.resubscribe();
120
+ },
121
+ onEvent: (name, data) => {
122
+ if (name === "plugins") latestPlugins = data;
123
+ if (name === "clients") latestClients = data.filter((entry) => entry.window === "main");
124
+ if (name === "services") proxy.update(data);
125
+ if (name === "service") proxy.deliver(data);
126
+ if (name === "plugin") bridge.deliver(data);
127
+ },
128
+ });
129
+ await waitFor(() => connection.state === "open" && latestClients.length === 1);
130
+ await loader.sync(latestClients);
131
+ const itemsBefore = registry.items("main.panel/v1");
132
+ const renderedBefore = await itemsBefore[0].component();
133
+ const notesClient = windowServices.get(notesV1);
134
+ const heardNotes = [];
135
+ const offAdded = notesClient.on("added", (note) => heardNotes.push(note));
136
+ const added = await notesClient.add({ text: "plugin base works" });
137
+ await waitFor(() => heardNotes.length === 1 && pluginMessages.length === 1);
138
+ const renderedAfter = await itemsBefore[0].component();
139
+ const allNotes = await notesClient.list({});
140
+ await offAdded();
141
+ writeConfig(true);
142
+ await waitFor(() => latestPlugins.find((item) => item.id === "word-count")?.state === "disabled" && latestClients.length === 0);
143
+ await loader.sync(latestClients);
144
+ const itemsAfterDisable = registry.items("main.panel/v1");
145
+ connection.close();
146
+ connection = null;
147
+ await loader.stop();
148
+ loader = null;
149
+ shell.send({ id: 99, method: "stop" });
150
+ const exitCode = await shell.exited;
151
+ return {
152
+ protocol: ready.params.protocol,
153
+ initialPanel: renderedBefore,
154
+ addedNote: added,
155
+ updatedPanel: renderedAfter,
156
+ allNotes,
157
+ heardNotes,
158
+ pluginMessages,
159
+ slotsAfterDisable: itemsAfterDisable.length,
160
+ exitCode,
161
+ };
162
+ } finally {
163
+ connection?.close();
164
+ await loader?.stop();
165
+ shell.child.kill();
166
+ rmSync(dataDir, { recursive: true, force: true });
167
+ }
168
+ }
169
+
170
+ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
171
+ const result = await runMinimalApp();
172
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
173
+ }
@@ -0,0 +1,11 @@
1
+ import { defineService } from "tauri-cordis/services";
2
+
3
+ export const notesV1 = defineService("notes/v1", {
4
+ methods: {
5
+ list: true,
6
+ add: true,
7
+ },
8
+ events: {
9
+ added: true,
10
+ },
11
+ });
package/package.json CHANGED
@@ -1,6 +1,86 @@
1
1
  {
2
2
  "name": "tauri-cordis",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Everything-is-a-plugin runtime base for Tauri + Node + React built on Cordis: host supervisor protocol, versioned services, managed side effects, and window slots",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TixXin/tauri-cordis.git",
10
+ "directory": "packages/tauri-cordis"
11
+ },
12
+ "homepage": "https://github.com/TixXin/tauri-cordis",
13
+ "bugs": {
14
+ "url": "https://github.com/TixXin/tauri-cordis/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "src",
21
+ "vendor",
22
+ "examples",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "types": "./src/index.d.mts",
29
+ "default": "./src/index.mjs"
30
+ },
31
+ "./host": {
32
+ "types": "./src/host/index.d.mts",
33
+ "default": "./src/host/index.mjs"
34
+ },
35
+ "./client": {
36
+ "types": "./src/client/index.d.mts",
37
+ "default": "./src/client/index.mjs"
38
+ },
39
+ "./client/slots": {
40
+ "types": "./src/client/slots.d.mts",
41
+ "default": "./src/client/slots.mjs"
42
+ },
43
+ "./client/window-services": {
44
+ "types": "./src/client/window-services.d.mts",
45
+ "default": "./src/client/window-services.mjs"
46
+ },
47
+ "./client/react": {
48
+ "types": "./src/client/react.d.mts",
49
+ "default": "./src/client/react.mjs"
50
+ },
51
+ "./protocol": {
52
+ "types": "./src/protocol.d.mts",
53
+ "default": "./src/protocol.mjs"
54
+ },
55
+ "./services": {
56
+ "types": "./src/services.d.mts",
57
+ "default": "./src/services.mjs"
58
+ },
59
+ "./package.json": "./package.json"
60
+ },
61
+ "engines": {
62
+ "node": ">=22.15"
63
+ },
64
+ "dependencies": {
65
+ "@babel/code-frame": "^7.29.0",
66
+ "@standard-schema/spec": "^1.1.0",
67
+ "@tauri-cordis/manifest": "0.2.0",
68
+ "chokidar": "^4.0.3",
69
+ "cosmokit": "^1.8.1",
70
+ "picomatch": "^4.0.3",
71
+ "schemastery": "^3.18.0",
72
+ "ws": "^8.23.0",
73
+ "yaml": "^2.9.1"
74
+ },
75
+ "peerDependencies": {
76
+ "react": "^19.0.0"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "react": {
80
+ "optional": true
81
+ }
82
+ },
83
+ "scripts": {
84
+ "test": "node --test \"test/**/*.test.mjs\""
85
+ }
6
86
  }
@@ -0,0 +1,37 @@
1
+ import { Service } from "../../vendor/cordis/core/lib/index.js";
2
+
3
+ export class HostBridge extends Service {
4
+ constructor(ctx, bridge) {
5
+ super(ctx, "host");
6
+ this.bridge = bridge;
7
+ }
8
+
9
+ call(method, params) {
10
+ return this.bridge.call(this.ctx.fiber.name, method, params);
11
+ }
12
+
13
+ on(topic, listener) {
14
+ const plugin = this.ctx.fiber.name;
15
+ return this.ctx.effect(
16
+ () =>
17
+ this.bridge.subscribe((message) => {
18
+ if (message.plugin === plugin && message.topic === topic) listener(message.data);
19
+ }),
20
+ `ctx.host.on(${topic})`,
21
+ );
22
+ }
23
+ }
24
+
25
+ export function createBridge(call) {
26
+ const listeners = new Set();
27
+ return {
28
+ call: (plugin, method, params) => call("plugin.call", { plugin, method, params }),
29
+ subscribe(listener) {
30
+ listeners.add(listener);
31
+ return () => listeners.delete(listener);
32
+ },
33
+ deliver(message) {
34
+ for (const listener of listeners) listener(message);
35
+ },
36
+ };
37
+ }