Skip to content

Commit fa6424d

Browse files
author
James Zhu
committed
fix prompt
1 parent cc791bd commit fa6424d

File tree

8 files changed

+264
-40
lines changed

8 files changed

+264
-40
lines changed

code_assistant_manager/cli/prompt_crud.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def _parse_app_list(app_str: str) -> List[str]:
3838

3939

4040
def list_prompts(
41-
app: str = typer.Option(
41+
app: Optional[str] = typer.Option(
4242
None,
4343
"--app",
4444
"-a",
4545
help="Filter by app type (claude, codex, gemini, copilot, codebuddy)",
4646
),
47-
level: str = typer.Option(
47+
level: Optional[str] = typer.Option(
4848
None,
4949
"--level",
5050
"-l",
@@ -88,14 +88,12 @@ def list_prompts(
8888
typer.echo(f"\nFound {len(prompts)} prompt(s):\n")
8989

9090
for prompt in prompts:
91-
status = "✓" if prompt.is_active else "✗"
91+
status = "✓" if prompt.is_default else "✗"
9292
default = " (default)" if prompt.is_default else ""
93-
typer.echo(f" {status} {prompt.prompt_id}{default}")
93+
typer.echo(f" {status} {prompt.id}{default}")
9494
if prompt.description:
9595
typer.echo(f" {Colors.DIM}{prompt.description}{Colors.RESET}")
96-
typer.echo(
97-
f" {Colors.DIM}App: {prompt.app}, Level: {prompt.level}{Colors.RESET}"
98-
)
96+
typer.echo(f" {Colors.DIM}Name: {prompt.name}{Colors.RESET}")
9997
typer.echo()
10098

10199
except Exception as e:
@@ -116,10 +114,8 @@ def view_prompt(prompt_id: str):
116114
typer.echo(f"Error: Prompt '{prompt_id}' not found.")
117115
raise typer.Exit(1)
118116

119-
typer.echo(f"\nPrompt: {prompt.prompt_id}")
120-
typer.echo(f"App: {prompt.app}")
121-
typer.echo(f"Level: {prompt.level}")
122-
typer.echo(f"Active: {'Yes' if prompt.is_active else 'No'}")
117+
typer.echo(f"\nPrompt: {prompt.id}")
118+
typer.echo(f"Name: {prompt.name}")
123119
typer.echo(f"Default: {'Yes' if prompt.is_default else 'No'}")
124120
if prompt.description:
125121
typer.echo(f"Description: {prompt.description}")
@@ -192,7 +188,7 @@ def add_prompt(
192188
project_dir=project_dir,
193189
)
194190

195-
typer.echo(f"Created prompt: {prompt.prompt_id}")
191+
typer.echo(f"Created prompt: {prompt.id}")
196192

197193
# Set as default if requested
198194
if set_default:
@@ -241,7 +237,7 @@ def update_prompt(
241237
name=name,
242238
)
243239

244-
typer.echo(f"Updated prompt: {updated_prompt.prompt_id}")
240+
typer.echo(f"Updated prompt: {updated_prompt.id}")
245241

246242
except Exception as e:
247243
logger.error(f"Error updating prompt '{prompt_id}': {e}")

code_assistant_manager/cli/prompt_defaults.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ def set_default_prompt(
5959
typer.echo(f"Error: Prompt '{prompt_id}' not found.")
6060
raise typer.Exit(1)
6161

62-
# Verify prompt matches app/level
63-
if prompt.app != app or prompt.level != level:
64-
typer.echo(
65-
f"Error: Prompt '{prompt_id}' is for {prompt.app}/{prompt.level}, not {app}/{level}."
66-
)
67-
raise typer.Exit(1)
68-
6962
# Set as default
7063
manager.set_default_prompt(app, level, prompt_id, project_dir)
7164
typer.echo(f"Set '{prompt_id}' as default for {app} ({level})")

code_assistant_manager/cli/prompt_install_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def install_prompts(
9898

9999

100100
def sync_prompts_alias(
101-
source_app: str = typer.Option(..., "--from", "-f", help="Source app"),
101+
source_app: str = typer.Option(..., "--from", "-s", help="Source app"),
102102
target_app: str = typer.Option(..., "--to", "-t", help="Target app"),
103103
level: str = typer.Option(
104104
"user", "--level", "-l", help="Level to sync at (user, project)"

code_assistant_manager/cli/prompt_status.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,22 @@ def _show_level_section(
9595
):
9696
"""Show prompts for a specific level."""
9797
prompts = manager.list_prompts(level=level, project_dir=project_dir)
98-
active_count = sum(1 for p in prompts if p.is_active)
98+
default_count = sum(1 for p in prompts if p.is_default)
9999
total_count = len(prompts)
100100

101-
typer.echo(f" {level.capitalize()}: {active_count}/{total_count} active")
101+
typer.echo(f" {level.capitalize()}: {default_count}/{total_count} default")
102102

103103
if prompts:
104104
default_id = manager.get_default_prompt(None, level, project_dir)
105105
if default_id:
106106
typer.echo(f" Default: {default_id}")
107107

108108
# Show recent prompts
109-
recent = sorted(prompts, key=lambda p: p.prompt_id, reverse=True)[:3]
109+
recent = sorted(prompts, key=lambda p: p.id, reverse=True)[:3]
110110
for prompt in recent:
111-
status = "✓" if prompt.is_active else "✗"
112-
default = " (default)" if prompt.prompt_id == default_id else ""
113-
typer.echo(f" {status} {prompt.prompt_id}{default}")
111+
status = "✓" if prompt.is_default else "✗"
112+
default = " (default)" if prompt.id == default_id else ""
113+
typer.echo(f" {status} {prompt.id}{default}")
114114

115115

116116
def _show_app_status(manager: PromptManager, app: str, project_dir: Optional[Path]):
@@ -133,11 +133,11 @@ def _show_copilot_status(manager: PromptManager, project_dir: Optional[Path]):
133133
prompts = manager.list_prompts(
134134
app="copilot", level="project", project_dir=project_dir
135135
)
136-
active_count = sum(1 for p in prompts if p.is_active)
136+
default_count = sum(1 for p in prompts if p.is_default)
137137
total_count = len(prompts)
138138

139139
typer.echo(
140-
f" Project ({project_dir.name}): {active_count}/{total_count} active"
140+
f" Project ({project_dir.name}): {default_count}/{total_count} default"
141141
)
142142
if prompts:
143143
default_id = manager.get_default_prompt("copilot", "project", project_dir)

code_assistant_manager/cli/prompt_uninstall.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
import typer
88

9-
from code_assistant_manager.cli.option_utils import (
10-
ensure_project_dir,
11-
resolve_level_targets,
12-
)
9+
from code_assistant_manager.cli.option_utils import ensure_project_dir
1310
from code_assistant_manager.prompts import PromptManager
1411

1512
logger = logging.getLogger(__name__)
@@ -26,6 +23,23 @@
2623
VALID_LEVELS = ["user", "project"]
2724

2825

26+
def _build_targets(
27+
app: Optional[str],
28+
level: Optional[str],
29+
project_dir: Optional[Path],
30+
) -> List[Dict]:
31+
"""Build target list for uninstallation."""
32+
targets = []
33+
apps = [app] if app else VALID_APP_TYPES
34+
levels = [level] if level else VALID_LEVELS
35+
36+
for a in apps:
37+
for l in levels:
38+
targets.append({"app": a, "level": l, "project_dir": project_dir})
39+
40+
return targets
41+
42+
2943
def uninstall_prompt(
3044
target: str = typer.Option(
3145
...,
@@ -77,11 +91,11 @@ def uninstall_prompt(
7791

7892
# Determine what to uninstall
7993
if target == "all":
80-
targets = resolve_level_targets(None, None, project_dir)
94+
targets = _build_targets(None, None, project_dir)
8195
elif target == "app":
82-
targets = resolve_level_targets(app, None, project_dir)
96+
targets = _build_targets(app, None, project_dir)
8397
elif target == "level":
84-
targets = resolve_level_targets(None, level, project_dir)
98+
targets = _build_targets(None, level, project_dir)
8599

86100
if not targets:
87101
typer.echo("No targets found to uninstall.")
@@ -94,8 +108,8 @@ def uninstall_prompt(
94108
typer.echo("No prompts found to uninstall.")
95109
return
96110

97-
# Show what will be removed and confirm
98-
if not _confirm_uninstall(all_targets):
111+
# Show what will be removed and confirm (skip if force)
112+
if not force and not _confirm_uninstall(all_targets):
99113
typer.echo("Uninstall cancelled.")
100114
return
101115

@@ -119,7 +133,7 @@ def _collect_uninstall_targets(targets: List[Dict]) -> List[Dict]:
119133
for prompt in prompts:
120134
all_targets.append(
121135
{
122-
"prompt_id": prompt.prompt_id,
136+
"prompt_id": prompt.id,
123137
"app": app,
124138
"level": level,
125139
"project_dir": project_dir,

code_assistant_manager/cli/prompts_commands.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,54 @@
55
import typer
66

77
# Import functions from refactored modules
8+
from code_assistant_manager.cli.prompt_crud import (
9+
add_prompt,
10+
list_prompts,
11+
remove_prompt,
12+
update_prompt,
13+
view_prompt,
14+
)
15+
from code_assistant_manager.cli.prompt_defaults import (
16+
clear_default_prompt,
17+
set_default_prompt,
18+
)
19+
from code_assistant_manager.cli.prompt_install_sync import (
20+
export_prompts,
21+
import_live_prompt,
22+
import_prompts,
23+
install_prompts,
24+
show_live_prompt,
25+
sync_prompts_alias,
26+
)
27+
from code_assistant_manager.cli.prompt_status import show_prompt_status
28+
from code_assistant_manager.cli.prompt_uninstall import (
29+
uninstall_prompt,
30+
unsync_prompt_alias,
31+
)
832

933
logger = logging.getLogger(__name__)
1034

1135
prompt_app = typer.Typer(
1236
help="Manage prompts for AI assistants (Claude, Codex, Gemini, Copilot, CodeBuddy)",
1337
no_args_is_help=True,
1438
)
39+
40+
# Register commands
41+
prompt_app.command("list")(list_prompts)
42+
prompt_app.command("ls", hidden=True)(list_prompts)
43+
prompt_app.command("view")(view_prompt)
44+
prompt_app.command("add")(add_prompt)
45+
prompt_app.command("update")(update_prompt)
46+
prompt_app.command("remove")(remove_prompt)
47+
prompt_app.command("rm", hidden=True)(remove_prompt)
48+
prompt_app.command("install")(install_prompts)
49+
prompt_app.command("uninstall")(uninstall_prompt)
50+
prompt_app.command("sync")(sync_prompts_alias)
51+
prompt_app.command("unsync")(unsync_prompt_alias)
52+
prompt_app.command("import")(import_prompts)
53+
prompt_app.command("export")(export_prompts)
54+
prompt_app.command("import-live")(import_live_prompt)
55+
prompt_app.command("show-live")(show_live_prompt)
56+
prompt_app.command("status")(show_prompt_status)
57+
prompt_app.command("set-default")(set_default_prompt)
58+
prompt_app.command("clear-default")(clear_default_prompt)

code_assistant_manager/menu/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Colors:
1717
YELLOW = "\033[1;33m"
1818
RED = "\033[0;31m"
1919
BOLD = "\033[1m"
20+
DIM = "\033[2m"
2021
RESET = "\033[0m"
2122
REVERSE = "\033[7m"
2223
REVERSE_OFF = "\033[27m"

0 commit comments

Comments
 (0)