This commit is contained in:
zyp
2026-11-27 14:43:37 +08:00
parent 1ae94dfb1f
commit b18c6efe92
64 changed files with 5629 additions and 2414 deletions
@@ -72,6 +72,78 @@ def draft_signature(result):
return hashlib.sha256(json.dumps(content, ensure_ascii=False, sort_keys=True).encode()).hexdigest()
_HARD_CONDITIONS = (
(re.compile(r'[,,]?\s*(?:落实|符合|满足|达到|通过|确保符合)[^,,。;!?\n]{0,16}(?:等级保护|等保)[^,,。;!?\n]*'),
re.compile(r'等级保护|等保')),
(re.compile(r'[,,]?\s*(?:确保|保证|承诺)[^,,。;!?\n]{0,10}(?:无后门|无(?:高危)?漏洞|零(?:故障|缺陷|漏洞))[^,,。;!?\n]*'),
re.compile(r'无后门|无(?:高危)?漏洞|零(?:故障|缺陷|漏洞)')),
)
def _ground_hard_conditions(text, source):
for condition, support in _HARD_CONDITIONS:
if not support.search(source):
text = condition.sub('', text)
return re.sub(r'(^|[。;!?])(?:[,,。;!?]+)', r'\1', text).strip()
def guard_generated_draft(request, result, invoke, deadline):
"""Remove continued text and unsupported hard conditions before saving a segment."""
previous = request.workbench.get('previous', '')
seen = {re.sub(r'\s+', '', paragraph) for paragraph in previous.splitlines()}
relevant = '\n'.join(row.text for row in request.requirements)
paragraphs = []
for paragraph in result['paragraphs']:
cleaned = _ground_hard_conditions(paragraph, relevant)
key = re.sub(r'\s+', '', cleaned)
if key and key not in seen:
paragraphs.append(cleaned)
seen.add(key)
if not paragraphs:
raise ValueError('本段重复已写内容,需要只补写当前分段的要求')
# A sentence is the smallest safe edit. A model can identify a sentence,
# but cannot introduce new wording during this check.
groups = [re.findall(r'[^。!?;\n]+[。!?;]?|[。!?;\n]+', para) for para in paragraphs]
excerpts = [sentence for group in groups for sentence in group]
schema = {'type': 'object', 'properties': {
'remove': {'type': 'array', 'items': {'type': 'integer', 'enum': list(range(len(excerpts)))},
'maxItems': len(excerpts)}}, 'required': ['remove'], 'additionalProperties': False}
raw, commit = _review_response(
'workspace_generation_conditions', invoke,
COMMON + '\n审查拟发布的本章正文。只选择需要删除的句子编号,不改写也不新增句子。'
'requirements是本章的要求和评分依据,source是补充上下文,不能把其他章节独立条件挪过来。'
'删掉缺少依据却写成必须或默认的签字主体、审批链、验收门槛、交付材料、固定工期/频次/数量、企业资质和类似硬性约束。'
'无原文明确依据的等级认证、零缺陷、交付无漏洞、指定技术产品或设施的硬性配置亦须删除。'
'主体、对象、触发条件要在同一条实际要求中成立,不能把变更须三方确认套给验收。'
'原文要求的硬条件、明确标为拟采用且不增加采购方义务的操作方法、实际有依据的证明应保留。'
'同时删掉针对用户或生成过程的说明、与本章无关的报价/违约/证书/合同段、只有口号的开头结尾,以及重述previous的句子。'
'有实质新措施的句子保留。只选确定不合格的编号;无问题返回空数组。',
{'chapter': request.workbench['title'], 'project': request.project,
'requirements': [row.model_dump() for row in request.requirements],
'source': [block.text for block in request.blocks],
'company': [block.text for block in request.company],
'previous': previous,
'sentences': [{'id': i, 'text': line} for i, line in enumerate(excerpts)]},
schema, deadline, max_tokens=900)
remove = raw.get('remove')
if (set(raw) != {'remove'} or not isinstance(remove, list)
or any(type(i) is not int or not 0 <= i < len(excerpts) for i in remove)):
raise ValueError('新增要求检查返回无效正文位置')
removed = set(remove)
accepted = []
offset = 0
for group in groups:
text = ''.join(line for index, line in enumerate(group, start=offset) if index not in removed).strip()
if text and text.strip('。!?;'):
accepted.append(text)
offset += len(group)
if not accepted:
raise ValueError('本段缺少符合原文的新增正文,请按当前要求重新编写')
commit()
result['paragraphs'] = accepted
def _visible_material_gap(required, explanation, actual, materials):
"""A visible, named placeholder satisfies a draft, not final delivery."""
if not re.search(r'待补|待核实|待确认|尚未提供', actual):