Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ Releases before `4.0.0` are recorded as git tags and GitHub Releases.

## [Unreleased]

## [4.1.0] - 2026-11-23

### Added

- `debug` and `verbose` can be set once on the `SSH2Shell` instance to override
host values for the whole run, including `false` suppressing a host that
enables the flag. Reading the instance property reports the effective value.
- `systemMsg(type, message, object)` is now a public helper for emitting debug
and verbose messages from handlers. It gates on the effective flag and applies
the standard host prefix and credential redaction. The internal `_systemMsg`
name is replaced; the frozen baseline keeps it for comparison tests.

### Development

- Added live coverage for keyboard-interactive authentication on a nested hop
Expand All @@ -19,6 +31,11 @@ Releases before `4.0.0` are recorded as git tags and GitHub Releases.
- Live workflow runs with the same ref now queue instead of cancelling each
other, so a parallel publish or push cannot remove a PR's required
`Live suite` check.
- Added a second round of unit tests for transport and state guards, host
traversal, shutdown flows, and behaviour hardening, plus two live tests for
the default command timeout and the TTY progress indicator. `test/coverage.md`
records the local coverage review and full miss-overlap analysis (98.12%
combined line coverage).

## [4.0.4] - 2026-11-18

Expand Down Expand Up @@ -153,7 +170,8 @@ See [docs/MIGRATING-4.md](./docs/MIGRATING-4.md) for the symptom-to-fix guide.
`~/.ssh/id_ed25519` copies that were only needed by nested `ssh -i` hops.
- `ssh2Client` is now `_ssh2Client` and is documented as an internal test seam.

[Unreleased]: https://github.com/cmp-202/ssh2shell/compare/v4.0.4...HEAD
[Unreleased]: https://github.com/cmp-202/ssh2shell/compare/v4.1.0...HEAD
[4.1.0]: https://github.com/cmp-202/ssh2shell/compare/v4.0.4...v4.1.0
[4.0.4]: https://github.com/cmp-202/ssh2shell/compare/v4.0.3...v4.0.4
[4.0.3]: https://github.com/cmp-202/ssh2shell/compare/v4.0.2...v4.0.3
[4.0.2]: https://github.com/cmp-202/ssh2shell/compare/v4.0.1...v4.0.2
Expand Down
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ value for that host.
| `window` | boolean \| object | `true` | First argument to `connection.shell()`. `false` disables the PTY; an object sets the terminal size. |
| `pty` | boolean | `true` | Request a pseudo-terminal. `false` is equivalent to `window: false`, because `ssh2` has no separate PTY option. |

