File size: 28,887 Bytes
a7fab52
 
 
23d257d
a7fab52
 
0399aa9
 
23d257d
0399aa9
 
3d4293e
 
a7fab52
23d257d
a7fab52
 
 
 
 
 
 
 
3d4293e
a7fab52
 
3d4293e
a7fab52
3d4293e
 
 
a7fab52
3d4293e
 
 
 
a7fab52
 
 
 
 
 
 
 
 
 
 
3d4293e
 
 
 
 
a7fab52
3d4293e
a7fab52
3d4293e
 
 
23d257d
a7fab52
 
 
 
3d4293e
a7fab52
 
3d4293e
 
 
 
 
 
23d257d
 
 
 
 
 
 
 
 
a7fab52
 
3d4293e
 
a7fab52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d4293e
a7fab52
 
3d4293e
a7fab52
 
 
 
 
 
 
 
0399aa9
a7fab52
 
 
3d4293e
 
a7fab52
 
 
 
 
3d4293e
 
a7fab52
23d257d
a7fab52
 
 
 
 
3d4293e
 
 
 
 
 
 
 
 
 
 
a7fab52
 
3d4293e
a7fab52
3d4293e
 
 
 
 
a7fab52
3d4293e
a7fab52
3d4293e
 
 
 
 
a7fab52
3d4293e
 
 
a7fab52
 
3d4293e
 
 
 
a7fab52
 
3d4293e
a7fab52
3d4293e
a7fab52
3d4293e
a7fab52
3d4293e
 
 
a7fab52
3d4293e
 
 
 
 
a7fab52
 
3d4293e
 
 
 
 
a7fab52
 
3d4293e
 
 
a7fab52
 
 
 
3d4293e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7fab52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d4293e
 
a7fab52
3d4293e
a7fab52
 
0399aa9
 
 
 
 
 
a7fab52
0399aa9
3d4293e
0399aa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7fab52
0399aa9
 
 
 
 
 
 
 
 
 
a7fab52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0399aa9
a7fab52
 
 
 
 
 
 
 
 
 
 
 
 
3d4293e
a7fab52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d4293e
a7fab52
 
 
 
 
 
 
 
 
 
 
0399aa9
a7fab52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d4293e
 
 
 
a7fab52
3d4293e
a7fab52
 
 
 
 
 
 
 
3d4293e
a7fab52
 
 
3d4293e
 
 
a7fab52
3d4293e
a7fab52
 
 
 
 
3d4293e
 
 
 
 
 
a7fab52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
import React, { useEffect, useMemo, useState } from 'react'
import {
  BookMarked, Map, Workflow, Bot, ShieldAlert, ListChecks, PenLine, Link2, Search, Check, AlertTriangle,
  ExternalLink, ChevronRight, Gauge, GitCompareArrows, Copy, Download, Quote, Ban, Info, CircleCheck, UserRound,
} from 'lucide-react'
import { guide, sources, srcMap, rules, ruleMap, ai, aiByRule, aiMarkdown, aiPromptBlock, LEVEL, type Rule, type AiRule } from '../handbook'
import { copyText, cx, fmtAgo, go, useAsync, useLocal } from '../lib'
import { agentApi, type AuditItem } from '../api'
import { AuditCard, AuthorProfile, ProjectPicker, ResultBadge, SayToAi } from './Agent'
import { Md } from '../md'
import { Empty, ErrorNote, Tag, useToast } from '../ui'

const SECTIONS = [
  { id: 'start', t: '总览', i: Map, n: '' },
  { id: 'author', t: '作者状态', i: UserRound, n: '必读' },
  { id: 'sign', t: '签约与收益', i: Workflow, n: '' },
  { id: 'red', t: '内容红线', i: ShieldAlert, n: '' },
  { id: 'quality', t: '低质与 AI', i: Gauge, n: '' },
  { id: 'craft', t: '写作方法', i: PenLine, n: '' },
  { id: 'check', t: '自查清单', i: ListChecks, n: '' },
  { id: 'ai', t: 'AI 写作规范', i: Bot, n: 'AI 看' },
  { id: 'map', t: '对照表', i: GitCompareArrows, n: '' },
  { id: 'sources', t: '资料来源', i: Link2, n: '' },
]
const ALIAS: Record<string, string> = { flow: 'sign', redlines: 'red', structure: 'craft' }
const SEC_NAME: Record<string, string> = Object.fromEntries(SECTIONS.map(s => [s.id, s.t]))

