Skip to content

Commit 8d7979b

Browse files
author
DavidQ
committed
BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION: migrate remaining state/sample toFiniteNumber duplicates to shared math helper
1 parent 7dec821 commit 8d7979b

10 files changed

Lines changed: 156 additions & 52 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ MODEL: GPT-5.4
22
REASONING: high
33

44
COMMAND:
5-
Create BUILD_PR_SHARED_EXTRACTION_50_VECTOR_NUMBER_NORMALIZATION_TO_SHARED_MATH exactly as written in `docs/pr/BUILD_PR_SHARED_EXTRACTION_50_VECTOR_NUMBER_NORMALIZATION_TO_SHARED_MATH.md`.
5+
Execute `docs/pr/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION.md` exactly as written.
66

7-
Hard constraints:
8-
- Touch exactly 3 code files:
9-
- create `src/shared/math/numberNormalization.js`
10-
- modify `tools/shared/vector/vectorGeometryMath.js`
11-
- modify `tools/shared/vector/vectorAssetContract.js`
12-
- Do not touch any other file.
13-
- Preserve exact behavior from PR 49 for `toFiniteNumber` and `roundNumber`.
14-
- Do not broaden scope.
15-
- Package output to `<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_50_VECTOR_NUMBER_NORMALIZATION_TO_SHARED_MATH_delta.zip`
7+
Requirements:
8+
- modify only these code files:
9+
- `src/advanced/state/transitions.js`
10+
- `samples/shared/worldGameStateSystem.js`
11+
- use existing helper from:
12+
- `src/shared/math/numberNormalization.js`
13+
- remove local `toFiniteNumber(value, fallback = 0)` implementations from both target files
14+
- add correct shared imports
15+
- preserve behavior
16+
- fail fast if the shared export is missing or if extra files would be required
17+
18+
Package output to:
19+
- `<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION_delta.zip`

docs/dev/COMMIT_COMMENT.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
BUILD_PR_SHARED_EXTRACTION_50_VECTOR_NUMBER_NORMALIZATION_TO_SHARED_MATH
2-
3-
Extract vector-lane numeric normalization helpers into src/shared/math/numberNormalization.js and rewire vector imports without widening scope.
1+
BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION: migrate remaining state/sample toFiniteNumber duplicates to shared math helper

docs/dev/NEXT_COMMAND.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
After this BUILD is complete, report:
2-
1. the exact files changed
3-
2. whether `vectorGeometryMath.js` no longer defines local `toFiniteNumber` / `roundNumber`
4-
3. whether `vectorAssetContract.js` now imports numeric helpers from `src/shared/math/numberNormalization.js`
5-
4. whether only the 3 targeted code files changed
6-
Do not start another BUILD automatically.
1+
After this lands, inspect the two migrated files for any leftover inline numeric normalization helpers and only then propose the next exact-cluster BUILD.
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
Purpose: extract PR 49 vector numeric helpers into canonical shared math home.
1+
PR purpose:
2+
- migrate the remaining state/sample-local `toFiniteNumber` duplicates to the canonical shared math helper
23

34
Exact code scope:
4-
- create src/shared/math/numberNormalization.js
5-
- modify tools/shared/vector/vectorGeometryMath.js
6-
- modify tools/shared/vector/vectorAssetContract.js
5+
- `src/advanced/state/transitions.js`
6+
- `samples/shared/worldGameStateSystem.js`
77

8-
No other files may be changed.
8+
Shared dependency consumed:
9+
- `src/shared/math/numberNormalization.js`
10+
11+
Out of scope:
12+
- any vector files
13+
- any other number helper
14+
- any repo-wide cleanup
15+
- any new shared helper creation

