dsh-data-cleaning-agent 0.8.10 → 0.8.11

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/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.8.11] - 2026-09-07
8
+
9
+ ### Fixed
10
+ - 补全结果按已确认映射填入原列空白单元格,保留非空值和列顺序;工作台预览、CSV/XLSX 和异常清单一致,不再为已映射列追加「(补全)」副列。首次调用及候选续跑均保护原表英文键的非空值。
11
+ - 字段映射覆盖当前 128 个可补全字段的标准中文名、英文键和明确别名;移除未知首列强制映射企业名称的兜底。
12
+ - 参照 AI 填表的推荐确认方式,为多义表头提供推荐、折叠分组选择和搜索;重复目标需人工选列,保留已有选择及输出字段范围。
13
+ - CSV/XLSX 重复表头生成唯一列键,防止法定代表人等同名列相互覆盖。旧任务已丢失的原值需重新导入原文件恢复。
14
+
7
15
  ## [0.8.10] - 2026-09-07
8
16
 
9
17
  ### Changed
package/README.en.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  > A data cleaning & completion agent plugin for DeepSeek Harness: local CSV/XLSX/JSON engine plus optional Qichacha (QCC) MCP enterprise-data enrichment. Initiated and maintained by the Qichacha (QCC) team.
4
4
  >
5
- > Current source version / 当前源码版本: **0.8.10** (stable release)
5
+ > Current source version / 当前源码版本: **0.8.11** (stable release)
6
6
 
7
- This release adds continuous resizing from the workbench's left edge, keeping the native composer clear. Arrow keys, Home/End, double-click reset, and width restoration on reopening are supported. Constrained layouts use a full-screen drawer. All 128 fields, QCC-blue menus, existing workflows, and native DSH input and send behavior are preserved.
7
+ This release adds automatic mapping for all 128 fields using standard labels, field keys, and explicit aliases, with searchable grouped choices and confirmation for ambiguous or duplicate columns. Enrichment fills empty cells in mapped original columns and preserves nonempty values; selected fields without a mapped column are appended. Duplicate CSV/XLSX headers retain independent values. Preview and exports follow the same rules. QCC-blue menus, resizable workbench, and native DSH input/send behavior remain unchanged. Existing download artifacts are not rewritten.
8
8
 
