PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
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
← All changes | includes/ai-copilot/analysis.php +28 -31 0.9.51.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — AI Copilot analysis: prompts, schemas, meta storage.
3 + * OpenStation — AI Copilot analysis: prompts, schemas, meta storage.
4 4 *
5 5 * This module owns:
6 6 * - The JSON Schema for comment analysis (filterable).
7 7 * - The prompt builder that converts a comment into a chat message array.
@@ -7,24 +7,33 @@
7 7 * - The prompt builder that converts a comment into a chat message array.
8 8 * - Meta read/write helpers so the job callback never touches meta keys
9 9 * directly; the key name lives in one place.
10 10 *
11 - * Comment analysis is the only auto-analysis the copilot performs (it feeds
12 - * the comments-window spam score). Posts, pages, and terms are not analyzed.
11 + * Nothing is analyzed automatically. Comment analysis runs on demand only,
12 + * through the `desktop-mode/analyze-comment` ability; posts, pages and terms
13 + * are not analyzed at all.
13 14 *
14 15 * Meta key: `_desktop_mode_ai_analysis` (prefixed underscore → hidden from
15 16 * the Custom Fields UI by default).
16 17 *
17 - * @package WPDesktopMode
18 + * @package OpenStation
18 19 */
19 20
20 21 defined( 'ABSPATH' ) || exit;
21 22
22 -/** Meta key used to store the per-comment AI analysis. */
23 -const DESKTOP_MODE_AI_META_KEY = '_desktop_mode_ai_analysis';
23 +/**
24 + * Meta key used to store the per-comment AI analysis.
25 + *
26 + * The VALUE keeps its pre-rebrand spelling on purpose: it is a
27 + * persisted or externally-visible identifier, so renaming it would
28 + * orphan data already written by live installs (or break a live
29 + * URL). The mismatch between this constant's name and its value is
30 + * deliberate — it is NOT a half-finished rename.
31 + */
32 +const OPENSTATION_AI_META_KEY = '_desktop_mode_ai_analysis';
24 33
25 34 /** Max characters of comment text sent to the provider. */
26 -const DESKTOP_MODE_AI_CONTENT_MAX_CHARS = 3000;
35 +const OPENSTATION_AI_CONTENT_MAX_CHARS = 3000;
27 36
28 37 // ---------------------------------------------------------------------------
29 38 // JSON Schemas
30 39 // ---------------------------------------------------------------------------
@@ -34,13 +43,11 @@
34 43 *
35 44 * Captures a topic label and summary plus the `harmful` and `spam`
36 45 * booleans that drive the comments-window spam score.
37 46 *
38 - * @since 0.5.0
39 - *
40 47 * @return array
41 48 */
42 -function desktop_mode_ai_schema_comment() {
49 +function openstation_ai_schema_comment() {
43 50 $schema = array(
44 51 'type' => 'object',
45 52 'additionalProperties' => false,
46 53 'required' => array( 'topic', 'ai_summary', 'harmful', 'spam' ),
@@ -66,13 +73,11 @@
66 73
67 74 /**
68 75 * Filters the JSON Schema used for comment AI analysis.
69 76 *
70 - * @since 0.5.0
71 - *
72 77 * @param array $schema The JSON Schema array.
73 78 */
74 - return (array) apply_filters( 'desktop_mode_ai_schema_comment', $schema );
79 + return (array) apply_filters( 'openstation_ai_schema_comment', $schema );
75 80 }
76 81
77 82 // ---------------------------------------------------------------------------
78 83 // Prompt builders
@@ -83,18 +88,16 @@
83 88 *
84 89 * The parent post's title is included so the model can judge `spam`
85 90 * (off-topic detection requires knowing what the post is about).
86 91 *
87 - * @since 0.5.0
88 - *
89 92 * @param WP_Comment $comment
90 93 * @return array Chat messages array.
91 94 */
92 -function desktop_mode_ai_messages_for_comment( WP_Comment $comment ) {
95 +function openstation_ai_messages_for_comment( WP_Comment $comment ) {
93 96 $text = wp_strip_all_tags( $comment->comment_content );
94 - $text = mb_substr( preg_replace( '/\s+/', ' ', trim( $text ) ), 0, DESKTOP_MODE_AI_CONTENT_MAX_CHARS );
97 + $text = mb_substr( preg_replace( '/\s+/', ' ', trim( $text ) ), 0, OPENSTATION_AI_CONTENT_MAX_CHARS );
95 98
96 - $user_text = "Analyze the following WordPress comment.\n\n";
99 + $user_text = "Analyze the following WordPress comment.\n\n";
97 100 $user_text .= "Comment:\n{$text}\n\n";
98 101
99 102 // Give the model post context so it can evaluate relevance (spam).
100 103 $post_id = (int) $comment->comment_post_ID;
@@ -108,19 +111,17 @@
108 111 $user_text .= "\n\nClassification rules:\n";
109 112 $user_text .= "- `harmful = true`: the comment is hostile, insulting, or demeaning — e.g. attacks on the author's competence, aggressive rhetoric, threats, hate speech. Tone matters: an angry rant calling the article \"garbage\" is harmful even without explicit language.\n";
110 113 $user_text .= "- `spam = true`: the comment is promotional or off-topic — e.g. commercial links, ALL CAPS sales copy, \"CLICK HERE\" / \"BOOK NOW\", generic praise unrelated to the post.\n";
111 114 $user_text .= "- These are INDEPENDENT flags. A hostile but on-topic comment is harmful=true, spam=false. A promotional but politely worded comment is spam=true, harmful=false. Both can be true simultaneously.\n";
112 - $user_text .= "- The `topic` and `ai_summary` fields MUST capture the tone and sentiment so that search queries like \"negative comment\", \"angry reader\", or \"spam\" return the correct results.";
115 + $user_text .= '- The `topic` and `ai_summary` fields MUST capture the tone and sentiment so that search queries like "negative comment", "angry reader", or "spam" return the correct results.';
113 116
114 117 /**
115 118 * Filters the user message sent to the provider for comment analysis.
116 119 *
117 - * @since 0.5.0
118 - *
119 120 * @param string $user_text The composed user message.
120 121 * @param WP_Comment $comment The comment being analyzed.
121 122 */
122 - $user_text = (string) apply_filters( 'desktop_mode_ai_comment_prompt', $user_text, $comment );
123 + $user_text = (string) apply_filters( 'openstation_ai_comment_prompt', $user_text, $comment );
123 124
124 125 return array(
125 126 array(
126 127 'role' => 'system',
@@ -143,16 +144,14 @@
143 144 * Comments are the only entity the copilot analyzes. The `$entity_type`
144 145 * parameter is retained for call-site/signature stability but only
145 146 * `'comment'` is supported — any other value is a no-op that returns false.
146 147 *
147 - * @since 0.5.0
148 - *
149 148 * @param string $entity_type Only `'comment'` is supported.
150 149 * @param int $entity_id Comment ID.
151 150 * @param array $analysis The structured output array from the provider.
152 151 * @return bool
153 152 */
154 -function desktop_mode_ai_save_meta( $entity_type, $entity_id, array $analysis ) {
153 +function openstation_ai_save_meta( $entity_type, $entity_id, array $analysis ) {
155 154 $entity_id = (int) $entity_id;
156 155 if ( $entity_id <= 0 || 'comment' !== $entity_type ) {
157 156 return false;
158 157 }
@@ -159,29 +158,27 @@
159 158
160 159 // Stamp when the analysis was performed so consumers can detect staleness.
161 160 $analysis['analyzed_at'] = time();
162 161
163 - return false !== update_comment_meta( $entity_id, DESKTOP_MODE_AI_META_KEY, $analysis );
162 + return false !== update_comment_meta( $entity_id, OPENSTATION_AI_META_KEY, $analysis );
164 163 }
165 164
166 165 /**
167 166 * Retrieves a previously saved comment AI analysis, or null if none exists.
168 167 *
169 - * Only `'comment'` is supported (see {@see desktop_mode_ai_save_meta}); any
168 + * Only `'comment'` is supported (see {@see openstation_ai_save_meta}); any
170 169 * other `$entity_type` returns null.
171 170 *
172 - * @since 0.5.0
173 - *
174 171 * @param string $entity_type Only `'comment'` is supported.
175 172 * @param int $entity_id Comment ID.
176 173 * @return array|null
177 174 */
178 -function desktop_mode_ai_get_meta( $entity_type, $entity_id ) {
175 +function openstation_ai_get_meta( $entity_type, $entity_id ) {
179 176 $entity_id = (int) $entity_id;
180 177 if ( $entity_id <= 0 || 'comment' !== $entity_type ) {
181 178 return null;
182 179 }
183 180
184 - $raw = get_comment_meta( $entity_id, DESKTOP_MODE_AI_META_KEY, true );
181 + $raw = get_comment_meta( $entity_id, OPENSTATION_AI_META_KEY, true );
185 182
186 183 return is_array( $raw ) && ! empty( $raw ) ? $raw : null;
187 184 }