@vibechain/os 0.5.1 → 0.6.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 (59) hide show
  1. package/AGENTS.md +52 -11
  2. package/README.md +115 -20
  3. package/SECURITY.md +6 -4
  4. package/dist/app-client.js +20 -4
  5. package/dist/app-host.d.ts +74 -5
  6. package/dist/app-host.js +94 -6
  7. package/dist/app-protocol.d.ts +21 -0
  8. package/dist/app-protocol.js +9 -0
  9. package/dist/app-wire.d.ts +186 -6
  10. package/dist/app-wire.js +213 -7
  11. package/dist/audio.d.ts +65 -0
  12. package/dist/audio.js +162 -0
  13. package/dist/browser.d.ts +2 -1
  14. package/dist/browser.js +2 -1
  15. package/dist/bundle.d.ts +2 -0
  16. package/dist/bundle.js +5 -3
  17. package/dist/check.js +11 -4
  18. package/dist/cli.js +3 -1
  19. package/dist/commands.d.ts +6 -0
  20. package/dist/commands.js +17 -0
  21. package/dist/fake-services.d.ts +88 -0
  22. package/dist/fake-services.js +132 -0
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +1 -1
  25. package/dist/links.d.ts +13 -0
  26. package/dist/links.js +17 -1
  27. package/dist/listing.d.ts +12 -0
  28. package/dist/listing.js +49 -1
  29. package/dist/manifest.d.ts +76 -1
  30. package/dist/manifest.js +170 -5
  31. package/dist/os.d.ts +83 -5
  32. package/dist/os.js +179 -15
  33. package/dist/preview-parent.d.ts +21 -2
  34. package/dist/preview-parent.js +101 -8
  35. package/dist/preview-surfaces.d.ts +36 -0
  36. package/dist/preview-surfaces.js +84 -0
  37. package/dist/preview-ui.js +1 -1
  38. package/dist/preview.js +4 -2
  39. package/dist/templates/plain/game.js +3 -1
  40. package/dist/testing.d.ts +50 -7
  41. package/dist/testing.js +137 -13
  42. package/dist/transport.d.ts +4 -1
  43. package/dist/transport.js +2 -2
  44. package/dist/vibemarket-os.js +1 -1
  45. package/examples/paw-beat/README.md +38 -10
  46. package/examples/paw-beat/cat.ts +13 -0
  47. package/examples/paw-beat/game.ts +290 -123
  48. package/examples/paw-beat/index.html +20 -4
  49. package/examples/paw-beat/main.ts +156 -48
  50. package/examples/paw-beat/music.ts +72 -337
  51. package/examples/paw-beat/stage.ts +23 -9
  52. package/examples/paw-beat/store/screenshot-1.webp +0 -0
  53. package/examples/paw-beat/store/screenshot-2.webp +0 -0
  54. package/examples/paw-beat/synth.ts +477 -0
  55. package/examples/paw-beat/tracks.ts +286 -0
  56. package/examples/paw-beat/vibemarket.json +15 -8
  57. package/examples/vibexp-app/plain/game.ts +6 -2
  58. package/package.json +7 -1
  59. package/skill.md +471 -0
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The `os` commands an app developer uses, in the order `os` prints them: one list for the CLI's help and the agent skill
3
+ * (https://vibechain.com/os/skill.md), so the two cannot drift. The internal Market-game publisher commands are not here.
4
+ */
5
+ import { APP_TEMPLATES } from "./scaffold.js";
6
+ export const APP_CLI_COMMANDS = Object.freeze([
7
+ { group: "build", usage: `os init <empty-directory> [sdk.tgz] [--template ${APP_TEMPLATES.join("|")}]`, does: "create an app from a template (canvas when no template is given)" },
8
+ { group: "build", usage: "os assets", does: "copy index.html, vibemarket.json, the listed store images and the whole public/ folder into dist/" },
9
+ { group: "build", usage: "os check [directory]", does: "print every problem with the manifest and the built folder, one per line; exits 1 on any" },
10
+ { group: "build", usage: "os preview <dist> [port]", does: "run the built app locally in a sandboxed window with the production policy and stand-in cards, saves and player" },
11
+ { group: "build", usage: "os pack <dist> <game.zip>", does: "check the build and write the ZIP to submit" },
12
+ { group: "publish", usage: "os login [--no-browser] [--device <name>]", does: "sign this computer in: prints a code the human approves at https://vibechain.com/os/cli" },
13
+ { group: "publish", usage: "os whoami", does: "show the signed-in account and computer" },
14
+ { group: "publish", usage: "os submit <dist> [--yes]", does: "check, pack and upload the build for review after showing a summary and asking" },
15
+ { group: "publish", usage: "os status [app-id]", does: "list your submissions and their review state" },
16
+ { group: "publish", usage: "os logout", does: "revoke this computer's sign-in, then delete it" },
17
+ ]);
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The in-memory stand-in for the vmOS services of SDK 0.6 (VM_OS_APPS_4.md sections 3 to 8): boards, achievements, friends,
3
+ * invites, sharing and spending. One implementation serves both the testing module (`createFakeOs`) and the local preview
4
+ * (`os preview`), so a game tested against one behaves the same in the other. It keeps the rules a game can rely on (declared
5
+ * ids, best score by the board's order, an unlock counted once, secret achievements, guests, owned permanent products,
6
+ * receipts that stay until consumed, at most 20 unconsumed, never spending more than the player has) and leaves out what only
7
+ * the server knows: rounds and their timing, rate limits, daily caps and the week's reset (`period: "week"` reads the same
8
+ * rows as all time). Pure: no DOM, no Node, no clock but the one given.
9
+ */
10
+ import { type Achievement, type Friend, type InviteOptions, type Leaderboard, type LeaderboardQuery, type Product, type Receipt, type ShareOptions } from "./app-wire.ts";
11
+ import { type AppAchievement, type AppLeaderboard, type AppProduct } from "./manifest.ts";
12
+ /** Another player's best score on a board (default `score`). `friend` puts them in the player's friends scope too. */
13
+ export interface FakeScore {
14
+ board?: string;
15
+ handle: string;
16
+ name: string;
17
+ picture?: string | null;
18
+ score: number;
19
+ friend?: boolean;
20
+ }
21
+ export interface FakeServicesOptions {
22
+ /** the manifest's declared lists, normalized (`parseServices`); the board `score` is added unless declared */
23
+ leaderboards?: readonly AppLeaderboard[];
24
+ achievements?: readonly AppAchievement[];
25
+ products?: readonly AppProduct[];
26
+ /** who is playing, or null for a guest */
27
+ player: {
28
+ handle: string;
29
+ name: string;
30
+ picture: string | null;
31
+ } | null;
32
+ scores?: readonly FakeScore[];
33
+ /** the player's friends who have the app */
34
+ friends?: readonly Friend[];
35
+ /** the player's Printer Cash; the fake never tells the app this number. Default 1,000. */
36
+ printerCash?: number;
37
+ /** whether the manifest declares `network` (receipt tokens) */
38
+ network?: boolean;
39
+ now: () => number;
40
+ }
41
+ /** What a game did, for a test to assert. */
42
+ export interface FakeServicesState {
43
+ /** every score a finish posted and the fake recorded, in order */
44
+ readonly posted: readonly {
45
+ board: string;
46
+ score: number;
47
+ }[];
48
+ /** achievement ids in the order they were first unlocked */
49
+ readonly unlocked: readonly string[];
50
+ readonly shares: readonly (ShareOptions & {
51
+ board?: string;
52
+ })[];
53
+ readonly invites: readonly (InviteOptions & {
54
+ sent: number;
55
+ })[];
56
+ /** every receipt, consumed or not */
57
+ readonly receipts: readonly Receipt[];
58
+ readonly printerCash: number;
59
+ }
60
+ export interface FakeServices {
61
+ /** a finished round's score: recorded as the player's best when it beats it; false when it is not recorded (a guest, an undeclared board, a time out of range) */
62
+ post(score: number, board?: string): boolean;
63
+ leaderboard(query: LeaderboardQuery): Leaderboard;
64
+ unlock(id: string): {
65
+ unlocked: boolean;
66
+ };
67
+ achievements(): Achievement[];
68
+ friends(): Friend[];
69
+ /** `confirmed`: whether the player confirmed the sheet */
70
+ invite(options: InviteOptions, confirmed: boolean): {
71
+ sent: number;
72
+ };
73
+ share(options: ShareOptions, confirmed: boolean): {
74
+ shared: boolean;
75
+ };
76
+ products(): Product[];
77
+ /** `confirmed`: whether the player confirmed the spend dialog */
78
+ buy(product: string, confirmed: boolean): Receipt;
79
+ purchases(): Receipt[];
80
+ consume(receipt: string): void;
81
+ receiptToken(receipt: string): string;
82
+ /** a product's declaration, for drawing its dialog */
83
+ product(id: string): AppProduct;
84
+ readonly state: FakeServicesState;
85
+ }
86
+ /** The most unconsumed receipts of one app a player may hold (VM_OS_APPS_4.md section 8.4). */
87
+ export declare const UNCONSUMED_RECEIPTS_MAX = 20;
88
+ export declare function createFakeServices(options: FakeServicesOptions): FakeServices;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The in-memory stand-in for the vmOS services of SDK 0.6 (VM_OS_APPS_4.md sections 3 to 8): boards, achievements, friends,
3
+ * invites, sharing and spending. One implementation serves both the testing module (`createFakeOs`) and the local preview
4
+ * (`os preview`), so a game tested against one behaves the same in the other. It keeps the rules a game can rely on (declared
5
+ * ids, best score by the board's order, an unlock counted once, secret achievements, guests, owned permanent products,
6
+ * receipts that stay until consumed, at most 20 unconsumed, never spending more than the player has) and leaves out what only
7
+ * the server knows: rounds and their timing, rate limits, daily caps and the week's reset (`period: "week"` reads the same
8
+ * rows as all time). Pure: no DOM, no Node, no clock but the one given.
9
+ */
10
+ import { APPS4_LIMITS, AppHostError, SECRET_ACHIEVEMENT_NAME, } from "./app-wire.js";
11
+ import { appLeaderboards } from "./manifest.js";
12
+ /** The most unconsumed receipts of one app a player may hold (VM_OS_APPS_4.md section 8.4). */
13
+ export const UNCONSUMED_RECEIPTS_MAX = 20;
14
+ const fail = (code, message) => new AppHostError(code, message);
15
+ export function createFakeServices(options) {
16
+ const boards = appLeaderboards({ leaderboards: [...(options.leaderboards ?? [])] }), declared = options.achievements ?? [], catalog = options.products ?? [];
17
+ const friends = (options.friends ?? []).map(friend => ({ ...friend }));
18
+ const others = (options.scores ?? []).map(entry => ({ board: entry.board ?? "score", handle: entry.handle, name: entry.name, picture: entry.picture ?? null, score: entry.score, friend: entry.friend === true }));
19
+ const best = new Map(), unlockedAt = new Map();
20
+ const posted = [], shares = [], invites = [], receipts = [];
21
+ let cash = options.printerCash ?? 1000, sequence = 0;
22
+ const player = options.player;
23
+ const signedIn = (what) => { if (!player)
24
+ throw fail("guest", `Guests cannot ${what}; the player has to sign in.`); return player; };
25
+ const board = (id) => { const found = boards.find(item => item.id === id); if (!found)
26
+ throw fail("invalid", `The board ${id} is not declared in the manifest.`); return found; };
27
+ const product = (id) => { const found = catalog.find(item => item.id === id); if (!found)
28
+ throw fail("invalid", `The product ${id} is not declared in the manifest.`); return found; };
29
+ const receipt = (id) => { const found = receipts.find(item => item.id === id); if (!found)
30
+ throw fail("invalid", "There is no such receipt."); return found; };
31
+ const better = (order, a, b) => order === "high" ? a > b : a < b;
32
+ return {
33
+ post(score, id = "score") {
34
+ const found = boards.find(item => item.id === id);
35
+ if (!player || !found || (found.format === "time" && score > APPS4_LIMITS.timeScoreMax))
36
+ return false;
37
+ const held = best.get(id);
38
+ if (!held || better(found.order, score, held.score))
39
+ best.set(id, { score, at: options.now() });
40
+ posted.push({ board: id, score });
41
+ return true;
42
+ },
43
+ leaderboard(query) {
44
+ const found = board(query.board), friendly = new Set(friends.map(friend => friend.handle));
45
+ const rows = others.filter(row => row.board === found.id && (query.scope === "everyone" || row.friend || friendly.has(row.handle)))
46
+ .map((row, index) => ({ handle: row.handle, name: row.name, picture: row.picture, score: row.score, you: false, at: index - others.length }));
47
+ const mine = best.get(found.id);
48
+ if (player && mine)
49
+ rows.push({ handle: player.handle, name: player.name, picture: player.picture, score: mine.score, you: true, at: mine.at });
50
+ // the better score first; a tie goes to the earlier one (seeded rows are older than anything the player posts)
51
+ rows.sort((a, b) => a.score === b.score ? a.at - b.at : better(found.order, a.score, b.score) ? -1 : 1);
52
+ const ranked = rows.map((row, index) => ({ rank: index + 1, handle: row.handle, name: row.name, picture: row.picture, score: row.score, you: row.you }));
53
+ const you = ranked.find(row => row.you);
54
+ return { board: found.id, name: found.name, order: found.order, format: found.format, period: query.period, entries: ranked.slice(0, query.limit), you: you ? { rank: you.rank, score: you.score } : null };
55
+ },
56
+ unlock(id) {
57
+ if (!declared.some(item => item.id === id))
58
+ throw fail("invalid", `The achievement ${id} is not declared in the manifest.`);
59
+ if (!player || unlockedAt.has(id))
60
+ return { unlocked: false };
61
+ unlockedAt.set(id, options.now());
62
+ return { unlocked: true };
63
+ },
64
+ achievements() {
65
+ return declared.map(item => {
66
+ const at = unlockedAt.get(item.id) ?? null, unlocked = at !== null;
67
+ if (item.secret && !unlocked)
68
+ return { id: item.id, name: SECRET_ACHIEVEMENT_NAME, description: "", icon: null, secret: true, unlocked: false, at: null };
69
+ return { id: item.id, name: item.name, description: item.description, icon: item.icon, secret: item.secret, unlocked, at };
70
+ });
71
+ },
72
+ friends() {
73
+ const rank = { playing: 0, online: 1, offline: 2 };
74
+ return friends.slice().sort((a, b) => rank[a.presence] - rank[b.presence] || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)).slice(0, APPS4_LIMITS.friendsMax).map(friend => ({ ...friend }));
75
+ },
76
+ invite(given, confirmed) {
77
+ signedIn("invite friends");
78
+ const chosen = given.to !== undefined && friends.some(friend => friend.handle === given.to) ? 1 : Math.min(friends.length, APPS4_LIMITS.inviteRecipients);
79
+ const sent = confirmed ? chosen : 0;
80
+ invites.push({ ...given, sent });
81
+ return { sent };
82
+ },
83
+ share(given, confirmed) {
84
+ signedIn("share");
85
+ if (given.score !== undefined)
86
+ board(given.board ?? "score");
87
+ if (!confirmed)
88
+ return { shared: false };
89
+ shares.push({ ...given, ...(given.score !== undefined ? { board: given.board ?? "score" } : {}) });
90
+ return { shared: true };
91
+ },
92
+ products() {
93
+ return catalog.map(item => ({ ...item, owned: item.kind === "permanent" && receipts.some(row => row.product === item.id) }));
94
+ },
95
+ buy(id, confirmed) {
96
+ const item = product(id);
97
+ signedIn("buy");
98
+ if (!confirmed)
99
+ throw fail("cancelled", "The player closed the dialog without spending.");
100
+ const owned = item.kind === "permanent" ? receipts.find(row => row.product === item.id) : undefined;
101
+ if (owned)
102
+ return { ...owned };
103
+ if (receipts.filter(row => row.kind === "consumable" && !row.consumed).length >= UNCONSUMED_RECEIPTS_MAX)
104
+ throw fail("limit", "Too many purchases are waiting to be consumed; consume them first.");
105
+ if (cash < item.price)
106
+ throw fail("insufficient", "The player does not have enough Printer Cash for that.");
107
+ cash -= item.price;
108
+ const made = { id: `fake-r${++sequence}`, product: item.id, kind: item.kind, price: item.price, at: options.now(), consumed: false };
109
+ receipts.push(made);
110
+ return { ...made };
111
+ },
112
+ purchases() { return receipts.filter(row => !row.consumed).map(row => ({ ...row })); },
113
+ consume(id) {
114
+ const found = receipt(id);
115
+ if (found.kind !== "consumable")
116
+ throw fail("invalid", "Only a consumable's receipt is consumed.");
117
+ found.consumed = true;
118
+ },
119
+ receiptToken(id) {
120
+ if (!options.network)
121
+ throw fail("not-permitted", "Receipt tokens are for apps that declare network.");
122
+ return `fake.receipt-token.${receipt(id).id}`;
123
+ },
124
+ product,
125
+ get state() {
126
+ return {
127
+ posted: posted.map(row => ({ ...row })), unlocked: [...unlockedAt.keys()], shares: shares.map(row => ({ ...row })), invites: invites.map(row => ({ ...row })),
128
+ receipts: receipts.map(row => ({ ...row })), printerCash: cash,
129
+ };
130
+ },
131
+ };
132
+ }
package/dist/index.d.ts CHANGED
@@ -2,16 +2,16 @@ export { connectGameSdk, createPortSdk } from "./client.ts";
2
2
  export { CHANNEL } from "./channel.ts";
