weaver-work-cli 0.1.52 → 0.1.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/chunks/{attachment-content-MBYYSQIX.js → attachment-content-W3TSJC3Y.js} +3 -3
  2. package/dist/chunks/{chunk-D3TDNRFE.js → chunk-2J3XY4ED.js} +7 -7
  3. package/dist/chunks/{chunk-IRMA3GVP.js → chunk-6GCXWKG6.js} +1 -1
  4. package/dist/chunks/{chunk-KLZ3ULQQ.js → chunk-76PRVYH4.js} +1 -1
  5. package/dist/chunks/{chunk-7UOXOGFL.js → chunk-DEHJ7PMA.js} +4 -4
  6. package/dist/chunks/{chunk-DZOC77ZD.js → chunk-IF33CG4V.js} +1 -1
  7. package/dist/chunks/{chunk-LTRLF6MM.js → chunk-PE334WL3.js} +4 -4
  8. package/dist/chunks/{chunk-RWFRZSIP.js → chunk-QQXMHM3J.js} +2 -2
  9. package/dist/chunks/{chunk-RPRFIG6I.js → chunk-U7ROML5E.js} +23 -23
  10. package/dist/chunks/{chunk-ZRHKGQRQ.js → chunk-WTLQGS6D.js} +2 -2
  11. package/dist/chunks/{chunk-LALWNK6M.js → chunk-XPQN4E5O.js} +41 -19
  12. package/dist/chunks/{chunk-LM2H7SZI.js → chunk-Z4G7LLDD.js} +25 -25
  13. package/dist/chunks/{conflict-D2HYKBMH.js → conflict-57WDJWL7.js} +2 -2
  14. package/dist/chunks/{contract-MFOFMM2J.js → contract-LJRAXVZU.js} +5448 -1857
  15. package/dist/chunks/{create-flow-7ZATJVTM.js → create-flow-3FMMZBCA.js} +6 -6
  16. package/dist/chunks/{env-5DO4YENS.js → env-JYZE3BZB.js} +2 -2
  17. package/dist/chunks/{factory-3M7D7WJC.js → factory-66SCIKW3.js} +1 -1
  18. package/dist/chunks/{group-chat-B2HT5NEO.js → group-chat-MNRYMLNG.js} +3 -3
  19. package/dist/chunks/{meeting-HZOX3CBB.js → meeting-IIY4UAJL.js} +10 -10
  20. package/dist/chunks/{registry-KYPFFQIH.js → registry-CJOVECZD.js} +1 -1
  21. package/dist/chunks/{registry-SJHSBO5G.js → registry-METZ2LWE.js} +10 -10
  22. package/dist/chunks/{room-recommend-5AHR4YQV.js → room-recommend-YFY7HTOF.js} +4 -4
  23. package/dist/chunks/{schedule-KZPJUPC2.js → schedule-6I63TERA.js} +4 -4
  24. package/dist/chunks/{smart-extract-IXHCZE4R.js → smart-extract-FOUYNIG3.js} +44 -8
  25. package/dist/chunks/{workflow-UHKCZJMY.js → workflow-YHXFIU63.js} +1 -1
  26. package/dist/index.js +4 -4
  27. package/dist/shortcuts/contract/manifest.js +105 -5
  28. package/dist/shortcuts/contract/ooxml/docx-table.js +233 -0
  29. package/dist/shortcuts/contract/operations/card-action.js +597 -17
  30. package/dist/shortcuts/contract/operations/card-ebdf-list.js +258 -2
  31. package/dist/shortcuts/contract/operations/card.js +6 -5
  32. package/dist/shortcuts/contract/operations/docx-fillfromquote.js +532 -0
  33. package/dist/shortcuts/contract/operations/docx-verify.js +258 -0
  34. package/dist/shortcuts/contract/operations/elements-build.js +47 -0
  35. package/dist/shortcuts/contract/operations/first-screen.js +28 -3
  36. package/dist/shortcuts/contract/operations/ledger.js +438 -0
  37. package/dist/shortcuts/contract/operations/performance.js +104 -3
  38. package/dist/shortcuts/contract/operations/quotescreen.js +529 -0
  39. package/dist/shortcuts/contract/operations/registry.js +10 -0
  40. package/dist/shortcuts/contract/operations/triage.js +1100 -0
  41. package/dist/shortcuts/smart-extract/operations/fill.js +10 -7
  42. package/dist/shortcuts/smart-extract/operations/validate.js +49 -3
  43. package/dist/shortcuts/workflow/operations/form.js +68 -33
  44. package/docs/smart-extract.md +5 -5
  45. package/package.json +1 -1
  46. package/skills/weaver-e10-jinchengda/SKILL.md +139 -99
  47. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +43 -482
  48. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +7 -8
  49. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +3 -3
  50. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  51. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +32 -16
  52. package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +478 -0
  53. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  54. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +2 -2
  55. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +39 -61
  56. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +13 -9
  57. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +2 -2
  58. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +2 -2
  59. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +3 -3
  60. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +3 -3
  61. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +263 -0
  62. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +525 -0
  63. package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +36 -0
  64. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +1 -1
  65. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +3 -6
  66. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +80 -54
  67. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +53 -76
  68. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +19 -21
  69. package/skills/weaver-e10-jinchengda/references/orchestration.md +12 -12
  70. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1 -6
  71. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +2 -1
  72. package/skills/weaver-e10-smart-extract/SKILL.md +15 -4
  73. package/skills/weaver-e10-smart-extract/references/result-format.md +2 -2
  74. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +2 -1
  75. package/skills/weaver-e10-workflow/references/workflow-create.md +6 -5
  76. package/skills/weaver-e10-workflow/references/workflow-edit.md +1 -1
  77. package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +0 -200
  78. package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +0 -572
  79. package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +0 -560
  80. package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +0 -894
  81. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +0 -598
  82. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +0 -118
@@ -23,7 +23,8 @@ import { planActions } from './card-plan.js';
23
23
  */
24
24
  const DEFAULT_BASE = 'https://www.e-cology.com.cn';
