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.
- package/PROMPT.md +21 -2
- package/README.md +42 -49
- package/client.js +867 -27
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +136 -25
- package/index.js +986 -51
- package/package.json +4 -4
- package/scripts/collect-day.ps1 +95 -0
- package/scripts/collect-range.ps1 +388 -0
- package/scripts/push-to-board.ps1 +182 -11
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { spawn } from 'node:child_process'
|
|
15
|
-
import { readFileSync } from 'node:fs'
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
16
16
|
import { appendFile, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
17
17
|
import { homedir } from 'node:os'
|
|
18
18
|
import { dirname, join } from 'node:path'
|
|
@@ -56,6 +56,20 @@ const DEFAULTS = {
|
|
|
56
56
|
scheduleTime: '23:00',
|
|
57
57
|
/** 计划时区。 */
|
|
58
58
|
scheduleTimeZone: 'Asia/Shanghai',
|
|
59
|
+
/** 是否让插件托管每周周报任务(每周一生成上一周)。 */
|
|
60
|
+
weekScheduleEnabled: true,
|
|
61
|
+
/** 周报计划时间 HH:mm;固定每周一。 */
|
|
62
|
+
weekScheduleTime: '01:00',
|
|
63
|
+
/** 周报计划任务标题;标题稳定才好认领和更新。 */
|
|
64
|
+
weekScheduleTitle: '每周工作周报',
|
|
65
|
+
/** 是否让插件托管每月月报任务(每月 1 号生成上个月)。 */
|
|
66
|
+
monthScheduleEnabled: true,
|
|
67
|
+
/** 月报计划时间 HH:mm;固定每月 1 号。 */
|
|
68
|
+
monthScheduleTime: '01:00',
|
|
69
|
+
/** 月报计划任务标题。 */
|
|
70
|
+
monthScheduleTitle: '每月工作月报',
|
|
71
|
+
/** 日报保存时的软校验;只提醒,不阻断落盘。 */
|
|
72
|
+
quality: { minEvidence: 3 },
|
|
59
73
|
/** 运行日志目录;留空表示 `<reportDir>\_日志`。设置页改的是这个键。 */
|
|
60
74
|
logDir: '',
|
|
61
75
|
}
|
|
@@ -70,6 +84,27 @@ const SECTIONS = [
|
|
|
70
84
|
['六', '明日开场清单'],
|
|
71
85
|
]
|
|
72
86
|
|
|
87
|
+
/** 空话词库:只用于日报软校验提醒,不决定落盘与否。 */
|
|
88
|
+
const FILLER_WORDS = [
|
|
89
|
+
'继续推进', '加强沟通', '持续优化', '进一步提升', '稳步推进', '深入推进',
|
|
90
|
+
'扎实做好', '高度重视', '协同发力', '形成闭环', '提质增效', '落地见效',
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
/** 建议小节里算「可执行」的命令线索。 */
|
|
94
|
+
const COMMAND_HINT = /(?:^|[\s`((])(?:npm|pnpm|yarn|git|node|pwsh|powershell|python|pip|dotnet|cargo|docker|kubectl|rg|curl|make)\b|(?:^|[\s`((])(?:Get|Set|New|Remove|Test|Start|Stop|Invoke|Import|Export|Select|Where|ForEach)-[A-Za-z]+/m
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 路径/提交号线索。分开写是为了让 Windows 盘符、UNC、POSIX/相对路径、
|
|
98
|
+
* 带扩展名的文件名和 7–40 位十六进制提交号都能被认出来。
|
|
99
|
+
*/
|
|
100
|
+
const EVIDENCE_PATTERNS = [
|
|
101
|
+
/[A-Za-z]:[\\/][^\s`"'<>|,。;:、))]+/g,
|
|
102
|
+
/\\\\[^\s`"'<>|,。;:、))]+/g,
|
|
103
|
+
/(?<![\w])(?:\.{1,2}[\\/]|[A-Za-z_][\w.-]*[\\/])[^\s`"'<>|,。;:、))]+/g,
|
|
104
|
+
/\b[\w.-]+\.(?:md|ps1|js|mjs|cjs|json|ya?ml|toml|txt|log|ts|tsx|jsx|py|cs|go|rs|sh|bat|cmd|exe|svg|png)\b/gi,
|
|
105
|
+
/\b[0-9a-f]{7,40}\b/gi,
|
|
106
|
+
]
|
|
107
|
+
|
|
73
108
|
/**
|
|
74
109
|
* 合并配置:只让显式给出的值覆盖默认值。
|
|
75
110
|
* @param {Record<string, unknown>} config - patch 里的 config。
|
|
@@ -85,6 +120,12 @@ function resolveConfig(config) {
|
|
|
85
120
|
if (typeof saved.logDir === 'string' && saved.logDir.trim() !== '') merged.logDir = saved.logDir.trim()
|
|
86
121
|
if (typeof saved.reportDir === 'string' && saved.reportDir.trim() !== '') merged.reportDir = saved.reportDir.trim()
|
|
87
122
|
if (typeof saved.workspace === 'string' && saved.workspace.trim() !== '') merged.workspace = saved.workspace.trim()
|
|
123
|
+
for (const key of ['weekScheduleTime', 'monthScheduleTime']) {
|
|
124
|
+
if (typeof saved[key] === 'string' && /^([01]\d|2[0-3]):[0-5]\d$/.test(saved[key])) merged[key] = saved[key]
|
|
125
|
+
}
|
|
126
|
+
for (const key of ['weekScheduleEnabled', 'monthScheduleEnabled']) {
|
|
127
|
+
if (typeof saved[key] === 'boolean') merged[key] = saved[key]
|
|
128
|
+
}
|
|
88
129
|
return merged
|
|
89
130
|
}
|
|
90
131
|
|
|
@@ -143,30 +184,34 @@ async function logLine(config, level, message) {
|
|
|
143
184
|
|
|
144
185
|
/**
|
|
145
186
|
* 写回设置页的选项。只认已知键,避免任意字段被塞进配置文件。
|
|
146
|
-
* @param {
|
|
187
|
+
* @param {Record<string, string | boolean | undefined>} patch - 要保存的键。
|
|
147
188
|
* @returns {Promise<Record<string, unknown>>} 保存后的全部设置。
|
|
148
189
|
*/
|
|
149
190
|
async function writeSettings(patch) {
|
|
150
191
|
const current = readSettings()
|
|
151
192
|
const next = {}
|
|
152
|
-
for (const key of ['reportDir', 'logDir', 'workspace']) {
|
|
193
|
+
for (const key of ['reportDir', 'logDir', 'workspace', 'weekScheduleTime', 'monthScheduleTime']) {
|
|
153
194
|
const value = typeof patch[key] === 'string' ? patch[key] : current[key]
|
|
154
195
|
if (typeof value === 'string') next[key] = value
|
|
155
196
|
}
|
|
197
|
+
for (const key of ['weekScheduleEnabled', 'monthScheduleEnabled']) {
|
|
198
|
+
const value = typeof patch[key] === 'boolean' ? patch[key] : current[key]
|
|
199
|
+
if (typeof value === 'boolean') next[key] = value
|
|
200
|
+
}
|
|
156
201
|
await mkdir(dirname(SETTINGS_FILE), { recursive: true })
|
|
157
202
|
await writeFile(SETTINGS_FILE, `${JSON.stringify(next, null, 2)}\n`, 'utf8')
|
|
158
203
|
return next
|
|
159
204
|
}
|
|
160
205
|
|
|
161
206
|
/**
|
|
162
|
-
*
|
|
163
|
-
* @param {Awaited<ReturnType<typeof scheduleState
|
|
207
|
+
* 设置页要的完整状态:日报/周报/月报三条定时任务 + 目录。
|
|
208
|
+
* @param {{ daily: Awaited<ReturnType<typeof scheduleState>>, week: Record<string, unknown>, month: Record<string, unknown> }} states - 定时任务状态。
|
|
164
209
|
* @param {typeof DEFAULTS} config - 生效配置。
|
|
165
210
|
* @returns {Record<string, unknown>} 响应体。
|
|
166
211
|
*/
|
|
167
|
-
function settingsPayload(
|
|
212
|
+
function settingsPayload(states, config) {
|
|
168
213
|
return {
|
|
169
|
-
...
|
|
214
|
+
...states.daily,
|
|
170
215
|
reportDir: config.reportDir,
|
|
171
216
|
reportDirDefault: DATA_HOME,
|
|
172
217
|
workspace: config.workspace,
|
|
@@ -174,6 +219,12 @@ function settingsPayload(state, config) {
|
|
|
174
219
|
logDir: logDirOf(config),
|
|
175
220
|
logDirDefault: join(config.reportDir, '_日志'),
|
|
176
221
|
logPattern: 'dsh-work-summary-YYYY-MM-DD.log',
|
|
222
|
+
week: states.week,
|
|
223
|
+
month: states.month,
|
|
224
|
+
weekTitle: config.weekScheduleTitle,
|
|
225
|
+
monthTitle: config.monthScheduleTitle,
|
|
226
|
+
weekTimeDefault: config.weekScheduleTime,
|
|
227
|
+
monthTimeDefault: config.monthScheduleTime,
|
|
177
228
|
}
|
|
178
229
|
}
|
|
179
230
|
|
|
@@ -245,6 +296,433 @@ function buildTemplate(date) {
|
|
|
245
296
|
].join('\n')
|
|
246
297
|
}
|
|
247
298
|
|
|
299
|
+
/**
|
|
300
|
+
* 周期报告(周报/月报)的类型表:标题前缀与首尾两节的名字随类型变。
|
|
301
|
+
* 中间两节固定为「关键产出」「未清与复发」。
|
|
302
|
+
*/
|
|
303
|
+
const PERIOD_KINDS = {
|
|
304
|
+
week: { label: '周报', title: '工作周报', first: '本周主线', last: '下周开场' },
|
|
305
|
+
month: { label: '月报', title: '工作月报', first: '本月主线', last: '下月开场' },
|
|
306
|
+
custom: { label: '周期报告', title: '周期总结', first: '本期主线', last: '下期开场' },
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 解析 YYYY-MM-DD 为 UTC 零点毫秒数;格式或日期不存在都直接报错。
|
|
311
|
+
* @param {string} text - 日期。
|
|
312
|
+
* @returns {number} 毫秒时间戳。
|
|
313
|
+
*/
|
|
314
|
+
function parseDay(text) {
|
|
315
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(text)) throw new Error(`日期格式应为 YYYY-MM-DD,收到:${text}`)
|
|
316
|
+
const [year, month, day] = text.split('-').map(Number)
|
|
317
|
+
const stamp = Date.UTC(year, month - 1, day)
|
|
318
|
+
const check = new Date(stamp)
|
|
319
|
+
if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day) {
|
|
320
|
+
throw new Error(`日期不存在:${text}`)
|
|
321
|
+
}
|
|
322
|
+
return stamp
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** 两个 YYYY-MM-DD 之间相差的天数(b - a)。 */
|
|
326
|
+
function daysBetween(from, to) {
|
|
327
|
+
return Math.round((parseDay(to) - parseDay(from)) / 86400000)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** 在 YYYY-MM-DD 上加若干天。 */
|
|
331
|
+
function shiftDay(date, delta) {
|
|
332
|
+
return new Date(parseDay(date) + delta * 86400000).toISOString().slice(0, 10)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** 某月的最后一天。 */
|
|
336
|
+
function lastDayOfMonth(date) {
|
|
337
|
+
const [year, month] = date.split('-').map(Number)
|
|
338
|
+
return new Date(Date.UTC(year, month, 0)).toISOString().slice(0, 10)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 把工具入参解析成区间:类型、起止、天数、是否整月。
|
|
343
|
+
* 不传 from/to 时按 kind 取默认区间(week=本周一至今天,month=本月 1 号至今天);
|
|
344
|
+
* offset 表示往前数几个完整周期(周报=整周,月报=整月),定时任务用它生成上一周期。
|
|
345
|
+
* @param {{ from?: string, to?: string, kind?: 'week'|'month'|'custom', offset?: number }} args - 工具入参。
|
|
346
|
+
* @param {string} timeZone - 时区。
|
|
347
|
+
* @returns {{ from: string, to: string, kind: 'week'|'month'|'custom', span: number, wholeMonth: boolean }} 区间。
|
|
348
|
+
*/
|
|
349
|
+
function resolvePeriod(args, timeZone) {
|
|
350
|
+
let from = typeof args.from === 'string' ? args.from.trim() : ''
|
|
351
|
+
let to = typeof args.to === 'string' ? args.to.trim() : ''
|
|
352
|
+
let kind = args.kind
|
|
353
|
+
const offset = args.offset === undefined ? 0 : Number(args.offset)
|
|
354
|
+
|
|
355
|
+
if (!Number.isInteger(offset) || offset < 0 || offset > 60) {
|
|
356
|
+
throw new Error(`offset 应为 0–60 的整数,收到:${args.offset}`)
|
|
357
|
+
}
|
|
358
|
+
if (offset > 0 && (from || to)) throw new Error('给了 from/to 就不要再传 offset')
|
|
359
|
+
if ((from && !to) || (!from && to)) throw new Error('from 和 to 要么都传,要么都不传')
|
|
360
|
+
if (kind !== undefined && !Object.prototype.hasOwnProperty.call(PERIOD_KINDS, kind)) {
|
|
361
|
+
throw new Error(`kind 只能是 week / month / custom,收到:${kind}`)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const today = dateInZone(timeZone)
|
|
365
|
+
if (!from) {
|
|
366
|
+
if (kind === 'custom') throw new Error('custom 周期需要同时给 from 和 to')
|
|
367
|
+
if (kind === 'month') {
|
|
368
|
+
const [year, month] = today.split('-').map(Number)
|
|
369
|
+
from = new Date(Date.UTC(year, month - 1 - offset, 1)).toISOString().slice(0, 10)
|
|
370
|
+
to = offset === 0 ? today : lastDayOfMonth(from)
|
|
371
|
+
} else {
|
|
372
|
+
kind = 'week'
|
|
373
|
+
const weekday = new Date(parseDay(today)).getUTCDay()
|
|
374
|
+
const monday = shiftDay(today, weekday === 0 ? -6 : 1 - weekday)
|
|
375
|
+
from = shiftDay(monday, -7 * offset)
|
|
376
|
+
to = offset === 0 ? today : shiftDay(from, 6)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const span = daysBetween(from, to) + 1
|
|
381
|
+
if (span < 1) throw new Error(`结束日期不能早于起始日期:${from} ~ ${to}`)
|
|
382
|
+
if (span > 400) throw new Error(`区间最长 400 天,当前 ${span} 天:${from} ~ ${to}`)
|
|
383
|
+
|
|
384
|
+
const wholeMonth = from.slice(0, 7) === to.slice(0, 7) && from.endsWith('-01') && to === lastDayOfMonth(from)
|
|
385
|
+
if (kind === undefined) {
|
|
386
|
+
kind = wholeMonth ? 'month' : span === 7 ? 'week' : 'custom'
|
|
387
|
+
}
|
|
388
|
+
return { from, to, kind, span, wholeMonth }
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 周期报告的文件名。整月月报用 `月报-YYYY-MM.md`,方便按月份排序。
|
|
393
|
+
* @param {{ from: string, to: string, kind: string, wholeMonth: boolean }} range - 区间。
|
|
394
|
+
* @returns {string} 文件名。
|
|
395
|
+
*/
|
|
396
|
+
function periodReportName(range) {
|
|
397
|
+
if (range.kind === 'week') return `周报-${range.from}_${range.to}.md`
|
|
398
|
+
if (range.kind === 'month') {
|
|
399
|
+
return range.wholeMonth ? `月报-${range.from.slice(0, 7)}.md` : `月报-${range.from}_${range.to}.md`
|
|
400
|
+
}
|
|
401
|
+
return `周期-${range.from}_${range.to}.md`
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* 周期报告的四节标题。首节接受「本周/本月/本期主线」,末节接受「下周/下月/下期开场」。
|
|
406
|
+
* @param {string} kind - week / month / custom。
|
|
407
|
+
* @returns {string[]} 四节标题。
|
|
408
|
+
*/
|
|
409
|
+
function periodSectionLabels(kind) {
|
|
410
|
+
const spec = PERIOD_KINDS[kind] ?? PERIOD_KINDS.custom
|
|
411
|
+
return [spec.first, '关键产出', '未清与复发', spec.last]
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* 列出周期报告缺少的固定小节;首尾两节兼容三种前缀。
|
|
416
|
+
* @param {string} text - 周期报告正文。
|
|
417
|
+
* @param {string} kind - week / month / custom。
|
|
418
|
+
* @returns {string[]} 形如 `## 一、本周主线`。
|
|
419
|
+
*/
|
|
420
|
+
function missingPeriodSections(text, kind) {
|
|
421
|
+
const holes = []
|
|
422
|
+
const specs = [
|
|
423
|
+
['一', '(?:本周|本月|本期)主线'],
|
|
424
|
+
['二', '关键产出'],
|
|
425
|
+
['三', '未清与复发'],
|
|
426
|
+
['四', '(?:下周|下月|下期)开场'],
|
|
427
|
+
]
|
|
428
|
+
for (const [num, label] of specs) {
|
|
429
|
+
const pattern = new RegExp(`^##\\s*(?:[一二三四五六七八九十]+\\s*[、..]\\s*)?${label}`, 'm')
|
|
430
|
+
if (!pattern.test(text)) holes.push(`## ${num}、${periodSectionLabels(kind)[['一', '二', '三', '四'].indexOf(num)]}`)
|
|
431
|
+
}
|
|
432
|
+
return holes
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* 周期报告骨架,交给模型填空;留着「待填」时校验会拒绝。
|
|
437
|
+
* @param {{ from: string, to: string, kind: string, wholeMonth: boolean }} range - 区间。
|
|
438
|
+
* @returns {string} Markdown 模板。
|
|
439
|
+
*/
|
|
440
|
+
function buildPeriodTemplate(range) {
|
|
441
|
+
const spec = PERIOD_KINDS[range.kind] ?? PERIOD_KINDS.custom
|
|
442
|
+
const heading = range.kind === 'month' && range.wholeMonth
|
|
443
|
+
? range.from.slice(0, 7)
|
|
444
|
+
: `${range.from} ~ ${range.to}`
|
|
445
|
+
const labels = periodSectionLabels(range.kind)
|
|
446
|
+
return [
|
|
447
|
+
`# ${spec.title} · ${heading}`,
|
|
448
|
+
'',
|
|
449
|
+
`> 区间:${range.from} ~ ${range.to}(${range.span} 天)`,
|
|
450
|
+
'',
|
|
451
|
+
`## 一、${labels[0]}`,
|
|
452
|
+
'(待填:这段区间真正推进的一两条主线,给证据,不要逐日流水账)',
|
|
453
|
+
'',
|
|
454
|
+
`## 二、${labels[1]}`,
|
|
455
|
+
'(待填:产出物 | 路径 | 状态 | 说明;只写区间内新增或完成的)',
|
|
456
|
+
'',
|
|
457
|
+
`## 三、${labels[2]}`,
|
|
458
|
+
'(待填:仍未清掉的事项、跨天复发的风险;写明已经挂了几天)',
|
|
459
|
+
'',
|
|
460
|
+
`## 四、${labels[3]}`,
|
|
461
|
+
`(待填:下个周期开工就能动手的 3 件事,具体到文件/命令)`,
|
|
462
|
+
].join('\n')
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* 取日报某小节里的非空行。
|
|
467
|
+
* @param {string} text - 日报正文。
|
|
468
|
+
* @param {string} number - 中文序号:一/二/…
|
|
469
|
+
* @returns {string[]} 行。
|
|
470
|
+
*/
|
|
471
|
+
function sectionLines(text, number) {
|
|
472
|
+
const lines = String(text).split(/\r?\n/)
|
|
473
|
+
const startPattern = new RegExp(`^##\\s*${number}\\s*[、..]`)
|
|
474
|
+
let start = -1
|
|
475
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
476
|
+
if (startPattern.test(lines[i])) { start = i + 1; break }
|
|
477
|
+
}
|
|
478
|
+
if (start < 0) return []
|
|
479
|
+
const out = []
|
|
480
|
+
for (let i = start; i < lines.length; i += 1) {
|
|
481
|
+
if (/^##\s/.test(lines[i])) break
|
|
482
|
+
const trimmed = lines[i].trim()
|
|
483
|
+
if (trimmed === '' || /^---+$/.test(trimmed)) continue
|
|
484
|
+
out.push(trimmed)
|
|
485
|
+
}
|
|
486
|
+
return out
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* 正文里的路径/提交号引用,按去重后的条目数计。
|
|
491
|
+
* @param {string} text - 日报正文。
|
|
492
|
+
* @returns {Set<string>} 归一化后的引用。
|
|
493
|
+
*/
|
|
494
|
+
function evidenceRefs(text) {
|
|
495
|
+
const found = new Set()
|
|
496
|
+
// 链接里的域名和路径不算「工作证据」,先去掉;行内代码保留内容,方便识别 `index.js`。
|
|
497
|
+
const clean = String(text).replace(/https?:\/\/\S+/g, ' ').replace(/`([^`]*)`/g, ' $1 ')
|
|
498
|
+
for (const pattern of EVIDENCE_PATTERNS) {
|
|
499
|
+
for (const match of clean.matchAll(pattern)) {
|
|
500
|
+
const value = match[0]
|
|
501
|
+
.replace(/^[`'"([(]+/, '')
|
|
502
|
+
.replace(/[`'")\]).,;:,。;:、]+$/, '')
|
|
503
|
+
.toLowerCase()
|
|
504
|
+
if (value.length >= 2) found.add(value)
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
// 同一个 Windows 路径会同时命中「完整路径 / 相对后缀 / 文件名」,只留最长的那条,避免虚高。
|
|
508
|
+
const refs = new Set()
|
|
509
|
+
for (const value of [...found].sort((a, b) => b.length - a.length)) {
|
|
510
|
+
if ([...refs].some(existing => existing.includes(value))) continue
|
|
511
|
+
refs.add(value)
|
|
512
|
+
}
|
|
513
|
+
return refs
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** 建议小节里是否已有路径或可执行命令。 */
|
|
517
|
+
function hasPathOrCommand(text) {
|
|
518
|
+
if (evidenceRefs(text).size > 0) return true
|
|
519
|
+
if (COMMAND_HINT.test(text)) return true
|
|
520
|
+
// 反引号里带空格的多半是命令或脚本调用,例如 `collect-day.ps1 -Date 2026-11-25`。
|
|
521
|
+
return (String(text).match(/`[^`\n]+`/g) ?? []).some(span => /\s/.test(span.trim()))
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** 读取 `quality.minEvidence`:支持嵌套对象,也兼容扁平点号键;非法值退回默认 3。 */
|
|
525
|
+
function minEvidenceOf(config) {
|
|
526
|
+
const quality = config?.quality
|
|
527
|
+
const nested = quality && typeof quality === 'object' ? quality.minEvidence : quality
|
|
528
|
+
const flat = config?.['quality.minEvidence']
|
|
529
|
+
const raw = flat ?? nested ?? DEFAULTS.quality.minEvidence
|
|
530
|
+
const value = Number(raw)
|
|
531
|
+
return Number.isInteger(value) && value > 0 ? value : DEFAULTS.quality.minEvidence
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* 日报软校验:只生成提醒,不抛错,也不阻止落盘。
|
|
536
|
+
* @param {string} content - 日报正文(未补 footer)。
|
|
537
|
+
* @param {number} minEvidence - 证据引用下限。
|
|
538
|
+
* @returns {string[]} 提醒文案。
|
|
539
|
+
*/
|
|
540
|
+
function qualityWarnings(content, minEvidence) {
|
|
541
|
+
const warnings = []
|
|
542
|
+
const refs = evidenceRefs(content)
|
|
543
|
+
if (refs.size < minEvidence) {
|
|
544
|
+
warnings.push(`证据偏少:正文只有 ${refs.size} 处路径/提交号引用(建议至少 ${minEvidence} 处)`)
|
|
545
|
+
}
|
|
546
|
+
const filler = FILLER_WORDS.filter(word => String(content).includes(word))
|
|
547
|
+
if (filler.length > 0) {
|
|
548
|
+
warnings.push(`空话词:${filler.join('、')};换成具体动作、对象或结果`)
|
|
549
|
+
}
|
|
550
|
+
const advice = sectionLines(content, '五').join('\n')
|
|
551
|
+
if (advice.trim() !== '' && !hasPathOrCommand(advice)) {
|
|
552
|
+
warnings.push('「五、后续建议」没有路径或命令,建议补上具体文件、脚本或命令')
|
|
553
|
+
}
|
|
554
|
+
return warnings
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* 逐日热力值:非空行数 + 产出条目数 × 3。
|
|
559
|
+
* 行数代表当天写了多少,产出条目代表落地的结果;权重 3 让「有产出」的一天明显亮于「写得长但没产出」。
|
|
560
|
+
* @param {string} content - 日报正文。
|
|
561
|
+
* @returns {{ lines: number, outputs: number, score: number }} 统计值。
|
|
562
|
+
*/
|
|
563
|
+
function heatStats(content) {
|
|
564
|
+
const text = String(content)
|
|
565
|
+
const lines = text.split(/\r?\n/).filter((line) => {
|
|
566
|
+
const trimmed = line.trim()
|
|
567
|
+
return trimmed !== '' && !/^---+$/.test(trimmed)
|
|
568
|
+
}).length
|
|
569
|
+
let outputs = 0
|
|
570
|
+
for (const line of sectionLines(text, '三')) {
|
|
571
|
+
const trimmed = line.trim()
|
|
572
|
+
if (/^\|[\s:|-]+\|$/.test(trimmed)) continue
|
|
573
|
+
if (/^\|/.test(trimmed)) {
|
|
574
|
+
const first = trimmed.slice(1).split('|')[0].trim()
|
|
575
|
+
if (/^(产出物|项目|条目|路径)$/.test(first)) continue
|
|
576
|
+
outputs += 1
|
|
577
|
+
continue
|
|
578
|
+
}
|
|
579
|
+
if (/^(?:[-*]|\d+[.、])\s+/.test(trimmed)) outputs += 1
|
|
580
|
+
}
|
|
581
|
+
return { lines, outputs, score: lines + outputs * 3 }
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** 去掉列表序号与加粗标记,保留正文。 */
|
|
585
|
+
function cleanItem(line) {
|
|
586
|
+
return String(line).replace(/^\s*(?:\d+[.、]|[-*])\s+/, '').replace(/\*\*/g, '').trim()
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** 表格行转成「单元格 | 单元格」;不是表格行就原样返回。 */
|
|
590
|
+
function tableCells(line) {
|
|
591
|
+
const trimmed = line.trim()
|
|
592
|
+
if (!/^\|.*\|$/.test(trimmed)) return cleanItem(trimmed)
|
|
593
|
+
return trimmed.slice(1, -1).split('|').map(cell => cell.trim()).filter(Boolean).join(' | ')
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** 看板条目的标题:`日期 | 标题 | 来源…` 取第二段。 */
|
|
597
|
+
function boardTitle(line) {
|
|
598
|
+
const parts = String(line).split('|')
|
|
599
|
+
return (parts.length >= 2 ? parts[1] : parts[0]).trim()
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** 截断过长的一行,避免自动草稿把整段原文搬进去。 */
|
|
603
|
+
function clip(text, max) {
|
|
604
|
+
const value = String(text).replace(/\s+/g, ' ').trim()
|
|
605
|
+
return value.length > max ? `${value.slice(0, max)}…` : value
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* 不传 content 时的兜底草稿:按区间日报的六节与看板拼出四节,保证验收里「直接产出可读周报」。
|
|
610
|
+
* 只做摘录和计数,不做跨天推断;模型可以在此基础上改写后再提交。
|
|
611
|
+
* @param {{ from: string, to: string, kind: string, span: number, wholeMonth: boolean }} range - 区间。
|
|
612
|
+
* @param {string[]} days - 区间内每一天。
|
|
613
|
+
* @param {Map<string, string>} daily - 日期 → 日报正文。
|
|
614
|
+
* @param {{ open: string[] }} board - 看板未完成条目。
|
|
615
|
+
* @param {string} today - 今天 YYYY-MM-DD(用于算待办已挂天数)。
|
|
616
|
+
* @returns {string} 四节正文。
|
|
617
|
+
*/
|
|
618
|
+
function composePeriodDraft(range, days, daily, board, today) {
|
|
619
|
+
const spec = PERIOD_KINDS[range.kind] ?? PERIOD_KINDS.custom
|
|
620
|
+
const labels = periodSectionLabels(range.kind)
|
|
621
|
+
const covered = days.filter(day => daily.has(day))
|
|
622
|
+
const missing = days.filter(day => !daily.has(day))
|
|
623
|
+
const heading = range.kind === 'month' && range.wholeMonth
|
|
624
|
+
? range.from.slice(0, 7)
|
|
625
|
+
: `${range.from} ~ ${range.to}`
|
|
626
|
+
|
|
627
|
+
const out = [`# ${spec.title} · ${heading}`, '', `> 区间:${range.from} ~ ${range.to}(${range.span} 天)`, '']
|
|
628
|
+
|
|
629
|
+
out.push(`## 一、${labels[0]}`, '')
|
|
630
|
+
out.push(`本区间 ${range.from} ~ ${range.to},共 ${range.span} 天;有日报 ${covered.length} 天${missing.length ? `、缺 ${missing.length} 天(${missing.map(day => day.slice(5)).join('、')})` : ''}。`)
|
|
631
|
+
out.push('')
|
|
632
|
+
if (covered.length === 0) {
|
|
633
|
+
out.push('_区间内没有日报,无法从记录里归纳主线。_')
|
|
634
|
+
} else {
|
|
635
|
+
out.push('按天摘录日报「今日概览」里的主线,未做跨天推断:')
|
|
636
|
+
out.push('')
|
|
637
|
+
for (const day of covered) {
|
|
638
|
+
const first = sectionLines(daily.get(day), '一')[0]
|
|
639
|
+
if (first) out.push(`- **${day.slice(5)}**:${clip(cleanItem(first), 180)}`)
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
out.push('')
|
|
643
|
+
|
|
644
|
+
out.push(`## 二、${labels[1]}`, '')
|
|
645
|
+
const outputs = []
|
|
646
|
+
for (const day of covered) {
|
|
647
|
+
for (const line of sectionLines(daily.get(day), '三')) {
|
|
648
|
+
if (/^\|[\s:|-]+\|$/.test(line) || /^\|\s*(产出物|建议|项目)\s*\|/.test(line)) continue
|
|
649
|
+
outputs.push(`- ${day.slice(5)}:${clip(tableCells(line), 220)}`)
|
|
650
|
+
if (outputs.length >= 24) break
|
|
651
|
+
}
|
|
652
|
+
if (outputs.length >= 24) break
|
|
653
|
+
}
|
|
654
|
+
out.push(...(outputs.length ? outputs : ['_区间日报里没有产出记录。_']))
|
|
655
|
+
out.push('')
|
|
656
|
+
|
|
657
|
+
out.push(`## 三、${labels[2]}`, '')
|
|
658
|
+
const open = Array.isArray(board.open) ? board.open : []
|
|
659
|
+
out.push(`看板当前未完成 ${open.length} 条:`)
|
|
660
|
+
out.push('')
|
|
661
|
+
if (open.length === 0) {
|
|
662
|
+
out.push('_看板没有未完成条目。_')
|
|
663
|
+
} else {
|
|
664
|
+
for (const line of open.slice(0, 8)) {
|
|
665
|
+
const bare = line.replace(/^-\s*\[ \]\s*/, '')
|
|
666
|
+
const dateMatch = /^(\d{4}-\d{2}-\d{2})/.exec(bare)
|
|
667
|
+
let age = ''
|
|
668
|
+
if (dateMatch) {
|
|
669
|
+
const gap = daysBetween(dateMatch[1], today)
|
|
670
|
+
if (gap >= 0) age = `(已挂 ${gap} 天)`
|
|
671
|
+
}
|
|
672
|
+
out.push(`- ${boardTitle(bare)}${age}`)
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
out.push('')
|
|
676
|
+
|
|
677
|
+
const riskDays = new Map()
|
|
678
|
+
for (const day of covered) {
|
|
679
|
+
for (const line of sectionLines(daily.get(day), '四')) {
|
|
680
|
+
const item = cleanItem(line)
|
|
681
|
+
const key = item
|
|
682
|
+
.replace(/([^)]*)/g, '')
|
|
683
|
+
.replace(/\d+/g, '#')
|
|
684
|
+
.replace(/[\s,。;:、!?,.;:!?()()【】\[\]「」“”"-]/g, '')
|
|
685
|
+
.slice(0, 40)
|
|
686
|
+
if (key.length < 6) continue
|
|
687
|
+
if (!riskDays.has(key)) riskDays.set(key, { dates: [], sample: clip(item, 60) })
|
|
688
|
+
const entry = riskDays.get(key)
|
|
689
|
+
if (!entry.dates.includes(day)) entry.dates.push(day)
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const repeated = [...riskDays.values()].filter(entry => entry.dates.length >= 2).sort((a, b) => b.dates.length - a.dates.length)
|
|
693
|
+
if (repeated.length > 0) {
|
|
694
|
+
out.push('跨天重复出现的风险:')
|
|
695
|
+
out.push('')
|
|
696
|
+
for (const entry of repeated.slice(0, 6)) {
|
|
697
|
+
out.push(`- ${entry.sample}(${entry.dates.length} 天:${entry.dates.map(day => day.slice(5)).join('、')})`)
|
|
698
|
+
}
|
|
699
|
+
out.push('')
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
out.push(`## 四、${labels[3]}`, '')
|
|
703
|
+
const lastWithList = [...covered].reverse().find(day => sectionLines(daily.get(day), '六').length > 0)
|
|
704
|
+
let actions = lastWithList
|
|
705
|
+
? sectionLines(daily.get(lastWithList), '六').map(cleanItem).filter(Boolean).slice(0, 3)
|
|
706
|
+
: []
|
|
707
|
+
if (actions.length === 0) actions = open.map(boardTitle).slice(0, 3)
|
|
708
|
+
if (actions.length === 0) actions = ['先补上区间内缺失的日报,再决定下个周期主攻方向。']
|
|
709
|
+
out.push(lastWithList
|
|
710
|
+
? `取自 ${lastWithList} 日报「明日开场清单」的末版(${actions.length} 条):`
|
|
711
|
+
: `取自看板当前未完成条目(${actions.length} 条):`)
|
|
712
|
+
out.push('')
|
|
713
|
+
actions.forEach((item, index) => out.push(`${index + 1}. ${item}`))
|
|
714
|
+
out.push('')
|
|
715
|
+
|
|
716
|
+
return out.join('\n')
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/** 周期报告的统一 footer:写清正文依据的区间源数据。 */
|
|
720
|
+
function withPeriodFooter(content, range, stamp) {
|
|
721
|
+
if (/数据来源:/.test(content)) return content
|
|
722
|
+
const source = `_源数据\\周期-${range.from}_${range.to}.md`
|
|
723
|
+
return `${content.replace(/\s*$/, '')}\n\n---\n数据来源:\`${source}\` | 生成时间:${stamp}\n`
|
|
724
|
+
}
|
|
725
|
+
|
|
248
726
|
/**
|
|
249
727
|
* 看板文件路径(push-to-board.ps1 的 -BoardPath)。
|
|
250
728
|
* @param {typeof DEFAULTS} config - 生效配置。
|
|
@@ -269,6 +747,71 @@ async function readBoard(reportDir) {
|
|
|
269
747
|
}
|
|
270
748
|
}
|
|
271
749
|
|
|
750
|
+
/**
|
|
751
|
+
* 校验并归一化看板更新参数:优先级、截止日、状态三者至少给一个。
|
|
752
|
+
* @param {{ priority?: unknown, due?: unknown, status?: unknown }} input - 原始参数。
|
|
753
|
+
* @returns {{ priority?: string, due?: string, status?: string }} 可传给脚本的参数。
|
|
754
|
+
*/
|
|
755
|
+
function boardPatch(input) {
|
|
756
|
+
const patch = {}
|
|
757
|
+
if (input.priority !== undefined) {
|
|
758
|
+
const value = String(input.priority).trim().toUpperCase()
|
|
759
|
+
if (!['P1', 'P2', 'P3', 'NONE'].includes(value)) throw new Error('priority 只能是 P1 / P2 / P3 / none')
|
|
760
|
+
patch.priority = value === 'NONE' ? 'none' : value
|
|
761
|
+
}
|
|
762
|
+
if (input.due !== undefined) {
|
|
763
|
+
const value = String(input.due).trim()
|
|
764
|
+
if (value.toLowerCase() !== 'none') parseDay(value)
|
|
765
|
+
patch.due = value.toLowerCase() === 'none' ? 'none' : value
|
|
766
|
+
}
|
|
767
|
+
if (input.status !== undefined) {
|
|
768
|
+
const value = String(input.status).trim().toLowerCase()
|
|
769
|
+
if (!['todo', 'doing', 'done', 'drop'].includes(value)) {
|
|
770
|
+
throw new Error('status 只能是 todo / doing / done / drop')
|
|
771
|
+
}
|
|
772
|
+
patch.status = value
|
|
773
|
+
}
|
|
774
|
+
if (Object.keys(patch).length === 0) throw new Error('update 至少要给 priority / due / status 之一')
|
|
775
|
+
return patch
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* 调 push-to-board.ps1 改一条看板条目的优先级、截止日或状态。
|
|
780
|
+
* @param {typeof DEFAULTS} config - 生效配置。
|
|
781
|
+
* @param {string} keyword - 标题关键词或 #h 指纹。
|
|
782
|
+
* @param {{ priority?: string, due?: string, status?: string }} patch - 更新参数。
|
|
783
|
+
* @param {AbortSignal | undefined} signal - 取消信号。
|
|
784
|
+
* @returns {Promise<{ stdout: string, board: { open: string[], text: string } }>} 脚本输出与更新后的看板。
|
|
785
|
+
*/
|
|
786
|
+
async function updateBoard(config, keyword, patch, signal) {
|
|
787
|
+
const args = ['-Update', keyword, '-BoardPath', boardPathOf(config)]
|
|
788
|
+
if (patch.priority !== undefined) args.push('-Priority', patch.priority)
|
|
789
|
+
if (patch.due !== undefined) args.push('-Due', patch.due)
|
|
790
|
+
if (patch.status !== undefined) args.push('-Status', patch.status)
|
|
791
|
+
const result = await runScript(config, 'push-to-board.ps1', args, signal)
|
|
792
|
+
if (result.code !== 0) {
|
|
793
|
+
throw new Error(`更新看板失败(退出码 ${result.code}):\n${tail(result.stderr || result.stdout)}`)
|
|
794
|
+
}
|
|
795
|
+
return { stdout: result.stdout.trim(), board: await readBoard(config.reportDir) }
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* 读取 POST body;空 body 当 {},非法 JSON 由调用方转成 400。
|
|
800
|
+
* @param {import('node:http').IncomingMessage} req - 请求。
|
|
801
|
+
* @returns {Promise<Record<string, unknown>>} 解析后的 body。
|
|
802
|
+
*/
|
|
803
|
+
async function readJsonBody(req) {
|
|
804
|
+
const chunks = []
|
|
805
|
+
for await (const chunk of req) chunks.push(chunk)
|
|
806
|
+
const raw = Buffer.concat(chunks).toString('utf8')
|
|
807
|
+
if (raw.trim() === '') return {}
|
|
808
|
+
try {
|
|
809
|
+
return JSON.parse(raw)
|
|
810
|
+
} catch {
|
|
811
|
+
throw new Error('请求体不是合法 JSON')
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
272
815
|
/**
|
|
273
816
|
* 取输出末尾若干行用于报错。
|
|
274
817
|
* @param {string} text - 进程输出。
|
|
@@ -285,7 +828,8 @@ function tail(text) {
|
|
|
285
828
|
* `& script '-Date' x` 会把 "-Date" 绑到第一个位置参数),所以新增开关必须补进这里。
|
|
286
829
|
*/
|
|
287
830
|
const PS_SWITCHES = new Set([
|
|
288
|
-
'-Date', '-NoSessions', '-Report', '-BoardPath', '-Show', '-Done', '-Drop', '-DryRun',
|
|
831
|
+
'-Date', '-From', '-To', '-Section', '-NoSessions', '-Report', '-BoardPath', '-Show', '-Done', '-Drop', '-DryRun',
|
|
832
|
+
'-Update', '-Priority', '-Due', '-Status',
|
|
289
833
|
'-Workspace', '-ReportDir', '-DshHome',
|
|
290
834
|
])
|
|
291
835
|
|
|
@@ -389,21 +933,49 @@ async function readState(config) {
|
|
|
389
933
|
names = []
|
|
390
934
|
}
|
|
391
935
|
const reports = []
|
|
392
|
-
for (const name of names.sort().reverse().slice(0,
|
|
936
|
+
for (const name of names.sort().reverse().slice(0, 91)) {
|
|
393
937
|
try {
|
|
394
938
|
const content = await readFile(join(config.reportDir, name), 'utf8')
|
|
939
|
+
const stats = heatStats(content)
|
|
395
940
|
reports.push({
|
|
396
941
|
date: name.slice(3, 13),
|
|
397
942
|
file: name,
|
|
398
943
|
size: Buffer.byteLength(content, 'utf8'),
|
|
944
|
+
lines: stats.lines,
|
|
945
|
+
outputs: stats.outputs,
|
|
946
|
+
score: stats.score,
|
|
399
947
|
content,
|
|
400
948
|
})
|
|
401
949
|
} catch {
|
|
402
950
|
// 单篇读不了就跳过,不让整个页面失败
|
|
403
951
|
}
|
|
404
952
|
}
|
|
953
|
+
const periods = []
|
|
954
|
+
let periodNames = []
|
|
955
|
+
try {
|
|
956
|
+
periodNames = (await readdir(config.reportDir)).filter(name => /^(?:周报|月报|周期)-.+\.md$/.test(name))
|
|
957
|
+
} catch {
|
|
958
|
+
periodNames = []
|
|
959
|
+
}
|
|
960
|
+
for (const name of periodNames.sort().reverse().slice(0, 40)) {
|
|
961
|
+
try {
|
|
962
|
+
const content = await readFile(join(config.reportDir, name), 'utf8')
|
|
963
|
+
const kind = name.startsWith('周报') ? 'week' : name.startsWith('月报') ? 'month' : 'custom'
|
|
964
|
+
const period = name.replace(/^(?:周报|月报|周期)-/, '').replace(/\.md$/, '').replace('_', ' ~ ')
|
|
965
|
+
periods.push({
|
|
966
|
+
file: name,
|
|
967
|
+
kind,
|
|
968
|
+
period,
|
|
969
|
+
size: Buffer.byteLength(content, 'utf8'),
|
|
970
|
+
content,
|
|
971
|
+
})
|
|
972
|
+
} catch {
|
|
973
|
+
// 同上:单篇失败不拖垮页面
|
|
974
|
+
}
|
|
975
|
+
}
|
|
405
976
|
return {
|
|
406
977
|
reportDir: config.reportDir,
|
|
978
|
+
today: dateInZone(config.scheduleTimeZone),
|
|
407
979
|
updatedAt: new Date().toISOString(),
|
|
408
980
|
board: {
|
|
409
981
|
text: board.text,
|
|
@@ -411,17 +983,27 @@ async function readState(config) {
|
|
|
411
983
|
done: lines.filter(line => /^- \[x\]/i.test(line)).length,
|
|
412
984
|
},
|
|
413
985
|
reports,
|
|
986
|
+
periods,
|
|
414
987
|
}
|
|
415
988
|
}
|
|
416
989
|
|
|
417
|
-
/**
|
|
990
|
+
/** 找出插件托管的那条日报任务:标题前缀或提示词特征都算。周期任务的提示词不含日报特征。 */
|
|
418
991
|
function findOwnTask(items, config) {
|
|
419
992
|
return items.find((task) => {
|
|
420
993
|
const title = String(task.title ?? '')
|
|
421
994
|
const prompt = String(task.prompt ?? '')
|
|
995
|
+
const looksDaily = /daily_report_collect|dsh-work-summary/.test(prompt) && !/work_summary_period/.test(prompt)
|
|
422
996
|
return title === config.scheduleTitle
|
|
423
997
|
|| title.startsWith(config.scheduleTitle)
|
|
424
|
-
||
|
|
998
|
+
|| looksDaily
|
|
999
|
+
}) ?? null
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/** 按标题找插件自己的任务;标题是稳定契约,不靠提示词猜。 */
|
|
1003
|
+
function findTaskByTitle(items, title) {
|
|
1004
|
+
return items.find((task) => {
|
|
1005
|
+
const current = String(task.title ?? '')
|
|
1006
|
+
return current === title || current.startsWith(title)
|
|
425
1007
|
}) ?? null
|
|
426
1008
|
}
|
|
427
1009
|
|
|
@@ -445,28 +1027,74 @@ function dailyRrule(timeZone, time) {
|
|
|
445
1027
|
return `DTSTART;TZID=${timeZone}:${today}T${hh}${mm}00\nRRULE:FREQ=DAILY;INTERVAL=1;BYHOUR=${hour};BYMINUTE=${minute}`
|
|
446
1028
|
}
|
|
447
1029
|
|
|
448
|
-
/**
|
|
449
|
-
|
|
1030
|
+
/** 从某天起最近的一个指定星期几(0=周日,1=周一)。 */
|
|
1031
|
+
function nextWeekday(date, weekday) {
|
|
1032
|
+
const current = new Date(parseDay(date)).getUTCDay()
|
|
1033
|
+
return shiftDay(date, (weekday - current + 7) % 7)
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/** 每周一固定时刻的 rrule:周报任务用。 */
|
|
1037
|
+
function weeklyRrule(timeZone, time) {
|
|
1038
|
+
const [hour, minute] = String(time).split(':').map(Number)
|
|
1039
|
+
const start = nextWeekday(dateInZone(timeZone), 1).replace(/-/g, '')
|
|
1040
|
+
const hh = String(hour).padStart(2, '0')
|
|
1041
|
+
const mm = String(minute).padStart(2, '0')
|
|
1042
|
+
return `DTSTART;TZID=${timeZone}:${start}T${hh}${mm}00\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;BYHOUR=${hour};BYMINUTE=${minute}`
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** 每月 1 号固定时刻的 rrule:月报任务用。 */
|
|
1046
|
+
function monthlyRrule(timeZone, time) {
|
|
1047
|
+
const [hour, minute] = String(time).split(':').map(Number)
|
|
1048
|
+
const today = dateInZone(timeZone)
|
|
1049
|
+
const [year, month, day] = today.split('-').map(Number)
|
|
1050
|
+
const start = day === 1
|
|
1051
|
+
? today
|
|
1052
|
+
: `${month === 12 ? year + 1 : year}-${String(month === 12 ? 1 : month + 1).padStart(2, '0')}-01`
|
|
1053
|
+
const hh = String(hour).padStart(2, '0')
|
|
1054
|
+
const mm = String(minute).padStart(2, '0')
|
|
1055
|
+
return `DTSTART;TZID=${timeZone}:${start.replace(/-/g, '')}T${hh}${mm}00\nRRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=1;BYHOUR=${hour};BYMINUTE=${minute}`
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** 通用任务状态:没找到时用配置里的默认时间撑住设置页。 */
|
|
1059
|
+
async function taskState(scheduleCtx, title, fallbackTime, timeZone) {
|
|
450
1060
|
const page = await scheduleCtx.schedule.list({ limit: 200 })
|
|
451
|
-
const task =
|
|
452
|
-
if (!task) {
|
|
453
|
-
return { found: false, scheduleTitle: config.scheduleTitle, timeZone: config.scheduleTimeZone, time: config.scheduleTime }
|
|
454
|
-
}
|
|
1061
|
+
const task = findTaskByTitle(page.items ?? [], title)
|
|
1062
|
+
if (!task) return { found: false, title, timeZone, time: fallbackTime }
|
|
455
1063
|
const parsed = parseRruleTime(task)
|
|
456
|
-
const hour = parsed.hour ?? Number(
|
|
457
|
-
const minute = parsed.minute ?? Number(
|
|
1064
|
+
const hour = parsed.hour ?? Number(fallbackTime.split(':')[0])
|
|
1065
|
+
const minute = parsed.minute ?? Number(fallbackTime.split(':')[1] ?? 0)
|
|
458
1066
|
return {
|
|
459
1067
|
found: true,
|
|
460
1068
|
id: task.id,
|
|
461
1069
|
title: task.title,
|
|
462
1070
|
active: task.status === 'active',
|
|
463
1071
|
time: `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`,
|
|
464
|
-
timeZone: parsed.timeZone ??
|
|
1072
|
+
timeZone: parsed.timeZone ?? timeZone,
|
|
465
1073
|
nextRunAt: task.scheduledAtLocal ?? task.scheduledAt ?? null,
|
|
466
1074
|
target: task.target?.kind ?? null,
|
|
467
1075
|
}
|
|
468
1076
|
}
|
|
469
1077
|
|
|
1078
|
+
/** 设置页要的日报任务状态。 */
|
|
1079
|
+
async function scheduleState(scheduleCtx, config) {
|
|
1080
|
+
const state = await taskState(scheduleCtx, config.scheduleTitle, config.scheduleTime, config.scheduleTimeZone)
|
|
1081
|
+
if (!state.found) {
|
|
1082
|
+
return { found: false, scheduleTitle: config.scheduleTitle, timeZone: config.scheduleTimeZone, time: config.scheduleTime }
|
|
1083
|
+
}
|
|
1084
|
+
return state
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/** 设置页要的周报/月报任务状态。 */
|
|
1088
|
+
async function periodScheduleState(scheduleCtx, config, kind) {
|
|
1089
|
+
const week = kind === 'week'
|
|
1090
|
+
return taskState(
|
|
1091
|
+
scheduleCtx,
|
|
1092
|
+
week ? config.weekScheduleTitle : config.monthScheduleTitle,
|
|
1093
|
+
week ? config.weekScheduleTime : config.monthScheduleTime,
|
|
1094
|
+
config.scheduleTimeZone,
|
|
1095
|
+
)
|
|
1096
|
+
}
|
|
1097
|
+
|
|
470
1098
|
/**
|
|
471
1099
|
* 注册三个工具,并按配置托管计划任务。
|
|
472
1100
|
* @param {import('@deepseek-ai/cordis').Context} ctx - 插件上下文。
|
|
@@ -486,7 +1114,7 @@ export function apply(ctx, rawConfig) {
|
|
|
486
1114
|
description:
|
|
487
1115
|
'采集某一天的工作痕迹,生成日报的源数据文件并返回它的路径、小节清单和日报模板。'
|
|
488
1116
|
+ '写日报前先调用它:结果里的 sourcePath 要读一遍,template 是必须填满的六节骨架。'
|
|
489
|
-
+ '
|
|
1117
|
+
+ '采集写 _源数据;超过 60 个时自动把旧文件按季度归档到 _归档。',
|
|
490
1118
|
parameters: {
|
|
491
1119
|
type: 'object',
|
|
492
1120
|
additionalProperties: false,
|
|
@@ -543,6 +1171,10 @@ export function apply(ctx, rawConfig) {
|
|
|
543
1171
|
throw new Error(`采集脚本未产出 ${date} 的源数据:${tail(result.stdout) || String(error)}`)
|
|
544
1172
|
}
|
|
545
1173
|
const lines = text.split(/\r?\n/)
|
|
1174
|
+
// 归档结果只出现在源数据里;这里顺手抄一行到运行日志,失败也不影响采集。
|
|
1175
|
+
for (const note of lines.filter(line => /^>\s*归档/.test(line))) {
|
|
1176
|
+
await logLine(config, note.includes('失败') ? 'warn' : 'info', note.replace(/^>\s*/, ''))
|
|
1177
|
+
}
|
|
546
1178
|
const headings = lines.filter(line => /^##\s/.test(line)).map(line => line.trim())
|
|
547
1179
|
const board = await readBoard(config.reportDir)
|
|
548
1180
|
return {
|
|
@@ -562,7 +1194,8 @@ export function apply(ctx, rawConfig) {
|
|
|
562
1194
|
description:
|
|
563
1195
|
'校验并落盘当天日报,然后把它「六、明日开场清单」推进看板。'
|
|
564
1196
|
+ '正文必须包含六个固定小节(一、今日概览 … 六、明日开场清单);缺节或留占位符会直接报错且不写文件,'
|
|
565
|
-
+ '按报错修好后重调即可。已存在同名日报会被整篇覆盖。'
|
|
1197
|
+
+ '按报错修好后重调即可。已存在同名日报会被整篇覆盖。'
|
|
1198
|
+
+ '落盘后会做证据密度、空话词、建议可执行性的软校验,提醒放在 warnings 与 text 里,不阻断写入。',
|
|
566
1199
|
parameters: {
|
|
567
1200
|
type: 'object',
|
|
568
1201
|
additionalProperties: false,
|
|
@@ -584,6 +1217,11 @@ export function apply(ctx, rawConfig) {
|
|
|
584
1217
|
pushed: { type: 'integer' },
|
|
585
1218
|
skipped: { type: 'integer' },
|
|
586
1219
|
boardOpen: { type: 'integer' },
|
|
1220
|
+
warnings: {
|
|
1221
|
+
type: 'array',
|
|
1222
|
+
items: { type: 'string' },
|
|
1223
|
+
description: '软校验提醒(证据密度 / 空话词 / 建议可执行性);为空表示没发现问题。',
|
|
1224
|
+
},
|
|
587
1225
|
text: { type: 'string' },
|
|
588
1226
|
},
|
|
589
1227
|
},
|
|
@@ -602,6 +1240,8 @@ export function apply(ctx, rawConfig) {
|
|
|
602
1240
|
if (problems.length > 0) {
|
|
603
1241
|
throw new Error(`日报未写入,先修正:\n- ${problems.join('\n- ')}`)
|
|
604
1242
|
}
|
|
1243
|
+
// 质量检查放在硬校验之后、写盘之前:只收集提醒,不改变落盘结果。
|
|
1244
|
+
const warnings = qualityWarnings(content, minEvidenceOf(config))
|
|
605
1245
|
|
|
606
1246
|
const stamp = stampInZone(config.scheduleTimeZone)
|
|
607
1247
|
const withFooter = /数据来源:/.test(content)
|
|
@@ -631,7 +1271,142 @@ export function apply(ctx, rawConfig) {
|
|
|
631
1271
|
const summary = shouldPush
|
|
632
1272
|
? `日报已写入 ${reportPath};看板 ${pushed ? `新增 ${pushed} 条` : '无新增条目'}${skipped ? `,跳过重复 ${skipped} 条` : ''},当前未完成 ${board.open.length} 条。`
|
|
633
1273
|
: `日报已写入 ${reportPath};按要求未推送看板。`
|
|
634
|
-
|
|
1274
|
+
const warningText = warnings.length > 0
|
|
1275
|
+
? `质量提醒(不影响落盘):\n- ${warnings.join('\n- ')}`
|
|
1276
|
+
: ''
|
|
1277
|
+
return {
|
|
1278
|
+
date,
|
|
1279
|
+
reportPath,
|
|
1280
|
+
pushed,
|
|
1281
|
+
skipped,
|
|
1282
|
+
boardOpen: board.open.length,
|
|
1283
|
+
warnings,
|
|
1284
|
+
text: [summary, pushText, warningText].filter(Boolean).join('\n'),
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
})
|
|
1288
|
+
|
|
1289
|
+
ctx.tools.register({
|
|
1290
|
+
name: 'work_summary_period',
|
|
1291
|
+
description:
|
|
1292
|
+
'聚合一个日期区间的周报/月报:先跑 collect-range.ps1 生成区间源数据,再写四节正文并推看板。'
|
|
1293
|
+
+ '四节固定为「主线 / 关键产出 / 未清与复发 / 开场」,缺节、正文过短或留占位符会报错且不写文件。'
|
|
1294
|
+
+ '不传 content 时按区间日报与看板自动拼一份可读草稿;传了 content 就按给定正文校验落盘。'
|
|
1295
|
+
+ 'kind 不传时自动推断:整月=month、跨度 7 天=week、其余=custom。'
|
|
1296
|
+
+ 'offset 用于定时任务生成上一完整周期:周报 offset=1 是上周一至周日,月报 offset=1 是上一个自然月。',
|
|
1297
|
+
parameters: {
|
|
1298
|
+
type: 'object',
|
|
1299
|
+
additionalProperties: false,
|
|
1300
|
+
properties: {
|
|
1301
|
+
from: { type: 'string', description: '起始日 YYYY-MM-DD;与 to 成对出现。都不传时 week=本周一至今天、month=本月 1 号至今天。' },
|
|
1302
|
+
to: { type: 'string', description: '结束日 YYYY-MM-DD(含当天)。' },
|
|
1303
|
+
kind: { type: 'string', enum: ['week', 'month', 'custom'], description: '报告类型;不传则按区间推断。' },
|
|
1304
|
+
offset: { type: 'integer', minimum: 0, maximum: 60, description: '往前数几个完整周期,默认 0;与 from/to 互斥。周报=整周,月报=整月。' },
|
|
1305
|
+
content: { type: 'string', description: '四节正文;不传则用区间日报自动聚合成草稿。' },
|
|
1306
|
+
push: { type: 'boolean', description: '是否把「开场」小节推进看板,默认 true。' },
|
|
1307
|
+
},
|
|
1308
|
+
},
|
|
1309
|
+
output: {
|
|
1310
|
+
schema: {
|
|
1311
|
+
type: 'object',
|
|
1312
|
+
additionalProperties: false,
|
|
1313
|
+
required: ['periodPath', 'reportPath', 'pushed', 'skipped', 'boardOpen', 'text'],
|
|
1314
|
+
properties: {
|
|
1315
|
+
periodPath: { type: 'string' },
|
|
1316
|
+
reportPath: { type: 'string' },
|
|
1317
|
+
pushed: { type: 'integer' },
|
|
1318
|
+
skipped: { type: 'integer' },
|
|
1319
|
+
boardOpen: { type: 'integer' },
|
|
1320
|
+
text: { type: 'string' },
|
|
1321
|
+
},
|
|
1322
|
+
},
|
|
1323
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
1324
|
+
},
|
|
1325
|
+
async execute(args, exec) {
|
|
1326
|
+
const range = resolvePeriod(args, config.scheduleTimeZone)
|
|
1327
|
+
const periodPath = join(config.reportDir, '_源数据', `周期-${range.from}_${range.to}.md`)
|
|
1328
|
+
const collected = await runScript(
|
|
1329
|
+
config,
|
|
1330
|
+
'collect-range.ps1',
|
|
1331
|
+
['-From', range.from, '-To', range.to, '-Workspace', config.workspace, '-ReportDir', config.reportDir],
|
|
1332
|
+
exec.signal,
|
|
1333
|
+
)
|
|
1334
|
+
if (collected.code !== 0) {
|
|
1335
|
+
throw new Error(`区间采集失败(退出码 ${collected.code}):\n${tail(collected.stderr || collected.stdout)}`)
|
|
1336
|
+
}
|
|
1337
|
+
if (!existsSync(periodPath)) {
|
|
1338
|
+
throw new Error(`区间采集脚本未产出 ${periodPath}:\n${tail(collected.stdout)}`)
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const days = []
|
|
1342
|
+
for (let day = range.from; day <= range.to; day = shiftDay(day, 1)) days.push(day)
|
|
1343
|
+
const daily = new Map()
|
|
1344
|
+
for (const day of days) {
|
|
1345
|
+
try {
|
|
1346
|
+
daily.set(day, await readFile(join(config.reportDir, `日报-${day}.md`), 'utf8'))
|
|
1347
|
+
} catch {
|
|
1348
|
+
// 缺日报就跳过;缺了几天不影响整体聚合
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
const board = await readBoard(config.reportDir)
|
|
1353
|
+
const provided = typeof args.content === 'string' && args.content.trim() !== ''
|
|
1354
|
+
let content = provided
|
|
1355
|
+
? String(args.content)
|
|
1356
|
+
: composePeriodDraft(range, days, daily, board, dateInZone(config.scheduleTimeZone))
|
|
1357
|
+
|
|
1358
|
+
const problems = []
|
|
1359
|
+
const missing = missingPeriodSections(content, range.kind)
|
|
1360
|
+
if (missing.length > 0) problems.push(`缺少小节:${missing.join('、')}`)
|
|
1361
|
+
const body = content.replace(/^#[^\n]*\n/m, '')
|
|
1362
|
+
if (body.trim().length < 200) problems.push(`正文过短(${body.trim().length} 字符),确认不是只写了骨架`)
|
|
1363
|
+
if (/\bTODO\b|待填|\{\{/.test(content)) problems.push('仍留有占位符(TODO / 待填 / {{…}})')
|
|
1364
|
+
if (problems.length > 0) {
|
|
1365
|
+
throw new Error(`周期报告未写入,先修正:\n- ${problems.join('\n- ')}`)
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
const stamp = stampInZone(config.scheduleTimeZone)
|
|
1369
|
+
const reportName = periodReportName(range)
|
|
1370
|
+
const reportPath = join(config.reportDir, reportName)
|
|
1371
|
+
await mkdir(config.reportDir, { recursive: true })
|
|
1372
|
+
await writeFile(reportPath, withPeriodFooter(content, range, stamp), 'utf8')
|
|
1373
|
+
|
|
1374
|
+
const shouldPush = args.push ?? config.pushOnSave
|
|
1375
|
+
let pushed = 0
|
|
1376
|
+
let skipped = 0
|
|
1377
|
+
let pushText = ''
|
|
1378
|
+
if (shouldPush) {
|
|
1379
|
+
const section = periodSectionLabels(range.kind)[3]
|
|
1380
|
+
const result = await runScript(
|
|
1381
|
+
config,
|
|
1382
|
+
'push-to-board.ps1',
|
|
1383
|
+
['-Report', reportPath, '-BoardPath', boardPathOf(config), '-Section', section],
|
|
1384
|
+
exec.signal,
|
|
1385
|
+
)
|
|
1386
|
+
if (result.code !== 0) {
|
|
1387
|
+
throw new Error(`周期报告已写入 ${reportPath},但推送看板失败(退出码 ${result.code}):\n${tail(result.stderr || result.stdout)}`)
|
|
1388
|
+
}
|
|
1389
|
+
pushText = result.stdout.trim()
|
|
1390
|
+
const match = /已写入\s*(\d+)\s*条[,,]\s*跳过重复\s*(\d+)\s*条/.exec(pushText)
|
|
1391
|
+
if (match) {
|
|
1392
|
+
pushed = Number(match[1])
|
|
1393
|
+
skipped = Number(match[2])
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
const after = await readBoard(config.reportDir)
|
|
1398
|
+
const kindLabel = PERIOD_KINDS[range.kind]?.label ?? '周期报告'
|
|
1399
|
+
const summary = shouldPush
|
|
1400
|
+
? `${kindLabel}已写入 ${reportPath};区间源数据 ${periodPath};看板 ${pushed ? `新增 ${pushed} 条` : '无新增条目'}${skipped ? `,跳过重复 ${skipped} 条` : ''},当前未完成 ${after.open.length} 条。`
|
|
1401
|
+
: `${kindLabel}已写入 ${reportPath};区间源数据 ${periodPath};按要求未推送看板。`
|
|
1402
|
+
return {
|
|
1403
|
+
periodPath,
|
|
1404
|
+
reportPath,
|
|
1405
|
+
pushed,
|
|
1406
|
+
skipped,
|
|
1407
|
+
boardOpen: after.open.length,
|
|
1408
|
+
text: `${summary}${provided ? '' : '\n正文由区间日报自动聚合,可直接使用,也可改写后用 content 重交。'}\n${pushText}`.trim(),
|
|
1409
|
+
}
|
|
635
1410
|
},
|
|
636
1411
|
})
|
|
637
1412
|
|
|
@@ -639,14 +1414,18 @@ export function apply(ctx, rawConfig) {
|
|
|
639
1414
|
name: 'daily_report_board',
|
|
640
1415
|
description:
|
|
641
1416
|
'查看或维护工作看板(_日报\\看板.md)。show 列出未完成待办;done 把匹配的待办移到「已完成」;'
|
|
642
|
-
+ 'drop
|
|
1417
|
+
+ 'drop 把决定不做的移到「已放弃」(不是完成);update 改一条的优先级、截止日或状态。'
|
|
1418
|
+
+ 'done/drop/update 需要 keyword(标题子串,或条目里的 #h 指纹)。',
|
|
643
1419
|
parameters: {
|
|
644
1420
|
type: 'object',
|
|
645
1421
|
additionalProperties: false,
|
|
646
1422
|
required: ['action'],
|
|
647
1423
|
properties: {
|
|
648
|
-
action: { type: 'string', enum: ['show', 'done', 'drop'], description: 'show | done | drop。' },
|
|
649
|
-
keyword: { type: 'string', description: 'done/drop
|
|
1424
|
+
action: { type: 'string', enum: ['show', 'done', 'drop', 'update'], description: 'show | done | drop | update。' },
|
|
1425
|
+
keyword: { type: 'string', description: 'done/drop/update 必填,待办标题里的关键词或 #h 指纹。' },
|
|
1426
|
+
priority: { type: 'string', enum: ['P1', 'P2', 'P3', 'none'], description: 'update 可选:优先级,none 表示清空。' },
|
|
1427
|
+
due: { type: 'string', description: 'update 可选:截止日 YYYY-MM-DD,none 表示清空。' },
|
|
1428
|
+
status: { type: 'string', enum: ['todo', 'doing', 'done', 'drop'], description: 'update 可选:目标状态,省略则只改元数据。' },
|
|
650
1429
|
},
|
|
651
1430
|
},
|
|
652
1431
|
output: {
|
|
@@ -658,6 +1437,7 @@ export function apply(ctx, rawConfig) {
|
|
|
658
1437
|
action: { type: 'string' },
|
|
659
1438
|
openCount: { type: 'integer' },
|
|
660
1439
|
open: { type: 'array', items: { type: 'string' } },
|
|
1440
|
+
updated: { type: 'string' },
|
|
661
1441
|
text: { type: 'string' },
|
|
662
1442
|
},
|
|
663
1443
|
},
|
|
@@ -665,9 +1445,22 @@ export function apply(ctx, rawConfig) {
|
|
|
665
1445
|
},
|
|
666
1446
|
async execute(args, exec) {
|
|
667
1447
|
const action = args.action
|
|
668
|
-
if (
|
|
1448
|
+
if (!['show', 'done', 'drop', 'update'].includes(action)) {
|
|
669
1449
|
throw new Error(`未知动作:${action}`)
|
|
670
1450
|
}
|
|
1451
|
+
if (action === 'update') {
|
|
1452
|
+
const keyword = String(args.keyword ?? '').trim()
|
|
1453
|
+
if (keyword === '') throw new Error('update 需要 keyword')
|
|
1454
|
+
const patch = boardPatch(args)
|
|
1455
|
+
const { stdout, board } = await updateBoard(config, keyword, patch, exec.signal)
|
|
1456
|
+
return {
|
|
1457
|
+
action,
|
|
1458
|
+
openCount: board.open.length,
|
|
1459
|
+
open: board.open,
|
|
1460
|
+
updated: stdout,
|
|
1461
|
+
text: `${stdout}\n未完成 ${board.open.length} 条。`.trim(),
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
671
1464
|
if (action !== 'show') {
|
|
672
1465
|
const keyword = String(args.keyword ?? '').trim()
|
|
673
1466
|
if (keyword === '') throw new Error(`${action} 需要 keyword`)
|
|
@@ -703,7 +1496,7 @@ export function apply(ctx, rawConfig) {
|
|
|
703
1496
|
|
|
704
1497
|
// 侧边栏「日报」页面读的数据:只读、同源、不缓存。Host 没接 Web 服务时这段自动缺席。
|
|
705
1498
|
ctx.inject(['webServer'], (webCtx) => {
|
|
706
|
-
const
|
|
1499
|
+
const stateDispose = webCtx.webServer.register({
|
|
707
1500
|
kind: 'exact',
|
|
708
1501
|
path: '/dsh-work-summary/state',
|
|
709
1502
|
resource: async () => {
|
|
@@ -720,7 +1513,38 @@ export function apply(ctx, rawConfig) {
|
|
|
720
1513
|
}
|
|
721
1514
|
},
|
|
722
1515
|
})
|
|
723
|
-
|
|
1516
|
+
|
|
1517
|
+
// 看板页是唯一允许写文件的页面入口:只改条目元数据/状态,不碰日报正文。
|
|
1518
|
+
const boardDispose = webCtx.webServer.register({
|
|
1519
|
+
kind: 'exact',
|
|
1520
|
+
path: '/dsh-work-summary/board',
|
|
1521
|
+
handler: async (req, res) => {
|
|
1522
|
+
const send = (status, value) => {
|
|
1523
|
+
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
1524
|
+
res.end(JSON.stringify(value))
|
|
1525
|
+
}
|
|
1526
|
+
try {
|
|
1527
|
+
if (req.method !== 'POST') {
|
|
1528
|
+
res.writeHead(405, { allow: 'POST' })
|
|
1529
|
+
res.end()
|
|
1530
|
+
return
|
|
1531
|
+
}
|
|
1532
|
+
const body = await readJsonBody(req)
|
|
1533
|
+
const keyword = String(body.keyword ?? '').trim()
|
|
1534
|
+
if (keyword === '') throw new Error('keyword 不能为空:写标题关键词或条目里的 #h 指纹')
|
|
1535
|
+
const patch = boardPatch(body)
|
|
1536
|
+
const { stdout, board } = await updateBoard(config, keyword, patch)
|
|
1537
|
+
send(200, { updated: stdout, openCount: board.open.length })
|
|
1538
|
+
} catch (error) {
|
|
1539
|
+
send(400, { error: String(error?.message ?? error) })
|
|
1540
|
+
}
|
|
1541
|
+
},
|
|
1542
|
+
})
|
|
1543
|
+
|
|
1544
|
+
return () => {
|
|
1545
|
+
if (typeof stateDispose === 'function') stateDispose()
|
|
1546
|
+
if (typeof boardDispose === 'function') boardDispose()
|
|
1547
|
+
}
|
|
724
1548
|
})
|
|
725
1549
|
|
|
726
1550
|
// 设置页:读/改那条日报计划任务。任务的 rrule 就是唯一真源,不另存一份配置。
|
|
@@ -735,7 +1559,12 @@ export function apply(ctx, rawConfig) {
|
|
|
735
1559
|
handler: async (req, res) => {
|
|
736
1560
|
try {
|
|
737
1561
|
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
738
|
-
|
|
1562
|
+
const [daily, week, month] = await Promise.all([
|
|
1563
|
+
scheduleState(sc, config),
|
|
1564
|
+
periodScheduleState(sc, config, 'week'),
|
|
1565
|
+
periodScheduleState(sc, config, 'month'),
|
|
1566
|
+
])
|
|
1567
|
+
send(res, 200, settingsPayload({ daily, week, month }, config))
|
|
739
1568
|
return
|
|
740
1569
|
}
|
|
741
1570
|
if (req.method !== 'POST') {
|
|
@@ -748,7 +1577,38 @@ export function apply(ctx, rawConfig) {
|
|
|
748
1577
|
const raw = Buffer.concat(chunks).toString('utf8')
|
|
749
1578
|
const body = raw.trim() === '' ? {} : JSON.parse(raw)
|
|
750
1579
|
const patch = {}
|
|
1580
|
+
let touched = false
|
|
1581
|
+
// 周报/月报:时间与启停都先落到 settings.json,再改任务本身;任务被删了还能按保存的值重建。
|
|
1582
|
+
for (const spec of [
|
|
1583
|
+
{ kind: 'week', label: '周报', timeField: 'weekTime', activeField: 'weekActive', timeKey: 'weekScheduleTime', enabledKey: 'weekScheduleEnabled', rrule: weeklyRrule },
|
|
1584
|
+
{ kind: 'month', label: '月报', timeField: 'monthTime', activeField: 'monthActive', timeKey: 'monthScheduleTime', enabledKey: 'monthScheduleEnabled', rrule: monthlyRrule },
|
|
1585
|
+
]) {
|
|
1586
|
+
const time = body[spec.timeField]
|
|
1587
|
+
const wantActive = body[spec.activeField]
|
|
1588
|
+
if (time === undefined && wantActive === undefined) continue
|
|
1589
|
+
touched = true
|
|
1590
|
+
const current = await periodScheduleState(sc, config, spec.kind)
|
|
1591
|
+
if (!current.found) throw new Error(`没找到${spec.label}计划任务;先重启一次让插件把它建出来`)
|
|
1592
|
+
const periodPatch = {}
|
|
1593
|
+
if (time !== undefined) {
|
|
1594
|
+
if (typeof time !== 'string') throw new Error(`${spec.timeField} 应为字符串`)
|
|
1595
|
+
if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(time)) throw new Error(`时间格式应为 HH:MM,收到:${time}`)
|
|
1596
|
+
periodPatch.timing = { kind: 'rrule', rrule: spec.rrule(current.timeZone, time) }
|
|
1597
|
+
await writeSettings({ [spec.timeKey]: time })
|
|
1598
|
+
config[spec.timeKey] = time
|
|
1599
|
+
}
|
|
1600
|
+
if (wantActive !== undefined) {
|
|
1601
|
+
if (typeof wantActive !== 'boolean') throw new Error(`${spec.activeField} 应为布尔值`)
|
|
1602
|
+
periodPatch.active = wantActive
|
|
1603
|
+
await writeSettings({ [spec.enabledKey]: wantActive })
|
|
1604
|
+
config[spec.enabledKey] = wantActive
|
|
1605
|
+
}
|
|
1606
|
+
if (Object.keys(periodPatch).length > 0) {
|
|
1607
|
+
await sc.schedule.edit({ id: current.id, action: 'update', patch: periodPatch })
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
751
1610
|
if (typeof body.time === 'string' || typeof body.active === 'boolean') {
|
|
1611
|
+
touched = true
|
|
752
1612
|
const current = await scheduleState(sc, config)
|
|
753
1613
|
if (!current.found) throw new Error('没找到日报计划任务;先重启一次让插件把它建出来')
|
|
754
1614
|
if (typeof body.time === 'string') {
|
|
@@ -758,6 +1618,7 @@ export function apply(ctx, rawConfig) {
|
|
|
758
1618
|
if (typeof body.active === 'boolean') patch.active = body.active
|
|
759
1619
|
}
|
|
760
1620
|
if (body.reportDir !== undefined) {
|
|
1621
|
+
touched = true
|
|
761
1622
|
if (typeof body.reportDir !== 'string') throw new Error('reportDir 应为字符串')
|
|
762
1623
|
const value = body.reportDir.trim()
|
|
763
1624
|
if (!/^[A-Za-z]:[\\/]|^\\\\|^\//.test(value)) {
|
|
@@ -769,6 +1630,7 @@ export function apply(ctx, rawConfig) {
|
|
|
769
1630
|
await logLine(config, 'info', `日报目录改为 ${value}(日报、看板、源数据都写到这里)`)
|
|
770
1631
|
}
|
|
771
1632
|
if (body.workspace !== undefined) {
|
|
1633
|
+
touched = true
|
|
772
1634
|
if (typeof body.workspace !== 'string') throw new Error('workspace 应为字符串')
|
|
773
1635
|
const value = body.workspace.trim()
|
|
774
1636
|
if (!/^[A-Za-z]:[\\/]|^\\\\|^\//.test(value)) {
|
|
@@ -780,6 +1642,7 @@ export function apply(ctx, rawConfig) {
|
|
|
780
1642
|
await logLine(config, 'info', `工作空间改为 ${value}(日报会扫描这里当天的改动)`)
|
|
781
1643
|
}
|
|
782
1644
|
if (body.logDir !== undefined) {
|
|
1645
|
+
touched = true
|
|
783
1646
|
if (typeof body.logDir !== 'string') throw new Error('logDir 应为字符串')
|
|
784
1647
|
const value = body.logDir.trim()
|
|
785
1648
|
if (value !== '' && !/^[A-Za-z]:[\\/]|^\\\\|^\//.test(value)) {
|
|
@@ -791,13 +1654,18 @@ export function apply(ctx, rawConfig) {
|
|
|
791
1654
|
config.logDir = value
|
|
792
1655
|
await logLine(config, 'info', `日志目录改为 ${logDirOf(config)}`)
|
|
793
1656
|
}
|
|
794
|
-
if (
|
|
795
|
-
throw new Error('没有要改的字段(time / active / reportDir / workspace / logDir)')
|
|
1657
|
+
if (!touched) {
|
|
1658
|
+
throw new Error('没有要改的字段(time / active / weekTime / weekActive / monthTime / monthActive / reportDir / workspace / logDir)')
|
|
796
1659
|
}
|
|
797
1660
|
if (Object.keys(patch).length > 0) {
|
|
798
1661
|
await sc.schedule.edit({ id: (await scheduleState(sc, config)).id, action: 'update', patch })
|
|
799
1662
|
}
|
|
800
|
-
|
|
1663
|
+
const [daily, week, month] = await Promise.all([
|
|
1664
|
+
scheduleState(sc, config),
|
|
1665
|
+
periodScheduleState(sc, config, 'week'),
|
|
1666
|
+
periodScheduleState(sc, config, 'month'),
|
|
1667
|
+
])
|
|
1668
|
+
send(res, 200, settingsPayload({ daily, week, month }, config))
|
|
801
1669
|
} catch (error) {
|
|
802
1670
|
send(res, 400, { error: String(error?.message ?? error) })
|
|
803
1671
|
}
|
|
@@ -810,8 +1678,8 @@ export function apply(ctx, rawConfig) {
|
|
|
810
1678
|
}
|
|
811
1679
|
|
|
812
1680
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
1681
|
+
* 插件自管的计划任务:日报每天一条,周报每周一、月报每月 1 号各一条。
|
|
1682
|
+
* 已有同标题任务就同步提示词/时间/启停;日报没有则认领旧任务,周报月报没有则按开关新建。
|
|
815
1683
|
* 失败只记日志,不影响工具可用。
|
|
816
1684
|
* @param {import('@deepseek-ai/cordis').Context} ctx - 插件上下文。
|
|
817
1685
|
* @param {typeof DEFAULTS} config - 生效配置。
|
|
@@ -830,34 +1698,80 @@ function installSchedule(ctx, config) {
|
|
|
830
1698
|
ctx.logger?.info?.('dsh-work-summary: 已同步日报计划任务的提示词')
|
|
831
1699
|
void logLine(config, 'info', `计划任务「${own.title}」的提示词已同步到当前版本`)
|
|
832
1700
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
1701
|
+
} else {
|
|
1702
|
+
const legacy = config.scheduleAdopt
|
|
1703
|
+
? items.find(task => task.status === 'active' && /collect-day\.ps1|daily_report_collect/.test(String(task.prompt ?? '')))
|
|
1704
|
+
: null
|
|
837
1705
|
if (legacy) {
|
|
838
1706
|
await scheduleCtx.schedule.edit({ id: legacy.id, action: 'update', patch: { prompt } })
|
|
839
1707
|
ctx.logger?.info?.(`dsh-work-summary: 已把旧日报计划任务「${legacy.title}」切到插件工具`)
|
|
840
1708
|
void logLine(config, 'info', `已认领旧任务「${legacy.title}」,提示词切到插件工具`)
|
|
841
|
-
|
|
1709
|
+
} else {
|
|
1710
|
+
const today = dateInZone(config.scheduleTimeZone).replace(/-/g, '')
|
|
1711
|
+
const [hour, minute] = config.scheduleTime.split(':')
|
|
1712
|
+
const rrule = `DTSTART;TZID=${config.scheduleTimeZone}:${today}T${hour}${minute}00\nRRULE:FREQ=DAILY`
|
|
1713
|
+
await scheduleCtx.schedule.create({
|
|
1714
|
+
title: config.scheduleTitle,
|
|
1715
|
+
prompt,
|
|
1716
|
+
timing: { kind: 'rrule', rrule },
|
|
1717
|
+
target: { kind: 'new_once' },
|
|
1718
|
+
})
|
|
1719
|
+
ctx.logger?.info?.(`dsh-work-summary: 已创建每日 ${config.scheduleTime} 的日报计划任务`)
|
|
1720
|
+
void logLine(config, 'info', `已创建每日 ${config.scheduleTime} 的日报计划任务`)
|
|
842
1721
|
}
|
|
843
1722
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const rrule = `DTSTART;TZID=${config.scheduleTimeZone}:${today}T${hour}${minute}00\nRRULE:FREQ=DAILY`
|
|
847
|
-
await scheduleCtx.schedule.create({
|
|
848
|
-
title: config.scheduleTitle,
|
|
849
|
-
prompt,
|
|
850
|
-
timing: { kind: 'rrule', rrule },
|
|
851
|
-
target: { kind: 'new_once' },
|
|
852
|
-
})
|
|
853
|
-
ctx.logger?.info?.(`dsh-work-summary: 已创建每日 ${config.scheduleTime} 的日报计划任务`)
|
|
854
|
-
void logLine(config, 'info', `已创建每日 ${config.scheduleTime} 的日报计划任务`)
|
|
1723
|
+
await installPeriodTask(ctx, scheduleCtx, config, 'week')
|
|
1724
|
+
await installPeriodTask(ctx, scheduleCtx, config, 'month')
|
|
855
1725
|
})().catch((error) => {
|
|
856
1726
|
ctx.logger?.warn?.(`dsh-work-summary: 计划任务处理失败:${error instanceof Error ? error.message : String(error)}`)
|
|
857
1727
|
})
|
|
858
1728
|
})
|
|
859
1729
|
}
|
|
860
1730
|
|
|
1731
|
+
/**
|
|
1732
|
+
* 托管一条周期任务:时间/启停以插件配置为准,标题是稳定识别键。
|
|
1733
|
+
* @param {import('@deepseek-ai/cordis').Context} ctx - 插件上下文。
|
|
1734
|
+
* @param {*} scheduleCtx - schedule 服务上下文。
|
|
1735
|
+
* @param {typeof DEFAULTS} config - 生效配置。
|
|
1736
|
+
* @param {'week'|'month'} kind - 周报或月报。
|
|
1737
|
+
* @returns {Promise<void>} 完成。
|
|
1738
|
+
*/
|
|
1739
|
+
async function installPeriodTask(ctx, scheduleCtx, config, kind) {
|
|
1740
|
+
const week = kind === 'week'
|
|
1741
|
+
const title = week ? config.weekScheduleTitle : config.monthScheduleTitle
|
|
1742
|
+
const time = week ? config.weekScheduleTime : config.monthScheduleTime
|
|
1743
|
+
const enabled = Boolean(week ? config.weekScheduleEnabled : config.monthScheduleEnabled)
|
|
1744
|
+
const prompt = periodPrompt(config, kind)
|
|
1745
|
+
const rrule = (week ? weeklyRrule : monthlyRrule)(config.scheduleTimeZone, time)
|
|
1746
|
+
const items = (await scheduleCtx.schedule.list({ limit: 200 })).items ?? []
|
|
1747
|
+
const task = findTaskByTitle(items, title)
|
|
1748
|
+
const label = week ? '周报' : '月报'
|
|
1749
|
+
|
|
1750
|
+
if (!task) {
|
|
1751
|
+
if (!enabled) return
|
|
1752
|
+
await scheduleCtx.schedule.create({
|
|
1753
|
+
title,
|
|
1754
|
+
prompt,
|
|
1755
|
+
timing: { kind: 'rrule', rrule },
|
|
1756
|
+
target: { kind: 'new_once' },
|
|
1757
|
+
})
|
|
1758
|
+
ctx.logger?.info?.(`dsh-work-summary: 已创建${label}计划任务(${time})`)
|
|
1759
|
+
void logLine(config, 'info', `已创建${label}计划任务「${title}」(${time})`)
|
|
1760
|
+
return
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
const patch = {}
|
|
1764
|
+
if (task.prompt !== prompt) patch.prompt = prompt
|
|
1765
|
+
const parsed = parseRruleTime(task)
|
|
1766
|
+
const [hour, minute] = time.split(':').map(Number)
|
|
1767
|
+
if (parsed.hour !== hour || parsed.minute !== minute) patch.timing = { kind: 'rrule', rrule }
|
|
1768
|
+
if ((task.status === 'active') !== enabled) patch.active = enabled
|
|
1769
|
+
if (Object.keys(patch).length === 0) return
|
|
1770
|
+
await scheduleCtx.schedule.edit({ id: task.id, action: 'update', patch })
|
|
1771
|
+
ctx.logger?.info?.(`dsh-work-summary: 已同步${label}计划任务`)
|
|
1772
|
+
void logLine(config, 'info', `${label}计划任务「${title}」已同步(${enabled ? time : '已暂停'})`)
|
|
1773
|
+
}
|
|
1774
|
+
|
|
861
1775
|
/**
|
|
862
1776
|
* 交给计划任务执行的提示词:只说流程,细则留在 PROMPT.md。
|
|
863
1777
|
* @param {typeof DEFAULTS} config - 生效配置。
|
|
@@ -875,3 +1789,24 @@ function schedulePrompt(config) {
|
|
|
875
1789
|
'只写有证据支撑的内容,推断标「推断:」;采集失败或数据缺失就写明原因,不要编造。当天几乎无产出就写短版。',
|
|
876
1790
|
].join('\n')
|
|
877
1791
|
}
|
|
1792
|
+
|
|
1793
|
+
/**
|
|
1794
|
+
* 周报/月报计划任务的提示词:固定生成上一完整周期,避免月初/周一拿到空区间。
|
|
1795
|
+
* @param {typeof DEFAULTS} config - 生效配置。
|
|
1796
|
+
* @param {'week'|'month'} kind - 周报或月报。
|
|
1797
|
+
* @returns {string} 提示词正文。
|
|
1798
|
+
*/
|
|
1799
|
+
function periodPrompt(config, kind) {
|
|
1800
|
+
const week = kind === 'week'
|
|
1801
|
+
const label = week ? '周报' : '月报'
|
|
1802
|
+
const span = week ? '上一周(周一至周日)' : '上一个自然月'
|
|
1803
|
+
return [
|
|
1804
|
+
`定时${label}时间到。用 work_summary_period 工具生成${span}的${label}:`,
|
|
1805
|
+
'',
|
|
1806
|
+
`1. 调用 \`work_summary_period\`,参数 { "kind": "${kind}", "offset": 1 };它会先采集区间源数据,再写四节正文并推看板。`,
|
|
1807
|
+
'2. 读返回的 reportPath,核对四节是否齐全,并记下哪些日期缺日报。',
|
|
1808
|
+
`3. 回复:${label}路径 + 看板新增条数 + 三条最重要结论(≤5 行);缺日报的日期一并点出。`,
|
|
1809
|
+
'',
|
|
1810
|
+
'只写有证据支撑的内容,不要编造;写入失败就说明原因,不要重复硬跑。',
|
|
1811
|
+
].join('\n')
|
|
1812
|
+
}
|