KakaruHayate/dsh-degen-heal ↗★ 1
@dsh-external/llm-degen-heal
检测并自愈 LLM 输出退化循环:流式碎词/熵骤降/空转仪表三信号,请求级惩罚注入(含需核心改一行项)、流中断重试、冷却幂等、dev_loop_status 诊断 适合需要自动中断并修复模型流式输出重复、碎词或死循环的用户。
설치
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:KakaruHayate/dsh-degen-healHarness Extension Points Used / 使用的 Harness 扩展点
The plugin registers listeners on six documented harness waterfall / serial events: 插件在 六个 文档化的 Harness waterfall / 串行事件上注册监听器:
| Event / 事件 | Type / 类型 | Purpose / 用途 |
|---|---|---|
llm/stream | waterfall | Per-chunk tokenization, rolling window update, in-stream classification, escalate-interrupt |
agent/pre-step | waterfall | Idle-turn aggregation, corrective message injection (once per epoch) |
agent/request | waterfall | Temperature rewrite (once per epoch, optional) |
agent/request-error | waterfall | Bounded retry for LLM_DEGENERATION interrupt finish reason |
agent/turn-stopping | serial | Idle-turn meter: escalate when consecutive idle turns exceed threshold |
ctx.tools.register | injection | Register dev_loop_status diagnostic tool |
Plus one lifecycle hook: 外加一个生命周期钩子:
| Hook / 钩子 | Purpose / 用途 |
|---|---|
ctx.effect(() => cleanup) | Clear all process-local state on fiber dispose |
Configuration / 配置
All tunables are validated at plugin load (fail-loud on bad values). Override in your profile's cordis.patch.yml, cordis.yml, or inject config.
所有参数在插件加载时校验(非法值报错)。在你的 profile 的 cordis.patch.yml、cordis.yml 或 inject 配置中覆盖。
Full Schema / 完整配置
plugins:
'@dsh-external/llm-degen-heal':
# ── Master switch ──
enabled: true # true = active; false = pure passthrough, no logging
# true = 生效;false = 纯透传,无日志
# ── Detection / 检测 ──
providers: [] # Provider allowlist; empty = all providers
# Provider 白名单;空 = 全部
windowTokens: 256 # Rolling token window size
# 滚动 token 窗口大小
shortTokenMaxLen: 32 # Max token length for "short token" classification
# "短词"分类的最大 token 长度
repeatThreshold: 8 # Consecutive identical short tokens to trigger token-loop
# 触发碎词循环的连续相同短词数
entropyRatio: 0.35 # unique/total below this (unstructured) → entropy-drop
# unique/total 低于此值(无结构)→ 熵骤降
detectAlternating: true # Detect A B A B… pair loops
# 检测 A B A B… 交替对循环
leakMarkers: [...] # Custom thinking/planning leak phrases (defaults built-in)
# 自定义思维/规划泄漏短语(内建默认值)
leakThreshold: 2 # Marker hits in window before leak-out fires
# 窗口内触发泄漏的标记命中次数
idleTurns: 2 # Consecutive idle turns before meter fires
# 仪表触发前的连续空转 turn 数
idleTurnWords: 60 # Word cap for "idle" turn classification
# "空转" turn 分类的词数上限
# ── Self-healing / 自愈 ──
temperatureDelta: 0 # Temperature adjustment per epoch; 0 = disabled, range [-2, 2]
# 每 epoch 的 temperature 调整;0 = 关闭,范围 [-2, 2]
cooldownMs: 30000 # Healing epoch cooldown (ms); triggers within this window stay in one epoch
# 治愈 epoch 冷却(毫秒);此窗口内的触发归入同一 epoch
escalateAt: 2 # Trigger count in epoch that causes stream interrupt
# epoch 内达到此触发数时中断流
maxRetriesPerEpoch: 1 # Max retry grants per epoch (0 = detect-only, no retry)
# 每 epoch 最大重试授权数(0 = 仅检测,不重试)
lockoutAt: 3 # Triggers in epoch before fail-open lockout
# epoch 内触发数超过此值进入 fail-open lockout
lockoutMs: 180000 # Lockout duration (ms); 180000 = 3 minutes
# Lockout 持续时间(毫秒);180000 = 3 分钟
# ── Corrective message / 修正消息 ──
healMessage: | # Message injected when degeneration is detected
Degeneration detected: your previous output either repeated the same
short fragments without making progress, or leaked your thinking/planning
as visible prose instead of concise final answers. Stop writing fragments
and stop writing your thought process into the reply. Truncate and rephrase
from your last meaningful step, then make exactly ONE tool call now to make
concrete progress. If the task is genuinely complete, say so in one short
sentence and stop.
Quick-Tune Presets / 快速调参
Observe-only (no intervention / 仅观察,不干预):
plugins:
'@dsh-external/llm-degen-heal':
enabled: true # still logs; set false to silence entirely
maxRetriesPerEpoch: 0
temperatureDelta: 0
Aggressive (interrupt early / 激进,尽早中断):
plugins:
'@dsh-external/llm-degen-heal':
repeatThreshold: 5
escalateAt: 1
maxRetriesPerEpoch: 2
temperatureDelta: 0.3
Lenient (high tolerance / 宽松,高容忍):
plugins:
'@dsh-external/llm-degen-heal':
repeatThreshold: 12
entropyRatio: 0.25
idleTurns: 4
lockoutAt: 5
Full Schema / 完整配置
plugins:
'@dsh-external/llm-degen-heal':
# ── Master switch ──
enabled: true # true = active; false = pure passthrough, no logging
# true = 生效;false = 纯透传,无日志
# ── Detection / 检测 ──
providers: [] # Provider allowlist; empty = all providers
# Provider 白名单;空 = 全部
windowTokens: 256 # Rolling token window size
# 滚动 token 窗口大小
shortTokenMaxLen: 32 # Max token length for "short token" classification
# "短词"分类的最大 token 长度
repeatThreshold: 8 # Consecutive identical short tokens to trigger token-loop
# 触发碎词循环的连续相同短词数
entropyRatio: 0.35 # unique/total below this (unstructured) → entropy-drop
# unique/total 低于此值(无结构)→ 熵骤降
detectAlternating: true # Detect A B A B… pair loops
# 检测 A B A B… 交替对循环
leakMarkers: [...] # Custom thinking/planning leak phrases (defaults built-in)
# 自定义思维/规划泄漏短语(内建默认值)
leakThreshold: 2 # Marker hits in window before leak-out fires
# 窗口内触发泄漏的标记命中次数
idleTurns: 2 # Consecutive idle turns before meter fires
# 仪表触发前的连续空转 turn 数
idleTurnWords: 60 # Word cap for "idle" turn classification
# "空转" turn 分类的词数上限
# ── Self-healing / 自愈 ──
temperatureDelta: 0 # Temperature adjustment per epoch; 0 = disabled, range [-2, 2]
# 每 epoch 的 temperature 调整;0 = 关闭,范围 [-2, 2]
cooldownMs: 30000 # Healing epoch cooldown (ms); triggers within this window stay in one epoch
# 治愈 epoch 冷却(毫秒);此窗口内的触发归入同一 epoch
escalateAt: 2 # Trigger count in epoch that causes stream interrupt
# epoch 内达到此触发数时中断流
maxRetriesPerEpoch: 1 # Max retry grants per epoch (0 = detect-only, no retry)
# 每 epoch 最大重试授权数(0 = 仅检测,不重试)
lockoutAt: 3 # Triggers in epoch before fail-open lockout
# epoch 内触发数超过此值进入 fail-open lockout
lockoutMs: 180000 # Lockout duration (ms); 180000 = 3 minutes
# Lockout 持续时间(毫秒);180000 = 3 分钟
# ── Corrective message / 修正消息 ──
healMessage: | # Message injected when degeneration is detected
Degeneration detected: your previous output either repeated the same
short fragments without making progress, or leaked your thinking/planning
as visible prose instead of concise final answers. Stop writing fragments
and stop writing your thought process into the reply. Truncate and rephrase
from your last meaningful step, then make exactly ONE tool call now to make
concrete progress. If the task is genuinely complete, say so in one short
sentence and stop.