Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

Codex App Pet Mod

I liked the Codex pet feature and the Hatch Pet skill, but the built-in pet system turned out to be pretty limiting: custom pets can swap the spritesheet, but they cannot define longer sequences, custom timing, chained animations, or more event triggers from pet.json.

So I set the agent upon improving itself, which is obviously a slippery slope.

For clarity: the agent is the one writing all of this, not me.

Demo

Demo video:

assets/oVRedOdhq0.mp4

The demo uses the bundled Datachan Extended pet in assets/datachan-extended. It is a normal Codex custom pet folder plus an animation config that exercises longer row playback, custom timing, idle/running chains, and a hover override.

What This Mod Does

The repo now owns an Advanced Pet System as TypeScript source code in src/advanced-pet-system.ts. The patch script is the installer that adapts the compiled system into the current Codex desktop bundle.

The system gives custom pets more expressive behavior without changing the existing pet folder format:

  • Passes optional animation config through from pet.json.
  • Auto-detects the number of non-empty frames in each spritesheet row.
  • Lets any configured state use up to all 8 atlas columns, either from auto-detected row content or explicit frames / frameCount.
  • Widens the built-in idle and jumping defaults so those rows are no longer capped at their original hardcoded frame counts.
  • Adds simple sequence chaining:
    • review -> waving -> idle
    • failed -> waiting -> idle
    • waiting -> waving -> idle
    • jumping -> waving -> idle
  • Adds configurable chain playback modes:
    • idleFallback: play the active chain once, then loop the configured idle chain
    • loop: loop the active chain until the app state changes
    • once: play the active chain once and hold the final frame
  • Adds activity-aware pet states for local Codex work:
    • thinking
    • editing / edited
    • running-command / ran-command
    • reading / read
    • listing / listed
    • searching / searched
    • searching-web / searched-web
    • calling-tool / called-tool
  • Adds more transient drag events:
    • drag right: running-right
    • drag left: running-left
    • drag up: waving
    • drag down: jumping
  • Makes hover and drag directions configurable with animation.events.

Current App Constraints

The copied app still expects the standard Codex pet atlas:

1536 x 1872
8 columns x 9 rows
192 x 208 per frame
PNG or WebP

Custom pets are loaded from:

%USERPROFILE%\.codex\pets\<pet-name>\pet.json

To install the included Datachan Extended example:

New-Item -ItemType Directory -Force "$env:USERPROFILE\.codex\pets" | Out-Null
Copy-Item .\assets\datachan-extended "$env:USERPROFILE\.codex\pets\datachan-extended" -Recurse -Force

The manifest remains simple:

{
  "displayName": "Datachan",
  "description": "A custom Codex pet.",
  "spritesheetPath": "spritesheet.webp",
  "animation": {
    "autoDetectFrames": true,
    "idleSlowdown": 6,
    "states": {
      "idle": { "row": 0, "durationMs": 140, "lastFrameDurationMs": 320 },
      "jumping": { "row": 4, "frames": 8, "durationMs": 110 },
      "review": { "row": 8, "frames": 6, "durationMs": 150 }
    },
    "chains": {
      "idle": ["idle", "waving", "review"],
      "review": ["review", "waving"],
      "running": {
        "mode": "loop",
        "sequence": ["running", "waving"]
      },
      "jumping": ["jumping", "waving"]
    },
    "events": {
      "hover": "waving",
      "dragLeft": "running-left",
      "dragRight": "running-right",
      "dragUp": "waving",
      "dragDown": "jumping"
    }
  }
}

animation can also be named sequences; the patcher passes either field through.

If autoDetectFrames is not set to false, the renderer scans each row and uses the last non-transparent frame in that row. Explicit frames or frameCount values override detection.

The per-state config applies to every pet state, not only idle and jumping. Each state is still capped by the current Codex atlas geometry: 8 columns per row.

chains.idle loops when the app state is actually idle. Active states such as running, waiting, failed, or review need their own chain entries. Non-idle chains default to idleFallback, which plays the active chain once and then loops chains.idle if configured, otherwise the plain idle row. Set a chain entry to { "mode": "loop", "sequence": [...] } to loop that chain until the app state changes.

Files Patched

Inside app\resources\app.asar:

.vite/build/workspace-root-drop-handler-*.js
webview/assets/codex-avatar-*.js
webview/assets/avatar-overlay-page-*.js

The patcher discovers these generated chunks by content, so it is not tied to one specific Vite hash.

Source Layout

src/advanced-pet-system.ts       The standalone animation, event, and activity-state engine.
test/advanced-pet-system.test.ts Focused TypeScript tests for the standalone engine.
dist/                            Generated CommonJS output used by the installer.
scripts/patch-codex-pet-behavior.js
                                  Installer that patches the Codex bundle to call equivalent runtime behavior.

Backups created by the first patch run:

app\resources\app.asar.backup-before-pet-patch
app\resources\pet-patch-backups\

Usage

Run from this repo:

npm install
npm test
node .\scripts\patch-codex-pet-behavior.js app\resources\app.asar

The patch script builds dist/ from TypeScript when needed.

The script accepts the path to the copied app's app.asar. It expects or creates the extracted directory beside the provided archive:

<path-to-app.asar>
<path-to-app.asar>.extracted

After repacking app.asar, Electron's ASAR integrity metadata in Codex.exe must also match the new archive header hash. If it does not, the copied app exits before startup with an error like:

Integrity check failed for asar archive

The patch script updates the copied Codex.exe metadata automatically. The first run creates backups:

app\Codex.exe.backup-before-pet-patch
app\resources\app.asar.backup-before-pet-patch
app\resources\pet-patch-backups\

Close the copied Codex app before running the patch. Windows locks Codex.exe while it is running, and the script must be able to update the embedded integrity metadata after repacking.

Manual unpacking is still fine if you want to inspect the files yourself:

asar extract app\resources\app.asar app\resources\app.asar.extracted

Then run the patch script.

Restore

To restore the original copied package:

Copy-Item app\resources\app.asar.backup-before-pet-patch app\resources\app.asar -Force
Copy-Item app\Codex.exe.backup-before-pet-patch app\Codex.exe -Force

Notes

The practical frame limit is still 8 frames per row for every state. Auto-detection finds how many of those 8 cells are actually populated. A true 9-frame sequence would require changing the atlas geometry, image dimensions, CSS background sizing, positioning math, and loader validation.

See docs/configuration.md for the supported animation config.

There is also an upstream issue draft in docs/upstream-issue.md.

Current version

26.429.61741

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages