| 1 |
<?php |
| 2 |
/** |
| 3 |
* Desktop Mode — Agents module bootstrap. |
| 4 |
* |
| 5 |
* Agents are durable workers that live on the site as real WordPress |
| 6 |
* users and act through the WordPress Abilities API under their own |
| 7 |
* role and capabilities. Three layers: |
| 8 |
* |
| 9 |
* - Guard — the marker meta, the agent test, and every login / |
| 10 |
* session block → guard.php (ALWAYS loaded) |
| 11 |
* - Identity — the synthetic `wp_users` row itself → identity.php |
| 12 |
* - Definition — everything else (system prompt, description, ability |
| 13 |
* allowlist, triggers, model override, rate limit) as |
| 14 |
* user meta on that row → store.php |
| 15 |
* |
| 16 |
* Plus the abilities bridge + runner (runner.php), a REST surface at |
| 17 |
* `/desktop-mode/v1/agents` (rest.php), privacy hooks (privacy.php), |
| 18 |
* the "Agent chat" native window (run-window.php), and the Agents |
| 19 |
* section inside the site folder (my-wordpress.php). |
| 20 |
* |
| 21 |
* The module is opt-in behind the `agents` extended option — while |
| 22 |
* off, no user-meta registration, no REST routes, no window, no |
| 23 |
* site-folder entity. The one exception is guard.php: see below. |
| 24 |
* |
| 25 |
* @package WPDesktopMode |
| 26 |
*/ |
| 27 |
|
| 28 |
defined( 'ABSPATH' ) || exit; |
| 29 |
|
| 30 |
/** |
| 31 |
* The authentication guard loads unconditionally, ahead of the feature |
| 32 |
* flag. Disabling the Agents framework does not delete the agent user |
| 33 |
* rows, and an agent row whose login blocks unloaded with the feature |
| 34 |
* would accept application passwords and password resets again. The |
| 35 |
* blocks are a property of the rows, not of the feature. |
| 36 |
*/ |
| 37 |
require_once DESKTOP_MODE_DIR . 'includes/agents/guard.php'; |
| 38 |
|
| 39 |
/** |
| 40 |
* Whether the Agents framework is enabled site-wide. |
| 41 |
* |
| 42 |
* Backed by the `agents` key of the extended options bundle |
| 43 |
* (`desktop_mode_get_extended_options()`), default off — opt-in. |
| 44 |
* |
| 45 |
* @return bool |
| 46 |
*/ |
| 47 |
function desktop_mode_agents_enabled() { |
| 48 |
$options = desktop_mode_get_extended_options(); |
| 49 |
$enabled = ! empty( $options['agents'] ); |
| 50 |
|
| 51 |
/** |
| 52 |
* Filters whether the Agents framework is enabled site-wide. |
| 53 |
* |
| 54 |
* Runs on `plugins_loaded` (priority 5) to decide whether the |
| 55 |
* agents module loads at all, and again at runtime wherever the |
| 56 |
* enabled state is consulted. |
| 57 |
* |
| 58 |
* @param bool $enabled Whether the Agents framework is enabled. |
| 59 |
*/ |
| 60 |
return (bool) apply_filters( 'desktop_mode_agents_enabled', $enabled ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Loads the agents module when the framework is enabled. |
| 65 |
* |
| 66 |
* @access private |
| 67 |
*/ |
| 68 |
function desktop_mode_agents_load() { |
| 69 |
if ( ! desktop_mode_agents_enabled() ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
require_once DESKTOP_MODE_DIR . 'includes/agents/store.php'; |
| 74 |
require_once DESKTOP_MODE_DIR . 'includes/agents/defaults.php'; |
| 75 |
require_once DESKTOP_MODE_DIR . 'includes/agents/identity.php'; |
| 76 |
require_once DESKTOP_MODE_DIR . 'includes/agents/abilities.php'; |
| 77 |
require_once DESKTOP_MODE_DIR . 'includes/agents/runner.php'; |
| 78 |
require_once DESKTOP_MODE_DIR . 'includes/agents/rest.php'; |
| 79 |
require_once DESKTOP_MODE_DIR . 'includes/agents/conversations.php'; |
| 80 |
require_once DESKTOP_MODE_DIR . 'includes/agents/privacy.php'; |
| 81 |
require_once DESKTOP_MODE_DIR . 'includes/agents/run-window.php'; |
| 82 |
require_once DESKTOP_MODE_DIR . 'includes/agents/my-wordpress.php'; |
| 83 |
} |
| 84 |
add_action( 'plugins_loaded', 'desktop_mode_agents_load', 5 ); |
| 85 |
|