PolicyGate
Policy gate for tool authorization. Checks scopes, channel policies, and tool permissions. Supports dynamic rules via PolicyRuleProviderInterface (e.g. the host's Doctrine-backed provider). **Fail-closed on unknown channels.** A channel nobody registered no longer inherits the laxest possible policy (the old `?? []`, under which `require_auth` defaulted to false and an anonymous caller sailed through). An unregistered channel now falls back to {@see self::UNKNOWN_CHANNEL_POLICY} — `require_auth: true`, no `allow_all` — and the gate emits a learnable warning naming it. An unknown channel is treated as untrusted, never as the most permissive one.
PolicyGate::__construct()
public function __construct(Psr\Log\LoggerInterface $logger = new NullLogger()):Parameters
| Name | Type | Description |
|---|---|---|
| $logger | LoggerInterface | sink for the learnable warning emitted when an unregistered channel falls back to the fail-closed policy — defaults to a {@see NullLogger} so existing `new PolicyGate()` callers keep working unchanged |
PolicyGate::setRuleProvider()
public function setRuleProvider(Milpa\ToolRuntime\Contracts\PolicyRuleProviderInterface $provider): voidSet the policy rule provider for database-driven rules.
Parameters
| Name | Type | Description |
|---|---|---|
| $provider | Milpa\ToolRuntime\Contracts\PolicyRuleProviderInterface |
PolicyGate::getRuleProvider()
public function getRuleProvider(): ?Milpa\ToolRuntime\Contracts\PolicyRuleProviderInterfaceGet the current rule provider (if set).
PolicyGate::channelPolicy()
public function channelPolicy(string $channel): arrayLa channel policy efectiva de un canal (lectura pura para la inspección, ADR#13) — delega en el mismo {@see policyFor()} que usa authorize()/requiresConfirmation(), así el plan renderea la MISMA política que el runtime consulta, con el mismo fail-closed para canales desconocidos.
Parameters
| Name | Type | Description |
|---|---|---|
| $channel | string |
PolicyGate::hasRuleProvider()
public function hasRuleProvider(): bool¿Hay un provider de reglas DB conectado? Lectura pura para la inspección (ADR#13).
PolicyGate::authorize()
public function authorize(Milpa\ToolRuntime\Contracts\ToolContext $ctx, Milpa\ToolRuntime\ToolDefinition $tool): Milpa\ToolRuntime\Policy\AuthorizationResultAuthorize a tool call.
Parameters
| Name | Type | Description |
|---|---|---|
| $ctx | ToolContext | The execution context |
| $tool | ToolDefinition | The tool being called |
PolicyGate::requiresConfirmation()
public function requiresConfirmation(Milpa\ToolRuntime\Contracts\ToolContext $ctx, Milpa\ToolRuntime\ToolDefinition $tool): boolCheck if confirmation is required for this context + tool.
Parameters
| Name | Type | Description |
|---|---|---|
| $ctx | Milpa\ToolRuntime\Contracts\ToolContext | |
| $tool | Milpa\ToolRuntime\ToolDefinition |
PolicyGate::setChannelPolicy()
public function setChannelPolicy(string $channel, array $policy): voidSet custom channel policy.
Parameters
| Name | Type | Description |
|---|---|---|
| $channel | string | |
| $policy | array<string, mixed> |