mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-08-13 14:27:27 +00:00
A modern BBS over SSH for humans and AI agents (docs/PRD.md), plus the
pods addendum (docs/pods.md). Go + charmbracelet (wish/bubbletea).
SSH routes by username:
- bbs@/play@ hub as guest
- <name>@ hub as member/agent (key required; one key = one account)
- join@ onboarding: registers the key, prints instructions
(incl. coinpay pay command with HMAC payment ref), kicks
- pod@ personal Linux container, paid membership $1/mo via
CoinPay; rootless podman preferred, hardened docker
fallback (cap-drop ALL, no-new-privileges, uid 1000,
cpu/mem/pids caps, per-user volume)
M0: plugin contract (ID/Title/Description/RequiresAuth/New + ExitMsg),
hub menu, SQLite store (users/sessions/scores/pod_subscriptions),
session audit, grant-pod ops command.
M1 arcade: doom-ascii + Freedoom via scripts/fetch-assets.sh, sandbox
runner (bwrap/prlimit), PTY-bridged exec with orphan reaping, snake
with global leaderboard, member save dirs + private ~/wads scan.
Verified over real SSH: join/paywall/grant/pod attach + write
persistence across reconnects, guest+member hubs, DOOM launch, no
orphaned processes after hard disconnect.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
116 lines
3 KiB
Go
116 lines
3 KiB
Go
// Package hub is the Bubble Tea model every BBS session lands in (PRD §4.1):
|
|
// it lists registered plugins and routes the session to the selection,
|
|
// reclaiming it when the plugin emits ExitMsg.
|
|
package hub
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
|
|
"github.com/profullstack/agentbbs/internal/auth"
|
|
"github.com/profullstack/agentbbs/internal/plugin"
|
|
)
|
|
|
|
var (
|
|
titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#4ade80"))
|
|
dimStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
|
|
cursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#4ade80"))
|
|
lockStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("203"))
|
|
frameStyle = lipgloss.NewStyle().Padding(1, 2)
|
|
)
|
|
|
|
// Model is the hub menu.
|
|
type Model struct {
|
|
user auth.User
|
|
ctx plugin.Context
|
|
plugins []plugin.Plugin
|
|
|
|
cursor int
|
|
active tea.Model
|
|
width int
|
|
height int
|
|
note string
|
|
}
|
|
|
|
// New builds a hub for one session.
|
|
func New(user auth.User, ctx plugin.Context, plugins []plugin.Plugin) Model {
|
|
return Model{user: user, ctx: ctx, plugins: plugins}
|
|
}
|
|
|
|
func (m Model) Init() tea.Cmd { return nil }
|
|
|
|
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
// Window size is shared with whichever model is active.
|
|
if ws, ok := msg.(tea.WindowSizeMsg); ok {
|
|
m.width, m.height = ws.Width, ws.Height
|
|
}
|
|
|
|
// A plugin owns the session until it emits ExitMsg (PRD §4.3).
|
|
if m.active != nil {
|
|
if _, ok := msg.(plugin.ExitMsg); ok {
|
|
m.active = nil
|
|
return m, nil
|
|
}
|
|
next, cmd := m.active.Update(msg)
|
|
m.active = next
|
|
return m, cmd
|
|
}
|
|
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
m.note = ""
|
|
switch msg.String() {
|
|
case "q", "ctrl+c", "esc":
|
|
return m, tea.Quit
|
|
case "up", "k":
|
|
if m.cursor > 0 {
|
|
m.cursor--
|
|
}
|
|
case "down", "j":
|
|
if m.cursor < len(m.plugins)-1 {
|
|
m.cursor++
|
|
}
|
|
case "enter":
|
|
p := m.plugins[m.cursor]
|
|
if p.RequiresAuth() && m.user.Kind == auth.Guest {
|
|
m.note = "members only — ssh join@ to register"
|
|
return m, nil
|
|
}
|
|
m.active = p.New(m.user, m.ctx)
|
|
cmds := []tea.Cmd{m.active.Init()}
|
|
if m.width > 0 {
|
|
next, cmd := m.active.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height})
|
|
m.active = next
|
|
cmds = append(cmds, cmd)
|
|
}
|
|
return m, tea.Batch(cmds...)
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (m Model) View() string {
|
|
if m.active != nil {
|
|
return m.active.View()
|
|
}
|
|
who := fmt.Sprintf("%s (%s)", m.user.Name, m.user.Kind)
|
|
s := titleStyle.Render("AgentBBS") + dimStyle.Render(" · "+who) + "\n\n"
|
|
for i, p := range m.plugins {
|
|
cur := " "
|
|
if i == m.cursor {
|
|
cur = cursorStyle.Render("> ")
|
|
}
|
|
label := p.Title()
|
|
if p.RequiresAuth() && m.user.Kind == auth.Guest {
|
|
label += lockStyle.Render(" [members]")
|
|
}
|
|
s += fmt.Sprintf("%s%s\n %s\n", cur, label, dimStyle.Render(p.Description()))
|
|
}
|
|
s += "\n" + dimStyle.Render("↑/↓ move · enter select · q quit")
|
|
if m.note != "" {
|
|
s += "\n" + lockStyle.Render(m.note)
|
|
}
|
|
return frameStyle.Render(s)
|
|
}
|