Skip to content

Commit 0853e80

Browse files
author
jzhu
committed
fix: enable/disable only change state, sync writes to files
- enable: only sets enabled=True and app_type, does NOT sync to file - disable: only sets enabled=False, does NOT clear file - sync: writes prompt content to app file - unsync: clears app file content Updated help text to clarify behavior and suggest using sync command.
1 parent 2d908b1 commit 0853e80

2 files changed

Lines changed: 27 additions & 55 deletions

File tree

code_assistant_manager/cli/prompts_commands.py

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -206,62 +206,51 @@ def enable_prompt(
206206
"-a",
207207
help="App type to enable for (claude, codex, gemini)",
208208
),
209-
level: str = typer.Option(
210-
"user",
211-
"--level",
212-
"-l",
213-
help="Enable level: 'user' or 'project'",
214-
),
215-
project_dir: Optional[Path] = typer.Option(
216-
None,
217-
"--project-dir",
218-
help="Project directory when using project level (defaults to current directory)",
219-
),
220209
):
221-
"""Enable a prompt and sync it to the app file.
210+
"""Enable a prompt for an app type.
222211
223-
This will:
224-
- Mark the prompt as enabled for the specified app
225-
- Disable other prompts for the same app (user level only)
226-
- Sync the prompt content to the app's prompt file
212+
This only marks the prompt as enabled and associates it with the app.
213+
It does NOT sync content to any files.
214+
Use 'sync' to write content to prompt files.
227215
"""
228216
if app_type not in USER_LEVEL_APPS:
229217
typer.echo(
230218
f"{Colors.RED}✗ Invalid app: {app_type}. Valid: {', '.join(USER_LEVEL_APPS)}{Colors.RESET}"
231219
)
232220
raise typer.Exit(1)
233221

234-
if level not in VALID_LEVELS:
235-
typer.echo(
236-
f"{Colors.RED}✗ Invalid level: {level}. Valid: {', '.join(VALID_LEVELS)}{Colors.RESET}"
237-
)
238-
raise typer.Exit(1)
239-
240222
manager = _get_prompt_manager()
241223
prompt = manager.get(prompt_id)
242224

243225
if not prompt:
244226
typer.echo(f"{Colors.RED}✗ Prompt '{prompt_id}' not found{Colors.RESET}")
245227
raise typer.Exit(1)
246228

247-
level_project_dir = (
248-
ensure_project_dir(level, project_dir if level == "project" else None)
249-
if level == "project"
250-
else None
251-
)
229+
if prompt.enabled and prompt.app_type == app_type:
230+
typer.echo(
231+
f"{Colors.YELLOW}Prompt '{prompt.name}' is already enabled for {app_type}{Colors.RESET}"
232+
)
233+
return
252234

253235
try:
254-
manager.activate(
255-
prompt_id,
256-
app_type,
257-
level=level,
258-
project_dir=level_project_dir,
236+
# Disable other prompts for this app type
237+
prompts = manager.get_all()
238+
for p in prompts.values():
239+
if p.id != prompt_id and p.enabled and p.app_type == app_type:
240+
p.enabled = False
241+
manager.update(p)
242+
243+
# Enable this prompt
244+
prompt.enabled = True
245+
prompt.app_type = app_type
246+
manager.update(prompt)
247+
248+
typer.echo(
249+
f"{Colors.GREEN}✓ Enabled '{prompt.name}' for {app_type}{Colors.RESET}"
259250
)
260251
typer.echo(
261-
f"{Colors.GREEN}✓ Enabled '{prompt.name}' for {app_type} ({level}){Colors.RESET}"
252+
f" {Colors.CYAN}Tip:{Colors.RESET} Use 'sync {prompt_id} --app {app_type}' to write to file"
262253
)
263-
file_path = get_prompt_file_path(app_type, level, level_project_dir)
264-
typer.echo(f" {Colors.CYAN}File:{Colors.RESET} {file_path}")
265254
except Exception as e:
266255
typer.echo(f"{Colors.RED}✗ Error: {e}{Colors.RESET}")
267256
raise typer.Exit(1)

tests/unit/test_prompts_cli.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,7 @@ def test_sync_prompt_with_enable(cli_manager, tmp_path, monkeypatch):
234234

235235

236236
def test_enable_prompt(cli_manager, tmp_path, monkeypatch):
237-
"""enable command activates a prompt and syncs it."""
238-
from code_assistant_manager.prompts import PROMPT_HANDLERS
239-
240-
# Setup user-level file path
241-
user_claude_file = tmp_path / "user_claude.md"
242-
243-
# Update manager's handler with the new path
244-
for name, cls in PROMPT_HANDLERS.items():
245-
overrides = {"user_path": user_claude_file} if name == "claude" else {}
246-
cli_manager._handlers[name] = cls(
247-
user_path_override=overrides.get("user_path"),
248-
)
249-
237+
"""enable command sets prompt state to enabled without syncing."""
250238
prompt = Prompt(id="test-enable", name="Test Enable", content="enable content")
251239
cli_manager.create(prompt)
252240

@@ -258,17 +246,14 @@ def test_enable_prompt(cli_manager, tmp_path, monkeypatch):
258246
prompts_commands.enable_prompt(
259247
prompt_id="test-enable",
260248
app_type="claude",
261-
level="user",
262-
project_dir=None,
263249
)
264250

265-
assert user_claude_file.exists()
266-
assert user_claude_file.read_text() == "enable content"
267-
268251
stored = cli_manager.get("test-enable")
269252
assert stored.enabled is True
270253
assert stored.app_type == "claude"
271254
assert any("enabled" in msg.lower() for msg in outputs)
255+
# Should suggest using sync
256+
assert any("sync" in msg.lower() for msg in outputs)
272257

273258

274259
def test_disable_prompt(cli_manager, tmp_path, monkeypatch):
@@ -331,8 +316,6 @@ def test_enable_prompt_invalid_app(cli_manager, tmp_path, monkeypatch):
331316
prompts_commands.enable_prompt(
332317
prompt_id="test-invalid-app",
333318
app_type="copilot", # copilot doesn't support enable
334-
level="user",
335-
project_dir=None,
336319
)
337320

338321
assert any("invalid" in msg.lower() for msg in outputs)

0 commit comments

Comments
 (0)