castle-web-cli 0.4.161 → 0.4.163

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 (66) hide show
  1. package/dist/agent.js +56 -5
  2. package/dist/devSessionChild.js +23 -0
  3. package/dist/devSessionServer.js +49 -4
  4. package/dist/init.js +1 -1
  5. package/dist/platformDoc.js +2 -1
  6. package/dist/shell/assets/index-BJO7LVCM.js +422 -0
  7. package/dist/shell/index.html +1 -1
  8. package/kits/base/castle.json +1 -1
  9. package/kits/base/package-lock.json +1 -1
  10. package/kits/base/sdk/README.md +12 -1
  11. package/kits/base/sdk/multiplayer.d.ts +2 -0
  12. package/kits/base/sdk/multiplayer.js +59 -16
  13. package/kits/base/sdk/multiplayerProtocol.d.ts +3 -0
  14. package/kits/base/sdk/multiplayerProtocol.js +13 -0
  15. package/kits/base/sdk/server/platformHandle.d.ts +3 -0
  16. package/kits/base/sdk/server/wrapper.d.ts +3 -0
  17. package/kits/base/sdk/server/wrapper.js +42 -0
  18. package/kits/blank/.castle/agent/children.json +1 -0
  19. package/kits/blank/.castle/agent/messages.json +9 -0
  20. package/kits/blank/.castle/agent/pending-sends.json +1 -0
  21. package/kits/blank/.castle/agent/tasks/index.md +2 -0
  22. package/kits/blank/.castle/docs/platform.md +36 -0
  23. package/kits/blank/node_modules/.vite/deps/_metadata.json +8 -0
  24. package/kits/blank/node_modules/.vite/deps/package.json +3 -0
  25. package/package.json +1 -1
  26. package/dist/shell/assets/index-DMSoTyXh.js +0 -441
  27. package/kits/base/node_modules/.package-lock.json +0 -28
  28. package/kits/base/node_modules/castle-web-fonts/README.md +0 -114
  29. package/kits/base/node_modules/castle-web-fonts/dist/catalog.d.ts +0 -18
  30. package/kits/base/node_modules/castle-web-fonts/dist/catalog.js +0 -142
  31. package/kits/base/node_modules/castle-web-fonts/dist/face.d.ts +0 -1
  32. package/kits/base/node_modules/castle-web-fonts/dist/face.js +0 -52
  33. package/kits/base/node_modules/castle-web-fonts/dist/faces/Bore.d.ts +0 -3
  34. package/kits/base/node_modules/castle-web-fonts/dist/faces/Bore.js +0 -10
  35. package/kits/base/node_modules/castle-web-fonts/dist/faces/CourierPrime.d.ts +0 -3
  36. package/kits/base/node_modules/castle-web-fonts/dist/faces/CourierPrime.js +0 -10
  37. package/kits/base/node_modules/castle-web-fonts/dist/faces/DMSans.d.ts +0 -3
  38. package/kits/base/node_modules/castle-web-fonts/dist/faces/DMSans.js +0 -10
  39. package/kits/base/node_modules/castle-web-fonts/dist/faces/Glacier.d.ts +0 -3
  40. package/kits/base/node_modules/castle-web-fonts/dist/faces/Glacier.js +0 -10
  41. package/kits/base/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.d.ts +0 -3
  42. package/kits/base/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.js +0 -10
  43. package/kits/base/node_modules/castle-web-fonts/dist/faces/Piazzolla.d.ts +0 -3
  44. package/kits/base/node_modules/castle-web-fonts/dist/faces/Piazzolla.js +0 -10
  45. package/kits/base/node_modules/castle-web-fonts/dist/faces/Synco.d.ts +0 -3
  46. package/kits/base/node_modules/castle-web-fonts/dist/faces/Synco.js +0 -10
  47. package/kits/base/node_modules/castle-web-fonts/dist/faces/Tektur.d.ts +0 -3
  48. package/kits/base/node_modules/castle-web-fonts/dist/faces/Tektur.js +0 -10
  49. package/kits/base/node_modules/castle-web-fonts/dist/faces/YatraOne.d.ts +0 -3
  50. package/kits/base/node_modules/castle-web-fonts/dist/faces/YatraOne.js +0 -10
  51. package/kits/base/node_modules/castle-web-fonts/dist/index.d.ts +0 -16
  52. package/kits/base/node_modules/castle-web-fonts/dist/index.js +0 -15
  53. package/kits/base/node_modules/castle-web-fonts/licenses/CC-BY-ND-4.0.txt +0 -393
  54. package/kits/base/node_modules/castle-web-fonts/licenses/FONTS.md +0 -64
  55. package/kits/base/node_modules/castle-web-fonts/licenses/OFL-1.1.txt +0 -95
  56. package/kits/base/node_modules/castle-web-fonts/package.json +0 -47
  57. package/kits/base/node_modules/castle-web-fonts/woff2/Bore.woff2 +0 -0
  58. package/kits/base/node_modules/castle-web-fonts/woff2/CourierPrime.woff2 +0 -0
  59. package/kits/base/node_modules/castle-web-fonts/woff2/DMSans.woff2 +0 -0
  60. package/kits/base/node_modules/castle-web-fonts/woff2/Glacier.woff2 +0 -0
  61. package/kits/base/node_modules/castle-web-fonts/woff2/HelicoCentrica.woff2 +0 -0
  62. package/kits/base/node_modules/castle-web-fonts/woff2/Piazzolla.woff2 +0 -0
  63. package/kits/base/node_modules/castle-web-fonts/woff2/SOURCE.txt +0 -2
  64. package/kits/base/node_modules/castle-web-fonts/woff2/Synco.woff2 +0 -0
  65. package/kits/base/node_modules/castle-web-fonts/woff2/Tektur.woff2 +0 -0
  66. package/kits/base/node_modules/castle-web-fonts/woff2/YatraOne.woff2 +0 -0