3
3
  export { watchInventory } from "./inventory.ts";
4
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";
5
+ export type { Achievement, BoardPeriod, BoardScope, Card, Friend, Invite, InviteOptions, Leaderboard, LeaderboardEntry, LeaderboardFormat, LeaderboardOptions, LeaderboardOrder, Os, OsErrorCode, OsLaunch, OsSize, OsSound, Pack, PackCard, PackSummary, Player, Presence, Product, ProductKind, Rarity, Receipt, ShareOptions, SignedInPlayer, } from "./os.ts";
6
6
  export type { CaptureResult } from "./capture.ts";
7
7
  export { spawnWorker } from "./worker.ts";
8
- export { cardLink, packLink, parseVmosLink, VMOS_LINK_MAX } from "./links.ts";
8
+ export { appLink, cardLink, packLink, parseVmosLink, VMOS_LINK_MAX } from "./links.ts";
9
9
  export type { VmosLink } from "./links.ts";
10
10
  export type { SpawnedWorker, WorkerHost } from "./worker.ts";
11
11
  /** @deprecated Use `connect()`: the same readiness, lifecycle and score, plus saves that outlive the window, cards and more. */
12
12
  export { connectVibeMarketApp } from "./app-client.ts";
13
13
  export { GAME_SCORE_LIMIT } from "./completion.ts";
