-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
135 lines (110 loc) · 4.34 KB
/
Copy pathmain.py
File metadata and controls
135 lines (110 loc) · 4.34 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
"""CLI entry for paper-validator (python -m paper_validator).
Imports: engine.query, config.defaults, state.store, state.flags
Data: uses StateStore for session tracking (JSON, schema in state/__init__.py)
"""
from __future__ import annotations
import argparse, sys, os
_pkg_root = os.path.dirname(os.path.abspath(__file__))
if _pkg_root not in sys.path:
sys.path.insert(0, _pkg_root)
def cmd_interactive(args):
from engine.query import run_query
from config.defaults import EXECUTION_LAWS
system_prompt = (
"You are a paper validation agent for AI agent governance systems. "
"Tools: read_file, write_file, bash, grep.\n"
"Core principles:\n" +
"\n".join(f"- {v}" for v in EXECUTION_LAWS.values()) +
"\n\nBe direct. Default to executing."
)
print("paper-validator v0.1.0 — interactive mode")
print("Type /exit to quit\n")
while True:
try:
ui = input("> ").strip()
except (EOFError, KeyboardInterrupt):
print("\nGoodbye."); break
if not ui:
continue
if ui == "/exit":
print("Goodbye."); break
print("Thinking...")
result = run_query(system_prompt=system_prompt, user_prompt=ui)
print(f"\n{result['text']}\n")
if result.get("usage"):
u = result["usage"]
print(f"[tokens: {u.get('total_tokens', '?')} | turns: {result['turns']}]\n")
def cmd_claim(args):
from claims.runner import run_claim, run_all, list_claims, summarize
from state.store import StateStore
store = StateStore()
if args.list_claims:
print("Available claims:")
for name in list_claims():
print(f" {name}")
return
if args.claim == "all":
results = run_all(n_trials=args.trials, state_store=store)
print(summarize(results))
return
report = run_claim(args.claim, n_trials=args.trials, state_store=store,
logprobs=args.logprobs)
if report is None:
print(f"Claim '{args.claim}' not found. Use --list to see available claims.")
return
print(f"\n{'='*50}")
print(f"Claim: {report.claim_title}")
print(f"Trials: {report.total_trials}, Errors: {len(report.errors)}")
print(f"Verdict: {report.verdict}")
if report.effect_size:
print(f"Effect size: {report.effect_size:.3f}")
print(f"Metrics: {report.metrics}")
print(f"{'='*50}")
def cmd_health(args):
from config.defaults import DEFAULT_RULES, DEFAULT_CONSTRAINT_PROBES, EVAL_PERSONAS
from state.store import StateStore
from state.flags import FlagManager
store = StateStore()
flags = FlagManager(store)
print("paper-validator v0.1.0 — health check")
print(f" Rules: {len(DEFAULT_RULES)}")
print(f" Probes: {len(DEFAULT_CONSTRAINT_PROBES)}")
print(f" Personas: {len(EVAL_PERSONAS)}")
print(f" Flags: {flags.active_flags()}")
print(f" Sessions: {store.get_counter('sessions')}")
print(" State: OK")
def main():
parser = argparse.ArgumentParser(description="paper-validator")
sub = parser.add_subparsers(dest="command")
sub.add_parser("interactive", aliases=["i"], help="Interactive agent mode")
pc = sub.add_parser("claim", aliases=["c"], help="Run claim experiment")
pc.add_argument("--claim", default="l1-visibility", help="Claim name or 'all'")
pc.add_argument("--trials", "-n", type=int, default=30)
pc.add_argument("--list", dest="list_claims", action="store_true",
help="List available claims")
pc.add_argument("--logprobs", action="store_true",
help="Request logprobs from API")
sub.add_parser("health", aliases=["h"], help="Run health check")
args = parser.parse_args()
store = None
try:
from state.store import StateStore
store = StateStore()
store.increment("sessions")
except Exception:
pass
try:
if args.command in ("interactive", "i"):
cmd_interactive(args)
elif args.command in ("claim", "c"):
cmd_claim(args)
elif args.command in ("health", "h"):
cmd_health(args)
else:
parser.print_help()
finally:
if store:
store.log_audit("session_end", {"command": args.command or "help"})
if __name__ == "__main__":
main()