@aiyiran/myclaw 1.1.201 → 1.1.203

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.
Files changed (40) hide show
  1. package/assets/myclaw-artifacts.js +316 -9
  2. package/assets/myclaw-inject.js +110 -9
  3. package/create_agent.js +15 -11
  4. package/index.js +8 -0
  5. package/package.json +1 -1
  6. package/publish.sh +6 -1
  7. package/server/sync_workspace.py +12 -5
  8. package/skills/yiran-playground-template-use/SKILL.md +5 -4
  9. package/skills/yiran-playground-template-use/prompts/single-html-handoff.txt +23 -0
  10. package/skills/yiran-playground-template-use/scripts/deploy_to_workspace.py +62 -10
  11. package/skills/yiran-playground-template-use/scripts/start_tui_handoff.py +22 -4
  12. package/skills/yiran-course-template-pipeline/README.md +0 -132
  13. package/skills/yiran-course-template-pipeline/SKILL.md +0 -74
  14. package/skills/yiran-course-template-pipeline/assets/a100-teacher.example.html +0 -66
  15. package/skills/yiran-course-template-pipeline/assets/student-template.html +0 -77
  16. package/skills/yiran-course-template-pipeline/assets/teacher-portrait-demo.html +0 -105
  17. package/skills/yiran-course-template-pipeline/assets/teacher-task-view.html +0 -110
  18. package/skills/yiran-course-template-pipeline/prompts//350/257/204/344/273/267/347/202/271/345/255/220.md +0 -107
  19. package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2651-demo/347/224/237/346/210/220.md +0 -121
  20. package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2652-student/347/224/237/346/210/220.md +0 -115
  21. package/skills/yiran-course-template-pipeline/prompts//351/230/266/346/256/2653-teacher/347/224/237/346/210/220.md +0 -144
  22. 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
  23. package/skills/yiran-course-template-pipeline/references/student-example.json +0 -38
  24. package/skills/yiran-course-template-pipeline/references/student-fields.md +0 -195
  25. package/skills/yiran-course-template-pipeline/references/student-scaffold.json +0 -34
  26. package/skills/yiran-course-template-pipeline/references/teacher-fields.md +0 -271
  27. package/skills/yiran-course-template-pipeline/references/teacher-scaffold.json +0 -25
  28. package/skills/yiran-course-template-pipeline/scripts/build_template_index.py +0 -150
  29. package/skills/yiran-course-template-pipeline/scripts/build_template_views.py +0 -132
  30. package/skills/yiran-course-template-pipeline/scripts/identify_template.py +0 -174
  31. package/skills/yiran-course-template-pipeline/scripts/migrate_templates.py +0 -104
  32. package/skills/yiran-course-template-pipeline/scripts/move_template_task.py +0 -107
  33. package/skills/yiran-course-template-pipeline/scripts/publish_template.py +0 -131
  34. package/skills/yiran-course-template-pipeline/scripts/release_template.py +0 -84
  35. package/skills/yiran-course-template-pipeline/scripts/render_student_page.py +0 -66
  36. package/skills/yiran-course-template-pipeline/scripts/render_teacher_view.py +0 -108
  37. package/skills/yiran-course-template-pipeline/template-index.json +0 -671
  38. package/skills/yiran-course-template-pipeline/template-index.md +0 -246
  39. package/skills/yiran-course-template-pipeline//344/270/232/345/212/241/350/203/214/346/231/257.md +0 -81
  40. package/skills/yiran-course-template-pipeline//345/272/237/345/274/203/rewrite_html_refs.py +0 -102
