-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (34 loc) · 1.09 KB
/
main.py
File metadata and controls
45 lines (34 loc) · 1.09 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
#!/usr/bin/env python3
"""
agentfs — AST-based file TOC tool for AI coding agents.
Commands:
toc <file> Print the TOC of a source file
benchmark <dir> [options] Compare token usage: full-read vs toc-first
"""
import sys
import os
def cmd_toc(args):
if not args or args[0] in ('-h', '--help'):
print("Usage: agentfs toc <file>")
print(" Print a token-efficient table of contents of a source file.")
sys.exit(0)
from agentfs.virtual.toc import generate_toc
print(generate_toc(args[0]), end='')
def cmd_benchmark(args):
bench = os.path.join(os.path.dirname(__file__), 'benchmark.py')
os.execv(sys.executable, [sys.executable, bench] + args)
COMMANDS = {
'toc': cmd_toc,
'benchmark': cmd_benchmark,
}
def main():
if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'):
print(__doc__)
sys.exit(0)
cmd = sys.argv[1]
if cmd not in COMMANDS:
print(f"Unknown command: {cmd}\n{__doc__}", file=sys.stderr)
sys.exit(1)
COMMANDS[cmd](sys.argv[2:])
if __name__ == '__main__':
main()