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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Provide explicit configuration, discovery, and full runtime assemblies. The default profile supports in-memory execution from installed Python, TypeScript, and Rust packages.
- Add the pure TypeScript Prometheus text renderer and host-owned subscriber factories for configured event delivery.
- **Protocol 2.0.0 draft revision 2.** Add opt-in policy evaluation after input validation. The enabled pipeline combines approval requirements at one gate, binds approval to the selected module version and effective arguments, and enforces the gate before ordinary and streaming execution. Final-scope pending approvals require an explicitly compatible scoped handler.

### Changed

Expand Down
1 change: 1 addition & 0 deletions conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ declared extension. Adapter wire projections are verified in Surfaces.
| `stream_completion.json` | SDK streaming completion | One invocation reports its canonical output, individual post-processing outcomes, and termination through the opt-in stream handle |
| `approval_gate.json` | A05 | Approval gate Step 5: explicit compatibility policy, result-status outcomes, and scoped resumption |
| `core_profile_governance.json` | §7.4, §7.9 | Core Profile defaults and explicit overrides through public preflight and execution, including an injected Executor |
| `post_validation_policy.json` | §7.4.1 | Opt-in policy evaluation, validated input approval binding, preflight, scoped resumption and zero stream starts on rejection |
| `approval_request_fields.json` | D-03 | `ApprovalRequest` carries `caller_id` (null for a top-level call) and `action` (= `module_id`) — fields the Contract text already required and no SDK's `ApprovalRequest` carried |
| `preflight_disclosure.json` | §12.8.5.1 | `Executor.validate()` withholds module-level introspection from a caller the ACL denied: no `module_preflight` / `module_preview` check, empty `predicted_changes`, and the hooks themselves not invoked. Module lookup is Step 3 and the ACL check is Step 4, so all three SDKs gated these hooks on "lookup succeeded" alone and ran module-authored code for a denied caller. Scoped to AUTHORIZATION: a failed `schema` check does **not** suppress introspection. Drivers MUST run the real `validate()` against a real Registry and ACL, and MUST observe hook invocation from inside the hook bodies — see `driver_contract` |
| `middleware_on_error_recovery.json` | A11 | After-middleware error recovery: first-dict-wins, null passthrough, success non-override |
Expand Down
84 changes: 84 additions & 0 deletions conformance/fixtures/post_validation_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"description": "Exercise the opted-in post-validation policy through the public Executor call, preflight, stream and scoped resumption paths.",
"driver_contract": {
"module_id": "demo.policy",
"module_version": "1.2.3",
"business_input": {"amount": 10, "secret": "private-fixture-value"},
"input_schema": {
"type": "object",
"properties": {
"amount": {"type": "integer"},
"secret": {"type": "string", "x-sensitive": true}
},
"required": ["amount", "secret"],
"additionalProperties": false
},
"notes": "Apply per-case input overrides. If configured, before middleware substitutes rewrite_amount. For resume, the handler first returns pending, then compares the full approval scope and atomically consumes the matching credential. Retry the original business inputs with _approval_token and any retry overrides. Counts include both traversals. For preflight, read the policy check or requires_approval in the public report. Count starts on module execute and on the stream producer. Spy requests must observe the real version, an argument snapshot without the credential, and /secret in sensitive_fields."
},
"test_cases": [
{
"id": "unary_uses_the_validated_middleware_result",
"entry": "call",
"rewrite_amount": 20,
"verdict": "allow",
"expected": {"module_starts": 1, "evaluated_amount": 20, "approval_requests": 0}
},
{
"id": "both_requirements_use_one_final_approval",
"entry": "call",
"requires_approval": true,
"rewrite_amount": 20,
"verdict": "require_approval",
"expected": {"module_starts": 1, "evaluated_amount": 20, "approval_requests": 1, "approved_amount": 20}
},
{
"id": "allow_preserves_the_early_approval_requirement",
"entry": "call",
"requires_approval": true,
"rewrite_amount": 20,
"verdict": "allow",
"expected": {"module_starts": 1, "evaluated_amount": 20, "approval_requests": 1, "approved_amount": 20}
},
{
"id": "preflight_reports_approval_without_prompting",
"entry": "preflight",
"rewrite_amount": 20,
"verdict": "require_approval",
"expected": {"module_starts": 0, "evaluated_amount": 10, "approval_requests": 0, "requires_approval": true}
},
{
"id": "denied_stream_does_not_start_its_producer",
"entry": "stream",
"verdict": "deny",
"expected": {"module_starts": 0, "evaluated_amount": 10, "approval_requests": 0, "error_code": "POLICY_DENIED"}
},
{
"id": "provider_fault_fails_closed",
"entry": "call",
"verdict": "throw",
"expected": {"module_starts": 0, "evaluated_amount": 10, "approval_requests": 0, "error_code": "POLICY_EVALUATION_ERROR"}
},
{
"id": "schema_rejection_prevents_policy_disclosure",
"entry": "call",
"inputs": {"amount": "invalid"},
"verdict": "allow",
"expected": {"module_starts": 0, "evaluated_amount": null, "approval_requests": 0}
},
{
"id": "resume_consumes_one_credential_for_final_inputs",
"entry": "resume",
"requires_approval": true,
"rewrite_amount": 20,
"verdict": "require_approval",
"expected": {"module_starts": 1, "evaluated_amount": 20, "approval_requests": 1, "approved_amount": 20, "resume_checks": 1}
},
{
"id": "resume_rejects_changed_effective_inputs",
"entry": "resume",
"verdict": "require_approval",
"retry_inputs": {"amount": 20},
"expected": {"module_starts": 0, "evaluated_amount": 20, "approval_requests": 1, "approved_amount": 10, "resume_checks": 1, "error_code": "APPROVAL_DENIED"}
}
]
}
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ my-project/

