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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,22 @@ jobs:

- name: Verify publish contents
run: npm pack --dry-run

typecheck:
name: Typecheck
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v7

- name: Set up Node
uses: actions/setup-node@v7
with:
node-version: 22
cache: npm

- name: Install
run: npm ci

- name: Typecheck declarations and annotated sources
run: npm run typecheck
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jobs:
- name: Install
run: npm ci

- name: Typecheck
run: npm run typecheck

- name: Verify version matches the ref
shell: bash
# Pass the ref through the environment. Interpolating it into the
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ node_modules
*.log
test/logs/

# Local editor project scope; tsconfig.json is the checked-in project file.
jsconfig.json

# Live-test private keys. Only the matching .pub files are committed.
test/certs/*_ed25519
test/certs/*.pem
Expand Down
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ Releases before `4.0.0` are recorded as git tags and GitHub Releases.

## [Unreleased]

## [4.2.1] - 2026-11-25

### Added

- Added a conditional `exports` map so Node 16+/node16/nodenext resolution finds
`index.d.ts` for the root import while preserving `lib/*` (including
extensionless deep imports) and `package.json` subpaths.
- Added a dev-only, pinned TypeScript typecheck gate that validates static type
contracts across annotated sources, repository scripts, live tests, and strict
consumer fixtures under `node16` and `nodenext`. This is contract coverage,
not line coverage; the line-coverage report remains diagnostic only. It is a
required CI check and runs from `prepublishOnly`; runtime dependencies are
unchanged. A root `tsconfig.json` also gives editors explicit project scope
for `index.d.ts`.

### Changed

- Tightened editor typing: host context records are explicitly typed, command
responses are declared as strings, `HostConfig` carries `ThisType<SSH2Shell>`,
and `stop()` returns `this`. Runtime behavior is unchanged.
- Cleaned up WebStorm inspection warnings in `src/ssh2shell.js`,
`src/ssh2shell/util.js`, `index.d.ts`, and the `scripts/` helpers: redundant
`return`s, unused callback parameters, timer/context JSDoc annotations,
redundant regex escapes, and EventEmitter-compatible `addListener` overloads.
The internal `compilePromptRegex` deep-import export remains available.
Runtime behavior is unchanged.
- Cleared the same WebStorm inspection categories from the live and unit tests:
unused `dotenv` bindings and callback parameters, annotated fixture hosts and
fake connections, typed timer stubs, corrected `Error` cause arguments,
simplified trivial ternaries, and removed redundant locals. Test behavior is
unchanged.

## [4.2.0] - 2026-11-25

### Added
Expand Down Expand Up @@ -210,7 +242,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.2.0...HEAD
[Unreleased]: https://github.com/cmp-202/ssh2shell/compare/v4.2.1...HEAD
[4.2.1]: https://github.com/cmp-202/ssh2shell/compare/v4.2.0...v4.2.1
[4.2.0]: https://github.com/cmp-202/ssh2shell/compare/v4.1.0...v4.2.0
[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
Expand Down
23 changes: 23 additions & 0 deletions REFACTORING.md
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,29 @@ API are unchanged; this level adds metadata, documentation, and examples.
- `npm test`, `npm run check:changelog`, `git diff --check`, and
`npm pack --dry-run` — passed.

### L7.27 deliverables (declaration typecheck gate)

Post-4.2.0 hardening of the editor-support work. Runtime behavior and runtime
dependencies are unchanged.

- Added pinned dev-only `typescript` and `@types/node`.
- Added `npm run typecheck` with checked-in configs that validate static type
contracts across annotated sources, repository scripts, README-linked live
tests, and strict consumer fixtures under `node16` and `nodenext`. This is
contract coverage, not line coverage; line coverage remains diagnostic only.
- Added a single-version `Typecheck` CI job and a publish step;
`prepublishOnly` also runs the gate.
- Added a conditional `exports` map with `types` first while preserving existing
subpaths, including extensionless `lib/*` deep imports.
- Narrowed command responses to `string`, added `ThisType<SSH2Shell>` to
`HostConfig`, typed internal host records, and documented `stop()` as `this`.

#### Verification

- `npm run typecheck` — 0 errors.
- `npm test`, `npm run check:changelog`, `git diff --check`, and
`npm pack --dry-run` — passed.

## Backlog and future work

Items explicitly deferred until after the mechanical refactor. Each one changes
Expand Down
56 changes: 43 additions & 13 deletions docs/AI-ASSISTED-WORKFLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ here.

Apply these whether or not a prompt repeats them:

- No commit, push, PR, tag, or publish without explicit user approval.
- Follow the session modes below. Local commits are allowed in agreed review
cycles; no push, PR, tag, or publish without explicit user approval.
- Docs live in git. `README.md` stays concise; detail belongs in `docs/`.
- Coverage is diagnostic, not a release gate. No coverage dependency and no CI
coverage gate.
- Line coverage is diagnostic, not a release gate. No coverage dependency and
no CI line-coverage gate. `npm run typecheck` is a separate static-contract
gate; it is not line coverage and produces no coverage percentage.
- Live tests count in CI. `publish` must not run unless the live suite passes.
- An external/free review of the release candidate is a release step; resolve
its actionable findings before tagging, with user sign-off on every change.
Expand All @@ -29,6 +31,27 @@ Apply these whether or not a prompt repeats them:
- Before a task that depends on remote services, live hosts, or free models,
run the environmental assessment below first.

## Session modes

Use the narrowest mode that matches the request. A stop for exploration ends
when the user explicitly asks to create or use a branch and implement changes.

1. **Read-only exploration** — inspect, review, compare, and report findings.
Do not edit files, create commits, or change branches. This is the default
when the user says “let’s look at this” or asks for a stop on repo activity.
2. **Branch implementation** — begins when the user asks to create or use a
branch and make changes. Normal development applies: edit files, add new
files, stage, commit locally in agreed review cycles, run checks, fix
findings, and expand the implementation. Push, PR, tag, publish, and release
remain blocked.
3. **Release and remote actions** — push, PR, tag, publish, or release only with
explicit user approval. Same-day follow-up releases still follow the critical
fix rule unless the user explicitly overrides it.

A read-only limit is not a permanent repository freeze. It protects the
exploration phase; once implementation on a branch is requested, do not keep
asking for permission for ordinary local development steps.

## Start or recover a session

```text
Expand All @@ -38,8 +61,9 @@ You are working in the ssh2shell repository. Start read-only.
docs/AI-ASSISTED-WORKFLOWS.md.
2. Report git status --short, the current branch, and the latest commit.
3. Summarise which document is the source of truth for the requested task.
4. Do not commit, push, tag, or publish. Ask before any action that changes
the working tree or remote state.
4. Stay read-only until asked to create or use a branch and implement. Do not
push, tag, or publish. Commit only in agreed review cycles, and ask before
any action that changes remote state or release metadata.
```

## Set up the environment
Expand Down Expand Up @@ -112,7 +136,8 @@ Run the full pre-PR verification for ssh2shell and report results only.
the text table, full miss-overlap table, missed by both headline, Node
version, and commands. Keep raw LCOV files local.

Do not commit, push, or open the PR without explicit approval.
Commit only in agreed review cycles; do not push or open the PR without
explicit approval.
```

## Add a live test
Expand Down Expand Up @@ -164,19 +189,22 @@ You are adding editor/type support to ssh2shell. Start read-only.
src/ssh2shell.js, src/ssh2shell/defaults.js, src/ssh2shell/util.js, and the
README-linked live tests before changing anything.
- Keep package.json `types` pointing at ./index.d.ts and keep index.d.ts in
`files`. Do not add a TypeScript runtime dependency, build step, or CI gate.
`files`. Do not add a TypeScript runtime dependency or build step. The
dev-only TypeScript toolchain is checked by the `typecheck` script in CI and
`prepublishOnly`.
- Add JSDoc typedef aliases and `// @ts-check` in src/ where they improve the
public contract. Keep lib/ in sync with src/ through the repository's normal
build/check process.
- Use import('ssh2shell') in consumer-facing docs. Inside README-linked live
tests, use import('../../index') for module and HostConfig annotations so they
resolve locally.
- Keep JSDoc @type tags immediately above the declaration they describe.
- Verify with tsc against src/ and the annotated live tests, npm test,
git diff --check, and npm pack --dry-run when package metadata changed.
- Verify with `npm run typecheck`, npm test, git diff --check, and
npm pack --dry-run when package metadata changed.
- Report the declared fields/signatures, docs that changed, and verification
results. Do not commit, push, open a PR, tag, publish, or release without
explicit approval. Docs/test-only editor support does not trigger a release.
results. Commit only in agreed review cycles; do not push, open a PR, tag,
publish, or release without explicit approval. Docs/test-only editor support
does not trigger a release.
```

## Decide whether a fix needs a release
Expand Down Expand Up @@ -246,8 +274,10 @@ Refresh the coverage evidence for ssh2shell using test/coverage.md as the method
Keep the full table and use missed by both as the residual-risk headline.
- Update test/coverage.md and include the summary in the PR description or a
PR comment. Raw LCOV files stay local.
- Never add a coverage dependency or a CI coverage gate. Coverage is
informational; the gates are CI checks, the live suite, and RC review.
- Never add a line-coverage dependency or a CI line-coverage gate. Line
coverage is informational; the gates are CI checks, the live suite, typecheck,
and RC review. `npm run typecheck` validates static contracts, not executed
lines.
```

## Hand off a session
Expand Down
8 changes: 5 additions & 3 deletions docs/PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Update the changelog in a fixed order:
to the link definitions at the bottom.
3. Point the existing `[Unreleased]` link at `compare/vX.Y.Z...HEAD`.
4. Run `npm run check:changelog`. It fails if the version, date, bullets, or
compare links are missing, and it runs again from `prepublishOnly`.
compare links are missing. `prepublishOnly` runs it again alongside
`npm run typecheck` and `npm test`.

Then update `REFACTORING.md` and any other affected docs, and push the branch:

Expand Down Expand Up @@ -144,6 +145,8 @@ left to memory.
link, and update the `[Unreleased]` link.
- [ ] Update `REFACTORING.md` and any docs affected by the release.
- [ ] `npm run check:changelog` passes.
- [ ] `npm run typecheck` passes (sources, annotated live tests, and strict
consumer fixtures under node16 and nodenext).
- [ ] `npm test` passes (`check:build`, unit, baseline).
- [ ] Run the live suite locally when the change touches connection or command
flow: `npm run test:live:all`.
Expand All @@ -170,8 +173,7 @@ If trusted publishing is not available, create a granular access token with:

Store it as the `NPM_TOKEN` secret in GitHub Actions and set
`NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}` on the publish step. This is a
stopgap: direct publishing with bypass-2FA tokens is being removed in January
2027.
stopgap: direct publishing with bypass-2FA tokens is being removed in January 2027.

## Do not

Expand Down
38 changes: 16 additions & 22 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ declare class SSH2Shell {

/** Connect and optionally receive the combined session text at the end. */
connect(callback?: (sessionText: string) => void): boolean;
/** Stop the run early with an optional reason label. */
stop(reason?: string): unknown;
/** Stop the run early with an optional reason label. Returns this instance for chaining. */
stop(reason?: string): this;
/** Close the active connection; `graceful` backs out of nested shells. */
close(options?: SSH2Shell.CloseOptions): unknown;
/** Emit a structured message on the `msg` or `debug`/`verbose` channel. */
Expand All @@ -39,10 +39,12 @@ declare class SSH2Shell {
): this;
on(event: string, listener: (...args: any[]) => void): this;

