castle-web-cli 0.4.204 → 0.4.205

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 (125) hide show
  1. package/dist/agent-failures.d.ts +3 -1
  2. package/dist/agent-failures.js +19 -0
  3. package/dist/agent-prompts.js +2 -1
  4. package/dist/agent.d.ts +3 -2
  5. package/dist/agent.js +19 -10
  6. package/dist/castle-host/host.d.ts +17 -0
  7. package/dist/castle-host/host.js +551 -4
  8. package/dist/devSessionStorage.js +65 -4
  9. package/dist/effortSupport.d.ts +7 -0
  10. package/dist/effortSupport.js +31 -0
  11. package/dist/init.js +13 -3
  12. package/dist/platformDoc.js +6 -1
  13. package/dist/serve.js +35 -2
  14. package/dist/shell/assets/{index-DHzA0-Sj.js → index-hWQTC8q6.js} +5 -5
  15. package/dist/shell/index.html +1 -1
  16. package/dist/vitePlugins.js +19 -1
  17. package/kits/base/CLAUDE.md +2 -0
  18. package/kits/base/castle.json +1 -1
  19. package/kits/base/sdk/README.md +131 -0
  20. package/kits/base/sdk/agent.d.ts +6 -0
  21. package/kits/base/sdk/agent.js +70 -0
  22. package/kits/base/sdk/castle.d.ts +4 -0
  23. package/kits/base/sdk/castle.js +2 -0
  24. package/kits/base/sdk/commands.d.ts +106 -0
  25. package/kits/base/sdk/commands.js +21 -0
  26. package/kits/base/sdk/decks.d.ts +7 -0
  27. package/kits/base/sdk/decks.js +31 -0
  28. package/kits/base/sdk/runtime.d.ts +4 -2
  29. package/kits/base/sdk/runtime.js +51 -40
  30. package/kits/base/sdk/server/storage.d.ts +44 -0
  31. package/kits/base/sdk/server/storage.js +54 -0
  32. package/kits/base/sdk/transport.d.ts +5 -1
  33. package/kits/base/sdk/transport.js +106 -23
  34. package/kits/multiplayer-2d/castle.json +4 -4
  35. package/kits/multiplayer-2d/code/client/poses.js +7 -0
  36. package/kits/multiplayer-2d/code/server/limits.js +3 -0
  37. package/kits/multiplayer-2d/code/server/ownership.js +36 -8
  38. package/kits/multiplayer-2d/code/systems/multiplayer.js +23 -2
  39. package/kits/multiplayer-3d/CLAUDE.md +12 -1
  40. package/kits/multiplayer-3d/castle.json +4 -4
  41. package/kits/multiplayer-3d/code/client/avatars.js +7 -1
  42. package/kits/multiplayer-3d/code/client/poses.js +61 -1
  43. package/kits/multiplayer-3d/code/client/steer.js +383 -0
  44. package/kits/multiplayer-3d/code/server/limits.js +3 -0
  45. package/kits/multiplayer-3d/code/server/ownership.js +114 -18
  46. package/kits/multiplayer-3d/code/server/world.js +12 -4
  47. package/kits/multiplayer-3d/code/systems/multiplayer.js +315 -34
  48. package/kits/physics-3d/CLAUDE.md +65 -7
  49. package/kits/physics-3d/castle.json +3 -3
  50. package/kits/physics-3d/docs/pxmodel-format.md +916 -15
  51. package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
  52. package/kits/physics-3d/engine3d/artobjects.js +218 -0
  53. package/kits/physics-3d/engine3d/blob.js +1058 -0
  54. package/kits/physics-3d/engine3d/branches.js +300 -0
  55. package/kits/physics-3d/engine3d/cage.js +496 -0
  56. package/kits/physics-3d/engine3d/cageops.js +516 -0
  57. package/kits/physics-3d/engine3d/frame.js +669 -0
  58. package/kits/physics-3d/engine3d/look.js +675 -0
  59. package/kits/physics-3d/engine3d/materialpresets.js +486 -0
  60. package/kits/physics-3d/engine3d/modelEditorWorld.js +3 -2
  61. package/kits/physics-3d/engine3d/modelrefs.js +120 -0
  62. package/kits/physics-3d/engine3d/motion.js +560 -0
  63. package/kits/physics-3d/engine3d/objtext.js +37 -0
  64. package/kits/physics-3d/engine3d/optimize.js +1083 -0
  65. package/kits/physics-3d/engine3d/paint.js +674 -0
  66. package/kits/physics-3d/engine3d/partgeometry.js +467 -0
  67. package/kits/physics-3d/engine3d/paths.js +324 -0
  68. package/kits/physics-3d/engine3d/pxmodel.js +429 -26
  69. package/kits/physics-3d/engine3d/scatter.js +102 -0
  70. package/kits/physics-3d/engine3d/sculpt.js +1148 -0
  71. package/kits/physics-3d/engine3d/surfacedetail.js +267 -0
  72. package/kits/physics-3d/engine3d/sweep.js +480 -0
  73. package/kits/physics-3d/engine3d/thumbnails.js +6 -4
  74. package/kits/physics-3d/engine3d/world3d.js +119 -17
  75. package/kits/physics-3d/eslint.config.js +13 -0
  76. package/kits/physics-3d/models/parts/axe.pxmodel +40 -0
  77. package/kits/physics-3d/models/parts/backpack.pxmodel +47 -0
  78. package/kits/physics-3d/models/parts/barrel.pxmodel +22 -0
  79. package/kits/physics-3d/models/parts/bedroll.pxmodel +28 -0
  80. package/kits/physics-3d/models/parts/belt-pouch.pxmodel +22 -0
  81. package/kits/physics-3d/models/parts/bolt.pxmodel +10 -0
  82. package/kits/physics-3d/models/parts/bracer.pxmodel +26 -0
  83. package/kits/physics-3d/models/parts/chain-span.pxmodel +12 -0
  84. package/kits/physics-3d/models/parts/chimney.pxmodel +11 -0
  85. package/kits/physics-3d/models/parts/crate.pxmodel +44 -0
  86. package/kits/physics-3d/models/parts/crystal.pxmodel +22 -0
  87. package/kits/physics-3d/models/parts/door-arched.pxmodel +12 -0
  88. package/kits/physics-3d/models/parts/engine-block.pxmodel +39 -0
  89. package/kits/physics-3d/models/parts/exhaust-pipe.pxmodel +30 -0
  90. package/kits/physics-3d/models/parts/fence-span.pxmodel +10 -0
  91. package/kits/physics-3d/models/parts/fender.pxmodel +19 -0
  92. package/kits/physics-3d/models/parts/headlight.pxmodel +24 -0
  93. package/kits/physics-3d/models/parts/hood.pxmodel +17 -0
  94. package/kits/physics-3d/models/parts/horned-helmet.pxmodel +37 -0
  95. package/kits/physics-3d/models/parts/jerry-can.pxmodel +26 -0
  96. package/kits/physics-3d/models/parts/ladder.pxmodel +10 -0
  97. package/kits/physics-3d/models/parts/lamp.pxmodel +20 -0
  98. package/kits/physics-3d/models/parts/lantern.pxmodel +30 -0
  99. package/kits/physics-3d/models/parts/leaf-cluster.pxmodel +21 -0
  100. package/kits/physics-3d/models/parts/offroad-tire.pxmodel +48 -0
  101. package/kits/physics-3d/models/parts/pauldron.pxmodel +26 -0
  102. package/kits/physics-3d/models/parts/rivet.pxmodel +8 -0
  103. package/kits/physics-3d/models/parts/rock.pxmodel +21 -0
  104. package/kits/physics-3d/models/parts/roll-bar-light.pxmodel +26 -0
  105. package/kits/physics-3d/models/parts/round-shield.pxmodel +31 -0
  106. package/kits/physics-3d/models/parts/saddlebag.pxmodel +30 -0
  107. package/kits/physics-3d/models/parts/spoked-wheel.pxmodel +39 -0
  108. package/kits/physics-3d/models/parts/staff.pxmodel +33 -0
  109. package/kits/physics-3d/models/parts/stepping-stones.pxmodel +8 -0
  110. package/kits/physics-3d/models/parts/stone-base.pxmodel +10 -0
  111. package/kits/physics-3d/models/parts/sword.pxmodel +33 -0
  112. package/kits/physics-3d/models/parts/window-lit.pxmodel +13 -0
  113. package/kits/physics-3d/models/parts/wizard-hat.pxmodel +28 -0
  114. package/kits/physics-3d/models/templates/biped-stout.pxmodel +59 -0
  115. package/kits/physics-3d/models/templates/biped-tall.pxmodel +63 -0
  116. package/kits/physics-3d/models/templates/quadruped.pxmodel +52 -0
  117. package/kits/physics-3d/scripts/render/filmstrip.js +217 -0
  118. package/kits/physics-3d/scripts/render/index.html +20 -0
  119. package/kits/physics-3d/scripts/render/sheet.js +411 -0
  120. package/kits/physics-3d/scripts/render.mjs +646 -0
  121. package/kits/real-time/castle.json +2 -2
  122. package/kits/real-time/code/client/ownership.js +14 -4
  123. package/kits/real-time/code/client/smooth.js +2 -2
  124. package/kits/real-time/code/server/session.js +20 -4
  125. package/package.json +2 -2
