dsh-session-superagent 0.9.67 → 0.9.68

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
@@ -1,1786 +1,1786 @@
1
- /**
2
- * dsh-session-superagent — browser half.
3
- *
4
- * Registers one list entry into `conversation.view` (the centre-column view
5
- * ring: chat / trajectory / waterfall live there), so the panel appears as a
6
- * tab beside them. It reads the read-only host route the server half
7
- * registers; no credential ever crosses this boundary.
8
- */
9
- window.__ModuleLoader__.load({
10
- id: 'dsh-session-superagent',
11
- factory(require) {
12
- const React = require('react')
13
- const h = React.createElement
14
- const { useCallback, useEffect, useRef, useState } = React
15
-
16
- // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.67'
18
- let BASE = '/session-superagent'
19
- /**
20
- * 挑「最新的那个服务端实例」。
21
- *
22
- * 宿主重载时旧 handler 摘不掉,所以可能同时存在多个前缀:默认的(旧代码)和 `/rN`(新代码)。
23
- * 甚至出现过「新实例在默认前缀注册成功、但请求仍被旧 handler 接走」的情况 ——
24
- * 所以不能只看「注册成功」,要按实例自报的版本 + routeBase 匹配来选。
25
- */
26
- async function discoverBase() {
27
- const candidates = [BASE]
28
- for (let i = 2; i <= 8; i += 1) candidates.push('/session-superagent/r' + i)
29
- const versionScore = (v) => {
30
- const parts = String(v || '0').split('.').map((n) => Number(n) || 0)
31
- return parts[0] * 1e6 + parts[1] * 1e3 + parts[2]
32
- }
33
- let best = null
34
- for (const base of candidates) {
35
- try {
36
- const res = await fetch(base + '/state', { headers: { accept: 'application/json' } })
37
- if (!res.ok) continue
38
- const body = await res.json()
39
- // 只有「自报前缀 = 我请求的前缀」才说明这个实例真的在这条路径上服务
40
- if (!body || body.routeBase !== base) continue
41
- const score = versionScore(body.serverVersion)
42
- if (!best || score > best.score) best = { base, score }
43
- } catch {}
44
- }
45
- if (best && best.base !== BASE) {
46
- BASE = best.base
47
- // 记一笔:排查「面板到底在跟哪一代」时用得上(不像轮询那样完全不落痕迹)
48
- try { note('client-base', BASE) } catch {}
49
- } else if (best) {
50
- BASE = best.base
51
- }
52
- return BASE
53
- }
54
-
55
- const POLL_MS = 5000
56
-
57
- // 上一次 /state 的 ETag:带上它,没变化时服务端回 304,省掉整份 JSON
58
- let stateEtag = null
59
-
60
- async function call(path, options, retried) {
61
- const init = {
62
- ...(options || {}),
63
- headers: { 'content-type': 'application/json', accept: 'application/json', ...((options && options.headers) || {}) },
64
- }
65
- let res
66
- try {
67
- res = await fetch(BASE + path, init)
68
- } catch (error) {
69
- // 前缀失效(这一代被新实例接管并释放了):重新探一次再试,还不行就把错抛出去
70
- if (retried) throw error
71
- await discoverBase()
72
- return call(path, options, true)
73
- }
74
- // 旧前缀被释放后宿主会 404:同样重探一次
75
- if (res.status === 404 && !retried) {
76
- await discoverBase()
77
- return call(path, options, true)
78
- }
79
- // 304:内容没变(服务端带 ETag)。不是错误,也没有正文。
80
- if (res.status === 304) {
81
- const etag = res.headers && res.headers.get ? res.headers.get('etag') : null
82
- if (etag) stateEtag = etag
83
- return { notModified: true }
84
- }
85
- const freshEtag = res.headers && res.headers.get ? res.headers.get('etag') : null
86
- if (freshEtag && path.startsWith('/state')) stateEtag = freshEtag
87
- const text = await res.text()
88
- let body = null
89
- try { body = text ? JSON.parse(text) : null } catch { body = { raw: text } }
90
- if (!res.ok) throw new Error((body && body.error) || ('HTTP ' + res.status))
91
- return body
92
- }
93
-
94
- const S = {
95
- wrap: { padding: '16px 20px', font: '13px/1.5 system-ui, sans-serif', height: '100%', overflow: 'auto' },
96
- title: { fontSize: 15, fontWeight: 600, margin: '0 0 4px' },
97
- sub: { opacity: 0.65, margin: '0 0 14px' },
98
- row: { display: 'grid', gridTemplateColumns: '1.4fr 1fr 70px 1.2fr 1.2fr 70px 112px', gap: 10, padding: '7px 0', borderBottom: '1px solid rgba(128,128,128,.18)' },
99
- head: { fontWeight: 600, opacity: 0.7, borderBottom: '1px solid rgba(128,128,128,.35)' },
100
- mono: { fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 12 },
101
- badgeOn: { color: '#1a7f37' },
102
- badgeOff: { color: '#9a6700' },
103
- err: { color: '#cf222e', fontSize: 12 },
104
- empty: { opacity: 0.6, marginTop: 12 },
105
- foot: { marginTop: 14, opacity: 0.55, fontSize: 12 },
106
- card: { border: '1px solid rgba(128,128,128,.25)', borderRadius: 8, padding: '12px 14px', marginBottom: 14 },
107
- cardTitle: { fontWeight: 600, margin: '0 0 8px' },
108
- field: { display: 'flex', gap: 8, alignItems: 'center', marginBottom: 8, flexWrap: 'wrap' },
109
- label: { minWidth: 72, opacity: 0.75 },
110
- input: { flex: 1, minWidth: 180, padding: '5px 8px', borderRadius: 6, border: '1px solid rgba(128,128,128,.4)', background: 'transparent', color: 'inherit', font: 'inherit' },
111
- button: { padding: '5px 12px', borderRadius: 6, border: '1px solid rgba(128,128,128,.5)', background: 'rgba(128,128,128,.12)', color: 'inherit', cursor: 'pointer' },
112
- tiny: { padding: '2px 8px', fontSize: 11, lineHeight: '16px', borderRadius: 5, border: '1px solid rgba(128,128,128,.45)', background: 'transparent', color: 'inherit', cursor: 'pointer' },
113
- ok: { color: '#1a7f37', fontSize: 12 },
114
- }
115
-
116
- // ── 移植自官方 dsh-superagent 的设计系统(scripts/port-official-ui.mjs 生成)──
117
- // 官方 GUI 的 376 条选择器 / 40KB 样式原样搬过来,类名统一 `dt-` 前缀,不污染宿主。
118
- const PORTED_CSS = "/* Panel layout and local UI controls styled with DSH `--dsw-alias-*` design tokens; one rule per line. */\n.dt-page { box-sizing: border-box; height: 100%; overflow: auto; scrollbar-gutter: stable; scroll-padding: 48px 0 72px; container-type: inline-size; padding: 28px clamp(24px, 4vw, 48px) 0; color: var(--dsw-alias-label-primary); }\n/* Deployment page rendered inside DSH Plugin Manager, which owns scrolling and padding. */\n.dt-embedded { container-type: inline-size; color: var(--dsw-alias-label-primary); }\n/* Disable sticky positioning inside DSH Plugin Manager, where the host container owns scrolling and bottom padding. */\n.dt-embedded .dt-savebar { position: static; }\n.dt-page > .dt-column { max-width: 960px; margin: 0 auto; padding-bottom: 48px; display: flex; flex-direction: column; gap: 24px; }\n.dt-head { position: relative; z-index: 3; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }\n.dt-search { position: relative; width: 240px; max-width: 100%; }\n.dt-search-results { position: absolute; top: calc(100% + 6px); right: 0; width: min(560px, 90cqw); max-height: 60vh; overflow: auto; padding: 8px 16px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 12px; background: var(--dsw-alias-bg-layer-2); box-shadow: var(--dsw-elevation-prominent); z-index: 5; display: flex; flex-direction: column; gap: 8px; }\n.dt-mark { background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 25%, transparent); color: inherit; border-radius: 2px; }\n[data-platform='darwin'] .dt-page .dt-head { padding-top: var(--dsh-frame-top-clearance, 0px); }\n.dt-title { margin: 0; font-size: 15px; line-height: 22px; font-weight: 600; color: var(--dsw-alias-label-secondary); }\n.dt-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }\n.dt-page .dt-tabs { overflow-x: auto; display: flex; gap: 20px; max-width: none; padding: 0; border-radius: 0; background: none; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-segmented { width: 100%; max-width: 420px; box-sizing: border-box; display: inline-grid; gap: 2px; padding: 3px; border-radius: 9px; background: var(--dsw-alias-interactive-bg-hover); }\n.dt-form.dt-block { padding: 16px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 16px; gap: 16px; }\n.dt-block-title { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 16px; line-height: 24px; font-weight: 500; }\n.dt-section { display: flex; flex-direction: column; gap: 8px; min-width: 0; }\n.dt-section-title { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--dsw-alias-label-secondary); }\n.dt-section-name { white-space: nowrap; }\n.dt-count { font-size: 14px; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; font-weight: 400; }\n.dt-hint { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-tertiary); }\n.dt-error { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-state-error-primary); }\n.dt-banner { margin: 0; padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 20px; background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 10%, transparent); overflow-wrap: anywhere; }\n.dt-banner.dt-danger { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent); }\n.dt-list { list-style: none; margin: 0 -8px; padding: 0; display: flex; flex-direction: column; gap: 2px; }\n.dt-row { position: relative; min-width: 0; border-radius: 12px; padding: 10px 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: flex-start; }\n.dt-row.dt-link:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-row-main { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }\n.dt-disclosure-body .dt-row-main { flex-basis: 0; }\n.dt-row-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; line-height: 20px; font-weight: 500; }\n.dt-open { max-width: 100%; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-size: 14px; line-height: 20px; font-weight: 500; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-open::after { content: ''; position: absolute; inset: 0; border-radius: 12px; }\n.dt-open:focus-visible { outline: none; }\n.dt-open-wrap { white-space: normal; }\n.dt-open:focus-visible::after { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-caption); overflow-wrap: anywhere; }\n.dt-row-quote { font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }\n/* Transparent block borders preserve vertical spacing when line clamping clips padding. */\n.dt-banner:is(.dt-clamp, .dt-clamp-8) { padding-block: 0; border-block: 8px solid transparent; }\n.dt-banner-label { font-weight: 500; }\n.dt-banner .dt-md { display: inline; }\n.dt-banner .dt-md > p:first-child { display: inline; }\n.dt-row-buttons { position: relative; z-index: 1; gap: 8px; margin-top: 4px; }\n.dt-row-actions { position: relative; z-index: 1; display: flex; align-items: center; gap: 4px; flex: none; margin-left: auto; font-size: 13px; line-height: 20px; }\n.dt-dot { flex: none; margin-top: 5px; }\n.dt-inline-link { position: relative; z-index: 1; color: var(--dsw-alias-link); text-decoration: none; }\n.dt-inline-link:hover { text-decoration: underline; }\n.dt-textlink { padding: 0; border: 0; background: none; font: inherit; color: var(--dsw-alias-link); cursor: pointer; text-align: left; }\n.dt-textlink:hover { text-decoration: underline; }\n.dt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; line-height: 20px; }\n.dt-kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13px; line-height: 20px; }\n.dt-kv dt { color: var(--dsw-alias-label-tertiary); }\n.dt-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }\n.dt-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }\n.dt-event { padding: 12px 0; border-bottom: 0.5px solid var(--dsw-alias-border-l2); display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.dt-event:last-child { border-bottom: 0; }\n.dt-event.dt-highlight { background: var(--dsw-alias-interactive-bg-hover); border-radius: 8px; padding-inline: 8px; margin-inline: -8px; }\n.dt-event-text { margin: 0; font-size: 13px; line-height: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }\n.dt-event-actor { font-weight: 500; color: var(--dsw-alias-label-secondary); }\n.dt-event-quiet .dt-event-text { color: var(--dsw-alias-label-tertiary); }\n.dt-flow { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n.dt-clamp-8 { display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }\n.dt-more { align-self: flex-start; font-size: 12px; }\n.dt-reveal { opacity: 0; }\n.dt-event:hover .dt-reveal, .dt-reveal:focus-visible { opacity: 1; }\n@media (hover: none) {\n .dt-reveal { opacity: 1; }\n}\n.dt-event-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n.dt-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }\n.dt-filters .dt-search { margin-left: auto; }\n.dt-form { display: flex; flex-direction: column; gap: 24px; }\n.dt-fieldset { display: flex; flex-direction: column; gap: inherit; min-width: 0; margin: 0; padding: 0; border: 0; }\n.dt-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 20px; min-width: 0; }\n.dt-field small { color: var(--dsw-alias-label-caption); font-size: 12px; }\n.dt-textarea { box-sizing: border-box; width: 100%; min-width: 0; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1, transparent); resize: vertical; }\n.dt-select { box-sizing: border-box; width: 100%; min-width: 0; height: 32px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: 8px; padding: 0 28px 0 8px; text-overflow: ellipsis; font: inherit; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1, transparent); }\n.dt-textarea:focus-visible, .dt-select:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }\n.dt-mono { font-family: var(--ds-font-family-code, Menlo, monospace); font-size: 12px; overflow-wrap: anywhere; }\n.dt-detail { margin-top: 2px; color: var(--dsw-alias-label-secondary); }\n.dt-savebar .dt-error { white-space: pre-line; }\n.dt-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 36px; font-size: 13px; }\n.dt-subhead-actions { display: inline-flex; align-items: center; gap: 4px; }\n.dt-btn-busy .dt-btn-icon svg { animation: dt-spin 1s linear infinite; }\n.dt-subhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n.dt-rules, .dt-changes { list-style: none; margin: 0; padding: 0; }\n.dt-field-head { display: inline-flex; align-items: center; gap: 4px; color: var(--dsw-alias-label-secondary); }\n.dt-info { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; padding: 0; border: 0; background: none; color: var(--dsw-alias-label-caption); cursor: help; }\n.dt-info:hover, .dt-info:focus-visible { color: var(--dsw-alias-label-secondary); }\n.dt-info:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; border-radius: 50%; }\n.dt-tooltip { position: fixed; z-index: 1100; width: max-content; max-width: min(320px, calc(100vw - 24px)); padding: 3px 7px; border-radius: 8px; background: var(--dsw-alias-tooltip-bg); color: var(--dsw-static-neutral-bluish-00); font-size: 13px; line-height: 20px; overflow-wrap: break-word; pointer-events: none; animation: dt-tooltip-in 150ms ease-in-out; }\n@keyframes dt-tooltip-in { from { opacity: 0; } }\n.dt-rules { border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-rule { display: flex; align-items: flex-start; gap: 12px; padding: 6px 0; border-bottom: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-rule > :first-child { flex: 1; min-width: 0; }\n.dt-rule-preview { flex: 1; min-width: 0; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--dsw-alias-label-caption); }\n.dt-rule-switch { margin-top: 2px; flex: none; }\n.dt-rule-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dsw-alias-label-caption); }\n.dt-rule-dot[data-enabled] { background: var(--dsw-alias-brand-primary); }\n.dt-rule-body { display: flex; flex-direction: column; gap: 12px; padding: 8px 0 8px 28px; }\n.dt-model { display: flex; flex-direction: column; gap: 6px; }\n.dt-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }\n.dt-changes { display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 20px; }\n.dt-changes li::before { content: '· '; color: var(--dsw-alias-label-caption); }\n.dt-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }\n.dt-modal.dt-glossary-modal { width: min(680px, 100%); }\n.dt-nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 32px; padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; line-height: 20px; text-align: left; cursor: pointer; }\n.dt-nav-item:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-nav-item[aria-current='true'] { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); font-weight: 500; }\n.dt-nav-item:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }\n.dt-changed-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-brand-primary); flex: none; }\n.dt-add-skill { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-prompt-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }\n.dt-editor { min-height: 360px; }\n.dt-inline-select { width: auto; }\n.dt-preview-part { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 2px 12px; border-left: 2px solid var(--dsw-alias-border-l3); }\n.dt-preview-head { font-size: 13px; line-height: 20px; display: flex; align-items: baseline; gap: 8px; }\ndiv.dt-preview-head { color: var(--dsw-alias-label-secondary); }\n.dt-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 16px; min-width: 0; }\n.dt-card-head { display: flex; align-items: center; gap: 12px; min-height: 28px; }\n.dt-card-head .dt-row-main { flex: 1 1 0; min-width: 64px; }\n.dt-card-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-row-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; }\n.dt-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }\n.dt-rows-item { display: grid; grid-template-columns: repeat(var(--dt-columns), minmax(0, 1fr)) auto; gap: 8px; align-items: center; }\n.dt-filter-gap { flex: 1; }\n.dt-page-head { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }\n.dt-page-head > .dt-btn { margin-left: -10px; }\n.dt-page-title { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; width: 100%; }\n.dt-page-title h2 { margin: 0; flex: 1 1 auto; min-width: 0; font-size: 20px; line-height: 28px; font-weight: 500; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }\n.dt-status-line { margin-top: -16px; }\n.dt-plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; line-height: 20px; }\n.dt-details { display: flex; flex-direction: column; gap: 2px; border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 8px; }\n.dt-danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 16px; border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-danger-zone .dt-btn { color: var(--dsw-alias-state-error-primary); }\n.dt-md { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }\n.dt-md p, .dt-md ul, .dt-md ol { margin: 0; }\n.dt-md ul, .dt-md ol { padding-left: 20px; display: flex; flex-direction: column; gap: 2px; }\n.dt-md-heading { font-weight: 500; }\n.dt-code { font-family: var(--ds-font-family-code, Menlo, monospace); font-size: 12px; padding: 0 4px; border-radius: 4px; background: var(--dsw-alias-bg-module-platform); }\n.dt-dot-wrap { display: inline-flex; flex: none; }\n.dt-search-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.dt-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }\n.dt-legend-title { margin: 16px 0 6px; font-size: 13px; color: var(--dsw-alias-label-tertiary); }\n.dt-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }\n.dt-legend li { display: flex; align-items: center; gap: 6px; }\n.dt-legend .dt-dot { margin-top: 0; }\n.dt-savebar { position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 12px 0; background: var(--dsw-alias-bg-base, var(--dsw-alias-bg-layer-1)); border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-savebar .dt-hint { margin-right: auto; }\n.dt-card > .dt-savebar, .dt-block > .dt-savebar { margin: 0 -16px -16px; padding: 12px 16px; border-radius: 0 0 16px 16px; }\n.dt-glossary { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 20px; }\n.dt-glossary th, .dt-glossary td { text-align: left; padding: 6px 8px; border-bottom: 0.5px solid var(--dsw-alias-border-l2); vertical-align: top; }\n.dt-glossary th { color: var(--dsw-alias-label-tertiary); font-weight: 400; }\n.dt-glossary th.dt-glossary-group { color: var(--dsw-alias-label-secondary); font-weight: 600; padding-top: 14px; }\n.dt-glossary th:nth-child(-n+2), .dt-glossary td:nth-child(-n+2) { white-space: nowrap; }\n.dt-values { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 16px 0 0; font-size: 13px; }\n.dt-values dt { color: var(--dsw-alias-label-tertiary); }\n.dt-values dd { margin: 0; }\n.dt-pre { margin: 0; padding: 12px; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); font-family: var(--ds-font-family-code, Menlo, monospace); font-size: 12px; line-height: 18px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow: auto; }\n.dt-pre ins { background: color-mix(in srgb, var(--dsw-alias-state-success-primary, green) 18%, transparent); text-decoration: none; }\n.dt-pre del { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 18%, transparent); text-decoration: none; }\n.dt-prompt { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; align-items: start; }\n.dt-prompt-nav { display: flex; flex-direction: column; gap: 2px; }\n.dt-prompt-nav button { justify-content: flex-start; }\n.dt-disclosure-body { padding: 8px 0 8px 28px; display: flex; flex-direction: column; gap: 8px; }\n@container (max-width: 640px) {\n .dt-tab { padding: 0 8px; font-size: 13px; }\n .dt-segment { padding: 0 10px; }\n .dt-head { align-items: center; }\n .dt-search-results { right: auto; left: 0; width: 100%; }\n .dt-page-title h2 { font-size: 17px; line-height: 24px; }\n .dt-status-line { margin-top: -12px; }\n .dt-page .dt-tabs { display: flex; flex-wrap: nowrap; scrollbar-width: thin; }\n .dt-page .dt-tab { flex: none; }\n .dt-page .dt-tabs[data-more='end'] { mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }\n .dt-page .dt-tabs[data-more='start'] { mask-image: linear-gradient(to right, transparent, #000 40px); }\n .dt-page .dt-tabs[data-more='both'] { mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }\n .dt-kv { grid-template-columns: 1fr; gap: 2px; }\n .dt-grid3, .dt-prompt { grid-template-columns: 1fr; }\n .dt-search { width: 100%; }\n .dt-filters .dt-search { margin-left: 0; }\n}\n/* Local UI primitive styles (see controls.tsx). */\n.dt-btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: none; border-radius: 18px; cursor: pointer; font: inherit; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); background: transparent; padding: 0 14px; white-space: nowrap; }\n.dt-btn:disabled { cursor: not-allowed; opacity: 0.4; }\n.dt-btn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-btn-md { height: 36px; }\n.dt-btn-sm { height: 28px; font-size: 12px; line-height: 18px; padding: 0 10px; border-radius: 14px; }\n.dt-btn-primary { background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground); }\n.dt-btn-primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }\n.dt-btn-ghost:hover:not(:disabled), .dt-btn-outline:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-btn-ghost:active:not(:disabled) { background: var(--dsw-alias-interactive-bg-active); }\n.dt-btn-outline { border: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-btn-icon { display: inline-flex; width: 16px; height: 16px; align-items: center; justify-content: center; }\n.dt-tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 1px 8px; font-size: 11px; line-height: 17px; font-weight: 500; white-space: nowrap; }\n.dt-tag[data-tone='outline'] { border: 0.5px solid var(--dsw-alias-border-l4); color: var(--dsw-alias-label-tertiary); }\n.dt-tag[data-tone='neutral'] { background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); }\n.dt-tag[data-tone='quiet'] { color: var(--dsw-alias-label-tertiary); }\n.dt-tag[data-tone='success'] { background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 10%, transparent); color: var(--dsw-alias-state-success-primary); }\n.dt-tag[data-tone='info'] { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 10%, transparent); color: var(--dsw-alias-state-business-primary); }\n.dt-tag[data-tone='warning'] { background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 12%, transparent); color: var(--dsw-alias-state-warn-primary); }\n.dt-tag[data-tone='danger'] { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent); color: var(--dsw-alias-state-error-primary); }\n.dt-pill { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border: none; border-radius: 12px; font: inherit; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-2); cursor: pointer; }\n.dt-pill:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-pill-active, .dt-pill-active:hover { color: var(--dsw-alias-label-primary); background: var(--dsw-alias-button-ghost-active-fill); box-shadow: inset 0 0 0 1px var(--dsw-alias-button-ghost-active-border); }\n.dt-tabs { display: grid; padding: 4px; border-radius: 12px; background: var(--dsw-alias-bg-module-platform); }\n.dt-tab { box-sizing: border-box; height: 34px; padding: 0 12px; border: 0.5px solid transparent; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 14px; line-height: 20px; white-space: nowrap; cursor: pointer; transition: color 180ms ease, background 180ms ease; }\n.dt-tab:hover { color: var(--dsw-alias-label-primary); }\n.dt-tab[aria-selected='true'] { color: var(--dsw-alias-label-primary); font-weight: 600; background: var(--dsw-alias-bg-layer-3); border-color: var(--dsw-alias-border-l3); }\n.dt-tab:focus-visible { outline: none; text-decoration: underline; text-underline-offset: 4px; }\n.dt-segment { height: 28px; padding: 0 16px; border: 0; border-radius: 7px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; line-height: 20px; font-weight: 500; white-space: nowrap; cursor: pointer; transition: color 120ms ease, background 160ms ease; }\n.dt-segment:hover:not(:disabled), .dt-segment[aria-selected='true'] { color: var(--dsw-alias-label-primary); }\n.dt-segment[aria-selected='true'] { background: var(--dsw-alias-bg-layer-1); box-shadow: var(--dsw-elevation-soft); }\n.dt-segment:disabled { cursor: default; opacity: 0.4; }\n.dt-segment:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }\n.dt-input { box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; height: 32px; min-width: 0; padding: 0 8px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: 8px; background: var(--dsw-alias-bg-layer-1); }\n.dt-input:focus-within { border-color: var(--dsw-alias-brand-primary); }\n.dt-input-icon { display: inline-flex; width: 16px; height: 16px; align-items: center; justify-content: center; color: var(--dsw-alias-label-tertiary); }\n.dt-input input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font: inherit; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); }\n.dt-input input::placeholder { color: var(--dsw-alias-label-dimmed); }\n.dt-input input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }\n.dt-field .dt-input, .dt-search .dt-input, .dt-add-skill .dt-input { display: flex; width: 100%; }\n.dt-switch { box-sizing: border-box; flex: 0 0 auto; width: 36px; height: 20px; padding: 2px; border: 0; border-radius: 10px; background: var(--dsw-alias-border-l3); cursor: pointer; }\n.dt-switch[aria-checked='true'] { background: var(--dsw-alias-brand-primary); }\n.dt-switch:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-switch-thumb { display: block; width: 16px; height: 16px; border-radius: 50%; background: var(--dsw-alias-label-primary-foreground); transition: transform 120ms ease; }\n.dt-switch[aria-checked='true'] .dt-switch-thumb { transform: translateX(16px); }\n.dt-state-dot { position: relative; display: inline-block; flex: none; width: 10px; height: 10px; color: var(--dsw-alias-state-idle-primary); }\n.dt-state-dot::after { content: ''; position: absolute; inset: 20%; border-radius: 50%; background: currentColor; }\n.dt-state-dot[data-state='done'] { color: var(--dsw-alias-state-success-primary); }\n.dt-state-dot[data-state='warning'] { color: var(--dsw-alias-state-warn-primary); }\n.dt-state-dot[data-state='error'] { color: var(--dsw-alias-state-error-primary); }\n.dt-spinner { flex: none; color: var(--dsw-alias-label-tertiary); }\n.dt-spinner g { transform-origin: center; animation: dt-spin 1.5s linear infinite; }\n.dt-spinner circle { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.dt-spinner circle:first-child { opacity: 0.25; }\n.dt-spinner circle:last-child { stroke-dasharray: 18 150; }\n@keyframes dt-spin { to { transform: rotate(360deg); } }\n.dt-disclosure-row { display: flex; align-items: center; gap: 4px; min-height: 28px; min-width: 0; border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n.dt-disclosure-row:hover { color: var(--dsw-alias-label-primary); }\n.dt-disclosure-row:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-disclosure-lead { position: relative; display: inline-flex; flex: none; width: 24px; height: 24px; align-items: center; justify-content: center; }\n.dt-disclosure-icon { display: inline-flex; align-items: center; justify-content: center; }\n.dt-disclosure-chevron { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }\n.dt-disclosure-row:hover .dt-disclosure-icon, .dt-disclosure[data-open] .dt-disclosure-icon { visibility: hidden; }\n.dt-disclosure-row:hover .dt-disclosure-chevron, .dt-disclosure[data-open] .dt-disclosure-chevron { display: inline-flex; }\n.dt-disclosure-title { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-modal-root { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: max(24px, var(--dsh-frame-top-clearance, 24px)) 24px; }\n.dt-modal-mask { position: absolute; inset: 0; background: var(--dsw-alias-bg-mask-1); backdrop-filter: var(--dsw-mask-blur); }\n.dt-modal { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 20px; width: min(380px, 100%); max-height: 100%; padding: 0 0 24px; overflow: hidden; border-radius: 24px; background: var(--dsw-alias-bg-layer-2); box-shadow: var(--dsw-elevation-prominent); color: var(--dsw-alias-label-primary); outline: none; }\n.dt-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 22px 14px 0 24px; }\n.dt-modal-header h2 { margin: 0; font-size: 16px; line-height: 24px; font-weight: 500; }\n.dt-modal-close { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: none; border-radius: 8px; background: transparent; cursor: pointer; color: var(--dsw-alias-label-secondary); }\n.dt-modal-close:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-modal-description { margin: -8px 0 0; padding: 0 24px; font-size: 14px; line-height: 22px; }\n.dt-modal-body { min-width: 0; min-height: 0; overflow: auto; padding: 0 24px; }\n.dt-modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 24px; }\n.dt-toast { position: fixed; top: 40px; left: 50%; z-index: 1100; pointer-events: none; width: max-content; max-width: min(640px, calc(100vw - 48px)); padding: 12px 16px; border-radius: 14px; background: var(--dsw-alias-toast-bg); color: var(--dsw-static-neutral-bluish-00); font-size: 14px; line-height: 22px; box-shadow: var(--dsw-shadow-lv3); transform: translateX(-50%); animation: dt-toast-in 160ms ease-out, dt-toast-fade 1000ms ease var(--dt-toast-hold, 3000ms) forwards; }\n@keyframes dt-toast-in { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }\n@keyframes dt-toast-fade { to { opacity: 0; visibility: hidden; } }\n@media (prefers-reduced-motion: reduce) {\n .dt-tab, .dt-segment, .dt-switch-thumb, .dt-spinner g, .dt-btn-busy .dt-btn-icon svg, .dt-tooltip { transition: none; animation: none; }\n .dt-toast { animation: dt-toast-fade 1000ms ease var(--dt-toast-hold, 3000ms) forwards; }\n}\n.dt-page .dt-tab { height: 34px; padding: 0 2px; border: 0; border-radius: 0; color: var(--dsw-alias-label-tertiary); font-size: 14px; }\n.dt-page .dt-tab[aria-selected='true'] { background: none; color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: inset 0 -1.5px 0 var(--dsw-alias-label-primary); }\n.dt-status-head { display: flex; align-items: center; gap: 8px; }\n.dt-status-title { margin: 0; flex: 1; display: flex; align-items: center; gap: 4px; font-size: 15px; line-height: 22px; font-weight: 600; }\n.dt-status-text { margin-left: auto; flex: none; font-size: 12px; font-weight: 400; color: var(--dsw-alias-label-secondary); }\n.dt-status-line .dt-status-text { margin-left: 0; }\n.dt-status-text[data-state='warning'] { color: var(--dsw-alias-state-warn-primary); }\n.dt-status-text[data-state='error'] { color: var(--dsw-alias-state-error-primary); }\n.dt-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.dt-lv { white-space: nowrap; }\n.dt-lv-label { color: var(--dsw-alias-label-caption); }\n.dt-lv-value { color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }\n.dt-chip { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 6px; overflow: hidden; font-size: 11px; line-height: 18px; color: var(--dsw-alias-label-secondary); }\n.dt-chip-source { padding: 0 6px; color: var(--dsw-alias-label-tertiary); background: var(--dsw-alias-bg-module-platform); }\n.dt-chip-fact { padding: 0 6px; border-left: 0.5px solid var(--dsw-alias-border-l3); white-space: nowrap; }\n.dt-chip-label { margin-right: 4px; color: var(--dsw-alias-label-caption); }\n.dt-chip-link { position: relative; z-index: 1; text-decoration: none; cursor: pointer; transition: border-color 120ms ease; }\n.dt-chip-link:hover { border-color: var(--dsw-alias-brand-primary); }\n.dt-chip-link:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }\n.dt-chip-open { display: inline-flex; align-items: center; padding: 0 5px; border-left: 0.5px solid var(--dsw-alias-border-l3); color: var(--dsw-alias-brand-primary); }\n.dt-chip-problem, .dt-chip-problem .dt-chip-label { color: var(--dsw-alias-state-error-primary); }\n.dt-cards { gap: 8px; }\n.dt-att .dt-inline-link { font-size: 13px; font-weight: 500; }\n.dt-list > .dt-att { margin: 2px 8px; }\n.dt-att { padding: 10px 12px 10px 16px; border: 0; border-radius: 0; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-att::before { content: ''; position: absolute; left: 6px; top: 10px; bottom: 10px; width: 2px; border-radius: 1px; background: var(--dsw-alias-state-warn-primary); opacity: 0.7; }\n.dt-att-error::before { background: var(--dsw-alias-state-error-primary); }\n.dt-att-what { font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-state-warn-primary); }\n.dt-att-error .dt-att-what, .dt-att-error .dt-att-what .dt-open { color: var(--dsw-alias-state-error-primary); }\n.dt-stats { display: flex; flex-wrap: wrap; gap: 6px 20px; }\n.dt-stat { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--dsw-alias-label-caption); }\n.dt-stat-value { font-size: 14px; font-weight: 500; color: var(--dsw-alias-label-primary); font-variant-numeric: tabular-nums; }\n.dt-more-link { font-size: 12px; font-weight: 400; }\n.dt-settings { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 24px; align-items: start; }\n.dt-settings-nav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }\n.dt-settings-link { padding: 6px 10px; border: 0; border-radius: 8px; background: none; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }\n.dt-settings-link:hover { color: var(--dsw-alias-label-primary); }\n.dt-settings-link[aria-current='page'] { background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-primary); font-weight: 500; }\n.dt-settings-link[data-stage] + .dt-settings-link:not([data-stage]) { margin-top: 10px; }\n.dt-settings-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }\n.dt-settings-title { margin: 0; font-size: 15px; line-height: 22px; font-weight: 600; }\n.dt-subtabs { display: flex; gap: 16px; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-subtab { padding: 0 0 6px; border: 0; background: none; color: var(--dsw-alias-label-tertiary); font: inherit; font-size: 13px; cursor: pointer; }\n.dt-subtab[aria-selected='true'] { color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: inset 0 -1.5px 0 var(--dsw-alias-label-primary); }\n.dt-part { display: flex; flex-direction: column; gap: 12px; }\n.dt-rows-summary { text-align: left; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }\n.dt-table { width: 100%; border-collapse: collapse; font-size: 12px; line-height: 18px; }\n.dt-table th { text-align: left; font-weight: 400; color: var(--dsw-alias-label-caption); padding: 2px 8px 2px 0; }\n.dt-table td { padding: 4px 8px 4px 0; border-top: 0.5px solid var(--dsw-alias-border-l3); vertical-align: top; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }\n@container (max-width: 640px) {\n .dt-settings { grid-template-columns: 1fr; gap: 12px; }\n .dt-settings-nav { position: static; flex-direction: row; flex-wrap: wrap; }\n .dt-settings-link[data-stage] + .dt-settings-link:not([data-stage]) { margin-top: 0; }\n .dt-page .dt-tabs { gap: 14px; }\n}\n.dt-list > .dt-ticket { display: grid; grid-template-columns: 112px minmax(0, 1fr); column-gap: 12px; align-items: start; margin: 0; padding: 12px 8px 12px 18px; border-radius: 0; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-list > .dt-ticket[data-state]::before { content: ''; position: absolute; left: 6px; top: 12px; bottom: 12px; width: 2px; border-radius: 1px; background: var(--dsw-alias-state-warn-primary); opacity: 0.7; }\n.dt-list > .dt-ticket[data-state='error']::before { background: var(--dsw-alias-state-error-primary); }\n.dt-ticket-stage { align-self: stretch; padding-top: 1px; border-right: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-ticket-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n.dt-ticket-body .dt-row-title .dt-open { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-ticket-meta { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }\n.dt-ticket-meta .dt-chip { flex: none; }\n.dt-ticket-note { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--dsw-alias-label-primary); }\n.dt-ticket-note-error { color: var(--dsw-alias-state-error-primary); }\n.dt-ticket-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; min-height: 30px; margin-top: 2px; }\n/* Pass pointer events through action containers to the row link, keeping only child controls interactive. */\n.dt-ticket-actions, .dt-row-buttons, .dt-row-actions { pointer-events: none; }\n.dt-ticket-actions > *, .dt-row-buttons > *, .dt-row-actions > * { pointer-events: auto; }\n.dt-line { min-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.dt-row-meta.dt-line { flex-wrap: nowrap; }\n.dt-line-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-error-text { color: var(--dsw-alias-state-error-primary); }\n.dt-stage { display: inline-flex; align-items: flex-start; gap: 5px; font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }\n.dt-stage svg { flex: none; margin-top: 2px; }\n.dt-stage[data-state='warning'] { color: var(--dsw-alias-state-warn-primary); }\n.dt-stage[data-state='error'] { color: var(--dsw-alias-state-error-primary); }\n.dt-stage[data-state='ongoing'] { color: var(--dsw-alias-state-business-primary); }\n.dt-icon-link { display: inline-flex; align-items: center; gap: 4px; }\na.dt-btn, a.dt-btn:hover { text-decoration: none; }\n.dt-section-icon { display: inline-flex; align-self: center; color: var(--dsw-alias-label-tertiary); }\n.dt-trigger-link { display: flex; flex-direction: column; gap: 2px; width: 100%; margin: -4px 0 -4px -8px; padding: 4px 8px; border: 0; border-radius: 8px; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }\n.dt-trigger-link:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-trigger-link:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }\n.dt-trigger-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }\n.dt-kv-stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.dt-banner-actions { margin-top: 6px; }\n@container (max-width: 640px) {\n .dt-list > .dt-ticket { grid-template-columns: 1fr; row-gap: 4px; }\n .dt-ticket-stage { border-right: 0; }\n}\n.dt-nav-group { margin: 10px 10px 2px; font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-secondary); }\n.dt-nav-group:first-child { margin-top: 0; }\n.dt-prompt-nav .dt-nav-item { flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; }\n.dt-nav-item > span { display: inline-flex; align-items: center; gap: 6px; }\n.dt-nav-item small { font-size: 12px; line-height: 18px; font-weight: 400; color: var(--dsw-alias-label-caption); }\n.dt-preview-part[data-editable] { border-left-color: var(--dsw-alias-brand-primary); }\n.dt-preview-head b { font-weight: 500; }\n.dt-preview-head > span { font-size: 12px; color: var(--dsw-alias-label-caption); }\n.dt-changed-tag { margin-left: 6px; padding: 0 5px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 4px; font-size: 11px; line-height: 16px; font-weight: 400; color: var(--dsw-alias-label-secondary); }\n.dt-updated-tag { border-color: var(--dsw-alias-state-warn-primary); color: var(--dsw-alias-state-warn-primary); }\n.dt-default-updated { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 2px 12px; border-left: 2px solid var(--dsw-alias-state-warn-primary); }\n.dt-diff-fold { color: var(--dsw-alias-label-caption); font-style: italic; }\n.dt-compare { margin-left: auto; }\n.dt-admission th { white-space: nowrap; }\n.dt-admission thead tr:first-child th:not(:first-child) { color: var(--dsw-alias-label-secondary); font-weight: 500; }\n.dt-admission td { vertical-align: middle; }\n.dt-admission-scope { color: var(--dsw-alias-label-primary); font-size: 13px; }\n.dt-admission-scope small { display: block; font-size: 11px; color: var(--dsw-alias-label-caption); }\n.dt-admission-na { color: var(--dsw-alias-label-caption); }\n.dt-admission-cell { display: flex; align-items: center; gap: 4px; }\n.dt-admission-cell .dt-select { flex: 1; min-width: 0; }\n.dt-admission-slot { display: inline-flex; flex: none; width: 16px; }\n.dt-info-warn { color: var(--dsw-alias-state-warn-primary); }\n.dt-field-segmented { max-width: 240px; }\n";
119
-
120
- /** 把移植过来的样式挂到 document 上,只挂一次。 */
121
- /**
122
- * 悬浮面板只保留「定位」用 inline style,视觉全部走 dt-* + token。
123
- * 以前这里是一整套自成体系的 inline style,和原生界面放一起能看出断层。
124
- */
125
- const DOCK_CSS = `
126
- .sa-dock-panel { box-shadow: var(--dsw-elevation-prominent); padding: 10px 12px 8px; font-size: 12px; line-height: 1.55; }
127
- .sa-dock-row { padding: 6px 0; }
128
- .sa-dock-row + .sa-dock-row { border-top: 0.5px solid var(--dsw-alias-border-l3, currentColor); }
129
- .sa-dock-foot { margin-top: 8px; padding-top: 8px; border-top: 0.5px solid var(--dsw-alias-border-l3, currentColor); color: var(--dsw-alias-label-caption, inherit); }
130
- .sa-mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
131
- `
132
-
133
- function ensurePortedCss() {
134
- try {
135
- if (document.getElementById('dsh-zhuli-ported-css')) return
136
- const style = document.createElement('style')
137
- style.id = 'dsh-zhuli-ported-css'
138
- style.textContent = PORTED_CSS + DOCK_CSS
139
- document.head.appendChild(style)
140
- } catch {}
141
- }
142
-
143
- // ── 官方 GUI 原语(移植自 dsh-superagent 的 src/client/controls.tsx + widgets.tsx)──
144
- // 类名沿用官方 `dt-*`,样式由上面的 PORTED_CSS 提供,所以视觉与官方一致。
145
- const ICON_PATHS = {
146
- 'chevron-left': 'M15 5l-7 7 7 7',
147
- 'chevron-right': 'M9 5l7 7-7 7',
148
- 'chevron-down': 'M5 9l7 7 7-7',
149
- search: 'M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4',
150
- question: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6v.6M12 17h.01',
151
- plus: 'M12 5v14M5 12h14',
152
- trash: 'M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3',
153
- refresh: 'M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5',
154
- clock: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7v5l3 2',
155
- history: 'M3.5 12a8.5 8.5 0 1 0 2.5-6M3.5 4v4h4M12 8v4l3 2',
156
- shield: 'M12 3l7 3v6c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6z',
157
- decision: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM8.5 12.5l2.5 2.5 4.5-5',
158
- message: 'M5 5h14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H10l-5 4V6a1 1 0 0 1 1-1z',
159
- inbox: 'M4 13l2.5-8h11l2.5 8M4 13v6h16v-6M4 13h5l1 2h4l1-2h5',
160
- hash: 'M10 4L8 20M16 4l-2 16M5 9h15M4 15h15',
161
- filter: 'M4 5h16l-6 7.5V18l-4 2v-7.5z',
162
- user: 'M12 4a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM4 20c1.5-3.5 4.5-5 8-5s6.5 1.5 8 5',
163
- close: 'M6 6l12 12M18 6L6 18',
164
- settings: 'M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4',
165
- external: 'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5',
166
- session: 'M4 5h16v14H4zM8 10l3 2-3 2M13 15h3',
167
- stop: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM9.5 9.5h5v5h-5z',
168
- pause: 'M9 6v12M15 6v12',
169
- play: 'M8 5l11 7-11 7z',
170
- copy: 'M9 9h10v11H9zM5 15V4h10',
171
- alert: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7.5v5.5M12 16.5h.01',
172
- running: 'M12 3a9 9 0 1 0 9 9',
173
- blocked: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM5.6 5.6l12.8 12.8',
174
- queue: 'M4 6h16M4 12h16M4 18h10',
175
- }
176
-
177
- function Icon({ name, size = 16 }) {
178
- return h('svg', {
179
- width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
180
- stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
181
- 'aria-hidden': 'true',
182
- }, h('path', { d: ICON_PATHS[name] || ICON_PATHS.question }))
183
- }
184
-
185
- const cx = (...names) => names.filter(Boolean).join(' ')
186
-
187
- function Btn({ variant = 'ghost', size = 'md', icon, children, className, ...rest }) {
188
- // className 必须最后合并:之前 ...rest 直接覆盖,导致 ConfirmBtn 的删除按钮丢掉全部样式
189
- return h('button', { type: 'button', ...rest, className: cx('dt-btn', 'dt-btn-' + variant, 'dt-btn-' + size, className) },
190
- icon !== undefined ? h('span', { className: 'dt-btn-icon' }, icon) : null,
191
- children)
192
- }
193
-
194
- function Tag({ tone = 'outline', title, children }) {
195
- return h('span', { className: 'dt-tag', 'data-tone': tone, title }, children)
196
- }
197
-
198
- /** 页级 tab 条:点当前页会再发一次 onChange(回调里可重置到根部)。 */
199
- function SegTabs({ items, value, onChange, label }) {
200
- const buttons = useRef({})
201
- const walk = (event) => {
202
- if (items.length === 0) return
203
- const values = items.map((item) => item.value)
204
- const index = values.indexOf(value)
205
- const target = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: values.length - 1 }[event.key]
206
- if (target === undefined) return
207
- event.preventDefault()
208
- const next = values[(target + values.length) % values.length]
209
- if (next !== value) {
210
- onChange(next)
211
- // 焦点跟随:旧页签变成 tabIndex=-1 后,键盘用户会掉出 tablist
212
- const nextButton = buttons.current[next]
213
- if (nextButton && typeof nextButton.focus === 'function') nextButton.focus()
214
- }
215
- }
216
- return h('div', {
217
- role: 'tablist', 'aria-label': label, className: 'dt-tabs', onKeyDown: walk,
218
- style: { gridTemplateColumns: 'repeat(' + items.length + ', minmax(0, 1fr))' },
219
- }, items.map((item) => h('button', {
220
- key: item.value, type: 'button', role: 'tab',
221
- ref: (node) => { buttons.current[item.value] = node },
222
- 'aria-selected': item.value === value,
223
- tabIndex: item.value === value ? 0 : -1,
224
- className: 'dt-tab',
225
- onClick: () => onChange(item.value),
226
- }, item.label)))
227
- }
228
-
229
- function Input({ icon, ...rest }) {
230
- return h('span', { className: 'dt-input' },
231
- icon !== undefined ? h('span', { className: 'dt-input-icon' }, icon) : null,
232
- h('input', rest))
233
- }
234
-
235
- function Toggle({ checked, onChange, label }) {
236
- return h('button', {
237
- type: 'button', role: 'switch', 'aria-checked': !!checked, 'aria-label': label,
238
- className: 'dt-switch', onClick: () => onChange(!checked),
239
- }, h('span', { className: 'dt-switch-thumb' }))
240
- }
241
-
242
- function StateDot({ state, className }) {
243
- if (state === 'ongoing') {
244
- return h('svg', { className: 'dt-spinner', 'data-state': 'ongoing', width: 14, height: 14, viewBox: '0 0 24 24', 'aria-hidden': 'true' },
245
- h('g', null,
246
- h('circle', { cx: 12, cy: 12, r: 9.5 }),
247
- h('animateTransform', { attributeName: 'transform', type: 'rotate', from: '0 12 12', to: '360 12 12', dur: '1.6s', repeatCount: 'indefinite' })))
248
- }
249
- return h('span', { className: cx('dt-state-dot', className), 'data-state': state, 'aria-hidden': 'true' })
250
- }
251
-
252
- function Dot({ state, label }) {
253
- const dot = h(StateDot, { className: 'dt-dot', state })
254
- if (!label) return dot
255
- return h('span', { className: 'dt-dot-wrap', title: label, role: 'img', 'aria-label': label }, dot)
256
- }
257
-
258
- // 官方 Section 还支持 hint(说明)与 action(右上角动作),我们之前只有 title/count。
259
- function Section({ title, count, hint, action, children }) {
260
- return h('section', { className: 'dt-section' },
261
- title
262
- ? h('div', { className: 'dt-section-title' },
263
- h('span', { className: 'dt-section-name' }, title),
264
- count !== undefined && count !== null ? h('span', { className: 'dt-count' }, String(count)) : null,
265
- action ? h('span', { className: 'dt-subhead-actions' }, action) : null)
266
- : null,
267
- hint ? h(Hint, null, hint) : null,
268
- children)
269
- }
270
-
271
- /**
272
- * 第一次打开面板时的空态:官方那种「不是白屏,而是告诉你下一步做什么」。
273
- * 三步走完就能跑起来 —— 客户不用去翻 README。
274
- */
275
- function Onboarding({ onStart }) {
276
- return h('div', { className: 'dt-card' },
277
- h('div', { className: 'dt-card-head' },
278
- h('span', { className: 'dt-card-title' }, '三步让这个会话开始盯办')),
279
- h('ol', { className: 'dt-plain-list' },
280
- h('li', null, '① 填一个仓库(owner/name,比如 MYCF711/dsh-session-superagent)'),
281
- h('li', null, '② 选间隔(默认 60 秒;建议先设 300 秒,别把 API 打满)'),
282
- h('li', null, '③ 点「添加到当前会话」——之后仓库有动静,这个会话就会被叫醒')),
283
- h('div', { className: 'dt-actions' },
284
- h(Btn, { variant: 'primary', icon: h(Icon, { name: 'plus' }), onClick: onStart }, '去添加第一条')),
285
- h(Hint, null, '想先看看效果?在「触发」页勾上「仅观察」:它只记录本会唤醒哪几条,不会真打扰你。'))
286
- }
287
-
288
- /** 官方 DisclosureRow 的实际用法:默认收起,点开看明细。 */
289
- function CollapsibleList({ title, items }) {
290
- const [open, setOpen] = useState(false)
291
- return h(DisclosureRow, {
292
- title: title + '(' + items.length + ')',
293
- open, onToggle: () => setOpen(!open),
294
- icon: h(Icon, { name: 'question', size: 14 }),
295
- collapsedContent: h('span', { className: 'dt-hint' }, items[0] ? String(items[0]).slice(0, 40) : ''),
296
- },
297
- h('ul', { className: 'dt-plain-list' },
298
- items.map((text, index) => h('li', { key: index }, text))))
299
- }
300
-
301
- /** 官方 Pill:可切换的小胶囊(用于「全部 / 只看失败」这类就地过滤)。 */
302
- function Pill({ active, onClick, children }) {
303
- return h('button', {
304
- type: 'button', className: cx('dt-pill', active && 'dt-pill-active'),
305
- 'aria-pressed': !!active, onClick,
306
- }, children)
307
- }
308
-
309
- /** 官方 SegmentedControl:单选分段(与 SegTabs 的页签语义不同,用于表单内的互斥选择)。 */
310
- function SegmentedControl({ options, value, onChange, label, disabled }) {
311
- return h('div', { className: 'dt-segmented', role: 'radiogroup', 'aria-label': label },
312
- options.map((option) => h('button', {
313
- key: option.value, type: 'button', role: 'radio',
314
- 'aria-checked': value === option.value, 'aria-selected': value === option.value,
315
- className: 'dt-segment', disabled: disabled || option.disabled,
316
- onClick: () => onChange(option.value),
317
- }, option.label)))
318
- }
319
-
320
- /** 官方 DisclosureRow:折叠行的标准写法(Enter / 空格可切换,带 aria-expanded)。 */
321
- function DisclosureRow({ icon, title, open, onToggle, collapsedContent, children }) {
322
- return h('div', { className: 'dt-disclosure', 'data-open': open ? 'true' : undefined },
323
- h('div', {
324
- className: 'dt-disclosure-row', role: 'button', tabIndex: 0, 'aria-expanded': !!open,
325
- onClick: onToggle,
326
- onKeyDown: (event) => {
327
- if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onToggle() }
328
- },
329
- },
330
- h('span', { className: 'dt-disclosure-lead' },
331
- h('span', { className: 'dt-disclosure-icon' }, icon),
332
- h('span', { className: 'dt-disclosure-chevron' }, h(Icon, { name: open ? 'chevron-up' : 'chevron-down' }))),
333
- h('span', { className: 'dt-disclosure-title' }, title),
334
- !open ? collapsedContent : null),
335
- open ? children : null)
336
- }
337
-
338
- /** 官方 InfoTip:点一下出气泡(我们之前只有 dt-info 的样式,没有组件)。 */
339
- function InfoTip({ text, icon = 'question', warn }) {
340
- const [open, setOpen] = useState(false)
341
- return h('span', { style: { position: 'relative', display: 'inline-flex' } },
342
- h('button', {
343
- type: 'button', className: cx('dt-info', warn && 'dt-info-warn'),
344
- 'aria-label': text, 'aria-expanded': open,
345
- onClick: () => setOpen(!open), onBlur: () => setOpen(false),
346
- }, h(Icon, { name: icon, size: 14 })),
347
- open ? h('span', { className: 'dt-tooltip', role: 'tooltip', style: { position: 'absolute', bottom: '130%', left: 0, visibility: 'visible' } }, text) : null)
348
- }
349
-
350
- const Hint = ({ children }) => h('p', { className: 'dt-hint' }, children)
351
-
352
- function KeyValues({ rows }) {
353
- return h('dl', { className: 'dt-kv' },
354
- rows.filter(Boolean).flatMap(([key, value]) => [
355
- h('dt', { key: key + '-k' }, key),
356
- h('dd', { key: key + '-v' }, value),
357
- ]))
358
- }
359
-
360
- // 官方 Modal 的键盘行为:Escape 关闭 + Tab 焦点陷阱 + 关闭后焦点回到触发元素。
361
- // 移植时只搬了样式,行为是后补的(2026-11-02 对官方 controls.tsx 逐行比对时发现)。
362
- const FOCUSABLE = 'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])'
363
- function trapTab(event, dialog) {
364
- const items = [...dialog.querySelectorAll('*')].filter((element) => element.matches(FOCUSABLE))
365
- const first = items[0]
366
- const last = items[items.length - 1]
367
- const active = document.activeElement
368
- const target = event.shiftKey ? last : first
369
- if (!target || !dialog.contains(active) || active === dialog || active === (event.shiftKey ? first : last)) {
370
- event.preventDefault()
371
- target.focus()
372
- }
373
- }
374
-
375
- function Modal({ open, title, children, onClose }) {
376
- const dialog = useRef(null)
377
- const restoreTo = useRef(null)
378
- useEffect(() => {
379
- if (!open || typeof document === 'undefined') return undefined
380
- restoreTo.current = document.activeElement
381
- // 打开后把焦点挪进对话框,否则键盘用户还停在背后的页面上
382
- const timer = setTimeout(() => {
383
- const node = dialog.current
384
- if (!node) return
385
- const first = [...node.querySelectorAll('*')].filter((el) => el.matches(FOCUSABLE))[0]
386
- ;(first || node).focus()
387
- }, 0)
388
- const onKey = (event) => {
389
- if (event.key === 'Escape') { event.preventDefault(); onClose(); return }
390
- if (event.key === 'Tab' && dialog.current) trapTab(event, dialog.current)
391
- }
392
- document.addEventListener('keydown', onKey)
393
- return () => {
394
- clearTimeout(timer)
395
- document.removeEventListener('keydown', onKey)
396
- const back = restoreTo.current
397
- if (back && typeof back.focus === 'function') { try { back.focus() } catch {} }
398
- }
399
- }, [open, onClose])
400
- if (!open) return null
401
- // class 必须与移植来的官方 CSS 对齐:dt-modal-root / dt-modal-mask / dt-modal-header
402
- return h('div', { className: 'dt-modal-root' },
403
- h('div', { className: 'dt-modal-mask', role: 'presentation', onClick: onClose }),
404
- h('div', {
405
- ref: dialog, tabIndex: -1,
406
- className: 'dt-modal', role: 'dialog', 'aria-modal': 'true',
407
- 'aria-label': typeof title === 'string' ? title : undefined,
408
- },
409
- h('div', { className: 'dt-modal-header' },
410
- h('span', { className: 'dt-title' }, title),
411
- h('button', { type: 'button', className: 'dt-modal-close', onClick: onClose, 'aria-label': '关闭' }, h(Icon, { name: 'close' }))),
412
- h('div', { className: 'dt-modal-body' }, children)))
413
- }
414
-
415
- /** 危险操作二次确认:点一次变成「确定吗」,再点才执行。 */
416
- function ConfirmBtn({ label, confirmLabel = '确定执行', onConfirm, variant = 'ghost', icon, size }) {
417
- const [armed, setArmed] = useState(false)
418
- return h(Btn, {
419
- variant,
420
- size,
421
- className: armed ? 'dt-danger' : undefined,
422
- icon,
423
- 'aria-label': armed ? confirmLabel : label,
424
- onClick: () => {
425
- if (!armed) { setArmed(true); return }
426
- setArmed(false)
427
- onConfirm()
428
- },
429
- onBlur: () => setArmed(false),
430
- }, armed ? confirmLabel : label)
431
- }
432
-
433
- const watcherId = (w) => (w && w.id) || String((w && w.repo) || '') + '#' + String((w && w.sessionId) || '')
434
- const short = (value, width = 19) => (typeof value === 'string' && value.length > width ? value.slice(0, width - 1) + '…' : (value ?? '—'))
435
- const when = (iso) => (typeof iso === 'string' ? iso.replace('T', ' ').replace('Z', '').slice(5, 19) : '—')
436
-
437
- // ── orbit badge: session header indicator ──────────────────────────────
438
- // Static geometry, three states: green dot orbiting (watching), amber dot on
439
- // a dashed ring (paused), red dot breathing (error). Icon only — the text
440
- // lives in the native tooltip so it does not compete with the session title.
441
- // ── status orbit: composer-dock indicator ─────────────────────────────
442
- // One ring for the whole machine. Every satellite on the ring is one
443
- // session-level superagent (a live watcher): green = watching, amber =
444
- // paused, red = last poll failed. Icon only — details live in the
445
- // click-through panel, and a native tooltip carries the one-line summary.
446
- /**
447
- * 现在是否落在活跃时段里。支持跨夜(22:00-06:00)。
448
- * 解析不了就返回 null —— 宁可显示「主理中」,也不要乱标。
449
- */
450
- function inWindowNow(hours) {
451
- const match = String(hours || '').match(/^(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})$/)
452
- if (!match) return null
453
- const now = new Date()
454
- const current = now.getHours() * 60 + now.getMinutes()
455
- const from = Number(match[1]) * 60 + Number(match[2])
456
- const to = Number(match[3]) * 60 + Number(match[4])
457
- return from <= to ? current >= from && current < to : current >= from || current < to
458
- }
459
-
460
- function orbitStateOf(w) {
461
- if (!w) return 'paused'
462
- if (w.lastError) return 'error'
463
- if (w.enabled === false) return 'paused'
464
- // 设了活跃时段、而此刻在窗口外:它其实不会唤醒,只是把条目攒着 ——
465
- // 这时候还标「主理中」就是在骗人(2026-11-02 用户截图指出)。
466
- if (w.activeHours && inWindowNow(w.activeHours) === false) return 'dormant'
467
- return 'active'
468
- }
469
-
470
- // 状态色一律走 token(写死 hex 在深色/浅色两套主题里会有一个是错的)
471
- const SAT_COLOR = {
472
- active: 'var(--dsw-alias-state-success-primary)',
473
- paused: 'var(--dsw-alias-state-warn-primary)',
474
- error: 'var(--dsw-alias-state-error-primary)',
475
- dormant: 'var(--dsw-alias-label-caption)',
476
- }
477
- const STATE_TEXT = { active: '主理中', paused: '已暂停', error: '异常', dormant: '时段外' }
478
-
479
- /** 尊重系统的「减少动态效果」设置。 */
480
- const prefersReducedMotion = () => {
481
- try { return window.matchMedia('(prefers-reduced-motion: reduce)').matches } catch { return false }
482
- }
483
-
484
- function OrbitMark(props) {
485
- const watchers = props.watchers || []
486
- const shown = watchers.slice(0, 6)
487
- const states = watchers.map(orbitStateOf)
488
- const anyActive = states.indexOf('active') >= 0
489
- // Zero watchers still draws the ring, just grey: an idle machine should
490
- // read as "nothing being watched", not as "the plugin is broken".
491
- const empty = states.length === 0
492
- const ringColor = empty
493
- ? 'currentColor'
494
- : states.indexOf('error') >= 0
495
- ? SAT_COLOR.error
496
- : anyActive ? SAT_COLOR.active : states.indexOf('dormant') >= 0 ? SAT_COLOR.dormant : SAT_COLOR.paused
497
- const dashed = states.indexOf('paused') >= 0
498
- const still = prefersReducedMotion()
499
-
500
- const dots = shown.map((w, i) => {
501
- const angle = (i / Math.max(shown.length, 1)) * Math.PI * 2 - Math.PI / 2
502
- const state = orbitStateOf(w)
503
- return h('circle', {
504
- key: String(w.repo || '') + '#' + String(w.sessionId || i),
505
- cx: 8 + Math.cos(angle) * 6.1,
506
- cy: 8 + Math.sin(angle) * 6.1,
507
- r: shown.length > 3 ? 1.75 : 2.05,
508
- fill: SAT_COLOR[state],
509
- }, state === 'error' && !still
510
- ? h('animate', { attributeName: 'opacity', values: '1;.3;1', dur: '1.6s', repeatCount: 'indefinite' })
511
- : null)
512
- })
513
-
514
- // 动画用 SMIL 写进 SVG 本身:不依赖注入的 <style>,也不吃 CSP /
515
- // transform-box 的差异;单独存成 .html 就能预览。
516
- const spin = anyActive && !still
517
- ? h('animateTransform', {
518
- attributeName: 'transform', type: 'rotate',
519
- from: '0 8 8', to: '360 8 8', dur: '6s', repeatCount: 'indefinite',
520
- })
521
- : null
522
- const breathe = anyActive && !still
523
- ? h('animate', { attributeName: 'opacity', values: '.95;.45;.95', dur: '2.6s', repeatCount: 'indefinite' })
524
- : null
525
-
526
- return h('svg', {
527
- width: 16, height: 16, viewBox: '0 0 16 16', 'aria-hidden': 'true',
528
- style: { overflow: 'visible' },
529
- },
530
- h('circle', {
531
- cx: 8, cy: 8, r: 6.1, fill: 'none', stroke: ringColor, strokeWidth: 1.1,
532
- strokeDasharray: dashed ? '2.2 1.9' : undefined,
533
- opacity: empty ? 0.38 : 0.9,
534
- }, breathe),
535
- h('g', null, spin, dots))
536
- }
537
-
538
- const notedOnce = new Set()
539
- /** Diagnostics: write once per page load, never on every poll. */
540
- function noteOnce(key, value) {
541
- if (notedOnce.has(key)) return
542
- notedOnce.add(key)
543
- note(key, value)
544
- }
545
-
546
- function note(key, value) {
547
- try { fetch(BASE + '/client-note?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(String(value || ''))).catch(() => {}) } catch {}
548
- }
549
-
550
- /** 8-char session tag. Titles come from the title model and several sessions
551
- * can share one, so every row carries the id suffix to stay unambiguous. */
552
- const sessionTag = (id) => {
553
- const raw = String(id || '')
554
- const core = raw.indexOf('session-') === 0 ? raw.slice(8) : raw
555
- return core.slice(0, 8) || '—'
556
- }
557
-
558
- /** 把 filters 压成一行人话,空配置返回空串。 */
559
- const filterText = (f) => {
560
- if (!f) return ''
561
- const parts = []
562
- if (f.labels && f.labels.length) parts.push('标签: ' + f.labels.join(','))
563
- if (f.ignoreLabels && f.ignoreLabels.length) parts.push('排除: ' + f.ignoreLabels.join(','))
564
- if (f.onlyAssigned) parts.push(f.assignee ? '只看指派给 @' + f.assignee : '只看已指派')
565
- return parts.join(' · ')
566
- }
567
-
568
- /** 只留路径最后两段,面板里放得下。 */
569
- const pathTail = (value) => String(value || '')
570
- .split(String.fromCharCode(92)).join('/')
571
- .split('/').filter(Boolean).slice(-2).join('/')
572
-
573
- /** 隔离执行状态:开着隔离就显示上次用的 worktree。 */
574
- const isolationText = (w) => {
575
- if (!w || !w.isolated) return ''
576
- return '隔离 · ' + (pathTail(w.lastWorktree) || pathTail(w.workdir) || '未建')
577
- }
578
-
579
- /** 最近一次唤醒的结果(面板第二行用)。 */
580
- const historyText = (w) => {
581
- const list = (w && w.history) || []
582
- const last = list[list.length - 1]
583
- if (!last) return ''
584
- const nums = (last.numbers || []).map((n) => '#' + n).join(' ')
585
- return (last.ok ? '上次唤醒 ' : '上次唤醒失败 ') + nums + ' · ' + ageText(last.at)
586
- }
587
-
588
- /** 失败退避中显示剩余秒数,否则空串。 */
589
- const backoffText = (w) => {
590
- if (!w || !w.nextAt) return ''
591
- const left = Date.parse(w.nextAt) - Date.now()
592
- if (!isFinite(left) || left <= 0) return ''
593
- return '退避 ' + Math.ceil(left / 1000) + 's'
594
- }
595
-
596
- const ageText = (iso) => {
597
- if (typeof iso !== 'string') return '—'
598
- const ms = Date.now() - Date.parse(iso)
599
- if (!isFinite(ms) || ms < 0) return '—'
600
- const s = Math.round(ms / 1000)
601
- if (s < 90) return s + ' 秒前'
602
- if (s < 5400) return Math.round(s / 60) + ' 分钟前'
603
- return Math.round(s / 3600) + ' 小时前'
604
- }
605
- const wakeText = (value) => {
606
- if (typeof value !== 'string' || value === '') return '—'
607
- if (value.indexOf('failed') === 0) return '失败'
608
- return ageText(value)
609
- }
610
-
611
- const PANEL_W = 344
612
- const BORDER = '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.22))'
613
-
614
- /** Dock entry: the machine-wide ring plus its click-through detail list. */
615
- /** 把错误拆成「现象」和「建议」:服务端存的是 short +(hint),建议在末尾的括号里。 */
616
- function splitErrorText(text) {
617
- const value = String(text || '')
618
- const match = /([^()]*)\s*$/.exec(value)
619
- if (!match) return { main: value, hint: '' }
620
- return { main: value.slice(0, match.index).trim(), hint: match[0].trim() }
621
- }
622
- function StatusOrbit() {
623
- const [watchers, setWatchers] = useState(null)
624
- const [open, setOpen] = useState(false)
625
- const [anchor, setAnchor] = useState(null)
626
- const btnRef = useRef(null)
627
- const panelRef = useRef(null)
628
-
629
- useEffect(() => {
630
- let alive = true
631
- noteOnce('orbit-mount', 'ok')
632
- const load = async () => {
633
- try {
634
- const body = await call('/state')
635
- if (alive) setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
636
- } catch {
637
- if (alive) setWatchers((prev) => (prev === null ? [] : prev))
638
- }
639
- }
640
- load()
641
- const timer = setInterval(load, POLL_MS)
642
- return () => { alive = false; clearInterval(timer) }
643
- }, [])
644
-
645
- useEffect(() => {
646
- if (!open) return undefined
647
- const onDown = (event) => {
648
- const target = event.target
649
- if (panelRef.current && panelRef.current.contains(target)) return
650
- if (btnRef.current && btnRef.current.contains(target)) return
651
- setOpen(false)
652
- }
653
- const onKey = (event) => { if (event.key === 'Escape') setOpen(false) }
654
- document.addEventListener('mousedown', onDown, true)
655
- document.addEventListener('keydown', onKey, true)
656
- return () => {
657
- document.removeEventListener('mousedown', onDown, true)
658
- document.removeEventListener('keydown', onKey, true)
659
- }
660
- }, [open])
661
-
662
- const list = watchers || []
663
- // Never hide the entry: with nothing being watched it stays as a grey
664
- // ring, so the affordance is always findable in the dock row.
665
- const running = list.filter((w) => orbitStateOf(w) === 'active').length
666
- const broken = list.filter((w) => orbitStateOf(w) === 'error').length
667
- const summary = list.length === 0
668
- ? '还没有主理鱼'
669
- : '会话级 superagent:' + running + ' 运行中'
670
- + (broken ? ',' + broken + ' 异常' : '')
671
- + '(共 ' + list.length + ' 条)'
672
-
673
- const toggle = () => {
674
- const el = btnRef.current
675
- if (el) {
676
- const rect = el.getBoundingClientRect()
677
- setAnchor({ x: rect.left + rect.width / 2, y: rect.top })
678
- }
679
- setOpen((value) => !value)
680
- }
681
-
682
- const button = h('button', {
683
- ref: btnRef,
684
- type: 'button',
685
- title: list.length
686
- ? list.map((w) => (w.repo + ' · ' + (w.title || '未命名会话') + ' · ' + sessionTag(w.sessionId) + ' · ' + STATE_TEXT[orbitStateOf(w)])).join('\n')
687
- : '还没有主理鱼 —— 在「主理鱼」页加一条',
688
- 'aria-label': summary,
689
- 'aria-expanded': open ? 'true' : 'false',
690
- onClick: toggle,
691
- style: {
692
- display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
693
- height: 20, minWidth: 20, padding: '0 2px', margin: '0 2px',
694
- border: 'none', borderRadius: 6,
695
- background: open ? 'rgba(128,128,128,.16)' : 'transparent',
696
- cursor: 'pointer', color: 'inherit', opacity: watchers === null ? 0.45 : 1,
697
- },
698
- }, h(OrbitMark, { watchers: list }))
699
-
700
- if (!open) return button
701
-
702
- // 空态没什么内容,窄一点更像提示而不是一张空表格
703
- const width = list.length === 0 ? 252 : PANEL_W
704
- const left = anchor
705
- ? Math.max(8, Math.min(anchor.x - width / 2, (window.innerWidth || 1200) - width - 8))
706
- : 8
707
- const bottom = anchor ? Math.max(8, (window.innerHeight || 800) - anchor.y + 8) : 64
708
-
709
- const act = async (w, action) => {
710
- if (action === 'delete') {
711
- const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
712
- ? window.confirm('删除主理鱼 ' + (w.repo || '') + '?')
713
- : true
714
- if (!ok) return
715
- }
716
- try {
717
- await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(w) }) })
718
- } catch {}
719
- try {
720
- const body = await call('/state')
721
- setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
722
- } catch {}
723
- }
724
-
725
- // 悬浮面板也走移植来的 dt-* 设计系统(以前这里是一套自成体系的 inline style,
726
- // 和原生界面放在一起能看出断层;ui-audit ⑥ 就是在盯这件事)。
727
- const rows = list.map((w) => {
728
- const state = orbitStateOf(w)
729
- const extra = [
730
- filterText(w.filters),
731
- w.activeHours ? '时段 ' + w.activeHours : '',
732
- isolationText(w),
733
- backoffText(w),
734
- historyText(w),
735
- w.lastDeferred,
736
- ].filter(Boolean).join(' · ')
737
- return h('div', {
738
- key: String(w.repo || '') + '#' + String(w.sessionId || ''),
739
- className: 'dt-row sa-dock-row',
740
- },
741
- h('div', { className: 'dt-row-main' },
742
- h('div', { className: 'dt-row-title' },
743
- h('span', { className: 'dt-dot-wrap' },
744
- h('span', { className: 'dt-state-dot', 'data-state': state === 'active' ? 'done' : state === 'paused' ? 'warning' : state === 'error' ? 'error' : 'idle' })),
745
- h('span', { className: 'sa-mono' }, String(w.repo || '?')),
746
- h('span', { className: 'dt-row-meta' }, STATE_TEXT[state])),
747
- h('div', { className: 'dt-hint' }, (w.title || '未命名会话') + ' · ' + sessionTag(w.sessionId)),
748
- h('div', { className: 'dt-hint' }, '每 ' + w.intervalSec + 's · 轮询 ' + ageText(w.lastPoll) + ' · 唤醒 ' + wakeText(w.lastWake)),
749
- extra ? h('div', { className: 'dt-hint' }, extra) : null,
750
- w.goal && w.goal.objective
751
- ? h('div', { className: 'dt-hint' }, 'goal · ' + String(w.goal.objective).slice(0, 60))
752
- : null,
753
- w.lastError ? (() => {
754
- // 之前整串 slice(0,160):错误一长就先切掉后面的建议 —— 恰好是最有用的部分
755
- const parts = splitErrorText(w.lastError)
756
- return h('div', { className: 'dt-error' },
757
- parts.main.slice(0, 120) + (parts.main.length > 120 ? '…' : ''),
758
- parts.hint ? h('div', { className: 'dt-hint' }, parts.hint) : null)
759
- })() : null),
760
- h('div', { className: 'dt-row-actions' },
761
- h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, 'poll') }, '立刻'),
762
- h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, w.enabled ? 'pause' : 'resume') },
763
- w.enabled ? '暂停' : '恢复'),
764
- h(ConfirmBtn, {
765
- label: '删除', confirmLabel: '确认删除', variant: 'ghost', size: 'sm',
766
- onConfirm: () => act(w, 'delete'),
767
- })))
768
- })
769
-
770
- const panel = h('div', {
771
- ref: panelRef, role: 'dialog', 'aria-label': summary, className: 'dt-card sa-dock-panel',
772
- style: { position: 'fixed', left, bottom, width, zIndex: 2147483000, maxHeight: 360, overflow: 'auto' },
773
- },
774
- h('div', { className: 'dt-card-head' },
775
- h('span', { className: 'dt-card-title' }, '主理鱼'),
776
- h('span', { className: 'dt-count' }, list.length === 0 ? '0 条' : running + '/' + list.length + ' 主理中')),
777
- list.length === 0
778
- ? h('div', { className: 'dt-hint' }, '在「主理鱼」页填 owner/name 加一条。')
779
- : h('div', { className: 'dt-rows' }, rows),
780
- list.length > 0
781
- ? h('div', { className: 'sa-dock-foot' }, '点「暂停 / 删除」直接停掉;「主理鱼」标签页可新增与配置凭证')
782
- : null)
783
-
784
- return h(React.Fragment, null, button, panel)
785
- }
786
-
787
-
788
- // ── 主理鱼面板(按官方 GUI 的信息架构重写:总览 / 触发 / 设置)────────────────
789
- // 布局、类名、控件都来自上面移植的 dt-* 设计系统,数据和动作接我们自己的 /state、/watch。
790
- // ── 官方 GUI 的三个交互件(移植自 src/client/provider.tsx + draft.tsx + src/client/controls.tsx)──
791
-
792
- /** 轮询:可见时按 interval,隐藏时降频 6 倍;上一轮没跑完就跳过;卸载时清干净。 */
793
- function usePoll(task, intervalMs = POLL_MS) {
794
- const ref = useRef(task)
795
- ref.current = task
796
- const busy = useRef(false)
797
- useEffect(() => {
798
- let alive = true
799
- let timer = null
800
- let discovered = false
801
- const step = async () => {
802
- if (!alive) return
803
- if (!discovered) {
804
- discovered = true
805
- try { await discoverBase() } catch {}
806
- }
807
- const hidden = typeof document !== 'undefined' && document.hidden === true
808
- const delay = hidden ? intervalMs * 6 : intervalMs
809
- if (!busy.current) {
810
- busy.current = true
811
- try { await ref.current() } catch {}
812
- finally { busy.current = false }
813
- }
814
- if (alive) timer = setTimeout(step, delay)
815
- }
816
- step()
817
- return () => { alive = false; if (timer) clearTimeout(timer) }
818
- }, [intervalMs])
819
- }
820
-
821
- /** 轻量 Toast:右下角堆叠,4 秒自动消失。 */
822
- function useToast() {
823
- // 官方 .dt-toast 是 position:fixed 顶部居中、且带自动淡出动画 —— 同时挂两条会重叠,
824
- // 所以这里保持「同一时刻只有最新一条」,停留时长用官方的 --dt-toast-hold 控制。
825
- const [item, setItem] = useState(null)
826
- const timer = useRef(null)
827
- useEffect(() => () => { if (timer.current) clearTimeout(timer.current) }, [])
828
- const notify = useCallback((text, tone = 'info') => {
829
- if (timer.current) clearTimeout(timer.current)
830
- setItem({ id: Math.random().toString(36).slice(2), text, tone })
831
- timer.current = setTimeout(() => setItem(null), 4000)
832
- }, [])
833
- const view = item === null ? null : h('div', {
834
- className: cx('dt-toast', item.tone === 'error' && 'dt-danger'),
835
- role: 'status',
836
- 'aria-live': 'polite',
837
- // 官方 toast 是深底白字;错误态不要改成浅红底(白字会看不清),改用左侧红条标记
838
- style: item.tone === 'error'
839
- ? { '--dt-toast-hold': '3600ms', borderLeft: '3px solid var(--dsw-alias-state-error-primary)' }
840
- : { '--dt-toast-hold': '3600ms' },
841
- }, item.text)
842
- return [view, notify]
843
- }
844
-
845
- function ZhuliPanel(props) {
846
- const sessionId = props && props.sessionId
847
- /** 暂停原因码 → 人话(服务端 deferReason 是唯一来源)。 */
848
- const DEFER_LABELS = {
849
- 'active-hours': '不在活跃时段',
850
- ratelimit: '被 GitHub 限流',
851
- quota: '额度紧张',
852
- unchanged: '没有变化',
853
- observe: '仅观察',
854
- 'cap-session': '撞会话上限',
855
- 'cap-watcher': '撞单守上限',
856
- busy: '会话忙',
857
- }
858
-
859
- const [snap, setSnap] = useState({ loading: true, error: null, body: null })
860
- const [tab, setTab] = useState('overview')
861
- const [notice, setNotice] = useState(null)
862
- const [form, setForm] = useState({
863
- repo: '', intervalSec: '60', goal: '', labels: '', onlyAssigned: false,
864
- activeHours: '', isolated: false, workdir: '',
865
- })
866
- const [token, setToken] = useState('')
867
- const [goalDraft, setGoalDraft] = useState('')
868
- const [goalTouched, setGoalTouched] = useState(false)
869
- const [toastView, notify] = useToast()
870
- const [editing, setEditing] = useState(null)
871
- const [draft, setDraft] = useState({})
872
- const [search, setSearch] = useState('')
873
- const [glossary, setGlossary] = useState(false)
874
- // 版本检查结果(只读):面板里直接告诉客户「有没有新版本、该跑什么命令」
875
- const [update, setUpdate] = useState(null)
876
- const [checking, setChecking] = useState(false)
877
- // 设置页用官方的「左栏 + 内容」结构(dt-settings),所以要记当前分区
878
- const [settingsSection, setSettingsSection] = useState('source')
879
- // 判定页:点「跳过原因」标签就只看这一类(知识库里记的"还没做",本轮补上)
880
- const [reasonFilter, setReasonFilter] = useState(null)
881
- // 行内徽章可点:点「只读」就只看只读的守(与跳过原因筛选同一套交互)
882
- const [badgeFilter, setBadgeFilter] = useState(null)
883
- // 只看有问题的:放在最后追加,避免打乱测试桩按位置取值的队列
884
- const [problemsOnly, setProblemsOnly] = useState(false)
885
- // 建议规则弹层:给"叫醒了没回音"一个下一步动作(只提供可复制的规则,不替客户写仓库文件)
886
-
887
- const load = useCallback(async () => {
888
- try {
889
- const payload = await call('/state', stateEtag ? { headers: { 'if-none-match': stateEtag } } : undefined)
890
- // 304:内容没变,别白白重渲染
891
- if (payload && payload.notModified) return null
892
- const body = payload
893
- setSnap({ loading: false, error: null, body })
894
- return body
895
- } catch (error) {
896
- setSnap((prev) => ({ loading: false, error: String((error && error.message) || error), body: prev.body }))
897
- return null
898
- }
899
- }, [])
900
-
901
- useEffect(() => { ensurePortedCss() }, [])
902
- usePoll(load, POLL_MS)
903
-
904
- const body = snap.body || {}
905
- const watchers = body.watchers || []
906
- const sessionGoal = body.sessionGoal || null
907
- const credentials = body.credentials || { token: 'none', sshKeyPath: 'none' }
908
-
909
- useEffect(() => {
910
- if (goalTouched || !sessionGoal) return
911
- setGoalDraft(sessionGoal.objective || '')
912
- }, [goalTouched, sessionGoal])
913
-
914
- const busyRef = useRef(false)
915
- const run = async (work, done) => {
916
- if (busyRef.current) return
917
- busyRef.current = true
918
- setNotice(null)
919
- try {
920
- await work()
921
- if (done) notify(done)
922
- await load()
923
- } catch (error) {
924
- const text = String((error && error.message) || error)
925
- setNotice({ ok: false, text })
926
- notify(text, 'error')
927
- } finally {
928
- busyRef.current = false
929
- }
930
- }
931
-
932
- /** 保存某条 watcher 的编辑(同一 repo+sessionId 即更新,enabled 不传 = 保持原值)。 */
933
- const saveEdit = (watcher) => run(async () => {
934
- await call('/watch', {
935
- method: 'POST',
936
- body: JSON.stringify({
937
- repo: watcher.repo,
938
- sessionId: watcher.sessionId,
939
- intervalSec: Number(draft.intervalSec) || watcher.intervalSec,
940
- filters: {
941
- labels: String(draft.labels || '').split(',').map((v) => v.trim()).filter(Boolean),
942
- onlyAssigned: !!draft.onlyAssigned,
943
- },
944
- activeHours: draft.activeHours || '',
945
- goal: draft.goal || '',
946
- isolated: !!draft.isolated,
947
- workdir: draft.workdir || '',
948
- observe: !!draft.observe,
949
- isolateKeepDays: Number(draft.isolateKeepDays) || undefined,
950
- maxIsolated: Number(draft.maxIsolated) || undefined,
951
- priority: {
952
- reopened: draft.priorityReopened !== false,
953
- comments: draft.priorityComments !== false,
954
- labels: draft.priorityLabels !== false,
955
- unassigned: draft.priorityUnassigned === true,
956
- stale: draft.priorityStale === true,
957
- },
958
- batchLimit: Number(draft.batchLimit) || undefined,
959
- maxWakesPerHour: Number(draft.maxWakesPerHour) || undefined,
960
- sessionMaxWakes: Number(draft.sessionMaxWakes) || undefined,
961
- }),
962
- })
963
- setEditing(null)
964
- }, '已保存:' + watcher.repo)
965
-
966
- const act = (watcher, action) => run(async () => {
967
- await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(watcher) }) })
968
- }, action === 'delete' ? '已删除 ' + watcher.repo : action === 'poll' ? '已触发一次轮询:' + watcher.repo : null)
969
-
970
- const actBulk = (action) => run(async () => {
971
- for (const watcher of watchers) {
972
- if (action === 'pause' && !watcher.enabled) continue
973
- if (action === 'resume' && watcher.enabled) continue
974
- await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(watcher) }) })
975
- }
976
- }, action === 'pause' ? '全部已暂停' : '全部已恢复')
977
-
978
- const addWatcher = () => run(async () => {
979
- const created = await call('/watch', {
980
- method: 'POST',
981
- body: JSON.stringify({
982
- repo: form.repo.trim(),
983
- intervalSec: Number(form.intervalSec) || 60,
984
- goal: form.goal,
985
- sessionId,
986
- filters: {
987
- labels: String(form.labels || '').split(',').map((v) => v.trim()).filter(Boolean),
988
- onlyAssigned: !!form.onlyAssigned,
989
- },
990
- activeHours: form.activeHours || '',
991
- isolated: !!form.isolated,
992
- workdir: form.workdir || '',
993
- observe: !!form.observe,
994
- batchLimit: Number(form.batchLimit) || undefined,
995
- maxWakesPerHour: Number(form.maxWakesPerHour) || undefined,
996
- }),
997
- })
998
- setForm({ repo: '', intervalSec: form.intervalSec, goal: '', labels: '', onlyAssigned: false, activeHours: form.activeHours, isolated: form.isolated, workdir: form.workdir, observe: form.observe })
999
- // 添加前体检的警告直接说出来:填错仓库名 / 只读 / 归档,这一刻讲最省事
1000
- const warnings = (created && Array.isArray(created.warnings)) ? created.warnings : []
1001
- if (warnings.length > 0) notify('已添加,但注意:' + warnings.join(' / '), 'error')
1002
- else notify('已添加,首轮立即开始轮询', 'info')
1003
- return warnings
1004
- }, null)
1005
-
1006
- const saveCredentials = () => run(async () => {
1007
- const payload = {}
1008
- if (token.trim()) payload.token = token.trim()
1009
- await call('/credentials', { method: 'POST', body: JSON.stringify(payload) })
1010
- setToken('')
1011
- }, '凭证已保存')
1012
-
1013
- const saveGoal = () => run(async () => {
1014
- await call('/goal', { method: 'POST', body: JSON.stringify({ sessionId, objective: goalDraft }) })
1015
- setGoalTouched(false)
1016
- }, 'goal 已保存')
1017
-
1018
- const running = watchers.filter((w) => orbitStateOf(w) === 'active').length
1019
- const broken = watchers.filter((w) => orbitStateOf(w) === 'error').length
1020
- const paused = watchers.filter((w) => w.enabled === false).length
1021
-
1022
- const stateTag = (watcher) => {
1023
- const state = orbitStateOf(watcher)
1024
- const tone = state === 'active' ? 'success' : state === 'paused' ? 'warning' : state === 'dormant' ? 'outline' : 'danger'
1025
- return h(Tag, { tone, title: state === 'dormant' ? '不在活跃时段:只攒条目,不唤醒' : undefined }, STATE_TEXT[state])
1026
- }
1027
-
1028
- // 行结构对齐官方 rows.tsx 的 TicketLine:dt-ticket(左侧状态列)+ dt-open 标题 + dt-ticket-actions。
1029
- // 标题本身是按钮 —— 官方就是点标题进详情,我们点标题展开行内编辑,交互更轻但不脱离这套结构。
1030
- const STAGE_STATE = { active: undefined, paused: 'warning', error: 'error', dormant: 'warning' }
1031
- const row = (watcher) => {
1032
- const key = watcher.repo + '#' + watcher.sessionId
1033
- const state = orbitStateOf(watcher)
1034
- const rowBody = h('div', { className: 'dt-ticket-body' },
1035
- h('div', { className: 'dt-row-title' },
1036
- h('button', {
1037
- type: 'button', className: 'dt-open', title: '展开或收起这条主理鱼的设置',
1038
- 'aria-expanded': editing === key, onClick: () => {
1039
- setEditing(editing === key ? null : key)
1040
- setDraft({
1041
- intervalSec: String(watcher.intervalSec ?? 60),
1042
- labels: (watcher.filters && watcher.filters.labels ? watcher.filters.labels : []).join(','),
1043
- activeHours: watcher.activeHours || '',
1044
- goal: watcher.note || watcher.goal || '',
1045
- onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
1046
- // 下面这些以前没填 —— 打开一条隔离执行的守再直接保存,会把 isolated 写回 false
1047
- observe: !!watcher.observe,
1048
- isolated: !!watcher.isolated,
1049
- workdir: watcher.workdir || '',
1050
- batchLimit: watcher.batchLimit ? String(watcher.batchLimit) : '',
1051
- maxWakesPerHour: watcher.maxWakesPerHour ? String(watcher.maxWakesPerHour) : '',
1052
- sessionMaxWakes: watcher.sessionMaxWakes ? String(watcher.sessionMaxWakes) : '',
1053
- isolateKeepDays: watcher.isolateKeepDays ? String(watcher.isolateKeepDays) : '',
1054
- maxIsolated: watcher.maxIsolated ? String(watcher.maxIsolated) : '',
1055
- priorityReopened: (watcher.priority && watcher.priority.reopened) !== false,
1056
- priorityComments: (watcher.priority && watcher.priority.comments) !== false,
1057
- priorityLabels: (watcher.priority && watcher.priority.labels) !== false,
1058
- priorityUnassigned: Boolean(watcher.priority && watcher.priority.unassigned) === true,
1059
- priorityStale: Boolean(watcher.priority && watcher.priority.stale) === true,
1060
- })
1061
- },
1062
- }, watcher.repo)),
1063
- h('div', { className: 'dt-row-meta dt-ticket-meta' },
1064
- stateTag(watcher),
1065
- ...repoBadges(watcher.repoAccess).map((badge) => h(Pill, {
1066
- key: 'b-' + badge.text,
1067
- active: badgeFilter === badge.text,
1068
- onClick: () => setBadgeFilter(badgeFilter === badge.text ? null : badge.text),
1069
- }, badge.text)),
1070
- watcher.observe ? h(Tag, { tone: 'warning' }, '仅观察') : null,
1071
- watcher.activeHours ? h(Tag, null, '时段 ' + watcher.activeHours) : null,
1072
- watcher.isolated ? h(Tag, null, isolationText(watcher)) : null,
1073
- filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
1074
- backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
1075
- h('div', { className: 'dt-ticket-note' },
1076
- [
1077
- (watcher.title || '未命名会话') + ' · ' + sessionTag(watcher.sessionId),
1078
- '每 ' + watcher.intervalSec + 's',
1079
- '轮询 ' + ageText(watcher.lastPoll),
1080
- '唤醒 ' + wakeText(watcher.lastWake),
1081
- historyText(watcher),
1082
- watcher.note ? '目标: ' + String(watcher.note).slice(0, 40) : '',
1083
- ].filter(Boolean).join(' · ')),
1084
- watcher.lastDeferred ? h('div', { className: 'dt-ticket-note' }, watcher.lastDeferred) : null,
1085
- watcher.lastError ? (() => {
1086
- const parts = splitErrorText(watcher.lastError)
1087
- return h('div', { className: 'dt-ticket-note dt-ticket-note-error' },
1088
- parts.main.slice(0, 120) + (parts.main.length > 120 ? '…' : ''),
1089
- parts.hint ? h('div', { className: 'dt-hint' }, parts.hint) : null)
1090
- })() : null,
1091
- h('div', { className: 'dt-ticket-actions' },
1092
- h(Btn, { size: 'sm', variant: 'outline', icon: h(Icon, { name: 'refresh' }), onClick: () => act(watcher, 'poll') }, '立刻'),
1093
- h(Btn, {
1094
- size: 'sm', variant: 'ghost',
1095
- icon: h(Icon, { name: watcher.enabled ? 'pause' : 'play' }),
1096
- label: watcher.enabled ? '暂停' : '恢复',
1097
- onClick: () => act(watcher, watcher.enabled ? 'pause' : 'resume'),
1098
- }, watcher.enabled ? '暂停' : '恢复'),
1099
- h(ConfirmBtn, {
1100
- size: 'sm', variant: 'ghost', icon: h(Icon, { name: 'trash' }), label: '删除',
1101
- confirmLabel: '确认删除', onConfirm: () => act(watcher, 'delete'),
1102
- })))
1103
- const editor = editing === key
1104
- ? h('div', { className: 'dt-fieldset' },
1105
- field('间隔(秒)', h(Input, { value: draft.intervalSec, onChange: (e) => setDraft({ ...draft, intervalSec: e.target.value }) }), '多长时间检查一次这个仓库,最小 30 秒'),
1106
- field('只处理这些标签', h(Input, { value: draft.labels, placeholder: '逗号分隔,留空 = 全部', onChange: (e) => setDraft({ ...draft, labels: e.target.value }) })),
1107
- field('活跃时段', h(Input, { value: draft.activeHours, placeholder: '09:00-23:00,留空 = 全天', onChange: (e) => setDraft({ ...draft, activeHours: e.target.value }) }), '只在这个时间段内唤醒;窗口外只攒条目,不打扰'),
1108
- field('目标/规则', h(Input, { value: draft.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setDraft({ ...draft, goal: e.target.value }) })),
1109
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.onlyAssigned, onChange: (v) => setDraft({ ...draft, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1110
- field('单次最多唤醒条数', h(Input, { value: draft.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setDraft({ ...draft, batchLimit: e.target.value }) })),
1111
- field('每小时最多唤醒次数', h(Input, { value: draft.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setDraft({ ...draft, maxWakesPerHour: e.target.value }) })),
1112
- field('这条会话每小时最多被唤醒', h(Input, { value: draft.sessionMaxWakes || '', placeholder: '12(1-60)', onChange: (e) => setDraft({ ...draft, sessionMaxWakes: e.target.value }) }), '跨所有守累计:守 5 个仓库时,光有单守上限挡不住叠加'),
1113
- field('优先级(一次只处理 N 条时先挑谁)', h('div', { className: 'dt-actions' },
1114
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityReopened !== false, onChange: (v) => setDraft({ ...draft, priorityReopened: v }), label: '重开优先' }), '被重开的排最前'),
1115
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityComments !== false, onChange: (v) => setDraft({ ...draft, priorityComments: v }), label: '评论优先' }), '有人在等回应的靠前'),
1116
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityLabels !== false, onChange: (v) => setDraft({ ...draft, priorityLabels: v }), label: '标签优先' }), '带标签的靠前'),
1117
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityUnassigned === true, onChange: (v) => setDraft({ ...draft, priorityUnassigned: v }), label: '未认领优先' }), '没人认领的靠前(默认关:这是我们的判断,不是规则)'),
1118
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityStale === true, onChange: (v) => setDraft({ ...draft, priorityStale: v }), label: '积压优先' }), '躺了 30 天以上的靠前(默认关,只展示)')), '全部关掉时按 GitHub 的「最近更新」顺序处理'),
1119
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.observe, onChange: (v) => setDraft({ ...draft, observe: v }), label: '仅观察' }), '仅观察(只记录不唤醒)'),
1120
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.isolated, onChange: (v) => setDraft({ ...draft, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一个临时副本;在副本里改,用完自动回收)'),
1121
- draft.isolated ? field('隔离工作目录', h(Input, { value: draft.workdir || '', placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setDraft({ ...draft, workdir: e.target.value }) })) : null,
1122
- draft.isolated ? field('隔离区保留天数', h(Input, { value: draft.isolateKeepDays || '', placeholder: '3(1-30)', onChange: (e) => setDraft({ ...draft, isolateKeepDays: e.target.value }) }), '每次唤醒前回收这个天数之前的一次性工作区;留空用默认 3 天') : null,
1123
- draft.isolated ? field('最多保留几个隔离区', h(Input, { value: draft.maxIsolated || '', placeholder: '5(1-50)', onChange: (e) => setDraft({ ...draft, maxIsolated: e.target.value }) }), '天数之外的第二道线:超出就回收最旧的(不影响正在用的那个)') : null,
1124
- h('div', { className: 'dt-actions' },
1125
- h(Btn, { size: 'sm', variant: 'primary', onClick: () => saveEdit(watcher) }, '保存'),
1126
- h(Btn, { size: 'sm', onClick: () => setEditing(null) }, '放弃')))
1127
- : null
1128
- // 官方 TicketLine 是 <li class="dt-row dt-link dt-ticket"> 里套「状态列 + 正文列」,
1129
- // 展开的表单跟在正文列里,不破坏两列网格。
1130
- const bodyChildren = [].concat(rowBody.props.children || []).filter(Boolean)
1131
- return h('li', {
1132
- key,
1133
- className: 'dt-row dt-link dt-ticket',
1134
- 'data-state': state === 'error' ? 'error' : undefined,
1135
- },
1136
- h('div', { className: 'dt-ticket-stage' },
1137
- h('span', { className: 'dt-stage', 'data-state': STAGE_STATE[state] }, STATE_TEXT[state])),
1138
- h('div', { className: 'dt-ticket-body' }, ...bodyChildren, editor))
1139
- }
1140
-
1141
- const problems = []
1142
- // 按暂停原因筛选时,「需要关注」也一起收窄(否则列表和告警会自相矛盾)
1143
- const deferFilter = reasonFilter && reasonFilter.startsWith('defer:') ? reasonFilter.slice(6) : null
1144
- for (const watcher of watchers) {
1145
- if (deferFilter && watcher.deferReason !== deferFilter) continue
1146
- // 仓库结构问题(关闭 Issues / 是 fork)比轮询失败更早该说:它注定收不到条目
1147
- const structure = repoStructureNote(watcher.repoAccess)
1148
- if (structure) problems.push({ key: 's-' + watcher.repo, text: structure })
1149
- // 只读:以前只在行内显示一个徽章,客户在「需要关注」里看不到,也不知道回写会 403
1150
- const readOnly = accessNoteForPanel(watcher.repoAccess, watcher.repo)
1151
- if (readOnly) problems.push({ key: 'ro-' + watcher.repo, text: readOnly })
1152
- // 叫醒了但没回音:守在工作、消息也进去了,但会话没动手(规则缺失或被忽略)
1153
- if (Number(watcher.silentWakes) >= 2) {
1154
- problems.push({
1155
- key: 'silent-' + watcher.repo,
1156
- text: watcher.repo + ' 连续 ' + watcher.silentWakes + ' 次被叫醒后没有动作(没看到 watch_ack 标签)—— 会话可能没按规则处理',
1157
- action: { label: '看建议规则', onClick: () => setGlossary('rules:' + watcher.repo) },
1158
- })
1159
- }
1160
- // 被反复重开的条目:说明"之前判过不做"可能有问题,值得人看一眼
1161
- if (watcher.lastReopened) {
1162
- problems.push({ key: 'r-' + watcher.repo, text: watcher.repo + ' #' + watcher.lastReopened + ' 被重新打开过 —— 之前判"不做"可能不对' })
1163
- }
1164
- if (structure) problems.push({ key: 's-' + watcher.repo, text: structure })
1165
- if (watcher.lastError) {
1166
- // 同样拆开:现象截断、建议保留(这里原来是整串塞进「需要关注」)
1167
- const parts = splitErrorText(watcher.lastError)
1168
- problems.push({
1169
- key: 'e-' + watcher.repo,
1170
- text: watcher.repo + ' 轮询失败:' + parts.main.slice(0, 120) + (parts.main.length > 120 ? '…' : '') + ' ' + parts.hint,
1171
- })
1172
- }
1173
- else if (watcher.lastDeferred) problems.push({ key: 'd-' + watcher.repo, text: watcher.repo + ' 暂停唤醒:' + watcher.lastDeferred })
1174
- }
1175
- if (body.gh && body.gh.ok === false && credentials.token === 'none') {
1176
- problems.push({ key: 'gh', text: 'gh CLI 不可用,且没有配置 token —— 现在所有轮询都会失败。先跑 gh auth login,或在「设置 → 来源」填一个 token。' })
1177
- }
1178
- if (watchers.length > 0 && credentials.token === 'none') {
1179
- problems.push({ key: 'cred', text: '未配置 token,正在复用已登录的 gh CLI(可用 panel 填 token 换成独立凭据)' })
1180
- }
1181
-
1182
- const needle = search.trim().toLowerCase()
1183
- const matches = (watcher) => !needle
1184
- || watcher.repo.toLowerCase().includes(needle)
1185
- || (watcher.title || '').toLowerCase().includes(needle)
1186
- || (watcher.filteredLog || []).some((entry) => String(entry.number).includes(needle) || String(entry.title || '').toLowerCase().includes(needle))
1187
- const matchesBadge = (watcher) => !badgeFilter
1188
- || repoBadges(watcher.repoAccess).some((badge) => badge.text === badgeFilter)
1189
- const hasProblem = (watcher) => Boolean(watcher.lastError)
1190
- || Number(watcher.silentWakes) >= 2
1191
- || Boolean(repoStructureNote(watcher.repoAccess))
1192
- || repoBadges(watcher.repoAccess).some((badge) => badge.tone === 'warning' || badge.tone === 'danger')
1193
- const visible = watchers.filter((watcher) => matches(watcher) && matchesBadge(watcher)
1194
- && (!problemsOnly || hasProblem(watcher))
1195
- && (!deferFilter || watcher.deferReason === deferFilter))
1196
-
1197
- const overview = [
1198
- watchers.some((w) => (w.filteredLog || []).length > 0)
1199
- ? h(Section, { key: 'filtered', title: '最近被过滤' },
1200
- h(CollapsibleList, {
1201
- title: '看被过滤的条目',
1202
- items: watchers.flatMap((w) => (w.filteredLog || []).slice(-2).map((entry) =>
1203
- '#' + entry.number + ' ' + (entry.title || '') + ' — ' + entry.reason)),
1204
- }))
1205
- : null,
1206
- problems.length > 0
1207
- ? h(Section, { key: 'problems', title: '需要关注', count: problems.length },
1208
- h('ul', { className: 'dt-plain-list' }, problems.map((item) => h('li', { key: item.key, className: 'dt-danger' }, item.text))))
1209
- : null,
1210
- // 中间态:已经有守、但一次都没唤醒过 —— 这不是"没配置",是"在等"
1211
- (watchers.length > 0 && watchers.every((w) => !w.lastWake))
1212
- ? h('div', { className: 'sa-dock-foot', key: 'waiting' },
1213
- '还没有唤醒过:守会在仓库出现新条目时叫醒这个会话。'
1214
- + '想先试一次,点行里的「立刻」;如果一直没动静,看上面「需要关注」里有没有被过滤的记录。'
1215
- + '叫醒之后:会话先读仓库 AGENTS.md → 决定「修 / 回 / 待定」→ 做完写回并 watch_ack 打标签;'
1216
- + '不做也要说明理由并 ack。每次只处理叫醒消息里列出的那几条,不会扩大范围。')
1217
- : null,
1218
- // 需要重启:这是"功能看起来没生效"最常见的根因,必须显眼
1219
- (body.installedVersion && body.runningVersion && body.installedVersion !== body.runningVersion)
1220
- ? h('div', { className: 'dt-banner dt-danger', key: 'restart-needed' },
1221
- '代码已更新到 ' + body.installedVersion + ',但宿主还在跑 ' + body.runningVersion
1222
- + ' —— 服务端改动需要重启宿主才生效(客户端部分已生效,所以界面可能看起来是新的)。')
1223
- : null,
1224
- badgeFilter
1225
- ? h('div', { className: 'dt-row-meta', key: 'badge-filter' },
1226
- h('span', null, '只看 ' + badgeFilter + ' 的守(' + visible.length + ' 条):'),
1227
- h(Pill, { onClick: () => setBadgeFilter(null) }, '清除'))
1228
- : null,
1229
- h('div', { className: 'dt-stats', key: 'stats' },
1230
- h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(watchers.length)), h('span', null, '条主理鱼')),
1231
- h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(running)), h('span', null, '主理中')),
1232
- h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(paused)), h('span', null, '已暂停')),
1233
- h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(broken)), h('span', null, '异常'))),
1234
- h(Section, { key: 'list', title: needle ? '搜索结果' : '主理鱼', count: visible.length },
1235
- watchers.length === 0
1236
- ? h(Onboarding, { onStart: () => setTab('trigger') })
1237
- : visible.length === 0
1238
- ? h(Hint, null, '没有匹配「' + search + '」的主理鱼。')
1239
- : h('ul', { className: 'dt-list' }, visible.map(row))),
1240
- ]
1241
-
1242
- // 判定日志(对应官方 eval 页):每轮的唤醒结果、跳过原因、被过滤记录,一次看全
1243
- // 判定页用官方的时间线结构(dt-timeline / dt-event / dt-event-foot),
1244
- // 官方在 thread.tsx 与 settings-kit.tsx 里就是这么铺「发生过什么」的。
1245
- // 跳过原因分布:把「为什么没叫醒」做成可读的统计(客户最常问的问题)
1246
- const reasonTotals = (() => {
1247
- const merged = {}
1248
- for (const w of watchers) for (const [reason, n] of Object.entries(w.filterCounts || {})) {
1249
- merged[reason] = (Number(merged[reason]) || 0) + (Number(n) || 0)
1250
- }
1251
- return Object.entries(merged).sort((a, b) => b[1] - a[1]).slice(0, 8)
1252
- })()
1253
- const judge = h(Section, {
1254
- title: '判定日志',
1255
- count: watchers.reduce((n, w) => n + (w.history || []).length, 0),
1256
- action: h(InfoTip, { text: '每轮判定都会记一条:唤醒、仅观察,或跳过及其原因。只存最近若干条。' }),
1257
- },
1258
- (() => {
1259
- const needle = search.trim()
1260
- const asNumber = /^#?[0-9]+$/.test(needle) ? needle.replace('#', '') : ''
1261
- const onlyRepo = watchers.length === 1 ? watchers[0].repo : ''
1262
- return h(Section, { key: 'trace', title: '追溯一条', hint: '在右上角搜索框输入编号(如 42),这里就能查它经历了什么' },
1263
- asNumber
1264
- ? h('div', { className: 'dt-row-meta' },
1265
- h('button', {
1266
- className: 'dt-textlink',
1267
- type: 'button',
1268
- onClick: async () => {
1269
- try {
1270
- const query = '/trace?number=' + encodeURIComponent(asNumber) + (onlyRepo ? '&repo=' + encodeURIComponent(onlyRepo) : '')
1271
- const payload = await call(query)
1272
- notify(String((payload && payload.text) || '没有结果').split(String.fromCharCode(10)).join(' · '), 'info')
1273
- } catch (error) {
1274
- notify('追溯失败:' + String((error && error.message) || error), 'error')
1275
- }
1276
- },
1277
- }, '追溯 #' + asNumber),
1278
- h('span', { className: 'dt-row-meta' }, onlyRepo ? '(在 ' + onlyRepo + ' 里查)' : '(在所有守里查)'))
1279
- : h(Hint, null, '追溯会告诉你:它被过滤了、已经唤醒过、还是根本没轮到。'))
1280
- })(),
1281
- (() => {
1282
- const counts = new Map()
1283
- for (const w of watchers) if (w.deferReason) counts.set(w.deferReason, (counts.get(w.deferReason) || 0) + 1)
1284
- if (counts.size === 0) return null
1285
- return h('div', { className: 'dt-row-meta', key: 'defer-totals' },
1286
- h('span', null, '暂停原因:'),
1287
- [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([code, n]) => h(Pill, {
1288
- key: code,
1289
- active: deferFilter === code,
1290
- onClick: () => setReasonFilter(deferFilter === code ? null : 'defer:' + code),
1291
- }, (DEFER_LABELS[code] || code) + ' × ' + n)),
1292
- deferFilter ? h(Pill, { key: 'clear-defer', onClick: () => setReasonFilter(null) }, '清除') : null)
1293
- })(),
1294
- reasonTotals.length > 0
1295
- ? h('div', { className: 'dt-row-meta', key: 'reason-totals' },
1296
- h('span', null, '跳过原因累计:'),
1297
- reasonTotals.map(([reason, n]) => h(Pill, {
1298
- key: reason,
1299
- active: reasonFilter === reason,
1300
- onClick: () => setReasonFilter(reasonFilter === reason ? null : reason),
1301
- }, reason + ' × ' + n)),
1302
- reasonFilter ? h(Pill, { key: 'clear', onClick: () => setReasonFilter(null) }, '清除筛选') : null)
1303
- : null,
1304
- reasonFilter
1305
- ? h('ul', { className: 'dt-plain-list', key: 'reason-entries' },
1306
- watchers.flatMap((w) => (w.filteredLog || [])
1307
- .filter((entry) => entry.reason === reasonFilter)
1308
- .map((entry) => h('li', { key: w.repo + '#' + entry.number + entry.at },
1309
- w.repo + ' #' + entry.number + ' ' + String(entry.title || '').slice(0, 60)))))
1310
- : null,
1311
- watchers.length === 0
1312
- ? h(Hint, null, '还没有主理鱼。')
1313
- : h('ol', { className: 'dt-timeline' },
1314
- watchers.flatMap((watcher) => (watcher.history || []).slice(-6).reverse().map((entry, index) => {
1315
- const label = entry.ok ? '已唤醒' : entry.reason === 'observe' ? '仅观察(未唤醒)' : '跳过:' + (entry.reason || '未知')
1316
- return h('li', {
1317
- key: watcher.repo + '#' + watcher.sessionId + entry.at + index,
1318
- className: 'dt-event' + (entry.ok ? '' : ' dt-event-quiet'),
1319
- },
1320
- h('div', { className: 'dt-event-foot' },
1321
- h('strong', { className: 'dt-event-actor' }, watcher.repo),
1322
- h('span', null, ageText(entry.at))),
1323
- h('p', { className: 'dt-event-text' }, label),
1324
- h('div', { className: 'dt-event-foot' },
1325
- (entry.numbers || []).length > 0
1326
- ? h('span', null, (entry.numbers || []).map((n) => '#' + n).join(' '))
1327
- : null,
1328
- h('span', null, (watcher.title || '未命名会话') + ' · ' + sessionTag(watcher.sessionId))))
1329
- }))))
1330
-
1331
- // 迷你时间线:回答"为什么这一轮没叫醒我"
1332
- const timeline = h(Section, { key: 'timeline', title: '时间线(最近 20 条)' },
1333
- watchers.length === 0
1334
- ? h(Hint, null, '还没有守。添加一条之后,这里会记录每次唤醒、攒着、限流、回收。')
1335
- : h('div', { className: 'dt-rows' }, watchers.flatMap((watcher) => (watcher.events || []).slice().reverse().map((event, index) => h('div', {
1336
- key: watcher.repo + '-ev' + index,
1337
- className: 'dt-row',
1338
- },
1339
- h('div', { className: 'dt-row-main' },
1340
- h('div', { className: 'dt-row-title' },
1341
- h(Tag, { tone: event.kind === 'wake' ? 'success' : event.kind === 'wake-failed' ? 'danger' : 'outline' },
1342
- event.kind + (Number(event.count) > 1 ? ' ×' + event.count : '')),
1343
- (Number(event.count) > 1 && event.since)
1344
- ? h('span', { className: 'dt-row-meta' }, '持续 ' + durationText(event.since, event.at))
1345
- : null,
1346
- h('span', { className: 'dt-row-meta' }, ageText(event.at))),
1347
- h('div', { className: 'dt-hint' }, watcher.repo + ' · ' + event.text)))))))
1348
-
1349
- // 按仓库汇总:守多个仓库时先看哪个健康,再看明细(渐进披露)
1350
- const problemCount = watchers.filter(hasProblem).length
1351
- const repoSummary = watchers.length === 0 ? null : h(Section, { key: 'repo-summary', title: '按仓库', hint: '点仓库名只看它(再点取消)' },
1352
- h('div', { className: 'dt-row-meta' },
1353
- h(Pill, { active: problemsOnly, onClick: () => setProblemsOnly(!problemsOnly) }, '只看有问题的' + (problemCount > 0 ? ' (' + problemCount + ')' : '')),
1354
- problemsOnly ? h(Pill, { onClick: () => setProblemsOnly(false) }, '全部') : null),
1355
- body.sessionUsage
1356
- ? h('div', { className: 'dt-row-meta' },
1357
- h('span', null, '本会话近一小时唤醒 ' + body.sessionUsage.used + '/' + body.sessionUsage.cap),
1358
- body.sessionUsage.used >= body.sessionUsage.cap
1359
- ? h('span', { className: 'dt-error-text' },
1360
- '已到上限:新条目会攒到下一小时' +
1361
- (body.sessionUsage.suggest ? ';建议把「这条会话每小时最多被唤醒」调到 ' + body.sessionUsage.suggest : ';可以把该上限调大'))
1362
- : null,
1363
- body.sessionUsage.capped > 0
1364
- ? h('span', { className: 'dt-error-text' }, body.sessionUsage.capped + ' 条守正因上限暂停')
1365
- : null,
1366
- (() => {
1367
- // 过去几天累计(数据来自每条守的 daily,几十字节)
1368
- const days = watchers.reduce((n, w) => n + (Number(w.daily && w.daily.days) || 0), 0)
1369
- const total = watchers.reduce((n, w) => n + (Number(w.daily && w.daily.total) || 0), 0)
1370
- if (total === 0) return null
1371
- const span = Math.max(...watchers.map((w) => Number(w.daily && w.daily.days) || 0))
1372
- return [
1373
- h('span', { key: 'hist', className: 'dt-row-meta' }, '过去 ' + span + ' 天:共 ' + total + ' 次(日均 ' + (Math.round((total / Math.max(1, span)) * 10) / 10) + ')'),
1374
- watchers.some((w) => w.busy)
1375
- ? h('span', { key: 'busy', className: 'dt-error-text' }, '今天明显比平时忙 —— 上限可能不够用')
1376
- : null,
1377
- ]
1378
- })())
1379
- : null,
1380
- visible.length === 0 ? h(Hint, null, '没有符合条件的主理鱼。点上面「全部」看所有守。') : null,
1381
- h('div', { className: 'dt-rows' }, ...summarizeByRepo(visible).map((group) => h('div', { key: 'repo-' + group.repo, className: 'dt-row' },
1382
- h('div', { className: 'dt-row-main' },
1383
- h('div', { className: 'dt-row-title' },
1384
- h(StateDot, { state: group.errors > 0 ? 'error' : group.silentWakes >= 2 ? 'warning' : 'done' }),
1385
- h('button', {
1386
- className: 'dt-textlink dt-row-name',
1387
- type: 'button',
1388
- onClick: () => setSearch(search === group.repo ? '' : group.repo),
1389
- title: '点一下只看这个仓库(再点取消)',
1390
- }, group.repo),
1391
- ...group.badges.map((badge) => h(Tag, { key: 'rb-' + badge.text, tone: badge.tone }, badge.text))),
1392
- h('div', { className: 'dt-row-meta' },
1393
- h('span', null, group.count + ' 条守(启用 ' + group.enabled + ')'),
1394
- h('span', null, group.lastWake ? '最近唤醒 ' + ageText(group.lastWake) : '还没唤醒过'),
1395
- group.silentWakes > 0 ? h('span', { className: 'dt-error-text' }, '未回音 ' + group.silentWakes + ' 次') : null,
1396
- group.errors > 0 ? h('span', { className: 'dt-error-text' }, group.errors + ' 条报错') : null))))))
1397
-
1398
- const trigger = h(Section, { title: '新增主理鱼' },
1399
- h('div', { className: 'dt-form' },
1400
- field('仓库', h(Input, { value: form.repo, placeholder: 'owner/name', onChange: (e) => setForm({ ...form, repo: e.target.value }) })),
1401
- field('间隔(秒)', h(Input, { value: form.intervalSec, onChange: (e) => setForm({ ...form, intervalSec: e.target.value }) })),
1402
- field('单次最多唤醒条数', h(Input, { value: form.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setForm({ ...form, batchLimit: e.target.value }) })),
1403
- field('每小时最多唤醒次数', h(Input, { value: form.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setForm({ ...form, maxWakesPerHour: e.target.value }) })),
1404
- field('只处理这些标签', h(Input, { value: form.labels, placeholder: '逗号分隔,留空 = 全部', onChange: (e) => setForm({ ...form, labels: e.target.value }) })),
1405
- field('活跃时段', h(Input, { value: form.activeHours, placeholder: '09:00-23:00,留空 = 全天', onChange: (e) => setForm({ ...form, activeHours: e.target.value }) })),
1406
- field('目标/规则', h(Input, { value: form.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setForm({ ...form, goal: e.target.value }) })),
1407
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: form.onlyAssigned, onChange: (v) => setForm({ ...form, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1408
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!form.observe, onChange: (v) => setForm({ ...form, observe: v }), label: '仅观察' }), '仅观察(只记录本会唤醒哪几条,不真唤醒)'),
1409
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: form.isolated, onChange: (v) => setForm({ ...form, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一个临时副本;在副本里改,用完自动回收)'),
1410
- form.isolated ? field('隔离工作目录', h(Input, { value: form.workdir, placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setForm({ ...form, workdir: e.target.value }) })) : null,
1411
- h('div', { className: 'dt-actions' },
1412
- h(Btn, { variant: 'primary', icon: h(Icon, { name: 'plus' }), onClick: addWatcher, disabled: !sessionId || !form.repo.trim() },
1413
- sessionId ? '添加到当前会话' : '需要会话上下文'))))
1414
-
1415
- const settingsSections = [
1416
- h(Section, { key: 'source', title: '来源' },
1417
- h(KeyValues, { rows: [
1418
- ['仓库', watchers.length === 0 ? '未绑定' : watchers.map((w) => w.repo).join(', ')],
1419
- ['gh CLI', !body.gh
1420
- ? '检测中…'
1421
- : body.gh.ok
1422
- ? '可用 · ' + (body.gh.version || '')
1423
- : '不可用 —— 先跑 gh auth login(或装 gh CLI);也可以直接在下面填 token · ' + String(body.gh.error || '').slice(0, 80)],
1424
- ['凭证', credentials.token === 'none' ? '回退到 gh CLI 登录态' : '使用面板配置的 token'],
1425
- ['权限范围', (() => {
1426
- const info = body.tokenScopes
1427
- if (!info) return '正在探测…'
1428
- if (!info.ok) return '探测失败:' + String(info.error || '').slice(0, 60)
1429
- if (!info.scopes.length) return '细粒度 token(无 OAuth scope)'
1430
- return info.scopes.join(', ')
1431
- })()],
1432
- (body.tokenScopes && body.tokenScopes.broad && body.tokenScopes.broad.length > 0)
1433
- ? ['提示', '这个 token 带 ' + body.tokenScopes.broad.join(', ') + ' —— 我们的功能只需要「读 issue/PR + 写评论和标签」,建议换细粒度 token 只授 Issues 读写']
1434
- : null,
1435
- ['隔离占用', !body.isolation || (body.isolation.roots || []).length === 0
1436
- ? '没有开隔离执行'
1437
- : (body.isolation.roots || []).map((r) => r.count + ' 个 · ' + bytesText(r.bytes)).join(';')
1438
- + '(合计 ' + bytesText(body.isolation.totalBytes) + ')'],
1439
- ] })),
1440
- h(Section, { key: 'creds', title: '凭证' },
1441
- h(KeyValues, { rows: [['GitHub token', credentials.token === 'none' ? '未配置(回退到已登录的 gh CLI)' : '已配置'], ['SSH 私钥', credentials.sshKeyPath === 'none' ? '未配置(当前版本不使用)' : '已配置']] }),
1442
- field('Token', h(Input, { type: 'password', value: token, placeholder: 'ghp_… / github_pat_…(留空不改)', onChange: (e) => setToken(e.target.value) })),
1443
- h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveCredentials }, '保存凭证')),
1444
- h(Hint, null, '不填也能用:插件直接复用已登录的 gh CLI。')),
1445
- h(Section, { key: 'update', title: '版本与更新' },
1446
- h(KeyValues, { rows: [
1447
- ['当前版本', (update && update.current) || CLIENT_VERSION],
1448
- ['npm 最新', !update ? '检测中…' : update.error ? '检测失败 · ' + update.error : (update.latest || '未知')],
1449
- ['状态', !update ? '…' : update.hasUpdate ? '有新版本,可以升级' : '已是最新'],
1450
- ] }),
1451
- update && update.hasUpdate
1452
- ? h('div', null,
1453
- h('code', { className: 'dt-code' }, update.command),
1454
- h('div', { className: 'dt-actions' },
1455
- h(Btn, { size: 'sm', onClick: () => { try { navigator.clipboard.writeText(update.command) } catch {} } }, '复制命令')))
1456
- : null,
1457
- h('div', { className: 'dt-actions' },
1458
- h(Btn, { size: 'sm', variant: 'ghost', onClick: () => checkUpdate(true), disabled: checking }, checking ? '检查中…' : '重新检查')),
1459
- h(Hint, null, '升级要改 profile,装完需要重载一次宿主才会用上新版本 —— 所以这里只给命令,不替你执行。'),
1460
- h(Hint, null, '反馈问题时把下面这份诊断贴给对方:里面有版本、挂载状态和每条守的最近错误(凭证已脱敏)。'),
1461
- h('div', { className: 'dt-actions' },
1462
- h(Btn, {
1463
- size: 'sm',
1464
- variant: 'outline',
1465
- onClick: async () => {
1466
- try {
1467
- const payload = await call('/diagnose')
1468
- const text = String((payload && payload.text) || '')
1469
- try { await navigator.clipboard.writeText(text) } catch {}
1470
- notify('诊断信息已复制(' + text.split(String.fromCharCode(10)).length + ' 行)', 'info')
1471
- } catch (error) {
1472
- notify('生成诊断失败:' + String((error && error.message) || error), 'error')
1473
- }
1474
- },
1475
- }, '复制诊断信息'))),
1476
- h(Section, { key: 'diagnose', title: '分诊信号与取舍' },
1477
- h(Hint, null, '一次只处理 N 条时,这些信号的加权决定先后。事实默认展示,判断默认关闭。'),
1478
- h('div', { className: 'dt-rows' }, (body.triageSignals || []).map((sig) => h('div', { key: sig.key, className: 'dt-row' },
1479
- h('div', { className: 'dt-row-main' },
1480
- h('div', { className: 'dt-row-title' },
1481
- h('span', { className: 'dt-row-name' }, sig.label),
1482
- h(Tag, { tone: sig.kind === 'fact' ? 'success' : 'warning' }, sig.kind === 'fact' ? '事实' : '判断'),
1483
- h(Tag, { tone: sig.default ? 'outline' : 'quiet' }, sig.default ? '默认开' : '默认关'),
1484
- h('span', { className: 'dt-row-meta' }, '+' + sig.weight + ' 分')),
1485
- h('div', { className: 'dt-hint' }, sig.why)))))),
1486
-
1487
- h(Section, { key: 'goal', title: '会话 goal' },
1488
- h('textarea', {
1489
- className: 'dt-textarea', rows: 3, value: goalDraft,
1490
- placeholder: '这个会话要达成什么(会写进 /goal)',
1491
- onChange: (e) => { setGoalTouched(true); setGoalDraft(e.target.value) },
1492
- }),
1493
- h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveGoal, disabled: !sessionId }, '保存 goal'))),
1494
- ]
1495
-
1496
-
1497
- // 官方设置页是「左栏导航 + 右侧内容」的网格(dt-settings / dt-settings-nav / dt-settings-body)。
1498
- // 我们之前是单列堆叠,四个分区一起铺开,深链路里翻起来很累。
1499
- const SETTINGS_SECTIONS = [
1500
- { key: 'source', title: '来源' },
1501
- { key: 'creds', title: '凭证' },
1502
- { key: 'update', title: '版本与更新' },
1503
- { key: 'diagnose', title: '诊断' },
1504
- { key: 'goal', title: '会话 goal' },
1505
- ]
1506
- const settingsBody = settingsSections.find((node) => node && node.props && node.props.key === settingsSection)
1507
- || settingsSections.find(Boolean)
1508
- const settings = h('div', { className: 'dt-settings' },
1509
- h('nav', { className: 'dt-settings-nav', 'aria-label': '设置分区' },
1510
- SETTINGS_SECTIONS.map((item) => h('button', {
1511
- key: item.key, type: 'button', className: 'dt-settings-link',
1512
- 'aria-current': settingsSection === item.key ? 'page' : undefined,
1513
- onClick: () => setSettingsSection(item.key),
1514
- }, item.title))),
1515
- h('div', { className: 'dt-settings-body' }, settingsBody))
1516
-
1517
- const checkUpdate = useCallback(async (force) => {
1518
- setChecking(true)
1519
- try {
1520
- const value = await call('/update' + (force ? '?refresh=1' : ''))
1521
- setUpdate(value)
1522
- } catch (error) {
1523
- setUpdate({ current: CLIENT_VERSION, latest: null, hasUpdate: false, error: String(error && error.message || error) })
1524
- } finally {
1525
- setChecking(false)
1526
- }
1527
- }, [])
1528
-
1529
- useEffect(() => {
1530
- let alive = true
1531
- try {
1532
- Promise.resolve(call('/update'))
1533
- .then((value) => { if (alive) setUpdate(value) })
1534
- .catch(() => {})
1535
- } catch { /* 宿主早期渲染时 fetch 可能还不存在,忽略即可 */ }
1536
- return () => { alive = false }
1537
- }, [])
1538
-
1539
-
1540
- /**
1541
- * 面板自己遇到的错误也要说人话。
1542
- *
1543
- * 服务端那边的 gh 错误已经由 classifyGhError 归类(并附了 hint);
1544
- * 但**面板拉自己接口失败**(宿主正在重启、端口变了、fetch 被拒)不会经过那套,
1545
- * 以前界面上就是一行 "Failed to fetch" —— 客户看不懂,也不知道要做什么。
1546
- */
1547
- function humanizeError(text) {
1548
- const raw = String(text == null ? '' : text)
1549
- if (!raw) return ''
1550
- if (/Failed to fetch|NetworkError|Load failed/i.test(raw)) {
1551
- return '连不上宿主:DSH 可能正在重启,或插件刚被重载。稍等几秒会自动重试;一直这样就去「设置 → 诊断」复制信息。'
1552
- }
1553
- if (/HTTP 401|HTTP 403/i.test(raw)) return '宿主拒绝了请求(401/403):面板接口可能需要重新挂载,重启宿主即可。'
1554
- if (/HTTP 5\d\d/.test(raw)) return '宿主内部报错(5xx):先把「设置 → 诊断」里的信息复制出来,再重启宿主试试。'
1555
- if (/HTTP 404/.test(raw)) return '接口不存在(404):多半还在跑旧版本代码,重启宿主。'
1556
- if (/timeout|timed out|ETIMEDOUT/i.test(raw)) return '请求超时:宿主可能正忙(比如同时在建隔离 worktree),稍后自动重试。'
1557
- return raw
1558
- }
1559
-
1560
- /** 建议追加到仓库 AGENTS.md 的处理规则(只给文本,绝不代写文件)。 */
1561
- const AGENTS_SNIPPET = [
1562
- '## 主理鱼(dsh-session-superagent)处理规则',
1563
- '',
1564
- '- 收到「【主理鱼】<owner/name> 有 N 条新动态」时,先读完整条目再决定做不做。',
1565
- '- 做:按【完成标准】三件事写清(改了什么 / 怎么验证 / 回写到哪),改完推分支开 PR。',
1566
- '- 不做:也要说明理由(例如"已有 PR 在做"),然后照样 ack。',
1567
- '- **无论做还是不做,最后都要 watch_ack 打标签**,否则下一轮会被再次唤醒。',
1568
- ].join(String.fromCharCode(10))
1569
-
1570
- /** 按仓库汇总(与服务端 watch.js:summarizeByRepo 同语义)。 */
1571
- function summarizeByRepo(list) {
1572
- const groups = new Map()
1573
- for (const watcher of Array.isArray(list) ? list : []) {
1574
- if (!watcher || !watcher.repo) continue
1575
- const repo = String(watcher.repo)
1576
- const group = groups.get(repo) || { repo, count: 0, lastWake: null, silentWakes: 0, errors: 0, enabled: 0, badges: [] }
1577
- group.count += 1
1578
- if (watcher.enabled !== false) group.enabled += 1
1579
- if (watcher.lastWake && (!group.lastWake || String(watcher.lastWake) > String(group.lastWake))) group.lastWake = watcher.lastWake
1580
- group.silentWakes = Math.max(group.silentWakes, Number(watcher.silentWakes) || 0)
1581
- if (watcher.lastError) group.errors += 1
1582
- for (const badge of repoBadges(watcher.repoAccess) || []) {
1583
- if (!group.badges.some((b) => b.text === badge.text)) group.badges.push(badge)
1584
- }
1585
- groups.set(repo, group)
1586
- }
1587
- const weight = (g) => (g.errors > 0 ? 0 : g.silentWakes >= 2 ? 1 : 2)
1588
- return [...groups.values()].sort((a, b) => (weight(a) - weight(b)) || a.repo.localeCompare(b.repo))
1589
- }
1590
-
1591
- /** 持续时长(与服务端 watch.js:durationText 同语义)。 */
1592
- function durationText(sinceIso, untilIso) {
1593
- const from = Date.parse(String(sinceIso || ''))
1594
- const to = Date.parse(String(untilIso || ''))
1595
- if (!Number.isFinite(from) || !Number.isFinite(to) || to < from) return ''
1596
- const minutes = Math.floor((to - from) / 60000)
1597
- if (minutes < 1) return '不到 1 分钟'
1598
- if (minutes < 60) return minutes + ' 分钟'
1599
- const hours = Math.floor(minutes / 60)
1600
- const rest = minutes % 60
1601
- return rest > 0 ? hours + ' 小时 ' + rest + ' 分' : hours + ' 小时'
1602
- }
1603
-
1604
- /** 只读仓库的提示(与服务端 gh-format.js:accessNote 同语义;面板要独立一份)。 */
1605
- function accessNoteForPanel(access, repo) {
1606
- if (!access || typeof access !== 'object') return ''
1607
- if (access.push === true) return ''
1608
- if (access.push !== false) return ''
1609
- return '你对 ' + String(access.repo || repo || '这个仓库') + ' 只有读权限:能看、能被叫醒,但没法回写评论或打标签 —— ' +
1610
- '要么换有写权限的 token,要么把结论写在本地/PR 描述里。'
1611
- }
1612
-
1613
- /** 仓库能力徽章(与服务端 watch.js:repoBadges 同语义)。 */
1614
- function repoBadges(access) {
1615
- if (!access || typeof access !== 'object') return []
1616
- const badges = []
1617
- if (access.archived === true) badges.push({ text: '已归档', tone: 'warning' })
1618
- if (access.disabled === true) badges.push({ text: '已禁用', tone: 'danger' })
1619
- if (access.hasIssues === false) badges.push({ text: '无 Issues', tone: 'warning' })
1620
- if (access.fork === true && access.parent && access.hasIssues !== true) badges.push({ text: 'fork · 上游 ' + String(access.parent), tone: 'outline' })
1621
- if (access.push === false) badges.push({ text: '只读', tone: 'warning' })
1622
- if (access.private === true) badges.push({ text: '私有', tone: 'outline' })
1623
- return badges
1624
- }
1625
-
1626
- /** 仓库结构提示(与服务端 watch.js:repoStructureNote 同语义;客户端要独立一份,不能跨包 import)。 */
1627
- function repoStructureNote(access) {
1628
- if (!access || typeof access !== 'object') return ''
1629
- const repo = String(access.repo || '这个仓库')
1630
- // 顺序与服务端 gh-format.js:repoStructureNote 保持一致:归档/禁用优先
1631
- if (access.archived === true) return repo + ' 已归档:GitHub 上归档仓库是只读的,评论和打标签都会失败 —— 守它只能看、不能回写。'
1632
- if (access.disabled === true) return repo + ' 已被禁用:这个仓库当前不可用,主理鱼不会拿到任何条目。'
1633
- if (access.hasIssues === false) return repo + ' 关闭了 Issues —— 主理鱼只认 issue / PR,这里不会有任何条目可接。'
1634
- if (access.fork === true && access.parent && access.hasIssues !== true) {
1635
- return repo + ' 是 ' + String(access.parent) + ' 的 fork。fork 默认不带 Issues,issue 大多落在上游 —— 确认你要守的是哪一个。'
1636
- }
1637
- return ''
1638
- }
1639
-
1640
- /** 人话字节数:客户看的是"3.2 MB",不是 3355443。 */
1641
- function bytesText(n) {
1642
- const value = Number(n) || 0
1643
- if (value < 1024) return value + ' B'
1644
- if (value < 1024 * 1024) return (value / 1024).toFixed(1) + ' KB'
1645
- if (value < 1024 * 1024 * 1024) return (value / 1024 / 1024).toFixed(1) + ' MB'
1646
- return (value / 1024 / 1024 / 1024).toFixed(2) + ' GB'
1647
- }
1648
-
1649
- // 官方 settings-kit.tsx 的 Field:label + hint(InfoTip) + 控件 + note(small)。
1650
- // 我们之前只有 label,说明只能塞进 placeholder —— 用户看不到「这个字段到底什么意思」。
1651
- function field(label, control, hint, note) {
1652
- return h('label', { className: 'dt-field', key: label },
1653
- h('span', { className: 'dt-field-head' }, label, hint ? h(InfoTip, { text: hint }) : null),
1654
- control,
1655
- note ? h('small', null, note) : null)
1656
- }
1657
-
1658
- return h('div', { className: 'dt-page' },
1659
- h('div', { className: 'dt-page-head' },
1660
- h('div', null,
1661
- h('h1', { className: 'dt-page-title' }, '主理鱼'),
1662
- h('span', { className: 'dt-hint' },
1663
- (body.sessionTitle ? '会话:' + body.sessionTitle + ' · ' : '')
1664
- + (sessionId ? '盯办 + 主动办:仓库有动静就叫醒本会话' : '需要会话上下文'))),
1665
- h('div', { className: 'dt-toolbar' },
1666
- h(Input, { value: search, placeholder: '搜索仓库 / 编号 / 标题', onChange: (e) => setSearch(e.target.value), 'aria-label': '搜索' }),
1667
- h(Btn, { size: 'sm', variant: 'ghost', icon: h(Icon, { name: 'question' }), onClick: () => setGlossary(true) }, '术语'),
1668
- h(Btn, { size: 'sm', icon: h(Icon, { name: 'refresh' }), onClick: () => load() }, '刷新'),
1669
- watchers.length > 0 ? h(Btn, { size: 'sm', onClick: () => actBulk('pause') }, '全部暂停') : null,
1670
- watchers.length > 0 ? h(Btn, { size: 'sm', onClick: () => actBulk('resume') }, '全部恢复') : null)),
1671
- h(SegTabs, {
1672
- items: [
1673
- { value: 'overview', label: '总览' },
1674
- { value: 'judge', label: '判定' },
1675
- { value: 'trigger', label: '触发' },
1676
- { value: 'settings', label: '设置' },
1677
- ],
1678
- value: tab, onChange: setTab, label: '主理鱼分区',
1679
- }),
1680
- notice ? h('div', { className: 'dt-banner dt-danger' }, notice.text) : null,
1681
- // 有新版本时在顶部提示一次(埋在设置页里客户不会主动翻)
1682
- update && update.hasUpdate
1683
- ? h('div', { className: 'dt-banner dt-banner-actions' },
1684
- h('span', { className: 'dt-banner-label' }, '有新版本 ' + update.latest + '(当前 ' + update.current + ')'),
1685
- h('a', { className: 'dt-btn dt-btn-sm dt-btn-outline', href: '#', onClick: (e) => { e.preventDefault(); setTab('settings') } }, '看升级命令'))
1686
- : null,
1687
- toastView,
1688
- snap.error ? h('div', { className: 'dt-banner dt-danger' }, '读取失败:' + humanizeError(snap.error)) : null,
1689
- snap.loading && !snap.body ? h(Hint, null, '正在读取…') : null,
1690
- tab === 'overview' ? overview : null,
1691
- tab === 'overview' ? repoSummary : null,
1692
- tab === 'judge' ? judge : null,
1693
- tab === 'judge' ? timeline : null,
1694
- tab === 'trigger' ? trigger : null,
1695
- tab === 'settings' ? settings : null,
1696
- typeof glossary === 'string' ? h(Modal, {
1697
- open: true,
1698
- title: '建议追加到 ' + String(glossary).replace('rules:', '') + ' 的 AGENTS.md',
1699
- onClose: () => setGlossary(false),
1700
- },
1701
- h('p', { className: 'dt-hint' }, '问题通常不是"没叫醒",而是"叫醒了但没动手"。这段规则会明确要求:无论做不做,最后都要 ack。'),
1702
- h('pre', { className: 'dt-pre' }, AGENTS_SNIPPET),
1703
- h('div', { className: 'dt-actions' },
1704
- h(Btn, {
1705
- size: 'sm',
1706
- variant: 'primary',
1707
- onClick: async () => {
1708
- try {
1709
- await navigator.clipboard.writeText(AGENTS_SNIPPET)
1710
- notify('规则已复制,粘贴到 AGENTS.md 末尾即可', 'info')
1711
- } catch {
1712
- notify('复制失败:请手动选中上面的文本', 'error')
1713
- }
1714
- },
1715
- }, '复制这段规则'),
1716
- h(Btn, { size: 'sm', variant: 'ghost', onClick: () => setGlossary(false) }, '关闭'))) : null,
1717
- h(Modal, { open: glossary === true, title: '主理鱼术语表', onClose: () => setGlossary(false) },
1718
- h(KeyValues, { rows: [
1719
- ['主理鱼', '一条「盯办」绑定:某个仓库 → 某个会话'],
1720
- ['盯', '轮询 issue/PR、按水位去重、冷却期吸收自己的操作'],
1721
- ['办', '唤醒会话后按仓库 AGENTS.md 主动处理,完成后 watch_ack 打标签'],
1722
- ['唤醒', '只在会话空闲(idle)时注入一条【主理鱼】消息'],
1723
- ['过滤', '标签白名单/黑名单、只看已指派、跳过机器人/草稿/已关闭'],
1724
- ['时段', 'activeHours,比如 09:00-23:00,时段外只攒不唤醒'],
1725
- ['隔离', 'isolated:每次唤醒开一次性 git worktree,改副本不碰主工作区'],
1726
- ['ack', '处理完给条目打「主理鱼:已处理」标签,轮询直接跳过'],
1727
- ['goal', '会话目标(ctx.goals),和 /goal 命令同一份状态'],
1728
- ['凭证', 'token 存在服务端 secrets.json,面板只显示是否已配置'],
1729
- ['上限', '两种:单条守每小时最多 6 次、整条会话 12 次(面板里可调);和 GitHub 的限流不是一回事'],
1730
- ['没有动作', '叫醒后会话没有调用 watch_ack(既没改也没回),连续 2 次就会在「需要关注」里提示'],
1731
- ['临时副本', '隔离执行开的一次性 git worktree:只在这里改,用完回收,不碰主工作区'],
1732
- ] })))
1733
- }
1734
-
1735
-
1736
- return {
1737
- inject: ['slots'],
1738
- apply(ctx) {
1739
- try { noteOnce('client-version', CLIENT_VERSION) } catch {}
1740
- try { note('apply', 'start') } catch {}
1741
-
1742
- // ① the 主理鱼 tab in the centre-column view ring
1743
- ctx.effect(() => {
1744
- try {
1745
- return ctx.slots.inject('conversation.view', () => {
1746
- const dispose = ctx.slots.register({
1747
- name: 'conversation.view',
1748
- id: 'session-superagent-desk',
1749
- order: 30,
1750
- label: '主理鱼',
1751
- }, ZhuliPanel)
1752
- note('desk-registered', 'ok')
1753
- return dispose
1754
- })
1755
- } catch (error) {
1756
- note('desk-fail', String((error && error.message) || error))
1757
- return undefined
1758
- }
1759
- })
1760
-
1761
- // ② the machine-wide orbit in the composer dock row — the same row as
1762
- // 轮/步 · token 用量 · 上下文环. One ring, one satellite per live
1763
- // session-level superagent; click opens the per-agent detail list.
1764
- ctx.effect(() => {
1765
- try {
1766
- return ctx.slots.inject('conversation.composer.dock', () => {
1767
- const dispose = ctx.slots.register({
1768
- name: 'conversation.composer.dock',
1769
- id: 'session-superagent-orbit',
1770
- order: -10, // 最左端:activity/usage 是 0/1,上下文环在槽位之外
1771
-
1772
- }, StatusOrbit)
1773
- note('orbit-registered', 'ok')
1774
- return dispose
1775
- })
1776
- } catch (error) {
1777
- note('orbit-fail', String((error && error.message) || error))
1778
- return undefined
1779
- }
1780
- })
1781
-
1782
- note('apply', 'done')
1783
- },
1784
- }
1785
- },
1786
- })
1
+ /**
2
+ * dsh-session-superagent — browser half.
3
+ *
4
+ * Registers one list entry into `conversation.view` (the centre-column view
5
+ * ring: chat / trajectory / waterfall live there), so the panel appears as a
6
+ * tab beside them. It reads the read-only host route the server half
7
+ * registers; no credential ever crosses this boundary.
8
+ */
9
+ window.__ModuleLoader__.load({
10
+ id: 'dsh-session-superagent',
11
+ factory(require) {
12
+ const React = require('react')
13
+ const h = React.createElement
14
+ const { useCallback, useEffect, useRef, useState } = React
15
+
16
+ // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
+ const CLIENT_VERSION = '0.9.68'
18
+ let BASE = '/session-superagent'
19
+ /**
20
+ * 挑「最新的那个服务端实例」。
21
+ *
22
+ * 宿主重载时旧 handler 摘不掉,所以可能同时存在多个前缀:默认的(旧代码)和 `/rN`(新代码)。
23
+ * 甚至出现过「新实例在默认前缀注册成功、但请求仍被旧 handler 接走」的情况 ——
24
+ * 所以不能只看「注册成功」,要按实例自报的版本 + routeBase 匹配来选。
25
+ */
26
+ async function discoverBase() {
27
+ const candidates = [BASE]
28
+ for (let i = 2; i <= 8; i += 1) candidates.push('/session-superagent/r' + i)
29
+ const versionScore = (v) => {
30
+ const parts = String(v || '0').split('.').map((n) => Number(n) || 0)
31
+ return parts[0] * 1e6 + parts[1] * 1e3 + parts[2]
32
+ }
33
+ let best = null
34
+ for (const base of candidates) {
35
+ try {
36
+ const res = await fetch(base + '/state', { headers: { accept: 'application/json' } })
37
+ if (!res.ok) continue
38
+ const body = await res.json()
39
+ // 只有「自报前缀 = 我请求的前缀」才说明这个实例真的在这条路径上服务
40
+ if (!body || body.routeBase !== base) continue
41
+ const score = versionScore(body.serverVersion)
42
+ if (!best || score > best.score) best = { base, score }
43
+ } catch {}
44
+ }
45
+ if (best && best.base !== BASE) {
46
+ BASE = best.base
47
+ // 记一笔:排查「面板到底在跟哪一代」时用得上(不像轮询那样完全不落痕迹)
48
+ try { note('client-base', BASE) } catch {}
49
+ } else if (best) {
50
+ BASE = best.base
51
+ }
52
+ return BASE
53
+ }
54
+
55
+ const POLL_MS = 5000
56
+
57
+ // 上一次 /state 的 ETag:带上它,没变化时服务端回 304,省掉整份 JSON
58
+ let stateEtag = null
59
+
60
+ async function call(path, options, retried) {
61
+ const init = {
62
+ ...(options || {}),
63
+ headers: { 'content-type': 'application/json', accept: 'application/json', ...((options && options.headers) || {}) },
64
+ }
65
+ let res
66
+ try {
67
+ res = await fetch(BASE + path, init)
68
+ } catch (error) {
69
+ // 前缀失效(这一代被新实例接管并释放了):重新探一次再试,还不行就把错抛出去
70
+ if (retried) throw error
71
+ await discoverBase()
72
+ return call(path, options, true)
73
+ }
74
+ // 旧前缀被释放后宿主会 404:同样重探一次
75
+ if (res.status === 404 && !retried) {
76
+ await discoverBase()
77
+ return call(path, options, true)
78
+ }
79
+ // 304:内容没变(服务端带 ETag)。不是错误,也没有正文。
80
+ if (res.status === 304) {
81
+ const etag = res.headers && res.headers.get ? res.headers.get('etag') : null
82
+ if (etag) stateEtag = etag
83
+ return { notModified: true }
84
+ }
85
+ const freshEtag = res.headers && res.headers.get ? res.headers.get('etag') : null
86
+ if (freshEtag && path.startsWith('/state')) stateEtag = freshEtag
87
+ const text = await res.text()
88
+ let body = null
89
+ try { body = text ? JSON.parse(text) : null } catch { body = { raw: text } }
90
+ if (!res.ok) throw new Error((body && body.error) || ('HTTP ' + res.status))
91
+ return body
92
+ }
93
+
94
+ const S = {
95
+ wrap: { padding: '16px 20px', font: '13px/1.5 system-ui, sans-serif', height: '100%', overflow: 'auto' },
96
+ title: { fontSize: 15, fontWeight: 600, margin: '0 0 4px' },
97
+ sub: { opacity: 0.65, margin: '0 0 14px' },
98
+ row: { display: 'grid', gridTemplateColumns: '1.4fr 1fr 70px 1.2fr 1.2fr 70px 112px', gap: 10, padding: '7px 0', borderBottom: '1px solid rgba(128,128,128,.18)' },
99
+ head: { fontWeight: 600, opacity: 0.7, borderBottom: '1px solid rgba(128,128,128,.35)' },
100
+ mono: { fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 12 },
101
+ badgeOn: { color: '#1a7f37' },
102
+ badgeOff: { color: '#9a6700' },
103
+ err: { color: '#cf222e', fontSize: 12 },
104
+ empty: { opacity: 0.6, marginTop: 12 },
105
+ foot: { marginTop: 14, opacity: 0.55, fontSize: 12 },
106
+ card: { border: '1px solid rgba(128,128,128,.25)', borderRadius: 8, padding: '12px 14px', marginBottom: 14 },
107
+ cardTitle: { fontWeight: 600, margin: '0 0 8px' },
108
+ field: { display: 'flex', gap: 8, alignItems: 'center', marginBottom: 8, flexWrap: 'wrap' },
109
+ label: { minWidth: 72, opacity: 0.75 },
110
+ input: { flex: 1, minWidth: 180, padding: '5px 8px', borderRadius: 6, border: '1px solid rgba(128,128,128,.4)', background: 'transparent', color: 'inherit', font: 'inherit' },
111
+ button: { padding: '5px 12px', borderRadius: 6, border: '1px solid rgba(128,128,128,.5)', background: 'rgba(128,128,128,.12)', color: 'inherit', cursor: 'pointer' },
112
+ tiny: { padding: '2px 8px', fontSize: 11, lineHeight: '16px', borderRadius: 5, border: '1px solid rgba(128,128,128,.45)', background: 'transparent', color: 'inherit', cursor: 'pointer' },
113
+ ok: { color: '#1a7f37', fontSize: 12 },
114
+ }
115
+
116
+ // ── 移植自官方 dsh-superagent 的设计系统(scripts/port-official-ui.mjs 生成)──
117
+ // 官方 GUI 的 376 条选择器 / 40KB 样式原样搬过来,类名统一 `dt-` 前缀,不污染宿主。
118
+ const PORTED_CSS = "/* Panel layout and local UI controls styled with DSH `--dsw-alias-*` design tokens; one rule per line. */\n.dt-page { box-sizing: border-box; height: 100%; overflow: auto; scrollbar-gutter: stable; scroll-padding: 48px 0 72px; container-type: inline-size; padding: 28px clamp(24px, 4vw, 48px) 0; color: var(--dsw-alias-label-primary); }\n/* Deployment page rendered inside DSH Plugin Manager, which owns scrolling and padding. */\n.dt-embedded { container-type: inline-size; color: var(--dsw-alias-label-primary); }\n/* Disable sticky positioning inside DSH Plugin Manager, where the host container owns scrolling and bottom padding. */\n.dt-embedded .dt-savebar { position: static; }\n.dt-page > .dt-column { max-width: 960px; margin: 0 auto; padding-bottom: 48px; display: flex; flex-direction: column; gap: 24px; }\n.dt-head { position: relative; z-index: 3; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }\n.dt-search { position: relative; width: 240px; max-width: 100%; }\n.dt-search-results { position: absolute; top: calc(100% + 6px); right: 0; width: min(560px, 90cqw); max-height: 60vh; overflow: auto; padding: 8px 16px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 12px; background: var(--dsw-alias-bg-layer-2); box-shadow: var(--dsw-elevation-prominent); z-index: 5; display: flex; flex-direction: column; gap: 8px; }\n.dt-mark { background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 25%, transparent); color: inherit; border-radius: 2px; }\n[data-platform='darwin'] .dt-page .dt-head { padding-top: var(--dsh-frame-top-clearance, 0px); }\n.dt-title { margin: 0; font-size: 15px; line-height: 22px; font-weight: 600; color: var(--dsw-alias-label-secondary); }\n.dt-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }\n.dt-page .dt-tabs { overflow-x: auto; display: flex; gap: 20px; max-width: none; padding: 0; border-radius: 0; background: none; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-segmented { width: 100%; max-width: 420px; box-sizing: border-box; display: inline-grid; gap: 2px; padding: 3px; border-radius: 9px; background: var(--dsw-alias-interactive-bg-hover); }\n.dt-form.dt-block { padding: 16px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 16px; gap: 16px; }\n.dt-block-title { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 16px; line-height: 24px; font-weight: 500; }\n.dt-section { display: flex; flex-direction: column; gap: 8px; min-width: 0; }\n.dt-section-title { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--dsw-alias-label-secondary); }\n.dt-section-name { white-space: nowrap; }\n.dt-count { font-size: 14px; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; font-weight: 400; }\n.dt-hint { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-tertiary); }\n.dt-error { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-state-error-primary); }\n.dt-banner { margin: 0; padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 20px; background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 10%, transparent); overflow-wrap: anywhere; }\n.dt-banner.dt-danger { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent); }\n.dt-list { list-style: none; margin: 0 -8px; padding: 0; display: flex; flex-direction: column; gap: 2px; }\n.dt-row { position: relative; min-width: 0; border-radius: 12px; padding: 10px 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: flex-start; }\n.dt-row.dt-link:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-row-main { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }\n.dt-disclosure-body .dt-row-main { flex-basis: 0; }\n.dt-row-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; line-height: 20px; font-weight: 500; }\n.dt-open { max-width: 100%; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-size: 14px; line-height: 20px; font-weight: 500; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-open::after { content: ''; position: absolute; inset: 0; border-radius: 12px; }\n.dt-open:focus-visible { outline: none; }\n.dt-open-wrap { white-space: normal; }\n.dt-open:focus-visible::after { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-caption); overflow-wrap: anywhere; }\n.dt-row-quote { font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }\n/* Transparent block borders preserve vertical spacing when line clamping clips padding. */\n.dt-banner:is(.dt-clamp, .dt-clamp-8) { padding-block: 0; border-block: 8px solid transparent; }\n.dt-banner-label { font-weight: 500; }\n.dt-banner .dt-md { display: inline; }\n.dt-banner .dt-md > p:first-child { display: inline; }\n.dt-row-buttons { position: relative; z-index: 1; gap: 8px; margin-top: 4px; }\n.dt-row-actions { position: relative; z-index: 1; display: flex; align-items: center; gap: 4px; flex: none; margin-left: auto; font-size: 13px; line-height: 20px; }\n.dt-dot { flex: none; margin-top: 5px; }\n.dt-inline-link { position: relative; z-index: 1; color: var(--dsw-alias-link); text-decoration: none; }\n.dt-inline-link:hover { text-decoration: underline; }\n.dt-textlink { padding: 0; border: 0; background: none; font: inherit; color: var(--dsw-alias-link); cursor: pointer; text-align: left; }\n.dt-textlink:hover { text-decoration: underline; }\n.dt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; line-height: 20px; }\n.dt-kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13px; line-height: 20px; }\n.dt-kv dt { color: var(--dsw-alias-label-tertiary); }\n.dt-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }\n.dt-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }\n.dt-event { padding: 12px 0; border-bottom: 0.5px solid var(--dsw-alias-border-l2); display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.dt-event:last-child { border-bottom: 0; }\n.dt-event.dt-highlight { background: var(--dsw-alias-interactive-bg-hover); border-radius: 8px; padding-inline: 8px; margin-inline: -8px; }\n.dt-event-text { margin: 0; font-size: 13px; line-height: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }\n.dt-event-actor { font-weight: 500; color: var(--dsw-alias-label-secondary); }\n.dt-event-quiet .dt-event-text { color: var(--dsw-alias-label-tertiary); }\n.dt-flow { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n.dt-clamp-8 { display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }\n.dt-more { align-self: flex-start; font-size: 12px; }\n.dt-reveal { opacity: 0; }\n.dt-event:hover .dt-reveal, .dt-reveal:focus-visible { opacity: 1; }\n@media (hover: none) {\n .dt-reveal { opacity: 1; }\n}\n.dt-event-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n.dt-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }\n.dt-filters .dt-search { margin-left: auto; }\n.dt-form { display: flex; flex-direction: column; gap: 24px; }\n.dt-fieldset { display: flex; flex-direction: column; gap: inherit; min-width: 0; margin: 0; padding: 0; border: 0; }\n.dt-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 20px; min-width: 0; }\n.dt-field small { color: var(--dsw-alias-label-caption); font-size: 12px; }\n.dt-textarea { box-sizing: border-box; width: 100%; min-width: 0; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1, transparent); resize: vertical; }\n.dt-select { box-sizing: border-box; width: 100%; min-width: 0; height: 32px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: 8px; padding: 0 28px 0 8px; text-overflow: ellipsis; font: inherit; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1, transparent); }\n.dt-textarea:focus-visible, .dt-select:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }\n.dt-mono { font-family: var(--ds-font-family-code, Menlo, monospace); font-size: 12px; overflow-wrap: anywhere; }\n.dt-detail { margin-top: 2px; color: var(--dsw-alias-label-secondary); }\n.dt-savebar .dt-error { white-space: pre-line; }\n.dt-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 36px; font-size: 13px; }\n.dt-subhead-actions { display: inline-flex; align-items: center; gap: 4px; }\n.dt-btn-busy .dt-btn-icon svg { animation: dt-spin 1s linear infinite; }\n.dt-subhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n.dt-rules, .dt-changes { list-style: none; margin: 0; padding: 0; }\n.dt-field-head { display: inline-flex; align-items: center; gap: 4px; color: var(--dsw-alias-label-secondary); }\n.dt-info { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; padding: 0; border: 0; background: none; color: var(--dsw-alias-label-caption); cursor: help; }\n.dt-info:hover, .dt-info:focus-visible { color: var(--dsw-alias-label-secondary); }\n.dt-info:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; border-radius: 50%; }\n.dt-tooltip { position: fixed; z-index: 1100; width: max-content; max-width: min(320px, calc(100vw - 24px)); padding: 3px 7px; border-radius: 8px; background: var(--dsw-alias-tooltip-bg); color: var(--dsw-static-neutral-bluish-00); font-size: 13px; line-height: 20px; overflow-wrap: break-word; pointer-events: none; animation: dt-tooltip-in 150ms ease-in-out; }\n@keyframes dt-tooltip-in { from { opacity: 0; } }\n.dt-rules { border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-rule { display: flex; align-items: flex-start; gap: 12px; padding: 6px 0; border-bottom: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-rule > :first-child { flex: 1; min-width: 0; }\n.dt-rule-preview { flex: 1; min-width: 0; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--dsw-alias-label-caption); }\n.dt-rule-switch { margin-top: 2px; flex: none; }\n.dt-rule-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dsw-alias-label-caption); }\n.dt-rule-dot[data-enabled] { background: var(--dsw-alias-brand-primary); }\n.dt-rule-body { display: flex; flex-direction: column; gap: 12px; padding: 8px 0 8px 28px; }\n.dt-model { display: flex; flex-direction: column; gap: 6px; }\n.dt-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }\n.dt-changes { display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 20px; }\n.dt-changes li::before { content: '· '; color: var(--dsw-alias-label-caption); }\n.dt-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }\n.dt-modal.dt-glossary-modal { width: min(680px, 100%); }\n.dt-nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 32px; padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; line-height: 20px; text-align: left; cursor: pointer; }\n.dt-nav-item:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-nav-item[aria-current='true'] { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); font-weight: 500; }\n.dt-nav-item:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }\n.dt-changed-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-brand-primary); flex: none; }\n.dt-add-skill { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-prompt-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }\n.dt-editor { min-height: 360px; }\n.dt-inline-select { width: auto; }\n.dt-preview-part { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 2px 12px; border-left: 2px solid var(--dsw-alias-border-l3); }\n.dt-preview-head { font-size: 13px; line-height: 20px; display: flex; align-items: baseline; gap: 8px; }\ndiv.dt-preview-head { color: var(--dsw-alias-label-secondary); }\n.dt-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 16px; min-width: 0; }\n.dt-card-head { display: flex; align-items: center; gap: 12px; min-height: 28px; }\n.dt-card-head .dt-row-main { flex: 1 1 0; min-width: 64px; }\n.dt-card-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-row-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; }\n.dt-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }\n.dt-rows-item { display: grid; grid-template-columns: repeat(var(--dt-columns), minmax(0, 1fr)) auto; gap: 8px; align-items: center; }\n.dt-filter-gap { flex: 1; }\n.dt-page-head { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }\n.dt-page-head > .dt-btn { margin-left: -10px; }\n.dt-page-title { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; width: 100%; }\n.dt-page-title h2 { margin: 0; flex: 1 1 auto; min-width: 0; font-size: 20px; line-height: 28px; font-weight: 500; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }\n.dt-status-line { margin-top: -16px; }\n.dt-plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; line-height: 20px; }\n.dt-details { display: flex; flex-direction: column; gap: 2px; border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 8px; }\n.dt-danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 16px; border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-danger-zone .dt-btn { color: var(--dsw-alias-state-error-primary); }\n.dt-md { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }\n.dt-md p, .dt-md ul, .dt-md ol { margin: 0; }\n.dt-md ul, .dt-md ol { padding-left: 20px; display: flex; flex-direction: column; gap: 2px; }\n.dt-md-heading { font-weight: 500; }\n.dt-code { font-family: var(--ds-font-family-code, Menlo, monospace); font-size: 12px; padding: 0 4px; border-radius: 4px; background: var(--dsw-alias-bg-module-platform); }\n.dt-dot-wrap { display: inline-flex; flex: none; }\n.dt-search-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.dt-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }\n.dt-legend-title { margin: 16px 0 6px; font-size: 13px; color: var(--dsw-alias-label-tertiary); }\n.dt-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }\n.dt-legend li { display: flex; align-items: center; gap: 6px; }\n.dt-legend .dt-dot { margin-top: 0; }\n.dt-savebar { position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 12px 0; background: var(--dsw-alias-bg-base, var(--dsw-alias-bg-layer-1)); border-top: 0.5px solid var(--dsw-alias-border-l2); }\n.dt-savebar .dt-hint { margin-right: auto; }\n.dt-card > .dt-savebar, .dt-block > .dt-savebar { margin: 0 -16px -16px; padding: 12px 16px; border-radius: 0 0 16px 16px; }\n.dt-glossary { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 20px; }\n.dt-glossary th, .dt-glossary td { text-align: left; padding: 6px 8px; border-bottom: 0.5px solid var(--dsw-alias-border-l2); vertical-align: top; }\n.dt-glossary th { color: var(--dsw-alias-label-tertiary); font-weight: 400; }\n.dt-glossary th.dt-glossary-group { color: var(--dsw-alias-label-secondary); font-weight: 600; padding-top: 14px; }\n.dt-glossary th:nth-child(-n+2), .dt-glossary td:nth-child(-n+2) { white-space: nowrap; }\n.dt-values { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 16px 0 0; font-size: 13px; }\n.dt-values dt { color: var(--dsw-alias-label-tertiary); }\n.dt-values dd { margin: 0; }\n.dt-pre { margin: 0; padding: 12px; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); font-family: var(--ds-font-family-code, Menlo, monospace); font-size: 12px; line-height: 18px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow: auto; }\n.dt-pre ins { background: color-mix(in srgb, var(--dsw-alias-state-success-primary, green) 18%, transparent); text-decoration: none; }\n.dt-pre del { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 18%, transparent); text-decoration: none; }\n.dt-prompt { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; align-items: start; }\n.dt-prompt-nav { display: flex; flex-direction: column; gap: 2px; }\n.dt-prompt-nav button { justify-content: flex-start; }\n.dt-disclosure-body { padding: 8px 0 8px 28px; display: flex; flex-direction: column; gap: 8px; }\n@container (max-width: 640px) {\n .dt-tab { padding: 0 8px; font-size: 13px; }\n .dt-segment { padding: 0 10px; }\n .dt-head { align-items: center; }\n .dt-search-results { right: auto; left: 0; width: 100%; }\n .dt-page-title h2 { font-size: 17px; line-height: 24px; }\n .dt-status-line { margin-top: -12px; }\n .dt-page .dt-tabs { display: flex; flex-wrap: nowrap; scrollbar-width: thin; }\n .dt-page .dt-tab { flex: none; }\n .dt-page .dt-tabs[data-more='end'] { mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }\n .dt-page .dt-tabs[data-more='start'] { mask-image: linear-gradient(to right, transparent, #000 40px); }\n .dt-page .dt-tabs[data-more='both'] { mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }\n .dt-kv { grid-template-columns: 1fr; gap: 2px; }\n .dt-grid3, .dt-prompt { grid-template-columns: 1fr; }\n .dt-search { width: 100%; }\n .dt-filters .dt-search { margin-left: 0; }\n}\n/* Local UI primitive styles (see controls.tsx). */\n.dt-btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: none; border-radius: 18px; cursor: pointer; font: inherit; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); background: transparent; padding: 0 14px; white-space: nowrap; }\n.dt-btn:disabled { cursor: not-allowed; opacity: 0.4; }\n.dt-btn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-btn-md { height: 36px; }\n.dt-btn-sm { height: 28px; font-size: 12px; line-height: 18px; padding: 0 10px; border-radius: 14px; }\n.dt-btn-primary { background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground); }\n.dt-btn-primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }\n.dt-btn-ghost:hover:not(:disabled), .dt-btn-outline:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-btn-ghost:active:not(:disabled) { background: var(--dsw-alias-interactive-bg-active); }\n.dt-btn-outline { border: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-btn-icon { display: inline-flex; width: 16px; height: 16px; align-items: center; justify-content: center; }\n.dt-tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 1px 8px; font-size: 11px; line-height: 17px; font-weight: 500; white-space: nowrap; }\n.dt-tag[data-tone='outline'] { border: 0.5px solid var(--dsw-alias-border-l4); color: var(--dsw-alias-label-tertiary); }\n.dt-tag[data-tone='neutral'] { background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); }\n.dt-tag[data-tone='quiet'] { color: var(--dsw-alias-label-tertiary); }\n.dt-tag[data-tone='success'] { background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 10%, transparent); color: var(--dsw-alias-state-success-primary); }\n.dt-tag[data-tone='info'] { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 10%, transparent); color: var(--dsw-alias-state-business-primary); }\n.dt-tag[data-tone='warning'] { background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 12%, transparent); color: var(--dsw-alias-state-warn-primary); }\n.dt-tag[data-tone='danger'] { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent); color: var(--dsw-alias-state-error-primary); }\n.dt-pill { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border: none; border-radius: 12px; font: inherit; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-2); cursor: pointer; }\n.dt-pill:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-pill-active, .dt-pill-active:hover { color: var(--dsw-alias-label-primary); background: var(--dsw-alias-button-ghost-active-fill); box-shadow: inset 0 0 0 1px var(--dsw-alias-button-ghost-active-border); }\n.dt-tabs { display: grid; padding: 4px; border-radius: 12px; background: var(--dsw-alias-bg-module-platform); }\n.dt-tab { box-sizing: border-box; height: 34px; padding: 0 12px; border: 0.5px solid transparent; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 14px; line-height: 20px; white-space: nowrap; cursor: pointer; transition: color 180ms ease, background 180ms ease; }\n.dt-tab:hover { color: var(--dsw-alias-label-primary); }\n.dt-tab[aria-selected='true'] { color: var(--dsw-alias-label-primary); font-weight: 600; background: var(--dsw-alias-bg-layer-3); border-color: var(--dsw-alias-border-l3); }\n.dt-tab:focus-visible { outline: none; text-decoration: underline; text-underline-offset: 4px; }\n.dt-segment { height: 28px; padding: 0 16px; border: 0; border-radius: 7px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; line-height: 20px; font-weight: 500; white-space: nowrap; cursor: pointer; transition: color 120ms ease, background 160ms ease; }\n.dt-segment:hover:not(:disabled), .dt-segment[aria-selected='true'] { color: var(--dsw-alias-label-primary); }\n.dt-segment[aria-selected='true'] { background: var(--dsw-alias-bg-layer-1); box-shadow: var(--dsw-elevation-soft); }\n.dt-segment:disabled { cursor: default; opacity: 0.4; }\n.dt-segment:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }\n.dt-input { box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; height: 32px; min-width: 0; padding: 0 8px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: 8px; background: var(--dsw-alias-bg-layer-1); }\n.dt-input:focus-within { border-color: var(--dsw-alias-brand-primary); }\n.dt-input-icon { display: inline-flex; width: 16px; height: 16px; align-items: center; justify-content: center; color: var(--dsw-alias-label-tertiary); }\n.dt-input input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font: inherit; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); }\n.dt-input input::placeholder { color: var(--dsw-alias-label-dimmed); }\n.dt-input input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }\n.dt-field .dt-input, .dt-search .dt-input, .dt-add-skill .dt-input { display: flex; width: 100%; }\n.dt-switch { box-sizing: border-box; flex: 0 0 auto; width: 36px; height: 20px; padding: 2px; border: 0; border-radius: 10px; background: var(--dsw-alias-border-l3); cursor: pointer; }\n.dt-switch[aria-checked='true'] { background: var(--dsw-alias-brand-primary); }\n.dt-switch:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-switch-thumb { display: block; width: 16px; height: 16px; border-radius: 50%; background: var(--dsw-alias-label-primary-foreground); transition: transform 120ms ease; }\n.dt-switch[aria-checked='true'] .dt-switch-thumb { transform: translateX(16px); }\n.dt-state-dot { position: relative; display: inline-block; flex: none; width: 10px; height: 10px; color: var(--dsw-alias-state-idle-primary); }\n.dt-state-dot::after { content: ''; position: absolute; inset: 20%; border-radius: 50%; background: currentColor; }\n.dt-state-dot[data-state='done'] { color: var(--dsw-alias-state-success-primary); }\n.dt-state-dot[data-state='warning'] { color: var(--dsw-alias-state-warn-primary); }\n.dt-state-dot[data-state='error'] { color: var(--dsw-alias-state-error-primary); }\n.dt-spinner { flex: none; color: var(--dsw-alias-label-tertiary); }\n.dt-spinner g { transform-origin: center; animation: dt-spin 1.5s linear infinite; }\n.dt-spinner circle { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.dt-spinner circle:first-child { opacity: 0.25; }\n.dt-spinner circle:last-child { stroke-dasharray: 18 150; }\n@keyframes dt-spin { to { transform: rotate(360deg); } }\n.dt-disclosure-row { display: flex; align-items: center; gap: 4px; min-height: 28px; min-width: 0; border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n.dt-disclosure-row:hover { color: var(--dsw-alias-label-primary); }\n.dt-disclosure-row:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dt-disclosure-lead { position: relative; display: inline-flex; flex: none; width: 24px; height: 24px; align-items: center; justify-content: center; }\n.dt-disclosure-icon { display: inline-flex; align-items: center; justify-content: center; }\n.dt-disclosure-chevron { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }\n.dt-disclosure-row:hover .dt-disclosure-icon, .dt-disclosure[data-open] .dt-disclosure-icon { visibility: hidden; }\n.dt-disclosure-row:hover .dt-disclosure-chevron, .dt-disclosure[data-open] .dt-disclosure-chevron { display: inline-flex; }\n.dt-disclosure-title { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-modal-root { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: max(24px, var(--dsh-frame-top-clearance, 24px)) 24px; }\n.dt-modal-mask { position: absolute; inset: 0; background: var(--dsw-alias-bg-mask-1); backdrop-filter: var(--dsw-mask-blur); }\n.dt-modal { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 20px; width: min(380px, 100%); max-height: 100%; padding: 0 0 24px; overflow: hidden; border-radius: 24px; background: var(--dsw-alias-bg-layer-2); box-shadow: var(--dsw-elevation-prominent); color: var(--dsw-alias-label-primary); outline: none; }\n.dt-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 22px 14px 0 24px; }\n.dt-modal-header h2 { margin: 0; font-size: 16px; line-height: 24px; font-weight: 500; }\n.dt-modal-close { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: none; border-radius: 8px; background: transparent; cursor: pointer; color: var(--dsw-alias-label-secondary); }\n.dt-modal-close:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-modal-description { margin: -8px 0 0; padding: 0 24px; font-size: 14px; line-height: 22px; }\n.dt-modal-body { min-width: 0; min-height: 0; overflow: auto; padding: 0 24px; }\n.dt-modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 24px; }\n.dt-toast { position: fixed; top: 40px; left: 50%; z-index: 1100; pointer-events: none; width: max-content; max-width: min(640px, calc(100vw - 48px)); padding: 12px 16px; border-radius: 14px; background: var(--dsw-alias-toast-bg); color: var(--dsw-static-neutral-bluish-00); font-size: 14px; line-height: 22px; box-shadow: var(--dsw-shadow-lv3); transform: translateX(-50%); animation: dt-toast-in 160ms ease-out, dt-toast-fade 1000ms ease var(--dt-toast-hold, 3000ms) forwards; }\n@keyframes dt-toast-in { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }\n@keyframes dt-toast-fade { to { opacity: 0; visibility: hidden; } }\n@media (prefers-reduced-motion: reduce) {\n .dt-tab, .dt-segment, .dt-switch-thumb, .dt-spinner g, .dt-btn-busy .dt-btn-icon svg, .dt-tooltip { transition: none; animation: none; }\n .dt-toast { animation: dt-toast-fade 1000ms ease var(--dt-toast-hold, 3000ms) forwards; }\n}\n.dt-page .dt-tab { height: 34px; padding: 0 2px; border: 0; border-radius: 0; color: var(--dsw-alias-label-tertiary); font-size: 14px; }\n.dt-page .dt-tab[aria-selected='true'] { background: none; color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: inset 0 -1.5px 0 var(--dsw-alias-label-primary); }\n.dt-status-head { display: flex; align-items: center; gap: 8px; }\n.dt-status-title { margin: 0; flex: 1; display: flex; align-items: center; gap: 4px; font-size: 15px; line-height: 22px; font-weight: 600; }\n.dt-status-text { margin-left: auto; flex: none; font-size: 12px; font-weight: 400; color: var(--dsw-alias-label-secondary); }\n.dt-status-line .dt-status-text { margin-left: 0; }\n.dt-status-text[data-state='warning'] { color: var(--dsw-alias-state-warn-primary); }\n.dt-status-text[data-state='error'] { color: var(--dsw-alias-state-error-primary); }\n.dt-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.dt-lv { white-space: nowrap; }\n.dt-lv-label { color: var(--dsw-alias-label-caption); }\n.dt-lv-value { color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }\n.dt-chip { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 6px; overflow: hidden; font-size: 11px; line-height: 18px; color: var(--dsw-alias-label-secondary); }\n.dt-chip-source { padding: 0 6px; color: var(--dsw-alias-label-tertiary); background: var(--dsw-alias-bg-module-platform); }\n.dt-chip-fact { padding: 0 6px; border-left: 0.5px solid var(--dsw-alias-border-l3); white-space: nowrap; }\n.dt-chip-label { margin-right: 4px; color: var(--dsw-alias-label-caption); }\n.dt-chip-link { position: relative; z-index: 1; text-decoration: none; cursor: pointer; transition: border-color 120ms ease; }\n.dt-chip-link:hover { border-color: var(--dsw-alias-brand-primary); }\n.dt-chip-link:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }\n.dt-chip-open { display: inline-flex; align-items: center; padding: 0 5px; border-left: 0.5px solid var(--dsw-alias-border-l3); color: var(--dsw-alias-brand-primary); }\n.dt-chip-problem, .dt-chip-problem .dt-chip-label { color: var(--dsw-alias-state-error-primary); }\n.dt-cards { gap: 8px; }\n.dt-att .dt-inline-link { font-size: 13px; font-weight: 500; }\n.dt-list > .dt-att { margin: 2px 8px; }\n.dt-att { padding: 10px 12px 10px 16px; border: 0; border-radius: 0; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-att::before { content: ''; position: absolute; left: 6px; top: 10px; bottom: 10px; width: 2px; border-radius: 1px; background: var(--dsw-alias-state-warn-primary); opacity: 0.7; }\n.dt-att-error::before { background: var(--dsw-alias-state-error-primary); }\n.dt-att-what { font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-state-warn-primary); }\n.dt-att-error .dt-att-what, .dt-att-error .dt-att-what .dt-open { color: var(--dsw-alias-state-error-primary); }\n.dt-stats { display: flex; flex-wrap: wrap; gap: 6px 20px; }\n.dt-stat { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--dsw-alias-label-caption); }\n.dt-stat-value { font-size: 14px; font-weight: 500; color: var(--dsw-alias-label-primary); font-variant-numeric: tabular-nums; }\n.dt-more-link { font-size: 12px; font-weight: 400; }\n.dt-settings { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 24px; align-items: start; }\n.dt-settings-nav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }\n.dt-settings-link { padding: 6px 10px; border: 0; border-radius: 8px; background: none; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }\n.dt-settings-link:hover { color: var(--dsw-alias-label-primary); }\n.dt-settings-link[aria-current='page'] { background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-primary); font-weight: 500; }\n.dt-settings-link[data-stage] + .dt-settings-link:not([data-stage]) { margin-top: 10px; }\n.dt-settings-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }\n.dt-settings-title { margin: 0; font-size: 15px; line-height: 22px; font-weight: 600; }\n.dt-subtabs { display: flex; gap: 16px; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-subtab { padding: 0 0 6px; border: 0; background: none; color: var(--dsw-alias-label-tertiary); font: inherit; font-size: 13px; cursor: pointer; }\n.dt-subtab[aria-selected='true'] { color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: inset 0 -1.5px 0 var(--dsw-alias-label-primary); }\n.dt-part { display: flex; flex-direction: column; gap: 12px; }\n.dt-rows-summary { text-align: left; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }\n.dt-table { width: 100%; border-collapse: collapse; font-size: 12px; line-height: 18px; }\n.dt-table th { text-align: left; font-weight: 400; color: var(--dsw-alias-label-caption); padding: 2px 8px 2px 0; }\n.dt-table td { padding: 4px 8px 4px 0; border-top: 0.5px solid var(--dsw-alias-border-l3); vertical-align: top; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }\n@container (max-width: 640px) {\n .dt-settings { grid-template-columns: 1fr; gap: 12px; }\n .dt-settings-nav { position: static; flex-direction: row; flex-wrap: wrap; }\n .dt-settings-link[data-stage] + .dt-settings-link:not([data-stage]) { margin-top: 0; }\n .dt-page .dt-tabs { gap: 14px; }\n}\n.dt-list > .dt-ticket { display: grid; grid-template-columns: 112px minmax(0, 1fr); column-gap: 12px; align-items: start; margin: 0; padding: 12px 8px 12px 18px; border-radius: 0; border-bottom: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-list > .dt-ticket[data-state]::before { content: ''; position: absolute; left: 6px; top: 12px; bottom: 12px; width: 2px; border-radius: 1px; background: var(--dsw-alias-state-warn-primary); opacity: 0.7; }\n.dt-list > .dt-ticket[data-state='error']::before { background: var(--dsw-alias-state-error-primary); }\n.dt-ticket-stage { align-self: stretch; padding-top: 1px; border-right: 0.5px solid var(--dsw-alias-border-l3); }\n.dt-ticket-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n.dt-ticket-body .dt-row-title .dt-open { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-ticket-meta { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }\n.dt-ticket-meta .dt-chip { flex: none; }\n.dt-ticket-note { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--dsw-alias-label-primary); }\n.dt-ticket-note-error { color: var(--dsw-alias-state-error-primary); }\n.dt-ticket-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; min-height: 30px; margin-top: 2px; }\n/* Pass pointer events through action containers to the row link, keeping only child controls interactive. */\n.dt-ticket-actions, .dt-row-buttons, .dt-row-actions { pointer-events: none; }\n.dt-ticket-actions > *, .dt-row-buttons > *, .dt-row-actions > * { pointer-events: auto; }\n.dt-line { min-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.dt-row-meta.dt-line { flex-wrap: nowrap; }\n.dt-line-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dt-error-text { color: var(--dsw-alias-state-error-primary); }\n.dt-stage { display: inline-flex; align-items: flex-start; gap: 5px; font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }\n.dt-stage svg { flex: none; margin-top: 2px; }\n.dt-stage[data-state='warning'] { color: var(--dsw-alias-state-warn-primary); }\n.dt-stage[data-state='error'] { color: var(--dsw-alias-state-error-primary); }\n.dt-stage[data-state='ongoing'] { color: var(--dsw-alias-state-business-primary); }\n.dt-icon-link { display: inline-flex; align-items: center; gap: 4px; }\na.dt-btn, a.dt-btn:hover { text-decoration: none; }\n.dt-section-icon { display: inline-flex; align-self: center; color: var(--dsw-alias-label-tertiary); }\n.dt-trigger-link { display: flex; flex-direction: column; gap: 2px; width: 100%; margin: -4px 0 -4px -8px; padding: 4px 8px; border: 0; border-radius: 8px; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }\n.dt-trigger-link:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dt-trigger-link:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }\n.dt-trigger-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }\n.dt-kv-stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.dt-banner-actions { margin-top: 6px; }\n@container (max-width: 640px) {\n .dt-list > .dt-ticket { grid-template-columns: 1fr; row-gap: 4px; }\n .dt-ticket-stage { border-right: 0; }\n}\n.dt-nav-group { margin: 10px 10px 2px; font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-secondary); }\n.dt-nav-group:first-child { margin-top: 0; }\n.dt-prompt-nav .dt-nav-item { flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; }\n.dt-nav-item > span { display: inline-flex; align-items: center; gap: 6px; }\n.dt-nav-item small { font-size: 12px; line-height: 18px; font-weight: 400; color: var(--dsw-alias-label-caption); }\n.dt-preview-part[data-editable] { border-left-color: var(--dsw-alias-brand-primary); }\n.dt-preview-head b { font-weight: 500; }\n.dt-preview-head > span { font-size: 12px; color: var(--dsw-alias-label-caption); }\n.dt-changed-tag { margin-left: 6px; padding: 0 5px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: 4px; font-size: 11px; line-height: 16px; font-weight: 400; color: var(--dsw-alias-label-secondary); }\n.dt-updated-tag { border-color: var(--dsw-alias-state-warn-primary); color: var(--dsw-alias-state-warn-primary); }\n.dt-default-updated { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 2px 12px; border-left: 2px solid var(--dsw-alias-state-warn-primary); }\n.dt-diff-fold { color: var(--dsw-alias-label-caption); font-style: italic; }\n.dt-compare { margin-left: auto; }\n.dt-admission th { white-space: nowrap; }\n.dt-admission thead tr:first-child th:not(:first-child) { color: var(--dsw-alias-label-secondary); font-weight: 500; }\n.dt-admission td { vertical-align: middle; }\n.dt-admission-scope { color: var(--dsw-alias-label-primary); font-size: 13px; }\n.dt-admission-scope small { display: block; font-size: 11px; color: var(--dsw-alias-label-caption); }\n.dt-admission-na { color: var(--dsw-alias-label-caption); }\n.dt-admission-cell { display: flex; align-items: center; gap: 4px; }\n.dt-admission-cell .dt-select { flex: 1; min-width: 0; }\n.dt-admission-slot { display: inline-flex; flex: none; width: 16px; }\n.dt-info-warn { color: var(--dsw-alias-state-warn-primary); }\n.dt-field-segmented { max-width: 240px; }\n";
119
+
120
+ /** 把移植过来的样式挂到 document 上,只挂一次。 */
121
+ /**
122
+ * 悬浮面板只保留「定位」用 inline style,视觉全部走 dt-* + token。
123
+ * 以前这里是一整套自成体系的 inline style,和原生界面放一起能看出断层。
124
+ */
125
+ const DOCK_CSS = `
126
+ .sa-dock-panel { box-shadow: var(--dsw-elevation-prominent); padding: 10px 12px 8px; font-size: 12px; line-height: 1.55; }
127
+ .sa-dock-row { padding: 6px 0; }
128
+ .sa-dock-row + .sa-dock-row { border-top: 0.5px solid var(--dsw-alias-border-l3, currentColor); }
129
+ .sa-dock-foot { margin-top: 8px; padding-top: 8px; border-top: 0.5px solid var(--dsw-alias-border-l3, currentColor); color: var(--dsw-alias-label-caption, inherit); }
130
+ .sa-mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
131
+ `
132
+
133
+ function ensurePortedCss() {
134
+ try {
135
+ if (document.getElementById('dsh-zhuli-ported-css')) return
136
+ const style = document.createElement('style')
137
+ style.id = 'dsh-zhuli-ported-css'
138
+ style.textContent = PORTED_CSS + DOCK_CSS
139
+ document.head.appendChild(style)
140
+ } catch {}
141
+ }
142
+
143
+ // ── 官方 GUI 原语(移植自 dsh-superagent 的 src/client/controls.tsx + widgets.tsx)──
144
+ // 类名沿用官方 `dt-*`,样式由上面的 PORTED_CSS 提供,所以视觉与官方一致。
145
+ const ICON_PATHS = {
146
+ 'chevron-left': 'M15 5l-7 7 7 7',
147
+ 'chevron-right': 'M9 5l7 7-7 7',
148
+ 'chevron-down': 'M5 9l7 7 7-7',
149
+ search: 'M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4',
150
+ question: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6v.6M12 17h.01',
151
+ plus: 'M12 5v14M5 12h14',
152
+ trash: 'M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3',
153
+ refresh: 'M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5',
154
+ clock: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7v5l3 2',
155
+ history: 'M3.5 12a8.5 8.5 0 1 0 2.5-6M3.5 4v4h4M12 8v4l3 2',
156
+ shield: 'M12 3l7 3v6c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6z',
157
+ decision: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM8.5 12.5l2.5 2.5 4.5-5',
158
+ message: 'M5 5h14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H10l-5 4V6a1 1 0 0 1 1-1z',
159
+ inbox: 'M4 13l2.5-8h11l2.5 8M4 13v6h16v-6M4 13h5l1 2h4l1-2h5',
160
+ hash: 'M10 4L8 20M16 4l-2 16M5 9h15M4 15h15',
161
+ filter: 'M4 5h16l-6 7.5V18l-4 2v-7.5z',
162
+ user: 'M12 4a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM4 20c1.5-3.5 4.5-5 8-5s6.5 1.5 8 5',
163
+ close: 'M6 6l12 12M18 6L6 18',
164
+ settings: 'M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4',
165
+ external: 'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5',
166
+ session: 'M4 5h16v14H4zM8 10l3 2-3 2M13 15h3',
167
+ stop: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM9.5 9.5h5v5h-5z',
168
+ pause: 'M9 6v12M15 6v12',
169
+ play: 'M8 5l11 7-11 7z',
170
+ copy: 'M9 9h10v11H9zM5 15V4h10',
171
+ alert: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7.5v5.5M12 16.5h.01',
172
+ running: 'M12 3a9 9 0 1 0 9 9',
173
+ blocked: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM5.6 5.6l12.8 12.8',
174
+ queue: 'M4 6h16M4 12h16M4 18h10',
175
+ }
176
+
177
+ function Icon({ name, size = 16 }) {
178
+ return h('svg', {
179
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
180
+ stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
181
+ 'aria-hidden': 'true',
182
+ }, h('path', { d: ICON_PATHS[name] || ICON_PATHS.question }))
183
+ }
184
+
185
+ const cx = (...names) => names.filter(Boolean).join(' ')
186
+
187
+ function Btn({ variant = 'ghost', size = 'md', icon, children, className, ...rest }) {
188
+ // className 必须最后合并:之前 ...rest 直接覆盖,导致 ConfirmBtn 的删除按钮丢掉全部样式
189
+ return h('button', { type: 'button', ...rest, className: cx('dt-btn', 'dt-btn-' + variant, 'dt-btn-' + size, className) },
190
+ icon !== undefined ? h('span', { className: 'dt-btn-icon' }, icon) : null,
191
+ children)
192
+ }
193
+
194
+ function Tag({ tone = 'outline', title, children }) {
195
+ return h('span', { className: 'dt-tag', 'data-tone': tone, title }, children)
196
+ }
197
+
198
+ /** 页级 tab 条:点当前页会再发一次 onChange(回调里可重置到根部)。 */
199
+ function SegTabs({ items, value, onChange, label }) {
200
+ const buttons = useRef({})
201
+ const walk = (event) => {
202
+ if (items.length === 0) return
203
+ const values = items.map((item) => item.value)
204
+ const index = values.indexOf(value)
205
+ const target = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: values.length - 1 }[event.key]
206
+ if (target === undefined) return
207
+ event.preventDefault()
208
+ const next = values[(target + values.length) % values.length]
209
+ if (next !== value) {
210
+ onChange(next)
211
+ // 焦点跟随:旧页签变成 tabIndex=-1 后,键盘用户会掉出 tablist
212
+ const nextButton = buttons.current[next]
213
+ if (nextButton && typeof nextButton.focus === 'function') nextButton.focus()
214
+ }
215
+ }
216
+ return h('div', {
217
+ role: 'tablist', 'aria-label': label, className: 'dt-tabs', onKeyDown: walk,
218
+ style: { gridTemplateColumns: 'repeat(' + items.length + ', minmax(0, 1fr))' },
219
+ }, items.map((item) => h('button', {
220
+ key: item.value, type: 'button', role: 'tab',
221
+ ref: (node) => { buttons.current[item.value] = node },
222
+ 'aria-selected': item.value === value,
223
+ tabIndex: item.value === value ? 0 : -1,
224
+ className: 'dt-tab',
225
+ onClick: () => onChange(item.value),
226
+ }, item.label)))
227
+ }
228
+
229
+ function Input({ icon, ...rest }) {
230
+ return h('span', { className: 'dt-input' },
231
+ icon !== undefined ? h('span', { className: 'dt-input-icon' }, icon) : null,
232
+ h('input', rest))
233
+ }
234
+
235
+ function Toggle({ checked, onChange, label }) {
236
+ return h('button', {
237
+ type: 'button', role: 'switch', 'aria-checked': !!checked, 'aria-label': label,
238
+ className: 'dt-switch', onClick: () => onChange(!checked),
239
+ }, h('span', { className: 'dt-switch-thumb' }))
240
+ }
241
+
242
+ function StateDot({ state, className }) {
243
+ if (state === 'ongoing') {
244
+ return h('svg', { className: 'dt-spinner', 'data-state': 'ongoing', width: 14, height: 14, viewBox: '0 0 24 24', 'aria-hidden': 'true' },
245
+ h('g', null,
246
+ h('circle', { cx: 12, cy: 12, r: 9.5 }),
247
+ h('animateTransform', { attributeName: 'transform', type: 'rotate', from: '0 12 12', to: '360 12 12', dur: '1.6s', repeatCount: 'indefinite' })))
248
+ }
249
+ return h('span', { className: cx('dt-state-dot', className), 'data-state': state, 'aria-hidden': 'true' })
250
+ }
251
+
252
+ function Dot({ state, label }) {
253
+ const dot = h(StateDot, { className: 'dt-dot', state })
254
+ if (!label) return dot
255
+ return h('span', { className: 'dt-dot-wrap', title: label, role: 'img', 'aria-label': label }, dot)
256
+ }
257
+
258
+ // 官方 Section 还支持 hint(说明)与 action(右上角动作),我们之前只有 title/count。
259
+ function Section({ title, count, hint, action, children }) {
260
+ return h('section', { className: 'dt-section' },
261
+ title
262
+ ? h('div', { className: 'dt-section-title' },
263
+ h('span', { className: 'dt-section-name' }, title),
264
+ count !== undefined && count !== null ? h('span', { className: 'dt-count' }, String(count)) : null,
265
+ action ? h('span', { className: 'dt-subhead-actions' }, action) : null)
266
+ : null,
267
+ hint ? h(Hint, null, hint) : null,
268
+ children)
269
+ }
270
+
271
+ /**
272
+ * 第一次打开面板时的空态:官方那种「不是白屏,而是告诉你下一步做什么」。
273
+ * 三步走完就能跑起来 —— 客户不用去翻 README。
274
+ */
275
+ function Onboarding({ onStart }) {
276
+ return h('div', { className: 'dt-card' },
277
+ h('div', { className: 'dt-card-head' },
278
+ h('span', { className: 'dt-card-title' }, '三步让这个会话开始盯办')),
279
+ h('ol', { className: 'dt-plain-list' },
280
+ h('li', null, '① 填一个仓库(owner/name,比如 MYCF711/dsh-session-superagent)'),
281
+ h('li', null, '② 选间隔(默认 60 秒;建议先设 300 秒,别把 API 打满)'),
282
+ h('li', null, '③ 点「添加到当前会话」——之后仓库有动静,这个会话就会被叫醒')),
283
+ h('div', { className: 'dt-actions' },
284
+ h(Btn, { variant: 'primary', icon: h(Icon, { name: 'plus' }), onClick: onStart }, '去添加第一条')),
285
+ h(Hint, null, '想先看看效果?在「触发」页勾上「仅观察」:它只记录本会唤醒哪几条,不会真打扰你。'))
286
+ }
287
+
288
+ /** 官方 DisclosureRow 的实际用法:默认收起,点开看明细。 */
289
+ function CollapsibleList({ title, items }) {
290
+ const [open, setOpen] = useState(false)
291
+ return h(DisclosureRow, {
292
+ title: title + '(' + items.length + ')',
293
+ open, onToggle: () => setOpen(!open),
294
+ icon: h(Icon, { name: 'question', size: 14 }),
295
+ collapsedContent: h('span', { className: 'dt-hint' }, items[0] ? String(items[0]).slice(0, 40) : ''),
296
+ },
297
+ h('ul', { className: 'dt-plain-list' },
298
+ items.map((text, index) => h('li', { key: index }, text))))
299
+ }
300
+
301
+ /** 官方 Pill:可切换的小胶囊(用于「全部 / 只看失败」这类就地过滤)。 */
302
+ function Pill({ active, onClick, children }) {
303
+ return h('button', {
304
+ type: 'button', className: cx('dt-pill', active && 'dt-pill-active'),
305
+ 'aria-pressed': !!active, onClick,
306
+ }, children)
307
+ }
308
+
309
+ /** 官方 SegmentedControl:单选分段(与 SegTabs 的页签语义不同,用于表单内的互斥选择)。 */
310
+ function SegmentedControl({ options, value, onChange, label, disabled }) {
311
+ return h('div', { className: 'dt-segmented', role: 'radiogroup', 'aria-label': label },
312
+ options.map((option) => h('button', {
313
+ key: option.value, type: 'button', role: 'radio',
314
+ 'aria-checked': value === option.value, 'aria-selected': value === option.value,
315
+ className: 'dt-segment', disabled: disabled || option.disabled,
316
+ onClick: () => onChange(option.value),
317
+ }, option.label)))
318
+ }
319
+
320
+ /** 官方 DisclosureRow:折叠行的标准写法(Enter / 空格可切换,带 aria-expanded)。 */
321
+ function DisclosureRow({ icon, title, open, onToggle, collapsedContent, children }) {
322
+ return h('div', { className: 'dt-disclosure', 'data-open': open ? 'true' : undefined },
323
+ h('div', {
324
+ className: 'dt-disclosure-row', role: 'button', tabIndex: 0, 'aria-expanded': !!open,
325
+ onClick: onToggle,
326
+ onKeyDown: (event) => {
327
+ if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onToggle() }
328
+ },
329
+ },
330
+ h('span', { className: 'dt-disclosure-lead' },
331
+ h('span', { className: 'dt-disclosure-icon' }, icon),
332
+ h('span', { className: 'dt-disclosure-chevron' }, h(Icon, { name: open ? 'chevron-up' : 'chevron-down' }))),
333
+ h('span', { className: 'dt-disclosure-title' }, title),
334
+ !open ? collapsedContent : null),
335
+ open ? children : null)
336
+ }
337
+
338
+ /** 官方 InfoTip:点一下出气泡(我们之前只有 dt-info 的样式,没有组件)。 */
339
+ function InfoTip({ text, icon = 'question', warn }) {
340
+ const [open, setOpen] = useState(false)
341
+ return h('span', { style: { position: 'relative', display: 'inline-flex' } },
342
+ h('button', {
343
+ type: 'button', className: cx('dt-info', warn && 'dt-info-warn'),
344
+ 'aria-label': text, 'aria-expanded': open,
345
+ onClick: () => setOpen(!open), onBlur: () => setOpen(false),
346
+ }, h(Icon, { name: icon, size: 14 })),
347
+ open ? h('span', { className: 'dt-tooltip', role: 'tooltip', style: { position: 'absolute', bottom: '130%', left: 0, visibility: 'visible' } }, text) : null)
348
+ }
349
+
350
+ const Hint = ({ children }) => h('p', { className: 'dt-hint' }, children)
351
+
352
+ function KeyValues({ rows }) {
353
+ return h('dl', { className: 'dt-kv' },
354
+ rows.filter(Boolean).flatMap(([key, value]) => [
355
+ h('dt', { key: key + '-k' }, key),
356
+ h('dd', { key: key + '-v' }, value),
357
+ ]))
358
+ }
359
+
360
+ // 官方 Modal 的键盘行为:Escape 关闭 + Tab 焦点陷阱 + 关闭后焦点回到触发元素。
361
+ // 移植时只搬了样式,行为是后补的(2026-11-02 对官方 controls.tsx 逐行比对时发现)。
362
+ const FOCUSABLE = 'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])'
363
+ function trapTab(event, dialog) {
364
+ const items = [...dialog.querySelectorAll('*')].filter((element) => element.matches(FOCUSABLE))
365
+ const first = items[0]
366
+ const last = items[items.length - 1]
367
+ const active = document.activeElement
368
+ const target = event.shiftKey ? last : first
369
+ if (!target || !dialog.contains(active) || active === dialog || active === (event.shiftKey ? first : last)) {
370
+ event.preventDefault()
371
+ target.focus()
372
+ }
373
+ }
374
+
375
+ function Modal({ open, title, children, onClose }) {
376
+ const dialog = useRef(null)
377
+ const restoreTo = useRef(null)
378
+ useEffect(() => {
379
+ if (!open || typeof document === 'undefined') return undefined
380
+ restoreTo.current = document.activeElement
381
+ // 打开后把焦点挪进对话框,否则键盘用户还停在背后的页面上
382
+ const timer = setTimeout(() => {
383
+ const node = dialog.current
384
+ if (!node) return
385
+ const first = [...node.querySelectorAll('*')].filter((el) => el.matches(FOCUSABLE))[0]
386
+ ;(first || node).focus()
387
+ }, 0)
388
+ const onKey = (event) => {
389
+ if (event.key === 'Escape') { event.preventDefault(); onClose(); return }
390
+ if (event.key === 'Tab' && dialog.current) trapTab(event, dialog.current)
391
+ }
392
+ document.addEventListener('keydown', onKey)
393
+ return () => {
394
+ clearTimeout(timer)
395
+ document.removeEventListener('keydown', onKey)
396
+ const back = restoreTo.current
397
+ if (back && typeof back.focus === 'function') { try { back.focus() } catch {} }
398
+ }
399
+ }, [open, onClose])
400
+ if (!open) return null
401
+ // class 必须与移植来的官方 CSS 对齐:dt-modal-root / dt-modal-mask / dt-modal-header
402
+ return h('div', { className: 'dt-modal-root' },
403
+ h('div', { className: 'dt-modal-mask', role: 'presentation', onClick: onClose }),
404
+ h('div', {
405
+ ref: dialog, tabIndex: -1,
406
+ className: 'dt-modal', role: 'dialog', 'aria-modal': 'true',
407
+ 'aria-label': typeof title === 'string' ? title : undefined,
408
+ },
409
+ h('div', { className: 'dt-modal-header' },
410
+ h('span', { className: 'dt-title' }, title),
411
+ h('button', { type: 'button', className: 'dt-modal-close', onClick: onClose, 'aria-label': '关闭' }, h(Icon, { name: 'close' }))),
412
+ h('div', { className: 'dt-modal-body' }, children)))
413
+ }
414
+
415
+ /** 危险操作二次确认:点一次变成「确定吗」,再点才执行。 */
416
+ function ConfirmBtn({ label, confirmLabel = '确定执行', onConfirm, variant = 'ghost', icon, size }) {
417
+ const [armed, setArmed] = useState(false)
418
+ return h(Btn, {
419
+ variant,
420
+ size,
421
+ className: armed ? 'dt-danger' : undefined,
422
+ icon,
423
+ 'aria-label': armed ? confirmLabel : label,
424
+ onClick: () => {
425
+ if (!armed) { setArmed(true); return }
426
+ setArmed(false)
427
+ onConfirm()
428
+ },
429
+ onBlur: () => setArmed(false),
430
+ }, armed ? confirmLabel : label)
431
+ }
432
+
433
+ const watcherId = (w) => (w && w.id) || String((w && w.repo) || '') + '#' + String((w && w.sessionId) || '')
434
+ const short = (value, width = 19) => (typeof value === 'string' && value.length > width ? value.slice(0, width - 1) + '…' : (value ?? '—'))
435
+ const when = (iso) => (typeof iso === 'string' ? iso.replace('T', ' ').replace('Z', '').slice(5, 19) : '—')
436
+
437
+ // ── orbit badge: session header indicator ──────────────────────────────
438
+ // Static geometry, three states: green dot orbiting (watching), amber dot on
439
+ // a dashed ring (paused), red dot breathing (error). Icon only — the text
440
+ // lives in the native tooltip so it does not compete with the session title.
441
+ // ── status orbit: composer-dock indicator ─────────────────────────────
442
+ // One ring for the whole machine. Every satellite on the ring is one
443
+ // session-level superagent (a live watcher): green = watching, amber =
444
+ // paused, red = last poll failed. Icon only — details live in the
445
+ // click-through panel, and a native tooltip carries the one-line summary.
446
+ /**
447
+ * 现在是否落在活跃时段里。支持跨夜(22:00-06:00)。
448
+ * 解析不了就返回 null —— 宁可显示「主理中」,也不要乱标。
449
+ */
450
+ function inWindowNow(hours) {
451
+ const match = String(hours || '').match(/^(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})$/)
452
+ if (!match) return null
453
+ const now = new Date()
454
+ const current = now.getHours() * 60 + now.getMinutes()
455
+ const from = Number(match[1]) * 60 + Number(match[2])
456
+ const to = Number(match[3]) * 60 + Number(match[4])
457
+ return from <= to ? current >= from && current < to : current >= from || current < to
458
+ }
459
+
460
+ function orbitStateOf(w) {
461
+ if (!w) return 'paused'
462
+ if (w.lastError) return 'error'
463
+ if (w.enabled === false) return 'paused'
464
+ // 设了活跃时段、而此刻在窗口外:它其实不会唤醒,只是把条目攒着 ——
465
+ // 这时候还标「主理中」就是在骗人(2026-11-02 用户截图指出)。
466
+ if (w.activeHours && inWindowNow(w.activeHours) === false) return 'dormant'
467
+ return 'active'
468
+ }
469
+
470
+ // 状态色一律走 token(写死 hex 在深色/浅色两套主题里会有一个是错的)
471
+ const SAT_COLOR = {
472
+ active: 'var(--dsw-alias-state-success-primary)',
473
+ paused: 'var(--dsw-alias-state-warn-primary)',
474
+ error: 'var(--dsw-alias-state-error-primary)',
475
+ dormant: 'var(--dsw-alias-label-caption)',
476
+ }
477
+ const STATE_TEXT = { active: '主理中', paused: '已暂停', error: '异常', dormant: '时段外' }
478
+
479
+ /** 尊重系统的「减少动态效果」设置。 */
480
+ const prefersReducedMotion = () => {
481
+ try { return window.matchMedia('(prefers-reduced-motion: reduce)').matches } catch { return false }
482
+ }
483
+
484
+ function OrbitMark(props) {
485
+ const watchers = props.watchers || []
486
+ const shown = watchers.slice(0, 6)
487
+ const states = watchers.map(orbitStateOf)
488
+ const anyActive = states.indexOf('active') >= 0
489
+ // Zero watchers still draws the ring, just grey: an idle machine should
490
+ // read as "nothing being watched", not as "the plugin is broken".
491
+ const empty = states.length === 0
492
+ const ringColor = empty
493
+ ? 'currentColor'
494
+ : states.indexOf('error') >= 0
495
+ ? SAT_COLOR.error
496
+ : anyActive ? SAT_COLOR.active : states.indexOf('dormant') >= 0 ? SAT_COLOR.dormant : SAT_COLOR.paused
497
+ const dashed = states.indexOf('paused') >= 0
498
+ const still = prefersReducedMotion()
499
+
500
+ const dots = shown.map((w, i) => {
501
+ const angle = (i / Math.max(shown.length, 1)) * Math.PI * 2 - Math.PI / 2
502
+ const state = orbitStateOf(w)
503
+ return h('circle', {
504
+ key: String(w.repo || '') + '#' + String(w.sessionId || i),
505
+ cx: 8 + Math.cos(angle) * 6.1,
506
+ cy: 8 + Math.sin(angle) * 6.1,
507
+ r: shown.length > 3 ? 1.75 : 2.05,
508
+ fill: SAT_COLOR[state],
509
+ }, state === 'error' && !still
510
+ ? h('animate', { attributeName: 'opacity', values: '1;.3;1', dur: '1.6s', repeatCount: 'indefinite' })
511
+ : null)
512
+ })
513
+
514
+ // 动画用 SMIL 写进 SVG 本身:不依赖注入的 <style>,也不吃 CSP /
515
+ // transform-box 的差异;单独存成 .html 就能预览。
516
+ const spin = anyActive && !still
517
+ ? h('animateTransform', {
518
+ attributeName: 'transform', type: 'rotate',
519
+ from: '0 8 8', to: '360 8 8', dur: '6s', repeatCount: 'indefinite',
520
+ })
521
+ : null
522
+ const breathe = anyActive && !still
523
+ ? h('animate', { attributeName: 'opacity', values: '.95;.45;.95', dur: '2.6s', repeatCount: 'indefinite' })
524
+ : null
525
+
526
+ return h('svg', {
527
+ width: 16, height: 16, viewBox: '0 0 16 16', 'aria-hidden': 'true',
528
+ style: { overflow: 'visible' },
529
+ },
530
+ h('circle', {
531
+ cx: 8, cy: 8, r: 6.1, fill: 'none', stroke: ringColor, strokeWidth: 1.1,
532
+ strokeDasharray: dashed ? '2.2 1.9' : undefined,
533
+ opacity: empty ? 0.38 : 0.9,
534
+ }, breathe),
535
+ h('g', null, spin, dots))
536
+ }
537
+
538
+ const notedOnce = new Set()
539
+ /** Diagnostics: write once per page load, never on every poll. */
540
+ function noteOnce(key, value) {
541
+ if (notedOnce.has(key)) return
542
+ notedOnce.add(key)
543
+ note(key, value)
544
+ }
545
+
546
+ function note(key, value) {
547
+ try { fetch(BASE + '/client-note?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(String(value || ''))).catch(() => {}) } catch {}
548
+ }
549
+
550
+ /** 8-char session tag. Titles come from the title model and several sessions
551
+ * can share one, so every row carries the id suffix to stay unambiguous. */
552
+ const sessionTag = (id) => {
553
+ const raw = String(id || '')
554
+ const core = raw.indexOf('session-') === 0 ? raw.slice(8) : raw
555
+ return core.slice(0, 8) || '—'
556
+ }
557
+
558
+ /** 把 filters 压成一行人话,空配置返回空串。 */
559
+ const filterText = (f) => {
560
+ if (!f) return ''
561
+ const parts = []
562
+ if (f.labels && f.labels.length) parts.push('标签: ' + f.labels.join(','))
563
+ if (f.ignoreLabels && f.ignoreLabels.length) parts.push('排除: ' + f.ignoreLabels.join(','))
564
+ if (f.onlyAssigned) parts.push(f.assignee ? '只看指派给 @' + f.assignee : '只看已指派')
565
+ return parts.join(' · ')
566
+ }
567
+
568
+ /** 只留路径最后两段,面板里放得下。 */
569
+ const pathTail = (value) => String(value || '')
570
+ .split(String.fromCharCode(92)).join('/')
571
+ .split('/').filter(Boolean).slice(-2).join('/')
572
+
573
+ /** 隔离执行状态:开着隔离就显示上次用的 worktree。 */
574
+ const isolationText = (w) => {
575
+ if (!w || !w.isolated) return ''
576
+ return '隔离 · ' + (pathTail(w.lastWorktree) || pathTail(w.workdir) || '未建')
577
+ }
578
+
579
+ /** 最近一次唤醒的结果(面板第二行用)。 */
580
+ const historyText = (w) => {
581
+ const list = (w && w.history) || []
582
+ const last = list[list.length - 1]
583
+ if (!last) return ''
584
+ const nums = (last.numbers || []).map((n) => '#' + n).join(' ')
585
+ return (last.ok ? '上次唤醒 ' : '上次唤醒失败 ') + nums + ' · ' + ageText(last.at)
586
+ }
587
+
588
+ /** 失败退避中显示剩余秒数,否则空串。 */
589
+ const backoffText = (w) => {
590
+ if (!w || !w.nextAt) return ''
591
+ const left = Date.parse(w.nextAt) - Date.now()
592
+ if (!isFinite(left) || left <= 0) return ''
593
+ return '退避 ' + Math.ceil(left / 1000) + 's'
594
+ }
595
+
596
+ const ageText = (iso) => {
597
+ if (typeof iso !== 'string') return '—'
598
+ const ms = Date.now() - Date.parse(iso)
599
+ if (!isFinite(ms) || ms < 0) return '—'
600
+ const s = Math.round(ms / 1000)
601
+ if (s < 90) return s + ' 秒前'
602
+ if (s < 5400) return Math.round(s / 60) + ' 分钟前'
603
+ return Math.round(s / 3600) + ' 小时前'
604
+ }
605
+ const wakeText = (value) => {
606
+ if (typeof value !== 'string' || value === '') return '—'
607
+ if (value.indexOf('failed') === 0) return '失败'
608
+ return ageText(value)
609
+ }
610
+
611
+ const PANEL_W = 344
612
+ const BORDER = '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.22))'
613
+
614
+ /** Dock entry: the machine-wide ring plus its click-through detail list. */
615
+ /** 把错误拆成「现象」和「建议」:服务端存的是 short +(hint),建议在末尾的括号里。 */
616
+ function splitErrorText(text) {
617
+ const value = String(text || '')
618
+ const match = /([^()]*)\s*$/.exec(value)
619
+ if (!match) return { main: value, hint: '' }
620
+ return { main: value.slice(0, match.index).trim(), hint: match[0].trim() }
621
+ }
622
+ function StatusOrbit() {
623
+ const [watchers, setWatchers] = useState(null)
624
+ const [open, setOpen] = useState(false)
625
+ const [anchor, setAnchor] = useState(null)
626
+ const btnRef = useRef(null)
627
+ const panelRef = useRef(null)
628
+
629
+ useEffect(() => {
630
+ let alive = true
631
+ noteOnce('orbit-mount', 'ok')
632
+ const load = async () => {
633
+ try {
634
+ const body = await call('/state')
635
+ if (alive) setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
636
+ } catch {
637
+ if (alive) setWatchers((prev) => (prev === null ? [] : prev))
638
+ }
639
+ }
640
+ load()
641
+ const timer = setInterval(load, POLL_MS)
642
+ return () => { alive = false; clearInterval(timer) }
643
+ }, [])
644
+
645
+ useEffect(() => {
646
+ if (!open) return undefined
647
+ const onDown = (event) => {
648
+ const target = event.target
649
+ if (panelRef.current && panelRef.current.contains(target)) return
650
+ if (btnRef.current && btnRef.current.contains(target)) return
651
+ setOpen(false)
652
+ }
653
+ const onKey = (event) => { if (event.key === 'Escape') setOpen(false) }
654
+ document.addEventListener('mousedown', onDown, true)
655
+ document.addEventListener('keydown', onKey, true)
656
+ return () => {
657
+ document.removeEventListener('mousedown', onDown, true)
658
+ document.removeEventListener('keydown', onKey, true)
659
+ }
660
+ }, [open])
661
+
662
+ const list = watchers || []
663
+ // Never hide the entry: with nothing being watched it stays as a grey
664
+ // ring, so the affordance is always findable in the dock row.
665
+ const running = list.filter((w) => orbitStateOf(w) === 'active').length
666
+ const broken = list.filter((w) => orbitStateOf(w) === 'error').length
667
+ const summary = list.length === 0
668
+ ? '还没有主理鱼'
669
+ : '会话级 superagent:' + running + ' 运行中'
670
+ + (broken ? ',' + broken + ' 异常' : '')
671
+ + '(共 ' + list.length + ' 条)'
672
+
673
+ const toggle = () => {
674
+ const el = btnRef.current
675
+ if (el) {
676
+ const rect = el.getBoundingClientRect()
677
+ setAnchor({ x: rect.left + rect.width / 2, y: rect.top })
678
+ }
679
+ setOpen((value) => !value)
680
+ }
681
+
682
+ const button = h('button', {
683
+ ref: btnRef,
684
+ type: 'button',
685
+ title: list.length
686
+ ? list.map((w) => (w.repo + ' · ' + (w.title || '未命名会话') + ' · ' + sessionTag(w.sessionId) + ' · ' + STATE_TEXT[orbitStateOf(w)])).join('\n')
687
+ : '还没有主理鱼 —— 在「主理鱼」页加一条',
688
+ 'aria-label': summary,
689
+ 'aria-expanded': open ? 'true' : 'false',
690
+ onClick: toggle,
691
+ style: {
692
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
693
+ height: 20, minWidth: 20, padding: '0 2px', margin: '0 2px',
694
+ border: 'none', borderRadius: 6,
695
+ background: open ? 'rgba(128,128,128,.16)' : 'transparent',
696
+ cursor: 'pointer', color: 'inherit', opacity: watchers === null ? 0.45 : 1,
697
+ },
698
+ }, h(OrbitMark, { watchers: list }))
699
+
700
+ if (!open) return button
701
+
702
+ // 空态没什么内容,窄一点更像提示而不是一张空表格
703
+ const width = list.length === 0 ? 252 : PANEL_W
704
+ const left = anchor
705
+ ? Math.max(8, Math.min(anchor.x - width / 2, (window.innerWidth || 1200) - width - 8))
706
+ : 8
707
+ const bottom = anchor ? Math.max(8, (window.innerHeight || 800) - anchor.y + 8) : 64
708
+
709
+ const act = async (w, action) => {
710
+ if (action === 'delete') {
711
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
712
+ ? window.confirm('删除主理鱼 ' + (w.repo || '') + '?')
713
+ : true
714
+ if (!ok) return
715
+ }
716
+ try {
717
+ await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(w) }) })
718
+ } catch {}
719
+ try {
720
+ const body = await call('/state')
721
+ setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
722
+ } catch {}
723
+ }
724
+
725
+ // 悬浮面板也走移植来的 dt-* 设计系统(以前这里是一套自成体系的 inline style,
726
+ // 和原生界面放在一起能看出断层;ui-audit ⑥ 就是在盯这件事)。
727
+ const rows = list.map((w) => {
728
+ const state = orbitStateOf(w)
729
+ const extra = [
730
+ filterText(w.filters),
731
+ w.activeHours ? '时段 ' + w.activeHours : '',
732
+ isolationText(w),
733
+ backoffText(w),
734
+ historyText(w),
735
+ w.lastDeferred,
736
+ ].filter(Boolean).join(' · ')
737
+ return h('div', {
738
+ key: String(w.repo || '') + '#' + String(w.sessionId || ''),
739
+ className: 'dt-row sa-dock-row',
740
+ },
741
+ h('div', { className: 'dt-row-main' },
742
+ h('div', { className: 'dt-row-title' },
743
+ h('span', { className: 'dt-dot-wrap' },
744
+ h('span', { className: 'dt-state-dot', 'data-state': state === 'active' ? 'done' : state === 'paused' ? 'warning' : state === 'error' ? 'error' : 'idle' })),
745
+ h('span', { className: 'sa-mono' }, String(w.repo || '?')),
746
+ h('span', { className: 'dt-row-meta' }, STATE_TEXT[state])),
747
+ h('div', { className: 'dt-hint' }, (w.title || '未命名会话') + ' · ' + sessionTag(w.sessionId)),
748
+ h('div', { className: 'dt-hint' }, '每 ' + w.intervalSec + 's · 轮询 ' + ageText(w.lastPoll) + ' · 唤醒 ' + wakeText(w.lastWake)),
749
+ extra ? h('div', { className: 'dt-hint' }, extra) : null,
750
+ w.goal && w.goal.objective
751
+ ? h('div', { className: 'dt-hint' }, 'goal · ' + String(w.goal.objective).slice(0, 60))
752
+ : null,
753
+ w.lastError ? (() => {
754
+ // 之前整串 slice(0,160):错误一长就先切掉后面的建议 —— 恰好是最有用的部分
755
+ const parts = splitErrorText(w.lastError)
756
+ return h('div', { className: 'dt-error' },
757
+ parts.main.slice(0, 120) + (parts.main.length > 120 ? '…' : ''),
758
+ parts.hint ? h('div', { className: 'dt-hint' }, parts.hint) : null)
759
+ })() : null),
760
+ h('div', { className: 'dt-row-actions' },
761
+ h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, 'poll') }, '立刻'),
762
+ h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, w.enabled ? 'pause' : 'resume') },
763
+ w.enabled ? '暂停' : '恢复'),
764
+ h(ConfirmBtn, {
765
+ label: '删除', confirmLabel: '确认删除', variant: 'ghost', size: 'sm',
766
+ onConfirm: () => act(w, 'delete'),
767
+ })))
768
+ })
769
+
770
+ const panel = h('div', {
771
+ ref: panelRef, role: 'dialog', 'aria-label': summary, className: 'dt-card sa-dock-panel',
772
+ style: { position: 'fixed', left, bottom, width, zIndex: 2147483000, maxHeight: 360, overflow: 'auto' },
773
+ },
774
+ h('div', { className: 'dt-card-head' },
775
+ h('span', { className: 'dt-card-title' }, '主理鱼'),
776
+ h('span', { className: 'dt-count' }, list.length === 0 ? '0 条' : running + '/' + list.length + ' 主理中')),
777
+ list.length === 0
778
+ ? h('div', { className: 'dt-hint' }, '在「主理鱼」页填 owner/name 加一条。')
779
+ : h('div', { className: 'dt-rows' }, rows),
780
+ list.length > 0
781
+ ? h('div', { className: 'sa-dock-foot' }, '点「暂停 / 删除」直接停掉;「主理鱼」标签页可新增与配置凭证')
782
+ : null)
783
+
784
+ return h(React.Fragment, null, button, panel)
785
+ }
786
+
787
+
788
+ // ── 主理鱼面板(按官方 GUI 的信息架构重写:总览 / 触发 / 设置)────────────────
789
+ // 布局、类名、控件都来自上面移植的 dt-* 设计系统,数据和动作接我们自己的 /state、/watch。
790
+ // ── 官方 GUI 的三个交互件(移植自 src/client/provider.tsx + draft.tsx + src/client/controls.tsx)──
791
+
792
+ /** 轮询:可见时按 interval,隐藏时降频 6 倍;上一轮没跑完就跳过;卸载时清干净。 */
793
+ function usePoll(task, intervalMs = POLL_MS) {
794
+ const ref = useRef(task)
795
+ ref.current = task
796
+ const busy = useRef(false)
797
+ useEffect(() => {
798
+ let alive = true
799
+ let timer = null
800
+ let discovered = false
801
+ const step = async () => {
802
+ if (!alive) return
803
+ if (!discovered) {
804
+ discovered = true
805
+ try { await discoverBase() } catch {}
806
+ }
807
+ const hidden = typeof document !== 'undefined' && document.hidden === true
808
+ const delay = hidden ? intervalMs * 6 : intervalMs
809
+ if (!busy.current) {
810
+ busy.current = true
811
+ try { await ref.current() } catch {}
812
+ finally { busy.current = false }
813
+ }
814
+ if (alive) timer = setTimeout(step, delay)
815
+ }
816
+ step()
817
+ return () => { alive = false; if (timer) clearTimeout(timer) }
818
+ }, [intervalMs])
819
+ }
820
+
821
+ /** 轻量 Toast:右下角堆叠,4 秒自动消失。 */
822
+ function useToast() {
823
+ // 官方 .dt-toast 是 position:fixed 顶部居中、且带自动淡出动画 —— 同时挂两条会重叠,
824
+ // 所以这里保持「同一时刻只有最新一条」,停留时长用官方的 --dt-toast-hold 控制。
825
+ const [item, setItem] = useState(null)
826
+ const timer = useRef(null)
827
+ useEffect(() => () => { if (timer.current) clearTimeout(timer.current) }, [])
828
+ const notify = useCallback((text, tone = 'info') => {
829
+ if (timer.current) clearTimeout(timer.current)
830
+ setItem({ id: Math.random().toString(36).slice(2), text, tone })
831
+ timer.current = setTimeout(() => setItem(null), 4000)
832
+ }, [])
833
+ const view = item === null ? null : h('div', {
834
+ className: cx('dt-toast', item.tone === 'error' && 'dt-danger'),
835
+ role: 'status',
836
+ 'aria-live': 'polite',
837
+ // 官方 toast 是深底白字;错误态不要改成浅红底(白字会看不清),改用左侧红条标记
838
+ style: item.tone === 'error'
839
+ ? { '--dt-toast-hold': '3600ms', borderLeft: '3px solid var(--dsw-alias-state-error-primary)' }
840
+ : { '--dt-toast-hold': '3600ms' },
841
+ }, item.text)
842
+ return [view, notify]
843
+ }
844
+
845
+ function ZhuliPanel(props) {
846
+ const sessionId = props && props.sessionId
847
+ /** 暂停原因码 → 人话(服务端 deferReason 是唯一来源)。 */
848
+ const DEFER_LABELS = {
849
+ 'active-hours': '不在活跃时段',
850
+ ratelimit: '被 GitHub 限流',
851
+ quota: '额度紧张',
852
+ unchanged: '没有变化',
853
+ observe: '仅观察',
854
+ 'cap-session': '撞会话上限',
855
+ 'cap-watcher': '撞单守上限',
856
+ busy: '会话忙',
857
+ }
858
+
859
+ const [snap, setSnap] = useState({ loading: true, error: null, body: null })
860
+ const [tab, setTab] = useState('overview')
861
+ const [notice, setNotice] = useState(null)
862
+ const [form, setForm] = useState({
863
+ repo: '', intervalSec: '60', goal: '', labels: '', onlyAssigned: false,
864
+ activeHours: '', isolated: false, workdir: '',
865
+ })
866
+ const [token, setToken] = useState('')
867
+ const [goalDraft, setGoalDraft] = useState('')
868
+ const [goalTouched, setGoalTouched] = useState(false)
869
+ const [toastView, notify] = useToast()
870
+ const [editing, setEditing] = useState(null)
871
+ const [draft, setDraft] = useState({})
872
+ const [search, setSearch] = useState('')
873
+ const [glossary, setGlossary] = useState(false)
874
+ // 版本检查结果(只读):面板里直接告诉客户「有没有新版本、该跑什么命令」
875
+ const [update, setUpdate] = useState(null)
876
+ const [checking, setChecking] = useState(false)
877
+ // 设置页用官方的「左栏 + 内容」结构(dt-settings),所以要记当前分区
878
+ const [settingsSection, setSettingsSection] = useState('source')
879
+ // 判定页:点「跳过原因」标签就只看这一类(知识库里记的"还没做",本轮补上)
880
+ const [reasonFilter, setReasonFilter] = useState(null)
881
+ // 行内徽章可点:点「只读」就只看只读的守(与跳过原因筛选同一套交互)
882
+ const [badgeFilter, setBadgeFilter] = useState(null)
883
+ // 只看有问题的:放在最后追加,避免打乱测试桩按位置取值的队列
884
+ const [problemsOnly, setProblemsOnly] = useState(false)
885
+ // 建议规则弹层:给"叫醒了没回音"一个下一步动作(只提供可复制的规则,不替客户写仓库文件)
886
+
887
+ const load = useCallback(async () => {
888
+ try {
889
+ const payload = await call('/state', stateEtag ? { headers: { 'if-none-match': stateEtag } } : undefined)
890
+ // 304:内容没变,别白白重渲染
891
+ if (payload && payload.notModified) return null
892
+ const body = payload
893
+ setSnap({ loading: false, error: null, body })
894
+ return body
895
+ } catch (error) {
896
+ setSnap((prev) => ({ loading: false, error: String((error && error.message) || error), body: prev.body }))
897
+ return null
898
+ }
899
+ }, [])
900
+
901
+ useEffect(() => { ensurePortedCss() }, [])
902
+ usePoll(load, POLL_MS)
903
+
904
+ const body = snap.body || {}
905
+ const watchers = body.watchers || []
906
+ const sessionGoal = body.sessionGoal || null
907
+ const credentials = body.credentials || { token: 'none', sshKeyPath: 'none' }
908
+
909
+ useEffect(() => {
910
+ if (goalTouched || !sessionGoal) return
911
+ setGoalDraft(sessionGoal.objective || '')
912
+ }, [goalTouched, sessionGoal])
913
+
914
+ const busyRef = useRef(false)
915
+ const run = async (work, done) => {
916
+ if (busyRef.current) return
917
+ busyRef.current = true
918
+ setNotice(null)
919
+ try {
920
+ await work()
921
+ if (done) notify(done)
922
+ await load()
923
+ } catch (error) {
924
+ const text = String((error && error.message) || error)
925
+ setNotice({ ok: false, text })
926
+ notify(text, 'error')
927
+ } finally {
928
+ busyRef.current = false
929
+ }
930
+ }
931
+
932
+ /** 保存某条 watcher 的编辑(同一 repo+sessionId 即更新,enabled 不传 = 保持原值)。 */
933
+ const saveEdit = (watcher) => run(async () => {
934
+ await call('/watch', {
935
+ method: 'POST',
936
+ body: JSON.stringify({
937
+ repo: watcher.repo,
938
+ sessionId: watcher.sessionId,
939
+ intervalSec: Number(draft.intervalSec) || watcher.intervalSec,
940
+ filters: {
941
+ labels: String(draft.labels || '').split(',').map((v) => v.trim()).filter(Boolean),
942
+ onlyAssigned: !!draft.onlyAssigned,
943
+ },
944
+ activeHours: draft.activeHours || '',
945
+ goal: draft.goal || '',
946
+ isolated: !!draft.isolated,
947
+ workdir: draft.workdir || '',
948
+ observe: !!draft.observe,
949
+ isolateKeepDays: Number(draft.isolateKeepDays) || undefined,
950
+ maxIsolated: Number(draft.maxIsolated) || undefined,
951
+ priority: {
952
+ reopened: draft.priorityReopened !== false,
953
+ comments: draft.priorityComments !== false,
954
+ labels: draft.priorityLabels !== false,
955
+ unassigned: draft.priorityUnassigned === true,
956
+ stale: draft.priorityStale === true,
957
+ },
958
+ batchLimit: Number(draft.batchLimit) || undefined,
959
+ maxWakesPerHour: Number(draft.maxWakesPerHour) || undefined,
960
+ sessionMaxWakes: Number(draft.sessionMaxWakes) || undefined,
961
+ }),
962
+ })
963
+ setEditing(null)
964
+ }, '已保存:' + watcher.repo)
965
+
966
+ const act = (watcher, action) => run(async () => {
967
+ await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(watcher) }) })
968
+ }, action === 'delete' ? '已删除 ' + watcher.repo : action === 'poll' ? '已触发一次轮询:' + watcher.repo : null)
969
+
970
+ const actBulk = (action) => run(async () => {
971
+ for (const watcher of watchers) {
972
+ if (action === 'pause' && !watcher.enabled) continue
973
+ if (action === 'resume' && watcher.enabled) continue
974
+ await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(watcher) }) })
975
+ }
976
+ }, action === 'pause' ? '全部已暂停' : '全部已恢复')
977
+
978
+ const addWatcher = () => run(async () => {
979
+ const created = await call('/watch', {
980
+ method: 'POST',
981
+ body: JSON.stringify({
982
+ repo: form.repo.trim(),
983
+ intervalSec: Number(form.intervalSec) || 60,
984
+ goal: form.goal,
985
+ sessionId,
986
+ filters: {
987
+ labels: String(form.labels || '').split(',').map((v) => v.trim()).filter(Boolean),
988
+ onlyAssigned: !!form.onlyAssigned,
989
+ },
990
+ activeHours: form.activeHours || '',
991
+ isolated: !!form.isolated,
992
+ workdir: form.workdir || '',
993
+ observe: !!form.observe,
994
+ batchLimit: Number(form.batchLimit) || undefined,
995
+ maxWakesPerHour: Number(form.maxWakesPerHour) || undefined,
996
+ }),
997
+ })
998
+ setForm({ repo: '', intervalSec: form.intervalSec, goal: '', labels: '', onlyAssigned: false, activeHours: form.activeHours, isolated: form.isolated, workdir: form.workdir, observe: form.observe })
999
+ // 添加前体检的警告直接说出来:填错仓库名 / 只读 / 归档,这一刻讲最省事
1000
+ const warnings = (created && Array.isArray(created.warnings)) ? created.warnings : []
1001
+ if (warnings.length > 0) notify('已添加,但注意:' + warnings.join(' / '), 'error')
1002
+ else notify('已添加,首轮立即开始轮询', 'info')
1003
+ return warnings
1004
+ }, null)
1005
+
1006
+ const saveCredentials = () => run(async () => {
1007
+ const payload = {}
1008
+ if (token.trim()) payload.token = token.trim()
1009
+ await call('/credentials', { method: 'POST', body: JSON.stringify(payload) })
1010
+ setToken('')
1011
+ }, '凭证已保存')
1012
+
1013
+ const saveGoal = () => run(async () => {
1014
+ await call('/goal', { method: 'POST', body: JSON.stringify({ sessionId, objective: goalDraft }) })
1015
+ setGoalTouched(false)
1016
+ }, 'goal 已保存')
1017
+
1018
+ const running = watchers.filter((w) => orbitStateOf(w) === 'active').length
1019
+ const broken = watchers.filter((w) => orbitStateOf(w) === 'error').length
1020
+ const paused = watchers.filter((w) => w.enabled === false).length
1021
+
1022
+ const stateTag = (watcher) => {
1023
+ const state = orbitStateOf(watcher)
1024
+ const tone = state === 'active' ? 'success' : state === 'paused' ? 'warning' : state === 'dormant' ? 'outline' : 'danger'
1025
+ return h(Tag, { tone, title: state === 'dormant' ? '不在活跃时段:只攒条目,不唤醒' : undefined }, STATE_TEXT[state])
1026
+ }
1027
+
1028
+ // 行结构对齐官方 rows.tsx 的 TicketLine:dt-ticket(左侧状态列)+ dt-open 标题 + dt-ticket-actions。
1029
+ // 标题本身是按钮 —— 官方就是点标题进详情,我们点标题展开行内编辑,交互更轻但不脱离这套结构。
1030
+ const STAGE_STATE = { active: undefined, paused: 'warning', error: 'error', dormant: 'warning' }
1031
+ const row = (watcher) => {
1032
+ const key = watcher.repo + '#' + watcher.sessionId
1033
+ const state = orbitStateOf(watcher)
1034
+ const rowBody = h('div', { className: 'dt-ticket-body' },
1035
+ h('div', { className: 'dt-row-title' },
1036
+ h('button', {
1037
+ type: 'button', className: 'dt-open', title: '展开或收起这条主理鱼的设置',
1038
+ 'aria-expanded': editing === key, onClick: () => {
1039
+ setEditing(editing === key ? null : key)
1040
+ setDraft({
1041
+ intervalSec: String(watcher.intervalSec ?? 60),
1042
+ labels: (watcher.filters && watcher.filters.labels ? watcher.filters.labels : []).join(','),
1043
+ activeHours: watcher.activeHours || '',
1044
+ goal: watcher.note || watcher.goal || '',
1045
+ onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
1046
+ // 下面这些以前没填 —— 打开一条隔离执行的守再直接保存,会把 isolated 写回 false
1047
+ observe: !!watcher.observe,
1048
+ isolated: !!watcher.isolated,
1049
+ workdir: watcher.workdir || '',
1050
+ batchLimit: watcher.batchLimit ? String(watcher.batchLimit) : '',
1051
+ maxWakesPerHour: watcher.maxWakesPerHour ? String(watcher.maxWakesPerHour) : '',
1052
+ sessionMaxWakes: watcher.sessionMaxWakes ? String(watcher.sessionMaxWakes) : '',
1053
+ isolateKeepDays: watcher.isolateKeepDays ? String(watcher.isolateKeepDays) : '',
1054
+ maxIsolated: watcher.maxIsolated ? String(watcher.maxIsolated) : '',
1055
+ priorityReopened: (watcher.priority && watcher.priority.reopened) !== false,
1056
+ priorityComments: (watcher.priority && watcher.priority.comments) !== false,
1057
+ priorityLabels: (watcher.priority && watcher.priority.labels) !== false,
1058
+ priorityUnassigned: Boolean(watcher.priority && watcher.priority.unassigned) === true,
1059
+ priorityStale: Boolean(watcher.priority && watcher.priority.stale) === true,
1060
+ })
1061
+ },
1062
+ }, watcher.repo)),
1063
+ h('div', { className: 'dt-row-meta dt-ticket-meta' },
1064
+ stateTag(watcher),
1065
+ ...repoBadges(watcher.repoAccess).map((badge) => h(Pill, {
1066
+ key: 'b-' + badge.text,
1067
+ active: badgeFilter === badge.text,
1068
+ onClick: () => setBadgeFilter(badgeFilter === badge.text ? null : badge.text),
1069
+ }, badge.text)),
1070
+ watcher.observe ? h(Tag, { tone: 'warning' }, '仅观察') : null,
1071
+ watcher.activeHours ? h(Tag, null, '时段 ' + watcher.activeHours) : null,
1072
+ watcher.isolated ? h(Tag, null, isolationText(watcher)) : null,
1073
+ filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
1074
+ backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
1075
+ h('div', { className: 'dt-ticket-note' },
1076
+ [
1077
+ (watcher.title || '未命名会话') + ' · ' + sessionTag(watcher.sessionId),
1078
+ '每 ' + watcher.intervalSec + 's',
1079
+ '轮询 ' + ageText(watcher.lastPoll),
1080
+ '唤醒 ' + wakeText(watcher.lastWake),
1081
+ historyText(watcher),
1082
+ watcher.note ? '目标: ' + String(watcher.note).slice(0, 40) : '',
1083
+ ].filter(Boolean).join(' · ')),
1084
+ watcher.lastDeferred ? h('div', { className: 'dt-ticket-note' }, watcher.lastDeferred) : null,
1085
+ watcher.lastError ? (() => {
1086
+ const parts = splitErrorText(watcher.lastError)
1087
+ return h('div', { className: 'dt-ticket-note dt-ticket-note-error' },
1088
+ parts.main.slice(0, 120) + (parts.main.length > 120 ? '…' : ''),
1089
+ parts.hint ? h('div', { className: 'dt-hint' }, parts.hint) : null)
1090
+ })() : null,
1091
+ h('div', { className: 'dt-ticket-actions' },
1092
+ h(Btn, { size: 'sm', variant: 'outline', icon: h(Icon, { name: 'refresh' }), onClick: () => act(watcher, 'poll') }, '立刻'),
1093
+ h(Btn, {
1094
+ size: 'sm', variant: 'ghost',
1095
+ icon: h(Icon, { name: watcher.enabled ? 'pause' : 'play' }),
1096
+ label: watcher.enabled ? '暂停' : '恢复',
1097
+ onClick: () => act(watcher, watcher.enabled ? 'pause' : 'resume'),
1098
+ }, watcher.enabled ? '暂停' : '恢复'),
1099
+ h(ConfirmBtn, {
1100
+ size: 'sm', variant: 'ghost', icon: h(Icon, { name: 'trash' }), label: '删除',
1101
+ confirmLabel: '确认删除', onConfirm: () => act(watcher, 'delete'),
1102
+ })))
1103
+ const editor = editing === key
1104
+ ? h('div', { className: 'dt-fieldset' },
1105
+ field('间隔(秒)', h(Input, { value: draft.intervalSec, onChange: (e) => setDraft({ ...draft, intervalSec: e.target.value }) }), '多长时间检查一次这个仓库,最小 30 秒'),
1106
+ field('只处理这些标签', h(Input, { value: draft.labels, placeholder: '逗号分隔,留空 = 全部', onChange: (e) => setDraft({ ...draft, labels: e.target.value }) })),
1107
+ field('活跃时段', h(Input, { value: draft.activeHours, placeholder: '09:00-23:00,留空 = 全天', onChange: (e) => setDraft({ ...draft, activeHours: e.target.value }) }), '只在这个时间段内唤醒;窗口外只攒条目,不打扰'),
1108
+ field('目标/规则', h(Input, { value: draft.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setDraft({ ...draft, goal: e.target.value }) })),
1109
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.onlyAssigned, onChange: (v) => setDraft({ ...draft, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1110
+ field('单次最多唤醒条数', h(Input, { value: draft.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setDraft({ ...draft, batchLimit: e.target.value }) })),
1111
+ field('每小时最多唤醒次数', h(Input, { value: draft.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setDraft({ ...draft, maxWakesPerHour: e.target.value }) })),
1112
+ field('这条会话每小时最多被唤醒', h(Input, { value: draft.sessionMaxWakes || '', placeholder: '12(1-60)', onChange: (e) => setDraft({ ...draft, sessionMaxWakes: e.target.value }) }), '跨所有守累计:守 5 个仓库时,光有单守上限挡不住叠加'),
1113
+ field('优先级(一次只处理 N 条时先挑谁)', h('div', { className: 'dt-actions' },
1114
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityReopened !== false, onChange: (v) => setDraft({ ...draft, priorityReopened: v }), label: '重开优先' }), '被重开的排最前'),
1115
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityComments !== false, onChange: (v) => setDraft({ ...draft, priorityComments: v }), label: '评论优先' }), '有人在等回应的靠前'),
1116
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityLabels !== false, onChange: (v) => setDraft({ ...draft, priorityLabels: v }), label: '标签优先' }), '带标签的靠前'),
1117
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityUnassigned === true, onChange: (v) => setDraft({ ...draft, priorityUnassigned: v }), label: '未认领优先' }), '没人认领的靠前(默认关:这是我们的判断,不是规则)'),
1118
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityStale === true, onChange: (v) => setDraft({ ...draft, priorityStale: v }), label: '积压优先' }), '躺了 30 天以上的靠前(默认关,只展示)')), '全部关掉时按 GitHub 的「最近更新」顺序处理'),
1119
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.observe, onChange: (v) => setDraft({ ...draft, observe: v }), label: '仅观察' }), '仅观察(只记录不唤醒)'),
1120
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.isolated, onChange: (v) => setDraft({ ...draft, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一个临时副本;在副本里改,用完自动回收)'),
1121
+ draft.isolated ? field('隔离工作目录', h(Input, { value: draft.workdir || '', placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setDraft({ ...draft, workdir: e.target.value }) })) : null,
1122
+ draft.isolated ? field('隔离区保留天数', h(Input, { value: draft.isolateKeepDays || '', placeholder: '3(1-30)', onChange: (e) => setDraft({ ...draft, isolateKeepDays: e.target.value }) }), '每次唤醒前回收这个天数之前的一次性工作区;留空用默认 3 天') : null,
1123
+ draft.isolated ? field('最多保留几个隔离区', h(Input, { value: draft.maxIsolated || '', placeholder: '5(1-50)', onChange: (e) => setDraft({ ...draft, maxIsolated: e.target.value }) }), '天数之外的第二道线:超出就回收最旧的(不影响正在用的那个)') : null,
1124
+ h('div', { className: 'dt-actions' },
1125
+ h(Btn, { size: 'sm', variant: 'primary', onClick: () => saveEdit(watcher) }, '保存'),
1126
+ h(Btn, { size: 'sm', onClick: () => setEditing(null) }, '放弃')))
1127
+ : null
1128
+ // 官方 TicketLine 是 <li class="dt-row dt-link dt-ticket"> 里套「状态列 + 正文列」,
1129
+ // 展开的表单跟在正文列里,不破坏两列网格。
1130
+ const bodyChildren = [].concat(rowBody.props.children || []).filter(Boolean)
1131
+ return h('li', {
1132
+ key,
1133
+ className: 'dt-row dt-link dt-ticket',
1134
+ 'data-state': state === 'error' ? 'error' : undefined,
1135
+ },
1136
+ h('div', { className: 'dt-ticket-stage' },
1137
+ h('span', { className: 'dt-stage', 'data-state': STAGE_STATE[state] }, STATE_TEXT[state])),
1138
+ h('div', { className: 'dt-ticket-body' }, ...bodyChildren, editor))
1139
+ }
1140
+
1141
+ const problems = []
1142
+ // 按暂停原因筛选时,「需要关注」也一起收窄(否则列表和告警会自相矛盾)
1143
+ const deferFilter = reasonFilter && reasonFilter.startsWith('defer:') ? reasonFilter.slice(6) : null
1144
+ for (const watcher of watchers) {
1145
+ if (deferFilter && watcher.deferReason !== deferFilter) continue
1146
+ // 仓库结构问题(关闭 Issues / 是 fork)比轮询失败更早该说:它注定收不到条目
1147
+ const structure = repoStructureNote(watcher.repoAccess)
1148
+ if (structure) problems.push({ key: 's-' + watcher.repo, text: structure })
1149
+ // 只读:以前只在行内显示一个徽章,客户在「需要关注」里看不到,也不知道回写会 403
1150
+ const readOnly = accessNoteForPanel(watcher.repoAccess, watcher.repo)
1151
+ if (readOnly) problems.push({ key: 'ro-' + watcher.repo, text: readOnly })
1152
+ // 叫醒了但没回音:守在工作、消息也进去了,但会话没动手(规则缺失或被忽略)
1153
+ if (Number(watcher.silentWakes) >= 2) {
1154
+ problems.push({
1155
+ key: 'silent-' + watcher.repo,
1156
+ text: watcher.repo + ' 连续 ' + watcher.silentWakes + ' 次被叫醒后没有动作(没看到 watch_ack 标签)—— 会话可能没按规则处理',
1157
+ action: { label: '看建议规则', onClick: () => setGlossary('rules:' + watcher.repo) },
1158
+ })
1159
+ }
1160
+ // 被反复重开的条目:说明"之前判过不做"可能有问题,值得人看一眼
1161
+ if (watcher.lastReopened) {
1162
+ problems.push({ key: 'r-' + watcher.repo, text: watcher.repo + ' #' + watcher.lastReopened + ' 被重新打开过 —— 之前判"不做"可能不对' })
1163
+ }
1164
+ if (structure) problems.push({ key: 's-' + watcher.repo, text: structure })
1165
+ if (watcher.lastError) {
1166
+ // 同样拆开:现象截断、建议保留(这里原来是整串塞进「需要关注」)
1167
+ const parts = splitErrorText(watcher.lastError)
1168
+ problems.push({
1169
+ key: 'e-' + watcher.repo,
1170
+ text: watcher.repo + ' 轮询失败:' + parts.main.slice(0, 120) + (parts.main.length > 120 ? '…' : '') + ' ' + parts.hint,
1171
+ })
1172
+ }
1173
+ else if (watcher.lastDeferred) problems.push({ key: 'd-' + watcher.repo, text: watcher.repo + ' 暂停唤醒:' + watcher.lastDeferred })
1174
+ }
1175
+ if (body.gh && body.gh.ok === false && credentials.token === 'none') {
1176
+ problems.push({ key: 'gh', text: 'gh CLI 不可用,且没有配置 token —— 现在所有轮询都会失败。先跑 gh auth login,或在「设置 → 来源」填一个 token。' })
1177
+ }
1178
+ if (watchers.length > 0 && credentials.token === 'none') {
1179
+ problems.push({ key: 'cred', text: '未配置 token,正在复用已登录的 gh CLI(可用 panel 填 token 换成独立凭据)' })
1180
+ }
1181
+
1182
+ const needle = search.trim().toLowerCase()
1183
+ const matches = (watcher) => !needle
1184
+ || watcher.repo.toLowerCase().includes(needle)
1185
+ || (watcher.title || '').toLowerCase().includes(needle)
1186
+ || (watcher.filteredLog || []).some((entry) => String(entry.number).includes(needle) || String(entry.title || '').toLowerCase().includes(needle))
1187
+ const matchesBadge = (watcher) => !badgeFilter
1188
+ || repoBadges(watcher.repoAccess).some((badge) => badge.text === badgeFilter)
1189
+ const hasProblem = (watcher) => Boolean(watcher.lastError)
1190
+ || Number(watcher.silentWakes) >= 2
1191
+ || Boolean(repoStructureNote(watcher.repoAccess))
1192
+ || repoBadges(watcher.repoAccess).some((badge) => badge.tone === 'warning' || badge.tone === 'danger')
1193
+ const visible = watchers.filter((watcher) => matches(watcher) && matchesBadge(watcher)
1194
+ && (!problemsOnly || hasProblem(watcher))
1195
+ && (!deferFilter || watcher.deferReason === deferFilter))
1196
+
1197
+ const overview = [
1198
+ watchers.some((w) => (w.filteredLog || []).length > 0)
1199
+ ? h(Section, { key: 'filtered', title: '最近被过滤' },
1200
+ h(CollapsibleList, {
1201
+ title: '看被过滤的条目',
1202
+ items: watchers.flatMap((w) => (w.filteredLog || []).slice(-2).map((entry) =>
1203
+ '#' + entry.number + ' ' + (entry.title || '') + ' — ' + entry.reason)),
1204
+ }))
1205
+ : null,
1206
+ problems.length > 0
1207
+ ? h(Section, { key: 'problems', title: '需要关注', count: problems.length },
1208
+ h('ul', { className: 'dt-plain-list' }, problems.map((item) => h('li', { key: item.key, className: 'dt-danger' }, item.text))))
1209
+ : null,
1210
+ // 中间态:已经有守、但一次都没唤醒过 —— 这不是"没配置",是"在等"
1211
+ (watchers.length > 0 && watchers.every((w) => !w.lastWake))
1212
+ ? h('div', { className: 'sa-dock-foot', key: 'waiting' },
1213
+ '还没有唤醒过:守会在仓库出现新条目时叫醒这个会话。'
1214
+ + '想先试一次,点行里的「立刻」;如果一直没动静,看上面「需要关注」里有没有被过滤的记录。'
1215
+ + '叫醒之后:会话先读仓库 AGENTS.md → 决定「修 / 回 / 待定」→ 做完写回并 watch_ack 打标签;'
1216
+ + '不做也要说明理由并 ack。每次只处理叫醒消息里列出的那几条,不会扩大范围。')
1217
+ : null,
1218
+ // 需要重启:这是"功能看起来没生效"最常见的根因,必须显眼
1219
+ (body.installedVersion && body.runningVersion && body.installedVersion !== body.runningVersion)
1220
+ ? h('div', { className: 'dt-banner dt-danger', key: 'restart-needed' },
1221
+ '代码已更新到 ' + body.installedVersion + ',但宿主还在跑 ' + body.runningVersion
1222
+ + ' —— 服务端改动需要重启宿主才生效(客户端部分已生效,所以界面可能看起来是新的)。')
1223
+ : null,
1224
+ badgeFilter
1225
+ ? h('div', { className: 'dt-row-meta', key: 'badge-filter' },
1226
+ h('span', null, '只看 ' + badgeFilter + ' 的守(' + visible.length + ' 条):'),
1227
+ h(Pill, { onClick: () => setBadgeFilter(null) }, '清除'))
1228
+ : null,
1229
+ h('div', { className: 'dt-stats', key: 'stats' },
1230
+ h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(watchers.length)), h('span', null, '条主理鱼')),
1231
+ h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(running)), h('span', null, '主理中')),
1232
+ h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(paused)), h('span', null, '已暂停')),
1233
+ h('div', { className: 'dt-stat' }, h('span', { className: 'dt-stat-value' }, String(broken)), h('span', null, '异常'))),
1234
+ h(Section, { key: 'list', title: needle ? '搜索结果' : '主理鱼', count: visible.length },
1235
+ watchers.length === 0
1236
+ ? h(Onboarding, { onStart: () => setTab('trigger') })
1237
+ : visible.length === 0
1238
+ ? h(Hint, null, '没有匹配「' + search + '」的主理鱼。')
1239
+ : h('ul', { className: 'dt-list' }, visible.map(row))),
1240
+ ]
1241
+
1242
+ // 判定日志(对应官方 eval 页):每轮的唤醒结果、跳过原因、被过滤记录,一次看全
1243
+ // 判定页用官方的时间线结构(dt-timeline / dt-event / dt-event-foot),
1244
+ // 官方在 thread.tsx 与 settings-kit.tsx 里就是这么铺「发生过什么」的。
1245
+ // 跳过原因分布:把「为什么没叫醒」做成可读的统计(客户最常问的问题)
1246
+ const reasonTotals = (() => {
1247
+ const merged = {}
1248
+ for (const w of watchers) for (const [reason, n] of Object.entries(w.filterCounts || {})) {
1249
+ merged[reason] = (Number(merged[reason]) || 0) + (Number(n) || 0)
1250
+ }
1251
+ return Object.entries(merged).sort((a, b) => b[1] - a[1]).slice(0, 8)
1252
+ })()
1253
+ const judge = h(Section, {
1254
+ title: '判定日志',
1255
+ count: watchers.reduce((n, w) => n + (w.history || []).length, 0),
1256
+ action: h(InfoTip, { text: '每轮判定都会记一条:唤醒、仅观察,或跳过及其原因。只存最近若干条。' }),
1257
+ },
1258
+ (() => {
1259
+ const needle = search.trim()
1260
+ const asNumber = /^#?[0-9]+$/.test(needle) ? needle.replace('#', '') : ''
1261
+ const onlyRepo = watchers.length === 1 ? watchers[0].repo : ''
1262
+ return h(Section, { key: 'trace', title: '追溯一条', hint: '在右上角搜索框输入编号(如 42),这里就能查它经历了什么' },
1263
+ asNumber
1264
+ ? h('div', { className: 'dt-row-meta' },
1265
+ h('button', {
1266
+ className: 'dt-textlink',
1267
+ type: 'button',
1268
+ onClick: async () => {
1269
+ try {
1270
+ const query = '/trace?number=' + encodeURIComponent(asNumber) + (onlyRepo ? '&repo=' + encodeURIComponent(onlyRepo) : '')
1271
+ const payload = await call(query)
1272
+ notify(String((payload && payload.text) || '没有结果').split(String.fromCharCode(10)).join(' · '), 'info')
1273
+ } catch (error) {
1274
+ notify('追溯失败:' + String((error && error.message) || error), 'error')
1275
+ }
1276
+ },
1277
+ }, '追溯 #' + asNumber),
1278
+ h('span', { className: 'dt-row-meta' }, onlyRepo ? '(在 ' + onlyRepo + ' 里查)' : '(在所有守里查)'))
1279
+ : h(Hint, null, '追溯会告诉你:它被过滤了、已经唤醒过、还是根本没轮到。'))
1280
+ })(),
1281
+ (() => {
1282
+ const counts = new Map()
1283
+ for (const w of watchers) if (w.deferReason) counts.set(w.deferReason, (counts.get(w.deferReason) || 0) + 1)
1284
+ if (counts.size === 0) return null
1285
+ return h('div', { className: 'dt-row-meta', key: 'defer-totals' },
1286
+ h('span', null, '暂停原因:'),
1287
+ [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([code, n]) => h(Pill, {
1288
+ key: code,
1289
+ active: deferFilter === code,
1290
+ onClick: () => setReasonFilter(deferFilter === code ? null : 'defer:' + code),
1291
+ }, (DEFER_LABELS[code] || code) + ' × ' + n)),
1292
+ deferFilter ? h(Pill, { key: 'clear-defer', onClick: () => setReasonFilter(null) }, '清除') : null)
1293
+ })(),
1294
+ reasonTotals.length > 0
1295
+ ? h('div', { className: 'dt-row-meta', key: 'reason-totals' },
1296
+ h('span', null, '跳过原因累计:'),
1297
+ reasonTotals.map(([reason, n]) => h(Pill, {
1298
+ key: reason,
1299
+ active: reasonFilter === reason,
1300
+ onClick: () => setReasonFilter(reasonFilter === reason ? null : reason),
1301
+ }, reason + ' × ' + n)),
1302
+ reasonFilter ? h(Pill, { key: 'clear', onClick: () => setReasonFilter(null) }, '清除筛选') : null)
1303
+ : null,
1304
+ reasonFilter
1305
+ ? h('ul', { className: 'dt-plain-list', key: 'reason-entries' },
1306
+ watchers.flatMap((w) => (w.filteredLog || [])
1307
+ .filter((entry) => entry.reason === reasonFilter)
1308
+ .map((entry) => h('li', { key: w.repo + '#' + entry.number + entry.at },
1309
+ w.repo + ' #' + entry.number + ' ' + String(entry.title || '').slice(0, 60)))))
1310
+ : null,
1311
+ watchers.length === 0
1312
+ ? h(Hint, null, '还没有主理鱼。')
1313
+ : h('ol', { className: 'dt-timeline' },
1314
+ watchers.flatMap((watcher) => (watcher.history || []).slice(-6).reverse().map((entry, index) => {
1315
+ const label = entry.ok ? '已唤醒' : entry.reason === 'observe' ? '仅观察(未唤醒)' : '跳过:' + (entry.reason || '未知')
1316
+ return h('li', {
1317
+ key: watcher.repo + '#' + watcher.sessionId + entry.at + index,
1318
+ className: 'dt-event' + (entry.ok ? '' : ' dt-event-quiet'),
1319
+ },
1320
+ h('div', { className: 'dt-event-foot' },
1321
+ h('strong', { className: 'dt-event-actor' }, watcher.repo),
1322
+ h('span', null, ageText(entry.at))),
1323
+ h('p', { className: 'dt-event-text' }, label),
1324
+ h('div', { className: 'dt-event-foot' },
1325
+ (entry.numbers || []).length > 0
1326
+ ? h('span', null, (entry.numbers || []).map((n) => '#' + n).join(' '))
1327
+ : null,
1328
+ h('span', null, (watcher.title || '未命名会话') + ' · ' + sessionTag(watcher.sessionId))))
1329
+ }))))
1330
+
1331
+ // 迷你时间线:回答"为什么这一轮没叫醒我"
1332
+ const timeline = h(Section, { key: 'timeline', title: '时间线(最近 20 条)' },
1333
+ watchers.length === 0
1334
+ ? h(Hint, null, '还没有守。添加一条之后,这里会记录每次唤醒、攒着、限流、回收。')
1335
+ : h('div', { className: 'dt-rows' }, watchers.flatMap((watcher) => (watcher.events || []).slice().reverse().map((event, index) => h('div', {
1336
+ key: watcher.repo + '-ev' + index,
1337
+ className: 'dt-row',
1338
+ },
1339
+ h('div', { className: 'dt-row-main' },
1340
+ h('div', { className: 'dt-row-title' },
1341
+ h(Tag, { tone: event.kind === 'wake' ? 'success' : event.kind === 'wake-failed' ? 'danger' : 'outline' },
1342
+ event.kind + (Number(event.count) > 1 ? ' ×' + event.count : '')),
1343
+ (Number(event.count) > 1 && event.since)
1344
+ ? h('span', { className: 'dt-row-meta' }, '持续 ' + durationText(event.since, event.at))
1345
+ : null,
1346
+ h('span', { className: 'dt-row-meta' }, ageText(event.at))),
1347
+ h('div', { className: 'dt-hint' }, watcher.repo + ' · ' + event.text)))))))
1348
+
1349
+ // 按仓库汇总:守多个仓库时先看哪个健康,再看明细(渐进披露)
1350
+ const problemCount = watchers.filter(hasProblem).length
1351
+ const repoSummary = watchers.length === 0 ? null : h(Section, { key: 'repo-summary', title: '按仓库', hint: '点仓库名只看它(再点取消)' },
1352
+ h('div', { className: 'dt-row-meta' },
1353
+ h(Pill, { active: problemsOnly, onClick: () => setProblemsOnly(!problemsOnly) }, '只看有问题的' + (problemCount > 0 ? ' (' + problemCount + ')' : '')),
1354
+ problemsOnly ? h(Pill, { onClick: () => setProblemsOnly(false) }, '全部') : null),
1355
+ body.sessionUsage
1356
+ ? h('div', { className: 'dt-row-meta' },
1357
+ h('span', null, '本会话近一小时唤醒 ' + body.sessionUsage.used + '/' + body.sessionUsage.cap),
1358
+ body.sessionUsage.used >= body.sessionUsage.cap
1359
+ ? h('span', { className: 'dt-error-text' },
1360
+ '已到上限:新条目会攒到下一小时' +
1361
+ (body.sessionUsage.suggest ? ';建议把「这条会话每小时最多被唤醒」调到 ' + body.sessionUsage.suggest : ';可以把该上限调大'))
1362
+ : null,
1363
+ body.sessionUsage.capped > 0
1364
+ ? h('span', { className: 'dt-error-text' }, body.sessionUsage.capped + ' 条守正因上限暂停')
1365
+ : null,
1366
+ (() => {
1367
+ // 过去几天累计(数据来自每条守的 daily,几十字节)
1368
+ const days = watchers.reduce((n, w) => n + (Number(w.daily && w.daily.days) || 0), 0)
1369
+ const total = watchers.reduce((n, w) => n + (Number(w.daily && w.daily.total) || 0), 0)
1370
+ if (total === 0) return null
1371
+ const span = Math.max(...watchers.map((w) => Number(w.daily && w.daily.days) || 0))
1372
+ return [
1373
+ h('span', { key: 'hist', className: 'dt-row-meta' }, '过去 ' + span + ' 天:共 ' + total + ' 次(日均 ' + (Math.round((total / Math.max(1, span)) * 10) / 10) + ')'),
1374
+ watchers.some((w) => w.busy)
1375
+ ? h('span', { key: 'busy', className: 'dt-error-text' }, '今天明显比平时忙 —— 上限可能不够用')
1376
+ : null,
1377
+ ]
1378
+ })())
1379
+ : null,
1380
+ visible.length === 0 ? h(Hint, null, '没有符合条件的主理鱼。点上面「全部」看所有守。') : null,
1381
+ h('div', { className: 'dt-rows' }, ...summarizeByRepo(visible).map((group) => h('div', { key: 'repo-' + group.repo, className: 'dt-row' },
1382
+ h('div', { className: 'dt-row-main' },
1383
+ h('div', { className: 'dt-row-title' },
1384
+ h(StateDot, { state: group.errors > 0 ? 'error' : group.silentWakes >= 2 ? 'warning' : 'done' }),
1385
+ h('button', {
1386
+ className: 'dt-textlink dt-row-name',
1387
+ type: 'button',
1388
+ onClick: () => setSearch(search === group.repo ? '' : group.repo),
1389
+ title: '点一下只看这个仓库(再点取消)',
1390
+ }, group.repo),
1391
+ ...group.badges.map((badge) => h(Tag, { key: 'rb-' + badge.text, tone: badge.tone }, badge.text))),
1392
+ h('div', { className: 'dt-row-meta' },
1393
+ h('span', null, group.count + ' 条守(启用 ' + group.enabled + ')'),
1394
+ h('span', null, group.lastWake ? '最近唤醒 ' + ageText(group.lastWake) : '还没唤醒过'),
1395
+ group.silentWakes > 0 ? h('span', { className: 'dt-error-text' }, '未回音 ' + group.silentWakes + ' 次') : null,
1396
+ group.errors > 0 ? h('span', { className: 'dt-error-text' }, group.errors + ' 条报错') : null))))))
1397
+
1398
+ const trigger = h(Section, { title: '新增主理鱼' },
1399
+ h('div', { className: 'dt-form' },
1400
+ field('仓库', h(Input, { value: form.repo, placeholder: 'owner/name', onChange: (e) => setForm({ ...form, repo: e.target.value }) })),
1401
+ field('间隔(秒)', h(Input, { value: form.intervalSec, onChange: (e) => setForm({ ...form, intervalSec: e.target.value }) })),
1402
+ field('单次最多唤醒条数', h(Input, { value: form.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setForm({ ...form, batchLimit: e.target.value }) })),
1403
+ field('每小时最多唤醒次数', h(Input, { value: form.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setForm({ ...form, maxWakesPerHour: e.target.value }) })),
1404
+ field('只处理这些标签', h(Input, { value: form.labels, placeholder: '逗号分隔,留空 = 全部', onChange: (e) => setForm({ ...form, labels: e.target.value }) })),
1405
+ field('活跃时段', h(Input, { value: form.activeHours, placeholder: '09:00-23:00,留空 = 全天', onChange: (e) => setForm({ ...form, activeHours: e.target.value }) })),
1406
+ field('目标/规则', h(Input, { value: form.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setForm({ ...form, goal: e.target.value }) })),
1407
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: form.onlyAssigned, onChange: (v) => setForm({ ...form, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1408
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!form.observe, onChange: (v) => setForm({ ...form, observe: v }), label: '仅观察' }), '仅观察(只记录本会唤醒哪几条,不真唤醒)'),
1409
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: form.isolated, onChange: (v) => setForm({ ...form, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一个临时副本;在副本里改,用完自动回收)'),
1410
+ form.isolated ? field('隔离工作目录', h(Input, { value: form.workdir, placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setForm({ ...form, workdir: e.target.value }) })) : null,
1411
+ h('div', { className: 'dt-actions' },
1412
+ h(Btn, { variant: 'primary', icon: h(Icon, { name: 'plus' }), onClick: addWatcher, disabled: !sessionId || !form.repo.trim() },
1413
+ sessionId ? '添加到当前会话' : '需要会话上下文'))))
1414
+
1415
+ const settingsSections = [
1416
+ h(Section, { key: 'source', title: '来源' },
1417
+ h(KeyValues, { rows: [
1418
+ ['仓库', watchers.length === 0 ? '未绑定' : watchers.map((w) => w.repo).join(', ')],
1419
+ ['gh CLI', !body.gh
1420
+ ? '检测中…'
1421
+ : body.gh.ok
1422
+ ? '可用 · ' + (body.gh.version || '')
1423
+ : '不可用 —— 先跑 gh auth login(或装 gh CLI);也可以直接在下面填 token · ' + String(body.gh.error || '').slice(0, 80)],
1424
+ ['凭证', credentials.token === 'none' ? '回退到 gh CLI 登录态' : '使用面板配置的 token'],
1425
+ ['权限范围', (() => {
1426
+ const info = body.tokenScopes
1427
+ if (!info) return '正在探测…'
1428
+ if (!info.ok) return '探测失败:' + String(info.error || '').slice(0, 60)
1429
+ if (!info.scopes.length) return '细粒度 token(无 OAuth scope)'
1430
+ return info.scopes.join(', ')
1431
+ })()],
1432
+ (body.tokenScopes && body.tokenScopes.broad && body.tokenScopes.broad.length > 0)
1433
+ ? ['提示', '这个 token 带 ' + body.tokenScopes.broad.join(', ') + ' —— 我们的功能只需要「读 issue/PR + 写评论和标签」,建议换细粒度 token 只授 Issues 读写']
1434
+ : null,
1435
+ ['隔离占用', !body.isolation || (body.isolation.roots || []).length === 0
1436
+ ? '没有开隔离执行'
1437
+ : (body.isolation.roots || []).map((r) => r.count + ' 个 · ' + bytesText(r.bytes)).join(';')
1438
+ + '(合计 ' + bytesText(body.isolation.totalBytes) + ')'],
1439
+ ] })),
1440
+ h(Section, { key: 'creds', title: '凭证' },
1441
+ h(KeyValues, { rows: [['GitHub token', credentials.token === 'none' ? '未配置(回退到已登录的 gh CLI)' : '已配置'], ['SSH 私钥', credentials.sshKeyPath === 'none' ? '未配置(当前版本不使用)' : '已配置']] }),
1442
+ field('Token', h(Input, { type: 'password', value: token, placeholder: 'ghp_… / github_pat_…(留空不改)', onChange: (e) => setToken(e.target.value) })),
1443
+ h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveCredentials }, '保存凭证')),
1444
+ h(Hint, null, '不填也能用:插件直接复用已登录的 gh CLI。')),
1445
+ h(Section, { key: 'update', title: '版本与更新' },
1446
+ h(KeyValues, { rows: [
1447
+ ['当前版本', (update && update.current) || CLIENT_VERSION],
1448
+ ['npm 最新', !update ? '检测中…' : update.error ? '检测失败 · ' + update.error : (update.latest || '未知')],
1449
+ ['状态', !update ? '…' : update.hasUpdate ? '有新版本,可以升级' : '已是最新'],
1450
+ ] }),
1451
+ update && update.hasUpdate
1452
+ ? h('div', null,
1453
+ h('code', { className: 'dt-code' }, update.command),
1454
+ h('div', { className: 'dt-actions' },
1455
+ h(Btn, { size: 'sm', onClick: () => { try { navigator.clipboard.writeText(update.command) } catch {} } }, '复制命令')))
1456
+ : null,
1457
+ h('div', { className: 'dt-actions' },
1458
+ h(Btn, { size: 'sm', variant: 'ghost', onClick: () => checkUpdate(true), disabled: checking }, checking ? '检查中…' : '重新检查')),
1459
+ h(Hint, null, '升级要改 profile,装完需要重载一次宿主才会用上新版本 —— 所以这里只给命令,不替你执行。'),
1460
+ h(Hint, null, '反馈问题时把下面这份诊断贴给对方:里面有版本、挂载状态和每条守的最近错误(凭证已脱敏)。'),
1461
+ h('div', { className: 'dt-actions' },
1462
+ h(Btn, {
1463
+ size: 'sm',
1464
+ variant: 'outline',
1465
+ onClick: async () => {
1466
+ try {
1467
+ const payload = await call('/diagnose')
1468
+ const text = String((payload && payload.text) || '')
1469
+ try { await navigator.clipboard.writeText(text) } catch {}
1470
+ notify('诊断信息已复制(' + text.split(String.fromCharCode(10)).length + ' 行)', 'info')
1471
+ } catch (error) {
1472
+ notify('生成诊断失败:' + String((error && error.message) || error), 'error')
1473
+ }
1474
+ },
1475
+ }, '复制诊断信息'))),
1476
+ h(Section, { key: 'diagnose', title: '分诊信号与取舍' },
1477
+ h(Hint, null, '一次只处理 N 条时,这些信号的加权决定先后。事实默认展示,判断默认关闭。'),
1478
+ h('div', { className: 'dt-rows' }, (body.triageSignals || []).map((sig) => h('div', { key: sig.key, className: 'dt-row' },
1479
+ h('div', { className: 'dt-row-main' },
1480
+ h('div', { className: 'dt-row-title' },
1481
+ h('span', { className: 'dt-row-name' }, sig.label),
1482
+ h(Tag, { tone: sig.kind === 'fact' ? 'success' : 'warning' }, sig.kind === 'fact' ? '事实' : '判断'),
1483
+ h(Tag, { tone: sig.default ? 'outline' : 'quiet' }, sig.default ? '默认开' : '默认关'),
1484
+ h('span', { className: 'dt-row-meta' }, '+' + sig.weight + ' 分')),
1485
+ h('div', { className: 'dt-hint' }, sig.why)))))),
1486
+
1487
+ h(Section, { key: 'goal', title: '会话 goal' },
1488
+ h('textarea', {
1489
+ className: 'dt-textarea', rows: 3, value: goalDraft,
1490
+ placeholder: '这个会话要达成什么(会写进 /goal)',
1491
+ onChange: (e) => { setGoalTouched(true); setGoalDraft(e.target.value) },
1492
+ }),
1493
+ h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveGoal, disabled: !sessionId }, '保存 goal'))),
1494
+ ]
1495
+
1496
+
1497
+ // 官方设置页是「左栏导航 + 右侧内容」的网格(dt-settings / dt-settings-nav / dt-settings-body)。
1498
+ // 我们之前是单列堆叠,四个分区一起铺开,深链路里翻起来很累。
1499
+ const SETTINGS_SECTIONS = [
1500
+ { key: 'source', title: '来源' },
1501
+ { key: 'creds', title: '凭证' },
1502
+ { key: 'update', title: '版本与更新' },
1503
+ { key: 'diagnose', title: '诊断' },
1504
+ { key: 'goal', title: '会话 goal' },
1505
+ ]
1506
+ const settingsBody = settingsSections.find((node) => node && node.props && node.props.key === settingsSection)
1507
+ || settingsSections.find(Boolean)
1508
+ const settings = h('div', { className: 'dt-settings' },
1509
+ h('nav', { className: 'dt-settings-nav', 'aria-label': '设置分区' },
1510
+ SETTINGS_SECTIONS.map((item) => h('button', {
1511
+ key: item.key, type: 'button', className: 'dt-settings-link',
1512
+ 'aria-current': settingsSection === item.key ? 'page' : undefined,
1513
+ onClick: () => setSettingsSection(item.key),
1514
+ }, item.title))),
1515
+ h('div', { className: 'dt-settings-body' }, settingsBody))
1516
+
1517
+ const checkUpdate = useCallback(async (force) => {
1518
+ setChecking(true)
1519
+ try {
1520
+ const value = await call('/update' + (force ? '?refresh=1' : ''))
1521
+ setUpdate(value)
1522
+ } catch (error) {
1523
+ setUpdate({ current: CLIENT_VERSION, latest: null, hasUpdate: false, error: String(error && error.message || error) })
1524
+ } finally {
1525
+ setChecking(false)
1526
+ }
1527
+ }, [])
1528
+
1529
+ useEffect(() => {
1530
+ let alive = true
1531
+ try {
1532
+ Promise.resolve(call('/update'))
1533
+ .then((value) => { if (alive) setUpdate(value) })
1534
+ .catch(() => {})
1535
+ } catch { /* 宿主早期渲染时 fetch 可能还不存在,忽略即可 */ }
1536
+ return () => { alive = false }
1537
+ }, [])
1538
+
1539
+
1540
+ /**
1541
+ * 面板自己遇到的错误也要说人话。
1542
+ *
1543
+ * 服务端那边的 gh 错误已经由 classifyGhError 归类(并附了 hint);
1544
+ * 但**面板拉自己接口失败**(宿主正在重启、端口变了、fetch 被拒)不会经过那套,
1545
+ * 以前界面上就是一行 "Failed to fetch" —— 客户看不懂,也不知道要做什么。
1546
+ */
1547
+ function humanizeError(text) {
1548
+ const raw = String(text == null ? '' : text)
1549
+ if (!raw) return ''
1550
+ if (/Failed to fetch|NetworkError|Load failed/i.test(raw)) {
1551
+ return '连不上宿主:DSH 可能正在重启,或插件刚被重载。稍等几秒会自动重试;一直这样就去「设置 → 诊断」复制信息。'
1552
+ }
1553
+ if (/HTTP 401|HTTP 403/i.test(raw)) return '宿主拒绝了请求(401/403):面板接口可能需要重新挂载,重启宿主即可。'
1554
+ if (/HTTP 5\d\d/.test(raw)) return '宿主内部报错(5xx):先把「设置 → 诊断」里的信息复制出来,再重启宿主试试。'
1555
+ if (/HTTP 404/.test(raw)) return '接口不存在(404):多半还在跑旧版本代码,重启宿主。'
1556
+ if (/timeout|timed out|ETIMEDOUT/i.test(raw)) return '请求超时:宿主可能正忙(比如同时在建隔离 worktree),稍后自动重试。'
1557
+ return raw
1558
+ }
1559
+
1560
+ /** 建议追加到仓库 AGENTS.md 的处理规则(只给文本,绝不代写文件)。 */
1561
+ const AGENTS_SNIPPET = [
1562
+ '## 主理鱼(dsh-session-superagent)处理规则',
1563
+ '',
1564
+ '- 收到「【主理鱼】<owner/name> 有 N 条新动态」时,先读完整条目再决定做不做。',
1565
+ '- 做:按【完成标准】三件事写清(改了什么 / 怎么验证 / 回写到哪),改完推分支开 PR。',
1566
+ '- 不做:也要说明理由(例如"已有 PR 在做"),然后照样 ack。',
1567
+ '- **无论做还是不做,最后都要 watch_ack 打标签**,否则下一轮会被再次唤醒。',
1568
+ ].join(String.fromCharCode(10))
1569
+
1570
+ /** 按仓库汇总(与服务端 watch.js:summarizeByRepo 同语义)。 */
1571
+ function summarizeByRepo(list) {
1572
+ const groups = new Map()
1573
+ for (const watcher of Array.isArray(list) ? list : []) {
1574
+ if (!watcher || !watcher.repo) continue
1575
+ const repo = String(watcher.repo)
1576
+ const group = groups.get(repo) || { repo, count: 0, lastWake: null, silentWakes: 0, errors: 0, enabled: 0, badges: [] }
1577
+ group.count += 1
1578
+ if (watcher.enabled !== false) group.enabled += 1
1579
+ if (watcher.lastWake && (!group.lastWake || String(watcher.lastWake) > String(group.lastWake))) group.lastWake = watcher.lastWake
1580
+ group.silentWakes = Math.max(group.silentWakes, Number(watcher.silentWakes) || 0)
1581
+ if (watcher.lastError) group.errors += 1
1582
+ for (const badge of repoBadges(watcher.repoAccess) || []) {
1583
+ if (!group.badges.some((b) => b.text === badge.text)) group.badges.push(badge)
1584
+ }
1585
+ groups.set(repo, group)
1586
+ }
1587
+ const weight = (g) => (g.errors > 0 ? 0 : g.silentWakes >= 2 ? 1 : 2)
1588
+ return [...groups.values()].sort((a, b) => (weight(a) - weight(b)) || a.repo.localeCompare(b.repo))
1589
+ }
1590
+
1591
+ /** 持续时长(与服务端 watch.js:durationText 同语义)。 */
1592
+ function durationText(sinceIso, untilIso) {
1593
+ const from = Date.parse(String(sinceIso || ''))
1594
+ const to = Date.parse(String(untilIso || ''))
1595
+ if (!Number.isFinite(from) || !Number.isFinite(to) || to < from) return ''
1596
+ const minutes = Math.floor((to - from) / 60000)
1597
+ if (minutes < 1) return '不到 1 分钟'
1598
+ if (minutes < 60) return minutes + ' 分钟'
1599
+ const hours = Math.floor(minutes / 60)
1600
+ const rest = minutes % 60
1601
+ return rest > 0 ? hours + ' 小时 ' + rest + ' 分' : hours + ' 小时'
1602
+ }
1603
+
1604
+ /** 只读仓库的提示(与服务端 gh-format.js:accessNote 同语义;面板要独立一份)。 */
1605
+ function accessNoteForPanel(access, repo) {
1606
+ if (!access || typeof access !== 'object') return ''
1607
+ if (access.push === true) return ''
1608
+ if (access.push !== false) return ''
1609
+ return '你对 ' + String(access.repo || repo || '这个仓库') + ' 只有读权限:能看、能被叫醒,但没法回写评论或打标签 —— ' +
1610
+ '要么换有写权限的 token,要么把结论写在本地/PR 描述里。'
1611
+ }
1612
+
1613
+ /** 仓库能力徽章(与服务端 watch.js:repoBadges 同语义)。 */
1614
+ function repoBadges(access) {
1615
+ if (!access || typeof access !== 'object') return []
1616
+ const badges = []
1617
+ if (access.archived === true) badges.push({ text: '已归档', tone: 'warning' })
1618
+ if (access.disabled === true) badges.push({ text: '已禁用', tone: 'danger' })
1619
+ if (access.hasIssues === false) badges.push({ text: '无 Issues', tone: 'warning' })
1620
+ if (access.fork === true && access.parent && access.hasIssues !== true) badges.push({ text: 'fork · 上游 ' + String(access.parent), tone: 'outline' })
1621
+ if (access.push === false) badges.push({ text: '只读', tone: 'warning' })
1622
+ if (access.private === true) badges.push({ text: '私有', tone: 'outline' })
1623
+ return badges
1624
+ }
1625
+
1626
+ /** 仓库结构提示(与服务端 watch.js:repoStructureNote 同语义;客户端要独立一份,不能跨包 import)。 */
1627
+ function repoStructureNote(access) {
1628
+ if (!access || typeof access !== 'object') return ''
1629
+ const repo = String(access.repo || '这个仓库')
1630
+ // 顺序与服务端 gh-format.js:repoStructureNote 保持一致:归档/禁用优先
1631
+ if (access.archived === true) return repo + ' 已归档:GitHub 上归档仓库是只读的,评论和打标签都会失败 —— 守它只能看、不能回写。'
1632
+ if (access.disabled === true) return repo + ' 已被禁用:这个仓库当前不可用,主理鱼不会拿到任何条目。'
1633
+ if (access.hasIssues === false) return repo + ' 关闭了 Issues —— 主理鱼只认 issue / PR,这里不会有任何条目可接。'
1634
+ if (access.fork === true && access.parent && access.hasIssues !== true) {
1635
+ return repo + ' 是 ' + String(access.parent) + ' 的 fork。fork 默认不带 Issues,issue 大多落在上游 —— 确认你要守的是哪一个。'
1636
+ }
1637
+ return ''
1638
+ }
1639
+
1640
+ /** 人话字节数:客户看的是"3.2 MB",不是 3355443。 */
1641
+ function bytesText(n) {
1642
+ const value = Number(n) || 0
1643
+ if (value < 1024) return value + ' B'
1644
+ if (value < 1024 * 1024) return (value / 1024).toFixed(1) + ' KB'
1645
+ if (value < 1024 * 1024 * 1024) return (value / 1024 / 1024).toFixed(1) + ' MB'
1646
+ return (value / 1024 / 1024 / 1024).toFixed(2) + ' GB'
1647
+ }
1648
+
1649
+ // 官方 settings-kit.tsx 的 Field:label + hint(InfoTip) + 控件 + note(small)。
1650
+ // 我们之前只有 label,说明只能塞进 placeholder —— 用户看不到「这个字段到底什么意思」。
1651
+ function field(label, control, hint, note) {
1652
+ return h('label', { className: 'dt-field', key: label },
1653
+ h('span', { className: 'dt-field-head' }, label, hint ? h(InfoTip, { text: hint }) : null),
1654
+ control,
1655
+ note ? h('small', null, note) : null)
1656
+ }
1657
+
1658
+ return h('div', { className: 'dt-page' },
1659
+ h('div', { className: 'dt-page-head' },
1660
+ h('div', null,
1661
+ h('h1', { className: 'dt-page-title' }, '主理鱼'),
1662
+ h('span', { className: 'dt-hint' },
1663
+ (body.sessionTitle ? '会话:' + body.sessionTitle + ' · ' : '')
1664
+ + (sessionId ? '盯办 + 主动办:仓库有动静就叫醒本会话' : '需要会话上下文'))),
1665
+ h('div', { className: 'dt-toolbar' },
1666
+ h(Input, { value: search, placeholder: '搜索仓库 / 编号 / 标题', onChange: (e) => setSearch(e.target.value), 'aria-label': '搜索' }),
1667
+ h(Btn, { size: 'sm', variant: 'ghost', icon: h(Icon, { name: 'question' }), onClick: () => setGlossary(true) }, '术语'),
1668
+ h(Btn, { size: 'sm', icon: h(Icon, { name: 'refresh' }), onClick: () => load() }, '刷新'),
1669
+ watchers.length > 0 ? h(Btn, { size: 'sm', onClick: () => actBulk('pause') }, '全部暂停') : null,
1670
+ watchers.length > 0 ? h(Btn, { size: 'sm', onClick: () => actBulk('resume') }, '全部恢复') : null)),
1671
+ h(SegTabs, {
1672
+ items: [
1673
+ { value: 'overview', label: '总览' },
1674
+ { value: 'judge', label: '判定' },
1675
+ { value: 'trigger', label: '触发' },
1676
+ { value: 'settings', label: '设置' },
1677
+ ],
1678
+ value: tab, onChange: setTab, label: '主理鱼分区',
1679
+ }),
1680
+ notice ? h('div', { className: 'dt-banner dt-danger' }, notice.text) : null,
1681
+ // 有新版本时在顶部提示一次(埋在设置页里客户不会主动翻)
1682
+ update && update.hasUpdate
1683
+ ? h('div', { className: 'dt-banner dt-banner-actions' },
1684
+ h('span', { className: 'dt-banner-label' }, '有新版本 ' + update.latest + '(当前 ' + update.current + ')'),
1685
+ h('a', { className: 'dt-btn dt-btn-sm dt-btn-outline', href: '#', onClick: (e) => { e.preventDefault(); setTab('settings') } }, '看升级命令'))
1686
+ : null,
1687
+ toastView,
1688
+ snap.error ? h('div', { className: 'dt-banner dt-danger' }, '读取失败:' + humanizeError(snap.error)) : null,
1689
+ snap.loading && !snap.body ? h(Hint, null, '正在读取…') : null,
1690
+ tab === 'overview' ? overview : null,
1691
+ tab === 'overview' ? repoSummary : null,
1692
+ tab === 'judge' ? judge : null,
1693
+ tab === 'judge' ? timeline : null,
1694
+ tab === 'trigger' ? trigger : null,
1695
+ tab === 'settings' ? settings : null,
1696
+ typeof glossary === 'string' ? h(Modal, {
1697
+ open: true,
1698
+ title: '建议追加到 ' + String(glossary).replace('rules:', '') + ' 的 AGENTS.md',
1699
+ onClose: () => setGlossary(false),
1700
+ },
1701
+ h('p', { className: 'dt-hint' }, '问题通常不是"没叫醒",而是"叫醒了但没动手"。这段规则会明确要求:无论做不做,最后都要 ack。'),
1702
+ h('pre', { className: 'dt-pre' }, AGENTS_SNIPPET),
1703
+ h('div', { className: 'dt-actions' },
1704
+ h(Btn, {
1705
+ size: 'sm',
1706
+ variant: 'primary',
1707
+ onClick: async () => {
1708
+ try {
1709
+ await navigator.clipboard.writeText(AGENTS_SNIPPET)
1710
+ notify('规则已复制,粘贴到 AGENTS.md 末尾即可', 'info')
1711
+ } catch {
1712
+ notify('复制失败:请手动选中上面的文本', 'error')
1713
+ }
1714
+ },
1715
+ }, '复制这段规则'),
1716
+ h(Btn, { size: 'sm', variant: 'ghost', onClick: () => setGlossary(false) }, '关闭'))) : null,
1717
+ h(Modal, { open: glossary === true, title: '主理鱼术语表', onClose: () => setGlossary(false) },
1718
+ h(KeyValues, { rows: [
1719
+ ['主理鱼', '一条「盯办」绑定:某个仓库 → 某个会话'],
1720
+ ['盯', '轮询 issue/PR、按水位去重、冷却期吸收自己的操作'],
1721
+ ['办', '唤醒会话后按仓库 AGENTS.md 主动处理,完成后 watch_ack 打标签'],
1722
+ ['唤醒', '只在会话空闲(idle)时注入一条【主理鱼】消息'],
1723
+ ['过滤', '标签白名单/黑名单、只看已指派、跳过机器人/草稿/已关闭'],
1724
+ ['时段', 'activeHours,比如 09:00-23:00,时段外只攒不唤醒'],
1725
+ ['隔离', 'isolated:每次唤醒开一次性 git worktree,改副本不碰主工作区'],
1726
+ ['ack', '处理完给条目打「主理鱼:已处理」标签,轮询直接跳过'],
1727
+ ['goal', '会话目标(ctx.goals),和 /goal 命令同一份状态'],
1728
+ ['凭证', 'token 存在服务端 secrets.json,面板只显示是否已配置'],
1729
+ ['上限', '两种:单条守每小时最多 6 次、整条会话 12 次(面板里可调);和 GitHub 的限流不是一回事'],
1730
+ ['没有动作', '叫醒后会话没有调用 watch_ack(既没改也没回),连续 2 次就会在「需要关注」里提示'],
1731
+ ['临时副本', '隔离执行开的一次性 git worktree:只在这里改,用完回收,不碰主工作区'],
1732
+ ] })))
1733
+ }
1734
+
1735
+
1736
+ return {
1737
+ inject: ['slots'],
1738
+ apply(ctx) {
1739
+ try { noteOnce('client-version', CLIENT_VERSION) } catch {}
1740
+ try { note('apply', 'start') } catch {}
1741
+
1742
+ // ① the 主理鱼 tab in the centre-column view ring
1743
+ ctx.effect(() => {
1744
+ try {
1745
+ return ctx.slots.inject('conversation.view', () => {
1746
+ const dispose = ctx.slots.register({
1747
+ name: 'conversation.view',
1748
+ id: 'session-superagent-desk',
1749
+ order: 30,
1750
+ label: '主理鱼',
1751
+ }, ZhuliPanel)
1752
+ note('desk-registered', 'ok')
1753
+ return dispose
1754
+ })
1755
+ } catch (error) {
1756
+ note('desk-fail', String((error && error.message) || error))
1757
+ return undefined
1758
+ }
1759
+ })
1760
+
1761
+ // ② the machine-wide orbit in the composer dock row — the same row as
1762
+ // 轮/步 · token 用量 · 上下文环. One ring, one satellite per live
1763
+ // session-level superagent; click opens the per-agent detail list.
1764
+ ctx.effect(() => {
1765
+ try {
1766
+ return ctx.slots.inject('conversation.composer.dock', () => {
1767
+ const dispose = ctx.slots.register({
1768
+ name: 'conversation.composer.dock',
1769
+ id: 'session-superagent-orbit',
1770
+ order: -10, // 最左端:activity/usage 是 0/1,上下文环在槽位之外
1771
+
1772
+ }, StatusOrbit)
1773
+ note('orbit-registered', 'ok')
1774
+ return dispose
1775
+ })
1776
+ } catch (error) {
1777
+ note('orbit-fail', String((error && error.message) || error))
1778
+ return undefined
1779
+ }
1780
+ })
1781
+
1782
+ note('apply', 'done')
1783
+ },
1784
+ }
1785
+ },
1786
+ })