Metadata-Version: 2.4
Name: quantycat-core
Version: 0.1.0
Summary: QuantyCat robot-side teaching, recording, playback, and task runtime
License-Expression: LicenseRef-Proprietary
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: iron-fleet[so101]>=0.1.0
Requires-Dist: fastapi
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: uvicorn[standard]
Requires-Dist: pyyaml
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: httpx; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: build; extra == "dev"
Dynamic: license-file

# QuantyCat Core

Robot-side backend extracted from Prime Radiant Small. Core owns the existing
HTTP/SSE API, robot session and worker process, leader teaching, timestamped
recordings, timed playback, task storage, cameras, visual-task supervision, and
setup integration. Prime Radiant Small keeps its browser assets and compatibility
imports. Hardware adapters and kinematics remain in Iron Fleet.

## Development installation

Use local source packages until release artifacts are available:

```bash
python -m pip install -e '../quantycat-iron-fleet[so101]' -e . -e ../quantycat-prime-radiant-small -e ../quantycat-library
```

Then run `quantycat setup` to start/reuse Core, or `quantycat serve` to run it in
the foreground. `python -m quantycat_core` is an equivalent foreground entry
point. Default address: `http://127.0.0.1:8765`. The existing `prs-console` launcher
retains port 8095 and calls Core rather than a second backend implementation.
Do not run these launchers simultaneously against the same robot.

This is a source-developer installation. The SO-101 extra currently brings in
LeRobot and Torch; the end-user design remains a lightweight SDK plus a verified
runtime provisioned by `quantycat setup`, without user-selected package extras.

Existing deployments can keep `QUANTYCAT_DEPLOYMENTS` and
`QUANTYCAT_IRON_FLEET_HOME`, including their per-robot worker environments. Without
an explicit store, the launcher creates an empty
`$XDG_CONFIG_HOME/quantycat/deployments` (default `~/.config/quantycat/deployments`).
Installed source packages can use the current interpreter instead of a checkout;
a compiled runtime launches its own `worker` subcommand. Existing files are not
silently imported or relocated. The full Prime
Radiant setup routers remain an optional legacy integration, as before this
extraction; missing routers do not disable teaching/playback for configured robots.

Core does not require UI assets to serve its API. When `prime-radiant-small` is
installed, it serves those assets without copying them into Core. Local API use
is the initial deployment; this launcher refuses non-loopback binds. An optional
`QUANTYCAT_API_TOKEN` protects all HTTP endpoints. Do not put secrets in URLs.

## What setup currently guarantees

- `/health` reports Core identity, API version, version, and stable instance ID.
- `quantycat setup` reuses a compatible Core or starts an installed runtime as a
  detached background process. Ordinary SDK calls do not auto-start anything.
- `/api/runtime` inspects saved deployments and the existing session without
  opening ports/cameras, enabling torque, recalibrating, or moving a robot.
- Missing configuration is reported as incomplete (CLI exit code 2). Existing
  or new SO-101 followers use the existing structured port/calibration guide in
  the terminal. Valid existing configuration is checked without recalibration.
  An active session is preserved instead of opening a second hardware connection.
- `quantycat setup --runtime-only` verifies service availability only. It is not
  a hardware readiness or calibration verification command.

Signed binary verification/provisioning is implemented in the SDK, but a real
compiled release, HTTPS catalog location, and pinned signing public key are still
needed before fresh end-user downloads can work. See
[runtime release](docs/runtime-release.md). No boot-time supervisor is installed.
`--runtime-only` is not proof of hardware readiness.

Core's session now takes the same follower/leader serial-device locks used by
the legacy SDK runtime before launching a worker, and retains them until the
worker exits. This prevents those two paths from opening the same serial ports
during the transition. Other hardware transports still need their adapter-specific
ownership integration before both stacks can be used against them.

## SDK and UI share one worker

Core now serves `/v1/rpc` using its migrated worker, alongside the existing UI
REST/SSE endpoints. The SDK can define/setup a follower, connect, read canonical
joint state, move, wait/cancel, save/go home, teach with a configured leader, and
save/replay named tasks. Worker command IDs distinguish submitted, running,
rejected, cancelled, succeeded, and unknown outcomes. Stop is available without
control ownership and is not serialized behind slow RPC operations.

One SDK writer controls the worker; additional read-only sessions can observe
an already connected robot. UI motion/configuration requests are refused while
the SDK owns control, while read-only UI status and Stop remain available. A UI
connection is not silently taken over by a new SDK writer. Lease expiry attempts
confirmed stopping and cleanup; uncertain cleanup retains ownership.

```python
import quantycat

with quantycat.connect("qubit") as robot:
    robot.move(joint=4, by=5, unit="deg").wait(timeout=10)
    teaching = robot.start_teaching()
    # Move the configured leader after alignment/countdown reaches recording.
    # When the demonstration is finished:
    teaching.finish("pick up")
    robot.play_task("pick up").wait(timeout=30)
```

The example commands movement if connected to a physical robot. Teaching and
playback timing live in the worker; the SDK does not sample or replay client-side.
New SDK recordings include a calibration identity. Missing/mismatched identity,
unsupported schema, interrupted recordings, and incompatible units are rejected.
Saving an existing task requires explicit replacement. Visual tasks continue
through the visual UI workflow; SDK playback refuses to bypass those corrections.

## Compatibility and remaining boundaries

The SDK and setup command both use `QUANTYCAT_CORE_ENDPOINT`, with
`QUANTYCAT_ENDPOINT` retained as a fallback. The startup manager refuses to kill
or replace an unrelated Iron Fleet service at that address. Stop it explicitly
before starting Core on the same port, or choose another port.

Terminal setup adapts the existing Iron Fleet calibration workflow onto Small's
deployment YAML and `so101_follower.json` files. Interrupted calibration is marked
invalid without deleting its recovery file. Legacy SDK JSON definitions are not
silently merged; their import needs a separate explicit migration. Terminal
leader/camera setup still uses the existing UI/setup integration.

The migrated worker supports leader teaching. The legacy SDK hand-guiding methods
return an explicit unsupported-operation error on Core until adapter support is
integrated; they remain available against the legacy Iron Fleet service. API
methods do not advertise hand-guiding capability when unavailable. Kinematics and
read-only planning still run through Iron Fleet on the robot host.

These source packages remain inspectable. The binary build/sign tools are release
preparation, not a claim that a protected production runtime has been published.

## Tests

```bash
python -m pytest -q
```

The migrated suite covers fake robot/leader teaching, playback, setup, session
failure, cameras, tags, and vision. New tests cover health, auth, management
inspection, and running without UI assets. No physical robot is needed.
