Slop: a small animated pea-shaped companion floats above a chat bubble, connected to a local OpenCode service.

You have inherited a repository. And this one is fun.

At a glance: 484×330 px pea · 9 idle actions · 4 signal colours · 0 tools built into the face · 1 local brain · runs on PowerShell 7.6 + WPF.

⚡ TL;DR

Slop is a Windows desktop companion — a small animated character (the "pea") that lives on your screen, chats with you, and delegates everything it cannot do to a local OpenCode service. The face is PowerShell plus WPF. The brain is OpenCode. The one rule that made it work: the face owns nothing but the face. No tool registry, no permission engine, no memory database, no workflow engine. Just a character, a chat surface, and a thin bridge over HTTP plus SSE to a working companion in one development run. The code itself lives in the repository — I am not going to paste it here. I am going to tell you the story, the decisions, and the order.

🎉 Fun Things You Can Do

  • ✨ A desktop companion that lives on your screen and reacts to what you're doing
  • ✨ Teach it to play digital hide and seek - it follows your cursor, hides, peeks
  • ✨ 9 idle actions: hop, sit, stretch, wander, blink, tilt, bounce, peek, yawn
  • ✨ System Sense watches your CPU/RAM/disk and leaves thought bubbles when something's wrong
  • ✨ Expand it into a chat surface with a spring-membrane that wobbles when you drag it

🤔 The Problem

I wanted a companion. Not a chatbot in a browser tab - something that lived on the desktop, had a presence, reacted to what it was doing, and could actually do things. The fun part: it has a personality, idle animations, and system awareness. It feels alive.

Two constraints shaped everything:

  1. Slop is the face. OpenCode is the brain. The face owns nothing but the face. No tool registry, no permission engine, no memory database. Just a character, a chat surface, and a thin bridge.
  2. Headless green does not mean live green. Verify destructive controls against the real backend.

✨ What It Does

Sloppy - Screen-aware Local OpenCode Pal - is a Windows desktop companion. It owns the animated pea, the chat bubble, the input box, and the visual signals. It does not own tools, permissions, memory, web search, browser automation, or workflows. A thin bridge connects Slop's streaming request path to opencode serve, translating OpenCode's events into the deltas and signals Slop already understands.

What it does today:

  • An animated pea with nine idle actions — hop, sit, stretch, wander, blink, tilt, bounce, peek, yawn
  • A chat bubble with streaming text
  • Visual signals: four colours mapped onto four shapes, so you can read the companion's state at a glance
  • In-chat approval cards — Allow once or Reject — for tool use
  • A spring-membrane expanded chat surface built from coupled springs
  • An opt-in System Sense mode that watches CPU, RAM, disk, and processes read-only
  • A resizable and maximisable expanded window that remembers its size

The stack is PowerShell 7.6 LTS, WPF and XAML, with .NET 10 used only for compiled geometry. No separate build step. You run one script.

🏗️ Architecture

Architecture: Slop face connects via HTTP+SSE bridge to OpenCode service, which owns sessions, tools, permissions, and MCP servers.

The shape is simple. The face talks to the brain over HTTP plus Server-Sent Events. The brain owns sessions, agents, tools, permissions, MCP servers, web search, and shell execution. The face owns the pea, the bubble, and the signals.

The rule that made it work is the "does not build" list. Slop does not build a tool registry. It does not build a permission engine. It does not build a conversation or memory database. It does not build a web-search client, a browser driver, or a Windows automation layer. It does not build a workflow engine. Every capability arrives through OpenCode. Adding a capability is an MCP server or a Markdown agent, not a new subsystem.

Why this over the alternatives

I evaluated four options before settling on the bridge.

The first was to build everything inside Slop. Full control, no external dependency. But it duplicates OpenCode feature for feature. PowerShell is a poor home for Playwright, UI Automation, and web search. Months of work before the first useful capability. I rejected it because the capabilities are commodity infrastructure.

The second was to connect to OpenCode. All five capabilities arrive at once. Permissions and activity logging come for free. Local-first by default. Adding a capability is configuration, not code. The cost is that OpenCode must be running, some routes are experimental, and replies can taste like coding unless you give it a companion persona. I accepted it because it is the largest capability gain for the smallest amount of new code.

The third was a fully local custom assistant. Maximum independence and privacy. But model capability becomes the ceiling, and you still build the whole tool stack. I rejected it because OpenCode can be configured with local providers too, so it buys little.