25
25
  const DEFAULT_AIID = '1326842382967570463';
26
- const WIDTH = 1200;
26
+ export const CARD_PANEL_WIDTH = 1300;
27
+ const WIDTH = CARD_PANEL_WIDTH;
27
28
  /** flowKey → workflowId(与 contract-flow-launch.md 保持一致)。 */
28
29
  const FLOW_IDS = new Map([
29
30
  ['契约锁', '100003460000002066'],
@@ -73,14 +74,17 @@ const SEND_TEXT = new Map([
73
74
  ['performance', '查一下这份合同的业绩核算'],
74
75
  ['retry-upload', '换一份文件重新解析'],
75
76
  ]);
76
- const CARD_TPL = "<div id='{dom_id}' role='button' tabindex='0' style='display:flex;align-items:center;gap:12px;"
77
+ // 2026-11-13 用户指定:卡片容器改用原生 <button>,键盘 Enter/Space 由浏览器原生处理,
78
+ // 模板里不再出现任何 keydown 判断(此前 e.key==='Enter' 的 === 在模型手写时易被写成 =,导致 JS 异常)。
79
+ const CARD_TPL = "<button type='button' id='{dom_id}' style='display:flex;align-items:center;gap:12px;"
80
+ + "width:100%;box-sizing:border-box;text-align:left;font-family:inherit;"
77
81
  + "background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;{mb}cursor:pointer'>"
78
82
  + "<span style='flex:0 0 auto;width:44px;height:44px;border-radius:10px;background:#eef1fb;"
79
83
  + "display:flex;align-items:center;justify-content:center'>{icon}</span>"
80
84
  + "<span style='min-width:0'>"
81
85
  + "<span style='display:block;font-size:15px;font-weight:700;color:#1f2430;margin-bottom:6px'>{title}{badge}</span>"
82
86
  + "<span style='display:block;font-size:13px;color:#7a8497;line-height:1.5'>{desc}</span>"
83
- + '</span></div>';
87
+ + '</span></button>';
84
88
  const BADGE = "<span style='font-size:11px;color:#3b6fe0;background:#eaf0fe;border-radius:10px;"
85
89
  + "padding:2px 8px;line-height:1.4;margin-left:8px'>推荐</span>";
86
90
  /** 交互脚本基础件(ES5、零双引号)。 */
@@ -102,8 +106,9 @@ const JS_BASE = "var P=window.xiaoePlugin||(window.rawWindow&&window.rawWindow.x
102
106
  + 'function bind(id,fn){var el=document.getElementById(id);if(!el){return;}el.onclick=fn;'
103
107
  + "el.onmouseenter=function(){el.style.borderColor='#1d6fd8';"
104
108
  + "el.style.boxShadow='0 2px 8px rgba(29,111,216,.12)';};"
105
- + "el.onmouseleave=function(){el.style.borderColor='#e8ebf2';el.style.boxShadow='none';};"
106
- + "el.onkeydown=function(e){if(e.key==='Enter'||e.key===' '){e.preventDefault();fn();}};}";
109
+ + "el.onmouseleave=function(){el.style.borderColor='#e8ebf2';el.style.boxShadow='none';};}";
110
+ // 2026-11-13 用户指定:不再绑定 onkeydown。卡片是原生 <button>,Enter/Space 由浏览器原生触发 click,
111
+ // 模板中因此不含任何 === 比较,避免模型手写时把 === 写成 = 造成 JS 语法异常。
107
112
  /** 内嵌模板(与 references/contract-action-card-template.html 一致)。 */
108
113
  const CARD_TEMPLATE = `<!--
109
114
  行为卡片内层模板(contract-action-card-template.html)
@@ -190,10 +195,11 @@ function buildHandler(action, cfg) {
190
195
  // fieldAssignKeys / initialCovertName:customParams 与 src 两处同值
191
196
  if (keyStr) {
192
197
  cp.push(`fieldAssignKeys:'${keyStr}'`);
193
- cp.push('initialCovertName:1');
194
198
  extraQ.push(`fieldAssignKeys=${keyStr}`);
195
- extraQ.push('initialCovertName=1');
196
199
  }
200
+ // initialCovertName 固定传 1,与 fieldAssignKeys 是否为空无关
201
+ cp.push('initialCovertName:1');
202
+ extraQ.push('initialCovertName=1');
197
203
  }
198
204
  // 逐值拼接,不做整体编码(值均为数字/固定串)
199
205
  if (extraQ.length)
@@ -337,13 +343,440 @@ export function renderActionCard(ctx, cfg, template) {
337
343
  };
338
344
  return { payload, planned: cards.map((card) => String(card.id)), cardCount: count };
339
345
  }
340
- /** 交付前自检:引号、反斜杠、`__W__` 残留、ES5、hover 绑定、脚本语法。 */
341
- export function selfCheckActionCard(payload) {
346
+ /** 交付参数白名单:多出来的键会被宿主静默忽略,是高风险拼写错误。 */
347
+ const KNOWN_TOP_KEYS = new Set(['version', 'callId', 'toolId', 'arguments']);
348
+ const KNOWN_ARG_KEYS = new Set(['type', 'title', 'src', 'width', 'sdkRenderType', 'sdkOptions']);
349
+ /** src → 目标页组件名(与 validate_action_card.py 的 E10_COMP_EXPECT 一致)。 */
350
+ const E10_COMP_EXPECT = [
351
+ ['/sp/contract/business/credit', 'ContractCreditDetail'],
352
+ ['/sp/contract/business/ai-contract', 'AIContractV2'],
353
+ ['/sp/ebdfpage/list/', 'TableViewList'],
354
+ ['/sp/workflow/flowpage/create/', 'Comp.WffpRoute'],
355
+ ['/sp/contract/xiaoe-list', 'XiaoeList'],
356
+ ];
357
+ function eachMatch(re, textValue) {
358
+ const out = [];
359
+ const flags = re.flags.includes('g') ? re.flags : `${re.flags}g`;
360
+ const scan = new RegExp(re.source, flags);
361
+ let hit = scan.exec(textValue);
362
+ while (hit) {
363
+ out.push(hit);
364
+ if (hit[0].length === 0)
365
+ scan.lastIndex += 1;
366
+ hit = scan.exec(textValue);
367
+ }
368
+ return out;
369
+ }
370
+ function countOf(hay, needle) {
371
+ if (!needle)
372
+ return 0;
373
+ let count = 0;
374
+ let at = hay.indexOf(needle);
375
+ while (at !== -1) {
376
+ count += 1;
377
+ at = hay.indexOf(needle, at + needle.length);
378
+ }
379
+ return count;
380
+ }
381
+ /**
382
+ * 深度自检:2026-11-13 从 `scripts/validate_action_card.py` 并入的检查项。
383
+ *
384
+ * 原脚本 511 行、15 项终检,与 `selfCheckActionCard` 已有的引号/反斜杠/ES5/
385
+ * hover/语法存在大量重叠。此处只补「原来没查、但一定会导致交付事故」的项:
386
+ * 外层 JSON 骨架、元素 id 与绑定目标、状态反馈节点、var S 常量、artifact 键、
387
+ * sendQuestion 命名空间、e10Sdk 组件名。重复项由调用方去重,保证一份判据。
388
+ *
389
+ * 与脚本的两处有意差异(均为避免误报):
390
+ * 1) 卡片容器同时认 `<button id=...>` 与 `<div role='button' id=...>`——
391
+ * CLI 生成的卡片是 button,脚本只认 div,照搬会把正常卡片判失败;
392
+ * 2) 双引号允许 0 个,或恰好是 `var S="..."` 的包裹对,其余一律失败。
393
+ */
394
+ export function deepCheckActionCard(payload) {
395
+ const problems = [];
396
+ const warnings = [];
397
+ const checks = [];
398
+ const pass = (item, detail = '') => {
399
+ checks.push({ level: 'PASS', item, detail });
400
+ };
401
+ const fail = (item, detail) => {
402
+ checks.push({ level: 'FAIL', item, detail });
403
+ problems.push(`${item}:${detail}`);
404
+ };
405
+ const warn = (item, detail) => {
406
+ checks.push({ level: 'WARN', item, detail });
407
+ warnings.push(`${item}:${detail}`);
408
+ };
409
+ const eqCheck = (actual, expect, item) => {
410
+ if (actual === expect)
411
+ pass(item);
412
+ else
413
+ fail(item, `期望 ${String(expect)},实际 ${String(actual)}`);
414
+ };
415
+ const args = (payload.arguments ?? {});
416
+ const sdk = (args.sdkOptions ?? {});
417
+ const paramsPc = (sdk.params_pc ?? {});
418
+ const routerPc = (sdk.routerProps_pc ?? {});
419
+ const html = String((paramsPc.customParams ?? {}).html ?? '');
420
+ // ── 外层 JSON 骨架(缺 src / compName / type 时整块不进渲染链路)
421
+ eqCheck(payload.version, 1, 'outer.version == 1');
422
+ if (String(payload.callId ?? '').trim())
423
+ pass('outer.callId 非空');
424
+ else
425
+ fail('outer.callId 非空', '缺失或为空');
426
+ eqCheck(payload.toolId, 'fill_form', "outer.toolId == 'fill_form'");
427
+ eqCheck(args.type, 'e10', "arguments.type == 'e10'");
428
+ const src = String(args.src ?? '');
429
+ if (src.endsWith('/sp/contract/xiaoe-custom-page'))
430
+ pass('arguments.src 指向 xiaoe-custom-page');
431
+ else
432
+ fail('arguments.src 指向 xiaoe-custom-page', `实际 ${src || '<空>'}`);
433
+ eqCheck(args.width, CARD_PANEL_WIDTH, `arguments.width == ${CARD_PANEL_WIDTH}`);
434
+ eqCheck(args.sdkRenderType, 'inline', "arguments.sdkRenderType == 'inline'");
435
+ eqCheck(sdk.compName, 'ui.CorsComponent', "sdkOptions.compName == 'ui.CorsComponent'");
436
+ eqCheck(sdk.routerType, 'MemoryRouter', "sdkOptions.routerType == 'MemoryRouter'");
437
+ if (Array.isArray(routerPc.initialEntries) && routerPc.initialEntries.length > 0) {
438
+ pass('routerProps_pc.initialEntries 非空');
439
+ }
440
+ else {
441
+ fail('routerProps_pc.initialEntries 非空', '缺失或空数组');
442
+ }
443
+ eqCheck(paramsPc.app, '@weapp/contract', "params_pc.app == '@weapp/contract'");
444
+ eqCheck(paramsPc.compName, 'xiaoeCustomPage', "params_pc.compName == 'xiaoeCustomPage'");
445
+ if (html)
446
+ pass('params_pc.customParams.html 存在', `${html.length} 字符`);
447
+ else {
448
+ fail('params_pc.customParams.html 存在', '缺失(摘要点开会是空白页)');
449
+ return { problems, warnings, checks };
450
+ }
451
+ const inner = html.replace(/<!--[\s\S]*?-->/gu, '');
452
+ // ── 摘要承载方式:禁用 textarea(内容会以纯文本泄漏)
453
+ if (inner.toLowerCase().includes('<textarea')) {
454
+ fail('不使用 textarea 承载摘要', 'textarea 会把摘要当纯文本渲染');
455
+ }
456
+ else {
457
+ pass('不使用 textarea 承载摘要');
458
+ }
459
+ // ── 标签配对(内嵌报告的 </script> 可能写成 <\/script>,先归一)
460
+ const normalized = inner.split('<\\/script>').join('</script>');
461
+ for (const tag of ['section', 'script']) {
462
+ const open = countOf(normalized, `<${tag}`);
463
+ const close = countOf(normalized, `</${tag}>`);
464
+ if (open === close && open > 0)
465
+ pass(`<${tag}> 配对`, `${open}`);
466
+ else if (open === 0 && close === 0)
467
+ warn(`<${tag}> 未出现`, '跳过');
468
+ else
469
+ fail(`<${tag}> 配对`, `开 ${open} / 闭 ${close}`);
470
+ }
471
+ // ── 元素 id 唯一 + 事件绑定目标必须存在
472
+ // (历史缺陷:绑定到不存在的 id 会被静默跳过,表现为「点了没反应」)
473
+ const allIds = [];
474
+ for (const hit of eachMatch(/<[a-zA-Z][a-zA-Z0-9]*[^>]*id='([^']+)'/gu, inner)) {
475
+ allIds.push(String(hit[1]));
476
+ }
477
+ const cardIds = [];
478
+ for (const hit of eachMatch(/<(button|div)[^>]*id='([^']+)'[^>]*>/gu, inner)) {
479
+ const tag = String(hit[1]);
480
+ const chunk = String(hit[0]);
481
+ if (tag === 'button' || chunk.includes("role='button'"))
482
+ cardIds.push(String(hit[2]));
483
+ }
484
+ if (cardIds.length === 0) {
485
+ fail('动作卡带 id', '未找到带 id 的 button 或 div[role=button]');
486
+ }
487
+ else if (new Set(cardIds).size !== cardIds.length) {
488
+ fail('卡片 id 唯一', `重复:${cardIds.join(',')}`);
489
+ }
490
+ else {
491
+ pass('卡片 id 唯一', `${cardIds.length} 张`);
492
+ }
493
+ const targets = [];
494
+ for (const hit of eachMatch(/getElementById\('([^']+)'\)/gu, inner))
495
+ targets.push(String(hit[1]));
496
+ for (const hit of eachMatch(/bind\('([^']+)'/gu, inner))
497
+ targets.push(String(hit[1]));
498
+ if (targets.length === 0) {
499
+ fail('事件绑定目标存在', '未找到 getElementById / bind 调用');
500
+ }
501
+ else {
502
+ const missing = [...new Set(targets)].filter((id) => !allIds.includes(id));
503
+ if (missing.length > 0)
504
+ fail('事件绑定目标存在', `缺少 id:${missing.join(',')}`);
505
+ else
506
+ pass('事件绑定目标存在', `${new Set(targets).size} 个`);
507
+ }
508
+ // ── 状态反馈节点(点击失败必须有可见提示,否则静默失效)
509
+ if (inner.includes('data-status') || /id='tip'/u.test(inner)) {
510
+ pass('有可见状态反馈节点');
511
+ }
512
+ else {
513
+ fail('有可见状态反馈节点', '无 data-status / id=tip,失败会静默');
514
+ }
515
+ // ── var S 摘要常量(反斜杠安全转义已由调用方统一检查,这里只查闭合与裸双引号)
516
+ const sAt = inner.indexOf('var S=');
517
+ if (sAt === -1) {
518
+ warn('var S 摘要常量存在', '未找到,跳过常量检查');
519
+ }
520
+ else {
521
+ const closed = /^var S=(['"])([\s\S]*?)\1;/u.exec(inner.slice(sAt));
522
+ if (!closed) {
523
+ fail('var S 常量正确闭合', '找不到闭合引号');
524
+ }
525
+ else {
526
+ const value = String(closed[2]);
527
+ const innerQuotes = countOf(value, '"');
528
+ if (innerQuotes === 0)
529
+ pass('var S 内无裸双引号');
530
+ else
531
+ fail('var S 内无裸双引号', `${innerQuotes} 个,字符串会提前闭合`);
532
+ }
533
+ }
534
+ // ── artifact 必须带 initialArtifactKeys,且与 artifacts[].id 匹配
535
+ if (inner.includes('artifact')) {
536
+ if (!inner.includes('initialArtifactKeys')) {
537
+ fail('artifact 带 initialArtifactKeys', '缺失会导致面板空白或打开错文档');
538
+ }
539
+ else {
540
+ pass('artifact 带 initialArtifactKeys');
541
+ const artIds = [];
542
+ for (const hit of eachMatch(/artifacts:\s*\[\s*\{\s*id:\s*'([^']+)'/gu, inner)) {
543
+ artIds.push(String(hit[1]));
544
+ }
545
+ const keyBlock = /initialArtifactKeys:\s*\[([^\]]*)\]/u.exec(inner);
546
+ if (artIds.length > 0 && keyBlock) {
547
+ const keys = String(keyBlock[1])
548
+ .split(',')
549
+ .map((item) => item.trim().replace(/^['"]|['"]$/gu, ''))
550
+ .filter((item) => item.length > 0);
551
+ if (keys.some((key) => artIds.includes(key)))
552
+ pass('initialArtifactKeys 与 artifacts.id 匹配');
553
+ else
554
+ fail('initialArtifactKeys 与 artifacts.id 匹配', `keys=${keys.join(',')} ids=${artIds.join(',')}`);
555
+ }
556
+ }
557
+ }
558
+ // ── 摘要必须由常量承载(raw.html:S 却无 var S 时点开是空白)
559
+ if (/raw:\s*\{\s*html:\s*S\s*\}/u.test(inner)) {
560
+ if (inner.includes('var S'))
561
+ pass('摘要由 var S 常量承载');
562
+ else
563
+ fail('摘要由 var S 常量承载', 'raw.html:S 但未定义 var S');
564
+ }
565
+ // ── sendQuestion 必须走 session 命名空间且传对象(写成 plugin.sendQuestion 会静默不发)
566
+ const sqCalls = eachMatch(/([A-Za-z0-9_$.]+)\s*\.\s*sendQuestion\s*\(/gu, inner);
567
+ if (sqCalls.length === 0) {
568
+ if (/[^A-Za-z0-9_$.]sendQuestion\s*\(/u.test(inner)) {
569
+ fail('sendQuestion 走 session 命名空间', '存在裸 sendQuestion(...) 调用');
570
+ }
571
+ else {
572
+ pass('sendQuestion 未调用(跳过)');
573
+ }
574
+ }
575
+ else {
576
+ const badNs = sqCalls.filter((hit) => String(hit[1]).split('.').pop() !== 'session');
577
+ if (badNs.length > 0) {
578
+ fail('sendQuestion 走 session 命名空间', `实际 ${badNs.map((hit) => hit[0]).join(', ')}`);
579
+ }
580
+ else {
581
+ pass('sendQuestion 走 session 命名空间', `${sqCalls.length} 处`);
582
+ }
583
+ let badArg = 0;
584
+ for (const hit of sqCalls) {
585
+ const from = (hit.index ?? 0) + hit[0].length;
586
+ const tail = inner.slice(from, from + 200);
587
+ if (!/^\s*\{/u.test(tail) || !/question\s*:/u.test(tail))
588
+ badArg += 1;
589
+ }
590
+ if (badArg > 0)
591
+ fail('sendQuestion 传 {question, files}', `${badArg} 处不是对象字面量`);
592
+ else
593
+ pass('sendQuestion 传 {question, files}');
594
+ }
595
+ // ── e10Sdk 必须带 params.compName 且与 src 对应(漏写时白屏但无 JS 错误)
596
+ const sdkStarts = eachMatch(/type\s*:\s*'e10Sdk'/gu, inner).map((hit) => hit.index ?? 0);
597
+ if (sdkStarts.length === 0) {
598
+ pass('e10Sdk compName(无调用,跳过)');
599
+ }
600
+ else {
601
+ const fails = [];
602
+ sdkStarts.forEach((start, index) => {
603
+ const end = index + 1 < sdkStarts.length ? sdkStarts[index + 1] : Math.min(inner.length, start + 3000);
604
+ const seg = inner.slice(start, end);
605
+ const srcHit = /src\s*:\s*'([^']+)'/u.exec(seg);
606
+ const pageSrc = srcHit ? String(srcHit[1]) : '';
607
+ const inParams = /params\s*:\s*\{[^{}]*?compName\s*:\s*'([^']+)'/u.exec(seg);
608
+ const inParamsPc = /params_pc\s*:\s*\{[^{}]*?compName\s*:\s*'([^']+)'/u.exec(seg);
609
+ const compName = inParams ? String(inParams[1]) : inParamsPc ? String(inParamsPc[1]) : '';
610
+ const expected = E10_COMP_EXPECT.find(([path]) => pageSrc.includes(path))?.[1];
611
+ if (!compName)
612
+ fails.push(`${pageSrc || '<无 src>'} 缺 compName(期望 ${expected || '?'})`);
613
+ else if (expected && compName !== expected)
614
+ fails.push(`${pageSrc} compName=${compName},期望 ${expected}`);
615
+ });
616
+ if (fails.length > 0)
617
+ fail('e10Sdk compName 与 src 对应', fails.join(';'));
618
+ else
619
+ pass('e10Sdk compName 与 src 对应', `${sdkStarts.length} 处`);
620
+ }
621
+ return { problems, warnings, checks };
622
+ }
623
+ /**
624
+ * 内容级自检:2026-11-13 从 `scripts/verify_card_delivery.py` 下沉(脚本已下线)。
625
+ *
626
+ * 原脚本 7 项里,html 非空 / hover 绑定 / 非安全转义已由
627
+ * `deepCheckActionCard`(html 非空、绑定目标与状态反馈)和
628
+ * `selfCheckActionCard`(hover 视觉反馈、反斜杠转义)覆盖,此处不重复实现。
629
+ * 只补原先查不到、又一定导致交付事故的内容项:
630
+ * 1. 流程卡 src 的 fileId 存在且与 cfg.file_id 同源;
631
+ * 2. customParams 合同文件字段值与 cfg.file_id 同源;
632
+ * 3. 审查详情卡 aiProps 的 aiid / fileId / fileName 非空且与 cfg 一致;
633
+ * 4. 被 art() 引用的 var S / R / C 常量非空(≥20 字符)且上游确有内容;
634
+ * 5. payload 顶层与 arguments 的未知参数。
635
+ *
636
+ * 判据不另起炉灶:结果合并进 selfCheck 的同一份 problems / warnings / checks。
637
+ */
638
+ export function contentCheckActionCard(payload, expected) {
639
+ const problems = [];
640
+ const warnings = [];
641
+ const checks = [];
642
+ const pass = (item, detail = '') => {
643
+ checks.push({ level: 'PASS', item, detail });
644
+ };
645
+ const fail = (item, detail) => {
646
+ checks.push({ level: 'FAIL', item, detail });
647
+ problems.push(`${item}:${detail}`);
648
+ };
649
+ const warn = (item, detail) => {
650
+ checks.push({ level: 'WARN', item, detail });
651
+ warnings.push(`${item}:${detail}`);
652
+ };
653
+ const html = String(payload.arguments?.sdkOptions?.params_pc?.customParams?.html ?? '');
654
+ const wantFileId = String(expected.fileId ?? '').trim();
655
+ // ── 1) 流程卡 src.fileId:缺 fileId 或与 cfg 不同源,流程附件会挂错文件
656
+ const flowSegments = eachMatch(/flowpage\/create\/[^']*/gu, html).map((hit) => String(hit[0]));
657
+ const flowIds = [];
658
+ for (const seg of flowSegments) {
659
+ for (const hit of eachMatch(/fileId=(\d+)/gu, seg))
660
+ flowIds.push(String(hit[1]));
661
+ }
662
+ const hasFlowSrc = flowSegments.some((seg) => seg.includes('workflowId='));
663
+ if (!hasFlowSrc) {
664
+ pass('流程卡 fileId 归属', '无流程卡,跳过');
665
+ }
666
+ else if (flowIds.length === 0) {
667
+ fail('流程卡 fileId 归属', '流程卡 src 缺 fileId=(cfg.file_id 为空,附件会挂不到文件)');
668
+ }
669
+ else if (!wantFileId) {
670
+ fail('流程卡 fileId 归属', 'cfg.file_id 为空,但流程卡带了 fileId(渲染器与 cfg 不一致)');
671
+ }
672
+ else {
673
+ const uniq = [...new Set(flowIds)];
674
+ const bad = uniq.filter((id) => id !== wantFileId);
675
+ if (bad.length)
676
+ fail('流程卡 fileId 归属', `卡片=${uniq.join(',')},应为=${wantFileId}(流程附件会挂错文件)`);
677
+ else
678
+ pass('流程卡 fileId 归属', uniq.join(','));
679
+ }
680
+ // ── 2) customParams 合同附件字段值也必须等于 cfg.file_id
681
+ const fieldPairs = eachMatch(/'(\d{10,})'\s*:\s*'(\d{10,})'/gu, html);
682
+ if (fieldPairs.length === 0) {
683
+ pass('customParams 附件字段归属', '无预填附件字段,跳过');
684
+ }
685
+ else if (!wantFileId) {
686
+ fail('customParams 附件字段归属', '存在附件字段但 cfg.file_id 为空');
687
+ }
688
+ else {
689
+ const bad = fieldPairs.map((hit) => String(hit[2])).filter((value) => value !== wantFileId);
690
+ if (bad.length)
691
+ fail('customParams 附件字段归属', `字段值=${bad.join(',')},应为=${wantFileId}`);
692
+ else
693
+ pass('customParams 附件字段归属', `${fieldPairs.length} 处`);
694
+ }
695
+ // ── 3) 审查详情卡 aiProps:三个值缺一个,审查页就打不开文件
696
+ const reviewHit = /aiProps:\{aiid:'([^']*)',fileId:'([^']*)',fileName:'([^']*)'\}/u.exec(html);
697
+ if (!reviewHit) {
698
+ pass('审查详情卡 aiProps', '无审查详情入口,跳过');
699
+ }
700
+ else {
701
+ const aiid = String(reviewHit[1]);
702
+ const fid = String(reviewHit[2]);
703
+ const fname = String(reviewHit[3]).trim();
704
+ const wantAiid = String(expected.aiid ?? '').trim();
705
+ const wantName = String(expected.fileName ?? '').split("'").join('').trim();
706
+ if (!aiid)
707
+ fail('审查详情卡 aiid', '为空(审查页打不开)');
708
+ else if (wantAiid && aiid !== wantAiid)
709
+ fail('审查详情卡 aiid', `卡片=${aiid},应为=${wantAiid}`);
710
+ else
711
+ pass('审查详情卡 aiid', aiid);
712
+ if (!fid)
713
+ fail('审查详情卡 fileId 归属', '为空(审查页打不开文件)');
714
+ else if (!wantFileId)
715
+ fail('审查详情卡 fileId 归属', `卡片=${fid},但 cfg.file_id 为空`);
716
+ else if (fid !== wantFileId)
717
+ fail('审查详情卡 fileId 归属', `卡片=${fid},应为=${wantFileId}`);
718
+ else
719
+ pass('审查详情卡 fileId 归属', fid);
720
+ if (!fname)
721
+ fail('审查详情卡 fileName', '为空(审查页打不开文件)');
722
+ else if (wantName && fname !== wantName)
723
+ warn('审查详情卡 fileName', `卡片=${fname},cfg.file_name=${wantName}`);
724
+ else
725
+ pass('审查详情卡 fileName', fname);
726
+ }
727
+ // ── 4) 被 art() 引用的内容常量:空常量点开就是空白页,且不会报 JS 错误
728
+ const consts = new Map();
729
+ for (const hit of eachMatch(/var ([SRC])='((?:[^'\\]|\\.)*)'/gu, html)) {
730
+ consts.set(String(hit[1]), String(hit[2]));
731
+ }
732
+ const used = [...new Set(eachMatch(/art\(\s*([SRC])\s*,/gu, html).map((hit) => String(hit[1])))].sort();
733
+ const upstream = {
734
+ S: String(expected.summaryHtml ?? ''),
735
+ R: String(expected.reportHtml ?? ''),
736
+ C: String(expected.compareHtml ?? ''),
737
+ };
738
+ if (used.length === 0) {
739
+ pass('内容常量 var S/R/C', '无 artifact 引用,跳过');
740
+ }
741
+ else {
742
+ for (const name of used) {
743
+ const item = `内容常量 var ${name}`;
744
+ const body = consts.get(name);
745
+ const source = upstream[name] || '';
746
+ if (body === undefined)
747
+ fail(item, 'art() 引用了未声明的常量');
748
+ else if (body.trim().length < 20) {
749
+ fail(item, `为空或过短(${body.trim().length} 字符,上游 ${source.length} 字符),点开是空白页`);
750
+ }
751
+ else if (!source.trim()) {
752
+ fail(item, `上游内容为空,但卡片出现 ${body.trim().length} 字符(渲染器与 cfg 不一致)`);
753
+ }
754
+ else
755
+ pass(item, `${body.trim().length} 字符`);
756
+ }
757
+ }
758
+ // ── 5) payload 未知参数:宿主会静默忽略,拼错参数名时排查成本极高
759
+ const args = (payload.arguments ?? {});
760
+ const extraTop = Object.keys(payload).filter((key) => !KNOWN_TOP_KEYS.has(key));
761
+ const extraArgs = Object.keys(args).filter((key) => !KNOWN_ARG_KEYS.has(key));
762
+ if (extraTop.length || extraArgs.length) {
763
+ fail('payload 参数识别', `未识别参数:${[...extraTop, ...extraArgs].sort().join(',')}(会被静默忽略)`);
764
+ }
765
+ else {
766
+ pass('payload 参数识别', `arguments ${Object.keys(args).length} 个键`);
767
+ }
768
+ return { problems, warnings, checks };
769
+ }
770
+ /** 交付前自检:引号、反斜杠、`__W__` 残留、ES5、hover 绑定、脚本语法、内容级项。 */
771
+ export function selfCheckActionCard(payload, expected) {
342
772
  const problems = [];
343
773
  const html = String(payload.arguments?.sdkOptions?.params_pc?.customParams?.html ?? '');
344
774
  const doubleQuotes = (html.match(/"/gu) ?? []).length;
345
- if (doubleQuotes !== 0)
346
- problems.push(`html 内双引号 ${doubleQuotes} 个(应为 0)`);
775
+ // 只允许 0 个,或恰好是 var S="..." 的那一对(与 validate_action_card.py 口径一致)
776
+ const sWrapped = /var S="/u.test(html);
777
+ if (doubleQuotes !== 0 && !(doubleQuotes === 2 && sWrapped)) {
778
+ problems.push(`html 内双引号 ${doubleQuotes} 个(只允许 0,或 var S="..." 的包裹对)`);
779
+ }
347
780
  const unsafe = (html.match(/\\(?!\/script>|')/gu) ?? []).length;
348
781
  if (unsafe)
349
782
  problems.push(`非安全转义反斜杠 ${unsafe} 处`);
@@ -361,13 +794,23 @@ export function selfCheckActionCard(payload) {
361
794
  [/\blet\b/u, 'let'],
362
795
  [/\?\?/u, '??'],
363
796
  [/\?\./u, '?.'],
797
+ [/`/u, 'template literal'],
364
798
  ];
