Skip to main content

dsh-tool-csv/packages/dsh-tool-csv

24Stars1Forks1Issues0Watchers

Provides CSV parsing, serialization, and transformation utilities without external dependencies.

Evidence5/5methodologySourceInstallMaintenanceDSH versionSecurity scan
Machine-auditedInstall commandRepo verifieddsh-plugin topicLicenseREADMEAI wiki

ⓘ 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
collectiondshdsh-plugintoolkitzero-dependency

Install

cmdweb profile
$ dsh plugin --profile web add github:omdsh-dev/dsh-toolkit#path:packages/dsh-tool-csv

Run 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-csv row 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.1peer 依赖,由 host profile 提供
@deepseek-ai/dsh-tools>=0.0.1-rc.1 <0.2.0peer 依赖,由 host profile 提供
@deepseek-ai/dsh-invariants>=0.0.1-rc.1 <0.2.0peer 依赖,由 host profile 提供
平台macOS / Windows / Linux跨平台,无原生模块依赖

安装方式

dsh plugin --profile web add github:omdsh-dev/dsh-toolkit/packages/dsh-tool-csv

配置项

本插件无需配置文件;所有行为通过工具调用参数控制。

参数类型必填说明默认值
actionstring✅操作类型:parse / query / stats / to_json无
csvstring✅CSV 文本,遵循 RFC 4180;首行 BOM 自动剥离无
columnstring查询列:有表头时用列名,无表头时用 "2" 这样的 1-based 索引无
valuestring查询的精确匹配值(严格相等,非子串模糊匹配)无
delimiterstring字段分隔符,单字符或 "tab" 关键字;拒绝控制字符与代理对","
headerboolean是否把首行当作表头;关闭后行解析为数组true
limitinteger返回行数上限;非法值(非有限数 / ≤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 注释

Read the usage guide →

Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.

Listing badge

Listed on deepseek-plugin.org
[![Listed on deepseek-plugin.org](https://img.shields.io/badge/listed_on-deepseek--plugin.org-007EC6)](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.

← Back to plugin directory