weaver-work-cli 0.1.54 → 0.1.57
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/{archive-ZQ4A4TV6.js → archive-4SQAVTIB.js} +3 -2
- package/dist/chunks/{archive-oa-57R2FYHV.js → archive-oa-W2UEJ67L.js} +137 -8
- package/dist/chunks/{asset-ZOJVBWZH.js → asset-EGZEABBI.js} +3 -2
- package/dist/chunks/{asset-idle-XGB5IPGT.js → asset-idle-EBUZBB6M.js} +3 -2
- package/dist/chunks/{attachment-content-2EPEI4HV.js → attachment-content-QGM5MLQE.js} +4 -3
- package/dist/chunks/{blog-QSHLZSFW.js → blog-2YKMWOWI.js} +3 -2
- package/dist/chunks/{caizhilian-KCQYFH72.js → caizhilian-QJ4FLSQJ.js} +5 -4
- package/dist/chunks/{calendar-DLGMRJQA.js → calendar-H4QTJCUY.js} +3 -2
- package/dist/chunks/{chunk-XPQN4E5O.js → chunk-44KJ7WFA.js} +300 -55
- package/dist/chunks/{chunk-CZNZKOHR.js → chunk-4GG72JAT.js} +2 -2
- package/dist/chunks/{chunk-YIKSL36S.js → chunk-5N222HK6.js} +2 -2
- package/dist/chunks/{chunk-XHMJBRLZ.js → chunk-6DVL5IN5.js} +4 -1
- package/dist/chunks/{chunk-JJRIT2ZN.js → chunk-6MS3RLPO.js} +5 -334
- package/dist/chunks/{chunk-QUDHSMG3.js → chunk-7EBV7Q3R.js} +112 -27
- package/dist/chunks/{chunk-CNVZETM5.js → chunk-AHJZIMCX.js} +1 -1
- package/dist/chunks/{chunk-TGAGQV4I.js → chunk-CQ4OVCKG.js} +2 -2
- package/dist/chunks/{chunk-2BQESR2U.js → chunk-DVR2EDUU.js} +99 -34
- package/dist/chunks/{chunk-7KKI5KDY.js → chunk-FDAJC7R4.js} +4 -4
- package/dist/chunks/{chunk-GR76ZDDX.js → chunk-FMNCSYIG.js} +2 -2
- package/dist/chunks/{chunk-6LGLI46Q.js → chunk-L2LMBFG5.js} +1 -1
- package/dist/chunks/{chunk-DLY5GUXX.js → chunk-PH7N4UFT.js} +1 -1
- package/dist/chunks/{chunk-U6R6FZHD.js → chunk-SFM3M2L3.js} +286 -93
- package/dist/chunks/chunk-SHYQUBY3.js +48 -0
- package/dist/chunks/{chunk-HFXK54M4.js → chunk-TGM7BWEH.js} +2 -2
- package/dist/chunks/{chunk-Z7B7QSR2.js → chunk-TJUAGZU7.js} +11 -11
- package/dist/chunks/{chunk-LYOFRYC4.js → chunk-UI66EMOR.js} +4 -4
- package/dist/chunks/{chunk-762M5XJS.js → chunk-VMCCRWFO.js} +2 -2
- package/dist/chunks/{chunk-FE3CQAAM.js → chunk-WHJIUKJW.js} +681 -48
- package/dist/chunks/{chunk-PGO4ILMQ.js → chunk-WMB3SMXI.js} +1 -1
- package/dist/chunks/chunk-WMRNO6IU.js +337 -0
- package/dist/chunks/{chunk-6NXT4ICB.js → chunk-WVH5ESDA.js} +1 -1
- package/dist/chunks/{chunk-O6RIBG5E.js → chunk-XU3FL3AW.js} +4 -4
- package/dist/chunks/{chunk-Z6UUBY37.js → chunk-Z4IPY5GV.js} +2 -2
- package/dist/chunks/{conflict-K2IAKKFR.js → conflict-VAFFPUY3.js} +2 -2
- package/dist/chunks/{contract-LJRAXVZU.js → contract-LLRKMLQQ.js} +2655 -1319
- package/dist/chunks/{cowork-3ACICHDQ.js → cowork-2RDFBZWB.js} +3 -2
- package/dist/chunks/{create-flow-UL37MZGP.js → create-flow-TVYE3IOH.js} +6 -6
- package/dist/chunks/{data-WK5CQXNF.js → data-WVICO3DT.js} +57 -11
- package/dist/chunks/{ebuilder-form-CBYI6CQ6.js → ebuilder-form-TWSXS5NA.js} +7 -6
- package/dist/chunks/{ehr-XI4BIVR2.js → ehr-52GBKNJR.js} +3 -2
- package/dist/chunks/{env-BZDB5OVZ.js → env-BVVFIN4P.js} +2 -2
- package/dist/chunks/{esb-4BQHNP5C.js → esb-HJSXCEOM.js} +5 -4
- package/dist/chunks/{factory-VD3YI6N7.js → factory-RCQ36LLE.js} +1 -1
- package/dist/chunks/{fna-ECOYBQYL.js → fna-OBACRT3J.js} +72 -3
- package/dist/chunks/{group-chat-DHNVO76L.js → group-chat-YFZDUUY3.js} +3 -3
- package/dist/chunks/{host-TUOIOEMC.js → host-2BKMPWDH.js} +4 -3
- package/dist/chunks/{host-3TNBMDTR.js → host-KJT3G5D2.js} +4 -3
- package/dist/chunks/{host-7OWWPLM4.js → host-KOWUMNAY.js} +4 -3
- package/dist/chunks/{host-M4XP5URR.js → host-MFXRA2MY.js} +4 -3
- package/dist/chunks/{host-7NTIBSPK.js → host-TTSGY5NZ.js} +4 -3
- package/dist/chunks/{host-G3VU7SDW.js → host-W4JCNRFS.js} +4 -3
- package/dist/chunks/{hrm-YGIR3HGF.js → hrm-AK3WGBMN.js} +4 -3
- package/dist/chunks/{im-TN2JYVGJ.js → im-JZSBPO4Z.js} +4 -3
- package/dist/chunks/{invoice-V7ZTITUO.js → invoice-7JGSEWT5.js} +22 -9
- package/dist/chunks/{jiuchuanhui-ASFZBMPU.js → jiuchuanhui-K4EQU6GK.js} +3 -2
- package/dist/chunks/{lazy-dispatch-XSAHDK6Z.js → lazy-dispatch-JHGFCKJN.js} +5 -4
- package/dist/chunks/{mail-M3HJF5ER.js → mail-IKVCQCVZ.js} +3 -2
- package/dist/chunks/{meeting-OWG4O2XH.js → meeting-JOHV4RH3.js} +14 -12
- package/dist/chunks/minute-doc-JLS4KMFZ.js +156 -0
- package/dist/chunks/{okr-EVX7FB5G.js → okr-KV43FPPX.js} +3 -2
- package/dist/chunks/{operations-J7PUIVWZ.js → operations-ZPWBMYKE.js} +5 -4
- package/dist/chunks/{plan-2QJQEPBO.js → plan-WOYR4WEG.js} +3 -2
- package/dist/chunks/{project-XELELW2T.js → project-CQJKBUIL.js} +3 -2
- package/dist/chunks/{reception-QGPNTGHG.js → reception-MPBU3JXC.js} +3 -2
- package/dist/chunks/{recruit-stage-XCMVEQA2.js → recruit-stage-USTTRHOX.js} +3 -2
- package/dist/chunks/{registry-CJOVECZD.js → registry-GURQG4ZV.js} +3 -2
- package/dist/chunks/{registry-ASYCWF2U.js → registry-LITYOH2W.js} +12 -10
- package/dist/chunks/{registry-QJCZ2GVG.js → registry-SS5J2FZQ.js} +5 -4
- package/dist/chunks/{room-recommend-LSVAMGKV.js → room-recommend-62MECG4J.js} +4 -4
- package/dist/chunks/{schedule-7QOPRUU4.js → schedule-6QRXIBGU.js} +4 -4
- package/dist/chunks/{smart-extract-FOUYNIG3.js → smart-extract-APX2PNIN.js} +3 -2
- package/dist/chunks/{workflow-YHXFIU63.js → workflow-WMPW3WSB.js} +5 -4
- package/dist/index.js +33 -32
- package/dist/internal/e10/auth/agent-host-key.js +68 -0
- package/dist/internal/e10/auth/agent-hosts.js +250 -0
- package/dist/internal/e10/auth/commands.js +99 -30
- package/dist/internal/e10/auth/paths.js +9 -0
- package/dist/internal/e10/auth/session.js +17 -0
- package/dist/internal/e10/auth/xiaoe.js +37 -3
- package/dist/shortcuts/archive-oa/operations/contract-modules.js +106 -0
- package/dist/shortcuts/archive-oa/operations/contract.js +38 -4
- package/dist/shortcuts/archive-oa/operations/registry.js +2 -1
- package/dist/shortcuts/contract/index.js +6 -7
- package/dist/shortcuts/contract/manifest.js +101 -24
- package/dist/shortcuts/contract/ooxml/docx-table.js +75 -3
- package/dist/shortcuts/contract/ooxml/xlsx.js +49 -13
- package/dist/shortcuts/contract/operations/card-action.js +113 -12
- package/dist/shortcuts/contract/operations/card-ebdf-list.js +29 -7
- package/dist/shortcuts/contract/operations/card-plan.js +75 -9
- package/dist/shortcuts/contract/operations/card-risk-report.js +2 -2
- package/dist/shortcuts/contract/operations/card.js +1 -1
- package/dist/shortcuts/contract/operations/clause-library.js +88 -16
- package/dist/shortcuts/contract/operations/compare-screen.js +378 -0
- package/dist/shortcuts/contract/operations/compare.js +1 -1
- package/dist/shortcuts/contract/operations/credit-page.js +1 -1
- package/dist/shortcuts/contract/operations/docx-slots.js +1000 -0
- package/dist/shortcuts/contract/operations/flow.js +2 -2
- package/dist/shortcuts/contract/operations/quote-to-contract.js +495 -0
- package/dist/shortcuts/contract/operations/quote.js +2 -229
- package/dist/shortcuts/contract/operations/recommend.js +1 -1
- package/dist/shortcuts/contract/operations/registry.js +6 -2
- package/dist/shortcuts/contract/operations/review.js +230 -4
- package/dist/shortcuts/contract/operations/save-recognize.js +122 -3
- package/dist/shortcuts/contract/operations/template.js +11 -10
- package/dist/shortcuts/data/operations/ds.js +5 -5
- package/dist/shortcuts/data/operations/shared.js +76 -4
- package/dist/shortcuts/fna/manifest.js +7 -2
- package/dist/shortcuts/fna/operations/budget.js +68 -0
- package/dist/shortcuts/invoice/manifest.js +8 -3
- package/dist/shortcuts/invoice/operations/reim.js +10 -3
- package/dist/shortcuts/meeting/minute-doc.js +153 -0
- package/dist/shortcuts/meeting/operations/compose-outcome.js +176 -0
- package/dist/shortcuts/meeting/operations/eb/catalog.js +1 -1
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +26 -0
- package/dist/shortcuts/meeting/operations/eb/decision-task-batch.js +144 -0
- package/dist/shortcuts/meeting/operations/eb/decision.js +92 -4
- package/dist/shortcuts/meeting/operations/eb/index.js +133 -4
- package/dist/shortcuts/meeting/operations/eb/meeting-link.js +90 -0
- package/dist/shortcuts/meeting/operations/from-group-chat.js +46 -0
- package/dist/shortcuts/meeting/operations/minute-content.js +61 -0
- package/dist/shortcuts/meeting/operations/registry.js +14 -1
- package/dist/shortcuts/meeting/operations/self-check.js +49 -0
- package/dist/shortcuts/workflow/endpoints.js +2 -0
- package/dist/shortcuts/workflow/operations/read.js +114 -8
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +72 -46
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +41 -0
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +46 -11
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +18 -1
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroupAdd.js +51 -0
- package/docs/e10-auth.md +78 -0
- package/docs/fna.md +8 -3
- package/docs/invoice.md +1 -1
- package/package.json +4 -2
- package/scripts/pack-offline.mjs +228 -0
- package/scripts/package-skill.mjs +14 -5
- package/skill-template/business-info.json +3 -0
- package/skill-template/domains/qiyecheng.md +4 -3
- package/skills/weaver-e10-archive-oa/SKILL.md +6 -1
- package/skills/weaver-e10-archive-oa/references/contract-search.md +91 -4
- package/skills/weaver-e10-jinchengda/SKILL.md +100 -81
- package/skills/weaver-e10-jinchengda/references/contract-action-card-template.html +11 -6
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -4
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +38 -12
- package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +20 -6
- package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +8 -3
- package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +56 -13
- package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +7 -0
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
- package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +11 -5
- package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +38 -7
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +13 -25
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +9 -8
- package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +8 -6
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +10 -7
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +3 -1
- package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +26 -18
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +4 -4
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +18 -13
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +5 -3
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +105 -49
- package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +3 -6
- package/skills/weaver-e10-meeting/SKILL.md +47 -9
- package/skills/weaver-e10-qiyecheng/SKILL.md +16 -7
- package/skills/weaver-e10-qiyecheng/references/budget.md +77 -3
- package/skills/weaver-e10-qiyecheng/references/catalog.md +6 -4
- package/skills/weaver-e10-qiyecheng/references/getEnabledTemplate-api.md +255 -0
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +70 -25
- package/skills/weaver-e10-workflow/SKILL.md +54 -40
- package/skills/weaver-e10-workflow/references/todo-dialogue.md +134 -0
- package/skills/weaver-e10-workflow/references/todo-smart-convert.md +102 -80
- package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +23 -13
- package/skills/weaver-e10-workflow/references/workflow-query.md +68 -46
- package/skills/weaver-e10-workflow/references/workflow-view.md +21 -13
- package/skills/weaver-e10-workflow/tools/todo-summary.cjs +317 -332
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +1 -0
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +23 -13
- package/skills/weaver-e10-yepiaotong.zip +0 -0
- package/dist/shortcuts/contract/ooxml/docx.js +0 -295
- package/dist/shortcuts/contract/operations/docx-fillfromquote.js +0 -532
- package/skills/weaver-e10-jinchengda/references/contract-risk-report-template.html +0 -178
- package/skills/weaver-e10-jinchengda/references/source-manifest.json +0 -1270
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +0 -998
- package/skills/weaver-e10-workflow/tools/todo-serve.cjs +0 -327
|
@@ -6,12 +6,15 @@
|
|
|
6
6
|
* 避免每次现场拼脚本,也避免多跑一次 stage=group 进程(每次 CLI 启动约 6~7s)。
|
|
7
7
|
*
|
|
8
8
|
* 用法:
|
|
9
|
-
* node todo-summary.cjs
|
|
9
|
+
* node todo-summary.cjs query [--limit 500] [筛选条件] [--out DIR] [--prompt "用户完整提示词"]
|
|
10
|
+
* → collect → smartGroup(不取摘要上下文)→ 仅标题清单落库与组件;不生成 AI 摘要或二次分组
|
|
11
|
+
* node todo-summary.cjs prep [--limit 100] [--exclude 内部留言] [--days 365 | --from A --to B] [--out DIR] [--prompt "用户完整提示词"] # 摘要默认/最多100条;未指定时间时由 CLI 按模式阈值自动收窄范围
|
|
10
12
|
* 筛选条件(2026-11-06 起,与 workflow.search 同口径,可任选组合):
|
|
11
13
|
* --workflow "费用报销(ID),采购申请(ID)" --workflow-term in|notin
|
|
12
14
|
* --request-name 报销 --request-name-term like|eq|ne|in|notin
|
|
13
15
|
* --request-mark QC4994681 --request-mark-term eq|like|ne|in|notin
|
|
14
16
|
* --request-level 紧急 --creator 郭杰 --creator-dept 研发中心 --creator-subcom 总部
|
|
17
|
+
* --unoperator 张三 --source-userid 李四 --creator-code A0001 --creator-code-term like
|
|
15
18
|
* --workflow-type 行政类 --node-id 123456,123457 --node-id-term in|notin
|
|
16
19
|
* --flow-status finish,notFinish --flow-status-term in|notin
|
|
17
20
|
* --request-id 5001,5002 --ex-request-id 5003
|
|
@@ -23,14 +26,14 @@
|
|
|
23
26
|
* node todo-summary.cjs build --dir DIR --plan aiGroups.json
|
|
24
27
|
* → 校验 1..count 全覆盖 → smartGroup;若还有待写摘要则打印,否则直接导出终态
|
|
25
28
|
* node todo-summary.cjs finish --dir DIR [--summaries aiSummaries.json]
|
|
26
|
-
* → 回填摘要(可选)→
|
|
29
|
+
* → 回填摘要(可选)→ 三键产物经 smartgroup/add 落 E10 服务端 → 打印结构自检、落库 id 与交付正文
|
|
27
30
|
*
|
|
28
|
-
*
|
|
31
|
+
* 摘要链路的二次分组必须由模型现场产出 aiGroups;普通 query 跳过摘要与二次分组。
|
|
29
32
|
*/
|
|
30
33
|
const { execFileSync } = require('node:child_process');
|
|
31
34
|
const fs = require('node:fs');
|
|
32
|
-
const os = require('node:os');
|
|
33
35
|
const path = require('node:path');
|
|
36
|
+
const os = require('node:os');
|
|
34
37
|
|
|
35
38
|
// 缓存与 aigroup 规则都锚定「当前 skill」(2026-11-01 用户定稿):本脚本就住在
|
|
36
39
|
// <skillDir>/tools/ 下,把自身 skill 目录显式指给 CLI——生成与提取一律用当前 skill
|
|
@@ -52,13 +55,21 @@ if (!process.env.WEAVER_WORK_CLI_SKILL_DIR) {
|
|
|
52
55
|
* `WEAVER_CLI` 环境变量优先级最高(值按原样当可执行文件用)。
|
|
53
56
|
*/
|
|
54
57
|
const CLI_LAUNCH = (() => {
|
|
58
|
+
const entryOverride = process.env.WEAVER_CLI_ENTRY;
|
|
59
|
+
if (entryOverride) {
|
|
60
|
+
if (!/\.(?:cjs|mjs|js)$/i.test(entryOverride) || !fs.statSync(entryOverride).isFile()) {
|
|
61
|
+
throw new Error('WEAVER_CLI_ENTRY 必须指向存在的 Node.js 入口文件');
|
|
62
|
+
}
|
|
63
|
+
return { file: process.execPath, prefix: [path.resolve(entryOverride)], shell: false };
|
|
64
|
+
}
|
|
55
65
|
const override = process.env.WEAVER_CLI;
|
|
56
66
|
if (override) return { file: override, prefix: [], shell: false };
|
|
57
67
|
if (process.platform !== 'win32') return { file: 'weaver-work-cli', prefix: [], shell: false };
|
|
58
68
|
const entry = path.join('node_modules', 'weaver-work-cli', 'dist', 'index.js');
|
|
59
69
|
const bases = [
|
|
60
|
-
|
|
70
|
+
// 跟随启动本脚本的 Node 安装,避免混用另一套全局 CLI。
|
|
61
71
|
path.dirname(process.execPath),
|
|
72
|
+
process.env.APPDATA ? path.join(process.env.APPDATA, 'npm') : '',
|
|
62
73
|
process.env.ProgramFiles ? path.join(process.env.ProgramFiles, 'nodejs') : '',
|
|
63
74
|
process.env['ProgramFiles(x86)'] ? path.join(process.env['ProgramFiles(x86)'], 'nodejs') : '',
|
|
64
75
|
].filter(Boolean);
|
|
@@ -100,6 +111,33 @@ function cliEnv() {
|
|
|
100
111
|
return env;
|
|
101
112
|
}
|
|
102
113
|
|
|
114
|
+
// 只探测当前实际入口的 schema,不用版本号推测能力,也不把能力缓存到后续 helper 进程。
|
|
115
|
+
// schema 不可用时使用既有协议;业务阶段仍只执行一次,失败直接交给原有错误处理。
|
|
116
|
+
let outputModeCapability;
|
|
117
|
+
function supportsOutputMode() {
|
|
118
|
+
if (outputModeCapability !== undefined) return outputModeCapability;
|
|
119
|
+
outputModeCapability = false;
|
|
120
|
+
try {
|
|
121
|
+
const raw = runCli(['--json', 'workflow', 'schema', '--operation', 'workflow.todoSmartConvert'], {
|
|
122
|
+
encoding: 'utf8',
|
|
123
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
124
|
+
timeout: 10000,
|
|
125
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
126
|
+
env: cliEnv(),
|
|
127
|
+
});
|
|
128
|
+
const result = JSON.parse(raw);
|
|
129
|
+
if (result && result.ok !== false) {
|
|
130
|
+
// 标准 CLI 直接输出 operation;部分入口使用统一的 ok/data 信封。
|
|
131
|
+
const schema = result.inputSchema || (result.ok === true && result.data && result.data.inputSchema);
|
|
132
|
+
const modes = schema && schema.properties && schema.properties.outputMode && schema.properties.outputMode.enum;
|
|
133
|
+
outputModeCapability = Array.isArray(modes) && modes.includes('query') && modes.includes('summary');
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
// 仅 schema 读取失败允许兼容既有协议;不要捕获或重试任何真实业务调用。
|
|
137
|
+
}
|
|
138
|
+
return outputModeCapability;
|
|
139
|
+
}
|
|
140
|
+
|
|
103
141
|
function parseArgs(argv) {
|
|
104
142
|
const out = { _: [] };
|
|
105
143
|
for (let i = 0; i < argv.length; i += 1) {
|
|
@@ -131,7 +169,11 @@ function cli(args) {
|
|
|
131
169
|
|
|
132
170
|
function runStage(input, dir, name) {
|
|
133
171
|
const file = path.join(dir, `in-${name}.json`);
|
|
134
|
-
|
|
172
|
+
const stageInput = { ...input };
|
|
173
|
+
if (Object.prototype.hasOwnProperty.call(stageInput, 'outputMode') && !supportsOutputMode()) {
|
|
174
|
+
delete stageInput.outputMode;
|
|
175
|
+
}
|
|
176
|
+
fs.writeFileSync(file, JSON.stringify(stageInput));
|
|
135
177
|
return cli(['--input', file, '--allow-file-input']);
|
|
136
178
|
}
|
|
137
179
|
|
|
@@ -190,10 +232,13 @@ function groupStats(wfIdGroup) {
|
|
|
190
232
|
/**
|
|
191
233
|
* 导出最终结构。
|
|
192
234
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
235
|
+
* 交付形态(2026-11-13 用户定稿,取代 2026-10-28 的本地服务 dataSource 版):
|
|
236
|
+
* stdout 输出 `<browsertool>` 载荷(`[JSON_BEGIN]/[JSON_END]` 之间)由 Agent 原样贴进回复;
|
|
237
|
+
* 三键产物 JSON **不再落物理文件**,经 CLI `stage=smartGroupAdd` 调
|
|
238
|
+
* `POST /api/workflow/list/smartgroup/add` 存进 E10 服务端,拿回落库主键 id,
|
|
239
|
+
* 组件载荷 `params.data` 只带 `{"id": "<id>"}`(id 为原样数字串,保雪花精度)。
|
|
240
|
+
* 本地 node 服务 / --no-serve 内联回退 / ~/Downloads 备用 json 均已整体删除——
|
|
241
|
+
* 落库失败即 exit 1 中断,skill 不再继续(不降级)。
|
|
197
242
|
*
|
|
198
243
|
* 顶层键固定三个:`smartSummaryTitle` / `totalCount` / `wfIdGroup`(用户 2026-10-25 要求加
|
|
199
244
|
* `totalCount` = 当前这批数据的总条数,与各大分组 `count` 之和一致)。
|
|
@@ -275,25 +320,18 @@ function resolveBaseUrl(state, dir) {
|
|
|
275
320
|
}
|
|
276
321
|
|
|
277
322
|
/**
|
|
278
|
-
* 把最终三键对象包成 browsertool 组件载荷(用户 2026-10-27
|
|
323
|
+
* 把最终三键对象包成 browsertool 组件载荷(用户 2026-10-27 要求;2026-11-13 改为 id 传参)。
|
|
279
324
|
* - 外框固定:`callId` 写死 `todo_summary`、`toolId` 写死 `fill_form`(2026-10-28 规范);
|
|
280
325
|
* - `arguments` 层新增 `displayMode: "tabs"` 与 `panelKey`(2026-11-10 用户要求,层级同 title/src):
|
|
281
326
|
* panelKey = `todo_summary_<当前时间戳>`,每轮汇总各开各的面板,避免前端把新旧载荷混进同一 panel;
|
|
282
|
-
* - `params.data`
|
|
283
|
-
*
|
|
284
|
-
*
|
|
327
|
+
* - `params.data` 只带 `{"id": "<smartgroup/add 落库返回的主键>"}`(2026-11-13 用户定稿,
|
|
328
|
+
* 取代旧的 `params.data.dataSource` 本地服务地址)。id 按服务端响应的**原样数字串**内嵌
|
|
329
|
+
* (字符串形态,防雪花 id 超出 JS Number 安全整数范围丢精度);组件侧拿 id 走服务端读回链路;
|
|
285
330
|
* - 包裹完成后立刻 `JSON.parse` 自检,坏载荷不交给用户。
|
|
286
331
|
*/
|
|
287
|
-
function wrapBrowseToolPayload(
|
|
288
|
-
const indentTail = (text, spaces) => text.split('\n')
|
|
289
|
-
.map((line, index) => (index === 0 ? line : ' '.repeat(spaces) + line))
|
|
290
|
-
.join('\n');
|
|
332
|
+
function wrapBrowseToolPayload(baseUrl, smartGroupId) {
|
|
291
333
|
const src = `${String(baseUrl).replace(/\/+$/, '')}/workflow/list/todo`;
|
|
292
334
|
const panelKey = `todo_summary_${Date.now()}`;
|
|
293
|
-
// 用户 2026-10-28 定稿的载荷结构:数据源地址放在 `params.data.dataSource`(不是 `params.dataSource`)。
|
|
294
|
-
const paramsBody = dataSourceUrl
|
|
295
|
-
? ` "data": {\n "dataSource": ${JSON.stringify(dataSourceUrl)}\n }`
|
|
296
|
-
: ` "data": ${indentTail(dataText, 8)}`;
|
|
297
335
|
const text = [
|
|
298
336
|
'{',
|
|
299
337
|
' "version": "1.0",',
|
|
@@ -314,7 +352,9 @@ function wrapBrowseToolPayload(dataText, baseUrl, dataSourceUrl) {
|
|
|
314
352
|
' "params_pc": { "app": "@weapp/workflow", "compName": "Comp.WflTodoSummary", "clientType": "pc" },',
|
|
315
353
|
' "params_mobile": { "app": "@weapp/workflow", "compName": "Comp.WflTodoSummary", "clientType": "mobile" },',
|
|
316
354
|
' "params": {',
|
|
317
|
-
|
|
355
|
+
' "data": {',
|
|
356
|
+
` "id": ${JSON.stringify(String(smartGroupId))}`,
|
|
357
|
+
' }',
|
|
318
358
|
' }',
|
|
319
359
|
' }',
|
|
320
360
|
' }',
|
|
@@ -324,201 +364,7 @@ function wrapBrowseToolPayload(dataText, baseUrl, dataSourceUrl) {
|
|
|
324
364
|
return `${text}\n`;
|
|
325
365
|
}
|
|
326
366
|
|
|
327
|
-
/**
|
|
328
|
-
function sleepSync(ms) {
|
|
329
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* 发布一份快照到「单进程多快照」的本地数据源,返回带 token 的完整 URL(2026-10-29 方案 B)。
|
|
334
|
-
*
|
|
335
|
-
* - 进程恒为 1、端口恒定:`~/.weaver-work-cli/serve/current.json` 里记录 pid/port/version,
|
|
336
|
-
* **只有 `/health` 探通且版本一致**才复用(只看 pid 存活会被 Windows 的 pid 复用骗到);
|
|
337
|
-
* - 每份汇总 = 一个快照目录 `<root>/snapshots/<token>/todo.json`,旧链接在各自空闲期内继续可用;
|
|
338
|
-
* - 快照按目录 mtime 计空闲,超时由服务端自己删;进程在所有快照过期且无请求后才退出。
|
|
339
|
-
*/
|
|
340
|
-
const SERVE_ROOT = path.join(require('node:os').tmpdir(), 'weaver-work-cli-serve');
|
|
341
|
-
const SERVE_VERSION = '4';
|
|
342
|
-
/** v4 服务的发布密钥:ensureServeServer 从 current.json 读出,publishSnapshot 发布时回传。 */
|
|
343
|
-
let servePublishKey = '';
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* 同步探一次本地数据源的 `/health`:通就返回解析后的 JSON,不通返回 null。
|
|
347
|
-
*
|
|
348
|
-
* 为什么不用 async `http.get`:`ensureServeServer` 整条调用链是**同步**的(端口要同步返回),
|
|
349
|
-
* 而 `Atomics.wait` 阻塞主线程后 http 回调永远排不上来。所以用一个极短的 node 子进程发这一发请求:
|
|
350
|
-
* env 走 `cliEnv()` 摘掉宿主 shim,实测子进程约 0.1~0.2s(不摘 shim 会到 4s)。
|
|
351
|
-
*
|
|
352
|
-
* 这一发探测解决两件事:
|
|
353
|
-
* 1. `current.json` 里的 pid 被系统复用给无关进程时,`process.kill(pid,0)` 会误判「还活着」;
|
|
354
|
-
* 2. 服务进程被强杀(Windows 的 TerminateProcess)后注册文件残留,端口已无人监听。
|
|
355
|
-
*/
|
|
356
|
-
function probeHealth(port) {
|
|
357
|
-
if (!port) return null;
|
|
358
|
-
const code = [
|
|
359
|
-
"const http=require('node:http');",
|
|
360
|
-
'const port=Number(process.argv[1]);',
|
|
361
|
-
"const req=http.get({host:'127.0.0.1',port,path:'/health',timeout:800},(res)=>{",
|
|
362
|
-
" let b='';res.setEncoding('utf8');",
|
|
363
|
-
" res.on('data',(d)=>{b+=d;});",
|
|
364
|
-
" res.on('end',()=>{try{process.stdout.write(b);}catch{}process.exit(0);});",
|
|
365
|
-
'});',
|
|
366
|
-
"req.on('timeout',()=>{req.destroy();process.exit(2);});",
|
|
367
|
-
"req.on('error',()=>process.exit(2));",
|
|
368
|
-
].join('');
|
|
369
|
-
try {
|
|
370
|
-
const raw = execFileSync(process.execPath, ['-e', code, String(port)], {
|
|
371
|
-
encoding: 'utf8',
|
|
372
|
-
timeout: 5000,
|
|
373
|
-
maxBuffer: 1024 * 1024,
|
|
374
|
-
env: cliEnv(),
|
|
375
|
-
});
|
|
376
|
-
const parsed = JSON.parse(raw);
|
|
377
|
-
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
378
|
-
} catch {
|
|
379
|
-
return null;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function ensureServeServer(portOption) {
|
|
384
|
-
const registryFile = path.join(SERVE_ROOT, 'current.json');
|
|
385
|
-
const wanted = portOption === true ? 0 : (Number(portOption) || 0);
|
|
386
|
-
fs.mkdirSync(path.join(SERVE_ROOT, 'snapshots'), { recursive: true });
|
|
387
|
-
if (fs.existsSync(registryFile)) {
|
|
388
|
-
try {
|
|
389
|
-
const cur = JSON.parse(fs.readFileSync(registryFile, 'utf8'));
|
|
390
|
-
if (cur && cur.pid && cur.port) {
|
|
391
|
-
// 先探活:既验「真有人在这端口上应答」,也验「应答的是不是我们这个版本的自己」。
|
|
392
|
-
const health = probeHealth(cur.port);
|
|
393
|
-
if (health && health.ok === true && String(health.version) === SERVE_VERSION) {
|
|
394
|
-
servePublishKey = String(cur.publishKey || '');
|
|
395
|
-
return cur.port;
|
|
396
|
-
}
|
|
397
|
-
if (health && health.ok === true) {
|
|
398
|
-
// 确认是本项目的**旧版本**实例:收掉再起新的(此时杀掉是安全的,端口已自证身份)。
|
|
399
|
-
// pid 取 /health 自己报的(authoritative),注册文件里的 pid 可能已过期或被复用。
|
|
400
|
-
const target = Number(health.pid) || cur.pid;
|
|
401
|
-
try { process.kill(target, 'SIGTERM'); } catch { /* 已退出 */ }
|
|
402
|
-
sleepSync(300);
|
|
403
|
-
}
|
|
404
|
-
// 应答不通时**绝不发信号**:pid 可能已被系统复用给无关进程,发 SIGTERM 会误杀别人的进程。
|
|
405
|
-
// 只清注册表、另起一个(旧实例若真活着,会按自己的空闲超时退出)。
|
|
406
|
-
// Windows 上 process.kill 走 TerminateProcess,服务端 SIGTERM 处理器不执行,
|
|
407
|
-
// 残留的 current.json 也由这里一并清掉。
|
|
408
|
-
try { fs.unlinkSync(registryFile); } catch { /* 已删或被杀进程清理过 */ }
|
|
409
|
-
}
|
|
410
|
-
} catch { /* 注册文件损坏,当不存在 */ }
|
|
411
|
-
}
|
|
412
|
-
const child = require('node:child_process').spawn(
|
|
413
|
-
process.execPath,
|
|
414
|
-
[path.join(__dirname, 'todo-serve.cjs'), '--root', SERVE_ROOT, '--port', String(wanted)],
|
|
415
|
-
{ detached: true, stdio: 'ignore' },
|
|
416
|
-
);
|
|
417
|
-
child.unref();
|
|
418
|
-
const deadline = Date.now() + 6000;
|
|
419
|
-
while (Date.now() < deadline) {
|
|
420
|
-
if (fs.existsSync(registryFile)) {
|
|
421
|
-
try {
|
|
422
|
-
const info = JSON.parse(fs.readFileSync(registryFile, 'utf8'));
|
|
423
|
-
if (info && info.version === SERVE_VERSION && info.port && info.pid === child.pid) {
|
|
424
|
-
servePublishKey = String(info.publishKey || '');
|
|
425
|
-
return info.port;
|
|
426
|
-
}
|
|
427
|
-
} catch { /* 文件正在写入,稍后重试 */ }
|
|
428
|
-
}
|
|
429
|
-
sleepSync(120);
|
|
430
|
-
}
|
|
431
|
-
console.log('⚠ 本地数据源启动超时,改用内联 data(检查 %s)', registryFile);
|
|
432
|
-
return null;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
function publishSnapshot(dir, portOption) {
|
|
436
|
-
const dataFile = path.join(dir, 'final.data.json');
|
|
437
|
-
if (!fs.existsSync(dataFile)) return null;
|
|
438
|
-
const port = ensureServeServer(portOption);
|
|
439
|
-
if (!port) return null;
|
|
440
|
-
const token = require('node:crypto').randomBytes(12).toString('hex');
|
|
441
|
-
const url = `http://127.0.0.1:${port}/s/${token}/todo.json`;
|
|
442
|
-
const body = fs.readFileSync(dataFile, 'utf8');
|
|
443
|
-
|
|
444
|
-
// v4 主通路:把 JSON 原文 POST 进服务内存(带发布密钥)。
|
|
445
|
-
// 服务端不再读磁盘 ⇒ 不受「常驻进程读权限被沙箱回收」的影响,链接跨命令/跨轮次稳定。
|
|
446
|
-
// POST 用独立的极短 node 子进程同步完成(与 probeHealth 同款手法:主进程 Atomics 阻塞时
|
|
447
|
-
// async 回调排不上队,只能用子进程);body 走 stdin 传给子进程,避免命令行长度问题。
|
|
448
|
-
const postCode = [
|
|
449
|
-
"const http=require('node:http');",
|
|
450
|
-
"const fs=require('node:fs');",
|
|
451
|
-
'const key=process.argv[1];',
|
|
452
|
-
'const port=Number(process.argv[2]);',
|
|
453
|
-
'const token=process.argv[3];',
|
|
454
|
-
"const body=fs.readFileSync(0,'utf8');",
|
|
455
|
-
"const req=http.request({host:'127.0.0.1',port,path:'/s/'+token+'/todo.json',method:'POST',",
|
|
456
|
-
" headers:{'content-type':'application/json','x-publish-key':key,'content-length':Buffer.byteLength(body)},timeout:10000},",
|
|
457
|
-
' (res)=>{let b="";res.setEncoding("utf8");',
|
|
458
|
-
' res.on("data",(d)=>{b+=d;});',
|
|
459
|
-
' res.on("end",()=>{process.stdout.write(b);process.exit(res.statusCode===200?0:3);});',
|
|
460
|
-
' });',
|
|
461
|
-
"req.on('timeout',()=>{req.destroy();process.exit(2);});",
|
|
462
|
-
"req.on('error',()=>process.exit(2));",
|
|
463
|
-
'req.end(body);',
|
|
464
|
-
].join('');
|
|
465
|
-
try {
|
|
466
|
-
const result = execFileSync(
|
|
467
|
-
process.execPath,
|
|
468
|
-
['-e', postCode, servePublishKey, String(port), token],
|
|
469
|
-
{ input: body, encoding: 'utf8', timeout: 20000, maxBuffer: 16 * 1024 * 1024, env: cliEnv() },
|
|
470
|
-
);
|
|
471
|
-
const parsed = JSON.parse(result);
|
|
472
|
-
if (parsed && parsed.ok === true) {
|
|
473
|
-
try {
|
|
474
|
-
fs.writeFileSync(path.join(dir, 'serve.json'), JSON.stringify({
|
|
475
|
-
url, token, port, mode: 'memory', bytes: parsed.bytes,
|
|
476
|
-
}, null, 2));
|
|
477
|
-
} catch { /* 只是排错用的旁路文件 */ }
|
|
478
|
-
return url;
|
|
479
|
-
}
|
|
480
|
-
} catch { /* POST 失败 ⇒ 回落写文件方式(旧服务兼容) */ }
|
|
481
|
-
|
|
482
|
-
// 回落:老路径——写快照文件,由服务端读磁盘(v3 服务或 POST 失败时才走这里)。
|
|
483
|
-
const snapDir = path.join(SERVE_ROOT, 'snapshots', token);
|
|
484
|
-
fs.mkdirSync(snapDir, { recursive: true });
|
|
485
|
-
// 先拷到临时名再拷成正式名:沙箱会拒绝对家目录做 rename(EPERM),copyFile 不受限;
|
|
486
|
-
// 这份 URL 此时还没交给任何人,所以不存在「读到半份」的窗口。
|
|
487
|
-
const tmp = path.join(snapDir, 'todo.json.tmp');
|
|
488
|
-
fs.copyFileSync(dataFile, tmp);
|
|
489
|
-
fs.copyFileSync(tmp, path.join(snapDir, 'todo.json'));
|
|
490
|
-
try { fs.unlinkSync(tmp); } catch { /* 残留也无害 */ }
|
|
491
|
-
try {
|
|
492
|
-
fs.writeFileSync(path.join(dir, 'serve.json'), JSON.stringify({ url, token, port, mode: 'file' }, null, 2));
|
|
493
|
-
} catch { /* 只是排错用的旁路文件 */ }
|
|
494
|
-
return url;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* 交付文件名的用户名(2026-11-01 用户拍板):`auth whoami` 拿 employeeId →
|
|
499
|
-
* `hrm run hrm.employee.detail` 取 `username`(认证系统当前登录人,不是本机账号)。
|
|
500
|
-
* 结果缓存在 state.json——同一次流水线只查一次;查不到返回 null(调用方退回手工命名)。
|
|
501
|
-
*/
|
|
502
|
-
function resolveDeliverUsername(state, dir) {
|
|
503
|
-
if (state.deliveryUsername) return state.deliveryUsername;
|
|
504
|
-
try {
|
|
505
|
-
const who = JSON.parse(runCli(['--json', 'auth', 'whoami'], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024, env: cliEnv() }));
|
|
506
|
-
const employeeId = String((who.data || who).employeeId || '').trim();
|
|
507
|
-
if (!employeeId) return null;
|
|
508
|
-
state.deliveryEmployeeId = employeeId;
|
|
509
|
-
const raw = runCli(['--json', 'hrm', 'run', 'hrm.employee.detail', '--input-json', JSON.stringify({ id: employeeId })], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024, env: cliEnv() });
|
|
510
|
-
const detail = JSON.parse(raw);
|
|
511
|
-
const username = String((detail.data || {}).username || '').trim();
|
|
512
|
-
if (!username) return null;
|
|
513
|
-
state.deliveryUsername = username;
|
|
514
|
-
fs.writeFileSync(path.join(dir, 'state.json'), JSON.stringify(state));
|
|
515
|
-
return username;
|
|
516
|
-
} catch {
|
|
517
|
-
return null;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
/** 当前登录用户的 employeeId(优先组链接的 secondEmpId,2026-11-10 用户定)。优先复用身份解析的缓存。 */
|
|
367
|
+
/** 当前登录用户的 employeeId(优先组链接的 secondEmpId,2026-11-10 用户定)。结果缓存在 state.json。 */
|
|
522
368
|
function resolveEmployeeId(state, dir) {
|
|
523
369
|
if (state.deliveryEmployeeId) return state.deliveryEmployeeId;
|
|
524
370
|
try {
|
|
@@ -536,43 +382,67 @@ function resolveEmployeeId(state, dir) {
|
|
|
536
382
|
/**
|
|
537
383
|
* 交付正文前段(2026-11-10 用户定稿,纯函数便于测试):
|
|
538
384
|
* ① 总数/降级说明行 —— 总数取 collect 首轮 getTodoListTotal 的结果(state.degrade.steps[0].total);
|
|
539
|
-
*
|
|
540
|
-
*
|
|
385
|
+
* 新模式由 windowDays / terminal 和最后一步 scope 描述实际范围(最低近7天);
|
|
386
|
+
* 历史无上述字段时保留 level=5 对应近1个月终点级的解释;
|
|
541
387
|
* ② 优先组条目表格(2026-11-11 16:10 用户定稿;16:19 反馈:摘要列只保留摘要文字,重要/紧急徽标不再展示)
|
|
542
388
|
* ——两列:摘要(纯文本,竖线转义;摘要为空用流程标题兜底)|
|
|
543
389
|
* 操作(固定「查看详情」,详情链接挂它上);超过 5 条截前 5 条并在标题提示「(前 5 条)」,
|
|
544
390
|
* 不超过不带括号;链接 = {baseUrl}/sp/workflow/flowpage/view/{requestId}?secondEmpId={employeeId}&requestId={requestId};
|
|
545
391
|
* ③ 工作流分组表格 —— 排除优先组,按组内条数降序。
|
|
546
392
|
*/
|
|
393
|
+
function describeDegradeWindow(degrade) {
|
|
394
|
+
const steps = Array.isArray(degrade.steps) ? degrade.steps : [];
|
|
395
|
+
const lastScope = String((steps[steps.length - 1] || {}).scope || '');
|
|
396
|
+
const modern = Object.prototype.hasOwnProperty.call(degrade, 'windowDays') || typeof degrade.terminal === 'boolean';
|
|
397
|
+
if (modern) {
|
|
398
|
+
const days = Number(degrade.windowDays);
|
|
399
|
+
const windows = { 365: '近一年内到达', 180: '近6个月内到达', 90: '近3个月内到达', 30: '近1个月内到达', 7: '近7天内到达' };
|
|
400
|
+
const windowText = days > 0 && Number.isInteger(days) ? (windows[days] || `近${days}天内到达`) : '缩小范围内到达';
|
|
401
|
+
return degrade.terminal === true
|
|
402
|
+
? `${windowText}${lastScope.includes('待处理') ? '且待处理' : '(保留指定分类)'}` : windowText;
|
|
403
|
+
}
|
|
404
|
+
const legacy = { 1: '近一年内到达', 2: '近6个月内到达', 3: '近3个月内到达', 4: '近1个月内到达', 5: '近1个月内到达且待处理' };
|
|
405
|
+
if (Number(degrade.level) === 5 && lastScope && !lastScope.includes('待处理')) return '近1个月内到达(保留指定分类)';
|
|
406
|
+
return legacy[Number(degrade.level)] || '部分范围';
|
|
407
|
+
}
|
|
408
|
+
|
|
547
409
|
function buildReplyPrologue(state, payload, opts) {
|
|
548
410
|
// 降级级别 → 窗口描述(2026-11-11 17:09 用户定稿句式:
|
|
549
411
|
// 降级:「本次共查询到X条待办,其中近N内到达的共N条。针对近期待办汇总如下:」
|
|
550
412
|
// 无降级:「本次共查询到X条待办,汇总如下:」)。
|
|
551
|
-
// 映射表放在函数体内:本文件被测试按函数体提取后 eval 调用,函数外的常量不会跟着走。
|
|
552
|
-
const DEGRADE_LEVEL_WINDOW_TEXTS = {
|
|
553
|
-
1: '近一年内到达',
|
|
554
|
-
2: '近6个月内到达',
|
|
555
|
-
3: '近3个月内到达',
|
|
556
|
-
4: '近1个月内到达',
|
|
557
|
-
5: '近1个月内到达且待处理',
|
|
558
|
-
};
|
|
559
413
|
const lines = [];
|
|
560
414
|
const degrade = state.degrade || null;
|
|
561
415
|
const steps = degrade && Array.isArray(degrade.steps) ? degrade.steps : [];
|
|
562
|
-
const
|
|
416
|
+
const initialCandidate = steps.length > 0 && steps[0].total !== null && steps[0].total !== undefined
|
|
563
417
|
? steps[0].total
|
|
564
418
|
: null;
|
|
565
419
|
const totalCount = Number(payload.totalCount) || 0;
|
|
420
|
+
const initialTotal = state.outputMode === 'summary'
|
|
421
|
+
? (!state.dropped && initialCandidate !== null && Number.isInteger(Number(initialCandidate))
|
|
422
|
+
&& Number(initialCandidate) >= totalCount ? Number(initialCandidate) : null)
|
|
423
|
+
: initialCandidate;
|
|
566
424
|
if (degrade && degrade.applied) {
|
|
567
425
|
// 2026-11-11 17:09 用户定稿:「本次共查询到X条待办,其中近N内到达的共N条。针对近期待办汇总如下:」
|
|
568
|
-
//
|
|
569
|
-
const windowText =
|
|
426
|
+
// 首轮总数未知时提示数量较多;新摘要模式另外说明该范围总数与本次实际汇总数。
|
|
427
|
+
const windowText = describeDegradeWindow(degrade);
|
|
570
428
|
const head = initialTotal !== null ? `本次共查询到${initialTotal}条待办,` : '待办数量较多,';
|
|
571
|
-
|
|
429
|
+
if (state.outputMode === 'summary') {
|
|
430
|
+
const last = steps[steps.length - 1] || {};
|
|
431
|
+
const totals = [(state.queryMeta || {}).totalAvailable, last.total]
|
|
432
|
+
.filter((value) => value !== null && value !== undefined).map(Number);
|
|
433
|
+
const scopedTotal = state.dropped > 0 ? undefined
|
|
434
|
+
: totals.find((value) => Number.isInteger(value) && value >= totalCount);
|
|
435
|
+
const coverage = scopedTotal !== undefined
|
|
436
|
+
? `其中${windowText}的共${scopedTotal}条,本次汇总${totalCount}条。`
|
|
437
|
+
: `本次汇总${windowText}的${totalCount}条待办。`;
|
|
438
|
+
lines.push(`${head}${coverage}针对近期待办汇总如下:`);
|
|
439
|
+
} else lines.push(`${head}其中${windowText}的共${totalCount}条。针对近期待办汇总如下:`);
|
|
572
440
|
} else {
|
|
573
441
|
// 无降级:「本次共查询到X条待办,汇总如下:」(首轮总数拿不到时用实际取到数兜底)
|
|
574
442
|
const shown = initialTotal !== null ? initialTotal : totalCount;
|
|
575
|
-
lines.push(
|
|
443
|
+
lines.push(state.outputMode === 'summary' && Number(shown) > totalCount
|
|
444
|
+
? `本次共查询到${shown}条待办,本次汇总${totalCount}条,汇总如下:`
|
|
445
|
+
: `本次共查询到${shown}条待办,汇总如下:`);
|
|
576
446
|
}
|
|
577
447
|
|
|
578
448
|
const groups = Array.isArray(payload.wfIdGroup) ? payload.wfIdGroup : [];
|
|
@@ -666,6 +536,23 @@ function requiredFieldsFor(title) {
|
|
|
666
536
|
return Array.isArray(rule.summaryRequiredFields) ? rule.summaryRequiredFields.filter((f) => typeof f === 'string' && f.trim()) : [];
|
|
667
537
|
}
|
|
668
538
|
|
|
539
|
+
/** 普通查询与摘要共用服务端落库协议;失败时不生成组件载荷。 */
|
|
540
|
+
function persistPayload(payload, dir, queryPrompt) {
|
|
541
|
+
const addResult = runStage({
|
|
542
|
+
stage: 'smartGroupAdd',
|
|
543
|
+
queryPrompt: String(queryPrompt || ''),
|
|
544
|
+
querySummary: JSON.stringify(payload),
|
|
545
|
+
queryCost: '',
|
|
546
|
+
}, dir, 'smartgroupadd');
|
|
547
|
+
const smartGroupId = String((addResult.data || {}).id || '');
|
|
548
|
+
if (!/^\d+$/.test(smartGroupId) || /^0+$/.test(smartGroupId)) {
|
|
549
|
+
console.error('✖ 智能分组产物落库失败:接口未返回有效 id。交付中断,请排查 /api/workflow/list/smartgroup/add 后重试。');
|
|
550
|
+
process.exit(1);
|
|
551
|
+
}
|
|
552
|
+
console.log('\n产物已落库:POST /api/workflow/list/smartgroup/add ⇒ id=%s(组件载荷 params.data 只带该 id)', smartGroupId);
|
|
553
|
+
return smartGroupId;
|
|
554
|
+
}
|
|
555
|
+
|
|
669
556
|
function exportFinal(result, dir, state, kept, opts = {}) {
|
|
670
557
|
const data = result.data;
|
|
671
558
|
const groupTotal = (data.wfIdGroup || []).reduce((sum, g) => sum + (Number(g.count) || 0), 0);
|
|
@@ -770,82 +657,25 @@ function exportFinal(result, dir, state, kept, opts = {}) {
|
|
|
770
657
|
console.log(` ${row.title} | ${row.count} | ${row.display}${row.singles ? ` +单条${row.singles}` : ''}`);
|
|
771
658
|
}
|
|
772
659
|
// 叠加视图:优先组的条目同时留在工作流组里,所以 Σcount 会大于 totalCount(去重条数)。
|
|
773
|
-
console.log('\n自检:totalCount=%d(去重)|Σcount=%d(含优先组叠加 %d)|汇总项覆盖 %d + 单条 %d | 空摘要 %d
|
|
774
|
-
totalCount, total, Math.max(0, total - totalCount), stats.covered, stats.singles, stats.empty
|
|
775
|
-
path.join(dir, 'final.data.json'));
|
|
660
|
+
console.log('\n自检:totalCount=%d(去重)|Σcount=%d(含优先组叠加 %d)|汇总项覆盖 %d + 单条 %d | 空摘要 %d',
|
|
661
|
+
totalCount, total, Math.max(0, total - totalCount), stats.covered, stats.singles, stats.empty);
|
|
776
662
|
const meta = result.meta || {};
|
|
777
663
|
const steps = (meta.timing && meta.timing.steps) || [];
|
|
778
664
|
console.log('CLI 自报分段:%s', steps.map((s) => `${s.name}:${s.kind}=${fmt(s.durationMs)}`).join(' '));
|
|
779
|
-
//
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
lines.push(` "title": ${JSON.stringify(g.title)},`);
|
|
791
|
-
lines.push(` "count": ${g.count},`);
|
|
792
|
-
lines.push(` "defaultExpanded": ${g.defaultExpanded},`);
|
|
793
|
-
lines.push(' "displayItems": [');
|
|
794
|
-
g.displayItems.forEach((item, ii) => {
|
|
795
|
-
const tail = ii < g.displayItems.length - 1 ? ',' : '';
|
|
796
|
-
if (item.type === 'request') {
|
|
797
|
-
lines.push(` {"type":"request","requestData":${JSON.stringify(item.requestData)}}${tail}`);
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
lines.push(' {');
|
|
801
|
-
lines.push(' "type": "group",');
|
|
802
|
-
lines.push(` "id": ${JSON.stringify(item.id)},`);
|
|
803
|
-
lines.push(` "title": ${JSON.stringify(item.title)},`);
|
|
804
|
-
lines.push(` "count": ${item.count},`);
|
|
805
|
-
lines.push(` "summary": ${JSON.stringify(item.summary)},`);
|
|
806
|
-
lines.push(` "defaultExpanded": ${item.defaultExpanded},`);
|
|
807
|
-
lines.push(' "requestDatas": [');
|
|
808
|
-
item.requestDatas.forEach((row, ri) => {
|
|
809
|
-
lines.push(` ${JSON.stringify(row)}${ri < item.requestDatas.length - 1 ? ',' : ''}`);
|
|
810
|
-
});
|
|
811
|
-
lines.push(' ]');
|
|
812
|
-
lines.push(` }${tail}`);
|
|
813
|
-
});
|
|
814
|
-
lines.push(' ]');
|
|
815
|
-
lines.push(` }${gi < payload.wfIdGroup.length - 1 ? ',' : ''}`);
|
|
816
|
-
});
|
|
817
|
-
lines.push(' ]', '}');
|
|
818
|
-
// 供 todo-serve.cjs 读取的同构数据(只有三键,无外框):服务与载荷永远读同一份,不会出现两份数据。
|
|
819
|
-
fs.writeFileSync(path.join(dir, 'final.data.json'), JSON.stringify(payload));
|
|
820
|
-
// 交付文件(2026-11-01 用户拍板):由**脚本**按「认证用户名_YYYYmmddHHMMSS.json」落到 ~/Downloads/,
|
|
821
|
-
// 执行方默认不展示该文件——仅当用户明确要求输出 json 时才交付(交付口径以 references §6.1 顶部为准)。
|
|
822
|
-
// 用户名 = auth whoami → hrm.employee.detail.username,state 缓存免重复查询;失败则不生成并在输出里说明。
|
|
823
|
-
let deliveredFile = null;
|
|
824
|
-
const username = resolveDeliverUsername(state, dir);
|
|
825
|
-
if (username) {
|
|
826
|
-
try {
|
|
827
|
-
const d = new Date();
|
|
828
|
-
const pad = (n) => String(n).padStart(2, '0');
|
|
829
|
-
const stamp = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
|
|
830
|
-
const downloads = path.join(os.homedir(), 'Downloads');
|
|
831
|
-
fs.mkdirSync(downloads, { recursive: true });
|
|
832
|
-
deliveredFile = path.join(downloads, `${username}_${stamp}.json`);
|
|
833
|
-
fs.writeFileSync(deliveredFile, JSON.stringify(payload));
|
|
834
|
-
} catch {
|
|
835
|
-
deliveredFile = null;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
if (deliveredFile) console.log('已生成备用文件:%s(默认不展示;仅当用户明确要求输出 json 时再交付——交付口径以 references §6.1 顶部为准)', deliveredFile);
|
|
839
|
-
else console.log('备用文件未生成(用户名查询失败或 Downloads 不可写):如用户要求输出 json,把 %s 复制为 ~/Downloads/<用户名>_<YYYYmmddHHMMSS>.json 后交付', path.join(dir, 'final.data.json'));
|
|
840
|
-
// 数据源模式:`--data-source <url>` 直接用给定地址;`--serve [端口]` 现起一个本地服务拿地址。
|
|
841
|
-
let dataSourceUrl = opts.dataSource && opts.dataSource !== true ? String(opts.dataSource) : null;
|
|
842
|
-
if (!dataSourceUrl && opts.serve) dataSourceUrl = publishSnapshot(dir, opts.serve);
|
|
843
|
-
// 落盘与 stdout 共用同一份载荷;data 段只保留三个业务键。
|
|
844
|
-
const finalText = wrapBrowseToolPayload(lines.join('\n'), baseUrl, dataSourceUrl);
|
|
845
|
-
if (dataSourceUrl) {
|
|
846
|
-
console.log('\n数据源模式:params.dataSource = %s', dataSourceUrl);
|
|
847
|
-
console.log(' 组件改为 GET 该地址(响应体就是 params.data 的三键对象);单进程多快照,快照空闲 30 分钟后自动清理');
|
|
665
|
+
// 产物落库(2026-11-13 用户定稿):三键 JSON 不落物理文件,经 CLI stage=smartGroupAdd 调
|
|
666
|
+
// POST /api/workflow/list/smartgroup/add 存 E10 服务端,拿回落库主键 id 给组件载荷用。
|
|
667
|
+
// 失败口径:不降级、不回退——CLI 抛错即 exit 1,skill 不再继续(2026-11-13 用户定稿)。
|
|
668
|
+
let smartGroupId = '';
|
|
669
|
+
try {
|
|
670
|
+
smartGroupId = persistPayload(payload, dir, opts.queryPrompt);
|
|
671
|
+
} catch (error) {
|
|
672
|
+
// runStage→cli 在 !ok 时已自己 exit(1),这里兜住其它同步异常
|
|
673
|
+
console.error('✖ 智能分组产物落库失败:%s', error && error.message ? error.message : error);
|
|
674
|
+
console.error(' → 交付中断:产物未存进 E10 服务端,不生成组件载荷。排查登录态/服务端 /api/workflow/list/smartgroup/add 后重跑 finish。');
|
|
675
|
+
process.exit(1);
|
|
848
676
|
}
|
|
677
|
+
// 交付正文与 stdout 共用同一份;`params.data.id` = 落库主键(原样数字串,保雪花精度)。
|
|
678
|
+
const finalText = wrapBrowseToolPayload(baseUrl, smartGroupId);
|
|
849
679
|
// 交付 = 回复正文(总数/降级说明 + 优先组前 5 列表 + 工作流表格 + <browsertool> 块)。
|
|
850
680
|
// 2026-11-10 用户定稿:正文不再是只有组件块,前段由脚本产出、模型原样粘贴(勿增删改写)。
|
|
851
681
|
const delivery = `<browsertool>\n${finalText.trimEnd()}\n</browsertool>`;
|
|
@@ -916,6 +746,10 @@ const COLLECT_FILTER_FLAGS = {
|
|
|
916
746
|
creator: 'creator',
|
|
917
747
|
'creator-dept': 'creatorDept',
|
|
918
748
|
'creator-subcom': 'creatorSubcom',
|
|
749
|
+
'unoperator': 'unoperator',
|
|
750
|
+
'source-userid': 'sourceUserid',
|
|
751
|
+
'creator-code': 'creatorcode',
|
|
752
|
+
'creator-code-term': 'creatorcodeTerm',
|
|
919
753
|
'workflow-type': 'workflowType',
|
|
920
754
|
'request-name': 'requestName',
|
|
921
755
|
'request-name-term': 'requestNameTerm',
|
|
@@ -930,6 +764,7 @@ const COLLECT_FILTER_FLAGS = {
|
|
|
930
764
|
'flow-status-term': 'flowStatusTerm',
|
|
931
765
|
'create-time': 'createTime',
|
|
932
766
|
'operate-time': 'operateTime',
|
|
767
|
+
'receive-time': 'receiveTime',
|
|
933
768
|
'finish-time': 'finishTime',
|
|
934
769
|
'filter-fields': 'filterFields',
|
|
935
770
|
'condition-type': 'conditionType',
|
|
@@ -944,7 +779,8 @@ const COLLECT_ORDER_FLAGS = { sort: 'sort' };
|
|
|
944
779
|
/** 条件回显用的中文名(控制台与「没有符合条件的待办」文案共用一套,避免两处叫法不一致)。 */
|
|
945
780
|
const FILTER_FLAG_LABELS = {
|
|
946
781
|
workflow: '工作流', workflowTerm: '工作流匹配', creator: '发起人', creatorDept: '发起部门',
|
|
947
|
-
creatorSubcom: '发起分部',
|
|
782
|
+
creatorSubcom: '发起分部', unoperator: '未操作者', sourceUserid: '来源',
|
|
783
|
+
creatorcode: '发起人工号', creatorcodeTerm: '工号匹配', workflowType: '工作流类型', requestName: '标题', requestNameTerm: '标题匹配',
|
|
948
784
|
requestMark: '流程编号', requestMarkTerm: '编号匹配', requestLevel: '紧急程度',
|
|
949
785
|
requestId: '指定流程', exRequestId: '排除流程', nodeId: '当前节点', nodeIdTerm: '节点匹配',
|
|
950
786
|
flowStatus: '流程状态', flowStatusTerm: '状态匹配', createTime: '发起时间',
|
|
@@ -999,17 +835,37 @@ function printClarification(data, dir) {
|
|
|
999
835
|
console.log(lines.join('\n'));
|
|
1000
836
|
}
|
|
1001
837
|
|
|
838
|
+
function readOutputLimit(args, outputMode) {
|
|
839
|
+
const maximum = outputMode === 'query' ? 1000 : 100;
|
|
840
|
+
const limit = args.limit === undefined ? (outputMode === 'query' ? 500 : 100) : Number(args.limit);
|
|
841
|
+
if (args.limit === true || !Number.isInteger(limit) || limit < 1 || limit > maximum) {
|
|
842
|
+
console.error('✖ %s --limit 必须是 1~%d 的整数;默认 %d。', outputMode, maximum, outputMode === 'query' ? 500 : 100);
|
|
843
|
+
process.exit(1);
|
|
844
|
+
}
|
|
845
|
+
return limit;
|
|
846
|
+
}
|
|
847
|
+
|
|
1002
848
|
function cmdPrep(args) {
|
|
1003
|
-
const
|
|
849
|
+
const outputMode = args._query === true ? 'query' : 'summary';
|
|
850
|
+
const limit = readOutputLimit(args, outputMode);
|
|
1004
851
|
const days = Number(args.days || 0);
|
|
1005
852
|
const exclude = args.exclude && args.exclude !== true ? String(args.exclude).split(',').map((x) => x.trim()).filter(Boolean) : [];
|
|
1006
|
-
const dir = args.out && args.out !== true ? String(args.out) :
|
|
853
|
+
const dir = args.out && args.out !== true ? String(args.out) : fs.mkdtempSync(path.join(os.tmpdir(), 'todo-summary-'));
|
|
1007
854
|
fs.mkdirSync(dir, { recursive: true });
|
|
1008
855
|
|
|
856
|
+
// prep 开始一次新查询;旧成品与回填状态不能充当本次结果。
|
|
857
|
+
// 保留到独立目录,finish/build 仍使用本次目录中的新状态。
|
|
858
|
+
const previousFiles = [
|
|
859
|
+
'final.data.json', 'reply.md', 'need-summaries.json', 'need-group-summaries.json',
|
|
860
|
+
'smartgroup.json', 'aiGroups.json', 'state.json', 'items.json',
|
|
861
|
+
].filter((name) => fs.existsSync(path.join(dir, name)));
|
|
862
|
+
if (previousFiles.length) {
|
|
863
|
+
const previousDir = fs.mkdtempSync(path.join(dir, '.previous-'));
|
|
864
|
+
for (const name of previousFiles) fs.renameSync(path.join(dir, name), path.join(previousDir, name));
|
|
865
|
+
}
|
|
866
|
+
|
|
1009
867
|
const startedAt = nowIso();
|
|
1010
|
-
|
|
1011
|
-
const input = { stage: 'collect' };
|
|
1012
|
-
if (limit > 0) input.limit = limit;
|
|
868
|
+
const input = { stage: 'collect', outputMode, limit };
|
|
1013
869
|
// 2026-11-11 用户定稿:排除清单必须进 CLI 查询条件——首轮 getTodoListTotal 要带上
|
|
1014
870
|
// 提示词中的**完整条件**(含排除项),否则交付正文的「您共 X 条待办」与实际纳入条数
|
|
1015
871
|
// 口径对不上(实测 223 vs 53)。本地剔除保留作兜底(正常情况下 CLI 已排除,dropped=0)。
|
|
@@ -1029,6 +885,18 @@ function cmdPrep(args) {
|
|
|
1029
885
|
if (args['sub-category'] && args['sub-category'] !== true) {
|
|
1030
886
|
input.subCategory = String(args['sub-category']);
|
|
1031
887
|
}
|
|
888
|
+
// 2026-11-16 审批 → 待处理:用户提示词含「审批」类限定表述(需要我审批 / 要我审批 / 等我审批 /
|
|
889
|
+
// 待我审批 / 需我审批 / 我待审批)时,语义上就是小分类「待处理」(tabid=7)——SKILL 的待办判定
|
|
890
|
+
// 把这些说法算作待办,但小分类规则只认字面「待处理」,导致走成 tabid=0(全部),把待阅/抄送/
|
|
891
|
+
// 传阅这类无需审批的条目也取回来(2026-11-16 用户实测)。仅在用户未显式指定小分类/tabid 时
|
|
892
|
+
// 自动注入;显式 --sub-category / --tabid 优先。审批**动作指令**("帮我审批通过单号xxx")不进
|
|
893
|
+
// 汇总链路,不受此映射影响;"我审批过的/我已审批"是已办语义,也不在词表内。
|
|
894
|
+
if (input.subCategory === undefined && input.tabid === undefined && args.prompt && args.prompt !== true) {
|
|
895
|
+
if (/(需要我审批|要我审批|等我审批|待我审批|需我审批|我待审批)/.test(String(args.prompt))) {
|
|
896
|
+
input.subCategory = '待处理';
|
|
897
|
+
console.log('审批类表述 → 自动限定小分类「待处理」(tabid=7),只取需要您操作审批的条目(显式指定其它小分类时不生效)');
|
|
898
|
+
}
|
|
899
|
+
}
|
|
1032
900
|
// 2026-11-02:小分类的等价直传入口。显式 tabid 优先级高于 subCategory/tabName
|
|
1033
901
|
// (CLI buildSearchQuery:先解析 subCategory/tabName,再用显式 tabid 覆盖)。
|
|
1034
902
|
// 仅影响本次汇总取数范围,不触碰 workflow.search 的默认行为。
|
|
@@ -1052,7 +920,7 @@ function cmdPrep(args) {
|
|
|
1052
920
|
} else if (days > 0) {
|
|
1053
921
|
const end = new Date();
|
|
1054
922
|
const start = new Date(end.getTime() - days * 24 * 3600 * 1000);
|
|
1055
|
-
const fmtDate = (d) => d.
|
|
923
|
+
const fmtDate = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
1056
924
|
input.receiveTime = `${fmtDate(start)} ${fmtDate(end)}`;
|
|
1057
925
|
}
|
|
1058
926
|
// 2026-11-06:筛选条件直通(编号 / 状态 / 节点 / 发起人 / 发起·办结时间 / 表单字段…)。
|
|
@@ -1084,8 +952,10 @@ function cmdPrep(args) {
|
|
|
1084
952
|
const collectMs = collectStep && Number.isFinite(collectStep.durationMs) ? collectStep.durationMs : collectWallMs;
|
|
1085
953
|
|
|
1086
954
|
const all = collect.data.items || [];
|
|
1087
|
-
const
|
|
1088
|
-
|
|
955
|
+
const filtered = exclude.length ? all.filter((row) => !exclude.includes(String(row.workflowName || ''))) : all;
|
|
956
|
+
// 旧 collect 的 limit 可能按整页停止;两类入口都在此严格限制交付/AI 处理条数。
|
|
957
|
+
const kept = filtered.slice(0, limit);
|
|
958
|
+
const dropped = all.length - filtered.length;
|
|
1089
959
|
|
|
1090
960
|
// 取数条件回显(2026-11-06):条件被静默丢弃时结果看不出异常,所以既打印也落盘。
|
|
1091
961
|
const appliedFilters = Object.entries(COLLECT_FILTER_FLAGS)
|
|
@@ -1128,11 +998,12 @@ function cmdPrep(args) {
|
|
|
1128
998
|
const workflowNameById = new Map();
|
|
1129
999
|
for (const row of all) workflowNameById.set(String(row.requestId || ''), String(row.workflowName || ''));
|
|
1130
1000
|
const isExcluded = (row) => exclude.includes(workflowNameById.get(String(row.requestId || '')) || '');
|
|
1001
|
+
const keptIds = new Set(kept.map((row) => String(row.requestId || '')));
|
|
1131
1002
|
|
|
1132
1003
|
const planGroups = [];
|
|
1133
1004
|
for (const group of collect.data.wfIdGroup || []) {
|
|
1134
1005
|
if (exclude.includes(String(group.title))) continue;
|
|
1135
|
-
const rows = (group.requestDatas || []).filter((row) => !isExcluded(row));
|
|
1006
|
+
const rows = (group.requestDatas || []).filter((row) => keptIds.has(String(row.requestId || '')) && !isExcluded(row));
|
|
1136
1007
|
if (rows.length === 0) continue;
|
|
1137
1008
|
planGroups.push({
|
|
1138
1009
|
groupId: String(group.id),
|
|
@@ -1169,7 +1040,13 @@ function cmdPrep(args) {
|
|
|
1169
1040
|
}
|
|
1170
1041
|
|
|
1171
1042
|
fs.writeFileSync(path.join(dir, 'state.json'), JSON.stringify({
|
|
1172
|
-
dir, startedAt, limit, days, from: args.from || null, to: args.to || null, exclude, subCategory: input.subCategory || null, collectMs, collectWallMs,
|
|
1043
|
+
dir, startedAt, outputMode, limit, days, from: args.from || null, to: args.to || null, exclude, subCategory: input.subCategory || null, collectMs, collectWallMs,
|
|
1044
|
+
// 记录本次取数实际能力,降级范围仍以 queryMeta/degrade 为准。后续进程会重新探测入口。
|
|
1045
|
+
cliCapabilities: { outputMode: supportsOutputMode() },
|
|
1046
|
+
// 编排标记(2026-11-16 入口自检):build/finish 只允许消费由本脚本 run 产出的目录;
|
|
1047
|
+
// 直调 CLI 裸 stage 的目录没有该标记,会被入口校验拒绝(--allow-manual 可临时放行调试)。
|
|
1048
|
+
run: true,
|
|
1049
|
+
demo: collect.meta?.demo === true,
|
|
1173
1050
|
// 取数条件回显(2026-11-06):条件被静默丢弃时结果看不出异常,落盘一份便于核对「传了没生效」。
|
|
1174
1051
|
filters: Object.fromEntries(Object.entries(COLLECT_FILTER_FLAGS)
|
|
1175
1052
|
.map(([, key]) => [key, input[key]])
|
|
@@ -1180,8 +1057,11 @@ function cmdPrep(args) {
|
|
|
1180
1057
|
groupFocus: args.focus && args.focus !== true ? String(args.focus) : null,
|
|
1181
1058
|
summaryMaxChars: args["summary-chars"] ? Number(args["summary-chars"]) : null,
|
|
1182
1059
|
groupSummaryMaxChars: args["group-summary-chars"] ? Number(args["group-summary-chars"]) : null,
|
|
1060
|
+
// 用户本轮完整提示词(2026-11-13):finish 落库时作为 queryPrompt 存 E10 服务端
|
|
1061
|
+
prompt: args.prompt && args.prompt !== true ? String(args.prompt) : null,
|
|
1183
1062
|
ruleFp: ruleFingerprint(),
|
|
1184
1063
|
fetched: all.length, kept: kept.length, dropped,
|
|
1064
|
+
queryMeta: collect.data.query || {}, truncated: filtered.length - kept.length,
|
|
1185
1065
|
planGroups,
|
|
1186
1066
|
}));
|
|
1187
1067
|
fs.writeFileSync(path.join(dir, 'items.json'), JSON.stringify(kept, null, 2));
|
|
@@ -1196,13 +1076,14 @@ function cmdPrep(args) {
|
|
|
1196
1076
|
.join('|'));
|
|
1197
1077
|
}
|
|
1198
1078
|
if (input.sort) console.log('排序:%s', String(input.sort));
|
|
1199
|
-
//
|
|
1079
|
+
// 无时间条件且超过本模式阈值时,原样回显 CLI 实际采用的降级链。
|
|
1200
1080
|
const degrade = collect.data && collect.data.query && collect.data.query.degrade;
|
|
1201
1081
|
if (degrade && degrade.applied) {
|
|
1202
1082
|
console.log('降级(阈值 %s):%s', degrade.threshold,
|
|
1203
1083
|
(degrade.steps || []).map((s) => `${s.scope}=${s.total === null ? '未知' : s.total}`).join(' → '));
|
|
1204
1084
|
}
|
|
1205
1085
|
console.log('输出目录:%s\n', dir);
|
|
1086
|
+
if (args._query === true) return;
|
|
1206
1087
|
const focusKinds = focusCoversKinds(args.focus && args.focus !== true ? args.focus : '');
|
|
1207
1088
|
// 规则里 focus:false 的组**必须**由模型给 aiGroups(如 安全问题处理工单),prep 阶段就标出来,
|
|
1208
1089
|
// 不要等 build 报 ai_groups_required 才知道(2026-11-01 用户确认的规范缺陷)。
|
|
@@ -1253,8 +1134,33 @@ function cmdPrep(args) {
|
|
|
1253
1134
|
console.log('(写 aiGroups 时给 needAI:true 的组带上 summary 字段,分组+组摘要在同一轮拿到,不用再跑一次组摘要)');
|
|
1254
1135
|
}
|
|
1255
1136
|
|
|
1137
|
+
/**
|
|
1138
|
+
* 入口自检(2026-11-16):build/finish 只允许消费由本脚本 run 产出的目录。
|
|
1139
|
+
* 背景:弱模型绕过编排脚本、手动直调 CLI 裸 stage(collect→smartGroup→summaryContext),
|
|
1140
|
+
* 永远到不了 finish,还会陷入 items_required/input_conflict 的补参数循环。
|
|
1141
|
+
* 直调 CLI 的目录没有 run 标记(state.json 由本脚本创建)⇒ 在这里结构性拦住并给出正路。
|
|
1142
|
+
* 开发调试确需手动分阶段时,加 --allow-manual 临时放行。
|
|
1143
|
+
*/
|
|
1144
|
+
function guardOrchestrated(args, dir, cmdName) {
|
|
1145
|
+
if (args['allow-manual'] === true) return;
|
|
1146
|
+
const stateFile = path.join(dir, 'state.json');
|
|
1147
|
+
if (!fs.existsSync(stateFile)) {
|
|
1148
|
+
console.error('✖ 目录 %s 下没有 state.json:%s 阶段只允许消费编排脚本 run 产出的目录。', dir, cmdName);
|
|
1149
|
+
console.error(' → 待办汇总交付请改用一键入口重新进入:node tools/todo-summary.cjs run [--unoperator 人员] --prompt "用户完整提示词"');
|
|
1150
|
+
console.error(' → 开发调试确需手动分阶段的,可临时加 --allow-manual 跳过本校验。');
|
|
1151
|
+
process.exit(1);
|
|
1152
|
+
}
|
|
1153
|
+
const state = readJson(stateFile);
|
|
1154
|
+
if (state.run !== true) {
|
|
1155
|
+
console.error('✖ %s 的 state.json 缺少编排标记(run=true):该目录不是由本脚本 run 产出的,交付链路不完整。', dir);
|
|
1156
|
+
console.error(' → 请改用一键入口重新进入:node tools/todo-summary.cjs run …;开发调试可临时加 --allow-manual 跳过本校验。');
|
|
1157
|
+
process.exit(1);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1256
1161
|
function cmdBuild(args) {
|
|
1257
1162
|
const dir = String(args.dir);
|
|
1163
|
+
guardOrchestrated(args, dir, 'build');
|
|
1258
1164
|
const planFile = args.plan !== undefined && args.plan !== true ? String(args.plan) : '';
|
|
1259
1165
|
const state = readJson(path.join(dir, 'state.json'));
|
|
1260
1166
|
const kept = readJson(path.join(dir, 'items.json'));
|
|
@@ -1300,6 +1206,7 @@ function cmdBuild(args) {
|
|
|
1300
1206
|
const t = Date.now();
|
|
1301
1207
|
const sg = runStage({
|
|
1302
1208
|
stage: 'smartGroup',
|
|
1209
|
+
outputMode: state.outputMode || 'summary',
|
|
1303
1210
|
// 2026-11-03:本阶段只做 workflowName 首次分组 + 平铺结构(二次分组在 finish 的 subGroup)。
|
|
1304
1211
|
items: kept,
|
|
1305
1212
|
withDetailContext: true,
|
|
@@ -1345,6 +1252,7 @@ function cmdBuild(args) {
|
|
|
1345
1252
|
|
|
1346
1253
|
function cmdFinish(args) {
|
|
1347
1254
|
const dir = String(args.dir);
|
|
1255
|
+
guardOrchestrated(args, dir, 'finish');
|
|
1348
1256
|
const state = readJson(path.join(dir, 'state.json'));
|
|
1349
1257
|
const kept = readJson(path.join(dir, 'items.json'));
|
|
1350
1258
|
// `aiGroups.json` 可能不存在(build 没传 --plan 时就是确定性分组),此时按「未传 aiGroups」处理。
|
|
@@ -1365,6 +1273,7 @@ function cmdFinish(args) {
|
|
|
1365
1273
|
const t = Date.now();
|
|
1366
1274
|
const result = runStage({
|
|
1367
1275
|
stage: 'summary',
|
|
1276
|
+
outputMode: state.outputMode || 'summary',
|
|
1368
1277
|
items: kept,
|
|
1369
1278
|
...(aiGroups !== undefined ? { aiGroups } : {}),
|
|
1370
1279
|
withDetailContext: true,
|
|
@@ -1411,6 +1320,7 @@ function cmdFinish(args) {
|
|
|
1411
1320
|
.map((x) => ({ groupId: x.groupId || x.id, summary: x.summary }));
|
|
1412
1321
|
const t2 = Date.now();
|
|
1413
1322
|
const gs = runStage({
|
|
1323
|
+
outputMode: state.outputMode || 'summary',
|
|
1414
1324
|
smartSummaryTitle: result.data.smartSummaryTitle,
|
|
1415
1325
|
totalCount: result.data.totalCount,
|
|
1416
1326
|
wfIdGroup: result.data.wfIdGroup,
|
|
@@ -1446,15 +1356,11 @@ function cmdFinish(args) {
|
|
|
1446
1356
|
}
|
|
1447
1357
|
}
|
|
1448
1358
|
}
|
|
1449
|
-
// 2026-
|
|
1450
|
-
//
|
|
1451
|
-
const serveOption = args['no-serve'] === true
|
|
1452
|
-
? false
|
|
1453
|
-
: (args.serve === undefined ? true : args.serve);
|
|
1359
|
+
// 2026-11-13 用户定稿:产物经 CLI smartGroupAdd 落 E10 服务端,载荷只带落库 id;
|
|
1360
|
+
// 本地 serve / --no-serve 内联回退已删除——落库失败即中断,无回退形态。
|
|
1454
1361
|
exportFinal(finalResult, dir, state, kept, {
|
|
1455
1362
|
timingReport: args['timing-report'],
|
|
1456
|
-
|
|
1457
|
-
serve: serveOption,
|
|
1363
|
+
queryPrompt: state.prompt || '',
|
|
1458
1364
|
// 交付硬闸门(2026-11-01):空摘要 / 详情取数失败都要显式豁免才能出文件。
|
|
1459
1365
|
// 详情取数发生在 smartGroup 阶段 ⇒ failed 从 smartgroup.json 的 data.summaryStats 取。
|
|
1460
1366
|
allowEmptySummary: args['allow-empty-summary'] === true,
|
|
@@ -1477,14 +1383,14 @@ function cmdFinish(args) {
|
|
|
1477
1383
|
function cmdRun(args) {
|
|
1478
1384
|
const dir = args.out && args.out !== true
|
|
1479
1385
|
? String(args.out)
|
|
1480
|
-
:
|
|
1386
|
+
: fs.mkdtempSync(path.join(os.tmpdir(), 'todo-summary-'));
|
|
1481
1387
|
// collect 空结果已在 prep 里给出用户文案并结束(EMPTY),不再进 build/finish
|
|
1482
1388
|
const prepResult = cmdPrep({ ...args, out: dir });
|
|
1483
1389
|
// EMPTY=确实没有匹配数据;CLARIFICATION=名称/字段没对上(**查询没执行**)——两者都不进 build。
|
|
1484
1390
|
if (prepResult === 'EMPTY' || prepResult === 'CLARIFICATION') return;
|
|
1485
1391
|
cmdBuild({ ...args, dir });
|
|
1486
1392
|
// 无待写摘要时 cmdBuild 已经内部走完 cmdFinish(含满意度标题填充与交付闸门),这里直接收工
|
|
1487
|
-
if (fs.existsSync(path.join(dir, '
|
|
1393
|
+
if (fs.existsSync(path.join(dir, 'reply.md'))) return;
|
|
1488
1394
|
// build→finish 已把组摘要素材落盘并停下(NEEDS_GROUP_SUMMARIES,exit 0)⇒ 不再重复跑 finish,
|
|
1489
1395
|
// 也不再重复打印(cmdFinish 刚打过完整指引),静默收工(2026-11-02 P2)。
|
|
1490
1396
|
if (fs.existsSync(path.join(dir, 'need-group-summaries.json'))) return;
|
|
@@ -1500,22 +1406,99 @@ function cmdRun(args) {
|
|
|
1500
1406
|
dir,
|
|
1501
1407
|
'timing-report': args['timing-report'],
|
|
1502
1408
|
'group-summaries': args['group-summaries'],
|
|
1503
|
-
serve: args.serve,
|
|
1504
|
-
'no-serve': args['no-serve'],
|
|
1505
1409
|
'allow-empty-summary': args['allow-empty-summary'] === true,
|
|
1506
1410
|
'allow-detail-fail': args['allow-detail-fail'] === true,
|
|
1507
1411
|
});
|
|
1508
1412
|
}
|
|
1509
1413
|
|
|
1414
|
+
/** 普通查询复用组件协议,但不调用任何 AI 摘要、组摘要或二次分组阶段。 */
|
|
1415
|
+
function cmdQuery(args) {
|
|
1416
|
+
const limit = readOutputLimit(args, 'query');
|
|
1417
|
+
const dir = args.out && args.out !== true
|
|
1418
|
+
? String(args.out)
|
|
1419
|
+
: fs.mkdtempSync(path.join(os.tmpdir(), 'todo-query-'));
|
|
1420
|
+
const prepResult = cmdPrep({
|
|
1421
|
+
...args, out: dir, limit, _query: true,
|
|
1422
|
+
// 这些是摘要/二次分组偏好,不是查询条件,不让 collect 为它们准备 AI 素材。
|
|
1423
|
+
focus: undefined, 'summary-chars': undefined, 'group-summary-chars': undefined,
|
|
1424
|
+
});
|
|
1425
|
+
if (prepResult === 'EMPTY' || prepResult === 'CLARIFICATION') return;
|
|
1426
|
+
const state = readJson(path.join(dir, 'state.json'));
|
|
1427
|
+
const kept = readJson(path.join(dir, 'items.json'));
|
|
1428
|
+
const grouped = runStage({ stage: 'smartGroup', outputMode: 'query', items: kept, withDetailContext: false }, dir, 'smartgroup');
|
|
1429
|
+
const seen = new Set();
|
|
1430
|
+
const wfIdGroup = [];
|
|
1431
|
+
for (const group of grouped.data.wfIdGroup || []) {
|
|
1432
|
+
// smartGroup 的首次分组是按工作流平铺;query 不创建优先组或复制优先规则解释器。
|
|
1433
|
+
if (group.topPriority === true || group.id === 'priority') continue;
|
|
1434
|
+
const displayItems = [];
|
|
1435
|
+
for (const item of group.displayItems || []) {
|
|
1436
|
+
for (const source of item.type === 'request' ? [item.requestData] : (item.requestDatas || [])) {
|
|
1437
|
+
if (!source || !source.requestId || seen.has(String(source.requestId))) continue;
|
|
1438
|
+
const requestData = { ...source, summary: '' };
|
|
1439
|
+
delete requestData._rawFields;
|
|
1440
|
+
seen.add(String(requestData.requestId));
|
|
1441
|
+
displayItems.push({ type: 'request', requestData });
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
if (displayItems.length) {
|
|
1445
|
+
wfIdGroup.push({
|
|
1446
|
+
id: group.id, title: group.title, count: displayItems.length,
|
|
1447
|
+
topPriority: false, defaultExpanded: true, displayItems,
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
const expectedIds = new Set(kept.map((row) => String(row.requestId || '')).filter(Boolean));
|
|
1452
|
+
if (seen.size !== expectedIds.size || [...expectedIds].some((id) => !seen.has(id))) {
|
|
1453
|
+
console.error('✖ 普通查询结构校验失败:工作流清单未完整覆盖本次查询条目,停止交付。');
|
|
1454
|
+
process.exit(1);
|
|
1455
|
+
}
|
|
1456
|
+
const count = seen.size;
|
|
1457
|
+
const payload = { smartSummaryTitle: `本次为您查询${count}条待办,清单如下:`, totalCount: count, wfIdGroup };
|
|
1458
|
+
const baseUrl = resolveBaseUrl(state, dir);
|
|
1459
|
+
const smartGroupId = persistPayload(payload, dir, state.prompt);
|
|
1460
|
+
const queryMeta = state.queryMeta || {};
|
|
1461
|
+
const degradeSteps = state.degrade && Array.isArray(state.degrade.steps) ? state.degrade.steps : [];
|
|
1462
|
+
const currentStep = state.degrade && state.degrade.applied ? degradeSteps[degradeSteps.length - 1] : degradeSteps[0];
|
|
1463
|
+
// 列表可能不带 total;只用相同查询范围的计数兜底,终点级不能借用原范围的首轮总数。
|
|
1464
|
+
const totals = [queryMeta.totalAvailable, currentStep && currentStep.total]
|
|
1465
|
+
.filter((value) => value !== null && value !== undefined && String(value).trim() !== '')
|
|
1466
|
+
.map(Number);
|
|
1467
|
+
const total = state.dropped > 0 ? null : (totals.find((value) => Number.isInteger(value) && value >= count) ?? null);
|
|
1468
|
+
const lines = [];
|
|
1469
|
+
if (state.degrade && state.degrade.applied) {
|
|
1470
|
+
const scope = describeDegradeWindow(state.degrade).replace('内到达', '到达').replace('近1个月', '近一个月');
|
|
1471
|
+
const first = degradeSteps[0];
|
|
1472
|
+
const initial = first && first.total !== null && first.total !== undefined ? Number(first.total) : null;
|
|
1473
|
+
const prefix = !state.dropped && initial !== null && Number.isInteger(initial) && initial >= count
|
|
1474
|
+
? `原条件共匹配${initial}条待办;` : '';
|
|
1475
|
+
lines.push(`${prefix}本次查询${scope}的待办,已展示${count}条。`);
|
|
1476
|
+
} else {
|
|
1477
|
+
lines.push(total !== null && total > count
|
|
1478
|
+
? `本次共查询到${total}条待办,已展示${count}条,清单如下:`
|
|
1479
|
+
: `本次展示${count}条待办,清单如下:`);
|
|
1480
|
+
}
|
|
1481
|
+
if (total !== null && total > count) lines.push(`本次展示范围内还有${total - count}条未展示。`);
|
|
1482
|
+
else if (total === null && (count >= limit || state.truncated > 0)) lines.push(`本次最多展示${limit}条,尚未确认是否已覆盖全部。`);
|
|
1483
|
+
const delivery = `<browsertool>\n${wrapBrowseToolPayload(baseUrl, smartGroupId).trimEnd()}\n</browsertool>`;
|
|
1484
|
+
const replyBody = [...lines, '', delivery].join('\n');
|
|
1485
|
+
fs.writeFileSync(path.join(dir, 'final.data.json'), JSON.stringify(payload));
|
|
1486
|
+
fs.writeFileSync(path.join(dir, 'reply.md'), replyBody);
|
|
1487
|
+
console.log('\n[JSON_BEGIN]\n%s\n[JSON_END]', replyBody);
|
|
1488
|
+
console.log('交付正文已落盘:%s(原样粘贴正文与 browsertool,勿改写为旧卡片列表)', path.join(dir, 'reply.md'));
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1510
1491
|
const args = parseArgs(process.argv.slice(2));
|
|
1511
1492
|
const cmd = args._[0];
|
|
1512
|
-
if (cmd === '
|
|
1493
|
+
if (cmd === 'query') cmdQuery(args);
|
|
1494
|
+
else if (cmd === 'prep') cmdPrep(args);
|
|
1513
1495
|
else if (cmd === 'build') cmdBuild(args);
|
|
1514
1496
|
else if (cmd === 'finish') cmdFinish(args);
|
|
1515
1497
|
else if (cmd === 'run') cmdRun(args);
|
|
1516
1498
|
else {
|
|
1517
|
-
console.log('用法:node ' + path.basename(__filename) + ' <run|prep|build|finish> [options]');
|
|
1518
|
-
console.log('
|
|
1499
|
+
console.log('用法:node ' + path.basename(__filename) + ' <query|run|prep|build|finish> [options]');
|
|
1500
|
+
console.log(' query [--limit 500] [筛选条件] [--out DIR] [--prompt "用户完整提示词"] # 标题清单组件,不生成 AI 摘要或二次分组;limit 为 1~1000,默认 500');
|
|
1501
|
+
console.log(' run [--days N | --from A --to B] [--limit 100] [--out DIR] [--timing-report] [--prompt "用户完整提示词"] # 摘要默认/最多100条,较小可降低;未指定时间时按 CLI 实际规则收窄范围');
|
|
1519
1502
|
console.log(' prep --limit 100 [--exclude 内部留言] [--days 1460] [--sub-category 待处理] [--tabid 7] [--isremarks 1,2] [--out DIR] # 小分类:--sub-category/--tabid(显式 tabid 优先);isremarks=备注筛选(数字逗号拼接)');
|
|
1520
1503
|
console.log(' build --dir DIR [--plan aiGroups.json] # aiGroups 可先落盘(不传也行):build 只做首次分组+平铺,二次分组在 finish');
|
|
1521
1504
|
console.log(' finish --dir DIR [--summaries aiSummaries.json] [--group-summaries aiGroupSummaries.json] [--timing-report]');
|
|
@@ -1524,7 +1507,9 @@ else {
|
|
|
1524
1507
|
console.log(' 组摘要未回填:以 exit 0 + NEEDS_GROUP_SUMMARIES 返回(不导出),完整素材在 <out>/need-group-summaries.json;');
|
|
1525
1508
|
console.log(' 在该文件补 summary 后用 --group-summaries 指回它重跑。真失败(空摘要/降级话术/要素缺失/详情失败)仍 exit 1;');
|
|
1526
1509
|
console.log(' 豁免:--allow-empty-summary / --allow-detail-fail');
|
|
1527
|
-
console.log(' 默认:载荷只带 params.
|
|
1510
|
+
console.log(' 默认:载荷只带 params.data.id(smartgroup/add 落库主键);本地 serve 与 --no-serve 内联回退已于 2026-11-13 删除');
|
|
1511
|
+
console.log(' 落库:finish 导出前调 POST /api/workflow/list/smartgroup/add(queryTypeId=todo_smart_group);失败即 exit 1,不降级');
|
|
1512
|
+
console.log(' queryPrompt:run/prep 传 --prompt "用户完整提示词",落库时存 queryPrompt(不传为空串)');
|
|
1528
1513
|
console.log(' 提示:`--timing-report` 会在控制台打一段耗时摘要(阶段墙钟 / CLI 内部),**不产出 md**');
|
|
1529
1514
|
process.exit(2);
|
|
1530
1515
|
}
|