mattvr / ShellGPT

Upgrade your terminal with GPT-4. Ask questions, automate commands, pipe I/O, etc. Made with Deno.
MIT License
232 stars 11 forks source link

Install script, `--repl` issues on Windows #8

Open pseudosavant opened 1 year ago

pseudosavant commented 1 year ago

Deno.run has been deprecated and replaced with Deno.command. See https://deno.land/api@v1.35.2?s=Deno.Command

I did try fixing it in a fork, but when I checked the current code out it would give me this error message even before I changed any code:

(No message passed)

{
  "error": {
    "message": "[] is too short - 'messages'",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

Failed to parse message TypeError: Cannot read properties of undefined (reading '0')
    at Object.next (file:///C:/Users/paul/Downloads/shellgpt/ShellGPT/lib/ai.ts:150:31)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async file:///C:/Users/paul/Downloads/shellgpt/ShellGPT/mod.ts:537:34
pseudosavant commented 1 year ago

I did notice that the getExecPrefix() tests for Powershell and cmd.exe will always be false as SHELL is not set in the environment for cmd.exe or Powershell. You can check for cmd.exe by checking Deno.env.get('comSpec');

mattvr commented 1 year ago

Ah sorry, @pseudosavant, I have never tested on Windows.

A few clarifying questions:

the current code out it would give me this error message even before I changed any code

pseudosavant commented 1 year ago
  1. Installing on Windows always seemed to error on the last step but was easily overcome with by just running the command it showed: deno install -frA -n gpt https://deno.land/x/shellgpt/mod.ts. Everything worked fine once installed that way. I assumed it probably hadn't been tested on Windows much.

  2. It seemed that 0.33 worked fine initially when I upgraded to it. But once I removed it and tried to install from local (to try making it work with Deno.command but at some point it started throwing the errors below. I typically use it with --repl and that doesn't work at all. These screenshots show it being installed and then invoked a few ways:

image image

  1. I had assumed from the error message I was seeing around the Deno.run invocation that it was related to the deprecation. I didn't see where it is still going to be available until 2.0.
mattvr commented 1 year ago

Ah okay. Very sorry for breaking things. @pseudosavant

It looks like the issue is Deno.stdin.setRaw does not support Windows. This is used to support newline pasting. But since that's not available, I think unfortunately this functionality can't easily work for Windows.

Any reason not to use cygwin, ConEmu, git bash, WSL, etc. for terminal instead of cmd.exe? I think everything should work fine with those.

You can also install an earlier working version with deno run -rA https://deno.land/x/shellgpt@0.3.1/install.ts until I get around to fixing it.

pseudosavant commented 1 year ago

I will use the previous version when in cmd.exe until there is a fix. It looks like Deno may be working in this area (setRaw + Windows): https://github.com/denoland/deno/blob/806137bb96c6f7e4b359a6e979c4e22d3a04a55c/Releases.md?plain=1#L533.

It would seem like that method only working on Linux and Mac OS would mean it should throw an error on Windows. At least then you could fall back to the previous prompt() behavior.

cmd.exe is just always there, and starts the fastest. It depends what I want to do. I have ShellGPT installed in Windows/cmd and WSL/bash.