castle-web-cli 0.4.229 → 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 (232) hide show
  1. package/dist/agent-prompts.d.ts +2 -0
  2. package/dist/agent-prompts.js +16 -8
  3. package/dist/agent.d.ts +2 -0
  4. package/dist/agent.js +21 -21
  5. package/dist/api.d.ts +28 -2
  6. package/dist/api.js +74 -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 +44 -0
  10. package/dist/castleJson.js +131 -0
  11. package/dist/check.js +27 -1
  12. package/dist/contentPack.d.ts +49 -0
  13. package/dist/contentPack.js +273 -0
  14. package/dist/devExperiments.d.ts +21 -0
  15. package/dist/devExperiments.js +139 -0
  16. package/dist/devHub.d.ts +55 -0
  17. package/dist/devHub.js +187 -0
  18. package/dist/devSessionChild.js +3 -1
  19. package/dist/devSessionServer.d.ts +14 -1
  20. package/dist/devSessionServer.js +229 -44
  21. package/dist/experimentAssignment.d.ts +15 -0
  22. package/dist/experimentAssignment.js +41 -0
  23. package/dist/importCheckHook.d.ts +40 -0
  24. package/dist/importCheckHook.js +171 -0
  25. package/dist/importRegression.d.ts +15 -0
  26. package/dist/importRegression.js +100 -0
  27. package/dist/importTrust.d.ts +2 -0
  28. package/dist/importTrust.js +27 -0
  29. package/dist/importUpdateHook.d.ts +18 -0
  30. package/dist/importUpdateHook.js +31 -8
  31. package/dist/importUpdateHookRunner.js +19 -7
  32. package/dist/imports.d.ts +16 -0
  33. package/dist/imports.js +141 -31
  34. package/dist/index.js +3 -1
  35. package/dist/init.d.ts +3 -0
  36. package/dist/init.js +125 -8
  37. package/dist/install.js +4 -1
  38. package/dist/localPaths.js +4 -0
  39. package/dist/login.js +2 -2
  40. package/dist/platformDoc.js +3 -8
  41. package/dist/playPagePolicy.js +3 -1
  42. package/dist/remix.js +5 -0
  43. package/dist/routerTaskReport.d.ts +28 -0
  44. package/dist/routerTaskReport.js +56 -0
  45. package/dist/save-deck.d.ts +18 -0
  46. package/dist/save-deck.js +142 -6
  47. package/dist/serve.d.ts +8 -0
  48. package/dist/serve.js +94 -13
  49. package/dist/serverBundle.d.ts +1 -1
  50. package/dist/serverBundle.js +5 -1
  51. package/dist/webSourceSync.d.ts +2 -0
  52. package/dist/webSourceSync.js +2 -0
  53. package/kits/base/CLAUDE.md +2 -3
  54. package/kits/base/castle.json +1 -1
  55. package/kits/base/sdk/README.md +258 -52
  56. package/kits/base/sdk/agent.js +4 -4
  57. package/kits/base/sdk/avatar.d.ts +12 -0
  58. package/kits/base/sdk/avatar.js +23 -0
  59. package/kits/base/sdk/castle.d.ts +5 -0
  60. package/kits/base/sdk/castle.js +3 -0
  61. package/kits/base/sdk/commands.d.ts +208 -0
  62. package/kits/base/sdk/commands.js +16 -0
  63. package/kits/base/sdk/context.d.ts +6 -0
  64. package/kits/base/sdk/experiments.d.ts +15 -0
  65. package/kits/base/sdk/experiments.js +83 -0
  66. package/kits/base/sdk/hub.d.ts +85 -0
  67. package/kits/base/sdk/hub.js +107 -0
  68. package/kits/base/sdk/multiplayer.d.ts +45 -1
  69. package/kits/base/sdk/multiplayer.js +106 -4
  70. package/kits/base/sdk/server/hub.d.ts +169 -0
  71. package/kits/base/sdk/server/hub.js +125 -0
  72. package/kits/base/sdk/server/platformHandle.d.ts +42 -1
  73. package/kits/base/sdk/server/storage.d.ts +55 -2
  74. package/kits/base/sdk/server/wrapper.d.ts +32 -2
  75. package/kits/base/sdk/server/wrapper.js +90 -11
  76. package/kits/base/sdk/transport.d.ts +2 -1
  77. package/kits/base/sdk/transport.js +13 -1
  78. package/kits/hub-game/.prettierrc +5 -0
  79. package/kits/hub-game/CLAUDE.md +146 -0
  80. package/kits/hub-game/blueprints/avatar-0.scene +28 -0
  81. package/kits/hub-game/blueprints/avatar-1.scene +28 -0
  82. package/kits/hub-game/blueprints/avatar-2.scene +28 -0
  83. package/kits/hub-game/blueprints/avatar-3.scene +28 -0
  84. package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
  85. package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
  86. package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
  87. package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
  88. package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
  89. package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
  90. package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
  91. package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
  92. package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
  93. package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
  94. package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
  95. package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
  96. package/kits/hub-game/castle.json +96 -0
  97. package/kits/hub-game/code/client/attention.js +133 -0
  98. package/kits/hub-game/code/client/avatar.js +288 -0
  99. package/kits/hub-game/code/client/cabinets.js +90 -0
  100. package/kits/hub-game/code/client/chat.js +135 -0
  101. package/kits/hub-game/code/client/chrome.js +1001 -0
  102. package/kits/hub-game/code/client/doorFrame.js +15 -0
  103. package/kits/hub-game/code/client/firstJoin.js +14 -0
  104. package/kits/hub-game/code/client/grab.js +241 -0
  105. package/kits/hub-game/code/client/hookLayer.js +230 -0
  106. package/kits/hub-game/code/client/idle.js +326 -0
  107. package/kits/hub-game/code/client/keys.js +48 -0
  108. package/kits/hub-game/code/client/pack.js +232 -0
  109. package/kits/hub-game/code/client/packFormat.js +397 -0
  110. package/kits/hub-game/code/client/say.js +127 -0
  111. package/kits/hub-game/code/client/sha256.js +80 -0
  112. package/kits/hub-game/code/client/sound.js +147 -0
  113. package/kits/hub-game/code/client/state.js +131 -0
  114. package/kits/hub-game/code/client/talk.js +259 -0
  115. package/kits/hub-game/code/client/together.js +365 -0
  116. package/kits/hub-game/code/client/wear.js +149 -0
  117. package/kits/hub-game/code/server/actors.js +627 -0
  118. package/kits/hub-game/code/server/blocks.js +103 -0
  119. package/kits/hub-game/code/server/cabinets.js +309 -0
  120. package/kits/hub-game/code/server/game.js +137 -0
  121. package/kits/hub-game/code/server/grab.js +247 -0
  122. package/kits/hub-game/code/server/history.js +96 -0
  123. package/kits/hub-game/code/server/hub.js +1904 -0
  124. package/kits/hub-game/code/server/idle.js +412 -0
  125. package/kits/hub-game/code/server/index.js +64 -0
  126. package/kits/hub-game/code/server/labels.js +59 -0
  127. package/kits/hub-game/code/server/manifest.js +527 -0
  128. package/kits/hub-game/code/server/npcs.js +745 -0
  129. package/kits/hub-game/code/server/party.js +381 -0
  130. package/kits/hub-game/code/server/place.js +43 -0
  131. package/kits/hub-game/code/server/say.js +83 -0
  132. package/kits/hub-game/code/server/wear.js +142 -0
  133. package/kits/hub-game/code/systems/hub.js +2230 -0
  134. package/kits/hub-game/docs/content-pack.md +151 -0
  135. package/kits/hub-game/docs/contract.md +1139 -0
  136. package/kits/hub-game/docs/style.md +137 -0
  137. package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
  138. package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
  139. package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
  140. package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
  141. package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
  142. package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
  143. package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
  144. package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
  145. package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
  146. package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
  147. package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
  148. package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
  149. package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
  150. package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
  151. package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
  152. package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
  153. package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
  154. package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
  155. package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
  156. package/kits/hub-game/eslint.config.js +20 -0
  157. package/kits/hub-game/fonts.generated.js +9 -0
  158. package/kits/hub-game/index.html +22 -0
  159. package/kits/hub-game/main.jsx +6 -0
  160. package/kits/hub-game/models/avatar-0.pxmodel +21 -0
  161. package/kits/hub-game/models/avatar-1.pxmodel +24 -0
  162. package/kits/hub-game/models/avatar-2.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-3.pxmodel +22 -0
  164. package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
  165. package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
  166. package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
  167. package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
  168. package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
  169. package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
  170. package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
  171. package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
  172. package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
  173. package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
  174. package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
  175. package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
  176. package/kits/hub-game/package-lock.json +365 -0
  177. package/kits/hub-game/package.json +32 -0
  178. package/kits/hub-game/scenes/main.scene +318 -0
  179. package/kits/hub-game/scripts/check.mjs +339 -0
  180. package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
  181. package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
  182. package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
  183. package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
  184. package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
  185. package/kits/hub-game/scripts/pack.mjs +192 -0
  186. package/kits/hub-game/scripts/test-actors.mjs +666 -0
  187. package/kits/hub-game/scripts/test-attention.mjs +103 -0
  188. package/kits/hub-game/scripts/test-avatar.mjs +472 -0
  189. package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
  190. package/kits/hub-game/scripts/test-blocks.mjs +351 -0
  191. package/kits/hub-game/scripts/test-chat.mjs +98 -0
  192. package/kits/hub-game/scripts/test-classic.mjs +590 -0
  193. package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
  194. package/kits/hub-game/scripts/test-door.mjs +56 -0
  195. package/kits/hub-game/scripts/test-grab.mjs +331 -0
  196. package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
  197. package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
  198. package/kits/hub-game/scripts/test-idle.mjs +518 -0
  199. package/kits/hub-game/scripts/test-interest.mjs +413 -0
  200. package/kits/hub-game/scripts/test-keys.mjs +50 -0
  201. package/kits/hub-game/scripts/test-manifest.mjs +224 -0
  202. package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
  203. package/kits/hub-game/scripts/test-npcs.mjs +714 -0
  204. package/kits/hub-game/scripts/test-pack.mjs +424 -0
  205. package/kits/hub-game/scripts/test-party.mjs +286 -0
  206. package/kits/hub-game/scripts/test-say.mjs +149 -0
  207. package/kits/hub-game/scripts/test-together.mjs +183 -0
  208. package/kits/hub-game/theme.style +3 -0
  209. package/kits/multiplayer-3d/castle.json +5 -5
  210. package/kits/multiplayer-3d/code/client/avatars.js +101 -1
  211. package/kits/multiplayer-3d/code/server/players.js +4 -1
  212. package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
  213. package/kits/multiplayer-3d/code/server/world.js +20 -7
  214. package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
  215. package/kits/physics-2d/castle.json +2 -2
  216. package/kits/physics-2d/engine/art.js +13 -0
  217. package/kits/physics-2d/engine/assets.js +4 -2
  218. package/kits/physics-2d/engine/scene.js +25 -5
  219. package/kits/physics-3d/CLAUDE.md +6 -1
  220. package/kits/physics-3d/castle.json +3 -3
  221. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
  222. package/kits/physics-3d/engine3d/artobjects.js +2 -2
  223. package/kits/physics-3d/engine3d/materials.js +29 -1
  224. package/kits/physics-3d/engine3d/world3d.js +65 -1
  225. package/kits/physics-3d/systems/physics3d.js +5 -2
  226. package/kits/real-time/castle.json +2 -2
  227. package/kits/real-time/code/client/connection.js +77 -7
  228. package/kits/real-time/code/client/gameHooks.js +63 -3
  229. package/kits/real-time/code/client/messages.js +7 -0
  230. package/kits/real-time/code/server/gameHooks.js +24 -0
  231. package/kits/real-time/code/server/session.js +390 -22
  232. package/package.json +2 -2
