dsh-ops-kit 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client.js +61 -8
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -697,6 +697,19 @@ window.__ModuleLoader__.load({
697
697
  }, host.name)))
698
698
 
699
699
  /** 监控:CPU/内存/磁盘/网络/IO 曲线;自己加载采样,不牵动其它 tab。 */
700
+ /** 只有这类 unit 值得推荐给普通用户;dbus/getty/gssproxy 等系统服务不提示。 */
701
+ const BUSINESS_SERVICE = /(nginx|apache|httpd|mysql|mariadb|postgres|redis|mongo|elasticsearch|php|java|tomcat|node|pm2|gunicorn|uwsgi|docker|containerd|supervisor|frp|traefik|caddy|haproxy|kafka|rabbit|memcached|minio|baota)/i
702
+ const BUSINESS_PORTS = new Set([80, 443, 3000, 3306, 5432, 6379, 8000, 8080, 8443, 9000, 9200, 27017])
703
+ /** 操作系统自带的服务:默认不推荐、不打扰用户。其余 unit 视为业务程序。 */
704
+ const SYSTEM_UNIT = /^(dbus|dbus-|getty|gssproxy|chronyd|cloudmonitor|aegis|aliyun|atd|crond|cron|firewalld|sshd|systemd|polkit|udisks|accounts-daemon|networkmanager|wpa_supplicant|rpc|rpcbind|irqbalance|rsyslog|auditd|tuned|kdump|kmod|bluetooth|avahi|cups|modemmanager|thermald|upower|multipathd|lvm2|dracut|nscd|sssd|oddjob|certmonger|abrt|packagekit|serial-getty|console-getty|user@|postfix|nfs|iscsid|iscsi|target|kubelet|bt-|baota|bt_tool)/i
705
+
706
+ function isBusinessService(name) {
707
+ const unit = String(name || '').toLowerCase().replace(/\.service$/, '')
708
+ if (!unit) return false
709
+ if (BUSINESS_SERVICE.test(unit)) return true
710
+ return !SYSTEM_UNIT.test(unit)
711
+ }
712
+
700
713
  function MonitorTab({ hosts, detailHost, detailTab, loadingMap, markLoading, setError }) {
701
714
  const [mHost, setMHost] = React.useState('')
702
715
  const [mHours, setMHours] = React.useState(6)
@@ -2184,13 +2197,17 @@ window.__ModuleLoader__.load({
2184
2197
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadInv(cHost || hosts[0]?.name, true) } }, busy === 'scan' ? T.rescanning : T.rescan)),
2185
2198
  h('div', { className: 'ops-card' },
2186
2199
  h('div', { className: 'ops-card-h' },
2187
- h('span', null, T.suggest, h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(monitorSuggestions.length))),
2200
+ h('span', null, L('建议监控(只列业务程序)', 'Suggested monitors (business apps only)'),
2201
+ h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(monitorSuggestions.length))),
2188
2202
  h('button', {
2189
2203
  className: 'ops-btn ops-btn-primary ops-btn-sm',
2190
2204
  disabled: monitorSuggestions.length === 0 || monBusy === 'suggest',
2191
2205
  onClick: () => { void addSuggestions(monitorSuggestions) },
2192
2206
  }, monBusy === 'suggest' ? T.reading : T.suggestAll)),
