Compline:以 Gemma 2、即時 3D 星盤與黑膠雜音打造離線哥德式助眠空間
Compline: The Radical Laziness of Sleep — Building an Offline Gothic Sanctuary with Gemma 2, a Real-Time 3D Astrolabe, and Vinyl Crackle
Compline 是一款離線哥德式睡前放鬆應用,結合本機 Gemma 2、即時 3D 星盤與黑膠唱片雜音,提供睡前故事及夜間樂曲。故事可由 Ollama 本機 Gemma 2(gemma2:2b / 9b)生成;無網絡時則由離線生成器創作故事。星盤呈現 89 個星座及 7 顆行星,並按裝置地理位置對照實際夜空。
This is my submission for the Hacktoberfest Open-Source AI Challenge, Week 3: Slow and Steady. 🦥
I'm Arnav, from Bengaluru. For Week 1's "Touch Grass" challenge, I built WildTrail to get people outdoors. For Week 2's "Side Hustle", I built GhostLedger for sovereign freelancer tax intelligence.
For Week 3, the prompt honors International Sloth Day:
"Build something with open-weight models or open-source AI that rewards laziness: a tool for relaxation, an automation for a task you dread, or anything that makes life easier."
One of the challenge's suggested sparks caught my eye immediately:
"A wind-down companion that generates a calming bedtime story or ambient soundscape, running entirely offline."
So I decided to lean fully into radical laziness and built Compline: a candlelit gothic wind-down companion that transforms your nightstand into an ancient, tranquil monastic scriptorium.
- 🌌 Live Web App: https://complineapp.vercel.app
- 💻 Open-Source Repository (MIT): https://github.com/XiaoArnav/complineapp
🦥 The Lazy Payoff
Falling asleep in the modern world is an exhausting, high-friction chore:
- Decision fatigue: You scroll endless Netflix menus, podcast libraries, or algorithmic YouTube feeds just trying to pick something relaxing.
- Blue light bombardment: Bright modern interfaces, push notifications, and recommendation carousels stimulate your brain when you should be slowing down.
- SaaS extortion: Sleep apps want $14.99/month, demand account signups, gate basic rainfall audio behind paywalls, and send your bedroom telemetry to cloud servers.
Sloths have it figured out: move at your own pace, conserve your energy, and let the universe come to you.
With Compline, going to sleep requires zero cognitive effort:
- You open the app in pitch darkness. Tap once. A match strikes, a candle flame flickers to life, and warm amber light floods the sanctuary.
- The Abbey Phonograph drops its physical needle onto a spinning vinyl platter, filling your room with authentic analog crackle and choral vespers.
- Google's open-weight Gemma 2 running locally (or our built-in offline hypnagogic generator) streams an unhurried medieval tale word-by-word with illuminated drop-caps and drying golden ink.
- A 3D celestial astrolabe queries your device's geolocation to orient the 89 classical constellations and 7 wandering planets to match the exact night sky directly above your roof.
- You don't search. You don't swipe. You don't configure. You just close your eyes.
🏛️ What I Built: The Gothic Nightstand Experience
flowchart TD
subgraph Client ["Gothic Nightstand Sanctuary (Zero Dependencies)"]
Candle["🕯️ Cinematic Candle Ritual (Match-Strike / Blackout)"]
Astrolabe["🧭 3D Celestial Astrolabe (Real Sky LST Alignment)"]
Phono["📻 Abbey Phonograph (The Needle & The Groove)"]
Scribe["📜 Scriptorium Tome (Illuminated Ink Stream)"]
Tarot["⚙️ Wheel of Fate & Gothic Slumber Tarot"]
Grimoire["📖 Scriptorium Grimoire (Local Bookmark Storage)"]
end
subgraph AudioEngine ["Web Audio Procedural Engine"]
Needle["📍 Needle Drop & Arm Physics"]
Crackle["🪵 Vintage Surface Crackle (Pink Noise + Lowpass)"]
Tracks["💿 Opus I: Nocturne / Opus II: Vespers"]
end
subgraph AI ["Open-Source AI & Hypnagogic Core"]
Gemma["🧠 Google Gemma 2 (Local Ollama gemma2:2b / 9b)"]
Offline["🕯️ Offline Hypnagogic Decrescendo Generator"]
end
Candle --> Astrolabe
Phono --> AudioEngine
Scribe --> AI1. 🌌 3D Celestial Astrolabe & "Tonight's Real Sky" Alignment
The nightstand sky isn't a generic looping starry wallpaper. It is an interactive 3D celestial sphere rendering 89 classical constellations (Ursa Major, Cygnus, Orion, Cassiopeia, Lyra, Taurus...), armillary coordinate rings, and the 7 classical wandering planets.
Tapping the dedicated [🌌 Tonight's Real Sky] header button queries your browser's Geolocation API, calculates the exact Greenwich Sidereal Time (GST) and Local Sidereal Time (LST) for your longitude, and rotates the entire celestial sphere so that the stars above your bed match what is overhead in reality.
2. 📻 The Abbey Phonograph (The Needle & The Groove)
A tactile analog player built entirely on the native Web Audio API:
- Physical Needle Drops: Interactive tone-arm mechanics with authentic physical needle-drop thuds and lift-off crackles.
- Vintage Surface Noise: A procedural audio synthesis pipeline (pink noise passed through highpass and biquad filters) that recreates warm vinyl record crackle.
-
The Sacred Repertoire: Integrated with atmospheric nocturnal arrangements:
- Opus I: Abbey Nocturne — Solitary nocturnal piano & cello.
- Opus II: Gothic Vespers — Sanctuary bells & ethereal Gregorian choral harmonies.
3. 📜 Scriptorium Story Generator & Hypnagogic Decrescendo
Bedtime stories should never have cliffhangers, sudden shocks, or escalating conflict. Compline connects to local Gemma 2 (via Ollama at http://localhost:11434) using structured relaxation prompts designed around hypnagogic decrescendo:
- Focuses entirely on rich, sensory descriptions (moss-covered stone arches, distant rainfall, flickering beeswax, cedar incense).
- Streams word-by-word with animated glowing quill cursors, illuminated rubricated drop-caps, and a simulated wet ink drying effect.
- If Ollama is offline or you're in airplane mode, a procedural Markovian offline scriptorium generates endless non-repeating bedtime tales without needing any internet connection.
4. ⚙️ Wheel of Fate & Gothic Slumber Tarot
An ornate brass-and-stained-glass mechanical wheel with procedural ratchet audio. Giving it a gentle spin draws from an 8-card Gothic Slumber Tarot deck (The Hermit of the Bell Tower, The Alchemist's Crucible, The Scribe of Midnight...) to seed the night's meditation.
5. 📖 Scriptorium Grimoire
Sleepers can bookmark chapters directly to their personal Grimoire, stored privately in the browser's local storage with zero cloud accounts.
🧠 Why Open Innovation & Gemma 2 Matter Here
In the DEV community discussion on running local LLMs, developer Kennedy Raju noted that side projects rarely need an external API key when open-weight models have gotten this good. And as highlighted in recent local AI benchmarks, running smaller models locally achieves real-time streaming speeds with zero network overhead.
Compline only works as a true sleep companion because of open-weight models:
- Sacred Bedroom Privacy: Bedtime thoughts, sleep schedules, and relaxation habits are deeply intimate. With Gemma 2 running locally, no prompts, reading history, or timestamps ever leave your room.
- Airplane Mode Safe: You can put your laptop or phone in full Airplane Mode to avoid late-night notifications, and Compline continues to write new stories, play vinyl audio, and chart the cosmos.
- Zero Marginal Cost: Cloud AI APIs charge per token. A bedtime app running streaming models all night on proprietary cloud APIs would bleed developer money or force obnoxious $15/month subscriptions onto tired users. Gemma 2 is 100% free to run.
🛠️ What Went Wrong (The Engineering Hurdles)
Just like my previous challenge submissions, I made a commitment to test every detail and inspect real network and runtime behavior. That uncovered three tricky technical challenges:
1. The Vercel Edge Node Cache Ghost Trap
After deploying a critical UI fix, I visited the live Vercel URL and noticed the changes weren't appearing. Opening terminal and inspecting HTTP response headers with curl -sI https://complineapp.vercel.app/ revealed the culprit:
HTTP/2 200
age: 558
cache-control: public, max-age=0, must-revalidate
x-vercel-cache: HIT
Even with max-age=0, Vercel edge nodes (like bom1 in India) cache static assets at the CDN layer unless explicitly told otherwise. The fix was updating vercel.json to enforce edge invalidation across all routes:
{
\"headers\": [
{\n \"source\": \"/(.*)\",\n \"headers\": [\n {\n \"key\": \"Cache-Control\",\n \"value\": \"no-cache, no-store, must-revalidate, max-age=0, s-maxage=0\"\n }\n ]\n }\n ]\n}
Setting s-maxage=0 forced edge cache misses (age: 0, x-vercel-cache: MISS) and instant propagation on every new commit!
2. The Celestial Sidereal Time Math
Translating GPS coordinates into an accurate 3D celestial sphere required real celestial mechanics. Standard clock time doesn't match star time because the Earth rotates once relative to the stars in 23 hours, 56 minutes, and 4 seconds (one sidereal day).
To compute the celestial rotation angle, I implemented Greenwich Mean Sidereal Time (GMST) and Local Sidereal Time (LST):
// Calculate Julian Date from UTC
const jd = 2440587.5 + (date.getTime() / 86400000);
const d = jd - 2451545.0; // Days from J2000.0
// Greenwich Mean Sidereal Time in degrees
let gmst = (280.46061837 + 360.98564736629 * d) % 360;
if (gmst < 0) gmst += 360;
// Local Sidereal Time
let lst = (gmst + longitude) % 360;
if (lst < 0) lst += 360;
// Rotate the celestial sphere canvas
const lstHours = lst / 15;
stellarSky.rotationAngle = -(lstHours / 24) * Math.PI * 2;
Now, when you look at Cygnus or Ursa Major in Compline, they are in the exact same orientation as the real night sky outside your window.
3. Killing the Over-Engineered Feature (The Rose Window Prism)
During development, I got excited and spent hours building a volumetric stained-glass god-ray lighting engine (\"Rose Window Prism\"). It rendered animated caustic light shafts and chromatic dust motes across the screen.
When I actually tested it at bedtime, it felt completely wrong:
- It was visually busy and distracted from the calm scriptorium text.
- It caused unnecessary GPU strain on mobile devices.
- It violated the fundamental sloth principle of the challenge: simplicity, calm, and conservation of energy.
So I ruthlessly deleted all 400+ lines of it. Recognizing when to delete code is just as important as knowing what to write. Stripping away the excess left the sanctuary feeling peaceful, quiet, and effortless.
🔍 Behind the Scenes: The Full Agent Session
To give the Hacktoberfest judges a transparent look into how Compline was planned, built, tested, and polished, here is the complete recorded agent session:
- 🔗 Interactive Session on DEV: Compline: Building an Offline Gothic Sleep Sanctuary with Gemma 2 & 3D Astrolabe
🏆 Prize Categories Entered
- Overall Winner: A complete, beautifully crafted wind-down sanctuary engineered specifically for radical laziness, low cognitive load, and effortless sleep.
- Featured Category: Best Use of Gemma ($200): Leverages Google's Gemma 2 open-weight model via Ollama for private, low-tension bedtime storytelling with zero cloud telemetry.
🚀 Try Compline
- 🌌 Live Web Application: https://complineapp.vercel.app
- 💻 GitHub Repository: https://github.com/XiaoArnav/complineapp
To run it locally with zero external dependencies (pure Python 3 standard library):
git clone https://github.com/XiaoArnav/complineapp.git
cd complineapp
python3 app/server.py
Then visit http://localhost:7777.
Connect local Gemma 2 anytime with ollama run gemma2:2b.
May your nights be restful and peaceful. Channel your inner sloth. 🦥✨
來源:DEV Community · dev.to