dsh-worklog-topics 0.0.0-stage → 0.1.3
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/LICENSE +21 -0
- package/README.md +95 -2
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +58 -0
- package/docs/DETAIL.zh.md +58 -0
- package/docs/screenshots/panel-gantt.webp +0 -0
- package/docs/screenshots/panel-topics.webp +0 -0
- package/icon.svg +6 -0
- package/lib/client.js +1294 -0
- package/lib/index.js +2049 -0
- package/lib/mobile.js +1 -0
- package/lib/store.js +142 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/mobile/page.html +76 -0
- package/mobile/style.css +3 -0
- package/mobile.js +132 -0
- package/package.json +69 -4
- package/scripts/bench-context.mjs +282 -0
- package/scripts/self-check.mjs +125 -0
- package/scripts/self-test.mjs +862 -0
- package/selftest.mjs +1 -0
- package/vendor/LICENSE.cosmokit +21 -0
- package/vendor/LICENSE.schemastery +21 -0
- package/vendor/cosmokit.mjs +418 -0
- package/vendor/schemastery.mjs +635 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1294 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-worklog',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
|
|
7
|
+
const NS = 'dsh-worklog'
|
|
8
|
+
const TAB_ID = 'dsh-worklog'
|
|
9
|
+
const TAB_KIND = 'worklog'
|
|
10
|
+
const VERSION = '0.1.3'
|
|
11
|
+
const PANEL_ROUTE = '/dsh-worklog/panel'
|
|
12
|
+
const TOGGLE_ROUTE = '/dsh-worklog/toggle'
|
|
13
|
+
const SETTINGS_ROUTE = '/dsh-worklog/settings'
|
|
14
|
+
const POLL_MS = 20000
|
|
15
|
+
|
|
16
|
+
const COPY = {
|
|
17
|
+
zh: {
|
|
18
|
+
'tab.title': '工作日志',
|
|
19
|
+
'tab.desc': '每次对话结束自动记一行,按天存文件。',
|
|
20
|
+
'date.today': '今日',
|
|
21
|
+
'date.prev': '前一天',
|
|
22
|
+
'date.next': '后一天',
|
|
23
|
+
'date.range': '日期范围',
|
|
24
|
+
'date.pick': '点击选择日期范围',
|
|
25
|
+
'date.from': '从',
|
|
26
|
+
'date.to': '到',
|
|
27
|
+
'date.apply': '查看',
|
|
28
|
+
'date.cancel': '取消',
|
|
29
|
+
'head.countOne': '{n} 条',
|
|
30
|
+
'head.count': '{n} 条',
|
|
31
|
+
'switch.label': '自动记录',
|
|
32
|
+
'switch.hintOn': '每轮对话结束时写一行,不写对话正文。',
|
|
33
|
+
'switch.hintOff': '已暂停,不会写入任何记录。',
|
|
34
|
+
'list.empty': '今天还没有记录。聊一轮、等这一轮结束,这里就会自动出现一行。',
|
|
35
|
+
'list.emptyHint': '不用手动确认,也不用点任何按钮。',
|
|
36
|
+
'foot.path': '存放',
|
|
37
|
+
'foot.last': '最后写入',
|
|
38
|
+
'foot.size': '磁盘占用',
|
|
39
|
+
'action.refresh': '刷新',
|
|
40
|
+
'action.refreshing': '刷新中…',
|
|
41
|
+
'status.loading': '正在读日志…',
|
|
42
|
+
'status.error': '读不到日志',
|
|
43
|
+
'status.retry': '重试',
|
|
44
|
+
'status.offline': 'Host 侧没有响应。确认「工作日志」插件还在运行。',
|
|
45
|
+
'toast.saved': '已更新,立即生效',
|
|
46
|
+
'meta.tools': '{n} 个工具',
|
|
47
|
+
'meta.files': '{n} 个文件',
|
|
48
|
+
'meta.noTools': '未调用工具',
|
|
49
|
+
'meta.agent': '预设',
|
|
50
|
+
'action.expand': '点击展开全文',
|
|
51
|
+
'gantt.empty': '还没有带主题的记录,主题累积起来后这里会出现时间轴。',
|
|
52
|
+
'gantt.time': '时间',
|
|
53
|
+
'gantt.now': '进行中',
|
|
54
|
+
'gantt.nowLine': '现在',
|
|
55
|
+
'gantt.topicCount': '{n} 个主题',
|
|
56
|
+
'gantt.underMinute': '<1m',
|
|
57
|
+
'gantt.foot': '{n} 个主题 · 覆盖 {covered},占今天已过时段 {share}%',
|
|
58
|
+
'action.collapse': '点击收起',
|
|
59
|
+
'ai.label': '摘要',
|
|
60
|
+
'settings.open': '设置',
|
|
61
|
+
'settings.close': '收起',
|
|
62
|
+
'settings.title': '摘要模型与提示词',
|
|
63
|
+
'settings.loading': '正在读可用模型…',
|
|
64
|
+
'settings.primary': '主摘要',
|
|
65
|
+
'settings.secondary': '对比摘要',
|
|
66
|
+
'settings.hostDefault': '跟随宿主默认',
|
|
67
|
+
'settings.effective': '当前生效:',
|
|
68
|
+
'settings.effectiveUnknown': '开启一轮对话后就知道宿主用的是哪个模型了',
|
|
69
|
+
'settings.off': '关闭对比',
|
|
70
|
+
'settings.local': '本地',
|
|
71
|
+
'settings.promptPrimary': '主摘要提示词',
|
|
72
|
+
'settings.promptSecondary': '对比摘要提示词',
|
|
73
|
+
'settings.promptPlaceholder': '留空使用内置提示词',
|
|
74
|
+
'settings.hint': '上面是当前实际使用的提示词,可以直接改;保存后即为你的自定义版本,点「恢复内置」可还原。',
|
|
75
|
+
'settings.restore': '恢复内置',
|
|
76
|
+
'settings.save': '保存',
|
|
77
|
+
'settings.saving': '保存中…',
|
|
78
|
+
'settings.error': '保存失败',
|
|
79
|
+
'ai.primary': '主',
|
|
80
|
+
'ai.secondary': '对比',
|
|
81
|
+
'ai.hostDefault': '宿主默认',
|
|
82
|
+
'ai.off': '零成本截断',
|
|
83
|
+
'ai.answer': '答',
|
|
84
|
+
'list.notes': '手记',
|
|
85
|
+
'list.end': '— 共 {n} 条,到底了 —',
|
|
86
|
+
'meta.turns': '{n} 条',
|
|
87
|
+
'group.workspace': '工作区',
|
|
88
|
+
'group.sessionFile': '会话文件',
|
|
89
|
+
'view.session': '按会话',
|
|
90
|
+
'view.topic': '按主题',
|
|
91
|
+
'view.gantt': '甘特',
|
|
92
|
+
'view.label': '分组方式',
|
|
93
|
+
'group.session': '会话',
|
|
94
|
+
'group.topicCount': '{n} 个主题',
|
|
95
|
+
'group.sessionCount': '{n} 个会话',
|
|
96
|
+
'topic.hint': '主题从开启后开始记录;之前的记录会留在「未归主题」里。',
|
|
97
|
+
'topic.untagged': '未归主题',
|
|
98
|
+
'topic.untaggedWhy': '主题开启前的记录',
|
|
99
|
+
'kind.turn': '对话',
|
|
100
|
+
'kind.note': '手记',
|
|
101
|
+
'kind.tool': '工具',
|
|
102
|
+
},
|
|
103
|
+
en: {
|
|
104
|
+
'tab.title': 'Worklog',
|
|
105
|
+
'tab.desc': 'One line per finished turn, one file per day.',
|
|
106
|
+
'date.today': 'Today',
|
|
107
|
+
'date.prev': 'Previous day',
|
|
108
|
+
'date.next': 'Next day',
|
|
109
|
+
'date.range': 'Range',
|
|
110
|
+
'date.pick': 'Pick a date range',
|
|
111
|
+
'date.from': 'From',
|
|
112
|
+
'date.to': 'To',
|
|
113
|
+
'date.apply': 'Show',
|
|
114
|
+
'date.cancel': 'Cancel',
|
|
115
|
+
'head.countOne': '{n}',
|
|
116
|
+
'head.count': '{n}',
|
|
117
|
+
'switch.label': 'Auto capture',
|
|
118
|
+
'switch.hintOn': 'One line when a turn ends. The conversation body is never stored.',
|
|
119
|
+
'switch.hintOff': 'Paused. Nothing is written.',
|
|
120
|
+
'list.empty': 'Nothing logged today yet. Finish a turn and a line appears here on its own.',
|
|
121
|
+
'list.emptyHint': 'No confirmation, no button to press.',
|
|
122
|
+
'foot.path': 'Store',
|
|
123
|
+
'foot.last': 'Last write',
|
|
124
|
+
'foot.size': 'On disk',
|
|
125
|
+
'action.refresh': 'Refresh',
|
|
126
|
+
'action.refreshing': 'Refreshing…',
|
|
127
|
+
'status.loading': 'Reading the log…',
|
|
128
|
+
'status.error': 'Cannot read the log',
|
|
129
|
+
'status.retry': 'Retry',
|
|
130
|
+
'status.offline': 'The Host side did not answer. Check that the Worklog plugin is still running.',
|
|
131
|
+
'toast.saved': 'Updated, effective now',
|
|
132
|
+
'meta.tools': '{n} tools',
|
|
133
|
+
'meta.files': '{n} files',
|
|
134
|
+
'meta.noTools': 'no tools',
|
|
135
|
+
'meta.agent': 'preset',
|
|
136
|
+
'action.expand': 'Click to read it all',
|
|
137
|
+
'gantt.empty': 'No topics yet. Once topics accumulate, the timeline appears here.',
|
|
138
|
+
'gantt.time': 'Time',
|
|
139
|
+
'gantt.now': 'now',
|
|
140
|
+
'gantt.nowLine': 'now',
|
|
141
|
+
'gantt.topicCount': '{n} topics',
|
|
142
|
+
'gantt.underMinute': '<1m',
|
|
143
|
+
'gantt.foot': '{n} topics · {covered} covered, {share}% of today so far',
|
|
144
|
+
'action.collapse': 'Click to collapse',
|
|
145
|
+
'ai.label': 'Summary',
|
|
146
|
+
'settings.open': 'Settings',
|
|
147
|
+
'settings.close': 'Close',
|
|
148
|
+
'settings.title': 'Summary models and prompts',
|
|
149
|
+
'settings.loading': 'Reading available models…',
|
|
150
|
+
'settings.primary': 'Primary',
|
|
151
|
+
'settings.secondary': 'Comparison',
|
|
152
|
+
'settings.hostDefault': 'Follow the host default',
|
|
153
|
+
'settings.effective': 'Currently: ',
|
|
154
|
+
'settings.effectiveUnknown': 'The model appears after the next turn',
|
|
155
|
+
'settings.off': 'Off',
|
|
156
|
+
'settings.local': 'Local',
|
|
157
|
+
'settings.promptPrimary': 'Primary prompt',
|
|
158
|
+
'settings.promptSecondary': 'Comparison prompt',
|
|
159
|
+
'settings.promptPlaceholder': 'Empty keeps the built-in prompt',
|
|
160
|
+
'settings.hint': 'These are the prompts actually in use; edit them and save to keep your own version. "Restore" brings back the built-in text.',
|
|
161
|
+
'settings.restore': 'Restore built-in',
|
|
162
|
+
'settings.save': 'Save',
|
|
163
|
+
'settings.saving': 'Saving…',
|
|
164
|
+
'settings.error': 'Save failed',
|
|
165
|
+
'ai.primary': 'A',
|
|
166
|
+
'ai.secondary': 'B',
|
|
167
|
+
'ai.hostDefault': 'host default',
|
|
168
|
+
'ai.off': 'zero-cost digest',
|
|
169
|
+
'ai.answer': 'A',
|
|
170
|
+
'list.notes': 'Notes',
|
|
171
|
+
'list.end': '— {n} entries, end —',
|
|
172
|
+
'meta.turns': '{n}',
|
|
173
|
+
'group.workspace': 'Workspace',
|
|
174
|
+
'group.sessionFile': 'Session file',
|
|
175
|
+
'view.session': 'Session',
|
|
176
|
+
'view.topic': 'Topic',
|
|
177
|
+
'view.gantt': 'Timeline',
|
|
178
|
+
'view.label': 'Group by',
|
|
179
|
+
'group.session': 'Session',
|
|
180
|
+
'group.topicCount': '{n} topics',
|
|
181
|
+
'group.sessionCount': '{n} sessions',
|
|
182
|
+
'topic.hint': 'Topics are recorded from the moment this was enabled; earlier entries stay under "No topic".',
|
|
183
|
+
'topic.untagged': 'No topic',
|
|
184
|
+
'topic.untaggedWhy': 'recorded before topics existed',
|
|
185
|
+
'kind.turn': 'Turn',
|
|
186
|
+
'kind.note': 'Note',
|
|
187
|
+
'kind.tool': 'Tool',
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const CSS = `
|
|
192
|
+
.wl-root, .wl-root *, .wl-root *::before, .wl-root *::after { box-sizing: border-box; }
|
|
193
|
+
.wl-root { display: flex; flex-direction: column; height: 100%; min-height: 0; color: var(--dsw-alias-label-primary); font-size: var(--wl-fs-md); line-height: 1.5; }
|
|
194
|
+
.wl-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px; flex: none; }
|
|
195
|
+
.wl-title { font-size: var(--wl-fs-lg); font-weight: 600; letter-spacing: 0.01em; }
|
|
196
|
+
.wl-count { margin-left: auto; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
197
|
+
.wl-switch { position: relative; flex: none; width: 34px; height: 20px; padding: 0; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--wl-radius-pill); background: var(--dsw-alias-bg-layer-2); cursor: pointer; transition: background 120ms ease, border-color 120ms ease; }
|
|
198
|
+
.wl-switch[aria-checked="true"] { background: var(--dsw-alias-state-business-primary); border-color: var(--dsw-alias-state-business-primary); }
|
|
199
|
+
.wl-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--dsw-alias-label-primary); transition: transform 120ms ease, background 120ms ease; }
|
|
200
|
+
.wl-switch[aria-checked="true"]::after { transform: translateX(14px); background: var(--dsw-alias-label-on-color); }
|
|
201
|
+
.wl-switch:disabled { opacity: 0.5; cursor: default; }
|
|
202
|
+
.wl-switch:focus-visible, .wl-btn:focus-visible { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 2px; }
|
|
203
|
+
.wl-bar { display: flex; align-items: center; gap: 8px; margin: 0 12px 10px; }
|
|
204
|
+
.wl-bar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
|
|
205
|
+
.wl-btn { flex: none; padding: 4px 10px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: var(--wl-fs-xs); cursor: pointer; }
|
|
206
|
+
.wl-btn:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); border-color: var(--dsw-alias-border-l2); }
|
|
207
|
+
.wl-btn:disabled { opacity: 0.55; cursor: default; }
|
|
208
|
+
.wl-views { flex: none; display: flex; gap: 2px; margin-right: auto; padding: 2px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); background: var(--dsw-alias-bg-layer-1); }
|
|
209
|
+
.wl-view { padding: 2px 8px; border: 0; border-radius: calc(var(--wl-radius-chip) - 2px); background: transparent; color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: var(--wl-fs-xs); cursor: pointer; }
|
|
210
|
+
.wl-view[aria-pressed="true"] { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); font-weight: 600; }
|
|
211
|
+
.wl-view:disabled { opacity: 0.55; cursor: default; }
|
|
212
|
+
.wl-list { flex: 1; min-height: 0; overflow: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
|
|
213
|
+
.wl-group { display: flex; flex-direction: column; gap: 8px; }
|
|
214
|
+
.wl-group-head { display: flex; align-items: baseline; gap: 8px; padding: 0 2px; }
|
|
215
|
+
.wl-group-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--wl-fs-sm); font-weight: 600; color: var(--dsw-alias-label-primary); }
|
|
216
|
+
.wl-group-meta { flex: none; margin-left: auto; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
217
|
+
.wl-group-sub { display: flex; gap: 6px; align-items: baseline; min-width: 0; padding: 0 2px; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
218
|
+
.wl-group-k { flex: none; }
|
|
219
|
+
.wl-group-v { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
220
|
+
.wl-group + .wl-group { border-top: 1px solid var(--dsw-alias-border-l1); padding-top: 10px; }
|
|
221
|
+
.wl-gantt { flex: 1; min-height: 0; overflow: auto; padding: 0 0 6px; }
|
|
222
|
+
.wl-gantt-canvas { position: relative; padding-bottom: 18px; }
|
|
223
|
+
.wl-gantt-row { display: flex; align-items: stretch; height: 28px; }
|
|
224
|
+
.wl-gantt-session { height: 30px; background: var(--dsw-alias-bg-layer-2); align-items: center; cursor: pointer; }
|
|
225
|
+
.wl-gantt-session:hover { background: var(--dsw-alias-bg-layer-1); }
|
|
226
|
+
.wl-gantt-session .wl-gantt-name { font-size: var(--wl-fs-xs); font-weight: 700; letter-spacing: 0.01em; }
|
|
227
|
+
.wl-gantt-session .wl-gantt-meta { opacity: 0.75; }
|
|
228
|
+
.wl-gantt-band { position: absolute; top: 50%; height: 5px; transform: translateY(-50%); border-radius: 3px; background: var(--dsw-alias-label-secondary); opacity: 0.32; }
|
|
229
|
+
.wl-gantt-topic .wl-gantt-label { padding-left: 22px; position: sticky; }
|
|
230
|
+
.wl-gantt-topic .wl-gantt-label::before { content: ""; position: absolute; left: 12px; top: 4px; bottom: 4px; width: 1px; background: var(--dsw-alias-border-l2); }
|
|
231
|
+
.wl-gantt-topic .wl-gantt-name { font-size: var(--wl-fs-sm); }
|
|
232
|
+
.wl-gantt-axis { height: 20px; position: sticky; top: 0; z-index: 4; background: var(--dsw-alias-bg-layer-1); }
|
|
233
|
+
.wl-gantt-label { position: sticky; left: 0; z-index: 3; flex: none; width: 180px; padding: 0 8px 0 12px; display: flex; align-items: center; gap: 6px; background: var(--dsw-alias-bg-layer-1); border-right: 1px solid var(--dsw-alias-border-l1); }
|
|
234
|
+
.wl-gantt-axis .wl-gantt-label { font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
235
|
+
.wl-gantt-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--wl-fs-sm); color: var(--dsw-alias-label-primary); }
|
|
236
|
+
.wl-gantt-meta { flex: none; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
237
|
+
.wl-gantt-track { position: relative; flex: none; height: 100%; background-image: repeating-linear-gradient(to right, var(--dsw-alias-border-l1) 0 1px, transparent 1px 100%); background-size: 360px 100%; }
|
|
238
|
+
.wl-gantt-axis .wl-gantt-track { background-image: none; }
|
|
239
|
+
.wl-gantt-tick { position: absolute; top: 3px; transform: translateX(-50%); font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
240
|
+
.wl-gantt-tick[data-major="false"] { opacity: 0.45; }
|
|
241
|
+
.wl-gantt-tick::after { content: ""; position: absolute; top: 14px; left: 50%; width: 1px; height: 4px; background: var(--dsw-alias-border-l2); }
|
|
242
|
+
.wl-gantt-bar { position: absolute; top: 50%; height: 16px; transform: translateY(-50%); border-radius: 5px; background: var(--dsw-alias-state-business-primary); opacity: 0.8; }
|
|
243
|
+
.wl-gantt-bar[data-ongoing="true"] { opacity: 1; box-shadow: 0 0 0 1px var(--dsw-alias-state-business-primary); }
|
|
244
|
+
.wl-gantt-tip { position: fixed; z-index: 8; transform: translate(-50%, calc(-100% - 8px)); max-width: 340px; padding: 7px 9px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); font-size: var(--wl-fs-xs); line-height: 1.5; white-space: pre-wrap; box-shadow: 0 8px 24px #0000002e; pointer-events: none; }
|
|
245
|
+
.wl-gantt-now { position: absolute; top: 20px; width: 0; height: calc(100% - 38px); border-left: 1px dashed var(--dsw-alias-label-secondary); opacity: 0.5; }
|
|
246
|
+
.wl-gantt-now-label { position: absolute; top: -1px; left: 4px; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); white-space: nowrap; }
|
|
247
|
+
.wl-gantt-foot { flex: none; padding: 4px 12px 0; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
248
|
+
.wl-dates { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
|
|
249
|
+
.wl-nav { width: 20px; height: 20px; padding: 0; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 1; cursor: pointer; }
|
|
250
|
+
.wl-nav:hover { background: var(--dsw-alias-bg-layer-2); }
|
|
251
|
+
.wl-date { padding: 2px 8px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: var(--wl-fs-xs); font-variant-numeric: tabular-nums; cursor: pointer; }
|
|
252
|
+
.wl-range { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 12px 10px; padding: 8px 10px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-inner); background: var(--dsw-alias-bg-layer-1); font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
253
|
+
.wl-range-row { display: flex; align-items: center; gap: 6px; }
|
|
254
|
+
.wl-input { font-family: inherit; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); padding: 3px 6px; }
|
|
255
|
+
.wl-settings { margin: 0 12px 12px; flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-inner); background: var(--dsw-alias-bg-layer-1); display: flex; flex-direction: column; gap: 8px; }
|
|
256
|
+
.wl-settings-head { display: flex; align-items: center; gap: 8px; }
|
|
257
|
+
.wl-settings-title { font-size: var(--wl-fs-sm); font-weight: 600; }
|
|
258
|
+
.wl-settings-head .wl-btn { margin-left: auto; }
|
|
259
|
+
.wl-settings-row { display: flex; align-items: center; gap: 8px; font-size: var(--wl-fs-xs); }
|
|
260
|
+
.wl-settings-row.wl-settings-col { flex-direction: column; align-items: stretch; gap: 4px; }
|
|
261
|
+
.wl-settings-k { flex: none; width: 88px; color: var(--dsw-alias-label-secondary); }
|
|
262
|
+
.wl-settings-col .wl-settings-k { width: auto; }
|
|
263
|
+
.wl-select, .wl-textarea { font-family: inherit; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); padding: 4px 6px; }
|
|
264
|
+
.wl-select { flex: 1; min-width: 0; }
|
|
265
|
+
.wl-textarea { resize: none; overflow: hidden; line-height: 1.6; }
|
|
266
|
+
.wl-hint-sm { margin: 0; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
267
|
+
.wl-settings-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
268
|
+
.wl-end { padding: 6px 0 2px; text-align: center; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); opacity: 0.75; }
|
|
269
|
+
.wl-group-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
|
|
270
|
+
.wl-item { border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--wl-radius-inner); background: var(--dsw-alias-bg-layer-1); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
|
|
271
|
+
.wl-item-head { display: flex; align-items: center; gap: 8px; }
|
|
272
|
+
.wl-topic { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-chip); color: var(--dsw-alias-label-secondary); font-size: var(--wl-fs-xs); }
|
|
273
|
+
.wl-time { font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
274
|
+
.wl-kind { flex: none; margin-left: auto; padding: 1px 7px; border-radius: var(--wl-radius-pill); background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary); font-size: var(--wl-fs-xs); }
|
|
275
|
+
.wl-kind[data-kind="turn"] { color: var(--dsw-alias-state-business-primary); }
|
|
276
|
+
.wl-kind[data-kind="note"] { color: var(--dsw-alias-state-warn-label); }
|
|
277
|
+
.wl-summary { margin: 0; color: var(--dsw-alias-label-primary); font-size: var(--wl-fs-md); overflow-wrap: anywhere; }
|
|
278
|
+
.wl-ai { display: flex; gap: 6px; align-items: baseline; margin: 0; }
|
|
279
|
+
.wl-ai-tag { flex: none; width: 58px; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.02em; }
|
|
280
|
+
.wl-ai-text[data-expandable="true"] { cursor: pointer; }
|
|
281
|
+
.wl-ai-text[data-open="true"] { display: block; -webkit-line-clamp: unset; }
|
|
282
|
+
.wl-ai-text { min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--dsw-alias-label-primary); font-size: var(--wl-fs-md); overflow-wrap: anywhere; }
|
|
283
|
+
.wl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
284
|
+
.wl-chip { padding: 1px 6px; border: 1px solid var(--dsw-alias-border-l1); border-radius: var(--wl-radius-pill); color: var(--dsw-alias-label-secondary); font-size: var(--wl-fs-xs); }
|
|
285
|
+
.wl-empty { margin: 4px 0 0; border: 1px dashed transparent; border-radius: var(--wl-radius-inner); padding: 16px 12px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); font-size: var(--wl-fs-sm); }
|
|
286
|
+
.wl-empty-hint { margin: 6px 0 0; color: var(--dsw-alias-label-secondary); font-size: var(--wl-fs-xs); }
|
|
287
|
+
.wl-note { margin: 0 12px 8px; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
288
|
+
.wl-note[data-tone="ok"] { color: var(--dsw-alias-state-success-primary); }
|
|
289
|
+
.wl-note[data-tone="err"] { color: var(--dsw-alias-state-error-primary); white-space: pre-wrap; }
|
|
290
|
+
.wl-foot { flex: none; padding: 10px 12px 12px; border-top: 1px solid var(--dsw-alias-border-l1); display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; font-size: var(--wl-fs-xs); color: var(--dsw-alias-label-secondary); }
|
|
291
|
+
.wl-foot-k { white-space: nowrap; }
|
|
292
|
+
.wl-foot-v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
293
|
+
`
|
|
294
|
+
|
|
295
|
+
const VARS = {
|
|
296
|
+
'--wl-fs-xs': '11px',
|
|
297
|
+
'--wl-fs-sm': '12px',
|
|
298
|
+
'--wl-fs-md': '13px',
|
|
299
|
+
'--wl-fs-lg': '14px',
|
|
300
|
+
'--wl-radius-card': '16px',
|
|
301
|
+
'--wl-radius-inner': '12px',
|
|
302
|
+
'--wl-radius-chip': '10px',
|
|
303
|
+
'--wl-radius-pill': '7px',
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function fmt(t, key, params) {
|
|
307
|
+
let text = t(key)
|
|
308
|
+
if (params) {
|
|
309
|
+
for (const name of Object.keys(params)) text = text.split(`{${name}}`).join(String(params[name]))
|
|
310
|
+
}
|
|
311
|
+
return text
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function tail(text, max) {
|
|
315
|
+
const value = String(text ?? '')
|
|
316
|
+
return value.length <= max ? value : `…${value.slice(-(max - 1))}`
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function clock(ts) {
|
|
320
|
+
if (typeof ts !== 'string' || ts.length < 16) return '--:--'
|
|
321
|
+
const date = new Date(ts)
|
|
322
|
+
if (Number.isNaN(date.getTime())) return '--:--'
|
|
323
|
+
const hh = String(date.getHours()).padStart(2, '0')
|
|
324
|
+
const mm = String(date.getMinutes()).padStart(2, '0')
|
|
325
|
+
return `${hh}:${mm}`
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function size(bytes) {
|
|
329
|
+
const value = Number(bytes)
|
|
330
|
+
if (!Number.isFinite(value) || value <= 0) return '0 B'
|
|
331
|
+
if (value < 1024) return `${value} B`
|
|
332
|
+
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`
|
|
333
|
+
return `${(value / 1024 / 1024).toFixed(1)} MB`
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function groupEntries(entries) {
|
|
337
|
+
const groups = new Map()
|
|
338
|
+
for (const entry of entries) {
|
|
339
|
+
const key = typeof entry.sessionId === 'string' ? entry.sessionId : ''
|
|
340
|
+
let group = groups.get(key)
|
|
341
|
+
if (group === undefined) {
|
|
342
|
+
group = { key, title: '', workspace: '', sessionPath: '', count: 0, from: entry.ts, to: entry.ts, entries: [] }
|
|
343
|
+
groups.set(key, group)
|
|
344
|
+
}
|
|
345
|
+
group.count += 1
|
|
346
|
+
group.entries.push(entry)
|
|
347
|
+
if (!group.title && entry.sessionTitle) group.title = entry.sessionTitle
|
|
348
|
+
if (!group.workspace && entry.workspace) group.workspace = entry.workspace
|
|
349
|
+
if (!group.sessionPath && entry.sessionPath) group.sessionPath = entry.sessionPath
|
|
350
|
+
if (typeof entry.ts === 'string' && entry.ts) {
|
|
351
|
+
if (!group.from || entry.ts < group.from) group.from = entry.ts
|
|
352
|
+
if (!group.to || entry.ts > group.to) group.to = entry.ts
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return [...groups.values()]
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Group by topic label, mirroring the host: a topic id is per session, so
|
|
360
|
+
* ids cannot be the key; untagged entries stay per session instead of
|
|
361
|
+
* collapsing every older record into one anonymous group.
|
|
362
|
+
*/
|
|
363
|
+
function groupByTopic(entries, t) {
|
|
364
|
+
const keyOf = (entry) => {
|
|
365
|
+
const label = typeof entry.topic === 'string' ? entry.topic : ''
|
|
366
|
+
if (label) return `#${label.toLowerCase().replace(/[\s,。、,.::;;!!??"'“”‘’()()【】\[\]<>《》\-—_/\\|]+/g, '')}`
|
|
367
|
+
return `#untagged#${entry.sessionId || ''}`
|
|
368
|
+
}
|
|
369
|
+
const groups = new Map()
|
|
370
|
+
for (const entry of entries) {
|
|
371
|
+
const key = keyOf(entry)
|
|
372
|
+
const topic = typeof entry.topic === 'string' ? entry.topic : ''
|
|
373
|
+
let group = groups.get(key)
|
|
374
|
+
if (group === undefined) {
|
|
375
|
+
group = { key, topic, title: topic || t('topic.untagged'), count: 0, from: entry.ts, to: entry.ts, sessions: [], entries: [] }
|
|
376
|
+
groups.set(key, group)
|
|
377
|
+
}
|
|
378
|
+
group.count += 1
|
|
379
|
+
group.entries.push(entry)
|
|
380
|
+
if (!group.topic && topic) group.topic = topic
|
|
381
|
+
const sessionId = entry.sessionId || ''
|
|
382
|
+
let session = group.sessions.find((item) => item.sessionId === sessionId)
|
|
383
|
+
if (session === undefined) {
|
|
384
|
+
session = { sessionId, sessionTitle: '', count: 0 }
|
|
385
|
+
group.sessions.push(session)
|
|
386
|
+
}
|
|
387
|
+
session.count += 1
|
|
388
|
+
if (!session.sessionTitle && entry.sessionTitle) session.sessionTitle = entry.sessionTitle
|
|
389
|
+
if (typeof entry.ts === 'string' && entry.ts) {
|
|
390
|
+
if (!group.from || entry.ts < group.from) group.from = entry.ts
|
|
391
|
+
if (!group.to || entry.ts > group.to) group.to = entry.ts
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return [...groups.values()].sort((left, right) => {
|
|
395
|
+
if (!left.topic !== !right.topic) return left.topic ? -1 : 1
|
|
396
|
+
return String(right.to).localeCompare(String(left.to))
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Model and prompt settings. The host lists the routes it knows; nothing here
|
|
402
|
+
* carries a credential, only provider/model ids the host already has.
|
|
403
|
+
*/
|
|
404
|
+
function SettingsPanel(props) {
|
|
405
|
+
const t = props.t
|
|
406
|
+
const settings = props.settings
|
|
407
|
+
const [primary, setPrimary] = React.useState('')
|
|
408
|
+
const [secondary, setSecondary] = React.useState('')
|
|
409
|
+
const [promptPrimary, setPromptPrimary] = React.useState('')
|
|
410
|
+
const [promptSecondary, setPromptSecondary] = React.useState('')
|
|
411
|
+
const [hydrated, setHydrated] = React.useState(false)
|
|
412
|
+
|
|
413
|
+
React.useEffect(() => {
|
|
414
|
+
if (settings === null || hydrated) return
|
|
415
|
+
const selected = settings.selected || {}
|
|
416
|
+
setPrimary(selected.provider && selected.model ? `${selected.provider}::${selected.model}` : '')
|
|
417
|
+
setSecondary(
|
|
418
|
+
selected.compareProvider && selected.compareModel
|
|
419
|
+
? `${selected.compareProvider}::${selected.compareModel}`
|
|
420
|
+
: (settings.local && settings.local.enabled ? 'local' : ''),
|
|
421
|
+
)
|
|
422
|
+
const builtin = settings.builtinPrompts || {}
|
|
423
|
+
setPromptPrimary((settings.prompts && settings.prompts.primary) || builtin.primary || '')
|
|
424
|
+
setPromptSecondary((settings.prompts && settings.prompts.secondary) || builtin.secondary || '')
|
|
425
|
+
setHydrated(true)
|
|
426
|
+
}, [settings, hydrated])
|
|
427
|
+
|
|
428
|
+
const routes = []
|
|
429
|
+
for (const provider of settings ? settings.providers || [] : []) {
|
|
430
|
+
for (const model of (settings.models && settings.models[provider.id]) || []) {
|
|
431
|
+
routes.push({ key: `${provider.id}::${model.id}`, label: `${provider.name || provider.id} · ${model.name || model.id}` })
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const builtin = (settings && settings.builtinPrompts) || {}
|
|
436
|
+
/** Grow the box to the text instead of hiding it behind an inner scrollbar. */
|
|
437
|
+
const rowsFor = (text, min) => Math.min(40, Math.max(min, String(text).split('\n').length))
|
|
438
|
+
const save = () => {
|
|
439
|
+
// Saving the untouched built-in keeps following future improvements; an
|
|
440
|
+
// edited prompt is stored as the user's own.
|
|
441
|
+
const patch = {
|
|
442
|
+
promptPrimary: promptPrimary.trim() === (builtin.primary || '').trim() ? '' : promptPrimary,
|
|
443
|
+
promptSecondary: promptSecondary.trim() === (builtin.secondary || '').trim() ? '' : promptSecondary,
|
|
444
|
+
}
|
|
445
|
+
if (primary === '') {
|
|
446
|
+
patch.provider = ''
|
|
447
|
+
patch.model = ''
|
|
448
|
+
} else {
|
|
449
|
+
const [provider, model] = primary.split('::')
|
|
450
|
+
patch.provider = provider
|
|
451
|
+
patch.model = model
|
|
452
|
+
}
|
|
453
|
+
if (secondary === 'local') {
|
|
454
|
+
patch.compareProvider = ''
|
|
455
|
+
patch.compareModel = ''
|
|
456
|
+
patch.ollama = true
|
|
457
|
+
} else if (secondary === '') {
|
|
458
|
+
patch.compareProvider = ''
|
|
459
|
+
patch.compareModel = ''
|
|
460
|
+
patch.ollama = false
|
|
461
|
+
} else {
|
|
462
|
+
const [provider, model] = secondary.split('::')
|
|
463
|
+
patch.compareProvider = provider
|
|
464
|
+
patch.compareModel = model
|
|
465
|
+
patch.ollama = false
|
|
466
|
+
}
|
|
467
|
+
props.onSave(patch)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return h('div', { className: 'wl-settings' },
|
|
471
|
+
h('div', { className: 'wl-settings-head' },
|
|
472
|
+
h('span', { className: 'wl-settings-title' }, t('settings.title')),
|
|
473
|
+
h('button', { type: 'button', className: 'wl-btn', onClick: props.onClose }, t('settings.close'))),
|
|
474
|
+
settings === null
|
|
475
|
+
? h('p', { className: 'wl-hint-sm' }, props.error || t('settings.loading'))
|
|
476
|
+
: h(React.Fragment, null,
|
|
477
|
+
h('label', { className: 'wl-settings-row' },
|
|
478
|
+
h('span', { className: 'wl-settings-k' }, t('settings.primary')),
|
|
479
|
+
h('select', {
|
|
480
|
+
className: 'wl-select',
|
|
481
|
+
value: primary,
|
|
482
|
+
onChange: (event) => setPrimary(event.target.value),
|
|
483
|
+
},
|
|
484
|
+
h('option', { value: '' }, t('settings.hostDefault')),
|
|
485
|
+
routes.map((route) => h('option', { key: route.key, value: route.key }, route.label))),
|
|
486
|
+
h('span', { className: 'wl-hint-sm' },
|
|
487
|
+
settings.effective && settings.effective.model
|
|
488
|
+
? `${t('settings.effective')} ${settings.effective.model}`
|
|
489
|
+
: t('settings.effectiveUnknown'))),
|
|
490
|
+
h('label', { className: 'wl-settings-row' },
|
|
491
|
+
h('span', { className: 'wl-settings-k' }, t('settings.secondary')),
|
|
492
|
+
h('select', {
|
|
493
|
+
className: 'wl-select',
|
|
494
|
+
value: secondary,
|
|
495
|
+
onChange: (event) => setSecondary(event.target.value),
|
|
496
|
+
},
|
|
497
|
+
h('option', { value: '' }, t('settings.off')),
|
|
498
|
+
settings.local ? h('option', { value: 'local' }, `${t('settings.local')} ${settings.local.model || ''}`.trim()) : null,
|
|
499
|
+
routes.map((route) => h('option', { key: route.key, value: route.key }, route.label)))),
|
|
500
|
+
h('label', { className: 'wl-settings-row wl-settings-col' },
|
|
501
|
+
h('span', { className: 'wl-settings-k' }, t('settings.promptPrimary')),
|
|
502
|
+
h('textarea', {
|
|
503
|
+
className: 'wl-textarea',
|
|
504
|
+
rows: rowsFor(promptPrimary, 4),
|
|
505
|
+
value: promptPrimary,
|
|
506
|
+
placeholder: t('settings.promptPlaceholder'),
|
|
507
|
+
onChange: (event) => setPromptPrimary(event.target.value),
|
|
508
|
+
})),
|
|
509
|
+
h('label', { className: 'wl-settings-row wl-settings-col' },
|
|
510
|
+
h('span', { className: 'wl-settings-k' }, t('settings.promptSecondary')),
|
|
511
|
+
h('textarea', {
|
|
512
|
+
className: 'wl-textarea',
|
|
513
|
+
rows: rowsFor(promptSecondary, 4),
|
|
514
|
+
value: promptSecondary,
|
|
515
|
+
placeholder: t('settings.promptPlaceholder'),
|
|
516
|
+
onChange: (event) => setPromptSecondary(event.target.value),
|
|
517
|
+
})),
|
|
518
|
+
h('p', { className: 'wl-hint-sm' }, t('settings.hint')),
|
|
519
|
+
props.error ? h('p', { className: 'wl-note', 'data-tone': 'err' }, props.error) : null,
|
|
520
|
+
h('div', { className: 'wl-settings-actions' },
|
|
521
|
+
h('button', {
|
|
522
|
+
type: 'button',
|
|
523
|
+
className: 'wl-btn',
|
|
524
|
+
onClick: () => { setPromptPrimary(builtin.primary || ''); setPromptSecondary(builtin.secondary || '') },
|
|
525
|
+
}, t('settings.restore')),
|
|
526
|
+
h('button', { type: 'button', className: 'wl-btn', disabled: props.busy, onClick: save }, props.busy ? t('settings.saving') : t('settings.save')))),
|
|
527
|
+
)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Topic timeline for one day.
|
|
532
|
+
*
|
|
533
|
+
* A bar spans a topic's first to last record, which is the only honest
|
|
534
|
+
* measure available: between two records of one topic the session may have
|
|
535
|
+
* been doing something else, or nothing at all. The footer reports the union
|
|
536
|
+
* of all spans so overlapping sessions do not double count.
|
|
537
|
+
*/
|
|
538
|
+
/**
|
|
539
|
+
* Topic timeline for one day.
|
|
540
|
+
*
|
|
541
|
+
* A turn owns the time from its own record until the next one in the same
|
|
542
|
+
* session — that is the only span the log can actually justify, and it makes
|
|
543
|
+
* a topic read as a block instead of a pin. Gaps longer than GAP_CAP are
|
|
544
|
+
* treated as leaving the topic, otherwise an idle afternoon would be charged
|
|
545
|
+
* to whatever was last touched. A topic that is revisited shows as several
|
|
546
|
+
* segments on one row, because merging them into one bar would claim time it
|
|
547
|
+
* did not have.
|
|
548
|
+
*/
|
|
549
|
+
function Gantt(props) {
|
|
550
|
+
const t = props.t
|
|
551
|
+
const day = props.day
|
|
552
|
+
const entries = Array.isArray(props.entries) ? props.entries : []
|
|
553
|
+
const GAP_CAP = 45 * 60 * 1000
|
|
554
|
+
// One day is drawn at 6 px/min (an hour is 360 px); a range falls back to a
|
|
555
|
+
// per-day scale, otherwise a week would be a 60 000 px canvas.
|
|
556
|
+
const span = props.range && props.range.from ? props.range : { from: day, to: day }
|
|
557
|
+
const rangeStart = new Date(`${span.from}T00:00:00`).getTime()
|
|
558
|
+
const rangeEnd = new Date(`${span.to}T00:00:00`).getTime() + 86400000
|
|
559
|
+
const spanMs = Math.max(3600000, rangeEnd - rangeStart)
|
|
560
|
+
const singleDay = spanMs <= 2 * 86400000
|
|
561
|
+
const pxPerMs = singleDay ? 6 / 60000 : 90 / 86400000
|
|
562
|
+
const trackWidth = Math.max(720, Math.round(spanMs * pxPerMs))
|
|
563
|
+
const [hover, setHover] = React.useState(null)
|
|
564
|
+
const now = Number.isFinite(props.now) ? props.now : Date.now()
|
|
565
|
+
const live = Boolean(props.live && props.live.tracked > 0)
|
|
566
|
+
|
|
567
|
+
const bySession = new Map()
|
|
568
|
+
for (const entry of entries) {
|
|
569
|
+
if (typeof entry.ts !== 'string' || entry.ts === '') continue
|
|
570
|
+
const id = entry.sessionId || ''
|
|
571
|
+
if (!bySession.has(id)) bySession.set(id, [])
|
|
572
|
+
bySession.get(id).push(entry)
|
|
573
|
+
}
|
|
574
|
+
let newestSession = ''
|
|
575
|
+
let newestTs = ''
|
|
576
|
+
for (const [id, list] of bySession) {
|
|
577
|
+
const last = list.reduce((best, entry) => (entry.ts > best ? entry.ts : best), '')
|
|
578
|
+
if (last > newestTs) {
|
|
579
|
+
newestTs = last
|
|
580
|
+
newestSession = id
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// Sessions are the outer level: a topic id is only unique inside its
|
|
585
|
+
// session, and a person reads "which session, which topic" before anything
|
|
586
|
+
// else. Topics therefore never merge across sessions here.
|
|
587
|
+
const blocks = []
|
|
588
|
+
for (const [sessionId, list] of bySession) {
|
|
589
|
+
list.sort((left, right) => String(left.ts).localeCompare(String(right.ts)))
|
|
590
|
+
const block = { sessionId, title: '', summary: '', topics: new Map(), first: 0, last: 0, segments: [] }
|
|
591
|
+
for (const [index, entry] of list.entries()) {
|
|
592
|
+
const start = new Date(entry.ts).getTime()
|
|
593
|
+
if (!Number.isFinite(start)) continue
|
|
594
|
+
if (!block.title && entry.sessionTitle) block.title = String(entry.sessionTitle)
|
|
595
|
+
if (!block.summary && typeof entry.summary === 'string') block.summary = entry.summary
|
|
596
|
+
if (!block.first || start < block.first) block.first = start
|
|
597
|
+
if (start > block.last) block.last = start
|
|
598
|
+
const topic = typeof entry.topic === 'string' ? entry.topic.trim() : ''
|
|
599
|
+
if (topic === '') continue
|
|
600
|
+
const next = index + 1 < list.length ? new Date(list[index + 1].ts).getTime() : Number.NaN
|
|
601
|
+
let stop
|
|
602
|
+
if (Number.isFinite(next)) stop = Math.min(next, start + GAP_CAP)
|
|
603
|
+
else if (live && sessionId === newestSession) stop = Math.min(now, start + GAP_CAP)
|
|
604
|
+
else stop = start
|
|
605
|
+
const key = topic.toLowerCase().replace(/[\s,。、,.::;;!!??"'“”‘’()()【】\[\]<>《》\-—_/\\|]+/g, '')
|
|
606
|
+
let row = block.topics.get(key)
|
|
607
|
+
if (row === undefined) {
|
|
608
|
+
row = { key: `${sessionId}#${key}`, topic, segments: [], turns: 0, first: start, total: 0, ongoing: false }
|
|
609
|
+
block.topics.set(key, row)
|
|
610
|
+
}
|
|
611
|
+
row.turns += 1
|
|
612
|
+
row.total += Math.max(0, stop - start)
|
|
613
|
+
if (start < row.first) row.first = start
|
|
614
|
+
// Nothing can have happened after this moment; a later timestamp is clock
|
|
615
|
+
// skew between host and browser, and drawing it past "now" reads as a bug.
|
|
616
|
+
if (stop > now) stop = now
|
|
617
|
+
if (stop > start) row.segments.push([start, stop, typeof entry.summary === 'string' ? entry.summary : ''])
|
|
618
|
+
if (!Number.isFinite(next) && live && sessionId === newestSession) row.ongoing = true
|
|
619
|
+
}
|
|
620
|
+
if (block.topics.size > 0) {
|
|
621
|
+
block.topics = [...block.topics.values()].sort((left, right) => left.first - right.first)
|
|
622
|
+
blocks.push(block)
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
blocks.sort((left, right) => left.first - right.first)
|
|
626
|
+
const rows = blocks.flatMap((block) => block.topics)
|
|
627
|
+
const list = blocks
|
|
628
|
+
const flat = rows
|
|
629
|
+
|
|
630
|
+
/** clock() wants an ISO string; the timeline works in epoch ms. */
|
|
631
|
+
const stamp = (ms) => new Date(ms).toISOString()
|
|
632
|
+
const clip = (text, max) => (String(text).length <= max ? String(text) : `${String(text).slice(0, max - 1)}…`)
|
|
633
|
+
/**
|
|
634
|
+
* Hover text: topic, span, then the line this turn earned. Native titles
|
|
635
|
+
* keep it dependency-free and work with a trackpad as well as a mouse.
|
|
636
|
+
*/
|
|
637
|
+
const tip = (title, from, to, summary) => [
|
|
638
|
+
title,
|
|
639
|
+
`${clock(stamp(from))}–${clock(stamp(to))} · ${fmtDuration(t, to - from)}`,
|
|
640
|
+
summary ? clip(summary, 160) : '',
|
|
641
|
+
].filter(Boolean).join('\n')
|
|
642
|
+
// Accepts a timestamp string or an epoch number.
|
|
643
|
+
const x = (value) => {
|
|
644
|
+
const at = typeof value === 'number' ? value : new Date(value).getTime()
|
|
645
|
+
return Math.max(0, Math.min(trackWidth, (at - rangeStart) * pxPerMs))
|
|
646
|
+
}
|
|
647
|
+
// Opening at 00:00 would hide everything the user came to see.
|
|
648
|
+
const scrollRef = React.useRef(null)
|
|
649
|
+
React.useEffect(() => {
|
|
650
|
+
const element = scrollRef.current
|
|
651
|
+
if (element === null) return
|
|
652
|
+
const lastEnd = flat.reduce((best, row) => Math.max(best, ...row.segments.map((segment) => segment[1]), row.first), rangeStart)
|
|
653
|
+
element.scrollLeft = Math.max(0, LABEL_W + x(lastEnd) - element.clientWidth * 0.72)
|
|
654
|
+
}, [])
|
|
655
|
+
|
|
656
|
+
// Everything starts expanded; the header still collapses a session when the
|
|
657
|
+
// day gets long. `null` means "no explicit choice yet".
|
|
658
|
+
const [expanded, setExpanded] = React.useState(null)
|
|
659
|
+
const allIds = blocks.map((block) => block.sessionId)
|
|
660
|
+
const isOpen = (block) => (expanded === null ? true : expanded.has(block.sessionId))
|
|
661
|
+
const toggleBlock = (block) => {
|
|
662
|
+
setExpanded((previous) => {
|
|
663
|
+
const next = new Set(previous === null ? allIds : previous)
|
|
664
|
+
if (next.has(block.sessionId)) next.delete(block.sessionId)
|
|
665
|
+
else next.add(block.sessionId)
|
|
666
|
+
return next
|
|
667
|
+
})
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (list.length === 0) {
|
|
671
|
+
return h('div', { className: 'wl-empty' }, t('gantt.empty'), h('p', { className: 'wl-empty-hint' }, t('topic.hint')))
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const ticks = []
|
|
675
|
+
if (singleDay) {
|
|
676
|
+
for (let hour = 0; hour < 24; hour += 1) {
|
|
677
|
+
ticks.push(h('span', {
|
|
678
|
+
className: 'wl-gantt-tick',
|
|
679
|
+
key: hour,
|
|
680
|
+
'data-major': hour % 2 === 0 ? 'true' : 'false',
|
|
681
|
+
style: { left: `${hour * 60 * 60000 * pxPerMs}px` },
|
|
682
|
+
}, String(hour).padStart(2, '0')))
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
const days = Math.round(spanMs / 86400000)
|
|
686
|
+
const step = Math.max(1, Math.ceil(days / 24))
|
|
687
|
+
for (let index = 0; index < days; index += step) {
|
|
688
|
+
const at = rangeStart + index * 86400000
|
|
689
|
+
ticks.push(h('span', {
|
|
690
|
+
className: 'wl-gantt-tick',
|
|
691
|
+
key: at,
|
|
692
|
+
'data-major': 'true',
|
|
693
|
+
style: { left: `${index * 86400000 * pxPerMs}px` },
|
|
694
|
+
}, `${String(new Date(at).getMonth() + 1).padStart(2, '0')}-${String(new Date(at).getDate()).padStart(2, '0')}`))
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
const merged = (() => {
|
|
698
|
+
const spans = flat.flatMap((row) => row.segments).sort((left, right) => left[0] - right[0])
|
|
699
|
+
let total = 0
|
|
700
|
+
let cursor = -Infinity
|
|
701
|
+
let end = -Infinity
|
|
702
|
+
for (const [from, to] of spans) {
|
|
703
|
+
if (from > end) {
|
|
704
|
+
if (end > cursor) total += end - cursor
|
|
705
|
+
cursor = from
|
|
706
|
+
end = to
|
|
707
|
+
} else if (to > end) {
|
|
708
|
+
end = to
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (end > cursor) total += end - cursor
|
|
712
|
+
return total
|
|
713
|
+
})()
|
|
714
|
+
const elapsed = Math.max(1, Math.min(now, rangeEnd) - rangeStart)
|
|
715
|
+
|
|
716
|
+
return h('div', { className: 'wl-gantt', ref: scrollRef },
|
|
717
|
+
h('div', { className: 'wl-gantt-canvas', style: { width: `${LABEL_W + trackWidth}px` } },
|
|
718
|
+
h('div', { className: 'wl-gantt-row wl-gantt-axis' },
|
|
719
|
+
h('span', { className: 'wl-gantt-label' }, t('gantt.time')),
|
|
720
|
+
h('span', { className: 'wl-gantt-track', style: { width: `${trackWidth}px`, backgroundSize: `${singleDay ? 360 : 90}px 100%` } }, ticks),
|
|
721
|
+
),
|
|
722
|
+
blocks.map((block) => h(React.Fragment, { key: block.sessionId },
|
|
723
|
+
h('div', {
|
|
724
|
+
className: 'wl-gantt-row wl-gantt-session',
|
|
725
|
+
role: 'button',
|
|
726
|
+
tabIndex: 0,
|
|
727
|
+
'aria-expanded': isOpen(block) ? 'true' : 'false',
|
|
728
|
+
onClick: () => toggleBlock(block),
|
|
729
|
+
onKeyDown: (event) => {
|
|
730
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
731
|
+
event.preventDefault()
|
|
732
|
+
toggleBlock(block)
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
h('span', {
|
|
737
|
+
className: 'wl-gantt-label',
|
|
738
|
+
title: tip(
|
|
739
|
+
`${block.title || t('gantt.untitled')} · ${fmt(t, 'gantt.topicCount', { n: block.topics.length })}`,
|
|
740
|
+
block.first,
|
|
741
|
+
block.last,
|
|
742
|
+
block.summary,
|
|
743
|
+
),
|
|
744
|
+
onMouseEnter: (event) => {
|
|
745
|
+
const box = event.currentTarget.getBoundingClientRect()
|
|
746
|
+
setHover({
|
|
747
|
+
text: tip(`${block.title || t('gantt.untitled')} · ${fmt(t, 'gantt.topicCount', { n: block.topics.length })}`, block.first, block.last, block.summary),
|
|
748
|
+
x: box.left + 120,
|
|
749
|
+
y: box.top + box.height,
|
|
750
|
+
})
|
|
751
|
+
},
|
|
752
|
+
onMouseLeave: () => setHover(null),
|
|
753
|
+
},
|
|
754
|
+
h('span', { className: 'wl-gantt-name' },
|
|
755
|
+
`${isOpen(block) ? '▾' : '▸'} ${block.title || t('gantt.untitled')}`),
|
|
756
|
+
h('span', { className: 'wl-gantt-meta' }, fmt(t, 'gantt.topicCount', { n: block.topics.length }))),
|
|
757
|
+
h('span', { className: 'wl-gantt-track', style: { width: `${trackWidth}px`, backgroundSize: `${singleDay ? 360 : 90}px 100%` } },
|
|
758
|
+
Math.min(block.last, now) > block.first
|
|
759
|
+
? h('span', {
|
|
760
|
+
className: 'wl-gantt-band',
|
|
761
|
+
style: {
|
|
762
|
+
left: `${x(block.first)}px`,
|
|
763
|
+
width: `${Math.max(3, x(Math.min(block.last, now)) - x(block.first))}px`,
|
|
764
|
+
},
|
|
765
|
+
})
|
|
766
|
+
: null)),
|
|
767
|
+
(isOpen(block) ? block.topics : []).map((row) => h('div', { className: 'wl-gantt-row wl-gantt-topic', key: row.key },
|
|
768
|
+
h('span', {
|
|
769
|
+
className: 'wl-gantt-label',
|
|
770
|
+
title: tip(`${row.topic} · ${row.turns}`, row.first, row.first + row.total, row.segments[0] ? row.segments[0][2] : ''),
|
|
771
|
+
},
|
|
772
|
+
h('span', { className: 'wl-gantt-name' }, row.topic),
|
|
773
|
+
h('span', { className: 'wl-gantt-meta' }, fmtDuration(t, row.total))),
|
|
774
|
+
h('span', { className: 'wl-gantt-track', style: { width: `${trackWidth}px`, backgroundSize: `${singleDay ? 360 : 90}px 100%` } },
|
|
775
|
+
row.segments.length === 0
|
|
776
|
+
? h('span', {
|
|
777
|
+
className: 'wl-gantt-bar',
|
|
778
|
+
'data-ongoing': row.ongoing ? 'true' : 'false',
|
|
779
|
+
style: { left: `${x(Math.min(row.first, now))}px`, width: '3px' },
|
|
780
|
+
title: tip(row.topic, row.first, row.first, '')
|
|
781
|
+
})
|
|
782
|
+
: row.segments.map((segment, index) => h('span', {
|
|
783
|
+
className: 'wl-gantt-bar',
|
|
784
|
+
'data-ongoing': row.ongoing && index === row.segments.length - 1 ? 'true' : 'false',
|
|
785
|
+
key: segment[0],
|
|
786
|
+
style: { left: `${x(segment[0])}px`, width: `${Math.max(3, x(segment[1]) - x(segment[0]))}px` },
|
|
787
|
+
title: tip(row.topic, segment[0], segment[1], segment[2]),
|
|
788
|
+
}))),
|
|
789
|
+
)),
|
|
790
|
+
)),
|
|
791
|
+
hover === null ? null : h('div', {
|
|
792
|
+
className: 'wl-gantt-tip',
|
|
793
|
+
style: { left: `${hover.x}px`, top: `${hover.y}px` },
|
|
794
|
+
}, hover.text),
|
|
795
|
+
now > rangeStart && now < rangeEnd
|
|
796
|
+
? h('span', { className: 'wl-gantt-now', style: { left: `${LABEL_W + x(now)}px` } },
|
|
797
|
+
h('span', { className: 'wl-gantt-now-label' }, t('gantt.nowLine')))
|
|
798
|
+
: null,
|
|
799
|
+
),
|
|
800
|
+
h('div', { className: 'wl-gantt-foot' },
|
|
801
|
+
fmt(t, 'gantt.foot', {
|
|
802
|
+
n: flat.length,
|
|
803
|
+
covered: fmtDuration(t, merged),
|
|
804
|
+
share: merged === 0 ? 0 : Math.round((merged / elapsed) * 100),
|
|
805
|
+
})),
|
|
806
|
+
)
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const LABEL_W = 180
|
|
810
|
+
|
|
811
|
+
/** `1h 20m` / `35m`, deliberately short: it sits under the topic name. */
|
|
812
|
+
function fmtDuration(t, ms) {
|
|
813
|
+
const minutes = Math.max(0, Math.round(ms / 60000))
|
|
814
|
+
if (minutes < 1) return t('gantt.underMinute')
|
|
815
|
+
const hours = Math.floor(minutes / 60)
|
|
816
|
+
return hours === 0 ? `${minutes}m` : `${hours}h ${minutes % 60}m`
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function Styles() {
|
|
820
|
+
return h('style', { 'data-dsh-worklog': 'style' }, CSS)
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function TabIcon(props) {
|
|
824
|
+
const scale = props && props.size === 'inline' ? 1.2 : 1.8
|
|
825
|
+
return h('svg', {
|
|
826
|
+
viewBox: '0 0 16 16',
|
|
827
|
+
width: 16,
|
|
828
|
+
height: 16,
|
|
829
|
+
fill: 'none',
|
|
830
|
+
stroke: 'currentColor',
|
|
831
|
+
strokeWidth: scale,
|
|
832
|
+
strokeLinecap: 'round',
|
|
833
|
+
strokeLinejoin: 'round',
|
|
834
|
+
'aria-hidden': 'true',
|
|
835
|
+
},
|
|
836
|
+
h('path', { d: 'M4.5 2.4h4.6L12 5.3v8.3H4.5z' }),
|
|
837
|
+
h('path', { d: 'M9 2.5v3h2.9' }),
|
|
838
|
+
h('path', { d: 'M6.2 8.6h4' }),
|
|
839
|
+
h('path', { d: 'M6.2 11h2.6' }),
|
|
840
|
+
)
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const KIND_LABELS = { turn: 'kind.turn', note: 'kind.note', tool: 'kind.tool' }
|
|
844
|
+
|
|
845
|
+
function kindLabel(t, kind) {
|
|
846
|
+
const key = KIND_LABELS[kind]
|
|
847
|
+
return key ? t(key) : String(kind || '')
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* A clamped paragraph that opens on click. `title` alone is not enough: the
|
|
852
|
+
* native tooltip needs a hover delay and never fires on touch.
|
|
853
|
+
*/
|
|
854
|
+
function Expandable(props) {
|
|
855
|
+
const [open, setOpen] = React.useState(false)
|
|
856
|
+
const long = props.text.length > 90
|
|
857
|
+
return h('span', {
|
|
858
|
+
className: 'wl-ai-text',
|
|
859
|
+
'data-open': open ? 'true' : 'false',
|
|
860
|
+
'data-expandable': long ? 'true' : 'false',
|
|
861
|
+
title: long ? (open ? props.t('action.collapse') : props.t('action.expand')) : undefined,
|
|
862
|
+
role: long ? 'button' : undefined,
|
|
863
|
+
tabIndex: long ? 0 : undefined,
|
|
864
|
+
onClick: long ? () => setOpen(!open) : undefined,
|
|
865
|
+
onKeyDown: long
|
|
866
|
+
? (event) => {
|
|
867
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
868
|
+
event.preventDefault()
|
|
869
|
+
setOpen(!open)
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
: undefined,
|
|
873
|
+
}, props.text)
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function Item(props) {
|
|
877
|
+
const t = props.t
|
|
878
|
+
const entry = props.entry
|
|
879
|
+
const tools = Array.isArray(entry.tools) ? entry.tools : []
|
|
880
|
+
const files = Array.isArray(entry.files) ? entry.files : []
|
|
881
|
+
const summaries = entry.summaries && typeof entry.summaries === 'object' ? entry.summaries : null
|
|
882
|
+
const rows = []
|
|
883
|
+
// Slot labels come from the record when present, so a user-chosen model is
|
|
884
|
+
// named correctly instead of being called "deepseek" forever.
|
|
885
|
+
const labels = entry.summaryLabels && typeof entry.summaryLabels === 'object' ? entry.summaryLabels : {}
|
|
886
|
+
const primary = summaries === null ? '' : (summaries.primary ?? summaries.deepseek)
|
|
887
|
+
const secondary = summaries === null ? '' : (summaries.secondary ?? summaries.ollama)
|
|
888
|
+
if (typeof primary === 'string' && primary) rows.push([labels.primary || t('ai.primary'), primary])
|
|
889
|
+
if (typeof secondary === 'string' && secondary) rows.push([labels.secondary || t('ai.secondary'), secondary])
|
|
890
|
+
return h('li', { className: 'wl-item' },
|
|
891
|
+
h('div', { className: 'wl-item-head' },
|
|
892
|
+
h('span', { className: 'wl-time' }, clock(entry.ts)),
|
|
893
|
+
typeof entry.topic === 'string' && entry.topic
|
|
894
|
+
? h('span', { className: 'wl-topic', title: entry.topic }, entry.topic)
|
|
895
|
+
: null,
|
|
896
|
+
h('span', { className: 'wl-kind', 'data-kind': entry.kind }, kindLabel(t, entry.kind)),
|
|
897
|
+
),
|
|
898
|
+
rows.length > 0
|
|
899
|
+
? rows.map((row) => h('div', { className: 'wl-ai', key: row[0] },
|
|
900
|
+
h('span', { className: 'wl-ai-tag' }, row[0]),
|
|
901
|
+
h(Expandable, { t, text: row[1] })))
|
|
902
|
+
: h(React.Fragment, null,
|
|
903
|
+
h('p', { className: 'wl-summary' }, entry.summary),
|
|
904
|
+
typeof entry.answer === 'string' && entry.answer
|
|
905
|
+
? h('div', { className: 'wl-ai' },
|
|
906
|
+
h('span', { className: 'wl-ai-tag' }, t('ai.answer')),
|
|
907
|
+
h(Expandable, { t, text: entry.answer }))
|
|
908
|
+
: null),
|
|
909
|
+
h('div', { className: 'wl-meta' },
|
|
910
|
+
tools.length === 0
|
|
911
|
+
? h('span', null, t('meta.noTools'))
|
|
912
|
+
: tools.slice(0, 4).map((tool) => h('span', { className: 'wl-chip', key: tool }, tool)),
|
|
913
|
+
files.length > 0 ? h('span', null, fmt(t, 'meta.files', { n: files.length })) : null,
|
|
914
|
+
entry.agent ? h('span', null, `${t('meta.agent')} ${entry.agent}`) : null,
|
|
915
|
+
),
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function Panel(props) {
|
|
920
|
+
const t = typeof props.t === 'function' ? props.t : (key) => key
|
|
921
|
+
const [data, setData] = React.useState(null)
|
|
922
|
+
const [error, setError] = React.useState('')
|
|
923
|
+
const [notice, setNotice] = React.useState('')
|
|
924
|
+
const [busy, setBusy] = React.useState(false)
|
|
925
|
+
const [showSettings, setShowSettings] = React.useState(false)
|
|
926
|
+
const [settings, setSettings] = React.useState(null)
|
|
927
|
+
const [settingsError, setSettingsError] = React.useState('')
|
|
928
|
+
const [view, setView] = React.useState(() => {
|
|
929
|
+
try {
|
|
930
|
+
const saved = window.localStorage.getItem('dsh-worklog:view')
|
|
931
|
+
return saved === 'topic' || saved === 'gantt' ? saved : 'session'
|
|
932
|
+
} catch {
|
|
933
|
+
return 'session'
|
|
934
|
+
}
|
|
935
|
+
})
|
|
936
|
+
|
|
937
|
+
// The range the user is looking at; `null` means "whatever the host says".
|
|
938
|
+
const [range, setRange] = React.useState(null)
|
|
939
|
+
const [picking, setPicking] = React.useState(false)
|
|
940
|
+
const [draft, setDraft] = React.useState({ from: '', to: '' })
|
|
941
|
+
|
|
942
|
+
const load = React.useCallback(async (wanted) => {
|
|
943
|
+
const target = wanted === undefined ? range : wanted
|
|
944
|
+
const query = target === null ? '' : `?from=${target.from}&to=${target.to}`
|
|
945
|
+
try {
|
|
946
|
+
const response = await fetch(`${PANEL_ROUTE}${query}`, { credentials: 'same-origin', headers: { accept: 'application/json' } })
|
|
947
|
+
const payload = await response.json().catch(() => ({}))
|
|
948
|
+
if (!response.ok || payload.ok !== true) throw new Error(payload.error || `HTTP ${response.status}`)
|
|
949
|
+
setData(payload)
|
|
950
|
+
if (target === null && payload.range) setRange({ from: payload.range.from, to: payload.range.to })
|
|
951
|
+
setError('')
|
|
952
|
+
} catch (failure) {
|
|
953
|
+
setError(`${t('status.error')}:${failure instanceof Error ? failure.message : String(failure)}`)
|
|
954
|
+
}
|
|
955
|
+
}, [t, range])
|
|
956
|
+
|
|
957
|
+
React.useEffect(() => {
|
|
958
|
+
void load()
|
|
959
|
+
const timer = setInterval(() => {
|
|
960
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
961
|
+
void load()
|
|
962
|
+
}, POLL_MS)
|
|
963
|
+
return () => clearInterval(timer)
|
|
964
|
+
}, [load])
|
|
965
|
+
|
|
966
|
+
React.useEffect(() => {
|
|
967
|
+
if (!notice) return undefined
|
|
968
|
+
const timer = setTimeout(() => setNotice(''), 3000)
|
|
969
|
+
return () => clearTimeout(timer)
|
|
970
|
+
}, [notice])
|
|
971
|
+
|
|
972
|
+
const toggle = async () => {
|
|
973
|
+
if (busy || !data) return
|
|
974
|
+
const next = !data.enabled
|
|
975
|
+
setBusy(true)
|
|
976
|
+
try {
|
|
977
|
+
const response = await fetch(TOGGLE_ROUTE, {
|
|
978
|
+
method: 'POST',
|
|
979
|
+
credentials: 'same-origin',
|
|
980
|
+
headers: { 'content-type': 'application/json' },
|
|
981
|
+
body: JSON.stringify({ enabled: next }),
|
|
982
|
+
})
|
|
983
|
+
const payload = await response.json().catch(() => ({}))
|
|
984
|
+
if (!response.ok || payload.ok !== true) throw new Error(payload.error || `HTTP ${response.status}`)
|
|
985
|
+
setData(payload)
|
|
986
|
+
setError('')
|
|
987
|
+
setNotice(t('toast.saved'))
|
|
988
|
+
} catch (failure) {
|
|
989
|
+
setError(`${t('status.error')}:${failure instanceof Error ? failure.message : String(failure)}`)
|
|
990
|
+
} finally {
|
|
991
|
+
setBusy(false)
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
const shiftDay = (delta) => {
|
|
996
|
+
const base = range === null ? (data ? data.range : null) : range
|
|
997
|
+
if (base === null || base === undefined) return
|
|
998
|
+
const move = (day, step) => {
|
|
999
|
+
const date = new Date(`${day}T12:00:00`)
|
|
1000
|
+
date.setDate(date.getDate() + step)
|
|
1001
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
|
1002
|
+
}
|
|
1003
|
+
const span = (base.to && base.to !== base.from)
|
|
1004
|
+
? Math.max(1, Math.round((new Date(`${base.to}T12:00:00`) - new Date(`${base.from}T12:00:00`)) / 86400000))
|
|
1005
|
+
: 1
|
|
1006
|
+
const next = { from: move(base.from, delta * span), to: move(base.to || base.from, delta * span) }
|
|
1007
|
+
setRange(next)
|
|
1008
|
+
void load(next)
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const goToday = () => {
|
|
1012
|
+
if (data === null || data.range === undefined) return
|
|
1013
|
+
const next = { from: data.today, to: data.today }
|
|
1014
|
+
setRange(next)
|
|
1015
|
+
void load(next)
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const applyRange = () => {
|
|
1019
|
+
if (draft.from === '' || draft.to === '') return
|
|
1020
|
+
const next = draft.from <= draft.to ? { ...draft } : { from: draft.to, to: draft.from }
|
|
1021
|
+
setRange(next)
|
|
1022
|
+
setPicking(false)
|
|
1023
|
+
void load(next)
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const openSettings = async () => {
|
|
1027
|
+
setShowSettings(true)
|
|
1028
|
+
setSettingsError('')
|
|
1029
|
+
try {
|
|
1030
|
+
const response = await fetch(SETTINGS_ROUTE, { credentials: 'same-origin' })
|
|
1031
|
+
const payload = await response.json().catch(() => ({}))
|
|
1032
|
+
if (!response.ok || payload.ok !== true) throw new Error(payload.error || `HTTP ${response.status}`)
|
|
1033
|
+
setSettings(payload)
|
|
1034
|
+
} catch (failure) {
|
|
1035
|
+
setSettingsError(`${t('settings.error')}:${failure instanceof Error ? failure.message : String(failure)}`)
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
const saveSettings = async (patch) => {
|
|
1040
|
+
setBusy(true)
|
|
1041
|
+
setSettingsError('')
|
|
1042
|
+
try {
|
|
1043
|
+
const response = await fetch(SETTINGS_ROUTE, {
|
|
1044
|
+
method: 'POST',
|
|
1045
|
+
credentials: 'same-origin',
|
|
1046
|
+
headers: { 'content-type': 'application/json' },
|
|
1047
|
+
body: JSON.stringify(patch),
|
|
1048
|
+
})
|
|
1049
|
+
const payload = await response.json().catch(() => ({}))
|
|
1050
|
+
if (!response.ok || payload.ok !== true) throw new Error(payload.error || `HTTP ${response.status}`)
|
|
1051
|
+
setSettings(payload)
|
|
1052
|
+
setNotice(t('toast.saved'))
|
|
1053
|
+
await load()
|
|
1054
|
+
} catch (failure) {
|
|
1055
|
+
setSettingsError(`${t('settings.error')}:${failure instanceof Error ? failure.message : String(failure)}`)
|
|
1056
|
+
} finally {
|
|
1057
|
+
setBusy(false)
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
const pickView = (next) => {
|
|
1062
|
+
setView(next)
|
|
1063
|
+
try {
|
|
1064
|
+
window.localStorage.setItem('dsh-worklog:view', next)
|
|
1065
|
+
} catch {
|
|
1066
|
+
// A blocked storage only loses the preference, not the view.
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
const entries = data && Array.isArray(data.entries) ? data.entries : []
|
|
1071
|
+
const topicGroups = groupByTopic(entries, t)
|
|
1072
|
+
const groups = view === 'topic' ? topicGroups : groupEntries(entries)
|
|
1073
|
+
const topicCount = new Set(entries.map((entry) => (entry.topic || '').toLowerCase().trim()).filter(Boolean)).size
|
|
1074
|
+
const untaggedOnly = topicCount === 0 && entries.length > 0
|
|
1075
|
+
const count = data ? data.count : 0
|
|
1076
|
+
const enabled = Boolean(data && data.enabled)
|
|
1077
|
+
const live = data && data.live ? data.live : { tracked: 0, turns: [] }
|
|
1078
|
+
const config = data && data.config ? data.config : {}
|
|
1079
|
+
const ai = data && data.ai ? data.ai : null
|
|
1080
|
+
const engines = []
|
|
1081
|
+
const slotName = (slot) => (slot?.model && slot.model !== 'host default' ? slot.model : t('ai.hostDefault'))
|
|
1082
|
+
if (ai && ai.primary && ai.primary.enabled) engines.push(`${slotName(ai.primary)}${ai.primary.last && ai.primary.last.error ? ' ✕' : ''}`)
|
|
1083
|
+
if (ai && ai.secondary && ai.secondary.enabled) engines.push(`${slotName(ai.secondary)}${ai.secondary.last && ai.secondary.last.error ? ' ✕' : ''}`)
|
|
1084
|
+
|
|
1085
|
+
return h('div', { className: 'wl-root', style: VARS },
|
|
1086
|
+
h(Styles, null),
|
|
1087
|
+
h('div', { className: 'wl-head' },
|
|
1088
|
+
h(TabIcon, null),
|
|
1089
|
+
h('span', { className: 'wl-title' }, t('tab.title')),
|
|
1090
|
+
h('span', { className: 'wl-count' }, fmt(t, count === 1 ? 'head.countOne' : 'head.count', { n: count })),
|
|
1091
|
+
h('div', { className: 'wl-dates' },
|
|
1092
|
+
h('button', { type: 'button', className: 'wl-nav', 'aria-label': t('date.prev'), onClick: () => shiftDay(-1) }, '‹'),
|
|
1093
|
+
h('button', {
|
|
1094
|
+
type: 'button',
|
|
1095
|
+
className: 'wl-date',
|
|
1096
|
+
title: t('date.pick'),
|
|
1097
|
+
onClick: () => {
|
|
1098
|
+
const base = range || (data ? data.range : null) || { from: '', to: '' }
|
|
1099
|
+
setDraft({ from: base.from || '', to: base.to || base.from || '' })
|
|
1100
|
+
setPicking(!picking)
|
|
1101
|
+
},
|
|
1102
|
+
}, range === null || range.from === range.to
|
|
1103
|
+
? (range ? range.from : (data ? data.range.from : ''))
|
|
1104
|
+
: `${range.from} – ${range.to}`),
|
|
1105
|
+
h('button', { type: 'button', className: 'wl-nav', 'aria-label': t('date.next'), onClick: () => shiftDay(1) }, '›'),
|
|
1106
|
+
h('button', { type: 'button', className: 'wl-btn', onClick: goToday }, t('date.today'))),
|
|
1107
|
+
h('button', {
|
|
1108
|
+
type: 'button',
|
|
1109
|
+
className: 'wl-btn',
|
|
1110
|
+
'aria-expanded': picking ? 'true' : 'false',
|
|
1111
|
+
onClick: () => {
|
|
1112
|
+
const base = range || (data ? data.range : null) || { from: '', to: '' }
|
|
1113
|
+
setDraft({ from: base.from || '', to: base.to || base.from || '' })
|
|
1114
|
+
setPicking(!picking)
|
|
1115
|
+
},
|
|
1116
|
+
}, t('date.range')),
|
|
1117
|
+
),
|
|
1118
|
+
picking
|
|
1119
|
+
? h('div', { className: 'wl-range' },
|
|
1120
|
+
h('label', { className: 'wl-range-row' }, t('date.from'),
|
|
1121
|
+
h('input', {
|
|
1122
|
+
type: 'date',
|
|
1123
|
+
className: 'wl-input',
|
|
1124
|
+
value: draft.from,
|
|
1125
|
+
onChange: (event) => setDraft({ ...draft, from: event.target.value }),
|
|
1126
|
+
})),
|
|
1127
|
+
h('label', { className: 'wl-range-row' }, t('date.to'),
|
|
1128
|
+
h('input', {
|
|
1129
|
+
type: 'date',
|
|
1130
|
+
className: 'wl-input',
|
|
1131
|
+
value: draft.to,
|
|
1132
|
+
onChange: (event) => setDraft({ ...draft, to: event.target.value }),
|
|
1133
|
+
})),
|
|
1134
|
+
h('button', { type: 'button', className: 'wl-btn', onClick: applyRange }, t('date.apply')),
|
|
1135
|
+
h('button', { type: 'button', className: 'wl-btn', onClick: () => setPicking(false) }, t('date.cancel')))
|
|
1136
|
+
: null,
|
|
1137
|
+
showSettings ? null : h('div', { className: 'wl-bar' },
|
|
1138
|
+
h('div', { className: 'wl-views', role: 'group', 'aria-label': t('view.label') },
|
|
1139
|
+
h('button', {
|
|
1140
|
+
type: 'button',
|
|
1141
|
+
className: 'wl-view',
|
|
1142
|
+
'aria-pressed': view === 'gantt' ? 'true' : 'false',
|
|
1143
|
+
disabled: !data,
|
|
1144
|
+
onClick: () => pickView('gantt'),
|
|
1145
|
+
}, t('view.gantt')),
|
|
1146
|
+
h('button', {
|
|
1147
|
+
type: 'button',
|
|
1148
|
+
className: 'wl-view',
|
|
1149
|
+
'aria-pressed': view === 'session' ? 'true' : 'false',
|
|
1150
|
+
disabled: !data,
|
|
1151
|
+
onClick: () => pickView('session'),
|
|
1152
|
+
}, t('view.session')),
|
|
1153
|
+
h('button', {
|
|
1154
|
+
type: 'button',
|
|
1155
|
+
className: 'wl-view',
|
|
1156
|
+
'aria-pressed': view === 'topic' ? 'true' : 'false',
|
|
1157
|
+
disabled: !data,
|
|
1158
|
+
onClick: () => pickView('topic'),
|
|
1159
|
+
}, topicCount > 0 ? `${t('view.topic')} ${topicCount}` : t('view.topic')),
|
|
1160
|
+
),
|
|
1161
|
+
h('div', { className: 'wl-bar-right' },
|
|
1162
|
+
h('button', {
|
|
1163
|
+
type: 'button',
|
|
1164
|
+
className: 'wl-switch',
|
|
1165
|
+
role: 'switch',
|
|
1166
|
+
'aria-checked': enabled ? 'true' : 'false',
|
|
1167
|
+
'aria-label': t('switch.label'),
|
|
1168
|
+
title: `${t('switch.label')} — ${t(enabled ? 'switch.hintOn' : 'switch.hintOff')}`,
|
|
1169
|
+
disabled: busy || !data,
|
|
1170
|
+
onClick: toggle,
|
|
1171
|
+
}),
|
|
1172
|
+
h('button', {
|
|
1173
|
+
type: 'button',
|
|
1174
|
+
className: 'wl-btn',
|
|
1175
|
+
disabled: busy,
|
|
1176
|
+
onClick: () => { setBusy(true); void load().finally(() => setBusy(false)) },
|
|
1177
|
+
}, busy ? t('action.refreshing') : t('action.refresh')),
|
|
1178
|
+
h('button', {
|
|
1179
|
+
type: 'button',
|
|
1180
|
+
className: 'wl-btn',
|
|
1181
|
+
'aria-expanded': showSettings ? 'true' : 'false',
|
|
1182
|
+
onClick: () => { if (showSettings) setShowSettings(false); else void openSettings() },
|
|
1183
|
+
}, t('settings.open')),
|
|
1184
|
+
),
|
|
1185
|
+
),
|
|
1186
|
+
showSettings
|
|
1187
|
+
? h(SettingsPanel, { t, settings, error: settingsError, busy, onSave: saveSettings, onClose: () => setShowSettings(false) })
|
|
1188
|
+
: null,
|
|
1189
|
+
notice ? h('p', { className: 'wl-note', 'data-tone': 'ok' }, notice) : null,
|
|
1190
|
+
view === 'topic' && untaggedOnly ? h('p', { className: 'wl-note' }, t('topic.hint')) : null,
|
|
1191
|
+
error ? h('p', { className: 'wl-note', 'data-tone': 'err' }, `${error}\n${t('status.offline')}`) : null,
|
|
1192
|
+
showSettings
|
|
1193
|
+
? null
|
|
1194
|
+
: view === 'gantt'
|
|
1195
|
+
? h(Gantt, { t, entries, day: data ? data.range.from : '', range: data ? data.range : null, now: data && data.now ? new Date(data.now).getTime() : Date.now(), live })
|
|
1196
|
+
: entries.length === 0
|
|
1197
|
+
? h('div', { className: 'wl-list' },
|
|
1198
|
+
h('div', { className: 'wl-empty' },
|
|
1199
|
+
data ? t('list.empty') : t('status.loading'),
|
|
1200
|
+
h('p', { className: 'wl-empty-hint' }, t('list.emptyHint')),
|
|
1201
|
+
),
|
|
1202
|
+
)
|
|
1203
|
+
: h('div', { className: 'wl-list' },
|
|
1204
|
+
groups.map((group) => h('section', { className: 'wl-group', key: group.key || 'notes' },
|
|
1205
|
+
h('div', { className: 'wl-group-head' },
|
|
1206
|
+
h('span', { className: 'wl-group-title' },
|
|
1207
|
+
view === 'topic'
|
|
1208
|
+
? group.title
|
|
1209
|
+
: (group.title || (group.key ? `#${group.key.replace(/^session-/, '').slice(0, 8)}` : t('list.notes')))),
|
|
1210
|
+
h('span', { className: 'wl-group-meta' },
|
|
1211
|
+
`${group.count > 1 ? `${clock(group.from)}–${clock(group.to)}` : clock(group.to)} · ${fmt(t, 'meta.turns', { n: group.count })}`),
|
|
1212
|
+
),
|
|
1213
|
+
view === 'topic' && group.sessions.length > 0
|
|
1214
|
+
? h('div', { className: 'wl-group-sub' },
|
|
1215
|
+
h('span', { className: 'wl-group-k' }, t('group.session')),
|
|
1216
|
+
h('span', { className: 'wl-group-v' },
|
|
1217
|
+
group.sessions.length > 1
|
|
1218
|
+
? fmt(t, 'group.sessionCount', { n: group.sessions.length })
|
|
1219
|
+
: (group.sessions[0].sessionTitle || '—')),
|
|
1220
|
+
group.topic ? null : h('span', { className: 'wl-group-k' }, t('topic.untaggedWhy')))
|
|
1221
|
+
: null,
|
|
1222
|
+
group.workspace
|
|
1223
|
+
? h('div', { className: 'wl-group-sub', title: group.workspace },
|
|
1224
|
+
h('span', { className: 'wl-group-k' }, t('group.workspace')),
|
|
1225
|
+
h('span', { className: 'wl-group-v' }, tail(group.workspace, 48)))
|
|
1226
|
+
: null,
|
|
1227
|
+
group.sessionPath
|
|
1228
|
+
? h('div', { className: 'wl-group-sub', title: group.sessionPath },
|
|
1229
|
+
h('span', { className: 'wl-group-k' }, t('group.sessionFile')),
|
|
1230
|
+
h('span', { className: 'wl-group-v' }, tail(group.sessionPath, 56)))
|
|
1231
|
+
: null,
|
|
1232
|
+
h('ul', { className: 'wl-group-list' },
|
|
1233
|
+
group.entries.map((entry) => h(Item, { key: `${entry.ts}-${entry.sessionId}`, t, entry })),
|
|
1234
|
+
),
|
|
1235
|
+
)),
|
|
1236
|
+
h('div', { className: 'wl-end' }, fmt(t, 'list.end', { n: entries.length })),
|
|
1237
|
+
),
|
|
1238
|
+
showSettings ? null : h('div', { className: 'wl-foot' },
|
|
1239
|
+
h('span', { className: 'wl-foot-k' }, t('foot.path')),
|
|
1240
|
+
h('span', { className: 'wl-foot-v', title: data ? data.todayFile : '' }, config.storePath || '~/.dsh/worklog'),
|
|
1241
|
+
h('span', { className: 'wl-foot-k' }, t('foot.last')),
|
|
1242
|
+
h('span', { className: 'wl-foot-v' }, data && data.store && data.store.lastWrite ? data.store.lastWrite.replace('T', ' ').slice(0, 19) : '—'),
|
|
1243
|
+
h('span', { className: 'wl-foot-k' }, t('foot.size')),
|
|
1244
|
+
h('span', { className: 'wl-foot-v' }, data && data.store ? size(data.store.totalBytes) : '—'),
|
|
1245
|
+
h('span', { className: 'wl-foot-k' }, t('ai.label')),
|
|
1246
|
+
h('span', { className: 'wl-foot-v' }, engines.length > 0 ? engines.join(' + ') : t('ai.off')),
|
|
1247
|
+
// The build marker makes a cached bundle obvious at a glance.
|
|
1248
|
+
h('span', { className: 'wl-foot-v', style: { marginLeft: 'auto', opacity: 0.6 } }, `v${VERSION}`),
|
|
1249
|
+
),
|
|
1250
|
+
)
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
return {
|
|
1254
|
+
name: NS,
|
|
1255
|
+
version: VERSION,
|
|
1256
|
+
inject: ['slots', 'sidebarRightTabs', 'locale'],
|
|
1257
|
+
apply(ctx) {
|
|
1258
|
+
ctx.effect(() => ctx.locale.register(NS, COPY), 'worklog: dictionaries')
|
|
1259
|
+
const locale = ctx.locale
|
|
1260
|
+
const t = locale.bind(NS)
|
|
1261
|
+
|
|
1262
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
1263
|
+
id: TAB_ID,
|
|
1264
|
+
kind: TAB_KIND,
|
|
1265
|
+
priority: 'extension',
|
|
1266
|
+
title: () => t('tab.title'),
|
|
1267
|
+
guide: [{
|
|
1268
|
+
id: TAB_ID,
|
|
1269
|
+
order: 78,
|
|
1270
|
+
title: () => t('tab.title'),
|
|
1271
|
+
description: () => t('tab.desc'),
|
|
1272
|
+
icon: TabIcon,
|
|
1273
|
+
}],
|
|
1274
|
+
}), 'worklog: tab type')
|
|
1275
|
+
|
|
1276
|
+
function TabTitle() {
|
|
1277
|
+
return t('tab.title')
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
|
|
1281
|
+
name: 'sidebar.right.pane.tab.title',
|
|
1282
|
+
key: TAB_ID,
|
|
1283
|
+
}, TabTitle)), 'worklog: tab title')
|
|
1284
|
+
|
|
1285
|
+
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
1286
|
+
name: 'sidebar.right.pane.tab',
|
|
1287
|
+
key: TAB_ID,
|
|
1288
|
+
locale: NS,
|
|
1289
|
+
inject: () => ({ t }),
|
|
1290
|
+
}, Panel)), 'worklog: tab body')
|
|
1291
|
+
},
|
|
1292
|
+
}
|
|
1293
|
+
},
|
|
1294
|
+
})
|