@linxin666/dsh-ssh 0.4.19 → 0.4.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +13 -2
  3. package/README.zh.md +13 -2
  4. package/lib/client.js +726 -109
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +1074 -352
  7. package/lib/types/client/api.d.ts +8 -4
  8. package/lib/types/client/locales.d.ts +27 -1
  9. package/lib/types/client/panel/HostFormDialog.d.ts +3 -3
  10. package/lib/types/client/panel/HostsTab.d.ts +3 -3
  11. package/lib/types/client/panel/KeysTab.d.ts +8 -0
  12. package/lib/types/client/panel/controller.d.ts +1 -1
  13. package/lib/types/connection-trust.d.ts +26 -0
  14. package/lib/types/engine/cluster.d.ts +7 -2
  15. package/lib/types/engine/connection-pool.d.ts +11 -2
  16. package/lib/types/engine/sftp.d.ts +5 -0
  17. package/lib/types/engine/terminal-sessions.d.ts +5 -3
  18. package/lib/types/index.d.ts +6 -5
  19. package/lib/types/protocol.d.ts +41 -0
  20. package/lib/types/routes.d.ts +3 -0
  21. package/lib/types/service.d.ts +148 -0
  22. package/lib/types/store.d.ts +16 -4
  23. package/package.json +1 -1
  24. package/src/client/api.ts +147 -58
  25. package/src/client/locales.ts +55 -2
  26. package/src/client/panel/HostFormDialog.tsx +76 -17
  27. package/src/client/panel/HostsTab.tsx +50 -25
  28. package/src/client/panel/KeysTab.tsx +192 -0
  29. package/src/client/panel/SshPanel.tsx +4 -1
  30. package/src/client/panel/TerminalTab.tsx +14 -9
  31. package/src/client/panel/TunnelsTab.tsx +24 -7
  32. package/src/client/panel/controller.ts +77 -12
  33. package/src/client/panel/helpers.ts +3 -2
  34. package/src/connection-trust.ts +70 -0
  35. package/src/engine/cluster.ts +45 -13
  36. package/src/engine/connection-pool.ts +279 -96
  37. package/src/engine/proxy-command.ts +27 -10
  38. package/src/engine/sftp.ts +69 -35
  39. package/src/engine/terminal-sessions.ts +110 -35
  40. package/src/engine/tunnel.ts +20 -2
  41. package/src/engine.ts +5 -8
  42. package/src/index.ts +113 -39
  43. package/src/protocol.ts +45 -0
  44. package/src/routes.ts +130 -23
  45. package/src/service.ts +158 -0
  46. package/src/store.ts +324 -104
  47. package/src/tools.ts +3 -5
@@ -2,7 +2,7 @@
2
2
  * Browser-side API client for the /api/dsh-ssh route family. The only data
3
3
  * access path the panel components use — plain fetch/WebSocket, same origin.
4
4
  */
5
- import { type ClusterResult, type ExecResult, type HostPayload, type ImportResult, type RemoteDirEntry, type SshHostSummary, type TestResult, type TransferProgress, type TunnelInfo } from '../protocol.ts';
5
+ import { type ClusterResult, type ExecResult, type HostPayload, type ImportResult, type RemoteDirEntry, type SshKeyPayload, type SshKeySummary, type SshPanelHostSummary, type TestResult, type TransferProgress, type TunnelInfo } from '../protocol.ts';
6
6
  /** Error carrying the route's JSON error message. */
