> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Automation Rule Copilot — Integration

> Feature ID: FW-51 Status: \U0001F4CB Specification -automation-rule-copilot.md Last Updated: 2026-03-20

**Feature ID:** FW-51\
**Status:** 📋 Specification\
**Spec:** [FW-51-automation-rule-copilot.md](../../../specs/fw/archive/FW-51-automation-rule-copilot.md)\
**Last Updated:** 2026-03-20

***

## Overview

FW-51 adds natural-language assistance for drafting automation rules. It extends FW-03 using Platform AI (PF-27) only—no new database tables. Suggestions apply to existing `fw_automation_rules` and `fw_automation_actions` under existing RLS and permissions.

***

## Integration Points (from Spec)

| Dependency                     | Pattern                                                   | Purpose                                                                                                            |
| ------------------------------ | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| PF-27 (Platform AI)            | Platform Layer (`@/platform/ai`, `useAIStructuredOutput`) | Structured rule suggestions; module context `module: 'fw', feature: 'automation-rule-copilot'`; no PHI in prompts. |
| PF-10 (Notifications)          | Platform dependency                                       | Suggested actions may use `create_notification` and PF-10 delivery paths.                                          |
| FW-03 (Automation Engine)      | Intra-core                                                | Rule builder UI, rule persistence, execution semantics.                                                            |
| FW-44 (AI Form Building)       | Pattern alignment                                         | Reuse prompts/schema/hook/UI patterns where practical.                                                             |
| FW-50 (NL Workflow Generation) | Pattern alignment                                         | Shared AI infrastructure and UX patterns for “describe → preview → apply.”                                         |

***

## Event / API Contracts

* **No new domain events** for FW-51 Phase 1.
* **AI invocation:** Existing Platform AI / `ai-assistant` path used by `useAIStructuredOutput` (same as FW-44/FW-50). Request/response shapes are defined by the feature Zod schema in FW code; tenant and auth follow PF-27 standards.
* **Apply mutations:** Transactional `SECURITY DEFINER` RPC (`fw_apply_rule_with_actions`) on `fw_automation_rules` / `fw_automation_actions` with `organization_id` enforced inside the function. Existing RLS still applies for non-RPC reads.

***

## Security and Tenant Isolation

* Suggest and apply gated by existing automation-rule edit permissions; `organization_id` enforced on all writes.
* Prompts: rule name + purpose description only; do not send existing rule payloads that could contain PHI/PII.
* Audit: log apply events with counts and metadata only (see spec)—no user description in audit plain text.

### Permissions (Phase 1)

* No new `pf_module_permissions` rows. Use the same gates as Automation Rule Builder; spec references `fw.automations.admin` (`FW_PERMISSIONS.AUTOMATIONS_ADMIN`) as the canonical automation admin key—keep UI consistent with builder when implementing.

***

## Related Docs

* [CROSS\_CORE\_INTEGRATIONS.md](./CROSS_CORE_INTEGRATIONS.md)
* [PLATFORM\_INTEGRATION\_LAYERS.md](./PLATFORM_INTEGRATION_LAYERS.md)
* [FW-03-automation-engine.md](../../../specs/fw/archive/FW-03-automation-engine.md)
