7d60a1af85
- Updated documentation to reflect product name change from 'pi' to 'omp' throughout guides and API references. - Restructured extension and hook documentation to clarify discovery mechanisms, loading behavior, and configuration across multiple config systems (.omp, .pi, .claude, .codex). - Updated SDK API documentation with new method signatures: discoverHooks() -> discoverExtensions(), SessionManager methods now async, settings format changed to YAML. - Expanded session architecture documentation with new entry types (TtsrInjectionEntry, SessionInitEntry), updated field names (fromHook -> fromExtension), and clarified session file format versioning. - Simplified session-tree-plan.md from detailed implementation checklist to architecture summary, removing completed tasks and rollout details.
4.2 KiB
4.2 KiB
Python REPL (Jupyter Kernel Gateway)
Requirements
- Python 3 available on PATH (or via an active virtualenv)
jupyter-kernel-gateway(kernel_gatewaymodule) andipykernelinstalled in the selected Python environment
Install:
python -m pip install jupyter_kernel_gateway ipykernel
How It Works
The Python tool uses a Jupyter Kernel Gateway and talks to it over REST and WebSocket APIs. By default it uses a shared local gateway so multiple pi instances reuse the same gateway process.
Shared-gateway startup flow:
- Filter the environment and resolve the Python runtime (including venv detection)
- Acquire the shared gateway (reuse a healthy gateway or spawn
python -m kernel_gatewayon 127.0.0.1:PORT) - Wait for gateway readiness (
GET /api/kernelspecs) - Create a kernel (
POST /api/kernels) - Connect WebSocket for execution messages
- Initialize kernel environment, run prelude helpers, and load extension modules
External Gateway Support
Instead of spawning a local gateway, you can connect to an already-running Jupyter Kernel Gateway:
# Connect to external gateway
export OMP_PYTHON_GATEWAY_URL="http://127.0.0.1:8888"
# Optional: auth token if gateway requires it (KG_AUTH_TOKEN)
export OMP_PYTHON_GATEWAY_TOKEN="your-token-here"
When OMP_PYTHON_GATEWAY_URL is set:
- No local gateway process is spawned
- Kernels are created on the external gateway
- The gateway process is not killed on shutdown
- Availability check uses
/api/kernelspecsendpoint instead of local module check
This is useful for:
- Remote kernel execution
- Shared kernel environments
- Pre-configured gateway setups
Environment Propagation
- The kernel inherits a filtered environment (explicit allowlist + denylist)
- Allowlisted prefixes include
LC_,XDG_, andOMP_; known API-key vars are removed PYTHONPATHis passed through if present- Virtual environments are detected via
VIRTUAL_ENV,.venv/, orvenv/and preferred when present
Prelude Extensions
Optional .py modules are loaded after the prelude from:
~/.omp/agent/modulesand~/.pi/agent/modules<project>/.omp/modulesand<project>/.pi/modules
Project modules override user modules with the same filename.
Kernel Modes
Settings under python control exposure and reuse:
toolMode:both(default),ipy-only,bash-onlykernelMode:session(default) orper-callsharedGateway:true(default). Setting tofalsethrows an error because local (per-process) gateways are not supported; the shared gateway is required.
Mode behavior:
session: reuse kernels per session id, serialize execution, evict after 5 minutes of idle time (max 4 sessions)per-call: create a fresh kernel per tool call and shut it down afterward
Environment override:
OMP_PY=0|bash→bash-onlyOMP_PY=1|py→ipy-onlyOMP_PY=mix|both→both
Shell Helper
The Python prelude exposes run() which executes a shell command via bash -c (or sh -c fallback)
and returns a ShellResult with stdout, stderr, and code.
Output Handling
- Streams
stdout/stderras text application/x-omp-statusemits structured status events for the TUIimage/pngdisplay data renders inline in TUIapplication/jsondisplay data renders as a collapsible treetext/markdownis rendered as-is,text/plainis used as a fallbacktext/htmldisplay data is converted to basic markdown
Troubleshooting
- Kernel unavailable: Ensure
python+jupyter-kernel-gateway+ipykernelare installed; the session will fall back to bash-only. - Python mode override: Check
python.toolModeorOMP_PYif the Python tool is missing. - Shared gateway disabled:
python.sharedGateway=falsecauses the Python tool to error because local (per-process) gateways are not supported. - Skip preflight checks: Set
OMP_PYTHON_SKIP_CHECK=1to bypass kernel availability checks. - External gateway unreachable: Check the URL is correct and the gateway is running. If auth is required, set
OMP_PYTHON_GATEWAY_TOKEN. - IPC tracing: Set
OMP_PYTHON_IPC_TRACE=1to log kernel message flow. - Stdin requests: Interactive input is not supported; refactor code to avoid
input()or provide data programmatically.