x-format-code
Formats source code using the appropriate formatter for {{LANGUAGE}}. First step of the pre-commit chain (format -> lint -> compile -> commit). Supports --check (dry-run) and --changed-only modes.
- License 许可
- MIT
- 最近更新
- 2026-10-27
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- x-format-code
- model
- haiku
- description
- Formats source code using the appropriate formatter for {{LANGUAGE}}. First step of the pre-commit chain (format -> lint -> compile -> commit). Supports --check (dry-run) and --changed-only modes.
- allowed-tools
- Bash, Read, Grep, Glob
- argument-hint
- [--check | --changed-only]
- context-budget
- light
- user-invocable
- true
- requires-capabilities
- []
02 资源文件 1
- 参考文档references/full-protocol.md6.0 KB
03 SKILL.md 正文
Global Output Policy
- Language: English ONLY.
- Tone: Technical, Direct, and Concise.
- Efficiency: Remove all conversational fillers and greetings to save tokens.
Skill: Format Code (slim — ADR-0012)
Ensures source code in {{PROJECT_NAME}} follows a consistent style before commits. First step of the pre-commit chain (RULE-007: x-format-code -> x-lint-code -> compile -> commit). Detects {{LANGUAGE}}, selects the appropriate formatter, runs it, and re-stages modified files automatically.
Triggers
/x-format-code-- format all project files/x-format-code --check-- verify formatting without modifying files (CI mode)/x-format-code --changed-only-- format only modified files (staged + unstaged)
Parameters
| Parameter | Required | Description |
|---|---|---|
--check |
No | Dry-run: exit 0 if formatted, exit 1 if not. No files modified. |
--changed-only |
No | Format only files detected via git diff (staged + unstaged). |
Output Contract
- Mutation: files formatted in place (unless
--check). Previously-staged files are automatically re-staged after format. - Exit codes:
0success / nothing to do;1formatter not installed, execution failure, or violations under--check. - Report to stdout: language, formatter used, files checked, files reformatted, files re-staged.
- Supported languages / formatter commands: see
references/full-protocol.md§1 for the full mapping. Slim summary: spotless (java), prettier (typescript), ruff/black (python), gofmt (go), rustfmt (rust), ktfmt (kotlin).
Error Envelope
Chain-wide error matrix. Canonical
format -> lint -> compile -> commitrows live in_shared/error-handling-pre-commit.md. Rows below arex-format-code-specific.
| Scenario | Behavior | Exit |
|---|---|---|
Unsupported language ({{LANGUAGE}} not in table) |
Report warning, do NOT block chain | 0 |
| No formatter installed (primary + fallback missing) | Report error with install instructions | 1 |
| Formatter execution fails | Report error with stderr output | 1 |
| No files to format | Report "No files to format" |
0 |
--check finds violations |
List files needing formatting | 1 |
Re-stage failure (git add error) |
Report error with git stderr | 1 |
Full Protocol
Minimum viable contract above. Detailed language/formatter mapping, the 6-step workflow (detect → select → scope → execute → re-stage → report), build-tool configuration examples (Maven/Gradle/npm/Python/Go/Rust), and per-language file extension lists live in references/full-protocol.md per ADR-0012 (skill body slim-by-default). Happy-path invocation needs only this SKILL.md; full protocol is consulted when a new language or fallback formatter is introduced.
Integration Notes
| Skill | Relationship | Context |
|---|---|---|
x-lint-code |
follows | Second step of the pre-commit chain (after format). |
x-commit-changes |
orchestrator | Invokes this skill as step 3a of its chain. |
Template Variables
| Variable | Description | Example |
|---|---|---|
{{LANGUAGE}} |
Project language | java |
{{BUILD_TOOL}} |
Project build tool | maven |
{{PROJECT_NAME}} |
Project name | my-java-cli |
04 同仓库更多 Skills
x-parallel-eval
Detects and classifies file-collision risks between work units (tasks, stories, or epic phases) before parallel execution. Reads ## File Footprint blocks produced by x-task-plan / x-story-plan, applies the parallelism-heuristics knowledge pack (hard / regen / soft categories + hotspot overrides), and emits a collision matrix + serialization recommendation in Markdown (default) or JSON.
parallelism-heuristics
Canonical catalog of file-collision heuristics for parallel task, story, and epic execution. Defines the File Footprint block format, the three Conflict Categories (hard / regen / soft), a hotspot list of high-contention paths, and the degrade-with-warning policy. Consumed by x-task-plan, x-story-plan, x-epic-map, x-parallel-eval, and x-dev-*-implement.
x-watch-pr-ci
Polls a PR's CI checks and Copilot review status, blocking until checks complete or timeout. Returns one of 8 stable exit codes (SUCCESS=0, CI_PENDING_PROCEED=10, CI_FAILED=20, TIMEOUT=30, PR_ALREADY_MERGED=40, NO_CI_CONFIGURED=50, PR_CLOSED=60, PR_NOT_FOUND=70). Writes a versioned state-file for session resume.
x-validate-docs
Documentation freshness gate: validates 6 dimensions (readme, api-specs, grpc-proto, adr, skill-docs, system-architecture) against code changes in a PR. Stack-aware — only validates targets declared/auto-detected from ProjectConfig.documentation.targets. Returns exit non-zero on staleness; produces structured report.
x-update-system-architecture
Incrementally updates docs/architecture/system.md after an epic completes. Appends new entries to the Decision Log (§11) using x-internal-write-report --append (dedup by ## ID: marker) and surgically inserts component/integration changes into sections 1-10 via Edit. Idempotent: re-running with the same epic produces a byte-identical system.md.
x-update-architecture
Incrementally updates the service architecture document with changes from architecture plans. Adds new components, integrations, flows, and ADR references without rewriting existing content. Use after implementation to keep architecture documentation current.