From 9a5158d09a0d29eded2efe887a21b5d3937da089 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 21 Apr 2026 14:43:26 +0800 Subject: [PATCH] fix: Simplify init.py according to correct module development rules - Update init.py to only expose variables/functions for web scripts (no routing) - Remove api.py (routing is automatic for wwwroot files) - Add MODULE_DEVELOPMENT_SPEC_UPDATE.md with clarified rules - Follow proper module development specification --- MODULE_DEVELOPMENT_SPEC_UPDATE.md | 47 ++++++++++++++++++++++ UNKNOWN.egg-info/PKG-INFO | 10 +++++ UNKNOWN.egg-info/SOURCES.txt | 5 +++ UNKNOWN.egg-info/dependency_links.txt | 1 + UNKNOWN.egg-info/top_level.txt | 1 + hermes-web-cli/__init__.py | 0 hermes-web-cli/init.py | 6 --- hermes_web_cli/api.py | 58 --------------------------- hermes_web_cli/init.py | 38 ++++++++++++------ 9 files changed, 90 insertions(+), 76 deletions(-) create mode 100644 MODULE_DEVELOPMENT_SPEC_UPDATE.md create mode 100644 UNKNOWN.egg-info/PKG-INFO create mode 100644 UNKNOWN.egg-info/SOURCES.txt create mode 100644 UNKNOWN.egg-info/dependency_links.txt create mode 100644 UNKNOWN.egg-info/top_level.txt delete mode 100644 hermes-web-cli/__init__.py delete mode 100644 hermes-web-cli/init.py delete mode 100644 hermes_web_cli/api.py diff --git a/MODULE_DEVELOPMENT_SPEC_UPDATE.md b/MODULE_DEVELOPMENT_SPEC_UPDATE.md new file mode 100644 index 0000000..864538b --- /dev/null +++ b/MODULE_DEVELOPMENT_SPEC_UPDATE.md @@ -0,0 +1,47 @@ +# Module Development Specification (Updated) + +## Directory Structure +``` +module-name/ +├── module_name/ # Python package (underscore format) +│ ├── __init__.py # Required for Python package +│ └── init.py # Exposes variables/functions for web scripts +├── wwwroot/ # Web resources (auto-routed) +│ ├── *.ui # Bricks framework UI files +│ └── *.dspy # DSPy workflow files +├── models/ # Database table definitions (JSON) +├── json/ # CRUD operation definitions (JSON) +├── init/ # Initial data (JSON) +├── pyproject.toml # Package configuration for pip install +└── build.sh # Build script (optional) +``` + +## Key Rules + +### 1. Automatic Routing +- Files in `wwwroot/` are automatically accessible via `/{module_name}/filename.ext` +- No need to register routes manually with ServerEnv +- Supported extensions: `.ui`, `.dspy` + +### 2. init.py Purpose +- **Primary role**: Expose variables and functions for use by other modules and web scripts +- **Not for**: Route registration, ServerEnv configuration, complex initialization +- **Should contain**: + - Module constants and configuration + - Helper functions callable from .ui/.dspy scripts + - Variables needed by other Python modules + +### 3. Python Package Naming +- Directory: `module-name/` (hyphen format for repository) +- Python package: `module_name/` (underscore format for import) +- PyPI package name: `module-name` (hyphen format) + +### 4. Installation +- Must include `pyproject.toml` or `setup.py` +- Must be installable via `pip install .` +- Should declare dependencies properly + +### 5. Web Script Integration +- .ui and .dspy files can import/use functions from init.py +- Use standard Python import syntax in web scripts +- Keep init.py lightweight and focused on exposure \ No newline at end of file diff --git a/UNKNOWN.egg-info/PKG-INFO b/UNKNOWN.egg-info/PKG-INFO new file mode 100644 index 0000000..405ec6f --- /dev/null +++ b/UNKNOWN.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 2.1 +Name: UNKNOWN +Version: 0.0.0 +Summary: UNKNOWN +Home-page: UNKNOWN +License: UNKNOWN +Platform: UNKNOWN + +UNKNOWN + diff --git a/UNKNOWN.egg-info/SOURCES.txt b/UNKNOWN.egg-info/SOURCES.txt new file mode 100644 index 0000000..3575518 --- /dev/null +++ b/UNKNOWN.egg-info/SOURCES.txt @@ -0,0 +1,5 @@ +pyproject.toml +UNKNOWN.egg-info/PKG-INFO +UNKNOWN.egg-info/SOURCES.txt +UNKNOWN.egg-info/dependency_links.txt +UNKNOWN.egg-info/top_level.txt \ No newline at end of file diff --git a/UNKNOWN.egg-info/dependency_links.txt b/UNKNOWN.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/UNKNOWN.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/UNKNOWN.egg-info/top_level.txt b/UNKNOWN.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/UNKNOWN.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/hermes-web-cli/__init__.py b/hermes-web-cli/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/hermes-web-cli/init.py b/hermes-web-cli/init.py deleted file mode 100644 index 4745adb..0000000 --- a/hermes-web-cli/init.py +++ /dev/null @@ -1,6 +0,0 @@ -from ahserver.serverenv import ServerEnv -from appPublic.worker import awaitify - -def load_hermes_web_cli(): - """Load hermes web cli module""" - env = Server...[truncated] \ No newline at end of file diff --git a/hermes_web_cli/api.py b/hermes_web_cli/api.py deleted file mode 100644 index 5355875..0000000 --- a/hermes_web_cli/api.py +++ /dev/null @@ -1,58 +0,0 @@ -from ahserver.serverenv import ServerEnv - -def register_routes(env: ServerEnv): - """Register API routes for hermes-web-cli module""" - - @env.route('/api/hermes-web-cli/services', methods=['GET', 'POST']) - async def handle_services(request): - # Handle service registration and listing - if request.method == 'GET': - return await get_services(request) - elif request.method == 'POST': - return await create_service(request) - - @env.route('/api/hermes-web-cli/services/', methods=['GET', 'PUT', 'DELETE']) - async def handle_service_detail(request, service_id): - # Handle individual service operations - if request.method == 'GET': - return await get_service(request, service_id) - elif request.method == 'PUT': - return await update_service(request, service_id) - elif request.method == 'DELETE': - return await delete_service(request, service_id) - - @env.route('/api/hermes-web-cli/sessions', methods=['POST']) - async def create_session(request): - # Create new session on remote service - return await create_remote_session(request) - - @env.route('/api/hermes-web-cli/sessions//messages', methods=['POST']) - async def send_message(request, session_id): - # Send message to remote session - return await send_remote_message(request, session_id) - - @env.route('/api/hermes-web-cli/health', methods=['GET']) - async def health_check(request): - return {'status': 'healthy', 'module': 'hermes-web-cli'} - -# Placeholder functions - these would be implemented with actual database and HTTP client logic -async def get_services(request): - return [] - -async def create_service(request): - return {} - -async def get_service(request, service_id): - return {} - -async def update_service(request, service_id): - return {} - -async def delete_service(request, service_id): - return {} - -async def create_remote_session(request): - return {} - -async def send_remote_message(request, session_id): - return {} \ No newline at end of file diff --git a/hermes_web_cli/init.py b/hermes_web_cli/init.py index 249b0c4..19553ba 100644 --- a/hermes_web_cli/init.py +++ b/hermes_web_cli/init.py @@ -1,13 +1,27 @@ -from ahserver.serverenv import ServerEnv +# hermes-web-cli module initialization +# This file exposes variables and functions for use by other modules and web scripts (.ui, .dspy) -def load_hermes_web_cli(): - """Load hermes web cli module""" - env = ServerEnv() - # Register static file serving for hermes-web-cli - env.register_static_path('/hermes-web-cli', 'wwwroot/hermes-web-cli') - - # Register API endpoints - from hermes_web_cli.api import register_routes - register_routes(env) - - return True \ No newline at end of file +# Module metadata +MODULE_NAME = "hermes-web-cli" +MODULE_VERSION = "0.1.0" + +# Configuration constants +DEFAULT_SERVICE_URL = "http://localhost:9120" +SUPPORTED_SERVICE_STATUS = ["active", "inactive", "disconnected"] + +# Helper functions that can be used by .ui or .dspy scripts +def get_service_config(service_id): + """Get service configuration by ID - can be called from .ui scripts""" + # This would typically query the database + pass + +def validate_service_url(url): + """Validate service URL format - can be called from .ui scripts""" + return url.startswith(('http://', 'https://')) + +def create_session_id(): + """Generate a new session ID - can be called from .ui scripts""" + import uuid + return str(uuid.uuid4()) + +# Any other variables or functions needed by web scripts \ No newline at end of file