Skip to content

feat: add Stack-chan WASM build support - #446

Merged
meganetaaan merged 17 commits into
dev/v1.0from
feat/wasm-stackchan-build
May 15, 2026
Merged

feat: add Stack-chan WASM build support#446
meganetaaan merged 17 commits into
dev/v1.0from
feat/wasm-stackchan-build

Conversation

@meganetaaan

@meganetaaan meganetaaan commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a WASM build target for Stack-chan firmware.
  • Adds WASM-specific manifests, driver/service/speech stubs, and default MOD launch wiring.
  • Updates CI/build setup for the WASM firmware path, including pinned Moddable setup.

What Changed

  • Added manifest_wasm.json and WASM renderer/utility manifests.
  • Added WASM driver facades and browser-oriented service/speech implementations.
  • Updated firmware build scripts and GitHub Actions setup for host/WASM builds.

Verification

  • cd firmware && npm run format
  • cd firmware && npm run lint
  • cd firmware && npm run test
  • Other checks were run when relevant

Not run locally in this PR-opening step; relying on CI and the branch's existing verification history.

Affected Areas

  • firmware
  • web
  • schematics
  • case
  • docs
  • ci/github-actions

Breaking Changes

  • none
  • yes, described below

Related Issues

  • Follow-up/reopen of the WASM build support branch against dev/v1.0.

Summary by CodeRabbit

  • New Features

    • Added input validation for servo rotation parameters in the WebAssembly driver to ensure proper motor control.
  • Tests

    • Expanded test coverage for driver validation, manifest mappings, and rotation parameter verification.
  • Chores

    • Simplified Moddable SDK pinning process in the build workflow.
    • Extended WebAssembly configuration with new driver and LED module mappings.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c7a514ed-87a6-4aa7-9af6-21a9c7ca2b2f

📥 Commits

Reviewing files that changed from the base of the PR and between 197a76f and 77b4abe.

📒 Files selected for processing (6)
  • .github/workflows/build.yml
  • firmware/stackchan/drivers/wasm/m5stackchan-servo-driver.ts
  • firmware/stackchan/drivers/wasm/wasm-driver.ts
  • firmware/stackchan/manifest_wasm.json
  • firmware/stackchan/wasm/py32-led.ts
  • firmware/tests/unit/wasm-stubs.test.ts
✅ Files skipped from review due to trivial changes (2)
  • firmware/stackchan/wasm/py32-led.ts
  • firmware/stackchan/manifest_wasm.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • firmware/stackchan/drivers/wasm/wasm-driver.ts

📝 Walkthrough

Walkthrough

This PR adds WASM facade module entrypoints for servo and LED drivers, validates their manifest routing and import patterns, enhances rotation payload validation in the driver bridge, and refactors CI Moddable SDK pinning to use action inputs.

Changes

WASM Facade Modules and Validation

Layer / File(s) Summary
M5StackChanServoDriver facade module
firmware/stackchan/drivers/wasm/m5stackchan-servo-driver.ts, firmware/tests/unit/wasm-stubs.test.ts
m5stackchan-servo-driver facade module re-exports M5StackChanServoDriver, test imports verify the alias is consolidated into WasmDriver, and manifest assertion coverage extends to include the new module mapping.
WASM manifest routing and facade integration tests
firmware/stackchan/manifest_wasm.json, firmware/tests/unit/wasm-stubs.test.ts
Module-to-path mappings are extended for both servo and LED facades, and test assertions verify that both py32-led and m5stackchan-servo-driver use manifest specifiers (e.g., from 'led') rather than relative ./ imports.
Rotation input validation testing
firmware/tests/unit/wasm-stubs.test.ts
applyRotation validation test mocks the host bridge and confirms that invalid rotation payloads containing NaN are rejected, valid rotations trigger a single host call, and getRotation() reflects the accepted value.

CI Moddable SDK Setup

