Files
ss-tools/.axiom/temp/convert_v3.py
2026-05-13 14:15:33 +03:00

65 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Phase 3: Final conversion pass - DEF→region, @PURPOSE→@BRIEF, strip @LAYER/@PARAM/@RETURN."""
import os, re, sys, glob
DRY_RUN = '--dry-run' in sys.argv
def convert_file(filepath):
with open(filepath) as f:
content = f.read()
original = content
# === PART 1: Convert DEF opening anchors ===
# Python style
content = re.sub(r'# \[DEF:([^:]+):([^\]]+)\]', r'# #region \1 [C:2] [TYPE \2]', content)
content = re.sub(r'# \[/DEF:([^:]+):([^\]]+)\]', r'# #endregion \1', content)
# JS/Svelte // style
content = re.sub(r'// \[DEF:([^:]+):([^\]]+)\]', r'// #region \1 [C:2] [TYPE \2]', content)
content = re.sub(r'// \[/DEF:([^:]+):([^\]]+)\]', r'// #endregion \1', content)
# JSDoc style: * [DEF:...]
content = re.sub(r' \* \[DEF:([^:]+):([^\]]+)\]', r' * #region \1 [C:2] [TYPE \2]', content)
content = re.sub(r' \* \[/DEF:([^:]+):([^\]]+)\]', r' * #endregion \1', content)
# HTML/Svelte <!-- style
content = re.sub(r'<!-- \[DEF:([^:]+):([^\]]+)\] -->', r'<!-- #region \1 [C:2] [TYPE \2] -->', content)
content = re.sub(r'<!-- \[/DEF:([^:]+):([^\]]+)\] -->', r'<!-- #endregion \1 -->', content)
# === PART 2: Normalize @PURPOSE: → @BRIEF ===
content = re.sub(r'^(\s*[#/])\s*@PURPOSE:\s*', r'\1 @BRIEF ', content, flags=re.MULTILINE)
content = re.sub(r'^(\s*[#/])\s*@PURPOSE\s+(?!\w)', r'\1 @BRIEF ', content, flags=re.MULTILINE)
# === PART 3: Remove @LAYER, @PARAM, @RETURN lines ===
content = re.sub(r'^[ \t]*[#/][ \t]*@LAYER:?[ \t]*.*$', '', content, flags=re.MULTILINE)
content = re.sub(r'^[ \t]*[#/][ \t]*@PARAM:?[ \t]*.*$', '', content, flags=re.MULTILINE)
content = re.sub(r'^[ \t]*[#/][ \t]*@RETURN:?[ \t]*.*$', '', content, flags=re.MULTILINE)
# Cleanup: collapse 3+ consecutive blank lines to 2
content = re.sub(r'\n[ \t]*\n[ \t]*\n', '\n\n', content)
if content == original:
return False
if DRY_RUN:
print(f"[DRY-RUN] Would modify: {filepath}")
return True
with open(filepath, 'w') as f:
f.write(content)
print(f"Modified: {filepath}")
return True
def main():
all_files = []
for pat in ['backend/**/*.py', 'frontend/src/**/*.svelte', 'frontend/src/**/*.js', 'frontend/src/**/*.ts']:
all_files.extend(glob.glob(os.path.join('/home/busya/dev/ss-tools', pat), recursive=True))
all_files = sorted(set(f for f in all_files if '.axiom' not in f and '.venv' not in f))
total = converted = 0
for fp in all_files:
total += 1
if convert_file(fp):
converted += 1
print(f"\nTotal: {total} files, Modified: {converted}")
if __name__ == '__main__':
main()