weaver-work-cli 0.1.52 → 0.1.54
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.
- package/dist/chunks/{attachment-content-MBYYSQIX.js → attachment-content-2EPEI4HV.js} +3 -3
- package/dist/chunks/{chunk-DZOC77ZD.js → chunk-6LGLI46Q.js} +1 -1
- package/dist/chunks/{chunk-RWFRZSIP.js → chunk-7KKI5KDY.js} +2 -2
- package/dist/chunks/{chunk-KLZ3ULQQ.js → chunk-CNVZETM5.js} +1 -1
- package/dist/chunks/{chunk-RPRFIG6I.js → chunk-FE3CQAAM.js} +23 -23
- package/dist/chunks/{chunk-ZRHKGQRQ.js → chunk-JJRIT2ZN.js} +2 -2
- package/dist/chunks/{chunk-LTRLF6MM.js → chunk-LYOFRYC4.js} +4 -4
- package/dist/chunks/{chunk-7UOXOGFL.js → chunk-O6RIBG5E.js} +4 -4
- package/dist/chunks/{chunk-LM2H7SZI.js → chunk-QUDHSMG3.js} +37 -25
- package/dist/chunks/{chunk-IRMA3GVP.js → chunk-XHMJBRLZ.js} +1 -1
- package/dist/chunks/{chunk-LALWNK6M.js → chunk-XPQN4E5O.js} +41 -19
- package/dist/chunks/{chunk-D3TDNRFE.js → chunk-Z7B7QSR2.js} +7 -7
- package/dist/chunks/{conflict-D2HYKBMH.js → conflict-K2IAKKFR.js} +2 -2
- package/dist/chunks/{contract-MFOFMM2J.js → contract-LJRAXVZU.js} +5448 -1857
- package/dist/chunks/{create-flow-7ZATJVTM.js → create-flow-UL37MZGP.js} +6 -6
- package/dist/chunks/{env-5DO4YENS.js → env-BZDB5OVZ.js} +2 -2
- package/dist/chunks/{factory-3M7D7WJC.js → factory-VD3YI6N7.js} +1 -1
- package/dist/chunks/{group-chat-B2HT5NEO.js → group-chat-DHNVO76L.js} +3 -3
- package/dist/chunks/{meeting-HZOX3CBB.js → meeting-OWG4O2XH.js} +10 -10
- package/dist/chunks/{registry-SJHSBO5G.js → registry-ASYCWF2U.js} +10 -10
- package/dist/chunks/{registry-KYPFFQIH.js → registry-CJOVECZD.js} +1 -1
- package/dist/chunks/{room-recommend-5AHR4YQV.js → room-recommend-LSVAMGKV.js} +4 -4
- package/dist/chunks/{schedule-KZPJUPC2.js → schedule-7QOPRUU4.js} +4 -4
- package/dist/chunks/{smart-extract-IXHCZE4R.js → smart-extract-FOUYNIG3.js} +44 -8
- package/dist/chunks/{workflow-UHKCZJMY.js → workflow-YHXFIU63.js} +1 -1
- package/dist/index.js +4 -4
- package/dist/shortcuts/contract/manifest.js +105 -5
- package/dist/shortcuts/contract/ooxml/docx-table.js +233 -0
- package/dist/shortcuts/contract/operations/card-action.js +597 -17
- package/dist/shortcuts/contract/operations/card-ebdf-list.js +258 -2
- package/dist/shortcuts/contract/operations/card.js +6 -5
- package/dist/shortcuts/contract/operations/docx-fillfromquote.js +532 -0
- package/dist/shortcuts/contract/operations/docx-verify.js +258 -0
- package/dist/shortcuts/contract/operations/elements-build.js +47 -0
- package/dist/shortcuts/contract/operations/first-screen.js +28 -3
- package/dist/shortcuts/contract/operations/ledger.js +438 -0
- package/dist/shortcuts/contract/operations/performance.js +104 -3
- package/dist/shortcuts/contract/operations/quotescreen.js +529 -0
- package/dist/shortcuts/contract/operations/registry.js +10 -0
- package/dist/shortcuts/contract/operations/triage.js +1100 -0
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +21 -0
- package/dist/shortcuts/smart-extract/operations/fill.js +10 -7
- package/dist/shortcuts/smart-extract/operations/validate.js +49 -3
- package/dist/shortcuts/workflow/operations/form.js +68 -33
- package/docs/smart-extract.md +5 -5
- package/package.json +1 -1
- package/skills/weaver-e10-jinchengda/SKILL.md +139 -99
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +43 -482
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +7 -8
- package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +32 -16
- package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +478 -0
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +39 -61
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +13 -9
- package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +263 -0
- package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +525 -0
- package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +36 -0
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +3 -6
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +80 -54
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +53 -76
- package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +19 -21
- package/skills/weaver-e10-jinchengda/references/orchestration.md +12 -12
- package/skills/weaver-e10-jinchengda/references/source-manifest.json +1 -6
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +2 -1
- package/skills/weaver-e10-meeting/SKILL.md +2 -1
- package/skills/weaver-e10-smart-extract/SKILL.md +15 -4
- package/skills/weaver-e10-smart-extract/references/result-format.md +2 -2
- package/skills/weaver-e10-smart-extract/references/troubleshooting.md +2 -1
- package/skills/weaver-e10-workflow/references/workflow-create.md +6 -5
- package/skills/weaver-e10-workflow/references/workflow-edit.md +1 -1
- package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +0 -200
- package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +0 -572
- package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +0 -560
- package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +0 -894
- package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +0 -598
- package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +0 -118
|
@@ -1,560 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
quote_screen.py — 报价单首屏(2026-11-11 新增,与 first_screen.py 对称)
|
|
5
|
-
|
|
6
|
-
背景:合同有 contract_first_screen.cmd 快路径,报价单没有,只能由模型手工串联
|
|
7
|
-
quote.sheets → quote.parse → render_action_card → validate,
|
|
8
|
-
天然摊成 4~5 轮。本脚本把这条链固化为两阶段,目标是报价单首屏 ≤3 轮。
|
|
9
|
-
|
|
10
|
-
设计要点:
|
|
11
|
-
1) 语义由模型判定:脚本只把 xlsx 还原成原始网格(extract)与金额结构(parse),
|
|
12
|
-
客户名称/税率/汇总表标记一律由模型读 rows 后产出,不在这里猜。
|
|
13
|
-
2) 两阶段:阶段1 出 sheets + raw_grid + parsed + 要素骨架;
|
|
14
|
-
阶段2 收模型 summary_data.json,产出「文字摘要」与动作卡片。
|
|
15
|
-
3) 报价单**不出摘要卡片、不生成摘要 HTML**(2026-11-11 用户指定):
|
|
16
|
-
报价单只是报价口径,摘要价值低,用对话正文几行文字说清即可;
|
|
17
|
-
省掉 summary render 与卡片内嵌 HTML,可再少 1~2 轮往返。
|
|
18
|
-
|
|
19
|
-
用法(Windows PowerShell / cmd):
|
|
20
|
-
阶段1:
|
|
21
|
-
contract_quote_screen.cmd --file "D:/q/报价.xlsx" --out-dir "D:/tmp/out"
|
|
22
|
-
阶段2:
|
|
23
|
-
contract_quote_screen.cmd --file "D:/q/报价.xlsx" --out-dir "D:/tmp/out" `
|
|
24
|
-
--summary-data "D:/tmp/out/summary_data.json" --company-name "某公司全称"
|
|
25
|
-
|
|
26
|
-
退出码:0 成功;1 CLI 调用失败;2 参数错误;3 卡片未产出
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
import argparse
|
|
30
|
-
import io
|
|
31
|
-
import json
|
|
32
|
-
import os
|
|
33
|
-
import shutil
|
|
34
|
-
import subprocess
|
|
35
|
-
import sys
|
|
36
|
-
import time
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def _find_cli():
|
|
40
|
-
"""直接使用 PATH 中的 weaver-work-cli(requires.bins 已声明该依赖)。
|
|
41
|
-
|
|
42
|
-
历史版本把 C:\\Users\\Administrator\\... 写死在模块级常量里,换机即失效且
|
|
43
|
-
没有任何回退;自行探测客户端安装目录同样属于规范禁止的 bootstrap 脚本。
|
|
44
|
-
仅保留环境变量与 PATH 两种显式来源。
|
|
45
|
-
|
|
46
|
-
2026-11-12 修正:Windows 下 subprocess 走 CreateProcessW,不解析 PATHEXT,
|
|
47
|
-
裸名 "weaver-work-cli" 不会被补全成 .cmd,进程启动阶段即抛 [WinError 2],
|
|
48
|
-
报价单首屏 --auto 必然失败且无覆盖入口。改用 shutil.which 解析完整路径,
|
|
49
|
-
解析不到时才回退裸名。
|
|
50
|
-
"""
|
|
51
|
-
explicit = os.environ.get("WEAVER_WORK_CLI")
|
|
52
|
-
if explicit:
|
|
53
|
-
return explicit
|
|
54
|
-
return shutil.which("weaver-work-cli") or "weaver-work-cli"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
CLI = _find_cli()
|
|
58
|
-
PY = sys.executable
|
|
59
|
-
SKILL_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
60
|
-
SCRIPTS = os.path.join(SKILL_DIR, "scripts")
|
|
61
|
-
BASE = "https://www.e-cology.com.cn"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def _run(args, timeout=180):
|
|
65
|
-
"""执行命令并返回 (ok, stdout, stderr)。stderr 只作诊断,成败看 JSON ok。"""
|
|
66
|
-
try:
|
|
67
|
-
p = subprocess.run(args, capture_output=True, timeout=timeout)
|
|
68
|
-
out = p.stdout.decode("utf-8", "replace")
|
|
69
|
-
err = p.stderr.decode("utf-8", "replace")
|
|
70
|
-
return p.returncode == 0, out, err
|
|
71
|
-
except Exception as e: # noqa: BLE001
|
|
72
|
-
return False, "", str(e)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def cli_json(operation, payload, tmp_dir, tag):
|
|
76
|
-
"""调 CLI 并解析 JSON envelope;成败只看 ok 字段,不看退出码(stderr 提示会污染退出码)。"""
|
|
77
|
-
argf = os.path.join(tmp_dir, "args_%s.json" % tag)
|
|
78
|
-
with io.open(argf, "w", encoding="utf-8") as f:
|
|
79
|
-
json.dump(payload, f, ensure_ascii=False)
|
|
80
|
-
ok, out, err = _run([CLI, "--runtime-agent", "xiaoe", "--json",
|
|
81
|
-
"contract", "run", operation, "--input", argf])
|
|
82
|
-
try:
|
|
83
|
-
start = out.index("{")
|
|
84
|
-
data = json.loads(out[start:])
|
|
85
|
-
except Exception:
|
|
86
|
-
return None, (out or err or "无输出")
|
|
87
|
-
return data, ""
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def write_json(path, obj):
|
|
91
|
-
with io.open(path, "w", encoding="utf-8") as f:
|
|
92
|
-
json.dump(obj, f, ensure_ascii=False, indent=2)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
# 预览关键词。模型判定客户名/税率/汇总表只需这些行,
|
|
96
|
-
# 直接在本轮打印可省掉「再读一次 raw_grid.json」的一轮往返。
|
|
97
|
-
PREVIEW_KEYS = ["客户", "用户名称", "甲方", "报价日期", "有效", "税率", "合计",
|
|
98
|
-
"标准价", "最终优惠", "总价", "汇总", "总计"]
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def preview(rows, head=12):
|
|
102
|
-
"""打印前 head 行 + 关键词命中行,供模型直接判语义。"""
|
|
103
|
-
total = len(rows)
|
|
104
|
-
|
|
105
|
-
def fmt(i, r):
|
|
106
|
-
cells = [c for c in r if str(c).strip()]
|
|
107
|
-
return "r%-3d %s" % (i + 1, " | ".join(str(c).strip()[:40] for c in cells))
|
|
108
|
-
|
|
109
|
-
print("---- GRID HEAD ----")
|
|
110
|
-
for i in range(min(head, total)):
|
|
111
|
-
line = fmt(i, rows[i])
|
|
112
|
-
if line.strip():
|
|
113
|
-
print(line)
|
|
114
|
-
|
|
115
|
-
print("---- GRID KEY HITS ----")
|
|
116
|
-
shown = set()
|
|
117
|
-
for i, r in enumerate(rows):
|
|
118
|
-
joined = "".join(str(c) for c in r)
|
|
119
|
-
if any(k in joined for k in PREVIEW_KEYS):
|
|
120
|
-
if i in shown:
|
|
121
|
-
continue
|
|
122
|
-
shown.add(i)
|
|
123
|
-
print(fmt(i, r))
|
|
124
|
-
|
|
125
|
-
if total > head:
|
|
126
|
-
print("NOTE 完整网格共 %d 行,见 raw_grid.json;上面只给头部与关键词行" % total)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def _money(v):
|
|
130
|
-
"""金额格式化:整数加千分位,非数字原样返回。"""
|
|
131
|
-
try:
|
|
132
|
-
n = float(v)
|
|
133
|
-
except (TypeError, ValueError):
|
|
134
|
-
return str(v) if v not in (None, "") else ""
|
|
135
|
-
if abs(n - int(n)) < 1e-9:
|
|
136
|
-
return "{:,}".format(int(n))
|
|
137
|
-
return "{:,.2f}".format(n)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def build_text_summary(sd):
|
|
141
|
-
"""把 summary_data.json 压成对话可直接使用的纯文字摘要(不出 HTML、不出卡片)。
|
|
142
|
-
|
|
143
|
-
结构兼容两种写法:
|
|
144
|
-
- sections[].type='table' 且带 rows/total → 取第一条作为「费用构成」
|
|
145
|
-
- sections[].type='list' / 'reasons' → 取 items 作为「要点」
|
|
146
|
-
模型只需给 meta / totals / sections,无需为文字摘要额外改造格式。
|
|
147
|
-
"""
|
|
148
|
-
if not isinstance(sd, dict):
|
|
149
|
-
sd = {}
|
|
150
|
-
lines = []
|
|
151
|
-
title = sd.get("title") or "报价单"
|
|
152
|
-
meta = sd.get("meta")
|
|
153
|
-
if not isinstance(meta, dict):
|
|
154
|
-
meta = {}
|
|
155
|
-
totals = sd.get("totals")
|
|
156
|
-
if not isinstance(totals, dict):
|
|
157
|
-
totals = {}
|
|
158
|
-
|
|
159
|
-
head = "报价单:%s" % title
|
|
160
|
-
lines.append(head)
|
|
161
|
-
|
|
162
|
-
who = []
|
|
163
|
-
if meta.get("customer"):
|
|
164
|
-
who.append("客户:%s" % meta["customer"])
|
|
165
|
-
if meta.get("quote_date"):
|
|
166
|
-
who.append("报价日期:%s" % meta["quote_date"])
|
|
167
|
-
if meta.get("sales"):
|
|
168
|
-
who.append("客户经理:%s" % meta["sales"])
|
|
169
|
-
if who:
|
|
170
|
-
lines.append(" | ".join(who))
|
|
171
|
-
|
|
172
|
-
std = totals.get("standard_total")
|
|
173
|
-
fin = totals.get("final_total")
|
|
174
|
-
if std not in (None, "") or fin not in (None, ""):
|
|
175
|
-
seg = []
|
|
176
|
-
if std not in (None, ""):
|
|
177
|
-
seg.append("标准价合计 %s 元" % _money(std))
|
|
178
|
-
if fin not in (None, ""):
|
|
179
|
-
seg.append("最终优惠报价 %s 元" % _money(fin))
|
|
180
|
-
same = False
|
|
181
|
-
try:
|
|
182
|
-
same = float(str(fin).replace(",", "")) == float(str(std).replace(",", ""))
|
|
183
|
-
except (TypeError, ValueError):
|
|
184
|
-
same = False
|
|
185
|
-
if same:
|
|
186
|
-
seg.append("未让价")
|
|
187
|
-
lines.append("金额:" + ",".join(seg))
|
|
188
|
-
|
|
189
|
-
# 费用构成:优先取 table 型 section(含 total)
|
|
190
|
-
comp = ""
|
|
191
|
-
for sec in sd.get("sections") or []:
|
|
192
|
-
if not isinstance(sec, dict):
|
|
193
|
-
continue
|
|
194
|
-
rows = sec.get("rows") or []
|
|
195
|
-
# 只认 >=3 列的明细表;2 列键值表(项目|内容)不是费用构成,跳过
|
|
196
|
-
if sec.get("type") == "table" and rows and len(rows[0]) >= 3:
|
|
197
|
-
parts = []
|
|
198
|
-
for r in rows:
|
|
199
|
-
if not isinstance(r, (list, tuple)) or len(r) < 2:
|
|
200
|
-
continue
|
|
201
|
-
name = str(r[1]).strip() if len(r) > 1 else ""
|
|
202
|
-
amt = str(r[-1]).strip()
|
|
203
|
-
if name:
|
|
204
|
-
parts.append("%s %s 元" % (name, amt))
|
|
205
|
-
if parts:
|
|
206
|
-
comp = ";".join(parts)
|
|
207
|
-
lines.append("构成:" + comp)
|
|
208
|
-
break
|
|
209
|
-
|
|
210
|
-
# 要点:list / reasons 型 section 的 items(最多 5 条,避免正文过长)
|
|
211
|
-
points = []
|
|
212
|
-
for sec in sd.get("sections") or []:
|
|
213
|
-
if not isinstance(sec, dict):
|
|
214
|
-
continue
|
|
215
|
-
if sec.get("type") in ("list", "reasons"):
|
|
216
|
-
for it in (sec.get("items") or [])[:5]:
|
|
217
|
-
s = str(it).strip()
|
|
218
|
-
if s and s not in points:
|
|
219
|
-
points.append(s)
|
|
220
|
-
if points:
|
|
221
|
-
lines.append("要点:" + ";".join(points[:5]))
|
|
222
|
-
|
|
223
|
-
warns = [str(w).strip() for w in (sd.get("warnings") or []) if str(w).strip()]
|
|
224
|
-
if warns:
|
|
225
|
-
lines.append("待核对:" + ";".join(warns[:3]))
|
|
226
|
-
|
|
227
|
-
return "\n".join(lines)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def stage1(path, out_dir):
|
|
231
|
-
os.makedirs(out_dir, exist_ok=True)
|
|
232
|
-
fwd = path.replace("\\", "/")
|
|
233
|
-
|
|
234
|
-
sheets_res, msg = cli_json("contract.quote.sheets", {"path": fwd}, out_dir, "sheets")
|
|
235
|
-
if not sheets_res or not sheets_res.get("ok"):
|
|
236
|
-
print("FAIL sheets: %s" % (msg or sheets_res))
|
|
237
|
-
return 1
|
|
238
|
-
sheets = sheets_res["data"]["sheets"]
|
|
239
|
-
sheet = sheets[0]
|
|
240
|
-
print("SHEETS=%s" % json.dumps(sheets, ensure_ascii=False))
|
|
241
|
-
print("DEFAULT_SHEET=%s (多 sheet 时先让用户选,不要静默取第一个)" % sheet)
|
|
242
|
-
|
|
243
|
-
ext, msg = cli_json("contract.quote.extract", {"path": fwd, "sheet": sheet}, out_dir, "extract")
|
|
244
|
-
if not ext or not ext.get("ok"):
|
|
245
|
-
print("FAIL extract: %s" % (msg or ext))
|
|
246
|
-
return 1
|
|
247
|
-
raw = ext["data"]
|
|
248
|
-
write_json(os.path.join(out_dir, "raw_grid.json"), raw)
|
|
249
|
-
print("RAW_GRID rows=%s cols=%s -> %s"
|
|
250
|
-
% (raw.get("counts", {}).get("rows"), raw.get("counts", {}).get("cols"),
|
|
251
|
-
os.path.join(out_dir, "raw_grid.json")))
|
|
252
|
-
preview(raw.get("rows") or [])
|
|
253
|
-
|
|
254
|
-
parsed, msg = cli_json("contract.quote.parse", {"path": fwd, "sheet": sheet}, out_dir, "parse")
|
|
255
|
-
if parsed and parsed.get("ok"):
|
|
256
|
-
write_json(os.path.join(out_dir, "parsed.json"), parsed["data"])
|
|
257
|
-
meta = parsed["data"].get("meta", {})
|
|
258
|
-
totals = parsed["data"].get("totals", {})
|
|
259
|
-
print("PARSED standard=%s final=%s customer_hit=%r"
|
|
260
|
-
% (totals.get("standard_total"), totals.get("final_total"), meta.get("customer")))
|
|
261
|
-
for w in parsed["data"].get("warnings", []):
|
|
262
|
-
print("WARN %s" % w)
|
|
263
|
-
print("NOTE 上述 customer_hit 为空不代表文件没写客户名;请读 raw_grid.json 由模型判定。")
|
|
264
|
-
else:
|
|
265
|
-
print("WARN parse 未成功(可只用 raw_grid 由模型判定): %s" % (msg or parsed))
|
|
266
|
-
|
|
267
|
-
skeleton = {
|
|
268
|
-
"kind": "quote",
|
|
269
|
-
"file": fwd,
|
|
270
|
-
"sheet": sheet,
|
|
271
|
-
"sheets": sheets,
|
|
272
|
-
"meta": {"customer": "", "quote_date": "", "sales": "", "phone": "",
|
|
273
|
-
"_note": "读 raw_grid.json 后由模型填写;取不到写空串,不要编造"},
|
|
274
|
-
"totals": {"standard_total": None, "final_total": None},
|
|
275
|
-
"sections": [],
|
|
276
|
-
"_next": "模型填好本骨架后产出 summary_data.json,再以 --summary-data 进入阶段2",
|
|
277
|
-
}
|
|
278
|
-
sk_path = os.path.join(out_dir, "elements_skeleton.json")
|
|
279
|
-
write_json(sk_path, skeleton)
|
|
280
|
-
print("SKELETON=%s" % sk_path)
|
|
281
|
-
print("STAGE1_DONE")
|
|
282
|
-
return 0
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
# ---------------------------------------------------------------- auto 模式
|
|
286
|
-
# 2026-11-11 用户反馈:报价单首屏被拆成「阶段1 → 模型填 JSON → 阶段2」两轮,
|
|
287
|
-
# 叠加读 reference、dup 探查,实测 105s。核心诉求是:判类型 → 认客户 →
|
|
288
|
-
# 查金额矛盾 → 出卡片,一条命令做完。--auto 就是这条命令。
|
|
289
|
-
|
|
290
|
-
_LABELS = [
|
|
291
|
-
("customer", r"客户(?:名称|全称)?\s*[::]\s*([^\s::||]+)"),
|
|
292
|
-
("quote_date", r"报价日期\s*[::]\s*([0-9]{4}\s*[-/年]\s*[0-9]{1,2}\s*[-/月]\s*[0-9]{1,2})"),
|
|
293
|
-
("sales", r"客户经理\s*[::]\s*([^\s::||]+)"),
|
|
294
|
-
("phone", r"联系电话\s*[::]\s*([0-9\-]{6,})"),
|
|
295
|
-
]
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
def _money0(n):
|
|
299
|
-
"""金额整数不带 .00,缺值给破折号。"""
|
|
300
|
-
if n in (None, ""):
|
|
301
|
-
return "—"
|
|
302
|
-
try:
|
|
303
|
-
v = float(str(n).replace(",", ""))
|
|
304
|
-
except (TypeError, ValueError):
|
|
305
|
-
return str(n)
|
|
306
|
-
if abs(v - round(v)) < 0.005:
|
|
307
|
-
return "{:,.0f}".format(v)
|
|
308
|
-
return "{:,.2f}".format(v)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
def auto_meta(rows):
|
|
312
|
-
"""从原始网格的『标签:值』单元格取客户/日期/经理/电话。取不到留空,不编造。"""
|
|
313
|
-
import re
|
|
314
|
-
meta = {"customer": "", "quote_date": "", "sales": "", "phone": ""}
|
|
315
|
-
for row in rows or []:
|
|
316
|
-
if not isinstance(row, (list, tuple)):
|
|
317
|
-
continue
|
|
318
|
-
for cell in row:
|
|
319
|
-
if cell is None:
|
|
320
|
-
continue
|
|
321
|
-
s = str(cell).strip()
|
|
322
|
-
if not s:
|
|
323
|
-
continue
|
|
324
|
-
for key, pat in _LABELS:
|
|
325
|
-
if meta[key]:
|
|
326
|
-
continue
|
|
327
|
-
m = re.search(pat, s)
|
|
328
|
-
if m:
|
|
329
|
-
meta[key] = m.group(1).strip()
|
|
330
|
-
return meta
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
def clean_title(file_path):
|
|
334
|
-
"""文件名 -> 可读标题:去【】前缀、去 _日期_后缀与尾部编号。"""
|
|
335
|
-
import re
|
|
336
|
-
base = os.path.splitext(os.path.basename(file_path))[0]
|
|
337
|
-
base = re.sub(r"^【[^】]*】", "", base)
|
|
338
|
-
base = re.sub(r"_[0-9]{6,}.*$", "", base)
|
|
339
|
-
base = re.sub(r"\s*\(\d+\)\s*$", "", base)
|
|
340
|
-
base = re.sub(r"_\d+$", "", base)
|
|
341
|
-
return base.strip() or "报价单"
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
def auto_summary(file_path, raw, parsed):
|
|
345
|
-
"""脚本能确定的部分全部自动填好;模型只需在需要时覆盖。"""
|
|
346
|
-
data = parsed or {}
|
|
347
|
-
meta = auto_meta(raw.get("rows") or [])
|
|
348
|
-
pm = data.get("meta") or {}
|
|
349
|
-
for k in ("customer", "quote_date", "sales", "phone"):
|
|
350
|
-
if not meta.get(k) and pm.get(k):
|
|
351
|
-
meta[k] = pm.get(k)
|
|
352
|
-
|
|
353
|
-
totals = data.get("totals") or {}
|
|
354
|
-
rows = []
|
|
355
|
-
points = []
|
|
356
|
-
for sec in data.get("sections") or []:
|
|
357
|
-
code = sec.get("code") or ""
|
|
358
|
-
name = sec.get("title") or ""
|
|
359
|
-
total = sec.get("total")
|
|
360
|
-
rows.append(["%s%s" % (code, name), _money0(total)])
|
|
361
|
-
items = sec.get("items") or []
|
|
362
|
-
if name:
|
|
363
|
-
points.append("%s%s:%d 项,%s 元" % (code, name, len(items), _money0(total)))
|
|
364
|
-
|
|
365
|
-
warns = [str(w) for w in (data.get("warnings") or []) if str(w).strip()]
|
|
366
|
-
# 客户名已自动取到时,parse 的「未识别到客户名称」告警已失效,不能带给用户
|
|
367
|
-
if meta.get("customer"):
|
|
368
|
-
# 2026-11-12:客户名已取到时,任何「未能定位 / 未识别到客户名称」的告警都已失效。
|
|
369
|
-
# 旧实现只过滤一种固定文案,措辞一改就会把假告警带给用户。
|
|
370
|
-
warns = [w for w in warns
|
|
371
|
-
if not ("客户名称" in w and ("未能" in w or "未从" in w or "未识别" in w))]
|
|
372
|
-
for c in data.get("checks") or []:
|
|
373
|
-
if not isinstance(c, dict):
|
|
374
|
-
continue
|
|
375
|
-
diff = c.get("diff")
|
|
376
|
-
if diff:
|
|
377
|
-
sec_key = (c.get("section") or "").replace("、", "")
|
|
378
|
-
if sec_key:
|
|
379
|
-
warns = [w for w in warns
|
|
380
|
-
if not ("表内" in w and sec_key in w.replace("、", ""))]
|
|
381
|
-
msg = "%s 明细求和 %s 元与表内合计 %s 元相差 %s 元" % (
|
|
382
|
-
c.get("section") or "某分项", _money0(c.get("sum_items")),
|
|
383
|
-
_money0(c.get("sheet_total")), _money0(abs(diff)))
|
|
384
|
-
if msg not in warns:
|
|
385
|
-
warns.append(msg)
|
|
386
|
-
|
|
387
|
-
totals_out = {
|
|
388
|
-
"standard_total": totals.get("standard_total"),
|
|
389
|
-
"final_total": totals.get("final_total"),
|
|
390
|
-
}
|
|
391
|
-
if totals.get("sum_items_grand") not in (None, ""):
|
|
392
|
-
std = totals.get("standard_total")
|
|
393
|
-
grand = totals.get("sum_items_grand")
|
|
394
|
-
try:
|
|
395
|
-
if std not in (None, "") and float(grand) != float(std):
|
|
396
|
-
warns.append("全部明细求和 %s 元与标准价合计 %s 元不一致,差额 %s 元"
|
|
397
|
-
% (_money0(grand), _money0(std), _money0(float(grand) - float(std))))
|
|
398
|
-
except (TypeError, ValueError):
|
|
399
|
-
pass
|
|
400
|
-
|
|
401
|
-
sd = {
|
|
402
|
-
"title": clean_title(file_path),
|
|
403
|
-
"doc_type": "quote",
|
|
404
|
-
"meta": meta,
|
|
405
|
-
"totals": totals_out,
|
|
406
|
-
"sections": [
|
|
407
|
-
{"type": "table", "title": "费用构成", "rows": rows,
|
|
408
|
-
"total": _money0(totals.get("final_total"))},
|
|
409
|
-
{"type": "list", "title": "要点", "items": points},
|
|
410
|
-
],
|
|
411
|
-
"warnings": warns,
|
|
412
|
-
}
|
|
413
|
-
return sd
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
def stage_auto(path, out_dir, doc_type="quote", title="", company_name=""):
|
|
417
|
-
"""一条命令:sheets → extract → parse → 自动识客户 → 矛盾校验 → 卡片。"""
|
|
418
|
-
t0 = time.time()
|
|
419
|
-
os.makedirs(out_dir, exist_ok=True)
|
|
420
|
-
fwd = path.replace("\\", "/")
|
|
421
|
-
|
|
422
|
-
sheets_res, msg = cli_json("contract.quote.sheets", {"path": fwd}, out_dir, "sheets")
|
|
423
|
-
if not sheets_res or not sheets_res.get("ok"):
|
|
424
|
-
print("FAIL sheets: %s" % (msg or sheets_res))
|
|
425
|
-
return 1
|
|
426
|
-
sheets = sheets_res["data"]["sheets"]
|
|
427
|
-
sheet = sheets[0]
|
|
428
|
-
print("SHEETS=%s" % json.dumps(sheets, ensure_ascii=False))
|
|
429
|
-
if len(sheets) > 1:
|
|
430
|
-
print("NOTE 多 sheet,已取第一个『%s』;需要换表请指定 --sheet" % sheet)
|
|
431
|
-
|
|
432
|
-
ext, msg = cli_json("contract.quote.extract", {"path": fwd, "sheet": sheet}, out_dir, "extract")
|
|
433
|
-
if not ext or not ext.get("ok"):
|
|
434
|
-
print("FAIL extract: %s" % (msg or ext))
|
|
435
|
-
return 1
|
|
436
|
-
raw = ext["data"]
|
|
437
|
-
write_json(os.path.join(out_dir, "raw_grid.json"), raw)
|
|
438
|
-
|
|
439
|
-
parsed, msg = cli_json("contract.quote.parse", {"path": fwd, "sheet": sheet}, out_dir, "parse")
|
|
440
|
-
if not parsed or not parsed.get("ok"):
|
|
441
|
-
print("FAIL parse: %s" % (msg or parsed))
|
|
442
|
-
return 1
|
|
443
|
-
pdata = parsed["data"]
|
|
444
|
-
write_json(os.path.join(out_dir, "parsed.json"), pdata)
|
|
445
|
-
|
|
446
|
-
sd = auto_summary(path, raw, pdata)
|
|
447
|
-
if company_name:
|
|
448
|
-
sd["meta"]["customer"] = company_name
|
|
449
|
-
sd_path = os.path.join(out_dir, "summary_data.json")
|
|
450
|
-
write_json(sd_path, sd)
|
|
451
|
-
|
|
452
|
-
cust = sd["meta"].get("customer") or ""
|
|
453
|
-
print("AUTO customer=%r date=%r sales=%r" % (cust, sd["meta"].get("quote_date"), sd["meta"].get("sales")))
|
|
454
|
-
print("AUTO totals standard=%s final=%s" % (sd["totals"].get("standard_total"), sd["totals"].get("final_total")))
|
|
455
|
-
for w in sd.get("warnings") or []:
|
|
456
|
-
print("CHECK %s" % w)
|
|
457
|
-
|
|
458
|
-
rc = stage2(path, out_dir, sd_path, doc_type, title, cust)
|
|
459
|
-
print("AUTO_ELAPSED=%.1fs" % (time.time() - t0))
|
|
460
|
-
return rc
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
def stage2(path, out_dir, summary_data="", doc_type="quote", title="", company_name=""):
|
|
464
|
-
# 报价单不出摘要 HTML、不出摘要卡(2026-11-11 用户指定):只产出文字摘要。
|
|
465
|
-
text_summary = ""
|
|
466
|
-
if summary_data:
|
|
467
|
-
if not os.path.isfile(summary_data):
|
|
468
|
-
print("FAIL summary-data 不存在: %s" % summary_data)
|
|
469
|
-
return 2
|
|
470
|
-
try:
|
|
471
|
-
with io.open(summary_data, encoding="utf-8-sig") as f:
|
|
472
|
-
sd = json.load(f)
|
|
473
|
-
except Exception as e: # noqa: BLE001
|
|
474
|
-
print("FAIL 摘要 JSON 读取失败: %s" % e)
|
|
475
|
-
return 2
|
|
476
|
-
text_summary = build_text_summary(sd)
|
|
477
|
-
txt_path = os.path.join(out_dir, "text_summary.txt")
|
|
478
|
-
with io.open(txt_path, "w", encoding="utf-8") as f:
|
|
479
|
-
f.write(text_summary)
|
|
480
|
-
print("TEXT_SUMMARY=%s" % txt_path)
|
|
481
|
-
else:
|
|
482
|
-
print("SKIP text summary:未提供 --summary-data,本轮只出动作卡片")
|
|
483
|
-
|
|
484
|
-
ctx = {
|
|
485
|
-
"scene": "doc",
|
|
486
|
-
"docType": doc_type,
|
|
487
|
-
"stage": "quote",
|
|
488
|
-
"hasFileId": False,
|
|
489
|
-
# 报价单写明对方企业全称时,按规则可追加「查对方资信」
|
|
490
|
-
"hasCounterparty": bool(company_name),
|
|
491
|
-
# 报价单不出摘要卡:固定 False,动作引擎据此不生成「查看合同摘要」
|
|
492
|
-
"summaryReady": False,
|
|
493
|
-
"flowKey": None,
|
|
494
|
-
}
|
|
495
|
-
ctx_path = os.path.join(out_dir, "card_ctx.json")
|
|
496
|
-
write_json(ctx_path, ctx)
|
|
497
|
-
|
|
498
|
-
card = os.path.join(out_dir, "card.html")
|
|
499
|
-
# 2026-11-12:卡片渲染下沉到 CLI operation(进程内,无子进程),
|
|
500
|
-
# render_action_card.py 已下线,不要再恢复对它的调用。
|
|
501
|
-
cli = shutil.which("weaver-work-cli") or "weaver-work-cli"
|
|
502
|
-
card_args = {"context": ctx, "out": card, "baseUrl": BASE}
|
|
503
|
-
if title:
|
|
504
|
-
card_args["title"] = title
|
|
505
|
-
if company_name:
|
|
506
|
-
card_args["companyName"] = company_name
|
|
507
|
-
args_path = os.path.join(out_dir, "card_args.json")
|
|
508
|
-
write_json(args_path, card_args)
|
|
509
|
-
ok, out, err = _run([cli, "--json", "contract", "run",
|
|
510
|
-
"contract.card.action", "--input", args_path])
|
|
511
|
-
if not os.path.isfile(card):
|
|
512
|
-
print("FAIL render_action_card: %s" % (err or out)[:600])
|
|
513
|
-
return 3
|
|
514
|
-
print("CARD=%s" % card)
|
|
515
|
-
|
|
516
|
-
ok, out, err = _run([PY, os.path.join(SCRIPTS, "validate_action_card.py"), card])
|
|
517
|
-
tail = [ln for ln in (out or "").splitlines() if ln.strip().startswith("summary:")]
|
|
518
|
-
print("VALIDATE %s" % (tail[0] if tail else "未取得校验结论"))
|
|
519
|
-
if not ok:
|
|
520
|
-
print("WARN 卡片校验未通过,详见上方输出")
|
|
521
|
-
|
|
522
|
-
if text_summary:
|
|
523
|
-
print("==== TEXT_SUMMARY_BEGIN ====")
|
|
524
|
-
print(text_summary)
|
|
525
|
-
print("==== TEXT_SUMMARY_END ====")
|
|
526
|
-
|
|
527
|
-
print("==== CARD_HTML_BEGIN ====")
|
|
528
|
-
with io.open(card, encoding="utf-8") as f:
|
|
529
|
-
print(f.read())
|
|
530
|
-
print("==== CARD_HTML_END ====")
|
|
531
|
-
print("STAGE2_DONE")
|
|
532
|
-
return 0
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
def main():
|
|
536
|
-
ap = argparse.ArgumentParser(description="报价单首屏:阶段1 取网格与骨架;阶段2 出文字摘要与动作卡")
|
|
537
|
-
ap.add_argument("--file", required=True, help="报价单 .xlsx 绝对路径")
|
|
538
|
-
ap.add_argument("--out-dir", required=True, help="中间产物与卡片输出目录")
|
|
539
|
-
ap.add_argument("--auto", action="store_true",
|
|
540
|
-
help="一条命令:提取→解析→自动识客户→金额校验→出卡片(首屏推荐)")
|
|
541
|
-
ap.add_argument("--summary-data", default="", help="阶段2:模型产出的摘要 JSON")
|
|
542
|
-
ap.add_argument("--doc-type", default="quote", help="quote | tender,默认 quote")
|
|
543
|
-
ap.add_argument("--title", default="", help="卡片标题,默认由动作引擎算")
|
|
544
|
-
ap.add_argument("--company-name", default="",
|
|
545
|
-
help="阶段2:对方企业全称(模型从 raw grid 判定后传入),用于出「查对方资信」卡")
|
|
546
|
-
a = ap.parse_args()
|
|
547
|
-
|
|
548
|
-
if not os.path.isfile(a.file):
|
|
549
|
-
print("FAIL 文件不存在: %s" % a.file)
|
|
550
|
-
return 2
|
|
551
|
-
|
|
552
|
-
if a.auto:
|
|
553
|
-
return stage_auto(a.file, a.out_dir, a.doc_type, a.title, a.company_name)
|
|
554
|
-
if a.summary_data or a.title:
|
|
555
|
-
return stage2(a.file, a.out_dir, a.summary_data, a.doc_type, a.title, a.company_name)
|
|
556
|
-
return stage1(a.file, a.out_dir)
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if __name__ == "__main__":
|
|
560
|
-
sys.exit(main())
|