Skip to content

feat(agents): OpenCode + DeepSeek cache integration - #264

Open
harijsvucens wants to merge 6 commits into
cabinetai:mainfrom
harijsvucens:feat/opencode-deepseek-cache
Open

feat(agents): OpenCode + DeepSeek cache integration#264
harijsvucens wants to merge 6 commits into
cabinetai:mainfrom
harijsvucens:feat/opencode-deepseek-cache

Conversation

@harijsvucens

Copy link
Copy Markdown

Summary

This PR improves OpenCode integration in Cabinet for token efficiency and cost visibility when using DeepSeek models. It also adds general-purpose reasoning token tracking for all OpenCode providers.

Research

The cache token pipeline from DeepSeek through OpenCode to Cabinet was verified from opencode source (branch dev). Cabinet already captures cached input tokens correctly via tokens.cache.read in the JSON stream. DeepSeek's KV cache is automatic (always on) with 50-120x cost savings on cache hits. See OPENCODE_PLAN.md for full analysis.

Changes

Phase 1 — DeepSeek fallback models

  • Added deepseek/deepseek-v4-pro and deepseek/deepseek-v4-flash to OPENCODE_FALLBACK_MODELS
  • Model picker now shows DeepSeek even when opencode models discovery fails

Phase 2 — Reasoning token separation

  • Added reasoningTokens to AdapterUsageSummary (types.ts)
  • Stream parser now tracks tokens.reasoning separately instead of merging into outputTokens
  • Reasoning persisted in TurnTokens, ConversationTokens, daemon client, store, and runner
  • UI: "(N.Nk think)" badge shown next to total tokens in turn headers with tooltip

Phase 3 — Compaction via config injection

  • Injects OPENCODE_CONFIG_CONTENT with compaction settings
  • Enables auto-pruning of stale tool outputs for long-running sessions
  • Keeps OPENCODE_DISABLE_PROJECT_CONFIG to prevent project config leakage

Phase 4 — Cache write tracking

  • Tracks tokens.cache.write as cacheWriteInputTokens for cache warming visibility

Tests

  • 412/412 passing (3 new tests added)
  • TypeScript compiles cleanly

Files changed

16 files, ~190 insertions, ~10 deletions

@harijsvucens
harijsvucens requested a review from a team as a code owner July 23, 2026 20:12
Harijs added 2 commits July 24, 2026 13:31
…ion, compaction config, and cache write tracking

- Add deepseek/deepseek-v4-pro and deepseek/deepseek-v4-flash
- Track reasoning tokens separately from output tokens
- Inject compaction config for long-running sessions
- Track cache write tokens for cache warming visibility
…ersation runtime

- Add contextWindow to ProviderModel type
- Parse limit.context from opencode models --verbose output
- Store on ConversationMeta.runtime.contextWindow
@harijsvucens
harijsvucens force-pushed the feat/opencode-deepseek-cache branch from bf92c10 to b37dfaa Compare July 24, 2026 10:32
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