@vibechain/os 0.4.1 → 0.5.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 (79) hide show
  1. package/AGENTS.md +76 -48
  2. package/README.md +131 -54
  3. package/SECURITY.md +45 -20
  4. package/dist/app-client.d.ts +4 -1
  5. package/dist/app-client.js +4 -1
  6. package/dist/app-host.d.ts +111 -9
  7. package/dist/app-host.js +339 -58
  8. package/dist/app-protocol.d.ts +2 -0
  9. package/dist/app-runtime.d.ts +18 -2
  10. package/dist/app-runtime.js +75 -11
  11. package/dist/app-wire.d.ts +194 -0
  12. package/dist/app-wire.js +253 -0
  13. package/dist/browser.d.ts +2 -0
  14. package/dist/browser.js +2 -0
  15. package/dist/bundle.js +6 -6
  16. package/dist/canvas.d.ts +2 -2
  17. package/dist/canvas.js +3 -1
  18. package/dist/check.d.ts +12 -0
  19. package/dist/check.js +167 -0
  20. package/dist/cli-publish.d.ts +24 -0
  21. package/dist/cli-publish.js +288 -0
  22. package/dist/cli-session.d.ts +108 -0
  23. package/dist/cli-session.js +245 -0
  24. package/dist/cli.d.ts +10 -0
  25. package/dist/cli.js +46 -10
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.js +3 -0
  28. package/dist/listing.d.ts +3 -3
  29. package/dist/listing.js +1 -1
  30. package/dist/loop.d.ts +18 -2
  31. package/dist/loop.js +13 -1
  32. package/dist/manifest.d.ts +90 -4
  33. package/dist/manifest.js +340 -5
  34. package/dist/os.d.ts +56 -0
  35. package/dist/os.js +354 -0
  36. package/dist/preview-parent.d.ts +36 -0
  37. package/dist/preview-parent.js +122 -11
  38. package/dist/preview-ui.js +1 -1
  39. package/dist/preview.js +25 -7
  40. package/dist/redact.d.ts +6 -0
  41. package/dist/redact.js +16 -0
  42. package/dist/runtime-policy.d.ts +20 -0
  43. package/dist/runtime-policy.js +45 -0
  44. package/dist/scaffold.d.ts +13 -2
  45. package/dist/scaffold.js +95 -31
  46. package/dist/submit-notice.d.ts +26 -0
  47. package/dist/submit-notice.js +34 -0
  48. package/dist/templates/plain/game.js +18 -0
  49. package/dist/testing.d.ts +63 -0
  50. package/dist/testing.js +157 -1
  51. package/dist/transport.d.ts +20 -0
  52. package/dist/transport.js +71 -19
  53. package/dist/vibemarket-os.js +1 -0
  54. package/dist/worker.d.ts +18 -0
  55. package/dist/worker.js +34 -0
  56. package/examples/paw-beat/README.md +20 -8
  57. package/examples/paw-beat/cat.ts +665 -89
  58. package/examples/paw-beat/game.ts +162 -28
  59. package/examples/paw-beat/index.html +114 -40
  60. package/examples/paw-beat/main.ts +264 -149
  61. package/examples/paw-beat/music.ts +314 -65
  62. package/examples/paw-beat/stage.ts +560 -0
  63. package/examples/paw-beat/store/icon.png +0 -0
  64. package/examples/paw-beat/store/screenshot-1.webp +0 -0
  65. package/examples/paw-beat/store/screenshot-2.webp +0 -0
  66. package/examples/paw-beat/vibemarket.json +2 -2
  67. package/examples/vibexp-app/README.md +7 -7
  68. package/examples/vibexp-app/index.html +3 -2
  69. package/examples/vibexp-app/plain/game.ts +20 -0
  70. package/examples/vibexp-app/plain/index.html +6 -0
  71. package/examples/vibexp-app/plain/vibemarket.json +17 -0
  72. package/examples/vibexp-app/src/main.ts +46 -31
  73. package/examples/vibexp-app/store/icon.png +0 -0
  74. package/examples/vibexp-app/three/README.md +21 -0
  75. package/examples/vibexp-app/three/index.html +4 -0
  76. package/examples/vibexp-app/three/src/main.ts +45 -0
  77. package/examples/vibexp-app/three/vibemarket.json +19 -0
  78. package/examples/vibexp-app/vibemarket.json +17 -11
  79. package/package.json +6 -2
