feat(skills): Scope B A2 — 4 竞品生成器注册表+上下文分派+端点接线

注册表 TOOLBOX +4 entry(continue/expand/de-ai/teardown,全 preview-only writes=[]);
ContextStrategy +with_prior_chapter/text_input;ToolGenerateRequest +text 字段。
toolbox_context 分派新策略(续写→build_continuation_context、原文→build_text_input_context);
路由续写经 chapter_repo 读最新 accepted/draft 正文注入 builder(core 不 import apps/api,仿 accept_op)。
预览仅 commit ledger 不写业务表(#3);只声明 tier(#2);system_prompt 进缓存前缀(#9)。
单测:4 生成器 generate 预览 + 续写读前文/草稿路由 + 扩写/降AI text 路由 + 拆书结构化;
更新 registry/strategy 计数测试(15 工具 / 6 策略)。门禁绿:ruff/format/mypy 196 files/pytest 168(api)+32(skills)。
This commit is contained in:
Yaojia Wang
2026-06-23 19:10:35 +02:00
parent 87dd09a797
commit a5351320a2
9 changed files with 417 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
"""T6 创作工具箱声明式描述符类型单测Wave-0 契约)。
仅校验描述符**类型**本身(无 TOOLBOX 注册表 seeding——那是 Wave A
- `ContextStrategy`4 种注入策略字面量;
- `ContextStrategy`:注入策略字面量4 基础 + 续写/原文输入 2 竞品策略)
- `InputField`声明式表单字段label/type/required/default/help
- `IngestSpec`可选入库目标table 必须在 KNOWN_TABLESNone=纯预览);
- `GeneratorTool`生成器声明legacy 带 legacy_route 且 spec 可为 None新工具带 spec+schema
@@ -45,18 +45,20 @@ def _spec() -> AgentSpec:
# ---- ContextStrategy ----
def test_context_strategy_has_four_values() -> None:
def test_context_strategy_values() -> None:
# Arrange / Act
from typing import get_args
values = set(get_args(ContextStrategy))
# Assert
# Assert4 基础策略 + 竞品快赢 2 策略(续写读前文 / 原文输入)。
assert values == {
"brief_only",
"with_project",
"with_world",
"with_outline_chapter",
"with_prior_chapter",
"text_input",
}

View File

@@ -1,7 +1,8 @@
"""T6.2 创作工具箱注册表(`TOOLBOX`)单测。
校验11 条齐全legacy 3 + 新 8legacy 携 legacy_route 且 spec=None新工具携 spec +
output_schema与 spec.output_schema 一致ingest 工具的 table 在白名单内;`get_tool` 解析。
校验15 条齐全legacy 3 + 新 8 + 竞品快赢 4legacy 携 legacy_route 且 spec=None
新工具携 spec + output_schema与 spec.output_schema 一致ingest 工具的 table 在白名单内;
`get_tool` 解析。
"""
from __future__ import annotations
@@ -18,17 +19,22 @@ _NEW_KEYS = {
"glossary",
"opening",
"fine-outline",
# 竞品快赢Scope B续写 / 扩写 / 降AI率 / 拆书(全 preview-only
"continue",
"expand",
"de-ai",
"teardown",
}
_INGEST_KEYS = {"golden-finger", "glossary", "fine-outline"}
def test_toolbox_has_all_eleven_tools() -> None:
def test_toolbox_has_all_tools() -> None:
# Arrange / Act
keys = set(TOOLBOX.keys())
# Assert
# Assertlegacy 3 + 新 8 + 竞品快赢 4 = 15。
assert keys == _LEGACY_KEYS | _NEW_KEYS
assert len(TOOLBOX) == 11
assert len(TOOLBOX) == 15
def test_legacy_tools_have_route_and_no_spec() -> None:

View File

@@ -24,16 +24,20 @@ from ww_shared import AppError, ErrorCode
from ww_skills.skill_permissions import KNOWN_TABLES
# 注入策略:决定为该生成器组哪些材料喂给网关(覆盖全部生成器~4 种)。
# 注入策略:决定为该生成器组哪些材料喂给网关(覆盖全部生成器)。
# - brief_only项目立意 + 用户一句话(脑洞/书名);
# - with_project+ 主线/卖点(简介);
# - with_world+ world_entities 卡(名字/金手指/词条——须契合世界观硬规则);
# - with_outline_chapter+ 指定章 outline beats细纲/黄金开篇)
# - with_outline_chapter+ 指定章 outline beats细纲/黄金开篇)
# - with_prior_chapter+ 最新已写正文(续写——端点先读最新 accepted/draft 正文注入);
# - text_input+ 作者提供的原文(扩写/降AI率/拆书样本——经请求 text 字段注入)。
ContextStrategy = Literal[
"brief_only",
"with_project",
"with_world",
"with_outline_chapter",
"with_prior_chapter",
"text_input",
]

View File

@@ -20,20 +20,28 @@ from ww_agents import (
blurb_spec,
book_title_spec,
brainstorm_spec,
continue_spec,
de_ai_spec,
expand_spec,
fine_outline_spec,
glossary_spec,
golden_finger_spec,
name_spec,
opening_spec,
teardown_spec,
)
from ww_agents.schemas import (
BlurbResult,
BookTeardownResult,
ContinuationResult,
DeAiResult,
DetailedOutlineResult,
GlossaryResult,
GoldenFingerResult,
IdeaListResult,
NameListResult,
OpeningResult,
PolishResult,
TitleListResult,
)
@@ -61,6 +69,16 @@ def _chapter_no_field() -> InputField:
)
# 原文输入(扩写/降AI率/拆书样本所需的大段正文)。
_SOURCE_TEXT_FIELD = InputField(
name="text",
label="原文",
type="textarea",
required=True,
help="待处理的正文/样本片段(扩写/降AI 的原文;拆书的章节样本)",
)
# 创作工具箱注册表key → 描述符。legacy 3 + 新 8 = 11 条。
TOOLBOX: dict[str, GeneratorTool] = {
# ---- legacyspec=None前端走 legacy_route 跳现有页面)----
@@ -179,6 +197,62 @@ TOOLBOX: dict[str, GeneratorTool] = {
input_fields=[_chapter_no_field(), _BRIEF_FIELD],
ingest=IngestSpec(table="outline"),
),
# ---- 竞品快赢Scope B续写 / 扩写 / 降AI率 / 拆书(全 preview-onlywrites=[]----
"continue": GeneratorTool(
key="continue",
title="续写生成器",
subtitle="承接前文,无缝续写下文",
spec=continue_spec,
output_schema=ContinuationResult,
context_strategy="with_prior_chapter",
input_fields=[
InputField(
name="chapter_no",
label="续写章号",
type="number",
required=False,
help="续写的目标章号(读取该章已写正文承接;缺则按设定起笔)",
),
_BRIEF_FIELD,
],
),
"expand": GeneratorTool(
key="expand",
title="扩写生成器",
subtitle="在原文基础上丰富细节铺陈",
spec=expand_spec,
output_schema=PolishResult,
context_strategy="text_input",
input_fields=[_SOURCE_TEXT_FIELD, _BRIEF_FIELD],
),
"de-ai": GeneratorTool(
key="de-ai",
title="降 AI 率生成器",
subtitle="去机翻腔,更自然的人写质感",
spec=de_ai_spec,
output_schema=DeAiResult,
context_strategy="text_input",
input_fields=[_SOURCE_TEXT_FIELD, _BRIEF_FIELD],
),
"teardown": GeneratorTool(
key="teardown",
title="拆书生成器",
subtitle="拆解主题/原型/结构/钩子套路",
spec=teardown_spec,
output_schema=BookTeardownResult,
context_strategy="text_input",
input_fields=[
InputField(
name="kind",
label="书名",
type="text",
required=False,
help="待拆解作品的书名(供拆解对照)",
),
_SOURCE_TEXT_FIELD,
_BRIEF_FIELD,
],
),
}