Skip to content

feat: add slim cli for local and remote plugin invocation#630

Open
41tair wants to merge 4 commits intomainfrom
feat/daemon-slim
Open

feat: add slim cli for local and remote plugin invocation#630
41tair wants to merge 4 commits intomainfrom
feat/daemon-slim

Conversation

@41tair
Copy link
Member

@41tair 41tair commented Mar 13, 2026

Description

Add cmd/slim CLI tool that invokes Dify plugins in two modes:

  1. local spawns Python subprocess directly
  2. remote proxies to a running daemon via /v2/invoke/dispatch SSE endpoints

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Additional Information

We need a way to easily deploy and invoke plugins for testing or running a standalone workflow.

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Mar 13, 2026
@41tair 41tair requested review from Yeuoly and fatelei March 13, 2026 04:01
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant new feature: a command-line interface (CLI) tool named slim that streamlines the process of invoking Dify plugins. This tool provides a unified way to interact with plugins, whether they are executed directly on the local machine or remotely through a daemon. The primary goal is to simplify testing, deployment, and standalone execution of plugins, offering greater flexibility and control over their lifecycle.

Highlights

  • New CLI Tool: Introduced a new slim CLI tool (cmd/slim) designed for invoking Dify plugins.
  • Dual Invocation Modes: The CLI supports two modes for plugin invocation: 'local' mode, which directly spawns a Python subprocess, and 'remote' mode, which proxies requests to a running daemon via /v2/invoke/dispatch SSE endpoints.
  • Flexible Configuration: The slim CLI can be configured via command-line flags, environment variables, or a JSON configuration file, providing flexibility for different deployment scenarios.
  • Structured Error Handling and Output: Implemented a structured error handling mechanism (SlimError) with distinct error codes and exit codes, along with a dedicated OutputWriter for streaming structured event data (chunks, errors, messages) to stdout.
  • Daemon API Enhancements: The daemon's HTTP server was updated to include a new /v2/invoke group with dispatch endpoints and middleware for handling direct plugin invocation requests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cmd/slim/main.go
    • Added the main entry point for the slim CLI, responsible for parsing command-line arguments, loading configuration, and orchestrating plugin invocation in either local or remote mode.
  • internal/core/local_runtime/constructor_slim.go
    • Added NewLocalPluginRuntime to create a local plugin runtime instance using a pre-determined working path, optimizing for scenarios where checksum-based path computation is not required.
  • internal/server/constants/constants.go
    • Added PluginUniqueIdentifier constant to facilitate identification of plugins via HTTP headers in the daemon.
  • internal/server/http_server.go
    • Introduced a new Gin router group /v2/invoke and its corresponding invokeGroup handler to manage incoming plugin invocation requests, integrating new middleware for processing.
  • internal/server/middleware.go
    • Added FetchPluginDirect middleware to extract the X-Plugin-Unique-Identifier header from requests and store it in the Gin context for subsequent processing.
  • pkg/slim/config.go
    • Added data structures (RequestMeta, LocalConfig, RemoteConfig, InvokeContext, SlimConfig) and logic for loading and validating slim CLI configurations from files or environment variables, supporting both local and remote execution parameters.
  • pkg/slim/config_test.go
    • Added comprehensive unit tests for the slim CLI configuration loading, default value assignment, and validation logic across different modes.
  • pkg/slim/errors.go
    • Added custom error types (SlimError, ErrorCode) and defined a set of standardized exit codes for the slim CLI, improving error reporting and handling.
  • pkg/slim/errors_test.go
    • Added unit tests to verify the functionality of SlimError, including its string representation and correct mapping to various exit codes.
  • pkg/slim/local.go
    • Added core logic for local plugin execution, including downloading and extracting plugins from a marketplace, initializing Python environments, and executing plugin entrypoints as subprocesses.
  • pkg/slim/output.go
    • Added OutputWriter for standardized, structured output of events (e.g., 'chunk', 'done', 'error', 'message') from the slim CLI to io.Writer.
  • pkg/slim/output_test.go
    • Added unit tests for OutputWriter to ensure that various event types are correctly formatted and written to the output stream.
  • pkg/slim/remote.go
    • Added DaemonClient and RunRemote functions to handle remote plugin invocation by making HTTP requests to the daemon and processing Server-Sent Events (SSE) responses.
  • pkg/slim/remote_test.go
    • Added unit tests for remote plugin invocation, covering route lookup, daemon client dispatch, and the parsing of SSE streams.
  • pkg/slim/transform.go
    • Added TransformRequest function to convert the InvokeContext into a standardized JSON request format suitable for both local and remote plugin execution.
  • pkg/slim/transform_test.go
    • Added unit tests for TransformRequest to validate the correct transformation of invocation contexts into the expected request message format for various plugin actions.
  • pkg/slim/utils.go
    • Added utility functions env and envInt for safely retrieving string and integer environment variables with default fallback values.
  • pkg/slim/utils_test.go
    • Added unit tests for utility functions such as truncate, pluginWorkingPath, env, and envInt to ensure their correctness.
Activity
  • The author, 41tair, has confirmed local testing of the changes, ensuring they work as expected.
  • Unit tests have been added where necessary and are passing, indicating a focus on code quality and reliability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added cmd go Pull requests that update go code labels Mar 13, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a slim CLI for plugin invocation, which is a great feature for testing and standalone use. The implementation is comprehensive, covering both local and remote invocation modes, with good separation of concerns in the new pkg/slim package. The code is well-structured and includes a good set of tests. I've identified a few areas for improvement, mainly around error handling robustness and consistency. Specifically, the fatal error handler in the CLI can be made more robust, there are a few places where errors from I/O operations are ignored, and a deprecated function is used for timeout detection.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd go Pull requests that update go code lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants