Surf commited on
Commit
db6b791
·
1 Parent(s): 125491b

新增 100 条素材批次下载与提炼提示词

Browse files
README.md CHANGED
@@ -27,3 +27,4 @@ pinned: false
27
  - 自动组稿:写一句创意 → 自动认母题、搜素材,按钩子/主线/反转/人物/情绪/细节各挑一条 → 拼出故事线和短篇/长篇框架 → 复制提示词给 AI
28
  - 素材串联创作:素材篮 → 找共同母题 → 虚构化 → 大纲 + 作品圣经 → 章纲 → 自查
29
  - 素材数据接口 /fanqie/api/materials/* 与本站共用访问密码 APP_PASSWORD;数据文件在 fanqie/data/
 
 
27
  - 自动组稿:写一句创意 → 自动认母题、搜素材,按钩子/主线/反转/人物/情绪/细节各挑一条 → 拼出故事线和短篇/长篇框架 → 复制提示词给 AI
28
  - 素材串联创作:素材篮 → 找共同母题 → 虚构化 → 大纲 + 作品圣经 → 章纲 → 自查
29
  - 素材数据接口 /fanqie/api/materials/* 与本站共用访问密码 APP_PASSWORD;数据文件在 fanqie/data/
30
+ - 批次下载页 /fanqie/batches:把 keep/edit 的素材按每批 100 条导出为 JSONL,也可一键下载全部 ZIP 和批次处理提示词;不含 drop,不在下载阶段重新调用 AI。
fanqie/batches.html ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>素材批次下载 · 番茄写作工作台</title>
7
+ <style>
8
+ :root{color-scheme:dark;--bg:#101116;--panel:#191b23;--line:#2d3140;--muted:#9ba3b5;--text:#f3f5f9;--accent:#e96a9a;--accent2:#8aa7ff;--ok:#64d39b}
9
+ *{box-sizing:border-box} body{margin:0;background:radial-gradient(1000px 450px at 50% -180px,#31233b 0%,var(--bg) 58%);color:var(--text);font:14px/1.6 system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif}
10
+ .wrap{width:min(1180px,calc(100% - 32px));margin:0 auto;padding:34px 0 64px}.top{display:flex;align-items:flex-start;justify-content:space-between;gap:20px;margin-bottom:24px}.eyebrow{color:var(--accent);font-weight:700;letter-spacing:.08em;font-size:12px}.title{font-size:30px;line-height:1.2;margin:5px 0 8px}.sub{color:var(--muted);margin:0;max-width:760px}.links{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end}.btn{appearance:none;border:1px solid var(--line);border-radius:10px;padding:10px 14px;background:#202331;color:var(--text);cursor:pointer;font-weight:650;text-decoration:none;white-space:nowrap}.btn:hover{border-color:var(--accent2);background:#252a3b}.btn.primary{background:var(--accent);border-color:var(--accent);color:#1b1018}.btn:disabled{opacity:.55;cursor:not-allowed}.panel{background:rgba(25,27,35,.9);border:1px solid var(--line);border-radius:16px;padding:20px;box-shadow:0 14px 45px #0004;margin-bottom:18px}.auth{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.auth input{min-width:280px;flex:1;background:#0f1117;color:var(--text);border:1px solid var(--line);border-radius:9px;padding:11px 12px;font:inherit}.status{color:var(--muted);margin-top:8px}.status.error{color:#ff9090}.stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin:16px 0}.stat{border:1px solid var(--line);border-radius:12px;padding:14px;background:#14161d}.stat b{display:block;font-size:22px}.stat span{color:var(--muted);font-size:12px}.toolbar{display:flex;gap:10px;align-items:center;justify-content:space-between;flex-wrap:wrap;margin-bottom:12px}.hint{color:var(--muted);font-size:13px}.table-wrap{overflow:auto;border:1px solid var(--line);border-radius:12px}table{width:100%;border-collapse:collapse;min-width:720px}th,td{text-align:left;padding:11px 13px;border-bottom:1px solid var(--line)}th{color:#c6ccdc;font-size:12px;background:#15171f;position:sticky;top:0}tr:last-child td{border-bottom:0}td{color:#e9ebf1}.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:#c9d1e8}.small{font-size:12px;color:var(--muted)}.empty{text-align:center;padding:30px;color:var(--muted)}.prompt{white-space:pre-wrap;background:#0d0f14;border:1px solid var(--line);border-radius:10px;padding:15px;max-height:300px;overflow:auto;color:#cbd3e8;font-size:12px}.footer{color:var(--muted);font-size:12px;margin-top:18px}@media(max-width:700px){.top{display:block}.links{justify-content:flex-start;margin-top:15px}.stats{grid-template-columns:repeat(2,1fr)}.wrap{width:min(100% - 20px,1180px);padding-top:22px}.title{font-size:25px}.auth input{min-width:0;width:100%}}
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <main class="wrap">
15
+ <div class="top">
16
+ <div>
17
+ <div class="eyebrow">FANQIE WRITING WORKBENCH</div>
18
+ <h1 class="title">素材批次下载</h1>
19
+ <p class="sub">把当前已经清洗完成的素材按每批 100 条导出为 JSONL。此页面只整理和下载,不会重新调用 AI,也不会改写素材。</p>
20
+ </div>
21
+ <div class="links"><a class="btn" href="/fanqie/">返回写作工作台</a></div>
22
+ </div>
23
+
24
+ <section class="panel" id="auth-panel">
25
+ <strong>输入网页访问密码</strong>
26
+ <div class="auth" style="margin-top:10px"><input id="password" type="password" placeholder="APP_PASSWORD" autocomplete="current-password"><button class="btn primary" id="login">读取批次</button></div>
27
+ <div class="status" id="auth-status">密码只保存在本浏览器的 localStorage,用于请求当前页面的受保护接口。</div>
28
+ </section>
29
+
30
+ <section class="panel" id="content" hidden>
31
+ <div class="toolbar">
32
+ <div><strong>下载包</strong><div class="hint">ZIP 内含全部批次、manifest.json、README.md 和本批处理提示词。</div></div>
33
+ <div class="links"><button class="btn primary" id="download-all">下载全部 ZIP</button><button class="btn" id="download-prompt">下载提示词 MD</button></div>
34
+ </div>
35
+ <div class="stats">
36
+ <div class="stat"><b id="total-items">—</b><span>可用素材(keep/edit)</span></div>
37
+ <div class="stat"><b id="total-batches">—</b><span>批次数(每批 100 条)</span></div>
38
+ <div class="stat"><b id="last-count">—</b><span>最后一批条数</span></div>
39
+ <div class="stat"><b id="source-time">—</b><span>源文件更新时间</span></div>
40
+ </div>
41
+ <div class="toolbar"><div class="hint" id="source-note"></div><label class="hint">筛选批次 <input id="filter" style="background:#0f1117;color:var(--text);border:1px solid var(--line);border-radius:7px;padding:7px 9px" placeholder="batch-001"></label></div>
42
+ <div class="table-wrap"><table><thead><tr><th>批次</th><th>范围</th><th>条数</th><th>首尾 uid</th><th>下载</th></tr></thead><tbody id="rows"><tr><td colspan="5" class="empty">正在读取…</td></tr></tbody></table></div>
43
+ <div class="footer">建议先下载完整 ZIP 备份。每条 JSONL 记录保留原始 uid,并附带旧母题/卡片字段,方便新结果回写 R2 时按 uid 断点续作。</div>
44
+ </section>
45
+
46
+ <section class="panel" id="prompt-panel" hidden>
47
+ <div class="toolbar"><strong>提示词预览</strong><button class="btn" id="copy-prompt">复制提示词</button></div>
48
+ <div class="prompt" id="prompt">读取后显示…</div>
49
+ </section>
50
+ </main>
51
+ <script>
52
+ (() => {
53
+ const $ = id => document.getElementById(id)
54
+ const key = 'xiaoshuo_batch_password'
55
+ let password = localStorage.getItem(key) || ''
56
+ let data = null
57
+ let prompt = ''
58
+ if (password) $('password').value = password
59
+
60
+ function setStatus(text, error = false) { $('auth-status').textContent = text; $('auth-status').className = 'status' + (error ? ' error' : '') }
61
+ async function api(path, options = {}) {
62
+ const headers = Object.assign({}, options.headers || {}, {'x-app-password': password})
63
+ const response = await fetch(path, Object.assign({}, options, {headers}))
64
+ if (!response.ok) { let msg = response.statusText; try { msg = (await response.json()).error || msg } catch (_) {} ; throw new Error(msg) }
65
+ return response
66
+ }
67
+ async function download(path, fallbackName) {
68
+ const response = await api(path)
69
+ const blob = await response.blob()
70
+ const disposition = response.headers.get('content-disposition') || ''
71
+ const match = disposition.match(/filename="?([^";]+)"?/i)
72
+ const name = match ? match[1] : fallbackName
73
+ const url = URL.createObjectURL(blob)
74
+ const a = document.createElement('a'); a.href = url; a.download = name; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(url), 2000)
75
+ }
76
+ function renderRows() {
77
+ const q = $('filter').value.trim().toLowerCase()
78
+ const list = (data?.batches || []).filter(x => !q || x.id.toLowerCase().includes(q))
79
+ $('rows').innerHTML = list.length ? list.map(x => `<tr><td class="mono">${x.id}</td><td>${x.start}–${x.end}</td><td>${x.count}</td><td class="small"><span class="mono">${x.first_uid || ''}</span><br><span class="mono">${x.last_uid || ''}</span></td><td><button class="btn" data-batch="${x.number}">下载 JSONL</button></td></tr>`).join('') : '<tr><td colspan="5" class="empty">没有匹配的批次</td></tr>'
80
+ document.querySelectorAll('[data-batch]').forEach(button => button.addEventListener('click', async () => { button.disabled = true; button.textContent = '生成中…'; try { await download('/fanqie/api/batches/batch-' + String(button.dataset.batch).padStart(3, '0') + '.jsonl', 'batch.jsonl') } catch (e) { alert(e.message) } finally { button.disabled = false; button.textContent = '下载 JSONL' } }))
81
+ }
82
+ async function load() {
83
+ password = $('password').value
84
+ if (!password) return setStatus('请输入密码。', true)
85
+ localStorage.setItem(key, password)
86
+ $('login').disabled = true; setStatus('正在读取清单…')
87
+ try {
88
+ const response = await api('/fanqie/api/batches/manifest')
89
+ data = await response.json()
90
+ const last = data.batches[data.batches.length - 1]
91
+ $('total-items').textContent = data.source.total_items.toLocaleString()
92
+ $('total-batches').textContent = data.total_batches.toLocaleString()
93
+ $('last-count').textContent = last ? last.count : '0'
94
+ $('source-time').textContent = new Date(data.source.mtime).toLocaleString()
95
+ $('source-note').textContent = `来源:${data.source.file} · SHA-256:${data.source.sha256.slice(0, 16)}… · 导出范围:${data.source.selection}`
96
+ $('content').hidden = false
97
+ const promptResponse = await api('/fanqie/api/batches/prompt')
98
+ prompt = await promptResponse.text(); $('prompt').textContent = prompt; $('prompt-panel').hidden = false
99
+ renderRows(); setStatus('读取成功。')
100
+ } catch (e) { setStatus('读取失败:' + e.message, true); $('content').hidden = true; $('prompt-panel').hidden = true } finally { $('login').disabled = false }
101
+ }
102
+ $('login').addEventListener('click', load)
103
+ $('password').addEventListener('keydown', e => { if (e.key === 'Enter') load() })
104
+ $('filter').addEventListener('input', renderRows)
105
+ $('download-all').addEventListener('click', async () => { $('download-all').disabled = true; $('download-all').textContent = '正在打包…'; try { await download('/fanqie/api/batches/all.zip', 'xiaoshuo-material-batches-100.zip') } catch (e) { alert(e.message) } finally { $('download-all').disabled = false; $('download-all').textContent = '下载全��� ZIP' } })
106
+ $('download-prompt').addEventListener('click', () => download('/fanqie/api/batches/prompt', 'batch_prompt.md').catch(e => alert(e.message)))
107
+ $('copy-prompt').addEventListener('click', async () => { try { await navigator.clipboard.writeText(prompt); $('copy-prompt').textContent = '已复制'; setTimeout(() => $('copy-prompt').textContent = '复制提示词', 1500) } catch (_) { alert('浏览器不允许自动复制,请手动选择文本。') } })
108
+ if (password) load()
109
+ })()
110
+ </script>
111
+ </body>
112
+ </html>
fanqie/batches.js ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ // 将已经清洗完成的素材按固定 100 条切成可供 AI 复核的 JSONL 批次。
4
+ // 这里不重新处理素材,也不改写原始材料;每次请求都以当前 materials.jsonl.gz 为准。
5
+ const fs = require('fs')
6
+ const path = require('path')
7
+ const zlib = require('zlib')
8
+ const crypto = require('crypto')
9
+
10
+ const DIR = process.env.FANQIE_DATA || path.join(__dirname, 'data')
11
+ const BATCH_SIZE = 100
12
+ let cache = null
13
+
14
+ function fileMtime(file) {
15
+ try { return fs.statSync(path.join(DIR, file)).mtimeMs } catch { return 0 }
16
+ }
17
+
18
+ function readText(file, fallback = '') {
19
+ try { return fs.readFileSync(path.join(DIR, file), 'utf8') } catch { return fallback }
20
+ }
21
+
22
+ function readGzipText(file, fallback = '') {
23
+ try { return zlib.gunzipSync(fs.readFileSync(path.join(DIR, file))).toString('utf8') } catch { return fallback }
24
+ }
25
+
26
+ function load() {
27
+ const key = [fileMtime('materials.jsonl.gz'), fileMtime('cards.jsonl.gz'), fileMtime('motif_index.json')].join('|')
28
+ if (cache && cache.key === key) return cache
29
+
30
+ const items = readGzipText('materials.jsonl.gz')
31
+ .split('\n')
32
+ .filter(Boolean)
33
+ .map(line => JSON.parse(line))
34
+ // materials.jsonl.gz 当前本身就是可用素材,但保留这个判断,避免以后误把 drop 导出。
35
+ .filter(item => item.d === 'keep' || item.d === 'edit')
36
+
37
+ const cards = new Map()
38
+ for (const line of readGzipText('cards.jsonl.gz').split('\n')) {
39
+ if (!line) continue
40
+ try {
41
+ const card = JSON.parse(line)
42
+ cards.set(card.uid, card)
43
+ } catch (_) { /* 跳过损坏的单行,不影响其它批次 */ }
44
+ }
45
+
46
+ let motifIndex = { index: {} }
47
+ try { motifIndex = JSON.parse(readText('motif_index.json', '{"index":{}}')) } catch (_) {}
48
+
49
+ cache = { key, items, cards, motifIndex }
50
+ return cache
51
+ }
52
+
53
+ function enrich(item, state) {
54
+ const card = state.cards.get(item.uid)
55
+ const existingMotifs = (card && Array.isArray(card.motifs) ? card.motifs : state.motifIndex.index?.[item.uid]) || []
56
+ return {
57
+ ...item,
58
+ // 旧字段保留,AI 可以把它们当作“已有结果”对照,而不是事实依据。
59
+ existing_motifs: existingMotifs,
60
+ existing_card: card || null
61
+ }
62
+ }
63
+
64
+ function batches() {
65
+ const state = load()
66
+ const out = []
67
+ for (let i = 0; i < state.items.length; i += BATCH_SIZE) {
68
+ const rows = state.items.slice(i, i + BATCH_SIZE)
69
+ const number = Math.floor(i / BATCH_SIZE) + 1
70
+ out.push({
71
+ id: `batch-${String(number).padStart(3, '0')}`,
72
+ number,
73
+ start: i + 1,
74
+ end: i + rows.length,
75
+ count: rows.length,
76
+ first_uid: rows[0]?.uid || null,
77
+ last_uid: rows[rows.length - 1]?.uid || null,
78
+ filename: `batch-${String(number).padStart(3, '0')}.jsonl`
79
+ })
80
+ }
81
+ return out
82
+ }
83
+
84
+ function manifest() {
85
+ const state = load()
86
+ const list = batches()
87
+ const sourceStat = fs.statSync(path.join(DIR, 'materials.jsonl.gz'))
88
+ const sourceHash = crypto.createHash('sha256').update(fs.readFileSync(path.join(DIR, 'materials.jsonl.gz'))).digest('hex')
89
+ const prompt = readText('batch_prompt.md')
90
+ return {
91
+ version: 1,
92
+ generated_at: new Date().toISOString(),
93
+ source: {
94
+ file: 'materials.jsonl.gz',
95
+ mtime: new Date(sourceStat.mtimeMs).toISOString(),
96
+ sha256: sourceHash,
97
+ selection: "d=keep 或 d=edit(不导出 drop)",
98
+ total_items: state.items.length
99
+ },
100
+ batch_size: BATCH_SIZE,
101
+ total_batches: list.length,
102
+ prompt_sha256: crypto.createHash('sha256').update(prompt).digest('hex'),
103
+ batches: list
104
+ }
105
+ }
106
+
107
+ function batchBuffer(number) {
108
+ const state = load()
109
+ const start = (number - 1) * BATCH_SIZE
110
+ if (number < 1 || start >= state.items.length) return null
111
+ const rows = state.items.slice(start, start + BATCH_SIZE).map(item => enrich(item, state))
112
+ return Buffer.from(rows.map(row => JSON.stringify(row)).join('\n') + '\n', 'utf8')
113
+ }
114
+
115
+ function dosDateTime(date = new Date()) {
116
+ const year = Math.max(1980, date.getFullYear())
117
+ return {
118
+ time: (date.getHours() << 11) | (date.getMinutes() << 5) | Math.floor(date.getSeconds() / 2),
119
+ date: ((year - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate()
120
+ }
121
+ }
122
+
123
+ // 轻量 ZIP writer:不引入新依赖,使用 Node 内置 DEFLATE;适合当前几十 MB 的批次包。
124
+ function crc32(buffer) {
125
+ let crc = 0xffffffff
126
+ for (let i = 0; i < buffer.length; i++) {
127
+ crc ^= buffer[i]
128
+ for (let j = 0; j < 8; j++) crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1))
129
+ }
130
+ return (crc ^ 0xffffffff) >>> 0
131
+ }
132
+
133
+ function u16(value) { const b = Buffer.alloc(2); b.writeUInt16LE(value & 0xffff); return b }
134
+ function u32(value) { const b = Buffer.alloc(4); b.writeUInt32LE(value >>> 0); return b }
135
+
136
+ function zipStore(entries) {
137
+ const parts = []
138
+ const central = []
139
+ let offset = 0
140
+ const dt = dosDateTime()
141
+
142
+ for (const entry of entries) {
143
+ const name = Buffer.from(entry.name, 'utf8')
144
+ const raw = Buffer.isBuffer(entry.data) ? entry.data : Buffer.from(entry.data)
145
+ const compressed = zlib.deflateRawSync(raw, { level: 6 })
146
+ const crc = crc32(raw)
147
+ const local = Buffer.concat([
148
+ Buffer.from('504b0304', 'hex'), u16(20), u16(0), u16(8), u16(dt.time), u16(dt.date),
149
+ u32(crc), u32(compressed.length), u32(raw.length), u16(name.length), u16(0), name, compressed
150
+ ])
151
+ parts.push(local)
152
+ central.push(Buffer.concat([
153
+ Buffer.from('504b0102', 'hex'), u16(20), u16(20), u16(0), u16(8), u16(dt.time), u16(dt.date),
154
+ u32(crc), u32(compressed.length), u32(raw.length), u16(name.length), u16(0), u16(0), u16(0), u16(0), u32(0), u32(offset), name
155
+ ]))
156
+ offset += local.length
157
+ }
158
+
159
+ const centralBuffer = Buffer.concat(central)
160
+ const body = Buffer.concat([...parts, centralBuffer])
161
+ const end = Buffer.concat([
162
+ Buffer.from('504b0506', 'hex'), u16(0), u16(0), u16(entries.length), u16(entries.length),
163
+ u32(centralBuffer.length), u32(offset), u16(0)
164
+ ])
165
+ return Buffer.concat([body, end])
166
+ }
167
+
168
+ function archiveBuffer() {
169
+ const state = load()
170
+ const list = batches()
171
+ const entries = [
172
+ { name: 'README.md', data: Buffer.from([
173
+ '# 小说素材 100 条批次包\n\n',
174
+ `共 ${state.items.length} 条可用素材,按每批 ${BATCH_SIZE} 条切分。`,
175
+ '每个 JSONL 文件一行一个素材,保留 uid/text 等原始字段,并附带 existing_motifs、existing_card 作为旧处理结果参考。\n',
176
+ '请先阅读 PROMPT.md,再逐批处理;不要改变 uid,不要把不同 uid 的现实人物直接合并。\n'
177
+ ].join(''), 'utf8') },
178
+ { name: 'PROMPT.md', data: Buffer.from(readText('batch_prompt.md'), 'utf8') },
179
+ { name: 'manifest.json', data: Buffer.from(JSON.stringify(manifest(), null, 2), 'utf8') }
180
+ ]
181
+ for (let i = 1; i <= list.length; i++) {
182
+ entries.push({ name: list[i - 1].filename, data: batchBuffer(i) })
183
+ }
184
+ return zipStore(entries)
185
+ }
186
+
187
+ function promptBuffer() { return Buffer.from(readText('batch_prompt.md'), 'utf8') }
188
+
189
+ module.exports = { manifest, batches, batchBuffer, archiveBuffer, promptBuffer, BATCH_SIZE }
fanqie/data/batch_prompt.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 100 条素材批次:母题库提炼与可组合写作结构化提示词
2
+
3
+ 你是“小说素材母题工程师”,负责把一批已经完成基础清洗的现实素材,重新提炼成**可检索、可组合、可约束验证**的母题资产。当前输入是一个 JSONL 文件;每行是一个独立素材,共约 100 条。请逐条阅读 `text`,不能只看 `sum`、`existing_motifs` 或 `existing_card`。
4
+
5
+ ## 一、任务边界
6
+
7
+ 1. 这一步不是写小说,不扩写成散文,不把 100 条硬拼成一个故事。
8
+ 2. 旧字段(`sum`、`existing_motifs`、`existing_card`、`why` 等)只是上一次处理结果,可能不准确;以 `text` 为第一依据,并在输出中标记修正点。
9
+ 3. 每条输入必须保留原 `uid`,输出一条对应记录;不得漏项、改 uid、重复 uid。若文本无法使用,也要输出 `status: "reject"` 和原因。
10
+ 4. 现实素材只提炼为创作参考,不把真人、真实姓名、真实单位、真实联系方式或可识别细节直接写进小说。涉及真实人物时,输出匿名化和虚构化建议。
11
+ 5. 不补写原文没有的事实。可以给出“创作推断”,但必须放进 `inferences`,并标记 `confidence`,不能伪装成原文事实。
12
+ 6. 对色情露骨、未成年人性内容、性暴力、详细违法/诈骗/自残方法、可识别个人隐私等内容,不复述细节;必要时 `status: "reject"` 或 `risk_flags` 标记,并只给出安全的抽象主题。
13
+
14
+ ## 二、每条素材的提炼目标
15
+
16
+ 请把每条素材转换为一张“母题卡候选”,重点回答:这条素材真正可迁移的冲突是什么?人物为什么做出选择?事件如何因果推进?哪些细节能支撑场景?哪些内容不能直接使用?
17
+
18
+ 输出字段至少包含:
19
+
20
+ - `uid`:原始 uid,必须原样保留
21
+ - `status`:`keep` / `revise` / `reject`
22
+ - `quality_score`:0-5;评价冲突清晰度、因果完整度、人物动机、细节可写性和虚构迁移价值
23
+ - `core_motif`:一句话概括最核心母题,避免只写“亲情/爱情/职场”等大类
24
+ - `motif_tags`:3-8 个可检索标签;同时给出 `motif_group`(亲情/情感/现实/内心/情节/悬疑等)
25
+ - `conflict`:核心矛盾,写成“谁想要什么 vs 谁/什么阻止了他”
26
+ - `stakes`:失去什么、得到什么、倒计时或代价是什么
27
+ - `characters`:人物清单,每人包含 `id`、`role`、`traits`、`want`、`fear`、`secret_or_limit`、`relationship_to_others`
28
+ - `events`:按时间顺序列出 3-10 个事件;每个事件包含 `order`、`event`、`cause`、`consequence`、`evidence_level`(`explicit`/`inferred`)
29
+ - `causal_chain`:用“因为→所以→但是→导致”写出完整因果链,不能只罗列情节
30
+ - `timeline`:明确时间跨度、先后关系、年龄/阶段;无法确定的地方写 `unknown`,不要擅自补日期
31
+ - `emotional_arc`:人物的情绪变化,例如“侥幸→拖延→失去→愧疚→承担”
32
+ - `usable_details`:5-12 个能转化为场景的动作、物件、环境、对白意图或生活细节;不要照抄真实隐私
33
+ - `adaptation_plan`:至少给出 2 种虚构化迁移方案(现代都市/古代/悬疑或其它适配题材),说明应该替换哪些身份、地点和事件
34
+ - `logic_constraints`:创作时必须满足的条件,至少包括人物关系、事件先后、动机、资源/能力边界和信息知情范围
35
+ - `forbidden_or_risky`:不应直接使用的事实、表达或细节,以及安全改写建议
36
+ - `similarity_keys`:用于和其它素材聚类的 5-10 个短语
37
+ - `merge_policy`:`standalone` / `can_combine` / `only_as_variant`;说明能否与哪些母题组合、组合时不能冲突的条件
38
+ - `corrections_to_old_result`:旧母题/旧卡片哪里不准确;没有则填空数组
39
+ - `inferences`:创作推断及其依据;没有则填空数组
40
+ - `confidence`:0-1
41
+
42
+ ## 三、关于“爷爷”或家庭人物的特别规则
43
+
44
+ 当素材涉及爷爷、奶奶、父母、兄弟姐妹等亲属时,不要把所有“爷爷”自动合成同一个人。必须区分:
45
+
46
+ 1. **角色模板**:例如“沉默付出的老人”“偏心的家族权威”“掌握秘密的见证人”。
47
+ 2. **素材事实**:这个 uid 中的爷爷做过什么、知道什么、与主角什么关系。
48
+ 3. **可组合关系**:只有当两条素材在时间、身份、动机、地点和信息知情范围上不冲突时,才建议组合。
49
+ 4. **组合方式**:优先组合“一个主冲突 + 一个辅助秘密/细节”,不要把两条完整人生经历机械相加。
50
+ 5. **禁止跨素材偷渡**:A 素材中的爷爷不能自动获得 B 素材的疾病、财产、秘密或性格;若采用,必须标为“虚构组合设定”。
51
+
52
+ ## 四、批次级输出:100 条处理完后再输出
53
+
54
+ 在逐条 JSONL 之后,另输出一个批次汇总对象(或单独的 `batch_summary.json`),包含:
55
+
56
+ - `batch_id`、`input_count`、`output_count`、`reject_count`
57
+ - `motif_clusters`:���可迁移冲突聚类,不要只按亲情/爱情等宽泛分类;每簇给 `cluster_id`、`name`、`definition`、`uids`、`shared_pattern`、`differences`
58
+ - `motif_relations`:母题之间的 `supports`、`escalates`、`contrasts_with`、`causes`、`resolves` 关系,并列出涉及 uid
59
+ - `character_archetypes`:人物角色模板及对应 uid;明确哪些是模板,哪些是事实
60
+ - `reusable_scene_details`:按场景功能分类的细节库
61
+ - `combination_candidates`:给出 5-10 组安全组合,每组列出 uid、主母题、辅助母题、组合后的新冲突、需要补写的桥接条件、不能违反的逻辑
62
+ - `global_risks`:本批次共性风险
63
+ - `quality_notes`:本批次最需要人工复核的地方
64
+
65
+ ## 五、输出格式
66
+
67
+ 默认严格输出 JSONL:每条输入对应一行 JSON,最后一行是 `{"record_type":"batch_summary", ...}`。不要输出 Markdown 解释、代码围栏或省略号。所有字段都必须是合法 JSON;没有内容用空数组或空字符串,不要用 `null` 代替必需字段。
68
+
69
+ 若一次只能输出一部分,先在当前结果中写明 `completed_uids` 和 `pending_uids`,下一次从第一个 `pending_uid` 继续;不要重新生成已经完成的 uid。处理完成后再写 `batch_summary`。
70
+
71
+ ## 六、质量自检
72
+
73
+ 提交前逐条检查:
74
+
75
+ - 是否每个输入 uid 都恰好出现一次?
76
+ - `core_motif` 是否比“亲情/爱情/反转”更具体?
77
+ - 是否把事实、推断、建议明确分开?
78
+ - 是否写清人物动机、事件因果、时间顺序和知情范围?
79
+ - 是否给出了可写的场景细节,而不是空泛形容词?
80
+ - 是否避免真实姓名、机构、平台和可识别隐私?
81
+ - 是否在跨素材组合时列出逻辑桥接条件和冲突禁区?
82
+ - 是否保留了原始 uid,方便结果随时保存到 R2、断点续作和回溯原文?
83
+
84
+ 在后续自动组稿时,优先使用 `core_motif`、`causal_chain`、`logic_constraints`、`characters` 和 `usable_details`;在检索“爷爷”等人物时,先按 `characters.role`、关系和 uid 找候选,再由逻辑约束筛选,不能让模型重新通读整个素材库。
fanqie/dist/index.html CHANGED
@@ -77,6 +77,13 @@
77
  },3000);