14
14
  export type { GameFinishInput } from "./completion.ts";
15
- export type { AppValue, AppLifecycle, VibeMarketAppSdk } from "./app-protocol.ts";
15
+ export type { AppValue, AppLifecycle, AppSound, VibeMarketAppSdk } from "./app-protocol.ts";
16
16
  export type { InventoryObserver } from "./inventory.ts";
17
17
  export type * from "./types.ts";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { CHANNEL } from "./channel.js";
3
3
  export { watchInventory } from "./inventory.js";
4
4
  export { connect, OsError, OS_ERROR_CODES, OS_SDK_VERSION } from "./os.js";
5
5
  export { spawnWorker } from "./worker.js";
6
- export { cardLink, packLink, parseVmosLink, VMOS_LINK_MAX } from "./links.js";
6
+ export { appLink, cardLink, packLink, parseVmosLink, VMOS_LINK_MAX } from "./links.js";
7
7
  /** @deprecated Use `connect()`: the same readiness, lifecycle and score, plus saves that outlive the window, cards and more. */
8
8
  export { connectVibeMarketApp } from "./app-client.js";
9
9
  export { GAME_SCORE_LIMIT } from "./completion.js";
package/dist/links.d.ts CHANGED
@@ -5,10 +5,23 @@ export type VmosLink = {
5
5
  kind: "card";
6
6
  pack: string;
7
7
  card: string;
8
+ } | {
9
+ kind: "app";
10
+ app: string;
8
11
  };