Layer / File(s) Summary
Moddable SDK revision as setup input
.github/workflows/build.yml
Pinned Moddable commit hash is passed as target-branch input to the ./.github/actions/setup step, removing the previous inline fetch and detached checkout step.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • stack-chan/stack-chan#414: Modifies the ./.github/actions/setup step to pin/default Moddable SDK revision, related to the refactored target-branch input pattern.
  • stack-chan/stack-chan#402: Changes Moddable SDK pinning in the GitHub Actions build workflow, overlapping with the CI setup refactor.
  • stack-chan/stack-chan#355: Adds the exported Led/led module that the new py32-led facade re-exports from, providing the underlying implementation.

Suggested reviewers

  • stc1988

Poem

🐰 New facades bloom, drivers aligned,
Manifest routes through the modules wind,
Rotations checked before they fly,
CI's setup simplified,
WASM pathways unified! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add Stack-chan WASM build support' directly and clearly summarizes the main objective of the changeset: adding WASM build capability to Stack-chan firmware.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/wasm-stackchan-build

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 197a76fbd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread firmware/stackchan/manifest_wasm.json

@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.

🧹 Nitpick comments (2)
.github/workflows/build.yml (1)

64-67: ⚡ Quick win

Align SDK pinning with setup action input for deterministic caching.

Line 64-67 pins a SHA after setup, but setup/cache-key resolution still follows its default ref path. Pass the same SHA via target-branch so install + cache + build all use one source of truth.

Proposed change
-      - uses: ./.github/actions/setup
-      - name: Pin Moddable SDK
-        run: |
-          git -C "$HOME/.local/share/moddable" fetch origin b0411457e4577ea5560c780cb7824f3b00c2b2af
-          git -C "$HOME/.local/share/moddable" checkout --detach FETCH_HEAD
+      - uses: ./.github/actions/setup
+        with:
+          target-branch: b0411457e4577ea5560c780cb7824f3b00c2b2af
🤖 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 @.github/workflows/build.yml around lines 64 - 67, The workflow currently
pins the Moddable SDK by checking out a SHA in the "Pin Moddable SDK" step but
does not pass that SHA to the earlier setup action; update the setup/install
step for the Moddable SDK to receive the same SHA via the target-branch input so
install, cache-key resolution, and the later checkout use the same ref; locate
the setup action step (the Moddable SDK setup or install step) and add
target-branch: "<the same SHA currently used in the Pin Moddable SDK step>" so
the cache and build are deterministic.
firmware/stackchan/drivers/wasm/wasm-driver.ts (1)

28-31: ⚡ Quick win

Consider validating the rotation parameter structure.

The applyRotation method accepts a rotation parameter but does not validate that it contains valid numeric y, p, and r properties. If called with malformed data (e.g., missing fields, non-numeric values), the spread operation on line 29 would silently accept invalid state, and the host bridge might receive unexpected data.

🛡️ Proposed validation guard
 async applyRotation(rotation: Rotation, time?: number): Promise<void> {
+  if (typeof rotation.y !== 'number' || typeof rotation.p !== 'number' || typeof rotation.r !== 'number') {
+    throw new TypeError('Invalid rotation: y, p, r must be numbers')
+  }
   this.#rotation = { ...rotation }
   globalThis.Host?.Driver?.applyRotation?.({ rotation, time })
 }
🤖 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/stackchan/drivers/wasm/wasm-driver.ts` around lines 28 - 31, The
applyRotation method currently assigns and forwards whatever is passed, risking
invalid state; add a validation guard inside applyRotation to ensure the
rotation object has numeric y, p, and r properties (e.g., Number.isFinite
checks) before setting this.#rotation and calling
globalThis.Host?.Driver?.applyRotation; if validation fails, do not mutate
this.#rotation and either throw or log an error (use existing logging pattern)
so malformed inputs are rejected and the host bridge never receives invalid
data.
🤖 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.

Nitpick comments:
In @.github/workflows/build.yml:
- Around line 64-67: The workflow currently pins the Moddable SDK by checking
out a SHA in the "Pin Moddable SDK" step but does not pass that SHA to the
earlier setup action; update the setup/install step for the Moddable SDK to
receive the same SHA via the target-branch input so install, cache-key
resolution, and the later checkout use the same ref; locate the setup action
step (the Moddable SDK setup or install step) and add target-branch: "<the same
SHA currently used in the Pin Moddable SDK step>" so the cache and build are
deterministic.

In `@firmware/stackchan/drivers/wasm/wasm-driver.ts`:
- Around line 28-31: The applyRotation method currently assigns and forwards
whatever is passed, risking invalid state; add a validation guard inside
applyRotation to ensure the rotation object has numeric y, p, and r properties
(e.g., Number.isFinite checks) before setting this.#rotation and calling
globalThis.Host?.Driver?.applyRotation; if validation fails, do not mutate
this.#rotation and either throw or log an error (use existing logging pattern)
so malformed inputs are rejected and the host bridge never receives invalid
data.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c103ccc2-a8a2-49e0-851f-3319ed1cef25

📥 Commits

Reviewing files that changed from the base of the PR and between 3a0fb5a and 197a76f.

📒 Files selected for processing (32)
  • .github/PULL_REQUEST_TEMPLATE.md
  • .github/actions/setup/action.yml
  • .github/workflows/build.yml
  • firmware/mods/chat_audioio/mod.js
  • firmware/package.json
  • firmware/scripts/README_ja.md
  • firmware/stackchan/default-mods/wasm/on-launch.ts
  • firmware/stackchan/drivers/wasm/driver-stub.ts
  • firmware/stackchan/drivers/wasm/dynamixel-driver.ts
  • firmware/stackchan/drivers/wasm/none-driver.ts
  • firmware/stackchan/drivers/wasm/rs30x-driver.ts
  • firmware/stackchan/drivers/wasm/scservo-driver.ts
  • firmware/stackchan/drivers/wasm/sg90-driver.ts
  • firmware/stackchan/drivers/wasm/wasm-driver.ts
  • firmware/stackchan/main.ts
  • firmware/stackchan/manifest_wasm.json
  • firmware/stackchan/renderers-piu/manifest_wasm_renderer_piu.json
  • firmware/stackchan/services/wasm/network-service.ts
  • firmware/stackchan/services/wasm/preference-server.ts
  • firmware/stackchan/speeches/wasm/tts-elevenlabs.ts
  • firmware/stackchan/speeches/wasm/tts-local.ts
  • firmware/stackchan/speeches/wasm/tts-openai.ts
  • firmware/stackchan/speeches/wasm/tts-remote.ts
  • firmware/stackchan/speeches/wasm/tts-stub.ts
  • firmware/stackchan/speeches/wasm/tts-voicevox-web.ts
  • firmware/stackchan/speeches/wasm/tts-voicevox.ts
  • firmware/stackchan/utilities/manifest_wasm_utility.json
  • firmware/stackchan/wasm/led.ts
  • firmware/stackchan/wasm/microphone.ts
  • firmware/stackchan/wasm/tone.ts
  • firmware/tests/unit/wasm-stubs.test.ts
  • firmware/tsconfig.test.json

@meganetaaan
meganetaaan force-pushed the feat/wasm-stackchan-build branch from faef7ee to 70a0807 Compare May 15, 2026 00:12
@meganetaaan

Copy link
Copy Markdown
Collaborator Author

レビューコメント対応しました。

対応内容:

  • Codex P1: main.ts の静的 import が WASM manifest で解決できるよう、m5stackchan-servo-driverpy32-led の manifest alias / facade / 回帰テストを追加しました。該当 thread に返信し、resolve 済みです。
  • CodeRabbit nit: WasmDriver.applyRotation() に finite number guard を追加し、不正な rotation では state 更新・Host bridge 呼び出しをしない回帰テストを追加しました。
  • CodeRabbit nit: Moddable SDK pin を setup action の target-branch 入力へ寄せ、cache key / install / build の参照を揃えました。
  • dev/v1.0 をマージして、PR は MERGEABLE に戻しています。

検証:

  • cd firmware && npm run format
  • cd firmware && npm run lint(既存 warning は残りますが exit 0)
  • cd firmware && npm test
  • cd firmware && npm run build:wasm

CI は push 後に再実行中です。

@meganetaaan
meganetaaan merged commit 3e2add5 into dev/v1.0 May 15, 2026
8 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
5 tasks
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.

1 participant