The fourth was to rewrite Slop in TypeScript around the OpenCode SDK. In-process host, no network hop. But it loses the existing WPF character renderer and the verified live verifier. Effectively a rewrite. I rejected it as a future frontend option, not as the path to capabilities.

🎁 What You Inherit

The repository has a specific shape. Here is what lives where and why it matters.

The src folder holds the face. Slop.ps1 is the entry point: the WPF window, the timer loop, the settings UI, and the wiring. Slop.Frame.ps1 holds the spring-membrane geometry. Slop.Face.ps1 holds face patterns and idle actions. Slop.Motion.ps1 holds motion and wander. Slop.Lifecycle.ps1 is the request lifecycle, SSE parsing, and cancellation — and it is pure, no WPF, no backend, so it can be tested headlessly. Slop.OpenCode.ps1 is the bridge adapter. Slop.Sense.ps1 is the opt-in System Sense. Slop.Config.ps1 is the portable configuration layer.

The tests folder holds headless assertion suites. The tools folder holds the live verifier and the process control script. The docs folder holds the architecture decision record and the build-order plan. The .opencode folder holds the agent definition and permissions.

The key invariant is that the lifecycle module is pure. No WPF, no backend. That is what makes it testable. If you are rebuilding, keep that boundary. It is the single most important structural decision in the repo.

💡 Core Ideas

The lifecycle module is the hard part

The hardest lesson in this repo is that headless tests do not prove live behaviour. Early on, both lifecycle and motion suites were green while the live app was broken. The DispatcherTimer handler silently dropped generation and queue variables because PowerShell event handlers do not close over function locals. The timer saw null and dropped every stream event. The bubble stayed empty. Amber hang.

The fix is to publish values to script scope and re-read them inside the handler. Never use GetNewClosure — it captures locals but rebinds script scope to an empty dynamic-module scope, breaking every script-scope reference.

The lifecycle module owns phases, a generation guard checked at both enqueue and dequeue boundaries, SSE parsing with malformed-event counting, and unconditional disposal of reader, stream, response, and client in a finally block. If you are rebuilding, write this module first, as pure PowerShell, with no WPF dependency. Test it headlessly before you wire it to anything.

Cancellation that actually cancels

A green headless state-machine suite does not prove Stop works against a real streaming backend. The first live audit exposed a critical failure: invoking Stop at token nine let tokens keep growing from sixteen to three hundred and eighty-one over twelve seconds. The cancellation token was passed only to SendAsync, which had already returned under ResponseHeadersRead. The SSE reader's ReadLine had no token.

The fix is native async reads. PowerShell scriptblocks converted to .NET delegates only run where a runspace exists. When cancellation fires on a threadpool or timer thread, they throw "no runspace available." Use StreamReader.ReadLineAsync with the token instead.

If you are rebuilding, do not trust your cancellation until you have watched it stop a real stream with your own eyes.

The spring membrane

The expanded chat surface is a forty-eight-point coupled-spring membrane. Every point is hard-clamped inside the window. Outward bulge is tanh-saturated so the outline can never be sliced by the window edge. The inner content grid receives no transform, and its rounded clip is rebuilt on size change so maximise never truncates chat.

When users reported the animation as janky, the instinct was to optimise CPU. Measurement showed the pop and stutter was spring design, not performance. A near-undamped spring finishing in six frames with one hundred and thirty pixels per frame reads as stutter even when pure Update cost is a tenth of a millisecond. Retuning damping from roughly zero point five three to roughly zero point nine fixed it. Measure the motion curve before assuming a bottleneck.

Event translation

OpenCode's event schema is still evolving. The bridge treats all four execution-terminal events as final, because version two point three point two emits no session.idle after a rejected permission. Without this, a rejected approval leaves the thread job blocked until request timeout and Send stays disabled.

Dump the raw event stream against the installed version before changing terminal-event handling. Documentation and dev source have already disagreed with live behaviour. This is not optional.

🧭 Key Decisions

Why PowerShell plus WPF over TypeScript

I considered rewriting in TypeScript around the OpenCode SDK for an in-process host with no network hop. It would be faster and cleaner. But it loses the existing WPF character renderer and the verified live verifier. Effectively a rewrite of the whole UI. The WPF shell stays. TypeScript is a future frontend option, not a prerequisite for any capability.

Why no second permission engine

Sloppy inherits OpenCode's permission model. A second engine is a second security surface. The bridge only ever replies once or reject, never always, so Sloppy itself never creates a saved grant. The loopback bind and Basic-auth password remain the primary barrier because several HTTP routes bypass the agent tool layer.

Why approvals in chat, not in the OpenCode TUI

