Development & Debugging
This page is for developers of this plugin: tech stack, directory layout, development flow, tests, and troubleshooting entry points. Readers who only use the plugin should start at Installation and Usage in Chat.
Tech stack
| Layer | Choice | Notes |
|---|---|---|
| Language | TypeScript 7 | Source is .ts / .tsx; tsconfig.json only type-checks (noEmit), tsdown produces the output |
| Build | tsdown + the in-repo build preset | Exactly one artifact, client.js; the preset is tsdown.preset.ts, carried by every plugin repository and byte-identical across them |
| UI | React 18 (provided by the host) | Declared in peerDependencies — not bundled, not version-pinned; host base words are externalized at build time and resolved by the host at runtime |
| Styles | Tailwind CSS 4 | CSS is generated at build time through postcss + lightningcss and injected as <style data-plugin>, scoped, without preflight |
| Icons | lucide-react | Named imports, never the whole package |
| Code highlighting | shiki + @shikijs/langs | Used when viewing the Python source on a card |
| Runtime and rendering | Core package manim-live ^0.4.0 | Python execution and the WebGL canvas come from it, inlined into client.js at build time |
| Tests | Vitest 5 + v8 coverage | Tests sit beside the file under test, named *.test.ts |
| Package manager | pnpm | The only lockfile is pnpm-lock.yaml |
Directory layout
index.js Host entry: re-exports src/host/index.js only, decoupling the entry path from the layout
client.js Client bundle artifact (build output, committed with the package)
cordis.patch.yml This plugin's registration entry in a host profile
src/
├── client/ Browser half — all of it is bundled into client.js
│ ├── index.tsx Entry: ModuleLoader registration + slot wiring + ErrorBoundary
│ ├── renderer.ts The one Manim renderer per page: the core package's factory is wired to this plugin's routes here
│ ├── plugin-config.tsx The configuration section on the plugin detail page
│ ├── components/ UI pieces: card, code view, status dot, hover tip
│ ├── definition.ts Session folding definition: one manim_card call = one render card
│ ├── render-queue.ts Render scheduling: which card runs now, how many canvases stay alive
│ ├── runtime-status.ts Environment status → display wording (pure selectors)
│ ├── storage.ts Export records on disk (localStorage read as untrusted input)
│ ├── clipboard.ts Copying source: clipboard API first, execCommand as fallback
│ ├── code-highlight.ts Python highlighting via shiki
│ ├── export.ts Export fetch layer (native render): the core package's local-CLI export client bound to this plugin's route
│ │ (Web export is not here: the card hands the canvas to the core package — see the info box below)
│ ├── environment.ts / packages.ts
│ │ Two fetch layers: the core package's environment-probe / package-manager clients bound to this plugin's routes
│ ├── i18n.ts Copy dictionary
│ └── styles.css Skin
├── host/ Host half — plain JS, no build step, published as-is
│ ├── index.js apply assembly: tool registration, asset routes, the skill
│ ├── environment.js Local environment probing (Host half of the configuration section's "Local environment" card)
│ ├── export.js Local CLI export (Host half of the menu's native-render row)
│ └── pyodide.js / assets.js / http.js Asset and on-demand package-fetch routes
└── routes.js Single source of truth for every HTTP route, shared by both halves
assets/ Bundled assets: pyodide / katex
scripts/gen-skill.mjs Generates the domain skill body for the model
skills/manim-card/ The skill body (Markdown, produced by the script above)
docs/ The docs site (VitePress, its own dependency, unrelated to the plugin's dependency graph)(*.test.ts files sit beside the file under test and are not listed here.)
This repository has only two halves, client and host — there is no third shared area. Constants both halves need live in src/routes.js; heavy shared machinery (the Python runtime, rendering) belongs to the core package.
src/routes.js is the single source of truth for every HTTP route of this plugin: six constants (KaTeX and Pyodide as two prefix-style file routes, plus four interface routes — packages / cache / environment / export, which together expose eight countable endpoints). The paths the Host registers, the fetch roots the client half passes to the core package, and the fetch addresses of the fetch layers all read from it. Changing one and forgetting the other shows up as "Pyodide stuck loading" or "formulas turned into tofu", and only on a real machine — which is why src/client/renderer.test.ts asserts against the constants instead of copying the literals a second time.
Export has two paths, both implemented in the core package
The export menu has one row per path:
- Native render:
src/client/export.tsbinds the core package'screateExportClient, and the Host half issrc/host/export.js(createLocalExport). Whether that row is enabled readsGET /export/ready(TTL-cached on the Host); the configuration section's "Local environment" card probes item by item over/environment. - Web export: this plugin only wires it up; the whole implementation lives in the core package (
manim-live'ssrc/export/browser-video.ts, on top of upstreamcreateWebCodecsExporter/createVideoExporter). It walks the timeline frame by frame withseek(t)and encodes each frame — no real-time playback — so the frame rate is steady and the cost is largely independent of animation length.seekresets every timeline animation before interpolating, so timeline animations are exact frame by frame; updaters that were never scheduled on the timeline do not advance.
Before exporting it aligns the canvas pixel count to the chosen tier (same aspect, camera frame untouched) and restores it afterwards, seeking back to the end. The trap here is dpr: upstream's width/height only configure the encoder, frames come from new VideoFrame(canvas), and canvas pixels are scene CSS size × pixelRatio (2× on retina). The core package measures that ratio, folds it back out before calling resize, and hands the resulting pixel count to the encoder — so "720p" really renders 720p and a dpr=2 screen does not burn four times the pixels.
Reaching 1080p ran into a second wall: upstream hard-codes the AVC codec string to avc1.42001f, i.e. Level 3.1, whose macroblock ceiling is 3600 blocks = 1280×720. At 1080p (8160 blocks) the browser rejects the config on the spot ("coded area 2088960 exceeds the maximum coded area 921600 supported by the AVC level (3.1)"). Upstream exposes no level option, so the core package's src/export/avc-level.ts wraps VideoEncoder.configure() for just the export window and raises the level byte at the end of the codec string to match the pixel count and frame rate (1080p30 → 0x28 = Level 4.0, 1080p60 → 0x2a = Level 4.2), restoring everything on exit; encoding itself is still native. The day upstream picks a level from the resolution, that file and its wrapper go away.
Quality tiers (added 2026-10-24) take two different routes and should not be conflated: the Web path hands video: { height, fps } to the core package, which uses it to decide how far to resize the canvas and how many frames per second to emit (cost is roughly proportional to frames × pixels per frame, so lowering the tier really does save time); the native path sends manim's own tier letter (l / m / h / p) as quality on POST /export, and the Host turns it into -q<letter> verbatim. The tier table lives in src/client/export-quality.ts (values only); the copy is listed tier by tier in card.tsx, because the i18n regression net only sees literal lookups. The chosen tier is stored in localStorage (loadExportQuality in storage.ts): it is a user preference, not a property of one card, so the whole page shares one value. The two defaults deliberately differ: native h (1080p60), Web smooth (720p30) — on the Web path every tier up costs several times the wait, so the default should not pre-select the slowest one for everybody. Changing a default means touching one line (DEFAULT_WEB_QUALITY / DEFAULT_LOCAL_QUALITY), and export-quality.test.ts pins both.
The export menu is a two-level menu: level one has two rows (native render / Web export), the › at the end of a row opens level two with the tiers, and picking one starts the export at that tier. In menu.tsx both panels are mounted together, keyboard roaming (↑↓) walks every row of both, → opens and ← / Esc steps back.
A "play once for real + captureStream" implementation (export-browser.ts) used to live here. On 2026-10-24 a real-machine comparison showed the frame-by-frame path was both better and faster, so that file was deleted — one capability, one implementation. Its original verdict of "unusable" actually came from running the same scene twice, with the old objects stacked under the new animation (the clearing fix lives in the core package); it was never about seek.
The export route is covered by src/host/routes.test.ts; the fetch binding lives in src/client/export.ts.
What ships is decided by files in package.json: index.js / client.js / src / assets / skills / cordis.patch.yml. docs/ is not part of the package.
Setting up the development environment
git clone https://github.com/snowowowo/dsh-manim-card.git
cd dsh-manim-card
pnpm install
pnpm build # produces client.jsInstalling into the host uses a symlink inside the profile plus a cordis.patch.yml entry: symlink this repository into the plugins directory of ~/.dsh/profiles/desktop/, and add a line for this plugin (the insert entry in this repository's own cordis.patch.yml) to that profile's cordis.patch.yml. HMR then takes effect, and the host side hot-reloads after a code change.
The npm publishing and GitHub direct-install paths have not yet been verified, see Installation.
Development flow
pnpm watch # tsdown --watch: rebuild client.js on every change under src/client
pnpm build # build the client.js artifact
pnpm test # vitest (offline test cases)
pnpm test:net # networked cases (MANIM_NET=1, timeout relaxed to 5 minutes)
pnpm coverage # coverage (v8, src only)
pnpm gen-skill # scripts/gen-skill.mjs: generate the domain skill for the model
pnpm docs # start the docs site locallyA typical change goes through these steps:
- Decide which half you are changing.
src/client/**must be rebuilt to take effect;src/host/**is plain JS and takes effect as soon as the file is saved, with no build. - For the client half, run
pnpm watch(orpnpm buildonce when done). - Refresh the host page before checking the result — HMR may not re-attach unloaded slots (especially the configuration section).
pnpm test; for changes touching on-demand package fetching, the real runtime, or network behaviour, runpnpm test:net.- When you touch the package name or the entry, confirm the client bundle's registration id still equals the package name — it is derived from
package.jsonbytsdown.preset.ts, never handwritten.
Tests
Unit tests sit next to their source files (*.test.ts); pnpm test runs the offline tier. Four divisions of labour worth knowing:
src/host/routes.test.tsrunsapply()for real against a fake ctx: the tool, the skill, the standing guide, and the registration and behavioural boundary of every asset and interface route all live in this one file;src/client/renderer.test.tspins the renderer wiring (the two asset addresses come fromsrc/routes.js, and exactly one renderer exists per page);src/client/runtime-status.test.tspins the pure selectors (status → tone, pending hints, actionability), driven by a fake translate function and touching neither the DOM nor render output;src/client/i18n.test.tsis a missing-copy regression net: a misspelled key or a mismatched placeholder is reported on the spot, naming the source file that uses it.
The native-render regression net lives in the core package (manim-live's export/local.test.ts and export/client.test.ts): on this side only the route and the fetch binding remain, and route behaviour belongs to routes.test.ts. Real runtime behaviour (Pyodide, the manim adaptation layer, the supported surface) is also covered by the core package's own suite, not by this repository.
The core package dependency
The core package is depended on by version (manim-live: ^0.4.0), not by a local link, so it can be kept aligned with the published release at any time:
pnpm add manim-live@latest # or edit the version in package.json, then pnpm install
pnpm build # re-inline into client.jsIf pnpm link was ever used to point at a local core-package checkout, node_modules/manim-live is a symlink and changing the version number does nothing — run pnpm unlink manim-live first, then pnpm install; pnpm-lock.yaml should go from link:../manim-live to a concrete version.
Troubleshooting entry points
- Artifact load failure /
duplicate factory registration: first check that the client bundle's registration id equals the package name. It is derived frompackage.jsonbytsdown.preset.ts, never handwritten. - Nothing renders: the real rendering and execution machinery lives in the core package manim-live (docs site), whose troubleshooting and development pages are more detailed than this one. Environment causes are all listed in the configuration section's "Browser runtime" card.
- Environment status empty or permanently "not loaded": check whether a second copy of the core package has been pulled in. Status must come from this plugin's own copy of
manim-live— this plugin provides no Cordis service, so there is no service surface to go through, see API Reference. - Formulas turned into tofu: check the KaTeX route in
src/routes.jsand whetherassets/katex/is complete.
Three parties, three jobs
From "AI writes code" to "an animation in the chat", three parties each own one stretch:
| Party | Owns | Does not own |
|---|---|---|
| The host | The conversation and chat stream, the slot and service systems, invocation and logging of manim_card | Rendering, Manim syntax, export |
| Core package manim-live | Python execution in the browser, the manim adaptation layer, the WebGL canvas, environment status verdicts, local probing and the local CLI export | Host integration, card UI, asset routes |
| This plugin | Host integration (routes, tool, slots), cards and playback scheduling, the configuration section, export wiring (both paths are wiring only) | Rendering, execution and export encoding themselves |
One difference from native Manim is worth remembering: the code is the same standard Manim Python, but execution happens in Pyodide inside the browser and the rendering engine is manim-web (not CE's Cairo pipeline). The usable surface is the common subset of Manim CE; coverage and gaps follow the core package's Support Surface.
Boundaries and conventions
- Corpus regression belongs to the core package repository (
corpus/); to pick or add samples, go over there. - The build preset
tsdown.preset.tshas its single source in thedsh-plugin-templaterepository and is byte-identical across plugin packages; change the preset in the template first, then copy the whole file over. - The single source of conventions and rules is the container repository
dsh-plugins'sAGENTS.mdand.agents/skills/; this page only points to them. - The docs site's two languages differ only in language, never in content: a change to Chinese must be mirrored in English, see
docs/README.md.