@@ -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()
@@ -1,131 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- publish_template.py
4
-
5
- 发布模板文件夹到七牛 CDN,完成后重建并上传 template-index.json。
6
-
7
- CDN 路径:{CDN_PREFIX}/{folder_name}/{version}/{filename}
8
- 版本号从 templates/{folder}/v{N}/ 子目录读取(以本地最新版本为准)。
9
-
10
- 用法:
11
- python3 scripts/publish_template.py <模板文件夹路径>
12
- python3 scripts/publish_template.py --all
13
- """
14
- import argparse
15
- import re
16
- import subprocess
17
- import sys
18
- from pathlib import Path
19
-
20
- from qiniu import Auth, put_file_v2, CdnManager
21
-
22
- QINIU_KEY = "T3tgxM7EMx1j4VESw4m4PIfFXoOvBo-wQEOQewXX"
23
- QINIU_SECRET = "PVZvlKVOjX2RqlV2ILMg-QwpNMssOlpVbaEzypz0"
24
- QINIU_BUCKET = "yiran1"
25
- CDN_DOMAIN = "https://cdn.yiranlaoshi.com"
26
- CDN_INDEX_KEY = "myclaw/live/yiran/skills/yiran-playground-template-use/template-index.json"
27
- CDN_PREFIX = "myclaw/live/yiran/skills/yiran-playground-template-use/templates"
28
-
29
- q = Auth(QINIU_KEY, QINIU_SECRET)
30
- cdn_manager = CdnManager(q)
31
-
32
-
33
- def get_latest_version_dir(folder: Path):
34
- """返回最新 v{N} 子目录和版本号,没有则返回 (None, 0)"""
35
- max_v = 0
36
- result = None
37
- for d in folder.iterdir():
38
- if d.is_dir():
39
- m = re.match(r'^v(\d+)$', d.name)
40
- if m:
41
- v = int(m.group(1))
42
- if v > max_v:
43
- max_v = v
44
- result = d
45
- return result, max_v
46
-
47
-
48
- def upload_file(local_path: Path, cdn_key: str) -> str:
49
- token = q.upload_token(QINIU_BUCKET, cdn_key, 3600, policy={'insertOnly': 0})
50
- ret, info = put_file_v2(token, cdn_key, str(local_path))
51
- if info.status_code != 200:
52
- raise RuntimeError('上传失败 {}: {}'.format(local_path.name, info))
53
- cdn_url = '{}/{}'.format(CDN_DOMAIN, cdn_key)
54
- cdn_manager.refresh_urls([cdn_url])
55
- return cdn_url
56
-
57
-
58
- def publish(folder_path: Path):
59
- folder_name = folder_path.name
60
- version_dir, version_num = get_latest_version_dir(folder_path)
61
-
62
- if not version_dir:
63
- print('⚠️ {} 没有版本子目录,跳过'.format(folder_name))
64
- return
65
-
66
- version_str = 'v{}'.format(version_num)
67
- files = [f for f in version_dir.rglob('*') if f.is_file() and f.name != '.sync-done']
68
-
69
- if not files:
70
- print('⚠️ 文件夹为空: {}/{}'.format(folder_name, version_str))
71
- return
72
-
73
- print('📂 发布: {}/{}'.format(folder_name, version_str))
74
- for f in sorted(files):
75
- rel = f.relative_to(version_dir)
76
- cdn_key = '{}/{}/{}/{}'.format(CDN_PREFIX, folder_name, version_str, rel.as_posix())
77
- cdn_url = upload_file(f, cdn_key)
78
- print(' ⬆️ {} → {}'.format(rel, cdn_url))
79
-
80
- print('✅ 完成: {}/{}\n'.format(folder_name, version_str))
81
-
82
-
83
- def publish_index(pipeline_root: Path):
84
- index_script = pipeline_root / 'scripts' / 'build_template_index.py'
85
- print('🔄 重建 template-index.json ...')
86
- subprocess.run(['python3', str(index_script)], check=True)
87
-
88
- index_file = pipeline_root / 'template-index.json'
89
- if not index_file.is_file():
90
- print('⚠️ template-index.json 未生成,跳过上传')
91
- return
92
-
93
- token = q.upload_token(QINIU_BUCKET, CDN_INDEX_KEY, 3600, policy={'insertOnly': 0})
94
- ret, info = put_file_v2(token, CDN_INDEX_KEY, str(index_file))
95
- if info.status_code != 200:
96
- raise RuntimeError('index 上传失败: {}'.format(info))
97
- cdn_url = '{}/{}'.format(CDN_DOMAIN, CDN_INDEX_KEY)
98
- cdn_manager.refresh_urls([cdn_url])
99
- print(' ⬆️ 已上传索引 → {}'.format(cdn_url))
100
-
101
-
102
- def main():
103
- parser = argparse.ArgumentParser(description='发布模板到七牛 CDN')
104
- group = parser.add_mutually_exclusive_group(required=True)
105
- group.add_argument('folder', nargs='?', help='单个模板文件夹路径')
106
- group.add_argument('--all', action='store_true', help='发布 templates/ 下所有模板')
107
- args = parser.parse_args()
108
-
109
- pipeline_root = Path(__file__).resolve().parent.parent
110
-
111
- if args.all:
112
- templates_dir = pipeline_root / 'templates'
113
- folders = sorted(d for d in templates_dir.iterdir() if d.is_dir())
114
- if not folders:
115
- print('⚠️ templates/ 下没有找到任何模板文件夹')
116
- sys.exit(0)
117
- print('📦 共 {} 个模板,开始全量发布...\n'.format(len(folders)))
118
- for folder in folders:
119
- publish(folder)
120
- else:
121
- folder = Path(args.folder).expanduser().resolve()
122
- if not folder.is_dir():
123
- print('❌ 路径不存在或不是文件夹: {}'.format(folder))
124
- sys.exit(1)
125
- publish(folder)
126
-
127
- publish_index(pipeline_root)
128
-
129
-
130
- if __name__ == '__main__':
131
- main()
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- release_template.py
4
-
5
- 一键发布脚本:合并 build → move → publish 三个步骤。
6
-
7
- 传入原始模板目录(或已有 vN/ 目录),自动执行:
8
- Step 1: build_template_views.py <source_dir> → 生成/更新 HTML 视图
9
- Step 2: move_template_task.py <source_dir> → 创建新版本目录 vN+1/
10
- Step 3: publish_template.py <templates/xxx/> → 上传 CDN + 上传 index
11
-
12
- 用法:
13
- python3 scripts/release_template.py <模板目录>
14
- """
15
- import json
16
- import re
17
- import subprocess
18
- import sys
19
- from pathlib import Path
20
-
21
- ROOT = Path(__file__).resolve().parent.parent
22
- BUILD_SCRIPT = ROOT / 'scripts' / 'build_template_views.py'
23
- MOVE_SCRIPT = ROOT / 'scripts' / 'move_template_task.py'
24
- PUBLISH_SCRIPT = ROOT / 'scripts' / 'publish_template.py'
25
- TEMPLATES_DIR = ROOT / 'templates'
26
-
27
-
28
- def load_json(path: Path) -> dict:
29
- try:
30
- return json.loads(path.read_text(encoding='utf-8'))
31
- except Exception:
32
- return {}
33
-
34
-
35
- def sanitize_name(name: str) -> str:
36
- return re.sub(r'[/\\ ]', '_', str(name).strip())
37
-
38
-
39
- def main():
40
- if len(sys.argv) < 2:
41
- print('用法: python3 scripts/release_template.py <模板目录>')
42
- sys.exit(1)
43
-
44
- source_dir = Path(sys.argv[1]).expanduser().resolve()
45
-
46
- if not source_dir.is_dir():
47
- print(f'❌ 目录不存在: {source_dir}')
48
- sys.exit(1)
49
-
50
- teacher_path = source_dir / '__teacher__.json'
51
- if not teacher_path.exists():
52
- print(f'❌ 找不到 __teacher__.json: {teacher_path}')
53
- sys.exit(1)
54
-
55
- # ── Step 1: Build HTML views ──────────────────────────────────────────
56
- print('\n══ Step 1: 生成 HTML 视图 ══════════════════════════════')
57
- subprocess.run([sys.executable, str(BUILD_SCRIPT), str(source_dir)], check=True)
58
-
59
- # ── Step 2: Move to templates/ ────────────────────────────────────────
60
- print('\n══ Step 2: 移入 templates/ ═════════════════════════════')
61
- subprocess.run([sys.executable, str(MOVE_SCRIPT), str(source_dir)], check=True)
62
-
63
- # ── Determine publish target from updated teacher.json ────────────────
64
- teacher = load_json(teacher_path)
65
- category = teacher.get('任务类别', '').upper()
66
- number = teacher.get('任务编号', '100')
67
- name = sanitize_name(teacher.get('任务名称', 'untitled'))
68
- folder_name = f'{category.lower()}{number}_{name}'
69
- publish_target = TEMPLATES_DIR / folder_name
70
-
71
- if not publish_target.is_dir():
72
- print(f'❌ 发布目标目录不存在: {publish_target}')
73
- sys.exit(1)
74
-
75
- # ── Step 3: Publish to CDN ────────────────────────────────────────────
76
- print('\n══ Step 3: 上传 CDN ════════════════════════════════════')
77
- subprocess.run([sys.executable, str(PUBLISH_SCRIPT), str(publish_target)], check=True)
78
-
79
- print('\n✅ 发布完成!')
80
- print(f' 模板目录: {publish_target}')
81
-
82
-
83
- if __name__ == '__main__':
84
- main()
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env python3
2
- import json
3
- import html
4
- import sys
5
- from pathlib import Path
6
-
7
-
8
- def esc(value):
9
- return html.escape(str(value if value is not None else ''))
10
-
11
-
12
- def render_steps(steps):
13
- blocks = []
14
- for idx, item in enumerate(steps, start=1):
15
- blocks.append(f'''<div class="task-item"><div class="item-top"><span class="num">{idx}</span><span>{esc(item.get('标题', '步骤'))}</span></div><div class="item-body">{esc(item.get('说明', ''))}</div></div>''')
16
- return ''.join(blocks)
17
-
18
-
19
- def render_goals(goals):
20
- blocks = []
21
- for item in goals:
22
- blocks.append(f'''<div class="task-item star-item"><div class="item-top"><span class="num">{esc(item.get('等级', ''))}</span><span>{esc(item.get('等级', ''))}</span></div><div class="item-body">{esc(item.get('说明', ''))}</div></div>''')
23
- return ''.join(blocks)
24
-
25
-
26
- def render_tips(tips):
27
- blocks = []
28
- for item in tips:
29
- blocks.append(f'''<div class="tip-item"><div class="tip-title">{esc(item.get('标题', '小提示'))}</div><div class="tip-desc">{esc(item.get('说明', ''))}</div><div class="tip-prompt">参考提示词:{esc(item.get('参考提示词', ''))}</div></div>''')
30
- return ''.join(blocks)
31
-
32
-
33
- def main():
34
- if len(sys.argv) < 2:
35
- print('用法: python3 render_student_page.py <__student__.json> [输出html] [模板html]')
36
- sys.exit(1)
37
-
38
- input_path = Path(sys.argv[1]).expanduser().resolve()
39
- output_path = Path(sys.argv[2]).expanduser().resolve() if len(sys.argv) > 2 else input_path.parent / '__student-view__.html'
40
- template_path = Path(sys.argv[3]).expanduser().resolve() if len(sys.argv) > 3 else Path(__file__).resolve().parent.parent / 'assets' / 'student-template.html'
41
-
42
- data = json.loads(input_path.read_text(encoding='utf-8'))
43
- template = template_path.read_text(encoding='utf-8')
44
-
45
- folder = input_path.parent
46
- if (folder / '__任务__.html').exists():
47
- preview_file = '__任务__.html'
48
- else:
49
- preview_file = data.get('示例页面文件', '__demo__.html')
50
-
51
- rendered = (template
52
- .replace('{{任务标题}}', esc(data.get('任务标题', '未命名任务')))
53
- .replace('{{一句话说明}}', esc(data.get('一句话说明', '')))
54
- .replace('{{步骤区域}}', render_steps(data.get('步骤', [])))
55
- .replace('{{评价目标区域}}', render_goals(data.get('评价目标', [])))
56
- .replace('{{示例区标题}}', esc(data.get('示例区标题', '示范样例')))
57
- .replace('{{示例页面文件}}', esc(preview_file))
58
- .replace('{{小提示区域}}', render_tips(data.get('小提示', [])))
59
- )
60
-
61
- output_path.write_text(rendered, encoding='utf-8')
62
- print(f'已生成: {output_path}')
63
-
64
-
65
- if __name__ == '__main__':
66
- main()