python-design
できること
このスキルは、Pythonのスクリプトとツールの設計の規則を示します。変更しやすく理解しやすいコードを求める開発者向けです。
使う場面
- ✓Pythonのファイル、特にコマンドラインスクリプトを書いたり変更したりするとき。
- ✓Pythonのプロジェクトをモジュールに分ける方法を計画しているとき。
- ✓Pythonコードをレビューして、設計の問題を見つけたいとき。
スキルのリンク
https://github.com/mindfold-ai/Trellis/blob/main/.agents/skills/python-design/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このPythonスクリプトをレビューして、設計がどこで雑然としてきて、変更しにくくなっているかを教えてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、有名なソフトウェア設計の本の規則を適用します。例えば、単純なインターフェースで深いモジュールを保つことや、変更しにくいコードの警告サインを確認することです。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Python Design for CLI Scripts
Design patterns and principles for writing maintainable Python CLI tools and utilities. Based on A Philosophy of Software Design (Ousterhout), adapted for scripting contexts.
When to Activate
- Writing or modifying Python files
- Planning module decomposition
- Code review of Python changes
- Refactoring scripts that feel "messy"
- Adding a new subcommand or utility function
Core Thesis
The central challenge is managing complexity, not adding features.
Complexity is anything that makes code hard to understand or modify. It has three symptoms:
- Change Amplification — A small change requires edits in many places
- Cognitive Load — You must hold too much context to make a safe change
- Unknown Unknowns — You don't know what you don't know (the most dangerous)
Complexity is incremental. It accumulates through hundreds of small decisions, not one catastrophic mistake. Therefore: sweat the small stuff.
Principle 1: Deep Modules
A module's value is the ratio of functionality hidden vs. interface exposed.
Deep module (good): Shallow module (bad):
┌──────────┐ ┌──────────────────────────┐
│ simple │ │ complex interface │
│ interface│ │ many params, many methods │
├──────────┤ ├──────────────────────────┤
│ │ │ │
│ rich │ │ thin implementation │
│ impl │ │ │
│ │ └──────────────────────────┘
│ │
└──────────┘
Practical test: If a caller must understand how the module works internally to use it correctly, the module is too shallow.
Example: Task Data Access
# Shallow — caller must know JSON structure, file paths, error handling
def _read_json_file(path: Path) -> dict:
with open(path, encoding="utf-8") as f:
return json.load(f)
# Every caller does this independently:
task_path = tasks_dir / name / "task.json"
data = _read_json_file(task_path)
title = data.get("title") or data.get("name", "")
status = data.get("status", "planning")
assignee = data.get("assignee", "")
# Deep — caller gets what they need, module hides JSON/path/parsing
@dataclass(frozen=True)
class TaskInfo:
name: str
title: str
status: str
assignee: str
priority: str
directory: Path
def load_task(tasks_dir: Path, name: str) -> TaskInfo | None:
"""Load task by directory name. Returns None if not found."""
...
def list_active_tasks(tasks_dir: Path) -> list[TaskInfo]:
"""List all non-archived tasks, sorted by priority."""
...
The deep version absorbs complexity: JSON parsing, field defaults, directory scanning, archive filtering. Callers just work with typed data.
Principle 2: Type-First Development
Types define contracts before implementation. This workflow catches design problems early:
- Define data shapes — dataclass or TypedDict first
- Define function signatures — parameter and return types
- Implement to satisfy types — let the type checker guide completeness
- Validate at boundaries — runtime checks only where data enters the system
Frozen Dataclasses for Internal Data
from dataclasses import dataclass
from typing import Literal
@dataclass(frozen=True)
class AgentRecord:
agent_id: str
task_name: str
worktree_path: Path
platform: Literal["Codex", "codex", "cursor"]
status: Literal["running", "done", "failed"]
branch: str
Frozen dataclasses are immutable — no accidental mutation, safe to pass around.
TypedDict for External JSON Shapes
When the data comes from a file (task.json, config.yaml, registry.json), use TypedDict to document the expected shape:
from typing import TypedDict, Required, NotRequired
class TaskData(TypedDict):
title: Required[str]
status: Required[str]
assignee: NotRequired[str]
priority: NotRequired[str]
parent: NotRequired[str]
children: NotRequired[list[str]]
This eliminates scattered .get("field", default) calls — the shape is documented once.
NewType for Domain Primitives
When two strings mean different things, make the type system enforce it:
from typing import NewType
TaskName = NewType("TaskName", str) # directory name like "03-10-v040"
BranchName = NewType("BranchName", str)
よくある質問
どんな問題を探しますか?
多くの場所に広がる変更、高い認知負荷、変更を危険にする隠れた驚きです。
Webアプリだけのものですか?
いいえ。スキルはスクリプトやコマンドラインツールのために書かれているので、そちらに最も合います。
新しい機能を加えますか?
いいえ。中心となる考えは、機能を増やすことではなく、複雑さを管理することです。
詳細
作者による元の説明
Python design patterns for CLI scripts and utilities — type-first development, deep modules, complexity management, and red flags. Use when reading, writing, reviewing, or refactoring Python files, especially in .trellis/scripts/ or any CLI/scripting context. Also activate when planning module structure, deciding where to put new code, or doing code review.
repo: mindfold-ai/Trellis
人気
- GitHubのスター
- 15k
- ランキング
- #11023
- ライセンス
- AGPL-3.0
- 更新日
- 2026/9/29
コメント
- …
このリポジトリの他のスキル
first-principles-thinking
15k計画や設計を基本的な真理に分解し、そこから積み上げて検討することで、慣習や習慣に頼らずに、それが本当に最良の方法かを確かめるよう、エージェントを手助けします。
trellis-before-dev
15k書き始める前に、プロジェクトのコーディングのガイドラインとタスクのメモを読み、エージェントがチームの慣例に従うよう手助けします。
trellis-brainstorm
15k新しい機能や不明確なタスクを、一度に一つの有益な質問をし、コードを確認し、狭いスコープに合意することで、明確にする手助けをします。
trellis-break-loop
15kバグを直した後で、その根本原因の種類と、以前の修正が失敗した理由を分析し、同じことが繰り返されないように教訓を保存するよう、エージェントを手助けします。
似ているスキル
api-connector-builder
280kエージェントが既存のパターンに従って、新しいAPI連携を構築します。新しい方式を作らずに、もう一つ連携を追加したいときに使います。
api-design
280kエージェントがベストプラクティスに沿ってREST APIを設計できるようにします。APIの通信方法、エラーの表示方法、データの整理方法を決めるのに役立ちます。
backend-patterns
280kエージェントのサーバーサイドのアーキテクチャパターンとデータベースの最適化を支援します。サーバー上で動くコードを作成またはレビューするときに役立ちます。