-
Notifications
You must be signed in to change notification settings - Fork 78
docs: add breakdown configuration guide #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ev3lynx727
wants to merge
8
commits into
cortexkit:master
Choose a base branch
from
Ev3lynx727:docs/breakdown-configuration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6b6ea6
Add breakdown configuration doc
Ev3lynx727 8538328
fix: address PR review feedback — use safe plugin-removal instruction…
Ev3lynx727 e69ef20
Review fix: targeted removal instead of unsafe jq-only check
Ev3lynx727 9143989
Greptile fixes: jq filter-then-check + canonical install path
Ev3lynx727 27dd07d
Fix bash line continuation: double backslash -> single
Ev3lynx727 aaf4fb2
Fix: echo inside && chain — only prints on success
Ev3lynx727 762463a
Fix: chain echo onto mv with && — only prints on success
Ev3lynx727 cc54df1
Fix: proper && chain for echo (remove stale && :)
Ev3lynx727 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| # Magic Context - Breakdown & Configuration | ||
|
|
||
| ## Installation | ||
|
|
||
| ### Proper Install - Global Scope (recommended) | ||
|
|
||
| ```bash | ||
| opencode plugin @cortexkit/opencode-magic-context --global | ||
| ``` | ||
|
|
||
| This: | ||
| 1. Runs `npm install --ignore-scripts` into the opencode cache | ||
| 2. Adds the plugin to `opencode.jsonc` `plugin[]` list | ||
| 3. Registers server and tui targets | ||
|
|
||
| ### Package Cache Locations | ||
|
|
||
| | Location | Purpose | | ||
| |----------|---------| | ||
| | `~/.cache/opencode/packages/@cortexkit/` | Proper install by `opencode plugin` | | ||
| | `~/.cache/opencode/node_modules/@cortexkit/` | Manual `npm install` (not canonical) | | ||
| | `~/.npm/_npx/` | Cached from npx (not persistent) | | ||
|
|
||
| ### Backend Data | ||
|
|
||
| | Location | Contents | | ||
| |----------|----------| | ||
| | `~/.local/share/cortexkit/magic-context/` | SQLite DB, model limits, ONNX model, RPC sockets | | ||
| | `~/.local/share/opencode/opencode.db` | OpenCode conversation database | | ||
|
|
||
| ### Verify | ||
|
|
||
| ```bash | ||
| grep 'magic-context' ~/.config/opencode/opencode.jsonc | ||
| ls ~/.cache/opencode/packages/@cortexkit/ | ||
| ls ~/.local/share/cortexkit/magic-context/ | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Plugin Schema | ||
|
|
||
| ### opencode.jsonc Entry | ||
|
|
||
| ```jsonc | ||
| { | ||
| "plugin": [ | ||
| "@cortexkit/opencode-magic-context" | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| No `@latest` tag - `opencode plugin` resolves and strips it on install. | ||
|
|
||
| ### Agent Model Binding | ||
|
|
||
| All agents reference `"model": "opencode/big-pickle"` (160K context). | ||
|
|
||
| Available `opencode/` model IDs: | ||
| - `big-pickle` - 160,000 context | ||
| - `deepseek-v4-flash` - 1,000,000 context | ||
| - `deepseek-v4-flash-free` - 200,000 context | ||
| - `deepseek-v4-pro` - 1,000,000 context | ||
| - `claude-sonnet-4` - 1,000,000 context | ||
| - `claude-opus-4-7` - 1,000,000 context | ||
| - `gpt-5.4` - 922,000 context | ||
| - `gemini-3.5-flash` - 1,048,576 context | ||
|
|
||
| ### Compaction Settings | ||
|
|
||
| ```jsonc | ||
| { | ||
| "compaction": { | ||
| "auto": false, | ||
| "prune": false, | ||
| "reserved": 20000 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| When Magic Context is active, compaction is managed by the plugin, not OpenCode's native engine. | ||
|
|
||
| --- | ||
|
|
||
| ## Backend Architecture | ||
|
|
||
| ### Data Directory: `~/.local/share/cortexkit/magic-context/` (~96 MB) | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `context.db` (+SHM, +WAL) | SQLite - session state, compacted history | | ||
| | `model-context-limits-opencode.json` | Per-model context limits (2,400+ entries) | | ||
| | `models/Xenova/all-MiniLM-L6-v2/` | ONNX embedding model | | ||
| | `rpc/` | RPC communication ports | | ||
| | `last_announced_version` | Version announcement tracker | | ||
|
|
||
| ### Model Context Limits | ||
|
|
||
| The `model-context-limits-opencode.json` caches context window limits populated from OpenCode's `config.providers()` SDK endpoint. Magic Context reads the live resolved config (never reads `models.json` directly) to avoid torn-read issues. | ||
|
|
||
| ```jsonc | ||
| { | ||
| "opencode/big-pickle": 160000, | ||
| "opencode/deepseek-v4-flash": 1000000, | ||
| // ... 2400+ entries | ||
| } | ||
| ``` | ||
|
|
||
| ### Context Resolution Flow | ||
|
|
||
| ``` | ||
| Plugin startup -> warm apiCache from last-known-good file | ||
| OpenCode SDK -> config.providers() -> merged models | ||
| (live + compiled-in + auth-plugin caps) | ||
| Magic Context -> consumes merged result | ||
| Result bounded to [20k, 3M] range | ||
| ``` | ||
|
|
||
| ### Process Architecture | ||
|
|
||
| ``` | ||
| OpenCode (main process) | ||
| +-- MCP servers (git, mempalace, hf-mcp, etc.) | ||
| +-- Magic Context (child process) | ||
| +-- SQLite (context.db) | ||
| +-- ONNX model (all-MiniLM-L6-v2) | ||
| +-- RPC socket | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "Model not found: opencode/small-pickle. Did you mean: big-pickle?" | ||
|
|
||
| **Cause:** OpenCode's runtime tries to resolve `opencode/small-pickle` which doesn't exist in the model catalog. Appears during context compaction cycles. | ||
|
|
||
| **Solution:** Harmless - no functional impact. `big-pickle` (160K context) is the correct model already configured for all agents. This is an upstream model alias issue - cannot fix via config. Ignore or report to OpenCode. | ||
|
|
||
| ### Duplicate Plugin Entries | ||
|
|
||
| **Solution:** Check both config files: | ||
|
|
||
| ```bash | ||
| grep 'magic-context' ~/.config/opencode/opencode.jsonc | ||
|
|
||
| # Check if local scope files exist and what's in them: | ||
| cat ~/.opencode/opencode.json 2>/dev/null | ||
| cat ~/.opencode/tui.json 2>/dev/null | ||
| ``` | ||
|
|
||
| **To remove only the plugin entry (not the whole file)** — if the local files contain other settings beyond the plugin entry, edit the file and remove just `"@cortexkit/opencode-magic-context"` from the `"plugin"` array. If the file contains only the plugin entry or no other useful config, delete the entire file: | ||
|
|
||
| ```bash | ||
| # Safe deletion check — only if file consists solely of the plugin entry: | ||
| if [ -f ~/.opencode/opencode.json ] && [ "$(jq '.plugin | length' ~/.opencode/opencode.json 2>/dev/null)" = "1" ]; then | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| rm ~/.opencode/opencode.json | ||
| echo "Removed (only plugin entry)" | ||
| fi | ||
|
Ev3lynx727 marked this conversation as resolved.
|
||
| ``` | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| Keep plugin in only one scope. | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| ### Package Missing (Plugin Registered But Not Installed) | ||
|
|
||
| **Symptom:** Plugin listed in config but OpenCode shows loading errors. | ||
|
|
||
| **Solution:** Install manually to cache: | ||
|
|
||
| ```bash | ||
| cd ~/.cache/opencode && npm install @cortexkit/opencode-magic-context --ignore-scripts | ||
| ``` | ||
|
|
||
| Or re-install with `opencode plugin @cortexkit/opencode-magic-context --global`. | ||
|
|
||
| --- | ||
|
|
||
| ## FAQ | ||
|
|
||
| ### Q: Why does Magic Context use its own SQLite database? | ||
|
|
||
| The plugin needs persistent session state for context management that survives OpenCode restarts. It cannot rely on OpenCode's in-memory state. The database at `context.db` stores compacted history, configuration overrides, and session bookkeeping. | ||
|
|
||
| ### Q: Where does the ONNX model come from? | ||
|
|
||
| `all-MiniLM-L6-v2` is a sentence-transformer embedding model downloaded from Hugging Face (Xenova/onnx conversion). It's used by Magic Context's sidebar for semantic compression features. | ||
|
|
||
| ### Q: Does Magic Context read `~/.cache/opencode/models.json`? | ||
|
|
||
| No. Magic Context explicitly does NOT read `models.json` due to torn-read issues. It consumes the merged, live-resolved model config from OpenCode's `config.providers()` API endpoint, which already combines the live cache, compiled-in snapshot, opencode.json overrides, and auth-plugin caps. | ||
|
|
||
| ### Q: What happens if both local and global scope have the plugin? | ||
|
|
||
| OpenCode loads both entries, potentially causing duplicate initialization. Remove one scope (preferably the local `~/.opencode/` files) to keep only the global scope. | ||
|
|
||
| ### Q: Is the opencode/small-pickle error breaking anything? | ||
|
|
||
| No. It's a console warning during compaction with zero functional impact. The model routing still works correctly with the configured `opencode/big-pickle`. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.