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
@@ -0,0 +1,327 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { contractValidationError } from '../errors.js';
4
+ /**
5
+ * 合同动作推荐引擎(本地,零依赖)。
6
+ *
7
+ * 迁移自 `scripts/plan_actions.py`(2026-11-12 第一批)。
8
+ * 原脚本把注册表、requires、抑制、排序、截断固化为可执行逻辑,
9
+ * 模型只提供上下文状态 JSON,不再自行推断卡片条数。
10
+ *
11
+ * 语义对齐要求:本实现与 Python 版**逐字段等价**,包括
12
+ * Python 的真值规则(`[]` / `{}` 为假)、`"set"` 判定(`0` 视为未设置)、
13
+ * 以及 `(-weight, id)` 的排序与 4 张卡片截断。
14
+ */
15
+ const MAX_CARDS = 4;
16
+ const EMPTY_HINT = '按 contract-action-engine.md §7 空结果处理:不出卡片,说明缺什么与补法';
17
+ /** scene = doc(默认)时的动作域。 */
18
+ const ACTIONS = [
19
+ {
20
+ id: 'generate-contract',
21
+ title: '按报价单生成合同',
22
+ weight: 100,
23
+ walk: 'sendQuestion',
24
+ desc: '用真实模板把标的与金额填成合同 docx | 缺 .docx 模板 | 3~5 步 · 确认 1 次',
25
+ requires: { docType: ['quote', 'tender'] },
26
+ blocked: ['generatedDocx'],
27
+ },
28
+ {
29
+ id: 'launch-flow',
30
+ title: '发起「{flowKey}」合同流程',
31
+ weight: 100,
32
+ walk: 'e10Sdk',
33
+ desc: '生成正式审批单并进入流转 | 证据齐 | 4~7 步 · 确认 2 次',
34
+ requires: { flowKey: 'set', hasFileId: true },
35
+ blocked: ['submitted'],
36
+ },
37
+ {
38
+ id: 'review',
39
+ title: '合同预审',
40
+ weight: 92,
41
+ walk: 'sendQuestion',
42
+ desc: '发消息让 AI 出风险条款与修改建议 | 只读,不改原文',
43
+ requires: { hasFileId: true },
44
+ // 已经触发过审查(reviewStarted)就不再给「合同预审」,避免重复触发
45
+ blocked: ['reviewed', 'reviewStarted'],
46
+ },
47
+ {
48
+ id: 'export-review',
49
+ title: '导出审查报告',
50
+ weight: 84,
51
+ walk: 'artifact',
52
+ desc: '查看风险条款、问题说明与建议修改 | 只读 | 点开即看',
53
+ // 只有「已拿到审查结果」才允许导出;reviewStarted 但无结果时不得出现
54
+ requires: { reviewed: true },
55
+ blocked: [],
56
+ },
57
+ {
58
+ id: 'view-compare',
59
+ title: '查看比对详情',
60
+ weight: 82,
61
+ walk: 'e10Sdk',
62
+ desc: '左右对照看两版差异 | 只读,仅开页面',
63
+ requires: { compared: true },
64
+ blocked: [],
65
+ },
66
+ {
67
+ id: 'view-review',
68
+ title: '查看审查详情',
69
+ weight: 80,
70
+ walk: 'e10Sdk',
71
+ desc: '打开 AI 审查页看逐条判定与原文定位 | 只读,不改原文',
72
+ // 审查进行中(reviewStarted)与已出结果(reviewed)两种情况都要给:
73
+ // 前者是用户稍后回来看进度的唯一入口,后者可看逐条判定
74
+ requires: {},
75
+ any_of: [{ reviewed: true }, { reviewStarted: true }],
76
+ blocked: [],
77
+ },
78
+ {
79
+ id: 'export-compare-report',
80
+ title: '生成比对报告',
81
+ weight: 78,
82
+ walk: 'artifact',
83
+ desc: '出四指标统计与差异清单 | 只读 | 点开即看',
84
+ requires: { compared: true },
85
+ blocked: [],
86
+ },
87
+ {
88
+ id: 'credit',
89
+ title: '查对方资信',
90
+ weight: 72,
91
+ walk: 'e10Sdk',
92
+ desc: '看诉讼/被执行/工商变更 | 只开页面,只读',
93
+ requires: { hasCounterparty: true },
94
+ blocked: [],
95
+ },
96
+ {
97
+ id: 'request-status',
98
+ title: '查这份合同的审批进度',
99
+ weight: 70,
100
+ walk: 'sendQuestion',
101
+ desc: '看当前节点与审批意见 | 只读 | 1~2 步',
102
+ requires: { submitted: true, requestId: 'set' },
103
+ blocked: [],
104
+ },
105
+ {
106
+ id: 'compare',
107
+ title: '比对两份合同',
108
+ weight: 60,
109
+ walk: 'e10Sdk',
110
+ desc: '逐条比差异 | 需两份文件 | 2~3 步',
111
+ requires: { otherVersionAvailable: true },
112
+ blocked: ['compared'],
113
+ },
114
+ {
115
+ id: 'clause-rewrite',
116
+ title: '按建议改条款',
117
+ weight: 56,
118
+ walk: 'sendQuestion',
119
+ desc: '把建议条款写回合同 | 会改原文 | 需确认 2 次',
120
+ requires: { reviewed: true },
121
+ blocked: [],
122
+ },
123
+ {
124
+ id: 'summary',
125
+ title: '查看合同摘要',
126
+ weight: 28,
127
+ walk: 'artifact',
128
+ desc: '要素、标的与关键条款 | 只读 | 点开即看',
129
+ requires: { summaryReady: true },
130
+ blocked: [],
131
+ },
132
+ ];
133
+ /** scene ≠ doc 时的动作域(query / config 不处理合同文件)。 */
134
+ const QUERY_ACTIONS = [
135
+ {
136
+ id: 'query-contracts',
137
+ title: '查我负责的合同',
138
+ weight: 100,
139
+ walk: 'sendQuestion',
140
+ desc: '按负责人查合同列表 | 只读',
141
+ requires: {},
142
+ blocked: [],
143
+ },
144
+ {
145
+ id: 'query-performance',
146
+ title: '查直销业绩',
147
+ weight: 90,
148
+ walk: 'sendQuestion',
149
+ desc: '按期间汇总直销业绩 | 只读',
150
+ requires: {},
151
+ blocked: [],
152
+ },
153
+ {
154
+ id: 'query-receipts',
155
+ title: '查合同收款',
156
+ weight: 80,
157
+ walk: 'sendQuestion',
158
+ desc: '按合同号查收款台账 | 只读',
159
+ requires: {},
160
+ blocked: [],
161
+ },
162
+ {
163
+ id: 'query-channel',
164
+ title: '查渠道订单',
165
+ weight: 70,
166
+ walk: 'sendQuestion',
167
+ desc: '按渠道查订单 | 只读',
168
+ requires: {},
169
+ blocked: [],
170
+ },
171
+ ];
172
+ /** Python 真值语义:None/False/0/""/[]/{} 均为假。 */
173
+ function pyTruthy(value) {
174
+ if (value === null || value === undefined || value === false)
175
+ return false;
176
+ if (value === true)
177
+ return true;
178
+ if (typeof value === 'number')
179
+ return value !== 0 && !Number.isNaN(value);
180
+ if (typeof value === 'string')
181
+ return value.length > 0;
182
+ if (Array.isArray(value))
183
+ return value.length > 0;
184
+ if (typeof value === 'object')
185
+ return Object.keys(value).length > 0;
186
+ return true;
187
+ }
188
+ /** Python `==`:数字与布尔可互相相等(0 == False、1 == True)。 */
189
+ function pyEq(left, right) {
190
+ const toNum = (value) => {
191
+ if (typeof value === 'boolean')
192
+ return value ? 1 : 0;
193
+ if (typeof value === 'number')
194
+ return value;
195
+ return null;
196
+ };
197
+ const ln = toNum(left);
198
+ const rn = toNum(right);
199
+ if (ln !== null && rn !== null)
200
+ return ln === rn;
201
+ if (left === null || left === undefined)
202
+ return right === null || right === undefined;
203
+ return left === right;
204
+ }
205
+ function asText(value) {
206
+ if (value === null || value === undefined)
207
+ return '';
208
+ return String(value);
209
+ }
210
+ /** 单个条件组:全部为真才通过。 */
211
+ function matchOne(cond, ctx) {
212
+ for (const [key, expect] of Object.entries(cond)) {
213
+ const actual = ctx[key];
214
+ if (expect === 'set') {
215
+ // Python: actual in (None, "", False),其中 0 == False 也视为未设置
216
+ if (actual === null || actual === undefined || actual === '' || actual === false)
217
+ return false;
218
+ if (typeof actual === 'number' && actual === 0)
219
+ return false;
220
+ continue;
221
+ }
222
+ if (Array.isArray(expect)) {
223
+ if (!expect.some((item) => pyEq(actual, item)))
224
+ return false;
225
+ continue;
226
+ }
227
+ if (pyTruthy(actual) !== pyTruthy(expect))
228
+ return false;
229
+ }
230
+ return true;
231
+ }
232
+ /** requires 判定:requires 全真 且(无 any_of 或任一分支全真)。 */
233
+ function matches(action, ctx) {
234
+ if (!matchOne(action.requires ?? {}, ctx))
235
+ return false;
236
+ const anyOf = action.any_of;
237
+ if (anyOf && anyOf.length) {
238
+ if (!anyOf.some((cond) => matchOne(cond, ctx)))
239
+ return false;
240
+ }
241
+ return true;
242
+ }
243
+ /** 抑制判定:终态不回推、已完成不重复、本轮刚执行的不立刻回推。 */
244
+ function suppressed(action, ctx) {
245
+ for (const key of action.blocked ?? []) {
246
+ if (pyTruthy(ctx[key]))
247
+ return true;
248
+ }
249
+ return ctx.lastAction === action.id;
250
+ }
251
+ export function planActions(ctx) {
252
+ const rawScene = ctx.scene;
253
+ const scene = pyTruthy(rawScene) ? String(rawScene) : 'doc';
254
+ const pool = scene === 'query' || scene === 'config' ? QUERY_ACTIONS : ACTIONS;
255
+ const scored = pool.filter((action) => matches(action, ctx) && !suppressed(action, ctx));
256
+ scored.sort((left, right) => {
257
+ if (right.weight !== left.weight)
258
+ return right.weight - left.weight;
259
+ if (left.id < right.id)
260
+ return -1;
261
+ if (left.id > right.id)
262
+ return 1;
263
+ return 0;
264
+ });
265
+ const picked = scored.slice(0, MAX_CARDS);
266
+ const flowKey = pyTruthy(ctx.flowKey) ? String(ctx.flowKey) : '';
267
+ const cards = picked.map((action) => ({
268
+ id: action.id,
269
+ title: action.title.split('{flowKey}').join(flowKey),
270
+ weight: action.weight,
271
+ walk: action.walk,
272
+ desc: action.desc,
273
+ }));
274
+ return {
275
+ scene,
276
+ count: cards.length,
277
+ title: `可做的 ${cards.length} 件事`,
278
+ cards,
279
+ dropped: scored.slice(MAX_CARDS).map((action) => action.id),
280
+ hint: cards.length ? '' : EMPTY_HINT,
281
+ };
282
+ }
283
+ function resolveContext(input) {
284
+ const direct = input.context;
285
+ if (direct && typeof direct === 'object' && !Array.isArray(direct)) {
286
+ return direct;
287
+ }
288
+ const file = typeof input.contextFile === 'string' && input.contextFile.trim() ? input.contextFile.trim() : '';
289
+ const inline = typeof input.contextJson === 'string' && input.contextJson.trim() ? input.contextJson.trim() : '';
290
+ if (!file && !inline) {
291
+ throw contractValidationError('context_required', '必须提供上下文:context(对象)、contextFile(JSON 文件路径)或 contextJson(JSON 字符串)三选一');
292
+ }
293
+ let raw;
294
+ if (file) {
295
+ try {
296
+ raw = readFileSync(resolve(file), 'utf8').replace(/^\uFEFF/u, '');
297
+ }
298
+ catch (error) {
299
+ const message = error instanceof Error ? error.message : String(error);
300
+ throw contractValidationError('context_unreadable', `无法读取上下文 JSON:${message}`);
301
+ }
302
+ }
303
+ else {
304
+ raw = inline;
305
+ }
306
+ let parsed;
307
+ try {
308
+ parsed = JSON.parse(raw);
309
+ }
310
+ catch (error) {
311
+ const message = error instanceof Error ? error.message : String(error);
312
+ throw contractValidationError('context_invalid', `上下文不是合法 JSON:${message}`);
313
+ }
314
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
315
+ throw contractValidationError('context_invalid', '上下文必须是 JSON 对象');
316
+ }
317
+ return parsed;
318
+ }
319
+ export const contractCardPlanOperation = {
320
+ name: 'contract.card.plan',
321
+ async execute(input) {
322
+ const ctx = resolveContext(input);
323
+ return { status: 'COMPLETE', data: planActions(ctx) };
324
+ },
325
+ };
326
+ export const contractCardPlanOperations = [contractCardPlanOperation];
327
+ export { asText };