package/dist/agent.js CHANGED
@@ -53,7 +53,8 @@ const DEFAULT_SETTINGS = {
53
53
  // Both roles run the claude CLI routed through OpenRouter at the slug below.
54
54
  // Note this takes the Anthropic credential out of play entirely: a role on
55
55
  // "openrouter" resolves OpenRouter auth, so a user's `claude /login` or
56
- // ANTHROPIC_API_KEY no longer applies (see buildAgentInvocation).
56
+ // ANTHROPIC_API_KEY no longer applies (see buildAgentInvocation) -- which is
57
+ // exactly why a user who HAS one defaults to ANTHROPIC_DEFAULT_MODELS below.
57
58
  routerClaudeModel: 'openrouter',
58
59
  tasksClaudeModel: 'openrouter',
59
60
  // Free-form -- change to any OpenRouter slug.
@@ -78,6 +79,25 @@ const DEFAULT_SETTINGS = {
78
79
  routerProviderTier: 'openai/priority',
79
80
  tasksProviderTier: '',
80
81
  };
82
+ // What the two claude-model defaults become once the user has an Anthropic
83
+ // credential of their own -- a key or a claude.ai login, which
84
+ // resolveAnthropicAuth already treats as one question. Signing in has to move
85
+ // these or it buys the user nothing: the openrouter default never resolves
86
+ // Anthropic auth, so an account added in the Accounts modal would sit unused
87
+ // (and the runs stay metered) until the user also found the model picker.
88
+ const ANTHROPIC_DEFAULT_MODELS = {
89
+ routerClaudeModel: 'opus',
90
+ tasksClaudeModel: 'sonnet',
91
+ };
92
+ // Resolved per read rather than captured once: the credential this asks about
93
+ // appears and disappears mid-session (the Accounts modal, `claude /login` in
94
+ // the terminal panel, a hand-edited user-keys.json), and
95
+ // refreshDefaultedSettings re-reads it when it does.
96
+ function defaultSettings() {
97
+ return resolveAnthropicAuth().mode === 'proxy'
98
+ ? { ...DEFAULT_SETTINGS }
99
+ : { ...DEFAULT_SETTINGS, ...ANTHROPIC_DEFAULT_MODELS };
100
+ }
81
101
  function normalizeBackend(value) {
82
102
  return value === 'cursor' || value === 'claude' || value === 'smith' ? value : null;
83
103
  }
@@ -182,15 +202,21 @@ const SETTING_KEYS = Object.keys(SETTING_NORMALIZERS);
182
202
  // default stores nothing, so that deck moves when the default moves. Nothing
183
203
  // is lost relative to the old behavior -- applyAgentSettings already
184
204
  // early-returns on a no-op change, so that click never persisted anything.
205
+ // Since defaultSettings() reads the Anthropic credential, "the default moves"
206
+ // now includes signing out: a role left on what was the signed-in default
207
+ // falls back to openrouter rather than sitting on a claude alias with no
208
+ // Anthropic account behind it.
185
209
  function serializeAgentSettings(settings) {
210
+ const defaults = defaultSettings();
186
211
  const out = { settingsEpoch: SETTINGS_EPOCH };
187
212
  for (const key of SETTING_KEYS) {
188
- if (settings[key] !== DEFAULT_SETTINGS[key])
213
+ if (settings[key] !== defaults[key])
189
214
  out[key] = settings[key];
190
215
  }
191
216
  return JSON.stringify(out, null, 2) + '\n';
192
217
  }
193
218
  function loadAgentSettings(settingsPath) {
219
+ const defaults = defaultSettings();
194
220
  const stored = readJsonFile(settingsPath);
195
221
  const storedEpoch = typeof stored?.settingsEpoch === 'number' ? stored.settingsEpoch : 0;
196
222
  // A stale file is ignored, not rewritten: leaving it means the wipe is a
@@ -198,7 +224,7 @@ function loadAgentSettings(settingsPath) {
198
224
  // change overwrites it in the sparse shape. A newer epoch (a downgraded CLI
199
225
  // reading a file from a newer one) is honored rather than wiped.
200
226
  if (!stored || storedEpoch < SETTINGS_EPOCH)
201
- return { ...DEFAULT_SETTINGS };
227
+ return defaults;
202
228
  const overrides = {};
203
229
  for (const key of SETTING_KEYS) {
204
230
  if (!(key in stored))
@@ -207,7 +233,24 @@ function loadAgentSettings(settingsPath) {
207
233
  if (value !== null)
208
234
  overrides[key] = value;
209
235
  }
210
- return { ...DEFAULT_SETTINGS, ...overrides };
236
+ return { ...defaults, ...overrides };
237
+ }
238
+ // Re-resolve the defaults into the live settings object after a credential
239
+ // change, in place because every consumer (the router queue, the task store)
240
+ // holds this same object. Only fields the stored file leaves unset can move --
241
+ // loadAgentSettings layers it back over the new defaults -- so a choice the
242
+ // user actually made is never overwritten. Returns whether anything moved, so
243
+ // the caller only broadcasts a real change.
244
+ function refreshDefaultedSettings(settings, settingsPath) {
245
+ const next = loadAgentSettings(settingsPath);
246
+ let changed = false;
247
+ for (const key of SETTING_KEYS) {
248
+ if (settings[key] === next[key])
249
+ continue;
250
+ Object.assign(settings, { [key]: next[key] });
251
+ changed = true;
252
+ }
253
+ return changed;
211
254
  }
212
255
  // Base for OpenRouter's Anthropic-compatible endpoint (confirmed current, 2026: it
213
256
  // accepts the standard Anthropic Messages API shape -- text/tool-use/extended-thinking
@@ -4174,7 +4217,15 @@ export function createAgentServer(opts) {
4174
4217
  const accountsFeed = createAccountsFeed({
4175
4218
  broadcast,
4176
4219
  hasClients: () => clients.size > 0,
4177
- onCredentialChange: () => usageFeed.refresh(),
4220
+ onCredentialChange: () => {
4221
+ // Signing in moves the claude-model default (see defaultSettings), and
4222
+ // nothing else pushes a settings frame -- without this the popover keeps
4223
+ // showing the model the page loaded with until a reload.
4224
+ if (refreshDefaultedSettings(settings, settingsPath)) {
4225
+ broadcast({ type: 'settings', settings });
4226
+ }
4227
+ usageFeed.refresh();
4228
+ },
4178
4229
  });
4179
4230
  const applySettings = (incoming) => {
4180
4231
  applyAgentSettings(incoming, { settings, settingsPath, broadcast });
@@ -60,6 +60,17 @@ function createPlatformHandle(init, platformEvents) {
60
60
  broadcast(text) {
61
61
  send({ protocolVersion: PROTOCOL_VERSION, t: 'broadcast', d: text });
62
62
  },
63
+ sendBinary(connId, bytes) {
64
+ send({
65
+ protocolVersion: PROTOCOL_VERSION,
66
+ t: 'sendBinary',
67
+ playerId: connId,
68
+ b: binaryBase64(bytes),
69
+ });
70
+ },
71
+ broadcastBinary(bytes) {
72
+ send({ protocolVersion: PROTOCOL_VERSION, t: 'broadcastBinary', b: binaryBase64(bytes) });
73
+ },
63
74
  disconnect(connId, code) {
64
75
  send({ protocolVersion: PROTOCOL_VERSION, t: 'kick', playerId: connId, reason: String(code) });
65
76
  },
@@ -90,6 +101,12 @@ async function dispatch(platformEvents, frame) {
90
101
  case 'clientMessage':
91
102
  await platformEvents.emit('message', frame.playerId, JSON.stringify(frame.d));
92
103
  return;
104
+ case 'clientBinary':
105
+ if (typeof frame.playerId !== 'string' || typeof frame.b !== 'string') {
106
+ throw new Error('platform channel sent an invalid binary message');
107
+ }
108
+ await platformEvents.emit('binaryMessage', frame.playerId, new Uint8Array(Buffer.from(frame.b, 'base64')));
109
+ return;
93
110
  case 'replaced':
94
111
  await platformEvents.emit('replaced');
95
112
  return;
@@ -111,6 +128,12 @@ function send(frame) {
111
128
  throw new Error('platform channel is not open');
112
129
  socket.send(JSON.stringify(frame));
113
130
  }
131
+ function binaryBase64(bytes) {
132
+ const buffer = bytes instanceof ArrayBuffer
133
+ ? Buffer.from(bytes)
134
+ : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
135
+ return buffer.toString('base64');
136
+ }
114
137
  function asRecord(value) {
115
138
  if (typeof value !== 'object' || value === null || Array.isArray(value)) {
116
139
  throw new Error('platform channel sent an invalid frame');
@@ -10,6 +10,9 @@ import { readCastleJson, resolveServerConfig } from './castleJson.js';
10
10
  import { bundleServerModule } from './serverBundle.js';
11
11
  const PROTOCOL_VERSION = 1;
12
12
  const MAX_CLIENT_FRAME_BYTES = 16 * 1024;
13
+ // Mirrors the host-agent's server-to-client broadcast cap.
14
+ const MAX_SERVER_FRAME_BYTES = 64 * 1024;
15
+ const BINARY_MESSAGE_TAG = 0x01;
13
16
  const NONCE_TTL_MS = 60_000;
14
17
  const CHILD_READY_TIMEOUT_MS = 15_000;
15
18
  const CHILD_STOP_GRACE_MS = 2_000;
@@ -38,7 +41,11 @@ class DevSessionServerImpl {
38
41
  noServer: true,
39
42
  maxPayload: MAX_CLIENT_FRAME_BYTES,
40
43
  });
41
- platformWss = new WebSocketServer({ noServer: true, maxPayload: 80 * 1024 });
44
+ // Leaves room for base64 and JSON envelope expansion around a legal server frame.
45
+ platformWss = new WebSocketServer({
46
+ noServer: true,
47
+ maxPayload: MAX_SERVER_FRAME_BYTES * 2 + 1024,
48
+ });
42
49
  nonces = new Map();
43
50
  reconnects = new Map();
44
51
  players = new Map();
@@ -229,7 +236,19 @@ class DevSessionServerImpl {
229
236
  }
230
237
  handleClientMessage(playerId, socket, data, isBinary) {
231
238
  if (isBinary) {
232
- socket.close(1003, 'binary frames are not supported');
239
+ const buffer = Buffer.isBuffer(data)
240
+ ? data
241
+ : Buffer.concat(Array.isArray(data) ? data : [Buffer.from(data)]);
242
+ if (buffer.length === 0 || buffer[0] !== BINARY_MESSAGE_TAG) {
243
+ socket.close(1003, 'unsupported binary frame');
244
+ return;
245
+ }
246
+ this.sendPlatform({
247
+ protocolVersion: PROTOCOL_VERSION,
248
+ t: 'clientBinary',
249
+ playerId,
250
+ b: buffer.subarray(1).toString('base64'),
251
+ });
233
252
  return;
234
253
  }
235
254
  let frame;
@@ -313,6 +332,13 @@ class DevSessionServerImpl {
313
332
  if (socket && payload.ok)
314
333
  this.sendClient(socket, { t: 'm', d: payload.value });
315
334
  }
335
+ else if (frame.t === 'sendBinary' &&
336
+ typeof frame.playerId === 'string' &&
337
+ typeof frame.b === 'string') {
338
+ const socket = this.players.get(frame.playerId)?.socket;
339
+ if (socket)
340
+ this.sendClientBinary(socket, Buffer.from(frame.b, 'base64'));
341
+ }
316
342
  else if (frame.t === 'broadcast') {
317
343
  const payload = parseAuthorPayload(frame.d);
318
344
  if (payload.ok)
@@ -321,6 +347,13 @@ class DevSessionServerImpl {
321
347
  this.sendClient(player.socket, { t: 'm', d: payload.value });
322
348
  }
323
349
  }
350
+ else if (frame.t === 'broadcastBinary' && typeof frame.b === 'string') {
351
+ const payload = Buffer.from(frame.b, 'base64');
352
+ for (const player of this.players.values()) {
353
+ if (player.socket)
354
+ this.sendClientBinary(player.socket, payload);
355
+ }
356
+ }
324
357
  else if (frame.t === 'kick' && typeof frame.playerId === 'string') {
325
358
  this.kick(frame.playerId, typeof frame.reason === 'string' ? frame.reason : undefined);
326
359
  }
@@ -420,12 +453,24 @@ class DevSessionServerImpl {
420
453
  if (socket.readyState !== WebSocket.OPEN)
421
454
  return;
422
455
  const text = JSON.stringify(frame);
423
- if (Buffer.byteLength(text) > MAX_CLIENT_FRAME_BYTES) {
424
- this.log('error', 'dropped a server message larger than 16KB');
456
+ if (Buffer.byteLength(text) > MAX_SERVER_FRAME_BYTES) {
457
+ this.log('error', 'dropped a server message larger than 64KB');
425
458
  return;
426
459
  }
427
460
  socket.send(text);
428
461
  }
462
+ sendClientBinary(socket, payload) {
463
+ if (socket.readyState !== WebSocket.OPEN)
464
+ return;
465
+ const frame = Buffer.allocUnsafe(payload.byteLength + 1);
466
+ frame[0] = BINARY_MESSAGE_TAG;
467
+ payload.copy(frame, 1);
468
+ if (frame.byteLength > MAX_SERVER_FRAME_BYTES) {
469
+ this.log('error', 'dropped a server message larger than 64KB');
470
+ return;
471
+ }
472
+ socket.send(frame, { binary: true });
473
+ }
429
474
  broadcastRoster() {
430
475
  const players = this.connectedPlayers();
431
476
  for (const player of this.players.values()) {
package/dist/init.js CHANGED
@@ -55,7 +55,7 @@ if (!(await mountEditorRoute())) startGame(initCard());
55
55
  // Registry version of castle-web-sdk to inject when scaffolding from a
56
56
  // globally-installed castle-web (not from inside the workspace). Bumped
57
57
  // alongside cli/sdk version bumps.
58
- const PUBLISHED_SDK_VERSION = '0.4.24';
58
+ const PUBLISHED_SDK_VERSION = '0.4.25';
59
59
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
60
60
  // face can ship without a cli release, and a caret range means an existing
61
61
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -217,7 +217,8 @@ const COMMON_SECTIONS = `## Imports are read-only
217
217
  \`named\` puts everyone passing the same \`key\` in one session, which is how you build room codes and invite links. \`public\` drops a player into a shared session for the deck; \`party\` uses the Castle party they are already in.
218
218
  - **Always handle \`conn.isSolo\`.** When a player cannot join — signed out, blocked, private deck, or no capacity free — the SDK returns a working single-player connection instead of throwing. Keep the deck playable on its own rather than gating the whole game behind other people showing up.
219
219
  - **What the server may and may not do.** Roughly 128MB of memory, no filesystem that survives, and **no network access at all**: no \`fetch\`, no database, no third-party API. Keep state in memory and send it to clients. A session ends once its last player leaves and nothing persists between sessions, so use \`sharedDeckStorage\` for anything that must outlive one.
220
- - **Limits worth designing around.** Messages from a client are capped at 16KB and about 30 per second; server broadcasts at 64KB. Sending 20–30 updates per second means sending deltas rather than whole-world snapshots, and every player's phone pays for whatever you broadcast.
220
+ - **Limits worth designing around.** Client→server messages are capped at 16 KB and about 30 per second; server→client messages are capped at 64 KB. These limits apply to both JSON and binary frames, and a binary frame includes a one-byte protocol tag. Sending 20–30 updates per second means sending deltas rather than whole-world snapshots, and every player's phone pays for whatever you broadcast.
221
+ - **Binary messages are opt-in per payload.** Pass any typed array, \`DataView\`, or \`ArrayBuffer\` to client \`send\`, server \`send\`, or server \`broadcast\` to send its raw bytes. \`onMessage\` always receives those bytes as a \`Uint8Array\`, while every other payload continues to use JSON. Reconstruct another view type such as \`Float32Array\` on receipt; multi-byte values use the sender platform's byte order.
221
222
  - **Test multiplayer locally with no setup.** \`castle-web serve\` runs your server file alongside the deck; open the play URL in two tabs and they share a session. Editing anything under \`server/\` restarts it and clients reconnect, so you exercise your reconnect path constantly. Server \`console.log\` goes to the serve's logs, not the browser console.
222
223
  - **Publishing does not disturb games in progress.** \`save-deck\` bundles and publishes \`server/\`, but sessions already running keep the code they started with (they get \`onReplaced\`, so you can prompt players), and the next new session picks up the new version.
223
224
  `;