R1 pilot: stems ES-module migration, step 4b (reassigned scalars → S object) - #27
Conversation
…ep 4b) ES imports are read-only bindings, so the ~28 reassigned module scalars (audio graph: audioCtx/masterGain/analyserNode; stemState; worklet + decode flags; current-song fields) can't be `export let` — they move into one exported `S` object and every main.js reference becomes `S.x` (~230 sites). Collision-free rewrite: the AudioContext is `S.audioCtx`, and the four capability-command functions' local `ctx` param was renamed to `cmdCtx` first, so `ctx` was unambiguous. Verified 0 bare references, 0 double-prefix, no property-key/shorthand hazards before the sed. Move-only, no behaviour change. node 31/31, pytest 10/10, import-x/no-cycle clean on the 6-module graph, boots + executes in-browser against core-with-R0. NOT yet exercised: real playback (needs a seeded stems song). Boot/load/lint are green; on-device playback smoke recommended before release. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR moves mutable runtime state in ChangesState consolidation into S
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
There was a problem hiding this comment.
Pull request overview
This PR continues the ES-module migration by moving the reassigned/mutable module-level scalars (audio graph nodes, per-song fields, worklet/decode flags, etc.) into a single exported S object in src/state.js, and updating src/main.js to read/write those values via S.* so reassignment works with ESM’s read-only import bindings.
Changes:
- Add exported
Sobject tosrc/state.jsto hold previously-reassigned mutable scalars. - Update
src/main.jsto importSand replace former module-scoped scalars withS.*across the playback/worklet/transport logic. - Document the migration step in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/state.js | Introduces exported S object to centralize reassigned mutable scalar state under ESM. |
| src/main.js | Converts prior module-scoped scalar references to S.* and imports S from state.js. |
| CHANGELOG.md | Adds an entry describing “step 4b” and the rationale/verification notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@src/main.js`:
- Around line 1152-1161: The inline comment in the stem gain setup has been
accidentally rewritten to reference a field name, turning “wired” into a
spurious S.wired reference. Update the comment near S.stemState and the gain
initialization branch in the map callback so it reads as plain English again
(“wired into S.masterGain”) and does not look like a property access.
- Around line 1831-1836: Fix the corrupted comment text in the streaming path
near the content-type probe logic in main.js: the phrase describing desktop
audio should use the plain English noun “container,” not the accidental
field-like token “S.container.” Update the surrounding comment in the same block
that references audio/wav, audio/ogg, and the full-decode path so it reads
naturally and avoids misleading symbol-style wording.
🪄 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 Plus
Run ID: eddc2b7a-e7c3-49f1-9eb0-8c0c371ada9b
📒 Files selected for processing (3)
CHANGELOG.mdsrc/main.jssrc/state.js
|
✅ On-device playback smoke passed (Byron, local uvicorn: core@main + this branch, real multi-stem songs). Stems audible + sample-locked, toggle/volume/seek/teardown all correct — the |
The S.x rewrite matched generic English words inside comments: 'wired' (verb) -> S.wired, 'container' (ogg container noun) -> S.container, and the public-API JSDoc 'stemState' -> S.stemState. Comment-only, no functional impact; reverted to plain English (the JSDoc documents the public window.stems.stemState name).
R1 pilot — stems ES-module migration, step 4b (reassigned scalars →
Sobject)The hard part of the state extraction. The ~28 reassigned module scalars — the audio graph (
audioCtx/masterGain/analyserNode),stemState, the worklet + decode flags, the current-song fields — move into a single exportedSobject insrc/state.js.Why an
Sobject (notexport let)ES imports are read-only bindings, so
main.jscan't dox = …on an importedlet. Grouping the reassigned scalars in one object meansS.x = new AudioContext()works. Every reference becomesS.x(~230 sites).How the rewrite was de-risked
ctxused as a local param in the four capability-command functions — was renamed tocmdCtxfirst (verified they never touch the AudioContext), soctx → S.audioCtxwas unambiguous.sedhazards (property keys, object shorthand, binding collisions): none.S.prefixes, parse clean.sedhad rewrittenObject.defineProperty(stemsApi, 'stemState', …)to'S.stemState', which would have broken the publicwindow.stems.stemStateAPI. Fixed (property name restored; getter returnsS.stemState). This is the only string-literal occurrence in the file.Verification
npm test: 31/31; pytest: 10/10;import-x/no-cycleclean on the 6-module graph.window.stemsinstalls, worklet resolves, no errors).These scalars drive playback, but a true playback test needs a seeded stems
.sloppak(unavailable in the headless/empty-library dev setup). Boot/load/lint/tests are green; an on-device playback smoke is recommended before release (load a multi-stem song, toggle stems, drag volume, seek, let it end).Move-only, no behaviour change intended.
🤖 Generated with Claude Code
Summary by CodeRabbit