weaver-work-cli 0.1.49 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{attachment-content-MU2LPI5P.js → attachment-content-MBYYSQIX.js} +3 -3
  3. package/dist/chunks/{chunk-ZKEUGS2U.js → chunk-7UOXOGFL.js} +4 -4
  4. package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
  5. package/dist/chunks/{chunk-3NV2ETZR.js → chunk-D3TDNRFE.js} +8 -8
  6. package/dist/chunks/{chunk-6GWU63YF.js → chunk-DZOC77ZD.js} +1 -1
  7. package/dist/chunks/{chunk-K3BT54CU.js → chunk-IRMA3GVP.js} +1 -1
  8. package/dist/chunks/{chunk-3X7VOSBA.js → chunk-KLZ3ULQQ.js} +1 -1
  9. package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
  10. package/dist/chunks/{chunk-NBEWUR7L.js → chunk-LALWNK6M.js} +167 -44
  11. package/dist/chunks/{chunk-BRRW7CWA.js → chunk-LM2H7SZI.js} +26 -26
  12. package/dist/chunks/{chunk-KV5SOWMS.js → chunk-LTRLF6MM.js} +4 -4
  13. package/dist/chunks/{chunk-D2QRZUW4.js → chunk-RPRFIG6I.js} +35 -28
  14. package/dist/chunks/{chunk-GEOMANP7.js → chunk-RWFRZSIP.js} +2 -2
  15. package/dist/chunks/{chunk-EJVA5ZVB.js → chunk-ZRHKGQRQ.js} +2 -2
  16. package/dist/chunks/{conflict-6347A7YK.js → conflict-D2HYKBMH.js} +2 -2
  17. package/dist/chunks/{contract-N6P2HIIE.js → contract-MFOFMM2J.js} +4284 -254
  18. package/dist/chunks/{create-flow-7WG7LVX5.js → create-flow-7ZATJVTM.js} +6 -6
  19. package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
  20. package/dist/chunks/{env-LHRKSLG6.js → env-5DO4YENS.js} +2 -2
  21. package/dist/chunks/{factory-2H7Z4RWJ.js → factory-3M7D7WJC.js} +1 -1
  22. package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
  23. package/dist/chunks/{group-chat-EW6PNDDT.js → group-chat-B2HT5NEO.js} +3 -3
  24. package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
  25. package/dist/chunks/{invoice-FXWH5GPO.js → invoice-V7ZTITUO.js} +726 -206
  26. package/dist/chunks/{meeting-N2FQBHXI.js → meeting-HZOX3CBB.js} +10 -10
  27. package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
  28. package/dist/chunks/{reception-MYOKJULO.js → reception-QGPNTGHG.js} +98 -82
  29. package/dist/chunks/{recruit-stage-FKWS5UQF.js → recruit-stage-XCMVEQA2.js} +718 -131
  30. package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
  31. package/dist/chunks/{registry-7VZ6YJUF.js → registry-KYPFFQIH.js} +1 -1
  32. package/dist/chunks/{registry-CKUVBS53.js → registry-SJHSBO5G.js} +10 -10
  33. package/dist/chunks/{room-recommend-MBCYENQ2.js → room-recommend-5AHR4YQV.js} +4 -4
  34. package/dist/chunks/{schedule-5IFMCXME.js → schedule-KZPJUPC2.js} +4 -4
  35. package/dist/chunks/smart-extract-IXHCZE4R.js +2846 -0
  36. package/dist/chunks/{workflow-2TRU2ZSP.js → workflow-UHKCZJMY.js} +1 -1
  37. package/dist/index.js +14 -9
  38. package/dist/shortcuts/contract/host.js +11 -0
  39. package/dist/shortcuts/contract/index.js +13 -0
  40. package/dist/shortcuts/contract/manifest.js +204 -0
  41. package/dist/shortcuts/contract/operations/card-action.js +585 -0
  42. package/dist/shortcuts/contract/operations/card-ebdf-list.js +315 -0
  43. package/dist/shortcuts/contract/operations/card-plan.js +327 -0
  44. package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
  45. package/dist/shortcuts/contract/operations/elements-build.js +714 -0
  46. package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
  47. package/dist/shortcuts/contract/operations/first-screen.js +563 -0
  48. package/dist/shortcuts/contract/operations/flow.js +81 -25
  49. package/dist/shortcuts/contract/operations/modeltext.js +132 -0
  50. package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
  51. package/dist/shortcuts/contract/operations/performance.js +58 -7
  52. package/dist/shortcuts/contract/operations/quote.js +410 -22
  53. package/dist/shortcuts/contract/operations/registry.js +22 -0
  54. package/dist/shortcuts/contract/operations/review.js +73 -58
  55. package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
  56. package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
  57. package/dist/shortcuts/contract/operations/summary.js +4 -2
  58. package/dist/shortcuts/contract/operations/upload.js +48 -7
  59. package/dist/shortcuts/contract/prewarm-cache.js +90 -0
  60. package/dist/shortcuts/contract/prewarm.js +88 -0
  61. package/dist/shortcuts/contract/upload-cache.js +49 -4
  62. package/dist/shortcuts/data/index.js +1 -6
  63. package/dist/shortcuts/data/manifest.js +2 -2
  64. package/dist/shortcuts/data/operations/index.js +1 -1
  65. package/dist/shortcuts/data/operations/query.js +23 -46
  66. package/dist/shortcuts/fna/host.js +4 -2
  67. package/dist/shortcuts/fna/manifest.js +14 -5
  68. package/dist/shortcuts/fna/operations/audit.js +334 -0
  69. package/dist/shortcuts/fna/operations/registry.js +2 -0
  70. package/dist/shortcuts/im/operations/at-mention.js +6 -3
  71. package/dist/shortcuts/im/operations/msg-parse.js +35 -5
  72. package/dist/shortcuts/im/operations/msg-sync.js +3 -1
  73. package/dist/shortcuts/im/operations/msg-write.js +57 -9
  74. package/dist/shortcuts/index.js +5 -0
  75. package/dist/shortcuts/invoice/index.js +0 -12
  76. package/dist/shortcuts/invoice/manifest.js +201 -50
  77. package/dist/shortcuts/invoice/operations/registry.js +4 -2
  78. package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
  79. package/dist/shortcuts/invoice/operations/shared.js +3 -19
  80. package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
  81. package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
  82. package/dist/shortcuts/reception/constants.js +3 -7
  83. package/dist/shortcuts/reception/operations/leads.js +30 -6
  84. package/dist/shortcuts/reception/operations/panels.js +3 -2
  85. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
  86. package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
  87. package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
  88. package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
  89. package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
  90. package/dist/shortcuts/recruit-stage/shared.js +5 -0
  91. package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
  92. package/dist/shortcuts/smart-extract/constants.js +79 -0
  93. package/dist/shortcuts/smart-extract/continuation.js +71 -0
  94. package/dist/shortcuts/smart-extract/errors.js +68 -0
  95. package/dist/shortcuts/smart-extract/host.js +191 -0
  96. package/dist/shortcuts/smart-extract/index.js +105 -0
  97. package/dist/shortcuts/smart-extract/ledger.js +70 -0
  98. package/dist/shortcuts/smart-extract/manifest.js +35 -0
  99. package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
  100. package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
  101. package/dist/shortcuts/smart-extract/operations/config.js +118 -0
  102. package/dist/shortcuts/smart-extract/operations/fill.js +489 -0
  103. package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
  104. package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
  105. package/dist/shortcuts/smart-extract/operations/save.js +355 -0
  106. package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
  107. package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
  108. package/dist/shortcuts/smart-extract/operations/target.js +167 -0
  109. package/dist/shortcuts/smart-extract/operations/types.js +22 -0
  110. package/dist/shortcuts/smart-extract/operations/validate.js +408 -0
  111. package/dist/shortcuts/workflow/operations/read.js +77 -15
  112. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +140 -24
  113. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +42 -14
  114. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +4 -6
  115. package/docs/SKILL.md +1 -1
  116. package/docs/_catalog.md +4 -1
  117. package/docs/agent-invoice.md +5 -7
  118. package/docs/data.md +5 -1
  119. package/docs/fna.md +24 -4
  120. package/docs/invoice.md +7 -5
  121. package/docs/smart-extract.md +156 -0
  122. package/package.json +1 -1
  123. package/skill-template/business-info.json +21 -1
  124. package/skill-template/domains/qiyecheng.md +6 -2
  125. package/skill-template/domains/smart-extract.md +16 -0
  126. package/skill-template/domains/yepiaotong.md +2 -2
  127. package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
  128. package/skills/weaver-e10-jinchengda/SKILL.md +159 -11
  129. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +13 -8
  130. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +5 -4
  131. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +44 -2
  132. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
  133. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +220 -0
  134. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +68 -33
  135. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +26 -15
  136. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  137. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
  138. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +90 -0
  139. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
  140. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +167 -5
  141. package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +200 -0
  142. package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +572 -0
  143. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
  144. package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +560 -0
  145. package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +894 -0
  146. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +93 -0
  147. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
  148. package/skills/weaver-e10-qiyecheng/SKILL.md +58 -7
  149. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +118 -0
  150. package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
  151. package/skills/weaver-e10-qiyecheng/references/catalog.md +42 -3
  152. package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
  153. package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
  154. package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
  155. package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
  156. package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
  157. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +153 -40
  158. package/skills/weaver-e10-reception-flow/SKILL.md +43 -6
  159. package/skills/weaver-e10-reception-flow/references/guide.md +1 -1
  160. package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
  161. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
  162. package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
  163. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
  164. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
  165. package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
  166. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
  167. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  168. package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
  169. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -40
  170. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
  171. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
  172. package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
  173. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
  174. package/skills/weaver-e10-smart-extract/SKILL.md +169 -0
  175. package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
  176. package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
  177. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +105 -0
  178. package/skills/weaver-e10-workflow/SKILL.md +2 -1
  179. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +29 -6
  180. package/skills/weaver-e10-workflow/references/workflow-query.md +1 -1
  181. package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
  182. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
  183. package/skills/weaver-e10-yepiaotong/SKILL.md +53 -35
  184. package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
  185. package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
  186. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
  187. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
  188. package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
  189. package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
  190. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +18 -53
  191. package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
  192. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +96 -7
  193. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +5 -38
  194. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +14 -14
  195. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
  196. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +139 -94
  197. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +131 -58
  198. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
  199. package/skills/weaver-e10-yimiaoban/SKILL.md +8 -6
  200. package/skills/weaver-e10-yimiaoban/references/msg-read.md +20 -0
  201. package/skills/weaver-e10-yimiaoban/references/msg-write.md +7 -0
  202. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +18 -15
  203. package/dist/shortcuts/invoice/operations/validate-preview.js +0 -40
  204. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
  205. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
  206. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
  207. package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +0 -40
