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 = { flow: 'sign', redlines: 'red', structure: 'craft' } const SEC_NAME: Record = Object.fromEntries(SECTIONS.map(s => [s.id, s.t])) export function Src({ ids }: { ids?: string[] }) { if (!ids?.length) return null return ( {ids.map(id => srcMap[id] ? {LEVEL[srcMap[id].level]} : null)} ) } 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 (
{s === 'start' && } {s === 'author' && } {s === 'sign' && } {s === 'red' && } {s === 'quality' && } {s === 'craft' && } {s === 'check' && } {s === 'ai' && } {s === 'map' && } {s === 'sources' && }
) } /* ---------- 作者状态:全局规则,写作 AI 和协作 AI 都要按它判断 ---------- */ function Author() { return <> } function Head({ eyebrow, title, sub, children }: { eyebrow: string; title: string; sub?: string; children?: React.ReactNode }) { return
{eyebrow}

{title}

{sub &&

{sub}

}{children}
} /* ---------- 通用条目卡片 ---------- */ const RISK: Record = { ban: { t: '封书封号', d: '最严重,可能永久封禁作品或账号' }, down: { t: '下架屏蔽', d: '作品或章节被下架、屏蔽' }, limit: { t: '限流降权', d: '不推荐、降低曝光、取消福利' }, reject: { t: '审核不过', d: '发布、签约或推荐被驳回' }, } const LV: Record = { 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' ? 作者本人负责 : null return {list.map(a => )} } function RuleCard({ r }: { r: Rule }) { return (
{r.id}

{r.t}

{r.level && {LV[r.level]?.t}} {r.risk && {RISK[r.risk]?.t}}

{r.d}

{r.official &&
{r.official}
} {r.traps?.length ?

容易踩的坑

    {r.traps.map(t =>
  • {t}
  • )}
: null} {r.safe &&

安全写法

{r.safe}

}
依据
) } 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) =>
{g &&

{g}

}
{rs.map(r => )}
)} } function RuleSection({ sec, eyebrow, title, sub }: { sec: string; eyebrow: string; title: string; sub?: string }) { return <> 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 <>
版本 {guide.meta.version}核对于 {guide.meta.checked} {nRules} 条手册条目{nAi} 条 AI 规范{sources.length} 份资料(官方与法规 {nOfficial} 份)

先记住这几件事

{guide.facts.map((f: any) => (
{f.k}{f.v}

{f.d}

{f.ref && }
))}

规则变化时间线

    {guide.changelog.map((c: any, i: number) => (
  1. {c.date}
    {c.t}

    {c.d}

  2. ))}

新手路线

    {guide.roadmap.map((r: any, i: number) => (
  1. {r.w}
    {r.t}

    {r.d}

    {r.go && }
  2. ))}
} /* ---------- 签约与收益 ---------- */ function Sign() { return <>
    {guide.flow.map((f: any) => (
  1. {f.n}
    {f.title}{f.tag && {f.tag}}
      {f.items.map((it: any, i: number) =>
    • {it.v === 'warn' ? : it.v === 'exp' ? 经验 : }{it.t}{it.ref && }
    • )}
  2. ))}
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 <>
{cats.map(c => )}
{Object.entries(RISK).map(([k, v]) => )}
{list.map(r => )} {!list.length && }
} /* ---------- 写作方法 ---------- */ function Craft() { const [tab, setTab] = useState<'short' | 'long'>('short') const frame = guide.frames[tab] return <> r.sec === 'craft')} />

结构模板

在作品的「大纲」页可以一键套用。模板是练习用的骨架,不是平台要求。

{tab === 'short' ? (
{guide.shortBeats.map((b: any, i: number) => (
{i + 1}{b.name}{b.range} · {b.words}

{b.goal}

{b.example &&
{b.example}
}
))}
) : (
{guide.longVolumes.map((v: any) => (

{v.vol}

{v.ch} · {v.words}

{v.goal}

    {v.beats.map((b: string) =>
  1. {b}
  2. )}
))}
)}

{frame.t}