9
9
  [![CI](https://github.com/duhu2000/dsh-data-cleaning-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/duhu2000/dsh-data-cleaning-agent/actions/workflows/ci.yml)
10
10
  [![npm](https://img.shields.io/npm/v/dsh-data-cleaning-agent)](https://www.npmjs.com/package/dsh-data-cleaning-agent)
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  > 在 DeepSeek Harness 中清洗、补全、画像企业名单数据的智能体插件:本地 CSV/XLSX/JSON 引擎 + 可选企查查(Qichacha/QCC)MCP 企业数据补全,由企查查(Qichacha/QCC)团队发起并维护。
4
4
  >
5
- > 当前源码版本 / Current source version: **0.8.10**(正式版本)
5
+ > 当前源码版本 / Current source version: **0.8.11**(正式版本)
6
6
 
7
- 本版支持拖动右侧工作台左边缘连续调宽,中央输入区同步让位;支持方向键微调、Home/End 边界、双击恢复默认和关闭重开保留宽度。空间不足时全屏降级。保留企查查蓝菜单、全部 128 个字段和原有工作流,不替换 DSH 原生输入和发送机制。
7
+ 本版为全部 128 个字段加入标准名、英文键及明确别名自动映射,多义表头和重复列提供可确认推荐与分组搜索。补全结果优先写入已映射原列的空白单元格,保留非空原值;无对应原列的已选字段才新增列。CSV/XLSX 重复表头独立保留,预览与导出规则一致。保留企查查蓝菜单、可调宽工作台及 DSH 原生输入和发送机制。历史下载文件不自动改写。
8
8
 
9
9
  [![CI](https://github.com/duhu2000/dsh-data-cleaning-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/duhu2000/dsh-data-cleaning-agent/actions/workflows/ci.yml)
10
10
  [![npm](https://img.shields.io/npm/v/dsh-data-cleaning-agent)](https://www.npmjs.com/package/dsh-data-cleaning-agent)
@@ -45,6 +45,8 @@ bash <(curl -fsSL https://raw.githubusercontent.com/duhu2000/dsh-data-cleaning-a
45
45
  4. **清洗补全**:执行本地确定性清洗;需要 QCC 时先零调用估算,再由当前用户确认使用自己的账号额度;
46
46
  5. **下载数据**:生成结果 CSV/XLSX 与异常清单 CSV/XLSX,后续可从任务历史恢复下载。
47
47
 
48
+ 0.8.11 起的原列回填规则:规则确认时同时检查「字段映射」和「输出字段」。已选字段优先填入已映射原列的空白单元格,非空原值保持不变,原表没有对应映射的已选字段才新增列。地址、网址、开业时间等推荐需确认含义;重复列需明确选定一列。未返回的数据不编造。结果预览、XLSX/CSV 及异常清单遵循同一规则;历史已生成文件不会自动改写。
49
+
48
50
  输入框左上角的「提示词生成」提供三种名单录入方式:
49
51
 
50
52
  - **粘贴名单**:每行一个企业名称或统一社会信用代码;
package/lib/artifacts.js CHANGED
@@ -8,6 +8,7 @@
8
8
  import { createHash, randomUUID } from 'node:crypto';
9
9
  import XLSX from 'xlsx';
10
10
  import { FIELD_LABELS, normalizeFieldSelection } from './workflow-contract.js';
11
+ import { projectCompletionResult } from './engine.js';
11
12
 
12
13
  const ROOT = '.dsh-data-cleaning-artifacts/v1';
13
14
  const MAX_ARTIFACT_BYTES = 32 * 1024 * 1024;
@@ -218,12 +219,17 @@ export class WorkflowArtifactStore {
218
219
 
219
220
  async createBundle(taskId, input = {}) {
220
221
  assertId(taskId, 'taskId');
221
- const rows = normalizeRows(input.rows);
222
- const headers = normalizeHeaders(input.headers, rows, input.fieldSelection);
222
+ const projected = projectCompletionResult({
223
+ rows: normalizeRows(input.rows), headers: input.headers || [],
224
+ mappings: input.mappings || [], fieldSelection: normalizeFieldSelection(input.fieldSelection),
225
+ });
226
+ const rows = projected.rows;
227
+ const headers = normalizeHeaders(projected.headers, rows);
223
228
  if (!headers.length) throw new ArtifactError('DC_ARTIFACT_HEADERS_REQUIRED', 'At least one export column is required.', 400);
224
229
  const exceptions = input.exceptionRows === undefined
225
230
  ? deriveExceptionRows(rows)
226
- : normalizeRows(input.exceptionRows);
231
+ : projectCompletionResult({ rows: normalizeRows(input.exceptionRows), headers: input.headers || [],
232
+ mappings: input.mappings || [], fieldSelection: normalizeFieldSelection(input.fieldSelection) }).rows;
227
233
  const exceptionHeaders = normalizeHeaders([...headers, '_exception_reason'], exceptions);
228
234
  const baseName = safeFilePart(input.baseName, '数据清洗补全结果');
229
235
  const timestamp = this.nowFn();
package/lib/client.js CHANGED
@@ -944,6 +944,11 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
944
944
  .dcAgentMappingRow { display: grid; grid-template-columns: minmax(0, 1fr) 24px minmax(180px, 1fr); align-items: center; gap: 8px; margin-top: 7px; font-size: 12px; }
945
945
  .dcAgentMappingRow > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
946
946
  .dcAgentMappingRow > b { text-align: center; color: light-dark(#8792a3, #8290a5); }
947
+ .dcAgentMappingPicker summary { cursor: pointer; overflow-wrap: anywhere; }
948
+ .dcAgentMappingPicker[open] { padding: 8px; border: 1px solid var(--dc-border); border-radius: 8px; }
949
+ .dcAgentMappingPicker input, .dcAgentMappingPicker select { width: 100%; margin-top: 8px; max-width: 100%; min-width: 0; }
950
+ .dcAgentMappingRow .dcAgentButton { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
951
+ .dcAgentMappingRow small { display: block; margin: 4px 0; overflow-wrap: anywhere; }
947
952
  .dcAgentRulesGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
948
953
  .dcAgentFieldGroup { display: grid; gap: 7px; margin-top: 12px; }
949
954
  .dcAgentFieldGroupHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
@@ -1428,30 +1433,128 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
1428
1433
  return RESULT_FIELD_LABELS.get(String(key ?? '')) ?? String(key ?? '');
1429
1434
  }
1430
1435
 
1431
- const MAPPING_PATTERNS = [
1432
- ['company_name', /^(name|company|company_name|企业名称|公司名称|单位名称)$/i],
1433
- ['credit_no', /^(credit_no|creditCode|unified_credit_code|统一社会信用代码|信用代码)$/i],
1434
- ['reg_no', /^(reg_no|registration_no|注册号)$/i],
1435
- ['phone', /^(phone|mobile|tel|telephone|联系电话|手机号码|手机号)$/i],
1436
- ['registered_address', /^(address|registered_address|注册地址|企业地址|公司地址)$/i],
1437
- ];
1438
-
1439
- function guessMappings(headers) {
1440
- const output = [];
1441
- const usedTargets = new Set();
1442
- for (const sourceField of Array.isArray(headers) ? headers : []) {
1443
- const match = MAPPING_PATTERNS.find(([targetField, pattern]) => !usedTargets.has(targetField) && pattern.test(String(sourceField)));
1444
- if (match) {
1445
- output.push({ sourceField: String(sourceField), targetField: match[0] });
1446
- usedTargets.add(match[0]);
1436
+ const MAPPING_ALIASES = {
1437
+ company_name: ['name', 'company', '公司名称', '单位名称', '企业全称', '公司全称', '主体标识'],
1438
+ credit_no: ['creditCode', 'unified_credit_code', '信用代码', '社会信用代码', '统一信用代码', 'USCC'],
1439
+ reg_no: ['registration_no', '工商注册号'],
1440
+ legal_rep: ['法定代表', '法人代表', 'legalRepresentative', 'legal_person'],
1441
+ reg_capital: ['注册资金'], establish_date: ['成立时间', '企业成立日期', 'establishmentDate'],
1442
+ reg_status: ['工商登记状态'], registered_address: ['企业注册地址', '公司注册地址'],
1443
+ phone: ['mobile', 'tel', 'telephone', '电话', '手机号码', '手机号'],
1444
+ contact_official_website: ['官网', '企业官网', '官方网站地址'],
1445
+ contact_preferred_email: ['首选电子邮箱'],
1446
+ };
1447
+ // 语义不完全等同:只推荐,绝不冒充精确匹配或发起调用。
1448
+ const MAPPING_HINTS = {
1449
+ 地址: ['registered_address', 'mailing_address', 'invoice_address'],
1450
+ address: ['registered_address', 'mailing_address'],
1451
+ 企业地址: ['registered_address', 'mailing_address'], 公司地址: ['registered_address', 'mailing_address'],
1452
+ 网址: ['contact_official_website'], website: ['contact_official_website'],
1453
+ 开业时间: ['establish_date'], 开业日期: ['establish_date'],
1454
+ 行业: ['industry_category', 'qcc_industry'],
1455
+ 法人: ['legal_rep'], 邮箱: ['contact_preferred_email'], email: ['contact_preferred_email'],
1456
+ };
1457
+ function normalizeMappingLabel(value) {
1458
+ return String(value ?? '').normalize('NFKC').toLowerCase().replace(/[\s_\-·]/g, '');
1459
+ }
1460
+ function mappingRecommendations(headers, fields = [...ENRICHMENT_OPTIONS, ...INPUT_ONLY_MAPPING_OPTIONS]) {
1461
+ const rows = (Array.isArray(headers) ? headers : []).map((sourceField) => {
1462
+ const label = normalizeMappingLabel(String(sourceField).replace(/(重复列 \d+)$/, ''));
1463
+ let candidates = fields.filter(([id, name]) => [id, name].some((value) => normalizeMappingLabel(value) === label));
1464
+ let reason = '标准字段名匹配';
1465
+ if (!candidates.length) {
1466
+ candidates = fields.filter(([id]) => (MAPPING_ALIASES[id] || []).some((value) => normalizeMappingLabel(value) === label));
1467
+ reason = '常用别名匹配';
1468
+ }
1469
+ const exact = candidates.length === 1;
1470
+ if (!candidates.length) {
1471
+ const hints = Object.entries(MAPPING_HINTS).find(([key]) => normalizeMappingLabel(key) === label)?.[1] || [];
1472
+ candidates = hints.flatMap((key) => fields.filter(([id]) => id === key));
1473
+ reason = candidates.length ? '含义需确认,点击推荐后采用' : '未识别表头,请手动选择';
1474
+ }
1475
+ return { sourceField: String(sourceField), candidates, automatic: exact, reason };
1476
+ });
1477
+ for (const row of rows) {
1478
+ if (row.automatic && rows.filter((other) => other.automatic && other.candidates[0][0] === row.candidates[0][0]).length > 1) {
1479
+ row.conflict = true;
1480
+ row.reason = '多列推荐同一字段,请选择其中一列;其他列保留原值';
1447
1481
  }
1448
1482
  }
1449
- if (!output.length && Array.isArray(headers) && headers[0]) {
1450
- output.push({ sourceField: String(headers[0]), targetField: 'company_name' });
1483
+ return rows.map((row) => ({ ...row, automatic: row.automatic && !row.conflict }));
1484
+ }
1485
+ function guessMappings(headers, fields) {
1486
+ return mappingRecommendations(headers, fields).filter((row) => row.automatic)
1487
+ .map((row) => ({ sourceField: row.sourceField, targetField: row.candidates[0][0] }));
1488
+ }
1489
+ function mergeRecommendedMappings(headers, mappings, fields) {
1490
+ const output = [...mappings];
1491
+ for (const item of guessMappings(headers, fields)) {
1492
+ if (!output.some((current) => current.sourceField === item.sourceField || current.targetField === item.targetField)) output.push(item);
1451
1493
  }
1452
1494
  return output;
1453
1495
  }
1454
1496
 
1497
+ function MappingPicker({ sourceField, mappings, groups, recommendation, onChange }) {
1498
+ const [query, setQuery] = react.useState('');
1499
+ const value = mappings.find((item) => item.sourceField === sourceField)?.targetField || '';
1500
+ const occupied = (id) => mappings.some((item) => item.sourceField !== sourceField && item.targetField === id);
1501
+ const fields = groups.flatMap(([, , items]) => items);
1502
+ const label = fields.find(([id]) => id === value)?.[1] || '不参与匹配 / 补全';
1503
+ const matches = (id, name) => normalizeMappingLabel([id, name, ...(MAPPING_ALIASES[id] || [])].join(' ')).includes(normalizeMappingLabel(query));
1504
+ return h('div', { className: 'dcAgentMappingRow' },
1505
+ h('span', { title: sourceField }, sourceField), h('b', { 'aria-hidden': 'true' }, '→'),
1506
+ h('div', { style: { minWidth: 0 } },
1507
+ h('details', { className: 'dcAgentMappingPicker', onKeyDown: (event) => {
1508
+ if (event.key === 'Escape' && event.currentTarget.open) {
1509
+ event.preventDefault(); event.stopPropagation();
1510
+ event.currentTarget.open = false; event.currentTarget.querySelector('summary')?.focus();
1511
+ }
1512
+ } },
1513
+ h('summary', { className: 'dcAgentField', 'aria-label': `${sourceField} 当前映射` }, label),
1514
+ h('input', { className: 'dcAgentField', value: query, placeholder: '搜索字段名称 / 英文键 / 别名', 'aria-label': `${sourceField} 搜索映射字段`, onChange: (event) => setQuery(event.target.value) }),
1515
+ h('select', { className: 'dcAgentField', value, 'aria-label': `${sourceField} 字段映射`, onChange: (event) => {
1516
+ onChange(sourceField, event.target.value);
1517
+ const details = event.currentTarget.closest('details');
1518
+ if (details) { details.open = false; details.querySelector('summary')?.focus(); }
1519
+ } },
1520
+ h('option', { value: '' }, '不参与匹配 / 补全'),
1521
+ groups.map(([id, title, items]) => h('optgroup', { key: id, label: title }, items.filter(([key, name]) => key === value || matches(key, name)).map(([key, name]) =>
1522
+ h('option', { key, value: key, disabled: occupied(key) }, `${name}${occupied(key) ? '(已被其他列使用)' : ''}`)))),
1523
+ ),
1524
+ query && !fields.some(([id, name]) => matches(id, name)) ? h('p', { className: 'dcAgentHint', role: 'status' }, '无匹配字段;当前选择保持不变。') : null,
1525
+ ),
1526
+ h('small', { className: 'dcAgentHint' }, value ? `已映射:${label};可手动调整` : recommendation.reason),
1527
+ !value && recommendation.candidates.length ? h('div', { className: 'dcAgentRow', 'aria-label': `${sourceField} 推荐映射` }, recommendation.candidates.map(([id, name]) =>
1528
+ h('button', { key: id, type: 'button', className: 'dcAgentButton', disabled: occupied(id), onClick: () => onChange(sourceField, id) }, `推荐:${name}${occupied(id) ? '(已占用)' : ''}`))) : null,
1529
+ ),
1530
+ );
1531
+ }
1532
+
1533
+ function projectCompletionResult({ rows = [], headers = [], mappings = [], fieldSelection = [] } = {}) {
1534
+ const sourceHeaders = [...new Set(headers)];
1535
+ const selected = [...new Set(fieldSelection)];
1536
+ const pairs = mappings.filter((item) => sourceHeaders.includes(item.sourceField) && selected.includes(item.targetField)
1537
+ && mappings.filter((other) => other.sourceField === item.sourceField).length === 1
1538
+ && mappings.filter((other) => other.targetField === item.targetField).length === 1);
1539
+ const hidden = new Set(pairs.filter((item) => item.sourceField !== item.targetField && !sourceHeaders.includes(item.targetField)).map((item) => item.targetField));
1540
+ const blank = (value) => value == null || (typeof value === 'string' && value.trim() === '');
1541
+ const output = rows.map((row) => {
1542
+ const next = { ...row };
1543
+ const status = row.qcc_match_status;
1544
+ if (!status || ['enriched', 'exact'].includes(status)) {
1545
+ for (const { sourceField, targetField } of pairs) {
1546
+ if (blank(row[sourceField]) && !blank(row[targetField])) next[sourceField] = row[targetField];
1547
+ }
1548
+ }
1549
+ for (const key of hidden) delete next[key];
1550
+ return next;
1551
+ });
1552
+ return {
1553
+ rows: output,
1554
+ headers: [...new Set([...sourceHeaders, ...selected, ...output.flatMap((row) => Object.keys(row))])].filter((key) => !hidden.has(key)),
1555
+ };
1556
+ }
1557
+
1455
1558
  function qualitySummaryFor(rows, mappings) {
1456
1559
  const list = Array.isArray(rows) ? rows : [];
1457
1560
  const anchors = (Array.isArray(mappings) ? mappings : []).filter((mapping) => ['company_name', 'credit_no', 'reg_no'].includes(mapping.targetField));
@@ -1663,7 +1766,8 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
1663
1766
  setTaskTitle: (draft, value) => { draft.taskTitle = String(value ?? ''); },
1664
1767
  setMappings: (draft, value) => { draft.mappings = Array.isArray(value) ? value : []; },
1665
1768
  setMapping: (draft, sourceField, targetField) => {
1666
- const mappings = draft.mappings.filter((item) => item.sourceField !== sourceField && item.targetField !== targetField);
1769
+ if (targetField && draft.mappings.some((item) => item.sourceField !== sourceField && item.targetField === targetField)) return;
1770
+ const mappings = draft.mappings.filter((item) => item.sourceField !== sourceField);
1667
1771
  if (targetField) mappings.push({ sourceField, targetField });
1668
1772
  draft.mappings = mappings;
1669
1773
  },
@@ -3792,6 +3896,7 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
3792
3896
  ? workflowContract.inputOnlyMappingFields.map((field) => [field.id, field.label])
3793
3897
  : INPUT_ONLY_MAPPING_OPTIONS;
3794
3898
  const targetFields = [...uiFieldGroups.flatMap(([, , fields]) => fields), ...inputOnlyMappingFields];
3899
+ const mappingHints = mappingRecommendations(dataset?.headers || [], targetFields);
3795
3900
  const setWorkbenchFieldGroup = (fields, enabledGroup) => {
3796
3901
  const selected = new Set(fieldSelection);
3797
3902
  for (const [id] of fields) {
@@ -3842,19 +3947,13 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
3842
3947
  h('section', { className: 'dcAgentSection' },
3843
3948
  h('h3', null, '字段映射'),
3844
3949
  h('p', { className: 'dcAgentHint' }, '至少映射企业名称、统一社会信用代码或注册号其中一项。未映射列会原样保留,但不参与匹配。'),
3845
- (dataset?.headers || []).map((sourceField) => h('label', { className: 'dcAgentMappingRow', key: sourceField },
3846
- h('span', { title: sourceField }, sourceField),
3847
- h('b', { 'aria-hidden': 'true' }, '→'),
3848
- h('select', {
3849
- className: 'dcAgentField',
3850
- value: mappings.find((mapping) => mapping.sourceField === sourceField)?.targetField || '',
3851
- 'aria-label': `${sourceField} 字段映射`,
3852
- onChange: (event) => actions.setMapping(sourceField, event.target.value),
3853
- },
3854
- h('option', { value: '' }, '不参与匹配 / 补全'),
3855
- targetFields.map(([id, label]) => h('option', { key: id, value: id }, label)),
3856
- ),
3857
- )),
3950
+ h('p', { className: 'dcAgentHint' }, `已映射 ${mappings.length} / ${dataset?.headers?.length || 0} 列。标准字段名和明确别名自动匹配;多义表头、重复列请确认推荐。仅在本机匹配表头,不调用模型或企查查,不改变下方输出字段。`),
3951
+ h('button', { type: 'button', className: 'dcAgentButton', onClick: () => actions.setMappings(mergeRecommendedMappings(dataset?.headers || [], mappings, targetFields)) }, '补充自动映射(保留已有选择)'),
3952
+ mappingHints.map((recommendation, index) => h(MappingPicker, {
3953
+ key: `${index}:${recommendation.sourceField}`, sourceField: recommendation.sourceField,
3954
+ mappings, groups: [...uiFieldGroups, ['input-only', '输入校验字段', inputOnlyMappingFields]],
3955
+ recommendation, onChange: actions.setMapping,
3956
+ })),
3858
3957
  ),
3859
3958
  h('section', { className: 'dcAgentSection' },
3860
3959
  h('h3', null, '任务目标'),
@@ -3872,6 +3971,7 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
3872
3971
  ),
3873
3972
  h('section', { className: 'dcAgentSection' },
3874
3973
  h('h3', null, `输出字段 · 已选 ${fieldSelection.length}`),
3974
+ h('p', { className: 'dcAgentHint' }, '补全结果优先填入已映射原列的空白单元格,保留非空原值;没有对应映射列的已选字段新增列。重复或多义列请先确认映射。'),
3875
3975
  h('div', { className: 'dcAgentRow', 'aria-label': '补全字段批次概览' },
3876
3976
  h('span', { className: 'dcAgentChip' }, '基础字段 30'),
3877
3977
  h('span', { className: 'dcAgentChip' }, '第一批 40'),
@@ -3983,7 +4083,7 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
3983
4083
  stat('失败', qccRun.summary?.failed ?? 0, (qccRun.summary?.failed ?? 0) > 0 ? 'bad' : null),
3984
4084
  ),
3985
4085
  Array.isArray(qccRun.rows) && qccRun.rows.length ? h(DatasetReview, {
3986
- key: qccRun.runId, rows: qccRun.rows, headers: runtime.headers,
4086
+ key: qccRun.runId, ...projectCompletionResult({ rows: qccRun.rows, headers: runtime.headers, mappings: cachedTask?.mappings || mappings, fieldSelection: cachedTask?.fieldSelection || fieldSelection }),
3987
4087
  title: '企查查匹配补全结果', expectedCount: qccRun.summary?.totalRows,
3988
4088
  onError: actions.setError,
3989
4089
  }) : null,
@@ -4314,6 +4414,10 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
4314
4414
  isImagePathEntry,
4315
4415
  requestPromptImage,
4316
4416
  guessMappings,
4417
+ projectCompletionResult,
4418
+ mappingRecommendations,
4419
+ mergeRecommendedMappings,
4420
+ MappingPicker,
4317
4421
  deactivateCleaningSession,
4318
4422
  installSessionOwnershipBridge,
4319
4423
  installNewSessionBridge,
package/lib/engine.js CHANGED
@@ -9,6 +9,47 @@
9
9
  * - 引擎层返回完整明细(供下载/入库),模型工具层只回摘要(安全边界在工具层)。
10
10
  */
11
11
 
12
+ // 重复表头必须获得稳定、无碰撞的键,否则行对象会覆盖前一列原值。
13
+ function uniqueHeaders(values) {
14
+ const bases = Array.from(values, (value, i) => String(value ?? '').trim() || `col_${i + 1}`);
15
+ const reserved = new Set(bases);
16
+ const used = new Set();
17
+ return bases.map((base) => {
18
+ let key = base;
19
+ let ordinal = 2;
20
+ // 原表也可能包含同名的重复列标记,不能覆盖它。
21
+ while (used.has(key) || (key !== base && reserved.has(key))) key = `${base}(重复列 ${ordinal++})`;
22
+ used.add(key);
23
+ return key;
24
+ });
25
+ }
26
+
27
+ /** 原列补空投影:由已确认映射决定目的列,非空原值(包括 0/false)不覆盖。 */
28
+ export function projectCompletionResult({ rows = [], headers = [], mappings = [], fieldSelection = [] } = {}) {
29
+ const sourceHeaders = [...new Set(headers)];
30
+ const selected = [...new Set(fieldSelection)];
31
+ const pairs = mappings.filter((item) => sourceHeaders.includes(item.sourceField) && selected.includes(item.targetField)
32
+ && mappings.filter((other) => other.sourceField === item.sourceField).length === 1
33
+ && mappings.filter((other) => other.targetField === item.targetField).length === 1);
34
+ const hidden = new Set(pairs.filter((item) => item.sourceField !== item.targetField && !sourceHeaders.includes(item.targetField)).map((item) => item.targetField));
35
+ const blank = (value) => value == null || (typeof value === 'string' && value.trim() === '');
36
+ const output = rows.map((row) => {
37
+ const next = { ...row };
38
+ const status = row.qcc_match_status;
39
+ if (!status || ['enriched', 'exact'].includes(status)) {
40
+ for (const { sourceField, targetField } of pairs) {
41
+ if (blank(row[sourceField]) && !blank(row[targetField])) next[sourceField] = row[targetField];
42
+ }
43
+ }
44
+ for (const key of hidden) delete next[key];
45
+ return next;
46
+ });
47
+ return {
48
+ rows: output,
49
+ headers: [...new Set([...sourceHeaders, ...selected, ...output.flatMap((row) => Object.keys(row))])].filter((key) => !hidden.has(key)),
50
+ };
51
+ }
52
+
12
53
  /** 去掉 BOM、按 CSV/RFC4180 子集解析为 { headers, rows }。 */
13
54
  export function parseCsv(text) {
14
55
  const src = String(text ?? '').replace(/^\uFEFF/, '');
@@ -48,7 +89,7 @@ export function parseCsv(text) {
48
89
  const nonEmpty = records.filter((r) => r.some((c) => c.trim() !== ''));
49
90
  if (nonEmpty.length === 0) return { headers: [], rows: [] };
50
91
 
51
- const headers = nonEmpty[0].map((h, i) => (String(h).trim() || `col_${i + 1}`));
92
+ const headers = uniqueHeaders(nonEmpty[0]);
52
93
  const rows = nonEmpty.slice(1).map((r) => {
53
94
  const o = {};
54
95
  headers.forEach((h, i) => { o[h] = r[i] === undefined ? '' : String(r[i]); });
@@ -72,7 +113,7 @@ export async function parseXlsx(buffer) {
72
113
  if (!sheetName) return { headers: [], rows: [] };
73
114
  const aoa = XLSX.utils.sheet_to_json(wb.Sheets[sheetName], { header: 1, defval: '', raw: false });
74
115
  if (!aoa.length) return { headers: [], rows: [] };
75
- const headers = aoa[0].map((h, i) => (String(h ?? '').trim() || `col_${i + 1}`));
116
+ const headers = uniqueHeaders(aoa[0]);
76
117
  const rows = aoa.slice(1).map((r) => {
77
118
  const o = {};
78
119
  headers.forEach((h, i) => { o[h] = r[i] === undefined || r[i] === null ? '' : String(r[i]); });
package/lib/qcc-runs.js CHANGED
@@ -229,7 +229,7 @@ export class G5RunStore {
229
229
  if (result.status === 'enriched') {
230
230
  record.rows[index] = {
231
231
  ...row,
232
- ...result.fields,
232
+ ...Object.fromEntries(Object.entries(result.fields || {}).filter(([key]) => row[key] == null || (typeof row[key] === 'string' && row[key].trim() === ''))),
233
233
  qcc_match_status: 'enriched',
234
234
  qcc_source: 'qcc-mcp',
235
235
  };
package/lib/qcc.js CHANGED
@@ -1027,7 +1027,7 @@ export class QccHostBridge {
1027
1027
  if (result?.status === 'enriched') {
1028
1028
  return {
1029
1029
  ...row,
1030
- ...result.fields,
1030
+ ...Object.fromEntries(Object.entries(result.fields || {}).filter(([key]) => row[key] == null || (typeof row[key] === 'string' && row[key].trim() === ''))),
1031
1031
  qcc_match_status: 'enriched',
1032
1032
  qcc_source: 'qcc-mcp',
1033
1033
  };
package/lib/web.js CHANGED
@@ -537,6 +537,7 @@ export function mountWebRoutes(wctx, { logger, report, TOOL_NAME, SKILL_NAME })
537
537
  rows: payload.rows,
538
538
  headers: payload.headers,
539
539
  fieldSelection: readyTask.fieldSelection,
540
+ mappings: readyTask.mappings,
540
541
  exceptionRows: payload.exceptionRows,
541
542
  baseName: payload.baseName || readyTask.title,
542
543
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-data-cleaning-agent",
3
- "version": "0.8.10",
3
+ "version": "0.8.11",
4
4
  "description": "Clean, complete, and profile enterprise name lists in DeepSeek Harness — a data cleaning & completion agent plugin with local CSV/XLSX/JSON engine and optional Qichacha (QCC) MCP enrichment. Maintained by Qichacha/QCC.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",