dsh-calculator
Manifest validAdds a calculate tool backed by a hand-written parser with no eval, batch evaluation and an exact-decimal mode for money math.
DSH Calculator
A deterministic math tool for DSH agents: it gives the model a
real evaluation engine instead of mental arithmetic, so 0.1 + 0.2 answers 0.3 and money math does
not drift.
The engine is a hand-written tokenizer plus a recursive-descent parser — no eval, no Function —
in one dependency-free file, core.js.
What it does
- Operators:
+ - * / ^ (or **) % !, parentheses, unary minus, scientific notation1.5e-3, and the× ÷ − ×aliases. - Constants:
pi e tau phi inf. - Functions:
sqrt cbrt abs sign ceil floor round trunc exp expm1 ln log(x) log(x,base) log2 log10 sin cos tan asin acos atan atan2 sinh cosh tanh pow mod gcd lcm min max hypot radians degrees. - Matrices (float mode): literals
[[1,2],[3,4]], row vectors[1,2,3];+ -elementwise,*matrix multiply (A * [x,y]treats the vector as a column), scalar*and/,A^ninteger power (negative = inverse),A'transpose; functionsdet inv transpose trace rank solve(A,b) dot cross norm eye zeros ones shape. - Variables: pass
variables: {"r": 3.5}and referencerin the expression; a value may also be a matrix (number[][]) or a vector (number[]). - Batches: pass an array as
expression, up to 50 expressions per call. - Actionable errors: syntax, domain and division-by-zero failures come back with a position, so the model can correct itself instead of guessing.
- Two precisions:
float(default) — IEEE doubles, output rounded to 15 significant digits.exact— arbitrary-precision decimal (BigInt backed) for money math. Supports+ - * / %, integer^and!; functions and irrational constants are rejected explicitly rather than silently rounded.
Install
From the plugin market (search for "DSH Calculator"), or by hand:
dsh plugin --profile web add https://github.com/QqiqiQ/dsh-calculator/releases/latest/download/dsh-calculator.tgz
Then restart dsh web. The bundle registers a single calculate tool for every session of the profile,
and appends a short usage rule to the system prompt so the model reaches for the tool instead of
estimating.
Usage
// single expression
{ "expression": "sqrt(2)^2" } // → 2
// variables
{ "expression": "2 * pi * r", "variables": { "r": 3 } } // → 18.8495559215388
// batch
{ "expression": ["0.1 + 0.2", "10!", "log(8, 2)"] } // → 0.3 / 3628800 / 3
// exact decimal mode
{ "expression": "price * qty",
"variables": { "price": "19.99", "qty": 3 },
"precision": "exact" } // → 59.97
// matrices
{ "expression": "[[1,2],[3,4]] * [[5,6],[7,8]]" } // → [[19, 22], [43, 50]]
{ "expression": "solve([[2,1],[1,3]], [1,2])" } // → [0.2, 0.6]
{ "expression": "det(A)", "variables": { "A": [[1,2],[3,4]] } } // → -2
OpenCode (optional)
The same engine also runs as an OpenCode custom tool —
opencode/tools/calculate.ts; the tool name comes from the filename.
Copy it together with a copy of core.js named calculator.core.js into .opencode/tools/ (project)
or ~/.config/opencode/tools/ (global):
$dst = "<your project>\.opencode\tools"
New-Item -ItemType Directory -Force $dst
Copy-Item .\opencode\tools\calculate.ts $dst
Copy-Item .\core.js "$dst\calculator.core.js"
Re-copy calculator.core.js after upgrading the engine, so both sides stay on the same implementation.
Development
node test.js # 81 assertions, no dependencies
License
MIT
Comments
Loading…
Similar plugins
by omdsh-dev
DSH 计算器工具插件:安全的数学表达式求值器,零依赖递归下降解析器
★ 9
MIT
TypeScript
Sep 10, 2026
dsh plugin --profile web add @deepseek-ai/dsh-tool-calculatorby omdsh-dev
DSH 零依赖工具包 collection —— time / encoding / json / calculator / csv / regex / markdown / diff / stat / schema 十个确定性工具,统一入口一键安装
★ 33
MIT
TypeScript
Sep 10, 2026
dsh plugin --profile web add @deepseek-ai/dsh-toolkitElectrical and electronics calculation plugin for DeepSeek Harness: every computation runs through dedicated tools on self-describing complex value objects in SI base units, with an isolated calculati
★ 0
↓ 378/wk
dsh plugin --profile web add dsh-electro-lab余额看板,可以添加多个按量计费/Token plan,同时查询余额。| Balance dashboard, allowing the addition of multiple pay-as-you-go/Token plans, while simultaneously checking balances.
★ 0
MIT
JavaScript
dsh plugin --profile web add dsh-balance-inquiryby zlZayn
DSH 插件:在左侧栏底部显示 DeepSeek 账户余额(原生 UI),设置页提供连接、展示币种、预警阈值与刷新节奏的配置卡片。(原生嵌入“设置-插件-插件配置”)
★ 2
↓ 362/wk
MIT
TypeScript
Sep 19, 2026
dsh plugin --profile web add dsh-ds-balanceby raphael-y7
把 DSH 桌面端底部的统计行换成可配置状态栏:10 个字段可选可排序,按 DeepSeek 官方峰谷口径估算费用,支持自定义模型单价与账户余额。非商业许可。
★ 7
↓ 531/wk
NOASSERTION
JavaScript
Oct 30, 2026
dsh plugin --profile web add dsh-desktop-statusbar