fix: improve minimax apply-patch compatibility

This commit is contained in:
Codex
2026-06-03 13:07:24 +00:00
parent d012fe9a5e
commit 67a0446e51
4 changed files with 177 additions and 27 deletions
+24 -10
View File
@@ -911,6 +911,17 @@ export function parseSshArgs(args: string[]): ParsedSshArgs {
};
}
export function normalizeSshOperationArgs(args: string[]): string[] {
return args[0] === "--" ? args.slice(1) : args;
}
export function sshRouteSeparatorCompatibilityHint(rawArgs: string[], normalizedArgs: string[]): string {
if (rawArgs === normalizedArgs || rawArgs[0] !== "--") return "";
const operation = normalizedArgs[0] ?? "";
const operationText = operation.length === 0 ? "operation" : `operation \`${operation}\``;
return `UNIDESK_SSH_HINT route-level -- is ignored before ${operationText}; canonical form is \`trans <route> ${normalizedArgs.join(" ")}\`. Keep -- only inside operations such as \`script -- <command>\` or \`exec -- <command>\`.\n`;
}
function validateDirectArgvCommand(commandName: string, toolArgs: string[]): void {
if (toolArgs.length !== 1) return;
const command = toolArgs[0] ?? "";
@@ -927,16 +938,17 @@ function looksLikeShellCommandString(value: string): boolean {
export function parseSshInvocation(target: string, args: string[]): ParsedSshInvocation {
const route = parseSshRoute(target);
const operationArgs = normalizeSshOperationArgs(args);
if (route.plane === "k3s") {
return { providerId: route.providerId, route, parsed: parseK3sRouteArgs(route, args) };
return { providerId: route.providerId, route, parsed: parseK3sRouteArgs(route, operationArgs) };
}
if (route.plane === "win") {
return { providerId: route.providerId, route, parsed: parseWinRouteArgs(route, args) };
return { providerId: route.providerId, route, parsed: parseWinRouteArgs(route, operationArgs) };
}
if ((args[0] ?? "") === "k3s") {
throw new Error(`ssh k3s shorthand is unsupported; use route syntax instead: trans ${route.providerId}:k3s ${args.slice(1).join(" ")}`.trim());
if ((operationArgs[0] ?? "") === "k3s") {
throw new Error(`ssh k3s shorthand is unsupported; use route syntax instead: trans ${route.providerId}:k3s ${operationArgs.slice(1).join(" ")}`.trim());
}
return { providerId: route.providerId, route, parsed: parseSshArgs(args) };
return { providerId: route.providerId, route, parsed: parseSshArgs(operationArgs) };
}
export function parseSshRoute(target: string): ParsedSshRoute {
@@ -2512,14 +2524,16 @@ function writeChunkedStdin(stdin: NodeJS.WritableStream, input: string): void {
}
export async function runSsh(config: UniDeskConfig, providerId: string, args: string[]): Promise<number> {
const invocation = parseSshInvocation(providerId, args);
const normalizedArgs = normalizeSshOperationArgs(args);
process.stderr.write(sshRouteSeparatorCompatibilityHint(args, normalizedArgs));
const invocation = parseSshInvocation(providerId, normalizedArgs);
const parsed = invocation.parsed;
const operationName = args[0] ?? "";
if (isSshFileTransferOperation(args)) {
const operationName = normalizedArgs[0] ?? "";
if (isSshFileTransferOperation(normalizedArgs)) {
const executor: SshRemoteCommandExecutor = {
runRemoteCommand: (remoteCommand, input) => runSshCaptureRemoteCommand(config, invocation, remoteCommand, input),
};
return await runSshFileTransferOperation(invocation, args, executor, {
return await runSshFileTransferOperation(invocation, normalizedArgs, executor, {
buildRouteCommand: remoteCommandForRoute,
buildWindowsPowerShellCommand: buildWindowsPowerShellInvocation,
});
@@ -2533,7 +2547,7 @@ export async function runSsh(config: UniDeskConfig, providerId: string, args: st
stdin: process.stdin,
stdout: process.stdout,
stderr: process.stderr,
argv: args.slice(1),
argv: normalizedArgs.slice(1),
});
}
const startedAtMs = Date.now();