@godspeedai/cognate-execution-ssh

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3104

SSH host as an execution world: SFTP filesystem and remote exec over ssh2, with mandatory host-key verification, ProxyJump and clean disposal. Same contracts as every other provider.

原始使用文档
文档目录7 节
  1. Installation
  2. Quick start
  3. What it guarantees
  4. Testing your integration
  5. Known limits
  6. Related packages
  7. License

@godspeedai/cognate-execution-ssh

An SSH host as a Cognate execution world: files over SFTP, commands over remote exec — behind the same filesystem.* / process.exec contracts as every other provider, so nothing above the provider knows it is SSH. Built on the ssh2 package.

When to use this package: an agent should read, write, and run commands on a remote machine you can reach over SSH (optionally through a jump host), with host identity verified before anything is sent. For the local machine use @godspeedai/cognate-execution's localExecutionWorld; for a WSL distribution use @godspeedai/cognate-execution-wsl.

Installation

bun add @godspeedai/cognate-execution-ssh

Requires Bun >= 1.4.0. Depends on ssh2 and @godspeedai/cognate-execution (the contracts this provider implements).

Quick start

import { sshExecutionWorld } from "@godspeedai/cognate-execution-ssh";

const world = sshExecutionWorld({
  worldId: "build-box",
  host: "build.example.com",
  username: "dev",
  auth: { kind: "key", privateKeyPath: "~/.ssh/id_ed25519" }, // or { kind: "agent" } / { kind: "password", password }
  hostKeys: { fingerprints: ["SHA256:..."] }, // REQUIRED — or { knownHostsPath: "/home/me/.ssh/known_hosts" }
  jump: [ // ProxyJump, optional; each hop is verified like the target
    { host: "bastion.example.com", username: "dev", auth: { kind: "agent" }, hostKeys: { knownHostsPath: "/home/me/.ssh/known_hosts" } },
  ],
});

const path = world.fileSystem.resolve("/srv/workspace", "README.md");
const readme = await world.fileSystem.readText(path);
const result = await world.process.exec({ argv: ["cargo", "test"], cwd: "/srv/workspace", timeoutMs: 300_000 });

console.log(world.metadata); // { host, port, username, auth: "key", hostKey: "SHA256:..." } — safe for logs

await world.dispose();

Construction refuses an empty host-key policy outright. A first connection to a new host should go through probeHostKey, which reads the server's key and refuses it — nothing is authenticated or sent — so a human can decide to pin the fingerprint it printed:

import { probeHostKey } from "@godspeedai/cognate-execution-ssh";

const probe = await probeHostKey({ host: "build.example.com" });
console.log(probe.fingerprint, probe.keyType, probe.known); // "SHA256:..." "ssh-ed25519" "unknown"
// Show it to a person; pin it in hostKeys.fingerprints or known_hosts before connecting for real.

What it guarantees

  • The server is who you pinned. Host-key verification is mandatory — no trust-on-first-use, no accept-anything mode. A mismatch raises HostKeyMismatchError before authentication is ever attempted and is never retried. Hashed and plain known_hosts entries, [host]:port forms, wildcards, negation, and @revoked markers are honoured; @cert-authority entries are ignored (unsupported).
  • Fail closed. An unreachable host, a changed key, or a disposed world raises WorldUnavailableError. Nothing ever falls back to local execution.
  • Containment. resolve rejects lexical escapes, and a symlink inside the root pointing outside is refused before any read/write/stat/list (via SFTP realpath).
  • A cancelled command really ends. Commands run under a supervisor with their own process group, ended on TERM or when stdin reaches EOF — so the whole process tree dies even against servers that ignore signal requests or drop the connection.
  • Reconnect. A dropped connection is re-dialled on the next operation; idempotent file operations retry once, commands and writes never do.
  • Clean disposal. dispose() closes live channels, SFTP, and every hop; it is idempotent, and later operations fail closed.
  • No secrets leak. metadata carries host, port, user, auth kind, and the verified host-key fingerprint — never a password, passphrase, or key. Errors never echo credentials either.

Testing your integration

The ./fixture subpath exports startSshFixture — a real in-process SSH server (ssh2 Server) with password/public-key auth, a working exec, an SFTP subset, and direct-tcpip forwarding for ProxyJump — so your own tests can run the shared conformance suite from @godspeedai/cognate-execution/conformance against a genuine SSH client/server pair without an external machine.

Known limits

  • The remote login shell must accept exec sh -c '<posix script>'.
  • version is mtime(seconds):size (SFTP attributes carry whole seconds only), so two writes within the same second with equal size look unchanged. Local and command worlds use mtime(ns):size:inode.
  • The symlink containment check is check-then-use: a concurrent swap between the check and the operation is not prevented.
  • No keyboard-interactive/2FA authentication and no @cert-authority support.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-execution-ssh 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-execution-ssh 的常见问题

@godspeedai/cognate-execution-ssh 是什么?

SSH host as an execution world: SFTP filesystem and remote exec over ssh2, with mandatory host-key verification, ProxyJump and clean disposal. Same contracts as every other provider.

如何安装 @godspeedai/cognate-execution-ssh?

在项目目录运行 npm install @godspeedai/cognate-execution-ssh,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-execution-ssh 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-execution-ssh 是否存在。

@godspeedai/cognate-execution-ssh 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@godspeedai/cognate-execution-ssh 可以商用吗?

@godspeedai/cognate-execution-ssh 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@godspeedai/cognate-execution-ssh 的下载量有多少?

根据 npm 官方下载统计,@godspeedai/cognate-execution-ssh 在 2026/10/17 – 2026/11/15 这 30 天内被下载 3,104 次,日均约 103 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@godspeedai/cognate-execution-ssh 还在维护吗?

最新版本 0.10.0 发布于 2026/11/16(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/10/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。