feat: M4 文风 + M5 生成/多provider/Skill + Kimi Code 订阅接入 + 本地联调修复

M4(文风): style-auditor 双轨(提取指纹/漂移第四审)+ jobs 长任务框架(zombie reaper) + 回炉 refine + GET /style read-back。
M5(生成+扩展): worldbuilder/character-gen(入库 continuity 409 gate + partition_writes 白名单 + schema→JSONB 形变);
  网关多 provider 回退链/熔断/能力降级(Anthropic/Gemini 适配器);Skill registry + 表权限沙箱 + 规则;
  前端 角色生成器/世界观/Codex/规则页/技能库/⌘K 命令面板。
K1(Kimi Code 订阅接入): OAuth device-flow(kimi-code)+ 静态 Console key(kimi-code-key)两路径;
  coding 端点 KimiCLI 伪造头(实测 UA allow-list 门禁,缺则 403)+ JSON 模式结构化(thinking ⊥ tool_choice)。
本地联调修复: CORS 中间件;assemble 注入 premise+「写第N章」指令(修空 prompt 400);
  GET /outline·/draft read-back + 大纲/工作台/审稿页重载;写页 client/server 常量边界 + notFound 健壮化;
  字数 toLocaleString locale 水合;审稿页终稿从已存草稿 seed(修 accept 422)。
门禁: backend ruff/mypy(157)/alembic 无漂移/pytest 451 · frontend lint/tsc/vitest/build。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2026-06-20 10:39:58 +02:00
parent 5fb7bfb1de
commit 765dbdfbd4
161 changed files with 17330 additions and 208 deletions

View File

@@ -0,0 +1,97 @@
"use client";
import type { CharacterCardView } from "@/lib/api/types";
interface CharacterCardItemProps {
card: CharacterCardView;
selected: boolean;
onToggle: () => void;
// 入库前作者就地编辑名/弧光(最小可编辑面,避免重型表单)。
onEdit?: (patch: Partial<CharacterCardView>) => void;
}
// 单张角色预览卡UX §6.6):勾选入库 + 关键字段就地编辑。
export function CharacterCardItem({
card,
selected,
onToggle,
onEdit,
}: CharacterCardItemProps) {
return (
<article
className={`rounded border p-3 text-sm ${
selected ? "border-cinnabar bg-[var(--color-cinnabar-wash)]" : "border-line bg-panel"
}`}
>
<header className="mb-2 flex items-center gap-2">
<input
type="checkbox"
checked={selected}
onChange={onToggle}
aria-label={`选择角色 ${card.name}`}
className="size-4 accent-cinnabar"
/>
{onEdit ? (
<input
value={card.name}
onChange={(e) => onEdit({ name: e.target.value })}
aria-label="角色名"
className="flex-1 rounded border border-line bg-bg px-2 py-1 font-serif text-base text-ink"
/>
) : (
<span className="flex-1 font-serif text-base text-ink">{card.name}</span>
)}
<span className="rounded bg-bg px-2 py-0.5 text-xs text-ink-soft">
{card.role}
</span>
</header>
{card.traits && card.traits.length > 0 ? (
<p className="mb-1 text-ink-soft">
<span className="text-ink"></span>
{card.traits.join("、")}
</p>
) : null}
<p className="mb-1 text-ink-soft">
<span className="text-ink"></span>
{card.backstory}
</p>
<div className="mb-1 flex items-start gap-1 text-ink-soft">
<span className="shrink-0 text-ink"></span>
{onEdit ? (
<input
value={card.arc}
onChange={(e) => onEdit({ arc: e.target.value })}
aria-label="人物弧光"
className="flex-1 rounded border border-line bg-bg px-2 py-1 text-ink"
/>
) : (
<span>{card.arc}</span>
)}
</div>
{card.speech_tics && card.speech_tics.length > 0 ? (
<p className="mb-1 text-ink-soft">
<span className="text-ink"></span>
{card.speech_tics.join("、")}
</p>
) : null}
{card.relations && card.relations.length > 0 ? (
<ul className="mt-1 flex flex-wrap gap-1">
{card.relations.map((r, i) => (
<li
key={`${r.name}-${i}`}
className="rounded bg-bg px-2 py-0.5 text-xs text-ink-soft"
>
{r.kind}{r.name}
{r.note ? `${r.note}` : ""}
</li>
))}
</ul>
) : null}
</article>
);
}

View File

