@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.
- package/LICENSE +202 -0
- package/NOTICE +23 -0
- package/README.en.md +29 -0
- package/README.i18n.yaml +6 -0
- package/README.md +28 -2
- package/README.zh.md +29 -0
- package/cordis.patch.yml +12 -0
- package/icon.svg +3 -0
- package/lib/client.js +16487 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +3511 -0
- package/lib/types/client/api.d.ts +141 -0
- package/lib/types/client/index.d.ts +37 -0
- package/lib/types/client/locales.d.ts +164 -0
- package/lib/types/client/native-panel.d.ts +70 -0
- package/lib/types/client/panel/ClusterTab.d.ts +7 -0
- package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
- package/lib/types/client/panel/HostsTab.d.ts +25 -0
- package/lib/types/client/panel/SshPanel.d.ts +14 -0
- package/lib/types/client/panel/TerminalTab.d.ts +22 -0
- package/lib/types/client/panel/TransferTab.d.ts +7 -0
- package/lib/types/client/panel/TunnelsTab.d.ts +19 -0
- package/lib/types/client/panel/controller.d.ts +89 -0
- package/lib/types/client/panel/helpers.d.ts +45 -0
- package/lib/types/client/panel/xterm.css.d.ts +2 -0
- package/lib/types/client/settings-binding.d.ts +61 -0
- package/lib/types/dsh-home.d.ts +16 -0
- package/lib/types/engine/cluster.d.ts +19 -0
- package/lib/types/engine/connection-pool.d.ts +112 -0
- package/lib/types/engine/proxy-command.d.ts +36 -0
- package/lib/types/engine/pty.d.ts +32 -0
- package/lib/types/engine/sftp.d.ts +20 -0
- package/lib/types/engine/terminal-sessions.d.ts +67 -0
- package/lib/types/engine/tunnel.d.ts +36 -0
- package/lib/types/engine.d.ts +89 -0
- package/lib/types/http.d.ts +59 -0
- package/lib/types/index.d.ts +83 -0
- package/lib/types/loopback.d.ts +24 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/lib/types/protocol.d.ts +239 -0
- package/lib/types/routes.d.ts +33 -0
- package/lib/types/ssh-config.d.ts +34 -0
- package/lib/types/store.d.ts +71 -0
- package/lib/types/tool-surface.d.ts +71 -0
- package/lib/types/tools.d.ts +42 -0
- package/package.json +109 -4
- package/src/client/api.ts +562 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +137 -0
- package/src/client/locales.ts +338 -0
- package/src/client/native-panel.tsx +141 -0
- package/src/client/panel/ClusterTab.tsx +123 -0
- package/src/client/panel/HostFormDialog.tsx +258 -0
- package/src/client/panel/HostsTab.tsx +325 -0
- package/src/client/panel/SshPanel.tsx +90 -0
- package/src/client/panel/TerminalTab.tsx +330 -0
- package/src/client/panel/TransferTab.tsx +232 -0
- package/src/client/panel/TunnelsTab.tsx +244 -0
- package/src/client/panel/controller.ts +167 -0
- package/src/client/panel/helpers.ts +84 -0
- package/src/client/panel/panel.module.css +876 -0
- package/src/client/panel/xterm.css.ts +2 -0
- package/src/client/settings-binding.ts +165 -0
- package/src/dsh-home.ts +42 -0
- package/src/engine/cluster.ts +60 -0
- package/src/engine/connection-pool.ts +543 -0
- package/src/engine/proxy-command.ts +248 -0
- package/src/engine/pty.ts +78 -0
- package/src/engine/sftp.ts +226 -0
- package/src/engine/terminal-sessions.ts +280 -0
- package/src/engine/tunnel.ts +194 -0
- package/src/engine.ts +176 -0
- package/src/http.ts +127 -0
- package/src/index.ts +234 -0
- package/src/loopback.ts +63 -0
- package/src/mount-once.ts +142 -0
- package/src/protocol.ts +230 -0
- package/src/routes.ts +494 -0
- package/src/ssh-config.ts +153 -0
- package/src/store.ts +419 -0
- package/src/tool-surface.ts +95 -0
- package/src/tools.ts +404 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** xterm.css text embedded at build-authoring time (the ?raw suffix is not resolvable by the tsdown/rolldown pipeline). Generated file — see the package docs. */
|
|
2
|
+
export const XTERM_CSS: string = "/**\n * Copyright (c) 2014 The xterm.js authors. All rights reserved.\n * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)\n * https://github.com/chjj/term.js\n * @license MIT\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n *\n * Originally forked from (with the author's permission):\n * Fabrice Bellard's javascript vt100 for jslinux:\n * http://bellard.org/jslinux/\n * Copyright (c) 2011 Fabrice Bellard\n * The original design remains. The terminal itself\n * has been extended to include xterm CSI codes, among\n * other features.\n */\n\n/**\n * Default styles for xterm.js\n */\n\n.xterm {\n cursor: text;\n position: relative;\n user-select: none;\n -ms-user-select: none;\n -webkit-user-select: none;\n}\n\n.xterm.focus,\n.xterm:focus {\n outline: none;\n}\n\n.xterm .xterm-helpers {\n position: absolute;\n top: 0;\n /**\n * The z-index of the helpers must be higher than the canvases in order for\n * IMEs to appear on top.\n */\n z-index: 5;\n}\n\n.xterm .xterm-helper-textarea {\n padding: 0;\n border: 0;\n margin: 0;\n /* Move textarea out of the screen to the far left, so that the cursor is not visible */\n position: absolute;\n opacity: 0;\n left: -9999em;\n top: 0;\n width: 0;\n height: 0;\n z-index: -5;\n /** Prevent wrapping so the IME appears against the textarea at the correct position */\n white-space: nowrap;\n overflow: hidden;\n resize: none;\n}\n\n.xterm .composition-view {\n /* TODO: Composition position got messed up somewhere */\n background: #000;\n color: #FFF;\n display: none;\n position: absolute;\n white-space: nowrap;\n z-index: 1;\n}\n\n.xterm .composition-view.active {\n display: block;\n}\n\n.xterm .xterm-viewport {\n /* On OS X this is required in order for the scroll bar to appear fully opaque */\n background-color: #000;\n overflow-y: scroll;\n cursor: default;\n position: absolute;\n right: 0;\n left: 0;\n top: 0;\n bottom: 0;\n}\n\n.xterm .xterm-screen {\n position: relative;\n}\n\n.xterm .xterm-screen canvas {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.xterm-char-measure-element {\n display: inline-block;\n visibility: hidden;\n position: absolute;\n top: 0;\n left: -9999em;\n line-height: normal;\n}\n\n.xterm.enable-mouse-events {\n /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */\n cursor: default;\n}\n\n.xterm.xterm-cursor-pointer,\n.xterm .xterm-cursor-pointer {\n cursor: pointer;\n}\n\n.xterm.column-select.focus {\n /* Column selection mode */\n cursor: crosshair;\n}\n\n.xterm .xterm-accessibility:not(.debug),\n.xterm .xterm-message {\n position: absolute;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n z-index: 10;\n color: transparent;\n pointer-events: none;\n}\n\n.xterm .xterm-accessibility-tree:not(.debug) *::selection {\n color: transparent;\n}\n\n.xterm .xterm-accessibility-tree {\n font-family: monospace;\n user-select: text;\n white-space: pre;\n}\n\n.xterm .xterm-accessibility-tree > div {\n transform-origin: left;\n width: fit-content;\n}\n\n.xterm .live-region {\n position: absolute;\n left: -9999px;\n width: 1px;\n height: 1px;\n overflow: hidden;\n}\n\n.xterm-dim {\n /* Dim should not apply to background, so the opacity of the foreground color is applied\n * explicitly in the generated class and reset to 1 here */\n opacity: 1 !important;\n}\n\n.xterm-underline-1 { text-decoration: underline; }\n.xterm-underline-2 { text-decoration: double underline; }\n.xterm-underline-3 { text-decoration: wavy underline; }\n.xterm-underline-4 { text-decoration: dotted underline; }\n.xterm-underline-5 { text-decoration: dashed underline; }\n\n.xterm-overline {\n text-decoration: overline;\n}\n\n.xterm-overline.xterm-underline-1 { text-decoration: overline underline; }\n.xterm-overline.xterm-underline-2 { text-decoration: overline double underline; }\n.xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; }\n.xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; }\n.xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; }\n\n.xterm-strikethrough {\n text-decoration: line-through;\n}\n\n.xterm-screen .xterm-decoration-container .xterm-decoration {\n\tz-index: 6;\n\tposition: absolute;\n}\n\n.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer {\n\tz-index: 7;\n}\n\n.xterm-decoration-overview-ruler {\n z-index: 8;\n position: absolute;\n top: 0;\n right: 0;\n pointer-events: none;\n}\n\n.xterm-decoration-top {\n z-index: 2;\n position: relative;\n}\n\n\n\n/* Derived from vs/base/browser/ui/scrollbar/media/scrollbar.css */\n\n/* xterm.js customization: Override xterm's cursor style */\n.xterm .xterm-scrollable-element > .scrollbar {\n cursor: default;\n}\n\n/* Arrows */\n.xterm .xterm-scrollable-element > .scrollbar > .scra {\n\tcursor: pointer;\n\tfont-size: 11px !important;\n}\n\n.xterm .xterm-scrollable-element > .visible {\n\topacity: 1;\n\n\t/* Background rule added for IE9 - to allow clicks on dom node */\n\tbackground:rgba(0,0,0,0);\n\n\ttransition: opacity 100ms linear;\n\t/* In front of peek view */\n\tz-index: 11;\n}\n.xterm .xterm-scrollable-element > .invisible {\n\topacity: 0;\n\tpointer-events: none;\n}\n.xterm .xterm-scrollable-element > .invisible.fade {\n\ttransition: opacity 800ms linear;\n}\n\n/* Scrollable Content Inset Shadow */\n.xterm .xterm-scrollable-element > .shadow {\n\tposition: absolute;\n\tdisplay: none;\n}\n.xterm .xterm-scrollable-element > .shadow.top {\n\tdisplay: block;\n\ttop: 0;\n\tleft: 3px;\n\theight: 3px;\n\twidth: 100%;\n\tbox-shadow: var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset;\n}\n.xterm .xterm-scrollable-element > .shadow.left {\n\tdisplay: block;\n\ttop: 3px;\n\tleft: 0;\n\theight: 100%;\n\twidth: 3px;\n\tbox-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;\n}\n.xterm .xterm-scrollable-element > .shadow.top-left-corner {\n\tdisplay: block;\n\ttop: 0;\n\tleft: 0;\n\theight: 3px;\n\twidth: 3px;\n}\n.xterm .xterm-scrollable-element > .shadow.top.left {\n\tbox-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;\n}\n"
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings reader of the dsh-ssh browser half.
|
|
3
|
+
*
|
|
4
|
+
* The plugin's browser half owns one preference: the xterm `fontFamily` the
|
|
5
|
+
* panel applies to its terminals. Under the 0.1.7 settings model that field
|
|
6
|
+
* belongs to the plugin's own profile entry (its Cordis Config schema), and
|
|
7
|
+
* the browser surface addresses settings as one form per profile entry id — so
|
|
8
|
+
* the entry has to be resolved before its section can be read:
|
|
9
|
+
*
|
|
10
|
+
* - the family binder (`ctx.get('webUiSettings')`, published while
|
|
11
|
+
* dsh-web-settings is loaded) resolves the dsh-ssh namespace to its entry id
|
|
12
|
+
* through the Host bridge and hands back the native shared form;
|
|
13
|
+
* - without that group the shared configuration forms serve the form directly,
|
|
14
|
+
* and the entry is recognised by the one field this plugin's own schema
|
|
15
|
+
* declares: the entry whose resolved section carries `terminalFontFamily`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
19
|
+
import type { ConfigForm, ConfigFormSnapshot, ConfigForms } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
20
|
+
|
|
21
|
+
/** Domain-owned description of one settings namespace a family surface binds. */
|
|
22
|
+
export interface ConfigFormSpec<T> {
|
|
23
|
+
/** Settings namespace the surface edits. */
|
|
24
|
+
namespace: string
|
|
25
|
+
/**
|
|
26
|
+
* Narrow one wire section; undefined keeps the section the Host resolved.
|
|
27
|
+
* The shared form already validates against the namespace's serialized
|
|
28
|
+
* schema, so a decoder exists only to narrow beyond it.
|
|
29
|
+
*/
|
|
30
|
+
decode?: (section: unknown) => T | undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare module '@deepseek-ai/cordis' {
|
|
34
|
+
interface Context {
|
|
35
|
+
/**
|
|
36
|
+
* Optional family settings binder provided by dsh-web-settings; absent when
|
|
37
|
+
* that group plugin is not installed, so callers fall back to the shared
|
|
38
|
+
* configuration forms service (`ctx.configForms`).
|
|
39
|
+
*/
|
|
40
|
+
webUiSettings?: { bind<S>(spec: ConfigFormSpec<S>): ConfigForm<S> }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The read face this plugin needs from its own settings entry. */
|
|
45
|
+
export interface SettingsReader<T> {
|
|
46
|
+
/** @returns the current snapshot (stable reference until the next change). */
|
|
47
|
+
getSnapshot(): ConfigFormSnapshot<T>
|
|
48
|
+
/** Observe snapshot replacements. */
|
|
49
|
+
subscribe(listener: () => void): () => void
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A reader plus the release of every subscription it installed. */
|
|
53
|
+
export interface SettingsBinding<T> extends SettingsReader<T> {
|
|
54
|
+
/** Release the reader's subscriptions; later calls are no-ops. */
|
|
55
|
+
dispose(): void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The snapshot a reader reports before the Host has answered with this
|
|
60
|
+
* plugin's entry: nothing is readable yet, and no write is attempted.
|
|
61
|
+
*/
|
|
62
|
+
const PENDING_SNAPSHOT: ConfigFormSnapshot<never> = {
|
|
63
|
+
status: 'loading',
|
|
64
|
+
value: undefined,
|
|
65
|
+
base: undefined,
|
|
66
|
+
user: undefined,
|
|
67
|
+
revision: undefined,
|
|
68
|
+
writable: false,
|
|
69
|
+
mode: 'host',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Whether one Host namespace section carries a field this plugin's schema declares. */
|
|
73
|
+
function carriesField(section: unknown, field: string): boolean {
|
|
74
|
+
return typeof section === 'object' && section !== null && Object.hasOwn(section, field)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Reader over the shared configuration forms service.
|
|
79
|
+
*
|
|
80
|
+
* The 0.1.7 surface carries no package identity, so this plugin recognises its
|
|
81
|
+
* own entry by the field its Config schema declares. The entry list arrives
|
|
82
|
+
* asynchronously with the shared describe mirror, and an id the Host has not
|
|
83
|
+
* answered with yet is not evidence of absence: the reader re-resolves on every
|
|
84
|
+
* mirror change and reports `loading` until it holds a form.
|
|
85
|
+
*/
|
|
86
|
+
class SharedFormsReader<T> implements SettingsReader<T> {
|
|
87
|
+
private readonly listeners = new Set<() => void>()
|
|
88
|
+
private readonly unsubscribeMirror: () => void
|
|
89
|
+
private unsubscribeForm: (() => void) | undefined
|
|
90
|
+
private form: ConfigForm<T> | undefined
|
|
91
|
+
private snapshot: ConfigFormSnapshot<T> = PENDING_SNAPSHOT as ConfigFormSnapshot<T>
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param forms - the shared configuration forms service (`ctx.configForms`).
|
|
95
|
+
* @param field - the field this plugin's own schema declares, which is what identifies its entry.
|
|
96
|
+
*/
|
|
97
|
+
constructor(private readonly forms: ConfigForms, private readonly field: string) {
|
|
98
|
+
this.unsubscribeMirror = forms.describe().subscribe(() => {
|
|
99
|
+
this.bind()
|
|
100
|
+
this.publish()
|
|
101
|
+
})
|
|
102
|
+
this.bind()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getSnapshot(): ConfigFormSnapshot<T> {
|
|
106
|
+
return this.snapshot
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
subscribe(listener: () => void): () => void {
|
|
110
|
+
this.listeners.add(listener)
|
|
111
|
+
return () => {
|
|
112
|
+
this.listeners.delete(listener)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Release the mirror and form subscriptions and drop every listener. */
|
|
117
|
+
dispose(): void {
|
|
118
|
+
this.unsubscribeMirror()
|
|
119
|
+
this.unsubscribeForm?.()
|
|
120
|
+
this.unsubscribeForm = undefined
|
|
121
|
+
this.listeners.clear()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Bind the entry form once the shared mirror names this plugin's entry. */
|
|
125
|
+
private bind(): void {
|
|
126
|
+
if (this.form !== undefined) return
|
|
127
|
+
const namespaces = this.forms.describe().getSnapshot().view?.namespaces
|
|
128
|
+
const entry = namespaces?.find(candidate => carriesField(candidate.value, this.field))
|
|
129
|
+
if (entry === undefined) return
|
|
130
|
+
const form = this.forms.get<T>(entry.ns)
|
|
131
|
+
// A service that answers no form for its own served entry leaves the reader
|
|
132
|
+
// unbound; it retries on the next mirror answer rather than failing a boot.
|
|
133
|
+
if (form === undefined) return
|
|
134
|
+
this.form = form
|
|
135
|
+
this.snapshot = form.getSnapshot()
|
|
136
|
+
this.unsubscribeForm = form.subscribe(() => {
|
|
137
|
+
this.snapshot = form.getSnapshot()
|
|
138
|
+
this.publish()
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private publish(): void {
|
|
143
|
+
for (const listener of this.listeners) listener()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Bind this plugin's settings reader.
|
|
149
|
+
* @param ctx - client context carrying the family binder and/or the shared forms service.
|
|
150
|
+
* @param namespace - the family settings namespace this plugin owns.
|
|
151
|
+
* @param field - the field this plugin's own schema declares, used to recognise its entry when the family binder is absent.
|
|
152
|
+
* @returns the reader and the release of its subscriptions.
|
|
153
|
+
*/
|
|
154
|
+
export function bindSettingsReader<T>(ctx: ClientContext, namespace: string, field: string): SettingsBinding<T> {
|
|
155
|
+
const family = ctx.get('webUiSettings')
|
|
156
|
+
if (family !== undefined) {
|
|
157
|
+
const form = family.bind<T>({ namespace })
|
|
158
|
+
return {
|
|
159
|
+
getSnapshot: () => form.getSnapshot(),
|
|
160
|
+
subscribe: listener => form.subscribe(listener),
|
|
161
|
+
dispose: () => {},
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return new SharedFormsReader<T>(ctx.configForms, field)
|
|
165
|
+
}
|
package/src/dsh-home.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Generated by scripts/sync-shared.mjs from shared/host/dsh-home.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
+
/**
|
|
3
|
+
* DSH_HOME resolution shared by the plugin family's Host halves: the
|
|
4
|
+
* environment override wins, the platform home fallback follows. Mirrors
|
|
5
|
+
* what dsh-pet and dsh-liangshen each used to implement locally.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { homedir } from 'node:os'
|
|
9
|
+
import { isAbsolute, join } from 'node:path'
|
|
10
|
+
import { isAbsolute as posixIsAbsolute, join as posixJoin } from 'node:path/posix'
|
|
11
|
+
|
|
12
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
13
|
+
export function expandHome(path: string, home: string = homedir()): string {
|
|
14
|
+
const isPosix = home.startsWith('/')
|
|
15
|
+
const j = isPosix ? posixJoin : join
|
|
16
|
+
if (path === '~') return home
|
|
17
|
+
if (path.startsWith('~/') || path.startsWith('~\\')) return j(home, path.slice(2))
|
|
18
|
+
return path
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the DSH home directory.
|
|
23
|
+
* @param env - process environment to read DSH_HOME from.
|
|
24
|
+
* @param home - platform home directory fallback (test seam).
|
|
25
|
+
* @returns the absolute DSH home path.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
28
|
+
const isPosix = home.startsWith('/')
|
|
29
|
+
const j = isPosix ? posixJoin : join
|
|
30
|
+
const isAbs = isPosix ? posixIsAbsolute : isAbsolute
|
|
31
|
+
const raw = env.DSH_HOME
|
|
32
|
+
if (raw !== undefined && raw.trim() !== '') {
|
|
33
|
+
const expanded = expandHome(raw.trim(), home)
|
|
34
|
+
return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
|
|
35
|
+
}
|
|
36
|
+
return j(home, '.dsh')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
40
|
+
export function dshHome(): string {
|
|
41
|
+
return resolveDshHome()
|
|
42
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster execution: run one command concurrently across selected hosts; the
|
|
3
|
+
* caller must provide at least one non-empty aliases / environment / tags filter.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ClusterResult } from '../protocol.ts'
|
|
7
|
+
import { execCommand, type PoolEngine } from './connection-pool.ts'
|
|
8
|
+
|
|
9
|
+
interface ClusterOptions {
|
|
10
|
+
command: string
|
|
11
|
+
aliases?: string[]
|
|
12
|
+
environment?: string
|
|
13
|
+
tags?: string[]
|
|
14
|
+
timeoutMs?: number
|
|
15
|
+
maxWorkers?: number
|
|
16
|
+
/** Caller cancellation, forwarded to every host's command. */
|
|
17
|
+
signal?: AbortSignal
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Run one command against many hosts concurrently. */
|
|
21
|
+
export async function cluster(engine: PoolEngine, options: ClusterOptions): Promise<ClusterResult[]> {
|
|
22
|
+
const hasAliases = Array.isArray(options.aliases) && options.aliases.some(alias => typeof alias === 'string' && alias.trim() !== '')
|
|
23
|
+
const hasEnvironment = typeof options.environment === 'string' && options.environment.trim() !== ''
|
|
24
|
+
const hasTags = Array.isArray(options.tags) && options.tags.some(tag => typeof tag === 'string' && tag.trim() !== '')
|
|
25
|
+
if (!hasAliases && !hasEnvironment && !hasTags) {
|
|
26
|
+
throw new Error('ssh_cluster requires aliases, environment, or tags to limit the target set')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let targets = engine.store.list()
|
|
30
|
+
if (options.aliases !== undefined && options.aliases.length > 0) {
|
|
31
|
+
targets = targets.filter(entry => options.aliases!.includes(entry.alias))
|
|
32
|
+
}
|
|
33
|
+
if (options.environment !== undefined && options.environment !== '') {
|
|
34
|
+
targets = targets.filter(entry => entry.environment === options.environment)
|
|
35
|
+
}
|
|
36
|
+
if (options.tags !== undefined && options.tags.length > 0) {
|
|
37
|
+
// ALL semantics (matches the ssh_cluster tool description).
|
|
38
|
+
targets = targets.filter(entry => options.tags!.every(tag => entry.tags.includes(tag)))
|
|
39
|
+
}
|
|
40
|
+
if (targets.length === 0) return []
|
|
41
|
+
if (options.maxWorkers !== undefined && (!Number.isInteger(options.maxWorkers) || options.maxWorkers < 1)) {
|
|
42
|
+
throw new Error('maxWorkers must be a positive integer')
|
|
43
|
+
}
|
|
44
|
+
const workers = Math.min(engine.opts.defaultMaxWorkers, options.maxWorkers ?? engine.opts.defaultMaxWorkers, targets.length)
|
|
45
|
+
const results: ClusterResult[] = []
|
|
46
|
+
const queue = [...targets]
|
|
47
|
+
const run = async (): Promise<void> => {
|
|
48
|
+
while (queue.length > 0) {
|
|
49
|
+
const entry = queue.shift()!
|
|
50
|
+
try {
|
|
51
|
+
const result = await execCommand(engine, entry.alias, options.command, options.timeoutMs, options.signal)
|
|
52
|
+
results.push({ alias: entry.alias, ok: result.success, exitCode: result.exitCode, timedOut: result.timedOut, stdout: result.stdout, stderr: result.stderr, durationMs: result.durationMs })
|
|
53
|
+
} catch (error) {
|
|
54
|
+
results.push({ alias: entry.alias, ok: false, error: error instanceof Error ? error.message : String(error) })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(Array.from({ length: workers }, () => run()))
|
|
59
|
+
return results
|
|
60
|
+
}
|