99from rich .table import Table
1010
1111from basic_memory .cli .app import app
12- from basic_memory .config import config
1312from basic_memory .mcp .project_session import session
1413from basic_memory .mcp .resources .project_info import project_info
1514import json
2423from basic_memory .schemas .project_info import ProjectStatusResponse
2524from basic_memory .mcp .tools .utils import call_delete
2625from basic_memory .mcp .tools .utils import call_put
26+ from basic_memory .utils import generate_permalink
2727
2828console = Console ()
2929
@@ -44,11 +44,8 @@ def format_path(path: str) -> str:
4444def list_projects () -> None :
4545 """List all configured projects."""
4646 # Use API to list projects
47-
48- project_url = config .project_url
49-
5047 try :
51- response = asyncio .run (call_get (client , f" { project_url } /project /projects" ))
48+ response = asyncio .run (call_get (client , "/projects /projects" ))
5249 result = ProjectList .model_validate (response .json ())
5350
5451 table = Table (title = "Basic Memory Projects" )
@@ -65,7 +62,6 @@ def list_projects() -> None:
6562 console .print (table )
6663 except Exception as e :
6764 console .print (f"[red]Error listing projects: { str (e )} [/red]" )
68- console .print ("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]" )
6965 raise typer .Exit (1 )
7066
7167
@@ -80,16 +76,14 @@ def add_project(
8076 resolved_path = os .path .abspath (os .path .expanduser (path ))
8177
8278 try :
83- project_url = config .project_url
8479 data = {"name" : name , "path" : resolved_path , "set_default" : set_default }
8580
86- response = asyncio .run (call_post (client , f" { project_url } /project /projects" , json = data ))
81+ response = asyncio .run (call_post (client , "/projects /projects" , json = data ))
8782 result = ProjectStatusResponse .model_validate (response .json ())
8883
8984 console .print (f"[green]{ result .message } [/green]" )
9085 except Exception as e :
9186 console .print (f"[red]Error adding project: { str (e )} [/red]" )
92- console .print ("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]" )
9387 raise typer .Exit (1 )
9488
9589 # Display usage hint
@@ -105,15 +99,13 @@ def remove_project(
10599) -> None :
106100 """Remove a project from configuration."""
107101 try :
108- project_url = config .project_url
109-
110- response = asyncio .run (call_delete (client , f"{ project_url } /project/projects/{ name } " ))
102+ project_name = generate_permalink (name )
103+ response = asyncio .run (call_delete (client , f"/projects/{ project_name } " ))
111104 result = ProjectStatusResponse .model_validate (response .json ())
112105
113106 console .print (f"[green]{ result .message } [/green]" )
114107 except Exception as e :
115108 console .print (f"[red]Error removing project: { str (e )} [/red]" )
116- console .print ("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]" )
117109 raise typer .Exit (1 )
118110
119111 # Show this message regardless of method used
@@ -126,20 +118,16 @@ def set_default_project(
126118) -> None :
127119 """Set the default project and activate it for the current session."""
128120 try :
129- project_url = config . project_url
121+ project_name = generate_permalink ( name )
130122
131- response = asyncio .run (call_put (client , f"{ project_url } /project/ projects/{ name } /default" ))
123+ response = asyncio .run (call_put (client , f"projects/{ project_name } /default" ))
132124 result = ProjectStatusResponse .model_validate (response .json ())
133125
134126 console .print (f"[green]{ result .message } [/green]" )
135127 except Exception as e :
136128 console .print (f"[red]Error setting default project: { str (e )} [/red]" )
137- console .print ("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]" )
138129 raise typer .Exit (1 )
139130
140- # Always activate it for the current session
141- os .environ ["BASIC_MEMORY_PROJECT" ] = name
142-
143131 # Reload configuration to apply the change
144132 from importlib import reload
145133 from basic_memory import config as config_module
@@ -149,21 +137,18 @@ def set_default_project(
149137 console .print ("[green]Project activated for current session[/green]" )
150138
151139
152- @project_app .command ("sync" )
140+ @project_app .command ("sync-config " )
153141def synchronize_projects () -> None :
154- """Synchronize projects between configuration file and database."""
142+ """Synchronize project config between configuration file and database."""
155143 # Call the API to synchronize projects
156144
157- project_url = config .project_url
158-
159145 try :
160- response = asyncio .run (call_post (client , f" { project_url } /project /sync" ))
146+ response = asyncio .run (call_post (client , "/projects /sync" ))
161147 result = ProjectStatusResponse .model_validate (response .json ())
162148
163149 console .print (f"[green]{ result .message } [/green]" )
164150 except Exception as e : # pragma: no cover
165151 console .print (f"[red]Error synchronizing projects: { str (e )} [/red]" )
166- console .print ("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]" )
167152 raise typer .Exit (1 )
168153
169154
0 commit comments