Community plugin

Khorsheed / @khorsheed/dsh-context-guard

Context-window compaction reminder: a compact button appears in the composer once context occupancy (the same number the context ring shows) crosses a configurable fraction of the model's context window, so you can compact before requests hit the provider's rejection wall (which sits below 100% occupancy because the request reserves output tokens)

  • TypeScript
  • MIT
  • 2 stars
  • Nov 14, 2026

About this plugin

Written by the registry from verified metadata, not from the README.

@khorsheed/dsh-context-guard is a DSH plugin published from the packages/context-guard package in the Khorsheed/dsh-plugins repository.

  • Listing statusManifest verified
  • Manifest checkedNov 16, 2026
  • Package@khorsheed/dsh-context-guard
  • Package pathpackages/context-guard
  • Repository createdAug 16, 2026

Capabilities and topics

dshdsh-plugincordiscontext
From the repository README

README

Everything below this line is the repository's own document, cached here. This site did not write or review it.

@khorsheed/dsh-context-guard

English | 中文

上下文快撑爆之前,输入框里会冒出一枚「立即压缩」按钮。

聊得越久,上下文占用越高,涨到头 provider 会直接拒收请求——这堵墙比进度环的 100% 来得更早(请求还要给输出留位置)。这个插件就是干这个的:占用一过你设的比例,输入框工具栏里就出现一枚琥珀色按钮,点一下等于亲手输入 /compact。它不替你自动压缩,只在你还来得及的时候提醒你。

功能

  • 输入框里的压缩按钮——低于阈值时看不见,越过后自动出现。
  • 和进度环同一个数——由官方 contextPressure 投影驱动,按钮和进度环永远不会打架。
  • 执行官方 /compact——空闲门控、压缩锁和流程展示都由宿主负责,点击的效果和手打命令一模一样。
  • 一个实时可调项——提醒阈值在设置里改,保存即生效,不用重启。
  • 外部 CLI 成员也提醒——装了本机 Agent 委派(Kimi、Codex 等)时,CLI 成员的会话和协作间里同样会出现压缩按钮;每个 CLI 可以单独设比例,点成员的上下文圆环还能给这一位单独设。没装就和原来一样。

安装

dsh plugin --profile web add @khorsheed/dsh-context-guard

安装后重启 web 实例。卸载即清除它添加的所有界面:

dsh plugin --profile web remove @khorsheed/dsh-context-guard

配置

一个可调项,在 GUI 里改且实时生效,无需重启——0.1.5:设置 → 插件配置 →「压缩提醒时机 / Compaction reminder timing」;0.1.6-alpha.2 起:插件管理页 → 本包详情页的配置区。

键默认值含义
thresholdRatio0.8压缩按钮出现时的上下文占用比例(限制在 (0, 1])。想更早收到提醒就调低——provider 拒绝墙在 100% 占用之下(见「实现原理」)。
harnessThresholds{}外部 CLI 各自的比例,按 CLI 名(kimi、codex…);没写的跟随 thresholdRatio。
memberThresholds{}单个成员的比例(在成员的上下文圆环里设);优先级:成员 > CLI > 全局。
plugins:
  context-guard:
    thresholdRatio: 0.65

该字段只影响按钮出现的时机——真实压缩时机仍由官方压缩引擎自己的 thresholdRatio / auto 配置决定。

Compatibility

  • npm 发布线(@deepseek-ai/dsh@0.1.2-rc.1):⚠️ 按钮完整、设置卡缺位——基线迁移至 0.1.2-rc.1 API 面(单臂消费 0.1.2 API,0.1.1-rc.2 运行臂已退役),全量构建测试通过;设置卡自本版起只挂 0.1.7-alpha.1 起的 Plugins 页 plugins.item 席位(随 configForms.whileServed 在宿主服务 context-guard 命名空间时挂载,独立安装、toolbox 家族 bundle、模式包同一张卡),此线不再呈现卡片,composer 按钮不受影响;minHost 前移至 0.1.2-rc.1,旧宿主请停留在旧发布线。
  • 0.1.6-alpha.2 预发布线(@deepseek-ai/dsh@0.1.6-alpha.2):⚠️ 按钮完整、设置卡缺位——plugins.item 槽已在,但 whileServed 门控随 0.1.7-alpha.1 落地,此线不挂卡;0.1.5 的旧 settings.plugin.item 席位已随宿主删除一并退役,minHost 不动。
  • 源码线(deepseek-harness master):✅(verifiedHost: 0.2.1-rc.5)——host-021 波对 0.2.1-rc.5 树全量 build+test 绿,无其它表面变化。

版本线对照:0.2.0 起支持宿主 0.1.2-rc.1 及以后;宿主 0.1.0-rc.6 ~ 0.1.1-rc.2 的用户请停留在 0.1.x 发布线(末版 0.1.0)。

Known Limitations

  • 提醒,不是保证——从按钮出现到点击之间上下文可能继续增长,agent 运行中 /compact 可能报 busy。
  • 没有输出上限旋钮——拒绝墙取决于 window − maxTokens,这是模型属性而非用户偏好。
  • 不自动压缩——官方 80% 自动压缩保持原样运行。

实现原理

在进度环看不到的"墙"之前提醒你

官方 compaction-basic 引擎在上下文窗口 80% 处自动压缩,且只在步间运行。但 provider 在 prompt + max_tokens > context_length 时拒绝请求——请求要预留输出 token,因此拒绝墙在 100% 占用之下。以 deepseek 适配器的默认值(窗口 1,000,000、输出上限 256,000)计,墙在约 74.4% 处,甚至低于官方 80% 压缩点;估算器还系统性低估 CJK 文本与 JSON schema,provider 侧计数比进度环显示的高。空闲会话上没有任何信号提示下一次发送会失败。

默认比例(0.8)下按钮与官方引擎要压缩的点重合;调低比例(如 0.6–0.7)可更早收到提醒——此时手动 /compact 的摘要调用还放得下。

机制

  • 位置:conversation.input.right(输入框工具栏、发送按钮之前)。
  • 数据:官方 contextPressure 会话投影——projectedTokens 与 contextWindow,旧日志回退到 provider 裸样本。
  • 公式:projectedTokens / contextWindow >= thresholdRatio——与进度环显示的是同一个占用数。
  • 动作:官方 /compact 命令通道(remote.commands.execute → ctx.commands → ctx.compaction.compactNow)。

模型体验

对模型没有任何变化:点击执行的是与用户手动输入相同的 /compact,会话日志里也是同样的命令生命周期。插件本身无 token 与 KV 缓存影响。

/client 导出即插件本体(apply/inject)与 CompactGuardButtonProps / ContextGuardBundleConfigProps 类型。

开发

隶属 dsh-plugins monorepo(packages/context-guard)。问题与贡献请移步该仓库。

变更记录

见 CHANGELOG.md。

Badge

Listed here? Link back with this badge — paste the snippet into your repository README.

Listed on DSH Plugin badge
[![Listed on DSH Plugin](https://dsh-plugin.com/badges/listed.svg)](https://dsh-plugin.com/plugins/Khorsheed/dsh-plugins/packages/context-guard)