castle-web-cli 0.4.225 → 0.4.226

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.
@@ -9,6 +9,8 @@ export interface PromptTask {
9
9
  status: string;
10
10
  progress: number;
11
11
  notes: string;
12
+ model?: string;
13
+ effort?: string;
12
14
  item?: string;
13
15
  error?: string;
14
16
  interrupted?: string;
@@ -56,6 +58,7 @@ export declare const PLAYTEST_ON_FENCE_RULE = "- The user turned playtest checks
56
58
  export declare const TASK_FENCE_PROMPT_EXAMPLE = "Then a SHORT self-contained prompt -- one tight paragraph (aim under 100\nwords): what to build or fix and what \"done\" looks like. Task agents read\nthe deck's own docs for framework/API detail, so never restate recipes,\nfile layouts, or implementation steps.";
57
59
  export declare const PLAYTEST_TASK_UNDRIVEN_RULE = "- The playtest tool is a headless preview, not the user's device. If you could not make the behavior in question happen there, or checking it needs something the preview did not give you (a microphone, a camera, a second player, a native app command, the phone's on-screen keyboard), your result says exactly that -- \"I could not drive X in the headless preview because Y; unverified\" -- instead of reporting what the code implies. Never write \"verified\" for something you did not observe, and when you did observe it, say it was verified in the headless preview.";
58
60
  export declare const STOP_RULE_STEER = "- When a new message is about work a task is still running or waiting to run -- it corrects it, adds to it, narrows it, or answers a question you asked about it -- `castle-send` it to that task instead of stopping it: the task keeps what it has done and adjusts. Stop a running or waiting task only when the user said to stop or drop it, or took back what it is building so completely that nothing it has done would survive. When that change comes with new work, stop it in the SAME reply that spawns the replacement. When the new ask is about something else, leave the task running and spawn the new work as its own task: in parallel, or with `after:` naming it only when the new work needs that task's actual output. Never stop a task because a new one restates it or covers it more broadly.";
61
+ export declare const STEER_MODEL_CLAUSE = ", as a new task even when it changes a running one: a castle-send keeps that task's model.";
59
62
  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).";
60
63
  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.";
61
64
  export declare function truncateToBytes(line: string, budget: number): string;
@@ -91,6 +94,8 @@ export declare function applyPlanOps(fileText: string, ops: PlanOp[], sources?:
91
94
  export declare function renderPlanDigest(plan: RouterPlanOpts, tasks: PromptTask[]): string;
92
95
  export declare function planOpenQuestionLines(fileText: string): string[];
93
96
  export declare function renderTaskPlanSlice(fileText: string, item: string | undefined, finishedWork?: PlanFinishedWork[]): string;
97
+ export type FreeModelCheck = (model: string) => boolean;
98
+ export declare function modelLabel(model: string, isFreeModel: FreeModelCheck): string;
94
99
  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.).";
95
100
  export declare const STOPPED_TASKS_HEADER = "Tasks you stopped with castle-stop. They started and you cancelled them; none finished. What the user saw: the task appeared on their board and then vanished. So if the user says a task never started, or asks where it went, say plainly that you stopped it (not that it never started), then re-send it if they still want it";
96
101
  export declare const BAD_TASK_ENDINGS_HEADER = "Tasks that ended badly since your last reply. Tell the user about these at the start of your reply, plainly. Do not talk as if they are still running";