docs/dev/reports/file_tree.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
src/shared/math/numberNormalization.js
2-
tools/shared/vector/vectorGeometryMath.js
3-
tools/shared/vector/vectorAssetContract.js
4-
docs/pr/BUILD_PR_SHARED_EXTRACTION_50_VECTOR_NUMBER_NORMALIZATION_TO_SHARED_MATH.md
5-
docs/dev/codex_commands.md
6-
docs/dev/commit_comment.txt
7-
docs/dev/next_command.txt
8-
docs/dev/reports/file_tree.txt
9-
docs/dev/reports/change_summary.txt
10-
docs/dev/reports/validation_checklist.txt
1+
docs/
2+
pr/
3+
BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION.md
4+
dev/
5+
codex_commands.md
6+
commit_comment.txt
7+
next_command.txt
8+
reports/
9+
file_tree.txt
10+
change_summary.txt
11+
validation_checklist.txt
12+
src/
13+
advanced/
14+
state/
15+
transitions.js
16+
samples/
17+
shared/
18+
worldGameStateSystem.js
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
[ ] Single PR purpose only
2-
[ ] Exact 3 code files only
3-
[ ] No repo scan / no scope expansion
4-
[ ] numberNormalization.js exports only toFiniteNumber and roundNumber
5-
[ ] vectorGeometryMath.js removes local helper definitions
6-
[ ] vectorAssetContract.js imports numeric helpers from shared math
7-
[ ] Behavior preserved from PR 49
8-
[ ] Output zip path set under <project folder>/tmp/
1+
[ ] Confirm `src/shared/math/numberNormalization.js` exports `toFiniteNumber`
2+
[ ] `src/advanced/state/transitions.js` imports shared `toFiniteNumber`
3+
[ ] Local `toFiniteNumber` removed from `src/advanced/state/transitions.js`
4+
[ ] `samples/shared/worldGameStateSystem.js` imports shared `toFiniteNumber`
5+
[ ] Local `toFiniteNumber` removed from `samples/shared/worldGameStateSystem.js`
6+
[ ] No unused imports remain in the two target files
7+
[ ] No files outside the exact target set were modified
8+
[ ] Delta zip written to `<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION_delta.zip`
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# BUILD PR — STATE + SAMPLE `toFiniteNumber` MIGRATION
2+
3+
## PR Purpose
4+
Migrate the remaining state/sample-local `toFiniteNumber(value, fallback = 0)` implementations to the canonical shared math helper in `src/shared/math/numberNormalization.js`.
5+
6+
This PR has one purpose only:
7+
- replace exact local duplicate implementations in the two known remaining consumer files
8+
- preserve behavior with fallback default `0`
9+
- do not widen scope beyond these files
10+
11+
## Exact Target Files
12+
### Code files to modify
13+
- `src/advanced/state/transitions.js`
14+
- `samples/shared/worldGameStateSystem.js`
15+
16+
### Existing shared dependency to use
17+
- `src/shared/math/numberNormalization.js`
18+
19+
### Delivery docs to include/update in this bundle
20+
- `docs/pr/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION.md`
21+
- `docs/dev/codex_commands.md`
22+
- `docs/dev/commit_comment.txt`
23+
- `docs/dev/next_command.txt`
24+
- `docs/dev/reports/file_tree.txt`
25+
- `docs/dev/reports/change_summary.txt`
26+
- `docs/dev/reports/validation_checklist.txt`
27+
28+
## Preconditions
29+
Assume BUILD 50 has already landed and the canonical helper exists in:
30+
- `src/shared/math/numberNormalization.js`
31+
32+
Assume that file exports:
33+
- `toFiniteNumber(value, fallback = 0)`
34+
- `roundNumber(value)` may also exist there, but it is out of scope for this PR
35+
36+
If the canonical `toFiniteNumber` export does not exist in `src/shared/math/numberNormalization.js`, fail fast and stop.
37+
38+
## Required Code Changes
39+
### 1) `src/advanced/state/transitions.js`
40+
- remove the local `function toFiniteNumber(value, fallback = 0)` implementation
41+
- import `toFiniteNumber` from `src/shared/math/numberNormalization.js` using the correct relative path
42+
- preserve all existing call-site behavior
43+
- do not change other helpers in this file
44+
45+
### 2) `samples/shared/worldGameStateSystem.js`
46+
- remove the local `function toFiniteNumber(value, fallback = 0)` implementation
47+
- import `toFiniteNumber` from `src/shared/math/numberNormalization.js` using the correct relative path
48+
- preserve all existing call-site behavior
49+
- do not change unrelated helpers in this file
50+
51+
## Explicit Non-Goals
52+
Do NOT:
53+
- modify `src/shared/math/numberNormalization.js`
54+
- touch any vector files
55+
- touch any other number helpers (`asFiniteNumber`, `asPositiveNumber`, `normalizeNumber`, `sanitizeFiniteNumber`, etc.)
56+
- touch any files other than the two exact code files listed above
57+
- rename exports
58+
- perform repo-wide cleanup
59+
- change logic beyond replacing the duplicate local helper with the shared import
60+
61+
## Acceptance Criteria
62+
- both target files import `toFiniteNumber` from `src/shared/math/numberNormalization.js`
63+
- both target files no longer define a local `toFiniteNumber`
64+
- behavior remains fallback-compatible with default `0`
65+
- no unused imports remain
66+
- no call sites are changed beyond the import-based migration
67+
- bundle output is written to `<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION_delta.zip`
68+
69+
## Validation Steps
70+
1. Confirm `src/shared/math/numberNormalization.js` exports `toFiniteNumber`
71+
2. Open `src/advanced/state/transitions.js`
72+
- verify local `toFiniteNumber` removed
73+
- verify shared import added
74+
3. Open `samples/shared/worldGameStateSystem.js`
75+
- verify local `toFiniteNumber` removed
76+
- verify shared import added
77+
4. Search only within the two target files for `function toFiniteNumber`
78+
- expect zero matches
79+
5. Ensure there are no unused imports in the two target files
80+
6. Package only the changed files plus required docs into:
81+
- `<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION_delta.zip`
82+
83+
## Fail-Fast Conditions
84+
Stop immediately if any of the following occurs:
85+
- `src/shared/math/numberNormalization.js` does not export `toFiniteNumber`
86+
- migration would require touching files beyond the two exact code files
87+
- behavior-preserving replacement cannot be completed directly
88+
- any ambiguity appears about which helper version should be used
89+
90+
## Output Expectation
91+
Return one repo-structured delta zip at:
92+
- `<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION_delta.zip`
93+
94+
Include only:
95+
- changed code files
96+
- docs for this PR
97+
- report files for this PR
98+
99+
Do not include unrelated files, full-repo copies, dependencies, or build artifacts.