@@ -0,0 +1,31 @@
1
+ export const EFFORT_ORDER = ['low', 'medium', 'high', 'xhigh', 'max'];
2
+ // Levels a model's endpoint refuses outright with a 400, keyed by exact
3
+ // OpenRouter slug so that deleting one entry re-enables the level for that
4
+ // model alone. Meta's docs: max is "Standard-tier muse-spark-1.3 only; not
5
+ // available on Contributor-tier models". The endpoint has flapped (it accepted
6
+ // max on 2026-09-22 and refused it from 09-24), so re-check before trusting
7
+ // either state for long.
8
+ export const UNSUPPORTED_EFFORTS = {
9
+ 'meta/muse-spark-1.3-contributor': ['max'],
10
+ };
11
+ // OpenRouter's ":nitro"-style variant suffixes route to the same endpoint.
12
+ function unsupportedFor(slug) {
13
+ const key = slug.trim().toLowerCase();
14
+ return UNSUPPORTED_EFFORTS[key] ?? UNSUPPORTED_EFFORTS[key.replace(/:[^/:]*$/, '')] ?? [];
15
+ }
16
+ export function effortSupported(slug, effort) {
17
+ return !unsupportedFor(slug).includes(effort);
18
+ }
19
+ export function supportedEffort(slug, effort) {
20
+ if (effortSupported(slug, effort))
21
+ return effort;
22
+ const at = EFFORT_ORDER.indexOf(effort);
23
+ const lower = EFFORT_ORDER.slice(0, at).reverse().find((level) => effortSupported(slug, level));
24
+ return lower ?? EFFORT_ORDER.slice(at + 1).find((level) => effortSupported(slug, level)) ?? effort;
25
+ }
26
+ export function isEffortLevel(value) {
27
+ return EFFORT_ORDER.includes(value);
28
+ }
29
+ export function pressedEffort(slug, stored) {
30
+ return slug && isEffortLevel(stored) ? supportedEffort(slug, stored) : stored;
31
+ }
package/dist/init.js CHANGED
@@ -56,7 +56,7 @@ if (!(await mountEditorRoute())) startGame(initCard());
56
56
  // Registry version of castle-web-sdk to inject when scaffolding from a
