From 215b8312fcb537622e093d1fd36bafb3d70da9b1 Mon Sep 17 00:00:00 2001
From: Miguel Angel
Date: Fri, 20 Nov 2026 16:56:20 -0400
Subject: [PATCH 1/3] feat: add error handling for empty Git repositories in
PluginManager
---
ProcessMaker/Managers/PluginManager.php | 60 +++++++++++
resources/js/admin/plugins/Plugins.vue | 74 +++++++++----
resources/js/admin/plugins/mcpSetupPrompt.js | 100 ++++++++++++++++++
tests/Managers/PluginManagerTest.php | 105 +++++++++++++++++++
4 files changed, 319 insertions(+), 20 deletions(-)
create mode 100644 resources/js/admin/plugins/mcpSetupPrompt.js
diff --git a/ProcessMaker/Managers/PluginManager.php b/ProcessMaker/Managers/PluginManager.php
index c65763a44f..3bd5f4cf27 100644
--- a/ProcessMaker/Managers/PluginManager.php
+++ b/ProcessMaker/Managers/PluginManager.php
@@ -18,6 +18,14 @@
*/
class PluginManager
{
+ /**
+ * Shown when the cloned repository has no plugin code yet, which is the normal state of a
+ * brand-new repository that the coding agent has not pushed the skeleton to.
+ */
+ public const EMPTY_REPOSITORY_MESSAGE = 'The repository has no plugin code yet (there is no composer.json). '
+ . 'Push the plugin skeleton to it first (use "Copy prompt" in the Create Plugin dialog and let your '
+ . 'coding agent do it), then install again.';
+
/**
* Plugin directory created by the current install attempt.
* Removed if that attempt fails before setup finishes.
@@ -128,6 +136,12 @@ private function installPluginFiles(string $repoUrl, ?string $branch, ?string $t
$this->markNewInstallForRollback($pluginPath);
$this->cloneRepository($authenticatedRepoUrl, $pluginPath, $repoName, $userId, $repoUrl);
+ // An empty remote clones fine but `git checkout ` would then fail with an obscure message.
+ if ($this->isEmptyGitRepository($pluginPath)) {
+ $this->logError(self::EMPTY_REPOSITORY_MESSAGE, $repoName, $userId);
+ throw new RuntimeException(self::EMPTY_REPOSITORY_MESSAGE);
+ }
+
if ($branch) {
$this->logRunning("Checking out branch: {$branch}", $repoName, $userId);
$this->checkoutBranch($pluginPath, $branch, $repoName, $userId);
@@ -851,6 +865,47 @@ protected function checkoutTag(string $pluginPath, string $tag, string $repoName
}
}
+ /**
+ * True when the plugin directory is a git clone without any commit (an empty remote).
+ */
+ protected function isEmptyGitRepository(string $pluginPath): bool
+ {
+ if (!is_dir($pluginPath . '/.git')) {
+ return false;
+ }
+
+ return !Process::path($pluginPath)->timeout(30)->run(['git', 'rev-parse', '--verify', 'HEAD'])->successful();
+ }
+
+ /**
+ * True when the git clone only holds what hosting sites add to a new repository
+ * ("Initialize with README / license / .gitignore"), so there is no plugin code yet.
+ */
+ protected function hasOnlyPlaceholderFiles(string $pluginPath): bool
+ {
+ if (!is_dir($pluginPath . '/.git')) {
+ return false;
+ }
+
+ $result = Process::path($pluginPath)->timeout(30)->run(['git', 'ls-files']);
+ if (!$result->successful()) {
+ return false;
+ }
+
+ $files = array_filter(array_map('trim', explode("\n", $result->output())));
+ if ($files === []) {
+ return false;
+ }
+
+ foreach ($files as $file) {
+ if (!preg_match('/^(README|LICENSE|LICENCE|COPYING|\.gitignore|\.gitattributes)(\.[A-Za-z]+)?$/i', $file)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/**
* Validate that the plugin has a valid composer.json structure.
*
@@ -863,6 +918,11 @@ protected function validatePlugin(string $pluginPath, string $repoName, ?int $us
$composerJsonPath = $pluginPath . '/composer.json';
if (!file_exists($composerJsonPath)) {
+ if ($this->isEmptyGitRepository($pluginPath) || $this->hasOnlyPlaceholderFiles($pluginPath)) {
+ $this->logError(self::EMPTY_REPOSITORY_MESSAGE, $repoName, $userId);
+ throw new RuntimeException(self::EMPTY_REPOSITORY_MESSAGE);
+ }
+
$this->logError('composer.json not found in plugin: ' . $pluginPath, $repoName, $userId);
throw new RuntimeException("composer.json not found in plugin: {$pluginPath}");
}
diff --git a/resources/js/admin/plugins/Plugins.vue b/resources/js/admin/plugins/Plugins.vue
index b790cfa7c9..708e40b843 100644
--- a/resources/js/admin/plugins/Plugins.vue
+++ b/resources/js/admin/plugins/Plugins.vue
@@ -242,6 +242,13 @@
+
+ {{
+ $t(
+ "The token is only used by ProcessMaker to clone private repositories. It is never included in the copied prompt."
+ )
+ }}
+
@@ -307,6 +314,15 @@
+
+
+ {{
+ $t(
+ "New plugin? Use an empty repository (no README), copy the prompt and let your agent push the skeleton first, then save."
+ )
+ }}
+
+
{{
$t(
- "Copy a ready-to-paste setup prompt for Claude, Cursor, or any coding agent. It connects this instance over MCP, loads ProcessMaker skills, and points the agent at the right endpoints."
+ "Copy a ready-to-paste setup prompt for Claude, Cursor, or any coding agent. It installs the prerequisites, creates your plugin from the skeleton, pushes it to the repository above, and connects this instance over MCP."
)
}}