dsh-ops-kit 0.4.9 → 0.4.11

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 (3) hide show
  1. package/client.js +24 -9
  2. package/index.js +4 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -687,6 +687,15 @@ window.__ModuleLoader__.load({
687
687
  h('polyline', { points: d, fill: 'none', stroke: color, strokeWidth: 1.6 }))
688
688
  }
689
689
 
690
+ /** 简单模式里把「(退出码 2)」这类技术尾巴去掉。 */
691
+ const plainCheckDetail = (detail) => {
692
+ const text = String(detail || '')
693
+ .replace(/[((]\s*退出码\s*\d+\s*[))]/g, '')
694
+ .replace(/[((]\s*exit(?:\s+code)?\s*\d+\s*[))]/gi, '')
695
+ .trim()
696
+ return text || L('检查不通过', 'Check failed')
697
+ }
698
+
690
699
  const sizeText = (bytes, dir) => {
691
700
  if (dir) return '—'
692
701
  const n = Number(bytes) || 0
@@ -2078,15 +2087,15 @@ window.__ModuleLoader__.load({
2078
2087
  }
2079
2088
 
2080
2089
  /** 设置:主机、通道、模型、巡检配置;状态仍由 Panel 持有,视图独立。 */
2081
- function SettingsTab({ adding, aiModels, audit, busy, chBusy, channelForm, channels, config, editName, form, health, hosts, info, loadingMap, notice, tab, uiMode, addHost, installKeyOn, removeChannelUi, removeHost, saveChannel, saveConfig, startEdit, testChannelUi, testHost, setAdding, setAiModels, setChannelForm, setConfig, setEditName, setForm, quickText, setQuickText, setUiMode }) {
2090
+ function SettingsTab({ adding, aiModels, audit, busy, chBusy, channelForm, channels, config, editName, form, health, hosts, info, loadingMap, notice, tab, uiMode, addHost, installKeyOn, removeChannelUi, removeHost, saveChannel, saveConfig, startEdit, testChannelUi, testHost, setAdding, setAiModels, setChannelForm, setConfig, setEditName, setForm, quickText, setQuickText, switchMode }) {
2082
2091
  const settingsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
2083
2092
  h('div', { className: 'ops-card' },
2084
2093
  h('div', { className: 'ops-card-h' }, h('span', null, T.uiMode),
2085
2094
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.save)),
2086
2095
  h('div', { className: 'ops-card-b' },
2087
2096
  h('div', { className: 'ops-chips' },
2088
- h('button', { className: `ops-tab${uiMode === 'simple' ? ' on' : ''}`, onClick: () => setUiMode('simple') }, T.modeSimple),
2089
- h('button', { className: `ops-tab${uiMode === 'pro' ? ' on' : ''}`, onClick: () => setUiMode('pro') }, T.modePro)),
2097
+ h('button', { className: `ops-tab${uiMode === 'simple' ? ' on' : ''}`, onClick: () => { void switchMode('simple') } }, T.modeSimple),
2098
+ h('button', { className: `ops-tab${uiMode === 'pro' ? ' on' : ''}`, onClick: () => { void switchMode('pro') } }, T.modePro)),
2090
2099
  h('p', { className: 'ops-sub', style: { margin: 0 } }, T.modeHint))),
2091
2100
  h('div', { className: 'ops-card' },
2092
2101
  h('div', { className: 'ops-card-h' }, h('span', null, T.patrol), notice ? h('span', { className: 'ops-ok' }, notice) : null),
@@ -2501,7 +2510,7 @@ window.__ModuleLoader__.load({
2501
2510
  ? h('div', { style: { marginTop: '6px' } }, ...state.failing.slice(0, 3).map(item => {
2502
2511
  const tip = suggestionFor(item)
2503
2512
  return h('div', { key: item.id, style: { fontSize: '12.5px', color: '#ff8a8a', lineHeight: 1.9 } },
2504
- `· ${item.label || item.target}:${item.last?.detail || L('异常', 'error')}`,
2513
+ `· ${item.label || item.target}:${plainCheckDetail(item.last?.detail)}`,
2505
2514
  h('div', { style: { color: 'var(--dsw-alias-text-secondary,#9aa0a6)', paddingLeft: '10px' } },
2506
2515
  `${T.suggestion}:${tip.text}`,
2507
2516
  tip.action === 'restart'
@@ -2539,7 +2548,7 @@ window.__ModuleLoader__.load({
2539
2548
  : h('div', null, ...alerts.map((alert, index) => h('div', { key: index, className: 'ops-row', style: { gridTemplateColumns: '1fr auto' } },
2540
2549
  h('span', { style: { display: 'flex', alignItems: 'center', gap: '8px', opacity: alert.acked ? 0.5 : 1 } },
2541
2550
  h('i', { className: 'ops-dot ' + (alert.level === 'critical' ? 'bad' : alert.level === 'warning' ? 'warn' : '') }),
2542
- h('span', null, alert.message),
2551
+ h('span', null, plainCheckDetail(alert.message)),
2543
2552
  h('span', { className: 'ops-dim', style: { fontSize: '11px' } }, fmt(alert.at))),
2544
2553
  alert.acked
2545
2554
  ? h('span', { className: 'ops-chip' }, T.acked)
@@ -2797,7 +2806,7 @@ window.__ModuleLoader__.load({
2797
2806
  return hostDetailView
2798
2807
  }
2799
2808
 
2800
- function Panel({ initialHosts = [], initialDetailHost = null, initialDetailTab = 'summary' } = {}) {
2809
+ function Panel({ initialHosts = [], initialDetailHost = null, initialDetailTab = 'summary', initialUiMode = 'pro' } = {}) {
2801
2810
  const [tab, setTab] = React.useState(0)
2802
2811
  const [detailHost, setDetailHost] = React.useState(initialDetailHost)
2803
2812
  const [detailTab, setDetailTab] = React.useState(initialDetailTab)
@@ -2840,7 +2849,7 @@ window.__ModuleLoader__.load({
2840
2849
  const [monDialog, setMonDialog] = React.useState(null)
2841
2850
  const [templates, setTemplates] = React.useState([])
2842
2851
  const [services, setServices] = React.useState([])
2843
- const [uiMode, setUiMode] = React.useState('pro')
2852
+ const [uiMode, setUiMode] = React.useState(initialUiMode)
2844
2853
  const [alerts, setAlerts] = React.useState([])
2845
2854
  const [audit, setAudit] = React.useState([])
2846
2855
  const [info, setInfo] = React.useState(null)
@@ -3845,9 +3854,15 @@ window.__ModuleLoader__.load({
3845
3854
  }
3846
3855
 
3847
3856
  const switchMode = async (next) => {
3857
+ const previous = uiMode
3848
3858
  setUiMode(next)
3849
3859
  if (next === 'simple') { setDetailHost(null); setTab(0) }
3850
- try { await api('config', { method: 'POST', body: JSON.stringify({ uiMode: next }) }, 15_000) } catch (e) { setError(String(e.message || e)) }
3860
+ try {
3861
+ await api('config', { method: 'POST', body: JSON.stringify({ uiMode: next }) }, 15_000)
3862
+ } catch (e) {
3863
+ setUiMode(previous)
3864
+ setError(String(e.message || e))
3865
+ }
3851
3866
  }
3852
3867
 
3853
3868
  const quickCommands = (Array.isArray(config.quickCommands) && config.quickCommands.length > 0)
@@ -3860,7 +3875,7 @@ window.__ModuleLoader__.load({
3860
3875
 
3861
3876
  const topTabs = [[0, T.tabs[0]], [1, T.tabs[8]], [2, T.tabs[9]]]
3862
3877
 
3863
- const body = detailHost ? subBody : [h(OverviewTab, { ackAlert, alerts, askAi, backupBusy, busy, cleanBusyHost, cleanRunBusy, cleanupHost, config, confirmDialog, conns, copyDiagnostics, copyReport, countOf, diag, diagnosticsText, doAction, error, hosts, info, loadBase, metricBox, monitors, openCleanPreview, openHost, overview, recheckHost, recheckOne, restartWebFor, sectionList, setAdding, setAlerts, setCHost, setChatNotice, setDetailHost, setDiag, setError, setHostCtx, setNotice, setSimpleCtx, setSimpleMonitors, setSimpleNotice, setTab, setUiMode, simpleCtx, simpleHostState, simpleMonitors, simpleNotice, statusOf, suggestionFor, switchMode, timeoutFor, uiMode }), h(AssistantTab, { picker: hostPicker(hosts, cHost, setCHost), askLog, askQuestion, setAskQuestion, askBusy, askHost, chatNotice, copyText, runNeedsConfirm, copyDiagnostics }), h(SettingsTab, { adding, aiModels, audit, busy, chBusy, channelForm, channels, config, editName, form, health, hosts, info, loadingMap, notice, tab, uiMode, addHost, installKeyOn, removeChannelUi, removeHost, saveChannel, saveConfig, startEdit, testChannelUi, testHost, setAdding, setAiModels, setChannelForm, setConfig, setEditName, setForm, quickText, setQuickText, setUiMode })][tab]
3878
+ const body = detailHost ? subBody : [h(OverviewTab, { ackAlert, alerts, askAi, backupBusy, busy, cleanBusyHost, cleanRunBusy, cleanupHost, config, confirmDialog, conns, copyDiagnostics, copyReport, countOf, diag, diagnosticsText, doAction, error, hosts, info, loadBase, metricBox, monitors, openCleanPreview, openHost, overview, recheckHost, recheckOne, restartWebFor, sectionList, setAdding, setAlerts, setCHost, setChatNotice, setDetailHost, setDiag, setError, setHostCtx, setNotice, setSimpleCtx, setSimpleMonitors, setSimpleNotice, setTab, setUiMode, simpleCtx, simpleHostState, simpleMonitors, simpleNotice, statusOf, suggestionFor, switchMode, timeoutFor, uiMode }), h(AssistantTab, { picker: hostPicker(hosts, cHost, setCHost), askLog, askQuestion, setAskQuestion, askBusy, askHost, chatNotice, copyText, runNeedsConfirm, copyDiagnostics }), h(SettingsTab, { adding, aiModels, audit, busy, chBusy, channelForm, channels, config, editName, form, health, hosts, info, loadingMap, notice, tab, uiMode, addHost, installKeyOn, removeChannelUi, removeHost, saveChannel, saveConfig, startEdit, testChannelUi, testHost, setAdding, setAiModels, setChannelForm, setConfig, setEditName, setForm, quickText, setQuickText, switchMode })][tab]
3864
3879
 
3865
3880
  const header = h('div', { className: 'ops-top' },
3866
3881
  h('div', null,
package/index.js CHANGED
@@ -1514,7 +1514,9 @@ async function saveConfig(patch) {
1514
1514
  async function loadState() {
1515
1515
  try {
1516
1516
  const data = JSON.parse(await readFile(stateFile(), 'utf8'))
1517
- return { hosts: data.hosts ?? {}, lastRunAt: data.lastRunAt ?? 0 }
1517
+ // 保留全部字段:monitorAlertAt / monitorSuppressed / monitorLastRun /
1518
+ // lastMetricsAt 等都要能读回,否则告警冷却和抑制会失效。
1519
+ return { ...data, hosts: data.hosts ?? {}, lastRunAt: data.lastRunAt ?? 0 }
1518
1520
  } catch (error) {
1519
1521
  softFail('loadState', error)
1520
1522
  return { hosts: {}, lastRunAt: 0 }
@@ -5260,6 +5262,7 @@ export function apply(ctx) {
5260
5262
  /** Internals for the test suite; not part of the plugin API. */
5261
5263
  export const __test = {
5262
5264
  q,
5265
+ loadState,
5263
5266
  friendlyUnit,
5264
5267
  appKey,
5265
5268
  clip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ops-kit",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
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",