package-product-review-intake.py 7.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """Package the verified review sources and a concrete publication handoff."""
  2. import hashlib
  3. import json
  4. from pathlib import Path
  5. import zipfile
  6. ROOT = Path(__file__).resolve().parents[1]
  7. WORK = ROOT / 'work/product-reviews/combined-batch-r1'
  8. OUT = ROOT / 'artifacts/高评价量商品补评-20261106-r1'
  9. DOC = ROOT / 'docs/industry-product-reviews-20261106'
  10. def sha(raw):
  11. return hashlib.sha256(raw).hexdigest()
  12. def main():
  13. OUT.mkdir(parents=True, exist_ok=True)
  14. DOC.mkdir(parents=True, exist_ok=True)
  15. archive = OUT / 'ksf-product-review-intake-20261106-r1.zip'
  16. if archive.exists():
  17. raise ValueError('RELEASE_ALREADY_EXISTS')
  18. report = json.loads((WORK / 'verification.json').read_text(encoding='utf-8'))
  19. rebuild = json.loads((WORK / 'rebuild-verification.json').read_text(encoding='utf-8'))
  20. assert report['selectedReviews'] == 104 and report['selectedProducts'] == 10
  21. assert rebuild['rebuiltReviewsMatch'] == 104 and not report['productionImported']
  22. wire = (WORK / 'channel-source.zip').read_bytes()
  23. assert sha(wire) == report['sourceArchiveSha256']
  24. instructions = '''# 高评价量商品补评:采集已完成,待生产入库
  25. 本包为真实来源数据,不是新的采集任务。Codex直接执行了7次评论请求(5次成功、2次失败,未自动重试),按返回样本筛选55条,并恢复50条历史原评;去掉1条重叠ID后,共104条、10件商品。当前生产仍有2380条评价,本包尚未发布。
  26. ## 已核结果
  27. - 生产商品4674件,其中44件有收录评价,4630件未收录。零收录不能推断平台零评论。
  28. - 已核实新增费用1.50元,失败请求仍保留0.60元未决预留;旧50元任务账本保持原口径。本交接不需再采集或新增费用。
  29. - 本轮成功商品:京东康师傅速达面馆(返回20万+);京东白象大辣娇(本轮返回50万+,与历史300万+分开保留);天猫康师傅一倍半(本轮9000+);天猫统一老坛酸菜(3万+)。返回总量是平台展示口径,京东仅开放maxPage=2,不能据此称完整收录几十万条。
  30. - 新采样本每商品最多选20条,按实际返回的点赞数降序选取。3条有赞记录各1赞,均来自天猫统一;不称平台全量高赞或爆款评价。点赞数在来源JSON里保留,现有reviews表没有点赞列。
  31. - 历史149条候选中,排除91条模板内容,再排除8条非模板但请求/返回商品ID不匹配的记录,恢复50条。新采中的错商品记录同样排除。
  32. - 104条均缺少上游明确默认状态和完整量表,保留未知;不得为进入分析而填false或造五星量表。发布后可在“全部评价(含待确认)”回读,不应冒称全部满足“推荐用于分析”。
  33. ## 包与原件
  34. `intake/channel-source.zip`是既有library_channel.pack生成的真实来源包,内含batch.json、原件、JSON Pointer、文件SHA、工具回执及媒体原件;不含数据库或凭据。解压到新的私有目录,不能覆盖旧批次。
  35. 来源包SHA256:SOURCE_SHA
  36. evidence/verification.json有10件商品逐件数量、来源口径及本轮回执;rebuild-verification.json证明从传输包重新构建后104条逐条一致;collection-audit.json保留本轮请求/成功/失败及费用汇总(不含共享余额或凭据)。
  37. ## 需要完成的事
  38. 1. 沿用之前真实使用的生产资料库受限发布通道。当前Codex Windows工作区未绑定KSF_LIBRARY_CHANNEL,实际发布检查报CHANNEL_NOT_CONFIGURED;F盘的Parse配置不能直接写这套SQLite资料库。请确认你所在实例的现有通道可用,或由运维为当前工作区接通既有受限通道,不用重采。
  39. 2. 先核当前生产generation和这10件商品的评论情况。准备时generation为EXPECTED_GENERATION。若发生并发更新,重新核当前上下文和合并计划,不盲目重放或覆盖当前数据。
  40. 3. 用已安装的ksf-voc-library Skill,从真实来源预检并新建暂存;按既有library_channel.py执行publish dry,核新增/重复/保留/冲突,再按原用户入库授权apply一次。保留原件和旧代际。不要覆盖当前SQLite。
  41. 4. 同批products只是必须的现有商品上下文,不是新商品采集。构建器还会从标题生成10条待确认规格;先核dry是否为已有重复或新增候选,不能替换已验证规格、店铺/品牌/品类或现有合法更新;有冲突回报实际mergePlan。
  42. 5. apply若超时,用同一来源包SHA查status,不重发。完成后回读新代际、104条ID、商品关联、来源及看板“全部评价”,分别报告净新增数、重复数、保留/冲突、实际展示和仍待确认的字段。
  43. 示例命令(脚本目录与通道采用目标实例已有路径;先核Skill与真实合同):
  44. ```sh
  45. python3 -B scripts/agent_batch.py --batch /本批/batch.json --output /本批/new-staging.sqlite
  46. python3 -B scripts/agent_batch.py --batch /本批/batch.json --output /本批/new-staging.sqlite --apply
  47. python3 -B scripts/library_channel.py publish --batch /本批/batch.json --expected-generation <实际当前代际>
  48. python3 -B scripts/library_channel.py publish --batch /本批/batch.json --expected-generation <核过dry的同一代际> --apply
  49. python3 -B scripts/library_channel.py status --archive-sha256 SOURCE_SHA
  50. ```
  51. 只有生产发布和回读成功后,才能说这批评论已经进入看板。当前状态:prepared-not-published。
  52. '''.replace('SOURCE_SHA', report['sourceArchiveSha256']).replace('EXPECTED_GENERATION', report['expectedProductionGeneration'])
  53. (DOC / 'README.md').write_text(instructions, encoding='utf-8')
  54. billing = json.loads((ROOT / 'work/product-reviews/live-r1/collection-audit.json').read_text(encoding='utf-8'))
  55. safe_billing = {**billing, 'records': [{k: v for k, v in r.items() if k != 'records'} for r in billing['records']]}
  56. files = {'交接说明.md': instructions.encode(), 'intake/channel-source.zip': wire,
  57. 'evidence/verification.json': (WORK / 'verification.json').read_bytes(),
  58. 'evidence/rebuild-verification.json': (WORK / 'rebuild-verification.json').read_bytes(),
  59. 'evidence/collection-audit.json': (json.dumps(safe_billing, ensure_ascii=False, indent=2) + '\n').encode(),
  60. 'evidence/coverage-audit.json': (ROOT / 'work/product-reviews/audit-r1/coverage-audit.json').read_bytes()}
  61. for name in ['audit-product-reviews.py', 'build-product-review-intake.py', 'summarize-product-review-samples.py']:
  62. files['reproduction/' + name] = (ROOT / 'scripts' / name).read_bytes()
  63. files['FILES.sha256'] = ''.join(sha(raw) + ' ' + name + '\n' for name, raw in sorted(files.items())).encode()
  64. with zipfile.ZipFile(archive, 'x', zipfile.ZIP_DEFLATED, compresslevel=9) as z:
  65. for name, raw in files.items():
  66. z.writestr(name, raw)
  67. with zipfile.ZipFile(archive) as z:
  68. assert z.testzip() is None
  69. for line in z.read('FILES.sha256').decode().splitlines():
  70. h, name = line.split(' ', 1)
  71. assert sha(z.read(name)) == h
  72. receipt = {'ok': True, 'file': str(archive), 'sha256': sha(archive.read_bytes()),
  73. 'bytes': archive.stat().st_size, 'filesVerified': len(files) - 1,
  74. 'selectedProducts': 10, 'selectedReviews': 104, 'productionImported': False,
  75. 'confirmedNewCostCny': 1.50, 'unsettledNewReservationCny': 0.60}
  76. (DOC / 'delivery-receipt.json').write_text(json.dumps(receipt, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
  77. print(json.dumps(receipt, ensure_ascii=False, indent=2))
  78. if __name__ == '__main__':
  79. main()