python-design
Fungsinya
Skill ini memberi aturan desain untuk skrip dan alat Python. Untuk developer yang ingin kode yang mudah diubah dan mudah dipahami.
Kapan dipakai
- βSaat Anda menulis atau mengubah file Python, terutama skrip baris perintah.
- βSaat Anda merencanakan cara memecah proyek Python menjadi modul.
- βSaat Anda meninjau kode Python dan ingin menemukan masalah desain.
Link skill
https://github.com/mindfold-ai/Trellis/blob/main/.agents/skills/python-design/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTinjau skrip Python ini dan beri tahu saya di mana desainnya mulai berantakan atau sulit diubah.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent menerapkan aturan dari buku desain perangkat lunak yang terkenal, seperti menjaga modul tetap dalam dengan antarmuka sederhana, dan memeriksa tanda peringatan yang membuat kode sulit diubah.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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)
Pertanyaan umum
Masalah apa yang dicari?
Perubahan yang menyebar ke banyak tempat, beban mental yang tinggi, dan kejutan tersembunyi yang membuat kode berisiko diubah.
Apakah hanya untuk aplikasi web?
Tidak. Skill ini ditulis untuk skrip dan alat baris perintah, jadi paling cocok untuk itu.
Apakah menambahkan fitur baru?
Tidak. Ide utamanya adalah mengelola kompleksitas, bukan menambah fitur.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 15k
- Peringkat
- #11023
- Lisensi
- AGPL-3.0
- Diperbarui
- 29/9/2026
Komentar
- β¦
Skill lain dari repositori ini
first-principles-thinking
15kMembantu agent Anda menguji rencana atau desain dengan memecahnya menjadi kebenaran dasar dan bernalar dari situ, bukan mengandalkan kebiasaan atau konvensi.
trellis-before-dev
15kMembantu agent Anda membaca panduan coding proyek dan catatan tugas sebelum mulai menulis kode, sehingga mengikuti konvensi tim.
trellis-brainstorm
15kMembantu agent Anda memperjelas fitur baru atau tugas yang belum jelas dengan mengajukan satu pertanyaan bermanfaat setiap kali, memeriksa kode, dan menyepakati ruang lingkup yang sempit.
trellis-break-loop
15kMembantu agent Anda menganalisis bug setelah diperbaiki, menemukan jenis penyebab utamanya dan alasan perbaikan sebelumnya gagal, serta menyimpan pelajaran untuk mencegah terulang.
Skill serupa
api-connector-builder
280kMembuat agent Anda membangun koneksi API baru mengikuti pola yang sudah ada. Gunakan saat ingin menambah integrasi lagi tanpa membuat cara baru.
api-design
280kMembantu agent Anda merancang REST API sesuai praktik terbaik. Berguna untuk mengatur cara API berkomunikasi, menampilkan error, dan mengorganisasi data.
backend-patterns
280kMembantu agent Anda dengan pola arsitektur sisi server dan optimasi database. Berguna untuk membangun atau meninjau kode yang berjalan di server.