Luke-Yong/dsh-plugin-knowledge-graph

插件Plugin 原生Native ⭐ 4 MIT

dsh-plugin-knowledge-graph 适用于 Deepseek Harness

项目介绍Project Overview

DSH 知识图谱插件暴露 read_graph 工具,基于工作区根目录构建内存图谱,记录文件、目录、导出符号及依赖关系。通过 structureexportsimports_ofexporters_ofdependentsunused_imports 等查询,让智能体快速回答结构与依赖问题。符号解析支持 TypeScript/JavaScript(编译器 API)和 Python(模块级 def/class/赋值)。适用于需要跨文件依赖分析的大型代码库。注意:项目处于早期阶段,行为和接口可能变动;root 默认值 process.cwd() 可能跨越多个项目,必须显式传入单工作区路径,避免 structure 误入相邻目录树。

The DSH knowledge graph plugin exposes a read_graph tool that builds an in-memory graph of files, directories, exported symbols, and their relationships for a given workspace root. It supports queries like structure, exports, imports_of, exporters_of, dependents, and unused_imports, parsing TypeScript/JavaScript via the compiler API and Python module-level bindings. Use it when an agent needs fast structural or dependency answers across a codebase instead of grepping. Note: the project is in its infancy and its surface may change, and the default root (process.cwd()) can span sibling projects, so always pass an explicit workspace path.

或使用命令行安装(适合开发者)Or use CLI install (for developers)

命令行安装CLI Install

dsh plugin --profile web add github:Luke-Yong/dsh-plugin-knowledge-graph

Luke-Yong/dsh-plugin-knowledge-graph 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-plugin-knowledge-graph

A DeepSeek Harness (DSH) plugin that exposes a read_graph tool backed by a codebase knowledge graph. The graph tracks every file, directory, exported symbol, and their relationships so an agent can answer structural and dependency questions faster than grepping or reading files.

Status: infancy. This project is in its infancy stage. Execution behavior, the query surface, and compatibility may change while the project is iterated on and tested by the open source community.

Derived work. This project is derived from the knowledge graph tool in Luke-Yong/H, adapted to DeepSeek Harness's "everything is a plugin" model.

What it does

Given a workspace root, the plugin builds an in-memory graph and answers queries such as:

  • structure — print the full directory tree
  • exports <file> — list every symbol exported by a file
  • imports_of <file> — list symbols a file imports (with their source files; stdlib/third-party imports are tagged)
  • exporters_of <symbol> — find which files export a symbol
  • dependents <file> — find which files import from a file
  • unused_imports <file> — list imports never referenced in the file

Symbols are parsed from TypeScript/JavaScript (via the TypeScript compiler API) and Python (module-level def, class, and name = value bindings).

Graph model

The graph uses three node types and four edge types:

Nodes Meaning
dir A directory
file A source file
symbol An exported symbol (function, class, const, type, interface, enum, default)
Edges Meaning
CONTAINS Structural parent → child (dir → dir/file, file → symbol)
EXPORTS File → symbol it exports
IMPORTS File-level dependency (file → file)
IMPORTS_SYMBOL Precise symbol-level dependency (file → symbol)

Installation

Install with the DSH CLI into a profile:

dsh plugin --profile web add github:Luke-Yong/dsh-plugin-knowledge-graph

Pin to a specific commit for reproducibility:

dsh plugin --profile web add github:Luke-Yong/dsh-plugin-knowledge-graph#<commit-sha>

Usage

The plugin registers a single tool, read_graph, on ctx.tools. Its parameters:

Parameter Type Required Description
query string yes Query string in <query_type> <target> form
root string no Absolute workspace root to graph. Defaults to process.cwd()

Root hygiene: the root default (process.cwd()) may be a parent directory containing several independent projects. Always pass an explicit root pointing at the single workspace you are working in, so structure doesn't descend into sibling trees.

Example queries:

exports src/index.ts
exporters_of buildKnowledgeGraph
imports_of src/query.ts
dependents src/knowledgeGraph.ts
unused_imports app.py
structure

Project structure

src/
  index.ts         Plugin entry — registers the read_graph tool
  knowledgeGraph.ts  Graph builder (filesystem walk, import/export parsing, serialization)
  query.ts         Query engine (runGraphQuery)

Building

npm run build   # tsc -p tsconfig.json

Output is emitted to dist/ (dist/index.js is the package entry point).

License

MIT

上一个 Prev dsh-llm-codex 下一个 Next jarvis-index