@@ -110,9 +115,17 @@ export interface RouterPromptOpts {
110
115
  plan?: RouterPlanOpts;
111
116
  playtest?: boolean;
112
117
  playtestPref?: 'on' | 'off';
113
- askCalls?: boolean;
114
118
  steer?: boolean;
115
119
  unsentSends?: string[];
120
+ routerModel?: {
121
+ model: string;
122
+ effort: string;
123
+ };
124
+ taskModel?: {
125
+ model: string;
126
+ effort: string;
127
+ };
128
+ isFreeModel?: FreeModelCheck;
116
129
  editorTabs?: string[];
117
130
  kits?: string[];
118
131
  paramsWrites?: string[];
@@ -35,6 +35,9 @@ file layouts, or implementation steps.`;
35
35
  export const PLAYTEST_TASK_UNDRIVEN_RULE = '- The playtest tool is a headless preview, not the user\'s device. If you could not make the behavior in question happen there, or checking it needs something the preview did not give you (a microphone, a camera, a second player, a native app command, the phone\'s on-screen keyboard), your result says exactly that -- "I could not drive X in the headless preview because Y; unverified" -- instead of reporting what the code implies. Never write "verified" for something you did not observe, and when you did observe it, say it was verified in the headless preview.';
36
36
  const STOP_RULE_NO_STEER = `- Stop a running or waiting task only when the new message makes its work unwanted: the user said to stop or drop it, took back or reversed what it is building, or corrected it -- it has the wrong idea, or they picked a different option than the one it is building -- so its result would have to be undone. When that change comes with new work, stop it in the SAME reply that spawns the replacement. When the new ask adds to a running task, extends it, or is about something else, leave it running and spawn the new work as its own task: in parallel, or with \`after:\` naming it only when the new work needs that task's actual output. Nothing reaches a running task, so leaving it running never covers the new ask by itself. Never stop a task because a new one restates it or covers it more broadly.`;
37
37
  export const STOP_RULE_STEER = `- When a new message is about work a task is still running or waiting to run -- it corrects it, adds to it, narrows it, or answers a question you asked about it -- \`castle-send\` it to that task instead of stopping it: the task keeps what it has done and adjusts. Stop a running or waiting task only when the user said to stop or drop it, or took back what it is building so completely that nothing it has done would survive. When that change comes with new work, stop it in the SAME reply that spawns the replacement. When the new ask is about something else, leave the task running and spawn the new work as its own task: in parallel, or with \`after:\` naming it only when the new work needs that task's actual output. Never stop a task because a new one restates it or covers it more broadly.`;
38
+ // A castle-send keeps the running task's recorded model, so a change the user
39
+ // wants on another model cannot ride it.
40
+ export const STEER_MODEL_CLAUSE = ", as a new task even when it changes a running one: a castle-send keeps that task's model.";
38
41
  export const SEND_FENCE_RULES = `
39
42
 
40
43
  To hand a message to a task that is running or waiting to run:
@@ -46,7 +49,7 @@ the user's message for it -- their own words, quoted, plus only what from this c
46
49
 
47
50
  - \`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.
48
51
  - It cannot reach a finished task. For those, spawn a new task (see the one-and-done rule below).`;
49
- function baseRouterRules(playtest, askCalls, playtestPref, steer = false) {
52
+ function baseRouterRules(playtest, playtestPref, steer = false) {
50
53
  const runningTaskRules = steer ? STOP_RULE_STEER : STOP_RULE_NO_STEER;
51
54
  const sendFenceRules = steer ? SEND_FENCE_RULES : '';
52
55
  const playtestRules = playtestPref === 'off'
@@ -56,6 +59,7 @@ function baseRouterRules(playtest, askCalls, playtestPref, steer = false) {
56
59
  : playtest
57
60
  ? `\n${PLAYTEST_ROUTER_RULE}`
58
61
  : '';
62
+ const modelsRule = `\n- You cannot change which models run. Both are set in the model chip under the message box (Agent & model settings): Operator model and Operator effort set the model you, this chat, run on; Task model and Task effort set the model new tasks run on. A change applies to what starts after it, not to anything already running. When the user asks which model you or their tasks run on, asks to switch to or use a model or effort, or says they have switched: answer from == models == (and, when relevant, the model on the rows they mean), which always shows the current settings; trust it over anything said earlier in this chat, which may be wrong. If it does not show what they say they picked, tell them that setting has not changed yet. Point them to the matching row; never say you switched it or that it has changed when == models == does not show it. If the same message asks for work they want done on a model or effort == models == does not show yet, do not spawn that work yet: tell them to change the setting and send the request again. When == models == already shows it, spawn the work as usual${steer ? STEER_MODEL_CLAUSE : '.'} Apart from a usage-limit failure (above), do not bring up models when the user did not.`;
59
63
  return `You are Castle's create assistant: the fast conversational router for a game-making session. The deck (game project) lives in the current directory and runs live in a pane right next to this chat.
60
64
 
61
65
  What a deck is: a normal web project served by vite -- index.html plus plain JS/JSX modules, with real npm dependencies (more can be installed), the castle-web-sdk package, and usually a kit framework whose engine, behaviors, scenes, editors, and drawings are ordinary files in this directory. The web platform is fully available (DOM, canvas, npm libraries like react, three, etc.). The deck's Quick reference and file list below describe its setup; the full CLAUDE.md / AGENTS.md has deeper detail. NEVER claim something is impossible or unsupported on the platform without checking that context (or, for specifics it doesn't cover, the deck's files) first.
@@ -81,7 +85,8 @@ Hard rules:
81
85
  \`\`\`castle-task
82
86
  short imperative title on the first line
83
87
  after: comma-separated titles or ids this task must wait for (optional line)
84
- ${askCalls ? 'hold: answer (optional line -- only on the task a probe in this same reply decides)\n' : ''}${TASK_FENCE_PROMPT_EXAMPLE}
88
+ hold: answer (optional line -- only on the task a probe in this same reply decides)
89
+ ${TASK_FENCE_PROMPT_EXAMPLE}
85
90
  \`\`\`
86
91
 
87
92
  - Use \`after:\` only for the fallback case above -- a task that genuinely needs another's produced output (it may reference tasks spawned in this same reply, by title). Never for file-contention; independent tasks must NOT wait on each other.
@@ -100,7 +105,7 @@ comma-separated active-task titles or ids, or \`all\`
100
105
  - When you spawn a task that fixes or redoes a FINISHED one, \`castle-done\` the earlier row in the SAME reply. Keep the board meaning "what to look at right now".
101
106
  ${runningTaskRules}
102
107
  - A \`failed\` row carries an \`error:\` line -- why it failed. A \`blocked\` row waited on a dep that failed or was stopped, so its output never arrived and it will never start on its own -- \`blocked by:\` names that dep. When you see one, decide for the user: usually spawn a replacement task (or pipeline) that redoes the failed work, and in the SAME reply \`castle-stop\` the blocked row and \`castle-done\` the failed one, so the board stays clean.
103
- - A failed row whose error is a usage limit -- the free-model daily allowance, credits, or a spending limit -- will fail the same way if respawned. Do not respawn it. Tell the user what ran out, when it resets if the row says, and that they can pick another model in settings (or get credits) to keep going. You cannot choose the model tasks run on.
108
+ - A failed row whose error is a usage limit -- the free-model daily allowance, credits, or a spending limit -- will fail the same way if respawned. Do not respawn it. Tell the user what ran out, when it resets if the row says, and that they can pick another model in settings (or get credits) to keep going. Point them to the Task model setting described below; you cannot change it.${modelsRule}
104
109
  - An interrupted row with an \`interrupted:\` platform reason was cut off, not stopped by you. Tell the user, and redo it only if they want it (their message may already ask); part of its work may already be on disk.
105
110
  - Do not mark a task done to imply YOU verified its quality -- the user playtests and confirms that. But DO keep the board tidy: clear finished work the user blessed, and remove anything clearly obsolete. When genuinely unsure, leave the row.
106
111
  - Never claim the board is cleared without actually emitting the fence.
@@ -129,14 +134,8 @@ Conversation style:
129
134
  - Spawning a task does NOT apply the change -- tasks run for minutes and finish on the board. Talk about spawned work in future tense ("this will dial the shake back"), and NEVER ask how a change feels right after spawning it -- the user cannot have tried it yet. Save "how is it?" for things whose task already finished.
130
135
  - The user playtests in the pane beside this chat; finished work shows up there after a reload.`;
131
136
  }
132
- const SPEC_RULE = `- CLEAR SPEC (mechanics named, a reference given, "like X but Y"): the gaps are closed. Build what they said; never probe taste they already expressed.`;
133
- const PROBE_CAP_RULE = `- At most ONE probe open at a time; none on spec, delegation, or conversation turns; never re-probe something answered. Probe feel and identity -- what the player DOES, how it should feel, the goal shape, the tone -- never implementation.`;
134
- // The q-a2 router arm (prompt-evals t1-router-ladder arms/q-a2.ts), for the
135
- // decks that opted in (`agent.askCalls` / CASTLE_AGENT_ASK_CALLS -- see
136
- // askCallsEnabled in agent.ts). Off for everyone by default, so the plan rules
137
- // stay byte-identical to a prompt built before it existed.
138
- const ASK_CALLS_SPEC_RULE = `- CLEAR SPEC (mechanics named, a reference given, "like X but Y"): build what they said; never probe taste they already expressed.`;
139
- const ASK_CALLS_PROBE_CAP_RULE = `- At most ONE probe open at a time; none on delegation or conversation turns; never re-probe something answered. Before you close a task fence, find the one thing that task will have to settle on its own: a word of theirs that reads two ways, or a case their ask never mentions. Quote the word and ask which, as a probe, your reading as the first chip and the other as the second. Then split the work by that answer. Tasks the answer cannot change spawn now. The task it decides gets a \`hold: answer\` line: it waits on the board and starts with their reply appended, whichever chip they tap or whatever they type. When the answer decides everything they asked for, the probe and that held task are the whole reply -- a held task is still building. Before you close each unheld task fence, reread its brief: if it names or assumes any option of your probe -- even in passing, like a control scheme, a count, or which screen -- that task decides it too. Give it the \`hold: answer\` line, or move that choice out of it into the held task and write the rest so it works with either answer. When they tap a chip, the task you held for it starts on its own with their answer -- the board shows it running with that answer. Acknowledge it in one line; never spawn it again or stop it. A row still held means they typed instead: if their message answers the probe, castle-stop the held row and spawn it again with their answer; otherwise leave it held.`;
137
+ const SPEC_RULE = `- CLEAR SPEC (mechanics named, a reference given, "like X but Y"): build what they said; never probe taste they already expressed.`;
138
+ const PROBE_CAP_RULE = `- At most ONE probe open at a time; none on delegation or conversation turns; never re-probe something answered. Before you close a task fence, find the one thing that task will have to settle on its own: a word of theirs that reads two ways, or a case their ask never mentions. Quote the word and ask which, as a probe, your reading as the first chip and the other as the second. Then split the work by that answer. Tasks the answer cannot change spawn now. The task it decides gets a \`hold: answer\` line: it waits on the board and starts with their reply appended, whichever chip they tap or whatever they type. When the answer decides everything they asked for, the probe and that held task are the whole reply -- a held task is still building. Before you close each unheld task fence, reread its brief: if it names or assumes any option of your probe -- even in passing, like a control scheme, a count, or which screen -- that task decides it too. Give it the \`hold: answer\` line, or move that choice out of it into the held task and write the rest so it works with either answer. When they tap a chip, the task you held for it starts on its own with their answer -- the board shows it running with that answer. Acknowledge it in one line; never spawn it again or stop it. A row still held means they typed instead: if their message answers the probe, castle-stop the held row and spawn it again with their answer; otherwise leave it held.`;
140
139
  // Appended to the rules above for a deck with the plan doc on -- see
141
140
  // planSession in agent.ts for which decks those are. One self-contained block,
142
141
  // so a deck without it gets the pre-plan prompt byte for byte.
@@ -147,10 +146,10 @@ const ASK_CALLS_PROBE_CAP_RULE = `- At most ONE probe open at a time; none on de
147
146
  // so out loud rather than quietly contradicting them.
148
147
  const PROBE_CLAUSE_NO_STEER = 'But NEVER spawn work a pending probe could invalidate: there is no telling a running task anything.';
149
148
  export 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.';
150
- function planRules(askCalls, steer = false) {
149
+ function planRules(steer = false) {
151
150
  const probeRunningTaskClause = steer ? PROBE_CLAUSE_STEER : PROBE_CLAUSE_NO_STEER;
152
151
  return `Reading the user, fresh from EACH message -- the same user hands you a spec, then a fragment, then delegates:
153
- ${askCalls ? ASK_CALLS_SPEC_RULE : SPEC_RULE}
152
+ ${SPEC_RULE}
154
153
  - FRAGMENT ("something with ants", "a cozy game about tea?"): gaps they cannot name yet. Draw their taste out on the few dimensions that decide whether this feels like THEIRS -- while building, never instead of building.
155
154
  - A fragment is not only a whole-game ask. "how about some obstacles?", "make it feel brighter" name a slice and leave its taste open: build the part they named, and probe the ONE dimension you were about to settle for them. Deciding it silently is how a deck becomes yours instead of theirs.
156
155
  - A build turn that was going to carry NO question at all is where a feel question belongs, and on a deck already underway most turns are that: they name a change, you make it, nothing is asked, and the feel of it was yours by default. If what you are about to build has a feel they have not named -- how hard it should be, how fast it should move, how it should land -- ask that one thing in the same reply as the work. This never replaces a question you were already going to ask: still one at a time, and if you already had one, keep it.
@@ -164,7 +163,7 @@ Probing while you build. A probe is one short plain question plus 2-4 tappable o
164
163
 
165
164
  - Tapping one sends its text as the user's next message; they can ignore it and type anything else, and the build continues either way. Never phrase a probe as if an answer were required.
166
165
  - Spawn the work the answer cannot invalidate AND attach the probe in the same reply -- this supersedes the rules above against pairing a question with task directives. ${probeRunningTaskClause}
167
- ${askCalls ? ASK_CALLS_PROBE_CAP_RULE : PROBE_CAP_RULE}
166
+ ${PROBE_CAP_RULE}
168
167
  - Chips NEVER stand on their own: a probe's question is the line right before them, and a probe is the only thing they are for. Alone they read as answers to a question nobody asked.
169
168
  - Praise is where the pull to offer something is strongest and most wrong: "oh nice, that works great" gets one plain sentence and nothing else. Vary it -- a compliment that always gets the same reply stops reading as one.
170
169
 
@@ -199,9 +198,9 @@ Promotion. Finished tasks leave notes worth keeping, listed above with the id of
199
198
 
200
199
  If the user asks you to ease off the questions or the plan upkeep, record that with a \`decide+\` quoting the ask, and honor it -- keep \`## Now\` current, quietly.`;
201
200
  }
202
- function routerRules(plan, playtest, askCalls, playtestPref, steer = false) {
203
- const base = baseRouterRules(playtest, askCalls, playtestPref, steer);
204
- return plan ? `${base}\n\n${planRules(askCalls, steer)}` : base;
201
+ function routerRules(plan, playtest, playtestPref, steer = false) {
202
+ const base = baseRouterRules(playtest, playtestPref, steer);
203
+ return plan ? `${base}\n\n${planRules(steer)}` : base;
205
204
  }
206
205
  function renderTranscriptLine(m) {
207
206
  if (m.role === "user")
@@ -883,12 +882,29 @@ export function renderTaskPlanSlice(fileText, item, finishedWork) {
883
882
  // deck that opted out -- which is both meaningless there (nothing tells that
884
883
  // router what an item is) and a break in the byte-identity the opt-out
885
884
  // promises.
886
- function renderTasks(tasks, showItems) {
885
+ // The names the composer's model chip shows (formatRoleSettings in
886
+ // shell/operator.tsx), so the router's answer matches what the user sees in
887
+ // settings rather than a provider slug. "Muse" is the chip's name for a model
888
+ // Castle pays for, which only the budget's free prefixes decide.
889
+ const CLAUDE_MODEL_LABELS = { sonnet: "Sonnet", opus: "Opus", fable: "Fable" };
890
+ const noFreeModels = () => false;
891
+ export function modelLabel(model, isFreeModel) {
892
+ const trimmed = model.trim();
893
+ if (CLAUDE_MODEL_LABELS[trimmed])
894
+ return CLAUDE_MODEL_LABELS[trimmed];
895
+ if (isFreeModel(trimmed))
896
+ return "Muse";
897
+ return trimmed.slice(trimmed.lastIndexOf("/") + 1);
898
+ }
899
+ function renderTasks(tasks, showItems, isFreeModel) {
887
900
  if (tasks.length === 0)
888
901
  return "(none yet)";
889
902
  return tasks
890
903
  .map((t) => {
891
904
  const item = showItems && t.item ? ` -- item: ${t.item}` : "";
905
+ const model = t.model || t.effort
906
+ ? ` -- model: ${[t.model && modelLabel(t.model, isFreeModel), t.effort].filter(Boolean).join(" ")}`
907
+ : "";
892
908
  const notes = t.notes.trim() ? ` -- notes: ${t.notes.trim()}` : "";
893
909
  const error = t.error ? ` -- error: ${t.error}` : "";
894
910
  const interrupted = t.interrupted ? ` -- interrupted: ${t.interrupted}` : "";
@@ -896,7 +912,7 @@ function renderTasks(tasks, showItems) {
896
912
  ? ` -- blocked by: ${t.blockedBy.join(", ")}`
897
913
  : "";
898
914
  const sent = t.sent ? ` -- messages you sent it: ${t.sent}` : "";
899
- const row = `- [${t.status} ${t.progress}%] ${t.title} (${t.id})${item}${notes}${error}${interrupted}${blockedBy}${sent}`;
915
+ const row = `- [${t.status} ${t.progress}%] ${t.title} (${t.id})${item}${model}${notes}${error}${interrupted}${blockedBy}${sent}`;
900
916
  const held = t.status === "held" && t.heldQuestion !== undefined
901
917
  ? `\n held -- waiting on the answer to: ${t.heldQuestion}`
902
918
  : "";
@@ -950,6 +966,18 @@ export function buildRouterPromptParts(opts) {
950
966
  const paramsWrites = opts.paramsWrites?.length
951
967
  ? `\n\n== parameters panel ==\nThe user set these from the Parameters panel since your last turn:\n${opts.paramsWrites.map((slot) => `- ${slot}`).join("\n")}`
952
968
  : "";
969
+ const models = [
970
+ opts.routerModel
971
+ ? `This chat (you) runs on: ${modelLabel(opts.routerModel.model, opts.isFreeModel ?? noFreeModels)} (effort ${opts.routerModel.effort})`
972
+ : undefined,
973
+ opts.taskModel
974
+ ? `New tasks run on: ${modelLabel(opts.taskModel.model, opts.isFreeModel ?? noFreeModels)} (effort ${opts.taskModel.effort})`
975
+ : undefined,
976
+ ].filter((line) => line !== undefined);
977
+ // Above the board, not beside the user's message: last in the prompt, the
978
+ // models lines tipped the router into spawning (n19-cover-host, 26-09-28:
979
+ // 19/19 spawns vs 6/19 off; 5/10 once moved here).
980
+ const modelsSection = models.length ? `\n\n== models ==\n${models.join("\n")}` : "";
953
981
  const stopped = opts.stopped?.length
954
982
  ? `\n\n${STOPPED_TASKS_HEADER}:\n${opts.stopped
955
983
  .map((stop) => {
@@ -977,15 +1005,15 @@ export function buildRouterPromptParts(opts) {
977
1005
  // does not. `user` holds what changes every turn: the transcript, the plan,
978
1006
  // the board and this instruction.
979
1007
  return {
980
- system: `${routerRules(opts.plan !== undefined, opts.playtest === true, opts.askCalls === true, opts.playtestPref, opts.steer === true)}
1008
+ system: `${routerRules(opts.plan !== undefined, opts.playtest === true, opts.playtestPref, opts.steer === true)}
981
1009
 
982
1010
  == deck ==
983
1011
  ${opts.deckLabel}${quickReference}${editorTabs}${kits}${deckFiles}`,
984
1012
  user: `== conversation so far ==
985
- ${renderTranscript(opts.messages)}${plan}
1013
+ ${renderTranscript(opts.messages)}${plan}${modelsSection}
986
1014
 
987
1015
  == background tasks ==
988
- ${renderTasks(opts.tasks, opts.plan !== undefined)}${endedBadly}${stopped}${unsent}${paramsWrites}
1016
+ ${renderTasks(opts.tasks, opts.plan !== undefined, opts.isFreeModel ?? noFreeModels)}${endedBadly}${stopped}${unsent}${paramsWrites}
989
1017
 
990
1018
  == now ==
991
1019
  ${opts.instruction}
package/dist/agent.d.ts CHANGED
@@ -98,7 +98,6 @@ interface TaskRecord {
98
98
  export declare function playtestEnabled(deckDir: string): boolean;
99
99
  export declare function playtestPrefFor(deckDir: string): 'on' | 'off' | undefined;
100
100
  export declare function setPlaytestPref(deckDir: string, value: 'on' | 'off'): boolean;
101
- export declare function askCallsEnabled(deckDir: string): boolean;
102
101
  interface AgentRunHandle {
103
102
  pid?: number | undefined;
104
103
  exitCode: number | null;
package/dist/agent.js CHANGED
@@ -653,23 +653,6 @@ function planSession(deckDir) {
653
653
  planSessions.set(deckDir, session);
654
654
  return session;
655
655
  }
656
- const askCallsSessions = new Map();
657
- // The inverse of planDefault: dormant until someone asks for it.
658
- function askCallsDefault() {
659
- return process.env.CASTLE_AGENT_ASK_CALLS === 'on';
660
- }
661
- // Resolved once per deck and cached for the reason planSession is: it decides
662
- // what sits in the prompt's cached prefix, so honoring a mid-session change
663
- // would split the prompt cache. Changing it takes a serve restart.
664
- export function askCallsEnabled(deckDir) {
665
- const cached = askCallsSessions.get(deckDir);
666
- if (cached !== undefined)
667
- return cached;
668
- const declared = readCastleJson(deckDir)?.agent?.askCalls;
669
- const enabled = declared === 'on' ? true : declared === 'off' ? false : askCallsDefault();
670
- askCallsSessions.set(deckDir, enabled);
671
- return enabled;
672
- }
673
656
  function readPlanSnapshot(deckDir) {
674
657
  let raw;
675
658
  try {
@@ -1943,6 +1926,9 @@ function createUsageFeed(opts) {
1943
1926
  refresh();
1944
1927
  return {
1945
1928
  latest: () => latest,
1929
+ // The budget outlives a switch to the user's own OpenRouter key; the chip
1930
+ // stops saying Muse then (usageFrame's freeModel), so the router must too.
1931
+ freeModelPrefixes: () => runIsCastlePaid('openrouter', null) ? (budget?.freeModelPrefixes ?? []) : [],
1946
1932
  recompute,
1947
1933
  refresh,
1948
1934
  stop: () => {
@@ -3466,6 +3452,8 @@ function asPromptTask(task) {
3466
3452
  status: task.rejected ? 'rejected by user' : task.status,
3467
3453
  progress: task.progress,
3468
3454
  notes: task.notes,
3455
+ ...(task.model ? { model: task.model } : {}),
3456
+ ...(task.effort ? { effort: task.effort } : {}),
3469
3457
  item: task.item,
3470
3458
  error: task.status === 'failed'
3471
3459
  ? withTimeoutReport(routerTaskError(firstErrorLine(task.resultSummary), task.failure, task.errorCopy), task)
@@ -3724,6 +3712,8 @@ function routerTurnPrompt(ctx, instruction, selfMessageId, plan) {
3724
3712
  const messages = ctx.log.messages.filter((message) => message.role !== 'log' && message.id !== selfMessageId && message.status !== 'streaming');
3725
3713
  const tasks = ctx.taskStore.sorted();
3726
3714
  const lastReplyAtMs = panelWriteWatermark(ctx.log.messages, selfMessageId);
3715
+ const taskClaudeModel = ctx.taskClaudeModel();
3716
+ const taskOpenrouterModel = ctx.taskOpenrouterModel();
3727
3717
  return buildRouterPromptParts({
3728
3718
  deckLabel: ctx.deckLabel,
3729
3719
  quickReference: quickReferenceFor(ctx.deckDir, deckGuide, 'router'),
@@ -3732,11 +3722,19 @@ function routerTurnPrompt(ctx, instruction, selfMessageId, plan) {
3732
3722
  deckTree: buildDeckTree(ctx.deckDir),
3733
3723
  playtest: playtestEnabled(ctx.deckDir),
3734
3724
  playtestPref: playtestPrefFor(ctx.deckDir),
3735
- askCalls: askCallsEnabled(ctx.deckDir),
3736
3725
  steer: TASK_STEER_ENABLED || undefined,
3737
3726
  unsentSends: TASK_STEER_ENABLED
3738
3727
  ? messages.filter((m) => m.role === 'assistant').at(-1)?.unsent
3739
3728
  : undefined,
3729
+ isFreeModel: (model) => modelIsFree(model, ctx.freeModelPrefixes()),
3730
+ routerModel: {
3731
+ model: spawnModelFor(ctx.claudeModel(), ctx.openrouterModel()),
3732
+ effort: spawnEffortFor(ctx.claudeModel(), ctx.openrouterModel(), ctx.effort()),
3733
+ },
3734
+ taskModel: {
3735
+ model: spawnModelFor(taskClaudeModel, taskOpenrouterModel),
3736
+ effort: spawnEffortFor(taskClaudeModel, taskOpenrouterModel, ctx.taskEffort()),
3737
+ },
3740
3738
  messages: messages.map((m) => ({
3741
3739
  role: m.role,
3742
3740
  // Replace a prior turn's raw ```ask JSON with a readable question list
@@ -4460,6 +4458,10 @@ function startRouterTurn(ctx, instruction) {
4460
4458
  claudeModel: () => ctx.settings.routerClaudeModel,
4461
4459
  openrouterModel: () => ctx.settings.routerOpenrouterModel,
4462
4460
  effort: () => ctx.settings.routerEffort,
4461
+ taskClaudeModel: () => ctx.settings.tasksClaudeModel,
4462
+ taskOpenrouterModel: () => ctx.settings.tasksOpenrouterModel,
4463
+ taskEffort: () => ctx.settings.tasksEffort,
4464
+ freeModelPrefixes: ctx.freeModelPrefixes,
4463
4465
  canAutoRetry: () => !ctx.state.autoRetryUsed && ctx.state.pendingSends.length === 0,
4464
4466
  onSettled: (retryable) => onRouterQueueSettled(ctx, retryable),
4465
4467
  }, instruction);
@@ -4784,10 +4786,9 @@ export function createAgentServer(opts) {
4784
4786
  const attachmentsDir = path.join(agentDir, 'attachments');
4785
4787
  const messagesPath = path.join(agentDir, 'messages.json');
4786
4788
  fs.mkdirSync(tasksDir, { recursive: true });
4787
- // Read the prompt switches this deck declares now, so the whole serve shares
4788
- // one answer for each -- see planSession and askCallsEnabled.
4789
+ // Read the plan switch this deck declares now, so the whole serve shares one
4790
+ // answer -- see planSession.
4789
4791
  planSession(deckDir);
4790
- askCallsEnabled(deckDir);
4791
4792
  // Warm the OpenRouter catalog now so the first pre-flight and the first
4792
4793
  // popover open read a cache instead of paying for the fetch. Fire-and-forget
4793
4794
  // by design -- nothing here depends on it, and it falls open if it fails.
@@ -4907,6 +4908,7 @@ export function createAgentServer(opts) {
4907
4908
  // guard). Lives in its own factory; createAgentServer just wires it up.
4908
4909
  const routerQueue = createRouterQueue({
4909
4910
  deckDir,
4911
+ freeModelPrefixes: usageFeed.freeModelPrefixes,
4910
4912
  deckLabel,
4911
4913
  agentDir,
4912
4914
  attachmentsDir,
@@ -20,7 +20,6 @@ export interface CastleJson {
20
20
  main?: string;
21
21
  agent?: {
22
22
  plan?: 'on' | 'off';
23
- askCalls?: 'on' | 'off';
24
23
  playtest?: 'on' | 'off';
25
24
  };
26
25
  server?: {
package/dist/init.js CHANGED
@@ -54,7 +54,7 @@ if (!(await mountEditorRoute())) startGame(initCard());
54
54
  // Registry version of castle-web-sdk to inject when scaffolding from a
55
55
  // globally-installed castle-web (not from inside the workspace). Bumped
56
56
  // alongside cli/sdk version bumps.
57
- const PUBLISHED_SDK_VERSION = '0.4.42';
57
+ const PUBLISHED_SDK_VERSION = '0.4.43';
58
58
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
59
59
  // face can ship without a cli release, and a caret range means an existing
60
60
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -3,13 +3,23 @@ import { type SavePrecondition } from './webSourceSync.js';
3
3
  export declare const SOURCE_ARCHIVE_EXCLUDES: string[];
4
4
  export declare const SAVE_STAGE_TELEMETRY_PREFIX = "CASTLE_SAVE_TELEMETRY ";
5
5
  export declare const SAVE_COVER_SELECTION_TELEMETRY_PREFIX = "CASTLE_SAVE_COVER_SELECTION ";
6
+ export declare const MAX_SCENE_DATA_BYTES: number;
7
+ export declare const MAX_SOURCE_ARCHIVE_BYTES: number;
6
8
  export type SaveStage = 'bundle' | 'cover' | 'scene_upload_config' | 'scene_upload' | 'content_publish' | 'server_publish' | 'source_archive' | 'source_upload_config' | 'source_upload' | 'source_commit';
7
9
  export declare function runTar(args: string[], opts?: {
8
10
  capture?: boolean;
9
11
  }): Promise<string>;
12
+ export declare function sceneTooLargeMessage(bytes: number): string;
13
+ export declare function sourceTooLargeMessage(bytes: number, largest: {
14
+ file: string;
15
+ bytes: number;
16
+ }[], published?: boolean): string;
10
17
  export declare function archiveSource(projectDir: string): Promise<Buffer>;
11
18
  export declare function downloadSourceArchive(source: api.WebDeckSource, namePrefix: string, log?: (line: string) => void): Promise<string>;
12
- export declare function uploadSource(projectDir: string, deckId: string, expectedS3Key?: string | null): Promise<api.WebDeckSource>;
19
+ export declare function packSourceForSave(projectDir: string, castleJson: string | null, { published }?: {
20
+ published?: boolean;
21
+ }): Promise<Buffer>;
22
+ export declare function uploadSource(projectDir: string, deckId: string, expectedS3Key?: string | null, archive?: Buffer): Promise<api.WebDeckSource>;
13
23
  export declare function checkSavePrecondition(projectDir: string, deckId: string, force: boolean): Promise<SavePrecondition>;
14
24
  export type SaveVisibility = 'unlisted' | 'private';
15
25
  export interface SaveDeckOptions {
package/dist/save-deck.js CHANGED
@@ -23,6 +23,14 @@ export const SOURCE_ARCHIVE_EXCLUDES = ['node_modules', 'dist', '.castle', '.git
23
23
  // independently deployable.
24
24
  export const SAVE_STAGE_TELEMETRY_PREFIX = 'CASTLE_SAVE_TELEMETRY ';
25
25
  export const SAVE_COVER_SELECTION_TELEMETRY_PREFIX = 'CASTLE_SAVE_COVER_SELECTION ';
26
+ // Ghost's upload ceilings, enforced by S3 in the presigned POST policies (diy.ts
27
+ // MAX_SCENE_DATA_BYTES, webDeckSource.ts MAX_ARCHIVE_BYTES). Mirrored here so an oversized deck
28
+ // is refused before anything is uploaded: past the cap S3 answers only an opaque HTTP 400, and the
29
+ // source upload runs after the deck has already gone live. Keep these in step with ghost.
30
+ export const MAX_SCENE_DATA_BYTES = 50 * 1024 * 1024;
31
+ export const MAX_SOURCE_ARCHIVE_BYTES = 100 * 1024 * 1024;
32
+ // Long enough to move a payload at either cap over a slow uplink (100 MB at ~3 Mbit/s).
33
+ const LARGE_UPLOAD_TIMEOUT_MS = 300_000;
26
34
  function emitSaveStage(stage, outcome, startedAtMs, fields = {}) {
27
35
  if (process.env.CASTLE_SAVE_STAGE_TELEMETRY !== '1')
28
36
  return;
@@ -74,6 +82,55 @@ export function runTar(args, opts = {}) {
74
82
  });
75
83
  });
76
84
  }
85
+ function formatMB(bytes) {
86
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
87
+ }
88
+ // The biggest files the source archive would carry, as a hint for what to shrink. Skips what the
89
+ // archive excludes and never follows a symlink; unreadable entries are left out.
90
+ function largestSourceFiles(projectDir, count) {
91
+ const found = [];
92
+ const walk = (rel) => {
93
+ let entries;
94
+ try {
95
+ entries = fs.readdirSync(path.join(projectDir, rel), { withFileTypes: true });
96
+ }
97
+ catch {
98
+ return;
99
+ }
100
+ for (const entry of entries) {
101
+ const child = rel ? path.join(rel, entry.name) : entry.name;
102
+ if (!rel && SOURCE_ARCHIVE_EXCLUDES.includes(entry.name))
103
+ continue;
104
+ if (entry.isDirectory())
105
+ walk(child);
106
+ else if (entry.isFile()) {
107
+ try {
108
+ found.push({ file: child, bytes: fs.lstatSync(path.join(projectDir, child)).size });
109
+ }
110
+ catch {
111
+ /* vanished mid-walk */
112
+ }
113
+ }
114
+ }
115
+ };
116
+ walk('');
117
+ return found.sort((a, b) => b.bytes - a.bytes).slice(0, count);
118
+ }
119
+ export function sceneTooLargeMessage(bytes) {
120
+ return (`This deck is too large to save: its game bundle is ${formatMB(bytes)}, and Castle accepts at ` +
121
+ `most ${formatMB(MAX_SCENE_DATA_BYTES)}. Nothing was published. Images, audio and models are ` +
122
+ 'packed into the bundle, so shrink or remove the largest assets and save again.');
123
+ }
124
+ export function sourceTooLargeMessage(bytes, largest, published = false) {
125
+ const list = largest.map((f) => `${f.file} (${formatMB(f.bytes)})`).join(', ');
126
+ return (`This deck's source is too large to save: compressed, it is ${formatMB(bytes)}, and Castle ` +
127
+ `accepts at most ${formatMB(MAX_SOURCE_ARCHIVE_BYTES)}. ` +
128
+ (published
129
+ ? 'The playable deck was updated, but its source was not saved.'
130
+ : 'Nothing was published.') +
131
+ (list ? ` Largest files: ${list}.` : '') +
132
+ ' Remove or shrink files the deck does not need and save again.');
133
+ }
77
134
  export async function archiveSource(projectDir) {
78
135
  const tmpFile = path.join(os.tmpdir(), `castle-source-${nanoid(8)}.tar.gz`);
79
136
  const args = ['-czf', tmpFile];
@@ -123,17 +180,57 @@ async function uploadPresignedFile(uploadConfig, file, contentType, timeoutMs, l
123
180
  if (response.status >= 300)
124
181
  throw new Error(`${label} failed: HTTP ${response.status}`);
125
182
  }
183
+ // The source a save uploads, packed (streamed through gzip by tar) and size-checked before
184
+ // anything is published, so the bytes checked are the bytes uploaded. `castleJson` is the
185
+ // castle.json to archive in place of the one on disk: save-deck rewrites that file only after
186
+ // publishing, from the publish result, and the saved source must already carry the new version
187
+ // (a new deck's ids, a new title). The top-level entries are named one by one to leave out only
188
+ // the root castle.json -- an --exclude pattern would also match nested files of that name (bsdtar).
189
+ export async function packSourceForSave(projectDir, castleJson, { published = false } = {}) {
190
+ const stageDir = fs.mkdtempSync(path.join(os.tmpdir(), 'castle-source-'));
191
+ const outFile = path.join(stageDir, 'source.tar.gz');
192
+ try {
193
+ const entries = fs
194
+ .readdirSync(projectDir)
195
+ .filter((name) => !SOURCE_ARCHIVE_EXCLUDES.includes(name))
196
+ .filter((name) => castleJson === null || name !== 'castle.json')
197
+ .sort()
198
+ .map((name) => `./${name}`);
199
+ const args = ['-czf', outFile];
200
+ for (const ex of SOURCE_ARCHIVE_EXCLUDES)
201
+ args.push(`--exclude=./${ex}`);
202
+ // Every name starts with `./`, so none reads as an option.
203
+ args.push('-C', projectDir, ...entries);
204
+ if (castleJson !== null) {
205
+ const castleJsonDir = path.join(stageDir, 'castle-json');
206
+ fs.mkdirSync(castleJsonDir);
207
+ fs.writeFileSync(path.join(castleJsonDir, 'castle.json'), castleJson, 'utf-8');
208
+ // `-C` is positional: it applies to the names after it.
209
+ args.push('-C', castleJsonDir, './castle.json');
210
+ }
211
+ await runTar(args);
212
+ const archive = fs.readFileSync(outFile);
213
+ if (archive.byteLength > MAX_SOURCE_ARCHIVE_BYTES) {
214
+ throw new Error(sourceTooLargeMessage(archive.byteLength, largestSourceFiles(projectDir, 3), published));
215
+ }
216
+ console.log(`Source archive: ${(archive.length / 1024).toFixed(1)}KB`);
217
+ return archive;
218
+ }
219
+ finally {
220
+ fs.rmSync(stageDir, { recursive: true, force: true });
221
+ }
222
+ }
126
223
  // `expectedS3Key` is the save precondition (api.saveWebDeckSource). Returns the saved source,
127
- // whose key and time become this folder's sync marker.
128
- export async function uploadSource(projectDir, deckId, expectedS3Key) {
129
- const archive = await traceSaveStage('source_archive', () => archiveSource(projectDir), (value) => ({ bytes: value.byteLength }));
130
- const sizeKB = archive.length / 1024;
131
- console.log(`Source archive: ${sizeKB.toFixed(1)}KB`);
224
+ // whose key and time become this folder's sync marker. `archive` is the source save-deck packed
225
+ // before publishing; without it the folder is packed here, as it is on disk.
226
+ export async function uploadSource(projectDir, deckId, expectedS3Key, archive) {
227
+ const source = archive ??
228
+ (await traceSaveStage('source_archive', () => packSourceForSave(projectDir, null, { published: true }), (value) => ({ bytes: value.byteLength })));
132
229
  const uploadConfig = await traceSaveStage('source_upload_config', () => api.createWebDeckSourceUploadConfig(deckId));
133
230
  // FormData expects a Blob; copy the Buffer's bytes so we don't share the underlying ArrayBuffer.
134
- const view = new Uint8Array(archive.byteLength);
135
- view.set(archive);
136
- await traceSaveStage('source_upload', () => uploadPresignedFile(uploadConfig, new Blob([view], { type: 'application/gzip' }), 'application/gzip', 60_000, 'Source upload'));
231
+ const view = new Uint8Array(source.byteLength);
232
+ view.set(source);
233
+ await traceSaveStage('source_upload', () => uploadPresignedFile(uploadConfig, new Blob([view], { type: 'application/gzip' }), 'application/gzip', LARGE_UPLOAD_TIMEOUT_MS, 'Source upload'));
137
234
  return traceSaveStage('source_commit', () => api.saveWebDeckSource(deckId, uploadConfig.uploadId, expectedS3Key));
138
235
  }
139
236
  // Refused: the saved copy is newer than this folder. One machine-readable stdout line (castle-www
@@ -232,6 +329,12 @@ async function uploadLocalCover(projectDir) {
232
329
  return null;
233
330
  }
234
331
  }
332
+ // Preserve any deck-owned config already in castle.json (notably the `editor` block); save-deck
333
+ // only owns the identity fields.
334
+ function castleJsonAfterSave(castleJson, deckId, cardId, title) {
335
+ const next = { ...(castleJson ?? {}), deckId, cardId, title };
336
+ return JSON.stringify(next, null, 2) + '\n';
337
+ }
235
338
  function readCastleJson(dir) {
236
339
  const p = path.join(dir, 'castle.json');
237
340
  if (!fs.existsSync(p))
@@ -298,10 +401,21 @@ export async function saveDeck(dir, opts = {}) {
298
401
  if (sizeKB > 1024) {
299
402
  console.warn(`Warning: Bundle is ${(sizeKB / 1024).toFixed(1)}MB. Large bundles may load slowly.`);
300
403
  }
301
- const sceneData = buildSceneData(bundle);
404
+ // Both of ghost's size caps are checked here, before anything is uploaded: the deck goes live at
405
+ // content_publish, and the source is uploaded only after that.
406
+ const sceneJson = JSON.stringify(buildSceneData(bundle));
407
+ const sceneBytes = Buffer.byteLength(sceneJson);
408
+ if (sceneBytes > MAX_SCENE_DATA_BYTES) {
409
+ // Reported as the stage that would have failed, so castle-www's failed_at stays comparable.
410
+ await traceSaveStage('scene_upload', () => Promise.reject(new Error(sceneTooLargeMessage(sceneBytes))));
411
+ }
302
412
  const isNew = !castleJson;
303
413
  const cardId = castleJson?.cardId ?? nanoid(12);
304
414
  const deckId = castleJson?.deckId ?? nanoid(12);
415
+ const title = opts.title ?? castleJson?.title ?? path.basename(path.resolve(projectDir));
416
+ // Packed now, from the same files as the bundle, with the castle.json this save will write, and
417
+ // uploaded as is after the deck is published.
418
+ const sourceArchive = await traceSaveStage('source_archive', () => packSourceForSave(projectDir, castleJsonAfterSave(castleJson, deckId, cardId, title)), (value) => ({ bytes: value.byteLength }));
305
419
  // Capturing and uploading the cover depends only on the already-running serve. Start it as
306
420
  // soon as the bundle has passed, while the independent scene upload is being authorized and
307
421
  // transferred. The promise is deliberately non-throwing: a thumbnail must never make the
@@ -320,17 +434,16 @@ export async function saveDeck(dir, opts = {}) {
320
434
  for (const [k, v] of Object.entries(uploadConfig.postFields)) {
321
435
  formData.append(k, String(v));
322
436
  }
323
- formData.append('file', new Blob([JSON.stringify(sceneData)]));
437
+ formData.append('file', new Blob([sceneJson]));
324
438
  await traceSaveStage('scene_upload', async () => {
325
439
  const response = await fetch(uploadConfig.postUrl, {
326
440
  method: 'POST',
327
441
  body: formData,
328
- signal: AbortSignal.timeout(30000),
442
+ signal: AbortSignal.timeout(LARGE_UPLOAD_TIMEOUT_MS),
329
443
  });
330
444
  if (response.status >= 300)
331
445
  throw new Error(`Upload failed: HTTP ${response.status}`);
332
446
  });
333
- const title = opts.title ?? castleJson?.title ?? path.basename(path.resolve(projectDir));
334
447
  const deckInput = { deckId, title };
335
448
  // Omitted unless asked for, or the deck is new and needs one: updateDeckV2
336
449
  // only touches visibility when it is sent, so a deck the creator published
@@ -366,20 +479,12 @@ export async function saveDeck(dir, opts = {}) {
366
479
  castleJson !== null && Object.prototype.hasOwnProperty.call(castleJson, 'characterBundle')
367
480
  ? api.updateCardAndDeckV2(deckInput, cardInput, castleJson?.characterBundle ?? null)
368
481
  : api.updateCardAndDeckV2(deckInput, cardInput));
369
- // Preserve any deck-owned config already in castle.json (notably the
370
- // `editor` block); save-deck only owns the identity fields below.
371
- const newCastleJson = {
372
- ...(castleJson ?? {}),
373
- deckId: result.deckId,
374
- cardId: result.cardId,
375
- title,
376
- };
377
482
  // Only write when the bytes actually move. An identical rewrite still bumps
378
483
  // mtime, which the serve's watcher reports as a change like any other -- so
379
484
  // a push that changed nothing here would flip the Play panel to "Changes
380
485
  // available" and put castle.json in the next saved version's diff.
381
486
  const castleJsonPath = path.join(projectDir, 'castle.json');
382
- const nextCastleJson = JSON.stringify(newCastleJson, null, 2) + '\n';
487
+ const nextCastleJson = castleJsonAfterSave(castleJson, result.deckId, result.cardId, title);
383
488
  const onDisk = fs.existsSync(castleJsonPath)
384
489
  ? fs.readFileSync(castleJsonPath, 'utf-8')
385
490
  : null;
@@ -406,7 +511,10 @@ export async function saveDeck(dir, opts = {}) {
406
511
  }
407
512
  console.log('Uploading source archive...');
408
513
  // The precondition only applies to the deck it was checked against.
409
- const saved = await uploadSource(projectDir, result.deckId, result.deckId === existingDeckId ? expectedS3Key : undefined);
514
+ const saved = await uploadSource(projectDir, result.deckId, result.deckId === existingDeckId ? expectedS3Key : undefined,
515
+ // Ghost keeps the ids it is sent, so this is the castle.json packed above; if it ever
516
+ // assigned others, the folder is packed again with the file as written.
517
+ result.deckId === deckId && result.cardId === cardId ? sourceArchive : undefined);
410
518
  console.log('Source archive saved.');
411
519
  try {
412
520
  writeSyncMarker(projectDir, result.deckId, saved, markerVia);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.225",
3
+ "version": "0.4.226",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"
@@ -12,7 +12,7 @@
12
12
  "scripts": {
13
13
  "build": "rm -rf dist && tsc && chmod +x dist/index.js && vite build && vite build -c vite.cover-bridge.config.ts && cp -R src/castle-host dist/castle-host && chmod -R u+w kits 2>/dev/null; rm -rf kits && cp -R ../kits kits && chmod -R u+w kits && rm -rf kits/*/imports",
14
14
  "dev": "tsc --watch",
15
- "check": "node ../scripts/sync-shared.mjs --check && node ../scripts/tests/icon-registry.mjs && node ../scripts/tests/sandbox-graphql-fields.mjs && node ../scripts/tests/kit-package-json.mjs && node ../scripts/tests/kit-catalog.mjs && node ../scripts/tests/router-fences.mjs && node ../scripts/tests/held-tasks.mjs && node ../scripts/tests/held-task-prompts.mjs && node ../scripts/tests/router-stops.mjs && node ../scripts/tests/task-steer.mjs && node ../scripts/tests/task-steer-store.mjs && node ../scripts/tests/router-task-endings.mjs && node ../scripts/tests/task-resume.mjs && node ../scripts/tests/plan-answered-questions.mjs && node ../scripts/tests/sdk-readme-limits.mjs && node ../scripts/tests/task-account.mjs && node ../scripts/tests/effort-support.mjs && eslint . && jscpd && tsc --noEmit && tsc --noEmit -p src/shell/tsconfig.json"
15
+ "check": "node ../scripts/sync-shared.mjs --check && node ../scripts/tests/icon-registry.mjs && node ../scripts/tests/sandbox-graphql-fields.mjs && node ../scripts/tests/kit-package-json.mjs && node ../scripts/tests/kit-catalog.mjs && node ../scripts/tests/router-fences.mjs && node ../scripts/tests/held-tasks.mjs && node ../scripts/tests/held-task-prompts.mjs && node ../scripts/tests/router-stops.mjs && node ../scripts/tests/task-steer.mjs && node ../scripts/tests/task-steer-store.mjs && node ../scripts/tests/router-task-endings.mjs && node ../scripts/tests/task-resume.mjs && node ../scripts/tests/task-model-request.mjs && node ../scripts/tests/plan-answered-questions.mjs && node ../scripts/tests/sdk-readme-limits.mjs && node ../scripts/tests/task-account.mjs && node ../scripts/tests/effort-support.mjs && eslint . && jscpd && tsc --noEmit && tsc --noEmit -p src/shell/tsconfig.json"
16
16
  },
17
17
  "jscpd": {
18
18
  "path": [