samples/shared/worldGameStateSystem.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ David Quesenberry
55
worldGameStateSystem.js
66
*/
77

8+
import { toFiniteNumber } from '../../src/shared/math/numberNormalization.js';
9+
810
const WORLD_GAME_STATE_SYSTEM_ID = 'worldGameStateSystem';
911

1012
const WORLD_GAME_STATE_EVENT_TYPES = Object.freeze({
@@ -99,11 +101,6 @@ function mergeDeep(baseValue, patchValue) {
99101
return patchValue === undefined ? cloneDeep(baseValue) : patchValue;
100102
}
101103

102-
function toFiniteNumber(value, fallback = 0) {
103-
const numeric = Number(value);
104-
return Number.isFinite(numeric) ? numeric : fallback;
105-
}
106-
107104
function createInitialWorldGameState(initialPatch = {}) {
108105
const baseline = {
109106
contractVersion: 1,

src/advanced/state/transitions.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ transitions.js
77

88
import { WORLD_GAME_STATE_EVENT_TYPES } from './constants.js';
99
import { isPlainObject } from '../../shared/utils/objectUtils.js';
10-
11-
function toFiniteNumber(value, fallback = 0) {
12-
const numeric = Number(value);
13-
return Number.isFinite(numeric) ? numeric : fallback;
14-
}
10+
import { toFiniteNumber } from '../../shared/math/numberNormalization.js';
1511

1612
function recalcObjectiveSummary(objectivesById) {
1713
const objectiveIds = Object.keys(objectivesById);

fix-engine-paths.ps1 renamed to tools/shared/powerShell/fix-engine-paths.ps1

File renamed without changes.

0 commit comments

Comments
 (0)