Zhang Han
All work

Personal project · In development

Cattt

A shared 3D companion app for couples

A shared companion app for couples on iOS and macOS. Tuanzi lives in a 3D felt yard with its own routines and temperament, joining chat, sitting nearby, keeping a diary and handling delegated tasks and reminders in the background.

GitHub repository (opens in a new tab)
On this page
Built
iOS & macOS thin clients · 3D yard · Cloud actor engine · Vectorless memory
Stack
SwiftUI Three.js TypeScript Cloudflare Workers Durable Objects Workflows SQLite FTS5

Product film

Recorded in the iOS Simulator and the web 3D yard · chat and diary use local mock data
Read the video description

The film opens on the felt yard at dusk, with Tuanzi by the mushroom house. By day it walks and rests around the yard; in the iOS app, the yard is the home screen. In Chat, Tuanzi’s replies appear word by word, and long-term memory keeps what you’ve told it. In the evening, today’s diary slides out of the yard’s mailbox, and at night the rain comes in as the yard follows time of day and weather. A closing card sums up what runs underneath: one Cloudflare Durable Object per household, vectorless SQLite FTS5 memory, Workflows for delegated tasks and diaries, APNs pushes and bring-your-own model keys. App footage was recorded in the iOS Simulator with local mock data for chat and diary, without connecting to the cloud or a real model.

Recorded demos

Walk to the pond

Ask Tuanzi to wait by the pond. Tuanzi walks there through the yard, and the app reports its arrival to the backend.

Sit with me

An invitation starts a sit-together action. The yard chooses a seat, and the app confirms that Tuanzi has settled beside the pond.

Remember a preference

Ask Tuanzi to remember that turquoise is your favorite color. Open Long-term Memory to see the saved preference and its original message.

The yard, three spaces and lifecycle

Tuanzi walks, drinks and rests on its own schedule while the yard shifts with time of day and weather. The yard is the home screen, chat opens over the scene, and the mailbox leads to the diary, without streaks, levels or feeding chores. Conversations span three spaces: a shared group chat, private direct chats with Tuanzi, and diaries authorized per entry. Neither partner can see the other’s direct chat, while Tuanzi shares household context and relays attributed notes only with permission. One person can sign up and start a yard, then pair later with a six-character invite code. Leaving supports personal data export before a single cloud transaction deletes the departing member’s private chats, diaries, private memories and keys.

One cloud writer per household

The backend moved from an earlier two-Mac local-host setup to a single-writer Cloud Actor model so couples can start without running local servers. Each household maps to one Cloudflare Durable Object with its own SQLite database, keeping data isolated and writes serialized on one thread. Core logic stays in a platform-free TypeScript package injected with a synchronous SqlDriver, separated from the Cloudflare edge adapter.

HouseholdDO · Single writer
Owns conversations, three-space permission views, yard state and the sole publishing gate. Both live replies and background reports pass through it to check consent, excluded topics and quiet hours, while a single Alarm wheel drives scheduled jobs and APNs pushes.
Workflows · Async work
Cloudflare Workflows handle memory extraction, profile refreshes, delegated tasks and daily cat diaries. A self-built streaming agent loop runs tools without a heavy AI SDK, saving step checkpoints and returning structured reports without posting directly to chat.
iOS & macOS · Thin clients
Both apps share zero-dependency Swift CatttCore for Keychain storage, single-flight token refresh, SQLite WAL caching and an offline outbox. Clients write through idempotent HTTP and receive live streams and yard sync over WebSocket.
3D world
Three.js drives pathfinding, poses and scene interactions inside one shared WKWebView for yard and chat. The household actor updates Tuanzi’s state on demand, syncs it to online clients over WebSocket and receives action receipts through a two-way bridge.

Global D1 handles login and household routing, and R2 stores static assets. Models run through shared household BYOK across DeepSeek, OpenRouter, OpenAI, Gemini and compatible endpoints. A single key maps automatically to Smart and Fast slots, stored with AES-256-GCM envelope encryption alongside SSRF blocking, health probes and a 30-day usage log. The retired dual-Mac local-host codebase is archived at archive/r9.8-local-host.

Since December, Tuanzi can look things up on the web in read-only mode through a DeepSeek adapter with a request gate, keeping a source record for every lookup and rechecking it before publishing. New household events land in an event-driven inbox, where triage decides whether and when Tuanzi should speak up; partner updates follow each member’s preferences and local hours, and pushes and health checks now run through to the iOS and macOS clients. Yard actions are deduplicated by Idempotency-Key, and Sign in with Apple uses bundled JWKS with replay protection.

From an invitation to a seat nearby

When a user asks Tuanzi to sit nearby, the agent calls a sitting tool. The client picks a seat based on the cat’s temperament and yard state, and the 3D scene walks Tuanzi over and sits it down. Accepted, running and arrived states are tracked separately, so chat confirms Tuanzi is seated only after an arrival receipt.

Three-layer vectorless memory

Memory runs in three layers without embeddings or a vector database. L1 keeps space-isolated household profile cards and recent active state. L2 indexes structured memories in SQLite FTS5 using Chinese pre-segmentation, adjacent bigrams and Fast-model search terms, recalling with BM25 and dual-subject slot binding. L3 exposes read-only lookup tools for verbatim chat history and authorized diaries. Every query, WebSocket broadcast and prompt build filters by member permissions, so withdrawing a message, revoking diary access or editing a memory takes effect immediately, checked by a 76-case agent and memory eval suite in both scripted red-line and live-model modes.

Bringing results back into chat

A unified entry stores the delegated request and passes execution to Cloudflare Workflows, which write structured reports back to the household actor. Before publishing, HouseholdDO rereads recent chat and checks cancellations, source permissions and quiet hours. New context sends the work back for reassessment. Delegated tasks call tools round by round, pause to wait when more detail is needed, and recheck any web sources before publishing. Once approved, the full result lands in the mailbox, chat picks up the thread, and offline members receive an APNs alert.

Resuming across disconnects

Write requests carry client_op_id for idempotency, and offline clients queue mutations in a local outbox until connectivity returns. Streaming chat deltas flush periodically under WebSocket Hibernation, allowing reconnecting clients to catch up from turn.snapshot without losing partial replies. Background tasks are capped by rounds, tokens and web lookups, and blocked or failed requests can be supplemented in chat to resume the same item.

In development. The product film was recorded in December 2026 in the iOS Simulator and the web yard, with local mock data for chat and diary; the recorded demos and iPhone captures come from earlier local-integration sessions. The architecture notes reflect the December 2026 Cloud Actor codebase (e93db48), with production Cloudflare and APNs rollout still underway.