`debug` and `verbose` may also be set once on the `SSH2Shell` instance; an
explicit instance value overrides the host value. See
[Verbose and debug output](#verbose-and-debug-output).

### Host event handlers

Handlers defined on the host object run only for that host. For most events
Expand Down Expand Up @@ -1146,16 +1150,38 @@ the session spans more than one host (multiple primary hosts or nested hosts); a
single-host session omits the prefix. Do not enable them inside
`onCommandProcessing`, which runs for every chunk of output.

Add your own messages with the same flags:
For a multi-host run, set either flag on the instance once before `connect()`
instead of repeating it in every host config. An explicit instance boolean
overrides every host value in both directions, so `false` also suppresses a
host that enables the flag:

```javascript
onCommandProcessing: function (command, response, sshObj, stream) {
if (sshObj.verbose) {
this.emit('msg', `${sshObj.server.host}: response: ${response}`);
}
const ssh = new SSH2Shell(hosts);
ssh.debug = process.env.DEBUG === 'true';
ssh.verbose = process.env.VERBOSE === 'true';
ssh.connect(callback);
```

`ssh.debug` and `ssh.verbose` report the effective value for the active host.
Host values are still used when the instance flag has not been set.

To add your own debug or verbose messages from a handler, call
`this.systemMsg(type, message)` with `'debug'` or `'verbose'`. Inside a handler,
`this` is the `SSH2Shell` instance:

```javascript
onCommandTimeout: function (command, response, stream, connection) {
this.systemMsg('debug', `${this.sshObj.server.host}: timeout: ${command}`);
},
```

`systemMsg()` gates the message on the effective flag for the active host, then
applies the same host prefix and credential redaction as the library's own
messages. Prefer it over manually checking `this.debug` / `this.verbose` and
calling `this.emit('msg', ...)`: a manual check can read the wrong value and
bypasses redaction. Reading `ssh.debug` / `ssh.verbose` is still appropriate
when you need the effective value for some other purpose.

Debug and verbose output redacts the configured password, passphrase, and
private key by default. Set `exposeCredentials: true` only while diagnosing an
authentication problem, and never leave it enabled in production or in logs.
Expand Down
12 changes: 6 additions & 6 deletions docs/API-BASELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ wrong, not because the code changed:
These changes intentionally differ from the L0 baseline. Each is covered by a
test that runs against both the current build and the frozen baseline artifact.

- **Debug/verbose gating.** `_systemMsg` emits debug and verbose messages only
when the host's `debug` / `verbose` flags are enabled. Normal `msg` output is
unchanged.
- **Debug/verbose gating.** `systemMsg` (called `_systemMsg` in the frozen
baseline) emits debug and verbose messages only when the effective `debug` /
`verbose` flags are enabled. Normal `msg` output is unchanged.
- **Listener lifecycle.** Default listeners are installed once; host listeners
replace defaults; leaving a host detaches both the cached handler and the
current host handler. Reloading defaults does not attach duplicates.
Expand Down Expand Up @@ -241,23 +241,23 @@ are covered by level-aware tests that also run against the frozen baseline.

## Post-L6.1 behavior changes (signed off)

- **Credential redaction in debug/verbose output.** `_systemMsg` now scrubs the
- **Credential redaction in debug/verbose output.** `systemMsg` now scrubs the
configured password and passphrase from every debug/verbose string and masks
`password` / `passphrase` keys in object dumps (including nested `hosts`
config). The sudo and nested-SSH credential messages, the verbose
`runCommand` echo, and the config dump therefore show `[REDACTED]` instead of
the plaintext value. The frozen baseline logs the raw credentials.
- **`exposeCredentials` (default `false`).** A per-host opt-in that restores the
raw credential output for fault-finding. It is applied in `_loadDefaults` and
read by `_systemMsg`; it does not change the connection itself. Test:
read by `systemMsg`; it does not change the connection itself. Test:
`test/unit/credentials.test.js`.
- **Instance timer base values.** `SSH.idleTime` / `SSH.dataIdleTime` set before
`connect()` are preserved instead of being replaced by the hard-coded 5000 /
500 defaults. A host's `idleTimeOut` / `dataIdleTimeOut` still overrides them,
and leaving a host restores the base. `idleTime` is accepted as a legacy host
alias for `idleTimeOut`. Test: `test/unit/timers.test.js`.
- **Message listener continuity.** `_removeListeners` keeps the default `msg`
listener attached while a host is being swapped, so `_systemMsg` debug/verbose
listener attached while a host is being swapped, so `systemMsg` debug/verbose
output is not dropped between hosts. `_loadDefaults` swaps in a host `msg`
handler when one exists and falls back to the default handler otherwise.
Tests: `test/unit/l5-behavior.test.js` — message-sink and duplicate-listener
Expand Down
10 changes: 6 additions & 4 deletions docs/MIGRATING-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ SSH.connect((sessionText) => {
});
```

Set `debug: true` and `verbose: true` on the host for connection-level detail.
The common error types are `Connection`, `Hop`, `Command Timeout`, `Stream`,
and `Connection close`; see [Error handling](./ERROR-HANDLING.md) for the full
contract.
Set `debug: true` and `verbose: true` on the host for connection-level detail,
or set `SSH.debug` / `SSH.verbose` once before `connect()` to apply the value to
every host in a multi-host run. An explicit instance boolean overrides the host
values in both directions. The common error types are `Connection`, `Hop`,
`Command Timeout`, `Stream`, and `Connection close`; see
[Error handling](./ERROR-HANDLING.md) for the full contract.

When you open an issue, include the `ssh2shell` and Node.js versions, the error
type, and a minimal host object and command list. Remove keys, passwords, and
Expand Down
6 changes: 3 additions & 3 deletions docs/NEXT-HOST-CONNECTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ _nextHost() {
const parent = this._activeContext();
this._removeListeners(parent);
const nextHost = parent.pendingHosts.shift();
this._systemMsg('debug', `nextHost: hop to ${nextHost.server.host}`);
this.systemMsg('debug', `nextHost: hop to ${nextHost.server.host}`);

this.sshObj = nextHost;
this.host = nextHost.server.host;
Expand Down Expand Up @@ -418,7 +418,7 @@ record shape changes from a host config to `record.host`:

### Deviation register

Logging is not a deviation. `_systemMsg`, `debug`, `verbose`, `msg` prefixes,
Logging is not a deviation. `systemMsg`, `debug`, `verbose`, `msg` prefixes,
progress, sudo prompts, command-response handling, `captureStderr`, and the
default error listener all read the active aliases and keep their current
behaviour. Only the following need code changes.
Expand Down Expand Up @@ -1479,7 +1479,7 @@ child is active. No handler needs to know whether the host is primary or nested.
| `onStderrData` | Fires for the active child stream. `captureStderr` still merges into the child response. |
| `onEnd` | Fires once per visited host, child before parent. |
| `onError` | Host handler runs for the event's record; the default listener keeps its existing close semantics for the active record. |
| `onMsg` | Same `_systemMsg` path and `[host]` prefix rules. |
| `onMsg` | Same `systemMsg` path and `[host]` prefix rules. |
| `onKeyboardInteractive` | Bound per connection; the instance event fires with that connection's `finish`. |
| `reconnect` | Follow-up only. Fires with the record's `sshObj` and `{ phase, attempt, maxRetries, delay, expected, reason }`; a reboot reports `expected: true`, a real failure is an `error` with `level: 'Reconnect'`. |
| `progress` | One heartbeat for the active command; `_progressEnd()` runs before a host switch. |
Expand Down
Loading