dsh-ppt 0.31.0 → 0.32.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/CHANGELOG.md +13 -0
- package/README.en.md +2 -1
- package/README.md +2 -1
- package/docs/USAGE.en.md +1 -0
- package/docs/USAGE.md +1 -0
- package/docs/VALIDATION.md +4 -0
- package/lib/client.js +1 -1
- package/lib/execution.d.ts +7 -0
- package/lib/execution.js +21 -0
- package/lib/tools.js +30 -2
- package/lib/types.d.ts +17 -0
- package/package.json +2 -2
- package/skills/dsh-ppt/SKILL.md +11 -5
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/references/research-plan.md +133 -0
- package/skills/dsh-ppt/scripts/build-deck.mjs +23 -3
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +21 -3
- package/skills/dsh-ppt/scripts/deck-core.mjs +5 -0
- package/skills/dsh-ppt/scripts/deck-delivery.mjs +4 -0
- package/skills/dsh-ppt/scripts/deck-evidence.mjs +628 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* deck-evidence.mjs —— 零资料深度调研与事实溯源引擎(Evidence Ledger、Storyboard Planner 与 SLOP-13 出处门禁)。
|
|
3
|
+
*
|
|
4
|
+
* 设计边界:
|
|
5
|
+
* - 100% 离线、零新增运行时依赖、绝不在引擎内部发起网络请求(检索由宿主 Agent / dsh-cite 完成);
|
|
6
|
+
* - 接收宿主 Agent 检索并交叉核验后的结构化 `evidence[]` 证据账本,实现:
|
|
7
|
+
* 1. `[E1]` / `evidenceIds` 自动注入规范左下角 `source` 脚注与演讲者备注 `notes` 完整 URL/口径溯源卡;
|
|
8
|
+
* 2. 可选在封底前自动插入「数据来源与事实核验清单」三线表附录页(`evidenceAppendix: true`);
|
|
9
|
+
* 3. `SLOP-13` 事实出处静态门禁:拦截悬空引用 `[E99]`、未标注口径的 `unverified`/`conflicting` 证据、
|
|
10
|
+
* 「数据来源:网络整理 / 公开资料」等空洞假出处,以及调研模式下无出处的量化数据页;
|
|
11
|
+
* 4. `buildResearchPlan`:围绕 20 套标杆范本生成 3 轮检索指南、证据缺口诊断与逐页分镜策划表(先策划、再生成)。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { stripInlineMarkdown } from './deck-layouts.mjs'
|
|
15
|
+
import { CURATED_EXEMPLARS, resolveExemplar, matchBestExemplar, getExemplarFewShotSlides } from './deck-exemplars.mjs'
|
|
16
|
+
|
|
17
|
+
const MAX_EVIDENCE_ITEMS = 60
|
|
18
|
+
const CONFIDENCE_SET = new Set(['verified', 'estimated', 'conflicting', 'unverified'])
|
|
19
|
+
const INLINE_REF_RE = /\[([Ee]\d{1,3})\]/g
|
|
20
|
+
const VAGUE_SOURCE_RE = /^(?:(?:数据|资料|信息)?来源\s*[::]\s*|sources?\s*[::]\s*)?(?:网络(?:整理|搜集|公开资料|资料|收集)?|互联网(?:整理|公开资料|资料)?|公开资料(?:整理)?|网上(?:资料|整理)?|综合整理|内部估算|估算|整理自网络|public\s+internet|online\s+sources?|web\s+search|various\s+sources?|internet|google|baidu|ai\s+generated?)[。.\s]*$/i
|
|
21
|
+
const QUANT_LAYOUTS = new Set(['kpi', 'chart', 'chart-split', 'waterfall', 'marimekko', 'tam', 'dumbbell', 'heatmap'])
|
|
22
|
+
|
|
23
|
+
function cleanText(value, maxLen = 240) {
|
|
24
|
+
return String(value ?? '').replace(/\s+/g, ' ').trim().slice(0, maxLen)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function estimateTextWidth(text) {
|
|
28
|
+
let w = 0
|
|
29
|
+
for (const ch of stripInlineMarkdown(String(text ?? ''))) {
|
|
30
|
+
w += /[^\x00-\xff]/.test(ch) ? 1 : 0.55
|
|
31
|
+
}
|
|
32
|
+
return w
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function trimCellByWidth(text, maxWidth = 17.2) {
|
|
36
|
+
const s = cleanText(text, 160)
|
|
37
|
+
if (!s || estimateTextWidth(s) <= maxWidth) return s
|
|
38
|
+
let out = ''
|
|
39
|
+
let w = 0
|
|
40
|
+
const limit = Math.max(4, maxWidth - 1.1)
|
|
41
|
+
for (const ch of s) {
|
|
42
|
+
const cw = /[^\x00-\xff]/.test(ch) ? 1 : 0.55
|
|
43
|
+
if (w + cw > limit) break
|
|
44
|
+
out += ch
|
|
45
|
+
w += cw
|
|
46
|
+
}
|
|
47
|
+
out = out.replace(/[\s,,、;;::(\[(【《「『&-]+$/, '')
|
|
48
|
+
// Drop an unclosed opening title/paren fragment if cut mid-phrase (e.g. "GGII《2025" -> "GGII")
|
|
49
|
+
out = out.replace(/[《((「『【][^》))」』】]*$/, '').replace(/[\s,,、;;::&-]+$/, '')
|
|
50
|
+
return (out || s.slice(0, 6)) + '…'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function sanitizeHttpUrl(raw) {
|
|
54
|
+
const s = String(raw ?? '').trim()
|
|
55
|
+
if (!s) return ''
|
|
56
|
+
try {
|
|
57
|
+
const parsed = new URL(s)
|
|
58
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
59
|
+
throw new Error('dsh-ppt:evidence.url 仅支持 http:// 或 https:// 链接:' + s)
|
|
60
|
+
}
|
|
61
|
+
return parsed.toString()
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err instanceof Error && err.message.startsWith('dsh-ppt:')) throw err
|
|
64
|
+
throw new Error('dsh-ppt:evidence.url 格式无效:' + s)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 校验并规范化外部传入的 `evidence[]` 证据账本。
|
|
70
|
+
* @param {Array<object>} rawEvidence
|
|
71
|
+
* @returns {Array<object>}
|
|
72
|
+
*/
|
|
73
|
+
export function normalizeEvidenceLedger(rawEvidence) {
|
|
74
|
+
if (rawEvidence === undefined || rawEvidence === null) return []
|
|
75
|
+
if (!Array.isArray(rawEvidence)) {
|
|
76
|
+
throw new Error('dsh-ppt:evidence 必须是证据条目数组')
|
|
77
|
+
}
|
|
78
|
+
if (rawEvidence.length > MAX_EVIDENCE_ITEMS) {
|
|
79
|
+
throw new Error(`dsh-ppt:evidence 最多支持 ${MAX_EVIDENCE_ITEMS} 条证据`)
|
|
80
|
+
}
|
|
81
|
+
const seen = new Set()
|
|
82
|
+
const out = []
|
|
83
|
+
for (let i = 0; i < rawEvidence.length; i += 1) {
|
|
84
|
+
const item = rawEvidence[i]
|
|
85
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
86
|
+
throw new Error(`dsh-ppt:evidence[${i}] 必须是对象`)
|
|
87
|
+
}
|
|
88
|
+
const rawId = cleanText(item.id || `E${i + 1}`, 24).toUpperCase()
|
|
89
|
+
if (!/^[A-Z][A-Z0-9_-]{0,23}$/.test(rawId)) {
|
|
90
|
+
throw new Error(`dsh-ppt:evidence[${i}].id 无效(请使用如 E1、E2 格式):${rawId}`)
|
|
91
|
+
}
|
|
92
|
+
if (seen.has(rawId)) {
|
|
93
|
+
throw new Error(`dsh-ppt:evidence 存在重复编号 ${rawId}`)
|
|
94
|
+
}
|
|
95
|
+
seen.add(rawId)
|
|
96
|
+
|
|
97
|
+
const claim = cleanText(item.claim ?? item.fact ?? item.summary, 320)
|
|
98
|
+
const source = cleanText(item.source ?? item.publisher ?? item.origin, 160)
|
|
99
|
+
if (!claim) {
|
|
100
|
+
throw new Error(`dsh-ppt:evidence ${rawId} 缺少事实描述 claim`)
|
|
101
|
+
}
|
|
102
|
+
if (!source) {
|
|
103
|
+
throw new Error(`dsh-ppt:evidence ${rawId} 缺少一手出处 source`)
|
|
104
|
+
}
|
|
105
|
+
const date = cleanText(item.date ?? item.year ?? item.period, 40)
|
|
106
|
+
const scope = cleanText(item.scope ?? item.region, 80)
|
|
107
|
+
const url = item.url ? sanitizeHttpUrl(item.url) : ''
|
|
108
|
+
const rawConf = cleanText(item.confidence || 'verified', 24).toLowerCase()
|
|
109
|
+
if (!CONFIDENCE_SET.has(rawConf)) {
|
|
110
|
+
throw new Error(`dsh-ppt:evidence ${rawId} 的 confidence 仅支持 verified / estimated / conflicting / unverified`)
|
|
111
|
+
}
|
|
112
|
+
const note = cleanText(item.note ?? item.caveat, 240)
|
|
113
|
+
out.push({
|
|
114
|
+
id: rawId,
|
|
115
|
+
claim,
|
|
116
|
+
source,
|
|
117
|
+
...(date ? { date } : {}),
|
|
118
|
+
...(scope ? { scope } : {}),
|
|
119
|
+
...(url ? { url } : {}),
|
|
120
|
+
confidence: rawConf,
|
|
121
|
+
...(note ? { note } : {}),
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
return out
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 提取单页显式 `evidenceIds` 与正文内联 `[E1]` 引用编号(去重保序)。
|
|
129
|
+
*/
|
|
130
|
+
export function extractSlideEvidenceRefs(slide) {
|
|
131
|
+
if (!slide || typeof slide !== 'object') return []
|
|
132
|
+
const refs = []
|
|
133
|
+
const seen = new Set()
|
|
134
|
+
const add = (id) => {
|
|
135
|
+
const norm = String(id ?? '').trim().toUpperCase()
|
|
136
|
+
if (!norm || seen.has(norm)) return
|
|
137
|
+
seen.add(norm)
|
|
138
|
+
refs.push(norm)
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(slide.evidenceIds)) {
|
|
141
|
+
for (const id of slide.evidenceIds) add(id)
|
|
142
|
+
}
|
|
143
|
+
const scanText = (val) => {
|
|
144
|
+
if (typeof val !== 'string' || !val.includes('[')) return
|
|
145
|
+
for (const m of val.matchAll(INLINE_REF_RE)) {
|
|
146
|
+
add(m[1])
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
scanText(slide.title)
|
|
150
|
+
scanText(slide.subtitle)
|
|
151
|
+
scanText(slide.takeaway)
|
|
152
|
+
scanText(slide.source)
|
|
153
|
+
scanText(slide.text)
|
|
154
|
+
if (Array.isArray(slide.bullets)) slide.bullets.forEach(scanText)
|
|
155
|
+
if (Array.isArray(slide.items)) {
|
|
156
|
+
for (const it of slide.items) {
|
|
157
|
+
if (!it || typeof it !== 'object') continue
|
|
158
|
+
scanText(it.tag); scanText(it.title); scanText(it.value); scanText(it.delta); scanText(it.text)
|
|
159
|
+
if (Array.isArray(it.bullets)) it.bullets.forEach(scanText)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(slide.rows)) {
|
|
163
|
+
for (const row of slide.rows) {
|
|
164
|
+
if (Array.isArray(row)) row.forEach(scanText)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (slide.chart?.caption) scanText(slide.chart.caption)
|
|
168
|
+
return refs
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatCompactEvidenceSource(entries, langEn) {
|
|
172
|
+
const parts = entries.slice(0, 2).map((e) => {
|
|
173
|
+
const shortSrc = trimCellByWidth(e.source, 16)
|
|
174
|
+
const dateTag = e.date ? ` (${e.date})` : ''
|
|
175
|
+
return `${shortSrc}${dateTag} [${e.id}]`
|
|
176
|
+
})
|
|
177
|
+
const suffix = entries.length > 2 ? (langEn ? ` +${entries.length - 2} more` : ` 等 ${entries.length} 项`) : ''
|
|
178
|
+
return parts.join(langEn ? '; ' : ';') + suffix
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function compareEvidenceId(a, b) {
|
|
182
|
+
const ma = /^([A-Z]+)(\d+)$/.exec(String(a?.id || ''))
|
|
183
|
+
const mb = /^([A-Z]+)(\d+)$/.exec(String(b?.id || ''))
|
|
184
|
+
if (ma && mb && ma[1] === mb[1]) return Number(ma[2]) - Number(mb[2])
|
|
185
|
+
return String(a?.id || '').localeCompare(String(b?.id || ''))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function confidenceLabel(conf, langEn) {
|
|
189
|
+
const mapZh = { verified: '已核验', estimated: '口径估算', conflicting: '存在口径差异', unverified: '待核实' }
|
|
190
|
+
const mapEn = { verified: 'Verified', estimated: 'Estimated', conflicting: 'Conflicting', unverified: 'Unverified' }
|
|
191
|
+
return (langEn ? mapEn[conf] : mapZh[conf]) || conf
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function formatNotesProvenanceBlock(entries, langEn) {
|
|
195
|
+
const header = langEn ? '[Evidence Provenance]' : '[证据溯源]'
|
|
196
|
+
const lines = entries.map((e) => {
|
|
197
|
+
const meta = [e.source, e.date, e.scope, confidenceLabel(e.confidence, langEn)].filter(Boolean).join(' · ')
|
|
198
|
+
const urlPart = e.url ? ` | ${e.url}` : ''
|
|
199
|
+
const notePart = e.note ? ` (${e.note})` : ''
|
|
200
|
+
return `- [${e.id}] ${e.claim} — ${meta}${notePart}${urlPart}`
|
|
201
|
+
})
|
|
202
|
+
return `${header}\n${lines.join('\n')}`
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 将核验后的证据账本绑定至幻灯片:
|
|
207
|
+
* - 自动为引用 `[E#]` / `evidenceIds` 的页面注入干净的 `slide.source` 脚注;
|
|
208
|
+
* - 将完整出处、统计口径、核验状态与原始 URL 写入演讲备注 `notes`(提词台随时备查);
|
|
209
|
+
* - 若 `evidenceAppendix: true`,在封底前自动插入「数据来源与事实核验清单」三线表附录页。
|
|
210
|
+
*/
|
|
211
|
+
export function applyEvidenceLedgerToSlides(slides, ledger, options = {}) {
|
|
212
|
+
const list = Array.isArray(slides) ? slides : []
|
|
213
|
+
const items = Array.isArray(ledger) ? ledger : []
|
|
214
|
+
if (list.length === 0 || items.length === 0) {
|
|
215
|
+
return { slides: list, citedIds: [], appendixAdded: false }
|
|
216
|
+
}
|
|
217
|
+
const langEn = String(options.lang || 'zh').toLowerCase() === 'en'
|
|
218
|
+
const byId = new Map(items.map((e) => [e.id, e]))
|
|
219
|
+
const citedOrder = []
|
|
220
|
+
const citedSet = new Set()
|
|
221
|
+
|
|
222
|
+
const enriched = list.map((rawSlide) => {
|
|
223
|
+
if (!rawSlide || typeof rawSlide !== 'object') return rawSlide
|
|
224
|
+
const refs = extractSlideEvidenceRefs(rawSlide)
|
|
225
|
+
const matched = refs.map((id) => byId.get(id)).filter(Boolean)
|
|
226
|
+
if (matched.length === 0) return rawSlide
|
|
227
|
+
|
|
228
|
+
for (const e of matched) {
|
|
229
|
+
if (!citedSet.has(e.id)) {
|
|
230
|
+
citedSet.add(e.id)
|
|
231
|
+
citedOrder.push(e.id)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const next = { ...rawSlide }
|
|
236
|
+
const existingSource = String(next.source ?? '').trim()
|
|
237
|
+
if (!existingSource || VAGUE_SOURCE_RE.test(existingSource)) {
|
|
238
|
+
next.source = formatCompactEvidenceSource(matched, langEn)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const existingNotes = String(next.notes ?? '').trim()
|
|
242
|
+
const marker = langEn ? '[Evidence Provenance]' : '[证据溯源]'
|
|
243
|
+
if (!existingNotes.includes(marker)) {
|
|
244
|
+
const provBlock = formatNotesProvenanceBlock(matched, langEn)
|
|
245
|
+
next.notes = existingNotes ? `${existingNotes}\n\n${provBlock}` : provBlock
|
|
246
|
+
}
|
|
247
|
+
return next
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
let appendixAdded = false
|
|
251
|
+
if (options.evidenceAppendix === true) {
|
|
252
|
+
const rawAppendixEntries = citedOrder.length > 0
|
|
253
|
+
? citedOrder.map((id) => byId.get(id)).filter(Boolean)
|
|
254
|
+
: items
|
|
255
|
+
const appendixEntries = [...rawAppendixEntries].sort(compareEvidenceId)
|
|
256
|
+
const maxRows = 6
|
|
257
|
+
const shortStatus = (conf) => {
|
|
258
|
+
if (langEn) return confidenceLabel(conf, true)
|
|
259
|
+
const compactZh = { verified: '已核验', estimated: '口径估算', conflicting: '口径差异', unverified: '待核实' }
|
|
260
|
+
return compactZh[conf] || conf
|
|
261
|
+
}
|
|
262
|
+
const rows = [
|
|
263
|
+
langEn
|
|
264
|
+
? ['ID', 'Key Verified Fact', 'Primary Source & Year', 'Status']
|
|
265
|
+
: ['编号', '核心核验事实', '一手出处与年份', '核验状态'],
|
|
266
|
+
...appendixEntries.slice(0, maxRows).map((e) => {
|
|
267
|
+
const datePart = e.date ? ` (${e.date})` : ''
|
|
268
|
+
const srcBudget = Math.max(7.5, 17.4 - estimateTextWidth(datePart))
|
|
269
|
+
const srcWithDate = `${trimCellByWidth(e.source, srcBudget)}${datePart}`
|
|
270
|
+
return [
|
|
271
|
+
trimCellByWidth(e.id, 6),
|
|
272
|
+
trimCellByWidth(e.claim, 16.5),
|
|
273
|
+
srcWithDate,
|
|
274
|
+
trimCellByWidth(shortStatus(e.confidence), 6),
|
|
275
|
+
]
|
|
276
|
+
}),
|
|
277
|
+
]
|
|
278
|
+
const verifiedCount = appendixEntries.filter((e) => e.confidence === 'verified').length
|
|
279
|
+
const allVerified = verifiedCount === appendixEntries.length
|
|
280
|
+
const shownCount = Math.min(maxRows, appendixEntries.length)
|
|
281
|
+
const appendixSlide = {
|
|
282
|
+
layout: 'table',
|
|
283
|
+
tableStyle: 'booktabs',
|
|
284
|
+
kicker: langEn ? 'APPENDIX · SOURCES' : '附录 · 事实溯源',
|
|
285
|
+
title: langEn
|
|
286
|
+
? (allVerified
|
|
287
|
+
? `All ${appendixEntries.length} Core Claims Verified Against Primary Sources`
|
|
288
|
+
: `Evidence Ledger: ${verifiedCount}/${appendixEntries.length} Core Claims Verified`)
|
|
289
|
+
: (allVerified
|
|
290
|
+
? `全篇 ${appendixEntries.length} 项核心论据均已完成一手出处核验`
|
|
291
|
+
: `全篇 ${appendixEntries.length} 项核心论据溯源清单(已核验 ${verifiedCount} 项)`),
|
|
292
|
+
rows,
|
|
293
|
+
takeaway: langEn
|
|
294
|
+
? `${shownCount < appendixEntries.length ? `Showing ${shownCount} of ${appendixEntries.length}` : `All ${appendixEntries.length}`} ledger entries carry publisher & scope metadata; full claims and URLs are preserved in speaker notes and handout.`
|
|
295
|
+
: `${shownCount < appendixEntries.length ? `表内列出 ${shownCount}/${appendixEntries.length} 条` : `共列出全部 ${appendixEntries.length} 条`}核心证据,完整原文链接、口径说明与备注已同步保存在演讲备注与讲义中。`,
|
|
296
|
+
notes: formatNotesProvenanceBlock(appendixEntries, langEn),
|
|
297
|
+
}
|
|
298
|
+
const lastIdx = enriched.length - 1
|
|
299
|
+
if (lastIdx >= 0 && enriched[lastIdx]?.layout === 'closing') {
|
|
300
|
+
enriched.splice(lastIdx, 0, appendixSlide)
|
|
301
|
+
} else {
|
|
302
|
+
enriched.push(appendixSlide)
|
|
303
|
+
}
|
|
304
|
+
appendixAdded = true
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return { slides: enriched, citedIds: citedOrder, appendixAdded }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function slideHasNumericClaims(slide) {
|
|
311
|
+
const parts = [
|
|
312
|
+
slide?.title,
|
|
313
|
+
...(Array.isArray(slide?.bullets) ? slide.bullets : []),
|
|
314
|
+
...(Array.isArray(slide?.items) ? slide.items.flatMap((it) => [it?.value, it?.delta, it?.before, it?.after, it?.text]) : []),
|
|
315
|
+
...(Array.isArray(slide?.rows) ? slide.rows.slice(1).flat() : []),
|
|
316
|
+
]
|
|
317
|
+
if (slide?.chart?.series?.length) return true
|
|
318
|
+
const text = parts.filter((v) => v !== undefined && v !== null).map((v) => stripInlineMarkdown(String(v))).join(' ')
|
|
319
|
+
return /\d+(?:\.\d+)?\s*(?:%|%|亿|万|M|B|GWh|GW|TB|ms|倍|x|元|美元|\$|¥)/i.test(text)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* SLOP-13 事实出处与证据账本静态门禁(100% 确定性、零误报)。
|
|
324
|
+
* 1. 拦截悬空 `[E99]` 引用;
|
|
325
|
+
* 2. 拦截将 `unverified` / `conflicting` 证据当作无说明定论展示;
|
|
326
|
+
* 3. 拦截「数据来源:网络整理 / 公开资料」等空洞占位假出处;
|
|
327
|
+
* 4. 在启用 `manifest.evidence[]` 调研账本时,拦截无出处且未绑定 `[E#]` 的量化数据页。
|
|
328
|
+
*/
|
|
329
|
+
export function auditEvidenceAndSourcing(manifest) {
|
|
330
|
+
const issues = []
|
|
331
|
+
const slides = Array.isArray(manifest?.slides) ? manifest.slides : []
|
|
332
|
+
if (slides.length === 0) return issues
|
|
333
|
+
|
|
334
|
+
const ledger = Array.isArray(manifest?.evidence) ? manifest.evidence : []
|
|
335
|
+
const hasLedger = ledger.length > 0
|
|
336
|
+
const byId = new Map(ledger.map((e) => [String(e?.id ?? '').toUpperCase(), e]))
|
|
337
|
+
|
|
338
|
+
const push = (index, code, message, suggestion) => {
|
|
339
|
+
issues.push({
|
|
340
|
+
slide: index + 1,
|
|
341
|
+
slideId: slides[index]?.id,
|
|
342
|
+
severity: 'warning',
|
|
343
|
+
code,
|
|
344
|
+
message,
|
|
345
|
+
suggestion,
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
slides.forEach((slide, i) => {
|
|
350
|
+
if (!slide || typeof slide !== 'object') return
|
|
351
|
+
const lay = slide.layout || 'bullets'
|
|
352
|
+
const isFraming = ['cover', 'section', 'closing', 'agenda', 'quote'].includes(lay)
|
|
353
|
+
const rawSource = String(slide.source ?? '').trim()
|
|
354
|
+
|
|
355
|
+
// 1. 拦截空洞假出处(「数据来源:网络整理 / 公开资料 / 综合整理」)
|
|
356
|
+
if (rawSource && VAGUE_SOURCE_RE.test(rawSource)) {
|
|
357
|
+
push(
|
|
358
|
+
i,
|
|
359
|
+
'vague-placeholder-source',
|
|
360
|
+
`来源标注「${rawSource}」属于空洞占位词,无法追溯真实发布方与年份(SLOP-13)`,
|
|
361
|
+
'请替换为具体机构、报告名与年份(如「IEA Global EV Outlook 2025」),或标注为「内部口径估算」',
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 2. 检查 `[E#]` / `evidenceIds` 悬空引用与未核验/冲突状态
|
|
366
|
+
const refs = extractSlideEvidenceRefs(slide)
|
|
367
|
+
if (refs.length > 0) {
|
|
368
|
+
const missing = refs.filter((id) => !byId.has(id))
|
|
369
|
+
if (missing.length > 0) {
|
|
370
|
+
push(
|
|
371
|
+
i,
|
|
372
|
+
'dangling-evidence-ref',
|
|
373
|
+
`页面引用了证据账本中不存在的编号 ${missing.join('、')}(SLOP-13)`,
|
|
374
|
+
'请在 evidence[] 中补齐对应核验条目与原始出处,或移除悬空引用编号',
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
const risky = refs.map((id) => byId.get(id)).filter((e) => e && (e.confidence === 'unverified' || e.confidence === 'conflicting'))
|
|
378
|
+
if (risky.length > 0) {
|
|
379
|
+
const rawNotes = String(slide.notes || '')
|
|
380
|
+
const authorNotes = rawNotes.split(/\[(?:证据溯源|Evidence Provenance)\]/)[0] || ''
|
|
381
|
+
const itemText = Array.isArray(slide.items)
|
|
382
|
+
? slide.items.flatMap((it) => [it?.tag, it?.title, it?.delta, it?.text]).filter(Boolean).join(' ')
|
|
383
|
+
: ''
|
|
384
|
+
const bulletText = Array.isArray(slide.bullets) ? slide.bullets.join(' ') : ''
|
|
385
|
+
const caveatContext = `${slide.title || ''} ${slide.subtitle || ''} ${slide.takeaway || ''} ${slide.source || ''} ${itemText} ${bulletText} ${authorNotes}`
|
|
386
|
+
const hasCaveat = /待核实|未核实|冲突|差异|区间|口径|估算|约\s*\d|caveat|conflict|unverified|range|estimate|approx/i.test(caveatContext)
|
|
387
|
+
if (!hasCaveat) {
|
|
388
|
+
push(
|
|
389
|
+
i,
|
|
390
|
+
'unverified-evidence-claim',
|
|
391
|
+
`页面引用了标记为 ${risky.map((e) => `${e.id}(${e.confidence})`).join('、')} 的证据,但未在页面中说明口径差异或待核实状态(SLOP-13)`,
|
|
392
|
+
'请先完成双源交叉核验,或在页面 takeaway / subtitle / 正文中明确标注数据区间与核验口径',
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// 3. 调研模式(存在 evidence[] 账本时)要求所有高密度量化数据页给出真实出处或绑定 [E#]
|
|
399
|
+
if (hasLedger && !isFraming && QUANT_LAYOUTS.has(lay) && slideHasNumericClaims(slide)) {
|
|
400
|
+
const hasBoundSource = refs.length > 0 || (rawSource.length > 0 && !VAGUE_SOURCE_RE.test(rawSource))
|
|
401
|
+
const hasDataModel = Boolean(manifest?.dataModel)
|
|
402
|
+
if (!hasBoundSource && !hasDataModel) {
|
|
403
|
+
push(
|
|
404
|
+
i,
|
|
405
|
+
'unsourced-research-numbers',
|
|
406
|
+
`${lay} 量化数据页未绑定任何已核验证据 [E#] 且缺少有效 source 出处(SLOP-13)`,
|
|
407
|
+
'请从 evidence[] 绑定对应证据编号(如 evidenceIds: ["E1"])或填写具体出处与口径;若无确凿数据请改用定性版式',
|
|
408
|
+
)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
return issues
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* 在演讲讲义 (.handout.md) 末尾追加结构化「事实核验与证据账本」总表。
|
|
418
|
+
*/
|
|
419
|
+
export function renderEvidenceHandoutSection(manifest, language) {
|
|
420
|
+
const ledger = Array.isArray(manifest?.evidence) ? manifest.evidence : []
|
|
421
|
+
if (ledger.length === 0) return ''
|
|
422
|
+
const en = (language || manifest?.language || 'zh') === 'en'
|
|
423
|
+
const lines = [
|
|
424
|
+
'',
|
|
425
|
+
`## ${en ? 'Verified Evidence Ledger & Fact-Check Sources' : '事实核验与证据账本(Evidence Ledger)'}`,
|
|
426
|
+
'',
|
|
427
|
+
en
|
|
428
|
+
? '| ID | Verified Claim | Source | Period / Scope | Confidence | URL |'
|
|
429
|
+
: '| 编号 | 核验事实与数据 | 一手出处 | 时间 / 口径 | 核验状态 | 原文链接 |',
|
|
430
|
+
'| --- | --- | --- | --- | --- | --- |',
|
|
431
|
+
]
|
|
432
|
+
for (const e of ledger) {
|
|
433
|
+
const esc = (v) => String(v ?? '').replace(/\|/g, '\\|').replace(/\s+/g, ' ').trim()
|
|
434
|
+
const periodScope = [e.date, e.scope].filter(Boolean).join(' · ') || '—'
|
|
435
|
+
const link = e.url ? `[link](${e.url})` : '—'
|
|
436
|
+
lines.push(`| ${esc(e.id)} | ${esc(e.claim)} | ${esc(e.source)} | ${esc(periodScope)} | ${esc(confidenceLabel(e.confidence, en))} | ${link} |`)
|
|
437
|
+
}
|
|
438
|
+
lines.push('')
|
|
439
|
+
return lines.join('\n')
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* 零资料调研策划器:给定选题(与可选已搜集的 evidence[] 账本),输出:
|
|
444
|
+
* 1. 最佳匹配的标杆范本(20 套内置 + 工作区已吸收)与配色骨架;
|
|
445
|
+
* 2. 3 轮定向检索清单(官方一手源 → 行业基准竞品 → 最新进展与反方风险);
|
|
446
|
+
* 3. 逐页分镜策划表(Storyboard)与证据绑定缺口诊断;
|
|
447
|
+
* 4. 可直接展示给用户确认的 Markdown 策划方案(`planMarkdown`)。
|
|
448
|
+
*/
|
|
449
|
+
export function buildResearchPlan(options = {}) {
|
|
450
|
+
const topic = cleanText(options.topic ?? options.title, 160)
|
|
451
|
+
if (!topic) {
|
|
452
|
+
throw new Error('dsh-ppt:buildResearchPlan 需要提供选题 topic')
|
|
453
|
+
}
|
|
454
|
+
const langEn = String(options.lang || 'zh').toLowerCase() === 'en'
|
|
455
|
+
const workspaceExemplars = options.workspaceExemplars || {}
|
|
456
|
+
const explicitId = cleanText(options.exemplarId || options.exemplar, 64)
|
|
457
|
+
let exemplar = null
|
|
458
|
+
if (explicitId && explicitId.toLowerCase() !== 'auto') {
|
|
459
|
+
exemplar = resolveExemplar(explicitId, workspaceExemplars)
|
|
460
|
+
}
|
|
461
|
+
if (!exemplar) {
|
|
462
|
+
exemplar = matchBestExemplar({
|
|
463
|
+
title: topic,
|
|
464
|
+
content: String(options.context || options.audience || ''),
|
|
465
|
+
persona: options.persona || '',
|
|
466
|
+
}, workspaceExemplars) || CURATED_EXEMPLARS['mckinsey-strategy']
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const evidence = normalizeEvidenceLedger(options.evidence || [])
|
|
470
|
+
const verified = evidence.filter((e) => e.confidence === 'verified')
|
|
471
|
+
const estimated = evidence.filter((e) => e.confidence === 'estimated')
|
|
472
|
+
const conflicting = evidence.filter((e) => e.confidence === 'conflicting')
|
|
473
|
+
const unverified = evidence.filter((e) => e.confidence === 'unverified')
|
|
474
|
+
|
|
475
|
+
const researchRounds = langEn
|
|
476
|
+
? [
|
|
477
|
+
{
|
|
478
|
+
round: 1,
|
|
479
|
+
goal: 'Primary Official & Authoritative Baseline',
|
|
480
|
+
queries: [
|
|
481
|
+
`"${topic}" official report OR whitepaper OR annual report 2025 2026`,
|
|
482
|
+
`"${topic}" government OR regulator OR IEA OR Gartner OR SEC statistics`,
|
|
483
|
+
],
|
|
484
|
+
requirement: 'Verify headline market size, growth rate, exact year & geographic scope from ≥2 primary sources.',
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
round: 2,
|
|
488
|
+
goal: 'Competitive Landscape & Quantitative Benchmarks',
|
|
489
|
+
queries: [
|
|
490
|
+
`"${topic}" leading companies market share benchmark comparison 2025 2026`,
|
|
491
|
+
`"${topic}" cost reduction OR efficiency improvement case study metrics`,
|
|
492
|
+
],
|
|
493
|
+
requirement: 'Collect comparable before→after metrics, unit economics, and player differentiation.',
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
round: 3,
|
|
497
|
+
goal: 'Latest Milestones, Bottlenecks & Counter-Arguments',
|
|
498
|
+
queries: [
|
|
499
|
+
`"${topic}" bottleneck OR risk OR limitation OR failed deployment 2025 2026`,
|
|
500
|
+
`"${topic}" roadmap 2026 2027 commercialization forecast`,
|
|
501
|
+
],
|
|
502
|
+
requirement: 'Record conflicting estimates honestly; switch any unsourced dimension to qualitative diagrams.',
|
|
503
|
+
},
|
|
504
|
+
]
|
|
505
|
+
: [
|
|
506
|
+
{
|
|
507
|
+
round: 1,
|
|
508
|
+
goal: '一手官方与权威基线数据(市场/政策/年报)',
|
|
509
|
+
queries: [
|
|
510
|
+
`${topic} 官方报告 OR 白皮书 OR 年报 2025 2026 数据`,
|
|
511
|
+
`${topic} 权威统计 规模 增速 口径 2025 2026`,
|
|
512
|
+
],
|
|
513
|
+
requirement: '核心规模、增速与关键指标须来自权威一手源并至少双源交叉核验,记清年份与地域口径。',
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
round: 2,
|
|
517
|
+
goal: '行业标杆对比与量化实绩(竞品/成本/提效)',
|
|
518
|
+
queries: [
|
|
519
|
+
`${topic} 头部厂商 竞争格局 市场份额 对比 2025 2026`,
|
|
520
|
+
`${topic} 标杆案例 降本 提效 实测指标`,
|
|
521
|
+
],
|
|
522
|
+
requirement: '收集同口径竞品对比、改造前后量化跃迁与单点经济模型,避免混用不可比口径。',
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
round: 3,
|
|
526
|
+
goal: '最新进展、落地瓶颈与反方风险(避免一边倒)',
|
|
527
|
+
queries: [
|
|
528
|
+
`${topic} 痛点 瓶颈 风险 局限 商业化障碍 2025 2026`,
|
|
529
|
+
`${topic} 2026 2027 路线图 发展趋势 商业化节点`,
|
|
530
|
+
],
|
|
531
|
+
requirement: '如实记录存在口径差异的预测区间;凡查不到确凿数字的维度改用定性图示,严禁编造数字。',
|
|
532
|
+
},
|
|
533
|
+
]
|
|
534
|
+
|
|
535
|
+
let evCursor = 0
|
|
536
|
+
const gaps = []
|
|
537
|
+
const storyboard = (exemplar.slots || []).map((slot) => {
|
|
538
|
+
const needsQuant = QUANT_LAYOUTS.has(slot.layout) || slot.layout === 'table' || slot.layout === 'sankey'
|
|
539
|
+
const assigned = []
|
|
540
|
+
if (needsQuant && evidence.length > 0 && evCursor < evidence.length) {
|
|
541
|
+
assigned.push(evidence[evCursor].id)
|
|
542
|
+
evCursor += 1
|
|
543
|
+
if (slot.layout === 'kpi' && evCursor < evidence.length) {
|
|
544
|
+
assigned.push(evidence[evCursor].id)
|
|
545
|
+
evCursor += 1
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const gap = needsQuant && assigned.length === 0
|
|
549
|
+
? (langEn
|
|
550
|
+
? `Needs verified primary data for [${slot.layout}]; search first or downgrade to qualitative cards/comparison.`
|
|
551
|
+
: `本页 [${slot.layout}] 尚缺已核验量化证据,请先检索补充或降级为定性卡片/对比页,严禁编造数字`)
|
|
552
|
+
: ''
|
|
553
|
+
if (gap) gaps.push({ slide: slot.index, role: slot.role, layout: slot.layout, gap })
|
|
554
|
+
|
|
555
|
+
return {
|
|
556
|
+
slide: slot.index,
|
|
557
|
+
role: slot.role,
|
|
558
|
+
layout: slot.variant ? `${slot.layout}[${slot.variant}]` : slot.layout,
|
|
559
|
+
needsQuantitativeEvidence: needsQuant,
|
|
560
|
+
boundEvidenceIds: assigned,
|
|
561
|
+
titleGuide: langEn ? (slot.exampleTitleEn || slot.fillGuideEn || slot.role) : (slot.exampleTitleZh || slot.fillGuideZh || slot.role),
|
|
562
|
+
fillGuide: langEn ? (slot.fillGuideEn || '') : (slot.fillGuideZh || ''),
|
|
563
|
+
...(gap ? { gap } : {}),
|
|
564
|
+
}
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
const lines = langEn
|
|
568
|
+
? [
|
|
569
|
+
`# Research & Storyboard Plan: ${topic}`,
|
|
570
|
+
'',
|
|
571
|
+
`- **Matched Gold Exemplar**: \`${exemplar.id}\` (${exemplar.enName || exemplar.name}) · Theme: \`${exemplar.theme}\` · Chrome: \`${exemplar.chromeStyle}\``,
|
|
572
|
+
`- **Evidence Ledger Status**: ${evidence.length} total (${verified.length} verified, ${estimated.length} estimated, ${conflicting.length} conflicting, ${unverified.length} unverified) · **Data Gaps**: ${gaps.length} quantitative slot(s)`,
|
|
573
|
+
'',
|
|
574
|
+
'## 1. 3-Round Retrieval & Fact-Check Checklist',
|
|
575
|
+
...researchRounds.map((r) => `- **Round ${r.round} — ${r.goal}**: ${r.requirement} (Queries: \`${r.queries.join('` / `')}\`)`),
|
|
576
|
+
'',
|
|
577
|
+
'## 2. Slide-by-Slide Storyboard Blueprint',
|
|
578
|
+
'| # | Role | Layout | Bound Evidence | Action-Title & Fill Direction |',
|
|
579
|
+
'| --- | --- | --- | --- | --- |',
|
|
580
|
+
...storyboard.map((s) => `| ${s.slide} | ${s.role} | \`${s.layout}\` | ${s.boundEvidenceIds.length ? s.boundEvidenceIds.map((id) => `[${id}]`).join(' ') : (s.needsQuantitativeEvidence ? '⚠️ Needs data' : 'Qualitative')} | ${s.titleGuide} |`),
|
|
581
|
+
'',
|
|
582
|
+
'## 3. Generation Rule',
|
|
583
|
+
`Once confirmed, call \`ppt_create({ title: ${JSON.stringify(topic)}, exemplar: ${JSON.stringify(exemplar.id)}, alignOrder: true, evidence: [...], evidenceAppendix: true, slides: [...] })\`.`,
|
|
584
|
+
]
|
|
585
|
+
: [
|
|
586
|
+
`# PPT 调研与分镜策划方案:${topic}`,
|
|
587
|
+
'',
|
|
588
|
+
`- **匹配标杆范本**:\`${exemplar.id}\`(${exemplar.name})|推荐主题 \`${exemplar.theme}\` |母版骨架 \`${exemplar.chromeStyle}\``,
|
|
589
|
+
`- **证据账本现状**:共 ${evidence.length} 条(已核验 ${verified.length} · 估算 ${estimated.length} · 口径差异 ${conflicting.length} · 待核实 ${unverified.length})|**待补量化缺口**:${gaps.length} 页`,
|
|
590
|
+
'',
|
|
591
|
+
'## 一、三轮定向检索与交叉核验清单',
|
|
592
|
+
...researchRounds.map((r) => `- **第 ${r.round} 轮 · ${r.goal}**:${r.requirement}(参考检索词:\`${r.queries.join('` / `')}\`)`),
|
|
593
|
+
'',
|
|
594
|
+
'## 二、逐页分镜策划表(Storyboard)',
|
|
595
|
+
'| 页码 | 叙事角色 | 推荐版式 | 绑定证据 | 结论标题方向与填空要点 |',
|
|
596
|
+
'| --- | --- | --- | --- | --- |',
|
|
597
|
+
...storyboard.map((s) => `| P${s.slide} | ${s.role} | \`${s.layout}\` | ${s.boundEvidenceIds.length ? s.boundEvidenceIds.map((id) => `[${id}]`).join(' ') : (s.needsQuantitativeEvidence ? '⚠️ 待补核验数据' : '定性叙事')} | ${s.titleGuide} |`),
|
|
598
|
+
'',
|
|
599
|
+
'## 三、确认后出稿参数',
|
|
600
|
+
`方案确认并补齐证据账本后,调用 \`ppt_create({ title: ${JSON.stringify(topic)}, exemplar: ${JSON.stringify(exemplar.id)}, alignOrder: true, evidence: [...], evidenceAppendix: true, slides: [...] })\` 生成带完整出处与零告警校验的三件套。`,
|
|
601
|
+
]
|
|
602
|
+
|
|
603
|
+
return {
|
|
604
|
+
ok: true,
|
|
605
|
+
topic,
|
|
606
|
+
exemplar: {
|
|
607
|
+
id: exemplar.id,
|
|
608
|
+
name: exemplar.name,
|
|
609
|
+
enName: exemplar.enName || exemplar.name,
|
|
610
|
+
theme: exemplar.theme,
|
|
611
|
+
chromeStyle: exemplar.chromeStyle,
|
|
612
|
+
slotCount: exemplar.slots?.length ?? 0,
|
|
613
|
+
},
|
|
614
|
+
evidenceAudit: {
|
|
615
|
+
total: evidence.length,
|
|
616
|
+
verified: verified.length,
|
|
617
|
+
estimated: estimated.length,
|
|
618
|
+
conflicting: conflicting.length,
|
|
619
|
+
unverified: unverified.length,
|
|
620
|
+
gapCount: gaps.length,
|
|
621
|
+
gaps,
|
|
622
|
+
},
|
|
623
|
+
researchRounds,
|
|
624
|
+
storyboard,
|
|
625
|
+
fewShotSlides: getExemplarFewShotSlides(exemplar.id, langEn ? 'en' : 'zh'),
|
|
626
|
+
planMarkdown: lines.join('\n'),
|
|
627
|
+
}
|
|
628
|
+
}
|