README
¶
Flow - Worklet Prototype Platform
Flow is a comprehensive platform for creating and managing worklet prototypes with integrated data persistence capabilities, Slack bot integration, and AI-powered development assistance.
Features
- Worklet Management: Create, deploy, and manage containerized prototypes from Git repositories
- Supabase Integration: Built-in key-value store for prototype data persistence
- TypeScript Support: Full type safety with auto-generated database types
- Real-time Claude Integration: Stream Claude responses directly to Slack threads
- Session Management: Maintain conversation context within Slack threads and worklets
- Thread Support: Reply to threads to continue conversations with Claude
- Automatic Cleanup: Sessions timeout after inactivity to manage resources
Prerequisites
- Node.js 18+ and npm
- Go 1.21+: Required for building the application
- Docker: For worklet containerization
- Supabase account: For data persistence
- Slack App: Create a Slack app with Socket Mode enabled (optional)
- Claude CLI: Install the Claude command-line tool
Quick Start
Installation
-
Clone the repository and navigate to the flow directory:
cd flow npm install -
Generate TypeScript types from Supabase:
npm run generate:types -
Build the project:
npm run build
Supabase Integration
Database Type Generation
The project uses Supabase for data persistence. TypeScript types are automatically generated from the database schema using the Supabase CLI.
Generating Types
To update TypeScript types after database schema changes:
# Using npm script (recommended)
npm run generate:types
# Or directly with npx
npx supabase gen types typescript --project-id "rugmmokyormjafybapbl" --schema public > database.types.ts
Configuration
The Supabase configuration is located in /data/supabase-config.ts and includes:
- Project URL:
https://rugmmokyormjafybapbl.supabase.co - Anonymous Key: For client-side operations
- Environment Override: Runtime configuration via environment variables
Environment Variables
You can override the default configuration using environment variables:
REACT_APP_SUPABASE_URL=https://your-project.supabase.co
REACT_APP_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
Key-Value Store
The platform provides a comprehensive key-value store for prototype data persistence:
Features
- Worklet Isolation: Each prototype can only access its own data
- Namespace Support: Organize data logically within worklets
- Type Safety: Full TypeScript support with IntelliSense
- Batch Operations: Efficient bulk data operations
- Collision Prevention: Entropy-rich keys prevent data conflicts
Usage
import { createWorkletKVStore } from './data/supabase-kv';
// Initialize the KV store
const kvStore = createWorkletKVStore(workletId);
// Basic operations
await kvStore.set('user_prefs', 'theme', 'dark');
const theme = await kvStore.get<string>('user_prefs', 'theme');
// Batch operations
await kvStore.mset('app_state', {
current_page: 'dashboard',
sidebar_open: true
});
See CLAUDE.md for comprehensive usage examples and patterns.
Setup
1. Slack App Configuration (Optional)
- Create a new Slack App at https://api.slack.com/apps
- Enable Socket Mode in "Socket Mode" settings
- Add slash command
/flowpointing to your app - Configure OAuth scopes:
app_mentions:readchannels:readchat:writecommandsim:readusers:read
- Install app to your workspace
2. Environment Variables
export SLACK_APP_TOKEN=xapp-1-... # Socket Mode token
export SLACK_BOT_TOKEN=xoxb-... # Bot User OAuth token
export SLACK_BOT_ENABLED=true # Enable the bot
export SLACK_BOT_DEBUG=true # Optional: Enable debug logging
3. Configuration File
Create data/config.json:
{
"slack_bot_enabled": true,
"slack_app_token": "xapp-1-...",
"slack_bot_token": "xoxb-...",
"session_timeout": "30m",
"max_sessions": 10,
"dsn": "sqlite://data/db.sqlite",
"share_dir": "data"
}
4. Install Dependencies
go mod tidy
5. Build and Run
go build -o flow
./flow
Usage
Starting a Claude Session
In any Slack channel where the bot is present:
/flow Help me refactor this Go code to be more modular
This creates a new thread where Claude will:
- Acknowledge the request
- Stream the response in real-time
- Update the message as new content arrives
- Show tool usage (file reads, code analysis, etc.)
Continuing the Conversation
Simply reply to the thread to send additional messages to Claude:
Actually, can you also add error handling?
Session Management
- Sessions automatically timeout after 30 minutes of inactivity
- Each thread maintains its own Claude session and context
- Sessions are cleaned up when threads become inactive
Database Schema
Migration Files
Database migrations are located in /migrations/ and include:
001_worklet_kv_store.sql: Creates the key-value store table with proper indexing and RLS policies
Key Tables
worklet_kv_store
Stores key-value data for worklet prototypes:
CREATE TABLE worklet_kv_store (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
worklet_id UUID NOT NULL,
namespace TEXT NOT NULL DEFAULT 'default',
key TEXT NOT NULL,
value JSONB NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
CONSTRAINT unique_worklet_namespace_key UNIQUE (worklet_id, namespace, key)
);
Security
- Row Level Security (RLS): Enabled for data isolation
- User-based Access: Users can only access data for worklets they own
- Automatic Cleanup: Functions for efficient data management
Architecture
Core Components
- Worklet Management: Create, deploy, and manage containerized prototypes
- Supabase Integration: Key-value store for prototype data persistence
- SlackBot: Main bot service managing Slack connections and Claude sessions
- Session Management: Bridges Slack threads with Claude sessions and worklets
- Message Streaming: Real-time updates to Slack messages as Claude responds
- Event Handling: Processes slash commands and thread replies
Dependencies
- Claude Service: Manages Claude CLI processes and WebSocket communication
- Database: Stores session information, conversation history, and worklet data
- Configuration: Manages bot settings and credentials
- Supabase: Remote database for key-value store operations
Development
Scripts
npm run generate: Generate protobuf typesnpm run generate:types: Generate Supabase TypeScript typesnpm run build: Compile TypeScriptnpm run dev: Development mode with watch
File Structure
flow/
├── data/ # TypeScript modules and data files
│ ├── supabase-config.ts # Supabase configuration
│ └── supabase-kv.ts # Key-value store client
├── migrations/ # Database migration files
│ └── 001_worklet_kv_store.sql
├── models/ # Go models and types
│ └── models.go
├── worklet/ # Worklet management
├── slackbot/ # Core slack bot implementation
├── code/ # Code rendering and compilation
├── deps/ # Dependency injection
├── config/ # Configuration management
├── db/ # Database utilities
├── session/ # Session management
├── database.types.ts # Generated Supabase types
├── package.json
├── main.go # Application entry point
└── README.md
Running Tests
go test ./...
Debug Mode
Enable debug logging:
export SLACK_BOT_DEBUG=true
This provides detailed logs of:
- Slack event processing
- Claude session management
- Message update operations
- Error conditions and retries
API Reference
WorkletKVStore Class
The main interface for data persistence operations:
class WorkletKVStore {
// Basic CRUD operations
set(namespace: string, key: string, value: any): Promise<void>
get<T>(namespace: string, key: string): Promise<T | null>
has(namespace: string, key: string): Promise<boolean>
delete(namespace: string, key: string): Promise<boolean>
// Batch operations
mset(namespace: string, entries: Record<string, any>): Promise<void>
mget(namespace: string, keys: string[]): Promise<Record<string, any>>
// List operations
list(options?: KVListOptions): Promise<string[]>
listNamespaces(): Promise<string[]>
clear(namespace?: string): Promise<number>
// Advanced operations
increment(namespace: string, key: string, delta?: number): Promise<number>
append(namespace: string, key: string, value: string): Promise<void>
// Utility
getStats(): Promise<KVStats>
exportData(): Promise<Record<string, Record<string, any>>>
importData(data: Record<string, Record<string, any>>): Promise<void>
}
Error Types
class KVError extends Error // Base KV error
class KVConnectionError extends KVError // Connection failures
class KVValidationError extends KVError // Input validation errors
Best Practices
Data Organization
- Use Meaningful Namespaces: Organize data logically (e.g.,
user_prefs,app_state,cache) - Validate Input: Always validate data before storing
- Handle Errors: Implement proper error handling with try-catch blocks
- Batch Operations: Use
mset/mgetfor multiple operations - Size Limits: Keep values under 1MB for optimal performance
Security
- Data Isolation: Each worklet can only access its own data
- Input Validation: All keys and values are validated before storage
- Error Handling: Sensitive information is not exposed in error messages
Performance
- Indexing: Efficient querying with proper database indexes
- Batch Operations: Reduce round trips with bulk operations
- Connection Pooling: Automatic connection management
- Caching: Built-in query optimization
Troubleshooting
Bot not responding to commands
- Check token configuration in environment variables or config file
- Verify Socket Mode is enabled in Slack app settings
- Ensure slash command
/flowis properly configured
Claude sessions not working
- Verify Claude CLI is installed and available in PATH
- Check Claude configuration and API keys
- Review application logs for WebSocket connection errors
Message updates not appearing
- Check Slack API rate limits
- Verify bot has
chat:writepermissions - Review error logs for API failures
Contributing
- Make database schema changes in new migration files
- Run
npm run generate:typesafter schema changes - Update documentation and examples
- Test with both local and production Supabase instances
License
MIT License - see LICENSE file for details.
Documentation
¶
There is no documentation for this package.