7
7
  export declare class SshApiError extends Error {
8
8
  constructor(message: string);
@@ -75,10 +75,14 @@ export interface TerminalConnection {
75
75
  }
76
76
  /** The browser half's only data entry point. */
77
77
  export declare class SshApi {
78
- listHosts(queryText?: string): Promise<SshHostSummary[]>;
79
- createHost(payload: HostPayload): Promise<SshHostSummary>;
80
- updateHost(alias: string, patch: HostPayload): Promise<SshHostSummary>;
78
+ listHosts(queryText?: string): Promise<SshPanelHostSummary[]>;
79
+ createHost(payload: HostPayload): Promise<SshPanelHostSummary>;
80
+ updateHost(alias: string, patch: HostPayload): Promise<SshPanelHostSummary>;
81
81
  deleteHost(alias: string): Promise<void>;
82
+ listKeys(): Promise<SshKeySummary[]>;
83
+ createKey(payload: SshKeyPayload): Promise<SshKeySummary>;
84
+ updateKey(id: string, patch: SshKeyPayload): Promise<SshKeySummary>;
85
+ deleteKey(id: string): Promise<void>;
82
86
  importSshConfig(): Promise<ImportResult>;
83
87
  testHost(alias: string): Promise<TestResult>;
84
88
  exec(alias: string, command: string, timeoutMs?: number): Promise<ExecResult>;
@@ -7,6 +7,7 @@ export declare const zh: {
7
7
  readonly 'panel.title': "远程 SSH";
8
8
  readonly 'panel.backToConversation': "返回会话";
9
9
  readonly 'tab.hosts': "主机";
10
+ readonly 'tab.keys': "密钥";
10
11
  readonly 'tab.terminal': "终端";
11
12
  readonly 'tab.transfer': "传输";
12
13
  readonly 'tab.tunnels': "隧道";
@@ -62,9 +63,15 @@ export declare const zh: {
62
63
  readonly 'form.auth.agent': "SSH Agent";
63
64
  readonly 'form.agentPath': "Agent 路径";
64
65
  readonly 'form.agentPathHint': "留空自动检测(SSH_AUTH_SOCK;Windows 上为原生 ssh-agent 命名管道);也可填 socket 路径或 pageant";
65
- readonly 'form.authKeepHint': "编辑时密码 / 私钥留空将保留已存凭据;Agent 路径留空是合法的自动检测,选「SSH Agent」即切换到 agent 认证。";
66
+ readonly 'form.authKeepHint': "编辑时密码 / 密钥口令留空将保留已存凭据;私钥路径用于匹配受管密钥且不会回读口令。Agent 路径留空是合法的自动检测。";
66
67
  readonly 'form.keyPath': "私钥路径";
67
68
  readonly 'form.keyPathHint': "如 ~/.ssh/id_ed25519";
69
+ readonly 'form.keyPathRequired': "请选择受管密钥或填写自定义私钥路径。";
70
+ readonly 'form.managedKey': "受管密钥";
71
+ readonly 'form.key.custom': "自定义路径…";
72
+ readonly 'form.key.customHint': "手动填写路径;编辑时口令留空保留原值。";
73
+ readonly 'form.key.managedHint': "路径与口令由受管密钥在宿主侧解析,不会向浏览器回读口令。";
74
+ readonly 'form.keyListError': "受管密钥列表读取失败:{error}。仍可使用自定义路径。";
68
75
  readonly 'form.passphrase': "密钥口令";
69
76
  readonly 'form.password': "密码";
70
77
  readonly 'form.passwordHint': "明文保存在 $DSH_HOME/dsh-ssh.json(本机私有文件)";
@@ -85,6 +92,25 @@ export declare const zh: {
85
92
  readonly 'form.cancel': "取消";
86
93
  readonly 'form.required': "请填写必填字段:别名、主机地址、用户名。";
87
94
  readonly 'form.portInvalid': "端口必须是 1-65535 之间的整数。";
95
+ readonly 'keys.add': "新增密钥";
96
+ readonly 'keys.empty': "尚未登记密钥。密钥只保存本机路径与可选口令,不复制或读取私钥内容。";
97
+ readonly 'keys.name': "名称";
98
+ readonly 'keys.col.name': "名称";
99
+ readonly 'keys.col.status': "文件状态";
100
+ readonly 'keys.col.usedBy': "引用主机";
101
+ readonly 'keys.exists': "文件存在";
102
+ readonly 'keys.missing': "文件不存在";
103
+ readonly 'keys.unused': "未被引用";
104
+ readonly 'keys.usedBy': "{count} 台:{hosts}";
105
+ readonly 'keys.pathHint': "绝对路径或 ~ 开头的路径;只检查文件元数据,不读取私钥内容。";
106
+ readonly 'keys.passphraseHint': "可选口令,明文存入本机 0600 配置文件;编辑时留空保留,勾选清除可移除。";
107
+ readonly 'keys.clearPassphrase': "清除已保存的口令";
108
+ readonly 'keys.required': "请填写密钥名称与路径。";
109
+ readonly 'keys.form.create': "新增受管密钥";
110
+ readonly 'keys.form.edit': "编辑受管密钥「{name}」";
111
+ readonly 'keys.editConfirm': "此密钥正被 {count} 台主机引用:{hosts}。本次只修改受管记录,不会自动改写这些主机的现有路径或凭据。继续?";
112
+ readonly 'keys.deleteConfirm': "删除受管密钥「{name}」?{count} 台引用主机({hosts})会保留各自现有私钥路径与凭据,不会被删除或改写。";
113
+ readonly 'keys.deleteConfirmUnused': "删除受管密钥「{name}」?只会删除这条受管记录,不会删除私钥文件。";
88
114
  readonly 'terminal.selectHost': "选择主机";
89
115
  readonly 'terminal.connect': "连接";
90
116
  readonly 'terminal.disconnect': "断开";
@@ -1,12 +1,12 @@
1
1
  import type { SshApi } from '../api.ts';
2
- import type { SshHostSummary } from '../../protocol.ts';
2
+ import type { SshPanelHostSummary } from '../../protocol.ts';
3
3
  /** Host form dialog props. */
4
4
  export interface HostFormDialogProps {
5
5
  api: SshApi;
6
6
  /** The host being edited; null/undefined means create. */
7
- editing?: SshHostSummary | null;
7
+ editing?: SshPanelHostSummary | null;
8
8
  onClose: () => void;
9
- onSaved: (host: SshHostSummary) => void;
9
+ onSaved: (host: SshPanelHostSummary) => void;
10
10
  }
11
11
  /** The create/edit host modal. */
12
12
  export declare function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialogProps): import("react").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import type { SshApi } from '../api.ts';
2
- import type { SshHostSummary } from '../../protocol.ts';
2
+ import type { SshPanelHostSummary } from '../../protocol.ts';
3
3
  /** Hosts tab props. */
4
4
  export interface HostsTabProps {
5
5
  api: SshApi;
@@ -12,7 +12,7 @@ export type HostGroupBy = 'none' | 'environment' | 'tags';
12
12
  export interface HostGroup {
13
13
  /** Group key: the environment name, one tag, or '' for the ungrouped bucket. */
14
14
  key: string;
15
- hosts: SshHostSummary[];
15
+ hosts: SshPanelHostSummary[];
16
16
  }
17
17
  /**
18
18
  * Bucket hosts into collapsible groups (#379). Grouping by tags places a
@@ -20,6 +20,6 @@ export interface HostGroup {
20
20
  * the grouping key land in the '' bucket, which always sorts last. Groups
21
21
  * sort alphabetically; host order inside a group follows the API listing.
22
22
  */
23
- export declare function groupHosts(hosts: SshHostSummary[], groupBy: HostGroupBy): HostGroup[];
23
+ export declare function groupHosts(hosts: SshPanelHostSummary[], groupBy: HostGroupBy): HostGroup[];
24
24
  /** The hosts table plus its toolbar and dialogs. */
25
25
  export declare function HostsTab({ api, onConnect }: HostsTabProps): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { SshApi } from '../api.ts';
2
+ interface KeysTabProps {
3
+ api: SshApi;
4
+ /** Confirmation seam for host-reference warnings; defaults to window.confirm. */
5
+ confirmAction?: (message: string) => boolean;
6
+ }
7
+ export declare function KeysTab({ api, confirmAction }: KeysTabProps): import("react").JSX.Element;
8
+ export {};
@@ -21,7 +21,7 @@
21
21
  */
22
22
  import type { TerminalConnection } from '../api.ts';
23
23
  /** The panel's tab identifiers. */
24
- export type SshTab = 'hosts' | 'terminal' | 'transfer' | 'tunnels' | 'cluster';
24
+ export type SshTab = 'hosts' | 'keys' | 'terminal' | 'transfer' | 'tunnels' | 'cluster';
25
25
  /** Stable id shared by the sidebar panel row and the main-slot page. */
26
26
  export declare const SSH_PANEL_ID = "ssh";
27
27
  /** Lifecycle of one terminal tab. */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Optional bridge to the Host connection trust decision. Newer hosts expose
3
+ * admit(request); the rc.3 SDK cohort exposes requestRejection(request). A
4
+ * missing or throwing bridge is not an admission: callers must retain their
5
+ * existing loopback or pairing fence.
6
+ */
7
+ import type { IncomingMessage } from 'node:http';
8
+ import type { Context } from '@deepseek-ai/cordis';
9
+ /** Structural host connection face across supported SDK cohorts. */
10
+ export interface HostConnectionService {
11
+ requestRejection?: (request: IncomingMessage) => unknown;
12
+ admit?: (request: IncomingMessage) => {
13
+ readonly peer?: unknown;
14
+ readonly rejection?: unknown;
15
+ };
16
+ }
17
+ /** Lazily read the service captured in the plugin's dependency scope. */
18
+ export type HostConnectionReader = () => HostConnectionService | undefined;
19
+ /** Whether the Host's own authenticated/trusted-host decision admits a request. */
20
+ export declare function connectionAdmits(connection: HostConnectionService | undefined, request: IncomingMessage): boolean;
21
+ /**
22
+ * Capture connection in a scope that also injects connection.authentication:
23
+ * admit(request) resolves that service through the calling fiber. The returned
24
+ * reader falls back to a bare optional lookup on cohorts without that service.
25
+ */
26
+ export declare function captureConnection(ctx: Context, effectName: string): HostConnectionReader;
@@ -4,11 +4,16 @@
4
4
  */
5
5
  import type { ClusterResult } from '../protocol.ts';
6
6
  import { type PoolEngine } from './connection-pool.ts';
7
- interface ClusterOptions {
8
- command: string;
7
+ /** Target selector fields shared by cluster engine, routes, and agent tool. */
8
+ export interface ClusterSelector {
9
9
  aliases?: string[];
10
10
  environment?: string;
11
11
  tags?: string[];
12
+ }
13
+ /** Whether at least one trimmed non-empty cluster target filter is present. */
14
+ export declare function hasClusterSelector(options: ClusterSelector): boolean;
15
+ interface ClusterOptions extends ClusterSelector {
16
+ command: string;
12
17
  timeoutMs?: number;
13
18
  maxWorkers?: number;
14
19
  /** Caller cancellation, forwarded to every host's command. */
@@ -2,6 +2,7 @@
2
2
  * Connection pool: per-alias persistent ssh2 connections with multi-hop jump
3
3
  * support, the acquire / dispose / sweep lifecycle, and the pooled exec path.
4
4
  */
5
+ import { StringDecoder } from 'node:string_decoder';
5
6
  import { Client, type ConnectConfig } from 'ssh2';
6
7
  import type { ExecResult, SshHostEntry } from '../protocol.ts';
7
8
  import { type HostStore } from '../store.ts';
@@ -102,11 +103,12 @@ export declare function readyTimeoutMessage(timeoutMs: number | undefined, hands
102
103
  export declare function isReadyTimeout(error: Error): boolean;
103
104
  /** Connect one ssh2 client (resolve on ready, reject on error/close). */
104
105
  export declare function connectClient(config: ConnectConfig, onKeyboardInteractive?: KeyboardInteractiveHandler): Promise<Client>;
105
- /** Cap captured output at the configured byte budget (marks truncation). */
106
+ /** Cap captured output at the configured UTF-8 byte budget (marks truncation). */
106
107
  export declare function appendOutput(target: {
107
108
  text: string;
108
109
  truncated: boolean;
109
- }, chunk: Buffer, maxBytes: number): void;
110
+ bytes?: number;
111
+ }, chunk: Buffer, maxBytes: number, decoder?: StringDecoder): void;
110
112
  /**
111
113
  * Parse an OpenSSH jump hop written as an address: `[user@]host[:port]`
112
114
  * (an IPv6 literal must be bracketed). Returns undefined when the value is not
@@ -142,6 +144,13 @@ export declare function connectChain(engine: PoolEngine, entry: SshHostEntry, on
142
144
  client: Client;
143
145
  hops: Client[];
144
146
  }>;
147
+ /**
148
+ * Invalidate any in-flight acquire for `alias` so a connection still handshaking
149
+ * under stale config or before a delete cannot enter `engine.pool` after completion.
150
+ */
151
+ export declare function invalidateAlias(engine: PoolEngine, alias: string): void;
152
+ /** Mark the pool disposed so in-flight acquires tear down instead of entering the pool. */
153
+ export declare function markPoolDisposed(engine: PoolEngine): void;
145
154
  /** Connect (or reuse) the pooled chain for one alias; pins nothing. */
146
155
  export declare function acquire(engine: PoolEngine, alias: string): Promise<PoolRecord>;
147
156
  /**
@@ -3,6 +3,7 @@
3
3
  * remote directory listing. Every channel is opened once per operation and
4
4
  * released exactly once so sshd's MaxSessions cap is never exhausted.
5
5
  */
6
+ import { type SFTPWrapper } from 'ssh2';
6
7
  import type { RemoteDirEntry, TransferProgress } from '../protocol.ts';
7
8
  import { type PoolEngine } from './connection-pool.ts';
8
9
  /** Walk a local directory, collecting relative paths of every file. */
@@ -18,3 +19,7 @@ export declare function download(engine: PoolEngine, alias: string, remotePath:
18
19
  }>;
19
20
  /** List a remote directory (file browser). */
20
21
  export declare function ls(engine: PoolEngine, alias: string, path: string): Promise<RemoteDirEntry[]>;
22
+ /** Create a remote directory chain (with a 1-RTT stat fast path and prefix cache). */
23
+ export declare function ensureRemoteDir(sftp: SFTPWrapper, remote: string, ensuredDirs?: Set<string>): Promise<void>;
24
+ /** One fastPut/fastGet transfer with throttled progress (the two directions share everything but the verb). */
25
+ export declare function fastTransfer(sftp: SFTPWrapper, kind: 'put' | 'get', src: string, dst: string, concurrency: number, onProgress?: (progress: TransferProgress) => void): Promise<void>;
@@ -49,15 +49,17 @@ export declare class TerminalSessionRegistry {
49
49
  private bind;
50
50
  /** Remove a socket from its session, keeping the shell alive. */
51
51
  private detach;
52
- /** End the session a socket is attached to (explicit close from the view). */
52
+ /** End the session and close every socket still attached to it. */
53
53
  private end;
54
54
  /** Mark a session exited and keep it briefly so a reattaching view sees it. */
55
55
  private finish;
56
- /** Append output to the replay buffer, trimmed to the byte cap. */
56
+ /** Keep at most `maxBytes` from the tail of `data` on a valid UTF-8 boundary. */
57
+ private trimTailToUtf8Bytes;
58
+ /** Append output to the O(1) replay ring, trimmed to the byte cap. */
57
59
  private pushOutput;
58
60
  /** Broadcast one frame to every attached socket, honoring backpressure. */
59
61
  private send;
60
- private sendTo;
62
+ private sendPayload;
61
63
  /** Pause while any attached socket is backed up; resume once all drained. */
62
64
  private applyBackpressure;
63
65
  /** Answer a keyboard-interactive challenge through whoever is attached. */
@@ -2,10 +2,11 @@
2
2
  * dsh-ssh — host half. Mounts the SSH engine (persistent ssh2 connection
3
3
  * pool, exec / PTY shell / SFTP / tunnels / cluster), the /api/dsh-ssh route
4
4
  * family plus the terminal WebSocket upgrade, the agent tools (ssh_list,
5
- * ssh_exec, ssh_upload, ssh_download, ssh_tunnel, ssh_cluster), and a
6
- * system-prompt announcement. The browser half (./client) renders the host
7
- * manager and web terminal. Everything rides official NPM SDK packages —
8
- * no dsh source changes.
5
+ * ssh_exec, ssh_upload, ssh_download, ssh_tunnel, ssh_cluster), a
6
+ * system-prompt announcement, and the `dshSsh` cordis service a sibling plugin
7
+ * injects to reuse the host inventory and the connection pool. The browser half
8
+ * (./client) renders the host manager and web terminal. Everything rides
9
+ * official NPM SDK packages — no dsh source changes.
9
10
  */
10
11
  import type { Context } from '@deepseek-ai/cordis';
11
12
  import z from '@deepseek-ai/schemastery';
@@ -84,7 +85,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
84
85
  /** Model-facing announcement: plugin presence, capabilities, and limits. */
85
86
  export declare const SSH_GUIDANCE = "\u672C\u673A\u5DF2\u5B89\u88C5 dsh-ssh \u63D2\u4EF6\uFF08DSH \u8FDC\u7A0B SSH \u8FD0\u7EF4\uFF09\uFF1A\u4FA7\u8FB9\u680F\u300CSSH\u300D\u5165\u53E3\uFF1B\u5728 dsh-web \u63D2\u4EF6\u5168\u5BB6\u6876\u4ED3\u5E93\uFF08packages/dsh-ssh\uFF09\u7EDF\u4E00\u7EF4\u62A4\u3002\u80FD\u529B\uFF1A\u4E3B\u673A\u914D\u7F6E\u5B58 $DSH_HOME/dsh-ssh.json\uFF08\u9ED8\u8BA4 ~/.dsh\uFF09\uFF08\u53EF\u4ECE ~/.ssh/config \u5BFC\u5165\uFF09\uFF1B\u6301\u4E45\u8FDE\u63A5\u6C60\u590D\u7528\u957F\u8FDE\u63A5\uFF08\u7A7A\u95F2 30 \u5206\u949F\u81EA\u52A8\u65AD\u5F00\uFF09\uFF1Bssh_list \u5217\u51FA\u4E3B\u673A\u3001ssh_exec \u6267\u884C\u8FDC\u7A0B\u547D\u4EE4\u3001ssh_upload/ssh_download \u4F20\u8F93\u6587\u4EF6\u3001ssh_tunnel \u672C\u5730\u7AEF\u53E3\u8F6C\u53D1\uFF08\u8BBF\u95EE\u8FDC\u7A0B\u6570\u636E\u5E93/\u5185\u7F51\u670D\u52A1\uFF09\u3001ssh_cluster \u6309 aliases/environment/tags \u81F3\u5C11\u4E00\u79CD\u975E\u7A7A selector \u7B5B\u9009\u540E\u96C6\u7FA4\u5E76\u53D1\u6267\u884C\uFF1B\u652F\u6301\u5BC6\u94A5/\u5BC6\u7801/ssh-agent \u8BA4\u8BC1\u3001passphrase \u5BC6\u94A5\u3001ProxyJump \u8DF3\u677F\u673A\uFF08\u522B\u540D\u6216 [user@]host[:port] \u5730\u5740\uFF09\u4E0E OpenSSH \u8BED\u4E49\u7684 ProxyCommand\uFF08\u8DF3\u8FC7\u5821\u5792\u673A\u5BA2\u6237\u7AEF\u573A\u666F\uFF0C\u53EA\u80FD\u7531\u7528\u6237\u5728 GUI \u914D\u7F6E\uFF0Cagent \u4E0D\u53EF\u5199\uFF09\uFF1BWeb \u7EC8\u7AEF\u8D70 WebSocket\u3002\u9650\u5236\uFF1A\u4E3B\u673A\u64CD\u4F5C\u7531\u7528\u6237\u5728 GUI \u4E2D\u914D\u7F6E\u540E agent \u65B9\u53EF\u4F7F\u7528\uFF1B\u5BC6\u7801\u4EE5\u660E\u6587\u5B58\u5728\u7528\u6237\u4E3B\u76EE\u5F55\u79C1\u6709\u6587\u4EF6\uFF08\u6743\u9650 0600\uFF09\uFF1B\u547D\u4EE4\u8F93\u51FA\u539F\u6837\u8FD4\u56DE\u3001\u53EF\u80FD\u542B\u654F\u611F\u4FE1\u606F\uFF1B\u65AD\u7EBF\u91CD\u8FDE\u53EF\u80FD\u91CD\u653E\u975E\u5E42\u7B49\u547D\u4EE4\uFF1B\u4F20\u8F93/\u6267\u884C\u6D88\u8017\u771F\u5B9E\u8FDC\u7A0B\u8D44\u6E90\uFF0C\u5148\u786E\u8BA4\u518D\u64CD\u4F5C\u3002\u8DEF\u5F84\u533A\u5206\uFF1A\u672C\u673A\uFF08dsh host\uFF09\u4E0A\u7684\u6587\u4EF6\u4E0E\u547D\u4EE4\u4E00\u5F8B\u7528\u672C\u5730\u5DE5\u5177\uFF08read / write / edit / bash\uFF09\uFF0Cssh_* \u5DE5\u5177\u53EA\u9488\u5BF9\u8FDC\u7A0B\u4E3B\u673A\u4E0A\u7684\u8DEF\u5F84\u3002\u7528\u6237\u63D0\u5230\u300CSSH / \u8FDC\u7A0B\u670D\u52A1\u5668 / \u670D\u52A1\u5668\u64CD\u4F5C / \u8DF3\u677F\u673A / \u96A7\u9053 / \u90E8\u7F72 / \u4E0A\u4F20\u4E0B\u8F7D\u300D\u65F6\u5373\u6307\u672C\u63D2\u4EF6\uFF0C\u8BF7\u636E\u6B64\u534F\u4F5C\u3002";
86
87
  /**
87
- * Mount the SSH engine, routes, tools, and announcement.
88
+ * Mount the SSH engine, routes, tools, the sibling-plugin service, and announcement.
88
89
  * @param ctx - host plugin context carrying webServer/tools/systemPrompt.
89
90
  * @param config - resolved plugin config (schema defaults applied by the loader).
90
91
  */
@@ -82,6 +82,44 @@ export interface SshHostSummary {
82
82
  createdAt: number;
83
83
  updatedAt: number;
84
84
  }
85
+ /** Browser-only host projection: includes the key path needed for managed-key matching. */
86
+ export interface SshPanelHostSummary extends SshHostSummary {
87
+ /** Private-key path for key auth; never exposed through the agent/service summary. */
88
+ keyPath?: string;
89
+ }
90
+ /** One managed private-key reference stored in dsh-ssh.json. */
91
+ export interface SshKeyEntry {
92
+ id: string;
93
+ name: string;
94
+ /** Absolute local path; key contents are never copied or read by the plugin. */
95
+ path: string;
96
+ passphrase?: string;
97
+ note?: string;
98
+ createdAt: number;
99
+ updatedAt: number;
100
+ }
101
+ /** Secret-free managed-key projection for the browser. */
102
+ export interface SshKeySummary {
103
+ id: string;
104
+ name: string;
105
+ path: string;
106
+ hasPassphrase: boolean;
107
+ note?: string;
108
+ /** Whether the local path currently exists (stat-only check). */
109
+ exists: boolean;
110
+ /** Aliases whose stored auth.keyPath equals this key's path. */
111
+ usedBy: string[];
112
+ createdAt: number;
113
+ updatedAt: number;
114
+ }
115
+ /** Managed-key create/update payload; null passphrase explicitly clears it on update. */
116
+ export interface SshKeyPayload {
117
+ name?: string;
118
+ path?: string;
119
+ passphrase?: string | null;
120
+ /** Empty string clears the note; omission preserves it on update. */
121
+ note?: string;
122
+ }
85
123
  /** Result of one non-interactive command execution. */
86
124
  export interface ExecResult {
87
125
  success: boolean;
@@ -152,6 +190,8 @@ export interface HostPayload {
152
190
  * stored secrets (the browser never receives them back).
153
191
  */
154
192
  auth?: SshHostEntry['auth'];
193
+ /** Transient managed-key selection resolved Host-side; never persisted on the host row. */
194
+ managedKeyId?: string;
155
195
  proxyJump?: string[];
156
196
  /**
157
197
  * ProxyCommand to store. An empty string or 'none' clears a stored value;
@@ -234,6 +274,7 @@ export type TerminalClientFrame = {
234
274
  export declare const SSH_API_BASE: "/api/dsh-ssh";
235
275
  export declare const SSH_API: {
236
276
  readonly hosts: string;
277
+ readonly keys: string;
237
278
  readonly importSshConfig: string;
238
279
  readonly test: string;
239
280
  readonly exec: string;
@@ -9,6 +9,7 @@
9
9
  import type { WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver';
10
10
  import type { SshEngine } from './engine.ts';
11
11
  import { TerminalSessionRegistry } from './engine/terminal-sessions.ts';
12
+ import { type HostConnectionReader } from './connection-trust.ts';
12
13
  import type { HostStore } from './store.ts';
13
14
  /** Route family dependencies. */
14
15
  export interface SshRoutesDeps {
@@ -16,6 +17,8 @@ export interface SshRoutesDeps {
16
17
  store: HostStore;
17
18
  /** The engine (ops). */
18
19
  engine: SshEngine;
20
+ /** Optional Host connection trust decision, read afresh for each request. */
21
+ connection?: HostConnectionReader;
19
22
  /** Temp dir for upload/download staging (tests inject a sandbox). */
20
23
  stagingDir?: string;
21
24
  /** Upload byte cap override (tests); defaults to MAX_UPLOAD_BYTES. */
@@ -0,0 +1,148 @@
1
+ /**
2
+ * The cordis service `dsh-ssh` publishes to sibling plugins.
3
+ *
4
+ * A plugin that needs the host inventory or the shared connection pool injects
5
+ * this service (`ctx.inject(['dshSsh'], ...)`) instead of importing this
6
+ * package. The face is a thin forwarder over the same `SshEngine` instance the
7
+ * routes, the agent tools and the panel drive, so a consumer shares one host
8
+ * store and one connection pool with the surfaces the user already operates.
9
+ *
10
+ * This module is the published contract and is deliberately import-free: a
11
+ * consuming package restates these declarations verbatim and resolves the
12
+ * service by {@link DSH_SSH_SERVICE} at runtime, so the two packages share a
13
+ * shape without sharing a module. Only the members named here exist — the web
14
+ * terminal, tunnels, cluster runs, directory listing and any streaming log
15
+ * stay behind the plugin's own surfaces.
16
+ *
17
+ * @module @linxin666/dsh-ssh/service
18
+ */
19
+ /** Cordis service name the host half publishes the face under. */
20
+ export declare const DSH_SSH_SERVICE = "dshSsh";
21
+ /** Version of this contract; a consumer restates the number it was built against. */
22
+ export declare const DSH_SSH_API_VERSION = 1;
23
+ /** Authentication flavors a host entry may carry. */
24
+ export type DshSshAuthKind = 'key' | 'password' | 'agent';
25
+ /**
26
+ * One host as the service reports it: the fields the plugin's own
27
+ * `SshHostSummary` already publishes, minus the `proxyCommand` text.
28
+ *
29
+ * The omission is the trust boundary, not an oversight. A ProxyCommand is a
30
+ * shell line the host process executes with its own privileges, so no consumer
31
+ * receives it — the agent tools project it to a boolean for the same reason.
32
+ * Passwords, key passphrases and private-key paths are absent as well: this
33
+ * face describes a host, it never hands out credentials.
34
+ */
35
+ export interface DshSshHost {
36
+ /** Stable, user-chosen identifier every operation addresses. */
37
+ alias: string;
38
+ /** Hostname or IP of the target. */
39
+ host: string;
40
+ /** SSH port. */
41
+ port: number;
42
+ /** Login user. */
43
+ user: string;
44
+ /** Authentication flavor the stored entry uses. */
45
+ auth: DshSshAuthKind;
46
+ /** Whether the configured private-key file exists on this machine (key auth only). */
47
+ keyReady: boolean;
48
+ /** Jump chain: local aliases connected through in order. */
49
+ proxyJump: string[];
50
+ /** Free-form note. */
51
+ description?: string;
52
+ /** Deployment environment label. */
53
+ environment?: string;
54
+ /** Free-form tags. */
55
+ tags: string[];
56
+ /** Physical location note. */
57
+ location?: string;
58
+ /** Whether this host's sessions forward the local ssh-agent. */
59
+ forwardAgent: boolean;
60
+ /** Creation timestamp (ms). */
61
+ createdAt: number;
62
+ /** Last-change timestamp (ms). */
63
+ updatedAt: number;
64
+ }
65
+ /** Ceiling and cancellation for one remote command. */
66
+ export interface DshSshExecOptions {
67
+ /** Wall-clock ceiling for the remote command; the engine default applies when absent. */
68
+ timeoutMs?: number;
69
+ /** Aborting closes the remote channel and settles the call as a cancelled command. */
70
+ signal?: AbortSignal;
71
+ }
72
+ /** One finished remote command. */
73
+ export interface DshSshExecResult {
74
+ /** Whether the command exited zero. */
75
+ success: boolean;
76
+ /** Remote exit code, or null when the channel died without one. */
77
+ exitCode: number | null;
78
+ /** Whether the ceiling stopped the run. */
79
+ timedOut: boolean;
80
+ /** Captured standard output, verbatim. */
81
+ stdout: string;
82
+ /** Captured standard error, verbatim. */
83
+ stderr: string;
84
+ /** Round trip in milliseconds. */
85
+ durationMs: number;
86
+ /** Connection error message when the command never ran. */
87
+ error?: string;
88
+ }
89
+ /** Outcome of one upload. */
90
+ export interface DshSshUploadResult {
91
+ /** Bytes written. */
92
+ bytes: number;
93
+ /** Files written (one for a single-file upload). */
94
+ files: number;
95
+ }
96
+ /** Outcome of one download. */
97
+ export interface DshSshDownloadResult {
98
+ /** Bytes written locally. */
99
+ bytes: number;
100
+ }
101
+ /**
102
+ * The face a sibling plugin receives under the `dshSsh` service name.
103
+ *
104
+ * Every member is a forward: no gate, no cache and no state of its own lives
105
+ * here, so a consumer is refused by exactly what refuses the GUI and the agent
106
+ * tools, and a settings change to the plugin reaches all of them at once.
107
+ */
108
+ export interface DshSshService {
109
+ /** Contract version this face implements. */
110
+ readonly apiVersion: typeof DSH_SSH_API_VERSION;
111
+ /** The host inventory the plugin's own surfaces read. */
112
+ readonly hosts: {
113
+ /** Every configured host, secret-free, in store order. */
114
+ list(): DshSshHost[];
115
+ /** One host by alias, or undefined when the alias is not configured. */
116
+ find(alias: string): DshSshHost | undefined;
117
+ };
118
+ /**
119
+ * Run one command on a host through the shared pool.
120
+ * @param alias - configured host alias.
121
+ * @param command - command line handed to the remote shell.
122
+ * @param options - ceiling and cancellation.
123
+ * @returns the finished command.
124
+ */
125
+ exec(alias: string, command: string, options?: DshSshExecOptions): Promise<DshSshExecResult>;
126
+ /**
127
+ * Upload one local file to an absolute remote path.
128
+ * @param alias - configured host alias.
129
+ * @param localPath - file on this machine (a directory is not part of this face).
130
+ * @param remotePath - absolute destination path on the host.
131
+ * @returns bytes and files written.
132
+ */
133
+ upload(alias: string, localPath: string, remotePath: string): Promise<DshSshUploadResult>;
134
+ /**
135
+ * Download one remote file to a local path.
136
+ * @param alias - configured host alias.
137
+ * @param remotePath - file on the host.
138
+ * @param localPath - destination path on this machine.
139
+ * @returns bytes written.
140
+ */
141
+ download(alias: string, remotePath: string, localPath: string): Promise<DshSshDownloadResult>;
142
+ }
143
+ declare module '@deepseek-ai/cordis' {
144
+ interface Context {
145
+ /** The dsh-ssh face, published while the plugin's master switch is on. */
146
+ dshSsh: DshSshService;
147
+ }
148
+ }
@@ -6,7 +6,7 @@
6
6
  * passphrases) live in this user-owned file in plaintext — same trust model
7
7
  * as ssh-skill's annotated ssh-config comments; document it, never log it.
8
8
  */
9
- import type { HostPayload, ImportResult, SshHostEntry, SshHostSummary } from './protocol.ts';
9
+ import type { HostPayload, ImportResult, SshHostEntry, SshHostSummary, SshKeyPayload, SshKeySummary, SshPanelHostSummary } from './protocol.ts';
10
10
  /** Store file location: $DSH_HOME/dsh-ssh.json (defaults to ~/.dsh). */
11
11
  export declare function storePath(): string;
12
12
  /** The user's standard OpenSSH config path. */
@@ -28,18 +28,31 @@ export declare class HostStore {
28
28
  * @param sshConfigOverride - ssh config path override (tests only).
29
29
  */
30
30
  constructor(path?: string, sshConfigOverride?: string);
31
- /** Load all entries (empty store when the file is absent). */
32
- list(): SshHostEntry[];
31
+ /** Load host entries, optionally filtered by the panel's search text. */
32
+ list(query?: string): SshHostEntry[];
33
33
  /** Find one entry by alias. */
34
34
  find(alias: string): SshHostEntry | undefined;
35
35
  /** Secret-free projection for the browser and agent surfaces. */
36
36
  summarize(entry: SshHostEntry): SshHostSummary;
37
+ /** Browser-only projection that can match a stored path to a managed key. */
38
+ summarizePanel(entry: SshHostEntry): SshPanelHostSummary;
37
39
  /** Create one entry. Throws on alias collision or invalid payload. */
38
40
  create(payload: HostPayload): SshHostEntry;
39
41
  /** Update the fields present in `patch`; unknown aliases throw. */
40
42
  update(alias: string, patch: Partial<HostPayload>): SshHostEntry;
41
43
  /** Remove one entry. */
42
44
  delete(alias: string): void;
45
+ /** List managed keys with file-existence and host-reference metadata. */
46
+ listKeys(): SshKeySummary[];
47
+ /** Create one managed key reference without reading its contents. */
48
+ createKey(payload: SshKeyPayload): SshKeySummary;
49
+ /** Update a managed key; omitted fields and a blank passphrase keep old values. */
50
+ updateKey(id: string, patch: SshKeyPayload): SshKeySummary;
51
+ /** Delete only the managed reference; stored host auth.keyPath values stay untouched. */
52
+ deleteKey(id: string): void;
53
+ /** Resolve a transient managedKeyId into the host's existing keyPath/passphrase shape. */
54
+ resolveManagedKey<T extends HostPayload | Partial<HostPayload>>(payload: T): T;
55
+ private summarizeKey;
43
56
  /**
44
57
  * Import hosts from `~/.ssh/config`: Host blocks with a single non-wildcard
45
58
  * pattern become entries (a missing HostName falls back to the pattern
@@ -50,7 +63,6 @@ export declare class HostStore {
50
63
  * @returns import statistics.
51
64
  */
52
65
  importFromSshConfig(): ImportResult;
53
- private skippedBlocks;
54
66
  /**
55
67
  * Last parsed store keyed by file identity. list/find ride every acquire
56
68
  * and GUI refresh; re-reading and re-parsing the whole file each call is
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-ssh",
3
3
  "description": "Remote SSH operations for the dsh web GUI: host config store (~/.dsh/dsh-ssh.json, import from ~/.ssh/config), a persistent ssh2 connection pool with jump-host support, exec / PTY web terminal / SFTP transfer / local port-forward tunnels / cluster execution, plus agent tools (ssh_list, ssh_exec, ssh_upload, ssh_download, ssh_tunnel, ssh_cluster). Hot-pluggable — mounted via ~/.dsh/cordis.patch.yml + a profile node_modules symlink, no dsh source changes.",
4
- "version": "0.4.19",
4
+ "version": "0.4.21",
5
5
  "icon": "icon.svg",
6
6
  "type": "module",
7
7
  "engines": {