@onceworlds/cli 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +39 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1046,7 +1046,7 @@ function readZip(zip) {
1046
1046
  var INSTRUCTIONS = `Onceworlds hosts browser games with multiplayer, saves and accounts built in. These tools build a game on the user's account as drafts: the user plays every draft on their Create page and publishes it there. You never publish.
1047
1047
 
1048
1048
  How to work:
1049
- 1. read_guide once. It is the reference for the platform's SDK (window.onceworlds) and what a multiplayer game must handle (lobby, ready, reloads, a host leaving, phones).
1049
+ 1. read_guide: it returns an outline of the platform guide (the SDK, window.onceworlds, and what a multiplayer game must handle: lobby, ready, reloads, a host leaving, phones). Read "Rules of the platform", "Multiplayer rooms", "Matches" and "Designing multiplayer" with read_guide section=... before building, and the rest as you need it.
1050
1050
  2. new_game starts a folder from a template (party: rounds with a lobby, the best start for most multiplayer games; starter: a small real-time game). Build the game in that folder: plain HTML, CSS and JavaScript, or a library from a CDN (jsdelivr, cdnjs). Keep onceworlds.json's name and description right.
1051
1051
  3. check, then deploy_preview after every meaningful change. The user sees each push on their Create page within seconds.
1052
1052
  4. game_status shows the errors the user's plays of your latest draft hit. Fix them and push again.
@@ -1056,8 +1056,8 @@ var TOOLS = [
1056
1056
  {
1057
1057
  name: "read_guide",
1058
1058
  title: "Read the Onceworlds guide",
1059
- description: 'The platform guide (AGENTS.md): the SDK, multiplayer rooms and matches, what to handle, how to design and ship a game. Read it before building. Pass `section` (part of a heading, like "Matches" or "Secrets") to get only that part.',
1060
- inputSchema: { type: "object", properties: { section: { type: "string", description: "Part of a heading to return only that section." } }, additionalProperties: false },
1059
+ description: 'The platform guide (AGENTS.md, about 80 KB): the SDK, multiplayer rooms and matches, what to handle, how to design and ship a game. Without `section` it returns the outline with sizes and which parts to read first. Pass `section` (part of a heading, like "Matches" or "Secrets") to get that part, or "all" for the whole guide (about 20,000 tokens: some clients cut that off).',
1060
+ inputSchema: { type: "object", properties: { section: { type: "string", description: 'Part of a heading to return only that section, or "all".' } }, additionalProperties: false },
1061
1061
  annotations: { readOnlyHint: true }
1062
1062
  },
1063
1063
  {
@@ -1236,7 +1236,8 @@ async function readGuide(host, section) {
1236
1236
  } catch {
1237
1237
  throw new ToolError(`Could not read the guide from ${host.api}/agents.md.`);
1238
1238
  }
1239
- if (!section) return guide;
1239
+ if (section?.toLowerCase() === "all") return guide;
1240
+ if (!section) return guideOutline(guide);
1240
1241
  const wanted = section.toLowerCase();
1241
1242
  const lines = guide.split("\n");
1242
1243
  const out = [];
@@ -1262,6 +1263,29 @@ async function readGuide(host, section) {
1262
1263
  }
1263
1264
  return out.join("\n");
1264
1265
  }
1266
+ function guideOutline(guide) {
1267
+ const lines = guide.split("\n");
1268
+ const parts = [];
1269
+ let fenced = false;
1270
+ for (const line of lines) {
1271
+ if (line.startsWith("```")) fenced = !fenced;
1272
+ const heading = !fenced ? /^(#{2,3})\s+(.*)$/.exec(line) : null;
1273
+ if (heading) parts.push({ title: heading[2], level: heading[1].length, bytes: 0 });
1274
+ else if (parts.length) parts[parts.length - 1].bytes += line.length + 1;
1275
+ }
1276
+ const sized = parts.map((part, i) => {
1277
+ let bytes = part.bytes;
1278
+ for (let j = i + 1; j < parts.length && parts[j].level > part.level; j++) bytes += parts[j].bytes;
1279
+ return { ...part, bytes };
1280
+ });
1281
+ const kb = (n) => `${Math.max(1, Math.round(n / 1024))} KB`;
1282
+ return [
1283
+ `The Onceworlds guide is ${kb(guide.length)}. Read it in parts: call read_guide again with section set to part of a heading below.`,
1284
+ 'Read these before building: "Rules of the platform", "Multiplayer rooms", "Matches", "Designing multiplayer for this game", "Before you ship a multiplayer game". Use section "all" for everything at once (about 20,000 tokens; some clients cut that off).',
1285
+ "",
1286
+ ...sized.map((part) => `${part.level === 2 ? "" : " "}- ${part.title} (${kb(part.bytes)})`)
1287
+ ].join("\n");
1288
+ }
1265
1289
  async function newGame(host, args) {
1266
1290
  const slug = stringArg(args, "slug") ?? "";
1267
1291
  const name = (stringArg(args, "name") ?? "").trim();
@@ -1295,6 +1319,16 @@ async function newGame(host, args) {
1295
1319
  }
1296
1320
  await writeFile3(join3(dir, "onceworlds.json"), `${JSON.stringify({ slug, name, description, dir: "." }, null, 2)}
1297
1321
  `);
1322
+ await writeFile3(
1323
+ join3(dir, "README.md"),
1324
+ `# ${name}
1325
+
1326
+ ${description ? `${description}
1327
+
1328
+ ` : ""}An Onceworlds game. Push drafts with the onceworlds tools (deploy_preview) and publish from ${host.api}/create/${slug}.
1329
+ The platform guide is AGENTS.md.
1330
+ `
1331
+ );
1298
1332
  return [
1299
1333
  `Created ${dir} from the ${template} template (${written.join(", ")}, onceworlds.json).`,
1300
1334
  "",
@@ -1334,7 +1368,7 @@ function formatStatus(raw) {
1334
1368
  }
1335
1369
 
1336
1370
  // src/index.ts
1337
- var CLI_VERSION = "0.5.1";
1371
+ var CLI_VERSION = "0.5.2";
1338
1372
  var PRODUCTION_API = "https://onceworlds.com";
1339
1373
  var LOCAL_API = "http://localhost:8787";
1340
1374
  var USAGE = `Usage:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onceworlds/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Deploy games to Onceworlds.",
5
5
  "homepage": "https://onceworlds.com",
6
6
  "type": "module",