소스 검색

fix: 显式调用插件 subagent

lingfengQAQ 1 개월 전
부모
커밋
8feea3a2d7

+ 25 - 0
webnovel-writer/scripts/data_modules/tests/test_prompt_integrity.py

@@ -240,6 +240,8 @@ def test_webnovel_review_skill_uses_unified_reviewer_pipeline():
     skill_text = _read_text(SKILLS_DIR / "webnovel-review" / "SKILL.md")
 
     assert "`reviewer`" in skill_text
+    assert "Agent(" in skill_text
+    assert 'subagent_type: "webnovel-writer:reviewer"' in skill_text
     assert "review-pipeline" in skill_text
     assert ".webnovel/tmp/review_results.json" in skill_text
     assert ".webnovel/tmp/review_metrics.json" in skill_text
@@ -257,6 +259,29 @@ def test_webnovel_review_skill_uses_unified_reviewer_pipeline():
     assert " workflow " not in skill_text
 
 
+def test_active_skills_use_agent_tool_name_not_legacy_task():
+    """Claude Code 2.1.63+ 将 Task 工具改名为 Agent;active skills 不应再声明 Task。"""
+    for skill_file in SKILL_FILES:
+        text = _read_text(skill_file)
+        fm = _extract_frontmatter(text)
+        allowed_tools = fm.get("allowed-tools", "")
+        assert "Task" not in allowed_tools, f"{skill_file.parent.name}: allowed-tools 仍声明 Task"
+        assert "Task 调用" not in text, f"{skill_file.parent.name}: 仍使用软性的 Task 调用描述"
+        assert "必须通过 `Task`" not in text, f"{skill_file.parent.name}: 仍要求旧 Task 工具名"
+
+
+def test_webnovel_write_skill_uses_explicit_agent_invocation_templates():
+    """webnovel-write 的关键 subagent 必须用显式 Agent(subagent_type=...) 调用模板。"""
+    text = _read_text(SKILLS_DIR / "webnovel-write" / "SKILL.md")
+    fm = _extract_frontmatter(text)
+
+    assert "Agent" in fm.get("allowed-tools", "")
+    for subagent in ("context-agent", "reviewer", "data-agent"):
+        assert f'subagent_type: "webnovel-writer:{subagent}"' in text
+        assert f'subagent_type: "{subagent}"' not in text
+    assert "不得用主流程口头代替 subagent 输出" in text
+
+
 def test_story_system_runtime_contract_commands_exist():
     text = (SKILLS_DIR / "webnovel-write" / "SKILL.md").read_text(encoding="utf-8")
     assert "story-system" in text

+ 3 - 3
webnovel-writer/skills/webnovel-init/SKILL.md

@@ -1,7 +1,7 @@
 ---
 name: webnovel-init
 description: 深度初始化网文项目。通过分阶段交互收集完整创作信息,生成可直接进入规划与写作的项目骨架与约束文件。
-allowed-tools: Read Write Edit Grep Bash Task AskUserQuestion WebSearch WebFetch
+allowed-tools: Read Write Edit Grep Bash Agent AskUserQuestion WebSearch WebFetch
 ---
 
 # Project Initialization (Deep Mode)
@@ -16,7 +16,7 @@ allowed-tools: Read Write Edit Grep Bash Task AskUserQuestion WebSearch WebFetch
 
 1. 先收集,再生成;未过充分性闸门,不执行 `init_project.py`。
 2. 分波次提问,每轮只问"当前缺失且会阻塞下一步"的信息。
-3. 允许调用 `Read/Grep/Bash/Task/AskUserQuestion/WebSearch/WebFetch` 辅助收集。
+3. 允许调用 `Read/Grep/Bash/Agent/AskUserQuestion/WebSearch/WebFetch` 辅助收集。
 4. 用户已明确的信息不重复问;冲突信息优先让用户裁决。
 5. Deep 模式优先完整性,允许慢一点,但禁止漏关键字段。
 
@@ -57,7 +57,7 @@ allowed-tools: Read Write Edit Grep Bash Task AskUserQuestion WebSearch WebFetch
 
 - `Read/Grep`:读取项目上下文与参考文件(`README.md`、`CLAUDE.md`、`templates/genres/*`、`references/*`)。
 - `Bash`:执行 `init_project.py`、文件存在性检查、最小验证命令。
-- `Task`:拆分并行子任务(如题材映射、约束包候选生成、文件验证)。
+- `Agent`:拆分并行子任务(如题材映射、约束包候选生成、文件验证)。
 - `AskUserQuestion`:用于关键分歧裁决、候选方案选择、最终确认。
 - `WebSearch`:用于检索最新市场趋势、平台风向、题材数据(可带域名过滤)。
 - `WebFetch`:用于抓取已确定来源页面内容并做事实核验。

+ 9 - 2
webnovel-writer/skills/webnovel-review/SKILL.md

