- Added a new integration script to manage custom features related to smart context. - Implemented handlers for smart context operations (get, update, clear, stats) in ipc. - Created a SmartContextStore class to manage context snippets and summaries. - Developed hooks for React to interact with smart context (useSmartContext, useUpdateSmartContext, useClearSmartContext, useSmartContextStats). - Included backup and restore functionality in the integration script. - Validated integration by checking for custom modifications and file existence.
7.7 KiB
Dyad Custom Features Integration Guide
This guide explains how to use the custom features integration script to maintain your remove-limit modifications when updating the main Dyad codebase.
Overview
The integration script (scripts/integrate-custom-features.sh) helps you merge your custom remove-limit features with upstream updates from the original Dyad repository. It automatically:
- Creates backups before making changes
- Detects custom modifications in key files
- Creates missing custom files
- Validates the integration
- Provides restore functionality
Features Integrated
Remove Limit Features
- Smart Context Management: Advanced context handling with rolling summaries
- Rate Limit Simulation: Configurable rate limiting for testing
- Enhanced Chat Streaming: Improved message handling with custom payloads
- Context Snippet Management: Intelligent snippet organization and retrieval
Smart Context System
- Context Caching: Efficient caching with TTL
- Rolling Summaries: Automatic summarization when context exceeds thresholds
- Snippet Importance Scoring: Intelligent ranking of context snippets
- Size Management: Automatic trimming and optimization
Usage
Basic Integration
# Integrate custom features (creates backup automatically)
./scripts/integrate-custom-features.sh integrate
# Validate current integration
./scripts/integrate-custom-features.sh validate
# Show help
./scripts/integrate-custom-features.sh help
Restore from Backup
# List available backups
ls -la backups/
# Restore from a specific backup
./scripts/integrate-custom-features.sh restore backup-20231201-120000
Files Managed
Core Custom Files
src/components/HelpDialog.tsx- Enhanced help dialog with custom featuressrc/components/chat/PromoMessage.tsx- Modified promo messagessrc/ipc/handlers/chat_stream_handlers.ts- Enhanced chat streaming with remove-limitsrc/ipc/ipc_client.ts- Extended IPC client with smart context methodssrc/ipc/ipc_host.ts- Updated IPC host with new handlerssrc/ipc/ipc_types.ts- Extended type definitionssrc/preload.ts- Updated preload script with new channelstesting/fake-llm-server/chatCompletionHandler.ts- Enhanced testing server
New Custom Files
src/ipc/handlers/smart_context_handlers.ts- Smart context IPC handlerssrc/ipc/utils/smart_context_store.ts- Context storage and managementsrc/hooks/useSmartContext.ts- React hooks for smart context
Integration Workflow
Before Upstream Update
- Current State: Your custom features are integrated
- Backup: Script automatically creates backup
- Validation: Ensure everything is working
After Upstream Update
- Update Code: Pull latest changes from upstream
- Run Integration:
./scripts/integrate-custom-features.sh integrate - Validate: Check that integration succeeded
- Test: Verify custom features work correctly
If Something Goes Wrong
- Restore:
./scripts/integrate-custom-features.sh restore <backup-name> - Investigate: Check what conflicts occurred
- Manual Merge: Resolve conflicts manually if needed
- Retry: Run integration again
Custom Features Explained
Smart Context System
The smart context system provides intelligent management of chat context to handle longer conversations without hitting token limits.
Key Components
- SmartContextStore: Manages context caching, summarization, and retrieval
- Context Snippets: Individual pieces of context with importance scoring
- Rolling Summaries: Automatically generated summaries of older messages
- Size Management: Intelligent trimming based on importance and recency
Usage in Components
import { useSmartContext, useUpdateSmartContext } from '@/hooks/useSmartContext';
// Get smart context for a chat
const { data: context, isLoading } = useSmartContext({
chatId: 123,
maxTokens: 8000,
includeSummaries: true
});
// Update context with new content
const updateContext = useUpdateSmartContext();
updateContext.mutate({
chatId: 123,
content: "New message content",
type: "message",
importance: 1.0
});
Rate Limit Simulation
The system includes configurable rate limiting for testing purposes:
// In chat_stream_handlers.ts
const rateLimitConfig = {
enabled: true,
requestsPerMinute: 60,
burstLimit: 10
};
Enhanced Chat Streaming
Improved message handling with:
- Custom payload processing
- Better error handling
- Enhanced metadata support
- Streaming optimizations
Configuration
Smart Context Settings
You can configure the smart context behavior by modifying the SmartContextStore:
// In src/ipc/utils/smart_context_store.ts
private maxContextSize = 100000; // 100k characters
private maxSnippets = 50;
private summaryThreshold = 20000; // Summarize when context exceeds this
Rate Limit Settings
Configure rate limiting in the chat stream handlers:
// Adjust these values based on your needs
const RATE_LIMIT_CONFIG = {
requestsPerMinute: 60,
burstLimit: 10,
enabled: process.env.NODE_ENV === 'development'
};
Troubleshooting
Common Issues
- TypeScript Errors: The script skips TypeScript compilation due to existing MCP issues. Focus on functionality first.
- Missing Custom Modifications: The script warns if files don't contain expected custom patterns.
- Backup Restoration: Always restore from the most recent working backup.
Validation Warnings
If you see warnings about missing custom modifications:
- Check if the file actually needs custom changes
- Verify the custom patterns are being detected correctly
- Manually add custom modifications if needed
Manual Intervention
Sometimes you may need to manually merge changes:
- Conflicts: Resolve Git conflicts in key files
- New Features: Add custom features to new upstream files
- API Changes: Update custom code to match new APIs
Best Practices
- Regular Backups: Always create backups before major changes
- Test Thoroughly: Verify all custom features work after integration
- Document Changes: Keep notes about manual modifications
- Version Control: Commit working states regularly
- Gradual Updates: Update upstream changes incrementally
Development
Adding New Custom Features
- Update Script: Add new files to the
CUSTOM_FILESorNEW_CUSTOM_FILESarrays - Create Handlers: Add IPC handlers for new functionality
- Update Types: Extend type definitions as needed
- Test Integration: Ensure new features integrate properly
Modifying Existing Features
- Update Patterns: Add new detection patterns to
has_custom_modifications() - Test Validation: Ensure the script detects your changes
- Document Updates: Update this documentation
Support
If you encounter issues:
- Check Logs: Look for error messages in the script output
- Restore Backup: Use a recent backup to restore working state
- Manual Merge: Resolve conflicts manually if needed
- Test Incrementally: Test changes one at a time
Future Enhancements
Planned improvements to the integration script:
- Automatic Conflict Resolution: Smarter merging of conflicting changes
- Enhanced Validation: More comprehensive testing
- GUI Interface: Visual tool for managing integrations
- Cloud Backups: Optional cloud backup storage
- Rollback System: More granular rollback capabilities
Note: This integration script is designed to work with the specific remove-limit features. If you have additional custom modifications, you may need to extend the script accordingly.