@wastee/dsh-goal-record-board 0.0.0-stage → 1.0.2

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,56 @@
1
- # Temporary Holding Version
1
+ # 目标记录看板
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
+ ## 安装
6
+
7
+ 包名:`@wastee/dsh-goal-record-board`
8
+
9
+ 要求 DSH 版本在 `>=0.2.0 <0.3.0` 范围内。
10
+
11
+ ### 方式一:图形界面(推荐)
12
+
13
+ 1. 打开 DSH,进入左侧栏底部的**插件**。
14
+ 2. 点击**添加插件**,选择**安装第三方插件**。
15
+ 3. 在**包名或地址**里填入 `@wastee/dsh-goal-record-board`;安装包默认从**默认安装源**(npm 官方源)下载,需要时可在**安装源**里切换成其他源。
16
+ 4. 点击**安装**,在**安装插件**确认框里核对包名后确认。
17
+ 5. 装好后,在同一页的**已安装**里找到"目标记录看板",打开开关启用。若提示需要重启,按提示重启 DSH。
18
+
19
+ > 只在插件页看到安装入口还不够,记得启用插件并新开一个会话,入口才会出现。
20
+
21
+ ### 方式二:命令行
22
+
23
+ ```sh
24
+ dsh plugin add @wastee/dsh-goal-record-board
25
+ ```
26
+
27
+ 装完后在**插件**页启用;如果当前 profile 是新初始化的,按提示重启 DSH。
28
+
29
+ ## 用法
30
+
31
+ 1. 当前会话有目标时,会话标题栏会出现一个清单图标的按钮,鼠标悬停时显示"目标记录看板"。点击后在右侧栏打开"目标记录看板"页签;没有目标的会话不显示这个按钮。
32
+ 2. 打开看板后,先显示第一批记录:取最近的若干整轮,累计不少于 10 条记录;同一轮的记录不拆开,所以这一批可能略多于 10 条,某一轮记录特别多时列表也会跟着变长。总共不足 10 条时全部显示。顶部一行条数:部分显示时写"已显示 X / N 条记录 · M 轮",全部显示后写"N 条记录 · M 轮"。轮数按不同的轮次号统计;轮次未知的记录只计入条数,不计入轮数。条数行的数字变化会被屏幕阅读器读出来。
33
+ 3. 记录按轮次分组,最新的一轮排在最上面。组标题写"第 N 轮";这一轮最新的记录不在今天时,组标题右侧再补上日期(月-日)。
34
+ 4. 每条记录默认折叠成一行,从左到右是时间和这条记录的问题摘要。摘要取问题一段的内容,把换行压成空格,太长时在末尾省略;问题为空时改显示成果的摘要。
35
+ 5. 点击一行,在这行下方直接显示问题、方案、成果三段全文,长文字不截断,也不需要再点第二次;再点一次同一行收起。
36
+ 6. 焦点在展开的记录里时,按 Esc 收起这条记录,焦点回到这一行的按钮上。
37
+ 7. 还有更早的记录时,列表末尾显示"加载更多"按钮,跟着列表一起滚动。点一次继续显示后面的整轮,每次新增至少 10 条,剩下的不足 10 条时一次显示完;已经展开的行保持展开,焦点落到新出现的第一行。"加载更多"可以用 Tab 选中,按 Enter 或空格触发。
38
+ 8. 全部记录显示完后,"加载更多"按钮消失,列表末尾显示"没有更早的记录了"。如果第一批就包含全部记录,不显示按钮,也不显示这条提示。
39
+ 9. 看板在页签内部自己滚动。记录多时,先显示最近几轮,点"加载更多"继续往前看,可以一直翻到最早一轮;最底部的记录能完整看到;滚动时当前这一轮的组标题固定在顶部。
40
+ 10. 看板开着时新产生的记录会出现在最上面,并短暂高亮一次;条数行跟着更新,已经看到的更早记录不会被挤掉。
41
+ 11. 切到别的页签再回来,或关掉再打开看板,会重新从第一批开始显示。
42
+ 12. 没有记录时,看板显示空状态提示,不显示条数行,也没有"加载更多"按钮和"没有更早的记录了"提示。
43
+
44
+ ## 数据从哪来
45
+
46
+ 记录来自模型在每轮结束时调用的 `goal_record` 工具。这个工具调用的三个字段(问题、方案、成果)会被会话日志持久保存;看板从日志中派生出列表,不写入第二份存储。因此刷新、分叉或重放会话后,记录仍然可以从日志重建。记录列表仍然一次发给浏览器,分批显示只影响页面上画多少行,不改日志、投影格式和 `goal_record` 工具。
47
+
48
+ 只有三个字段都非空、且目标处于活动状态的轮次才会出现在看板上。
49
+
50
+ ## 关闭插件后
51
+
52
+ 关闭插件不会删除任何日志记录。看板页签、标题栏按钮和 `goal_record` 工具会一并消失;重新启用后,过去的记录会从日志重新显示出来。
53
+
54
+ ## 字体与图标
55
+
56
+ 界面继承 DSH 的主题变量,不打包任何字体文件。插件图标为原创图形。
package/client.js ADDED
@@ -0,0 +1,606 @@
1
+ /**
2
+ * Goal record board — Client half.
3
+ *
4
+ * Entry: a checklist button in the session header's action area opens a
5
+ * right-sidebar tab.
6
+ * The tab body reads the goalRecordBoard projection, the per-session list
7
+ * published by the Host projection. Records are grouped by turn, newest first;
8
+ * each row is collapsed to a one-line problem summary and opens a drawer with
9
+ * the full problem, solution and result.
10
+ */
11
+ window.__ModuleLoader__.load({
12
+ id: '@wastee/dsh-goal-record-board',
13
+ factory(require) {
14
+ const React = require('react')
15
+ const h = React.createElement
16
+
17
+ const TAB_ID = '@wastee/dsh-goal-record-board'
18
+ const TAB_KIND = 'goal-record-board'
19
+ const NS = 'goalRecordBoard'
20
+ /** Stable empty list for renders without a projection. */
21
+ const NO_RECORDS = []
22
+ /** Target record count for the first batch and for each "load more" click. */
23
+ const RECORDS_PER_PAGE = 10
24
+
25
+ const zh = {
26
+ menu: '目标记录看板',
27
+ title: '目标记录看板',
28
+ empty: '还没有记录',
29
+ emptyHint: '目标每轮结束后,遇到的问题、采用的方案和取得的成果会记录在这里。',
30
+ guide: '每轮的什么问题、什么方案、什么成果',
31
+ problem: '问题',
32
+ solution: '方案',
33
+ result: '成果',
34
+ roundHeader: '第 {n} 轮',
35
+ unknownRound: '轮次未知',
36
+ countLine: '{n} 条记录 · {m} 轮',
37
+ countLinePartial: '已显示 {r} / {n} 条记录 · {m} 轮',
38
+ loadMore: '加载更多',
39
+ endOfList: '没有更早的记录了',
40
+ }
41
+ const en = {
42
+ menu: 'Goal Record Board',
43
+ title: 'Goal Record Board',
44
+ empty: 'No records yet',
45
+ emptyHint: 'When a goal finishes each round, the problem, solution and result it produced are recorded here.',
46
+ guide: 'Problem, solution and result for each round',
47
+ problem: 'Problem',
48
+ solution: 'Solution',
49
+ result: 'Result',
50
+ roundHeader: 'Round {n}',
51
+ unknownRound: 'Unknown round',
52
+ countLine: '{n} records · {m} rounds',
53
+ countLinePartial: 'Showing {r} of {n} records · {m} rounds',
54
+ loadMore: 'Load more',
55
+ endOfList: 'No earlier records',
56
+ }
57
+ const dicts = { zh, en, ja: en, es: en, fr: en, de: en, ru: en, pt: en }
58
+
59
+ /** Build a translator that reads the active language at call time. */
60
+ function makeT(locale) {
61
+ if (locale === undefined || typeof locale.bind !== 'function') {
62
+ return key => (zh[key] ?? en[key] ?? key)
63
+ }
64
+ const t = locale.bind(NS)
65
+ return key => {
66
+ const value = t(key)
67
+ return typeof value === 'string' && value !== '' ? value : (zh[key] ?? key)
68
+ }
69
+ }
70
+
71
+ function useT(ctx) {
72
+ return makeT(ctx.get('locale'))
73
+ }
74
+
75
+ /** Two-digit zero padding for the clock and date parts. */
76
+ function pad2(value) {
77
+ return String(value).padStart(2, '0')
78
+ }
79
+
80
+ /** Local-zone day key (year-month-day): equal keys mean the same day. */
81
+ function dayKey(ms) {
82
+ if (typeof ms !== 'number' || !isFinite(ms)) return ''
83
+ const d = new Date(ms)
84
+ return d.getFullYear() + '-' + pad2(d.getMonth() + 1) + '-' + pad2(d.getDate())
85
+ }
86
+
87
+ /** HH:mm in the browser's local zone, or an empty string for a non-finite timestamp. */
88
+ function formatClock(ms) {
89
+ if (typeof ms !== 'number' || !isFinite(ms)) return ''
90
+ const d = new Date(ms)
91
+ return pad2(d.getHours()) + ':' + pad2(d.getMinutes())
92
+ }
93
+
94
+ /** MM-DD in the browser's local zone, or an empty string for a non-finite timestamp. */
95
+ function formatDate(ms) {
96
+ if (typeof ms !== 'number' || !isFinite(ms)) return ''
97
+ const d = new Date(ms)
98
+ return pad2(d.getMonth() + 1) + '-' + pad2(d.getDate())
99
+ }
100
+
101
+ /**
102
+ * Group the oldest-first projection into newest-first turn groups: reverse
103
+ * the array, then keep adjacent records with the same turn together, so a
104
+ * group is newest first as well.
105
+ */
106
+ function groupByTurn(records) {
107
+ const groups = []
108
+ for (let index = records.length - 1; index >= 0; index -= 1) {
109
+ const record = records[index]
110
+ const group = groups[groups.length - 1]
111
+ if (group !== undefined && group.turn === record.turn) {
112
+ group.records.push(record)
113
+ } else {
114
+ groups.push({ turn: record.turn, records: [record] })
115
+ }
116
+ }
117
+ return groups
118
+ }
119
+
120
+ /**
121
+ * Whole groups from index `start` onward until at least `minimum` records
122
+ * are covered. A turn is never split across batches; running out of groups
123
+ * returns whatever is left.
124
+ */
125
+ function takeBatch(groups, start, minimum) {
126
+ const batch = []
127
+ let total = 0
128
+ for (let index = start; index < groups.length && total < minimum; index += 1) {
129
+ const group = groups[index]
130
+ batch.push(group)
131
+ total += group.records.length
132
+ }
133
+ return batch
134
+ }
135
+
136
+ /**
137
+ * Newest-first groups up to and including the group that holds `pivotId`;
138
+ * null when that record is gone and the caller must fall back to the first
139
+ * batch.
140
+ */
141
+ function groupsThroughPivot(groups, pivotId) {
142
+ if (typeof pivotId !== 'string') return null
143
+ for (let index = 0; index < groups.length; index += 1) {
144
+ if (groups[index].records.some(record => record.id === pivotId)) {
145
+ return groups.slice(0, index + 1)
146
+ }
147
+ }
148
+ return null
149
+ }
150
+
151
+ /** Total records across a list of turn groups. */
152
+ function sumRecords(groups) {
153
+ let total = 0
154
+ for (const group of groups) total += group.records.length
155
+ return total
156
+ }
157
+
158
+ /** Id of the oldest record in a newest-first batch: the shown boundary. */
159
+ function lastRecordId(groups) {
160
+ const group = groups[groups.length - 1]
161
+ if (group === undefined) return null
162
+ return group.records[group.records.length - 1].id
163
+ }
164
+
165
+ /** Collapse text to one line: newlines become spaces and outer blanks go away. */
166
+ function singleLine(text) {
167
+ return typeof text === 'string' ? text.replace(/\s*\n\s*/g, ' ').trim() : ''
168
+ }
169
+
170
+ /** Collapsed-row summary: the problem, or the result when the problem is empty. */
171
+ function summarize(record) {
172
+ const problem = singleLine(record.problem)
173
+ return problem !== '' ? problem : singleLine(record.result)
174
+ }
175
+
176
+ /** Total records and distinct turns; turn 0 means unknown and is not counted. */
177
+ function countRecords(records) {
178
+ const turns = new Set()
179
+ for (const record of records) {
180
+ if (record.turn !== 0) turns.add(record.turn)
181
+ }
182
+ return { total: records.length, rounds: turns.size }
183
+ }
184
+
185
+ /** Fill the count-line template with this projection's two numbers. */
186
+ function countText(t, records) {
187
+ const counts = countRecords(records)
188
+ return String(t('countLine'))
189
+ .replace('{n}', String(counts.total))
190
+ .replace('{m}', String(counts.rounds))
191
+ }
192
+
193
+ /** Partial count line: shown records, total records and total rounds. */
194
+ function partialCountText(t, shownRecords, records) {
195
+ const counts = countRecords(records)
196
+ return String(t('countLinePartial'))
197
+ .replace('{r}', String(shownRecords))
198
+ .replace('{n}', String(counts.total))
199
+ .replace('{m}', String(counts.rounds))
200
+ }
201
+
202
+ /** Row clock; a record on another day than its group's newest also shows MM-DD. */
203
+ function rowTime(record, groupDay) {
204
+ const clock = formatClock(record.time)
205
+ if (dayKey(record.time) === groupDay) return clock
206
+ const date = formatDate(record.time)
207
+ if (date === '') return clock
208
+ return clock === '' ? date : date + ' ' + clock
209
+ }
210
+
211
+ function Field(props) {
212
+ const { label, text } = props
213
+ return h('div', { className: 'grb-field' },
214
+ h('div', { className: 'grb-field-label' }, label),
215
+ h('div', { className: 'grb-field-text' }, text),
216
+ )
217
+ }
218
+
219
+ /** Sticky turn heading; the date appears only when the group is not from today. */
220
+ function GroupHead(props) {
221
+ const { turn, dateText, t } = props
222
+ const title = turn === 0
223
+ ? t('unknownRound')
224
+ : String(t('roundHeader')).replace('{n}', String(turn))
225
+ return h('div', { className: 'grb-group-head' },
226
+ h('span', { className: 'grb-group-title' }, title),
227
+ dateText === '' ? null : h('span', { className: 'grb-group-date' }, dateText),
228
+ )
229
+ }
230
+
231
+ function Row(props) {
232
+ const { record, t, timeText, summary, isNew, focusId, onFocusHandled } = props
233
+ const [open, setOpen] = React.useState(false)
234
+ const drawerId = React.useId()
235
+ const headRef = React.useRef(null)
236
+
237
+ // "Load more" moves focus to the first newly shown row. The parent clears
238
+ // focusId right after, so this runs once and later renders leave focus be.
239
+ React.useEffect(() => {
240
+ if (focusId !== record.id) return
241
+ const head = headRef.current
242
+ if (head !== null) head.focus()
243
+ onFocusHandled()
244
+ }, [focusId, record.id, onFocusHandled])
245
+
246
+ // Escape collapses an open row, moves focus back to its button, and stops
247
+ // the event so the host page does not also act on it. A collapsed row
248
+ // leaves Escape alone.
249
+ const handleKeyDown = event => {
250
+ if (event.key !== 'Escape' || !open) return
251
+ event.stopPropagation()
252
+ setOpen(false)
253
+ const head = headRef.current
254
+ if (head !== null) head.focus()
255
+ }
256
+
257
+ return h('div', {
258
+ className: isNew ? 'grb-row grb-row-new' : 'grb-row',
259
+ onKeyDown: handleKeyDown,
260
+ },
261
+ h('button', {
262
+ ref: headRef,
263
+ type: 'button',
264
+ className: 'grb-row-head',
265
+ 'aria-expanded': open,
266
+ 'aria-controls': drawerId,
267
+ onClick: () => { setOpen(value => !value) },
268
+ },
269
+ h('span', { className: 'grb-time' }, timeText),
270
+ h('span', { className: 'grb-summary' }, summary),
271
+ h('svg', {
272
+ className: 'grb-chevron' + (open ? ' grb-chevron-open' : ''),
273
+ width: 14, height: 14, viewBox: '0 0 16 16',
274
+ fill: 'none', stroke: 'currentColor', strokeWidth: 1,
275
+ 'aria-hidden': 'true',
276
+ }, h('path', { d: 'M4 6L7.29289 9.29289C7.68342 9.68342 8.31658 9.68342 8.70711 9.29289L12 6' })),
277
+ ),
278
+ // The drawer stays mounted so aria-controls always points at a real
279
+ // element; hidden keeps it out of layout and the accessibility tree,
280
+ // and removing hidden restarts the opening animation.
281
+ h('div', { className: 'grb-drawer', id: drawerId, hidden: !open },
282
+ h(Field, { label: t('problem'), text: record.problem }),
283
+ h(Field, { label: t('solution'), text: record.solution }),
284
+ h(Field, { label: t('result'), text: record.result }),
285
+ ),
286
+ )
287
+ }
288
+
289
+ function Group(props) {
290
+ const { group, t, todayKey, freshIds, focusId, onFocusHandled } = props
291
+ const newest = group.records[0]
292
+ const newestDay = dayKey(newest.time)
293
+ const dateText = newestDay === todayKey ? '' : formatDate(newest.time)
294
+ return h('div', { className: 'grb-group' },
295
+ h(GroupHead, { turn: group.turn, dateText, t }),
296
+ group.records.map(record => h(Row, {
297
+ key: record.id,
298
+ record,
299
+ t,
300
+ timeText: rowTime(record, newestDay),
301
+ summary: summarize(record),
302
+ isNew: freshIds.has(record.id),
303
+ focusId,
304
+ onFocusHandled,
305
+ })),
306
+ )
307
+ }
308
+
309
+ function EmptyState(props) {
310
+ const t = props.t
311
+ const icon = h('svg', {
312
+ className: 'grb-empty-icon', width: 24, height: 24, viewBox: '0 0 24 24',
313
+ fill: 'none', stroke: 'currentColor', strokeWidth: 1.4,
314
+ 'aria-hidden': 'true',
315
+ },
316
+ h('rect', { x: 3, y: 4, width: 18, height: 16, rx: 2 }),
317
+ h('path', { d: 'M7 9h10M7 13h10M7 17h6' }),
318
+ )
319
+ return h('div', { className: 'grb-empty' },
320
+ icon,
321
+ h('div', { className: 'grb-empty-title' }, t('empty')),
322
+ h('div', { className: 'grb-empty-hint' }, t('emptyHint')),
323
+ )
324
+ }
325
+
326
+ function Board(props) {
327
+ const t = props.t
328
+ const projection = props.useProjection('goalRecordBoard')
329
+ const records = Array.isArray(projection) ? projection : NO_RECORDS
330
+ const seenIds = React.useRef(new Set())
331
+ const hasBaseline = React.useRef(false)
332
+ const timers = React.useRef(new Set())
333
+ const [freshIds, setFreshIds] = React.useState(() => new Set())
334
+ // `pivotId` is the oldest record currently shown; it decides where the
335
+ // visible list ends. `pinned` remembers the first batch once, so records
336
+ // that arrive later only extend the newest end instead of pushing rows
337
+ // the user already read out of view.
338
+ const [pivotId, setPivotId] = React.useState(null)
339
+ const [focusId, setFocusId] = React.useState(null)
340
+ const pinned = React.useRef(null)
341
+ // Stable callback: Row effects depend on it and must not re-run each render.
342
+ const onFocusHandled = React.useCallback(() => { setFocusId(null) }, [])
343
+
344
+ // Mark records that appeared after the baseline; the first defined
345
+ // projection (an empty array included) only records the baseline. A
346
+ // projection that is not an array yet, or stops being one, resets that
347
+ // readiness so records already present when it finally arrives are not
348
+ // flashed. Each batch of new ids clears itself 1.4s later, matching the
349
+ // highlight animation (reduced motion holds it steady for that time).
350
+ React.useEffect(() => {
351
+ if (!Array.isArray(projection)) {
352
+ hasBaseline.current = false
353
+ seenIds.current = new Set()
354
+ return
355
+ }
356
+ const ids = new Set(projection.map(record => record.id))
357
+ const fresh = []
358
+ if (hasBaseline.current) {
359
+ for (const id of ids) {
360
+ if (!seenIds.current.has(id)) fresh.push(id)
361
+ }
362
+ }
363
+ hasBaseline.current = true
364
+ seenIds.current = ids
365
+ if (fresh.length === 0) return
366
+ setFreshIds(previous => {
367
+ const next = new Set(previous)
368
+ for (const id of fresh) next.add(id)
369
+ return next
370
+ })
371
+ const timer = setTimeout(() => {
372
+ timers.current.delete(timer)
373
+ setFreshIds(previous => {
374
+ const next = new Set(previous)
375
+ for (const id of fresh) next.delete(id)
376
+ return next
377
+ })
378
+ }, 1400)
379
+ timers.current.add(timer)
380
+ }, [projection])
381
+
382
+ React.useEffect(() => () => {
383
+ for (const timer of timers.current) clearTimeout(timer)
384
+ timers.current.clear()
385
+ }, [])
386
+
387
+ const groups = groupByTurn(records)
388
+ const firstBatch = takeBatch(groups, 0, RECORDS_PER_PAGE)
389
+
390
+ // Pin the first batch the first time a non-empty projection arrives. Its
391
+ // boundary never moves afterwards, so a live update cannot hide records
392
+ // the user already saw.
393
+ React.useEffect(() => {
394
+ if (pinned.current !== null || records.length === 0) return
395
+ const currentGroups = groupByTurn(records)
396
+ const batch = takeBatch(currentGroups, 0, RECORDS_PER_PAGE)
397
+ const boundary = lastRecordId(batch)
398
+ if (boundary === null) return
399
+ pinned.current = { complete: batch.length === currentGroups.length }
400
+ setPivotId(boundary)
401
+ }, [records])
402
+
403
+ // A replaced projection can lose the pivot; fall back to the first batch
404
+ // instead of failing.
405
+ const shownGroups = groupsThroughPivot(groups, pivotId) ?? firstBatch
406
+ const shownRecords = sumRecords(shownGroups)
407
+ const allShown = shownGroups.length === groups.length
408
+ const initialComplete = pinned.current === null
409
+ ? firstBatch.length === groups.length
410
+ : pinned.current.complete
411
+
412
+ // One click appends whole older groups until roughly another page of records.
413
+ const loadMore = () => {
414
+ const batch = takeBatch(groups, shownGroups.length, RECORDS_PER_PAGE)
415
+ const boundary = lastRecordId(batch)
416
+ if (boundary === null) return
417
+ setPivotId(boundary)
418
+ // The first row of a newest-first batch is that group's newest record.
419
+ setFocusId(batch[0].records[0].id)
420
+ }
421
+
422
+ const todayKey = dayKey(Date.now())
423
+ return h('div', { className: 'grb-root' },
424
+ h('div', { className: 'grb-scroll' },
425
+ records.length === 0
426
+ ? h(EmptyState, { t })
427
+ : [
428
+ h('div', {
429
+ key: 'count',
430
+ className: 'grb-count',
431
+ role: 'status',
432
+ 'aria-atomic': 'true',
433
+ }, allShown ? countText(t, records) : partialCountText(t, shownRecords, records)),
434
+ shownGroups.map(group => h(Group, {
435
+ // A group only ever gains records at its newest end, so the
436
+ // oldest record keeps the key stable across updates.
437
+ key: group.turn + ':' + group.records[group.records.length - 1].id,
438
+ group,
439
+ t,
440
+ todayKey,
441
+ freshIds,
442
+ focusId,
443
+ onFocusHandled,
444
+ })),
445
+ allShown ? null : h('div', { key: 'more', className: 'grb-more' },
446
+ h('button', {
447
+ type: 'button',
448
+ className: 'grb-more-button',
449
+ onClick: loadMore,
450
+ }, t('loadMore')),
451
+ ),
452
+ allShown && !initialComplete
453
+ ? h('div', { key: 'end', className: 'grb-end' }, t('endOfList'))
454
+ : null,
455
+ ],
456
+ ),
457
+ )
458
+ }
459
+
460
+ /**
461
+ * Checklist glyph copied from the product icon set, drawn as inline paths
462
+ * so the plugin carries no dependency on an official Client package.
463
+ */
464
+ function ChecklistIcon(props) {
465
+ const size = props && props.size ? props.size : 14
466
+ return h('svg', {
467
+ className: 'grb-header-icon', width: size, height: size,
468
+ viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor',
469
+ strokeWidth: 1, 'aria-hidden': 'true',
470
+ },
471
+ h('path', { d: 'M3.75 6.25C4.7165 6.25 5.5 5.4665 5.5 4.5C5.5 3.5335 4.7165 2.75 3.75 2.75C2.7835 2.75 2 3.5335 2 4.5C2 5.4665 2.7835 6.25 3.75 6.25Z' }),
472
+ h('path', { d: 'M7.5 4.5H13.5' }),
473
+ h('path', { d: 'M3.75 13.25C4.7165 13.25 5.5 12.4665 5.5 11.5C5.5 10.5335 4.7165 9.75 3.75 9.75C2.7835 9.75 2 10.5335 2 11.5C2 12.4665 2.7835 13.25 3.75 13.25Z' }),
474
+ h('path', { d: 'M7.5 11.5H13.5' }),
475
+ )
476
+ }
477
+
478
+ /**
479
+ * Compact title-bar button, styled after the official header actions
480
+ * (ui-jobs / ui-subagent): icon + label, theme tokens, hover/focus states.
481
+ * The native title keeps hover labels visible even where the header clips
482
+ * overflow, without a portal or an official Client package dependency.
483
+ */
484
+ function HeaderAction(props) {
485
+ const { sessionId, openIn, t, useProjection } = props
486
+ // Only sessions that have run a goal get this entry. `current` is present
487
+ // for active, paused, blocked and complete goals alike.
488
+ const hasGoal = typeof useProjection === 'function'
489
+ ? useProjection('goal', goal => goal != null)
490
+ : true
491
+ if (!hasGoal) return null
492
+ const label = typeof t === 'function' ? t('menu') : zh.menu
493
+ return h('button', {
494
+ type: 'button',
495
+ className: 'grb-header-action',
496
+ 'aria-label': label,
497
+ title: label,
498
+ onClick: () => { if (typeof openIn === 'function') openIn(sessionId) },
499
+ }, h(ChecklistIcon, { size: 14 }), h('span', { className: 'grb-header-action-label' }, label))
500
+ }
501
+
502
+ function apply(ctx) {
503
+ const slots = ctx.get('slots')
504
+ const locale = ctx.get('locale')
505
+ const sidebarRight = ctx.get('sidebarRight')
506
+ const tabs = ctx.get('sidebarRightTabs')
507
+
508
+ // Styles: inherit the host theme and font through --dsw-alias-* tokens.
509
+ ctx.effect(() => {
510
+ const tagId = TAB_ID + '/board'
511
+ let tag = document.querySelector('style[data-plugin-css="' + tagId + '"]')
512
+ if (tag === null) {
513
+ tag = document.createElement('style')
514
+ tag.dataset.plugin = TAB_ID
515
+ tag.dataset.pluginCss = tagId
516
+ tag.textContent = [
517
+ '.grb-root{display:flex;flex-direction:column;height:100%;min-height:0;overflow:hidden;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}',
518
+ '.grb-scroll{--dsh-scrollbar-width:9px;--dsh-scrollbar-thumb-border:2px;flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding:12px 12px 28px}',
519
+ '.grb-count{padding:0 8px;margin-bottom:4px;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary)}',
520
+ '.grb-more{display:flex;justify-content:center;padding:8px 8px 4px}',
521
+ '.grb-more-button{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 10px;border:.5px solid transparent;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-primary);font-family:inherit;font-size:12px;line-height:18px;cursor:pointer;box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsh-button-outline-color,var(--dsw-alias-border-l3,var(--dsw-alias-border-l2)))}',
522
+ '@media (hover:hover){.grb-more-button:hover{background:var(--dsw-alias-interactive-bg-hover)}}',
523
+ '.grb-end{padding:8px;text-align:center;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary)}',
524
+ '.grb-group-head{position:sticky;top:0;z-index:1;display:flex;justify-content:space-between;align-items:baseline;padding:12px 8px 6px;background:var(--dsw-alias-bg-base);border-bottom:.5px solid var(--dsw-alias-border-l1)}',
525
+ '.grb-group-title{font-size:12px;line-height:20px;font-weight:500;color:var(--dsw-alias-label-secondary)}',
526
+ '.grb-group-date{font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}',
527
+ '.grb-row{border-radius:var(--dsw-radius-sm)}',
528
+ '.grb-row-head{display:flex;align-items:center;gap:10px;width:100%;box-sizing:border-box;padding:7px 8px;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:inherit;font:inherit;font-size:13px;line-height:22px;text-align:left;cursor:pointer}',
529
+ '@media (hover:hover){.grb-row-head:hover{background:var(--dsw-alias-interactive-bg-hover)}}',
530
+ '.grb-row-head:active{background:var(--dsw-alias-interactive-bg-active)}',
531
+ '.grb-row-head:focus-visible{outline:2px solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));outline-offset:-2px}',
532
+ '.grb-time{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}',
533
+ '.grb-summary{flex:1;min-width:0;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--dsw-alias-label-primary)}',
534
+ '.grb-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}',
535
+ '.grb-chevron-open{transform:rotate(180deg)}',
536
+ '@keyframes grb-highlight{from{background:var(--dsw-alias-interactive-bg-active)}to{background:transparent}}',
537
+ '.grb-row-new{animation:grb-highlight 1.4s ease-out}',
538
+ '@keyframes grb-open{from{opacity:0;transform:translateY(-3px)}to{opacity:1;transform:none}}',
539
+ '.grb-drawer{padding:2px 8px 10px;animation:grb-open .16s ease-out}',
540
+ '.grb-drawer[hidden]{display:none}',
541
+ '.grb-field + .grb-field{margin-top:10px}',
542
+ '.grb-field-label{font-size:12px;line-height:20px;font-weight:500;color:var(--dsw-alias-label-secondary)}',
543
+ '.grb-field-text{margin-top:2px;font-size:13px;line-height:22px;color:var(--dsw-alias-label-primary);white-space:pre-wrap;overflow-wrap:anywhere}',
544
+ '@media (prefers-reduced-motion:reduce){.grb-row-new{animation:none;background:var(--dsw-alias-interactive-bg-active)}}',
545
+ '.grb-empty{display:flex;flex-direction:column;align-items:center;padding:48px 20px;text-align:center;color:var(--dsw-alias-label-tertiary);font-size:14px}',
546
+ '.grb-empty-icon{margin-bottom:12px;color:var(--dsw-alias-label-caption)}',
547
+ '.grb-empty-title{margin-bottom:8px;font-size:14px;line-height:1.6;font-weight:400;color:var(--dsw-alias-label-tertiary)}',
548
+ '.grb-empty-hint{max-width:280px;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary)}',
549
+ '.grb-header-action{display:inline-flex;align-items:center;gap:4px;min-height:28px;padding:3px 6px;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-tertiary);font-family:inherit;font-size:12px;line-height:18px;cursor:pointer}',
550
+ '.grb-header-action svg{flex:none;display:block}',
551
+ '.grb-header-action:focus-visible{color:var(--dsw-alias-label-secondary)}',
552
+ '@media (hover:hover){.grb-header-action:hover{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover)}}',
553
+ '.grb-header-action:active{background:var(--dsw-alias-interactive-bg-active)}',
554
+ '@container (max-width:460px){.grb-header-action-label{display:none}.grb-header-action{box-sizing:border-box;width:28px;height:28px;padding:0;justify-content:center;color:var(--dsw-alias-label-secondary)}}',
555
+ ].join('\n')
556
+ document.head.appendChild(tag)
557
+ }
558
+ return () => { tag.remove() }
559
+ }, 'goal-record-board: styles')
560
+
561
+ if (locale !== undefined) {
562
+ ctx.effect(() => locale.register(NS, dicts), 'goal-record-board: locale')
563
+ }
564
+
565
+ const t = makeT(locale)
566
+
567
+ if (tabs !== undefined) {
568
+ ctx.effect(() => tabs.register({
569
+ id: TAB_ID,
570
+ kind: TAB_KIND,
571
+ title: () => t('title'),
572
+ guide: [{
573
+ id: 'goal-record-board', order: 500,
574
+ title: () => t('title'),
575
+ description: () => t('guide'),
576
+ }],
577
+ }), 'goal-record-board: tab type')
578
+ }
579
+
580
+ if (slots !== undefined) {
581
+ ctx.effect(() => slots.inject('sidebar.right.pane.tab', () => slots.register(
582
+ { name: 'sidebar.right.pane.tab', key: TAB_ID },
583
+ props => h(Board, { t: useT(ctx), useProjection: props.useProjection }),
584
+ )), 'goal-record-board: tab body')
585
+ }
586
+
587
+ if (slots !== undefined) {
588
+ ctx.effect(() => slots.inject('conversation.session.header.actions', () => slots.register(
589
+ {
590
+ name: 'conversation.session.header.actions',
591
+ id: 'goal-record-board',
592
+ order: 20,
593
+ locale: NS,
594
+ inject: () => ({ openIn: sessionId => sidebarRight?.openTabIn(sessionId, TAB_KIND) }),
595
+ },
596
+ HeaderAction,
597
+ )), 'goal-record-board: session header action')
598
+ }
599
+ }
600
+
601
+ return {
602
+ inject: ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs'],
603
+ apply,
604
+ }
605
+ },
606
+ })
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: goal-record-board
3
+ name: '@wastee/dsh-goal-record-board'
package/icon.svg ADDED
@@ -0,0 +1,19 @@
1
+ <svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect x="6" y="8" width="24" height="5" rx="2.5" fill="url(#grb-a)" />
3
+ <rect x="6" y="15.5" width="24" height="5" rx="2.5" fill="url(#grb-b)" />
4
+ <rect x="6" y="23" width="16" height="5" rx="2.5" fill="url(#grb-c)" />
5
+ <defs>
6
+ <linearGradient id="grb-a" x1="6" y1="10.5" x2="30" y2="10.5" gradientUnits="userSpaceOnUse">
7
+ <stop stop-color="#7AC2FF" />
8
+ <stop offset="1" stop-color="#4A65E8" />
9
+ </linearGradient>
10
+ <linearGradient id="grb-b" x1="6" y1="18" x2="30" y2="18" gradientUnits="userSpaceOnUse">
11
+ <stop stop-color="#6FAEF6" />
12
+ <stop offset="1" stop-color="#4A6FE0" />
13
+ </linearGradient>
14
+ <linearGradient id="grb-c" x1="6" y1="25.5" x2="22" y2="25.5" gradientUnits="userSpaceOnUse">
15
+ <stop stop-color="#5F9CE8" />
16
+ <stop offset="1" stop-color="#3F5EC8" />
17
+ </linearGradient>
18
+ </defs>
19
+ </svg>
package/index.js ADDED
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Goal record board — Host half.
3
+ *
4
+ * The agent calls `goal_record` at the end of a goal round with three fields:
5
+ * problem, solution, result. Every call is already committed as a durable
6
+ * session event by the framework, either as a direct `tool/call` or, when the
7
+ * model reaches it through `run_code`, as a `tool/ptc-dispatch` sub-event. A
8
+ * session projection folds both shapes into a plain-JSON list and publishes it
9
+ * as a Client view. Nothing is written to a second store, so the board is
10
+ * reconstructable from the log.
11
+ */
12
+ import { defineTool } from '@deepseek-ai/dsh-tools'
13
+ import { z } from 'zod'
14
+
15
+ /** Model-facing tool name. Also the fold discriminator on `tool/call` events. */
16
+ const TOOL_NAME = 'goal_record'
17
+
18
+ /** Projection key consumed by the Client through `useProjection('goalRecordBoard')`. */
19
+ const PROJECTION_KEY = 'goalRecordBoard'
20
+
21
+ /** One board record, stored in plain JSON and sent to the Client as-is. */
22
+ const recordSchema = z.object({
23
+ id: z.string(),
24
+ turn: z.number(),
25
+ seq: z.number(),
26
+ time: z.number(),
27
+ problem: z.string(),
28
+ solution: z.string(),
29
+ result: z.string(),
30
+ })
31
+
32
+ /** callTurns maps a top-level tool/call callId to the turn it happened in. */
33
+ const stateSchema = z.object({
34
+ records: z.array(recordSchema),
35
+ callTurns: z.record(z.string(), z.number()),
36
+ })
37
+ const viewSchema = z.array(recordSchema)
38
+
39
+ /** Only goal_record calls with three non-empty fields become board records. */
40
+ function appendRecord(state, event, args, id, turn) {
41
+ if (args === null || typeof args !== 'object') return state
42
+ const text = value => typeof value === 'string' ? value.trim() : ''
43
+ const problem = text(args.problem)
44
+ const solution = text(args.solution)
45
+ const result = text(args.result)
46
+ if (problem === '' || solution === '' || result === '') return state
47
+ if (state.records.some(record => record.id === id)) return state
48
+ return {
49
+ ...state,
50
+ records: [...state.records, {
51
+ id,
52
+ turn,
53
+ seq: event.seq,
54
+ time: event.time,
55
+ problem,
56
+ solution,
57
+ result,
58
+ }],
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Pure fold over two log shapes: a direct `tool/call` and a PTC sub-call
64
+ * (`tool/ptc-dispatch`) emitted when the model reaches goal_record through
65
+ * run_code. The record id deduplicates both; the callId -> turn map supplies
66
+ * the turn that a PTC sub-event does not carry.
67
+ */
68
+ export const projection = {
69
+ key: PROJECTION_KEY,
70
+ stateVersion: 2,
71
+ stateSchema,
72
+ init: () => ({ records: [], callTurns: {} }),
73
+ apply(state, event) {
74
+ if (event.type === 'tool/call') {
75
+ // Remember the turn of every top-level call so a later PTC sub-event
76
+ // can recover it through rootCallId.
77
+ const callId = event.data.callId
78
+ const turn = event.data.turn
79
+ const callTurns = state.callTurns ?? {}
80
+ if (callId !== undefined && callId !== null && typeof turn === 'number') {
81
+ state = { ...state, callTurns: { ...callTurns, [String(callId)]: turn } }
82
+ }
83
+ if (event.data.name !== TOOL_NAME) return state
84
+ let args
85
+ try {
86
+ args = JSON.parse(event.data.arguments)
87
+ } catch {
88
+ return state
89
+ }
90
+ return appendRecord(state, event, args, String(callId), typeof turn === 'number' ? turn : 0)
91
+ }
92
+
93
+ if (event.type === 'tool/ptc-dispatch') {
94
+ if (event.data.name !== TOOL_NAME) return state
95
+ // A PTC dispatch already carries arguments as an object, no JSON.parse.
96
+ const args = event.data.arguments
97
+ const id = String(event.data.subCallId)
98
+ const rootCallId = String(event.data.rootCallId)
99
+ const turn = (state.callTurns ?? {})[rootCallId] ?? 0
100
+ return appendRecord(state, event, args, id, turn)
101
+ }
102
+
103
+ return state
104
+ },
105
+ wire: { viewSchema, view: state => state.records },
106
+ }
107
+
108
+ export const inject = ['tools', 'systemPrompt', 'sessionProjections']
109
+
110
+ export function apply(ctx) {
111
+ // The projection reads the durable tool log; the tool itself only confirms.
112
+ // register() resolves to a handle whose dispose() releases it. The effect owns
113
+ // that release so the registration follows this plugin's lifetime.
114
+ ctx.effect(() => {
115
+ let handle
116
+ let disposed = false
117
+ void ctx.sessionProjections.register(projection).then((ready) => {
118
+ if (disposed) void ready.dispose()
119
+ else handle = ready
120
+ })
121
+ return () => {
122
+ disposed = true
123
+ if (handle !== undefined) void handle.dispose()
124
+ }
125
+ }, 'goal-record-board: projection')
126
+
127
+ ctx.effect(() => ctx.tools.register(defineTool({
128
+ name: TOOL_NAME,
129
+ description: 'Record one goal round in the board: the problem hit, the solution used, and the result achieved. Call once at the end of each round while a goal is active. The board keeps one collapsed row per call for the user to expand.',
130
+ parameters: {
131
+ problem: {
132
+ type: 'string',
133
+ required: true,
134
+ description: 'What problem or obstacle this round ran into.',
135
+ },
136
+ solution: {
137
+ type: 'string',
138
+ required: true,
139
+ description: 'What approach or change was used to handle it.',
140
+ },
141
+ result: {
142
+ type: 'string',
143
+ required: true,
144
+ description: 'What was actually achieved or verified at the end of the round.',
145
+ },
146
+ },
147
+ output: {
148
+ schema: {
149
+ type: 'object',
150
+ additionalProperties: false,
151
+ properties: { recorded: { type: 'boolean' } },
152
+ },
153
+ render: (_args, value) => [{
154
+ type: 'text',
155
+ text: value.recorded === true ? 'Recorded this round in the goal board.' : 'The round was not recorded.',
156
+ }],
157
+ },
158
+ execute: () => Promise.resolve({ recorded: true }),
159
+ })), 'goal-record-board: tool')
160
+
161
+ ctx.effect(() => ctx.systemPrompt.section({
162
+ name: 'goal-record-board',
163
+ order: 9050,
164
+ text: 'When a goal is active, call goal_record once at the end of each round. Put the problem met, the solution used, and the result achieved in its three fields. Keep each field to a short, concrete statement; do not repeat the whole answer.',
165
+ }), 'goal-record-board: prompt')
166
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Goal Record Board",
4
+ "description": "Records the problem, solution and result of each goal round in a session-side board. A checklist button in the session header opens the board; click a record to expand it."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "目标记录看板",
4
+ "description": "在会话右侧记录 goal 每一轮遇到的问题、采用的方案和取得的成果。会话标题栏的清单按钮可打开看板,点击记录展开查看。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@wastee/dsh-goal-record-board",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.2",
4
+ "description": "把目标每个轮次遇到的问题、采用的方案和取得的成果记录到右栏看板,点击进入抽屉查看。",
5
+ "type": "module",
6
+ "scripts": {
7
+ "test": "node --test tests/*.test.js"
8
+ },
9
+ "keywords": [
10
+ "dsh",
11
+ "dsh-plugin",
12
+ "goal",
13
+ "board",
14
+ "session"
15
+ ],
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/wastee/dsh-goal-record-board.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/wastee/dsh-goal-record-board/issues"
23
+ },
24
+ "homepage": "https://github.com/wastee/dsh-goal-record-board#readme",
25
+ "engines": {
26
+ "dsh": ">=0.2.0 <0.3.0"
27
+ },
28
+ "exports": {
29
+ ".": "./index.js",
30
+ "./client": "./client.js",
31
+ "./locale/*.json": "./locale/*.json",
32
+ "./icon": "./icon.svg"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "client.js",
37
+ "cordis.patch.yml",
38
+ "locale/*.json",
39
+ "icon.svg",
40
+ "README.md"
41
+ ],
42
+ "dsh": {
43
+ "bundle": {
44
+ "patch": "./cordis.patch.yml"
45
+ },
46
+ "client": {
47
+ "platform": "web",
48
+ "immediately": true,
49
+ "inject": [
50
+ "@deepseek-ai/dsh-client-ui-conversation",
51
+ "@deepseek-ai/dsh-client-ui-sidebar-right",
52
+ "@deepseek-ai/dsh-client-ui-session"
53
+ ]
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
58
+ "zod": "^4.6.7"
59
+ }
60
+ }