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
22 changes: 22 additions & 0 deletions .github/workflows/surfaces-alpha1-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Surfaces alpha.1 verification

on:
push:
branches: [core-alpha1]
paths: [.github/workflows/surfaces-alpha1-ci.yml]

permissions:
contents: read
actions: read

jobs:
verify:
uses: aiperceivable/apcore-surfaces/.github/workflows/core-candidate.yml@fa3ab784dc5f69afa75c0a8e969fb8d985b187ed
with:
core_run_id: '45933698251'
core_sha: b28e1bfd01b804c8662e9e418d8487d0e08cc0ce
core_example_sha: eb2e795e47070369e2347e8a1f4b625831c877c7
surfaces_sha: fa3ab784dc5f69afa75c0a8e969fb8d985b187ed
python_sha256: 9a7de3440413cf891ec2efb4a634350efbbf28659734ddad1c28db70182e7bff
npm_sha256: 833e1f2e4c9328c0c4192c02d9e2c8bfbb62ae651fddd62980b448c41d5842db
rust_sha256: bbc1db3680f3d81b7096fa5eb70476a2c043b333681c2a7bba3597a49bbf11f6
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0-alpha.1]

This prerelease delivers the cross-repository governance and streaming fixes ahead of the microkernel package split. SDK installations use `1.0.0a1` for Python and `1.0.0-alpha.1` for TypeScript and Rust. The full package and configuration entry points remain available for adapter migration.

### Added

- **Protocol 2.1.0 draft, §6.7, §9.16.2, and §12.7.9.** Add managed drain and recovery hooks, async lifecycle adapters, host-directed cancellation before forced removal, opt-in reload reports, and lifecycle events across the three SDKs.
Expand Down
1 change: 1 addition & 0 deletions docs/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The guides are arranged as a learning path. Read the Foundations in order, then

## Integration

