Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/kernel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## v0.2.0 (2026-11-29)

Breaking: autopilot now fails closed on any pack that is not signed and promoted.

- `run_portal_pack(mode="autopilot")` and `openadapt-kernel run --mode autopilot` load the pack through the registry's Ed25519 signature, digest and zero-PII check against a pinned key (`trusted_pack_public_key` / `--trusted-pack-pub`). A missing key, unsigned file, foreign key, edited envelope, or a signed stage other than `VERIFIED_AUTOPILOT` returns `ESCALATED` with zero submissions. Draft mode still loads flat or signed packs.
- The signature also binds autopilot to the signed `portal_origin`. Unless the page has exactly that scheme, host and port (default ports 80 and 443), the run returns `ESCALATED` with `autopilot_origin_not_signed`. The check runs before the browser opens when `url` is elsewhere, after navigation, redirects or CDP attach, on any popup before it is staged, and again right before the commit click. A pack with no valid http(s) origin cannot run autopilot. Before this change, a pack signed for one site could submit a form on any other.
- `NonDomKernelExecutor.execute(autonomy_stage=...)` can only lower the pack's stage; unknown stages resolve to `SHADOW`.
- Self-healing no longer promotes or publishes the healed pack. It used to qualify the pack against its own written values. `auto_publish_on_heal` and `registry_dir` are kept for compatibility but publish nothing.
- Autopilot no longer repairs and commits in the same run. When staging fails or the commit control is blocked, `coding_agent_fn` may propose a repair inside the zero-PHI twin. The run then returns `ESCALATED` with `heal_proposed=True` and the reason suffix `self_heal_proposed_not_applied`, and clicks nothing on the live page. Before this change, the unqualified repair was replayed live and could click Save.
- When read-back refutes persistence after the commit click, the run returns `ESCALATED` with `readback_refuted_after_commit`. It never heals, re-clicks or re-submits. Before this change, a heal could re-submit and report `VERIFIED` after a duplicate write. The old reason `readback_refuted_persistence` is replaced.
- Every exit after the commit click that does not end `VERIFIED` adds a pending `uncertain_write_reconcile` obligation to the ledger and the signed receipt and sets `RunResult.uncertain_write`. That covers `commit_not_observed`, `readback_refuted_after_commit`, a completion-closure failure, and an exception after the click, which now returns `ESCALATED` with `post_commit_error:<type>` instead of raising.
- `RunResult.heal_proposed` and `RunResult.uncertain_write` are new. In autopilot, `RunResult.healed` is now always `False`.
- MCP server: mode ceiling, trusted pack key, receipt key and output root are server configuration (`McpServerConfig`, `serve-mcp --allow-autopilot --trusted-pack-pub --priv --output-root`). Tool calls default to draft, cannot request autopilot unless the server allows it, cannot pass `private_key_path` or any other undeclared argument, and write only under the output root.
- `pull_verified_pack` raises `ValueError` for non-envelope files, non-Ed25519 keys and bad signatures instead of relying on `assert`.
- New `openadapt-kernel publish-pack` command signs a pack into a registry directory.
- README: removed the stale line-count claim.

## v0.1.0 (2026-11-25)

- Initial release of `openadapt-kernel` with zero `openadapt-flow` dependencies and zero per-app engine code.
Expand Down
48 changes: 45 additions & 3 deletions packages/kernel/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# openadapt-kernel

Minimal, self-contained runtime kernel (`< 3,200` LOC, zero `openadapt-flow` dependencies, zero per-app code) implementing commit-boundary verification, cross-rail read-back, reversible occlusion probing, online ACI calibration, macro staging, stepwise live-DOM healing, and shadow-to-autopilot execution:
Self-contained runtime kernel (zero `openadapt-flow` dependencies, zero per-app code) implementing commit-boundary verification, cross-rail read-back, reversible occlusion probing, online ACI calibration, macro staging, stepwise live-DOM healing, and shadow-to-autopilot execution:

