zizi b0bc7a8745 框架: 技能按动作-对象重组 + 先审后入创作闭环
一、技能重组(动作-对象命名)
- 旧目录 clean/confirm/continuation/db/detect/embed/… 重组为
  clean-book-text/decide-candidate/write-next-chapter/access-database/
  check-content-consistency/embed-knowledge/…(git 识别为 rename,内容保持)
- agents/*.md、AGENTS.md/CLAUDE.md 收编、example_skill 登记表同步新名

二、先审后入创作闭环(本次核心)
正文接受从"机械门一过就写正典"改为"机械门+语义审查双通过+用户批准+单事务原子提交",
DB 级兜底,编排层跳步即被硬拒。
- candidate_cas.py + example_candidate_cas(109):持久化 CAS 状态链
- fact_delta.py + example_fact_delta/example_fact_ledger(106):结构化事实增量,
  模型只提六型闭集增量+正文证据引文,仅用户批准的增量随正文同事务入账本
- projection_registry.py + example_projection_run(107):投影登记与恢复
- acceptance_state.py:接受前置实时状态重读
- lesson_registry.py + example_lesson(108):经验升格链,禁止自动升格
- DDL 105:example_candidate 增 semantic_status/semantic_report_sha256
- write_canonical.accept:语义兜底+同事务合并增量+登记投影;
  run_writer_pipeline/persist_writer_run/run_writer_semantic_detector/step2 接入全链
- claude_runtime:兼容新 CLI modelUsage 信息字段

三、审查修复(独立子代理四维审查后)
- 事实增量 propose→approve 翻态正道,不撞唯一键
- 冻结配置探针重刷(CLI 2.1.211→2.1.231 漂移),profileSha256/adapterVersion 再登记
- 可视化合同悬空路径/五六空间矛盾、 SoT 旧技能名漂移、行尾空白清理

测试:离线 65 套 + 真实库集成 5 套(CAS/接受故障注入/事实增量/投影/经验升格)+ 回放 79 项全绿。
创作内容(docs/design、生成正文 artifacts)按"框架与创作分开"未入本提交。
2026-08-14 10:24:08 +08:00

125 lines
4.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""细纲 detector 的机器可读输入输出合同。"""
from __future__ import annotations
from typing import Any, Mapping
DETECTOR_PROTOCOL = "fine_outline_detector_v0"
ALLOWED_SEVERITIES = frozenset({"high", "medium", "low"})
ALLOWED_FINDING_CATEGORIES = frozenset(
{
"candidate_structure",
"causal_chain",
"entity_state",
"foreshadowing_action",
"source_reference",
"unknowns_discipline",
}
)
ALLOWED_COVERAGE_CATEGORIES = frozenset({"frozen_context_gap"})
FINDING_FIELDS = frozenset({"category", "severity", "location", "evidenceSummary"})
COVERAGE_FINDING_FIELDS = frozenset({"category", "summary"})
def build_detector_request(
*,
candidate_id: str,
candidate: Mapping[str, Any],
as_of_chapter: int,
frozen_snapshot: Mapping[str, Any],
common_context: Mapping[str, Any],
sources: list[Any],
) -> dict[str, Any]:
"""只用公共冻结事实和匿名候选构造真正不识别评测臂的盲检输入。"""
return {
"protocol": DETECTOR_PROTOCOL,
"candidateId": candidate_id,
"asOfChapter": as_of_chapter,
"candidate": dict(candidate),
"planningContext": {
"frozenSnapshot": dict(frozen_snapshot),
"commonContext": dict(common_context),
"sources": list(sources),
},
"rules": {
"referenceProxyVisible": False,
"mayJudgeTargetRoleCardCoverage": False,
"highSeverityBlocksGroup": True,
},
}
def validate_detector_report(
report: Mapping[str, Any], expected_candidate_id: str
) -> dict[str, Any]:
"""机械校验 detector JSON;合同不完整时失败关闭。"""
errors: list[str] = []
if not isinstance(report, Mapping):
return {"ok": False, "errors": ["detector 报告必须是对象"], "highSeverityCount": 0}
if report.get("protocol") != DETECTOR_PROTOCOL:
errors.append(f"protocol 必须是 {DETECTOR_PROTOCOL}")
if report.get("candidateId") != expected_candidate_id:
errors.append("candidateId 与盲检输入不一致")
unexpected = sorted(
set(report) - {"protocol", "candidateId", "findings", "coverageFindings"}
)
if unexpected:
errors.append(f"detector 报告包含未登记字段: {','.join(unexpected)}")
findings = report.get("findings")
coverage_findings = report.get("coverageFindings")
if not isinstance(findings, list):
errors.append("findings 必须是数组")
findings = []
if not isinstance(coverage_findings, list):
errors.append("coverageFindings 必须是数组")
coverage_findings = []
sections = (
("findings", findings, ALLOWED_FINDING_CATEGORIES),
("coverageFindings", coverage_findings, ALLOWED_COVERAGE_CATEGORIES),
)
for section, items, allowed_categories in sections:
for index, finding in enumerate(items):
if not isinstance(finding, Mapping):
errors.append(f"{section}[{index}] 必须是对象")
continue
allowed_fields = FINDING_FIELDS if section == "findings" else COVERAGE_FINDING_FIELDS
unexpected_fields = sorted(set(finding) - allowed_fields)
if unexpected_fields:
errors.append(
f"{section}[{index}] 包含未登记字段: {','.join(unexpected_fields)}"
)
category = finding.get("category")
if not isinstance(category, str) or category not in allowed_categories:
errors.append(f"{section}[{index}].category 未登记")
if section == "findings":
severity = finding.get("severity")
if not isinstance(severity, str) or severity not in ALLOWED_SEVERITIES:
errors.append(f"findings[{index}].severity 无效")
for field in ("category", "location", "evidenceSummary"):
value = finding.get(field)
if not isinstance(value, str) or not value.strip():
errors.append(f"findings[{index}].{field} 必须是非空字符串")
else:
summary = finding.get("summary")
if not isinstance(summary, str) or not summary.strip():
errors.append(f"coverageFindings[{index}].summary 必须是非空字符串")
high_count = sum(
1
for finding in findings
if isinstance(finding, Mapping) and finding.get("severity") == "high"
)
return {
"ok": not errors,
"errors": errors,
"findingCount": len(findings),
"coverageFindingCount": len(coverage_findings),
"highSeverityCount": high_count,
}