castle-web-cli 0.4.203 → 0.4.205
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.
- package/dist/agent-failures.d.ts +3 -1
- package/dist/agent-failures.js +19 -0
- package/dist/agent-prompts.d.ts +1 -0
- package/dist/agent-prompts.js +20 -8
- package/dist/agent.d.ts +5 -2
- package/dist/agent.js +59 -125
- package/dist/castle-host/host.d.ts +17 -0
- package/dist/castle-host/host.js +551 -4
- package/dist/castleJson.d.ts +1 -0
- package/dist/devSessionStorage.js +65 -4
- package/dist/effortSupport.d.ts +7 -0
- package/dist/effortSupport.js +31 -0
- package/dist/init.js +13 -3
- package/dist/platformDoc.js +6 -1
- package/dist/routerFences.d.ts +22 -0
- package/dist/routerFences.js +139 -0
- package/dist/serve.js +35 -2
- package/dist/shell/assets/index-b_bebkRb.css +1 -0
- package/dist/shell/assets/{index-CxrtbzHf.js → index-hWQTC8q6.js} +5 -5
- package/dist/shell/index.html +2 -2
- package/dist/taskAccount.d.ts +13 -0
- package/dist/taskAccount.js +38 -0
- package/dist/vitePlugins.js +19 -1
- package/kits/base/CLAUDE.md +2 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +131 -0
- package/kits/base/sdk/agent.d.ts +6 -0
- package/kits/base/sdk/agent.js +70 -0
- package/kits/base/sdk/castle.d.ts +4 -0
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +106 -0
- package/kits/base/sdk/commands.js +21 -0
- package/kits/base/sdk/decks.d.ts +7 -0
- package/kits/base/sdk/decks.js +31 -0
- package/kits/base/sdk/runtime.d.ts +4 -2
- package/kits/base/sdk/runtime.js +51 -40
- package/kits/base/sdk/server/storage.d.ts +44 -0
- package/kits/base/sdk/server/storage.js +54 -0
- package/kits/base/sdk/transport.d.ts +5 -1
- package/kits/base/sdk/transport.js +106 -23
- package/kits/multiplayer-2d/castle.json +4 -4
- package/kits/multiplayer-2d/code/client/poses.js +7 -0
- package/kits/multiplayer-2d/code/server/limits.js +3 -0
- package/kits/multiplayer-2d/code/server/ownership.js +36 -8
- package/kits/multiplayer-2d/code/systems/multiplayer.js +23 -2
- package/kits/multiplayer-3d/CLAUDE.md +12 -1
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/avatars.js +7 -1
- package/kits/multiplayer-3d/code/client/poses.js +61 -1
- package/kits/multiplayer-3d/code/client/steer.js +383 -0
- package/kits/multiplayer-3d/code/server/limits.js +3 -0
- package/kits/multiplayer-3d/code/server/ownership.js +114 -18
- package/kits/multiplayer-3d/code/server/world.js +12 -4
- package/kits/multiplayer-3d/code/systems/multiplayer.js +315 -34
- package/kits/physics-3d/CLAUDE.md +65 -7
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +916 -15
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
- package/kits/physics-3d/engine3d/artobjects.js +218 -0
- package/kits/physics-3d/engine3d/blob.js +1058 -0
- package/kits/physics-3d/engine3d/branches.js +300 -0
- package/kits/physics-3d/engine3d/cage.js +496 -0
- package/kits/physics-3d/engine3d/cageops.js +516 -0
- package/kits/physics-3d/engine3d/frame.js +669 -0
- package/kits/physics-3d/engine3d/look.js +675 -0
- package/kits/physics-3d/engine3d/materialpresets.js +486 -0
- package/kits/physics-3d/engine3d/modelEditorWorld.js +3 -2
- package/kits/physics-3d/engine3d/modelrefs.js +120 -0
- package/kits/physics-3d/engine3d/motion.js +560 -0
- package/kits/physics-3d/engine3d/objtext.js +37 -0
- package/kits/physics-3d/engine3d/optimize.js +1083 -0
- package/kits/physics-3d/engine3d/paint.js +674 -0
- package/kits/physics-3d/engine3d/partgeometry.js +467 -0
- package/kits/physics-3d/engine3d/paths.js +324 -0
- package/kits/physics-3d/engine3d/pxmodel.js +429 -26
- package/kits/physics-3d/engine3d/scatter.js +102 -0
- package/kits/physics-3d/engine3d/sculpt.js +1148 -0
- package/kits/physics-3d/engine3d/surfacedetail.js +267 -0
- package/kits/physics-3d/engine3d/sweep.js +480 -0
- package/kits/physics-3d/engine3d/thumbnails.js +6 -4
- package/kits/physics-3d/engine3d/world3d.js +119 -17
- package/kits/physics-3d/eslint.config.js +13 -0
- package/kits/physics-3d/models/parts/axe.pxmodel +40 -0
- package/kits/physics-3d/models/parts/backpack.pxmodel +47 -0
- package/kits/physics-3d/models/parts/barrel.pxmodel +22 -0
- package/kits/physics-3d/models/parts/bedroll.pxmodel +28 -0
- package/kits/physics-3d/models/parts/belt-pouch.pxmodel +22 -0
- package/kits/physics-3d/models/parts/bolt.pxmodel +10 -0
- package/kits/physics-3d/models/parts/bracer.pxmodel +26 -0
- package/kits/physics-3d/models/parts/chain-span.pxmodel +12 -0
- package/kits/physics-3d/models/parts/chimney.pxmodel +11 -0
- package/kits/physics-3d/models/parts/crate.pxmodel +44 -0
- package/kits/physics-3d/models/parts/crystal.pxmodel +22 -0
- package/kits/physics-3d/models/parts/door-arched.pxmodel +12 -0
- package/kits/physics-3d/models/parts/engine-block.pxmodel +39 -0
- package/kits/physics-3d/models/parts/exhaust-pipe.pxmodel +30 -0
- package/kits/physics-3d/models/parts/fence-span.pxmodel +10 -0
- package/kits/physics-3d/models/parts/fender.pxmodel +19 -0
- package/kits/physics-3d/models/parts/headlight.pxmodel +24 -0
- package/kits/physics-3d/models/parts/hood.pxmodel +17 -0
- package/kits/physics-3d/models/parts/horned-helmet.pxmodel +37 -0
- package/kits/physics-3d/models/parts/jerry-can.pxmodel +26 -0
- package/kits/physics-3d/models/parts/ladder.pxmodel +10 -0
- package/kits/physics-3d/models/parts/lamp.pxmodel +20 -0
- package/kits/physics-3d/models/parts/lantern.pxmodel +30 -0
- package/kits/physics-3d/models/parts/leaf-cluster.pxmodel +21 -0
- package/kits/physics-3d/models/parts/offroad-tire.pxmodel +48 -0
- package/kits/physics-3d/models/parts/pauldron.pxmodel +26 -0
- package/kits/physics-3d/models/parts/rivet.pxmodel +8 -0
- package/kits/physics-3d/models/parts/rock.pxmodel +21 -0
- package/kits/physics-3d/models/parts/roll-bar-light.pxmodel +26 -0
- package/kits/physics-3d/models/parts/round-shield.pxmodel +31 -0
- package/kits/physics-3d/models/parts/saddlebag.pxmodel +30 -0
- package/kits/physics-3d/models/parts/spoked-wheel.pxmodel +39 -0
- package/kits/physics-3d/models/parts/staff.pxmodel +33 -0
- package/kits/physics-3d/models/parts/stepping-stones.pxmodel +8 -0
- package/kits/physics-3d/models/parts/stone-base.pxmodel +10 -0
- package/kits/physics-3d/models/parts/sword.pxmodel +33 -0
- package/kits/physics-3d/models/parts/window-lit.pxmodel +13 -0
- package/kits/physics-3d/models/parts/wizard-hat.pxmodel +28 -0
- package/kits/physics-3d/models/templates/biped-stout.pxmodel +59 -0
- package/kits/physics-3d/models/templates/biped-tall.pxmodel +63 -0
- package/kits/physics-3d/models/templates/quadruped.pxmodel +52 -0
- package/kits/physics-3d/scripts/render/filmstrip.js +217 -0
- package/kits/physics-3d/scripts/render/index.html +20 -0
- package/kits/physics-3d/scripts/render/sheet.js +411 -0
- package/kits/physics-3d/scripts/render.mjs +646 -0
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/ownership.js +14 -4
- package/kits/real-time/code/client/smooth.js +2 -2
- package/kits/real-time/code/server/session.js +20 -4
- package/package.json +2 -2
- package/dist/shell/assets/index-CHMcsJrW.css +0 -1
package/dist/agent-failures.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type FailureKind = "config" | "limit" | "transient" | "no-work" | "spawn" | "timeout" | "exit";
|
|
2
|
-
export type ConfigReason = "no-key" | "bad-key" | "no-credits" | "model-not-allowed" | "unknown-model" | "no-tools" | "no-endpoints" | "flagged" | "context-length";
|
|
2
|
+
export type ConfigReason = "no-key" | "bad-key" | "no-credits" | "model-not-allowed" | "unknown-model" | "no-tools" | "no-endpoints" | "flagged" | "context-length" | "rejected-parameters";
|
|
3
3
|
export interface AgentFailure {
|
|
4
4
|
kind: FailureKind;
|
|
5
5
|
reason?: ConfigReason;
|
|
@@ -21,6 +21,8 @@ export declare function classifyProviderError(text: string | undefined, model?:
|
|
|
21
21
|
* the error path, which must not fail.
|
|
22
22
|
*/
|
|
23
23
|
export declare function setReaderTimeZone(zone: string): void;
|
|
24
|
+
export declare function failureLabel(failure: AgentFailure): string;
|
|
25
|
+
export declare function routerTaskError(errorLine: string | undefined, failure: string | undefined, errorCopy: string | undefined): string | undefined;
|
|
24
26
|
export declare function failureCopy(opts: {
|
|
25
27
|
failure: AgentFailure;
|
|
26
28
|
spawnedTasks: boolean;
|
package/dist/agent-failures.js
CHANGED
|
@@ -109,6 +109,12 @@ export function failureForStatus(status, body, model) {
|
|
|
109
109
|
if (/model[ _-]?not[ _-]?found|not a valid model|unknown model/i.test(body)) {
|
|
110
110
|
return config("unknown-model");
|
|
111
111
|
}
|
|
112
|
+
// Meta's own sentence, relayed verbatim by OpenRouter, for any parameter
|
|
113
|
+
// its endpoint refuses (seen for effort max on muse-spark-1.3-contributor).
|
|
114
|
+
// Only this exact prose: an unrecognised 400 must stay unclassified.
|
|
115
|
+
if (/The request contains invalid parameters/i.test(body)) {
|
|
116
|
+
return config("rejected-parameters");
|
|
117
|
+
}
|
|
112
118
|
}
|
|
113
119
|
// Unrecognised: leave it unlabelled so the caller keeps its existing
|
|
114
120
|
// behavior rather than inventing a diagnosis.
|
|
@@ -212,10 +218,23 @@ function configCopy(failure) {
|
|
|
212
218
|
return `${model} refused that request. Try rewording it, or switch to a different model in settings.`;
|
|
213
219
|
case "context-length":
|
|
214
220
|
return `That turn got too big for ${model} to hold. Try breaking it into smaller steps, or switch to a model with more room in settings.`;
|
|
221
|
+
case "rejected-parameters":
|
|
222
|
+
return `${model} rejected the request as invalid, so sending the same thing again won't help. Try a different effort level or model in settings, or reach out to Castle.`;
|
|
215
223
|
default:
|
|
216
224
|
return "Something about this session's model setup isn't right. Check the model in settings, or reach out to Castle.";
|
|
217
225
|
}
|
|
218
226
|
}
|
|
227
|
+
export function failureLabel(failure) {
|
|
228
|
+
return failure.reason ? `${failure.kind}/${failure.reason}` : failure.kind;
|
|
229
|
+
}
|
|
230
|
+
// The router reads only a failed task's technical error line, and its standing
|
|
231
|
+
// advice is to spawn a replacement; a config failure would fail the same way
|
|
232
|
+
// again, so its row also carries the copy that says so.
|
|
233
|
+
export function routerTaskError(errorLine, failure, errorCopy) {
|
|
234
|
+
if (!errorLine || !errorCopy || !failure?.startsWith("config"))
|
|
235
|
+
return errorLine;
|
|
236
|
+
return `${errorLine} -- ${errorCopy}`;
|
|
237
|
+
}
|
|
219
238
|
export function failureCopy(opts) {
|
|
220
239
|
if (opts.willRetry) {
|
|
221
240
|
return "Something went wrong on my end -- give me a moment to try that again.";
|
package/dist/agent-prompts.d.ts
CHANGED
package/dist/agent-prompts.js
CHANGED
|
@@ -29,7 +29,7 @@ function baseRouterRules(playtest) {
|
|
|
29
29
|
|
|
30
30
|
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.
|
|
31
31
|
|
|
32
|
-
What the user sees beside this chat: Castle's own panels -- Play, Files, Parameters, Terminal, and this chat -- plus a tab for each file they open. Those panels belong to Castle, and nothing in the deck can change them. A file's tab is different: unless it is the plain code view, it is an EDITOR, an ordinary module that comes from the deck or its kit (this deck's are listed under == editor tabs ==). Users name one by its label ("the <label> tab") or just say "this tab", and they mean that editor, not Castle. When they ask whether a tab can do something it doesn't do yet, or whether it can be changed at all, the answer is yes: a task forks the kit's editor into the deck and changes that copy (see the imports rule below), or gives a new file type an editor of its own. Never tell the user a file's tab is part of Castle.
|
|
32
|
+
What the user sees beside this chat: Castle's own panels -- Play, Files, Parameters, Terminal, and this chat -- plus a tab for each file they open. Those panels belong to Castle, and nothing in the deck can change them. The Parameters panel is where the deck's tunable values live: everything any file exposes as \`PARAMS\`. A file's tab is different: unless it is the plain code view, it is an EDITOR, an ordinary module that comes from the deck or its kit (this deck's are listed under == editor tabs ==). Users name one by its label ("the <label> tab") or just say "this tab", and they mean that editor, not Castle. When they ask whether a tab can do something it doesn't do yet, or whether it can be changed at all, the answer is yes: a task forks the kit's editor into the deck and changes that copy (see the imports rule below), or gives a new file type an editor of its own. Never tell the user a file's tab is part of Castle.
|
|
33
33
|
|
|
34
34
|
Hard rules:
|
|
35
35
|
- You NEVER edit files or run state-changing commands. All building and fixing happens through background task agents -- always hand the longer work to them.
|
|
@@ -38,6 +38,7 @@ Hard rules:
|
|
|
38
38
|
- 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. That brief carries the SYMPTOM, not a cause: the user's own words for what they saw, quoted, plus where the behavior lives when the docs or the conversation name it. You have not read the code, so a mechanism you name is a guess, and a task given a guess implements the guess instead of investigating. A QUESTION is not a fix request: "why is X happening?" gets a task told explicitly to diagnose and CHANGE NOTHING, and your reply says that it will only look and report back.
|
|
39
39
|
- 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.${playtest ? `\n${PLAYTEST_ROUTER_RULE}` : ""}
|
|
40
40
|
- When you point the user at a file, a line, or a tunable value, write it as a link they can tap: \`[label](game.js)\` for a file, \`[label](game.js#L108)\` for a line, \`[label](game.js#params)\` for a file's tunable values and \`[label](game.js#params:enemySpeed)\` for ONE of them (the key exactly as it is written in that file's \`PARAMS\` object -- \`player.speed\` for a nested one). The label is your own words for the thing; the path must be exact and must be a file this deck actually has, or it renders as plain text. A bare \`game.js#108\` in a sentence links too. Cite a line number ONLY when you have read that file with numbered lines -- any deck contents in this prompt carry none, so never count them yourself; link the file or its params instead when you are unsure.
|
|
41
|
+
- When the user asks what they can tune, what controls something, or where to change a value, first see whether that value is already tunable: a key in that file's \`PARAMS\` object, or one of the \`knobs:\` a \`## Built\` line lists. If it is, do not spawn a task to move it -- link that one value with \`#params:key\`. If they asked for it to change, make that change the way any tweak is made, with a task that sets it, and say they can keep adjusting it in the Parameters panel; otherwise tell them they can change it there now. If it is not -- a plain constant or expression in code -- spawn the task that moves it into that file's \`PARAMS\` object, keeping its current value as the default and adding a \`PARAMS_META\` range where one is obvious, and say in your plain-text line that it is going into the Parameters panel, linking that file's \`#params\` where it will land. If they also asked for a new value, the same task sets it. If they asked where it is set, link the file too (the line, if you have read it) -- the move does not replace the answer. Do not just point them at the line. Three different things get called a parameter: an argument a function takes (plain code, nothing to do with the panel); a setting each placed thing carries for itself, so two of them can differ -- the deck's own guide says what those are called and where they are set, and they never go in \`PARAMS\`; and one value for the whole deck that someone tunes while playing, which is the only kind the panel holds. The deciding question is scope: does each one need its own value, or is there one value for everyone? Read that from what they are trying to do; when it is genuinely unclear, ask.
|
|
41
42
|
- 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.
|
|
42
43
|
- Every piece of work should be TESTABLE in actual gameplay. Run tasks 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.
|
|
43
44
|
- 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.sprite\` 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.sprite\` 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.
|
|
@@ -96,6 +97,14 @@ Conversation style:
|
|
|
96
97
|
- 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.
|
|
97
98
|
- The user playtests in the pane beside this chat; finished work shows up there after a reload.`;
|
|
98
99
|
}
|
|
100
|
+
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.`;
|
|
101
|
+
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.`;
|
|
102
|
+
// The q-a2 router arm (prompt-evals t1-router-ladder arms/q-a2.ts), for the
|
|
103
|
+
// decks that opted in (`agent.askCalls` / CASTLE_AGENT_ASK_CALLS -- see
|
|
104
|
+
// askCallsEnabled in agent.ts). Off for everyone by default, so the plan rules
|
|
105
|
+
// stay byte-identical to a prompt built before it existed.
|
|
106
|
+
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.`;
|
|
107
|
+
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. The work spawns either way; the chip only tells the next task which way it went.`;
|
|
99
108
|
// Appended to the rules above for a deck with the plan doc on -- see
|
|
100
109
|
// planSession in agent.ts for which decks those are. One self-contained block,
|
|
101
110
|
// so a deck without it gets the pre-plan prompt byte for byte.
|
|
@@ -104,8 +113,9 @@ Conversation style:
|
|
|
104
113
|
// deliberately supersede rules in the block above (pairing a question with
|
|
105
114
|
// task directives, and holding follow-up questions back), which is why they say
|
|
106
115
|
// so out loud rather than quietly contradicting them.
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
function planRules(askCalls) {
|
|
117
|
+
return `Reading the user, fresh from EACH message -- the same user hands you a spec, then a fragment, then delegates:
|
|
118
|
+
${askCalls ? ASK_CALLS_SPEC_RULE : SPEC_RULE}
|
|
109
119
|
- 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.
|
|
110
120
|
- 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.
|
|
111
121
|
- 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.
|
|
@@ -119,7 +129,7 @@ Probing while you build. A probe is one short plain question plus 2-4 tappable o
|
|
|
119
129
|
|
|
120
130
|
- 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.
|
|
121
131
|
- 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. But NEVER spawn work a pending probe could invalidate: there is no telling a running task anything.
|
|
122
|
-
|
|
132
|
+
${askCalls ? ASK_CALLS_PROBE_CAP_RULE : PROBE_CAP_RULE}
|
|
123
133
|
- 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.
|
|
124
134
|
- 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.
|
|
125
135
|
|
|
@@ -153,9 +163,10 @@ now- food-hauling
|
|
|
153
163
|
Promotion. Finished tasks leave notes worth keeping, listed above with the id of the task that left each. Promote the keepers by quoting the note itself and citing its task; let the rest go -- they are offered once.
|
|
154
164
|
|
|
155
165
|
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.`;
|
|
156
|
-
|
|
166
|
+
}
|
|
167
|
+
function routerRules(plan, playtest, askCalls) {
|
|
157
168
|
const base = baseRouterRules(playtest);
|
|
158
|
-
return plan ? `${base}\n\n${
|
|
169
|
+
return plan ? `${base}\n\n${planRules(askCalls)}` : base;
|
|
159
170
|
}
|
|
160
171
|
function renderTranscriptLine(m) {
|
|
161
172
|
if (m.role === "user")
|
|
@@ -862,7 +873,7 @@ export function buildRouterPromptParts(opts) {
|
|
|
862
873
|
// does not. `user` holds what changes every turn: the transcript, the plan,
|
|
863
874
|
// the board and this instruction.
|
|
864
875
|
return {
|
|
865
|
-
system: `${routerRules(opts.plan !== undefined, opts.playtest === true)}
|
|
876
|
+
system: `${routerRules(opts.plan !== undefined, opts.playtest === true, opts.askCalls === true)}
|
|
866
877
|
|
|
867
878
|
== deck ==
|
|
868
879
|
${opts.deckLabel}${quickReference}${editorTabs}${deckFiles}`,
|
|
@@ -1011,7 +1022,8 @@ phase: wiring the paddle to touch
|
|
|
1011
1022
|
|
|
1012
1023
|
- \`avatar\` -- what you're doing RIGHT NOW, exactly one of: \`thinking\` (figuring out the plan), \`reading\` (looking through files), \`building\` (writing game logic), \`painting\` (making or editing art/visuals), \`playing\` (trying it in the game).
|
|
1013
1024
|
- \`phase\` -- a SHORT, plain-language line for this moment ("wiring the paddle to touch", "drawing the flag"). No file or code names. Update \`avatar\` and \`phase\` together each time your stage changes -- a few times across the task, not every turn. (You may also include \`progress: NN\` here, but the progress file above is the primary progress channel.)
|
|
1014
|
-
- Before finishing, write ${opts.notesPath}: a tiny test guide for the PLAYER -- AT MOST 2-3 bullets (markdown \`- \` lines), each ONE short phrase: what to try and what should happen. NO code, NO API or "integration contract" detail, and no tour of how you built it -- that part is for you, not them. But DO name a file or a value where the user could act on it: a number they might want changed is worth naming, and worth naming the way they would find it, as a link they can tap: "enemy speed -- [spawnRate](game.js#params:spawnRate)" when it is an entry in that file's \`PARAMS\` object, "[the spawn loop](game.js#L42)" for a place in the code (a line number only from a numbered read of the file). Occasionally one bullet may run a little longer, but default to terse. Mention a blocker only if you hit one. The user reads this verbatim to check your work
|
|
1025
|
+
- Before finishing, write ${opts.notesPath}: a tiny test guide for the PLAYER -- AT MOST 2-3 bullets (markdown \`- \` lines), each ONE short phrase: what to try and what should happen. NO code, NO API or "integration contract" detail, and no tour of how you built it -- that part is for you, not them. But DO name a file or a value where the user could act on it: a number they might want changed is worth naming, and worth naming the way they would find it, as a link they can tap: "enemy speed -- [spawnRate](game.js#params:spawnRate)" when it is an entry in that file's \`PARAMS\` object, "[the spawn loop](game.js#L42)" for a place in the code (a line number only from a numbered read of the file). Occasionally one bullet may run a little longer, but default to terse. Mention a blocker only if you hit one. The user reads this verbatim to check your work.
|
|
1026
|
+
- Your final message -- the text after your wrap-up call -- is shown to the user under those notes once the task ends. It is the record of what you did for someone who did not watch the stream, so make it a short plain account: what changed and where (files as tappable links, the same forms as above), the mechanism you chose and why, and any call you made where the brief left a choice. A few sentences or a few short bullets. No signal block, no list of the steps you ran, and do not restate the notes.${wrapUp}
|
|
1015
1027
|
- If you are truly blocked, write the blocker to the notes file and stop rather than guessing wildly.
|
|
1016
1028
|
- Never touch files under .castle/ other than ${opts.plan ? "those three paths" : "those two paths"}. (The version store lives there too, but you never edit it by hand -- \`castle-web save-version\` writes it for you.)`;
|
|
1017
1029
|
}
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type EffortLevel } from './effortSupport.js';
|
|
1
2
|
import * as http from 'http';
|
|
2
3
|
import { Duplex } from 'stream';
|
|
3
4
|
import { type PlaytestToolResult } from './native/playtest.js';
|
|
4
5
|
export declare const AGENT_WS_PATH = "/__castle/agent";
|
|
5
6
|
export type ClaudeModel = 'sonnet' | 'opus' | 'fable' | 'openrouter';
|
|
6
|
-
export type EffortLevel
|
|
7
|
+
export type { EffortLevel };
|
|
7
8
|
interface AgentSettings {
|
|
8
9
|
routerClaudeModel: ClaudeModel;
|
|
9
10
|
tasksClaudeModel: ClaudeModel;
|
|
@@ -46,8 +47,10 @@ interface TaskRecord {
|
|
|
46
47
|
originMessageId?: string;
|
|
47
48
|
playtestFrames?: string[];
|
|
48
49
|
resultSummary?: string;
|
|
50
|
+
account?: string;
|
|
49
51
|
errorCopy?: string;
|
|
50
52
|
errorDetail?: string;
|
|
53
|
+
failure?: string;
|
|
51
54
|
avatar?: string;
|
|
52
55
|
phase?: string;
|
|
53
56
|
acknowledged?: boolean;
|
|
@@ -67,6 +70,7 @@ interface TaskRecord {
|
|
|
67
70
|
usage?: TaskUsage;
|
|
68
71
|
modelUsage?: Record<string, TaskModelUsage>;
|
|
69
72
|
}
|
|
73
|
+
export declare function askCallsEnabled(deckDir: string): boolean;
|
|
70
74
|
export interface DepsState {
|
|
71
75
|
kind: 'ready' | 'waiting' | 'blocked';
|
|
72
76
|
blockedBy?: string[];
|
|
@@ -100,4 +104,3 @@ export declare function createAgentServer(opts: {
|
|
|
100
104
|
restart?: () => void;
|
|
101
105
|
authorizeUpgrade?: (req: http.IncomingMessage, endpoint: 'agent') => boolean;
|
|
102
106
|
}): AgentServer;
|
|
103
|
-
export {};
|
package/dist/agent.js
CHANGED
|
@@ -21,18 +21,21 @@ import { IMPORTS_DIR } from './imports.js';
|
|
|
21
21
|
import { isSameOriginUpgrade } from './wsOrigin.js';
|
|
22
22
|
import { resolveDeckPath } from './ide.js';
|
|
23
23
|
import { lineRange, uniqueLocators } from './deckLocatorShape.js';
|
|
24
|
+
import { supportedEffort } from './effortSupport.js';
|
|
24
25
|
import * as fs from 'fs';
|
|
25
26
|
import * as os from 'os';
|
|
26
27
|
import * as path from 'path';
|
|
27
28
|
import { nanoid } from 'nanoid';
|
|
28
29
|
import { WebSocketServer } from 'ws';
|
|
29
30
|
import { rawDataToString } from './rawData.js';
|
|
31
|
+
import { extractDirectives, meansAll, parseTaskFenceBody, resolveTargets, taskFenceRegex, } from './routerFences.js';
|
|
32
|
+
import { accountForRun, closingMessageOf } from './taskAccount.js';
|
|
30
33
|
import { atomicWriteFileSync } from './atomicFile.js';
|
|
31
34
|
import { AGENT_ATTACHMENT_PREFIX, AGENT_PLAYTEST_PREFIX, PLAN_FILE } from './localPaths.js';
|
|
32
35
|
import { applyPlanOps, buildRouterPromptParts, buildTaskPrompt, parsePlanOps, planOpenQuestionLines, truncateToBytes, userTurnInstruction, CLAUDE_TASK_SYSTEM_REMINDER, modelTaskAddendum, isMuseModel, } from './agent-prompts.js';
|
|
33
36
|
import { readCastleJson } from './castleJson.js';
|
|
34
37
|
import { checkOpenrouterKey, checkOpenrouterModel, primeOpenrouterCatalog, } from './openrouter-catalog.js';
|
|
35
|
-
import { classifyProviderError, failureCopy, setReaderTimeZone, } from './agent-failures.js';
|
|
38
|
+
import { classifyProviderError, failureCopy, failureLabel, routerTaskError, setReaderTimeZone, } from './agent-failures.js';
|
|
36
39
|
import { castleCreditsExhausted, createBudgetRefreshRetry, createRefreshQueue, fetchAiCredits, fetchBudget, freeRolesFor, freeTierForRoles, meteringHeaders, modelIsFree, newAgentSessionId, spendableMicros, withCustomHeaders, } from './metering.js';
|
|
37
40
|
import { anthropicKeyHelperCommand, resolveAnthropicAuth, userKey, ANTHROPIC_CREDENTIAL_ENV, ANTHROPIC_PROXY_ENV, CASTLE_USER_KEYS_PATH, } from './byo-auth.js';
|
|
38
41
|
import { accountsSnapshot, loginProviderFor, watchCredentials, writeCredential, } from './byo-accounts.js';
|
|
@@ -382,6 +385,11 @@ function claudeSettingsArg(auth) {
|
|
|
382
385
|
function spawnModelFor(claudeModel, openrouterModel) {
|
|
383
386
|
return claudeModel === 'openrouter' ? openrouterModel : claudeModel;
|
|
384
387
|
}
|
|
388
|
+
// Like the model, the effort a task records is the one it was spawned at, which
|
|
389
|
+
// differs from the stored setting when the model refuses that level.
|
|
390
|
+
function spawnEffortFor(claudeModel, openrouterModel, effort) {
|
|
391
|
+
return claudeModel === 'openrouter' ? supportedEffort(openrouterModel, effort) : effort;
|
|
392
|
+
}
|
|
385
393
|
// The only harness left (the native loop is dormant), recorded on both the run
|
|
386
394
|
// log header and the task so a second one would read as a different value.
|
|
387
395
|
const AGENT_BACKEND = 'claude';
|
|
@@ -400,6 +408,7 @@ taskId,
|
|
|
400
408
|
systemPrompt) {
|
|
401
409
|
const viaOpenrouter = claudeModel === 'openrouter';
|
|
402
410
|
const spawnModel = spawnModelFor(claudeModel, openrouterModel);
|
|
411
|
+
const spawnEffort = spawnEffortFor(claudeModel, openrouterModel, effort);
|
|
403
412
|
const systemText = [systemPrompt, role === 'task' ? CLAUDE_TASK_SYSTEM_REMINDER : undefined, role === 'task' ? modelTaskAddendum(spawnModel) : undefined]
|
|
404
413
|
.filter((text) => Boolean(text))
|
|
405
414
|
.join('\n\n');
|
|
@@ -413,6 +422,7 @@ systemPrompt) {
|
|
|
413
422
|
return {
|
|
414
423
|
command: 'claude',
|
|
415
424
|
model: spawnModel,
|
|
425
|
+
effort: spawnEffort,
|
|
416
426
|
systemText,
|
|
417
427
|
args: [
|
|
418
428
|
'-p',
|
|
@@ -426,7 +436,7 @@ systemPrompt) {
|
|
|
426
436
|
'--model',
|
|
427
437
|
spawnModel,
|
|
428
438
|
'--effort',
|
|
429
|
-
|
|
439
|
+
spawnEffort,
|
|
430
440
|
// Newer claude models default thinking display to "omitted" (empty
|
|
431
441
|
// thinking_delta text, signature only); "summarized" restores actual
|
|
432
442
|
// summary text so the shell's expandable thinking transcript has
|
|
@@ -528,90 +538,6 @@ function visibleLength(raw) {
|
|
|
528
538
|
}
|
|
529
539
|
return raw.length;
|
|
530
540
|
}
|
|
531
|
-
// Parse one ```castle-task fence's body (title line, optional "after:" and
|
|
532
|
-
// "item:" lines in either order, then the prompt) into a directive. Shared by
|
|
533
|
-
// the settle-time full-text extraction below and the mid-stream incremental
|
|
534
|
-
// scanner (runRouterTurnIn), so a fence spawned early behaves identically to
|
|
535
|
-
// one spawned at settle.
|
|
536
|
-
function parseTaskFenceBody(body) {
|
|
537
|
-
const lines = body.replace(/\r/g, '').split('\n');
|
|
538
|
-
const title = (lines.shift() ?? '').trim();
|
|
539
|
-
if (!title)
|
|
540
|
-
return null;
|
|
541
|
-
const after = [];
|
|
542
|
-
let item;
|
|
543
|
-
while (lines.length > 0) {
|
|
544
|
-
const headerMatch = /^(after|item):\s*(.*)$/i.exec((lines[0] ?? '').trim());
|
|
545
|
-
if (!headerMatch)
|
|
546
|
-
break;
|
|
547
|
-
lines.shift();
|
|
548
|
-
if (headerMatch[1].toLowerCase() === 'item') {
|
|
549
|
-
const label = headerMatch[2].trim();
|
|
550
|
-
// `item: -` is the fence saying "chore, no plan item" -- an answer, not
|
|
551
|
-
// an omission, so it lands the same as no line at all.
|
|
552
|
-
if (label && label !== '-')
|
|
553
|
-
item = label;
|
|
554
|
-
continue;
|
|
555
|
-
}
|
|
556
|
-
after.push(...headerMatch[2]
|
|
557
|
-
.split(',')
|
|
558
|
-
.map((s) => s.trim())
|
|
559
|
-
.filter(Boolean));
|
|
560
|
-
}
|
|
561
|
-
return { title, after, item, prompt: lines.join('\n').trim() };
|
|
562
|
-
}
|
|
563
|
-
// A fresh RegExp per call -- this is matched with manual .exec() loops in
|
|
564
|
-
// TWO independent call sites (settle-time extractDirectives via .replace, and
|
|
565
|
-
// the mid-stream scanNewTaskFences via a lastIndex-seeded loop) that must
|
|
566
|
-
// never share mutable lastIndex state.
|
|
567
|
-
function taskFenceRegex() {
|
|
568
|
-
return /```castle-task[ \t]*\r?\n([\s\S]*?)```/g;
|
|
569
|
-
}
|
|
570
|
-
// Take the body of a ```castle-plan fence out of a router reply: the ops it
|
|
571
|
-
// wants applied to plan.md. A reply emitting more than one is stating more ops,
|
|
572
|
-
// so the bodies concatenate in order. Returns the reply with every such fence
|
|
573
|
-
// removed.
|
|
574
|
-
function takePlanFence(source) {
|
|
575
|
-
const bodies = [];
|
|
576
|
-
const rest = source.replace(/```castle-plan[ \t]*\r?\n([\s\S]*?)```/g, (_match, body) => {
|
|
577
|
-
bodies.push(String(body));
|
|
578
|
-
return '';
|
|
579
|
-
});
|
|
580
|
-
return { plan: bodies.length > 0 ? bodies.join('\n') : undefined, rest };
|
|
581
|
-
}
|
|
582
|
-
// Pull ```castle-task fenced directives out of a finished router reply.
|
|
583
|
-
// Block format: title line, then an optional "after:" line, then the prompt.
|
|
584
|
-
function extractDirectives(full) {
|
|
585
|
-
const directives = [];
|
|
586
|
-
const checkoffs = [];
|
|
587
|
-
const stops = [];
|
|
588
|
-
const listFence = (source, name, into) => {
|
|
589
|
-
const re = new RegExp('```' + name + '[ \\t]*\\r?\\n([\\s\\S]*?)```', 'g');
|
|
590
|
-
return source.replace(re, (_match, body) => {
|
|
591
|
-
for (const token of String(body).split(/[,\n]/)) {
|
|
592
|
-
const trimmed = token.trim();
|
|
593
|
-
if (trimmed)
|
|
594
|
-
into.push(trimmed);
|
|
595
|
-
}
|
|
596
|
-
return '';
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
const { plan, rest } = takePlanFence(full);
|
|
600
|
-
const withoutDone = listFence(listFence(rest, 'castle-done', checkoffs), 'castle-stop', stops);
|
|
601
|
-
const cleaned = withoutDone.replace(taskFenceRegex(), (_match, body) => {
|
|
602
|
-
const directive = parseTaskFenceBody(String(body));
|
|
603
|
-
if (directive)
|
|
604
|
-
directives.push(directive);
|
|
605
|
-
return '';
|
|
606
|
-
});
|
|
607
|
-
return {
|
|
608
|
-
cleaned: cleaned.replace(/\n{3,}/g, '\n\n').trim(),
|
|
609
|
-
directives,
|
|
610
|
-
checkoffs,
|
|
611
|
-
stops,
|
|
612
|
-
plan,
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
541
|
const planSessions = new Map();
|
|
616
542
|
// What a deck that says nothing gets. On unless the serve was explicitly told
|
|
617
543
|
// otherwise -- `CASTLE_AGENT_PLAN=off` is what the agent-qa harness uses to keep
|
|
@@ -640,6 +566,23 @@ function planSession(deckDir) {
|
|
|
640
566
|
planSessions.set(deckDir, session);
|
|
641
567
|
return session;
|
|
642
568
|
}
|
|
569
|
+
const askCallsSessions = new Map();
|
|
570
|
+
// The inverse of planDefault: dormant until someone asks for it.
|
|
571
|
+
function askCallsDefault() {
|
|
572
|
+
return process.env.CASTLE_AGENT_ASK_CALLS === 'on';
|
|
573
|
+
}
|
|
574
|
+
// Resolved once per deck and cached for the reason planSession is: it decides
|
|
575
|
+
// what sits in the prompt's cached prefix, so honoring a mid-session change
|
|
576
|
+
// would split the prompt cache. Changing it takes a serve restart.
|
|
577
|
+
export function askCallsEnabled(deckDir) {
|
|
578
|
+
const cached = askCallsSessions.get(deckDir);
|
|
579
|
+
if (cached !== undefined)
|
|
580
|
+
return cached;
|
|
581
|
+
const declared = readCastleJson(deckDir)?.agent?.askCalls;
|
|
582
|
+
const enabled = declared === 'on' ? true : declared === 'off' ? false : askCallsDefault();
|
|
583
|
+
askCallsSessions.set(deckDir, enabled);
|
|
584
|
+
return enabled;
|
|
585
|
+
}
|
|
643
586
|
function readPlanSnapshot(deckDir) {
|
|
644
587
|
let raw;
|
|
645
588
|
try {
|
|
@@ -1118,6 +1061,7 @@ function createAgentStreamState() {
|
|
|
1118
1061
|
return {
|
|
1119
1062
|
accumulated: '',
|
|
1120
1063
|
finalText: '',
|
|
1064
|
+
finalTextFromResult: false,
|
|
1121
1065
|
resultIsError: false,
|
|
1122
1066
|
usage: undefined,
|
|
1123
1067
|
stats: undefined,
|
|
@@ -1304,7 +1248,9 @@ function makeAgentEventHandler(opts, state) {
|
|
|
1304
1248
|
// return their blocks as `text, thinking` (gemini through OpenRouter's
|
|
1305
1249
|
// anthropic-compatible endpoint) end the turn on an empty thinking block,
|
|
1306
1250
|
// and the CLI reports `result: ""` even though the answer streamed fine.
|
|
1307
|
-
|
|
1251
|
+
const closing = closingMessageOf(ev.result, state.accumulated);
|
|
1252
|
+
state.finalText = closing.finalText;
|
|
1253
|
+
state.finalTextFromResult = closing.fromResult;
|
|
1308
1254
|
state.resultIsError = ev.is_error === true;
|
|
1309
1255
|
state.usage = parseCliUsage(ev.usage);
|
|
1310
1256
|
state.stats = parseCliRunStats(ev);
|
|
@@ -1499,6 +1445,7 @@ function runAgentCli(opts) {
|
|
|
1499
1445
|
settle({
|
|
1500
1446
|
ok,
|
|
1501
1447
|
finalText: state.finalText || state.accumulated,
|
|
1448
|
+
finalTextFromResult: state.finalTextFromResult,
|
|
1502
1449
|
usage: state.usage,
|
|
1503
1450
|
stats: state.stats,
|
|
1504
1451
|
crashed: !state.sawResult,
|
|
@@ -1857,7 +1804,7 @@ async function runAgentTurn(opts) {
|
|
|
1857
1804
|
sessionId,
|
|
1858
1805
|
backend: AGENT_BACKEND,
|
|
1859
1806
|
model: invocation.model,
|
|
1860
|
-
effort:
|
|
1807
|
+
effort: invocation.effort,
|
|
1861
1808
|
systemPrompt: invocation.systemText || undefined,
|
|
1862
1809
|
prompt: opts.prompt,
|
|
1863
1810
|
},
|
|
@@ -1934,8 +1881,8 @@ function writeTaskIndex(tasksDir, tasks) {
|
|
|
1934
1881
|
// board (blockedBy intact) until the router stops it, same as before restart.
|
|
1935
1882
|
const TASK_STATUSES = ['waiting', 'running', 'blocked', 'done', 'failed', 'interrupted'];
|
|
1936
1883
|
const TASK_OPTIONAL_STRINGS = [
|
|
1937
|
-
'item', 'startedAt', 'finishedAt', 'originMessageId', 'resultSummary', 'errorCopy',
|
|
1938
|
-
'errorDetail', 'avatar', 'phase', 'durable', 'what', 'model', 'backend',
|
|
1884
|
+
'item', 'startedAt', 'finishedAt', 'originMessageId', 'resultSummary', 'account', 'errorCopy',
|
|
1885
|
+
'errorDetail', 'failure', 'avatar', 'phase', 'durable', 'what', 'model', 'backend',
|
|
1939
1886
|
];
|
|
1940
1887
|
const TASK_OPTIONAL_NUMBERS = ['pid', 'costUsd', 'durationApiMs', 'numTurns'];
|
|
1941
1888
|
const TASK_OPTIONAL_OBJECTS = ['usage', 'modelUsage'];
|
|
@@ -2106,24 +2053,6 @@ function refreshTaskFiles(tasksDir, task) {
|
|
|
2106
2053
|
changed = true;
|
|
2107
2054
|
return changed;
|
|
2108
2055
|
}
|
|
2109
|
-
// "after:" entries may reference task ids or titles -- including titles of
|
|
2110
|
-
// tasks spawned earlier in the same reply (spawn order follows block order).
|
|
2111
|
-
function resolveDeps(tasks, tokens) {
|
|
2112
|
-
const resolved = [];
|
|
2113
|
-
for (const token of tokens) {
|
|
2114
|
-
if (tasks.has(token)) {
|
|
2115
|
-
resolved.push(token);
|
|
2116
|
-
continue;
|
|
2117
|
-
}
|
|
2118
|
-
const byTitle = [...tasks.values()]
|
|
2119
|
-
.sort((a, b) => a.createdAt.localeCompare(b.createdAt))
|
|
2120
|
-
.filter((t) => t.title.toLowerCase() === token.toLowerCase());
|
|
2121
|
-
const last = byTitle[byTitle.length - 1];
|
|
2122
|
-
if (last)
|
|
2123
|
-
resolved.push(last.id);
|
|
2124
|
-
}
|
|
2125
|
-
return [...new Set(resolved)];
|
|
2126
|
-
}
|
|
2127
2056
|
export function classifyDeps(tasks, task) {
|
|
2128
2057
|
const blockedBy = [];
|
|
2129
2058
|
let waiting = false;
|
|
@@ -2331,7 +2260,7 @@ function startTask(ctx, task) {
|
|
|
2331
2260
|
task.startedAt = nowIso();
|
|
2332
2261
|
task.model = spawnModelFor(claudeModel, openrouterModel);
|
|
2333
2262
|
task.backend = AGENT_BACKEND;
|
|
2334
|
-
task.effort = effort;
|
|
2263
|
+
task.effort = spawnEffortFor(claudeModel, openrouterModel, effort);
|
|
2335
2264
|
ctx.touch(task);
|
|
2336
2265
|
ctx.onStarted(task);
|
|
2337
2266
|
const runCtx = {
|
|
@@ -2399,6 +2328,12 @@ function startTask(ctx, task) {
|
|
|
2399
2328
|
: result.ok
|
|
2400
2329
|
? result.finalText.slice(-RESULT_SUMMARY_CHARS)
|
|
2401
2330
|
: `${result.error ?? 'failed'}\n${result.finalText.slice(-RESULT_SUMMARY_CHARS)}`;
|
|
2331
|
+
task.account = accountForRun({
|
|
2332
|
+
ok: result.ok,
|
|
2333
|
+
stopped: wasStopped,
|
|
2334
|
+
finalText: result.finalText,
|
|
2335
|
+
finalTextFromResult: result.finalTextFromResult === true,
|
|
2336
|
+
});
|
|
2402
2337
|
if (!wasStopped && !result.ok) {
|
|
2403
2338
|
const failure = resolveFailure(result);
|
|
2404
2339
|
// spawnedTasks/willRetry are router-turn concepts; a task card has
|
|
@@ -2409,8 +2344,8 @@ function startTask(ctx, task) {
|
|
|
2409
2344
|
willRetry: false,
|
|
2410
2345
|
});
|
|
2411
2346
|
task.errorDetail = failure.detail || result.error;
|
|
2412
|
-
|
|
2413
|
-
console.error(`[task ${task.id}] failed (${
|
|
2347
|
+
task.failure = failureLabel(failure);
|
|
2348
|
+
console.error(`[task ${task.id}] failed (${task.failure}): ${failure.verbose ?? task.errorDetail}`);
|
|
2414
2349
|
}
|
|
2415
2350
|
ctx.touch(task);
|
|
2416
2351
|
}
|
|
@@ -2567,7 +2502,7 @@ function createTaskStore(opts) {
|
|
|
2567
2502
|
id: nanoid(8),
|
|
2568
2503
|
title: directive.title,
|
|
2569
2504
|
prompt: directive.prompt,
|
|
2570
|
-
after:
|
|
2505
|
+
after: resolveTargets(tasks, directive.after),
|
|
2571
2506
|
item: directive.item,
|
|
2572
2507
|
status: 'waiting',
|
|
2573
2508
|
progress: 0,
|
|
@@ -2628,17 +2563,12 @@ function createTaskStore(opts) {
|
|
|
2628
2563
|
}
|
|
2629
2564
|
writeTaskIndex(tasksDir, tasks);
|
|
2630
2565
|
}
|
|
2631
|
-
// True when a fence body is the special token "all" / "*" (clear/stop
|
|
2632
|
-
// everything, no per-task enumeration).
|
|
2633
|
-
function meansAll(tokens) {
|
|
2634
|
-
return tokens.some((t) => t.toLowerCase() === 'all' || t === '*');
|
|
2635
|
-
}
|
|
2636
2566
|
// The router checks finished tasks off by title or id (castle-done fence),
|
|
2637
2567
|
// or "all" to clear every finished row off the board at once.
|
|
2638
2568
|
function checkOff(tokens) {
|
|
2639
2569
|
const ids = meansAll(tokens)
|
|
2640
2570
|
? [...tasks.values()].filter((t) => isTerminal(t.status) && !t.acknowledged).map((t) => t.id)
|
|
2641
|
-
:
|
|
2571
|
+
: resolveTargets(tasks, tokens);
|
|
2642
2572
|
for (const id of ids)
|
|
2643
2573
|
acknowledge(id, false);
|
|
2644
2574
|
}
|
|
@@ -2652,7 +2582,7 @@ function createTaskStore(opts) {
|
|
|
2652
2582
|
? [...tasks.values()]
|
|
2653
2583
|
.filter((t) => t.status === 'running' || t.status === 'waiting' || t.status === 'blocked')
|
|
2654
2584
|
.map((t) => t.id)
|
|
2655
|
-
:
|
|
2585
|
+
: resolveTargets(tasks, tokens);
|
|
2656
2586
|
for (const id of ids) {
|
|
2657
2587
|
const task = tasks.get(id);
|
|
2658
2588
|
if (task)
|
|
@@ -2845,7 +2775,9 @@ function asPromptTask(task) {
|
|
|
2845
2775
|
progress: task.progress,
|
|
2846
2776
|
notes: task.notes,
|
|
2847
2777
|
item: task.item,
|
|
2848
|
-
error: task.status === 'failed'
|
|
2778
|
+
error: task.status === 'failed'
|
|
2779
|
+
? routerTaskError(firstErrorLine(task.resultSummary), task.failure, task.errorCopy)
|
|
2780
|
+
: undefined,
|
|
2849
2781
|
blockedBy: task.status === 'blocked' ? task.blockedBy : undefined,
|
|
2850
2782
|
};
|
|
2851
2783
|
}
|
|
@@ -2860,6 +2792,7 @@ function asClientTask(task, signPath) {
|
|
|
2860
2792
|
startedAt: task.startedAt,
|
|
2861
2793
|
finishedAt: task.finishedAt,
|
|
2862
2794
|
resultSummary: task.resultSummary,
|
|
2795
|
+
account: task.account,
|
|
2863
2796
|
avatar: task.avatar,
|
|
2864
2797
|
phase: task.phase,
|
|
2865
2798
|
acknowledged: task.acknowledged,
|
|
@@ -3088,6 +3021,7 @@ function routerTurnPrompt(ctx, instruction, selfMessageId, plan) {
|
|
|
3088
3021
|
editorTabs: editorTabsFor(ctx.deckDir),
|
|
3089
3022
|
deckTree: buildDeckTree(ctx.deckDir),
|
|
3090
3023
|
playtest: playtestSteering(),
|
|
3024
|
+
askCalls: askCallsEnabled(ctx.deckDir),
|
|
3091
3025
|
messages: ctx.log.messages
|
|
3092
3026
|
.filter((m) => m.role !== 'log' && m.id !== selfMessageId && m.status !== 'streaming')
|
|
3093
3027
|
.map((m) => ({
|
|
@@ -3328,8 +3262,7 @@ function runRouterTurnIn(ctx, instruction) {
|
|
|
3328
3262
|
message.status = 'error';
|
|
3329
3263
|
message.errorDetail = failure.detail || result.error || 'unknown failure';
|
|
3330
3264
|
errorVerbose = failure.verbose;
|
|
3331
|
-
|
|
3332
|
-
console.error(`[router] turn failed (${label}): ${failure.verbose ?? message.errorDetail}`);
|
|
3265
|
+
console.error(`[router] turn failed (${failureLabel(failure)}): ${failure.verbose ?? message.errorDetail}`);
|
|
3333
3266
|
}
|
|
3334
3267
|
if (taskIds.length > 0)
|
|
3335
3268
|
message.taskIds = taskIds;
|
|
@@ -4012,9 +3945,10 @@ export function createAgentServer(opts) {
|
|
|
4012
3945
|
const attachmentsDir = path.join(agentDir, 'attachments');
|
|
4013
3946
|
const messagesPath = path.join(agentDir, 'messages.json');
|
|
4014
3947
|
fs.mkdirSync(tasksDir, { recursive: true });
|
|
4015
|
-
// Read the
|
|
4016
|
-
// planSession.
|
|
3948
|
+
// Read the prompt switches this deck declares now, so the whole serve shares
|
|
3949
|
+
// one answer for each -- see planSession and askCallsEnabled.
|
|
4017
3950
|
planSession(deckDir);
|
|
3951
|
+
askCallsEnabled(deckDir);
|
|
4018
3952
|
// Warm the OpenRouter catalog now so the first pre-flight and the first
|
|
4019
3953
|
// popover open read a cache instead of paying for the fetch. Fire-and-forget
|
|
4020
3954
|
// by design -- nothing here depends on it, and it falls open if it fails.
|
|
@@ -4144,7 +4078,7 @@ export function createAgentServer(opts) {
|
|
|
4144
4078
|
function handleTaskAck(id, rejected) {
|
|
4145
4079
|
taskStore.acknowledge(id, rejected);
|
|
4146
4080
|
}
|
|
4147
|
-
// `after` goes through the same
|
|
4081
|
+
// `after` goes through the same resolveTargets the router's fences use, so a
|
|
4148
4082
|
// caller may name an upstream by id or by title and gets the real dependency
|
|
4149
4083
|
// path -- waiting, blocked, and the upstream summaries in the task prompt.
|
|
4150
4084
|
function handleSpawnTask(socket, msg) {
|
|
@@ -40,6 +40,7 @@ export type PlatformHandler = (
|
|
|
40
40
|
export interface HostCapabilities {
|
|
41
41
|
graphqlFetch: GraphqlFetch;
|
|
42
42
|
platformHandler?: PlatformHandler;
|
|
43
|
+
oracleStream?: OracleStream;
|
|
43
44
|
localPassGrant?: (passId: string) => boolean;
|
|
44
45
|
showLeaderboard?: (payload: CastleLeaderboardPayload) => void;
|
|
45
46
|
canShowLeaderboard?: () => boolean;
|
|
@@ -52,6 +53,21 @@ export interface HostCapabilities {
|
|
|
52
53
|
) => Promise<MultiplayerGetSessionResult>;
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
export type OracleStream = (url: string, body: string, sink: OracleStreamSink) => () => void;
|
|
57
|
+
|
|
58
|
+
export interface OracleStreamSink {
|
|
59
|
+
event(name: string, data: string): void;
|
|
60
|
+
end(): void;
|
|
61
|
+
fail(status: number, text: string): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CommandOptions {
|
|
65
|
+
onStream?: (event: unknown) => void;
|
|
66
|
+
signal?: AbortSignal;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function fetchOracleStream(getToken: () => string | null | undefined): OracleStream;
|
|
70
|
+
|
|
55
71
|
export interface MultiplayerGetSessionParams {
|
|
56
72
|
mode: 'named' | 'party' | 'public';
|
|
57
73
|
key?: string | null;
|
|
@@ -91,4 +107,5 @@ export function executeCommand(
|
|
|
91
107
|
command: unknown,
|
|
92
108
|
params: unknown,
|
|
93
109
|
capabilities: HostCapabilities,
|
|
110
|
+
options?: CommandOptions,
|
|
94
111
|
): Promise<HostResult>;
|