Skip to content

Commit 2c5316c

Browse files
committed
Move push to config
1 parent 0f738e3 commit 2c5316c

7 files changed

Lines changed: 61 additions & 20 deletions

File tree

codeclash/agents/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from codeclash.agents.utils import GameContext
77

88

9-
def get_agent(config: dict, game_context: GameContext, environment: DockerEnvironment, push: bool = False) -> Player:
9+
def get_agent(config: dict, game_context: GameContext, environment: DockerEnvironment) -> Player:
1010
agents = {
1111
"dummy": Dummy,
1212
"mini": MiniSWEAgent,
1313
}.get(config["agent"])
1414
if agents is None:
1515
raise ValueError(f"Unknown agent type: {config['agent']}")
16-
return agents(config, environment, game_context, push=push)
16+
return agents(config, environment, game_context)

codeclash/agents/minisweagent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def add_message(self, role: str, content: str, **kwargs):
4747
class MiniSWEAgent(Player):
4848
"""Player with agentic code editing capabilities"""
4949

50-
def __init__(self, config: dict, environment: DockerEnvironment, game_context: GameContext, push: bool = False):
51-
super().__init__(config, environment=environment, game_context=game_context, push=push)
50+
def __init__(self, config: dict, environment: DockerEnvironment, game_context: GameContext):
51+
super().__init__(config, environment=environment, game_context=game_context)
5252

5353
def run(self):
5454
# temporary workaround around https://github.com/SWE-agent/mini-swe-agent/issues/477

codeclash/agents/player.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ def __init__(
2222
config: dict,
2323
environment: DockerEnvironment,
2424
game_context: GameContext,
25-
push: bool = False,
2625
) -> None:
2726
self.config = config
2827
self.name = config["name"]
2928
self._player_unique_id = str(uuid.uuid4())
3029
"""Unique ID that doesn't clash even across multiple games. Used for git tags."""
3130
self.environment = environment
3231
self.game_context = game_context
33-
self.push = push
32+
self.push = config.get("push", False)
3433
self.logger = get_logger(
3534
self.name,
3635
log_path=self.game_context.log_local / "players" / self.name / "player.log",

codeclash/tournaments/pvp.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def __init__(
2727
*,
2828
output_dir: Path,
2929
cleanup: bool = False,
30-
push: bool = False,
3130
keep_containers: bool = False,
3231
):
3332
metadata_file = output_dir / "metadata.json"
@@ -44,7 +43,7 @@ def __init__(
4443
)
4544
self.agents: list[Player] = []
4645
for agent_conf in self.config["players"]:
47-
self.agents.append(self.get_agent(agent_conf, self.config["prompts"], push=push))
46+
self.agents.append(self.get_agent(agent_conf, self.config["prompts"]))
4847

4948
@property
5049
def metadata_file(self) -> Path:
@@ -66,7 +65,7 @@ def get_metadata(self) -> dict:
6665
"agents": [agent.get_metadata() for agent in self.agents],
6766
}
6867

69-
def get_agent(self, agent_config: dict, prompts: dict, push: bool) -> Player:
68+
def get_agent(self, agent_config: dict, prompts: dict) -> Player:
7069
"""Create an agent with environment and game context."""
7170
environment = self.game.get_environment(f"{self.game.game_id}.{agent_config['name']}")
7271

@@ -82,7 +81,7 @@ def get_agent(self, agent_config: dict, prompts: dict, push: bool) -> Player:
8281
working_dir=str(DIR_WORK),
8382
)
8483

85-
return get_agent(agent_config, game_context, environment, push=push)
84+
return get_agent(agent_config, game_context, environment)
8685

8786
def run(self) -> None:
8887
"""Main execution function that runs all rounds."""

main.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def main(
1818
config_path: Path,
1919
*,
2020
cleanup: bool = False,
21-
push: bool = False,
2221
output_dir: Path | None = None,
2322
suffix: str = "",
2423
keep_containers: bool = False,
@@ -62,9 +61,7 @@ def get_output_path() -> Path:
6261

6362
full_output_dir = get_output_path()
6463

65-
tournament = PvpTournament(
66-
config, output_dir=full_output_dir, cleanup=cleanup, push=push, keep_containers=keep_containers
67-
)
64+
tournament = PvpTournament(config, output_dir=full_output_dir, cleanup=cleanup, keep_containers=keep_containers)
6865
tournament.run()
6966

7067

@@ -81,12 +78,6 @@ def main_cli(argv: list[str] | None = None):
8178
action="store_true",
8279
help="If set, do not clean up the game environment after running.",
8380
)
84-
parser.add_argument(
85-
"-p",
86-
"--push",
87-
action="store_true",
88-
help="If set, push each agent's codebase to a new repository after running.",
89-
)
9081
parser.add_argument(
9182
"-o",
9283
"--output-dir",

scripts/make_ladder.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import argparse
2+
from pathlib import Path
3+
4+
import yaml
5+
6+
from codeclash import CONFIG_DIR
7+
from codeclash.constants import LOCAL_LOG_DIR
8+
from codeclash.tournaments.pvp import PvpTournament
9+
from codeclash.utils.yaml_utils import resolve_includes
10+
11+
12+
def main(
13+
config_path: Path,
14+
):
15+
yaml_content = config_path.read_text()
16+
preprocessed_yaml = resolve_includes(yaml_content, base_dir=CONFIG_DIR)
17+
config = yaml.safe_load(preprocessed_yaml)
18+
19+
players = config["players"]
20+
num_players = len(players)
21+
for i in range(num_players):
22+
for j in range(i + 1, num_players):
23+
player1 = players[i]
24+
player1["name"] = player1["branch_init"]
25+
player2 = players[j]
26+
player2["name"] = player2["branch_init"]
27+
pvp_config = {
28+
**config,
29+
"players": [player1, player2],
30+
}
31+
vs = f"PvpTournament.{player1['name']}_vs_{player2['name']}".replace("/", "_")
32+
output_dir = LOCAL_LOG_DIR / "ladder" / config["game"]["name"] / vs
33+
try:
34+
tournament = PvpTournament(pvp_config, output_dir=output_dir)
35+
except FileExistsError:
36+
continue
37+
tournament.run()
38+
39+
40+
def main_cli(argv: list[str] | None = None):
41+
parser = argparse.ArgumentParser(description="CodeClash Ladder Runner")
42+
parser.add_argument(
43+
"config_path",
44+
type=Path,
45+
help="Path to the ladder configuration YAML file.",
46+
)
47+
args = parser.parse_args(argv)
48+
main(**vars(args))
49+
50+
51+
if __name__ == "__main__":
52+
main_cli()

0 commit comments

Comments
 (0)