A headless opencode serve has no TUI. A dangling ask would hang until request timeout. So the bridge subscribes to permission.asked, renders the card inline, and replies. Collapse, Stop, generation change, or window close rejects all pending requests.

Why not build a memory database

OpenCode sessions own context. The agent file and skills provide persona and instructions. Adding a Slop-owned memory store would duplicate what already exists. Resolved for this slice: no Slop-owned store.

🚫 Mistakes I Avoided

These are the ones that cost me time. Read them before you start.

Assuming headless green means live green. Two suites were green while the live app dropped every event. Verify destructive controls against the real backend.

Optimising before measuring. The janky animation was spring design, not CPU. Fix the curve, not the processor.

Trusting docs over the installed version. Version two point three point two taught me that. Dump the raw stream first.

PowerShell event handlers do not close over locals. Publish to script scope. Never GetNewClosure.

Naming a module instance after a XAML element. A script-scoped variable named Frame silently overwrote the XAML grid named Frame, crashing ShowDialog with "The property Width cannot be found." Use distinct names and add a shell assertion.

Piping git show through PowerShell. It decodes raw UTF-8 with the console codepage, turning em dashes into mojibake. Use git cat-file blob with raw byte reads instead.

Recreate It: A Lab Walkthrough

This is the part you can read aloud. Each step is verifiable before you move on. The code is in the repository — follow along there.

Step zero — scaffold. Create the folder tree: src, tests, tools, docs, .opencode. Add a minimal WPF window with a thirty-three millisecond timer. Verify the window opens and the timer ticks.

Step one — lifecycle module. Write the lifecycle as pure PowerShell. No WPF, no backend. Phases, generation guard, SSE parser, finally disposal, cancellation via ReadLineAsync with a token. Write headless assertions. Verify every lifecycle test passes before touching anything else. This is the foundation. Everything depends on it.

Step two — face and motion. Add the pea at four hundred and eighty-four by three hundred and thirty pixels. Nine idle actions. Breathing and sway. Reduced-motion support. Verify the live verifier shows idle animation.

Step three — OpenCode bridge. Write the adapter: session create, prompt send, event translation, interrupt. Test against a real opencode serve. Verify a message round-trips and streams.

Step four — signal mapping. Map OpenCode events to four colours and four shapes. Add approval cards. The bridge replies once or reject only, never always. Verify a tool call shows a card and Allow once runs it.

Step five — spring membrane. Port the forty-eight-point spring membrane. Hard clamp. Tanh saturation. SizeChanged clip rebuild. Verify expand, drag, maximise, and restore all pass in the live verifier.

Step six — System Sense, optional. Read-only. One scan per minute. At most one bubble. Five-minute cooldown per alert. Never takes action, spawns jobs, or contacts the network. Verify toggle on and off with no network calls.

Step seven — hardening. Configure the agent, workspace scope, nine fetch denies, credential-read denies. The tripwire validates before accepting a prompt. Verify startslop syncs config and the tripwire passes.

Step eight — tests and verification. Convert headless suites to Pester. Add an aggregator so the verify gate runs them all. Run the full verify. Verify all gates green, live verifier exit zero, clean teardown with no orphaned processes.

🚀 Quick Start

You need Windows, PowerShell 7.6 or later in STA mode, and a local OpenCode service. Then:

Start the OpenCode service. Launch Slop with pwsh -STA -File src/Slop.ps1. The pea appears. Type a message. Watch it stream.

✅ Verification

The repository ships with a verify ritual that auto-detects tests, typecheck, and lint. Three hundred and forty-two Pester cases pass. The live verifier exercises expand, maximise, restore, chat, escape, and drag with clean teardown. Degradation check: if OpenCode is down, Slop shows a connection error and the pea stays idle — no crash. Privacy check: no credentials in logs; the service password is read at runtime from OpenCode's own persisted config, never stored in source.

📌 Takeaways

The face owns nothing but the face. Delegate commodity infrastructure. Your differentiator is the character, not the tool registry.

Headless green does not mean live green. Verify destructive controls against the real backend.

Measure before optimising. A six-frame spring pop reads as stutter at a tenth of a millisecond of Update cost. Fix the curve, not the CPU.

Docs lie about event semantics. Dump the raw stream against the installed version.

PowerShell event handlers do not close over locals. Publish to script scope.

Name collisions between script scope and XAML names are silent killers. Use distinct names and assert.

🔗 Links

  • Repo: Sloppy
  • Architecture: docs/architecture.md
  • Build order: docs/plans/build-order.md