Skip to content

Architecture: coding agent integration ​

Scope ​

  • How coding agents (Claude Code, Codex, Gemini CLI, Cursor, Grok Build, Qoder, Kimi Code, and tools that use MCP) report their status to PlayPets friends, as it works today.
  • For people adding a new integration or building tools on the agent side.
  • The whole app's architecture: PlayPets app architecture.

What leaves the agent, and where it goes:

  • The bridge stays inside this computer.
  • Hook adapters leave out user prompts and tool inputs.
  • They forward short notifications and Codex's last answer.
  • MCP and direct commands can also supply sentences.
  • The app keeps recent reports.
  • When you chat, it adds them to the connected friend's AI prompt as labeled status notes.
  • That AI may run outside this computer.

Diagram ​

A container-level diagram: from what the agent runs to what appears on the friend.

Components ​

ComponentLocationResponsibility
CLI modesrc-tauri/src/agent/cli.rs, agent/run.rs for runWith a command argument (hook, mcp, status, say, react, pets, run), the app executable runs in this mode with no window. Node.js is not needed
Hook translationagent::hooks::hook_eventTurns each agent's hook payload into a state and a code. Prompts and tool inputs are not sent
MCP serveragent::cli::mcp_replyAn MCP server that takes JSON-RPC one line at a time over standard input and output. Four tools
Bridgesrc-tauri/src/agent/bridge.rsThe HTTP server inside the app. A random port on 127.0.0.1, a token check on every request, browser requests refused
Event handlingsrc-tauri/src/agent/mod.rsTurns codes into sentences in the current language, remembers them as recent activity, and shows them as the friend's status
Settings snippetsconnection_snippet in agent/snippets.rs (the agent list is in agent/kinds.rs)The snippet to paste into each agent's settings file, built by "Copy settings" in the Settings tab (details)
Connectsrc-tauri/src/agent/connect.rsMerges the same snippet into the agent's own settings file, and takes PlayPets' entries out again (details)

Data flow ​

  1. When the app launches:
    • The bridge opens on 127.0.0.1:0.
    • The app writes the assigned port and a new token (64 random characters) to bridge.json in the data folder.
    • Both change every time the app restarts.
  2. Hooks:
    • At each step the agent runs playpets hook claude --bridge <bridge.json> and passes the hook JSON on standard input.
    • Codex passes the notification JSON as the last argument.
    • CLI mode turns it into a state and a code and sends it with POST /events.
    • A hook never blocks the agent's work: it is quiet, gives up on a slow app within a few seconds, and exits with code 0 even when it fails.
  3. MCP:
    • The agent starts playpets mcp as an MCP server and sends initialize, tools/list and tools/call.
    • Tool calls go through the same bridge path.
  4. Commands:
    • A person or script can run commands directly: playpets say "Tests passed".
    • playpets run -- npm test sends working while the command runs, then done or error when it ends.
  5. Inside the app:
    • The bridge checks the token and the payload.
    • It picks the friend: pet/petId is an id or a name. Without one, it uses the first friend.
    • A code becomes a sentence in the current language (@tool Bash → "Using Bash") and shows above the friend.
    • It is remembered among that friend's 8 most recent activities.
  6. In the yard:
    • The friend acts on the state (src/yard/duty.js): working or failed, it stays where it stands; waiting, it comes to the front of the yard; done, it rests a moment.
    • In a place with stations (the garden workshop), it works and fails at a desk, waits at the approval spot and rests in the rest corner (agent workspaces).
  • A gallery adds a playpets://import?url=<pet page address> link.
  • The operating system hands the link to PlayPets (src-tauri/src/links.rs).
  • The app imports the pet through the same path as a pasted address, then opens the Invite tab.
  • The scheme is registered under plugins.deep-link in tauri.conf.json.
  • A link received by a second launch is handed over by the single-instance plugin.
  • Other kinds of links are ignored.

Interfaces ​

CLI commands

Common optionDefault
--pet <id or name>The first friend, or PLAYPETS_PET
--bridge <path to bridge.json>The data folder, or PLAYPETS_BRIDGE
CommandWhat it does
playpets petsFriend list and states
playpets status <state> [message]Status notification
playpets say <message>Only a speech bubble, without changing the state
playpets react <wave|jump|pet>A one-off reaction
playpets run -- <command…>Status notifications while a command runs
playpets hook <claude|gemini|cursor|grok|qoder|kimi>Handles hook JSON on standard input
playpets hook codex <json>Handles a Codex notification
playpets mcpMCP server (standard input and output)

States and reactions

  • States: idle, working, waiting, done, error.
  • Reactions: wave, jump, pet.