{frame.size}
{frame.parts.map((p: any) => )}
{p.t}{p.range}{p.goal}
{guide.genres?.length > 0 && <>

题材怎么选

{guide.genres.map((g: any) => (
{g.name}{g.pick && 新手推荐}{g.side}
安全 上手 {g.form}

{g.why}

{g.lines?.length > 0 && <>

守住这些线

    {g.lines.map((l: string) =>
  • {l}
  • )}
} {g.tips?.length > 0 && <>

写法建议

    {g.tips.map((l: string) =>
  • {l}
  • )}
}
))}
} } const Dots = ({ n }: { n: number }) => {[1, 2, 3, 4, 5].map(i => )} /* ---------- 自查清单 ---------- */ 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 = {} 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 <>
{d.error && } {pid && !d.data && !d.error &&

正在读取检查结果…

} {d.data && (latest ?
最近一次:{latest.by} · {fmtAgo(latest.created_at)}{latest.scope === 'chapter' ? ` · 第${latest.chapter_number}章` : ' · 全书'}{cnt('fail')} 不通过{cnt('warn')} 需注意{cnt('pass')} 通过{all.length - cnt('fail') - cnt('warn') - cnt('pass')} 未检查
:
未检查这本书还没有自查记录。把上面那句话发给 AI 即可。
)} {latest?.summary &&
} {guide.checklist.map((g: any) => (

{g.name} {g.when}

    {g.items.map((i: any) => { const r = res[i.id] || res[i.t] return (
  • {r ? : 未检查} {i.t}{i.why && {i.why}} {i.ref?.length > 0 && {i.ref.map((id: string) => )}}
    {r && (r.note || r.quote || r.fix) &&
    {r.note &&

    {r.note}

    }{r.quote &&
    {r.quote}
    }{r.fix &&

    建议:{r.fix}

    }
    }
  • ) })}
))}

番茄平台规定检查 内容红线 + 低质与 AI 规则,共 {rules.filter(r => r.sec === 'red' || r.sec === 'quality').length} 条

{plat ? :

还没有全书的平台规定检查。单章检查结果在书房每章的「检查」面板里。

}
} /* ---------- 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 <>

你的角色

    {ai.preamble.map(p =>
  • {p}
  • )}
{ai.groups.map(g => { const list = ai.rules.filter(r => r.g === g.id && match(r)) if (!list.length) return null return (

{g.t}

{g.d &&

{g.d}

}
{list.map(r => (
{r.id}

{r.rule}

{r.hard && 硬性}
{r.detail &&

{r.detail}

} {(r.do?.length || r.dont?.length) ? (
{r.do?.length ?

要

    {r.do.map(x =>
  • {x}
  • )}
: null} {r.dont?.length ?

不要

    {r.dont.map(x =>
  • {x}
  • )}
: null}
) : null} {r.check &&

自检:{r.check}

}
对应手册 {r.maps.map(h => )}
))}
) })}

遇到这些请求,拒绝或改写

    {ai.refuse.map(x =>
  • {x}
  • )}

每次输出前的自检

    {ai.output.map(x =>
  1. {x}
  2. )}

精简版(硬性条款)

{aiPromptBlock()}
} /* ---------- 对照表 ---------- */ 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 <>
{rules.length}手册条目
{covered}有 AI 对应条款
{na}作者本人负责
{ai.rules.length}AI 规范条款
{(gap.length > 0 || orphan.length > 0) &&

{gap.length > 0 && `未对照:${gap.map(r => r.id).join('、')}。`}{orphan.length > 0 && `编号失效:${orphan.join('、')}。`}

}
{([['all', '全部'], ['ai', '有 AI 对应'], ['na', '作者本人负责']] as const).map(([k, t]) => )} {secs.map(x => )}
{list.map(r => { const as = aiByRule[r.id] || [] return ( ) })}
手册条目(给人)AI 规范(给 AI)依据
{r.t}
{SEC_NAME[r.sec]}{r.grp ? ` · ${r.grp}` : ''}
{as.length ? as.map(a =>
{a.rule}
) : {r.ai === 'na' ? '作者本人负责(AI 无法代办)' : '—'}}
} /* ---------- 资料来源 ---------- */ function Sources() { const cites = useMemo(() => { const m: Record = {} 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 = { official: '番茄官方', gov: '国家法规与政府文件', media: '媒体报道', author: '作者经验(仅作参考)' } return <> {ORDER.map(lv => { const list = sources.filter(s => s.level === lv) if (!list.length) return null return (

{NAME[lv]} {list.length} 份

    {list.map(s =>
  • {s.title} {[s.publisher, s.date, cites[s.id] ? `引用 ${cites[s.id]} 处` : ''].filter(Boolean).join(' · ')} {s.note && {s.note}}
  • )}
) })} }