@hyzyn/dsh-tty 0.2.1 → 0.5.0

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.
package/lib/index.d.ts CHANGED
@@ -6,21 +6,36 @@
6
6
  * spawn 帧创建真实 PTY 会话(ctx.subprocess.spawnTerminal,node-pty),
7
7
  * 之后双向透传:input/resize/kill 上行,data/exit/error 下行。
8
8
  *
9
- * 帧协议 v2(JSON 文本帧;sid 维度支持单连接多会话/标签页):
9
+ * 帧协议 v3(JSON 文本帧;sid 维度支持单连接多会话/标签页 + 断线重连):
10
10
  * C→S {t:'spawn', sid?, cols?, rows?, cwd?} 创建本地会话;sid 缺省时宿主生成
11
11
  * C→S {t:'ssh', sid?, cols?, rows?, name? | host, username, ...}
12
12
  * 创建 SSH 会话(ssh2 原生,见 ssh.ts);
13
13
  * name 引用连接簿条目,内联字段可覆盖
14
14
  * C→S {t:'input', sid?, d} 按键/粘贴数据
15
15
  * C→S {t:'resize', sid?, cols, rows} xterm fit 触发
16
- * C→S {t:'kill', sid?} 关闭会话
16
+ * C→S {t:'kill', sid?} 关闭会话(孤儿会话也可跨连接 kill)
17
+ * C→S {t:'sessions'} 列出全局会话(attachable 标记可重连者)
18
+ * C→S {t:'attach', sid} 重连孤儿会话(断线保活窗口内):
19
+ * ready 后紧跟一帧 data 回放输出缓冲
17
20
  * S→C {t:'ready', sid, pid, kind, target?} 会话就绪(ssh 时 pid=null,target=user@host)
18
- * S→C {t:'data', sid, d} 终端输出(utf8 文本)
21
+ * S→C {t:'data', sid, d} 终端输出(utf8 文本,StringDecoder 兜多字节分帧)
19
22
  * S→C {t:'exit', sid, code, signal} PTY 退出事实(恰好一次)
20
23
  * S→C {t:'error', sid?, m} 错误
24
+ * S→C {t:'sessions', list} 会话快照(attachable=true 表示前连接已断、可 attach)
21
25
  * 省略 sid 时按「该连接唯一会话」路由;连接上存在 0 或多个会话时省略 sid 报错。
22
26
  * 旧脚本(spawn 不带 sid)自动兼容:宿主生成 sid,响应帧多带 sid 字段。
23
27
  *
28
+ * 断线保活:客户端正常关面板会先逐个 kill 再断开;因此「WS close 且仍有
29
+ * 存活会话」判定为异常断开(刷新/网络抖动),会话转入孤儿状态保活
30
+ * reconnectGraceSec(默认 120s,0 = 旧行为立即结束),等待新连接 attach
31
+ * 并回放 256KB 环形缓冲;到点由回收器清理。
32
+ *
33
+ * shell 集成(src/shell-integration.ts,0.4.0):spawn 时经 -c 包装层注入
34
+ * OSC 133/7 钩子(zsh ZDOTDIR 桩 / bash --rcfile 桩),输出流解析出命令
35
+ * 边界(tty_capture{last} / tty_expect 早停)与实时 cwd(tty_list)。
36
+ * 辅助路由:/api/dsh-tty/ssh-config(~/.ssh/config 导入候选)、
37
+ * /api/dsh-tty/env-vars(SSH 对话框 env:VAR 下拉,仅变量名)。
38
+ *
24
39
  * M0 探针(scripts/probe.mjs)验证过的三个关键结论:
25
40
  * 1. TERM 必须用 `shell -c 'export TERM=...; exec "$shell"'` 包装层注入——
26
41
  * DSH 的 spawnTerminal 硬编码 node-pty name:"dumb",且 node-pty 里
@@ -31,7 +46,9 @@
31
46
  * 子进程),必须 best-effort:失败降级为对顶层 shell 直接 SIGKILL。
32
47
  */
33
48
  import type { Context } from '@deepseek-ai/cordis';
34
- import type { SshHostEntry } from './ssh.js';
49
+ import type { HostKeyRecord, SshHostEntry } from './ssh.js';
50
+ import type { TunnelSpec } from './tunnels.js';
51
+ export type { HostKeyRecord } from './ssh.js';
35
52
  export interface Config {
36
53
  /** 关闭整个插件。默认开。 */
37
54
  enabled?: boolean;
@@ -49,5 +66,13 @@ export interface Config {
49
66
  cwd?: string;
50
67
  /** SSH 连接簿(面板「+」菜单可选;密码/口令支持 env:VAR 引用)。 */
51
68
  sshHosts?: SshHostEntry[];
69
+ /** 异常断开后会话保活秒数(0 = 立即结束;默认 120,最大 3600)。 */
70
+ reconnectGraceSec?: number;
71
+ /** 已记录的 SSH 主机密钥指纹(TOFU 钉扎,按 host:port 唯一)。 */
72
+ hostKeys?: HostKeyRecord[];
73
+ /** 是否注入 OSC 133/7 shell 集成(命令边界标记 + cwd 上报)。默认开。 */
74
+ shellIntegration?: boolean;
75
+ /** 端口转发隧道(引用连接簿条目;宿主自持连接与重连,见 src/tunnels.ts)。 */
76
+ tunnels?: TunnelSpec[];
52
77
  }
53
78
  export declare const name: string, inject: string[] | undefined, apply: (ctx: Context, config?: Config | undefined) => void;