feat: DQN Rainbow enhancements with hyperopt results and test coverage

- Update DQN trainer with gradient collapse detection warmup
- Add portfolio tracker improvements
- Include hyperopt trial results (multiple Sharpe ratio experiments)
- Add new test files for action/position sign convention, early stopping,
  cash reserve bugs, and portfolio execution
- Update trained model files
- Add Claude Code configuration and skills

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2025-11-27 14:45:25 +01:00
parent ae64902564
commit 2c1acda2f3
233 changed files with 51887 additions and 479 deletions

View File

@@ -0,0 +1,251 @@
#!/bin/bash
# Claude Checkpoint Manager
# Provides easy rollback and management of Claude Code checkpoints
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
CHECKPOINT_DIR=".claude/checkpoints"
BACKUP_DIR=".claude/backups"
# Help function
show_help() {
cat << EOF
Claude Checkpoint Manager
========================
Usage: $0 <command> [options]
Commands:
list List all checkpoints
show <id> Show details of a specific checkpoint
rollback <id> Rollback to a specific checkpoint
diff <id> Show diff since checkpoint
clean Clean old checkpoints (older than 7 days)
summary Show session summary
Options:
--hard For rollback: use git reset --hard (destructive)
--soft For rollback: use git reset --soft (default)
--branch For rollback: create new branch from checkpoint
Examples:
$0 list
$0 show checkpoint-20240130-143022
$0 rollback checkpoint-20240130-143022 --branch
$0 diff session-end-session-20240130-150000
EOF
}
# List all checkpoints
function list_checkpoints() {
echo -e "${BLUE}📋 Available Checkpoints:${NC}"
echo ""
# List checkpoint tags
echo -e "${YELLOW}Git Tags:${NC}"
local tags=$(git tag -l 'checkpoint-*' -l 'session-end-*' -l 'task-*' --sort=-creatordate | head -20)
if [ -n "$tags" ]; then
echo "$tags"
else
echo "No checkpoint tags found"
fi
echo ""
# List checkpoint branches
echo -e "${YELLOW}Checkpoint Branches:${NC}"
local branches=$(git branch -a | grep "checkpoint/" | sed 's/^[ *]*//')
if [ -n "$branches" ]; then
echo "$branches"
else
echo "No checkpoint branches found"
fi
echo ""
# List checkpoint files
if [ -d "$CHECKPOINT_DIR" ]; then
echo -e "${YELLOW}Recent Checkpoint Files:${NC}"
find "$CHECKPOINT_DIR" -name "*.json" -type f -printf "%T@ %p\n" | \
sort -rn | head -10 | cut -d' ' -f2- | xargs -I {} basename {}
fi
}
# Show checkpoint details
function show_checkpoint() {
local checkpoint_id="$1"
echo -e "${BLUE}📍 Checkpoint Details: $checkpoint_id${NC}"
echo ""
# Check if it's a tag
if git tag -l "$checkpoint_id" | grep -q "$checkpoint_id"; then
echo -e "${YELLOW}Type:${NC} Git Tag"
echo -e "${YELLOW}Commit:${NC} $(git rev-list -n 1 "$checkpoint_id")"
echo -e "${YELLOW}Date:${NC} $(git log -1 --format=%ai "$checkpoint_id")"
echo -e "${YELLOW}Message:${NC}"
git log -1 --format=%B "$checkpoint_id" | sed 's/^/ /'
echo ""
echo -e "${YELLOW}Files changed:${NC}"
git diff-tree --no-commit-id --name-status -r "$checkpoint_id" | sed 's/^/ /'
# Check if it's a branch
elif git branch -a | grep -q "$checkpoint_id"; then
echo -e "${YELLOW}Type:${NC} Git Branch"
echo -e "${YELLOW}Latest commit:${NC}"
git log -1 --oneline "$checkpoint_id"
else
echo -e "${RED}❌ Checkpoint not found: $checkpoint_id${NC}"
exit 1
fi
}
# Rollback to checkpoint
function rollback_checkpoint() {
local checkpoint_id="$1"
local mode="$2"
echo -e "${YELLOW}🔄 Rolling back to checkpoint: $checkpoint_id${NC}"
echo ""
# Verify checkpoint exists
if ! git tag -l "$checkpoint_id" | grep -q "$checkpoint_id" && \
! git branch -a | grep -q "$checkpoint_id"; then
echo -e "${RED}❌ Checkpoint not found: $checkpoint_id${NC}"
exit 1
fi
# Create backup before rollback
local backup_name="backup-$(date +%Y%m%d-%H%M%S)"
echo "Creating backup: $backup_name"
git tag "$backup_name" -m "Backup before rollback to $checkpoint_id"
case "$mode" in
"--hard")
echo -e "${RED}⚠️ Performing hard reset (destructive)${NC}"
git reset --hard "$checkpoint_id"
echo -e "${GREEN}✅ Rolled back to $checkpoint_id (hard reset)${NC}"
;;
"--branch")
local branch_name="rollback-$checkpoint_id-$(date +%Y%m%d-%H%M%S)"
echo "Creating new branch: $branch_name"
git checkout -b "$branch_name" "$checkpoint_id"
echo -e "${GREEN}✅ Created branch $branch_name from $checkpoint_id${NC}"
;;
"--stash"|*)
echo "Stashing current changes..."
git stash push -m "Stash before rollback to $checkpoint_id"
git reset --soft "$checkpoint_id"
echo -e "${GREEN}✅ Rolled back to $checkpoint_id (soft reset)${NC}"
echo "Your changes are stashed. Use 'git stash pop' to restore them."
;;
esac
}
# Show diff since checkpoint
function diff_checkpoint() {
local checkpoint_id="$1"
echo -e "${BLUE}📊 Changes since checkpoint: $checkpoint_id${NC}"
echo ""
if git tag -l "$checkpoint_id" | grep -q "$checkpoint_id"; then
git diff "$checkpoint_id"
elif git branch -a | grep -q "$checkpoint_id"; then
git diff "$checkpoint_id"
else
echo -e "${RED}❌ Checkpoint not found: $checkpoint_id${NC}"
exit 1
fi
}
# Clean old checkpoints
function clean_checkpoints() {
local days=${1:-7}
echo -e "${YELLOW}🧹 Cleaning checkpoints older than $days days...${NC}"
echo ""
# Clean old checkpoint files
if [ -d "$CHECKPOINT_DIR" ]; then
find "$CHECKPOINT_DIR" -name "*.json" -type f -mtime +$days -delete
echo "✅ Cleaned old checkpoint files"
fi
# List old tags (but don't delete automatically)
echo ""
echo "Old checkpoint tags (manual deletion required):"
git tag -l 'checkpoint-*' --sort=-creatordate | tail -n +50 || echo "No old tags found"
}
# Show session summary
function show_summary() {
echo -e "${BLUE}📊 Session Summary${NC}"
echo ""
# Find most recent session summary
if [ -d "$CHECKPOINT_DIR" ]; then
local latest_summary=$(find "$CHECKPOINT_DIR" -name "summary-*.md" -type f -printf "%T@ %p\n" | \
sort -rn | head -1 | cut -d' ' -f2-)
if [ -n "$latest_summary" ]; then
echo -e "${YELLOW}Latest session summary:${NC}"
cat "$latest_summary"
else
echo "No session summaries found"
fi
fi
}
# Main command handling
case "$1" in
list)
list_checkpoints
;;
show)
if [ -z "$2" ]; then
echo -e "${RED}Error: Please specify a checkpoint ID${NC}"
show_help
exit 1
fi
show_checkpoint "$2"
;;
rollback)
if [ -z "$2" ]; then
echo -e "${RED}Error: Please specify a checkpoint ID${NC}"
show_help
exit 1
fi
rollback_checkpoint "$2" "$3"
;;
diff)
if [ -z "$2" ]; then
echo -e "${RED}Error: Please specify a checkpoint ID${NC}"
show_help
exit 1
fi
diff_checkpoint "$2"
;;
clean)
clean_checkpoints "$2"
;;
summary)
show_summary
;;
help|--help|-h)
show_help
;;
*)
echo -e "${RED}Error: Unknown command: $1${NC}"
echo ""
show_help
exit 1
;;
esac

