weaver-work-cli 0.1.50 → 0.1.53

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 (191) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{attachment-content-EJYIOJPH.js → attachment-content-W3TSJC3Y.js} +3 -3
  3. package/dist/chunks/{chunk-BFKLQLBK.js → chunk-2J3XY4ED.js} +7 -7
  4. package/dist/chunks/{chunk-K67FODVC.js → chunk-6GCXWKG6.js} +1 -1
  5. package/dist/chunks/{chunk-WNJUGI2F.js → chunk-76PRVYH4.js} +1 -1
  6. package/dist/chunks/{chunk-RYFRGTUV.js → chunk-DEHJ7PMA.js} +4 -4
  7. package/dist/chunks/{chunk-3NCFFHB2.js → chunk-IF33CG4V.js} +1 -1
  8. package/dist/chunks/{chunk-YB3AJYPY.js → chunk-PE334WL3.js} +4 -4
  9. package/dist/chunks/{chunk-MCZG6HPM.js → chunk-QQXMHM3J.js} +2 -2
  10. package/dist/chunks/{chunk-7ECB22G3.js → chunk-U7ROML5E.js} +23 -23
  11. package/dist/chunks/{chunk-7AYQJSFY.js → chunk-WTLQGS6D.js} +2 -2
  12. package/dist/chunks/{chunk-6T53BSWZ.js → chunk-XPQN4E5O.js} +50 -19
  13. package/dist/chunks/{chunk-HARQF5IP.js → chunk-Z4G7LLDD.js} +25 -25
  14. package/dist/chunks/{conflict-C4UDHCWV.js → conflict-57WDJWL7.js} +2 -2
  15. package/dist/chunks/{contract-VUC6JOPG.js → contract-LJRAXVZU.js} +8587 -1421
  16. package/dist/chunks/{create-flow-6OG2LYBD.js → create-flow-3FMMZBCA.js} +6 -6
  17. package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
  18. package/dist/chunks/{env-WP57TF2S.js → env-JYZE3BZB.js} +2 -2
  19. package/dist/chunks/{factory-VUXI7N5C.js → factory-66SCIKW3.js} +1 -1
  20. package/dist/chunks/{group-chat-UQRGXILK.js → group-chat-MNRYMLNG.js} +3 -3
  21. package/dist/chunks/{invoice-E7GOITEU.js → invoice-V7ZTITUO.js} +725 -205
  22. package/dist/chunks/{meeting-4BBLVAWM.js → meeting-IIY4UAJL.js} +10 -10
  23. package/dist/chunks/{recruit-stage-FKWS5UQF.js → recruit-stage-XCMVEQA2.js} +718 -131
  24. package/dist/chunks/{registry-V4CHRQDI.js → registry-CJOVECZD.js} +1 -1
  25. package/dist/chunks/{registry-5CRCN2TV.js → registry-METZ2LWE.js} +10 -10
  26. package/dist/chunks/{room-recommend-AYR3UG7R.js → room-recommend-YFY7HTOF.js} +4 -4
  27. package/dist/chunks/{schedule-JZEFIXUS.js → schedule-6I63TERA.js} +4 -4
  28. package/dist/chunks/smart-extract-FOUYNIG3.js +2882 -0
  29. package/dist/chunks/{workflow-3ZAF2J5E.js → workflow-YHXFIU63.js} +1 -1
  30. package/dist/index.js +11 -6
  31. package/dist/shortcuts/contract/manifest.js +251 -0
  32. package/dist/shortcuts/contract/ooxml/docx-table.js +233 -0
  33. package/dist/shortcuts/contract/operations/card-action.js +1165 -0
  34. package/dist/shortcuts/contract/operations/card-ebdf-list.js +571 -0
  35. package/dist/shortcuts/contract/operations/card-plan.js +327 -0
  36. package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
  37. package/dist/shortcuts/contract/operations/card.js +6 -5
  38. package/dist/shortcuts/contract/operations/docx-fillfromquote.js +532 -0
  39. package/dist/shortcuts/contract/operations/docx-verify.js +258 -0
  40. package/dist/shortcuts/contract/operations/elements-build.js +761 -0
  41. package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
  42. package/dist/shortcuts/contract/operations/first-screen.js +588 -0
  43. package/dist/shortcuts/contract/operations/flow.js +81 -25
  44. package/dist/shortcuts/contract/operations/ledger.js +438 -0
  45. package/dist/shortcuts/contract/operations/modeltext.js +132 -0
  46. package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
  47. package/dist/shortcuts/contract/operations/performance.js +104 -3
  48. package/dist/shortcuts/contract/operations/quote.js +131 -25
  49. package/dist/shortcuts/contract/operations/quotescreen.js +529 -0
  50. package/dist/shortcuts/contract/operations/registry.js +30 -0
  51. package/dist/shortcuts/contract/operations/review.js +73 -58
  52. package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
  53. package/dist/shortcuts/contract/operations/summary.js +4 -2
  54. package/dist/shortcuts/contract/operations/triage.js +1100 -0
  55. package/dist/shortcuts/contract/operations/upload.js +48 -7
  56. package/dist/shortcuts/contract/prewarm-cache.js +90 -0
  57. package/dist/shortcuts/contract/prewarm.js +88 -0
  58. package/dist/shortcuts/contract/upload-cache.js +49 -4
  59. package/dist/shortcuts/data/index.js +1 -6
  60. package/dist/shortcuts/data/manifest.js +2 -2
  61. package/dist/shortcuts/data/operations/index.js +1 -1
  62. package/dist/shortcuts/data/operations/query.js +23 -46
  63. package/dist/shortcuts/index.js +5 -0
  64. package/dist/shortcuts/invoice/index.js +0 -12
  65. package/dist/shortcuts/invoice/manifest.js +200 -49
  66. package/dist/shortcuts/invoice/operations/registry.js +4 -2
  67. package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
  68. package/dist/shortcuts/invoice/operations/shared.js +3 -19
  69. package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
  70. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
  71. package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
  72. package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
  73. package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
  74. package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
  75. package/dist/shortcuts/recruit-stage/shared.js +5 -0
  76. package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
  77. package/dist/shortcuts/smart-extract/constants.js +79 -0
  78. package/dist/shortcuts/smart-extract/continuation.js +71 -0
  79. package/dist/shortcuts/smart-extract/errors.js +68 -0
  80. package/dist/shortcuts/smart-extract/host.js +191 -0
  81. package/dist/shortcuts/smart-extract/index.js +105 -0
  82. package/dist/shortcuts/smart-extract/ledger.js +70 -0
  83. package/dist/shortcuts/smart-extract/manifest.js +35 -0
  84. package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
  85. package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
  86. package/dist/shortcuts/smart-extract/operations/config.js +118 -0
  87. package/dist/shortcuts/smart-extract/operations/fill.js +492 -0
  88. package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
  89. package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
  90. package/dist/shortcuts/smart-extract/operations/save.js +355 -0
  91. package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
  92. package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
  93. package/dist/shortcuts/smart-extract/operations/target.js +167 -0
  94. package/dist/shortcuts/smart-extract/operations/types.js +22 -0
  95. package/dist/shortcuts/smart-extract/operations/validate.js +454 -0
  96. package/dist/shortcuts/workflow/operations/form.js +68 -33
  97. package/dist/shortcuts/workflow/operations/read.js +19 -1
  98. package/docs/SKILL.md +1 -1
  99. package/docs/_catalog.md +3 -0
  100. package/docs/agent-invoice.md +5 -7
  101. package/docs/data.md +5 -1
  102. package/docs/fna.md +14 -1
  103. package/docs/invoice.md +7 -5
  104. package/docs/smart-extract.md +156 -0
  105. package/package.json +1 -1
  106. package/skill-template/business-info.json +16 -1
  107. package/skill-template/domains/qiyecheng.md +2 -0
  108. package/skill-template/domains/smart-extract.md +16 -0
  109. package/skill-template/domains/yepiaotong.md +2 -2
  110. package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
  111. package/skills/weaver-e10-jinchengda/SKILL.md +223 -35
  112. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +47 -481
  113. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +11 -11
  114. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +3 -3
  115. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  116. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +32 -16
  117. package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +478 -0
  118. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  119. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +2 -2
  120. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +39 -61
  121. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +18 -13
  122. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +2 -2
  123. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +21 -6
  124. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +6 -4
  125. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +3 -3
  126. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +263 -0
  127. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +525 -0
  128. package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +36 -0
  129. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
  130. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +87 -0
  131. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +80 -54
  132. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +110 -14
  133. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +19 -21
  134. package/skills/weaver-e10-jinchengda/references/orchestration.md +12 -12
  135. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1 -6
  136. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +2 -1
  137. package/skills/weaver-e10-qiyecheng/SKILL.md +37 -0
  138. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +14 -0
  139. package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
  140. package/skills/weaver-e10-qiyecheng/references/catalog.md +25 -0
  141. package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
  142. package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
  143. package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
  144. package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
  145. package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
  146. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +34 -27
  147. package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
  148. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
  149. package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
  150. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
  151. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
  152. package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
  153. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
  154. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  155. package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
  156. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -42
  157. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
  158. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
  159. package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
  160. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
  161. package/skills/weaver-e10-smart-extract/SKILL.md +180 -0
  162. package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
  163. package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
  164. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +106 -0
  165. package/skills/weaver-e10-workflow/references/workflow-create.md +6 -5
  166. package/skills/weaver-e10-workflow/references/workflow-edit.md +1 -1
  167. package/skills/weaver-e10-workflow/references/workflow-query.md +1 -1
  168. package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
  169. package/skills/weaver-e10-yepiaotong/SKILL.md +46 -33
  170. package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
  171. package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
  172. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
  173. package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
  174. package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
  175. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +12 -8
  176. package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
  177. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +91 -2
  178. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +1 -1
  179. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +12 -12
  180. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
  181. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +136 -91
  182. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +109 -23
  183. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
  184. package/dist/shortcuts/invoice/operations/validate-preview.js +0 -40
  185. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
  186. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
  187. package/skills/weaver-e10-jinchengda/scripts/render_ebdf_list_card.py +0 -265
  188. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
  189. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +0 -588
  190. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +0 -118
  191. package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +0 -40
