@vibechain/os 0.4.1 → 0.5.1

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 (84) hide show
  1. package/AGENTS.md +80 -48
  2. package/README.md +143 -55
  3. package/SECURITY.md +47 -20
  4. package/dist/app-client.d.ts +4 -1
  5. package/dist/app-client.js +15 -4
  6. package/dist/app-host.d.ts +124 -9
  7. package/dist/app-host.js +395 -57
  8. package/dist/app-protocol.d.ts +17 -1
  9. package/dist/app-protocol.js +12 -0
  10. package/dist/app-runtime.d.ts +18 -2
  11. package/dist/app-runtime.js +75 -11
  12. package/dist/app-wire.d.ts +215 -0
  13. package/dist/app-wire.js +268 -0
  14. package/dist/browser.d.ts +3 -0
  15. package/dist/browser.js +3 -0
  16. package/dist/bundle.js +6 -6
  17. package/dist/canvas.d.ts +2 -2
  18. package/dist/canvas.js +3 -1
  19. package/dist/capture.d.ts +22 -0
  20. package/dist/capture.js +99 -0
  21. package/dist/check.d.ts +12 -0
  22. package/dist/check.js +167 -0
  23. package/dist/cli-publish.d.ts +24 -0
  24. package/dist/cli-publish.js +288 -0
  25. package/dist/cli-session.d.ts +108 -0
  26. package/dist/cli-session.js +245 -0
  27. package/dist/cli.d.ts +10 -0
  28. package/dist/cli.js +46 -10
  29. package/dist/index.d.ts +8 -0
  30. package/dist/index.js +4 -0
  31. package/dist/links.d.ts +15 -0
  32. package/dist/links.js +41 -0
  33. package/dist/listing.d.ts +3 -3
  34. package/dist/listing.js +1 -1
  35. package/dist/loop.d.ts +18 -2
  36. package/dist/loop.js +13 -1
  37. package/dist/manifest.d.ts +90 -4
  38. package/dist/manifest.js +340 -5
  39. package/dist/os.d.ts +63 -0
  40. package/dist/os.js +383 -0
  41. package/dist/preview-parent.d.ts +42 -0
  42. package/dist/preview-parent.js +134 -11
  43. package/dist/preview-ui.js +1 -1
  44. package/dist/preview.js +25 -7
  45. package/dist/redact.d.ts +6 -0
  46. package/dist/redact.js +16 -0
  47. package/dist/runtime-policy.d.ts +20 -0
  48. package/dist/runtime-policy.js +45 -0
  49. package/dist/scaffold.d.ts +13 -2
  50. package/dist/scaffold.js +95 -31
  51. package/dist/submit-notice.d.ts +26 -0
  52. package/dist/submit-notice.js +34 -0
  53. package/dist/templates/plain/game.js +18 -0
  54. package/dist/testing.d.ts +68 -0
  55. package/dist/testing.js +181 -1
  56. package/dist/transport.d.ts +22 -0
  57. package/dist/transport.js +71 -19
  58. package/dist/vibemarket-os.js +1 -0
  59. package/dist/worker.d.ts +18 -0
  60. package/dist/worker.js +34 -0
  61. package/examples/paw-beat/README.md +20 -8
  62. package/examples/paw-beat/cat.ts +665 -89
  63. package/examples/paw-beat/game.ts +162 -28
  64. package/examples/paw-beat/index.html +114 -40
  65. package/examples/paw-beat/main.ts +264 -149
  66. package/examples/paw-beat/music.ts +314 -65
  67. package/examples/paw-beat/stage.ts +560 -0
  68. package/examples/paw-beat/store/icon.png +0 -0
  69. package/examples/paw-beat/store/screenshot-1.webp +0 -0
  70. package/examples/paw-beat/store/screenshot-2.webp +0 -0
  71. package/examples/paw-beat/vibemarket.json +2 -2
  72. package/examples/vibexp-app/README.md +7 -7
  73. package/examples/vibexp-app/index.html +3 -2
  74. package/examples/vibexp-app/plain/game.ts +20 -0
  75. package/examples/vibexp-app/plain/index.html +6 -0
  76. package/examples/vibexp-app/plain/vibemarket.json +17 -0
  77. package/examples/vibexp-app/src/main.ts +46 -31
  78. package/examples/vibexp-app/store/icon.png +0 -0
  79. package/examples/vibexp-app/three/README.md +21 -0
  80. package/examples/vibexp-app/three/index.html +4 -0
  81. package/examples/vibexp-app/three/src/main.ts +45 -0
  82. package/examples/vibexp-app/three/vibemarket.json +19 -0
  83. package/examples/vibexp-app/vibemarket.json +17 -11
  84. package/package.json +6 -2
