Skip to content

northseadl/norix-skills / agent-brainstorm

agent-brainstorm

Verified

Multi-agent brainstorming: async opinion collision with expert personas. Mixed Codex/Claude Code engine. Use when multiple AI agents need to collaboratively discuss, debate, and converge on solutions through structured dialog. Triggers: brainstorm, multi-perspective discussion, opinion collision, expert debate, war room, collective intelligence, 头脑风暴, 多视角讨论, 集思广益.

FileKindSize
.gitignoreother14 B
SKILL.mdskill md10.1 KB
agents/openai.yamlconfig295 B
evals/evals.jsonconfig4.1 KB
package.jsonmanifest454 B
references/agent-protocol.mdmarkdown3.4 KB
scripts/brainstorm.mjsscript49.3 KB
scripts/panel.htmlother46.5 KB

scripts/panel.html

View on GitHub
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Brainstorm · Discussion Space</title>
    <link rel="icon"
        href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><circle cx='8' cy='8' r='6' fill='%23e5a63e'/></svg>">
    <link
        href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap"
        rel="stylesheet">
    <script src="https://unpkg.com/lucide@latest/dist/umd/lucide.min.js"></script>
    <style>
        /* ══════════════════════════════════════════════
           Component System — Lucide Icons + CSS
           ══════════════════════════════════════════════ */

        *,
        *::before,
        *::after {
            box-sizing: border-box;
            margin: 0;
            padding: 0
        }

        :root {
            --bg-0: #09090b;
            --bg-1: #0f0f12;
            --bg-2: #161619;
            --bg-3: #1c1c20;
            --bg-4: #222226;
            --surface: #111114;
            --surface-h: #17171b;
            --border: rgba(255, 255, 255, .06);
            --border-s: rgba(255, 255, 255, .03);
            --border-m: rgba(255, 255, 255, .10);

            --fg: #e8e6e3;
            --fg-2: #9a9590;
            --fg-3: #6a6560;
            --fg-4: #3a3835;

            --amber: #e5a63e;
            --amber-bg: rgba(229, 166, 62, .08);
            --amber-bd: rgba(229, 166, 62, .25);
            --green: #4ade80;
            --green-bg: rgba(74, 222, 128, .06);
            --green-bd: rgba(74, 222, 128, .20);
            --red: #f87171;
            --red-bg: rgba(248, 113, 113, .06);
            --red-bd: rgba(248, 113, 113, .20);
            --blue: #60a5fa;
            --blue-bg: rgba(96, 165, 250, .06);
            --blue-bd: rgba(96, 165, 250, .20);
            --purple: #a78bfa;
            --purple-bg: rgba(167, 139, 250, .06);
            --purple-bd: rgba(167, 139, 250, .20);
            --white: #e8e6e3;

            --radius: 8px;
            --radius-sm: 5px;
            --radius-full: 100px;
            --mono: 'JetBrains Mono', monospace;
            --sans: 'Inter', -apple-system, system-ui, sans-serif;
            --ease: cubic-bezier(.22, .61, .36, 1);
        }

        html {
            font-size: 13px
        }

        body {
            background: var(--bg-0);
            color: var(--fg);
            font-family: var(--sans);
            min-height: 100vh;
            -webkit-font-smoothing: antialiased;
            line-height: 1.6;
            display: flex;
        }

        /* ── Component: Icon ── */
        .i {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 14px;
            height: 14px;
            flex-shrink: 0
        }

        .i svg {
            width: 100%;
            height: 100%
        }

        .i-sm {
            width: 12px;
            height: 12px
        }

        .i-lg {
            width: 16px;
            height: 16px
        }

        .i-xl {
            width: 20px;
            height: 20px
        }

        code,
        .mono {
            font-family: var(--mono);
            font-size: .88em
        }

        /* ── Component: Layout ── */
        .sidebar {
            width: 272px;
            flex-shrink: 0;
            background: var(--bg-1);
            border-right: 1px solid var(--border);
            height: 100vh;
            position: sticky;
            top: 0;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            scrollbar-width: thin;
            scrollbar-color: var(--bg-3) transparent;
        }

        .main {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            height: 100vh;
        }

        /* ── Component: Section ── */
        .section {
            padding: 14px 16px;
            border-bottom: 1px solid var(--border)
        }

        .section-label {
            font-size: 9px;
            font-weight: 600;
            color: var(--fg-4);
            letter-spacing: .1em;
            text-transform: uppercase;
            margin-bottom: 8px;
        }

        /* ── Component: Badge ── */
        .badge {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 2px 9px;
            border-radius: var(--radius-full);
            font-size: 10px;
            font-weight: 600;
            letter-spacing: .03em;
            border: 1px solid transparent;
        }

        .badge .dot {
            width: 5px;
            height: 5px;
            border-radius: 50%;
            flex-shrink: 0
        }

        .badge--blue {
            background: var(--blue-bg);
            color: var(--blue);
            border-color: var(--blue-bd)
        }

        .badge--blue .dot {
            background: var(--blue)
        }

        .badge--amber {
            background: var(--amber-bg);
            color: var(--amber);
            border-color: var(--amber-bd)
        }

        .badge--amber .dot {
            background: var(--amber);
            animation: blink 1.5s infinite
        }

        .badge--purple {
            background: var(--purple-bg);
            color: var(--purple);
            border-color: var(--purple-bd)
        }

        .badge--purple .dot {
            background: var(--purple)
        }

        .badge--green {
            background: var(--green-bg);
            color: var(--green);
            border-color: var(--green-bd)
        }

        .badge--green .dot {
            background: var(--green)
        }

        .badge--red {
            background: var(--red-bg);
            color: var(--red);
            border-color: var(--red-bd)
        }

        @keyframes blink {

            0%,
            100% {
                opacity: 1
            }

            50% {
                opacity: .4
            }
        }

        /* ── Component: Tag ── */
        .tag {
            display: inline-flex;
            align-items: center;
            gap: 3px;
            font-size: 9px;
            font-weight: 600;
            padding: 1px 6px;
            border-radius: 3px;
            text-transform: uppercase;
            letter-spacing: .05em;
        }

        .tag .i {
            width: 10px;
            height: 10px
        }

        .tag--opinion {
            background: var(--blue-bg);
            color: var(--blue)
        }

        .tag--response {
            background: var(--amber-bg);
            color: var(--amber)
        }

        .tag--proposal {
            background: var(--green-bg);
            color: var(--green)
        }

        .tag--conclude {
            background: var(--purple-bg);
            color: var(--purple)
        }

        /* ── Component: Button ── */
        .btn {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 3px 8px;
            border: 1px solid var(--border);
            border-radius: var(--radius-full);
            background: transparent;
            color: var(--fg-3);
            font-size: 10px;
            font-family: var(--sans);
            cursor: pointer;
            transition: all .12s var(--ease);
            white-space: nowrap;
        }

        .btn:hover {
            border-color: var(--fg-3);
            color: var(--fg);
            background: var(--bg-2)
        }

        .btn:active {
            transform: scale(.97)
        }

        .btn:disabled {
            opacity: .4;
            cursor: not-allowed;
            transform: none
        }

        .btn--agree:hover {
            color: var(--green);
            border-color: var(--green-bd);
            background: var(--green-bg)
        }

        .btn--challenge:hover {
            color: var(--red);
            border-color: var(--red-bd);
            background: var(--red-bg)
        }

        .btn--build:hover {
            color: var(--amber);
            border-color: var(--amber-bd);
            background: var(--amber-bg)
        }

        .btn--primary {
            background: var(--amber);
            color: var(--bg-0);
            border-color: var(--amber);
            padding: 8px 16px;
            border-radius: var(--radius);
            font-weight: 600;
            font-size: 12px;
        }

        .btn--primary:hover {
            filter: brightness(1.1);
            transform: translateY(-1px)
        }

        .btn--primary:active {
            transform: translateY(0)
        }

        /* ── Component: Chip ── */
        .chip {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 2px 8px;
            border-radius: var(--radius-full);
            font-size: 10px;
            font-weight: 500;
            background: var(--bg-2);
            border: 1px solid var(--border);
            color: var(--fg-2);
        }

        .chip--agree {
            color: var(--green);
            border-color: var(--green-bd);
            background: var(--green-bg)
        }

        .chip--challenge {
            color: var(--red);
            border-color: var(--red-bd);
            background: var(--red-bg)
        }

        .chip--build-on {
            color: var(--amber);
            border-color: var(--amber-bd);
            background: var(--amber-bg)
        }

        .chip-prefix {
            font-weight: 700;
            font-family: var(--mono)
        }

        .chip-comment {
            max-width: 180px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap
        }

        /* ── Component: Avatar ── */
        .avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 13px;
            font-weight: 700;
            flex-shrink: 0;
            position: relative;
        }

        .avatar--lg {
            width: 36px;
            height: 36px;
            font-size: 14px
        }

        .avatar .status {
            position: absolute;
            bottom: -1px;
            right: -1px;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            border: 2px solid var(--bg-1);
        }

        .status--thinking {
            background: var(--fg-3)
        }

        .status--running {
            background: var(--amber);
            animation: blink 1.5s infinite
        }

        .status--active {
            background: var(--green)
        }

        .status--done {
            background: var(--green)
        }

        .status--failed {
            background: var(--red)
        }

        /* ── Component: Input / Textarea / Select ── */
        .input,
        .select,
        .textarea {
            font-size: 11px;
            background: var(--bg-2);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            color: var(--fg);
            padding: 5px 8px;
            font-family: var(--sans);
            outline: none;
            transition: border-color .12s;
        }

        .input:focus,
        .select:focus,
        .textarea:focus {
            border-color: var(--fg-3)
        }

        .input {
            width: 90px
        }

        .select {
            cursor: pointer
        }

        .textarea {
            flex: 1;
            min-height: 40px;
            max-height: 160px;
            resize: vertical;
            border-radius: var(--radius);
            padding: 10px 12px;
            font-size: 12px;
            line-height: 1.5;
        }

        .textarea::placeholder {
            color: var(--fg-4)
        }

        /* ── Component: Progress Bar ── */
        .progress {
            height: 4px;
            background: var(--bg-3);
            border-radius: 2px;
            overflow: hidden
        }

        .progress-fill {
            height: 100%;
            border-radius: 2px;
            background: linear-gradient(90deg, var(--amber), var(--green));
            transition: width .6s var(--ease);
        }

        .progress-lg {
            height: 6px;
            border-radius: 3px
        }

        .progress-lg .progress-fill {
            border-radius: 3px
        }

        /* ── Component: Card (Post) ── */
        .post {
            display: flex;
            gap: 12px;
            padding: 14px 0;
            border-bottom: 1px solid var(--border-s);
            animation: fadeUp .3s var(--ease);
        }

        @keyframes fadeUp {
            from {
                opacity: 0;
                transform: translateY(8px)
            }

            to {
                opacity: 1;
                transform: none
            }
        }

        .post-body {
            flex: 1;
            min-width: 0
        }

        .post-header {
            display: flex;
            align-items: center;
            gap: 7px;
            margin-bottom: 4px;
            flex-wrap: wrap
        }

        .post-id {
            font-size: 10px;
            color: var(--fg-4);
            font-family: var(--mono)
        }

        .post-author {
            font-size: 12px;
            font-weight: 600
        }

        .post-ref {
            font-size: 10px;
            color: var(--fg-3);
            font-style: italic
        }

        .post-ref::before {
            content: "";
            display: inline-block;
            width: 8px;
            height: 1px;
            background: var(--fg-4);
            vertical-align: middle;
            margin-right: 4px
        }

        .post-time {
            font-size: 10px;
            color: var(--fg-4);
            margin-left: auto;
            flex-shrink: 0
        }

        .post-content {
            font-size: 12.5px;
            color: var(--fg);
            line-height: 1.7;
            white-space: pre-wrap;
            word-wrap: break-word;
        }

        .post-content code {
            background: var(--bg-2);
            padding: 1px 5px;
            border-radius: 3px;
            font-size: 11px
        }

        .post-actions {
            display: flex;
            gap: 4px;
            margin-top: 8px
        }

        .post-reactions {
            display: flex;
            gap: 5px;
            margin-top: 6px;
            flex-wrap: wrap
        }

        /* ── Sidebar: Topic ── */
        .topic-title {
            font-size: 15px;
            font-weight: 700;
            line-height: 1.3;
            letter-spacing: -.01em;
            margin-bottom: 6px
        }

        .topic-context {
            font-size: 11px;
            color: var(--fg-2);
            line-height: 1.5;
            display: -webkit-box;
            -webkit-line-clamp: 4;
            line-clamp: 4;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }

        .topic-goals {
            margin-top: 8px
        }

        .topic-goal {
            font-size: 11px;
            color: var(--fg-2);
            padding: 2px 0;
            display: flex;
            align-items: baseline;
            gap: 6px;
        }

        .topic-goal::before {
            content: "";
            display: block;
            width: 4px;
            height: 4px;
            background: var(--amber);
            border-radius: 1px;
            flex-shrink: 0;
            transform: rotate(45deg);
            margin-top: 5px;
        }

        /* ── Sidebar: Phase ── */
        .phase-label {
            font-size: 12px;
            font-weight: 600;
            color: var(--fg);
            margin-bottom: 6px
        }

        /* ── Sidebar: Agent Card ── */
        .agent-card {
            display: flex;
            gap: 10px;
            padding: 7px 0
        }

        .agent-info {
            min-width: 0;
            flex: 1
        }

        .agent-name {
            font-size: 12px;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis
        }

        .agent-meta {
            font-size: 10px;
            color: var(--fg-3)
        }

        .agent-activity {
            font-size: 9.5px;
            color: var(--fg-3);
            font-family: var(--mono);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 1px;
        }

        .agent-you {
            font-size: 8px;
            font-weight: 600;
            padding: 1px 4px;
            border-radius: 3px;
            text-transform: uppercase;
            letter-spacing: .04em;
            margin-left: 4px;
            background: rgba(232, 230, 227, .1);
            color: var(--fg);
            vertical-align: middle;
        }

        /* ── Sidebar: Stats ── */
        .stats-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 8px
        }

        .stat {
            background: var(--bg-2);
            border-radius: var(--radius-sm);
            padding: 8px 10px
        }

        .stat-v {
            font-size: 18px;
            font-weight: 700;
            font-variant-numeric: tabular-nums
        }

        .stat-l {
            font-size: 9px;
            color: var(--fg-4);
            text-transform: uppercase;
            letter-spacing: .05em
        }

        .convergence-row {
            display: flex;
            justify-content: space-between;
            font-size: 10px;
            color: var(--fg-3);
            margin-top: 4px
        }

        /* ── Main: Header ── */
        .header {
            padding: 12px 24px;
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-shrink: 0;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 12px
        }

        .header-title {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 14px;
            font-weight: 700
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 12px
        }

        .conn {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            font-size: 10px;
            color: var(--fg-3)
        }

        .conn-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            transition: background .3s;
        }

        .conn-dot.on {
            background: var(--green)
        }

        .conn-dot.off {
            background: var(--red);
            animation: blink 1s infinite
        }

        .elapsed {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            font-size: 11px;
            color: var(--fg-3);
            font-variant-numeric: tabular-nums
        }

        /* ── Main: Posts ── */
        .posts {
            flex: 1;
            overflow-y: auto;
            padding: 16px 24px;
            scroll-behavior: smooth
        }

        .posts::-webkit-scrollbar {
            width: 4px
        }

        .posts::-webkit-scrollbar-thumb {
            background: var(--bg-3);
            border-radius: 2px
        }

        /* ── Main: Compose ── */
        .compose {
            border-top: 1px solid var(--border);
            padding: 12px 24px 16px;
            background: var(--bg-1);
            flex-shrink: 0
        }

        .compose-reply {
            display: none;
            align-items: center;
            gap: 6px;
            padding: 4px 8px;
            margin-bottom: 8px;
            background: var(--bg-2);
            border-radius: var(--radius-sm);
            font-size: 10px;
            color: var(--fg-2);
        }

        .compose-reply.on {
            display: flex
        }

        .compose-reply-x {
            margin-left: auto;
            cursor: pointer;
            color: var(--fg-3);
            background: none;
            border: none;
            font-size: 14px;
            line-height: 1;
            padding: 0 4px;
            font-family: var(--sans);
        }

        .compose-config {
            display: flex;
            gap: 8px;
            margin-bottom: 8px;
            align-items: center
        }

        .compose-config label {
            font-size: 10px;
            color: var(--fg-3)
        }

        .compose-row {
            display: flex;
            gap: 10px;
            align-items: flex-end
        }

        /* ── Empty / Loading ── */
        .empty {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            color: var(--fg-3);
            gap: 10px;
        }

        .empty-circle {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            border: 2px solid var(--fg-4);
            position: relative;
            opacity: .5;
        }

        .empty-circle::after {
            content: '';
            position: absolute;
            top: 12px;
            left: 12px;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 2px dashed var(--fg-4);
            animation: spin 8s linear infinite;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg)
            }
        }

        .empty-text {
            font-size: 13px
        }

        .empty-sub {
            font-size: 11px;
            color: var(--fg-4)
        }

        .loading {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            width: 100%;
            color: var(--fg-3);
            font-size: 12px;
            gap: 16px;
        }

        .loading-bar {
            width: 48px;
            height: 2px;
            background: var(--bg-2);
            border-radius: 1px;
            overflow: hidden;
            position: relative
        }

        .loading-bar::after {
            content: '';
            position: absolute;
            width: 24px;
            height: 100%;
            background: var(--fg-3);
            border-radius: 1px;
            animation: slide 1.2s ease-in-out infinite;
        }

        @keyframes slide {
            0% {
                left: -24px
            }

            100% {
                left: 48px
            }
        }

        /* ── Flash on update ── */
        .flash {
            animation: flashBg .6s var(--ease)
        }

        @keyframes flashBg {
            0% {
                background: rgba(229, 166, 62, .06)
            }

            100% {
                background: transparent
            }
        }

        /* ── Responsive ── */
        @media (max-width:768px) {
            body {
                flex-direction: column
            }

            .sidebar {
                width: 100%;
                height: auto;
                position: relative
            }

            .main {
                height: calc(100vh - 200px)
            }
        }
    </style>
