AGENTS.md instructions for /home/clive/PycharmProjects/Orac
Follow standard Python conventions unless otherwise specified.
Module structure:
A module docstring MUST appear at the very top of the file describing its purpose.
Immediately following the module docstring, include comment-based metadata headers:
Author: Clive Bostock
Date:
Description:
Command-line scripts:
Use argparse for command-line parameters.
Code quality:
Include Google-style docstrings for all new public modules, classes, and functions.
When modifying existing public code, add missing docstrings where it is reasonable to do so within the scope of the change.
Use type hints where appropriate.
Favour readable, production-usable code with sensible error handling.
General:
Prefer clarity over cleverness.
Avoid unnecessary complexity.
For any created programs / executable scripts include provenance.
If pre-existing code does not already have these, ask for confirmation before adding.
Template:
Implement selectable TTS voice support for Orac user preferences.
Scope:
This change should add database, APEX UI, and runtime support for selecting a TTS voice per user.
The selected voice should come from the user's preferences. Runtime voice selection must only fall back to the existing orac.ini TTS voice setting if the user's preferred voice is missing, disabled, unavailable, or invalid.
Do not implement vocal model switching or a voice-command plugin in this change.
Part 1: Database table
Add a new table:
orac.tts_voices
Purpose:
orac.tts_voices is a startup-refreshed runtime catalogue of available TTS voices. It is populated from available TTS providers such as Piper and Kokoro. It is not master/reference data and must not be used as the target of hard foreign keys from user preferences.
Each row represents one selectable voice from one provider.
I’ll inspect the project guardrails and the existing DB/APEX/runtime preference paths first, then make the smallest changes that fit the current conventions.
Assistant
I found the preference system and APEX export under resources/db/schema/orac_core/orac_apps/f1042.sql, plus existing voice runtime code and tests. Next I’m reading the database, PL/SQL, Python, web/APEX-adjacent, security, and project guardrails so the object placement and naming stay consistent.
Assistant
The preference row tts_voice already exists, so I’ll keep that field and change it from the old static values to a SQL-backed voice-key LOV. The APEX page is metadata-driven already, so the UI change appears to be mostly preference-definition data plus access to a new catalogue view.
Assistant
I’m going to add the catalogue as a core-owned table exposed through an API view and least-privilege grants, then wire startup refresh and per-request selection through the existing context/preference path. For the worker, the important change is making the engine selectable per queued utterance instead of being fixed once at startup.
Assistant
The core code path is now in place: startup refreshes the voice catalogue, request metadata resolves the user’s tts_voice soft reference with config/default fallback, and queued TTS chunks carry the selected catalogue row so provider routing can change per request. I’m running targeted checks now and will fix whatever falls out.
Assistant
Targeted TTS tests and the nearby voice-worker tests pass. The guardrail checker itself is blocked by an existing docs/agent-guardrails/Untitled Document drift issue, while its unit tests pass. I’m checking the broader context tests next because the request metadata path now does voice preference resolution.
Assistant
Implemented selectable per-user TTS voice support across DB, APEX preference metadata, startup refresh, and runtime routing.
Key changes:
Added orac_core.tts_voices plus PK/UK/check constraints, JSON validation, comments, API view, grants, and orac / orac_apx_pub synonyms.
Updated tts_voice preference metadata to store a single tts_voice_key soft reference and use a SQL-backed Popup LOV from orac_api.tts_voices_v.
Added startup TTS voice discovery/refresh for Piper filesystem voices and Kokoro /v1/audio/voices.
Added runtime selection order: user preference, configured orac.ini voice, discovered default, then clean failure logging.
Updated TTS worker so selected provider routes per utterance, e.g. kokoro:af_heart uses Kokoro even if global config differs.
Added tests for schema shape, soft-reference behaviour, catalogue loading, fallback, and provider routing.
Verification:
poetry run pytest tests/test_tts_voice_catalog.py passed.
poetry run pytest tests/test_orac_voice.py -k "local_tts_worker or kokoro_tts_engine or piper_engine" passed.
poetry run pytest tests/test_orac_context_history.py -k "preference or llm_registry_sync or request_start" passed.
poetry run pytest tests/test_check_guardrails.py passed.
git diff --check passed.
poetry run python scripts/check_guardrails.py is still blocked by an existing unrelated file: docs/agent-guardrails/Untitled Document.
black is not installed in the Poetry environment, so I could not run formatting through Black.
User
Do I need to redeploy Orac to implement this?
User
status
User
<turn_aborted>
The user interrupted the previous turn on purpose. Any running unified exec processes may still be running in the background. If any tools/commands were aborted, they may have partially executed.
</turn_aborted>
Do not add foreign keys from user preferences to this table.
Use varchar2(n char), not varchar2(n).
Use lowercase SQL reserved words.
Let the existing project guardrails determine object names, index names, constraint names, comments, Liquibase formatting, and migration placement.
Follow the existing project conventions for DDL, comments, install scripts, and migrations.
Part 2: User preference storage
Locate the existing user preference placeholder for selected TTS voice.
Use that existing preference field if it already exists.
The stored value should be:
tts_voice_key
Do not store provider_code and provider_voice_id as two separate preference values unless the existing design already requires that. The selected key should be a single soft-reference value.
Do not add a foreign key to orac.tts_voices.
Part 3: Startup/refreshed catalogue behaviour
Implement or extend the existing startup catalogue-loading pattern if one already exists for Ollama / LM Studio model discovery.
The TTS voice catalogue should be refreshed at Orac startup.
Expected behaviour:
Discover available voices from all enabled/configured TTS providers.
Include Piper voices when Piper is configured/available.
Include Kokoro voices when Kokoro is configured/available.
Insert each discovered voice into orac.tts_voices.
Use provider_code to distinguish providers.
Build tts_voice_key as provider_code || ':' || provider_voice_id.
Mark the configured orac.ini default voice with default_yn = 'Y' where it matches a discovered row.
Set enabled_yn = 'Y' for usable voices.
Log unavailable providers, but do not fail startup unless no usable TTS voice remains available.
If the project already has a safe truncate-and-load pattern for runtime catalogues, follow that pattern.
Part 4: APEX User Preferences UI
Update the APEX User Preferences UI so the user can select a TTS voice from orac.tts_voices.
Use a Popup LOV or Shared LOV according to the existing APEX application conventions.
The LOV should:
Return:
tts_voice_key
Display:
provider_code
display_name
provider_voice_id
locale_code
voice_quality
Suggested LOV query shape:
select
initcap(provider_code) || ' - ' || display_name as d,
tts_voice_key as r,
provider_code,
provider_voice_id,
locale_code,
voice_quality
from
orac.tts_voices
where
enabled_yn = 'Y'
order by
provider_code,
nvl(sort_order, 999999),
display_name
The UI should write the selected tts_voice_key into the existing user preference field.
If the current APEX application uses exported application metadata, update the appropriate APEX export files according to the existing project workflow.
If the current project uses SQL migrations or APEX supporting objects for LOVs/preferences, follow that pattern.
Part 5: Runtime voice selection in voice_ai.py
Update voice_ai.py so TTS voice selection uses user preference first.
Runtime selection order:
Read the current user's preferred TTS voice key from user preferences.
Look up that key in orac.tts_voices.
If the row exists and enabled_yn = 'Y':
use provider_code to select the TTS provider/adapter.
use provider_voice_id, model_path, config_path, and metadata_json as needed by that provider.
If the user preference is null, missing, disabled, unavailable, or invalid:
fall back to the existing orac.ini TTS voice setting.
If the orac.ini voice is also unavailable:
fall back to a discovered default row where default_yn = 'Y'.
If there is still no valid voice:
fail cleanly with a clear log message.
Important runtime behaviour:
Selecting a voice should implicitly select the provider.
For example, selecting kokoro:af_heart should route to Kokoro even if the old orac.ini default was Piper.
Do not assume the configured global tts_engine is the only provider available.
Preserve backwards compatibility with the existing orac.ini behaviour.
Log when a user preference is unavailable and fallback is used.
Do not crash merely because a stored user preference points to a voice that is no longer present in orac.tts_voices.
Part 6: Tests
Add or update tests for:
Creation/migration of orac.tts_voices according to project conventions.
Startup loading of Piper voices, if an existing discovery seam is available.
Startup loading of Kokoro voices, if an existing discovery seam is available.
Runtime selection uses the user's preferred voice when valid.
Runtime selection falls back to orac.ini when the user's preferred voice is unavailable.
Runtime selection falls back cleanly when the preference is null.
Runtime selection routes to the correct provider based on provider_code.
A stored preference value is treated as a soft reference, not a hard database relationship.
Keep the implementation focused. Do not add voice-command switching, persona-level voice defaults, or model-switching behaviour in this change.