Hook translation

  • Events not in the table are not sent.
  • Claude Code:
    • Its Notification says by notification_type what it tells. Only permission_prompt, elicitation_dialog, elicitation_url_dialog and agent_needs_input wait on the person; one with no type comes from an older version that only notified to ask.
    • idle_prompt follows every turn about a minute later. A turn stopped with Esc fires no Stop, so hook claude settles the friend with it only while the friend is still working, as hook grok does.
    • StopFailure replaces Stop when a turn ends on an API error. Settings copied before 1.4.0 do not have it.
  • Grok Build:
    • It sends Claude's hook_event_name and tool_name; its other keys are camelCase.
    • Its UserPromptSubmit, StopFailure, StopCancelled and SessionEnd from a subagent (subagentType set) are not sent.
    • It also runs the hooks in ~/.claude/settings.json and ~/.cursor/hooks.json. A hook claude or hook cursor it runs (GROK_SESSION_ID set) sends nothing, so its work shows only on the Grok Build friend. Other agents' hooks still report with the variable set.
    • Some turns end without a Stop (cancel-and-send, rewind, a finished ! command). idle_prompt follows every turn, so hook grok reads GET /pets first and settles the friend only while it is still working.
  • Qoder:
    • It names its events and payload fields as Claude Code does, so hook qoder reads them as hook claude does, idle_prompt included.
    • The Qoder IDE reads hook changes only after a restart; Qoder CLI reads them at once.
  • Kimi Code:
    • It waits on the person through PermissionRequest. Its Notification only tells of background tasks and is not sent.
    • A turn stopped with Esc fires Interrupt instead of Stop.
    • It writes every payload key snake_case (tool_name). Its error_type is the error's class name, so StopFailure is always @error.
    • On Windows it runs a hook through cmd.exe; its folder is .kimi-code under the home folder, as on macOS and Linux.
  • The app turns codes into the current language.
  • by names who reported: <agent>:<session id> from a hook, or <agent> alone when the payload names no session (Codex); cut at 80 characters; empty from older hooks and other commands.
    • /pets returns the by of the friend's last report, and source: chat while the state is a chat answer on its way rather than an agent's turn.
    • An idle_prompt settles the friend only when the last report has the same by, so one session's notice leaves another session's turn alone.
Agent eventStateSentence sent
Claude, Qoder, Grok, Kimi UserPromptSubmit, Gemini BeforeAgent, Cursor afterAgentThoughtworking@thinking
Claude, Qoder, Grok, Kimi PreToolUse, Gemini BeforeTool, Cursor postToolUseworking@tool <tool name>, or @tool_any when there is no name
Cursor afterFileEdit, afterShellExecution, subagentStartworking@editing, @command, @subtask
Claude, Qoder Notification of a type that asks (or no type), Gemini Notification, Grok Notification of type permission_promptwaitingThe agent's notification sentence, or @confirm when there is none
Kimi PermissionRequestwaiting@confirm
Claude, Qoder, Kimi Stop, Grok Stop with reason end_turn, Gemini AfterAgent, Cursor stopdone@done
Claude, Qoder, Grok StopFailureerror@rate_limit, @sign_in (authentication_failed, oauth_org_not_allowed), or @error
Kimi StopFailureerror@error
Claude, Qoder, Grok Notification of type idle_promptidle, only while the friend is workingNone
Claude, Qoder, Gemini, Grok, Kimi SessionEnd, Grok StopCancelled, Kimi Interrupt, Cursor sessionEndidleNone
Codex agent-turn-completedoneThe last answer (120 characters), or @done when there is none
playpets run start, failureworking, error@running <command>, @failed <exit code>
playpets run stopped by Ctrl-C, a TERM or its terminal closing (also a command that exits 130 or 143)idle@stopped

HTTP bridge

  • Every request needs Authorization: Bearer <token from bridge.json>.
  • Requests with an Origin header (browsers) are refused.
  • The body is JSON of 8 KB or less.
  • Sentences are cut at 240 characters.
RequestBodyResponse
GET /petsNone[{id, name, state, source, by}], and {id, parked: true} for a friend kept for later
POST /events{pet or petId, state, message, by?}{ok, petId}
POST /say{pet, message}{ok, petId}
POST /react{pet, action}{ok, petId}
ErrorMeaning
400Bad payload
401Missing or wrong token
403Browser request
404Unknown path or friend
413Over 8 KB

MCP tools

  • Protocol version 2024-11-05.
ToolInputWhat it does
list_petsNoneFriend list and states
set_pet_statestate (required), message, petStatus notification
saymessage (required), petSpeech bubble
reactaction (required), petReaction

Environment and touchpoints ​

  • The Settings tab's "Connect" writes the settings into the file below; "Copy settings" tells you which file to paste into.
