File size: 1,222 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
"""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())