Provides CSV parsing, serialization, and transformation utilities without external dependencies.
ⓘ This plugin is a sub-package of the omdsh-dev/dsh-toolkit monorepo — stars and activity count the whole repository.
- Language
- TypeScript
- License
- MIT
- Branch
- main
Install
$ dsh plugin --profile web add github:omdsh-dev/dsh-toolkit#path:packages/dsh-tool-csvRun the command above in your terminal to install this plugin via the dsh CLI. You can switch Profile in the top-right corner. New to dsh? Read the beginner tutorial
Install via your agent
Install the DeepSeek Harness plugin omdsh-dev/dsh-toolkit/packages/dsh-tool-csv for me: review the repository at https://github.com/omdsh-dev/dsh-toolkit first, then run the install command and verify the plugin loads successfully.
Paste this instruction to the DSH Web GUI assistant — it will install and verify for you.
本页文档对应子包
dsh-tool-csv(meta 包dsh-toolkit下属 10 个独立工具之一)。
一句话定位
在 DSH 会话里处理表格形态的 CSV 文本:解析为 JSON、按列精确过滤、统计行列数。一次工具调用、毫秒级返回纯文本结果,无需模型手写解析脚本。
核心能力
- 解析 CSV 文本为 JSON 数组(有表头时每行一个对象,否则为数组)
- 按列名或 1-based 索引做精确匹配过滤行,结果保留表头以便回读
- 统计行数、列数、列名、空行数与字段不一致/重复列名等警告
- 自定义分隔符(单字符或
"tab"),可选关闭表头识别 - 容忍 UTF-8 BOM、CRLF、跨行字段与
""转义等 RFC 4180 边界 - 严格校验引号闭合:未闭合引号或闭合后多余字符直接报错,不静默容错
技术实现
- 语言: TypeScript(ESM,
type: module) - 关键依赖:
@deepseek-ai/cordis、@deepseek-ai/dsh-tools、@deepseek-ai/dsh-invariants(均为 peerDependency,运行时零业务依赖) - 架构模式: 通过
cordis.patch.yml把插件以tool-csvrow id 插入 profile layer stack;apply(ctx)注册到ctx.tools,由 cordis 依赖注入 - 入口文件:
packages/dsh-tool-csv/src/index.ts(导出apply/name/inject) - 解析器: 手写 RFC 4180 状态机,单遍扫描 O(n),无第三方解析库
适用场景
当 AI Agent 在会话中需要处理 API 返回、报表片段、导出文件等表格数据时使用:以前模型得开 bash 自己写解析脚本(易踩引号、CRLF、BOM 这些坑,且每次都起进程),现在直接调用 csv 工具即可拿到结构化 JSON。配合 dsh-tool-json 处理对象、CSV 处理表格,组成完整结构化数据工具对。
前置依赖与兼容性
| 依赖 | 最低版本 | 说明 |
|---|---|---|
| DSH | >= 0.1.0-rc.8(已验证) | 安装时通过 dsh.bundle.patch 写入 profile layer stack |
| Node.js | ^22.19.0 或 >=24.0.0 | 由 package.json#engines 强制 |
| @deepseek-ai/cordis | ^4.0.1 | peer 依赖,由 host profile 提供 |
| @deepseek-ai/dsh-tools | >=0.0.1-rc.1 <0.2.0 | peer 依赖,由 host profile 提供 |
| @deepseek-ai/dsh-invariants | >=0.0.1-rc.1 <0.2.0 | peer 依赖,由 host profile 提供 |
| 平台 | macOS / Windows / Linux | 跨平台,无原生模块依赖 |
安装方式
dsh plugin --profile web add github:omdsh-dev/dsh-toolkit/packages/dsh-tool-csv
配置项
本插件无需配置文件;所有行为通过工具调用参数控制。
| 参数 | 类型 | 必填 | 说明 | 默认值 |
|---|---|---|---|---|
action | string | ✅ | 操作类型:parse / query / stats / to_json | 无 |
csv | string | ✅ | CSV 文本,遵循 RFC 4180;首行 BOM 自动剥离 | 无 |
column | string | 查询列:有表头时用列名,无表头时用 "2" 这样的 1-based 索引 | 无 | |
value | string | 查询的精确匹配值(严格相等,非子串模糊匹配) | 无 | |
delimiter | string | 字段分隔符,单字符或 "tab" 关键字;拒绝控制字符与代理对 | "," | |
header | boolean | 是否把首行当作表头;关闭后行解析为数组 | true | |
limit | integer | 返回行数上限;非法值(非有限数 / ≤0 / 小数)回退默认 | 100 |
常见问题
Q: 这个插件和 dsh-tool-json 有什么区别?
A: dsh-tool-json 处理对象/数组形态的结构化数据;本插件专门处理 CSV 表格文本。两者构成 DSH 的"结构化数据处理"对子,模型按数据形态选用即可。
Q: 是否会读我的本地 CSV 文件或联网?
A: 不会。插件是纯函数实现,只处理工具调用时传入的 csv 字符串,不读文件、不写文件、不发网络请求、不执行任何表达式求值。查询过滤只做字面精确匹配(===),没有注入面。
Q: 输入超大会怎样?
A: CSV 文本超过 256000 字节(约 256KB)会被直接拒绝并抛错,不会偷偷截断。单个工具调用另有 2000 毫秒超时兜底。这是故意的——截断会产生看起来"正常"但实际错误的数据,所以选择直接报错。
Q: 单次调用最多能拿多少行?
A: parse / to_json / query 默认返回上限 100 行,可在 limit 参数上调(必须为正整数,非法值如负数、小数、字符串会回退到 100)。stats 不受 limit 影响。
Q: 引号没闭合会怎么处理?
A: 报错。本插件采用严格模式:未闭合引号抛 csv: unterminated quoted field;闭合引号后出现非分隔符/非换行字符抛 csv: invalid character "x" after closing quote。不会静默容错,避免脏数据漏到下游。
Q: 怎么从 profile 里卸掉?
A: 与 DSH profile bundle 卸载一致:dsh plugin --profile web remove tool-csv。注意 web 与 headless 是两个独立 profile,需要分别卸载。
上手难度
入门 — 工具参数就 action + csv 两个必填项,其他都是可选调优;不读文件、不联网、没有副作用,失败立刻抛错,模型按 README 提示调用即可。
已知问题与限制
- 分隔符仅接受单 UTF-16 code unit 或
"tab";含代理对的 emoji(如😀)和换行等控制字符会被拒绝(src/parse.ts:34-49) - 查询过滤只做严格相等(
===),不支持模糊匹配、正则、子串查询,避免表达式求值带来的注入面 - 表头使用 null-prototype 对象写入,
__proto__/constructor/prototype等危险字段作为普通字段保留,可被JSON.stringify无损输出(src/query.ts:203-207) - 字段数不一致时不报错:缺失补
null、多余并入最后一个字段;这种情况只通过stats的warnings字段报告 - 重复列名后出现的覆盖先出现的,并通过
stats的warnings报告 - 代码中无 TODO/FIXME 注释
DSH 零依赖工具包 collection —— time / encoding / json / calculator / csv / regex / markdown / diff / stat / schema 十个确定性工具,统一入口一键安装。
为什么
DSH 生态仓库持续增长,单插件在 hub 中容易被淹没;collection 分类是辨识度最高的形态。本仓库把 10 个工具插件 vendored 冻结为 pack artifact 快照(各子仓库独立演进,当前源位于 omdsh-dev 组织下),统一工程、统一测试、统一维护。
定位(官方 Profile Bundle 生态方向):本仓库是 collection 与安装辅助仓库——每个子包都是可独立安装/启用/禁用/卸载的 bundle(dsh plugin --profile <p> add <子包>);collection 提供目录、清单与批量安装脚本。meta 包 @deepseek-ai/dsh-toolkit 保留为可选的原子挂载模型(见下文两种运行模型)。
分发边界:根 meta 包保持 private: true,用于 Git/collection 分发,不代表会发布到 npm registry。根目录已提交由当前 src 构建出的 lib/index.js 与 lib/types/index.d.ts,因此从 Git 安装时不依赖消费端 lifecycle;prepack 仍会在生成 pack artifact 前执行完整构建。
工具一览
| 工具 | 能力 | 用例数 |
|---|---|---|
time | ISO 8601 / 时区 / 日历运算 / 时长差 | 65 |
encoding | base64 / url / hex / hash / UUID | 46 |
json | JMESPath 子集查询 | 66 |
calculator | 安全数学表达式求值(无 eval) | 31 |
csv | RFC 4180 解析 / 查询 / 统计(严格引号) | 50 |
regex | 测试 / 提取 / 替换 / 静态解释(worker 硬超时) | 63 |
markdown | HTML↔Markdown / GFM 表格 / 目录生成(白名单安全) | 71 |
diff | 文本/JSON/CSV/Markdown 结构化比较与 unified diff(只读) | 124 |
stat | 描述统计 / 百分位数 / 频数分布 / 相关性(零依赖确定性) | 82 |
schema | JSON Schema 验证 / 路径 / 解释 / 安全 default(零网络零动态) | 125 |
| 合计 | 723 |
架构
dsh-toolkit/
├── src/index.ts # meta 包:相对路径动态导入 10 个子包 apply(),聚合注册
├── packages/dsh-tool-* # vendored 子包(pack artifact 快照,name 保持 @deepseek-ai/dsh-tool-*)
├── scripts/
│ ├── link-deps.sh # 构建期 junction(cordis → vendor/cordis,dsh-tools → packages/core/tools)
│ ├── build-all.sh # 一键构建 10 子包 + meta 包(tsc)
│ ├── test-all.sh # 一键跑 10 子包 vitest(合计用例数)
│ ├── install.sh # meta / 逐包两种挂载模式(含 dry-run)
│ ├── install-web.sh # 独立 bundle 批量安装 → web profile
│ ├── install-headless.sh # 独立 bundle 批量安装 → headless profile
│ └── install-all.sh # web + headless 都装
├── catalog.json # collection 清单(hub collection 分类识别依据)
└── tsconfig.base.json # 共享编译配置(固化踩坑经验)
与实施文档方案 A 的工程化适配:子包为私有 Git/collection 包,peer 名解析在 profile 内不可行, 故 meta 包采用相对路径动态导入(零解析魔法、打包自足);子包 runtime 依赖 (
@deepseek-ai/dsh-tools)在 npm 独立模式(默认)下不依赖 DSH monorepo,monorepo 模式经子包构建期 junction 解析。
安装
仓库位于 omdsh-dev/dsh-toolkit(public)。
独立 bundle 模型(推荐)
每个子包独立安装、启用、禁用、卸载:
# 安装单个工具到 web profile
dsh plugin --profile web add github:omdsh-dev/dsh-tool-csv
# 一次性任务(headless)profile
dsh plugin --profile headless add github:omdsh-dev/dsh-tool-diff
批量安装(collection 辅助脚本,幂等——重复执行不会重复添加):
./scripts/install-web.sh # 全部 10 工具 → web profile
./scripts/install-headless.sh # 全部 10 工具 → headless profile(dsh run 使用面)
./scripts/install-all.sh # 两个 profile 都装
验证与运行:
dsh --profile web --dump-config | grep tool-csv # 行存在即安装成功
dsh run "使用 csv 工具解析 'a,b\n1,2'" # headless 端到端
⚠️ web 与 headless 是不同 profile:web 安装不会自动覆盖 headless;
dsh run默认使用 headless。 Windows 路径使用正斜杠(C:/...)。
npm pack tarball 安装
本地构建后用 tarball 路径安装(不依赖 GitHub):
# tarball 方式(web 为例;headless 同)
npm pack
dsh plugin --profile web add <npm pack 产物 tarball 路径>
meta bundle 模型(可选)
需要一次原子挂载全部工具时,挂载根 meta 包:
dsh plugin --profile web add github:omdsh-dev/dsh-toolkit
dsh --profile web --dump-config | grep tool-kit
⚠️ 若 profile 已单独挂载过同名插件(tool-time/.../tool-diff/tool-stat/tool-schema),挂 meta 包会注册重名报错—— 此时先移除旧插件,或用独立 bundle 模型。meta apply 具备原子性(任一子插件失败时 逆序回滚已注册工具,不残留部分状态)。
手动安装与旧版本兼容
旧场景(monorepo 集成、不支持 Profile Bundle 的旧快照或插件开发调试环境——本地 junction/symlink、手动编辑 profile 层)。
构建与测试
npm 独立模式(默认,推荐):无需 DSH monorepo;npm install(devDependencies 自包含)后即可:
npm run build:all # 10 子包 + meta 包 tsc + 产物完整性验证(无 .ts 残留导入、10+1 个 lib/index.js)
bash scripts/test-all.sh # 10 子包 vitest 全量(723 用例);任一失败整体非零退出
npm pack # prepack 自包含(build:all),tarball 含 lib + 10 个子包
monorepo 模式(可选:源码贡献/旧 snapshot):显式提供 DSH monorepo 根:
export DSH_MONOREPO=<DSH 0.1.0-rc.8(npm)安装路径> # 或作为第一个参数
bash scripts/build-all.sh # link-deps + 10 子包 + meta 包 tsc + 产物完整性验证
bash scripts/test-all.sh
prepack已指向build:all(完整构建 10 子包 + meta),保证 pack artifact 含全部运行入口;根 Git 入口由当前src预构建并提交。 本仓库只在本地验证构建、测试与 pack artifact;不要将这些结果解读为 npm registry 发布或未实际执行的 consumer/profile 验证。
同步 vendored(子仓库有更新时)
把 packages/<name> 与源仓库重新同步(src/tests/package.json/tsconfig/cordis.patch.yml/LICENSE/README.md),并在 README 标注子包版本。
新增工具
见 docs/CONTRIBUTING.md:复制模板子包 → 实现 → 测试 → build-all 验证 → 更新 catalog.json。
许可
MIT
Read the usage guide →
Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.
Listing badge
[](https://deepseek-plugin.org/plugins/omdsh-dev/dsh-toolkit/packages/dsh-tool-csv)Paste this markdown into your GitHub README to link back to this listing. The badge only states the listing — not a security endorsement.