dsh-work-summary 0.2.0 → 0.3.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.
@@ -6,17 +6,28 @@
6
6
  # 用法:
7
7
  # pwsh -NoProfile -File push-to-board.ps1 -BoardPath ~\.dsh\dsh-work-summary\看板.md -Show
8
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 ... -Report ...\周报-2026-11-18_2026-11-24.md -Section 下周开场
9
10
  # pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -DryRun # 只解析不写入
10
11
  # pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -Done "git init" # 移到「已完成」
11
12
  # pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -Drop "git init" # 移到「已放弃」
13
+ # pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -Update "git init" -Priority P1 -Due 2026-11-30 -Status doing
14
+ # pwsh -NoProfile -File push-to-board.ps1 -BoardPath ... -Update "#h1234abcd" -Priority none -Due none
12
15
  #
16
+ # 条目格式:- [ ] 日期 | 标题 | 来源:… | #h指纹 | @P1 | !2026-11-30
17
+ # 后两段可省略,老看板(无优先级/截止)照常读写。日报条目末尾写 @P1 / !2026-11-30 会被带进看板。
13
18
  # 去重:同一标题(条目取前 36 字)已在看板任意一栏出现时跳过。
19
+ # 小节名由 -Section 指定:日报默认「明日开场清单」,周报/月报传「下周开场」「下月开场」。
14
20
 
15
21
  param(
16
22
  [string]$Report,
17
23
  [string]$BoardPath,
24
+ [string]$Section = '明日开场清单',
18
25
  [string]$Done,
19
26
  [string]$Drop,
27
+ [string]$Update,
28
+ [string]$Priority,
29
+ [string]$Due,
30
+ [string]$Status,
20
31
  [switch]$DryRun,
21
32
  [switch]$Show
22
33
  )
@@ -71,6 +82,44 @@ function Section-End([string[]]$lines, [int]$start) {
71
82
  return $lines.Count
72
83
  }
73
84
 
