Skip to content

feat(app): add manifest-driven factory registry - #532

Draft
meganetaaan wants to merge 3 commits into
developfrom
feat/issue-511-compose-lazy-registry
Draft

feat(app): add manifest-driven factory registry#532
meganetaaan wants to merge 3 commits into
developfrom
feat/issue-511-compose-lazy-registry

Conversation

@meganetaaan

@meganetaaan meganetaaan commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

概要

compose.ts の driver / TTS / face 実装を manifest-controlled registry に移し、不要な実装を target ごとに外せる構成にします。

設計

  • compose.ts は registry から factory を解決
  • 各実装は small registrar module として factory を登録
  • default manifest は manifest_factories_all.json を include し、既存挙動どおり全実装を登録
  • サイズ最適化した target は include する registrar を絞ることで不要実装を外せます

変更内容

  • app factory registry と registrar 群を追加
  • manifest_base / manifest_factory_registry / manifest_factories_all を追加
  • audio / motion の汎用 manifest から全実装 preload を削除
  • registry unit test と architecture test を追加・更新

検証

  • cd firmware && npm run lint: pass
  • cd firmware && npm run test:unit: pass, 32 tests
  • cd firmware && npm run check:architecture: pass, 13 tests
  • git diff --check: pass

未実施

  • mcconfig 環境での manifest 解決確認
  • build:lin / 各ターゲット build
  • flash size 実測

リリース影響

patch。default manifest では既存挙動を維持しますが、build 構成に関わるためリリースノートに記載推奨です。

Closes #511
関連 #418

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Introduced a configurable factory-based setup for motion, text-to-speech, and UI selection.
    • Added additional motion options (none, pwm, dynamixel, m5stackchan, rs30x) and TTS options (openai, local, remote, elevenlabs, voicevox, voicevox-web).
    • Added new UI types (dog, image, simple, small-face).
    • Refreshed app startup composition to load capabilities via a shared base plus factory modules; updated preload contents for audio and motion.
  • Bug Fixes
    • Improved handling and validation of missing/duplicate factory types.
    • Tightened manifest wiring behavior to match actual startup module inclusion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb518f2e-f6af-4962-90eb-d8e6997172b1

📥 Commits

Reviewing files that changed from the base of the PR and between 19f3cc0 and 5409f13.

📒 Files selected for processing (5)
  • firmware/host/app/factory-registry/ui.ts
  • firmware/host/app/manifest.json
  • firmware/host/app/manifest_base.json
  • firmware/host/app/manifest_factories_all.json
  • firmware/host/modules/testing/fakes/capabilities.ts
💤 Files with no reviewable changes (2)
  • firmware/host/app/manifest_factories_all.json
  • firmware/host/app/manifest_base.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • firmware/host/app/factory-registry/ui.ts

📝 Walkthrough

Walkthrough

Introduces a factory registry for motion, TTS, and UI implementations, moves compose.ts to registry lookups, splits manifest wiring into base and registry fragments, trims preload lists, and updates TypeScript aliases and tests for the new layout.

Changes

Factory Registry Feature

