Skip to content

Commit f0d48bf

Browse files
committed
WIP
1 parent 1da01c1 commit f0d48bf

3 files changed

Lines changed: 62 additions & 69 deletions

File tree

CLAUDE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ Module/
151151
**utils** - Infrastructure module providing:
152152

153153
* Dependency injection container (`locate_implementations`, `locate_subclasses`)
154-
* Structured logging (`get_logger`)
154+
* Structured logging (via `loguru.logger`)
155155
* Settings management (Pydantic-based)
156156
* Health check framework (`BaseService`, `Health`)
157+
* MCP server with auto-discovery of plugin tools (`mcp_create_server`, `mcp_run`, `mcp_list_tools`)
158+
* GUI navigation infrastructure (`BaseNavBuilder`, `NavItem`, `NavGroup`)
159+
* Enhanced user agent generation with CI/CD context (`user_agent`)
157160

158161
### API Layer
159162

@@ -333,6 +336,10 @@ aignostics qupath launch --project my_project.qpproj
333336

334337
# System diagnostics
335338
aignostics system health
339+
340+
# MCP server (AI agent integration)
341+
aignostics mcp run
342+
aignostics mcp list-tools
336343
```
337344

338345
### GUI Launch

src/aignostics/CLAUDE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ This file provides a comprehensive overview of all modules in the Aignostics SDK
2525

2626
- **Core Features**:
2727
- OAuth 2.0 authentication, JWT token management, API client wrapper
28-
- **SDK Metadata System** (NEW): Automatic tracking of execution context, user info, CI/CD environment
29-
- JSON Schema validation for metadata with versioning (v0.0.1)
28+
- **SDK Metadata System**: Automatic tracking of execution context, user info, CI/CD environment
29+
- JSON Schema validation for metadata with versioning (Run v0.0.4, Item v0.0.3)
3030
- Operation caching for non-mutating API calls
3131
- **CLI**:
3232
- `user login`, `user logout`, `user whoami` for authentication
@@ -80,9 +80,11 @@ This file provides a comprehensive overview of all modules in the Aignostics SDK
8080

8181
- **Core Features**:
8282
- Dependency injection, logging, settings, health checks
83-
- **Enhanced User Agent** (NEW): Context-aware user agent with CI/CD tracking
83+
- Enhanced user agent with CI/CD context tracking
84+
- **MCP Server**: Central MCP server with auto-discovery of plugin tools (`mcp_create_server`, `mcp_run`, `mcp_list_tools`)
85+
- **Navigation**: GUI sidebar navigation infrastructure (`BaseNavBuilder`, `NavItem`, `NavGroup`)
8486
- **Service Discovery**: `locate_implementations()`, `locate_subclasses()`
85-
- **User Agent**: Generates `{name}/{version} ({platform}; {test}; {github_run_url})`
87+
- **User Agent**: Generates `{name}-python-sdk/{version} ({platform}; +{repo_url}; {test}; {github_run_url})`
8688
- **Used By**: All modules; platform module for SDK metadata
8789

8890
### 🖥️ gui
@@ -226,7 +228,7 @@ utils.locate_implementations(BaseService)
226228

227229
- **Authentication**: Token cached by `platform`, used by all API calls
228230
- **Settings**: Managed by `utils`, consumed by all modules
229-
- **Logging**: Centralized through `utils.get_logger()`
231+
- **Logging**: Centralized through `loguru.logger`
230232
- **Health Checks**: All services implement `BaseService.health()`
231233

232234
## CLI Usage Examples

src/aignostics/utils/CLAUDE.md

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ The utils module provides core infrastructure and shared utilities used across a
1717

1818
**Core Infrastructure:**
1919

20+
- `_service.py` - `BaseService` abstract base class for service discovery
2021
- `_di.py` - Dependency injection container with service discovery
2122
- `_settings.py` - Settings management with Pydantic validation
2223
- `_log.py` - Structured logging configuration
2324
- `_health.py` - Health check framework
24-
- `_user_agent.py` - **Enhanced user agent generation with CI/CD context** (NEW)
25+
- `_user_agent.py` - Enhanced user agent generation with CI/CD context
2526
- `boot.py` - Application bootstrap and initialization
2627

2728
**System Utilities:**
@@ -31,11 +32,15 @@ The utils module provides core infrastructure and shared utilities used across a
3132
- `_constants.py` - Project metadata and environment detection
3233
- `_console.py` - Rich console interface
3334

35+
**Navigation & GUI:**
36+
37+
- `_nav.py` - Navigation infrastructure (`NavItem`, `NavGroup`, `BaseNavBuilder`, `gui_get_nav_groups`)
38+
- `_gui.py` - GUI utilities and NiceGUI helpers (conditional on `nicegui`)
39+
- `_notebook.py` - Marimo notebook utilities (conditional on `marimo`)
40+
3441
**Integration Services:**
3542

36-
- `_sentry.py` - Sentry error monitoring
37-
- `_notebook.py` - Jupyter notebook utilities
38-
- `_gui.py` - GUI utilities and NiceGUI helpers
43+
- `_sentry.py` - Sentry error monitoring (conditional on `sentry`)
3944
- `_mcp.py` - MCP server utilities for AI agent integration
4045

4146
## Usage Patterns
@@ -68,13 +73,13 @@ from aignostics.utils import user_agent
6873

6974
# Generate enhanced user agent with CI/CD context
7075
ua = user_agent()
71-
# Format: {project_name}/{version} ({platform}; {pytest_test}; {github_run_url})
76+
# Format: {project_name}-python-sdk/{version} ({platform}; +{repository_url}; {pytest_test}; {github_run_url})
7277

7378
# Examples:
74-
# "aignostics/1.0.0-beta.7 (darwin)"
75-
# "aignostics/1.0.0-beta.7 (linux; tests/platform/test_auth.py::test_login)"
76-
# "aignostics/1.0.0-beta.7 (linux; +https://github.com/org/repo/actions/runs/123)"
77-
# "aignostics/1.0.0-beta.7 (linux; tests/.../test_e2e.py; +https://github.com/org/repo/actions/runs/456)"
79+
# "aignostics-python-sdk/1.0.0-beta.7 (macOS-15.0-arm64-arm-64bit; +https://github.com/aignostics/python-sdk)"
80+
# "aignostics-python-sdk/1.0.0-beta.7 (Linux-6.1-x86_64; +https://github.com/aignostics/python-sdk; tests/platform/test_auth.py::test_login)"
81+
# "aignostics-python-sdk/1.0.0-beta.7 (Linux-6.1-x86_64; +https://github.com/aignostics/python-sdk; +https://github.com/org/repo/actions/runs/123)"
82+
# "aignostics-python-sdk/1.0.0-beta.7 (Linux-6.1-x86_64; +https://github.com/aignostics/python-sdk; tests/.../test_e2e.py; +https://github.com/org/repo/actions/runs/456)"
7883

7984
# Used automatically by:
8085
# - SDK metadata system (platform._sdk_metadata)
@@ -122,73 +127,46 @@ class MyService(BaseService):
122127
from aignostics.utils import (
123128
MCP_SERVER_NAME,
124129
MCP_TRANSPORT,
125-
create_server,
126-
run,
127-
list_tools,
128-
discover_mcp_servers,
130+
mcp_create_server,
131+
mcp_run,
132+
mcp_list_tools,
133+
mcp_discover_servers,
129134
)
130135

131136
# Constants
132137
print(MCP_SERVER_NAME) # "Central Aignostics MCP Server"
133138
print(MCP_TRANSPORT) # "stdio"
134139

135140
# Create and configure MCP server
136-
server = create_server()
137-
server = create_server(server_name="Custom Server")
141+
server = mcp_create_server()
142+
server = mcp_create_server(server_name="Custom Server")
138143

139144
# Run MCP server (blocking)
140-
run()
145+
mcp_run()
141146

142147
# List available tools
143-
tools = list_tools()
148+
tools = mcp_list_tools()
144149
for tool in tools:
145150
print(f"{tool['name']}: {tool['description']}")
146151

147152
# Discover all MCP servers from SDK and plugins
148-
servers = discover_mcp_servers()
153+
servers = mcp_discover_servers()
149154
```
150155

