castle-web-cli 0.4.228 → 0.4.230

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 (236) hide show
  1. package/dist/agent-prompts.d.ts +11 -3
  2. package/dist/agent-prompts.js +153 -53
  3. package/dist/agent.d.ts +2 -0
  4. package/dist/agent.js +43 -33
  5. package/dist/api.d.ts +47 -2
  6. package/dist/api.js +85 -16
  7. package/dist/castle-host/host.d.ts +91 -0
  8. package/dist/castle-host/host.js +779 -3
  9. package/dist/castleJson.d.ts +59 -0
  10. package/dist/castleJson.js +267 -3
  11. package/dist/check.js +27 -1
  12. package/dist/cloudGit.d.ts +20 -1
  13. package/dist/cloudGit.js +267 -10
  14. package/dist/contentPack.d.ts +49 -0
  15. package/dist/contentPack.js +273 -0
  16. package/dist/devExperiments.d.ts +21 -0
  17. package/dist/devExperiments.js +139 -0
  18. package/dist/devHub.d.ts +55 -0
  19. package/dist/devHub.js +187 -0
  20. package/dist/devSessionChild.js +3 -1
  21. package/dist/devSessionServer.d.ts +14 -1
  22. package/dist/devSessionServer.js +229 -44
  23. package/dist/experimentAssignment.d.ts +15 -0
  24. package/dist/experimentAssignment.js +41 -0
  25. package/dist/importCheckHook.d.ts +40 -0
  26. package/dist/importCheckHook.js +171 -0
  27. package/dist/importRegression.d.ts +15 -0
  28. package/dist/importRegression.js +100 -0
  29. package/dist/importTrust.d.ts +2 -0
  30. package/dist/importTrust.js +27 -0
  31. package/dist/importUpdateHook.d.ts +18 -0
  32. package/dist/importUpdateHook.js +31 -8
  33. package/dist/importUpdateHookRunner.js +19 -7
  34. package/dist/imports.d.ts +16 -0
  35. package/dist/imports.js +145 -33
  36. package/dist/index.js +8 -1
  37. package/dist/init.d.ts +3 -0
  38. package/dist/init.js +125 -8
  39. package/dist/install.js +4 -1
  40. package/dist/localPaths.js +4 -0
  41. package/dist/login.js +2 -2
  42. package/dist/platformDoc.js +3 -8
  43. package/dist/playPagePolicy.js +3 -1
  44. package/dist/remix.js +5 -0
  45. package/dist/routerTaskReport.d.ts +28 -0
  46. package/dist/routerTaskReport.js +56 -0
  47. package/dist/save-deck.d.ts +18 -0
  48. package/dist/save-deck.js +145 -6
  49. package/dist/serve.d.ts +8 -0
  50. package/dist/serve.js +94 -13
  51. package/dist/serverBundle.d.ts +1 -1
  52. package/dist/serverBundle.js +5 -1
  53. package/dist/sourceLineage.d.ts +42 -0
  54. package/dist/sourceLineage.js +380 -0
  55. package/dist/webSourceSync.d.ts +11 -0
  56. package/dist/webSourceSync.js +26 -9
  57. package/kits/base/CLAUDE.md +2 -3
  58. package/kits/base/castle.json +1 -1
  59. package/kits/base/sdk/README.md +301 -52
  60. package/kits/base/sdk/agent.js +4 -4
  61. package/kits/base/sdk/avatar.d.ts +12 -0
  62. package/kits/base/sdk/avatar.js +23 -0
  63. package/kits/base/sdk/castle.d.ts +6 -1
  64. package/kits/base/sdk/castle.js +3 -0
  65. package/kits/base/sdk/commands.d.ts +208 -0
  66. package/kits/base/sdk/commands.js +16 -0
  67. package/kits/base/sdk/context.d.ts +6 -0
  68. package/kits/base/sdk/experiments.d.ts +15 -0
  69. package/kits/base/sdk/experiments.js +83 -0
  70. package/kits/base/sdk/hub.d.ts +85 -0
  71. package/kits/base/sdk/hub.js +107 -0
  72. package/kits/base/sdk/multiplayer.d.ts +86 -6
  73. package/kits/base/sdk/multiplayer.js +157 -4
  74. package/kits/base/sdk/server/hub.d.ts +169 -0
  75. package/kits/base/sdk/server/hub.js +125 -0
  76. package/kits/base/sdk/server/platformHandle.d.ts +49 -2
  77. package/kits/base/sdk/server/storage.d.ts +55 -2
  78. package/kits/base/sdk/server/wrapper.d.ts +85 -6
  79. package/kits/base/sdk/server/wrapper.js +393 -30
  80. package/kits/base/sdk/transport.d.ts +2 -1
  81. package/kits/base/sdk/transport.js +13 -1
  82. package/kits/hub-game/.prettierrc +5 -0
  83. package/kits/hub-game/CLAUDE.md +146 -0
  84. package/kits/hub-game/blueprints/avatar-0.scene +28 -0
  85. package/kits/hub-game/blueprints/avatar-1.scene +28 -0
  86. package/kits/hub-game/blueprints/avatar-2.scene +28 -0
  87. package/kits/hub-game/blueprints/avatar-3.scene +28 -0
  88. package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
  89. package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
  90. package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
  91. package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
  92. package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
  93. package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
  94. package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
  95. package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
  96. package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
  97. package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
  98. package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
  99. package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
  100. package/kits/hub-game/castle.json +96 -0
  101. package/kits/hub-game/code/client/attention.js +133 -0
  102. package/kits/hub-game/code/client/avatar.js +288 -0
  103. package/kits/hub-game/code/client/cabinets.js +90 -0
  104. package/kits/hub-game/code/client/chat.js +135 -0
  105. package/kits/hub-game/code/client/chrome.js +1001 -0
  106. package/kits/hub-game/code/client/doorFrame.js +15 -0
  107. package/kits/hub-game/code/client/firstJoin.js +14 -0
  108. package/kits/hub-game/code/client/grab.js +241 -0
  109. package/kits/hub-game/code/client/hookLayer.js +230 -0
  110. package/kits/hub-game/code/client/idle.js +326 -0
  111. package/kits/hub-game/code/client/keys.js +48 -0
  112. package/kits/hub-game/code/client/pack.js +232 -0
  113. package/kits/hub-game/code/client/packFormat.js +397 -0
  114. package/kits/hub-game/code/client/say.js +127 -0
  115. package/kits/hub-game/code/client/sha256.js +80 -0
  116. package/kits/hub-game/code/client/sound.js +147 -0
  117. package/kits/hub-game/code/client/state.js +131 -0
  118. package/kits/hub-game/code/client/talk.js +259 -0
  119. package/kits/hub-game/code/client/together.js +365 -0
  120. package/kits/hub-game/code/client/wear.js +149 -0
  121. package/kits/hub-game/code/server/actors.js +627 -0
  122. package/kits/hub-game/code/server/blocks.js +103 -0
  123. package/kits/hub-game/code/server/cabinets.js +309 -0
  124. package/kits/hub-game/code/server/game.js +137 -0
  125. package/kits/hub-game/code/server/grab.js +247 -0
  126. package/kits/hub-game/code/server/history.js +96 -0
  127. package/kits/hub-game/code/server/hub.js +1904 -0
  128. package/kits/hub-game/code/server/idle.js +412 -0
  129. package/kits/hub-game/code/server/index.js +64 -0
  130. package/kits/hub-game/code/server/labels.js +59 -0
  131. package/kits/hub-game/code/server/manifest.js +527 -0
  132. package/kits/hub-game/code/server/npcs.js +745 -0
  133. package/kits/hub-game/code/server/party.js +381 -0
  134. package/kits/hub-game/code/server/place.js +43 -0
  135. package/kits/hub-game/code/server/say.js +83 -0
  136. package/kits/hub-game/code/server/wear.js +142 -0
  137. package/kits/hub-game/code/systems/hub.js +2230 -0
  138. package/kits/hub-game/docs/content-pack.md +151 -0
  139. package/kits/hub-game/docs/contract.md +1139 -0
  140. package/kits/hub-game/docs/style.md +137 -0
  141. package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
  142. package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
  143. package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
  144. package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
  145. package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
  146. package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
  147. package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
  148. package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
  149. package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
  150. package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
  151. package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
  152. package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
  153. package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
  154. package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
  155. package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
  156. package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
  157. package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
  158. package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
  159. package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
  160. package/kits/hub-game/eslint.config.js +20 -0
  161. package/kits/hub-game/fonts.generated.js +9 -0
  162. package/kits/hub-game/index.html +22 -0
  163. package/kits/hub-game/main.jsx +6 -0
  164. package/kits/hub-game/models/avatar-0.pxmodel +21 -0
  165. package/kits/hub-game/models/avatar-1.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-2.pxmodel +27 -0
  167. package/kits/hub-game/models/avatar-3.pxmodel +22 -0
  168. package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
  169. package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
  170. package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
  171. package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
  172. package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
  173. package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
  174. package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
  175. package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
  176. package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
  177. package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
  178. package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
  179. package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
  180. package/kits/hub-game/package-lock.json +365 -0
  181. package/kits/hub-game/package.json +32 -0
  182. package/kits/hub-game/scenes/main.scene +318 -0
  183. package/kits/hub-game/scripts/check.mjs +339 -0
  184. package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
  185. package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
  186. package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
  187. package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
  188. package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
  189. package/kits/hub-game/scripts/pack.mjs +192 -0
  190. package/kits/hub-game/scripts/test-actors.mjs +666 -0
  191. package/kits/hub-game/scripts/test-attention.mjs +103 -0
  192. package/kits/hub-game/scripts/test-avatar.mjs +472 -0
  193. package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
  194. package/kits/hub-game/scripts/test-blocks.mjs +351 -0
  195. package/kits/hub-game/scripts/test-chat.mjs +98 -0
  196. package/kits/hub-game/scripts/test-classic.mjs +590 -0
  197. package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
  198. package/kits/hub-game/scripts/test-door.mjs +56 -0
  199. package/kits/hub-game/scripts/test-grab.mjs +331 -0
  200. package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
  201. package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
  202. package/kits/hub-game/scripts/test-idle.mjs +518 -0
  203. package/kits/hub-game/scripts/test-interest.mjs +413 -0
  204. package/kits/hub-game/scripts/test-keys.mjs +50 -0
  205. package/kits/hub-game/scripts/test-manifest.mjs +224 -0
  206. package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
  207. package/kits/hub-game/scripts/test-npcs.mjs +714 -0
  208. package/kits/hub-game/scripts/test-pack.mjs +424 -0
  209. package/kits/hub-game/scripts/test-party.mjs +286 -0
  210. package/kits/hub-game/scripts/test-say.mjs +149 -0
  211. package/kits/hub-game/scripts/test-together.mjs +183 -0
  212. package/kits/hub-game/theme.style +3 -0
  213. package/kits/multiplayer-3d/castle.json +5 -5
  214. package/kits/multiplayer-3d/code/client/avatars.js +101 -1
  215. package/kits/multiplayer-3d/code/server/players.js +4 -1
  216. package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
  217. package/kits/multiplayer-3d/code/server/world.js +20 -7
  218. package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
  219. package/kits/physics-2d/castle.json +2 -2
  220. package/kits/physics-2d/engine/art.js +13 -0
  221. package/kits/physics-2d/engine/assets.js +4 -2
  222. package/kits/physics-2d/engine/scene.js +25 -5
  223. package/kits/physics-3d/CLAUDE.md +6 -1
  224. package/kits/physics-3d/castle.json +3 -3
  225. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
  226. package/kits/physics-3d/engine3d/artobjects.js +2 -2
  227. package/kits/physics-3d/engine3d/materials.js +29 -1
  228. package/kits/physics-3d/engine3d/world3d.js +65 -1
  229. package/kits/physics-3d/systems/physics3d.js +5 -2
  230. package/kits/real-time/castle.json +2 -2
  231. package/kits/real-time/code/client/connection.js +77 -7
  232. package/kits/real-time/code/client/gameHooks.js +63 -3
  233. package/kits/real-time/code/client/messages.js +7 -0
  234. package/kits/real-time/code/server/gameHooks.js +24 -0
  235. package/kits/real-time/code/server/session.js +390 -22
  236. package/package.json +2 -2
