castle-web-cli 0.4.190 → 0.4.191
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-prompts.d.ts +3 -0
- package/dist/agent-prompts.js +10 -0
- package/dist/agent.d.ts +3 -0
- package/dist/agent.js +84 -10
- package/dist/shell/assets/{index-Bo8dx2Ps.js → index-6eWEUoBA.js} +1 -1
- package/dist/shell/assets/index-D6leLNUq.css +1 -0
- package/dist/shell/index.html +2 -2
- package/package.json +1 -1
- package/dist/shell/assets/index-DrFIFZVh.css +0 -1
package/dist/agent-prompts.d.ts
CHANGED
|
@@ -121,3 +121,6 @@ export declare function buildTaskPrompt(opts: {
|
|
|
121
121
|
playtest?: boolean;
|
|
122
122
|
}): string;
|
|
123
123
|
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.";
|
|
124
|
+
export declare const MUSE_TASK_ADDENDUM = "Kit code rules for this deck. The kit guide documents every API you need; use exactly the names and signatures it gives and nothing else. Do not guess at APIs: no typeof checks on methods, no ?. or ?? fallbacks on documented objects, no try/catch around ordinary calls, no alternate spellings of a callback. One mechanism per feature, chosen for what the task asks (a tap on the actor is its onTap; a tap anywhere on the card is the pointer checked in update; a contact is onCollisionEnter): use that one and never also scan for the same event another way. Props come from defaultProps, so never repeat a default with ?? value. Find actors by the behavior or id the task names; never sniff ids like 'player' or 'ball' as fallbacks. Read the guide's gotchas for every API you use and follow them. Reference only files that exist in the deck tree or that you create in this task. Build everything the task names and only that: no extra input methods, actors, or polish it did not mention.";
|
|
125
|
+
export declare function isMuseModel(model: string): boolean;
|
|
126
|
+
export declare function modelTaskAddendum(model: string): string | undefined;
|
package/dist/agent-prompts.js
CHANGED
|
@@ -1001,3 +1001,13 @@ phase: wiring the paddle to touch
|
|
|
1001
1001
|
// Appended to claude task agents' system prompt (portable replacement for the
|
|
1002
1002
|
// machine-specific /goal slash command): commit to autonomous completion.
|
|
1003
1003
|
export 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.";
|
|
1004
|
+
// Meta's muse models hedge on uncertain kit APIs with typeof probes, several
|
|
1005
|
+
// callback spellings, and per-frame scans beside callbacks. These rules apply to
|
|
1006
|
+
// muse task agents only; other models are untouched.
|
|
1007
|
+
export const MUSE_TASK_ADDENDUM = "Kit code rules for this deck. The kit guide documents every API you need; use exactly the names and signatures it gives and nothing else. Do not guess at APIs: no typeof checks on methods, no ?. or ?? fallbacks on documented objects, no try/catch around ordinary calls, no alternate spellings of a callback. One mechanism per feature, chosen for what the task asks (a tap on the actor is its onTap; a tap anywhere on the card is the pointer checked in update; a contact is onCollisionEnter): use that one and never also scan for the same event another way. Props come from defaultProps, so never repeat a default with ?? value. Find actors by the behavior or id the task names; never sniff ids like 'player' or 'ball' as fallbacks. Read the guide's gotchas for every API you use and follow them. Reference only files that exist in the deck tree or that you create in this task. Build everything the task names and only that: no extra input methods, actors, or polish it did not mention.";
|
|
1008
|
+
export function isMuseModel(model) {
|
|
1009
|
+
return /muse/i.test(model);
|
|
1010
|
+
}
|
|
1011
|
+
export function modelTaskAddendum(model) {
|
|
1012
|
+
return isMuseModel(model) ? MUSE_TASK_ADDENDUM : undefined;
|
|
1013
|
+
}
|
package/dist/agent.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ import { Duplex } from 'stream';
|
|
|
3
3
|
import { type PlaytestToolResult } from './native/playtest.js';
|
|
4
4
|
export declare const AGENT_WS_PATH = "/__castle/agent";
|
|
5
5
|
export type ClaudeModel = 'sonnet' | 'opus' | 'fable' | 'openrouter';
|
|
6
|
+
export type EffortLevel = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
6
7
|
interface AgentSettings {
|
|
7
8
|
routerClaudeModel: ClaudeModel;
|
|
8
9
|
tasksClaudeModel: ClaudeModel;
|
|
9
10
|
routerOpenrouterModel: string;
|
|
10
11
|
tasksOpenrouterModel: string;
|
|
12
|
+
routerEffort: EffortLevel;
|
|
13
|
+
tasksEffort: EffortLevel;
|
|
11
14
|
}
|
|
12
15
|
type OpenrouterSlugKey = 'routerOpenrouterModel' | 'tasksOpenrouterModel';
|
|
13
16
|
type SettingsWarnings = Partial<Record<OpenrouterSlugKey, {
|
package/dist/agent.js
CHANGED
|
@@ -27,7 +27,7 @@ import { WebSocketServer } from 'ws';
|
|
|
27
27
|
import { rawDataToString } from './rawData.js';
|
|
28
28
|
import { atomicWriteFileSync } from './atomicFile.js';
|
|
29
29
|
import { AGENT_ATTACHMENT_PREFIX, AGENT_PLAYTEST_PREFIX, PLAN_FILE } from './localPaths.js';
|
|
30
|
-
import { applyPlanOps, buildRouterPromptParts, buildTaskPrompt, parsePlanOps, planOpenQuestionLines, truncateToBytes, userTurnInstruction, CLAUDE_TASK_SYSTEM_REMINDER, } from './agent-prompts.js';
|
|
30
|
+
import { applyPlanOps, buildRouterPromptParts, buildTaskPrompt, parsePlanOps, planOpenQuestionLines, truncateToBytes, userTurnInstruction, CLAUDE_TASK_SYSTEM_REMINDER, modelTaskAddendum, isMuseModel, } from './agent-prompts.js';
|
|
31
31
|
import { readCastleJson } from './castleJson.js';
|
|
32
32
|
import { checkOpenrouterKey, checkOpenrouterModel, primeOpenrouterCatalog, } from './openrouter-catalog.js';
|
|
33
33
|
import { classifyProviderError, failureCopy, setReaderTimeZone, } from './agent-failures.js';
|
|
@@ -55,6 +55,8 @@ const DEFAULT_SETTINGS = {
|
|
|
55
55
|
// castleSpendRefusal. Picking any other slug puts that role back on credits.
|
|
56
56
|
routerOpenrouterModel: 'meta/muse-spark-1.3-contributor',
|
|
57
57
|
tasksOpenrouterModel: 'meta/muse-spark-1.3-contributor',
|
|
58
|
+
routerEffort: 'medium',
|
|
59
|
+
tasksEffort: 'medium',
|
|
58
60
|
};
|
|
59
61
|
// What the two claude-model defaults become once the user has an Anthropic
|
|
60
62
|
// credential of their own -- a key or a claude.ai login, which
|
|
@@ -70,10 +72,26 @@ const ANTHROPIC_DEFAULT_MODELS = {
|
|
|
70
72
|
// appears and disappears mid-session (the Accounts modal, `claude /login` in
|
|
71
73
|
// the terminal panel, a hand-edited user-keys.json), and
|
|
72
74
|
// refreshDefaultedSettings re-reads it when it does.
|
|
75
|
+
// The effort a role starts at for a given model. Tasks on a muse model start
|
|
76
|
+
// at low: castle-agent-evals/muse-tune measured medium as slower with more api
|
|
77
|
+
// guessing. The operator stays at medium on every model, and claude models
|
|
78
|
+
// stay at medium for both roles. A level the user picks is stored and stands.
|
|
79
|
+
function defaultEffortFor(role, claudeModel, openrouterModel) {
|
|
80
|
+
return role === 'tasks' && claudeModel === 'openrouter' && isMuseModel(openrouterModel) ? 'low' : 'medium';
|
|
81
|
+
}
|
|
82
|
+
const EFFORT_ROLES = [
|
|
83
|
+
{ role: 'router', label: 'operator', claude: 'routerClaudeModel', slug: 'routerOpenrouterModel', effort: 'routerEffort' },
|
|
84
|
+
{ role: 'tasks', label: 'tasks', claude: 'tasksClaudeModel', slug: 'tasksOpenrouterModel', effort: 'tasksEffort' },
|
|
85
|
+
];
|
|
73
86
|
function defaultSettings() {
|
|
74
|
-
|
|
87
|
+
const models = resolveAnthropicAuth().mode === 'proxy'
|
|
75
88
|
? { ...DEFAULT_SETTINGS }
|
|
76
89
|
: { ...DEFAULT_SETTINGS, ...ANTHROPIC_DEFAULT_MODELS };
|
|
90
|
+
return {
|
|
91
|
+
...models,
|
|
92
|
+
routerEffort: defaultEffortFor('router', models.routerClaudeModel, models.routerOpenrouterModel),
|
|
93
|
+
tasksEffort: defaultEffortFor('tasks', models.tasksClaudeModel, models.tasksOpenrouterModel),
|
|
94
|
+
};
|
|
77
95
|
}
|
|
78
96
|
// Bump to force every deck onto the current DEFAULT_SETTINGS once, discarding
|
|
79
97
|
// what users had chosen: a stored file below this epoch has ALL of its setting
|
|
@@ -120,6 +138,15 @@ function normalizeOpenrouterModel(value) {
|
|
|
120
138
|
const trimmed = value.trim();
|
|
121
139
|
return trimmed && trimmed.length <= OPENROUTER_MODEL_MAX_LEN ? trimmed : null;
|
|
122
140
|
}
|
|
141
|
+
function normalizeEffort(value) {
|
|
142
|
+
return value === 'low' ||
|
|
143
|
+
value === 'medium' ||
|
|
144
|
+
value === 'high' ||
|
|
145
|
+
value === 'xhigh' ||
|
|
146
|
+
value === 'max'
|
|
147
|
+
? value
|
|
148
|
+
: null;
|
|
149
|
+
}
|
|
123
150
|
// Every setting's validator, keyed the same as AgentSettings, so load and save
|
|
124
151
|
// iterate one list rather than repeating the field names per direction.
|
|
125
152
|
const SETTING_NORMALIZERS = {
|
|
@@ -127,6 +154,8 @@ const SETTING_NORMALIZERS = {
|
|
|
127
154
|
tasksClaudeModel: normalizeClaudeModel,
|
|
128
155
|
routerOpenrouterModel: normalizeOpenrouterModel,
|
|
129
156
|
tasksOpenrouterModel: normalizeOpenrouterModel,
|
|
157
|
+
routerEffort: normalizeEffort,
|
|
158
|
+
tasksEffort: normalizeEffort,
|
|
130
159
|
};
|
|
131
160
|
const SETTING_KEYS = Object.keys(SETTING_NORMALIZERS);
|
|
132
161
|
// Sparse ON PURPOSE: only fields that DIFFER from the current defaults are
|
|
@@ -150,6 +179,16 @@ function serializeAgentSettings(settings) {
|
|
|
150
179
|
if (settings[key] !== defaults[key])
|
|
151
180
|
out[key] = settings[key];
|
|
152
181
|
}
|
|
182
|
+
// Effort's default follows the role's stored model, not the default model.
|
|
183
|
+
for (const role of EFFORT_ROLES) {
|
|
184
|
+
const value = settings[role.effort];
|
|
185
|
+
if (value === defaultEffortFor(role.role, settings[role.claude], settings[role.slug])) {
|
|
186
|
+
delete out[role.effort];
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
out[role.effort] = value;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
153
192
|
return JSON.stringify(out, null, 2) + '\n';
|
|
154
193
|
}
|
|
155
194
|
function loadAgentSettings(settingsPath) {
|
|
@@ -170,7 +209,14 @@ function loadAgentSettings(settingsPath) {
|
|
|
170
209
|
if (value !== null)
|
|
171
210
|
overrides[key] = value;
|
|
172
211
|
}
|
|
173
|
-
|
|
212
|
+
const merged = { ...defaults, ...overrides };
|
|
213
|
+
for (const role of EFFORT_ROLES) {
|
|
214
|
+
if (role.effort in overrides) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
merged[role.effort] = defaultEffortFor(role.role, merged[role.claude], merged[role.slug]);
|
|
218
|
+
}
|
|
219
|
+
return merged;
|
|
174
220
|
}
|
|
175
221
|
// Re-resolve the defaults into the live settings object after a credential
|
|
176
222
|
// change, in place because every consumer (the router queue, the task store)
|
|
@@ -265,7 +311,7 @@ function openrouterApiKey() {
|
|
|
265
311
|
// Build the headless CLI invocation for a role. Hosted claude runs
|
|
266
312
|
// bypassPermissions for both roles because the container is already the
|
|
267
313
|
// permission boundary. Local claude stays on auto (NOT plan mode -- that makes it emit plan tool calls)
|
|
268
|
-
// at
|
|
314
|
+
// at the role's effort setting. claudeModel "openrouter" keeps the SAME claude binary and
|
|
269
315
|
// swaps only the model slug and env (see envForOpenrouterSpawn).
|
|
270
316
|
// claude CLI 2.1.198 SILENTLY resolves `--permission-mode auto` to "default"
|
|
271
317
|
// whenever --model is not in its built-in catalog -- which is every free-form
|
|
@@ -347,7 +393,7 @@ const ROUTER_CLAUDE_ENV = {
|
|
|
347
393
|
function buildAgentInvocation(role, prompt, claudeModel,
|
|
348
394
|
// Already resolved for this role by the caller (router turns pass
|
|
349
395
|
// settings.routerOpenrouterModel, task spawns settings.tasksOpenrouterModel).
|
|
350
|
-
openrouterModel,
|
|
396
|
+
openrouterModel, effort,
|
|
351
397
|
// This run's ledger identity, and the deck dir its castle.json is read from.
|
|
352
398
|
metering,
|
|
353
399
|
// The task this spawn belongs to, so its playtest frames land under
|
|
@@ -357,11 +403,12 @@ taskId,
|
|
|
357
403
|
// The stable part of a router prompt, passed as appended system text so the
|
|
358
404
|
// CLI's own cache breakpoints cover it.
|
|
359
405
|
systemPrompt) {
|
|
360
|
-
const
|
|
406
|
+
const viaOpenrouter = claudeModel === 'openrouter';
|
|
407
|
+
const spawnModel = viaOpenrouter ? openrouterModel : claudeModel;
|
|
408
|
+
const systemText = [systemPrompt, role === 'task' ? CLAUDE_TASK_SYSTEM_REMINDER : undefined, role === 'task' ? modelTaskAddendum(spawnModel) : undefined]
|
|
361
409
|
.filter((text) => Boolean(text))
|
|
362
410
|
.join('\n\n');
|
|
363
411
|
const hosted = Boolean(process.env.CASTLE_SANDBOX_ID);
|
|
364
|
-
const viaOpenrouter = claudeModel === 'openrouter';
|
|
365
412
|
const orAuth = viaOpenrouter ? resolveOpenrouterAuth() : null;
|
|
366
413
|
const anAuth = viaOpenrouter ? null : resolveAnthropicAuth();
|
|
367
414
|
// Direct = the user's own credential/login is in play, so this run bypasses
|
|
@@ -380,9 +427,9 @@ systemPrompt) {
|
|
|
380
427
|
hosted ? 'bypassPermissions' : 'auto',
|
|
381
428
|
...(!hosted && viaOpenrouter ? [openrouterAllowedToolsArg(role)] : []),
|
|
382
429
|
'--model',
|
|
383
|
-
|
|
430
|
+
spawnModel,
|
|
384
431
|
'--effort',
|
|
385
|
-
|
|
432
|
+
effort,
|
|
386
433
|
// Newer claude models default thinking display to "omitted" (empty
|
|
387
434
|
// thinking_delta text, signature only); "summarized" restores actual
|
|
388
435
|
// summary text so the shell's expandable thinking transcript has
|
|
@@ -1663,7 +1710,7 @@ async function runAgentTurn(opts) {
|
|
|
1663
1710
|
// conversation -- nothing is resumed).
|
|
1664
1711
|
const sessionId = newAgentSessionId(opts.role);
|
|
1665
1712
|
const settled = (run) => run.finally(() => notifyAgentRunFinished());
|
|
1666
|
-
const invocation = buildAgentInvocation(opts.role, opts.prompt, opts.claudeModel, opts.openrouterModel, { sessionId, deckDir: opts.cwd }, opts.taskId, opts.systemPrompt);
|
|
1713
|
+
const invocation = buildAgentInvocation(opts.role, opts.prompt, opts.claudeModel, opts.openrouterModel, opts.effort, { sessionId, deckDir: opts.cwd }, opts.taskId, opts.systemPrompt);
|
|
1667
1714
|
const run = runAgentCli({
|
|
1668
1715
|
cwd: opts.cwd,
|
|
1669
1716
|
command: invocation.command,
|
|
@@ -2018,6 +2065,7 @@ async function runTaskAgentIn(ctx, task) {
|
|
|
2018
2065
|
prompt: taskPrompt,
|
|
2019
2066
|
claudeModel: ctx.claudeModel,
|
|
2020
2067
|
openrouterModel: ctx.openrouterModel,
|
|
2068
|
+
effort: ctx.effort,
|
|
2021
2069
|
cwd: ctx.deckDir,
|
|
2022
2070
|
timeoutMs: TASK_TIMEOUT_MS,
|
|
2023
2071
|
logPath: path.join(dir, 'log.jsonl'),
|
|
@@ -2074,6 +2122,7 @@ function startTask(ctx, task) {
|
|
|
2074
2122
|
children: ctx.children,
|
|
2075
2123
|
claudeModel: ctx.claudeModel(),
|
|
2076
2124
|
openrouterModel: ctx.openrouterModel(),
|
|
2125
|
+
effort: ctx.effort(),
|
|
2077
2126
|
stopRequested: ctx.stopRequested,
|
|
2078
2127
|
quickReference: ctx.quickReference,
|
|
2079
2128
|
playtest: ctx.playtest,
|
|
@@ -2281,6 +2330,7 @@ function createTaskStore(opts) {
|
|
|
2281
2330
|
quickReference: opts.quickReference,
|
|
2282
2331
|
claudeModel: opts.claudeModel,
|
|
2283
2332
|
openrouterModel: opts.openrouterModel,
|
|
2333
|
+
effort: opts.effort,
|
|
2284
2334
|
playtest: opts.playtest,
|
|
2285
2335
|
onStarted: opts.onStarted,
|
|
2286
2336
|
onFinished: opts.onFinished,
|
|
@@ -2908,6 +2958,7 @@ function runRouterTurnIn(ctx, instruction) {
|
|
|
2908
2958
|
systemPrompt: prompt.system,
|
|
2909
2959
|
claudeModel: ctx.claudeModel(),
|
|
2910
2960
|
openrouterModel: ctx.openrouterModel(),
|
|
2961
|
+
effort: ctx.effort(),
|
|
2911
2962
|
cwd: ctx.deckDir,
|
|
2912
2963
|
timeoutMs: ROUTER_TIMEOUT_MS,
|
|
2913
2964
|
logPath: path.join(ctx.agentDir, 'router-log.jsonl'),
|
|
@@ -3102,6 +3153,27 @@ function applyAgentSettings(incoming, ctx) {
|
|
|
3102
3153
|
changes.push(`${key === 'routerOpenrouterModel' ? 'operator' : 'tasks'} openrouter model -> ${value}`);
|
|
3103
3154
|
}
|
|
3104
3155
|
}
|
|
3156
|
+
for (const key of ['routerEffort', 'tasksEffort']) {
|
|
3157
|
+
const value = normalizeEffort(incoming[key]);
|
|
3158
|
+
if (value && value !== settings[key]) {
|
|
3159
|
+
settings[key] = value;
|
|
3160
|
+
changes.push(`${key === 'routerEffort' ? 'operator' : 'tasks'} effort -> ${value}`);
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
// A role whose model just changed takes that model's default effort, unless
|
|
3164
|
+
// this same message chose one. The reset is written and broadcast like any
|
|
3165
|
+
// other change, so the picker shows the level the next spawn will use.
|
|
3166
|
+
for (const role of EFFORT_ROLES) {
|
|
3167
|
+
const modelChanged = changes.some((c) => c.startsWith(`${role.label} claude model`) || c.startsWith(`${role.label} openrouter model`));
|
|
3168
|
+
if (!modelChanged || normalizeEffort(incoming[role.effort])) {
|
|
3169
|
+
continue;
|
|
3170
|
+
}
|
|
3171
|
+
const value = defaultEffortFor(role.role, settings[role.claude], settings[role.slug]);
|
|
3172
|
+
if (value !== settings[role.effort]) {
|
|
3173
|
+
settings[role.effort] = value;
|
|
3174
|
+
changes.push(`${role.label} effort -> ${value} (default for this model)`);
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3105
3177
|
if (changes.length === 0)
|
|
3106
3178
|
return;
|
|
3107
3179
|
atomicWriteFileSync(ctx.settingsPath, serializeAgentSettings(settings));
|
|
@@ -3394,6 +3466,7 @@ function startRouterTurn(ctx, instruction) {
|
|
|
3394
3466
|
currentEpoch: () => ctx.state.userEpoch,
|
|
3395
3467
|
claudeModel: () => ctx.settings.routerClaudeModel,
|
|
3396
3468
|
openrouterModel: () => ctx.settings.routerOpenrouterModel,
|
|
3469
|
+
effort: () => ctx.settings.routerEffort,
|
|
3397
3470
|
canAutoRetry: () => !ctx.state.autoRetryUsed && ctx.state.pendingSends.length === 0,
|
|
3398
3471
|
onSettled: (retryable) => onRouterQueueSettled(ctx, retryable),
|
|
3399
3472
|
}, instruction);
|
|
@@ -3770,6 +3843,7 @@ export function createAgentServer(opts) {
|
|
|
3770
3843
|
quickReference,
|
|
3771
3844
|
openrouterModel: () => settings.tasksOpenrouterModel,
|
|
3772
3845
|
claudeModel: () => settings.tasksClaudeModel,
|
|
3846
|
+
effort: () => settings.tasksEffort,
|
|
3773
3847
|
playtest,
|
|
3774
3848
|
// Task lifecycle stays on the board only -- log lines for it were spam.
|
|
3775
3849
|
onUpdate: (task) => broadcast({ type: 'task-update', task: asClientTask(task, opts.signPath) }),
|