Squashed 'docs/standards/playbook/' changes from e504a68..b529012

b529012  test(tests): avoid hardcoded missing path
07583c8 🐛 fix(tests): make doc link check awk-portable
6244aa3 🔧 chore(ci): relax gitattributes check
31dd0c5 🐛 fix(scripts): require existing project root
15d4d63 🔧 chore(ci): install python3-pip
90c6313 🔧 chore(ci): run tests in a single job
d84eff0 🔧 chore(ci): make actions base url configurable
395598d 🔧 chore(ci): fix yaml step names
4ae2733  feat(sync_standards): auto-detect existing languages
e97fb00  feat(sync_standards): default gitattributes to append
da0ef2b  test: add automated tests and ci workflow
99bef30 🎨 style(markdown): format all markdown files with prettier
7e96bc8 ♻️ refactor(tsl): split function.md into 44 modular files
0d6b2a0 📝 docs(readme): add quick decision table and TL;DR for distribution methods
3b2188f 🎨 style(markdown): format markdown files with prettier
41fc43b 📝 docs(tsl): document {Unit.}Type source annotation
3dceaf7 📝 docs(tsl): clarify tsf-only top-level rules and type annotations
3a63829 📝 docs(skills): add create-plan skill
f02a707 🐛 fix(scripts): escape markdown backticks in vendor_playbook
064aa92 🐛 fix(scripts): correct bat scripts
4881feb 🔧 chore(gitattributes): enforce crlf for bat files
1fa3e2a 🐛 fix(scripts): escape parentheses in sync_standards output
3958cad 📝 docs(vendor_playbook): mention ci templates
9d059cf  feat(templates): add gitea ci example
a52bb24 📝 docs(codex_skills): normalize markdown formatting
cc8ad4c 📝 docs(skills): slim commit-message
2a98e15 🐛 fix(skills): quote YAML descriptions
8f78d22 🐛 fix(sync_standards): generate minimal AGENTS.md
5547665  feat(skills): add commit-message suggestion skill
3fe8bd7 🔧 chore(sync_standards): create AGENTS.md on sync
283d311  feat(playbook): add syntax book and codex skills tooling
5b97ed5 📝 docs(tsl): clarify syntax references
27e0700  feat(skills): add pdf/docx/pptx/xlsx wrapper workflows
5551363  feat(skills): add debugging and bulk refactor workflows
1d4f548  feat(skills): add built-in workflow skills
c0895dd 📝 docs(skills): add anthropics document-skills integration
cf9f80d 🔧 chore(playbook): add Claude Code skills guide and align python templates