export function Src({ ids }: { ids?: string[] }) {
  if (!ids?.length) return null
  return (
    <span className="src-refs">
      {ids.map(id => srcMap[id] ? <a key={id} href={srcMap[id].url} target="_blank" rel="noreferrer" title={`${srcMap[id].title}${srcMap[id].date ? ` · ${srcMap[id].date}` : ''}`} className={cx('src-ref', srcMap[id].level)}>{LEVEL[srcMap[id].level]}</a> : null)}
    </span>
  )
}

export default function Guide({ section, focus }: { section: string; focus?: string }) {
  const s0 = ALIAS[section] || section
  const s = SECTIONS.find(x => x.id === s0) ? s0 : 'start'
  useEffect(() => {
    if (!focus) return
    const t = setTimeout(() => {
      const el = document.getElementById(`r-${focus}`)
      if (el) { el.scrollIntoView({ behavior: 'smooth', block: 'center' }); el.classList.add('flash'); setTimeout(() => el.classList.remove('flash'), 1600) }
    }, 80)
    return () => clearTimeout(t)
  }, [s, focus])
  return (
    <div className="guide">
      <aside className="guide-toc">
        <div className="eyebrow"><BookMarked size={14} />写作手册</div>
        <nav>
          {SECTIONS.map(x => <button key={x.id} className={cx('toc-link', s === x.id && 'on')} onClick={() => go(`guide/${x.id}`)}><x.i size={15} />{x.t}{x.n && <em className="toc-badge">{x.n}</em>}</button>)}
        </nav>
        <p className="muted small-note">规则核对于 {guide.meta.checked}。番茄规则会变,冲突时以作家后台最新公告为准。</p>
      </aside>
      <article className="guide-body page" key={s}>
        {s === 'start' && <Start />}
        {s === 'author' && <Author />}
        {s === 'sign' && <Sign />}
        {s === 'red' && <Red />}
        {s === 'quality' && <RuleSection sec="quality" eyebrow="低质与 AI" title={guide.secs.quality.title} sub={guide.secs.quality.sub} />}
        {s === 'craft' && <Craft />}
        {s === 'check' && <Checklist />}
        {s === 'ai' && <AiRules />}
        {s === 'map' && <MapTable />}
        {s === 'sources' && <Sources />}
      </article>
    </div>
  )
}

/* ---------- 作者状态:全局规则,写作 AI 和协作 AI 都要按它判断 ---------- */
function Author() {
  return <>
    <Head eyebrow="作者状态 · 全局规则" title="你现在处在哪个阶段"
      sub="这是全书通用的规则:我(写作 AI)动笔前、协作 AI 审查前,都会先读这里,按你的账号、等级、签约情况和目标来判断该怎么写、怎么提意见。改了马上生效。" />
    <AuthorProfile />
  </>
}

function Head({ eyebrow, title, sub, children }: { eyebrow: string; title: string; sub?: string; children?: React.ReactNode }) {
  return <header className="doc-head"><div className="eyebrow">{eyebrow}</div><h1 className="page-title serif">{title}</h1>{sub && <p className="page-sub">{sub}</p>}{children}</header>
}

/* ---------- 通用条目卡片 ---------- */
const RISK: Record<string, { t: string; d: string }> = {
  ban: { t: '封书封号', d: '最严重,可能永久封禁作品或账号' },
  down: { t: '下架屏蔽', d: '作品或章节被下架、屏蔽' },
  limit: { t: '限流降权', d: '不推荐、降低曝光、取消福利' },
  reject: { t: '审核不过', d: '发布、签约或推荐被驳回' },
}
const LV: Record<string, { t: string; tone: string }> = { must: { t: '必须', tone: 'err' }, should: { t: '建议', tone: 'accent' }, know: { t: '须知', tone: '' } }

function AiChips({ id }: { id: string }) {
  const list = aiByRule[id] || []
  const r = ruleMap[id]
  if (!list.length) return r?.ai === 'na' ? <span className="ai-chip na" title="这一条需要作者本人在后台完成,AI 无法代办">作者本人负责</span> : null
  return <span className="ai-chips">{list.map(a => <button key={a.id} className="ai-chip" title={a.rule} onClick={() => go(`guide/ai/${a.id}`)}><Bot size={11} />{a.id}</button>)}</span>
}