@@ -1,7 +1,7 @@
 ---
 name: webnovel-review
 description: 使用审查 Agent 评估章节质量,生成报告并写回审查指标。
-allowed-tools: Read Grep Write Edit Bash Task AskUserQuestion
+allowed-tools: Read Grep Write Edit Bash Agent AskUserQuestion
 ---
 
 # Quality Review Skill
@@ -91,7 +91,14 @@ cat "${PROJECT_ROOT}/.webnovel/state.json"
 
 ### Step 4:调用统一审查 Agent
 
-必须通过 `Task` 调用 `reviewer`,禁止主流程伪造结论。
+必须通过 `Agent` 工具调用 `reviewer`,禁止主流程伪造结论或口头总结代替 subagent 输出。
+
+```text
+Agent(
+  subagent_type: "webnovel-writer:reviewer",
+  prompt: "chapter={chapter_num}; chapter_file={chapter_file}; project_root=${PROJECT_ROOT}; scripts_dir=${SCRIPTS_DIR}。严格输出 reviewer schema JSON,并保存到 ${PROJECT_ROOT}/.webnovel/tmp/review_results.json。"
+)
+```
 
 输入:
 - `chapter`

+ 26 - 4
webnovel-writer/skills/webnovel-write/SKILL.md

@@ -1,7 +1,7 @@
 ---
 name: webnovel-write
 description: 产出可发布章节,完整执行上下文→起草→审查→润色→提交→备份。
-allowed-tools: Read Write Edit Grep Bash Task
+allowed-tools: Read Write Edit Grep Bash Agent
 ---
 
 # 写章流程
@@ -21,6 +21,7 @@ allowed-tools: Read Write Edit Grep Bash Task
 ## 硬规则
 
 - 禁止并步、跳步、伪造审查
+- 必须使用 `Agent` 工具调用指定 subagent;不得用主流程口头代替 subagent 输出
 - blocking issue 未解决不进 Step 4/5
 - 失败只补跑失败步骤,不回退
 - 参考资料按步骤按需加载
@@ -67,7 +68,14 @@ python -X utf8 "${SCRIPTS_DIR}/webnovel.py" --project-root "${WORKSPACE_ROOT}" \
 
 ### Step 1:context-agent 生成写作任务书
 
-Task 调用 `context-agent`,传入 chapter/project_root/storage_path/state_file。
+必须使用 `Agent` 工具调用 `context-agent`,不得由主流程自行整理任务书。
+
+```text
+Agent(
+  subagent_type: "webnovel-writer:context-agent",
+  prompt: "chapter={chapter_num}; project_root=${PROJECT_ROOT}; scripts_dir=${SCRIPTS_DIR}; storage_path=${PROJECT_ROOT}/.webnovel; state_file=${PROJECT_ROOT}/.webnovel/state.json。先 research,再输出五段写作任务书。"
+)
+```
 
 产物:一份写作任务书,能独立支撑 Step 2 起草。
 
@@ -77,7 +85,14 @@ Task 调用 `context-agent`,传入 chapter/project_root/storage_path/state_fil
 
 ### Step 3:审查
 
-Task 调用 `reviewer`,传入 chapter/chapter_file/project_root/scripts_dir。
+必须使用 `Agent` 工具调用 `reviewer`,不得由主流程伪造审查 JSON。
+
+```text
+Agent(
+  subagent_type: "webnovel-writer:reviewer",
+  prompt: "chapter={chapter_num}; chapter_file=${CHAPTER_FILE}; project_root=${PROJECT_ROOT}; scripts_dir=${SCRIPTS_DIR}。严格输出 reviewer schema JSON,并保存到 ${PROJECT_ROOT}/.webnovel/tmp/review_results.json。"
+)
+```
 
 ```bash
 python -X utf8 "${SCRIPTS_DIR}/webnovel.py" --project-root "${PROJECT_ROOT}" review-pipeline \
@@ -102,7 +117,14 @@ blocking=true → 修复后重审,不进 Step 4。`--fast` 只检查 setting/t
 
 #### 5.1 Data Agent 提取事实
 
-Task 调用 `data-agent`,产出 review_results / fulfillment_result / disambiguation_result / extraction_result 四份 JSON。
+必须使用 `Agent` 工具调用 `data-agent`,产出 fulfillment_result / disambiguation_result / extraction_result 三份 JSON,并复用 Step 3 的 review_results。
+
+```text
+Agent(
+  subagent_type: "webnovel-writer:data-agent",
+  prompt: "chapter={chapter_num}; chapter_file=${CHAPTER_FILE}; project_root=${PROJECT_ROOT}; scripts_dir=${SCRIPTS_DIR}。从正文提取事实,生成 .webnovel/tmp/ 下的 fulfillment_result.json、disambiguation_result.json、extraction_result.json;不直接写 state/index/summaries/memory。"
+)
+```
 
 Data Agent 只提取事实+生成 artifacts,不直接写 state/index/summaries/memory。