git-subtree-dir: docs/standards/playbook
git-subtree-split: b529012c59c5d67c3073884d7b617763647417fd
This commit is contained in:
csh
2026-01-08 15:56:36 +08:00
parent eada742d75
commit ac794a6a70
113 changed files with 254751 additions and 176 deletions
+34
View File
@@ -0,0 +1,34 @@
# CI 模板(templates/ci
本目录提供“目标项目可复制启用”的 CI 模板示例,用于在 CI 中自动化校验部分 Playbook 规范。
当前提供:
- `gitea/`Gitea ActionsGitHub Actions 语法)
## 使用(Gitea Actions
前提:目标项目已经 vendoring Playbook(例如 `docs/standards/playbook/`)。
复制到目标项目根目录:
```sh
cp -R docs/standards/playbook/templates/ci/gitea/.gitea ./
```
提交:
```sh
git add .gitea
git commit -m ":memo: docs(ci): add standards check workflow"
```
## commit message 校验
工作流会运行 `.gitea/ci/commit_message_lint.py`
- 规范来源(自动探测其一):
- `docs/common/commit_message.md`
- `docs/standards/playbook/docs/common/commit_message.md`
- 默认要求 emoji;如需允许无 emoji:在 workflow 中设置
`COMMIT_LINT_REQUIRE_EMOJI=0`
@@ -0,0 +1,210 @@
#!/usr/bin/env python3
from __future__ import annotations
import json
import os
import pathlib
import re
import subprocess
import sys
from typing import Dict, List, Optional, Tuple
def _eprint(*args: object) -> None:
print(*args, file=sys.stderr)
def _git(*args: str) -> str:
return subprocess.check_output(["git", *args], text=True).strip()
def _repo_root() -> pathlib.Path:
return pathlib.Path(_git("rev-parse", "--show-toplevel"))
def _find_commit_spec(root: pathlib.Path) -> pathlib.Path:
candidates = [
root / "docs" / "common" / "commit_message.md",
root / "docs" / "standards" / "playbook" / "docs" / "common" / "commit_message.md",
]
for path in candidates:
if path.is_file():
return path
raise FileNotFoundError(
"commit_message.md not found; expected one of:\n"
+ "\n".join(f"- {p}" for p in candidates)
)
def _parse_type_emoji_mapping(md_text: str) -> Dict[str, str]:
mapping: Dict[str, str] = {}
for raw_line in md_text.splitlines():
line = raw_line.strip()
if not (line.startswith("|") and line.endswith("|")):
continue
if "type" in line and "emoji" in line:
continue
if re.fullmatch(r"\|\s*-+\s*(\|\s*-+\s*)+\|", line):
continue
cols = [c.strip() for c in line.strip("|").split("|")]
if len(cols) < 2:
continue
m_type = re.search(r"`([^`]+)`", cols[0])
m_emoji = re.search(r"`(:[^`]+:)`", cols[1])
if not m_type or not m_emoji:
continue
type_name = m_type.group(1).strip()
emoji_code = m_emoji.group(1).strip()
mapping[type_name] = emoji_code
if not mapping:
raise ValueError("failed to parse type/emoji mapping from commit_message.md")
return mapping
def _validate_subject_line(
line: str,
mapping: Dict[str, str],
*,
require_emoji: bool,
) -> Optional[str]:
subject = line.strip()
if not subject:
return "empty subject"
m = re.match(
r"^(?:(?P<emoji>:[a-z0-9_+-]+:)\s+)?"
r"(?P<type>[a-z]+)"
r"(?P<scope>\([a-z0-9_]+\))?"
r":\s+(?P<text>.+)$",
subject,
)
if not m:
return "does not match ':emoji: type(scope): subject' or 'type(scope): subject'"
emoji = m.group("emoji")
type_name = m.group("type")
text = (m.group("text") or "").rstrip()
if type_name not in mapping:
return f"unknown type: {type_name}"
if emoji:
expected = mapping[type_name]
if emoji != expected:
return f"emoji/type mismatch: got {emoji} {type_name}, expected {expected} for type {type_name}"
elif require_emoji:
return "missing emoji (set COMMIT_LINT_REQUIRE_EMOJI=0 to allow)"
if text.endswith((".", "")):
return "subject should not end with a period"
return None
def _load_event_payload() -> Tuple[str, Optional[dict]]:
event_name = os.getenv("GITHUB_EVENT_NAME") or os.getenv("GITEA_EVENT_NAME") or ""
event_path = os.getenv("GITHUB_EVENT_PATH") or os.getenv("GITEA_EVENT_PATH") or ""
if not event_path:
return event_name, None
path = pathlib.Path(event_path)
if not path.is_file():
return event_name, None
try:
return event_name, json.loads(path.read_text(encoding="utf-8"))
except Exception as exc:
_eprint(f"WARN: failed to parse event payload: {path} ({exc})")
return event_name, None
def _gather_subjects(event_name: str, payload: Optional[dict]) -> List[Tuple[str, str]]:
subjects: List[Tuple[str, str]] = []
if isinstance(payload, dict):
if event_name.startswith("pull_request"):
pr = payload.get("pull_request")
if isinstance(pr, dict):
title = (pr.get("title") or "").strip()
if title:
subjects.append(("pull_request.title", title.splitlines()[0].strip()))
if event_name == "push":
commits = payload.get("commits")
if isinstance(commits, list):
for commit in commits:
if not isinstance(commit, dict):
continue
msg = (commit.get("message") or "").strip()
if not msg:
continue
subject = msg.splitlines()[0].strip()
sha = commit.get("id") or commit.get("sha") or ""
label = f"push.commit {sha[:7]}" if sha else "push.commit"
subjects.append((label, subject))
if subjects:
return subjects
try:
subjects.append(("HEAD", _git("log", "-1", "--format=%s", "HEAD")))
except Exception:
pass
return subjects
def main() -> int:
try:
root = _repo_root()
except Exception as exc:
_eprint(f"ERROR: not a git repository: {exc}")
return 2
os.chdir(root)
require_emoji = os.getenv("COMMIT_LINT_REQUIRE_EMOJI", "1") not in ("0", "false", "False")
try:
spec_path = _find_commit_spec(root)
except FileNotFoundError as exc:
_eprint(f"ERROR: {exc}")
return 2
try:
mapping = _parse_type_emoji_mapping(spec_path.read_text(encoding="utf-8"))
except Exception as exc:
_eprint(f"ERROR: failed to read/parse {spec_path}: {exc}")
return 2
event_name, payload = _load_event_payload()
subjects = _gather_subjects(event_name, payload)
print(f"commit spec: {spec_path}")
if event_name:
print(f"event: {event_name}")
print(f"require emoji: {require_emoji}")
print(f"checks: {len(subjects)} subject(s)")
errors: List[str] = []
for label, subject in subjects:
err = _validate_subject_line(subject, mapping, require_emoji=require_emoji)
if err:
errors.append(f"- {label}: {err}\n subject: {subject}")
if errors:
_eprint("ERROR: commit message lint failed:")
for item in errors:
_eprint(item)
return 1
print("OK")
return 0
if __name__ == "__main__":
raise SystemExit(main())
@@ -0,0 +1,19 @@
name: Standards Check
on:
push:
pull_request:
jobs:
commit-message:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint commit message / PR title
env:
COMMIT_LINT_REQUIRE_EMOJI: "1"
run: |
python3 .gitea/ci/commit_message_lint.py
+1 -2
View File
@@ -8,7 +8,7 @@ repos:
- id: check-toml
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.10.0
hooks:
- id: black
args: ["--line-length", "80"]
@@ -22,4 +22,3 @@ repos:
rev: 6.0.0
hooks:
- id: flake8
-1
View File
@@ -11,4 +11,3 @@
"python.analysis.autoImportCompletions": true,
"python.formatting.provider": "none"
}
-1
View File
@@ -48,4 +48,3 @@ markers = [
"slow: marks tests as slow",
"integration: marks tests as integration tests",
]