dsh-fmt
Formats and validates JSON/YAML/TOML/SQL, with line-and-column error locations.
zhijiangtang
@zhijiangtang
⬇ 2
★ 0
main
安装
dsh plugin --profile web add github:zhijiangtang/dsh-fmt
需要可复现安装时,可在仓库后追加 #commit 固定提交。
Formats and validates JSON/YAML/TOML/SQL, with line-and-column error locations.
该插件未提供要点说明,请参考仓库 README。
deepseek-harnessdsh-plugin
- 安装并启动 DeepSeek Harness:
npx @deepseek-ai/dsh web - 在终端执行上面的安装命令(CLI 会解析插件并核验来源)
- 用 dsh plugins list 确认已安装,必要时重启 Harness 生效
插件以当前 dsh 进程的权限运行,安装时可能执行代码。请先通读仓库源码与许可证,确认无破坏性命令与越权访问;本站只做索引,不对第三方插件安全性作担保。
| 代码仓库 | github.com/zhijiangtang/dsh-fmt |
| 许可证 | MIT |
| 主要语言 | main |
| 下载量 | 2 |
| GitHub 星标 | 0 |
| 最近推送 | 2026-08-16 |
| 收录日期 | 2026-09-19 |
| 分类 | 工具与能力 |
事实信息来自公开插件目录快照(2026-10-03),介绍文案由本站再加工。
以下为插件仓库 README 全文(原始内容,由公开目录抓取整理)。
# dsh-fmt
DSH 插件:格式化 / 校验文本,支持 **JSON / YAML / TOML / SQL** 四种格式。纯 ESM、无构建、无原生依赖。
## 安装
```sh
dsh plugin --profile add file:./plugins/dsh-fmt
```
(发布到 npm 后:`dsh plugin --profile add dsh-fmt`)
## 工具
- `format_text` —— 输入文本与目标格式,返回规范值 `{ format, ok, output, error? }`。
## 参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
| --- | --- | --- | --- | --- |
| `text` | string | 是 | - | 要格式化 / 校验的文本 |
| `format` | enum | 是 | - | `json` / `yaml` / `toml` / `sql` |
| `indent` | number | 否 | `2` | 缩进宽度(JSON/YAML 美化;SQL 的 tab 宽度) |
| `sqlDialect` | enum | 否 | `standard` | `standard` / `postgresql` / `mysql` / `sqlite`,仅 SQL 使用 |
| `keywordCase` | enum | 否 | `upper` | `upper` / `lower` / `preserve`,仅 SQL 使用 |
## 返回值
规范 JSON 值:
```jsonc
{
"format": "json", // 本次使用的格式
"ok": true, // 解析/格式化是否成功
"output": "…", // 格式化结果(ok=true)
"error": { // 仅 ok=false 时存在
"message": "…",
"line": 1, // 可选
"column": 2 // 可选
}
}
```
**解析失败不算工具失败**:错误以 `ok:false` + `error`(尽力带 `line`/`column` 位置)返回,而不是抛出工具异常。
## 各格式示例
### JSON
输入 `{"b":1,"a":[1,2]}`,`format=json`,`indent=2`:
```json
{
"b": 1,
"a": [
1,
2
]
}
```
非法输入 `{bad` 返回 `ok:false`,`error.message` 含 Node 报错原文,`line`/`column` 从报错中的 `position … (line L column C)` 正则提取。
### YAML
输入:
```yaml
a:
b: 1
c: [x, y]
```
`format=yaml` 先 `parse` 校验,再 `stringify` 美化(流式数组会展开为块式)。解析失败捕获 `YAMLParseError`,取 `linePos[0]` 作为位置。
### TOML
输入:
```toml
title="demo"
[owner]
name="t"
```
`format=toml` 先 `parse` 校验再 `stringify` 规范化;解析失败取 `TomlError` 的 `line` / `column`。
### SQL
输入 `select a,b from t where x=1 order by b`,`format=sql`、`keywordCase=upper`:
```sql
SELECT
a,
b
FROM
t
WHERE
x = 1
ORDER BY
b
```
`sqlDialect` 映射到 sql-formatter 的 `language`:`standard→sql`、`postgresql→postgresql`、`mysql→mysql`、`sqlite→sqlite`。
## SQL 不做语法校验的说明
`format_text` 的 SQL 分支本身**不做主动语法校验**:不先解析再格式化,直接把文本交给 `sql-formatter` 的 `format()`,多数可读 SQL 都能得到规范化输出。但 `sql-formatter` 底层是一个完整的 SQL 解析器,遇到**根本无法解析**的片段会抛错——此时同样遵循「解析失败不算工具失败」的约定,返回 `ok:false` + `error.message`,而不会让工具调用失败。
## License
MIT
数据来源:公开的 DeepSeek Harness 插件目录与各插件 GitHub 仓库。本站为独立第三方目录,与 DeepSeek、幻方(High-Flyer)及插件作者均无隶属或背书关系。