Skip to content

Commit 2de89b1

Browse files
ilicfilipSculptor
andcommitted
WIP
Co-authored-by: Sculptor <sculptor@imbue.com>
1 parent cb3ff55 commit 2de89b1

File tree

9 files changed

+1100
-0
lines changed

9 files changed

+1100
-0
lines changed

.distignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ phpcs.xml.dist
1919
phpstan.neon.dist
2020
phpunit.xml.dist
2121
README.md
22+
/third-party/angie/node_modules
23+
/third-party/angie/src
24+
/third-party/angie/tsconfig.json
25+
/third-party/angie/package.json
26+
/third-party/angie/package-lock.json

classes/class-base.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @method \Progress_Planner\Page_Types get_page_types()
1919
* @method \Progress_Planner\Rest\Stats get_rest__stats()
2020
* @method \Progress_Planner\Rest\Tasks get_rest__tasks()
21+
* @method \Progress_Planner\Third_Party\Angie\Integration get_third_party__angie__integration()
2122
* @method \Progress_Planner\Todo get_todo()
2223
* @method \Progress_Planner\Utils\Onboard get_utils__onboard()
2324
* @method \Progress_Planner\Utils\Playground get_utils__playground()
@@ -122,6 +123,9 @@ public function init() {
122123
$this->get_rest__stats();
123124
$this->get_rest__tasks();
124125

126+
// Third-party integrations.
127+
$this->get_third_party__angie__integration();
128+
125129
// Onboarding.
126130
$this->get_utils__onboard();
127131

third-party/angie/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build outputs
5+
dist/
6+
7+
# TypeScript cache
8+
*.tsbuildinfo
9+
10+
# Logs
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
15+
# Environment files
16+
.env
17+
.env.local
18+
19+
# IDE
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~

third-party/angie/README.md

Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
# Angie AI Integration for Progress Planner
2+
3+
This document describes the Angie AI integration for Progress Planner, which provides REST API endpoints and an MCP (Model Context Protocol) server that allow the Angie AI assistant to interact with task recommendations in Progress Planner.
4+
5+
## Overview
6+
7+
The integration enables Angie to:
8+
- List all active tasks (recommendations with `post_status` = `publish`)
9+
- List all completed tasks (recommendations with `post_status` = `trash`)
10+
- Complete tasks, including the "Set blog description" task
11+
12+
## Architecture
13+
14+
The integration consists of two main components:
15+
16+
1. **PHP REST API** (`class-angie.php`): WordPress REST API endpoints for task management
17+
2. **MCP Server** (`src/mcp-server.ts`): TypeScript-based MCP server that bridges Angie AI with the REST API
18+
19+
## Installation
20+
21+
### Prerequisites
22+
23+
1. WordPress site with Progress Planner plugin installed
24+
2. Angie plugin installed from the WordPress plugin repository: https://wordpress.org/plugins/angie/
25+
3. User must be logged in with `manage_options` capability (typically Administrator role)
26+
4. Node.js 20+ and npm for building the MCP server
27+
28+
### Setup
29+
30+
1. **Install Dependencies:**
31+
```bash
32+
cd third-party/angie
33+
npm install
34+
```
35+
36+
2. **Build the MCP Server:**
37+
```bash
38+
npm run build
39+
```
40+
41+
This will compile the TypeScript code and generate `dist/mcp-server.js`.
42+
43+
3. **Development Mode:**
44+
For active development, use watch mode:
45+
```bash
46+
npm run watch
47+
```
48+
49+
The integration is automatically enabled when Progress Planner is active. The MCP server script will be automatically enqueued when the Angie plugin is detected.
50+
51+
## API Endpoints
52+
53+
All endpoints are prefixed with: `/wp-json/progress-planner/v1/angie`
54+
55+
### 1. Get Active Tasks
56+
57+
**Endpoint:** `GET /wp-json/progress-planner/v1/angie/tasks`
58+
59+
**Description:** Returns all active (published) task recommendations.
60+
61+
**Authentication:** Requires logged-in user with `manage_options` capability.
62+
63+
**Response Example:**
64+
```json
65+
{
66+
"success": true,
67+
"count": 3,
68+
"tasks": [
69+
{
70+
"id": "core-blogdescription",
71+
"title": "Set tagline",
72+
"description": "Set the tagline to make your website look more professional.",
73+
"url": "https://example.com/wp-admin/options-general.php?pp-focus-el=core-blogdescription",
74+
"priority": 2,
75+
"status": "active"
76+
},
77+
{
78+
"id": "content-create",
79+
"title": "Create new content",
80+
"description": "Create new content to improve your site.",
81+
"url": "https://example.com/wp-admin/post-new.php",
82+
"priority": 1,
83+
"status": "active"
84+
}
85+
]
86+
}
87+
```
88+
89+
**cURL Example:**
90+
```bash
91+
curl -X GET \
92+
-H "Cookie: wordpress_logged_in_xxxxx=..." \
93+
"https://example.com/wp-json/progress-planner/v1/angie/tasks"
94+
```
95+
96+
### 2. Get Completed Tasks
97+
98+
**Endpoint:** `GET /wp-json/progress-planner/v1/angie/tasks/completed`
99+
100+
**Description:** Returns all completed (trashed) task recommendations.
101+
102+
**Authentication:** Requires logged-in user with `manage_options` capability.
103+
104+
**Response Example:**
105+
```json
106+
{
107+
"success": true,
108+
"count": 5,
109+
"tasks": [
110+
{
111+
"id": "core-blogdescription",
112+
"title": "Set tagline",
113+
"description": "Set the tagline to make your website look more professional.",
114+
"url": "https://example.com/wp-admin/options-general.php?pp-focus-el=core-blogdescription",
115+
"priority": 2,
116+
"status": "completed"
117+
}
118+
]
119+
}
120+
```
121+
122+
**cURL Example:**
123+
```bash
124+
curl -X GET \
125+
-H "Cookie: wordpress_logged_in_xxxxx=..." \
126+
"https://example.com/wp-json/progress-planner/v1/angie/tasks/completed"
127+
```
128+
129+
### 3. Complete a Task
130+
131+
**Endpoint:** `POST /wp-json/progress-planner/v1/angie/tasks/complete`
132+
133+
**Description:** Marks a task as completed. For the "Set blog description" task, it also updates the WordPress tagline.
134+
135+
**Authentication:** Requires logged-in user with `manage_options` capability.
136+
137+
**Parameters:**
138+
- `task_id` (string, required): The ID of the task to complete (e.g., "core-blogdescription")
139+
- `value` (string, optional): For tasks that require a value (like blog description), provide the value here
140+
141+
**Response Example (Blog Description):**
142+
```json
143+
{
144+
"success": true,
145+
"message": "Blog description has been set successfully and the task has been marked as completed.",
146+
"task_id": "core-blogdescription",
147+
"blog_description": "Your new tagline here"
148+
}
149+
```
150+
151+
**Response Example (Generic Task):**
152+
```json
153+
{
154+
"success": true,
155+
"message": "Task \"Create new content\" has been marked as completed.",
156+
"task_id": "content-create"
157+
}
158+
```
159+
160+
**cURL Example:**
161+
```bash
162+
# Complete the blog description task
163+
curl -X POST \
164+
-H "Cookie: wordpress_logged_in_xxxxx=..." \
165+
-H "Content-Type: application/json" \
166+
-d '{"task_id": "core-blogdescription", "value": "My awesome WordPress site"}' \
167+
"https://example.com/wp-json/progress-planner/v1/angie/tasks/complete"
168+
169+
# Complete a generic task
170+
curl -X POST \
171+
-H "Cookie: wordpress_logged_in_xxxxx=..." \
172+
-H "Content-Type: application/json" \
173+
-d '{"task_id": "content-create"}' \
174+
"https://example.com/wp-json/progress-planner/v1/angie/tasks/complete"
175+
```
176+
177+
## Error Responses
178+
179+
### 403 Forbidden
180+
```json
181+
{
182+
"code": "rest_forbidden",
183+
"message": "You do not have permission to access this endpoint.",
184+
"data": {
185+
"status": 403
186+
}
187+
}
188+
```
189+
190+
### 404 Not Found
191+
```json
192+
{
193+
"code": "task_not_found",
194+
"message": "Task with ID \"unknown-task\" not found or already completed.",
195+
"data": {
196+
"status": 404
197+
}
198+
}
199+
```
200+
201+
### 400 Bad Request
202+
```json
203+
{
204+
"code": "missing_value",
205+
"message": "The \"value\" parameter is required to complete the blog description task. Please provide a blog description.",
206+
"data": {
207+
"status": 400
208+
}
209+
}
210+
```
211+
212+
### 500 Internal Server Error
213+
```json
214+
{
215+
"code": "task_completion_error",
216+
"message": "Error message here",
217+
"data": {
218+
"status": 500
219+
}
220+
}
221+
```
222+
223+
## Task IDs
224+
225+
Common task IDs in Progress Planner include:
226+
227+
- `core-blogdescription` - Set the site tagline/blog description
228+
- `content-create` - Create new content
229+
- `content-review` - Review existing content
230+
- `update-core` - Update WordPress core
231+
- `settings-saved` - Configure site settings
232+
- `debug-display` - Disable debug display
233+
234+
To get a complete list of available task IDs, use the "Get Active Tasks" endpoint.
235+
236+
## Implementation Details
237+
238+
### File Structure
239+
240+
- **Main Integration Class:** `/code/classes/rest/class-angie.php`
241+
- **Registration:** The class is automatically instantiated in `/code/classes/class-base.php`
242+
243+
### How It Works
244+
245+
1. **Task Retrieval:** The integration queries the `prpl_recommendations` custom post type using the `Suggested_Tasks_DB` class.
246+
247+
2. **Task Completion:** When a task is completed:
248+
- For the blog description task: Updates the `blogdescription` WordPress option
249+
- For all tasks: Calls the task's `celebrate()` method, which transitions the post status to `pending` (celebration mode) and then to `trash` (completed)
250+
251+
3. **Authentication:** Uses WordPress's built-in authentication system. Requires users to have the `manage_options` capability.
252+
253+
### Task Status Flow
254+
255+
```
256+
publish (active) → pending (celebrating) → trash (completed)
257+
```
258+
259+
## Using with Angie
260+
261+
Once the Angie plugin is installed and activated, it can automatically discover and use these endpoints to help users manage their Progress Planner tasks through natural language interactions.
262+
263+
### Example Angie Interactions
264+
265+
**User:** "What tasks do I have in Progress Planner?"
266+
**Angie:** *Calls GET /angie/tasks and lists active tasks*
267+
268+
**User:** "Set my site tagline to 'Building awesome websites'"
269+
**Angie:** *Calls POST /angie/tasks/complete with task_id=core-blogdescription and value="Building awesome websites"*
270+
271+
**User:** "Show me my completed tasks"
272+
**Angie:** *Calls GET /angie/tasks/completed and displays results*
273+
274+
## Development & Testing
275+
276+
### Testing Endpoints
277+
278+
You can test the endpoints using WordPress REST API testing tools or browser extensions like:
279+
- WP REST API Testing (Chrome/Firefox extension)
280+
- Postman
281+
- Insomnia
282+
- curl (command line)
283+
284+
### Authentication for Testing
285+
286+
To authenticate in testing tools:
287+
1. Log in to WordPress admin in your browser
288+
2. Copy the authentication cookies
289+
3. Include them in your API requests
290+
291+
### Debug Mode
292+
293+
If you encounter issues, enable WordPress debug mode:
294+
295+
```php
296+
// wp-config.php
297+
define('WP_DEBUG', true);
298+
define('WP_DEBUG_LOG', true);
299+
```
300+
301+
Check the debug log at `/wp-content/debug.log` for error messages.
302+
303+
## Security Considerations
304+
305+
1. **Authentication Required:** All endpoints require WordPress authentication with `manage_options` capability
306+
2. **Input Sanitization:** All input values are sanitized using WordPress sanitization functions
307+
3. **Permission Checks:** Each request validates user permissions before processing
308+
4. **No Token Authentication:** Unlike some other Progress Planner REST endpoints, the Angie integration relies on WordPress's native authentication for better security in the context of AI-assisted interactions
309+
310+
## Troubleshooting
311+
312+
### "You do not have permission to access this endpoint"
313+
314+
**Solution:** Ensure you're logged in as an Administrator or user with `manage_options` capability.
315+
316+
### "Task not found or already completed"
317+
318+
**Solution:** The task may already be completed or may not be active. Use the "Get Active Tasks" endpoint to see which tasks are currently available.
319+
320+
### "Failed to update the blog description"
321+
322+
**Solution:** This typically happens if the value hasn't changed. WordPress's `update_option()` returns false when the new value is the same as the old value.
323+
324+
## Contributing
325+
326+
To extend this integration:
327+
328+
1. Add new methods to `/code/classes/rest/class-angie.php`
329+
2. Register new routes in the `register_rest_endpoint()` method
330+
3. Follow WordPress REST API best practices
331+
4. Update this documentation
332+
333+
## Support
334+
335+
For issues or questions:
336+
- Progress Planner: https://prpl.fyi/
337+
- Angie Plugin: https://wordpress.org/plugins/angie/
338+
339+
## License
340+
341+
This integration is part of the Progress Planner plugin and is licensed under GPL-3.0+.

0 commit comments

Comments
 (0)