365
799
  for (const [pattern, name] of esPatterns) {
366
800
  if (pattern.test(jsCode))
367
801
  problems.push(`ES5 违规:${name}`);
368
802
  }
369
- if (!jsCode.includes('mouseenter'))
370
- problems.push('缺少 hover 绑定(mouseenter)');
803
+ // 可点卡片必须同时具备 click、hover 绑定与视觉变化:
804
+ // 只绑 click 用户不知道能点;只绑 hover 无样式变化等于没有反馈。
805
+ const hasClick = jsCode.includes('onclick') || jsCode.includes("addEventListener('click'");
806
+ const hasHover = jsCode.includes('mouseenter') || jsCode.includes('mouseover');
807
+ const hasHoverStyle = jsCode.includes('borderColor') || jsCode.includes('boxShadow');
808
+ if (hasClick && !hasHover) {
809
+ problems.push('缺少 hover 绑定:有 click 但无 mouseenter/mouseover');
810
+ }
811
+ else if (hasClick && hasHover && !hasHoverStyle) {
812
+ problems.push('缺少 hover 视觉反馈:无 borderColor/boxShadow 变化');
813
+ }
371
814
  if (!scriptMatch) {
372
815
  problems.push('未找到 script');
373
816
  }
@@ -382,8 +825,128 @@ export function selfCheckActionCard(payload) {
382
825
  problems.push(`node --check 失败:${message.split('\n').slice(0, 3).join(' / ')}`);
383
826
  }