57
57
  // globally-installed castle-web (not from inside the workspace). Bumped
58
58
  // alongside cli/sdk version bumps.
59
- const PUBLISHED_SDK_VERSION = '0.4.34';
59
+ const PUBLISHED_SDK_VERSION = '0.4.35';
60
60
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
61
61
  // face can ship without a cli release, and a caret range means an existing
62
62
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -118,7 +118,7 @@ function tryMakeAgentsSymlink(agentsPath) {
118
118
  // scaffold gets, plus the kit's own authoring commands re-pointed at where the
119
119
  // kit now lives -- a kit's CLAUDE.md tells the agent to run `npm run draw` and
120
120
  // `npm run restart`, and those have to exist in the deck for that to be true.
121
- function makeKitDeckScripts(kitDir, alias, cliCommand) {
121
+ function makeKitDeckScripts(kitDir, alias, cliCommand, copied) {
122
122
  const scripts = {
123
123
  restart: `${cliCommand} restart .`,
124
124
  screenshot: `${cliCommand} screenshot .`,
@@ -130,6 +130,16 @@ function makeKitDeckScripts(kitDir, alias, cliCommand) {
130
130
  if (fs.existsSync(path.join(kitDir, 'scripts', 'draw.mjs'))) {
131
131
  scripts.draw = `node ${IMPORTS_DIR}/${alias}/scripts/draw.mjs`;
132
132
  }
133
+ // `render` is physics-3d's. A kit built on it (multiplayer-3d) has it copied
134
+ // in beside itself, so every copied kit is checked, the scaffolding kit
135
+ // first. The script starts serves and playtests of its own and is told the
136
+ // CLI command the deck's other scripts use.
137
+ for (const [copiedAlias, copiedDir] of copied) {
138
+ if (fs.existsSync(path.join(copiedDir, 'scripts', 'render.mjs'))) {
139
+ scripts.render = `CASTLE_WEB_CLI='${cliCommand}' node ${IMPORTS_DIR}/${copiedAlias}/scripts/render.mjs`;
140
+ break;
141
+ }
142
+ }
133
143
  return scripts;
134
144
  }
135
145
  // No `castle-web-sdk` dependency: the SDK is a file of the `base` kit this deck
@@ -570,7 +580,7 @@ function scaffoldFromKitImport(kit, projectDir) {
570
580
  name: path.basename(projectDir),
571
581
  private: true,
572
582
  type: 'module',
573
- scripts: makeKitDeckScripts(kitDir, alias, cliCommand),
583
+ scripts: makeKitDeckScripts(kitDir, alias, cliCommand, copied),
574
584
  dependencies,
575
585
  });
576
586
  fs.writeFileSync(path.join(projectDir, 'CLAUDE.md'), makeImportedKitClaudeMd(alias, !!kitConfig.server));
@@ -53,6 +53,7 @@ const MODE_BULLET = "- Unprompted, an editor is an offer, never a build: when th
53
53
  // list computed per deck.
54
54
  export function everyDeckBullets(deckDir) {
55
55
  return [
56
+ "- **Castle's Parameters panel is where a creator tunes the deck.** It is one of Castle's own panels, beside Play and Files: it shows the `PARAMS` values of every file that has one as live fields the creator drags while the deck runs, which is how they change the way it plays without putting a cursor in code.",
56
57
  `- **Supported media formats are exactly**: ${mediaList(deckDir)}. Nothing else — a published deck inlines every asset as a \`data:\` URI, where the browser trusts the declared type instead of sniffing the bytes, so a format that merely works while serving (\`.mov\` is the classic case) can be dead once published. Convert, don't improvise.`,
57
58
  "- To add an npm package, put it in `package.json` `dependencies` and run `castle-web install .` (the install `init` ran; it uses whichever package manager made the lockfile).",
58
59
  "- Do not reload the deck after an edit. Nothing auto-reloads: the person applies your changes when they are ready, from the Play panel's restart button or a panel's own reload control. `npm run restart` reloads every open panel at once and breaks their flow — only when asked.",
@@ -264,7 +265,11 @@ export function platformGuide(deckDir) {
264
265
 
265
266
  ## Formats, reloading, editors
266
267
 
267
- ${everyDeckBullets(deckDir).join('\n')}
268
+ ${everyDeckBullets(deckDir).filter((b) => !b.includes('PARAMS')).join('\n')}
269
+
270
+ ## Tunable values and the Parameters panel
271
+
272
+ ${everyDeckBullets(deckDir).filter((b) => b.includes('PARAMS')).join('\n')}
268
273
  `;
269
274
  }
270
275
  function platformDoc(deckDir) {
package/dist/serve.js CHANGED
@@ -20,7 +20,7 @@ import { migrateClaudeMd, PLATFORM_DOC_REL, writePlatformDocs } from './platform
20
20
  import { FORKS_DIR, ownForkFile, splitImportRel } from './forks.js';
21
21
  import * as config from './config.js';
22
22
  import { graphql as castleGraphql } from './api.js';
23
- import { executeCommand } from './castle-host/host.js';
23
+ import { executeCommand, fetchOracleStream } from './castle-host/host.js';
24
24
  import { ServeSecurity } from './serveSecurity.js';
25
25
  import { atomicWriteFileSync } from './atomicFile.js';
26
26
  import { isSameOriginUpgrade } from './wsOrigin.js';
@@ -726,8 +726,33 @@ async function devHostContext(projectDir) {
726
726
  username: me.username,
727
727
  };
728
728
  }
729
+ // Agent.chat's route to the oracle, authed with the CLI's login token.
730
+ const oracleStream = fetchOracleStream(() => config.getToken());
731
+ // Commands in flight on each socket, so a deck's cancel or a closed socket can
732
+ // abort a streaming one.
733
+ const commandAborts = new WeakMap();
734
+ function abortCommand(ws, requestId) {
735
+ commandAborts.get(ws)?.get(requestId)?.abort();
736
+ }
737
+ function abortSocketCommands(ws) {
738
+ for (const controller of commandAborts.get(ws)?.values() ?? []) {
739
+ controller.abort();
740
+ }
741
+ commandAborts.delete(ws);
742
+ }
729
743
  async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multiplayerUrl, playSessionSlot, requestId, command, params) {
744
+ // Registered before the first await, so a cancel that arrives while the
745
+ // context is being fetched still finds it.
746
+ const aborts = commandAborts.get(ws) ?? new Map();
747
+ commandAborts.set(ws, aborts);
748
+ const controller = new AbortController();
749
+ aborts.set(requestId, controller);
730
750
  const ctx = await devHostContext(projectDir);
751
+ const onStream = (event) => {
752
+ if (ws.readyState === WebSocket.OPEN) {
753
+ ws.send(JSON.stringify({ type: 'castle_command_stream', castleSdk: 1, requestId, stream: event }));
754
+ }
755
+ };
731
756
  // The dev server services data commands via GraphQL but supplies no
732
757
  // platformHandler, so platform/capability commands (e.g. passes.purchase)
733
758
  // resolve to their normalized "unavailable" outcome. The leaderboard UI it
@@ -735,6 +760,7 @@ async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multi
735
760
  // shell, which mounts the same panel the app and the website use.
736
761
  const result = await executeCommand(ctx, command, params, {
737
762
  graphqlFetch: castleGraphql,
763
+ oracleStream,
738
764
  showLeaderboard: (payload) => broadcast({ type: 'castle_leaderboard_show', payload }),
739
765
  getMultiplayerSession: () => {
740
766
  if (!multiplayer || !multiplayerUrl) {
@@ -755,7 +781,8 @@ async function handleCastleCommand(ws, projectDir, broadcast, multiplayer, multi
755
781
  ...(playSessionSlot ? { devReconnectScope: playSessionSlot } : {}),
756
782
  });
757
783
  },
758
- });
784
+ }, { onStream, signal: controller.signal });
785
+ aborts.delete(requestId);
759
786
  if (ws.readyState === WebSocket.OPEN) {
760
787
  ws.send(JSON.stringify({ type: 'castle_command_response', castleSdk: 1, requestId, ...result }));
761
788
  }
@@ -806,6 +833,7 @@ const BRIDGED_CONTENT_MESSAGES = new Set([
806
833
  'write_file',
807
834
  'rename_file',
808
835
  'castle_command',
836
+ 'castle_command_cancel',
809
837
  ]);
810
838
  const LEGACY_CONTENT_MESSAGES = new Set([...BRIDGED_CONTENT_MESSAGES, 'ping']);
811
839
  function readServeJson(projectDir) {
@@ -1659,6 +1687,10 @@ function startWSServer(projectDir, logFile, screenshotsDir, viteHolder, security
1659
1687
  // it runs the command via the SDK host executor with the CLI's login
1660
1688
  // token, then replies to just this socket. See castle-web-sdk's
1661
1689
  // transport.ts (local channel) + host.ts.
1690
+ if (msg.type === 'castle_command_cancel' && typeof msg.requestId === 'string') {
1691
+ abortCommand(ws, msg.requestId);
1692
+ return;
1693
+ }
1662
1694
  if (msg.type === 'castle_command' && typeof msg.requestId === 'string') {
1663
1695
  const commandMultiplayerUrl = bridgeRole
1664
1696
  ? devMultiplayerUrlFromOrigin(bridgeContentOrigin ??
@@ -1673,6 +1705,7 @@ function startWSServer(projectDir, logFile, screenshotsDir, viteHolder, security
1673
1705
  });
1674
1706
  ws.on('close', () => {
1675
1707
  clients.delete(ws);
1708
+ abortSocketCommands(ws);
1676
1709
  // Drop any in-flight requests this socket issued so the map can't leak.
1677
1710
  for (const [id, pending] of requestOrigins) {
1678
1711
  if (pending.origin === ws)