function RuleCard({ r }: { r: Rule }) {
  return (
    <section id={`r-${r.id}`} className={cx('rule', r.risk && `risk-${r.risk}`)}>
      <div className="rule-head">
        <span className="rule-id">{r.id}</span>
        <h3 className="serif">{r.t}</h3>
        <span className="push row gap-s">
          {r.level && <Tag tone={LV[r.level]?.tone}>{LV[r.level]?.t}</Tag>}
          {r.risk && <span className={cx('risk-badge', `risk-${r.risk}`)} title={RISK[r.risk]?.d}>{RISK[r.risk]?.t}</span>}
        </span>
      </div>
      <p className="rule-d">{r.d}</p>
      {r.official && <blockquote className="rule-quote"><Quote size={13} /><span>{r.official}</span></blockquote>}
      {r.traps?.length ? <div className="rl-block"><h4>容易踩的坑</h4><ul className="bullets warn">{r.traps.map(t => <li key={t}>{t}</li>)}</ul></div> : null}
      {r.safe && <div className="rl-block safe"><h4>安全写法</h4><p>{r.safe}</p></div>}
      <div className="rule-foot"><span className="muted small-note">依据</span><Src ids={r.src} /><span className="push" /><AiChips id={r.id} /></div>
    </section>
  )
}

function Groups({ list }: { list: Rule[] }) {
  const groups: [string, Rule[]][] = []
  for (const r of list) {
    const g = r.grp || ''
    const last = groups[groups.length - 1]
    if (last && last[0] === g) last[1].push(r); else groups.push([g, [r]])
  }
  return <>{groups.map(([g, rs], i) => <div key={g + i} className="rule-group">{g && <h2 className="h2 serif">{g}</h2>}<div className="rules">{rs.map(r => <RuleCard key={r.id} r={r} />)}</div></div>)}</>
}

function RuleSection({ sec, eyebrow, title, sub }: { sec: string; eyebrow: string; title: string; sub?: string }) {
  return <>
    <Head eyebrow={eyebrow} title={title} sub={sub} />
    <Groups list={rules.filter(r => r.sec === sec)} />
  </>
}

/* ---------- 总览 ---------- */
function Start() {
  const nRules = rules.length, nAi = ai.rules.length
  const nOfficial = sources.filter(s => s.level === 'official' || s.level === 'gov').length
  return <>
    <Head eyebrow="写作手册" title={guide.secs.start.title} sub={guide.secs.start.sub}>
      <div className="meta-row">
        <span>版本 {guide.meta.version}</span><span>核对于 {guide.meta.checked}</span>
        <span>{nRules} 条手册条目</span><span>{nAi} 条 AI 规范</span><span>{sources.length} 份资料(官方与法规 {nOfficial} 份)</span>
      </div>
    </Head>
    <div className="three-docs">
      <button className="doc-card" onClick={() => go('guide/red')}><ShieldAlert size={20} /><b>写作手册</b><span>给你看。平台规则、红线、签约、写法,每条带编号和出处。</span></button>
      <button className="doc-card" onClick={() => go('guide/ai')}><Bot size={20} /><b>AI 写作规范</b><span>给 AI 看。AI 在工作台上写作时必须遵守,「AI 协作 → AI 守则」里已引用。</span></button>
      <button className="doc-card" onClick={() => go('guide/map')}><GitCompareArrows size={20} /><b>对照表</b><span>手册每一条对应 AI 的哪一条,哪些只能你自己做。</span></button>
    </div>
    <h2 className="h2 serif">先记住这几件事</h2>
    <section className="facts">
      {guide.facts.map((f: any) => (
        <div key={f.k} className="fact">
          <span className="fact-k">{f.k}</span><b className="fact-v serif">{f.v}</b>
          <p>{f.d} <Src ids={f.src} /></p>
          {f.ref && <button className="link-btn small-note" onClick={() => go(`guide/${ruleMap[f.ref]?.sec || 'start'}/${f.ref}`)}>{f.ref} <ChevronRight size={12} /></button>}
        </div>
      ))}
    </section>
    <h2 className="h2 serif">规则变化时间线</h2>
    <ol className="timeline gt">
      {guide.changelog.map((c: any, i: number) => (
        <li key={i}><span className="tl-date">{c.date}</span><div><b>{c.t}</b><p>{c.d} <Src ids={c.src} /></p></div></li>
      ))}
    </ol>
    <h2 className="h2 serif">新手路线</h2>
    <ol className="roadmap">
      {guide.roadmap.map((r: any, i: number) => (
        <li key={i}>
          <span className="rm-w">{r.w}</span>
          <div className="rm-body"><b>{r.t}</b><p>{r.d}</p>{r.go && <button className="link-btn" onClick={() => go(`guide/${r.go}`)}>去看 <ChevronRight size={13} /></button>}</div>
        </li>
      ))}
    </ol>
  </>
}

