用途:在代码库问答中,借助项目知识图谱回答关于代码结构、依赖与架构的问题。
主要能力:读取 .ua/knowledge-graph.json(若存在旧目录 .understand-anything/ 则优先使用其 knowledge-graph.json)。图谱包含 project 元数据、nodes(file、function、class、module、concept 及 config、document、service、table、endpoint、pipeline、schema、resource 等,另有 domain、flow、step、article、entity、topic、claim、source)、edges(imports、contains、calls、depends_on、configures、documents、deploys、triggers、contains_flow、flow_step、related、cites 等)、layers 与 tour。
使用方式:先解析数据目录,命令为 UA_DIR=$([ -d .understand-anything ] && echo .understand-anything || echo .ua),并确认 $UA_DIR/knowledge-graph.json 存在,否则提示先运行 /understand。使用前检查图谱新鲜度:读取 project.gitCommitHash,解析为提交后与 git rev-parse HEAD 比较,并检查项目范围内的已提交与工作区变更,命令包括 git rev-parse --verify --end-of-options "${GRAPH_COMMIT_RAW}^{commit}"、git rev-parse HEAD、git diff --name-only "$GRAPH_COMMIT" HEAD -- .、git diff --cached --name-only -- .、git diff --name-only -- .、git ls-files --others --exclude-standard -- .。-- . 路径限定必须保留,避免同级 monorepo 项目提交误判为过期;仅哈希不一致而项目差异为空时不算过期。所有命令输出需忽略所选数据目录。若发现项目文件变更,应先警告图谱上下文可能遗漏这些改动,并建议运行 /understand 刷新。仅当 GRAPH_COMMIT_RAW 能成功解析时才运行提交差异;缺失或无效时给出简短警告并继续。随后只读取 project 元数据,用 Grep 在 name、summary、tags 中检索查询关键词,记录匹配节点 id,再在 edges 中查找这些 id 以获取上下游 1 跳子图,并检索 layers 了解所属架构层。最后仅基于相关子图作答,引用具体文件、函数与关系,说明相关层及原因;若无匹配节点,应说明并建议图谱中的相关术语。
限制:依赖已生成的知识图谱,未运行 /understand 时无法使用;图谱可能因代码变更而过期;回答范围受图谱内容约束。