Skip to content

feat: implement anti-AI infrastructure (issue #139) - #178

Merged
DankerMu merged 5 commits into
mainfrom
feat/issue-139-anti-ai-infrastructure
Mar 7, 2026
Merged

feat: implement anti-AI infrastructure (issue #139)#178
DankerMu merged 5 commits into
mainfrom
feat/issue-139-anti-ai-infrastructure

Conversation

@DankerMu

@DankerMu DankerMu commented Mar 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • upgrade anti-AI infrastructure docs, manifests, schema, and prompts for issue 139
  • add blacklist/structural lint support plus runtime anti-AI context injection
  • add regression coverage for prompts, runtime packets, lint scripts, and schema compatibility

Testing

  • npm test

Closes #139

@DankerMu

DankerMu commented Mar 7, 2026

Copy link
Copy Markdown
Owner Author

🔍 PR #178 交叉审核报告

审核方式:5 个独立 Agent 并行审查(TypeScript 代码质量 / Shell 脚本 / 规范一致性 / Schema+Template / 跨系统映射),以下为汇总结论。


🔴 P0 — 架构债务(建议修复)

1. Genre 别名映射跨系统不一致

  • TypeScript canonical: "scifi" / "suspense"
  • Python (lint-structural.sh) canonical: "sci-fi" / "mystery"
  • 当前已有桥接 (toStructuralLintGenre() at anti-ai-context.ts:552-565) 做了翻译,运行时安全。但这是脆弱设计——后续新增脚本或维护者修改映射时若漏掉桥接,会静默产生错误结果。
  • 建议:统一两端 canonical name,或至少在两端 GENRE_ALIASES 中加交叉引用注释。

2. TypeScript 端缺少 "science-fiction" 别名

  • Python 端注册了 "science-fiction" → "sci-fi" (lint-structural.sh:40)
  • TypeScript GENRE_ALIASES 无此条目
  • 影响:用户在 brief 中写 science-fiction 时,TypeScript 端返回 null,genre 覆写整条链路静默失效。
  • 修复anti-ai-context.ts:129 附近补 "science-fiction": "scifi"

🟡 P1 — 需要关注

3. BlacklistLintReport 类型擦除 (anti-ai-context.ts:657)

  • 精心构建的 BlacklistLintReport 对象被 as unknown as Record<string, unknown> 双重断言擦除为无类型字典。AntiAiJudgeContext.blacklistLint 字段类型应改为 BlacklistLintReport | null

4. 测试中 as any 泛滥

  • anti-ai-infrastructure.test.ts 中 8 处 (built as any).packet.manifest.inline。建议定义 extractInline() helper 做一次性断言。

5. Schema severity 枚举不统一 (labeled-chapter.schema.json)

  • structural_rule_violation.severity: ["warning", "error"] (L314)
  • 全局 $defs/severity: ["high", "medium", "low"] (L155)
  • 两套语义完全不同但未复用 $ref,消费代码如果期望统一 severity 类型会静默出错。

6. quality-rubric.md vs style-guide.md 罚分表述分歧

  • quality-rubric.md 用硬上限:"至少压到不高于 4/3 分"
  • style-guide.md 用增量:"额外 +1 个 yellow/red"
  • 两种表述在边界情况(如 0 yellow + 0 red + 2 violations)的结果不同。建议统一措辞。

7. narration_connector 词条设计需确认代码端已处理

  • 12 个 narration_connector 词条有意不在 words[] 中(category_metadata 注释明确)
  • 消费代码必须额外遍历 categories.narration_connector 并检查 context: "narration_only"lint-blacklist.sh_collect_entries() 已正确实现此逻辑 ✅

8. update_log words_count 不一致

  • v2.0.0 和 v2.1.0 的 words_count 均为 229,但 v2.1.0 声称新增了 8 个 simile_cliche 词条。至少有一个版本的计数不准确。

🟢 P2 — 轻微改善建议

9. 8 处空 catch {}anti-ai-context.ts L221/350/495/511/519/625)— 静默吞错误,生产排障困难。建议至少加注释说明意图。

10. mean([]) 返回 NaNanti-ai-context.ts:401)— 虽然调用链有保护,建议加 guard:if (values.length === 0) return 0;

11. BOM 处理缺失 — 两个 Python 脚本用 encoding="utf-8" 读文件,如果输入带 BOM 会影响首行匹配。建议改用 "utf-8-sig"

12. Windows 换行处理不一致lint-structural.sh 仅在 split_paragraphs 中处理 \r,其他函数直接操作原始文本。lint-blacklist.sh 完全不处理 \r

13. anti_ai_statistical_profileadditionalProperties: false — schema 其余对象均为 true,此处为迭代期新字段却锁死扩展。

14. lint-structural.sh Python 端 load_text() 隐式返回 Nonedie() 通过 raise SystemExit 退出所以运行时无问题,但类型检查器会报警。

15. _in_dialogue() 线性搜索 (lint-blacklist.sh:199-203) — 每个匹配项遍历全部 dialogue ranges。10 万字章节 + 大量黑名单词时可能产生延迟。可用二分搜索优化。


✅ 已确认无问题的审查点

审查项 结论
字段名一致性(4 个核心字段 × 所有文件) ✅ 完全对齐
默认值一致性([8,18] / [0.4,1.2] / "medium" ✅ 四处一致
zone→score 主映射表 ✅ 完全对齐
阈值数值(7 genre × 4 维度) ✅ TS/Python/style-guide 三端完全一致
参数名转译(max_paragraph_chars ↔ paragraph_char_max) toStructuralLintConfig() 桥接正确
indicator_mode 三级回退链 ✅ 13→7→4 正确升级
黑名单上限 250 ✅ periodic-maintenance / template / tasks 三处一致
安全性(命令注入/heredoc/路径穿越/symlink) ✅ 无安全问题
退出码约定 ✅ 两脚本一致(0/1/2)
向后兼容性 ✅ schema 新字段均 optional,fixture 兼容
测试覆盖(集成测试 + 降级场景) ✅ 充分(缺少纯函数单元测试但不阻塞)

📊 综合评分

维度 分数 说明
代码质量 3.5/5 类型擦除和空 catch 块拉低分数
安全性 4.0/5 execFile 正确使用,symlink 防护到位
规范一致性 4.5/5 几乎完美,仅罚分表述轻微分歧
数据质量 4.0/5 无重复词条,update_log 计数需修正
跨系统对齐 3.5/5 桥接层正确但架构脆弱
测试覆盖 4.0/5 集成充分,缺少纯函数单测

总体结论:PR 功能完整、安全性良好,核心规范高度一致。建议优先修复 P0 #1-#2(genre 映射)和 P1 #5(schema severity 枚举)后合入。 其余 P1/P2 可作为后续技术债务跟进。


🤖 交叉审核由 5 个独立 Agent 并行完成(TypeScript 代码 / Shell 脚本 / 规范一致性 / Schema+Template / 跨系统映射)

@DankerMu
DankerMu merged commit aafbdb8 into main Mar 7, 2026
3 checks passed
@DankerMu
DankerMu deleted the feat/issue-139-anti-ai-infrastructure branch March 7, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CS-A4: 支撑设施更新(quality-rubric 7 指标 + lint-structural.sh + genre_overrides + eval schema)

1 participant