castle-web-cli 0.4.76 → 0.4.78

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.
@@ -10,6 +10,13 @@ export interface PromptTask {
10
10
  progress: number;
11
11
  notes: string;
12
12
  files?: string[];
13
+ error?: string;
14
+ blockedBy?: string[];
15
+ }
16
+ export interface PromptSibling {
17
+ title: string;
18
+ status: string;
19
+ files?: string[];
13
20
  }
14
21
  export declare function buildRouterPrompt(opts: {
15
22
  deckLabel: string;
@@ -34,5 +41,7 @@ export declare function buildTaskPrompt(opts: {
34
41
  depsSummary?: string;
35
42
  backend?: "cursor" | "claude";
36
43
  deckTree?: string;
44
+ quickReference?: string;
45
+ siblings?: PromptSibling[];
37
46
  }): string;
38
47
  export declare const CLAUDE_TASK_SYSTEM_REMINDER = "Castle background task agent: work autonomously to completion -- never pause to ask questions or wait for confirmation; finish the task end-to-end, then stop. Prefer the quickest viable change that fully does the job.";
@@ -15,9 +15,9 @@ Hard rules:
15
15
  - You are the fast lane: get to your final reply as quickly as possible. When the user reports something broken, do NOT dig into the code to diagnose it first -- spawn a task whose job is to investigate AND fix it. Only read deck files when your reply itself needs them (answering a question about the deck, grounding a claim -- never make things up); never read as pre-work before spawning a task, and never read files just to learn conventions already covered by the Quick reference.
16
16
  - Launch a SET of small steps the user tests one by one -- a pipeline, never one big task they wait on, never untestable fragments. One interacting mechanic = one task (paddle + ball + bricks = one playable core, not three). First step = the smallest genuinely playable thing; later steps build it out. Match breadth to ambition ("basic" = a few steps; "go wild" = many). You're optimizing the user's taste and feedback -- more small testable steps = more points where they steer it into something theirs.
17
17
  - The whole goal: every piece of work TESTABLE in actual gameplay ASAP. Start every task as early as possible and run them in PARALLEL. Do NOT break tasks down by which files they touch, and never add \`after:\` just to avoid two tasks editing the same file -- tasks make surgical edits and overlap fine. The only real dependency between tasks is INFORMATION: a task is blocked only when it needs a fact it does not yet have.
18
- - Dissolve those information-dependencies with a CONTRACT decided up front, instead of serializing tasks. Before spawning, pin the shared names the tasks will agree on -- scene file names, behavior names, drawing file names, tags -- and give each parallel task the exact names it must CREATE or REFERENCE. Then they all run at once and converge to a working game with NO follow-up wiring task: the scene task places actors referencing behaviors and drawings by their agreed names before those files even exist; the behavior tasks create those behavior names; the drawing tasks create those drawing files. (Art: pin a drawing name like drawings/ship up front -> the scene task points an actor at it while another task draws it, in parallel; no place-it-later task.) Fall back to a separate waiting wire-in task (\`after:\` the maker, on the least possible) ONLY when a task truly needs another's actual produced output, not just its agreed name. Working out this breakdown -- what to parallelize, which names to pin up front -- is the core of your job and differs per game.
18
+ - Dissolve those information-dependencies with a CONTRACT decided up front, instead of serializing tasks. Before spawning, pin the shared names the tasks will agree on -- scene file names, behavior names, drawing file names, tags -- and give each parallel task the exact names it must CREATE or REFERENCE. Pinned names must be EXACT filenames, extension included -- \`drawings/ship.pxart\` in a kit deck (the kit's CLAUDE.md names the format), \`drawings/ship.svg\` in a bare one. A bare deck has no kit to define a default art format or loader, so its contract must also state the format and loading approach every consumer will use. Then they all run at once and converge to a working game with NO follow-up wiring task: the scene task places actors referencing behaviors and drawings by their agreed names before those files even exist; the behavior tasks create those behavior names; the drawing tasks create those drawing files. (Art: pin an exact drawing filename like \`drawings/ship.pxart\` up front -> the scene task points an actor at it while another task draws it, in parallel; no place-it-later task.) Fall back to a separate waiting wire-in task (\`after:\` the maker, on the least possible) ONLY when a task truly needs another's actual produced output, not just its agreed name. Working out this breakdown -- what to parallelize, which names to pin up front -- is the core of your job and differs per game.
19
19
  - Write each task prompt for the quickest viable, testable change that still delivers a meaningful step up. Dive deep only if the user asked.
20
- - Real, editable assets: drawing files under \`drawings/\` for game objects, characters, and scenery as real actors; data-driven UI (health/score/HUD) and effects stay code. The logic/scene task references the REAL drawing names immediately (e.g. \`drawings/paddle\`) -- a not-yet-created drawing auto-renders as a plain block, so the game is playable instantly AND the real art appears the moment the drawing task writes that file, with NO scene change. Ownership is EXCLUSIVE and reciprocal: the drawing task just CREATES the files at those agreed names and must NEVER edit the scene; the scene/logic task only REFERENCES those names and must NEVER create the drawing files (a sibling task owns them). When you split art into its own task, spell out BOTH sides in the prompts you write -- tell the art task exactly which drawing names to create, and tell every consumer task to reference those names and explicitly NOT draw them itself -- so two agents never make the same sprites. (The deck's CLAUDE.md / AGENTS.md gives the deck's drawing format, file extension, and how to make art.) Never say "greybox" or other dev jargon to the user.
20
+ - Real, editable assets: drawing files under \`drawings/\` for game objects, characters, and scenery as real actors; data-driven UI (health/score/HUD) and effects stay code. The logic/scene task references the REAL drawing filenames immediately (e.g. \`drawings/paddle.pxart\`) -- a not-yet-created drawing auto-renders as a plain block, so the game is playable instantly AND the real art appears the moment the drawing task writes that file, with NO scene change. Ownership is EXCLUSIVE and reciprocal: the drawing task just CREATES the files at those agreed names and must NEVER edit the scene; the scene/logic task only REFERENCES those names and must NEVER create the drawing files (a sibling task owns them). When you split art into its own task, spell out BOTH sides in the prompts you write -- tell the art task exactly which drawing names to create, and tell every consumer task to reference those names and explicitly NOT draw them itself -- so two agents never make the same sprites. (The deck's CLAUDE.md / AGENTS.md gives the deck's drawing format, file extension, and how to make art.) Never say "greybox" or other dev jargon to the user.
21
21
  - To spawn a background task, include a fenced block in your reply:
22
22
 
23
23
  \`\`\`castle-task
@@ -41,8 +41,9 @@ comma-separated active-task titles or ids, or \`all\`
41
41
  \`\`\`
42
42
 
43
43
  - \`castle-done\` removes FINISHED rows (done/failed). Use it when the user confirms a task works, or to clear a finished task that has become obsolete (replaced by newer work). \`all\` clears every finished row.
44
- - \`castle-stop\` stops AND removes ACTIVE rows (running/waiting) -- a running task's agent is killed. Use it when the user asks to stop something, or when you spawn a fix/replacement that makes an in-flight task obsolete. \`all\` stops everything active.
45
- - When you spawn a task that fixes, redoes, or replaces an earlier one, remove the earlier one in the SAME reply: \`castle-done\` if it already finished, \`castle-stop\` if it is still running or waiting. Keep the board meaning "what to look at right now".
44
+ - \`castle-stop\` stops AND removes ACTIVE rows (running/waiting/blocked) -- a running task's agent is killed. Use it when the user asks to stop something, or when you spawn a fix/replacement that makes an in-flight task obsolete. \`all\` stops everything active.
45
+ - When you spawn a task that fixes, redoes, or replaces an earlier one, remove the earlier one in the SAME reply: \`castle-done\` if it already finished, \`castle-stop\` if it is still running, waiting, or blocked. Keep the board meaning "what to look at right now".
46
+ - 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.
46
47
  - 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.
47
48
  - Never claim the board is cleared without actually emitting the fence.
48
49
  - Tasks are one-and-done -- when the user gives feedback on a finished task, spawn a new fix task (and \`castle-done\` the old row) rather than reopening it.
@@ -88,7 +89,11 @@ function renderTasks(tasks) {
88
89
  .map((t) => {
89
90
  const notes = t.notes.trim() ? ` -- notes: ${t.notes.trim()}` : "";
90
91
  const files = t.files && t.files.length > 0 ? ` -- files: ${t.files.join(", ")}` : "";
91
- return `- [${t.status} ${t.progress}%] ${t.title} (${t.id})${notes}${files}`;
92
+ const error = t.error ? ` -- error: ${t.error}` : "";
93
+ const blockedBy = t.blockedBy && t.blockedBy.length > 0
94
+ ? ` -- blocked by: ${t.blockedBy.join(", ")}`
95
+ : "";
96
+ return `- [${t.status} ${t.progress}%] ${t.title} (${t.id})${notes}${files}${error}${blockedBy}`;
92
97
  })
93
98
  .join("\n");
94
99
  }
@@ -99,13 +104,17 @@ export function buildRouterPrompt(opts) {
99
104
  const deckFiles = opts.deckTree?.trim()
100
105
  ? `\n\n== deck files ==\n${opts.deckTree.trim()}`
101
106
  : "";
107
+ // Section order is stable-to-volatile for prompt caching: rules + deck
108
+ // identity never change within a serve, the transcript is append-only, and
109
+ // the churning state (file tree, task board, instruction) rides at the tail
110
+ // so a task creating a file doesn't invalidate the cached transcript prefix.
102
111
  return `${ROUTER_RULES}
103
112
 
104
113
  == deck ==
105
- ${opts.deckLabel}${quickReference}${deckFiles}
114
+ ${opts.deckLabel}${quickReference}
106
115
 
107
116
  == conversation so far ==
108
- ${renderTranscript(opts.messages)}
117
+ ${renderTranscript(opts.messages)}${deckFiles}
109
118
 
110
119
  == background tasks ==
111
120
  ${renderTasks(opts.tasks)}
@@ -138,6 +147,15 @@ export function buildTaskPrompt(opts) {
138
147
  const deps = opts.depsSummary
139
148
  ? `\n\nThis task waited on earlier tasks:\n${opts.depsSummary}\n`
140
149
  : "";
150
+ const siblingRows = (opts.siblings ?? [])
151
+ .map((s) => `- [${s.status}] ${s.title}${s.files && s.files.length > 0 ? ` -- files: ${s.files.join(", ")}` : ""}`)
152
+ .join("\n");
153
+ const siblings = siblingRows
154
+ ? `\n\nOther tasks on this deck's board (snapshot at your start):\n${siblingRows}\nRunning and waiting rows are sibling agents working in this same directory. If a sibling plainly owns something your prompt only references (art, a scene, a behavior), leave it to them -- create only what YOUR prompt says to create. Finished rows' file lists show where recent work landed.\n`
155
+ : "";
156
+ const quickReference = opts.quickReference?.trim()
157
+ ? `\n\nHow this deck works (from its docs -- read the full CLAUDE.md / AGENTS.md only when you need detail beyond this):\n\n${opts.quickReference.trim()}\n`
158
+ : "";
141
159
  const layout = opts.deckTree?.trim()
142
160
  ? `\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`
143
161
  : "";
@@ -151,11 +169,11 @@ export function buildTaskPrompt(opts) {
151
169
  const wrapUp = opts.backend === "claude"
152
170
  ? `\n- Wrap up in ONE tool call, not several: once your last file edit is done, combine the 90-progress write, the final \`npm run restart\`, and writing the notes file into a single shell command (\`;\`-separated so the notes land even if the restart hiccups). Then stop -- no extra turns after it.`
153
171
  : "";
154
- return `You are a background build agent for the Castle deck "${opts.deckLabel}" (current directory). A separate conversation agent dispatched you with one task. Follow the deck's CLAUDE.md / AGENTS.md conventions, and reload the served deck after changes (\`npm run restart\`).${layout}
172
+ return `You are a background build agent for the Castle deck "${opts.deckLabel}" (current directory). A separate conversation agent dispatched you with one task. Follow the deck's CLAUDE.md / AGENTS.md conventions, and reload the served deck after changes (\`npm run restart\`).${quickReference}${layout}
155
173
 
156
174
  Your task (id ${opts.taskId}): ${opts.title}
157
175
 
158
- ${opts.prompt}${deps}
176
+ ${opts.prompt}${deps}${siblings}
159
177
 
160
178
  Operating rules:
161
179
  - The file snapshot above is for orientation. Prefer going straight to the files this task touches, but if this is an investigation or debugging task, survey what you need to understand the failure.
package/dist/agent.d.ts CHANGED
@@ -4,6 +4,34 @@ export declare const AGENT_WS_PATH = "/__castle/agent";
4
4
  export declare const AGENT_ATTACHMENT_PREFIX = "/__castle/agent/attachments/";
5
5
  export type AgentBackend = "cursor" | "claude";
6
6
  export type ClaudeModel = "sonnet" | "opus" | "fable";
7
+ type TaskStatus = "waiting" | "running" | "blocked" | "done" | "failed" | "interrupted";
8
+ interface TaskRecord {
9
+ id: string;
10
+ title: string;
11
+ prompt: string;
12
+ after: string[];
13
+ status: TaskStatus;
14
+ progress: number;
15
+ notes: string;
16
+ createdAt: string;
17
+ updatedAt: string;
18
+ startedAt?: string;
19
+ finishedAt?: string;
20
+ pid?: number;
21
+ originMessageId?: string;
22
+ files?: string[];
23
+ resultSummary?: string;
24
+ avatar?: string;
25
+ phase?: string;
26
+ acknowledged?: boolean;
27
+ rejected?: boolean;
28
+ blockedBy?: string[];
29
+ }
30
+ export interface DepsState {
31
+ kind: "ready" | "waiting" | "blocked";
32
+ blockedBy?: string[];
33
+ }
34
+ export declare function classifyDeps(tasks: Map<string, TaskRecord>, task: TaskRecord): DepsState;
7
35
  export interface AgentServer {
8
36
  /** Attach the agent WebSocket if the upgrade targets the agent path. */
9
37
  handleUpgrade(req: http.IncomingMessage, socket: Duplex, head: Buffer): boolean;
@@ -15,3 +43,4 @@ export declare function createAgentServer(opts: {
15
43
  deckDir: string;
16
44
  deckLabel: string;
17
45
  }): AgentServer;
46
+ export {};