forked from zhaohui-yang/official-document-drafting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
101 lines (78 loc) · 2.88 KB
/
Copy pathbuild.py
File metadata and controls
101 lines (78 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""在线 skill 产物构建脚本。
功能说明:
- 从 `prompts/` 主源生成在线 skill 场景所需的正式产物。
- 同步更新仓库根目录的 `SKILL.md`、`agents/openai.yaml`,以及 `dist/skill/` 下的构建产物。
- 可通过 `--check` 检查当前产物是否与主源规则保持同步。
主要产物:
- `SKILL.md`
- `agents/openai.yaml`
- `dist/skill/SKILL.md`
- `dist/skill/agents/openai.yaml`
适用场景:
- Codex
- agents
- Claude Code 等兼容 skill / agent 入口的在线宿主
Author: official-document-drafting maintainers
"""
from __future__ import annotations
import argparse
import pathlib
import sys
__author__ = "official-document-drafting maintainers"
__maintainer__ = "official-document-drafting maintainers"
REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
from adapters.shared import ( # noqa: E402
DIST_DIR,
ROOT_AGENT_PATH,
ROOT_SKILL_PATH,
export_templates,
load_doc_types,
load_profile,
render_agent_yaml,
render_skill_markdown,
write_text,
)
DIST_SKILL_PATH = DIST_DIR / "skill" / "SKILL.md"
DIST_AGENT_PATH = DIST_DIR / "skill" / "agents" / "openai.yaml"
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="从 prompts/ 主源生成 skill 产物。")
parser.add_argument("--profile", default="default", help="profile 名称,默认 default")
parser.add_argument("--check", action="store_true", help="只检查产物是否与当前主源同步")
return parser.parse_args()
def main() -> int:
args = parse_args()
profile = load_profile(args.profile)
doc_types = load_doc_types()
skill_md = render_skill_markdown(profile, doc_types)
agent_yaml = render_agent_yaml(profile)
targets = {
ROOT_SKILL_PATH: skill_md,
ROOT_AGENT_PATH: agent_yaml,
DIST_SKILL_PATH: skill_md,
DIST_AGENT_PATH: agent_yaml,
}
if args.check:
mismatched: list[pathlib.Path] = []
for path, expected in targets.items():
if not path.exists() or path.read_text(encoding="utf-8") != expected:
mismatched.append(path)
if mismatched:
print("[ERROR] 以下文件未与 prompts/ 主源同步:", file=sys.stderr)
for path in mismatched:
print(f"- {path}", file=sys.stderr)
return 1
print("[OK] skill 产物已与 prompts/ 主源同步。")
return 0
for path, content in targets.items():
write_text(path, content)
export_templates(doc_types, profile.default_template)
print(f"[OK] 已生成 {ROOT_SKILL_PATH}")
print(f"[OK] 已生成 {ROOT_AGENT_PATH}")
print(f"[OK] 已生成 {DIST_SKILL_PATH}")
print(f"[OK] 已生成 {DIST_AGENT_PATH}")
return 0
if __name__ == "__main__":
sys.exit(main())