python-design
यह क्या करती है
यह स्किल Python स्क्रिप्ट और टूल के लिए डिज़ाइन नियम देती है। यह उन डेवलपर्स के लिए है जिन्हें ऐसा कोड चाहिए जिसे बदलना और समझना आसान हो।
कब इस्तेमाल करें
- ✓जब आप Python फ़ाइलें लिखते या बदलते हैं, खासकर command-line स्क्रिप्ट।
- ✓जब आप योजना बना रहे हैं कि Python प्रोजेक्ट को मॉड्यूल में कैसे बाँटें।
- ✓जब आप Python कोड की समीक्षा करते हैं और डिज़ाइन की समस्याएँ पकड़ना चाहते हैं।
Skill का लिंक
https://github.com/mindfold-ai/Trellis/blob/main/.agents/skills/python-design/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“इस Python स्क्रिप्ट की समीक्षा कीजिए और बताइए कि इसका डिज़ाइन कहाँ उलझ रहा है या बदलना कठिन हो रहा है।”
हर हफ़्ते 5 नई skills, 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)
अक्सर पूछे जाने वाले सवाल
यह कौन-सी समस्याएँ खोजती है?
ऐसे बदलाव जो कई जगह फैलते हैं, भारी मानसिक बोझ, और छिपे आश्चर्य जो कोड को बदलना जोखिम भरा बनाते हैं।
क्या यह केवल वेब ऐप के लिए है?
नहीं। स्किल स्क्रिप्ट और command-line टूल के लिए लिखी गई है, इसलिए वे इसके लिए सबसे उपयुक्त हैं।
क्या यह नई सुविधाएँ जोड़ती है?
नहीं। इसका मुख्य विचार फ़ीचर जोड़ने के बजाय जटिलता को संभालना है।
जानकारी
लेखक का मूल विवरण
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
- अपडेट की गई
- 29/9/2026
कमेंट
- …
इस repository की और skills
first-principles-thinking
15kयोजना या डिज़ाइन को बुनियादी सच्चाइयों में तोड़कर और उनसे ऊपर तर्क करके जाँचने में आपके एजेंट की मदद करती है, आदत या परंपरा पर भरोसा किए बिना।
trellis-before-dev
15kकोड लिखना शुरू करने से पहले प्रोजेक्ट के कोडिंग दिशानिर्देश और कार्य-नोट्स पढ़ने में आपके एजेंट की मदद करती है, ताकि वह टीम की परंपराओं का पालन करे।
trellis-brainstorm
15kएक समय में एक उपयोगी सवाल पूछकर, कोड जाँचकर और एक संकीर्ण दायरे पर सहमति बनाकर नए फ़ीचर या अस्पष्ट काम को स्पष्ट करने में आपके एजेंट की मदद करती है।
trellis-break-loop
15kठीक किए गए बग का विश्लेषण करने, उसका मूल कारण प्रकार और पिछले सुधार क्यों विफल हुए यह खोजने, और दोहराव रोकने के लिए सबक सहेजने में आपके एजेंट की मदद करती है।
मिलती-जुलती skills
api-connector-builder
280kयह आपके एजेंट को मौजूदा pattern के हिसाब से नए API connections बनाने देता है। जब बिना कोई नया तरीका बनाए एक और integration जोड़ना हो, तब इसका इस्तेमाल करें।
api-design
280kयह आपके एजेंट को best practices के हिसाब से REST APIs डिज़ाइन करने में मदद करता है। यह तय करने में काम आता है कि APIs आपस में कैसे बात करें, errors कैसे दिखें, और data को कैसे व्यवस्थित करें।
backend-patterns
280kआपके एजेंट को server-side architecture patterns और database optimization में मदद करता है। server पर चलने वाला code बनाने या review करने के लिए उपयोगी है।