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
@@ -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;
@@ -31,6 +32,7 @@ export interface PromptSibling {
31
32
  }
32
33
  export interface RouterPlanOpts {
33
34
  fileText?: string;
35
+ settledItems?: string[];
34
36
  pendingDurables?: PlanNomination[];
35
37
  finishedWork?: PlanFinishedWork[];
36
38
  notices?: string[];
@@ -62,6 +64,13 @@ export declare const STEER_MODEL_CLAUSE = ", as a new task even when it changes
62
64
  export declare const SEND_FENCE_RULES = "\n\nTo hand a message to a task that is running or waiting to run:\n\n```castle-send\nthe task's title or id, alone on the first line\nthe user's message for it -- their own words, quoted, plus only what from this conversation the task needs to act on them\n```\n\n- `castle-send` reaches a RUNNING or WAITING task: it reads the message at its next step and folds it into the work it is doing, without starting over. One fence per task. It is the ONLY thing that reaches a running task -- a reply that says a task will pick something up, without this fence, sends nothing. The board row shows each message you sent and whether the task has read it.\n- It cannot reach a finished task. For those, spawn a new task (see the one-and-done rule below).";
63
65
  export declare const PROBE_CLAUSE_STEER = "But NEVER spawn work a pending probe could invalidate outright: castle-send can pass the answer to a running task, but it cannot undo work the answer throws away.";
64
66
  export declare function truncateToBytes(line: string, budget: number): string;
67
+ export declare const PLAN_SECTION_CAPS: Record<string, number>;
68
+ export declare const PLAN_DIGEST_BYTE_BUDGET: number;
69
+ export declare const BUILT_MAX_LINES = 15;
70
+ export declare const BUILT_WHAT_TARGET_CHARS = 150;
71
+ export declare const TASK_PLAN_SLICE_BYTE_BUDGET: number;
72
+ export declare const DECISIONS_PINNED = 10;
73
+ export declare const DECISIONS_RETRIEVED = 6;
65
74
  export type PlanOpVerb = "decide" | "open" | "tried" | "now" | "identity";
66
75
  export interface PlanOpSource {
67
76
  kind: "user" | "task";
@@ -91,9 +100,8 @@ export interface PlanOpsApplied {
91
100
  notices: string[];
92
101
  }
93
102
  export declare function applyPlanOps(fileText: string, ops: PlanOp[], sources?: PlanOpSources): PlanOpsApplied;
94
- export declare function renderPlanDigest(plan: RouterPlanOpts, tasks: PromptTask[]): string;
95
- export declare function planOpenQuestionLines(fileText: string): string[];
96
- export declare function renderTaskPlanSlice(fileText: string, item: string | undefined, finishedWork?: PlanFinishedWork[]): string;
103
+ export declare function renderPlanDigest(plan: RouterPlanOpts, tasks: PromptTask[], query?: string): string;
104
+ export declare function renderTaskPlanSlice(fileText: string, item: string | undefined, finishedWork?: PlanFinishedWork[], query?: string): string;
97
105
  export type FreeModelCheck = (model: string) => boolean;
98
106
  export declare function modelLabel(model: string, isFreeModel: FreeModelCheck): string;
99
107
  export declare const NO_DECK_DOCS = "This deck has no CLAUDE.md / AGENTS.md quick reference. There is no documentation to read -- do not search for one (CLAUDE.md, README, **/*.md, etc.).";
@@ -257,17 +257,21 @@ function renderTranscript(messages) {
257
257
  // runaway section is trimmed here instead, and can never crowd the rest of the
258
258
  // plan out of the digest. Key is the lowercased heading; "" is the title +
259
259
  // pitch ahead of the first heading, which only the user writes.
260
- const PLAN_SECTION_CAPS = {
260
+ export const PLAN_SECTION_CAPS = {
261
261
  "": 2,
262
262
  "what this game is": 6,
263
- decisions: 12,
264
- "open questions": 7,
263
+ decisions: 16,
264
+ "open questions": 3,
265
265
  now: 10,
266
266
  tried: 8,
267
267
  };
268
268
  const PLAN_SECTION_DEFAULT_CAP = 8;
269
- const PLAN_DIGEST_BYTE_BUDGET = 3 * 1024;
270
- const BUILT_MAX_LINES = 15;
269
+ export const PLAN_DIGEST_BYTE_BUDGET = 4 * 1024;
270
+ export const BUILT_MAX_LINES = 15;
271
+ export const BUILT_WHAT_TARGET_CHARS = 150;
272
+ export const TASK_PLAN_SLICE_BYTE_BUDGET = 6 * 1024;
273
+ export const DECISIONS_PINNED = 10;
274
+ export const DECISIONS_RETRIEVED = 6;
271
275
  // plan.md's sections in the order they are written and rendered, with the
272
276
  // heading each is created as. `built` is listed for its POSITION only: it is
273
277
  // derived into the digest from finished tasks (see deriveBuiltLines) and is
@@ -683,6 +687,54 @@ function trimSection(section) {
683
687
  function planItemLabel(line) {
684
688
  return /^[-*]\s*([^\s:]+)\s*:/.exec(line)?.[1];
685
689
  }
690
+ const DECISION_STOP_WORDS = new Set("the a an and or but if then than that this these those there here with without into onto from for to of in on at by as is are was were be been being it its it's i you we they he she them him her my your our their me us do does did done have has had having not no yes so just like get got make made makes making want wants wanted need needs should would could can cant can't will wont won't dont don't doesnt doesn't didnt didn't isnt isn't arent aren't im i'm ive i've lets let's ok okay yeah yep nah also too very really still now when where what which who how why all any some more most much many few each every other another same different new old first last next back up down out over under again once only ever never always also thing things something anything nothing everything way ways kind sort bit lot little big small good bad great nice fine right wrong sure maybe actually probably think thought feel feels felt look looks looked looking see seen show shows keep keeps kept go goes going went come comes came put take takes took use used using work works worked working try tries tried trying add adds added adding change changes changed changing fix fixes fixed fixing remove removed set sets user task game play player players screen currently current one two three".split(" "));
691
+ function planContentTokens(text) {
692
+ const unattributed = text.toLowerCase()
693
+ .replace(/\(".*?"\s*--\s*(?:user|task\s+\S+)\)/g, "")
694
+ .replace(/--\s*(?:user|task\s+\S+)/g, "");
695
+ const tokens = new Set();
696
+ for (const raw of unattributed.match(/[a-z][a-z']+/g) ?? []) {
697
+ let word = raw.replace(/^'+|'+$/g, "");
698
+ if (word.length < 4 || DECISION_STOP_WORDS.has(word))
699
+ continue;
700
+ for (const suffix of ["ing", "ers", "er", "es", "ed", "s", "ly"]) {
701
+ if (word.endsWith(suffix) && word.length - suffix.length >= 4) {
702
+ word = word.slice(0, -suffix.length);
703
+ break;
704
+ }
705
+ }
706
+ tokens.add(word);
707
+ }
708
+ return tokens;
709
+ }
710
+ function selectDecisionLines(section, built, query) {
711
+ const lines = section.lines.map((line) => line.trim()).filter(Boolean);
712
+ if (lines.length <= PLAN_SECTION_CAPS.decisions)
713
+ return { lines, trimmed: false };
714
+ const pinned = lines.slice(0, DECISIONS_PINNED);
715
+ const shownBuilt = new Set(built.map(planItemLabel).filter(Boolean));
716
+ const queryTokens = planContentTokens(query);
717
+ const candidates = lines.slice(DECISIONS_PINNED).map((line, index) => {
718
+ const shared = [...planContentTokens(line)].filter((token) => queryTokens.has(token)).length;
719
+ const labelTokens = planContentTokens((planItemLabel(line) ?? "").replace(/-/g, " "));
720
+ const labelMatch = labelTokens.size > 0 && [...labelTokens].every((token) => queryTokens.has(token));
721
+ return { line, index, score: shared + (labelMatch ? 1 : 0), qualifies: shared >= 2 || labelMatch };
722
+ }).filter((candidate) => !shownBuilt.has(planItemLabel(candidate.line)));
723
+ const ranked = candidates.filter((candidate) => candidate.qualifies)
724
+ .sort((a, b) => b.score - a.score || b.index - a.index);
725
+ const selected = ranked.slice(0, DECISIONS_RETRIEVED);
726
+ const selectedIndexes = new Set(selected.map((candidate) => candidate.index));
727
+ for (const candidate of [...candidates].reverse()) {
728
+ if (selected.length >= DECISIONS_RETRIEVED)
729
+ break;
730
+ if (selectedIndexes.has(candidate.index))
731
+ continue;
732
+ selected.push(candidate);
733
+ selectedIndexes.add(candidate.index);
734
+ }
735
+ const retrieved = selected.sort((a, b) => a.index - b.index).map((candidate) => candidate.line);
736
+ return { lines: [...pinned, ...retrieved], trimmed: pinned.length + retrieved.length < lines.length };
737
+ }
686
738
  // The machine half of the digest: which board rows belong to this plan item.
687
739
  // It is joined in here, never written into plan.md -- the file stays prose with
688
740
  // two human writers, and everything the runtime knows rides in the render.
@@ -729,6 +781,10 @@ function trimVictim(sections) {
729
781
  longestOf((s) => s.key !== "built") ??
730
782
  longestOf(() => true));
731
783
  }
784
+ function routerBuiltLine(work) {
785
+ const knobs = work.knobs?.length ? ` (knobs: ${work.knobs.join(", ")})` : "";
786
+ return `- ${work.item}: ${work.what}${knobs}`;
787
+ }
732
788
  function builtLine(work) {
733
789
  const files = work.files?.length ? ` (files: ${work.files.join(", ")})` : "";
734
790
  const knobs = work.knobs?.length ? ` (knobs: ${work.knobs.join(", ")})` : "";
@@ -738,7 +794,7 @@ function builtLine(work) {
738
794
  // first. Latest-wins per item rather than a log -- the section answers "what
739
795
  // exists now", and a per-task history would grow with every task the deck ever
740
796
  // ran. What is evicted is still on disk in the task handoffs.
741
- function deriveBuiltLines(finished) {
797
+ function deriveBuiltLines(finished, renderLine = builtLine) {
742
798
  const latest = new Map();
743
799
  for (const work of finished) {
744
800
  if (!work.item.trim() || work.item === "-" || !work.what.trim())
@@ -748,17 +804,43 @@ function deriveBuiltLines(finished) {
748
804
  latest.set(work.item, work);
749
805
  }
750
806
  const newestFirst = [...latest.values()].sort((a, b) => (b.at ?? "").localeCompare(a.at ?? ""));
751
- const lines = newestFirst.slice(0, BUILT_MAX_LINES).map(builtLine);
807
+ const lines = newestFirst.slice(0, BUILT_MAX_LINES).map(renderLine);
752
808
  const dropped = newestFirst.length - lines.length;
753
809
  if (dropped > 0)
754
810
  lines.push(`(${dropped} more in the archive)`);
755
811
  return lines;
756
812
  }
757
- function fitPlanSections(plan, tasks) {
813
+ const NO_PLAN_PREFIX = "(no plan.md yet)\n\n";
814
+ function fitPlanSections(plan, tasks, query) {
758
815
  const sections = [];
759
- for (const section of parsePlanSections(plan.fileText ?? "")) {
760
- const { lines, trimmed } = trimSection(section);
761
- if (lines.length === 0 && !section.heading)
816
+ const built = deriveBuiltLines(plan.finishedWork ?? [], routerBuiltLine);
817
+ const settled = new Set(plan.settledItems ?? []);
818
+ const source = parsePlanSections(plan.fileText ?? "");
819
+ const decided = new Set(source
820
+ .filter((section) => section.key === "decisions" || section.key === "tried")
821
+ .flatMap((section) => section.lines.map((line) => planItemLabel(line.trim())))
822
+ .filter((label) => Boolean(label)));
823
+ for (const section of source) {
824
+ const visible = section.key === "now"
825
+ ? {
826
+ ...section,
827
+ lines: section.lines
828
+ .filter((line) => !settled.has(planItemLabel(line.trim()) ?? ""))
829
+ .reverse(),
830
+ }
831
+ : section.key === "open questions"
832
+ ? {
833
+ ...section,
834
+ lines: section.lines
835
+ .filter((line) => line.includes("(proposed -- confirm?)") ||
836
+ !decided.has(planItemLabel(line.trim()) ?? ""))
837
+ .reverse(),
838
+ }
839
+ : section;
840
+ const { lines, trimmed } = section.key === "decisions"
841
+ ? selectDecisionLines(section, built, query)
842
+ : trimSection(visible);
843
+ if (lines.length === 0)
762
844
  continue;
763
845
  sections.push({
764
846
  heading: section.heading,
@@ -769,7 +851,6 @@ function fitPlanSections(plan, tasks) {
769
851
  trimmed,
770
852
  });
771
853
  }
772
- const built = deriveBuiltLines(plan.finishedWork ?? []);
773
854
  if (built.length > 0) {
774
855
  insertByOrder(sections, {
775
856
  heading: "## Built",
@@ -778,25 +859,50 @@ function fitPlanSections(plan, tasks) {
778
859
  trimmed: false,
779
860
  });
780
861
  }
862
+ const reserved = plan.fileText?.trim() ? 0 : Buffer.byteLength(NO_PLAN_PREFIX, "utf8");
863
+ return fitSectionsToBytes(sections, PLAN_DIGEST_BYTE_BUDGET - reserved);
864
+ }
865
+ function fitSectionsToBytes(sections, budget) {
781
866
  const render = () => sections
782
867
  .map((s) => [s.heading, ...s.lines, s.trimmed ? "(trimmed)" : ""]
783
868
  .filter(Boolean)
784
869
  .join("\n"))
785
870
  .join("\n\n");
786
- while (Buffer.byteLength(render(), "utf8") > PLAN_DIGEST_BYTE_BUDGET) {
871
+ while (Buffer.byteLength(render(), "utf8") > budget) {
787
872
  const victim = trimVictim(sections);
788
873
  if (!victim)
789
874
  break;
790
875
  victim.lines.pop();
791
876
  victim.trimmed = true;
792
877
  }
793
- // Backstop for a plan whose remaining one-line-per-section still overruns
794
- // (pathological line lengths); the 8KB file cap upstream keeps it rare.
795
- const rendered = render();
796
- if (Buffer.byteLength(rendered, "utf8") <= PLAN_DIGEST_BYTE_BUDGET) {
797
- return rendered;
878
+ // Every section is down to a line and the render still overruns: one line
879
+ // is pathologically long. Shorten THAT line rather than cutting the render's
880
+ // tail, which is where Built and a task's own item line sit.
881
+ const ellipsis = " ...";
882
+ const ellipsisBytes = Buffer.byteLength(ellipsis, "utf8");
883
+ const lineFloor = 16;
884
+ const bodyOf = (line) => line.endsWith(ellipsis) ? line.slice(0, -ellipsis.length) : line;
885
+ for (;;) {
886
+ const over = Buffer.byteLength(render(), "utf8") - budget;
887
+ if (over <= 0)
888
+ return render();
889
+ let longest;
890
+ for (const section of sections) {
891
+ section.lines.forEach((line, at) => {
892
+ const bytes = Buffer.byteLength(bodyOf(line), "utf8");
893
+ if (bytes > lineFloor && (!longest || bytes > longest.bytes))
894
+ longest = { section, at, bytes };
895
+ });
896
+ }
897
+ if (!longest)
898
+ break;
899
+ const keep = Math.max(lineFloor, longest.bytes - over - ellipsisBytes);
900
+ const body = bodyOf(longest.section.lines[longest.at]);
901
+ longest.section.lines[longest.at] = `${truncateToBytes(body, keep).trimEnd()}${ellipsis}`;
902
+ longest.section.trimmed = true;
798
903
  }
799
- return `${truncateToBytes(rendered, PLAN_DIGEST_BYTE_BUDGET).trimEnd()}\n(trimmed)`;
904
+ const marker = "\n(trimmed)";
905
+ return `${truncateToBytes(render(), budget - Buffer.byteLength(marker, "utf8")).trimEnd()}${marker}`;
800
906
  }
801
907
  // The plan as the router sees it: the file (capped, with board status joined
802
908
  // onto its items and `## Built` derived in) plus the nominations waiting on its
@@ -806,15 +912,15 @@ function fitPlanSections(plan, tasks) {
806
912
  // it. They are small and bounded, and they are the input to promotion -- a
807
913
  // long plan crowding them out would silently stop promotion working at exactly
808
914
  // the point a deck most needs it.
809
- export function renderPlanDigest(plan, tasks) {
810
- const fitted = fitPlanSections(plan, tasks);
915
+ export function renderPlanDigest(plan, tasks, query = "") {
916
+ const fitted = fitPlanSections(plan, tasks, query);
811
917
  // A deck can have finished work before it has a plan.md -- what exists is
812
918
  // still worth showing, and saying the file is missing is what gets one
813
919
  // drafted.
814
920
  const parts = [
815
921
  plan.fileText?.trim()
816
922
  ? fitted
817
- : ["(no plan.md yet)", fitted].filter(Boolean).join("\n\n"),
923
+ : fitted ? `${NO_PLAN_PREFIX}${fitted}` : NO_PLAN_PREFIX.trimEnd(),
818
924
  ];
819
925
  const nominations = plan.pendingDurables ?? [];
820
926
  if (nominations.length > 0) {
@@ -830,47 +936,36 @@ export function renderPlanDigest(plan, tasks) {
830
936
  }
831
937
  return parts.join("\n\n");
832
938
  }
833
- export function planOpenQuestionLines(fileText) {
834
- const section = parsePlanSections(fileText).find((s) => s.key === "open questions");
835
- return (section?.lines ?? []).map((l) => l.trim()).filter(Boolean);
836
- }
837
939
  // The slice one task agent gets: the constraints and the don't-rebuilds, plus
838
940
  // the single item line its own work belongs to. See TASK_PLAN_SECTIONS for what
839
941
  // is deliberately left out.
840
- export function renderTaskPlanSlice(fileText, item, finishedWork) {
841
- const sections = parsePlanSections(fileText);
842
- const parts = [];
843
- // Only this item's own Built line: what already exists where this task is
844
- // about to work, so it extends rather than rebuilds. Other items' work is
845
- // not its business.
942
+ export function renderTaskPlanSlice(fileText, item, finishedWork, query = "") {
943
+ const source = parsePlanSections(fileText);
944
+ const sections = [];
846
945
  const built = deriveBuiltLines((finishedWork ?? []).filter((w) => item && w.item === item));
847
- let builtDone = built.length === 0;
848
- const pushBuilt = () => {
849
- if (builtDone)
850
- return;
851
- parts.push(["## Built", ...built].join("\n"));
852
- builtDone = true;
853
- };
854
- for (const section of sections) {
946
+ for (const section of source) {
855
947
  if (section.key !== "" && !TASK_PLAN_SECTIONS.has(section.key))
856
948
  continue;
857
- const { lines } = trimSection(section);
949
+ const { lines, trimmed } = section.key === "decisions"
950
+ ? selectDecisionLines(section, built, query)
951
+ : trimSection(section);
858
952
  if (lines.length === 0)
859
953
  continue;
860
- if (sectionRank(section.key) > sectionRank("built"))
861
- pushBuilt();
862
- parts.push([section.heading, ...lines].filter(Boolean).join("\n"));
954
+ sections.push({ heading: section.heading, key: section.key, lines, trimmed });
955
+ }
956
+ if (built.length > 0) {
957
+ insertByOrder(sections, { heading: "## Built", key: "built", lines: built, trimmed: false });
863
958
  }
864
- pushBuilt();
865
959
  const itemLine = item
866
- ? sections
960
+ ? source
867
961
  .find((s) => s.key === "now")
868
962
  ?.lines.map((l) => l.trim())
869
963
  .find((l) => planItemLabel(l) === item)
870
964
  : undefined;
871
- if (itemLine)
872
- parts.push(`The plan item your task belongs to:\n${itemLine}`);
873
- return parts.join("\n\n");
965
+ if (itemLine) {
966
+ sections.push({ heading: "The plan item your task belongs to:", key: "now", lines: [itemLine], trimmed: false });
967
+ }
968
+ return fitSectionsToBytes(sections, TASK_PLAN_SLICE_BYTE_BUDGET);
874
969
  }
875
970
  // `showItems` is the plan opt's presence, not the row's. A deck that ran with
876
971
  // the plan doc on and then switched it off still has item labels on its old
@@ -903,13 +998,14 @@ function renderTasks(tasks, showItems, isFreeModel) {
903
998
  ? ` -- model: ${[t.model && modelLabel(t.model, isFreeModel), t.effort].filter(Boolean).join(" ")}`
904
999
  : "";
905
1000
  const notes = t.notes.trim() ? ` -- notes: ${t.notes.trim()}` : "";
1001
+ const report = t.report ? ` -- report: ${t.report}` : "";
906
1002
  const error = t.error ? ` -- error: ${t.error}` : "";
907
1003
  const interrupted = t.interrupted ? ` -- interrupted: ${t.interrupted}` : "";
908
1004
  const blockedBy = t.blockedBy && t.blockedBy.length > 0
909
1005
  ? ` -- blocked by: ${t.blockedBy.join(", ")}`
910
1006
  : "";
911
1007
  const sent = t.sent ? ` -- messages you sent it: ${t.sent}` : "";
912
- 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}`;
913
1009
  const held = t.status === "held" && t.heldQuestion !== undefined
914
1010
  ? `\n held -- waiting on the answer to: ${t.heldQuestion}`
915
1011
  : "";
@@ -955,7 +1051,11 @@ export function buildRouterPromptParts(opts) {
955
1051
  // roughly the turns the board does, so co-locating them means it invalidates
956
1052
  // nothing the board wasn't already invalidating.
957
1053
  const plan = opts.plan
958
- ? `\n\n== plan ==\n${renderPlanDigest(opts.plan, opts.tasks)}`
1054
+ ? `\n\n== plan ==\n${renderPlanDigest(opts.plan, opts.tasks, opts.messages
1055
+ .filter((message) => message.role === "user")
1056
+ .slice(-4)
1057
+ .map((message) => message.text)
1058
+ .join("\n"))}`
959
1059
  : "";
960
1060
  // Omitted entirely when nothing was tuned: a quiet turn has to cost 0 bytes,
961
1061
  // and every prompt built before this section existed has to stay
@@ -1086,7 +1186,7 @@ export function buildTaskPrompt(opts) {
1086
1186
  ? `\n\nDeck files (snapshot at task start; parallel sibling tasks may create files named in your prompt that are absent here):\n\n${opts.deckTree.trim()}\n`
1087
1187
  : "";
1088
1188
  const planSliceText = opts.plan
1089
- ? renderTaskPlanSlice(opts.plan.fileText ?? "", opts.plan.item, opts.plan.finishedWork)
1189
+ ? renderTaskPlanSlice(opts.plan.fileText ?? "", opts.plan.item, opts.plan.finishedWork, `${opts.title}\n${opts.prompt}`)
1090
1190
  : "";
1091
1191
  const planSlice = planSliceText.trim()
1092
1192
  ? `\n\nThe deck's plan (from plan.md):\n\n${planSliceText}\n`
@@ -1096,7 +1196,7 @@ export function buildTaskPrompt(opts) {
1096
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."
1097
1197
  : "",
1098
1198
  opts.plan
1099
- ? `\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.`
1100
1200
  : "",
1101
1201
  ].join("");
1102
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,11 +34,12 @@ 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';
40
41
  import { readGitIncomingNote, removeGitIncoming } from './gitIncoming.js';
41
- import { applyPlanOps, buildRouterPromptParts, buildTaskPrompt, parsePlanOps, truncateToBytes, userTurnInstruction, CLAUDE_TASK_SYSTEM_REMINDER, modelTaskAddendum, isMuseModel, } from './agent-prompts.js';
42
+ import { applyPlanOps, buildRouterPromptParts, buildTaskPrompt, parsePlanOps, userTurnInstruction, CLAUDE_TASK_SYSTEM_REMINDER, modelTaskAddendum, isMuseModel, } from './agent-prompts.js';
42
43
  import { readCastleJson } from './castleJson.js';
43
44
  import { checkOpenrouterKey, checkOpenrouterModel, primeOpenrouterCatalog, } from './openrouter-catalog.js';
44
45
  import { classifyProviderError, failureCopy, failureLabel, routerTaskError, setReaderTimeZone, } from './agent-failures.js';
@@ -543,12 +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
- // Byte ceiling on the plan.md injected into router turns and task prompts.
548
- // Nothing bounds the file itself -- ops touch one line each and the user pastes
549
- // what they like -- meanwhile the whole prompt rides inside one argv entry (see
550
- // TRANSCRIPT_BYTE_BUDGET in agent-prompts.ts), so this term needs its own bound.
551
- const PLAN_BYTE_BUDGET = 8 * 1024;
552
547
  const MAX_ATTACHMENTS = 6;
553
548
  // @-mentioned places are references, so the only cost is instruction bytes --
554
549
  // but a client is not the one to decide how many the router is told about.
@@ -664,12 +659,7 @@ function readPlanSnapshot(deckDir) {
664
659
  }
665
660
  if (!raw.trim())
666
661
  return { raw };
667
- if (Buffer.byteLength(raw, 'utf8') <= PLAN_BYTE_BUDGET)
668
- return { raw, text: raw.trim() };
669
- return {
670
- raw,
671
- text: `${truncateToBytes(raw, PLAN_BYTE_BUDGET).trim()}\n\n(trimmed -- plan.md is longer than this. Tell the user it has grown too long; it should stay a short working plan.)`,
672
- };
662
+ return { raw, text: raw.trim() };
673
663
  }
674
664
  // How many op notices ride into the next router turn. More than a handful is a
675
665
  // fence that went wrong wholesale, and the first few say so.
@@ -726,9 +716,7 @@ function planOpSources(taskStore, messages) {
726
716
  const taskReports = new Map();
727
717
  for (const task of taskStore.sorted()) {
728
718
  const row = asPromptTask(task);
729
- const text = [task.durable, row.error, row.interrupted, row.notes]
730
- .filter((s) => s?.trim())
731
- .join('\n');
719
+ const text = quotableTaskText(row, task.durable);
732
720
  if (text)
733
721
  taskReports.set(task.id, text);
734
722
  }
@@ -755,6 +743,7 @@ function routerPlanOpts(deckDir, snapshot, nominations, tasks) {
755
743
  text: t.durable ?? '',
756
744
  })),
757
745
  finishedWork: planFinishedWork(tasks),
746
+ settledItems: planSettledItems(tasks),
758
747
  notices,
759
748
  };
760
749
  }
@@ -2051,7 +2040,9 @@ const TASK_OPTIONAL_STRINGS = [
2051
2040
  ];
2052
2041
  const TASK_OPTIONAL_NUMBERS = ['pid', 'costUsd', 'durationApiMs', 'numTurns', 'resumeCount'];
2053
2042
  const TASK_OPTIONAL_OBJECTS = ['usage', 'modelUsage'];
2054
- const TASK_OPTIONAL_BOOLEANS = ['acknowledged', 'rejected', 'durablePending'];
2043
+ const TASK_OPTIONAL_BOOLEANS = [
2044
+ 'acknowledged', 'rejected', 'durablePending', 'resultSummaryStartsMidWord', 'handoffNoDeckFiles',
2045
+ ];
2055
2046
  const TASK_OPTIONAL_STRING_LISTS = ['playtestFrames', 'files', 'knobs', 'blockedBy'];
2056
2047
  const isStringList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string');
2057
2048
  function isHeldFor(v) {
@@ -2137,22 +2128,21 @@ function loadTasks(tasksDir) {
2137
2128
  }
2138
2129
  return tasks;
2139
2130
  }
2140
- // A handoff line is one fact, and a long one is a summary rather than the
2141
- // single fact the prompt asks for.
2142
- const HANDOFF_MAX_CHARS = 200;
2143
- const HANDOFF_MAX_LIST = 8;
2144
2131
  // One field of the handoff file -- the FIRST line carrying it, since the prompt
2145
2132
  // asks for one of each and a task that wrote several has already missed the
2146
2133
  // point.
2147
- function handoffField(handoff, field) {
2134
+ function rawHandoffField(handoff, field) {
2148
2135
  const match = new RegExp(`^${field}:\\s*(.+)$`, 'i');
2149
2136
  for (const line of handoff.split('\n')) {
2150
2137
  const found = match.exec(line.trim());
2151
2138
  if (found)
2152
- return found[1].trim().slice(0, HANDOFF_MAX_CHARS);
2139
+ return found[1].trim();
2153
2140
  }
2154
2141
  return undefined;
2155
2142
  }
2143
+ function handoffField(handoff, field) {
2144
+ return rawHandoffField(handoff, field)?.slice(0, HANDOFF_MAX_CHARS);
2145
+ }
2156
2146
  function handoffList(handoff, field) {
2157
2147
  const items = (handoffField(handoff, field) ?? '')
2158
2148
  .split(',')
@@ -2173,6 +2163,11 @@ function refreshHandoff(dir, task) {
2173
2163
  return false;
2174
2164
  }
2175
2165
  let changed = false;
2166
+ const handoffNoDeckFiles = noDeckFiles(rawHandoffField(handoff, 'files'));
2167
+ if (handoffNoDeckFiles !== task.handoffNoDeckFiles) {
2168
+ task.handoffNoDeckFiles = handoffNoDeckFiles;
2169
+ changed = true;
2170
+ }
2176
2171
  const durable = handoffField(handoff, 'durable');
2177
2172
  if (durable && durable !== task.durable) {
2178
2173
  task.durable = durable;
@@ -2193,6 +2188,25 @@ function refreshHandoff(dir, task) {
2193
2188
  }
2194
2189
  return changed;
2195
2190
  }
2191
+ // An item is settled when nothing on it is live and the LATEST task spawned for
2192
+ // it finished done: a failed or interrupted follow-up after an earlier success
2193
+ // is work still owed, and hiding the item would hide that.
2194
+ function planSettledItems(tasks) {
2195
+ const latest = new Map();
2196
+ const live = new Set();
2197
+ for (const task of tasks) {
2198
+ if (!task.item || task.item === '-')
2199
+ continue;
2200
+ if (!isTerminal(task.status))
2201
+ live.add(task.item);
2202
+ const prev = latest.get(task.item);
2203
+ if (!prev || task.createdAt >= prev.createdAt)
2204
+ latest.set(task.item, task);
2205
+ }
2206
+ return [...latest.entries()]
2207
+ .filter(([item, task]) => task.status === 'done' && !live.has(item))
2208
+ .map(([item]) => item);
2209
+ }
2196
2210
  // What the plan's derived `## Built` is made of: the work of tasks that
2197
2211
  // actually finished, addressed by the plan item they advanced. A task that
2198
2212
  // belongs to no item, failed, or never wrote a `what:` line has nothing to
@@ -2839,11 +2853,14 @@ function startTask(ctx, task) {
2839
2853
  if (result.ok && !wasStopped)
2840
2854
  task.progress = 100;
2841
2855
  task.finishedAt = nowIso();
2856
+ const summary = summarizeTaskResult(result.finalText);
2842
2857
  task.resultSummary = wasStopped
2843
2858
  ? ROUTER_STOPPED_RESULT
2844
2859
  : result.ok
2845
- ? result.finalText.slice(-RESULT_SUMMARY_CHARS)
2846
- : `${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;
2847
2864
  task.account = accountForRun({
2848
2865
  ok: result.ok,
2849
2866
  stopped: wasStopped,
@@ -3443,14 +3460,7 @@ function firstErrorLine(resultSummary) {
3443
3460
  }
3444
3461
  function asPromptTask(task) {
3445
3462
  return {
3446
- id: task.id,
3447
- title: task.title,
3448
- status: task.rejected ? 'rejected by user' : task.status,
3449
- progress: task.progress,
3450
- notes: task.notes,
3451
- ...(task.model ? { model: task.model } : {}),
3452
- ...(task.effort ? { effort: task.effort } : {}),
3453
- item: task.item,
3463
+ ...routerPromptTask(task),
3454
3464
  error: task.status === 'failed'
3455
3465
  ? withTimeoutReport(routerTaskError(firstErrorLine(task.resultSummary), task.failure, task.errorCopy), task)
3456
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;
@@ -171,16 +172,53 @@ export interface CauldronServerConfig {
171
172
  selection: 'exact' | 'find';
172
173
  persistence: 'transient' | 'world';
173
174
  characters?: 'shared';
175
+ worldTime?: {
176
+ advance: 'wallClock';
177
+ };
174
178
  maxPlayers: number;
175
179
  }>;
180
+ worldNotifications?: {
181
+ version: 1;
182
+ templates: Array<{
183
+ id: string;
184
+ text: string;
185
+ slots: string[];
186
+ timeSensitive?: boolean;
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
+ };
176
198
  }
177
199
  export interface CauldronServerBundleResult {
178
200
  deckId: string;
179
201
  version: string;
180
202
  sha256: string;
181
203
  sizeBytes: number;
204
+ /** The content pack this release pairs with the bundle, when one was sent. */
205
+ contentPackSha256?: string | null;
182
206
  }
183
- 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>;
184
222
  export interface WebDeckSource {
185
223
  deckId: string;
186
224
  archiveUrl: string;
@@ -200,6 +238,13 @@ export interface DeckMeta {
200
238
  }
201
239
  export declare function deckMeta(deckId: string): Promise<DeckMeta | null>;
202
240
  export declare function webDeckSource(deckId: string): Promise<WebDeckSource | null>;
241
+ export interface SavedSourceVersion {
242
+ s3Key: string;
243
+ archiveUrl: string;
244
+ savedAt: string;
245
+ bytes: number;
246
+ }
247
+ export declare function savedSourceHistory(deckId: string, timeoutMs?: number): Promise<SavedSourceVersion[]>;
203
248
  export declare function clearDeckLeaderboards(deckId: string): Promise<void>;
204
249
  export declare function saveWebDeckSource(deckId: string, uploadId: string, expectedS3Key?: string | null): Promise<WebDeckSource>;
205
250
  export type CloudDeckKit = 'PHYSICS_2D' | 'PHYSICS_3D' | 'MULTIPLAYER_2D' | 'MULTIPLAYER_3D' | 'TURN_BASED' | 'NONE';