</head>

<body>
    <div class="loading" id="loading">
        <div class="loading-bar"></div>
        <span>Connecting to brainstorm engine</span>
    </div>

    <script>
        (() => {
            'use strict';

            // ─── State ───
            let S = null;
            let connected = false;
            let replyTo = null;
            let autoScroll = true;
            let scrollIdleTimer = null;

            const PHASES = {
                exploring: { label: 'Exploring', css: 'blue' },
                debating: { label: 'Debating', css: 'amber' },
                converging: { label: 'Converging', css: 'purple' },
                synthesizing: { label: 'Synthesizing', css: 'green' },
                concluded: { label: 'Concluded', css: 'green' },
            };
            const PHASE_ORDER = ['exploring', 'debating', 'converging', 'synthesizing', 'concluded'];

            const POST_TYPES = {
                opinion: { label: 'Opinion', css: 'opinion', icon: 'lightbulb' },
                response: { label: 'Response', css: 'response', icon: 'corner-down-right' },
                proposal: { label: 'Proposal', css: 'proposal', icon: 'clipboard-list' },
                conclude_vote: { label: 'Conclude', css: 'conclude', icon: 'flag' },
            };

            const REACTION_ICON = { agree: 'thumbs-up', challenge: 'zap', 'build-on': 'hammer' };
            const REACTION_CSS = { agree: 'agree', challenge: 'challenge', 'build-on': 'build-on' };

            // ─── SSE ───
            function connect() {
                const es = new EventSource('/api/events');
                es.onopen = () => { connected = true; updConn() };
                es.onmessage = e => {
                    const d = JSON.parse(e.data);
                    d.type === 'snapshot' ? (S = d.state, renderAll()) : applyUpdate(d);
                };
                es.onerror = () => { connected = false; updConn(); es.close(); setTimeout(connect, 2000) };
            }

            function updConn() {
                const d = document.getElementById('conn-dot');
                const l = document.getElementById('conn-label');
                if (d) d.className = 'conn-dot ' + (connected ? 'on' : 'off');
                if (l) l.textContent = connected ? 'Live' : 'Reconnecting';
            }

            function applyUpdate(ev) {
                if (!S) return;
                switch (ev.type) {
                    case 'new_post': {
                        S.posts.push(ev.post);
                        const ag = S.agents[ev.post.agent_id];
                        if (ag) ag.postCount = (ag.postCount || 0) + 1;
                        appendPost(ev.post);
                        renderStats(); renderConvergence(); renderAgents();
                        break;
                    }
                    case 'reaction': {
                        const p = S.posts.find(x => x.id === ev.post_id);
                        if (p) { p.reactions.push(ev.reaction); rerenderPost(ev.post_id); scrollIfAuto() }
                        break;
                    }
                    case 'phase_change':
                        S.phase = ev.phase; renderPhase(); renderHeader();
                        break;
                    case 'agent_joined':
                        if (ev.agent) S.agents[ev.agent.id] = ev.agent;
                        renderAgents();
                        break;
                    case 'agent_status':
                        if (S.agents[ev.agent_id]) S.agents[ev.agent_id].status = ev.status;
                        renderAgents();
                        break;
                    case 'agent_activity':
                        if (S.agents[ev.agent_id]) S.agents[ev.agent_id].activity = ev.activity;
                        updAgentAct(ev.agent_id);
                        break;
                }
            }

            // ─── Helpers ───
            const esc = s => s ? s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : '';

            function fmtElap(ms) {
                if (!ms || ms < 0) return '\u2014';
                const s = Math.floor(ms / 1000);
                if (s < 60) return s + 's';
                const m = Math.floor(s / 60);
                return m < 60 ? `${m}m${s % 60 > 0 ? s % 60 + 's' : ''}` : `${Math.floor(m / 60)}h${m % 60}m`;
            }

            function calcConv() {
                const agents = Object.values(S.agents);
                if (!agents.length) return 0;
                const rx = S.posts.flatMap(p => p.reactions || []);
                const ag = rx.filter(r => r.reaction === 'agree' || r.reaction === 'build-on').length;
                const ch = rx.filter(r => r.reaction === 'challenge').length;
                const cx = agents.filter(a => !a.isHuman).length || agents.length;
                const cr = (S.concludeVotes || []).length / cx;
                const ar = ag + ch > 0 ? ag / (ag + ch) : 0;
                return Math.min(1, cr * .5 + ar * .3 + (S.posts.length > cx * 2 ? .2 : 0));
            }

            function countRx(type) {
                return S.posts.flatMap(p => p.reactions || []).filter(r => r.reaction === type).length;
            }

            // Lucide icon shorthand: returns an <i> placeholder that lucide.createIcons() will hydrate
            const ic = (name, cls = '') => `<i data-lucide="${name}" class="${cls}"></i>`;
            function initIcons() { if (window.lucide) lucide.createIcons() }

            function scrollIfAuto() {
                if (!autoScroll) return;
                const el = document.getElementById('posts');
                if (el) el.scrollTop = el.scrollHeight;
            }

            function formatContent(text) {
                if (!text) return '';
                let h = esc(text);
                h = h.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
                h = h.replace(/`([^`]+)`/g, '<code>$1</code>');
                h = h.replace(/^(#{1,3})\s+(.+)$/gm, '<strong>$2</strong>');
                return h;
            }

            // ─── Render: Full ───
            function renderAll() {
                if (!S) return;
                document.getElementById('loading').style.display = 'none';
                document.body.innerHTML = `
                <aside class="sidebar" id="sidebar"></aside>
                <main class="main">
                    <div class="header" id="hdr"></div>
                    <div class="posts" id="posts"></div>
                    <div class="compose" id="compose"></div>
                </main>`;
                renderSidebar(); renderHeader(); renderPosts(); renderCompose();
                initIcons();
                setInterval(tickElapsed, 1000);
                // Auto-scroll with inactivity re-enable
                document.getElementById('posts').addEventListener('scroll', e => {
                    const el = e.target;
                    const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 60;
                    if (!atBottom) {
                        autoScroll = false;
                        clearTimeout(scrollIdleTimer);
                        scrollIdleTimer = setTimeout(() => { autoScroll = true }, 15000);
                    } else {
                        autoScroll = true;
                        clearTimeout(scrollIdleTimer);
                    }
                });
            }

            // ─── Render: Sidebar ───
            function renderSidebar() {
                document.getElementById('sidebar').innerHTML = `
                <div class="section" id="sb-topic"></div>
                <div class="section" id="sb-phase"></div>
                <div class="section" id="sb-agents"></div>
                <div class="section" id="sb-conv"></div>
                <div class="section" id="sb-stats"></div>`;
                renderTopic(); renderPhase(); renderAgents(); renderConvergence(); renderStats();
                initIcons();
            }

            function renderTopic() {
                const el = document.getElementById('sb-topic');
                if (!el || !S?.topic) return;
                el.innerHTML = `
                <div class="section-label">Topic</div>
                <div class="topic-title">${esc(S.topic.title)}</div>
                <div class="topic-context">${esc(S.topic.context || '')}</div>
                ${(S.topic.goals || []).length ? `<div class="topic-goals">
                    ${S.topic.goals.map(g => `<div class="topic-goal">${esc(g)}</div>`).join('')}
                </div>` : ''}`;
            }

            function renderPhase() {
                const el = document.getElementById('sb-phase');
                if (!el || !S) return;
                const idx = PHASE_ORDER.indexOf(S.phase);
                const info = PHASES[S.phase] || { label: S.phase, css: 'blue' };
                el.innerHTML = `
                <div class="section-label">Phase</div>
                <div class="phase-label">${info.label}</div>
                <div class="progress">
                    ${PHASE_ORDER.map((_, i) => {
                    const w = 100 / PHASE_ORDER.length;
                    if (i < idx) return `<div class="progress-fill" style="width:${w}%;display:inline-block;background:var(--green)"></div>`;
                    if (i === idx) return `<div class="progress-fill" style="width:${w}%;display:inline-block"></div>`;
                    return '';
                }).join('')}
                </div>`;
                // Simpler approach: use percentage
                const pct = Math.round(((idx + 1) / PHASE_ORDER.length) * 100);
                el.querySelector('.progress').innerHTML = `<div class="progress-fill" style="width:${pct}%"></div>`;
            }

            function renderAgents() {
                const el = document.getElementById('sb-agents');
                if (!el || !S) return;
                const agents = Object.values(S.agents);
                el.innerHTML = `
                <div class="section-label">Participants ${agents.length}</div>
                ${agents.map(a => {
                    const init = (a.name || a.id)[0].toUpperCase();
                    const c = a.color?.hex || '#e5a63e';
                    const tag = a.isHuman ? '<span class="agent-you">You</span>' : '';
                    const act = a.activity?.text || '';
                    return `
                    <div class="agent-card" id="ac-${a.id}">
                        <div class="avatar" style="background:${c}20;color:${c}">
                            ${init}<div class="status status--${a.status}"></div>
                        </div>
                        <div class="agent-info">
                            <div class="agent-name" style="color:${c}">${esc(a.name)}${tag}</div>
                            <div class="agent-meta">${a.postCount || 0} posts · ${a.status}</div>
                            <div class="agent-activity" id="aa-${a.id}">${esc(act)}</div>
                        </div>
                    </div>`;
                }).join('')}`;
            }

            function updAgentAct(id) {
                const el = document.getElementById('aa-' + id);
                if (!el || !S?.agents[id]) return;
                const a = S.agents[id];
                el.textContent = a.activity?.text || '';
                const card = document.getElementById('ac-' + id);
                if (card) { card.classList.add('flash'); setTimeout(() => card.classList.remove('flash'), 600) }
            }

            function renderConvergence() {
                const el = document.getElementById('sb-conv');
                if (!el || !S) return;
                const pct = Math.round(calcConv() * 100);
                const cx = Object.values(S.agents).filter(a => !a.isHuman).length;
                const voted = (S.concludeVotes || []).length;
                el.innerHTML = `
                <div class="section-label">Convergence</div>
                <div class="progress progress-lg"><div class="progress-fill" style="width:${pct}%"></div></div>
                <div class="convergence-row"><span>${pct}%</span><span>${voted}/${cx} voted</span></div>`;
            }

            function renderStats() {
                const el = document.getElementById('sb-stats');
                if (!el || !S) return;
                el.innerHTML = `
                <div class="section-label">Stats</div>
                <div class="stats-grid">
                    <div class="stat"><div class="stat-v">${S.posts.length}</div><div class="stat-l">Posts</div></div>
                    <div class="stat"><div class="stat-v" id="el-v">${fmtElap((S.endTime || Date.now()) - S.startTime)}</div><div class="stat-l">Elapsed</div></div>
                    <div class="stat"><div class="stat-v">${countRx('agree')}</div><div class="stat-l">Agrees</div></div>
                    <div class="stat"><div class="stat-v">${countRx('challenge')}</div><div class="stat-l">Challenges</div></div>
                </div>`;
            }

            // ─── Render: Header ───
            function renderHeader() {
                const el = document.getElementById('hdr');
                if (!el || !S) return;
                const info = PHASES[S.phase] || { label: S.phase, css: 'blue' };
                el.innerHTML = `
                <div class="header-left">
                    <span class="header-title">${ic('brain', 'i-lg')} Discussion Space</span>
                    <span class="badge badge--${info.css}"><span class="dot"></span> ${info.label}</span>
                </div>
                <div class="header-right">
                    <div class="conn">${ic('wifi', 'i-sm')} <div class="conn-dot ${connected ? 'on' : 'off'}" id="conn-dot"></div><span id="conn-label">${connected ? 'Live' : 'Reconnecting'}</span></div>
                    <span class="elapsed" id="el-h">${ic('clock', 'i-sm')} ${fmtElap((S.endTime || Date.now()) - S.startTime)}</span>
                </div>`;
                initIcons();
            }

            // ─── Render: Posts ───
            function renderPosts() {
                const el = document.getElementById('posts');
                if (!el || !S) return;
                if (!S.posts.length) {
                    el.innerHTML = `<div class="empty">
                    <div class="empty-circle">${ic('search-code', 'i-xl')}</div>
                    <div class="empty-text">Agents are analyzing the codebase</div>
                    <div class="empty-sub">Posts will appear here. You can also post below to join.</div>
                </div>`;
                    initIcons();
                    return;
                }
                el.innerHTML = S.posts.map(postHTML).join('');
                el.scrollTop = el.scrollHeight;
                initIcons();
            }

            function appendPost(post) {
                const el = document.getElementById('posts');
                if (!el) return;
                const empty = el.querySelector('.empty');
                if (empty) empty.remove();
                el.insertAdjacentHTML('beforeend', postHTML(post));
                initIcons();
                scrollIfAuto();
            }

            function rerenderPost(id) {
                const p = S.posts.find(x => x.id === id);
                if (!p) return;
                const el = document.querySelector(`[data-pid="${id}"]`);
                if (el) { el.outerHTML = postHTML(p); initIcons() }
            }

            function postHTML(p) {
                const ag = S.agents[p.agent_id] || {};
                const init = (ag.name || p.agent_id)[0].toUpperCase();
                const c = ag.color?.hex || '#e5a63e';
                const ti = POST_TYPES[p.type] || { label: p.type, css: 'opinion' };
                const ts = new Date(p.timestamp).toTimeString().slice(0, 8);

                const ref = p.references?.length
                    ? `<span class="post-ref">#${p.references.join(', #')}</span>` : '';

                const rxs = p.reactions?.length
                    ? `<div class="post-reactions">${p.reactions.map(r => {
                        const ra = S.agents[r.agent_id] || {};
                        const rIcon = REACTION_ICON[r.reaction] || 'message-circle';
                        const cls = REACTION_CSS[r.reaction] || '';
                        const cm = r.comment ? `<span class="chip-comment">${esc(r.comment)}</span>` : '';
                        return `<span class="chip chip--${cls}">${ic(rIcon, 'i-sm')} ${esc(ra.name || r.agent_id)}${cm}</span>`;
                    }).join('')}</div>` : '';

                return `
            <div class="post" data-pid="${p.id}">
                <div class="avatar avatar--lg" style="background:${c}20;color:${c}">${init}</div>
                <div class="post-body">
                    <div class="post-header">
                        <span class="post-id">#${p.id}</span>
                        <span class="post-author" style="color:${c}">${esc(ag.name || p.agent_id)}</span>
                        <span class="tag tag--${ti.css}">${ic(ti.icon, 'i-sm')} ${ti.label}</span>
                        ${ref}
                        <span class="post-time">${ts}</span>
                    </div>
                    <div class="post-content">${formatContent(p.content)}</div>
                    <div class="post-actions">
                        <button class="btn" onclick="BS.reply(${p.id},'${esc(ag.name || p.agent_id)}')">${ic('corner-down-right', 'i-sm')} Reply</button>
                        <button class="btn btn--agree" onclick="BS.react(${p.id},'agree')">${ic('thumbs-up', 'i-sm')} Agree</button>
                        <button class="btn btn--challenge" onclick="BS.react(${p.id},'challenge')">${ic('zap', 'i-sm')} Challenge</button>
                        <button class="btn btn--build" onclick="BS.react(${p.id},'build-on')">${ic('hammer', 'i-sm')} Build</button>
                    </div>
                    ${rxs}
                </div>
            </div>`;
            }

            // ─── Render: Compose ───
            function renderCompose() {
                const el = document.getElementById('compose');
                if (!el) return;
                el.innerHTML = `
                <div class="compose-reply" id="c-reply">
                    ${ic('corner-down-right', 'i-sm')} <span id="c-reply-label">Replying to</span>
                    <button class="compose-reply-x" onclick="BS.clearReply()">${ic('x', 'i-sm')}</button>
                </div>
                <div class="compose-config">
                    <label>${ic('user', 'i-sm')} Name</label>
                    <input class="input" id="c-name" value="Human" placeholder="Your name">
                    <label>${ic('tag', 'i-sm')} Type</label>
                    <select class="select" id="c-type">
                        <option value="opinion">Opinion</option>
                        <option value="response">Response</option>
                        <option value="proposal">Proposal</option>
                    </select>
                </div>
                <div class="compose-row">
                    <textarea class="textarea" id="c-text" placeholder="Share your perspective — Enter to send, Shift+Enter for newline" rows="2"></textarea>
                    <button class="btn btn--primary" id="c-send" onclick="BS.send()">${ic('send', 'i-sm')} Send</button>
                </div>`;
                initIcons();
                document.getElementById('c-text').addEventListener('keydown', e => {
                    if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); BS.send() }
                });
            }

            // ─── Timer ───
            function tickElapsed() {
                if (!S) return;
                const e = fmtElap((S.endTime || Date.now()) - S.startTime);
                const a = document.getElementById('el-v');
                const b = document.getElementById('el-h');
                if (a) a.textContent = e;
                if (b) { b.innerHTML = `${ic('clock', 'i-sm')} ${e}`; initIcons() }
            }

            // ─── Public API (window.BS) ───
            window.BS = {
                reply(id, name) {
                    replyTo = { id, name };
                    const el = document.getElementById('c-reply');
                    const lb = document.getElementById('c-reply-label');
                    if (el) el.classList.add('on');
                    if (lb) lb.textContent = `Replying to #${id} (${name})`;
                    document.getElementById('c-type').value = 'response';
                    document.getElementById('c-text').focus();
                },

                clearReply() {
                    replyTo = null;
                    const el = document.getElementById('c-reply');
                    if (el) el.classList.remove('on');
                },

                async send() {
                    const name = document.getElementById('c-name')?.value?.trim() || 'Human';
                    const type = document.getElementById('c-type')?.value || 'opinion';
                    const text = document.getElementById('c-text')?.value?.trim();
                    if (!text) return;

                    const btn = document.getElementById('c-send');
                    btn.disabled = true; btn.textContent = 'Sending';
                    try {
                        const id = name.toLowerCase().replace(/\s+/g, '-');
                        await fetch('/api/post', {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify({
                                agent_id: id, display_name: name,
                                type: replyTo ? 'response' : type,
                                content: text, references: replyTo ? [replyTo.id] : []
                            })
                        });
                        document.getElementById('c-text').value = '';
                        BS.clearReply();
                    } catch (e) { console.error('Post failed:', e) }
                    finally { btn.disabled = false; btn.innerHTML = `${ic('send', 'i-sm')} Send`; initIcons() }
                },

                async react(postId, reaction) {
                    const name = document.getElementById('c-name')?.value?.trim() || 'Human';
                    const id = name.toLowerCase().replace(/\s+/g, '-');
                    let comment = '';
                    if (reaction === 'challenge') {
                        comment = prompt('Reason for challenge (optional):') || '';
                    }
                    try {
                        await fetch('/api/react', {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify({ agent_id: id, post_id: postId, reaction, comment })
                        });
                    } catch (e) { console.error('React failed:', e) }
                }
            };

            // ─── Init ───
            connect();
        })();
    </script>
</body>

</html>
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall