freerange: assert user-facing option ranges - #2187
Draft
u9g wants to merge 3 commits into
Draft
Conversation
Add @chenglou/freerange and encode the ranges of user-supplied numeric options as leading `console.assert` contracts. Contracts must be per-file functions with literal bounds: freerange does not follow imported bodies, and a leading assert may only compare a parameter to a fixed number. Drop `baseUrl` (deprecated in the TS 6 that freerange bundles) and make `paths` relative, which resolves identically.
|
Contracts propagate within a file, and the call sites are constructors and methods that freerange does not analyze wherever the contract lives, so one module can hold them all and share the domain helpers across providers. Add `pnpm fr` / `pnpm fr:audit`.
Three ranges had two names each: 0..1 (checkedProbability, checkedEotThreshold), >= 0 (checkedDuration, checkedWeight) and 0.5..0.9 (checkedTurnStartThreshold, checkedFluxEotThreshold). Naming each contract after its bounds makes a duplicate impossible to add without noticing; each one lists the options that carry it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds @chenglou/freerange and encodes the ranges of user-supplied numeric options as leading
console.assertcontracts, so out-of-range values are caught at compile time (pnpm fr) and reported at runtime.All contracts live in
agents/src/option_ranges.ts, one function per distinct range, named after its bounds and documenting which options carry it. Covered so far:inference/{vad,stt,llm}.ts,inference/interruption,inference/eot,voice/agent_session.ts,voice/turn_config/utils.ts,voice/background_audio.ts,worker.ts.pnpm frreports 0 findings;pnpm fr:auditprints requirements likerequires: modelOptions.max_delay >= 0.7.Two freerange constraints shape the file: requirements propagate only within a file, so the aggregators sit next to the helpers they call (call sites are constructors and methods, which freerange does not analyze wherever the contract lives), and a leading assert may only compare a parameter to a fixed number, so bounds are literals rather than parameters.
tsconfig.jsondrops the deprecatedbaseUrl(the TS 6 freerange bundles errors on it) and makespathsrelative, which resolves identically.Draft:
inference/tts.ts,transcription/synchronizer.ts,ipc/supervised_proc.tsand the plugins with documented ranges are still to come.