@fish-under-sea/dsh-ssh-fish 0.0.0-stage → 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.
Files changed (80) hide show
  1. package/LICENSE +202 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +98 -2
  4. package/README.zh.md +99 -0
  5. package/cordis.patch.yml +12 -0
  6. package/icon.svg +3 -0
  7. package/lib/client.js +16487 -0
  8. package/lib/client.js.map +1 -0
  9. package/lib/index.js +3511 -0
  10. package/lib/types/client/api.d.ts +141 -0
  11. package/lib/types/client/index.d.ts +37 -0
  12. package/lib/types/client/locales.d.ts +164 -0
  13. package/lib/types/client/native-panel.d.ts +70 -0
  14. package/lib/types/client/panel/ClusterTab.d.ts +7 -0
  15. package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
  16. package/lib/types/client/panel/HostsTab.d.ts +25 -0
  17. package/lib/types/client/panel/SshPanel.d.ts +14 -0
  18. package/lib/types/client/panel/TerminalTab.d.ts +22 -0
  19. package/lib/types/client/panel/TransferTab.d.ts +7 -0
  20. package/lib/types/client/panel/TunnelsTab.d.ts +19 -0
  21. package/lib/types/client/panel/controller.d.ts +89 -0
  22. package/lib/types/client/panel/helpers.d.ts +45 -0
  23. package/lib/types/client/panel/xterm.css.d.ts +2 -0
  24. package/lib/types/client/settings-binding.d.ts +61 -0
  25. package/lib/types/dsh-home.d.ts +16 -0
  26. package/lib/types/engine/cluster.d.ts +19 -0
  27. package/lib/types/engine/connection-pool.d.ts +112 -0
  28. package/lib/types/engine/proxy-command.d.ts +36 -0
  29. package/lib/types/engine/pty.d.ts +32 -0
  30. package/lib/types/engine/sftp.d.ts +20 -0
  31. package/lib/types/engine/terminal-sessions.d.ts +67 -0
  32. package/lib/types/engine/tunnel.d.ts +36 -0
  33. package/lib/types/engine.d.ts +89 -0
  34. package/lib/types/http.d.ts +59 -0
  35. package/lib/types/index.d.ts +83 -0
  36. package/lib/types/loopback.d.ts +24 -0
  37. package/lib/types/mount-once.d.ts +55 -0
  38. package/lib/types/protocol.d.ts +239 -0
  39. package/lib/types/routes.d.ts +33 -0
  40. package/lib/types/ssh-config.d.ts +34 -0
  41. package/lib/types/store.d.ts +71 -0
  42. package/lib/types/tool-surface.d.ts +71 -0
  43. package/lib/types/tools.d.ts +42 -0
  44. package/package.json +106 -4
  45. package/src/client/api.ts +562 -0
  46. package/src/client/css-modules.d.ts +5 -0
  47. package/src/client/index.ts +137 -0
  48. package/src/client/locales.ts +338 -0
  49. package/src/client/native-panel.tsx +141 -0
  50. package/src/client/panel/ClusterTab.tsx +123 -0
  51. package/src/client/panel/HostFormDialog.tsx +258 -0
  52. package/src/client/panel/HostsTab.tsx +325 -0
  53. package/src/client/panel/SshPanel.tsx +90 -0
  54. package/src/client/panel/TerminalTab.tsx +330 -0
  55. package/src/client/panel/TransferTab.tsx +232 -0
  56. package/src/client/panel/TunnelsTab.tsx +244 -0
  57. package/src/client/panel/controller.ts +167 -0
  58. package/src/client/panel/helpers.ts +84 -0
  59. package/src/client/panel/panel.module.css +876 -0
  60. package/src/client/panel/xterm.css.ts +2 -0
  61. package/src/client/settings-binding.ts +165 -0
  62. package/src/dsh-home.ts +42 -0
  63. package/src/engine/cluster.ts +60 -0
  64. package/src/engine/connection-pool.ts +543 -0
  65. package/src/engine/proxy-command.ts +248 -0
  66. package/src/engine/pty.ts +78 -0
  67. package/src/engine/sftp.ts +226 -0
  68. package/src/engine/terminal-sessions.ts +280 -0
  69. package/src/engine/tunnel.ts +194 -0
  70. package/src/engine.ts +176 -0
  71. package/src/http.ts +127 -0
  72. package/src/index.ts +234 -0
  73. package/src/loopback.ts +63 -0
  74. package/src/mount-once.ts +142 -0
  75. package/src/protocol.ts +230 -0
  76. package/src/routes.ts +494 -0
  77. package/src/ssh-config.ts +153 -0
  78. package/src/store.ts +419 -0
  79. package/src/tool-surface.ts +95 -0
  80. package/src/tools.ts +404 -0
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Cluster tab: run one command across many hosts (aliases / environment /
3
+ * tags filters) and inspect per-host results. Stdout/stderr render in
4
+ * collapsed <details> blocks; status renders as a colored badge.
5
+ */
6
+ import { useState } from 'react'
7
+ import type { SshApi } from '../api.ts'
8
+ import type { ClusterResult } from '../../protocol.ts'
9
+ import { errorMessage, tt } from './helpers.ts'
10
+ import css from './panel.module.css'
11
+
12
+ /** Cluster tab props. */
13
+ export interface ClusterTabProps {
14
+ api: SshApi
15
+ }
16
+
17
+ /** Split a comma-separated input into a trimmed, non-empty string list. */
18
+ function splitList(text: string): string[] {
19
+ return text.split(',').map(part => part.trim()).filter(part => part !== '')
20
+ }
21
+
22
+ /** The cluster execution tab. */
23
+ export function ClusterTab({ api }: ClusterTabProps) {
24
+ const [command, setCommand] = useState('')
25
+ const [aliases, setAliases] = useState('')
26
+ const [environment, setEnvironment] = useState('')
27
+ const [tags, setTags] = useState('')
28
+ const [running, setRunning] = useState(false)
29
+ const [results, setResults] = useState<ClusterResult[] | null>(null)
30
+ const [error, setError] = useState<string | null>(null)
31
+
32
+ const run = async (): Promise<void> => {
33
+ if (command.trim() === '' || running) return
34
+ if (!window.confirm(tt('cluster.confirm'))) return
35
+ setRunning(true)
36
+ setError(null)
37
+ try {
38
+ const aliasList = splitList(aliases)
39
+ const tagList = splitList(tags)
40
+ const outcome = await api.cluster({
41
+ command: command.trim(),
42
+ aliases: aliasList.length > 0 ? aliasList : undefined,
43
+ environment: environment.trim() === '' ? undefined : environment.trim(),
44
+ tags: tagList.length > 0 ? tagList : undefined,
45
+ })
46
+ setResults(outcome)
47
+ } catch (cause) {
48
+ setError(errorMessage(cause))
49
+ } finally {
50
+ setRunning(false)
51
+ }
52
+ }
53
+
54
+ return (
55
+ <div className={css.fillBody}>
56
+ <div className={css.clusterForm}>
57
+ <label className={css.field}>
58
+ <span className={css.fieldLabel}>{tt('cluster.command')}</span>
59
+ <textarea className={css.input + ' ' + css.commandInput} value={command} onChange={event => { setCommand(event.target.value) }} />
60
+ </label>
61
+ <div className={css.clusterFilters}>
62
+ <input className={css.input} placeholder={tt('cluster.aliases')} value={aliases} onChange={event => { setAliases(event.target.value) }} />
63
+ <input className={css.input} placeholder={tt('cluster.environment')} value={environment} onChange={event => { setEnvironment(event.target.value) }} />
64
+ <input className={css.input} placeholder={tt('cluster.tags')} value={tags} onChange={event => { setTags(event.target.value) }} />
65
+ </div>
66
+ <div>
67
+ <button type="button" className={css.primaryButton} disabled={running || command.trim() === ''} onClick={() => { void run() }}>{tt('cluster.run')}</button>
68
+ </div>
69
+ </div>
70
+ {error !== null && <div className={css.banner} data-kind="error">{tt('common.error', { error })}</div>}
71
+ {results === null && error === null && <div className={css.empty}>{tt('cluster.empty')}</div>}
72
+ {results !== null && results.length === 0 && <div className={css.empty}>{tt('cluster.noMatch')}</div>}
73
+ {results !== null && results.length > 0 && (
74
+ <div className={css.tableWrap}>
75
+ <table className={css.table}>
76
+ <thead>
77
+ <tr>
78
+ <th>{tt('cluster.col.alias')}</th>
79
+ <th>{tt('cluster.col.status')}</th>
80
+ <th>{tt('cluster.col.exit')}</th>
81
+ <th>{tt('cluster.col.stdout')}</th>
82
+ <th>{tt('cluster.col.stderr')}</th>
83
+ <th>{tt('cluster.col.error')}</th>
84
+ <th>{tt('cluster.col.duration')}</th>
85
+ </tr>
86
+ </thead>
87
+ <tbody>
88
+ {results.map(result => {
89
+ const status = result.ok ? 'ok' : result.timedOut === true ? 'timeout' : 'fail'
90
+ const label = result.ok ? tt('cluster.ok') : result.timedOut === true ? tt('cluster.timeout') : tt('cluster.fail')
91
+ return (
92
+ <tr key={result.alias}>
93
+ <td className={css.mono}>{result.alias}</td>
94
+ <td><span className={css.badge} data-status={status}>{label}</span></td>
95
+ <td className={css.mono}>{result.exitCode ?? '-'}</td>
96
+ <td>
97
+ {result.stdout !== undefined && result.stdout !== '' && (
98
+ <details className={css.cellDetails}>
99
+ <summary>{tt('cluster.col.stdout')}</summary>
100
+ <pre className={css.cellPre}>{result.stdout}</pre>
101
+ </details>
102
+ )}
103
+ </td>
104
+ <td>
105
+ {result.stderr !== undefined && result.stderr !== '' && (
106
+ <details className={css.cellDetails}>
107
+ <summary>{tt('cluster.col.stderr')}</summary>
108
+ <pre className={css.cellPre}>{result.stderr}</pre>
109
+ </details>
110
+ )}
111
+ </td>
112
+ <td className={css.cellMuted}>{result.error ?? ''}</td>
113
+ <td className={css.mono}>{result.durationMs !== undefined ? result.durationMs + ' ms' : '-'}</td>
114
+ </tr>
115
+ )
116
+ })}
117
+ </tbody>
118
+ </table>
119
+ </div>
120
+ )}
121
+ </div>
122
+ )
123
+ }
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Host form dialog: create/edit one stored host entry. A fixed backdrop with
3
+ * a centered card; Escape and backdrop clicks close it. Secrets (key path,
4
+ * passphrase, password) are never pre-filled when editing (the API only
5
+ * exposes the secret-free summary).
6
+ */
7
+ import { useEffect, useState } from 'react'
8
+ import type { SshApi } from '../api.ts'
9
+ import type { HostPayload, SshAuthKind, SshHostSummary } from '../../protocol.ts'
10
+ import { errorMessage, tt } from './helpers.ts'
11
+ import css from './panel.module.css'
12
+
13
+ /** Host form dialog props. */
14
+ export interface HostFormDialogProps {
15
+ api: SshApi
16
+ /** The host being edited; null/undefined means create. */
17
+ editing?: SshHostSummary | null
18
+ onClose: () => void
19
+ onSaved: (host: SshHostSummary) => void
20
+ }
21
+
22
+ /** The staged form values (all strings; parsed on save). */
23
+ interface FormState {
24
+ alias: string
25
+ host: string
26
+ port: string
27
+ user: string
28
+ authKind: SshAuthKind
29
+ keyPath: string
30
+ passphrase: string
31
+ password: string
32
+ agentPath: string
33
+ proxyJump: string
34
+ proxyCommand: string
35
+ description: string
36
+ environment: string
37
+ tags: string
38
+ location: string
39
+ }
40
+
41
+ /** Split a comma-separated input into a trimmed, non-empty string list. */
42
+ function splitList(text: string): string[] {
43
+ return text.split(',').map(part => part.trim()).filter(part => part !== '')
44
+ }
45
+
46
+ /** Initial form state: the summary's public fields plus empty secrets. */
47
+ function blankOf(editing: SshHostSummary | null | undefined): FormState {
48
+ return {
49
+ alias: editing?.alias ?? '',
50
+ host: editing?.host ?? '',
51
+ port: String(editing?.port ?? 22),
52
+ user: editing?.user ?? '',
53
+ authKind: editing?.auth ?? 'key',
54
+ keyPath: '',
55
+ passphrase: '',
56
+ password: '',
57
+ agentPath: '',
58
+ proxyJump: (editing?.proxyJump ?? []).join(', '),
59
+ proxyCommand: editing?.proxyCommand ?? '',
60
+ description: editing?.description ?? '',
61
+ environment: editing?.environment ?? '',
62
+ tags: (editing?.tags ?? []).join(', '),
63
+ location: editing?.location ?? '',
64
+ }
65
+ }
66
+
67
+ /** The create/edit host modal. */
68
+ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialogProps) {
69
+ const [form, setForm] = useState<FormState>(() => blankOf(editing))
70
+ const [saving, setSaving] = useState(false)
71
+ const [error, setError] = useState<string | null>(null)
72
+
73
+ // Escape closes the dialog.
74
+ useEffect(() => {
75
+ const onKey = (event: KeyboardEvent): void => {
76
+ if (event.key === 'Escape') onClose()
77
+ }
78
+ document.addEventListener('keydown', onKey)
79
+ return () => { document.removeEventListener('keydown', onKey) }
80
+ }, [onClose])
81
+
82
+ const set = <K extends keyof FormState>(key: K, value: FormState[K]): void => {
83
+ setForm(prev => ({ ...prev, [key]: value }))
84
+ }
85
+
86
+ const save = async (): Promise<void> => {
87
+ const alias = form.alias.trim()
88
+ const host = form.host.trim()
89
+ const user = form.user.trim()
90
+ if (alias === '' || host === '' || user === '') {
91
+ setError(tt('form.required'))
92
+ return
93
+ }
94
+ const port = Number(form.port)
95
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
96
+ setError(tt('form.portInvalid'))
97
+ return
98
+ }
99
+ // A password-auth host needs a password on create; when editing, a blank
100
+ // secret field preserves the stored credential instead.
101
+ if (editing == null && form.authKind === 'password' && form.password === '') {
102
+ setError(tt('form.passwordRequired'))
103
+ return
104
+ }
105
+ // Secrets are never echoed back by the API: when editing and the secret
106
+ // fields are left empty, the auth block is omitted so the stored
107
+ // authentication is preserved.
108
+ const secretEmpty = form.authKind === 'password'
109
+ ? form.password === ''
110
+ : form.authKind === 'key'
111
+ ? form.keyPath.trim() === ''
112
+ : form.agentPath.trim() === ''
113
+ const auth: HostPayload['auth'] = editing != null && secretEmpty
114
+ ? undefined
115
+ : form.authKind === 'password'
116
+ ? { kind: 'password', password: form.password }
117
+ : form.authKind === 'key'
118
+ ? { kind: 'key', keyPath: form.keyPath.trim(), passphrase: form.passphrase === '' ? undefined : form.passphrase }
119
+ : { kind: 'agent', agentPath: form.agentPath.trim() === '' ? undefined : form.agentPath.trim() }
120
+ const payload: HostPayload = {
121
+ host,
122
+ port,
123
+ user,
124
+ auth,
125
+ proxyJump: splitList(form.proxyJump),
126
+ // Always sent (never omitted): an empty value is the explicit clear,
127
+ // because the API cannot express "remove this field" any other way.
128
+ proxyCommand: form.proxyCommand.trim(),
129
+ description: form.description.trim() === '' ? undefined : form.description.trim(),
130
+ environment: form.environment.trim() === '' ? undefined : form.environment.trim(),
131
+ tags: splitList(form.tags),
132
+ location: form.location.trim() === '' ? undefined : form.location.trim(),
133
+ }
134
+ setSaving(true)
135
+ setError(null)
136
+ try {
137
+ const saved = editing != null
138
+ ? await api.updateHost(editing.alias, payload)
139
+ : await api.createHost({ ...payload, alias })
140
+ onSaved(saved)
141
+ } catch (cause) {
142
+ setError(errorMessage(cause))
143
+ setSaving(false)
144
+ }
145
+ }
146
+
147
+ return (
148
+ <div className={css.modalBackdrop} onClick={onClose}>
149
+ <div className={css.modal} role="dialog" aria-modal="true" onClick={event => { event.stopPropagation() }}>
150
+ <h3 className={css.modalTitle}>{editing != null ? tt('form.title.edit', { alias: editing.alias }) : tt('form.title.create')}</h3>
151
+ <div className={css.formRow}>
152
+ <label className={css.field}>
153
+ <span className={css.fieldLabel}>{tt('form.alias')}</span>
154
+ <input className={css.input} value={form.alias} disabled={editing != null} onChange={event => { set('alias', event.target.value) }} />
155
+ <span className={css.hint}>{tt('form.aliasHint')}</span>
156
+ </label>
157
+ <label className={css.field}>
158
+ <span className={css.fieldLabel}>{tt('form.host')}</span>
159
+ <input className={css.input} value={form.host} onChange={event => { set('host', event.target.value) }} />
160
+ </label>
161
+ </div>
162
+ <div className={css.formRow}>
163
+ <label className={css.field}>
164
+ <span className={css.fieldLabel}>{tt('form.port')}</span>
165
+ <input className={css.input} type="number" min={1} max={65535} value={form.port} onChange={event => { set('port', event.target.value) }} />
166
+ </label>
167
+ <label className={css.field}>
168
+ <span className={css.fieldLabel}>{tt('form.user')}</span>
169
+ <input className={css.input} value={form.user} onChange={event => { set('user', event.target.value) }} />
170
+ </label>
171
+ </div>
172
+ <div className={css.field}>
173
+ <span className={css.fieldLabel}>{tt('form.auth')}</span>
174
+ <div className={css.radioRow}>
175
+ <label className={css.radioLabel}>
176
+ <input type="radio" name="dsh-ssh-auth" checked={form.authKind === 'key'} onChange={() => { set('authKind', 'key') }} />
177
+ {tt('form.auth.key')}
178
+ </label>
179
+ <label className={css.radioLabel}>
180
+ <input type="radio" name="dsh-ssh-auth" checked={form.authKind === 'password'} onChange={() => { set('authKind', 'password') }} />
181
+ {tt('form.auth.password')}
182
+ </label>
183
+ <label className={css.radioLabel}>
184
+ <input type="radio" name="dsh-ssh-auth" checked={form.authKind === 'agent'} onChange={() => { set('authKind', 'agent') }} />
185
+ {tt('form.auth.agent')}
186
+ </label>
187
+ </div>
188
+ {editing != null && <span className={css.hint}>{tt('form.authKeepHint')}</span>}
189
+ </div>
190
+ {form.authKind === 'key' ? (
191
+ <div className={css.formRow}>
192
+ <label className={css.field}>
193
+ <span className={css.fieldLabel}>{tt('form.keyPath')}</span>
194
+ <input className={css.input} value={form.keyPath} onChange={event => { set('keyPath', event.target.value) }} />
195
+ <span className={css.hint}>{tt('form.keyPathHint')}</span>
196
+ </label>
197
+ <label className={css.field}>
198
+ <span className={css.fieldLabel}>{tt('form.passphrase')}</span>
199
+ <input className={css.input} type="password" value={form.passphrase} onChange={event => { set('passphrase', event.target.value) }} />
200
+ </label>
201
+ </div>
202
+ ) : form.authKind === 'agent' ? (
203
+ <label className={css.field}>
204
+ <span className={css.fieldLabel}>{tt('form.agentPath')}</span>
205
+ <input className={css.input} value={form.agentPath} onChange={event => { set('agentPath', event.target.value) }} />
206
+ <span className={css.hint}>{tt('form.agentPathHint')}</span>
207
+ </label>
208
+ ) : (
209
+ <label className={css.field}>
210
+ <span className={css.fieldLabel}>{tt('form.password')}</span>
211
+ <input className={css.input} type="password" value={form.password} onChange={event => { set('password', event.target.value) }} />
212
+ <span className={css.hint}>{tt('form.passwordHint')}</span>
213
+ </label>
214
+ )}
215
+ <label className={css.field}>
216
+ <span className={css.fieldLabel}>{tt('form.proxyJump')}</span>
217
+ <input className={css.input} value={form.proxyJump} onChange={event => { set('proxyJump', event.target.value) }} />
218
+ <span className={css.hint}>{tt('form.proxyJumpHint')}</span>
219
+ </label>
220
+ <label className={css.field}>
221
+ <span className={css.fieldLabel}>{tt('form.proxyCommand')}</span>
222
+ <input
223
+ className={css.input}
224
+ value={form.proxyCommand}
225
+ placeholder="corp-vpn proxy %h %p %r"
226
+ onChange={event => { set('proxyCommand', event.target.value) }}
227
+ />
228
+ <span className={css.hint}>{tt('form.proxyCommandHint')}</span>
229
+ </label>
230
+ <div className={css.formRow}>
231
+ <label className={css.field}>
232
+ <span className={css.fieldLabel}>{tt('form.environment')}</span>
233
+ <input className={css.input} value={form.environment} onChange={event => { set('environment', event.target.value) }} />
234
+ <span className={css.hint}>{tt('form.environmentHint')}</span>
235
+ </label>
236
+ <label className={css.field}>
237
+ <span className={css.fieldLabel}>{tt('form.location')}</span>
238
+ <input className={css.input} value={form.location} onChange={event => { set('location', event.target.value) }} />
239
+ </label>
240
+ </div>
241
+ <label className={css.field}>
242
+ <span className={css.fieldLabel}>{tt('form.description')}</span>
243
+ <input className={css.input} value={form.description} onChange={event => { set('description', event.target.value) }} />
244
+ </label>
245
+ <label className={css.field}>
246
+ <span className={css.fieldLabel}>{tt('form.tags')}</span>
247
+ <input className={css.input} value={form.tags} onChange={event => { set('tags', event.target.value) }} />
248
+ <span className={css.hint}>{tt('form.tagsHint')}</span>
249
+ </label>
250
+ {error !== null && <p className={css.formError}>{tt('common.error', { error })}</p>}
251
+ <div className={css.modalFooter}>
252
+ <button type="button" className={css.ghostButton} disabled={saving} onClick={onClose}>{tt('form.cancel')}</button>
253
+ <button type="button" className={css.primaryButton} disabled={saving} onClick={() => { void save() }}>{tt('form.save')}</button>
254
+ </div>
255
+ </div>
256
+ </div>
257
+ )
258
+ }