This file documents the implementation work completed for Phase 2.1 of the OpenCode integration sprint.
Phase 2.1: Decide execution model (fire-and-poll vs SSE vs synchronous) and extend api/opencode.php to support it
- ✅ Followed Front Controller Pattern (routes through index.php)
- ✅ Maintained flat namespace structure in
/view/,/lib/,/api/ - ✅ Used Shared Library Pattern (OpenCodeClient remains standalone)
- ✅ Respected API Contract rules (POST-only, JSON responses, method checks)
Extended to handle both health probe and command execution:
- Health Check Endpoint:
POST /api/opencode.php(existing behavior preserved) - Command Execution Endpoint:
POST /api/opencode.phpwith JSON payload:
{
"command": "/plan",
"project_slug": "kanban"
}- Synchronous execution with extended timeout (2x configured timeout)
- Command validation against whitelist (
/plan,/next,/debug,/review,/document) - Project slug validation and directory verification
- Settings validation for OpenCode enabling
{
"status": "ok|error",
"output": "command output as string",
"errors": "error details if any",
"commitHash": "git commit hash if available"
}
executeCommand()- Core AJAX command execution with error handlingexecuteAndDisplayCommand()- UI display helper function- HTML escaping utilities to prevent XSS
- ✅ PHP syntax validation (
php -l) - ✅ No git whitespace issues
- ✅ Backward compatibility maintained
- ✅ Follows existing project patterns and conventions
Selected option C from the design notes (vs A. Fire-and-poll or B. SSE) because:
- Simpler implementation for Phase 2 development
- Suitable for immediate execution needs
- Provides clear response without additional async complexity
- Follows project's approach to incremental development
api/opencode.php- Extended functionalityNEXT.md- Marked task as completedassets/js/opencode.js- New JavaScript client-side utilities
Prepare for extension of OpenCodeClient with task-id management and progress polling functionality.