@@ -9,6 +9,7 @@ export interface PromptTask {
9
9
  status: string;
10
10
  progress: number;
11
11
  notes: string;
12
+ report?: string;
12
13
  model?: string;
13
14
  effort?: string;
14
15
  item?: string;
@@ -66,6 +67,7 @@ export declare function truncateToBytes(line: string, budget: number): string;
66
67
  export declare const PLAN_SECTION_CAPS: Record<string, number>;
67
68
  export declare const PLAN_DIGEST_BYTE_BUDGET: number;
68
69
  export declare const BUILT_MAX_LINES = 15;
70
+ export declare const BUILT_WHAT_TARGET_CHARS = 150;
69
71
  export declare const TASK_PLAN_SLICE_BYTE_BUDGET: number;
70
72
  export declare const DECISIONS_PINNED = 10;
71
73
  export declare const DECISIONS_RETRIEVED = 6;
@@ -266,8 +266,9 @@ export const PLAN_SECTION_CAPS = {
266
266
  tried: 8,
267
267
  };
268
268
  const PLAN_SECTION_DEFAULT_CAP = 8;
269
- export const PLAN_DIGEST_BYTE_BUDGET = 3 * 1024;
269
+ export const PLAN_DIGEST_BYTE_BUDGET = 4 * 1024;
270
270
  export const BUILT_MAX_LINES = 15;
271
+ export const BUILT_WHAT_TARGET_CHARS = 150;
271
272
  export const TASK_PLAN_SLICE_BYTE_BUDGET = 6 * 1024;
272
273
  export const DECISIONS_PINNED = 10;
273
274
  export const DECISIONS_RETRIEVED = 6;
@@ -780,6 +781,10 @@ function trimVictim(sections) {
780
781
  longestOf((s) => s.key !== "built") ??
781
782
  longestOf(() => true));
782
783
  }