@@ -0,0 +1,565 @@
1
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { contractValidationError } from '../errors.js';
4
+ /**
5
+ * 合同风险审查报告渲染器(本地,零依赖)。
6
+ *
7
+ * 迁移自 `scripts/render_risk_report.py`(2026-11-12 第二批)。
8
+ *
9
+ * 约定不变:
10
+ * - 输出 HTML 内**不得出现双引号**(放进 customParams.html 会被截断);
11
+ * - 统计只保留三项:审查规则总数 / 判定无风险 / 判定有风险;
12
+ * - 「查看审查详情」按钮通过 rightPanel.open 打开 AIContractV2 审查组件。
13
+ *
14
+ * 模板内嵌在源码中:CLI 以 npm 包装安装后 `dist/` 与 `skills/` 相对位置不稳定,
15
+ * 依赖外部模板文件会在打包场景下静默失效。显式传 `template` 才读外部文件。
16
+ */
17
+ const DEFAULT_AIID = '1326842382967570463';
18
+ const DEFAULT_SRC_PATH = '/sp/contract/business/ai-contract';
19
+ const DEFAULT_BASE = 'https://www.e-cology.com.cn';
20
+ const DEFAULT_TEMPLATE = `<section id='{{CARD_ID}}' style='padding:16px 18px;font-family:sans-serif;background:#fafbfd;border-radius:12px'>
21
+
22
+ <div style='display:flex;align-items:center;justify-content:space-between;margin-bottom:16px'>
23
+ <div>
24
+ <div style='font-size:17px;font-weight:700;color:#1f2430'>合同风险审查报告</div>
25
+ <div style='font-size:12px;color:#7a8497;margin-top:4px'>{{CONTRACT_NAME}}</div>
26
+ </div>
27
+ <div style='flex:0 0 auto;display:flex;align-items:center;gap:8px'>
28
+ <button type='button' data-act='download' style='background:#fff;color:#1d6fd8;border:1px solid #1d6fd8;border-radius:8px;padding:8px 16px;font-size:13px;font-weight:600;cursor:pointer;font-family:inherit'>下载报告</button>
29
+ <button type='button' data-act='detail' style='background:#1d6fd8;color:#fff;border:none;border-radius:8px;padding:9px 18px;font-size:13px;font-weight:600;cursor:pointer;font-family:inherit'>查看审查详情</button>
30
+ </div>
31
+ </div>
32
+
33
+ <div style='background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;margin-bottom:14px'>
34
+ <div style='font-size:14px;font-weight:700;color:#1f2430;margin-bottom:12px'>审查基本信息</div>
35
+ <table style='border-collapse:collapse;width:100%;font-size:13px'>{{TINFO}}</table>
36
+ </div>
37
+
38
+ <div style='font-size:14px;font-weight:700;color:#1f2430;margin:0 0 10px 2px'>审查统计</div>
39
+ <div style='display:flex;gap:12px;margin-bottom:18px;flex-wrap:wrap'>
40
+ <div style='flex:1;min-width:130px;background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;text-align:center'>
41
+ <div style='font-size:26px;font-weight:700;color:#1f2430'>{{STAT_TOTAL}}</div>
42
+ <div style='font-size:12px;color:#7a8497;margin-top:4px'>审查规则总数</div>
43
+ </div>
44
+ <div style='flex:1;min-width:130px;background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;text-align:center'>
45
+ <div style='font-size:26px;font-weight:700;color:#1a9c5b'>{{STAT_NO_RISK}}</div>
46
+ <div style='font-size:12px;color:#7a8497;margin-top:4px'>判定无风险</div>
47
+ </div>
48
+ <div style='flex:1;min-width:130px;background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;text-align:center'>
49
+ <div style='font-size:26px;font-weight:700;color:#c0392b'>{{STAT_RISK}}</div>
50
+ <div style='font-size:12px;color:#7a8497;margin-top:4px'>判定有风险</div>
51
+ </div>
52
+ </div>
53
+
54
+ <div style='font-size:14px;font-weight:700;color:#1f2430;margin:18px 0 10px 2px'>风险详情({{RISK_COUNT}} 条)</div>
55
+ {{RISK_ITEMS}}
56
+
57
+ <div style='background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;margin-top:6px'>
58
+ <div style='font-size:14px;font-weight:700;color:#1f2430;margin-bottom:4px'>审查通过({{PASS_COUNT}} 条)</div>
59
+ <div style='font-size:12px;color:#7a8497;margin-bottom:12px'>以下规则已执行判定,未发现与规则冲突的条款</div>
60
+ {{PASS_TAGS}}
61
+ </div>
62
+
63
+ <p data-status style='margin:10px 0 0;color:#b45309;font-size:12px'></p>
64
+ </section>
65
+ <script>
66
+ (function () {
67
+ var CARD_ID = '{{CARD_ID}}';
68
+ var FILE_BASE = '{{FILE_BASE}}';
69
+
70
+ function getRoot() {
71
+ var el = null;
72
+ var sc = document.currentScript;
73
+ if (sc && sc.previousElementSibling && sc.previousElementSibling.id === CARD_ID) {
74
+ el = sc.previousElementSibling;
75
+ }
76
+ if (!el) { el = document.getElementById(CARD_ID); }
77
+ if (!el && document.querySelector) { el = document.querySelector('#' + CARD_ID); }
78
+ return el;
79
+ }
80
+
81
+ var root = getRoot();
82
+ if (!root) { return; }
83
+
84
+ var statusEl = root.querySelector('[data-status]');
85
+ function say(m) { if (statusEl) { statusEl.textContent = m; } }
86
+
87
+ function getPlugin() {
88
+ if (window.xiaoePlugin) { return window.xiaoePlugin; }
89
+ if (window.rawWindow && window.rawWindow.xiaoePlugin) { return window.rawWindow.xiaoePlugin; }
90
+ return null;
91
+ }
92
+
93
+ var DETAIL_CFG = {{DETAIL_CFG}};
94
+
95
+ function openDetail() {
96
+ var plugin = getPlugin();
97
+ if (!plugin || !plugin.rightPanel || typeof plugin.rightPanel.open !== 'function') {
98
+ say('当前环境不支持打开右侧面板,请在小e客户端内查看');
99
+ return;
100
+ }
101
+ say('正在打开审查详情…');
102
+ try {
103
+ plugin.rightPanel.open(DETAIL_CFG);
104
+ say('');
105
+ } catch (err) {
106
+ say('审查详情打开失败,请确认右侧面板已挂载');
107
+ }
108
+ }
109
+
110
+ // 导出前先克隆,去掉脚本、按钮与提示位,得到干净的静态报告
111
+ function cleanClone() {
112
+ var clone = root.cloneNode(true);
113
+ var nodes = clone.querySelectorAll('script, [data-act], [data-status]');
114
+ var i;
115
+ for (i = nodes.length - 1; i >= 0; i--) {
116
+ if (nodes[i].parentNode) { nodes[i].parentNode.removeChild(nodes[i]); }
117
+ }
118
+ return clone;
119
+ }
120
+
121
+ function downloadReport() {
122
+ var doc = root.ownerDocument || document;
123
+ var clone = cleanClone();
124
+ var html = '<!DOCTYPE html><html><head><meta charset=\\'utf-8\\'>'
125
+ + '<title>' + FILE_BASE + '</title>'
126
+ + '<style>body{margin:0;padding:16px;background:#fafbfd;font-family:sans-serif}'
127
+ + '@media print{body{background:#fff}}</style></head><body>'
128
+ + clone.outerHTML + '</body></html>';
129
+
130
+ if (!window.Blob || !window.URL || typeof window.URL.createObjectURL !== 'function') {
131
+ say('当前环境不支持文件下载,请在小e客户端内使用');
132
+ return;
133
+ }
134
+
135
+ var url;
136
+ try {
137
+ url = window.URL.createObjectURL(new Blob([html], { type: 'text/html;charset=utf-8' }));
138
+ } catch (err) {
139
+ say('报告生成失败,请稍后重试');
140
+ return;
141
+ }
142
+
143
+ var a = doc.createElement('a');
144
+ a.href = url;
145
+ a.download = FILE_BASE + '.html';
146
+ a.style.display = 'none';
147
+ if (doc.body && doc.body.appendChild) { doc.body.appendChild(a); }
148
+ a.click();
149
+ if (a.parentNode) { a.parentNode.removeChild(a); }
150
+ setTimeout(function () { window.URL.revokeObjectURL(url); }, 1500);
151
+ say('报告已开始下载:' + FILE_BASE + '.html');
152
+ }
153
+
154
+ // 事件委托:绑定在报告根节点上,避免子元素取不到导致点击无响应
155
+ root.addEventListener('click', function (e) {
156
+ var t = e.target;
157
+ var act = null;
158
+ while (t && t !== root) {
159
+ if (t.getAttribute) {
160
+ act = t.getAttribute('data-act');
161
+ if (act) { break; }
162
+ }
163
+ t = t.parentNode;
164
+ }
165
+ if (act === 'detail') { openDetail(); return; }
166
+ if (act === 'download') { downloadReport(); return; }
167
+ });
168
+
169
+ root.addEventListener('mouseover', function (e) {
170
+ var t = e.target;
171
+ var act = null;
172
+ while (t && t !== root) {
173
+ if (t.getAttribute) {
174
+ act = t.getAttribute('data-act');
175
+ if (act) { break; }
176
+ }
177
+ t = t.parentNode;
178
+ }
179
+ if (act === 'detail') { t.style.background = '#1659b8'; }
180
+ if (act === 'download') { t.style.background = '#eef4fd'; }
181
+ });
182
+
183
+ root.addEventListener('mouseout', function (e) {
184
+ var t = e.target;
185
+ var act = null;
186
+ while (t && t !== root) {
187
+ if (t.getAttribute) {
188
+ act = t.getAttribute('data-act');
189
+ if (act) { break; }
190
+ }
191
+ t = t.parentNode;
192
+ }
193
+ if (act === 'detail') { t.style.background = '#1d6fd8'; }
194
+ if (act === 'download') { t.style.background = '#fff'; }
195
+ });
196
+ })();
197
+ </script>
198
+ `;
199
+ // ---------------------------------------------------------------- 工具
200
+ /** Python `str(x or '')`。 */
201
+ function truthyText(value) {
202
+ if (value === null || value === undefined || value === false || value === '' || value === 0)
203
+ return '';
204
+ return String(value);
205
+ }
206
+ /**
207
+ * 等价 Python `html.escape(s, quote=True)` 后再把 `&quot;` 换成 `&apos;`。
208
+ * 顺序必须一致:& 先转,避免二次转义。
209
+ */
210
+ function esc(value) {
211
+ const text = truthyText(value);
212
+ return text
213
+ .replace(/&/gu, '&amp;')
214
+ .replace(/</gu, '&lt;')
215
+ .replace(/>/gu, '&gt;')
216
+ .replace(/"/gu, '&apos;')
217
+ .replace(/'/gu, '&#x27;');
218
+ }
219
+ function readJson(path) {
220
+ const raw = readFileSync(path, 'utf8').replace(/^\uFEFF/u, '');
221
+ const parsed = JSON.parse(raw);
222
+ if (!parsed || typeof parsed !== 'object')
223
+ throw new Error('JSON 根节点不是对象');
224
+ return parsed;
225
+ }
226
+ function isFile(path) {
227
+ try {
228
+ return existsSync(path) && statSync(path).isFile();
229
+ }
230
+ catch {
231
+ return false;
232
+ }
233
+ }
234
+ /** 从规则 title 中取【规则名称】那一行;取不到则回退首行前 60 字。 */
235
+ function ruleName(title) {
236
+ const text = truthyText(title);
237
+ for (const line of text.split('\n')) {
238
+ if (line.includes('规则名称')) {
239
+ return line.split('【规则名称】').join('').trim();
240
+ }
241
+ }
242
+ return text.split('\n')[0].slice(0, 60);
243
+ }
244
+ /** 转成可安全用于下载文件名的字符串(去掉路径非法字符与单引号)。 */
245
+ function safeName(value, fallback = '合同风险审查报告') {
246
+ const base = truthyText(value).trim() || fallback;
247
+ let out = base;
248
+ for (const bad of ['\\', '/', ':', '*', '?', '"', '<', '>', '|', "'", '\r', '\n']) {
249
+ out = out.split(bad).join('_');
250
+ }
251
+ return out.slice(0, 80);
252
+ }
253
+ /** 从 CLI 落盘结果(含 envelope 包裹)抽取报告数据。 */
254
+ export function extractFromRef(path) {
255
+ const top = readJson(path);
256
+ const env = (top.envelope && typeof top.envelope === 'object') ? top.envelope : top;
257
+ const data = (env.data && typeof env.data === 'object') ? env.data : {};
258
+ const records = Array.isArray(data.records) ? data.records : [];
259
+ if (!records.length) {
260
+ throw contractValidationError('records_empty', '该结果没有审查记录,无法生成报告(status 可能为 EMPTY)');
261
+ }
262
+ const scnr = records[0].scnr;
263
+ let obj;
264
+ if (typeof scnr === 'string') {
265
+ try {
266
+ obj = JSON.parse(scnr);
267
+ }
268
+ catch (error) {
269
+ const message = error instanceof Error ? error.message : String(error);
270
+ throw contractValidationError('scnr_invalid', `审查记录 scnr 不是合法 JSON:${message}`);
271
+ }
272
+ }
273
+ else if (scnr && typeof scnr === 'object') {
274
+ obj = scnr;
275
+ }
276
+ else {
277
+ obj = {};
278
+ }
279
+ let roleKey = obj.entryRole || 'partyB';
280
+ const byRole = (obj.resultsByRole && typeof obj.resultsByRole === 'object')
281
+ ? obj.resultsByRole
282
+ : {};
283
+ let items = Array.isArray(byRole[roleKey]) ? byRole[roleKey] : [];
284
+ if (!items.length) {
285
+ // 立场键兜底
286
+ for (const [key, value] of Object.entries(byRole)) {
287
+ if (Array.isArray(value) && value.length) {
288
+ roleKey = key;
289
+ items = value;
290
+ break;
291
+ }
292
+ }
293
+ }
294
+ const rules = (obj.rules && typeof obj.rules === 'object') ? obj.rules : {};
295
+ const selected = Array.isArray(rules.selected) ? rules.selected : [];
296
+ const risks = [];
297
+ const passed = [];
298
+ for (const item of items) {
299
+ if (!item || typeof item !== 'object')
300
+ continue;
301
+ const record = item;
302
+ const name = ruleName(record.title);
303
+ if (record.customRuleNoRisk === true) {
304
+ passed.push({ name });
305
+ }
306
+ else {
307
+ risks.push({
308
+ name,
309
+ original: truthyText(record.originalContent).trim(),
310
+ suggestion: truthyText(record.suggestion).trim(),
311
+ explanation: truthyText(record.explanation).trim(),
312
+ status: truthyText(record.ruleStatus),
313
+ });
314
+ }
315
+ }
316
+ return {
317
+ role: roleKey,
318
+ ruleTotal: selected.length ? selected.length : items.length,
319
+ judged: items.length,
320
+ noRisk: passed.length,
321
+ risk: risks.length,
322
+ risks,
323
+ passed,
324
+ };
325
+ }
326
+ /** 补入报告抬头信息(可从命令行覆盖)。 */
327
+ function mergeMeta(data, meta) {
328
+ const setDefault = (key, value) => {
329
+ if (!(key in data) || data[key] === undefined)
330
+ data[key] = value;
331
+ };
332
+ setDefault('contract', truthyText(meta.contract) || '合同风险审查报告');
333
+ setDefault('partyA', truthyText(meta.partyA));
334
+ setDefault('partyB', truthyText(meta.partyB));
335
+ setDefault('reviewDate', truthyText(meta.reviewDate));
336
+ data.fileId = truthyText(meta.fileId) || truthyText(data.fileId);
337
+ data.fileName = truthyText(meta.fileName) || truthyText(data.fileName);
338
+ data.aiid = truthyText(meta.aiid) || DEFAULT_AIID;
339
+ data.base = truthyText(meta.baseUrl) || DEFAULT_BASE;
340
+ data.cardId = truthyText(meta.cardId) || truthyText(data.cardId) || `cr-report-${truthyText(data.stamp) || '000'}`;
341
+ const datePart = truthyText(data.reviewDate).split('-').join('') || 'report';
342
+ data.fileBase = safeName(`风险审查报告_${truthyText(data.contract)}_${datePart}`);
343
+ return data;
344
+ }
345
+ // ---------------------------------------------------------------- 渲染
346
+ function infoRows(d) {
347
+ const rows = [
348
+ ['合同名称', truthyText(d.contract)],
349
+ ['甲方(用户)', truthyText(d.partyA)],
350
+ ['乙方(供方)', truthyText(d.partyB)],
351
+ ['审查立场', d.role === 'partyB' ? '乙方(partyB)' : truthyText(d.role)],
352
+ ['审查类型', '风险审查(合同预审)'],
353
+ ['审查日期', truthyText(d.reviewDate)],
354
+ ];
355
+ const out = [];
356
+ for (const [key, value] of rows) {
357
+ if (!value)
358
+ continue;
359
+ out.push("<tr><td style='padding:7px 10px;background:#f7f9fc;width:110px;color:#7a8497;border-radius:6px'>"
360
+ + esc(key) + "</td><td style='padding:7px 10px'>" + esc(value) + '</td></tr>');
361
+ }
362
+ return out.join('');
363
+ }
364
+ function riskItems(d) {
365
+ const out = [];
366
+ (d.risks ?? []).forEach((risk, index) => {
367
+ const no = index + 1;
368
+ out.push("<div style='background:#fff;border:1px solid #e8ebf2;border-left:3px solid #c0392b;"
369
+ + "border-radius:10px;padding:14px 16px;margin-bottom:12px'>"
370
+ + "<div style='display:flex;align-items:center;gap:8px;margin-bottom:10px'>"
371
+ + "<span style='background:#fdecea;color:#c0392b;border-radius:10px;padding:2px 8px;font-size:11px'>待整改</span>"
372
+ + "<span style='font-size:14px;font-weight:700;color:#1f2430'>" + String(no) + '. ' + esc(risk.name) + '</span></div>'
373
+ + "<div style='font-size:12px;color:#7a8497;margin-bottom:4px'>合同原文</div>"
374
+ + "<div style='background:#f7f9fc;border-radius:6px;padding:10px;font-size:13px;color:#3c4453;"
375
+ + "line-height:1.7;margin-bottom:10px'>" + esc(risk.original) + '</div>'
376
+ + "<div style='font-size:12px;color:#7a8497;margin-bottom:4px'>问题说明</div>"
377
+ + "<div style='font-size:13px;color:#b45309;line-height:1.7;margin-bottom:10px'>" + esc(risk.explanation) + '</div>'
378
+ + "<div style='font-size:12px;color:#7a8497;margin-bottom:4px'>建议修改为</div>"
379
+ + "<div style='background:#f0f9f4;border:1px solid #cfeadd;border-radius:6px;padding:10px;font-size:13px;"
380
+ + "color:#1a6b45;line-height:1.7'>" + esc(risk.suggestion) + '</div>'
381
+ + '</div>');
382
+ });
383
+ return out.join('');
384
+ }
385
+ function passTags(d) {
386
+ const out = [];
387
+ (d.passed ?? []).forEach((item, index) => {
388
+ out.push("<span style='display:inline-block;background:#f0f9f4;border:1px solid #cfeadd;color:#1a6b45;"
389
+ + "border-radius:8px;padding:5px 10px;font-size:12px;margin:0 8px 8px 0'>"
390
+ + String(index + 1) + '. ' + esc(item.name) + '</span>');
391
+ });
392
+ return out.join('');
393
+ }
394
+ /** rightPanel.open 的 e10Sdk 配置,单引号序列化(ES5 安全)。 */
395
+ function detailCfg(d) {
396
+ const cfg = {
397
+ type: 'e10Sdk',
398
+ width: 1200,
399
+ contentProps: {
400
+ src: `${truthyText(d.base)}${DEFAULT_SRC_PATH}`,
401
+ sdkOptions: {
402
+ compName: 'ui.CorsComponent',
403
+ routerType: 'MemoryRouter',
404
+ routerProps: { initialEntries: [DEFAULT_SRC_PATH] },
405
+ params: {
406
+ app: '@weapp/contract',
407
+ compName: 'AIContractV2',
408
+ aiProps: {
409
+ aiid: truthyText(d.aiid),
410
+ fileId: truthyText(d.fileId),
411
+ fileName: truthyText(d.fileName),
412
+ },
413
+ },
414
+ },
415
+ },
416
+ };
417
+ return JSON.stringify(cfg).replace(/"/gu, "'");
418
+ }
419
+ export function renderRiskReport(d, template) {
420
+ const cardId = truthyText(d.cardId) || `cr-report-${truthyText(d.stamp) || '000'}`;
421
+ return template
422
+ .split('{{CARD_ID}}').join(cardId)
423
+ .split('{{FILE_BASE}}').join(safeName(d.fileBase || '合同风险审查报告'))
424
+ .split('{{CONTRACT_NAME}}').join(esc(d.contract))
425
+ .split('{{TINFO}}').join(infoRows(d))
426
+ .split('{{STAT_TOTAL}}').join(String(d.ruleTotal ?? 0))
427
+ .split('{{STAT_NO_RISK}}').join(String(d.noRisk ?? 0))
428
+ .split('{{STAT_RISK}}').join(String(d.risk ?? 0))
429
+ .split('{{RISK_COUNT}}').join(String(d.risk ?? 0))
430
+ .split('{{RISK_ITEMS}}').join(riskItems(d))
431
+ .split('{{PASS_COUNT}}').join(String(d.noRisk ?? 0))
432
+ .split('{{PASS_TAGS}}').join(passTags(d))
433
+ .split('{{DETAIL_CFG}}').join(detailCfg(d));
434
+ }
435
+ export function buildRiskPayload(html, d, callId) {
436
+ return {
437
+ version: 1,
438
+ callId,
439
+ toolId: 'fill_form',
440
+ arguments: {
441
+ type: 'e10',
442
+ title: truthyText(d.title) || '合同风险审查报告',
443
+ src: `${truthyText(d.base)}/sp/contract/xiaoe-custom-page`,
444
+ width: 1200,
445
+ sdkRenderType: 'inline',
446
+ sdkOptions: {
447
+ compName: 'ui.CorsComponent',
448
+ routerType: 'MemoryRouter',
449
+ routerProps_pc: { initialEntries: ['/sp/contract/xiaoe-custom-page'] },
450
+ params_pc: {
451
+ app: '@weapp/contract',
452
+ compName: 'xiaoeCustomPage',
453
+ customParams: { html },
454
+ },
455
+ },
456
+ },
457
+ };
458
+ }
459
+ /** 交付前自检:双引号数量、ES5 语法禁用项。 */
460
+ export function lintRiskHtml(html) {
461
+ const problems = [];
462
+ const doubleQuotes = (html.match(/"/gu) ?? []).length;
463
+ if (doubleQuotes)
464
+ problems.push(`html 内含 ${doubleQuotes} 个双引号(必须为 0)`);
465
+ for (const bad of ['=>', 'const ', 'let ', '??', '?.', '`']) {
466
+ if (html.includes(bad))
467
+ problems.push(`html 内出现 ES5 禁用语法: ${bad}`);
468
+ }
469
+ const start = html.indexOf('<script>');
470
+ const end = html.lastIndexOf('</script>');
471
+ const js = (start >= 0 && end > start) ? html.slice(start + 8, end) : '';
472
+ return { problems, js };
473
+ }
474
+ const META_KEYS = [
475
+ 'contract', 'partyA', 'partyB', 'reviewDate', 'fileId', 'fileName',
476
+ 'aiid', 'baseUrl', 'cardId', 'callId', 'title',
477
+ ];
478
+ /**
479
+ * 渲染合同风险审查报告卡片。
480
+ *
481
+ * 入参二选一:`ref`(CLI 落盘审查结果,含 envelope)或 `data`(已归一化 report_data.json)。
482
+ * 输出 HTML 不默认落盘(报告只作为卡片交付);显式传 `out` 才写文件。
483
+ */
484
+ export const contractCardRiskReportOperation = {
485
+ name: 'contract.card.risk-report',
486
+ async execute(input) {
487
+ const refPath = typeof input.ref === 'string' && input.ref.trim() ? resolve(input.ref.trim()) : '';
488
+ const dataPath = typeof input.data === 'string' && input.data.trim() ? resolve(input.data.trim()) : '';
489
+ if (!refPath && !dataPath) {
490
+ throw contractValidationError('source_required', '必须提供 ref(CLI 落盘审查结果)或 data(已归一化 report_data.json)');
491
+ }
492
+ if (!isFile(refPath || dataPath)) {
493
+ throw contractValidationError('source_not_found', `输入文件不存在:${refPath || dataPath}`);
494
+ }
495
+ let data;
496
+ if (refPath) {
497
+ data = extractFromRef(refPath);
498
+ }
499
+ else {
500
+ data = readJson(dataPath);
501
+ if (!data || typeof data !== 'object') {
502
+ throw contractValidationError('data_invalid', 'report_data 必须是 JSON 对象');
503
+ }
504
+ }
505
+ const meta = {};
506
+ for (const key of META_KEYS) {
507
+ if (input[key] !== undefined && input[key] !== null && input[key] !== '')
508
+ meta[key] = input[key];
509
+ }
510
+ data = mergeMeta(data, meta);
511
+ const templatePath = typeof input.template === 'string' && input.template.trim()
512
+ ? resolve(input.template.trim())
513
+ : '';
514
+ let template = DEFAULT_TEMPLATE;
515
+ if (templatePath) {
516
+ if (!isFile(templatePath)) {
517
+ throw contractValidationError('template_not_found', `模板文件不存在:${templatePath}`);
518
+ }
519
+ template = readFileSync(templatePath, 'utf8');
520
+ }
521
+ const html = renderRiskReport(data, template);
522
+ const { problems, js } = lintRiskHtml(html);
523
+ const dumpPath = typeof input.dumpData === 'string' && input.dumpData.trim()
524
+ ? resolve(input.dumpData.trim())
525
+ : '';
526
+ let dumpDataOut;
527
+ if (dumpPath) {
528
+ mkdirSync(dirname(dumpPath), { recursive: true });
529
+ writeFileSync(dumpPath, JSON.stringify(data, null, 2), 'utf8');
530
+ dumpDataOut = dumpPath;
531
+ }
532
+ let htmlOut;
533
+ if (typeof input.out === 'string' && input.out.trim()) {
534
+ htmlOut = resolve(input.out.trim());
535
+ mkdirSync(dirname(htmlOut), { recursive: true });
536
+ writeFileSync(htmlOut, html, 'utf8');
537
+ }
538
+ let payloadOut;
539
+ let payload;
540
+ if (typeof input.payload === 'string' && input.payload.trim()) {
541
+ const callId = truthyText(input.callId) || `contract-risk-report-${truthyText(data.stamp) || '000'}`;
542
+ payload = buildRiskPayload(html, data, callId);
543
+ payloadOut = resolve(input.payload.trim());
544
+ mkdirSync(dirname(payloadOut), { recursive: true });
545
+ writeFileSync(payloadOut, JSON.stringify(payload, null, 2), 'utf8');
546
+ }
547
+ return {
548
+ status: 'COMPLETE',
549
+ data: {
550
+ ruleTotal: data.ruleTotal,
551
+ noRisk: data.noRisk,
552
+ risk: data.risk,
553
+ htmlLength: html.length,
554
+ lint: problems.length ? 'FAIL' : 'OK',
555
+ lintProblems: problems,
556
+ ...(js ? { scriptLength: js.length } : {}),
557
+ ...(dumpDataOut ? { dumpData: dumpDataOut } : {}),
558
+ ...(htmlOut ? { output: htmlOut } : {}),
559
+ ...(payloadOut && payload ? { payload: payloadOut, callId: payload.callId } : {}),
560
+ note: htmlOut ? '' : '未传 out:按约定报告只作为卡片交付,不落盘',
561
+ },
562
+ };
563
+ },
564
+ };
565
+ export const contractCardRiskReportOperations = [contractCardRiskReportOperation];