Skip to content

Commit 77f9254

Browse files
author
DavidQ
committed
Promote asNumber into src/shared/math/numberNormalization.js and migrate the two exact network debug utility duplicates.
1 parent 8d7979b commit 77f9254

10 files changed

Lines changed: 76 additions & 67 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
MODEL: GPT-5.4
1+
MODEL: GPT-5.4-codex
22
REASONING: high
33

44
COMMAND:
5-
Execute `docs/pr/BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION.md` exactly as written.
6-
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`
5+
Execute exactly docs/pr/BUILD_PR_SHARED_EXTRACTION_52_ASNUMBER_TO_SHARED_MATH.md.
6+
Modify only the exact target files listed in the PR doc.
7+
Do not expand scope.
8+
Package the delta zip to:
9+
<project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_52_ASNUMBER_TO_SHARED_MATH_delta.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BUILD_PR_SHARED_EXTRACTION_51_STATE_SAMPLE_TOFINITENUMBER_MIGRATION: migrate remaining state/sample toFiniteNumber duplicates to shared math helper
1+
Promote asNumber into src/shared/math/numberNormalization.js and migrate the two exact network debug utility duplicates.

docs/dev/NEXT_COMMAND.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
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.
1+
After commit, continue with BUILD_PR_SHARED_EXTRACTION_53_ASTEROIDS_NUMBER_SANITIZERS_TO_SHARED_MATH using exact files only.
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
PR purpose:
2-
- migrate the remaining state/sample-local `toFiniteNumber` duplicates to the canonical shared math helper
3-
4-
Exact code scope:
5-
- `src/advanced/state/transitions.js`
6-
- `samples/shared/worldGameStateSystem.js`
7-
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
1+
- Promote duplicated asNumber helper into canonical shared math
2+
- Remove duplicate local asNumber definitions from the two exact network debug utility files
3+
- Preserve existing exports and caller-facing API

docs/dev/reports/file_tree.txt

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
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
1+
src/shared/math/numberNormalization.js
2+
src/shared/utils/networkDebugUtils.js
3+
src/engine/debug/network/shared/networkDebugUtils.js
4+
docs/pr/BUILD_PR_SHARED_EXTRACTION_52_ASNUMBER_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
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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`
1+
# Validation Checklist
2+
- Confirm only the exact target files were modified
3+
- Confirm no wildcard or repo-wide scanning was introduced into the implementation
4+
- Confirm imports resolve correctly after the change
5+
- Confirm no dead local helper remains in the touched files for this PR purpose
6+
- Confirm no unrelated refactor or formatting-only churn was introduced
7+
- Confirm `asObject` and `asArray` were not changed in this PR
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# BUILD PR — Promote `asNumber(value, fallback = 0)` into shared math
2+
3+
## Purpose
4+
Move the duplicate `asNumber` helper into the canonical numeric home and migrate the exact duplicate sites.
5+
6+
## Exact Target Files
7+
- `src/shared/math/numberNormalization.js`
8+
- `src/shared/utils/networkDebugUtils.js`
9+
- `src/engine/debug/network/shared/networkDebugUtils.js`
10+
11+
## Required Code Changes
12+
1. In `src/shared/math/numberNormalization.js`
13+
- add/export `asNumber(value, fallback = 0)`
14+
- preserve current runtime behavior of the duplicate helper exactly
15+
16+
2. In `src/shared/utils/networkDebugUtils.js`
17+
- stop defining local `asNumber`
18+
- import `asNumber` from `src/shared/math/numberNormalization.js`
19+
- preserve the file's existing public API
20+
21+
3. In `src/engine/debug/network/shared/networkDebugUtils.js`
22+
- stop defining local `asNumber`
23+
- import `asNumber` from `src/shared/math/numberNormalization.js`
24+
- preserve the file's existing public API
25+
26+
## Hard Constraints
27+
- exact files only
28+
- do not touch `asObject`, `asArray`, or any other helper in this PR
29+
- do not modify any consumer files outside the exact list
30+
- do not rename exports other than replacing local helper definitions with shared import usage
31+
- do not refactor unrelated logic
32+
33+
## Acceptance Criteria
34+
- one canonical `asNumber` implementation exists in `src/shared/math/numberNormalization.js`
35+
- both network debug utility files use the shared math implementation
36+
- no local `asNumber` implementation remains in the two target files
37+
- no import/export breakage

src/engine/debug/network/shared/networkDebugUtils.js

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

8+
import { asNumber } from "../../../../shared/math/numberNormalization.js";
9+
810
export function sanitizeText(value) {
911
return typeof value === "string" ? value.trim() : "";
1012
}
@@ -17,10 +19,7 @@ export function asArray(value) {
1719
return Array.isArray(value) ? value : [];
1820
}
1921

20-
export function asNumber(value, fallback = 0) {
21-
const numeric = Number(value);
22-
return Number.isFinite(numeric) ? numeric : fallback;
23-
}
22+
export { asNumber };
2423

2524
export function asBoolean(value, fallback = false) {
2625
if (typeof value === "boolean") {

src/shared/math/numberNormalization.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ export function toFiniteNumber(value, fallback = NaN) {
33
return Number.isFinite(numeric) ? numeric : fallback;
44
}
55

6+
export function asNumber(value, fallback = 0) {
7+
const numeric = Number(value);
8+
return Number.isFinite(numeric) ? numeric : fallback;
9+
}
10+
611
export function roundNumber(value) {
712
if (!Number.isFinite(value)) {
813
return value;

src/shared/utils/networkDebugUtils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { asNumber } from "../math/numberNormalization.js";
2+
13
function sanitizeText(value) {
24
return typeof value === "string" ? value.trim() : "";
35
}
@@ -14,10 +16,7 @@ function toSafeKey(value) {
1416
return sanitizeText(value);
1517
}
1618

17-
export function asNumber(value, fallback = 0) {
18-
const numeric = Number(value);
19-
return Number.isFinite(numeric) ? numeric : fallback;
20-
}
19+
export { asNumber };
2120

2221
export function toNetworkSnapshot(snapshot) {
2322
const sampleKey = arguments[1];

0 commit comments

Comments
 (0)