GitHub Action
commited on
Commit
·
968fd34
1
Parent(s):
a03d30e
Sync from GitHub with Git LFS
Browse files- scripts/AI_friendly.py +29 -6
- structured_md/README_ko.md +5 -1
scripts/AI_friendly.py
CHANGED
|
@@ -6,6 +6,13 @@ import yaml
|
|
| 6 |
# Корень репозитория — отталкиваемся от местоположения скрипта
|
| 7 |
REPO_ROOT = Path(__file__).resolve().parent.parent
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
ROOT_DIR = Path(".")
|
| 10 |
STRUCTURED_DIR = ROOT_DIR / "structured_md"
|
| 11 |
INDEX_FILE = STRUCTURED_DIR / "index.md"
|
|
@@ -122,10 +129,24 @@ def generate_json_ld(content, front_matter, ftype, title, rel_path):
|
|
| 122 |
title=title, description=desc
|
| 123 |
).replace("}}", f',\n "url": "{url}"\n}}', 1)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
def mirror_md_files():
|
| 126 |
processed = []
|
| 127 |
for path in REPO_ROOT.rglob("*.md"):
|
| 128 |
-
# пропускаем всё внутри structured_md и index.md
|
| 129 |
if "structured_md" in path.parts or path.name.lower() == "index.md":
|
| 130 |
continue
|
| 131 |
|
|
@@ -136,14 +157,13 @@ def mirror_md_files():
|
|
| 136 |
with path.open("r", encoding="utf-8") as f:
|
| 137 |
content = f.read()
|
| 138 |
|
| 139 |
-
# извлекаем существующий фронт-маттер
|
| 140 |
front_matter, clean_content = extract_front_matter(content)
|
| 141 |
ftype = detect_file_type(clean_content, front_matter)
|
| 142 |
title = front_matter.get("title", path.stem)
|
| 143 |
description = front_matter.get("description", clean_content[:100].replace("\n", " ") + "...")
|
| 144 |
-
tags = front_matter.get("tags", [])
|
| 145 |
|
| 146 |
-
# формируем YAML фронт-маттер
|
| 147 |
fm_dict = {
|
| 148 |
"title": title,
|
| 149 |
"description": description,
|
|
@@ -152,10 +172,13 @@ def mirror_md_files():
|
|
| 152 |
}
|
| 153 |
yaml_fm = "---\n" + yaml.safe_dump(fm_dict, sort_keys=False, allow_unicode=True) + "---\n\n"
|
| 154 |
|
|
|
|
|
|
|
|
|
|
| 155 |
# формируем JSON-LD
|
| 156 |
json_ld = generate_json_ld(clean_content, front_matter, ftype, title, rel_path)
|
| 157 |
|
| 158 |
-
# пишем новый Markdown
|
| 159 |
with target_path.open("w", encoding="utf-8") as f:
|
| 160 |
f.write(yaml_fm)
|
| 161 |
f.write(clean_content.rstrip())
|
|
@@ -165,7 +188,7 @@ def mirror_md_files():
|
|
| 165 |
processed.append(rel_path)
|
| 166 |
|
| 167 |
return processed
|
| 168 |
-
|
| 169 |
def generate_index(files):
|
| 170 |
index_lines = ["# ИИ-дружелюбные версии файлов\n"]
|
| 171 |
tree = {}
|
|
|
|
| 6 |
# Корень репозитория — отталкиваемся от местоположения скрипта
|
| 7 |
REPO_ROOT = Path(__file__).resolve().parent.parent
|
| 8 |
|
| 9 |
+
# теги по ключевым словам для автодобавления
|
| 10 |
+
KEYWORD_TAGS = [
|
| 11 |
+
"CCore", "CShell", "REPL", "Mesh", "Agent", "HMP",
|
| 12 |
+
"MeshConsensus", "CogSync", "GMP", "EGP",
|
| 13 |
+
"Ethics", "Scenarios", "JSON"
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
ROOT_DIR = Path(".")
|
| 17 |
STRUCTURED_DIR = ROOT_DIR / "structured_md"
|
| 18 |
INDEX_FILE = STRUCTURED_DIR / "index.md"
|
|
|
|
| 129 |
title=title, description=desc
|
| 130 |
).replace("}}", f',\n "url": "{url}"\n}}', 1)
|
| 131 |
|
| 132 |
+
def add_index_link(content, file_path):
|
| 133 |
+
# относительный путь от текущего файла до structured_md/index.md
|
| 134 |
+
rel_path = os.path.relpath(STRUCTURED_DIR / "index.md", file_path.parent)
|
| 135 |
+
link_line = f"\n\n---\n> ⚡ [AI friendly version docs (structured_md)]({rel_path})\n"
|
| 136 |
+
if link_line.strip() not in content:
|
| 137 |
+
content += link_line
|
| 138 |
+
return content
|
| 139 |
+
|
| 140 |
+
def extract_tags(content, existing_tags):
|
| 141 |
+
tags = set(existing_tags or [])
|
| 142 |
+
for kw in KEYWORD_TAGS:
|
| 143 |
+
if kw.lower() in content.lower():
|
| 144 |
+
tags.add(kw)
|
| 145 |
+
return list(tags)
|
| 146 |
+
|
| 147 |
def mirror_md_files():
|
| 148 |
processed = []
|
| 149 |
for path in REPO_ROOT.rglob("*.md"):
|
|
|
|
| 150 |
if "structured_md" in path.parts or path.name.lower() == "index.md":
|
| 151 |
continue
|
| 152 |
|
|
|
|
| 157 |
with path.open("r", encoding="utf-8") as f:
|
| 158 |
content = f.read()
|
| 159 |
|
|
|
|
| 160 |
front_matter, clean_content = extract_front_matter(content)
|
| 161 |
ftype = detect_file_type(clean_content, front_matter)
|
| 162 |
title = front_matter.get("title", path.stem)
|
| 163 |
description = front_matter.get("description", clean_content[:100].replace("\n", " ") + "...")
|
| 164 |
+
tags = extract_tags(clean_content, front_matter.get("tags", []))
|
| 165 |
|
| 166 |
+
# формируем YAML фронт-маттер
|
| 167 |
fm_dict = {
|
| 168 |
"title": title,
|
| 169 |
"description": description,
|
|
|
|
| 172 |
}
|
| 173 |
yaml_fm = "---\n" + yaml.safe_dump(fm_dict, sort_keys=False, allow_unicode=True) + "---\n\n"
|
| 174 |
|
| 175 |
+
# добавляем ссылку на индекс
|
| 176 |
+
clean_content = add_index_link(clean_content, target_path)
|
| 177 |
+
|
| 178 |
# формируем JSON-LD
|
| 179 |
json_ld = generate_json_ld(clean_content, front_matter, ftype, title, rel_path)
|
| 180 |
|
| 181 |
+
# пишем новый Markdown
|
| 182 |
with target_path.open("w", encoding="utf-8") as f:
|
| 183 |
f.write(yaml_fm)
|
| 184 |
f.write(clean_content.rstrip())
|
|
|
|
| 188 |
processed.append(rel_path)
|
| 189 |
|
| 190 |
return processed
|
| 191 |
+
|
| 192 |
def generate_index(files):
|
| 193 |
index_lines = ["# ИИ-дружелюбные версии файлов\n"]
|
| 194 |
tree = {}
|
structured_md/README_ko.md
CHANGED
|
@@ -410,7 +410,11 @@ OpenCog Hyperon과의 통합은 [HMP\_Hyperon\_Integration.md](docs/HMP_Hyperon_
|
|
| 410 |
* 🤖 — AI 에이전트
|
| 411 |
* 🧒 — 인간-AI 상호작용
|
| 412 |
* ☁️ — 인프라스트럭처
|
| 413 |
-
* 🧪 — 실험적 또는 개념적
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
|
| 415 |
|
| 416 |
```json
|
|
|
|
| 410 |
* 🤖 — AI 에이전트
|
| 411 |
* 🧒 — 인간-AI 상호작용
|
| 412 |
* ☁️ — 인프라스트럭처
|
| 413 |
+
* 🧪 — 실험적 또는 개념적
|
| 414 |
+
|
| 415 |
+
---
|
| 416 |
+
|
| 417 |
+
> ⚡ [AI friendly version docs (structured_md)](structured_md/index.md)
|
| 418 |
|
| 419 |
|
| 420 |
```json
|