## 5. Extension Points

apcore provides a formal `ExtensionManager` API for managing pluggable extension points. The six built-in extension points are: `discoverer`, `middleware`, `acl`, `span_exporter`, `module_validator`, and `approval_handler`.
apcore provides `ExtensionManager` for pluggable extension points. The built-in points are `discoverer`, `middleware`, `acl`, `span_exporter`, `module_validator`, `approval_handler`, and `policy_evaluator`.

### 5.1 ExtensionManager API

Expand Down
19 changes: 18 additions & 1 deletion docs/features/approval-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: "Approval gate at Executor Step 5: fires on the governance union, p

## Overview

The Approval System decides whether a particular invocation needs sign-off before it runs, and asks an `ApprovalHandler` for that sign-off at **Step 5** of the execution pipeline — after ACL enforcement (Step 4) and before the Middleware Before Chain (Step 6).
The Approval System decides whether a particular invocation needs sign-off before it runs. By default, the Executor asks an `ApprovalHandler` for sign-off at **Step 5**, after ACL enforcement and before before middleware.

The gate considers the module's own flags, the registry's declared annotations, the platform's execution policy, and the [ACL decision](./acl-system.md) for the invocation. [Execution Policy](#execution-policy) defines how these sources combine.

Expand Down Expand Up @@ -48,6 +48,23 @@ An exception raised by the handler itself propagates unchanged; it is not conver

