PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.1
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.1
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / includes / agents / bootstrap.php

bootstrap.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.1, at includes/agents/bootstrap.php

166 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — 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 WP Explorer (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 and no chat window.
23 * Two files load regardless of the flag: guard.php and
24 * my-wordpress.php. See below for why.
25 *
26 * @package OpenStation
27 */
28
29 defined( 'ABSPATH' ) || exit;
30
31 /**
32 * The authentication guard loads unconditionally, ahead of the feature
33 * flag. Disabling the Agents framework does not delete the agent user
34 * rows, and an agent row whose login blocks unloaded with the feature
35 * would accept application passwords and password resets again. The
36 * blocks are a property of the rows, not of the feature.
37 */
38 require_once OPENSTATION_DIR . 'includes/agents/guard.php';
39
40 // ---------------------------------------------------------------------------
41 // Always-available helpers
42 //
43 // The capability helpers and the avatar URL live here rather than in
44 // rest.php / identity.php because the WP Explorer integration needs
45 // all four to build its entity descriptor, and it now loads while the
46 // feature flag is off — when neither of those files is loaded.
47 // ---------------------------------------------------------------------------
48
49 /**
50 * URL of the bot avatar as a real static file.
51 *
52 * The avatar MUST be a file URL, not the data URI: consumers routinely
53 * run avatar URLs through `esc_url()` (wp-admin's `get_avatar()`, the
54 * desktop user-tile renderer), and `data` is not in
55 * `wp_allowed_protocols()` — the data URI silently becomes an empty
56 * string and the avatar renders broken.
57 *
58 * @return string
59 */
60 function openstation_agent_avatar_url() {
61 return OPENSTATION_URL . 'assets/images/agent-avatar.svg';
62 }
63
64 /**
65 * Whether the current user can see agents.
66 *
67 * @return bool
68 */
69 function openstation_agents_user_can_read() {
70 /**
71 * Filter whether the current user can read OpenStation agents.
72 *
73 * @param bool $can Default: `edit_posts` capability.
74 */
75 return (bool) apply_filters( 'openstation_agents_user_can_read', current_user_can( 'edit_posts' ) );
76 }
77
78 /**
79 * Whether the current user can create / edit / delete agents.
80 *
81 * @return bool
82 */
83 function openstation_agents_user_can_manage() {
84 /**
85 * Filter whether the current user can manage OpenStation agents.
86 *
87 * @param bool $can Default: `edit_users` capability.
88 */
89 return (bool) apply_filters( 'openstation_agents_user_can_manage', current_user_can( 'edit_users' ) );
90 }
91
92 /**
93 * Whether the current user can invoke agents.
94 *
95 * @return bool
96 */
97 function openstation_agents_user_can_invoke() {
98 /**
99 * Filter whether the current user can invoke OpenStation agents.
100 *
101 * @param bool $can Default: `edit_posts` capability.
102 */
103 return (bool) apply_filters( 'openstation_agents_user_can_invoke', current_user_can( 'edit_posts' ) );
104 }
105
106 /**
107 * Whether the Agents framework is enabled site-wide.
108 *
109 * Backed by the `agents` key of the extended options bundle
110 * (`openstation_get_extended_options()`), default off — opt-in.
111 *
112 * @return bool
113 */
114 function openstation_agents_enabled() {
115 $options = openstation_get_extended_options();
116 $enabled = ! empty( $options['agents'] );
117
118 /**
119 * Filters whether the Agents framework is enabled site-wide.
120 *
121 * Runs on `plugins_loaded` (priority 5) to decide whether the
122 * agents module loads at all, and again at runtime wherever the
123 * enabled state is consulted.
124 *
125 * @param bool $enabled Whether the Agents framework is enabled.
126 */
127 return (bool) apply_filters( 'openstation_agents_enabled', $enabled );
128 }
129
130 /**
131 * The WP Explorer integration also loads unconditionally, so the Agents
132 * section is always discoverable: a site that has never turned the
133 * framework on still shows the tile, and the section explains how to
134 * switch it on instead of hiding the feature from the one person who
135 * could enable it. Everything inside renders inert while the flag is
136 * off — `openstation_agents_my_wordpress_window_args()` ships
137 * `enabled => false`, and the renderer disables every control and skips
138 * every fetch (the REST routes genuinely do not exist while off).
139 *
140 * Loaded after the helpers above, which it needs to build the entity
141 * descriptor and the section config.
142 */
143 require_once OPENSTATION_DIR . 'includes/agents/my-wordpress.php';
144
145 /**
146 * Loads the agents module when the framework is enabled.
147 *
148 * @access private
149 */
150 function openstation_agents_load() {
151 if ( ! openstation_agents_enabled() ) {
152 return;
153 }
154
155 require_once OPENSTATION_DIR . 'includes/agents/store.php';
156 require_once OPENSTATION_DIR . 'includes/agents/defaults.php';
157 require_once OPENSTATION_DIR . 'includes/agents/identity.php';
158 require_once OPENSTATION_DIR . 'includes/agents/abilities.php';
159 require_once OPENSTATION_DIR . 'includes/agents/runner.php';
160 require_once OPENSTATION_DIR . 'includes/agents/rest.php';
161 require_once OPENSTATION_DIR . 'includes/agents/conversations.php';
162 require_once OPENSTATION_DIR . 'includes/agents/privacy.php';
163 require_once OPENSTATION_DIR . 'includes/agents/run-window.php';
164 }
165 add_action( 'plugins_loaded', 'openstation_agents_load', 5 );
166