Skip to content

Commit c384373

Browse files
author
DavidQ
committed
PR_03_03_SHARED_SELECTORS_CONTRACTS
1 parent 2b31fec commit c384373

9 files changed

Lines changed: 167 additions & 24 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,40 @@ MODEL: GPT-5.4
88
REASONING: high
99

1010
COMMAND:
11-
Implement PR_03_02_SHARED_STRINGS_EXTRACTION.
11+
Implement PR_03_03_SHARED_SELECTORS_CONTRACTS.
1212

1313
Goal:
14-
Consolidate duplicated string helpers onto the shared layer with no behavior or API changes.
14+
Standardize selector usage and contract boundaries onto shared state/public reader surfaces with no behavior or API changes.
1515

16-
Target layer:
17-
- src/shared/utils/
16+
Target areas:
17+
- src/shared/state/
18+
- public selector/read boundary surfaces
1819

19-
Focus helpers:
20-
- normalizeString
21-
- safeTrim
22-
- toLowerSafe
23-
- stringCompare
20+
Focus:
21+
- getState
22+
- getSimulationState
23+
- getReplayState
24+
- getEditorState
25+
- public selector/read boundaries
2426

2527
Required steps:
26-
1. Produce docs/dev/reports/string_usage_scan.txt for string helper duplicates and consumers in scope.
27-
2. Produce docs/dev/reports/extraction_map.txt with exact source -> shared target mapping.
28-
3. Standardize consumers in scope onto shared string helpers.
29-
4. Remove only obsolete duplicate string helper implementations within this PR scope.
28+
1. Produce docs/dev/reports/selector_usage_scan.txt for selector variants and consumers in scope.
29+
2. Produce docs/dev/reports/contract_map.txt with exact source -> standardized target mapping.
30+
3. Standardize consumers in scope onto shared selector/contract surfaces.
31+
4. Remove only obsolete duplicate selector/contract implementations within this PR scope.
3032
5. Keep changes surgical.
3133

3234
Rules:
33-
- string helpers only
34-
- no number/id/object helper extraction
35+
- selector/contract work only
36+
- no number/string/id helper extraction
3537
- no broad cleanup
3638
- no API changes
3739
- no behavior changes
3840

3941
Validation:
4042
- impacted imports resolve
41-
- duplicate string helpers in scope removed or redirected
43+
- duplicate selector variants in scope removed or redirected
4244
- impacted tests/smoke pass
4345

4446
Return ZIP:
45-
<project folder>/tmp/PR_03_02_SHARED_STRINGS_EXTRACTION.zip
47+
<project folder>/tmp/PR_03_03_SHARED_SELECTORS_CONTRACTS.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
PR_03_02_SHARED_STRINGS_EXTRACTION
1+
PR_03_03_SHARED_SELECTORS_CONTRACTS
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Shared string helper consolidation package focused on canonicalizing string normalization utilities under src/shared/utils.
1+
Shared selector and contract consolidation package focused on canonicalizing selector/read boundaries under shared state surfaces.

docs/dev/reports/contract_map.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
PR_03_03_SHARED_SELECTORS_CONTRACTS - contract map
2+
3+
Canonical selector/contract surfaces:
4+
1) src/shared/state/getState.js::getState
5+
- canonical public reader for promotion gate state snapshots
6+
7+
2) src/shared/state/publicSelectors.js
8+
- getState(source)
9+
- getSimulationState(source)
10+
- getReplayState(source)
11+
- getEditorState(source)
12+
13+
Source -> standardized target mapping:
14+
- src/advanced/state/createWorldGameStateSystem.js
15+
- direct createPromotionStateSnapshot(...) call
16+
-> src/shared/state/getState.js::getState(...)
17+
18+
Obsolete in-scope variant removed/redirection:
19+
- Removed direct promotion snapshot-construction bypass in createWorldGameStateSystem getState().
20+
- Behavior/API preserved by using same underlying snapshot contract through shared getState selector.
21+
22+
No API removals:
23+
- Existing shared exports remain valid.
24+
- New selector reader surface is additive and non-breaking.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
PR_03_03_SHARED_SELECTORS_CONTRACTS - selector usage scan
2+
3+
Scope scanned:
4+
- src/shared/state/
5+
- public selector/read boundary surfaces in moved scope
6+
- in-scope consumer: src/advanced/state/createWorldGameStateSystem.js
7+
8+
Focused selectors:
9+
- getState
10+
- Canonical shared selector: src/shared/state/getState.js
11+
- Consumer(s) in scope:
12+
- src/advanced/promotion/createPromotionGate.js (already canonical via shared getState)
13+
- src/advanced/state/createWorldGameStateSystem.js (standardized in this PR)
14+
- getSimulationState
15+
- No pre-existing selector variant in scanned scope
16+
- getReplayState
17+
- No pre-existing selector variant in scanned scope
18+
- getEditorState
19+
- No pre-existing selector variant in scanned scope
20+
21+
Contract boundary findings:
22+
- Duplicate/bypass contract call in scope before change:
23+
- src/advanced/state/createWorldGameStateSystem.js used createPromotionStateSnapshot directly
24+
- Standardized contract usage after change:
25+
- src/advanced/state/createWorldGameStateSystem.js now routes through shared selector boundary src/shared/state/getState.js
26+
27+
New standardized selector/read surface added:
28+
- src/shared/state/publicSelectors.js
29+
- getState
30+
- getSimulationState
31+
- getReplayState
32+
- getEditorState
33+
34+
Out-of-scope selector/getState implementations (unchanged):
35+
- runtime/tool-specific local getState functions outside target scope

