Files
vibemake-pcb-studio/backend/api/app/core_runner.py
T

28 lines
1.5 KiB
Python

"""Child process boundary. Uses only the core's public service interface."""
import argparse,json,os,sys
from pathlib import Path
def emit(value):print(json.dumps(value,ensure_ascii=False),flush=True)
def main():
p=argparse.ArgumentParser();p.add_argument('--pack',help='Deprecated compatibility argument; unused');p.add_argument('--root',required=True);a=p.parse_args()
command=json.load(sys.stdin)
backend=Path(__file__).resolve().parents[2]
sys.path.insert(0,str(backend))
task_id=command.get('payload',{}).get('task_id')
native=True
if task_id:
# New tasks persist their engine; old frozen tasks remain readable.
import re
if not isinstance(task_id,str) or not re.fullmatch(r'pcb-[a-z0-9]{12,32}',task_id):
raise ValueError('Invalid task identity')
path=Path(a.root)/'tasks'/task_id/'task.json'
if path.is_file():native=json.loads(path.read_text()).get('eda_engine')=='kicad'
if not native and command['action'] not in {'status','events'}:
raise ValueError('旧绘图引擎已停用;历史冻结成果仍可下载,请创建 KiCad 新任务继续设计')
from kicad_backend.service import handle_request
def on_event(event):emit({'event':event})
value=handle_request(a.root,command,event_callback=on_event);emit({'result':value})
if __name__=='__main__':
try:main()
except Exception as exc:emit({'result':{'error':type(exc).__name__,'message':str(exc)}});raise SystemExit(1)