384
827
  }
385
- const cardCount = (html.match(/role='button'/gu) ?? []).length;
386
- return { problems, cardCount, htmlLength: html.length };
828
+ const cardCount = (html.match(/<button type='button'/gu) ?? []).length;
829
+ // 2026-11-13:并入原 scripts/validate_action_card.py 的终检项(该脚本已下线)。
830
+ // 两处 problems 去重后返回,保证交付判据只有一份。
831
+ const deep = deepCheckActionCard(payload);
832
+ for (const item of deep.problems) {
833
+ if (!problems.includes(item))
834
+ problems.push(item);
835
+ }
836
+ const warnings = [...deep.warnings];
837
+ const checks = [...deep.checks];
838
+ // 2026-11-13 第九批下沉:原 scripts/verify_card_delivery.py 的内容级项(脚本已下线)。
839
+ // expected 由 operation 用内部 cfg 构造;不传时仍兼容纯结构自检的旧调用方。
840
+ // 不新增 contract.card.verify:判据只认 selfCheck / selfCheckChecks / selfCheckPassed。
841
+ if (expected) {
842
+ const content = contentCheckActionCard(payload, expected);
843
+ for (const item of content.problems) {
844
+ if (!problems.includes(item))
845
+ problems.push(item);
846
+ }
847
+ for (const item of content.warnings) {
848
+ if (!warnings.includes(item))
849
+ warnings.push(item);
850
+ }
851
+ checks.push(...content.checks);
852
+ }
853
+ return {
854
+ problems,
855
+ warnings,
856
+ checks,
857
+ cardCount,
858
+ htmlLength: html.length,
859
+ };
860
+ }
861
+ /**
862
+ * 成品 `<browsertool>` 文本校验:外层 JSON 可解析 + 内层脚本语法可解析。
863
+ *
864
+ * 与 `selfCheckActionCard` 的分工:那个查「构造出来的对象」是否合规,
865
+ * 这个查「最终要发出去的那段字符串」是否还能被宿主解析。手改少一层反斜杠
866
+ * (如 JSON 里写成 `\'`)时对象层完全正常,只有本函数能在交付前拦住。
867
+ */
868
+ export function verifyBrowsertoolText(text) {
869
+ const raw = String(text ?? '');
870
+ const bytes = Buffer.byteLength(raw, 'utf8');
871
+ const trimmed = raw.trim();
872
+ if (!trimmed)
873
+ return { passed: false, problems: ['内容为空'], bytes };
874
+ const problems = [];
875
+ if (trimmed.startsWith('```')) {
876
+ problems.push('被代码围栏包裹(宿主会当普通文本,卡片不渲染)');
877
+ }
878
+ const openCount = (trimmed.match(/<browsertool>/gu) ?? []).length;
879
+ const closeCount = (trimmed.match(/<\/browsertool>/gu) ?? []).length;
880
+ if (openCount !== 1 || closeCount !== 1) {
881
+ problems.push(`标签不成对:<browsertool> ${openCount} 个、</browsertool> ${closeCount} 个`);
882
+ }
883
+ const openIndex = trimmed.indexOf('<browsertool>');
884
+ const closeIndex = trimmed.lastIndexOf('</browsertool>');
885
+ const closeTail = closeIndex + '</browsertool>'.length;
886
+ if (openIndex !== 0 || closeIndex < 0 || closeTail !== trimmed.length) {
887
+ problems.push('标签外还有内容(闭合标签后不得续写正文,也不得前置说明)');
888
+ }
889
+ if (openIndex !== 0 || closeIndex <= openIndex) {
890
+ return { passed: false, problems, bytes };
891
+ }
892
+ const payloadText = trimmed.slice('<browsertool>'.length, closeIndex).trim();
893
+ let payload;
894
+ try {
895
+ payload = JSON.parse(payloadText);
896
+ }
897
+ catch (error) {
898
+ const message = error instanceof Error ? error.message : String(error);
899
+ const hit = /position (\d+)/u.exec(message);
900
+ const at = hit ? Number(hit[1]) : -1;
901
+ const from = at >= 0 ? Math.max(0, at - 40) : 0;
902
+ const snippet = payloadText.slice(from, from + 80).replace(/\s+/gu, ' ');
903
+ problems.push(`外层 JSON 解析失败:${message}(附近:${snippet || '<空>'})`);
904
+ return { passed: false, problems, bytes };
905
+ }
906
+ const args = (payload.arguments ?? {});
907
+ if (payload.toolId !== 'fill_form') {
908
+ problems.push(`toolId 应为 fill_form,实际 ${String(payload.toolId ?? '<空>')}`);
909
+ }
910
+ if (args.type !== 'e10') {
911
+ problems.push(`arguments.type 应为 e10,实际 ${String(args.type ?? '<空>')}`);
912
+ }
913
+ if (!String(args.src ?? '').trim())
914
+ problems.push('缺少 arguments.src');
915
+ if (!(typeof args.width === 'number' && args.width > 0))
916
+ problems.push('缺少有效的 arguments.width');
917
+ const sdk = (args.sdkOptions ?? {});
918
+ const paramsPc = (sdk.params_pc ?? {});
919
+ const html = String((paramsPc.customParams ?? {}).html ?? '');
920
+ if (!String(paramsPc.compName ?? '').trim()) {
921
+ problems.push('缺少 params_pc.compName(组件不会挂载,卡片不显示)');
922
+ }
923
+ if (!(sdk.routerProps_pc ?? {}).initialEntries) {
924
+ problems.push('缺少 sdkOptions.routerProps_pc.initialEntries');
925
+ }
926
+ if (!html) {
927
+ problems.push('缺少 params_pc.customParams.html');
928
+ return { passed: false, problems, bytes };
929
+ }
930
+ const scriptOpen = html.lastIndexOf('<script>');
931
+ const scriptClose = html.lastIndexOf('</script>');
932
+ if (scriptOpen < 0 || scriptClose <= scriptOpen) {
933
+ problems.push('html 内缺少完整 <script> 块');
934
+ }
935
+ else {
936
+ const jsCode = html.slice(scriptOpen + '<script>'.length, scriptClose);
937
+ if (jsCode.includes('__W__'))
938
+ problems.push('脚本残留宽度占位符 __W__(点击会 ReferenceError)');
939
+ try {
940
+ // 只编译不执行,等价 node --check
941
+ // eslint-disable-next-line no-new
942
+ new Script(jsCode);
943
+ }
944
+ catch (error) {
945
+ const message = error instanceof Error ? error.message : String(error);
946
+ problems.push(`脚本语法错误:${message.split('\n').slice(0, 3).join(' / ')}`);
947
+ }
948
+ }
949
+ return { passed: problems.length === 0, problems, bytes };
387
950
  }
