From bc4e25048ef4488a9eacf46e73e35ae59a22b819 Mon Sep 17 00:00:00 2001 From: abrichr Date: Sun, 29 Nov 2026 21:44:52 -0500 Subject: [PATCH] build: make openadapt-kernel an optional, capped alpha extra; run its suite in ci - Remove openadapt-kernel from the launcher's base dependencies. The kernel extra stays and is capped: openadapt-kernel>=0.1.0,<0.2. Relock. - openadapt kernel, its --help and the lazy openadapt.* kernel exports say to install 'openadapt[kernel]' when the kernel is missing. A subprocess test blocks openadapt_kernel and checks import openadapt, openadapt --help and openadapt kernel. - Install-weight budgets forbid the kernel in the base install; the platform manifest's compatibility range follows pyproject. - packages.yml (called by the required ci check) gets a kernel job: ruff, mypy and the whole suite with headless Chromium, Python 3.12 on PR and queue tiers, 3.11 and 3.12 on main. Selected by packages/kernel changes and enforced by packages-gate. - Delete kernel.yml and kernel-ci.yml, which ran the same checks outside the required check. Kernel releases now read the packages.yml kernel job. - Docs: kernel README install section, root README row, capability row. --- .github/workflows/kernel-ci.yml | 45 ----- .github/workflows/kernel.yml | 44 ----- .github/workflows/packages.yml | 58 ++++++- README.md | 2 +- ...boundary-kernel-an-optional-alpha-extra.md | 1 + openadapt/__init__.py | 10 +- openadapt/cli.py | 9 +- openadapt/cli_tasks.py | 2 +- packages/kernel/README.md | 19 ++ platform-manifest.json | 2 +- pyproject.toml | 10 +- scripts/ci/newest_green.py | 2 +- scripts/install_weight/budgets.json | 2 +- tests/fixtures/cli_surface.json | 4 +- tests/test_ci_locked_installs.py | 2 +- tests/test_kernel_ci.py | 162 ++++++++++++++++++ tests/test_kernel_integration.py | 96 ++++++++++- uv.lock | 4 +- 18 files changed, 355 insertions(+), 119 deletions(-) delete mode 100644 .github/workflows/kernel-ci.yml delete mode 100644 .github/workflows/kernel.yml create mode 100644 capabilities/04-the-core-a-checked-entry-every-time/0620-commit-boundary-kernel-an-optional-alpha-extra.md create mode 100644 tests/test_kernel_ci.py diff --git a/.github/workflows/kernel-ci.yml b/.github/workflows/kernel-ci.yml deleted file mode 100644 index 3f53fb551c..0000000000 --- a/.github/workflows/kernel-ci.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Kernel CI - -on: - pull_request: - paths: - - "packages/kernel/**" - - ".github/workflows/kernel-ci.yml" - push: - paths: - - "packages/kernel/**" - - ".github/workflows/kernel-ci.yml" - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: kernel-ci-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - kernel-ci: - name: openadapt-kernel (uv py3.12 + ruff + mypy + pytest) - runs-on: ubuntu-latest - timeout-minutes: 15 - defaults: - run: - working-directory: packages/kernel - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 - with: - python-version: "3.12" - - name: Install kernel dependencies and headless Chromium - run: | - uv sync --locked --extra browser --extra dev - uv run --no-sync playwright install chromium - - name: Lint with ruff - run: uv run --no-sync ruff check src tests - - name: Typecheck with mypy - run: uv run --no-sync mypy --ignore-missing-imports src - - name: Run full test suite - run: uv run --no-sync pytest tests -q diff --git a/.github/workflows/kernel.yml b/.github/workflows/kernel.yml deleted file mode 100644 index 00a08d73ee..0000000000 --- a/.github/workflows/kernel.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Kernel Package CI - -on: - pull_request: - paths: - - "packages/kernel/**" - - ".github/workflows/kernel.yml" - push: - branches: [main] - paths: - - "packages/kernel/**" - - ".github/workflows/kernel.yml" - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: kernel-${{ github.event.pull_request.number || github.run_id }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - kernel-test: - name: openadapt-kernel (py3.12 + Chromium) - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 - with: - python-version: "3.12" - - name: Install package and test dependencies - working-directory: packages/kernel - run: | - uv sync --locked --extra browser --extra dev - uv run --no-sync python -m playwright install chromium - - name: Lint with ruff - working-directory: packages/kernel - run: uv run --no-sync ruff check . - - name: Run unit, boundary, CLI, and headless Chromium tests - working-directory: packages/kernel - run: uv run --no-sync pytest -v tests diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 7e68221a90..fd10ba7859 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -67,6 +67,12 @@ # from the push-to-main run, so no Desktop release ships without the # installers having built and passed their smoke tests. # +# openadapt-kernel (packages/kernel), the optional alpha commit-boundary +# runtime, keeps its own uv.lock and runs `uv sync --locked` against it: ruff, +# mypy and its whole suite, headless Chromium tests included, on Python 3.12 +# for a PR and in the queue, plus 3.11 on main. It depends on no other +# package here, so only its own files select it. +# # openadapt-tray (packages/tray) keeps its own uv.lock and runs `uv sync # --locked` against it: its suite on Linux with Python 3.12 for a PR and in # the queue, plus 3.11, macOS and Windows on main; ruff, the version and changelog @@ -122,6 +128,7 @@ jobs: agent: ${{ steps.classify.outputs.agent }} eligibility: ${{ steps.classify.outputs.eligibility }} verify: ${{ steps.classify.outputs.verify }} + kernel: ${{ steps.classify.outputs.kernel }} capture: ${{ steps.classify.outputs.capture }} privacy: ${{ steps.classify.outputs.privacy }} desktop: ${{ steps.classify.outputs.desktop }} @@ -149,7 +156,7 @@ jobs: if [ "$EVENT_NAME" = pull_request ]; then unit_shards=4; else unit_shards=2; fi echo "flow_unit_shards=$unit_shards" >> "$GITHUB_OUTPUT" all() { - for pkg in flow flow_at_rest flow_onprem flow_agent_frameworks types agent eligibility verify capture privacy desktop tray program_graph seal_view weight fast_checks; do echo "$pkg=true" >> "$GITHUB_OUTPUT"; done + for pkg in flow flow_at_rest flow_onprem flow_agent_frameworks types agent eligibility verify kernel capture privacy desktop tray program_graph seal_view weight fast_checks; do echo "$pkg=true" >> "$GITHUB_OUTPUT"; done exit 0 } case "$EVENT_NAME" in @@ -213,6 +220,7 @@ jobs: # The optional eligibility connector is tested against the in-tree core. eligibility="$(hit "^packages/(connectors/eligibility|flow|types)/|$wf")" verify="$(hit "^packages/(verify|flow|types)/|$wf")" + kernel="$(hit "^packages/kernel/|$wf")" capture="$(hit "^packages/capture/|$wf")" privacy="$(hit "^packages/privacy/|$wf")" # Desktop bundles the program map from packages/program-graph. @@ -241,6 +249,7 @@ jobs: echo "agent=$agent" echo "eligibility=$eligibility" echo "verify=$verify" + echo "kernel=$kernel" echo "capture=$capture" echo "privacy=$privacy" echo "desktop=$desktop" @@ -760,8 +769,8 @@ jobs: packages/capture/uv.lock cache-suffix: flow-default-at-rest - name: Install from the locks - # Root's lock first (for `--editable .` dependencies such as - # openadapt-kernel), then Flow's, then Capture's: the in-tree Capture + # Root's lock first (for dependencies only `--editable .` declares), + # then Flow's, then Capture's: the in-tree Capture # can need newer dependencies than the published one Flow's lock names. run: >- python ../../scripts/ci/locked_install.py --lock . --lock 'packages/flow[dev,capture,agent]' --lock packages/capture @@ -935,8 +944,8 @@ jobs: packages/capture/uv.lock cache-suffix: flow-unit - name: Install from the locks - # Root's lock first (for `--editable .` dependencies such as - # openadapt-kernel), then Flow's, then Capture's: the in-tree Capture + # Root's lock first (for dependencies only `--editable .` declares), + # then Flow's, then Capture's: the in-tree Capture # can need newer dependencies than the published one Flow's lock names. run: >- python ../../scripts/ci/locked_install.py --lock . --lock 'packages/flow[dev,capture,agent]' --lock packages/capture @@ -1780,6 +1789,43 @@ jobs: - name: Test run: uv run --no-sync pytest tests/ -v + kernel: + name: kernel (py${{ matrix.python-version }}) + needs: scope + if: github.event.pull_request.draft != true && (needs.scope.outputs.kernel == 'true') + runs-on: ubuntu-latest + # About two minutes on ubuntu-latest (Nov 2026), most of it the suite. + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + # PR and queue tiers: one Python; main adds the oldest. + python-version: ${{ fromJSON((github.event_name == 'pull_request' || github.event_name == 'merge_group') && '["3.12"]' || '["3.11", "3.12"]') }} + defaults: + run: + working-directory: packages/kernel + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + with: + enable-cache: true + cache-dependency-glob: "packages/kernel/uv.lock" + cache-suffix: kernel-py${{ matrix.python-version }} + - name: Set up Python ${{ matrix.python-version }} + run: uv python install ${{ matrix.python-version }} + - name: Install from the lock, with headless Chromium + run: | + uv sync --locked --python ${{ matrix.python-version }} --extra browser --extra dev + uv run --no-sync python -m playwright install chromium + - name: Ruff + run: uv run --no-sync ruff check src tests + - name: Mypy + run: uv run --no-sync mypy --ignore-missing-imports src + - name: Test (unit, boundary, CLI and headless Chromium) + run: uv run --no-sync pytest tests -q + desktop-test: name: desktop test needs: scope @@ -2080,6 +2126,7 @@ jobs: - eligibility - verify - verify-clean-install + - kernel - flow-lint - flow-unit - flow-default-at-rest @@ -2135,6 +2182,7 @@ jobs: "eligibility": "eligibility", "verify": "verify", "verify-clean-install": "verify", + "kernel": "kernel", "flow-lint": "flow", "flow-unit": "flow", "flow-default-at-rest": "flow_at_rest", diff --git a/README.md b/README.md index 5ab3caaa80..476e732eeb 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Full methodology, benchmark tables, and verifiable raw runs: **[openadapt.ai/pro | Package | Role | Source | |---|---|---| | [`openadapt`](https://pypi.org/project/openadapt/) | Unified CLI (`quickstart`, `wrap`, `connect`, `record`, `compile`, `run`, `verify`, `kernel`, `agent`, `mcpify`) | [`openadapt/`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/openadapt) | -| [`openadapt-kernel`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/kernel) | Commit-boundary kernel: default-deny write ledger, wire/DOM commit interceptor, stepwise live-DOM healer, cross-rail oracles, Ed25519 receipts, stdio MCP | [`packages/kernel/`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/kernel) | +| [`openadapt-kernel`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/kernel) | Optional alpha extra (`pip install 'openadapt[kernel]'`). Commit-boundary kernel: default-deny write ledger, wire/DOM commit interceptor, stepwise live-DOM healer, cross-rail oracles, Ed25519 receipts, stdio MCP | [`packages/kernel/`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/kernel) | | [`openadapt-flow`](https://pypi.org/project/openadapt-flow/) | Demonstration compiler, certification, qualification, governed replay, auto-repair, and BYOC connector | [`packages/flow/`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/flow) | | [`openadapt-agent`](https://pypi.org/project/openadapt-agent/) | MCP server, Agent Skills export, and A2A handoffs | [`packages/agent/`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/agent) | | [`openadapt-verify`](https://pypi.org/project/openadapt-verify/) | Standalone Python SDK (`@verified`, `checked_write`, local JIT compiler, `mcpify`) | [`packages/verify/`](https://github.com/OpenAdaptAI/OpenAdapt/tree/main/packages/verify) | diff --git a/capabilities/04-the-core-a-checked-entry-every-time/0620-commit-boundary-kernel-an-optional-alpha-extra.md b/capabilities/04-the-core-a-checked-entry-every-time/0620-commit-boundary-kernel-an-optional-alpha-extra.md new file mode 100644 index 0000000000..a968c0f0ae --- /dev/null +++ b/capabilities/04-the-core-a-checked-entry-every-time/0620-commit-boundary-kernel-an-optional-alpha-extra.md @@ -0,0 +1 @@ +| Commit-boundary kernel, an optional alpha extra: `pip install 'openadapt[kernel]'` adds `openadapt kernel` (or install `openadapt-kernel` alone for its own command), an experimental runtime with shadow, draft and autopilot modes and signed receipts that does not depend on `openadapt-flow`. `pip install openadapt` leaves it out, and the extra is capped below the next minor version because its API may change before 1.0 | On main | Synthetic (its own suite, headless Chromium tests included, runs in the required `ci` check on every kernel change) | [packages/kernel](packages/kernel/README.md) | diff --git a/openadapt/__init__.py b/openadapt/__init__.py index a30601d70e..13344d757d 100644 --- a/openadapt/__init__.py +++ b/openadapt/__init__.py @@ -1,7 +1,8 @@ """OpenAdapt launcher and compatibility meta-package. -``openadapt-kernel`` (``openadapt kernel ...``) is the canonical minimal -commit-boundary and shadow-to-autopilot runtime. ``openadapt-flow`` ships in +``openadapt-kernel`` (``openadapt kernel ...``) is the minimal commit-boundary +and shadow-to-autopilot runtime, an optional alpha extra +(``pip install 'openadapt[kernel]'``). ``openadapt-flow`` ships in the base install for backward-compatible workflow compilation, replay, and receipt verification (``openadapt flow ...``). The lazy exports below preserve compatibility with optional supporting and research packages: @@ -9,6 +10,7 @@ pip install openadapt # launcher + openadapt-flow pip install openadapt[capture] # native capture pip install openadapt[privacy] # privacy scrubbing + pip install openadapt[kernel] # commit-boundary runtime (alpha) pip install openadapt[ml,evals] # research toolkits """ @@ -116,8 +118,8 @@ def __getattr__(name: str): return locals()[name] except ImportError: raise ImportError( - f"{name} requires openadapt-kernel. " - "Install with: pip install openadapt-kernel" + f"{name} requires openadapt-kernel, an optional alpha extra. " + "Install with: pip install 'openadapt[kernel]'" ) # Lightweight 2-line Python SDK wrapper (stdlib-only at import time) diff --git a/openadapt/cli.py b/openadapt/cli.py index c3ec268a2c..38661e68be 100644 --- a/openadapt/cli.py +++ b/openadapt/cli.py @@ -2386,12 +2386,15 @@ def _optional_engine_entrypoint(command_ctx: click.Context, modules: tuple[str, ) @click.pass_context def kernel(command_ctx: click.Context) -> None: - """Run the minimal commit-boundary and shadow-to-autopilot runtime.""" + """Run the minimal commit-boundary and shadow-to-autopilot runtime. + + An optional alpha extra: pip install 'openadapt[kernel]' + """ kernel_main = _optional_engine_entrypoint(command_ctx, ("openadapt_kernel.cli",)) if kernel_main is None: click.echo( - "Error: openadapt-kernel is not installed. " - "Install with: pip install openadapt-kernel", + "Error: openadapt-kernel is not installed. It is an optional " + "alpha extra. Install with: pip install 'openadapt[kernel]'", err=True, ) sys.exit(2) diff --git a/openadapt/cli_tasks.py b/openadapt/cli_tasks.py index c2ed0f7700..852fa127ab 100644 --- a/openadapt/cli_tasks.py +++ b/openadapt/cli_tasks.py @@ -25,7 +25,7 @@ # These tasks are implemented by launcher-native commands, not the Flow parser. LAUNCHER_TASKS = { - "kernel": "Run the minimal commit-boundary and shadow-to-autopilot runtime", + "kernel": "Run the commit-boundary runtime (optional alpha extra)", "mcpify": "Serve compiled workflow packs or JIT plans as a local MCP server", "wrap": "Run an agent task once, then reuse its checked compiled tool", "test": "Test an agent on real apps with planted faults, for CI", diff --git a/packages/kernel/README.md b/packages/kernel/README.md index b496394214..a369e9fa47 100644 --- a/packages/kernel/README.md +++ b/packages/kernel/README.md @@ -9,6 +9,25 @@ Minimal, self-contained runtime kernel (`< 3,200` LOC, zero `openadapt-flow` dep 5. **Reversible Pre-Click Probe & Online ACI Calibration (`probe.py`, `aci.py`):** Hit-tests commit controls via `elementsFromPoint` plus an 80ms hover/focus probe to block transparent-overlay click-jacking (`probe_before_click`), and calibrates anomaly thresholds across shifting UI themes via `SessionStartNormalizer` and Gibbs-Candes `OnlineACICalibrator`. 6. **Shadow-to-Autopilot, 4-Mutant Offline Qualification, Micro-Handoff, Live Runner, and MCP Server (`copilot.py`, `extension_bridge.py`, `runner.py`, `mcp_server.py`, `cli.py`):** Induces zero-PII `PortalPack` specs from live Chrome Co-Pilot `extension_evidence.jsonl` recordings, qualifies verifiers offline against four counterfactual mutants (zero staging DB), runs `Draft-to-Commit` or `Verified Autopilot` across main and child popup windows via Playwright or `--cdp-url`, signs `openadapt.kernel.receipt/v1` Ed25519 receipts, and serves tools over stdio JSON-RPC 2.0 MCP. +## Install + +openadapt-kernel is an alpha, and `pip install openadapt` does not include it. +Install it as the launcher's optional extra, which runs it as +`openadapt kernel ...`: + +```bash +pip install 'openadapt[kernel]' +``` + +Or install it on its own, which gives you the `openadapt-kernel` command: + +```bash +pip install openadapt-kernel +``` + +Its API can change in any minor release before 1.0, so the launcher's extra is +capped below the next minor version. + ## CLI Quickstart ```bash diff --git a/platform-manifest.json b/platform-manifest.json index 3d104cc2f2..2e1a75296a 100644 --- a/platform-manifest.json +++ b/platform-manifest.json @@ -1204,7 +1204,7 @@ ">=0.1.0" ], "openadapt-kernel": [ - ">=0.1.0" + ">=0.1.0,<0.2" ], "openadapt-ml": [ ">=0.2.0" diff --git a/pyproject.toml b/pyproject.toml index a108a97f69..659dfc4d0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,9 +84,6 @@ dependencies = [ # `openadapt-agent` command without a second package. 2.2.4 widens its # openadapt-flow cap to <5 so it resolves cleanly alongside Flow 4.0.0. "openadapt-agent>=2.2.4,<3; python_version < '3.13'", - # Minimal commit-boundary and shadow-to-autopilot runtime (`openadapt kernel`). - # Depends only on cryptography, which openadapt-flow already pulls. - "openadapt-kernel>=0.1.0; python_version < '3.13'", ] [project.optional-dependencies] @@ -156,10 +153,11 @@ flow = [ agent = [ "openadapt-agent>=2.2.4,<3; python_version < '3.13'", ] -# `openadapt-kernel` ships in the base install on Python <3.13. Keep the extra -# so `pip install openadapt[kernel]` also resolves directly (including 3.13+). +# The commit-boundary and shadow-to-autopilot runtime behind `openadapt kernel`. +# An alpha, so it is opt-in (`pip install 'openadapt[kernel]'`) and capped +# below its next minor release, which may break its API. kernel = [ - "openadapt-kernel>=0.1.0", + "openadapt-kernel>=0.1.0,<0.2", ] # Agent-to-agent handoffs over the A2A (Agent2Agent) protocol: # `openadapt agent serve --a2a`. Handoffs over MCP, HTTP and files need no extra. diff --git a/scripts/ci/newest_green.py b/scripts/ci/newest_green.py index d73ea22e95..848ddb89d5 100644 --- a/scripts/ci/newest_green.py +++ b/scripts/ci/newest_green.py @@ -47,7 +47,7 @@ "packages.yml", ["verify facade (", "verify clean install"], ), - "kernel": (["packages/kernel"], "kernel.yml", ["openadapt-kernel ("]), + "kernel": (["packages/kernel"], "packages.yml", ["kernel ("]), "program-graph": (["packages/program-graph"], "packages.yml", ["program-graph"]), "desktop": ( ["packages/desktop"], diff --git a/scripts/install_weight/budgets.json b/scripts/install_weight/budgets.json index 601b0e556d..a476b0c01a 100644 --- a/scripts/install_weight/budgets.json +++ b/scripts/install_weight/budgets.json @@ -345,6 +345,7 @@ "forbid": [ "openadapt-desktop", "openadapt-capture", + "openadapt-kernel", "matplotlib" ], "allow": [ @@ -380,7 +381,6 @@ "openadapt", "openadapt-agent", "openadapt-flow", - "openadapt-kernel", "openadapt-types", "opencv-python", "opentelemetry-api", diff --git a/tests/fixtures/cli_surface.json b/tests/fixtures/cli_surface.json index ea29d0b242..4d300026b9 100644 --- a/tests/fixtures/cli_surface.json +++ b/tests/fixtures/cli_surface.json @@ -1,14 +1,14 @@ { "click": "8.5.0", "help": { - "openadapt": "Usage: openadapt [OPTIONS] COMMAND [ARGS]...\n\n Record, compile and run workflows with OpenAdapt.\n\n Compile a demonstrated workflow into deterministic local replay. Healthy runs make no model calls;\n configured checks can halt on ambiguity. Native and remote substrates use platform-specific extras\n and permissions; training/evaluation commands are research.\n\n Quick Start (uv fetches Python 3.12 if needed):\n uvx --python 3.12 openadapt@latest quickstart\n Or, on Python 3.11-3.12:\n python -m pip install --upgrade openadapt\n openadapt quickstart\n\n Manual Demo Lifecycle:\n openadapt flow demo-record --out rec\n openadapt compile rec --out bundle --name demo\n openadapt flow lint bundle\n openadapt flow certify bundle --policy permissive\n openadapt flow replay bundle --demo-app\n\n Lint lists the demo's coverage gaps. The demo has warnings, so `lint --strict` exits 1 on it. The\n manual demo is runnable but not certified for consequential work. Use `openadapt flow tutorial`\n for the effect-verified first run.\n\n Give an MCP client your compiled workflows:\n openadapt agent serve --bundles DIR --mode production\n\nOptions:\n --version Show the version and exit.\n --help Show this message and exit.\n\nCommands:\n demo Try the demonstration and tutorial\n verify Check effects, receipts, and evidence\n record Record a task and its narration\n teach Teach a correction to a stopped workflow\n compile Compile and prepare workflow bundles\n run Run, resume, and route workflows\n approve Review and approve paused work\n undo Declare and run approved undo steps\n qualify Qualify a workflow for its intended use\n repair Review, test, and promote repairs\n inspect Inspect workflows, runs, and reports\n workflow Manage reusable workflow libraries\n services Run local services and connectors\n setup Configure connections, privacy, and access\n research Run benchmarks and research tools\n kernel Run the minimal commit-boundary and shadow-to-autopilot runtime\n mcpify Serve compiled workflow packs or JIT plans as a local MCP server\n wrap Run an agent task once, then reuse its checked compiled tool\n test Test an agent on real apps with planted faults, for CI\n audit Sample verified runs for statistical compliance spot-checks\n\nLegacy commands:\n agent Serve compiled workflows to an MCP client...\n bench Public benchmarks you can rerun with your...\n capture Standalone local human GUI capture...\n cohort-receipt Build or verify a zero-PHI Ed25519 Merkle...\n connect Connect this computer or VPC runner to...\n deploy Check this host and print the safe...\n doctor Check system requirements and dependencies.\n eval Research: evaluate computer-use models on...\n flight Record any agent you already run, and hold...\n flow Run the canonical demonstration compiler...\n handoff Hand a result to another agent with its...\n hooks Check a coding agent's writes to declared...\n login Sign in to OpenAdapt Cloud: `openadapt...\n plan Legacy (superseded by `openadapt kernel`):...\n pool Manage containerized xfreerdp3 + Xvfb...\n proxy Legacy (superseded by `openadapt kernel`):...\n pull Download a packaged workflow: `openadapt...\n quickstart Show a task once, run it, then watch it...\n receipt Check, view and share a run's receipt:...\n serve Research: serve the training dashboard and...\n shadow Check each write your agent makes against...\n support-bundle Redact a run directory into a...\n train Research: train ML models on captured...\n trust Manage customer-owned Ed25519 signing keys.\n version Show version information for all packages.", + "openadapt": "Usage: openadapt [OPTIONS] COMMAND [ARGS]...\n\n Record, compile and run workflows with OpenAdapt.\n\n Compile a demonstrated workflow into deterministic local replay. Healthy runs make no model calls;\n configured checks can halt on ambiguity. Native and remote substrates use platform-specific extras\n and permissions; training/evaluation commands are research.\n\n Quick Start (uv fetches Python 3.12 if needed):\n uvx --python 3.12 openadapt@latest quickstart\n Or, on Python 3.11-3.12:\n python -m pip install --upgrade openadapt\n openadapt quickstart\n\n Manual Demo Lifecycle:\n openadapt flow demo-record --out rec\n openadapt compile rec --out bundle --name demo\n openadapt flow lint bundle\n openadapt flow certify bundle --policy permissive\n openadapt flow replay bundle --demo-app\n\n Lint lists the demo's coverage gaps. The demo has warnings, so `lint --strict` exits 1 on it. The\n manual demo is runnable but not certified for consequential work. Use `openadapt flow tutorial`\n for the effect-verified first run.\n\n Give an MCP client your compiled workflows:\n openadapt agent serve --bundles DIR --mode production\n\nOptions:\n --version Show the version and exit.\n --help Show this message and exit.\n\nCommands:\n demo Try the demonstration and tutorial\n verify Check effects, receipts, and evidence\n record Record a task and its narration\n teach Teach a correction to a stopped workflow\n compile Compile and prepare workflow bundles\n run Run, resume, and route workflows\n approve Review and approve paused work\n undo Declare and run approved undo steps\n qualify Qualify a workflow for its intended use\n repair Review, test, and promote repairs\n inspect Inspect workflows, runs, and reports\n workflow Manage reusable workflow libraries\n services Run local services and connectors\n setup Configure connections, privacy, and access\n research Run benchmarks and research tools\n kernel Run the commit-boundary runtime (optional alpha extra)\n mcpify Serve compiled workflow packs or JIT plans as a local MCP server\n wrap Run an agent task once, then reuse its checked compiled tool\n test Test an agent on real apps with planted faults, for CI\n audit Sample verified runs for statistical compliance spot-checks\n\nLegacy commands:\n agent Serve compiled workflows to an MCP client...\n bench Public benchmarks you can rerun with your...\n capture Standalone local human GUI capture...\n cohort-receipt Build or verify a zero-PHI Ed25519 Merkle...\n connect Connect this computer or VPC runner to...\n deploy Check this host and print the safe...\n doctor Check system requirements and dependencies.\n eval Research: evaluate computer-use models on...\n flight Record any agent you already run, and hold...\n flow Run the canonical demonstration compiler...\n handoff Hand a result to another agent with its...\n hooks Check a coding agent's writes to declared...\n login Sign in to OpenAdapt Cloud: `openadapt...\n plan Legacy (superseded by `openadapt kernel`):...\n pool Manage containerized xfreerdp3 + Xvfb...\n proxy Legacy (superseded by `openadapt kernel`):...\n pull Download a packaged workflow: `openadapt...\n quickstart Show a task once, run it, then watch it...\n receipt Check, view and share a run's receipt:...\n serve Research: serve the training dashboard and...\n shadow Check each write your agent makes against...\n support-bundle Redact a run directory into a...\n train Research: train ML models on captured...\n trust Manage customer-owned Ed25519 signing keys.\n version Show version information for all packages.", "openadapt approve": "Usage: openadapt approve [OPTIONS]\n\n Run the canonical demonstration compiler and governed runtime.\n\n Every argument passes to openadapt-flow unchanged. This keeps the launcher command list, help,\n options, validation, and exit codes identical to the installed engine version.\n\nOptions:\n --help Show this message and exit.", "openadapt audit": "Usage: openadapt audit [OPTIONS] COMMAND [ARGS]...\n\n Sample verified runs for statistical compliance spot-checks.\n\nOptions:\n --help Show this message and exit.\n\nCommands:\n sample Draw a random statistical spot-check sample of verified runs.", "openadapt audit sample": "Usage: openadapt audit sample [OPTIONS]\n\n Draw a random statistical spot-check sample of verified runs.\n\nOptions:\n --receipts-dir, --input PATH Path to receipts directory or JSONL ledger (default:\n ~/.openadapt/verify).\n --rate FLOAT Fraction of eligible runs to sample, in (0.0, 1.0]. [default:\n 0.05]\n --count INTEGER Explicit number of runs to sample instead of using --rate.\n --min-samples INTEGER Minimum number of runs to sample (capped at eligible count).\n --max-samples INTEGER Maximum number of runs to sample.\n --since TEXT Include only runs at or after this ISO date/timestamp or window\n (e.g. 7d, 24h).\n --seed TEXT Deterministic seed for reproducible sampling (omit for\n cryptographic random sampling).\n --status TEXT Run status filter (case-insensitive, comma-separated, or ALL).\n [default: VERIFIED]\n --out PATH Write an audit_sample_v1 manifest to a JSON or JSONL file.\n --json Print the audit_sample_v1 manifest as JSON to stdout.\n --exclude-already-sampled PATH Exclude run IDs and digests already in a prior manifest or ledger\n (repeatable).\n --help Show this message and exit.", "openadapt compile": "Usage: openadapt compile [OPTIONS]\n\n Compile a recording. Uses the same options as flow compile.\n\nOptions:\n --help Show this message and exit.", "openadapt demo": "Usage: openadapt demo [OPTIONS]\n\n Run the canonical demonstration compiler and governed runtime.\n\n Every argument passes to openadapt-flow unchanged. This keeps the launcher command list, help,\n options, validation, and exit codes identical to the installed engine version.\n\nOptions:\n --help Show this message and exit.", "openadapt inspect": "Usage: openadapt inspect [OPTIONS]\n\n Run the canonical demonstration compiler and governed runtime.\n\n Every argument passes to openadapt-flow unchanged. This keeps the launcher command list, help,\n options, validation, and exit codes identical to the installed engine version.\n\nOptions:\n --help Show this message and exit.", - "openadapt kernel": "Usage: openadapt kernel [OPTIONS]\n\n Run the minimal commit-boundary and shadow-to-autopilot runtime.\n\nOptions:\n --help Show this message and exit.", + "openadapt kernel": "Usage: openadapt kernel [OPTIONS]\n\n Run the minimal commit-boundary and shadow-to-autopilot runtime.\n\n An optional alpha extra: pip install 'openadapt[kernel]'\n\nOptions:\n --help Show this message and exit.", "openadapt mcpify": "Usage: openadapt mcpify [OPTIONS]\n\n Serve compiled workflow packs or JIT plans as a local MCP server.\n\nOptions:\n --help Show this message and exit.", "openadapt qualify": "Usage: openadapt qualify [OPTIONS]\n\n Run the canonical demonstration compiler and governed runtime.\n\n Every argument passes to openadapt-flow unchanged. This keeps the launcher command list, help,\n options, validation, and exit codes identical to the installed engine version.\n\nOptions:\n --help Show this message and exit.", "openadapt record": "Usage: openadapt record [OPTIONS]\n\n Record a workflow. Uses the same options as flow record.\n\nOptions:\n --help Show this message and exit.", diff --git a/tests/test_ci_locked_installs.py b/tests/test_ci_locked_installs.py index 3abb13aa7f..505adad77c 100644 --- a/tests/test_ci_locked_installs.py +++ b/tests/test_ci_locked_installs.py @@ -178,7 +178,7 @@ def test_every_lock_the_helper_names_exists() -> None: def test_editable_root_installs_include_root_lock() -> None: # Installing `--editable .` registers the root `openadapt` metadata; its # own lockfile must be included so `uv pip check` sees root-only deps - # (such as `openadapt-kernel`) instead of failing with a missing package. + # instead of failing with a missing package. missing = [] for workflow, line in COMMANDS: if "locked_install.py" not in line: diff --git a/tests/test_kernel_ci.py b/tests/test_kernel_ci.py new file mode 100644 index 0000000000..489e5fd392 --- /dev/null +++ b/tests/test_kernel_ci.py @@ -0,0 +1,162 @@ +"""openadapt-kernel's suite runs inside the required `ci` check. + +ci.yml calls packages.yml, whose `kernel` job runs ruff, mypy and the kernel's +whole suite when a change touches packages/kernel. packages-gate fails the +check when that job was selected but skipped, so a kernel change can't merge +untested. The release lookup (scripts/ci/newest_green.py) reads the same job. +""" + +from __future__ import annotations + +import importlib.util +import json +import os +import subprocess +import sys +from pathlib import Path + +import pytest +import yaml + +ROOT = Path(__file__).resolve().parents[1] +WORKFLOWS = ROOT / ".github" / "workflows" + + +def _load(name: str) -> dict: + return yaml.safe_load((WORKFLOWS / name).read_text(encoding="utf-8")) + + +PACKAGES = _load("packages.yml") +JOBS = PACKAGES["jobs"] + + +def _classify(changed: list[str], event: str, tmp_path: Path) -> dict[str, str]: + step = next( + s for s in JOBS["scope"]["steps"] if s.get("name") == "Classify the change" + ) + diff = 'changed="$(git diff --name-only "$base" HEAD)"' + assert diff in step["run"] + script = step["run"].replace(diff, 'changed="$STUB_CHANGED"') + out = tmp_path / "github_output" + out.write_text("", encoding="utf-8") + env = { + **os.environ, + "EVENT_NAME": event, + "BEFORE_SHA": "", + "GROUP_BASE_SHA": "", + "STUB_CHANGED": "\n".join(changed), + "GITHUB_OUTPUT": str(out), + } + result = subprocess.run( + ["bash", "-c", script], env=env, capture_output=True, text=True, cwd=ROOT + ) + assert result.returncode == 0, result.stdout + result.stderr + return dict( + line.split("=", 1) for line in out.read_text().splitlines() if "=" in line + ) + + +def _gate(outputs: dict[str, str], results: dict[str, str], event: str) -> int: + step = next( + s + for s in JOBS["packages-gate"]["steps"] + if s.get("name") == "Require every selected package job to pass" + ) + script = "\n".join(step["run"].splitlines()[1:-1]) + needs = {"scope": {"result": "success", "outputs": outputs}} + needs.update({name: {"result": result} for name, result in results.items()}) + return subprocess.run( + [sys.executable, "-c", script], + env={**os.environ, "RESULTS": json.dumps(needs), "EVENT_NAME": event}, + capture_output=True, + text=True, + ).returncode + + +def test_ci_reaches_the_kernel_job_through_packages(): + assert _load("ci.yml")["jobs"]["packages"]["uses"] == ( + "./.github/workflows/packages.yml" + ) + job = JOBS["kernel"] + assert job["needs"] == "scope" + assert "needs.scope.outputs.kernel == 'true'" in job["if"] + assert "draft != true" in job["if"] + assert JOBS["scope"]["outputs"]["kernel"] == "${{ steps.classify.outputs.kernel }}" + assert "kernel" in JOBS["packages-gate"]["needs"] + + +def test_the_kernel_job_lints_typechecks_and_runs_the_whole_suite(): + job = JOBS["kernel"] + assert job["defaults"]["run"]["working-directory"] == "packages/kernel" + runs = "\n".join(step.get("run", "") for step in job["steps"]) + assert "uv sync --locked" in runs + assert "--extra browser --extra dev" in runs + assert "playwright install chromium" in runs + assert "ruff check src tests" in runs + assert "mypy" in runs + assert "pytest tests" in runs + # Nothing narrows the suite on the PR tier. + (pytest_line,) = [line for line in runs.splitlines() if "pytest" in line] + assert pytest_line.strip() == "uv run --no-sync pytest tests -q" + for step in job["steps"]: + if "uses" in step: + ref = step["uses"].split("@", 1)[1].split()[0] + assert len(ref) == 40 and all(c in "0123456789abcdef" for c in ref) + + +@pytest.mark.parametrize( + ("changed", "selected"), + [ + (["packages/kernel/src/openadapt_kernel/runner.py"], "true"), + (["packages/kernel/README.md"], "true"), + (["packages/kernel/uv.lock"], "true"), + ([".github/workflows/packages.yml"], "true"), + (["packages/flow/openadapt_flow/ir.py"], "false"), + (["openadapt/cli.py"], "false"), + (["README.md"], "false"), + ], +) +def test_scope_selects_the_kernel_for_kernel_changes_only( + changed: list[str], selected: str, tmp_path: Path +): + assert _classify(changed, "pull_request", tmp_path)["kernel"] == selected + + +def test_a_scheduled_run_selects_the_kernel(tmp_path: Path): + assert _classify([], "schedule", tmp_path)["kernel"] == "true" + + +@pytest.mark.parametrize("event", ["pull_request", "merge_group", "push"]) +@pytest.mark.parametrize( + ("result", "code"), + [("success", 0), ("failure", 1), ("cancelled", 1), ("skipped", 1)], +) +def test_the_gate_fails_a_selected_kernel_job_that_did_not_pass( + event: str, result: str, code: int +): + assert _gate({"kernel": "true"}, {"kernel": result}, event) == code + + +def test_the_gate_accepts_an_unselected_skipped_kernel_job(): + assert _gate({"kernel": "false"}, {"kernel": "skipped"}, "pull_request") == 0 + + +def test_the_old_kernel_workflows_are_gone(): + assert not (WORKFLOWS / "kernel.yml").exists() + assert not (WORKFLOWS / "kernel-ci.yml").exists() + + +def test_kernel_releases_read_the_packages_kernel_job(): + spec = importlib.util.spec_from_file_location( + "newest_green", ROOT / "scripts" / "ci" / "newest_green.py" + ) + module = importlib.util.module_from_spec(spec) + assert spec.loader is not None + spec.loader.exec_module(module) + paths, workflow, prefixes = module.PACKAGES["kernel"] + assert paths == ["packages/kernel"] + assert workflow == "packages.yml" + name = JOBS["kernel"]["name"] + for python in ("3.11", "3.12"): + rendered = name.replace("${{ matrix.python-version }}", python) + assert any(rendered.startswith(prefix) for prefix in prefixes), rendered diff --git a/tests/test_kernel_integration.py b/tests/test_kernel_integration.py index e9db4e5a33..ae650ebe61 100644 --- a/tests/test_kernel_integration.py +++ b/tests/test_kernel_integration.py @@ -3,15 +3,24 @@ from __future__ import annotations import builtins +import os +import subprocess +import sys +import tomllib import types +from pathlib import Path from types import SimpleNamespace import pytest from click.testing import CliRunner +from packaging.requirements import Requirement +from packaging.utils import canonicalize_name import openadapt from openadapt import cli +ROOT = Path(__file__).resolve().parents[1] + def test_kernel_cli_works_on_python_314_without_flow_python_cap(monkeypatch): calls: list[list[str]] = [] @@ -37,6 +46,17 @@ def missing(name): result = CliRunner().invoke(cli.main, ["kernel", "run"]) assert result.exit_code == 2 assert "openadapt-kernel is not installed" in result.output + assert "pip install 'openadapt[kernel]'" in result.output + + +def test_kernel_help_without_package_names_the_extra(monkeypatch): + def missing(name): + raise ModuleNotFoundError(name="openadapt_kernel") + + monkeypatch.setattr(cli, "import_module", missing) + result = CliRunner().invoke(cli.main, ["kernel", "--help"]) + assert result.exit_code == 0, result.output + assert "pip install 'openadapt[kernel]'" in result.output def test_openadapt_lazy_exports_kernel_symbols(monkeypatch): @@ -68,8 +88,9 @@ def block_kernel(name, *args, **kwargs): return real_import(name, *args, **kwargs) monkeypatch.setattr(builtins, "__import__", block_kernel) - with pytest.raises(ImportError, match="requires openadapt-kernel"): + with pytest.raises(ImportError, match="requires openadapt-kernel") as excinfo: getattr(openadapt, "ObligationLedger") + assert "pip install 'openadapt[kernel]'" in str(excinfo.value) def test_legacy_plan_and_proxy_help_point_to_openadapt_kernel(monkeypatch): @@ -77,3 +98,76 @@ def test_legacy_plan_and_proxy_help_point_to_openadapt_kernel(monkeypatch): for cmd in ("plan", "proxy"): help_text = cli.main.commands[cmd].help or "" assert "openadapt kernel" in help_text + + +# Runs in a fresh interpreter whose import system refuses `openadapt_kernel`, +# so it holds even where the kernel is installed or on PYTHONPATH. +_WITHOUT_KERNEL = r""" +import importlib.abc +import sys + + +class _NoKernel(importlib.abc.MetaPathFinder): + def find_spec(self, name, path=None, target=None): + if name == "openadapt_kernel" or name.startswith("openadapt_kernel."): + raise ModuleNotFoundError(f"No module named {name!r}", name=name) + return None + + +sys.meta_path.insert(0, _NoKernel()) +for loaded in [m for m in sys.modules if m.split(".")[0] == "openadapt_kernel"]: + del sys.modules[loaded] + +import openadapt +from openadapt import cli + +assert "openadapt_kernel" not in sys.modules +try: + openadapt.ObligationLedger +except ImportError as exc: + print("EXPORT:", exc) +else: + raise SystemExit("ObligationLedger imported without openadapt-kernel") + +for argv in (["--help"], ["kernel", "run"], ["kernel", "--help"]): + try: + cli.main(argv, prog_name="openadapt") + except SystemExit as exc: + print("EXIT", " ".join(argv), exc.code) +""" + + +def test_launcher_imports_and_runs_without_kernel_installed(tmp_path): + env = dict(os.environ) + env["PYTHONPATH"] = os.pathsep.join( + [str(ROOT), *filter(None, [env.get("PYTHONPATH")])] + ) + result = subprocess.run( + [sys.executable, "-c", _WITHOUT_KERNEL], + capture_output=True, + text=True, + cwd=tmp_path, + env=env, + timeout=120, + ) + out = result.stdout + result.stderr + assert result.returncode == 0, out + assert "EXIT --help 0" in out + assert "EXIT kernel run 2" in out + assert "EXIT kernel --help 0" in out + assert "openadapt-kernel is not installed" in out + assert out.count("pip install 'openadapt[kernel]'") >= 3, out + assert "Traceback" not in out, out + + +def test_kernel_is_an_opt_in_capped_extra(): + project = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"] + base = [Requirement(spec) for spec in project["dependencies"]] + assert "openadapt-kernel" not in {canonicalize_name(r.name) for r in base} + extras = project["optional-dependencies"] + (kernel,) = [Requirement(spec) for spec in extras["kernel"]] + assert canonicalize_name(kernel.name) == "openadapt-kernel" + assert str(kernel.specifier) == "<0.2,>=0.1.0" + # Bundles stay opt-out of the alpha too. + for name in ("all", "core"): + assert not any("kernel" in spec for spec in extras[name]), name diff --git a/uv.lock b/uv.lock index 05a79941fa..ee689e9dee 100644 --- a/uv.lock +++ b/uv.lock @@ -2902,7 +2902,6 @@ dependencies = [ { name = "click" }, { name = "openadapt-agent", marker = "python_full_version < '3.13'" }, { name = "openadapt-flow", extra = ["browser", "hosted"], marker = "python_full_version < '3.13'" }, - { name = "openadapt-kernel", marker = "python_full_version < '3.13'" }, { name = "openadapt-types", marker = "python_full_version < '3.13'" }, { name = "rich", marker = "python_full_version < '3.13'" }, ] @@ -3014,8 +3013,7 @@ requires-dist = [ { name = "openadapt-flow", extras = ["vision"], marker = "python_full_version < '3.13' and extra == 'flow'", specifier = ">=4.0.1,<5.0.0" }, { name = "openadapt-flow", extras = ["windows"], marker = "python_full_version < '3.13' and extra == 'windows'", specifier = ">=4.0.1,<5.0.0" }, { name = "openadapt-grounding", marker = "extra == 'grounding'", specifier = ">=0.1.0" }, - { name = "openadapt-kernel", marker = "python_full_version < '3.13'", specifier = ">=0.1.0" }, - { name = "openadapt-kernel", marker = "extra == 'kernel'", specifier = ">=0.1.0" }, + { name = "openadapt-kernel", marker = "extra == 'kernel'", specifier = ">=0.1.0,<0.2" }, { name = "openadapt-ml", marker = "extra == 'ml'", specifier = ">=0.2.0" }, { name = "openadapt-retrieval", marker = "extra == 'retrieval'", specifier = ">=0.1.0" }, { name = "openadapt-types", marker = "python_full_version < '3.13'", specifier = ">=0.24.2,<0.25.0" },