@@ -0,0 +1,171 @@
"use client";
import { useCallback, useEffect, useMemo, useState } from "react";
import type { CharacterCardView } from "@/lib/api/types";
import {
MAX_CHARACTER_COUNT,
MIN_CHARACTER_COUNT,
updateCard,
} from "@/lib/generation/cards";
import { useCharacterGen } from "@/lib/generation/useCharacterGen";
import { CharacterCardItem } from "./CharacterCardItem";
import { ConflictAdjudication } from "./ConflictAdjudication";
interface CharacterGeneratorProps {
projectId: string;
// 入库成功后回调(如刷新 Codex 本地列表)。
onIngested?: (created: string[], cards: CharacterCardView[]) => void;
}
// 角色生成器UX §6.6):一句话需求 + 数量 + 定位 → 预览卡 → 选/改 → 入库(处理 409 裁决)。
export function CharacterGenerator({
projectId,
onIngested,
}: CharacterGeneratorProps) {
const gen = useCharacterGen();
const [brief, setBrief] = useState("");
const [count, setCount] = useState(MIN_CHARACTER_COUNT);
const [role, setRole] = useState("");
// 编辑态卡片(预览返回后拷贝进本地,允许就地改)。
const [drafts, setDrafts] = useState<CharacterCardView[]>([]);
const [selected, setSelected] = useState<Set<number>>(new Set());
// 预览返回 → 同步进本地编辑态 + 默认全选。
const syncDrafts = useCallback((cards: CharacterCardView[]) => {
setDrafts(cards);
setSelected(new Set(cards.map((_, i) => i)));
}, []);
const onGenerate = useCallback(async () => {
await gen.generate({ projectId, brief, count, role });
}, [gen, projectId, brief, count, role]);
// gen.cards 变化(新预览)→ 重新同步本地草稿。
const previewKey = gen.cards.map((c) => c.name).join("|");
useEffect(() => {
if (gen.genStatus === "preview") syncDrafts(gen.cards);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [previewKey, gen.genStatus]);
const toggle = (i: number): void => {
setSelected((prev) => {
const next = new Set(prev);
if (next.has(i)) next.delete(i);
else next.add(i);
return next;
});
};
const selectedCards = useMemo(
() => drafts.filter((_, i) => selected.has(i)),
[drafts, selected],
);
const doIngest = useCallback(
async (acknowledge: boolean) => {
const ok = await gen.ingest(projectId, selectedCards, acknowledge);
if (ok) {
onIngested?.(gen.created, selectedCards);
setDrafts([]);
setSelected(new Set());
}
},
[gen, projectId, selectedCards, onIngested],
);
const generating = gen.genStatus === "generating";
const ingesting = gen.ingestStatus === "ingesting";
return (
<section className="flex flex-col gap-4" aria-label="角色生成器">
<div className="rounded border border-line bg-panel p-4">
<h2 className="mb-3 font-serif text-base text-ink"></h2>
<label className="mb-2 block text-sm text-ink-soft">
<input
value={brief}
onChange={(e) => setBrief(e.target.value)}
placeholder="如:一个亦正亦邪的剑修,背负灭门血仇"
className="mt-1 w-full rounded border border-line bg-bg px-3 py-2 text-sm text-ink"
/>
</label>
<div className="flex flex-wrap items-end gap-3">
<label className="text-sm text-ink-soft">
<input
type="number"
min={MIN_CHARACTER_COUNT}
max={MAX_CHARACTER_COUNT}
value={count}
onChange={(e) => setCount(Number(e.target.value))}
className="mt-1 block w-20 rounded border border-line bg-bg px-2 py-1.5 text-sm text-ink"
/>
</label>
<label className="flex-1 text-sm text-ink-soft">
<input
value={role}
onChange={(e) => setRole(e.target.value)}
placeholder="主角 / CP / 对手 / 导师 / 工具人"
className="mt-1 block w-full rounded border border-line bg-bg px-2 py-1.5 text-sm text-ink"
/>
</label>
<button
type="button"
onClick={() => void onGenerate()}
disabled={generating || brief.trim().length === 0}
className="rounded bg-cinnabar px-4 py-2 text-sm text-white disabled:opacity-50"
>
{generating ? "生成中…" : "生成"}
</button>
</div>
</div>
{gen.genStatus === "preview" && drafts.length > 0 ? (
<div className="flex flex-col gap-3">
<p className="text-xs text-ink-soft">
{drafts.length} {selectedCards.length} /
</p>
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
{drafts.map((card, i) => (
<CharacterCardItem
key={i}
card={card}
selected={selected.has(i)}
onToggle={() => toggle(i)}
onEdit={(patch) =>
setDrafts((prev) =>
prev.map((c, j) => (j === i ? updateCard(c, patch) : c)),
)
}
/>
))}
</div>
{gen.ingestStatus === "conflict" && gen.conflicts ? (
<ConflictAdjudication
conflicts={gen.conflicts}
busy={ingesting}
onAcknowledge={() => void doIngest(true)}
onCancel={() => gen.reset()}
/>
) : (
<button
type="button"
onClick={() => void doIngest(false)}
disabled={ingesting || selectedCards.length === 0}
className="self-start rounded bg-cinnabar px-4 py-2 text-sm text-white disabled:opacity-50"
>
{ingesting ? "入库中…" : `入库选中 ${selectedCards.length}`}
</button>
)}
</div>
) : null}
{gen.ingestStatus === "done" && gen.created.length > 0 ? (
<p className="text-sm text-pass">{gen.created.join("、")}</p>
) : null}
</section>
);
}

View File

@@ -0,0 +1,75 @@
"use client";
import type { IngestConflicts } from "@/lib/generation/cards";
interface ConflictAdjudicationProps {
conflicts: IngestConflicts;
busy: boolean;
// 作者已查看冲突,确认带 acknowledge 重发入库。
onAcknowledge: () => void;
onCancel: () => void;
}
// 入库 409 CONFLICT_UNRESOLVED 裁决面板UX §7 / 不变量#3
// 展示 continuity 预检冲突 → 作者裁决(确认入库 = acknowledge 重发 / 取消回去改卡)。
export function ConflictAdjudication({
conflicts,
busy,
onAcknowledge,
onCancel,
}: ConflictAdjudicationProps) {
return (
<div
role="alertdialog"
aria-label="continuity 冲突裁决"
className="rounded border border-conflict bg-panel p-4"
>
<h3 className="mb-1 font-serif text-base text-conflict">
{conflicts.conflictCount}
</h3>
<p className="mb-3 text-xs text-ink-soft">
</p>
<ul className="mb-3 flex flex-col gap-2">
{conflicts.conflicts.map((c, i) => (
<li key={i} className="rounded border border-line bg-bg p-2 text-sm">
<div className="mb-1 flex items-center gap-2">
<span className="rounded bg-conflict/10 px-2 py-0.5 text-xs text-conflict">
{c.type}
</span>
{c.where ? (
<span className="text-xs text-ink-soft">{c.where}</span>
) : null}
</div>
{c.refs.length > 0 ? (
<p className="mb-1 text-xs text-ink-soft">
{c.refs.join("、")}
</p>
) : null}
{c.suggestion ? (
<p className="text-ink">{c.suggestion}</p>
) : null}
</li>
))}
</ul>
<div className="flex gap-2">
<button
type="button"
onClick={onAcknowledge}
disabled={busy}
className="rounded bg-conflict px-3 py-1.5 text-sm text-white disabled:opacity-50"
>
</button>
<button
type="button"
onClick={onCancel}
disabled={busy}
className="rounded border border-line px-3 py-1.5 text-sm text-ink disabled:opacity-50"
>
</button>
</div>
</div>
);
}

View File

@@ -0,0 +1,78 @@
"use client";
import { useCallback, useState } from "react";
import { worldEntityRules } from "@/lib/generation/cards";
import { useWorldGen } from "@/lib/generation/useWorldGen";
interface WorldGeneratorProps {
projectId: string;
}
// 世界观设计器UX §6.5):一句话需求 → 预览实体卡type/name/rules
// 本期世界观入库端点未建(仅预览);预览结果供作者参考/复制。
export function WorldGenerator({ projectId }: WorldGeneratorProps) {
const gen = useWorldGen();
const [brief, setBrief] = useState("");
const onGenerate = useCallback(async () => {
await gen.generate(projectId, brief);
}, [gen, projectId, brief]);
const generating = gen.status === "generating";
return (
<section className="flex flex-col gap-4" aria-label="世界观设计器">
<div className="rounded border border-line bg-panel p-4">
<h2 className="mb-3 font-serif text-base text-ink"></h2>
<label className="mb-3 block text-sm text-ink-soft">
<textarea
value={brief}
onChange={(e) => setBrief(e.target.value)}
placeholder="如:东方修真世界,灵气复苏,宗门林立,强者寿元有限"
rows={3}
className="mt-1 w-full resize-y rounded border border-line bg-bg px-3 py-2 text-sm text-ink"
/>
</label>
<button
type="button"
onClick={() => void onGenerate()}
disabled={generating || brief.trim().length === 0}
className="rounded bg-cinnabar px-4 py-2 text-sm text-white disabled:opacity-50"
>
{generating ? "生成中…" : "生成世界观"}
</button>
</div>
{gen.status === "done" && gen.entities.length > 0 ? (
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
{gen.entities.map((entity, i) => (
<article
key={`${entity.name}-${i}`}
className="rounded border border-line bg-panel p-3 text-sm"
>
<header className="mb-2 flex items-center gap-2">
<span className="font-serif text-base text-ink">
{entity.name}
</span>
<span className="rounded bg-bg px-2 py-0.5 text-xs text-ink-soft">
{entity.type}
</span>
</header>
{worldEntityRules(entity).length > 0 ? (
<ul className="flex list-disc flex-col gap-1 pl-5 text-ink-soft">
{worldEntityRules(entity).map((rule, j) => (
<li key={j}>{rule}</li>
))}
</ul>
) : (
<p className="text-ink-soft"></p>
)}
</article>
))}
</div>
) : null}
</section>
);
}