9
12
  export declare const VMOS_LINK_MAX = 200;
13
+ /** The accepted forms, exactly as parseVmosLink matches them (the agent skill prints these). */
14
+ export declare const VMOS_LINK_PATTERNS: Readonly<{
15
+ pack: RegExp;
16
+ card: RegExp;
17
+ web: RegExp;
18
+ app: RegExp;
19
+ webApp: RegExp;
20
+ }>;
10
21
  /** The target a link names, or null when it is not exactly one of the three forms. */
11
22
  export declare function parseVmosLink(text: unknown): VmosLink | null;
23
+ /** `vmos://app/<appId>` (0.6); throws an OsError `invalid` for a value that is not an app id. */
24
+ export declare function appLink(id: string): string;
12
25
  /** `vmos://pack/<slug>`; throws an OsError `invalid` for a value that is not a pack slug. */
13
26
  export declare function packLink(slug: string): string;
14
27
  /** `vmos://card/<slug>/<cardId>`; throws an OsError `invalid` for a value that is not a pack slug or a card id. */
package/dist/links.js CHANGED
@@ -6,17 +6,24 @@
6
6
  * vmos://pack/<slug>
7
7
  * vmos://card/<slug>/<cardId>
8
8
  * https://vibechain.com/os/pack/<slug> (and https://www.vibechain.com/...; one optional trailing "/")