// noinspection JSUnusedGlobalSymbols
addListener<E extends keyof SSH2Shell.EventMap>(
event: E,
listener: (this: SSH2Shell, ...args: SSH2Shell.EventMap[E]) => void
): this;
// noinspection JSUnusedGlobalSymbols
addListener(event: string, listener: (...args: any[]) => void): this;

once<E extends keyof SSH2Shell.EventMap>(
Expand Down Expand Up @@ -145,8 +147,8 @@ declare namespace SSH2Shell {

/** Extra values supplied with the `commandComplete` event. */
interface CommandCompleteDetails {
/** Always the unprocessed response buffer. */
rawResponse: string | Uint8Array;
/** Always a string; the shell stream is decoded before handlers receive it. */
rawResponse: string;
/** Captured stderr when `captureStderr` is enabled. */
stderr?: string;
[property: string]: unknown;
Expand Down Expand Up @@ -192,23 +194,23 @@ declare namespace SSH2Shell {
type CommandProcessingHandler = (
this: SSH2Shell,
command: string,
response: string | Uint8Array,
response: string,
host: HostConfig,
stream: ShellStream
) => void;
/** Runs when a command returns to the prompt. */
type CommandCompleteHandler = (
this: SSH2Shell,
command: string,
response: string | Uint8Array,
response: string,
host: HostConfig,
details: CommandCompleteDetails
) => void;
/** Runs when no prompt is detected before `idleTimeOut`. */
type CommandTimeoutHandler = (
this: SSH2Shell,
command: string,
response: string | Uint8Array,
response: string,
stream: ShellStream,
connection: SSHConnection,
details: TimeoutDetails
Expand Down Expand Up @@ -243,20 +245,9 @@ declare namespace SSH2Shell {
msg: [unknown];
data: [string | Uint8Array];
stderrData: [string | Uint8Array];
commandProcessing: [string, string | Uint8Array, HostConfig, ShellStream];
commandComplete: [
string,
string | Uint8Array,
HostConfig,
CommandCompleteDetails
];
commandTimeout: [
string,
string | Uint8Array,
ShellStream,
SSHConnection,
TimeoutDetails
];
commandProcessing: [string, string, HostConfig, ShellStream];
commandComplete: [string, string, HostConfig, CommandCompleteDetails];
commandTimeout: [string, string, ShellStream, SSHConnection, TimeoutDetails];
end: [string, HostConfig];
error: [
unknown,
Expand Down Expand Up @@ -289,7 +280,7 @@ declare namespace SSH2Shell {
*
* @see https://github.com/cmp-202/ssh2shell#configuration-reference
*/
interface HostConfig {
interface HostOptions {
/** How ssh2shell connects. Passed through to `ssh2.Client.connect()`. */
server: ServerConfig;

Expand Down Expand Up @@ -400,6 +391,9 @@ declare namespace SSH2Shell {
/** Runtime state and forward-compatible host keys. */
[property: string]: unknown;
}

/** Host configuration with `this` typed as the owning SSH2Shell instance. */
type HostConfig = HostOptions & ThisType<SSH2Shell>;
}

export = SSH2Shell;
Loading