151156
## Technical Implementation
152157

153158
**User Agent System (`_user_agent.py`):**
154159

155-
**NEW FEATURE**: Enhanced user agent generation with automatic CI/CD context detection.
160+
Enhanced user agent generation with automatic CI/CD context detection.
156161

157-
```python
158-
def user_agent() -> str:
159-
"""Generate user agent string for HTTP requests.
160-
161-
Format: {project_name}/{version} ({platform}; {current_test}; {github_run})
162-
163-
Detection:
164-
- Platform: sys.platform (darwin, linux, win32)
165-
- Pytest: PYTEST_CURRENT_TEST environment variable
166-
- GitHub Actions: GITHUB_RUN_ID, GITHUB_REPOSITORY environment variables
167-
168-
Returns:
169-
str: User agent string with contextual information
170-
"""
171-
current_test = os.getenv("PYTEST_CURRENT_TEST") # e.g., "tests/test_foo.py::test_bar"
172-
github_run_id = os.getenv("GITHUB_RUN_ID") # GitHub Actions workflow run ID
173-
github_repository = os.getenv("GITHUB_REPOSITORY") # e.g., "owner/repo"
174-
175-
optional_parts = []
176-
177-
# Add test context if running under pytest
178-
if current_test:
179-
optional_parts.append(current_test)
180-
181-
# Add GitHub Actions context if available
182-
if github_run_id and github_repository:
183-
github_run_url = f"+https://github.com/{github_repository}/actions/runs/{github_run_id}"
184-
optional_parts.append(github_run_url)
185-
186-
# Build user agent
187-
base = f"{PROJECT_NAME}/{VERSION} ({sys.platform})"
188-
if optional_parts:
189-
return f"{base}; {'; '.join(optional_parts)}"
190-
return base
191-
```
162+
**Format:** `{project_name}-python-sdk/{version_full} ({platform}; +{repository_url}; {optional_parts})`
163+
164+
**Detection:**
165+
166+
- **Platform**: `platform.platform()` (e.g., `macOS-15.0-arm64-arm-64bit`, `Linux-6.1-x86_64`)
167+
- **Repository URL**: From package metadata (`__repository_url__`)
168+
- **Pytest**: `PYTEST_CURRENT_TEST` environment variable
169+
- **GitHub Actions**: `GITHUB_RUN_ID` + `GITHUB_REPOSITORY` environment variables
192170

