renaming from mybot to myclaude
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
"""CLI subcommands."""
|
||||
|
||||
from .chat import chat_cmd
|
||||
from .update import update_cmd
|
||||
|
||||
__all__ = ["chat_cmd", "update_cmd"]
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Start Claude Code in the myclaude project directory."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
from rich.console import Console
|
||||
|
||||
from myclaude.project_root import get_myclaude_project_root
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def _resolve_chat_cwd() -> Path:
|
||||
root = get_myclaude_project_root()
|
||||
fallback = Path.home() / ".myclaude"
|
||||
if root == fallback:
|
||||
console.print(
|
||||
"[red]Cannot resolve myclaude project root.[/red] Run from the repo or set "
|
||||
"[cyan]MYCLAUDE_PROJECT_ROOT[/cyan].",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
return root
|
||||
|
||||
|
||||
@click.command(
|
||||
"chat",
|
||||
context_settings={
|
||||
"ignore_unknown_options": True,
|
||||
"allow_extra_args": True,
|
||||
},
|
||||
)
|
||||
@click.option(
|
||||
"--dangerously-skip-permissions",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Forward to claude: bypass permission checks (sandbox / isolated use only).",
|
||||
)
|
||||
@click.pass_context
|
||||
def chat_cmd(ctx: click.Context, dangerously_skip_permissions: bool) -> None:
|
||||
"""Run `claude` in the myclaude repo so CLAUDE.md and .claude/ apply; extra args pass through."""
|
||||
binary = os.environ.get("CLAUDE_BIN") or shutil.which("claude")
|
||||
if not binary:
|
||||
console.print(
|
||||
"[red]claude CLI not found in PATH.[/red] Install Claude Code or set "
|
||||
"[cyan]CLAUDE_BIN[/cyan].",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(127)
|
||||
|
||||
cwd = _resolve_chat_cwd()
|
||||
cmd: list[str] = [binary]
|
||||
if dangerously_skip_permissions:
|
||||
cmd.append("--dangerously-skip-permissions")
|
||||
cmd.extend(ctx.args)
|
||||
|
||||
proc = subprocess.run(cmd, cwd=str(cwd), check=False)
|
||||
raise SystemExit(proc.returncode)
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Reinstall myclaude from the local repo."""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
from rich.console import Console
|
||||
|
||||
from myclaude.project_root import get_myclaude_project_root
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def _run_make_install(root: Path) -> int:
|
||||
return subprocess.run(
|
||||
["make", "install"],
|
||||
cwd=str(root),
|
||||
check=False,
|
||||
).returncode
|
||||
|
||||
|
||||
def _run_pip_editable(root: Path) -> int:
|
||||
cmd = [sys.executable, "-m", "pip", "install", "-e", str(root)]
|
||||
return subprocess.run(cmd, cwd=str(root), check=False).returncode
|
||||
|
||||
|
||||
@click.command("update")
|
||||
def update_cmd() -> None:
|
||||
"""Reinstall myclaude from this repository (make install, or pip install -e)."""
|
||||
root = get_myclaude_project_root()
|
||||
fallback = Path.home() / ".myclaude"
|
||||
if root == fallback:
|
||||
console.print(
|
||||
"[red]Not inside myclaude repo.[/red] Set [cyan]MYCLAUDE_PROJECT_ROOT[/cyan] "
|
||||
"or run from the clone.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
|
||||
console.print("[bold cyan]Updating myclaude…[/bold cyan]")
|
||||
makefile = root / "Makefile"
|
||||
if makefile.is_file():
|
||||
rc = _run_make_install(root)
|
||||
if rc != 0:
|
||||
console.print("[yellow]make install failed, trying pip -e…[/yellow]")
|
||||
rc = _run_pip_editable(root)
|
||||
else:
|
||||
rc = _run_pip_editable(root)
|
||||
|
||||
if rc != 0:
|
||||
console.print("[red]Update failed.[/red]", file=sys.stderr)
|
||||
raise SystemExit(rc)
|
||||
console.print("[green]myclaude updated.[/green]")
|
||||
Reference in New Issue
Block a user