To observe which parts of the gate are live on an executor, read [`governance_state()`](./core-executor.md#governance-state-api) — `builtin_approval_gate_wired`, `approval_handler_configured` and `policy_strict` are reported separately ([PROTOCOL_SPEC §6.6.5](../spec/protocol-spec.md#665-governance-state-query)). `Executor.validate()` reports the governance-effective `requires_approval` for a call, the same verdict the gate will enforce (§7.9.5).

### Policy on validated execution arguments

A host can install a `PolicyEvaluator` on an Executor directly or through the
`policy_evaluator` extension point. The evaluator can allow the call, deny it, or
require approval. It receives the selected module version and detached inputs
after before middleware and validation. With this extension enabled, the
Executor combines the existing and evaluator approval requirements and asks the
handler once for the actual execution inputs. Before middleware in this assembly
performs trusted transformations without approval-dependent side effects.

Preflight evaluates its own validated inputs and reports approval requirements.
The actual call evaluates again before dispatch. A denied policy blocks ordinary
execution and stream startup. A final-scope pending credential can be resumed
only through a handler that advertises final-scope support and checks the
principal, caller, target, selected version, and argument digest. See the
[post-validation policy contract](../spec/protocol-spec.md#741-post-validation-policy).

### Startup Approval Report

After registering modules and configuring the executor, call its startup report to list module IDs that declare `requires_approval` without an effective built-in approval gate.
Expand Down
8 changes: 8 additions & 0 deletions docs/features/execution-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ A trace is process-local. `call_with_trace()` returns it; a `PipelineStepError`

### The standard pipeline

An Executor with a `PolicyEvaluator` runs `post_validation_policy` after input
validation and before execution or producer startup. This opt-in gate evaluates
the validated execution snapshot and enforces the combined approval requirement.
Install it with the built-in `standard` or `performance` strategy to retain the
validation and dispatch boundaries it depends on.
The [post-validation policy contract](../spec/protocol-spec.md#741-post-validation-policy)
describes the supported strategy boundary and preflight behavior.

| # | Step | Core | pure | removable | replaceable | What it does |
|---|---|---|---|---|---|---|
| 1 | `context_creation` | yes | yes | no | no | Create or inherit the execution context; set the global deadline. |
Expand Down
17 changes: 10 additions & 7 deletions docs/features/extension-system.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: "ExtensionManager wiring named extension points (discoverer, middleware, acl, span_exporter, module_validator, approval_handler) into Registry and Executor, with cardinality/type checks."
description: "ExtensionManager wiring named extension points into Registry and Executor, with cardinality and type checks."
---

# Extension System
Expand Down Expand Up @@ -41,6 +41,7 @@ The Extension System provides a pluggable architecture for customizing and exten
| `span_exporter` | Yes | SpanExporter protocol | Tracing span exporter |
| `module_validator` | No | ModuleValidator protocol | Custom module validation |
| `approval_handler` | No | ApprovalHandler protocol | Approval gate handler |
| `policy_evaluator` | No | PolicyEvaluator protocol | Optional policy over validated execution arguments |

### ExtensionPoint

Expand Down Expand Up @@ -171,8 +172,9 @@ When `apply(registry, executor)` is called, the manager performs the following i
2. **Module Validator** → `registry.set_validator(ext)` — replaces the default module validator.
3. **ACL** → `executor.set_acl(ext)` — replaces the executor's ACL provider.
4. **Approval Handler** → `executor.set_approval_handler(ext)` — replaces the executor's approval handler.
5. **Middleware** → `executor.use(mw)` for each registered middleware — appends to the middleware chain.
6. **Span Exporters** → Locates the `TracingMiddleware` already in the executor's middleware chain and sets its exporter:
5. **Policy Evaluator** → `executor.set_policy_evaluator(ext)` — enables [policy on validated arguments](../spec/protocol-spec.md#741-post-validation-policy).
6. **Middleware** → `executor.use(mw)` for each registered middleware — appends to the middleware chain.
7. **Span Exporters** → Locates the `TracingMiddleware` already in the executor's middleware chain and sets its exporter:
- If a single exporter is registered, it is set directly.
- If multiple exporters are registered, they are wrapped in a composite exporter that delegates to all of them. A failure in one exporter is logged and does not affect the others.
- If the chain has no `TracingMiddleware`, a warning is logged and the exporters are not applied — `apply` does not add one.
Expand Down Expand Up @@ -272,21 +274,22 @@ Rust, where the manager owns its extensions, that path is

### Inputs
- `registry` (Registry, required) — registry to wire extensions into (discoverer, module_validator)
- `executor` (Executor, required) — executor to wire extensions into (acl, approval_handler, middleware, span_exporter)
- `executor` (Executor, required) — executor to wire extensions into (acl, approval_handler, policy_evaluator, middleware, span_exporter)

### Errors
- Errors raised by the Registry / Executor setters propagate (Rust: `Err(ModuleError)`, e.g. a rejected middleware). A registered span exporter with no `TracingMiddleware` in the chain is **not** an error: it is logged as a warning and skipped.

### Returns
- On success: void/None/() — all registered extensions wired in the documented order (discoverer → module_validator → acl → approval_handler → middleware chain → span exporters)
- On success: void/None/() — all registered extensions wired in the documented order (discoverer → module_validator → acl → approval_handler → policy_evaluator → middleware chain → span exporters)

### Side Effects (ordered)
1. `registry.set_discoverer(ext)` if discoverer registered
2. `registry.set_validator(ext)` if module_validator registered
3. `executor.set_acl(ext)` if acl registered
4. `executor.set_approval_handler(ext)` if approval_handler registered
5. `executor.use(mw)` for each middleware in registration order
6. Locate `TracingMiddleware` in the executor chain; set a single exporter directly or wrap several in a composite exporter; warn and skip if there is none
5. `executor.set_policy_evaluator(ext)` if policy_evaluator registered
6. `executor.use(mw)` for each middleware in registration order
7. Locate `TracingMiddleware` in the executor chain; set a single exporter directly or wrap several in a composite exporter; warn and skip if there is none

### Postconditions

Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ A schema makes a capability contract machine-readable and validatable. It does n

| Component | Package | Stable | In development |
|---|---|---|---|
| Protocol specification | [protocol-spec.md](spec/protocol-spec.md) | `1.66.0` | `2.0.0` (draft) |
| Python SDK | `apcore` | `0.33.0` | `1.0.0a2` |
| TypeScript SDK | `apcore-js` | `0.33.0` | `1.0.0-alpha.2` |
| Rust SDK | `apcore` | `0.33.0` | `1.0.0-alpha.2` |
| Protocol specification | [protocol-spec.md](spec/protocol-spec.md) | `1.66.0` | `2.0.0` (draft revision 2) |
| Python SDK | `apcore` | `0.33.0` | `1.0.0a3` |
| TypeScript SDK | `apcore-js` | `0.33.0` | `1.0.0-alpha.3` |
| Rust SDK | `apcore` | `0.33.0` | `1.0.0-alpha.3` |

The protocol `2.0.0` draft defines the contract for the SDK `1.0.0` release line. The three core SDKs share that 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
9 changes: 5 additions & 4 deletions docs/spec/algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ Steps:
|------|------|------|
| `manager` | `ExtensionManager` | The registered extensions, keyed by extension point name |
| `registry` | `Registry` | Receives `discoverer` and `module_validator` |
| `executor` | `Executor` | Receives `acl`, `approval_handler`, `middleware` and `span_exporter` |
| `executor` | `Executor` | Receives `acl`, `approval_handler`, `policy_evaluator`, `middleware` and `span_exporter` |

**Output:**

Expand All @@ -1263,8 +1263,9 @@ Steps:
2. If manager holds a module_validator → registry.set_validator(it)
3. If manager holds an acl → executor.set_acl(it)
4. If manager holds an approval_handler → executor.set_approval_handler(it)
5. For each middleware, in registration order → executor.use(it)
6. If one or more span_exporters are registered → set them (composed into one
5. If manager holds a policy_evaluator → executor.set_policy_evaluator(it)
6. For each middleware, in registration order → executor.use(it)
7. If one or more span_exporters are registered → set them (composed into one
exporter when there are several) on the tracing middleware already in the
executor's chain; when the chain has none, log a warning and install nothing
```
Expand All @@ -1278,7 +1279,7 @@ Steps:

**Implementation Notes:**

- The six extension point names are `discoverer`, `middleware`, `acl`, `span_exporter`, `module_validator`, `approval_handler` (protocol-spec §11.3). A single-valued point holds one implementation and a later registration replaces it; `middleware` and `span_exporter` are multi-valued.
- A single-valued point holds one implementation and a later registration replaces it. `middleware` and `span_exporter` are multi-valued. The built-in points are listed in protocol-spec §11.3.
- There is no priority ordering among implementations of one point, no `first_success` / `all` / `fallback` strategy, and no registration from `apcore.yaml` (D-143).

---
Expand Down
Loading
Loading