-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathai-hist
More file actions
executable file
·161 lines (135 loc) · 4.07 KB
/
Copy pathai-hist
File metadata and controls
executable file
·161 lines (135 loc) · 4.07 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
"""Rust-first ai-hist dispatcher."""
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
PYTHON_CLI = ROOT / "ai-hist-python"
RUST_MANIFEST = ROOT / "Cargo.toml"
RUST_COMMANDS = {
"search",
"recent",
"session",
"resume",
"sync-opencode",
"show",
"context",
"stats",
"pack",
"watch",
"export",
"import",
"tag",
"untag",
"tags",
"sync",
"login",
"admin-mint",
"push",
"coverage",
"pair",
"learn",
}
PYTHON_COMMANDS = set()
PYTHON_ONLY_FLAGS = {}
def main():
mode = os.environ.get("AI_HIST_CLI", "auto").strip().lower()
if mode not in {"auto", "rust", "python"}:
print(
"ai-hist: AI_HIST_CLI must be one of auto, rust, or python",
file=sys.stderr,
)
return 2
argv = sys.argv[1:]
if mode == "python":
return run_python(argv, warn=False)
if mode == "rust":
return run_rust(argv)
if is_top_level_help(argv):
print_wrapper_help()
return 0
route, reason = route_auto(argv)
if route == "python":
return run_python(argv, warn=True, reason=reason)
return run_rust(argv)
def route_auto(argv):
if not argv:
return "help", None
first = argv[0]
if first in {"-V", "--version"}:
return "rust", None
if first in PYTHON_COMMANDS:
return "python", f"`{first}` is still implemented by the legacy Python CLI"
if first in PYTHON_ONLY_FLAGS:
used = [arg for arg in argv[1:] if arg in PYTHON_ONLY_FLAGS[first]]
if used:
return (
"python",
f"`{first}` option(s) {', '.join(used)} are still implemented by the legacy Python CLI",
)
if first in RUST_COMMANDS:
return "rust", None
return "rust", None
def is_top_level_help(argv):
return not argv or argv in (["-h"], ["--help"], ["help"])
def print_wrapper_help():
print(
"""ai-hist: Rust-first AI history CLI
Usage:
ai-hist [COMMAND] [OPTIONS]
Rust-default commands:
search Full-text search prompts
recent Show most recent entries
session Show all prompts in a session
resume Print a resume command
sync-opencode Sync OpenCode history explicitly
show Show full details for an entry by ID
context Show entries around an ID
stats Show summary statistics
pack Evidence bundle for LLM handoff
watch Continuous sync loop
export Export JSONL/gzip/SQLite with filters
import Import JSONL/gzip/SQLite with dry-run support
setup Install local integrations (for example git hooks)
link Link sessions to commits and other artifacts
tag Tag a session
untag Remove a tag from a session
tags List tags and tagged sessions
login Authenticate through Agent Relay Cloud
admin-mint Dev-only local relayhistory token mint
push Push new local history to relayhistory-cloud
coverage Show which machines are pushing, and how recently
pair Ask relayhistory-cloud for in-session warnings
learn Distill history into Pair signal
Rust binary override:
AI_HIST_RUST_BIN=/path/to/ai-hist
ai-hist-rust"""
)
def run_python(argv, warn=False, reason=None):
if warn:
detail = f": {reason}" if reason else ""
print(
f"ai-hist: using deprecated Python fallback{detail}",
file=sys.stderr,
)
return subprocess.run([sys.executable, str(PYTHON_CLI), *argv]).returncode
def run_rust(argv):
rust_bin = os.environ.get("AI_HIST_RUST_BIN")
if rust_bin:
cmd = [rust_bin, *argv]
else:
cmd = [
"cargo",
"run",
"-q",
"-p",
"ai-hist-cli",
"--manifest-path",
str(RUST_MANIFEST),
"--",
*argv,
]
return subprocess.run(cmd).returncode
if __name__ == "__main__":
raise SystemExit(main())