2193
2207
  h('div', { className: 'ops-card-b' },
2208
+ h('p', { className: 'ops-sub', style: { margin: '0 0 8px' } },
2209
+ L('只会列出 nginx、mysql、redis 这类业务程序;dbus、getty 等系统服务默认不出现,也不需要你管。',
2210
+ 'Only business apps such as nginx, mysql and redis are listed. System units (dbus, getty…) are left alone.')),
2194
2211
  monitorSuggestions.length === 0
2195
2212
  ? h('p', { className: 'ops-empty' }, T.suggestNone)
2196
2213
  : h('div', null, ...monitorSuggestions.slice(0, 12).map(item => h('div', {
@@ -2205,7 +2222,10 @@ window.__ModuleLoader__.load({
2205
2222
  h('span', { style: { display: 'flex', justifyContent: 'flex-end' } },
2206
2223
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void addSuggestions([item]) } }, T.suggestAdd))))))),
2207
2224
  h('div', { className: 'ops-card' },
2208
- h('div', { className: 'ops-card-h' }, h('span', null, T.tabs[3]), h('span', { className: 'ops-chip' }, String((inv?.apps || []).length))),
2225
+ h('div', { className: 'ops-card-h' }, h('span', null, L('你的业务程序', 'Your apps')), h('span', { className: 'ops-chip' }, String((inv?.apps || []).length))),
2226
+ h('p', { className: 'ops-sub', style: { margin: '8px 14px 0' } },
2227
+ L('「日志」看运行记录;「重启」会中断服务几秒。系统自带的程序不在这里。',
2228
+ 'Logs shows recent output; Restart briefly interrupts the service. System units are not listed.')),
2209
2229
  (inv?.apps || []).length === 0 ? h('p', { className: 'ops-empty' }, T.empty)
2210
2230
  : h('div', { className: 'ops-list' }, ...(inv.apps || []).map(app => h('div', { key: app.kind + app.name, className: 'ops-row' },
2211
2231
  h('span', null, h('span', { className: 'ops-chip', style: { marginRight: '6px' } }, app.kind), h('span', { className: 'ops-name' }, app.name)),
@@ -2738,11 +2758,11 @@ window.__ModuleLoader__.load({
2738
2758
  return hostDetailView
2739
2759
  }
2740
2760
 
2741
- function Panel() {
2761
+ function Panel({ initialHosts = [], initialDetailHost = null, initialDetailTab = 'summary' } = {}) {
2742
2762
  const [tab, setTab] = React.useState(0)
2743
- const [detailHost, setDetailHost] = React.useState(null)
2744
- const [detailTab, setDetailTab] = React.useState('summary')
2745
- const [hosts, setHosts] = React.useState([])
2763
+ const [detailHost, setDetailHost] = React.useState(initialDetailHost)
2764
+ const [detailTab, setDetailTab] = React.useState(initialDetailTab)
2765
+ const [hosts, setHosts] = React.useState(initialHosts)
2746
2766
  const [config, setConfig] = React.useState({ enabled: true, intervalMinutes: 10, diskWarnPercent: 90, metricsMinutes: 5 })
2747
2767
  const [overview, setOverview] = React.useState({})
2748
2768
  const [cHost, setCHost] = React.useState('')
@@ -3255,11 +3275,12 @@ window.__ModuleLoader__.load({
3255
3275
  const items = []
3256
3276
  for (const row of inv.services || []) {
3257
3277
  const unit = String(row).trim().split(/\s+/)[0]
3258
- if (!unit) continue
3278
+ if (!unit || !isBusinessService(unit)) continue
3259
3279
  items.push({ type: 'service', target: unit, label: serviceLabel(row) || unit })
3260
3280
  }
3261
3281
  for (const port of inv.portsParsed || []) {
3262
3282
  if (!port?.port) continue
3283
+ if (!BUSINESS_PORTS.has(Number(port.port)) && !isBusinessService(port.process)) continue
3263
3284
  items.push({ type: 'port', target: `127.0.0.1:${port.port}`, label: `${port.process || L('端口', 'Port')} :${port.port}` })
3264
3285
  }
3265
3286
  for (const line of inv.nginx || []) {
@@ -3278,6 +3299,34 @@ window.__ModuleLoader__.load({
3278
3299
  })
3279
3300
  })()
3280
3301
 
3302
+ const termKey = (event) => {
3303
+ if (!term?.id) return
3304
+ if (aiMode) {
3305
+ if (event.key === 'Escape') { event.preventDefault(); setAiMode(false); setAiDraft(''); return }
3306
+ if (event.key === 'Enter') { event.preventDefault(); void aiFill(aiDraft); return }
3307
+ if (event.key === 'Backspace') { event.preventDefault(); setAiDraft(current => current.slice(0, -1)); return }
3308
+ if (!event.ctrlKey && !event.metaKey && !event.altKey && event.key.length === 1) {
3309
+ event.preventDefault(); setAiDraft(current => current + event.key); return
3310
+ }
3311
+ return
3312
+ }
3313
+ if (event.key === '?' && !event.ctrlKey && !event.metaKey && !event.altKey) {
3314
+ event.preventDefault(); setAiMode(true); setAiDraft(''); return
3315
+ }
3316
+ const map = {
3317
+ Enter: '\r', Backspace: '\x7f', Tab: '\t', Escape: '\x1b',
3318
+ ArrowUp: '\x1b[A', ArrowDown: '\x1b[B', ArrowRight: '\x1b[C', ArrowLeft: '\x1b[D',
3319
+ Home: '\x1b[H', End: '\x1b[F', Delete: '\x1b[3~', PageUp: '\x1b[5~', PageDown: '\x1b[6~',
3320
+ }
3321
+ let data
3322
+ if (map[event.key]) data = map[event.key]
3323
+ else if (event.ctrlKey && event.key.length === 1) data = String.fromCharCode(event.key.toUpperCase().charCodeAt(0) - 64)
3324
+ else if (!event.metaKey && !event.altKey && event.key.length === 1) data = event.key
3325
+ if (data === undefined) return
3326
+ event.preventDefault()
3327
+ void sendKey(data)
3328
+ }
3329
+
3281
3330
  const loadChannels = async () => {
3282
3331
  markLoading('channels', true)
3283
3332
  try { const data = await api('channels', {}, 20_000); setChannels(data.channels || []) } catch { setChannels([]) }
@@ -3754,6 +3803,10 @@ window.__ModuleLoader__.load({
3754
3803
  try { await api('config', { method: 'POST', body: JSON.stringify({ uiMode: next }) }, 15_000) } catch (e) { setError(String(e.message || e)) }
3755
3804
  }
3756
3805
 
3806
+ const quickCommands = (Array.isArray(config.quickCommands) && config.quickCommands.length > 0)
3807
+ ? config.quickCommands
3808
+ : ['df -h', 'free -h', 'uptime', 'systemctl --failed', 'docker ps', 'tail -n 30 /var/log/messages']
3809
+
3757
3810
  const subBody = detailHost
3758
3811
  ? ({ monitor: h(MonitorTab, { hosts, detailHost, detailTab, loadingMap, markLoading, setError }), config: h(ConfigTab, { busy, cHost, detailHost, histDiff, histList, histPath, hosts, inv, loadHistory, loadInv, monitorSuggestions, monitors, opBusy, restoreVersion, sectionList, services, setCHost, setHistPath, showDiff }), apps: h(AppsTab, { addSuggestions, busy, cHost, config, detailHost, doAction, fileState, hosts, inv, loadInv, monBusy, monitorSuggestions, openFile, output, saveFile, setCHost, setDetailTab, setFileState, setLogRequest }), logs: h(LogsTab, { host: cHost || hosts[0]?.name, notice, logRequest, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), setError, setNotice, timeoutFor, onInventoryRefresh: loadInv, config, logUsageData, loadLogUsage, openCleanPreview, cleanBusyHost, cleanRunBusy, backupBusy }), files: h(FilesTab, { host: cHost || hosts[0]?.name, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), setError, setNotice, confirmDialog }), terminal: h(TerminalTab, { host: cHost || hosts[0]?.name, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), term, setTerm, openTerm, closeTerm, busy, aiMode, aiDraft, quickCommands, termKey, sendKey, focusTerm, generateCommand, runGenerated, aiResult, aiIntent, setAiIntent, aiBusy, setAiMode, setAiDraft, askLog, error, output, consoleCmd, setConsoleCmd, consoleOut, consoleHistory, runConsole }), backups: h(BackupsTab, { host: dhost(), confirmDialog, trackJob, setError, refreshTick }), cron: h(CronTab, { host: dhost(), setError, loadingMap, markLoading, refreshTick }), deploy: h(DeployTab, { host: dhost(), trackJob, setError, loadingMap, refreshTick }) }[detailTab] || h(HostDetailTab, { ackAlert: ackAlert, ackMonitorUi: ackMonitorUi, addHost: addHost, addSuggestions: addSuggestions, adding: adding, aiBusy: aiBusy, aiDraft: aiDraft, aiIntent: aiIntent, aiMode: aiMode, aiModels: aiModels, aiResult: aiResult, alerts: alerts, applyTemplateUi: applyTemplateUi, askAi: askAi, askBusy: askBusy, askHost: askHost, askLog: askLog, askQuestion: askQuestion, audit: audit, backupBusy: backupBusy, backupSelected: backupSelected, busy: busy, cHost: cHost, certs: certs, chBusy: chBusy, channelForm: channelForm, channels: channels, chatNotice: chatNotice, cleanBackupFile: cleanBackupFile, cleanBusyHost: cleanBusyHost, cleanPreview: cleanPreview, cleanRunBusy: cleanRunBusy, cleanSel: cleanSel, cleanupHost: cleanupHost, closeTerm: closeTerm, config: config, confirmClean: confirmClean, confirmDialog: confirmDialog, conns: conns, consoleCmd: consoleCmd, consoleHistory: consoleHistory, consoleOut: consoleOut, copyDiagnostics: copyDiagnostics, copyReport: copyReport, copyText: copyText, countOf: countOf, createServiceUi: createServiceUi, detailHost: detailHost, detailTab: detailTab, dhost: dhost, diag: diag, diagnoseMonitorUi: diagnoseMonitorUi, diagnosticsText: diagnosticsText, doAction: doAction, downloadBackup: downloadBackup, editMonitor: editMonitor, editName: editName, error: error, fileState: fileState, focusTerm: focusTerm, form: form, generateCommand: generateCommand, health: health, histDiff: histDiff, histList: histList, histPath: histPath, hosts: hosts, info: info, installKeyOn: installKeyOn, inv: inv, loadBase: loadBase, loadCerts: loadCerts, loadChannels: loadChannels, loadHealth: loadHealth, loadHistory: loadHistory, loadInv: loadInv, loadLogUsage: loadLogUsage, loadMaintenance: loadMaintenance, loadMonitors: loadMonitors, loadServicesUi: loadServicesUi, loadTemplatesUi: loadTemplatesUi, loadingMap: loadingMap, logRequest: logRequest, logUsageData: logUsageData, maintenanceUntil: maintenanceUntil, markLoading: markLoading, metricBox: metricBox, monBusy: monBusy, monEditId: monEditId, monForm: monForm, monitorSuggestions: monitorSuggestions, monitors: monitors, notice: notice, opBusy: opBusy, opOut: opOut, openCleanPreview: openCleanPreview, openFile: openFile, openHost: openHost, openTerm: openTerm, output: output, overview: overview, p2Busy: p2Busy, quickText: quickText, recheckHost: recheckHost, recheckOne: recheckOne, refreshTick: refreshTick, removeChannelUi: removeChannelUi, removeHost: removeHost, removeMonitor: removeMonitor, removeServiceUi: removeServiceUi, removeTemplateUi: removeTemplateUi, renewCertsNow: renewCertsNow, restartWebFor: restartWebFor, restoreVersion: restoreVersion, runConsole: runConsole, runGenerated: runGenerated, runNeedsConfirm: runNeedsConfirm, saveAsTemplate: saveAsTemplate, saveChannel: saveChannel, saveConfig: saveConfig, saveFile: saveFile, saveMonitor: saveMonitor, sectionList: sectionList, selectedLogPaths: selectedLogPaths, sendKey: sendKey, services: services, setAdding: setAdding, setAiDraft: setAiDraft, setAiIntent: setAiIntent, setAiMode: setAiMode, setAiModels: setAiModels, setAlerts: setAlerts, setAskQuestion: setAskQuestion, setBackupBusy: setBackupBusy, setCHost: setCHost, setCerts: setCerts, setChBusy: setChBusy, setChannelForm: setChannelForm, setChannels: setChannels, setChatNotice: setChatNotice, setCleanBackupFile: setCleanBackupFile, setCleanBusyHost: setCleanBusyHost, setCleanPreview: setCleanPreview, setCleanRunBusy: setCleanRunBusy, setCleanSel: setCleanSel, setConfig: setConfig, setConsoleCmd: setConsoleCmd, setDetailHost: setDetailHost, setDetailTab: setDetailTab, setDiag: setDiag, setEditName: setEditName, setError: setError, setFileState: setFileState, setForm: setForm, setHealth: setHealth, setHistDiff: setHistDiff, setHistList: setHistList, setHistPath: setHistPath, setHostCtx: setHostCtx, setLogRequest: setLogRequest, setLogUsageData: setLogUsageData, setMaintenanceUi: setMaintenanceUi, setMaintenanceUntil: setMaintenanceUntil, setMonBusy: setMonBusy, setMonDialog: setMonDialog, setMonEditId: setMonEditId, setMonForm: setMonForm, setMonitors: setMonitors, setNotice: setNotice, setOpBusy: setOpBusy, setOpOut: setOpOut, setP2Busy: setP2Busy, setQuickText: setQuickText, setServices: setServices, setSimpleCtx: setSimpleCtx, setSimpleMonitors: setSimpleMonitors, setSimpleNotice: setSimpleNotice, setTab: setTab, setTemplateId: setTemplateId, setTemplates: setTemplates, setTerm: setTerm, setUiMode: setUiMode, showDiff: showDiff, simpleCtx: simpleCtx, simpleHostState: simpleHostState, simpleMonitors: simpleMonitors, simpleNotice: simpleNotice, startEdit: startEdit, statusOf: statusOf, suggestionFor: suggestionFor, switchMode: switchMode, tab: tab, templateId: templateId, templates: templates, term: term, testChannelUi: testChannelUi, testHost: testHost, testMonitor: testMonitor, timeoutFor: timeoutFor, trackJob: trackJob, uiMode: uiMode }))
3759
3812
  : null
@@ -3992,6 +4045,6 @@ window.__ModuleLoader__.load({
3992
4045
  ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL }, PanelRoot))
3993
4046
  }
3994
4047
 
3995
- return { isPlugin: true, inject: ['slots'], apply, __test: { PanelRoot, MonitorTab, BackupsTab, CronTab, DeployTab, FilesTab, LogsTab, AssistantTab, TerminalTab, SettingsTab, ConfigTab, AppsTab, OverviewTab, HostDetailTab, Chart } }
4048
+ return { isPlugin: true, inject: ['slots'], apply, __test: { PanelRoot, Panel, isBusinessService, MonitorTab, BackupsTab, CronTab, DeployTab, FilesTab, LogsTab, AssistantTab, TerminalTab, SettingsTab, ConfigTab, AppsTab, OverviewTab, HostDetailTab, Chart } }
3996
4049
  },
3997
4050
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ops-kit",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "OPC-运维工作台 (dsh-ops-kit) — Server operations kit for DeepSeek Harness: server cards, health charts, config browser, app manager and plain-language AI diagnosis — over SSH, no agent install.",
5
5
  "license": "MIT",
6
6
  "type": "module",