Merge pull request #5 from southseact-3d/cto-task-ok-so-for-this-app-can-you-change-how-the-prompt-works-by-mo
Refactor WordPress prompt system and add completion signal
This commit is contained in:
@@ -1749,87 +1749,11 @@
|
||||
|
||||
// Load plugin builder prompt from file
|
||||
async function loadPluginPrompt() {
|
||||
try {
|
||||
const response = await fetch('/chat/shopify-builder-prompt.txt');
|
||||
if (response.ok) {
|
||||
builderState.pluginPrompt = await response.text();
|
||||
} else {
|
||||
console.warn('Could not load plugin prompt file, using default');
|
||||
builderState.pluginPrompt = getDefaultPrompt();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error loading plugin prompt file:', error);
|
||||
builderState.pluginPrompt = getDefaultPrompt();
|
||||
}
|
||||
|
||||
// Load subsequent prompt for follow-up messages
|
||||
try {
|
||||
const response = await fetch('/chat/shopify-builder-subsequent-prompt.txt');
|
||||
if (response.ok) {
|
||||
builderState.subsequentPrompt = await response.text();
|
||||
} else {
|
||||
console.warn('Could not load subsequent prompt file, using default');
|
||||
builderState.subsequentPrompt = getDefaultSubsequentPrompt();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error loading subsequent prompt file:', error);
|
||||
builderState.subsequentPrompt = getDefaultSubsequentPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaultPrompt() {
|
||||
return `You are an expert WordPress plugin developer. When asked to build a WordPress plugin, you must create a COMPLETE, FULLY FUNCTIONAL PHP plugin with all necessary files and WordPress integrations.
|
||||
|
||||
Here is the user's request:
|
||||
{{USER_REQUEST}}
|
||||
|
||||
IMPORTANT REQUIREMENTS:
|
||||
1. Create a complete WordPress plugin in PHP following WordPress coding standards
|
||||
2. Include plugin header comment block and proper folder structure
|
||||
3. Register activation/deactivation/uninstall hooks and any required DB migrations
|
||||
4. Provide admin UI using WordPress admin pages, Settings API, or custom blocks as requested
|
||||
5. Add shortcodes or Gutenberg blocks for frontend features where applicable
|
||||
6. Include REST API endpoints or AJAX handlers if the plugin exposes APIs
|
||||
7. Ensure capability checks, nonce protection, sanitization, and escaping for security
|
||||
8. Provide a clear README with installation, activation, and usage instructions
|
||||
|
||||
STRUCTURE TO CREATE:
|
||||
- plugin-name.php (main plugin bootstrap file with header)
|
||||
- includes/ for helper classes and functions
|
||||
- admin/ for admin pages, settings, and menu registration
|
||||
- public/ for frontend templates, shortcodes, and assets
|
||||
- uninstall.php for cleanup
|
||||
- readme.txt and README.md with usage and installation steps
|
||||
- composer.json or package.json only if needed for build tooling
|
||||
|
||||
When building, explain each major step and create all files needed for a production-ready plugin. The plugin should be installable via the WordPress admin and follow WP security best practices.
|
||||
`;
|
||||
}
|
||||
|
||||
function getDefaultSubsequentPrompt() {
|
||||
return `You are continuing to help build a WordPress plugin. Follow the same strict standards as before.
|
||||
|
||||
User's request: {{USER_REQUEST}}
|
||||
|
||||
REMEMBER THESE CRITICAL REQUIREMENTS:
|
||||
1. PHP SYNTAX CHECKING - MUST use \`php -l filename.php\` for every PHP file you create or modify
|
||||
2. After generating code, run \`./scripts/validate-wordpress-plugin.sh <plugin-root-directory>\` to verify all PHP files
|
||||
3. Use {{PLUGIN_SLUG}} prefix for all functions, classes, and CSS classes
|
||||
4. Main plugin file must include WordPress.org update prevention filter
|
||||
5. Plugin header: Plugin URI and Update URI as specified, Author: Plugin Compass
|
||||
6. Complete admin styling with WordPress admin classes (.wrap, .card, .notice, .button, .widefat)
|
||||
7. Complete public styling with responsive design, mobile-first, WCAG 2.1 AA compliance
|
||||
8. Enqueue styles/scripts properly with dependencies
|
||||
9. Security: capability checks, nonce protection, sanitization, escaping
|
||||
10. Compatibility with latest WordPress and WooCommerce
|
||||
|
||||
STYLING REQUIREMENTS:
|
||||
- Admin: WordPress color schemes, proper icons (Dashicons/SVG), responsive design
|
||||
- Public: Modern responsive design, hover states, transitions, high contrast
|
||||
- Both: Clear hierarchy, consistent spacing, accessible
|
||||
|
||||
Never edit files outside the workspace. Be concise and provide complete, production-ready code with full CSS.
|
||||
`;
|
||||
// Since WordPress-specific instructions are now handled by OpenCode system prompts,
|
||||
// we load empty prompts to ensure only the user's text/plan is sent to OpenCode
|
||||
builderState.pluginPrompt = '';
|
||||
builderState.subsequentPrompt = '';
|
||||
console.log('Using OpenCode system prompts for WordPress plugin development');
|
||||
}
|
||||
|
||||
function latestPlanMessage() {
|
||||
|
||||
@@ -3514,15 +3514,15 @@ async function sendMessage() {
|
||||
try {
|
||||
let messageContent = content;
|
||||
|
||||
if (builderState.mode === 'build' && cli === 'opencode' && !content.includes('proceed with build')) {
|
||||
const subsequentPromptTemplate = builderState.subsequentPrompt || '';
|
||||
const userRequest = builderState.lastUserRequest || content;
|
||||
const pluginSlug = (currentSession && currentSession.pluginSlug) || 'plugin-name';
|
||||
const pluginName = (currentSession && currentSession.pluginName) || `Plugin Compass ${(currentSession && currentSession.title) || 'Plugin'}`;
|
||||
const promptWithRequest = subsequentPromptTemplate.replace('{{USER_REQUEST}}', userRequest);
|
||||
const promptWithSlug = promptWithRequest.replace(/{{PLUGIN_SLUG}}/g, pluginSlug).replace(/{{PLUGIN_NAME}}/g, pluginName);
|
||||
messageContent = promptWithSlug + '\n\n' + content;
|
||||
}
|
||||
// if (builderState.mode === 'build' && cli === 'opencode' && !content.includes('proceed with build')) {
|
||||
// const subsequentPromptTemplate = builderState.subsequentPrompt || '';
|
||||
// const userRequest = builderState.lastUserRequest || content;
|
||||
// const pluginSlug = (currentSession && currentSession.pluginSlug) || 'plugin-name';
|
||||
// const pluginName = (currentSession && currentSession.pluginName) || `Plugin Compass ${(currentSession && currentSession.title) || 'Plugin'}`;
|
||||
// const promptWithRequest = subsequentPromptTemplate.replace('{{USER_REQUEST}}', userRequest);
|
||||
// const promptWithSlug = promptWithRequest.replace(/{{PLUGIN_SLUG}}/g, pluginSlug).replace(/{{PLUGIN_NAME}}/g, pluginName);
|
||||
// messageContent = promptWithSlug + '\n\n' + content;
|
||||
// }
|
||||
|
||||
const payload = {
|
||||
content: messageContent,
|
||||
|
||||
@@ -8723,6 +8723,20 @@ async function sendToOpencode({ session, model, content, message, cli, streamCal
|
||||
// Use accumulated text output (partialOutput) since we're using --format json
|
||||
const finalOutput = filterOpencodeStatusMessages(partialOutput || '');
|
||||
|
||||
// Check for completion signal and process it
|
||||
const completionMatch = finalOutput.match(/\s*[COMPLETE]\s*$/i);
|
||||
let processedOutput = finalOutput;
|
||||
if (completionMatch) {
|
||||
// Remove the completion signal from the output
|
||||
processedOutput = finalOutput.slice(0, completionMatch.index).trim();
|
||||
log('OpenCode completion signal detected', {
|
||||
messageId: messageKey,
|
||||
hadCompletionSignal: true,
|
||||
originalLength: finalOutput.length,
|
||||
processedLength: processedOutput.length
|
||||
});
|
||||
}
|
||||
|
||||
// Mark message as done to prevent false "stalled" detection
|
||||
if (message) {
|
||||
message.status = 'done';
|
||||
@@ -8733,7 +8747,7 @@ async function sendToOpencode({ session, model, content, message, cli, streamCal
|
||||
}
|
||||
|
||||
// The reply is the final accumulated output
|
||||
let reply = finalOutput;
|
||||
let reply = processedOutput;
|
||||
|
||||
if (message) {
|
||||
message.partialOutput = finalOutput;
|
||||
|
||||
16637
chat/server.js.backup
Normal file
16637
chat/server.js.backup
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user