@aiyiran/myclaw 1.1.201 → 1.1.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/myclaw-artifacts.js +2 -1
- package/package.json +1 -1
- package/publish.sh +6 -1
- package/skills/yiran-playground-template-use/SKILL.md +1 -0
- package/skills/yiran-playground-template-use/prompts/single-html-handoff.txt +23 -0
- package/skills/yiran-playground-template-use/scripts/deploy_to_workspace.py +11 -5
- package/skills/yiran-course-template-pipeline/README.md +0 -132
- package/skills/yiran-course-template-pipeline/SKILL.md +0 -74
- package/skills/yiran-course-template-pipeline/assets/a100-teacher.example.html +0 -66
- package/skills/yiran-course-template-pipeline/assets/student-template.html +0 -77
- package/skills/yiran-course-template-pipeline/assets/teacher-portrait-demo.html +0 -105
- package/skills/yiran-course-template-pipeline/assets/teacher-task-view.html +0 -110
- package/skills/yiran-course-template-pipeline/prompts//350/257/204/344/273/267/347/202/271/345/255/220.md +0 -107
- package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2651-demo/347/224/237/346/210/220.md +0 -121
- package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2652-student/347/224/237/346/210/220.md +0 -115
- package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2653-teacher/347/224/237/346/210/220.md +0 -144
- package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2654-/346/211/223/345/214/205/350/220/275/347/233/230.md +0 -130
- package/skills/yiran-course-template-pipeline/references/student-example.json +0 -38
- package/skills/yiran-course-template-pipeline/references/student-fields.md +0 -195
- package/skills/yiran-course-template-pipeline/references/student-scaffold.json +0 -34
- package/skills/yiran-course-template-pipeline/references/teacher-fields.md +0 -271
- package/skills/yiran-course-template-pipeline/references/teacher-scaffold.json +0 -25
- package/skills/yiran-course-template-pipeline/scripts/build_template_index.py +0 -150
- package/skills/yiran-course-template-pipeline/scripts/build_template_views.py +0 -132
- package/skills/yiran-course-template-pipeline/scripts/identify_template.py +0 -174
- package/skills/yiran-course-template-pipeline/scripts/migrate_templates.py +0 -104
- package/skills/yiran-course-template-pipeline/scripts/move_template_task.py +0 -107
- package/skills/yiran-course-template-pipeline/scripts/publish_template.py +0 -131
- package/skills/yiran-course-template-pipeline/scripts/release_template.py +0 -84
- package/skills/yiran-course-template-pipeline/scripts/render_student_page.py +0 -66
- package/skills/yiran-course-template-pipeline/scripts/render_teacher_view.py +0 -108
- package/skills/yiran-course-template-pipeline/template-index.json +0 -671
- package/skills/yiran-course-template-pipeline/template-index.md +0 -246
- package/skills/yiran-course-template-pipeline//344/270/232/345/212/241/350/203/214/346/231/257.md +0 -81
- package/skills/yiran-course-template-pipeline//345/272/237/345/274/203/rewrite_html_refs.py +0 -102
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
build_template_index.py
|
|
4
|
-
|
|
5
|
-
扫描 templates/ 目录,为每个模板读取最新版本子目录(v{N}/)中的
|
|
6
|
-
__teacher__.json 和 __student__.json,生成 template-index.json 和 template-index.md。
|
|
7
|
-
|
|
8
|
-
index 以 _id 为主键(flat 结构),每条记录包含版本号。
|
|
9
|
-
"""
|
|
10
|
-
import json
|
|
11
|
-
import re
|
|
12
|
-
from datetime import datetime, timezone
|
|
13
|
-
from pathlib import Path
|
|
14
|
-
from typing import Optional
|
|
15
|
-
|
|
16
|
-
ROOT = Path(__file__).resolve().parent.parent
|
|
17
|
-
TEMPLATES_DIR = ROOT / 'templates'
|
|
18
|
-
OUTPUT_JSON = ROOT / 'template-index.json'
|
|
19
|
-
OUTPUT_MD = ROOT / 'template-index.md'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def read_json(path: Path) -> dict:
|
|
23
|
-
try:
|
|
24
|
-
return json.loads(path.read_text(encoding='utf-8'))
|
|
25
|
-
except Exception:
|
|
26
|
-
return {}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def parse_folder_name(name: str):
|
|
30
|
-
m = re.match(r'^([a-zA-Z]+)(\d+)_(.+)$', name)
|
|
31
|
-
if m:
|
|
32
|
-
return m.group(1).upper(), str(int(m.group(2))), m.group(3)
|
|
33
|
-
return None, None, None
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def get_latest_version_dir(folder: Path):
|
|
37
|
-
"""返回最新版本子目录 Path 和版本号 int,没有则返回 (None, 0)"""
|
|
38
|
-
max_v = 0
|
|
39
|
-
result = None
|
|
40
|
-
for d in folder.iterdir():
|
|
41
|
-
if d.is_dir():
|
|
42
|
-
m = re.match(r'^v(\d+)$', d.name)
|
|
43
|
-
if m:
|
|
44
|
-
v = int(m.group(1))
|
|
45
|
-
if v > max_v:
|
|
46
|
-
max_v = v
|
|
47
|
-
result = d
|
|
48
|
-
return result, max_v
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def get_entry_file(version_dir: Path) -> Optional[Path]:
|
|
52
|
-
for name in ['index.html', '__demo__.html', '__student-view__.html']:
|
|
53
|
-
if (version_dir / name).exists():
|
|
54
|
-
return version_dir / name
|
|
55
|
-
return None
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def main():
|
|
59
|
-
templates = {} # { _id: record }
|
|
60
|
-
items_for_md = []
|
|
61
|
-
|
|
62
|
-
for folder in sorted(TEMPLATES_DIR.iterdir() if TEMPLATES_DIR.exists() else []):
|
|
63
|
-
if not folder.is_dir():
|
|
64
|
-
continue
|
|
65
|
-
|
|
66
|
-
series, number, _ = parse_folder_name(folder.name)
|
|
67
|
-
if not series:
|
|
68
|
-
continue
|
|
69
|
-
|
|
70
|
-
version_dir, version_num = get_latest_version_dir(folder)
|
|
71
|
-
if not version_dir:
|
|
72
|
-
continue
|
|
73
|
-
|
|
74
|
-
teacher = read_json(version_dir / '__teacher__.json')
|
|
75
|
-
student = read_json(version_dir / '__student__.json')
|
|
76
|
-
|
|
77
|
-
tid = teacher.get('_id', '').strip()
|
|
78
|
-
if not tid:
|
|
79
|
-
continue
|
|
80
|
-
|
|
81
|
-
name = teacher.get('任务名称') or student.get('任务标题', '')
|
|
82
|
-
一句话 = student.get('一句话说明', '')
|
|
83
|
-
能力标签 = teacher.get('主能力标签', '')
|
|
84
|
-
类型标签 = teacher.get('任务类型标签', '')
|
|
85
|
-
|
|
86
|
-
keywords = list(dict.fromkeys(filter(None, [
|
|
87
|
-
folder.name,
|
|
88
|
-
一句话,
|
|
89
|
-
*teacher.get('适合学生类型', []),
|
|
90
|
-
*teacher.get('训练重点', []),
|
|
91
|
-
name,
|
|
92
|
-
能力标签,
|
|
93
|
-
类型标签,
|
|
94
|
-
])))
|
|
95
|
-
|
|
96
|
-
entry = get_entry_file(version_dir)
|
|
97
|
-
|
|
98
|
-
all_files = list(version_dir.rglob('*'))
|
|
99
|
-
folder_mtime = max(
|
|
100
|
-
(f.stat().st_mtime for f in all_files if f.is_file()),
|
|
101
|
-
default=0
|
|
102
|
-
)
|
|
103
|
-
updated_at = datetime.fromtimestamp(folder_mtime, tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
104
|
-
|
|
105
|
-
version_str = f'v{version_num}'
|
|
106
|
-
|
|
107
|
-
record = {
|
|
108
|
-
'id': tid,
|
|
109
|
-
'系列': series,
|
|
110
|
-
'编号': number,
|
|
111
|
-
'名称': name,
|
|
112
|
-
'文件夹名': folder.name,
|
|
113
|
-
'version': version_str,
|
|
114
|
-
'路径': str(version_dir.relative_to(ROOT)),
|
|
115
|
-
'入口文件': str(entry.relative_to(ROOT)) if entry else '',
|
|
116
|
-
'一句话说明': 一句话,
|
|
117
|
-
'主能力标签': 能力标签,
|
|
118
|
-
'任务类型标签': 类型标签,
|
|
119
|
-
'关键词': keywords,
|
|
120
|
-
'updated_at': updated_at,
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
templates[tid] = record
|
|
124
|
-
items_for_md.append(record)
|
|
125
|
-
|
|
126
|
-
index_updated_at = datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
127
|
-
output = {'index_updated_at': index_updated_at, 'templates': templates}
|
|
128
|
-
OUTPUT_JSON.write_text(json.dumps(output, ensure_ascii=False, indent=2), encoding='utf-8')
|
|
129
|
-
|
|
130
|
-
items_for_md.sort(key=lambda x: (x['系列'], int(x['编号'])))
|
|
131
|
-
lines = ['# 模板索引', '', '每次 templates 内模板有变化后,都应重新运行本脚本。', '']
|
|
132
|
-
for item in items_for_md:
|
|
133
|
-
lines.append(f"## {item['系列']}{item['编号']} {item['名称']}")
|
|
134
|
-
lines.append(f"- ID:{item['id']}")
|
|
135
|
-
lines.append(f"- 版本:{item['version']}")
|
|
136
|
-
lines.append(f"- 路径:{item['路径']}")
|
|
137
|
-
lines.append(f"- 入口文件:{item['入口文件']}")
|
|
138
|
-
lines.append(f"- 主能力标签:{item['主能力标签']}")
|
|
139
|
-
lines.append(f"- 任务类型标签:{item['任务类型标签']}")
|
|
140
|
-
if item['关键词']:
|
|
141
|
-
lines.append(f"- 关键词:{', '.join(str(k) for k in item['关键词'])}")
|
|
142
|
-
lines.append('')
|
|
143
|
-
|
|
144
|
-
OUTPUT_MD.write_text('\n'.join(lines), encoding='utf-8')
|
|
145
|
-
print(f'已生成: {OUTPUT_JSON}(共 {len(templates)} 条)')
|
|
146
|
-
print(f'已生成: {OUTPUT_MD}')
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if __name__ == '__main__':
|
|
150
|
-
main()
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import html
|
|
3
|
-
import json
|
|
4
|
-
import subprocess
|
|
5
|
-
import sys
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
|
|
8
|
-
REQUIRED_BASE_FILES = ['__demo__.html', '__student__.json', '__teacher__.json']
|
|
9
|
-
REQUIRED_STUDENT_KEYS = ['任务标题', '一句话说明', '步骤', '评价目标', '示例区标题', '示例页面文件', '小提示']
|
|
10
|
-
REQUIRED_TEACHER_KEYS = ['任务类别', '任务编号', '任务名称', '主能力标签', '任务类型标签', '适合学生类型', '训练重点', '卡点和解决方案', '可拓展方向', '课后作业']
|
|
11
|
-
ROOT = Path(__file__).resolve().parent
|
|
12
|
-
|
|
13
|
-
INDEX_TEMPLATE = """\
|
|
14
|
-
<!DOCTYPE html>
|
|
15
|
-
<html lang="zh-CN">
|
|
16
|
-
<head>
|
|
17
|
-
<meta charset="UTF-8">
|
|
18
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
-
<title>{title}</title>
|
|
20
|
-
<style>
|
|
21
|
-
* {{ box-sizing: border-box; }}
|
|
22
|
-
body {{
|
|
23
|
-
margin: 0;
|
|
24
|
-
padding: 24px;
|
|
25
|
-
font-family: monospace;
|
|
26
|
-
background: #f6f8fc;
|
|
27
|
-
color: #1f2937;
|
|
28
|
-
}}
|
|
29
|
-
.grid {{
|
|
30
|
-
display: grid;
|
|
31
|
-
grid-template-columns: 1fr 1fr;
|
|
32
|
-
gap: 20px;
|
|
33
|
-
align-items: start;
|
|
34
|
-
}}
|
|
35
|
-
h2 {{
|
|
36
|
-
margin: 0 0 10px;
|
|
37
|
-
font-size: 18px;
|
|
38
|
-
}}
|
|
39
|
-
pre {{
|
|
40
|
-
margin: 0;
|
|
41
|
-
white-space: pre-wrap;
|
|
42
|
-
word-break: break-word;
|
|
43
|
-
background: #ffffff;
|
|
44
|
-
border: 1px solid #dbe3f0;
|
|
45
|
-
border-radius: 12px;
|
|
46
|
-
padding: 16px;
|
|
47
|
-
line-height: 1.7;
|
|
48
|
-
}}
|
|
49
|
-
</style>
|
|
50
|
-
</head>
|
|
51
|
-
<body>
|
|
52
|
-
<!--
|
|
53
|
-
[AI 编辑说明]
|
|
54
|
-
这是学生作品的主文件。当你开始编辑时:
|
|
55
|
-
1. 先删除 <body> 内所有现有内容(包括本注释)
|
|
56
|
-
2. 根据参考材料(__demo__.html 等 __XXX__ 文件)重新制作学生作品
|
|
57
|
-
__XXX__ 文件只读,不要修改。
|
|
58
|
-
-->
|
|
59
|
-
<div class="grid">
|
|
60
|
-
<section>
|
|
61
|
-
<h2>评价目标</h2>
|
|
62
|
-
<pre>{goals_json}</pre>
|
|
63
|
-
</section>
|
|
64
|
-
<section>
|
|
65
|
-
<h2>步骤</h2>
|
|
66
|
-
<pre>{steps_json}</pre>
|
|
67
|
-
</section>
|
|
68
|
-
</div>
|
|
69
|
-
|
|
70
|
-
<script type="application/json" id="task-data">
|
|
71
|
-
{raw_task_json}
|
|
72
|
-
</script>
|
|
73
|
-
</body>
|
|
74
|
-
</html>
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def load_json(path):
|
|
79
|
-
with path.open('r', encoding='utf-8') as f:
|
|
80
|
-
return json.load(f)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def check_keys(data, keys, name):
|
|
84
|
-
missing = [k for k in keys if k not in data]
|
|
85
|
-
if missing:
|
|
86
|
-
raise ValueError(f'{name} 缺少字段: {", ".join(missing)}')
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def validate_folder(source_dir: Path):
|
|
90
|
-
for filename in REQUIRED_BASE_FILES:
|
|
91
|
-
if not (source_dir / filename).exists():
|
|
92
|
-
raise FileNotFoundError(f'缺少必需文件: {filename}')
|
|
93
|
-
student = load_json(source_dir / '__student__.json')
|
|
94
|
-
teacher = load_json(source_dir / '__teacher__.json')
|
|
95
|
-
check_keys(student, REQUIRED_STUDENT_KEYS, '__student__.json')
|
|
96
|
-
check_keys(teacher, REQUIRED_TEACHER_KEYS, '__teacher__.json')
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def render_index_page(source_dir: Path):
|
|
100
|
-
student = load_json(source_dir / '__student__.json')
|
|
101
|
-
task_json = json.dumps(student, ensure_ascii=False, indent=2)
|
|
102
|
-
goals_json = json.dumps(student.get('评价目标', []), ensure_ascii=False, indent=2)
|
|
103
|
-
steps_json = json.dumps(student.get('步骤', []), ensure_ascii=False, indent=2)
|
|
104
|
-
content = INDEX_TEMPLATE.format(
|
|
105
|
-
title=html.escape(student.get('任务标题', '未命名任务')),
|
|
106
|
-
goals_json=html.escape(goals_json),
|
|
107
|
-
steps_json=html.escape(steps_json),
|
|
108
|
-
raw_task_json=task_json,
|
|
109
|
-
)
|
|
110
|
-
out = source_dir / 'index.html'
|
|
111
|
-
out.write_text(content, encoding='utf-8')
|
|
112
|
-
print(f'已生成: {out}')
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def main():
|
|
116
|
-
if len(sys.argv) < 2:
|
|
117
|
-
print('用法: python3 build_template_views.py <已有文件夹>')
|
|
118
|
-
sys.exit(1)
|
|
119
|
-
|
|
120
|
-
source_dir = Path(sys.argv[1]).expanduser().resolve()
|
|
121
|
-
validate_folder(source_dir)
|
|
122
|
-
|
|
123
|
-
subprocess.run(['python3', str(ROOT / 'render_student_page.py'), str(source_dir / '__student__.json'), str(source_dir / '__student-view__.html')], check=True)
|
|
124
|
-
subprocess.run(['python3', str(ROOT / 'render_teacher_view.py'), str(source_dir / '__teacher__.json'), str(source_dir / '__teacher-view__.html')], check=True)
|
|
125
|
-
render_index_page(source_dir)
|
|
126
|
-
|
|
127
|
-
print(f'已在原文件夹生成: {source_dir}')
|
|
128
|
-
print('已生成 __student-view__.html、__teacher-view__.html、index.html')
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if __name__ == '__main__':
|
|
132
|
-
main()
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
identify_template.py
|
|
4
|
-
|
|
5
|
-
给模板源目录颁发或校准身份信息,直接修改源目录的 __teacher__.json。
|
|
6
|
-
不做任何文件移动,可单独运行。
|
|
7
|
-
|
|
8
|
-
写入字段:
|
|
9
|
-
_id : 8位十六进制,首次颁发,后续不变
|
|
10
|
-
任务类别 : 校准后的系列(A/B/C)
|
|
11
|
-
任务编号 : 校准后的3位编号(100起)
|
|
12
|
-
|
|
13
|
-
用法:
|
|
14
|
-
python3 identify_template.py <模板目录>
|
|
15
|
-
"""
|
|
16
|
-
import json
|
|
17
|
-
import re
|
|
18
|
-
import secrets
|
|
19
|
-
import sys
|
|
20
|
-
from pathlib import Path
|
|
21
|
-
|
|
22
|
-
ROOT = Path(__file__).resolve().parent.parent
|
|
23
|
-
TEMPLATES_DIR = ROOT / 'templates'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def load_json(path: Path) -> dict:
|
|
27
|
-
try:
|
|
28
|
-
return json.loads(path.read_text(encoding='utf-8'))
|
|
29
|
-
except Exception:
|
|
30
|
-
return {}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def save_json(path: Path, data: dict):
|
|
34
|
-
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def gen_id() -> str:
|
|
38
|
-
return secrets.token_hex(4) # 8位十六进制
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def normalize_category(raw) -> str:
|
|
42
|
-
cat = str(raw).upper().strip()
|
|
43
|
-
if cat not in {'A', 'B', 'C', 'D', 'E'}:
|
|
44
|
-
raise ValueError(f'任务类别只能是 A、B、C、D、E,当前: {cat}')
|
|
45
|
-
return cat
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def get_latest_version_num(folder: Path) -> int:
|
|
49
|
-
"""返回 folder 下最大的版本号,没有则返回 0"""
|
|
50
|
-
max_v = 0
|
|
51
|
-
for d in folder.iterdir():
|
|
52
|
-
if d.is_dir():
|
|
53
|
-
m = re.match(r'^v(\d+)$', d.name)
|
|
54
|
-
if m:
|
|
55
|
-
max_v = max(max_v, int(m.group(1)))
|
|
56
|
-
return max_v
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def scan_templates(templates_dir: Path):
|
|
60
|
-
"""
|
|
61
|
-
扫描 templates/ 下所有已入库模板。
|
|
62
|
-
返回:
|
|
63
|
-
id_map : { _id -> {'folder': Path, 'version': int} }
|
|
64
|
-
number_map : { category -> { number(int) -> _id } }
|
|
65
|
-
"""
|
|
66
|
-
id_map = {}
|
|
67
|
-
number_map = {}
|
|
68
|
-
pattern = re.compile(r'^([a-zA-Z])(\d{3})_')
|
|
69
|
-
|
|
70
|
-
if not templates_dir.exists():
|
|
71
|
-
return id_map, number_map
|
|
72
|
-
|
|
73
|
-
for folder in templates_dir.iterdir():
|
|
74
|
-
if not folder.is_dir():
|
|
75
|
-
continue
|
|
76
|
-
m = pattern.match(folder.name)
|
|
77
|
-
if not m:
|
|
78
|
-
continue
|
|
79
|
-
|
|
80
|
-
version_num = get_latest_version_num(folder)
|
|
81
|
-
if version_num == 0:
|
|
82
|
-
continue
|
|
83
|
-
|
|
84
|
-
version_dir = folder / f'v{version_num}'
|
|
85
|
-
teacher = load_json(version_dir / '__teacher__.json')
|
|
86
|
-
tid = teacher.get('_id')
|
|
87
|
-
if not tid:
|
|
88
|
-
continue
|
|
89
|
-
|
|
90
|
-
cat = m.group(1).upper()
|
|
91
|
-
num = int(m.group(2))
|
|
92
|
-
|
|
93
|
-
id_map[tid] = {'folder': folder, 'version': version_num}
|
|
94
|
-
number_map.setdefault(cat, {})[num] = tid
|
|
95
|
-
|
|
96
|
-
return id_map, number_map
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def calibrate_number(category: str, desired: int, number_map: dict, own_id: str) -> int:
|
|
100
|
-
"""
|
|
101
|
-
校准编号:
|
|
102
|
-
- 宣称的编号不存在,或已属于自己 → 合法,直接用
|
|
103
|
-
- 已被别人占用 → 找最小可用编号(>=100)
|
|
104
|
-
"""
|
|
105
|
-
used = number_map.get(category, {})
|
|
106
|
-
owner = used.get(desired)
|
|
107
|
-
if owner is None or owner == own_id:
|
|
108
|
-
return desired
|
|
109
|
-
# 冲突,找最小可用
|
|
110
|
-
for num in range(100, 1000):
|
|
111
|
-
if num not in used or used[num] == own_id:
|
|
112
|
-
return num
|
|
113
|
-
raise RuntimeError(f'{category} 类编号已用尽')
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def main():
|
|
117
|
-
if len(sys.argv) < 2:
|
|
118
|
-
print('用法: python3 identify_template.py <模板目录>')
|
|
119
|
-
sys.exit(1)
|
|
120
|
-
|
|
121
|
-
source_dir = Path(sys.argv[1]).expanduser().resolve()
|
|
122
|
-
teacher_path = source_dir / '__teacher__.json'
|
|
123
|
-
|
|
124
|
-
if not teacher_path.exists():
|
|
125
|
-
print(f'❌ 找不到 __teacher__.json: {teacher_path}')
|
|
126
|
-
sys.exit(1)
|
|
127
|
-
|
|
128
|
-
teacher = load_json(teacher_path)
|
|
129
|
-
id_map, number_map = scan_templates(TEMPLATES_DIR)
|
|
130
|
-
|
|
131
|
-
# ── 1. _id 与版本号 ────────────────────────────────────────────────────
|
|
132
|
-
tid = teacher.get('_id', '').strip()
|
|
133
|
-
in_templates = tid and tid in id_map
|
|
134
|
-
|
|
135
|
-
if not tid:
|
|
136
|
-
tid = gen_id()
|
|
137
|
-
new_version = 1
|
|
138
|
-
print(f'🆔 颁发新 ID: {tid} 版本: v1')
|
|
139
|
-
elif not in_templates:
|
|
140
|
-
new_version = 1
|
|
141
|
-
print(f'🆔 已有 ID {tid},首次入库 版本: v1')
|
|
142
|
-
else:
|
|
143
|
-
old_version = id_map[tid]['version']
|
|
144
|
-
new_version = old_version + 1
|
|
145
|
-
print(f'🔄 更新 ID {tid} 版本: v{old_version} → v{new_version}')
|
|
146
|
-
|
|
147
|
-
# ── 2. 校准 任务类别 + 任务编号 ────────────────────────────────────────
|
|
148
|
-
try:
|
|
149
|
-
category = normalize_category(teacher.get('任务类别', ''))
|
|
150
|
-
except ValueError as e:
|
|
151
|
-
print(f'❌ {e}')
|
|
152
|
-
sys.exit(1)
|
|
153
|
-
|
|
154
|
-
try:
|
|
155
|
-
desired = int(str(teacher.get('任务编号', '100')))
|
|
156
|
-
except ValueError:
|
|
157
|
-
desired = 100
|
|
158
|
-
|
|
159
|
-
calibrated = calibrate_number(category, desired, number_map, tid)
|
|
160
|
-
if calibrated != desired:
|
|
161
|
-
print(f'⚠️ 编号冲突:{category}{desired:03d} 已被占用,校准为 {category}{calibrated:03d}')
|
|
162
|
-
|
|
163
|
-
# ── 3. 写回 __teacher__.json ───────────────────────────────────────────
|
|
164
|
-
teacher['_id'] = tid
|
|
165
|
-
teacher['任务类别'] = category
|
|
166
|
-
teacher['任务编号'] = f'{calibrated:03d}'
|
|
167
|
-
save_json(teacher_path, teacher)
|
|
168
|
-
|
|
169
|
-
print(f'✅ 已写回: {teacher_path}')
|
|
170
|
-
print(f' _id={tid}, _version=v{new_version}, 分类={category}{calibrated:03d}')
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if __name__ == '__main__':
|
|
174
|
-
main()
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
migrate_templates.py
|
|
4
|
-
|
|
5
|
-
将旧版平铺结构迁移到版本化结构:
|
|
6
|
-
templates/{folder}/*.html → templates/{folder}/v1/*.html
|
|
7
|
-
|
|
8
|
-
同时为没有 _id 的模板颁发 ID,写入 __teacher__.json。
|
|
9
|
-
|
|
10
|
-
用法:
|
|
11
|
-
python3 scripts/migrate_templates.py [--dry-run]
|
|
12
|
-
"""
|
|
13
|
-
import json
|
|
14
|
-
import re
|
|
15
|
-
import secrets
|
|
16
|
-
import shutil
|
|
17
|
-
import sys
|
|
18
|
-
from pathlib import Path
|
|
19
|
-
|
|
20
|
-
ROOT = Path(__file__).resolve().parent.parent
|
|
21
|
-
TEMPLATES_DIR = ROOT / 'templates'
|
|
22
|
-
INDEX_SCRIPT = ROOT / 'scripts' / 'build_template_index.py'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def load_json(path: Path) -> dict:
|
|
26
|
-
try:
|
|
27
|
-
return json.loads(path.read_text(encoding='utf-8'))
|
|
28
|
-
except Exception:
|
|
29
|
-
return {}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def save_json(path: Path, data: dict):
|
|
33
|
-
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def gen_id() -> str:
|
|
37
|
-
return secrets.token_hex(4)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def has_version_subdir(folder: Path) -> bool:
|
|
41
|
-
for d in folder.iterdir():
|
|
42
|
-
if d.is_dir() and re.match(r'^v\d+$', d.name):
|
|
43
|
-
return True
|
|
44
|
-
return False
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def main():
|
|
48
|
-
dry_run = '--dry-run' in sys.argv
|
|
49
|
-
if dry_run:
|
|
50
|
-
print('🔍 DRY RUN 模式,不实际修改文件\n')
|
|
51
|
-
|
|
52
|
-
if not TEMPLATES_DIR.exists():
|
|
53
|
-
print('❌ templates/ 目录不存在')
|
|
54
|
-
sys.exit(1)
|
|
55
|
-
|
|
56
|
-
folders = sorted(d for d in TEMPLATES_DIR.iterdir() if d.is_dir())
|
|
57
|
-
migrated = 0
|
|
58
|
-
|
|
59
|
-
for folder in folders:
|
|
60
|
-
if has_version_subdir(folder):
|
|
61
|
-
print(f'✓ 跳过(已版本化): {folder.name}')
|
|
62
|
-
continue
|
|
63
|
-
|
|
64
|
-
# 列出所有直接子文件(排除目录)
|
|
65
|
-
files = [f for f in folder.iterdir() if f.is_file()]
|
|
66
|
-
if not files:
|
|
67
|
-
print(f'⚠️ 空目录,跳过: {folder.name}')
|
|
68
|
-
continue
|
|
69
|
-
|
|
70
|
-
teacher_path = folder / '__teacher__.json'
|
|
71
|
-
teacher = load_json(teacher_path)
|
|
72
|
-
|
|
73
|
-
# 补充 _id
|
|
74
|
-
if not teacher.get('_id'):
|
|
75
|
-
teacher['_id'] = gen_id()
|
|
76
|
-
print(f'🆔 颁发 ID {teacher["_id"]}: {folder.name}')
|
|
77
|
-
|
|
78
|
-
# 补充 _version
|
|
79
|
-
if not teacher.get('_version'):
|
|
80
|
-
teacher['_version'] = 1
|
|
81
|
-
|
|
82
|
-
if not dry_run:
|
|
83
|
-
# 先写回 __teacher__.json
|
|
84
|
-
save_json(teacher_path, teacher)
|
|
85
|
-
|
|
86
|
-
# 创建 v1/ 并移动所有文件
|
|
87
|
-
v1_dir = folder / 'v1'
|
|
88
|
-
v1_dir.mkdir(exist_ok=True)
|
|
89
|
-
for f in files:
|
|
90
|
-
shutil.move(str(f), str(v1_dir / f.name))
|
|
91
|
-
|
|
92
|
-
print(f'📦 迁移: {folder.name} → {folder.name}/v1/')
|
|
93
|
-
migrated += 1
|
|
94
|
-
|
|
95
|
-
print(f'\n{"[DRY RUN] " if dry_run else ""}共迁移 {migrated} 个模板')
|
|
96
|
-
|
|
97
|
-
if not dry_run and migrated > 0:
|
|
98
|
-
import subprocess
|
|
99
|
-
subprocess.run(['python3', str(INDEX_SCRIPT)], check=True)
|
|
100
|
-
print('✅ 索引已重建')
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if __name__ == '__main__':
|
|
104
|
-
main()
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
move_template_task.py
|
|
4
|
-
|
|
5
|
-
将模板源目录纳入 pipeline(复制,不删除原目录)。
|
|
6
|
-
|
|
7
|
-
流程:
|
|
8
|
-
1. 校验必需文件
|
|
9
|
-
2. 调用 identify_template.py(颁发/校准身份,写回源目录)
|
|
10
|
-
3. 读取更新后的 __teacher__.json,拼出目标路径
|
|
11
|
-
4. 复制到 templates/{folder_name}/v{N}/
|
|
12
|
-
5. 重建 template-index.json
|
|
13
|
-
|
|
14
|
-
用法:
|
|
15
|
-
python3 move_template_task.py <模板目录> [目标根目录]
|
|
16
|
-
"""
|
|
17
|
-
import json
|
|
18
|
-
import re
|
|
19
|
-
import shutil
|
|
20
|
-
import subprocess
|
|
21
|
-
import sys
|
|
22
|
-
from pathlib import Path
|
|
23
|
-
|
|
24
|
-
ROOT = Path(__file__).resolve().parent.parent
|
|
25
|
-
DEFAULT_TARGET = ROOT / 'templates'
|
|
26
|
-
IDENTIFY_SCRIPT = ROOT / 'scripts' / 'identify_template.py'
|
|
27
|
-
INDEX_SCRIPT = ROOT / 'scripts' / 'build_template_index.py'
|
|
28
|
-
REQUIRED_FILES = [
|
|
29
|
-
'__demo__.html', '__student__.json', '__teacher__.json',
|
|
30
|
-
'__student-view__.html', '__teacher-view__.html',
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def load_json(path: Path) -> dict:
|
|
35
|
-
try:
|
|
36
|
-
return json.loads(path.read_text(encoding='utf-8'))
|
|
37
|
-
except Exception:
|
|
38
|
-
return {}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def sanitize_name(name: str) -> str:
|
|
42
|
-
return re.sub(r'[/\\ ]', '_', str(name).strip())
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def get_latest_version_num(folder: Path) -> int:
|
|
46
|
-
"""返回 folder 下最大的版本号,没有则返回 0"""
|
|
47
|
-
if not folder.exists():
|
|
48
|
-
return 0
|
|
49
|
-
max_v = 0
|
|
50
|
-
for d in folder.iterdir():
|
|
51
|
-
if d.is_dir():
|
|
52
|
-
m = re.match(r'^v(\d+)$', d.name)
|
|
53
|
-
if m:
|
|
54
|
-
max_v = max(max_v, int(m.group(1)))
|
|
55
|
-
return max_v
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def main():
|
|
59
|
-
if len(sys.argv) < 2:
|
|
60
|
-
print('用法: python3 move_template_task.py <模板目录> [目标根目录]')
|
|
61
|
-
sys.exit(1)
|
|
62
|
-
|
|
63
|
-
source_dir = Path(sys.argv[1]).expanduser().resolve()
|
|
64
|
-
target_root = Path(sys.argv[2]).expanduser().resolve() if len(sys.argv) > 2 else DEFAULT_TARGET
|
|
65
|
-
|
|
66
|
-
if not source_dir.is_dir():
|
|
67
|
-
print(f'❌ 目录不存在: {source_dir}')
|
|
68
|
-
sys.exit(1)
|
|
69
|
-
|
|
70
|
-
# 1. 校验必需文件
|
|
71
|
-
for filename in REQUIRED_FILES:
|
|
72
|
-
if not (source_dir / filename).exists():
|
|
73
|
-
print(f'❌ 缺少必需文件: {filename}')
|
|
74
|
-
sys.exit(1)
|
|
75
|
-
|
|
76
|
-
# 2. 颁发/校准身份(写回源目录的 __teacher__.json)
|
|
77
|
-
print('\n── 身份认证 ────────────────────────────────')
|
|
78
|
-
subprocess.run([sys.executable, str(IDENTIFY_SCRIPT), str(source_dir)], check=True)
|
|
79
|
-
|
|
80
|
-
# 3. 读取更新后的身份信息
|
|
81
|
-
teacher = load_json(source_dir / '__teacher__.json')
|
|
82
|
-
category = teacher.get('任务类别', '').upper()
|
|
83
|
-
number = teacher.get('任务编号', '100')
|
|
84
|
-
name = sanitize_name(teacher.get('任务名称', 'untitled'))
|
|
85
|
-
|
|
86
|
-
folder_name = f'{category.lower()}{number}_{name}'
|
|
87
|
-
next_version = get_latest_version_num(target_root / folder_name) + 1
|
|
88
|
-
version_str = f'v{next_version}'
|
|
89
|
-
target_dir = target_root / folder_name / version_str
|
|
90
|
-
|
|
91
|
-
if target_dir.exists():
|
|
92
|
-
print(f'❌ 目标目录已存在(重复操作?): {target_dir}')
|
|
93
|
-
sys.exit(1)
|
|
94
|
-
|
|
95
|
-
# 4. 复制到 templates/{folder}/v{N}/
|
|
96
|
-
print(f'\n── 复制文件 ────────────────────────────────')
|
|
97
|
-
target_root.mkdir(parents=True, exist_ok=True)
|
|
98
|
-
shutil.copytree(str(source_dir), str(target_dir))
|
|
99
|
-
print(f'✅ 已复制到: {target_dir}')
|
|
100
|
-
|
|
101
|
-
# 5. 重建 index
|
|
102
|
-
print(f'\n── 重建索引 ────────────────────────────────')
|
|
103
|
-
subprocess.run([sys.executable, str(INDEX_SCRIPT)], check=True)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if __name__ == '__main__':
|
|
107
|
-
main()
|