Skip to content

Commit 422fa50

Browse files
authored
feat!: remove set-store config command (#130)
Blocked by #129.
1 parent 3cfb08b commit 422fa50

5 files changed

Lines changed: 4 additions & 216 deletions

File tree

context_use/cli/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
"Show current settings\n"
6060
" context-use config set-key "
6161
"Change OpenAI API key\n"
62-
" context-use config set-store <backend> "
63-
"Switch store (sqlite)\n"
6462
" context-use config path "
6563
"Print config file location\n"
6664
)

context_use/cli/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ class EphemeralApiCommand(ContextCommand, ABC):
351351
llm_mode: ClassVar[str] = "sync"
352352

353353
def _prepare(self, cfg: Config, args: argparse.Namespace) -> Config:
354-
cfg.store_provider = "sqlite"
355354
cfg.ensure_dirs()
356355
ensure_api_key(cfg)
357356
return cfg

context_use/cli/commands/config.py

Lines changed: 1 addition & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from __future__ import annotations
22

33
import argparse
4-
import subprocess
5-
import sys
64

75
from context_use.cli import output as out
86
from context_use.cli.base import BaseCommand, CommandGroup
97
from 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-
23494
class 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
]

context_use/config.py

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ class _FieldSpec(NamedTuple):
3838
_FieldSpec(
3939
"openai_embedding_model", "openai", "embedding_model", "OPENAI_EMBEDDING_MODEL"
4040
),
41-
_FieldSpec("store_provider", "store", "provider", "CONTEXT_USE_STORE"),
42-
_FieldSpec("db_host", "database", "host", "POSTGRES_HOST"),
43-
_FieldSpec("db_port", "database", "port", "POSTGRES_PORT", int),
44-
_FieldSpec("db_name", "database", "name", "POSTGRES_DB"),
45-
_FieldSpec("db_user", "database", "user", "POSTGRES_USER"),
46-
_FieldSpec("db_password", "database", "password", "POSTGRES_PASSWORD"),
4741
_FieldSpec("agent_backend", "agent", "backend", "CONTEXT_USE_AGENT_BACKEND"),
4842
_FieldSpec("data_dir", "data", "dir", None, Path),
4943
]
@@ -57,16 +51,6 @@ class Config:
5751
openai_model: str = _DEFAULT_MODEL
5852
openai_embedding_model: str = _DEFAULT_EMBEDDING_MODEL
5953

60-
# Store backend: "sqlite" (default), "memory", or "postgres"
61-
store_provider: str = "sqlite"
62-
63-
# Postgres settings (only used when store_provider == "postgres")
64-
db_host: str = "localhost"
65-
db_port: int = 5432
66-
db_name: str = "context_use"
67-
db_user: str = "postgres"
68-
db_password: str = "postgres"
69-
7054
# Agent backend: "" (not configured), "adk", …
7155
agent_backend: str = ""
7256

@@ -92,10 +76,6 @@ def storage_path(self) -> str:
9276
def db_path(self) -> str:
9377
return str(self.data_dir / "context_use.db")
9478

95-
@property
96-
def uses_postgres(self) -> bool:
97-
return self.store_provider == "postgres"
98-
9979
def ensure_dirs(self) -> None:
10080
"""Create the data directory structure if it doesn't exist."""
10181
self.input_dir.mkdir(parents=True, exist_ok=True)
@@ -152,25 +132,6 @@ def save_config(cfg: Config) -> Path:
152132
lines.append(f'embedding_model = "{cfg.openai_embedding_model}"')
153133
lines.append("")
154134

155-
lines += [
156-
"[store]",
157-
f'provider = "{cfg.store_provider}"',
158-
"",
159-
]
160-
161-
if cfg.uses_postgres:
162-
lines.extend(
163-
[
164-
"[database]",
165-
f'host = "{cfg.db_host}"',
166-
f"port = {cfg.db_port}",
167-
f'name = "{cfg.db_name}"',
168-
f'user = "{cfg.db_user}"',
169-
f'password = "{cfg.db_password}"',
170-
"",
171-
]
172-
)
173-
174135
if cfg.agent_backend:
175136
lines.extend(
176137
[
@@ -195,27 +156,10 @@ def save_config(cfg: Config) -> Path:
195156
def build_ctx(cfg: Config, *, llm_mode: str = "batch") -> ContextUse:
196157
"""Construct a :class:`ContextUse` from a :class:`Config`."""
197158

198-
storage = DiskStorage(cfg.storage_path)
159+
from context_use.store.sqlite import SqliteStore
199160

200-
if cfg.store_provider == "postgres":
201-
from context_use.store.postgres import PostgresStore
202-
203-
store = PostgresStore(
204-
host=cfg.db_host,
205-
port=cfg.db_port,
206-
database=cfg.db_name,
207-
user=cfg.db_user,
208-
password=cfg.db_password,
209-
)
210-
elif cfg.store_provider == "sqlite":
211-
from context_use.store.sqlite import SqliteStore
212-
213-
store = SqliteStore(path=cfg.db_path)
214-
else:
215-
raise ValueError(
216-
f"Unknown store provider {cfg.store_provider!r}. "
217-
"Supported: 'sqlite', 'postgres'."
218-
)
161+
storage = DiskStorage(cfg.storage_path)
162+
store = SqliteStore(path=cfg.db_path)
219163

220164
api_key = cfg.openai_api_key or ""
221165
model = OpenAIModel(cfg.openai_model)

context_use/ext/mcp_use/run.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from __future__ import annotations
1414

1515
import argparse
16-
import sys
1716

1817
from context_use.config import build_ctx, load_config
1918

@@ -33,11 +32,6 @@ def main() -> None:
3332
args = parser.parse_args()
3433

3534
cfg = load_config()
36-
if cfg.store_provider not in ("sqlite"):
37-
sys.exit(
38-
"error: MCP server requires a persistent store (sqlite).\n"
39-
" Run: context-use config set-store sqlite"
40-
)
4135

4236
from context_use.ext.mcp_use.server import create_server
4337

0 commit comments

Comments
 (0)