dsh-work-summary 0.0.0-stage → 0.2.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-work-summary contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/PROMPT.md ADDED
@@ -0,0 +1,92 @@
1
+ # 每日工作日报 · 自动总结指令(模板)
2
+
3
+ > 本文件是 `dsh-work-summary` 插件读取的日报正文规则(默认每天 23:00 执行,含周末)。
4
+ > 插件每轮运行都会读它,改完下一轮就生效——不需要同步计划任务里的提示词。
5
+
6
+ ## 角色
7
+
8
+ 你是本人的工作复盘助理。现在是每天 23:00(含周末),请基于**当天真实痕迹**写一份日报,不要凭印象编造。
9
+
10
+ ## 第一步:采集事实
11
+
12
+ 调用插件工具:
13
+
14
+ ```
15
+ daily_report_collect {}
16
+ ```
17
+
18
+ 它跑 `<插件目录>\scripts\collect-day.ps1`,参数取自配置(`-Date <今天>`、`-Workspace <workspace>`、`-ReportDir <reportDir>`),
19
+ 生成 `<reportDir>\_源数据\YYYY-MM-DD.md` 并返回它的 `sourcePath`。里面包含:
20
+
21
+ 1. 工作区当日改动文件(含大小、时间)
22
+ 2. 工作区内 Git 仓库当日提交与未提交改动
23
+ 3. DSH 当日有活动的会话(标题、用户消息、工具分布、最后一条回复)
24
+ 4. 工作看板 `看板.md` 的状态
25
+ 5. 工作区里 `_报告源文件` / `_巡检` / `_协作规范` 等已知产物目录的新增文件
26
+
27
+ 数据目录默认是 `~/.dsh/dsh-work-summary`(Windows 下即 `%USERPROFILE%\.dsh\dsh-work-summary`),也可以在插件的设置页改。
28
+
29
+ 然后**读取该文件**。若采集失败或文件缺失,在日报里注明「数据缺失」并说明原因,不要静默跳过。
30
+
31
+ ## 第二步:写日报
32
+
33
+ 调用 `daily_report_save { content }` 落盘到 `<reportDir>\日报-YYYY-MM-DD.md`(UTF-8,Markdown);
34
+ 它会校验六个小节、拒绝空骨架和占位符,并在文末补「数据来源 / 生成时间」脚注。结构固定为:
35
+
36
+ ```
37
+ # 工作日报 · YYYY-MM-DD
38
+
39
+ ## 一、今日概览
40
+ (3–5 句:今天的主线是什么,投入在哪几个方向,一句话结论)
41
+
42
+ ## 二、做了什么
43
+ (按主题分组,不按时间流水账。每条:做了什么 → 落在哪个路径/模块)
44
+ (证据来源标注:文件路径、提交号、会话标题)
45
+
46
+ ## 三、结果与产出
47
+ (表格:产出物 | 路径 | 状态[完成/进行中/待验证] | 说明)
48
+ (没有可交付物就写"今日无新增可运行产物",并说明卡在哪)
49
+
50
+ ## 四、问题与风险
51
+ (暴露的问题、未通过的验证、口径不一致、遗留脏数据;每条给出影响面)
52
+
53
+ ## 五、后续建议
54
+ (3–6 条,按优先级排序。每条格式:建议 | 为什么现在做 | 预估工作量 | 建议何时做)
55
+ (区分"今天没做完的收尾"与"值得启动的新动作")
56
+
57
+ ## 六、明日开场清单
58
+ (明天打开电脑后 30 分钟内可以动手的 3 件事,具体到文件/命令)
59
+
60
+ ---
61
+ 数据来源:`_源数据\YYYY-MM-DD.md` | 生成时间:YYYY-MM-DD HH:mm
62
+ ```
63
+
64
+ ## 第三步:把「明日开场清单」写进工作看板
65
+
66
+ `daily_report_save` 默认已经顺手推了看板(`pushOnSave`)。只有需要单独重推、或手工维护时,才用
67
+ `daily_report_board`(底层是 `scripts\push-to-board.ps1 -BoardPath <reportDir>\看板.md`):
68
+
69
+ - 目标看板:`<reportDir>\看板.md`(纯 Markdown 看板,**不依赖任何插件**,可 git 追踪、可手工勾选)。
70
+ - 解析「六、明日开场清单」,按内容指纹去重后追加到「## 待办」,形如 `- [ ] 日期 | 标题 | 来源 | #h指纹`,下挂一行 `详情:…`。
71
+ - 成功:工具返回里写明「新增 N 条 / 跳过重复 M 条」。已存在的条目会跳过,重复执行安全。
72
+ - 若看板里有 `- [ ]` 未完成项,在日报「四、问题与风险」提一句「昨日待办尚有 N 条未清」,不要装作没看见。
73
+ - **同一件事不要换措辞**:清单里某件事如果看板上已有未完成项(哪怕路径变了),就沿用那条的原话,不要改写——改写会被当成新条目重复写入,看板会越滚越乱。
74
+ - 以 `✅` 开头或含「已完成」的条目不会进看板。
75
+
76
+ ## 看板操作
77
+
78
+ 完成用 `daily_report_board { action: "done", keyword: "…" }`;**决定不做**用
79
+ `daily_report_board { action: "drop", keyword: "…" }`(移入「已放弃」并标日期),不要把"放弃"写成"完成"。
80
+
81
+ ## 硬性约束
82
+
83
+ - 只写有证据支撑的内容;推断必须显式标注「推断:」。
84
+ - 不写"继续推进""加强沟通"这类空话;每条建议要能落到具体文件、命令或验收标准。
85
+ - 客观描述,不自我表扬;对没做完的事直接写明。
86
+ - 若当天几乎无产出(节假日、休息),就写短版:概览 + 一句说明,不要硬凑。
87
+ - 日报写完后,在回复里给出:日报路径 + 三条最重要的结论(不超过 5 行)。
88
+
89
+ ## 例行检查(每天顺带)
90
+
91
+ - `<reportDir>\_源数据\` 是否超过 60 个文件?超了就提示归档。
92
+ - 若发现同一个坑连续两天出现,在「四、问题与风险」里标为「复发项」。
package/README.md CHANGED
@@ -1,3 +1,87 @@
1
- # Temporary Holding Version
1
+ # dsh-work-summary
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
+ [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)
4
+
5
+ DeepSeek Harness 插件:把「每天定时写一份工作日报」变成一条确定流水线——**采集、校验、落盘、推看板交给工具,模型只写正文**。
6
+
7
+ - 采集工作区当天的改动、Git 提交、DSH 会话、看板与产物目录,生成源数据底稿;
8
+ - 正文强制六节结构,缺节、空骨架、占位符直接报错且不写文件;
9
+ - 写盘后把「明日开场清单」按指纹去重推进看板,已完成 / 已放弃可回写;
10
+ - 侧边栏内置页面:读日报、看待办、改定时与目录,不用切会话。
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ # 从 npm 安装(已发布时;也可在设置 → 插件里填包名)
16
+ plugin_manager install_bundle dsh-work-summary
17
+
18
+ ```
19
+
20
+ 装完重启 DSH。默认数据目录 `~/.dsh/dsh-work-summary` 在首次激活时自动创建,首次启用还会接管(或新建)每日计划任务,保留原有的触发时间与投递会话。
21
+
22
+ ## 工具
23
+
24
+ | 工具 | 作用 |
25
+ |---|---|
26
+ | `daily_report_collect` | 采集当天痕迹,返回源数据路径、小节、看板未完成数、六节模板 |
27
+ | `daily_report_save` | 校验六节 → 写 `日报-YYYY-MM-DD.md` → 推看板 |
28
+ | `daily_report_board` | `show` 未完成;`done` 移到已完成;`drop` 移到已放弃 |
29
+
30
+ ## 配置
31
+
32
+ 设置页(侧边栏「日报 → 设置」)改的值写在 `~/.dsh/dsh-work-summary/settings.json`,优先级高于默认值;其余键可在 profile 的 `cordis.patch.yml` 里覆盖。
33
+
34
+ | 键 | 默认 | 说明 |
35
+ |---|---|---|
36
+ | `reportDir` | `~/.dsh/dsh-work-summary` | 数据目录:日报、看板、源数据、日志 |
37
+ | `workspace` | 同 `reportDir` | 采集扫描的工作区根,指向你平时干活的目录才有料 |
38
+ | `logDir` | `<reportDir>\_日志` | 运行日志,按天切 `dsh-work-summary-YYYY-MM-DD.log` |
39
+ | `scheduleEnabled` / `scheduleAdopt` | `true` / `true` | 托管 / 认领每日计划任务 |
40
+ | `scheduleTime` / `scheduleTimeZone` | `23:00` / `Asia/Shanghai` | 仅新建任务时用;之后以任务自身 rrule 为准 |
41
+ | `pwsh` / `timeoutMs` | `pwsh` / `240000` | PowerShell 可执行文件与单次超时 |
42
+
43
+ > 定时时间不写进 YAML:设置页改的是计划任务自己的 rrule,重启不会被默认值盖回去。
44
+
45
+ ## 数据布局
46
+
47
+ ```
48
+ ~/.dsh/dsh-work-summary/
49
+ ├── 日报-YYYY-MM-DD.md # 日报正文
50
+ ├── 看板.md # 待办看板(- [ ] 未完成)
51
+ ├── _源数据/YYYY-MM-DD.md # 采集底稿,只读生成
52
+ ├── _日志/ # 运行日志
53
+ └── settings.json # 设置页保存的选项
54
+ ```
55
+
56
+ 代码随插件仓库走(`scripts/`、`PROMPT.md`),数据目录只放运行期产物,不进版本库。
57
+
58
+ ## 手动跑脚本
59
+
60
+ ```powershell
61
+ pwsh -File .\scripts\collect-day.ps1 -Workspace D:\work -ReportDir "$env:USERPROFILE\.dsh\dsh-work-summary"
62
+
63
+ pwsh -File .\scripts\push-to-board.ps1 -BoardPath "$env:USERPROFILE\.dsh\dsh-work-summary\看板.md" -Show
64
+ pwsh -File .\scripts\push-to-board.ps1 -BoardPath ...\看板.md -DryRun # 预演,不写
65
+ pwsh -File .\scripts\push-to-board.ps1 -BoardPath ...\看板.md -Done "关键词"
66
+ ```
67
+
68
+ `-BoardPath` 必须显式传:脚本不猜看板位置,避免搬家后写错目录。
69
+
70
+ ## 开发
71
+
72
+ ```powershell
73
+ node test\route.test.mjs # 假 ctx 驱动真实 apply:工具、路由、计划任务同步、POST 校验
74
+ ```
75
+
76
+ 仓库结构:`index.js`(Host:工具 / 计划任务 / HTTP 路由)、`client.js`(侧边栏与设置页)、`scripts/*.ps1`(采集与看板)、`PROMPT.md`(正文规则,改完下一轮生效)、`docs/DETAIL.md`(详细说明)。
77
+
78
+ ## 限制
79
+
80
+ - 会话解析依赖 `zstd.exe`,缺失时该节降级为空。
81
+ - 只能看到文件与会话痕迹,线下工作需要在正文里补一句。
82
+ - 计划任务只在 DSH 运行时投递;卸插件前先停任务,否则投递到的会话调不到工具。
83
+ - 改目录只影响之后的写入位置,不搬动已有文件。
84
+
85
+ ## 许可
86
+
87
+ [MIT](LICENSE) © 2026 dsh-work-summary contributors
package/client.js ADDED
@@ -0,0 +1,393 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-work-summary',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const { useState, useEffect, useCallback } = React
7
+
8
+ const PANEL_ID = 'dsh-work-summary'
9
+ const ENDPOINT = '/dsh-work-summary/state'
10
+ const SCHEDULE_ENDPOINT = '/dsh-work-summary/schedule'
11
+
12
+ const S = {
13
+ page: {
14
+ boxSizing: 'border-box',
15
+ height: '100%',
16
+ overflow: 'auto',
17
+ padding: '24px 32px 48px',
18
+ marginTop: 'var(--dsh-frame-top-clearance, 0px)',
19
+ color: 'inherit',
20
+ fontSize: 14,
21
+ lineHeight: 1.65,
22
+ },
23
+ bar: { display: 'flex', alignItems: 'center', gap: 12, marginBottom: 18, flexWrap: 'wrap' },
24
+ title: { fontSize: 20, fontWeight: 600, margin: 0 },
25
+ tabs: { display: 'flex', gap: 4, marginLeft: 'auto' },
26
+ tab: (active) => ({
27
+ border: '1px solid rgba(127,127,127,.28)',
28
+ background: active ? 'rgba(127,127,127,.16)' : 'transparent',
29
+ color: 'inherit',
30
+ borderRadius: 8,
31
+ padding: '5px 12px',
32
+ fontSize: 13,
33
+ cursor: 'pointer',
34
+ }),
35
+ ghost: {
36
+ border: '1px solid rgba(127,127,127,.28)', background: 'transparent', color: 'inherit',
37
+ borderRadius: 8, padding: '5px 12px', fontSize: 13, cursor: 'pointer',
38
+ },
39
+ muted: { opacity: 0.62, fontSize: 12 },
40
+ split: { display: 'flex', gap: 20, alignItems: 'flex-start' },
41
+ list: {
42
+ flex: '0 0 176px', display: 'flex', flexDirection: 'column', gap: 2,
43
+ maxHeight: 'calc(100vh - 200px)', overflow: 'auto', paddingRight: 4,
44
+ },
45
+ item: (active) => ({
46
+ textAlign: 'left', border: 'none', borderRadius: 8, cursor: 'pointer', color: 'inherit',
47
+ background: active ? 'rgba(99,155,255,.16)' : 'transparent',
48
+ fontWeight: active ? 600 : 400, padding: '6px 10px', fontSize: 13, display: 'block', width: '100%',
49
+ }),
50
+ doc: { flex: 1, minWidth: 0, maxWidth: 860 },
51
+ heading: { fontWeight: 600, margin: '18px 0 6px' },
52
+ para: { margin: '4px 0' },
53
+ bullet: { margin: '3px 0', paddingLeft: 4 },
54
+ table: { fontFamily: 'ui-monospace, SFMono-Regular, Consolas, monospace', fontSize: 12.5, whiteSpace: 'pre-wrap' },
55
+ code: { fontFamily: 'ui-monospace, SFMono-Regular, Consolas, monospace', fontSize: 12.5, background: 'rgba(127,127,127,.14)', padding: '1px 4px', borderRadius: 4 },
56
+ quote: { margin: '6px 0', paddingLeft: 10, borderLeft: '3px solid rgba(127,127,127,.3)', opacity: 0.8 },
57
+ hr: { border: 'none', borderTop: '1px solid rgba(127,127,127,.24)', margin: '14px 0' },
58
+ section: { marginBottom: 22 },
59
+ boardHead: { fontSize: 15, fontWeight: 600, margin: '0 0 8px' },
60
+ row: { display: 'flex', gap: 8, alignItems: 'baseline', padding: '3px 0' },
61
+ dot: (open) => ({
62
+ flex: '0 0 auto', width: 13, height: 13, borderRadius: 3, marginTop: 4,
63
+ border: '1.5px solid rgba(127,127,127,.6)',
64
+ background: open ? 'transparent' : 'rgba(127,127,127,.55)',
65
+ }),
66
+ empty: { opacity: 0.6, padding: '24px 0' },
67
+ error: { color: '#d14343', margin: '12px 0', whiteSpace: 'pre-wrap' },
68
+ notice: { color: '#2f9e44', fontSize: 13 },
69
+ field: { display: 'flex', alignItems: 'center', gap: 10, margin: '14px 0' },
70
+ label: { width: 88, opacity: 0.75, fontSize: 13 },
71
+ input: {
72
+ border: '1px solid rgba(127,127,127,.3)', background: 'transparent', color: 'inherit',
73
+ borderRadius: 8, padding: '5px 8px', fontSize: 13, fontFamily: 'inherit',
74
+ },
75
+ hint: { opacity: 0.62, fontSize: 12, lineHeight: 1.7, marginTop: 20, maxWidth: 620 },
76
+ }
77
+
78
+ function inline(text) {
79
+ const out = []
80
+ const re = /(\*\*[^*]+\*\*|`[^`]+`)/g
81
+ let last = 0
82
+ let match
83
+ let key = 0
84
+ while ((match = re.exec(text)) !== null) {
85
+ if (match.index > last) out.push(text.slice(last, match.index))
86
+ const token = match[0]
87
+ if (token.startsWith('**')) out.push(h('strong', { key: `b${key++}` }, token.slice(2, -2)))
88
+ else out.push(h('code', { key: `c${key++}`, style: S.code }, token.slice(1, -1)))
89
+ last = match.index + token.length
90
+ }
91
+ if (last < text.length) out.push(text.slice(last))
92
+ return out.length === 0 ? text : out
93
+ }
94
+
95
+ function renderLine(line, index) {
96
+ const text = line.replace(/\s+$/, '')
97
+ const trimmed = text.trim()
98
+ if (trimmed === '') return h('div', { key: index, style: { height: 7 } })
99
+ if (/^(---|\*\*\*)$/.test(trimmed)) return h('hr', { key: index, style: S.hr })
100
+ let match
101
+ if ((match = /^(#{1,4})\s+(.*)$/.exec(trimmed))) {
102
+ const level = match[1].length
103
+ const size = [21, 17, 15.5, 14.5][level - 1]
104
+ return h('div', { key: index, style: { ...S.heading, fontSize: size, marginTop: level === 1 ? 0 : 18 } }, inline(match[2]))
105
+ }
106
+ if ((match = /^[-*]\s+(.*)$/.exec(trimmed))) {
107
+ return h('div', { key: index, style: S.bullet }, '• ', inline(match[1]))
108
+ }
109
+ if ((match = /^(\d+)[.、]\s+(.*)$/.exec(trimmed))) {
110
+ return h('div', { key: index, style: S.bullet }, `${match[1]}. `, inline(match[2]))
111
+ }
112
+ if (trimmed.startsWith('|')) return h('div', { key: index, style: S.table }, text)
113
+ if (trimmed.startsWith('>')) return h('div', { key: index, style: S.quote }, inline(trimmed.replace(/^>\s?/, '')))
114
+ return h('div', { key: index, style: S.para }, inline(trimmed))
115
+ }
116
+
117
+ function parseBoard(text) {
118
+ const sections = []
119
+ let current = null
120
+ for (const raw of String(text ?? '').split(/\r?\n/)) {
121
+ const heading = /^##\s+(.+?)\s*$/.exec(raw)
122
+ if (heading) {
123
+ current = { title: heading[1], items: [] }
124
+ sections.push(current)
125
+ continue
126
+ }
127
+ const item = /^\s*-\s*\[( |x|X)\]\s*(.*)$/.exec(raw)
128
+ if (item && current) current.items.push({ open: item[1] === ' ', text: item[2] })
129
+ }
130
+ return sections.filter(section => section.items.length > 0)
131
+ }
132
+
133
+ function Icon(props) {
134
+ const size = (props && props.size) || 16
135
+ return h('svg', {
136
+ viewBox: '0 0 16 16', width: size, height: size, fill: 'none',
137
+ stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round', strokeLinejoin: 'round',
138
+ 'aria-hidden': true, style: { display: 'block' },
139
+ },
140
+ h('rect', { x: 3, y: 2, width: 10, height: 12, rx: 1.5 }),
141
+ h('path', { d: 'M5.5 5.5h5M5.5 8h5M5.5 10.5h3' }),
142
+ )
143
+ }
144
+
145
+ function ReportsView({ state }) {
146
+ const reports = state.reports || []
147
+ const [selected, setSelected] = useState(reports.length > 0 ? reports[0].file : null)
148
+ useEffect(() => {
149
+ if (!reports.some(report => report.file === selected)) setSelected(reports.length > 0 ? reports[0].file : null)
150
+ }, [reports, selected])
151
+ const current = reports.find(report => report.file === selected)
152
+ if (reports.length === 0) return h('div', { style: S.empty }, '这个目录里还没有日报。')
153
+ return h('div', { style: S.split },
154
+ h('div', { style: S.list }, reports.map(report => h('button', {
155
+ key: report.file,
156
+ type: 'button',
157
+ onClick: () => setSelected(report.file),
158
+ style: S.item(report.file === selected),
159
+ title: `${report.file} · ${Math.round(report.size / 102.4) / 10} KB`,
160
+ }, report.date))),
161
+ h('div', { style: S.doc },
162
+ current
163
+ ? [
164
+ h('div', { key: 'meta', style: S.muted },
165
+ `${current.date} · ${Math.round(current.size / 102.4) / 10} KB · ${current.file}`),
166
+ ...current.content.split(/\r?\n/).map(renderLine),
167
+ ]
168
+ : h('div', { style: S.empty }, '选一天看。'),
169
+ ),
170
+ )
171
+ }
172
+
173
+ function BoardView({ state }) {
174
+ const sections = parseBoard(state.board && state.board.text)
175
+ if (sections.length === 0) return h('div', { style: S.empty }, '看板里还没有条目。')
176
+ return h('div', null, sections.map(section => h('div', { key: section.title, style: S.section },
177
+ h('h3', { style: S.boardHead }, `${section.title}(${section.items.length})`),
178
+ section.items.map((item, index) => h('div', { key: `${section.title}-${index}`, style: S.row },
179
+ h('span', { style: S.dot(item.open) }),
180
+ h('span', { style: item.open ? undefined : { opacity: 0.65 } }, item.text),
181
+ )),
182
+ )))
183
+ }
184
+
185
+ function SettingsView() {
186
+ const [info, setInfo] = useState(null)
187
+ const [time, setTime] = useState('23:00')
188
+ const [reportDir, setReportDir] = useState('')
189
+ const [workspace, setWorkspace] = useState('')
190
+ const [logDir, setLogDir] = useState('')
191
+ const [busy, setBusy] = useState(false)
192
+ const [notice, setNotice] = useState(null)
193
+ const [error, setError] = useState(null)
194
+
195
+ const load = useCallback(async () => {
196
+ try {
197
+ const response = await fetch(SCHEDULE_ENDPOINT, { cache: 'no-store' })
198
+ const payload = await response.json()
199
+ if (!response.ok) throw new Error(payload && payload.error ? payload.error : `HTTP ${response.status}`)
200
+ setInfo(payload)
201
+ if (payload.time) setTime(payload.time)
202
+ if (typeof payload.reportDir === 'string') setReportDir(payload.reportDir)
203
+ if (typeof payload.workspace === 'string') setWorkspace(payload.workspace)
204
+ if (typeof payload.logDir === 'string') setLogDir(payload.logDir)
205
+ setError(null)
206
+ } catch (cause) {
207
+ setError(`读取定时设置失败:${cause && cause.message ? cause.message : String(cause)}`)
208
+ }
209
+ }, [])
210
+
211
+ useEffect(() => { load() }, [load])
212
+
213
+ const save = useCallback(async (patch) => {
214
+ setBusy(true)
215
+ setNotice(null)
216
+ setError(null)
217
+ try {
218
+ const response = await fetch(SCHEDULE_ENDPOINT, {
219
+ method: 'POST',
220
+ headers: { 'content-type': 'application/json' },
221
+ body: JSON.stringify(patch),
222
+ })
223
+ const payload = await response.json()
224
+ if (!response.ok) throw new Error(payload && payload.error ? payload.error : `HTTP ${response.status}`)
225
+ setInfo(payload)
226
+ if (payload.time) setTime(payload.time)
227
+ if (typeof payload.reportDir === 'string') setReportDir(payload.reportDir)
228
+ if (typeof payload.workspace === 'string') setWorkspace(payload.workspace)
229
+ if (typeof payload.logDir === 'string') setLogDir(payload.logDir)
230
+ setNotice('已保存')
231
+ } catch (cause) {
232
+ setError(`保存失败:${cause && cause.message ? cause.message : String(cause)}`)
233
+ } finally {
234
+ setBusy(false)
235
+ }
236
+ }, [])
237
+
238
+ if (!info) return error ? h('div', { style: S.error }, error) : h('div', { style: S.empty }, '加载中…')
239
+
240
+ const scheduleBlock = info.found
241
+ ? h('div', null,
242
+ h('h3', { style: S.boardHead }, '定时'),
243
+ h('div', { style: S.field },
244
+ h('span', { style: S.label }, '每天'),
245
+ h('input', {
246
+ type: 'time',
247
+ value: time,
248
+ style: S.input,
249
+ onChange: event => setTime(event.target.value),
250
+ }),
251
+ h('span', { style: S.muted }, info.timeZone),
252
+ ),
253
+ h('div', { style: S.field },
254
+ h('span', { style: S.label }, '启用'),
255
+ h('input', {
256
+ type: 'checkbox',
257
+ checked: Boolean(info.active),
258
+ onChange: event => save({ active: event.target.checked }),
259
+ }),
260
+ h('span', { style: S.muted }, info.active ? '到点投递到会话' : '已暂停,任务仍保留'),
261
+ ),
262
+ h('div', { style: S.field },
263
+ h('button', { type: 'button', style: S.ghost, disabled: busy, onClick: () => save({ time }) },
264
+ busy ? '保存中…' : '保存时间'),
265
+ notice ? h('span', { style: S.notice }, notice) : null,
266
+ ),
267
+ )
268
+ : h('div', { style: S.empty }, '还没找到日报计划任务:重启一次 DSH,插件会把它建出来。')
269
+
270
+ return h('div', { style: { maxWidth: 640 } },
271
+ h('h3', { style: S.boardHead }, '日报文件目录'),
272
+ h('div', { style: S.field },
273
+ h('span', { style: S.label }, '目录'),
274
+ h('input', {
275
+ type: 'text',
276
+ value: reportDir,
277
+ placeholder: info.reportDirDefault,
278
+ style: { ...S.input, width: 360 },
279
+ onChange: event => setReportDir(event.target.value),
280
+ }),
281
+ h('button', { type: 'button', style: S.ghost, disabled: busy, onClick: () => save({ reportDir }) },
282
+ busy ? '保存中…' : '保存目录'),
283
+ ),
284
+ h('div', { style: { ...S.hint, marginTop: 4 } },
285
+ `默认 ${info.reportDirDefault};日报、看板、_源数据 都写在这里。改目录不会搬动已有文件。`,
286
+ ),
287
+ h('h3', { style: S.boardHead }, '工作空间'),
288
+ h('div', { style: S.field },
289
+ h('span', { style: S.label }, '目录'),
290
+ h('input', {
291
+ type: 'text',
292
+ value: workspace,
293
+ placeholder: info.workspaceDefault,
294
+ style: { ...S.input, width: 360 },
295
+ onChange: event => setWorkspace(event.target.value),
296
+ }),
297
+ h('button', { type: 'button', style: S.ghost, disabled: busy, onClick: () => save({ workspace }) },
298
+ busy ? '保存中…' : '保存目录'),
299
+ ),
300
+ h('div', { style: { ...S.hint, marginTop: 4 } },
301
+ '日报从这里扫当天改了哪些文件、有哪些 git 仓库;默认和插件数据目录同一个(装好就有),填你平时干活的目录更贴合实际。',
302
+ ),
303
+ scheduleBlock,
304
+ h('h3', { style: S.boardHead }, '日志'),
305
+ h('div', { style: S.field },
306
+ h('span', { style: S.label }, '目录'),
307
+ h('input', {
308
+ type: 'text',
309
+ value: logDir,
310
+ placeholder: info.logDirDefault,
311
+ style: { ...S.input, width: 360 },
312
+ onChange: event => setLogDir(event.target.value),
313
+ }),
314
+ h('button', { type: 'button', style: S.ghost, disabled: busy, onClick: () => save({ logDir }) },
315
+ busy ? '保存中…' : '保存目录'),
316
+ ),
317
+ h('div', { style: { ...S.hint, marginTop: 4 } },
318
+ `留空表示用数据目录下的 _日志(${info.logDirDefault})。`,
319
+ h('br'),
320
+ `文件名 ${info.logPattern},每次调脚本记一行:参数、退出码、耗时;失败带 stderr 尾部。`,
321
+ ),
322
+ error ? h('div', { style: S.error }, error) : null,
323
+ info.found
324
+ ? h('div', { style: S.hint },
325
+ `任务:${info.title}(${info.id})`,
326
+ h('br'),
327
+ info.nextRunAt ? `下次触发:${info.nextRunAt}` : '当前没有下次触发时间',
328
+ h('br'),
329
+ '时间改的是计划任务本身,重启后不会被默认值盖回去;暂停只停投递,不删任务。',
330
+ )
331
+ : null,
332
+ )
333
+ }
334
+
335
+ function Panel() {
336
+ const [state, setState] = useState(null)
337
+ const [error, setError] = useState(null)
338
+ const [tab, setTab] = useState('reports')
339
+ const [busy, setBusy] = useState(false)
340
+
341
+ const load = useCallback(async () => {
342
+ setBusy(true)
343
+ try {
344
+ const response = await fetch(ENDPOINT, { cache: 'no-store' })
345
+ const payload = await response.json()
346
+ if (!response.ok) throw new Error(payload && payload.error ? payload.error : `HTTP ${response.status}`)
347
+ setState(payload)
348
+ setError(null)
349
+ } catch (cause) {
350
+ setError(`读取日报数据失败:${cause && cause.message ? cause.message : String(cause)}`)
351
+ } finally {
352
+ setBusy(false)
353
+ }
354
+ }, [])
355
+
356
+ useEffect(() => { load() }, [load])
357
+
358
+ const open = state && state.board ? state.board.open : 0
359
+ return h('div', { style: S.page },
360
+ h('div', { style: S.bar },
361
+ h('h1', { style: S.title }, '工作日报'),
362
+ state ? h('span', { style: S.muted }, `${state.reportDir} · 待办 ${open} 条`) : null,
363
+ h('div', { style: S.tabs },
364
+ h('button', { type: 'button', style: S.tab(tab === 'reports'), onClick: () => setTab('reports') }, '日报'),
365
+ h('button', { type: 'button', style: S.tab(tab === 'board'), onClick: () => setTab('board') }, '看板'),
366
+ h('button', { type: 'button', style: S.tab(tab === 'settings'), onClick: () => setTab('settings') }, '设置'),
367
+ h('button', { type: 'button', style: S.ghost, onClick: load, disabled: busy }, busy ? '刷新中…' : '刷新'),
368
+ ),
369
+ ),
370
+ error ? h('div', { style: S.error }, error) : null,
371
+ tab === 'settings' ? h(SettingsView)
372
+ : !state ? (error ? null : h('div', { style: S.empty }, '加载中…'))
373
+ : tab === 'reports' ? h(ReportsView, { state }) : h(BoardView, { state }),
374
+ )
375
+ }
376
+
377
+ return {
378
+ inject: ['slots'],
379
+ apply(ctx) {
380
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
381
+ name: 'sidebar.panellist',
382
+ id: PANEL_ID,
383
+ order: 10,
384
+ label: '日报',
385
+ }, Icon))
386
+ ctx.slots.inject('main', () => ctx.slots.register({
387
+ name: 'main',
388
+ key: PANEL_ID,
389
+ }, Panel))
390
+ },
391
+ }
392
+ },
393
+ })
@@ -0,0 +1,9 @@
1
+ - insert:
2
+ - id: dsh-work-summary
3
+ name: 'dsh-work-summary'
4
+ config:
5
+ # 数据目录默认 ~/.dsh/dsh-work-summary,设置页可改,所以这里不写死。
6
+ scheduleEnabled: true
7
+ scheduleAdopt: true
8
+ scheduleTime: '23:00'
9
+ scheduleTimeZone: 'Asia/Shanghai'