tailot's picture
thinking-python: reference implementation, corpus and gates
4bc63c7 verified
Raw History Blame Contribute Delete
1.38 kB
"""Node: locator. Finds the candidate in the workspace for a frame.
Deterministic. It runs the preflight admission first, so a workspace outside the mission
never reaches the planner.
"""
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, preflight, session # noqa: E402
def main() -> int:
task = json.load(sys.stdin)
workspace = task["workspace"]
ir = task["ir"]
entries = catalog.load_entries()
admit = preflight.admit(workspace)
if not admit["admitted"]:
print(json.dumps({"node": "locator", "status": "refused",
"reasons": admit["reasons"]}))
return 1
candidates, reasons = session.locate(workspace, ir["frame"], ir.get("anchor"), entries)
if not candidates:
print(json.dumps({"node": "locator", "status": "refused", "reasons": reasons}))
return 1
print(json.dumps({"node": "locator", "status": "ok",
"candidates": [{"file": c["file"], "target": c["target"],
"entry": c["entry"].get("id", ""),
"evidence": c["evidence"]} for c in candidates],
"reasons": reasons}))
return 0
if __name__ == "__main__":
raise SystemExit(main())