Open
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Both test_build and test_index called duckdb.execute() on the shared default in-memory connection instead of the file-scoped connection, causing "table t1 already exists" when both tests ran in the same suite. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements “Phase 2” of the databao-cli refactor by reorganizing the codebase into a 4-layer architecture (commands/, workflows/, features/, shared/) and updating the CLI/UI/MCP entrypoints and tests to match.
Changes:
- Introduces the new
features/,shared/, andworkflows/layers and moves/rewires core logic accordingly. - Refactors Click commands to be thin routing wrappers and centralizes command registration via
COMMANDSin__main__.py. - Updates Streamlit UI and MCP server/tool modules to their new package locations and adjusts tests/imports.
Reviewed changes
Copilot reviewed 65 out of 91 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_query_executor_race_conditions.py | Updates imports/patch paths for moved Streamlit query executor. |
| tests/test_query_executor.py | Updates imports/patch paths for moved Streamlit query executor. |
| tests/test_index.py | Updates ProjectLayout import and fixes DuckDB usage to close connection. |
| tests/test_build.py | Updates ProjectLayout import and fixes DuckDB usage to close connection. |
| tests/test_app.py | Updates patch target to new Streamlit bootstrap location. |
| tests/test_add_datasource.py | Updates init implementation import to new feature layer. |
| tests/conftest.py | Updates init/layout imports to new feature/shared locations. |
| src/databao_cli/workflows/datasource/check.py | Adds CLI printing workflow for datasource connection checks. |
| src/databao_cli/workflows/datasource/add.py | Moves datasource “add wizard” interaction into workflows layer; delegates to feature functions. |
| src/databao_cli/workflows/datasource/init.py | Package marker for datasource workflows. |
| src/databao_cli/workflows/ask.py | Adds interactive/one-shot ask workflows and CLI result display. |
| src/databao_cli/workflows/init.py | Package marker for workflows. |
| src/databao_cli/ui/models/init.py | Removes legacy UI models package re-export (moved under features). |
| src/databao_cli/shared/project/layout.py | Introduces shared project layout + project discovery utilities. |
| src/databao_cli/shared/project/init.py | Package marker for shared project utilities. |
| src/databao_cli/shared/log/logging.py | Updates import path for moved ProjectLayout. |
| src/databao_cli/shared/log/llm_errors.py | Adds shared LLM error formatting helpers for CLI/UI. |
| src/databao_cli/shared/log/init.py | Package marker for shared logging. |
| src/databao_cli/shared/executor_utils.py | Centralizes executor/provider constants and LLM config builder. |
| src/databao_cli/shared/errors.py | Adds FeatureError exception type for feature-layer failures. |
| src/databao_cli/shared/context_engine_cli.py | Adds Click↔DCE user input adapter (ClickUserInputCallback). |
| src/databao_cli/shared/cli_utils.py | Adds get_project_or_raise and @handle_feature_errors decorator for Click commands. |
| src/databao_cli/shared/init.py | Package marker for shared utilities. |
| src/databao_cli/mcp/tools/databao_ask/init.py | Removes legacy MCP tool package re-export (moved under features). |
| src/databao_cli/features/ui/suggestions.py | Adds Streamlit suggested-questions generation + background execution. |
| src/databao_cli/features/ui/streaming.py | Adds streaming writer used by UI and CLI workflows. |
| src/databao_cli/features/ui/services/storage.py | Adds UI storage path management with basic validation and secure mkdir. |
| src/databao_cli/features/ui/services/settings_persistence.py | Updates imports to new UI models/storage locations. |
| src/databao_cli/features/ui/services/query_executor.py | Updates imports for moved results/models/streaming modules. |
| src/databao_cli/features/ui/services/llm_models.py | Updates shared executor utils import for model preference selection. |
| src/databao_cli/features/ui/services/dce_operations.py | Updates init/status/layout imports to new feature/shared locations. |
| src/databao_cli/features/ui/services/chat_title.py | Updates chat session import path. |
| src/databao_cli/features/ui/services/chat_persistence.py | Updates storage/chat session imports to new feature locations. |
| src/databao_cli/features/ui/services/build_service.py | Updates dce_operations import path. |
| src/databao_cli/features/ui/services/init.py | Updates service re-exports to new feature/ui service module paths. |
| src/databao_cli/features/ui/project_utils.py | Updates ProjectLayout import path to shared. |
| src/databao_cli/features/ui/pages/welcome.py | Updates imports to new feature/ui module structure. |
| src/databao_cli/features/ui/pages/general_settings.py | Updates imports to new feature/ui module structure. |
| src/databao_cli/features/ui/pages/context_settings.py | Updates imports to new feature/ui module structure. |
| src/databao_cli/features/ui/pages/chat.py | Updates imports to new feature/ui module structure. |
| src/databao_cli/features/ui/pages/agent_settings.py | Updates imports to shared executor utils and new feature/ui services. |
| src/databao_cli/features/ui/pages/init.py | Adds package docstring for UI pages. |
| src/databao_cli/features/ui/models/settings.py | Introduces new settings dataclasses and YAML (de)serialization. |
| src/databao_cli/features/ui/models/chat_session.py | Updates streaming writer type import path. |
| src/databao_cli/features/ui/models/init.py | Adds models package re-exports in new location. |
| src/databao_cli/features/ui/components/status.py | Adds Streamlit status component with fragment polling + context manager. |
| src/databao_cli/features/ui/components/sidebar.py | Updates imports to new feature/shared modules. |
| src/databao_cli/features/ui/components/results.py | Updates imports to new feature/ui services and models. |
| src/databao_cli/features/ui/components/icons.py | Adds DB icon/type detection utilities for UI. |
| src/databao_cli/features/ui/components/datasource_manager.py | Updates imports to new feature/ui module structure. |
| src/databao_cli/features/ui/components/datasource_form.py | Adds dynamic form rendering driven by DCE config definitions. |
| src/databao_cli/features/ui/components/chat.py | Updates imports to new feature/ui module structure. |
| src/databao_cli/features/ui/components/init.py | Adds package docstring for UI components. |
| src/databao_cli/features/ui/cli.py | Updates Streamlit app module resolution and adds app_impl wrapper raising FeatureError. |
| src/databao_cli/features/ui/assets/bao.png | Adds UI asset image. |
| src/databao_cli/features/ui/app.py | Updates imports throughout to new feature/shared module layout. |
| src/databao_cli/features/ui/init.py | Adds package docstring for UI feature. |
| src/databao_cli/features/status.py | Moves status business logic into features layer. |
| src/databao_cli/features/mcp/tools/databao_ask/tool.py | Updates imports to new feature/mcp module layout. |
| src/databao_cli/features/mcp/tools/databao_ask/agent_factory.py | Updates imports and shared LLM config builder usage. |
| src/databao_cli/features/mcp/tools/databao_ask/init.py | Adds MCP tool package re-export in new location. |
| src/databao_cli/features/mcp/tools/init.py | Package marker for feature MCP tools. |
| src/databao_cli/features/mcp/server.py | Updates tool import path and adds mcp_impl entrypoint. |
| src/databao_cli/features/mcp/init.py | Package marker for feature MCP module. |
| src/databao_cli/features/init/service.py | Moves init project creation logic into features layer. |
| src/databao_cli/features/init/errors.py | Adds typed init error hierarchy. |
| src/databao_cli/features/init/init.py | Package marker for init feature. |
| src/databao_cli/features/index.py | Moves index logic into features layer. |
| src/databao_cli/features/datasource/check.py | Moves datasource check logic into features layer. |
| src/databao_cli/features/datasource/add.py | Moves datasource config creation helpers into features layer. |
| src/databao_cli/features/datasource/init.py | Package marker for datasource feature. |
| src/databao_cli/features/build.py | Moves build logic into features layer. |
| src/databao_cli/features/ask/service.py | Adds ask feature service that validates inputs and initializes agent. |
| src/databao_cli/features/ask/display.py | Adds DataFrame→PrettyTable formatter for CLI display. |
| src/databao_cli/features/ask/agent_factory.py | Moves agent initialization logic into feature layer. |
| src/databao_cli/features/ask/init.py | Package marker for ask feature. |
| src/databao_cli/features/init.py | Package marker for features. |
| src/databao_cli/commands/status.py | Refactors command into Click-only routing; delegates to features.status. |
| src/databao_cli/commands/mcp.py | Implements Click command wrapper for MCP server execution. |
| src/databao_cli/commands/init.py | Refactors init command to route to init feature + datasource workflow. |
| src/databao_cli/commands/index.py | Refactors index command to route to features.index. |
| src/databao_cli/commands/datasource/check.py | Adds datasource check Click command routing to feature + workflow print. |
| src/databao_cli/commands/datasource/add.py | Adds datasource add Click command routing to workflow. |
| src/databao_cli/commands/datasource/init.py | Adds datasource Click group and registers subcommands. |
| src/databao_cli/commands/build.py | Refactors build command to route to features.build. |
| src/databao_cli/commands/ask.py | Refactors ask command to route to ask feature + ask workflows. |
| src/databao_cli/commands/app.py | Refactors app command to route to UI feature CLI bootstrap. |
| src/databao_cli/main.py | Centralizes command registration via COMMANDS list and adds commands to root group. |
| examples/demo-snowflake-project/src/databao_snowflake_demo/app.py | Updates example import to new Streamlit app module path. |
| docs/architecture.md | Updates architecture documentation to describe the new 4-layer structure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes DBA-292
Summary
Restructures the codebase into a clean four-layer architecture, removing business logic from
commands/, consolidating scattered domain code, and fully decouplingfeatures/from Click.Changes
1. Feature-Based Architecture
Restructures the codebase into the following layers:
Moves
mcp/,ui/,log/, andproject/intofeatures/andshared/.Files
src/databao_cli/features/(ask, init, datasource, mcp, ui, build, index, status)src/databao_cli/shared/(project, log, cli_utils, context_engine_cli, executor_utils, errors)2.
commands/as a Pure Routing LayerEach command file now contains only Click wiring and delegates execution via a single call. Business logic, error handling, and I/O are no longer in
commands/.Files
src/databao_cli/commands/ask.pysrc/databao_cli/commands/app.pysrc/databao_cli/commands/build.pysrc/databao_cli/commands/index.pysrc/databao_cli/commands/init.pysrc/databao_cli/commands/mcp.pysrc/databao_cli/commands/status.pysrc/databao_cli/commands/datasource/add.pysrc/databao_cli/commands/datasource/check.py3.
features/Decoupled from ClickAll
clickimports and usage removed fromfeatures/. Feature functions now return structured data instead of printing, and do not implement REPL loops, user prompts, or output formatting. They are directly callable from tests, MCP tools, and the Streamlit UI.Introduces
FeatureError+@handle_feature_errorsdecorator so feature functions raise a typed exception instead of callingsys.exit.Files
src/databao_cli/shared/errors.pysrc/databao_cli/shared/cli_utils.pysrc/databao_cli/features/ask/agent_factory.pysrc/databao_cli/features/ask/service.pysrc/databao_cli/features/ask/display.pysrc/databao_cli/features/datasource/add.pysrc/databao_cli/features/datasource/check.pysrc/databao_cli/features/ui/cli.pysrc/databao_cli/features/status.py4.
workflows/Layer for Interactive CLI SequencesMoves all interactive flows (REPL, wizards, output display) into
workflows/.workflows/owns CLI UX and orchestration;features/owns business logic and correctness.Files
src/databao_cli/workflows/ask.pysrc/databao_cli/workflows/datasource/add.pysrc/databao_cli/workflows/datasource/check.pyTest Plan
make checkpasses (ruff + mypy)make test— 66/66 passingdatabao --helpsmoke testdatabao datasource addinteractive wizard works end-to-enddatabao statusexits 0 both inside and outside a project directory