784
+ function routerBuiltLine(work) {
785
+ const knobs = work.knobs?.length ? ` (knobs: ${work.knobs.join(", ")})` : "";
786
+ return `- ${work.item}: ${work.what}${knobs}`;
787
+ }
783
788
  function builtLine(work) {
784
789
  const files = work.files?.length ? ` (files: ${work.files.join(", ")})` : "";
785
790
  const knobs = work.knobs?.length ? ` (knobs: ${work.knobs.join(", ")})` : "";
@@ -789,7 +794,7 @@ function builtLine(work) {
789
794
  // first. Latest-wins per item rather than a log -- the section answers "what
790
795
  // exists now", and a per-task history would grow with every task the deck ever
791
796
  // ran. What is evicted is still on disk in the task handoffs.
792
- function deriveBuiltLines(finished) {
797
+ function deriveBuiltLines(finished, renderLine = builtLine) {
793
798
  const latest = new Map();
794
799
  for (const work of finished) {
795
800
  if (!work.item.trim() || work.item === "-" || !work.what.trim())
@@ -799,15 +804,16 @@ function deriveBuiltLines(finished) {
799
804
  latest.set(work.item, work);
800
805
  }
801
806
  const newestFirst = [...latest.values()].sort((a, b) => (b.at ?? "").localeCompare(a.at ?? ""));
802
- const lines = newestFirst.slice(0, BUILT_MAX_LINES).map(builtLine);
807
+ const lines = newestFirst.slice(0, BUILT_MAX_LINES).map(renderLine);
803
808
  const dropped = newestFirst.length - lines.length;
804
809
  if (dropped > 0)
805
810
  lines.push(`(${dropped} more in the archive)`);
806
811
  return lines;
807
812
  }
813
+ const NO_PLAN_PREFIX = "(no plan.md yet)\n\n";
808
814
  function fitPlanSections(plan, tasks, query) {
809
815
  const sections = [];
810
- const built = deriveBuiltLines(plan.finishedWork ?? []);
816
+ const built = deriveBuiltLines(plan.finishedWork ?? [], routerBuiltLine);
811
817
  const settled = new Set(plan.settledItems ?? []);
812
818
  const source = parsePlanSections(plan.fileText ?? "");
813
819
  const decided = new Set(source
@@ -853,7 +859,8 @@ function fitPlanSections(plan, tasks, query) {
853
859
  trimmed: false,
854
860
  });
855
861
  }
856
- return fitSectionsToBytes(sections, PLAN_DIGEST_BYTE_BUDGET);
862
+ const reserved = plan.fileText?.trim() ? 0 : Buffer.byteLength(NO_PLAN_PREFIX, "utf8");
863
+ return fitSectionsToBytes(sections, PLAN_DIGEST_BYTE_BUDGET - reserved);
857
864
  }
858
865
  function fitSectionsToBytes(sections, budget) {
859
866
  const render = () => sections
@@ -913,7 +920,7 @@ export function renderPlanDigest(plan, tasks, query = "") {
913
920
  const parts = [
914
921
  plan.fileText?.trim()
915
922
  ? fitted
916
- : ["(no plan.md yet)", fitted].filter(Boolean).join("\n\n"),
923
+ : fitted ? `${NO_PLAN_PREFIX}${fitted}` : NO_PLAN_PREFIX.trimEnd(),
917
924
  ];
918
925
  const nominations = plan.pendingDurables ?? [];
919
926
  if (nominations.length > 0) {
@@ -991,13 +998,14 @@ function renderTasks(tasks, showItems, isFreeModel) {
991
998
  ? ` -- model: ${[t.model && modelLabel(t.model, isFreeModel), t.effort].filter(Boolean).join(" ")}`
992
999
  : "";
993
1000
  const notes = t.notes.trim() ? ` -- notes: ${t.notes.trim()}` : "";
1001
+ const report = t.report ? ` -- report: ${t.report}` : "";
994
1002
  const error = t.error ? ` -- error: ${t.error}` : "";
995
1003
  const interrupted = t.interrupted ? ` -- interrupted: ${t.interrupted}` : "";
996
1004
  const blockedBy = t.blockedBy && t.blockedBy.length > 0
997
1005
  ? ` -- blocked by: ${t.blockedBy.join(", ")}`
998
1006
  : "";
999
1007
  const sent = t.sent ? ` -- messages you sent it: ${t.sent}` : "";
1000
- const row = `- [${t.status} ${t.progress}%] ${t.title} (${t.id})${item}${model}${notes}${error}${interrupted}${blockedBy}${sent}`;
1008
+ const row = `- [${t.status} ${t.progress}%] ${t.title} (${t.id})${item}${model}${notes}${report}${error}${interrupted}${blockedBy}${sent}`;
1001
1009
  const held = t.status === "held" && t.heldQuestion !== undefined
1002
1010
  ? `\n held -- waiting on the answer to: ${t.heldQuestion}`
1003
1011
  : "";
@@ -1188,7 +1196,7 @@ export function buildTaskPrompt(opts) {
1188
1196
  ? "\n- The plan above is context, not a brief. It tells you what is settled and what already exists; it never widens your task. Do NOT edit plan.md -- it belongs to the conversation agent and the user."
1189
1197
  : "",
1190
1198
  opts.plan
1191
- ? `\n- Before you finish, write these lines to ${opts.handoffPath} -- they are the ONLY record of this task once the task itself is forgotten:\n - \`what: <what now exists, and where>\` -- an existence fact, not a report of activity: "a shop panel in ui/shop.js the bag button opens", never "updated the shop logic". This is what the plan shows as already built, so a later agent extends it instead of rebuilding it.\n - \`files: <the files you created or changed, comma-separated>\`\n - \`knobs: <the values worth tuning, comma-separated>\` -- names only, and only if there are real ones.\n - \`durable: <fact>\` -- the single thing worth remembering that is NOT covered by the three above (a preference the user expressed, a constraint you ran into, an approach that did not work). At most 200 characters. Leave it out only if nothing genuinely qualifies.`
1199
+ ? `\n- Before you finish, write these lines to ${opts.handoffPath} -- they are the ONLY record of this task once the task itself is forgotten:\n - \`what: <what now exists, and where>\` -- an existence fact, not a report of activity: "a shop panel in ui/shop.js the bag button opens", never "updated the shop logic". This is what the plan shows as already built, so a later agent extends it instead of rebuilding it. Try to keep it under ${BUILT_WHAT_TARGET_CHARS} characters and lead with the feature: the plan shows this line whole, and a long one crowds out the rest of the plan.\n - \`files: <the files you created or changed, comma-separated>\`\n - \`knobs: <the values worth tuning, comma-separated>\` -- names only, and only if there are real ones.\n - \`durable: <fact>\` -- the single thing worth remembering that is NOT covered by the three above (a preference the user expressed, a constraint you ran into, an approach that did not work). At most 200 characters. Leave it out only if nothing genuinely qualifies.`
1192
1200
  : "",
1193
1201
  ].join("");
1194
1202
  // Collapsing the wrap-up (progress 90 + notes) into one shell call reliably
package/dist/agent.d.ts CHANGED
@@ -68,6 +68,7 @@ interface TaskRecord {
68
68
  answer?: string;
69
69
  playtestFrames?: string[];
70
70
  resultSummary?: string;
71
+ resultSummaryStartsMidWord?: boolean;
71
72
  account?: string;
72
73
  errorCopy?: string;
73
74
  errorDetail?: string;
@@ -82,6 +83,7 @@ interface TaskRecord {
82
83
  durable?: string;
83
84
  what?: string;
84
85
  files?: string[];
86
+ handoffNoDeckFiles?: boolean;
85
87
  knobs?: string[];
86
88
  durablePending?: boolean;
87
89
  blockedBy?: string[];
package/dist/agent.js CHANGED
@@ -34,6 +34,7 @@ import { extractDirectives, meansAll, closedPrefLines, parsePrefLines, parseTask
34
34
  import { isPendingSteer, newTaskSteer, normalizeSteers, replayedUuid, steerBoardNote, steerMessageText, streamUserLine, } from './taskSteer.js';
35
35
  import { carriesStopNotes, recentStops, stopNotes, } from './routerStops.js';
36
36
  import { badTaskEndingsSince, platformInterruptionReason, ROUTER_STOPPED_RESULT, withTimeoutReport, } from './routerTaskEndings.js';
37
+ import { HANDOFF_MAX_CHARS, HANDOFF_MAX_LIST, noDeckFiles, quotableTaskText, routerPromptTask, summarizeTaskResult, } from './routerTaskReport.js';
37
38
  import { accountForRun, closingMessageOf } from './taskAccount.js';
38
39
  import { atomicWriteFileSync } from './atomicFile.js';
39
40
  import { AGENT_ATTACHMENT_PREFIX, AGENT_PLAYTEST_PREFIX, PLAN_FILE } from './localPaths.js';
@@ -543,7 +544,6 @@ const TASK_STEER_ENABLED = process.env.CASTLE_TASK_STEER === '1';
543
544
  const MAX_TASK_RESUMES = 3;
544
545
  const TASK_POLL_MS = 1_000;
545
546
  const FENCE_HOLDBACK = '```castle-';
546
- const RESULT_SUMMARY_CHARS = 600;
547
547
  const MAX_ATTACHMENTS = 6;
548
548
  // @-mentioned places are references, so the only cost is instruction bytes --
549
549
  // but a client is not the one to decide how many the router is told about.
@@ -716,9 +716,7 @@ function planOpSources(taskStore, messages) {
716
716
  const taskReports = new Map();
717
717
  for (const task of taskStore.sorted()) {
718
718
  const row = asPromptTask(task);
719
- const text = [task.durable, row.error, row.interrupted, row.notes]
720
- .filter((s) => s?.trim())
721
- .join('\n');
719
+ const text = quotableTaskText(row, task.durable);
722
720
  if (text)
723
721
  taskReports.set(task.id, text);
724
722
  }
@@ -2042,7 +2040,9 @@ const TASK_OPTIONAL_STRINGS = [
2042
2040
  ];
2043
2041
  const TASK_OPTIONAL_NUMBERS = ['pid', 'costUsd', 'durationApiMs', 'numTurns', 'resumeCount'];
2044
2042
  const TASK_OPTIONAL_OBJECTS = ['usage', 'modelUsage'];
2045
- const TASK_OPTIONAL_BOOLEANS = ['acknowledged', 'rejected', 'durablePending'];
2043
+ const TASK_OPTIONAL_BOOLEANS = [
2044
+ 'acknowledged', 'rejected', 'durablePending', 'resultSummaryStartsMidWord', 'handoffNoDeckFiles',
2045
+ ];
2046
2046
  const TASK_OPTIONAL_STRING_LISTS = ['playtestFrames', 'files', 'knobs', 'blockedBy'];
2047
2047
  const isStringList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string');
2048
2048
  function isHeldFor(v) {
@@ -2128,22 +2128,21 @@ function loadTasks(tasksDir) {
2128
2128
  }
2129
2129
  return tasks;
2130
2130
  }
2131
- // A handoff line is one fact, and a long one is a summary rather than the
2132
- // single fact the prompt asks for.
2133
- const HANDOFF_MAX_CHARS = 200;
2134
- const HANDOFF_MAX_LIST = 8;
2135
2131
  // One field of the handoff file -- the FIRST line carrying it, since the prompt
2136
2132
  // asks for one of each and a task that wrote several has already missed the
2137
2133
  // point.
2138
- function handoffField(handoff, field) {
2134
+ function rawHandoffField(handoff, field) {
2139
2135
  const match = new RegExp(`^${field}:\\s*(.+)$`, 'i');
2140
2136
  for (const line of handoff.split('\n')) {
2141
2137
  const found = match.exec(line.trim());
2142
2138
  if (found)
2143
- return found[1].trim().slice(0, HANDOFF_MAX_CHARS);
2139
+ return found[1].trim();
2144
2140
  }
2145
2141
  return undefined;
2146
2142
  }
2143
+ function handoffField(handoff, field) {
2144
+ return rawHandoffField(handoff, field)?.slice(0, HANDOFF_MAX_CHARS);
2145
+ }
2147
2146
  function handoffList(handoff, field) {
2148
2147
  const items = (handoffField(handoff, field) ?? '')
2149
2148
  .split(',')
@@ -2164,6 +2163,11 @@ function refreshHandoff(dir, task) {
2164
2163
  return false;
2165
2164
  }
2166
2165
  let changed = false;
2166
+ const handoffNoDeckFiles = noDeckFiles(rawHandoffField(handoff, 'files'));
2167
+ if (handoffNoDeckFiles !== task.handoffNoDeckFiles) {
2168
+ task.handoffNoDeckFiles = handoffNoDeckFiles;
2169
+ changed = true;
2170
+ }
2167
2171
  const durable = handoffField(handoff, 'durable');
2168
2172
  if (durable && durable !== task.durable) {
2169
2173
  task.durable = durable;
@@ -2849,11 +2853,14 @@ function startTask(ctx, task) {
2849
2853
  if (result.ok && !wasStopped)
2850
2854
  task.progress = 100;
2851
2855
  task.finishedAt = nowIso();
2856
+ const summary = summarizeTaskResult(result.finalText);
2852
2857
  task.resultSummary = wasStopped
2853
2858
  ? ROUTER_STOPPED_RESULT
2854
2859
  : result.ok
2855
- ? result.finalText.slice(-RESULT_SUMMARY_CHARS)
2856
- : `${result.error ?? 'failed'}\n${result.finalText.slice(-RESULT_SUMMARY_CHARS)}`;
2860
+ ? summary.resultSummary
2861
+ : `${result.error ?? 'failed'}\n${summary.resultSummary}`;
2862
+ task.resultSummaryStartsMidWord =
2863
+ result.ok && !wasStopped ? summary.resultSummaryStartsMidWord : undefined;
2857
2864
  task.account = accountForRun({
2858
2865
  ok: result.ok,
2859
2866
  stopped: wasStopped,
@@ -3453,14 +3460,7 @@ function firstErrorLine(resultSummary) {
3453
3460
  }
3454
3461
  function asPromptTask(task) {
3455
3462
  return {
3456
- id: task.id,
3457
- title: task.title,
3458
- status: task.rejected ? 'rejected by user' : task.status,
3459
- progress: task.progress,
3460
- notes: task.notes,
3461
- ...(task.model ? { model: task.model } : {}),
3462
- ...(task.effort ? { effort: task.effort } : {}),
3463
- item: task.item,
3463
+ ...routerPromptTask(task),
3464
3464
  error: task.status === 'failed'
3465
3465
  ? withTimeoutReport(routerTaskError(firstErrorLine(task.resultSummary), task.failure, task.errorCopy), task)
3466
3466
  : undefined,
package/dist/api.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare function runBrowserJob(contentGrant: string, operation: BrowserOp
50
50
  export declare function startCLILogin(): Promise<{
51
51
  pollToken: string;
52
52
  url: string;
53
+ verifier: string;
53
54
  }>;
54
55
  export interface MeResult {
55
56
  userId: string;
@@ -57,7 +58,7 @@ export interface MeResult {
57
58
  token: string;
58
59
  isAnonymous: boolean;
59
60
  }
60
- export declare function pollForCLILogin(pollToken: string): Promise<MeResult | null>;
61
+ export declare function pollForCLILogin(pollToken: string, verifier: string): Promise<MeResult | null>;
61
62
  export interface MeProfile {
62
63
  userId: string;
63
64
  username: string;
@@ -185,14 +186,39 @@ export interface CauldronServerConfig {
185
186
  timeSensitive?: boolean;
186
187
  }>;
187
188
  };
189
+ /** castle.json `hub`, reduced to what ghost pins: titles and result shapes. */
190
+ hub?: {
191
+ title?: unknown;
192
+ result?: unknown;
193
+ places?: Record<string, {
194
+ title?: unknown;
195
+ result?: unknown;
196
+ }>;
197
+ };
188
198
  }
189
199
  export interface CauldronServerBundleResult {
190
200
  deckId: string;
191
201
  version: string;
192
202
  sha256: string;
193
203
  sizeBytes: number;
204
+ /** The content pack this release pairs with the bundle, when one was sent. */
205
+ contentPackSha256?: string | null;
194
206
  }
195
- export declare function saveCauldronServerBundle(deckId: string, uploadId: string | null, serverConfig?: CauldronServerConfig): Promise<CauldronServerBundleResult | null>;
207
+ export declare function saveCauldronServerBundle(deckId: string, uploadId: string | null, serverConfig?: CauldronServerConfig, contentPackUploadId?: string): Promise<CauldronServerBundleResult | null>;
208
+ /**
209
+ * A presigned upload for a content pack, or null when this Ghost does not host
210
+ * packs yet (the field is not in its schema). Anything else is thrown.
211
+ */
212
+ export declare function createCauldronContentPackUploadConfig(deckId: string): Promise<CauldronServerBundleUploadConfig | null>;
213
+ /**
214
+ * Sets, or with null clears, the A/B experiments a deck runs (castle.json
215
+ * `experiments`, already validated). Returns false when this Ghost predates
216
+ * experiments (the field is not in its schema) and so stored nothing; anything
217
+ * else is thrown.
218
+ */
219
+ export declare function setCauldronDeckExperiments(deckId: string, experiments: Record<string, unknown> | null, options?: {
220
+ signal?: AbortSignal;
221
+ }): Promise<boolean>;
196
222
  export interface WebDeckSource {
197
223
  deckId: string;
198
224
  archiveUrl: string;
package/dist/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as config from './config.js';
2
+ import { createHash, randomBytes } from 'node:crypto';
2
3
  // CASTLE_API_URL reroutes API traffic to a local forwarding proxy inside Castle cloud
3
4
  // sandboxes (which also set CASTLE_TOKEN to a sandbox-scoped credential). Unset anywhere
4
5
  // else, so normal installs always talk to the real API.
@@ -76,16 +77,21 @@ function pickData(data, key) {
76
77
  return (data.data?.[key] ?? null);
77
78
  }
78
79
  export async function startCLILogin() {
79
- const data = await graphql(`mutation { startCLILogin { pollToken url } }`);
80
+ const verifier = randomBytes(32).toString('base64url');
81
+ const challenge = createHash('sha256').update(verifier, 'ascii').digest('base64url');
82
+ const data = await graphql(`mutation($challenge: String!) {
83
+ startCLILogin(challenge: $challenge) { pollToken url }
84
+ }`, { challenge });
80
85
  handleAPIError(data);
81
- return pickData(data, 'startCLILogin');
86
+ const login = pickData(data, 'startCLILogin');
87
+ return { pollToken: login.pollToken, url: login.url, verifier };
82
88
  }
83
- export async function pollForCLILogin(pollToken) {
84
- const data = await graphql(`query($pollToken: String!) {
85
- pollForCLILogin(pollToken: $pollToken) {
89
+ export async function pollForCLILogin(pollToken, verifier) {
90
+ const data = await graphql(`query($pollToken: String!, $verifier: String!) {
91
+ pollForCLILogin(pollToken: $pollToken, verifier: $verifier) {
86
92
  userId username token isAnonymous
87
93
  }
88
- }`, { pollToken });
94
+ }`, { pollToken, verifier });
89
95
  handleAPIError(data);
90
96
  return pickData(data, 'pollForCLILogin');
91
97
  }
@@ -197,6 +203,11 @@ export async function webDeckSourceVersions(deckIds) {
197
203
  export async function deckRows(deckIds) {
198
204
  return aliasedDeckQuery(deckIds, (id) => `deck(deckId: "${id}") { ${DECK_ROW_FIELDS} }`);
199
205
  }
206
+ // Ghost reads the uploaded scene, compares it with the saved one and stores it before it
207
+ // answers, which scales with the bundle: a 20-40 MB scene has taken 10-40 s. Under the
208
+ // default 10 s the save was reported failed after Ghost had published it, and the source
209
+ // that belongs with it was never uploaded. Matches save-deck's large upload timeout.
210
+ const PUBLISH_API_TIMEOUT_MS = 300_000;
200
211
  export async function updateCardAndDeckV2(deck, card, characterBundle) {
201
212
  // Old Ghost versions do not know the characterBundle argument. Keep the exact
202
213
  // pre-feature mutation for ordinary decks; only a deck that explicitly owns the
@@ -214,7 +225,7 @@ export async function updateCardAndDeckV2(deck, card, characterBundle) {
214
225
  deck { deckId }
215
226
  card { cardId }
216
227
  }
217
- }`, publishesCharacters ? { deck, card, characterBundle } : { deck, card });
228
+ }`, publishesCharacters ? { deck, card, characterBundle } : { deck, card }, { timeoutMs: PUBLISH_API_TIMEOUT_MS });
218
229
  handleAPIError(data);
219
230
  const result = data.data?.updateCardAndDeckV2;
220
231
  return { deckId: result.deck.deckId, cardId: result.card.cardId };
@@ -279,18 +290,65 @@ export async function createCauldronServerBundleUploadConfig(deckId) {
279
290
  handleAPIError(data);
280
291
  return pickData(data, 'createCauldronServerBundleUploadConfig');
281
292
  }
282
- export async function saveCauldronServerBundle(deckId, uploadId, serverConfig) {
283
- const data = await graphql(`mutation($deckId: ID!, $uploadId: String, $config: Json) {
284
- saveCauldronServerBundle(deckId: $deckId, uploadId: $uploadId, config: $config) {
285
- deckId
286
- version
287
- sha256
288
- sizeBytes
289
- }
290
- }`, { deckId, uploadId, ...(serverConfig ? { config: serverConfig } : {}) });
293
+ export async function saveCauldronServerBundle(deckId, uploadId, serverConfig, contentPackUploadId) {
294
+ // The pack rides the server bundle's own write, so the two are one release
295
+ // (contentPack.ts). Sent only with a pack: a Ghost that predates the argument
296
+ // refuses a document naming it.
297
+ const data = contentPackUploadId
298
+ ? await graphql(`mutation($deckId: ID!, $uploadId: String, $config: Json, $contentPackUploadId: String) {
299
+ saveCauldronServerBundle(deckId: $deckId, uploadId: $uploadId, config: $config, contentPackUploadId: $contentPackUploadId) {
300
+ deckId
301
+ version
302
+ sha256
303
+ sizeBytes
304
+ contentPackSha256
305
+ }
306
+ }`, { deckId, uploadId, contentPackUploadId, ...(serverConfig ? { config: serverConfig } : {}) })
307
+ : await graphql(`mutation($deckId: ID!, $uploadId: String, $config: Json) {
308
+ saveCauldronServerBundle(deckId: $deckId, uploadId: $uploadId, config: $config) {
309
+ deckId
310
+ version
311
+ sha256
312
+ sizeBytes
313
+ }
314
+ }`, { deckId, uploadId, ...(serverConfig ? { config: serverConfig } : {}) });
291
315
  handleAPIError(data);
292
316
  return pickData(data, 'saveCauldronServerBundle');
293
317
  }
318
+ /**
319
+ * A presigned upload for a content pack, or null when this Ghost does not host
320
+ * packs yet (the field is not in its schema). Anything else is thrown.
321
+ */
322
+ export async function createCauldronContentPackUploadConfig(deckId) {
323
+ const data = await graphql(`mutation($deckId: ID!) {
324
+ createCauldronContentPackUploadConfig(deckId: $deckId) {
325
+ deckId uploadId postUrl postFields
326
+ }
327
+ }`, { deckId });
328
+ const first = data?.errors?.[0];
329
+ if (first && /Cannot query field "createCauldronContentPackUploadConfig"/.test(first.message ?? '')) {
330
+ return null;
331
+ }
332
+ handleAPIError(data);
333
+ return pickData(data, 'createCauldronContentPackUploadConfig');
334
+ }
335
+ /**
336
+ * Sets, or with null clears, the A/B experiments a deck runs (castle.json
337
+ * `experiments`, already validated). Returns false when this Ghost predates
338
+ * experiments (the field is not in its schema) and so stored nothing; anything
339
+ * else is thrown.
340
+ */
341
+ export async function setCauldronDeckExperiments(deckId, experiments, options = {}) {
342
+ const data = await graphql(`mutation($deckId: ID!, $experiments: Json) {
343
+ setCauldronDeckExperiments(deckId: $deckId, experiments: $experiments)
344
+ }`, { deckId, experiments }, options);
345
+ const first = data?.errors?.[0];
346
+ if (first && /Cannot query field "setCauldronDeckExperiments"/.test(first.message ?? '')) {
347
+ return false;
348
+ }
349
+ handleAPIError(data);
350
+ return true;
351
+ }
294
352
  // Metadata for naming an import and distinguishing classic decks. Readable
295
353
  // without auth for the same decks webDeckSource is, including unlisted ones.
296
354
  export async function deckMeta(deckId) {
@@ -20,6 +20,7 @@ export interface HostContext {
20
20
  routeId?: string | null;
21
21
  slot?: string | null;
22
22
  } | null;
23
+ experimentVariants?: Record<string, string> | null;
23
24
  }
24
25
 
25
26
  export interface GraphqlError {
@@ -62,6 +63,7 @@ export interface HostCapabilities {
62
63
  ctx: HostContext,
63
64
  signal?: AbortSignal,
64
65
  ) => Promise<MultiplayerJoinDestinationResult>;
66
+ hub?: HostHub;
65
67
  }
66
68
 
67
69
  export type OracleStream = (url: string, body: string, sink: OracleStreamSink) => () => void;
@@ -134,6 +136,95 @@ export function acquireCauldronMultiplayerDestination(
134
136
  expectedConfigRevision: string,
135
137
  ): Promise<MultiplayerJoinDestinationResult>;
136
138
 
139
+ export type HubHandoffStatus =
140
+ | 'ok'
141
+ | 'cancelled'
142
+ | 'full'
143
+ | 'unavailable'
144
+ | 'not_found'
145
+ | 'forbidden'
146
+ | 'party_required';
147
+
148
+ export type HubHandoffResult =
149
+ | { status: 'ok'; url: string; nonce: string; sessionId: string; bundleHash: string; contentUrl: string | null }
150
+ | {
151
+ status: Exclude<HubHandoffStatus, 'ok'>;
152
+ url: null;
153
+ nonce: null;
154
+ sessionId: null;
155
+ bundleHash: null;
156
+ contentUrl: null;
157
+ };
158
+
159
+ export interface HubDoor {
160
+ doorId: string;
161
+ launcherKind: string;
162
+ placementKind: 'layer' | 'pad' | 'exact';
163
+ placement: unknown;
164
+ padSize: number | null;
165
+ enabled: boolean;
166
+ featured: boolean;
167
+ status: { playersInside: number; friendsInside: number };
168
+ }
169
+
170
+ export type HubDoorsResult =
171
+ | { status: 'ok'; doors: HubDoor[] }
172
+ | { status: 'unavailable'; doors: null };
173
+
174
+ export interface HubFriend {
175
+ userId: string;
176
+ username: string | null;
177
+ here: boolean;
178
+ }
179
+
180
+ export type HubFriendsResult =
181
+ | { status: 'ok'; friends: HubFriend[] }
182
+ | { status: 'unavailable'; friends: null };
183
+
184
+ export interface HubReportResult {
185
+ status: 'ok' | 'unavailable';
186
+ }
187
+
188
+ export interface HubChatMessage {
189
+ id: string;
190
+ fromUserId: string;
191
+ fromUsername: string | null;
192
+ text: string;
193
+ at: string;
194
+ }
195
+
196
+ export type HubChatResult =
197
+ | { status: 'ok'; canChat: boolean; peers: string[]; messages: HubChatMessage[]; cursor: string | null }
198
+ | { status: 'unavailable'; canChat: false; peers: null; messages: null; cursor: null };
199
+
200
+ export interface HubSayResult {
201
+ status: 'sent' | 'none' | 'refused' | 'limited' | 'unavailable';
202
+ id: string | null;
203
+ }
204
+
205
+ export interface HubCommitResult {
206
+ status: 'committed' | 'expired' | 'superseded' | 'cancelled' | 'none' | 'unavailable';
207
+ }
208
+
209
+ export interface HubCancelResult {
210
+ status: 'cancelled' | 'expired' | 'none' | 'unavailable';
211
+ }
212
+
213
+ export interface HostHub {
214
+ go(doorId: string, ctx: HostContext, signal?: AbortSignal): Promise<HubHandoffResult>;
215
+ back(ctx: HostContext, signal?: AbortSignal): Promise<HubHandoffResult>;
216
+ doors(ctx: HostContext): Promise<HubDoorsResult>;
217
+ friends?(ctx: HostContext): Promise<HubFriendsResult>;
218
+ jump?(userId: string, ctx: HostContext, signal?: AbortSignal): Promise<HubHandoffResult>;
219
+ report?(userId: string, reason: string | null, ctx: HostContext): Promise<HubReportResult>;
220
+ chat?(after: string | null, ctx: HostContext): Promise<HubChatResult>;
221
+ say?(text: string, ctx: HostContext): Promise<HubSayResult>;
222
+ reportChat?(messageId: string, ctx: HostContext): Promise<HubReportResult>;
223
+ commit(sessionId: string, ctx: HostContext): Promise<HubCommitResult>;
224
+ cancel(sessionId: string | null, ctx: HostContext): Promise<HubCancelResult>;
225
+ sessionAcquired?(sessionId: string, ctx: HostContext): void;
226
+ }
227
+
137
228
  export interface LeaderboardStreakCredit {
138
229
  deckId: string | null;
139
230
  kind: string;