package/dist/imports.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as crypto from 'crypto';
1
2
  import * as fs from 'fs';
2
3
  import * as path from 'path';
3
4
  import { nanoid } from 'nanoid';
@@ -7,6 +8,7 @@ import { normalizeDeckPackageJson } from './normalize.js';
7
8
  import { getKitsDir } from './localPaths.js';
8
9
  import { shippedFrameworkKit, shippedKitAlias } from './kitCatalog.js';
9
10
  import { SDK_PACKAGE } from './sdkResolve.js';
11
+ import { importIsOnTrustedAccount, TRUSTED_IMPORT_ACCOUNT } from './importTrust.js';
10
12
  import { writePlatformDocs } from './platformDoc.js';
11
13
  import { findImportUpdateHook, runImportUpdateHook, } from './importUpdateHook.js';
12
14
  import { IMPORTS_DIR, IMPORT_VERSION_FILE, STARTER_THEME_FILES, readCastleJson as tryReadCastleJson, readCastleJsonOrThrow as readCastleJson, } from './castleJson.js';
@@ -46,6 +48,129 @@ export function readImportVersion(deckDir, alias) {
46
48
  return null;
47
49
  }
48
50
  }
51
+ // --- builtin kits -----------------------------------------------------------
52
+ //
53
+ // A builtin pin (`source: 'builtin'`) is a copy of a kit this CLI ships, and its
54
+ // version is the CLI's version. A kit changes on main far more often than that
55
+ // version string does, so a deck's copy is stamped with a digest of the kit's
56
+ // files, and a CLI of the same version whose own copy differs replaces it
57
+ // (`refreshStaleBuiltinImports`) before the deck is installed, served or saved
58
+ // -- otherwise a save ships whatever kit the deck happened to copy first. A copy
59
+ // from another CLI version is left alone: that is never a move to make silently.
60
+ const BUILTIN_COPY_EXCLUDE = new Set(['node_modules', '.castle', 'dist', '.git']);
61
+ function builtinCopyFilter(kitDir) {
62
+ // The kit's own `imports/` is derived state, re-placed at the deck root.
63
+ const nested = path.join(kitDir, IMPORTS_DIR);
64
+ return (src) => src === kitDir || (src !== nested && !BUILTIN_COPY_EXCLUDE.has(path.basename(src)));
65
+ }
66
+ /** A kit tree's files, as a builtin copy takes them: relative path and bytes, hashed. */
67
+ export function builtinKitDigest(kitDir) {
68
+ const hash = crypto.createHash('sha256');
69
+ const keep = builtinCopyFilter(kitDir);
70
+ const walk = (dir) => {
71
+ for (const name of fs.readdirSync(dir).sort()) {
72
+ const abs = path.join(dir, name);
73
+ if (!keep(abs) || name === IMPORT_VERSION_FILE)
74
+ continue;
75
+ const stat = fs.lstatSync(abs);
76
+ const rel = path.relative(kitDir, abs).split(path.sep).join('/');
77
+ if (stat.isDirectory())
78
+ walk(abs);
79
+ else if (stat.isSymbolicLink())
80
+ hash.update(`L ${rel}\0${fs.readlinkSync(abs)}\0`);
81
+ else if (stat.isFile()) {
82
+ hash.update(`F ${rel}\0`);
83
+ hash.update(fs.readFileSync(abs));
84
+ hash.update('\0');
85
+ }
86
+ }
87
+ };
88
+ walk(kitDir);
89
+ return hash.digest('hex');
90
+ }
91
+ export function writeBuiltinStamp(importDir, stamp) {
92
+ fs.writeFileSync(path.join(importDir, IMPORT_VERSION_FILE), JSON.stringify(stamp, null, 2) + '\n', 'utf-8');
93
+ }
94
+ function readBuiltinStamp(importDir) {
95
+ try {
96
+ const value = JSON.parse(fs.readFileSync(path.join(importDir, IMPORT_VERSION_FILE), 'utf-8'));
97
+ return value?.source === 'builtin' && typeof value.digest === 'string' ? value : null;
98
+ }
99
+ catch {
100
+ return null;
101
+ }
102
+ }
103
+ /** A builtin kit copied into a deck, stamped. `destDir` must not exist. */
104
+ export function copyBuiltinKit(kitDir, destDir, kit, version) {
105
+ fs.mkdirSync(path.dirname(destDir), { recursive: true });
106
+ fs.cpSync(kitDir, destDir, { recursive: true, verbatimSymlinks: true, filter: builtinCopyFilter(kitDir) });
107
+ writeBuiltinStamp(destDir, { source: 'builtin', kit, version, digest: builtinKitDigest(kitDir) });
108
+ }
109
+ /**
110
+ * Builtin imports whose copy differs from this CLI's kit of the same version,
111
+ * replaced with this CLI's. Returns the aliases replaced.
112
+ */
113
+ export async function refreshStaleBuiltinImports(deckDir, log = (message) => console.log(message)) {
114
+ const pins = tryReadCastleJson(deckDir)?.imports ?? {};
115
+ const { getCliVersion } = await import('./init.js');
116
+ const cliVersion = getCliVersion();
117
+ const refreshed = [];
118
+ // Never throws: a kit that cannot be refreshed is left as it is and named,
119
+ // and the ones that were are still returned (serve invalidates on them).
120
+ for (const [alias, pin] of Object.entries(pins)) {
121
+ if (pin?.source !== 'builtin' || pin.version !== cliVersion)
122
+ continue;
123
+ const destDir = path.join(deckDir, IMPORTS_DIR, alias);
124
+ const kitDir = path.join(getKitsDir(), pin.kit ?? alias);
125
+ try {
126
+ if (!fs.existsSync(destDir) || !fs.existsSync(kitDir))
127
+ continue;
128
+ const digest = builtinKitDigest(kitDir);
129
+ const stamp = readBuiltinStamp(destDir);
130
+ if (stamp?.digest === digest)
131
+ continue;
132
+ if (!stamp && builtinKitDigest(destDir) === digest) {
133
+ // A copy from before stamps, already this kit: stamp it and move on.
134
+ unlockImportTree(destDir);
135
+ writeBuiltinStamp(destDir, { source: 'builtin', kit: pin.kit ?? alias, version: cliVersion, digest });
136
+ lockImportTree(destDir);
137
+ continue;
138
+ }
139
+ // Staged beside the old copy and swapped in whole, so a failed copy
140
+ // leaves the deck's import as it was.
141
+ const staged = `${destDir}.refresh-${process.pid}`;
142
+ fs.rmSync(staged, { recursive: true, force: true });
143
+ copyBuiltinKit(kitDir, staged, pin.kit ?? alias, cliVersion);
144
+ unlockImportTree(destDir);
145
+ fs.rmSync(destDir, { recursive: true, force: true });
146
+ fs.renameSync(staged, destDir);
147
+ lockImportTree(destDir);
148
+ refreshed.push(alias);
149
+ log(`Refreshed ${alias}: this deck's copy differed from the ${pin.kit ?? alias} kit this CLI (${cliVersion}) ships.`);
150
+ }
151
+ catch (e) {
152
+ log(`Left ${alias} as it is: ${e instanceof Error ? e.message : String(e)}`);
153
+ }
154
+ }
155
+ if (refreshed.length) {
156
+ // A newer copy can name imports and packages the old one did not.
157
+ try {
158
+ const { addKitDependencies } = await import('./init.js');
159
+ for (const alias of refreshed) {
160
+ const pin = pins[alias];
161
+ for (const added of addKitDependencies(deckDir, path.join(getKitsDir(), pin?.kit ?? alias))) {
162
+ log(`Added import ${added}, which the refreshed ${alias} needs.`);
163
+ }
164
+ }
165
+ await restoreMissingImports(deckDir);
166
+ await installAddedDependencies(deckDir, syncImportDependencies(deckDir));
167
+ }
168
+ catch (e) {
169
+ log(`Refreshed kits' dependencies were not all added -- run \`castle-web install\`. ${e instanceof Error ? e.message : String(e)}`);
170
+ }
171
+ }
172
+ return refreshed;
173
+ }
49
174
  // A match proves the files on disk are the ones the pin names -- same deck, same
