agharsallah Codex commited on
Commit ·
a8039c4
1
Parent(s): dfae9ee
feat: add Fishbowl Gradio app shell + integrator (Unit 9)
Browse filesTwo-tab FISHBOWL theater (The Lab / The Show) with CRT chrome, per-user
gr.State session, and all cross-module wiring: Summon, hybrid transport
(scrub-back = pure prefix view, play-at-head = step the Conductor), poke
inject, speed/layout/mind-reader re-render. Owns render_show_html
composition over the render units.
Every leaf unit (theme/render/session/show/lab) is imported defensively
with friendly placeholders, so the shell builds and launches standalone
before sibling units land and upgrades itself once they merge. Package
import stays Gradio-free (lazy PEP 562 exports of build_app/demo). Root
app.py is now a thin shim. Offline, no API key needed.
Co-Authored-By: Codex <codex@openai.com>
- app.py +8 -242
- src/ui/fishbowl/__init__.py +20 -1
- src/ui/fishbowl/app.py +625 -0
- tests/test_fishbowl_app.py +100 -0
app.py
CHANGED
|
@@ -1,249 +1,15 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
import socket
|
| 5 |
-
|
| 6 |
-
import gradio as gr
|
| 7 |
-
|
| 8 |
-
from src.core.conductor import Conductor
|
| 9 |
-
from src.core.ledger_factory import make_ledger
|
| 10 |
-
from src.core.registry import default_registry
|
| 11 |
-
from src.tools.builtins import default_tool_registry
|
| 12 |
-
from src.ui.render import render_config, render_event_log, render_stage, render_stats
|
| 13 |
-
|
| 14 |
-
# ── scenario registry (assembled from config/, not hardcoded) ───────────────────
|
| 15 |
-
|
| 16 |
-
_registry = default_registry()
|
| 17 |
-
_tools = default_tool_registry()
|
| 18 |
-
_PROFILE_MODELS = _registry.build_router().describe()
|
| 19 |
-
|
| 20 |
-
# Preferred display order, then any other scenarios dropped into config/.
|
| 21 |
-
_PREFERRED = ["thousand-token-wood", "mystery-roots", "oracle-grove"]
|
| 22 |
-
_names = [n for n in _PREFERRED if n in _registry.scenarios] + [
|
| 23 |
-
n for n in sorted(_registry.scenarios) if n not in _PREFERRED
|
| 24 |
-
]
|
| 25 |
-
|
| 26 |
-
# display title -> internal scenario name
|
| 27 |
-
SCENARIOS: dict[str, str] = {(_registry.scenarios[n].title or n): n for n in _names}
|
| 28 |
-
|
| 29 |
-
# Ledger backend is env-gated (ADR-0014): DATABASE_URL → durable event store,
|
| 30 |
-
# otherwise an in-memory Ledger. Offline (the default) each scenario gets its own
|
| 31 |
-
# fresh in-memory ledger, exactly as before. With a single DATABASE_URL the
|
| 32 |
-
# scenarios share one store; use scripts/resume_run.py (one DB per scenario) for
|
| 33 |
-
# isolated durable runs.
|
| 34 |
-
_conductors: dict[str, Conductor] = {
|
| 35 |
-
title: Conductor(
|
| 36 |
-
_registry.build_scenario(name, tools=_tools),
|
| 37 |
-
governor=_registry.governor_for(name),
|
| 38 |
-
ledger=make_ledger(),
|
| 39 |
-
)
|
| 40 |
-
for title, name in SCENARIOS.items()
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
# ── CSS ───────────────────────────────────────────────────────────────────────
|
| 44 |
-
|
| 45 |
-
APP_CSS = """
|
| 46 |
-
:root {
|
| 47 |
-
--bg: #0e1209;
|
| 48 |
-
--surface: #141a0f;
|
| 49 |
-
--border: #2e3d25;
|
| 50 |
-
--text: #e8e2cc;
|
| 51 |
-
--muted: #8a9c7a;
|
| 52 |
-
--accent: #6db56d;
|
| 53 |
-
--accent2: #c9a84c;
|
| 54 |
-
--danger: #c96b6b;
|
| 55 |
-
}
|
| 56 |
-
body { background: var(--bg); color: var(--text); }
|
| 57 |
-
.gradio-container { max-width: 1200px !important; font-family: 'Georgia', serif; }
|
| 58 |
-
footer { display: none !important; }
|
| 59 |
|
| 60 |
-
|
| 61 |
-
.
|
| 62 |
-
|
| 63 |
-
color: var(--accent);
|
| 64 |
-
letter-spacing: .04em;
|
| 65 |
-
margin-bottom: 2px;
|
| 66 |
-
}
|
| 67 |
-
.wood-header p { color: var(--muted); margin-top: 0; font-style: italic; }
|
| 68 |
-
|
| 69 |
-
/* Stage */
|
| 70 |
-
#stage {
|
| 71 |
-
border: 1px solid var(--border);
|
| 72 |
-
background: linear-gradient(180deg, #172017 0%, var(--surface) 100%);
|
| 73 |
-
color: var(--text);
|
| 74 |
-
padding: 20px 24px;
|
| 75 |
-
border-radius: 10px;
|
| 76 |
-
min-height: 380px;
|
| 77 |
-
font-size: 0.97rem;
|
| 78 |
-
line-height: 1.7;
|
| 79 |
-
}
|
| 80 |
-
#stage h2 { color: var(--accent); font-size: 1.1rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
|
| 81 |
-
#stage h3 { color: var(--accent2); font-size: 0.95rem; margin-top: 16px; margin-bottom: 6px; }
|
| 82 |
-
|
| 83 |
-
/* Ledger + stats */
|
| 84 |
-
#events textarea, #stats textarea {
|
| 85 |
-
font-family: ui-monospace, 'Cascadia Code', 'Fira Mono', monospace;
|
| 86 |
-
font-size: 11px;
|
| 87 |
-
background: var(--surface);
|
| 88 |
-
color: var(--muted);
|
| 89 |
-
border-color: var(--border);
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/* Buttons */
|
| 93 |
-
button.primary { background: var(--accent) !important; color: var(--bg) !important; font-weight: 700; }
|
| 94 |
-
button.secondary { border-color: var(--border) !important; color: var(--muted) !important; }
|
| 95 |
-
|
| 96 |
-
/* Scenario selector */
|
| 97 |
-
.scenario-selector label { color: var(--accent2) !important; }
|
| 98 |
-
|
| 99 |
-
/* Seed input */
|
| 100 |
-
#seed-box textarea { font-style: italic; }
|
| 101 |
-
|
| 102 |
-
/* Inject row */
|
| 103 |
-
#inject-box textarea { border-color: var(--accent2) !important; }
|
| 104 |
-
|
| 105 |
-
/* Status pill */
|
| 106 |
-
.status-pill {
|
| 107 |
-
display: inline-block;
|
| 108 |
-
padding: 2px 10px;
|
| 109 |
-
border-radius: 999px;
|
| 110 |
-
font-size: 0.75rem;
|
| 111 |
-
font-family: monospace;
|
| 112 |
-
background: var(--surface);
|
| 113 |
-
border: 1px solid var(--border);
|
| 114 |
-
color: var(--muted);
|
| 115 |
-
}
|
| 116 |
"""
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
def _conductor(scenario_name: str) -> Conductor:
|
| 122 |
-
return _conductors[scenario_name]
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
def _outputs(c: Conductor):
|
| 126 |
-
return (
|
| 127 |
-
render_stage(c.projection),
|
| 128 |
-
render_event_log(c.ledger.events),
|
| 129 |
-
render_stats(c.ledger.events, c.governor),
|
| 130 |
-
render_config(c.scenario, _PROFILE_MODELS),
|
| 131 |
-
)
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
def start(scenario_name: str, seed: str):
|
| 135 |
-
c = _conductor(scenario_name)
|
| 136 |
-
c.reset(seed.strip() or c.scenario.default_seed)
|
| 137 |
-
return _outputs(c)
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
def step(scenario_name: str):
|
| 141 |
-
c = _conductor(scenario_name)
|
| 142 |
-
c.step()
|
| 143 |
-
return _outputs(c)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
def inject(scenario_name: str, user_event: str):
|
| 147 |
-
c = _conductor(scenario_name)
|
| 148 |
-
if user_event.strip():
|
| 149 |
-
c.inject_user_event(user_event.strip())
|
| 150 |
-
c.step()
|
| 151 |
-
return _outputs(c)
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
def change_scenario(scenario_name: str):
|
| 155 |
-
c = _conductor(scenario_name)
|
| 156 |
-
seeds = c.scenario.example_seeds
|
| 157 |
-
choices = [(s, s) for s in seeds]
|
| 158 |
-
default = seeds[0] if seeds else c.scenario.default_seed
|
| 159 |
-
return (
|
| 160 |
-
gr.update(choices=choices, value=default),
|
| 161 |
-
render_config(c.scenario, _PROFILE_MODELS),
|
| 162 |
-
)
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
# ── layout ────────────────────────────────────────────────────────────────────
|
| 166 |
-
|
| 167 |
-
with gr.Blocks(title="Multi-Agent Land · Thousand Token Wood") as demo: # css passed to launch() (Gradio 6)
|
| 168 |
-
gr.Markdown(
|
| 169 |
-
"""
|
| 170 |
-
# Multi-Agent Land
|
| 171 |
-
*Tiny specialist agents share a ledger and build a living world — turn by turn.*
|
| 172 |
-
""",
|
| 173 |
-
elem_classes=["wood-header"],
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
-
with gr.Row():
|
| 177 |
-
scenario_select = gr.Dropdown(
|
| 178 |
-
choices=list(SCENARIOS.keys()),
|
| 179 |
-
value=list(SCENARIOS.keys())[0],
|
| 180 |
-
label="Scenario",
|
| 181 |
-
elem_classes=["scenario-selector"],
|
| 182 |
-
scale=1,
|
| 183 |
-
)
|
| 184 |
-
|
| 185 |
-
with gr.Row():
|
| 186 |
-
_first_title = list(SCENARIOS.keys())[0]
|
| 187 |
-
seed_examples = _conductors[_first_title].scenario.example_seeds
|
| 188 |
-
seed = gr.Dropdown(
|
| 189 |
-
choices=[(s, s) for s in seed_examples],
|
| 190 |
-
value=seed_examples[0],
|
| 191 |
-
label="World seed",
|
| 192 |
-
allow_custom_value=True,
|
| 193 |
-
elem_id="seed-box",
|
| 194 |
-
scale=4,
|
| 195 |
-
)
|
| 196 |
-
with gr.Column(scale=1, min_width=160):
|
| 197 |
-
start_btn = gr.Button("▶ Start", variant="primary")
|
| 198 |
-
step_btn = gr.Button("⏭ Advance one turn", variant="secondary")
|
| 199 |
-
|
| 200 |
-
stage = gr.Markdown(
|
| 201 |
-
value="> Select a scenario and press **Start** to raise the curtain.",
|
| 202 |
-
elem_id="stage",
|
| 203 |
-
)
|
| 204 |
-
|
| 205 |
-
with gr.Row():
|
| 206 |
-
user_event = gr.Textbox(
|
| 207 |
-
label="Drop something into the world",
|
| 208 |
-
placeholder="Example: A lantern starts whispering recipes.",
|
| 209 |
-
lines=2,
|
| 210 |
-
elem_id="inject-box",
|
| 211 |
-
scale=4,
|
| 212 |
-
)
|
| 213 |
-
inject_btn = gr.Button("💬 Inject & advance", scale=1, min_width=160)
|
| 214 |
-
|
| 215 |
-
with gr.Row():
|
| 216 |
-
events_box = gr.Textbox(label="Event ledger (append-only)", lines=18, elem_id="events")
|
| 217 |
-
stats_box = gr.Textbox(label="Run stats", lines=18, elem_id="stats")
|
| 218 |
-
|
| 219 |
-
with gr.Accordion("⚙ Configuration — live, from config/ (YAML, not code)", open=False):
|
| 220 |
-
config_box = gr.Markdown(
|
| 221 |
-
value=render_config(_conductors[_first_title].scenario, _PROFILE_MODELS),
|
| 222 |
-
elem_id="config",
|
| 223 |
-
)
|
| 224 |
-
|
| 225 |
-
# ── wiring ────────────────────────────────────────────────────────────────
|
| 226 |
-
_outs = [stage, events_box, stats_box, config_box]
|
| 227 |
-
scenario_select.change(change_scenario, inputs=[scenario_select], outputs=[seed, config_box])
|
| 228 |
-
|
| 229 |
-
start_btn.click(start, inputs=[scenario_select, seed], outputs=_outs)
|
| 230 |
-
step_btn.click(step, inputs=[scenario_select], outputs=_outs)
|
| 231 |
-
inject_btn.click(inject, inputs=[scenario_select, user_event], outputs=_outs)
|
| 232 |
-
|
| 233 |
|
| 234 |
-
|
| 235 |
-
configured = os.getenv("GRADIO_SERVER_PORT")
|
| 236 |
-
if configured:
|
| 237 |
-
return int(configured)
|
| 238 |
-
for port in range(7960, 8060):
|
| 239 |
-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 240 |
-
try:
|
| 241 |
-
sock.bind(("127.0.0.1", port))
|
| 242 |
-
return port
|
| 243 |
-
except OSError:
|
| 244 |
-
continue
|
| 245 |
-
raise RuntimeError("No free development port found in range 7960-8059.")
|
| 246 |
|
|
|
|
| 247 |
|
| 248 |
if __name__ == "__main__":
|
| 249 |
-
|
|
|
|
| 1 |
+
"""Root entry point — a thin shim over the FISHBOWL Gradio shell.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
The app itself lives in ``src.ui.fishbowl.app`` (Unit 9). This shim keeps ``uv run
|
| 4 |
+
app.py`` working and preserves the no-API-key / offline behaviour: the deterministic
|
| 5 |
+
stub drives the cast so the demo is reproducible on stage with no credentials.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
+
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
from src.ui.fishbowl.app import demo, launch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
__all__ = ["demo", "launch"]
|
| 13 |
|
| 14 |
if __name__ == "__main__":
|
| 15 |
+
launch()
|
src/ui/fishbowl/__init__.py
CHANGED
|
@@ -10,9 +10,28 @@ Layers:
|
|
| 10 |
* ``cast_state`` — ``derive_cast_state`` : per-agent {said, thought, mood} ledger view (G1)
|
| 11 |
* ``adapter`` — engine vocabulary → the design's say/narrate/poke/verdict + hue/tier/voice
|
| 12 |
* ``view_model`` — ``view_model_at`` : a JSON-serialisable snapshot at any scrubbed step k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
|
|
|
|
|
|
|
| 15 |
from src.ui.fishbowl.cast_state import CastMemberState, derive_cast_state
|
| 16 |
from src.ui.fishbowl.view_model import view_model_at
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
* ``cast_state`` — ``derive_cast_state`` : per-agent {said, thought, mood} ledger view (G1)
|
| 11 |
* ``adapter`` — engine vocabulary → the design's say/narrate/poke/verdict + hue/tier/voice
|
| 12 |
* ``view_model`` — ``view_model_at`` : a JSON-serialisable snapshot at any scrubbed step k
|
| 13 |
+
|
| 14 |
+
The Gradio shell (``build_app`` / ``demo``) also lives in this package (``app`` module),
|
| 15 |
+
but is exposed **lazily** via :pep:`562` ``__getattr__`` so that importing the package
|
| 16 |
+
stays Gradio-free — the pure presenter above must remain importable without Gradio for
|
| 17 |
+
``tests/test_modularity.py`` and the JSON-endpoint path.
|
| 18 |
"""
|
| 19 |
|
| 20 |
+
from typing import TYPE_CHECKING
|
| 21 |
+
|
| 22 |
from src.ui.fishbowl.cast_state import CastMemberState, derive_cast_state
|
| 23 |
from src.ui.fishbowl.view_model import view_model_at
|
| 24 |
|
| 25 |
+
if TYPE_CHECKING: # for type-checkers only; no runtime Gradio import
|
| 26 |
+
from src.ui.fishbowl.app import build_app, demo
|
| 27 |
+
|
| 28 |
+
__all__ = ["CastMemberState", "derive_cast_state", "view_model_at", "build_app", "demo"]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def __getattr__(name: str):
|
| 32 |
+
"""Lazily expose the Gradio shell so ``import src.ui.fishbowl`` stays Gradio-free."""
|
| 33 |
+
if name in ("build_app", "demo"):
|
| 34 |
+
from src.ui.fishbowl import app as _app
|
| 35 |
+
|
| 36 |
+
return getattr(_app, name)
|
| 37 |
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
src/ui/fishbowl/app.py
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FISHBOWL — the Gradio app shell (Unit 9: integrator + root shim).
|
| 2 |
+
|
| 3 |
+
Two tabs — **The Lab** (compose a run) and **The Show** (watch the say-vs-think
|
| 4 |
+
MindCard replay) — wrapped in the CRT theater chrome. This module owns the app shell
|
| 5 |
+
and *all* cross-module wiring: it holds the per-user session in ``gr.State``, drives the
|
| 6 |
+
hybrid transport (scrub-back = pure prefix view; play-at-head = step the Conductor), and
|
| 7 |
+
composes the Show's stage/feed/meters/verdict HTML from the render units.
|
| 8 |
+
|
| 9 |
+
Every sibling unit (theme, render.*, session, show, lab) is imported **defensively**:
|
| 10 |
+
this worker runs in its own worktree before the leaf modules land, so each import falls
|
| 11 |
+
back to a friendly placeholder. The shell therefore builds and launches standalone, and
|
| 12 |
+
upgrades itself the moment the real modules are merged — no edits required here.
|
| 13 |
+
|
| 14 |
+
Offline-first: no API key is needed; the deterministic stub keeps the demo reproducible.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
import os
|
| 20 |
+
import socket
|
| 21 |
+
|
| 22 |
+
import gradio as gr
|
| 23 |
+
|
| 24 |
+
# ── engine read surface (public; never mutated here) ───────────────────────────
|
| 25 |
+
from src.core.conductor import Conductor
|
| 26 |
+
from src.core.ledger_factory import make_ledger
|
| 27 |
+
from src.core.registry import default_registry
|
| 28 |
+
from src.tools.builtins import default_tool_registry
|
| 29 |
+
from src.ui.fishbowl.view_model import view_model_at
|
| 30 |
+
|
| 31 |
+
# ── defensive imports of sibling units ─────────────────────────────────────────
|
| 32 |
+
# Each block degrades to a placeholder so the shell runs before the leaf modules land.
|
| 33 |
+
|
| 34 |
+
try: # theme: CSS + <head> + a gr.Theme
|
| 35 |
+
from src.ui.fishbowl.theme import FISHBOWL_HEAD, FishbowlTheme, load_css
|
| 36 |
+
except Exception: # pragma: no cover - exercised only before the theme unit lands
|
| 37 |
+
|
| 38 |
+
def load_css() -> str:
|
| 39 |
+
# Minimal CRT-ish palette so the placeholder shell is legible.
|
| 40 |
+
return """
|
| 41 |
+
:root { --bg:#070a06; --ink:#cfe8c0; --lime:#8fe36a; --cyan:#5fd0d0;
|
| 42 |
+
--violet:#b59cff; --amber:#e3c14c; --coral:#e3786a; }
|
| 43 |
+
body { background: var(--bg); color: var(--ink);
|
| 44 |
+
font-family: 'IBM Plex Mono', ui-monospace, monospace; }
|
| 45 |
+
footer { display: none !important; }
|
| 46 |
+
.fishbowl-topbar { display:flex; align-items:baseline; gap:12px;
|
| 47 |
+
padding:10px 16px; border-bottom:1px solid #2e3d25; }
|
| 48 |
+
.fishbowl-topbar .logo { color: var(--lime); font-weight:800; letter-spacing:.08em; }
|
| 49 |
+
.fishbowl-topbar .sub { color: var(--cyan); font-style:italic; opacity:.8; }
|
| 50 |
+
.crt-bg, .crt-grid, .crt-scan, .crt-vignette {
|
| 51 |
+
position: fixed; inset: 0; pointer-events: none; z-index: 0; }
|
| 52 |
+
.crt-vignette { box-shadow: inset 0 0 220px rgba(0,0,0,.8); }
|
| 53 |
+
.fishbowl-placeholder { padding: 24px; color: var(--ink);
|
| 54 |
+
border:1px dashed #2e3d25; border-radius:10px; line-height:1.6; }
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
FISHBOWL_HEAD = (
|
| 58 |
+
'<link rel="preconnect" href="https://fonts.googleapis.com" />'
|
| 59 |
+
'<link href="https://fonts.googleapis.com/css2?family=Martian+Mono:wght@400;700;800'
|
| 60 |
+
'&family=IBM+Plex+Mono:ital,wght@0,400;0,500;1,400&display=swap" rel="stylesheet" />'
|
| 61 |
+
)
|
| 62 |
+
FishbowlTheme = None # launch() tolerates theme=None
|
| 63 |
+
|
| 64 |
+
try: # render: the HTML pieces of the Show
|
| 65 |
+
from src.ui.fishbowl.render.mindcard import render_mindcard
|
| 66 |
+
except Exception: # pragma: no cover
|
| 67 |
+
|
| 68 |
+
def render_mindcard(card, *, mind_reader: bool = False) -> str:
|
| 69 |
+
name = card.get("name", "?")
|
| 70 |
+
said = card.get("said") or "…"
|
| 71 |
+
body = said
|
| 72 |
+
if mind_reader and card.get("thought"):
|
| 73 |
+
body += f"<br/><span style='opacity:.7;font-style:italic'>“{card['thought']}”</span>"
|
| 74 |
+
return f"<div class='mind' data-id='{card.get('id', '')}'><b>{name}</b><br/>{body}</div>"
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
from src.ui.fishbowl.render.constellation import render_constellation
|
| 79 |
+
except Exception: # pragma: no cover
|
| 80 |
+
|
| 81 |
+
def render_constellation(vm, cards_html_by_id) -> str:
|
| 82 |
+
cards = "".join(cards_html_by_id.values())
|
| 83 |
+
return f"<div class='constellation'>{cards}</div>"
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
from src.ui.fishbowl.render.split import render_split
|
| 88 |
+
except Exception: # pragma: no cover
|
| 89 |
+
|
| 90 |
+
def render_split(vm) -> str:
|
| 91 |
+
rows = "".join(
|
| 92 |
+
f"<tr><td>{c.get('name', '?')}</td><td>{c.get('said') or ''}</td>"
|
| 93 |
+
f"<td><i>{c.get('thought') or ''}</i></td></tr>"
|
| 94 |
+
for c in vm.get("cast", [])
|
| 95 |
+
)
|
| 96 |
+
return f"<table class='split'><tbody>{rows}</tbody></table>"
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
try:
|
| 100 |
+
from src.ui.fishbowl.render.feed import render_feed
|
| 101 |
+
except Exception: # pragma: no cover
|
| 102 |
+
|
| 103 |
+
def render_feed(vm, *, mind_reader: bool = False) -> str:
|
| 104 |
+
items = []
|
| 105 |
+
for it in vm.get("feed", []):
|
| 106 |
+
kind = it.get("kind", "")
|
| 107 |
+
if kind == "say":
|
| 108 |
+
line = f"<b>{it.get('agent', '?')}</b>: {it.get('said') or ''}"
|
| 109 |
+
if mind_reader and it.get("thought"):
|
| 110 |
+
line += f" <i style='opacity:.7'>({it['thought']})</i>"
|
| 111 |
+
elif kind == "narrate":
|
| 112 |
+
line = f"<i>{it.get('text', '')}</i>"
|
| 113 |
+
elif kind == "poke":
|
| 114 |
+
line = f"<b>[{it.get('label', 'POKE')}]</b> {it.get('text', '')}"
|
| 115 |
+
elif kind == "verdict":
|
| 116 |
+
line = f"<b>VERDICT:</b> {it.get('text', '')}"
|
| 117 |
+
else:
|
| 118 |
+
line = it.get("text", "")
|
| 119 |
+
items.append(f"<div class='feed-item feed-{kind}'>{line}</div>")
|
| 120 |
+
return f"<div class='feed'>{''.join(items)}</div>"
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
from src.ui.fishbowl.render.meters import render_meters
|
| 125 |
+
except Exception: # pragma: no cover
|
| 126 |
+
|
| 127 |
+
def render_meters(vm) -> str:
|
| 128 |
+
return (
|
| 129 |
+
"<div class='meters'>"
|
| 130 |
+
f"<span>step {vm.get('step', 0)}/{vm.get('total', 0)}</span> · "
|
| 131 |
+
f"<span>tokens {vm.get('tokens', 0)}</span> · "
|
| 132 |
+
f"<span>round {vm.get('rounds', 1)}</span>"
|
| 133 |
+
"</div>"
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
try:
|
| 138 |
+
from src.ui.fishbowl.render.verdict import render_verdict
|
| 139 |
+
except Exception: # pragma: no cover
|
| 140 |
+
|
| 141 |
+
def render_verdict(vm) -> str:
|
| 142 |
+
v = vm.get("verdict")
|
| 143 |
+
if not v:
|
| 144 |
+
return ""
|
| 145 |
+
return f"<div class='verdict'>{v.get('text', '')}</div>"
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
try: # session: the transport wrapper over a Conductor
|
| 149 |
+
from src.ui.fishbowl.session import FishbowlSession
|
| 150 |
+
except Exception: # pragma: no cover - fallback session keeps the shell live
|
| 151 |
+
|
| 152 |
+
class FishbowlSession:
|
| 153 |
+
"""Minimal transport over a Conductor (real session unit supersedes this).
|
| 154 |
+
|
| 155 |
+
Mirrors the contract the integrator wires against: ``reset(seed)``,
|
| 156 |
+
``step()`` (generate at the head), ``inject(text, label=...)``, and
|
| 157 |
+
``snapshot(k)`` (a pure prefix view via ``view_model_at``)."""
|
| 158 |
+
|
| 159 |
+
def __init__(self, conductor: Conductor, *, scenario_name: str = "") -> None:
|
| 160 |
+
self.conductor = conductor
|
| 161 |
+
self.scenario_name = scenario_name
|
| 162 |
+
|
| 163 |
+
@property
|
| 164 |
+
def head(self) -> int:
|
| 165 |
+
return len(self.conductor.ledger.events)
|
| 166 |
+
|
| 167 |
+
def reset(self, seed: str) -> None:
|
| 168 |
+
self.conductor.reset(seed or self.conductor.scenario.default_seed)
|
| 169 |
+
|
| 170 |
+
def step(self) -> None:
|
| 171 |
+
self.conductor.step()
|
| 172 |
+
|
| 173 |
+
def inject(self, text: str, *, label: str | None = None) -> None:
|
| 174 |
+
if text and text.strip():
|
| 175 |
+
self.conductor.inject_user_event(text.strip(), label=label)
|
| 176 |
+
self.conductor.step()
|
| 177 |
+
|
| 178 |
+
def snapshot(self, k: int | None = None) -> dict:
|
| 179 |
+
events = self.conductor.ledger.events
|
| 180 |
+
kk = self.head if k is None else max(0, min(int(k), len(events)))
|
| 181 |
+
scn = self.conductor.scenario
|
| 182 |
+
# view_model_at wants AgentManifests; agents carry theirs on .manifest.
|
| 183 |
+
cast = [getattr(a, "manifest", a) for a in scn.agents]
|
| 184 |
+
return view_model_at(
|
| 185 |
+
events,
|
| 186 |
+
kk,
|
| 187 |
+
cast,
|
| 188 |
+
scenario_name=self.scenario_name,
|
| 189 |
+
goal=getattr(scn, "goal", ""),
|
| 190 |
+
governor=self.conductor.governor,
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
try: # the two tab bodies (leaf units own their internals)
|
| 195 |
+
from src.ui.fishbowl.show import build_show
|
| 196 |
+
except Exception: # pragma: no cover
|
| 197 |
+
|
| 198 |
+
def build_show():
|
| 199 |
+
gr.HTML(
|
| 200 |
+
"<div class='fishbowl-placeholder'>The Show stage loads here once the <code>show</code> unit lands.</div>"
|
| 201 |
+
)
|
| 202 |
+
return {}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
try:
|
| 206 |
+
from src.ui.fishbowl.lab import build_lab
|
| 207 |
+
except Exception: # pragma: no cover
|
| 208 |
+
|
| 209 |
+
def build_lab():
|
| 210 |
+
gr.HTML(
|
| 211 |
+
"<div class='fishbowl-placeholder'>The Lab composer loads here once the <code>lab</code> unit lands.</div>"
|
| 212 |
+
)
|
| 213 |
+
return {}
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
# ── scenario registry (assembled from config/, not hardcoded) ───────────────────
|
| 217 |
+
|
| 218 |
+
_registry = default_registry()
|
| 219 |
+
_tools = default_tool_registry()
|
| 220 |
+
|
| 221 |
+
_PREFERRED = ["thousand-token-wood", "mystery-roots", "oracle-grove"]
|
| 222 |
+
_names = [n for n in _PREFERRED if n in _registry.scenarios] + [
|
| 223 |
+
n for n in sorted(_registry.scenarios) if n not in _PREFERRED
|
| 224 |
+
]
|
| 225 |
+
# display title -> internal scenario name
|
| 226 |
+
SCENARIOS: dict[str, str] = {(_registry.scenarios[n].title or n): n for n in _names}
|
| 227 |
+
_DEFAULT_TITLE = next(iter(SCENARIOS), "")
|
| 228 |
+
|
| 229 |
+
# Transport speeds → gr.Timer interval (seconds). Keys mirror the speed radio.
|
| 230 |
+
SPEEDS: dict[str, float] = {"live": 3.0, "1×": 1.9, "fast": 1.0}
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
# ── session lifecycle (a fresh Conductor + session per Summon) ──────────────────
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def _new_session(scenario_name: str) -> FishbowlSession:
|
| 237 |
+
conductor = Conductor(
|
| 238 |
+
_registry.build_scenario(scenario_name, tools=_tools),
|
| 239 |
+
governor=_registry.governor_for(scenario_name),
|
| 240 |
+
ledger=make_ledger(),
|
| 241 |
+
)
|
| 242 |
+
return FishbowlSession(conductor, scenario_name=scenario_name)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def _empty_vm() -> dict:
|
| 246 |
+
"""A safe, empty view-model so the Show renders before the first Summon."""
|
| 247 |
+
return {"step": 0, "total": 0, "cast": [], "feed": [], "verdict": None, "rounds": 1, "tokens": 0}
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
# ── HTML composition (this worker owns this) ────────────────────────────────────
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def render_show_html(
|
| 254 |
+
vm: dict, *, layout: str = "constellation", mind_reader: bool = False
|
| 255 |
+
) -> tuple[str, str, str, str]:
|
| 256 |
+
"""Compose the Show's four HTML panes from a view-model snapshot.
|
| 257 |
+
|
| 258 |
+
Returns ``(stage, feed, meters, verdict)``. The stage honours the layout radio:
|
| 259 |
+
*constellation* (MindCards), *split* (omniscient table), or *feed* (feed-only)."""
|
| 260 |
+
cards_html_by_id: dict[str, str] = {}
|
| 261 |
+
for card in vm.get("cast", []):
|
| 262 |
+
cards_html_by_id[card.get("id", card.get("name", ""))] = render_mindcard(card, mind_reader=mind_reader)
|
| 263 |
+
|
| 264 |
+
if layout == "split":
|
| 265 |
+
stage = render_split(vm)
|
| 266 |
+
elif layout == "feed":
|
| 267 |
+
stage = render_feed(vm, mind_reader=mind_reader)
|
| 268 |
+
else: # constellation (default)
|
| 269 |
+
stage = render_constellation(vm, cards_html_by_id)
|
| 270 |
+
|
| 271 |
+
feed = render_feed(vm, mind_reader=mind_reader)
|
| 272 |
+
meters = render_meters(vm)
|
| 273 |
+
verdict = render_verdict(vm)
|
| 274 |
+
return stage, feed, meters, verdict
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def _render_at(session: FishbowlSession | None, k: int, *, layout: str, mind_reader: bool) -> tuple[str, str, str, str]:
|
| 278 |
+
"""Render the Show at play-head *k* (pure prefix view), or empty if no session."""
|
| 279 |
+
vm = session.snapshot(k) if session is not None else _empty_vm()
|
| 280 |
+
return render_show_html(vm, layout=layout, mind_reader=mind_reader)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# ── CRT theater chrome ──────────────────────────────────────────────────────────
|
| 284 |
+
|
| 285 |
+
_TOPBAR_HTML = """
|
| 286 |
+
<div class="fishbowl-topbar topbar">
|
| 287 |
+
<span class="logo">◉ FISHBOWL</span>
|
| 288 |
+
<span class="sub">a fishbowl of minds you can read</span>
|
| 289 |
+
</div>
|
| 290 |
+
"""
|
| 291 |
+
|
| 292 |
+
# The CSS expects these overlay layers (ui/raw/Fishbowl.html).
|
| 293 |
+
_CRT_BG_HTML = '<div class="crt-bg"></div><div class="crt-grid"></div>'
|
| 294 |
+
_CRT_FG_HTML = '<div class="crt-scan"></div><div class="crt-vignette"></div>'
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
# ── app builder ─────────────────────────────────────────────────────────────────
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def build_app() -> gr.Blocks:
|
| 301 |
+
"""Build the two-tab FISHBOWL theater (defensive about absent leaf modules)."""
|
| 302 |
+
# Theme/css/head are applied at launch() time (Gradio 6 moved them off Blocks).
|
| 303 |
+
with gr.Blocks(title="FISHBOWL — a fishbowl of minds you can read") as demo:
|
| 304 |
+
# CRT background layers (behind everything).
|
| 305 |
+
gr.HTML(_CRT_BG_HTML)
|
| 306 |
+
# Branding top bar.
|
| 307 |
+
gr.HTML(_TOPBAR_HTML)
|
| 308 |
+
|
| 309 |
+
# ── per-user state ──────────────────────────────────────────────────────
|
| 310 |
+
session_state = gr.State(None) # FishbowlSession | None
|
| 311 |
+
k_state = gr.State(0) # play-head
|
| 312 |
+
scenario_state = gr.State(_DEFAULT_TITLE)
|
| 313 |
+
mind_reader_state = gr.State(False)
|
| 314 |
+
layout_state = gr.State("constellation")
|
| 315 |
+
blank_state = gr.State("") # stand-in input when a leaf widget is absent
|
| 316 |
+
|
| 317 |
+
with gr.Tabs() as tabs:
|
| 318 |
+
with gr.Tab("The Lab", id="lab"):
|
| 319 |
+
lab_handles = build_lab()
|
| 320 |
+
with gr.Tab("The Show", id="show"):
|
| 321 |
+
show_handles = build_show()
|
| 322 |
+
|
| 323 |
+
# CRT foreground layers (scanlines + vignette, above content, click-through).
|
| 324 |
+
gr.HTML(_CRT_FG_HTML)
|
| 325 |
+
|
| 326 |
+
_wire(
|
| 327 |
+
tabs=tabs,
|
| 328 |
+
lab_handles=lab_handles or {},
|
| 329 |
+
show_handles=show_handles or {},
|
| 330 |
+
session_state=session_state,
|
| 331 |
+
k_state=k_state,
|
| 332 |
+
scenario_state=scenario_state,
|
| 333 |
+
mind_reader_state=mind_reader_state,
|
| 334 |
+
layout_state=layout_state,
|
| 335 |
+
blank_state=blank_state,
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
return demo
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
# ── wiring (the integrator's core job) ──────────────────────────────────────────
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def _h(handles: dict, *names):
|
| 345 |
+
"""First present handle among *names* (leaf units may name things variously)."""
|
| 346 |
+
for n in names:
|
| 347 |
+
if n in handles and handles[n] is not None:
|
| 348 |
+
return handles[n]
|
| 349 |
+
return None
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def _wire(
|
| 353 |
+
*,
|
| 354 |
+
tabs: gr.Tabs,
|
| 355 |
+
lab_handles: dict,
|
| 356 |
+
show_handles: dict,
|
| 357 |
+
session_state: gr.State,
|
| 358 |
+
k_state: gr.State,
|
| 359 |
+
scenario_state: gr.State,
|
| 360 |
+
mind_reader_state: gr.State,
|
| 361 |
+
layout_state: gr.State,
|
| 362 |
+
blank_state: gr.State,
|
| 363 |
+
) -> None:
|
| 364 |
+
"""Connect Lab/Show component handles to session transport + HTML re-render.
|
| 365 |
+
|
| 366 |
+
Every handle lookup is defensive: if a leaf unit doesn't expose a widget yet, the
|
| 367 |
+
corresponding wiring is simply skipped so the shell still builds and runs."""
|
| 368 |
+
# Show output panes (rendered HTML).
|
| 369 |
+
stage_out = _h(show_handles, "stage", "stage_html", "constellation")
|
| 370 |
+
feed_out = _h(show_handles, "feed", "feed_html")
|
| 371 |
+
meters_out = _h(show_handles, "meters", "meters_html")
|
| 372 |
+
verdict_out = _h(show_handles, "verdict", "verdict_html")
|
| 373 |
+
show_outs = [c for c in (stage_out, feed_out, meters_out, verdict_out) if c is not None]
|
| 374 |
+
|
| 375 |
+
# Show transport controls.
|
| 376 |
+
timer = _h(show_handles, "timer")
|
| 377 |
+
scrubber = _h(show_handles, "scrubber", "slider", "scrub")
|
| 378 |
+
play_btn = _h(show_handles, "play", "play_btn")
|
| 379 |
+
step_btn = _h(show_handles, "step", "step_btn", "next", "advance")
|
| 380 |
+
back_btn = _h(show_handles, "rewind", "back", "to_start", "first")
|
| 381 |
+
speed_radio = _h(show_handles, "speed", "speed_radio")
|
| 382 |
+
layout_radio = _h(show_handles, "layout", "layout_radio")
|
| 383 |
+
mind_toggle = _h(show_handles, "mind_reader", "read_minds", "minds")
|
| 384 |
+
poke_send = _h(show_handles, "poke_send", "poke_btn", "poke")
|
| 385 |
+
poke_text = _h(show_handles, "poke_text", "poke_input")
|
| 386 |
+
poke_buttons = show_handles.get("poke_buttons") or []
|
| 387 |
+
|
| 388 |
+
# Lab controls.
|
| 389 |
+
summon_btn = _h(lab_handles, "summon", "summon_btn", "launch", "start")
|
| 390 |
+
scenario_in = _h(lab_handles, "scenario", "scenario_select", "scenario_dropdown")
|
| 391 |
+
seed_in = _h(lab_handles, "seed", "seed_in", "world_seed")
|
| 392 |
+
|
| 393 |
+
def _scenario_title(value) -> str:
|
| 394 |
+
"""Resolve a Lab scenario selection (title or internal name) to a title key."""
|
| 395 |
+
if value in SCENARIOS:
|
| 396 |
+
return value
|
| 397 |
+
for title, name in SCENARIOS.items():
|
| 398 |
+
if value == name:
|
| 399 |
+
return title
|
| 400 |
+
return _DEFAULT_TITLE
|
| 401 |
+
|
| 402 |
+
# ── Summon: build a fresh session, reset, jump to the Show, render head ──────
|
| 403 |
+
def on_summon(scenario_value, seed_value, layout, mind_reader):
|
| 404 |
+
title = _scenario_title(scenario_value)
|
| 405 |
+
name = SCENARIOS.get(title, "")
|
| 406 |
+
session = _new_session(name) if name else None
|
| 407 |
+
if session is not None:
|
| 408 |
+
session.reset((seed_value or "").strip())
|
| 409 |
+
k = session.head
|
| 410 |
+
else:
|
| 411 |
+
k = 0
|
| 412 |
+
out = _render_at(session, k, layout=layout, mind_reader=mind_reader)
|
| 413 |
+
return (session, k, title, gr.update(selected="show"), *_pad_values(out, show_outs))
|
| 414 |
+
|
| 415 |
+
if summon_btn is not None:
|
| 416 |
+
summon_inputs = [
|
| 417 |
+
scenario_in if scenario_in is not None else scenario_state,
|
| 418 |
+
seed_in if seed_in is not None else blank_state, # empty seed when no widget
|
| 419 |
+
layout_state,
|
| 420 |
+
mind_reader_state,
|
| 421 |
+
]
|
| 422 |
+
summon_btn.click(
|
| 423 |
+
on_summon,
|
| 424 |
+
inputs=summon_inputs,
|
| 425 |
+
outputs=[session_state, k_state, scenario_state, tabs, *show_outs],
|
| 426 |
+
)
|
| 427 |
+
|
| 428 |
+
# ── ⏭ / ▶ at head → step (generate) then render at the new head ─────────────
|
| 429 |
+
def step_at_head(session, layout, mind_reader):
|
| 430 |
+
if session is not None:
|
| 431 |
+
session.step()
|
| 432 |
+
k = session.head
|
| 433 |
+
else:
|
| 434 |
+
k = 0
|
| 435 |
+
out = _render_at(session, k, layout=layout, mind_reader=mind_reader)
|
| 436 |
+
return (k, *_pad_values(out, show_outs))
|
| 437 |
+
|
| 438 |
+
if step_btn is not None and show_outs:
|
| 439 |
+
step_btn.click(
|
| 440 |
+
step_at_head,
|
| 441 |
+
inputs=[session_state, layout_state, mind_reader_state],
|
| 442 |
+
outputs=[k_state, *show_outs],
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
# ── scrubber / ⏮ → pure prefix view (no stepping) ───────────────────────────
|
| 446 |
+
def scrub_to(session, k, layout, mind_reader):
|
| 447 |
+
kk = int(k or 0)
|
| 448 |
+
out = _render_at(session, kk, layout=layout, mind_reader=mind_reader)
|
| 449 |
+
return (kk, *_pad_values(out, show_outs))
|
| 450 |
+
|
| 451 |
+
if scrubber is not None and show_outs:
|
| 452 |
+
scrubber.change(
|
| 453 |
+
scrub_to,
|
| 454 |
+
inputs=[session_state, scrubber, layout_state, mind_reader_state],
|
| 455 |
+
outputs=[k_state, *show_outs],
|
| 456 |
+
)
|
| 457 |
+
|
| 458 |
+
def to_start(session, layout, mind_reader):
|
| 459 |
+
out = _render_at(session, 0, layout=layout, mind_reader=mind_reader)
|
| 460 |
+
return (0, *_pad_values(out, show_outs))
|
| 461 |
+
|
| 462 |
+
if back_btn is not None and show_outs:
|
| 463 |
+
back_btn.click(
|
| 464 |
+
to_start,
|
| 465 |
+
inputs=[session_state, layout_state, mind_reader_state],
|
| 466 |
+
outputs=[k_state, *show_outs],
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
# ── gr.Timer.tick → hybrid: advance k (replay) below head, else step ────────
|
| 470 |
+
def on_tick(session, k, layout, mind_reader):
|
| 471 |
+
k = int(k or 0)
|
| 472 |
+
if session is None:
|
| 473 |
+
out = _render_at(None, 0, layout=layout, mind_reader=mind_reader)
|
| 474 |
+
return (0, *_pad_values(out, show_outs))
|
| 475 |
+
if k < session.head:
|
| 476 |
+
k += 1 # replay forward through the existing prefix
|
| 477 |
+
else:
|
| 478 |
+
session.step() # at the head → generate
|
| 479 |
+
k = session.head
|
| 480 |
+
out = _render_at(session, k, layout=layout, mind_reader=mind_reader)
|
| 481 |
+
return (k, *_pad_values(out, show_outs))
|
| 482 |
+
|
| 483 |
+
if timer is not None and show_outs:
|
| 484 |
+
timer.tick(
|
| 485 |
+
on_tick,
|
| 486 |
+
inputs=[session_state, k_state, layout_state, mind_reader_state],
|
| 487 |
+
outputs=[k_state, *show_outs],
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
# ── speed radio → timer interval; play/pause → timer.active ──────────────────
|
| 491 |
+
if speed_radio is not None and timer is not None:
|
| 492 |
+
|
| 493 |
+
def on_speed(speed):
|
| 494 |
+
return gr.update(value=SPEEDS.get(speed, SPEEDS["1×"]))
|
| 495 |
+
|
| 496 |
+
speed_radio.change(on_speed, inputs=[speed_radio], outputs=[timer])
|
| 497 |
+
|
| 498 |
+
if play_btn is not None and timer is not None:
|
| 499 |
+
# A tiny state tracks timer activity so the same button toggles play/pause.
|
| 500 |
+
play_active = gr.State(False)
|
| 501 |
+
|
| 502 |
+
def on_play(active):
|
| 503 |
+
new = not bool(active)
|
| 504 |
+
return new, gr.update(active=new)
|
| 505 |
+
|
| 506 |
+
play_btn.click(on_play, inputs=[play_active], outputs=[play_active, timer])
|
| 507 |
+
|
| 508 |
+
# ── layout radio + "Read their minds" → re-render the stage HTML ─────────────
|
| 509 |
+
if layout_radio is not None and show_outs:
|
| 510 |
+
|
| 511 |
+
def on_layout(value, session, k, mind_reader):
|
| 512 |
+
out = _render_at(session, int(k or 0), layout=value, mind_reader=mind_reader)
|
| 513 |
+
return (value, *_pad_values(out, show_outs))
|
| 514 |
+
|
| 515 |
+
layout_radio.change(
|
| 516 |
+
on_layout,
|
| 517 |
+
inputs=[layout_radio, session_state, k_state, mind_reader_state],
|
| 518 |
+
outputs=[layout_state, *show_outs],
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
if mind_toggle is not None and show_outs:
|
| 522 |
+
|
| 523 |
+
def on_minds(value, session, k, layout):
|
| 524 |
+
out = _render_at(session, int(k or 0), layout=layout, mind_reader=bool(value))
|
| 525 |
+
return (bool(value), *_pad_values(out, show_outs))
|
| 526 |
+
|
| 527 |
+
mind_toggle.change(
|
| 528 |
+
on_minds,
|
| 529 |
+
inputs=[mind_toggle, session_state, k_state, layout_state],
|
| 530 |
+
outputs=[mind_reader_state, *show_outs],
|
| 531 |
+
)
|
| 532 |
+
|
| 533 |
+
# ── poke buttons / poke_send → inject then render at the new head ────────────
|
| 534 |
+
def _poke_after(session, text, label_value, layout, mind_reader):
|
| 535 |
+
if session is not None:
|
| 536 |
+
session.inject((text or ""), label=label_value)
|
| 537 |
+
k = session.head
|
| 538 |
+
else:
|
| 539 |
+
k = 0
|
| 540 |
+
out = _render_at(session, k, layout=layout, mind_reader=mind_reader)
|
| 541 |
+
return (k, *_pad_values(out, show_outs))
|
| 542 |
+
|
| 543 |
+
if poke_send is not None and poke_text is not None and show_outs:
|
| 544 |
+
# Free-text poke: the textbox supplies the text; a neutral label.
|
| 545 |
+
def on_poke_send(session, text, layout, mind_reader):
|
| 546 |
+
return _poke_after(session, text, None, layout, mind_reader)
|
| 547 |
+
|
| 548 |
+
poke_send.click(
|
| 549 |
+
on_poke_send,
|
| 550 |
+
inputs=[session_state, poke_text, layout_state, mind_reader_state],
|
| 551 |
+
outputs=[k_state, *show_outs],
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
for btn in poke_buttons:
|
| 555 |
+
if btn is None or not show_outs:
|
| 556 |
+
continue
|
| 557 |
+
# Preset poke buttons: the button's own label is both the disturbance text
|
| 558 |
+
# and its label; capture it per-button so each button injects its own.
|
| 559 |
+
label = str(getattr(btn, "value", None) or "DISTURBANCE")
|
| 560 |
+
|
| 561 |
+
def make_preset(label_value: str):
|
| 562 |
+
def _on_preset(session, layout, mind_reader):
|
| 563 |
+
return _poke_after(session, label_value, label_value, layout, mind_reader)
|
| 564 |
+
|
| 565 |
+
return _on_preset
|
| 566 |
+
|
| 567 |
+
btn.click(
|
| 568 |
+
make_preset(label),
|
| 569 |
+
inputs=[session_state, layout_state, mind_reader_state],
|
| 570 |
+
outputs=[k_state, *show_outs],
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
# ── small output helper (keep emitted values aligned to present panes) ──────────
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def _pad_values(values, show_outs: list) -> tuple:
|
| 578 |
+
"""Trim a (stage, feed, meters, verdict) tuple to the present panes' count."""
|
| 579 |
+
return tuple(values[: len(show_outs)])
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
# ── dev server port (ported from the original root app.py) ──────────────────────
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
def dev_server_port() -> int:
|
| 586 |
+
configured = os.getenv("GRADIO_SERVER_PORT")
|
| 587 |
+
if configured:
|
| 588 |
+
return int(configured)
|
| 589 |
+
for port in range(7960, 8060):
|
| 590 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 591 |
+
try:
|
| 592 |
+
sock.bind(("127.0.0.1", port))
|
| 593 |
+
return port
|
| 594 |
+
except OSError:
|
| 595 |
+
continue
|
| 596 |
+
raise RuntimeError("No free development port found in range 7960-8059.")
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
# ── module-level app + launch ────────────────────────────────────────────────────
|
| 600 |
+
|
| 601 |
+
demo = build_app()
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
def _launch_kwargs() -> dict:
|
| 605 |
+
"""Theme/css/head applied at launch() time (Gradio 6), when available."""
|
| 606 |
+
kwargs: dict = {"css": load_css()}
|
| 607 |
+
if FISHBOWL_HEAD:
|
| 608 |
+
kwargs["head"] = FISHBOWL_HEAD
|
| 609 |
+
theme = FishbowlTheme() if callable(FishbowlTheme) else FishbowlTheme
|
| 610 |
+
if theme is not None:
|
| 611 |
+
kwargs["theme"] = theme
|
| 612 |
+
return kwargs
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
def launch(**overrides):
|
| 616 |
+
"""Launch the FISHBOWL theater with theme/css/head + a free dev port.
|
| 617 |
+
|
| 618 |
+
The single entry point the root shim and ``uv run app.py`` call; keeps the
|
| 619 |
+
no-API-key offline behaviour (the deterministic stub drives the cast)."""
|
| 620 |
+
kwargs = {"server_port": dev_server_port(), **_launch_kwargs(), **overrides}
|
| 621 |
+
return demo.launch(**kwargs)
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
if __name__ == "__main__":
|
| 625 |
+
launch()
|
tests/test_fishbowl_app.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The FISHBOWL Gradio shell builds standalone (Unit 9) — mock-free.
|
| 2 |
+
|
| 3 |
+
These tests exercise the *integrator* surface only: that the two-tab Blocks builds even
|
| 4 |
+
when every leaf module (theme/render/session/show/lab) is absent (defensive placeholders),
|
| 5 |
+
that the package import stays Gradio-free, that the root shim re-exports the app, and that
|
| 6 |
+
the HTML-composition + fallback-session transport work end-to-end offline (no API key).
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import gradio as gr
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def test_build_app_builds_with_placeholders() -> None:
|
| 15 |
+
from src.ui.fishbowl.app import build_app
|
| 16 |
+
|
| 17 |
+
demo = build_app()
|
| 18 |
+
assert isinstance(demo, gr.Blocks)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_module_level_demo_exists() -> None:
|
| 22 |
+
from src.ui.fishbowl.app import demo
|
| 23 |
+
|
| 24 |
+
assert isinstance(demo, gr.Blocks)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_package_import_is_gradio_free() -> None:
|
| 28 |
+
"""Importing the package must not pull in Gradio (pure presenter promise)."""
|
| 29 |
+
import subprocess
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
result = subprocess.run(
|
| 33 |
+
[sys.executable, "-c", "import src.ui.fishbowl, sys; print('gradio' in sys.modules)"],
|
| 34 |
+
capture_output=True,
|
| 35 |
+
text=True,
|
| 36 |
+
check=True,
|
| 37 |
+
)
|
| 38 |
+
assert result.stdout.strip() == "False"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def test_lazy_exports_resolve() -> None:
|
| 42 |
+
import src.ui.fishbowl as pkg
|
| 43 |
+
|
| 44 |
+
assert callable(pkg.build_app)
|
| 45 |
+
assert isinstance(pkg.demo, gr.Blocks)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def test_root_shim_imports() -> None:
|
| 49 |
+
import app
|
| 50 |
+
|
| 51 |
+
assert isinstance(app.demo, gr.Blocks)
|
| 52 |
+
assert callable(app.launch)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def test_fallback_session_transport_offline() -> None:
|
| 56 |
+
"""The placeholder session steps a real Conductor and snapshots a prefix view."""
|
| 57 |
+
from src.ui.fishbowl.app import SCENARIOS, _new_session
|
| 58 |
+
|
| 59 |
+
name = next(iter(SCENARIOS.values()))
|
| 60 |
+
session = _new_session(name)
|
| 61 |
+
session.reset("") # default seed; genesis events appended
|
| 62 |
+
assert session.head > 0
|
| 63 |
+
|
| 64 |
+
before = session.head
|
| 65 |
+
session.step()
|
| 66 |
+
assert session.head >= before # stepping never rewinds the head
|
| 67 |
+
|
| 68 |
+
vm = session.snapshot(0) # pure prefix view at k=0
|
| 69 |
+
assert vm["step"] == 0
|
| 70 |
+
assert "cast" in vm and "feed" in vm
|
| 71 |
+
|
| 72 |
+
vm_head = session.snapshot(session.head)
|
| 73 |
+
assert vm_head["step"] == session.head
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_render_show_html_returns_four_panes() -> None:
|
| 77 |
+
from src.ui.fishbowl.app import SCENARIOS, _new_session, render_show_html
|
| 78 |
+
|
| 79 |
+
session = _new_session(next(iter(SCENARIOS.values())))
|
| 80 |
+
session.reset("")
|
| 81 |
+
vm = session.snapshot(session.head)
|
| 82 |
+
|
| 83 |
+
panes = render_show_html(vm, layout="constellation", mind_reader=True)
|
| 84 |
+
assert isinstance(panes, tuple) and len(panes) == 4
|
| 85 |
+
assert all(isinstance(p, str) for p in panes)
|
| 86 |
+
|
| 87 |
+
# Each layout produces a string stage without raising.
|
| 88 |
+
for layout in ("constellation", "split", "feed"):
|
| 89 |
+
stage, _feed, _meters, _verdict = render_show_html(vm, layout=layout, mind_reader=False)
|
| 90 |
+
assert isinstance(stage, str)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_inject_appends_a_poke() -> None:
|
| 94 |
+
from src.ui.fishbowl.app import SCENARIOS, _new_session
|
| 95 |
+
|
| 96 |
+
session = _new_session(next(iter(SCENARIOS.values())))
|
| 97 |
+
session.reset("")
|
| 98 |
+
before = session.head
|
| 99 |
+
session.inject("A lantern starts whispering recipes.", label="DISTURBANCE")
|
| 100 |
+
assert session.head > before
|