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

Early local integration recording · iOS Simulator, Cattt backend and DeepSeek
Read the video description

The film opens in Tuanzi’s 3D yard. In chat, the user asks Tuanzi to plan a relaxed half day with a walk and some time to draw. Tuanzi acknowledges the request. A background workflow drafts the plan, saves three checkpoints, and submits a report. The foreground publisher checks consent and conversation context, then sends a chat message letting the user know a letter is ready. The user returns to the yard and opens the letter to read the plan and its rainy-day alternative.

More 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.

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 scripted red-line and live-model eval suites.

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. 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 enforce step limits and daily token budgets, and blocked or failed requests can be supplemented in chat to resume the same item.

In development. The film and iPhone captures come from earlier local-integration recordings. The architecture notes reflect the December 2026 Cloud Actor codebase, with production Cloudflare and APNs rollout still underway.