File size: 1,382 Bytes
4bc63c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """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())
|