Layer / File(s) Summary
Registry core and UI helper
firmware/host/app/factory-registry/registry.ts, firmware/host/app/factory-registry/ui.ts
Adds motion/TTS/UI registry maps with register, lookup, listing, and clear functions, plus Stackchan UI helper types and constructors.
Per-implementation factory registration modules
firmware/host/app/factory-registry/register/motion/*, firmware/host/app/factory-registry/register/tts/*, firmware/host/app/factory-registry/register/ui/*
Adds registry entries for concrete motion drivers, TTS engines, and UI faces.
compose.ts refactor to use factory registry
firmware/host/app/compose.ts
Replaces direct imports and local factory maps with registry lookups for driver, TTS, and UI selection.
Manifest fragments and preload updates
firmware/host/app/manifest.json, firmware/host/app/manifest_base.json, firmware/host/app/manifest_factory_registry.json, firmware/host/app/manifest_factories_all.json, firmware/host/app/manifest_wasm.json, firmware/host/modules/audio/manifest.json, firmware/host/modules/motion/manifest.json
Splits app manifest wiring into fragments, adds registry and factory preload manifests, and reduces audio/motion preload entries.
TypeScript path aliases for factory registry
firmware/tsconfig.json, firmware/tsconfig.test.json
Adds path aliases for the factory registry root, ui helper, and register subpaths.
Registry and manifest test updates
firmware/host/app/__tests__/factory-registry.test.ts, firmware/host/app/app-capabilities.architecture.ts, firmware/host/modules/testing/fakes/capabilities.ts, firmware/host/modules/ui/application/app-controller.architecture.ts, firmware/host/modules/ui/views/splash/splash-view.architecture.ts, firmware/host/platforms/platform-manifest.architecture.ts, firmware/host/platforms/wasm/wasm-stubs.architecture.ts, firmware/host/modules/audio/__tests__/audio-buffer-ownership.architecture.ts
Adds registry behavior tests, retargets manifest assertions to the new manifest files, and adds the RobotUI fake type.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RegisterModules
  participant Registry
  participant Compose
  RegisterModules->>Registry: registerMotionDriverFactory/registerTTSFactory/registerUIFactory(type, factory)
  Compose->>Registry: getMotionDriverFactory/getTTSFactory/getUIFactory(preferences.type)
  Registry-->>Compose: factory or undefined
Loading

Possibly related PRs

  • stack-chan/stack-chan#413: Adds the M5StackChanServoDriver implementation used by the new m5stackchan motion factory registration.
  • stack-chan/stack-chan#446: Updates the M5StackChanServoDriver export and related WASM manifest wiring used by the new m5stackchan motion factory registration.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change: introducing a manifest-driven factory registry.
Linked Issues check ✅ Passed The PR removes direct imports from compose.ts and moves driver, TTS, and UI registration into manifest-driven registry modules.
Out of Scope Changes check ✅ Passed The added manifests, registrars, tests, and tsconfig aliases all support the factory-registry refactor and appear in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-511-compose-lazy-registry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@meganetaaan

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meganetaaan

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
firmware/host/modules/testing/fakes/capabilities.ts (1)

15-16: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a more structured fake RobotUI type.

Record<string, unknown> is extremely permissive — any object satisfies it, which could mask missing methods in test fakes. The real RobotUI contract (from capabilities.ts) has specific methods like update, setFace, setMain, showFace, drawer operations, etc. A Partial<RobotUI> or a Pick of the methods actually used in tests would provide better compile-time safety while keeping fakes minimal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@firmware/host/modules/testing/fakes/capabilities.ts` around lines 15 - 16,
The fake RobotUI type is too permissive, so tests can compile even when required
UI methods are missing. Update the RobotUI alias in capabilities.ts to use a
structured shape based on the real RobotUI contract, such as a Partial or Pick
of only the methods the fakes actually rely on (for example update, setFace,
setMain, showFace, and drawer-related methods). Keep the fake minimal, but make
the type strict enough to catch missing methods at compile time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@firmware/host/app/factory-registry/ui.ts`:
- Around line 7-30: createRegisteredStackchanUI is ignoring
StackchanUIOptions.displayListLength and always using the separate
displayListLength parameter, so update the function to read the value from
options with a default fallback instead. Use the existing
createRegisteredStackchanUI and StackchanUIOptions symbols to remove the
redundant third argument or make it a fallback only, and ensure the value passed
into createAppControllerApplication comes from the resolved options value.

---

Nitpick comments:
In `@firmware/host/modules/testing/fakes/capabilities.ts`:
- Around line 15-16: The fake RobotUI type is too permissive, so tests can
compile even when required UI methods are missing. Update the RobotUI alias in
capabilities.ts to use a structured shape based on the real RobotUI contract,
such as a Partial or Pick of only the methods the fakes actually rely on (for
example update, setFace, setMain, showFace, and drawer-related methods). Keep
the fake minimal, but make the type strict enough to catch missing methods at
compile time.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0eb462d-4b97-4f80-9236-4554d07ea11d

📥 Commits

Reviewing files that changed from the base of the PR and between 092e56a and 19f3cc0.

📒 Files selected for processing (36)
  • firmware/host/app/__tests__/factory-registry.test.ts
  • firmware/host/app/app-capabilities.architecture.ts
  • firmware/host/app/compose.ts
  • firmware/host/app/factory-registry/register/motion/dynamixel.ts
  • firmware/host/app/factory-registry/register/motion/m5stackchan.ts
  • firmware/host/app/factory-registry/register/motion/none.ts
  • firmware/host/app/factory-registry/register/motion/pwm.ts
  • firmware/host/app/factory-registry/register/motion/rs30x.ts
  • firmware/host/app/factory-registry/register/motion/scservo.ts
  • firmware/host/app/factory-registry/register/tts/elevenlabs.ts
  • firmware/host/app/factory-registry/register/tts/local.ts
  • firmware/host/app/factory-registry/register/tts/openai.ts
  • firmware/host/app/factory-registry/register/tts/remote.ts
  • firmware/host/app/factory-registry/register/tts/voicevox-web.ts
  • firmware/host/app/factory-registry/register/tts/voicevox.ts
  • firmware/host/app/factory-registry/register/ui/dog.ts
  • firmware/host/app/factory-registry/register/ui/image.ts
  • firmware/host/app/factory-registry/register/ui/simple.ts
  • firmware/host/app/factory-registry/register/ui/small-face.ts
  • firmware/host/app/factory-registry/registry.ts
  • firmware/host/app/factory-registry/ui.ts
  • firmware/host/app/manifest.json
  • firmware/host/app/manifest_base.json
  • firmware/host/app/manifest_factories_all.json
  • firmware/host/app/manifest_factory_registry.json
  • firmware/host/app/manifest_wasm.json
  • firmware/host/modules/audio/__tests__/audio-buffer-ownership.architecture.ts
  • firmware/host/modules/audio/manifest.json
  • firmware/host/modules/motion/manifest.json
  • firmware/host/modules/testing/fakes/capabilities.ts
  • firmware/host/modules/ui/application/app-controller.architecture.ts
  • firmware/host/modules/ui/views/splash/splash-view.architecture.ts
  • firmware/host/platforms/platform-manifest.architecture.ts
  • firmware/host/platforms/wasm/wasm-stubs.architecture.ts
  • firmware/tsconfig.json
  • firmware/tsconfig.test.json

Comment thread firmware/host/app/factory-registry/ui.ts
@meganetaaan

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compose.ts が全ドライバ・全TTS・全Face実装を無条件にリンクし flash/RAM を圧迫する

1 participant