tailot's picture
thinking-python: reference implementation, corpus and gates
4bc63c7 verified
Raw History Blame Contribute Delete
1.22 kB
"""Node: planner. Turns the located candidate into a language free plan.
The plan carries a frame, a file, a line window and the text of the edit pair. It carries
no word of the request: tests/test_language_free_plan.py checks exactly that.
"""
import json
import os
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT)
from lingologos_thinkingpython import catalog, session # noqa: E402
def main() -> int:
task = json.load(sys.stdin)
workspace = task["workspace"]
candidate = task["candidates"][0]
entries = catalog.load_entries()
entry = catalog.by_id(entries, candidate["entry"]) or {}
shaped = {"file": candidate["file"], "target": candidate["target"], "entry": entry,
"evidence": candidate["evidence"]}
cwd = os.getcwd()
try:
os.chdir(workspace)
planned = session.plan(shaped)
finally:
os.chdir(cwd)
if not planned.get("edits"):
print(json.dumps({"node": "planner", "status": "refused", "reason": "NO_EDIT"}))
return 1
print(json.dumps({"node": "planner", "status": "ok", "plan": planned}))
return 0
if __name__ == "__main__":
raise SystemExit(main())