omdsh-dev/dsh-tool-regex

Plugin插件 Native原生 ⭐ 3 MIT Approval & Security审批与安全

DSH 正则工具插件:测试匹配/提取捕获组/安全替换/静态解释正则(不执行代码),零依赖,注册 regex 工具

Project Overview项目介绍

This is a native DSH plugin that provides regex processing capabilities for DeepSeek Harness agents. It supports four core actions: test a regex pattern against input, find all matches with full capture group details, perform safe regex replacement, and statically explain a regex pattern without execution. The plugin can be installed directly from the public GitHub repository using the DSH CLI command dsh plugin --profile <profile> add github:omdsh-dev/dsh-tool-regex. You can also build it locally with npm pack to generate a tarball, then install the plugin via that local file.

The plugin is built with multiple layers of protection against ReDoS (regular expression denial of service) attacks. It runs matching operations in a worker thread with a hard 1000ms timeout, enforces size limits on input, pattern, replacement, and output, and the explain action never constructs a RegExp instance at all. It is intended for DSH agents that need to reliably work with regular expressions on untrusted input, avoiding the errors that come from calculating regex results manually and the overhead of spawning external bash processes.

This plugin has zero runtime dependencies and requires only a DSH 0.1.5-rc.1 or newer environment, which provides the required peer dependencies automatically. It is released under the permissive MIT open source license. After installation, you can verify the plugin is correctly registered by running dsh --profile <profile> --dump-config | grep tool-regex, and you can run a functional test with dsh run "use regex tool to check if d+ matches abc123". All operations enforce explicit size limits to prevent resource exhaustion, with clear error messages returned for any invalid input or out-of-bounds requests.

这是一款专为 DSH 开发的原生正则工具插件,提供正则测试匹配、提取捕获组、安全替换、静态解释四大核心功能。它的差异化能力是 explain 动作:可以静态解析正则结构并生成人类可读的解释,全程不执行正则匹配,天然免疫 ReDoS 灾难性回溯攻击。它解决了大语言模型手工计算正则结果错误率高、现有方案需要额外启动进程的开销问题。

面向需要使用正则处理文本的 DSH 代理场景,典型工作流是通过调用 regex 工具,传入动作类型、正则模式、目标文本等参数,获取结构化的 JSON 结果返回。它设置了多层 ReDoS 防线,包括 worker 硬超时、输入长度上限、资源大小限制,所有边界错误都被捕获并返回清晰提示,不会阻塞宿主进程。

本插件零额外运行时依赖,仅需要 DSH 0.1.5-rc.1 及以上版本环境,遵循 MIT 许可开源。可以通过 dsh plugin add 命令直接从 GitHub 仓库安装,也可以本地打包后通过 tarball 安装,安装后可以通过 dsh --dump-config 验证安装结果。各操作都有明确的大小限制,超出限制会直接拒绝,避免资源浪费。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin --profile web add github:omdsh-dev/dsh-tool-regex

把 omdsh-dev/dsh-tool-regex 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-tool-regex

English

DSH 正则工具插件 —— 测试匹配、提取捕获组、安全替换、静态解释正则含义(不执行任何代码)。零依赖、纯函数。

License

动机

模型经常需要验证用户给的 pattern、从日志/文本中提取字段、做文本替换。"心算"正则结果错误率极高,且无法给用户展示可验证的过程。现有替代是起 bash 进程跑 node -e 或 python——进程开销 + 模型现写脚本的正确性风险。内置 grep 只能做文件域搜索,无法对任意文本测试/提取/替换/解释。

本插件提供确定性正则工具,其中 explain 是差异化能力:静态解析 pattern 结构并给出人读解释,不执行匹配,天然免疫 ReDoS。

安全模型(ReDoS 多层防线)

JS 正则的灾难性回溯是真实威胁(如 (a+)+$ 配合超长输入)。防线:

  1. worker 硬超时:test/find/replace 在可终止的 worker 线程内同步执行,1,000ms 预算到期 worker.terminate() 并返回 regex: execution timed out——灾难性回溯不再能阻塞宿主进程(工具管道的 timeoutMs 对同步阻塞体是协作式,仅靠它不够;worker 内会再次执行全部上限校验)
  2. 输入长度上限:64,000 字节(UTF-8)——超限在入口直接拒绝,不进入回溯
  3. 资源上限:pattern ≤ 16KB、replacement ≤ 16KB、输出 ≤ 1MB、匹配数 ≤ 1,000(limit 钳制)
  4. explain 零执行:只做静态 tokenizer,不构造 RegExp 实例,任何 pattern 都即时返回

⚠️ 工具描述与 README 均明确警告模型:不要对不可信的大输入使用无锚点的嵌套量词 pattern(如 (a+)+、(.*)*)。

其余边界:无效 pattern 捕获 SyntaxError 报错(含位置信息);无效/重复 flag 逐字符校验;replace 使用 String.replace 字符串替换路径(JS 原生 $-语义,无 new Function、无 eval)。

工具声明

注册 regex 工具(@deepseek-ai/dsh-tool-regex,row id tool-regex),统一输出 JSON 文本字符串。

参数 类型 必填 说明
action string ✅ test / find / replace / explain
pattern string ✅ 正则(JavaScript 语法,不含外围 /);≤ 16KB
input string 待匹配文本(test/find/replace 必需);≤ 64KB
flags string 如 "gi";支持 g i m s u y d v,需唯一且合法
replacement string replace 的替换文本,支持 $1/$2/$<name>/$$;≤ 16KB
limit integer find 最大报告匹配数,默认 50,上限 1,000

Actions

action 功能 输出示例
test 判断是否匹配(整串语义由模型自行用 ^...$ 表达) {"matched":true}
find 全部匹配:index / 完整匹配 / 编号捕获组 captures / 命名组 groups(无 g 自动补 g) [{"index":0,"match":"a@b","captures":["a","b"],"groups":{"name":"a"}}]
replace 全局安全替换($1/$<name>/$$),返回结果与替换次数 {"result":"world hello","replaced":1}
explain 静态解析 pattern → 人读节点序列(不执行匹配;节点数 ≤ 4,096) [{"kind":"escape","text":"\\d","meaning":"A digit [0-9]"}]

示例

regex { action: "find", pattern: "(\\w+)@(\\w+)", input: "a@b x c@d" }
  → [{"index":0,"match":"a@b","captures":["a","b"],"groups":null},{"index":6,"match":"c@d","captures":["c","d"],"groups":null}]

regex { action: "replace", pattern: "(\\w+) (\\w+)", input: "hello world", replacement: "$2 $1" }
  → {"result":"world hello","replaced":1}

regex { action: "explain", pattern: "\\d{4}-\\d{2}" }
  → [{"kind":"escape","text":"\\d","meaning":"A digit [0-9]"},{"kind":"quantifier","text":"{4}",...},...]

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-doc-generator 下一个 Next dsh-tool-schema →