[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81390":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":13,"forks30d":13,"starsTrendScore":17,"compositeScore":13,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":13,"starSnapshotCount":13,"syncStatus":16,"lastSyncTime":26,"discoverSource":27},81390,"opencode-acp","ranxianglei\u002Fopencode-acp","ranxianglei","Active Context Pruning — model-driven context management for OpenCode ，主动压缩上下文","",null,"TypeScript",40,0,37,1,2,3,"Other",false,"master",true,[],"2026-06-12 02:04:14","[English](.\u002FREADME.md) | [中文](.\u002FREADME.zh-CN.md)\n\n\u003Cp align=\"center\">\n\u003Cstrong>Active Context Pruning\u003C\u002Fstrong> for \u003Ca href=\"https:\u002F\u002Fopencode.ai\">OpenCode\u003C\u002Fa>\n\u003Cbr \u002F>\nThe model decides \u003Cem>when\u003C\u002Fem> and \u003Cem>what\u003C\u002Fem> to compress — not a hard limit.\n\u003C\u002Fp>\n\n---\n\n\u003Cp align=\"center\">\n\u003Ca href=\"https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fopencode-acp\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Fopencode-acp.svg?style=flat-square\" alt=\"npm\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Franxianglei\u002Fopencode-acp\u002Fblob\u002Fmaster\u002FLICENSE\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fl\u002Fopencode-acp.svg?style=flat-square\" alt=\"license\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Franxianglei\u002Fopencode-acp\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGitHub-ranxianglei%2Fopencode--acp-181717?style=flat-square&logo=github\" alt=\"GitHub\">\u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n\u003Ccode>opencode plugin opencode-acp@latest --global\u003C\u002Fcode>\n\u003C\u002Fp>\n\n---\n\n## Why ACP\n\nACP is a hardened fork of [DCP](https:\u002F\u002Fgithub.com\u002FTarquinen\u002Fopencode-dynamic-context-pruning) with **35 bug fixes** applied. It turns context management from a passive, crash-prone mechanism into something stable enough for production use.\n\n| | DCP (original) | ACP (this fork) |\n|---|---|---|\n| **Max stable session** | ~200 messages | 10,000+ messages |\n| **Per-turn overhead** | 20 -- 50 seconds | ~90ms |\n| **State persistence** | Lost on restart | Survives restart |\n| **GC effectiveness** | Never deactivates old blocks | Age-based auto-cleanup |\n| **Compress reliability** | Fails on edge cases, model gives up | Auto-recovers reversed boundaries |\n\n> **Active** means the model proactively decides *when* and *what* to compress -- as opposed to passive approaches that only react when context hits a hard limit. The model uses the `compress` tool to produce high-fidelity summaries of completed conversation segments, preserving important details while freeing context space. This is superior to passive truncation because the model controls what information to keep.\n\nKey fixes include: state persistence across restarts, token usage reporting (was returning 0), summary message ID resolution, GC age-based deactivation, 268x logger\u002Ftokenizer speedup, auto-swap for reversed compress boundaries, and aging warning suppression at low context usage.\n\n---\n\n## Installation\n\n```bash\nopencode plugin opencode-acp@latest --global\n```\n\nOr add to your opencode config:\n\n```json\n{\n  \"plugin\": {\n    \"opencode-acp\": \"latest\"\n  }\n}\n```\n\n---\n\n## How It Works\n\nACP reduces context size through a compress tool and automatic cleanup. Your session history is never modified -- ACP replaces pruned content with placeholders before sending requests to your LLM.\n\n### Compress\n\nCompress is a tool exposed to your model that replaces closed, stale conversation content with high-fidelity technical summaries. You can think of this as a much smarter version of Opencode's compaction process. Instead of triggering statically when your session reaches its maximum context and on the entire coding session, Compress allows the model to pick when to activate based on task completion, and to only compress the specific messages that are no longer needed verbatim.\n\nACP supports two compression modes:\n\n- **`range` mode** compresses contiguous spans of conversation into one or more summaries.\n- **`message` mode** (experimental) compresses individual raw messages independently, letting the model manage context much more surgically.\n\nIn `range` mode, when a new compression overlaps an earlier one, the earlier summary is nested inside the new one so information is preserved through layers of compression rather than diluted away. In both modes, protected tool outputs (such as subagents and skills) and protected file patterns are kept in compression summaries, ensuring that the most important information is never lost. You can also enable `protectUserMessages` to preserve your messages verbatim during compression, though note that large prompts (e.g. copy-pasting log files in the prompt) will then never be compressed away.\n\n### Deduplication\n\nIdentifies repeated tool calls (same tool, same arguments) and keeps only the most recent output. Recalculated when the compress tool runs, so prompt cache is only impacted alongside compression.\n\n### Purge Errors\n\nPrunes inputs from errored tool calls after a configurable number of turns (default: 4). Error messages are preserved; only the potentially large input content is removed. Recalculated on compress tool use.\n\n---\n\n## Commands\n\nACP provides an `\u002Facp` slash command (also accepts `\u002Fdcp` for backward compatibility):\n\n| Command | Description |\n|---------|-------------|\n| `\u002Facp` | Shows available ACP commands |\n| `\u002Facp context` | Token usage breakdown by category (system, user, assistant, tools, etc.) and how much has been saved through pruning |\n| `\u002Facp stats` | Cumulative pruning statistics across all sessions |\n| `\u002Facp sweep [n]` | Prunes all tools since the last user message. Optional count: `\u002Facp sweep 10` prunes the last 10 tools. Respects `commands.protectedTools` |\n| `\u002Facp manual [on\\|off]` | Toggle manual mode. When on, the AI will not autonomously use context management tools |\n| `\u002Facp compress [focus]` | Trigger a single compress tool execution. Optional focus text directs what content to compress, following the active `compress.mode` |\n| `\u002Facp decompress \u003Cn>` | Restore a specific active compression by ID. Running without an argument shows available compression IDs, token sizes, and topics |\n| `\u002Facp recompress \u003Cn>` | Re-apply a user-decompressed compression by ID. Running without an argument shows recompressible IDs, token sizes, and topics |\n\n---\n\n## Configuration\n\nACP uses its own config file, searched in order:\n\n1. **Global:** `~\u002F.config\u002Fopencode\u002Facp.jsonc` (or `acp.json`), created automatically on first run\n2. **Custom config directory:** `$OPENCODE_CONFIG_DIR\u002Facp.jsonc` (or `acp.json`), if `OPENCODE_CONFIG_DIR` is set\n3. **Project:** `.opencode\u002Facp.jsonc` (or `acp.json`) in your project's `.opencode` directory\n\nIf no `acp.jsonc` is found, ACP falls back to `dcp.jsonc` \u002F `dcp.json` (for backward compatibility with existing DCP installations) and auto-migrates on first write.\n\nEach level overrides the previous, so project settings take priority over global. Restart OpenCode after making config changes.\n\n> [!IMPORTANT]\n> **Disable OpenCode's built-in auto-compaction.** ACP handles context management itself — OpenCode's compaction conflicts with ACP and can cause issues (re-expanded messages, lost compression state). Add to your `opencode.json`:\n>\n> ```jsonc\n> {\n>   \"compaction\": {\n>     \"auto\": false\n>   }\n> }\n> ```\n>\n> Or set the environment variable: `OPENCODE_DISABLE_AUTOCOMPACT=1`\n\n> [!NOTE]\n> If you use models with smaller context windows, such as GitHub Copilot models or local models, lower `compress.minContextLimit` and `compress.maxContextLimit` in your configuration to match the available context.\n\n\u003Cdetails>\n\u003Csummary>\u003Cstrong>Default Configuration\u003C\u002Fstrong> (click to expand)\u003C\u002Fsummary>\n\n```jsonc\n{\n    \"$schema\": \"https:\u002F\u002Fraw.githubusercontent.com\u002FOpencode-DCP\u002Fopencode-dynamic-context-pruning\u002Fmaster\u002Fdcp.schema.json\",\n    \u002F\u002F Enable or disable the plugin\n    \"enabled\": true,\n    \u002F\u002F Automatically update npm-installed ACP when a newer npm latest is available.\n    \u002F\u002F Version-locked plugin specs are not updated.\n    \"autoUpdate\": true,\n    \u002F\u002F Enable debug logging to ~\u002F.config\u002Fopencode\u002Flogs\u002Facp\u002F\n    \"debug\": false,\n    \u002F\u002F Notification display: \"off\", \"minimal\", or \"detailed\"\n    \"pruneNotification\": \"detailed\",\n    \u002F\u002F Notification type: \"chat\" (in-conversation) or \"toast\" (system toast)\n    \"pruneNotificationType\": \"chat\",\n    \u002F\u002F Slash commands configuration\n    \"commands\": {\n        \"enabled\": true,\n        \u002F\u002F Additional tools to protect from pruning via commands (e.g., \u002Facp sweep)\n        \"protectedTools\": [],\n    },\n    \u002F\u002F Manual mode: disables autonomous context management,\n    \u002F\u002F tools only run when explicitly triggered via \u002Facp commands\n    \"manualMode\": {\n        \"enabled\": false,\n        \u002F\u002F When true, automatic cleanup (deduplication, purgeErrors)\n        \u002F\u002F still runs even in manual mode\n        \"automaticStrategies\": true,\n    },\n    \u002F\u002F Protect from pruning for \u003Cturns> message turns past tool invocation\n    \"turnProtection\": {\n        \"enabled\": false,\n        \"turns\": 4,\n    },\n    \u002F\u002F Experimental settings\n    \"experimental\": {\n        \u002F\u002F Allow ACP processing in subagent sessions\n        \"allowSubAgents\": false,\n        \u002F\u002F Enable user-editable prompt overrides under dcp-prompts directories\n        \u002F\u002F When false (default), prompt override files\u002Fdirectories are ignored\n        \"customPrompts\": false,\n    },\n    \u002F\u002F Protect file operations from pruning via glob patterns\n    \u002F\u002F Patterns match tool parameters.filePath (e.g. read\u002Fwrite\u002Fedit)\n    \"protectedFilePatterns\": [],\n    \u002F\u002F Unified context compression tool and behavior settings\n    \"compress\": {\n        \u002F\u002F Compression mode: \"range\" (compress spans into block summaries)\n        \u002F\u002F or experimental \"message\" (compress individual raw messages)\n        \"mode\": \"range\",\n        \u002F\u002F Permission mode: \"allow\" (no prompt), \"ask\" (prompt), \"deny\" (tool not registered)\n        \"permission\": \"allow\",\n        \u002F\u002F Show compression content in a chat notification\n        \"showCompression\": true,\n        \u002F\u002F Let active summary tokens extend the effective maxContextLimit\n        \"summaryBuffer\": true,\n        \u002F\u002F Soft upper threshold: above this, ACP keeps injecting strong\n        \u002F\u002F compression nudges (based on nudgeFrequency), so compression is\n        \u002F\u002F much more likely. Accepts: number or \"X%\" of model context window.\n        \"maxContextLimit\": \"55%\",\n        \u002F\u002F Soft lower threshold for reminder nudges: below this, turn\u002Fiteration\n        \u002F\u002F reminders are off (compression less likely). At\u002Fabove this, reminders\n        \u002F\u002F are on. Accepts: number or \"X%\" of model context window.\n        \"minContextLimit\": \"45%\",\n        \u002F\u002F Optional per-model override for maxContextLimit by providerID\u002FmodelID.\n        \u002F\u002F If present, this wins over the global maxContextLimit.\n        \u002F\u002F Accepts: number or \"X%\".\n        \u002F\u002F Example:\n        \u002F\u002F \"modelMaxLimits\": {\n        \u002F\u002F     \"openai\u002Fgpt-5.3-codex\": 120000,\n        \u002F\u002F     \"anthropic\u002Fclaude-sonnet-4.6\": \"80%\"\n        \u002F\u002F },\n        \u002F\u002F Optional per-model override for minContextLimit.\n        \u002F\u002F If present, this wins over the global minContextLimit.\n        \u002F\u002F \"modelMinLimits\": {\n        \u002F\u002F     \"openai\u002Fgpt-5.3-codex\": 50000,\n        \u002F\u002F     \"anthropic\u002Fclaude-sonnet-4.6\": \"25%\"\n        \u002F\u002F },\n        \u002F\u002F How often the context-limit nudge fires (1 = every fetch, 5 = every 5th)\n        \"nudgeFrequency\": 5,\n        \u002F\u002F Start adding compression reminders after this many\n        \u002F\u002F messages have happened since the last user message\n        \"iterationNudgeThreshold\": 15,\n        \u002F\u002F Controls how likely compression is after user messages\n        \u002F\u002F (\"strong\" = more likely, \"soft\" = less likely)\n        \"nudgeForce\": \"soft\",\n        \u002F\u002F Tool names whose completed outputs are appended to the compression\n        \"protectedTools\": [],\n        \u002F\u002F Preserve text wrapped in \u003Cprotect>...\u003C\u002Fprotect> when compressed\n        \"protectTags\": false,\n        \u002F\u002F Preserve your messages during compression.\n        \u002F\u002F Warning: large copy-pasted prompts will never be compressed away\n        \"protectUserMessages\": false,\n    },\n    \u002F\u002F Automatic pruning strategies\n    \"strategies\": {\n        \u002F\u002F Remove duplicate tool calls (same tool with same arguments)\n        \"deduplication\": {\n            \"enabled\": true,\n            \u002F\u002F Additional tools to protect from pruning\n            \"protectedTools\": [],\n        },\n        \u002F\u002F Prune tool inputs for errored tools after X turns\n        \"purgeErrors\": {\n            \"enabled\": true,\n            \u002F\u002F Number of turns before errored tool inputs are pruned\n            \"turns\": 4,\n            \u002F\u002F Additional tools to protect from pruning\n            \"protectedTools\": [],\n        },\n    },\n}\n```\n\n\u003C\u002Fdetails>\n\n### Prompt Overrides\n\nACP exposes six editable prompts:\n\n- `system`\n- `compress-range`\n- `compress-message`\n- `context-limit-nudge`\n- `turn-nudge`\n- `iteration-nudge`\n\nThis feature is disabled by default. Set `experimental.customPrompts` to `true` in your ACP config to activate it.\n\nWhen enabled, managed defaults are written to `~\u002F.config\u002Fopencode\u002Facp-prompts\u002Fdefaults\u002F` as plain-text prompt files. A single `README.md` in that directory explains each prompt and how to create overrides.\n\nTo customize behavior, add a file with the same name under an overrides directory and edit it as plain text.\n\nTo reset an override, delete the matching file from your overrides directory.\n\n### Protected Tools\n\nBy default, these tools are always protected from pruning:\n`task`, `skill`, `todowrite`, `todoread`, `compress`, `batch`, `plan_enter`, `plan_exit`, `write`, `edit`\n\nThe `protectedTools` arrays in `commands` and `strategies` add to this default list.\n\nFor the `compress` tool, `compress.protectedTools` ensures specific tool outputs are appended to the compressed summary. By default it includes `task`, `skill`, `todowrite`, and `todoread`.\n\n---\n\n## Impact on Prompt Caching\n\nLLM providers cache prompts based on exact prefix matching. When ACP prunes content, it changes messages, which invalidates cached prefixes from that point forward.\n\n**Trade-off:** You lose some cache reads but gain token savings from reduced context size and fewer hallucinations from stale context. In most cases, especially in long sessions, the savings outweigh the cache miss cost.\n\n> [!NOTE]\n> In testing, cache hit rates were approximately 85% with ACP vs 90% without.\n\n**No impact for:**\n\n- **Request-based billing** -- Providers like GitHub Copilot that charge per request, not tokens.\n- **Uniform token pricing** -- Providers like Cerebras that bill cached and uncached tokens at the same rate.\n\n---\n\n## Migrating from DCP\n\nACP is a drop-in replacement for DCP. To migrate:\n\n1. Remove the old DCP plugin from your `opencode.json`\n2. Install ACP: `opencode plugin install opencode-acp@latest --global`\n3. Restart OpenCode\n\n**What's preserved:**\n\n- Session state (compression blocks, message ID mappings) -- auto-migrated from `plugin\u002Fdcp\u002F` to `~\u002F.local\u002Fshare\u002Fopencode\u002Fstorage\u002Fplugin\u002Facp\u002F`\n- Config file `~\u002F.config\u002Fopencode\u002Fdcp.jsonc` -- ACP auto-migrates to `acp.jsonc`\n- Prompt overrides in `~\u002F.config\u002Fopencode\u002Fdcp-prompts\u002F` -- auto-migrates to `acp-prompts\u002F`\n\n**What changes:**\n\n- Storage directory: `plugin\u002Fdcp\u002F` to `plugin\u002Facp\u002F` (auto-migrated on first launch)\n- Log directory: `logs\u002Fdcp\u002F` to `logs\u002Facp\u002F`\n- Slash command: `\u002Fdcp` to `\u002Facp` (both work for backward compatibility)\n- Notification headers: `DCP` to `ACP`\n- Context usage label: `DCP threshold` to `ACP threshold`\n\nACP auto-migrates config from `dcp.jsonc` to `acp.jsonc` and prompts from `dcp-prompts\u002F` to `acp-prompts\u002F` on first launch.\n\n---\n\n\u003Cdetails>\n\u003Csummary>\u003Cstrong>Bug Fixes (35 total)\u003C\u002Fstrong> -- applied on top of DCP v3.1.11\u003C\u002Fsummary>\n\n| # | Severity | Summary |\n|---|----------|---------|\n| 1 | CRITICAL | State not persisted across restarts -- messageIds, block deactivation, save errors silently lost |\n| 2 | CRITICAL | resetOnCompaction() clears all compression blocks -- undoes all pruning work |\n| 3 | CRITICAL | prune silently drops summary -- DATA LOSS when no user message precedes anchor |\n| 4 | CRITICAL | getCurrentTokenUsage returns 0 -- prevents nudge from ever triggering |\n| 5 | HIGH | loadPruneMessagesState duplicates activeBlockIds + reasoning-strip undefined guard |\n| 6 | HIGH | Synthetic summary messages get mNNNN refs but are invisible to boundary lookup |\n| 7 | HIGH | State not persisted across restarts -- messageIds, block deactivation, and save errors silently lost |\n| 8 | HIGH | isMessageCompacted() inconsistent with compaction summary message handling |\n| 9 | HIGH | Compressed block summaries retain stale mNNNN message ID tags -- model copies stale IDs |\n| 10 | HIGH | Model uses stale mNNNN IDs from nudges\u002Fsummaries -- compress fails with \"startId not available\" |\n| 11 | HIGH | Major GC skips legacy blocks without generation field -- oversized blocks never collected |\n| 12 | HIGH | Percentage-based thresholds calculated against effective input context instead of full model context window |\n| 13 | HIGH | Context window leaks -- compressed messages reappear after \u002Fcompact |\n| 14 | HIGH | Compression notifications write full block summaries to DB -- can reach 150KB+ per notification |\n| 15 | HIGH | npm auto-install overwrites fork with upstream package |\n| 16 | HIGH | Summary mNNNN refs in compress output -- model copies stale message IDs |\n| 17 | HIGH | Synthetic messages not in messageIdToBlockId -- compress fails to find them |\n| 18 | HIGH | Compress stops model from responding after compression completes |\n| 19 | HIGH | Dynamic block guidance breaks API prefix cache |\n| 20 | HIGH | GC never deactivates old blocks -- dead-weight accumulates indefinitely |\n| 21 | HIGH | Logger + tokenizer 20-50s per-turn latency (268x slowdown) |\n| 22 | HIGH | compress throws hard error on reversed block boundaries -- model gives up |\n| 23--34 | MEDIUM | Various fixes for dedup, purge errors, schema validation, hook timing, etc. |\n| 35 | HIGH | Aging warnings shown at low context usage (\u003C50%) -- triggers unnecessary compress, wastes tokens |\n\nFor the complete list with root cause analysis, see the [bug tracker](https:\u002F\u002Fgithub.com\u002Franxianglei\u002Fopencode-acp\u002Fissues).\n\n\u003C\u002Fdetails>\n\n---\n\n## License\n\nAGPL-3.0-or-later -- This project is a fork of [@tarquinen\u002Fopencode-dcp](https:\u002F\u002Fgithub.com\u002FTarquinen\u002Fopencode-dynamic-context-pruning). Original copyright belongs to the original author. Modifications and bug fixes by ranxianglei.\n","Active Context Pruning (ACP) 是一个针对OpenCode的上下文主动压缩工具，旨在通过模型驱动的方式智能管理对话上下文。它基于TypeScript开发，能够根据实际需要决定何时以及对哪些内容进行压缩，而不是简单地设置硬性限制。ACP相比原始版本DCP，在稳定性、性能和用户体验上均有显著提升，如支持更长会话、更快处理速度及重启后状态保持等特性。适用于需要高效且稳定管理大规模对话历史记录的应用场景中，尤其是在开发环境或需要长时间连续交互的聊天机器人服务里表现尤为出色。","2026-06-11 04:04:52","CREATED_QUERY"]