85
+ function Get-EntryMeta([string]$text) {
86
+ $priority = ''
87
+ $due = ''
88
+ $p = [regex]::Match($text, '(?i)(?:^|\s)@(p[1-3])(?=\s|$)')
89
+ if ($p.Success) { $priority = $p.Groups[1].Value.ToUpper() }
90
+ $d = [regex]::Match($text, '(?:^|\s)!(\d{4}-\d{2}-\d{2})(?=\s|$)')
91
+ if ($d.Success) { $due = $d.Groups[1].Value }
92
+ return @{ Priority = $priority; Due = $due }
93
+ }
94
+
95
+ function Remove-EntryMeta([string]$text) {
96
+ $clean = $text -replace '(?i)(?:^|\s)@p[1-3](?=\s|$)', ' '
97
+ $clean = $clean -replace '(?:^|\s)!\d{4}-\d{2}-\d{2}(?=\s|$)', ' '
98
+ return ($clean -replace '\s+', ' ').Trim()
99
+ }
100
+
101
+ # 重写条目的元数据段,保留原有顺序与详情行;没有优先级/截止时就是老格式。
102
+ function Set-EntryMeta([string]$line, [string]$priority, [string]$due) {
103
+ $body = ($line -replace '^\s*-\s*(?:\[[ xX]\]|⛔)\s*', '').Trim()
104
+ $body = $body -replace '((?:完成|放弃) \d{4}-\d{2}-\d{2})(?=\s*(?:||$))', ''
105
+ $parts = @()
106
+ foreach ($part in ($body -split '|')) {
107
+ $value = $part.Trim()
108
+ if ($value -eq '') { continue }
109
+ if ($value -match '^@[Pp][1-3]$' -or $value -match '^!\d{4}-\d{2}-\d{2}$') { continue }
110
+ $parts += (Remove-EntryMeta $value)
111
+ }
112
+ if ($priority) { $parts += ('@' + $priority.ToUpper()) }
113
+ if ($due) { $parts += ('!' + $due) }
114
+ return ('- [ ] ' + ($parts -join ' | '))
115
+ }
116
+
117
+ function Get-EntryEnd([string[]]$lines, [int]$start) {
118
+ $end = $start
119
+ while ($end + 1 -lt $lines.Count -and $lines[$end + 1] -match '^\s{2,}\S') { $end++ }
120
+ return $end
121
+ }
122
+
74
123
  function Save-Board([string[]]$lines) {
75
124
  $outList = New-Object System.Collections.Generic.List[string]
76
125
  foreach ($l in $lines) {
@@ -86,6 +135,120 @@ $board = Read-Board
86
135
 
87
136
  if ($Show) { $board | ForEach-Object { Write-Output $_ }; return }
88
137
 
138
+ # ---------- -Update:改优先级 / 截止日 / 状态,一条一条来 ----------
139
+ if ($Update) {
140
+ if ($Done -or $Drop) { throw '-Update 不能和 -Done / -Drop 同用。' }
141
+ if (-not $Priority -and -not $Due -and -not $Status) {
142
+ throw '-Update 至少要给一个 -Priority / -Due / -Status。'
143
+ }
144
+ if ($Priority -and $Priority -notmatch '^(P[1-3]|none)$') { throw "-Priority 只能是 P1/P2/P3/none,收到:$Priority" }
145
+ if ($Due -and $Due -ne 'none') {
146
+ if ($Due -notmatch '^\d{4}-\d{2}-\d{2}$') { throw "-Due 要写 YYYY-MM-DD 或 none,收到:$Due" }
147
+ try { [void][datetime]::ParseExact($Due, 'yyyy-MM-dd', $null) }
148
+ catch { throw "-Due 不是有效日期:$Due" }
149
+ }
150
+ $statusValue = if ($Status) { $Status.ToLower() } else { '' }
151
+ if ($statusValue -and $statusValue -notin @('todo', 'doing', 'done', 'drop')) {
152
+ throw "-Status 只能是 todo/doing/done/drop,收到:$Status"
153
+ }
154
+
155
+ $hits = @()
156
+ $needle = $Update.Trim()
157
+ for ($i = 0; $i -lt $board.Count; $i++) {
158
+ if ($board[$i] -notmatch '^\s*-\s*(?:\[[ xX]\]|⛔)') { continue }
159
+ if ($board[$i].IndexOf($needle, [StringComparison]::OrdinalIgnoreCase) -ge 0) { $hits += $i }
160
+ }
161
+ if ($hits.Count -eq 0) { throw "看板里没有匹配「$needle」的条目。" }
162
+ if ($hits.Count -gt 1) {
163
+ throw "「$needle」匹配到 $($hits.Count) 条,请写得更具体(也可以直接用条目里的 #h 指纹)。"
164
+ }
165
+
166
+ $start = $hits[0]
167
+ $end = Get-EntryEnd $board $start
168
+ $detail = @()
169
+ if ($end -gt $start) { $detail = @($board[($start + 1)..$end]) }
170
+
171
+ $sectionName = ''
172
+ for ($i = $start; $i -ge 0; $i--) {
173
+ if ($board[$i] -match '^##\s+(.+?)\s*$') { $sectionName = $Matches[1]; break }
174
+ }
175
+ $currentStatus = switch ($sectionName) {
176
+ '待办' { 'todo' }
177
+ '进行中' { 'doing' }
178
+ '已完成' { 'done' }
179
+ '已放弃' { 'drop' }
180
+ default { 'todo' }
181
+ }
182
+ $targetStatus = if ($statusValue) { $statusValue } else { $currentStatus }
183
+
184
+ $old = Get-EntryMeta $board[$start]
185
+ $newPriority = if ($Priority) { if ($Priority -eq 'none') { '' } else { $Priority.ToUpper() } } else { $old.Priority }
186
+ $newDue = if ($Due) { if ($Due -eq 'none') { '' } else { $Due } } else { $old.Due }
187
+ $body = (Set-EntryMeta $board[$start] $newPriority $newDue) -replace '^- \[ \]\s*', ''
188
+ $existingStamp = ''
189
+ if ($board[$start] -match '((?:完成|放弃) \d{4}-\d{2}-\d{2})') { $existingStamp = $Matches[0] }
190
+ $body = $body -replace '((?:完成|放弃) \d{4}-\d{2}-\d{2})(?=\s*(?:||$))', ''
191
+ # 只改优先级/截止日时保留原来的完成/放弃日期,别把历史改写成今天。
192
+ $stamp = if ($targetStatus -eq $currentStatus -and $existingStamp) { $existingStamp } else { "(完成 $Today)" }
193
+ $newLine = switch ($targetStatus) {
194
+ 'done' { '- [x] ' + $body + $stamp }
195
+ 'drop' { '- ⛔ ' + $body + $(if ($existingStamp -and $targetStatus -eq $currentStatus) { $existingStamp } else { "(放弃 $Today)" }) }
196
+ default { '- [ ] ' + $body }
197
+ }
198
+
199
+ if ($targetStatus -eq $currentStatus) {
200
+ if ($DryRun) {
201
+ Write-Output 'DryRun:将改为:'
202
+ Write-Output $newLine
203
+ return
204
+ }
205
+ $board[$start] = $newLine
206
+ Save-Board $board
207
+ Write-Output ("已更新 1 条 → {0}" -f $BoardPath)
208
+ Write-Output $newLine
209
+ return
210
+ }
211
+
212
+ $targetSection = switch ($targetStatus) {
213
+ 'doing' { '进行中' }
214
+ 'done' { '已完成' }
215
+ 'drop' { '已放弃' }
216
+ default { '待办' }
217
+ }
218
+ if ($DryRun) {
219
+ Write-Output ("DryRun:将移到「{0}」:" -f $targetSection)
220
+ Write-Output $newLine
221
+ return
222
+ }
223
+
224
+ $kept = New-Object System.Collections.Generic.List[string]
225
+ for ($i = 0; $i -lt $board.Count; $i++) {
226
+ if ($i -ge $start -and $i -le $end) { continue }
227
+ $kept.Add($board[$i])
228
+ }
229
+ $targetIdx = Find-Section $kept.ToArray() $targetSection
230
+ if ($targetIdx -lt 0) {
231
+ if ($kept.Count -gt 0 -and $kept[$kept.Count - 1].Trim() -ne '') { $kept.Add('') }
232
+ $kept.Add('## ' + $targetSection)
233
+ $targetIdx = $kept.Count - 1
234
+ }
235
+ $targetEnd = Section-End $kept.ToArray() $targetIdx
236
+ $insertAt = $targetEnd
237
+ while ($insertAt -gt $targetIdx + 1 -and $kept[$insertAt - 1].Trim() -eq '') { $insertAt-- }
238
+
239
+ $out = New-Object System.Collections.Generic.List[string]
240
+ for ($i = 0; $i -lt $insertAt; $i++) { $out.Add($kept[$i]) }
241
+ if ($out.Count -gt 0 -and $out[$out.Count - 1] -match '^##\s') { $out.Add('') }
242
+ $out.Add($newLine)
243
+ foreach ($line in $detail) { $out.Add($line) }
244
+ for ($i = $insertAt; $i -lt $kept.Count; $i++) { $out.Add($kept[$i]) }
245
+
246
+ Save-Board $out.ToArray()
247
+ Write-Output ("已移到「{0}」→ {1}" -f $targetSection, $BoardPath)
248
+ Write-Output $newLine
249
+ return
250
+ }
251
+
89
252
  # ---------- -Done / -Drop:把匹配的待办移到「已完成」/「已放弃」 ----------
90
253
  $mode = if ($Drop) { 'drop' } elseif ($Done) { 'done' } else { $null }
91
254
  if ($mode) {
@@ -139,7 +302,7 @@ if ($mode) {
139
302
  return
140
303
  }
141
304
 
142
- # ---------- 从日报解析「明日开场清单」 ----------
305
+ # ---------- 从日报/周报解析指定小节(默认「明日开场清单」) ----------
143
306
  if (-not $Report) {
144
307
  $Report = (Get-ChildItem (Split-Path -Parent $BoardPath) -Filter '日报-*.md' -File |
145
308
  Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName
@@ -148,10 +311,11 @@ if (-not $Report -or -not (Test-Path $Report)) { throw "找不到日报文件:
148
311
 
149
312
  $lines = Get-Content $Report -Encoding UTF8
150
313
  $start = -1
314
+ $sectionPattern = '^##\s.*' + [regex]::Escape($Section)
151
315
  for ($i = 0; $i -lt $lines.Count; $i++) {
152
- if ($lines[$i] -match '^##\s.*明日开场清单') { $start = $i + 1; break }
316
+ if ($lines[$i] -match $sectionPattern) { $start = $i + 1; break }
153
317
  }
154
- if ($start -lt 0) { throw "日报里没有「明日开场清单」小节:$Report" }
318
+ if ($start -lt 0) { throw "日报里没有「$Section」小节:$Report" }
155
319
 
156
320
  $items = @()
157
321
  for ($i = $start; $i -lt $lines.Count; $i++) {
@@ -159,13 +323,17 @@ for ($i = $start; $i -lt $lines.Count; $i++) {
159
323
  if ($lines[$i] -match '^\s*(?:\d+[\.、]|[-*])\s+(.+)$') {
160
324
  $t = $Matches[1].Trim()
161
325
  # 以 ✅ 开头或标注「已完成」的条目视为已办,不进看板
162
- if ($t -notmatch '^(✅|\[x\])' -and $t -notmatch '已完成') { $items += $t }
326
+ if ($t -notmatch '^(✅|\[x\])' -and $t -notmatch '已完成') {
327
+ $meta = Get-EntryMeta $t
328
+ $clean = Remove-EntryMeta $t
329
+ if ($clean -ne '') { $items += [pscustomobject]@{ Text = $clean; Priority = $meta.Priority; Due = $meta.Due } }
330
+ }
163
331
  }
164
332
  }
165
- if ($items.Count -eq 0) { throw "「明日开场清单」里没有解析到条目:$Report" }
333
+ if ($items.Count -eq 0) { throw "「$Section」里没有解析到条目:$Report" }
166
334
 
167
335
  Write-Output ("解析到 {0} 条待办:来自 {1}" -f $items.Count, $Report)
168
- foreach ($it in $items) { Write-Output (' - ' + $it) }
336
+ foreach ($it in $items) { Write-Output (' - ' + $it.Text) }
169
337
 
170
338
  # ---------- 去重:同时比对「详情指纹」与「标题指纹」 ----------
171
339
  function Get-TitleOfLine([string]$line) {
@@ -194,18 +362,21 @@ for ($i = 0; $i -lt $board.Count; $i++) {
194
362
  $newLines = @(); $added = 0; $skipped = @()
195
363
  $src = Split-Path $Report -Leaf
196
364
  foreach ($it in $items) {
197
- $title = Get-Title $it
198
- $hash = Get-Hash $it
365
+ $title = Get-Title $it.Text
366
+ $hash = Get-Hash $it.Text
199
367
  $tkey = Get-Hash $title
200
368
  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)
369
+ $metaText = ''
370
+ if ($it.Priority) { $metaText += ' | @' + $it.Priority }
371
+ if ($it.Due) { $metaText += ' | !' + $it.Due }
372
+ $newLines += ('- [ ] {0} | {1} | 来源:{2} | #h{3}{4}' -f $Today, $title, $src, $hash, $metaText)
373
+ $newLines += (' - 详情:{0}' -f $it.Text)
203
374
  $existing[$hash] = $true
204
375
  $existing[$tkey] = $true
205
376
  $added++
206
377
  }
207
378
 
208
- if ($added -eq 0) { Write-Output '没有新条目需要写入(全部已存在)。'; return }
379
+ if ($added -eq 0) { Write-Output ("已写入 0 条,跳过重复 {0} 条 → {1}" -f $skipped.Count, $BoardPath); return }
209
380
  if ($DryRun) {
210
381
  Write-Output ("DryRun:将写入 {0} 条:" -f $added)
211
382
  $newLines | ForEach-Object { Write-Output $_ }