78
  })();
79
  </script>
 
 
 
 
 
 
 
80
  <!-- Made by Surf badge -->
81
  <style>
82
  #surf-badge{position:fixed;bottom:16px;right:16px;z-index:2147483647;display:inline-flex;align-items:center;gap:4px;padding:4px 12px;border-radius:20px;font-family:"Lato",system-ui,sans-serif;font-size:12px;font-weight:500;line-height:16px;text-decoration:none;box-shadow:0 1px 1px rgba(51,51,51,.08),0 6px 12px rgba(51,51,51,.08);opacity:.9;transition:opacity .2s}
 
77
  },3000);
78
  })();
79
  </script>
80
+ <!-- 素材批次下载入口 -->
81
+ <style>
82
+ #batch-download-link{position:fixed;top:16px;right:16px;z-index:2147483647;display:inline-flex;align-items:center;gap:6px;padding:8px 13px;border-radius:10px;font-family:system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif;font-size:13px;font-weight:650;line-height:18px;text-decoration:none;background:#24283a;color:#f4f5fb;border:1px solid #454c69;box-shadow:0 5px 18px rgba(0,0,0,.18);opacity:.94;transition:opacity .2s,transform .2s}
83
+ #batch-download-link:hover{opacity:1;transform:translateY(-1px)}
84
+ @media print{#batch-download-link{display:none}}
85
+ </style>
86
+ <a id="batch-download-link" href="/fanqie/batches" aria-label="素材批次下载">⬇ 素材批次下载</a>
87
  <!-- Made by Surf badge -->
88
  <style>
89
  #surf-badge{position:fixed;bottom:16px;right:16px;z-index:2147483647;display:inline-flex;align-items:center;gap:4px;padding:4px 12px;border-radius:20px;font-family:"Lato",system-ui,sans-serif;font-size:12px;font-weight:500;line-height:16px;text-decoration:none;box-shadow:0 1px 1px rgba(51,51,51,.08),0 6px 12px rgba(51,51,51,.08);opacity:.9;transition:opacity .2s}
fanqie/mount.js CHANGED
@@ -1,11 +1,44 @@
1
  // 番茄写作工作台:挂在 /fanqie/ 下,素材接口与原素材库共用访问密码(APP_PASSWORD)
2
  const path = require('path')
 
3
  module.exports = function mountFanqie(app, passwordOk, express) {
4
  const DIST = path.join(__dirname, 'dist')
 
5
  const materials = require('./materials.js')
 
 
 
 
6
  app.use('/fanqie/api', (req, res, next) => (passwordOk(req) ? next() : res.status(401).json({ error: 'password required' })))
7
  app.use('/fanqie/api/materials', materials)
8
  app.get('/fanqie/api/health', (_req, res) => res.json({ ok: true }))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  app.use('/fanqie', express.static(DIST, { index: false, maxAge: '1h' }))
10
  app.get(['/fanqie', '/fanqie/*'], (_req, res) => { res.setHeader('Cache-Control', 'no-cache'); res.sendFile(path.join(DIST, 'index.html')) })
11
  console.log('番茄写作工作台 mounted at /fanqie/')
 
1
  // 番茄写作工作台:挂在 /fanqie/ 下,素材接口与原素材库共用访问密码(APP_PASSWORD)
2
  const path = require('path')
3
+ const batches = require('./batches.js')
4
  module.exports = function mountFanqie(app, passwordOk, express) {
5
  const DIST = path.join(__dirname, 'dist')
6
+ const BATCH_PAGE = path.join(__dirname, 'batches.html')
7
  const materials = require('./materials.js')
8
+ const guarded = (handler) => async (req, res) => {
9
+ if (!passwordOk(req)) return res.status(401).json({ error: 'password required' })
10
+ try { await handler(req, res) } catch (e) { res.status(500).json({ error: e.message || String(e) }) }
11
+ }
12
  app.use('/fanqie/api', (req, res, next) => (passwordOk(req) ? next() : res.status(401).json({ error: 'password required' })))
13
  app.use('/fanqie/api/materials', materials)
14
  app.get('/fanqie/api/health', (_req, res) => res.json({ ok: true }))
15
+
16
+ // 批次下载:只导出 keep/edit 的已清洗素材,不触发 AI 处理,也不修改原始数据。
17
+ app.get('/fanqie/batches', (_req, res) => {
18
+ // 页面本身不含素材,允许打开;清单、提示词和下载接口仍需密码。
19
+ res.setHeader('Cache-Control', 'no-cache')
20
+ res.sendFile(BATCH_PAGE)
21
+ })
22
+ app.get('/fanqie/api/batches/manifest', guarded(async (_req, res) => {
23
+ res.setHeader('Cache-Control', 'no-cache')
24
+ res.json(batches.manifest())
25
+ }))
26
+ app.get('/fanqie/api/batches/prompt', guarded(async (_req, res) => {
27
+ res.setHeader('Content-Disposition', 'attachment; filename="batch_prompt.md"')
28
+ res.type('text/markdown; charset=utf-8').send(batches.promptBuffer())
29
+ }))
30
+ app.get('/fanqie/api/batches/all.zip', guarded(async (_req, res) => {
31
+ res.setHeader('Content-Disposition', 'attachment; filename="xiaoshuo-material-batches-100.zip"')
32
+ res.type('application/zip').send(batches.archiveBuffer())
33
+ }))
34
+ app.get('/fanqie/api/batches/:batch.jsonl', guarded(async (req, res) => {
35
+ const m = String(req.params.batch || '').match(/^batch-(\d{1,4})$/)
36
+ const number = m ? Number(m[1]) : 0
37
+ const data = number ? batches.batchBuffer(number) : null
38
+ if (!data) return res.status(404).json({ error: 'no such batch' })
39
+ res.setHeader('Content-Disposition', `attachment; filename="batch-${String(number).padStart(3, '0')}.jsonl"`)
40
+ res.type('application/x-ndjson').send(data)
41
+ }))
42
  app.use('/fanqie', express.static(DIST, { index: false, maxAge: '1h' }))
43
  app.get(['/fanqie', '/fanqie/*'], (_req, res) => { res.setHeader('Cache-Control', 'no-cache'); res.sendFile(path.join(DIST, 'index.html')) })
44
  console.log('番茄写作工作台 mounted at /fanqie/')