File size: 1,604 Bytes
297df1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Offline agent integration example; runs from any working directory."""
from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path

REPOSITORY = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPOSITORY))
import agent_tools


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--fixture", type=Path,
                        default=REPOSITORY / "fixtures" / "hidden-forks-rank-12.bin")
    options = parser.parse_args()
    try:
        result = agent_tools.assess_file(options.fixture)
        result["example"] = {
            "name": "bounded one-file assessment",
            "repository_resolved_from_script": str(REPOSITORY),
            "next_action": "retain exact byte and digest verification when evaluating another file"}
        print(json.dumps({"schema_version": agent_tools.SCHEMA_VERSION, "ok": True,
                          "command": "agent_quickstart",
                          "packaging_version": agent_tools.PACKAGING_VERSION,
                          "codec_archive_version": 3, "result": result},
                         sort_keys=True, allow_nan=False))
        return 0
    except (OSError, ValueError, RuntimeError, AssertionError) as error:
        print(json.dumps({"schema_version": agent_tools.SCHEMA_VERSION, "ok": False,
                          "command": "agent_quickstart",
                          "error": {"type": type(error).__name__, "message": str(error)}}))
        return 2


if __name__ == "__main__":
    sys.exit(main())