crp.cli¶
Auto-generated reference for the crp.cli subpackage.
cli¶
crp.cli ¶
CRP CLI - crp init, dispatch, ingest, status, preview, serve.
StartupResult dataclass ¶
StartupStep dataclass ¶
Result of one startup step.
run_startup(*, provider=None, config_overrides=None, binding_secret=None, skip_auth=False, skip_health=False) ¶
Execute the 6-step startup sequence.
Returns (result, context) where context is a dict of resolved objects: config, provider, binding, warm_store, emitter, session.
cli.main¶
crp.cli.main ¶
CRP CLI entry point - crp init | dispatch | ingest | status | preview | serve.
UNIX-friendly: reads stdin, writes JSON to stdout, pipe-compatible. Requires the click package (pip install crprotocol[cli]).
cli() ¶
CRP CLI entry point - delegates to click group.
cli.sidecar¶
crp.cli.sidecar ¶
CRP HTTP sidecar - lightweight REST API for inter-process context sharing (§9.3).
Architecture ~~~~~~~~~~~~ The sidecar exposes CRP sessions over HTTP, enabling:
-
Inter-LLM fact sharing - two applications using different LLMs can share extracted knowledge. Application A (Claude) extracts facts, Application B (GPT-4) receives them via
/facts/share- both benefit from the other's knowledge without direct LLM-to-LLM communication. -
Full protocol surface - every CRP dispatch variant (basic, tools, reflexive, progressive, stream-augmented, agentic) is available over HTTP. Feedback loops, cost estimation, and provider registration are also exposed.
-
Language-agnostic integration - any language/framework can interact with CRP via HTTP (TypeScript frontend, Rust service, Python backend).
-
Dashboard & monitoring - query session status, inspect facts, preview envelopes, and track event history.
Endpoints ~~~~~~~~~ Session lifecycle::
POST /sessions Create a new CRP session GET /sessions List active sessions GET /sessions/:id/status Session status / metrics POST /sessions/:id/close Close session
Dispatch (all 6 variants)::
POST /sessions/:id/dispatch Basic dispatch POST /sessions/:id/dispatch/tools Tool-mediated dispatch POST /sessions/:id/dispatch/reflexive Reflexive (verify) dispatch POST /sessions/:id/dispatch/progressive Progressive dispatch POST /sessions/:id/dispatch/stream-augmented Stream-augmented dispatch POST /sessions/:id/dispatch/agentic Agentic dispatch
Knowledge::
POST /sessions/:id/ingest Ingest raw text GET /sessions/:id/facts Query extracted facts POST /sessions/:id/facts/share Share facts TO another session POST /sessions/:id/facts/feedback Boost / penalize / reject facts GET /sessions/:id/envelope Preview envelope
Provider::
POST /sessions/:id/providers Register fallback provider
Admin::
GET /health Health check POST /sessions/:id/estimate Cost estimation
Security ~~~~~~~~ - Off by default - crp serve must be explicitly invoked; the sidecar is never started automatically by the library. - Binds to 127.0.0.1 (loopback only) by default. - Optional bearer-token authentication (--auth-token). - Per-session RBAC enforced through the orchestrator's existing security layer. - Request body size capped at 10 MB (configurable). - Rate limiting: configurable per-IP burst window. - Session ownership: sessions are bound to the token hash that created them. - --bind-all requires explicit --auth-token or --allow-unauthenticated. - No HTTPS built-in - deploy behind a TLS-terminating reverse proxy for production use (nginx, Caddy, etc.).
CRPSidecarHandler ¶
Bases: BaseHTTPRequestHandler
HTTP request handler for CRP sidecar endpoints.
Security enforced at every layer: 1. Rate limiting (per-IP) 2. Bearer token authentication 3. Session ownership verification 4. Request body size limits 5. Input validation on all endpoints
log_message(format, *args) ¶
Route access logs through Python logging.
setup() ¶
Initialise the request handler (delegates to BaseHTTPRequestHandler).
finish() ¶
Complete the request, flushing the response stream.
flush_headers() ¶
Send all buffered headers to the client.
do_GET() ¶
Route incoming GET requests to the appropriate handler.
do_POST() ¶
Route incoming POST requests to the appropriate handler.
start_sidecar(host='127.0.0.1', port=9470, auth_token=None, max_body_bytes=10 * 1024 * 1024, max_sessions=64, rate_limit=120, rate_window=60, dispatch_rate_limit=30, dispatch_rate_window=60) ¶
Start the CRP HTTP sidecar.
The sidecar is optional - it is never started automatically by the library. Users must explicitly invoke crp serve or call this function from their own code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host | str | Bind address. Default | '127.0.0.1' |
port | int | Port number. Default | 9470 |
auth_token | str | None | Bearer token for authentication. Strongly recommended when binding to non-loopback addresses. | None |
max_body_bytes | int | Maximum request body size (default 10 MB). | 10 * 1024 * 1024 |
max_sessions | int | Maximum concurrent sessions (default 64). | 64 |
rate_limit | int | Maximum requests per IP per rate window (default 120). | 120 |
rate_window | int | Rate-limit window in seconds (default 60). | 60 |
dispatch_rate_limit | int | Max dispatch requests per caller per window (default 30). | 30 |
dispatch_rate_window | int | Dispatch rate-limit window in seconds (default 60). | 60 |
Returns:
| Type | Description |
|---|---|
HTTPServer | HTTPServer instance (call |
cli.startup¶
crp.cli.startup ¶
CRP startup sequence - 6 steps per §09 §9.5.
Step 1: Resolve config (5-layer, ~1 ms) Step 2: Validate config (type checks, ~5 ms) Step 3: Authenticate app (HMAC handshake, ~1 ms) Step 4: Connect to LLM (health check, ~200–500 ms cloud) Step 5: Init session state (warm store + event log, ~5–50 ms) Step 6: Start event emitter (~1 ms)
StartupStep dataclass ¶
Result of one startup step.
StartupResult dataclass ¶
run_startup(*, provider=None, config_overrides=None, binding_secret=None, skip_auth=False, skip_health=False) ¶
Execute the 6-step startup sequence.
Returns (result, context) where context is a dict of resolved objects: config, provider, binding, warm_store, emitter, session.