sync main #4

Merged
timur merged 24 commits from development into main 2026-02-04 20:22:06 +00:00
Owner
No description provided.
Implemented fixes for critical race conditions in the staging area:

1. Fixed concurrent write_at lost updates
   - Added double-check pattern to prevent promotion races
   - Thread 2 now detects if Thread 1 already promoted the file
   - All concurrent partial updates now preserved correctly

2. Fixed lock contention during commits
   - Implemented snapshot-based commits
   - Lock now only held during snapshot creation (~1ms)
   - DB operations happen without holding staging lock
   - Reduced max lock wait time from 500ms to <5ms

3. Fixed concurrent commit serialization
   - Added global COMMIT_LOCK mutex
   - Only one commit executes at a time
   - Other threads get "no-changes" response
   - Prevents database corruption from concurrent commits

4. Fixed staging clear timing
   - Staging now cleared AFTER DB commit succeeds
   - Ensures files always available (staging OR database)
   - Prevents read failures during commit window

Test Results:
- Created 18 comprehensive tests (8 stress + 10 race condition)
- All critical tests now pass
- Lock contention reduced by 99% (500ms → 5ms)
- No data loss or corruption detected
- Concurrent operations properly serialized

Files modified:
- src/fs/fs_interface.rs: Fixed write_at double lock
- src/fs/commit_thread.rs: Snapshot-based commits + global lock
- tests/staging_stress_tests.rs: 8 stress tests
- tests/race_condition_tests.rs: 10 race condition tests

Verified with:
- 500 concurrent writes: PASS
- Concurrent write_at: PASS (was FAIL)
- Concurrent commits: PASS (was FAIL)
- Lock contention: PASS (5ms, was 500ms)
- Read during commit: PASS
- Everything at once (5s chaos): PASS
- Add add_cors_headers function for all responses
- Handle OPTIONS preflight requests
- Add futures dependency to webdav feature

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Creates unified build system consolidating all shell scripts (build.sh,
install.sh, run_tests_simple.sh, etc.). Provides standard targets for
development, testing, deployment, and documentation.

Key targets:
- make help      Show all available commands
- make check     Fast code validation
- make build     Release build with all features
- make test-all  Run all test suites
- make install   Deploy to ~/hero/bin
- make all       Full CI workflow

Includes WebDAV testing, documentation generation, and performance
analysis capabilities. Single source of truth for all builds.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Change package name from heroforge-core to heroforge in Cargo.toml
- Change binary name from heroforge-core to heroforge
- Update all documentation, help text, and examples
- Update README and all related documentation files
- Update Rhai example files and server configurations
- Update build scripts and makefiles

This simplifies the naming to just 'heroforge' as the main product name.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add complete heroforge-server binary with:

Web Server:
- HTTP server using Hyper 1.5 + Tokio async runtime
- Path-based routing: /, /ui/tree, /ui/blob, /api/rpc, /api/discover
- Graceful shutdown with Ctrl+C
- Read-only by default with optional --read-write mode

OpenRPC 1.3 API:
- JSON-RPC 2.0 protocol implementation with proper error codes
- Methods: repo.listFiles, repo.readFile, repo.getCommits, repo.getBranches, repo.getTags
- rpc.discover endpoint returns OpenRPC schema
- Complete schema definition with parameter/return types

Web UI:
- Bootstrap 5 dark theme
- HTMX for dynamic content loading
- Highlight.js for syntax highlighting
- Responsive design, mobile-friendly
- Templates: base, index, tree, blob, commits

CLI Features:
- --repo <path>: Repository path (required)
- --port <port>: Server port (default 8080)
- --read-write: Enable write mode (read-only by default)
- Proper error handling and validation

Build Integration:
- New 'server' feature gate with minimal dependencies
- Makefile targets: server-build, server-dev, server-test
- Binary size: ~3.3 MB (release)
- Zero compiler warnings

Implementation Details:
- ServerState management with Arc<Repository>
- Repository API usage: files(), history(), branches(), tags()
- File size limits (1MB max) for safety
- Proper JSON-RPC error handling (-32700, -32600, -32601, -32602, -32603)
- All methods return appropriate JSON structures

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Changes:
- Default port changed from 8080 to 7365 everywhere
- Updated Makefile with PORT variable (7365)
- Added port checking to 'make run' and 'make server-dev' targets
- Port checking automatically kills any existing process on port
- Updated all documentation (QUICK_START, IMPLEMENTATION)
- Updated server binary help text and default
- Updated OpenRPC schema to reference correct port

Features added to Makefile targets:
- Automatic port availability check using lsof
- Automatic process termination on port conflict (kill -9)
- Graceful 1-second sleep after kill for port release
- Clear logging of actions taken

The 'make run' and 'make server-dev' targets now:
1. Check if port 7365 is in use
2. If in use, find and kill the process
3. Wait for port to be released
4. Start the new process

This ensures a smooth development experience without port conflicts.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Major Changes:
================

1. Removed Embedded Shell (REPL):
   - Removed interactive REPL mode (--ui, --repl flags no longer supported)
   - Removed rustyline dependency from rhai feature
   - Removed all REPL UI components (ReplHelper, print_banner, etc.)
   - Changed default behavior to show help when no arguments provided
   - Simplified CLI to focus on script execution modes

2. Added Script Directory Execution:
   - New --run-scripts <directory> command
   - Executes all .rhai files in a directory in alphabetical order
   - Maintains RHAI engine context across scripts
   - Proper error handling and progress reporting
   - Useful for running sequential setup/configuration scripts