@@ -0,0 +1,6 @@
1
+ <!doctype html>
2
+ <meta charset="utf-8">
3
+ <title>Tap the Cat</title>
4
+ <button id="cat" style="font: 32px sans-serif; width: 100%; height: 100vh">Tap the cat</button>
5
+ <script src="vibemarket-os.js"></script>
6
+ <script src="game.js"></script>
@@ -0,0 +1,17 @@
1
+ {
2
+ "schemaVersion": 3,
3
+ "id": "tap-the-cat",
4
+ "version": "1.0.0",
5
+ "name": "Tap the Cat",
6
+ "tagline": "Thirty seconds. One cat. Tap.",
7
+ "entry": "index.html",
8
+ "window": { "width": 480, "height": 360, "resizable": false },
9
+ "store": {
10
+ "icon": "icon.png",
11
+ "screenshots": ["screenshot.png"],
12
+ "description": "Tap the cat as many times as you can in thirty seconds, then try to beat your best.",
13
+ "category": "game",
14
+ "rating": { "violence": "none", "language": "none", "mature": false },
15
+ "support": "you@example.com"
16
+ }
17
+ }
@@ -1,37 +1,52 @@
1
- import { connectVibeMarketApp, GAME_SCORE_LIMIT } from "@vibechain/os";
1
+ import { connect, GAME_SCORE_LIMIT } from "@vibechain/os";
2
+ import { fitCanvas } from "@vibechain/os/canvas";
2
3
 
3
- const count = document.querySelector<HTMLOutputElement>("#count");
4
- const button = document.querySelector<HTMLButtonElement>("#stamp");
5
- const status = document.querySelector<HTMLElement>("#status");
6
- const start = document.querySelector<HTMLButtonElement>("#start"), finish = document.querySelector<HTMLButtonElement>("#finish");
7
- const intro = document.querySelector<HTMLElement>("#intro"), round = document.querySelector<HTMLElement>("#round");
8
- if (!count || !button || !status || !start || !finish || !intro || !round) throw Error("Starter markup is missing.");
9
- const sdk = await connectVibeMarketApp();
10
- const checkpoint = await sdk.checkpoint.read();
11
- let stamps = checkpoint !== null && typeof checkpoint === "object" && !Array.isArray(checkpoint)
12
- && typeof checkpoint.stamps === "number" && Number.isSafeInteger(checkpoint.stamps) && checkpoint.stamps >= 0 && checkpoint.stamps <= GAME_SCORE_LIMIT ? checkpoint.stamps : 0;
13
- const paint = () => { count.value = String(stamps); };
14
- paint();
15
- const playing = checkpoint !== null && typeof checkpoint === "object" && !Array.isArray(checkpoint) && checkpoint.playing === true;
16
- intro.hidden = playing; round.hidden = !playing;
17
- button.disabled = false;
18
- finish.disabled = false;
4
+ /** What Stamp Club saves: the best round, kept by the host between opens (signed-in players). */
5
+ interface Save { best: number }
6
+ interface Stamp { x: number; y: number; hue: number }
7
+ const element = <T extends HTMLElement>(id: string) => { const node = document.getElementById(id); if (!node) throw Error(`Starter markup is missing #${id}.`); return node as T; };
8
+ const board = element<HTMLCanvasElement>("board"), count = element<HTMLOutputElement>("count"), status = element("status");
9
+ const start = element<HTMLButtonElement>("start"), finish = element<HTMLButtonElement>("finish");
10
+ const context = board.getContext("2d");
11
+ if (!context) throw Error("This browser cannot draw 2D canvas.");
12
+
13
+ const os = await connect();
14
+ const saved = await os.load<Save>();
15
+ let best = typeof saved?.best === "number" ? saved.best : 0, stamps: Stamp[] = [], playing = false, scale = 1;
16
+
17
+ function draw() {
18
+ context!.setTransform(scale, 0, 0, scale, 0, 0);
19
+ context!.clearRect(0, 0, board.width, board.height);
20
+ context!.font = "bold 28px Arial"; context!.textAlign = "center"; context!.textBaseline = "middle";
21
+ for (const stamp of stamps) {
22
+ context!.fillStyle = `hsl(${stamp.hue} 70% 45%)`;
23
+ context!.beginPath(); context!.arc(stamp.x, stamp.y, 22, 0, Math.PI * 2); context!.fill();
24
+ context!.fillStyle = "#fff"; context!.fillText("★", stamp.x, stamp.y + 1);
25
+ }
26
+ count.value = String(stamps.length);
27
+ }
28
+ fitCanvas(os, board, { onResize: fit => { scale = fit.pixelRatio; draw(); } });
29
+ const say = (text: string) => { status.textContent = text; };
30
+ say(best ? `Your best round: ${best} stamps.` : "Start a round, then press the board to place stamps.");
19
31
  start.disabled = false;
