Procházet zdrojové kódy

feat: 过滤中间产物,只搬运/对账真正的交付物

用户要求:「上传 S3 仅能上传真正的交付物,不能上传中间产物」。

## 改动

新增 isIntermediateName() 判定,接入两处:

① artifact-sync.service.ts::isDeadSource
   中间产物不入搬运队列(不上云、不进成果列表)

② assistant-turn.ts::countMissingFiles
   中间产物不计入对账,消除「还有 N 个文件未收到」的误报

## 判定规则(只拦高置信度的辅助产物)

拦:
  · data.json / tmp.json / state.yaml 等「中间名 + 纯数据格式」
  · build.py / gen.sh / test.js 等生成脚本
  · draft.* / backup.* / *.bak / *.tmp
  · probe.txt / same.txt 等自测探针

放(不误杀):
  · data.xlsx(用户要的 Excel)
  · report.json(用户可能要的 JSON 成果)
  · build.html(用户要的页面)

## 兼容的云盘存储名

 → data.json
            → probe.txt
两种前缀形态都能正确剥离。

## 测试

新增 6 条:中间产物不计入 / data.xlsx 与 report.json 必须计入 / 正常交付物照常。
全量 1861/1861 通过。

Co-Authored-By: Claude Code <noreply@anthropic.com>
Huccct před 4 dny
rodič
revize
0df4cbb27a

+ 63 - 0
src/app/core/artifact-sync.service.ts

@@ -44,6 +44,69 @@ export function isDeadSource(source: string): boolean {
   if (s.startsWith('/tmp/')) return true;
   /* 内部临时命名(fmode 自己的中转产物) */
   if (/\/_fmode_(outbound|managed)_/i.test(s)) return true;
+  /*
+   * 🔴 明显的中间产物(2026-11-18 用户要求「上传 S3 仅能上传真正的交付物」)。
+   *
+   * 容器常把生成过程中的辅助文件也当成交付物上报:
+   *   · `data.json`  —— 生成表格用的中间数据
+   *   · `probe.txt` / `same.txt` —— 自测探针
+   *   · `build.py` / `gen.sh` —— 生成脚本
+   *   · `index.tmp` / `draft.*` —— 草稿
+   *
+   * 这些不是用户要的成品,搬上云只会让成果列表变脏、对账提示误报。
+   *
+   * 注意:**按文件名判断**,不看路径 —— 中间产物可能在任何目录。
+   * 只拦「明显是辅助产物」的命名,不做模糊猜测(宁可放过,不可误杀真交付物)。
+   */
+  const base = s.split('/').pop() ?? '';
+  if (isIntermediateName(base)) return true;
+  return false;
+}
+
+/**
+ * 文件名是否明显属于「中间产物 / 辅助文件」(2026-11-18)。
+ *
+ * 与 `isDeadSource` 分开,方便单测与复用(正文清单对账也用同一判据)。
+ *
+ * 原则:**只拦高置信度的辅助产物**。
+ * 用户想要的成品可能叫什么名字无法预知,误杀比漏放代价更大。
+ */
+export function isIntermediateName(fileName: string): boolean {
+  const n = (fileName || '').trim().toLowerCase();
+  if (!n) return true;
+  /* 云盘存储名带 `序号-随机串-` 前缀,先剥掉再判断 */
+  /*
+   * 剥掉云盘存储名的序号前缀,兼容两种形态:
+   *   `3-mwln7vrfjy-data.json`  → `data.json`(数字-随机串-)
+   *   `0-probe.txt`             → `probe.txt`(数字-)
+   */
+  const clean = n.replace(/^\d+-([a-z0-9]{6,}-)?/, '');
+
+  /*
+   * 🔴 不能按「文件名前缀」一刀切(2026-11-18 单测暴露的误杀)。
+   *
+   * 曾写成 `/^(data|tmp|...)\./` → **把 `data.xlsx` 也拦掉了**,
+   * 但 `data.xlsx` 完全可能是用户要的交付物。
+   *
+   * 正确思路:**只有「纯数据中转格式」+ 典型中间名 才拦**。
+   *   拦:`data.json` / `tmp.json` / `build.py` / `probe.txt`
+   *   放:`data.xlsx` / `report.json`(用户可能要 JSON 成果)/ `build.html`
+   */
+  const DATA_ONLY = /\.(json|yaml|yml|toml|ini|log|lock)$/;
+  if (DATA_ONLY.test(clean) && /^(data|tmp|temp|cache|intermediate|scratch|state)/.test(clean))
+    return true;
+
+  /* 生成脚本:容器自测/构建用的,不是交付物 */
+  if (/^(build|gen|generate|make|run|test|probe)[-_a-z0-9]*\.(py|sh|js|ts|mjs|bat|ps1)$/.test(clean))
+    return true;
+
+  /* 草稿 / 备份 / 临时副本 */
+  if (/^(draft|backup|bak|old|tmp)[-_.]/.test(clean)) return true;
+  if (/\.(bak|tmp|swp|orig)$/.test(clean)) return true;
+
+  /* 自测探针(容器排查问题时留下的,形状固定) */
+  if (/^(probe|same|wtest)([-_.]|\d)/.test(clean)) return true;
+
   return false;
 }
 

+ 41 - 0
src/app/core/assistant-turn.spec.ts

