360 Secure SkillHub
360 安全技能中心

My Calculator

面向 OpenClaw 计算器项目的开发维护技能,指导修改 calculator.py、__main__.py 与 tests/test_calculator.py 中基于 Python AST 的安全表达式求值、受限运算符校验、CalculationError 错误处理和命令行交互,并要求补充 unittest 用例后运行 python -m unittest discover -s test…

分类:开发
lidongsjtu
lidongsjtu
热度 0.29
最近更新 2026-03-19 00:36:53

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add lidongsjtu/my-calculator
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
openclaw-calculator
description
Maintain the OpenClaw calculator project. Use when changing expression parsing, arithmetic behavior, CLI interaction, error handling, or unittest coverage for the safe AST-based calculator.
argument-hint
Describe the calculator change, bug, or test you want to add.
user-invocable
true

OpenClaw Calculator

When to Use

  • Add or change supported arithmetic behavior in the calculator.
  • Tighten validation for unsupported AST syntax or unsafe expressions.
  • Update command-line behavior for expression input or interactive mode.
  • Add or adjust regression tests for parsing, precedence, unary operators, or error cases.

Project Facts

  • Main implementation lives in calculator.py.
  • CLI entry points live in __main__.py and package exports in __init__.py.
  • Tests live in tests/test_calculator.py and use unittest.
  • The calculator evaluates parsed Python AST nodes and only allows a small set of operators.

Procedure

  1. Read calculator.py, __main__.py, and any affected tests before changing behavior.
  2. Identify whether the request changes parsing rules, supported operators, error messages, or CLI flow.
  3. Prefer small, explicit AST validation changes instead of broad eval-style execution.
  4. Preserve the safety model: only accept numeric constants, allowed binary operators, and allowed unary operators unless the task explicitly expands support.
  5. Add or update unittest coverage in tests/test_calculator.py for both success cases and rejected input.
  6. Run python -m unittest discover -s tests from the workspace root after changes.

Implementation Notes

  • Raise CalculationError for invalid input and unsupported operations.
  • Keep public behavior simple and predictable; avoid adding implicit coercions or side effects.
  • If a new operator or syntax form is added, update the allowed AST handling in one place and test at least one valid and one invalid case.
  • If CLI behavior changes, verify both direct expression execution and interactive mode.

Done Criteria

  • Behavior matches the requested calculator change.
  • Unsafe or unsupported syntax is still rejected.
  • Relevant unit tests are added or updated.
  • The unittest command passes locally.