From de869a88f264966da6f35f7dd78079086a08b375 Mon Sep 17 00:00:00 2001 From: BlueRose <378100977@qq.com> Date: Wed, 15 Apr 2026 10:36:52 +0800 Subject: [PATCH] vault backup: 2026-04-15 10:36:52 --- .../UnrealEngine/Graphify 知识图谱.md | 129 +++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/07-Other/AI/AI Agent/UnrealEngine/Graphify 知识图谱.md b/07-Other/AI/AI Agent/UnrealEngine/Graphify 知识图谱.md index ed20900..80661b1 100644 --- a/07-Other/AI/AI Agent/UnrealEngine/Graphify 知识图谱.md +++ b/07-Other/AI/AI Agent/UnrealEngine/Graphify 知识图谱.md @@ -172,4 +172,131 @@ graphify install # 自动向 CLAUDE.md 注入架构索引规则 ### 总结建议 - **如果你追求立即理解代码逻辑:** 优先配置 **Graphify**。它能让 Claude 从“逐行看代码”进化到“看地图写代码”。 -- **如果你在进行长期复杂的特性开发:** 引入 **Graphiti** 作为 Claude 的“开发日志”,防止它忘记你之前的架构决策。 \ No newline at end of file +- **如果你在进行长期复杂的特性开发:** 引入 **Graphiti** 作为 Claude 的“开发日志”,防止它忘记你之前的架构决策。 + +--- + +# 具体执行方案 +--- + +**Gemini** + +实现这一方案的关键在于将 `graphify` 从一个“傻瓜式扫描器”转变为一个“受控的提取引擎”。针对 Unreal Engine 的庞大规模,我们需要通过精确的路径控制和排除规则来实施。 + +以下是具体的执行方法与命令: + +### 1\. 离线构建 Engine 基础图谱 (The Static Atlas) + +由于引擎源码几乎不变量,我们只需构建一次。 + +**执行策略:** 只索引 `Public` 接口,忽略所有实现(`.cpp` )和私有目录。 + +**具体命令:** + +``` +# 进入引擎 Source 目录 +cd /Users/Shared/Epic\ Games/UE_5.4/Engine/Source + +# 执行 graphify 扫描 +# --include: 仅包含 Public 文件夹下的头文件,这是剪枝的核心 +# --ignore: 排除掉极其庞大的第三方库和中间件 +graphify index . \ + --output ~/ue_engine_full.graph \ + --include "**/Public/**/*.h" \ + --ignore "ThirdParty/**,Developer/**,Programs/**,Intermediate/**,**/Private/**" \ + --max-depth 5 +``` + +**提示:** 这一步在 M1 Ultra 上可能仍需数十分钟。建议通过 `--max-depth` 限制继承链的抓取深度,通常设置为 5 已经能覆盖 90% 的关键基类(如 `UObject` -> `AActor` -> `APawn` -> `ACharacter` )。 + +--- + +### 2\. 针对 UE 的“剪枝”策略配置文件 + +为了避免长命令,建议在项目根目录创建一个 `.graphifyconfig` (或工具支持的配置文件)。 + +**精细化剪枝逻辑:** + +- **反射优先:** 重点提取带有 `GENERATED_BODY()` 的类。 +- **模块白名单:** 如果你主要做游戏逻辑,只包含以下核心模块: + - `Runtime/Engine` + - `Runtime/Core` + - `Runtime/CoreUObject` + - `Runtime/InputCore` + +**自动化剪枝脚本示例 (Python):** 如果你发现 `graphify` 无法过滤细碎路径,可以用这个脚本生成一个“干净”的临时符号链接目录供其索引: + +``` +import os +from pathlib import Path + +source_dir = Path("/Users/Shared/Epic Games/UE_5.4/Engine/Source/Runtime") +target_dir = Path("./UE_Thin_Source") + +# 仅挑选核心模块的 Public 目录建立软链接 +core_modules = ['Engine', 'Core', 'CoreUObject', 'RenderCore'] + +for module in core_modules: + pub_path = source_dir / module / "Public" + if pub_path.exists(): + os.makedirs(target_dir / module, exist_ok=True) + os.symlink(pub_path, target_dir / module / "Public") +``` + +然后对 `UE_Thin_Source` 运行 `/graphify` 。 + +--- + +### 3\. 实时构建 Project 业务图谱 (The Dynamic Layer) + +业务代码变动频繁,需要更轻量、更高频的更新。 + +**执行命令:** + +``` +# 在你的项目根目录执行,排除插件和中间文件 +graphify index ./Source \ + --output ./project_current.graph \ + --ignore "**/Intermediate/**,**/Binaries/**" \ + --watch +``` + +**进阶:结合 ClaudeCode 的 `CLAUDE.md`** 在项目根目录的 `CLAUDE.md` 中添加指令,让 Claude 意识到有两个图谱存在: + +``` +### Knowledge Graph Context +- **Static Engine Graph:** \`~/ue_engine_full.graph\` (Read-only, contains UE5 API) +- **Project Graph:** \`./project_current.graph\` (Updated on save, contains business logic) +- **Rule:** When a class is prefixed with 'U' or 'A' and not in Project Graph, query Engine Graph via \`mcp-graph-tool\`. +``` + +--- + +### 4\. 实施 Multi-Graph 挂载的 MCP 方案 + +要让 ClaudeCode 真正理解这两个图谱,你需要一个简单的 MCP Server 来做中转。 + +**开发建议:** + +1. **加载:** 启动时同时 Load 两个 `.graph` 文件到内存。 +2. **查询逻辑:** + ``` + async function searchClass(className) { + // 1. 先查项目图谱 + let result = projectGraph.find(className); + if (!result) { + // 2. 如果没找到,且符合 UE 命名规范,查引擎图谱 + result = engineGraph.find(className); + } + return result; + } + ``` + +### 总结执行清单: + +1. **环境准备:** 确定 UE 引擎路径。 +2. **首次索引:** 使用上述“剪枝命令”生成 `ue_engine_full.graph` ,存放在家目录作为持久缓存。 +3. **项目配置:** 在项目内运行带有 `--watch` 的 `graphify` 。 +4. **注入 Claude:** 编写 MCP Server 将两个图谱的查询接口暴露给 ClaudeCode。 + +这种“重引擎索引 + 轻业务监控”的模式,能保证在 64GB 内存的本地环境下,ClaudeCode 既能秒回 API 调用问题,又能深刻理解你的业务代码耦合。你想尝试编写这个 MCP 路由器的代码吗? \ No newline at end of file