Package entry point — enables ``python -m oc_chat``.
Purpose
-------
Pre-scans ``sys.argv`` for environment-affecting flags
(``--no-color``, ``--workdir``) *before* importing :mod:`oc_chat.main`.
This is necessary because :mod:`oc_chat.core.config` reads ``NO_COLOR`` at
import time and any module using ``from … import STYLE_DIM`` would
otherwise bind to the original ANSI strings before argparse runs; likewise
the sandbox-root walk-up, ``.oc_chat/`` state anchor, and prompt-layer
anchors all derive from ``cwd`` — the ``--workdir`` chdir must precede
every one of them.
Also forces stdout/stderr to UTF-8 on Windows so glyphs like ``→``
and ``⏳`` don't crash the legacy ``cp1252`` codepage.
Responsibilities
----------------
- :func:`_preparse_env_flags` — translate
environment-affecting CLI flags into env vars before any imports.
- :func:`_force_utf8_stdio` — best-effort UTF-8 reconfiguration on
Windows; no-op on platforms whose streams already use UTF-8.
- :func:`_apply_workdir` — parse ``--workdir PATH`` (or ``--workdir=PATH``)
from ``argv``, resolve, validate (exit 2 on nonexistent dir), and
``os.chdir``; called before the ``oc_chat.main`` import so every
anchor resolves from the requested directory.
- Import and run :func:`oc_chat.main.main` after the pre-flight is
done.
Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
L2 — lifecycle events
L3 — semantic details
L4 — deep tracing
Contracts
---------
- Pre-flight functions run *before* any other ``oc_chat`` import to
guarantee correct environment-variable and working-directory timing.
- ``--workdir`` fail-closed: a nonexistent path exits 2 immediately;
the session never falls through to a wrong anchor.
- ``reconfigure`` failures are silently tolerated — falling back to
the platform default is preferable to crashing on a stream that
refuses reconfiguration.
- Standalone-only: importing this module via something other than
``python -m oc_chat`` still runs the pre-flight side effects.
Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)
- oc_chat.main (oc_chat engine module — main)