dsh-ssh-hub 0.0.0-stage → 0.2.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/README.md +271 -2
- package/cordis.patch.yml +16 -0
- package/icon.svg +3 -0
- package/lib/client.js +13975 -0
- package/lib/index.js +6908 -0
- package/lib/types/activity/history.d.ts +50 -0
- package/lib/types/alerting/notify.d.ts +89 -0
- package/lib/types/alerting/prompt-summary.d.ts +28 -0
- package/lib/types/alerting/rules.d.ts +135 -0
- package/lib/types/alerting/tools.d.ts +30 -0
- package/lib/types/audit/audit-log.d.ts +84 -0
- package/lib/types/audit/recorder.d.ts +50 -0
- package/lib/types/client/api.d.ts +222 -0
- package/lib/types/client/index.d.ts +45 -0
- package/lib/types/client/locales.d.ts +319 -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/DeployTab.d.ts +10 -0
- package/lib/types/client/panel/FleetTab.d.ts +10 -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/LogsTab.d.ts +10 -0
- package/lib/types/client/panel/SshPanel.d.ts +14 -0
- package/lib/types/client/panel/TerminalTab.d.ts +27 -0
- package/lib/types/client/panel/TransferTab.d.ts +7 -0
- package/lib/types/client/panel/TunnelEditDialog.d.ts +15 -0
- package/lib/types/client/panel/TunnelsTab.d.ts +27 -0
- package/lib/types/client/panel/controller.d.ts +253 -0
- package/lib/types/client/panel/helpers.d.ts +45 -0
- package/lib/types/client/panel/tabs.d.ts +62 -0
- package/lib/types/client/panel/xterm.css.d.ts +2 -0
- package/lib/types/client/settings-binding.d.ts +71 -0
- package/lib/types/deploy/orchestrator.d.ts +158 -0
- package/lib/types/deploy/tools.d.ts +14 -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 +183 -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-discovery.d.ts +89 -0
- package/lib/types/engine/tunnel-remarks.d.ts +49 -0
- package/lib/types/engine/tunnel.d.ts +76 -0
- package/lib/types/engine.d.ts +103 -0
- package/lib/types/http.d.ts +59 -0
- package/lib/types/index.d.ts +128 -0
- package/lib/types/inspect/checks.d.ts +118 -0
- package/lib/types/inspect/inspection.d.ts +111 -0
- package/lib/types/inspect/tools.d.ts +50 -0
- package/lib/types/logs/search.d.ts +131 -0
- package/lib/types/logs/tools.d.ts +6 -0
- package/lib/types/loopback.d.ts +64 -0
- package/lib/types/monitor/loop.d.ts +133 -0
- package/lib/types/monitor/metrics.d.ts +151 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/lib/types/protocol.d.ts +524 -0
- package/lib/types/routes.d.ts +82 -0
- package/lib/types/security/known-hosts.d.ts +153 -0
- package/lib/types/security/master-secret.d.ts +157 -0
- package/lib/types/security/redact.d.ts +44 -0
- package/lib/types/security/secrets.d.ts +70 -0
- package/lib/types/ssh-config.d.ts +42 -0
- package/lib/types/store.d.ts +183 -0
- package/lib/types/tool-surface.d.ts +72 -0
- package/lib/types/tools.d.ts +56 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +126 -6
- package/src/activity/history.ts +117 -0
- package/src/alerting/notify.ts +212 -0
- package/src/alerting/prompt-summary.ts +71 -0
- package/src/alerting/rules.ts +281 -0
- package/src/alerting/tools.ts +263 -0
- package/src/audit/audit-log.ts +199 -0
- package/src/audit/recorder.ts +73 -0
- package/src/client/api.ts +782 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +150 -0
- package/src/client/locales.ts +654 -0
- package/src/client/native-panel.tsx +141 -0
- package/src/client/panel/ClusterTab.tsx +141 -0
- package/src/client/panel/DeployTab.tsx +314 -0
- package/src/client/panel/FleetTab.tsx +494 -0
- package/src/client/panel/HostFormDialog.tsx +289 -0
- package/src/client/panel/HostsTab.tsx +395 -0
- package/src/client/panel/LogsTab.tsx +208 -0
- package/src/client/panel/SshPanel.tsx +105 -0
- package/src/client/panel/TerminalTab.tsx +550 -0
- package/src/client/panel/TransferTab.tsx +238 -0
- package/src/client/panel/TunnelEditDialog.tsx +174 -0
- package/src/client/panel/TunnelsTab.tsx +328 -0
- package/src/client/panel/controller.ts +507 -0
- package/src/client/panel/helpers.ts +84 -0
- package/src/client/panel/panel.module.css +1734 -0
- package/src/client/panel/tabs.ts +52 -0
- package/src/client/panel/xterm.css.ts +2 -0
- package/src/client/settings-binding.ts +184 -0
- package/src/deploy/orchestrator.ts +326 -0
- package/src/deploy/tools.ts +225 -0
- package/src/dsh-home.ts +42 -0
- package/src/engine/cluster.ts +60 -0
- package/src/engine/connection-pool.ts +721 -0
- package/src/engine/proxy-command.ts +248 -0
- package/src/engine/pty.ts +78 -0
- package/src/engine/sftp.ts +229 -0
- package/src/engine/terminal-sessions.ts +280 -0
- package/src/engine/tunnel-discovery.ts +353 -0
- package/src/engine/tunnel-remarks.ts +120 -0
- package/src/engine/tunnel.ts +300 -0
- package/src/engine.ts +195 -0
- package/src/http.ts +127 -0
- package/src/index.ts +690 -0
- package/src/inspect/checks.ts +251 -0
- package/src/inspect/inspection.ts +321 -0
- package/src/inspect/tools.ts +366 -0
- package/src/logs/search.ts +251 -0
- package/src/logs/tools.ts +160 -0
- package/src/loopback.ts +119 -0
- package/src/monitor/loop.ts +265 -0
- package/src/monitor/metrics.ts +333 -0
- package/src/mount-once.ts +142 -0
- package/src/protocol.ts +534 -0
- package/src/routes.ts +998 -0
- package/src/security/known-hosts.ts +342 -0
- package/src/security/master-secret.ts +334 -0
- package/src/security/redact.ts +119 -0
- package/src/security/secrets.ts +152 -0
- package/src/ssh-config.ts +182 -0
- package/src/store.ts +757 -0
- package/src/tool-surface.ts +96 -0
- package/src/tools.ts +550 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native panel registration for the SSH panel.
|
|
3
|
+
*
|
|
4
|
+
* The panel is an official-style center-column page, not a DOM takeover: it
|
|
5
|
+
* contributes a row into the sidebar shell's own global panel list
|
|
6
|
+
* (`sidebar.panellist`) and its page into the layout's keyed `main` slot. The
|
|
7
|
+
* shell then owns the row box, the label, the active highlight, the collapsed
|
|
8
|
+
* rail and the panel switch, exactly as it does for the shipped Plugins and
|
|
9
|
+
* Schedule pages and for the task board and the skill center.
|
|
10
|
+
*
|
|
11
|
+
* Both registrations go through `ctx.slots.inject`, which fires only once the
|
|
12
|
+
* owning shell entry has declared the seat: load order between this plugin and
|
|
13
|
+
* ui-layout / ui-sidebar therefore does not matter, and neither does a shell
|
|
14
|
+
* that cannot serve the seats (the callback simply never runs).
|
|
15
|
+
*
|
|
16
|
+
* The terminal's PTY shell lives on the host and outlives this page (see
|
|
17
|
+
* engine/terminal-sessions.ts), so the layout unmounting a deselected page
|
|
18
|
+
* costs the view its xterm instance, not the remote session: the terminal tab
|
|
19
|
+
* reattaches by session id when the page mounts again.
|
|
20
|
+
*
|
|
21
|
+
* @module @linxin666/dsh-client-ssh/client
|
|
22
|
+
*/
|
|
23
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
24
|
+
import type {} from '@deepseek-ai/dsh-client-ui-slots'
|
|
25
|
+
import type {} from '@deepseek-ai/dsh-client-ui-layout/client'
|
|
26
|
+
import type {} from '@deepseek-ai/dsh-client-ui-sidebar/client'
|
|
27
|
+
import type { SshApi } from './api.ts'
|
|
28
|
+
import { SSH_PANEL_ID, type PanelController } from './panel/controller.ts'
|
|
29
|
+
import { tt, type TerminalFontSource } from './panel/helpers.ts'
|
|
30
|
+
import { SshPanel } from './panel/SshPanel.tsx'
|
|
31
|
+
import css from './panel/panel.module.css'
|
|
32
|
+
|
|
33
|
+
/** The panel id shared by the sidebar row and the main-slot occupant. */
|
|
34
|
+
export { SSH_PANEL_ID }
|
|
35
|
+
|
|
36
|
+
/** Row order among the shell's global panel rows (Plugins 0, Schedule 10, board 20, skill center 30). */
|
|
37
|
+
const PANEL_ORDER = 40
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The sidebar row glyph the shell asks for at its own size and active state.
|
|
41
|
+
* The shell owns the button, label, tooltip and rail geometry; this component
|
|
42
|
+
* draws only the glyph, like every other panel row.
|
|
43
|
+
*
|
|
44
|
+
* The glyph carries `data-dsh-panel-entry` because it is the only DOM this
|
|
45
|
+
* panel's own code owns inside that shell-owned row: the L2 contract (skins)
|
|
46
|
+
* resolves which row belongs to which plugin through it, since the shell
|
|
47
|
+
* stamps no per-entry hook of its own (see contracts/semantic-attrs-v1.md).
|
|
48
|
+
* @param props - the shell's icon share: square edge and selection state.
|
|
49
|
+
* @returns the decorative terminal glyph.
|
|
50
|
+
*/
|
|
51
|
+
export function SshPanelIcon({ size }: { size: number; active: boolean }): React.ReactElement {
|
|
52
|
+
return (
|
|
53
|
+
<svg
|
|
54
|
+
data-dsh-panel-entry={SSH_PANEL_ID}
|
|
55
|
+
viewBox="0 0 16 16"
|
|
56
|
+
width={size}
|
|
57
|
+
height={size}
|
|
58
|
+
fill="none"
|
|
59
|
+
stroke="currentColor"
|
|
60
|
+
strokeWidth="1.5"
|
|
61
|
+
strokeLinecap="round"
|
|
62
|
+
strokeLinejoin="round"
|
|
63
|
+
aria-hidden="true"
|
|
64
|
+
>
|
|
65
|
+
<rect x="1.75" y="2.25" width="12.5" height="11.5" rx="1.75" />
|
|
66
|
+
<path d="M4.25 5.25l2.75 2.75-2.75 2.75" />
|
|
67
|
+
<path d="M8.5 10.75h3.25" />
|
|
68
|
+
</svg>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The main-slot page. The layout mounts it only while this panel is selected;
|
|
74
|
+
* the wrapper carries the pinned `data-dsh-ssh-view` semantic anchor (L2
|
|
75
|
+
* contract, skins) the takeover container used to own.
|
|
76
|
+
* @param props - the framework main-slot share plus this entry's injected face.
|
|
77
|
+
* @returns the SSH panel page.
|
|
78
|
+
*/
|
|
79
|
+
export function SshPanelPage({ controller, api, terminalFont }: {
|
|
80
|
+
controller: PanelController
|
|
81
|
+
api: SshApi
|
|
82
|
+
terminalFont?: TerminalFontSource
|
|
83
|
+
}): React.ReactElement {
|
|
84
|
+
return (
|
|
85
|
+
<div className={css.view} data-dsh-ssh-view="" data-dsh-plugin="ssh">
|
|
86
|
+
<SshPanel controller={controller} api={api} terminalFont={terminalFont} />
|
|
87
|
+
</div>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The injected face both registrations receive. */
|
|
92
|
+
interface PanelFace {
|
|
93
|
+
controller: PanelController
|
|
94
|
+
api: SshApi
|
|
95
|
+
terminalFont?: TerminalFontSource
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Register the SSH panel's sidebar row and center-column page.
|
|
100
|
+
*
|
|
101
|
+
* Both seats are declared by shell plugins this package does not depend on at
|
|
102
|
+
* runtime, so each registration is wrapped in `ctx.slots.inject`: the callback
|
|
103
|
+
* runs only after the owning entry declares the seat, and a shell that never
|
|
104
|
+
* declares it leaves the panel simply absent instead of failing boot.
|
|
105
|
+
* @param ctx - client root context (services: slots).
|
|
106
|
+
* @param controller - the controller the page and the row drive.
|
|
107
|
+
* @param api - the SSH API client the page operates through.
|
|
108
|
+
* @param terminalFont - live terminal-font setting source (issue #577).
|
|
109
|
+
* @returns disposer releasing both registrations.
|
|
110
|
+
*/
|
|
111
|
+
export function registerSshPanel(
|
|
112
|
+
ctx: ClientContext,
|
|
113
|
+
controller: PanelController,
|
|
114
|
+
api: SshApi,
|
|
115
|
+
terminalFont?: TerminalFontSource,
|
|
116
|
+
): () => void {
|
|
117
|
+
const slots = ctx.slots as {
|
|
118
|
+
inject(key: string, callback: () => () => void): () => void
|
|
119
|
+
register(options: Record<string, unknown>, component: unknown): () => void
|
|
120
|
+
}
|
|
121
|
+
const disposers: Array<() => void> = []
|
|
122
|
+
|
|
123
|
+
disposers.push(slots.inject('sidebar.panellist', () => slots.register({
|
|
124
|
+
name: 'sidebar.panellist',
|
|
125
|
+
id: SSH_PANEL_ID,
|
|
126
|
+
order: PANEL_ORDER,
|
|
127
|
+
// The shell resolves this through resolveSlotLabel on every locale change,
|
|
128
|
+
// so the module-level translate reads the active language at call time.
|
|
129
|
+
label: () => tt('entry.label'),
|
|
130
|
+
}, SshPanelIcon)))
|
|
131
|
+
|
|
132
|
+
disposers.push(slots.inject('main', () => slots.register({
|
|
133
|
+
name: 'main',
|
|
134
|
+
key: SSH_PANEL_ID,
|
|
135
|
+
inject: (): PanelFace => ({ controller, api, terminalFont }),
|
|
136
|
+
}, SshPanelPage as never)))
|
|
137
|
+
|
|
138
|
+
return () => {
|
|
139
|
+
for (const dispose of disposers.splice(0)) dispose()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
// Mirror the server's rule: a command alone is not enough, because running it
|
|
33
|
+
// against the whole fleet by accident is exactly what the selector requirement
|
|
34
|
+
// exists to prevent. See src/engine/cluster.ts.
|
|
35
|
+
const hasSelector = splitList(aliases).length > 0
|
|
36
|
+
|| environment.trim() !== ''
|
|
37
|
+
|| splitList(tags).length > 0
|
|
38
|
+
const canRun = command.trim() !== '' && hasSelector
|
|
39
|
+
|
|
40
|
+
const run = async (): Promise<void> => {
|
|
41
|
+
if (!canRun || running) return
|
|
42
|
+
if (!window.confirm(tt('cluster.confirm'))) return
|
|
43
|
+
setRunning(true)
|
|
44
|
+
setError(null)
|
|
45
|
+
try {
|
|
46
|
+
const aliasList = splitList(aliases)
|
|
47
|
+
const tagList = splitList(tags)
|
|
48
|
+
const outcome = await api.cluster({
|
|
49
|
+
command: command.trim(),
|
|
50
|
+
aliases: aliasList.length > 0 ? aliasList : undefined,
|
|
51
|
+
environment: environment.trim() === '' ? undefined : environment.trim(),
|
|
52
|
+
tags: tagList.length > 0 ? tagList : undefined,
|
|
53
|
+
})
|
|
54
|
+
setResults(outcome)
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
setError(errorMessage(cause))
|
|
57
|
+
} finally {
|
|
58
|
+
setRunning(false)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className={css.fillBody}>
|
|
64
|
+
<div className={css.clusterForm}>
|
|
65
|
+
<label className={css.field}>
|
|
66
|
+
<span className={css.fieldLabel}>{tt('cluster.command')}</span>
|
|
67
|
+
<textarea className={css.input + ' ' + css.commandInput} value={command} onChange={event => { setCommand(event.target.value) }} />
|
|
68
|
+
</label>
|
|
69
|
+
<div className={css.clusterFilters}>
|
|
70
|
+
{/* Placeholder-only fields have no accessible name: a screen reader
|
|
71
|
+
announces them as "edit text" with no indication of which filter it
|
|
72
|
+
is. The placeholders already carry the label text, so they are
|
|
73
|
+
reused as the aria-label rather than duplicated in the locale. */}
|
|
74
|
+
<input className={css.input} aria-label={tt('cluster.aliases')} placeholder={tt('cluster.aliases')} value={aliases} onChange={event => { setAliases(event.target.value) }} />
|
|
75
|
+
<input className={css.input} aria-label={tt('cluster.environment')} placeholder={tt('cluster.environment')} value={environment} onChange={event => { setEnvironment(event.target.value) }} />
|
|
76
|
+
<input className={css.input} aria-label={tt('cluster.tags')} placeholder={tt('cluster.tags')} value={tags} onChange={event => { setTags(event.target.value) }} />
|
|
77
|
+
</div>
|
|
78
|
+
<div className={css.clusterActions}>
|
|
79
|
+
<button type="button" className={css.primaryButton} disabled={running || !canRun} onClick={() => { void run() }}>{tt('cluster.run')}</button>
|
|
80
|
+
{/* The server rejects a run with no selector outright, so the button
|
|
81
|
+
waits for one too. Leaving it enabled meant the user typed a
|
|
82
|
+
command, pressed Run, and got a 400 explaining the rule they were
|
|
83
|
+
never told: the filters are placeholders-only, so the requirement
|
|
84
|
+
had no visible home. Say it before the click, not after. */}
|
|
85
|
+
{!canRun && <span className={css.inlineHint}>{tt('cluster.needSelector')}</span>}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
{error !== null && <div className={css.banner} data-kind="error" role="alert">{tt('common.error', { error })}</div>}
|
|
89
|
+
{results === null && error === null && <div className={css.empty}>{tt('cluster.empty')}</div>}
|
|
90
|
+
{results !== null && results.length === 0 && <div className={css.empty}>{tt('cluster.noMatch')}</div>}
|
|
91
|
+
{results !== null && results.length > 0 && (
|
|
92
|
+
<div className={css.tableWrap}>
|
|
93
|
+
<table className={css.table}>
|
|
94
|
+
<thead>
|
|
95
|
+
<tr>
|
|
96
|
+
<th>{tt('cluster.col.alias')}</th>
|
|
97
|
+
<th>{tt('cluster.col.status')}</th>
|
|
98
|
+
<th>{tt('cluster.col.exit')}</th>
|
|
99
|
+
<th>{tt('cluster.col.stdout')}</th>
|
|
100
|
+
<th>{tt('cluster.col.stderr')}</th>
|
|
101
|
+
<th>{tt('cluster.col.error')}</th>
|
|
102
|
+
<th>{tt('cluster.col.duration')}</th>
|
|
103
|
+
</tr>
|
|
104
|
+
</thead>
|
|
105
|
+
<tbody>
|
|
106
|
+
{results.map(result => {
|
|
107
|
+
const status = result.ok ? 'ok' : result.timedOut === true ? 'timeout' : 'fail'
|
|
108
|
+
const label = result.ok ? tt('cluster.ok') : result.timedOut === true ? tt('cluster.timeout') : tt('cluster.fail')
|
|
109
|
+
return (
|
|
110
|
+
<tr key={result.alias}>
|
|
111
|
+
<td className={css.mono}>{result.alias}</td>
|
|
112
|
+
<td><span className={css.badge} data-status={status}>{label}</span></td>
|
|
113
|
+
<td className={css.mono}>{result.exitCode ?? '-'}</td>
|
|
114
|
+
<td>
|
|
115
|
+
{result.stdout !== undefined && result.stdout !== '' && (
|
|
116
|
+
<details className={css.cellDetails}>
|
|
117
|
+
<summary>{tt('cluster.col.stdout')}</summary>
|
|
118
|
+
<pre className={css.cellPre}>{result.stdout}</pre>
|
|
119
|
+
</details>
|
|
120
|
+
)}
|
|
121
|
+
</td>
|
|
122
|
+
<td>
|
|
123
|
+
{result.stderr !== undefined && result.stderr !== '' && (
|
|
124
|
+
<details className={css.cellDetails}>
|
|
125
|
+
<summary>{tt('cluster.col.stderr')}</summary>
|
|
126
|
+
<pre className={css.cellPre}>{result.stderr}</pre>
|
|
127
|
+
</details>
|
|
128
|
+
)}
|
|
129
|
+
</td>
|
|
130
|
+
<td className={css.cellMuted}>{result.error ?? ''}</td>
|
|
131
|
+
<td className={css.mono}>{result.durationMs !== undefined ? result.durationMs + ' ms' : '-'}</td>
|
|
132
|
+
</tr>
|
|
133
|
+
)
|
|
134
|
+
})}
|
|
135
|
+
</tbody>
|
|
136
|
+
</table>
|
|
137
|
+
</div>
|
|
138
|
+
)}
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deploy tab: run a rollout and read what it did.
|
|
3
|
+
*
|
|
4
|
+
* Two halves, deliberately in this order. The form on top is how a plan is
|
|
5
|
+
* submitted; the history below is what actually happened, including runs from
|
|
6
|
+
* earlier sessions. A deployment surface that only shows the result of the run
|
|
7
|
+
* you just triggered cannot answer "did last night's rollout finish", which is
|
|
8
|
+
* the question that matters more often.
|
|
9
|
+
*
|
|
10
|
+
* Every step requires its rollback command, and the form enforces it before
|
|
11
|
+
* submitting. The host route refuses a plan without one too — this is the same
|
|
12
|
+
* rule stated twice, because a UI that lets you compose an unrollbackable plan
|
|
13
|
+
* and only fails at submit time teaches the wrong habit.
|
|
14
|
+
*
|
|
15
|
+
* No host picker per step: the plan is uniform across the fleet, which is what
|
|
16
|
+
* makes a rollout reviewable. Per-host divergence belongs in a different tool.
|
|
17
|
+
*/
|
|
18
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
19
|
+
import type { SshApi } from '../api.ts'
|
|
20
|
+
import type { DeployPlanPayload, DeployRunRow, DeployStepPayload, SshHostSummary } from '../../protocol.ts'
|
|
21
|
+
import { errorMessage, tt } from './helpers.ts'
|
|
22
|
+
import css from './panel.module.css'
|
|
23
|
+
|
|
24
|
+
/** Deploy tab props. */
|
|
25
|
+
export interface DeployTabProps {
|
|
26
|
+
/** The SSH API client. */
|
|
27
|
+
api: SshApi
|
|
28
|
+
/** Whether the panel is open, so refreshes only run while visible. */
|
|
29
|
+
active: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Format an epoch millisecond value as a short local timestamp. */
|
|
33
|
+
function stamp(ms: number | undefined): string {
|
|
34
|
+
if (ms === undefined) return '—'
|
|
35
|
+
return new Date(ms).toLocaleString(undefined, { hour12: false })
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One editable step row. */
|
|
39
|
+
interface StepDraft {
|
|
40
|
+
name: string
|
|
41
|
+
command: string
|
|
42
|
+
rollbackCommand: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A blank step the form starts from. */
|
|
46
|
+
const EMPTY_STEP: StepDraft = { name: '', command: '', rollbackCommand: '' }
|
|
47
|
+
|
|
48
|
+
/** The deploy tab. */
|
|
49
|
+
export function DeployTab({ api, active }: DeployTabProps) {
|
|
50
|
+
const [hosts, setHosts] = useState<SshHostSummary[]>([])
|
|
51
|
+
const [runs, setRuns] = useState<DeployRunRow[]>([])
|
|
52
|
+
const [planId, setPlanId] = useState('')
|
|
53
|
+
const [steps, setSteps] = useState<StepDraft[]>([{ ...EMPTY_STEP }])
|
|
54
|
+
const [batchSize, setBatchSize] = useState('5')
|
|
55
|
+
const [stopOnFailure, setStopOnFailure] = useState(true)
|
|
56
|
+
const [selected, setSelected] = useState<string[]>([])
|
|
57
|
+
const [healthCommand, setHealthCommand] = useState('')
|
|
58
|
+
const [busy, setBusy] = useState(false)
|
|
59
|
+
const [error, setError] = useState<string | null>(null)
|
|
60
|
+
const [notice, setNotice] = useState<string | null>(null)
|
|
61
|
+
const [expanded, setExpanded] = useState<string | null>(null)
|
|
62
|
+
|
|
63
|
+
const refresh = useCallback(async (): Promise<void> => {
|
|
64
|
+
try {
|
|
65
|
+
setError(null)
|
|
66
|
+
const [nextHosts, nextRuns] = await Promise.all([api.listHosts(), api.deployHistory(20)])
|
|
67
|
+
setHosts(nextHosts)
|
|
68
|
+
setRuns(nextRuns)
|
|
69
|
+
} catch (cause) {
|
|
70
|
+
setError(errorMessage(cause))
|
|
71
|
+
}
|
|
72
|
+
}, [api])
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!active) return
|
|
76
|
+
void refresh()
|
|
77
|
+
}, [active, refresh])
|
|
78
|
+
|
|
79
|
+
/** Replace one step field without disturbing the others. */
|
|
80
|
+
const editStep = (index: number, patch: Partial<StepDraft>): void => {
|
|
81
|
+
setSteps(current => current.map((step, at) => (at === index ? { ...step, ...patch } : step)))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const submit = async (): Promise<void> => {
|
|
85
|
+
if (busy) return
|
|
86
|
+
setError(null)
|
|
87
|
+
setNotice(null)
|
|
88
|
+
if (planId.trim() === '') { setError(tt('deploy.error.noPlanId')); return }
|
|
89
|
+
const filled = steps.filter(step => step.command.trim() !== '')
|
|
90
|
+
if (filled.length === 0) { setError(tt('deploy.error.noSteps')); return }
|
|
91
|
+
const unrollbackable = filled.filter(step => step.rollbackCommand.trim() === '')
|
|
92
|
+
if (unrollbackable.length > 0) {
|
|
93
|
+
// The host refuses this too; catching it here means the operator learns
|
|
94
|
+
// the rule before a rollout is half submitted.
|
|
95
|
+
setError(tt('deploy.error.noRollback'))
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
// This is the most destructive action in the panel: it runs arbitrary
|
|
99
|
+
// commands on many hosts at once. Every comparable action here confirms
|
|
100
|
+
// first (host delete, cluster run, stop-all), so deploying without one was
|
|
101
|
+
// an inconsistency as well as a gap. Name the plan, the target count and the
|
|
102
|
+
// rollback intent, because those are what an operator needs to re-check.
|
|
103
|
+
const targetCount = selected.length === 0 ? hosts.length : selected.length
|
|
104
|
+
if (!window.confirm(tt('deploy.confirm', { plan: planId.trim(), count: targetCount }))) return
|
|
105
|
+
const plan: DeployPlanPayload = {
|
|
106
|
+
id: planId.trim(),
|
|
107
|
+
steps: filled.map((step, index) => ({
|
|
108
|
+
// A step with no name would be unidentifiable in the report.
|
|
109
|
+
name: step.name.trim() === '' ? `step-${String(index + 1)}` : step.name.trim(),
|
|
110
|
+
command: step.command,
|
|
111
|
+
rollbackCommand: step.rollbackCommand,
|
|
112
|
+
})),
|
|
113
|
+
batchSize: Number(batchSize) > 0 ? Number(batchSize) : 5,
|
|
114
|
+
stopOnFailure,
|
|
115
|
+
...(healthCommand.trim() === ''
|
|
116
|
+
? {}
|
|
117
|
+
: { healthCheck: { command: healthCommand, expectExitCode: 0 } }),
|
|
118
|
+
}
|
|
119
|
+
setBusy(true)
|
|
120
|
+
try {
|
|
121
|
+
const run = await api.deploy(plan, selected.length > 0 ? selected : undefined)
|
|
122
|
+
setNotice(tt('deploy.done').replace('{ok}', String(run.hosts.filter(host => host.ok).length)).replace('{total}', String(run.hosts.length)))
|
|
123
|
+
setExpanded(run.id)
|
|
124
|
+
await refresh()
|
|
125
|
+
} catch (cause) {
|
|
126
|
+
setError(errorMessage(cause))
|
|
127
|
+
} finally {
|
|
128
|
+
setBusy(false)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const toggleTarget = (alias: string): void => {
|
|
133
|
+
setSelected(current => (current.includes(alias) ? current.filter(item => item !== alias) : [...current, alias]))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div className={css.panel}>
|
|
138
|
+
{error !== null && <div className={css.banner} data-kind="error" role="alert">{error}</div>}
|
|
139
|
+
{notice !== null && <div className={css.banner} data-kind="info">{notice}</div>}
|
|
140
|
+
|
|
141
|
+
<section className={css.formCard}>
|
|
142
|
+
<h3 className={css.sectionTitle}>{tt('deploy.form.title')}</h3>
|
|
143
|
+
<p className={css.hint}>{tt('deploy.form.hint')}</p>
|
|
144
|
+
|
|
145
|
+
<label className={css.field}>
|
|
146
|
+
<span className={css.fieldLabel}>{tt('deploy.form.planId')}</span>
|
|
147
|
+
<input className={css.input} value={planId} onChange={event => { setPlanId(event.target.value) }} placeholder="release-2026-11-16" />
|
|
148
|
+
</label>
|
|
149
|
+
|
|
150
|
+
{steps.map((step, index) => (
|
|
151
|
+
<div className={css.stepCard} key={index}>
|
|
152
|
+
<div className={css.stepHead}>
|
|
153
|
+
<strong>{tt('deploy.form.step')} {index + 1}</strong>
|
|
154
|
+
{steps.length > 1 && (
|
|
155
|
+
<button
|
|
156
|
+
type="button"
|
|
157
|
+
className={css.linkButton}
|
|
158
|
+
onClick={() => { setSteps(current => current.filter((_, at) => at !== index)) }}
|
|
159
|
+
>
|
|
160
|
+
{tt('deploy.form.removeStep')}
|
|
161
|
+
</button>
|
|
162
|
+
)}
|
|
163
|
+
</div>
|
|
164
|
+
<label className={css.field}>
|
|
165
|
+
<span className={css.fieldLabel}>{tt('deploy.form.stepName')}</span>
|
|
166
|
+
<input className={css.input} value={step.name} onChange={event => { editStep(index, { name: event.target.value }) }} placeholder="replace-binary" />
|
|
167
|
+
</label>
|
|
168
|
+
<label className={css.field}>
|
|
169
|
+
<span className={css.fieldLabel}>{tt('deploy.form.command')}</span>
|
|
170
|
+
<textarea
|
|
171
|
+
className={css.input}
|
|
172
|
+
rows={2}
|
|
173
|
+
value={step.command}
|
|
174
|
+
onChange={event => { editStep(index, { command: event.target.value }) }}
|
|
175
|
+
placeholder="systemctl stop app && cp new /opt/app/app && systemctl start app"
|
|
176
|
+
/>
|
|
177
|
+
</label>
|
|
178
|
+
<label className={css.field}>
|
|
179
|
+
<span className={css.fieldLabel}>{tt('deploy.form.rollback')} <em className={css.cellMuted}>{tt('deploy.form.rollbackWhy')}</em></span>
|
|
180
|
+
<textarea
|
|
181
|
+
className={css.input}
|
|
182
|
+
rows={2}
|
|
183
|
+
value={step.rollbackCommand}
|
|
184
|
+
onChange={event => { editStep(index, { rollbackCommand: event.target.value }) }}
|
|
185
|
+
placeholder="cp /opt/app/app.prev /opt/app/app && systemctl start app"
|
|
186
|
+
/>
|
|
187
|
+
</label>
|
|
188
|
+
</div>
|
|
189
|
+
))}
|
|
190
|
+
|
|
191
|
+
<button type="button" className={css.secondaryButton} onClick={() => { setSteps(current => [...current, { ...EMPTY_STEP }]) }}>
|
|
192
|
+
{tt('deploy.form.addStep')}
|
|
193
|
+
</button>
|
|
194
|
+
|
|
195
|
+
<div className={css.inlineRow}>
|
|
196
|
+
<label className={css.field}>
|
|
197
|
+
<span className={css.fieldLabel}>{tt('deploy.form.batchSize')}</span>
|
|
198
|
+
<input className={css.input} value={batchSize} onChange={event => { setBatchSize(event.target.value) }} inputMode="numeric" />
|
|
199
|
+
</label>
|
|
200
|
+
<label className={css.checkRow}>
|
|
201
|
+
<input type="checkbox" checked={stopOnFailure} onChange={event => { setStopOnFailure(event.target.checked) }} />
|
|
202
|
+
<span className={css.fieldLabel}>{tt('deploy.form.stopOnFailure')}</span>
|
|
203
|
+
</label>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<label className={css.field}>
|
|
207
|
+
<span className={css.fieldLabel}>{tt('deploy.form.health')} <em className={css.cellMuted}>{tt('deploy.form.healthOptional')}</em></span>
|
|
208
|
+
<input
|
|
209
|
+
className={css.input}
|
|
210
|
+
value={healthCommand}
|
|
211
|
+
onChange={event => { setHealthCommand(event.target.value) }}
|
|
212
|
+
placeholder="systemctl is-active app"
|
|
213
|
+
/>
|
|
214
|
+
</label>
|
|
215
|
+
|
|
216
|
+
<div className={css.field}>
|
|
217
|
+
<span className={css.fieldLabel}>{tt('deploy.form.targets')} <em className={css.cellMuted}>{tt('deploy.form.targetsHint')}</em></span>
|
|
218
|
+
<div className={css.chipRow}>
|
|
219
|
+
{hosts.length === 0 && <span className={css.cellMuted}>{tt('deploy.form.noHosts')}</span>}
|
|
220
|
+
{hosts.map(host => (
|
|
221
|
+
<button
|
|
222
|
+
key={host.alias}
|
|
223
|
+
type="button"
|
|
224
|
+
className={css.chip}
|
|
225
|
+
data-selected={selected.includes(host.alias) ? 'true' : 'false'}
|
|
226
|
+
onClick={() => { toggleTarget(host.alias) }}
|
|
227
|
+
>
|
|
228
|
+
{host.alias}
|
|
229
|
+
</button>
|
|
230
|
+
))}
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
<button type="button" className={css.primaryButton} disabled={busy} onClick={() => { void submit() }}>
|
|
235
|
+
{busy ? tt('deploy.form.running') : tt('deploy.form.run')}
|
|
236
|
+
</button>
|
|
237
|
+
</section>
|
|
238
|
+
|
|
239
|
+
<section>
|
|
240
|
+
<h3 className={css.sectionTitle}>{tt('deploy.history.title')}</h3>
|
|
241
|
+
{runs.length === 0 && <p className={css.hint}>{tt('deploy.history.empty')}</p>}
|
|
242
|
+
{runs.length > 0 && (
|
|
243
|
+
<div className={css.tableWrap}>
|
|
244
|
+
<table className={css.table}>
|
|
245
|
+
<thead>
|
|
246
|
+
<tr>
|
|
247
|
+
<th>{tt('deploy.col.time')}</th>
|
|
248
|
+
<th>{tt('deploy.col.plan')}</th>
|
|
249
|
+
<th>{tt('deploy.col.hosts')}</th>
|
|
250
|
+
<th>{tt('deploy.col.result')}</th>
|
|
251
|
+
<th />
|
|
252
|
+
</tr>
|
|
253
|
+
</thead>
|
|
254
|
+
<tbody>
|
|
255
|
+
{runs.map(run => {
|
|
256
|
+
const failed = run.hosts.filter(host => !host.ok).length
|
|
257
|
+
return (
|
|
258
|
+
<tr key={run.id}>
|
|
259
|
+
<td className={css.cellMuted}>{stamp(run.at)}</td>
|
|
260
|
+
<td>{run.planId}</td>
|
|
261
|
+
<td>
|
|
262
|
+
{run.hostCount}
|
|
263
|
+
{failed > 0 && <span className={css.cellMuted}> ({failed} {tt('deploy.col.failed')})</span>}
|
|
264
|
+
</td>
|
|
265
|
+
<td><span className={css.badge} data-status={run.ok ? 'ok' : 'fail'}>{run.ok ? tt('deploy.ok') : tt('deploy.failed')}</span></td>
|
|
266
|
+
<td>
|
|
267
|
+
<button type="button" className={css.linkButton} onClick={() => { setExpanded(expanded === run.id ? null : run.id) }}>
|
|
268
|
+
{expanded === run.id ? tt('deploy.hide') : tt('deploy.show')}
|
|
269
|
+
</button>
|
|
270
|
+
</td>
|
|
271
|
+
</tr>
|
|
272
|
+
)
|
|
273
|
+
})}
|
|
274
|
+
</tbody>
|
|
275
|
+
</table>
|
|
276
|
+
</div>
|
|
277
|
+
)}
|
|
278
|
+
|
|
279
|
+
{expanded !== null && (() => {
|
|
280
|
+
const run = runs.find(candidate => candidate.id === expanded)
|
|
281
|
+
if (run === undefined) return null
|
|
282
|
+
return (
|
|
283
|
+
<div className={css.tableWrap}>
|
|
284
|
+
<table className={css.table}>
|
|
285
|
+
<thead>
|
|
286
|
+
<tr>
|
|
287
|
+
<th>{tt('deploy.col.host')}</th>
|
|
288
|
+
<th>{tt('deploy.col.result')}</th>
|
|
289
|
+
<th>{tt('deploy.col.health')}</th>
|
|
290
|
+
<th>{tt('deploy.col.detail')}</th>
|
|
291
|
+
</tr>
|
|
292
|
+
</thead>
|
|
293
|
+
<tbody>
|
|
294
|
+
{run.hosts.map(host => (
|
|
295
|
+
<tr key={host.alias}>
|
|
296
|
+
<td>{host.alias}</td>
|
|
297
|
+
<td><span className={css.badge} data-status={host.ok ? 'ok' : 'fail'}>{host.ok ? tt('deploy.ok') : tt('deploy.failed')}</span></td>
|
|
298
|
+
<td className={css.cellMuted}>
|
|
299
|
+
{host.healthy === undefined ? '—' : host.healthy ? tt('deploy.ok') : tt('deploy.failed')}
|
|
300
|
+
</td>
|
|
301
|
+
<td className={css.cellMuted}>
|
|
302
|
+
{host.error ?? (host.rolledBack === true ? tt('deploy.rolledBack') : '—')}
|
|
303
|
+
</td>
|
|
304
|
+
</tr>
|
|
305
|
+
))}
|
|
306
|
+
</tbody>
|
|
307
|
+
</table>
|
|
308
|
+
</div>
|
|
309
|
+
)
|
|
310
|
+
})()}
|
|
311
|
+
</section>
|
|
312
|
+
</div>
|
|
313
|
+
)
|
|
314
|
+
}
|