193171
**Usage in SDK:**
194172

@@ -202,7 +180,7 @@ def user_agent() -> str:
202180
- **Automatic Context Detection**: No manual configuration required
203181
- **CI/CD Integration**: Captures GitHub Actions workflow context with direct links to runs
204182
- **Test Traceability**: Links API requests to specific pytest tests
205-
- **Platform Identification**: Operating system detection for debugging platform-specific issues
183+
- **Platform Identification**: Detailed OS detection via `platform.platform()` for debugging
206184
- **Lightweight**: Minimal performance overhead, simple environment variable reads
207185

208186
**Service Discovery System:**
@@ -241,23 +219,29 @@ def user_agent() -> str:
241219

242220
- `__init__.py` - Public API exports and module coordination
243221
- `boot.py` - Application initialization and setup
222+
- `_service.py` - `BaseService` abstract base class
244223
- `_di.py` - Dependency injection implementation
245224
- `_settings.py` - Configuration management
246225
- `_log.py` - Logging infrastructure
226+
- `_health.py` - Health check framework
227+
- `_user_agent.py` - User agent string generation
247228

248229
**System Utilities:**
249230

250231
- `_fs.py` - File system operations
251232
- `_process.py` - Process utilities
252233
- `_constants.py` - Environment and metadata
253234
- `_console.py` - Console interface
254-
- `_health.py` - Health check framework
235+
236+
**Navigation & GUI:**
237+
238+
- `_nav.py` - Navigation infrastructure for GUI sidebar
239+
- `_gui.py` - GUI framework utilities (conditional on `nicegui`)
240+
- `_notebook.py` - Marimo notebook integration (conditional on `marimo`)
255241

256242
**Integration Modules:**
257243

258-
- `_sentry.py` - Error monitoring
259-
- `_notebook.py` - Jupyter integration
260-
- `_gui.py` - GUI framework utilities
244+
- `_sentry.py` - Error monitoring (conditional on `sentry`)
261245
- `_mcp.py` - MCP server utilities
262246

263247
## Development Notes
@@ -313,10 +297,10 @@ The MCP module provides utilities for creating and running Model Context Protoco
313297

314298
**Functions:**
315299

316-
- `discover_mcp_servers()` - Discover all FastMCP server instances from SDK and plugins
317-
- `create_server(server_name)` - Create and configure the MCP server with discovered plugins
318-
- `run(server_name)` - Run the MCP server using stdio transport
319-
- `list_tools(server_name)` - List all available MCP tools
300+
- `mcp_discover_servers()` - Discover all FastMCP server instances from SDK and plugins
301+
- `mcp_create_server(server_name)` - Create and configure the MCP server with discovered plugins
302+
- `mcp_run(server_name)` - Run the MCP server using stdio transport
303+
- `mcp_list_tools(server_name)` - List all available MCP tools
320304

321305
**CLI Commands:**
322306

0 commit comments

Comments
 (0)