@tiphareth/dsh-hardssh 0.1.2
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/README.md +50 -0
- package/cordis.patch.yml +26 -0
- package/lib/client.js +17780 -0
- package/lib/environment-BL1jddfB.js +449 -0
- package/lib/fs.js +478 -0
- package/lib/index.js +6758 -0
- package/lib/subprocess.js +600 -0
- package/lib/switch-fs-CAJpFY9C.js +193 -0
- package/lib/switch-fs-RrZtG2gv.js +210 -0
- package/lib/types/backend.d.ts +108 -0
- package/lib/types/base/capability.d.ts +107 -0
- package/lib/types/base/index.d.ts +18 -0
- package/lib/types/base/ledger-router.d.ts +48 -0
- package/lib/types/base/ledger.d.ts +82 -0
- package/lib/types/base/model.d.ts +108 -0
- package/lib/types/base/namespace.d.ts +57 -0
- package/lib/types/base/plugin.d.ts +102 -0
- package/lib/types/base/registry.d.ts +60 -0
- package/lib/types/base/router.d.ts +40 -0
- package/lib/types/client/api.d.ts +85 -0
- package/lib/types/client/directory-flow.d.ts +82 -0
- package/lib/types/client/icons.d.ts +19 -0
- package/lib/types/client/index.d.ts +34 -0
- package/lib/types/client/locales.d.ts +104 -0
- package/lib/types/client/manager-button.d.ts +32 -0
- package/lib/types/client/migrate.d.ts +20 -0
- package/lib/types/client/ssh/api.d.ts +89 -0
- package/lib/types/client/ssh/apply.d.ts +23 -0
- package/lib/types/client/ssh/locales.d.ts +156 -0
- package/lib/types/client/ssh/mount.d.ts +13 -0
- package/lib/types/client/ssh/panel/ClusterTab.d.ts +8 -0
- package/lib/types/client/ssh/panel/HostFingerprintDialog.d.ts +16 -0
- package/lib/types/client/ssh/panel/HostFormDialog.d.ts +13 -0
- package/lib/types/client/ssh/panel/HostsTab.d.ts +10 -0
- package/lib/types/client/ssh/panel/SessionSecretDialog.d.ts +16 -0
- package/lib/types/client/ssh/panel/SshPanel.d.ts +14 -0
- package/lib/types/client/ssh/panel/TerminalTab.d.ts +12 -0
- package/lib/types/client/ssh/panel/TransferTab.d.ts +8 -0
- package/lib/types/client/ssh/panel/TunnelsTab.d.ts +8 -0
- package/lib/types/client/ssh/panel/controller.d.ts +23 -0
- package/lib/types/client/ssh/panel/helpers.d.ts +15 -0
- package/lib/types/client/ssh/panel/xterm.css.d.ts +3 -0
- package/lib/types/client/ssh/sidebar-entry.d.ts +25 -0
- package/lib/types/client/state.d.ts +32 -0
- package/lib/types/client/text.d.ts +11 -0
- package/lib/types/client/workspace-badges.d.ts +38 -0
- package/lib/types/client/workspace-gate.d.ts +15 -0
- package/lib/types/client-http.d.ts +15 -0
- package/lib/types/core.d.ts +43 -0
- package/lib/types/fs.d.ts +36 -0
- package/lib/types/host-http.d.ts +25 -0
- package/lib/types/index.d.ts +53 -0
- package/lib/types/ledger.d.ts +132 -0
- package/lib/types/protocol.d.ts +101 -0
- package/lib/types/providers/index.d.ts +19 -0
- package/lib/types/providers/local/provider.d.ts +58 -0
- package/lib/types/providers/ssh/provider.d.ts +112 -0
- package/lib/types/remote/environment.d.ts +29 -0
- package/lib/types/remote/output.d.ts +38 -0
- package/lib/types/remote/remote-fs.d.ts +69 -0
- package/lib/types/remote/remote-process.d.ts +41 -0
- package/lib/types/remote/remote-subprocess.d.ts +31 -0
- package/lib/types/remote/remote-terminal.d.ts +41 -0
- package/lib/types/remote-runner.d.ts +83 -0
- package/lib/types/remote-search.d.ts +50 -0
- package/lib/types/routes.d.ts +24 -0
- package/lib/types/runtime/workspace-core.d.ts +59 -0
- package/lib/types/seam-state.d.ts +69 -0
- package/lib/types/shell.d.ts +8 -0
- package/lib/types/ssh/connection/lease.d.ts +16 -0
- package/lib/types/ssh/connection/pool.d.ts +57 -0
- package/lib/types/ssh/engine.d.ts +434 -0
- package/lib/types/ssh/exec/output.d.ts +31 -0
- package/lib/types/ssh/known-hosts.d.ts +89 -0
- package/lib/types/ssh/plugin.d.ts +57 -0
- package/lib/types/ssh/protocol.d.ts +236 -0
- package/lib/types/ssh/routes.d.ts +44 -0
- package/lib/types/ssh/store.d.ts +107 -0
- package/lib/types/ssh/tools.d.ts +35 -0
- package/lib/types/ssh/transfer/progress.d.ts +14 -0
- package/lib/types/ssh/vault.d.ts +110 -0
- package/lib/types/subprocess.d.ts +32 -0
- package/lib/types/switch/switch-fs.d.ts +88 -0
- package/lib/types/switch/switch-subprocess.d.ts +34 -0
- package/lib/types/tools.d.ts +12 -0
- package/package.json +134 -0
- package/src/backend.ts +624 -0
- package/src/base/capability.ts +86 -0
- package/src/base/index.ts +18 -0
- package/src/base/ledger-router.ts +128 -0
- package/src/base/ledger.ts +299 -0
- package/src/base/model.ts +118 -0
- package/src/base/namespace.ts +102 -0
- package/src/base/plugin.ts +170 -0
- package/src/base/registry.ts +109 -0
- package/src/base/router.ts +43 -0
- package/src/client/api.ts +196 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/directory-flow.tsx +482 -0
- package/src/client/icons.tsx +50 -0
- package/src/client/index.ts +210 -0
- package/src/client/locales.ts +105 -0
- package/src/client/manager-button.tsx +269 -0
- package/src/client/migrate.ts +109 -0
- package/src/client/ssh/api.ts +411 -0
- package/src/client/ssh/apply.ts +50 -0
- package/src/client/ssh/locales.ts +322 -0
- package/src/client/ssh/mount.tsx +83 -0
- package/src/client/ssh/panel/ClusterTab.tsx +123 -0
- package/src/client/ssh/panel/HostFingerprintDialog.tsx +82 -0
- package/src/client/ssh/panel/HostFormDialog.tsx +228 -0
- package/src/client/ssh/panel/HostsTab.tsx +236 -0
- package/src/client/ssh/panel/SessionSecretDialog.tsx +80 -0
- package/src/client/ssh/panel/SshPanel.tsx +77 -0
- package/src/client/ssh/panel/TerminalTab.tsx +176 -0
- package/src/client/ssh/panel/TransferTab.tsx +232 -0
- package/src/client/ssh/panel/TunnelsTab.tsx +177 -0
- package/src/client/ssh/panel/controller.ts +48 -0
- package/src/client/ssh/panel/helpers.ts +26 -0
- package/src/client/ssh/panel/panel.module.css +1006 -0
- package/src/client/ssh/panel/xterm.css.ts +2 -0
- package/src/client/ssh/sidebar-entry.ts +123 -0
- package/src/client/state.ts +99 -0
- package/src/client/text.ts +22 -0
- package/src/client/workspace-badges.ts +96 -0
- package/src/client/workspace-gate.ts +225 -0
- package/src/client/workspace.module.css +283 -0
- package/src/client-http.ts +45 -0
- package/src/core.ts +47 -0
- package/src/fs.ts +85 -0
- package/src/host-http.ts +74 -0
- package/src/index.ts +244 -0
- package/src/ledger.ts +416 -0
- package/src/protocol.ts +114 -0
- package/src/providers/index.ts +34 -0
- package/src/providers/local/provider.ts +179 -0
- package/src/providers/ssh/provider.ts +274 -0
- package/src/remote/environment.ts +123 -0
- package/src/remote/output.ts +142 -0
- package/src/remote/remote-fs.ts +532 -0
- package/src/remote/remote-process.ts +203 -0
- package/src/remote/remote-subprocess.ts +159 -0
- package/src/remote/remote-terminal.ts +141 -0
- package/src/remote-runner.ts +201 -0
- package/src/remote-search.ts +163 -0
- package/src/routes.ts +395 -0
- package/src/runtime/workspace-core.ts +154 -0
- package/src/seam-state.ts +185 -0
- package/src/shell.ts +10 -0
- package/src/ssh/connection/lease.ts +17 -0
- package/src/ssh/connection/pool.ts +275 -0
- package/src/ssh/engine.ts +1761 -0
- package/src/ssh/exec/output.ts +70 -0
- package/src/ssh/known-hosts.ts +214 -0
- package/src/ssh/plugin.ts +184 -0
- package/src/ssh/protocol.ts +227 -0
- package/src/ssh/routes.ts +892 -0
- package/src/ssh/store.ts +544 -0
- package/src/ssh/tools.ts +402 -0
- package/src/ssh/transfer/progress.ts +75 -0
- package/src/ssh/vault.ts +477 -0
- package/src/subprocess.ts +71 -0
- package/src/switch/switch-fs.ts +253 -0
- package/src/switch/switch-subprocess.ts +59 -0
- package/src/tools.ts +221 -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,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar entry injection.
|
|
3
|
+
*
|
|
4
|
+
* dsh's sidebar shell exposes no slot an external plugin can register into,
|
|
5
|
+
* so — following the task-board precedent of DOM-level extension — the entry
|
|
6
|
+
* row is injected between the shell's New Session button and the workspace
|
|
7
|
+
* browser. The injection self-heals: a MutationObserver watches the sidebar
|
|
8
|
+
* root and re-inserts the row whenever a React re-render displaces it
|
|
9
|
+
* (re-insertion happens in the same frame, before paint, so no flicker).
|
|
10
|
+
*
|
|
11
|
+
* The row is plain DOM (no React tree) so it can never disturb the shell's
|
|
12
|
+
* reconciliation; the panel view it toggles is a separate React root mounted
|
|
13
|
+
* in the center column (see mount.tsx).
|
|
14
|
+
*/
|
|
15
|
+
import type { PanelController } from './panel/controller.ts'
|
|
16
|
+
import { tt } from './panel/helpers.ts'
|
|
17
|
+
import css from './panel/panel.module.css'
|
|
18
|
+
|
|
19
|
+
/** Stable data attribute identifying the injected entry row. */
|
|
20
|
+
export const ENTRY_SELECTOR = '[data-dsh-ssh-entry]'
|
|
21
|
+
|
|
22
|
+
/** The sidebar column is the grid item AppFrame renders with this pane marker. */
|
|
23
|
+
const SIDEBAR_COLUMN_SELECTOR = '[data-pane="sidebar"]'
|
|
24
|
+
|
|
25
|
+
/** Inline icon (matches the shell's 16px nav-icon look): a terminal prompt glyph. */
|
|
26
|
+
const ICON = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="2.5" width="12" height="11" rx="1.5"/><path d="M4.5 5.5l2.5 2.5-2.5 2.5"/><path d="M8.5 10.5h3"/></svg>'
|
|
27
|
+
|
|
28
|
+
/** Find the sidebar shell root element, or undefined while not yet mounted. */
|
|
29
|
+
function sidebarRoot(): HTMLElement | undefined {
|
|
30
|
+
const column = document.querySelector<HTMLElement>(SIDEBAR_COLUMN_SELECTOR)
|
|
31
|
+
const root = column?.firstElementChild as HTMLElement | undefined
|
|
32
|
+
return root ?? undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The New Session button: the shell's only direct-child button of the root. */
|
|
36
|
+
function newSessionButton(root: HTMLElement): HTMLButtonElement | undefined {
|
|
37
|
+
for (const child of root.children) {
|
|
38
|
+
if (child.tagName === 'BUTTON') return child as HTMLButtonElement
|
|
39
|
+
}
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Build the entry row (a detached button; insert once the shell is up). */
|
|
44
|
+
function createEntry(controller: PanelController): HTMLButtonElement {
|
|
45
|
+
const entry = document.createElement('button')
|
|
46
|
+
entry.type = 'button'
|
|
47
|
+
entry.dataset.dshSshEntry = ''
|
|
48
|
+
entry.className = css.entry
|
|
49
|
+
entry.setAttribute('aria-label', tt('entry.label'))
|
|
50
|
+
entry.setAttribute('title', tt('entry.tooltip'))
|
|
51
|
+
entry.innerHTML = '<span class="' + css.entryIcon + '">' + ICON + '</span><span class="' + css.entryLabel + '">' + tt('entry.label') + '</span>'
|
|
52
|
+
entry.addEventListener('click', () => { controller.toggle() })
|
|
53
|
+
return entry
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Re-insert the entry after the New Session button (before the browser region). */
|
|
57
|
+
function placeEntry(root: HTMLElement, entry: HTMLButtonElement): boolean {
|
|
58
|
+
const button = newSessionButton(root)
|
|
59
|
+
if (button === undefined) return false
|
|
60
|
+
if (entry.parentElement !== root) {
|
|
61
|
+
// Insert after the button: React never manages this node, and the shell
|
|
62
|
+
// keeps its own child order intact around it.
|
|
63
|
+
root.insertBefore(entry, button.nextElementSibling)
|
|
64
|
+
}
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Mount the sidebar entry, waiting for the shell to render and self-healing
|
|
70
|
+
* on later React re-renders.
|
|
71
|
+
* @param controller - the panel controller the entry toggles.
|
|
72
|
+
* @returns disposer removing the entry and its observers.
|
|
73
|
+
*/
|
|
74
|
+
export function mountSidebarEntry(controller: PanelController): () => void {
|
|
75
|
+
const entry = createEntry(controller)
|
|
76
|
+
let root: HTMLElement | undefined
|
|
77
|
+
let placed = false
|
|
78
|
+
|
|
79
|
+
const tryPlace = (): void => {
|
|
80
|
+
if (placed) return
|
|
81
|
+
if (root !== undefined && !root.isConnected) {
|
|
82
|
+
// The shell re-created the sidebar pane; re-query from scratch.
|
|
83
|
+
rootObserver.disconnect()
|
|
84
|
+
root = undefined
|
|
85
|
+
}
|
|
86
|
+
root ??= sidebarRoot()
|
|
87
|
+
if (root === undefined) return
|
|
88
|
+
placed = placeEntry(root, entry)
|
|
89
|
+
if (placed) rootObserver.observe(root, { childList: true, subtree: true })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The shell renders after boot settlement; watch for its arrival.
|
|
93
|
+
const waitObserver = new MutationObserver(() => { tryPlace() })
|
|
94
|
+
waitObserver.observe(document.body, { childList: true, subtree: true })
|
|
95
|
+
|
|
96
|
+
// Self-heal: if a React re-render displaces the row, re-insert it in the
|
|
97
|
+
// same frame (microtask before paint -> no visible flicker).
|
|
98
|
+
const rootObserver = new MutationObserver(() => {
|
|
99
|
+
if (root === undefined || !root.isConnected) {
|
|
100
|
+
placed = false
|
|
101
|
+
tryPlace()
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
if (!root.contains(entry)) {
|
|
105
|
+
placed = placeEntry(root, entry)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// Reflect the panel's open state on the row (active highlight).
|
|
110
|
+
const unsubscribe = controller.subscribe(() => {
|
|
111
|
+
entry.dataset.active = controller.getSnapshot().panelOpen ? 'true' : undefined
|
|
112
|
+
})
|
|
113
|
+
entry.dataset.active = controller.getSnapshot().panelOpen ? 'true' : undefined
|
|
114
|
+
|
|
115
|
+
tryPlace()
|
|
116
|
+
|
|
117
|
+
return () => {
|
|
118
|
+
waitObserver.disconnect()
|
|
119
|
+
rootObserver.disconnect()
|
|
120
|
+
unsubscribe()
|
|
121
|
+
entry.remove()
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side SSH workspace state: the list of SSH-bound workspaces plus a
|
|
3
|
+
* light poll (3s) keeping it fresh. The snapshot is replaced only on
|
|
4
|
+
* successful fetches, so React's useSyncExternalStore sees stable references
|
|
5
|
+
* between polls. There is NO global local/remote mode anymore — a session's
|
|
6
|
+
* execution world is decided host-side by its cwd (an anchor path of an SSH
|
|
7
|
+
* workspace routes remote); this client state only drives the management UI
|
|
8
|
+
* (list / create / delete) and the sidebar title annotations.
|
|
9
|
+
*/
|
|
10
|
+
import type { SshWorkspaceRecord } from '../protocol.ts'
|
|
11
|
+
import type { WorkspaceApi } from './api.ts'
|
|
12
|
+
|
|
13
|
+
const POLL_MS = 3_000
|
|
14
|
+
|
|
15
|
+
/** True when two ledgers are identical (same order, same display fields). */
|
|
16
|
+
function sameLedger(a: SshWorkspaceRecord[], b: SshWorkspaceRecord[]): boolean {
|
|
17
|
+
if (a.length !== b.length) return false
|
|
18
|
+
for (let index = 0; index < a.length; index += 1) {
|
|
19
|
+
const left = a[index]
|
|
20
|
+
const right = b[index]
|
|
21
|
+
if (
|
|
22
|
+
left.id !== right.id
|
|
23
|
+
|| left.title !== right.title
|
|
24
|
+
|| left.alias !== right.alias
|
|
25
|
+
|| left.remoteRoot !== right.remoteRoot
|
|
26
|
+
|| left.anchorPath !== right.anchorPath
|
|
27
|
+
) {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface WorkspaceManagerState {
|
|
35
|
+
/** SSH-bound workspaces, in creation order. */
|
|
36
|
+
workspaces: SshWorkspaceRecord[]
|
|
37
|
+
/** Whether the last load failed (keeps the previous list). */
|
|
38
|
+
error: string | null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class WorkspaceManager {
|
|
42
|
+
private state: WorkspaceManagerState = { workspaces: [], error: null }
|
|
43
|
+
private readonly listeners = new Set<() => void>()
|
|
44
|
+
private timer: number | undefined
|
|
45
|
+
|
|
46
|
+
constructor(private readonly api: WorkspaceApi) {}
|
|
47
|
+
|
|
48
|
+
getSnapshot(): WorkspaceManagerState {
|
|
49
|
+
return this.state
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
subscribe(listener: () => void): () => void {
|
|
53
|
+
this.listeners.add(listener)
|
|
54
|
+
return () => {
|
|
55
|
+
this.listeners.delete(listener)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private emit(): void {
|
|
60
|
+
for (const listener of [...this.listeners]) listener()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async refresh(): Promise<void> {
|
|
64
|
+
try {
|
|
65
|
+
const workspaces = await this.api.listWorkspaces()
|
|
66
|
+
const next: WorkspaceManagerState = { workspaces, error: null }
|
|
67
|
+
// Emit only on real change: identical polls keep the same snapshot
|
|
68
|
+
// reference, so subscribers (badges, the manager menu) don't re-run
|
|
69
|
+
// on every 3s tick.
|
|
70
|
+
if (!sameLedger(this.state.workspaces, next.workspaces) || this.state.error !== null) {
|
|
71
|
+
this.state = next
|
|
72
|
+
this.emit()
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
76
|
+
if (this.state.error !== message) {
|
|
77
|
+
this.state = { ...this.state, error: message }
|
|
78
|
+
this.emit()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
start(): void {
|
|
84
|
+
void this.refresh()
|
|
85
|
+
this.timer = window.setInterval(() => void this.refresh(), POLL_MS)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
stop(): void {
|
|
89
|
+
if (this.timer !== undefined) {
|
|
90
|
+
window.clearInterval(this.timer)
|
|
91
|
+
this.timer = undefined
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async remove(id: string): Promise<void> {
|
|
96
|
+
await this.api.deleteWorkspace(id)
|
|
97
|
+
await this.refresh()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny localization helper: resolves the active dictionary (zh when the
|
|
3
|
+
* document language starts with zh, else en). The dictionary is swapped by
|
|
4
|
+
* the plugin's apply() on <html lang> changes.
|
|
5
|
+
*/
|
|
6
|
+
import { en, zh, type WorkspaceKey } from './locales.ts'
|
|
7
|
+
|
|
8
|
+
let current: typeof zh = document.documentElement.lang?.startsWith('zh') ? zh : en
|
|
9
|
+
|
|
10
|
+
/** Switch the active dictionary (called by the client entry on lang change). */
|
|
11
|
+
export function setLanguage(zhMode: boolean): void {
|
|
12
|
+
current = zhMode ? zh : en
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Resolve one copy key (supports %s / %d substitution). */
|
|
16
|
+
export function tt(key: WorkspaceKey, ...args: Array<string | number>): string {
|
|
17
|
+
let text = current[key] ?? zh[key] ?? key
|
|
18
|
+
for (const arg of args) {
|
|
19
|
+
text = text.replace(/%[sd]/, String(arg))
|
|
20
|
+
}
|
|
21
|
+
return text
|
|
22
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar workspace-row augmentation: labels every host workspace row whose
|
|
3
|
+
* title matches an SSH-bound workspace with a compact remote badge
|
|
4
|
+
* (`alias @ remoteRoot`), so a glance tells a local workspace from a remote
|
|
5
|
+
* one. Pure DOM-level extension (the sidebar shell exposes no slot for row
|
|
6
|
+
* decoration), following the dsh-ssh sidebar-entry precedent: a
|
|
7
|
+
* MutationObserver self-heals when React re-renders displace the injected
|
|
8
|
+
* badge.
|
|
9
|
+
*
|
|
10
|
+
* The row title alone matches: SSH-bound workspace titles are unique enough
|
|
11
|
+
* in practice (the ledger title is what the row shows). A title match against
|
|
12
|
+
* `~/.dsh/ssh-workspaces/<id>` anchors also works when the host picks that
|
|
13
|
+
* default title.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-hardssh/client/workspace-badges
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const PROJECT_ROW_SELECTOR = '[class*="projectRow"]'
|
|
19
|
+
const TITLE_SELECTOR = '[class*="title"]'
|
|
20
|
+
|
|
21
|
+
/** Render a small remote badge element. The cloud icon marks "remote";
|
|
22
|
+
* connected servers render in DeepSeek blue, disconnected stay gray. The
|
|
23
|
+
* tooltip shows the REMOTE directory plus the server, e.g.
|
|
24
|
+
* `/data/app (prod-01)`. */
|
|
25
|
+
export function makeBadge(alias: string, remoteRoot: string, connected: boolean): HTMLElement {
|
|
26
|
+
const badge = document.createElement('span')
|
|
27
|
+
badge.dataset.sshBadge = connected ? 'connected' : 'disconnected'
|
|
28
|
+
badge.title = `${remoteRoot}(${alias})`
|
|
29
|
+
badge.setAttribute(
|
|
30
|
+
'style',
|
|
31
|
+
connected
|
|
32
|
+
? 'display:inline-flex;align-items:center;gap:3px;margin-left:6px;max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;line-height:16px;color:#1476E6;border:1px solid #1476E6;border-radius:999px;padding:0 6px;background:#D4E0F7;flex:none'
|
|
33
|
+
: 'display:inline-flex;align-items:center;gap:3px;margin-left:6px;max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,rgba(128,128,128,.75));border:1px solid var(--dsw-alias-line-secondary,rgba(128,128,128,.28));border-radius:999px;padding:0 6px;background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.10));flex:none',
|
|
34
|
+
)
|
|
35
|
+
const icon = document.createElement('span')
|
|
36
|
+
icon.setAttribute('style', 'display:inline-flex;flex:none;line-height:1')
|
|
37
|
+
icon.innerHTML = '<svg viewBox="0 0 1024 1024" width="11" height="11" fill="currentColor" aria-hidden="true"><path d="M743.936 758.499556h-273.066667c-17.066667 0-34.133333-17.066667-34.133333-34.133334s17.066667-34.133333 34.133333-34.133333h273.066667c28.444444 0 153.6-5.688889 153.6-130.844445 0-142.222222-153.6-164.977778-159.288889-164.977777-17.066667 0-28.444444-11.377778-28.444444-22.755556-22.755556-85.333333-108.088889-142.222222-193.422223-130.844444-136.533333 0-176.355556 79.644444-199.111111 164.977777-5.688889 5.688889-22.755556 17.066667-39.822222 17.066667 0 0-153.6 5.688889-153.6 142.222222 0 119.466667 130.844444 125.155556 153.6 125.155556 17.066667 0 34.133333 17.066667 34.133333 34.133333s-17.066667 34.133333-34.133333 34.133334c-113.777778 0-227.555556-62.577778-227.555555-193.422223 0-142.222222 119.466667-204.8 199.111111-210.488889 22.755556-68.266667 79.644444-193.422222 261.688889-193.422222 113.777778-11.377778 216.177778 56.888889 256 164.977778 79.644444 17.066667 199.111111 79.644444 199.111111 233.244444 5.688889 136.533333-108.088889 199.111111-221.866667 199.111112z"/><path d="M573.269333 866.588444c-11.377778 0-17.066667-5.688889-22.755555-11.377777l-108.088889-108.088889c-5.688889-5.688889-11.377778-17.066667-11.377778-22.755556s5.688889-17.066667 11.377778-22.755555l108.088889-108.088889c11.377778-11.377778 34.133333-11.377778 51.2 0 11.377778 11.377778 11.377778 34.133333 0 51.2l-79.644445 79.644444 79.644445 79.644445c11.377778 11.377778 11.377778 34.133333 0 51.2-5.688889 5.688889-17.066667 11.377778-28.444445 11.377777z"/></svg>'
|
|
38
|
+
const label = document.createElement('span')
|
|
39
|
+
label.textContent = alias
|
|
40
|
+
label.setAttribute('style', 'font-weight:400')
|
|
41
|
+
badge.append(icon, label)
|
|
42
|
+
return badge
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Mount the row-decoration pass. Queries the sidebar for project rows and
|
|
47
|
+
* appends a remote badge when the row's title belongs to an SSH workspace.
|
|
48
|
+
* Badges of aliases in `connected` render blue, others gray. Self-heals via
|
|
49
|
+
* MutationObserver on the sidebar container (rows re-render on
|
|
50
|
+
* session/workspace changes).
|
|
51
|
+
* @param workspaces - the SSH workspace records (id/title/alias/remoteRoot).
|
|
52
|
+
* @param connected - aliases with a live pooled connection (badge coloring).
|
|
53
|
+
* @returns disposer.
|
|
54
|
+
*/
|
|
55
|
+
export function mountWorkspaceBadges(
|
|
56
|
+
workspaces: Array<{ id: string; title: string; alias: string; remoteRoot: string }>,
|
|
57
|
+
connected?: ReadonlySet<string>,
|
|
58
|
+
): () => void {
|
|
59
|
+
const byTitle = new Map<string, { alias: string; remoteRoot: string }>()
|
|
60
|
+
for (const workspace of workspaces) byTitle.set(workspace.title, workspace)
|
|
61
|
+
|
|
62
|
+
/** Decorate one project row (idempotent: skip rows already tagged). */
|
|
63
|
+
const decorate = (row: HTMLElement): void => {
|
|
64
|
+
if (row.querySelector('[data-ssh-badge]') !== null) return
|
|
65
|
+
const titleEl = row.querySelector<HTMLElement>(TITLE_SELECTOR)
|
|
66
|
+
if (titleEl === null || titleEl === undefined) return
|
|
67
|
+
const title = titleEl.textContent?.trim() ?? ''
|
|
68
|
+
const target = byTitle.get(title)
|
|
69
|
+
if (target === undefined) return
|
|
70
|
+
const isConnected = connected?.has(target.alias) ?? false
|
|
71
|
+
// Hovering the row shows the REMOTE directory (not the local anchor path
|
|
72
|
+
// the shell would otherwise display).
|
|
73
|
+
row.title = `${target.remoteRoot}(${target.alias})`
|
|
74
|
+
titleEl.appendChild(makeBadge(target.alias, target.remoteRoot, isConnected))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Scan the sidebar column for project rows and decorate each. */
|
|
78
|
+
const scan = (): void => {
|
|
79
|
+
for (const row of document.querySelectorAll<HTMLElement>(PROJECT_ROW_SELECTOR)) {
|
|
80
|
+
decorate(row)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Watch the whole document for the sidebar column arriving / re-rendering.
|
|
85
|
+
const observer = new MutationObserver(() => { scan() })
|
|
86
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
87
|
+
scan()
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
observer.disconnect()
|
|
91
|
+
// Remove injected badges.
|
|
92
|
+
for (const badge of document.querySelectorAll<HTMLElement>('[data-ssh-badge]')) {
|
|
93
|
+
badge.remove()
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar workspace-row click gate: when the operator clicks an SSH-bound
|
|
3
|
+
* workspace row in the session sidebar, ensure the server connection can
|
|
4
|
+
* actually be established BEFORE the shell proceeds with the native open —
|
|
5
|
+
* otherwise the shell surfaces raw SSH errors (host key untrusted, session
|
|
6
|
+
* password missing) and the workspace appears "dead" with no prompt.
|
|
7
|
+
*
|
|
8
|
+
* The gate runs the engine's /test probe (a real, lightweight connect):
|
|
9
|
+
* - HOST_KEY_UNKNOWN / HOST_KEY_MISMATCH → the host fingerprint confirm
|
|
10
|
+
* dialog (HostFingerprintDialog; TOFU first encounter / key rotation);
|
|
11
|
+
* - NEEDS_PASSWORD / NEEDS_PASSPHRASE → the VSCode-style session password
|
|
12
|
+
* dialog (SessionSecretDialog; never persisted, session-only);
|
|
13
|
+
* - ok → mark the alias as gated (5-minute TTL — trust is durable and the
|
|
14
|
+
* session password survives in the engine table) and re-dispatch the click.
|
|
15
|
+
*
|
|
16
|
+
* Pure DOM-level extension following the workspace-badges precedent: the
|
|
17
|
+
* sidebar shell exposes no row slot, so a MutationObserver self-heals when
|
|
18
|
+
* React re-renders displace the injected listener. A capture-phase listener
|
|
19
|
+
* on the row blocks the shell's click while a dialog is needed, then lets
|
|
20
|
+
* clicks through once the alias has passed the gate.
|
|
21
|
+
*
|
|
22
|
+
* @module dsh-hardssh/client/workspace-gate
|
|
23
|
+
*/
|
|
24
|
+
import { createElement, type ReactElement } from 'react'
|
|
25
|
+
import { createRoot } from 'react-dom/client'
|
|
26
|
+
import type { SshApi } from './ssh/api.ts'
|
|
27
|
+
import { SshApiError } from './ssh/api.ts'
|
|
28
|
+
import { HostFingerprintDialog } from './ssh/panel/HostFingerprintDialog.tsx'
|
|
29
|
+
import { SessionSecretDialog } from './ssh/panel/SessionSecretDialog.tsx'
|
|
30
|
+
import { tt } from './text.ts'
|
|
31
|
+
|
|
32
|
+
const PROJECT_ROW_SELECTOR = '[class*="projectRow"]'
|
|
33
|
+
const TITLE_SELECTOR = '[class*="title"]'
|
|
34
|
+
/** A passed gate stays valid this long (trust is durable; the session
|
|
35
|
+
* password table lives in the host process for the session). */
|
|
36
|
+
const GATE_TTL_MS = 5 * 60 * 1000
|
|
37
|
+
/** Cap on interactive retry rounds (wrong password loops etc.). */
|
|
38
|
+
const MAX_ATTEMPTS = 3
|
|
39
|
+
|
|
40
|
+
/** alias → last successful gate timestamp (browser-session scope). */
|
|
41
|
+
const gatePassedAt = new Map<string, number>()
|
|
42
|
+
/** alias → in-flight gate promise (no duplicate dialogs on multi-click). */
|
|
43
|
+
const pending = new Map<string, Promise<boolean>>()
|
|
44
|
+
/** alias → SSH login name (fetched once for the user@alias prompt). */
|
|
45
|
+
let hostsCache: Map<string, string> | null = null
|
|
46
|
+
|
|
47
|
+
async function hostsUser(api: SshApi, alias: string): Promise<string | undefined> {
|
|
48
|
+
if (hostsCache === null) {
|
|
49
|
+
try {
|
|
50
|
+
const list = await api.listHosts()
|
|
51
|
+
hostsCache = new Map(list.map(host => [host.alias, host.user]))
|
|
52
|
+
} catch {
|
|
53
|
+
hostsCache = new Map()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return hostsCache.get(alias)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function gateActive(alias: string, now: number): boolean {
|
|
60
|
+
const at = gatePassedAt.get(alias)
|
|
61
|
+
return at !== undefined && now - at < GATE_TTL_MS
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Mount a dialog component into a fresh portal root; returns its closer.
|
|
65
|
+
* The dialog's onClose prop is forced to the closer so cancel works. */
|
|
66
|
+
function mountModal(node: ReactElement): () => void {
|
|
67
|
+
const host = document.createElement('div')
|
|
68
|
+
host.dataset.sshGateDialog = ''
|
|
69
|
+
document.body.appendChild(host)
|
|
70
|
+
const root = createRoot(host)
|
|
71
|
+
const close = (): void => {
|
|
72
|
+
root.unmount()
|
|
73
|
+
host.remove()
|
|
74
|
+
}
|
|
75
|
+
root.render(createElement(node.type, { ...node.props, onClose: close }))
|
|
76
|
+
return close
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Transient inline error under the clicked row (removed after 8 s).
|
|
80
|
+
* A null row means the caller owns error surfacing — stay silent. */
|
|
81
|
+
function showBanner(row: HTMLElement | null, alias: string, message: string): void {
|
|
82
|
+
if (row === null) return
|
|
83
|
+
const banner = document.createElement('div')
|
|
84
|
+
banner.dataset.sshGateError = ''
|
|
85
|
+
banner.textContent = `${tt('gate.failed', alias)}: ${message}`
|
|
86
|
+
banner.setAttribute(
|
|
87
|
+
'style',
|
|
88
|
+
'margin:2px 4px;padding:6px 8px;font-size:12px;color:#b00020;background:rgba(176,0,32,.08);border-radius:4px;white-space:normal;line-height:1.5',
|
|
89
|
+
)
|
|
90
|
+
row.insertAdjacentElement('afterend', banner)
|
|
91
|
+
setTimeout(() => { banner.remove() }, 8000)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Interactive prompts, resolving true when the user finished the action. */
|
|
95
|
+
function promptFingerprint(api: SshApi, alias: string, fingerprintSha256: string, mismatch: boolean): Promise<boolean> {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
const close = mountModal(createElement(HostFingerprintDialog, {
|
|
98
|
+
api,
|
|
99
|
+
alias,
|
|
100
|
+
fingerprintSha256,
|
|
101
|
+
mismatch,
|
|
102
|
+
onClose: () => { resolve(false) },
|
|
103
|
+
onTrusted: () => { close(); resolve(true) },
|
|
104
|
+
}))
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function promptSecret(api: SshApi, alias: string, secret: 'password' | 'passphrase'): Promise<boolean> {
|
|
109
|
+
return new Promise((resolve) => {
|
|
110
|
+
let closed = false
|
|
111
|
+
const finish = (ok: boolean): void => {
|
|
112
|
+
if (closed) return
|
|
113
|
+
closed = true
|
|
114
|
+
resolve(ok)
|
|
115
|
+
}
|
|
116
|
+
void hostsUser(api, alias).then((user) => {
|
|
117
|
+
const close = mountModal(createElement(SessionSecretDialog, {
|
|
118
|
+
api,
|
|
119
|
+
alias,
|
|
120
|
+
user,
|
|
121
|
+
secret,
|
|
122
|
+
onClose: () => { finish(false) },
|
|
123
|
+
onProvided: () => { close(); finish(true) },
|
|
124
|
+
}))
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Probe + prompt until connected. Resolves true when the alias may proceed
|
|
131
|
+
* (the gate passed); false when the user cancelled or the failure is not
|
|
132
|
+
* interactive (banner left behind).
|
|
133
|
+
*/
|
|
134
|
+
function ensureConnected(api: SshApi, alias: string, row: HTMLElement | null): Promise<boolean> {
|
|
135
|
+
const now = Date.now()
|
|
136
|
+
if (gateActive(alias, now)) return Promise.resolve(true)
|
|
137
|
+
const inFlight = pending.get(alias)
|
|
138
|
+
if (inFlight !== undefined) return inFlight
|
|
139
|
+
|
|
140
|
+
const attempt = (async (): Promise<boolean> => {
|
|
141
|
+
for (let i = 0; i < MAX_ATTEMPTS; i++) {
|
|
142
|
+
try {
|
|
143
|
+
const result = await api.testHost(alias)
|
|
144
|
+
if (result.ok) {
|
|
145
|
+
gatePassedAt.set(alias, Date.now())
|
|
146
|
+
return true
|
|
147
|
+
}
|
|
148
|
+
if (result.code === 'NEEDS_PASSWORD' && (result.secret === 'password' || result.secret === 'passphrase')) {
|
|
149
|
+
if (await promptSecret(api, alias, result.secret)) continue
|
|
150
|
+
return false
|
|
151
|
+
}
|
|
152
|
+
showBanner(row, alias, result.error ?? 'connection failed')
|
|
153
|
+
return false
|
|
154
|
+
} catch (cause) {
|
|
155
|
+
if (cause instanceof SshApiError && (cause.code === 'HOST_KEY_UNKNOWN' || cause.code === 'HOST_KEY_MISMATCH')) {
|
|
156
|
+
const fingerprint = cause.hostKeyFingerprint ?? ''
|
|
157
|
+
if (fingerprint !== '' && await promptFingerprint(api, alias, fingerprint, cause.code === 'HOST_KEY_MISMATCH')) continue
|
|
158
|
+
if (fingerprint === '') showBanner(row, alias, cause.message)
|
|
159
|
+
return false
|
|
160
|
+
}
|
|
161
|
+
showBanner(row, alias, cause instanceof Error ? cause.message : String(cause))
|
|
162
|
+
return false
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
showBanner(row, alias, tt('gate.retryLimit'))
|
|
166
|
+
return false
|
|
167
|
+
})()
|
|
168
|
+
|
|
169
|
+
pending.set(alias, attempt)
|
|
170
|
+
void attempt.finally(() => { pending.delete(alias) })
|
|
171
|
+
return attempt
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Silent prompt-only connection gate (no row / banner) for flows that
|
|
175
|
+
* surface their own errors (e.g. the directory browser). */
|
|
176
|
+
export function connectHost(api: SshApi, alias: string): Promise<boolean> {
|
|
177
|
+
return ensureConnected(api, alias, null)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Mount the click gate over every sidebar workspace row whose title belongs
|
|
182
|
+
* to an SSH-bound workspace. Self-heals via MutationObserver. Returns a
|
|
183
|
+
* disposer that removes listeners and injected state.
|
|
184
|
+
*/
|
|
185
|
+
export function mountWorkspaceGates(
|
|
186
|
+
workspaces: Array<{ id: string; title: string; alias: string }>,
|
|
187
|
+
api: SshApi,
|
|
188
|
+
): () => void {
|
|
189
|
+
const byTitle = new Map<string, string>()
|
|
190
|
+
for (const workspace of workspaces) byTitle.set(workspace.title, workspace.alias)
|
|
191
|
+
|
|
192
|
+
const attach = (row: HTMLElement): void => {
|
|
193
|
+
if (row.dataset.sshGate !== undefined) return
|
|
194
|
+
const titleEl = row.querySelector<HTMLElement>(TITLE_SELECTOR)
|
|
195
|
+
if (titleEl === null || titleEl === undefined) return
|
|
196
|
+
const alias = byTitle.get(titleEl.textContent?.trim() ?? '')
|
|
197
|
+
if (alias === undefined) return
|
|
198
|
+
row.dataset.sshGate = '1'
|
|
199
|
+
row.addEventListener('click', (event: MouseEvent) => {
|
|
200
|
+
if (gateActive(alias, Date.now())) return // passed: let the native click through
|
|
201
|
+
event.preventDefault()
|
|
202
|
+
event.stopPropagation()
|
|
203
|
+
void ensureConnected(api, alias, row).then((ok) => {
|
|
204
|
+
if (ok) row.click() // re-dispatch; the guard now lets it through
|
|
205
|
+
})
|
|
206
|
+
}, true)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const scan = (): void => {
|
|
210
|
+
for (const row of document.querySelectorAll<HTMLElement>(PROJECT_ROW_SELECTOR)) {
|
|
211
|
+
attach(row)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const observer = new MutationObserver(() => { scan() })
|
|
216
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
217
|
+
scan()
|
|
218
|
+
|
|
219
|
+
return () => {
|
|
220
|
+
observer.disconnect()
|
|
221
|
+
for (const row of document.querySelectorAll<HTMLElement>('[data-ssh-gate]')) {
|
|
222
|
+
delete row.dataset.sshGate
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|