/* ---------- 签约与收益 ---------- */
function Sign() {
  return <>
    <Head eyebrow="签约与收益" title={guide.secs.sign.title} sub={guide.secs.sign.sub} />
    <ol className="flow">
      {guide.flow.map((f: any) => (
        <li key={f.n} className="flow-step">
          <span className="flow-n serif">{f.n}</span>
          <div className="flow-body">
            <div className="flow-head"><b>{f.title}</b>{f.tag && <Tag>{f.tag}</Tag>}<Src ids={f.src} /></div>
            <ul className="flow-items">
              {f.items.map((it: any, i: number) => <li key={i} className={it.v}>{it.v === 'warn' ? <AlertTriangle size={13} /> : it.v === 'exp' ? <span className="exp">经验</span> : <Check size={13} />}<span>{it.t}{it.ref && <button className="link-btn inline" onClick={() => go(`guide/sign/${it.ref}`)}>{it.ref}</button>}</span></li>)}
            </ul>
          </div>
        </li>
      ))}
    </ol>
    <Groups list={rules.filter(r => r.sec === 'sign')} />
  </>
}

/* ---------- 内容红线 ---------- */
function Red() {
  const [cat, setCat] = useState('')
  const [risk, setRisk] = useState('')
  const [q, setQ] = useState('')
  const cats: any[] = guide.redCats
  const all = rules.filter(r => r.sec === 'red')
  const list = useMemo(() => all.filter(r =>
    (!cat || r.cat === cat) && (!risk || r.risk === risk) &&
    (!q || [r.id, r.t, r.d, r.safe, r.official, ...(r.traps || [])].join(' ').includes(q))), [cat, risk, q])
  return <>
    <Head eyebrow="内容红线" title={guide.secs.red.title} sub={guide.secs.red.sub} />
    <div className="toolbar">
      <label className="search-row grow"><Search size={15} /><input className="input bare" value={q} onChange={e => setQ(e.target.value)} placeholder="搜索关键词,例如:谐音、未成年、灵异、洗稿" /></label>
    </div>
    <div className="chips-row">
      <button className={cx('chip', !cat && 'on')} onClick={() => setCat('')}>全部类别</button>
      {cats.map(c => <button key={c.id} className={cx('chip', cat === c.id && 'on')} onClick={() => setCat(cat === c.id ? '' : c.id)}>{c.icon} {c.name}<em>{all.filter(r => r.cat === c.id).length}</em></button>)}
    </div>
    <div className="chips-row">
      <button className={cx('chip', !risk && 'on')} onClick={() => setRisk('')}>任何后果</button>
      {Object.entries(RISK).map(([k, v]) => <button key={k} className={cx('chip', `risk-${k}`, risk === k && 'on')} onClick={() => setRisk(risk === k ? '' : k)} title={v.d}>{v.t}</button>)}
    </div>
    <div className="rules">
      {list.map(r => <RuleCard key={r.id} r={r} />)}
      {!list.length && <Empty title="没有匹配的红线" />}
    </div>
  </>
}

