mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 22:04:56 +00:00
refactor(workflow): convert all plugins to class/struct + factory pattern
- Python: class extending NodeExecutor + factory.py (80+ plugins) - TypeScript: class implements NodeExecutor + factory.ts (7 groups, 116 classes) - Go: struct with methods + factory.go (36 plugins) - Rust: struct impl NodeExecutor trait + factory.rs (54 plugins) - Mojo: struct + factory.mojo (11 plugins) All package.json files now include: - files array listing source files - metadata.class/struct field - metadata.entrypoint field This enables a unified plugin loading system across all languages with no import side effects (Spring-style DI pattern). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsCreateBranch plugin."""
|
||||
|
||||
from .tools_create_branch import ToolsCreateBranch
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsCreateBranch instance."""
|
||||
return ToolsCreateBranch()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_create_branch",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_create_branch plugin",
|
||||
"description": "Create a Git branch from a base branch",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"main": "tools_create_branch.py",
|
||||
"files": ["tools_create_branch.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.create_branch",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsCreateBranch",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
"""Workflow plugin: create branch."""
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
def run(runtime, inputs):
|
||||
"""Create a branch via tool runner."""
|
||||
result = runtime.tool_runner.call(
|
||||
"create_branch",
|
||||
branch_name=inputs.get("branch_name"),
|
||||
base_branch=inputs.get("base_branch", "main")
|
||||
)
|
||||
return {"result": result}
|
||||
|
||||
class ToolsCreateBranch(NodeExecutor):
|
||||
"""Create a Git branch via tool runner."""
|
||||
|
||||
node_type = "tools.create_branch"
|
||||
category = "tools"
|
||||
description = "Create a Git branch from a base branch"
|
||||
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""Create a branch via tool runner."""
|
||||
result = runtime.tool_runner.call(
|
||||
"create_branch",
|
||||
branch_name=inputs.get("branch_name"),
|
||||
base_branch=inputs.get("base_branch", "main")
|
||||
)
|
||||
return {"result": result}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsCreatePullRequest plugin."""
|
||||
|
||||
from .tools_create_pull_request import ToolsCreatePullRequest
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsCreatePullRequest instance."""
|
||||
return ToolsCreatePullRequest()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_create_pull_request",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_create_pull_request plugin",
|
||||
"description": "Create a pull request with title, body, and branch information",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"main": "tools_create_pull_request.py",
|
||||
"files": ["tools_create_pull_request.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.create_pull_request",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsCreatePullRequest",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
"""Workflow plugin: create pull request."""
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
def run(runtime, inputs):
|
||||
|
||||
class ToolsCreatePullRequest(NodeExecutor):
|
||||
"""Create a pull request via tool runner."""
|
||||
result = runtime.tool_runner.call(
|
||||
"create_pull_request",
|
||||
title=inputs.get("title"),
|
||||
body=inputs.get("body"),
|
||||
head_branch=inputs.get("head_branch"),
|
||||
base_branch=inputs.get("base_branch", "main")
|
||||
)
|
||||
return {"result": result}
|
||||
|
||||
node_type = "tools.create_pull_request"
|
||||
category = "tools"
|
||||
description = "Create a pull request with title, body, and branch information"
|
||||
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""Create a pull request via tool runner."""
|
||||
result = runtime.tool_runner.call(
|
||||
"create_pull_request",
|
||||
title=inputs.get("title"),
|
||||
body=inputs.get("body"),
|
||||
head_branch=inputs.get("head_branch"),
|
||||
base_branch=inputs.get("base_branch", "main")
|
||||
)
|
||||
return {"result": result}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsListFiles plugin."""
|
||||
|
||||
from .tools_list_files import ToolsListFiles
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsListFiles instance."""
|
||||
return ToolsListFiles()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_list_files",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_list_files plugin",
|
||||
"description": "List files in a directory",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"main": "tools_list_files.py",
|
||||
"files": ["tools_list_files.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.list_files",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsListFiles",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
"""Workflow plugin: list files."""
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
def run(runtime, inputs):
|
||||
"""List files via tool runner."""
|
||||
result = runtime.tool_runner.call("list_files", directory=inputs.get("path", "."))
|
||||
return {"files": result}
|
||||
|
||||
class ToolsListFiles(NodeExecutor):
|
||||
"""List files in a directory via tool runner."""
|
||||
|
||||
node_type = "tools.list_files"
|
||||
category = "tools"
|
||||
description = "List files in a directory"
|
||||
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""List files via tool runner."""
|
||||
result = runtime.tool_runner.call("list_files", directory=inputs.get("path", "."))
|
||||
return {"files": result}
|
||||
|
||||
8
workflow/plugins/python/tools/tools_read_file/factory.py
Normal file
8
workflow/plugins/python/tools/tools_read_file/factory.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsReadFile plugin."""
|
||||
|
||||
from .tools_read_file import ToolsReadFile
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsReadFile instance."""
|
||||
return ToolsReadFile()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_read_file",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_read_file plugin",
|
||||
"description": "Read the contents of a file",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"main": "tools_read_file.py",
|
||||
"files": ["tools_read_file.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.read_file",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsReadFile",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
"""Workflow plugin: read file."""
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
def run(runtime, inputs):
|
||||
|
||||
class ToolsReadFile(NodeExecutor):
|
||||
"""Read a file via tool runner."""
|
||||
result = runtime.tool_runner.call("read_file", path=inputs.get("path"))
|
||||
return {"content": result}
|
||||
|
||||
node_type = "tools.read_file"
|
||||
category = "tools"
|
||||
description = "Read the contents of a file"
|
||||
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""Read a file via tool runner."""
|
||||
result = runtime.tool_runner.call("read_file", path=inputs.get("path"))
|
||||
return {"content": result}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsRunDocker plugin."""
|
||||
|
||||
from .tools_run_docker import ToolsRunDocker
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsRunDocker instance."""
|
||||
return ToolsRunDocker()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_run_docker",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_run_docker plugin",
|
||||
"description": "Run a command inside a Docker container with optional volumes and working directory",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"keywords": ["tools", "workflow", "plugin", "docker"],
|
||||
"main": "tools_run_docker.py",
|
||||
"files": ["tools_run_docker.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.run_docker",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsRunDocker",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +1,68 @@
|
||||
"""Workflow plugin: run command in Docker container."""
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import logging
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
logger = logging.getLogger("metabuilder.docker")
|
||||
|
||||
|
||||
def _run_command_in_docker(image: str, command: str, volumes: dict = None, workdir: str = None):
|
||||
"""Run a command inside a Docker container.
|
||||
class ToolsRunDocker(NodeExecutor):
|
||||
"""Run a command inside a Docker container."""
|
||||
|
||||
:param image: Docker image to use.
|
||||
:param command: Command to execute.
|
||||
:param volumes: Dictionary of volume mappings {host_path: container_path}.
|
||||
:param workdir: Working directory inside the container.
|
||||
:return: Standard output of the command.
|
||||
"""
|
||||
docker_command = ["docker", "run", "--rm"]
|
||||
node_type = "tools.run_docker"
|
||||
category = "tools"
|
||||
description = "Run a command inside a Docker container with optional volumes and working directory"
|
||||
|
||||
if volumes:
|
||||
for host_path, container_path in volumes.items():
|
||||
docker_command.extend(["-v", f"{os.path.abspath(host_path)}:{container_path}"])
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""Run a command inside a Docker container.
|
||||
|
||||
if workdir:
|
||||
docker_command.extend(["-w", workdir])
|
||||
Inputs:
|
||||
- image: Docker image to use
|
||||
- command: Command to execute
|
||||
- volumes: Optional dict of volume mappings {host_path: container_path}
|
||||
- workdir: Optional working directory inside the container
|
||||
"""
|
||||
image = inputs.get("image")
|
||||
command = inputs.get("command")
|
||||
volumes = inputs.get("volumes")
|
||||
workdir = inputs.get("workdir")
|
||||
|
||||
docker_command.append(image)
|
||||
docker_command.extend(["sh", "-c", command])
|
||||
if not image or not command:
|
||||
return {"error": "Both 'image' and 'command' are required"}
|
||||
|
||||
logger.info(f"Executing in Docker ({image}): {command}")
|
||||
result = subprocess.run(docker_command, capture_output=True, text=True, check=False)
|
||||
output = self._run_command_in_docker(image, command, volumes, workdir)
|
||||
return {"output": output}
|
||||
|
||||
output = result.stdout
|
||||
if result.stderr:
|
||||
output += "\n" + result.stderr
|
||||
def _run_command_in_docker(self, image: str, command: str, volumes: dict = None, workdir: str = None):
|
||||
"""Run a command inside a Docker container.
|
||||
|
||||
logger.info(output)
|
||||
return output
|
||||
:param image: Docker image to use.
|
||||
:param command: Command to execute.
|
||||
:param volumes: Dictionary of volume mappings {host_path: container_path}.
|
||||
:param workdir: Working directory inside the container.
|
||||
:return: Standard output of the command.
|
||||
"""
|
||||
docker_command = ["docker", "run", "--rm"]
|
||||
|
||||
if volumes:
|
||||
for host_path, container_path in volumes.items():
|
||||
docker_command.extend(["-v", f"{os.path.abspath(host_path)}:{container_path}"])
|
||||
|
||||
def run(_runtime, inputs):
|
||||
"""Run a command inside a Docker container.
|
||||
if workdir:
|
||||
docker_command.extend(["-w", workdir])
|
||||
|
||||
Inputs:
|
||||
- image: Docker image to use
|
||||
- command: Command to execute
|
||||
- volumes: Optional dict of volume mappings {host_path: container_path}
|
||||
- workdir: Optional working directory inside the container
|
||||
"""
|
||||
image = inputs.get("image")
|
||||
command = inputs.get("command")
|
||||
volumes = inputs.get("volumes")
|
||||
workdir = inputs.get("workdir")
|
||||
docker_command.append(image)
|
||||
docker_command.extend(["sh", "-c", command])
|
||||
|
||||
if not image or not command:
|
||||
return {"error": "Both 'image' and 'command' are required"}
|
||||
logger.info(f"Executing in Docker ({image}): {command}")
|
||||
result = subprocess.run(docker_command, capture_output=True, text=True, check=False)
|
||||
|
||||
output = _run_command_in_docker(image, command, volumes, workdir)
|
||||
return {"output": output}
|
||||
output = result.stdout
|
||||
if result.stderr:
|
||||
output += "\n" + result.stderr
|
||||
|
||||
logger.info(output)
|
||||
return output
|
||||
|
||||
8
workflow/plugins/python/tools/tools_run_lint/factory.py
Normal file
8
workflow/plugins/python/tools/tools_run_lint/factory.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsRunLint plugin."""
|
||||
|
||||
from .tools_run_lint import ToolsRunLint
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsRunLint instance."""
|
||||
return ToolsRunLint()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_run_lint",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_run_lint plugin",
|
||||
"description": "Run linting on source files",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"keywords": ["tools", "workflow", "plugin", "lint"],
|
||||
"main": "tools_run_lint.py",
|
||||
"files": ["tools_run_lint.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.run_lint",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsRunLint",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
"""Workflow plugin: run lint."""
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
def run(runtime, inputs):
|
||||
|
||||
class ToolsRunLint(NodeExecutor):
|
||||
"""Run lint via tool runner."""
|
||||
result = runtime.tool_runner.call("run_lint", path=inputs.get("path", "src"))
|
||||
return {"results": result}
|
||||
|
||||
node_type = "tools.run_lint"
|
||||
category = "tools"
|
||||
description = "Run linting on source files"
|
||||
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""Run lint via tool runner."""
|
||||
result = runtime.tool_runner.call("run_lint", path=inputs.get("path", "src"))
|
||||
return {"results": result}
|
||||
|
||||
8
workflow/plugins/python/tools/tools_run_tests/factory.py
Normal file
8
workflow/plugins/python/tools/tools_run_tests/factory.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""Factory for ToolsRunTests plugin."""
|
||||
|
||||
from .tools_run_tests import ToolsRunTests
|
||||
|
||||
|
||||
def create():
|
||||
"""Create and return a ToolsRunTests instance."""
|
||||
return ToolsRunTests()
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "@metabuilder/tools_run_tests",
|
||||
"version": "1.0.0",
|
||||
"description": "tools_run_tests plugin",
|
||||
"description": "Run tests in a specified directory",
|
||||
"author": "MetaBuilder",
|
||||
"license": "MIT",
|
||||
"keywords": ["tools", "workflow", "plugin"],
|
||||
"keywords": ["tools", "workflow", "plugin", "tests"],
|
||||
"main": "tools_run_tests.py",
|
||||
"files": ["tools_run_tests.py", "factory.py"],
|
||||
"metadata": {
|
||||
"plugin_type": "tools.run_tests",
|
||||
"category": "tools"
|
||||
"category": "tools",
|
||||
"class": "ToolsRunTests",
|
||||
"entrypoint": "execute"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
"""Workflow plugin: run tests."""
|
||||
|
||||
from ...base import NodeExecutor
|
||||
|
||||
def run(runtime, inputs):
|
||||
|
||||
class ToolsRunTests(NodeExecutor):
|
||||
"""Run tests via tool runner."""
|
||||
result = runtime.tool_runner.call("run_tests", path=inputs.get("path", "tests"))
|
||||
return {"results": result}
|
||||
|
||||
node_type = "tools.run_tests"
|
||||
category = "tools"
|
||||
description = "Run tests in a specified directory"
|
||||
|
||||
def execute(self, inputs, runtime=None):
|
||||
"""Run tests via tool runner."""
|
||||
result = runtime.tool_runner.call("run_tests", path=inputs.get("path", "tests"))
|
||||
return {"results": result}
|
||||
|
||||
Reference in New Issue
Block a user