64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import os
|
||
|
|
import re
|
||
|
|
import subprocess
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
INTELLECTON_DIR = Path("/home/antigravity/intellecton/papers")
|
||
|
|
PORTAL_DIR = Path("/home/antigravity/knowledge-engineering-fortress/content/papers")
|
||
|
|
|
||
|
|
def extract_tex(file_path):
|
||
|
|
with open(file_path, "r", encoding="utf-8") as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
title_match = re.search(r"\\title\{(.*?)\}", content, re.DOTALL)
|
||
|
|
abstract_match = re.search(r"\\begin\{abstract\}(.*?)\\end\{abstract\}", content, re.DOTALL)
|
||
|
|
|
||
|
|
title = title_match.group(1).strip() if title_match else "Untitled"
|
||
|
|
title = re.sub(r"\\(?:textbf|textit)\{(.*?)\}", r"\1", title) # clean simple latex
|
||
|
|
|
||
|
|
abstract = abstract_match.group(1).strip() if abstract_match else "No abstract provided."
|
||
|
|
# Clean up basic latex math and newlines
|
||
|
|
abstract = re.sub(r"\\\\", "\n", abstract)
|
||
|
|
abstract = re.sub(r"\$([^\$]+)\$", r"`\1`", abstract) # Convert inline math to code block or leave as math
|
||
|
|
return title, abstract
|
||
|
|
|
||
|
|
def build_bridge():
|
||
|
|
changed = False
|
||
|
|
print("JULES CI/CD: Scanning Intellecton Canon...")
|
||
|
|
for root, dirs, files in os.walk(INTELLECTON_DIR):
|
||
|
|
for f in files:
|
||
|
|
if f.endswith(".tex") and "master_key" in root:
|
||
|
|
tex_path = Path(root) / f
|
||
|
|
title, abstract = extract_tex(tex_path)
|
||
|
|
|
||
|
|
# Create Markdown filename
|
||
|
|
paper_id = tex_path.parent.parent.name # e.g. project_paper_1_relativity
|
||
|
|
md_filename = f"{paper_id}.md"
|
||
|
|
md_path = PORTAL_DIR / md_filename
|
||
|
|
|
||
|
|
# Check if it already exists and is up to date
|
||
|
|
new_content = f"# {title}\n\n**Abstract:**\n{abstract}\n\n*This file is continuously synchronized by the Jules CI/CD Bridge.*"
|
||
|
|
|
||
|
|
if md_path.exists():
|
||
|
|
with open(md_path, "r", encoding="utf-8") as existing:
|
||
|
|
if existing.read() == new_content:
|
||
|
|
continue # No changes needed
|
||
|
|
|
||
|
|
# Write to portal
|
||
|
|
print(f"JULES CI/CD: Syncing {paper_id} to portal...")
|
||
|
|
with open(md_path, "w", encoding="utf-8") as out:
|
||
|
|
out.write(new_content)
|
||
|
|
changed = True
|
||
|
|
|
||
|
|
if changed:
|
||
|
|
print("JULES CI/CD: Detected changes. Committing to portal...")
|
||
|
|
subprocess.run(["git", "add", "."], cwd=PORTAL_DIR)
|
||
|
|
subprocess.run(["git", "commit", "-m", "Jules CI/CD: Autonomous paper sync from Intellecton"], cwd=PORTAL_DIR)
|
||
|
|
print("JULES CI/CD: Sync complete.")
|
||
|
|
else:
|
||
|
|
print("JULES CI/CD: All portals are synchronized.")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
build_bridge()
|