20
32
  start.addEventListener("click", () => {
21
- start.disabled = true;
22
- void sdk.checkpoint.write({ stamps, playing: true }).then(() => { intro.hidden = true; round.hidden = false; })
23
- .catch(() => { status.textContent = "This app session ended. Restore the window to reconnect."; start.disabled = false; });
33
+ stamps = []; playing = true; start.disabled = true; finish.disabled = false; draw();
34
+ say("Press the board to place stamps. Finish when you are done.");
24
35
  });
25
- finish.addEventListener("click", () => {
26
- button.disabled = true; finish.disabled = true;
27
- void sdk.game.finish({ score: stamps }).catch(() => { status.textContent = "The game session ended. Check the host result before retrying."; });
36
+ board.addEventListener("pointerdown", event => {
37
+ if (!playing || !os.active || stamps.length >= GAME_SCORE_LIMIT) return;
38
+ const box = board.getBoundingClientRect();
39
+ stamps.push({ x: event.clientX - box.left, y: event.clientY - box.top, hue: (stamps.length * 47) % 360 });
40
+ draw();
28
41
  });
29
- button.addEventListener("click", () => {
30
- button.disabled = true;
31
- void sdk.checkpoint.write({ stamps: stamps + 1, playing: true }).then(() => { stamps++; paint(); status.textContent = "Saved in this open VibeMarket OS window. Try minimizing and restoring it."; })
32
- .catch(() => { status.textContent = "This app session ended. Restore the window to reconnect."; })
33
- .finally(() => { button.disabled = !sdk.lifecycle.current().active || stamps === GAME_SCORE_LIMIT; });
42
+ finish.addEventListener("click", async () => {
43
+ playing = false; finish.disabled = true;
44
+ try {
45
+ if (stamps.length > best) { best = stamps.length; await os.save({ best } satisfies Save); }
46
+ await os.finish({ score: stamps.length });
47
+ } catch { say("The app session ended. Check the host's result before retrying."); }
34
48
  });
35
- sdk.lifecycle.onChanged(state => { button.disabled = !state.active || stamps === GAME_SCORE_LIMIT; });
36
- window.addEventListener("pagehide", () => sdk.destroy(), { once: true });
37
- await sdk.ready();
49
+ os.onPause(() => { say("Paused while the window is in the background."); });
50
+ os.onResume(() => { say(playing ? "Back again: keep stamping." : `Your best round: ${best} stamps.`); });
51
+ window.addEventListener("pagehide", () => os.close(), { once: true });
52
+ await os.ready();
Binary file
@@ -0,0 +1,21 @@
1
+ # Card Spinner
2
+
3
+ The Three.js starter of `os init --template three`: a card that spins in 3D. When `vibemarket.json` links a vmOS pack, the card shows that pack's first card art; otherwise it draws a placeholder face.
4
+
5
+ Run `npm install`, `npm run build`, then `npm run dev`, and open the printed **127.0.0.1** URL.
6
+
7
+ ## Showing a pack's cards
8
+
9
+ Add the pack's slug (the last part of its `vibechain.com/os/pack/<slug>` link) to `vibemarket.json`:
10
+
11
+ ```json
12
+ "packs": ["rooftop-rats"]
13
+ ```
14
+
15
+ `os.pack(slug)` then returns the pack's public card list with art URLs, and `os.showPack(slug)` (after a click) opens the pack in VibeMarket. A pack you did not create is linked only after its creator approves the request your submission sends. To read which cards the player holds, also set `"cards": "linked"` (the linked packs) or `"cards": "all"` (every vmOS pack the player holds). The preview fakes six cards per linked pack.
16
+
17
+ Card art is served from your app's own address with `Access-Control-Allow-Origin: *`, so it works as a WebGL texture: Three.js's `TextureLoader` sets `crossOrigin = "anonymous"` for you. An `<img>` you make yourself needs `img.crossOrigin = "anonymous"` before `src`.
18
+
19
+ ## Before you submit to VibeStore
20
+
21
+ Replace the placeholder `id`, `name`, `tagline`, `store.description`, `store.support`, the icon and the screenshot, as the Stamp Club starter's README lists. `npm run check` lists every problem first. A person reviews every version, and approval is publication: an approved version is copied to public IPFS.
@@ -0,0 +1,4 @@
1
+ <!doctype html>
2
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Card Spinner</title>
3
+ <style>html,body{margin:0;height:100%;background:#10131c;color:#e8ecf5;font:14px Arial;overflow:hidden}canvas{display:block;width:100%;height:100%}p{position:fixed;left:0;right:0;bottom:8px;margin:0;text-align:center;opacity:.8}</style></head>
4
+ <body><canvas id="scene"></canvas><p id="status" role="status">Connecting to the host…</p><script type="module" src="./main.js"></script></body></html>
@@ -0,0 +1,45 @@
1
+ import * as THREE from "three";
2
+ import { connect, OsError, type PackCard } from "@vibechain/os";
3
+ import { fitCanvas } from "@vibechain/os/canvas";
4
+ import { createLoop } from "@vibechain/os/loop";
5
+
6
+ const canvas = document.getElementById("scene") as HTMLCanvasElement, status = document.getElementById("status") as HTMLElement;
7
+ const os = await connect();
8
+
9
+ const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
10
+ const scene = new THREE.Scene(), camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
11
+ camera.position.set(0, 0, 6);
12
+ scene.add(new THREE.AmbientLight(0xffffff, 1.6));
13
+ const light = new THREE.DirectionalLight(0xffffff, 2); light.position.set(2, 3, 4); scene.add(light);
14
+
15
+ /** A placeholder face drawn on a canvas, used when no linked pack has art. */
16
+ function placeholder(): THREE.Texture {
17
+ const face = document.createElement("canvas"); face.width = 320; face.height = 448;
18
+ const draw = face.getContext("2d")!;
19
+ draw.fillStyle = "#3b5bdb"; draw.fillRect(0, 0, face.width, face.height);
20
+ draw.fillStyle = "#fff"; draw.font = "bold 48px Arial"; draw.textAlign = "center"; draw.fillText("vmOS", face.width / 2, face.height / 2);
21
+ return new THREE.CanvasTexture(face);
22
+ }
23
+ /** The first card with art of the first linked pack, or null. */
24
+ async function firstCard(): Promise<PackCard | null> {
25
+ try {
26
+ for (const summary of await os.packs()) {
27
+ const card = (await os.pack(summary.id)).cards.find(item => item.art !== null);
28
+ if (card) return card;
29
+ }
30
+ } catch (error) { if (!(error instanceof OsError) || error.code !== "unsupported") throw error; }
31
+ return null;
32
+ }
33
+ const card = await firstCard();
34
+ const texture = card?.art ? await new THREE.TextureLoader().loadAsync(card.art) : placeholder();
35
+ texture.colorSpace = THREE.SRGBColorSpace;
36
+ const front = new THREE.MeshStandardMaterial({ map: texture }), edge = new THREE.MeshStandardMaterial({ color: 0x222833 });
37
+ const mesh = new THREE.Mesh(new THREE.BoxGeometry(2.5, 3.5, 0.04), [edge, edge, edge, edge, front, front]);
38
+ scene.add(mesh);
39
+ status.textContent = card ? `${card.name} · ${card.rarity}` : "Link a pack in vibemarket.json to show its art.";
40
+
41
+ fitCanvas(os, canvas, { onResize: ({ width, height }) => { renderer.setSize(width, height, false); camera.aspect = width / height; camera.updateProjectionMatrix(); } });
42
+ let angle = 0;
43
+ const loop = createLoop(os, { update: stepMs => { angle += stepMs / 1000; }, render: () => { mesh.rotation.y = angle; renderer.render(scene, camera); } });
44
+ window.addEventListener("pagehide", () => { loop.stop(); os.close(); }, { once: true });
45
+ await os.ready();
@@ -0,0 +1,19 @@
1
+ {
2
+ "schemaVersion": 3,
3
+ "id": "card-spinner",
4
+ "version": "1.0.0",
5
+ "name": "Card Spinner",
6
+ "tagline": "A vmOS card, spinning in 3D.",
7
+ "entry": "index.html",
8
+ "window": { "width": 640, "height": 480, "resizable": true },
9
+ "store": {
10
+ "icon": "store/icon.png",
11
+ "screenshots": ["store/screenshot-1.png"],
12
+ "description": "Replace this description before you submit. It is the placeholder text of the VibeMarket OS Three.js starter: a card spinning in 3D, drawn with the art of a vmOS pack when vibemarket.json links one. Describe your own app here in plain text.",
13
+ "category": "app",
14
+ "rating": { "violence": "none", "language": "none", "mature": false },
15
+ "support": "https://example.com/replace-with-your-support-page"
16
+ },
17
+ "packs": [],
18
+ "cards": "none"
19
+ }
@@ -1,21 +1,27 @@
1
1
  {
2
- "schemaVersion": 2,
3
- "sdkVersion": 1,
2
+ "schemaVersion": 3,
4
3
  "id": "stamp-club",
5
4
  "version": "1.0.0",
6
5
  "name": "Stamp Club",
7
- "tagline": "A tiny VibeMarket OS app with restorable state.",
8
- "category": "vibexp-app",
6
+ "tagline": "A tiny VibeMarket OS app with a saved best.",
9
7
  "entry": "index.html",
10
- "permissions": [],
11
- "collectionId": null,
12
- "window": { "width": 640, "height": 480, "resizable": true },
8
+ "window": {
9
+ "width": 640,
10
+ "height": 480,
11
+ "resizable": true
12
+ },
13
13
  "store": {
14
14
  "icon": "store/icon.png",
15
- "screenshots": ["store/screenshot-1.png"],
16
- "description": "Replace this description before you submit. It is the placeholder text of the VibeMarket OS starter app, Stamp Club: start a round, add stamps, minimize and restore the window to see them come back, then finish to report a score. Describe your own app here in plain text.",
17
- "category": "toy",
18
- "rating": { "violence": "none", "language": "none", "mature": false },
15
+ "screenshots": [
16
+ "store/screenshot-1.png"
17
+ ],
18
+ "description": "Replace this description before you submit. It is the placeholder text of the VibeMarket OS starter app, Stamp Club: start a round, press the board to place stamps, finish to report a score, and your best round is saved for the next time you open it. Describe your own app here in plain text.",
19
+ "category": "app",
20
+ "rating": {
21
+ "violence": "none",
22
+ "language": "none",
23
+ "mature": false
24
+ },
19
25
  "support": "https://example.com/replace-with-your-support-page"
20
26
  }
21
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibechain/os",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -34,6 +34,10 @@
34
34
  "types": "./dist/listing.d.ts",
35
35
  "import": "./dist/listing.js"
36
36
  },
37
+ "./policy": {
38
+ "types": "./dist/runtime-policy.d.ts",
39
+ "import": "./dist/runtime-policy.js"
40
+ },
37
41
  "./loop": {
38
42
  "types": "./dist/loop.d.ts",
39
43
  "import": "./dist/loop.js"
@@ -52,7 +56,7 @@
52
56
  "vibemarket-game": "./dist/bin.js"
53
57
  },
54
58
  "scripts": {
55
- "build": "tsc && esbuild src/preview-parent.ts --bundle --minify --format=esm --target=es2022 --outfile=dist/preview-ui.js",
59
+ "build": "tsc && esbuild src/preview-parent.ts --bundle --minify --format=esm --target=es2022 --outfile=dist/preview-ui.js && esbuild src/browser.ts --bundle --minify --format=iife --global-name=VibemarketOS --target=es2022 --outfile=dist/vibemarket-os.js && esbuild examples/vibexp-app/plain/game.ts --format=iife --target=es2022 --outfile=dist/templates/plain/game.js",
56
60
  "typecheck": "tsc --noEmit",
57
61
  "review": "pnpm typecheck && tsc -p examples/tsconfig.json && vitest run --coverage",
58
62
  "check:package": "publint --pack npm && attw --pack --profile esm-only",