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 -19 0.9.81.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 // ---------------------------------------------------------------------------
@@ -36,9 +45,9 @@
36 45 * booleans that drive the comments-window spam score.
37 46 *
38 47 * @return array
39 48 */
40 -function desktop_mode_ai_schema_comment() {
49 +function openstation_ai_schema_comment() {
41 50 $schema = array(
42 51 'type' => 'object',
43 52 'additionalProperties' => false,
44 53 'required' => array( 'topic', 'ai_summary', 'harmful', 'spam' ),
@@ -66,9 +75,9 @@
66 75 * Filters the JSON Schema used for comment AI analysis.
67 76 *
68 77 * @param array $schema The JSON Schema array.
69 78 */
70 - return (array) apply_filters( 'desktop_mode_ai_schema_comment', $schema );
79 + return (array) apply_filters( 'openstation_ai_schema_comment', $schema );
71 80 }
72 81
73 82 // ---------------------------------------------------------------------------
74 83 // Prompt builders
@@ -82,13 +91,13 @@
82 91 *
83 92 * @param WP_Comment $comment
84 93 * @return array Chat messages array.
85 94 */
86 -function desktop_mode_ai_messages_for_comment( WP_Comment $comment ) {
95 +function openstation_ai_messages_for_comment( WP_Comment $comment ) {
87 96 $text = wp_strip_all_tags( $comment->comment_content );
88 - $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 );
89 98
90 - $user_text = "Analyze the following WordPress comment.\n\n";
99 + $user_text = "Analyze the following WordPress comment.\n\n";
91 100 $user_text .= "Comment:\n{$text}\n\n";
92 101
93 102 // Give the model post context so it can evaluate relevance (spam).
94 103 $post_id = (int) $comment->comment_post_ID;
@@ -102,9 +111,9 @@
102 111 $user_text .= "\n\nClassification rules:\n";
103 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";
104 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";
105 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";
106 - $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.';
107 116
108 117 /**
109 118 * Filters the user message sent to the provider for comment analysis.
110 119 *
@@ -110,9 +119,9 @@
110 119 *
111 120 * @param string $user_text The composed user message.
112 121 * @param WP_Comment $comment The comment being analyzed.
113 122 */
114 - $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 );
115 124
116 125 return array(
117 126 array(
118 127 'role' => 'system',
@@ -140,9 +149,9 @@
140 149 * @param int $entity_id Comment ID.
141 150 * @param array $analysis The structured output array from the provider.
142 151 * @return bool
143 152 */
144 -function desktop_mode_ai_save_meta( $entity_type, $entity_id, array $analysis ) {
153 +function openstation_ai_save_meta( $entity_type, $entity_id, array $analysis ) {
145 154 $entity_id = (int) $entity_id;
146 155 if ( $entity_id <= 0 || 'comment' !== $entity_type ) {
147 156 return false;
148 157 }
@@ -149,15 +158,15 @@
149 158
150 159 // Stamp when the analysis was performed so consumers can detect staleness.
151 160 $analysis['analyzed_at'] = time();
152 161
153 - 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 );
154 163 }
155 164
156 165 /**
157 166 * Retrieves a previously saved comment AI analysis, or null if none exists.
158 167 *
159 - * Only `'comment'` is supported (see {@see desktop_mode_ai_save_meta}); any
168 + * Only `'comment'` is supported (see {@see openstation_ai_save_meta}); any
160 169 * other `$entity_type` returns null.
161 170 *
162 171 * @param string $entity_type Only `'comment'` is supported.
163 172 * @param int $entity_id Comment ID.
@@ -162,14 +171,14 @@
162 171 * @param string $entity_type Only `'comment'` is supported.
163 172 * @param int $entity_id Comment ID.
164 173 * @return array|null
165 174 */
166 -function desktop_mode_ai_get_meta( $entity_type, $entity_id ) {
175 +function openstation_ai_get_meta( $entity_type, $entity_id ) {
167 176 $entity_id = (int) $entity_id;
168 177 if ( $entity_id <= 0 || 'comment' !== $entity_type ) {
169 178 return null;
170 179 }
171 180
172 - $raw = get_comment_meta( $entity_id, DESKTOP_MODE_AI_META_KEY, true );
181 + $raw = get_comment_meta( $entity_id, OPENSTATION_AI_META_KEY, true );
173 182
174 183 return is_array( $raw ) && ! empty( $raw ) ? $raw : null;
175 184 }