1. **Default-Deny Obligation, Capability, and Saga Ledger (`ledger.py`):** Episodes start `UNVERIFIED` and emit `VERIFIED` only when every obligation has an independent post-commit read-back proof and zero dirty form buffers remain. Step-limit timeouts, crashes, and unverified exits deterministically return `ESCALATED`. Carries both cross-screen `<MANDATORY_CONSTRAINTS>` and `<VERIFIED_CAPABILITIES>` (user consent and SSA opaque-ID provenance), with durable Saga checkpointing across multi-system workflows.
2. **Wire and DOM-Effect Commit Interceptor (`interceptor.py`):** Detects commits from actual network mutations (`POST`, `PUT`, `PATCH`, `DELETE`) or non-empty dirty form submissions instead of button-label regexes. Excludes search/filter inputs from dirty buffers and escapes escalation payloads safely.
Expand All @@ -15,8 +15,50 @@ Minimal, self-contained runtime kernel (`< 3,200` LOC, zero `openadapt-flow` dep
openadapt-kernel shadow-sync --dir ./recordings --pack-id portal-v1 --out pack.json
openadapt-kernel qualify --pack pack.json --evidence ./recordings/run_1/extension_evidence.jsonl
openadapt-kernel keygen --priv priv.pem --pub pub.pem
openadapt-kernel keygen --priv pack_priv.pem --pub pack_pub.pem
openadapt-kernel run --pack pack.json --dossier dossier.json --mode draft --cdp-url http://127.0.0.1:9222
openadapt-kernel run --pack pack.json --dossier dossier.json --mode autopilot --url https://portal.example --commit-selector '[data-testid="submit-btn"]' --priv priv.pem --receipt-out receipt.json
openadapt-kernel publish-pack --pack promoted_pack.json --priv pack_priv.pem --registry-dir ./registry
openadapt-kernel run --pack ./registry/portal-v1-<digest>.pack.json --dossier dossier.json --mode autopilot --trusted-pack-pub pack_pub.pem --url https://portal.example --commit-selector '[data-testid="submit-btn"]' --priv priv.pem --receipt-out receipt.json
openadapt-kernel verify-receipt --receipt receipt.json --pub pub.pem
openadapt-kernel serve-mcp
openadapt-kernel serve-mcp --output-root ./mcp-out
```

## Autopilot needs a signed, promoted pack

`--mode autopilot` submits only when the pack file is a signed
`openadapt.kernel.pack/v1` envelope that verifies against `--trusted-pack-pub`
and whose signed stage is `VERIFIED_AUTOPILOT`. An unsigned file, a pack signed
by another key, an envelope edited after signing, or a `SHADOW` or
`DRAFT_TO_COMMIT` stage returns `ESCALATED` before the browser opens, and
nothing is submitted. Draft mode accepts unsigned packs because it stops
before the commit control.

The signature also covers where the run may click. Autopilot refuses with
`autopilot_origin_not_signed` unless the page has exactly the pack's
`portal_origin` (scheme, host and port), checked before the browser opens,
after navigation or CDP attach, on any popup, and right before the commit
click.

Signing with `publish-pack` is the promotion step, so whoever holds the pack
key approves autopilot. Keep that key apart from the receipt key (`--priv`),
which the runner holds. A run never publishes or promotes its own pack.

Autopilot never repairs and commits in the same run. If staging fails or the
commit control is blocked, a coding agent may propose a repair inside the
zero-PHI twin; the run escalates with the proposal recorded and clicks nothing.
If read-back refutes persistence after the commit click, the run escalates with
`readback_refuted_after_commit` and never clicks or submits again. Any run that
clicked commit and did not end `VERIFIED` records an `uncertain_write_reconcile`
obligation in the signed receipt, so the write is reconciled rather than
retried.

`NonDomKernelExecutor.execute(autonomy_stage=...)` can only lower a pack's
stage, never raise it.

## MCP server limits

The model calling the MCP tools does not set how far a run may go. Autopilot,
the trusted pack key, the receipt key and the output root are `serve-mcp` flags
(`--allow-autopilot`, `--trusted-pack-pub`, `--priv`, `--output-root`). Tool
calls run in draft unless the server allows autopilot, cannot pass key paths,
and can write only under the output root (default `~/.openadapt/kernel/mcp`).
2 changes: 1 addition & 1 deletion packages/kernel/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "openadapt-kernel"
version = "0.1.0"
version = "0.2.0"
description = "Minimal commit-boundary verification, macro-action staging, stepwise live-DOM healing, and shadow-to-autopilot kernel for GUI agents"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
57 changes: 54 additions & 3 deletions packages/kernel/src/openadapt_kernel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
induce_pack_from_extension_recordings,
parse_extension_evidence_jsonl,
)
from openadapt_kernel.mcp_server import serve_stdio
from openadapt_kernel.mcp_server import DEFAULT_OUTPUT_ROOT, McpServerConfig, serve_stdio
from openadapt_kernel.prepare import (
PrepareCard,
PrepareResumeResponse,
RubberStampViolationError,
UnresolvedSlot,
resume_from_prepare_card,
)
from openadapt_kernel.registry import portal_pack_from_dict, publish_signed_pack
from openadapt_kernel.runner import format_run_result_json, run_portal_pack
from openadapt_kernel.stateful_twin import synthesize_twin_with_coding_agent

Expand Down Expand Up @@ -129,6 +130,14 @@ def _cmd_verify_receipt(args: argparse.Namespace) -> int:
return 0 if valid else 1


def _cmd_publish_pack(args: argparse.Namespace) -> int:
"""Sign a flat pack JSON into the registry. Holding the key is the approval."""
pack = portal_pack_from_dict(json.loads(Path(args.pack).read_text(encoding="utf-8")))
out = publish_signed_pack(pack, Path(args.priv).read_bytes(), Path(args.registry_dir))
print(json.dumps({"pack_id": pack.pack_id, "stage": pack.stage, "out": str(out)}))
return 0


def _cmd_run(args: argparse.Namespace) -> int:
dossier = json.loads(Path(args.dossier).read_text(encoding="utf-8"))
result = run_portal_pack(
Expand All @@ -142,6 +151,9 @@ def _cmd_run(args: argparse.Namespace) -> int:
receipt_out=Path(args.receipt_out) if args.receipt_out else None,
episode_id=args.episode_id,
headless=not args.headed,
trusted_pack_public_key=(
Path(args.trusted_pack_pub).read_bytes() if args.trusted_pack_pub else None
),
)
print(format_run_result_json(result))
return 0 if result.outcome in ("READY_FOR_HUMAN_COMMIT", "VERIFIED") else 1
Expand All @@ -166,8 +178,19 @@ def _cmd_shadow_sync(args: argparse.Namespace) -> int:
return 0


def _cmd_serve_mcp(_args: argparse.Namespace) -> int:
serve_stdio()
def _cmd_serve_mcp(args: argparse.Namespace) -> int:
if args.allow_autopilot and not args.trusted_pack_pub:
raise ValueError("serve-mcp --allow-autopilot requires --trusted-pack-pub")
serve_stdio(
config=McpServerConfig(
allow_autopilot=bool(args.allow_autopilot),
trusted_pack_public_key_path=(
Path(args.trusted_pack_pub) if args.trusted_pack_pub else None
),
private_key_path=Path(args.priv) if args.priv else None,
output_root=Path(args.output_root),
)
)
return 0


Expand Down Expand Up @@ -402,6 +425,15 @@ def build_parser() -> argparse.ArgumentParser:
p_ver.add_argument("--pub", required=True)
p_ver.set_defaults(func=_cmd_verify_receipt)

p_pub = sub.add_parser(
"publish-pack",
help="Sign a PortalPack with the pack-approval key and write it to a registry directory",
)
p_pub.add_argument("--pack", required=True)
p_pub.add_argument("--priv", required=True, help="Ed25519 pack-approval private key PEM")
p_pub.add_argument("--registry-dir", required=True)
p_pub.set_defaults(func=_cmd_publish_pack)

p_run = sub.add_parser("run", help="Run a PortalPack in draft or verified autopilot mode")
p_run.add_argument("--pack", required=True)
p_run.add_argument("--dossier", required=True)
Expand All @@ -413,6 +445,13 @@ def build_parser() -> argparse.ArgumentParser:
p_run.add_argument("--receipt-out")
p_run.add_argument("--episode-id", default=None)
p_run.add_argument("--headed", action="store_true")
p_run.add_argument(
"--trusted-pack-pub",
help=(
"Ed25519 public key PEM that must have signed the pack. Required for "
"--mode autopilot; the signed stage must be VERIFIED_AUTOPILOT."
),
)
p_run.set_defaults(func=_cmd_run)

p_sync = sub.add_parser("shadow-sync", help="Scan a directory of Chrome Co-Pilot recordings and induce a PortalPack")
Expand All @@ -422,6 +461,18 @@ def build_parser() -> argparse.ArgumentParser:
p_sync.set_defaults(func=_cmd_shadow_sync)

p_mcp = sub.add_parser("serve-mcp", help="Run the zero-dependency stdio JSON-RPC 2.0 MCP server")
p_mcp.add_argument(
"--allow-autopilot",
action="store_true",
help="Let tool calls request autopilot (still needs a pack signed by --trusted-pack-pub)",
)
p_mcp.add_argument("--trusted-pack-pub", help="Ed25519 public key PEM that signs autopilot packs")
p_mcp.add_argument("--priv", help="Ed25519 private key PEM used to sign run receipts")
p_mcp.add_argument(
"--output-root",
default=str(DEFAULT_OUTPUT_ROOT),
help="Directory every tool-written file must resolve under",
)
p_mcp.set_defaults(func=_cmd_serve_mcp)

p_twin = sub.add_parser("twin-synthesize", help="Synthesize a Zero-PHI StatefulTwinApp via a coding agent CLI")
Expand Down
Loading