Back to home

Hyna-hla

dsh-md-table-formatter

No description

Stars
1
Language
TypeScript
Created
Aug 14, 2026
Updated
Aug 14, 2026

Introduction

dsh-md-table-formatter

DeepSeek Harness 插件:两个功能,都建立在会话 surface-replace 机制上(与内置 compaction 同一套,可安全回放):

  1. 自动对齐 Markdown 表格:每个回合结束后,把助手回复里没对齐的 GFM 表格在「模型可见表面」上替换为对齐版本。原始输出仍完整保留在仅追加的会话日志里。
    • 支持 :---(左)、---:(右)、:---:(居中)对齐标记。
    • 宽度按 Unicode 码点计算,CJK/全角字符按 2 列计算。
    • 代码围栏(``` 内)的表格不动;连续两张表不会互相吞行。
  2. /clear-history 命令:把模型可见的对话记录整体替换为一条占位消息(原始日志保留,可继续对话)。回合进行中会拒绝执行。

移植思路来源:@franlol/opencode-md-table-formatter(OpenCode 的 experimental.text.complete 钩子 → DSH 的 turn/end + surface-replace)。

配置(cordis.patch.yml 可覆写)

- insert:
    - id: dsh-md-table-formatter
      name: dsh-md-table-formatter
      config:
        autoFormat: true      # 是否回合后自动格式化
        minColumns: 2         # 少于该列数的表格不动
        clearMarker: '(对话记录已清除)'  # /clear-history 的占位文本

构建与安装

pnpm install
pnpm build
pnpm test
# 安装到 profile(拷 node_modules + 注册 cordis.patch.yml):
.\scripts\install-to-profile.ps1 -Name dsh-md-table-formatter -SourceDir .
# 然后重启 DeepSeek Harness

实现要点

  • 替换事件 = assistant/message + { surfaceOp: { op: 'replace', start: seq, end: seq }, sourceEventSeqs: [seq] },与 dsh-compaction-tool-result-pruner 完全同款;替换副本保留原消息 id(freezeMessage),usage 只留在原始事件上避免重复计数。
  • 格式化 pass 由 session/event 观察者里的 turn/end 触发,用 queueMicrotask 逃出刚提交 append 的接纳边界后再写替换。
  • apply 是箭头函数(cordis 4 会把带 prototype 的 function 当类构造器)。