python-script

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Python Scripter

Python 脚本编写工具

Overview

概述

Design and run Python scripts with clear requirements, safety checks, and reproducible logging.
设计并运行具备明确需求、安全检查与可复现日志记录的Python脚本。

Workflow

工作流程

  1. Confirm inputs, outputs, constraints, and preferred libraries.
  2. Identify risky operations and secure explicit approval.
  3. Scaffold a script with PEP 723 metadata and structured logging.
  4. Lint with
    uvx ruff check --fix .agents/scripts/{script_name}.py
    .
  5. Run with
    uv run --script .agents/scripts/{script_name}.py
    and monitor logs.
  6. Report results, risks encountered, and any follow-up steps.
  1. 确认输入、输出、约束条件及首选库。
  2. 识别高风险操作并获取明确许可。
  3. 基于PEP 723元数据和结构化日志搭建脚本框架。
  4. 使用
    uvx ruff check --fix .agents/scripts/{script_name}.py
    进行代码检查与修复。
  5. 通过
    uv run --script .agents/scripts/{script_name}.py
    运行脚本并监控日志。
  6. 汇报执行结果、遇到的风险及后续步骤。

Logging requirements

日志记录要求

  • Log to
    .agents/logs/{script_name}.log
    and stream to console
  • Capture start/end timestamps, parameters, file operations, and errors
  • Add
    RotatingFileHandler
    if logs may grow large
  • 日志输出至
    .agents/logs/{script_name}.log
    同时输出到控制台
  • 捕获开始/结束时间戳、参数、文件操作及错误信息
  • 若日志可能过大,添加
    RotatingFileHandler

Template

模板

Read
references/script-template.md
for the full script template.
查看
references/script-template.md
获取完整脚本模板。

Safety practices

安全实践

  • Provide dry-run or rollback paths
  • Validate external inputs and API responses
  • Use temporary directories for intermediates
  • Never run destructive steps without confirmation
  • 提供dry-run或回滚路径
  • 验证外部输入与API响应
  • 使用临时目录存储中间文件
  • 未经确认绝不执行破坏性操作