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 +21 -0
- package/PROMPT.md +92 -0
- package/README.md +86 -2
- package/client.js +393 -0
- package/cordis.patch.yml +9 -0
- package/docs/DETAIL.md +86 -0
- package/icon.svg +12 -0
- package/index.js +877 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +56 -4
- package/scripts/collect-day.ps1 +270 -0
- package/scripts/push-to-board.ps1 +232 -0
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-work-summary",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Daily work report for DeepSeek Harness: collect the day's traces, write and validate a report, push tomorrow's checklist onto the board.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.js",
|
|
8
|
+
"./client": "./client.js",
|
|
9
|
+
"./locale/*.json": "./locale/*.json",
|
|
10
|
+
"./icon": "./icon.svg"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.js",
|
|
14
|
+
"client.js",
|
|
15
|
+
"cordis.patch.yml",
|
|
16
|
+
"scripts",
|
|
17
|
+
"PROMPT.md",
|
|
18
|
+
"README.md",
|
|
19
|
+
"locale/*.json",
|
|
20
|
+
"docs",
|
|
21
|
+
"icon.svg",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"dsh",
|
|
26
|
+
"dsh-plugin",
|
|
27
|
+
"deepseek-harness",
|
|
28
|
+
"daily-report",
|
|
29
|
+
"work-summary",
|
|
30
|
+
"journal",
|
|
31
|
+
"productivity"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"dsh": ">=0.2.3-alpha.2"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "node test/route.test.mjs",
|
|
38
|
+
"check": "node --check index.js && node --check client.js"
|
|
39
|
+
},
|
|
40
|
+
"dsh": {
|
|
41
|
+
"bundle": {
|
|
42
|
+
"patch": "./cordis.patch.yml"
|
|
43
|
+
},
|
|
44
|
+
"client": {
|
|
45
|
+
"platform": "web",
|
|
46
|
+
"immediately": true,
|
|
47
|
+
"inject": [
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
49
|
+
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"registry": "https://registry.npmjs.org/",
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"license": "MIT"
|
|
58
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# collect-day.ps1 —— 收集某一天的"工作痕迹",输出一份源数据 Markdown,供日报总结引用。
|
|
2
|
+
# 用法:
|
|
3
|
+
# pwsh -NoProfile -File collect-day.ps1 # 今天
|
|
4
|
+
# pwsh -NoProfile -File collect-day.ps1 -Date 2026-10-28
|
|
5
|
+
# pwsh -NoProfile -File collect-day.ps1 -NoSessions # 跳过会话解析(更快)
|
|
6
|
+
# 输出:<ReportDir>\_源数据\YYYY-MM-DD.md(同时打印路径)
|
|
7
|
+
# 本脚本属于 dsh-work-summary 插件仓库;扫哪里由 -Workspace 决定,产物写哪由 -ReportDir 决定。
|
|
8
|
+
# 默认数据根是 ~/.dsh/dsh-work-summary(插件激活时创建),插件调用时会把两个参数都显式传进来。
|
|
9
|
+
|
|
10
|
+
param(
|
|
11
|
+
[string]$Date = (Get-Date -Format 'yyyy-MM-dd'),
|
|
12
|
+
[string]$DshHome = (Join-Path $HOME '.dsh'),
|
|
13
|
+
[string]$Workspace = (Join-Path $DshHome 'dsh-work-summary'),
|
|
14
|
+
[string]$ReportDir = (Join-Path $DshHome 'dsh-work-summary'),
|
|
15
|
+
[switch]$NoSessions
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
$ErrorActionPreference = 'Stop'
|
|
19
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
20
|
+
|
|
21
|
+
try { $day = [datetime]::ParseExact($Date, 'yyyy-MM-dd', $null) }
|
|
22
|
+
catch { throw "日期格式应为 yyyy-MM-dd,收到:$Date" }
|
|
23
|
+
|
|
24
|
+
$dayStart = $day
|
|
25
|
+
$dayEnd = $day.AddDays(1)
|
|
26
|
+
$startMs = [DateTimeOffset]::new($dayStart).ToUnixTimeMilliseconds()
|
|
27
|
+
$endMs = [DateTimeOffset]::new($dayEnd).ToUnixTimeMilliseconds()
|
|
28
|
+
$sinceArg = $dayStart.ToString('yyyy-MM-dd HH:mm:ss')
|
|
29
|
+
$untilArg = $dayEnd.ToString('yyyy-MM-dd HH:mm:ss')
|
|
30
|
+
|
|
31
|
+
$outDir = Join-Path $ReportDir '_源数据'
|
|
32
|
+
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
|
|
33
|
+
$outFile = Join-Path $outDir "$Date.md"
|
|
34
|
+
|
|
35
|
+
$skipDirs = @('node_modules', '.pnpm-store', '.git', 'dist', 'build', '.next', 'target',
|
|
36
|
+
'temp', 'tmp', '.cache', '__pycache__', '_源数据', '.dsh-vision-router',
|
|
37
|
+
# 第三方资产/工具目录:装技能、跑示例产生的海量文件不该进日报
|
|
38
|
+
'.dsh', 'anatomy', 'shots', '备份',
|
|
39
|
+
# 临时/调试文件专区:一次性脚本与中间产物不算工作产出
|
|
40
|
+
'_scratch')
|
|
41
|
+
|
|
42
|
+
function Test-SkipPath([string]$rel) {
|
|
43
|
+
foreach ($seg in ($rel -split '[\\/]')) {
|
|
44
|
+
if ($skipDirs -contains $seg) { return $true }
|
|
45
|
+
}
|
|
46
|
+
return $false
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
$sb = [System.Collections.Generic.List[string]]::new()
|
|
50
|
+
function Add-Line([string]$s = '') { $sb.Add($s) }
|
|
51
|
+
|
|
52
|
+
Add-Line "# 工作痕迹源数据 · $Date"
|
|
53
|
+
Add-Line ''
|
|
54
|
+
Add-Line "> 采集窗口:$sinceArg ~ $untilArg(本地时区 $([DateTime]::Now.ToString('zzz')))"
|
|
55
|
+
Add-Line '> 本文件由 `collect-day.ps1` 只读生成,用于日报的事实依据;不要手工编辑。'
|
|
56
|
+
Add-Line ''
|
|
57
|
+
|
|
58
|
+
# ---------- 1. 工作区文件改动 ----------
|
|
59
|
+
Add-Line '## 1. 工作区当日改动文件'
|
|
60
|
+
Add-Line ''
|
|
61
|
+
$files = @()
|
|
62
|
+
if (Test-Path $Workspace) {
|
|
63
|
+
$files = Get-ChildItem -Path $Workspace -Recurse -File -Force -ErrorAction SilentlyContinue |
|
|
64
|
+
Where-Object {
|
|
65
|
+
$_.LastWriteTime -ge $dayStart -and $_.LastWriteTime -lt $dayEnd -and
|
|
66
|
+
-not (Test-SkipPath $_.FullName.Substring($Workspace.Length))
|
|
67
|
+
} | Sort-Object LastWriteTime
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ($files.Count -eq 0) {
|
|
71
|
+
Add-Line '_当日无文件改动。_'
|
|
72
|
+
} else {
|
|
73
|
+
Add-Line "共 $($files.Count) 个文件:"
|
|
74
|
+
Add-Line ''
|
|
75
|
+
Add-Line '| 时间 | 大小 | 相对路径 |'
|
|
76
|
+
Add-Line '|------|------|----------|'
|
|
77
|
+
foreach ($f in $files) {
|
|
78
|
+
$rel = $f.FullName.Substring($Workspace.Length).TrimStart('\')
|
|
79
|
+
$size = if ($f.Length -ge 1MB) { '{0:N1} MB' -f ($f.Length / 1MB) }
|
|
80
|
+
elseif ($f.Length -ge 1KB) { '{0:N1} KB' -f ($f.Length / 1KB) }
|
|
81
|
+
else { "$($f.Length) B" }
|
|
82
|
+
Add-Line ("| {0:HH:mm} | {1} | {2} |" -f $f.LastWriteTime, $size, $rel)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Add-Line ''
|
|
86
|
+
Add-Line '### 按顶层目录汇总'
|
|
87
|
+
Add-Line ''
|
|
88
|
+
$files | Group-Object { ($_.FullName.Substring($Workspace.Length).TrimStart('\') -split '[\\/]')[0] } |
|
|
89
|
+
Sort-Object Count -Descending |
|
|
90
|
+
ForEach-Object { Add-Line ("- ``{0}``:{1} 个文件" -f $_.Name, $_.Count) }
|
|
91
|
+
}
|
|
92
|
+
Add-Line ''
|
|
93
|
+
|
|
94
|
+
# ---------- 2. Git 仓库提交 ----------
|
|
95
|
+
Add-Line '## 2. Git 仓库当日提交'
|
|
96
|
+
Add-Line ''
|
|
97
|
+
$gitExe = (Get-Command git -ErrorAction SilentlyContinue).Source
|
|
98
|
+
$repos = @()
|
|
99
|
+
if ($gitExe -and (Test-Path $Workspace)) {
|
|
100
|
+
$repos = Get-ChildItem -Path $Workspace -Directory -Recurse -Depth 3 -Force -ErrorAction SilentlyContinue |
|
|
101
|
+
Where-Object { Test-Path (Join-Path $_.FullName '.git') } |
|
|
102
|
+
Select-Object -ExpandProperty FullName
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (-not $gitExe) {
|
|
106
|
+
Add-Line '_未找到 git,跳过。_'
|
|
107
|
+
} elseif ($repos.Count -eq 0) {
|
|
108
|
+
Add-Line '_工作区内未发现 Git 仓库。_'
|
|
109
|
+
} else {
|
|
110
|
+
$anyCommit = $false
|
|
111
|
+
foreach ($repo in $repos) {
|
|
112
|
+
$rel = if ($repo -eq $Workspace) { '.' } else { $repo.Substring($Workspace.Length).TrimStart('\') }
|
|
113
|
+
$log = & $gitExe -C $repo log --since="$sinceArg" --until="$untilArg" --pretty='%h %ad %s' --date=format:'%H:%M' --no-decorate 2>$null
|
|
114
|
+
$branch = (& $gitExe -C $repo rev-parse --abbrev-ref HEAD 2>$null)
|
|
115
|
+
$dirty = @(& $gitExe -C $repo status --porcelain 2>$null).Count
|
|
116
|
+
if ($log) {
|
|
117
|
+
$anyCommit = $true
|
|
118
|
+
Add-Line "### ``$rel`` (分支 $branch)"
|
|
119
|
+
Add-Line ''
|
|
120
|
+
foreach ($l in $log) { Add-Line "- $l" }
|
|
121
|
+
Add-Line ''
|
|
122
|
+
if ($dirty -gt 0) { Add-Line "- 另有 $dirty 个未提交改动" ; Add-Line '' }
|
|
123
|
+
} elseif ($dirty -gt 0) {
|
|
124
|
+
Add-Line "- ``$rel``:当日无提交,但有 $dirty 个未提交改动(分支 $branch)"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (-not $anyCommit) { Add-Line '' }
|
|
128
|
+
}
|
|
129
|
+
Add-Line ''
|
|
130
|
+
|
|
131
|
+
# ---------- 3. DSH 会话 ----------
|
|
132
|
+
Add-Line '## 3. DSH 会话(当日有活动的会话)'
|
|
133
|
+
Add-Line ''
|
|
134
|
+
if ($NoSessions) {
|
|
135
|
+
Add-Line '_(-NoSessions 跳过)_'
|
|
136
|
+
} else {
|
|
137
|
+
$sessRoot = Join-Path $DshHome 'sessions'
|
|
138
|
+
$zstd = (Get-Command zstd -ErrorAction SilentlyContinue).Source
|
|
139
|
+
if (-not $zstd) { $zstd = 'C:\Program Files\poppler\Library\bin\zstd.exe' }
|
|
140
|
+
|
|
141
|
+
$sessFiles = @()
|
|
142
|
+
if (Test-Path $sessRoot) {
|
|
143
|
+
$sessFiles = Get-ChildItem -Path $sessRoot -Recurse -File -Filter 'session.v4.jsonl.zstd' -ErrorAction SilentlyContinue |
|
|
144
|
+
Where-Object { $_.LastWriteTime -ge $dayStart -and $_.LastWriteTime -lt $dayEnd } |
|
|
145
|
+
Sort-Object LastWriteTime
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if ($sessFiles.Count -eq 0) {
|
|
149
|
+
Add-Line '_当日无 DSH 会话活动。_'
|
|
150
|
+
} else {
|
|
151
|
+
Add-Line "共 $($sessFiles.Count) 个会话有活动。"
|
|
152
|
+
Add-Line ''
|
|
153
|
+
foreach ($sf in $sessFiles) {
|
|
154
|
+
$wsName = $sf.Directory.Parent.Name
|
|
155
|
+
$title = $null; $cwd = $null; $users = @(); $toolCount = 0
|
|
156
|
+
$toolNames = @{}; $lastReply = $null
|
|
157
|
+
if (Test-Path $zstd) {
|
|
158
|
+
try {
|
|
159
|
+
$raw = & $zstd -d -c $sf.FullName 2>$null
|
|
160
|
+
foreach ($line in $raw) {
|
|
161
|
+
if (-not $line) { continue }
|
|
162
|
+
try { $o = $line | ConvertFrom-Json } catch { continue }
|
|
163
|
+
switch ($o.type) {
|
|
164
|
+
'session' { if ($o.cwd) { $cwd = $o.cwd } }
|
|
165
|
+
'session/title' { if ($o.data.title) { $title = $o.data.title } }
|
|
166
|
+
'user/message' {
|
|
167
|
+
if ($o.time -ge $startMs -and $o.time -lt $endMs) {
|
|
168
|
+
$txt = ($o.data.content | Where-Object { $_.type -eq 'text' } | ForEach-Object { $_.text }) -join ' '
|
|
169
|
+
if ($txt) {
|
|
170
|
+
$txt = ($txt -replace '\s+', ' ').Trim()
|
|
171
|
+
# 过滤注入内容与无信息量的催更
|
|
172
|
+
$injected = $txt -match '^(<system-reminder>|Current runtime context|Time sampled|\[System\]|A skill is a reusable)'
|
|
173
|
+
$filler = $txt.Length -le 4 -and $txt -match '^(继续|好的|ok|OK|嗯|你好)'
|
|
174
|
+
if (-not $injected -and -not $filler) {
|
|
175
|
+
if ($txt.Length -gt 110) { $txt = $txt.Substring(0, 110) + '…' }
|
|
176
|
+
if ($users.Count -eq 0 -or $users[-1] -ne $txt) { $users += $txt }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
'assistant/message' {
|
|
182
|
+
if ($o.time -ge $startMs -and $o.time -lt $endMs) {
|
|
183
|
+
$r = ($o.data.content | Where-Object { $_.type -eq 'text' } | ForEach-Object { $_.text }) -join ' '
|
|
184
|
+
if ($r) {
|
|
185
|
+
$r = ($r -replace '\s+', ' ').Trim()
|
|
186
|
+
if ($r.Length -gt 220) { $r = $r.Substring(0, 220) + '…' }
|
|
187
|
+
$lastReply = $r
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
'tool/call' {
|
|
192
|
+
if ($o.time -ge $startMs -and $o.time -lt $endMs) {
|
|
193
|
+
$toolCount++
|
|
194
|
+
if ($o.data.name) { $toolNames[$o.data.name] = 1 + [int]$toolNames[$o.data.name] }
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} catch { Add-Line ("- ``{0}`` 解析失败:{1}" -f $wsName, $_.Exception.Message) }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Add-Line ("### ``{0}``" -f $wsName)
|
|
203
|
+
Add-Line ''
|
|
204
|
+
Add-Line ("- 会话目录:``{0}``" -f $sf.FullName)
|
|
205
|
+
if ($cwd) { Add-Line ("- 工作目录:``{0}``" -f $cwd) }
|
|
206
|
+
if ($title) { Add-Line ("- 标题:{0}" -f $title) }
|
|
207
|
+
Add-Line ("- 当日有效用户消息 {0} 条,工具调用 {1} 次" -f $users.Count, $toolCount)
|
|
208
|
+
if ($toolNames.Count -gt 0) {
|
|
209
|
+
$top = ($toolNames.GetEnumerator() | Sort-Object Value -Descending | Select-Object -First 6 |
|
|
210
|
+
ForEach-Object { '{0}×{1}' -f $_.Key, $_.Value }) -join '、'
|
|
211
|
+
Add-Line ("- 工具分布:{0}" -f $top)
|
|
212
|
+
}
|
|
213
|
+
if ($lastReply) { Add-Line ("- 最后一条回复:{0}" -f $lastReply) }
|
|
214
|
+
foreach ($u in ($users | Select-Object -First 12)) { Add-Line (" - 「{0}」" -f $u) }
|
|
215
|
+
if ($users.Count -gt 12) { Add-Line (" - …另有 {0} 条" -f ($users.Count - 12)) }
|
|
216
|
+
Add-Line ''
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
Add-Line ''
|
|
221
|
+
|
|
222
|
+
# ---------- 4. 工作看板(工作区内的 Markdown 看板) ----------
|
|
223
|
+
Add-Line '## 4. 工作看板(`看板.md`)'
|
|
224
|
+
Add-Line ''
|
|
225
|
+
$boardMd = Join-Path $ReportDir '看板.md'
|
|
226
|
+
if (Test-Path $boardMd) {
|
|
227
|
+
$bl = Get-Content $boardMd -Encoding UTF8
|
|
228
|
+
$cur = ''
|
|
229
|
+
$counts = @{}; $openItems = @()
|
|
230
|
+
foreach ($line in $bl) {
|
|
231
|
+
if ($line -match '^##\s*(.+?)\s*$') { $cur = $Matches[1]; $counts[$cur] = 0; continue }
|
|
232
|
+
if ($line -match '^\s*-\s*\[ \]\s*(.+)$') {
|
|
233
|
+
if ($cur) { $counts[$cur] = [int]$counts[$cur] + 1 }
|
|
234
|
+
if ($cur -eq '待办') { $openItems += $Matches[1].Trim() }
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
$total = ($counts.Values | Measure-Object -Sum).Sum
|
|
238
|
+
if (-not $total) {
|
|
239
|
+
Add-Line '_看板为空。_'
|
|
240
|
+
} else {
|
|
241
|
+
foreach ($k in $counts.Keys) { if ($counts[$k] -gt 0) { Add-Line ("- {0}:{1} 条未完成" -f $k, $counts[$k]) } }
|
|
242
|
+
if ($openItems.Count -gt 0) {
|
|
243
|
+
Add-Line ''
|
|
244
|
+
Add-Line '待办明细:'
|
|
245
|
+
foreach ($it in ($openItems | Select-Object -First 12)) { Add-Line ("- {0}" -f $it) }
|
|
246
|
+
if ($openItems.Count -gt 12) { Add-Line ("- …另有 {0} 条" -f ($openItems.Count - 12)) }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
Add-Line '_未找到 `看板.md`(看板路径由 -ReportDir 决定)。_'
|
|
251
|
+
}
|
|
252
|
+
Add-Line ''
|
|
253
|
+
|
|
254
|
+
# ---------- 5. 当日已有产物 ----------
|
|
255
|
+
Add-Line '## 5. 已知产物目录'
|
|
256
|
+
Add-Line ''
|
|
257
|
+
foreach ($d in @('_报告源文件', '_巡检', '_日报', '_协作规范')) {
|
|
258
|
+
$p = Join-Path $Workspace $d
|
|
259
|
+
if (Test-Path $p) {
|
|
260
|
+
$recent = Get-ChildItem $p -File -Recurse -Force -ErrorAction SilentlyContinue |
|
|
261
|
+
Where-Object { $_.LastWriteTime -ge $dayStart -and $_.LastWriteTime -lt $dayEnd }
|
|
262
|
+
if ($recent) {
|
|
263
|
+
foreach ($r in $recent) { Add-Line ("- ``{0}``({1:HH:mm})" -f $r.FullName, $r.LastWriteTime) }
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
Add-Line ''
|
|
268
|
+
|
|
269
|
+
Set-Content -Path $outFile -Value $sb -Encoding UTF8
|
|
270
|
+
Write-Output $outFile
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# push-to-board.ps1 —— 把日报的「明日开场清单」追加到工作看板(看板.md)。
|
|
2
|
+
# 纯 Markdown + 复选框,不依赖任何 DSH 插件,可 git 追踪、可手工改。
|
|
3
|
+
# 本脚本属于 dsh-work-summary 插件仓库,而看板/日报在数据目录(默认 ~/.dsh/dsh-work-summary),
|
|
4
|
+
# 所以脚本不再猜看板位置:-BoardPath 必须显式给出(插件会传)。
|
|
5
|
+
#
|
|
6
|
+
# 用法:
|
|
7
|
+
# pwsh -NoProfile -File push-to-board.ps1 -BoardPath ~\.dsh\dsh-work-summary\看板.md -Show
|
|
8
|
+
# pwsh -NoProfile -File push-to-board.ps1 -BoardPath ~\.dsh\dsh-work-summary\看板.md -Report ~\.dsh\dsh-work-summary\日报-2026-10-29.md
|
|
9
|
+
# pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -DryRun # 只解析不写入
|
|
10
|
+
# pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -Done "git init" # 移到「已完成」
|
|
11
|
+
# pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -Drop "git init" # 移到「已放弃」
|
|
12
|
+
#
|
|
13
|
+
# 去重:同一标题(条目取前 36 字)已在看板任意一栏出现时跳过。
|
|
14
|
+
|
|
15
|
+
param(
|
|
16
|
+
[string]$Report,
|
|
17
|
+
[string]$BoardPath,
|
|
18
|
+
[string]$Done,
|
|
19
|
+
[string]$Drop,
|
|
20
|
+
[switch]$DryRun,
|
|
21
|
+
[switch]$Show
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
$ErrorActionPreference = 'Stop'
|
|
25
|
+
$Today = (Get-Date -Format 'yyyy-MM-dd')
|
|
26
|
+
if (-not $BoardPath) {
|
|
27
|
+
throw '缺少 -BoardPath:看板在数据目录(默认 ~\.dsh\dsh-work-summary\看板.md),不在脚本旁边。'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function Read-Board {
|
|
31
|
+
if (-not (Test-Path $BoardPath)) {
|
|
32
|
+
return @(
|
|
33
|
+
'# 工作看板', '',
|
|
34
|
+
'> 由 `dsh-work-summary\push-to-board.ps1` 自动追加;手工维护也完全可以。', '',
|
|
35
|
+
'## 待办', '', '## 进行中', '', '## 已完成', ''
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
return @(Get-Content $BoardPath -Encoding UTF8)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function Get-Hash([string]$s) {
|
|
42
|
+
$norm = ($s -replace '\s', '' -replace '`', '' -replace '\*\*', '')
|
|
43
|
+
$bytes = [System.Text.Encoding]::UTF8.GetBytes($norm)
|
|
44
|
+
$sha = [System.Security.Cryptography.SHA256]::Create()
|
|
45
|
+
$hex = ([System.BitConverter]::ToString($sha.ComputeHash($bytes)) -replace '-', '').ToLower()
|
|
46
|
+
$sha.Dispose()
|
|
47
|
+
return $hex.Substring(0, 8)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function Get-Title([string]$s) {
|
|
51
|
+
$t = ($s -replace '\*\*', '' -replace '`', '').Trim()
|
|
52
|
+
foreach ($sep in ':', ';', '。', ',') {
|
|
53
|
+
$i = $t.IndexOf($sep)
|
|
54
|
+
if ($i -ge 8 -and $i -le 36) { return $t.Substring(0, $i) }
|
|
55
|
+
}
|
|
56
|
+
if ($t.Length -gt 36) { return $t.Substring(0, 36) + '…' }
|
|
57
|
+
return $t
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function Find-Section([string[]]$lines, [string]$name) {
|
|
61
|
+
for ($i = 0; $i -lt $lines.Count; $i++) {
|
|
62
|
+
if ($lines[$i] -match ('^##\s*' + [regex]::Escape($name))) { return $i }
|
|
63
|
+
}
|
|
64
|
+
return -1
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function Section-End([string[]]$lines, [int]$start) {
|
|
68
|
+
for ($i = $start + 1; $i -lt $lines.Count; $i++) {
|
|
69
|
+
if ($lines[$i] -match '^##\s') { return $i }
|
|
70
|
+
}
|
|
71
|
+
return $lines.Count
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function Save-Board([string[]]$lines) {
|
|
75
|
+
$outList = New-Object System.Collections.Generic.List[string]
|
|
76
|
+
foreach ($l in $lines) {
|
|
77
|
+
if ($l.Trim() -eq '' -and $outList.Count -gt 0 -and $outList[$outList.Count - 1].Trim() -eq '') { continue }
|
|
78
|
+
$outList.Add($l)
|
|
79
|
+
}
|
|
80
|
+
while ($outList.Count -gt 0 -and $outList[$outList.Count - 1].Trim() -eq '') { $outList.RemoveAt($outList.Count - 1) }
|
|
81
|
+
$outList.Add('')
|
|
82
|
+
Set-Content -Path $BoardPath -Value $outList -Encoding UTF8
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
$board = Read-Board
|
|
86
|
+
|
|
87
|
+
if ($Show) { $board | ForEach-Object { Write-Output $_ }; return }
|
|
88
|
+
|
|
89
|
+
# ---------- -Done / -Drop:把匹配的待办移到「已完成」/「已放弃」 ----------
|
|
90
|
+
$mode = if ($Drop) { 'drop' } elseif ($Done) { 'done' } else { $null }
|
|
91
|
+
if ($mode) {
|
|
92
|
+
$keyword = if ($mode -eq 'drop') { $Drop } else { $Done }
|
|
93
|
+
$targetSection = if ($mode -eq 'drop') { '已放弃' } else { '已完成' }
|
|
94
|
+
$todoIdx = Find-Section $board '待办'
|
|
95
|
+
if ($todoIdx -lt 0) { throw "看板缺少「## 待办」小节:$BoardPath" }
|
|
96
|
+
$todoEnd = Section-End $board $todoIdx
|
|
97
|
+
|
|
98
|
+
$kept = @(); $moved = @()
|
|
99
|
+
for ($i = 0; $i -lt $board.Count; $i++) {
|
|
100
|
+
$inTodo = ($i -gt $todoIdx -and $i -lt $todoEnd)
|
|
101
|
+
if ($inTodo -and $board[$i] -match '^\s*-\s*\[ \]' -and $board[$i].Contains($keyword)) {
|
|
102
|
+
$body = ($board[$i] -replace '^\s*-\s*\[ \]\s*', '').Trim()
|
|
103
|
+
if ($mode -eq 'drop') { $moved += ('- ⛔ {0}(放弃 {1})' -f $body, $Today) }
|
|
104
|
+
else { $moved += ('- [x] {0}(完成 {1})' -f $body, $Today) }
|
|
105
|
+
while ($i + 1 -lt $todoEnd -and $board[$i + 1] -match '^\s{2,}\S') { $i++ }
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
$kept += $board[$i]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if ($moved.Count -eq 0) { Write-Output ("「待办」里没有包含「{0}」的条目。" -f $keyword); return }
|
|
112
|
+
if ($DryRun) {
|
|
113
|
+
Write-Output ("DryRun:将处理 {0} 条:" -f $moved.Count)
|
|
114
|
+
$moved | ForEach-Object { Write-Output $_ }
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
$doneIdx = Find-Section $kept $targetSection
|
|
119
|
+
if ($doneIdx -lt 0) {
|
|
120
|
+
if ($kept.Count -gt 0 -and $kept[-1].Trim() -ne '') { $kept += '' }
|
|
121
|
+
$kept += ('## ' + $targetSection)
|
|
122
|
+
$doneIdx = $kept.Count - 1
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
$out = @()
|
|
126
|
+
$out += $kept[0..$doneIdx]
|
|
127
|
+
$tail = @()
|
|
128
|
+
if ($doneIdx + 1 -lt $kept.Count) { $tail = @($kept[($doneIdx + 1)..($kept.Count - 1)]) }
|
|
129
|
+
# 去掉紧跟标题的空行,再统一补一个空行,避免出现连续空行
|
|
130
|
+
while ($tail.Count -gt 0 -and $tail[0].Trim() -eq '') { $tail = @($tail[1..($tail.Count - 1)]) }
|
|
131
|
+
$out += ''
|
|
132
|
+
$out += $moved
|
|
133
|
+
if ($tail.Count -gt 0) { $out += $tail }
|
|
134
|
+
|
|
135
|
+
Save-Board $out
|
|
136
|
+
$verb = if ($mode -eq 'drop') { '已放弃' } else { '已标记完成' }
|
|
137
|
+
Write-Output ("{0} {1} 条:" -f $verb, $moved.Count)
|
|
138
|
+
$moved | ForEach-Object { Write-Output $_ }
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# ---------- 从日报解析「明日开场清单」 ----------
|
|
143
|
+
if (-not $Report) {
|
|
144
|
+
$Report = (Get-ChildItem (Split-Path -Parent $BoardPath) -Filter '日报-*.md' -File |
|
|
145
|
+
Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName
|
|
146
|
+
}
|
|
147
|
+
if (-not $Report -or -not (Test-Path $Report)) { throw "找不到日报文件:$Report" }
|
|
148
|
+
|
|
149
|
+
$lines = Get-Content $Report -Encoding UTF8
|
|
150
|
+
$start = -1
|
|
151
|
+
for ($i = 0; $i -lt $lines.Count; $i++) {
|
|
152
|
+
if ($lines[$i] -match '^##\s.*明日开场清单') { $start = $i + 1; break }
|
|
153
|
+
}
|
|
154
|
+
if ($start -lt 0) { throw "日报里没有「明日开场清单」小节:$Report" }
|
|
155
|
+
|
|
156
|
+
$items = @()
|
|
157
|
+
for ($i = $start; $i -lt $lines.Count; $i++) {
|
|
158
|
+
if ($lines[$i] -match '^##\s') { break }
|
|
159
|
+
if ($lines[$i] -match '^\s*(?:\d+[\.、]|[-*])\s+(.+)$') {
|
|
160
|
+
$t = $Matches[1].Trim()
|
|
161
|
+
# 以 ✅ 开头或标注「已完成」的条目视为已办,不进看板
|
|
162
|
+
if ($t -notmatch '^(✅|\[x\])' -and $t -notmatch '已完成') { $items += $t }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if ($items.Count -eq 0) { throw "「明日开场清单」里没有解析到条目:$Report" }
|
|
166
|
+
|
|
167
|
+
Write-Output ("解析到 {0} 条待办:来自 {1}" -f $items.Count, $Report)
|
|
168
|
+
foreach ($it in $items) { Write-Output (' - ' + $it) }
|
|
169
|
+
|
|
170
|
+
# ---------- 去重:同时比对「详情指纹」与「标题指纹」 ----------
|
|
171
|
+
function Get-TitleOfLine([string]$line) {
|
|
172
|
+
$parts = $line -split '|'
|
|
173
|
+
if ($parts.Count -ge 2) { return $parts[1].Trim() }
|
|
174
|
+
return ''
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# 只在「## 待办」里查重:已完成/已放弃的条目允许再次进入待办(是新的待办,不是重复)
|
|
178
|
+
$existing = @{}
|
|
179
|
+
$todoStart = Find-Section $board '待办'
|
|
180
|
+
$todoEndIdx = if ($todoStart -ge 0) { Section-End $board $todoStart } else { 0 }
|
|
181
|
+
for ($i = 0; $i -lt $board.Count; $i++) {
|
|
182
|
+
if ($todoStart -lt 0 -or $i -le $todoStart -or $i -ge $todoEndIdx) { continue }
|
|
183
|
+
$l = $board[$i]
|
|
184
|
+
if ($l -notmatch '^\s*-\s*\[ \]') { continue }
|
|
185
|
+
$tk = Get-TitleOfLine $l
|
|
186
|
+
if ($tk) { $existing[(Get-Hash $tk)] = $true }
|
|
187
|
+
if ($l -match '#h([0-9a-f]{8})') { $existing[$Matches[1]] = $true; continue }
|
|
188
|
+
# 兼容手写/旧格式条目:用紧随其后的「详情:」行(或条目正文)算指纹
|
|
189
|
+
$src2 = $l
|
|
190
|
+
if ($i + 1 -lt $board.Count -and $board[$i + 1] -match '^\s{2,}-\s*详情:(.+)$') { $src2 = $Matches[1] }
|
|
191
|
+
$existing[(Get-Hash $src2)] = $true
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
$newLines = @(); $added = 0; $skipped = @()
|
|
195
|
+
$src = Split-Path $Report -Leaf
|
|
196
|
+
foreach ($it in $items) {
|
|
197
|
+
$title = Get-Title $it
|
|
198
|
+
$hash = Get-Hash $it
|
|
199
|
+
$tkey = Get-Hash $title
|
|
200
|
+
if ($existing.ContainsKey($hash) -or $existing.ContainsKey($tkey)) { $skipped += $title; continue }
|
|
201
|
+
$newLines += ('- [ ] {0} | {1} | 来源:{2} | #h{3}' -f $Today, $title, $src, $hash)
|
|
202
|
+
$newLines += (' - 详情:{0}' -f $it)
|
|
203
|
+
$existing[$hash] = $true
|
|
204
|
+
$existing[$tkey] = $true
|
|
205
|
+
$added++
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if ($added -eq 0) { Write-Output '没有新条目需要写入(全部已存在)。'; return }
|
|
209
|
+
if ($DryRun) {
|
|
210
|
+
Write-Output ("DryRun:将写入 {0} 条:" -f $added)
|
|
211
|
+
$newLines | ForEach-Object { Write-Output $_ }
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
# ---------- 插入到「## 待办」末尾 ----------
|
|
216
|
+
$todoIdx = Find-Section $board '待办'
|
|
217
|
+
if ($todoIdx -lt 0) { throw "看板缺少「## 待办」小节:$BoardPath" }
|
|
218
|
+
$todoEnd = Section-End $board $todoIdx
|
|
219
|
+
|
|
220
|
+
$insertAt = $todoEnd
|
|
221
|
+
while ($insertAt -gt $todoIdx + 1 -and $board[$insertAt - 1].Trim() -eq '') { $insertAt-- }
|
|
222
|
+
|
|
223
|
+
$out = @()
|
|
224
|
+
if ($insertAt -gt 0) { $out += $board[0..($insertAt - 1)] }
|
|
225
|
+
# 待办为空时插在标题正下方,补一个空行保持 Markdown 结构
|
|
226
|
+
if ($out.Count -gt 0 -and $out[-1] -match '^##\s') { $out += '' }
|
|
227
|
+
$out += $newLines
|
|
228
|
+
if ($insertAt -lt $board.Count) { $out += $board[$insertAt..($board.Count - 1)] }
|
|
229
|
+
|
|
230
|
+
Save-Board $out
|
|
231
|
+
Write-Output ("已写入 {0} 条,跳过重复 {1} 条 → {2}" -f $added, $skipped.Count, $BoardPath)
|
|
232
|
+
if ($skipped.Count -gt 0) { foreach ($s in $skipped) { Write-Output (' 跳过:' + $s) } }
|