Prompt Cache Worker
NOTE: Startup and cleanup are handled by worker-base. This skill defines the WORK PROCEDURE.
When to Use This Skill
Features that modify the prompt assembler pipeline (.claude/lib/spawn/), add caching/memoization layers, or create cache-break detection modules.
Work Procedure
Read the feature description carefully. Understand which prompt assembler files to modify and what the expected behavior is.
Read existing code. Before any changes, read ALL files in .claude/lib/spawn/ to understand the full assembly pipeline. Pay special attention to:
prompt-assembler.cjs — main entry (assembleSpawnPrompt, buildBasePrompt)
prompt-assembler-sections.cjs — section builders (buildToolsSection, buildSkillsSection, injectSections)
prompt-assembler-data.cjs — data loading (filterAndDescribeTools, getSkillsByAgent, caches)
- How sections are concatenated in injectSections() — this order is critical for cache
Write tests first (red). Create test files. Tests should use mocks for tool-manifest.json and skill-index.json to avoid dependency on disk state. Use node:test and node:assert. Tests should verify:
- Determinism (same inputs → same outputs)
- Ordering (alphabetical)
- Memoization hits/misses (call counters)
- Cache invalidation (changed inputs → fresh output)
Run tests — they should FAIL (red).
Implement changes. Key patterns:
- Sorting:
.sort((a, b) => a.name.localeCompare(b.name)) after filtering
- Memoization:
Map<string, string> with JSON.stringify key or custom hash
- Hashing:
crypto.createHash('sha256').update(content).digest('hex')
- Flight recorder:
require('../monitoring/flight-recorder.cjs').record()
- IMPORTANT: All changes must be backward-compatible — existing callers must work unchanged
Run tests (green). All tests pass.
Verify no regressions. Run any existing spawn-related tests.
Lint and format.
pnpm lint
pnpm format:check
Example Handoff
{
"salientSummary": "Added alphabetical sorting to filterAndDescribeTools() and getSkillsByAgent(). Eliminated duplicate TaskUpdate contract from buildBasePrompt() (kept in buildToolsSection()). Created tests/lib/spawn/prompt-sorting.test.cjs with 12 tests verifying deterministic ordering and single contract.",
"whatWasImplemented": "In prompt-assembler-data.cjs: added .sort((a,b) => a.name.localeCompare(b.name)) after tool filtering and after skill tier grouping. In prompt-assembler.cjs: removed TaskUpdate contract block from Patch 4 (agent protocol injection) since it already exists in buildToolsSection(). Created test file with mocked tool-manifest and skill-index.",
"whatWasLeftUndone": "",
"verification": {
"commandsRun": [
{ "command": "node --test tests/lib/spawn/prompt-sorting.test.cjs", "exitCode": 0, "observation": "12 tests passing" },
{ "command": "pnpm lint", "exitCode": 0, "observation": "0 errors" }
]
},
"tests": {
"added": [{ "file": "tests/lib/spawn/prompt-sorting.test.cjs", "cases": [
{ "name": "tools sorted alphabetically", "verifies": "VAL-PC-001" },
{ "name": "skills sorted within tiers", "verifies": "VAL-PC-002" },
{ "name": "TaskUpdate contract appears once", "verifies": "VAL-PC-005" }
]}]
},
"discoveredIssues": []
}
When to Return to Orchestrator
- assembleSpawnPrompt() signature or return type needs to change
- Memoization invalidation logic is unclear for a specific section
- Flight recorder module doesn't exist or has different API than expected
- Existing tests break and the fix isn't obvious
1---2name: prompt-cache-worker3description: Prompt assembler optimization — sorting, memoization, cache-break detection, integration tests4---56# Prompt Cache Worker78NOTE: Startup and cleanup are handled by `worker-base`. This skill defines the WORK PROCEDURE.910## When to Use This Skill1112Features that modify the prompt assembler pipeline (.claude/lib/spawn/), add caching/memoization layers, or create cache-break detection modules.1314## Work Procedure15161. **Read the feature description carefully.** Understand which prompt assembler files to modify and what the expected behavior is.17182. **Read existing code.** Before any changes, read ALL files in .claude/lib/spawn/ to understand the full assembly pipeline. Pay special attention to:19 - `prompt-assembler.cjs` — main entry (assembleSpawnPrompt, buildBasePrompt)20 - `prompt-assembler-sections.cjs` — section builders (buildToolsSection, buildSkillsSection, injectSections)21 - `prompt-assembler-data.cjs` — data loading (filterAndDescribeTools, getSkillsByAgent, caches)22 - How sections are concatenated in injectSections() — this order is critical for cache23243. **Write tests first (red).** Create test files. Tests should use mocks for tool-manifest.json and skill-index.json to avoid dependency on disk state. Use node:test and node:assert. Tests should verify:25 - Determinism (same inputs → same outputs)26 - Ordering (alphabetical)27 - Memoization hits/misses (call counters)28 - Cache invalidation (changed inputs → fresh output)29 Run tests — they should FAIL (red).30314. **Implement changes.** Key patterns:32 - Sorting: `.sort((a, b) => a.name.localeCompare(b.name))` after filtering33 - Memoization: `Map<string, string>` with JSON.stringify key or custom hash34 - Hashing: `crypto.createHash('sha256').update(content).digest('hex')`35 - Flight recorder: `require('../monitoring/flight-recorder.cjs').record()`36 - IMPORTANT: All changes must be backward-compatible — existing callers must work unchanged37385. **Run tests (green).** All tests pass.39406. **Verify no regressions.** Run any existing spawn-related tests.41427. **Lint and format.**43 ```44 pnpm lint45 pnpm format:check46 ```4748## Example Handoff4950```json51{52 "salientSummary": "Added alphabetical sorting to filterAndDescribeTools() and getSkillsByAgent(). Eliminated duplicate TaskUpdate contract from buildBasePrompt() (kept in buildToolsSection()). Created tests/lib/spawn/prompt-sorting.test.cjs with 12 tests verifying deterministic ordering and single contract.",53 "whatWasImplemented": "In prompt-assembler-data.cjs: added .sort((a,b) => a.name.localeCompare(b.name)) after tool filtering and after skill tier grouping. In prompt-assembler.cjs: removed TaskUpdate contract block from Patch 4 (agent protocol injection) since it already exists in buildToolsSection(). Created test file with mocked tool-manifest and skill-index.",54 "whatWasLeftUndone": "",55 "verification": {56 "commandsRun": [57 { "command": "node --test tests/lib/spawn/prompt-sorting.test.cjs", "exitCode": 0, "observation": "12 tests passing" },58 { "command": "pnpm lint", "exitCode": 0, "observation": "0 errors" }59 ]60 },61 "tests": {62 "added": [{ "file": "tests/lib/spawn/prompt-sorting.test.cjs", "cases": [63 { "name": "tools sorted alphabetically", "verifies": "VAL-PC-001" },64 { "name": "skills sorted within tiers", "verifies": "VAL-PC-002" },65 { "name": "TaskUpdate contract appears once", "verifies": "VAL-PC-005" }66 ]}]67 },68 "discoveredIssues": []69}70```7172## When to Return to Orchestrator7374- assembleSpawnPrompt() signature or return type needs to change75- Memoization invalidation logic is unclear for a specific section76- Flight recorder module doesn't exist or has different API than expected77- Existing tests break and the fix isn't obvious