@fish-under-sea/dsh-ssh-fish 0.0.0-stage → 1.0.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.
Files changed (82) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +23 -0
  3. package/README.en.md +29 -0
  4. package/README.i18n.yaml +6 -0
  5. package/README.md +28 -2
  6. package/README.zh.md +29 -0
  7. package/cordis.patch.yml +12 -0
  8. package/icon.svg +3 -0
  9. package/lib/client.js +16487 -0
  10. package/lib/client.js.map +1 -0
  11. package/lib/index.js +3511 -0
  12. package/lib/types/client/api.d.ts +141 -0
  13. package/lib/types/client/index.d.ts +37 -0
  14. package/lib/types/client/locales.d.ts +164 -0
  15. package/lib/types/client/native-panel.d.ts +70 -0
  16. package/lib/types/client/panel/ClusterTab.d.ts +7 -0
  17. package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
  18. package/lib/types/client/panel/HostsTab.d.ts +25 -0
  19. package/lib/types/client/panel/SshPanel.d.ts +14 -0
  20. package/lib/types/client/panel/TerminalTab.d.ts +22 -0
  21. package/lib/types/client/panel/TransferTab.d.ts +7 -0
  22. package/lib/types/client/panel/TunnelsTab.d.ts +19 -0
  23. package/lib/types/client/panel/controller.d.ts +89 -0
  24. package/lib/types/client/panel/helpers.d.ts +45 -0
  25. package/lib/types/client/panel/xterm.css.d.ts +2 -0
  26. package/lib/types/client/settings-binding.d.ts +61 -0
  27. package/lib/types/dsh-home.d.ts +16 -0
  28. package/lib/types/engine/cluster.d.ts +19 -0
  29. package/lib/types/engine/connection-pool.d.ts +112 -0
  30. package/lib/types/engine/proxy-command.d.ts +36 -0
  31. package/lib/types/engine/pty.d.ts +32 -0
  32. package/lib/types/engine/sftp.d.ts +20 -0
  33. package/lib/types/engine/terminal-sessions.d.ts +67 -0
  34. package/lib/types/engine/tunnel.d.ts +36 -0
  35. package/lib/types/engine.d.ts +89 -0
  36. package/lib/types/http.d.ts +59 -0
  37. package/lib/types/index.d.ts +83 -0
  38. package/lib/types/loopback.d.ts +24 -0
  39. package/lib/types/mount-once.d.ts +55 -0
  40. package/lib/types/protocol.d.ts +239 -0
  41. package/lib/types/routes.d.ts +33 -0
  42. package/lib/types/ssh-config.d.ts +34 -0
  43. package/lib/types/store.d.ts +71 -0
  44. package/lib/types/tool-surface.d.ts +71 -0
  45. package/lib/types/tools.d.ts +42 -0
  46. package/package.json +109 -4
  47. package/src/client/api.ts +562 -0
  48. package/src/client/css-modules.d.ts +5 -0
  49. package/src/client/index.ts +137 -0
  50. package/src/client/locales.ts +338 -0
  51. package/src/client/native-panel.tsx +141 -0
  52. package/src/client/panel/ClusterTab.tsx +123 -0
  53. package/src/client/panel/HostFormDialog.tsx +258 -0
  54. package/src/client/panel/HostsTab.tsx +325 -0
  55. package/src/client/panel/SshPanel.tsx +90 -0
  56. package/src/client/panel/TerminalTab.tsx +330 -0
  57. package/src/client/panel/TransferTab.tsx +232 -0
  58. package/src/client/panel/TunnelsTab.tsx +244 -0
  59. package/src/client/panel/controller.ts +167 -0
  60. package/src/client/panel/helpers.ts +84 -0
  61. package/src/client/panel/panel.module.css +876 -0
  62. package/src/client/panel/xterm.css.ts +2 -0
  63. package/src/client/settings-binding.ts +165 -0
  64. package/src/dsh-home.ts +42 -0
  65. package/src/engine/cluster.ts +60 -0
  66. package/src/engine/connection-pool.ts +543 -0
  67. package/src/engine/proxy-command.ts +248 -0
  68. package/src/engine/pty.ts +78 -0
  69. package/src/engine/sftp.ts +226 -0
  70. package/src/engine/terminal-sessions.ts +280 -0
  71. package/src/engine/tunnel.ts +194 -0
  72. package/src/engine.ts +176 -0
  73. package/src/http.ts +127 -0
  74. package/src/index.ts +234 -0
  75. package/src/loopback.ts +63 -0
  76. package/src/mount-once.ts +142 -0
  77. package/src/protocol.ts +230 -0
  78. package/src/routes.ts +494 -0
  79. package/src/ssh-config.ts +153 -0
  80. package/src/store.ts +419 -0
  81. package/src/tool-surface.ts +95 -0
  82. package/src/tools.ts +404 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * dsh-ssh — host half. Mounts the SSH engine (persistent ssh2 connection
3
+ * pool, exec / PTY shell / SFTP / tunnels / cluster), the /api/dsh-ssh route
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.
9
+ */
10
+ import type { Context } from '@deepseek-ai/cordis';
11
+ import z from '@deepseek-ai/schemastery';
12
+ /** Stable cordis plugin name. */
13
+ export declare const name = "ssh";
14
+ /** Services required before the SSH surfaces can mount. */
15
+ export declare const inject: string[];
16
+ declare module '@deepseek-ai/cordis' {
17
+ interface Events {
18
+ /**
19
+ * Volatile config values were committed into the running instance without a
20
+ * remount (cordis-plugin-loader); dispatched to the owning fiber only.
21
+ * @param paths - the changed config paths, as key arrays.
22
+ * @mode emit
23
+ */
24
+ 'loader/volatile-update'(paths: readonly (readonly string[])[]): void;
25
+ }
26
+ }
27
+ /** Plugin config as a profile patch declares it, before schema resolution. */
28
+ export interface Config {
29
+ /**
30
+ * When true, a system-prompt section announces the SSH plugin to every agent
31
+ * (tools + host store). Off by default to keep prompts clean.
32
+ */
33
+ announceToAgent?: boolean;
34
+ /** Master switch for the plugin (routes, tools, prompt section). */
35
+ enabled?: boolean;
36
+ /**
37
+ * xterm `fontFamily` for the web terminal (issue #577). Empty (default)
38
+ * defers to the CSS chain: `--dsh-ssh-terminal-font`, then the official
39
+ * `--ds-font-family-code` token, then the built-in monospace stack. Set a
40
+ * Nerd Font stack here to render powerline/Nerd glyphs.
41
+ */
42
+ terminalFontFamily?: string;
43
+ }
44
+ /** The stable reference a `volatile()` config field resolves to; its owner updates it in place. */
45
+ interface ConfigRef<T> {
46
+ /** @returns the field's current value. */
47
+ get(): T;
48
+ }
49
+ /** One resolved config field: a live reference, or a plain value from a hand-built context. */
50
+ type ConfigField<T> = ConfigRef<T> | T;
51
+ /** The config the Host hands to {@link apply} — the runtime face of {@link Config}. */
52
+ export interface ResolvedConfig {
53
+ announceToAgent?: ConfigField<boolean>;
54
+ enabled?: ConfigField<boolean>;
55
+ terminalFontFamily?: ConfigField<string>;
56
+ }
57
+ /**
58
+ * Plugin config schema. Under the 0.1.7 settings model this schema IS the
59
+ * entry's settings page: the Host derives one form per profile entry from it
60
+ * and serves it through the shared configuration forms. Every field is
61
+ * `volatile()`, which is what puts it on that page and what lets an edit reach
62
+ * a running instance without a remount: the loader commits the new value into
63
+ * the field's reference and announces `loader/volatile-update` on this fiber.
64
+ */
65
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
66
+ announceToAgent: z<boolean, boolean, "volatile-defined">;
67
+ enabled: z<boolean, boolean, "volatile-defined">;
68
+ terminalFontFamily: z<string, string, "volatile-defined">;
69
+ }>>, Schemastery.ObjectT<NoInfer<{
70
+ announceToAgent: z<boolean, boolean, "volatile-defined">;
71
+ enabled: z<boolean, boolean, "volatile-defined">;
72
+ terminalFontFamily: z<string, string, "volatile-defined">;
73
+ }>>, "plain">;
74
+ /** Model-facing announcement: plugin presence, capabilities, and limits. */
75
+ 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";
76
+ /**
77
+ * Mount the SSH engine, routes, tools, and announcement.
78
+ * @param ctx - host plugin context carrying webServer/tools/systemPrompt.
79
+ * @param config - resolved plugin config (schema defaults applied by the loader).
80
+ */
81
+ export declare const apply: typeof applyImpl;
82
+ declare function applyImpl(ctx: Context, config?: ResolvedConfig): void;
83
+ export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Loopback trust fence shared by the host route families: socket address,
3
+ * Host header, and browser same-origin markers. Packages receive this file as
4
+ * a generated copy via scripts/sync-shared.mjs; edit the shared source and
5
+ * re-run the sync instead of editing a copy.
6
+ *
7
+ * Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
8
+ * remote-web-ui gate), localhost hostnames, plus the browser same-origin
9
+ * markers (sec-fetch-site and Origin) for the request-level fence.
10
+ * @module dsh-web-shared/host/loopback
11
+ */
12
+ import type { IncomingMessage } from 'node:http';
13
+ /** IPv4 127/8 predicate (four decimal octets, first == 127). */
14
+ export declare function isIPv4Loopback(v4: string): boolean;
15
+ /** Whether a socket remote address names the loopback range (127/8, ::1, IPv4-mapped). */
16
+ export declare function isLoopbackAddress(address: string | undefined): boolean;
17
+ /** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
18
+ export declare function isLoopbackHostname(hostname: string): boolean;
19
+ /**
20
+ * Request-level trust fence: a loopback socket address AND a loopback Host
21
+ * header, plus browser same-origin markers. The socket address is
22
+ * authoritative; X-Forwarded-For is never trusted.
23
+ */
24
+ export declare function isLoopbackRequest(request: IncomingMessage): boolean;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Host single-instance guard shared by the plugin family. The family bundle
3
+ * (dsh-web-all / dsh-skins) namespaces every child row id (web-ui-*), so
4
+ * the loader accepts a standalone install of the same package side by side;
5
+ * without this guard the second instance would still re-register the same
6
+ * webserver routes, tools, settings namespaces, and system-prompt sections
7
+ * and fail the boot. mountOnce makes a mount of an already-mounted package a
8
+ * no-op for as long as the first instance lives (the browser half is already
9
+ * deduped by package name in the client module host).
10
+ *
11
+ * A no-op is only safe while the holder is ALIVE. The holder can be disposed
12
+ * long after the refused mount ran its course: the Host reloads a profile by
13
+ * creating the new loader entries before the old ones are torn down (a
14
+ * plugin-manager enable/disable/install write, a settings-driven row reload,
15
+ * HMR), so the new aggregate shell entry mounts its family plugin while the
16
+ * previous entry still owns the name. Dropping that refused mount lost the
17
+ * plugin for good - the previous entry then disposed its own mount, releasing
18
+ * the name with nobody left to take it, and the family row stayed listed as
19
+ * active while its host routes 404ed (the task-board panel showed
20
+ * "board.hostError.notMounted", no degraded record appeared, and only a Host
21
+ * restart recovered it).
22
+ *
23
+ * The refused mount is therefore QUEUED, not dropped, and replayed the moment
24
+ * the holder releases the name - if the waiting fiber is still alive then. The
25
+ * single-instance guarantee is unchanged: exactly one mount is live per
26
+ * package name, and the replay re-enters the guard so a later mount still
27
+ * dedupes against it.
28
+ *
29
+ * The registry rides a global symbol so two module instances of the same
30
+ * package (npm copy vs repository link) still share one verdict. That symbol
31
+ * is a CROSS-REPOSITORY contract, not this file's private state: the four
32
+ * satellite packages (dsh-skins / dsh-pet / dsh-presets /
33
+ * dsh-community-plugins) are separate repositories carrying their own copy of
34
+ * this guard, rebuilt on their own schedule, so the value under `MOUNTED`
35
+ * must keep the shape every published copy reads (a `Set` of package names
36
+ * with `has`/`add`/`delete`). The wait queues this guard added therefore live
37
+ * under their own additive key, and the registry reads back a `Set` even when
38
+ * some other build left a different value there. Changing `MOUNTED`'s shape
39
+ * in place broke that contract once: a satellite's legacy copy created a
40
+ * `Set`, the family's new copy read it as a `Map`, and every family row
41
+ * mounted after it failed with "claims.get is not a function".
42
+ *
43
+ * cordis `ctx.effect` runs its callback immediately and treats the callback's
44
+ * return value as the fiber disposer, so the unmarker is returned, not run.
45
+ */
46
+ /**
47
+ * Wrap a cordis plugin apply so the package runs at most once per process.
48
+ * The first mount registers normally and releases the name when its fiber
49
+ * disposes; a mount refused while that name is held waits for the release and
50
+ * then runs, unless its own fiber disposes first.
51
+ * @param packageName - npm package identity shared by every install source.
52
+ * @param fn - the original plugin apply.
53
+ * @returns an apply of the same shape.
54
+ */
55
+ export declare function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T;
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Wire contract between the host half (routes.ts) and the browser half
3
+ * (client/api.ts). Pure types only — imported by both halves, bundled into
4
+ * each, no runtime identity to share.
5
+ */
6
+ /** Authentication flavors a host entry may carry. */
7
+ export type SshAuthKind = 'key' | 'password' | 'agent';
8
+ /** One stored host entry (the $DSH_HOME/dsh-ssh.json store shape). */
9
+ export interface SshHostEntry {
10
+ /** Stable, user-chosen identifier used by every operation. */
11
+ alias: string;
12
+ /** Hostname or IP of the target. */
13
+ host: string;
14
+ /** SSH port (default 22). */
15
+ port: number;
16
+ /** Login user. */
17
+ user: string;
18
+ /** Authentication. */
19
+ auth: {
20
+ kind: SshAuthKind;
21
+ /** Absolute path to the private key for 'key' auth. */
22
+ keyPath?: string;
23
+ /** Passphrase for an encrypted key. */
24
+ passphrase?: string;
25
+ /** Password for 'password' auth. */
26
+ password?: string;
27
+ /**
28
+ * ssh-agent endpoint for 'agent' auth. A socket path, the special value
29
+ * 'pageant' (PuTTY Pageant on Windows), or undefined for auto-detect
30
+ * (SSH_AUTH_SOCK, then Pageant on Windows).
31
+ */
32
+ agentPath?: string;
33
+ };
34
+ /** Jump chain: local aliases connected through in order (ProxyJump). */
35
+ proxyJump: string[];
36
+ /**
37
+ * OpenSSH-compatible ProxyCommand: a shell command whose stdio becomes the
38
+ * connection transport. Tokens %h (host) / %p (port) / %r (user) / %n (alias)
39
+ * expand before exec and %% is a literal percent; an empty value or 'none'
40
+ * means "no proxy command". Mutually exclusive with a non-empty proxyJump.
41
+ */
42
+ proxyCommand?: string;
43
+ /** Free-form note. */
44
+ description?: string;
45
+ /** Deployment environment label (development / production / ...). */
46
+ environment?: string;
47
+ /** Free-form tags. */
48
+ tags: string[];
49
+ /** Physical location note. */
50
+ location?: string;
51
+ createdAt: number;
52
+ updatedAt: number;
53
+ }
54
+ /** Public (secret-free) projection of an entry, safe for the browser/agent. */
55
+ export interface SshHostSummary {
56
+ alias: string;
57
+ host: string;
58
+ port: number;
59
+ user: string;
60
+ auth: SshAuthKind;
61
+ /** Whether the key path exists on the host machine (key auth only). */
62
+ keyReady: boolean;
63
+ proxyJump: string[];
64
+ /** Configured ProxyCommand, echoed to the browser so the form can edit it. */
65
+ proxyCommand?: string;
66
+ description?: string;
67
+ environment?: string;
68
+ tags: string[];
69
+ location?: string;
70
+ createdAt: number;
71
+ updatedAt: number;
72
+ }
73
+ /** Result of one non-interactive command execution. */
74
+ export interface ExecResult {
75
+ success: boolean;
76
+ /** Remote exit code, or null when the channel died without one. */
77
+ exitCode: number | null;
78
+ timedOut: boolean;
79
+ stdout: string;
80
+ stderr: string;
81
+ /** Wall-clock duration of the round trip in ms. */
82
+ durationMs: number;
83
+ /** Connection error message when the command never ran. */
84
+ error?: string;
85
+ }
86
+ /** One server entry in a cluster run. */
87
+ export interface ClusterResult {
88
+ alias: string;
89
+ ok: boolean;
90
+ exitCode?: number | null;
91
+ timedOut?: boolean;
92
+ stdout?: string;
93
+ stderr?: string;
94
+ durationMs?: number;
95
+ error?: string;
96
+ }
97
+ /** SFTP transfer progress frame (upload stream). */
98
+ export interface TransferProgress {
99
+ phase: 'connecting' | 'transferring' | 'done' | 'error';
100
+ file: string;
101
+ transferred: number;
102
+ total: number;
103
+ percent: number;
104
+ speedBps?: number;
105
+ error?: string;
106
+ }
107
+ /** One active local port-forward tunnel. */
108
+ export interface TunnelInfo {
109
+ id: string;
110
+ alias: string;
111
+ localPort: number;
112
+ remoteHost: string;
113
+ remotePort: number;
114
+ state: 'forwarding' | 'connecting' | 'failed';
115
+ error?: string;
116
+ startedAt: number;
117
+ }
118
+ /** One directory listing entry (remote file browser). */
119
+ export interface RemoteDirEntry {
120
+ name: string;
121
+ type: 'dir' | 'file' | 'other';
122
+ size: number;
123
+ mtimeMs: number;
124
+ mode?: number;
125
+ }
126
+ /** Test-connection outcome. */
127
+ export interface TestResult {
128
+ ok: boolean;
129
+ latencyMs?: number;
130
+ error?: string;
131
+ }
132
+ /** Host edit payload (create/update); 'alias' comes from the URL for updates. */
133
+ export interface HostPayload {
134
+ alias?: string;
135
+ host: string;
136
+ port?: number;
137
+ user: string;
138
+ /**
139
+ * Authentication. Required on create; on update an omitted auth keeps the
140
+ * stored secrets (the browser never receives them back).
141
+ */
142
+ auth?: SshHostEntry['auth'];
143
+ proxyJump?: string[];
144
+ /**
145
+ * ProxyCommand to store. An empty string or 'none' clears a stored value;
146
+ * omitting the key leaves it untouched (PATCH semantics).
147
+ */
148
+ proxyCommand?: string;
149
+ description?: string;
150
+ environment?: string;
151
+ tags?: string[];
152
+ location?: string;
153
+ }
154
+ /** Why one ssh_config Host block was not imported. */
155
+ export type ImportSkipReason = 'wildcard' | 'existing' | 'match' | 'invalid';
156
+ /** One skipped ssh_config block and the reason it could not be imported. */
157
+ export interface ImportSkipBlock {
158
+ /** Host pattern (or '`Match …`' label) that was skipped. */
159
+ name: string;
160
+ reason: ImportSkipReason;
161
+ }
162
+ /** Import outcome from ~/.ssh/config. */
163
+ export interface ImportResult {
164
+ parsed: number;
165
+ added: number;
166
+ skipped: number;
167
+ /** Every skipped block with its reason, in scan order and deduplicated by name. */
168
+ skippedBlocks: ImportSkipBlock[];
169
+ }
170
+ /** JSON error body used by every route. */
171
+ export interface ApiErrorBody {
172
+ error: string;
173
+ }
174
+ /** WebSocket terminal protocol frames (host -> client and client -> host). */
175
+ export type TerminalServerFrame =
176
+ /** The shell is up; `sessionId` reattaches to it after a view detach. */
177
+ {
178
+ type: 'ready';
179
+ alias: string;
180
+ sessionId: string;
181
+ } | {
182
+ type: 'output';
183
+ data: string;
184
+ } | {
185
+ type: 'exit';
186
+ code: number | null;
187
+ error?: string;
188
+ } | {
189
+ type: 'auth_prompt';
190
+ name: string;
191
+ instructions: string;
192
+ prompts: Array<{
193
+ prompt: string;
194
+ echo: boolean;
195
+ }>;
196
+ };
197
+ export type TerminalClientFrame = {
198
+ type: 'input';
199
+ data: string;
200
+ } | {
201
+ type: 'resize';
202
+ cols: number;
203
+ rows: number;
204
+ } | {
205
+ type: 'auth_response';
206
+ responses: string[];
207
+ }
208
+ /** Leave the socket while the host keeps the shell alive for a reattach. */
209
+ | {
210
+ type: 'detach';
211
+ }
212
+ /** End the session outright (the view's disconnect control). */
213
+ | {
214
+ type: 'close';
215
+ };
216
+ /** Route paths the client calls (shared literals). */
217
+ export declare const SSH_API_BASE: "/api/dsh-ssh";
218
+ export declare const SSH_API: {
219
+ readonly hosts: string;
220
+ readonly importSshConfig: string;
221
+ readonly test: string;
222
+ readonly exec: string;
223
+ readonly cluster: string;
224
+ readonly upload: string;
225
+ readonly download: string;
226
+ readonly ls: string;
227
+ readonly tunnel: string;
228
+ readonly terminal: string;
229
+ };
230
+ /** NDJSON transfer stream line shapes (upload). */
231
+ export type TransferStreamLine = {
232
+ type: 'progress';
233
+ progress: TransferProgress;
234
+ } | {
235
+ type: 'result';
236
+ ok: boolean;
237
+ transferredBytes?: number;
238
+ error?: string;
239
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The /api/dsh-ssh route family: host CRUD, exec, cluster, SFTP transfer
3
+ * (NDJSON progress stream for uploads, binary stream for downloads), remote
4
+ * listing, tunnels, and the WebSocket PTY terminal upgrade. Every route
5
+ * carries a loopback-only trust fence (plus browser same-origin markers) —
6
+ * these endpoints execute commands on remote servers, so LAN-exposed dsh web
7
+ * deployments must not serve them.
8
+ */
9
+ import type { WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver';
10
+ import type { SshEngine } from './engine.ts';
11
+ import { TerminalSessionRegistry } from './engine/terminal-sessions.ts';
12
+ import type { HostStore } from './store.ts';
13
+ /** Route family dependencies. */
14
+ export interface SshRoutesDeps {
15
+ /** The host store (CRUD). */
16
+ store: HostStore;
17
+ /** The engine (ops). */
18
+ engine: SshEngine;
19
+ /** Temp dir for upload/download staging (tests inject a sandbox). */
20
+ stagingDir?: string;
21
+ /** Upload byte cap override (tests); defaults to MAX_UPLOAD_BYTES. */
22
+ maxUploadBytes?: number;
23
+ }
24
+ /**
25
+ * Build every /api/dsh-ssh route (exact paths) plus the terminal upgrade.
26
+ * @param deps - store, engine, staging dir.
27
+ * @returns routes and the upgrade route.
28
+ */
29
+ export declare function makeRoutes(deps: SshRoutesDeps): {
30
+ routes: WebRoute[];
31
+ upgrade: WebUpgradeRoute;
32
+ terminalSessions: TerminalSessionRegistry;
33
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Minimal `~/.ssh/config` reader for the one-shot host import: Host blocks with
3
+ * `Include` expansion and explicit skip reasons. Values stay raw strings; the
4
+ * store maps them onto a HostPayload.
5
+ *
6
+ * Deliberate simplifications (documented in the package README):
7
+ * - `Match` blocks are skipped — their options are conditional and must never
8
+ * merge into the Host block above them.
9
+ * - A multi-pattern `Host a b` line only exposes its first pattern.
10
+ * - Include pathnames accept `~`, globs, and several whitespace-separated
11
+ * pathnames, but not environment variables, `%` tokens, or quoting.
12
+ * - Relative Include pathnames resolve against the directory of the config
13
+ * file the import started from (OpenSSH: `~/.ssh` for a user config).
14
+ * - A file that already contributed lines is never read twice, which doubles
15
+ * as the Include cycle guard.
16
+ */
17
+ import type { ImportSkipBlock } from './protocol.ts';
18
+ /** One parsed Host block. */
19
+ export interface SshBlock {
20
+ /** Raw Host line value (may hold several whitespace-separated patterns). */
21
+ pattern: string;
22
+ /** Lowercased option key/value pairs; the last occurrence of a key wins. */
23
+ props: Record<string, string>;
24
+ }
25
+ /** One config file read, with every Include expanded in place. */
26
+ export interface SshConfigRead {
27
+ blocks: SshBlock[];
28
+ skipped: ImportSkipBlock[];
29
+ }
30
+ /**
31
+ * Parse one ssh_config file (Include expanded) into Host blocks plus the
32
+ * `Match` blocks that were deliberately skipped.
33
+ */
34
+ export declare function readSshConfigBlocks(configPath: string): SshConfigRead;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Host config store: one JSON file (`$DSH_HOME/dsh-ssh.json`, defaulting
3
+ * to `~/.dsh`) holding every
4
+ * SSH host entry, written atomically (tmp + rename). Also parses the user's
5
+ * standard `~/.ssh/config` for one-shot import. Secrets (passwords,
6
+ * passphrases) live in this user-owned file in plaintext — same trust model
7
+ * as ssh-skill's annotated ssh-config comments; document it, never log it.
8
+ */
9
+ import type { HostPayload, ImportResult, SshHostEntry, SshHostSummary } from './protocol.ts';
10
+ /** Store file location: $DSH_HOME/dsh-ssh.json (defaults to ~/.dsh). */
11
+ export declare function storePath(): string;
12
+ /** The user's standard OpenSSH config path. */
13
+ export declare function sshConfigPath(): string;
14
+ /** Validate the wire shape of a host payload; returns a message or undefined. */
15
+ export declare function validateHostPayload(payload: unknown): string | undefined;
16
+ /** Validate an alias for creation. */
17
+ export declare function validateAlias(alias: string): string | undefined;
18
+ /**
19
+ * The host store. Pure file I/O — no cordis dependency, unit-testable.
20
+ */
21
+ export declare class HostStore {
22
+ /** The JSON file path. */
23
+ readonly path: string;
24
+ /** Optional override of the ~/.ssh/config path (tests). */
25
+ private readonly sshConfigOverride;
26
+ /**
27
+ * @param path - store file path (defaults to the standard location).
28
+ * @param sshConfigOverride - ssh config path override (tests only).
29
+ */
30
+ constructor(path?: string, sshConfigOverride?: string);
31
+ /** Load all entries (empty store when the file is absent). */
32
+ list(): SshHostEntry[];
33
+ /** Find one entry by alias. */
34
+ find(alias: string): SshHostEntry | undefined;
35
+ /** Secret-free projection for the browser and agent surfaces. */
36
+ summarize(entry: SshHostEntry): SshHostSummary;
37
+ /** Create one entry. Throws on alias collision or invalid payload. */
38
+ create(payload: HostPayload): SshHostEntry;
39
+ /** Update the fields present in `patch`; unknown aliases throw. */
40
+ update(alias: string, patch: Partial<HostPayload>): SshHostEntry;
41
+ /** Remove one entry. */
42
+ delete(alias: string): void;
43
+ /**
44
+ * Import hosts from `~/.ssh/config`: Host blocks with a single non-wildcard
45
+ * pattern become entries (a missing HostName falls back to the pattern
46
+ * itself; key auth via IdentityFile; jump hosts via ProxyJump; ProxyCommand
47
+ * kept verbatim). `Include` files are expanded, and `Match` blocks,
48
+ * wildcard patterns, and aliases that already exist are skipped with a
49
+ * reason instead of silently disappearing.
50
+ * @returns import statistics.
51
+ */
52
+ importFromSshConfig(): ImportResult;
53
+ private skippedBlocks;
54
+ /**
55
+ * Last parsed store keyed by file identity. list/find ride every acquire
56
+ * and GUI refresh; re-reading and re-parsing the whole file each call is
57
+ * wasted work when the file has not changed. Any save invalidates.
58
+ */
59
+ private cache;
60
+ private load;
61
+ private save;
62
+ }
63
+ /** Normalize an agent endpoint for storage: trim, expand `~`, and resolve the SSH_AUTH_SOCK token. */
64
+ export declare function normalizeAgentPath(agentPath: string | undefined): string | undefined;
65
+ /**
66
+ * Normalize a ProxyCommand for storage: trim, and treat an empty value or
67
+ * OpenSSH's `none` keyword as "no proxy command" (an explicit clear).
68
+ */
69
+ export declare function normalizeProxyCommand(raw: string | undefined): string | undefined;
70
+ /** Expand a leading `~` in a filesystem path. */
71
+ export declare function expandHome(path: string): string;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Family-shared tool-surface conventions for the packages that register
3
+ * model-facing tools.
4
+ *
5
+ * One home for the prompt-section placement and the visibility gate this
6
+ * family previously restated per package.
7
+ *
8
+ * Modelled on the official tool packages:
9
+ * - `@deepseek-ai/dsh-tool-subagent` renders its section through
10
+ * `tools.get(name, context.scope) === undefined ? '' : text`, so guidance
11
+ * disappears together with a restricted tool.
12
+ * - 21 of the 22 official tool packages register their tools GLOBALLY and gate
13
+ * them with a setting, not per agent. Only the Agent Teams tool package —
14
+ * whose tools belong to one membership — installs into each `agent.ctx`.
15
+ * This family follows the majority: registration stays global so the
16
+ * registry's per-scope `restrict()` mask (which filters inherited global
17
+ * tools and REJECTS scope-local names) can still withhold these tools.
18
+ *
19
+ * Structural types only: this copy lands in packages that do not all depend on
20
+ * the same SDK service packages.
21
+ */
22
+ /**
23
+ * Prompt-section order for each package's tool guidance.
24
+ *
25
+ * These sit in the family band between the deployment persona and the SDK's
26
+ * `PLAN_POLICY` (500). Values are owned here rather than written per package so
27
+ * the host plugins whose guidance shares one prompt cannot drift into an
28
+ * accidental tie.
29
+ */
30
+ export declare const PLUGIN_TOOL_SECTION_ORDERS: {
31
+ readonly ssh: 150;
32
+ readonly 'task-board': 200;
33
+ };
34
+ /** One plugin id keyed by {@link PLUGIN_TOOL_SECTION_ORDERS}. */
35
+ export type PluginToolSectionId = keyof typeof PLUGIN_TOOL_SECTION_ORDERS;
36
+ /**
37
+ * Order of an external provider extension's own guidance section, right after
38
+ * the band of the plugin it extends.
39
+ *
40
+ * An extension names itself, not the plugin it plugs into, so its order stays
41
+ * out of {@link PLUGIN_TOOL_SECTION_ORDERS}: every package's copy of this module
42
+ * then carries no provider id. The slot still has one owner and cannot collide
43
+ * with a host plugin's band.
44
+ */
45
+ export declare const EXTENSION_TOOL_SECTION_ORDER = 210;
46
+ /**
47
+ * The scoped tool lookup a section provider needs: the registry read for one
48
+ * assembly's scope. Matches `ctx.tools.get(name, scope)`.
49
+ */
50
+ export interface ScopedToolLookup {
51
+ get(name: string, scope?: unknown): unknown;
52
+ }
53
+ /** One assembly context carrying the scope the section is rendered for. */
54
+ export interface SectionScopeContext {
55
+ scope?: unknown;
56
+ }
57
+ /**
58
+ * Build a section provider that renders \`text\` only while at least one of
59
+ * \`toolNames\` is visible to the rendering scope.
60
+ *
61
+ * The native convention: a tool that a restriction, a preset, or a missing
62
+ * registry removed must not leave guidance behind telling the model to call it.
63
+ * An unreadable registry renders the text unchanged — guidance that outlives a
64
+ * momentary read failure is recoverable; guidance for a tool that is gone is
65
+ * not.
66
+ * @param tools - the scoped tool registry, when the deployment serves one.
67
+ * @param toolNames - registered names the guidance describes.
68
+ * @param text - the guidance rendered while they are reachable.
69
+ * @returns the section text provider.
70
+ */
71
+ export declare function visibleToolText(tools: ScopedToolLookup | undefined, toolNames: readonly string[], text: string): (context: SectionScopeContext) => string;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Agent tools: the DSH-native counterpart of ssh-skill's CLI. Every tool
3
+ * talks to the same engine the web UI uses, so a host configured in the GUI
4
+ * is immediately operable by any agent, and vice versa.
5
+ */
6
+ import type { SshEngine } from './engine.ts';
7
+ import type { SshAuthKind, SshHostSummary } from './protocol.ts';
8
+ /**
9
+ * One host row for the agent surface. The ProxyCommand STRING is deliberately
10
+ * projected to a boolean: the command may embed credentials for a bastion
11
+ * client, and the model only needs to know that the host goes through one.
12
+ */
13
+ export interface AgentHostRow {
14
+ alias: string;
15
+ host: string;
16
+ port: number;
17
+ user: string;
18
+ auth: SshAuthKind;
19
+ keyReady: boolean;
20
+ proxyJump: string[];
21
+ proxyCommandConfigured: boolean;
22
+ description?: string;
23
+ environment?: string;
24
+ tags: string[];
25
+ location?: string;
26
+ createdAt: number;
27
+ updatedAt: number;
28
+ }
29
+ /** Project one summary onto the agent-facing row shape. */
30
+ export declare function toAgentHostRow(host: SshHostSummary): AgentHostRow;
31
+ /** The host-list tool. */
32
+ export declare function sshListTool(engine: SshEngine): import("@deepseek-ai/dsh-tools").ToolDefinition;
33
+ /** The command-execution tool. */
34
+ export declare function sshExecTool(engine: SshEngine): import("@deepseek-ai/dsh-tools").ToolDefinition;
35
+ /** The upload tool. */
36
+ export declare function sshUploadTool(engine: SshEngine): import("@deepseek-ai/dsh-tools").ToolDefinition;
37
+ /** The download tool. */
38
+ export declare function sshDownloadTool(engine: SshEngine): import("@deepseek-ai/dsh-tools").ToolDefinition;
39
+ /** The tunnel tool. */
40
+ export declare function sshTunnelTool(engine: SshEngine): import("@deepseek-ai/dsh-tools").ToolDefinition;
41
+ /** The cluster tool. */
42
+ export declare function sshClusterTool(engine: SshEngine): import("@deepseek-ai/dsh-tools").ToolDefinition;