$npx -y skills add kweaver-ai/kweaver-dip --skill bkn-backfill将绑定/映射结果写回 .bkn 文件。
| 1 | # BKN 回填 |
| 2 | |
| 3 | 公约:`../_shared/contract.md` |
| 4 | |
| 5 | ## 做什么 |
| 6 | |
| 7 | 把 `bkn-bind` 和 `bkn-map` 的结果合并,写回 `.bkn` 文件,完成数据视图绑定闭环。 |
| 8 | |
| 9 | ## 输入 |
| 10 | |
| 11 | - `binding_decision_list`:对象级绑定结果 |
| 12 | - `property_mapping_draft`:属性级映射结果 |
| 13 | - `relation_binding_result`:`bkn-relation-bind` 的输出(关系类型 + 中间视图) |
| 14 | - `relation_mapping_draft`:`bkn-map` 的关系类映射结果 |
| 15 | - `network_dir`:网络目录(`.bkn` 文件位于 `{network_dir}/bkn/`) |
| 16 | |
| 17 | ## 流程 |
| 18 | |
| 19 | 1. **属性回灌门禁**(P1-2): |
| 20 | - 读取 `{network_dir}/pipeline_state.yaml`(文件不存在时视为 `map_completed` 缺失) |
| 21 | - **`map_completed == true`** → 继续 |
| 22 | - **`map_completed == skipped`**(`bind_mode == deferred` 场景)→ 记录 `map_status: skipped (deferred)`,继续 |
| 23 | - **`map_completed` 不存在或为 false**: |
| 24 | - 用户明确要求跳过 → 在 `pipeline_state.yaml` 中追加 `skipped_steps: [bkn-map]`,输出警告后继续 |
| 25 | - 否则,**阻断并回交 pipeline 调度**,输出: |
| 26 | `"bkn-backfill 需要 bkn-map 先执行完成(map_completed 未就绪)。请 pipeline 调度 bkn-map 后再调用本 skill。"` |
| 27 | 2. 合并绑定变更 + 属性变更 + 映射状态为统一差异清单 |
| 28 | 3. **存储位置过滤**: |
| 29 | - 跳过 `存储位置: local` 的对象(本地对象无需数据视图绑定,不参与回填) |
| 30 | - 在输出摘要中单独列出被跳过的 local 对象 |
| 31 | 4. **对象类回填**(仅 platform 对象): |
| 32 | - Data Source 绑定值替换(名称/技术名 → 稳定 `view_id`) |
| 33 | - Mapped Field 更新为数据视图真实字段名 |
| 34 | - 数据视图中不存在的属性:默认标注 Mapped Field 为 `-`(保留属性定义,便于后续补绑);用户可指定删除该行 |
| 35 | - 不改动 Description 或其他业务语义字段 |
| 36 | 5. **级联修正**(关键改进): |
| 37 | - 构建 `rename_map`:`{object_id: {old_property_name → new_property_name}}` |
| 38 | - 来源 1:`bkn-map` 的 `property_regen_summary.rename` 动作(draft 属性名 → 视图字段名) |
| 39 | - 来源 2:用户手动指定的属性重命名 |
| 40 | - 扫描 `{network_dir}/bkn/relation_types/*.bkn` 的 Mapping Rules,将 Source Property / Target Property 中引用了已重命名属性的值替换 |
| 41 | - 扫描 `{network_dir}/bkn/action_types/*.bkn` 的 Parameter Binding / Pre-conditions,将 Binding 列中引用了已重命名属性的值替换 |
| 42 | - 级联修正只改引用名,不改语义 |
| 43 | 6. **关系类回填**(新增): |
| 44 | - 仅处理 `relation_binding_result` 中 `status: confirmed` 的关系 |
| 45 | - **direct 类型**: |
| 46 | - 回填 Endpoint 表的 Type 列为 `direct` |
| 47 | - 回填 Mapping Rules 表(Source Property → Target Property) |
| 48 | - **data_view 类型**: |
| 49 | - 回填 Endpoint 表的 Type 列为 `data_view` |
| 50 | - 回填 Mapping View 表(Type = data_view, ID = intermediate_view_id) |
| 51 | - 回填 Source Mapping 表(Source Property → View Property) |
| 52 | - 回填 Target Mapping 表(View Property → Target Property) |
| 53 | - **pending 关系**: |
| 54 | - 仅回填 Endpoint 表(Type 列保留占位符或留空) |
| 55 | - Mapping View / Source/Target Mapping 段不生成 |
| 56 | - 跳过 `relation_mapping_quality: blocked` 的关系(在输出中标记) |
| 57 | 7. **推送前关系映射完整性预检**(执行 `../_shared/prepush-validation.md`): |
| 58 | - 检查所有 `relation_types` 的 Source/Target Property 是否存在于对应对象的 Data Properties |
| 59 | - 检查所有 `action_types` 的 Parameter Binding 属性是否存在于绑定对象的 Data Properties |
| 60 | - 检查 Concept Group 成员和 Network Overview 一致性 |
| 61 | - 检查 data_view 类型关系的 Mapping View ID 是否非空 |
| 62 | - 检查 data_view 类型关系的 Source/Target Mapping 属性是否存在于对应视图 schema |
| 63 | - `local` 对象跳过属性存在性检查,但仍参与对象存在性检查 |
| 64 | - `pending` 关系仅 warning,不阻断 |
| 65 | - **预检失败 → 阻断写入,列出全部错误**,提示修复后重试 |
| 66 | 8. 执行写入(写入 `{network_dir}/bkn/` 下对应的 `.bkn` 文件) |
| 67 | 9. 回读校验(文件存在、关键字段已替换、级联引用一致、关系类结构完整) |
| 68 | 10. 输出精简摘要,提示用户检查 |
| 69 | |
| 70 | ## 输出 |
| 71 | |
| 72 | ```yaml |
| 73 | backfill_plan: |
| 74 | binding_replacements: [{object, old_value, new_view_id}] |
| 75 | property_changes: [{object, property, action, layer}] |
| 76 | cascade_renames: [{file, table, old_ref, new_ref}] |
| 77 | # 新增:关系类回填计划 |
| 78 | relation_replacements: |
| 79 | - 关系ID: "" |
| 80 | 关系名称: "" |
| 81 | 关系类型: direct | data_view |
| 82 | actions: |
| 83 | - action: "" # fill_endpoint_type / fill_mapping_view / fill_source_mapping / fill_target_mapping |
| 84 | target_section: "" # Endpoint / Mapping View / Source Mapping / Target Mapping |
| 85 | old_value: "" |
| 86 | new_value: "" |
| 87 | skipped_local_objects: [对象名] |
| 88 | skipped_pending_relations: [关系名] # pending 关系,跳过回填 |
| 89 | map_gate: {map_completed: true|false|skipped, user_skipped_map: true|false, blocked_for_map: true|false} |
| 90 | prepush_validation: {status, errors} # 写入前预检结果 |
| 91 | backfill_status: success | partial | failed |
| 92 | verification: |
| 93 | files_checked: 0 |
| 94 | fields_replaced: 0 |
| 95 | cascade_refs_fixed: 0 |
| 96 | relations_filled: 0 # 新增:已回填的关系数量 |
| 97 | pending_relations: 0 # 新增:pending 关系数量 |
| 98 | issues: [] |
| 99 | ``` |
| 100 | |
| 101 | ## 约束 |
| 102 | |
| 103 | - 只写 Data Source、Mapped Field 和级联引用,不改业务语义字段 |
| 104 | - 级联修正仅限属性名引用,不修改关系方向或动作语义 |
| 105 | - **写入前必须执行 `../_shared/prepush-validation.md` 预检,失败则阻断写入** |
| 106 | - **执行回填前必须确认 `map_completed == true` 或 `skipped`,否则阻断并回交 pipeline 调度** |
| 107 | - 写入后必须回读校验,包括级联引用一致性 |
| 108 | - 回填失败时保留差异清单,可重试 |