- [Python Golden Path](https://github.com/aiperceivable/apcore/tree/main/examples/python/golden-path) — Register an existing function and verify the same governance from Python and MCP
- [Multi-Language](./multi-language.md) — Sharing schemas and module IDs across the Python, TypeScript, and Rust SDKs
- [Adapter Development](./adapter-development.md) — Exposing modules through a web framework
- [Integrating Existing Projects](./integrating-existing-projects.md) — Adopting apcore in an application that already has request and correlation IDs
Expand Down
12 changes: 6 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ A schema makes a capability contract machine-readable and validatable. It does n

## Current Versions

| Component | Package | Version |
|---|---|---|
| Protocol specification | [protocol-spec.md](spec/protocol-spec.md) | `2.1.0` (draft) |
| Python SDK | `apcore` | `0.33.0` |
| TypeScript SDK | `apcore-js` | `0.33.0` |
| Rust SDK | `apcore` | `0.33.0` |
| Component | Package | Stable | In development |
|---|---|---|---|
| Protocol specification | [protocol-spec.md](spec/protocol-spec.md) | `1.66.0` | `2.1.0` (draft) |
| Python SDK | `apcore` | `0.33.0` | `1.0.0a1` |
| TypeScript SDK | `apcore-js` | `0.33.0` | `1.0.0-alpha.1` |
| Rust SDK | `apcore` | `0.33.0` | `1.0.0-alpha.1` |

The three core SDKs share a release line. Surface adapters (`apcore-mcp`, `apcore-a2a`, `apcore-cli`, `apcore-toolkit`) are versioned independently and declare the core range they support in their package metadata.

Expand Down
27 changes: 27 additions & 0 deletions examples/python/golden-path/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Python Golden Path

Register an existing application function as an APCore module and call it from Python and through MCP. The two executors use the same notebook, module definitions, and governance policy. Each uses an in-memory approval store. The MCP server binds to a temporary loopback port and uses the local process as its trust boundary.

## Run the example

Use Python 3.11 or newer. From this directory, create a clean environment and install a compatible Core and MCP pair. To test a release candidate, install its two wheels explicitly so the resolver uses the intended builds.

```bash
python -m venv .venv
. .venv/bin/activate
python -m pip install "$APCORE_WHEEL" "$APCORE_MCP_WHEEL"
python -m pip check
python verify.py
```

Set `APCORE_WHEEL` and `APCORE_MCP_WHEEL` to the absolute paths of the Core and MCP wheels. The verification runs in seconds once the dependencies are installed.

## Follow a call

1. `app.py` registers the notebook's archive operation with an input type inferred from the function signature and an output schema inferred from `ArchiveResult`. It marks the operation as destructive and configures `ExecutionPolicy(strict=True, gate_destructive=True)`.
2. `verify.py` checks a normal lookup, an ACL denial, and invalid input through both entry points. An archive request stays pending until the reviewer records a decision.
3. In Python, the verifier resolves the pending result's public `audit_id` in the store. It retries the same arguments through Core with the private `approval_id` in the reserved `_approval_token` field.
4. Through MCP, the verifier reads `approvalId` and `resumeToken` from the pending tool result's `_meta.apcore.approval`. It polls `__apcore_approval_check` with the public ID, resolves the request, and checks that the status changes to approved. It then retries the original tool arguments with the private token in request `_meta.approvalId`.
5. The verifier checks that each archive executes once and prints the ACL decisions with trace ID, caller ID, and target ID. The approval credential stays out of the audit output.

The in-memory stores are for this local example. A deployed application can use an authenticated review service and a persistent scoped approval store.
54 changes: 54 additions & 0 deletions examples/python/golden-path/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Register an existing application capability for code and MCP callers."""

from dataclasses import dataclass, field

from apcore import ACL, ACLRule, APCore, ExecutionPolicy
from apcore.acl import AuditEntry
from apcore_mcp import APCoreMCP, InMemoryApprovalStore
from pydantic import BaseModel

ARCHIVE = "notes.archive"
LOOKUP = "notes.lookup"
RESTRICTED = "notes.restricted"


class ArchiveResult(BaseModel):
archived: str


@dataclass
class Notebook:
archived: list[str] = field(default_factory=list)

def archive(self, note_id: str) -> ArchiveResult:
self.archived.append(note_id)
return ArchiveResult(archived=note_id)


def build_app(notebook: Notebook, audit: list[AuditEntry]) -> APCore:
client = APCore(policy=ExecutionPolicy(strict=True, gate_destructive=True))
client.executor.set_acl(
ACL(
[ACLRule(callers=["@external"], targets=[ARCHIVE, LOOKUP], effect="allow")],
default_effect="deny",
audit_logger=audit.append,
)
)

@client.module(ARCHIVE, description="Archive a note", annotations={"destructive": True})
def archive(note_id: str) -> ArchiveResult:
return notebook.archive(note_id)

@client.module(LOOKUP, description="Look up a note", annotations={"readonly": True})
def lookup(note_id: str) -> dict[str, bool]:
return {"archived": note_id in notebook.archived}

@client.module(RESTRICTED, description="Access a restricted note")
def restricted() -> dict[str, bool]:
raise AssertionError("The ACL must prevent this function from running")

return client


def build_mcp(client: APCore, reviews: InMemoryApprovalStore) -> APCoreMCP:
return APCoreMCP(client.executor, approval_store=reviews, require_auth=False, async_tasks=False)
148 changes: 148 additions & 0 deletions examples/python/golden-path/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""Exercise one application through direct calls and a real MCP session."""

import asyncio
import json
from collections.abc import AsyncIterator
from contextlib import AsyncExitStack, asynccontextmanager
from socket import socket

import uvicorn
from apcore import APCore
from apcore.acl import AuditEntry
from apcore.errors import ACLDeniedError, ApprovalPendingError, SchemaValidationError
from apcore_mcp import APCoreMCP, InMemoryApprovalStore, StorageBackedApprovalHandler
from app import ARCHIVE, LOOKUP, RESTRICTED, Notebook, build_app, build_mcp
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
from mcp.types import CallToolResult, TextContent


async def verify_direct(client: APCore, notebook: Notebook, reviews: InMemoryApprovalStore) -> None:
assert await client.call_async(LOOKUP, {"note_id": "from-code"}) == {"archived": False}

try:
await client.call_async(RESTRICTED, {})
except ACLDeniedError:
pass
else:
raise AssertionError("Expected an ACL denial")

try:
await client.call_async(LOOKUP, {"note_id": ["invalid"]})
except SchemaValidationError:
pass
else:
raise AssertionError("Expected input validation to fail")

arguments = {"note_id": "from-code"}
try:
await client.call_async(ARCHIVE, arguments)
except ApprovalPendingError as pending:
approval_id = pending.result.audit_id
resume_token = pending.approval_id
assert approval_id and resume_token and approval_id != resume_token
else:
raise AssertionError("Expected approval to be pending")
assert notebook.archived == []
assert await reviews.resolve(approval_id, approved=True)
resumed = await client.call_async(ARCHIVE, {**arguments, "_approval_token": resume_token})
assert resumed == {"archived": "from-code"}
assert notebook.archived == ["from-code"]


@asynccontextmanager
async def local_session(mcp: APCoreMCP) -> AsyncIterator[ClientSession]:
async with mcp.async_serve() as application:
with socket() as listener:
listener.bind(("127.0.0.1", 0))
port = listener.getsockname()[1]
config = uvicorn.Config(application, lifespan="off", log_level="warning")
server = uvicorn.Server(config)
task = asyncio.create_task(server.serve(sockets=[listener]))
try:
async with asyncio.timeout(10):
while not server.started:
if task.done():
task.result()
raise RuntimeError("The MCP server stopped before startup")
await asyncio.sleep(0.01)
url = f"http://127.0.0.1:{port}/mcp"
async with (
streamable_http_client(url, terminate_on_close=False) as (read, write, _),
ClientSession(read, write) as session,
):
await session.initialize()
yield session
finally:
server.should_exit = True
await task


def tool_text(result: CallToolResult) -> str:
(content,) = result.content
assert isinstance(content, TextContent)
return content.text


async def verify_mcp(mcp: APCoreMCP, notebook: Notebook, reviews: InMemoryApprovalStore) -> None:
async with local_session(mcp) as session:
tools = {tool.name: tool for tool in (await session.list_tools()).tools}
assert tools[ARCHIVE].inputSchema["properties"]["note_id"]["type"] == "string"
assert "__apcore_approval_check" in tools
lookup = await session.call_tool(LOOKUP, {"note_id": "from-code"})
assert not lookup.isError and json.loads(tool_text(lookup)) == {"archived": True}
denied = await session.call_tool(RESTRICTED, {})
assert denied.isError and "Access denied" in tool_text(denied)
invalid = await session.call_tool(LOOKUP, {"note_id": ["invalid"]})
assert invalid.isError and "validation" in tool_text(invalid).lower()

arguments = {"note_id": "from-mcp"}
pending = await session.call_tool(ARCHIVE, arguments)
assert pending.isError and "Approval pending" in tool_text(pending)
assert notebook.archived == ["from-code"]
assert pending.meta is not None
approval = pending.meta["apcore"]["approval"]
approval_id, resume_token = approval["approvalId"], approval["resumeToken"]
assert approval_id != resume_token
assert resume_token not in tool_text(pending)

poll_arguments = {"approval_id": approval_id}
status = await session.call_tool("__apcore_approval_check", poll_arguments)
assert not status.isError
assert json.loads(tool_text(status)) == {**poll_arguments, "status": "pending"}
assert await reviews.resolve(approval_id, approved=True)
status = await session.call_tool("__apcore_approval_check", poll_arguments)
assert not status.isError
assert json.loads(tool_text(status)) == {**poll_arguments, "status": "approved"}

approved = await session.call_tool(ARCHIVE, arguments, meta={"approvalId": resume_token})
assert not approved.isError, tool_text(approved)
assert json.loads(tool_text(approved)) == {"archived": "from-mcp"}
assert notebook.archived == ["from-code", "from-mcp"]


async def main() -> None:
notebook = Notebook()
audit: list[AuditEntry] = []
async with AsyncExitStack() as cleanup:
direct = build_app(notebook, audit)
cleanup.push_async_callback(direct.shutdown)
direct_reviews = InMemoryApprovalStore()
direct.executor.set_approval_handler(StorageBackedApprovalHandler(direct_reviews))
await verify_direct(direct, notebook, direct_reviews)

mcp_client = build_app(notebook, audit)
cleanup.push_async_callback(mcp_client.shutdown)
mcp_reviews = InMemoryApprovalStore()
await verify_mcp(build_mcp(mcp_client, mcp_reviews), notebook, mcp_reviews)

assert sum(entry.decision == "deny" and entry.target_id == RESTRICTED for entry in audit) == 2
assert sum(entry.decision == "allow" and entry.target_id == ARCHIVE for entry in audit) == 4
assert all(entry.trace_id for entry in audit)
for entry in audit:
print(entry.trace_id, entry.caller_id, entry.target_id, entry.decision)
print("Direct calls and MCP both passed the governance checks.")


if __name__ == "__main__":
asyncio.run(main())
29 changes: 29 additions & 0 deletions planning/microkernel-delivery/alpha-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# APCore alpha.1 delivery record

The last stable release on the old line is `0.33.0`. The next public Core candidate is `1.0.0-alpha.1`. The Python distribution uses the PEP 440 spelling `1.0.0a1`. Each affected Surfaces package uses its own prerelease version.

## Scope

Core includes the C1 execution and governance fixes, C2 streaming completion, and the managed lifecycle already merged at `316cb05ce1d30931586a12e9296751690782bc7a`. The release changes package metadata and adds the Python Golden Path. The import surface, default governance, and configuration behavior follow the current SDKs until the microkernel work in the next alpha.

Surfaces starts from `a2b4a3af7d58cf1095569fbea9434f48270668e7` and the candidate work for MCP cancellation and completion, A2A deadlines and cleanup, CLI strict streaming and structured arguments, registration integrity, and the M1 and M2 migration paths.

## Core rehearsal

| Local artifact | SHA-256 |
|---|---|
| `apcore-1.0.0a1-py3-none-any.whl` | `a674d4bfd25790a928e67a8960604205dc676f4f1f70522012b2a5ebdfe96e9c` |
| `apcore-1.0.0a1.tar.gz` | `e875f3c03e6aad8c2d6fdd99dcd818731b38968ac2ccc6e2e4c4a4e0817447fc` |
| `apcore-js-1.0.0-alpha.1.tgz` | `fe86feb59e4f8ce9686217c1d9bbd80b1c12360b99ca58107000473a0c0890a5` |
| `apcore-1.0.0-alpha.1.crate` | `a98f01a31ebdd737c9cadb46b8a4e2a44d0635a0a3a305063ef6fa7eba2c87e9` |

Full local suites passed 6,703 Python, 5,910 TypeScript, and 3,286 Rust tests. The fixture integrity checks covered 98 shared fixtures and 643 expected fields. The installed wheel and npm tarball and unpacked crate passed the Quick Start and governed-stream examples and lifecycle checks. The wheel was exercised on Python 3.11.18 and the npm archive on Node 20.0.0. The local Rust rehearsal used Rust 1.100.0. The distribution workflow covers the declared Rust floor.

The [Golden Path](../../examples/python/golden-path/README.md) passed after installing `apcore==1.0.0a1` and `apcore-mcp==0.23.5a1` from their local wheels in an isolated environment. It uses a real MCP session and verifies schema rejection, ACL denial, approval suspension and resumption, one execution per authorized call, and ACL audit evidence.

## Public release gates

- Record the final source commits, workflow runs, and SHA-256 digests of the exact build artifacts. Verify package contents and the declared runtime versions from clean checkouts.
- Against the selected Core artifacts, run the Surfaces matrix for each component's declared minimum and the alpha candidate. Verify Rust MCP and CLI installations using registry resolution and confirm the resolved Core identity.
- After release approval, publish Core first and then the affected Surfaces packages in dependency order. Verify the same behavior from public package installs and record the resolved versions and checksums. Keep the prior stable line available for consumers that have not adopted an alpha.
- Use the Golden Path with the first Python pilot and record setup, governance outcomes, and adoption friction separately from build acceptance.
5 changes: 5 additions & 0 deletions python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0a1]

### Added

- Add the `stream_with_completion()` handle for a single invocation's chunks, validated output, and terminal outcome.
- Add owned shutdown and removal operations, managed drain and recovery hooks, and opt-in governed reload reports.
- Expose Prometheus text rendering without starting an HTTP listener.
- Expose `APCore(fail_on_error=True)` and `sys_modules_errors` for system-module startup, and `Executor.ungated_approval_modules()` for approval readiness. ([#230](https://github.com/aiperceivable/apcore/issues/230), [#231](https://github.com/aiperceivable/apcore/issues/231))

### Changed
Expand Down
2 changes: 1 addition & 1 deletion python/apcore-conformance.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
implementation:
name: apcore-python
version: 0.33.0
version: 1.0.0a1
language: python
spec_version: 1.65.0
maintainer: AI Perceivable
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "apcore"
version = "0.33.0"
version = "1.0.0a1"
description = "Build once, invoke by code or AI — with schema, ACL, approval, and audit enforced at every call"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
Loading
Loading