All jobs

Replace golang.org/x/crypto/ssh/terminal With golang.org/x/term

Yes. An agent swaps the deprecated ssh/terminal import for golang.org/x/term, cross-builds every target you release, and opens a pull request.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

A linter usually raises this one. staticcheck reports golang.org/x/crypto/ssh/terminal is deprecated: this package moved to golang.org/x/term as SA1019, and the fix looks like one line. The agent treats it as a small change that still deserves proof, because terminal handling is where platforms differ. In an SSH client like yinheli/sshw, client.go imports the old package on line 19 and calls it six times: terminal.ReadPassword twice for password and keyboard-interactive prompts, terminal.MakeRaw and terminal.Restore around the interactive session, and terminal.GetSize twice, once to size the remote pty and once in a goroutine that watches for window resizes.

It reads go.mod before editing. sshw requires golang.org/x/crypto v0.48.0 directly, and golang.org/x/term v0.40.0 is already there, marked // indirect. That is the detail that makes this safe: the deprecated package is a thin wrapper whose functions call x/term, so the program has been running the new code all along through one extra hop. The agent rewrites the import and the six call sites from terminal. to term., runs gofmt, and runs go mod tidy. The only change to go.mod is that golang.org/x/term moves from the indirect block to the direct one, at the same version. golang.org/x/crypto stays, since client.go and config.go still use ssh and ssh/agent.

Then it builds for more than the machine it is on. sshw's .goreleaser.yml lists six operating systems, Windows, macOS, Linux, FreeBSD, OpenBSD and Solaris, and the file-descriptor arguments are platform-sensitive: the code passes int(syscall.Stdin) to ReadPassword, and a comment above the first GetSize call explains that it uses os.Stdout because the call did not work on Windows with standard input. The agent runs go build ./... and go vet ./... natively and then go build ./... with GOOS set to each of the other five, and reports each. It runs staticcheck before and after: two SA1019 findings before, one after. The remaining one is io/ioutil in config.go, which is a separate deprecation and is left for its own change.

Neither package in sshw has test files, and go test ./... in the workflow reports that and passes. The agent says so plainly, since a green test step proves nothing here. What it can and does check without a terminal attached is that the binary builds for each release target and that the set of exported names it uses exists in x/term with the same signatures. It also mentions one thing it saw and did not touch: the resize watcher calls GetSize on the standard-input descriptor, while the comment a few lines above says standard output is the one that works on Windows.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Replace the deprecated golang.org/x/crypto/ssh/terminal package with golang.org/x/term in this Go module. Read go.mod and report the versions of golang.org/x/crypto and golang.org/x/term and whether each is direct or indirect. List every file that imports ssh/terminal and every call, by function: IsTerminal, MakeRaw, Restore, GetState, GetSize, ReadPassword, NewTerminal and the Terminal type, and note what file descriptor each call passes. Run staticcheck (or the linter the repository configures) before the change and record the deprecation findings. Rewrite the import and the call sites, keep any import alias the code used only if it avoids a name clash, and run gofmt. Run go mod tidy and show the go.mod diff; say whether golang.org/x/crypto is still needed and by which packages. Do not upgrade either module's version in this change. Build and vet natively, then cross-build with GOOS set to every operating system the release configuration, Makefile or CI builds for, and report each result. Run go test and say how many packages have test files; if the changed code has none, say that the tests do not cover it. Run the linter again and list what remains, marking findings unrelated to this change as out of scope. Mention any terminal-handling issue you noticed in the surrounding code without fixing it. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that touches two files: eight lines in client.go, counting the import, the six calls and one comment that named the old package, and one moved line in go.mod. The description lists the six call sites with the descriptor each passes, the build result for each operating system, and the linter count before and after. It states that no version changed, with the go.mod diff as evidence, so a reviewer does not have to wonder whether a dependency upgrade came along.

The reviewer's check is short. They confirm that go.sum needed no new entries, since both modules were already in the graph. They read the note on tests and, if they want more than a compile check, run the binary against a host once on the platform they care about most, which for terminal code is usually Windows. The out-of-scope items, the io/ioutil finding and the resize watcher's descriptor, are listed at the bottom as candidates for separate changes.

Run it on every repository the linter flags

The same import sits in many Go command-line tools written before the package moved, so one organisation tends to have it in several repositories. GET /o/{org}/github lists every repository the Rush GitHub App can reach, as installations with their repositories and each one's full_name. Loop over that list, and for each Go repository send this body to POST /o/{org}/sessions with https://github.com/ plus the full_name as the resources URL.

The prompt already handles a repository that does not use the package: the first step lists imports, and with none found the agent reports that and opens nothing. Include a request_id, a new UUID per repository that you save, so that running the loop again after an interruption returns the runs it already started. Runs beyond the key's concurrency limit are accepted as queued and start as slots free.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A change this small is the kind that gets merged on sight and breaks a platform nobody built for. The run cross-builds for every target in the release configuration in its own sandbox, using the Go version the module asks for, and keeps the output of each build in the session transcript. The claim that Windows still compiles comes with the command that showed it.

It is also work that never reaches the top of anyone's list. A deprecation warning with a mechanical fix, spread over a dozen repositories, costs more in context switching than in effort. Handing each repository to its own run, many at once, and reviewing a two-file pull request per repository is a better use of an afternoon than doing the same edit by hand twelve times.

Frequently asked questions

Is golang.org/x/term a drop-in replacement?

For the functions most programs use, yes: IsTerminal, MakeRaw, Restore, GetState, GetSize, ReadPassword and NewTerminal have the same names and signatures. The old package is deprecated with a notice that it moved to golang.org/x/term, and its functions forward there. Change the import path and the package qualifier and the code compiles.

Do I need to add golang.org/x/term to go.mod?

go mod tidy does it. In a module that already depends on golang.org/x/crypto, x/term is normally present as an indirect requirement, and tidy moves it to the direct block once your code imports it. The version does not have to change.

Can I remove golang.org/x/crypto afterwards?

Only if nothing else in the module uses it. Programs that used ssh/terminal usually also use golang.org/x/crypto/ssh itself, so the requirement stays. go mod tidy removes it automatically when the last import is gone, and go mod why -m golang.org/x/crypto names what still needs it.

Does this change behaviour on Windows?

It should not, because the old package already called the new one. What matters on Windows is which handle you pass: console size comes from the output handle, and a redirected standard input is not a terminal. The agent cross-builds for Windows to prove the code compiles there, and flags descriptor choices it thinks deserve a look on a real console.

The project has no tests. How do I know it works?

For this change the strongest automatic evidence is that every release target builds and vets, and that no module version moved. Interactive behaviour, a password prompt that hides input and a session that restores the terminal on exit, needs a real terminal to observe, and the pull request says that it was not exercised.

More jobs like this: Upgrade dependencies weekly

Keep reading