@@ -1346,3 +1346,44 @@ describe('countMissingFiles(正文声明数 vs 实际卡片数)', () => {
     expect(t.missingFileCount).toBe(0);
   });
 });
+
+/**
+ * 中间产物过滤(2026-11-18 用户要求「上传 S3 仅能上传真正的交付物」)。
+ *
+ * 容器常把生成过程中的辅助文件也列进正文(data.json、probe.txt 等),
+ * 它们本来就不会挂附件卡片,算进「缺失」会让对账提示一直误报。
+ */
+describe('中间产物不计入对账', () => {
+  const count = (text: string) => turnsFromDm([dmTurn([msg('a1', 'agent', text)])], 0, false)[0].missingFileCount;
+
+  it('data.json(纯中间数据)不计入', () => {
+    expect(count('https://s3.fmode.cn/deliverables/a/3-mwln7vrfjy-data.json')).toBe(0);
+  });
+
+  it('probe.txt / same.txt(自测探针)不计入', () => {
+    expect(count('https://s3.fmode.cn/deliverables/a/0-probe.txt\nhttps://s3.fmode.cn/deliverables/a/1-same.txt')).toBe(0);
+  });
+
+  it('build.py(生成脚本)不计入', () => {
+    expect(count('https://s3.fmode.cn/deliverables/a/build.py')).toBe(0);
+  });
+
+  it('🔴 data.xlsx 是合法交付物,必须计入', () => {
+    // 曾因按文件名前缀一刀切被误杀
+    expect(count('https://s3.fmode.cn/deliverables/a/data.xlsx')).toBe(1);
+  });
+
+  it('🔴 report.json 是合法交付物,必须计入', () => {
+    // JSON 也可以是用户要的成果,只有 data/tmp 这类前缀才拦
+    expect(count('https://s3.fmode.cn/deliverables/a/report.json')).toBe(1);
+  });
+
+  it('正常交付物照常计入', () => {
+    const text = [
+      'https://s3.fmode.cn/deliverables/a/report.pdf',
+      'https://s3.fmode.cn/deliverables/a/table.xlsx',
+      'https://s3.fmode.cn/deliverables/a/page.html',
+    ].join('\n');
+    expect(count(text)).toBe(3);
+  });
+});

+ 43 - 0
src/app/core/assistant-turn.ts

@@ -1485,11 +1485,54 @@ function countMissingFiles(text: string, cardCount: number): number {
     declared.add(basename(match[0]));
   }
 
+  /*
+   * 🔴 剔除中间产物(2026-11-18)。
+   *
+   * 容器有时会把 `data.json` / `probe.txt` / `same.txt` 这类辅助文件也列进正文。
+   * 它们本来就不是交付物、也不会挂附件卡片,算进「缺失」会让提示一直误报
+   * (实测:「还有 4 个文件未收到」,其中 2 个是容器自测的探针文件)。
+   *
+   * 判据与 `artifact-sync.service.ts::isIntermediateName()` 保持同一套口径。
+   */
+  for (const name of declared) {
+    if (isPaidDeliverableGuess(name) === false) declared.delete(name);
+  }
+
   // 正文里一个明确的文件都没声明 → 谈不上缺失(避免把纯文字回复误判)
   if (declared.size === 0) return 0;
   return Math.max(0, declared.size - cardCount);
 }
 
+/**
+ * 粗判「这个文件名像不像用户要的交付物」(2026-11-18)。
+ *
+ * ⚠️ 与 `artifact-sync.service.ts::isIntermediateName()` 是**镜像实现** ——
+ *    两个模块分属不同层(core/assistant-turn 与 core/artifact-sync),
+ *    为避免循环依赖没有直接 import。改判据时**两处都要改**。
+ */
+function isPaidDeliverableGuess(fileName: string): boolean {
+  const n = (fileName || '').trim().toLowerCase();
+  if (!n) return false;
+  /* 去掉云盘前缀(`3-mwln7vrfjy-data.json` → `data.json`) */
+  /*
+   * 剥掉云盘存储名的序号前缀,兼容两种形态:
+   *   `3-mwln7vrfjy-data.json`  → `data.json`(数字-随机串-)
+   *   `0-probe.txt`             → `probe.txt`(数字-)
+   */
+  const clean = n.replace(/^\d+-([a-z0-9]{6,}-)?/, '');
+
+  /* 与 artifact-sync.service.ts::isIntermediateName 保持同一口径 */
+  const DATA_ONLY = /\.(json|yaml|yml|toml|ini|log|lock)$/;
+  if (DATA_ONLY.test(clean) && /^(data|tmp|temp|cache|intermediate|scratch|state)/.test(clean))
+    return false;
+  if (/^(build|gen|generate|make|run|test|probe)[-_a-z0-9]*\.(py|sh|js|ts|mjs|bat|ps1)$/.test(clean))
+    return false;
+  if (/^(draft|backup|bak|old|tmp)[-_.]/.test(clean)) return false;
+  if (/\.(bak|tmp|swp|orig)$/.test(clean)) return false;
+  if (/^(probe|same|wtest)([-_.]|\d)/.test(clean)) return false;
+  return true;
+}
+
 /** 取路径/URL 最后一段(去掉 query 与 hash),用于按文件名去重比对 */
 function basename(pathOrUrl: string): string {
   const noQuery = pathOrUrl.split(/[?#]/)[0];