AI-powered iRacing crew chat.
  • Python 65.3%
  • Go 25.9%
  • Nix 3.4%
  • JavaScript 2.4%
  • HTML 2.1%
  • Other 0.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
adam bdcc80ad47
All checks were successful
Test and build / build (push) Successful in 3m36s
Publish release / release (push) Successful in 3m57s
Logging service / logging (push) Successful in 6m27s
Merge pull request 'Publish Crewbot v0.3.0b6 with headset and wheel fixes' (#13) from codex/publish-v0.3.0b6 into main
2026-12-02 14:04:44 -05:00
.forgejo/workflows Authenticate immutable release tag verification 2026-11-29 14:51:31 -05:00
ci Request publication of Crewbot v0.3.0b6 2026-12-02 14:04:28 -05:00
crewbot Follow audio device changes and discard interrupted speech 2026-12-02 12:40:11 -05:00
docs Prepare Crewbot 0.3.0b6 with headset and wheel fixes 2026-12-02 13:54:59 -05:00
examples Add offline proximity spotter with priority audio and replay coverage 2026-11-29 14:45:22 -05:00
logging Track unsupported driver requests for feature discovery 2026-11-30 13:45:07 -05:00
nix Add standalone local-only logger mode 2026-11-28 18:44:10 -05:00
scripts Add offline proximity spotter with priority audio and replay coverage 2026-11-29 14:45:22 -05:00
tests Follow audio device changes and discard interrupted speech 2026-12-02 12:40:11 -05:00
.gitattributes Add portable multi-user logging service 2026-11-28 02:25:55 -05:00
.gitignore Implement Crewbot voice race engineer 2026-11-26 18:20:18 -05:00
AGENTS.md Document Forgejo pull request workflow 2026-11-27 23:12:14 -05:00
flake.lock Add portable multi-user logging service 2026-11-28 02:25:55 -05:00
flake.nix Add standalone local-only logger mode 2026-11-28 18:44:10 -05:00
pyproject.toml Prepare Crewbot 0.3.0b6 with headset and wheel fixes 2026-12-02 13:54:59 -05:00
README.md Prepare Crewbot 0.3.0b6 with headset and wheel fixes 2026-12-02 13:54:59 -05:00

Crewbot

A personal Windows companion that connects your headset and iRacing telemetry to an OpenAI Realtime voice engineer. It answers race questions and applies explicitly requested next-stop fuel and tire selections through the iRacing SDK.

Crewbot also includes an offline proximity spotter, disabled by default. See Local spotter and the validation report.

Automated tests and the Linux desktop demo have been exercised; a paid live voice session, Windows audio/wheel input, and real iRacing commands still require a Windows practice-session acceptance test.

Install and run on your racing PC

Install 64-bit Python 3.12 and clone the repository. From the repository root, run these commands in PowerShell:

py -3.12 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e .
.\.venv\Scripts\python.exe -m crewbot --demo

This installs the repository's code and resolves its dependencies from PyPI. For a packaged version, use the Windows beta install commands or choose a Forgejo release. Forgejo's package index does not mirror PyPI; install third-party dependencies from PyPI separately rather than mixing indexes with --extra-index-url.

The optional Windows app and WSL local logger runs at http://localhost:8765 without authentication. It displays track/car names and recording times and provides uniquely named log downloads. Telemetry logs, recordings, and replay exports preserve CarLeftRight; see the capture guide. The logging service guide covers authenticated hosting.

Demo mode generates synthetic telemetry and simulates pit changes. It cannot control iRacing. The desktop and telemetry work without an API key; starting voice requires an OpenAI API key with access to the selected model.

For live iRacing, start a practice session and run:

.\.venv\Scripts\python.exe -m crewbot
  1. Select microphone and headset output. Enter your OpenAI API key. Save key is optional and stores it in Windows Credential Manager; otherwise it stays in memory. Settings never contain the key.
  2. Select the voice model and your default fuel units. The full model is the default; mini is available for cost/quality comparison.
  3. Choose a global push-to-talk key (default F9), or a zero-based wheel device/button index. Setting Wheel device to Disabled turns off the engineer's wheel binding. The onscreen Hold to talk button is always available when voice is connected. A wheel that exposes keyboard mappings can also use the keyboard binding.
  4. Press Start engineer, wait for the connected message, then hold push-to-talk while speaking. Release it for a reply. Press again to interrupt speech and abandon an unfinished request.
  5. Press Stop engineer to stop voice and discard pending requests. A failed connection must be restarted explicitly; old actions are not retried.

On Windows, Crewbot reads wheel buttons with shared background access so iRacing can control force feedback. If you saved wheel bindings in an earlier build, check both push-to-talk and spotter mute in practice. Windows may number your devices differently. To isolate a force feedback interruption, set Wheel device to Disabled and Spotter settings → Mute wheel device to -1, then use F9 with iRacing focused.

Choose System default to follow Windows when it switches to or from a VR headset. A named microphone or output stays selected while unplugged and becomes available again when reconnected. If a device change interrupts push-to-talk, Crewbot discards the recording. Hold push-to-talk again to repeat the request.

Requests must be between 0.1 and 30 seconds. Overlong recordings are discarded rather than executing a truncated command. Configure proximity speech as described below. Avoid running two automatic pit planners that continually overwrite each other.

Example requests:

  • “How much fuel do I have?”
  • “How many laps can I do on this fuel?”
  • “What's the gap behind?”
  • “Add 20 liters at the next stop, no tires.”
  • “Take left-side tires and leave the fuel alone.”
  • “Should we change tires?” — advice only, not an instruction to apply a change.

There is no extra confirmation for a clear change request. The voice model interprets intent under a constrained tool prompt; this still needs real speech acceptance testing. Ambiguous amounts or questions should lead to clarification, not a write.

Local spotter

The local spotter announces left/right overlap, persistent traffic, three-wide positions, two-to-one reductions, and clearance. It uses iRacing's CarLeftRight, independently of OpenAI, the microphone, and Start engineer. “Clear” reports the end of alongside overlap; it does not establish a safe lane change or rejoin. Flag, incident, approaching-car, and pit-exit warnings are outside this feature's scope.

To configure the spotter:

  1. Open Spotter settings… and choose Prepare voice. This explicit setup generates all 15 phrases offline using one installed English Windows desktop voice. It saves a versioned cache under %LOCALAPPDATA%\Crewbot\spotter. Setup may take a few seconds; the transcript reports completion or failure.
  2. Use Preview while spotting is disabled or temporarily muted. Select the headset in the main window, then Apply / retry output to use that device.
  3. Enable local spotting and apply. Status distinguishes disabled, waiting, active, muted, and unavailable, with a reason when data or output is unavailable.
  4. Set independent volume and optional reminders (default: every three seconds, adjustable from one to ten). Disabling reminders retains overlap/clear calls. Enable, volume, reminders, and optional mute bindings persist across restarts.
  5. Use Mute spotter or a separate keyboard/wheel binding for temporary mute. Bindings that conflict with engineer PTT are rejected. Stop engineer leaves spotting running. If audio is still unavailable after reconnecting a device, Apply / retry output refreshes the device list and reopens active audio streams. This also works when only the engineer is running.

Speech is preloaded and validated before active status; missing or corrupt clips prevent activation. Nothing is synthesized or downloaded in response to traffic. On Linux, demo and replay can prepare a local voice with espeak-ng installed; the repository's Nix development environment includes a file-output build of it. The equivalent setup/check commands are:

.\.venv\Scripts\python.exe -m crewbot.spotter_voice --prepare
.\.venv\Scripts\python.exe -m crewbot.spotter_voice --check
.\.venv\Scripts\python.exe -m crewbot --replay examples\spotter.jsonl

Demo mode also cycles through reproducible traffic. App replay is read-only; iRacing's own simulator replay suppresses calls. Pit road, leaving the car, inactive/missing proximity, session changes, rewind, and frozen source ticks discard obsolete speech without inventing clearance. Clearance requires 200 ms of fresh stable frames; source freshness expires at 250 ms. Spotter calls take priority over engineer speech while PTT capture continues. Routine engineer announcements wait for traffic to clear and are rechecked before speaking.

Native spotter configuration still needs live Windows verification. There is no verified recommendation yet for disabling native speech or selecting text-only mode while retaining flag/incident/pit warnings and valid CarLeftRight. For normal driving, leave Crewbot's spotter disabled and retain your current spotter until the practice-session checklist is completed. During validation, compare one audible proximity source at a time and record the exact native settings; the tests do not establish that either native setting works as intended.

Capture independent timing diagnostics alongside telemetry, using new filenames:

$spotterRun = [guid]::NewGuid().ToString('N')
.\.venv\Scripts\python.exe -m crewbot --record "traffic-$spotterRun.jsonl" --spotter-log "spotter-$spotterRun.jsonl"

The diagnostic file records source progress, transitions, phrase intents, playback start/completion/cancellation, and suppression reasons. Playback records include buffer size, selected device index, and estimated callback-to-DAC latency. They contain no microphone audio or transcripts. Enable diagnostic uploads separately in Logging settings to send the same spotter event categories to the logger.

Proactive announcements

While the engineer is connected, Crewbot automatically announces:

  • Estimated fuel range at 3, 2, and 1 lap remaining, after enough valid laps establish consumption. These estimates include no safety reserve.
  • Session time remaining at 10, 5, 2, and 1 minute, including practice and qualifying. Missed milestones are not replayed when you connect late.
  • Opening or closing race classification gaps ahead/behind: a 1-second change, sustained for 5 seconds, while the same rival is within 10 seconds. Each side has a 60-second cooldown. These are not proximity/spotter calls.

Announcements wait for your conversation and playback to finish, plus one quiet second. Push-to-talk interrupts them. Fuel has priority over time, then gaps, with at least 15 seconds between announcements. Old time/gap events expire after 15 seconds; fuel warnings are rechecked before speaking. Nothing is announced with stale telemetry, outside the car, on pit road, or during simulator replay. Announcements cannot execute tools or change your pit selections.

Open Announcement settings… to toggle categories, edit milestone lists, change gap sensitivity/range/cooldown, or restore defaults. The dialog stays available during voice sessions. Use Apply to save edits. Empty milestone lists disable those milestones. Limits: up to 20 milestones; fuel 0–100 laps and time 0–1440 minutes (both strictly positive); gap change 0.1–60 seconds, range 1–120 seconds, and cooldown 15–600 seconds.

You can also hold push-to-talk and say:

  • “Don't warn me when ten minutes are remaining.”
  • “Warn me at four laps of fuel.”
  • “Turn off gap announcements.”
  • “Only report gap changes of two seconds.”
  • “Set the gap announcement cooldown to ninety seconds.”
  • “What are my announcement settings?”
  • “Reset announcement settings.”

Spoken changes save across app restarts, update the UI, and receive a spoken confirmation. Unrelated preferences stay unchanged. Ambiguous requests should produce clarification. If settings change while a spoken edit is being processed, Crewbot rejects the stale edit rather than overwriting the newer settings. Settings can be changed without live telemetry.

Triggers are calculated locally; only a due announcement requests speech from the selected Realtime model. These responses incur API usage and appear in the transcript/token logs. No microphone recording is needed to trigger them.

For an approximately 140-second reproducible scenario, run python -m crewbot --replay examples/announcements.jsonl from a source checkout and start the engineer promptly. It exercises fuel warnings, a time milestone, and both gap directions; conversation activity may delay or expire events. This explicit app replay is read-only and supports announcements; old recordings without rival identifiers still support fuel/time but suppress gap trends. Automated tests use a fake clock and require no API key. Live speech and Windows audio timing still require acceptance testing.

Behavior and limits

  • Telemetry is sampled locally approximately 20 times/second. A compact current snapshot replaces voice instructions once/second; this does not trigger a model response every second. Separate remote logging is disabled by default; uploading normalized telemetry requires its own opt-in.
  • Only microphone audio captured while push-to-talk is held is sent. The active voice session receives compact telemetry, tool results, and conversation context. Microphone and engineer audio are not saved to disk; explicitly prepared spotter clips are cached locally. Transcription is enabled for the local transcript, which may incur additional API charges.
  • The fuel estimator discards the first partial lap and requires two measured full valid laps. It averages up to five recent valid laps, excluding detected incidents, off-track samples, pit laps, refueling, skipped laps, and simulator replay. Session/car changes, time rewinds, and disconnects reset history. Range has no safety reserve and is not a guaranteed finish prediction.
  • Gaps are race classification gaps, not physical proximity calls. Practice/qualifying and unavailable or lapped-car comparisons return unknown. No tire-wear, brake-bias, driving-control, or arbitrary setup tools are exposed.
  • Pit fuel means amount to add at the next stop, not desired total fuel in the tank. SDK fuel parameters are whole liters: fractional liters and gallon conversions round up, and the readback reports the effective quantity. Zero clears refueling. Requests exceeding the session's tank capacity are rejected, not silently clamped.
  • Tire updates preserve unspecified selections. The SDK requires clearing the tire set and reselecting the desired tires. These multiple broadcasts are not atomic; if a send fails partway through, the result is explicitly unverified and never retried.
  • The SDK does not acknowledge pit changes. Crewbot checks newer telemetry for up to roughly 0.6 seconds and reports verified or sent but unverified. Unknown readback is not success. Missing/stale telemetry, replay mode, being out of the car, expired requests, and interrupted turns block writes.
  • Driver turns authorize tools for at most 30 seconds. A delayed response cannot borrow a later turn's permission. Function-call IDs are deduplicated. Completed response IDs are also deduplicated.
  • To bound cost/history growth, conversation history resets at the next push-to-talk boundary after more than 40 conversation items. Current telemetry remains available; long-term conversational memory is not implemented. The UI logs API usage events and cumulative input/output token counts, not an exact dollar invoice.
  • No hosting service is required for the engineer. The client talks directly to OpenAI over TLS using its in-memory key. All iRacing commands execute locally. An optional independent logging service can collect diagnostics and normalized telemetry.

Record and replay telemetry

Record a new local JSONL file (existing files will not be overwritten):

.\.venv\Scripts\python.exe -m crewbot --record practice.jsonl

Replay it without iRacing:

.\.venv\Scripts\python.exe -m crewbot --replay practice.jsonl

Each line contains elapsed seconds and a normalized snapshot matching crewbot.core.Snapshot. Playback is paced by elapsed, is always read-only, and becomes stale after the recording ends. examples/session.jsonl is a short synthetic fixture, not a real racing recording. Demo mode accelerates laps to 20 seconds so fuel estimation can be explored quickly.

Transcripts and action logs remain in the window unless you explicitly use Export transcript and action log. The window retains the most recent 2,000 text blocks. Telemetry recording is separate and opt-in.

Optional logging

To run just the logger in WSL without authentication, use nix run .#logger-local from the repository root, then open http://localhost:8765. See the standalone logger instructions for an archive-based startup command that also works without Git installed, startup options, example uploads, and the NixOS service configuration. In Crewbot, open Logging settings…, check Local logger (no authentication), set Service origin to http://localhost:8765, and enable the desired upload categories. No upload token or OS keyring is used in this mode.

The repository includes a Go logging web service, packaged as a locked Nix flake and reusable NixOS module for x86 and ARM64 hosts. It uses existing OIDC login, upload-only device tokens, tenant-isolated search, expiring support grants, 30-day searchable logs, and one-year compressed local archives.

For authenticated logging, leave Local logger unchecked in Logging settings… and enter your service's HTTPS origin and an upload token created on its website. Enable diagnostic events and full telemetry separately. Tokens use the OS keyring; uploads omit conversation transcripts, microphone audio, and OpenAI credentials. Background uploads tolerate outages with a bounded local spool; the window shows backlog, dropped records, and last upload time. The engineer works independently when logging is unavailable.

See the Windows beta and NixOS-WSL installation guide, logging service deployment and API instructions, and validation evidence. The flake supplies the service rather than replacing your WSL, Pi 5, or EC2 host configuration.

Find requested features

When the voice engineer identifies an action it cannot perform, it adds an [unsupported_request] entry to the session log with a category and a short feature label. For example, “put 22 PSI in the left front” becomes pit_service / set_tire_pressure. Use Export transcript and action log… to keep the entry with the original exchange. For sessions on older versions, the exchange may still be in the open window or a transcript you exported.

To track demand across runs, open Logging settings… in the updated app. Upload diagnostic event categories sends the category for each occurrence. Upload unsupported request labels includes the model-generated feature label and can be enabled on its own. Both options default to off. On the logging website, set Start to 30d and select Rank unsupported requests. Each row shows the number of requests and the number of runs they came from. For the search query, see the logging guide.

Tests and development

Core, adapter, audio-buffer, and scripted voice-protocol tests need only Python's standard library:

.\.venv\Scripts\python.exe -m unittest discover -s tests -v

After installing the application dependencies, the desktop smoke test can run without a display:

QT_QPA_PLATFORM=offscreen XDG_CONFIG_HOME=/tmp/crewbot-test-config .venv/bin/python tests/gui_smoke.py

On Linux, the demo UI works; microphone use also requires the OS PortAudio library. The iRacing bridge deliberately refuses live mode on Linux. Linux cannot validate Windows Credential Manager, wheel/background keyboard behavior, or the simulator SDK.

Architecture:

  • core.py: normalized race state, fuel calculations, freshness, turn authorization, validated pit execution/readback.
  • bridges.py: live Windows SDK, synthetic simulator, and JSONL playback.
  • realtime.py / tools.py: Realtime protocol, tools, context updates, interruption, and conversation bounds.
  • audio.py / inputs.py: gated PCM capture, playback, keyboard and wheel buttons.
  • spotter.py: pure traffic policy, phrase vocabulary, and validated spotter preferences.
  • spotter_runtime.py / spotter_voice.py: independent freshness watchdog, playback acknowledgements, bounded diagnostics, and offline voice preparation/cache validation.
  • app.py: desktop settings, credential storage, telemetry polling/recording, and logs.
  • logging_client.py: opt-in background uploads and bounded durable spooling; logging/ contains the independent Go web service.

Windows acceptance checklist

  1. Launch demo; verify microphone/output selection, F9, wheel button, and onscreen push-to-talk. Confirm spoken replies and transcript/action entries.
  2. In practice, confirm fuel, position, session changes, and telemetry disconnection against iRacing. Drive enough full clean laps to establish a fuel estimate. With force feedback active, check that it feels the same after starting and stopping the engineer and while using wheel buttons for PTT and spotter mute. Return focus to iRacing after interacting with Crewbot.
  3. Inspect the pit black box while requesting “add 20 liters, no tires.” Confirm both settings and the spoken verified readback. Test gallons, zero fuel, and partial tire changes without altering unrelated settings.
  4. Ask “should we take tires?” and an ambiguous request such as “put in twenty.” Confirm no unauthorized change; specify a unit/default clearly when testing ambiguity.
  5. Interrupt a reply, disconnect the network, leave the car, and restart a session. Confirm older requests never execute after reconnecting. Review unverified outcomes against the black box.
  6. In practice, enable announcements and verify fuel/time milestones and opening/closing gaps. Hold push-to-talk during an announcement; confirm immediate interruption and no pit-setting changes. Ask to remove the ten-minute warning, check the settings dialog, restart the app, and confirm the change persists. Test restoring defaults.
  7. Review API usage for a representative hour before relying on a monthly cost estimate. Do not interpret mocked protocol tests as proof of live model intent recognition.

References: OpenAI Realtime conversations, Realtime billing, pyirsdk, iRacing pit commands.

CI and releases

Forgejo Actions runs .forgejo/workflows/ci.yml on every branch push, pull request, and manual dispatch. It uses the kaiba-aws-x86_64-small NixOS runner label from kaiba-infra. The runner controller must admit this repository as a consumer; enabling Actions alone does not provision a runner for it.

Each build runs the automated test suite, builds a wheel, validates its metadata and console entrypoint, and smoke-tests the installed wheel in the offscreen desktop demo. Successful builds retain the wheel as a workflow artifact for 30 days. This Linux lane does not replace the Windows acceptance tests above.

CI uses the pinned environment in ci/shell.nix; no OpenAI key or iRacing account is needed. Package publishing requires a repository Actions secret named PACKAGE_PUBLISH_TOKEN: a personal access token belonging to the package owner (adam for this repository), with write:package scope. Create it under the owner's Settings → Applications, then save it under the repository's Settings → Actions → Secrets. Do not put it in source files or commands. Forgejo 17.0.2's generated job token does not grant package-owner write access; the workflow checks that the publishing secret exists before building. The separate Forgejo Release step still uses the generated job token with repository release-write permission under the server's policy.

The runner admission policy accepts protected-main workflows, not tag-triggered workflows. Releases therefore run through .forgejo/workflows/release.yml on protected main, using ci/release.json to name the existing tag and exact commit. The workflow verifies the remote tag matches that commit, checks out that commit, and builds and tests the tagged source before publication.

To publish a release:

  1. Update version in pyproject.toml, commit and push it, and wait for CI.
  2. Tag that tested commit and push the tag (for example git tag -a v0.3.0b1 -m "Crewbot 0.3.0b1" followed by git push origin v0.3.0b1).
  3. Update ci/release.json with the tag and full tagged commit SHA, then commit and push that request to main. Changing the request starts the release workflow. A manual dispatch on main can also run the current request.

Never move a published tag. The release source commit must contain the build and publication scripts used by the workflow.

After all checks pass, CI publishes the wheel to the owner's Forgejo Python registry, downloads it through pip, verifies the bytes, and smoke-tests the registry-installed app. It then creates a Forgejo release named for the tag (for example Crewbot v0.3.0b1) and attaches the matching wheel directly to it. Release tags use the v prefix and must match the package version exactly; mismatches and non-version tags fail validation rather than publishing mislabeled wheels. PEP 440 prerelease tags such as v0.3.0b1 are also accepted (with aN, bN, or rcN suffixes) and automatically marked Pre-Release in Forgejo. Install a beta by its exact version; ordinary upgrades continue to prefer stable releases. Existing packages and releases are not overwritten automatically. This publishes to the Forgejo Python registry and Forgejo Releases, not pypi.org. Pushing a tag alone does not start publication; the protected-main release request is required.

Run the same build checks locally with Nix:

nix-shell ci/shell.nix --run 'bash ci/check.sh'
RELEASE_TAG=v0.3.0b1 nix-shell ci/shell.nix --run 'bash ci/check.sh'