feat: chained signal composition — 3→1→final + mood mixing

Add compose-metrics.ds (Layer 1): receives counter+clock+stats,
derives uptime/events/status, re-streams on /peer/metrics. This app
is BOTH a receiver and a source.

Add compose-master.ds (Layer 2): receives chained metrics from
Layer 1 + mood direct from Layer 0. Demonstrates multi-layer
signal composition with independent stream mixing.

Verified: Uptime: 51s, Total Events: 9 flowing through the full
three-layer chain to the master dashboard.
This commit is contained in:
enzotar 2026-02-26 09:51:36 -08:00
parent 442a2db65e
commit b5d813b9af
2 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,42 @@
-- DreamStack Chained Composition — Layer 2: Master Dashboard
-- Receives the aggregated metrics (from Layer 1) AND mood (from Layer 0).
--
-- Architecture:
-- Counter ──┐
-- Clock ───┤──► compose-metrics ──┐
-- Stats ───┘ (Layer 1) │
-- ├──► THIS APP (Layer 2)
-- Mood ────────────────────────────┘
--
-- This demonstrates:
-- 1. Chained composition (3 → 1 → final)
-- 2. Multiple layers of signal derivation
-- 3. Mixing independently-sourced streams
--
-- Run with:
-- dreamstack build examples/compose-master.ds
let metrics = stream from "ws://localhost:9100/stream/metrics"
let mood = stream from "ws://localhost:9100/stream/mood"
view main =
column [
text "🏗️ Master Dashboard (Layer 2)"
text "Chained: 3→1→here + mood"
row [
column [
text "── ⚡ Aggregated Metrics ──"
text "(from compose-metrics)"
text "Uptime: {metrics.uptime}s"
text "Total Events: {metrics.events}"
text "Status: {metrics.status}"
]
column [
text "── 😊 Mood (Direct) ──"
text "(from streaming-mood)"
text "Mood: {mood.mood}"
text "Energy: {mood.energy}%"
text "Color: {mood.color}"
]
]
]

View file

@ -0,0 +1,39 @@
-- DreamStack Chained Composition — Layer 1: Metrics Aggregator
-- Receives 3 signal streams, derives combined metrics, re-streams them.
--
-- Architecture:
-- Counter ──┐
-- Clock ───┤──► THIS APP ──► /peer/metrics
-- Stats ───┘
--
-- This app is BOTH a receiver AND a source:
-- - Receives: counter.count, counter.doubled, clock.seconds, stats.total, stats.max
-- - Derives: uptime (from clock), events (from stats+counter), status (combined)
-- - Streams: uptime, events, status on /peer/metrics
--
-- Run with:
-- dreamstack stream examples/compose-metrics.ds --port 3006
let counter = stream from "ws://localhost:9100/stream/counter"
let clock = stream from "ws://localhost:9100/stream/clock"
let stats = stream from "ws://localhost:9100/stream/stats"
-- Derived metrics from upstream streams
let uptime = clock.seconds
let events = counter.count + stats.total
let status = "nominal"
-- Re-stream derived metrics downstream
stream metrics on "ws://localhost:9100/peer/metrics" {
mode: signal,
output: uptime, events, status
}
view metrics =
column [
text "⚡ Metrics Aggregator (Layer 1)"
text "Receives: counter + clock + stats"
text "Uptime: {uptime}s"
text "Total Events: {events}"
text "Status: {status}"
]