Skip to content

[codex] Extract light environment model#457

Merged
elkimek merged 2 commits into
mainfrom
codex/extract-light-env-model
May 30, 2026
Merged

[codex] Extract light environment model#457
elkimek merged 2 commits into
mainfrom
codex/extract-light-env-model

Conversation

@elkimek
Copy link
Copy Markdown
Owner

@elkimek elkimek commented May 30, 2026

Summary

  • Extract Light Environment option lists, picker buckets, severity scoring, screen status, and burden math into js/light-env-model.js.
  • Keep js/light-env.js as the state/storage/rendering facade with compatibility wrappers for existing callers.
  • Precache the new model module and bump version.js to 1.8.285.

Validation

  • node --check js/light-env.js
  • node --check js/light-env-model.js
  • node --check tests/test-light-env.js
  • node tests/test-light-env.js
  • node tests/test-correctness-phase2.js
  • ./run-tests.sh

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
get-based Ready Ready Preview, Comment May 30, 2026 4:37pm

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 30, 2026

Greptile Summary

This PR extracts all deterministic light-environment logic (option lists, picker bucket helpers, and scoring math) from js/light-env.js into a new stateless js/light-env-model.js, keeping light-env.js as the stateful facade with thin wrappers that inject getEnvironment, getScreensForRoom, and isActiveToday.

  • New model module (light-env-model.js) exports PRIMARY_SOURCES, SCREEN_DEVICES, SOURCE_ARCHETYPES, the three bucket arrays, four pure helpers, computeRoomSeverityForRoom, computeScreenStatus, computeDeficitAxesForEnvironment, and computeIndoorBurdenForEnvironment — all free of app state and storage calls.
  • Facade wrappers in light-env.js (computeRoomSeverity, computeDeficitAxes, computeIndoorBurden) delegate to the model, injecting environment and screen state so every existing caller continues to work without changes.
  • Service worker + tests are updated to precache the new module and assert both the re-export identity and isolation invariants (no saveImportedData, no renderEnvironmentSection, no _hasAnyRoomSignal leaking back into light-env.js).

Confidence Score: 5/5

Safe to merge — the refactor is a clean extraction with no logic changes; all public APIs are preserved and new tests verify both isolation and behavioural equivalence.

All scoring math, bucket helpers, and option lists are moved verbatim into the model module. The stateful wrappers in light-env.js inject the same environment and screen state that the old functions used directly, so runtime behaviour is unchanged for every existing caller. New tests assert re-export identity, screen-aware vs. skipped-screen room severity, and source-text isolation invariants. No logic was altered.

No files require special attention.

Important Files Changed

Filename Overview
js/light-env-model.js New stateless model module exporting option lists, picker buckets, and all scoring math (computeRoomSeverityForRoom, computeScreenStatus, computeDeficitAxesForEnvironment, computeIndoorBurdenForEnvironment); correctly isolated from app state and rendering
js/light-env.js Strips extracted logic and replaces it with import+re-export from light-env-model.js; adds thin stateful wrappers (computeRoomSeverity, computeDeficitAxes, computeIndoorBurden) that inject getEnvironment/getScreensForRoom/isActiveToday; public API preserved for all existing callers
tests/test-light-env.js Adds direct model imports and new assertions covering: re-export identity, screen-aware wrapper vs. skipped-screen behaviour, state-free deficit axes with isActiveToday filter, and isolation guard (modelSrc checks)
service-worker.js Adds /js/light-env-model.js to APP_SHELL precache list; correctly placed with the other light-env* modules
tests/test-correctness-phase2.js Adds /js/light-env-model.js to the pwaAppShellAssets list so the service-worker precache test covers the new module
version.js Patch-level version bump from 1.8.284 to 1.8.285 to bust the service-worker cache after adding the new module

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[light-env.js\nfacade / storage / rendering] -->|imports pure logic| B[light-env-model.js\nstateless model]
    A -->|imports evening helpers| C[light-env-evening.js]
    B -->|imports evening helpers| C
    A -->|re-exports option lists &\npicker helpers unchanged| D[Existing callers]
    A -->|stateful wrappers\ninject getEnvironment / getScreensForRoom / isActiveToday| E[computeRoomSeverity\ncomputeDeficitAxes\ncomputeIndoorBurden]
    B -->|pure state-free exports| F[computeRoomSeverityForRoom\ncomputeDeficitAxesForEnvironment\ncomputeIndoorBurdenForEnvironment]
    F -->|used by| G[Tests / future AI-context callers]
    E -->|delegates to| F
Loading

Reviews (2): Last reviewed commit: "Clarify light environment severity model" | Re-trigger Greptile

Comment thread js/light-env-model.js
@elkimek elkimek merged commit 540234f into main May 30, 2026
4 checks passed
@elkimek elkimek deleted the codex/extract-light-env-model branch May 30, 2026 16:39
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