Skip to content

feat(claude-code): add context offloading for large context injections#594

Merged
zbigniewsobiecki merged 2 commits intodevfrom
refactor/integration-driven-capabilities
Mar 1, 2026
Merged

feat(claude-code): add context offloading for large context injections#594
zbigniewsobiecki merged 2 commits intodevfrom
refactor/integration-driven-capabilities

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • Context offloading: When context injections exceed the inline threshold (8k tokens), offload them to files under .cascade/context/ and instruct Claude to read them on-demand using its Read tool
  • Filename collision prevention: Slugify filenames with index suffix to guarantee uniqueness within a batch
  • Cross-platform paths: Use POSIX paths (forward slashes) for consistent instructions across platforms
  • Auto-cleanup: Context files are cleaned up after agent execution via try/finally

Test plan

  • Unit tests for offloadLargeContext - small context inline, large context offloaded
  • Unit tests for cleanupContextFiles - removes directory, handles missing directory
  • Unit tests for buildInlineContextSection - formatting
  • Unit tests for collision scenarios - duplicate descriptions, empty descriptions, special chars
  • Unit tests for buildTaskPrompt integration - inline small, offload large
  • Typecheck passes
  • Lint passes
  • All 3621 tests pass

🤖 Generated with Claude Code

zbigniewsobiecki and others added 2 commits March 1, 2026 16:56
Replace the ad-hoc capability system with a unified capability-centric
architecture where integrations provide capabilities and capabilities
provide tools.

Key changes:

**New capability system (`src/agents/capabilities/`):**
- Add capability registry mapping capabilities to gadgets and SDK tools
- Add resolver functions for deriving integrations from capabilities
- Add `resolveEffectiveCapabilities()` for runtime optional capability filtering
- Add `createIntegrationChecker()` factory for project integration lookups
- Add `generateUnavailableCapabilitiesNote()` for system prompt injection

**Schema changes (`src/agents/definitions/schema.ts`):**
- Replace boolean capability flags with typed capability arrays
- `capabilities: { required: Capability[], optional: Capability[] }`
- Remove separate `integrations` and `tools` sections (now derived)
- Remove `gadgetBuilder` strategy (replaced by capability-based building)

**Agent definition updates (all YAML files):**
- Migrate all 10 agent definitions to new capability format
- debug.yaml: Remove fs:write (read-only analysis agent)
- respond-to-ci.yaml: Add pm:checklist to optional capabilities

**Runtime improvements:**
- Wire `IntegrationChecker` through profiles.ts and llmist backend
- Optional capabilities filtered by actual project integration availability
- Fix: Throw on missing gadget constructors (was silently skipped)
- Fix: Only fall back to full access for "not found" errors in legacy shim
- Fix: Pass correct agentType to preExecute hooks
- Add validation warning for missing tools in filterToolManifests

**Test coverage:**
- Add comprehensive resolver.test.ts for capability resolution functions
- Update all affected tests for new capability format
- Add mock for createIntegrationChecker in llmist tests

This refactoring:
- Eliminates redundancy between schema and runtime capability logic
- Makes integration requirements derivable from capability declarations
- Provides architectural safety (tools don't exist if cap not enabled)
- Enables graceful degradation for optional integrations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When context injections exceed the inline threshold (8k tokens), offload
them to files under .cascade/context/ and instruct Claude to read them
on-demand using its Read tool. This prevents prompt size issues with
large PR diffs or file contents.

Key changes:
- Add contextFiles.ts module with offloadLargeContext, cleanupContextFiles
- Add CONTEXT_OFFLOAD_CONFIG with inlineThreshold, contextDir, enabled
- Update buildTaskPrompt to be async and handle context offloading
- Auto-cleanup context files after agent execution via try/finally
- Slugify filenames with index suffix to prevent collisions
- Use POSIX paths for cross-platform consistency in instructions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zbigniewsobiecki zbigniewsobiecki merged commit 22c8fdb into dev Mar 1, 2026
6 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the refactor/integration-driven-capabilities branch March 1, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant