kaizen-agent 1.7.6 → 1.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/state.ts CHANGED
@@ -75,27 +75,23 @@ export function findTerminal(cwd: string, fullCmd: string[]): { cmd: string[]; d
75
75
  const inTmux = Boolean(process.env.TMUX);
76
76
 
77
77
  // Windows has no xdg anything, and none of the terminals below exist there.
78
- // PowerShell is what a Windows user has open anyway: one -Command string,
79
- // where a single quote is doubled rather than escaped. Windows Terminal hosts
80
- // it when installed; otherwise `start` gives it a window of its own.
78
+ // PowerShell is what a Windows user has open anyway. The command reaches it as
79
+ // -EncodedCommand (base64 of UTF-16LE): a prompt with notes has newlines, which
80
+ // end a cmd.exe command line, and semicolons, which Windows Terminal splits its
81
+ // own arguments on -- neither survives as a plain -Command string. Windows
82
+ // Terminal hosts the shell when installed; otherwise `start` gives it a window.
81
83
  if (process.platform === "win32") {
82
84
  const q = (a: string) => `'${a.replace(/'/g, "''")}'`;
83
85
  const shell = Bun.which("pwsh.exe") ? "pwsh.exe" : "powershell.exe";
84
- // No Set-Location in the command: both launchers set the directory themselves,
85
- // and the semicolon that would separate the two statements is what Windows
86
- // Terminal splits its own arguments on. Any semicolon still left in the prompt
87
- // is escaped for wt, which reads it before PowerShell ever sees the quoting.
88
- const ps = `& ${fullCmd.map(q).join(" ")}`;
86
+ const ps = `Set-Location ${q(cwd)}; & ${fullCmd.map(q).join(" ")}`;
87
+ const enc = Buffer.from(ps, "utf16le").toString("base64");
89
88
  if (Bun.which("wt.exe")) {
90
- return {
91
- cmd: ["wt.exe", "-d", cwd, shell, "-NoExit", "-Command", ps.replace(/;/g, "\\;")],
92
- detached: true,
93
- };
89
+ return { cmd: ["wt.exe", "-d", cwd, shell, "-NoExit", "-EncodedCommand", enc], detached: true };
94
90
  }
95
91
  // `start` reads a title only when quoted; an unquoted word is the command, so
96
92
  // "kaizen" here ran kaizen's own launcher. The empty title is what Bun quotes.
97
93
  return {
98
- cmd: ["cmd.exe", "/c", "start", "", "/D", cwd, shell, "-NoExit", "-Command", ps],
94
+ cmd: ["cmd.exe", "/c", "start", "", "/D", cwd, shell, "-NoExit", "-EncodedCommand", enc],
99
95
  detached: true,
100
96
  };
101
97
  }