docs/dev/reports/validation_checklist.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[ ] string_usage_scan.txt generated
2-
[ ] extraction_map.txt generated
3-
[ ] string helpers consolidated to src/shared/utils
1+
[ ] selector_usage_scan.txt generated
2+
[ ] contract_map.txt generated
3+
[ ] selectors/contracts standardized to shared surfaces
44
[ ] no API changes
55
[ ] no behavior changes
66
[ ] impacted imports resolve
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# PR_03_03_SHARED_SELECTORS_CONTRACTS
2+
3+
## Purpose
4+
Standardize shared selector usage and confirm state contract boundaries without changing behavior.
5+
6+
## Scope
7+
- selector and contract consolidation only
8+
- no logic changes
9+
- no behavior changes
10+
- no non-selector helper extraction
11+
12+
## Target Areas
13+
- src/shared/state/
14+
- public selector/read boundary surfaces
15+
16+
## Required Work
17+
1. Inventory active selector variants and contract surfaces duplicated or inconsistently named in this PR scope.
18+
2. Build an exact standardization map for selectors and contract readers.
19+
3. Consolidate consumers in scope onto the standardized shared selector/contract surfaces.
20+
4. Remove only obsolete duplicate selector/contract implementations made unnecessary by this consolidation.
21+
5. Keep changes surgical and execution-backed.
22+
23+
## Candidate Focus
24+
- getState
25+
- getSimulationState
26+
- getReplayState
27+
- getEditorState
28+
- public selector/read boundaries
29+
30+
## Constraints
31+
- no broad repo scan beyond selector/contract consumers needed for this PR
32+
- no number/string/id helper work in this PR
33+
- no engine logic refactors
34+
- no sample/game/tool behavior changes
35+
- preserve public contracts
36+
37+
## Deliverables
38+
- docs/dev/reports/selector_usage_scan.txt
39+
- docs/dev/reports/contract_map.txt
40+
- docs/dev/reports/validation_checklist.txt
41+
42+
## Validation
43+
- shared selector/contract surfaces are canonical for this PR scope
44+
- consumers in scope resolve to standardized shared selector/contract surfaces
45+
- no duplicate selector variants remain in moved scope
46+
- impacted tests/smoke pass
47+
48+
## Output
49+
<project folder>/tmp/PR_03_03_SHARED_SELECTORS_CONTRACTS.zip

src/advanced/state/createWorldGameStateSystem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
createTransitionAppliedEvent,
1919
createTransitionRejectedEvent
2020
} from './events.js';
21-
import { createPromotionStateSnapshot } from '../../shared/state/createPromotionStateSnapshot.js';
21+
import { getState as getPromotionPublicState } from '../../shared/state/getState.js';
2222
import { asFiniteNumber, asPositiveInteger } from '../../shared/math/numberNormalization.js';
2323
import { isPlainObject } from '../../shared/utils/objectUtils.js';
2424
import {
@@ -232,7 +232,7 @@ function createInlinePromotionGate({
232232
evaluate,
233233
getMetrics,
234234
getState() {
235-
return createPromotionStateSnapshot({
235+
return getPromotionPublicState({
236236
promoted,
237237
stableFrames,
238238
stabilityWindowFrames: windowFrames,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function asObject(value) {
2+
return value && typeof value === 'object' ? value : null;
3+
}
4+
5+
function getState(source) {
6+
if (!source || typeof source.getState !== 'function') return null;
7+
return source.getState();
8+
}
9+
10+
function getSimulationState(source) {
11+
const state = asObject(getState(source));
12+
if (!state) return null;
13+
return asObject(state.simulationState) || asObject(state.simulation);
14+
}
15+
16+
function getReplayState(source) {
17+
const state = asObject(getState(source));
18+
if (!state) return null;
19+
return asObject(state.replayState) || asObject(state.replay);
20+
}
21+
22+
function getEditorState(source) {
23+
const state = asObject(getState(source));
24+
if (!state) return null;
25+
return asObject(state.editorState) || asObject(state.editor);
26+
}
27+
28+
export {
29+
getState,
30+
getSimulationState,
31+
getReplayState,
32+
getEditorState
33+
};

0 commit comments

Comments
 (0)