50
175
  // version. No marker, or one that disagrees, proves nothing about them, so the
51
176
  // only way to be sure of what is there is to fetch it again.
@@ -361,13 +486,7 @@ export async function restoreMissingImports(deckDir) {
361
486
  console.warn(`Could not restore import "${alias}": this CLI ships no kit by that name.`);
362
487
  continue;
363
488
  }
364
- fs.mkdirSync(path.dirname(destDir), { recursive: true });
365
- fs.cpSync(kitDir, destDir, {
366
- recursive: true,
367
- verbatimSymlinks: true,
368
- filter: (src) => src === kitDir ||
369
- !['node_modules', '.castle', 'dist', '.git'].includes(path.basename(src)),
370
- });
489
+ copyBuiltinKit(kitDir, destDir, pin.kit ?? alias, pin.version);
371
490
  }
372
491
  else {
373
492
  console.warn(`Import "${alias}" has no deckId to fetch from; skipping.`);
@@ -594,11 +713,13 @@ async function placeFetchedImport(targetDir, deckId, givenAlias) {
594
713
  ? await api.webDeckSource(canonicalDeckId)
595
714
  : initialSource;
596
715
  if (!source) {
597
- if (meta && meta.initialCard?.type !== 'experimentalWeb') {
716
+ // 'cauldron' is the new name for the 'experimentalWeb' card type.
717
+ const cardType = meta?.initialCard?.type;
718
+ if (meta && cardType !== 'cauldron' && cardType !== 'experimentalWeb') {
598
719
  const title = meta.title?.trim();
599
720
  const subject = title ? `"${title}"` : `Deck ${canonicalDeckId}`;
600
721
  throw new ImportError('classic-deck', `${subject} is a classic Castle deck, made in the Castle app's editor. ` +
601
- `Only web decks built with castle-web can be imported; a classic deck's scenes can't be.`);
722
+ `Only Cauldron decks can be imported; a classic deck's scenes can't be.`);
602
723
  }
603
724
  throw new ImportError('no-source', `No source archive on the server for deck ${canonicalDeckId}. ` +
604
725
  'Its owner needs to run `castle-web save-deck` before it can be imported.');
@@ -652,10 +773,11 @@ export async function addImportTo(dir, options = {}) {
652
773
  const declaredMain = tryReadCastleJson(importDir)?.main;
653
774
  let adoptedMain = null;
654
775
  if (typeof declaredMain === 'string' && declaredMain.trim()) {
655
- const { isPristineBareDeck, adoptImportEntry, writeStarterScene, writeStarterTheme, retargetBareClaudeMd, adoptKitConfig, } = await import('./init.js');
776
+ const { isPristineBareDeck, adoptImportEntry, writeStarterScene, writeStarterTheme, retargetBareClaudeMd, adoptKitConfig, adoptStarterConfig, writeStarterFiles, } = await import('./init.js');
656
777
  if (isPristineBareDeck(targetDir)) {
657
778
  adoptImportEntry(targetDir, alias, declaredMain.trim());
658
779
  adoptKitConfig(targetDir, importDir, alias);
780
+ adoptStarterConfig(targetDir, importDir);
659
781
  adoptedMain = declaredMain.trim();
660
782
  retargetBareClaudeMd(targetDir, alias);
661
783
  // A kit's runtime with no scene to run is a blank screen, and the agent
@@ -677,6 +799,14 @@ export async function addImportTo(dir, options = {}) {
677
799
  catch (e) {
678
800
  console.warn(`Adopted ${alias} but could not write its starter theme.style: ${e instanceof Error ? e.message : String(e)}`);
679
801
  }
802
+ // And the rest of what the kit hands a deck starting from it, same as
803
+ // `init --kit`; each file skips on its own if the deck already has it.
804
+ try {
805
+ writeStarterFiles(targetDir, importDir);
806
+ }
807
+ catch (e) {
808
+ console.warn(`Adopted ${alias} but could not write its starter files: ${e instanceof Error ? e.message : String(e)}`);
809
+ }
680
810
  }
681
811
  }
682
812
  // An import's packages have to be ON DISK, not just named in package.json:
@@ -796,7 +926,7 @@ async function resolveUpdateHook(deckDir, alias, update, to, log) {
796
926
  return null;
797
927
  const trusted = update.trusted ?? (await importIsOnTrustedAccount(update.deckId));
798
928
  if (!trusted) {
799
- log(`${alias} ships an update hook, which only runs for imports on the ${AUTO_UPDATE_ACCOUNT} ` +
929
+ log(`${alias} ships an update hook, which only runs for imports on the ${TRUSTED_IMPORT_ACCOUNT} ` +
800
930
  `account -- skipped. Its new files are in place; this deck's own files were not migrated.`);
801
931
  return null;
802
932
  }
@@ -848,37 +978,19 @@ function importOptsIntoAutoUpdate(deckDir, alias) {
848
978
  const config = tryReadCastleJson(path.join(deckDir, IMPORTS_DIR, alias));
849
979
  return config?.autoUpdateWhenImported === true;
850
980
  }
851
- // Auto-update is honored only for imports of decks on the castle account. The
852
- // flag is the mechanism and this is a leash on it: a deck that pushes new code
853
- // to everyone who imported it is asking for a lot of trust, and until decks
854
- // carry some other signal of it, the only ones that get it are the ones we
855
- // publish (the framework kits -- the same account `init` qualifies their aliases
856
- // with).
857
- //
858
- // Deliberately not a deck setting: nothing in castle.json a person can flip,
859
- // since that would be the leash undoing itself. Process env is the escape
860
- // hatch for local kit work and tests:
981
+ // Auto-update is honored only for imports the account gate trusts (importTrust.ts
982
+ // says who, and why it is not a deck setting). Process env is the escape hatch
983
+ // for local kit work and tests:
861
984
  // - CASTLE_NO_AUTO_UPDATE=1 -- skip serve-start auto-update entirely (keep
862
985
  // whatever is already under imports/, including hand-synced kits from this
863
986
  // checkout).
864
- // - CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT -- which username counts as trusted
865
- // (default `castle`). Tests set it to exercise both branches; setting it to
866
- // a non-matching name also disables updates as a side effect.
867
- const AUTO_UPDATE_ACCOUNT = process.env.CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT ?? 'castle';
987
+ // - CASTLE_AUTO_UPDATE_TRUSTED_ACCOUNT -- which username counts as trusted.
868
988
  function autoUpdateDisabled() {
869
989
  const raw = process.env.CASTLE_NO_AUTO_UPDATE;
870
990
  if (raw == null || raw === '')
871
991
  return false;
872
992
  return raw !== '0' && raw.toLowerCase() !== 'false' && raw.toLowerCase() !== 'no';
873
993
  }
874
- // Who published a deck. Readable without auth for the same decks webDeckSource
875
- // is, so this answers in a sandbox with no login. A lookup that fails answers
876
- // "not trusted": the failure direction has to be the one that leaves an import
877
- // where its deck's author pinned it.
878
- async function importIsOnTrustedAccount(deckId) {
879
- const meta = await api.deckMeta(deckId).catch(() => null);
880
- return meta?.creator?.username === AUTO_UPDATE_ACCOUNT;
881
- }
882
994
  // Move every opted-in import that the account gate allows to the version the
883
995
  // server has now.
884
996
  //
package/dist/index.js CHANGED
@@ -138,6 +138,7 @@ function getServeSocketPort(dir) {
138
138
  }
139
139
  const FALLBACK_KITS = [
140
140
  'base',
141
+ 'hub-game',
141
142
  'multiplayer-2d',
142
143
  'multiplayer-3d',
143
144
  'physics-2d',
@@ -147,6 +148,7 @@ const FALLBACK_KITS = [
147
148
  ];
148
149
  const KIT_DESCRIPTIONS = {
149
150
  base: 'Library kit: shared SDK, editor host, and authoring guide imported by every deck.',
151
+ 'hub-game': 'A game behind a door in the Cauldron hub (experimental, not offered to the create assistant): multiplayer-3d with the hub contract, no client code.',
150
152
  'multiplayer-2d': 'Real-time multiplayer over physics-2d: a shared matter world with an authoritative server already written.',
151
153
  'multiplayer-3d': 'Real-time multiplayer over physics-3d: a shared rapier world with an authoritative server already written.',
152
154
  'physics-2d': 'Actor / behavior / scene framework for 2D games with matter-js physics. Default if --kit is omitted.',
@@ -193,7 +195,7 @@ function usage() {
193
195
  castle-web revert-import-file <imports/...> [dir]
194
196
  castle-web update-import [alias] [dir] [--check] [--revert] (re-fetches imports; no alias means all)
195
197
  castle-web install [dir]
196
- castle-web check [dir] (bundles the deck and its server, the same builds save-deck runs)
198
+ castle-web check [dir] (bundles the deck and its server, then runs each import's onCheck -- the same gates save-deck runs)
197
199
  castle-web save-version [-m MESSAGE] [paths...] [--dir DIR] (no paths saves the whole deck)
198
200
  castle-web list-versions [version] [--dir DIR] (defaults to the latest version)
199
201
  castle-web show-version <version> [--dir DIR] (diffs of the files that version changed)
@@ -442,6 +444,11 @@ async function cloudGitCommand(sub) {
442
444
  throw new Error('Usage: castle-web git attach <dir> --remote <url>');
443
445
  }
444
446
  const outcome = await cloudGit.cloudAttach(dir, remote, deps);
447
+ if ('output' in outcome) {
448
+ // The attach ran in a child of its own; this is what it said.
449
+ process.stdout.write(outcome.output);
450
+ return;
451
+ }
445
452
  console.log(`Attached ${path.resolve(dir)} to ${remote} (${outcome.repo} repo, ${outcome.outcome}).`);
446
453
  if (outcome.backup)
447
454
  console.log(`The cloud copy's differing files are saved in ${outcome.backup}.`);
package/dist/init.d.ts CHANGED
@@ -13,7 +13,10 @@ export declare function adoptImportEntry(deckDir: string, alias: string, mainFil
13
13
  export declare function getCliVersion(): string;
14
14
  export declare function writeStarterScene(projectDir: string, kitDir: string, alias: string): void;
15
15
  export declare function writeStarterTheme(projectDir: string, kitDir: string): void;
16
+ export declare function writeStarterFiles(projectDir: string, kitDir: string): string[];
17
+ export declare function adoptStarterConfig(deckDir: string, kitDir: string): string[];
16
18
  export declare function retargetBareClaudeMd(deckDir: string, alias: string): void;
19
+ export declare function addKitDependencies(deckDir: string, kitDir: string): string[];
17
20
  export interface ShippedKitImport {
18
21
  alias: string;
19
22
  deckId: string;
package/dist/init.js CHANGED
@@ -3,13 +3,14 @@ import * as path from 'path';
3
3
  import { CLAUDE_MD_PLATFORM_SECTION } from './platformDoc.js';
4
4
  import { installDeps } from './install.js';
5
5
  import { deckMainFile, deckStarterScene, STARTER_THEME_FILES } from './castleJson.js';
6
- import { addImportTo, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, writeImportVersion, } from './imports.js';
6
+ import { addImportTo, builtinKitDigest, IMPORTS_DIR, lockImportTree, restoreMissingImports, syncImportDependencies, writeBuiltinStamp, writeImportVersion, } from './imports.js';
7
7
  import { discardParentSource, fetchParentSource, unpackParentSource, writeRemixIdentity, } from './remix.js';
8
8
  import { kitFromAlias, shippedKitAlias } from './kitCatalog.js';
9
9
  import { getCliEntryPath, getKitsDir, getSdkPackagePath, toPosixPath } from './localPaths.js';
10
10
  import { SDK_PACKAGE } from './sdkResolve.js';
11
11
  import { serve } from './serve.js';
12
12
  import { createVersion } from './versions.js';
13
+ import { resolveFileInside } from './importUpdateHook.js';
13
14
  // Default kit imported by `init` when no --kit is given. `none`/`bare` skips the
14
15
  // framework and produces the minimal index.html + game.js stub below.
15
16
  const DEFAULT_KIT = 'physics-2d';
@@ -19,13 +20,10 @@ const DEFAULT_KIT = 'physics-2d';
19
20
  // A framework kit imports it too, so a kit deck has it as well.
20
21
  export const BASE_KIT = 'base';
21
22
  export const BASE_ALIAS = shippedKitAlias(BASE_KIT);
22
- // A bare deck lays itself out, so it starts as a fill deck (platformDoc.ts,
23
- // "Fit the stage"); a kit deck's entry is the kit's, and follows its guide.
24
23
  const INDEX_HTML = `<!DOCTYPE html>
25
24
  <html>
26
25
  <head>
27
26
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
28
- <meta name="castle-display" content="layout=fill">
29
27
  <title>My Castle Game</title>
30
28
  </head>
31
29
  <body>
@@ -43,7 +41,7 @@ function startGame(card) {
43
41
  el.style.cssText = \`
44
42
  width: 100%; height: 100%;
45
43
  display: flex; align-items: center; justify-content: center;
46
- font-family: system-ui; color: #fff; font-size: calc(6 * var(--castle-unit));
44
+ font-family: system-ui; color: #fff; font-size: 24px;
47
45
  \`;
48
46
  el.textContent = 'Hello Castle!';
49
47
  card.appendChild(el);
@@ -55,12 +53,12 @@ function startGame(card) {
55
53
  if (!(await mountEditorRoute())) startGame(initCard());
56
54
  `;
57
55
  // Every bare scaffold `init` has written, so isPristineBareDeck still knows an
58
- // untouched deck made before the scaffold became a fill deck.
56
+ // untouched deck made while the scaffold was a fill deck (Sept 29-30, 2026).
59
57
  const BARE_SCAFFOLDS = [
60
58
  { html: INDEX_HTML, js: GAME_JS },
61
59
  {
62
- html: INDEX_HTML.replace(' <meta name="castle-display" content="layout=fill">\n', ''),
63
- js: GAME_JS.replace('calc(6 * var(--castle-unit))', '24px'),
60
+ html: INDEX_HTML.replace(' <title>', ' <meta name="castle-display" content="layout=fill">\n <title>'),
61
+ js: GAME_JS.replace('font-size: 24px;', 'font-size: calc(6 * var(--castle-unit));'),
64
62
  },
65
63
  ];
66
64
  // Registry version of castle-web-sdk to inject when scaffolding from a
@@ -348,6 +346,87 @@ export function writeStarterTheme(projectDir, kitDir) {
348
346
  fs.copyFileSync(src, dest);
349
347
  }
350
348
  }
349
+ // The kit's `starterFiles` (castleJson.ts): files it authors that a deck
350
+ // starting from it owns from then on -- a server module to fill in, a blueprint
351
+ // to edit. Each lands at the same relative path in the deck, verbatim, and
352
+ // never over a file the deck already has. A declared path gets the same guard
353
+ // an update hook's does (`resolveFileInside`), since a kit's castle.json is
354
+ // somebody else's word for which files to copy.
355
+ //
356
+ // Read and written rather than `copyFileSync`, which would carry the mode
357
+ // across: when adopting a kit by add-import the source is a locked import, and
358
+ // the deck's copy has to be writable.
359
+ export function writeStarterFiles(projectDir, kitDir) {
360
+ const declared = readJsonFile(path.join(kitDir, 'castle.json'))?.starterFiles;
361
+ if (declared === undefined)
362
+ return [];
363
+ if (!Array.isArray(declared)) {
364
+ console.warn(`Warning: ${kitDir}'s starterFiles is not a list -- skipping it.`);
365
+ return [];
366
+ }
367
+ const written = [];
368
+ for (const entry of declared) {
369
+ const src = typeof entry === 'string' ? resolveFileInside(kitDir, entry) : null;
370
+ if (!src) {
371
+ console.warn(`Warning: starter file ${JSON.stringify(entry)} is not a file inside the kit -- skipping it.`);
372
+ continue;
373
+ }
374
+ const rel = toPosixPath(path.relative(kitDir, src));
375
+ const dest = path.join(projectDir, rel);
376
+ if (fs.existsSync(dest))
377
+ continue;
378
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
379
+ fs.writeFileSync(dest, fs.readFileSync(src));
380
+ written.push(rel);
381
+ }
382
+ return written;
383
+ }
384
+ // Never taken from a kit's `starterConfig`. The pins and the deck's identity
385
+ // are the deck's own; `editor` and `server` are `adoptKitConfig`'s, which
386
+ // rewrites them for the deck; and the rest are statements a deck makes about
387
+ // ITSELF to the decks importing it, which a deck starting from a kit has not
388
+ // made just because the kit did.
389
+ const STARTER_CONFIG_RESERVED = new Set([
390
+ 'imports',
391
+ 'editor',
392
+ 'server',
393
+ 'deckId',
394
+ 'cardId',
395
+ 'publishedVersion',
396
+ 'title',
397
+ 'autoUpdateWhenImported',
398
+ 'importWhenRemixed',
399
+ 'onUpdate',
400
+ 'onCheck',
401
+ 'main',
402
+ 'starterScene',
403
+ 'starterFiles',
404
+ 'starterConfig',
405
+ ]);
406
+ // The kit's `starterConfig` (castleJson.ts), merged into the deck's castle.json
407
+ // one top-level key at a time, for keys the deck does not have yet. Runs after
408
+ // `adoptKitConfig`, so a block that adopts first is kept.
409
+ export function adoptStarterConfig(deckDir, kitDir) {
410
+ const starter = readJsonFile(path.join(kitDir, 'castle.json'))?.starterConfig;
411
+ if (starter === undefined)
412
+ return [];
413
+ if (!starter || typeof starter !== 'object' || Array.isArray(starter)) {
414
+ console.warn(`Warning: ${kitDir}'s starterConfig is not an object -- skipping it.`);
415
+ return [];
416
+ }
417
+ const configPath = path.join(deckDir, 'castle.json');
418
+ const deckConfig = readJsonFile(configPath) ?? {};
419
+ const added = [];
420
+ for (const [key, value] of Object.entries(starter)) {
421
+ if (STARTER_CONFIG_RESERVED.has(key) || key in deckConfig)
422
+ continue;
423
+ deckConfig[key] = value;
424
+ added.push(key);
425
+ }
426
+ if (added.length > 0)
427
+ writeJsonFile(configPath, deckConfig);
428
+ return added;
429
+ }
351
430
  // A bare deck's own guide. Its `## Quick reference` is HERE rather than in the
352
431
  // base kit for one reason: this is the only place a claim like "there is no
353
432
  // scene format" is true. Every deck imports base now, kit decks included, so
@@ -508,6 +587,9 @@ function copyKitImport(projectDir, kitDir, kit, alias, pins, copied) {
508
587
  if (typeof pin.deckId === 'string') {
509
588
  writeImportVersion(importDir, { deckId: pin.deckId, version: pin.version });
510
589
  }
590
+ else if (pin.source === 'builtin' && typeof pin.version === 'string') {
591
+ writeBuiltinStamp(importDir, { source: 'builtin', kit, version: pin.version, digest: builtinKitDigest(kitDir) });
592
+ }
511
593
  const kitPins = (kitConfig.imports ?? {});
512
594
  for (const [depAlias, depPin] of Object.entries(kitPins)) {
513
595
  if (copied.has(depAlias) || pins[depAlias])
@@ -522,6 +604,37 @@ function copyKitImport(projectDir, kitDir, kit, alias, pins, copied) {
522
604
  }
523
605
  }
524
606
  }
607
+ // The imports a kit names that the deck does not pin yet, pinned and placed as
608
+ // `init` would place them (a shipped kit copied, anything else pinned for
609
+ // `install` to fetch). For a builtin kit refreshed under the deck: a newer
610
+ // copy can name dependencies the old one did not. Returns the aliases added.
611
+ export function addKitDependencies(deckDir, kitDir) {
612
+ const configPath = path.join(deckDir, 'castle.json');
613
+ const config = readJsonFile(configPath) ?? {};
614
+ const pins = { ...(config.imports ?? {}) };
615
+ const before = new Set(Object.keys(pins));
616
+ const copied = new Map();
617
+ const kitPins = ((readJsonFile(path.join(kitDir, 'castle.json')) ?? {}).imports ?? {});
618
+ for (const [depAlias, depPin] of Object.entries(kitPins)) {
619
+ if (pins[depAlias])
620
+ continue;
621
+ const depKit = kitFromAlias(depAlias);
622
+ const depKitDir = path.join(getKitsDir(), depKit);
623
+ if (fs.existsSync(depKitDir) && fs.statSync(depKitDir).isDirectory()) {
624
+ copyKitImport(deckDir, depKitDir, depKit, depAlias, pins, copied);
625
+ }
626
+ else {
627
+ pins[depAlias] = depPin;
628
+ }
629
+ }
630
+ const added = Object.keys(pins).filter((alias) => !before.has(alias));
631
+ if (added.length) {
632
+ writeJsonFile(configPath, { ...readJsonFile(configPath), imports: pins });
633
+ for (const alias of copied.keys())
634
+ lockImportTree(path.join(deckDir, IMPORTS_DIR, alias));
635
+ }
636
+ return added;
637
+ }
525
638
  // `add-import <kit>`: the same copy `init --kit` makes, into an existing deck
526
639
  // that does not have the kit yet (the caller refuses one that does). Kits the
527
640
  // deck already pins are left as they are, which is what keeps a bare deck's
@@ -599,6 +712,7 @@ function scaffoldFromKitImport(kit, projectDir) {
599
712
  writeStarterTheme(projectDir, kitDir);
600
713
  writeJsonFile(path.join(projectDir, 'castle.json'), { imports: pins });
601
714
  adoptKitConfig(projectDir, kitDir, alias);
715
+ adoptStarterConfig(projectDir, kitDir);
602
716
  // The kit's code runs from THIS deck's node_modules, so its dependencies are
603
717
  // declared here (see syncImportDependencies, which does the same for imports
604
718
  // added later). Every copied kit contributes, the scaffolding kit first, so
@@ -628,6 +742,9 @@ function scaffoldFromKitImport(kit, projectDir) {
628
742
  fs.writeFileSync(path.join(projectDir, 'CLAUDE.md'), makeImportedKitClaudeMd(alias, !!kitConfig.server));
629
743
  appendPlatformSection(projectDir);
630
744
  ensureAgentsSymlink(projectDir);
745
+ // Last, so a starter file never stands in for one the scaffold writes
746
+ // (package.json, CLAUDE.md) -- it skips any path already on disk.
747
+ writeStarterFiles(projectDir, kitDir);
631
748
  for (const importedAlias of copied.keys()) {
632
749
  lockImportTree(path.join(projectDir, IMPORTS_DIR, importedAlias));
633
750
  }
package/dist/install.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { execSync, spawn } from 'child_process';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
- import { restoreMissingImports, syncImportDependencies } from './imports.js';
4
+ import { refreshStaleBuiltinImports, restoreMissingImports, syncImportDependencies, } from './imports.js';
5
5
  import { normalizeDeckPackageJson } from './normalize.js';
6
6
  import { writePlatformDocs } from './platformDoc.js';
7
7
  // Probed in the deck, where the install itself runs: Corepack's pnpm shim refuses
@@ -74,6 +74,9 @@ export async function install(dir) {
74
74
  const restored = await restoreMissingImports(projectDir);
75
75
  for (const alias of restored)
76
76
  console.log(`Restored import ${alias}`);
77
+ // A builtin kit changes under an unchanged CLI version: a copy that differs
78
+ // from this CLI's is replaced, so the deck runs (and later saves) this kit.
79
+ await refreshStaleBuiltinImports(projectDir);
77
80
  // A fetched deck's CLAUDE.md already @imports the platform guide; write it
78
81
  // now rather than leaving the reference dangling until the first serve.
79
82
  writePlatformDocs(projectDir);
@@ -21,6 +21,10 @@ export function getSdkPackagePath() {
21
21
  return path.join(getRepoRoot(), 'sdk');
22
22
  }
23
23
  export function getKitsDir() {
24
+ // Tests stand in a kits directory of their own (scripts/tests/kit-starter-and-check.mjs).
25
+ const override = process.env.CASTLE_WEB_KITS_DIR;
26
+ if (override)
27
+ return override;
24
28
  // Prefer bundled kits (shipped inside the published cli package);
25
29
  // fall back to the workspace `kits/` alongside cli/.
26
30
  const bundled = path.join(getPackageRoot(), 'kits');
package/dist/login.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as api from './api.js';
2
2
  import * as config from './config.js';
3
3
  export async function login() {
4
- const { pollToken, url } = await api.startCLILogin();
4
+ const { pollToken, url, verifier } = await api.startCLILogin();
5
5
  console.log(`Opening browser to log in: ${url}`);
6
6
  const { default: open } = await import('open');
7
7
  await open(url);
@@ -9,7 +9,7 @@ export async function login() {
9
9
  const MAX_POLLS = 600;
10
10
  for (let i = 0; i < MAX_POLLS; i++) {
11
11
  await new Promise((r) => setTimeout(r, 1000));
12
- const user = await api.pollForCLILogin(pollToken);
12
+ const user = await api.pollForCLILogin(pollToken, verifier);
13
13
  if (user) {
14
14
  config.setAuth(user.token, user.userId);
15
15
  console.log(`Logged in as @${user.username}`);
@@ -232,14 +232,9 @@ const COMMON_SECTIONS = `## Imports are read-only
232
232
 
233
233
  - **Playable on a touchscreen, with only the controls the game actually needs.** Castle decks are played on phones, so whatever input a game does use must work by touch — direct tap/drag on the game itself wherever possible, and on-screen buttons only where the mechanics genuinely call for them. Do NOT add controls a game doesn't need: never drop in a generic d-pad or movement overlay by default. Prefer touching the game directly over an overlay that just mirrors keyboard keys. Keyboard input is fine to support on top for desktop play. Match the controls to the actual mechanics — a game with no directional movement should have no movement controls at all.
234
234
 
235
- ## Fit the stage
236
-
237
- - **A deck plays inside a stage that clips overflow and does not scroll.** By default the stage is a 5:7 portrait card sized to fit the screen (at most about 450x630px). A deck that declares \`<meta name="castle-display" content="layout=fill">\` in its \`index.html\` \`<head>\` instead gets whatever box the host can give it -- a wide stage on desktop, the full height of a tall phone, the whole screen in fullscreen -- as long as the box's width / height is inside its range (default 9/21 to 21/9; narrow it with \`min-aspect=\` / \`max-aspect=\`, as \`16/9\`, \`16:9\` or \`1.78\`). Outside the range the deck gets the largest in-range box, centered. The SDK exports \`CARD_RATIO\` (= 5 / 7) if you need the exact ratio.
238
- - **Declare fill for a deck you lay out yourself**, unless it is built around a fixed portrait board (a card game, a vertical puzzle) that would only gain empty margins: that is the default for new bare decks, and Castle's web player gives a fill deck a bigger stage and a fullscreen button. A kit deck keeps whatever its kit guide says; don't add the tag to a kit deck whose guide doesn't mention it. Fullscreen belongs to the host: never build a fullscreen button or call \`requestFullscreen\` in a deck.
239
- - **A fill deck has no fixed shape, and must look right at every shape in its range -- including 5:7, which it still gets from hosts that ignore the tag.** Lay out with flex/grid against the stage -- the element \`initCard()\` returns (its \`clientWidth\`/\`clientHeight\`), or \`var(--castle-card-w)\`/\`var(--castle-card-h)\` in CSS -- not against the window: the stage is smaller than the window whenever the host frame is outside the deck's range, and inside \`castle-web serve\`'s own page. Re-layout on \`resize\`; let the playfield use the extra room (a wider view of the world, a bigger board), and anchor HUD to the stage's edges and corners. Don't letterbox the game back into a 5:7 box inside a fill stage -- that just gives up the space.
240
- - **A deck that lays itself out sizes HUD, buttons and text in the card unit, \`var(--castle-unit)\`, not \`vw\`, \`vh\` or \`cqw\`**: \`font-size: calc(5 * var(--castle-unit))\`. It is 1% of the width of the largest 5:7 card that fits in the stage -- the same as \`1vw\` on a card -- so a HUD keeps its card size on a wide stage, where anything in \`vw\` grows to fill a monitor. Canvas code gets the same px value from \`cardUnit(width, height)\` of the stage. A kit deck sizes things the way its kit guide says: a kit's scene editor draws the stage smaller inside the editor, where the unit follows the window instead.
241
- - **A 3D camera keeps its framing across shapes with \`fovForAspect(fov, aspect)\`**: \`camera.fov = fovForAspect(50, width / height)\` on every resize. It keeps \`fov\` at 5:7 and wider and widens it on a stage taller than 5:7, so a tall phone doesn't crop the sides of the scene.
242
- - **The Play panel shows a card deck as a 5:7 card, and a fill deck at the shape picked under it**: Fit (the whole panel), Phone, Card or Landscape, each clamped into the deck's range the way a host would, with the frame's size beside the picker. A new or changed tag takes effect with the next run (Restart), like any other change to the deck. \`npm run screenshot\` captures whatever shape the open deck tab has. Those are a few shapes of many: make the layout's rules (anchors, the card unit, the camera) hold at any shape rather than tuning it pixel by pixel to what the Play panel shows. A fill deck's cover is taken at the card shape (the nearest one its range allows), since a cover is shown as a card.
235
+ ## Fit the card
236
+
237
+ - **The deck plays inside a fixed 5:7 portrait card, not the full window.** The card is sized to fit the screen (at most about 450x630px), clips overflow, and does not scroll. Design the whole layout to fit inside that portrait box: size UI relative to the card with percentages, flex/grid, \`min()\`, \`clamp()\`, or viewport-relative units instead of fixed tall panels. Let playfields scale down on smaller cards rather than overflowing; anything outside the card edges is cut off. The SDK exports \`CARD_RATIO\` (= 5 / 7) if you need the exact ratio.
243
238
  - **Hand-rolled \`<canvas>\` elements must account for devicePixelRatio, or the game looks blurry on phones.** Size the backing store to the CSS layout size times \`devicePixelRatio\` (e.g. \`canvas.width = rect.width * dpr\`), keep the CSS width/height as the layout size, and scale the 2D context (\`ctx.scale(dpr, dpr)\`) so drawing code stays in CSS units — re-apply on resize. Kit decks don't need to do this by hand; the kit's engine already configures its canvas for DPR.
244
239
  - Exception: deliberate pixel art wants a fixed low-resolution backing store with \`image-rendering: pixelated\` CSS instead — don't DPR-scale that; the crisp chunky look is the point.
245
240
  - **A WebGL canvas must be created with \`preserveDrawingBuffer: true\`, or every in-page capture of the deck comes back blank** — the Play panel's Snap and \`npm run screenshot\` both read the canvas after the frame has been shown, and by then the browser has cleared it, so the image is just the card's background. Pass it through whatever library makes the canvas: \`new THREE.WebGLRenderer({ preserveDrawingBuffer: true })\`, PixiJS \`app.init({ preserveDrawingBuffer: true })\`, or \`canvas.getContext('webgl2', { preserveDrawingBuffer: true })\`. A 2D canvas needs nothing, and kit decks already set it.
@@ -5,6 +5,8 @@
5
5
  // published bundle gets. The two must match; change both together.
6
6
  const CDN_HOSTS = 'https://esm.sh https://cdnjs.cloudflare.com';
7
7
  const PLAY_HOSTS = 'wss://*.play.castle.xyz';
8
+ // Content packs a hub door mounts (kits/hub-game/docs/content-pack.md); connect-src only.
9
+ const CONTENT_PACK_HOSTS = 'https://hosted.castle.games';
8
10
  const DECK_CSP = [
9
11
  "default-src 'self' data: blob:",
10
12
  `script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' data: blob: ${CDN_HOSTS}`,
@@ -12,7 +14,7 @@ const DECK_CSP = [
12
14
  "font-src 'self' data: blob: https://fonts.gstatic.com",
13
15
  "img-src 'self' data: blob:",
14
16
  "media-src 'self' data: blob:",
15
- `connect-src 'self' data: blob: ${CDN_HOSTS} ${PLAY_HOSTS}`,
17
+ `connect-src 'self' data: blob: ${CDN_HOSTS} ${PLAY_HOSTS} ${CONTENT_PACK_HOSTS}`,
16
18
  "frame-src 'none'",
17
19
  "child-src 'self' blob:",
18
20
  "worker-src 'self' blob:",
package/dist/remix.js CHANGED
@@ -7,6 +7,11 @@ import { downloadSourceArchive, runTar } from './save-deck.js';
7
7
  // promise to ITS importers, which a remix hasn't made -- and `onUpdate` is the
8
8
  // migration it runs in them, naming a module the remix keeps as ordinary source
9
9
  // rather than as a hook.
10
+ //
11
+ // `onCheck`, `starterScene`, `starterFiles` and `starterConfig` are kept on
12
+ // purpose: each names files the remix copied along with it, so they stay true
13
+ // of the remix. A remix of a kit that runs its own check (alias `self`) or that
14
+ // someone starts a deck from should behave as the kit did.
10
15
  const PARENT_ONLY_KEYS = [
11
16
  'deckId',
12
17
  'cardId',
@@ -0,0 +1,28 @@
1
+ import type { PromptTask } from './agent-prompts.js';
2
+ export declare const RESULT_SUMMARY_CHARS = 600;
3
+ export declare const HANDOFF_MAX_CHARS = 200;
4
+ export declare const HANDOFF_MAX_LIST = 8;
5
+ interface TaskReportTarget {
6
+ status: string;
7
+ rejected?: boolean;
8
+ handoffNoDeckFiles?: boolean;
9
+ resultSummary?: string;
10
+ resultSummaryStartsMidWord?: boolean;
11
+ }
12
+ export declare function summarizeTaskResult(finalText: string): {
13
+ resultSummary: string;
14
+ resultSummaryStartsMidWord?: boolean;
15
+ };
16
+ export declare function noDeckFiles(filesLine: string | undefined): boolean;
17
+ export declare function routerTaskReport(task: TaskReportTarget): string | undefined;
18
+ export declare function routerPromptTask(task: TaskReportTarget & {
19
+ id: string;
20
+ title: string;
21
+ progress: number;
22
+ notes: string;
23
+ model?: string;
24
+ effort?: string;
25
+ item?: string;
26
+ }): PromptTask;
27
+ export declare function quotableTaskText(row: Pick<PromptTask, 'error' | 'interrupted' | 'notes' | 'report'>, durable?: string): string;
28
+ export {};