mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-09 09:56:47 +08:00
Task and chat runs pass --mode json, so isPiRPCInvocation sent every real task down the PowerShell -File route. In -File mode PowerShell 5.1 reads stdin through the console ANSI codepage, so the prompt that has travelled on stdin since #6457 lost every non-ASCII byte (#7355). Route every Pi invocation through rewriteCmdToPS1Command (-Command with @args), which forwards stdin untouched; delete the now-dead isPiRPCInvocation predicate. Extract the argv construction into an untagged piPowerShellCommandArgs helper so the shape is testable off Windows, and update choosePiInvocation's doc comment: the #3306 -File reasoning is stale for Pi now that the prompt is on stdin, and the residual exposure is a multi-line custom option value.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
//go:build windows
|
|
|
|
package agent
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// platformPiInvocation rewrites pi.cmd → PowerShell -Command pi.ps1 on
|
|
// Windows. -Command with @args is the only route that preserves stdin bytes:
|
|
// -File re-encodes stdin under the console ANSI codepage, destroying
|
|
// non-ASCII input (#7355). It also avoids cmd.exe %* re-tokenisation (#3306).
|
|
// powerShellLookup and rewriteCmdToPS1 are defined in cursor_invocation_windows.go.
|
|
func platformPiInvocation(lookedUp string, args []string, logger *slog.Logger) (string, []string, bool) {
|
|
return rewriteCmdToPS1Command("pi", lookedUp, args, logger)
|
|
}
|
|
|
|
func rewriteCmdToPS1Command(toolName, lookedUp string, args []string, logger *slog.Logger) (string, []string, bool) {
|
|
ext := strings.ToLower(filepath.Ext(lookedUp))
|
|
if ext != ".cmd" && ext != ".bat" {
|
|
return "", nil, false
|
|
}
|
|
ps1 := filepath.Join(filepath.Dir(lookedUp), toolName+".ps1")
|
|
if st, err := os.Stat(ps1); err != nil || st.IsDir() {
|
|
return "", nil, false
|
|
}
|
|
|
|
psExe, ok := powerShellLookup()
|
|
if !ok {
|
|
return "", nil, false
|
|
}
|
|
|
|
full := piPowerShellCommandArgs(ps1, args)
|
|
|
|
if logger != nil {
|
|
logger.Info(toolName+": routing through powershell -Command to preserve stdin",
|
|
"powershell", psExe,
|
|
"ps1", ps1,
|
|
"original", lookedUp,
|
|
)
|
|
}
|
|
return psExe, full, true
|
|
}
|