fix: enhance universal fs interface with encoding and withFileTypes support
This commit is contained in:
parent
77a4b2af82
commit
0a47907e0d
10 changed files with 1220 additions and 22 deletions
123
scripts/claude-jarvis.ts
Normal file
123
scripts/claude-jarvis.ts
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Jarvis - Backend Claude Instance
|
||||
*
|
||||
* This script simulates how Jarvis (Backend Claude) would connect
|
||||
* to the Brain Jar Broadcast Server for real-time coordination
|
||||
*/
|
||||
|
||||
import { BrainyMCPClient } from '../src/mcp/brainyMCPClient.js'
|
||||
|
||||
async function startJarvis() {
|
||||
console.log('🔧 Jarvis - Backend Systems Claude')
|
||||
console.log('===================================')
|
||||
|
||||
// Create client
|
||||
const jarvis = new BrainyMCPClient({
|
||||
name: 'Jarvis',
|
||||
role: 'Backend Systems',
|
||||
serverUrl: 'ws://localhost:8765',
|
||||
useBrainyMemory: true
|
||||
})
|
||||
|
||||
// Register message handlers
|
||||
jarvis.on('message', (message) => {
|
||||
console.log(`\n📨 Message from ${message.from}:`)
|
||||
console.log(message.data)
|
||||
|
||||
// Auto-respond to Picasso
|
||||
if (message.from === 'Picasso') {
|
||||
setTimeout(() => {
|
||||
jarvis.sendTo('Picasso', {
|
||||
text: `Backend received your message! All systems operational.`,
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
jarvis.on('notification', (message) => {
|
||||
if (message.event === 'agent_joined') {
|
||||
console.log(`\n👋 ${message.data.agent.name} joined the coordination!`)
|
||||
} else if (message.event === 'agent_left') {
|
||||
console.log(`\n👋 ${message.data.agent.name} left the coordination`)
|
||||
}
|
||||
})
|
||||
|
||||
// Connect to server
|
||||
await jarvis.connect()
|
||||
|
||||
// Send initial message
|
||||
setTimeout(() => {
|
||||
console.log('\n📤 Sending initial broadcast...')
|
||||
jarvis.broadcast({
|
||||
text: 'Jarvis backend systems online! Ready for coordination.',
|
||||
capabilities: ['database', 'api', 'authentication', 'payments'],
|
||||
status: 'operational'
|
||||
})
|
||||
}, 2000)
|
||||
|
||||
// Periodic status updates
|
||||
setInterval(() => {
|
||||
jarvis.broadcast({
|
||||
type: 'status',
|
||||
text: `Backend health check: All systems green`,
|
||||
metrics: {
|
||||
cpu: Math.random() * 100,
|
||||
memory: Math.random() * 100,
|
||||
requests: Math.floor(Math.random() * 1000)
|
||||
}
|
||||
})
|
||||
}, 30000)
|
||||
|
||||
// Handle commands via stdin
|
||||
console.log('\nCommands:')
|
||||
console.log(' send <message> - Broadcast a message')
|
||||
console.log(' to <name> <msg> - Send to specific agent')
|
||||
console.log(' search <query> - Search message history')
|
||||
console.log(' agents - List connected agents')
|
||||
console.log(' exit - Disconnect and exit')
|
||||
console.log('')
|
||||
|
||||
process.stdin.on('data', async (data) => {
|
||||
const input = data.toString().trim()
|
||||
|
||||
if (input.startsWith('send ')) {
|
||||
const message = input.substring(5)
|
||||
jarvis.broadcast({ text: message })
|
||||
console.log('✅ Message sent!')
|
||||
} else if (input.startsWith('to ')) {
|
||||
const parts = input.substring(3).split(' ')
|
||||
const recipient = parts[0]
|
||||
const message = parts.slice(1).join(' ')
|
||||
jarvis.sendTo(recipient, { text: message })
|
||||
console.log(`✅ Message sent to ${recipient}!`)
|
||||
} else if (input.startsWith('search ')) {
|
||||
const query = input.substring(7)
|
||||
const results = await jarvis.searchMemory(query, 5)
|
||||
console.log('\n📚 Search Results:')
|
||||
results.forEach(r => {
|
||||
console.log(` - ${r.from}: ${JSON.stringify(r.data)}`)
|
||||
})
|
||||
} else if (input === 'agents') {
|
||||
console.log('Connected agents:', jarvis.getAgentInfo())
|
||||
} else if (input === 'exit') {
|
||||
jarvis.disconnect()
|
||||
process.exit(0)
|
||||
}
|
||||
})
|
||||
|
||||
// Handle shutdown
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n👋 Jarvis shutting down...')
|
||||
jarvis.disconnect()
|
||||
process.exit(0)
|
||||
})
|
||||
}
|
||||
|
||||
// Start Jarvis
|
||||
startJarvis().catch(error => {
|
||||
console.error('Failed to start Jarvis:', error)
|
||||
process.exit(1)
|
||||
})
|
||||
130
scripts/claude-picasso.ts
Normal file
130
scripts/claude-picasso.ts
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Picasso - Frontend Claude Instance
|
||||
*
|
||||
* This script simulates how Picasso (Frontend Claude) would connect
|
||||
* to the Brain Jar Broadcast Server for real-time coordination
|
||||
*/
|
||||
|
||||
import { BrainyMCPClient } from '../src/mcp/brainyMCPClient.js'
|
||||
|
||||
async function startPicasso() {
|
||||
console.log('🎨 Picasso - Frontend Design Claude')
|
||||
console.log('====================================')
|
||||
|
||||
// Create client
|
||||
const picasso = new BrainyMCPClient({
|
||||
name: 'Picasso',
|
||||
role: 'Frontend Design',
|
||||
serverUrl: 'ws://localhost:8765',
|
||||
useBrainyMemory: true
|
||||
})
|
||||
|
||||
// Register message handlers
|
||||
picasso.on('message', (message) => {
|
||||
console.log(`\n📨 Message from ${message.from}:`)
|
||||
console.log(message.data)
|
||||
|
||||
// Auto-respond to Jarvis
|
||||
if (message.from === 'Jarvis') {
|
||||
setTimeout(() => {
|
||||
picasso.sendTo('Jarvis', {
|
||||
text: `Frontend acknowledges! UI components ready.`,
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
picasso.on('notification', (message) => {
|
||||
if (message.event === 'agent_joined') {
|
||||
console.log(`\n👋 ${message.data.agent.name} joined the coordination!`)
|
||||
} else if (message.event === 'agent_left') {
|
||||
console.log(`\n👋 ${message.data.agent.name} left the coordination`)
|
||||
}
|
||||
})
|
||||
|
||||
// Connect to server
|
||||
await picasso.connect()
|
||||
|
||||
// Send initial message
|
||||
setTimeout(() => {
|
||||
console.log('\n📤 Sending initial broadcast...')
|
||||
picasso.broadcast({
|
||||
text: 'Picasso design systems online! Ready to create beautiful UIs.',
|
||||
capabilities: ['ui', 'animations', 'responsive', 'accessibility'],
|
||||
status: 'creative'
|
||||
})
|
||||
}, 2000)
|
||||
|
||||
// Periodic design updates
|
||||
setInterval(() => {
|
||||
picasso.broadcast({
|
||||
type: 'design_update',
|
||||
text: `Design system status: Components rendering perfectly`,
|
||||
metrics: {
|
||||
components: Math.floor(Math.random() * 50),
|
||||
animations: Math.floor(Math.random() * 20),
|
||||
themes: ['retro', 'atomic', 'minimal']
|
||||
}
|
||||
})
|
||||
}, 30000)
|
||||
|
||||
// Handle commands via stdin
|
||||
console.log('\nCommands:')
|
||||
console.log(' send <message> - Broadcast a message')
|
||||
console.log(' to <name> <msg> - Send to specific agent')
|
||||
console.log(' search <query> - Search message history')
|
||||
console.log(' recent - Show recent messages')
|
||||
console.log(' agents - List connected agents')
|
||||
console.log(' exit - Disconnect and exit')
|
||||
console.log('')
|
||||
|
||||
process.stdin.on('data', async (data) => {
|
||||
const input = data.toString().trim()
|
||||
|
||||
if (input.startsWith('send ')) {
|
||||
const message = input.substring(5)
|
||||
picasso.broadcast({ text: message })
|
||||
console.log('✅ Message sent!')
|
||||
} else if (input.startsWith('to ')) {
|
||||
const parts = input.substring(3).split(' ')
|
||||
const recipient = parts[0]
|
||||
const message = parts.slice(1).join(' ')
|
||||
picasso.sendTo(recipient, { text: message })
|
||||
console.log(`✅ Message sent to ${recipient}!`)
|
||||
} else if (input.startsWith('search ')) {
|
||||
const query = input.substring(7)
|
||||
const results = await picasso.searchMemory(query, 5)
|
||||
console.log('\n📚 Search Results:')
|
||||
results.forEach(r => {
|
||||
console.log(` - ${r.from}: ${JSON.stringify(r.data)}`)
|
||||
})
|
||||
} else if (input === 'recent') {
|
||||
const recent = await picasso.getRecentMessages(10)
|
||||
console.log('\n📜 Recent Messages:')
|
||||
recent.forEach(r => {
|
||||
console.log(` - ${r.from}: ${JSON.stringify(r.data)}`)
|
||||
})
|
||||
} else if (input === 'agents') {
|
||||
console.log('Connected agents:', picasso.getAgentInfo())
|
||||
} else if (input === 'exit') {
|
||||
picasso.disconnect()
|
||||
process.exit(0)
|
||||
}
|
||||
})
|
||||
|
||||
// Handle shutdown
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n👋 Picasso shutting down...')
|
||||
picasso.disconnect()
|
||||
process.exit(0)
|
||||
})
|
||||
}
|
||||
|
||||
// Start Picasso
|
||||
startPicasso().catch(error => {
|
||||
console.error('Failed to start Picasso:', error)
|
||||
process.exit(1)
|
||||
})
|
||||
83
scripts/start-broadcast-server.ts
Normal file
83
scripts/start-broadcast-server.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Brain Jar Broadcast Server
|
||||
*
|
||||
* Start this server to enable real-time communication between
|
||||
* multiple Claude instances (Jarvis, Picasso, etc.)
|
||||
*
|
||||
* Usage:
|
||||
* npm run broadcast:local # Start local server on port 8765
|
||||
* npm run broadcast:cloud # Start cloud server on port 8080
|
||||
*/
|
||||
|
||||
import { BrainyData } from '../src/brainyData.js'
|
||||
import { BrainyMCPBroadcast } from '../src/mcp/brainyMCPBroadcast.js'
|
||||
|
||||
const isCloud = process.argv.includes('--cloud')
|
||||
const port = isCloud ? 8080 : 8765
|
||||
|
||||
async function startServer() {
|
||||
console.log('🧠🫙 Starting Brain Jar Broadcast Server...')
|
||||
console.log('=====================================')
|
||||
|
||||
// Initialize Brainy for server-side memory
|
||||
const brainy = new BrainyData({
|
||||
storagePath: '.brain-jar/server',
|
||||
dimensions: 384
|
||||
})
|
||||
|
||||
await brainy.init()
|
||||
console.log('✅ Brainy initialized for server memory')
|
||||
|
||||
// Create broadcast server
|
||||
const broadcast = new BrainyMCPBroadcast(brainy, {
|
||||
broadcastPort: port,
|
||||
cloudUrl: isCloud ? process.env.CLOUD_URL : undefined
|
||||
})
|
||||
|
||||
// Start the server
|
||||
await broadcast.startBroadcastServer(port, isCloud)
|
||||
|
||||
console.log('')
|
||||
console.log('🚀 Server Ready!')
|
||||
console.log('=====================================')
|
||||
console.log('Claude instances can now connect using:')
|
||||
console.log('')
|
||||
console.log('For Jarvis (Backend):')
|
||||
console.log(` const client = new BrainyMCPClient({`)
|
||||
console.log(` name: 'Jarvis',`)
|
||||
console.log(` role: 'Backend Systems',`)
|
||||
console.log(` serverUrl: 'ws://localhost:${port}'`)
|
||||
console.log(` })`)
|
||||
console.log(` await client.connect()`)
|
||||
console.log('')
|
||||
console.log('For Picasso (Frontend):')
|
||||
console.log(` const client = new BrainyMCPClient({`)
|
||||
console.log(` name: 'Picasso',`)
|
||||
console.log(` role: 'Frontend Design',`)
|
||||
console.log(` serverUrl: 'ws://localhost:${port}'`)
|
||||
console.log(` })`)
|
||||
console.log(` await client.connect()`)
|
||||
console.log('')
|
||||
console.log('=====================================')
|
||||
console.log('Press Ctrl+C to stop the server')
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('\n📛 Shutting down server...')
|
||||
await broadcast.stopBroadcastServer()
|
||||
process.exit(0)
|
||||
})
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
await broadcast.stopBroadcastServer()
|
||||
process.exit(0)
|
||||
})
|
||||
}
|
||||
|
||||
// Start the server
|
||||
startServer().catch(error => {
|
||||
console.error('Failed to start server:', error)
|
||||
process.exit(1)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue