dsh-self-clock 0.0.0-stage → 0.3.10

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/README.md CHANGED
@@ -1,3 +1,158 @@
1
- # Temporary Holding Version
1
+ # 鱼的心跳 · dsh-self-clock
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 一个会自己定闹钟的插件。到点了,它在同一条会话里给自己留一句「到点了」——不是用户消息,不派任务,也不替你安排什么。
4
+
5
+ 内置的 `schedule` 是一张张写好的时刻表;心跳是**会话自己决定**什么时候该醒。想每隔半小时看一眼、想在夜里某个点回头捡起一件事,一句话就够,不用先去写一条 cron。
6
+
7
+ ## 它做的事
8
+
9
+ - **模型自己设**:`heartbeat_set({ inMinutes: 30, label: "把刚才那半段写完" })`,三十分钟后在原会话醒一次,带着你留的那句话。
10
+ - **不是提醒你,是提醒它自己**:投的是一条 `notice`,出现在对话里,不弹窗、不响铃、不冒充你说过话。
11
+ - **会看你在不在**:到点先读会话日志正文,判断你刚说完话没有、我上一条回复多久了。你正说着话,它就不响。
12
+ - **一口气能关**:总开关、频次、时段、每日上限、临时静音,都在设置页里点,不用改文件。
13
+
14
+ ![鱼的心跳设置页](assets/screenshot-1.png)
15
+
16
+ ## 和内置 `schedule` 的区别
17
+
18
+ | | `schedule` | 心跳 |
19
+ | --- | --- | --- |
20
+ | 谁定时间 | 你写在任务里 | 会话自己,随时改 |
21
+ | 提示词 | 写死的 | `label`,一句「上次停在哪」 |
22
+ | 到点不响的理由 | 没有 | 会告诉你是「太近」「在等你」「刚收尾」「不在时段」「预算用完」 |
23
+ | 看你在不在 | 不看 | 看正文,不看到 mtime |
24
+
25
+ ## 什么时候不会响
26
+
27
+ 开关只管「能不能响」;真到点还有五道闸,任何一条不过就安静跳过:
28
+
29
+ - 你上一条消息至少过去 5 分钟——刚说完话不打断
30
+ - 上一条你已经回过了,它没有在等你
31
+ - 它上一条回复也过去 2 分钟了
32
+ - 这条会话 10 分钟内没被叫过——只有半页的书房时间会避让心跳,心跳自己不避让
33
+ - 在时段内、今日预算没用完、没有临时静音
34
+
35
+ 安静 5–20 分钟只说「到点了」;超过 20 分钟,连你留言的那句话一起说。
36
+
37
+ 读不到会话日志(还没落盘、换了目录、文件坏了)时,五道闸一起失效,照时段和预算响——宁可白叫一次,也不漏。
38
+
39
+ ## 装
40
+
41
+ ```bash
42
+ dsh plugin add dsh-self-clock
43
+ ```
44
+
45
+ 或者在 DSH 的「插件市场」里搜「心跳」,点安装。装完在「设置 → 心跳」里能看到面板。
46
+
47
+ ## 说两句
48
+
49
+ 装了就麻烦点个 ⭐(仓库右上角),让我知道有人在用;装不上、用着别扭、想要什么功能,直接在市场评论区留言或开个 issue——都会看到。
50
+
51
+ ## 工具
52
+
53
+ ### `heartbeat_set`
54
+
55
+ 一条会话同时只挂一个闹钟,重复调用覆盖旧的。
56
+
57
+ | 参数 | 说明 |
58
+ | --- | --- |
59
+ | `inMinutes` | N 分钟后响一次(1–1440) |
60
+ | `everyMinutes` | 每隔 N 分钟响一次(5–1440) |
61
+ | `cron` | 五个字段:分 时 日 月 周,支持 `*`、`a`、`a,b`、`a-b`、`*/n`,例如 `30 7 * * *` |
62
+ | `label` | 唤醒时提示自己「上次停在哪」的一句话,不超过 80 字 |
63
+
64
+ 三个时间参数只能给一个。返回里的 `nextAtLocal` / `statusText` / `window` 说明什么时候响、以及为什么没响。子会话拒绝设置。
65
+
66
+ ### `heartbeat_config`
67
+
68
+ 改这条会话的设置,只传要改的字段:`enabled`、`everyMinutes`、`windowStart` / `windowEnd`(0–23 小时,`start > end` 表示跨夜)、`dailyBudget`、`muteMinutes`。
69
+
70
+ ### `heartbeat_mute`
71
+
72
+ 临时静音,默认 30 分钟。期间不响、不消耗预算,到点自动恢复。
73
+
74
+ ### `heartbeat_list`
75
+
76
+ 看所有闹钟和「为什么没响」:`等待中 · 下次 09:30`、`已关闭(总开关)`、`不在时段(23:00–06:00,跨夜)`、`今日预算用完(48/48)`、`临时静音中 · 09:52 恢复`、`距上条消息太近(3 分钟)`、`⚠ 未排到下次触发`。
77
+
78
+ ### `heartbeat_cancel`
79
+
80
+ 取消本会话的闹钟,没有也算成功。
81
+
82
+ ### `presence`
83
+
84
+ 读会话日志**正文**,回答「他本人最后说话是什么时候、走的哪条通道」。不看 mtime——会话文件每轮都在写(系统注入、插件汇报都算),mtime 永远是新的。
85
+
86
+ | 参数 | 说明 |
87
+ | --- | --- |
88
+ | `sessionId` | 要查的会话;不填就是当前这条 |
89
+ | `maxScan` | 最多往前翻多少条 user 消息,默认 400 |
90
+ | `kinds` | 临时覆盖白名单,例如只看 `["qq"]` |
91
+
92
+ 判据是三道闸,顺序固定:白名单(`ownerSourceKinds`)→ 必须含(`ownerSourceRequire`)→ 排除(`ownerSourceDeny`)。默认白名单是 `["user", "qq"]`,默认排除挡系统注入和定时提醒。
93
+
94
+ 一个坑:落盘的 `user/message` 事件里不带 `source`,来源只活在 `agent/inbox/spliced` 的 `inserted[].source`。所以先建「正文 → 来源」表再对,对不上才当 `user`。
95
+
96
+ ## 设置页
97
+
98
+ DSH 的「设置」里有一节「心跳」:
99
+
100
+ - 顶上一行:现在几点、今天已响几次、几个闹钟;右上角「新建」/「刷新」
101
+ - 一张表:会话 / 状态 / 开关 / 频次 / 上限 / 静音
102
+ - **新建**只列**现在还活着**(有会话开着)且还没闹钟的会话
103
+ - **上限**:每行自己的每日上限,改完立刻写回
104
+ - 表下一段「什么时候才会真叫一声」,就是上面那五道闸
105
+
106
+ ## 落盘
107
+
108
+ `~/.dsh/heartbeat.json`(或 `$DSH_HOME/heartbeat.json`):
109
+
110
+ ```json
111
+ {
112
+ "version": 1,
113
+ "alarms": {
114
+ "<sessionId>": { "mode": "interval", "everyMinutes": 30, "nextAt": 0, "label": "" }
115
+ },
116
+ "usage": { "date": "2026-11-24", "count": 3 }
117
+ }
118
+ ```
119
+
120
+ `alarms` 是按 `sessionId` 的对象 map;`cronParsed` 不落盘(Set 序列化会变成空对象,读回来按 `cron` 重解析)。插件起来时读它,到点的立刻补响一次;卸载时定时器清掉,文件留着。
121
+
122
+ ## 配置(`cordis.patch.yml`)
123
+
124
+ ```yaml
125
+ config:
126
+ windowStart: 0
127
+ windowEnd: 23
128
+ dailyBudget: 48
129
+ chatGraceMinutes: 5
130
+ postReplyGraceMinutes: 2
131
+ ```
132
+
133
+ `chatGraceMinutes` / `postReplyGraceMinutes` 就是「5 分钟」「2 分钟」两个门槛。
134
+
135
+ ## 开发
136
+
137
+ ```bash
138
+ cd "D:/dsh work/plugins/heartbeat"
139
+ ELECTRON_RUN_AS_NODE=1 "D:/deepseek/DeepSeek Harness.exe" --test test/*.test.mjs
140
+ ```
141
+
142
+ `core.test.mjs` 只测时间算法;`plugin.test.mjs` 用临时 `DSH_HOME` + 伪造 ctx 跑真实投递;`acceptance.test.mjs` 是工单验收;`presence.test.mjs` 测三道闸。
143
+
144
+ ## 投递方式
145
+
146
+ 照 DSH 自己的 schedule 运行时:
147
+
148
+ ```js
149
+ const message = createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'heartbeat', form: 'notice', summary } })
150
+ agent.followup(message)
151
+ await ctx.sessions.flush(agent.session)
152
+ ```
153
+
154
+ 会话没活着就 `ctx.sessionController.resolveAgent(sessionId)` 复活。`createUserMessage` 优先从宿主树里 `@deepseek-ai/dsh-llm` 取(profile 里没有这个包),拿不到就用本地等价实现,对象形状一致。
155
+
156
+ ## 许可
157
+
158
+ MIT
Binary file
package/client.js ADDED
@@ -0,0 +1,355 @@
1
+ /**
2
+ * dsh-self-clock — 心跳(Client 半边)
3
+ * 设置页里的一节:看每个会话的闹钟状态,改开关 / 频次 / 临时静音。
4
+ * 数据全部走宿主那两个路由,不另做后端:
5
+ * GET /dsh-heartbeat.json 现在的状态
6
+ * POST /dsh-heartbeat/config { sessionId, enabled?, everyMinutes?, muteMinutes? }
7
+ */
8
+ // 下面的 id 必须等于 package.json 的 name(DSH 按入口名判重)
9
+ window.__ModuleLoader__.load({
10
+ id: 'dsh-self-clock',
11
+ factory(require) {
12
+ const React = require('react')
13
+ const h = React.createElement
14
+ const { useState, useEffect, useCallback } = React
15
+
16
+ // 浅色,跟 DSH 主界面一致
17
+ const C = {
18
+ text: 'var(--dsw-alias-label-primary, #1f2329)',
19
+ dim: 'var(--dsw-alias-label-tertiary, #8a9099)',
20
+ line: 'var(--dsw-alias-border-secondary, #e6e8eb)',
21
+ card: 'var(--dsw-alias-bg-secondary, #fff)',
22
+ bg: 'var(--dsw-alias-bg-primary, #f7f8fa)',
23
+ accent: '#2f6fed',
24
+ warn: '#c25e00',
25
+ }
26
+
27
+ const S = {
28
+ wrap: { height: '100%', overflow: 'auto', padding: '14px 16px 28px', background: C.bg, color: C.text, fontSize: 13 },
29
+ card: { background: C.card, border: '1px solid ' + C.line, borderRadius: 10, padding: '12px 14px', marginBottom: 12 },
30
+ head: { display: 'flex', alignItems: 'baseline', gap: 10, flexWrap: 'wrap', marginBottom: 10 },
31
+ title: { fontSize: 15, fontWeight: 600 },
32
+ dim: { color: C.dim, fontSize: 12 },
33
+ row: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
34
+ table: { width: '100%', tableLayout: 'fixed', borderCollapse: 'collapse', fontSize: 12 },
35
+ th: { textAlign: 'left', color: C.dim, fontWeight: 500, padding: '6px 6px', borderBottom: '1px solid ' + C.line, whiteSpace: 'nowrap' },
36
+ td: { padding: '7px 6px', borderBottom: '1px solid ' + C.line, verticalAlign: 'middle' },
37
+ sel: { fontSize: 12, padding: '2px 4px', borderRadius: 6, border: '1px solid ' + C.line, background: C.card, color: C.text },
38
+ btn: { fontSize: 12, padding: '3px 9px', borderRadius: 6, border: '1px solid ' + C.line, background: C.card, color: C.text, cursor: 'pointer' },
39
+ btnOn: { fontSize: 12, padding: '3px 9px', borderRadius: 6, border: '1px solid ' + C.accent, background: C.accent, color: '#fff', cursor: 'pointer' },
40
+ chip: { display: 'inline-block', padding: '1px 7px', borderRadius: 999, fontSize: 11, border: '1px solid ' + C.line, color: C.dim },
41
+ }
42
+
43
+ const FREQS = [15, 30, 60, 120]
44
+
45
+ // settings.section 是 root scope,注册时拿不到 sessionId;
46
+ // 借一个 scope:session 的槽位把它记下来(见下面 apply 里的 session-probe)
47
+ let lastSessionId = ''
48
+
49
+ function shortId(id) {
50
+ const s = String(id || '')
51
+ return s.length > 16 ? s.slice(0, 8) + '…' + s.slice(-4) : s
52
+ }
53
+
54
+ function nameOf(a) {
55
+ return (a && a.label) || ('会话 ' + shortId(a && a.sessionId))
56
+ }
57
+
58
+ function statusStyle(code) {
59
+ if (code === 'waiting') return { color: C.accent, borderColor: C.accent }
60
+ if (code === 'disabled') return { color: C.dim }
61
+ if (code === 'muted') return { color: C.warn, borderColor: C.warn }
62
+ if (code === 'budget' || code === 'window') return { color: C.warn }
63
+ if (code === 'none') return { color: C.warn, borderColor: C.warn }
64
+ return {}
65
+ }
66
+
67
+ function nextText(a) {
68
+ if (!a) return ''
69
+ if (a.nextAtLocal) return a.nextAtLocal
70
+ return String(a.statusText || '').indexOf('未排到') >= 0 ? '⚠ 未排到下次触发' : '—'
71
+ }
72
+
73
+ function Panel() {
74
+ const [data, setData] = useState(null)
75
+ const [error, setError] = useState('')
76
+ const [busy, setBusy] = useState('')
77
+ const [creating, setCreating] = useState(false)
78
+ const [newSid, setNewSid] = useState('')
79
+ const [newFreq, setNewFreq] = useState(30)
80
+ const [newBudget, setNewBudget] = useState(48)
81
+ const [pendingDel, setPendingDel] = useState('')
82
+
83
+ const load = useCallback(async () => {
84
+ try {
85
+ const res = await fetch('/dsh-heartbeat.json', { cache: 'no-store' })
86
+ const j = await res.json()
87
+ setData(j)
88
+ setError('')
89
+ } catch (e) {
90
+ setError(String((e && e.message) || e))
91
+ }
92
+ }, [])
93
+
94
+ useEffect(() => {
95
+ load()
96
+ const timer = setInterval(load, 30000)
97
+ return () => clearInterval(timer)
98
+ }, [load])
99
+
100
+ const post = async (sessionId, patch, key) => {
101
+ setBusy(key)
102
+ try {
103
+ await fetch('/dsh-heartbeat/config', {
104
+ method: 'POST',
105
+ headers: { 'content-type': 'application/json' },
106
+ body: JSON.stringify({ sessionId, ...patch }),
107
+ })
108
+ await load()
109
+ } catch (e) {
110
+ setError(String((e && e.message) || e))
111
+ } finally {
112
+ setBusy('')
113
+ }
114
+ }
115
+
116
+ const alarms = (data && Array.isArray(data.alarms)) ? data.alarms.slice() : []
117
+ const mine = lastSessionId ? alarms.find((a) => a.sessionId === lastSessionId) : null
118
+ // 本会话那条排最前;其余按「下次要响」升序,已关掉 / 排不出的放后面
119
+ const rank = (a) => {
120
+ if (mine && a.sessionId === mine.sessionId) return -1
121
+ return a.nextAt ? Date.parse(a.nextAt) : Infinity
122
+ }
123
+ alarms.sort((a, b) => {
124
+ const ra = rank(a)
125
+ const rb = rank(b)
126
+ if (ra !== rb) return ra - rb
127
+ return String(nameOf(a)).localeCompare(String(nameOf(b)))
128
+ })
129
+
130
+ const nowLocal = (data && data.nowLocal) || '—'
131
+ const used = data ? Number(data.used || 0) : 0
132
+
133
+ const summary = h('div', { style: S.head },
134
+ h('div', { style: S.title }, '现在 ' + String(nowLocal).slice(11)),
135
+ h('div', { style: S.dim }, '今天已响 ' + used + ' 次' + (alarms.length ? '|' + alarms.length + ' 个闹钟' : '')),
136
+ mine ? h('div', { style: { ...S.chip, color: C.accent, borderColor: C.accent } }, '本会话:' + (mine.title || nameOf(mine))) : null,
137
+ h('div', { style: { flex: 1 } }),
138
+ h('button', { style: S.btnOn, onClick: () => setCreating((v) => !v) }, creating ? '收起' : '新建'),
139
+ h('button', { style: S.btn, onClick: load }, '刷新'),
140
+ )
141
+
142
+ const sessions = (data && Array.isArray(data.sessions)) ? data.sessions : []
143
+ const takenSids = new Set(alarms.map((a) => a.sessionId))
144
+ const freeSessions = sessions.filter((s) => !takenSids.has(s.id))
145
+ const sessionLabel = (s) => (s.title ? s.title : '会话 ' + shortId(s.id)) + (s.atLocal ? ' · ' + s.atLocal : '')
146
+
147
+ const createCard = creating
148
+ ? h('div', { style: S.card },
149
+ h('div', { style: { fontWeight: 600, marginBottom: 8 } }, '给一条会话开一个闹钟'),
150
+ h('div', { style: S.row },
151
+ h('select', {
152
+ style: { ...S.sel, maxWidth: 380 },
153
+ value: newSid,
154
+ onChange: (e) => setNewSid(e.target.value),
155
+ },
156
+ h('option', { value: '' }, freeSessions.length ? '选一条活着的会话…' : '现在没有活着的会话'),
157
+ freeSessions.map((s) => h('option', { key: s.id, value: s.id }, sessionLabel(s))),
158
+ ),
159
+ h('select', {
160
+ style: S.sel,
161
+ value: String(newFreq),
162
+ onChange: (e) => setNewFreq(Number(e.target.value)),
163
+ }, FREQS.map((m) => h('option', { key: m, value: String(m) }, '每 ' + m + ' 分'))),
164
+ h('div', { style: S.dim }, '每日上限'),
165
+ h('input', {
166
+ style: { ...S.sel, width: 58 },
167
+ type: 'number', min: 1, max: 999,
168
+ value: newBudget,
169
+ onChange: (e) => setNewBudget(Number(e.target.value) || 48),
170
+ }),
171
+ h('button', {
172
+ style: S.btnOn,
173
+ disabled: !newSid || busy === 'new',
174
+ onClick: async () => {
175
+ if (!newSid) return
176
+ await post(newSid, { enabled: true, everyMinutes: newFreq, dailyBudget: newBudget }, 'new')
177
+ setNewSid('')
178
+ setCreating(false)
179
+ },
180
+ }, '建'),
181
+ h('button', { style: S.btn, onClick: () => setCreating(false) }, '取消'),
182
+ ),
183
+ h('div', { style: { ...S.dim, marginTop: 6 } }, '建完就是一个「每 N 分钟叫一次」的闹钟,之后在表里改开关 / 频次 / 上限。'),
184
+ )
185
+ : null
186
+
187
+ const notice = error
188
+ ? h('div', { style: { ...S.card, borderColor: '#e8b4b4', color: '#b23b3b' } }, '读不到心跳状态:' + error)
189
+ : null
190
+
191
+ if (!data) {
192
+ return h('div', { style: S.wrap }, summary, notice, h('div', { style: S.dim }, '正在读…'))
193
+ }
194
+
195
+ if (!alarms.length) {
196
+ return h('div', { style: S.wrap }, summary, notice, createCard,
197
+ h('div', { style: S.card },
198
+ h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '还没有闹钟'),
199
+ h('div', { style: S.dim }, '点右上角「新建」挑一条会话——这里只列现在还活着的(有会话开着)那条;也可以在会话里让我设一个(比如「三十分钟后提醒我」)。'),
200
+ ),
201
+ )
202
+ }
203
+
204
+ const rows = alarms.map((a, i) => {
205
+ const key = a.sessionId + ':' + i
206
+ const isMine = !!mine && a.sessionId === mine.sessionId
207
+ const isNext = !mine && i === 0 && !!a.nextAt
208
+ const freq = Number(a.everyMinutes || 0)
209
+ const freqOptions = FREQS.slice()
210
+ if (freq && freqOptions.indexOf(freq) < 0) freqOptions.push(freq)
211
+ freqOptions.sort((x, y) => x - y)
212
+
213
+ return h('tr', { key, style: (isMine || isNext) ? { background: 'rgba(47,111,237,0.06)' } : null },
214
+ h('td', { style: { ...S.td, maxWidth: 0 } },
215
+ h('div', {
216
+ style: {
217
+ fontWeight: (isMine || isNext) ? 600 : 500,
218
+ overflow: 'hidden',
219
+ textOverflow: 'ellipsis',
220
+ whiteSpace: 'nowrap',
221
+ },
222
+ title: a.title || a.label || a.sessionId,
223
+ }, a.title || ('会话 ' + shortId(a.sessionId))),
224
+ a.nextAtLocal
225
+ ? h('div', { style: { fontSize: 11, opacity: 0.6, marginTop: 2, whiteSpace: 'nowrap' } }, '下次 ' + String(a.nextAtLocal).slice(11))
226
+ : null,
227
+ ),
228
+ h('td', { style: S.td },
229
+ h('span', { style: { ...S.chip, ...statusStyle(a.status) } },
230
+ String(a.statusText || a.status || '—').split('·')[0].trim()),
231
+ ),
232
+ h('td', { style: S.td },
233
+ h('input', {
234
+ type: 'checkbox',
235
+ checked: a.enabled !== false,
236
+ disabled: busy === key,
237
+ onChange: (e) => post(a.sessionId, { enabled: e.target.checked }, key),
238
+ }),
239
+ ),
240
+ h('td', { style: S.td },
241
+ h('select', {
242
+ style: { ...S.sel, width: '100%', padding: '1px 2px' },
243
+ value: String(freq || 30),
244
+ disabled: busy === key,
245
+ onChange: (e) => post(a.sessionId, { everyMinutes: Number(e.target.value) }, key),
246
+ }, freqOptions.map((m) => h('option', { key: m, value: String(m) }, m + ' 分'))),
247
+ ),
248
+ h('td', { style: S.td },
249
+ h('input', {
250
+ type: 'number', min: 1, max: 999,
251
+ style: { ...S.sel, width: '100%', maxWidth: 54, padding: '2px 2px' },
252
+ defaultValue: a.dailyBudget || 48,
253
+ disabled: busy === key,
254
+ onBlur: (e) => post(a.sessionId, { dailyBudget: Number(e.target.value) || 48 }, key),
255
+ }),
256
+ ),
257
+ h('td', { style: S.td },
258
+ h('button', {
259
+ style: { ...S.btn, padding: '2px 4px', fontSize: 11 },
260
+ disabled: busy === key,
261
+ title: '静音 30 分钟,不响也不消耗预算',
262
+ onClick: () => post(a.sessionId, { muteMinutes: 30 }, key),
263
+ }, '静音'),
264
+ ),
265
+ h('td', { style: S.td },
266
+ h('button', {
267
+ style: pendingDel === a.sessionId
268
+ ? { ...S.btn, padding: '2px 6px', background: C.dangerBg || '#fde8e8', borderColor: C.dangerBg || '#f4c2c2', color: '#b42318' }
269
+ : { ...S.btn, padding: '2px 6px' },
270
+ disabled: busy === key,
271
+ title: '删掉这条会话的闹钟(再点一次确认)',
272
+ onClick: () => {
273
+ if (pendingDel !== a.sessionId) {
274
+ setPendingDel(a.sessionId)
275
+ window.setTimeout(() => setPendingDel((cur) => (cur === a.sessionId ? '' : cur)), 5000)
276
+ return
277
+ }
278
+ setPendingDel('')
279
+ post(a.sessionId, { remove: true }, key)
280
+ },
281
+ }, pendingDel === a.sessionId ? '确定' : '删'),
282
+ ),
283
+ )
284
+ })
285
+
286
+ return h('div', { style: S.wrap },
287
+ summary,
288
+ notice,
289
+ createCard,
290
+ h('div', { style: S.card },
291
+ h('table', { style: S.table },
292
+ h('thead', null,
293
+ h('tr', null,
294
+ h('th', { style: { ...S.th, width: '30%' } }, '会话'),
295
+ h('th', { style: { ...S.th, width: '17%' } }, '状态'),
296
+ h('th', { style: { ...S.th, width: '8%' } }, '开关'),
297
+ h('th', { style: { ...S.th, width: '16%' } }, '频次'),
298
+ h('th', { style: { ...S.th, width: '10%' } }, '上限'),
299
+ h('th', { style: { ...S.th, width: '10%' } }, '静音'),
300
+ h('th', { style: { ...S.th, width: '9%' } }, '删'),
301
+ ),
302
+ ),
303
+ h('tbody', null, rows),
304
+ ),
305
+ h('div', { style: { marginTop: 10, paddingTop: 10, borderTop: '1px solid ' + C.line } },
306
+ h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '什么时候才会真叫一声'),
307
+ h('div', { style: S.dim }, '上面这些开关只管「能不能响」;真到点的时候还有五道闸,任何一条不过就安静跳过:'),
308
+ h('ul', { style: { ...S.dim, margin: '6px 0 0', paddingLeft: 18, lineHeight: 1.7 } },
309
+ h('li', null, '你上一条消息至少过去 5 分钟——刚说完话不打断'),
310
+ h('li', null, '上一条你已经回过了,我没有在等你'),
311
+ h('li', null, '我上一条回复也过去 2 分钟了'),
312
+ h('li', null, '这条会话 10 分钟内没被叫过——只有半页的书房时间会避让心跳,心跳自己不避让'),
313
+ h('li', null, '在时段内、今日预算没用完、没有临时静音'),
314
+ ),
315
+ h('div', { style: { ...S.dim, marginTop: 6 } },
316
+ '安静 5–20 分钟:只说「到点了」;超过 20 分钟:连你留言的那句话一起说。'),
317
+ h('div', { style: { ...S.dim, marginTop: 4 } },
318
+ '上面五道闸靠读会话日志判断;万一读不到(日志没落盘、换了目录、文件坏了),五道闸一起失效,照时段和预算响——宁可白叫一次,也不漏。'),
319
+ ),
320
+ ),
321
+ h('div', { style: { ...S.dim, marginTop: 2 } }, mine ? '「本会话」那条排最前并高亮。改完立刻写回,宿主那边是同一份状态。' : '下次要响的那条高亮。改完立刻写回,宿主那边是同一份状态。'),
322
+ )
323
+ }
324
+
325
+ function Boundary(props) {
326
+ try {
327
+ return h(Panel, props)
328
+ } catch (e) {
329
+ return h('div', { style: { padding: 14, color: '#b23b3b', fontSize: 12 } }, '心跳面板出错了:' + String((e && e.message) || e))
330
+ }
331
+ }
332
+
333
+ return {
334
+ inject: ['slots'],
335
+ apply(ctx) {
336
+ const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
337
+ if (!slots) return
338
+ // 探针:scope:session 的槽位能拿到 sessionId,记下最后看过的那个会话
339
+ slots.inject('conversation.chat.assistant-actions', () => slots.register({
340
+ name: 'conversation.chat.assistant-actions',
341
+ id: 'dsh-self-clock/session-probe',
342
+ order: 999,
343
+ inject: (sessionId) => {
344
+ if (typeof sessionId === 'string' && sessionId !== '') lastSessionId = sessionId
345
+ return {}
346
+ },
347
+ }, () => null))
348
+ slots.inject('settings.section', () => slots.register(
349
+ { name: 'settings.section', id: 'dsh-self-clock', order: 68, label: '鱼的心跳' },
350
+ () => h(Boundary),
351
+ ))
352
+ },
353
+ }
354
+ },
355
+ })
@@ -0,0 +1,9 @@
1
+ - insert:
2
+ - id: dsh-self-clock
3
+ name: dsh-self-clock
4
+ config:
5
+ windowStart: 0
6
+ windowEnd: 23
7
+ dailyBudget: 48
8
+ chatGraceMinutes: 5
9
+ postReplyGraceMinutes: 2
package/icon.svg ADDED
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" width="40" height="40" fill="none">
2
+ <rect x="1.5" y="1.5" width="37" height="37" rx="10" fill="#1d2f45"/>
3
+ <circle cx="20" cy="16.5" r="9.2" stroke="#7fd1ff" stroke-width="1.7"/>
4
+ <path d="M20 10.6v6.1l4.1 2.6" stroke="#e6f4ff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <circle cx="20" cy="16.5" r="1.3" fill="#e6f4ff"/>
6
+ <path d="M8.6 31.6h5.1l1.7-3 2.1 6 2.7-9.2 2.1 6.2 1.4-2.5h4.7" stroke="#ff8fa3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
7
+ </svg>