-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathentry.py
More file actions
89 lines (72 loc) · 3.21 KB
/
Copy pathentry.py
File metadata and controls
89 lines (72 loc) · 3.21 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
"""engraphis - the single front door, so the portal's copy-paste command actually runs.
Every capability already ships as its own ``engraphis-<verb>`` console script; this adds
the spelling customers are *shown*. The account portal hands out
engraphis connect --token engr_ct_...
and until there was an ``engraphis`` executable that string was not a runnable command.
This is a dispatcher, not a second CLI: it rewrites ``sys.argv`` and calls the same
``main()`` the matching ``engraphis-<verb>`` script calls, so a verb behaves identically
either way and there is exactly one implementation of each command. The import is lazy
so ``engraphis connect`` never drags in the memory/embedding stack that ``engraphis cli``
needs.
"""
from __future__ import annotations
import sys
from importlib import import_module
#: verb -> "module:function", mirroring ``[project.scripts]`` with the prefix dropped.
COMMANDS = {
"connect": "scripts.connect:main",
"init": "scripts.init:main",
"cli": "scripts.cli:main",
"mcp": "engraphis.mcp_cli:main",
"server": "scripts.start_server:main",
"dashboard": "scripts.start_dashboard:main",
"inspector": "scripts.inspector:main",
"consolidate": "scripts.consolidate:main",
"graph": "scripts.graph_cli:main",
"graph-server": "scripts.graph_server:main",
"update": "scripts.update:main",
}
_USAGE = """usage: engraphis <command> [options]
commands:
connect redeem the connect token from your account portal
init write a project .env and print agent setup snippets
cli store and recall memories from the terminal
mcp run the MCP server (Claude Code, Cursor, Cline, Zed)
server run the REST server
dashboard run the product dashboard
inspector inspect the local database
consolidate run consolidation over stored memories
graph query the knowledge graph
graph-server run the graph server
update check for and install a newer Engraphis release
Run `engraphis <command> --help` for a command's options.
Every command is also installed as `engraphis-<command>`."""
def main(argv=None) -> int:
args = list(sys.argv[1:] if argv is None else argv)
if not args or args[0] in {"-h", "--help", "help"}:
print(_USAGE)
return 0 if args else 2
if args[0] in {"-V", "--version"}:
from engraphis import __version__
print(__version__)
return 0
verb = args[0]
target = COMMANDS.get(verb)
if target is None:
print("engraphis: unknown command %r\n" % verb, file=sys.stderr)
print(_USAGE, file=sys.stderr)
return 2
module_name, _, attribute = target.partition(":")
command = getattr(import_module(module_name), attribute)
# Hand the verb its own argv. Some targets take ``main(argv)`` and some read
# ``sys.argv`` directly, so rewriting is the one approach that works for all of
# them -- and it also puts "engraphis connect" in that command's --help/usage.
saved = sys.argv
sys.argv = ["engraphis %s" % verb] + args[1:]
try:
result = command()
finally:
sys.argv = saved
return 0 if result is None else int(result)
if __name__ == "__main__":
raise SystemExit(main())