Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6137: fix(daemon): preserve name-dispatching agent shims (#6775)
weiwei Wang060731c7dfc3
diff --git a/server/internal/daemon/canonical_path.go b/server/internal/daemon/canonical_path.goindex 47f0cc8225..abb1bce369 100644--- a/server/internal/daemon/canonical_path.go+++ b/server/internal/daemon/canonical_path.go@@ -2,14 +2,52 @@package daemon-import "path/filepath"+import (+ "path/filepath"+ "strings"+)func canonicalPath(path string) (string, error) {return filepath.EvalSymlinks(path)}+// discoveredExecutablePath canonicalizes ordinary executable symlinks but+// preserves entrypoints backed by a known name-dispatching shim. Volta's+// volta-shim and Vite Plus's vp select the managed package from the invoked+// name; spawning the final target directly turns `claude --version` into+// `volta-shim --version` or `vp --version`, so the daemon reads the manager's+// version instead of the agent's and drops the runtime (#6183, #6702).+//+// The entrypoint's parent is still canonicalized. This keeps paths stable when+// their containing directory is a symlink or an ephemeral version-manager+// prefix, while retaining the basename the dispatcher needs — the same+// semantics buildLoginShellResolveScript has always applied via `pwd -P`.func discoveredExecutablePath(path string) string {- return canonicalExecutablePath(path)+ real := canonicalExecutablePath(path)+ if !isNameDispatchingAgentShim(real) {+ return real+ }+ abs, err := filepath.Abs(path)+ if err != nil {+ return real+ }+ realDir, err := filepath.EvalSymlinks(filepath.Dir(abs))+ if err != nil {+ return abs+ }+ return filepath.Join(realDir, filepath.Base(abs))+}++func isNameDispatchingAgentShim(path string) bool {+ base := strings.ToLower(filepath.Base(path))+ // "vp" is intentionally admitted despite being a short, generic token:+ // it is Vite Plus's shared dispatcher and, like Volta, selects the managed+ // package from argv[0]. Keep this exact-match list limited to dispatchers+ // confirmed to require the invoked entrypoint name. Do not strip executable+ // extensions: these managers use wrappers or trampolines rather than+ // name-dispatching symlinks, and that is a Windows shape this file never+ // compiles for.+ return base == "volta-shim" || base == "vp"}var executablePathForLaunch = executablePathForLaunchDefaultdiff --git a/server/internal/daemon/canonical_path_test.go b/server/internal/daemon/canonical_path_test.gonew file mode 100644index 0000000000..5e829ffa3c--- /dev/null+++ b/server/internal/daemon/canonical_path_test.go@@ -0,0 +1,32 @@+//go:build !windows++package daemon++import (+ "path/filepath"+ "testing"+)++func TestIsNameDispatchingAgentShim_RequiresExactDispatcherName(t *testing.T) {+ tests := []struct {+ name string+ path string+ want bool+ }{+ {name: "Volta", path: filepath.Join("manager", "volta-shim"), want: true},+ {name: "Vite Plus", path: filepath.Join("manager", "vp"), want: true},+ {name: "case insensitive", path: filepath.Join("manager", "VP"), want: true},+ {name: "short name prefix", path: filepath.Join("manager", "vpn"), want: false},+ {name: "short name word", path: filepath.Join("manager", "vproxy"), want: false},+ {name: "extension is not stripped", path: filepath.Join("manager", "volta-shim.exe"), want: false},+ {name: "ordinary version target", path: filepath.Join("manager", "claude-2.1.216"), want: false},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ if got := isNameDispatchingAgentShim(tt.path); got != tt.want {+ t.Fatalf("isNameDispatchingAgentShim(%q) = %v, want %v", tt.path, got, tt.want)+ }+ })+ }+}diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex 35f4ac5f74..e597e66d98 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -642,6 +642,9 @@ func shellArgsFromEnv(name string) ([]string, error) {// resolveAgentExecutablePath returns the executable entry point the daemon// should keep for an agent command. Bare command names are pinned to the path// resolved during startup so later PATH changes cannot redirect task launches.+// Ordinary executables are pinned to their concrete target; entrypoints owned+// by a name-dispatching shim keep the command name the manager needs to select+// the right package (see discoveredExecutablePath).// On Windows this deliberately keeps the stable discovered junction path;// resolveAgentEntryWithHeal follows it for each launch so installer upgrades// that retarget a still-live junction take effect without a daemon restart.@@ -843,8 +846,8 @@ var supportedLoginShells = map[string]struct{}{"ksh": {},}-// resolveAgentsViaLoginShell asks the user's login shell to print the canonical-// (symlink-resolved) absolute path to each name in `names`. It returns a map+// resolveAgentsViaLoginShell asks the user's login shell to print an absolute,+// invocation-safe path to each name in `names`. It returns a map// of name → path for whatever the shell could find, and an empty map if the// shell is unavailable / unsupported / times out / produces no usable output.//@@ -945,7 +948,8 @@ var resolveAgentsViaLoginShell = func(names []string) map[string]string {// still print the alias/function definition, and we'd rather drop it// than hand back garbage),// 5. canonicalises the directory via `cd ... && pwd -P` so symlinked prefix-// dirs (fnm/nvm/volta) collapse to stable paths,+// dirs (fnm/nvm/volta) collapse to stable paths while the invoked command+// name is kept,// 6. if the resolved path lives in ~/.multica/hooks, searches the same// shell-expanded PATH for the first executable outside that hooks dir,// 7. prints `<name>\t<canonical_path>` one entry per line for the caller.diff --git a/server/internal/daemon/config_test.go b/server/internal/daemon/config_test.goindex 0602cfc35c..e142b67224 100644--- a/server/internal/daemon/config_test.go+++ b/server/internal/daemon/config_test.go@@ -15,6 +15,80 @@ import ("github.com/multica-ai/multica/server/internal/cli")+func TestResolveAgentExecutablePath_PreservesDispatchShimName(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("creating symlinks requires elevated privileges on Windows")+ }++ for _, shimName := range []string{"volta-shim", "vp"} {+ t.Run(shimName, func(t *testing.T) {+ managerDir := t.TempDir()+ manager := filepath.Join(managerDir, shimName)+ if err := os.WriteFile(manager, []byte("#!/bin/sh\nprintf '%s\\n' \"${0##*/}\"\n"), 0o755); err != nil {+ t.Fatalf("write dispatcher: %v", err)+ }++ binDir := t.TempDir()+ entrypoint := filepath.Join(binDir, "claude")+ if err := os.Symlink(manager, entrypoint); err != nil {+ t.Fatalf("symlink dispatcher: %v", err)+ }+ t.Setenv("PATH", binDir)++ got, err := resolveAgentExecutablePath("claude")+ if err != nil {+ t.Fatalf("resolveAgentExecutablePath: %v", err)+ }+ realBinDir, err := filepath.EvalSymlinks(binDir)+ if err != nil {+ t.Fatalf("resolve bin directory: %v", err)+ }+ want := filepath.Join(realBinDir, "claude")+ if got != want {+ t.Fatalf("resolved path = %q, want command-preserving entrypoint %q", got, want)+ }+ output, err := exec.Command(got, "--version").CombinedOutput()+ if err != nil {+ t.Fatalf("run resolved entrypoint: %v: %s", err, output)+ }+ if got := strings.TrimSpace(string(output)); got != "claude" {+ t.Fatalf("dispatcher observed command name %q, want claude", got)+ }+ })+ }+}++func TestResolveAgentExecutablePath_CanonicalizesOrdinaryVersionTarget(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("creating symlinks requires elevated privileges on Windows")+ }++ versionDir := t.TempDir()+ target := filepath.Join(versionDir, "claude-2.1.216")+ if err := os.WriteFile(target, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {+ t.Fatalf("write versioned executable: %v", err)+ }++ binDir := t.TempDir()+ entrypoint := filepath.Join(binDir, "claude")+ if err := os.Symlink(target, entrypoint); err != nil {+ t.Fatalf("symlink versioned executable: %v", err)+ }+ t.Setenv("PATH", binDir)++ got, err := resolveAgentExecutablePath("claude")+ if err != nil {+ t.Fatalf("resolveAgentExecutablePath: %v", err)+ }+ want, err := filepath.EvalSymlinks(entrypoint)+ if err != nil {+ t.Fatalf("resolve versioned executable: %v", err)+ }+ if got != want {+ t.Fatalf("resolved path = %q, want pinned version target %q", got, want)+ }+}+func TestPatternsFromEnv_DefaultsWhenUnset(t *testing.T) {t.Setenv("MULTICA_GC_ARTIFACT_PATTERNS", "")defaults := []string{"node_modules", ".next", ".turbo"}