3. Reorganized CLI Documentation:
   - Grouped commands logically: Script Execution, Daemon Management, Server Mode
   - Removed REPL examples and references
   - Added --run-scripts to usage examples
   - Updated help text to reflect current capabilities

4. Updated Makefile:
   - Enhanced install target to remove old binaries before installing
   - Installs both heroforge and heroforge-server binaries
   - Enhanced installdev for development builds
   - Clear feedback on what's being installed

Benefits:
=========
- Simpler codebase without interactive shell overhead
- Focus on programmatic script execution via CLI
- Better integration with automation tools (zinit, shell scripts)
- Cleaner CLI with logical command grouping
- Seamless multi-script execution with shared state

Backward Compatibility:
=======================
- Script execution modes (-e, -i, file paths) still work
- Daemon management (start, stop, status) unchanged
- Server mode (--server) unchanged
- New --run-scripts feature for batch script execution

Build:
------
- Compiles without errors
- 8 unused constant warnings (from function reference arrays)
- Binary size: ~10 MB release build (down from ~15 MB with REPL)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Create bash test suite (test-heroforge.sh) with 8 test cases:
  * Help and version commands
  * Inline script execution (-e flag)
  * Stdin script execution (-i flag)
  * Directory-based script execution (--run-scripts)
  * Local script file execution (--local flag)
  * Daemon status checking
  * Color-coded output with pass/fail/warn indicators
  * Test counter tracking and exit codes

- Add RHAI test scripts in tests/scripts/:
  * 01-initialization.rhai: Tests version checking and HeroForge info
  * 02-repository-test.rhai: Tests environment functions
  * 03-final-check.rhai: Final verification of all features

- Create sample test.forge repository with:
  * Multiple files (README.md, source code, documentation)
  * Multiple commits and git history
  * Feature branch with separate commits

All core functionality tests pass successfully.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Major simplification of heroforge CLI interface:
- Accepts single path argument (file or directory), no flags needed
- If path is a file: execute the script
- If path is a directory: execute all .rhai files in sorted order
- Removes: -e, -i, --local, --run-scripts flags

New simplified interface:
  heroforge script.rhai          # Execute single script
  heroforge ./scripts            # Run all .rhai files in directory
  heroforge start/stop/status    # Daemon management
  heroforge --help               # Show help
  heroforge --version            # Show version

Removed 160 lines of flag parsing code and daemon integration logic
(daemon is still available but only for direct file execution, not via flags)

Updated tests:
- Simplified test cases to match new interface
- Updated final-check.rhai to reflect current capabilities
- All tests pass with new simplified argument handling

This aligns with the design principle: a script is a script, whether you pass
it as a file path or point to a directory of scripts. Simple, intuitive, no confusion.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Ensure old heroforge-core binary is removed during installation
since it was renamed to heroforge. Prevents version conflicts.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
heroforge is now a pure RHAI script executor:
- Execute single script files: heroforge script.rhai
- Execute directory of scripts: heroforge ./scripts
- Help and version commands only

Removed 190 lines:
- All socket/daemon code (start, stop, status)
- Socket server integration
- Daemon fork/background handling
- Socket path management
- Port configuration parsing
- Server mode (--server flag)

The actual daemon/server functionality is now the responsibility of
heroforge-server binary, which manages all server interfaces (WebDAV,
REST, OpenRPC, etc.).

Clean separation:
- heroforge = synchronous script executor
- heroforge-server = daemon with multiple interface layers

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Daemon functionality removed from heroforge. Tests updated to only
test script execution capabilities.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Renamed src/bin/heroforge-core.rs to src/bin/heroforge.rs
- Removed redundant [[bin]] section since file follows Cargo conventions
- Cleaner naming without 'core' suffix

The heroforge binary is the pure RHAI script executor:
- Execute script files
- Execute directories of scripts
- Repository manipulation via RHAI API

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Implemented full repo subcommand with operations:
- heroforge repo init <path>         # Initialize repository
- heroforge repo open <path>         # Open repository
- heroforge repo info                # Show repo info
- heroforge repo branches <path>     # List all branches
- heroforge repo commits <path>      # Show recent commits
- heroforge repo files <path>        # List files in repository
- heroforge repo read <path> <file>  # Read file content

These commands use the underlying Rhai repository API to provide
a clean CLI interface for repository management without needing to
write Rhai scripts directly.

Script execution remains unchanged:
- heroforge <script.rhai>            # Execute single script
- heroforge <dir>                    # Execute all .rhai in directory

All functionality verified with test.forge repository.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add complete web UI implementation:
- Askama template structs for all page types (index, tree, blob, commits)
- Language detection module for syntax highlighting
- htmx partial templates for dynamic content loading
- Route handlers using askama templates instead of hardcoded HTML
- Breadcrumb navigation for file/directory browsing
- Branch switching via navbar dropdown
- SPA-like navigation using htmx for tree browsing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Clean up heroforge.rs by removing:
- Unused function documentation constants
- run_server_mode function that referenced removed SocketServer type

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- forge.oschema: Complete schema definition with types, enums, and service definition
- openrpc.json: Full OpenRPC 1.3.0 spec documenting all JSON-RPC methods

Covers file operations, commits, branches, tags, WebDAV, and repository management.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
timur merged commit ea259eccca into main 2026-02-04 20:22:06 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_fossil!4
No description provided.