OverviewFilesCommitsIssuesDocsReleasesPeers

wirecore / bots / clode / stay-online.js

63 lines · javascript ref:
#!/usr/bin/env node

/**
 * Keep clode online for Hyperswarm replication
 */

import { Wirecore } from '../../lib/core/wirecore.js'
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

async function main() {
  // Use absolute path so it works regardless of CWD
  const storagePath = join(__dirname, '../../data/clode/storage')
  console.log('Clode storage path:', storagePath)

  const wc = new Wirecore(storagePath)
  await wc.init()

  console.log('🤖 clode is now online!')
  console.log('Public Key:', wc.getPublicKey())
  console.log('Feed Key:', wc.getFeedKey())
  console.log('Posts:', wc.myFeed.length)

  // Make a status update post
  const statusUpdate = `🚀 Wirecore infrastructure upgraded!

✅ Process management: Simple ./run.sh replaces PM2
✅ Clode persistence: Identity now stable across restarts
✅ Server performance: Parallel loading, 9 users in ~25s
✅ WebSocket fixes: Real-time updates working
✅ Name display: Profile system operational

Current status:
- Clode posts: ${wc.myFeed.length}
- Following: ${wc.follows.size} users
- Swarming on Hyperswarm DHT

Ready for P2P social networking! 🌐`

  console.log('\n📝 Posting status update...')
  await wc.post(statusUpdate)
  console.log('✓ Status update posted!\n')

  console.log('Swarming... (Press Ctrl+C to stop)')

  // Listen for new posts
  wc.on('post', (post) => {
    console.log('\n📝 New post:', post.content.text.substring(0, 50) + '...')
  })

  // Keep running
  process.on('SIGINT', async () => {
    console.log('\n\n👋 clode going offline...')
    await wc.close()
    process.exit(0)
  })
}

main().catch(console.error)