9
+ * vmos://app/<appId> (0.6: an app's page in MiniVibe, to install or play it)
10
+ * https://vibechain.com/os/app/<appId> (0.6; www. and one trailing "/" as above)
9
11
  *
10
12
  * Exact and anchored: lowercase scheme and host, at most 200 characters, no percent-encoding, query, fragment, user, port,
11
13
  * other host or other path. `<slug>` is a pack slug (at most 56 characters), `<cardId>` a creator card id.
12
14
  */
13
- import { CARD_ID, OsError } from "./app-wire.js";
15
+ import { CARD_ID, OsError, appId } from "./app-wire.js";
14
16
  import { packSlug } from "./manifest.js";
15
17
  export const VMOS_LINK_MAX = 200;
16
18
  const SLUG = "[a-z0-9]+(?:-[a-z0-9]+)*", CARD = "[A-Za-z0-9_-]{1,64}";
17
19
  const PACK_LINK = new RegExp(`^vmos://pack/(${SLUG})$`);
18
20
  const CARD_LINK = new RegExp(`^vmos://card/(${SLUG})/(${CARD})$`);
19
21
  const WEB_PACK = new RegExp(`^https://(?:www\\.)?vibechain\\.com/os/pack/(${SLUG})/?$`);
22
+ const APP = "[a-z][a-z0-9]*(?:-[a-z0-9]+)*";
23
+ const APP_LINK = new RegExp(`^vmos://app/(${APP})$`);
24
+ const WEB_APP = new RegExp(`^https://(?:www\\.)?vibechain\\.com/os/app/(${APP})/?$`);
25
+ /** The accepted forms, exactly as parseVmosLink matches them (the agent skill prints these). */
26
+ export const VMOS_LINK_PATTERNS = Object.freeze({ pack: PACK_LINK, card: CARD_LINK, web: WEB_PACK, app: APP_LINK, webApp: WEB_APP });
20
27
  /** The target a link names, or null when it is not exactly one of the three forms. */
21
28
  export function parseVmosLink(text) {
22
29
  if (typeof text !== "string" || text.length > VMOS_LINK_MAX)
@@ -24,9 +31,18 @@ export function parseVmosLink(text) {
24
31
  const card = CARD_LINK.exec(text);
25
32
  if (card)
26
33
  return packSlug(card[1]) ? { kind: "card", pack: card[1], card: card[2] } : null;
34
+ const app = APP_LINK.exec(text) ?? WEB_APP.exec(text);
35
+ if (app)
36
+ return appId(app[1]) ? { kind: "app", app: app[1] } : null;
27
37
  const pack = PACK_LINK.exec(text) ?? WEB_PACK.exec(text);
28
38
  return pack && packSlug(pack[1]) ? { kind: "pack", pack: pack[1] } : null;
29
39
  }
40
+ /** `vmos://app/<appId>` (0.6); throws an OsError `invalid` for a value that is not an app id. */
41
+ export function appLink(id) {
42
+ if (!appId(id))
43
+ throw new OsError("invalid", "That is not an app id.");
44
+ return `vmos://app/${id}`;
45
+ }
30
46
  /** `vmos://pack/<slug>`; throws an OsError `invalid` for a value that is not a pack slug. */
31
47
  export function packLink(slug) {
32
48
  if (!packSlug(slug))
package/dist/listing.d.ts CHANGED
@@ -25,6 +25,18 @@ export type ListingResult = {
25
25
  * Nothing else in the file is read or trusted; this is not a decoder.
26
26
  */
27
27
  export declare function pngSize(bytes: Uint8Array): ImageSize | null;
28
+ /**
29
+ * Width and height of a WebP from its first chunk (`VP8X`, `VP8 ` or `VP8L`), or null. Like `pngSize`, a header reader, not
30
+ * a decoder: only the RIFF/WEBP signature, the first chunk's tag and its size fields are read.
31
+ */
32
+ export declare function webpSize(bytes: Uint8Array): ImageSize | null;
33
+ /** The size of a PNG or WebP by its contents, whatever its name, or null. */
34
+ export declare const imageSize: (bytes: Uint8Array) => ImageSize | null;
35
+ /**
36
+ * Why an achievement's icon (VM_OS_APPS_4.md section 2) is not acceptable, or null: it must be in the bundle, a PNG or WebP
37
+ * whose contents match its extension, exactly 128 x 128 pixels and at most 64 KiB. `os check` and `checkListing` both say this.
38
+ */
39
+ export declare function achievementIconProblem(icon: string, bytes: Uint8Array | undefined): string | null;
28
40
  /** The image format named by a file's magic bytes, or null. */
29
41
  export declare function imageKind(bytes: Uint8Array): ImageKind | null;
30
42
  /**
package/dist/listing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { APP_STORE_LIMITS } from "./manifest.js";
1
+ import { APP_SERVICE_LIMITS, APP_STORE_LIMITS } from "./manifest.js";
2
2
  const PNG = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
3
3
  const IHDR = [0x49, 0x48, 0x44, 0x52];
4
4
  const startsWith = (bytes, prefix, offset = 0) => bytes.length >= offset + prefix.length && prefix.every((value, i) => bytes[offset + i] === value);
@@ -14,6 +14,45 @@ export function pngSize(bytes) {
14
14
  const width = uint32(bytes, 16), height = uint32(bytes, 20);
15
15
  return width > 0 && height > 0 && width <= 0x7fffffff && height <= 0x7fffffff ? { width, height } : null;
16
16
  }
17
+ const uint24le = (bytes, offset) => bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16);
18
+ const uint14le = (bytes, offset) => (bytes[offset] + (bytes[offset + 1] << 8)) & 0x3fff;
19
+ /**
20
+ * Width and height of a WebP from its first chunk (`VP8X`, `VP8 ` or `VP8L`), or null. Like `pngSize`, a header reader, not
21
+ * a decoder: only the RIFF/WEBP signature, the first chunk's tag and its size fields are read.
22
+ */
23
+ export function webpSize(bytes) {
24
+ if (bytes.length < 30 || imageKind(bytes) !== "webp")
25
+ return null;
26
+ const tag = String.fromCharCode(bytes[12], bytes[13], bytes[14], bytes[15]);
27
+ if (tag === "VP8X")
28
+ return { width: uint24le(bytes, 24) + 1, height: uint24le(bytes, 27) + 1 };
29
+ if (tag === "VP8 " && bytes[23] === 0x9d && bytes[24] === 0x01 && bytes[25] === 0x2a)
30
+ return { width: uint14le(bytes, 26), height: uint14le(bytes, 28) };
31
+ if (tag === "VP8L" && bytes[20] === 0x2f) {
32
+ const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
33
+ return { width: (bits & 0x3fff) + 1, height: ((bits >>> 14) & 0x3fff) + 1 };
34
+ }
35
+ return null;
36
+ }
37
+ /** The size of a PNG or WebP by its contents, whatever its name, or null. */
38
+ export const imageSize = (bytes) => imageKind(bytes) === "webp" ? webpSize(bytes) : pngSize(bytes);
39
+ /**
40
+ * Why an achievement's icon (VM_OS_APPS_4.md section 2) is not acceptable, or null: it must be in the bundle, a PNG or WebP
41
+ * whose contents match its extension, exactly 128 x 128 pixels and at most 64 KiB. `os check` and `checkListing` both say this.
42
+ */
43
+ export function achievementIconProblem(icon, bytes) {
44
+ const limits = APP_SERVICE_LIMITS, expected = icon.endsWith(".webp") ? "webp" : "png";
45
+ if (!bytes)
46
+ return `${icon} is not in the built folder; copy it in.`;
47
+ if (imageKind(bytes) !== expected)
48
+ return `${icon} is not a ${expected === "png" ? "PNG" : "WebP"} image; its contents must match its extension.`;
49
+ if (bytes.byteLength > limits.achievementIconBytes)
50
+ return `${icon} is ${Math.ceil(bytes.byteLength / KiB)} KiB; an achievement icon may be at most ${limits.achievementIconBytes / KiB} KiB.`;
51
+ const size = imageSize(bytes);
52
+ if (!size || size.width !== limits.achievementIconSize || size.height !== limits.achievementIconSize)
53
+ return `${icon} is ${size ? `${size.width} x ${size.height}` : "not readable"}; it must be exactly ${limits.achievementIconSize} x ${limits.achievementIconSize} pixels.`;
54
+ return null;
55
+ }
17
56
  /** The image format named by a file's magic bytes, or null. */
18
57
  export function imageKind(bytes) {
19
58
  if (startsWith(bytes, PNG))
@@ -52,5 +91,14 @@ export function checkListing(manifest, files) {
52
91
  if (!expected || imageKind(bytes) !== expected)
53
92
  return fail("bad-screenshot", `The screenshot ${shot} is not a ${expected ?? "supported"} image, or its contents do not match its extension.`, shot);
54
93
  }
94
+ // SDK 0.6: an achievement's icon is a listing image too (a schema version 3 manifest only)
95
+ if (manifest.schemaVersion === 3)
96
+ for (const achievement of manifest.achievements ?? []) {
97
+ if (achievement.icon === null)
98
+ continue;
99
+ const problem = achievementIconProblem(achievement.icon, file(achievement.icon));
100
+ if (problem)
101
+ return fail("bad-icon", `The icon of the achievement ${achievement.id}: ${problem}`, achievement.icon);
102
+ }
55
103
  return { ok: true };
56
104
  }
@@ -85,6 +85,62 @@ export interface AppManifestV2 {
85
85
  /** What a schema version 3 app may read of the player's vmOS cards: nothing, its linked packs, or every pack. */
86
86
  export declare const APP_CARDS_ACCESS: readonly ["none", "linked", "all"];
87
87
  export type AppCardsAccess = typeof APP_CARDS_ACCESS[number];
88
+ /**
89
+ * The id of a leaderboard, achievement or product (VM_OS_APPS_4.md section 2): a lowercase letter, then up to 31 lowercase
90
+ * letters, digits and hyphens. Unique within its list; once in an approved version it keeps its meaning.
91
+ */
92
+ export declare const SERVICE_ID: RegExp;
93
+ export declare const serviceId: (value: unknown) => value is string;
94
+ /**
95
+ * Bounds of the optional `leaderboards`, `achievements` and `products` (SDK 0.6). Names and descriptions count Unicode code
96
+ * points and are one line. `priceMax` is only the SDK's structural bound on a product's whole Printer Cash price: the
97
+ * store's current maximum is lower, is set by VibeMarket and is checked when a version is submitted.
98
+ */
99
+ export declare const APP_SERVICE_LIMITS: {
100
+ readonly leaderboards: 5;
101
+ readonly achievements: 50;
102
+ readonly products: 50;
103
+ readonly nameMax: 40;
104
+ readonly descriptionMax: 120;
105
+ readonly achievementIconSize: 128;
106
+ readonly achievementIconBytes: number;
107
+ readonly priceMax: 1000000;
108
+ };
109
+ export declare const LEADERBOARD_ORDERS: readonly ["high", "low"];
110
+ export declare const LEADERBOARD_FORMATS: readonly ["number", "time"];
111
+ export declare const PRODUCT_KINDS: readonly ["consumable", "permanent"];
112
+ export type LeaderboardOrder = typeof LEADERBOARD_ORDERS[number];
113
+ export type LeaderboardFormat = typeof LEADERBOARD_FORMATS[number];
114
+ export type ProductKind = typeof PRODUCT_KINDS[number];
115
+ /** A declared leaderboard, normalized: `order` defaults to `"high"` (bigger is better), `format` to `"number"` (`"time"` is milliseconds). */
116
+ export interface AppLeaderboard {
117
+ id: string;
118
+ name: string;
119
+ order: LeaderboardOrder;
120
+ format: LeaderboardFormat;
121
+ }
122
+ /** A declared achievement, normalized: `icon` is a bundle path to a 128 x 128 PNG or WebP or null; `secret` defaults to false. */
123
+ export interface AppAchievement {
124
+ id: string;
125
+ name: string;
126
+ description: string;
127
+ icon: string | null;
128
+ secret: boolean;
129
+ }
130
+ /** A declared product: a whole Printer Cash price, bought with the player's confirmation and burned (never paid to anyone). */
131
+ export interface AppProduct {
132
+ id: string;
133
+ name: string;
134
+ description: string;
135
+ price: number;
136
+ kind: ProductKind;
137
+ }
138
+ /** The board every app has unless it declares one with this id: `finish({ score })` posts to it. */
139
+ export declare const DEFAULT_LEADERBOARD: Readonly<AppLeaderboard>;
140
+ /** The boards an app has: those it declares, in order, then the default `score` board unless one of them is `score`. */
141
+ export declare function appLeaderboards(manifest: {
142
+ leaderboards?: readonly AppLeaderboard[];
143
+ }): AppLeaderboard[];
88
144
  /** Schema version 3: a VibeStore app that may link packs, read cards and connect to declared servers. */
89
145
  export interface AppManifestV3 {
90
146
  schemaVersion: 3;
@@ -101,6 +157,12 @@ export interface AppManifestV3 {
101
157
  cards: AppCardsAccess;
102
158
  /** 0 to 8 `https://` or `wss://` origins, lowercase and sorted. Optional in the file; `[]` when absent. */
103
159
  network: string[];
160
+ /** SDK 0.6, optional: 0 to 5 boards. Present only when the file has the field, so older manifests normalize as before. */
161
+ leaderboards?: AppLeaderboard[];
162
+ /** SDK 0.6, optional: 0 to 50 achievements. Present only when the file has the field. */
163
+ achievements?: AppAchievement[];
164
+ /** SDK 0.6, optional: 0 to 50 products. Present only when the file has the field. */
165
+ products?: AppProduct[];
104
166
  }
105
167
  /** Every manifest `parseManifest` admits, discriminated on `schemaVersion`. */
106
168
  export type GameManifest = GameManifestV1 | AppManifestV2 | AppManifestV3;
@@ -122,11 +184,15 @@ export declare const APP_BUNDLE_LIMITS: {
122
184
  readonly file: number;
123
185
  readonly files: 2000;
124
186
  };
125
- /** Schema version 3 bounds: linked packs, declared origins and a pack slug's length. */
187
+ /**
188
+ * Schema version 3 bounds: linked packs, declared origins, a pack slug's length and the size of `vibemarket.json` itself
189
+ * (64 KiB since SDK 0.6, so a manifest that fills every list of APP_SERVICE_LIMITS still fits; 16 KiB before).
190
+ */
126
191
  export declare const APP_MANIFEST_LIMITS: {
127
192
  readonly packs: 3;
128
193
  readonly network: 8;
129
194
  readonly packSlugMax: 56;
195
+ readonly manifestBytes: number;
130
196
  };
131
197
  /** A pack slug, as `vibemarket/steam/pack-slug.ts` defines it (at most `APP_MANIFEST_LIMITS.packSlugMax` characters). */
132
198
  export declare const PACK_SLUG: RegExp;
@@ -161,6 +227,15 @@ export interface ManifestProblem {
161
227
  }
162
228
  /** `path: message`, the line `os check` prints and the text `parseManifest` throws for schema version 3. */
163
229
  export declare const manifestProblemText: (problem: ManifestProblem) => string;
230
+ /**
231
+ * The `leaderboards`, `achievements` and `products` of a manifest-shaped object, normalized by the manifest's own rules (for
232
+ * the testing fakes and the preview); throws the first problem as `parseManifest` would.
233
+ */
234
+ export declare function parseServices(input: {
235
+ leaderboards?: unknown;
236
+ achievements?: unknown;
237
+ products?: unknown;
238
+ }): Pick<AppManifestV3, "leaderboards" | "achievements" | "products">;
164
239
  /**
165
240
  * Things `parseManifest` accepts but a developer should change, as `os check` prints them without failing: today only a
166
241
  * schema version 2 `store.category` of "tool" or "toy", which is read as "app".