AgentSettings fileWhat you paste
Claude Code~/.claude/settings.jsonA hook claude command for each event
Codex CLITop of ~/.codex/config.tomlnotify = [executable, "hook", "codex", …]
Gemini CLI~/.gemini/settings.jsonA hook gemini command for each event
Cursor~/.cursor/hooks.jsonA hook cursor command for each event
Grok Build~/.grok/hooks/playpets.json, a new fileA hook grok command for each event (timeouts in seconds)
Qoder~/.qoder/settings.jsonA hook qoder command for each event, in Claude Code's shape
Kimi CodeEnd of ~/.kimi-code/config.tomlA [[hooks]] row with a hook kimi command for each event
Other MCP toolsEach tool's MCP settingsThe playpets mcp server

Settings snippets ​

  • Built by connection_snippet when you press "Copy settings" in the Settings tab.
  • Contains the executable path and the bridge.json path.
  • If a friend was picked for that agent in the Settings tab, it adds --pet <friend id> (PLAYPETS_PET for MCP).
  • The assignment is saved in AppData.agent_pets and removed when that friend is sent away.

Connect ​

  • "Connect" asks first and names the file, then merges the snippet into it (agent::connect::connect).
  • Everything else in the file stays, other tools' hooks and mcpServers included. New entries go after the file's own.
  • Formats (Format in agent/kinds.rs):
FormatAgentsWhere PlayPets' entries go
GroupedClaude Code, Gemini CLI, Grok Build, QoderA group with one handler in hooks.<event>
FlatCursorA handler in hooks.<event>; version only when the file has none
NotifyCodexThe top-level notify key; comments and tables stay (toml_edit)
HookRowsKimi Code[[hooks]] rows of event, command and timeout only; any other key stops Kimi Code loading its config
  • PlayPets' entries are the ones whose command has hook <kind> --bridge, whose args start with hook <kind> (Claude Code and Qoder on Windows), or a Codex notify with "hook", "codex". No marker key is added.
  • agentLinks reports each agent as on, off, outdated, unreadable or taken:
    • on: PlayPets' entries are exactly what Connect would write now. Connect then writes nothing.
    • outdated: another Reacting friend, a moved app or older events. Connect replaces the entries.
    • unreadable: not JSON or TOML (a comment, a typo), or hooks in another shape. Nothing is written; Copy settings stays.
    • taken: Codex's notify runs another program. Codex runs only one, so nothing is written.
  • <name>.playpets-backup keeps the file as it was before PlayPets was in it. A write to a file without PlayPets' entries copies it there first; a later Connect or Disconnect leaves the backup, unless there is none yet.
  • The write goes through <name>.playpets-tmp and a rename, keeping the file's permissions.
  • A read-only file is left as it is, with the write error shown.
  • A linked settings file (a dotfiles folder) is written through its link.
  • "Disconnect" removes only PlayPets' entries and the groups and events they leave empty. A file left empty is removed, as before Connect made it.
  • The home folder is the system's. An e2e run reads PLAYPETS_E2E_HOME instead, and only in an e2e run; unit tests pass a temporary folder.
  • File work runs without the state lock; only the bridge path and the Reacting friend are read under it.

Hook commands on Windows (agent/snippets.rs):

  • PowerShell takes a quoted path followed by arguments as a syntax error, so each agent gets the form its shell reads.
  • Claude Code runs a failing PreToolUse hook as a block on the tool call, so a command PowerShell cannot parse would stop every tool.
AgentShell on WindowsHook written
Claude Code, QoderGit Bash, or PowerShell without itcommand is the app, the rest is in args (exec form); no shell reads it
Gemini CLI, CursorPowerShell& '<app>' hook <kind> --bridge '<file>'; a ' in a path is doubled
Kimi Codecmd.exeThe quoted form used on macOS and Linux
Grok BuildNot checkedThe quoted form used on macOS and Linux
CodexNone (notify is an argument list)Unchanged

MSIX install on Windows:

  • The executable lives under WindowsApps and cannot be run by path from outside.
  • The settings snippet points at the execution alias instead: %LOCALAPPDATA%\Microsoft\WindowsApps\playpets.exe.
  • The package declares the playpets scheme (windows.protocol), since a packaged app's own registry writes stay inside the package; Windows passes the link to playpets.exe as its argument.

Change history ​

  • 2026-09-29 Moved hooks, MCP and status commands into the CLI mode of the app executable (no Node needed)
  • 2026-09-30 Hook states are sent as codes so they show in the app's language. CLI and MCP text is fixed to English
  • 2026-09-30 With an MSIX install, the settings snippet points at the execution alias
  • 2026-10-28 Grok Build reports through hook grok; hooks it borrows from Claude Code and Cursor send nothing
  • 2026-10-28 hook claude waits only on notices that ask, settles on idle_prompt and reports StopFailure; the MSIX package declares playpets://
  • 2026-10-30 Connect and Disconnect write and remove PlayPets' entries in each agent's own settings file
  • 2026-10-30 Qoder reports through hook qoder and Kimi Code through hook kimi

Free and open source under the MIT license. Not affiliated with OpenAI; ChatGPT and Codex are trademarks of OpenAI.