11from __future__ import annotations
22
33import argparse
4- import subprocess
5- import sys
64
75from context_use .cli import output as out
86from context_use .cli .base import BaseCommand , CommandGroup
97from context_use .config import (
108 Config ,
11- build_ctx ,
129 config_path ,
1310 load_config ,
1411 load_config_with_sources ,
@@ -46,13 +43,7 @@ def badge(attr: str) -> str:
4643 f"{ cfg .openai_embedding_model } { badge ('openai_embedding_model' )} " ,
4744 )
4845
49- if cfg .store_provider == "postgres" :
50- store_val = f"postgres ({ cfg .db_host } :{ cfg .db_port } /{ cfg .db_name } )"
51- elif cfg .store_provider == "sqlite" :
52- store_val = f"sqlite ({ cfg .db_path } )"
53- else :
54- store_val = cfg .store_provider
55- out .kv ("Store" , f"{ store_val } { badge ('store_provider' )} " )
46+ out .kv ("Store" , f"sqlite ({ cfg .db_path } )" )
5647
5748 if cfg .agent_backend :
5849 out .kv ("Agent backend" , f"{ cfg .agent_backend } { badge ('agent_backend' )} " )
@@ -72,7 +63,6 @@ def badge(attr: str) -> str:
7263 print ()
7364 out .info ("To change settings:" )
7465 out .next_step ("context-use config set-key" , "change OpenAI API key" )
75- out .next_step ("context-use config set-store sqlite" , "use SQLite (default)" )
7666 out .next_step ("context-use config set-agent adk" , "configure agent backend" )
7767 print ()
7868
@@ -101,136 +91,6 @@ async def execute(self, args: argparse.Namespace) -> None:
10191 out .success (f"API key saved to { path } " )
10292
10393
104- def _start_docker_postgres (cfg : Config ) -> None :
105- """Start a pgvector/pgvector Postgres container via ``docker run``."""
106- probe = subprocess .run (["docker" , "info" ], capture_output = True , text = True )
107- if probe .returncode != 0 :
108- out .error ("Docker daemon is not running." )
109- out .info ("Start Docker Desktop (or the docker service) and try again:" )
110- out .next_step ("context-use config set-store postgres" )
111- sys .exit (1 )
112-
113- container_name = "context-use-postgres"
114-
115- result = subprocess .run (
116- ["docker" , "inspect" , "-f" , "{{.State.Running}}" , container_name ],
117- capture_output = True ,
118- text = True ,
119- )
120- if result .returncode == 0 and "true" in result .stdout :
121- out .success ("Postgres container already running" )
122- return
123-
124- subprocess .run (["docker" , "rm" , "-f" , container_name ], capture_output = True )
125-
126- out .info ("Starting Postgres container..." )
127- result = subprocess .run (
128- [
129- "docker" ,
130- "run" ,
131- "-d" ,
132- "--name" ,
133- container_name ,
134- "-p" ,
135- f"{ cfg .db_port } :5432" ,
136- "-e" ,
137- f"POSTGRES_USER={ cfg .db_user } " ,
138- "-e" ,
139- f"POSTGRES_PASSWORD={ cfg .db_password } " ,
140- "-e" ,
141- f"POSTGRES_DB={ cfg .db_name } " ,
142- "-v" ,
143- "context-use-pgdata:/var/lib/postgresql/data" ,
144- "pgvector/pgvector:pg17" ,
145- ],
146- capture_output = True ,
147- text = True ,
148- )
149- if result .returncode == 0 :
150- import time
151-
152- out .success (f"Postgres running on localhost:{ cfg .db_port } " )
153- out .info ("Waiting for Postgres to be ready..." )
154- time .sleep (3 )
155- else :
156- out .error (f"Failed to start Postgres: { result .stderr .strip ()} " )
157- sys .exit (1 )
158-
159-
160- class ConfigSetStoreCommand (BaseCommand ):
161- name = "set-store"
162- help = "Configure the store backend"
163-
164- def add_arguments (self , parser : argparse .ArgumentParser ) -> None :
165- parser .add_argument (
166- "backend" ,
167- choices = ["postgres" , "memory" ],
168- help = "Store backend to use" ,
169- )
170-
171- async def execute (self , args : argparse .Namespace ) -> None :
172- import shutil
173-
174- cfg = load_config () if config_path ().exists () else Config ()
175- backend = args .backend
176-
177- if backend == "memory" :
178- cfg .store_provider = "memory"
179- path = save_config (cfg )
180- out .success (f"Store set to in-memory. Config written to { path } " )
181- out .info ("Data will only persist for the duration of a single command." )
182- out .info (
183- "Use 'context-use quickstart' to ingest + generate in one session."
184- )
185- return
186-
187- # postgres
188- cfg .store_provider = "postgres"
189- out .info ("Setting up PostgreSQL for persistent storage across sessions." )
190- out .info ("For trying it out without PostgreSQL, run 'context-use quickstart'\n " )
191-
192- if shutil .which ("docker" ) is not None :
193- prompt_text = " Start a local Postgres container with Docker? [Y/n] "
194- start_db = input (prompt_text ).strip ().lower ()
195- if start_db in ("" , "y" , "yes" ):
196- _start_docker_postgres (cfg )
197-
198- host = input (f" Database host [{ cfg .db_host } ]: " ).strip () or cfg .db_host
199- port = input (f" Database port [{ cfg .db_port } ]: " ).strip () or str (cfg .db_port )
200- name = input (f" Database name [{ cfg .db_name } ]: " ).strip () or cfg .db_name
201- user = input (f" Database user [{ cfg .db_user } ]: " ).strip () or cfg .db_user
202- pw_prompt = f" Database password [{ cfg .db_password } ]: "
203- password = input (pw_prompt ).strip () or cfg .db_password
204- cfg .db_host = host
205- cfg .db_port = int (port )
206- cfg .db_name = name
207- cfg .db_user = user
208- cfg .db_password = password
209-
210- path = save_config (cfg )
211- out .success (f"PostgreSQL configured. Config written to { path } " )
212-
213- try :
214- ctx = build_ctx (cfg )
215- await ctx .init ()
216- out .success ("Database initialised" )
217- except Exception as exc :
218- out .warn (f"Could not initialise database: { exc } " )
219- out .info ("You can retry later with: context-use config set-store postgres" )
220-
221- print ()
222- out .header ("You're all set! Next steps:" )
223- print ()
224- out .info ("Run the full pipeline:" )
225- out .next_step ("context-use pipeline" )
226- out .info ("Or step by step:" )
227- out .next_step ("context-use ingest" )
228- out .next_step ("context-use memories generate" )
229- out .info ("Start the MCP server:" )
230- out .next_step ("python -m context_use.ext.mcp_use.run" )
231- print ()
232-
233-
23494class ConfigSetAgentCommand (BaseCommand ):
23595 name = "set-agent"
23696 help = "Configure the agent backend"
@@ -253,12 +113,6 @@ async def execute(self, args: argparse.Namespace) -> None:
253113 if backend == "adk" :
254114 out .info ("Requires the adk extra: uv sync --extra adk" )
255115
256- if cfg .store_provider not in ("sqlite" , "postgres" ):
257- out .warn ("The agent requires a persistent store (sqlite or postgres)." )
258- out .info ("Set it up first with:" )
259- out .next_step ("context-use config set-store sqlite" )
260- print ()
261-
262116 print ()
263117 out .header ("Next steps:" )
264118 out .next_step (
@@ -282,7 +136,6 @@ class ConfigGroup(CommandGroup):
282136 subcommands = [
283137 ConfigShowCommand ,
284138 ConfigSetKeyCommand ,
285- ConfigSetStoreCommand ,
286139 ConfigSetAgentCommand ,
287140 ConfigPathCommand ,
288141 ]
0 commit comments