@@ -0,0 +1,245 @@
1
+ import { spawn as spawnProcess } from "node:child_process";
2
+ import { randomBytes } from "node:crypto";
3
+ import { constants } from "node:fs";
4
+ import { lstat, mkdir, open, rename, unlink } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { createInterface } from "node:readline";
7
+ import { printable, redact } from "./redact.js";
8
+ /**
9
+ * The CLI's sign-in plumbing (VibeStore's build contract, section 11): where the token lives, which host it may go to, how a
10
+ * request is made and what an error may print. The commands are in cli-publish.ts.
11
+ *
12
+ * The token is a bearer secret. It is read only from the credentials file or `VIBEMARKET_OS_TOKEN`, never from an argument;
13
+ * it is sent only in an Authorization header, only to the origin that issued it, never across a redirect; and every line
14
+ * this CLI prints about a request passes `redact`.
15
+ */
16
+ export const DEFAULT_ORIGIN = "https://vibechain.com";
17
+ export const TOKEN_ENV = "VIBEMARKET_OS_TOKEN";
18
+ /** The CLI token's only shape (vibemarket/steam/os-cli.ts `OS_CLI_TOKEN`; a website test binds the two). */
19
+ export const CLI_TOKEN = /^vmos_cli_[A-Za-z0-9_-]{43}$/;
20
+ export const CLI_TOKEN_ID = /^[a-f0-9]{16}$/;
21
+ export const DEVICE_CODE = /^[A-Za-z0-9_-]{43}$/;
22
+ export const USER_CODE = /^[BCDFGHJKLMNPQRSTVWXZ]{4}-[BCDFGHJKLMNPQRSTVWXZ]{4}$/;
23
+ export const CLI_PAGE = "/os/cli";
24
+ export const API_PREFIX = "/api/os/cli/";
25
+ const CREDENTIALS = "credentials.json", CREDENTIALS_MAX = 4096, ANSWER_MAX = 1024 * 1024;
26
+ // ---------- what may be printed ----------
27
+ export { printable, redact } from "./redact.js";
28
+ /** A device label as the backend accepts it (1 to 64 characters, no control or format characters). */
29
+ export function deviceLabel(hostname, platform) {
30
+ // never empty: the platform in parentheses is always there
31
+ return printable(`${hostname.slice(0, 48)} (${platform})`).replace(/\s+/g, " ").trim().slice(0, 64);
32
+ }
33
+ /** vibechain.com, or with `--origin` a loopback HTTP server for local development only. */
34
+ export function resolveOrigin(flag) {
35
+ if (flag === undefined || flag === DEFAULT_ORIGIN)
36
+ return { origin: DEFAULT_ORIGIN, development: false };
37
+ let url = null;
38
+ try {
39
+ url = new URL(flag);
40
+ }
41
+ catch { /* refused below */ }
42
+ if (!url || url.protocol !== "http:" || !["127.0.0.1", "localhost"].includes(url.hostname) || !url.port || url.username || url.password
43
+ || url.pathname !== "/" || url.search || url.hash || flag.replace(/\/$/, "") !== url.origin)
44
+ throw Error("--origin accepts only http://127.0.0.1:<port> or http://localhost:<port>, for local development. Without it the CLI talks to https://vibechain.com.");
45
+ return { origin: url.origin, development: true };
46
+ }
47
+ /** `$XDG_CONFIG_HOME/vibemarket-os` when it is absolute; else the platform's per-user config directory. Never the project. */
48
+ export function configDirectory(storage) {
49
+ const { env, home, platform } = storage;
50
+ const xdg = env.XDG_CONFIG_HOME, appData = env.APPDATA;
51
+ if (xdg && path.isAbsolute(xdg))
52
+ return path.join(xdg, "vibemarket-os");
53
+ if (platform === "darwin")
54
+ return path.join(home, "Library", "Application Support", "vibemarket-os");
55
+ // node:path is path.win32 on Windows itself
56
+ if (platform === "win32")
57
+ return path.join(appData && path.win32.isAbsolute(appData) ? appData : path.join(home, "AppData", "Roaming"), "vibemarket-os");
58
+ return path.join(home, ".config", "vibemarket-os");
59
+ }
60
+ export const credentialPath = (storage) => path.join(configDirectory(storage), CREDENTIALS);
61
+ /** node:fs rejects with ErrnoException objects only. */
62
+ const code = (error) => error.code;
63
+ /** O_NOFOLLOW where the platform has it (Windows does not: undefined | 0 is 0). */
64
+ const NOFOLLOW = constants.O_NOFOLLOW | 0;
65
+ /**
66
+ * POSIX: the directory and file must be this user's, not symlinks, and closed to group and others. Windows has no such mode
67
+ * bits (Node reports 0o666); the file relies on the per-user ACL of %APPDATA%.
68
+ */
69
+ function guard(storage, stat, name, mode) {
70
+ if (storage.platform === "win32")
71
+ return;
72
+ if ((stat.mode & 0o077) !== 0)
73
+ throw Error(`${name} can be read by other users. Fix it with: chmod ${mode} '${name}' (or run os logout and os login again).`);
74
+ if (storage.uid !== undefined && stat.uid !== storage.uid)
75
+ throw Error(`${name} belongs to another user. Remove it and run os login again.`);
76
+ }
77
+ async function guardDirectory(storage, directory) {
78
+ let stat;
79
+ try {
80
+ stat = await lstat(directory);
81
+ }
82
+ catch (error) {
83
+ if (code(error) === "ENOENT")
84
+ return false;
85
+ throw error;
86
+ }
87
+ if (stat.isSymbolicLink() || !stat.isDirectory())
88
+ throw Error(`${directory} must be a directory, not a link or a file. Remove it and run os login again.`);
89
+ guard(storage, stat, directory, "700");
90
+ return true;
91
+ }
92
+ const record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
93
+ /** The saved sign-in, or null when there is none. Refuses a file anyone else could read, a link, or a malformed file. */
94
+ export async function readCredential(storage) {
95
+ const directory = configDirectory(storage), file = credentialPath(storage);
96
+ if (!await guardDirectory(storage, directory))
97
+ return null;
98
+ let handle;
99
+ try {
100
+ handle = await open(file, constants.O_RDONLY | NOFOLLOW);
101
+ }
102
+ catch (error) {
103
+ if (code(error) === "ENOENT")
104
+ return null;
105
+ if (code(error) === "ELOOP")
106
+ throw Error(`${file} is a link. Remove it and run os login again.`);
107
+ throw error;
108
+ }
109
+ try {
110
+ const stat = await handle.stat();
111
+ if (!stat.isFile() || stat.size > CREDENTIALS_MAX)
112
+ throw Error(`${file} is not a saved sign-in. Remove it and run os login again.`);
113
+ guard(storage, stat, file, "600");
114
+ let value = null;
115
+ try {
116
+ value = JSON.parse(await handle.readFile("utf8"));
117
+ }
118
+ catch { /* refused below */ }
119
+ if (!record(value) || value.version !== 1 || typeof value.origin !== "string" || typeof value.token !== "string" || !CLI_TOKEN.test(value.token)
120
+ || typeof value.tokenId !== "string" || typeof value.account !== "string" || typeof value.device !== "string" || typeof value.expiresAt !== "string")
121
+ throw Error(`${file} is damaged. Run os logout, then os login.`);
122
+ return { version: 1, origin: value.origin, token: value.token, tokenId: value.tokenId, account: value.account, device: value.device, expiresAt: value.expiresAt };
123
+ }
124
+ finally {
125
+ await handle.close();
126
+ }
127
+ }
128
+ /** Saves the sign-in: the directory made 0700, the file written to a new name with O_EXCL and mode 0600, then renamed over. */
129
+ export async function writeCredential(storage, credential) {
130
+ const directory = configDirectory(storage), file = credentialPath(storage);
131
+ await mkdir(directory, { recursive: true, mode: 0o700 });
132
+ await guardDirectory(storage, directory);
133
+ const temporary = path.join(directory, `.credentials-${randomBytes(8).toString("hex")}.tmp`);
134
+ const handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | NOFOLLOW, 0o600);
135
+ try {
136
+ try {
137
+ await handle.writeFile(`${JSON.stringify(credential)}\n`, "utf8");
138
+ await handle.sync();
139
+ }
140
+ finally {
141
+ await handle.close();
142
+ }
143
+ await rename(temporary, file);
144
+ }
145
+ catch (error) {
146
+ await unlink(temporary).catch(() => undefined);
147
+ throw error;
148
+ }
149
+ return file;
150
+ }
151
+ /** Deletes the saved sign-in; true when there was one. */
152
+ export async function deleteCredential(storage) {
153
+ try {
154
+ await unlink(credentialPath(storage));
155
+ return true;
156
+ }
157
+ catch (error) {
158
+ if (code(error) === "ENOENT")
159
+ return false;
160
+ throw error;
161
+ }
162
+ }
163
+ /**
164
+ * One request to `<origin>/api/os/cli/<path>`. Redirects are never followed (`redirect: "manual"`, and any 3xx is an error),
165
+ * so the Authorization header cannot reach another host. `verbose` lines name the method, URL and status only.
166
+ */
167
+ export async function apiCall(fetcher, origin, call, verbose, now = Date.now) {
168
+ const url = new URL(`${API_PREFIX}${call.path}`, origin.origin);
169
+ const headers = { Accept: "application/json" };
170
+ if (call.token)
171
+ headers.Authorization = `Bearer ${call.token}`;
172
+ let body;
173
+ if (call.zip) {
174
+ headers["Content-Type"] = "application/zip";
175
+ body = new Blob([call.zip]);
176
+ }
177
+ else if (call.json !== undefined) {
178
+ headers["Content-Type"] = "application/json";
179
+ body = JSON.stringify(call.json);
180
+ }
181
+ const started = now(), secrets = call.token ? [call.token, call.token.slice(9)] : [];
182
+ verbose?.(`→ ${call.method} ${url.href}${call.token ? " (Authorization: Bearer vmos_cli_[redacted])" : ""}`);
183
+ let response;
184
+ try {
185
+ response = await fetcher(url, { method: call.method, headers, body, redirect: "manual", cache: "no-store" });
186
+ }
187
+ catch (error) {
188
+ throw Error(redact(`Could not reach ${origin.origin}: ${error instanceof Error ? error.message : "network error"}.`, secrets));
189
+ }
190
+ verbose?.(`← ${response.status} (${now() - started} ms)`);
191
+ if ((response.status >= 300 && response.status < 400) || response.type === "opaqueredirect") {
192
+ await response.body?.cancel();
193
+ throw Error(`${origin.origin} answered with a redirect. The CLI does not follow redirects, so nothing was sent anywhere else.`);
194
+ }
195
+ const text = await readBounded(response);
196
+ let value = null;
197
+ try {
198
+ value = text ? JSON.parse(text) : null;
199
+ }
200
+ catch { /* not JSON: null */ }
201
+ const retry = Number(response.headers.get("retry-after"));
202
+ return { status: response.status, body: value, retryAfter: Number.isFinite(retry) && retry > 0 ? Math.min(retry, 300) : null };
203
+ }
204
+ async function readBounded(response) {
205
+ const bytes = new Uint8Array(await response.arrayBuffer());
206
+ return new TextDecoder().decode(bytes.byteLength > ANSWER_MAX ? bytes.subarray(0, 0) : bytes);
207
+ }
208
+ /** The server's `message` from an error answer, as safe text, or the fallback. */
209
+ export function messageOf(answer, fallback) {
210
+ const message = record(answer.body) ? printable(answer.body.message, 300) : "";
211
+ return message || fallback;
212
+ }
213
+ /** The platform opener with a fixed argument list (no shell). */
214
+ export function openerCommand(platform, url) {
215
+ if (platform === "darwin")
216
+ return ["open", [url]];
217
+ if (platform === "win32")
218
+ return ["rundll32", ["url.dll,FileProtocolHandler", url]];
219
+ return ["xdg-open", [url]];
220
+ }
221
+ export function systemSeams(env, machine, terminal, spawn = spawnProcess) {
222
+ return {
223
+ storage: { platform: machine.platform, home: machine.home, env, uid: machine.uid },
224
+ hostname: machine.hostname,
225
+ interactive: terminal.stdin.isTTY === true && terminal.stderr.isTTY === true,
226
+ ask: question => new Promise(resolve => {
227
+ const lines = createInterface({ input: terminal.stdin, output: terminal.stderr });
228
+ // resolve before close: closing emits "close", which answers "" to a question nobody answered
229
+ lines.question(question, answer => { resolve(answer); lines.close(); });
230
+ lines.once("close", () => resolve(""));
231
+ }),
232
+ openBrowser: url => {
233
+ const [command, args] = openerCommand(machine.platform, url);
234
+ try {
235
+ const child = spawn(command, args, { stdio: "ignore", detached: true, shell: false });
236
+ child.on("error", () => undefined);
237
+ child.unref();
238
+ }
239
+ catch { /* the URL is printed anyway */ }
240
+ },
241
+ sleep: ms => new Promise(resolve => { setTimeout(resolve, ms); }),
242
+ now: () => Date.now(),
243
+ warn: line => { terminal.stderr.write(`${line}\n`); },
244
+ };
245
+ }
package/dist/cli.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ import type { Seams } from "./cli-session.ts";
2
+ /** The facts about this machine and process the real seams need; `proc` is injectable for tests. */
3
+ export declare function machineOf(proc: Pick<NodeJS.Process, "platform" | "getuid">, home: string, host: string): {
4
+ platform: NodeJS.Platform;
5
+ home: string;
6
+ hostname: string;
7
+ uid: number | undefined;
8
+ };
1
9
  export interface CliSignals {
2
10
  once(signal: "SIGINT" | "SIGTERM", handler: () => void): unknown;
3
11
  off(signal: "SIGINT" | "SIGTERM", handler: () => void): unknown;
@@ -14,6 +22,8 @@ export interface CliRuntime {
14
22
  log(line: string): void;
15
23
  readonly signals: CliSignals;
16
24
  request(url: URL, init: RequestInit): Promise<Response>;
25
+ /** The machine the sign-in and submission commands use (cli-session.ts); the real one when absent. */
26
+ readonly seams?: Seams;
17
27
  }
18
28
  export declare function createCliRuntime(host?: CliProcess, log?: (line: string) => void, request?: typeof fetch): CliRuntime;
19
29
  /** Passive dispatcher: tests and other tools provide owned process boundaries. */
package/dist/cli.js CHANGED
@@ -1,19 +1,52 @@
1
1
  import { readFile, lstat, writeFile } from "node:fs/promises";
2
2
  import { zipSync } from "fflate";
3
- import { GAME_LIMITS } from "./manifest.js";
3
+ import { APP_BUNDLE_LIMITS, GAME_LIMITS } from "./manifest.js";
4
4
  import { readBuiltBundle } from "./bundle.js";
5
- import { createApp, stageAppAssets } from "./scaffold.js";
5
+ import { APP_TEMPLATES, appTemplate, createApp, stageAppAssets } from "./scaffold.js";
6
+ import { checkApp } from "./check.js";
6
7
  import { startAppPreview } from "./preview.js";
8
+ import { redact } from "./redact.js";
9
+ const MiB = 1024 * 1024;
10
+ /** The sign-in and submission commands (cli-publish.ts), loaded only when one of them runs. */
11
+ const PUBLISH = new Set(["login", "logout", "whoami", "submit", "status"]);
12
+ /** The facts about this machine and process the real seams need; `proc` is injectable for tests. */
13
+ export function machineOf(proc, home, host) {
14
+ return { platform: proc.platform, home, hostname: host, uid: typeof proc.getuid === "function" ? proc.getuid() : undefined };
15
+ }
7
16
  export function createCliRuntime(host = process, log = console.log, request = fetch) {
8
17
  return { env: host.env, cwd: () => host.cwd(), log, request: (url, init) => request(url, init), signals: { once: (signal, handler) => host.once(signal, handler), off: (signal, handler) => host.off(signal, handler) } };
9
18
  }
10
19
  /** Passive dispatcher: tests and other tools provide owned process boundaries. */
11
20
  export async function runCli(argv, runtime = createCliRuntime()) {
12
21
  const [command, ...args] = argv;
22
+ if (command !== undefined && PUBLISH.has(command)) {
23
+ const [{ runPublish }, session, os] = await Promise.all([import("./cli-publish.js"), import("./cli-session.js"), import("node:os")]);
24
+ const seams = runtime.seams ?? session.systemSeams(runtime.env, machineOf(process, os.homedir(), os.hostname()), { stdin: process.stdin, stderr: process.stderr });
25
+ await runPublish(command, args, { log: line => runtime.log(line), request: (url, init) => runtime.request(url, init), seams });
26
+ return;
27
+ }
13
28
  if (command === "init") {
14
- if (!args[0] || args.length > 2)
15
- throw Error("Usage: os init <empty-directory> [sdk.tgz]");
16
- runtime.log(`Created ${await createApp(args[0], args[1])}. Run npm install, npm run build, then npm run dev there.`);
29
+ const at = args.indexOf("--template"), template = at < 0 ? "canvas" : args[at + 1];
30
+ const rest = at < 0 ? args : [...args.slice(0, at), ...args.slice(at + 2)];
31
+ if (!rest[0] || rest.length > 2 || !appTemplate(template))
32
+ throw Error(`Usage: os init <empty-directory> [sdk.tgz] [--template ${APP_TEMPLATES.join("|")}]`);
33
+ const created = await createApp(rest[0], rest[1], template);
34
+ runtime.log(template === "plain"
35
+ ? `Created ${created}. Nothing to install: run os preview there (npx @vibechain/os preview ${rest[0]}), and zip the folder to submit.`
36
+ : `Created ${created}. Run npm install, npm run build, then npm run dev there.`);
37
+ return;
38
+ }
39
+ if (command === "check") {
40
+ if (args.length > 1)
41
+ throw Error("Usage: os check [directory]");
42
+ const report = await checkApp(args[0] ?? runtime.cwd());
43
+ for (const notice of report.notices)
44
+ runtime.log(`notice: ${notice}`);
45
+ for (const problem of report.problems)
46
+ runtime.log(problem);
47
+ if (report.problems.length)
48
+ throw Error(`${report.problems.length} problem${report.problems.length === 1 ? "" : "s"} found; fix each line above.`);
49
+ runtime.log(`No problems in ${report.bundle}.`);
17
50
  return;
18
51
  }
19
52
  if (command === "assets") {
@@ -42,14 +75,16 @@ export async function runCli(argv, runtime = createCliRuntime()) {
42
75
  throw Error("Usage: vibemarket-game pack <built-directory> <game.zip>");
43
76
  const { files, manifest } = await readBuiltBundle(directory);
44
77
  const archive = zipSync(files, { level: 6 });
45
- if (archive.length > GAME_LIMITS.archive)
46
- throw Error("Compressed bundle exceeds 20 MiB.");
78
+ // VibeStore apps (schema 2 and 3) are bounded by the store; schema 1 Market games by the legacy publisher.
79
+ const limit = manifest.schemaVersion === 1 ? GAME_LIMITS.archive : APP_BUNDLE_LIMITS.archive;
80
+ if (archive.length > limit)
81
+ throw Error(`Compressed bundle exceeds ${limit / MiB} MiB.`);
47
82
  await writeFile(output, archive);
48
83
  runtime.log(`Packed ${manifest.id}@${manifest.version}: ${Object.keys(files).length} files → ${output}`);
49
84
  return;
50
85
  }
51
86
  if (!["upload", "list", "publish", "rollback"].includes(command ?? "")) {
52
- runtime.log("os init <empty-directory> [sdk.tgz]\nos assets\nos preview <dist> [port]\nos pack <dist> <game.zip>\nos upload <game.zip>\nos list\nos publish <game-id> <version> <registry-revision>\nos rollback <game-id> <version> <registry-revision>\n\nSet VIBEMARKET_PUBLISH_URL=http://127.0.0.1:8888 and VIBEMARKET_PUBLISH_TOKEN (local operator credential). Upload returns a draft preview URL. Publish and rollback only update the active version pointer.");
87
+ runtime.log("os init <empty-directory> [sdk.tgz] [--template plain|canvas|three]\nos assets\nos check [directory]\nos preview <dist> [port]\nos pack <dist> <game.zip>\n\nSubmit to VibeStore (sign in with Steam in your browser):\nos login [--no-browser] [--device <name>]\nos whoami\nos submit <dist> [--yes]\nos status [app-id]\nos logout\n\nInternal publisher (local operators only):\nos upload <game.zip>\nos list\nos publish <game-id> <version> <registry-revision>\nos rollback <game-id> <version> <registry-revision>\n\nSet VIBEMARKET_PUBLISH_URL=http://127.0.0.1:8888 and VIBEMARKET_PUBLISH_TOKEN (local operator credential). Upload returns a draft preview URL. Publish and rollback only update the active version pointer.");
53
88
  return;
54
89
  }
55
90
  const base = new URL(runtime.env.VIBEMARKET_PUBLISH_URL ?? "http://127.0.0.1:8888");
@@ -65,7 +100,7 @@ export async function runCli(argv, runtime = createCliRuntime()) {
65
100
  throw Error("Pass the game ZIP path.");
66
101
  const stat = await lstat(args[0]);
67
102
  if (stat.size > GAME_LIMITS.archive)
68
- throw Error("Archive exceeds 20 MiB.");
103
+ throw Error(`Archive exceeds ${GAME_LIMITS.archive / MiB} MiB.`);
69
104
  body = new Uint8Array(await readFile(args[0]));
70
105
  }
71
106
  else if (command === "publish" || command === "rollback") {
@@ -83,8 +118,9 @@ export async function launchCli(host, log = console.log, report = console.error,
83
118
  try {
84
119
  await runCli(host.argv.slice(2), createCliRuntime(host, log, request));
85
120
  }
121
+ // a CLI token never reaches the terminal, even inside an error a dependency wrote
86
122
  catch (error) {
87
- report(error instanceof Error ? error.message : "SDK command failed.");
123
+ report(redact(error instanceof Error ? error.message : "SDK command failed."));
88
124
  host.exitCode = 1;
89
125
  }
90
126
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  export { connectGameSdk, createPortSdk } from "./client.ts";
2
2
  export { CHANNEL } from "./channel.ts";
3
3
  export { watchInventory } from "./inventory.ts";
4
+ export { connect, OsError, OS_ERROR_CODES, OS_SDK_VERSION } from "./os.ts";
5
+ export type { Card, Os, OsErrorCode, OsSize, Pack, PackCard, PackSummary, Player, Rarity, SignedInPlayer } from "./os.ts";
6
+ export { spawnWorker } from "./worker.ts";
7
+ export type { SpawnedWorker, WorkerHost } from "./worker.ts";
8
+ /** @deprecated Use `connect()`: the same readiness, lifecycle and score, plus saves that outlive the window, cards and more. */
4
9
  export { connectVibeMarketApp } from "./app-client.ts";
5
10
  export { GAME_SCORE_LIMIT } from "./completion.ts";
6
11
  export type { GameFinishInput } from "./completion.ts";
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  export { connectGameSdk, createPortSdk } from "./client.js";
2
2
  export { CHANNEL } from "./channel.js";
3
3
  export { watchInventory } from "./inventory.js";
4
+ export { connect, OsError, OS_ERROR_CODES, OS_SDK_VERSION } from "./os.js";
5
+ export { spawnWorker } from "./worker.js";
6
+ /** @deprecated Use `connect()`: the same readiness, lifecycle and score, plus saves that outlive the window, cards and more. */
4
7
  export { connectVibeMarketApp } from "./app-client.js";
5
8
  export { GAME_SCORE_LIMIT } from "./completion.js";
package/dist/listing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type AppManifestV2 } from "./manifest.ts";
1
+ import { type AppManifest } from "./manifest.ts";
2
2
  /**
3
3
  * Byte checks for a schema version 2 store listing. Pure functions over `Uint8Array` with no Node or DOM
4
4
  * dependency, so the same rules run in the CLI, a server and a browser.
@@ -28,8 +28,8 @@ export declare function pngSize(bytes: Uint8Array): ImageSize | null;
28
28
  /** The image format named by a file's magic bytes, or null. */
29
29
  export declare function imageKind(bytes: Uint8Array): ImageKind | null;
30
30
  /**
31
- * Checks the icon and screenshots a v2 manifest names against the bundle's files: the icon exists, is a PNG of
31
+ * Checks the icon and screenshots a v2 or v3 manifest names against the bundle's files: the icon exists, is a PNG of
32
32
  * exactly 256 x 256 pixels and at most 256 KiB; each screenshot exists, is at most 1 MiB and its signature matches
33
33
  * its extension. `detail` is the offending path. Assumes `manifest` came from `parseManifest`.
34
34
  */
35
- export declare function checkListing(manifest: AppManifestV2, files: Readonly<Record<string, Uint8Array>>): ListingResult;
35
+ export declare function checkListing(manifest: AppManifest, files: Readonly<Record<string, Uint8Array>>): ListingResult;
package/dist/listing.js CHANGED
@@ -28,7 +28,7 @@ const KIND_BY_EXTENSION = { png: "png", jpg: "jpeg", jpeg: "jpeg", webp: "webp"
28
28
  const fail = (code, message, detail) => ({ ok: false, code, message, detail });
29
29
  const KiB = 1024;
30
30
  /**
31
- * Checks the icon and screenshots a v2 manifest names against the bundle's files: the icon exists, is a PNG of
31
+ * Checks the icon and screenshots a v2 or v3 manifest names against the bundle's files: the icon exists, is a PNG of
32
32
  * exactly 256 x 256 pixels and at most 256 KiB; each screenshot exists, is at most 1 MiB and its signature matches
33
33
  * its extension. `detail` is the offending path. Assumes `manifest` came from `parseManifest`.
34
34
  */
package/dist/loop.d.ts CHANGED
@@ -1,11 +1,27 @@
1
1
  import type { AppLifecycle } from "./app-protocol.ts";
2
- /** The part of the app SDK the game helpers read. `connectVibeMarketApp()` satisfies it. */
2
+ /** The part of the 0.4 app SDK the game helpers read. `connectVibeMarketApp()` satisfies it. */
3
3
  export interface LifecycleSource {
4
4
  lifecycle: {
5
5
  current(): Readonly<AppLifecycle>;
6
6
  onChanged(listener: (state: Readonly<AppLifecycle>) => void): () => void;
7
7
  };
8
8
  }
9
+ /** The part of `connect()`'s `Os` the game helpers read. */
10
+ export interface OsLifecycle {
11
+ readonly active: boolean;
12
+ readonly size: Readonly<{
13
+ width: number;
14
+ height: number;
15
+ }>;
16
+ onPause(listener: () => void): () => void;
17
+ onResume(listener: () => void): () => void;
18
+ onResize(listener: (size: Readonly<{
19
+ width: number;
20
+ height: number;
21
+ }>) => void): () => void;
22
+ }
23
+ /** Either app object as the 0.4 lifecycle shape, so `createLoop(os, ...)` and `fitCanvas(os, ...)` take the result of `connect()`. */
24
+ export declare function lifecycleSource(app: LifecycleSource | OsLifecycle): LifecycleSource;
9
25
  export interface LoopOptions {
10
26
  /** Fixed simulation step in milliseconds, above 0 and at most 1000. Default: 1000 / 60. */
11
27
  stepMs?: number;
@@ -31,4 +47,4 @@ export interface FrameClock {
31
47
  * Time spent inactive is discarded rather than simulated on return. If `update` or
32
48
  * `render` throws, the error propagates and the loop stays stopped.
33
49
  */
34
- export declare function createLoop(app: LifecycleSource, options: LoopOptions, clock?: FrameClock): Loop;
50
+ export declare function createLoop(source: LifecycleSource | OsLifecycle, options: LoopOptions, clock?: FrameClock): Loop;
package/dist/loop.js CHANGED
@@ -1,9 +1,21 @@
1
+ /** Either app object as the 0.4 lifecycle shape, so `createLoop(os, ...)` and `fitCanvas(os, ...)` take the result of `connect()`. */
2
+ export function lifecycleSource(app) {
3
+ if ("lifecycle" in app)
4
+ return app;
5
+ const current = () => Object.freeze({ active: app.active, width: app.size.width, height: app.size.height });
6
+ return { lifecycle: { current, onChanged(listener) {
7
+ const offs = [app.onPause(() => listener(current())), app.onResume(() => listener(current())), app.onResize(() => listener(current()))];
8
+ return () => { for (const off of offs)
9
+ off(); };
10
+ } } };
11
+ }
1
12
  /**
2
13
  * A fixed-timestep game loop that runs only while the host reports the app active.
3
14
  * Time spent inactive is discarded rather than simulated on return. If `update` or
4
15
  * `render` throws, the error propagates and the loop stays stopped.
5
16
  */
6
- export function createLoop(app, options, clock = window) {
17
+ export function createLoop(source, options, clock = window) {
18
+ const app = lifecycleSource(source);
7
19
  const step = options.stepMs ?? 1000 / 60, maxSteps = options.maxSteps ?? 5;
8
20
  if (!Number.isFinite(step) || step <= 0 || step > 1000)
9
21
  throw Error("stepMs must be above 0 and at most 1000.");
@@ -13,9 +13,15 @@ export interface GameManifestV1 {
13
13
  permissions: GamePermission[];
14
14
  collectionId: string | null;
15
15
  }
16
- /** VibeStore listing categories. */
17
- export declare const APP_STORE_CATEGORIES: readonly ["game", "tool", "toy"];
16
+ /** VibeStore listing categories: a game or an app (owner decision, 2026-11-23). */
17
+ export declare const APP_STORE_CATEGORIES: readonly ["game", "app"];
18
18
  export type AppStoreCategory = typeof APP_STORE_CATEGORIES[number];
19
+ /**
20
+ * Categories @vibechain/os 0.4 accepted. A schema version 2 manifest that names one still validates and is normalized to
21
+ * "app" (`manifestNotices` says so); schema version 3 refuses them.
22
+ */
23
+ export declare const APP_LEGACY_STORE_CATEGORIES: readonly ["tool", "toy"];
24
+ export type AppLegacyStoreCategory = typeof APP_LEGACY_STORE_CATEGORIES[number];
19
25
  /** Content rating levels for `store.rating.violence` and `store.rating.language`. */
20
26
  export declare const APP_CONTENT_RATINGS: readonly ["none", "mild", "strong"];
21
27
  export type AppContentRating = typeof APP_CONTENT_RATINGS[number];
@@ -76,8 +82,31 @@ export interface AppManifestV2 {
76
82
  window: AppWindow;
77
83
  store: AppStoreListing;
78
84
  }
85
+ /** What a schema version 3 app may read of the player's vmOS cards: nothing, its linked packs, or every pack. */
86
+ export declare const APP_CARDS_ACCESS: readonly ["none", "linked", "all"];
87
+ export type AppCardsAccess = typeof APP_CARDS_ACCESS[number];
88
+ /** Schema version 3: a VibeStore app that may link packs, read cards and connect to declared servers. */
89
+ export interface AppManifestV3 {
90
+ schemaVersion: 3;
91
+ id: string;
92
+ version: string;
93
+ name: string;
94
+ tagline: string;
95
+ entry: string;
96
+ window: AppWindow;
97
+ store: AppStoreListing;
98
+ /** 0 to 3 pack slugs, in listing order. Optional in the file; `[]` when absent. */
99
+ packs: string[];
100
+ /** Optional in the file; `"none"` when absent. `"linked"` needs at least one pack. */
101
+ cards: AppCardsAccess;
102
+ /** 0 to 8 `https://` or `wss://` origins, lowercase and sorted. Optional in the file; `[]` when absent. */
103
+ network: string[];
104
+ }
79
105
  /** Every manifest `parseManifest` admits, discriminated on `schemaVersion`. */
80
- export type GameManifest = GameManifestV1 | AppManifestV2;
106
+ export type GameManifest = GameManifestV1 | AppManifestV2 | AppManifestV3;
107
+ /** A VibeStore app manifest: schema version 2 or 3, both with a window and a store listing. */
108
+ export type AppManifest = AppManifestV2 | AppManifestV3;
109
+ /** The legacy Market-game bounds. VibeStore bundles use `APP_BUNDLE_LIMITS`. */
81
110
  export declare const GAME_LIMITS: {
82
111
  readonly archive: number;
83
112
  readonly expanded: number;
@@ -86,8 +115,65 @@ export declare const GAME_LIMITS: {
86
115
  readonly versions: 100;
87
116
  readonly games: 40;
88
117
  };
118
+ /** VibeStore bundle bounds: the submitted ZIP, its expanded bytes, the largest file and the entries (files and folders). */
119
+ export declare const APP_BUNDLE_LIMITS: {
120
+ readonly archive: number;
121
+ readonly expanded: number;
122
+ readonly file: number;
123
+ readonly files: 2000;
124
+ };
125
+ /** Schema version 3 bounds: linked packs, declared origins and a pack slug's length. */
126
+ export declare const APP_MANIFEST_LIMITS: {
127
+ readonly packs: 3;
128
+ readonly network: 8;
129
+ readonly packSlugMax: 56;
130
+ };
131
+ /** A pack slug, as `vibemarket/steam/pack-slug.ts` defines it (at most `APP_MANIFEST_LIMITS.packSlugMax` characters). */
132
+ export declare const PACK_SLUG: RegExp;
133
+ export declare const packSlug: (value: unknown) => value is string;
89
134
  export declare function assetPath(value: string): boolean;
90
135
  /** An `https://` URL without credentials, or a plausible email address. Exported for forms that validate as the parser does. */
91
136
  export declare function supportContact(value: string): boolean;
92
- /** Accepts schema version 1 exactly as before and schema version 2 with its window and store listing. Unknown fields are rejected at every level. */
137
+ /** Names that resolve anywhere a resolver likes, or nowhere public (section 3.3, rule 5). */
138
+ export declare const NETWORK_RESERVED_SUFFIXES: readonly ["localhost", "local", "internal", "lan", "home.arpa", "test", "example", "invalid", "onion", "arpa"];
139
+ /** Wildcard-DNS services that map a name to any address (rule 6). Extended by review. */
140
+ export declare const NETWORK_WILDCARD_DNS: readonly ["nip.io", "sslip.io", "xip.io", "localtest.me", "lvh.me", "traefik.me"];
141
+ /** Vibechain's own domains (rule 7): an app never declares them. */
142
+ export declare const NETWORK_OWN_DOMAINS: readonly ["vibechain.com", "vibe.market", "eattherich.gg"];
143
+ /**
144
+ * Why `value` is not a declared network origin, or `null` with its normalized form. The single implementation of
145
+ * section 3.3: `https://` or `wss://`, exactly `scheme://host[:port]`, a public DNS name, never an IP address, a
146
+ * local or reserved name, a wildcard-DNS service or a Vibechain domain.
147
+ */
148
+ export declare function networkOriginCheck(value: unknown): {
149
+ origin: string;
150
+ problem: null;
151
+ } | {
152
+ origin: null;
153
+ problem: string;
154
+ };
155
+ /** The normalized (lowercase) origin, or `null` when `value` is not an origin an app may declare (section 3.3). */
156
+ export declare function networkOrigin(value: unknown): string | null;
157
+ /** One thing wrong with a manifest: the field path (`""` for the whole file) and a plain sentence saying what to change. */
158
+ export interface ManifestProblem {
159
+ path: string;
160
+ message: string;
161
+ }
162
+ /** `path: message`, the line `os check` prints and the text `parseManifest` throws for schema version 3. */
163
+ export declare const manifestProblemText: (problem: ManifestProblem) => string;
164
+ /**
165
+ * Things `parseManifest` accepts but a developer should change, as `os check` prints them without failing: today only a
166
+ * schema version 2 `store.category` of "tool" or "toy", which is read as "app".
167
+ */
168
+ export declare function manifestNotices(input: unknown): ManifestProblem[];
169
+ /**
170
+ * Every problem with a manifest, or `[]` when `parseManifest` accepts it. For schema version 3 this is every problem,
171
+ * one per field path, in field order. Schema versions 1 and 2 keep their single legacy message (`path` `""`).
172
+ */
173
+ export declare function checkManifest(input: unknown): ManifestProblem[];
174
+ /**
175
+ * Accepts schema version 1 exactly as before, schema version 2 with its window and store listing, and schema
176
+ * version 3 (no constant fields; optional `packs`, `cards` and `network`). Unknown fields are rejected at every
177
+ * level. Throws the first problem; `checkManifest` lists them all.
178
+ */
93
179
  export declare function parseManifest(input: unknown): GameManifest;