Skip to content

Commit 0a9750a

Browse files
authored
fix: remove secrets prefix + .env at root (#595)
1 parent 5806b6f commit 0a9750a

File tree

10 files changed

+50
-28
lines changed

10 files changed

+50
-28
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
timeout-minutes: 5
142142
env:
143143
GITHUB_WORKSPACE: $GITHUB_WORKSPACE
144-
SECRETS_GITHUB_TOKEN: ${{ secrets.GHA_PAT }}
144+
GITHUB_TOKEN: ${{ secrets.GHA_PAT }}
145145
run: |
146146
uv run pytest \
147147
-n auto \

src/codegen/cli/auth/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, repo_path: Path, git_token: str | None = None) -> None:
3030
self.repo_path = repo_path
3131
self.local_git = LocalGitRepo(repo_path=repo_path)
3232
self.codegen_dir = repo_path / CODEGEN_DIR_NAME
33-
self.config = UserConfig(env_filepath=self.codegen_dir / ENV_FILENAME)
33+
self.config = UserConfig(env_filepath=repo_path / ENV_FILENAME)
3434
self.config.secrets.github_token = git_token or self.config.secrets.github_token
3535
self.existing = session_manager.get_session(repo_path) is not None
3636

src/codegen/cli/commands/config/main.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import logging
2-
from itertools import groupby
32

43
import rich
54
import rich_click as click
65
from rich.table import Table
76

8-
from codegen.shared.configs.constants import CODEGEN_DIR_NAME, ENV_FILENAME, GLOBAL_ENV_FILE
7+
from codegen.shared.configs.constants import ENV_FILENAME, GLOBAL_ENV_FILE
98
from codegen.shared.configs.session_manager import session_manager
109
from codegen.shared.configs.user_config import UserConfig
1110

@@ -43,14 +42,39 @@ def flatten_dict(data: dict, prefix: str = "") -> dict:
4342
table.add_column("Key", style="cyan", no_wrap=True)
4443
table.add_column("Value", style="magenta")
4544

46-
# Group by prefix (before underscore)
47-
def get_prefix(item):
48-
return item[0].split("_")[0]
45+
# Group items by prefix
46+
codebase_items = []
47+
repository_items = []
48+
other_items = []
49+
50+
for key, value in sorted_items:
51+
prefix = key.split("_")[0].lower()
52+
if prefix == "codebase":
53+
codebase_items.append((key, value))
54+
elif prefix == "repository":
55+
repository_items.append((key, value))
56+
else:
57+
other_items.append((key, value))
58+
59+
# Add codebase section
60+
if codebase_items:
61+
table.add_section()
62+
table.add_row("[bold yellow]Codebase[/bold yellow]", "")
63+
for key, value in codebase_items:
64+
table.add_row(f" {key}", str(value))
65+
66+
# Add repository section
67+
if repository_items:
68+
table.add_section()
69+
table.add_row("[bold yellow]Repository[/bold yellow]", "")
70+
for key, value in repository_items:
71+
table.add_row(f" {key}", str(value))
4972

50-
for prefix, group in groupby(sorted_items, key=get_prefix):
73+
# Add other section
74+
if other_items:
5175
table.add_section()
52-
table.add_row(f"[bold yellow]{prefix.title()}[/bold yellow]", "")
53-
for key, value in group:
76+
table.add_row("[bold yellow]Other[/bold yellow]", "")
77+
for key, value in other_items:
5478
table.add_row(f" {key}", str(value))
5579

5680
rich.print(table)
@@ -91,13 +115,13 @@ def set_command(key: str, value: str, is_global: bool):
91115
rich.print(f"[red]{e}[/red]")
92116
return
93117

94-
rich.print(f"[green]Successfully set {key}=[magenta]{value}[/magenta] and saved to .env[/green]")
118+
rich.print(f"[green]Successfully set {key}=[magenta]{value}[/magenta] and saved to {ENV_FILENAME}[/green]")
95119

96120

97121
def _get_user_config(is_global: bool) -> UserConfig:
98122
if is_global or (active_session_path := session_manager.get_active_session()) is None:
99123
env_filepath = GLOBAL_ENV_FILE
100124
else:
101-
env_filepath = active_session_path / CODEGEN_DIR_NAME / ENV_FILENAME
125+
env_filepath = active_session_path / ENV_FILENAME
102126

103127
return UserConfig(env_filepath)

src/codegen/cli/commands/init/render.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
def get_success_message(codegen_dir: Path, docs_dir: Path, examples_dir: Path) -> str:
55
"""Get the success message to display after initialization."""
66
return """📁 .codegen configuration folder created:
7-
[dim].env[/dim] Project configuration
87
[dim]codemods/[/dim] Your codemod implementations
98
[dim].venv/[/dim] Python virtual environment (gitignored)
109
[dim]codegen-system-prompt.txt[/dim] AI system prompt (gitignored)"""

src/codegen/cli/mcp/resources/system_prompt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ def baz():
524524
```bash
525525
.codegen/
526526
├── .venv/ # Python virtual environment (gitignored)
527-
├── .env # Project configuration
528527
├── codemods/ # Your codemod implementations
529528
├── jupyter/ # Jupyter notebooks for exploration
530529
└── codegen-system-prompt.txt # AI system prompt

src/codegen/cli/workspace/initialize_workspace.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def modify_gitignore(codegen_folder: Path):
105105
"prompts/",
106106
"jupyter/",
107107
".venv/", # Add venv to gitignore
108-
".env",
109108
"codegen-system-prompt.txt",
110109
"",
111110
"# Python cache files",

src/codegen/shared/configs/models/base_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pydantic_settings import BaseSettings, SettingsConfigDict
66

77
from codegen.shared.configs.constants import ENV_FILENAME, GLOBAL_ENV_FILE
8-
from codegen.shared.configs.session_manager import session_codegen_dir
8+
from codegen.shared.configs.session_manager import session_root
99

1010

1111
class BaseConfig(BaseSettings, ABC):
@@ -18,9 +18,9 @@ class BaseConfig(BaseSettings, ABC):
1818

1919
def __init__(self, prefix: str, env_filepath: Path | None = None, *args, **kwargs) -> None:
2020
if env_filepath is None:
21-
codegen_dir = session_codegen_dir
22-
if codegen_dir is not None:
23-
env_filepath = codegen_dir / ENV_FILENAME
21+
root_path = session_root
22+
if root_path is not None:
23+
env_filepath = root_path / ENV_FILENAME
2424

2525
# Only include env files that exist
2626
env_filepaths = []
@@ -29,7 +29,7 @@ def __init__(self, prefix: str, env_filepath: Path | None = None, *args, **kwarg
2929
if env_filepath and env_filepath.exists() and env_filepath != GLOBAL_ENV_FILE:
3030
env_filepaths.append(env_filepath)
3131

32-
self.model_config["env_prefix"] = f"{prefix.upper()}_"
32+
self.model_config["env_prefix"] = f"{prefix.upper()}_" if len(prefix) > 0 else ""
3333
self.model_config["env_file"] = env_filepaths
3434

3535
super().__init__(*args, **kwargs)

src/codegen/shared/configs/models/secrets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ class SecretsConfig(BaseConfig):
88
Falls back to .env file for missing values.
99
"""
1010

11-
def __init__(self, prefix: str = "SECRETS", *args, **kwargs) -> None:
11+
def __init__(self, prefix: str = "", *args, **kwargs) -> None:
1212
super().__init__(prefix=prefix, *args, **kwargs)
1313

1414
github_token: str | None = None
1515
openai_api_key: str | None = None
16+
linear_api_key: str | None = None
1617

1718

1819
DefaultSecrets = SecretsConfig()

src/codegen/shared/configs/session_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def __str__(self) -> str:
6161
return f"GlobalConfig:\n Active Session: {active}\n Sessions:\n {sessions_str}\n Global Session:\n {self.session_config}"
6262

6363

64-
def _get_codegen_dir() -> Path | None:
64+
def _get_project_root() -> Path | None:
6565
"""Get the active codegen directory."""
6666
active_session = session_manager.get_active_session()
6767
if active_session:
68-
return active_session / CODEGEN_DIR_NAME
68+
return active_session
6969

7070
try:
7171
path = Path.cwd().resolve()
@@ -78,9 +78,9 @@ def _get_codegen_dir() -> Path | None:
7878
git_path = path / ".git"
7979

8080
if codegen_path.exists():
81-
return codegen_path
81+
return path
8282
if git_path.exists():
83-
return codegen_path
83+
return path
8484

8585
parent = path.parent.resolve()
8686
if parent == path: # We've reached the root directory
@@ -91,4 +91,4 @@ def _get_codegen_dir() -> Path | None:
9191

9292

9393
session_manager = SessionManager()
94-
session_codegen_dir = _get_codegen_dir()
94+
session_root = _get_project_root()

src/codegen/shared/configs/user_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def set(self, full_key: str, value: str) -> None:
5959
match f"{prefix}_":
6060
case self.repository.env_prefix:
6161
self.repository.set(self.env_filepath, key, value)
62-
case self.secrets.env_prefix:
63-
self.secrets.set(self.env_filepath, key, value)
6462
case self.codebase.env_prefix:
6563
self.codebase.set(self.env_filepath, key, value)
64+
case _:
65+
self.secrets.set(self.env_filepath, full_key, value)
6666

6767
def __str__(self) -> str:
6868
"""Return a pretty-printed string representation of the config."""

0 commit comments

Comments
 (0)