vibe-python-style
Python coding conventions for Mistral Vibe. Use when writing, reviewing, or refactoring Python code in the Vibe codebase. Covers style, type hints, imports, Pydantic patterns, logging, error handling, and file I/O.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-11
- Stars
- ★ 5.4k
- Forks
- 795
01 前言 Front Matter
- name
- vibe-python-style
- metadata
- { "display-name": "Vibe Python Style", "default-prompt": "Use $vibe-python-style to follow Vibe Python conventions when writing or reviewing code.", "short-description": "Python style and patterns for Vibe" }
- description
- Python coding conventions for Mistral Vibe. Use when writing, reviewing, or refactoring Python code in the Vibe codebase. Covers style, type hints, imports, Pydantic patterns, logging, error handling, and file I/O.
03 SKILL.md 正文
Vibe Python Style
Conventions for writing Python in the Vibe codebase. Apply whenever writing, reviewing, or refactoring Python code.
Style
- Prefer
match/caseover longif/elifchains. - Use the walrus operator
:=only when it shortens code and improves clarity. - Be a never-nester: early returns and guard clauses over nested blocks.
- Modern type hints only: built-in generics (
list,dict) and|unions. Never importOptional,Union,Dict,Listfromtyping. - Use
pathlib.Path(andanyio.Pathin async paths) instead ofos.path. - Use f-strings, comprehensions, and context managers; follow PEP 8.
- Enums:
StrEnum/IntEnumwithauto()and UPPERCASE members. For type-mixing, the mix-in type comes beforeEnumin the bases. Add methods or@propertyrather than parallel lookup tables. - Write declarative, minimalist code: express intent, drop boilerplate.
- Never call a private method from outside of its class in production code. Accessing private methods in tests is acceptable.
- Avoid comments and docstrings, except for when there's a hard to spot corner case
Typing & imports
- Pyright is strict and gates CI; fix types at the source.
- No relative imports —
ban-relative-imports = "all". Alwaysfrom vibe.core.x import …. - No inline
# type: ignoreor# noqa. Fix with refined signatures (TypeVar, Protocol),isinstanceguards,typing.castwhen control flow guarantees the type, or a small typed wrapper at the boundary.
TYPE_CHECKING and lazy imports
Moving imports under if TYPE_CHECKING: or into function bodies cuts startup time but risks runtime NameError. Before merging any import-deferral change, run:
- Ruff
TC004(pre-commit hook) — per-file: flagsTYPE_CHECKING-only names referenced at runtime. uv run python scripts/check_import_contracts.py— runtime cross-file: imports everyfrom <mod> import <name>acrossvibe/andtests/to verify it resolves; also rebuilds Pydantic models to catch lazily-failing field types. Catches cross-file re-exportsTC004misses. Missing non-vibe deps are non-blocking warnings.uv run scripts/suggest_lazy_imports.py— informational: reports deferral candidates (TC001–TC003+ single-function heuristic). Not gated.
Pydantic
- Parse external data via
model_validate,field_validator, ormodel_validator(mode="before")— never ad-hocgetattr/hasattrwalks or customfrom_sdkconstructors. - Set
ConfigDict(extra=…)explicitly. Usevalidation_alias(or field aliases) for kebab-case TOML keys. - Discriminated unions (e.g. MCP
transport): use sibling final classes plus a shared base/mixin, and compose withAnnotated[Union[...], Field(discriminator=...)]. Never narrow the discriminator field in a subclass — it violates LSP and pyright will reject it. - Document
Raises:only for exceptions the function actually raises (or that propagate from public API calls). Don't list speculative built-ins.
Logging & errors
- Use
from vibe.observability.logging import logger— stdlibloggingwithStructuredLogFormatter, notstructlog. - Configure via env:
LOG_LEVEL(defaultWARNING),LOG_MAX_BYTES. Logs land in~/.vibe/logs/vibe.log. - Pass variables as
%spositional args, not f-string interpolation: preferlogger.error("Failed to fetch url=%s", url)overlogger.error(f"Failed to fetch {url}"). This defers formatting to the logging framework (only formats if the message is emitted) and keeps messages grep-friendly. - Define module-local exception hierarchies. Always chain with
raise NewError(...) from e. Rich exceptions expose a_fmt()helper for human-readable output.
File I/O
- Prefer
vibe.core.utils.io.read_safe/read_safe_async/decode_safeover rawPath.read_text(),Path.read_bytes().decode(), oropen(). - They return
ReadSafeResult(text, encoding)and try UTF-8, then BOM detection, then locale, thencharset_normalizerlazily. - Pass
raise_on_error=Trueonly when callers must distinguish corrupt files from valid ones; the default replaces undecodable bytes with U+FFFD.
04 同仓库更多 Skills
import
Import the user's setup from other coding CLIs (Claude Code, Codex, OpenCode) into Vibe — instructions, skills, subagents, commands, hooks, MCP servers, permissions, and plugins. Load when the user wants to switch to Vibe, import or reuse another CLI's configuration, or asks whether a file from another CLI works in Vibe.
worktree
Create, reuse, and clean up git worktrees under $VIBE_HOME/worktrees. Use when the user wants to work in an isolated git worktree, create a worktree for a task, or list/remove existing worktrees.
vibe
Authoritative reference for Mistral Vibe — the CLI agent you (the model) are running inside. LOAD when the user: - asks anything about Vibe itself, even by indirect name ("this CLI", "this tool", "you"); - wants to change, inspect, or reset their setup; - asks why the agent did or did not act; - asks how to make the CLI do X, where X lives, or what a flag/command/setting does; - asks any meta question about your own behavior; - is unsure whether a command, flag, env var, or file is in scope — this skill is the source of truth. SCOPE: config under `~/.vibe/` and project-local `.vibe/`; `VIBE_*` and `LOG_*` env vars; models and providers; agents and subagents; skills; tools and their permission model; every slash command and CLI flag; hooks; MCP servers; connectors; plugins; trusted folders; `@`-file mentions; logs; themes; voice.
skill-creator
Load this skill before creating, updating, or deleting a Vibe skill, or whenever you plan to add or modify SKILL.md files under a skills directory. It explains Vibe's SKILL.md frontmatter, discovery order, support files, and the permission flow.
create-plugin
Create a Vibe plugin package — the Agent Plugins 1.0 format with optional Vibe extensions for skills, MCP servers, hooks, knowledge, agents, libraries, and connectors. Use when the user wants to create, scaffold, or author a plugin for Mistral Vibe.
prompts
暂无简介