6.1 KiB
6.1 KiB
Task 1 — Dynamic Choice Contracts and Stop Policy
Implementation
- Added browser-safe dynamic choice and time-range Zod schemas. Public question parsing is strict and rejects hidden partition fields.
- Added internal-only dynamic choice contracts, persisted/private question schemas, candidate-difference packet schemas, and an explicit public projection helper.
- Added pure deterministic stop policy with the specified precedence and a material-change calculation for candidate range, representative time, and two-point margin changes.
- Added separate
DynamicNextActionandDynamicJourneyProgressschemas, preserving the legacy guided-v1NextActionandJourneyProgressparser path. - Kept the internal contract module dependency-free as resolved by the user. A source-contract test scans components, hooks, client transports, and response schemas to prohibit imports of the private module.
- Dynamic IDs are opaque nonempty server-issued strings, rather than being overconstrained to UUIDs.
Files changed
frontend/src/lib/birth-time-dynamic-choice.tsfrontend/src/lib/birth-time-dynamic-choice-internal.tsfrontend/src/lib/birth-time-dynamic-stop-policy.tsfrontend/src/lib/birth-time-journey-turn-protocol.tsfrontend/src/lib/birth-time-journey-turn.tsfrontend/tests/birth-time-dynamic-choice.test.tsfrontend/tests/birth-time-dynamic-stop-policy.test.ts
RED
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-dynamic-choice.test.ts- Failed as expected before the public contract existed:
ERR_MODULE_NOT_FOUNDforbirth-time-dynamic-choice.ts.
- Failed as expected before the public contract existed:
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-dynamic-stop-policy.test.ts- Failed as expected before the policy existed:
ERR_MODULE_NOT_FOUNDforbirth-time-dynamic-stop-policy.ts.
- Failed as expected before the policy existed:
- After the boundary resolution, the dynamic choice test failed as expected while the obsolete
server-onlymarker remained:ERR_MODULE_NOT_FOUND: Cannot find package 'server-only'. - The opaque-ID regression initially failed because the first implementation required UUIDs.
GREEN
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-dynamic-choice.test.ts tests/birth-time-dynamic-stop-policy.test.ts tests/birth-time-journey-turn.test.ts14passed,0failed.
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-*.test.ts194passed,0failed, duration1449ms.
git diff --check- Passed with no whitespace errors.
Self-review
- Public choices are strict, require 2–4 primary options plus exactly one unknown and one unmatched option, reject duplicate IDs, cap labels at 80 characters, and reject private fields.
- Persisted primary choices require nonempty partitions and finite score maps. Unknown/unmatched choices require both private fields to be
null. - The public projection parses through the public schema, so partition IDs and candidate scores cannot cross the browser boundary.
- Stop ordering is high confidence, effective-answer safety cap, plateau, no information gain, repeated partition, then continue. Non-effective answers retain the prior plateau count.
- Legacy schemas and turn behavior remain unchanged; v2 schemas use distinct dynamic names and are re-exported from the turn module.
- All created/modified source files are within the 250 pure-LOC threshold (largest:
birth-time-journey-turn.ts, 229 lines; new internal contract, 208 lines).
Concerns
- Full
tsc --noEmit --incremental falseremains blocked by an unrelated existing error infrontend/tests/profile-persistence.test.ts:7: the project targets ES2017 while that test uses an ES2018 regular-expression flag. None of the Task 1 files produced a TypeScript error. - The supplied no-excuse checker could not run because it is outside the frontend dependency tree and cannot resolve its own
typescriptpackage. The focused runtime suite, full birth-time suite, diff check, and manual forbidden-pattern scan completed successfully.
Review fixes
DynamicStopInput.resultis now nullable, so a dynamic flow can finish before its first score. It also carries the explicitforcedReasonunion:user_finished,generation_unavailable, ornull.- Forced terminal reasons now win over every score-derived condition. A null result preserves the current plateau count instead of attempting score comparison.
- Added and re-exported
dynamicJourneyTurnStateSchema/DynamicJourneyTurnState. The schema is strict and explicitly requiresjourneyProtocol: "dynamic-choice-v2", a nonnegative turn version, a dynamic action, dynamic progress, and the existing permissions shape. The legacyjourneyTurnStateSchemais unchanged. - Added regressions for both forced terminal reasons, their high-confidence precedence, the dynamic discriminator, and rejection of a valid legacy action under the v2 schema.
Review RED
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-dynamic-choice.test.ts tests/birth-time-dynamic-stop-policy.test.ts
- Failed before implementation because
dynamicJourneyTurnStateSchemawas not exported. - Existing stop policy threw on
result: nulland returnedhigh_confidenceinstead of the forceduser_finishedreason.
Review GREEN
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-dynamic-choice.test.ts tests/birth-time-dynamic-stop-policy.test.ts tests/birth-time-journey-turn.test.ts16passed,0failed.
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --test tests/birth-time-*.test.ts196passed,0failed, duration1472ms.
/Users/jesse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node ./node_modules/typescript/bin/tsc --noEmit --incremental false- Still reports only the existing
tests/profile-persistence.test.ts:7ES2018-regexp/ES2017-target incompatibility; no Task 1 diagnostic was emitted.
- Still reports only the existing