Open an interactive claude with the setup loaded through claude-release
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
This commit is contained in:
@@ -31,6 +31,7 @@ build-release runs every claude in the loop's Claude home, ~/.local/share/build-
|
||||
which it builds from the clone it ships in before it starts anything. Until someone has signed in
|
||||
there, it stops and prints the command to sign in with. README.md → Install says what the
|
||||
home holds.
|
||||
`claude-release [<claude argument>…]` opens an interactive claude in that home.
|
||||
|
||||
build-release needs tmux 3.2 or later, and checks that too before it starts anything. Each chunk
|
||||
runs in its own window of one tmux session per project, named loop-<key>, such as
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
# Said before the first import of the setup's code, which an older Python cannot read.
|
||||
if sys.version_info < (3, 14):
|
||||
sys.exit(f"claude-release needs Python 3.14 or later as python3 on PATH; it found Python {sys.version.split()[0]}")
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from claude_release import main
|
||||
from loop_effects import effects
|
||||
|
||||
sys.exit(main.main(sys.argv[1:], pathlib.Path.cwd(), effects.system_effects(pathlib.Path.home(), os.environ)))
|
||||
@@ -19,6 +19,8 @@ LINKED = ("CLAUDE.md", "agents", "bin", "principles", "rules", "skills")
|
||||
CLONE = "{clone}"
|
||||
# Stands for the reports folder, which holds every chunk's review folder, in the clone's settings.json. Every value that holds it is a path, so unlike CLONE it isn't shell-quoted.
|
||||
REPORTS = "{reports}"
|
||||
# What `unready` says first where nobody has signed in to the home yet; `claude-release` runs there anyway, since /login is typed in that claude.
|
||||
SIGNED_OUT = "nobody is signed in to the loop's Claude home"
|
||||
# The file in the home that names the clone, its commit and the reports folder the home was built from.
|
||||
BUILT_FROM = "built-from"
|
||||
|
||||
@@ -45,7 +47,7 @@ def unready(home: pathlib.Path, clone: pathlib.Path, reports: pathlib.Path, clau
|
||||
if signed:
|
||||
return None
|
||||
# /login is typed in a claude that runs in the home: docs/decisions.md → `Claude Code in a home of its own`.
|
||||
return f"nobody is signed in to the loop's Claude home; run `CLAUDE_CONFIG_DIR={shlex.quote(str(home))} claude` and type /login there, once"
|
||||
return f"{SIGNED_OUT}; run `CLAUDE_CONFIG_DIR={shlex.quote(str(home))} claude` and type /login there, once"
|
||||
|
||||
|
||||
def signed_in(status: str) -> bool | None:
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from claude_home.home import SIGNED_OUT
|
||||
from loop_effects.effects import Effects
|
||||
|
||||
|
||||
# The spelling, a command of its own beside build-release: a panel of readers seated as the README's audience rejected `build-release claude`, since build-release reads every word after its name as a task, so a task that starts with "claude" would mean something else. They picked the name that opens with the word they look for.
|
||||
def main(argv: list[str], cwd: pathlib.Path, effects: Effects) -> int:
|
||||
"""Runs claude on the terminal in cwd with argv as its arguments, in the loop's Claude home with the release's tools first on `PATH`, which the effect sets for every claude it starts. Returns claude's exit code, or 1 where the home cannot be built."""
|
||||
not_ready = effects.claude_home()
|
||||
# Where nobody has signed in yet, the login is typed in this claude.
|
||||
if not_ready and not not_ready.startswith(SIGNED_OUT):
|
||||
print(not_ready, file=sys.stderr)
|
||||
return 1
|
||||
return effects.claude_on_terminal(argv, str(cwd), {})
|
||||
@@ -0,0 +1,41 @@
|
||||
import contextlib
|
||||
import io
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from claude_home.home import SIGNED_OUT
|
||||
from claude_release import main
|
||||
from loop_effects.doubles import FakeEffects
|
||||
|
||||
|
||||
class ClaudeRelease(unittest.TestCase):
|
||||
def run_main(self, args: list[str], fake: FakeEffects) -> tuple[int, str]:
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err):
|
||||
return main.main(args, pathlib.Path("/project"), fake.effects()), err.getvalue()
|
||||
|
||||
def test_passes_every_argument_on_to_claude_in_the_folder_it_runs_in(self):
|
||||
fake = FakeEffects(on_terminal_claude=[0])
|
||||
code, err = self.run_main(["--resume", "abc", "--model", "opus", "-p", "hi"], fake)
|
||||
self.assertEqual((code, err, fake.made("claude_on_terminal"), fake.terminal_folders), (0, "", [["--resume", "abc", "--model", "opus", "-p", "hi"]], ["/project"]))
|
||||
|
||||
def test_exits_with_the_code_of_claude(self):
|
||||
self.assertEqual(self.run_main([], FakeEffects(on_terminal_claude=[3]))[0], 3)
|
||||
|
||||
def test_opens_claude_where_nobody_is_signed_in_yet_for_the_login_typed_there(self):
|
||||
fake = FakeEffects(on_terminal_claude=[0])
|
||||
fake.home_unready = f"{SIGNED_OUT}; run `CLAUDE_CONFIG_DIR=/h claude` and type /login there, once"
|
||||
self.assertEqual((self.run_main([], fake)[0], len(fake.made("claude_on_terminal"))), (0, 1))
|
||||
|
||||
def test_stops_where_the_home_cannot_be_built(self):
|
||||
fake = FakeEffects()
|
||||
fake.home_unready = "could not build the loop's Claude home, /h: disk full"
|
||||
code, err = self.run_main(["--resume"], fake)
|
||||
self.assertEqual((code, err, fake.made("claude_on_terminal")), (1, "could not build the loop's Claude home, /h: disk full\n", []))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user