Open-source Grok Bot alternative with a virtual machine that bots can use
Chat Widgets Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: A bot can show a ChatKit-style widget in chat with show_widget, it renders on desktop, iOS and Android from one payload, and a press reaches the bot as the person's next message.
Architecture: One canonical JSON tree, normalised once on the server by shared/widget.ts, stored on a new widget message kind with a text fallback. One recursive renderer per platform. A press is posted on the existing send-message route as widgetAction, becomes an ordinary user message that replies to the widget, and settles the widget with a message.patch.
Tech Stack: TypeScript (Node type-stripping server, React 19 + Tailwind v4 renderer, vitest); Swift 5.9 / SwiftUI / Swift Charts (iOS 16); Kotlin 2.2 / Jetpack Compose / kotlinx.serialization.
Spec: docs/superpowers/specs/2026-10-13-chat-widgets-design.md (this repo). Design canvas: https://claude.ai/artifact/3jp8ZJ62qQCx8BXejVp8gv
Global Constraints
- Two repos, two branches named
feat/chat-widgets: server, shared and desktop inOpenGrokBot-widgets(milind-soni/OpenMausBot); iOS and Android inmausbot-mobile-widgets(SupaMaus/mausbot-mobile). Never put phone code in the first or desktop code in the second. No push, no PR. - Ratchets (
scripts/testing/file-size-ratchet.test.ts,index-route-ratchet.test.ts):server/index.ts,src/state/store.tsx,server/store.ts,server/config.ts,ChatView.tsx,GroupView.tsx,scripts/mcp-server.ts,server/drivers/agents-call.tsmay not gain a line;server/index.tsmay not gain a path guard; no new file over 1,000 lines. Move code out to make room and lower the pinned number. - Server code runs on type stripping: type-only imports must be
import type, no enums, no parameter properties. - Tests are colocated
*.test.ts(never.tsx); React tests start with// @vitest-environment happy-domand usecreateElement. - Every desktop UI string goes through
t()with a key insrc/locales/en.json. iOS strings needpt-BR,zh-Hans,zh-Hantentries inios/App/Localizable.xcstrings; Android strings needvalues/,values-b+zh+Hans/,values-b+zh+Hant/. - Colours come from tokens only: no hex literals in widget renderers on any platform.
- On phones the type prefix is
ChatWidget;Widgetthere means the home-screen extension. - Renderers read canonical trees only and must never crash on one: an unknown node type draws its children or nothing.
- Checks before a task is done. Desktop:
pnpm typecheck,pnpm lint,pnpm exec vitest run <files>,pnpm i18n:check, plus the two ratchet tests. iOS:swift test --package-path ios,bash scripts/check-ios-view-shims.sh,node --test scripts/ios-strings.test.mjs. Android:JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home" ./gradlew :core:test :app:testDebugUnitTestfromandroid/.
Review Focus
- A model sends sloppy JSON (a string, extra props, a non-root at the top, ChatKit spacing units): it must normalise or fail with a sentence naming the path, never post a broken card. Pinned in Task 1.
- A press arrives twice (double tap, client retry with the same
sendId): one user message, one settle. Pinned in Task 2. - A press arrives for a settled widget, a wrong thread or another bot's message: refused with 409 or 404, nothing sent. Pinned in Task 2.
- A secret pasted into a widget string, and a password field: redacted before storage; rejected at parse. Pinned in Tasks 1 and 2.
- An older or offline client: the text fallback reads well on its own, and a cached phone thread shows values but no live actions. Pinned in Tasks 1, 4 and 5.
Task 1: Shared schema and wire kind
Files:
- Create:
shared/widget.ts,shared/widget-samples.ts,shared/widget.test.ts - Modify:
shared/wire.ts(kind union,widget?: WidgetPayload),src/lib/taskTimeline.ts(kind union)
Interfaces (produces):
export const WIDGET_LIMITS: {...}; export const WIDGET_ICON_NAMES: readonly string[];
export interface WidgetAction { type: string; payload?: JsonValue }
export interface WidgetNode { type: string; id: string; children?: WidgetNode[]; [prop: string]: unknown }
export type WidgetRoot = WidgetNode; // type "Card" | "ListView"
export interface WidgetSettled { ref: string; label: string; tone: "confirm" | "cancel" | "submit"; at: number; sendId?: string }
export interface WidgetPayload { v: 1; root: WidgetRoot; settled?: WidgetSettled }
export type WidgetValues = Record<string, string | boolean>;
export function parseWidgetInput(value: unknown): { ok: true; value: WidgetRoot } | { ok: false; error: string };
export function widgetToText(root: WidgetRoot): string;
export function widgetFields(scope: WidgetNode, root: WidgetRoot): WidgetField[]; // {name, type, label, node}
export function widgetInitialValues(scope: WidgetNode): WidgetValues;
export function widgetScope(root: WidgetRoot, ref: string): WidgetNode; // nearest Form, else root
export function widgetActions(root: WidgetRoot): WidgetActionEntry[]; // {ref, label, action, tone?, client?}
export function widgetActionByLabel(root: WidgetRoot, label: string): WidgetActionEntry | undefined;
export function resolveWidgetAction(payload: WidgetPayload, ref: string, values: unknown):
| { ok: true; ref: string; label: string; action: WidgetAction; values: WidgetValues; text: string; tone?: "confirm" | "cancel" | "submit" }
| { ok: false; status: 400 | 404 | 409; error: string };
WIDGET_SAMPLES (in widget-samples.ts) is a record of named model-shaped inputs covering every node type; tests, fixtures and the verification recipe all use it.
- Write
shared/widget.test.tsfirst: one case per node type normalising, each limit refusing with its path, password refusal, non-root wrapping, JSON-string input, spacing-unit conversion, duplicate action labels made unique by their row title,widgetToTextsnapshots for the list, form, table and chart samples, andresolveWidgetActionfor scope, required, option, date, settled (409), unknown ref (404) andcancelskipping validation. - Run
pnpm exec vitest run shared/widget.test.ts; it fails on the missing module. - Implement
shared/widget.tsandshared/widget-samples.ts; add the kind and field toshared/wire.tsand the kind tosrc/lib/taskTimeline.ts. - Run the test,
pnpm typecheck,pnpm lint. Commit.
Task 2: Server
Files:
- Create:
server/chat-widgets.ts,server/chat-widgets.test.ts,server/drivers/agents-widget-tools.ts,server/drivers/agents-call-cards.ts - Modify:
server/index.ts(swapcreateOptionsCardforcreateAgentCard, same line count),server/drivers/agents-catalog.ts(spread the two definitions; read-only annotation list untouched),server/drivers/agents-call.ts(thecreate_options_cardbranch moves intoagents-call-cards.ts, which also handles the two widget tools; lower its ratchet number),server/routes/bot-messages.ts(widgetAction),server/replies.ts(widget branch),server/delta-context.ts(isContextMessage),server/routes/threads.ts(markdown export line),server/team-backup.ts(messageText),scripts/mcp-server.ts(projection keepswidget, in place),server/drivers/agents-catalog-wire.test.tsgoldens and budget baselines,scripts/testing/file-size-ratchet.test.ts
Interfaces:
Consumes: everything Task 1 produces.
Produces:
createAgentCard({store, bot, threadId, input}): {ok: true; messageId: string} | {ok: false; status: 400|403|404|409; error: string}; the internal body shape{tool: "show_widget", widget, fallback_text?}and{tool: "update_widget", widget_id, widget}; the public body fieldwidgetAction: {messageId: string, ref: string, values?: Record<string, string|boolean>}onPOST /api/bots/:id/messageswithtextomitted.Tests first (
server/chat-widgets.test.ts, additions toserver/replies.test.tsor a new one, and a bot-messages route test following the existing route tests): create postskind: "widget"with fallback text and nofrom; a room thread is 409; strings are redacted;update_widgetreplaces a live tree and refuses a settled one, another bot's message and another thread's; a press sends one user message replying to the widget with the label text;confirmsettles, a plain button does not; the samesendIdtwice sends once and patches once; a settled widget is 409;promptWithReplynames the action and payload;isContextMessageadmits a widget row.Implement.
createAgentCarddelegates a body withouttooltocreateOptionsCardunchanged.Regenerate goldens with
UPDATE_AGENTS_CATALOG_GOLDENS=1 pnpm exec vitest run server/drivers/agents-catalog-wire.test.ts, then editBUDGET_BASELINEby hand to the printed sizes.Run the touched tests, both ratchet tests,
pnpm typecheck,pnpm lint. Commit.
Task 3: Desktop renderer
Files:
- Create:
src/components/widget/WidgetMessage.tsx,WidgetNodes.tsx,WidgetControls.tsx,WidgetChart.tsx,widget-icons.ts,widget-send.ts, tests beside them (*.test.ts),src/components/OptionsCardRow.tsx - Modify:
src/components/ChatView.tsx(theoptionscase moves intoOptionsCardRow; addcase "widget"; lower its ratchet number),src/state/store.tsx(MessagegainskindandwidgetfromWireMessage, in place),src/lib/export-transcript.ts,src/locales/en.json
Interfaces:
Consumes: Task 1 types and helpers; the
widgetActionbody from Task 2.Produces:
<WidgetMessage botId threadId message />, default-exported pieces not used elsewhere.Tests first: every sample in
WIDGET_SAMPLESrenders to markup without throwing; a list withlimitshows "Show all"; a settled payload renders the tick line and no buttons; pressingconfirmposts{threadId, sendId, widgetAction}with the form's current values; a required empty field blocks the post and marks the field;open_urlopens the link and posts nothing; a server refusal shows its sentence in the card.Implement to the canvas: surface, header, rows, dot status, actions under the card, settled line with Details,
sizewidths, SVG chart from tokens.Run tests,
pnpm typecheck,pnpm lint,pnpm i18n:check,pnpm check:contrast, both ratchets. Commit.
Task 4: iOS
Files (in mausbot-mobile-widgets):
Create:
ios/Sources/CompanionCore/ChatWidget.swift(forgivingJSONValue,ChatWidgetPayload,ChatWidgetNodeaccessors, field and action helpers mirroring Task 1's scope rules),ios/Tests/CompanionCoreTests/ChatWidgetTests.swift,ios/App/Cards/ChatWidgetView.swift,ChatWidgetNodes.swift,ChatWidgetControls.swift,ChatWidgetChart.swift,ChatWidgetIcons.swiftModify:
Models.swift(Kind.widget,widgetpayload),StateSnapshot.swiftand its guard tests,ChatPreferences.swiftandWalkie.swiftkind switches,Client.swift(sendWidgetAction),Session.swift,TranscriptRows.swift(TranscriptActions.sendWidgetAction),ChatView.swift(dispatch),Localizable.xcstringsFixture:
ios/Tests/CompanionCoreTests/Fixtures/widget-messages.json(written by Task 1's samples; do not hand-edit)Core tests first: the fixture decodes every message with
kind == .widget; a malformed tree decodes to a message that falls back to text and never throws; field collection and required checks match the fixture's expectations; the snapshot round-trips the payload.Implement core, then views. Offline uses the existing reconnect notice. Remote images use
AsyncImageover https only.Run the three iOS checks and
xcodegen generateplus a simulator build if the toolchain is present. Commit.
Task 5: Android
Files (in mausbot-mobile-widgets):
Create:
android/core/.../core/ChatWidget.kt,android/core/src/test/.../ChatWidgetTest.kt,android/app/.../ui/ChatWidgetView.kt,ChatWidgetNodes.kt,ChatWidgetControls.kt,ChatWidgetChart.kt,ChatWidgetIcons.kt, app tests beside the existing onesModify:
Models.kt(Kind.WIDGET, serializer,widgetfield last),StateSnapshot.ktand its test,ChatPreferences.kt,ChatPolicy.ktkind switches,Client.kt,Session.kt(sendWidgetAction),MessageRow.kt(dispatch), the threestrings.xmlCore tests first, mirroring Task 4 on the shared fixture.
Implement core, then composables with
Maus.colors,Space,MausShapes; charts on a Canvas; https images through a small bounded loader.Run
:core:test :app:testDebugUnitTestand:app:assembleDebug. Read the real counts frombuild/test-results. Commit.
Task 6: End-to-end verification and review
- Add
docs/verification/widgets.md(checked byscripts/testing/verification-docs.test.ts) and run it against an isolated fixture: a fake-engineshow_widgetcall,messagesshows the widget row, the UI snapshot shows the card, a click settles it and starts a turn. Keep the JSON and screenshots. - Compare desktop screenshots in Meadow and Midnight against the canvas; fix differences.
- Whole-branch review of both repos; fix findings; run every check in Global Constraints once more.