-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplease
More file actions
executable file
·233 lines (172 loc) · 6.98 KB
/
Copy pathplease
File metadata and controls
executable file
·233 lines (172 loc) · 6.98 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python3
"""please -- the project runner (stdlib-only, zero deps).
./please # pretty-printed command listing
./please setup
./please build [--local]
./please run
./please test
./please install <target>
./please deploy <target> [--local]
Windows has no shebang execution -- use `python please <task>` instead of
`./please <task>`.
Targets: opencode, cursor, antigravity, claude, codex, windsurf, cline, copilot
"""
from __future__ import annotations
import argparse
import os
import subprocess
import sys
TARGETS = ("opencode", "cursor", "antigravity", "claude", "codex", "windsurf", "cline", "copilot")
# ── output ──────────────────────────────────────────────────────────────
def _enable_windows_ansi() -> bool:
try:
import ctypes
kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined]
handle = kernel32.GetStdHandle(-11) # STD_OUTPUT_HANDLE
mode = ctypes.c_uint32()
if not kernel32.GetConsoleMode(handle, ctypes.byref(mode)):
return False
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
return bool(kernel32.SetConsoleMode(handle, mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
except Exception:
return False
def _supports_color() -> bool:
if os.environ.get("NO_COLOR"):
return False
if not sys.stdout.isatty():
return False
if sys.platform == "win32":
return _enable_windows_ansi()
return True
_COLOR = _supports_color()
def _c(code: str, text: str) -> str:
return f"\033[{code}m{text}\033[0m" if _COLOR else text
def _bold(text: str) -> str:
return _c("1", text)
def _dim(text: str) -> str:
return _c("2", text)
def _green(text: str) -> str:
return _c("32", text)
def _red(text: str) -> str:
return _c("31", text)
def _cyan(text: str) -> str:
return _c("36", text)
def step(msg: str) -> None:
print(f"{_cyan('→')} {msg}")
def ok(msg: str) -> None:
print(f"{_green('✓')} {msg}")
def fail(msg: str) -> None:
print(f"{_red('✗')} {msg}")
def header(msg: str) -> None:
print(f"\n{_bold(msg)}")
# ── task runner ─────────────────────────────────────────────────────────
def run(cmd: list[str], *, label: str) -> int:
step(label)
print(_dim(" $ " + " ".join(cmd)))
try:
result = subprocess.run(cmd)
except FileNotFoundError:
fail(f"{label} failed -- '{cmd[0]}' not found on PATH. Install it first: https://docs.astral.sh/uv/")
return 1
if result.returncode != 0:
fail(f"{label} failed (exit {result.returncode})")
return result.returncode
def cmd_setup(_args: argparse.Namespace) -> int:
rc = run(["uv", "sync", "--group", "dev"], label="Installing dependencies")
if rc == 0:
ok("Dependencies installed")
return rc
def cmd_build(args: argparse.Namespace) -> int:
if args.local:
rc = run(
["uv", "sync", "--group", "dev", "--extra", "local"],
label="Installing dependencies (with local inference)",
)
if rc:
return rc
pyinstaller_args = [
"uv", "run", "pyinstaller", "--noconfirm", "--onefile", "--name", "codegrave",
"--collect-all", "fastmcp",
"--collect-all", "sqlite_vec",
"--collect-all", "llama_cpp",
"--collect-all", "huggingface_hub",
"main.py",
]
label = "Building fully-offline binary"
else:
rc = cmd_setup(args)
if rc:
return rc
pyinstaller_args = [
"uv", "run", "pyinstaller", "--noconfirm", "--onefile", "--name", "codegrave",
"--collect-all", "fastmcp",
"--collect-all", "sqlite_vec",
"main.py",
]
label = "Building binary"
rc = run(pyinstaller_args, label=label)
if rc == 0:
ok("Binary built -- see ./dist/codegrave")
return rc
def cmd_run(_args: argparse.Namespace) -> int:
return run(["uv", "run", "python", "main.py"], label="Starting codegrave")
def cmd_test(_args: argparse.Namespace) -> int:
rc = run(["uv", "run", "pytest", "tests/", "-v", "--disable-warnings"], label="Running test suite")
if rc == 0:
ok("All tests passed")
return rc
def cmd_install(args: argparse.Namespace) -> int:
rc = run(
["uv", "run", "python", "-m", f"vendors.{args.target}_installer"],
label=f"Wiring up {args.target}",
)
if rc == 0:
ok(f"{args.target} configured")
return rc
def cmd_deploy(args: argparse.Namespace) -> int:
header(f"Deploying to {args.target}")
rc = cmd_build(args)
if rc:
return rc
return cmd_install(args)
def _cmd_list() -> int:
"""Pretty-print the available commands (like just --list)."""
header("Available tasks:")
print()
tasks = [
("setup", "", "Install dependencies (uv sync)"),
("build", "[--local]", "Build the PyInstaller binary"),
("run", "", "Run the MCP server locally"),
("test", "", "Run the test suite"),
("install", "<target>", "Wire codegrave into an IDE workspace"),
("deploy", "<target> [--local]", "Build then install for an IDE (one-click)"),
]
max_cmd = max(len(cmd) + len(args) + 2 for cmd, args, _ in tasks)
for cmd, args, desc in tasks:
name = f"{cmd} {args}".strip() if args else cmd
print(f" {_bold(name):<{max_cmd}} {_dim(desc)}")
print()
print(_dim("Targets: ") + ", ".join(TARGETS))
return 0
def main() -> int:
parser = argparse.ArgumentParser(prog="please", description="The Codegrave project runner")
sub = parser.add_subparsers(dest="task")
sub.add_parser("setup", help="Install dependencies (uv sync)").set_defaults(func=cmd_setup)
build_p = sub.add_parser("build", help="Build the PyInstaller binary")
build_p.add_argument("--local", action="store_true", help="Bundle local GGUF inference (llama-cpp, huggingface-hub)")
build_p.set_defaults(func=cmd_build)
sub.add_parser("run", help="Run the MCP server locally").set_defaults(func=cmd_run)
sub.add_parser("test", help="Run the test suite").set_defaults(func=cmd_test)
install_p = sub.add_parser("install", help="Wire codegrave into an IDE workspace")
install_p.add_argument("target", choices=TARGETS)
install_p.set_defaults(func=cmd_install)
deploy_p = sub.add_parser("deploy", help="Build then install for an IDE (one-click)")
deploy_p.add_argument("target", choices=TARGETS)
deploy_p.add_argument("--local", action="store_true", help="Bundle local GGUF inference in the build step")
deploy_p.set_defaults(func=cmd_deploy)
args = parser.parse_args()
if args.task is None:
return _cmd_list()
return args.func(args)
if __name__ == "__main__":
sys.exit(main())