@@ -1,279 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- plan_actions.py — 合同动作推荐引擎(可执行实现,2026-11-09 新增)
5
-
6
- 背景:此前 `contract-action-engine.md` 只是算法文档,1~4 张卡片全靠模型每次手算,
7
- 实测出现「预审后只给 1 张报告卡、漏掉查看审查详情/发起流程/查资信」的偏差。
8
- 本脚本把注册表、requires、抑制、排序、截断固化为可执行逻辑,
9
- 模型只需提供上下文状态 JSON,不再自行推断卡片条数。
10
-
11
- 用法:
12
- python scripts/plan_actions.py --context ctx.json
13
- python scripts/plan_actions.py --context ctx.json --pretty
14
- 也可以传 JSON 字符串: python scripts/plan_actions.py --context-json '{"reviewed":true,...}'
15
-
16
- 上下文(全部可选,缺省为 false / null):
17
- scene doc | query | config(默认 doc)
18
- docType contract | quote | tender | other
19
- hasFileId 已有审查用 fileId
20
- flowKey 契约锁 | 新客户 | 常规二次销售 | 老客户增值 | null
21
- hasCounterparty 有对方企业全称
22
- summaryReady 摘要已生成
23
- reviewStarted 预审已触发(已预热/审查在跑),但**尚未拿到审查结果**
24
- reviewed 已拿到审查结果(只有它为真才允许导出审查报告)
25
- submitted 流程已发起
26
- requestId 流程实例 id
27
- compared 已完成比对
28
- comparePair 比对文件对
29
- compareReportReady 比对报告已生成
30
- generatedDocx 报价单已生成合同
31
- otherVersionAvailable 会话内存在另一版本
32
- lastAction 上一步刚执行的动作 id(本轮剔除)
33
-
34
- 输出:JSON(count / title / cards[]),退出码 0。FAIL 情形返回 1 并说明缺口。
35
- """
36
-
37
- import argparse
38
- import io
39
- import json
40
- import sys
41
-
42
- MAX_CARDS = 4
43
-
44
- # ── 动作注册表 ───────────────────────────────────────────────
45
- # requires : 全部为真才进候选
46
- # blocked : 任一为真则退场(终态不回推 / 已完成不重复)
47
- # walk : e10Sdk(系统页面已存在)/ artifact(内容已在手)/ sendQuestion(需现场加工)
48
- ACTIONS = [
49
- {
50
- "id": "generate-contract",
51
- "title": "按报价单生成合同",
52
- "weight": 100,
53
- "walk": "sendQuestion",
54
- "desc": "用真实模板把标的与金额填成合同 docx | 缺 .docx 模板 | 3~5 步 · 确认 1 次",
55
- "requires": {"docType": ["quote", "tender"]},
56
- "blocked": ["generatedDocx"],
57
- },
58
- {
59
- "id": "launch-flow",
60
- "title": "发起「{flowKey}」合同流程",
61
- "weight": 100,
62
- "walk": "e10Sdk",
63
- "desc": "生成正式审批单并进入流转 | 证据齐 | 4~7 步 · 确认 2 次",
64
- "requires": {"flowKey": "set", "hasFileId": True},
65
- "blocked": ["submitted"],
66
- },
67
- {
68
- "id": "review",
69
- "title": "合同预审",
70
- "weight": 92,
71
- "walk": "sendQuestion",
72
- "desc": "发消息让 AI 出风险条款与修改建议 | 只读,不改原文",
73
- "requires": {"hasFileId": True},
74
- # 已经触发过审查(reviewStarted)就不再给「合同预审」,避免重复触发
75
- "blocked": ["reviewed", "reviewStarted"],
76
- },
77
- {
78
- "id": "export-review",
79
- "title": "导出审查报告",
80
- "weight": 84,
81
- "walk": "artifact",
82
- "desc": "查看风险条款、问题说明与建议修改 | 只读 | 点开即看",
83
- # 只有「已拿到审查结果」才允许导出;reviewStarted 但无结果时不得出现
84
- "requires": {"reviewed": True},
85
- "blocked": [],
86
- },
87
- {
88
- "id": "view-compare",
89
- "title": "查看比对详情",
90
- "weight": 82,
91
- "walk": "e10Sdk",
92
- "desc": "左右对照看两版差异 | 只读,仅开页面",
93
- "requires": {"compared": True},
94
- "blocked": [],
95
- },
96
- {
97
- "id": "view-review",
98
- "title": "查看审查详情",
99
- "weight": 80,
100
- "walk": "e10Sdk",
101
- "desc": "打开 AI 审查页看逐条判定与原文定位 | 只读,不改原文",
102
- # 审查进行中(reviewStarted)与已出结果(reviewed)两种情况都要给:
103
- # 前者是用户稍后回来看进度的唯一入口,后者可看逐条判定
104
- "requires": {},
105
- "any_of": [{"reviewed": True}, {"reviewStarted": True}],
106
- "blocked": [],
107
- },
108
- {
109
- "id": "export-compare-report",
110
- "title": "生成比对报告",
111
- "weight": 78,
112
- "walk": "artifact",
113
- "desc": "出四指标统计与差异清单 | 只读 | 点开即看",
114
- "requires": {"compared": True},
115
- "blocked": [],
116
- },
117
- {
118
- "id": "credit",
119
- "title": "查对方资信",
120
- "weight": 72,
121
- "walk": "e10Sdk",
122
- "desc": "看诉讼/被执行/工商变更 | 只开页面,只读",
123
- "requires": {"hasCounterparty": True},
124
- "blocked": [],
125
- },
126
- {
127
- "id": "request-status",
128
- "title": "查这份合同的审批进度",
129
- "weight": 70,
130
- "walk": "sendQuestion",
131
- "desc": "看当前节点与审批意见 | 只读 | 1~2 步",
132
- "requires": {"submitted": True, "requestId": "set"},
133
- "blocked": [],
134
- },
135
- {
136
- "id": "compare",
137
- "title": "比对两份合同",
138
- "weight": 60,
139
- "walk": "e10Sdk",
140
- "desc": "逐条比差异 | 需两份文件 | 2~3 步",
141
- "requires": {"otherVersionAvailable": True},
142
- "blocked": ["compared"],
143
- },
144
- {
145
- "id": "clause-rewrite",
146
- "title": "按建议改条款",
147
- "weight": 56,
148
- "walk": "sendQuestion",
149
- "desc": "把建议条款写回合同 | 会改原文 | 需确认 2 次",
150
- "requires": {"reviewed": True},
151
- "blocked": [],
152
- },
153
- {
154
- "id": "summary",
155
- "title": "查看合同摘要",
156
- "weight": 28,
157
- "walk": "artifact",
158
- "desc": "要素、标的与关键条款 | 只读 | 点开即看",
159
- "requires": {"summaryReady": True},
160
- "blocked": [],
161
- },
162
- ]
163
-
164
- # scene ≠ doc 时的动作域(query / config 不处理合同文件)
165
- QUERY_ACTIONS = [
166
- {"id": "query-contracts", "title": "查我负责的合同", "weight": 100, "walk": "sendQuestion",
167
- "desc": "按负责人查合同列表 | 只读", "requires": {}, "blocked": []},
168
- {"id": "query-performance", "title": "查直销业绩", "weight": 90, "walk": "sendQuestion",
169
- "desc": "按期间汇总直销业绩 | 只读", "requires": {}, "blocked": []},
170
- {"id": "query-receipts", "title": "查合同收款", "weight": 80, "walk": "sendQuestion",
171
- "desc": "按合同号查收款台账 | 只读", "requires": {}, "blocked": []},
172
- {"id": "query-channel", "title": "查渠道订单", "weight": 70, "walk": "sendQuestion",
173
- "desc": "按渠道查订单 | 只读", "requires": {}, "blocked": []},
174
- ]
175
-
176
-
177
- def _ok(rule_value, ctx):
178
- if rule_value is True:
179
- return bool(ctx.get("hasFileId") if False else True)
180
- return True
181
-
182
-
183
- def _match_one(cond, ctx):
184
- """单个条件组:全部为真才通过。"""
185
- for key, expect in cond.items():
186
- actual = ctx.get(key)
187
- if expect == "set":
188
- if actual in (None, "", False):
189
- return False
190
- continue
191
- if isinstance(expect, list):
192
- if actual not in expect:
193
- return False
194
- continue
195
- if bool(actual) != bool(expect):
196
- return False
197
- return True
198
-
199
-
200
- def matches(action, ctx):
201
- """requires 判定:requires 全真 且 (无 any_of 或任一分支全真)。"""
202
- if not _match_one(action.get("requires") or {}, ctx):
203
- return False
204
- any_of = action.get("any_of")
205
- if any_of:
206
- if not any(_match_one(c, ctx) for c in any_of):
207
- return False
208
- return True
209
-
210
-
211
- def suppressed(action, ctx):
212
- """抑制判定:终态不回推、已完成不重复、本轮刚执行的不立刻回推。"""
213
- aid = action["id"]
214
- for key in action.get("blocked", []):
215
- if ctx.get(key):
216
- return True
217
- if ctx.get("lastAction") == aid:
218
- return True
219
- return False
220
-
221
-
222
- def plan(ctx):
223
- scene = ctx.get("scene") or "doc"
224
- pool = QUERY_ACTIONS if scene in ("query", "config") else ACTIONS
225
-
226
- scored = []
227
- for a in pool:
228
- if not matches(a, ctx):
229
- continue
230
- if suppressed(a, ctx):
231
- continue
232
- scored.append(a)
233
-
234
- scored.sort(key=lambda x: (-x["weight"], x["id"]))
235
- picked = scored[:MAX_CARDS]
236
-
237
- cards = []
238
- for a in picked:
239
- title = a["title"].replace("{flowKey}", str(ctx.get("flowKey") or ""))
240
- cards.append({
241
- "id": a["id"],
242
- "title": title,
243
- "weight": a["weight"],
244
- "walk": a["walk"],
245
- "desc": a["desc"],
246
- })
247
-
248
- return {
249
- "scene": scene,
250
- "count": len(cards),
251
- "title": "可做的 %d 件事" % len(cards),
252
- "cards": cards,
253
- "dropped": [a["id"] for a in scored[MAX_CARDS:]],
254
- "hint": "" if cards else "按 contract-action-engine.md §7 空结果处理:不出卡片,说明缺什么与补法",
255
- }
256
-
257
-
258
- def main():
259
- ap = argparse.ArgumentParser(description="合同动作推荐引擎")
260
- ap.add_argument("--context", help="上下文状态 JSON 文件")
261
- ap.add_argument("--context-json", help="上下文状态 JSON 字符串")
262
- ap.add_argument("--pretty", action="store_true", help="缩进输出")
263
- args = ap.parse_args()
264
-
265
- if args.context:
266
- with io.open(args.context, "r", encoding="utf-8-sig") as f:
267
- ctx = json.load(f)
268
- elif args.context_json:
269
- ctx = json.loads(args.context_json)
270
- else:
271
- ap.error("必须提供 --context 或 --context-json")
272
-
273
- result = plan(ctx)
274
- print(json.dumps(result, ensure_ascii=False, indent=2 if args.pretty else None))
275
- return 0
276
-
277
-
278
- if __name__ == "__main__":
279
- sys.exit(main())