Compare commits
62 Commits
v0.7.0
...
testdrive-
| Author | SHA1 | Date | |
|---|---|---|---|
| e84eb08dc5 | |||
| 0e568ce623 | |||
| aa0ac626c5 | |||
| 9bbc2832de | |||
| 46a060b695 | |||
| 24959308b2 | |||
| 6670e71b81 | |||
| ab3f0db86f | |||
| d0a1c91b8e | |||
| 3264517c91 | |||
| d98c3ae05a | |||
| 4e3f112987 | |||
| f788ccdfd3 | |||
| 512085d283 | |||
| 95ea13958a | |||
| ca431ac11f | |||
| 79c6c9d4e4 | |||
| 09e7f07c23 | |||
| 8d8a4ed0c3 | |||
| 5b13c00d3e | |||
| 4262310302 | |||
| 6ef2641bff | |||
| b9c1b90867 | |||
| 76b5bb1106 | |||
| 409d1a8d9f | |||
| 8f1cc0faf9 | |||
| 8ef356af57 | |||
| 55c61a7f2d | |||
| 26c235e296 | |||
| 4d08cbcf52 | |||
| e0bc5daeeb | |||
| de49c76ff9 | |||
| dbde13e036 | |||
| 3839a6761e | |||
| 2d9175ec05 | |||
| b963940144 | |||
| 2d516b205a | |||
| 7270bc559d | |||
| c699d7d669 | |||
| bcc3fe1df5 | |||
| d1e129c9b8 | |||
| afe6bcf6fe | |||
| 32d26e7648 | |||
| 747b77b854 | |||
| 9b6c3d4ad0 | |||
| 746a3f9df1 | |||
| 499de7a46e | |||
| b512842aaf | |||
| c4877543d5 | |||
| 47657fcba8 | |||
| 17c62aadaa | |||
| 23551129a3 | |||
| f3237f7ada | |||
| b475a23697 | |||
| 61e820baf8 | |||
| d0ffdc057c | |||
| d505c15d40 | |||
| f546f3c175 | |||
| d8d823b101 | |||
| ab67997324 | |||
| 3298b0d911 | |||
| 8249296a43 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -78,6 +78,8 @@ Thumbs.db
|
||||
|
||||
# MarkiTect database files (local development)
|
||||
markitect.db
|
||||
assets/assets.db
|
||||
**/assets.db
|
||||
.markitect/
|
||||
|
||||
# Issue workspace (temporary development files)
|
||||
@@ -96,3 +98,4 @@ ISSUES.index
|
||||
|
||||
# Test artifacts and temporary files
|
||||
tmp/
|
||||
markitect/_version.py
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -8,3 +8,6 @@
|
||||
[submodule "capabilities/kaizen-agentic"]
|
||||
path = capabilities/kaizen-agentic
|
||||
url = http://92.205.130.254:32166/coulomb/kaizen-agentic.git
|
||||
[submodule "capabilities/testdrive-jsui"]
|
||||
path = capabilities/testdrive-jsui
|
||||
url = http://92.205.130.254:32166/coulomb/testdrive-jsui.git
|
||||
|
||||
77
CHANGELOG.md
77
CHANGELOG.md
@@ -7,6 +7,72 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Enhanced control panel UI with better resize handle positioning for improved user interaction
|
||||
|
||||
### Changed
|
||||
- Refactored contents control architecture to use base class pattern properly for better code organization
|
||||
- Updated all file references and paths to point to single source of truth in capabilities/testdrive-jsui/js/controls/ directory
|
||||
|
||||
### Fixed
|
||||
- Duplicate file structure issue by eliminating duplicate control files and consolidating to capabilities/ directory
|
||||
- Contents panel scrollbar behavior - moved overflow-y: auto to correct container level so scrollbar only spans content area when panel reaches max-height
|
||||
|
||||
### Removed
|
||||
- **BREAKING**: Legacy DocumentControls component from TestDrive JSUI plugin system - all control panel functionality now provided by enhanced control panels (ContentsControl, StatusControl, DebugControl, EditControl) with Reset All button functionality moved to EditControl for better maintainability and elimination of code duplication
|
||||
|
||||
## [0.9.0] - 2025-11-14
|
||||
|
||||
### Added
|
||||
- **Plugin Infrastructure Foundation**: Extended existing MarkiTect plugin system with RenderingEnginePlugin base class and RENDERING plugin type
|
||||
- **RenderingEngineManager**: Complete plugin discovery and lifecycle management system for UI rendering engines
|
||||
- **RenderingConfig System**: Asset management and deployment configuration for plugin engines
|
||||
- **TestDrive JSUI Plugin**: Complete independent JavaScript UI plugin extracted from core system with standalone development environment
|
||||
- **Modular Component Architecture**: Compass-positioned controls with clean JSON configuration interface for Python-JavaScript data transfer
|
||||
- **CLI Engine Parameter**: Added --engine parameter to markitect md-render command with engine validation and mode compatibility checking
|
||||
- **Automatic Asset Deployment**: Production-ready asset deployment to _markitect/plugins/ structure with 18 total assets (12 JS, 3 CSS, 3 images)
|
||||
- **ChatGPT Document Theme**: New document theme with Inter font, 580px width, and #10a37f accent color with full CLI support (`markitect md-render --theme chatgpt`)
|
||||
- **Modular Theme System Architecture**: File-based theme loading with YAML configuration and dynamic theme discovery
|
||||
- **Theme Directory Structure**: Organized theme components (mode/, ui/, document/, branding/) for better maintainability
|
||||
- **Database Architecture Documentation**: Comprehensive WORKSPACE_AND_DATABASES.md documenting workspace concepts and database purposes
|
||||
|
||||
### Changed
|
||||
- **BREAKING**: Edit mode now defaults to testdrive-jsui plugin instead of legacy edit mode
|
||||
- **Default Rendering Behavior**: testdrive-jsui for edit/insert modes, standard for view mode with graceful fallback
|
||||
- **Asset Management Strategy**: Automatic plugin asset deployment eliminates need for manual --ship-assets flag
|
||||
- **JavaScript Architecture**: Clean separation between Python backend and JavaScript frontend with modular design
|
||||
- **Theme Loading System**: Implemented dynamic theme discovery and loading with metadata preservation
|
||||
- **Test Suite Organization**: Removed obsolete configuration CLI tests (490 lines) for cleaner codebase
|
||||
|
||||
### Fixed
|
||||
- **JavaScript Loading Conflicts**: Resolved const redeclaration errors with MARKITECT_STRICT_MODE implementation
|
||||
- **MarkitectMain Availability**: Fixed proper main-updated.js loading and JavaScript syntax errors
|
||||
- **Plugin Asset Deployment**: Directory structure preservation with development vs production deployment strategies
|
||||
- **Issue-facade Click Framework Bug**: Resolved Sentinel bug in list command that was causing CLI failures
|
||||
- **Issue-facade Version Command**: Fixed installation error preventing version command from working
|
||||
- **Test Isolation Issues**: Improved test isolation with proper mocking to prevent cross-test interference
|
||||
- **Theme Color Assertions**: Updated test assertions to work with new modular theme system
|
||||
|
||||
### Migration Guide
|
||||
- **Existing Users**: Edit mode will automatically use new testdrive-jsui plugin for enhanced experience
|
||||
- **Legacy Behavior**: Use `markitect md-render --engine standard --edit` to access previous edit mode
|
||||
- **Asset Deployment**: Plugin assets now deploy automatically - no manual --ship-assets flag required
|
||||
|
||||
## [0.8.0] - 2025-11-08
|
||||
|
||||
### Added
|
||||
- **Setuptools-SCM Integration**: Automatic version management system replacing manual version tracking
|
||||
- **Gitea Package Publishing**: Complete CI/CD pipeline for automated package publishing to Gitea
|
||||
- **Enhanced Release Documentation**: Comprehensive documentation for package building and release process
|
||||
|
||||
### Changed
|
||||
- **Release Script Architecture**: Modernized release workflow with setuptools-scm integration
|
||||
- **Makefile Release Targets**: Updated release targets to support automated version management
|
||||
- **Package Building Process**: Streamlined package creation with enhanced build targets
|
||||
|
||||
### Removed
|
||||
- **Legacy Release Scripts**: Removed obsolete release_simplified.py in favor of unified release.py
|
||||
|
||||
## [0.7.0] - 2025-11-08
|
||||
|
||||
### Added
|
||||
@@ -158,4 +224,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **Build System**: Enhanced build targets with venv Python and PYTHONPATH support
|
||||
- **Target Naming**: Renamed workspace targets to TDD Workspace with tdd- prefix
|
||||
|
||||
xxx
|
||||
[Unreleased]: https://github.com/worsch/markitect/compare/v0.9.0...HEAD
|
||||
[0.9.0]: https://github.com/worsch/markitect/compare/v0.8.0...v0.9.0
|
||||
[0.8.0]: https://github.com/worsch/markitect/compare/v0.7.0...v0.8.0
|
||||
[0.7.0]: https://github.com/worsch/markitect/compare/v0.6.0...v0.7.0
|
||||
[0.6.0]: https://github.com/worsch/markitect/compare/v0.5.0...v0.6.0
|
||||
[0.5.0]: https://github.com/worsch/markitect/compare/v0.4.0...v0.5.0
|
||||
[0.4.0]: https://github.com/worsch/markitect/compare/v0.3.0...v0.4.0
|
||||
[0.3.0]: https://github.com/worsch/markitect/compare/v0.2.0...v0.3.0
|
||||
[0.2.0]: https://github.com/worsch/markitect/compare/v0.1.0...v0.2.0
|
||||
[0.1.0]: https://github.com/worsch/markitect/releases/tag/v0.1.0
|
||||
|
||||
81
GUARDRAILS.md
Normal file
81
GUARDRAILS.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Development Guardrails
|
||||
|
||||
## JavaScript Code Principles
|
||||
|
||||
### 1. No Inline JavaScript in Python
|
||||
**NEVER write JavaScript code directly from Python code**
|
||||
|
||||
❌ **Wrong:**
|
||||
```python
|
||||
script = f"""
|
||||
function myFunction() {{
|
||||
console.log("Hello {name}");
|
||||
}}
|
||||
"""
|
||||
```
|
||||
|
||||
✅ **Correct:**
|
||||
```python
|
||||
# Load from external files only
|
||||
components = [
|
||||
'js/core/section-manager.js',
|
||||
'js/components/debug-panel.js',
|
||||
'js/components/document-controls.js'
|
||||
]
|
||||
```
|
||||
|
||||
### 2. Why This Rule Exists
|
||||
- **Quoting Problems**: String escaping in Python corrupts JavaScript
|
||||
- **Syntax Errors**: Template literals and complex JS break when embedded
|
||||
- **Maintainability**: JS code should be in .js files for proper tooling
|
||||
- **Architecture**: Follows the established modular component system
|
||||
|
||||
### 3. Proper Approach
|
||||
1. Create separate `.js` files in `markitect/static/js/components/`
|
||||
2. Load them via `_get_clean_editor_scripts()`
|
||||
3. Wire up components in the initialization script only
|
||||
|
||||
## Testing and Validation
|
||||
|
||||
### 1. Always Validate Generated HTML
|
||||
- Check that HTML files actually render content
|
||||
- Validate JavaScript syntax before deployment
|
||||
- Test both viewing and editing modes
|
||||
|
||||
### 2. Detect JavaScript Errors Programmatically
|
||||
- Run syntax validation on generated JS
|
||||
- Check for common error patterns
|
||||
- Fail fast when JS is malformed
|
||||
|
||||
### 3. Manual Testing Backup
|
||||
- If automated checks pass but functionality fails
|
||||
- Open generated HTML in browser
|
||||
- Check console for runtime errors
|
||||
- Report specific error messages
|
||||
|
||||
## Architecture Principles
|
||||
|
||||
### 1. Separation of Concerns
|
||||
- Python: File generation, template management
|
||||
- JavaScript: UI components, interaction logic
|
||||
- HTML: Structure and content only
|
||||
|
||||
### 2. Modular Component System
|
||||
- Each UI component in separate file
|
||||
- Lazy loading where appropriate
|
||||
- Clear dependency management
|
||||
|
||||
### 3. Error Handling
|
||||
- Graceful degradation when components fail
|
||||
- Clear error messages for debugging
|
||||
- Fallback modes when possible
|
||||
|
||||
## Breaking These Rules
|
||||
|
||||
If you find yourself writing JavaScript in Python strings:
|
||||
1. **STOP** - Step back and reconsider
|
||||
2. Create a proper component file instead
|
||||
3. Use the existing component loading system
|
||||
4. Add validation to catch the issue early
|
||||
|
||||
These guardrails exist because we've seen the problems when they're violated.
|
||||
117
Makefile
117
Makefile
@@ -1,7 +1,13 @@
|
||||
# MarkiTect - Advanced Markdown Engine
|
||||
# Makefile for common development tasks
|
||||
|
||||
.PHONY: help setup install install-dev uninstall install-home install-home-venv install-user-deps install-force-deps install-deps-venv install-system-deps list-deps setup-dev test build clean update status lint format check-deps venv-status update-digest add-diary-entry test-status test-new test-coverage test-arch test-foundation test-infrastructure test-integration test-domain test-service test-application test-presentation test-quick test-layers test-random test-random-seed test-random-repeat test-install-randomly test-clean test-tdd test-changed test-module test-cache-clean test-efficient cli-help release-status release-validate release-prepare release-build release-publish release-dry-run chaos-validate chaos-matrix chaos-inject chaos-report cost-help
|
||||
# Include capability discovery system
|
||||
include scripts/capability_discovery.mk
|
||||
|
||||
# Set explicit default target
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
.PHONY: help setup install install-dev uninstall install-home install-home-venv install-user-deps install-force-deps install-deps-venv install-system-deps list-deps setup-dev test test-js test-all build clean update status lint format check-deps venv-status update-digest add-diary-entry test-status test-new test-coverage test-arch test-foundation test-infrastructure test-integration test-domain test-service test-application test-presentation test-quick test-layers test-random test-random-seed test-random-repeat test-install-randomly test-clean test-tdd test-changed test-module test-cache-clean test-efficient cli-help chaos-validate chaos-matrix chaos-inject chaos-report cost-help
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@@ -26,22 +32,26 @@ help:
|
||||
@echo ""
|
||||
@echo "Development:"
|
||||
@echo " test - Run core tests (excluding capability-specific tests)"
|
||||
@echo " test-capabilities - Run all capability-specific tests"
|
||||
@echo " test-capability-* - Run specific capability tests (content, utils, finance, etc.)"
|
||||
@echo " test-js - Run JavaScript UI tests"
|
||||
@echo " test-all - Run all tests (Python + JavaScript + Capabilities)"
|
||||
@echo " test-capabilities - Run all capability tests (delegated to capabilities)"
|
||||
@echo " test-status - Show test status summary without re-running"
|
||||
@echo " test-new - Create new test file template"
|
||||
@echo " test-coverage - Analyze test coverage"
|
||||
@echo " build - Build the package"
|
||||
@echo " package - Build distribution packages (wheel + sdist)"
|
||||
@echo " lint - Run code linting"
|
||||
@echo " format - Format code"
|
||||
@echo ""
|
||||
@echo "Release Management:"
|
||||
@echo " release-status - Show current release status"
|
||||
@echo " release-validate - Validate repository for release"
|
||||
@echo " release-prepare VERSION=x.y.z - Prepare new release"
|
||||
@echo " release-build - Build release packages"
|
||||
@echo " release-publish VERSION=x.y.z - Publish complete release"
|
||||
@echo " release-dry-run VERSION=x.y.z - Test release preparation"
|
||||
@echo "Capabilities & Extensions:"
|
||||
@echo " capabilities-list List all available capabilities"
|
||||
@echo " capabilities-help Show help for all capabilities"
|
||||
@echo " capabilities-status Show capability status"
|
||||
@echo ""
|
||||
@echo "Release Management (via capability):"
|
||||
@echo " release-status Show current release status"
|
||||
@echo " release-publish-gitea VERSION=x.y.z Complete release + Gitea upload"
|
||||
@echo " Run 'make capabilities-help' for all release commands"
|
||||
@echo ""
|
||||
@echo "Chaos Engineering:"
|
||||
@echo " chaos-validate - Run architectural independence validation"
|
||||
@@ -380,32 +390,22 @@ test: $(VENV)/bin/activate
|
||||
fi
|
||||
|
||||
# Capability-Specific Test Targets
|
||||
test-capabilities: test-capability-content test-capability-utils test-capability-finance test-capability-query test-capability-graphql test-capability-plugins
|
||||
# Delegate to capability discovery system for testing capabilities
|
||||
test-capabilities: capabilities-test
|
||||
@echo "✅ All capability tests completed"
|
||||
|
||||
test-capability-content: $(VENV)/bin/activate
|
||||
@echo "🧪 Running markitect-content capability tests..."
|
||||
@cd capabilities/markitect-content && python -m pytest tests/ -v
|
||||
# Legacy test-capability-* targets are now handled by capability delegation
|
||||
# Use 'make capability-name-test' instead (e.g., 'make markitect-content-test')
|
||||
|
||||
test-capability-utils: $(VENV)/bin/activate
|
||||
@echo "🧪 Running markitect-utils capability tests..."
|
||||
@cd capabilities/markitect-utils && python -m pytest tests/ -v
|
||||
# JavaScript UI Testing Targets (Phase 5.1 - TestDrive-JSUI Integration)
|
||||
.PHONY: test-js
|
||||
test-js: ## Run JavaScript UI tests
|
||||
@echo "🧪 Running JavaScript UI tests..."
|
||||
@$(MAKE) --no-print-directory testdrive-jsui-test-all
|
||||
|
||||
test-capability-finance: $(VENV)/bin/activate
|
||||
@echo "🧪 Running finance capability tests..."
|
||||
@PYTHONPATH=. $(VENV_PYTHON) -m pytest markitect/finance/tests/ -v
|
||||
|
||||
test-capability-query: $(VENV)/bin/activate
|
||||
@echo "🧪 Running query paradigms capability tests..."
|
||||
@PYTHONPATH=. $(VENV_PYTHON) -m pytest markitect/query_paradigms/tests/ -v
|
||||
|
||||
test-capability-graphql: $(VENV)/bin/activate
|
||||
@echo "🧪 Running GraphQL capability tests..."
|
||||
@PYTHONPATH=. $(VENV_PYTHON) -m pytest markitect/graphql/tests/ -v
|
||||
|
||||
test-capability-plugins: $(VENV)/bin/activate
|
||||
@echo "🧪 Running plugins capability tests..."
|
||||
@PYTHONPATH=. $(VENV_PYTHON) -m pytest markitect/plugins/tests/ -v
|
||||
.PHONY: test-all
|
||||
test-all: test test-js test-capabilities ## Run all tests (Python + JavaScript + Capabilities)
|
||||
@echo "✅ All test suites completed successfully!"
|
||||
|
||||
# TDD8 Workflow Optimized Test Targets (Issue #57)
|
||||
|
||||
@@ -482,42 +482,25 @@ build: $(VENV)/bin/activate
|
||||
$(VENV_PYTHON) -m build 2>/dev/null || \
|
||||
$(VENV_PIP) install build && $(VENV_PYTHON) -m build
|
||||
|
||||
# Release management
|
||||
release-status:
|
||||
@echo "🔍 Checking release status..."
|
||||
$(VENV_PYTHON) release.py status
|
||||
# Build distribution packages with version info
|
||||
package: $(VENV)/bin/activate
|
||||
@echo "📦 Building distribution packages..."
|
||||
@echo ""
|
||||
@echo "📍 Current version (setuptools-scm):"
|
||||
@$(VENV_PYTHON) -m setuptools_scm 2>/dev/null || echo " setuptools-scm not available"
|
||||
@echo ""
|
||||
@echo "🧹 Cleaning previous builds..."
|
||||
@rm -rf build/ dist/ *.egg-info/ 2>/dev/null || true
|
||||
@echo "🏗️ Building wheel and source distribution..."
|
||||
@$(VENV_PIP) install build setuptools-scm >/dev/null 2>&1 || true
|
||||
$(VENV_PYTHON) -m build --wheel --sdist
|
||||
@echo ""
|
||||
@echo "✅ Packages built successfully:"
|
||||
@ls -lah dist/ 2>/dev/null || echo " No packages found"
|
||||
|
||||
release-validate:
|
||||
@echo "✅ Validating release readiness..."
|
||||
$(VENV_PYTHON) release.py validate
|
||||
|
||||
release-prepare:
|
||||
@echo "🚀 Preparing release..."
|
||||
@if [ -z "$(VERSION)" ]; then \
|
||||
echo "❌ Usage: make release-prepare VERSION=1.0.0"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(VENV_PYTHON) release.py prepare --version $(VERSION)
|
||||
|
||||
release-build:
|
||||
@echo "📦 Building release packages..."
|
||||
$(VENV_PYTHON) release.py build $(if $(VERSION),--version $(VERSION))
|
||||
|
||||
release-publish:
|
||||
@echo "📢 Publishing release..."
|
||||
@if [ -z "$(VERSION)" ]; then \
|
||||
echo "❌ Usage: make release-publish VERSION=1.0.0"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(VENV_PYTHON) release.py publish --version $(VERSION)
|
||||
|
||||
release-dry-run:
|
||||
@echo "🧪 Dry run release preparation..."
|
||||
@if [ -z "$(VERSION)" ]; then \
|
||||
echo "❌ Usage: make release-dry-run VERSION=1.0.0"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(VENV_PYTHON) release.py prepare --version $(VERSION) --dry-run
|
||||
# Release management targets are provided by capabilities/release-management/Makefile
|
||||
# All capability targets are automatically discovered and available via delegation
|
||||
# Run 'make capabilities-help' to see all available capability commands
|
||||
|
||||
# Chaos Engineering targets
|
||||
chaos-validate:
|
||||
|
||||
149
TODO.html
Normal file
149
TODO.html
Normal file
@@ -0,0 +1,149 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="generator" content="TestDrive JSUI Markitect 1.0.0">
|
||||
<title>TestDrive JSUI Document</title>
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
line-height: 1.6;
|
||||
color: #333333;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
#markdown-content {
|
||||
min-height: 200px;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: #333333;
|
||||
}
|
||||
pre {
|
||||
background-color: #f6f8fa;
|
||||
color: #333333;
|
||||
padding: 1rem;
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #d0d7de;
|
||||
}
|
||||
code {
|
||||
background-color: #f6f8fa;
|
||||
color: #333333;
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 3px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
pre code {
|
||||
background: none;
|
||||
padding: 0;
|
||||
}
|
||||
blockquote {
|
||||
border-left: 4px solid #dfe2e5;
|
||||
margin: 0;
|
||||
padding-left: 1rem;
|
||||
color: #6a737d;
|
||||
}
|
||||
table {
|
||||
font-size: 0.85em;
|
||||
border-collapse: collapse;
|
||||
margin: 1rem 0;
|
||||
width: 100%;
|
||||
border: 1px solid #d0d7de;
|
||||
}
|
||||
th, td {
|
||||
font-size: inherit;
|
||||
border: 1px solid #d0d7de;
|
||||
padding: 0.5rem;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f6f8fa;
|
||||
font-weight: 600;
|
||||
}
|
||||
img {
|
||||
max-width: 12cm;
|
||||
max-height: 20cm;
|
||||
height: auto;
|
||||
display: block;
|
||||
margin: 1rem auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- Plugin-specific CSS -->
|
||||
<link rel="stylesheet" href="_markitect/plugins/testdrive-jsui/static/css/editor.css">
|
||||
<link rel="stylesheet" href="_markitect/plugins/testdrive-jsui/static/css/controls.css">
|
||||
<link rel="stylesheet" href="_markitect/plugins/testdrive-jsui/static/css/themes/github.css">
|
||||
|
||||
<!-- External dependencies -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"
|
||||
onload="window.markitectMarkedLoaded = true"
|
||||
onerror="console.error('CDN library failed to load - network or firewall blocking marked.js'); window.markitectMarkedError = true;"></script>
|
||||
</head>
|
||||
<body class="markitect-edit-mode">
|
||||
|
||||
<!-- Content container with fallback content -->
|
||||
<div id="markdown-content">
|
||||
<h1>Todofile</h1></p><p>This is a "to do next" file, particularly useful to keep the human and a coding assistant in sync.</p><p>The format is based on [Keep a Todofile V0.0.1](https://coulomb.social/open/KeepaTodofile).</p><p>The structure organizes **future tasks** by their impact, just as a changelog organizes past changes by their impact.</p><p>***</p><p><h2>[Unreleased] - *Active Vibe-Coding State* 💡</h2></p><p>This section is for tasks currently being discussed with or worked on by the coding assistant. These are the ephemeral, flow-of-thought tasks.</p><p>*No active tasks at this time.*</p><p>***</p><p><h2>Completed Tasks</h2></p><p>*Recent completed tasks have been documented in CHANGELOG.md following Keep a Changelog format.*
|
||||
</div>
|
||||
|
||||
<!-- Configuration Data Interface - Clean JSON configuration -->
|
||||
<script id="markitect-config" type="application/json">{
|
||||
"markdownContent": "# Todofile\n\nThis is a \"to do next\" file, particularly useful to keep the human and a coding assistant in sync.\n\nThe format is based on [Keep a Todofile V0.0.1](https://coulomb.social/open/KeepaTodofile).\n\nThe structure organizes **future tasks** by their impact, just as a changelog organizes past changes by their impact.\n\n***\n\n## [Unreleased] - *Active Vibe-Coding State* \ud83d\udca1\n\nThis section is for tasks currently being discussed with or worked on by the coding assistant. These are the ephemeral, flow-of-thought tasks.\n\n*No active tasks at this time.*\n\n***\n\n## Completed Tasks\n\n*Recent completed tasks have been documented in CHANGELOG.md following Keep a Changelog format.*",
|
||||
"markdownContentWithDogtag": "# Todofile\n\nThis is a \"to do next\" file, particularly useful to keep the human and a coding assistant in sync.\n\nThe format is based on [Keep a Todofile V0.0.1](https://coulomb.social/open/KeepaTodofile).\n\nThe structure organizes **future tasks** by their impact, just as a changelog organizes past changes by their impact.\n\n***\n\n## [Unreleased] - *Active Vibe-Coding State* \ud83d\udca1\n\nThis section is for tasks currently being discussed with or worked on by the coding assistant. These are the ephemeral, flow-of-thought tasks.\n\n*No active tasks at this time.*\n\n***\n\n## Completed Tasks\n\n*Recent completed tasks have been documented in CHANGELOG.md following Keep a Changelog format.*",
|
||||
"dogtagContent": "",
|
||||
"mode": "edit",
|
||||
"theme": "github",
|
||||
"keyboardShortcuts": true,
|
||||
"autosave": false,
|
||||
"sections": true,
|
||||
"originalFilename": "document",
|
||||
"base64References": {},
|
||||
"version": "Markitect 1.0.0",
|
||||
"repoName": "Markitect"
|
||||
}</script>
|
||||
|
||||
<!-- Plugin JavaScript Assets -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/core/debug-system.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/core/section-manager.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/components/debug-panel.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/components/document-controls.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/components/dom-renderer.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/controls/control-base.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/controls/contents-control.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/controls/status-control.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/controls/debug-control.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/controls/edit-control.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/config-loader.js"></script>
|
||||
<script src="_markitect/plugins/testdrive-jsui/static/js/main-updated.js"></script>
|
||||
|
||||
<!-- Initialization Script -->
|
||||
<script>
|
||||
window.addEventListener('load', function() {
|
||||
console.log('🎯 TestDrive JSUI loading complete, initializing...');
|
||||
|
||||
// Handle CDN loading errors
|
||||
if (window.markitectMarkedError) {
|
||||
console.error("CDN library failed to load - network or firewall blocking marked.js");
|
||||
}
|
||||
|
||||
// Initialize main application
|
||||
try {
|
||||
if (typeof MarkitectMain !== 'undefined') {
|
||||
console.log('🚀 Starting MarkitectMain initialization...');
|
||||
MarkitectMain.initialize();
|
||||
} else {
|
||||
console.warn('⚠️ MarkitectMain not available, edit functionality may be limited');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ TestDrive JSUI initialization failed:', error);
|
||||
console.log('📄 Content should still be visible in fallback mode');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
167
TODO.md
167
TODO.md
@@ -12,173 +12,10 @@ The structure organizes **future tasks** by their impact, just as a changelog or
|
||||
|
||||
This section is for tasks currently being discussed with or worked on by the coding assistant. These are the ephemeral, flow-of-thought tasks.
|
||||
|
||||
**🏗️ MAJOR ARCHITECTURE REFACTORING (2025-11-03) - COMPLETED ✅**: Successfully completed comprehensive JavaScript refactoring using Test-Driven Development methodology.
|
||||
|
||||
**PROBLEMS SOLVED**:
|
||||
1. ✅ **Monolithic Architecture**: Extracted 5,188-line `editor.js` into 4 modular components
|
||||
2. ✅ **Server-Side Debug Generation**: Implemented pure client-side DebugPanel component
|
||||
3. ✅ **Architectural Boundary Violations**: Clean separation with no Python code modifications
|
||||
4. ✅ **Tight Coupling**: All components independently testable with event-driven communication
|
||||
5. ✅ **Generic Editor Compromise**: Debug system now purely client-side and component-based
|
||||
|
||||
**SOLUTION IMPLEMENTED**: Modular JavaScript Architecture with complete component separation and TDD validation.
|
||||
|
||||
**📊 PREVIOUS STATUS (2025-11-02)**: Systematic JavaScript functionality recovery using TDD methodology had made excellent progress. **5 major features** were successfully implemented and tested:
|
||||
|
||||
1. **Advanced EditState Management** ✅ - Implemented enum-based state tracking with pending changes preservation
|
||||
2. **Keyboard Shortcuts** ✅ - Added Ctrl+Enter (accept) and Escape (cancel) functionality
|
||||
3. **Section Splitting** ✅ - Restored dynamic heading detection with automatic section reorganization
|
||||
4. **Real-time Status Tracking** ✅ - Implemented periodic updates with visual status panel (2-second intervals)
|
||||
5. **Intelligent Filename Generation** ✅ - Added 4-method fallback system (options→title→URL→heading→timestamp)
|
||||
|
||||
All implementations include comprehensive TDD test suites and are fully integrated into the existing codebase. The recovery approach has proven highly effective for restoring sophisticated lost functionality.
|
||||
|
||||
## 🏗️ JAVASCRIPT ARCHITECTURE REFACTORING - COMPLETED ✅
|
||||
|
||||
### **Phase 1: Preparation & Backup (CRITICAL) - ✅ COMPLETED**
|
||||
* ✅ Updated TODO.md with comprehensive refactoring plan
|
||||
* ✅ Created modular directory structure `markitect/static/js/`
|
||||
* ✅ Set up component template files with proper exports/imports
|
||||
* ✅ Implemented TDD test framework for safe refactoring
|
||||
|
||||
### **Phase 2: Core System Extraction (HIGH) - ✅ COMPLETED**
|
||||
* ✅ Extracted SectionManager to `core/section-manager.js` (490 lines)
|
||||
* ✅ Integrated EventSystem into SectionManager with pub/sub pattern
|
||||
* ✅ Created comprehensive section state management with EditState enum
|
||||
|
||||
### **Phase 3: Component Separation (HIGH) - ✅ COMPLETED**
|
||||
* ✅ Document Controls → `components/document-controls.js` (200 lines)
|
||||
* ✅ DOMRenderer (includes status functionality) → `components/dom-renderer.js` (540 lines)
|
||||
* ✅ Debug Panel → `components/debug-panel.js` (150 lines, pure client-side)
|
||||
* ✅ Floating Menu → integrated into DOMRenderer component
|
||||
* ✅ Text/Image Editors → integrated into DOMRenderer component
|
||||
|
||||
### **Phase 4: Testing Infrastructure (MEDIUM) - ✅ COMPLETED**
|
||||
* ✅ Standalone TDD test runner (`RefactorTestRunner`) that doesn't require md-render
|
||||
* ✅ Component unit tests for all individual functionality
|
||||
* ✅ Integration tests for component interaction
|
||||
* ✅ Full system integration tests for complete workflow validation
|
||||
|
||||
### **Phase 5: Integration & Cleanup (MEDIUM) - ✅ COMPLETED**
|
||||
* ✅ All components work together with preserved functionality
|
||||
* ✅ Monolithic editor.js functionality fully distributed
|
||||
* ✅ Python code completely unchanged - zero md-render modifications
|
||||
* ✅ All functionality validated through comprehensive test suite (31 tests passing)
|
||||
|
||||
### **Directory Structure Implemented:**
|
||||
```
|
||||
markitect/static/js/
|
||||
├── core/
|
||||
│ └── section-manager.js # ✅ Section state management with EventSystem (490 lines)
|
||||
├── components/
|
||||
│ ├── document-controls.js # ✅ Document controls panel (200 lines)
|
||||
│ ├── dom-renderer.js # ✅ DOM rendering, FloatingMenu, editors (540 lines)
|
||||
│ └── debug-panel.js # ✅ Debug panel (150 lines, pure client-side)
|
||||
└── tests/
|
||||
├── refactor-test-runner.js # ✅ TDD test framework
|
||||
├── test-component-integration.js # ✅ Component integration tests
|
||||
├── test-full-integration.js # ✅ Full system tests
|
||||
├── test-section-manager-extraction.js # ✅ SectionManager tests
|
||||
├── test-extracted-section-manager.js # ✅ SectionManager TDD tests
|
||||
├── test-domrenderer-extraction.js # ✅ DOMRenderer extraction tests
|
||||
├── test-extracted-domrenderer.js # ✅ DOMRenderer TDD tests
|
||||
├── test-debugpanel-extraction.js # ✅ DebugPanel extraction tests
|
||||
├── test-debugpanel-integration.js # ✅ DebugPanel integration tests
|
||||
└── test-documentcontrols-extraction.js # ✅ DocumentControls tests
|
||||
```
|
||||
|
||||
### **REFACTORING RESULTS SUMMARY:**
|
||||
- **Lines Extracted**: 1,380 lines from monolithic 5,188-line editor.js
|
||||
- **Components Created**: 4 modular, independently testable components
|
||||
- **Tests Created**: 11 comprehensive test files with 31 passing tests
|
||||
- **Architecture**: Event-driven, pub/sub communication between components
|
||||
- **Functionality**: 100% preserved with zero regression
|
||||
- **Performance**: Improved modularity enables better maintainability and testing
|
||||
- **Python Code**: Zero modifications - clean architectural separation achieved
|
||||
|
||||
### **PREVIOUS COMPLETED FEATURES (Now successfully refactored):**
|
||||
* **Successfully Refactored:**
|
||||
* ✅ Advanced state management with EditState enum and pending changes (CRITICAL) - REFACTORED INTO SectionManager
|
||||
* ✅ Keyboard shortcuts (Ctrl+Enter accept, Escape cancel) (CRITICAL) - REFACTORED INTO DOMRenderer
|
||||
* ✅ Section splitting functionality for dynamic heading detection (HIGH) - REFACTORED INTO SectionManager
|
||||
* ✅ Real-time status tracking with periodic updates (HIGH) - REFACTORED INTO DocumentControls
|
||||
* ✅ Intelligent save filename generation with 4-method fallback (MEDIUM) - PRESERVED IN MONOLITH
|
||||
* ✅ Professional message system with color-coded positioning (MEDIUM) - REFACTORED INTO DebugPanel
|
||||
* ✅ Multiple concurrent editing sessions support (MEDIUM) - REFACTORED INTO DOMRenderer
|
||||
* ✅ Enhanced DOM event system with 6 event types (LOW) - REFACTORED INTO DOMRenderer
|
||||
* ✅ Automatic section type detection (heading, code, list, etc) (LOW) - REFACTORED INTO SectionManager
|
||||
* ✅ Sophisticated section ID generation with hash-based algorithm (LOW) - REFACTORED INTO SectionManager
|
||||
|
||||
* **Successfully Implemented:**
|
||||
* ✅ Comprehensive status reporting dialog with detailed stats (HIGH) - IMPLEMENTED IN DocumentControls
|
||||
* ✅ Floating global control panel with professional styling (MEDIUM) - IMPLEMENTED IN DocumentControls
|
||||
* ✅ Enhanced setupSectionElement with comprehensive styling (LOW) - IMPLEMENTED IN DOMRenderer
|
||||
|
||||
* **Core Methods Successfully Refactored:**
|
||||
* ✅ stopEditing method with state preservation (CRITICAL) - REFACTORED INTO SectionManager
|
||||
* ✅ getAllSections method for section collection management (MEDIUM) - REFACTORED INTO SectionManager
|
||||
* ✅ hasChanges detection for unsaved modifications (HIGH) - REFACTORED INTO SectionManager
|
||||
* ✅ updateGlobalStatus method with 2-second interval updates (MEDIUM) - REFACTORED INTO DocumentControls
|
||||
* ✅ handleSectionSplit for dynamic section reorganization (LOW) - REFACTORED INTO SectionManager
|
||||
* ✅ checkForSectionSplits automatic heading detection (LOW) - REFACTORED INTO SectionManager
|
||||
|
||||
* **To Remove:**
|
||||
* None currently identified
|
||||
|
||||
*No active tasks at this time.*
|
||||
|
||||
***
|
||||
|
||||
## Completed Tasks
|
||||
|
||||
**JavaScript Architecture Refactoring - COMPLETED ✅ (2025-11-03)**:
|
||||
- ✅ Successfully extracted monolithic 5,188-line editor.js into 4 modular components using TDD methodology
|
||||
- ✅ Created SectionManager component (490 lines) handling section state management and event system
|
||||
- ✅ Created DOMRenderer component (540 lines) handling DOM interactions, rendering, and editing workflows
|
||||
- ✅ Created DebugPanel component (150 lines) providing pure client-side debug message management
|
||||
- ✅ Created DocumentControls component (200 lines) managing floating control panel and document actions
|
||||
- ✅ Implemented comprehensive TDD test framework with 11 test files and 31 passing tests
|
||||
- ✅ Achieved 100% functionality preservation with zero regression through rigorous testing
|
||||
- ✅ Established event-driven architecture with pub/sub communication between components
|
||||
- ✅ Maintained complete separation from Python code - zero md-render modifications required
|
||||
- ✅ Created modular directory structure enabling independent component development and testing
|
||||
|
||||
**Architecture Improvements Achieved**:
|
||||
- Clean separation of concerns with single-responsibility components
|
||||
- Event-driven communication reducing tight coupling
|
||||
- Independent component testing enabling confident refactoring
|
||||
- Scalable structure supporting future feature development
|
||||
- Client-side debug system eliminating server-side debug generation issues
|
||||
- Modular design allowing selective component updates without affecting others
|
||||
|
||||
**Asset Shipping for md-render - COMPLETED ✅**:
|
||||
- ✅ Implemented automatic asset copying when rendering markdown to different output directories
|
||||
- ✅ Added asset discovery functionality parsing markdown for image/link references
|
||||
- ✅ Implemented timestamp-based asset copying (only copy if source newer than destination)
|
||||
- ✅ Added `--ship-assets` and `--no-ship-assets` CLI flags for explicit control
|
||||
- ✅ Added `MARKITECT_OUTPUT_DIR` environment variable support for default output directory
|
||||
- ✅ Smart defaults: assets ship automatically when output is directory, disabled for specific files
|
||||
- ✅ Preserved relative path structure in output directory maintaining markdown link compatibility
|
||||
- ✅ Graceful handling of missing assets with warning messages
|
||||
- ✅ Full backward compatibility with existing md-render workflows
|
||||
- ✅ Comprehensive TDD test suite covering all functionality and edge cases
|
||||
|
||||
**Feature Capabilities**:
|
||||
- Environment variable priority: CLI `--output` > `MARKITECT_OUTPUT_DIR` > input file directory
|
||||
- Automatic asset discovery from standard markdown syntax: `` and `[text](path)`
|
||||
- Timestamp-based incremental copying prevents unnecessary file operations
|
||||
- Directory structure preservation maintains working relative links in output HTML
|
||||
- Support for images, documents, and other asset types referenced in markdown
|
||||
|
||||
**CHANGELOG.md Enhancement - COMPLETED ✅**:
|
||||
- ✅ Added missing version entries for 0.1.0, 0.2.0, and 0.3.0
|
||||
- ✅ Added standard Keep a Changelog header with proper format
|
||||
- ✅ Included Unreleased section
|
||||
- ✅ Research completed for all historical versions using git log analysis
|
||||
- ✅ All entries follow Keep a Changelog categories (Added, Changed, Fixed)
|
||||
- ✅ Chronological order maintained with latest versions first
|
||||
- ✅ Appropriate release dates included based on git commit timestamps
|
||||
|
||||
**Version Details Added**:
|
||||
- v0.1.0 (2025-10-15): Development infrastructure, TDD workspace, issue management
|
||||
- v0.2.0 (2025-10-20): Advanced Markdown Engine with GraphQL, search, plugins
|
||||
- v0.3.0 (2025-10-25): Architectural improvements with kaizen-agentic integration
|
||||
*Recent completed tasks have been documented in CHANGELOG.md following Keep a Changelog format.*
|
||||
210
agents/agent-capability-manager.md
Normal file
210
agents/agent-capability-manager.md
Normal file
@@ -0,0 +1,210 @@
|
||||
# Capability Manager Agent
|
||||
|
||||
You are a specialized agent for managing MarkiTect's capability system. You understand the modular architecture where capabilities are self-contained packages in the `capabilities/` directory, each with their own Makefiles, documentation, and functionality.
|
||||
|
||||
## Your Role
|
||||
|
||||
You are responsible for:
|
||||
- **Capability Discovery**: Finding and cataloging all capabilities in the project
|
||||
- **Makefile Management**: Creating and maintaining Makefiles for capabilities
|
||||
- **Target Delegation**: Ensuring proper target delegation from main Makefile to capabilities
|
||||
- **Documentation**: Maintaining capability documentation and help systems
|
||||
- **Quality Assurance**: Ensuring capabilities follow the established patterns
|
||||
|
||||
## Capability Architecture Understanding
|
||||
|
||||
### Directory Structure
|
||||
```
|
||||
markitect_project/
|
||||
├── Makefile # Main project Makefile
|
||||
├── scripts/
|
||||
│ └── capability_discovery.mk # Auto-discovery and delegation system
|
||||
└── capabilities/
|
||||
├── capability-name/
|
||||
│ ├── Makefile # Capability-specific targets
|
||||
│ ├── README.md # Capability documentation
|
||||
│ ├── pyproject.toml # Package configuration
|
||||
│ └── src/capability_name/ # Source code
|
||||
└── ...
|
||||
```
|
||||
|
||||
### Makefile System
|
||||
|
||||
#### Main Makefile Integration
|
||||
- Includes `scripts/capability_discovery.mk` for auto-discovery
|
||||
- Provides capability management targets:
|
||||
- `capabilities-list` - Show all capabilities
|
||||
- `capabilities-help` - Show help for all capabilities
|
||||
- `capabilities-status` - Show capability status
|
||||
- `capabilities-install` - Install all capabilities
|
||||
|
||||
#### Capability Makefile Pattern
|
||||
Each capability should have a Makefile with:
|
||||
1. **Capability metadata** (name, description)
|
||||
2. **Help target** showing available commands
|
||||
3. **Core functionality targets** specific to the capability
|
||||
4. **Installation/setup targets**
|
||||
5. **Testing targets**
|
||||
6. **Meta information target** for discovery
|
||||
|
||||
#### Target Delegation System
|
||||
- Direct delegation: `release-*` targets → `release-management` capability
|
||||
- Generic delegation: `capability-name-target` → `capability-name/Makefile:target`
|
||||
- Auto-discovery includes all capability Makefiles
|
||||
|
||||
### Established Patterns
|
||||
|
||||
#### Successful Example: release-management
|
||||
```makefile
|
||||
# Capability metadata
|
||||
CAPABILITY_NAME := release-management
|
||||
CAPABILITY_DESCRIPTION := Comprehensive release management for Python projects
|
||||
|
||||
# Help target
|
||||
.PHONY: help
|
||||
help: ## Show release management help
|
||||
@echo "📦 Release Management Capability"
|
||||
# ... help content
|
||||
|
||||
# Core targets
|
||||
.PHONY: release-status release-build release-publish
|
||||
release-status: ## Show current release status
|
||||
release status
|
||||
|
||||
# Meta information
|
||||
.PHONY: capability-info
|
||||
capability-info: ## Show capability information
|
||||
@echo "Name: $(CAPABILITY_NAME)"
|
||||
@echo "Description: $(CAPABILITY_DESCRIPTION)"
|
||||
```
|
||||
|
||||
#### CLI Integration Pattern
|
||||
- Capabilities can provide CLI tools (e.g., `release` command)
|
||||
- Makefile targets can delegate to CLI commands
|
||||
- CLI availability is checked before execution
|
||||
|
||||
## Current Capabilities to Manage
|
||||
|
||||
Based on the `capabilities/` directory, you need to manage:
|
||||
|
||||
1. **release-management** ✅ - Fully implemented with Makefile
|
||||
2. **markitect-content** ❓ - Content parsing capability, needs Makefile
|
||||
3. **markitect-utils** ❓ - Utility functions capability, needs Makefile
|
||||
4. **issue-facade** ❓ - Issue tracking CLI, needs Makefile
|
||||
5. **kaizen-agentic** ✅ - AI agent framework, has Makefile but may need review
|
||||
|
||||
## Your Tasks
|
||||
|
||||
### 1. Capability Audit
|
||||
When asked to audit capabilities:
|
||||
- Scan `capabilities/` directory
|
||||
- Check each capability for:
|
||||
- README.md existence and quality
|
||||
- pyproject.toml configuration
|
||||
- Makefile existence and completeness
|
||||
- CLI tools or main functionality
|
||||
- Integration with main project
|
||||
|
||||
### 2. Makefile Creation
|
||||
For capabilities missing Makefiles:
|
||||
- Follow the established pattern from `release-management/Makefile`
|
||||
- Include appropriate targets based on capability type
|
||||
- Ensure proper capability metadata
|
||||
- Add help documentation
|
||||
- Include installation and testing targets
|
||||
|
||||
### 3. Target Analysis
|
||||
- Scan main Makefile for orphaned targets that should be in capabilities
|
||||
- Identify targets that could benefit from delegation
|
||||
- Recommend improvements to capability organization
|
||||
|
||||
### 4. Documentation Maintenance
|
||||
- Ensure each capability has proper README.md
|
||||
- Update capability descriptions and help text
|
||||
- Maintain consistency across capability documentation
|
||||
|
||||
## Capability Types and Their Typical Targets
|
||||
|
||||
### Code/Library Capabilities (markitect-content, markitect-utils)
|
||||
```makefile
|
||||
# Typical targets
|
||||
capability-name-test # Run tests
|
||||
capability-name-install # Install capability
|
||||
capability-name-install-dev # Install with dev dependencies
|
||||
capability-name-build # Build packages
|
||||
capability-name-clean # Clean build artifacts
|
||||
capability-name-lint # Code linting
|
||||
capability-name-format # Code formatting
|
||||
```
|
||||
|
||||
### Tool/CLI Capabilities (issue-facade, release-management)
|
||||
```makefile
|
||||
# Typical targets
|
||||
capability-name-status # Show tool status
|
||||
capability-name-help # Show CLI help
|
||||
capability-name-install # Install tool
|
||||
capability-name-config # Configure tool
|
||||
capability-name-test # Run tests
|
||||
```
|
||||
|
||||
### Framework Capabilities (kaizen-agentic)
|
||||
```makefile
|
||||
# Typical targets
|
||||
capability-name-setup # Initial setup
|
||||
capability-name-agents-list # List agents/components
|
||||
capability-name-test # Run tests
|
||||
capability-name-build # Build framework
|
||||
capability-name-docs # Generate documentation
|
||||
```
|
||||
|
||||
## Quality Standards
|
||||
|
||||
### Makefile Requirements
|
||||
- ✅ Must have capability metadata (NAME, DESCRIPTION)
|
||||
- ✅ Must have help target with clear documentation
|
||||
- ✅ Must have capability-info target for discovery
|
||||
- ✅ Must check for dependencies/CLI availability
|
||||
- ✅ Must follow consistent naming patterns
|
||||
- ✅ Must include installation targets
|
||||
|
||||
### Documentation Requirements
|
||||
- ✅ README.md with clear description
|
||||
- ✅ Installation instructions
|
||||
- ✅ Usage examples
|
||||
- ✅ API documentation where applicable
|
||||
- ✅ Integration with main project explained
|
||||
|
||||
### Integration Requirements
|
||||
- ✅ Proper pyproject.toml configuration
|
||||
- ✅ Compatible with capability discovery system
|
||||
- ✅ No conflicts with existing targets
|
||||
- ✅ Clear dependency management
|
||||
|
||||
## Commands You Should Use
|
||||
|
||||
When auditing and managing capabilities:
|
||||
|
||||
1. **Discovery Commands**:
|
||||
- `make capabilities-list` - See current capabilities
|
||||
- `make capabilities-status` - Check capability health
|
||||
- `find capabilities/ -name "Makefile"` - Find existing Makefiles
|
||||
|
||||
2. **Testing Commands**:
|
||||
- `make capabilities-help` - Test help system
|
||||
- `make capability-name-help` - Test specific capability help
|
||||
|
||||
3. **File Operations**:
|
||||
- Use Read tool to examine existing Makefiles and documentation
|
||||
- Use Write tool to create new Makefiles
|
||||
- Use Edit tool to update existing files
|
||||
|
||||
## Your Approach
|
||||
|
||||
When given a task:
|
||||
1. **Assess Current State**: Use discovery commands to understand what exists
|
||||
2. **Identify Gaps**: Compare what exists vs. what should exist
|
||||
3. **Create Missing Components**: Generate Makefiles, documentation, etc.
|
||||
4. **Validate Integration**: Test that everything works together
|
||||
5. **Document Changes**: Update any necessary documentation
|
||||
|
||||
Remember: You're maintaining a sophisticated capability system that should be easy to extend, discover, and use. Every capability should follow the established patterns while being tailored to its specific functionality.
|
||||
@@ -5055,6 +5055,94 @@
|
||||
"size": 43,
|
||||
"created_at": "2025-10-20T07:21:34.059271",
|
||||
"description": null
|
||||
},
|
||||
"d1f2de1aa975f05ac067cb3512059a675aad9acd6e1bcd5dc57e1dd51d00db01": {
|
||||
"path": "/home/worsch/markitect_project/assets/d1/d1f2de1aa975f05ac067cb3512059a675aad9acd6e1bcd5dc57e1dd51d00db01.pdf",
|
||||
"content_hash": "d1f2de1aa975f05ac067cb3512059a675aad9acd6e1bcd5dc57e1dd51d00db01",
|
||||
"mime_type": "application/pdf",
|
||||
"size": 29,
|
||||
"created_at": "2025-11-09T09:25:06.866540",
|
||||
"description": null
|
||||
},
|
||||
"1895a4a5b1a7afcba497477008076e1a9b70442342092d5ce43f7ab447b30873": {
|
||||
"path": "/home/worsch/markitect_project/assets/18/1895a4a5b1a7afcba497477008076e1a9b70442342092d5ce43f7ab447b30873.svg",
|
||||
"content_hash": "1895a4a5b1a7afcba497477008076e1a9b70442342092d5ce43f7ab447b30873",
|
||||
"mime_type": "image/svg+xml",
|
||||
"size": 25,
|
||||
"created_at": "2025-11-09T09:25:06.893302",
|
||||
"description": null
|
||||
},
|
||||
"f45288fe7b30287abefccd6e96eafa2413c2f73671c433a9fd17f96876dcba68": {
|
||||
"path": "/home/worsch/markitect_project/assets/f4/f45288fe7b30287abefccd6e96eafa2413c2f73671c433a9fd17f96876dcba68.png",
|
||||
"content_hash": "f45288fe7b30287abefccd6e96eafa2413c2f73671c433a9fd17f96876dcba68",
|
||||
"mime_type": "image/png",
|
||||
"size": 28,
|
||||
"created_at": "2025-11-09T09:25:06.917300",
|
||||
"description": null
|
||||
},
|
||||
"61cb7a679ea77d0765e7f2285b080add305d096a795abc48e82a7cd8d915d9d3": {
|
||||
"path": "/home/worsch/markitect_project/assets/61/61cb7a679ea77d0765e7f2285b080add305d096a795abc48e82a7cd8d915d9d3.jpg",
|
||||
"content_hash": "61cb7a679ea77d0765e7f2285b080add305d096a795abc48e82a7cd8d915d9d3",
|
||||
"mime_type": "image/jpeg",
|
||||
"size": 26,
|
||||
"created_at": "2025-11-09T09:25:06.939018",
|
||||
"description": null
|
||||
},
|
||||
"33ed8dd1f8e470138f016e1a2641d38ccbc1c1cfb10ffdac59ef309974748c6d": {
|
||||
"path": "/home/worsch/markitect_project/assets/33/33ed8dd1f8e470138f016e1a2641d38ccbc1c1cfb10ffdac59ef309974748c6d.png",
|
||||
"content_hash": "33ed8dd1f8e470138f016e1a2641d38ccbc1c1cfb10ffdac59ef309974748c6d",
|
||||
"mime_type": "image/png",
|
||||
"size": 27,
|
||||
"created_at": "2025-11-09T09:25:06.959757",
|
||||
"description": null
|
||||
},
|
||||
"b509163964e822915ea7e822759ecae39dd696626e70b74b96de6ac7396415d0": {
|
||||
"path": "/home/worsch/markitect_project/assets/b5/b509163964e822915ea7e822759ecae39dd696626e70b74b96de6ac7396415d0.png",
|
||||
"content_hash": "b509163964e822915ea7e822759ecae39dd696626e70b74b96de6ac7396415d0",
|
||||
"mime_type": "image/png",
|
||||
"size": 14,
|
||||
"created_at": "2025-11-09T09:25:07.012411",
|
||||
"description": null
|
||||
},
|
||||
"e4d8e7de1bda3f19dd16c984ec045bed1a60fe69989ff48a2875cf81dfd56bb6": {
|
||||
"path": "/home/worsch/markitect_project/assets/e4/e4d8e7de1bda3f19dd16c984ec045bed1a60fe69989ff48a2875cf81dfd56bb6.pdf",
|
||||
"content_hash": "e4d8e7de1bda3f19dd16c984ec045bed1a60fe69989ff48a2875cf81dfd56bb6",
|
||||
"mime_type": "application/pdf",
|
||||
"size": 33,
|
||||
"created_at": "2025-11-09T09:25:07.219675",
|
||||
"description": null
|
||||
},
|
||||
"6e64079b752375a2e3ae5d6d67af3d2569b284997536c5fa8bd01af2baafdc08": {
|
||||
"path": "/home/worsch/markitect_project/assets/6e/6e64079b752375a2e3ae5d6d67af3d2569b284997536c5fa8bd01af2baafdc08.svg",
|
||||
"content_hash": "6e64079b752375a2e3ae5d6d67af3d2569b284997536c5fa8bd01af2baafdc08",
|
||||
"mime_type": "image/svg+xml",
|
||||
"size": 29,
|
||||
"created_at": "2025-11-09T09:25:07.243001",
|
||||
"description": null
|
||||
},
|
||||
"33794900aef1bda0b9bbb8f24f26e6181507169bb1979a8502503ae68962a9aa": {
|
||||
"path": "/home/worsch/markitect_project/assets/33/33794900aef1bda0b9bbb8f24f26e6181507169bb1979a8502503ae68962a9aa.png",
|
||||
"content_hash": "33794900aef1bda0b9bbb8f24f26e6181507169bb1979a8502503ae68962a9aa",
|
||||
"mime_type": "image/png",
|
||||
"size": 32,
|
||||
"created_at": "2025-11-09T09:25:07.265421",
|
||||
"description": null
|
||||
},
|
||||
"9e90160cc46e32c3790e38e55bdc3bbd8d61f85036191b6693d02e53c06b1e4d": {
|
||||
"path": "/home/worsch/markitect_project/assets/9e/9e90160cc46e32c3790e38e55bdc3bbd8d61f85036191b6693d02e53c06b1e4d.jpg",
|
||||
"content_hash": "9e90160cc46e32c3790e38e55bdc3bbd8d61f85036191b6693d02e53c06b1e4d",
|
||||
"mime_type": "image/jpeg",
|
||||
"size": 30,
|
||||
"created_at": "2025-11-09T09:25:07.286159",
|
||||
"description": null
|
||||
},
|
||||
"345fe884e0f85e1d08e893f4c977b8e7437542126b6be90d86e8b8f68bba686f": {
|
||||
"path": "/home/worsch/markitect_project/assets/34/345fe884e0f85e1d08e893f4c977b8e7437542126b6be90d86e8b8f68bba686f.png",
|
||||
"content_hash": "345fe884e0f85e1d08e893f4c977b8e7437542126b6be90d86e8b8f68bba686f",
|
||||
"mime_type": "image/png",
|
||||
"size": 31,
|
||||
"created_at": "2025-11-09T09:25:07.306652",
|
||||
"description": null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
mock content for icon.svg
|
||||
@@ -0,0 +1 @@
|
||||
modified content for diagram.png
|
||||
@@ -0,0 +1 @@
|
||||
mock content for image1.png
|
||||
@@ -0,0 +1 @@
|
||||
modified content for image1.png
|
||||
@@ -0,0 +1 @@
|
||||
mock content for photo.jpg
|
||||
@@ -0,0 +1 @@
|
||||
modified content for icon.svg
|
||||
@@ -0,0 +1 @@
|
||||
modified content for photo.jpg
|
||||
BIN
assets/assets.db
BIN
assets/assets.db
Binary file not shown.
@@ -0,0 +1 @@
|
||||
nested content
|
||||
@@ -0,0 +1 @@
|
||||
mock content for document.pdf
|
||||
@@ -0,0 +1 @@
|
||||
modified content for document.pdf
|
||||
@@ -0,0 +1 @@
|
||||
mock content for diagram.png
|
||||
Submodule capabilities/issue-facade updated: 51aea5effb...34a8bc7d4c
114
capabilities/markitect-content/Makefile
Normal file
114
capabilities/markitect-content/Makefile
Normal file
@@ -0,0 +1,114 @@
|
||||
# MarkiTect Content Capability Makefile
|
||||
# Content parsing and statistics for MarkdownMatters documents
|
||||
|
||||
# Capability metadata
|
||||
CAPABILITY_NAME := markitect-content
|
||||
CAPABILITY_DESCRIPTION := Content parsing and statistics for MarkdownMatters documents
|
||||
|
||||
# Default target
|
||||
.PHONY: help
|
||||
help: ## Show content capability help
|
||||
@echo "📄 MarkiTect Content Capability"
|
||||
@echo "================================"
|
||||
@echo ""
|
||||
@echo "Content Operations:"
|
||||
@echo " content-get FILE=file.md Extract content without frontmatter/tailmatter"
|
||||
@echo " content-stats FILE=file.md Calculate content statistics (word count, etc.)"
|
||||
@echo " content-stats-json FILE=file.md Get content statistics in JSON format"
|
||||
@echo ""
|
||||
@echo "Development & Setup:"
|
||||
@echo " content-install Install content capability"
|
||||
@echo " content-install-dev Install with development dependencies"
|
||||
@echo " content-test Run content capability tests"
|
||||
@echo " content-test-cov Run tests with coverage report"
|
||||
@echo " content-lint Run code quality checks"
|
||||
@echo " content-clean Clean build artifacts"
|
||||
|
||||
# Check if markitect command is available (assumes CLI integration)
|
||||
MARKITECT_CLI := $(shell command -v markitect 2> /dev/null)
|
||||
|
||||
# Content Operations
|
||||
.PHONY: content-get
|
||||
content-get: ## Extract content without frontmatter and tailmatter (requires FILE=path/to/file.md)
|
||||
ifndef FILE
|
||||
@echo "❌ FILE is required. Usage: make content-get FILE=document.md"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef MARKITECT_CLI
|
||||
@echo "⚠️ markitect CLI not available, trying direct Python execution..."
|
||||
cd capabilities/markitect-content && python -m markitect_content.commands content-get --file "$(FILE)"
|
||||
else
|
||||
markitect content-get --file "$(FILE)"
|
||||
endif
|
||||
|
||||
.PHONY: content-stats
|
||||
content-stats: ## Calculate content statistics (requires FILE=path/to/file.md)
|
||||
ifndef FILE
|
||||
@echo "❌ FILE is required. Usage: make content-stats FILE=document.md"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef MARKITECT_CLI
|
||||
@echo "⚠️ markitect CLI not available, trying direct Python execution..."
|
||||
cd capabilities/markitect-content && python -m markitect_content.commands content-stats --file "$(FILE)" --format text
|
||||
else
|
||||
markitect content-stats --file "$(FILE)" --format text
|
||||
endif
|
||||
|
||||
.PHONY: content-stats-json
|
||||
content-stats-json: ## Get content statistics in JSON format (requires FILE=path/to/file.md)
|
||||
ifndef FILE
|
||||
@echo "❌ FILE is required. Usage: make content-stats-json FILE=document.md"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef MARKITECT_CLI
|
||||
@echo "⚠️ markitect CLI not available, trying direct Python execution..."
|
||||
cd capabilities/markitect-content && python -m markitect_content.commands content-stats --file "$(FILE)" --format json
|
||||
else
|
||||
markitect content-stats --file "$(FILE)" --format json
|
||||
endif
|
||||
|
||||
# Development and Setup
|
||||
.PHONY: content-install
|
||||
content-install: ## Install content capability
|
||||
pip install -e capabilities/markitect-content/
|
||||
|
||||
.PHONY: content-install-dev
|
||||
content-install-dev: ## Install content capability with development dependencies
|
||||
pip install -e "capabilities/markitect-content/[dev]"
|
||||
|
||||
.PHONY: content-test
|
||||
content-test: ## Run content capability tests
|
||||
cd capabilities/markitect-content && pytest tests/
|
||||
|
||||
.PHONY: content-test-cov
|
||||
content-test-cov: ## Run tests with coverage report
|
||||
cd capabilities/markitect-content && pytest tests/ --cov=markitect_content --cov-report=html --cov-report=term
|
||||
|
||||
.PHONY: content-lint
|
||||
content-lint: ## Run code quality checks
|
||||
@echo "🔍 Running code quality checks for markitect-content..."
|
||||
cd capabilities/markitect-content && python -m py_compile src/markitect_content/*.py
|
||||
@echo "✅ Code quality checks passed"
|
||||
|
||||
.PHONY: content-clean
|
||||
content-clean: ## Clean build artifacts
|
||||
cd capabilities/markitect-content && rm -rf build/ dist/ *.egg-info/ __pycache__/ .pytest_cache/ htmlcov/ .coverage
|
||||
find capabilities/markitect-content -name "*.pyc" -delete
|
||||
find capabilities/markitect-content -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
|
||||
|
||||
# Library Functions (for other capabilities to use)
|
||||
.PHONY: content-api-test
|
||||
content-api-test: ## Test content parsing API functionality
|
||||
@echo "🧪 Testing content parsing API..."
|
||||
cd capabilities/markitect-content && python -c "from src.markitect_content import ContentParser; parser = ContentParser(); content = parser.extract_content('---\\ntitle: Test\\n---\\n\\n# Hello\\n\\nContent here\\n\\n\`\`\`yaml tailmatter\\nfoo: bar\\n\`\`\`'); stats = parser.calculate_stats(content); print(f'Content: {repr(content)}'); print(f'Stats: {stats.to_dict()}')"
|
||||
|
||||
# Meta information for capability discovery
|
||||
.PHONY: capability-info
|
||||
capability-info: ## Show capability information
|
||||
@echo "Name: $(CAPABILITY_NAME)"
|
||||
@echo "Description: $(CAPABILITY_DESCRIPTION)"
|
||||
@echo "Type: Library capability with CLI commands"
|
||||
@echo "Main functions: Content extraction, statistics calculation"
|
||||
@echo "CLI commands: content-get, content-stats"
|
||||
@echo "Targets:"
|
||||
@$(MAKE) --no-print-directory help | grep "^ " | sed 's/^ / /'
|
||||
131
capabilities/markitect-utils/Makefile
Normal file
131
capabilities/markitect-utils/Makefile
Normal file
@@ -0,0 +1,131 @@
|
||||
# MarkiTect Utils Capability Makefile
|
||||
# Utility functions library for the MarkiTect ecosystem
|
||||
|
||||
# Capability metadata
|
||||
CAPABILITY_NAME := markitect-utils
|
||||
CAPABILITY_DESCRIPTION := Common utility functions for the MarkiTect ecosystem
|
||||
|
||||
# Default target
|
||||
.PHONY: help
|
||||
help: ## Show utils capability help
|
||||
@echo "🛠️ MarkiTect Utils Capability"
|
||||
@echo "==============================="
|
||||
@echo ""
|
||||
@echo "Library Testing:"
|
||||
@echo " utils-test-string Test string utility functions"
|
||||
@echo " utils-test-file Test file utility functions"
|
||||
@echo " utils-test-validation Test validation utility functions"
|
||||
@echo " utils-test-api Test complete API functionality"
|
||||
@echo ""
|
||||
@echo "Development & Setup:"
|
||||
@echo " utils-install Install utils capability"
|
||||
@echo " utils-install-dev Install with development dependencies"
|
||||
@echo " utils-test Run utils capability tests"
|
||||
@echo " utils-test-cov Run tests with coverage report"
|
||||
@echo " utils-lint Run code quality checks"
|
||||
@echo " utils-clean Clean build artifacts"
|
||||
@echo ""
|
||||
@echo "Quality & Compliance:"
|
||||
@echo " utils-validate-paradigm Validate ComposableRepositoryParadigm compliance"
|
||||
@echo " utils-check-dependencies Verify zero external dependencies"
|
||||
|
||||
# Development and Setup
|
||||
.PHONY: utils-install
|
||||
utils-install: ## Install utils capability
|
||||
pip install -e capabilities/markitect-utils/
|
||||
|
||||
.PHONY: utils-install-dev
|
||||
utils-install-dev: ## Install utils capability with development dependencies
|
||||
pip install -e "capabilities/markitect-utils/[dev]"
|
||||
|
||||
.PHONY: utils-test
|
||||
utils-test: ## Run utils capability tests
|
||||
cd capabilities/markitect-utils && pytest tests/
|
||||
|
||||
.PHONY: utils-test-cov
|
||||
utils-test-cov: ## Run tests with coverage report
|
||||
cd capabilities/markitect-utils && pytest tests/ --cov=markitect_utils --cov-report=html --cov-report=term
|
||||
|
||||
.PHONY: utils-lint
|
||||
utils-lint: ## Run code quality checks
|
||||
@echo "🔍 Running code quality checks for markitect-utils..."
|
||||
cd capabilities/markitect-utils && python -m py_compile src/markitect_utils/*.py
|
||||
@echo "✅ Code quality checks passed"
|
||||
|
||||
.PHONY: utils-clean
|
||||
utils-clean: ## Clean build artifacts
|
||||
cd capabilities/markitect-utils && rm -rf build/ dist/ *.egg-info/ __pycache__/ .pytest_cache/ htmlcov/ .coverage
|
||||
find capabilities/markitect-utils -name "*.pyc" -delete
|
||||
find capabilities/markitect-utils -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
|
||||
|
||||
# Library Function Testing
|
||||
.PHONY: utils-test-string
|
||||
utils-test-string: ## Test string utility functions
|
||||
@echo "🧪 Testing string utilities..."
|
||||
cd capabilities/markitect-utils && python -c "from src.markitect_utils import slugify, truncate, camel_to_snake, snake_to_camel, strip_ansi_codes; print('slugify(\"Hello World!\"):', slugify('Hello World!')); print('truncate(\"This is a long string\", 10):', truncate('This is a long string', 10)); print('camel_to_snake(\"camelCase\"):', camel_to_snake('camelCase')); print('snake_to_camel(\"snake_case\"):', snake_to_camel('snake_case')); print('strip_ansi_codes(\"\\\\033[31mRed\\\\033[0m\"):', strip_ansi_codes('\\033[31mRed\\033[0m')); print('✅ String utilities working')"
|
||||
|
||||
.PHONY: utils-test-file
|
||||
utils-test-file: ## Test file utility functions
|
||||
@echo "🧪 Testing file utilities..."
|
||||
cd capabilities/markitect-utils && python -c "from src.markitect_utils import safe_filename, ensure_extension, normalize_path; import tempfile, os; print('safe_filename(\"file<name>.txt\"):', safe_filename('file<name>.txt')); print('ensure_extension(\"document\", \".md\"):', ensure_extension('document', '.md')); print('normalize_path(\"./test/../file.txt\"):', normalize_path('./test/../file.txt')); print('✅ File utilities working')"
|
||||
|
||||
.PHONY: utils-test-validation
|
||||
utils-test-validation: ## Test validation utility functions
|
||||
@echo "🧪 Testing validation utilities..."
|
||||
cd capabilities/markitect-utils && python -c "from src.markitect_utils import is_valid_email, is_valid_url, is_valid_semver, validate_required_fields; print('is_valid_email(\"user@example.com\"):', is_valid_email('user@example.com')); print('is_valid_url(\"https://example.com\"):', is_valid_url('https://example.com')); print('is_valid_semver(\"1.0.0\"):', is_valid_semver('1.0.0')); result = validate_required_fields({'name': 'John', 'email': '', 'age': 30}, ['name', 'email', 'phone']); print('validate_required_fields test:', result); print('✅ Validation utilities working')"
|
||||
|
||||
.PHONY: utils-test-api
|
||||
utils-test-api: ## Test complete API functionality
|
||||
@echo "🧪 Testing complete utils API..."
|
||||
@$(MAKE) --no-print-directory utils-test-string
|
||||
@$(MAKE) --no-print-directory utils-test-file
|
||||
@$(MAKE) --no-print-directory utils-test-validation
|
||||
@echo "🎉 All utility functions tested successfully!"
|
||||
|
||||
# Quality & Compliance
|
||||
.PHONY: utils-validate-paradigm
|
||||
utils-validate-paradigm: ## Validate ComposableRepositoryParadigm compliance
|
||||
@echo "🏛️ Validating ComposableRepositoryParadigm compliance..."
|
||||
@echo "✅ Checking src layout structure..."
|
||||
test -d capabilities/markitect-utils/src/markitect_utils
|
||||
@echo "✅ Checking pyproject.toml exists..."
|
||||
test -f capabilities/markitect-utils/pyproject.toml
|
||||
@echo "✅ Checking README.md exists..."
|
||||
test -f capabilities/markitect-utils/README.md
|
||||
@echo "✅ Checking tests directory..."
|
||||
test -d capabilities/markitect-utils/tests
|
||||
@echo "✅ Verifying independent configuration..."
|
||||
cd capabilities/markitect-utils && python -c "import tomllib; f=open('pyproject.toml','rb'); data=tomllib.load(f); assert data['project']['name']=='markitect-utils'; print('✅ Independent pyproject.toml configuration verified')"
|
||||
@echo "🎉 ComposableRepositoryParadigm compliance validated!"
|
||||
|
||||
.PHONY: utils-check-dependencies
|
||||
utils-check-dependencies: ## Verify zero external dependencies
|
||||
@echo "📦 Checking dependency compliance..."
|
||||
cd capabilities/markitect-utils && python -c "import tomllib; f=open('pyproject.toml','rb'); data=tomllib.load(f); deps=data.get('project',{}).get('dependencies',[]); print(f'❌ Found external dependencies: {deps}') if deps else print('✅ Zero external dependencies confirmed - paradigm compliant!'); exit(1) if deps else None"
|
||||
|
||||
# Demonstration Functions
|
||||
.PHONY: utils-demo
|
||||
utils-demo: ## Demonstrate utility functions with examples
|
||||
@echo "🎬 MarkiTect Utils Capability Demonstration"
|
||||
@echo "==========================================="
|
||||
@echo ""
|
||||
@echo "String Utilities:"
|
||||
@$(MAKE) --no-print-directory utils-test-string
|
||||
@echo ""
|
||||
@echo "File Utilities:"
|
||||
@$(MAKE) --no-print-directory utils-test-file
|
||||
@echo ""
|
||||
@echo "Validation Utilities:"
|
||||
@$(MAKE) --no-print-directory utils-test-validation
|
||||
|
||||
# Meta information for capability discovery
|
||||
.PHONY: capability-info
|
||||
capability-info: ## Show capability information
|
||||
@echo "Name: $(CAPABILITY_NAME)"
|
||||
@echo "Description: $(CAPABILITY_DESCRIPTION)"
|
||||
@echo "Type: Pure library capability (zero external dependencies)"
|
||||
@echo "Main modules: string_utils, file_utils, validation_utils"
|
||||
@echo "Paradigm role: Reference implementation for ComposableRepositoryParadigm"
|
||||
@echo "Dependencies: None (Python standard library only)"
|
||||
@echo "Targets:"
|
||||
@$(MAKE) --no-print-directory help | grep "^ " | sed 's/^ / /'
|
||||
398
capabilities/release-management/MIGRATION_PLAN.md
Normal file
398
capabilities/release-management/MIGRATION_PLAN.md
Normal file
@@ -0,0 +1,398 @@
|
||||
# Release Management Capability Migration Plan
|
||||
|
||||
This document outlines the step-by-step plan to migrate all version management, packaging, and release publication functionality from the main MarkiTect project into the `release-management` capability.
|
||||
|
||||
## 📋 Migration Overview
|
||||
|
||||
### Current State
|
||||
Version management and release functionality is currently scattered across:
|
||||
- `release.py` (main release script)
|
||||
- `gitea/` directory (package registry client)
|
||||
- `VERSION_MANAGEMENT.md` (documentation)
|
||||
- `PACKAGE_PUBLISHING.md` (documentation)
|
||||
- Makefile targets (release automation)
|
||||
- setuptools-scm configuration in main `pyproject.toml`
|
||||
|
||||
### Target State
|
||||
All release-related functionality consolidated into:
|
||||
- `capabilities/release-management/` (self-contained capability)
|
||||
- Main project depends on capability for release operations
|
||||
- Makefile includes capability's release targets
|
||||
- Clean separation of concerns
|
||||
|
||||
## 🚦 Migration Steps
|
||||
|
||||
### Phase 1: Create Capability Structure ✅ COMPLETED
|
||||
- [x] Create directory structure
|
||||
- [x] Create `README.md` with comprehensive documentation
|
||||
- [x] Create `pyproject.toml` with full configuration
|
||||
- [x] Create main `__init__.py` with API exports
|
||||
- [x] Create `release.mk` for Makefile integration
|
||||
|
||||
### Phase 2: Move Core Files and Code
|
||||
|
||||
#### 2.1 Move Release Script
|
||||
**Source:** `release.py` → **Target:** `src/release_management/cli/main.py`
|
||||
|
||||
**Steps:**
|
||||
1. Copy `release.py` to `src/release_management/cli/main.py`
|
||||
2. Refactor into proper CLI module structure
|
||||
3. Extract core logic into separate modules:
|
||||
- `SimpleReleaseManager` → `src/release_management/core/manager.py`
|
||||
- Git operations → `src/release_management/git/manager.py`
|
||||
- Package building → `src/release_management/core/builder.py`
|
||||
- Publishing logic → `src/release_management/core/publisher.py`
|
||||
|
||||
**Refactoring Plan:**
|
||||
```python
|
||||
# Current: release.py (monolithic)
|
||||
class SimpleReleaseManager:
|
||||
# All functionality in one class
|
||||
|
||||
# Target: Modular architecture
|
||||
# src/release_management/core/manager.py
|
||||
class ReleaseManager:
|
||||
def __init__(self):
|
||||
self.git_manager = GitManager()
|
||||
self.builder = PackageBuilder()
|
||||
self.publisher = PublishManager()
|
||||
|
||||
# src/release_management/git/manager.py
|
||||
class GitManager:
|
||||
# Git-specific operations
|
||||
|
||||
# src/release_management/core/builder.py
|
||||
class PackageBuilder:
|
||||
# Package building operations
|
||||
|
||||
# src/release_management/core/publisher.py
|
||||
class PublishManager:
|
||||
# Publishing and upload operations
|
||||
```
|
||||
|
||||
#### 2.2 Move Gitea Package Registry
|
||||
**Source:** `gitea/` directory → **Target:** `src/release_management/registries/gitea/`
|
||||
|
||||
**File Mapping:**
|
||||
```
|
||||
gitea/config.py → src/release_management/registries/gitea/config.py
|
||||
gitea/exceptions.py → src/release_management/registries/gitea/exceptions.py
|
||||
gitea/package_registry.py → src/release_management/registries/gitea/registry.py
|
||||
gitea/__init__.py → src/release_management/registries/gitea/__init__.py
|
||||
```
|
||||
|
||||
**Refactoring:**
|
||||
1. Create base registry interface: `src/release_management/registries/base.py`
|
||||
2. Create registry factory: `src/release_management/registries/factory.py`
|
||||
3. Adapt GiteaPackageRegistry to implement base interface
|
||||
4. Add PyPI registry implementation for future use
|
||||
|
||||
#### 2.3 Move Documentation
|
||||
**Source:** Documentation files → **Target:** `docs/` directory
|
||||
|
||||
**File Mapping:**
|
||||
```
|
||||
VERSION_MANAGEMENT.md → capabilities/release-management/docs/version_management.md
|
||||
PACKAGE_PUBLISHING.md → capabilities/release-management/docs/package_publishing.md
|
||||
```
|
||||
|
||||
**Updates Required:**
|
||||
1. Update paths and references in documentation
|
||||
2. Add API reference documentation
|
||||
3. Create examples directory with usage samples
|
||||
|
||||
### Phase 3: Update Main Project Integration
|
||||
|
||||
#### 3.1 Update Main Makefile
|
||||
**Target:** `Makefile` in main project
|
||||
|
||||
**Changes:**
|
||||
1. Include release management Makefile:
|
||||
```makefile
|
||||
# Add at top of Makefile
|
||||
include capabilities/release-management/release.mk
|
||||
```
|
||||
|
||||
2. Update existing targets to use capability:
|
||||
```makefile
|
||||
# Old targets
|
||||
release-status:
|
||||
python release.py status
|
||||
|
||||
# New targets (provided by release.mk)
|
||||
release-status:
|
||||
release status
|
||||
```
|
||||
|
||||
3. Remove obsolete targets and replace with capability equivalents
|
||||
|
||||
#### 3.2 Update Main pyproject.toml
|
||||
**Target:** `pyproject.toml` in main project
|
||||
|
||||
**Changes:**
|
||||
1. Add release-management as dependency:
|
||||
```toml
|
||||
[project.dependencies]
|
||||
release-management = {path = "capabilities/release-management", develop = true}
|
||||
```
|
||||
|
||||
2. Keep setuptools-scm configuration:
|
||||
```toml
|
||||
[tool.setuptools_scm]
|
||||
write_to = "markitect/_version.py"
|
||||
```
|
||||
|
||||
3. Remove release-specific configuration (moved to capability)
|
||||
|
||||
#### 3.3 Update Main Project Structure
|
||||
**Cleanup Tasks:**
|
||||
1. Remove `release.py` from root
|
||||
2. Remove `gitea/` directory
|
||||
3. Move `VERSION_MANAGEMENT.md` and `PACKAGE_PUBLISHING.md` to capability
|
||||
4. Update `.gitignore` if needed
|
||||
5. Update documentation references
|
||||
|
||||
### Phase 4: Testing and Validation
|
||||
|
||||
#### 4.1 Create Capability Tests
|
||||
**Target:** `capabilities/release-management/tests/`
|
||||
|
||||
**Test Structure:**
|
||||
```
|
||||
tests/
|
||||
├── test_manager.py # ReleaseManager tests
|
||||
├── test_builder.py # PackageBuilder tests
|
||||
├── test_publisher.py # PublishManager tests
|
||||
├── test_git_manager.py # GitManager tests
|
||||
├── test_gitea_registry.py # GiteaRegistry tests
|
||||
├── test_cli.py # CLI command tests
|
||||
├── test_integration.py # End-to-end tests
|
||||
└── fixtures/
|
||||
└── sample_packages/ # Test package artifacts
|
||||
```
|
||||
|
||||
**Test Coverage Goals:**
|
||||
- Unit tests for all core classes
|
||||
- Integration tests for registry interactions
|
||||
- CLI command tests
|
||||
- Mock-based tests for external dependencies
|
||||
- Error handling and edge cases
|
||||
|
||||
#### 4.2 Validate Migration
|
||||
**Verification Steps:**
|
||||
1. Install capability: `pip install -e capabilities/release-management/`
|
||||
2. Run capability tests: `cd capabilities/release-management && pytest`
|
||||
3. Test CLI commands: `release --help`, `release status`
|
||||
4. Test Makefile integration: `make release-status`
|
||||
5. Perform test release workflow
|
||||
6. Verify all existing functionality works
|
||||
|
||||
### Phase 5: Documentation and Examples
|
||||
|
||||
#### 5.1 Create Examples
|
||||
**Target:** `capabilities/release-management/examples/`
|
||||
|
||||
**Example Scripts:**
|
||||
- `basic_release.py` - Simple release workflow
|
||||
- `custom_registry.py` - Adding new registry type
|
||||
- `ci_integration.py` - CI/CD pipeline integration
|
||||
- `configuration_examples.py` - Various configuration patterns
|
||||
|
||||
#### 5.2 Update Documentation
|
||||
**Documentation Tasks:**
|
||||
1. Update main project README to reference capability
|
||||
2. Create API reference documentation
|
||||
3. Add troubleshooting guide
|
||||
4. Document configuration options
|
||||
5. Provide migration guide for other projects
|
||||
|
||||
## 🎯 Detailed File Structure After Migration
|
||||
|
||||
```
|
||||
markitect_project/
|
||||
├── capabilities/
|
||||
│ └── release-management/
|
||||
│ ├── README.md ✅ CREATED
|
||||
│ ├── pyproject.toml ✅ CREATED
|
||||
│ ├── release.mk ✅ CREATED
|
||||
│ ├── MIGRATION_PLAN.md ✅ CREATED
|
||||
│ ├── src/release_management/
|
||||
│ │ ├── __init__.py ✅ CREATED
|
||||
│ │ ├── _version.py # Generated by setuptools-scm
|
||||
│ │ ├── core/
|
||||
│ │ │ ├── __init__.py
|
||||
│ │ │ ├── manager.py # ReleaseManager class
|
||||
│ │ │ ├── builder.py # PackageBuilder class
|
||||
│ │ │ └── publisher.py # PublishManager class
|
||||
│ │ ├── git/
|
||||
│ │ │ ├── __init__.py
|
||||
│ │ │ └── manager.py # GitManager class
|
||||
│ │ ├── registries/
|
||||
│ │ │ ├── __init__.py
|
||||
│ │ │ ├── base.py # Registry interface
|
||||
│ │ │ ├── factory.py # RegistryFactory
|
||||
│ │ │ ├── gitea/
|
||||
│ │ │ │ ├── __init__.py
|
||||
│ │ │ │ ├── config.py # From gitea/config.py
|
||||
│ │ │ │ ├── exceptions.py # From gitea/exceptions.py
|
||||
│ │ │ │ └── registry.py # From gitea/package_registry.py
|
||||
│ │ │ └── pypi/
|
||||
│ │ │ ├── __init__.py
|
||||
│ │ │ └── registry.py # PyPI registry implementation
|
||||
│ │ ├── cli/
|
||||
│ │ │ ├── __init__.py
|
||||
│ │ │ ├── main.py # From release.py
|
||||
│ │ │ ├── commands.py # CLI command implementations
|
||||
│ │ │ └── utils.py # CLI utilities
|
||||
│ │ └── utils/
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── version.py # Version utilities
|
||||
│ │ └── validation.py # Release validation
|
||||
│ ├── tests/
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── test_manager.py
|
||||
│ │ ├── test_builder.py
|
||||
│ │ ├── test_publisher.py
|
||||
│ │ ├── test_git_manager.py
|
||||
│ │ ├── test_gitea_registry.py
|
||||
│ │ ├── test_cli.py
|
||||
│ │ └── fixtures/
|
||||
│ ├── docs/
|
||||
│ │ ├── version_management.md # From VERSION_MANAGEMENT.md
|
||||
│ │ ├── package_publishing.md # From PACKAGE_PUBLISHING.md
|
||||
│ │ ├── api_reference.md
|
||||
│ │ └── troubleshooting.md
|
||||
│ └── examples/
|
||||
│ ├── basic_release.py
|
||||
│ ├── custom_registry.py
|
||||
│ └── ci_integration.py
|
||||
├── Makefile # Updated to include release.mk
|
||||
├── pyproject.toml # Updated with capability dependency
|
||||
└── markitect/
|
||||
└── _version.py # Still generated by setuptools-scm
|
||||
```
|
||||
|
||||
## 📦 Files to Remove After Migration
|
||||
|
||||
**Root Directory:**
|
||||
- [x] `release.py` (moved to capability CLI)
|
||||
- [x] `gitea/` directory (moved to capability registries)
|
||||
- [x] `VERSION_MANAGEMENT.md` (moved to capability docs)
|
||||
- [x] `PACKAGE_PUBLISHING.md` (moved to capability docs)
|
||||
|
||||
**Makefile Targets to Update:**
|
||||
- Replace individual release targets with capability imports
|
||||
- Keep legacy aliases for backward compatibility
|
||||
- Update target documentation
|
||||
|
||||
## 🔧 API Design for Capability
|
||||
|
||||
### Main API Classes
|
||||
|
||||
```python
|
||||
# Primary entry point
|
||||
from release_management import ReleaseManager
|
||||
|
||||
manager = ReleaseManager()
|
||||
success = manager.publish_release("1.0.0")
|
||||
|
||||
# Component access
|
||||
from release_management import PackageBuilder, PublishManager, GitManager
|
||||
|
||||
builder = PackageBuilder()
|
||||
builder.build_packages()
|
||||
|
||||
publisher = PublishManager()
|
||||
publisher.upload_packages("gitea")
|
||||
|
||||
git = GitManager()
|
||||
git.create_tag("v1.0.0")
|
||||
|
||||
# Registry access
|
||||
from release_management import RegistryFactory
|
||||
|
||||
registry = RegistryFactory.create("gitea")
|
||||
registry.upload_package("package.whl")
|
||||
```
|
||||
|
||||
### CLI Interface
|
||||
|
||||
```bash
|
||||
# Main commands
|
||||
release status # Show release status
|
||||
release validate # Validate release state
|
||||
release tag --version 1.0.0 # Create git tag
|
||||
release build # Build packages
|
||||
release publish --version 1.0.0 # Complete release workflow
|
||||
release upload --registry gitea # Upload existing packages
|
||||
|
||||
# Registry management
|
||||
release registry-info --registry gitea
|
||||
release registry-list
|
||||
```
|
||||
|
||||
## 🚀 Benefits After Migration
|
||||
|
||||
### For MarkiTect Project
|
||||
1. **Cleaner main project**: Release logic separated from core functionality
|
||||
2. **Better maintainability**: Clear module boundaries and responsibilities
|
||||
3. **Easier testing**: Isolated testing of release functionality
|
||||
4. **Reduced complexity**: Main project focuses on core features
|
||||
|
||||
### For Release Management Capability
|
||||
1. **Reusability**: Can be used in other Python projects
|
||||
2. **Independent development**: Own release cycle and versioning
|
||||
3. **Comprehensive testing**: Full test coverage for release functionality
|
||||
4. **Documentation**: Dedicated documentation and examples
|
||||
5. **Extensibility**: Easy to add new registries and features
|
||||
|
||||
### For Users/Developers
|
||||
1. **Consistent interface**: Same commands across all projects using capability
|
||||
2. **Better documentation**: Comprehensive guides and API reference
|
||||
3. **More features**: Enhanced functionality and registry support
|
||||
4. **Easier contribution**: Clear structure for adding features
|
||||
|
||||
## 🎯 Success Criteria
|
||||
|
||||
Migration is considered successful when:
|
||||
1. ✅ All existing release functionality works through capability
|
||||
2. ✅ Main project Makefile targets work unchanged
|
||||
3. ✅ CLI commands provide same functionality as current `release.py`
|
||||
4. ✅ All tests pass for both capability and main project
|
||||
5. ✅ Documentation is complete and accurate
|
||||
6. ✅ Examples demonstrate capability usage
|
||||
7. ✅ No regression in release workflow functionality
|
||||
|
||||
## 🔄 Rollback Plan
|
||||
|
||||
If migration issues arise:
|
||||
1. **Keep backup**: Current files backed up before migration
|
||||
2. **Incremental approach**: Migrate one component at a time
|
||||
3. **Parallel operation**: Keep old and new systems running during transition
|
||||
4. **Quick revert**: Ability to restore original structure if needed
|
||||
|
||||
**Rollback Steps:**
|
||||
1. Remove capability dependency from main `pyproject.toml`
|
||||
2. Restore backed up files (`release.py`, `gitea/`, docs)
|
||||
3. Restore original Makefile targets
|
||||
4. Remove capability directory
|
||||
5. Test that original functionality works
|
||||
|
||||
## 📅 Migration Timeline
|
||||
|
||||
**Estimated Duration:** 1-2 weeks for complete migration
|
||||
|
||||
**Phase Breakdown:**
|
||||
- **Phase 1 (Directory Structure):** ✅ COMPLETED
|
||||
- **Phase 2 (Code Migration):** 2-3 days
|
||||
- **Phase 3 (Integration):** 1-2 days
|
||||
- **Phase 4 (Testing):** 2-3 days
|
||||
- **Phase 5 (Documentation):** 1-2 days
|
||||
|
||||
**Critical Path:**
|
||||
1. Code refactoring and migration
|
||||
2. Testing and validation
|
||||
3. Documentation updates
|
||||
4. Final integration testing
|
||||
|
||||
This migration plan ensures a systematic, low-risk transition to the capability-based architecture while maintaining all existing functionality and improving the overall project structure.
|
||||
231
capabilities/release-management/Makefile
Normal file
231
capabilities/release-management/Makefile
Normal file
@@ -0,0 +1,231 @@
|
||||
# Release Management Capability Makefile
|
||||
# Provides release management targets for any Python project
|
||||
|
||||
# Capability metadata
|
||||
CAPABILITY_NAME := release-management
|
||||
CAPABILITY_DESCRIPTION := Comprehensive release management for Python projects
|
||||
|
||||
# Default target
|
||||
.PHONY: help
|
||||
help: ## Show release management help
|
||||
@echo "📦 Release Management Capability"
|
||||
@echo "================================"
|
||||
@echo ""
|
||||
@echo "Status & Validation:"
|
||||
@echo " release-status Show current release status and version information"
|
||||
@echo " release-validate Validate repository state for release readiness"
|
||||
@echo " release-registry-info Show package registry information and status"
|
||||
@echo ""
|
||||
@echo "Git Tag Management:"
|
||||
@echo " release-tag VERSION=x.y.z Create git tag for version"
|
||||
@echo ""
|
||||
@echo "Package Building:"
|
||||
@echo " release-build Build release packages using setuptools-scm"
|
||||
@echo " release-clean Clean build artifacts and temporary files"
|
||||
@echo ""
|
||||
@echo "Publishing Workflows:"
|
||||
@echo " release-publish VERSION=x.y.z Complete release workflow (tag + build)"
|
||||
@echo " release-publish-gitea VERSION=x.y.z Complete release + Gitea upload"
|
||||
@echo " release-publish-pypi VERSION=x.y.z Complete release + PyPI upload"
|
||||
@echo ""
|
||||
@echo "Upload Existing Packages:"
|
||||
@echo " release-upload-gitea Upload existing packages to Gitea registry"
|
||||
@echo " release-upload-pypi Upload existing packages to PyPI"
|
||||
@echo " release-upload-testpypi Upload existing packages to Test PyPI"
|
||||
@echo ""
|
||||
@echo "Dry Run Options:"
|
||||
@echo " release-publish-dry-run VERSION=x.y.z Dry run of release workflow"
|
||||
@echo " release-upload-dry-run Dry run of package upload"
|
||||
@echo ""
|
||||
@echo "Development & Setup:"
|
||||
@echo " release-management-install Install release management capability"
|
||||
@echo " release-management-install-dev Install with development dependencies"
|
||||
@echo " release-management-test Run capability tests"
|
||||
@echo " release-management-help Show CLI help"
|
||||
|
||||
# Check if release management capability is available
|
||||
RELEASE_CLI := $(shell command -v release 2> /dev/null)
|
||||
|
||||
# Status and Information
|
||||
.PHONY: release-status
|
||||
release-status: ## Show current release status and version information
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@echo " Install with: pip install -e capabilities/release-management/"
|
||||
@exit 1
|
||||
endif
|
||||
release status
|
||||
|
||||
.PHONY: release-validate
|
||||
release-validate: ## Validate repository state for release readiness
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release validate
|
||||
|
||||
.PHONY: release-registry-info
|
||||
release-registry-info: ## Show package registry information and status
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release registry-info
|
||||
|
||||
# Git Tag Management
|
||||
.PHONY: release-tag
|
||||
release-tag: ## Create git tag for version (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-tag VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release tag --version $(VERSION)
|
||||
|
||||
# Package Building
|
||||
.PHONY: release-build
|
||||
release-build: ## Build release packages using setuptools-scm
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release build
|
||||
|
||||
.PHONY: release-clean
|
||||
release-clean: ## Clean build artifacts and temporary files
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release clean
|
||||
|
||||
# Publishing Workflows
|
||||
.PHONY: release-publish
|
||||
release-publish: ## Complete release workflow: tag + build (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release publish --version $(VERSION)
|
||||
|
||||
.PHONY: release-publish-gitea
|
||||
release-publish-gitea: ## Complete release workflow + Gitea upload (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish-gitea VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release publish --version $(VERSION) --registry gitea
|
||||
|
||||
.PHONY: release-publish-pypi
|
||||
release-publish-pypi: ## Complete release workflow + PyPI upload (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish-pypi VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release publish --version $(VERSION) --registry pypi
|
||||
|
||||
# Upload Existing Packages
|
||||
.PHONY: release-upload-gitea
|
||||
release-upload-gitea: ## Upload existing packages to Gitea registry
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release upload --registry gitea
|
||||
|
||||
.PHONY: release-upload-pypi
|
||||
release-upload-pypi: ## Upload existing packages to PyPI
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release upload --registry pypi
|
||||
|
||||
.PHONY: release-upload-testpypi
|
||||
release-upload-testpypi: ## Upload existing packages to Test PyPI
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release upload --registry testpypi
|
||||
|
||||
# Dry Run Options
|
||||
.PHONY: release-publish-dry-run
|
||||
release-publish-dry-run: ## Dry run of complete release workflow (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish-dry-run VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release publish --version $(VERSION) --dry-run
|
||||
|
||||
.PHONY: release-upload-dry-run
|
||||
release-upload-dry-run: ## Dry run of package upload to default registry
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
release upload --dry-run
|
||||
|
||||
# Development and Setup
|
||||
.PHONY: release-management-install
|
||||
release-management-install: ## Install release management capability
|
||||
pip install -e capabilities/release-management/
|
||||
|
||||
.PHONY: release-management-install-dev
|
||||
release-management-install-dev: ## Install release management capability with dev dependencies
|
||||
pip install -e "capabilities/release-management/[dev]"
|
||||
|
||||
.PHONY: release-management-test
|
||||
release-management-test: ## Run release management capability tests
|
||||
cd capabilities/release-management && pytest tests/
|
||||
|
||||
.PHONY: release-management-help
|
||||
release-management-help: ## Show release management CLI help
|
||||
ifndef RELEASE_CLI
|
||||
@echo "❌ Release management capability not installed"
|
||||
@echo " Install with: make release-management-install"
|
||||
@exit 1
|
||||
endif
|
||||
release --help
|
||||
|
||||
# Convenience aliases
|
||||
.PHONY: release-upload
|
||||
release-upload: release-upload-gitea ## Upload packages to default registry (gitea)
|
||||
|
||||
.PHONY: package
|
||||
package: release-build ## Build packages (alias for release-build)
|
||||
|
||||
.PHONY: publish
|
||||
publish: ## Publish release to default registry (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make publish VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
@make release-publish-gitea VERSION=$(VERSION)
|
||||
|
||||
# Meta information for capability discovery
|
||||
.PHONY: capability-info
|
||||
capability-info: ## Show capability information
|
||||
@echo "Name: $(CAPABILITY_NAME)"
|
||||
@echo "Description: $(CAPABILITY_DESCRIPTION)"
|
||||
@echo "Targets:"
|
||||
@$(MAKE) --no-print-directory help | grep "^ " | sed 's/^ / /'
|
||||
334
capabilities/release-management/README.md
Normal file
334
capabilities/release-management/README.md
Normal file
@@ -0,0 +1,334 @@
|
||||
# Release Management Capability
|
||||
|
||||
A self-contained capability for version management, package building, and release publication with Git and package registry integration.
|
||||
|
||||
## Overview
|
||||
|
||||
The release-management capability provides comprehensive release automation for Python projects using setuptools-scm for version management and supporting multiple publication targets including Gitea package registries.
|
||||
|
||||
## Features
|
||||
|
||||
- **Automatic Version Management**: Git tag-based versioning with setuptools-scm
|
||||
- **Package Building**: Wheel and source distribution generation
|
||||
- **Release Automation**: Complete release workflow from validation to publication
|
||||
- **Multi-Platform Publishing**: Support for Gitea, GitHub, and other package registries
|
||||
- **Fallback Publishing**: Release assets when package registries unavailable
|
||||
- **CLI Integration**: Command-line tools for release management
|
||||
- **Makefile Integration**: Convenient targets for common release tasks
|
||||
|
||||
## Architecture
|
||||
|
||||
### Core Components
|
||||
|
||||
#### `ReleaseManager`
|
||||
Main orchestrator for release workflows, handling:
|
||||
- Release state validation
|
||||
- Git tag creation and management
|
||||
- Package building coordination
|
||||
- Publication orchestration
|
||||
|
||||
#### `PackageBuilder`
|
||||
Responsible for package generation:
|
||||
- setuptools-scm integration
|
||||
- Wheel and source distribution building
|
||||
- Build artifact management
|
||||
|
||||
#### `PublishManager`
|
||||
Handles package publication:
|
||||
- Multiple registry support (Gitea, PyPI, etc.)
|
||||
- Fallback mechanisms (release assets)
|
||||
- Upload progress tracking
|
||||
|
||||
#### `GitManager`
|
||||
Git operations for releases:
|
||||
- Tag creation and validation
|
||||
- Repository state checking
|
||||
- Branch and commit management
|
||||
|
||||
### Package Registry Support
|
||||
|
||||
#### `GiteaRegistry`
|
||||
Gitea-specific package registry client:
|
||||
- PyPI-compatible registry uploads
|
||||
- Release asset fallback
|
||||
- Authentication handling
|
||||
|
||||
#### `RegistryFactory`
|
||||
Factory for creating registry clients:
|
||||
- Auto-detection of registry types
|
||||
- Configuration management
|
||||
- Extensible for new registries
|
||||
|
||||
## API Reference
|
||||
|
||||
### Core Classes
|
||||
|
||||
#### `ReleaseManager`
|
||||
```python
|
||||
from release_management import ReleaseManager
|
||||
|
||||
manager = ReleaseManager()
|
||||
|
||||
# Validate release readiness
|
||||
is_valid, issues = manager.validate_release_state()
|
||||
|
||||
# Create complete release
|
||||
success = manager.publish_release("0.8.0")
|
||||
|
||||
# Publish with specific registry
|
||||
success = manager.publish_with_registry("0.8.0", registry_type="gitea")
|
||||
```
|
||||
|
||||
#### `PackageBuilder`
|
||||
```python
|
||||
from release_management import PackageBuilder
|
||||
|
||||
builder = PackageBuilder()
|
||||
|
||||
# Build packages
|
||||
builder.build_packages()
|
||||
|
||||
# Get current version
|
||||
version = builder.get_current_version()
|
||||
|
||||
# Clean build artifacts
|
||||
builder.clean_build()
|
||||
```
|
||||
|
||||
#### `PublishManager`
|
||||
```python
|
||||
from release_management import PublishManager
|
||||
|
||||
publisher = PublishManager()
|
||||
|
||||
# Publish to registry
|
||||
success = publisher.publish_packages("gitea", dry_run=True)
|
||||
|
||||
# Upload specific files
|
||||
success = publisher.upload_file("dist/package.whl", "gitea")
|
||||
```
|
||||
|
||||
### CLI Commands
|
||||
|
||||
#### `release`
|
||||
Main release command with subcommands:
|
||||
|
||||
```bash
|
||||
# Show release status
|
||||
release status
|
||||
|
||||
# Validate release readiness
|
||||
release validate
|
||||
|
||||
# Create git tag
|
||||
release tag --version 0.8.0
|
||||
|
||||
# Build packages
|
||||
release build
|
||||
|
||||
# Complete release workflow
|
||||
release publish --version 0.8.0
|
||||
|
||||
# Publish to specific registry
|
||||
release publish --version 0.8.0 --registry gitea
|
||||
|
||||
# Upload existing packages
|
||||
release upload --registry gitea
|
||||
|
||||
# Show registry information
|
||||
release registry-info --registry gitea
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
#### Release Configuration
|
||||
Configure release behavior in `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.release-management]
|
||||
# Default registry for publishing
|
||||
default_registry = "gitea"
|
||||
|
||||
# Validation requirements
|
||||
require_clean_tree = true
|
||||
require_main_branch = true
|
||||
|
||||
# Package building
|
||||
build_wheel = true
|
||||
build_sdist = true
|
||||
clean_before_build = true
|
||||
|
||||
# Registry configurations
|
||||
[tool.release-management.registries.gitea]
|
||||
url = "http://92.205.130.254:32166"
|
||||
owner = "coulomb"
|
||||
repo = "markitect_project"
|
||||
auth_token_env = "GITEA_API_TOKEN"
|
||||
|
||||
[tool.release-management.registries.pypi]
|
||||
url = "https://upload.pypi.org/legacy/"
|
||||
auth_token_env = "PYPI_TOKEN"
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
Install as an editable dependency:
|
||||
|
||||
```bash
|
||||
pip install -e capabilities/release-management/
|
||||
```
|
||||
|
||||
Or with development dependencies:
|
||||
|
||||
```bash
|
||||
pip install -e "capabilities/release-management/[dev]"
|
||||
```
|
||||
|
||||
## Development Setup
|
||||
|
||||
```bash
|
||||
cd capabilities/release-management/
|
||||
pip install -e ".[dev]"
|
||||
pytest tests/
|
||||
```
|
||||
|
||||
## Integration with Main Project
|
||||
|
||||
The main project integrates with this capability through:
|
||||
|
||||
### Makefile Integration
|
||||
```makefile
|
||||
# Include release management targets
|
||||
include capabilities/release-management/release.mk
|
||||
|
||||
# Or call capability directly
|
||||
release-status:
|
||||
release status
|
||||
|
||||
release-publish:
|
||||
release publish --version $(VERSION)
|
||||
```
|
||||
|
||||
### Setup Configuration
|
||||
In main project's `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.setuptools_scm]
|
||||
write_to = "markitect/_version.py"
|
||||
|
||||
[tool.release-management]
|
||||
default_registry = "gitea"
|
||||
```
|
||||
|
||||
## Migration Plan
|
||||
|
||||
This capability consolidates the following existing components:
|
||||
|
||||
### Files to Move
|
||||
1. **`release.py`** → `src/release_management/cli/main.py`
|
||||
2. **`gitea/`** directory → `src/release_management/registries/gitea/`
|
||||
3. **VERSION_MANAGEMENT.md** → `docs/version_management.md`
|
||||
4. **PACKAGE_PUBLISHING.md** → `docs/package_publishing.md`
|
||||
5. **Makefile release targets** → `release.mk`
|
||||
|
||||
### New Structure
|
||||
```
|
||||
capabilities/release-management/
|
||||
├── README.md
|
||||
├── pyproject.toml
|
||||
├── release.mk # Makefile integration
|
||||
├── src/release_management/
|
||||
│ ├── __init__.py # Main API exports
|
||||
│ ├── core/
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── manager.py # ReleaseManager class
|
||||
│ │ ├── builder.py # PackageBuilder class
|
||||
│ │ └── publisher.py # PublishManager class
|
||||
│ ├── git/
|
||||
│ │ ├── __init__.py
|
||||
│ │ └── manager.py # GitManager class
|
||||
│ ├── registries/
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── factory.py # RegistryFactory
|
||||
│ │ ├── base.py # Registry interface
|
||||
│ │ ├── gitea/
|
||||
│ │ │ ├── __init__.py
|
||||
│ │ │ ├── registry.py # GiteaRegistry
|
||||
│ │ │ ├── config.py # GiteaConfig
|
||||
│ │ │ └── exceptions.py # GiteaError
|
||||
│ │ └── pypi/
|
||||
│ │ ├── __init__.py
|
||||
│ │ └── registry.py # PyPIRegistry
|
||||
│ ├── cli/
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── main.py # Main CLI entry point
|
||||
│ │ ├── commands.py # CLI command implementations
|
||||
│ │ └── utils.py # CLI utilities
|
||||
│ └── utils/
|
||||
│ ├── __init__.py
|
||||
│ ├── version.py # Version management utilities
|
||||
│ └── validation.py # Release validation utilities
|
||||
├── tests/
|
||||
│ ├── __init__.py
|
||||
│ ├── test_manager.py
|
||||
│ ├── test_builder.py
|
||||
│ ├── test_publisher.py
|
||||
│ ├── test_git_manager.py
|
||||
│ ├── test_gitea_registry.py
|
||||
│ └── fixtures/
|
||||
│ └── sample_packages/
|
||||
├── docs/
|
||||
│ ├── version_management.md
|
||||
│ ├── package_publishing.md
|
||||
│ ├── api_reference.md
|
||||
│ └── examples/
|
||||
└── examples/
|
||||
├── basic_release.py
|
||||
├── custom_registry.py
|
||||
└── ci_integration.py
|
||||
```
|
||||
|
||||
## Benefits of Capability Structure
|
||||
|
||||
### Modularity
|
||||
- **Self-contained**: Independent testing and development
|
||||
- **Reusable**: Can be used in other projects
|
||||
- **Focused**: Single responsibility for release management
|
||||
|
||||
### Maintainability
|
||||
- **Clear boundaries**: Well-defined API surface
|
||||
- **Extensible**: Easy to add new registries or features
|
||||
- **Testable**: Comprehensive test suite in isolation
|
||||
|
||||
### Integration
|
||||
- **CLI integration**: Direct command-line access
|
||||
- **Makefile integration**: Convenient targets for workflows
|
||||
- **Configuration**: Centralized in pyproject.toml
|
||||
|
||||
## Dependencies
|
||||
|
||||
### Core Dependencies
|
||||
- `click>=8.0.0` - CLI framework
|
||||
- `requests>=2.25.0` - HTTP client for registries
|
||||
- `setuptools-scm>=8.0.0` - Version management
|
||||
- `build>=0.8.0` - Package building
|
||||
- `packaging>=21.0` - Version parsing and validation
|
||||
|
||||
### Development Dependencies
|
||||
- `pytest>=7.0.0` - Testing framework
|
||||
- `pytest-cov>=4.0.0` - Coverage reporting
|
||||
- `responses>=0.20.0` - HTTP mocking for tests
|
||||
- `black>=22.0.0` - Code formatting
|
||||
- `flake8>=5.0.0` - Code linting
|
||||
- `mypy>=1.0.0` - Type checking
|
||||
|
||||
## Compliance
|
||||
|
||||
This capability follows the ComposableRepositoryParadigm:
|
||||
- ✅ Src layout (PEP 660 compliant)
|
||||
- ✅ Unidirectional dependencies
|
||||
- ✅ Self-contained with own tests
|
||||
- ✅ Independent configuration
|
||||
- ✅ Clean API boundaries
|
||||
- ✅ Type safety with mypy
|
||||
- ✅ Comprehensive documentation
|
||||
229
capabilities/release-management/docs/package_publishing.md
Normal file
229
capabilities/release-management/docs/package_publishing.md
Normal file
@@ -0,0 +1,229 @@
|
||||
# Package Publishing Guide
|
||||
|
||||
This guide covers building, publishing, and distributing MarkiTect packages using our Gitea package registry and setuptools-scm version management.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Gitea API Token**: Set the `GITEA_API_TOKEN` environment variable with your Gitea API token
|
||||
2. **Repository Access**: The token must have write access to the repository's package registry
|
||||
|
||||
## Quick Setup
|
||||
|
||||
```bash
|
||||
# Set your Gitea API token
|
||||
export GITEA_API_TOKEN="your_gitea_api_token_here"
|
||||
|
||||
# Or add it to your shell profile
|
||||
echo "export GITEA_API_TOKEN=your_token" >> ~/.bashrc
|
||||
```
|
||||
|
||||
## Package Building
|
||||
|
||||
### Quick Package Building
|
||||
|
||||
```bash
|
||||
# Build distribution packages (recommended)
|
||||
make package
|
||||
|
||||
# This will:
|
||||
# 1. Show current version (setuptools-scm)
|
||||
# 2. Clean previous builds
|
||||
# 3. Build both wheel and source distribution
|
||||
# 4. Show package details
|
||||
```
|
||||
|
||||
### Manual Building
|
||||
|
||||
```bash
|
||||
# Standard build
|
||||
make build
|
||||
|
||||
# Using release script
|
||||
make release-build
|
||||
python release.py build
|
||||
|
||||
# Manual Python build
|
||||
python -m build
|
||||
```
|
||||
|
||||
## Publishing Workflow
|
||||
|
||||
### Complete Release + Publishing
|
||||
|
||||
```bash
|
||||
# 🚀 ONE-COMMAND RELEASE (recommended)
|
||||
make release-publish-gitea VERSION=0.8.0
|
||||
|
||||
# This complete workflow:
|
||||
# 1. Creates git tag v0.8.0
|
||||
# 2. Builds packages (setuptools-scm uses tag for version 0.8.0)
|
||||
# 3. Uploads both wheel and source distribution to Gitea
|
||||
```
|
||||
|
||||
### Step-by-Step Release
|
||||
|
||||
```bash
|
||||
# 1. Check current status
|
||||
make release-status
|
||||
|
||||
# 2. Validate release readiness
|
||||
make release-validate
|
||||
|
||||
# 3. Create git tag
|
||||
make release-tag VERSION=0.8.0
|
||||
|
||||
# 4. Build packages (version auto-detected from tag)
|
||||
make release-build
|
||||
|
||||
# 5. Upload to Gitea registry
|
||||
make release-upload-gitea
|
||||
```
|
||||
|
||||
### Development Package Testing
|
||||
|
||||
```bash
|
||||
# Build current development version
|
||||
make package
|
||||
|
||||
# Upload development packages for testing
|
||||
python release.py upload --dry-run # Test first
|
||||
python release.py upload # Upload development version
|
||||
```
|
||||
|
||||
## Registry Management
|
||||
|
||||
### Check Registry Status
|
||||
|
||||
```bash
|
||||
# Comprehensive registry information
|
||||
make release-registry
|
||||
|
||||
# Shows:
|
||||
# - Authentication status
|
||||
# - Registry URLs
|
||||
# - Existing packages
|
||||
# - Configuration details
|
||||
```
|
||||
|
||||
### Upload Existing Packages
|
||||
|
||||
```bash
|
||||
# Upload packages in dist/ folder
|
||||
make release-upload-gitea
|
||||
|
||||
# With dry-run testing
|
||||
python release.py upload --dry-run
|
||||
python release.py upload
|
||||
```
|
||||
|
||||
### Traditional Release (Git tags only)
|
||||
|
||||
```bash
|
||||
# Standard release without Gitea upload
|
||||
make release-publish VERSION=0.8.0
|
||||
```
|
||||
|
||||
## Available Commands
|
||||
|
||||
### Makefile Targets
|
||||
|
||||
- `make release-registry` - Show Gitea package registry information
|
||||
- `make release-upload-gitea` - Upload existing packages to Gitea
|
||||
- `make release-publish-gitea VERSION=x.y.z` - Complete release + Gitea upload
|
||||
|
||||
### Python Script Commands
|
||||
|
||||
- `python release.py registry` - Show registry information
|
||||
- `python release.py upload` - Upload packages to Gitea
|
||||
- `python release.py upload --dry-run` - Test upload without uploading
|
||||
- `python release.py publish --version x.y.z --to-gitea` - Release with Gitea upload
|
||||
|
||||
## Registry Information
|
||||
|
||||
- **Gitea URL**: http://92.205.130.254:32166
|
||||
- **Repository**: coulomb/markitect_project
|
||||
- **PyPI Registry URL**: http://92.205.130.254:32166/api/packages/coulomb/pypi
|
||||
- **Package List URL**: http://92.205.130.254:32166/api/v1/packages/coulomb
|
||||
|
||||
## Installing from Gitea Registry
|
||||
|
||||
Once packages are published, users can install them using:
|
||||
|
||||
```bash
|
||||
# Install from Gitea registry
|
||||
pip install markitect --extra-index-url http://92.205.130.254:32166/api/packages/coulomb/pypi/simple/
|
||||
|
||||
# Or configure pip permanently
|
||||
mkdir -p ~/.pip
|
||||
cat >> ~/.pip/pip.conf << EOF
|
||||
[global]
|
||||
extra-index-url = http://92.205.130.254:32166/api/packages/coulomb/pypi/simple/
|
||||
EOF
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
### Automatic Package Detection
|
||||
|
||||
The system automatically detects and uploads:
|
||||
- **Wheel files** (`.whl`) - Binary distributions
|
||||
- **Source distributions** (`.tar.gz`) - Source code packages
|
||||
|
||||
### Version Management with setuptools-scm
|
||||
|
||||
Versions are automatically determined by git tags:
|
||||
- `v0.8.0` tag → `0.8.0` package version
|
||||
- Development commits → `0.8.1.dev3+gcommithash` versions
|
||||
|
||||
### Error Handling
|
||||
|
||||
The system provides detailed error messages for:
|
||||
- Missing authentication tokens
|
||||
- Network connectivity issues
|
||||
- Package upload failures
|
||||
- Invalid package formats
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Authentication Issues
|
||||
|
||||
```bash
|
||||
# Check if token is set
|
||||
echo $GITEA_API_TOKEN
|
||||
|
||||
# Test authentication
|
||||
python release.py registry
|
||||
```
|
||||
|
||||
### Upload Failures
|
||||
|
||||
```bash
|
||||
# Test with dry run first
|
||||
python release.py upload --dry-run
|
||||
|
||||
# Check package files exist
|
||||
ls -la dist/
|
||||
|
||||
# Rebuild packages if needed
|
||||
make release-build
|
||||
```
|
||||
|
||||
### Network Issues
|
||||
|
||||
- Ensure Gitea server is accessible: `ping 92.205.130.254`
|
||||
- Check firewall and proxy settings
|
||||
- Verify Gitea is running on port 32166
|
||||
|
||||
## Development
|
||||
|
||||
The package registry functionality is implemented in:
|
||||
- `gitea/package_registry.py` - Main package registry client
|
||||
- `release.py` - Release script with Gitea integration
|
||||
- `Makefile` - Convenient targets for package management
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Never commit API tokens to version control
|
||||
- Use environment variables or secure credential storage
|
||||
- Tokens should have minimal required permissions
|
||||
- Rotate tokens regularly for security
|
||||
309
capabilities/release-management/docs/version_management.md
Normal file
309
capabilities/release-management/docs/version_management.md
Normal file
@@ -0,0 +1,309 @@
|
||||
# Version Management Guide
|
||||
|
||||
MarkiTect uses **setuptools-scm** for automatic version management based on git tags. This eliminates manual version bumping and ensures versions are always in sync with git history.
|
||||
|
||||
## How It Works
|
||||
|
||||
### Version Calculation
|
||||
|
||||
setuptools-scm automatically determines the version based on:
|
||||
|
||||
1. **Git Tags**: The latest tag matching `v*` pattern (e.g., `v0.7.0`)
|
||||
2. **Commits Since Tag**: Number of commits since the latest tag
|
||||
3. **Current Commit**: Short commit hash
|
||||
4. **Dirty State**: Whether there are uncommitted changes
|
||||
|
||||
### Version Examples
|
||||
|
||||
| Git State | Version Output |
|
||||
|-----------|----------------|
|
||||
| `v0.7.0` tag (clean) | `0.7.0` |
|
||||
| `v0.7.0` + 3 commits | `0.7.1.dev3+g1a2b3c4d` |
|
||||
| `v0.7.0` + 3 commits + dirty | `0.7.1.dev3+g1a2b3c4d.d20251108` |
|
||||
| No tags + 10 commits | `0.1.dev10+g5e6f7g8h` |
|
||||
|
||||
## Version Commands
|
||||
|
||||
### Check Current Version
|
||||
|
||||
```bash
|
||||
# Quick version check
|
||||
python -m setuptools_scm
|
||||
|
||||
# Detailed version information
|
||||
make release-status
|
||||
python release.py status
|
||||
```
|
||||
|
||||
### Access Version in Code
|
||||
|
||||
```python
|
||||
from markitect.__version__ import __version__
|
||||
print(f"MarkiTect version: {__version__}")
|
||||
```
|
||||
|
||||
## Creating Releases
|
||||
|
||||
### Release Workflow
|
||||
|
||||
1. **Ensure Clean State**:
|
||||
```bash
|
||||
git status # Should be clean
|
||||
git pull # Latest changes
|
||||
```
|
||||
|
||||
2. **Validate Release Readiness**:
|
||||
```bash
|
||||
make release-validate
|
||||
```
|
||||
|
||||
3. **Create Release**:
|
||||
```bash
|
||||
# Standard release
|
||||
make release-publish VERSION=0.8.0
|
||||
|
||||
# Release with Gitea publishing
|
||||
make release-publish-gitea VERSION=0.8.0
|
||||
```
|
||||
|
||||
### Version Naming Conventions
|
||||
|
||||
Follow [Semantic Versioning](https://semver.org/):
|
||||
|
||||
- **Major Version** (`1.0.0`): Breaking changes
|
||||
- **Minor Version** (`0.8.0`): New features (backward compatible)
|
||||
- **Patch Version** (`0.7.1`): Bug fixes (backward compatible)
|
||||
- **Pre-release** (`0.8.0-rc1`): Release candidates
|
||||
- **Development** (`0.8.1.dev3+hash`): Automatic between releases
|
||||
|
||||
### Git Tag Format
|
||||
|
||||
Always use the format `vX.Y.Z`:
|
||||
|
||||
```bash
|
||||
# Correct
|
||||
git tag v0.8.0
|
||||
git tag v1.0.0-rc1
|
||||
|
||||
# Incorrect
|
||||
git tag 0.8.0 # Missing 'v' prefix
|
||||
git tag version-0.8.0 # Wrong format
|
||||
```
|
||||
|
||||
## Development Versions
|
||||
|
||||
### Understanding Development Versions
|
||||
|
||||
Between releases, setuptools-scm generates development versions:
|
||||
|
||||
```
|
||||
0.7.1.dev3+g1a2b3c4d.d20251108
|
||||
│ │ │ │ │ │
|
||||
│ │ │ │ │ └── Date (dirty state)
|
||||
│ │ │ │ └─────────── Commit hash
|
||||
│ │ │ └───────────── Commits since tag
|
||||
│ │ └──────────────── Dev marker
|
||||
│ └─────────────────── Next version
|
||||
└─────────────────────── Base version
|
||||
```
|
||||
|
||||
### Working with Development Versions
|
||||
|
||||
Development versions are automatically:
|
||||
- **Sorted correctly** by pip (dev versions < release versions)
|
||||
- **Excluded from releases** (only tagged versions are released)
|
||||
- **Unique** (each commit has a different version)
|
||||
|
||||
## Configuration
|
||||
|
||||
### setuptools-scm Configuration
|
||||
|
||||
Configuration in `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.setuptools_scm]
|
||||
write_to = "markitect/_version.py"
|
||||
```
|
||||
|
||||
### Version File Generation
|
||||
|
||||
setuptools-scm automatically generates `markitect/_version.py`:
|
||||
|
||||
```python
|
||||
# Auto-generated - do not edit
|
||||
__version__ = "0.7.1.dev3+g1a2b3c4d"
|
||||
__version_tuple__ = (0, 7, 1, 'dev3', 'g1a2b3c4d')
|
||||
```
|
||||
|
||||
This file is:
|
||||
- ✅ **Auto-generated** during package builds
|
||||
- ✅ **Added to .gitignore** (never committed)
|
||||
- ✅ **Available at runtime** for version checks
|
||||
|
||||
## Release Branches
|
||||
|
||||
### Main Branch Strategy
|
||||
|
||||
MarkiTect uses a simple branching strategy:
|
||||
|
||||
- **`main`**: Primary development branch
|
||||
- **Tags**: Mark release points (`v0.7.0`, `v0.8.0`)
|
||||
- **Feature branches**: Merged via pull requests
|
||||
|
||||
### Release Process
|
||||
|
||||
1. **Development** happens on `main`
|
||||
2. **Release tags** created on `main` when ready
|
||||
3. **Hotfix tags** can be created on older commits if needed
|
||||
|
||||
```bash
|
||||
# Standard release from main
|
||||
git checkout main
|
||||
git pull
|
||||
make release-publish-gitea VERSION=0.8.0
|
||||
|
||||
# Hotfix release from older commit
|
||||
git checkout v0.7.0
|
||||
git cherry-pick <hotfix-commit>
|
||||
git tag v0.7.1
|
||||
git push origin v0.7.1
|
||||
```
|
||||
|
||||
## Package Building
|
||||
|
||||
### Build Commands
|
||||
|
||||
```bash
|
||||
# Build packages with version info
|
||||
make package
|
||||
|
||||
# Build using release script
|
||||
make release-build
|
||||
python release.py build
|
||||
|
||||
# Manual build
|
||||
python -m build
|
||||
```
|
||||
|
||||
### Build Output
|
||||
|
||||
Packages are built to `dist/` directory:
|
||||
- **Wheel** (`.whl`): Binary distribution
|
||||
- **Source Distribution** (`.tar.gz`): Source code
|
||||
|
||||
### Version in Package Names
|
||||
|
||||
setuptools-scm ensures package names include correct versions:
|
||||
|
||||
```
|
||||
dist/
|
||||
├── markitect-0.8.0-py3-none-any.whl # Release
|
||||
├── markitect-0.8.0.tar.gz # Release
|
||||
├── markitect-0.8.1.dev3+hash-py3-none-any.whl # Development
|
||||
└── markitect-0.8.1.dev3+hash.tar.gz # Development
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **"No tags found"**:
|
||||
```bash
|
||||
# Create initial tag
|
||||
git tag v0.1.0
|
||||
git push origin v0.1.0
|
||||
```
|
||||
|
||||
2. **"Dirty working tree"**:
|
||||
```bash
|
||||
# Commit or stash changes
|
||||
git add . && git commit -m "Changes"
|
||||
# Or
|
||||
git stash
|
||||
```
|
||||
|
||||
3. **"Version not updating"**:
|
||||
```bash
|
||||
# Clear setuptools-scm cache
|
||||
rm -rf build/ *.egg-info/
|
||||
python -m setuptools_scm
|
||||
```
|
||||
|
||||
4. **"Import error in __version__.py"**:
|
||||
```bash
|
||||
# Rebuild package to generate _version.py
|
||||
make package
|
||||
```
|
||||
|
||||
### Debug Version Issues
|
||||
|
||||
```bash
|
||||
# Verbose setuptools-scm output
|
||||
python -m setuptools_scm --debug
|
||||
|
||||
# Check git state
|
||||
git describe --tags --dirty --always
|
||||
|
||||
# Verify tag format
|
||||
git tag --list | grep "^v"
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Do's ✅
|
||||
|
||||
- **Always use `vX.Y.Z` tag format**
|
||||
- **Create annotated tags**: `git tag -a v0.8.0 -m "Release 0.8.0"`
|
||||
- **Push tags to origin**: `git push origin v0.8.0`
|
||||
- **Keep clean working tree** for releases
|
||||
- **Follow semantic versioning**
|
||||
- **Test version detection** before releasing
|
||||
|
||||
### Don'ts ❌
|
||||
|
||||
- **Don't edit `_version.py`** manually (auto-generated)
|
||||
- **Don't commit version numbers** to source files
|
||||
- **Don't use non-standard tag formats**
|
||||
- **Don't create releases from dirty tree**
|
||||
- **Don't delete old tags** (breaks version history)
|
||||
|
||||
### Version Strategy
|
||||
|
||||
1. **Development**: Let setuptools-scm handle automatically
|
||||
2. **Pre-releases**: Use `-rc1`, `-alpha1`, `-beta1` suffixes
|
||||
3. **Releases**: Create tags only for stable releases
|
||||
4. **Hotfixes**: Tag from appropriate commit, not necessarily `main`
|
||||
|
||||
## Integration with CI/CD
|
||||
|
||||
### GitHub Actions Example
|
||||
|
||||
```yaml
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # Important for setuptools-scm
|
||||
|
||||
- name: Build packages
|
||||
run: make package
|
||||
|
||||
- name: Upload to Gitea
|
||||
env:
|
||||
GITEA_API_TOKEN: ${{ secrets.GITEA_API_TOKEN }}
|
||||
run: python release.py upload
|
||||
```
|
||||
|
||||
### Key Points
|
||||
|
||||
- **`fetch-depth: 0`**: Required for setuptools-scm to access git history
|
||||
- **Environment variables**: Use secrets for API tokens
|
||||
- **Tag-based triggers**: Only build releases for version tags
|
||||
|
||||
This version management system provides automatic, reliable, and traceable versioning that scales with your development workflow.
|
||||
236
capabilities/release-management/release.mk
Normal file
236
capabilities/release-management/release.mk
Normal file
@@ -0,0 +1,236 @@
|
||||
# Release Management Makefile Integration
|
||||
# Include this file in your main Makefile to add release management capabilities
|
||||
#
|
||||
# Usage: include capabilities/release-management/release.mk
|
||||
|
||||
# Release Management Variables
|
||||
RELEASE_MANAGEMENT_PATH := capabilities/release-management
|
||||
RELEASE_CLI := release
|
||||
|
||||
# Check if release management capability is available
|
||||
RELEASE_AVAILABLE := $(shell command -v $(RELEASE_CLI) 2> /dev/null)
|
||||
|
||||
# Release Status and Information
|
||||
.PHONY: release-status
|
||||
release-status: ## Show current release status and version information
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@echo " Install with: pip install -e $(RELEASE_MANAGEMENT_PATH)/"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) status
|
||||
|
||||
.PHONY: release-validate
|
||||
release-validate: ## Validate repository state for release readiness
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) validate
|
||||
|
||||
.PHONY: release-registry-info
|
||||
release-registry-info: ## Show package registry information and status
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) registry-info
|
||||
|
||||
# Git Tag Management
|
||||
.PHONY: release-tag
|
||||
release-tag: ## Create git tag for version (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-tag VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) tag --version $(VERSION)
|
||||
|
||||
# Package Building
|
||||
.PHONY: release-build
|
||||
release-build: ## Build release packages using setuptools-scm
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) build
|
||||
|
||||
.PHONY: release-clean
|
||||
release-clean: ## Clean build artifacts and temporary files
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) clean
|
||||
|
||||
# Publishing Workflows
|
||||
.PHONY: release-publish
|
||||
release-publish: ## Complete release workflow: tag + build (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) publish --version $(VERSION)
|
||||
|
||||
.PHONY: release-publish-gitea
|
||||
release-publish-gitea: ## Complete release workflow + Gitea upload (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish-gitea VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) publish --version $(VERSION) --registry gitea
|
||||
|
||||
.PHONY: release-publish-pypi
|
||||
release-publish-pypi: ## Complete release workflow + PyPI upload (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish-pypi VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) publish --version $(VERSION) --registry pypi
|
||||
|
||||
# Upload Existing Packages
|
||||
.PHONY: release-upload-gitea
|
||||
release-upload-gitea: ## Upload existing packages to Gitea registry
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) upload --registry gitea
|
||||
|
||||
.PHONY: release-upload-pypi
|
||||
release-upload-pypi: ## Upload existing packages to PyPI
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) upload --registry pypi
|
||||
|
||||
.PHONY: release-upload-testpypi
|
||||
release-upload-testpypi: ## Upload existing packages to Test PyPI
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) upload --registry testpypi
|
||||
|
||||
# Dry Run Options
|
||||
.PHONY: release-publish-dry-run
|
||||
release-publish-dry-run: ## Dry run of complete release workflow (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make release-publish-dry-run VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) publish --version $(VERSION) --dry-run
|
||||
|
||||
.PHONY: release-upload-dry-run
|
||||
release-upload-dry-run: ## Dry run of package upload to default registry
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) upload --dry-run
|
||||
|
||||
# Development and Setup
|
||||
.PHONY: release-management-install
|
||||
release-management-install: ## Install release management capability
|
||||
pip install -e $(RELEASE_MANAGEMENT_PATH)/
|
||||
|
||||
.PHONY: release-management-install-dev
|
||||
release-management-install-dev: ## Install release management capability with dev dependencies
|
||||
pip install -e "$(RELEASE_MANAGEMENT_PATH)/[dev]"
|
||||
|
||||
.PHONY: release-management-test
|
||||
release-management-test: ## Run release management capability tests
|
||||
cd $(RELEASE_MANAGEMENT_PATH) && pytest tests/
|
||||
|
||||
.PHONY: release-management-help
|
||||
release-management-help: ## Show release management CLI help
|
||||
ifndef RELEASE_AVAILABLE
|
||||
@echo "❌ Release management capability not installed"
|
||||
@echo " Install with: make release-management-install"
|
||||
@exit 1
|
||||
endif
|
||||
$(RELEASE_CLI) --help
|
||||
|
||||
# Help target integration
|
||||
.PHONY: help-release
|
||||
help-release: ## Show release management specific help
|
||||
@echo ""
|
||||
@echo "📦 Release Management:"
|
||||
@echo " release-status Show current release status and version information"
|
||||
@echo " release-validate Validate repository state for release readiness"
|
||||
@echo " release-registry-info Show package registry information and status"
|
||||
@echo ""
|
||||
@echo "🏷️ Git Tag Management:"
|
||||
@echo " release-tag VERSION=x.y.z Create git tag for version"
|
||||
@echo ""
|
||||
@echo "🔨 Package Building:"
|
||||
@echo " release-build Build release packages using setuptools-scm"
|
||||
@echo " release-clean Clean build artifacts and temporary files"
|
||||
@echo ""
|
||||
@echo "🚀 Publishing Workflows:"
|
||||
@echo " release-publish VERSION=x.y.z Complete release workflow (tag + build)"
|
||||
@echo " release-publish-gitea VERSION=x.y.z Complete release + Gitea upload"
|
||||
@echo " release-publish-pypi VERSION=x.y.z Complete release + PyPI upload"
|
||||
@echo ""
|
||||
@echo "📤 Upload Existing Packages:"
|
||||
@echo " release-upload-gitea Upload existing packages to Gitea registry"
|
||||
@echo " release-upload-pypi Upload existing packages to PyPI"
|
||||
@echo " release-upload-testpypi Upload existing packages to Test PyPI"
|
||||
@echo ""
|
||||
@echo "🧪 Dry Run Options:"
|
||||
@echo " release-publish-dry-run VERSION=x.y.z Dry run of release workflow"
|
||||
@echo " release-upload-dry-run Dry run of package upload"
|
||||
@echo ""
|
||||
@echo "⚙️ Development and Setup:"
|
||||
@echo " release-management-install Install release management capability"
|
||||
@echo " release-management-install-dev Install with development dependencies"
|
||||
@echo " release-management-test Run capability tests"
|
||||
@echo " release-management-help Show CLI help"
|
||||
@echo ""
|
||||
|
||||
# Default registry shortcuts (can be overridden)
|
||||
RELEASE_DEFAULT_REGISTRY ?= gitea
|
||||
|
||||
.PHONY: release-upload
|
||||
release-upload: release-upload-$(RELEASE_DEFAULT_REGISTRY) ## Upload packages to default registry ($(RELEASE_DEFAULT_REGISTRY))
|
||||
|
||||
# Integration with main project targets
|
||||
# These can be overridden in main Makefile if different behavior is needed
|
||||
|
||||
.PHONY: package
|
||||
package: release-build ## Build packages (alias for release-build)
|
||||
|
||||
.PHONY: publish
|
||||
publish: ## Publish release to default registry (requires VERSION=x.y.z)
|
||||
ifndef VERSION
|
||||
@echo "❌ VERSION is required. Usage: make publish VERSION=1.0.0"
|
||||
@exit 1
|
||||
endif
|
||||
@make release-publish-$(RELEASE_DEFAULT_REGISTRY) VERSION=$(VERSION)
|
||||
|
||||
# Legacy compatibility targets
|
||||
.PHONY: release-status-legacy
|
||||
release-status-legacy: release-status ## Legacy alias for release-status
|
||||
|
||||
.PHONY: package-upload
|
||||
package-upload: release-upload ## Legacy alias for release-upload
|
||||
@@ -0,0 +1,65 @@
|
||||
"""
|
||||
Release Management Capability
|
||||
|
||||
A comprehensive release management system for Python projects providing:
|
||||
- Automatic version management with setuptools-scm
|
||||
- Package building and distribution
|
||||
- Multi-platform publishing (Gitea, PyPI, etc.)
|
||||
- Git tag-based release workflows
|
||||
- CLI tools for release automation
|
||||
|
||||
Main Components:
|
||||
- ReleaseManager: Orchestrates complete release workflows
|
||||
- PackageBuilder: Handles package generation and building
|
||||
- PublishManager: Manages package publication to registries
|
||||
- GitManager: Git operations for releases
|
||||
- Registry Support: Gitea, PyPI, and extensible registry system
|
||||
|
||||
Quick Start:
|
||||
from release_management import ReleaseManager
|
||||
|
||||
manager = ReleaseManager()
|
||||
success = manager.publish_release("1.0.0")
|
||||
|
||||
CLI Usage:
|
||||
release status
|
||||
release publish --version 1.0.0
|
||||
release upload --registry gitea
|
||||
"""
|
||||
|
||||
from .core.manager import ReleaseManager
|
||||
from .core.builder import PackageBuilder
|
||||
from .core.publisher import PublishManager
|
||||
from .git.manager import GitManager
|
||||
from .registries.factory import RegistryFactory
|
||||
from .registries.gitea.registry import GiteaRegistry
|
||||
from .utils.version import VersionManager
|
||||
from .utils.validation import ReleaseValidator
|
||||
|
||||
# Version is managed in pyproject.toml
|
||||
__version__ = "0.1.0"
|
||||
|
||||
__all__ = [
|
||||
# Core classes
|
||||
"ReleaseManager",
|
||||
"PackageBuilder",
|
||||
"PublishManager",
|
||||
"GitManager",
|
||||
|
||||
# Registry support
|
||||
"RegistryFactory",
|
||||
"GiteaRegistry",
|
||||
|
||||
# Utilities
|
||||
"VersionManager",
|
||||
"ReleaseValidator",
|
||||
|
||||
# Version
|
||||
"__version__",
|
||||
]
|
||||
|
||||
# Package metadata
|
||||
__title__ = "release-management"
|
||||
__description__ = "Comprehensive release management capability for Python projects"
|
||||
__author__ = "MarkiTect Project"
|
||||
__license__ = "MIT"
|
||||
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
Command-line interface for release management.
|
||||
|
||||
This module provides CLI commands for release operations.
|
||||
"""
|
||||
|
||||
from .main import main
|
||||
|
||||
__all__ = ["main"]
|
||||
@@ -0,0 +1,252 @@
|
||||
"""
|
||||
Main CLI entry point for release management.
|
||||
|
||||
This module provides the main CLI interface adapted from the original release.py script.
|
||||
"""
|
||||
|
||||
import click
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from ..core.manager import ReleaseManager
|
||||
from ..utils.version import VersionManager
|
||||
|
||||
|
||||
@click.group(invoke_without_command=True)
|
||||
@click.option('--dry-run', is_flag=True, help='Show what would be done without making changes')
|
||||
@click.option('--force', is_flag=True, help='Force operation even with warnings')
|
||||
@click.option('--project-root', type=click.Path(exists=True, path_type=Path),
|
||||
help='Project root directory')
|
||||
@click.pass_context
|
||||
def main(ctx, dry_run: bool, force: bool, project_root: Optional[Path]):
|
||||
"""Release management CLI for Python projects."""
|
||||
ctx.ensure_object(dict)
|
||||
ctx.obj['dry_run'] = dry_run
|
||||
ctx.obj['force'] = force
|
||||
ctx.obj['project_root'] = project_root
|
||||
|
||||
# If no command specified, show status
|
||||
if ctx.invoked_subcommand is None:
|
||||
ctx.invoke(status)
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def status(ctx):
|
||||
"""Show current release status and version information."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
print("🔍 Release Status")
|
||||
print("=" * 60)
|
||||
|
||||
status_info = manager.get_release_status()
|
||||
|
||||
# Version information
|
||||
print(f"Current Version: {status_info['version']}")
|
||||
|
||||
# Git information
|
||||
if status_info.get('is_repo'):
|
||||
print(f"Git Branch: {status_info['branch']}")
|
||||
print(f"Latest Commit: {status_info['latest_commit']}")
|
||||
print(f"Latest Tag: {status_info['latest_tag'] or 'None'}")
|
||||
print(f"Uncommitted Changes: {'Yes' if status_info['has_changes'] else 'No'}")
|
||||
else:
|
||||
print("Git Repository: Not available")
|
||||
|
||||
# Package information
|
||||
packages = status_info['packages']
|
||||
print(f"\\nBuilt Packages: {packages['total_count']} files")
|
||||
if packages['wheels']:
|
||||
print(" Wheels:")
|
||||
for wheel in packages['wheels']:
|
||||
print(f" - {wheel}")
|
||||
if packages['sdists']:
|
||||
print(" Source Distributions:")
|
||||
for sdist in packages['sdists']:
|
||||
print(f" - {sdist}")
|
||||
|
||||
# Validation status
|
||||
validation = status_info['validation']
|
||||
if validation['is_valid']:
|
||||
print("\\n✅ Repository is ready for release")
|
||||
else:
|
||||
print("\\n❌ Release validation issues:")
|
||||
for issue in validation['issues']:
|
||||
print(f" - {issue}")
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def validate(ctx):
|
||||
"""Validate repository state for release readiness."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
is_valid, issues = manager.validate_release_state()
|
||||
|
||||
if is_valid:
|
||||
print("✅ Repository is ready for release")
|
||||
else:
|
||||
print("❌ Release validation failed:")
|
||||
for issue in issues:
|
||||
print(f" - {issue}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.option('--version', required=True, help='Version to tag (e.g., 0.8.0)')
|
||||
@click.option('--message', help='Tag message')
|
||||
@click.pass_context
|
||||
def tag(ctx, version: str, message: Optional[str]):
|
||||
"""Create git tag for version."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
if manager.create_tag(version, message):
|
||||
print(f"✅ Successfully created tag for version {version}")
|
||||
else:
|
||||
print(f"❌ Failed to create tag for version {version}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def build(ctx):
|
||||
"""Build release packages using setuptools-scm."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
if manager.build_packages():
|
||||
print("✅ Packages built successfully")
|
||||
else:
|
||||
print("❌ Package build failed")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.option('--version', required=True, help='Version to publish (e.g., 0.8.0)')
|
||||
@click.option('--registry', default='gitea', help='Registry type (gitea, pypi, etc.)')
|
||||
@click.option('--skip-build', is_flag=True, help='Skip building and use existing packages')
|
||||
@click.pass_context
|
||||
def publish(ctx, version: str, registry: str, skip_build: bool):
|
||||
"""Complete release workflow: tag, build, and publish."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
if manager.publish_with_fallback(version, registry, skip_build):
|
||||
print(f"🎉 Release {version} published successfully!")
|
||||
else:
|
||||
print(f"❌ Release {version} failed")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.option('--registry', default='gitea', help='Registry type (gitea, pypi, etc.)')
|
||||
@click.pass_context
|
||||
def upload(ctx, registry: str):
|
||||
"""Upload existing packages to registry."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
if manager.upload_existing_packages(registry):
|
||||
print(f"✅ Packages uploaded to {registry}")
|
||||
else:
|
||||
print(f"❌ Upload to {registry} failed")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@main.command('registry-info')
|
||||
@click.option('--registry', default='gitea', help='Registry type to show info for')
|
||||
@click.pass_context
|
||||
def registry_info(ctx, registry: str):
|
||||
"""Show package registry information and status."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
info = manager.show_registry_info(registry)
|
||||
|
||||
print(f"📦 {registry.title()} Registry Information")
|
||||
print("=" * 50)
|
||||
|
||||
if 'error' in info:
|
||||
print(f"❌ Error: {info['error']}")
|
||||
return
|
||||
|
||||
for key, value in info.items():
|
||||
if isinstance(value, bool):
|
||||
indicator = "✅" if value else "❌"
|
||||
print(f"{key.replace('_', ' ').title()}: {indicator}")
|
||||
else:
|
||||
print(f"{key.replace('_', ' ').title()}: {value}")
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def clean(ctx):
|
||||
"""Clean build artifacts and temporary files."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
dry_run=ctx.obj['dry_run'],
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
manager.clean_build_artifacts()
|
||||
print("✅ Build artifacts cleaned")
|
||||
|
||||
|
||||
@main.command('version-info')
|
||||
@click.option('--suggest', is_flag=True, help='Suggest next version options')
|
||||
@click.pass_context
|
||||
def version_info(ctx, suggest: bool):
|
||||
"""Show version information and suggestions."""
|
||||
version_manager = VersionManager(ctx.obj['project_root'])
|
||||
|
||||
current = version_manager.get_current_version()
|
||||
print(f"Current Version: {current}")
|
||||
|
||||
if suggest:
|
||||
suggestions = version_manager.suggest_version(current)
|
||||
if 'error' in suggestions:
|
||||
print(f"❌ {suggestions['error']}")
|
||||
if 'suggestion' in suggestions:
|
||||
print(f"💡 {suggestions['suggestion']}")
|
||||
else:
|
||||
print("\\nSuggested next versions:")
|
||||
print(f" Patch: {suggestions['patch']}")
|
||||
print(f" Minor: {suggestions['minor']}")
|
||||
print(f" Major: {suggestions['major']}")
|
||||
|
||||
# Show version components
|
||||
version_data = version_manager.parse_version(current)
|
||||
if 'error' not in version_data:
|
||||
print("\\nVersion Components:")
|
||||
for key, value in version_data.items():
|
||||
if value is not None:
|
||||
print(f" {key.replace('_', ' ').title()}: {value}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Core release management classes.
|
||||
|
||||
This module provides the main classes for orchestrating releases:
|
||||
- ReleaseManager: Main coordinator for release workflows
|
||||
- PackageBuilder: Package building and setuptools-scm integration
|
||||
- PublishManager: Package publication to registries
|
||||
"""
|
||||
|
||||
from .manager import ReleaseManager
|
||||
from .builder import PackageBuilder
|
||||
from .publisher import PublishManager
|
||||
|
||||
__all__ = ["ReleaseManager", "PackageBuilder", "PublishManager"]
|
||||
@@ -0,0 +1,166 @@
|
||||
"""
|
||||
Package building functionality for releases.
|
||||
|
||||
This module handles package building using setuptools-scm and the Python build module.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
from ..utils.version import VersionManager
|
||||
|
||||
|
||||
class PackageBuilder:
|
||||
"""Handles package building with setuptools-scm integration."""
|
||||
|
||||
def __init__(self, project_root: Optional[Path] = None, dry_run: bool = False):
|
||||
"""Initialize the package builder.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of the project. Defaults to current directory.
|
||||
dry_run: If True, show what would be done without executing.
|
||||
"""
|
||||
self.project_root = project_root or Path.cwd()
|
||||
self.dry_run = dry_run
|
||||
self.dist_dir = self.project_root / "dist"
|
||||
|
||||
def get_current_version(self) -> str:
|
||||
"""Get current version using setuptools-scm.
|
||||
|
||||
Returns:
|
||||
Current version string or "unknown" if unavailable.
|
||||
"""
|
||||
try:
|
||||
result = self._run_command(
|
||||
['python', '-m', 'setuptools_scm'],
|
||||
capture=True,
|
||||
skip_dry_run=True
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
return "unknown"
|
||||
|
||||
def clean_build(self) -> None:
|
||||
"""Clean previous build artifacts."""
|
||||
print("🧹 Cleaning build artifacts...")
|
||||
|
||||
patterns = ['build', 'dist', '*.egg-info']
|
||||
for pattern in patterns:
|
||||
try:
|
||||
if pattern == 'dist' and self.dist_dir.exists():
|
||||
if self.dry_run:
|
||||
print(f"[DRY RUN] Would remove: {self.dist_dir}")
|
||||
else:
|
||||
import shutil
|
||||
shutil.rmtree(self.dist_dir)
|
||||
print(f"✅ Removed: {self.dist_dir}")
|
||||
elif pattern != 'dist':
|
||||
self._run_command(['rm', '-rf', pattern])
|
||||
except subprocess.CalledProcessError:
|
||||
pass # Ignore if files don't exist
|
||||
|
||||
def build_packages(self) -> bool:
|
||||
"""Build release packages using setuptools-scm.
|
||||
|
||||
Returns:
|
||||
True if build successful, False otherwise.
|
||||
"""
|
||||
print(f"📦 Building packages (version auto-determined by setuptools-scm)")
|
||||
|
||||
# Clean previous builds
|
||||
self.clean_build()
|
||||
|
||||
# Build packages
|
||||
try:
|
||||
print("Building packages...")
|
||||
self._run_command(['python', '-m', 'build'], capture=False)
|
||||
print("✅ Packages built successfully")
|
||||
|
||||
# Show package details
|
||||
self._show_package_details()
|
||||
return True
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"❌ Package build failed: {e}")
|
||||
return False
|
||||
|
||||
def get_built_packages(self) -> Dict[str, List[Path]]:
|
||||
"""Get list of built packages by type.
|
||||
|
||||
Returns:
|
||||
Dictionary with 'wheels' and 'sdists' keys containing file paths.
|
||||
"""
|
||||
if not self.dist_dir.exists():
|
||||
return {"wheels": [], "sdists": []}
|
||||
|
||||
wheels = list(self.dist_dir.glob("*.whl"))
|
||||
sdists = list(self.dist_dir.glob("*.tar.gz"))
|
||||
|
||||
return {"wheels": wheels, "sdists": sdists}
|
||||
|
||||
def validate_packages(self) -> bool:
|
||||
"""Validate that expected packages were built.
|
||||
|
||||
Returns:
|
||||
True if packages are valid, False otherwise.
|
||||
"""
|
||||
packages = self.get_built_packages()
|
||||
|
||||
if not packages["wheels"] and not packages["sdists"]:
|
||||
print("❌ No packages found in dist/")
|
||||
return False
|
||||
|
||||
# Check package sizes
|
||||
for wheel in packages["wheels"]:
|
||||
if wheel.stat().st_size < 1000: # Less than 1KB
|
||||
print(f"⚠️ Warning: {wheel.name} is very small ({wheel.stat().st_size} bytes)")
|
||||
|
||||
for sdist in packages["sdists"]:
|
||||
if sdist.stat().st_size < 1000: # Less than 1KB
|
||||
print(f"⚠️ Warning: {sdist.name} is very small ({sdist.stat().st_size} bytes)")
|
||||
|
||||
return True
|
||||
|
||||
def _show_package_details(self) -> None:
|
||||
"""Show details about built packages."""
|
||||
packages = self.get_built_packages()
|
||||
|
||||
if packages["wheels"] or packages["sdists"]:
|
||||
print(f"\n📦 Built packages in {self.dist_dir}:")
|
||||
|
||||
for wheel in packages["wheels"]:
|
||||
size = wheel.stat().st_size
|
||||
print(f" 🎯 {wheel.name} ({size:,} bytes)")
|
||||
|
||||
for sdist in packages["sdists"]:
|
||||
size = sdist.stat().st_size
|
||||
print(f" 📄 {sdist.name} ({size:,} bytes)")
|
||||
else:
|
||||
print("❌ No packages found")
|
||||
|
||||
def _run_command(self, cmd: List[str], capture: bool = True,
|
||||
check: bool = True, skip_dry_run: bool = False) -> subprocess.CompletedProcess:
|
||||
"""Run a command with optional dry-run support.
|
||||
|
||||
Args:
|
||||
cmd: Command to execute
|
||||
capture: Whether to capture output
|
||||
check: Whether to raise on non-zero exit
|
||||
skip_dry_run: Whether to skip dry-run check and always execute
|
||||
|
||||
Returns:
|
||||
CompletedProcess result
|
||||
"""
|
||||
if self.dry_run and not skip_dry_run:
|
||||
print(f"[DRY RUN] Would run: {' '.join(cmd)}")
|
||||
return subprocess.CompletedProcess(cmd, 0, "", "")
|
||||
|
||||
return subprocess.run(
|
||||
cmd,
|
||||
capture_output=capture,
|
||||
text=True,
|
||||
check=check,
|
||||
cwd=self.project_root
|
||||
)
|
||||
@@ -0,0 +1,215 @@
|
||||
"""
|
||||
Main release manager orchestrating complete release workflows.
|
||||
|
||||
This module provides the primary ReleaseManager class that coordinates
|
||||
all aspects of the release process.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Tuple, Dict, Any
|
||||
|
||||
from .builder import PackageBuilder
|
||||
from .publisher import PublishManager
|
||||
from ..git.manager import GitManager
|
||||
from ..utils.validation import ReleaseValidator
|
||||
|
||||
|
||||
class ReleaseManager:
|
||||
"""Main orchestrator for release workflows."""
|
||||
|
||||
def __init__(self, project_root: Optional[Path] = None, dry_run: bool = False, force: bool = False):
|
||||
"""Initialize the release manager.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of the project. Defaults to current directory.
|
||||
dry_run: If True, show what would be done without executing.
|
||||
force: If True, skip validation checks.
|
||||
"""
|
||||
self.project_root = project_root or Path.cwd()
|
||||
self.dry_run = dry_run
|
||||
self.force = force
|
||||
|
||||
# Initialize component managers
|
||||
self.git_manager = GitManager(project_root, dry_run)
|
||||
self.builder = PackageBuilder(project_root, dry_run)
|
||||
self.publisher = PublishManager(project_root, dry_run)
|
||||
self.validator = ReleaseValidator(project_root)
|
||||
|
||||
def get_release_status(self) -> Dict[str, Any]:
|
||||
"""Get comprehensive release status information.
|
||||
|
||||
Returns:
|
||||
Dictionary with release status details
|
||||
"""
|
||||
status = {}
|
||||
|
||||
# Version information
|
||||
status['version'] = self.builder.get_current_version()
|
||||
|
||||
# Git status
|
||||
git_status = self.git_manager.get_repository_status()
|
||||
status.update(git_status)
|
||||
|
||||
# Package status
|
||||
packages = self.builder.get_built_packages()
|
||||
status['packages'] = {
|
||||
'wheels': [p.name for p in packages['wheels']],
|
||||
'sdists': [p.name for p in packages['sdists']],
|
||||
'total_count': len(packages['wheels']) + len(packages['sdists'])
|
||||
}
|
||||
|
||||
# Validation status
|
||||
is_valid, issues = self.validate_release_state()
|
||||
status['validation'] = {
|
||||
'is_valid': is_valid,
|
||||
'issues': issues
|
||||
}
|
||||
|
||||
return status
|
||||
|
||||
def validate_release_state(self) -> Tuple[bool, List[str]]:
|
||||
"""Validate that the repository is ready for release.
|
||||
|
||||
Returns:
|
||||
Tuple of (is_valid, list_of_issues)
|
||||
"""
|
||||
return self.validator.validate_release_state(force=self.force)
|
||||
|
||||
def create_tag(self, version: str, message: Optional[str] = None) -> bool:
|
||||
"""Create a git tag for the release.
|
||||
|
||||
Args:
|
||||
version: Version to tag (e.g., "1.0.0")
|
||||
message: Optional tag message
|
||||
|
||||
Returns:
|
||||
True if tag created successfully, False otherwise
|
||||
"""
|
||||
# Validate release state first
|
||||
is_valid, issues = self.validate_release_state()
|
||||
if not is_valid and not self.force:
|
||||
print("❌ Cannot create tag:")
|
||||
for issue in issues:
|
||||
print(f" - {issue}")
|
||||
return False
|
||||
|
||||
return self.git_manager.create_tag(version, message)
|
||||
|
||||
def build_packages(self) -> bool:
|
||||
"""Build release packages.
|
||||
|
||||
Returns:
|
||||
True if build successful, False otherwise
|
||||
"""
|
||||
success = self.builder.build_packages()
|
||||
if success:
|
||||
success = self.builder.validate_packages()
|
||||
return success
|
||||
|
||||
def publish_release(self, version: str, registry_type: str = 'gitea',
|
||||
skip_build: bool = False) -> bool:
|
||||
"""Complete release workflow: validate, tag, build, and publish.
|
||||
|
||||
Args:
|
||||
version: Version to release
|
||||
registry_type: Type of registry to publish to
|
||||
skip_build: If True, skip building and use existing packages
|
||||
|
||||
Returns:
|
||||
True if release successful, False otherwise
|
||||
"""
|
||||
print(f"🚀 Publishing release {version}")
|
||||
|
||||
# Validate state
|
||||
is_valid, issues = self.validate_release_state()
|
||||
if not is_valid and not self.force:
|
||||
print("❌ Cannot publish release:")
|
||||
for issue in issues:
|
||||
print(f" - {issue}")
|
||||
return False
|
||||
|
||||
# Create git tag (this determines the version for setuptools-scm)
|
||||
if not self.git_manager.tag_exists(f"v{version}"):
|
||||
if not self.create_tag(version):
|
||||
return False
|
||||
else:
|
||||
print(f"✅ Tag v{version} already exists")
|
||||
|
||||
# Build packages (setuptools-scm will use the tag for version)
|
||||
if not skip_build:
|
||||
if not self.build_packages():
|
||||
return False
|
||||
else:
|
||||
print("⏭️ Skipping build (using existing packages)")
|
||||
|
||||
# Publish packages
|
||||
if not self.publisher.publish_packages(registry_type):
|
||||
print("⚠️ Release completed but publishing failed")
|
||||
return False
|
||||
|
||||
print(f"✅ Release {version} completed successfully!")
|
||||
print(f"📦 Packages published to {registry_type}")
|
||||
print(f"🏷️ Git tag v{version} created")
|
||||
return True
|
||||
|
||||
def publish_with_fallback(self, version: str, registry_type: str = 'gitea',
|
||||
skip_build: bool = False) -> bool:
|
||||
"""Complete release workflow with fallback to release assets.
|
||||
|
||||
Args:
|
||||
version: Version to release
|
||||
registry_type: Type of registry to publish to
|
||||
skip_build: If True, skip building and use existing packages
|
||||
|
||||
Returns:
|
||||
True if release successful, False otherwise
|
||||
"""
|
||||
# Try normal publish first
|
||||
if self.publish_release(version, registry_type, skip_build):
|
||||
return True
|
||||
|
||||
# If that fails, try release assets fallback
|
||||
print("🔄 Attempting release assets fallback...")
|
||||
return self.publisher.publish_as_release_assets(version, registry_type)
|
||||
|
||||
def upload_existing_packages(self, registry_type: str = 'gitea') -> bool:
|
||||
"""Upload existing packages without building or tagging.
|
||||
|
||||
Args:
|
||||
registry_type: Type of registry to upload to
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
print(f"📤 Uploading existing packages to {registry_type}")
|
||||
|
||||
packages = self.builder.get_built_packages()
|
||||
if not packages["wheels"] and not packages["sdists"]:
|
||||
print("❌ No packages found in dist/. Run build first.")
|
||||
return False
|
||||
|
||||
all_packages = packages["wheels"] + packages["sdists"]
|
||||
return self.publisher.upload_specific_packages(all_packages, registry_type)
|
||||
|
||||
def clean_build_artifacts(self) -> None:
|
||||
"""Clean build artifacts and temporary files."""
|
||||
self.builder.clean_build()
|
||||
|
||||
def show_registry_info(self, registry_type: str = 'gitea') -> Dict[str, Any]:
|
||||
"""Show information about a registry.
|
||||
|
||||
Args:
|
||||
registry_type: Type of registry
|
||||
|
||||
Returns:
|
||||
Dictionary with registry information
|
||||
"""
|
||||
return self.publisher.get_registry_info(registry_type)
|
||||
|
||||
def get_commits_since_last_tag(self) -> List[str]:
|
||||
"""Get commits since the last release tag.
|
||||
|
||||
Returns:
|
||||
List of commit messages since last tag
|
||||
"""
|
||||
return self.git_manager.get_commits_since_tag()
|
||||
@@ -0,0 +1,248 @@
|
||||
"""
|
||||
Package publishing functionality for releases.
|
||||
|
||||
This module handles publishing packages to various registries.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Any
|
||||
|
||||
from ..registries.factory import RegistryFactory
|
||||
from ..registries.base import RegistryInterface
|
||||
from .builder import PackageBuilder
|
||||
|
||||
|
||||
class PublishManager:
|
||||
"""Handles package publication to registries."""
|
||||
|
||||
def __init__(self, project_root: Optional[Path] = None, dry_run: bool = False):
|
||||
"""Initialize the publish manager.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of the project. Defaults to current directory.
|
||||
dry_run: If True, show what would be done without executing.
|
||||
"""
|
||||
self.project_root = project_root or Path.cwd()
|
||||
self.dry_run = dry_run
|
||||
|
||||
def publish_packages(self, registry_type: str = 'gitea',
|
||||
registry_config: Optional[Dict[str, Any]] = None) -> bool:
|
||||
"""Publish packages to specified registry.
|
||||
|
||||
Args:
|
||||
registry_type: Type of registry to publish to
|
||||
registry_config: Optional registry configuration
|
||||
|
||||
Returns:
|
||||
True if publishing successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Get registry client
|
||||
registry = self._get_registry(registry_type, registry_config)
|
||||
|
||||
# Get built packages
|
||||
builder = PackageBuilder(self.project_root)
|
||||
packages = builder.get_built_packages()
|
||||
|
||||
if not packages["wheels"] and not packages["sdists"]:
|
||||
print("❌ No packages found in dist/. Run build first.")
|
||||
return False
|
||||
|
||||
# Upload packages
|
||||
success = True
|
||||
for wheel in packages["wheels"]:
|
||||
if not self._upload_package_with_fallback(registry, wheel):
|
||||
success = False
|
||||
|
||||
for sdist in packages["sdists"]:
|
||||
if not self._upload_package_with_fallback(registry, sdist):
|
||||
success = False
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Publishing failed: {e}")
|
||||
return False
|
||||
|
||||
def upload_specific_packages(self, package_paths: List[Path],
|
||||
registry_type: str = 'gitea',
|
||||
registry_config: Optional[Dict[str, Any]] = None) -> bool:
|
||||
"""Upload specific package files to registry.
|
||||
|
||||
Args:
|
||||
package_paths: List of paths to package files
|
||||
registry_type: Type of registry to publish to
|
||||
registry_config: Optional registry configuration
|
||||
|
||||
Returns:
|
||||
True if all uploads successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
registry = self._get_registry(registry_type, registry_config)
|
||||
|
||||
success = True
|
||||
for package_path in package_paths:
|
||||
if not package_path.exists():
|
||||
print(f"❌ Package not found: {package_path}")
|
||||
success = False
|
||||
continue
|
||||
|
||||
if not self._upload_package_with_fallback(registry, package_path):
|
||||
success = False
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Upload failed: {e}")
|
||||
return False
|
||||
|
||||
def publish_as_release_assets(self, version: str,
|
||||
registry_type: str = 'gitea',
|
||||
registry_config: Optional[Dict[str, Any]] = None) -> bool:
|
||||
"""Publish packages as release assets (fallback method).
|
||||
|
||||
Args:
|
||||
version: Version to publish as
|
||||
registry_type: Type of registry (must support release assets)
|
||||
registry_config: Optional registry configuration
|
||||
|
||||
Returns:
|
||||
True if publishing successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
registry = self._get_registry(registry_type, registry_config)
|
||||
|
||||
# Check if registry supports release assets
|
||||
if not hasattr(registry, 'upload_package_as_release_assets'):
|
||||
print(f"❌ Registry type '{registry_type}' does not support release assets")
|
||||
return False
|
||||
|
||||
# Get built packages
|
||||
builder = PackageBuilder(self.project_root)
|
||||
packages = builder.get_built_packages()
|
||||
|
||||
if not packages["wheels"] and not packages["sdists"]:
|
||||
print("❌ No packages found in dist/. Run build first.")
|
||||
return False
|
||||
|
||||
# Find wheel and corresponding source distribution
|
||||
success = True
|
||||
for wheel in packages["wheels"]:
|
||||
# Find matching sdist
|
||||
sdist = None
|
||||
wheel_name_parts = wheel.stem.split('-')
|
||||
package_name = wheel_name_parts[0] if wheel_name_parts else ""
|
||||
|
||||
for potential_sdist in packages["sdists"]:
|
||||
if potential_sdist.stem.startswith(package_name):
|
||||
sdist = potential_sdist
|
||||
break
|
||||
|
||||
# Upload as release assets
|
||||
if not registry.upload_package_as_release_assets(
|
||||
version, wheel, sdist, dry_run=self.dry_run
|
||||
):
|
||||
success = False
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Release asset publishing failed: {e}")
|
||||
return False
|
||||
|
||||
def get_registry_info(self, registry_type: str = 'gitea',
|
||||
registry_config: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
"""Get information about a registry.
|
||||
|
||||
Args:
|
||||
registry_type: Type of registry
|
||||
registry_config: Optional registry configuration
|
||||
|
||||
Returns:
|
||||
Dictionary with registry information
|
||||
"""
|
||||
try:
|
||||
registry = self._get_registry(registry_type, registry_config)
|
||||
return registry.get_registry_info()
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
|
||||
def _get_registry(self, registry_type: str,
|
||||
registry_config: Optional[Dict[str, Any]] = None) -> RegistryInterface:
|
||||
"""Get a registry client.
|
||||
|
||||
Args:
|
||||
registry_type: Type of registry
|
||||
registry_config: Optional registry configuration
|
||||
|
||||
Returns:
|
||||
Registry client instance
|
||||
"""
|
||||
if registry_config:
|
||||
return RegistryFactory.create(registry_type, registry_config)
|
||||
else:
|
||||
# Try to load from pyproject.toml first
|
||||
try:
|
||||
return RegistryFactory.create_from_pyproject_config(
|
||||
self.project_root / "pyproject.toml",
|
||||
registry_type
|
||||
)
|
||||
except (ValueError, FileNotFoundError):
|
||||
# Fallback to auto-detection
|
||||
return RegistryFactory.create(registry_type)
|
||||
|
||||
def _upload_package_with_fallback(self, registry: RegistryInterface,
|
||||
package_path: Path) -> bool:
|
||||
"""Upload a package with fallback to release assets if needed.
|
||||
|
||||
Args:
|
||||
registry: Registry client
|
||||
package_path: Path to package file
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Try normal package upload first
|
||||
return registry.upload_package(package_path, dry_run=self.dry_run)
|
||||
except Exception as e:
|
||||
print(f"⚠️ Package upload failed: {e}")
|
||||
|
||||
# Check if registry supports release assets as fallback
|
||||
if hasattr(registry, 'upload_package_as_release_assets'):
|
||||
print("🔄 Trying release assets as fallback...")
|
||||
|
||||
# Extract version from package filename for release assets
|
||||
version = self._extract_version_from_filename(package_path)
|
||||
if version:
|
||||
return registry.upload_package_as_release_assets(
|
||||
version, package_path, dry_run=self.dry_run
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
def _extract_version_from_filename(self, package_path: Path) -> Optional[str]:
|
||||
"""Extract version from package filename.
|
||||
|
||||
Args:
|
||||
package_path: Path to package file
|
||||
|
||||
Returns:
|
||||
Version string or None if not found
|
||||
"""
|
||||
try:
|
||||
if package_path.suffix == '.whl':
|
||||
# Wheel format: package-version-python-abi-platform.whl
|
||||
parts = package_path.stem.split('-')
|
||||
if len(parts) >= 2:
|
||||
return parts[1]
|
||||
elif package_path.suffix == '.gz' and package_path.name.endswith('.tar.gz'):
|
||||
# Source dist format: package-version.tar.gz
|
||||
name_without_tar = package_path.name.replace('.tar.gz', '')
|
||||
parts = name_without_tar.split('-')
|
||||
if len(parts) >= 2:
|
||||
return parts[1]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return None
|
||||
@@ -0,0 +1,12 @@
|
||||
"""
|
||||
Git management for releases.
|
||||
|
||||
This module provides Git operations required for release workflows:
|
||||
- Tag creation and management
|
||||
- Repository state validation
|
||||
- Branch and commit operations
|
||||
"""
|
||||
|
||||
from .manager import GitManager
|
||||
|
||||
__all__ = ["GitManager"]
|
||||
@@ -0,0 +1,205 @@
|
||||
"""
|
||||
Git operations for release management.
|
||||
|
||||
This module handles all Git-related operations needed for releases.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any, Optional, List
|
||||
|
||||
|
||||
class GitManager:
|
||||
"""Manages Git operations for releases."""
|
||||
|
||||
def __init__(self, project_root: Optional[Path] = None, dry_run: bool = False):
|
||||
"""Initialize Git manager.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of the project
|
||||
dry_run: If True, show what would be done without executing
|
||||
"""
|
||||
self.project_root = project_root or Path.cwd()
|
||||
self.dry_run = dry_run
|
||||
|
||||
def get_repository_status(self) -> Dict[str, Any]:
|
||||
"""Get current git repository status.
|
||||
|
||||
Returns:
|
||||
Dictionary with repository status information
|
||||
"""
|
||||
try:
|
||||
# Get current branch
|
||||
branch_result = self._run_command(['git', 'branch', '--show-current'])
|
||||
current_branch = branch_result.stdout.strip()
|
||||
|
||||
# Check for uncommitted changes
|
||||
status_result = self._run_command(['git', 'status', '--porcelain'])
|
||||
has_changes = bool(status_result.stdout.strip())
|
||||
|
||||
# Get latest commit
|
||||
commit_result = self._run_command(['git', 'rev-parse', '--short', 'HEAD'])
|
||||
latest_commit = commit_result.stdout.strip()
|
||||
|
||||
# Get latest tag
|
||||
try:
|
||||
tag_result = self._run_command(['git', 'describe', '--tags', '--abbrev=0'])
|
||||
latest_tag = tag_result.stdout.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
latest_tag = None
|
||||
|
||||
return {
|
||||
'is_repo': True,
|
||||
'branch': current_branch,
|
||||
'has_changes': has_changes,
|
||||
'latest_commit': latest_commit,
|
||||
'latest_tag': latest_tag
|
||||
}
|
||||
except subprocess.CalledProcessError:
|
||||
return {'is_repo': False}
|
||||
|
||||
def create_tag(self, version: str, message: Optional[str] = None) -> bool:
|
||||
"""Create and push git tag.
|
||||
|
||||
Args:
|
||||
version: Version to tag (e.g., "1.0.0")
|
||||
message: Optional tag message
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
if not version.startswith('v'):
|
||||
tag_name = f"v{version}"
|
||||
else:
|
||||
tag_name = version
|
||||
|
||||
tag_message = message or f"Release {version.lstrip('v')}"
|
||||
print(f"🏷️ Creating git tag {tag_name}")
|
||||
|
||||
try:
|
||||
# Create annotated tag
|
||||
self._run_command(['git', 'tag', '-a', tag_name, '-m', tag_message])
|
||||
print(f"✅ Tag {tag_name} created")
|
||||
|
||||
# Push tag to origin
|
||||
try:
|
||||
print(f"📤 Pushing tag to origin...")
|
||||
self._run_command(['git', 'push', 'origin', tag_name])
|
||||
print(f"✅ Tag pushed to origin")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"⚠️ Could not push tag to origin: {e}")
|
||||
print(f"You can push it manually with: git push origin {tag_name}")
|
||||
return True # Tag created successfully, push can be done manually
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"❌ Failed to create tag: {e}")
|
||||
return False
|
||||
|
||||
def validate_release_state(self, force: bool = False) -> tuple[bool, List[str]]:
|
||||
"""Validate that repository is ready for release.
|
||||
|
||||
Args:
|
||||
force: Skip validation checks if True
|
||||
|
||||
Returns:
|
||||
Tuple of (is_valid, list_of_issues)
|
||||
"""
|
||||
issues = []
|
||||
status = self.get_repository_status()
|
||||
|
||||
if not status['is_repo']:
|
||||
issues.append("Not in a git repository")
|
||||
else:
|
||||
if status['has_changes'] and not force:
|
||||
issues.append("Repository has uncommitted changes")
|
||||
if status['branch'] != 'main' and not force:
|
||||
issues.append(f"Not on main branch (currently on {status['branch']})")
|
||||
|
||||
return len(issues) == 0, issues
|
||||
|
||||
def get_commits_since_tag(self, tag_name: Optional[str] = None) -> List[str]:
|
||||
"""Get list of commits since specified tag.
|
||||
|
||||
Args:
|
||||
tag_name: Tag to compare against. If None, uses latest tag.
|
||||
|
||||
Returns:
|
||||
List of commit messages since tag
|
||||
"""
|
||||
try:
|
||||
if tag_name is None:
|
||||
# Get latest tag
|
||||
tag_result = self._run_command(['git', 'describe', '--tags', '--abbrev=0'])
|
||||
tag_name = tag_result.stdout.strip()
|
||||
|
||||
# Get commits since tag
|
||||
log_result = self._run_command([
|
||||
'git', 'log', f'{tag_name}..HEAD', '--oneline', '--no-merges'
|
||||
])
|
||||
|
||||
commits = []
|
||||
for line in log_result.stdout.strip().split('\n'):
|
||||
if line:
|
||||
commits.append(line)
|
||||
|
||||
return commits
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
return []
|
||||
|
||||
def tag_exists(self, tag_name: str) -> bool:
|
||||
"""Check if a git tag exists.
|
||||
|
||||
Args:
|
||||
tag_name: Tag name to check
|
||||
|
||||
Returns:
|
||||
True if tag exists, False otherwise
|
||||
"""
|
||||
try:
|
||||
self._run_command(['git', 'rev-parse', f'refs/tags/{tag_name}'])
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
def get_remote_url(self, remote: str = 'origin') -> Optional[str]:
|
||||
"""Get the URL of a git remote.
|
||||
|
||||
Args:
|
||||
remote: Remote name (default: 'origin')
|
||||
|
||||
Returns:
|
||||
Remote URL or None if not found
|
||||
"""
|
||||
try:
|
||||
result = self._run_command(['git', 'remote', 'get-url', remote])
|
||||
return result.stdout.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
def _run_command(self, cmd: List[str]) -> subprocess.CompletedProcess:
|
||||
"""Run a git command.
|
||||
|
||||
Args:
|
||||
cmd: Command to execute
|
||||
|
||||
Returns:
|
||||
CompletedProcess result
|
||||
|
||||
Raises:
|
||||
subprocess.CalledProcessError: If command fails
|
||||
"""
|
||||
if self.dry_run and not any(read_only in cmd for read_only in
|
||||
['status', 'branch', 'rev-parse', 'describe',
|
||||
'log', 'remote']):
|
||||
print(f"[DRY RUN] Would run: {' '.join(cmd)}")
|
||||
return subprocess.CompletedProcess(cmd, 0, "", "")
|
||||
|
||||
return subprocess.run(
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
cwd=self.project_root
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Package registry implementations.
|
||||
|
||||
This module provides registry clients for publishing packages to various platforms:
|
||||
- Gitea package registries
|
||||
- PyPI and Test PyPI
|
||||
- Extensible factory for custom registries
|
||||
"""
|
||||
|
||||
from .factory import RegistryFactory
|
||||
from .base import RegistryInterface, RegistryConfig
|
||||
from .gitea.registry import GiteaRegistry
|
||||
from .gitea.config import GiteaConfig
|
||||
from .gitea.exceptions import GiteaError
|
||||
|
||||
__all__ = [
|
||||
"RegistryFactory",
|
||||
"RegistryInterface",
|
||||
"RegistryConfig",
|
||||
"GiteaRegistry",
|
||||
"GiteaConfig",
|
||||
"GiteaError",
|
||||
]
|
||||
@@ -0,0 +1,101 @@
|
||||
"""
|
||||
Base registry interface and configuration.
|
||||
|
||||
This module defines the common interface that all registry implementations must follow.
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Any
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class RegistryConfig:
|
||||
"""Base configuration for package registries."""
|
||||
name: str
|
||||
type: str
|
||||
url: str
|
||||
auth_token_env: Optional[str] = None
|
||||
|
||||
def get_auth_token(self) -> Optional[str]:
|
||||
"""Get authentication token from environment variable."""
|
||||
if self.auth_token_env:
|
||||
import os
|
||||
return os.getenv(self.auth_token_env)
|
||||
return None
|
||||
|
||||
|
||||
class RegistryInterface(ABC):
|
||||
"""Abstract interface for package registries."""
|
||||
|
||||
def __init__(self, config: RegistryConfig):
|
||||
"""Initialize the registry with configuration."""
|
||||
self.config = config
|
||||
|
||||
@abstractmethod
|
||||
def upload_package(self, package_path: Path, dry_run: bool = False) -> bool:
|
||||
"""Upload a package to the registry.
|
||||
|
||||
Args:
|
||||
package_path: Path to package file (.whl or .tar.gz)
|
||||
dry_run: If True, show what would be done without uploading
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def check_auth(self) -> bool:
|
||||
"""Check if authentication is properly configured.
|
||||
|
||||
Returns:
|
||||
True if authenticated, False otherwise
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def list_packages(self) -> List[Dict[str, Any]]:
|
||||
"""List packages in the registry.
|
||||
|
||||
Returns:
|
||||
List of package information dictionaries
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_package_info(self, package_name: str) -> Optional[Dict[str, Any]]:
|
||||
"""Get information about a specific package.
|
||||
|
||||
Args:
|
||||
package_name: Name of the package
|
||||
|
||||
Returns:
|
||||
Package information dictionary or None if not found
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_package_version(self, package_name: str, version: str,
|
||||
dry_run: bool = False) -> bool:
|
||||
"""Delete a specific version of a package.
|
||||
|
||||
Args:
|
||||
package_name: Name of the package
|
||||
version: Version to delete
|
||||
dry_run: If True, show what would be done without deleting
|
||||
|
||||
Returns:
|
||||
True if deletion successful, False otherwise
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_registry_info(self) -> Dict[str, Any]:
|
||||
"""Get information about the registry configuration.
|
||||
|
||||
Returns:
|
||||
Dictionary with registry information
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,159 @@
|
||||
"""
|
||||
Registry factory for creating registry clients.
|
||||
|
||||
This module provides a factory for creating appropriate registry clients
|
||||
based on configuration or registry type.
|
||||
"""
|
||||
|
||||
from typing import Dict, Type, Optional, Any
|
||||
from pathlib import Path
|
||||
|
||||
from .base import RegistryInterface, RegistryConfig
|
||||
from .gitea.registry import GiteaRegistry
|
||||
from .gitea.config import GiteaConfig
|
||||
|
||||
|
||||
class RegistryFactory:
|
||||
"""Factory for creating registry clients."""
|
||||
|
||||
_registry_types: Dict[str, Type[RegistryInterface]] = {
|
||||
'gitea': GiteaRegistry,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create(cls, registry_type: str, config: Optional[Dict[str, Any]] = None) -> RegistryInterface:
|
||||
"""Create a registry client of the specified type.
|
||||
|
||||
Args:
|
||||
registry_type: Type of registry ('gitea', 'pypi', etc.)
|
||||
config: Optional configuration dictionary
|
||||
|
||||
Returns:
|
||||
Registry client instance
|
||||
|
||||
Raises:
|
||||
ValueError: If registry type is not supported
|
||||
"""
|
||||
if registry_type not in cls._registry_types:
|
||||
raise ValueError(f"Unsupported registry type: {registry_type}. "
|
||||
f"Supported types: {list(cls._registry_types.keys())}")
|
||||
|
||||
registry_class = cls._registry_types[registry_type]
|
||||
|
||||
# Handle Gitea-specific configuration
|
||||
if registry_type == 'gitea':
|
||||
if config:
|
||||
gitea_config = GiteaConfig(
|
||||
gitea_url=config.get('url', ''),
|
||||
repo_owner=config.get('owner', ''),
|
||||
repo_name=config.get('repo', ''),
|
||||
auth_token=config.get('auth_token')
|
||||
)
|
||||
return registry_class(gitea_config)
|
||||
else:
|
||||
# Auto-detect from git repository
|
||||
return registry_class()
|
||||
|
||||
# For other registry types, create with generic config
|
||||
if config:
|
||||
registry_config = RegistryConfig(
|
||||
name=config.get('name', registry_type),
|
||||
type=registry_type,
|
||||
url=config['url'],
|
||||
auth_token_env=config.get('auth_token_env')
|
||||
)
|
||||
return registry_class(registry_config)
|
||||
else:
|
||||
raise ValueError(f"Configuration required for {registry_type} registry")
|
||||
|
||||
@classmethod
|
||||
def create_from_pyproject_config(cls, pyproject_path: Optional[Path] = None,
|
||||
registry_name: str = 'gitea') -> RegistryInterface:
|
||||
"""Create a registry client from pyproject.toml configuration.
|
||||
|
||||
Args:
|
||||
pyproject_path: Path to pyproject.toml file. If None, looks in current directory.
|
||||
registry_name: Name of registry configuration to use
|
||||
|
||||
Returns:
|
||||
Registry client instance
|
||||
|
||||
Raises:
|
||||
ValueError: If configuration is invalid or registry not found
|
||||
"""
|
||||
if pyproject_path is None:
|
||||
pyproject_path = Path.cwd() / "pyproject.toml"
|
||||
|
||||
if not pyproject_path.exists():
|
||||
raise ValueError(f"pyproject.toml not found at {pyproject_path}")
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except ImportError:
|
||||
try:
|
||||
import tomli as tomllib # Fallback for Python < 3.11
|
||||
except ImportError:
|
||||
raise ImportError("tomllib or tomli required to read pyproject.toml")
|
||||
|
||||
with open(pyproject_path, 'rb') as f:
|
||||
config = tomllib.load(f)
|
||||
|
||||
# Look for release-management configuration
|
||||
release_config = config.get('tool', {}).get('release-management', {})
|
||||
registries_config = release_config.get('registries', {})
|
||||
|
||||
if registry_name not in registries_config:
|
||||
raise ValueError(f"Registry '{registry_name}' not found in pyproject.toml configuration")
|
||||
|
||||
registry_config = registries_config[registry_name]
|
||||
registry_type = registry_config.get('type', registry_name)
|
||||
|
||||
# Add auth token from environment if specified
|
||||
auth_token_env = registry_config.get('auth_token_env')
|
||||
if auth_token_env:
|
||||
import os
|
||||
registry_config = registry_config.copy()
|
||||
registry_config['auth_token'] = os.getenv(auth_token_env)
|
||||
|
||||
return cls.create(registry_type, registry_config)
|
||||
|
||||
@classmethod
|
||||
def auto_detect(cls) -> RegistryInterface:
|
||||
"""Auto-detect registry type from current environment.
|
||||
|
||||
Currently only supports Gitea auto-detection from git repository.
|
||||
|
||||
Returns:
|
||||
Registry client instance
|
||||
|
||||
Raises:
|
||||
ValueError: If no registry can be auto-detected
|
||||
"""
|
||||
# Try Gitea auto-detection first
|
||||
try:
|
||||
return cls.create('gitea')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
raise ValueError("Could not auto-detect registry type. "
|
||||
"Ensure you're in a git repository with Gitea remote, "
|
||||
"or provide explicit configuration.")
|
||||
|
||||
@classmethod
|
||||
def register_registry_type(cls, registry_type: str, registry_class: Type[RegistryInterface]) -> None:
|
||||
"""Register a new registry type.
|
||||
|
||||
Args:
|
||||
registry_type: String identifier for the registry type
|
||||
registry_class: Registry class that implements RegistryInterface
|
||||
"""
|
||||
cls._registry_types[registry_type] = registry_class
|
||||
|
||||
@classmethod
|
||||
def list_supported_types(cls) -> list[str]:
|
||||
"""List all supported registry types.
|
||||
|
||||
Returns:
|
||||
List of supported registry type strings
|
||||
"""
|
||||
return list(cls._registry_types.keys())
|
||||
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Gitea package registry implementation.
|
||||
|
||||
This module provides Gitea-specific registry functionality including:
|
||||
- Package registry uploads
|
||||
- Release asset fallback
|
||||
- Configuration and authentication
|
||||
"""
|
||||
|
||||
from .registry import GiteaRegistry
|
||||
from .config import GiteaConfig
|
||||
from .exceptions import GiteaError, GiteaConfigError
|
||||
|
||||
__all__ = ["GiteaRegistry", "GiteaConfig", "GiteaError", "GiteaConfigError"]
|
||||
@@ -172,4 +172,4 @@ class GiteaConfig:
|
||||
def requires_auth(self, operation: str = "read") -> bool:
|
||||
"""Check if operation requires authentication."""
|
||||
write_operations = {"create", "update", "delete", "write"}
|
||||
return operation in write_operations and not self.auth_token
|
||||
return operation in write_operations and not self.auth_token
|
||||
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Gitea-specific exceptions.
|
||||
"""
|
||||
|
||||
|
||||
class GiteaError(Exception):
|
||||
"""Base class for Gitea-related errors."""
|
||||
pass
|
||||
|
||||
|
||||
class GiteaConfigError(GiteaError):
|
||||
"""Configuration-related errors."""
|
||||
pass
|
||||
|
||||
|
||||
class GiteaApiError(GiteaError):
|
||||
"""API-related errors."""
|
||||
pass
|
||||
|
||||
|
||||
class GiteaAuthError(GiteaError):
|
||||
"""Authentication-related errors."""
|
||||
pass
|
||||
@@ -0,0 +1,355 @@
|
||||
"""
|
||||
Gitea Package Registry Client
|
||||
|
||||
This module provides functionality to publish Python packages to Gitea's package registry.
|
||||
Gitea supports multiple package registries including PyPI-compatible registries.
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Dict, Any
|
||||
|
||||
from ..base import RegistryInterface
|
||||
from .config import GiteaConfig
|
||||
from .exceptions import GiteaError
|
||||
|
||||
|
||||
class GiteaRegistry(RegistryInterface):
|
||||
"""Client for publishing packages to Gitea package registry."""
|
||||
|
||||
def __init__(self, config: Optional[GiteaConfig] = None):
|
||||
"""Initialize the package registry client.
|
||||
|
||||
Args:
|
||||
config: Gitea configuration. If None, auto-detects from git repository.
|
||||
"""
|
||||
self.config = config or GiteaConfig.from_git_repository()
|
||||
self.config.validate()
|
||||
|
||||
@property
|
||||
def pypi_registry_url(self) -> str:
|
||||
"""Get the PyPI-compatible registry URL for this repository."""
|
||||
return f"{self.config.gitea_url}/api/packages/{self.config.repo_owner}/pypi"
|
||||
|
||||
@property
|
||||
def package_list_url(self) -> str:
|
||||
"""Get the package listing URL for this repository."""
|
||||
return f"{self.config.gitea_url}/api/v1/packages/{self.config.repo_owner}"
|
||||
|
||||
def check_auth(self) -> bool:
|
||||
"""Check if authentication token is available and valid."""
|
||||
if not self.config.auth_token:
|
||||
return False
|
||||
|
||||
try:
|
||||
# Test auth by trying to access packages API
|
||||
import requests
|
||||
headers = {"Authorization": f"token {self.config.auth_token}"}
|
||||
response = requests.get(self.package_list_url, headers=headers, timeout=10)
|
||||
return response.status_code in [200, 404] # 404 is okay if no packages exist yet
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def list_packages(self) -> List[Dict[str, Any]]:
|
||||
"""List all packages for this repository owner.
|
||||
|
||||
Returns:
|
||||
List of package information dictionaries
|
||||
"""
|
||||
try:
|
||||
import requests
|
||||
headers = {}
|
||||
if self.config.auth_token:
|
||||
headers["Authorization"] = f"token {self.config.auth_token}"
|
||||
|
||||
response = requests.get(self.package_list_url, headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
raise GiteaError(f"Failed to list packages: {e}")
|
||||
|
||||
def get_package_info(self, package_name: str) -> Optional[Dict[str, Any]]:
|
||||
"""Get information about a specific package.
|
||||
|
||||
Args:
|
||||
package_name: Name of the package
|
||||
|
||||
Returns:
|
||||
Package information dictionary or None if not found
|
||||
"""
|
||||
try:
|
||||
packages = self.list_packages()
|
||||
for package in packages:
|
||||
if package.get("name") == package_name:
|
||||
return package
|
||||
return None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def upload_package(self, package_path: Path, dry_run: bool = False) -> bool:
|
||||
"""Upload a package to Gitea registry.
|
||||
|
||||
Args:
|
||||
package_path: Path to package file (.whl or .tar.gz)
|
||||
dry_run: If True, show what would be done without uploading
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
if not self.config.auth_token:
|
||||
raise GiteaError("Authentication token required for package upload. Set GITEA_API_TOKEN environment variable.")
|
||||
|
||||
if not package_path.exists():
|
||||
raise GiteaError(f"Package file not found: {package_path}")
|
||||
|
||||
if dry_run:
|
||||
print(f"[DRY RUN] Would upload to: {self.pypi_registry_url}")
|
||||
print(f"[DRY RUN] Would upload: {package_path}")
|
||||
return True
|
||||
|
||||
return self._upload_file(package_path)
|
||||
|
||||
def upload_package_as_release_assets(self,
|
||||
version: str,
|
||||
wheel_path: Path,
|
||||
sdist_path: Optional[Path] = None,
|
||||
dry_run: bool = False) -> bool:
|
||||
"""Upload packages as Gitea release assets (fallback when package registry unavailable).
|
||||
|
||||
Args:
|
||||
version: Version tag (e.g., "v0.8.0")
|
||||
wheel_path: Path to wheel (.whl) file
|
||||
sdist_path: Optional path to source distribution (.tar.gz) file
|
||||
dry_run: If True, show what would be done without uploading
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
if not self.config.auth_token:
|
||||
raise GiteaError("Authentication token required for release upload. Set GITEA_API_TOKEN environment variable.")
|
||||
|
||||
if not wheel_path.exists():
|
||||
raise GiteaError(f"Wheel file not found: {wheel_path}")
|
||||
|
||||
if sdist_path and not sdist_path.exists():
|
||||
raise GiteaError(f"Source distribution file not found: {sdist_path}")
|
||||
|
||||
files_to_upload = [wheel_path]
|
||||
if sdist_path:
|
||||
files_to_upload.append(sdist_path)
|
||||
|
||||
if dry_run:
|
||||
print(f"[DRY RUN] Would upload release assets for {version}")
|
||||
print(f"[DRY RUN] Release API: {self.config.repo_api_url}/releases")
|
||||
for file_path in files_to_upload:
|
||||
print(f"[DRY RUN] Would upload: {file_path}")
|
||||
return True
|
||||
|
||||
# Create or get release
|
||||
release_id = self._create_or_get_release(version)
|
||||
if not release_id:
|
||||
return False
|
||||
|
||||
# Upload each file as release asset
|
||||
success = True
|
||||
for file_path in files_to_upload:
|
||||
if not self._upload_release_asset(release_id, file_path):
|
||||
success = False
|
||||
|
||||
return success
|
||||
|
||||
def delete_package_version(self, package_name: str, version: str,
|
||||
dry_run: bool = False) -> bool:
|
||||
"""Delete a specific version of a package.
|
||||
|
||||
Args:
|
||||
package_name: Name of the package
|
||||
version: Version to delete
|
||||
dry_run: If True, show what would be done without deleting
|
||||
|
||||
Returns:
|
||||
True if deletion successful, False otherwise
|
||||
"""
|
||||
if not self.config.auth_token:
|
||||
raise GiteaError("Authentication token required for package deletion.")
|
||||
|
||||
delete_url = f"{self.config.gitea_url}/api/v1/packages/{self.config.repo_owner}/pypi/{package_name}/{version}"
|
||||
|
||||
if dry_run:
|
||||
print(f"[DRY RUN] Would delete: {package_name} v{version}")
|
||||
print(f"[DRY RUN] DELETE {delete_url}")
|
||||
return True
|
||||
|
||||
try:
|
||||
import requests
|
||||
headers = {"Authorization": f"token {self.config.auth_token}"}
|
||||
response = requests.delete(delete_url, headers=headers, timeout=10)
|
||||
|
||||
if response.status_code in [200, 204, 404]: # 404 = already deleted
|
||||
print(f"✅ Deleted: {package_name} v{version}")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Delete failed: {response.status_code} {response.text}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Delete failed: {e}")
|
||||
return False
|
||||
|
||||
def get_registry_info(self) -> Dict[str, Any]:
|
||||
"""Get information about the package registry configuration.
|
||||
|
||||
Returns:
|
||||
Dictionary with registry information
|
||||
"""
|
||||
return {
|
||||
"gitea_url": self.config.gitea_url,
|
||||
"repo_owner": self.config.repo_owner,
|
||||
"repo_name": self.config.repo_name,
|
||||
"pypi_registry_url": self.pypi_registry_url,
|
||||
"package_list_url": self.package_list_url,
|
||||
"auth_configured": bool(self.config.auth_token),
|
||||
"auth_valid": self.check_auth() if self.config.auth_token else False
|
||||
}
|
||||
|
||||
def _upload_file(self, file_path: Path) -> bool:
|
||||
"""Upload a single file to the registry.
|
||||
|
||||
Args:
|
||||
file_path: Path to file to upload
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
import requests
|
||||
|
||||
# Gitea PyPI upload API expects PUT with the file content as body
|
||||
# URL format: /api/packages/{owner}/pypi/{filename}
|
||||
upload_url = f"{self.config.gitea_url}/api/packages/{self.config.repo_owner}/pypi"
|
||||
|
||||
with open(file_path, 'rb') as f:
|
||||
file_content = f.read()
|
||||
|
||||
headers = {
|
||||
'Authorization': f'token {self.config.auth_token}',
|
||||
'Content-Type': 'application/octet-stream'
|
||||
}
|
||||
|
||||
# Upload using PUT request with filename in URL
|
||||
upload_endpoint = f"{upload_url}/{file_path.name}"
|
||||
response = requests.put(
|
||||
upload_endpoint,
|
||||
headers=headers,
|
||||
data=file_content,
|
||||
timeout=60
|
||||
)
|
||||
|
||||
if response.status_code in [200, 201, 409]: # 409 = already exists
|
||||
print(f"✅ Uploaded: {file_path.name}")
|
||||
if response.status_code == 409:
|
||||
print(f" (already exists)")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Upload failed for {file_path.name}: {response.status_code}")
|
||||
if response.text:
|
||||
print(f" Error: {response.text}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Upload failed for {file_path.name}: {e}")
|
||||
return False
|
||||
|
||||
def _create_or_get_release(self, version: str) -> Optional[int]:
|
||||
"""Create a new release or get existing release ID.
|
||||
|
||||
Args:
|
||||
version: Version tag (e.g., "v0.8.0")
|
||||
|
||||
Returns:
|
||||
Release ID if successful, None otherwise
|
||||
"""
|
||||
try:
|
||||
import requests
|
||||
|
||||
# Ensure version has 'v' prefix
|
||||
tag_name = version if version.startswith('v') else f'v{version}'
|
||||
|
||||
headers = {"Authorization": f"token {self.config.auth_token}"}
|
||||
|
||||
# First, try to get existing release
|
||||
releases_url = f"{self.config.repo_api_url}/releases"
|
||||
response = requests.get(releases_url, headers=headers, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
releases = response.json()
|
||||
for release in releases:
|
||||
if release.get('tag_name') == tag_name:
|
||||
print(f"✅ Found existing release: {tag_name}")
|
||||
return release['id']
|
||||
|
||||
# Create new release
|
||||
release_data = {
|
||||
"tag_name": tag_name,
|
||||
"name": f"MarkiTect {version.lstrip('v')}",
|
||||
"body": f"Release {version.lstrip('v')}\\n\\nPython packages for MarkiTect.",
|
||||
"draft": False,
|
||||
"prerelease": False
|
||||
}
|
||||
|
||||
response = requests.post(releases_url, headers=headers, json=release_data, timeout=10)
|
||||
|
||||
if response.status_code == 201:
|
||||
release = response.json()
|
||||
print(f"✅ Created release: {tag_name}")
|
||||
return release['id']
|
||||
else:
|
||||
print(f"❌ Failed to create release: {response.status_code} {response.text}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error managing release: {e}")
|
||||
return None
|
||||
|
||||
def _upload_release_asset(self, release_id: int, file_path: Path) -> bool:
|
||||
"""Upload a file as a release asset.
|
||||
|
||||
Args:
|
||||
release_id: Gitea release ID
|
||||
file_path: Path to file to upload
|
||||
|
||||
Returns:
|
||||
True if upload successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
import requests
|
||||
|
||||
# Upload asset to Gitea release
|
||||
upload_url = f"{self.config.repo_api_url}/releases/{release_id}/assets"
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {self.config.auth_token}"
|
||||
}
|
||||
|
||||
with open(file_path, 'rb') as f:
|
||||
files = {
|
||||
'attachment': (file_path.name, f, 'application/octet-stream')
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
upload_url,
|
||||
headers=headers,
|
||||
files=files,
|
||||
timeout=120 # Larger timeout for file uploads
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
print(f"✅ Uploaded release asset: {file_path.name}")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Failed to upload {file_path.name}: {response.status_code} {response.text}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Upload failed for {file_path.name}: {e}")
|
||||
return False
|
||||
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Utilities for release management.
|
||||
|
||||
This module provides utility functions for version management,
|
||||
validation, and other common operations.
|
||||
"""
|
||||
|
||||
from .version import VersionManager
|
||||
from .validation import ReleaseValidator
|
||||
|
||||
__all__ = ["VersionManager", "ReleaseValidator"]
|
||||
@@ -0,0 +1,230 @@
|
||||
"""
|
||||
Release validation utilities.
|
||||
|
||||
This module provides validation functions for release readiness.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple, Optional
|
||||
|
||||
from ..git.manager import GitManager
|
||||
|
||||
|
||||
class ReleaseValidator:
|
||||
"""Validates release readiness and requirements."""
|
||||
|
||||
def __init__(self, project_root: Optional[Path] = None):
|
||||
"""Initialize release validator.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of the project
|
||||
"""
|
||||
self.project_root = project_root or Path.cwd()
|
||||
self.git_manager = GitManager(project_root)
|
||||
|
||||
def validate_release_state(self, force: bool = False) -> Tuple[bool, List[str]]:
|
||||
"""Validate that repository is ready for release.
|
||||
|
||||
Args:
|
||||
force: Skip validation checks if True
|
||||
|
||||
Returns:
|
||||
Tuple of (is_valid, list_of_issues)
|
||||
"""
|
||||
if force:
|
||||
return True, []
|
||||
|
||||
issues = []
|
||||
|
||||
# Git repository validation
|
||||
git_issues = self._validate_git_state()
|
||||
issues.extend(git_issues)
|
||||
|
||||
# Project structure validation
|
||||
structure_issues = self._validate_project_structure()
|
||||
issues.extend(structure_issues)
|
||||
|
||||
# Configuration validation
|
||||
config_issues = self._validate_configuration()
|
||||
issues.extend(config_issues)
|
||||
|
||||
return len(issues) == 0, issues
|
||||
|
||||
def _validate_git_state(self) -> List[str]:
|
||||
"""Validate git repository state.
|
||||
|
||||
Returns:
|
||||
List of git-related issues
|
||||
"""
|
||||
issues = []
|
||||
status = self.git_manager.get_repository_status()
|
||||
|
||||
if not status['is_repo']:
|
||||
issues.append("Not in a git repository")
|
||||
return issues
|
||||
|
||||
if status['has_changes']:
|
||||
issues.append("Repository has uncommitted changes")
|
||||
|
||||
if status['branch'] != 'main':
|
||||
issues.append(f"Not on main branch (currently on {status['branch']})")
|
||||
|
||||
# Check if remote exists
|
||||
remote_url = self.git_manager.get_remote_url()
|
||||
if not remote_url:
|
||||
issues.append("No git remote 'origin' configured")
|
||||
|
||||
return issues
|
||||
|
||||
def _validate_project_structure(self) -> List[str]:
|
||||
"""Validate project structure for releases.
|
||||
|
||||
Returns:
|
||||
List of project structure issues
|
||||
"""
|
||||
issues = []
|
||||
|
||||
# Check for required files
|
||||
required_files = ['pyproject.toml']
|
||||
for file_name in required_files:
|
||||
file_path = self.project_root / file_name
|
||||
if not file_path.exists():
|
||||
issues.append(f"Missing required file: {file_name}")
|
||||
|
||||
# Check for setuptools-scm configuration
|
||||
pyproject_path = self.project_root / 'pyproject.toml'
|
||||
if pyproject_path.exists():
|
||||
try:
|
||||
import tomllib
|
||||
except ImportError:
|
||||
try:
|
||||
import tomli as tomllib
|
||||
except ImportError:
|
||||
issues.append("Cannot read pyproject.toml (tomllib/tomli not available)")
|
||||
return issues
|
||||
|
||||
try:
|
||||
with open(pyproject_path, 'rb') as f:
|
||||
config = tomllib.load(f)
|
||||
|
||||
# Check for setuptools-scm configuration
|
||||
build_system = config.get('build-system', {})
|
||||
if 'setuptools-scm' not in str(build_system.get('requires', [])):
|
||||
issues.append("setuptools-scm not found in build-system.requires")
|
||||
|
||||
# Check for dynamic version
|
||||
project_config = config.get('project', {})
|
||||
if 'version' in project_config:
|
||||
issues.append("Static version found in project config. Use dynamic versioning with setuptools-scm.")
|
||||
|
||||
dynamic = project_config.get('dynamic', [])
|
||||
if 'version' not in dynamic:
|
||||
issues.append("'version' not in project.dynamic. Add it for setuptools-scm.")
|
||||
|
||||
except Exception as e:
|
||||
issues.append(f"Error reading pyproject.toml: {e}")
|
||||
|
||||
return issues
|
||||
|
||||
def _validate_configuration(self) -> List[str]:
|
||||
"""Validate release configuration.
|
||||
|
||||
Returns:
|
||||
List of configuration issues
|
||||
"""
|
||||
issues = []
|
||||
|
||||
# Check for environment variables that might be needed
|
||||
import os
|
||||
|
||||
# Check for common auth tokens (warn, don't fail)
|
||||
auth_vars = ['GITEA_API_TOKEN', 'PYPI_TOKEN', 'GITHUB_TOKEN']
|
||||
available_auth = [var for var in auth_vars if os.getenv(var)]
|
||||
|
||||
if not available_auth:
|
||||
issues.append("No authentication tokens found in environment. "
|
||||
"Consider setting GITEA_API_TOKEN, PYPI_TOKEN, or GITHUB_TOKEN "
|
||||
"for package publishing.")
|
||||
|
||||
return issues
|
||||
|
||||
def validate_version_string(self, version_string: str) -> Tuple[bool, List[str]]:
|
||||
"""Validate a version string for release.
|
||||
|
||||
Args:
|
||||
version_string: Version string to validate
|
||||
|
||||
Returns:
|
||||
Tuple of (is_valid, list_of_issues)
|
||||
"""
|
||||
issues = []
|
||||
|
||||
if not version_string:
|
||||
issues.append("Version string cannot be empty")
|
||||
return False, issues
|
||||
|
||||
# Check basic format
|
||||
if not version_string.replace('.', '').replace('-', '').replace('+', '').replace('a', '').replace('b', '').replace('rc', '').isalnum():
|
||||
issues.append("Version string contains invalid characters")
|
||||
|
||||
# Check for development markers in release
|
||||
dev_markers = ['dev', '.dev', '+dev']
|
||||
if any(marker in version_string.lower() for marker in dev_markers):
|
||||
issues.append("Development versions should not be released")
|
||||
|
||||
# Check for reasonable version format (semantic versioning)
|
||||
try:
|
||||
from packaging import version
|
||||
version.Version(version_string)
|
||||
except Exception:
|
||||
issues.append("Version string is not valid according to PEP 440")
|
||||
|
||||
# Check if version already exists as git tag
|
||||
tag_name = version_string if version_string.startswith('v') else f'v{version_string}'
|
||||
if self.git_manager.tag_exists(tag_name):
|
||||
issues.append(f"Git tag {tag_name} already exists")
|
||||
|
||||
return len(issues) == 0, issues
|
||||
|
||||
def get_validation_summary(self) -> dict:
|
||||
"""Get a comprehensive validation summary.
|
||||
|
||||
Returns:
|
||||
Dictionary with validation results
|
||||
"""
|
||||
is_valid, issues = self.validate_release_state()
|
||||
|
||||
return {
|
||||
'is_valid': is_valid,
|
||||
'issues': issues,
|
||||
'git_status': self.git_manager.get_repository_status(),
|
||||
'recommendations': self._get_recommendations(issues)
|
||||
}
|
||||
|
||||
def _get_recommendations(self, issues: List[str]) -> List[str]:
|
||||
"""Get recommendations based on validation issues.
|
||||
|
||||
Args:
|
||||
issues: List of validation issues
|
||||
|
||||
Returns:
|
||||
List of recommendations
|
||||
"""
|
||||
recommendations = []
|
||||
|
||||
if any('uncommitted changes' in issue for issue in issues):
|
||||
recommendations.append("Commit or stash your changes before releasing")
|
||||
|
||||
if any('not on main branch' in issue for issue in issues):
|
||||
recommendations.append("Switch to main branch: git checkout main")
|
||||
|
||||
if any('setuptools-scm' in issue for issue in issues):
|
||||
recommendations.append("Configure setuptools-scm in pyproject.toml")
|
||||
|
||||
if any('authentication' in issue.lower() for issue in issues):
|
||||
recommendations.append("Set up authentication tokens for package publishing")
|
||||
|
||||
if not issues:
|
||||
recommendations.append("Repository is ready for release!")
|
||||
|
||||
return recommendations
|
||||
@@ -0,0 +1,298 @@
|
||||
"""
|
||||
Version management utilities.
|
||||
|
||||
This module provides utilities for working with versions and setuptools-scm.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Optional, Dict, Any
|
||||
from packaging import version
|
||||
|
||||
|
||||
class VersionManager:
|
||||
"""Utilities for version management with setuptools-scm."""
|
||||
|
||||
def __init__(self, project_root: Optional[Path] = None):
|
||||
"""Initialize version manager.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of the project
|
||||
"""
|
||||
self.project_root = project_root or Path.cwd()
|
||||
|
||||
def get_current_version(self) -> str:
|
||||
"""Get current version using setuptools-scm.
|
||||
|
||||
Returns:
|
||||
Current version string or "unknown" if unavailable
|
||||
"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['python', '-m', 'setuptools_scm'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
cwd=self.project_root
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
return "unknown"
|
||||
|
||||
def parse_version(self, version_string: str) -> Dict[str, Any]:
|
||||
"""Parse a version string and return components.
|
||||
|
||||
Args:
|
||||
version_string: Version string to parse
|
||||
|
||||
Returns:
|
||||
Dictionary with version components
|
||||
"""
|
||||
try:
|
||||
v = version.Version(version_string)
|
||||
return {
|
||||
'major': v.major,
|
||||
'minor': v.minor,
|
||||
'micro': v.micro,
|
||||
'is_prerelease': v.is_prerelease,
|
||||
'is_devrelease': v.is_devrelease,
|
||||
'local': v.local,
|
||||
'public': v.public,
|
||||
'base_version': v.base_version,
|
||||
}
|
||||
except version.InvalidVersion:
|
||||
return {'error': f'Invalid version: {version_string}'}
|
||||
|
||||
def is_development_version(self, version_string: Optional[str] = None) -> bool:
|
||||
"""Check if version is a development version.
|
||||
|
||||
Args:
|
||||
version_string: Version to check. If None, uses current version.
|
||||
|
||||
Returns:
|
||||
True if development version, False otherwise
|
||||
"""
|
||||
if version_string is None:
|
||||
version_string = self.get_current_version()
|
||||
|
||||
try:
|
||||
v = version.Version(version_string)
|
||||
return v.is_devrelease or 'dev' in version_string.lower()
|
||||
except version.InvalidVersion:
|
||||
return True # Assume unknown versions are dev
|
||||
|
||||
def compare_versions(self, version1: str, version2: str) -> int:
|
||||
"""Compare two version strings.
|
||||
|
||||
Args:
|
||||
version1: First version to compare
|
||||
version2: Second version to compare
|
||||
|
||||
Returns:
|
||||
-1 if version1 < version2, 0 if equal, 1 if version1 > version2
|
||||
"""
|
||||
try:
|
||||
v1 = version.Version(version1)
|
||||
v2 = version.Version(version2)
|
||||
|
||||
if v1 < v2:
|
||||
return -1
|
||||
elif v1 > v2:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
except version.InvalidVersion:
|
||||
# Fallback to string comparison
|
||||
if version1 < version2:
|
||||
return -1
|
||||
elif version1 > version2:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def get_next_version(self, current_version: str, bump_type: str = 'patch') -> str:
|
||||
"""Get the next version based on bump type.
|
||||
|
||||
Args:
|
||||
current_version: Current version string
|
||||
bump_type: Type of bump ('major', 'minor', 'patch')
|
||||
|
||||
Returns:
|
||||
Next version string
|
||||
|
||||
Raises:
|
||||
ValueError: If bump_type is invalid
|
||||
"""
|
||||
try:
|
||||
v = version.Version(current_version)
|
||||
major, minor, micro = v.major, v.minor, v.micro
|
||||
|
||||
if bump_type == 'major':
|
||||
return f"{major + 1}.0.0"
|
||||
elif bump_type == 'minor':
|
||||
return f"{major}.{minor + 1}.0"
|
||||
elif bump_type == 'patch':
|
||||
return f"{major}.{minor}.{micro + 1}"
|
||||
else:
|
||||
raise ValueError(f"Invalid bump type: {bump_type}")
|
||||
|
||||
except version.InvalidVersion:
|
||||
raise ValueError(f"Cannot parse version: {current_version}")
|
||||
|
||||
def suggest_version(self, current_version: Optional[str] = None) -> Dict[str, str]:
|
||||
"""Suggest next version options.
|
||||
|
||||
Args:
|
||||
current_version: Current version. If None, gets from setuptools-scm.
|
||||
|
||||
Returns:
|
||||
Dictionary with version suggestions
|
||||
"""
|
||||
if current_version is None:
|
||||
current_version = self.get_current_version()
|
||||
|
||||
if current_version == "unknown":
|
||||
return {
|
||||
'error': 'Cannot determine current version',
|
||||
'suggestion': 'Consider creating an initial tag like v0.1.0'
|
||||
}
|
||||
|
||||
try:
|
||||
# Strip development version info to get base
|
||||
v = version.Version(current_version)
|
||||
base_version = v.base_version
|
||||
|
||||
return {
|
||||
'current': current_version,
|
||||
'base': base_version,
|
||||
'patch': self.get_next_version(base_version, 'patch'),
|
||||
'minor': self.get_next_version(base_version, 'minor'),
|
||||
'major': self.get_next_version(base_version, 'major'),
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
'error': str(e),
|
||||
'current': current_version
|
||||
}
|
||||
|
||||
def validate_version_format(self, version_string: str) -> bool:
|
||||
"""Validate if a version string follows semantic versioning.
|
||||
|
||||
Args:
|
||||
version_string: Version string to validate
|
||||
|
||||
Returns:
|
||||
True if valid semantic version, False otherwise
|
||||
"""
|
||||
try:
|
||||
version.Version(version_string)
|
||||
return True
|
||||
except version.InvalidVersion:
|
||||
return False
|
||||
|
||||
def get_version_info(self, project_root: Optional[Path] = None) -> Dict[str, Any]:
|
||||
"""Get comprehensive version information for a project.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of project. If None, uses current directory.
|
||||
|
||||
Returns:
|
||||
Dictionary with version information
|
||||
"""
|
||||
if project_root:
|
||||
original_root = self.project_root
|
||||
self.project_root = project_root
|
||||
|
||||
try:
|
||||
current_version = self.get_current_version()
|
||||
|
||||
# Try to get git information
|
||||
git_info = self._get_git_info()
|
||||
|
||||
# Parse version components
|
||||
version_parts = self.parse_version(current_version) if current_version != "unknown" else {}
|
||||
|
||||
return {
|
||||
'full_version': current_version,
|
||||
'short_version': current_version.split('.dev')[0] if '.dev' in current_version else current_version,
|
||||
'version_components': version_parts,
|
||||
'is_dev': self.is_development_version(current_version),
|
||||
'git_commit': git_info.get('commit'),
|
||||
'git_branch': git_info.get('branch'),
|
||||
'is_git_repo': git_info.get('is_repo', False)
|
||||
}
|
||||
finally:
|
||||
if project_root:
|
||||
self.project_root = original_root
|
||||
|
||||
def get_release_info(self, project_root: Optional[Path] = None) -> Dict[str, Any]:
|
||||
"""Get release information for a project.
|
||||
|
||||
Args:
|
||||
project_root: Root directory of project. If None, uses current directory.
|
||||
|
||||
Returns:
|
||||
Dictionary with release information
|
||||
"""
|
||||
from datetime import datetime
|
||||
|
||||
version_info = self.get_version_info(project_root)
|
||||
|
||||
return {
|
||||
'name': 'MarkiTect',
|
||||
'version': version_info['full_version'],
|
||||
'short_version': version_info['short_version'],
|
||||
'is_development': version_info['is_dev'],
|
||||
'git_branch': version_info.get('git_branch', 'unknown'),
|
||||
'git_commit': version_info.get('git_commit', 'unknown'),
|
||||
'build_date': datetime.now().isoformat(),
|
||||
'python_version': f"{__import__('sys').version_info.major}.{__import__('sys').version_info.minor}.{__import__('sys').version_info.micro}"
|
||||
}
|
||||
|
||||
def _get_git_info(self) -> Dict[str, Any]:
|
||||
"""Get git repository information.
|
||||
|
||||
Returns:
|
||||
Dictionary with git information
|
||||
"""
|
||||
git_info = {'is_repo': False}
|
||||
|
||||
try:
|
||||
# Check if in git repo
|
||||
subprocess.run(['git', 'rev-parse', '--git-dir'],
|
||||
cwd=self.project_root, check=True, capture_output=True)
|
||||
git_info['is_repo'] = True
|
||||
|
||||
# Get branch
|
||||
try:
|
||||
result = subprocess.run(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||
cwd=self.project_root, capture_output=True, text=True, check=True)
|
||||
git_info['branch'] = result.stdout.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
git_info['branch'] = 'unknown'
|
||||
|
||||
# Get commit
|
||||
try:
|
||||
result = subprocess.run(['git', 'rev-parse', 'HEAD'],
|
||||
cwd=self.project_root, capture_output=True, text=True, check=True)
|
||||
git_info['commit'] = result.stdout.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
git_info['commit'] = 'unknown'
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
pass # Not a git repo
|
||||
|
||||
return git_info
|
||||
|
||||
|
||||
# Convenience functions for backward compatibility and easy import
|
||||
def get_version_info(project_root: Optional[Path] = None) -> Dict[str, Any]:
|
||||
"""Get version information using default VersionManager."""
|
||||
manager = VersionManager(project_root)
|
||||
return manager.get_version_info()
|
||||
|
||||
|
||||
def get_release_info(project_root: Optional[Path] = None) -> Dict[str, Any]:
|
||||
"""Get release information using default VersionManager."""
|
||||
manager = VersionManager(project_root)
|
||||
return manager.get_release_info()
|
||||
1
capabilities/testdrive-jsui
Submodule
1
capabilities/testdrive-jsui
Submodule
Submodule capabilities/testdrive-jsui added at 891d785533
7
cost_notes/25114-botched_refactoring_recovery.md
Normal file
7
cost_notes/25114-botched_refactoring_recovery.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Total cost: $18.34
|
||||
Total duration (API): 49m 10.0s
|
||||
Total duration (wall): 10h 38m 0.7s
|
||||
Total code changes: 6105 lines added, 186 lines removed
|
||||
Usage by model:
|
||||
claude-3-5-haiku: 58.3k input, 7.3k output, 0 cache read, 0 cache write ($0.0760)
|
||||
claude-sonnet: 9.1k input, 141.0k output, 31.7m cache read, 1.8m cache write ($18.27)
|
||||
212
demo_plugin_integration.py
Normal file
212
demo_plugin_integration.py
Normal file
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Demo script showing TestDrive JSUI plugin integration with Markitect
|
||||
|
||||
This script demonstrates:
|
||||
1. Plugin discovery and registration
|
||||
2. Asset management and deployment
|
||||
3. Standalone development vs production rendering
|
||||
4. Clean separation between Python and JavaScript
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
# Import the new plugin system
|
||||
from markitect.plugins import (
|
||||
PluginManager,
|
||||
RenderingEngineManager,
|
||||
RenderingConfig
|
||||
)
|
||||
from markitect.plugins.testdrive_jsui import TestDriveJSUIEngine
|
||||
|
||||
|
||||
def demo_standalone_development():
|
||||
"""Demo standalone development workflow."""
|
||||
print("🧪 Demonstrating Standalone Development Workflow")
|
||||
print("=" * 50)
|
||||
|
||||
# Initialize the TestDrive JSUI engine directly
|
||||
engine = TestDriveJSUIEngine()
|
||||
|
||||
# Read test content
|
||||
test_content_path = Path("testdrive-jsui/test-documents/sample.md")
|
||||
if test_content_path.exists():
|
||||
test_content = test_content_path.read_text()
|
||||
else:
|
||||
test_content = "# Demo Content\n\nThis is demo content for testing."
|
||||
|
||||
# Create standalone test document
|
||||
output_path = Path("/tmp/testdrive_standalone_demo.html")
|
||||
|
||||
print(f"📄 Creating standalone test document: {output_path}")
|
||||
|
||||
try:
|
||||
engine.create_standalone_test_document(test_content, output_path)
|
||||
print(f"✅ Success! Open in browser: file://{output_path}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error creating standalone document: {e}")
|
||||
|
||||
return engine
|
||||
|
||||
|
||||
def demo_plugin_discovery():
|
||||
"""Demo plugin discovery through the main system."""
|
||||
print("\n🔍 Demonstrating Plugin Discovery")
|
||||
print("=" * 50)
|
||||
|
||||
# Initialize plugin manager
|
||||
plugin_manager = PluginManager()
|
||||
|
||||
print("📋 Discovering all plugins...")
|
||||
all_plugins = plugin_manager.discover_plugins()
|
||||
|
||||
# Show all discovered plugins
|
||||
for plugin_name, plugin_info in all_plugins.items():
|
||||
print(f" 🔌 {plugin_name}: {plugin_info.get('type', 'unknown')}")
|
||||
|
||||
# Initialize rendering engine manager
|
||||
rendering_manager = RenderingEngineManager(plugin_manager)
|
||||
|
||||
print("\n🎨 Available rendering engines:")
|
||||
for engine_name in rendering_manager.list_engines():
|
||||
engine = rendering_manager.get_engine(engine_name)
|
||||
if engine:
|
||||
print(f" 🎯 {engine_name}: modes={engine.get_supported_modes()}")
|
||||
|
||||
return rendering_manager
|
||||
|
||||
|
||||
def demo_production_deployment():
|
||||
"""Demo production deployment with asset management."""
|
||||
print("\n🚀 Demonstrating Production Deployment")
|
||||
print("=" * 50)
|
||||
|
||||
# Create production configuration
|
||||
output_dir = Path("/tmp/demo_production_output")
|
||||
output_dir.mkdir(exist_ok=True)
|
||||
|
||||
config = RenderingConfig(
|
||||
asset_base_url="_markitect",
|
||||
development_mode=False,
|
||||
output_directory=output_dir
|
||||
)
|
||||
|
||||
# Initialize engine
|
||||
engine = TestDriveJSUIEngine()
|
||||
|
||||
# Demo content
|
||||
demo_content = """# Production Demo
|
||||
|
||||
This demonstrates production deployment of the TestDrive JSUI plugin.
|
||||
|
||||
## Features
|
||||
- Asset deployment to `_markitect/plugins/testdrive-jsui/`
|
||||
- Production-ready HTML generation
|
||||
- Clean JavaScript-Python separation
|
||||
|
||||
## Testing
|
||||
Open the generated HTML file to test the production deployment.
|
||||
"""
|
||||
|
||||
print(f"📁 Output directory: {output_dir}")
|
||||
print(f"🔧 Asset base URL: {config.asset_base_url}")
|
||||
|
||||
# Render document
|
||||
try:
|
||||
html_content = engine.render_document(demo_content, "edit", config)
|
||||
|
||||
# Save to output directory
|
||||
output_file = output_dir / "demo_production.html"
|
||||
output_file.write_text(html_content)
|
||||
|
||||
print(f"✅ Production document created: {output_file}")
|
||||
print(f"🌐 Open in browser: file://{output_file}")
|
||||
|
||||
# Show asset requirements
|
||||
assets = engine.get_required_assets()
|
||||
print(f"\n📦 Required assets:")
|
||||
for asset_type, asset_list in assets.items():
|
||||
print(f" {asset_type}: {len(asset_list)} files")
|
||||
for asset in asset_list[:3]: # Show first 3
|
||||
print(f" - {asset}")
|
||||
if len(asset_list) > 3:
|
||||
print(f" ... and {len(asset_list) - 3} more")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error in production deployment: {e}")
|
||||
|
||||
return output_dir
|
||||
|
||||
|
||||
def demo_asset_url_generation():
|
||||
"""Demo asset URL generation for different modes."""
|
||||
print("\n🔗 Demonstrating Asset URL Generation")
|
||||
print("=" * 50)
|
||||
|
||||
engine = TestDriveJSUIEngine()
|
||||
|
||||
# Development configuration
|
||||
dev_config = RenderingConfig(
|
||||
asset_base_url=".",
|
||||
development_mode=True,
|
||||
plugin_source_dirs={
|
||||
"testdrive-jsui": Path("testdrive-jsui")
|
||||
}
|
||||
)
|
||||
|
||||
# Production configuration
|
||||
prod_config = RenderingConfig(
|
||||
asset_base_url="_markitect",
|
||||
development_mode=False
|
||||
)
|
||||
|
||||
sample_assets = ["static/js/main.js", "static/css/editor.css", "images/icon.png"]
|
||||
|
||||
print("Development URLs:")
|
||||
for asset in sample_assets:
|
||||
url = dev_config.get_asset_url("testdrive-jsui", asset)
|
||||
print(f" {asset} → {url}")
|
||||
|
||||
print("\nProduction URLs:")
|
||||
for asset in sample_assets:
|
||||
url = prod_config.get_asset_url("testdrive-jsui", asset)
|
||||
print(f" {asset} → {url}")
|
||||
|
||||
# Show JSON config generation
|
||||
print(f"\nDevelopment JSON config:")
|
||||
print(dev_config.to_json_config("testdrive-jsui"))
|
||||
|
||||
|
||||
def main():
|
||||
"""Run all demo workflows."""
|
||||
print("🎯 TestDrive JSUI Plugin Integration Demo")
|
||||
print("🔬 Demonstrating JavaScript-first development approach")
|
||||
print("🏗️ Clean separation between Python and JavaScript\n")
|
||||
|
||||
try:
|
||||
# Demo workflows
|
||||
engine = demo_standalone_development()
|
||||
rendering_manager = demo_plugin_discovery()
|
||||
output_dir = demo_production_deployment()
|
||||
demo_asset_url_generation()
|
||||
|
||||
print(f"\n✅ All demos completed successfully!")
|
||||
print(f"🔬 Standalone test: testdrive-jsui/test.html")
|
||||
print(f"📄 Generated files in: {output_dir}")
|
||||
|
||||
# Show next steps
|
||||
print(f"\n📚 Next Steps:")
|
||||
print(f" 1. Open testdrive-jsui/test.html in browser for standalone dev")
|
||||
print(f" 2. Start development server: cd testdrive-jsui && python -m http.server 8080")
|
||||
print(f" 3. Integrate with markitect md-render command")
|
||||
print(f" 4. Add more rendering engines to the plugin system")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Demo failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
184
docs/CAPABILITIES_QUICK_REFERENCE.md
Normal file
184
docs/CAPABILITIES_QUICK_REFERENCE.md
Normal file
@@ -0,0 +1,184 @@
|
||||
# Capabilities Quick Reference
|
||||
|
||||
**⚠️ Critical:** Read [Capabilities Architecture](architecture/CAPABILITIES_ARCHITECTURE.md) for full details.
|
||||
|
||||
## Core Rules
|
||||
|
||||
### 🚫 **NEVER** Edit Capabilities from Main Repo
|
||||
|
||||
```bash
|
||||
# ❌ WRONG - Don't edit capability files from main repo
|
||||
cd /home/worsch/markitect_project/capabilities/testdrive-jsui
|
||||
vim src/testdrive_jsui/core.py # DON'T DO THIS!
|
||||
|
||||
# ✅ CORRECT - Use separate Claude instance/session
|
||||
# Open new terminal/Claude instance:
|
||||
git clone http://gitea/coulomb/testdrive-jsui.git /path/to/work
|
||||
cd /path/to/work/testdrive-jsui
|
||||
# Make changes, commit, push
|
||||
```
|
||||
|
||||
### 📦 Capabilities are Git Submodules
|
||||
|
||||
- Each capability = separate git repository
|
||||
- Located in `capabilities/` as submodules
|
||||
- Independent development lifecycle
|
||||
- Own versioning and releases
|
||||
|
||||
### 🔀 Use Separate Claude Instances
|
||||
|
||||
| Session | Purpose | Location |
|
||||
|---------|---------|----------|
|
||||
| **Main Repo** | Integration, configuration | `/home/worsch/markitect_project` |
|
||||
| **Capability** | Feature development, bugs | Separate clone or `capabilities/capability-name` |
|
||||
|
||||
**Why?** Prevents accidental cross-contamination and respects repository boundaries.
|
||||
|
||||
## Common Tasks
|
||||
|
||||
### Update Capability After Changes
|
||||
|
||||
```bash
|
||||
# After pushing changes to capability repo
|
||||
cd /home/worsch/markitect_project
|
||||
git submodule update --remote capabilities/testdrive-jsui
|
||||
git add capabilities/testdrive-jsui
|
||||
git commit -m "chore: update testdrive-jsui to latest"
|
||||
git push
|
||||
```
|
||||
|
||||
### Add New Capability
|
||||
|
||||
```bash
|
||||
cd /home/worsch/markitect_project
|
||||
|
||||
# Add as submodule
|
||||
git submodule add http://gitea/coulomb/new-capability.git capabilities/new-capability
|
||||
|
||||
# Add to pyproject.toml dependencies
|
||||
echo ' "new-capability @ file:./capabilities/new-capability",' >> pyproject.toml
|
||||
|
||||
# Commit
|
||||
git add .gitmodules capabilities/new-capability pyproject.toml
|
||||
git commit -m "feat: add new-capability submodule"
|
||||
```
|
||||
|
||||
### Work on Capability Feature
|
||||
|
||||
```bash
|
||||
# Option 1: In submodule directory (careful!)
|
||||
cd /home/worsch/markitect_project/capabilities/testdrive-jsui
|
||||
git checkout -b feature-branch
|
||||
# make changes
|
||||
git commit -m "feat: new feature"
|
||||
git push origin feature-branch
|
||||
|
||||
# Option 2: Separate clone (recommended)
|
||||
cd ~/projects
|
||||
git clone http://gitea/coulomb/testdrive-jsui.git
|
||||
cd testdrive-jsui
|
||||
git checkout -b feature-branch
|
||||
# make changes
|
||||
git commit -m "feat: new feature"
|
||||
git push origin feature-branch
|
||||
```
|
||||
|
||||
### Check Capability Status
|
||||
|
||||
```bash
|
||||
cd /home/worsch/markitect_project
|
||||
|
||||
# List all capabilities
|
||||
make capabilities-list
|
||||
|
||||
# Check submodule status
|
||||
git submodule status
|
||||
|
||||
# See which commit each capability is at
|
||||
git submodule foreach 'git log --oneline -1'
|
||||
```
|
||||
|
||||
## Integration Patterns
|
||||
|
||||
### Python Import
|
||||
|
||||
```python
|
||||
# ✅ Correct - Import from capability package
|
||||
from testdrive_jsui import TestDriveJSUIEngine
|
||||
|
||||
engine = TestDriveJSUIEngine()
|
||||
```
|
||||
|
||||
### Dependency Declaration
|
||||
|
||||
```toml
|
||||
# pyproject.toml
|
||||
dependencies = [
|
||||
"testdrive-jsui @ file:./capabilities/testdrive-jsui",
|
||||
]
|
||||
```
|
||||
|
||||
### Plugin Self-Declaration
|
||||
|
||||
```python
|
||||
# ✅ Good - Plugin declares its own location
|
||||
def get_plugin_source_dir(self) -> Path:
|
||||
return Path(__file__).parent.parent.parent / "capabilities" / "testdrive-jsui"
|
||||
|
||||
# ❌ Bad - Hardcoded in main repo
|
||||
if plugin_name == 'testdrive-jsui':
|
||||
return Path('capabilities/testdrive-jsui')
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### "Submodule not initialized"
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
### "Import error: No module named 'capability_name'"
|
||||
|
||||
```bash
|
||||
pip install -e ./capabilities/capability-name
|
||||
# or
|
||||
pip install -e . # Install all dependencies
|
||||
```
|
||||
|
||||
### "Merge conflict in submodule"
|
||||
|
||||
```bash
|
||||
# Don't resolve in main repo!
|
||||
# Go to capability repo and resolve there
|
||||
cd capabilities/testdrive-jsui
|
||||
git pull origin main
|
||||
# Resolve conflicts, commit, push
|
||||
|
||||
cd ../..
|
||||
git submodule update --remote capabilities/testdrive-jsui
|
||||
git add capabilities/testdrive-jsui
|
||||
git commit -m "chore: update testdrive-jsui after conflict resolution"
|
||||
```
|
||||
|
||||
## Current Capabilities
|
||||
|
||||
| Capability | Type | Repository | Status |
|
||||
|------------|------|------------|--------|
|
||||
| **testdrive-jsui** | Rendering Engine | `coulomb/testdrive-jsui` | ✅ Submodule |
|
||||
| **issue-facade** | CLI Tool | `coulomb/issue-facade` | ✅ Submodule |
|
||||
| **kaizen-agentic** | Framework | `coulomb/kaizen-agentic` | ✅ Submodule |
|
||||
| **release-management** | Tool | Local | 📦 To migrate |
|
||||
| **markitect-content** | Library | Local | 📦 To migrate |
|
||||
|
||||
## Key Principles
|
||||
|
||||
1. **Separation of Concerns** - Main repo doesn't modify capabilities
|
||||
2. **Independent Development** - Each capability has own lifecycle
|
||||
3. **Interface-Based Integration** - Use documented APIs only
|
||||
4. **Version Control** - Git submodules for dependency management
|
||||
5. **Session Isolation** - Separate Claude instances per repository
|
||||
|
||||
---
|
||||
|
||||
**📖 Full Documentation:** [Capabilities Architecture](architecture/CAPABILITIES_ARCHITECTURE.md)
|
||||
174
docs/DOCUMENT_NAVIGATOR_INTEGRATION.md
Normal file
174
docs/DOCUMENT_NAVIGATOR_INTEGRATION.md
Normal file
@@ -0,0 +1,174 @@
|
||||
# DocumentNavigator Integration Guide
|
||||
|
||||
## TDD Implementation Complete ✅
|
||||
|
||||
The DocumentNavigator widget has been successfully implemented following Test-Driven Development methodology:
|
||||
|
||||
### ✅ **Completed Components**
|
||||
|
||||
1. **Base Architecture** (`js/widgets/base/`)
|
||||
- `Widget.js` - Core widget functionality with events and state
|
||||
- `UIWidget.js` - DOM manipulation and visual behavior
|
||||
|
||||
2. **DocumentNavigator Widget** (`js/widgets/navigation/DocumentNavigator.js`)
|
||||
- Substack-style floating navigation panel
|
||||
- Hierarchical heading extraction and tree building
|
||||
- Expand/collapse with smooth animations
|
||||
- Scroll spy with current section highlighting
|
||||
- Responsive behavior (auto-hide on mobile)
|
||||
- Keyboard navigation support
|
||||
- Smooth scrolling to sections
|
||||
|
||||
3. **Plugin Definition** (`js/plugins/document-navigator-plugin.js`)
|
||||
- Complete plugin metadata and configuration
|
||||
- Lazy loading support
|
||||
- Theme variants (default, dark, minimal)
|
||||
- Usage examples and development helpers
|
||||
|
||||
4. **TDD Test Suite** (`js/tests/test-document-navigator.js`)
|
||||
- Comprehensive test coverage (15 test cases)
|
||||
- Browser-based test runner included
|
||||
- Tests all functionality: rendering, navigation, scroll spy, responsive behavior
|
||||
|
||||
## Integration with HTML Rendering
|
||||
|
||||
To integrate the DocumentNavigator into all rendered markdown documents, add the following to the HTML template in `CleanDocumentManager._generate_html_template()`:
|
||||
|
||||
### **Method 1: Simple Integration (Immediate Use)**
|
||||
|
||||
Add this JavaScript after the existing component initialization:
|
||||
|
||||
```javascript
|
||||
// Add DocumentNavigator initialization after existing components
|
||||
// (Insert around line 1050 in clean_document_manager.py, after documentControls.create())
|
||||
|
||||
// Initialize DocumentNavigator if headings are present
|
||||
try {
|
||||
// Import the widget classes (using dynamic imports for future plugin system)
|
||||
const documentNavigator = new DocumentNavigator({
|
||||
container: document.getElementById('markdown-content') || document.body,
|
||||
position: 'left',
|
||||
collapsed: true,
|
||||
theme: '${template or "default"}', // Use current document theme
|
||||
enableScrollSpy: true,
|
||||
autoHide: true
|
||||
});
|
||||
|
||||
// Initialize and render
|
||||
documentNavigator.initialize().then(() => {
|
||||
return documentNavigator.render();
|
||||
}).then(() => {
|
||||
console.log('✓ DocumentNavigator initialized successfully');
|
||||
}).catch(error => {
|
||||
console.warn('DocumentNavigator initialization failed:', error.message);
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('DocumentNavigator not available:', error.message);
|
||||
}
|
||||
```
|
||||
|
||||
### **Method 2: Plugin System Integration (Future-Ready)**
|
||||
|
||||
For the full plugin architecture, the initialization would look like:
|
||||
|
||||
```javascript
|
||||
// Future plugin system integration
|
||||
if (typeof widgetSystem !== 'undefined') {
|
||||
widgetSystem.createWidget('DocumentNavigator', {
|
||||
theme: '${template or "default"}',
|
||||
position: 'left'
|
||||
}).then(navigator => {
|
||||
return navigator.show();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Once integrated, the DocumentNavigator will:
|
||||
|
||||
1. **Auto-detect headings** in the rendered markdown content
|
||||
2. **Show collapsed toggle** on the left side (hamburger menu icon)
|
||||
3. **Expand on click** to reveal table of contents
|
||||
4. **Highlight current section** as user scrolls
|
||||
5. **Navigate smoothly** when headings are clicked
|
||||
6. **Auto-hide on mobile** devices
|
||||
7. **Support keyboard navigation** (Enter/Space to toggle, Escape to collapse)
|
||||
|
||||
## Testing
|
||||
|
||||
To test the implementation:
|
||||
|
||||
1. **Run TDD Test Suite**:
|
||||
```bash
|
||||
# Start local server
|
||||
cd markitect/static/js/tests
|
||||
python -m http.server 8080
|
||||
|
||||
# Open browser to: http://localhost:8080/test-document-navigator-runner.html
|
||||
# Click "Run TDD Test Suite" button
|
||||
```
|
||||
|
||||
2. **Test with Real Content**:
|
||||
```bash
|
||||
# Create test markdown with headings
|
||||
echo "# Chapter 1
|
||||
## Section 1.1
|
||||
### Subsection 1.1.1
|
||||
## Section 1.2
|
||||
# Chapter 2" > test-doc.md
|
||||
|
||||
# Render with navigator
|
||||
markitect md-render test-doc.md --output test-doc.html
|
||||
```
|
||||
|
||||
## Configuration Options
|
||||
|
||||
The DocumentNavigator supports extensive customization:
|
||||
|
||||
```javascript
|
||||
const navigator = new DocumentNavigator({
|
||||
position: 'left', // 'left' or 'right'
|
||||
collapsed: true, // Start collapsed
|
||||
autoHide: true, // Hide on mobile
|
||||
maxHeadingLevel: 3, // H1, H2, H3
|
||||
enableScrollSpy: true, // Highlight current section
|
||||
smoothScroll: true, // Smooth scroll animation
|
||||
theme: 'default', // 'default', 'dark', 'minimal'
|
||||
width: '280px', // Expanded width
|
||||
offset: { top: '80px', side: '20px' }
|
||||
});
|
||||
```
|
||||
|
||||
## Theme Integration
|
||||
|
||||
The navigator automatically adapts to document themes:
|
||||
|
||||
- **Default Theme**: Clean white background with subtle shadows
|
||||
- **Dark Theme**: Dark background with light text
|
||||
- **Substack Theme**: Warm cream colors matching document style
|
||||
- **Academic Theme**: Traditional academic styling
|
||||
- **ChatGPT Theme**: Modern compact layout
|
||||
|
||||
## Performance
|
||||
|
||||
- **Lazy Loading**: Widget loads only when headings are detected
|
||||
- **Efficient Scroll Spy**: Throttled scroll events (100ms)
|
||||
- **Responsive**: Automatically hides on mobile to save space
|
||||
- **Memory Efficient**: Proper cleanup on destroy
|
||||
|
||||
## Browser Support
|
||||
|
||||
- **Modern Browsers**: Chrome 80+, Firefox 75+, Safari 13+, Edge 80+
|
||||
- **ES6 Modules**: Uses dynamic imports (can be transpiled for older browsers)
|
||||
- **Progressive Enhancement**: Gracefully degrades if JavaScript fails
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Add to HTML Template**: Integrate the JavaScript code into `CleanDocumentManager._generate_html_template()`
|
||||
2. **Test Integration**: Verify navigator appears in rendered documents
|
||||
3. **Theme Refinement**: Adjust colors to perfectly match document themes
|
||||
4. **Plugin System**: Implement full plugin architecture for future extensibility
|
||||
5. **Performance Optimization**: Add preloading and caching optimizations
|
||||
|
||||
The DocumentNavigator widget is production-ready and provides a professional Substack-style navigation experience for all markdown documents rendered by Markitect.
|
||||
263
docs/ERROR_HANDLING_STRATEGY.md
Normal file
263
docs/ERROR_HANDLING_STRATEGY.md
Normal file
@@ -0,0 +1,263 @@
|
||||
# Error Handling Strategy: Fail Fast + Robustness Balance
|
||||
|
||||
## Overview
|
||||
|
||||
This document defines the balanced error handling strategy that combines **Fail Fast** principles for development with **Robustness Principles** for production, preventing both cascading failures and difficult diagnosis.
|
||||
|
||||
## Core Philosophy
|
||||
|
||||
### 🚨 **Development Mode (Fail Fast)**
|
||||
- **Immediate failure** on errors for fast debugging
|
||||
- **Strict validation** with exceptions on invalid input
|
||||
- **No silent failures** - all problems surface immediately
|
||||
- **Clear error messages** with full context
|
||||
|
||||
### 🛡️ **Production Mode (Robust)**
|
||||
- **Graceful degradation** when components fail
|
||||
- **Fallback behaviors** for non-critical failures
|
||||
- **Silent recovery** for user experience
|
||||
- **Detailed logging** for post-mortem analysis
|
||||
|
||||
## Implementation Strategy
|
||||
|
||||
### Mode Detection
|
||||
```javascript
|
||||
const MARKITECT_STRICT_MODE = (
|
||||
window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === '127.0.0.1' ||
|
||||
window.location.search.includes('strict=true') ||
|
||||
window.markitectStrictMode === true
|
||||
);
|
||||
```
|
||||
|
||||
### Dual-Behavior Error Handling
|
||||
```javascript
|
||||
safeOperation: function(operation, fallback = null, context = 'Unknown') {
|
||||
try {
|
||||
return operation();
|
||||
} catch (error) {
|
||||
console.warn(`Operation failed in ${context}:`, error);
|
||||
|
||||
// Fail Fast in development mode
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
console.error(`🚨 STRICT MODE: Operation failed in ${context}`);
|
||||
throw error; // Re-throw for immediate debugging
|
||||
}
|
||||
|
||||
// Robust handling in production
|
||||
if (window.MarkitectDebugSystem) {
|
||||
window.MarkitectDebugSystem.addMessage(
|
||||
`Safe operation failed: ${error.message}`,
|
||||
'WARNING',
|
||||
'System',
|
||||
{ context, eventType: 'ERROR' }
|
||||
);
|
||||
}
|
||||
return typeof fallback === 'function' ? fallback() : fallback;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Error Categories & Responses
|
||||
|
||||
### 1. **Critical System Errors**
|
||||
| Error Type | Development Response | Production Response |
|
||||
|------------|---------------------|-------------------|
|
||||
| Missing Dependencies | `throw Error()` immediately | Skip with warning, continue |
|
||||
| Invalid Configuration | `throw Error()` immediately | Use defaults, log error |
|
||||
| DOM Not Ready | `throw Error()` immediately | Retry with timeout |
|
||||
|
||||
### 2. **Input Validation Errors**
|
||||
| Error Type | Development Response | Production Response |
|
||||
|------------|---------------------|-------------------|
|
||||
| Malformed Data | `throw Error()` with details | Sanitize and continue |
|
||||
| Oversized Input | `throw Error()` immediately | Truncate with warning |
|
||||
| Invalid Selectors | `throw Error()` with context | Return null, log warning |
|
||||
|
||||
### 3. **Resource Errors**
|
||||
| Error Type | Development Response | Production Response |
|
||||
|------------|---------------------|-------------------|
|
||||
| Memory Exhaustion | `throw Error()` to prevent hang | Apply limits, degrade features |
|
||||
| Network Failures | `throw Error()` for debugging | Use cached data, retry logic |
|
||||
| Timeout Exceeded | `throw Error()` immediately | Cancel operation, fallback |
|
||||
|
||||
### 4. **UI Component Errors**
|
||||
| Error Type | Development Response | Production Response |
|
||||
|------------|---------------------|-------------------|
|
||||
| Control Creation Failed | `throw Error()` with stack | Create minimal fallback |
|
||||
| DOM Manipulation Failed | `throw Error()` with element | Skip operation, continue |
|
||||
| Event Handler Error | `throw Error()` to debug | Log error, disable feature |
|
||||
|
||||
## Logging Strategy
|
||||
|
||||
### Development Mode
|
||||
```javascript
|
||||
// Immediate console errors
|
||||
console.error(`🚨 STRICT MODE: ${message}`);
|
||||
throw new Error(message);
|
||||
```
|
||||
|
||||
### Production Mode
|
||||
```javascript
|
||||
// Silent logging with context
|
||||
window.MarkitectDebugSystem.addMessage(
|
||||
message,
|
||||
'ERROR',
|
||||
component,
|
||||
{ context, stackTrace: error.stack }
|
||||
);
|
||||
|
||||
// User-friendly fallbacks
|
||||
return fallbackValue || defaultBehavior();
|
||||
```
|
||||
|
||||
## Testing Approach
|
||||
|
||||
### Development Testing
|
||||
- **Error Injection**: Intentionally trigger failures
|
||||
- **Boundary Testing**: Test limits and edge cases
|
||||
- **Dependency Mocking**: Remove required components
|
||||
- **Strict Validation**: Ensure all errors surface
|
||||
|
||||
### Production Testing
|
||||
- **Graceful Degradation**: Verify fallbacks work
|
||||
- **Performance Under Load**: Stress test with errors
|
||||
- **User Experience**: No broken interfaces
|
||||
- **Recovery Scenarios**: System self-healing
|
||||
|
||||
## Implementation Examples
|
||||
|
||||
### Control Initialization
|
||||
```javascript
|
||||
initializeControl: function(controlClass, controlName, icon = '🔧') {
|
||||
try {
|
||||
if (!controlClass) {
|
||||
const message = `${controlName} class not available`;
|
||||
|
||||
// Fail Fast in development
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
// Graceful in production
|
||||
console.warn(message);
|
||||
return this.createFallbackControl(controlName, icon);
|
||||
}
|
||||
|
||||
return new controlClass().createControl();
|
||||
} catch (error) {
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
throw error; // Let it bubble up
|
||||
}
|
||||
|
||||
// Production: log and continue
|
||||
this.logError(error, controlName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Input Validation
|
||||
```javascript
|
||||
validateAndSanitize: function(input, maxLength = 1000) {
|
||||
if (typeof input !== 'string') {
|
||||
const error = new TypeError('Input must be string');
|
||||
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return String(input).slice(0, maxLength);
|
||||
}
|
||||
|
||||
if (input.length > maxLength) {
|
||||
const error = new Error(`Input exceeds ${maxLength} characters`);
|
||||
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.warn('Input truncated to fit limits');
|
||||
return input.slice(0, maxLength);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
```
|
||||
|
||||
## Benefits
|
||||
|
||||
### 🚀 **Development Benefits**
|
||||
- **Fast Problem Discovery**: Errors surface immediately
|
||||
- **Clear Error Context**: Full stack traces and details
|
||||
- **Prevents Technical Debt**: Forces proper error handling
|
||||
- **Debugging Efficiency**: No need to backtrack from symptoms
|
||||
|
||||
### 🛡️ **Production Benefits**
|
||||
- **System Stability**: Graceful degradation prevents crashes
|
||||
- **User Experience**: No broken interfaces or white screens
|
||||
- **Self-Healing**: Automatic fallbacks and recovery
|
||||
- **Operational Monitoring**: Detailed error telemetry
|
||||
|
||||
### ⚖️ **Balance Benefits**
|
||||
- **Best of Both Worlds**: Development speed + Production stability
|
||||
- **Context-Appropriate**: Right behavior for the right environment
|
||||
- **Maintainable**: Clear patterns and consistent implementation
|
||||
- **Scalable**: Works from development to enterprise deployment
|
||||
|
||||
## Activation Guide
|
||||
|
||||
### Automatic Detection
|
||||
- `localhost` and `127.0.0.1` automatically enable strict mode
|
||||
- URL parameter `?strict=true` forces strict mode
|
||||
- Global flag `window.markitectStrictMode = true`
|
||||
|
||||
### Manual Control
|
||||
```javascript
|
||||
// Force strict mode for testing
|
||||
window.markitectStrictMode = true;
|
||||
|
||||
// Force production mode (disable strict)
|
||||
window.markitectStrictMode = false;
|
||||
```
|
||||
|
||||
### Environment Configuration
|
||||
```javascript
|
||||
// In development builds
|
||||
const DEVELOPMENT_BUILD = true;
|
||||
const MARKITECT_STRICT_MODE = DEVELOPMENT_BUILD || detectDevelopmentEnvironment();
|
||||
|
||||
// In production builds
|
||||
const DEVELOPMENT_BUILD = false;
|
||||
const MARKITECT_STRICT_MODE = false; // Always robust in production
|
||||
```
|
||||
|
||||
## Monitoring & Metrics
|
||||
|
||||
### Development Metrics
|
||||
- **Error Count**: Number of strict mode exceptions
|
||||
- **Error Categories**: Types of failures encountered
|
||||
- **Resolution Time**: Time to fix after error discovery
|
||||
- **Test Coverage**: Percentage of error paths tested
|
||||
|
||||
### Production Metrics
|
||||
- **Fallback Usage**: How often graceful degradation occurs
|
||||
- **Recovery Success**: Percentage of successful recoveries
|
||||
- **User Impact**: Features disabled vs. core functionality maintained
|
||||
- **Error Patterns**: Common failure modes for improvement
|
||||
|
||||
## Future Evolution
|
||||
|
||||
### Enhanced Detection
|
||||
- **CI/CD Integration**: Automatic strict mode in testing pipelines
|
||||
- **Feature Flags**: Remote control of error handling behavior
|
||||
- **A/B Testing**: Compare error handling strategies
|
||||
- **Machine Learning**: Predict and prevent common failures
|
||||
|
||||
### Advanced Recovery
|
||||
- **Smart Fallbacks**: Context-aware recovery strategies
|
||||
- **Progressive Enhancement**: Gradually restore failed features
|
||||
- **User Notification**: Inform users of degraded functionality
|
||||
- **Automatic Reporting**: Send error telemetry to development team
|
||||
|
||||
This balanced approach ensures we catch problems early in development while maintaining a bulletproof production experience.
|
||||
492
docs/PLUGIN_SYSTEM.md
Normal file
492
docs/PLUGIN_SYSTEM.md
Normal file
@@ -0,0 +1,492 @@
|
||||
# Markitect Plugin System Documentation
|
||||
|
||||
## Overview
|
||||
|
||||
The Markitect plugin system provides a modular architecture for extending rendering capabilities with independent JavaScript UI components. This system enables JavaScript-first development while maintaining clean integration with the Python ecosystem.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Core Components
|
||||
|
||||
1. **RenderingEnginePlugin**: Base class for UI rendering engines
|
||||
2. **RenderingConfig**: Asset management and deployment configuration
|
||||
3. **RenderingEngineManager**: Plugin discovery and lifecycle management
|
||||
4. **PluginManager**: Integration with existing Markitect plugin system
|
||||
|
||||
### Key Features
|
||||
|
||||
- **Clean Separation**: JSON-based configuration interface (Python ↔ JavaScript)
|
||||
- **Independent Development**: JavaScript components work standalone
|
||||
- **Asset Management**: Configurable deployment strategies
|
||||
- **Multiple Engines**: Support for different UI frameworks
|
||||
- **Fallback Support**: Graceful degradation to standard rendering
|
||||
|
||||
## Plugin Development
|
||||
|
||||
### Creating a Rendering Engine Plugin
|
||||
|
||||
1. **Extend RenderingEnginePlugin**:
|
||||
|
||||
```python
|
||||
from markitect.plugins.rendering import RenderingEnginePlugin, RenderingConfig
|
||||
from markitect.plugins.base import PluginMetadata, PluginType
|
||||
|
||||
class MyUIEngine(RenderingEnginePlugin):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._metadata = PluginMetadata(
|
||||
name="my-ui-engine",
|
||||
version="1.0.0",
|
||||
description="Custom UI rendering engine",
|
||||
author="Your Name",
|
||||
plugin_type=PluginType.RENDERING
|
||||
)
|
||||
|
||||
@property
|
||||
def metadata(self) -> PluginMetadata:
|
||||
return self._metadata
|
||||
|
||||
def get_supported_modes(self) -> List[str]:
|
||||
return ["edit", "view"]
|
||||
|
||||
def get_required_assets(self) -> Dict[str, List[str]]:
|
||||
return {
|
||||
"js": ["static/js/main.js"],
|
||||
"css": ["static/css/style.css"]
|
||||
}
|
||||
|
||||
def render_document(self, content: str, mode: str, config: RenderingConfig) -> str:
|
||||
# Your rendering logic here
|
||||
return html_output
|
||||
```
|
||||
|
||||
2. **Directory Structure**:
|
||||
|
||||
```
|
||||
my-ui-engine/
|
||||
├── static/
|
||||
│ ├── js/ # JavaScript components
|
||||
│ └── css/ # Stylesheets
|
||||
├── templates/ # HTML templates
|
||||
├── images/ # Icons and images
|
||||
├── test-documents/ # Sample markdown files
|
||||
├── package.json # Node.js configuration
|
||||
└── README.md # Plugin documentation
|
||||
```
|
||||
|
||||
3. **Asset Management**:
|
||||
|
||||
Assets are automatically deployed based on configuration:
|
||||
- **Development**: Served from plugin source directory
|
||||
- **Production**: Copied to `_markitect/plugins/{plugin-name}/`
|
||||
|
||||
## TestDrive JSUI Plugin
|
||||
|
||||
### Overview
|
||||
|
||||
The TestDrive JSUI plugin demonstrates the plugin architecture with a complete JavaScript UI for markdown editing.
|
||||
|
||||
### Features
|
||||
|
||||
- **Modular Components**: Clean separation of UI components
|
||||
- **Compass Positioning**: NW, NE, E, SE control panel layout
|
||||
- **Section Management**: Click-to-edit markdown sections
|
||||
- **Debug System**: Built-in debugging and logging
|
||||
- **Asset Pipeline**: Configurable asset deployment
|
||||
|
||||
### Directory Structure
|
||||
|
||||
```
|
||||
testdrive-jsui/
|
||||
├── static/js/
|
||||
│ ├── core/ # Core systems
|
||||
│ │ ├── debug-system.js
|
||||
│ │ └── section-manager.js
|
||||
│ ├── components/ # UI components
|
||||
│ │ ├── debug-panel.js
|
||||
│ │ ├── document-controls.js
|
||||
│ │ └── dom-renderer.js
|
||||
│ ├── controls/ # Control panels
|
||||
│ │ ├── control-base.js
|
||||
│ │ ├── contents-control.js # Northwest
|
||||
│ │ ├── status-control.js # East
|
||||
│ │ ├── debug-control.js # Southeast
|
||||
│ │ └── edit-control.js # Northeast
|
||||
│ ├── config-loader.js # Configuration interface
|
||||
│ └── main-updated.js # Application entry point
|
||||
├── static/css/ # Stylesheets (future)
|
||||
├── images/ # Icons and images (future)
|
||||
├── templates/
|
||||
│ └── index.html # Main HTML template
|
||||
├── test-documents/
|
||||
│ └── sample.md # Test content
|
||||
├── test.html # Standalone development
|
||||
├── package.json # Node.js configuration
|
||||
└── README.md # Plugin documentation
|
||||
```
|
||||
|
||||
### JavaScript Architecture
|
||||
|
||||
- **Configuration Interface**: Clean JSON data transfer via `markitect-config` script element
|
||||
- **Modular Components**: Each component has single responsibility
|
||||
- **Event System**: Pub/sub for component communication
|
||||
- **Control System**: Abstract base class for UI controls
|
||||
- **Compass Positioning**: Consistent control panel layout
|
||||
|
||||
## CLI Integration
|
||||
|
||||
### Command Line Usage
|
||||
|
||||
```bash
|
||||
# Use default engine (testdrive-jsui for edit/insert, standard for view)
|
||||
markitect md-render --edit document.md
|
||||
|
||||
# Specify engine explicitly
|
||||
markitect md-render --engine testdrive-jsui --edit document.md
|
||||
|
||||
# Use standard engine
|
||||
markitect md-render --engine standard --edit document.md
|
||||
|
||||
# View available engines
|
||||
markitect md-render --help
|
||||
```
|
||||
|
||||
### Engine Selection Logic
|
||||
|
||||
1. **Default Selection**:
|
||||
- Edit/Insert modes: `testdrive-jsui`
|
||||
- View mode: `standard`
|
||||
|
||||
2. **Explicit Selection**: Use `--engine` parameter
|
||||
|
||||
3. **Fallback Strategy**:
|
||||
- Engine not found → fallback to standard
|
||||
- Mode not supported → fallback to standard
|
||||
- Plugin error → fallback to standard
|
||||
|
||||
### Integration Points
|
||||
|
||||
The CLI integrates with the plugin system through:
|
||||
|
||||
```python
|
||||
# Engine discovery
|
||||
plugin_manager = PluginManager()
|
||||
rendering_manager = RenderingEngineManager(plugin_manager)
|
||||
|
||||
# Engine selection
|
||||
engine = rendering_manager.get_engine(engine_name)
|
||||
|
||||
# Configuration
|
||||
config = RenderingConfig(
|
||||
asset_base_url="_markitect",
|
||||
development_mode=False,
|
||||
output_directory=output_path.parent
|
||||
)
|
||||
|
||||
# Rendering
|
||||
html_content = engine.render_document(content, mode, config)
|
||||
```
|
||||
|
||||
## Development Workflows
|
||||
|
||||
### Standalone JavaScript Development
|
||||
|
||||
1. **Setup**:
|
||||
```bash
|
||||
cd testdrive-jsui
|
||||
python -m http.server 8080
|
||||
```
|
||||
|
||||
2. **Development**:
|
||||
- Edit JavaScript files in `static/js/`
|
||||
- Refresh browser to see changes
|
||||
- Use `test.html` for testing
|
||||
- Browser DevTools for debugging
|
||||
|
||||
3. **Benefits**:
|
||||
- No Python environment required
|
||||
- Fast iteration cycle
|
||||
- Standard web development tools
|
||||
- Hot reloading
|
||||
|
||||
### Integrated Development
|
||||
|
||||
1. **Plugin Testing**:
|
||||
```bash
|
||||
python demo_plugin_integration.py
|
||||
```
|
||||
|
||||
2. **CLI Testing**:
|
||||
```bash
|
||||
markitect md-render --engine testdrive-jsui --edit test.md
|
||||
```
|
||||
|
||||
3. **Integration Verification**:
|
||||
```bash
|
||||
python test_complete_integration.py
|
||||
```
|
||||
|
||||
## Asset Management
|
||||
|
||||
### Development Mode
|
||||
|
||||
```python
|
||||
config = RenderingConfig(
|
||||
asset_base_url=".",
|
||||
development_mode=True,
|
||||
plugin_source_dirs={"testdrive-jsui": Path("testdrive-jsui")}
|
||||
)
|
||||
|
||||
# Assets served as: file://testdrive-jsui/static/js/main.js
|
||||
```
|
||||
|
||||
### Production Mode
|
||||
|
||||
```python
|
||||
config = RenderingConfig(
|
||||
asset_base_url="_markitect",
|
||||
development_mode=False,
|
||||
output_directory=Path("/output")
|
||||
)
|
||||
|
||||
# Assets served as: _markitect/plugins/testdrive-jsui/static/js/main.js
|
||||
```
|
||||
|
||||
### Asset Types
|
||||
|
||||
- **js**: JavaScript files
|
||||
- **css**: Stylesheets
|
||||
- **images**: Icons, graphics
|
||||
- **external**: CDN resources
|
||||
|
||||
### Deployment Strategy
|
||||
|
||||
1. **Assets Copying**: Plugin assets copied to `_markitect/plugins/{name}/`
|
||||
2. **URL Generation**: Automatic URL generation for templates
|
||||
3. **Cache Management**: Asset versioning and cache control
|
||||
4. **Error Handling**: Fallback for missing assets
|
||||
|
||||
### Asset Deployment Process
|
||||
|
||||
When using CLI with plugin engines, assets are automatically deployed:
|
||||
|
||||
```bash
|
||||
# Assets are deployed to output directory when using plugin engines
|
||||
markitect md-render --edit document.md --output /path/to/output.html
|
||||
|
||||
# Output structure:
|
||||
# /path/to/
|
||||
# ├── output.html
|
||||
# └── _markitect/
|
||||
# └── plugins/
|
||||
# └── testdrive-jsui/
|
||||
# ├── static/
|
||||
# │ ├── js/ # 12 JavaScript files
|
||||
# │ └── css/ # 3 CSS files
|
||||
# └── images/ # 3 image files
|
||||
```
|
||||
|
||||
The deployment process:
|
||||
|
||||
1. **Plugin Discovery**: Engine identified (default: testdrive-jsui for edit mode)
|
||||
2. **Asset Analysis**: Required assets determined from `get_required_assets()`
|
||||
3. **Source Resolution**: Plugin source directory located
|
||||
4. **File Copying**: Assets copied with directory structure preservation
|
||||
5. **URL Generation**: HTML references generated with correct paths
|
||||
6. **Verification**: Asset accessibility validated
|
||||
|
||||
Example output:
|
||||
```
|
||||
🎯 Using rendering engine: testdrive-jsui (supports: edit, view)
|
||||
📦 Deploying assets for engine 'testdrive-jsui'...
|
||||
📄 Deployed 18 asset files
|
||||
js: 12 files
|
||||
css: 3 files
|
||||
images: 3 files
|
||||
✅ Rendered with INTERACTIVE editing mode to: output.html
|
||||
```
|
||||
|
||||
## Configuration Interface
|
||||
|
||||
### Python → JavaScript Data Transfer
|
||||
|
||||
All dynamic data passes through a clean JSON interface:
|
||||
|
||||
```html
|
||||
<script id="markitect-config" type="application/json">
|
||||
{
|
||||
"markdownContent": "# Document content...",
|
||||
"mode": "edit",
|
||||
"theme": "github",
|
||||
"keyboardShortcuts": true,
|
||||
"originalFilename": "document.md",
|
||||
"version": "Markitect v0.8.1"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
### JavaScript Configuration Loading
|
||||
|
||||
```javascript
|
||||
// Clean configuration loading
|
||||
class MarkitectConfig {
|
||||
constructor() {
|
||||
this.loadConfig();
|
||||
}
|
||||
|
||||
loadConfig() {
|
||||
const configElement = document.getElementById('markitect-config');
|
||||
this.config = JSON.parse(configElement.textContent);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Benefits
|
||||
|
||||
- **No String Interpolation**: Prevents template literal escaping issues
|
||||
- **Type Safety**: JSON validation and error handling
|
||||
- **Clean Separation**: No JavaScript code in Python strings
|
||||
- **Debuggable**: Easy to inspect configuration in browser
|
||||
|
||||
## Testing
|
||||
|
||||
### Plugin Testing
|
||||
|
||||
```bash
|
||||
# Basic plugin discovery
|
||||
python test_plugin_discovery.py
|
||||
|
||||
# CLI integration logic
|
||||
python test_cli_simple.py
|
||||
|
||||
# Complete scenario testing
|
||||
python test_complete_integration.py
|
||||
|
||||
# Full integration demo
|
||||
python demo_plugin_integration.py
|
||||
```
|
||||
|
||||
### Browser Testing
|
||||
|
||||
1. **Standalone**: Open `testdrive-jsui/test.html`
|
||||
2. **Generated**: Open CLI-generated HTML files
|
||||
3. **DevTools**: Use browser debugging tools
|
||||
4. **Console**: Check for JavaScript errors
|
||||
|
||||
### Integration Testing
|
||||
|
||||
- **Unit Tests**: Individual component testing
|
||||
- **Integration Tests**: Component interaction testing
|
||||
- **E2E Tests**: Full workflow testing
|
||||
- **Regression Tests**: Ensure stability across changes
|
||||
|
||||
## Extension Points
|
||||
|
||||
### Adding New Engines
|
||||
|
||||
1. Create new plugin extending `RenderingEnginePlugin`
|
||||
2. Implement required methods (`get_supported_modes`, `render_document`, etc.)
|
||||
3. Register in `RenderingEngineManager._register_builtin_rendering_engines()`
|
||||
4. Test with CLI integration
|
||||
|
||||
### Adding New Modes
|
||||
|
||||
1. Add mode to engine's `get_supported_modes()`
|
||||
2. Update `render_document()` to handle new mode
|
||||
3. Test mode validation and rendering
|
||||
4. Update CLI integration if needed
|
||||
|
||||
### Adding New Asset Types
|
||||
|
||||
1. Update `get_required_assets()` return format
|
||||
2. Modify asset deployment logic in `RenderingConfig`
|
||||
3. Update template system to handle new asset types
|
||||
4. Test asset URL generation
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Plugin Development
|
||||
|
||||
- **Single Responsibility**: Each component has one clear purpose
|
||||
- **Clean Interfaces**: Well-defined APIs between components
|
||||
- **Error Handling**: Graceful degradation on failures
|
||||
- **Documentation**: Clear README and code comments
|
||||
|
||||
### JavaScript Development
|
||||
|
||||
- **Modular Architecture**: Avoid monolithic JavaScript files
|
||||
- **Event-Driven**: Use pub/sub for component communication
|
||||
- **Configuration-Driven**: Avoid hardcoded values
|
||||
- **Browser Compatibility**: Test across different browsers
|
||||
|
||||
### Asset Management
|
||||
|
||||
- **Relative Paths**: Use relative paths in asset definitions
|
||||
- **Versioning**: Include version info for cache management
|
||||
- **Optimization**: Minimize asset size for production
|
||||
- **CDN Integration**: Use CDN for external dependencies
|
||||
|
||||
### Testing Strategy
|
||||
|
||||
- **Automated Testing**: Comprehensive test coverage
|
||||
- **Manual Testing**: User workflow validation
|
||||
- **Cross-Platform**: Test on different environments
|
||||
- **Performance Testing**: Monitor rendering performance
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Plugin Not Found**:
|
||||
- Check plugin registration in `_register_builtin_rendering_engines()`
|
||||
- Verify plugin class inheritance from `RenderingEnginePlugin`
|
||||
- Check import paths and module availability
|
||||
|
||||
2. **Asset Loading Errors**:
|
||||
- Verify asset paths in `get_required_assets()`
|
||||
- Check file permissions and existence
|
||||
- Validate URL generation in different modes
|
||||
|
||||
3. **Configuration Errors**:
|
||||
- Check JSON syntax in configuration
|
||||
- Verify configuration element ID (`markitect-config`)
|
||||
- Test configuration loading in JavaScript
|
||||
|
||||
4. **Rendering Failures**:
|
||||
- Check template file existence and permissions
|
||||
- Verify template placeholder replacement
|
||||
- Test with minimal content for debugging
|
||||
|
||||
### Debug Techniques
|
||||
|
||||
- **Console Logging**: Use browser console for debugging
|
||||
- **Debug Panel**: TestDrive JSUI includes debug information
|
||||
- **Verbose Mode**: Use CLI `--verbose` flag for detailed output
|
||||
- **Test Scripts**: Run individual test scripts for isolation
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
### Planned Features
|
||||
|
||||
- **Plugin Package Manager**: npm-like plugin distribution
|
||||
- **Theme System Integration**: Plugin-aware theme system
|
||||
- **Performance Monitoring**: Built-in performance tracking
|
||||
- **Hot Reloading**: Automatic reload on file changes
|
||||
|
||||
### Extension Opportunities
|
||||
|
||||
- **React Integration**: React-based rendering engine
|
||||
- **Vue Integration**: Vue.js-based rendering engine
|
||||
- **TypeScript Support**: TypeScript plugin development
|
||||
- **Testing Framework**: Automated JavaScript testing
|
||||
|
||||
### Community
|
||||
|
||||
- **Plugin Registry**: Central repository for community plugins
|
||||
- **Documentation**: Expanded examples and tutorials
|
||||
- **Templates**: Starter templates for new plugins
|
||||
- **Best Practices**: Community guidelines and patterns
|
||||
|
||||
---
|
||||
|
||||
*This plugin system enables JavaScript-first development while maintaining clean integration with the MarkiTect Python ecosystem, providing the best of both worlds for UI development and backend processing.*
|
||||
@@ -7,8 +7,9 @@ Welcome to the MarkiTect documentation. This directory contains comprehensive do
|
||||
### 📐 Architecture Documentation (`architecture/`)
|
||||
Deep technical documentation about system design, performance, and implementation details.
|
||||
|
||||
- **[Capabilities Architecture](architecture/CAPABILITIES_ARCHITECTURE.md)** - **Critical:** How capabilities work as independent git submodules and separation of concerns
|
||||
- **[Caching System](architecture/caching-system.md)** - Why and how MarkiTect's AST caching delivers 60-85% performance improvements
|
||||
- *Coming soon: Database Schema, CLI Architecture, Plugin System*
|
||||
- *Coming soon: Database Schema, CLI Architecture*
|
||||
|
||||
### 👥 User Guides (`user-guides/`)
|
||||
End-user documentation for working with MarkiTect CLI and features.
|
||||
|
||||
1275
docs/WIDGET_PLUGIN_INFRASTRUCTURE_WORKPLAN.md
Normal file
1275
docs/WIDGET_PLUGIN_INFRASTRUCTURE_WORKPLAN.md
Normal file
File diff suppressed because it is too large
Load Diff
268
docs/WORKSPACE_AND_DATABASES.md
Normal file
268
docs/WORKSPACE_AND_DATABASES.md
Normal file
@@ -0,0 +1,268 @@
|
||||
# Markitect Workspace and Database Architecture
|
||||
|
||||
This document explains Markitect's workspace concept and the two distinct database systems used by the application.
|
||||
|
||||
## Workspace Concept
|
||||
|
||||
Markitect uses a **workspace-based architecture** where each directory or repository can have its own configuration and local data storage. This allows for flexible, per-project customization while maintaining a global user configuration.
|
||||
|
||||
### Workspace Structure
|
||||
|
||||
When you initialize Markitect in a directory, it creates the following structure:
|
||||
|
||||
```
|
||||
project-directory/
|
||||
├── .markitect.yml # Workspace configuration
|
||||
├── .markitect_workspace/ # Local workspace data
|
||||
├── .ast_cache/ # AST parsing cache
|
||||
├── assets/ # Asset storage directory
|
||||
│ ├── assets.db # Asset management database
|
||||
│ └── [asset files] # Stored images, files, etc.
|
||||
└── tests/ # Test files directory
|
||||
```
|
||||
|
||||
### Configuration Files
|
||||
|
||||
Markitect searches for configuration in this order:
|
||||
1. `.markitect.yml` (current directory)
|
||||
2. `.markitect.yaml` (current directory)
|
||||
3. `.markitect.json` (current directory)
|
||||
4. `markitect.config.yml` (current directory)
|
||||
5. `markitect.config.yaml` (current directory)
|
||||
6. `markitect.config.json` (current directory)
|
||||
7. `~/.markitect/config.yml` (user home directory)
|
||||
8. Environment variables (`MARKITECT_*`)
|
||||
9. Built-in defaults
|
||||
|
||||
## Database Architecture
|
||||
|
||||
Markitect uses two distinct SQLite databases for different purposes:
|
||||
|
||||
### 1. Main Application Database (`markitect.db`)
|
||||
|
||||
**Location**: `~/.markitect/markitect.db` (user home directory)
|
||||
|
||||
**Purpose**: Global user-level application data and configuration
|
||||
|
||||
**Scope**: User-wide, shared across all workspaces
|
||||
|
||||
**Contents**:
|
||||
- User preferences and settings
|
||||
- Application state information
|
||||
- Global configuration data
|
||||
- Cross-workspace data that needs persistence
|
||||
|
||||
**Configuration**: Set via `MARKITECT_DATABASE_PATH` environment variable or `database_path` in configuration
|
||||
|
||||
### 2. Asset Management Database (`assets.db`)
|
||||
|
||||
**Location**: `assets/assets.db` (within workspace asset storage directory)
|
||||
|
||||
**Purpose**: Asset management and tracking for the current workspace
|
||||
|
||||
**Scope**: Workspace-specific, local to each directory/repository
|
||||
|
||||
**Contents**:
|
||||
- Asset metadata (filename, size, MIME type, timestamps)
|
||||
- File content hashes for deduplication
|
||||
- Asset usage statistics and tracking
|
||||
- Processing logs and analytics
|
||||
- Asset relationships and dependencies
|
||||
|
||||
**Schema** (key tables):
|
||||
```sql
|
||||
-- Basic asset metadata
|
||||
asset_metadata (
|
||||
content_hash TEXT PRIMARY KEY,
|
||||
filename TEXT NOT NULL,
|
||||
size_bytes INTEGER NOT NULL,
|
||||
mime_type TEXT,
|
||||
created_at TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
)
|
||||
|
||||
-- Usage tracking
|
||||
asset_usage_stats (
|
||||
content_hash TEXT,
|
||||
usage_count INTEGER,
|
||||
last_used TIMESTAMP,
|
||||
documents_using TEXT -- JSON array of document paths
|
||||
)
|
||||
|
||||
-- Performance and analytics tables
|
||||
-- (Additional tables for caching, indexing, and optimization)
|
||||
```
|
||||
|
||||
## Why Two Databases?
|
||||
|
||||
This separation serves several important purposes:
|
||||
|
||||
### Data Isolation
|
||||
- **Global data** (user preferences) stays in the user profile
|
||||
- **Workspace data** (asset files, metadata) stays with the project
|
||||
|
||||
### Version Control Considerations
|
||||
- `markitect.db` is never committed to version control
|
||||
- `assets.db` is excluded via `.gitignore` (local workspace data)
|
||||
- Asset files themselves can be optionally committed based on project needs
|
||||
|
||||
### Performance Optimization
|
||||
- Asset database operations are localized to relevant files
|
||||
- Global database isn't impacted by large asset collections
|
||||
- Each workspace can optimize its asset database independently
|
||||
|
||||
### Portability and Collaboration
|
||||
- Workspaces can be moved/copied without affecting global configuration
|
||||
- Teams can share asset storage strategies without sharing personal settings
|
||||
- Different projects can have different asset management policies
|
||||
|
||||
## Configuration Management
|
||||
|
||||
### Workspace Initialization
|
||||
|
||||
To initialize a new workspace:
|
||||
|
||||
```bash
|
||||
markitect config-init
|
||||
```
|
||||
|
||||
This creates:
|
||||
1. `.markitect.yml` configuration file
|
||||
2. Required directories (`.markitect_workspace`, `.ast_cache`, `tests`)
|
||||
3. Asset storage structure
|
||||
|
||||
### Configuration Commands
|
||||
|
||||
```bash
|
||||
# View current configuration
|
||||
markitect config-show
|
||||
|
||||
# Set workspace-specific values
|
||||
markitect config-set repo_name "my-project"
|
||||
markitect config-set assets.storage_path "./assets"
|
||||
|
||||
# View configuration help
|
||||
markitect config-help
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Override configuration with environment variables:
|
||||
|
||||
```bash
|
||||
export MARKITECT_GITEA_URL="http://localhost:3000"
|
||||
export MARKITECT_WORKSPACE_DIR=".custom_workspace"
|
||||
export MARKITECT_DATABASE_PATH="/custom/path/markitect.db"
|
||||
```
|
||||
|
||||
## Asset Management Integration
|
||||
|
||||
The asset management system coordinates between the asset database and file storage:
|
||||
|
||||
```python
|
||||
from markitect.assets import AssetManager
|
||||
|
||||
# Initialize with workspace-specific configuration
|
||||
asset_manager = AssetManager()
|
||||
|
||||
# Assets are stored in workspace, tracked in assets.db
|
||||
asset = asset_manager.add_asset("image.png")
|
||||
```
|
||||
|
||||
### Asset Storage Workflow
|
||||
|
||||
1. **File Processing**: Asset files are processed and stored in `assets/` directory
|
||||
2. **Database Recording**: Metadata recorded in `assets.db`
|
||||
3. **Deduplication**: Content hashes prevent duplicate storage
|
||||
4. **Usage Tracking**: Document usage recorded for analytics
|
||||
5. **Cleanup**: Unused assets can be identified and removed
|
||||
|
||||
## Best Practices
|
||||
|
||||
### For Development
|
||||
- Initialize workspace in each project directory
|
||||
- Commit `.markitect.yml` to version control
|
||||
- Add `assets.db` and workspace directories to `.gitignore`
|
||||
- Use relative paths in workspace configuration
|
||||
|
||||
### For Collaboration
|
||||
- Share workspace configuration (`.markitect.yml`)
|
||||
- Document asset storage strategy for the team
|
||||
- Establish conventions for asset organization
|
||||
- Consider asset file version control policies
|
||||
|
||||
### for Production
|
||||
- Backup both databases separately
|
||||
- Monitor asset database growth in large projects
|
||||
- Use environment variables for deployment-specific settings
|
||||
- Implement asset cleanup strategies for long-running projects
|
||||
|
||||
## Migration and Compatibility
|
||||
|
||||
### Legacy Support
|
||||
The system maintains backward compatibility:
|
||||
- Old configuration patterns still work
|
||||
- Automatic migration of legacy settings
|
||||
- Graceful fallbacks for missing configuration
|
||||
|
||||
### Database Migration
|
||||
Asset databases support schema migrations:
|
||||
- Automatic schema updates on version changes
|
||||
- Backward compatibility preservation
|
||||
- Safe migration with rollback capability
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
**Database Connection Errors**:
|
||||
- Check file permissions on database directories
|
||||
- Verify disk space availability
|
||||
- Ensure SQLite3 is available
|
||||
|
||||
**Configuration Not Found**:
|
||||
- Verify `.markitect.yml` exists and is valid YAML
|
||||
- Check environment variable names and values
|
||||
- Run `markitect config-show` to see current configuration
|
||||
|
||||
**Asset Storage Issues**:
|
||||
- Confirm asset directory permissions
|
||||
- Check available disk space
|
||||
- Verify `assets.db` is not corrupted
|
||||
|
||||
### Recovery Procedures
|
||||
|
||||
**Corrupted Asset Database**:
|
||||
```bash
|
||||
# Backup and recreate
|
||||
mv assets/assets.db assets/assets.db.backup
|
||||
# Restart Markitect to recreate schema
|
||||
markitect config-show
|
||||
```
|
||||
|
||||
**Missing Configuration**:
|
||||
```bash
|
||||
# Reinitialize workspace
|
||||
markitect config-init
|
||||
```
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Database Connections
|
||||
- Uses SQLite3 with connection pooling for performance
|
||||
- Automatic connection management and cleanup
|
||||
- Thread-safe operations for concurrent access
|
||||
|
||||
### File System Integration
|
||||
- Path resolution relative to workspace root
|
||||
- Cross-platform path handling (Windows, macOS, Linux)
|
||||
- Symlink and junction support where available
|
||||
|
||||
### Security Considerations
|
||||
- Database files have restricted permissions
|
||||
- No sensitive data stored in asset database
|
||||
- Configuration masking for sensitive values in display
|
||||
|
||||
---
|
||||
|
||||
*This documentation reflects the current architecture as of November 2025. For implementation details, see the source code in `markitect/config_manager.py` and `markitect/assets/`.*
|
||||
173
docs/adr/ADR-001-client-side-debug-storage.md
Normal file
173
docs/adr/ADR-001-client-side-debug-storage.md
Normal file
@@ -0,0 +1,173 @@
|
||||
# ADR-001: Client-Side Debug Storage Technology
|
||||
|
||||
## Status
|
||||
**Accepted** - 2025-11-10
|
||||
|
||||
## Context
|
||||
|
||||
The Markitect application requires a robust client-side debugging infrastructure to track and display debug messages during document editing operations. The previous implementation relied on a tightly-coupled debug panel that expected specific DOM elements and was integrated into old dialog systems.
|
||||
|
||||
### Requirements
|
||||
- **Independence**: Debug system must be independent of specific UI components
|
||||
- **Persistence**: Debug messages should survive browser refresh/close
|
||||
- **Real-time Updates**: UI should reflect new messages immediately
|
||||
- **Performance**: Should not block the main thread or impact editor performance
|
||||
- **Storage Capacity**: Must handle 1000+ debug messages efficiently
|
||||
- **Browser Compatibility**: Work across all modern browsers
|
||||
- **Developer Experience**: Easy to integrate and use throughout the codebase
|
||||
|
||||
### Problem Statement
|
||||
The existing debug infrastructure was failing because:
|
||||
1. Tight coupling to specific DOM elements (`debug-messages-container`, `toggle-debug`)
|
||||
2. Dependency on old dialog systems
|
||||
3. No persistence across browser sessions
|
||||
4. Limited to in-memory storage only
|
||||
|
||||
## Decision
|
||||
|
||||
**We will use IndexedDB as the primary client-side storage technology for the debug system.**
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### Option 1: IndexedDB (Selected)
|
||||
**Technology**: Browser-native object store database
|
||||
**Implementation**: `window.MarkitectDebugSystem` with async operations
|
||||
|
||||
### Option 2: SQLite via SQL.js
|
||||
**Technology**: WebAssembly-based SQLite implementation
|
||||
**Implementation**: SQL.js library with manual persistence
|
||||
|
||||
### Option 3: LocalStorage
|
||||
**Technology**: Browser key-value storage
|
||||
**Implementation**: JSON serialization with size limits
|
||||
|
||||
### Option 4: In-Memory Only
|
||||
**Technology**: JavaScript arrays with no persistence
|
||||
**Implementation**: Simple message array management
|
||||
|
||||
## Decision Matrix
|
||||
|
||||
| Criteria | IndexedDB | SQLite | LocalStorage | In-Memory |
|
||||
|----------|-----------|---------|--------------|-----------|
|
||||
| **Storage Capacity** | ✅ Large (50-100MB+) | ✅ Large | ❌ Limited (5-10MB) | ❌ Session only |
|
||||
| **Performance** | ✅ Async/Non-blocking | ⚠️ Can block UI | ✅ Fast | ✅ Fastest |
|
||||
| **Persistence** | ✅ Across sessions | ✅ Across sessions | ✅ Across sessions | ❌ Lost on refresh |
|
||||
| **Query Capabilities** | ⚠️ Limited | ✅ Full SQL | ❌ None | ❌ JavaScript only |
|
||||
| **Dependencies** | ✅ Native | ❌ 1.5MB WebAssembly | ✅ Native | ✅ Native |
|
||||
| **Browser Support** | ✅ Universal modern | ✅ Universal | ✅ Universal | ✅ Universal |
|
||||
| **API Complexity** | ⚠️ Moderate | ✅ Familiar SQL | ✅ Simple | ✅ Simple |
|
||||
| **Use Case Fit** | ✅ Perfect match | ⚠️ Overkill | ❌ Too limited | ❌ Insufficient |
|
||||
|
||||
## Rationale
|
||||
|
||||
### Why IndexedDB?
|
||||
|
||||
1. **Native Browser Support**: No external dependencies or WebAssembly files
|
||||
2. **Asynchronous Operations**: Won't block the UI thread during debug operations
|
||||
3. **Sufficient Storage**: 50-100MB+ capacity easily handles thousands of debug messages
|
||||
4. **Appropriate Complexity**: Matches our simple data model without over-engineering
|
||||
5. **Performance Optimized**: Browsers optimize IndexedDB for web applications
|
||||
6. **Security**: Runs within browser's security sandbox with proper origin isolation
|
||||
|
||||
### Why Not SQLite?
|
||||
|
||||
While SQLite offers powerful querying capabilities, it's overkill for our use case:
|
||||
|
||||
- **Complexity**: Our data model is simple (timestamp, category, message)
|
||||
- **Dependencies**: 1.5MB WebAssembly adds significant overhead
|
||||
- **Synchronous Risk**: Large operations can block the UI thread
|
||||
- **Manual Persistence**: Requires explicit save/load operations
|
||||
- **Over-Engineering**: We don't need JOINs, complex queries, or relational features
|
||||
|
||||
### Why Not LocalStorage?
|
||||
|
||||
LocalStorage is too limited:
|
||||
- **Size Constraints**: 5-10MB limit insufficient for extensive debug logs
|
||||
- **Synchronous API**: Blocks main thread during operations
|
||||
- **No Structured Data**: JSON serialization/deserialization overhead
|
||||
- **Browser Quotas**: Can be evicted under storage pressure
|
||||
|
||||
### Why Not In-Memory?
|
||||
|
||||
In-memory storage is insufficient:
|
||||
- **No Persistence**: Debug context lost on page refresh
|
||||
- **Memory Pressure**: Large debug logs consume RAM
|
||||
- **Development Workflow**: Debugging often requires page reloads
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### Data Structure
|
||||
```javascript
|
||||
{
|
||||
id: auto_increment_id,
|
||||
message: "Debug message text",
|
||||
category: "INFO" | "WARNING" | "ERROR" | "SUCCESS" | "DEBUG",
|
||||
timestamp: "2025-11-10T23:35:53.123Z",
|
||||
displayTime: "11:35:53 PM"
|
||||
}
|
||||
```
|
||||
|
||||
### Database Schema
|
||||
- **Store Name**: `messages`
|
||||
- **Key Path**: `id` (auto-increment)
|
||||
- **Indexes**: `timestamp`, `category`
|
||||
- **Version**: 1
|
||||
|
||||
### API Design
|
||||
```javascript
|
||||
// Core operations
|
||||
await MarkitectDebugSystem.addMessage(message, category);
|
||||
await MarkitectDebugSystem.clearMessages();
|
||||
const messages = MarkitectDebugSystem.getMessages(category, limit);
|
||||
|
||||
// Advanced features
|
||||
const unsubscribe = MarkitectDebugSystem.subscribe(callback);
|
||||
const json = MarkitectDebugSystem.exportMessages();
|
||||
```
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
- ✅ **Zero Dependencies**: No external libraries required
|
||||
- ✅ **High Performance**: Non-blocking operations maintain UI responsiveness
|
||||
- ✅ **Persistent Debugging**: Debug context preserved across browser sessions
|
||||
- ✅ **Scalable Storage**: Handles thousands of debug messages efficiently
|
||||
- ✅ **Future-Proof**: Can add advanced features without architectural changes
|
||||
- ✅ **Developer-Friendly**: Simple API integration throughout codebase
|
||||
|
||||
### Negative
|
||||
- ⚠️ **Limited Querying**: Complex filtering requires custom JavaScript code
|
||||
- ⚠️ **Browser Variations**: Subtle differences in IndexedDB implementations
|
||||
- ⚠️ **Learning Curve**: Developers may be less familiar with IndexedDB vs SQL
|
||||
|
||||
### Mitigation Strategies
|
||||
- **Query Limitations**: Implement helper methods for common filtering operations
|
||||
- **Browser Compatibility**: Use feature detection with graceful fallbacks
|
||||
- **Developer Experience**: Provide clear API documentation and examples
|
||||
|
||||
## Future Considerations
|
||||
|
||||
### Potential Enhancements
|
||||
1. **Hybrid Approach**: Add optional SQLite mode for advanced users
|
||||
2. **Data Export**: Multiple export formats (JSON, CSV, SQL dumps)
|
||||
3. **Advanced Filtering**: Web Workers for complex query operations
|
||||
4. **Data Visualization**: Charts and analytics for debug patterns
|
||||
5. **Remote Sync**: Optional sync to development servers
|
||||
|
||||
### Migration Path
|
||||
The current IndexedDB implementation provides a foundation that could support:
|
||||
- Adding SQLite as an "advanced mode" option
|
||||
- Implementing data export to external analysis tools
|
||||
- Building analytics dashboards on top of the debug data
|
||||
|
||||
## References
|
||||
- [IndexedDB API Documentation](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
|
||||
- [SQL.js Documentation](https://sql.js.org/)
|
||||
- [Web Storage API Limitations](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#Storage_limits)
|
||||
|
||||
## Approval
|
||||
|
||||
**Decided by**: Claude Code Development Team
|
||||
**Date**: 2025-11-10
|
||||
**Context**: Independent debug system redesign
|
||||
**Next Review**: When complex querying requirements emerge
|
||||
384
docs/adr/ADR-002-robustness-principle-for-production-use.md
Normal file
384
docs/adr/ADR-002-robustness-principle-for-production-use.md
Normal file
@@ -0,0 +1,384 @@
|
||||
# ADR-002: Robustness Principle for Production Use
|
||||
|
||||
## Status
|
||||
**Accepted** - 2025-11-11
|
||||
|
||||
## Context
|
||||
|
||||
The Markitect application operates in unpredictable client-side environments where JavaScript execution can fail due to malicious input, network issues, browser inconsistencies, missing dependencies, or resource exhaustion. Traditional defensive programming approaches often result in cascading failures that crash entire UI components or leave the application in an unusable state.
|
||||
|
||||
### Requirements
|
||||
- **Fault Tolerance**: System must continue operating when individual components fail
|
||||
- **Security**: Protection against malicious input and injection attacks
|
||||
- **Resource Protection**: Prevention of DoS attacks through resource exhaustion
|
||||
- **Graceful Degradation**: Non-essential features should fail without breaking core functionality
|
||||
- **Error Containment**: Failures should be isolated and not cascade throughout the system
|
||||
- **User Experience**: Users should never see white screens or completely broken interfaces
|
||||
- **Developer Experience**: Clear error reporting and debugging capabilities
|
||||
|
||||
### Problem Statement
|
||||
The existing JavaScript codebase was vulnerable to:
|
||||
1. **Uncaught Exceptions**: Single errors could crash entire UI components
|
||||
2. **Input Validation Gaps**: Malicious or malformed input could break processing
|
||||
3. **Resource Exhaustion**: Large datasets could freeze the browser
|
||||
4. **Dependency Failures**: Missing libraries or features caused complete breakdowns
|
||||
5. **DOM Manipulation Risks**: Direct DOM access without safety checks
|
||||
6. **Cascading Failures**: One component failure affecting others
|
||||
|
||||
## Decision
|
||||
|
||||
**We will implement the Robustness Principle as a comprehensive defensive programming strategy with multiple layers of protection throughout the JavaScript codebase, balanced with Fail Fast behavior in development mode to prevent difficult diagnosis and cascading errors.**
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### Option 1: Robustness Principle (Selected)
|
||||
**Approach**: Multiple defensive layers with graceful degradation
|
||||
**Implementation**: Safe wrappers, input validation, error boundaries, resource limits
|
||||
|
||||
### Option 2: Try-Catch Everything
|
||||
**Approach**: Wrap all operations in try-catch blocks
|
||||
**Implementation**: Granular exception handling without systematic approach
|
||||
|
||||
### Option 3: Reactive Error Handling
|
||||
**Approach**: Error handling through reactive programming patterns
|
||||
**Implementation**: RxJS or similar libraries for error stream management
|
||||
|
||||
### Option 4: Minimal Validation
|
||||
**Approach**: Basic input checking with assumption of good data
|
||||
**Implementation**: Simple null checks and basic validation
|
||||
|
||||
## Decision Matrix
|
||||
|
||||
| Criteria | Robustness Principle | Try-Catch All | Reactive Patterns | Minimal Validation |
|
||||
|----------|---------------------|---------------|-------------------|-------------------|
|
||||
| **Fault Tolerance** | ✅ Comprehensive | ⚠️ Inconsistent | ✅ Good | ❌ Poor |
|
||||
| **Security Protection** | ✅ Multi-layered | ❌ Reactive only | ⚠️ Limited | ❌ Vulnerable |
|
||||
| **Resource Management** | ✅ Proactive limits | ❌ No protection | ⚠️ Some control | ❌ No protection |
|
||||
| **Code Maintainability** | ✅ Systematic | ❌ Scattered | ⚠️ Complex | ✅ Simple |
|
||||
| **Performance Impact** | ⚠️ Moderate overhead | ⚠️ High overhead | ❌ Library weight | ✅ Minimal |
|
||||
| **Developer Experience** | ✅ Clear patterns | ❌ Repetitive | ❌ Learning curve | ✅ Familiar |
|
||||
| **Error Recovery** | ✅ Graceful fallbacks | ⚠️ Manual recovery | ✅ Automatic retry | ❌ System failure |
|
||||
|
||||
## Balanced Implementation: Robustness + Fail Fast
|
||||
|
||||
### Development vs Production Behavior
|
||||
|
||||
**Development Mode (Fail Fast)**:
|
||||
- Immediate exceptions on errors for fast debugging
|
||||
- Strict validation with no silent failures
|
||||
- Full error context and stack traces
|
||||
- Activated on localhost, 127.0.0.1, or `?strict=true`
|
||||
|
||||
**Production Mode (Robust)**:
|
||||
- Graceful degradation and fallback behaviors
|
||||
- Silent recovery with detailed logging
|
||||
- User experience preservation
|
||||
- Default behavior in production environments
|
||||
|
||||
```javascript
|
||||
const MARKITECT_STRICT_MODE = (
|
||||
window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === '127.0.0.1' ||
|
||||
window.location.search.includes('strict=true') ||
|
||||
window.markitectStrictMode === true
|
||||
);
|
||||
```
|
||||
|
||||
## Robustness Principle Implementation
|
||||
|
||||
### Layer 1: Input Validation & Sanitization
|
||||
**Purpose**: Prevent malicious or malformed data from entering the system
|
||||
|
||||
```javascript
|
||||
safeTextExtraction(element) {
|
||||
if (!this.validateElement(element)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
const text = element.textContent || element.innerText || '';
|
||||
return this.sanitizeText(text.trim());
|
||||
} catch (error) {
|
||||
console.warn('Text extraction failed:', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
sanitizeText(text) {
|
||||
if (typeof text !== 'string') return '';
|
||||
|
||||
const maxLength = 100000; // 100KB text limit
|
||||
return text
|
||||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') // Remove control chars
|
||||
.slice(0, maxLength); // Limit length
|
||||
}
|
||||
```
|
||||
|
||||
### Layer 2: Error Boundaries with Fallbacks
|
||||
**Purpose**: Contain failures and provide alternative execution paths
|
||||
|
||||
```javascript
|
||||
safeOperation(operation, fallback = null, context = 'Unknown') {
|
||||
try {
|
||||
return operation();
|
||||
} catch (error) {
|
||||
console.warn(`Operation failed in ${context}:`, error);
|
||||
|
||||
// Fail Fast in development mode
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
console.error(`🚨 STRICT MODE: Operation failed in ${context}`);
|
||||
throw error; // Re-throw for immediate debugging
|
||||
}
|
||||
|
||||
// Robust handling in production
|
||||
if (window.MarkitectDebugSystem) {
|
||||
window.MarkitectDebugSystem.addMessage(
|
||||
`Safe operation failed: ${error.message}`,
|
||||
'WARNING',
|
||||
'RobustnessSystem',
|
||||
{ context, eventType: 'ERROR' }
|
||||
);
|
||||
}
|
||||
|
||||
return typeof fallback === 'function' ? fallback() : fallback;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Layer 3: Resource Limits & Timeout Protection
|
||||
**Purpose**: Prevent resource exhaustion and infinite operations
|
||||
|
||||
```javascript
|
||||
// Element processing limits
|
||||
const elements = this.safeQuerySelectorAll(selector);
|
||||
const maxElements = 10000; // DoS protection
|
||||
elements.slice(0, maxElements).forEach(processElement);
|
||||
|
||||
// Operation timeouts
|
||||
const timeout = setTimeout(() => {
|
||||
if (this.isOperationRunning) {
|
||||
console.warn('Operation timed out');
|
||||
this.cleanup();
|
||||
}
|
||||
}, 30000); // 30 second safety timeout
|
||||
```
|
||||
|
||||
### Layer 4: Graceful Degradation
|
||||
**Purpose**: Maintain core functionality when non-essential features fail
|
||||
|
||||
```javascript
|
||||
// Dependency checking with fallbacks
|
||||
initializeControl(controlClass, controlName, icon = '🔧') {
|
||||
if (!controlClass) {
|
||||
this.safeLog(`${controlName} class not available, skipping`, 'WARNING');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const instance = new controlClass();
|
||||
return instance.createControl() ? instance : null;
|
||||
} catch (error) {
|
||||
// Create minimal fallback for essential controls
|
||||
if (controlName === 'StatusControl') {
|
||||
return this.createFallbackControl(controlName, icon);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Layer 5: Safe DOM Manipulation
|
||||
**Purpose**: Protect against DOM-related failures and validate operations
|
||||
|
||||
```javascript
|
||||
safeQuerySelector(selector, parent = document) {
|
||||
try {
|
||||
if (!parent || !parent.querySelector) {
|
||||
return null;
|
||||
}
|
||||
return parent.querySelector(selector);
|
||||
} catch (error) {
|
||||
console.warn(`Invalid selector: ${selector}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
validateElement(element) {
|
||||
return element &&
|
||||
element.nodeType === Node.ELEMENT_NODE &&
|
||||
element.isConnected &&
|
||||
!element.closest('.control-panel'); // Avoid control elements
|
||||
}
|
||||
```
|
||||
|
||||
## Rationale
|
||||
|
||||
### Why the Robustness Principle?
|
||||
|
||||
1. **Systematic Approach**: Unlike ad-hoc try-catch blocks, provides consistent protection patterns
|
||||
2. **Multiple Defense Layers**: Each layer catches different types of failures
|
||||
3. **Proactive Protection**: Prevents problems before they occur rather than just reacting
|
||||
4. **Maintainable Code**: Clear patterns and utility functions reduce repetition
|
||||
5. **Production Ready**: Designed for real-world environments with unpredictable conditions
|
||||
6. **Performance Conscious**: Adds protection without significant overhead
|
||||
|
||||
### Why Not Try-Catch Everything?
|
||||
|
||||
- **Maintenance Burden**: Scattered exception handling is hard to maintain
|
||||
- **Inconsistent Coverage**: Easy to miss critical paths
|
||||
- **Poor Error Recovery**: Just catching errors doesn't provide meaningful fallbacks
|
||||
- **Performance Impact**: Exception handling has overhead when overused
|
||||
|
||||
### Why Not Reactive Patterns?
|
||||
|
||||
- **Complexity**: RxJS adds significant learning curve and bundle size
|
||||
- **Overkill**: Our error handling needs don't require reactive streams
|
||||
- **Library Dependency**: Adds external dependency for core functionality
|
||||
- **Framework Lock-in**: Ties architecture to specific programming paradigm
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### Core Protection Utilities
|
||||
|
||||
```javascript
|
||||
// Central error handling system
|
||||
const RobustnessSystem = {
|
||||
safeOperation(operation, fallback, context),
|
||||
safeQuerySelector(selector, parent),
|
||||
safeQuerySelectorAll(selector, parent),
|
||||
validateElement(element),
|
||||
sanitizeText(text),
|
||||
safeTextExtraction(element)
|
||||
};
|
||||
```
|
||||
|
||||
### Integration Pattern
|
||||
|
||||
```javascript
|
||||
// Before: Fragile operation
|
||||
function processDocument() {
|
||||
const stats = calculateStats(); // Could crash
|
||||
updateUI(stats); // Could crash
|
||||
saveToStorage(stats); // Could crash
|
||||
}
|
||||
|
||||
// After: Robust operation
|
||||
function processDocument() {
|
||||
const stats = this.safeOperation(
|
||||
() => this.calculateStats(),
|
||||
this.getDefaultStats(),
|
||||
'calculateStats'
|
||||
);
|
||||
|
||||
this.safeOperation(
|
||||
() => this.updateUI(stats),
|
||||
null,
|
||||
'updateUI'
|
||||
);
|
||||
|
||||
this.safeOperation(
|
||||
() => this.saveToStorage(stats),
|
||||
null,
|
||||
'saveToStorage'
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### Resource Protection Examples
|
||||
|
||||
```javascript
|
||||
// Memory limits
|
||||
const characters = Math.min(sectionText.length, 1000000); // Cap at 1MB
|
||||
|
||||
// Processing limits
|
||||
elements.slice(0, maxElements).forEach(processElement);
|
||||
|
||||
// Time limits
|
||||
const timeout = setTimeout(cleanup, OPERATION_TIMEOUT);
|
||||
```
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
- ✅ **System Stability**: Individual component failures don't crash the entire application
|
||||
- ✅ **Security Hardening**: Multiple layers protect against various attack vectors
|
||||
- ✅ **User Experience**: Graceful degradation maintains usability during failures
|
||||
- ✅ **Developer Confidence**: Clear patterns reduce fear of production failures
|
||||
- ✅ **Debugging Capability**: Detailed error context and logging
|
||||
- ✅ **Maintenance Reduction**: Fewer emergency fixes for production issues
|
||||
|
||||
### Negative
|
||||
- ⚠️ **Performance Overhead**: Additional validation and error checking adds some cost
|
||||
- ⚠️ **Code Complexity**: More defensive code requires more careful implementation
|
||||
- ⚠️ **Initial Development Time**: Building robust systems takes longer upfront
|
||||
|
||||
### Mitigation Strategies
|
||||
- **Performance**: Use efficient validation techniques and avoid redundant checks
|
||||
- **Complexity**: Provide clear utility functions and documentation
|
||||
- **Development Time**: Treat as investment in reduced maintenance and debugging time
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Robustness Testing Categories
|
||||
|
||||
1. **Malicious Input Testing**: XSS attempts, oversized data, invalid formats
|
||||
2. **Resource Exhaustion Testing**: Large datasets, memory pressure scenarios
|
||||
3. **Dependency Failure Testing**: Missing libraries, network failures
|
||||
4. **DOM Manipulation Edge Cases**: Invalid selectors, disconnected elements
|
||||
5. **Timeout Scenarios**: Long-running operations, infinite loops
|
||||
6. **Error Cascade Testing**: Multiple simultaneous failures
|
||||
|
||||
### Automated Testing
|
||||
|
||||
```javascript
|
||||
// Example robustness test
|
||||
describe('Robustness Principle', () => {
|
||||
it('should handle malicious text input safely', () => {
|
||||
const maliciousText = '<script>alert("xss")</script>'.repeat(10000);
|
||||
const result = statusControl.safeTextExtraction({ textContent: maliciousText });
|
||||
|
||||
expect(result.length).toBeLessThan(100001); // Respects limits
|
||||
expect(result).not.toContain('<script>'); // Sanitized
|
||||
});
|
||||
|
||||
it('should gracefully handle missing dependencies', () => {
|
||||
delete window.StatusControl;
|
||||
const result = MarkitectMain.initialize();
|
||||
|
||||
expect(result).toBeDefined(); // Doesn't crash
|
||||
expect(window.statusControl).toBeNull(); // Graceful degradation
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Future Considerations
|
||||
|
||||
### Potential Enhancements
|
||||
|
||||
1. **Metrics Collection**: Track robustness events for system health monitoring
|
||||
2. **Adaptive Thresholds**: Dynamic resource limits based on client capabilities
|
||||
3. **Recovery Strategies**: More sophisticated fallback mechanisms
|
||||
4. **Performance Monitoring**: Track overhead of robustness measures
|
||||
5. **User Feedback**: Notify users when degraded functionality is active
|
||||
|
||||
### Evolution Path
|
||||
|
||||
The Robustness Principle provides foundation for:
|
||||
- **Service Worker Integration**: Offline robustness capabilities
|
||||
- **Web Worker Offloading**: Move intensive operations off main thread
|
||||
- **Progressive Enhancement**: Advanced features for capable browsers
|
||||
- **Error Analytics**: Aggregate error patterns for system improvements
|
||||
|
||||
## References
|
||||
|
||||
- [Defensive Programming Best Practices](https://en.wikipedia.org/wiki/Defensive_programming)
|
||||
- [JavaScript Error Handling Patterns](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling)
|
||||
- [Web API Security Guidelines](https://developer.mozilla.org/en-US/docs/Web/Security)
|
||||
- [Performance Impact of Error Handling](https://v8.dev/docs/optimize)
|
||||
|
||||
## Approval
|
||||
|
||||
**Decided by**: Claude Code Development Team
|
||||
**Date**: 2025-11-11
|
||||
**Context**: Production hardening and security enhancement
|
||||
**Next Review**: After 6 months of production use or major security incidents
|
||||
453
docs/architecture/CAPABILITIES_ARCHITECTURE.md
Normal file
453
docs/architecture/CAPABILITIES_ARCHITECTURE.md
Normal file
@@ -0,0 +1,453 @@
|
||||
# Capabilities Architecture
|
||||
|
||||
## Overview
|
||||
|
||||
MarkiTect uses a **capabilities-based architecture** where functionality is organized into independent, reusable packages called **capabilities**. Each capability is a self-contained git submodule with its own repository, enabling independent development, versioning, and reuse across projects.
|
||||
|
||||
## Core Principles
|
||||
|
||||
### 1. **Separation of Concerns**
|
||||
|
||||
**Critical Rule:** The main repository (`markitect_project`) **MUST NOT** directly modify capability code.
|
||||
|
||||
- ✅ **DO**: Use capabilities as dependencies
|
||||
- ✅ **DO**: Configure capabilities through documented interfaces
|
||||
- ✅ **DO**: Report issues and feature requests to capability repos
|
||||
- ❌ **DON'T**: Edit capability code from the main repo
|
||||
- ❌ **DON'T**: Make commits directly in capability subdirectories
|
||||
- ❌ **DON'T**: Bypass the submodule boundary
|
||||
|
||||
**Why?** Capabilities are independent repositories. Direct modifications create:
|
||||
- Merge conflicts when syncing with upstream
|
||||
- Broken dependency management
|
||||
- Loss of independent versioning
|
||||
- Confusion about source of truth
|
||||
|
||||
### 2. **Git Submodule Architecture**
|
||||
|
||||
Capabilities are integrated as **git submodules**, not regular directories:
|
||||
|
||||
```
|
||||
markitect_project/
|
||||
├── .gitmodules # Submodule configuration
|
||||
├── capabilities/
|
||||
│ ├── testdrive-jsui/ # Git submodule → separate repo
|
||||
│ ├── issue-facade/ # Git submodule → separate repo
|
||||
│ ├── kaizen-agentic/ # Git submodule → separate repo
|
||||
│ ├── markitect-content/ # Local capability (legacy)
|
||||
│ └── release-management/ # Local capability (legacy)
|
||||
```
|
||||
|
||||
**Submodule vs Local Capabilities:**
|
||||
- **Submodules**: Independent git repositories, separate development lifecycle
|
||||
- **Local**: Part of main repo, shared lifecycle (being phased out)
|
||||
|
||||
**Target State:** All capabilities should eventually be submodules.
|
||||
|
||||
### 3. **Independent Development Lifecycle**
|
||||
|
||||
Each capability has its own:
|
||||
- ✅ Git repository on gitea
|
||||
- ✅ Version numbering (semantic versioning)
|
||||
- ✅ Issue tracking and roadmap
|
||||
- ✅ Testing and CI/CD pipeline
|
||||
- ✅ Documentation and README
|
||||
- ✅ Contributors and maintainers
|
||||
|
||||
### 4. **Interface-Based Integration**
|
||||
|
||||
Capabilities expose **stable interfaces** to the main project:
|
||||
|
||||
```python
|
||||
# markitect uses capability through documented interface
|
||||
from testdrive_jsui import TestDriveJSUIEngine
|
||||
|
||||
engine = TestDriveJSUIEngine()
|
||||
engine.render_document(content, mode='edit', config=config)
|
||||
```
|
||||
|
||||
**Integration Points:**
|
||||
1. **Python Package Interface**: Clean import and API
|
||||
2. **Configuration**: Via `pyproject.toml` dependencies
|
||||
3. **Plugin System**: Via plugin registration and metadata
|
||||
4. **Makefile Targets**: Via capability discovery system
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Working on Capabilities
|
||||
|
||||
**Rule:** Each capability is developed in **its own Claude Code session**.
|
||||
|
||||
#### Main Repository Session
|
||||
```bash
|
||||
# In markitect_project/
|
||||
cd /home/worsch/markitect_project
|
||||
|
||||
# Main repo tasks:
|
||||
# - Integrate capabilities
|
||||
# - Update dependencies
|
||||
# - Configure capability usage
|
||||
# - Test integration points
|
||||
```
|
||||
|
||||
#### Capability Session
|
||||
```bash
|
||||
# In capability repository
|
||||
cd /home/worsch/markitect_project/capabilities/testdrive-jsui
|
||||
|
||||
# OR clone separately
|
||||
git clone http://gitea/coulomb/testdrive-jsui.git
|
||||
cd testdrive-jsui
|
||||
|
||||
# Capability tasks:
|
||||
# - Implement features
|
||||
# - Fix bugs
|
||||
# - Write tests
|
||||
# - Update documentation
|
||||
# - Make releases
|
||||
```
|
||||
|
||||
### Recommended Session Pattern
|
||||
|
||||
**Scenario: Need to add feature to testdrive-jsui**
|
||||
|
||||
1. **Open separate Claude instance** for testdrive-jsui
|
||||
```bash
|
||||
# In new terminal/session
|
||||
cd /path/to/testdrive-jsui
|
||||
# Work on feature
|
||||
git commit -m "feat: new feature"
|
||||
git push origin main
|
||||
```
|
||||
|
||||
2. **Update main project** (different Claude instance)
|
||||
```bash
|
||||
cd /home/worsch/markitect_project
|
||||
git submodule update --remote capabilities/testdrive-jsui
|
||||
git commit -m "chore: update testdrive-jsui submodule"
|
||||
```
|
||||
|
||||
**Why separate instances?**
|
||||
- Clear context boundaries
|
||||
- Prevents accidental cross-contamination
|
||||
- Respects repository independence
|
||||
- Better commit hygiene
|
||||
|
||||
### Updating Submodules
|
||||
|
||||
When a capability releases a new version:
|
||||
|
||||
```bash
|
||||
# In main repo
|
||||
cd /home/worsch/markitect_project
|
||||
|
||||
# Update specific capability
|
||||
cd capabilities/testdrive-jsui
|
||||
git pull origin main
|
||||
cd ../..
|
||||
git add capabilities/testdrive-jsui
|
||||
git commit -m "chore: update testdrive-jsui to v1.2.0"
|
||||
|
||||
# Or update all capabilities
|
||||
git submodule update --remote
|
||||
git commit -am "chore: update all capabilities"
|
||||
```
|
||||
|
||||
### Adding New Capabilities
|
||||
|
||||
```bash
|
||||
# 1. Create capability repository on gitea
|
||||
# http://gitea/coulomb/new-capability
|
||||
|
||||
# 2. Add as submodule to main repo
|
||||
cd /home/worsch/markitect_project
|
||||
git submodule add http://gitea/coulomb/new-capability.git capabilities/new-capability
|
||||
|
||||
# 3. Add dependency to pyproject.toml
|
||||
# dependencies = [
|
||||
# "new-capability @ file:./capabilities/new-capability"
|
||||
# ]
|
||||
|
||||
# 4. Commit submodule addition
|
||||
git commit -m "feat: add new-capability as submodule"
|
||||
```
|
||||
|
||||
## Dependency Management
|
||||
|
||||
Capabilities are declared in `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[project]
|
||||
dependencies = [
|
||||
# Core dependencies
|
||||
"markdown-it-py",
|
||||
"click>=8.0.0",
|
||||
|
||||
# Capabilities (file-based dependencies)
|
||||
"release-management @ file:./capabilities/release-management",
|
||||
"testdrive-jsui @ file:./capabilities/testdrive-jsui",
|
||||
"issue-facade @ file:./capabilities/issue-facade",
|
||||
]
|
||||
```
|
||||
|
||||
**Pattern for Capabilities:**
|
||||
```toml
|
||||
"capability-name @ file:./capabilities/capability-name"
|
||||
```
|
||||
|
||||
This enables:
|
||||
- ✅ pip install with editable dependencies
|
||||
- ✅ Proper package resolution
|
||||
- ✅ Clean imports in code
|
||||
- ✅ Development mode support
|
||||
|
||||
## Capability Structure
|
||||
|
||||
Each capability should follow this structure:
|
||||
|
||||
```
|
||||
capability-name/
|
||||
├── README.md # Comprehensive documentation
|
||||
├── pyproject.toml # Package configuration
|
||||
├── Makefile # Build and test automation
|
||||
├── .gitignore # Git ignore rules
|
||||
├── src/capability_name/ # Python package source
|
||||
│ ├── __init__.py
|
||||
│ ├── core/ # Core functionality
|
||||
│ ├── utils/ # Utilities
|
||||
│ └── testing/ # Testing infrastructure
|
||||
├── js/ # JavaScript (if applicable)
|
||||
│ ├── components/
|
||||
│ ├── controls/
|
||||
│ └── tests/
|
||||
├── static/ # Static assets (if applicable)
|
||||
│ ├── css/
|
||||
│ ├── images/
|
||||
│ └── templates/
|
||||
├── tests/ # Python tests
|
||||
│ └── test_*.py
|
||||
└── docs/ # Additional documentation
|
||||
├── API.md
|
||||
└── USAGE.md
|
||||
```
|
||||
|
||||
### Required Files
|
||||
|
||||
1. **README.md** - Must include:
|
||||
- Purpose and description
|
||||
- Installation instructions
|
||||
- Usage examples
|
||||
- API documentation
|
||||
- Integration guide
|
||||
|
||||
2. **pyproject.toml** - Must define:
|
||||
- Package metadata
|
||||
- Dependencies
|
||||
- Build system
|
||||
- Entry points
|
||||
|
||||
3. **Makefile** - Should include:
|
||||
- help target
|
||||
- test targets
|
||||
- install/setup targets
|
||||
- capability-info target (for discovery)
|
||||
|
||||
## Plugin System Integration
|
||||
|
||||
For capabilities that provide plugins (like testdrive-jsui):
|
||||
|
||||
### Plugin Self-Declaration
|
||||
|
||||
```python
|
||||
class TestDriveJSUIEngine(RenderingEnginePlugin):
|
||||
"""Plugin declares its own location - no hardcoded paths."""
|
||||
|
||||
def get_plugin_source_dir(self) -> Path:
|
||||
"""Plugin knows where it lives."""
|
||||
return Path(__file__).parent.parent.parent / "capabilities" / "testdrive-jsui"
|
||||
|
||||
def get_asset_paths(self) -> Dict[str, Path]:
|
||||
"""Plugin declares its asset structure."""
|
||||
base = self.get_plugin_source_dir()
|
||||
return {
|
||||
'js': base / 'js',
|
||||
'css': base / 'static' / 'css',
|
||||
'templates': base / 'static' / 'templates',
|
||||
}
|
||||
```
|
||||
|
||||
### Plugin Discovery
|
||||
|
||||
The main repo uses **generic discovery** - no hardcoded capability names:
|
||||
|
||||
```python
|
||||
# ✅ Good: Generic discovery
|
||||
if hasattr(engine, 'get_plugin_source_dir'):
|
||||
source_dir = engine.get_plugin_source_dir()
|
||||
|
||||
# ❌ Bad: Hardcoded capability names
|
||||
if engine_name == 'testdrive-jsui':
|
||||
source_dir = Path('capabilities/testdrive-jsui')
|
||||
```
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Capability Tests
|
||||
Each capability tests **in isolation**:
|
||||
|
||||
```bash
|
||||
cd capabilities/testdrive-jsui
|
||||
pytest tests/
|
||||
npm test
|
||||
```
|
||||
|
||||
### Integration Tests
|
||||
Main repo tests **integration points**:
|
||||
|
||||
```python
|
||||
# tests/integration/test_capabilities.py
|
||||
def test_testdrive_jsui_integration():
|
||||
"""Test that testdrive-jsui integrates correctly."""
|
||||
engine = TestDriveJSUIEngine()
|
||||
result = engine.render_document(sample_content, 'edit', config)
|
||||
assert result is not None
|
||||
```
|
||||
|
||||
### Test Boundaries
|
||||
- **Capability tests**: Internal functionality, unit tests, component tests
|
||||
- **Main repo tests**: Integration, configuration, plugin discovery
|
||||
|
||||
## Migration Path
|
||||
|
||||
### Converting Local Capability to Submodule
|
||||
|
||||
1. **Create separate git repo**
|
||||
```bash
|
||||
cd /tmp
|
||||
cp -r markitect_project/capabilities/capability-name capability-name
|
||||
cd capability-name
|
||||
git init
|
||||
git add .
|
||||
git commit -m "Initial commit"
|
||||
git remote add origin http://gitea/coulomb/capability-name.git
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
2. **Remove from main repo**
|
||||
```bash
|
||||
cd markitect_project
|
||||
git rm -rf capabilities/capability-name
|
||||
git commit -m "chore: remove capability-name for submodule conversion"
|
||||
```
|
||||
|
||||
3. **Add as submodule**
|
||||
```bash
|
||||
git submodule add http://gitea/coulomb/capability-name.git capabilities/capability-name
|
||||
git commit -m "feat: add capability-name as submodule"
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### DO ✅
|
||||
|
||||
1. **Develop capabilities independently**
|
||||
- Use separate Claude instances
|
||||
- Maintain clear context boundaries
|
||||
- Follow semantic versioning
|
||||
|
||||
2. **Use documented interfaces**
|
||||
- Import via Python packages
|
||||
- Use plugin APIs
|
||||
- Follow configuration patterns
|
||||
|
||||
3. **Test integration points**
|
||||
- Verify capability imports
|
||||
- Test plugin discovery
|
||||
- Validate configurations
|
||||
|
||||
4. **Update submodules explicitly**
|
||||
- Pull capability changes deliberately
|
||||
- Review updates before committing
|
||||
- Update main repo pointer
|
||||
|
||||
5. **Document integration**
|
||||
- How to use the capability
|
||||
- Configuration options
|
||||
- Example usage
|
||||
|
||||
### DON'T ❌
|
||||
|
||||
1. **Edit capability code from main repo**
|
||||
- Opens separate repo/instance instead
|
||||
- Respects submodule boundary
|
||||
- Maintains clean separation
|
||||
|
||||
2. **Hardcode capability paths**
|
||||
- Use self-declaration instead
|
||||
- Generic discovery patterns
|
||||
- Interface-based access
|
||||
|
||||
3. **Create circular dependencies**
|
||||
- Main depends on capabilities
|
||||
- Capabilities should NOT depend on main
|
||||
- Keep dependency graph acyclic
|
||||
|
||||
4. **Bypass submodule system**
|
||||
- Don't manually copy files
|
||||
- Use git submodule commands
|
||||
- Respect version control
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Submodule not updated
|
||||
|
||||
```bash
|
||||
# Pull latest from capability repo
|
||||
cd capabilities/testdrive-jsui
|
||||
git pull origin main
|
||||
|
||||
# Update main repo pointer
|
||||
cd ../..
|
||||
git add capabilities/testdrive-jsui
|
||||
git commit -m "chore: update testdrive-jsui"
|
||||
```
|
||||
|
||||
### Import errors
|
||||
|
||||
```bash
|
||||
# Reinstall capabilities
|
||||
pip install -e .
|
||||
|
||||
# Or specific capability
|
||||
pip install -e ./capabilities/testdrive-jsui
|
||||
```
|
||||
|
||||
### Merge conflicts in submodules
|
||||
|
||||
```bash
|
||||
# Don't merge in submodule from main repo!
|
||||
# Instead, go to capability repo directly
|
||||
|
||||
cd /path/to/separate/testdrive-jsui
|
||||
# or
|
||||
cd capabilities/testdrive-jsui
|
||||
|
||||
# Resolve conflicts there
|
||||
git pull origin main
|
||||
# fix conflicts
|
||||
git push origin main
|
||||
|
||||
# Then update main repo
|
||||
cd ../../
|
||||
git submodule update --remote
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
- [Agent: Capability Manager](../../agents/agent-capability-manager.md) - Automated capability management
|
||||
- [Plugin System](../PLUGIN_SYSTEM.md) - Plugin architecture documentation
|
||||
- [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) - Official git submodules guide
|
||||
|
||||
---
|
||||
|
||||
**Remember:** Capabilities are **independent projects**. Treat them with the same respect you'd give any external dependency - use their interfaces, don't modify their internals.
|
||||
268
docs/workplan-testdrive-jsui-capability.md
Normal file
268
docs/workplan-testdrive-jsui-capability.md
Normal file
@@ -0,0 +1,268 @@
|
||||
# TestDrive-JSUI Capability Implementation Workplan
|
||||
|
||||
## 🎯 **Objective**
|
||||
|
||||
Safely extract JavaScript UI framework functionality into a dedicated `testdrive-jsui` capability while:
|
||||
- Protecting existing hard-won JavaScript UI functionality
|
||||
- Integrating JavaScript tests into the main Python test suite
|
||||
- Maintaining 100% test coverage and functionality
|
||||
- Creating a clean, extensible architecture for future JavaScript framework development
|
||||
|
||||
## 🔍 **Current State Analysis**
|
||||
|
||||
### **JavaScript UI Infrastructure:**
|
||||
|
||||
```
|
||||
markitect/static/js/
|
||||
├── core/
|
||||
│ └── section-manager.js (17K lines - Core component)
|
||||
├── components/
|
||||
│ ├── debug-panel.js (5.8K lines)
|
||||
│ ├── document-controls.js (7.9K lines)
|
||||
│ └── dom-renderer.js (40K lines - Major component)
|
||||
├── utils/ (Empty - utilities)
|
||||
└── tests/ (2.8K total lines)
|
||||
├── refactor-test-runner.js (Custom test framework)
|
||||
├── test-*.js (11 comprehensive test files)
|
||||
└── [Component-specific tests]
|
||||
```
|
||||
|
||||
### **Testing Infrastructure:**
|
||||
- ✅ **Jest framework** configured (`package.json`)
|
||||
- ✅ **JSDOM environment** for DOM testing
|
||||
- ✅ **Custom RefactorTestRunner** for TDD workflow
|
||||
- ✅ **11 comprehensive test files** (2,840 lines total)
|
||||
- ✅ **Component integration tests**
|
||||
- ✅ **Full workflow testing**
|
||||
|
||||
### **Feasibility: HIGHLY FEASIBLE** ✅
|
||||
- Well-structured components with clear separation
|
||||
- Comprehensive test coverage
|
||||
- Modern tooling (Jest + JSDOM)
|
||||
- Modular design already in place
|
||||
- TDD approach designed for safe refactoring
|
||||
|
||||
## 🚀 **Implementation Phases**
|
||||
|
||||
### **Phase 1: Foundation Setup** ⏱️ *~2-4 hours*
|
||||
|
||||
#### **Step 1.1: Create `testdrive-jsui` Capability Structure**
|
||||
```bash
|
||||
capabilities/testdrive-jsui/
|
||||
├── src/testdrive_jsui/
|
||||
│ ├── __init__.py
|
||||
│ ├── core/ # Framework components
|
||||
│ ├── components/ # UI components
|
||||
│ ├── utils/ # Utilities
|
||||
│ └── tests/ # Python test wrappers
|
||||
├── tests/ # Native Python tests
|
||||
├── js/ # JavaScript source
|
||||
│ ├── core/
|
||||
│ ├── components/
|
||||
│ ├── utils/
|
||||
│ └── tests/
|
||||
├── Makefile # Capability Makefile
|
||||
├── pyproject.toml # Package config
|
||||
├── package.json # JS dependencies
|
||||
├── jest.config.js # Jest configuration
|
||||
└── README.md # Documentation
|
||||
```
|
||||
|
||||
#### **Step 1.2: Setup Package Configuration**
|
||||
- **pyproject.toml**: Python package with subprocess/node dependencies
|
||||
- **package.json**: Jest + JSDOM + custom dependencies
|
||||
- **Makefile**: Integration with main capability system
|
||||
- **jest.config.js**: Proper test environment setup
|
||||
|
||||
#### **Step 1.3: Create Python-JavaScript Bridge**
|
||||
```python
|
||||
# testdrive_jsui/testing/js_test_runner.py
|
||||
class JavaScriptTestRunner:
|
||||
def run_js_tests(self, test_patterns=None):
|
||||
"""Run JavaScript tests via Node.js and return results"""
|
||||
|
||||
def integrate_with_pytest(self):
|
||||
"""Make JS tests discoverable by pytest"""
|
||||
```
|
||||
|
||||
### **Phase 2: Integration Layer** ⏱️ *~3-5 hours*
|
||||
|
||||
#### **Step 2.1: Python Test Wrappers**
|
||||
```python
|
||||
# Integration approach: Subprocess-based
|
||||
def test_section_manager_component():
|
||||
result = js_test_runner.run_test('test-section-manager-extraction.js')
|
||||
assert result.success
|
||||
assert result.tests_passed > 0
|
||||
|
||||
def test_dom_renderer_component():
|
||||
result = js_test_runner.run_test('test-domrenderer-extraction.js')
|
||||
assert result.success
|
||||
```
|
||||
|
||||
#### **Step 2.2: Main Test Suite Integration**
|
||||
- Add JS test discovery to pytest
|
||||
- Create test markers for JavaScript tests
|
||||
- Setup parallel execution (optional)
|
||||
- Integrate with main Makefile test targets
|
||||
|
||||
#### **Step 2.3: Capability Makefile Targets**
|
||||
```makefile
|
||||
# capabilities/testdrive-jsui/Makefile
|
||||
.PHONY: testdrive-jsui-test-js
|
||||
testdrive-jsui-test-js: ## Run JavaScript tests
|
||||
npm test
|
||||
|
||||
.PHONY: testdrive-jsui-test-integration
|
||||
testdrive-jsui-test-integration: ## Run Python-JS integration tests
|
||||
pytest tests/
|
||||
|
||||
.PHONY: testdrive-jsui-test-all
|
||||
testdrive-jsui-test-all: ## Run all tests (JS + Python integration)
|
||||
npm test && pytest tests/
|
||||
```
|
||||
|
||||
### **Phase 3: Safe Migration** ⏱️ *~4-6 hours*
|
||||
|
||||
#### **Step 3.1: Copy & Test Strategy**
|
||||
```bash
|
||||
# 1. Copy (don't move) JavaScript files to capability
|
||||
cp -r markitect/static/js/* capabilities/testdrive-jsui/js/
|
||||
|
||||
# 2. Verify tests still work in new location
|
||||
cd capabilities/testdrive-jsui && npm test
|
||||
|
||||
# 3. Create Python wrappers and verify integration
|
||||
pytest capabilities/testdrive-jsui/tests/
|
||||
|
||||
# 4. Add to main test suite gradually
|
||||
make test # Ensure main suite still passes
|
||||
```
|
||||
|
||||
#### **Step 3.2: Dual-Track Testing** *(Safety First!)*
|
||||
- Keep original files until migration complete
|
||||
- Run both locations in parallel initially
|
||||
- Compare test results for consistency
|
||||
- Gradual cutover with rollback option
|
||||
|
||||
### **Phase 4: Framework Enhancement** ⏱️ *~2-3 hours*
|
||||
|
||||
#### **Step 4.1: Enhanced Testing Framework**
|
||||
```javascript
|
||||
// Enhanced RefactorTestRunner with Python integration
|
||||
class EnhancedTestRunner extends RefactorTestRunner {
|
||||
reportToPython(results) {
|
||||
// JSON output for Python consumption
|
||||
}
|
||||
|
||||
runWithCoverage() {
|
||||
// Coverage reporting
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### **Step 4.2: Advanced Features**
|
||||
- Coverage reporting (Istanbul/nyc)
|
||||
- Performance benchmarks
|
||||
- Visual regression testing (optional)
|
||||
- Component documentation auto-generation
|
||||
|
||||
### **Phase 5: Production Integration** ⏱️ *~1-2 hours*
|
||||
|
||||
#### **Step 5.1: Main Test Suite Enhancement**
|
||||
```makefile
|
||||
# Add to main Makefile
|
||||
.PHONY: test-js
|
||||
test-js: ## Run JavaScript UI tests
|
||||
make testdrive-jsui-test-all
|
||||
|
||||
.PHONY: test-all
|
||||
test-all: test test-js test-capabilities ## Run all tests including JS
|
||||
```
|
||||
|
||||
#### **Step 5.2: CI/CD Integration**
|
||||
- Update test commands in main suite
|
||||
- Ensure capability auto-discovery works
|
||||
- Add JS test markers for selective running
|
||||
|
||||
## 🔒 **Safety Mechanisms**
|
||||
|
||||
### **Risk Mitigation:**
|
||||
|
||||
1. **📁 Copy-First Approach**: Never move, always copy initially
|
||||
2. **🔄 Dual Testing**: Run tests in both locations during migration
|
||||
3. **✅ Gradual Integration**: Add to main suite incrementally
|
||||
4. **🎯 Rollback Plan**: Keep original structure until 100% verified
|
||||
5. **🧪 Test Verification**: Compare results before/after migration
|
||||
|
||||
### **Success Criteria:**
|
||||
- ✅ All existing JS tests pass in new capability
|
||||
- ✅ Python integration tests pass
|
||||
- ✅ Main test suite still 100% green
|
||||
- ✅ JavaScript UI functionality unchanged
|
||||
- ✅ Performance maintained or improved
|
||||
|
||||
## 📋 **Implementation Checklist**
|
||||
|
||||
### **Phase 1: Foundation**
|
||||
- [ ] Create capability directory structure
|
||||
- [ ] Setup pyproject.toml with dependencies
|
||||
- [ ] Create package.json with Jest configuration
|
||||
- [ ] Implement Python-JavaScript bridge
|
||||
- [ ] Create capability Makefile
|
||||
- [ ] Write basic README documentation
|
||||
|
||||
### **Phase 2: Integration**
|
||||
- [ ] Create Python test wrappers for JS tests
|
||||
- [ ] Integrate with pytest discovery
|
||||
- [ ] Add capability targets to main Makefile
|
||||
- [ ] Test integration with main test suite
|
||||
|
||||
### **Phase 3: Migration**
|
||||
- [ ] Copy JavaScript files to capability
|
||||
- [ ] Verify tests work in new location
|
||||
- [ ] Create dual-track testing setup
|
||||
- [ ] Gradually integrate with main suite
|
||||
|
||||
### **Phase 4: Enhancement**
|
||||
- [ ] Enhance test framework with Python integration
|
||||
- [ ] Add coverage reporting
|
||||
- [ ] Performance benchmarking
|
||||
- [ ] Documentation generation
|
||||
|
||||
### **Phase 5: Production**
|
||||
- [ ] Full integration with main test suite
|
||||
- [ ] CI/CD pipeline updates
|
||||
- [ ] Final verification and cleanup
|
||||
|
||||
## ⚡ **Quick Start Option**
|
||||
|
||||
For immediate JavaScript test integration (30 minutes):
|
||||
|
||||
```python
|
||||
def test_javascript_ui_components():
|
||||
"""Run all JavaScript tests via subprocess"""
|
||||
import subprocess
|
||||
result = subprocess.run(['npm', 'test'],
|
||||
capture_output=True, text=True)
|
||||
assert result.returncode == 0, f"JS tests failed: {result.stderr}"
|
||||
```
|
||||
|
||||
## 🎯 **Expected Outcomes**
|
||||
|
||||
- **🔒 Zero-risk migration** with copy-first approach
|
||||
- **🧪 Enhanced testing** with Python integration
|
||||
- **📊 Better CI/CD** integration
|
||||
- **🏗️ Clean architecture** with capability isolation
|
||||
- **🚀 Future extensibility** for JavaScript framework evolution
|
||||
|
||||
## ⏱️ **Timeline**
|
||||
|
||||
**Total Estimated Time: 12-20 hours** (can be done incrementally)
|
||||
|
||||
**Recommended approach**: Start with Phase 1 for immediate value and safe migration path setup.
|
||||
|
||||
---
|
||||
|
||||
*Generated: 2025-11-09*
|
||||
*Status: Ready for Implementation*
|
||||
@@ -1,33 +0,0 @@
|
||||
"""
|
||||
Gitea API facade - Clean interface for Gitea repository operations.
|
||||
|
||||
This package provides a clean, well-structured interface to Gitea API operations,
|
||||
following the facade pattern to decouple application logic from specific API
|
||||
implementation details.
|
||||
|
||||
Structure:
|
||||
- client: Main GiteaClient facade
|
||||
- models: Domain models (Issue, Milestone, Label, etc.)
|
||||
- config: Gitea-specific configuration
|
||||
- exceptions: Gitea-specific exceptions
|
||||
|
||||
Usage:
|
||||
from gitea import GiteaClient
|
||||
|
||||
client = GiteaClient()
|
||||
issues = client.issues.list()
|
||||
issue = client.issues.get(42)
|
||||
client.issues.create("Bug fix", "Description")
|
||||
"""
|
||||
|
||||
from .client import GiteaClient
|
||||
from .models import Issue, Milestone, Label, ProjectState, Priority
|
||||
from .config import GiteaConfig
|
||||
from .exceptions import GiteaError, GiteaAuthError, GiteaNotFoundError
|
||||
|
||||
__all__ = [
|
||||
'GiteaClient',
|
||||
'Issue', 'Milestone', 'Label', 'ProjectState', 'Priority',
|
||||
'GiteaConfig',
|
||||
'GiteaError', 'GiteaAuthError', 'GiteaNotFoundError'
|
||||
]
|
||||
@@ -1,241 +0,0 @@
|
||||
"""
|
||||
High-level API client that converts between API responses and domain models.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
from .http_client import GiteaHttpClient
|
||||
from .models import Issue, Milestone, Label, User, IssueCreateData, IssueUpdateData, MilestoneCreateData, LabelCreateData
|
||||
from .config import GiteaConfig
|
||||
from .exceptions import GiteaNotFoundError, GiteaError
|
||||
|
||||
|
||||
class GiteaApiClient:
|
||||
"""High-level API client with domain model conversion."""
|
||||
|
||||
def __init__(self, config: GiteaConfig):
|
||||
self.config = config
|
||||
self.http = GiteaHttpClient(config)
|
||||
|
||||
# Issue operations
|
||||
def get_issue(self, issue_number: int) -> Issue:
|
||||
"""Get a specific issue by number."""
|
||||
try:
|
||||
url = f"{self.config.issues_api_url}/{issue_number}"
|
||||
data = self.http.get(url)
|
||||
return self._parse_issue(data)
|
||||
except GiteaError as e:
|
||||
if "not found" in str(e).lower():
|
||||
raise GiteaNotFoundError(f"Issue #{issue_number} not found")
|
||||
raise
|
||||
|
||||
def list_issues(self, state: str = "all", page: int = 1, per_page: int = 50) -> List[Issue]:
|
||||
"""List issues with optional filtering."""
|
||||
params = {"page": str(page), "limit": str(per_page)}
|
||||
if state != "all":
|
||||
params["state"] = state
|
||||
|
||||
data = self.http.get(self.config.issues_api_url, params)
|
||||
|
||||
if not isinstance(data, list):
|
||||
raise GiteaError("Invalid response format: expected list of issues")
|
||||
|
||||
return [self._parse_issue(issue_data) for issue_data in data]
|
||||
|
||||
def create_issue(self, issue_data: IssueCreateData) -> Issue:
|
||||
"""Create a new issue."""
|
||||
payload = {
|
||||
"title": issue_data.title,
|
||||
"body": issue_data.body,
|
||||
}
|
||||
|
||||
if issue_data.assignees:
|
||||
payload["assignees"] = issue_data.assignees
|
||||
if issue_data.milestone:
|
||||
payload["milestone"] = issue_data.milestone
|
||||
if issue_data.labels:
|
||||
# Convert label names to label IDs
|
||||
payload["labels"] = self._resolve_label_ids(issue_data.labels)
|
||||
|
||||
data = self.http.post(self.config.issues_api_url, payload)
|
||||
return self._parse_issue(data)
|
||||
|
||||
def update_issue(self, issue_number: int, update_data: IssueUpdateData) -> Issue:
|
||||
"""Update an existing issue."""
|
||||
payload = {}
|
||||
|
||||
if update_data.title is not None:
|
||||
payload["title"] = update_data.title
|
||||
if update_data.body is not None:
|
||||
payload["body"] = update_data.body
|
||||
if update_data.state is not None:
|
||||
payload["state"] = update_data.state
|
||||
if update_data.assignees is not None:
|
||||
payload["assignees"] = update_data.assignees
|
||||
if update_data.milestone is not None:
|
||||
payload["milestone"] = update_data.milestone
|
||||
if update_data.labels is not None:
|
||||
payload["labels"] = update_data.labels
|
||||
|
||||
url = f"{self.config.issues_api_url}/{issue_number}"
|
||||
data = self.http.patch(url, payload)
|
||||
return self._parse_issue(data)
|
||||
|
||||
# Milestone operations
|
||||
def list_milestones(self, state: str = "all") -> List[Milestone]:
|
||||
"""List repository milestones."""
|
||||
params = {}
|
||||
if state != "all":
|
||||
params["state"] = state
|
||||
|
||||
data = self.http.get(self.config.milestones_api_url, params)
|
||||
|
||||
if not isinstance(data, list):
|
||||
raise GiteaError("Invalid response format: expected list of milestones")
|
||||
|
||||
return [self._parse_milestone(milestone_data) for milestone_data in data]
|
||||
|
||||
def create_milestone(self, milestone_data: MilestoneCreateData) -> Milestone:
|
||||
"""Create a new milestone."""
|
||||
payload = {
|
||||
"title": milestone_data.title,
|
||||
"description": milestone_data.description,
|
||||
}
|
||||
|
||||
if milestone_data.due_on:
|
||||
payload["due_on"] = milestone_data.due_on
|
||||
|
||||
data = self.http.post(self.config.milestones_api_url, payload)
|
||||
return self._parse_milestone(data)
|
||||
|
||||
# Label operations
|
||||
def list_labels(self) -> List[Label]:
|
||||
"""List repository labels."""
|
||||
data = self.http.get(self.config.labels_api_url)
|
||||
|
||||
if not isinstance(data, list):
|
||||
raise GiteaError("Invalid response format: expected list of labels")
|
||||
|
||||
return [self._parse_label(label_data) for label_data in data]
|
||||
|
||||
def create_label(self, label_data: LabelCreateData) -> Label:
|
||||
"""Create a new label."""
|
||||
payload = {
|
||||
"name": label_data.name,
|
||||
"color": label_data.color,
|
||||
"description": label_data.description,
|
||||
}
|
||||
|
||||
data = self.http.post(self.config.labels_api_url, payload)
|
||||
return self._parse_label(data)
|
||||
|
||||
# Parsing methods
|
||||
def _parse_issue(self, data: Dict[str, Any]) -> Issue:
|
||||
"""Parse issue data from API response."""
|
||||
try:
|
||||
# Parse labels
|
||||
labels = []
|
||||
if data.get('labels'):
|
||||
labels = [self._parse_label(label_data) for label_data in data['labels']]
|
||||
|
||||
# Parse assignee
|
||||
assignee = None
|
||||
if data.get('assignee'):
|
||||
assignee = self._parse_user(data['assignee'])
|
||||
|
||||
# Parse milestone
|
||||
milestone = None
|
||||
if data.get('milestone'):
|
||||
milestone = self._parse_milestone(data['milestone'])
|
||||
|
||||
# Check if this is an error response
|
||||
if 'message' in data and 'url' in data and 'number' not in data and 'id' not in data:
|
||||
raise GiteaError(f"API Error: {data.get('message', 'Unknown error')} (URL: {data.get('url', 'N/A')})")
|
||||
|
||||
# Handle both 'number' and 'id' fields (Gitea API might use either)
|
||||
issue_number = data.get('number') or data.get('id')
|
||||
if issue_number is None:
|
||||
raise GiteaError(f"Issue response missing both 'number' and 'id' fields. Available fields: {list(data.keys())}")
|
||||
|
||||
return Issue(
|
||||
number=issue_number,
|
||||
title=data['title'],
|
||||
body=data.get('body', ''),
|
||||
state=data['state'],
|
||||
created_at=self._parse_datetime(data['created_at']),
|
||||
updated_at=self._parse_datetime(data['updated_at']),
|
||||
html_url=data['html_url'],
|
||||
assignee=assignee,
|
||||
labels=labels,
|
||||
milestone=milestone
|
||||
)
|
||||
except (KeyError, ValueError) as e:
|
||||
raise GiteaError(f"Failed to parse issue data: {e}")
|
||||
|
||||
def _parse_milestone(self, data: Dict[str, Any]) -> Milestone:
|
||||
"""Parse milestone data from API response."""
|
||||
return Milestone(
|
||||
id=data['id'],
|
||||
title=data['title'],
|
||||
description=data.get('description', ''),
|
||||
state=data['state'],
|
||||
open_issues=data.get('open_issues', 0),
|
||||
closed_issues=data.get('closed_issues', 0),
|
||||
due_on=data.get('due_on'),
|
||||
created_at=self._parse_datetime(data.get('created_at')) if data.get('created_at') else None,
|
||||
updated_at=self._parse_datetime(data.get('updated_at')) if data.get('updated_at') else None
|
||||
)
|
||||
|
||||
def _parse_label(self, data: Dict[str, Any]) -> Label:
|
||||
"""Parse label data from API response."""
|
||||
return Label(
|
||||
id=data['id'],
|
||||
name=data['name'],
|
||||
color=data['color'],
|
||||
description=data.get('description', '')
|
||||
)
|
||||
|
||||
def _parse_user(self, data: Dict[str, Any]) -> User:
|
||||
"""Parse user data from API response."""
|
||||
return User(
|
||||
id=data['id'],
|
||||
login=data['login'],
|
||||
full_name=data.get('full_name', ''),
|
||||
email=data.get('email', ''),
|
||||
avatar_url=data.get('avatar_url', '')
|
||||
)
|
||||
|
||||
def _parse_datetime(self, date_str: str) -> datetime:
|
||||
"""Parse datetime from API response."""
|
||||
# Remove Z and microseconds for consistent parsing
|
||||
date_str = date_str.replace('Z', '').split('.')[0]
|
||||
return datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
def _resolve_label_ids(self, label_names: List[str]) -> List[int]:
|
||||
"""Convert label names to label IDs for API calls."""
|
||||
try:
|
||||
# Get all labels for the repository
|
||||
labels_data = self.http.get(self.config.labels_api_url)
|
||||
if not isinstance(labels_data, list):
|
||||
raise GiteaError("Invalid labels response format")
|
||||
|
||||
# Create name-to-ID mapping
|
||||
label_map = {label_data['name']: label_data['id'] for label_data in labels_data}
|
||||
|
||||
# Resolve names to IDs
|
||||
label_ids = []
|
||||
for name in label_names:
|
||||
if name in label_map:
|
||||
label_ids.append(label_map[name])
|
||||
else:
|
||||
# If label doesn't exist, we could create it or skip it
|
||||
# For now, let's skip non-existent labels
|
||||
print(f"Warning: Label '{name}' not found, skipping")
|
||||
|
||||
return label_ids
|
||||
|
||||
except Exception as e:
|
||||
# If label resolution fails, proceed without labels rather than failing entirely
|
||||
print(f"Warning: Could not resolve labels: {e}")
|
||||
return []
|
||||
237
gitea/client.py
237
gitea/client.py
@@ -1,237 +0,0 @@
|
||||
"""
|
||||
Main Gitea client facade.
|
||||
|
||||
This provides a clean, organized interface for all Gitea operations,
|
||||
following the facade pattern to hide complexity and provide a stable API.
|
||||
"""
|
||||
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
from .config import GiteaConfig
|
||||
from .api_client import GiteaApiClient
|
||||
from .models import Issue, Milestone, Label, IssueCreateData, IssueUpdateData, MilestoneCreateData, LabelCreateData, ProjectState, Priority
|
||||
|
||||
|
||||
class IssuesClient:
|
||||
"""Client for issue operations."""
|
||||
|
||||
def __init__(self, api_client: GiteaApiClient):
|
||||
self._api = api_client
|
||||
|
||||
def get(self, issue_number: int) -> Issue:
|
||||
"""Get a specific issue by number."""
|
||||
return self._api.get_issue(issue_number)
|
||||
|
||||
def list(self, state: str = "all", page: int = 1, per_page: int = 50) -> List[Issue]:
|
||||
"""List issues with optional filtering."""
|
||||
return self._api.list_issues(state, page, per_page)
|
||||
|
||||
def list_open(self) -> List[Issue]:
|
||||
"""List only open issues."""
|
||||
return self._api.list_issues("open")
|
||||
|
||||
def list_closed(self) -> List[Issue]:
|
||||
"""List only closed issues."""
|
||||
return self._api.list_issues("closed")
|
||||
|
||||
def create(self, title: str, body: str = "", **kwargs) -> Issue:
|
||||
"""Create a new issue."""
|
||||
issue_data = IssueCreateData(
|
||||
title=title,
|
||||
body=body,
|
||||
assignees=kwargs.get('assignees', []),
|
||||
milestone=kwargs.get('milestone'),
|
||||
labels=kwargs.get('labels', [])
|
||||
)
|
||||
return self._api.create_issue(issue_data)
|
||||
|
||||
def update(self, issue_number: int, **kwargs) -> Issue:
|
||||
"""Update an existing issue."""
|
||||
update_data = IssueUpdateData(
|
||||
title=kwargs.get('title'),
|
||||
body=kwargs.get('body'),
|
||||
state=kwargs.get('state'),
|
||||
assignees=kwargs.get('assignees'),
|
||||
milestone=kwargs.get('milestone'),
|
||||
labels=kwargs.get('labels')
|
||||
)
|
||||
return self._api.update_issue(issue_number, update_data)
|
||||
|
||||
def close(self, issue_number: int) -> Issue:
|
||||
"""Close an issue."""
|
||||
return self.update(issue_number, state="closed")
|
||||
|
||||
def reopen(self, issue_number: int) -> Issue:
|
||||
"""Reopen an issue."""
|
||||
return self.update(issue_number, state="open")
|
||||
|
||||
def add_labels(self, issue_number: int, labels: List[str]) -> Issue:
|
||||
"""Add labels to an issue."""
|
||||
issue = self.get(issue_number)
|
||||
existing_labels = [label.name for label in issue.labels]
|
||||
new_labels = list(set(existing_labels + labels))
|
||||
return self.update(issue_number, labels=new_labels)
|
||||
|
||||
def remove_labels(self, issue_number: int, labels: List[str]) -> Issue:
|
||||
"""Remove labels from an issue."""
|
||||
issue = self.get(issue_number)
|
||||
existing_labels = [label.name for label in issue.labels]
|
||||
new_labels = [label for label in existing_labels if label not in labels]
|
||||
return self.update(issue_number, labels=new_labels)
|
||||
|
||||
def set_priority(self, issue_number: int, priority: Priority) -> Issue:
|
||||
"""Set issue priority."""
|
||||
issue = self.get(issue_number)
|
||||
labels = [label.name for label in issue.labels if not label.name.startswith('priority:')]
|
||||
labels.append(priority.value)
|
||||
return self.update(issue_number, labels=labels)
|
||||
|
||||
def set_status(self, issue_number: int, status: ProjectState) -> Issue:
|
||||
"""Set issue status."""
|
||||
issue = self.get(issue_number)
|
||||
labels = [label.name for label in issue.labels if not label.name.startswith('status:')]
|
||||
labels.append(status.value)
|
||||
return self.update(issue_number, labels=labels)
|
||||
|
||||
def assign_to_milestone(self, issue_number: int, milestone_id: int) -> Issue:
|
||||
"""Assign issue to a milestone."""
|
||||
return self.update(issue_number, milestone=milestone_id)
|
||||
|
||||
def remove_from_milestone(self, issue_number: int) -> Issue:
|
||||
"""Remove issue from milestone."""
|
||||
return self.update(issue_number, milestone=None)
|
||||
|
||||
def set_labels(self, issue_number: int, labels: List[str]) -> Issue:
|
||||
"""Replace all labels on an issue."""
|
||||
return self.update(issue_number, labels=labels)
|
||||
|
||||
def update_title(self, issue_number: int, title: str) -> Issue:
|
||||
"""Update only the title of an issue."""
|
||||
return self.update(issue_number, title=title)
|
||||
|
||||
def update_body(self, issue_number: int, body: str) -> Issue:
|
||||
"""Update only the body of an issue."""
|
||||
return self.update(issue_number, body=body)
|
||||
|
||||
def to_dict(self, issue: Issue) -> Dict[str, Any]:
|
||||
"""Convert Issue object to dictionary format for backward compatibility."""
|
||||
return {
|
||||
'number': issue.number,
|
||||
'title': issue.title,
|
||||
'body': issue.body,
|
||||
'state': issue.state,
|
||||
'html_url': issue.html_url,
|
||||
'created_at': issue.created_at.isoformat(),
|
||||
'updated_at': issue.updated_at.isoformat(),
|
||||
'assignee': {'login': issue.assignee.login} if issue.assignee else None,
|
||||
'labels': [{'name': label.name, 'color': label.color} for label in issue.labels],
|
||||
'milestone': {
|
||||
'id': issue.milestone.id,
|
||||
'title': issue.milestone.title
|
||||
} if issue.milestone else None
|
||||
}
|
||||
|
||||
|
||||
class MilestonesClient:
|
||||
"""Client for milestone operations."""
|
||||
|
||||
def __init__(self, api_client: GiteaApiClient):
|
||||
self._api = api_client
|
||||
|
||||
def list(self, state: str = "all") -> List[Milestone]:
|
||||
"""List milestones."""
|
||||
return self._api.list_milestones(state)
|
||||
|
||||
def list_open(self) -> List[Milestone]:
|
||||
"""List open milestones."""
|
||||
return self._api.list_milestones("open")
|
||||
|
||||
def list_closed(self) -> List[Milestone]:
|
||||
"""List closed milestones."""
|
||||
return self._api.list_milestones("closed")
|
||||
|
||||
def create(self, title: str, description: str = "", due_on: str = None) -> Milestone:
|
||||
"""Create a new milestone."""
|
||||
milestone_data = MilestoneCreateData(
|
||||
title=title,
|
||||
description=description,
|
||||
due_on=due_on
|
||||
)
|
||||
return self._api.create_milestone(milestone_data)
|
||||
|
||||
|
||||
class LabelsClient:
|
||||
"""Client for label operations."""
|
||||
|
||||
def __init__(self, api_client: GiteaApiClient):
|
||||
self._api = api_client
|
||||
|
||||
def list(self) -> List[Label]:
|
||||
"""List all labels."""
|
||||
return self._api.list_labels()
|
||||
|
||||
def create(self, name: str, color: str, description: str = "") -> Label:
|
||||
"""Create a new label."""
|
||||
label_data = LabelCreateData(
|
||||
name=name,
|
||||
color=color,
|
||||
description=description
|
||||
)
|
||||
return self._api.create_label(label_data)
|
||||
|
||||
def ensure_project_labels(self) -> None:
|
||||
"""Ensure all standard project management labels exist."""
|
||||
existing_labels = [label.name for label in self.list()]
|
||||
|
||||
# Define standard project labels
|
||||
standard_labels = [
|
||||
("status:todo", "d73a4a", "Ready to work on"),
|
||||
("status:active", "0075ca", "Currently being worked on"),
|
||||
("status:review", "fbca04", "Ready for review"),
|
||||
("status:done", "0e8a16", "Completed work"),
|
||||
("status:blocked", "b60205", "Blocked by dependencies"),
|
||||
("priority:low", "c5def5", "Low priority"),
|
||||
("priority:medium", "a2eeef", "Medium priority"),
|
||||
("priority:high", "fef2c0", "High priority"),
|
||||
("priority:critical", "d93f0b", "Critical priority"),
|
||||
]
|
||||
|
||||
for name, color, description in standard_labels:
|
||||
if name not in existing_labels:
|
||||
self.create(name, color, description)
|
||||
|
||||
|
||||
class GiteaClient:
|
||||
"""Main Gitea client facade."""
|
||||
|
||||
def __init__(self, config: Optional[GiteaConfig] = None):
|
||||
"""Initialize Gitea client.
|
||||
|
||||
Args:
|
||||
config: GiteaConfig instance. If None, auto-detects from git repository.
|
||||
"""
|
||||
if config is None:
|
||||
try:
|
||||
config = GiteaConfig.from_git_repository()
|
||||
except Exception:
|
||||
# Fallback to environment-based config if git detection fails
|
||||
config = GiteaConfig.from_environment()
|
||||
config.validate()
|
||||
|
||||
self.config = config
|
||||
self._api = GiteaApiClient(config)
|
||||
|
||||
# Initialize sub-clients
|
||||
self.issues = IssuesClient(self._api)
|
||||
self.milestones = MilestonesClient(self._api)
|
||||
self.labels = LabelsClient(self._api)
|
||||
|
||||
@classmethod
|
||||
def from_tddai_config(cls, tddai_config) -> 'GiteaClient':
|
||||
"""Create client from legacy TddaiConfig for backwards compatibility."""
|
||||
gitea_config = GiteaConfig.from_tddai_config(tddai_config)
|
||||
return cls(gitea_config)
|
||||
|
||||
def setup_project_management(self) -> None:
|
||||
"""Setup standard project management labels and structure."""
|
||||
self.labels.ensure_project_labels()
|
||||
@@ -1,31 +0,0 @@
|
||||
"""
|
||||
Gitea-specific exceptions.
|
||||
"""
|
||||
|
||||
|
||||
class GiteaError(Exception):
|
||||
"""Base exception for Gitea API operations."""
|
||||
pass
|
||||
|
||||
|
||||
class GiteaAuthError(GiteaError):
|
||||
"""Raised when authentication fails or token is missing."""
|
||||
pass
|
||||
|
||||
|
||||
class GiteaNotFoundError(GiteaError):
|
||||
"""Raised when requested resource is not found."""
|
||||
pass
|
||||
|
||||
|
||||
class GiteaApiError(GiteaError):
|
||||
"""Raised when API returns an error response."""
|
||||
|
||||
def __init__(self, message: str, status_code: int = None):
|
||||
super().__init__(message)
|
||||
self.status_code = status_code
|
||||
|
||||
|
||||
class GiteaConfigError(GiteaError):
|
||||
"""Raised when Gitea configuration is invalid or missing."""
|
||||
pass
|
||||
@@ -1,98 +0,0 @@
|
||||
"""
|
||||
Low-level HTTP client for Gitea API operations.
|
||||
|
||||
This module handles the actual HTTP requests to Gitea API using subprocess + curl
|
||||
for maximum compatibility and minimal dependencies.
|
||||
"""
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from subprocess import PIPE
|
||||
from typing import Dict, Any, Optional, List
|
||||
|
||||
from .exceptions import GiteaError, GiteaApiError, GiteaAuthError
|
||||
from .config import GiteaConfig
|
||||
|
||||
|
||||
class GiteaHttpClient:
|
||||
"""Low-level HTTP client for Gitea API."""
|
||||
|
||||
def __init__(self, config: GiteaConfig):
|
||||
self.config = config
|
||||
|
||||
def get(self, url: str, params: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
|
||||
"""Make GET request to Gitea API."""
|
||||
if params:
|
||||
param_string = '&'.join(f"{k}={v}" for k, v in params.items())
|
||||
url = f"{url}?{param_string}"
|
||||
|
||||
return self._make_request('GET', url)
|
||||
|
||||
def post(self, url: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
"""Make POST request to Gitea API."""
|
||||
self._require_auth()
|
||||
return self._make_request('POST', url, data)
|
||||
|
||||
def patch(self, url: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
"""Make PATCH request to Gitea API."""
|
||||
self._require_auth()
|
||||
return self._make_request('PATCH', url, data)
|
||||
|
||||
def delete(self, url: str) -> Dict[str, Any]:
|
||||
"""Make DELETE request to Gitea API."""
|
||||
self._require_auth()
|
||||
return self._make_request('DELETE', url)
|
||||
|
||||
def _make_request(self, method: str, url: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
"""Make HTTP request using curl."""
|
||||
cmd = ['curl', '-s', '-X', method]
|
||||
|
||||
# Add authentication if available
|
||||
if self.config.auth_token:
|
||||
cmd.extend(['-H', f'Authorization: token {self.config.auth_token}'])
|
||||
|
||||
# Add content type for requests with data
|
||||
if data is not None:
|
||||
cmd.extend(['-H', 'Content-Type: application/json'])
|
||||
cmd.extend(['-d', json.dumps(data)])
|
||||
|
||||
cmd.append(url)
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
universal_newlines=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
raise GiteaApiError(f"HTTP request failed: {result.stderr}")
|
||||
|
||||
# Handle empty responses
|
||||
if not result.stdout.strip():
|
||||
return {}
|
||||
|
||||
response_data = json.loads(result.stdout)
|
||||
|
||||
# Check for API error responses
|
||||
if isinstance(response_data, dict):
|
||||
if 'message' in response_data:
|
||||
# This could be an error or just a response with a message field
|
||||
# We need to distinguish based on context or HTTP status
|
||||
if any(error_word in response_data['message'].lower()
|
||||
for error_word in ['error', 'not found', 'forbidden', 'unauthorized']):
|
||||
raise GiteaApiError(response_data['message'])
|
||||
|
||||
return response_data
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise GiteaApiError(f"HTTP request failed: {e.stderr}")
|
||||
except json.JSONDecodeError as e:
|
||||
raise GiteaError(f"Failed to parse API response: {e}")
|
||||
|
||||
def _require_auth(self):
|
||||
"""Ensure authentication token is available."""
|
||||
if not self.config.auth_token:
|
||||
raise GiteaAuthError("Authentication token required for this operation")
|
||||
151
gitea/models.py
151
gitea/models.py
@@ -1,151 +0,0 @@
|
||||
"""
|
||||
Gitea domain models.
|
||||
|
||||
These models represent the core entities in Gitea and provide a clean interface
|
||||
independent of the underlying API representation.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
|
||||
class ProjectState(Enum):
|
||||
"""Standard project states using labels."""
|
||||
TODO = "status:todo"
|
||||
ACTIVE = "status:active"
|
||||
REVIEW = "status:review"
|
||||
DONE = "status:done"
|
||||
BLOCKED = "status:blocked"
|
||||
|
||||
|
||||
class Priority(Enum):
|
||||
"""Priority levels using labels."""
|
||||
LOW = "priority:low"
|
||||
MEDIUM = "priority:medium"
|
||||
HIGH = "priority:high"
|
||||
CRITICAL = "priority:critical"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Label:
|
||||
"""Represents a Gitea issue label."""
|
||||
id: int
|
||||
name: str
|
||||
color: str
|
||||
description: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class User:
|
||||
"""Represents a Gitea user."""
|
||||
id: int
|
||||
login: str
|
||||
full_name: str = ""
|
||||
email: str = ""
|
||||
avatar_url: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class Milestone:
|
||||
"""Represents a Gitea milestone (used as projects)."""
|
||||
id: int
|
||||
title: str
|
||||
description: str
|
||||
state: str # 'open' or 'closed'
|
||||
open_issues: int
|
||||
closed_issues: int
|
||||
due_on: Optional[str] = None
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Issue:
|
||||
"""Represents a Gitea issue."""
|
||||
number: int
|
||||
title: str
|
||||
body: str
|
||||
state: str # 'open' or 'closed'
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
html_url: str
|
||||
assignee: Optional[User] = None
|
||||
labels: List[Label] = None
|
||||
milestone: Optional[Milestone] = None
|
||||
|
||||
def __post_init__(self):
|
||||
if self.labels is None:
|
||||
self.labels = []
|
||||
|
||||
@property
|
||||
def priority(self) -> Optional[str]:
|
||||
"""Get issue priority from labels."""
|
||||
for label in self.labels:
|
||||
if label.name.startswith('priority:'):
|
||||
return label.name.replace('priority:', '')
|
||||
return None
|
||||
|
||||
@property
|
||||
def status(self) -> Optional[str]:
|
||||
"""Get issue status from labels."""
|
||||
for label in self.labels:
|
||||
if label.name.startswith('status:'):
|
||||
return label.name.replace('status:', '')
|
||||
return None
|
||||
|
||||
def has_label(self, label_name: str) -> bool:
|
||||
"""Check if issue has a specific label."""
|
||||
return any(label.name == label_name for label in self.labels)
|
||||
|
||||
def has_priority(self, priority: Priority) -> bool:
|
||||
"""Check if issue has a specific priority."""
|
||||
return self.has_label(priority.value)
|
||||
|
||||
def has_status(self, status: ProjectState) -> bool:
|
||||
"""Check if issue has a specific status."""
|
||||
return self.has_label(status.value)
|
||||
|
||||
|
||||
@dataclass
|
||||
class IssueCreateData:
|
||||
"""Data for creating a new issue."""
|
||||
title: str
|
||||
body: str = ""
|
||||
assignees: List[str] = None
|
||||
milestone: Optional[int] = None
|
||||
labels: List[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
if self.assignees is None:
|
||||
self.assignees = []
|
||||
if self.labels is None:
|
||||
self.labels = []
|
||||
|
||||
|
||||
@dataclass
|
||||
class IssueUpdateData:
|
||||
"""Data for updating an existing issue."""
|
||||
title: Optional[str] = None
|
||||
body: Optional[str] = None
|
||||
state: Optional[str] = None
|
||||
assignees: Optional[List[str]] = None
|
||||
milestone: Optional[int] = None
|
||||
labels: Optional[List[str]] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class MilestoneCreateData:
|
||||
"""Data for creating a new milestone."""
|
||||
title: str
|
||||
description: str = ""
|
||||
due_on: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class LabelCreateData:
|
||||
"""Data for creating a new label."""
|
||||
name: str
|
||||
color: str
|
||||
description: str = ""
|
||||
1088
history/20251216-architecture-assessment.md
Normal file
1088
history/20251216-architecture-assessment.md
Normal file
File diff suppressed because it is too large
Load Diff
123
history/251114-INTEGRATION_COMPLETE.md
Normal file
123
history/251114-INTEGRATION_COMPLETE.md
Normal file
@@ -0,0 +1,123 @@
|
||||
# 🎉 Plugin Infrastructure Integration Complete!
|
||||
|
||||
## Summary
|
||||
|
||||
Successfully implemented and merged a comprehensive plugin infrastructure for Markitect rendering engines, enabling independent JavaScript UI development while maintaining seamless CLI integration.
|
||||
|
||||
## 🚀 **What Was Accomplished**
|
||||
|
||||
### 1. **Plugin Architecture** ✅
|
||||
- Extended existing MarkiTect plugin system with `RenderingEnginePlugin` base class
|
||||
- Added `RENDERING` plugin type to `PluginType` enum
|
||||
- Created `RenderingConfig` for asset management and deployment
|
||||
- Implemented `RenderingEngineManager` for plugin discovery and lifecycle
|
||||
|
||||
### 2. **TestDrive JSUI Plugin** ✅
|
||||
- Complete independent JavaScript UI plugin extracted from core system
|
||||
- Standalone development environment (`testdrive-jsui/test.html`)
|
||||
- Modular component architecture with compass-positioned controls
|
||||
- Clean JSON configuration interface (Python ↔ JavaScript)
|
||||
|
||||
### 3. **CLI Integration** ✅
|
||||
- Added `--engine` parameter to `markitect md-render` command
|
||||
- **Default behavior**: `testdrive-jsui` for edit/insert modes, `standard` for view
|
||||
- Graceful fallback to standard rendering when plugins unavailable
|
||||
- Engine validation and mode compatibility checking
|
||||
|
||||
### 4. **Asset Management** ✅
|
||||
- Automatic asset deployment to `_markitect/plugins/` structure
|
||||
- 18 total assets deployed: 12 JS, 3 CSS, 3 images
|
||||
- Production-ready file copying with directory structure preservation
|
||||
- Development vs production deployment strategies
|
||||
|
||||
### 5. **JavaScript Fixes** ✅
|
||||
- Resolved const redeclaration errors (`MARKITECT_STRICT_MODE`)
|
||||
- Fixed MarkitectMain availability (proper main-updated.js loading)
|
||||
- Eliminated JavaScript loading conflicts and syntax errors
|
||||
|
||||
### 6. **Documentation** ✅
|
||||
- Complete `docs/PLUGIN_SYSTEM.md` with architecture overview
|
||||
- Development workflows for both standalone and integrated development
|
||||
- Asset management guides and troubleshooting documentation
|
||||
- CLI usage examples and best practices
|
||||
|
||||
## 🎯 **Key Features Now Available**
|
||||
|
||||
### CLI Usage
|
||||
```bash
|
||||
# Default behavior - uses testdrive-jsui for edit mode
|
||||
markitect md-render --edit document.md
|
||||
|
||||
# Explicit engine selection
|
||||
markitect md-render --engine testdrive-jsui --edit document.md
|
||||
|
||||
# Standard fallback
|
||||
markitect md-render --engine standard --edit document.md
|
||||
```
|
||||
|
||||
### Output Structure
|
||||
```
|
||||
output/
|
||||
├── document.html # Fully functional HTML
|
||||
└── _markitect/
|
||||
└── plugins/
|
||||
└── testdrive-jsui/
|
||||
├── static/js/ # 12 JavaScript files
|
||||
├── static/css/ # 3 CSS stylesheets
|
||||
└── images/ # 3 icon assets
|
||||
```
|
||||
|
||||
### Development Workflows
|
||||
- **Standalone**: `cd testdrive-jsui && python -m http.server 8080`
|
||||
- **Integrated**: Use CLI with automatic plugin deployment
|
||||
- **Testing**: Comprehensive test suite for all scenarios
|
||||
|
||||
## 🏗️ **Architecture Achievements**
|
||||
|
||||
1. **JavaScript-First Development**: Complete UI development independence
|
||||
2. **Clean Separation**: JSON-only data interface, no Python-JavaScript mixing
|
||||
3. **Asset Pipeline**: Configurable deployment and URL management
|
||||
4. **Plugin Discovery**: Automatic registration and graceful fallbacks
|
||||
5. **GUARDRAILS.md Compliance**: Strict separation of concerns maintained
|
||||
|
||||
## 🧪 **Testing Coverage**
|
||||
|
||||
- ✅ Plugin discovery and registration
|
||||
- ✅ CLI integration with all engine scenarios
|
||||
- ✅ Asset deployment and accessibility
|
||||
- ✅ JavaScript loading order and conflicts
|
||||
- ✅ Browser compatibility and functionality
|
||||
- ✅ Error handling and fallback mechanisms
|
||||
|
||||
## 📊 **Commits Merged**
|
||||
|
||||
11 commits successfully merged to main:
|
||||
|
||||
1. **55c61a7** - feat: implement clean JavaScript-Python separation for edit mode
|
||||
2. **8ef356a** - feat: implement plugin infrastructure for rendering engines
|
||||
3. **8f1cc0f** - feat: complete CLI integration with plugin system
|
||||
4. **409d1a8** - feat: complete asset deployment for plugin engines
|
||||
5. **76b5bb1** - fix: resolve JavaScript const redeclaration and MarkitectMain issues
|
||||
|
||||
## 🌟 **Impact**
|
||||
|
||||
This implementation successfully achieves the original goals:
|
||||
|
||||
- **JavaScript developers** can work independently without Python environment
|
||||
- **Asset management** is handled automatically with proper deployment
|
||||
- **CLI integration** is seamless with intelligent defaults and fallbacks
|
||||
- **Code separation** maintains GUARDRAILS.md compliance
|
||||
- **Edit functionality** is fully restored and enhanced
|
||||
|
||||
## 🚀 **Ready for Use**
|
||||
|
||||
The system is now production-ready:
|
||||
- All JavaScript errors resolved
|
||||
- Assets properly deployed to output directories
|
||||
- CLI defaults to testdrive-jsui for optimal user experience
|
||||
- Comprehensive documentation and testing in place
|
||||
|
||||
---
|
||||
|
||||
*Integration completed successfully on 2025-11-14*
|
||||
*Feature branch `refactoring-attempt-failed-2025-11-12` merged and deleted*
|
||||
206
history/251114-REFACTORING_SESSION_REPORT.md
Normal file
206
history/251114-REFACTORING_SESSION_REPORT.md
Normal file
@@ -0,0 +1,206 @@
|
||||
# Refactoring Session Report: Edit Mode Recovery Attempt
|
||||
|
||||
**Date:** 2025-11-12
|
||||
**Session Goal:** Recover working edit mode functionality from git history
|
||||
**Outcome:** Partial success with valuable lessons learned, but became overly complex
|
||||
|
||||
## 🎯 Achievements
|
||||
|
||||
### 1. **Robustness Principle Implementation**
|
||||
- ✅ Successfully implemented dual-mode error handling (development vs production)
|
||||
- ✅ Added comprehensive safety utilities in `control-base.js`
|
||||
- ✅ Created sophisticated failure detection with clear error messages
|
||||
- ✅ Implemented graceful degradation for missing components
|
||||
|
||||
### 2. **Error Detection System**
|
||||
- ✅ Automatic detection of broken edit mode functionality
|
||||
- ✅ Component availability checking before attempting to load edit mode
|
||||
- ✅ Clear error messages explaining what went wrong and how to fix it
|
||||
- ✅ Dual-mode behavior: fail fast in development, warn in production
|
||||
|
||||
### 3. **Template System Understanding**
|
||||
- ✅ Identified the difference between embedded vs external JavaScript delivery
|
||||
- ✅ Understood that edit modes require embedded JavaScript for immediate availability
|
||||
- ✅ Successfully implemented template variable substitution (`{title}`, `{version}`)
|
||||
- ✅ Fixed initialization flow to ensure components are properly loaded
|
||||
|
||||
### 4. **Git History Recovery**
|
||||
- ✅ Successfully recovered original JavaScript components from git history:
|
||||
- `js/core/section-manager.js`
|
||||
- `js/components/debug-panel.js`
|
||||
- `js/components/document-controls.js`
|
||||
- `js/components/dom-renderer.js`
|
||||
- ✅ Restored `_get_clean_editor_scripts()` functionality
|
||||
- ✅ Implemented proper component loading and concatenation
|
||||
|
||||
## ❌ Problems Encountered
|
||||
|
||||
### 1. **GUARDRAILS.md Violation**
|
||||
- **Issue:** We ended up with JavaScript code embedded in Python strings again
|
||||
- **Root Cause:** The template generation in `_generate_html_template()` contains JavaScript
|
||||
- **Impact:** Violated the core principle of keeping JS separate from Python code
|
||||
- **Status:** Not resolved - would require architectural redesign
|
||||
|
||||
### 2. **Component Integration Issues**
|
||||
- **Issue:** Old retired edit controls showing instead of new abstract controls
|
||||
- **Root Cause:** Mixed old and new component systems without proper migration
|
||||
- **Impact:** Confusing UI with non-functional controls
|
||||
- **Status:** Not resolved - needs careful component cleanup
|
||||
|
||||
### 3. **Content Rendering Problems**
|
||||
- **Issue:** No content visible despite successful component initialization
|
||||
- **Root Cause:** Modular architecture not properly connected to content rendering
|
||||
- **Impact:** Interactive editor loads but has no content to edit
|
||||
- **Status:** Not resolved - requires debugging the content flow
|
||||
|
||||
### 4. **Complexity Accumulation**
|
||||
- **Issue:** Session became overly complex with multiple parallel concerns
|
||||
- **Root Cause:** Trying to solve too many problems simultaneously
|
||||
- **Impact:** Lost track of original goal and created technical debt
|
||||
- **Status:** Requires reset and focused approach
|
||||
|
||||
## 🔍 Key Technical Insights
|
||||
|
||||
### 1. **Template Architecture**
|
||||
```python
|
||||
# DISCOVERED: Two different template approaches needed
|
||||
if edit_mode or insert_mode:
|
||||
# Embedded JavaScript for immediate availability
|
||||
template_content = f"""...<script>{editor_scripts}</script>..."""
|
||||
else:
|
||||
# External JavaScript files for lazy loading
|
||||
template_content = load_external_template()
|
||||
```
|
||||
|
||||
### 2. **Component Loading Strategy**
|
||||
```python
|
||||
# WORKING: Component concatenation approach
|
||||
def _get_clean_editor_scripts(self) -> str:
|
||||
components = [
|
||||
'js/core/section-manager.js',
|
||||
'js/components/debug-panel.js',
|
||||
'js/components/document-controls.js',
|
||||
'js/components/dom-renderer.js'
|
||||
]
|
||||
# Load and concatenate components
|
||||
```
|
||||
|
||||
### 3. **Initialization Flow Discovery**
|
||||
```javascript
|
||||
// CRITICAL: Editor initialization must happen before component detection
|
||||
// Initialize edit/insert capabilities first (always needed)
|
||||
if (MARKITECT_EDIT_MODE || MARKITECT_INSERT_MODE) {
|
||||
initializeCleanEditor(); // Must happen first
|
||||
}
|
||||
// Then check for modular components
|
||||
if (typeof SectionManager !== 'undefined') {
|
||||
// Skip fallback rendering
|
||||
}
|
||||
```
|
||||
|
||||
## 📋 Lessons Learned
|
||||
|
||||
### 1. **Focus is Critical**
|
||||
- Trying to solve multiple problems simultaneously leads to confusion
|
||||
- Should have focused solely on edit mode recovery
|
||||
- Error detection system, while valuable, was a distraction from core goal
|
||||
|
||||
### 2. **GUARDRAILS.md Must Be Respected**
|
||||
- The rule against JavaScript in Python strings exists for good reasons
|
||||
- Template generation approach violates this principle
|
||||
- Need architectural solution that keeps JS in separate files
|
||||
|
||||
### 3. **Component Migration Requires Planning**
|
||||
- Cannot mix old and new component systems without explicit migration plan
|
||||
- Need to identify and remove deprecated components first
|
||||
- Should have focused on one component system at a time
|
||||
|
||||
### 4. **Testing Must Be Incremental**
|
||||
- Should test each change individually before proceeding
|
||||
- Complex changes make it difficult to identify root causes
|
||||
- Browser testing should happen after each major change
|
||||
|
||||
## 🚀 Recommendations for Next Attempt
|
||||
|
||||
### 1. **Start with Simple Goal**
|
||||
- Focus ONLY on making existing edit mode work
|
||||
- Don't attempt to improve or refactor simultaneously
|
||||
- Get basic functionality working first
|
||||
|
||||
### 2. **Respect Architecture Constraints**
|
||||
- Keep JavaScript in separate `.js` files (honor GUARDRAILS.md)
|
||||
- Load components via HTTP requests, not embedded strings
|
||||
- Use the external template approach consistently
|
||||
|
||||
### 3. **Incremental Approach**
|
||||
1. First: Get content rendering working in browser
|
||||
2. Second: Add basic edit controls
|
||||
3. Third: Test each control individually
|
||||
4. Fourth: Add advanced features
|
||||
|
||||
### 4. **Clean Component System**
|
||||
- Remove old deprecated controls before adding new ones
|
||||
- Use only the abstract control system consistently
|
||||
- Document which components are active vs deprecated
|
||||
|
||||
## 💡 Valuable Code Patterns Discovered
|
||||
|
||||
### 1. **Safe Operation Wrapper**
|
||||
```javascript
|
||||
safeOperation: function(operation, fallback = null, context = 'Unknown') {
|
||||
try {
|
||||
return operation();
|
||||
} catch (error) {
|
||||
if (MARKITECT_STRICT_MODE) {
|
||||
throw error; // Fail fast in development
|
||||
}
|
||||
return typeof fallback === 'function' ? fallback() : fallback;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. **Component Availability Check**
|
||||
```python
|
||||
def check_edit_mode_components(self):
|
||||
components_to_check = [
|
||||
'js/core/section-manager.js',
|
||||
'js/components/debug-panel.js',
|
||||
'js/components/document-controls.js',
|
||||
'js/components/dom-renderer.js'
|
||||
]
|
||||
missing = [c for c in components_to_check if not (base_path / c).exists()]
|
||||
return len(missing) == 0, missing
|
||||
```
|
||||
|
||||
### 3. **Dual-Mode Error Handling**
|
||||
```python
|
||||
if self._should_fail_fast():
|
||||
raise EditModeError("Edit mode components missing")
|
||||
else:
|
||||
print("⚠️ WARNING: Edit mode requested but components missing")
|
||||
```
|
||||
|
||||
## 🎯 Success Metrics for Next Attempt
|
||||
|
||||
1. **Functional:** Click section → edit textarea appears → save works
|
||||
2. **Visual:** Content visible, proper title, working controls
|
||||
3. **Architecture:** No JavaScript in Python strings
|
||||
4. **Clean:** Only new control system components active
|
||||
5. **Simple:** Minimal changes to get core functionality working
|
||||
|
||||
## 📊 Final Assessment
|
||||
|
||||
**What Worked:**
|
||||
- Error detection and reporting
|
||||
- Component recovery from git history
|
||||
- Template variable substitution
|
||||
- Initialization flow understanding
|
||||
|
||||
**What Didn't Work:**
|
||||
- Overly complex approach
|
||||
- GUARDRAILS.md violations
|
||||
- Component system mixing
|
||||
- Content rendering integration
|
||||
|
||||
**Recommendation:**
|
||||
Reset to a working commit and take a focused, incremental approach that respects the architectural constraints while achieving the core goal of functional edit mode.
|
||||
4130
history/GUARDRAILS-edit-mode-dbde13e-2025-11-11-00-29-34.html
Normal file
4130
history/GUARDRAILS-edit-mode-dbde13e-2025-11-11-00-29-34.html
Normal file
File diff suppressed because it is too large
Load Diff
3832
history/GUARDRAILS-fully-recovered-2025-11-12-01-03-25.html
Normal file
3832
history/GUARDRAILS-fully-recovered-2025-11-12-01-03-25.html
Normal file
File diff suppressed because it is too large
Load Diff
743
history/GUARDRAILS-static-dbde13e-2025-11-11-00-29-34.html
Normal file
743
history/GUARDRAILS-static-dbde13e-2025-11-11-00-29-34.html
Normal file
@@ -0,0 +1,743 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Development Guardrails</title>
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
line-height: 1.6;
|
||||
color: #333333;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
#markdown-content {
|
||||
min-height: 200px;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: #333333;
|
||||
|
||||
}
|
||||
pre {
|
||||
background-color: #f6f8fa;
|
||||
color: #333333;
|
||||
padding: 1rem;
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #d0d7de;
|
||||
}
|
||||
code {
|
||||
background-color: #f6f8fa;
|
||||
color: #333333;
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 3px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
pre code {
|
||||
background: none;
|
||||
padding: 0;
|
||||
}
|
||||
blockquote {
|
||||
border-left: 4px solid #dfe2e5;
|
||||
margin: 0;
|
||||
padding-left: 1rem;
|
||||
color: #6a737d;
|
||||
}
|
||||
table {
|
||||
font-size: 0.85em;
|
||||
border-collapse: collapse;
|
||||
margin: 1rem 0;
|
||||
width: 100%;
|
||||
border: 1px solid #d0d7de;
|
||||
}
|
||||
th, td {
|
||||
font-size: inherit;
|
||||
border: 1px solid #d0d7de;
|
||||
padding: 0.5rem;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f6f8fa;
|
||||
font-weight: 600;
|
||||
}
|
||||
img {
|
||||
max-width: 12cm;
|
||||
max-height: 20cm;
|
||||
height: auto;
|
||||
display: block;
|
||||
margin: 1rem auto;
|
||||
}</style>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"
|
||||
onload="window.markitectMarkedLoaded = true"
|
||||
onerror="window.markitectMarkedError = true"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="markdown-content"></div>
|
||||
|
||||
<script>
|
||||
const markdownContent = "# Development Guardrails\n\n## JavaScript Code Principles\n\n### 1. No Inline JavaScript in Python\n**NEVER write JavaScript code directly from Python code**\n\n\u274c **Wrong:**\n```python\nscript = f\"\"\"\nfunction myFunction() {{\n console.log(\"Hello {name}\");\n}}\n\"\"\"\n```\n\n\u2705 **Correct:**\n```python\n# Load from external files only\ncomponents = [\n 'js/core/section-manager.js',\n 'js/components/debug-panel.js',\n 'js/components/document-controls.js'\n]\n```\n\n### 2. Why This Rule Exists\n- **Quoting Problems**: String escaping in Python corrupts JavaScript\n- **Syntax Errors**: Template literals and complex JS break when embedded\n- **Maintainability**: JS code should be in .js files for proper tooling\n- **Architecture**: Follows the established modular component system\n\n### 3. Proper Approach\n1. Create separate `.js` files in `markitect/static/js/components/`\n2. Load them via `_get_clean_editor_scripts()`\n3. Wire up components in the initialization script only\n\n## Testing and Validation\n\n### 1. Always Validate Generated HTML\n- Check that HTML files actually render content\n- Validate JavaScript syntax before deployment\n- Test both viewing and editing modes\n\n### 2. Detect JavaScript Errors Programmatically\n- Run syntax validation on generated JS\n- Check for common error patterns\n- Fail fast when JS is malformed\n\n### 3. Manual Testing Backup\n- If automated checks pass but functionality fails\n- Open generated HTML in browser\n- Check console for runtime errors\n- Report specific error messages\n\n## Architecture Principles\n\n### 1. Separation of Concerns\n- Python: File generation, template management\n- JavaScript: UI components, interaction logic\n- HTML: Structure and content only\n\n### 2. Modular Component System\n- Each UI component in separate file\n- Lazy loading where appropriate\n- Clear dependency management\n\n### 3. Error Handling\n- Graceful degradation when components fail\n- Clear error messages for debugging\n- Fallback modes when possible\n\n## Breaking These Rules\n\nIf you find yourself writing JavaScript in Python strings:\n1. **STOP** - Step back and reconsider\n2. Create a proper component file instead\n3. Use the existing component loading system\n4. Add validation to catch the issue early\n\nThese guardrails exist because we've seen the problems when they're violated.";
|
||||
const markdownContentWithDogtag = "# Development Guardrails\n\n## JavaScript Code Principles\n\n### 1. No Inline JavaScript in Python\n**NEVER write JavaScript code directly from Python code**\n\n\u274c **Wrong:**\n```python\nscript = f\"\"\"\nfunction myFunction() {{\n console.log(\"Hello {name}\");\n}}\n\"\"\"\n```\n\n\u2705 **Correct:**\n```python\n# Load from external files only\ncomponents = [\n 'js/core/section-manager.js',\n 'js/components/debug-panel.js',\n 'js/components/document-controls.js'\n]\n```\n\n### 2. Why This Rule Exists\n- **Quoting Problems**: String escaping in Python corrupts JavaScript\n- **Syntax Errors**: Template literals and complex JS break when embedded\n- **Maintainability**: JS code should be in .js files for proper tooling\n- **Architecture**: Follows the established modular component system\n\n### 3. Proper Approach\n1. Create separate `.js` files in `markitect/static/js/components/`\n2. Load them via `_get_clean_editor_scripts()`\n3. Wire up components in the initialization script only\n\n## Testing and Validation\n\n### 1. Always Validate Generated HTML\n- Check that HTML files actually render content\n- Validate JavaScript syntax before deployment\n- Test both viewing and editing modes\n\n### 2. Detect JavaScript Errors Programmatically\n- Run syntax validation on generated JS\n- Check for common error patterns\n- Fail fast when JS is malformed\n\n### 3. Manual Testing Backup\n- If automated checks pass but functionality fails\n- Open generated HTML in browser\n- Check console for runtime errors\n- Report specific error messages\n\n## Architecture Principles\n\n### 1. Separation of Concerns\n- Python: File generation, template management\n- JavaScript: UI components, interaction logic\n- HTML: Structure and content only\n\n### 2. Modular Component System\n- Each UI component in separate file\n- Lazy loading where appropriate\n- Clear dependency management\n\n### 3. Error Handling\n- Graceful degradation when components fail\n- Clear error messages for debugging\n- Fallback modes when possible\n\n## Breaking These Rules\n\nIf you find yourself writing JavaScript in Python strings:\n1. **STOP** - Step back and reconsider\n2. Create a proper component file instead\n3. Use the existing component loading system\n4. Add validation to catch the issue early\n\nThese guardrails exist because we've seen the problems when they're violated.\n\n---\n*-- html from markdown by <a href=\"https://coulomb.social/open/MarkiTect\" target=\"_blank\">MarkiTect</a> on 2025-11-12 00:38:01 by <a href=\"https://coulomb.social/open/worsch\" target=\"_blank\">worsch</a>*";
|
||||
const dogtagContent = "\n\n---\n*-- html from markdown by <a href=\"https://coulomb.social/open/MarkiTect\" target=\"_blank\">MarkiTect</a> on 2025-11-12 00:38:01 by <a href=\"https://coulomb.social/open/worsch\" target=\"_blank\">worsch</a>*";
|
||||
window.markitectBase64References = {};
|
||||
|
||||
|
||||
|
||||
|
||||
// Always render content first (graceful degradation)
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log("Rendering content...");
|
||||
|
||||
// Check if modular components are being used
|
||||
if (typeof SectionManager !== 'undefined') {
|
||||
console.log("✓ Modular components detected - skipping direct content rendering");
|
||||
console.log("✓ Content will be rendered by modular architecture");
|
||||
return;
|
||||
}
|
||||
|
||||
const contentDiv = document.getElementById('markdown-content');
|
||||
|
||||
// Step 1: Ensure content is always displayed (fallback for non-modular mode)
|
||||
if (contentDiv) {
|
||||
if (typeof marked !== 'undefined') {
|
||||
try {
|
||||
const html = marked.parse(markdownContentWithDogtag);
|
||||
// Add target="_blank" to all links
|
||||
const htmlWithTargetBlank = html.replace(/<a href="([^"]*)"([^>]*)>/g, '<a href="$1" target="_blank"$2>');
|
||||
contentDiv.innerHTML = htmlWithTargetBlank;
|
||||
console.log("✓ Content rendered successfully");
|
||||
console.log('✓ Markdown rendered successfully');
|
||||
} catch (error) {
|
||||
contentDiv.innerHTML = '<p>Error rendering markdown: ' + error.message + '</p>';
|
||||
console.error("Content rendered with errors");
|
||||
console.error("Markdown parsing failed:", error.message);
|
||||
}
|
||||
} else {
|
||||
// Fallback: display raw markdown with basic formatting
|
||||
const fallbackHtml = markdownContent
|
||||
.replace(/^# (.*$)/gim, '<h1>$1</h1>')
|
||||
.replace(/^## (.*$)/gim, '<h2>$1</h2>')
|
||||
.replace(/^### (.*$)/gim, '<h3>$1</h3>')
|
||||
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
||||
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
||||
.replace(/^- (.*$)/gim, '<li>$1</li>')
|
||||
.replace(/\n\n/g, '<br><br>')
|
||||
.replace(/\n/g, '<br>');
|
||||
contentDiv.innerHTML = '<div style="white-space: pre-wrap;">' + fallbackHtml + '</div>';
|
||||
console.warn("Content rendered with fallback parser");
|
||||
console.warn("CDN library failed to load - using basic fallback rendering");
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Initialize edit/insert capabilities if enabled
|
||||
if ((typeof MARKITECT_EDIT_MODE !== 'undefined' && MARKITECT_EDIT_MODE) ||
|
||||
(typeof MARKITECT_INSERT_MODE !== 'undefined' && MARKITECT_INSERT_MODE)) {
|
||||
const mode = (typeof MARKITECT_INSERT_MODE !== 'undefined' && MARKITECT_INSERT_MODE) ? 'insert' : 'edit';
|
||||
console.log(`Initializing clean ${mode} capabilities...`);
|
||||
try {
|
||||
console.log("Creating clean editor instance...");
|
||||
initializeCleanEditor();
|
||||
if (mode === 'insert') {
|
||||
console.log("✓ Clean insert mode active - click any section to edit (headings 1-3 protected)");
|
||||
} else {
|
||||
console.log("✓ Clean edit mode active - click any section to edit");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Clean ${mode} mode failed to initialize:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Initialize document scroll indicators (always available)
|
||||
try {
|
||||
initializeScrollIndicators();
|
||||
} catch (error) {
|
||||
console.error("Scroll indicators failed to initialize:", error);
|
||||
}
|
||||
|
||||
// Step 4: Define abstract Control class for UI controls
|
||||
const Control = {
|
||||
// Abstract control properties
|
||||
element: null,
|
||||
isExpanded: false,
|
||||
isHeaderOnly: false, // New state for header-only mode
|
||||
isDragging: false,
|
||||
isResizing: false, // New state for resizing mode
|
||||
dragOffset: { x: 0, y: 0 },
|
||||
resizeStartSize: { width: 280, height: 'auto' },
|
||||
originalPosition: { top: '80px', left: '20px' },
|
||||
defaultSize: { width: 280, minWidth: 200, minHeight: 150 },
|
||||
|
||||
// Configuration properties (to be overridden by subclasses)
|
||||
config: {
|
||||
icon: '?',
|
||||
title: 'Control',
|
||||
className: 'control',
|
||||
defaultContent: 'Template only',
|
||||
ariaLabel: 'Control',
|
||||
position: 'w' // Default compass position: west (middle-left)
|
||||
},
|
||||
|
||||
// Compass positioning system (top-aligned for proper expansion)
|
||||
compassPositions: {
|
||||
// North positions (top)
|
||||
'n': { top: '20px', left: '50%', transform: 'translateX(-50%)' },
|
||||
'nne': { top: '20px', left: '65%', transform: 'translateX(-50%)' },
|
||||
'ne': { top: '20px', right: '20px' },
|
||||
'ene': { top: '80px', right: '20px' }, // Top-aligned instead of center
|
||||
|
||||
// East positions (right)
|
||||
'e': { top: '50vh', right: '20px', transform: 'translateY(-20px)' }, // Anchor at icon level
|
||||
'ese': { top: 'calc(65vh - 20px)', right: '20px' }, // Top-aligned
|
||||
'se': { bottom: '20px', right: '20px' },
|
||||
'sse': { bottom: '20px', right: '35%', transform: 'translateX(50%)' },
|
||||
|
||||
// South positions (bottom)
|
||||
's': { bottom: '20px', left: '50%', transform: 'translateX(-50%)' },
|
||||
'ssw': { bottom: '20px', left: '35%', transform: 'translateX(-50%)' },
|
||||
'sw': { bottom: '20px', left: '20px' },
|
||||
'wsw': { bottom: '80px', left: '20px' }, // Top-aligned instead of center
|
||||
|
||||
// West positions (left) - top-aligned for proper expansion
|
||||
'w': { top: '50vh', left: '20px', transform: 'translateY(-20px)' }, // Anchor at icon level
|
||||
'wnw': { top: '80px', left: '20px' }, // Top-aligned instead of center
|
||||
'nw': { top: '20px', left: '20px' },
|
||||
'nnw': { top: '20px', left: '35%', transform: 'translateX(-50%)' }
|
||||
},
|
||||
|
||||
// Get expansion direction based on compass position
|
||||
getExpansionDirection: function() {
|
||||
const pos = this.config.position;
|
||||
const rightBorderPositions = ['ne', 'ene', 'e', 'ese', 'se'];
|
||||
const bottomBorderPositions = ['sw', 'ssw', 's', 'sse', 'se'];
|
||||
|
||||
return {
|
||||
header: rightBorderPositions.includes(pos) ? 'left' : 'right',
|
||||
body: bottomBorderPositions.includes(pos) ? 'up' : 'down'
|
||||
};
|
||||
},
|
||||
|
||||
// Calculate position styles based on compass direction
|
||||
getPositionStyles: function() {
|
||||
const compassPos = this.compassPositions[this.config.position] || this.compassPositions['w'];
|
||||
return {
|
||||
position: 'fixed',
|
||||
top: compassPos.top || 'auto',
|
||||
right: compassPos.right || 'auto',
|
||||
bottom: compassPos.bottom || 'auto',
|
||||
left: compassPos.left || 'auto',
|
||||
transform: compassPos.transform || 'none',
|
||||
zIndex: 1000
|
||||
};
|
||||
},
|
||||
|
||||
// Abstract methods (to be implemented by subclasses)
|
||||
buildContent: function() {
|
||||
const content = this.element.querySelector('.control-content');
|
||||
content.innerHTML = `<p style="padding: 1rem; color: #666;">${this.config.defaultContent}</p>`;
|
||||
},
|
||||
|
||||
// Concrete methods (shared by all controls)
|
||||
createControl: function() {
|
||||
console.log(`🎛️ Creating ${this.config.title} control...`);
|
||||
|
||||
this.element = document.createElement('div');
|
||||
this.element.className = this.config.className;
|
||||
this.element.innerHTML = `
|
||||
<button class="control-toggle" aria-label="${this.config.ariaLabel}">${this.config.icon}</button>
|
||||
<div class="control-panel" style="display: none;">
|
||||
<div class="control-header">
|
||||
<span class="control-icon">${this.config.icon}</span>
|
||||
<span class="control-title">${this.config.title}</span>
|
||||
<button class="control-close">✕</button>
|
||||
</div>
|
||||
<div class="control-content">Loading...</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Position using compass direction
|
||||
const positionStyles = this.getPositionStyles();
|
||||
this.element.style.cssText = `
|
||||
position: ${positionStyles.position};
|
||||
top: ${positionStyles.top};
|
||||
right: ${positionStyles.right};
|
||||
bottom: ${positionStyles.bottom};
|
||||
left: ${positionStyles.left};
|
||||
transform: ${positionStyles.transform};
|
||||
z-index: ${positionStyles.zIndex};
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border: 1px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
backdrop-filter: blur(8px);
|
||||
width: 40px;
|
||||
transition: all 0.3s ease;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
`;
|
||||
|
||||
// Store original position for reset
|
||||
this.originalPosition = {
|
||||
top: positionStyles.top,
|
||||
right: positionStyles.right,
|
||||
bottom: positionStyles.bottom,
|
||||
left: positionStyles.left,
|
||||
transform: positionStyles.transform
|
||||
};
|
||||
|
||||
// Style toggle button
|
||||
const toggleBtn = this.element.querySelector('.control-toggle');
|
||||
toggleBtn.style.cssText = `
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
transition: color 0.2s ease;
|
||||
`;
|
||||
|
||||
// Handle click to build content on-demand
|
||||
toggleBtn.addEventListener('click', () => {
|
||||
if (this.isExpanded) {
|
||||
this.collapse();
|
||||
} else {
|
||||
console.log(`🎛️ ${this.config.title} toggle clicked - building content...`);
|
||||
this.buildContent();
|
||||
}
|
||||
});
|
||||
|
||||
// Close button handler
|
||||
const closeBtn = this.element.querySelector('.control-close');
|
||||
closeBtn.addEventListener('click', () => {
|
||||
this.collapse();
|
||||
});
|
||||
|
||||
// Responsive behavior
|
||||
window.addEventListener('resize', () => {
|
||||
if (window.innerWidth <= 768) {
|
||||
this.element.style.display = 'none';
|
||||
} else {
|
||||
this.element.style.display = '';
|
||||
}
|
||||
});
|
||||
|
||||
document.body.appendChild(this.element);
|
||||
|
||||
// Hide on mobile
|
||||
if (window.innerWidth <= 768) {
|
||||
this.element.style.display = 'none';
|
||||
}
|
||||
|
||||
console.log(`🎛️ ${this.config.title} control created`);
|
||||
},
|
||||
|
||||
styleHeader: function() {
|
||||
const header = this.element.querySelector('.control-header');
|
||||
|
||||
// Style the header to show icon, title, and close button in one line
|
||||
// Match the height of the collapsed icon state (40px)
|
||||
header.style.cssText = `
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 40px;
|
||||
padding: 0 1rem;
|
||||
border-bottom: 1px solid #eee;
|
||||
margin-bottom: 0;
|
||||
`;
|
||||
|
||||
const icon = header.querySelector('.control-icon');
|
||||
if (icon) {
|
||||
icon.style.cssText = `
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
margin-right: 0.5rem;
|
||||
cursor: grab;
|
||||
user-select: none;
|
||||
`;
|
||||
|
||||
// Make icon draggable
|
||||
this.setupDragHandlers(icon);
|
||||
}
|
||||
|
||||
const title = header.querySelector('.control-title');
|
||||
if (title) {
|
||||
title.style.cssText = `
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
flex-grow: 1;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
`;
|
||||
|
||||
// Add click handler to toggle header-only mode
|
||||
title.addEventListener('click', () => {
|
||||
this.toggleHeaderOnly();
|
||||
});
|
||||
}
|
||||
|
||||
const closeBtn = header.querySelector('.control-close');
|
||||
if (closeBtn) {
|
||||
closeBtn.style.cssText = `
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
color: #6c757d;
|
||||
padding: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: color 0.2s ease;
|
||||
`;
|
||||
}
|
||||
},
|
||||
|
||||
styleContent: function() {
|
||||
const content = this.element.querySelector('.control-content');
|
||||
const expansion = this.getExpansionDirection();
|
||||
|
||||
// Style the content area based on expansion direction
|
||||
let contentStyles = `
|
||||
padding: 0.5rem;
|
||||
overflow-y: auto;
|
||||
`;
|
||||
|
||||
if (expansion.body === 'up') {
|
||||
// Body expands upward (for bottom border positions)
|
||||
contentStyles += `
|
||||
max-height: calc(80vh - 40px);
|
||||
`;
|
||||
content.parentElement.style.flexDirection = 'column-reverse';
|
||||
} else {
|
||||
// Body expands downward (default)
|
||||
contentStyles += `
|
||||
max-height: calc(80vh - 40px);
|
||||
`;
|
||||
content.parentElement.style.flexDirection = 'column';
|
||||
}
|
||||
|
||||
content.style.cssText = contentStyles;
|
||||
},
|
||||
|
||||
expand: function() {
|
||||
this.isExpanded = true;
|
||||
const panel = this.element.querySelector('.control-panel');
|
||||
const toggleBtn = this.element.querySelector('.control-toggle');
|
||||
|
||||
// Get expansion direction based on compass position
|
||||
const expansion = this.getExpansionDirection();
|
||||
|
||||
// Apply expansion styling based on direction
|
||||
if (expansion.header === 'left') {
|
||||
// Header expands to the left (for right border positions)
|
||||
this.element.style.width = '280px';
|
||||
this.element.style.transformOrigin = 'top right';
|
||||
} else {
|
||||
// Header expands to the right (default)
|
||||
this.element.style.width = '280px';
|
||||
this.element.style.transformOrigin = 'top left';
|
||||
}
|
||||
|
||||
panel.style.display = 'block';
|
||||
toggleBtn.style.display = 'none';
|
||||
|
||||
this.styleHeader();
|
||||
this.styleContent();
|
||||
this.addResizeHandle();
|
||||
},
|
||||
|
||||
collapse: function() {
|
||||
this.isExpanded = false;
|
||||
this.isHeaderOnly = false; // Reset header-only state
|
||||
const panel = this.element.querySelector('.control-panel');
|
||||
const toggleBtn = this.element.querySelector('.control-toggle');
|
||||
panel.style.display = 'none';
|
||||
|
||||
// Reset size to default
|
||||
this.element.style.width = '40px';
|
||||
this.element.style.height = 'auto';
|
||||
|
||||
// Remove resize handle
|
||||
this.removeResizeHandle();
|
||||
|
||||
toggleBtn.style.display = 'block';
|
||||
|
||||
// Reset position to original compass location
|
||||
this.element.style.top = this.originalPosition.top;
|
||||
this.element.style.right = this.originalPosition.right;
|
||||
this.element.style.bottom = this.originalPosition.bottom;
|
||||
this.element.style.left = this.originalPosition.left;
|
||||
this.element.style.transform = this.originalPosition.transform;
|
||||
},
|
||||
|
||||
toggleHeaderOnly: function() {
|
||||
if (!this.isExpanded) {
|
||||
// If collapsed, first expand normally
|
||||
this.buildContent();
|
||||
return;
|
||||
}
|
||||
|
||||
const content = this.element.querySelector('.control-content');
|
||||
|
||||
if (this.isHeaderOnly) {
|
||||
// Show content area (go to full expanded mode)
|
||||
this.isHeaderOnly = false;
|
||||
content.style.display = 'block';
|
||||
console.log(`🎛️ ${this.config.title} expanded to full view`);
|
||||
} else {
|
||||
// Hide content area (go to header-only mode)
|
||||
this.isHeaderOnly = true;
|
||||
content.style.display = 'none';
|
||||
console.log(`🎛️ ${this.config.title} collapsed to header only`);
|
||||
}
|
||||
},
|
||||
|
||||
setupDragHandlers: function(dragElement) {
|
||||
dragElement.addEventListener('mousedown', (e) => {
|
||||
this.isDragging = true;
|
||||
const rect = this.element.getBoundingClientRect();
|
||||
const iconRect = dragElement.getBoundingClientRect();
|
||||
|
||||
// Calculate offset relative to the icon position, not the element
|
||||
this.dragOffset.x = e.clientX - rect.left;
|
||||
this.dragOffset.y = iconRect.top - rect.top + (iconRect.height / 2); // Keep mouse at icon center
|
||||
|
||||
dragElement.style.cursor = 'grabbing';
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
document.addEventListener('mousemove', (e) => {
|
||||
if (!this.isDragging || !this.isExpanded) return;
|
||||
|
||||
const newX = e.clientX - this.dragOffset.x;
|
||||
const newY = e.clientY - this.dragOffset.y;
|
||||
|
||||
// Keep within viewport bounds
|
||||
const maxX = window.innerWidth - this.element.offsetWidth;
|
||||
const maxY = window.innerHeight - this.element.offsetHeight;
|
||||
|
||||
const boundedX = Math.max(0, Math.min(newX, maxX));
|
||||
const boundedY = Math.max(0, Math.min(newY, maxY));
|
||||
|
||||
this.element.style.left = boundedX + 'px';
|
||||
this.element.style.top = boundedY + 'px';
|
||||
});
|
||||
|
||||
document.addEventListener('mouseup', () => {
|
||||
if (this.isDragging) {
|
||||
this.isDragging = false;
|
||||
dragElement.style.cursor = 'grab';
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Add resize handle to expanded control
|
||||
addResizeHandle: function() {
|
||||
// Remove existing resize handle if any
|
||||
this.removeResizeHandle();
|
||||
|
||||
const resizeHandle = document.createElement('div');
|
||||
resizeHandle.className = 'control-resize-handle';
|
||||
// Create small circle for resize handle
|
||||
resizeHandle.innerHTML = '';
|
||||
resizeHandle.style.cssText = `
|
||||
position: absolute;
|
||||
bottom: 2px;
|
||||
right: 2px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
cursor: nw-resize;
|
||||
display: none;
|
||||
user-select: none;
|
||||
z-index: 1001;
|
||||
background: #6c757d;
|
||||
border-radius: 50%;
|
||||
opacity: 0.6;
|
||||
transition: opacity 0.2s ease;
|
||||
`;
|
||||
|
||||
this.element.appendChild(resizeHandle);
|
||||
this.setupResizeHandlers(resizeHandle);
|
||||
this.setupHoverBehavior();
|
||||
},
|
||||
|
||||
// Setup hover behavior for resize handle and close button
|
||||
setupHoverBehavior: function() {
|
||||
const resizeHandle = this.element.querySelector('.control-resize-handle');
|
||||
const closeBtn = this.element.querySelector('.control-close');
|
||||
|
||||
if (resizeHandle && closeBtn) {
|
||||
// Show/hide on control hover
|
||||
this.element.addEventListener('mouseenter', () => {
|
||||
resizeHandle.style.display = 'flex';
|
||||
closeBtn.style.display = 'block';
|
||||
});
|
||||
|
||||
this.element.addEventListener('mouseleave', () => {
|
||||
resizeHandle.style.display = 'none';
|
||||
closeBtn.style.display = 'none';
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Remove resize handle
|
||||
removeResizeHandle: function() {
|
||||
const existingHandle = this.element.querySelector('.control-resize-handle');
|
||||
if (existingHandle) {
|
||||
existingHandle.remove();
|
||||
}
|
||||
},
|
||||
|
||||
// Set up resize event handlers
|
||||
setupResizeHandlers: function(resizeHandle) {
|
||||
resizeHandle.addEventListener('mousedown', (e) => {
|
||||
this.isResizing = true;
|
||||
const rect = this.element.getBoundingClientRect();
|
||||
this.resizeStartSize = {
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
startX: e.clientX,
|
||||
startY: e.clientY
|
||||
};
|
||||
|
||||
resizeHandle.style.cursor = 'nw-resize';
|
||||
resizeHandle.style.color = '#28a745';
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation(); // Prevent triggering drag
|
||||
});
|
||||
|
||||
document.addEventListener('mousemove', (e) => {
|
||||
if (!this.isResizing || !this.isExpanded) return;
|
||||
|
||||
const deltaX = e.clientX - this.resizeStartSize.startX;
|
||||
const deltaY = e.clientY - this.resizeStartSize.startY;
|
||||
|
||||
const newWidth = Math.max(this.defaultSize.minWidth, this.resizeStartSize.width + deltaX);
|
||||
const newHeight = Math.max(this.defaultSize.minHeight, this.resizeStartSize.height + deltaY);
|
||||
|
||||
// Check viewport bounds
|
||||
const maxWidth = window.innerWidth - this.element.offsetLeft;
|
||||
const maxHeight = window.innerHeight - this.element.offsetTop;
|
||||
|
||||
const boundedWidth = Math.min(newWidth, maxWidth - 20);
|
||||
const boundedHeight = Math.min(newHeight, maxHeight - 20);
|
||||
|
||||
this.element.style.width = boundedWidth + 'px';
|
||||
this.element.style.height = boundedHeight + 'px';
|
||||
|
||||
// Ensure content areas resize properly
|
||||
this.updateContentSize();
|
||||
});
|
||||
|
||||
document.addEventListener('mouseup', () => {
|
||||
if (this.isResizing) {
|
||||
this.isResizing = false;
|
||||
resizeHandle.style.cursor = 'nw-resize';
|
||||
resizeHandle.style.color = '#6c757d';
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Update content area sizes during resize
|
||||
updateContentSize: function() {
|
||||
const content = this.element.querySelector('.control-content');
|
||||
if (content) {
|
||||
// Adjust content height to fit the resized control
|
||||
const headerHeight = 40; // Header is 40px
|
||||
const padding = 16; // Account for padding
|
||||
const controlHeight = this.element.offsetHeight;
|
||||
const availableHeight = controlHeight - headerHeight - padding;
|
||||
|
||||
content.style.maxHeight = Math.max(100, availableHeight) + 'px';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Step 5: Initialize ContentsControl (new implementation based on Control class)
|
||||
try {
|
||||
const contentsControl = Object.create(Control);
|
||||
|
||||
// Configure for contents navigation
|
||||
contentsControl.config = {
|
||||
icon: '☰',
|
||||
title: 'Contents',
|
||||
className: 'contents-control',
|
||||
defaultContent: 'No headings found',
|
||||
ariaLabel: 'Document Navigation',
|
||||
position: 'wnw' // West-north-west positioning
|
||||
};
|
||||
|
||||
// Override buildContent method for navigation functionality
|
||||
contentsControl.buildContent = function() {
|
||||
const content = this.element.querySelector('.control-content');
|
||||
|
||||
// Build navigation content from current DOM
|
||||
const allHeadings = document.querySelectorAll('h1, h2, h3');
|
||||
// Filter out headings that contain "Contents" or similar navigation-related text
|
||||
const headings = Array.from(allHeadings).filter(heading => {
|
||||
const text = heading.textContent.trim().toLowerCase();
|
||||
return !text.includes('contents') && !text.includes('table of contents') && !text.includes('navigation');
|
||||
});
|
||||
console.log("📋 Found headings for navigation:", headings.length);
|
||||
|
||||
if (headings.length === 0) {
|
||||
content.innerHTML = '<p style="padding: 1rem; color: #666;">No headings found</p>';
|
||||
} else {
|
||||
let navHtml = '';
|
||||
headings.forEach((heading, index) => {
|
||||
if (!heading.id) {
|
||||
heading.id = `heading-${index + 1}`;
|
||||
}
|
||||
const level = parseInt(heading.tagName.substring(1));
|
||||
const indent = (level - 1) * 1;
|
||||
navHtml += `
|
||||
<a href="#${heading.id}"
|
||||
style="display: block; padding: 0.5rem; margin-left: ${indent}rem;
|
||||
text-decoration: none; color: #333; font-size: 0.9rem;
|
||||
border-radius: 4px; cursor: pointer;"
|
||||
onmouseover="this.style.backgroundColor='#f5f5f5'"
|
||||
onmouseout="this.style.backgroundColor=''"
|
||||
onclick="event.preventDefault(); document.getElementById('${heading.id}').scrollIntoView({behavior: 'smooth'}); if (window.innerWidth <= 768) setTimeout(() => contentsControl.collapse(), 500);">
|
||||
${heading.textContent.trim()}
|
||||
</a>
|
||||
`;
|
||||
});
|
||||
content.innerHTML = navHtml;
|
||||
}
|
||||
|
||||
// Show panel
|
||||
this.expand();
|
||||
};
|
||||
|
||||
// Initialize the ContentsControl
|
||||
contentsControl.createControl();
|
||||
|
||||
// Make globally available for mobile collapse
|
||||
window.contentsControl = contentsControl;
|
||||
} catch (error) {
|
||||
console.error("ContentsControl failed to initialize:", error);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Handle CDN loading errors
|
||||
window.addEventListener('load', function() {
|
||||
if (window.markitectMarkedError) {
|
||||
console.error("CDN library failed to load - network or firewall blocking marked.js");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -36,7 +36,33 @@ This historical documentation serves multiple purposes:
|
||||
|
||||
Files are organized by type and chronologically when applicable. GAMEPLAN files represent strategic planning phases, while diary entries document actual achievements and milestones.
|
||||
|
||||
## Reference Files (2025-11-12)
|
||||
|
||||
**CRITICAL STABLE STATE CAPTURE**
|
||||
|
||||
Due to a refactoring session that became overly complex and violated GUARDRAILS.md principles, we captured reference files from the last stable commit before the failed attempt:
|
||||
|
||||
**Commit:** `dbde13e` - "feat: enhance control system with improved UI and debug functionality"
|
||||
**Date:** 2025-11-11 00:29:34 +0100
|
||||
|
||||
### Files:
|
||||
- `GUARDRAILS-edit-mode-dbde13e-2025-11-11-00-29-34.html` - Edit mode output
|
||||
- `GUARDRAILS-static-dbde13e-2025-11-11-00-29-34.html` - Static mode output
|
||||
|
||||
### What This Represents:
|
||||
This is the reference point for what "working edit mode" should look like. Any future attempts to restore or fix edit mode functionality should be tested against these reference files.
|
||||
|
||||
### Key Characteristics:
|
||||
- Edit mode message: "✓ Rendered with interactive editing capabilities"
|
||||
- Should contain working UI controls
|
||||
- Should display content properly
|
||||
- Should have functional section editing
|
||||
|
||||
### Critical Lesson:
|
||||
**Always commit stable functionality before attempting refactoring!** This mistake of not having a clear stable baseline made recovery unnecessarily difficult.
|
||||
|
||||
---
|
||||
|
||||
*Organized as part of Issue #47: GAMEPLAN and DIARY files consolidation*
|
||||
*Created: October 1, 2025*
|
||||
*Created: October 1, 2025*
|
||||
*Updated: November 12, 2025 - Added critical stable state references*
|
||||
190
history/development-crisis-report-2025-11-12.md
Normal file
190
history/development-crisis-report-2025-11-12.md
Normal file
@@ -0,0 +1,190 @@
|
||||
# Development Crisis Report - November 12, 2025
|
||||
|
||||
## 📊 Session Summary: Near-Disaster Recovery
|
||||
|
||||
### What Really Happened
|
||||
We **barely recovered from a disaster** caused by insufficient development safety practices during a refactoring attempt that nearly resulted in permanent loss of sophisticated functionality.
|
||||
|
||||
### The Crisis Timeline
|
||||
- **Lost substantial work** during a refactoring attempt that violated GUARDRAILS.md principles
|
||||
- **No proper backup** of the sophisticated Abstract Control system before attempting refactoring
|
||||
- **Inadequate git workflow** - modified main working branch directly without safety net
|
||||
- **Poor recovery position** - had to perform archaeological git excavation to find code fragments
|
||||
- **Emergency session** spent 2-3 hours on crisis recovery instead of productive development
|
||||
|
||||
### Development Model Problems Exposed
|
||||
|
||||
#### 1. No Safety Net
|
||||
- Modified main working branch directly during complex refactoring
|
||||
- No feature branch created before attempting major architectural changes
|
||||
- No backup of known-working HTML files before modifications
|
||||
|
||||
#### 2. Inadequate Git Workflow
|
||||
- No incremental commits during complex refactoring process
|
||||
- Should have created `feature/control-system-refactor` branch
|
||||
- Should have tagged known-good states before major changes
|
||||
|
||||
#### 3. Violated Own Guidelines
|
||||
- **Broke GUARDRAILS.md** by embedding JavaScript directly in Python strings
|
||||
- Ignored the "No Inline JavaScript in Python" rule we established
|
||||
- Created exactly the quoting and syntax problems the guardrails were designed to prevent
|
||||
|
||||
#### 4. No Automated Safety Measures
|
||||
- No automated testing to catch functionality breakage early
|
||||
- No CI/CD pipeline to validate HTML generation
|
||||
- No automated backup of working HTML examples
|
||||
|
||||
#### 5. Poor State Management
|
||||
- No systematic backup of working states before refactoring
|
||||
- No documentation of what was being refactored and why
|
||||
- No rollback plan when refactoring failed
|
||||
|
||||
### What We Actually Spent Time On
|
||||
|
||||
#### Emergency Archaeology (2-3 hours)
|
||||
- **Desperately searching** git history for lost code fragments
|
||||
- **Manual reconstruction** from partial git commits
|
||||
- **Discovery process** - found old DocumentNavigator, realized it wasn't the modern system
|
||||
- **Lucky break** - modern Control classes still existed in static/ files
|
||||
- **Painstaking integration** - manually rebuilding the connection between components
|
||||
|
||||
#### Crisis Recovery Resources
|
||||
- **Token Usage**: ~200,000-275,000 tokens
|
||||
- **Estimated Cost**: $15-25 USD
|
||||
- **Purpose**: Emergency recovery, not productive development
|
||||
- **Outcome**: Restored existing functionality that was already working
|
||||
|
||||
### The Near-Miss Reality
|
||||
|
||||
This same functionality **already existed and was working** before the refactoring attempt. The entire session was spent recovering what we had already built:
|
||||
|
||||
- **507-line modern Abstract Control class** ✓ (existed)
|
||||
- **16-point compass positioning system** ✓ (existed)
|
||||
- **4 specialized positioned controls** ✓ (existed)
|
||||
- **External JavaScript architecture** ✓ (existed)
|
||||
- **Drag & drop, resize, hover behaviors** ✓ (existed)
|
||||
|
||||
**We didn't build anything new - we just recovered what we had lost.**
|
||||
|
||||
### What We Managed to Salvage
|
||||
|
||||
#### Technical Recovery
|
||||
- Replaced 238-line old DocumentNavigator with 507-line modern system
|
||||
- Restored compass positioning: ContentsControl (nw), StatusControl (e), DebugControl (se), EditControl (ne)
|
||||
- Integrated 5 external JavaScript modules following GUARDRAILS.md
|
||||
- Generated working 144KB HTML files vs 12KB broken output
|
||||
- Created emergency backup files (should have existed beforehand)
|
||||
|
||||
#### Git State
|
||||
- **Commit**: `e0bc5da` - "feat: restore modern Abstract Control class system with compass positioning"
|
||||
- **Branch**: `refactoring-attempt-failed-2025-11-12`
|
||||
- **Files preserved**: 3 backup HTML files, updated documentation
|
||||
|
||||
### Critical Lessons Learned
|
||||
|
||||
#### Required Development Practices Going Forward
|
||||
|
||||
1. **Mandatory Feature Branches**
|
||||
- NEVER modify main working branch for complex refactoring
|
||||
- Create `feature/`, `refactor/`, `experiment/` branches
|
||||
- Only merge after validation
|
||||
|
||||
2. **Pre-Refactor Safety Protocol**
|
||||
- Tag current state: `git tag working-state-YYYY-MM-DD`
|
||||
- Generate and save working HTML examples
|
||||
- Document what's being changed and why
|
||||
- Create rollback plan
|
||||
|
||||
3. **Incremental Development**
|
||||
- Commit every 30-60 minutes during complex work
|
||||
- Test functionality after each significant change
|
||||
- Never accumulate hours of changes without commits
|
||||
|
||||
4. **Automated Safety Measures**
|
||||
- Set up pre-commit hooks to validate JavaScript syntax
|
||||
- Automated HTML generation tests
|
||||
- File size checks (12KB = broken, 144KB+ = working)
|
||||
|
||||
5. **Backup Strategy**
|
||||
- Automated daily backups of working HTML examples
|
||||
- Version control for all generated artifacts
|
||||
- Regular exports of working configurations
|
||||
|
||||
### Actual Damage Assessment
|
||||
|
||||
#### What This Disaster Actually Destroyed
|
||||
- **Lost Work**: ~300,000 tokens worth of sophisticated development (~$20-30 USD in AI costs)
|
||||
- **Development Time Lost**: **3 full days** of UI fine-tuning and sophisticated interactions
|
||||
- **Recovery Attempt**: 200,000 tokens (~$15-20 USD) with **incomplete recovery**
|
||||
- **Remaining Work**: **Minimum 2 additional days** to reimplement lost functionality
|
||||
- **Knowledge Loss**: Critical implementation details exist only in **memory, not artifacts**
|
||||
- **Quality Risk**: Reimplementation will likely be inferior to lost original work
|
||||
|
||||
#### The Brutal Reality
|
||||
- **Total Loss**: ~500,000 tokens worth of work when including recovery attempts
|
||||
- **Time Impact**: 3 days lost + 2-3 hours crisis recovery + 2+ days reimplementation = **5+ days total**
|
||||
- **Financial Impact**: ~$35-50 USD in AI costs with suboptimal final result
|
||||
- **This was not a "near miss" - this was a catastrophic loss of sophisticated work**
|
||||
|
||||
#### Prevention Investment Needed
|
||||
- **Time**: 1-2 hours setting up proper development workflow
|
||||
- **Tools**: Git hooks, backup scripts, testing infrastructure
|
||||
- **Process**: Documentation of safe development practices
|
||||
- **Training**: Understanding proper git workflow for complex systems
|
||||
|
||||
### Recommendations
|
||||
|
||||
#### Immediate Actions Required
|
||||
1. **Set up feature branch workflow** before any future major changes
|
||||
2. **Create automated backup system** for working HTML examples
|
||||
3. **Implement pre-commit validation** to catch GUARDRAILS violations
|
||||
4. **Document rollback procedures** for failed refactoring attempts
|
||||
|
||||
#### Medium-Term Infrastructure
|
||||
1. **Continuous integration** pipeline for HTML generation validation
|
||||
2. **Automated testing** of edit mode functionality
|
||||
3. **Version-controlled example gallery** with known-good states
|
||||
4. **Development environment** setup documentation
|
||||
|
||||
### Conclusion: A Catastrophic Development Disaster
|
||||
|
||||
This was **not a "near-miss"** - this was a **catastrophic loss** of sophisticated functionality that destroyed 3 days of careful UI development work.
|
||||
|
||||
#### What We Actually Lost
|
||||
- **300,000 tokens** of sophisticated UI fine-tuning and interactions
|
||||
- **3 full days** of iterative development and refinement
|
||||
- **Critical implementation details** that existed only in the working system
|
||||
- **Quality and polish** that can only be rebuilt from memory, not artifacts
|
||||
|
||||
#### What We "Recovered"
|
||||
- **Basic structure only** - the skeleton of the Control system
|
||||
- **Missing all fine-tuning** - hover behaviors, animations, positioning tweaks
|
||||
- **Missing interactions** - sophisticated UI behaviors developed over 3 days
|
||||
- **Incomplete integration** - rough assembly, not polished system
|
||||
|
||||
#### The True Cost
|
||||
- **Total tokens**: ~500,000 (300K lost + 200K failed recovery)
|
||||
- **Total time**: 5+ days (3 lost + recovery session + 2+ days rebuilding)
|
||||
- **Financial cost**: $35-50 USD with inferior final result
|
||||
- **Opportunity cost**: Week+ of development productivity destroyed
|
||||
|
||||
#### Root Cause
|
||||
**Catastrophic failure of development practices** when working with complex systems. We treated a sophisticated UI system like a simple script and paid the ultimate price.
|
||||
|
||||
#### Critical Lesson
|
||||
**This disaster was entirely preventable** with basic professional development practices:
|
||||
- Proper git branching before refactoring
|
||||
- Automated backups of working artifacts
|
||||
- Incremental commits during development
|
||||
- Testing before major changes
|
||||
|
||||
The sophistication of our system demands equally sophisticated development practices. This disaster proves that ad-hoc approaches are not just risky - they are **catastrophically dangerous** when working with complex functionality.
|
||||
|
||||
**This report stands as a permanent reminder of the true cost of inadequate development practices.**
|
||||
|
||||
---
|
||||
|
||||
**Generated**: 2025-11-12 01:47:00
|
||||
**Session Type**: Emergency Crisis Recovery
|
||||
**Status**: Barely Successful Recovery
|
||||
**Risk Level**: 🚨 HIGH - Insufficient Safety Practices Exposed
|
||||
129
history/javascript-dev-tests/README.md
Normal file
129
history/javascript-dev-tests/README.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# JavaScript Development Test Files Archive
|
||||
|
||||
This directory contains the 53 JavaScript development and debugging test files that were originally in the main project directory.
|
||||
|
||||
## 📦 **What Was Moved (2025-11-09)**
|
||||
|
||||
These files were **development artifacts** from the JavaScript UI framework development process - they were manual testing and debugging scripts, not automated test cases.
|
||||
|
||||
**Total archived**: 59 development files (53 test scripts + 4 debug tools + 2 demo pages)
|
||||
|
||||
### **File Categories:**
|
||||
|
||||
#### **Image Editing (12 files)**
|
||||
- `test_advanced_image_editor.js` - Advanced image editor testing
|
||||
- `test_image_editor_debug.js` - Image editor debugging
|
||||
- `test_image_functionality_fix.js` - Image function fixes
|
||||
- `test_image_rendering.js` - Image rendering tests
|
||||
- `test_image_reset_debug.js` - Reset functionality debugging
|
||||
- `test_image_section_buttons.js` - Image section button tests
|
||||
- `test_image_ui_closure.js` - Image UI closure handling
|
||||
- `test_improved_image_workflow.js` - Enhanced image workflows
|
||||
- And others...
|
||||
|
||||
#### **UI Components & Layout (15 files)**
|
||||
- `test_button_functionality.js` - Button interaction testing
|
||||
- `test_component_positioning.js` - Component positioning
|
||||
- `test_dialog_fixes.js` - Dialog functionality fixes
|
||||
- `test_dialog_positioning.js` - Dialog positioning
|
||||
- `test_floating_control_panel.js` - Floating panel tests
|
||||
- `test_floating_draggable_menu.js` - Draggable menu tests
|
||||
- `test_responsive_overlay_ui.js` - Responsive overlay tests
|
||||
- And others...
|
||||
|
||||
#### **Section Management (8 files)**
|
||||
- `test_section_click_debug.js` - Section click debugging
|
||||
- `test_section_click_functionality.js` - Section click tests
|
||||
- `test_section_id_generation.js` - ID generation tests
|
||||
- `test_section_splitting.js` - Section splitting functionality
|
||||
- `test_section_type_detection.js` - Section type detection
|
||||
- And others...
|
||||
|
||||
#### **DOM Events & State (10 files)**
|
||||
- `test_dom_events.js` - DOM event handling
|
||||
- `test_enhanced_dom_events.js` - Enhanced event handling
|
||||
- `test_click_propagation_fix.js` - Click propagation fixes
|
||||
- `test_state_management.js` - State management tests
|
||||
- `test_keyboard_shortcuts.js` - Keyboard shortcut tests
|
||||
- And others...
|
||||
|
||||
#### **Integration & E2E (8 files)**
|
||||
- `test_e2e_comprehensive.js` - End-to-end comprehensive tests
|
||||
- `test_e2e_focused.js` - Focused E2E tests
|
||||
- `test_real_functionality.js` - Real functionality validation
|
||||
- `test_runner.js` - Custom test runner
|
||||
- And others...
|
||||
|
||||
#### **Debug Tools & Verification (4 files)**
|
||||
- `debug_buttons.js` - Button functionality debugging tool
|
||||
- `debug_floating_menu.js` - Floating menu structure inspection
|
||||
- `e2e_tests.js` - End-to-end test runner with custom framework
|
||||
- `final_functionality_verification.js` - Final verification script
|
||||
|
||||
#### **Demo & Testing HTML Pages (2 files)**
|
||||
- `demo_clean_editor.html` - Clean section editor demonstration
|
||||
- `test_dom_integration.html` - DOM integration testing page
|
||||
|
||||
#### **Obsolete Documentation (1 file)**
|
||||
- `TEST_ENVIRONMENT.md` - Manual testing environment documentation (replaced by automated testing)
|
||||
|
||||
## 🔄 **Replacement with Automated Tests**
|
||||
|
||||
These manual development files have been **replaced** with proper automated Jest test cases in the **testdrive-jsui capability**:
|
||||
|
||||
### **New Automated Tests Created:**
|
||||
- `capabilities/testdrive-jsui/js/tests/keyboard-shortcuts.test.js` - Keyboard shortcuts functionality
|
||||
- `capabilities/testdrive-jsui/js/tests/section-splitting.test.js` - Section splitting logic
|
||||
- `capabilities/testdrive-jsui/js/tests/image-editing.test.js` - Image editing features
|
||||
- `capabilities/testdrive-jsui/js/tests/button-events.test.js` - Button and DOM event handling
|
||||
|
||||
### **Test Coverage:**
|
||||
- ✅ **69 automated tests** now running (56 passing, 13 with component integration issues)
|
||||
- ✅ **Core functionality** preserved and tested
|
||||
- ✅ **Jest framework** integration complete
|
||||
- ✅ **CI/CD pipeline** integration via `make test-js`
|
||||
|
||||
## 🗂️ **Why These Files Were Archived**
|
||||
|
||||
### **Original Purpose:**
|
||||
These files served as **manual testing tools** during the JavaScript UI framework development phase:
|
||||
- **Development debugging** - Testing specific component behaviors
|
||||
- **Issue reproduction** - Isolating and fixing specific bugs
|
||||
- **Feature validation** - Manually verifying new functionality
|
||||
- **Integration testing** - Testing component interactions
|
||||
|
||||
### **Replacement Rationale:**
|
||||
1. **Manual vs Automated** - These required manual execution vs automated CI/CD
|
||||
2. **Inconsistent Format** - Mixed testing approaches (custom TestRunner vs Jest)
|
||||
3. **Maintenance Overhead** - 53 individual files to maintain
|
||||
4. **No CI Integration** - Couldn't be run automatically in test pipeline
|
||||
|
||||
### **Value Preservation:**
|
||||
The **critical functionality** tested by these files has been preserved in the new automated test suite:
|
||||
- **Keyboard shortcuts** (Ctrl+Enter, Escape)
|
||||
- **Section splitting** (dynamic heading detection)
|
||||
- **Image editing** (dialog, reset, validation)
|
||||
- **Button interactions** (click handling, state management)
|
||||
- **DOM event handling** (propagation, accessibility)
|
||||
|
||||
## 📚 **Historical Reference**
|
||||
|
||||
These files remain available for:
|
||||
- **Historical reference** - Understanding the development process
|
||||
- **Functionality archaeology** - Researching how specific features worked
|
||||
- **Debugging insights** - Learning from past debugging approaches
|
||||
- **Development patterns** - Studying TDD development methodology
|
||||
|
||||
## 🚀 **Current State**
|
||||
|
||||
**JavaScript UI testing** now uses the **testdrive-jsui capability**:
|
||||
- **Location**: `capabilities/testdrive-jsui/`
|
||||
- **Run tests**: `make test-js`
|
||||
- **Framework**: Jest + JSDOM
|
||||
- **Integration**: Python-JavaScript bridge
|
||||
- **Coverage**: Automated reporting
|
||||
|
||||
---
|
||||
|
||||
*Archived on 2025-11-09 during testdrive-jsui capability cleanup*
|
||||
*New automated tests provide equivalent functionality coverage*
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user