castle-web-cli 0.4.191 → 0.4.192

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.
@@ -142,6 +142,7 @@ now- food-hauling
142
142
  - A bare number, a knob setting, or a bug they want gone is not taste -- just do the tweak. The REASON they give for one is: "make the islands bigger, it's already pretty hard" is a \`decide+\` about the difficulty they want, not about island size.
143
143
  - Put the fence AFTER your task fences: tasks spawn the moment their fence closes, so one in front just delays the user's first build.
144
144
  - NOTHING in \`## Open questions\` may be answered by anything else in the same reply, fence or task: asking and deciding are different acts. A probe IS the top open question, asked in its own words.
145
+ - An open question you have asked outright twice, and the user passed over both times, is TABLED: \`open- <label>\` it in that reply's fence and stop asking it. Passing over it twice is their answer about the question. It comes back only if they bring it up.
145
146
  - An ask that goes against a \`## Decisions\` line: say what was decided and why in one sentence BEFORE you build it. They may well have changed their mind -- that is theirs to say, and the line is yours to raise.
146
147
  - No plan.md yet and the deck is getting work? Open one here with the ops the moment supports: an \`identity:\` line, the \`## Now\` items you are spawning, an \`open+\` for what you are guessing at. SPARSE AND TRUE, and never in place of their actual ask.
147
148
 
package/dist/agent.js CHANGED
@@ -14,7 +14,7 @@
14
14
  // Backend CLI: the claude CLI in headless print mode (stream-json), behind
15
15
  // runAgentCli.
16
16
  import { execFileSync, spawn } from 'child_process';
17
- import { quickReferenceFor } from './platformDoc.js';
17
+ import { claudeContextEnv, quickReferenceFor } from './platformDoc.js';
18
18
  import { IMPORTS_DIR } from './imports.js';
19
19
  import { isSameOriginUpgrade } from './wsOrigin.js';
20
20
  import { resolveDeckPath } from './ide.js';
@@ -375,21 +375,6 @@ function claudeSettingsArg(auth) {
375
375
  ...(auth?.mode === 'user-key' ? { apiKeyHelper: anthropicKeyHelperCommand() } : {}),
376
376
  });
377
377
  }
378
- // The claude CLI puts every CLAUDE.md it finds, and a git-status note, into the
379
- // first user message of each process, ahead of the prompt. A router turn is a
380
- // new process, so that text (the kit guide: ~23k tokens on a kit deck) is sent
381
- // uncached on every call of every turn. The router already carries the deck's
382
- // quick reference and file tree in its cached system part, and can read a
383
- // guide on demand; tasks keep the CLI's own loading. Auto memory is off for the
384
- // same reason: the first process in a deck creates the memory store, the next
385
- // one's system prompt gains a memory block, and the cached prefix only matches
386
- // from the third turn on. Measured on a 30k-token router prompt: a second turn
387
- // goes from 50k tokens written to 6k.
388
- const ROUTER_CLAUDE_ENV = {
389
- CLAUDE_CODE_DISABLE_CLAUDE_MDS: '1',
390
- CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS: '1',
391
- CLAUDE_CODE_DISABLE_AUTO_MEMORY: '1',
392
- };
393
378
  function buildAgentInvocation(role, prompt, claudeModel,
394
379
  // Already resolved for this role by the caller (router turns pass
395
380
  // settings.routerOpenrouterModel, task spawns settings.tasksOpenrouterModel).
@@ -451,7 +436,7 @@ systemPrompt) {
451
436
  route: viaOpenrouter ? 'openrouter' : 'anthropic',
452
437
  direct,
453
438
  })),
454
- ...(role === 'router' ? ROUTER_CLAUDE_ENV : {}),
439
+ ...claudeContextEnv(role),
455
440
  // Claude Code 2.1.258 refuses bypassPermissions as root unless the
456
441
  // child explicitly identifies itself as running in a sandbox.
457
442
  ...(hosted ? { IS_SANDBOX: '1' } : {}),
@@ -2012,7 +1997,7 @@ async function runTaskAgentIn(ctx, task) {
2012
1997
  depsSummary: ctx.depsSummary,
2013
1998
  playtest: playtestSteering(),
2014
1999
  deckTree: buildDeckTree(ctx.deckDir),
2015
- quickReference: quickReferenceFor(ctx.deckDir, ctx.quickReference),
2000
+ quickReference: quickReferenceFor(ctx.deckDir, ctx.quickReference, 'task'),
2016
2001
  plan: taskPlanOpts(ctx.deckDir, task.item, ctx.finishedWork),
2017
2002
  siblings: ctx.siblings,
2018
2003
  });
@@ -2828,7 +2813,7 @@ function resolveFailure(result) {
2828
2813
  function routerTurnPrompt(ctx, instruction, selfMessageId, plan) {
2829
2814
  return buildRouterPromptParts({
2830
2815
  deckLabel: ctx.deckLabel,
2831
- quickReference: quickReferenceFor(ctx.deckDir, ctx.quickReference),
2816
+ quickReference: quickReferenceFor(ctx.deckDir, ctx.quickReference, 'router'),
2832
2817
  deckTree: buildDeckTree(ctx.deckDir),
2833
2818
  playtest: playtestSteering(),
2834
2819
  messages: ctx.log.messages
@@ -1,9 +1,10 @@
1
1
  export declare const PLATFORM_DOCS_DIR: string;
2
2
  export declare const PLATFORM_DOC_REL: string;
3
3
  export declare function everyDeckBullets(deckDir: string): string[];
4
- export declare const PLATFORM_SECTION_HEADING = "### from the Castle platform (every deck)";
5
- export declare function platformSection(deckDir: string): string;
6
- export declare function quickReferenceFor(deckDir: string, quickReference: string): string;
4
+ export type AgentRole = 'router' | 'task';
5
+ export declare function roleLoadsClaudeMd(role: AgentRole): boolean;
6
+ export declare function claudeContextEnv(role: AgentRole): NodeJS.ProcessEnv;
7
+ export declare function quickReferenceFor(deckDir: string, quickReference: string, role: AgentRole): string;
7
8
  export declare function platformGuide(deckDir: string): string;
8
9
  export declare function writePlatformDocs(deckDir: string): void;
9
10
  export declare const CLAUDE_MD_IMPORT_LINE: string;
@@ -7,8 +7,9 @@ import { resolveFileTypes } from './editorConfig.js';
7
7
  // editors. Its one home is here. The serve writes it under the deck's .castle/
8
8
  // at every start (runtime state: not saved, not versioned, never edited), the
9
9
  // deck's root CLAUDE.md `@`-imports the compact copy so any agent that
10
- // auto-loads CLAUDE.md gets it for free, and backends that read no CLAUDE.md
11
- // get the same bullets in their composed prompt. Kits
10
+ // auto-loads CLAUDE.md gets it for free, and a role whose claude loads no
11
+ // CLAUDE.md gets the every-deck bullets in its composed prompt instead
12
+ // (roleLoadsClaudeMd below decides that once, for both sides). Kits
12
13
  // state only what is theirs; nothing below is restated in a kit's guide.
13
14
  //
14
15
  // The text is what was always in context before it had one home: the four
@@ -59,12 +60,6 @@ export function everyDeckBullets(deckDir) {
59
60
  MODE_BULLET,
60
61
  ];
61
62
  }
62
- // The guide as a section of the prompt's "how this deck works", for the
63
- // backends that read no CLAUDE.md. Same heading shape as an import's section.
64
- export const PLATFORM_SECTION_HEADING = '### from the Castle platform (every deck)';
65
- export function platformSection(deckDir) {
66
- return `${PLATFORM_SECTION_HEADING}\n\n${platformGuide(deckDir)}`;
67
- }
68
63
  // ------------------------------------------------------------------- the gate
69
64
  // Whether this serve may rewrite an EXISTING deck's root CLAUDE.md onto the
70
65
  // @import. That rewrite is the one irreversible thing here, so it reaches decks
@@ -117,14 +112,47 @@ function withEveryDeckBullets(deckDir, quickReference) {
117
112
  const bullets = everyDeckBullets(deckDir).join('\n');
118
113
  return own ? `${own}\n\n${bullets}` : bullets;
119
114
  }
120
- // A deck's quick reference as the agent sees it. claude auto-loads the root
121
- // CLAUDE.md -- but only a deck whose file carries the @import line has the
122
- // guide that way. A deck the migration has not reached (gated off) or refused
123
- // ('kept' -- someone edited its sections) still has the four legacy sections
124
- // inline and is missing just the every-deck bullets, which left the kits'
125
- // quick reference in the same change that added the guide.
126
- export function quickReferenceFor(deckDir, quickReference) {
127
- return deckLoadsGuide(deckDir)
115
+ // Whether a role's claude process auto-loads the deck's CLAUDE.md, and with it
116
+ // the @imported platform guide. The ONE place that is decided: both consumers
117
+ // -- quickReferenceFor below and the spawn env in agent.ts -- derive from it.
118
+ //
119
+ // A router turn is a new process every turn, and the claude CLI puts every
120
+ // CLAUDE.md it finds, a git-status note and the auto-memory block into that
121
+ // process's first user message, ahead of the prompt and uncached: the kit
122
+ // guide alone is ~23k tokens on a kit deck, sent again on every call of every
123
+ // turn. So the router carries the deck's quick reference (and file tree) in
124
+ // its cached system part instead and reads a guide on demand; tasks keep the
125
+ // CLI's own loading. Measured on a 30k-token router prompt: a second turn goes
126
+ // from 50k tokens written to 6k. (6d974dc turned the loading off; the
127
+ // regression 330075e had to fix is what happens when one of the two consumers
128
+ // moves and the other does not.)
129
+ export function roleLoadsClaudeMd(role) {
130
+ return role === 'task';
131
+ }
132
+ // The env for a claude spawn of this role: the CLI's own context injection
133
+ // switched off for a role that loads no CLAUDE.md, nothing for one that does.
134
+ // Auto memory rides along for the same cache reason -- the first process in a
135
+ // deck creates the memory store, the next one's system prompt gains a memory
136
+ // block, and the cached prefix only matches from the third turn on.
137
+ export function claudeContextEnv(role) {
138
+ return roleLoadsClaudeMd(role)
139
+ ? {}
140
+ : {
141
+ CLAUDE_CODE_DISABLE_CLAUDE_MDS: '1',
142
+ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS: '1',
143
+ CLAUDE_CODE_DISABLE_AUTO_MEMORY: '1',
144
+ };
145
+ }
146
+ // A deck's quick reference as one agent role sees it. A task's claude
147
+ // auto-loads the root CLAUDE.md -- but only a deck whose file carries the
148
+ // @import line has the guide that way. A deck the migration has not reached
149
+ // (gated off) or refused ('kept' -- someone edited its sections) still has the
150
+ // four legacy sections inline and is missing just the every-deck bullets, which
151
+ // left the kits' quick reference in the same change that added the guide. A
152
+ // role that loads no CLAUDE.md (roleLoadsClaudeMd) takes the bullets here
153
+ // whatever the deck's file says.
154
+ export function quickReferenceFor(deckDir, quickReference, role) {
155
+ return roleLoadsClaudeMd(role) && deckLoadsGuide(deckDir)
128
156
  ? quickReference
129
157
  : withEveryDeckBullets(deckDir, quickReference);
130
158
  }