106
.claude/helpers/github-safe.js Executable file
View File

@@ -0,0 +1,106 @@
#!/usr/bin/env node
/**
* Safe GitHub CLI Helper
* Prevents timeout issues when using gh commands with special characters
*
* Usage:
* ./github-safe.js issue comment 123 "Message with `backticks`"
* ./github-safe.js pr create --title "Title" --body "Complex body"
*/
import { execSync } from 'child_process';
import { writeFileSync, unlinkSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { randomBytes } from 'crypto';
const args = process.argv.slice(2);
if (args.length < 2) {
console.log(`
Safe GitHub CLI Helper
Usage:
./github-safe.js issue comment <number> <body>
./github-safe.js pr comment <number> <body>
./github-safe.js issue create --title <title> --body <body>
./github-safe.js pr create --title <title> --body <body>
This helper prevents timeout issues with special characters like:
- Backticks in code examples
- Command substitution \$(...)
- Directory paths
- Special shell characters
`);
process.exit(1);
}
const [command, subcommand, ...restArgs] = args;
// Handle commands that need body content
if ((command === 'issue' || command === 'pr') &&
(subcommand === 'comment' || subcommand === 'create')) {
let bodyIndex = -1;
let body = '';
if (subcommand === 'comment' && restArgs.length >= 2) {
// Simple format: github-safe.js issue comment 123 "body"
body = restArgs[1];
bodyIndex = 1;
} else {
// Flag format: --body "content"
bodyIndex = restArgs.indexOf('--body');
if (bodyIndex !== -1 && bodyIndex < restArgs.length - 1) {
body = restArgs[bodyIndex + 1];
}
}
if (body) {
// Use temporary file for body content
const tmpFile = join(tmpdir(), `gh-body-${randomBytes(8).toString('hex')}.tmp`);
try {
writeFileSync(tmpFile, body, 'utf8');
// Build new command with --body-file
const newArgs = [...restArgs];
if (subcommand === 'comment' && bodyIndex === 1) {
// Replace body with --body-file
newArgs[1] = '--body-file';
newArgs.push(tmpFile);
} else if (bodyIndex !== -1) {
// Replace --body with --body-file
newArgs[bodyIndex] = '--body-file';
newArgs[bodyIndex + 1] = tmpFile;
}
// Execute safely
const ghCommand = `gh ${command} ${subcommand} ${newArgs.join(' ')}`;
console.log(`Executing: ${ghCommand}`);
const result = execSync(ghCommand, {
stdio: 'inherit',
timeout: 30000 // 30 second timeout
});
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
} finally {
// Clean up
try {
unlinkSync(tmpFile);
} catch (e) {
// Ignore cleanup errors
}
}
} else {
// No body content, execute normally
execSync(`gh ${args.join(' ')}`, { stdio: 'inherit' });
}
} else {
// Other commands, execute normally
execSync(`gh ${args.join(' ')}`, { stdio: 'inherit' });
}

28
.claude/helpers/github-setup.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# Setup GitHub integration for Claude Flow
echo "🔗 Setting up GitHub integration..."
# Check for gh CLI
if ! command -v gh &> /dev/null; then
echo "⚠️ GitHub CLI (gh) not found"
echo "Install from: https://cli.github.com/"
echo "Continuing without GitHub features..."
else
echo "✅ GitHub CLI found"
# Check auth status
if gh auth status &> /dev/null; then
echo "✅ GitHub authentication active"
else
echo "⚠️ Not authenticated with GitHub"
echo "Run: gh auth login"
fi
fi
echo ""
echo "📦 GitHub swarm commands available:"
echo " - npx claude-flow github swarm"
echo " - npx claude-flow repo analyze"
echo " - npx claude-flow pr enhance"
echo " - npx claude-flow issue triage"

19
.claude/helpers/quick-start.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# Quick start guide for Claude Flow
echo "🚀 Claude Flow Quick Start"
echo "=========================="
echo ""
echo "1. Initialize a swarm:"
echo " npx claude-flow swarm init --topology hierarchical"
echo ""
echo "2. Spawn agents:"
echo " npx claude-flow agent spawn --type coder --name "API Developer""
echo ""
echo "3. Orchestrate tasks:"
echo " npx claude-flow task orchestrate --task "Build REST API""
echo ""
echo "4. Monitor progress:"
echo " npx claude-flow swarm monitor"
echo ""
echo "📚 For more examples, see .claude/commands/"

18
.claude/helpers/setup-mcp.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
# Setup MCP server for Claude Flow
echo "🚀 Setting up Claude Flow MCP server..."
# Check if claude command exists
if ! command -v claude &> /dev/null; then
echo "❌ Error: Claude Code CLI not found"
echo "Please install Claude Code first"
exit 1
fi
# Add MCP server
echo "📦 Adding Claude Flow MCP server..."
claude mcp add claude-flow npx claude-flow mcp start
echo "✅ MCP server setup complete!"
echo "🎯 You can now use mcp__claude-flow__ tools in Claude Code"

View File

@@ -0,0 +1,179 @@
#!/bin/bash
# Standard checkpoint hook functions for Claude settings.json (without GitHub features)
# Function to handle pre-edit checkpoints
pre_edit_checkpoint() {
local tool_input="$1"
local file=$(echo "$tool_input" | jq -r '.file_path // empty')
if [ -n "$file" ]; then
local checkpoint_branch="checkpoint/pre-edit-$(date +%Y%m%d-%H%M%S)"
local current_branch=$(git branch --show-current)
# Create checkpoint
git add -A
git stash push -m "Pre-edit checkpoint for $file" >/dev/null 2>&1
git branch "$checkpoint_branch"
# Store metadata
mkdir -p .claude/checkpoints
cat > ".claude/checkpoints/$(date +%s).json" <<EOF
{
"branch": "$checkpoint_branch",
"file": "$file",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"type": "pre-edit",
"original_branch": "$current_branch"
}
EOF
# Restore working directory
git stash pop --quiet >/dev/null 2>&1 || true
echo "✅ Created checkpoint: $checkpoint_branch for $file"
fi
}
# Function to handle post-edit checkpoints
post_edit_checkpoint() {
local tool_input="$1"
local file=$(echo "$tool_input" | jq -r '.file_path // empty')
if [ -n "$file" ] && [ -f "$file" ]; then
# Check if file was modified - first check if file is tracked
if ! git ls-files --error-unmatch "$file" >/dev/null 2>&1; then
# File is not tracked, add it first
git add "$file"
fi
# Now check if there are changes
if git diff --cached --quiet "$file" 2>/dev/null && git diff --quiet "$file" 2>/dev/null; then
echo " No changes to checkpoint for $file"
else
local tag_name="checkpoint-$(date +%Y%m%d-%H%M%S)"
local current_branch=$(git branch --show-current)
# Create commit
git add "$file"
if git commit -m "🔖 Checkpoint: Edit $file
Automatic checkpoint created by Claude
- File: $file
- Branch: $current_branch
- Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
[Auto-checkpoint]" --quiet; then
# Create tag only if commit succeeded
git tag -a "$tag_name" -m "Checkpoint after editing $file"
# Store metadata
mkdir -p .claude/checkpoints
local diff_stats=$(git diff HEAD~1 --stat | tr '\n' ' ' | sed 's/"/\"/g')
cat > ".claude/checkpoints/$(date +%s).json" <<EOF
{
"tag": "$tag_name",
"file": "$file",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"type": "post-edit",
"branch": "$current_branch",
"diff_summary": "$diff_stats"
}
EOF
echo "✅ Created checkpoint: $tag_name for $file"
else
echo " No commit created (no changes or commit failed)"
fi
fi
fi
}
# Function to handle task checkpoints
task_checkpoint() {
local user_prompt="$1"
local task=$(echo "$user_prompt" | head -c 100 | tr '\n' ' ')
if [ -n "$task" ]; then
local checkpoint_name="task-$(date +%Y%m%d-%H%M%S)"
# Commit current state
git add -A
git commit -m "🔖 Task checkpoint: $task..." --quiet || true
# Store metadata
mkdir -p .claude/checkpoints
cat > ".claude/checkpoints/task-$(date +%s).json" <<EOF
{
"checkpoint": "$checkpoint_name",
"task": "$task",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"commit": "$(git rev-parse HEAD)"
}
EOF
echo "✅ Created task checkpoint: $checkpoint_name"
fi
}
# Function to handle session end
session_end_checkpoint() {
local session_id="session-$(date +%Y%m%d-%H%M%S)"
local summary_file=".claude/checkpoints/summary-$session_id.md"
mkdir -p .claude/checkpoints
# Create summary
cat > "$summary_file" <<EOF
# Session Summary - $(date +'%Y-%m-%d %H:%M:%S')
## Checkpoints Created
$(find .claude/checkpoints -name '*.json' -mtime -1 -exec basename {} \; | sort)
## Files Modified
$(git diff --name-only $(git log --format=%H -n 1 --before="1 hour ago" 2>/dev/null) 2>/dev/null || echo "No files tracked")
## Recent Commits
$(git log --oneline -10 --grep="Checkpoint" || echo "No checkpoint commits")
## Rollback Instructions
To rollback to a specific checkpoint:
\`\`\`bash
# List all checkpoints
git tag -l 'checkpoint-*' | sort -r
# Rollback to a checkpoint
git checkout checkpoint-YYYYMMDD-HHMMSS
# Or reset to a checkpoint (destructive)
git reset --hard checkpoint-YYYYMMDD-HHMMSS
\`\`\`
EOF
# Create final checkpoint
git add -A
git commit -m "🏁 Session end checkpoint: $session_id" --quiet || true
git tag -a "session-end-$session_id" -m "End of Claude session"
echo "✅ Session summary saved to: $summary_file"
echo "📌 Final checkpoint: session-end-$session_id"
}
# Main entry point
case "$1" in
pre-edit)
pre_edit_checkpoint "$2"
;;
post-edit)
post_edit_checkpoint "$2"
;;
task)
task_checkpoint "$2"
;;
session-end)
session_end_checkpoint
;;
*)
echo "Usage: $0 {pre-edit|post-edit|task|session-end} [input]"
exit 1
;;
esac