/* ---------- 写作方法 ---------- */
function Craft() {
  const [tab, setTab] = useState<'short' | 'long'>('short')
  const frame = guide.frames[tab]
  return <>
    <Head eyebrow="写作方法" title={guide.secs.craft.title} sub={guide.secs.craft.sub} />
    <Groups list={rules.filter(r => r.sec === 'craft')} />
    <h2 className="h2 serif">结构模板</h2>
    <p className="page-sub">在作品的「大纲」页可以一键套用。模板是练习用的骨架,不是平台要求。</p>
    <div className="seg big">
      <button className={cx(tab === 'short' && 'on')} onClick={() => setTab('short')}>短故事</button>
      <button className={cx(tab === 'long' && 'on')} onClick={() => setTab('long')}>长篇</button>
    </div>
    {tab === 'short' ? (
      <div className="beats-line">
        {guide.shortBeats.map((b: any, i: number) => (
          <div key={i} className="beat-card">
            <div className="beat-top"><span className="beat-n serif">{i + 1}</span><b>{b.name}</b><span className="muted push">{b.range} · {b.words}</span></div>
            <p>{b.goal}</p>
            {b.example && <blockquote className="serif">{b.example}</blockquote>}
          </div>
        ))}
      </div>
    ) : (
      <div className="vol-list">
        {guide.longVolumes.map((v: any) => (
          <section key={v.vol} className="sheet vol">
            <div className="row between"><h2 className="sheet-title serif">{v.vol}</h2><span className="muted">{v.ch} · {v.words}</span></div>
            <p>{v.goal}</p>
            <ol className="vol-beats">{v.beats.map((b: string) => <li key={b}>{b}</li>)}</ol>
          </section>
        ))}
      </div>
    )}
    <section className="sheet">
      <div className="row between"><h2 className="sheet-title">{frame.t}</h2><span className="muted">{frame.size}</span></div>
      <table className="frame-table">
        <tbody>{frame.parts.map((p: any) => <tr key={p.t}><th>{p.t}</th><td className="muted">{p.range}</td><td>{p.goal}</td></tr>)}</tbody>
      </table>
    </section>
    {guide.genres?.length > 0 && <>
      <h2 className="h2 serif">题材怎么选</h2>
      <div className="genre-grid">
        {guide.genres.map((g: any) => (
          <div key={g.id} className={cx('genre', g.pick && 'pick')}>
            <div className="genre-head"><b>{g.name}</b>{g.pick && <Tag tone="accent">新手推荐</Tag>}<span className="muted push">{g.side}</span></div>
            <div className="genre-meter"><span>安全 <Dots n={g.safe} /></span><span>上手 <Dots n={g.ease} /></span><span className="muted">{g.form}</span></div>
            <p>{g.why}</p>
            {g.lines?.length > 0 && <><h4>守住这些线</h4><ul className="bullets warn">{g.lines.map((l: string) => <li key={l}>{l}</li>)}</ul></>}
            {g.tips?.length > 0 && <><h4>写法建议</h4><ul className="bullets">{g.tips.map((l: string) => <li key={l}>{l}</li>)}</ul></>}
            <Src ids={g.src} />
          </div>
        ))}
      </div>
    </>}
  </>
}
const Dots = ({ n }: { n: number }) => <span className="dots">{[1, 2, 3, 4, 5].map(i => <i key={i} className={i <= n ? 'on' : ''} />)}</span>

