
omdsh-dev/dsh-tool-calculator
60Last commit Aug 14, 2026
dsh-tool-calculator DSH plugin
The DSH Calculator plugin provides a safe math expression evaluator that runs in-process without spawning a shell. It uses a hand-written recursive descent parser to evaluate expressions with support for arithmetic operators, common math functions, and constants. No eval, no new Function, ensuring security.
How to install the dsh-tool-calculator DSH plugin
dsh plugin --profile web add github:omdsh-dev/dsh-tool-calculatorCopying does not run this command. Review the repository and version before installing the dsh-tool-calculator DSH plugin.
dsh-tool-calculator DSH plugin data source
dsh-tool-calculator DSH plugin snapshot date: Aug 16, 2026
discovered
What the dsh-tool-calculator DSH plugin can do
- Supports arithmetic operators: +, -, *, /, %, ** (power, right-associative)
- Supports math functions: abs, ceil, floor, round, sqrt, log, log2, log10, exp, sin, cos, tan, max, min, pow
- Supports constants: PI, E
- Hand-written recursive descent parser, no eval or new Function
- Returns finite number only; NaN/Infinity rejected
- Millisecond-level evaluation, no subprocess overhead
Where the dsh-tool-calculator DSH plugin fits
- Agent needs to calculate complex expressions with trigonometric functions
- Avoid spawning a subprocess for every arithmetic operation, reducing latency
- Perform safe math evaluation without risk of code injection
- Integrate with DSH workflows that require precise numeric computations
Who the dsh-tool-calculator DSH plugin is for
- DSH agent developers who want reliable math computation
- Users running DSH agents that need to perform calculations frequently
dsh-tool-calculator DSH plugin limitations
- Trigonometric functions use radians, not degrees
- Does not support big integers beyond IEEE 754 double precision (±9e15)
- Does not support scientific notation (e.g., 1e5)
- Only available for DSH 0.1.0-rc.6 (npm) and above
dsh-tool-calculator DSH plugin: from the repository README
Quoted from the omdsh-dev/dsh-tool-calculator README, the upstream source of the dsh-tool-calculator DSH plugin. Copyright remains with the original authors.
DSH 计算器工具插件 —— 安全的数学表达式求值器。零依赖、零进程、纯函数。 [](LICENSE) ## 动机 Agent 做算术不稳定是 LLM 的通病。DSH 内置的 `bash` 工具可以调用 `echo $((15 + 27 * 3))` 完成计算,但有两个问题: 1. **每次算术都起一个 bash 进程**——Windows 上尤其昂贵(创建进程、加载 shell、执行、收集输出),高频调用时累积延迟显著 2. **bash 算术语法有限**——不支持 `sqrt`、`sin`、`cos`、`log`、`pow` 等数学函数,agent 在这些场景下只能猜答案或写脚本 本插件提供零依赖、零进程、纯函数的计算器——一次函数调用,毫秒级得出结果,覆盖常用初等数学函数。 ## 安全模型 **无 `eval`、无 `new Function`。** 使用手写递归下降解析器(词法层 + 语法层),只求值白名单节点: - 词法层只识别数字字面量、白名单标识符、运算符;引号、分号、反引号、`{}` `[]` 直接报错 - 标识符按名查白名单表(15 个函数 + 2 个常量),查不到即抛 `Unknown identifier` - 求值结果必须是有限数字,`NaN`/`Infinity`(除零、负数开方等)统一拒绝 `new Function` + 正则白名单是**不安全的**——`constructor.constructor(...)` 可直达 `Function` 构造器执行任意代码,`process.exit(0)` 可直接杀死宿主进程(均已实测复现)。本实现不使用任何代码求值捷径。 ## 架构 ``` ┌──────────────────────────────┐ │ DSH Agent │ │ tool call: calculator { ... }│ └──────────┬───────────────────┘ │ ctx.tools.register() ┌──────────▼───────────────────┐ │ src/index.ts │ │ Cordis 插件入口 │ └──────────┬───────────────────┘ │ ┌──────────▼───────────────────┐ │ src/evaluate.ts │ │ tokenize() → parse() │
Read the full READMERepository license: MIT
dsh-tool-calculator DSH plugin questions
How do I install the DSH calculator plugin?
Use the command: dsh plugin add github:omdsh-dev/dsh-tool-calculator. You can also install via tarball by cloning the repo, running npm pack, and then using dsh plugin add ./deepseek-ai-dsh-tool-calculator-*.tgz. Make sure you are using DSH 0.1.0-rc.6 (npm) or later.
Is the calculator plugin safe from code injection?
Yes. The plugin uses a hand-written recursive descent parser, not eval or new Function. It only recognizes numbers, operators, and a whitelist of identifiers (functions and constants). Quotes, semicolons, backticks, curly braces, and square brackets are rejected at the lexical level. This prevents attackers from executing arbitrary code.
What math functions does the plugin support?
It supports: abs, ceil, floor, round, sqrt, log, log2, log10, exp, sin, cos, tan, pow, max, min. It also includes constants PI and E. For a full list, check the tool description when registering the plugin.
Can I use degrees instead of radians for trigonometric functions?
No. The plugin uses radians for sin, cos, and tan, consistent with JavaScript's Math functions. To use degrees, convert manually in the expression: sin(30 * PI / 180).
Why does the plugin reject scientific notation like 1e5?
The lexical analyzer does not recognize the 'e' notation as a valid number literal. This is a known limitation. You can rewrite 1e5 as 1 * 10**5 or 100000 in the expression.