Index of every page on this site: llms.txt
All skills
victory-hugo avatar

/python-dual-mode

@0b19307
Run it yourself

将既有或新编写的 Python 脚本重构为双模式模块,用于稳定、可维护的数据处理流。

  • 1 file
  • 3 KB
  • Updated 9 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/victory-hugo/s2-agent-skill/python-dual-mode

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈32 tokens for metadata: the name and description. ≈735 when used: this file.

How this Skill uses context

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈61 characters, or 0.8%.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

指令

触发条件(When to use)

  • 仅在编写或改写 Python 代码为数据处理流时使用。
  • 输入包含:现有脚本、需求描述,或需要从零生成脚本,但明确要求双模式模块化。

能力范围(Must / Must Not)

  • 必须生成一个可被 import 调用且可通过 CLI 运行的 Python 模块。
  • 必须提供一个 run()(或语义等价命名)函数,参数覆盖原脚本全部输入。
  • 必须使用 argparse 解析命令行参数,并在 main() 中调用 run()。
  • 必须保留 if __name__ == "__main__":,且仅在其中调用 main()。
  • 必须将硬编码路径与环境依赖参数化,不得写死路径。
  • 不得在 run() 中读取全局变量、环境变量或命令行状态。
  • 不得在 import 时触发主流程执行。
  • 不得假设未声明的外部资源、权限或运行环境。

结构与实现要求

  • 模块结构:

    • run(...):纯函数式主流程,显式参数输入,返回结构化结果或状态码。
    • build_parser()(可选):集中定义 CLI 参数,避免散落。
    • main(argv=None):解析参数并调用 run();argv 可注入以便测试。
  • 错误处理:

    • 预期错误(参数缺失、文件不存在、格式错误)必须抛出可读异常或返回非 0 状态码。
    • 不确定性(外部 I/O、第三方库行为)必须有失败策略(重试/降级/明确失败)。
  • 日志:

    • 应当使用 logging,不得使用 print 作为主要日志。
  • 可测试性:

    • run() 应当可被单元测试直接调用。

失败策略与不确定性处理

  • 参数校验失败:立即失败,给出最小可行动错误信息。
  • I/O 失败:明确失败原因;如允许重试,需显式声明次数与退避策略。
  • 第三方依赖异常:捕获并封装为领域错误,避免泄露内部栈信息(调试模式除外)。

安全与合规

  • 不得执行越权操作(如未声明的网络访问、系统修改)。
  • 不得隐式调用外部命令或下载资源,除非明确声明并获得输入授权。

输出物

  • 生成的 Python 文件必须:

    • 可被 import 使用;
    • 可通过 python module.py --args 运行;
    • 文档化参数与示例用法。

示例骨架(非实现,仅结构)

import argparse
import logging

log = logging.getLogger(__name__)

def run(input_path: str, output_path: str, **kwargs):
    """Pure entry point."""
    # ...
    return 0


def build_parser():
    p = argparse.ArgumentParser()
    p.add_argument("--input-path", required=True)
    p.add_argument("--output-path", required=True)
    return p


def main(argv=None):
    parser = build_parser()
    args = parser.parse_args(argv)
    return run(**vars(args))


if __name__ == "__main__":
    raise SystemExit(main())

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 0b19307. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 9 months ago

README badge

README badge for victory-hugo/s2-agent-skill/python-dual-mode