/* ---------- 自查清单 ---------- */
function Checklist() {
  const [pid, setPid] = useState('')
  const d = useAsync(() => (pid ? Promise.all([agentApi.audits({ project_id: pid, kind: 'checklist', n: 20 }), agentApi.audits({ project_id: pid, kind: 'platform', scope: 'book', n: 5 })]) : Promise.resolve(null)), [pid])
  const latest = d.data?.[0].items[0]
  const plat = d.data?.[1].items[0]
  const res: Record<string, AuditItem> = {}
  for (const it of latest?.items || []) { if (it.id) res[it.id] = it; else if (it.title) res[it.title] = it }
  const all = guide.checklist.flatMap((g: any) => g.items)
  const cnt = (r: string) => all.filter((i: any) => (res[i.id] || res[i.t])?.result === r).length
  return <>
    <Head eyebrow="自查清单 · 由 AI 执行" title="发布前,让 AI 逐条检查" sub="清单不再由你手动勾选:写作 AI 会逐条阅读正文后判断,把结果(通过 / 需注意 / 不通过,附原文和修改建议)写进检查记录。你和 AI 读的是同一份结果。">
      <div className="row gap wrap"><ProjectPicker value={pid} onChange={setPid} /><button className="btn small ghost" onClick={() => go('agent/audits')}>全部检查记录</button></div>
    </Head>
    <SayToAi text="请对这本书跑一遍「自查清单」,逐条阅读正文判断,结果写进检查记录。" />
    {d.error && <ErrorNote error={d.error} onRetry={d.reload} />}
    {pid && !d.data && !d.error && <p className="muted">正在读取检查结果…</p>}
    {d.data && (latest
      ? <div className="ck-sum"><ResultBadge r={latest.status} /><span>最近一次:{latest.by} · {fmtAgo(latest.created_at)}{latest.scope === 'chapter' ? ` · 第${latest.chapter_number}章` : ' · 全书'}</span><span className="ck-n"><em className="t-err">{cnt('fail')} 不通过</em><em className="t-warn">{cnt('warn')} 需注意</em><em>{cnt('pass')} 通过</em><em className="muted">{all.length - cnt('fail') - cnt('warn') - cnt('pass')} 未检查</em></span></div>
      : <div className="ck-sum"><span className="res-badge">未检查</span><span>这本书还没有自查记录。把上面那句话发给 AI 即可。</span></div>)}
    {latest?.summary && <div className="sheet tight"><Md text={latest.summary} /></div>}
    {guide.checklist.map((g: any) => (
      <section key={g.id} className="sheet">
        <h2 className="sheet-title">{g.name} <span className="muted small-note">{g.when}</span></h2>
        <ul className="checklist ai">
          {g.items.map((i: any) => {
            const r = res[i.id] || res[i.t]
            return (
              <li key={i.id} className={r ? `ck-${r.result}` : ''}>
                <div className="ck-row">
                  {r ? <ResultBadge r={r.result} small /> : <span className="res-badge sm">未检查</span>}
                  <span className="ck-t">{i.t}{i.why && <em className="muted">{i.why}</em>}</span>
                  {i.ref?.length > 0 && <span className="ck-refs">{i.ref.map((id: string) => <button key={id} className="rule-id link" onClick={() => go(`guide/${ruleMap[id]?.sec || 'red'}/${id}`)}>{id}</button>)}</span>}
                </div>
                {r && (r.note || r.quote || r.fix) && <div className="ck-ai">{r.note && <p>{r.note}</p>}{r.quote && <blockquote>{r.quote}</blockquote>}{r.fix && <p><b>建议:</b>{r.fix}</p>}</div>}
              </li>
            )
          })}
        </ul>
      </section>
    ))}
    <section className="sheet">
      <h2 className="sheet-title">番茄平台规定检查 <span className="muted small-note">内容红线 + 低质与 AI 规则,共 {rules.filter(r => r.sec === 'red' || r.sec === 'quality').length} 条</span></h2>
      {plat ? <AuditCard a={plat} /> : <p className="muted">还没有全书的平台规定检查。单章检查结果在书房每章的「检查」面板里。</p>}
      <SayToAi text="请按「番茄平台规定」逐条检查全书,结果写进检查记录。" />
    </section>
  </>
}

