Mistral Vibe Python编码规范
vibe-python-style
Mistral Vibe 的 Python 编码规范。用于在 Vibe 代码库中编写、审查或重构 Python 代码。涵盖风格、类型注解、导入、Pydantic 模式、日志、错误处理及文件 I/O。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-11
- Stars
- ★ 5.4k
- Forks
- 796
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.
Git 工作树管理
worktree
在 $VIBE_HOME/worktrees 下创建、复用和清理 git worktrees。当用户想要在隔离的 git worktree 中工作、为某个任务创建 worktree,或列出/删除现有 worktrees 时使用。
Vibe CLI 权威参考
vibe
Mistral Vibe 的权威参考——你(模型)正运行于其中的 CLI agent。 在以下情况加载本技能: - 用户询问任何关于 Vibe 本身的问题,即使是间接称呼(“这个 CLI”“这个工具”“你”); - 想要更改、检查或重置其设置; - 询问 agent 为何采取或未采取某行动; - 询问如何让 CLI 做 X、X 位于何处,或某个 flag/command/setting 的作用; - 询问关于你自身行为的任何元问题; - 不确定某个命令、flag、环境变量或文件是否在范围内——本技能即为权威来源。 范围:`~/.vibe/` 下的配置及项目本地的 `.vibe/`;`VIBE_*` 和 `LOG_*` 环境变量;模型与提供者;agents 与 subagents;skills;工具及其权限模型;所有斜杠命令和 CLI flag;hooks;MCP servers;connectors;plugins;受信任文件夹;`@` 文件引用;日志;主题;语音。
Vibe 技能创建与管理
skill-creator
在创建、更新或删除 Vibe 技能之前,或当你计划添加或修改 skills 目录下的 SKILL.md 文件时,加载本技能。它讲解 Vibe 的 SKILL.md frontmatter、发现顺序、支持文件以及权限流程。
Vibe 插件创建
create-plugin
创建 Vibe 插件包——采用 Agent Plugins 1.0 格式,并可选地包含针对 skills、MCP servers、hooks、knowledge、agents、libraries 和 connectors 的 Vibe 扩展。当用户想要为 Mistral Vibe 创建、搭建或编写插件时使用。
提示词
prompts
暂无简介