This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git


The following commit(s) were added to refs/heads/master by this push:
     new 28ba4b7  fix(agent): pass an agent the arguments it needs to start
28ba4b7 is described below

commit 28ba4b7ec249bbc7b8d22bfe4d0bfe3c7513d2da
Author: Yang Luo <[email protected]>
AuthorDate: Thu Aug 27 21:27:57 2026 +0800

    fix(agent): pass an agent the arguments it needs to start
---
 agent/fingerprint.go           |  3 +++
 agent/fingerprints/dsh.json    |  1 +
 agent/launch.go                |  3 +++
 agentprocess/launch_darwin.go  | 33 ++++++++++++++++++++++++++++++---
 agentprocess/launch_linux.go   |  5 +++--
 agentprocess/launch_windows.go | 10 +++++++---
 agentprocess/process.go        |  2 ++
 controllers/agent_process.go   |  1 +
 8 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/agent/fingerprint.go b/agent/fingerprint.go
index 3e4ce33..145b3ba 100644
--- a/agent/fingerprint.go
+++ b/agent/fingerprint.go
@@ -22,6 +22,9 @@ type Fingerprint struct {
        DisplayName string `json:"displayName"`
 
        ExecName string `json:"execName,omitempty"`
+       // LaunchArgs are the arguments a start passes, literally: an agent that
+       // refuses to run bare needs the ones that pick its default mode.
+       LaunchArgs []string `json:"launchArgs,omitempty"`
        // Desktop marks a windowed app, which is launched without a console.
        Desktop bool `json:"desktop,omitempty"`
 
diff --git a/agent/fingerprints/dsh.json b/agent/fingerprints/dsh.json
index daf8fd4..7441e30 100644
--- a/agent/fingerprints/dsh.json
+++ b/agent/fingerprints/dsh.json
@@ -2,5 +2,6 @@
   "id": "dsh",
   "displayName": "DeepSeek Harness",
   "execName": "dsh",
+  "launchArgs": ["web"],
   "npmPackage": "@deepseek-ai/dsh"
 }
diff --git a/agent/launch.go b/agent/launch.go
index 1ac9e52..c5e285d 100644
--- a/agent/launch.go
+++ b/agent/launch.go
@@ -25,6 +25,8 @@ import (
 type Launch struct {
        // Executable is the file to run, empty when none was resolved.
        Executable string
+       // Args are passed to the executable, literally.
+       Args []string
        // Desktop marks a windowed app, which needs no console of its own.
        Desktop bool
 }
@@ -36,6 +38,7 @@ func LaunchOf(installation Installation) Launch {
        for i := range fingerprints {
                if fingerprints[i].ID == installation.AgentId {
                        execName = fingerprints[i].ExecName
+                       launch.Args = fingerprints[i].LaunchArgs
                        launch.Desktop = fingerprints[i].Desktop
                        break
                }
diff --git a/agentprocess/launch_darwin.go b/agentprocess/launch_darwin.go
index 300b738..e3ef036 100644
--- a/agentprocess/launch_darwin.go
+++ b/agentprocess/launch_darwin.go
@@ -24,11 +24,38 @@ import (
 func start(target Target) error {
        if target.Desktop {
                if bundle := appBundle(target.Executable); bundle != "" {
-                       return spawn("open", "-a", bundle)
+                       arguments := []string{"-a", bundle}
+                       if len(target.Args) > 0 {
+                               arguments = append(append(arguments, "--args"), 
target.Args...)
+                       }
+                       return spawn("open", arguments...)
                }
-               return spawn(target.Executable)
+               return spawn(target.Executable, target.Args...)
        }
-       return spawn("open", "-a", "Terminal", target.Executable)
+       if len(target.Args) == 0 {
+               return spawn("open", "-a", "Terminal", target.Executable)
+       }
+
+       // open hands Terminal a file to run and has nowhere to put arguments, 
so a
+       // command line is scripted instead. Only an agent that needs arguments 
pays
+       // for it: scripting Terminal asks the user for automation access, 
opening it
+       // does not.
+       command := shellQuote(target.Executable)
+       for _, argument := range target.Args {
+               command += " " + shellQuote(argument)
+       }
+       return spawn("osascript",
+               "-e", `tell application "Terminal" to do script 
`+appleScriptString(command),
+               "-e", `tell application "Terminal" to activate`)
+}
+
+func shellQuote(value string) string {
+       return "'" + strings.ReplaceAll(value, "'", `'\''`) + "'"
+}
+
+func appleScriptString(value string) string {
+       value = strings.ReplaceAll(value, `\`, `\\`)
+       return `"` + strings.ReplaceAll(value, `"`, `\"`) + `"`
 }
 
 // appBundle is the .app an executable lives in, empty outside a bundle. 
Opening
diff --git a/agentprocess/launch_linux.go b/agentprocess/launch_linux.go
index 442beb3..062c958 100644
--- a/agentprocess/launch_linux.go
+++ b/agentprocess/launch_linux.go
@@ -33,7 +33,7 @@ var terminals = [][]string{
 
 func start(target Target) error {
        if target.Desktop {
-               return spawn(target.Executable)
+               return spawn(target.Executable, target.Args...)
        }
 
        for _, terminal := range terminals {
@@ -41,7 +41,8 @@ func start(target Target) error {
                if err != nil {
                        continue
                }
-               return spawn(path, append(terminal[1:], target.Executable)...)
+               arguments := append(append([]string{}, terminal[1:]...), 
target.Executable)
+               return spawn(path, append(arguments, target.Args...)...)
        }
        return errors.New("no terminal emulator was found to run this agent in")
 }
diff --git a/agentprocess/launch_windows.go b/agentprocess/launch_windows.go
index 003f0d4..0e4dba8 100644
--- a/agentprocess/launch_windows.go
+++ b/agentprocess/launch_windows.go
@@ -20,6 +20,7 @@ import (
        "os"
        "os/exec"
        "strconv"
+       "strings"
        "syscall"
 )
 
@@ -27,10 +28,13 @@ import (
 // and gives a CLI the console window it needs. Its quoting rules are its own, 
so
 // the command line is written literally rather than assembled by os/exec.
 func start(target Target) error {
-       quoted := `"` + target.Executable + `"`
-       line := `cmd.exe /c start "" ` + quoted
+       command := `"` + target.Executable + `"`
+       if len(target.Args) > 0 {
+               command += " " + strings.Join(target.Args, " ")
+       }
+       line := `cmd.exe /c start "" ` + command
        if !target.Desktop {
-               line = `cmd.exe /c start "" cmd.exe /k ` + quoted
+               line = `cmd.exe /c start "" cmd.exe /k ` + command
        }
 
        cmd := exec.Command("cmd.exe")
diff --git a/agentprocess/process.go b/agentprocess/process.go
index e4c50a4..91ea537 100644
--- a/agentprocess/process.go
+++ b/agentprocess/process.go
@@ -40,6 +40,8 @@ type Target struct {
        Owner   string
        // Executable is the file to launch, empty when none was resolved.
        Executable string
+       // Args are passed to the executable, literally.
+       Args []string
        // Desktop marks a windowed app, which is started without a console.
        Desktop bool
 }
diff --git a/controllers/agent_process.go b/controllers/agent_process.go
index 43e8d15..322a7c2 100644
--- a/controllers/agent_process.go
+++ b/controllers/agent_process.go
@@ -110,6 +110,7 @@ func processTarget(installation agent.Installation) 
agentprocess.Target {
                Path:       installation.Path,
                Owner:      installation.Owner,
                Executable: launch.Executable,
+               Args:       launch.Args,
                Desktop:    launch.Desktop,
        }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to