/* ---------- AI 写作规范 ---------- */
function download(name: string, text: string) {
  const url = URL.createObjectURL(new Blob([text], { type: 'text/markdown;charset=utf-8' }))
  const a = document.createElement('a'); a.href = url; a.download = name; a.click()
  setTimeout(() => URL.revokeObjectURL(url), 1000)
}
function AiRules() {
  const toast = useToast()
  const [q, setQ] = useState('')
  const [hardOnly, setHardOnly] = useState(false)
  const match = (r: AiRule) => (!hardOnly || r.hard) && (!q || [r.id, r.rule, r.detail, r.check, ...(r.do || []), ...(r.dont || []), ...r.maps].join(' ').includes(q))
  return <>
    <Head eyebrow="AI 写作规范 · 给 AI 看" title={`番茄小说 AI 写作规范 ${ai.version}`} sub="写作 AI 直接在工作台上写作,动笔前会读这份规范(「AI 协作 → AI 守则」里已引用)。也可以复制或下载,放进 AI 的项目知识库。">
      <div className="row gap wrap ai-actions">
        <button className="btn primary" onClick={async () => { await copyText(aiMarkdown()); toast('完整规范已复制', 'ok') }}><Copy size={14} />复制完整版</button>
        <button className="btn ghost" onClick={() => download(`番茄AI写作规范-${ai.version}.md`, aiMarkdown())}><Download size={14} />下载 .md</button>
        <button className="btn ghost" onClick={async () => { await copyText(aiPromptBlock()); toast('精简版已复制', 'ok') }}><Copy size={14} />复制精简版</button>
      </div>
    </Head>
    <section className="sheet ai-role">
      <h2 className="sheet-title serif"><Bot size={16} />你的角色</h2>
      <ul className="bullets">{ai.preamble.map(p => <li key={p}>{p}</li>)}</ul>
    </section>
    <div className="toolbar">
      <label className="search-row grow"><Search size={15} /><input className="input bare" value={q} onChange={e => setQ(e.target.value)} placeholder="搜索规范,例如:未成年、声明、素材、洗稿" /></label>
      <button className={cx('chip', hardOnly && 'on')} onClick={() => setHardOnly(v => !v)}>只看硬性条款</button>
    </div>
    {ai.groups.map(g => {
      const list = ai.rules.filter(r => r.g === g.id && match(r))
      if (!list.length) return null
      return (
        <div key={g.id} className="rule-group">
          <h2 className="h2 serif">{g.t}</h2>
          {g.d && <p className="page-sub">{g.d}</p>}
          <div className="rules">
            {list.map(r => (
              <section key={r.id} id={`r-${r.id}`} className={cx('rule ai-rule', r.hard && 'hard')}>
                <div className="rule-head"><span className="rule-id ai">{r.id}</span><h3>{r.rule}</h3>{r.hard && <span className="push"><Tag tone="err">硬性</Tag></span>}</div>
                {r.detail && <p className="rule-d">{r.detail}</p>}
                {(r.do?.length || r.dont?.length) ? (
                  <div className="dodont">
                    {r.do?.length ? <div className="do"><h4><CircleCheck size={13} />要</h4><ul>{r.do.map(x => <li key={x}>{x}</li>)}</ul></div> : null}
                    {r.dont?.length ? <div className="dont"><h4><Ban size={13} />不要</h4><ul>{r.dont.map(x => <li key={x}>{x}</li>)}</ul></div> : null}
                  </div>
                ) : null}
                {r.check && <p className="ai-check"><Info size={13} /><span><b>自检:</b>{r.check}</span></p>}
                <div className="rule-foot">
                  <span className="muted small-note">对应手册</span>
                  {r.maps.map(h => <button key={h} className="rule-id link" title={ruleMap[h]?.t} onClick={() => go(`guide/${ruleMap[h]?.sec || 'red'}/${h}`)}>{h}</button>)}
                  <span className="push" /><Src ids={r.src} />
                </div>
              </section>
            ))}
          </div>
        </div>
      )
    })}
    <section className="sheet">
      <h2 className="sheet-title serif"><Ban size={16} />遇到这些请求,拒绝或改写</h2>
      <ul className="bullets warn">{ai.refuse.map(x => <li key={x}>{x}</li>)}</ul>
    </section>
    <section className="sheet">
      <h2 className="sheet-title serif"><ListChecks size={16} />每次输出前的自检</h2>
      <ol className="vol-beats">{ai.output.map(x => <li key={x}>{x}</li>)}</ol>
    </section>
    <section className="sheet">
      <h2 className="sheet-title serif">精简版(硬性条款)</h2>
      <pre className="pre-block">{aiPromptBlock()}</pre>
    </section>
  </>
}

/* ---------- 对照表 ---------- */
function MapTable() {
  const [f, setF] = useState<'all' | 'ai' | 'na'>('all')
  const [sec, setSec] = useState('')
  const covered = rules.filter(r => aiByRule[r.id]?.length).length
  const na = rules.filter(r => !aiByRule[r.id]?.length && r.ai === 'na').length
  const gap = rules.filter(r => !aiByRule[r.id]?.length && r.ai !== 'na')
  const orphan = ai.rules.flatMap(a => a.maps.filter(h => !ruleMap[h]).map(h => `${a.id}→${h}`))
  const list = rules.filter(r => (!sec || r.sec === sec) && (f === 'all' || (f === 'ai' ? aiByRule[r.id]?.length : !aiByRule[r.id]?.length)))
  const secs = [...new Set(rules.map(r => r.sec))]
  return <>
    <Head eyebrow="对照表" title="手册与 AI 规范逐条对照" sub="左边是给你看的手册条目,右边是 AI 必须遵守的对应条款。没有 AI 对应的,是只能由作者本人完成的事(比如实名、勾选声明、签合同)。" />
    <div className="stat-row">
      <div className="stat"><b>{rules.length}</b><span>手册条目</span></div>
      <div className="stat"><b>{covered}</b><span>有 AI 对应条款</span></div>
      <div className="stat"><b>{na}</b><span>作者本人负责</span></div>
      <div className="stat"><b>{ai.rules.length}</b><span>AI 规范条款</span></div>
    </div>
    {(gap.length > 0 || orphan.length > 0) && <p className="warn-note"><AlertTriangle size={14} />{gap.length > 0 && `未对照:${gap.map(r => r.id).join('、')}。`}{orphan.length > 0 && `编号失效:${orphan.join('、')}。`}</p>}
    <div className="chips-row">
      {([['all', '全部'], ['ai', '有 AI 对应'], ['na', '作者本人负责']] as const).map(([k, t]) => <button key={k} className={cx('chip', f === k && 'on')} onClick={() => setF(k)}>{t}</button>)}
      <span className="chip-sep" />
      <button className={cx('chip', !sec && 'on')} onClick={() => setSec('')}>全部章节</button>
      {secs.map(x => <button key={x} className={cx('chip', sec === x && 'on')} onClick={() => setSec(sec === x ? '' : x)}>{SEC_NAME[x] || x}</button>)}
    </div>
    <div className="map-table-wrap">
      <table className="map-table">
        <thead><tr><th>手册条目(给人)</th><th>AI 规范(给 AI)</th><th>依据</th></tr></thead>
        <tbody>
          {list.map(r => {
            const as = aiByRule[r.id] || []
            return (
              <tr key={r.id}>
                <td><button className="rule-id link" onClick={() => go(`guide/${r.sec}/${r.id}`)}>{r.id}</button> <b>{r.t}</b><div className="muted small-note">{SEC_NAME[r.sec]}{r.grp ? ` · ${r.grp}` : ''}</div></td>
                <td>{as.length ? as.map(a => <div key={a.id} className="map-ai"><button className="rule-id ai link" onClick={() => go(`guide/ai/${a.id}`)}>{a.id}</button> {a.rule}</div>) : <span className="muted">{r.ai === 'na' ? '作者本人负责(AI 无法代办)' : '—'}</span>}</td>
                <td className="nowrap"><Src ids={r.src} /></td>
              </tr>
            )
          })}
        </tbody>
      </table>
    </div>
  </>
}

/* ---------- 资料来源 ---------- */
function Sources() {
  const cites = useMemo(() => {
    const m: Record<string, number> = {}
    const add = (ids?: string[]) => ids?.forEach(id => { m[id] = (m[id] || 0) + 1 })
    rules.forEach(r => add(r.src)); ai.rules.forEach(r => add(r.src)); guide.facts.forEach((f: any) => add(f.src)); guide.changelog.forEach((c: any) => add(c.src)); guide.flow.forEach((f: any) => add(f.src))
    return m
  }, [])
  const ORDER = ['official', 'gov', 'media', 'author'] as const
  const NAME: Record<string, string> = { official: '番茄官方', gov: '国家法规与政府文件', media: '媒体报道', author: '作者经验(仅作参考)' }
  return <>
    <Head eyebrow="资料来源" title="这份手册依据了哪些资料" sub={`共 ${sources.length} 份。规则以「番茄官方」和「国家法规」为准;媒体与作者经验只用来补充官方没有公开写明的细节,并在条目里单独标注。`} />
    {ORDER.map(lv => {
      const list = sources.filter(s => s.level === lv)
      if (!list.length) return null
      return (
        <section key={lv} className="sheet">
          <h2 className="sheet-title">{NAME[lv]} <span className="muted small-note">{list.length} 份</span></h2>
          <ul className="src-list-doc">
            {list.map(s => <li key={s.id}>
              <a href={s.url} target="_blank" rel="noreferrer">{s.title} <ExternalLink size={11} /></a>
              <span className="muted">{[s.publisher, s.date, cites[s.id] ? `引用 ${cites[s.id]} 处` : ''].filter(Boolean).join(' · ')}</span>
              {s.note && <span className="muted small-note">{s.note}</span>}
            </li>)}
          </ul>
        </section>
      )
    })}
  </>
}