388
951
  function isFile(path) {
389
952
  try {
@@ -527,7 +1090,7 @@ export const contractCardActionOperation = {
527
1090
  aiid: truthyText(input.aiid) || DEFAULT_AIID,
528
1091
  ai_extra_id: truthyText(input.aiExtraId) || truthyText(ctx.aiExtraId) || '',
529
1092
  attachment_field_id: truthyText(input.attachmentFieldId) || truthyText(ctx.attachmentFieldId) || '',
530
- field_assign_keys: ctx.fieldAssignKeys || '',
1093
+ field_assign_keys: truthyText(input.fieldAssignKeys) || ctx.fieldAssignKeys || '',
531
1094
  card_id: truthyText(input.cardId) || `card-${stamp}`,
532
1095
  call_id: truthyText(input.callId) || `contract-card-${stamp}-01`,
533
1096
  title: truthyText(input.title) || undefined,
@@ -552,8 +1115,23 @@ export const contractCardActionOperation = {
552
1115
  },
553
1116
  };
554
1117
  }
555
- const check = selfCheckActionCard(payload);
1118
+ // 内容级自检的期望值一律取内部 cfg,不接受调用方另传,避免「自己验自己」。
1119
+ const check = selfCheckActionCard(payload, {
1120
+ fileId: cfg.file_id || '',
1121
+ fileName: cfg.file_name || '',
1122
+ aiid: cfg.aiid,
1123
+ summaryHtml: cfg.summary_html || '',
1124
+ reportHtml: cfg.report_html || '',
1125
+ compareHtml: cfg.compare_html || '',
1126
+ });
556
1127
  const text = `<browsertool>\n${JSON.stringify(payload, null, 1)}\n</browsertool>`;
1128
+ // 成品文本自检:查的是「最终要发出去的那段字符串」。
1129
+ // 外层 JSON 非法转义、script 被截断、被代码围栏包裹,只有这一步能拦住。
1130
+ for (const item of verifyBrowsertoolText(text).problems) {
1131
+ const message = `browsertool 文本校验:${item}`;
1132
+ if (!check.problems.includes(message))
1133
+ check.problems.push(message);
1134
+ }
557
1135
  let output;
558
1136
  const outPath = truthyText(input.out);
559
1137
  if (outPath) {
@@ -572,6 +1150,8 @@ export const contractCardActionOperation = {
572
1150
  callId: payload.callId,
573
1151
  htmlLength: check.htmlLength,
574
1152
  selfCheck: check.problems,
1153
+ selfCheckWarnings: check.warnings,
1154
+ selfCheckChecks: check.checks,
575
1155
  selfCheckPassed: check.problems.length === 0,
576
1156
  bytes: Buffer.byteLength(text, 'utf8'),
577
1157
  ...(output ? { output, browsertool: text } : { browsertool: text }),