dsh-session-superagent 0.9.286 → 0.10.1

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/client.js CHANGED
@@ -418,7 +418,7 @@ window.__ModuleLoader__.load({
418
418
  }
419
419
 
420
420
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
421
- const CLIENT_VERSION = '0.9.286'
421
+ const CLIENT_VERSION = '0.10.1'
422
422
  // SEMVER_COMPARATOR_SOURCE_START
423
423
  // This block is duplicated verbatim in client.js because the browser UMD cannot import ESM.
424
424
  // test/update-semver.test.mjs audits both copies and exercises their behavior.
@@ -515,8 +515,19 @@ window.__ModuleLoader__.load({
515
515
 
516
516
  const POLL_MS = 5000
517
517
 
518
- // 上一次 /state 的 ETag:带上它,没变化时服务端回 304,省掉整份 JSON
519
- let stateEtag = null
518
+ // 上一次 /state 的 ETag:带上它,没变化时服务端回 304,省掉整份 JSON。
519
+ // 必须按作用域分开存(终审 N3):状态栏圆环拉的是全局 /state,主面板拉的是 /state?sessionId=…;
520
+ // 服务端 etag 对整份 body 求值,两个作用域 body 不同 —— 共用一个 etag 会让面板的条件请求永远打不中 304。
521
+ // 不带 sessionId 时仍然只有一个键,与旧行为一致。
522
+ const stateEtags = new Map()
523
+ const readStateEtag = (path) => (typeof path === 'string' && path.startsWith('/state')
524
+ ? (stateEtags.get(path) || null)
525
+ : null)
526
+ const writeStateEtag = (path, etag) => {
527
+ if (typeof path !== 'string' || !path.startsWith('/state')) return
528
+ if (etag) stateEtags.set(path, etag)
529
+ else stateEtags.delete(path)
530
+ }
520
531
 
521
532
  async function call(path, options, retried) {
522
533
  const init = {
@@ -551,11 +562,11 @@ window.__ModuleLoader__.load({
551
562
  // 304:内容没变(服务端带 ETag)。不是错误,也没有正文。
552
563
  if (res.status === 304) {
553
564
  const etag = res.headers && res.headers.get ? res.headers.get('etag') : null
554
- if (etag) stateEtag = etag
565
+ if (etag) writeStateEtag(path, etag)
555
566
  return { notModified: true }
556
567
  }
557
568
  const freshEtag = res.headers && res.headers.get ? res.headers.get('etag') : null
558
- if (freshEtag && path.startsWith('/state')) stateEtag = freshEtag
569
+ if (freshEtag && path.startsWith('/state')) writeStateEtag(path, freshEtag)
559
570
  const text = await res.text()
560
571
  let body = null
561
572
  try { body = text ? JSON.parse(text) : null } catch { body = { raw: text } }
@@ -851,7 +862,7 @@ window.__ModuleLoader__.load({
851
862
  function Section({ title, count, subtitle, hint, action, children }) {
852
863
  return h('section', { className: 'dt-section' },
853
864
  title
854
- ? h('div', { className: 'dt-section-title' },
865
+ ? h('h2', { className: 'dt-section-title' },
855
866
  h('span', { className: 'dt-section-name' }, title),
856
867
  count !== undefined && count !== null ? h('span', { className: 'dt-count' }, String(count)) : null,
857
868
  subtitle ? h('span', { className: 'dt-section-sub' }, subtitle) : null,
@@ -890,25 +901,30 @@ window.__ModuleLoader__.load({
890
901
  /** 官方 DisclosureRow 承载过滤清单;缺导出时完整保留本地键盘与焦点行为。 */
891
902
  function CollapsibleList({ title, items }) {
892
903
  const [open, setOpen] = useState(false)
904
+ // 字符串仍是兼容调用面;结构化记录带独立摘要、正文和稳定 key,避免先压平而丢失来源。
905
+ const summaryOf = (item) => item && typeof item === 'object' && 'summary' in item ? item.summary : item
906
+ const contentOf = (item) => item && typeof item === 'object' && 'content' in item ? item.content : item
893
907
  const rowProps = {
894
908
  title: title + '(' + items.length + ')',
895
909
  open, onToggle: () => setOpen((current) => !current),
896
910
  icon: h(Icon, { name: 'question', size: 14 }),
897
- collapsedContent: h('span', { className: 'dt-hint' }, items[0] ? String(items[0]).slice(0, 40) : ''),
911
+ collapsedContent: h('span', { className: 'dt-hint' }, items[0] ? String(summaryOf(items[0])).slice(0, 40) : ''),
898
912
  }
899
913
  return h(hostCollapsibleRow || DisclosureRow,
900
914
  hostCollapsibleRow ? { ...rowProps, expandable: true, expandOnRowClick: true } : rowProps,
901
915
  h('ul', { className: 'dt-plain-list' },
902
- items.map((text, index) => h('li', { key: index }, text))))
916
+ items.map((item, index) => h('li', {
917
+ key: item && typeof item === 'object' && item.key !== undefined ? item.key : index,
918
+ }, contentOf(item)))))
903
919
  }
904
920
 
905
- /** DSH Pill:有 onClick 时是可切换按钮,否则是静态只读胶囊。 */
906
- function Pill({ active = false, className, onClick, children, ...rest }) {
921
+ /** DSH Pill:active 有定义时才是 toggle;无 active 的 onClick 只是动作,静态则无 onClick。 */
922
+ function Pill({ active, className, onClick, children, ...rest }) {
907
923
  if (hostPill) {
908
- // 官方没有 aria-pressed;只在交互形态最小补齐,不把只读 badge 变成按钮。
924
+ // 官方没有 aria-pressed;只给真正的 toggle 补齐,清除等普通动作不得误报 pressed=false。
909
925
  return h(hostPill, {
910
926
  ...rest, active, className, onClick,
911
- 'aria-pressed': onClick ? !!active : undefined,
927
+ 'aria-pressed': onClick && active !== undefined ? !!active : undefined,
912
928
  }, children)
913
929
  }
914
930
  if (!onClick) {
@@ -916,7 +932,7 @@ window.__ModuleLoader__.load({
916
932
  }
917
933
  return h('button', {
918
934
  type: 'button', ...rest, className: cx('dt-pill', active && 'dt-pill-active', className),
919
- 'aria-pressed': !!active, onClick,
935
+ 'aria-pressed': active !== undefined ? !!active : undefined, onClick,
920
936
  }, children)
921
937
  }
922
938
 
@@ -932,15 +948,23 @@ window.__ModuleLoader__.load({
932
948
  }
933
949
 
934
950
  /** 官方 DisclosureRow:折叠行的标准写法(Enter / 空格可切换,带 aria-expanded)。 */
935
- function DisclosureRow({ icon, title, open, onToggle, collapsedContent, bodyId, children }) {
951
+ function DisclosureRow({ icon, title, open, onToggle, collapsedContent, bodyId, busy = false, disabled = false, children }) {
936
952
  const content = Array.isArray(children) && children.length === 1 ? children[0] : children
953
+ const unavailable = Boolean(busy || disabled)
937
954
  return h('div', { className: 'dt-disclosure', 'data-open': open ? 'true' : undefined },
938
955
  h('div', {
939
- className: 'dt-disclosure-row', role: 'button', tabIndex: 0, 'aria-expanded': !!open,
956
+ className: 'dt-disclosure-row', role: 'button', tabIndex: unavailable ? -1 : 0, 'aria-expanded': !!open,
940
957
  'aria-controls': bodyId,
941
- onClick: onToggle,
958
+ 'aria-disabled': unavailable,
959
+ 'aria-busy': busy ? 'true' : undefined,
960
+ 'aria-label': busy && typeof title === 'string' ? title + '(保存中,暂不可开合)' : undefined,
961
+ onClick: () => { if (!unavailable) onToggle() },
942
962
  onKeyDown: (event) => {
943
- if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onToggle() }
963
+ if (event.key !== 'Enter' && event.key !== ' ') return
964
+ event.preventDefault()
965
+ // 长按只认第一次;busy/disabled 也必须在本层拦截,不能依赖调用方静默吞掉。
966
+ if (unavailable || event.repeat) return
967
+ onToggle()
944
968
  },
945
969
  },
946
970
  h('span', { className: 'dt-disclosure-lead' },
@@ -957,16 +981,36 @@ window.__ModuleLoader__.load({
957
981
  : null)
958
982
  }
959
983
 
960
- /** 无 DSH Tooltip 时完整保留原实现:原 trigger、点击/失焦与本地气泡都不改写。 */
984
+ // 本地气泡的 id 序号:同一 trigger 反复开合复用同一个 id,trigger 才能稳定用 aria-describedby 指向它。
985
+ // 用 ref 而不是新增 state,避免打乱父组件按位置取值的 hook 队列。
986
+ let fallbackTipSerial = 0
987
+ /** 无 DSH Tooltip 时完整保留原实现;补上 Escape 关闭与 trigger↔tooltip 关联(W15)。 */
961
988
  function FallbackInfoTip({ text, icon = 'question', warn }) {
962
989
  const [open, setOpen] = useState(false)
990
+ const tipIdRef = useRef(null)
991
+ if (!tipIdRef.current) {
992
+ fallbackTipSerial += 1
993
+ tipIdRef.current = 'dt-info-tip-' + fallbackTipSerial
994
+ }
995
+ const tipId = tipIdRef.current
963
996
  return h('span', { style: { position: 'relative', display: 'inline-flex' } },
964
997
  h('button', {
965
998
  type: 'button', className: cx('dt-info', warn && 'dt-info-warn'),
966
999
  'aria-label': text, 'aria-expanded': open,
1000
+ // 只有气泡真的在 DOM 里才关联;关闭时同步清掉,读屏不会指向已消失的节点。
1001
+ 'aria-describedby': open ? tipId : undefined,
967
1002
  onClick: () => setOpen(!open), onBlur: () => setOpen(false),
1003
+ onKeyDown: (event) => {
1004
+ if (event.key !== 'Escape' || !open) return
1005
+ // 键盘约定:Escape 只关气泡,焦点留在 trigger 上(不能 blur 掉)。
1006
+ event.preventDefault()
1007
+ setOpen(false)
1008
+ },
968
1009
  }, h(Icon, { name: icon, size: 14 })),
969
- open ? h('span', { className: 'dt-tooltip', role: 'tooltip', style: { position: 'absolute', bottom: '130%', left: 0, visibility: 'visible' } }, text) : null)
1010
+ open ? h('span', {
1011
+ id: tipId, className: 'dt-tooltip', role: 'tooltip',
1012
+ style: { position: 'absolute', bottom: '130%', left: 0, visibility: 'visible' },
1013
+ }, text) : null)
970
1014
  }
971
1015
 
972
1016
  // 保持 InfoTip({text,icon,warn}) 调用面;静态分支不会在组件生命周期内改变 hooks 顺序。
@@ -994,7 +1038,14 @@ window.__ModuleLoader__.load({
994
1038
  const parsed = Number(value)
995
1039
  return Number.isFinite(parsed) ? parsed : undefined
996
1040
  }
997
- const watcherValuesFrom = (watcher) => ({
1041
+ // ack 默认值来自 /state.defaultAckLabels(issue #11);老服务端没有这个字段时仍回落旧字面量。
1042
+ const ACK_LABEL_FALLBACK = { github: '主理鱼:已处理', gitee: '主理鱼-已处理' }
1043
+ const ackLabelFallback = (watcher, defaults) => {
1044
+ const provider = watcher && watcher.provider === 'gitee' ? 'gitee' : 'github'
1045
+ const fromState = defaults && typeof defaults[provider] === 'string' ? defaults[provider].trim() : ''
1046
+ return fromState || ACK_LABEL_FALLBACK[provider]
1047
+ }
1048
+ const watcherValuesFrom = (watcher, ackDefaults) => ({
998
1049
  repo: watcher.repo || '',
999
1050
  intervalSec: watcherNumberText(watcher.intervalSec ?? 60),
1000
1051
  labels: (watcher.filters && Array.isArray(watcher.filters.labels) ? watcher.filters.labels : []).join(','),
@@ -1002,7 +1053,7 @@ window.__ModuleLoader__.load({
1002
1053
  assignee: (watcher.filters && watcher.filters.assignee) || '',
1003
1054
  activeHours: watcher.activeHours || '',
1004
1055
  goal: watcher.note || (typeof watcher.goal === 'string' ? watcher.goal : (watcher.goal && watcher.goal.objective) || ''),
1005
- ackLabel: watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'),
1056
+ ackLabel: watcher.ackLabel || ackLabelFallback(watcher, ackDefaults),
1006
1057
  onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
1007
1058
  allowAuthors: (watcher.filters && Array.isArray(watcher.filters.allowAuthors) ? watcher.filters.allowAuthors : []).join(', '),
1008
1059
  observe: !!watcher.observe,
@@ -1082,6 +1133,31 @@ window.__ModuleLoader__.load({
1082
1133
  h(Btn, { size: 'sm', variant: 'primary', type: 'submit', disabled: !dirty || !!busy || !!disabled, onClick: onSave }, busy ? '保存中…' : saveLabel))
1083
1134
  }
1084
1135
 
1136
+ /**
1137
+ * SaveBar 消失后只在焦点仍属于这张表单时归还;用户已移到其它存活控件就不抢。
1138
+ * 编辑保存会卸载整个 form,所以 opener 在提交前捕获;新增/放弃则回首个可编辑控件。
1139
+ */
1140
+ function restoreSaveBarFocus({ form, saveBar, opener, wasFocused = false, shouldRestore }) {
1141
+ if (typeof document === 'undefined') return
1142
+ const active = document.activeElement
1143
+ const inSaveBar = (node) => Boolean(node && saveBar && typeof saveBar.contains === 'function' && saveBar.contains(node))
1144
+ const lost = (node) => !node || node === document.body || node.isConnected === false
1145
+ if (!inSaveBar(active) && !wasFocused) return
1146
+ setTimeout(() => {
1147
+ const current = document.activeElement
1148
+ if (!inSaveBar(current) && !lost(current)) return
1149
+ if (typeof shouldRestore === 'function' && !shouldRestore()) return
1150
+ // busy=true 时 input 仍 disabled;必须等 finally 与 React commit 后再找可编辑控件。
1151
+ const target = opener && opener.isConnected !== false
1152
+ ? opener
1153
+ : form && form.isConnected !== false && typeof form.querySelector === 'function'
1154
+ ? form.querySelector('input:not(:disabled), textarea:not(:disabled), select:not(:disabled)')
1155
+ : null
1156
+ if (!target || target.isConnected === false || typeof target.focus !== 'function') return
1157
+ try { target.focus({ preventScroll: true }) } catch { try { target.focus() } catch {} }
1158
+ }, 0)
1159
+ }
1160
+
1085
1161
  /** derived HoursField:两个原生时间控件,Field 的 label 只关联起始控件。 */
1086
1162
  function HoursField({ value, onChange, id, disabled }) {
1087
1163
  const match = String(value || '').match(/^(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})$/)
@@ -1139,10 +1215,24 @@ window.__ModuleLoader__.load({
1139
1215
  const [busy, setBusy] = useState(false)
1140
1216
  const [error, setError] = useState(null)
1141
1217
  const busyRef = useRef(false)
1218
+ const formRef = useRef(null)
1219
+ const formFocusedRef = useRef(false)
1142
1220
  const values = value || {}
1143
1221
  const opening = snapshot || values
1144
1222
  const dirty = watcherDirty(values, opening)
1145
1223
  const change = (key, next) => { setError(null); onChange(key, next) }
1224
+ const captureFocus = () => {
1225
+ const form = formRef.current
1226
+ const active = typeof document === 'undefined' ? null : document.activeElement
1227
+ const ticket = mode === 'edit' && form && typeof form.closest === 'function' ? form.closest('.dt-ticket') : null
1228
+ return {
1229
+ form,
1230
+ saveBar: form && typeof form.querySelector === 'function' ? form.querySelector('.dt-savebar') : null,
1231
+ opener: ticket && typeof ticket.querySelector === 'function' ? ticket.querySelector('.dt-open') : null,
1232
+ wasFocused: formFocusedRef.current || Boolean(form && active && typeof form.contains === 'function' && form.contains(active)),
1233
+ shouldRestore: () => formFocusedRef.current,
1234
+ }
1235
+ }
1146
1236
  const submit = async (event) => {
1147
1237
  if (event && typeof event.preventDefault === 'function') event.preventDefault()
1148
1238
  // 原生点击保存时仍执行 constraints;测试桩没有 form,直接走同一提交函数。
@@ -1155,12 +1245,14 @@ window.__ModuleLoader__.load({
1155
1245
  }
1156
1246
  if (busyRef.current || disabled || (mode === 'edit' && !dirty)) return false
1157
1247
  if (mode === 'create' && (!sessionId || !String(values.repo || '').trim())) return false
1248
+ const focus = captureFocus()
1158
1249
  busyRef.current = true
1159
1250
  setBusy(true)
1160
1251
  setError(null)
1161
1252
  try {
1162
1253
  const result = await onSave(values)
1163
1254
  if (result === false) throw new Error('保存失败,请重试')
1255
+ restoreSaveBarFocus(focus)
1164
1256
  return result
1165
1257
  } catch (failure) {
1166
1258
  setError(String((failure && failure.message) || failure || '保存失败,请重试'))
@@ -1172,8 +1264,10 @@ window.__ModuleLoader__.load({
1172
1264
  }
1173
1265
  const discard = () => {
1174
1266
  if (busyRef.current) return
1267
+ const focus = captureFocus()
1175
1268
  setError(null)
1176
1269
  onDiscard(opening)
1270
+ restoreSaveBarFocus({ ...focus, opener: null })
1177
1271
  }
1178
1272
  const renderField = (spec) => {
1179
1273
  if (spec.modes && !spec.modes.includes(mode)) return null
@@ -1215,12 +1309,21 @@ window.__ModuleLoader__.load({
1215
1309
  return h('span', { key: spec.key, className: 'dt-hint', placeholder }, spec.label + ' ' + placeholder)
1216
1310
  }))
1217
1311
  const submitFromClick = (event) => submit(event)
1218
- return h('form', { id: idPrefix, className: 'dt-form dt-card', 'data-mode': mode, onSubmit: submit },
1312
+ return h('form', {
1313
+ id: idPrefix, ref: formRef, className: 'dt-form dt-card', 'data-mode': mode, onSubmit: submit,
1314
+ onFocusCapture: () => { formFocusedRef.current = true },
1315
+ onBlurCapture: (event) => {
1316
+ const next = event.relatedTarget
1317
+ // disabled 让当前控件失焦时 relatedTarget 可能为空;保存 pending 不应因此丢掉回焦资格。
1318
+ if ((!next || !event.currentTarget.contains(next)) && !(busyRef.current && !next)) formFocusedRef.current = false
1319
+ },
1320
+ },
1219
1321
  h(Fields, { disabled: busy || disabled },
1220
1322
  basic,
1221
1323
  h(DisclosureRow, {
1222
1324
  icon: h(Icon, { name: 'settings' }), title: '高级设置', open: advancedOpen,
1223
- onToggle: () => { if (!busy && !disabled) setAdvancedOpen(!advancedOpen) },
1325
+ busy, disabled,
1326
+ onToggle: () => { if (!busyRef.current && !busy && !disabled) setAdvancedOpen((current) => !current) },
1224
1327
  collapsedContent: collapsedAdvanced, bodyId: idPrefix + '-advanced-body',
1225
1328
  }, h('div', { className: 'dt-disclosure-body' }, advanced))),
1226
1329
  h(SaveBar, { dirty, busy, error, disabled, onDiscard: discard, onSave: submitFromClick, saveLabel: submitLabel }),
@@ -1243,6 +1346,9 @@ window.__ModuleLoader__.load({
1243
1346
 
1244
1347
  // 官方 Modal 的键盘行为:Escape 关闭 + Tab 焦点陷阱 + 关闭后焦点回到触发元素。
1245
1348
  // 移植时只搬了样式,行为是后补的(2026-11-02 对官方 controls.tsx 逐行比对时发现)。
1349
+ // 本地 Modal 打开层数:Modal 存在时 Escape 属于最上层对话框,底层 Orbit 的 capture 必须让位(W16)。
1350
+ // 用模块级计数而不是给 StatusOrbit 加 hook,保持它按位置取值的 hook 契约不变。
1351
+ let localDialogDepth = 0
1246
1352
  const FOCUSABLE = 'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])'
1247
1353
  function trapTab(event, dialog) {
1248
1354
  const items = [...dialog.querySelectorAll('*')].filter((element) => element.matches(FOCUSABLE))
@@ -1264,6 +1370,7 @@ window.__ModuleLoader__.load({
1264
1370
  close.current = onClose
1265
1371
  useEffect(() => {
1266
1372
  if (!open || typeof document === 'undefined') return undefined
1373
+ localDialogDepth += 1
1267
1374
  restoreTo.current = document.activeElement
1268
1375
  // 打开后把焦点挪进对话框,否则键盘用户还停在背后的页面上
1269
1376
  const timer = setTimeout(() => {
@@ -1273,11 +1380,16 @@ window.__ModuleLoader__.load({
1273
1380
  ;(first || node).focus()
1274
1381
  }, 0)
1275
1382
  const onKey = (event) => {
1276
- if (event.key === 'Escape') { event.preventDefault(); close.current(); return }
1383
+ if (event.key === 'Escape') {
1384
+ // 已被更上层控件(如 fallback Tooltip)消费的 Escape 不再关 Modal。
1385
+ if (event.defaultPrevented) return
1386
+ event.preventDefault(); close.current(); return
1387
+ }
1277
1388
  if (event.key === 'Tab' && dialog.current) trapTab(event, dialog.current)
1278
1389
  }
1279
1390
  document.addEventListener('keydown', onKey)
1280
1391
  return () => {
1392
+ localDialogDepth = Math.max(0, localDialogDepth - 1)
1281
1393
  clearTimeout(timer)
1282
1394
  document.removeEventListener('keydown', onKey)
1283
1395
  const back = restoreTo.current
@@ -1355,7 +1467,7 @@ window.__ModuleLoader__.load({
1355
1467
  }
1356
1468
 
1357
1469
  /** 官方 ConfirmButton 动线:触发按钮只开 Modal,取消不执行,确认期间 busy 防重复。 */
1358
- function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel', ButtonComponent = Btn, danger = true, preventDismissOnBusy = false, error = null, busyLabel = confirmLabel, busyHint }) {
1470
+ function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel', ButtonComponent = Btn, danger = true, preventDismissOnBusy = false, error = null, busyLabel = confirmLabel, busyHint, onOpen }) {
1359
1471
  const [open, setOpen] = useState(false)
1360
1472
  const close = useCallback(() => setOpen(false), [])
1361
1473
  return h(React.Fragment, null,
@@ -1365,7 +1477,11 @@ window.__ModuleLoader__.load({
1365
1477
  icon,
1366
1478
  'aria-label': label,
1367
1479
  'aria-haspopup': 'dialog',
1368
- onClick: () => setOpen(true),
1480
+ onClick: () => {
1481
+ // 打开前先跑调用方的清理(例如清掉上一次「删除失败」);打开行为本身不变。
1482
+ if (typeof onOpen === 'function') onOpen()
1483
+ setOpen(true)
1484
+ },
1369
1485
  }, label),
1370
1486
  h(ConfirmDialog, { open, label, confirmLabel, title, message, onConfirm, onClose: close, modalContext, ButtonComponent, danger, preventDismissOnBusy, error, busyLabel, busyHint }))
1371
1487
  }
@@ -1575,6 +1691,9 @@ window.__ModuleLoader__.load({
1575
1691
  const [orbitError, setOrbitError] = useState(null)
1576
1692
  const [open, setOpen] = useState(false)
1577
1693
  const [anchor, setAnchor] = useState(null)
1694
+ // 品牌名(issue #11):/state 下发;老服务端没有这个字段时仍是「主理鱼」。
1695
+ // 只能在末尾追加状态槽,前面的位置契约(观测/删除确认)保持不变。
1696
+ const [brandName, setBrandName] = useState('主理鱼')
1578
1697
  const btnRef = useRef(null)
1579
1698
  const panelRef = useRef(null)
1580
1699
  const actionLocks = useRef(new Set())
@@ -1584,7 +1703,8 @@ window.__ModuleLoader__.load({
1584
1703
  orbitRef: btnRef,
1585
1704
  onCloseOrbit: () => setOpen(false),
1586
1705
  // DSH 路径复用旧 anchor 槽保存待删 watcher;fallback 仍只保存手算坐标,状态槽位不变。
1587
- onRequestConfirm: ({ watcher }) => setAnchor(watcher),
1706
+ // 打开时先清掉上一次的「删除失败:…」,否则新确认框一打开就带着别人的错误。
1707
+ onRequestConfirm: ({ watcher }) => openDeleteConfirm(watcher),
1588
1708
  })
1589
1709
 
1590
1710
  const isReadError = (value) => typeof value === 'string'
@@ -1596,6 +1716,7 @@ window.__ModuleLoader__.load({
1596
1716
  const body = await call('/state')
1597
1717
  if (!orbitAlive.current || sequence !== stateSequence.current) return { applied: false, ok: true }
1598
1718
  setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
1719
+ setBrandName((typeof (body && body.brandName) === 'string' && body.brandName.trim()) || '主理鱼')
1599
1720
  setOrbitError((current) => isReadError(current) ? null : current)
1600
1721
  return { applied: true, ok: true }
1601
1722
  } catch (error) {
@@ -1623,16 +1744,33 @@ window.__ModuleLoader__.load({
1623
1744
  // 而弹层是"一开就要好看"的东西,不能等到下次渲染才发现没样式
1624
1745
  useEffect(() => { if (open) ensurePortedCss(true) }, [open])
1625
1746
 
1747
+ // 终审 N2:删除失败只属于「那一次确认框」。打开新的删除确认时必须先清掉它,
1748
+ // 否则 A 的失败会跟着 B 的确认框一起出现(B 还没发任何请求)。读取错误属于列表状态,不能一起清。
1749
+ const clearDeleteError = () => setOrbitError((current) =>
1750
+ typeof current === 'string' && current.startsWith('删除失败:') ? null : current)
1751
+ const openDeleteConfirm = (watcher) => {
1752
+ // 先选中待删 watcher(保持原有 state 调用顺序),再清旧错误;两者同批渲染。
1753
+ setAnchor(watcher)
1754
+ clearDeleteError()
1755
+ }
1756
+
1626
1757
  useEffect(() => {
1627
1758
  // 仅旧路径保留 capture mousedown / 手算焦点;DSH 由 OrbitPopover 与宿主 dismiss hook 接管。
1628
1759
  if (!open || hostOrbit) return undefined
1629
1760
  const onDown = (event) => {
1761
+ // 本地确认 Modal 在最上层时,点背板/取消不能穿透到 Orbit(W16)。
1762
+ if (localDialogDepth > 0) return
1630
1763
  const target = event.target
1631
1764
  if (panelRef.current && panelRef.current.contains(target)) return
1632
1765
  if (btnRef.current && btnRef.current.contains(target)) return
1633
1766
  setOpen(false)
1634
1767
  }
1635
- const onKey = (event) => { if (event.key === 'Escape') setOpen(false) }
1768
+ const onKey = (event) => {
1769
+ if (event.key !== 'Escape' || event.repeat) return
1770
+ // 第一次 Escape 只关 Modal;Modal 的 keydown 在 bubble 阶段处理并归还焦点(W16)。
1771
+ if (localDialogDepth > 0) return
1772
+ setOpen(false)
1773
+ }
1636
1774
  document.addEventListener('mousedown', onDown, true)
1637
1775
  document.addEventListener('keydown', onKey, true)
1638
1776
  // 键盘可达:打开后把焦点送进弹层(Tab 才能顺序走进去),关掉时还给圆环按钮。
@@ -1657,9 +1795,9 @@ window.__ModuleLoader__.load({
1657
1795
  const running = list.filter((w) => orbitStateOf(w) === 'active').length
1658
1796
  const broken = list.filter((w) => orbitStateOf(w) === 'error').length
1659
1797
  const summary = readError && watchers === null
1660
- ? '读不到主理鱼状态'
1798
+ ? '读不到' + brandName + '状态'
1661
1799
  : list.length === 0
1662
- ? '还没有主理鱼'
1800
+ ? '还没有' + brandName
1663
1801
  : '会话级 superagent:' + running + ' 运行中'
1664
1802
  + (broken ? ',' + broken + ' 异常' : '')
1665
1803
  + '(共 ' + list.length + ' 条)'
@@ -1682,7 +1820,7 @@ window.__ModuleLoader__.load({
1682
1820
  ? readError
1683
1821
  : list.length
1684
1822
  ? list.map((w) => (w.repo + ' · ' + (w.title || '未命名会话') + ' · ' + sessionTag(w.sessionId) + ' · ' + STATE_TEXT[orbitStateOf(w)])).join('\n')
1685
- : '还没有主理鱼 —— 在「主理鱼」页加一条',
1823
+ : '还没有' + brandName + ' —— 在「' + brandName + '」页加一条',
1686
1824
  'aria-label': summary,
1687
1825
  'aria-expanded': open ? 'true' : 'false',
1688
1826
  className: cx('dt-btn', 'dt-btn-ghost', 'sa-orbit-trigger', watchers === null && 'is-loading'),
@@ -1707,7 +1845,7 @@ window.__ModuleLoader__.load({
1707
1845
  // 新数组只触发一次渲染,watcher 内容不变;可见 pending 直接读取同步锁集合。
1708
1846
  setWatchers((current) => Array.isArray(current) ? [...current] : current)
1709
1847
  if (action === 'delete') {
1710
- setOrbitError((current) => typeof current === 'string' && current.startsWith('删除失败:') ? null : current)
1848
+ clearDeleteError()
1711
1849
  }
1712
1850
  try {
1713
1851
  // 删除只走 ConfirmButton + Modal;不要再叠一层原生确认框(同一动作问两次)。
@@ -1732,6 +1870,8 @@ window.__ModuleLoader__.load({
1732
1870
  // fallback 完全保留原提前返回;DSH 即使 orbit 已关,也要继续渲染由本组件持有的确认 Modal。
1733
1871
  if (!open && !hostOrbit) return button
1734
1872
  const closeConfirm = () => {
1873
+ // 关掉确认框等于放弃这一次删除:错误跟着走,不要留在弹层里冒充「刚发生的失败」。
1874
+ clearDeleteError()
1735
1875
  setAnchor(null)
1736
1876
  orbitConfirm.onConfirmClose()
1737
1877
  }
@@ -1803,6 +1943,8 @@ window.__ModuleLoader__.load({
1803
1943
  : h(ConfirmButton, {
1804
1944
  label: '删除', confirmLabel: '确认删除', variant: 'ghost', size: 'sm', modalContext: 'orbit',
1805
1945
  icon: h(Icon, { name: 'trash' }),
1946
+ // 打开确认框时清掉上一次的删除失败(读取错误不动);本次失败由 act() 重新写入。
1947
+ onOpen: clearDeleteError,
1806
1948
  onConfirm: () => act(w, 'delete'), error: deleteError,
1807
1949
  preventDismissOnBusy: true, busyLabel: '删除中…', busyHint: '删除进行中,完成后才能关闭',
1808
1950
  }))
@@ -1848,7 +1990,7 @@ window.__ModuleLoader__.load({
1848
1990
 
1849
1991
  const panelBody = h(React.Fragment, null,
1850
1992
  h('div', { className: 'sa-dock-head' },
1851
- h('span', { className: 'sa-dock-title' }, '主理鱼'),
1993
+ h('span', { className: 'sa-dock-title' }, brandName),
1852
1994
  // 和面板统计条同一套官方素材:dt-stat(数值强 + 单位弱),不再自己发明 sa-dock-metric-*
1853
1995
  h(Stat, {
1854
1996
  className: 'sa-dock-metric',
@@ -1859,13 +2001,13 @@ window.__ModuleLoader__.load({
1859
2001
  watchers === null
1860
2002
  ? (!readError ? h('div', { className: 'sa-dock-empty' }, '正在读取…') : null)
1861
2003
  : list.length === 0
1862
- ? h('div', { className: 'sa-dock-empty' }, '还没有。在「主理鱼」标签页填 owner/name 加一条。')
2004
+ ? h('div', { className: 'sa-dock-empty' }, '还没有。在「' + brandName + '」标签页填 owner/name 加一条。')
1863
2005
  : h(hostOrbitRow ? 'ul' : 'div', { className: 'sa-dock-rows' }, rows),
1864
2006
  // 读失败与写操作失败分开说;旧列表仍可保留在错误上方。
1865
2007
  readError ? h('div', { className: 'sa-dock-err', role: 'alert' }, readError) : null,
1866
2008
  !readError && orbitError ? h('div', { className: 'sa-dock-err', role: 'alert' }, '操作失败:' + orbitError) : null,
1867
2009
  list.length > 0
1868
- ? h('div', { className: 'sa-dock-foot' }, '详细状态与凭证在「主理鱼」标签页')
2010
+ ? h('div', { className: 'sa-dock-foot' }, '详细状态与凭证在「' + brandName + '」标签页')
1869
2011
  : null)
1870
2012
 
1871
2013
  const panel = hostOrbit
@@ -1938,7 +2080,9 @@ window.__ModuleLoader__.load({
1938
2080
  }, [intervalMs])
1939
2081
  }
1940
2082
 
1941
- /** 轻量 Toast:DSH 可用时由宿主计时;fallback 保留原有 4 秒自动消失。 */
2083
+ /** 轻量 Toast:DSH 可用时由宿主计时;fallback 保留 4 秒自动消失。 */
2084
+ const TOAST_HOLD_MS = 3000
2085
+ const TOAST_FADE_MS = 1000
1942
2086
  function useToast() {
1943
2087
  if (hostUi) {
1944
2088
  const { item, notify, dismiss } = hostUi.createToastState()
@@ -1954,16 +2098,19 @@ window.__ModuleLoader__.load({
1954
2098
  const notify = useCallback((text, tone = 'info') => {
1955
2099
  if (timer.current) clearTimeout(timer.current)
1956
2100
  setItem({ id: Math.random().toString(36).slice(2), text, tone })
1957
- timer.current = setTimeout(() => setItem(null), 4000)
2101
+ // timer 覆盖 hold + fade 全段;比只等 hold 长 1 秒,淡出不会被提前卸载打断。
2102
+ timer.current = setTimeout(() => setItem(null), TOAST_HOLD_MS + TOAST_FADE_MS)
1958
2103
  }, [])
1959
2104
  const view = item === null ? null : h('div', {
2105
+ // key 用 item.id:连续通知换 id 时 React 会重建节点,dt-toast-in 动画才会从头播(W17)。
2106
+ key: item.id,
1960
2107
  className: cx('dt-toast', item.tone === 'error' && 'dt-danger'),
1961
2108
  role: 'status',
1962
2109
  'aria-live': 'polite',
1963
2110
  // 官方 toast 是深底白字;错误态不要改成浅红底(白字会看不清),改用左侧红条标记
1964
2111
  style: item.tone === 'error'
1965
- ? { '--dt-toast-hold': '3600ms', borderLeft: '3px solid var(--dsw-alias-state-error-primary)' }
1966
- : { '--dt-toast-hold': '3600ms' },
2112
+ ? { '--dt-toast-hold': TOAST_HOLD_MS + 'ms', borderLeft: '3px solid var(--dsw-alias-state-error-primary)' }
2113
+ : { '--dt-toast-hold': TOAST_HOLD_MS + 'ms' },
1967
2114
  }, item.text)
1968
2115
  return [view, notify]
1969
2116
  }
@@ -1971,7 +2118,7 @@ window.__ModuleLoader__.load({
1971
2118
  /** 判定页内联追溯时间线:结构化 traces 优先,旧服务端只有 text 时降级。 */
1972
2119
  function TraceTimeline({ payload }) {
1973
2120
  if (payload.loading) return h('p', { className: 'dt-hint' }, '正在追溯 #' + payload.number + '…')
1974
- if (payload.error) return h('p', { className: 'dt-error' }, '追溯失败:' + payload.error)
2121
+ if (payload.error) return h('p', { className: 'dt-error', role: 'alert', 'aria-atomic': 'true' }, '追溯失败:' + payload.error)
1975
2122
  const traces = Array.isArray(payload.traces) ? payload.traces : []
1976
2123
  if (traces.length === 0) return h('p', { className: 'dt-hint' }, payload.text || '没有结果')
1977
2124
  return h('ol', { className: 'dt-timeline' }, traces.map((trace) => {
@@ -2074,6 +2221,8 @@ window.__ModuleLoader__.load({
2074
2221
  const [giteeToken, setGiteeToken] = useState('')
2075
2222
  // 判定页内联追溯结果(官方 Thread 详情最小吸收):不再只塞进一条 Toast。
2076
2223
  const [traceResult, setTraceResult] = useState(null)
2224
+ // 每次追溯独占一个代际:新编号一开始,旧请求的结果/错误就全部作废。
2225
+ const traceSeqRef = useRef(0)
2077
2226
  // 安装回执与版本检查分开:POST 失败不能冲掉当前版本和命令回退。
2078
2227
  const [updateResult, setUpdateResult] = useState(null)
2079
2228
  // POST 后 GET 仍以 runningVersion 比较 latest;已装到 latest 且等待重载时,回执优先于 hasUpdate。
@@ -2087,8 +2236,8 @@ window.__ModuleLoader__.load({
2087
2236
  // 建议规则弹层:给"叫醒了没回音"一个下一步动作(只提供可复制的规则,不替客户写仓库文件)
2088
2237
 
2089
2238
  // 「我现在手上有没有能渲染的数据」。判断依据必须是**当前 snap**,不是"以前拿到过一次" ——
2090
- // 状态栏圆环每 5 秒全量拉一次 /state 并刷新模块级 stateEtag;面板首次挂载时正好带着这个
2091
- // etag 去问,首帧必然 304。旧代码在 304 分支直接 return、从不 setSnap,于是面板永远停在
2239
+ // 会话作用域的 etag 只属于本会话;面板挂载时如果带着一份自己以前留下的 etag(快照已丢),
2240
+ // 首帧会 304。旧代码在 304 分支直接 return、从不 setSnap,于是面板永远停在
2092
2241
  // {loading:true, body:null}:统计条全 0、列表空态、底下还挂着「正在读取…」(真机现象:2 条显示 0 条)。
2093
2242
  const hasBodyRef = useRef(false)
2094
2243
  hasBodyRef.current = Boolean(snap.body)
@@ -2096,28 +2245,49 @@ window.__ModuleLoader__.load({
2096
2245
  // 审核 M1:四条路径(轮询 / 工具栏刷新 / 错误卡重试 / run() 成功后)都能并发,
2097
2246
  // 没有序号时「后到的旧响应」会覆盖新数据。序号只认最新的那次。
2098
2247
  const loadSeqRef = useRef(0)
2099
- const load = useCallback(async () => {
2248
+ // 终审 N1:被更新的一次 load 顶掉时,旧的那次不能把「成功」当失败 ——
2249
+ // run() 的 requireReload 会因此假报「回读失败,请重试」(数据其实已经取到了)。
2250
+ // 记下最新一次的 promise:被顶掉就等它,用最新快照回话;它真失败时仍然按失败返回。
2251
+ const latestLoadRef = useRef(null)
2252
+ const load = useCallback(() => {
2100
2253
  const seq = ++loadSeqRef.current
2101
- const statePath = sessionId ? '/state?sessionId=' + encodeURIComponent(String(sessionId)) : '/state'
2102
- try {
2103
- const payload = await call(statePath, stateEtag ? { headers: { 'if-none-match': stateEtag } } : undefined)
2104
- if (seq !== loadSeqRef.current) return null // 已经有更新的一次请求在飞:这次结果作废
2105
- // 304:内容没变,别白白重渲染 —— 前提是本地已经有一份能渲染的 body
2106
- if (payload && payload.notModified) {
2107
- // 有本地快照时,304 也是一次成功回读;保存后的成功反馈可以依赖它。
2108
- if (hasBodyRef.current) return payload
2109
- // 本地没有数据:这次 304 是被状态栏的 etag 带出来的,清掉 etag 重取一次全量
2110
- stateEtag = null
2111
- return load()
2254
+ const job = (async () => {
2255
+ const statePath = sessionId ? '/state?sessionId=' + encodeURIComponent(String(sessionId)) : '/state'
2256
+ const etag = readStateEtag(statePath)
2257
+ try {
2258
+ const payload = await call(statePath, etag ? { headers: { 'if-none-match': etag } } : undefined)
2259
+ // 已经有更新的一次请求在飞:等它的结果,别把自己的成功报成失败
2260
+ if (seq !== loadSeqRef.current) return await (latestLoadRef.current || null)
2261
+ // 304:内容没变,前提是本地已经有一份能渲染的 body
2262
+ if (payload && payload.notModified) {
2263
+ // 有本地快照时,304 也是一次成功回读;清掉此前的 500/网络错误。
2264
+ // 正常且无旧错时返回原 state,避免每次条件轮询都重渲染。
2265
+ if (hasBodyRef.current) {
2266
+ setSnap((prev) => prev.error || prev.loading
2267
+ ? { loading: false, error: null, body: prev.body }
2268
+ : prev)
2269
+ return payload
2270
+ }
2271
+ // 本地没有数据:这次 304 是被同一作用域旧 etag 带出来的,清掉它重取一次全量
2272
+ writeStateEtag(statePath, null)
2273
+ return load()
2274
+ }
2275
+ const body = payload
2276
+ setSnap({ loading: false, error: null, body })
2277
+ return body
2278
+ } catch (error) {
2279
+ // 旧请求的失败同样不盖新数据:等最新那次的结果(它失败就一并按失败返回)
2280
+ if (seq !== loadSeqRef.current) return await (latestLoadRef.current || null)
2281
+ const message = String((error && error.message) || error)
2282
+ // 同文轮询失败复用同一 snap/alert DOM;显式重试成功仍会清错,错误文本变化仍会通知。
2283
+ setSnap((prev) => prev.error === message && !prev.loading
2284
+ ? prev
2285
+ : { loading: false, error: message, body: prev.body })
2286
+ return null
2112
2287
  }
2113
- const body = payload
2114
- setSnap({ loading: false, error: null, body })
2115
- return body
2116
- } catch (error) {
2117
- if (seq !== loadSeqRef.current) return null // 旧请求的失败也别盖掉新数据
2118
- setSnap((prev) => ({ loading: false, error: String((error && error.message) || error), body: prev.body }))
2119
- return null
2120
- }
2288
+ })()
2289
+ latestLoadRef.current = job
2290
+ return job
2121
2291
  }, [sessionId])
2122
2292
 
2123
2293
  useEffect(() => { ensurePortedCss() }, [])
@@ -2126,10 +2296,13 @@ window.__ModuleLoader__.load({
2126
2296
  const body = snap.body || {}
2127
2297
  // 默认值提示从后端读:写死 12/3/6 会在常量变化后变成谎话(JSON Schema 的 default 也是这个用法)
2128
2298
  const DEFAULTS = body.defaults || {}
2299
+ // 品牌与默认 ack 都来自 /state(issue #11);缺省时保持 0.10.0 的文案。
2300
+ const BRAND = (typeof body.brandName === 'string' && body.brandName.trim()) || '主理鱼'
2301
+ const ACK_DEFAULTS = body.defaultAckLabels || null
2129
2302
  const watchers = body.watchers || []
2130
2303
  // 行内编辑只有这一条入口:clean 维持原直达行为;dirty 先确认,取消绝不重置 draft/touched。
2131
2304
  const applyWatcherEditor = (watcher, nextKey) => {
2132
- const values = watcherValuesFrom(watcher)
2305
+ const values = watcherValuesFrom(watcher, ACK_DEFAULTS)
2133
2306
  setEditing(nextKey)
2134
2307
  touchedRef.current = new Set()
2135
2308
  editSnapshotRef.current = nextKey ? { key: nextKey, values } : null
@@ -2141,7 +2314,7 @@ window.__ModuleLoader__.load({
2141
2314
  activeHours: watcher.activeHours || '',
2142
2315
  // `watcher.goal` 可能是 goalView 对象;输入框只能接收已展开的字符串。
2143
2316
  goal: watcher.note || (typeof watcher.goal === 'string' ? watcher.goal : (watcher.goal && watcher.goal.objective) || ''),
2144
- ackLabel: watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'),
2317
+ ackLabel: watcher.ackLabel || ackLabelFallback(watcher, ACK_DEFAULTS),
2145
2318
  onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
2146
2319
  allowAuthors: (watcher.filters && watcher.filters.allowAuthors ? watcher.filters.allowAuthors : []).join(', '),
2147
2320
  observe: !!watcher.observe,
@@ -2162,7 +2335,7 @@ window.__ModuleLoader__.load({
2162
2335
  const editingWatcher = watchers.find((watcher) => watcher.repo + '#' + watcher.sessionId === editing)
2163
2336
  const editingOpening = editSnapshotRef.current && editSnapshotRef.current.key === editing
2164
2337
  ? editSnapshotRef.current.values
2165
- : editingWatcher ? watcherValuesFrom(editingWatcher) : null
2338
+ : editingWatcher ? watcherValuesFrom(editingWatcher, ACK_DEFAULTS) : null
2166
2339
  const editingDirty = Boolean(editing && editingOpening && (
2167
2340
  touchedRef.current.size > 0 || watcherDirty({ ...editingOpening, ...draft }, editingOpening)))
2168
2341
  const pendingCollapseKey = glossary && glossary.type === 'watcher-draft' && !glossary.nextKey
@@ -2369,7 +2542,10 @@ window.__ModuleLoader__.load({
2369
2542
  return warnings
2370
2543
  }, null, { rethrow: true })
2371
2544
 
2545
+ const credentialsDirty = Boolean(token.trim() || giteeToken.trim() || ghDir.trim())
2372
2546
  const saveCredentials = () => {
2547
+ // 空草稿没有可保存的改动;即使绕过 disabled 直接调用,也不能发 {} 后假报成功。
2548
+ if (!credentialsDirty) return Promise.resolve(false)
2373
2549
  const draftVersion = credentialsDraftVersionRef.current
2374
2550
  let saveSeq = 0
2375
2551
  return run(async () => {
@@ -2401,6 +2577,8 @@ window.__ModuleLoader__.load({
2401
2577
  }, '已解绑 gh 账号目录(评论改回宿主账号)')
2402
2578
 
2403
2579
  const saveGoal = () => {
2580
+ // 与按钮/文本域的 disabled 同一道防线:没有会话归属时不能提交或假报成功。
2581
+ if (!sessionId) return Promise.resolve(false)
2404
2582
  const draftVersion = goalDraftVersionRef.current
2405
2583
  let saveSeq = 0
2406
2584
  return run(async () => {
@@ -2460,7 +2638,7 @@ window.__ModuleLoader__.load({
2460
2638
  const rowBody = h('div', { className: 'dt-ticket-body' },
2461
2639
  h('div', { className: 'dt-row-title' },
2462
2640
  h('button', {
2463
- type: 'button', className: 'dt-open', title: '展开或收起这条主理鱼的设置',
2641
+ type: 'button', className: 'dt-open', title: '展开或收起这条' + BRAND + '的设置',
2464
2642
  'aria-expanded': displayedEditing === key, onClick: () => toggleWatcherEditor(watcher),
2465
2643
  }, watcher.repo)),
2466
2644
  pauseNote(watcher),
@@ -2476,7 +2654,7 @@ window.__ModuleLoader__.load({
2476
2654
  watcher.isolated ? h(Tag, null, isolationText(watcher)) : null,
2477
2655
  filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
2478
2656
  // ack 标签决定这条是否还会被叫醒,不能只在工具参数里出现。
2479
- h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'))),
2657
+ h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || ackLabelFallback(watcher, ACK_DEFAULTS))),
2480
2658
  watcher.queuedWakes > 0 ? h(Tag, { tone: 'warning' }, '排队 ' + watcher.queuedWakes) : null,
2481
2659
  backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
2482
2660
  // 三行,各管一件事:① 是谁 ② 节律与最近结果 ③ 目标
@@ -2550,7 +2728,7 @@ window.__ModuleLoader__.load({
2550
2728
  })))
2551
2729
  const opening = editSnapshotRef.current && editSnapshotRef.current.key === key
2552
2730
  ? editSnapshotRef.current.values
2553
- : watcherValuesFrom(watcher)
2731
+ : watcherValuesFrom(watcher, ACK_DEFAULTS)
2554
2732
  const editorValue = { ...opening, ...draft }
2555
2733
  const editor = displayedEditing === key
2556
2734
  ? h(WatcherForm, {
@@ -2635,7 +2813,7 @@ window.__ModuleLoader__.load({
2635
2813
  // 两处并排会让同一句话在同一屏出现两次;而且「时段外 / 已停用」是配置出来的状态、不是待处理的问题。
2636
2814
  }
2637
2815
  if (body.gh && body.gh.ok === false && credentials.token === 'none') {
2638
- problems.push({ key: 'gh', rank: 0, kind: 'gh', text: 'gh CLI 不可用,且没有配置 token —— 现在所有轮询都会失败。先跑 gh auth login,或在「设置 → 来源」填一个 token。' })
2816
+ problems.push({ key: 'gh', rank: 0, kind: 'gh', text: 'gh CLI 不可用,且没有配置 token —— 现在所有轮询都会失败。先跑 gh auth login,或在「设置 → 凭证」填一个 token。' })
2639
2817
  }
2640
2818
  if (watchers.length > 0 && credentials.token === 'none') {
2641
2819
  problems.push({ key: 'cred', rank: 7, kind: 'cred', text: '未配置 token,正在复用已登录的 gh CLI(可用 panel 填 token 换成独立凭据)' })
@@ -2649,6 +2827,7 @@ window.__ModuleLoader__.load({
2649
2827
  const matchesBadge = (watcher) => !badgeFilter
2650
2828
  || repoBadges(watcher.repoAccess).some((badge) => badge.text === badgeFilter)
2651
2829
  const hasProblem = (watcher) => Boolean(watcher.lastError)
2830
+ || Boolean(watcher.lastReopened)
2652
2831
  || Number(watcher.silentWakes) >= 2
2653
2832
  || Boolean(repoStructureNote(watcher.repoAccess))
2654
2833
  || repoBadges(watcher.repoAccess).some((badge) => badge.tone === 'warning' || badge.tone === 'danger')
@@ -2663,6 +2842,10 @@ window.__ModuleLoader__.load({
2663
2842
  const visible = watchers.filter((watcher) => matches(watcher) && matchesBadge(watcher) && stateMatches(watcher)
2664
2843
  && (!problemsOnly || hasProblem(watcher))
2665
2844
  && (!deferFilter || watcher.deferReason === deferFilter))
2845
+ const hasActiveFilters = Boolean(needle || badgeFilter || stateFilter || problemsOnly || deferFilter)
2846
+ const clearAllFilters = () => {
2847
+ setBadgeFilter(null); setStateFilter(null); setSearch(''); setProblemsOnly(false); setReasonFilter(null)
2848
+ }
2666
2849
 
2667
2850
  // T24 W1:「全部暂停/全部恢复」对**这一屏**生效,可用性也按这一屏算(同口径)。
2668
2851
  const pausable = countPausable(visible)
@@ -2688,11 +2871,7 @@ window.__ModuleLoader__.load({
2688
2871
  })(),
2689
2872
  ...chips.map((chip) => h(Pill, { key: chip.label, onClick: chip.clear }, chip.label + ' ✕')),
2690
2873
  chips.length > 1
2691
- ? h(Pill, {
2692
- key: '__all', onClick: () => {
2693
- setBadgeFilter(null); setStateFilter(null); setSearch(''); setProblemsOnly(false); setReasonFilter(null)
2694
- },
2695
- }, '全部清除')
2874
+ ? h(Pill, { key: '__all', onClick: clearAllFilters }, '全部清除')
2696
2875
  : null)
2697
2876
  })()
2698
2877
 
@@ -2707,11 +2886,16 @@ window.__ModuleLoader__.load({
2707
2886
  return acc
2708
2887
  }, { woken: 0, acked: 0 })
2709
2888
 
2889
+ // 服务端已限制每守带回的记录数;面板在全局合并后排序,不能按守各切两条再拼接。
2890
+ const filteredEntries = watchers
2891
+ .flatMap((watcher) => (watcher.filteredLog || []).map((entry, sourceIndex) => ({ watcher, entry, sourceIndex })))
2892
+ .sort((a, b) => String(b.entry.at || '').localeCompare(String(a.entry.at || '')))
2893
+
2710
2894
  const overview = [
2711
2895
  filterSummary,
2712
2896
  h('div', { className: 'dt-stats', key: 'stats' },
2713
2897
  h(Stat, {
2714
- key: 'all', value: watchers.length, unit: '条主理鱼',
2898
+ key: 'all', value: watchers.length, unit: '条' + BRAND,
2715
2899
  active: stateFilter === null, onClick: () => setStateFilter(null),
2716
2900
  }),
2717
2901
  h(Stat, {
@@ -2735,12 +2919,22 @@ window.__ModuleLoader__.load({
2735
2919
  key: 'dormant', value: dormant, unit: '时段外',
2736
2920
  active: stateFilter === 'dormant', onClick: () => setStateFilter(stateFilter === 'dormant' ? null : 'dormant'),
2737
2921
  }) : null),
2738
- watchers.some((w) => (w.filteredLog || []).length > 0)
2922
+ filteredEntries.length > 0
2739
2923
  ? h(Section, { key: 'filtered', title: '最近被过滤' },
2740
2924
  h(CollapsibleList, {
2741
2925
  title: '看被过滤的条目',
2742
- items: watchers.flatMap((w) => (w.filteredLog || []).slice(-2).map((entry) =>
2743
- '#' + entry.number + ' ' + (entry.title || '') + ' — ' + entry.reason)),
2926
+ items: filteredEntries.map(({ watcher, entry, sourceIndex }) => {
2927
+ const head = watcher.repo + ' · 会话 ' + sessionTag(watcher.sessionId)
2928
+ + ' · #' + String(entry.number ?? '—') + ' ' + (entry.title || '') + ' — ' + entry.reason
2929
+ const at = String(entry.at || '')
2930
+ return {
2931
+ key: ['filtered', watcher.sessionId, watcher.repo, entry.number, entry.at, entry.reason, sourceIndex]
2932
+ .map((part) => String(part ?? '')).join('|'),
2933
+ summary: head + ' · ' + (at || '时间未知'),
2934
+ content: h(React.Fragment, null, head, ' · ',
2935
+ h('time', { dateTime: at || undefined, title: at || undefined }, at || '时间未知')),
2936
+ }
2937
+ }),
2744
2938
  }))
2745
2939
  : null,
2746
2940
  // 排序:会丢消息的(失败/没回音)排前面;静态提示(仓库归档、只读)排后面
@@ -2778,11 +2972,20 @@ window.__ModuleLoader__.load({
2778
2972
  '代码已更新到 ' + body.installedVersion + ',但宿主还在跑 ' + body.runningVersion
2779
2973
  + ' —— 服务端改动需要重启宿主才生效(客户端部分已生效,所以界面可能看起来是新的)。')
2780
2974
  : null,
2781
- h(Section, { key: 'list', title: needle ? '搜索结果' : '主理鱼', count: visible.length },
2975
+ h(Section, { key: 'list', title: needle ? '搜索结果' : BRAND, count: visible.length },
2782
2976
  watchers.length === 0
2783
2977
  ? h(Onboarding, { onStart: () => setTab('trigger') })
2784
2978
  : visible.length === 0
2785
- ? h(Hint, null, '没有匹配「' + search + '」的主理鱼。')
2979
+ ? h('div', { className: 'dt-empty' },
2980
+ h(Hint, null, needle
2981
+ ? '没有匹配「' + search.trim() + '」的' + BRAND + '。'
2982
+ : hasActiveFilters
2983
+ ? '没有符合当前筛选条件的' + BRAND + '。'
2984
+ : '当前没有可显示的' + BRAND + '。'),
2985
+ hasActiveFilters
2986
+ ? h('div', { className: 'dt-actions' },
2987
+ h(Btn, { size: 'sm', variant: 'outline', onClick: clearAllFilters }, '清除全部筛选'))
2988
+ : null)
2786
2989
  : h('ul', { className: 'dt-list' }, visible.map(row))),
2787
2990
  ]
2788
2991
 
@@ -2815,12 +3018,15 @@ window.__ModuleLoader__.load({
2815
3018
  className: 'dt-textlink',
2816
3019
  type: 'button',
2817
3020
  onClick: async () => {
3021
+ const seq = ++traceSeqRef.current
2818
3022
  setTraceResult({ loading: true, number: asNumber })
2819
3023
  try {
2820
3024
  const query = '/trace?number=' + encodeURIComponent(asNumber) + (onlyRepo ? '&repo=' + encodeURIComponent(onlyRepo) : '')
2821
3025
  const payload = await call(query)
3026
+ if (seq !== traceSeqRef.current) return
2822
3027
  setTraceResult(payload || { text: '没有结果', traces: [] })
2823
3028
  } catch (error) {
3029
+ if (seq !== traceSeqRef.current) return
2824
3030
  setTraceResult({ error: String((error && error.message) || error), number: asNumber })
2825
3031
  }
2826
3032
  },
@@ -2863,7 +3069,7 @@ window.__ModuleLoader__.load({
2863
3069
  // 判定页的空态也要给路径:说清「加一条之后这里会出现什么」,而不是一句「还没有主理鱼」
2864
3070
  ? h('div', { className: 'dt-empty' },
2865
3071
  h('p', { className: 'dt-step-title' }, '还没有可判定的记录'),
2866
- h('p', { className: 'dt-step-detail' }, '添加一条主理鱼之后,每轮判定都会记在这里:唤醒、仅观察,或跳过及其原因。'),
3072
+ h('p', { className: 'dt-step-detail' }, '添加一条' + BRAND + '之后,每轮判定都会记在这里:唤醒、仅观察,或跳过及其原因。'),
2867
3073
  h('div', { className: 'dt-actions' },
2868
3074
  h(Btn, { size: 'sm', variant: 'primary', onClick: () => setTab('trigger') }, '去添加第一条')))
2869
3075
  : (() => {
@@ -2930,7 +3136,13 @@ window.__ModuleLoader__.load({
2930
3136
  h('time', { className: 'dt-event-time', dateTime: entry.at, title: entry.at }, ageText(entry.at)))))
2931
3137
  }
2932
3138
 
2933
- // 迷你时间线:回答"为什么这一轮没叫醒我"
3139
+ // 迷你时间线:回答"为什么这一轮没叫醒我"。先全局合并排序,再兑现标题的最近 20 条。
3140
+ const runtimeEvents = watchers
3141
+ .flatMap((watcher) => (watcher.events || []).map((event, sourceIndex) => ({ watcher, event, sourceIndex })))
3142
+ .sort((a, b) => String(b.event.at || '').localeCompare(String(a.event.at || ''))
3143
+ // 同守同时间戳仍保持原先 slice().reverse() 的后进先出;跨守同刻交给稳定排序。
3144
+ || (a.watcher === b.watcher ? b.sourceIndex - a.sourceIndex : 0))
3145
+ .slice(0, 20)
2934
3146
  const timeline = h(Section, {
2935
3147
  key: 'timeline',
2936
3148
  title: '运行时事件(最近 20 条)',
@@ -2939,19 +3151,24 @@ window.__ModuleLoader__.load({
2939
3151
  },
2940
3152
  watchers.length === 0
2941
3153
  ? h(Hint, null, '还没有守。添加一条之后,这里会记录每次唤醒、攒着、限流、回收。')
2942
- : h('ol', { className: 'dt-timeline' }, watchers.flatMap((watcher) => (watcher.events || []).slice().reverse().map((event, index) => h('li', {
2943
- key: watcher.repo + '-ev' + index,
2944
- className: 'dt-event',
2945
- },
2946
- h('div', { className: 'dt-event-head' },
2947
- h(Tag, { tone: event.kind === 'wake' ? 'success' : event.kind === 'wake-failed' ? 'danger' : 'outline' },
2948
- event.kind + (Number(event.count) > 1 ? ' ×' + event.count : '')),
2949
- (Number(event.count) > 1 && event.since)
2950
- ? h('span', { className: 'dt-row-meta' }, '持续 ' + durationText(event.since, event.at))
2951
- : null,
2952
- h('span', { className: 'dt-row-meta' }, ageText(event.at))),
2953
- h('div', { className: 'dt-event-text' }, watcher.repo + ' · ' + event.text),
2954
- h('div', { className: 'dt-event-foot' }, event.at))))))
3154
+ : runtimeEvents.length === 0
3155
+ ? h(Hint, null, '还没有运行时事件;完成一次轮询后,这里会记录唤醒、攒着、限流、回收。')
3156
+ : h('ol', { className: 'dt-timeline' }, runtimeEvents.map(({ watcher, event, sourceIndex }) => h('li', {
3157
+ key: ['event', watcher.sessionId, watcher.repo,
3158
+ event.number ?? (Array.isArray(event.numbers) ? event.numbers.join(',') : ''),
3159
+ event.kind, event.at, sourceIndex].map((part) => String(part ?? '')).join('|'),
3160
+ className: 'dt-event',
3161
+ },
3162
+ h('div', { className: 'dt-event-head' },
3163
+ h(Tag, { tone: event.kind === 'wake' ? 'success' : event.kind === 'wake-failed' ? 'danger' : 'outline' },
3164
+ event.kind + (Number(event.count) > 1 ? ' ×' + event.count : '')),
3165
+ (Number(event.count) > 1 && event.since)
3166
+ ? h('span', { className: 'dt-row-meta' }, '持续 ' + durationText(event.since, event.at))
3167
+ : null,
3168
+ h('span', { className: 'dt-row-meta' }, '会话 ' + sessionTag(watcher.sessionId)),
3169
+ h('span', { className: 'dt-row-meta' }, ageText(event.at))),
3170
+ h('div', { className: 'dt-event-text' }, watcher.repo + ' · ' + event.text),
3171
+ h('div', { className: 'dt-event-foot' }, event.at)))))
2955
3172
 
2956
3173
  // 按仓库汇总:守多个仓库时先看哪个健康,再看明细(渐进披露)
2957
3174
  const problemCount = watchers.filter(hasProblem).length
@@ -2985,7 +3202,9 @@ window.__ModuleLoader__.load({
2985
3202
  ]
2986
3203
  })())
2987
3204
  : null,
2988
- visible.length === 0 ? h(Hint, null, '没有符合条件的主理鱼。点上面「全部」看所有守。') : null,
3205
+ visible.length === 0 && watchers.length > 0
3206
+ ? h(Hint, null, '按仓库汇总也为空;请用上方「清除全部筛选」恢复。')
3207
+ : null,
2989
3208
  h('div', { className: 'dt-rows' }, ...summarizeByRepo(visible).map((group) => h('div', { key: 'repo-' + group.repo, className: 'dt-row' },
2990
3209
  h('div', { className: 'dt-row-main' },
2991
3210
  h('div', { className: 'dt-row-title' },
@@ -3003,7 +3222,7 @@ window.__ModuleLoader__.load({
3003
3222
  group.silentWakes > 0 ? h('span', { className: 'dt-error-text' }, '未回音 ' + group.silentWakes + ' 次') : null,
3004
3223
  group.errors > 0 ? h('span', { className: 'dt-error-text' }, group.errors + ' 条报错') : null))))))
3005
3224
 
3006
- const trigger = h(Section, { title: '新增主理鱼' },
3225
+ const trigger = h(Section, { title: '新增' + BRAND },
3007
3226
  h(WatcherForm, {
3008
3227
  mode: 'create', idPrefix: 'watcher-new', value: { ...CREATE_WATCHER_VALUES, ...form },
3009
3228
  snapshot: createSnapshotRef.current, defaults: DEFAULTS, disabled: !sessionId, sessionId,
@@ -3036,7 +3255,7 @@ window.__ModuleLoader__.load({
3036
3255
  ? '不需要(没有 GitHub 主理鱼)' + (body.gh.skipped ? ' · ' + String(body.gh.skipped) : '')
3037
3256
  : body.gh.ok
3038
3257
  ? '可用 · ' + (body.gh.version || '')
3039
- : '不可用 —— 先跑 gh auth login(或装 gh CLI);也可以直接在下面填 token · ' + String(body.gh.error || '').slice(0, 80)],
3258
+ : '不可用 —— 先跑 gh auth login(或装 gh CLI);也可以去「凭证」填 token · ' + String(body.gh.error || '').slice(0, 80)],
3040
3259
  // 标签要能和左栏「凭证」分区区分开;值要写出「面板 token / gh 登录态」二选一。
3041
3260
  ['GitHub 凭证', credentials.token === 'none' ? '回退到已登录的 gh CLI' : '用面板 token(不再需要 gh login)'],
3042
3261
  ['权限范围', (() => {
@@ -3068,12 +3287,14 @@ window.__ModuleLoader__.load({
3068
3287
  credentials.ghConfigDir === 'configured'
3069
3288
  ? h('div', { className: 'dt-actions' }, h(Btn, { variant: 'ghost', size: 'sm', onClick: clearGhDir }, '解绑 gh 账号目录'))
3070
3289
  : null,
3071
- h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveCredentials }, '保存凭证')),
3290
+ h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveCredentials, disabled: !credentialsDirty }, '保存凭证')),
3072
3291
  h(Hint, null, '不填也能用:插件直接复用已登录的 gh CLI。填了 gh 账号目录,插件就用那个目录里的账号发言(git push 仍用会话自己的身份,唤醒消息里会提醒会话)。')),
3073
3292
  h(Section, { key: 'update', title: '版本与更新' },
3074
3293
  h(KeyValues, { rows: [
3075
3294
  ['当前版本', (update && update.current) || CLIENT_VERSION],
3076
- ['npm 最新', !update ? '检测中…' : update.error ? '检测失败 · ' + update.error : (update.latest || '未知')],
3295
+ ['npm 最新', !update ? '检测中…' : update.error
3296
+ ? h('span', { className: 'dt-error', role: 'alert', 'aria-atomic': 'true' }, '检测失败 · ' + update.error)
3297
+ : (update.latest || '未知')],
3077
3298
  ['状态', updateResult && updateResult.resultUnknown
3078
3299
  ? UPDATE_UNKNOWN_HINT
3079
3300
  : updateAwaitingReload
@@ -3143,9 +3364,11 @@ window.__ModuleLoader__.load({
3143
3364
  h(Section, { key: 'goal', title: '会话 goal' },
3144
3365
  h('textarea', {
3145
3366
  className: 'dt-textarea', rows: 3, value: goalDraft,
3367
+ 'aria-label': '会话 goal', disabled: !sessionId,
3146
3368
  placeholder: '这个会话要达成什么(会写进 /goal)',
3147
3369
  onChange: (e) => { goalDraftVersionRef.current += 1; setGoalTouched(true); setGoalDraft(e.target.value) },
3148
3370
  }),
3371
+ !sessionId ? h(Hint, null, '没有会话上下文,无法编辑或保存 goal;请先在会话里打开本面板。') : null,
3149
3372
  h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveGoal, disabled: !sessionId }, '保存 goal'))),
3150
3373
  ]
3151
3374
 
@@ -3358,7 +3581,7 @@ window.__ModuleLoader__.load({
3358
3581
  return h('div', { className: 'dt-page' },
3359
3582
  h('div', { className: 'dt-page-head' },
3360
3583
  h('div', null,
3361
- h('h1', { className: 'dt-page-title' }, '主理鱼'),
3584
+ h('h1', { className: 'dt-page-title' }, BRAND),
3362
3585
  h('span', { className: 'dt-hint' },
3363
3586
  (body.sessionTitle ? '会话:' + body.sessionTitle + ' · ' : '')
3364
3587
  + (sessionId ? '盯办 + 主动办:仓库有动静就叫醒本会话' : '(在会话里打开本面板,才能把仓库绑到会话上)'))),
@@ -3397,7 +3620,7 @@ window.__ModuleLoader__.load({
3397
3620
  ],
3398
3621
  value: tab, onChange: setTab, label: '主理鱼分区',
3399
3622
  }),
3400
- notice ? h('div', { className: 'dt-banner dt-danger' }, notice.text) : null,
3623
+ notice ? h('div', { className: 'dt-banner dt-danger', role: 'alert', 'aria-atomic': 'true' }, notice.text) : null,
3401
3624
  // 有新版本时在顶部提示一次;已装到 latest 且等待重载时完全隐藏,避免重复安装入口。
3402
3625
  update && update.hasUpdate && !updateAwaitingReload
3403
3626
  ? h('div', { className: 'dt-banner dt-banner-actions' },
@@ -3408,7 +3631,7 @@ window.__ModuleLoader__.load({
3408
3631
  snap.error
3409
3632
  ? h('div', { className: 'dt-card dt-error-card', key: 'read-error' },
3410
3633
  h('div', { className: 'dt-card-head' }, h('span', { className: 'dt-card-title' }, '读不到面板数据')),
3411
- h('p', { className: 'dt-error' }, humanizeError(snap.error)),
3634
+ h('p', { className: 'dt-error', role: 'alert', 'aria-atomic': 'true' }, humanizeError(snap.error)),
3412
3635
  h('div', { className: 'dt-actions' }, h(Btn, { size: 'sm', variant: 'primary', onClick: () => load() }, '重试')))
3413
3636
  : null,
3414
3637
  snap.loading && !snap.body ? h(Hint, null, '正在读取…') : null,
@@ -3453,16 +3676,16 @@ window.__ModuleLoader__.load({
3453
3676
  onClick: () => copyText(AGENTS_SNIPPET, '规则已复制,粘贴到 AGENTS.md 末尾即可'),
3454
3677
  }, '复制这段规则'),
3455
3678
  h(Btn, { size: 'sm', variant: 'ghost', onClick: () => setGlossary(false) }, '关闭'))) : null,
3456
- h(PanelModal, { open: glossary === true, title: '主理鱼术语表', onClose: () => setGlossary(false) },
3679
+ h(PanelModal, { open: glossary === true, title: BRAND + '术语表', onClose: () => setGlossary(false) },
3457
3680
  h(KeyValues, { rows: [
3458
- ['主理鱼', '一条「盯办」绑定:某个仓库 → 某个会话'],
3681
+ [BRAND, '一条「盯办」绑定:某个仓库 → 某个会话'],
3459
3682
  ['盯', '轮询 issue/PR、按水位去重、冷却期吸收自己的操作'],
3460
3683
  ['办', '唤醒会话后按仓库 AGENTS.md 主动处理,完成后 watch_ack 打标签'],
3461
- ['唤醒', '只在会话空闲(idle)时注入一条【主理鱼】消息'],
3684
+ ['唤醒', '只在会话空闲(idle)时注入一条【' + BRAND + '】消息'],
3462
3685
  ['过滤', '标签白名单/黑名单、只看已指派、跳过机器人/草稿/已关闭'],
3463
3686
  ['时段', 'activeHours,比如 09:00-23:00,时段外只攒不唤醒'],
3464
3687
  ['隔离', 'isolated:每次唤醒开一次性 git worktree,改副本不碰主工作区'],
3465
- ['ack', '处理完给条目打「主理鱼:已处理」标签,轮询直接跳过'],
3688
+ ['ack', '处理完给条目打「' + (ACK_DEFAULTS && ACK_DEFAULTS.github ? ACK_DEFAULTS.github : '主理鱼:已处理') + '」标签,轮询直接跳过'],
3466
3689
  ['goal', '会话目标(ctx.goals),和 /goal 命令同一份状态'],
3467
3690
  ['凭证', 'token 存在服务端 secrets.json,面板只显示是否已配置'],
3468
3691
  ['上限', '两种:单条守每小时最多 6 次、整条会话 12 次(面板里可调);和 GitHub 的限流不是一回事'],