跳到正文
Skillpedia
通用编程48k · #4326

data-structure-protocol

它能做什么

这个工具可以帮助AI理解代码项目的结构、各部分之间的联系,以及它们存在的原因。这样AI就能更高效地浏览和修改代码,而无需把所有内容重新读一遍。

适用场景

  • ✓当AI需要理解代码项目是如何组织的时。
  • ✓在进行重大代码修改之前,用来了解可能受影响的部分。
  • ✓当你希望AI帮你梳理或整理项目结构时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/data-structure-protocol/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/data-structure-protocol/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我该如何使用DSP来了解我项目中各模块之间的依赖关系?”

每周 5 个新技能,1 分钟读完。

工作原理

DSP会把代码转换成一张图谱,其中每个部分是一个“节点”,部分之间的连接是“边”。它会把每个部分的用途和连接的原因都记录在简单的文本文件中。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Data Structure Protocol (DSP)

LLM coding agents lose context between tasks. On large codebases they spend most of their tokens on "orientation" — figuring out where things live, what depends on what, and what is safe to change. DSP solves this by externalizing the project's structural map into a persistent, queryable graph stored in a .dsp/ directory next to the code.

DSP is NOT documentation for humans and NOT an AST dump. It captures three things: meaning (why an entity exists), boundaries (what it imports and exposes), and reasons (why each connection exists). This is enough for an agent to navigate, refactor, and generate code without loading the entire source tree into the context window.

When to Use

Use this skill when:

  • The project has a .dsp/ directory (DSP is already set up)
  • The user asks to set up DSP, bootstrap, or map a project's structure
  • Creating, modifying, or deleting code files in a DSP-tracked project (to keep the graph updated)
  • Navigating project structure, understanding dependencies, or finding specific modules
  • The user mentions DSP, dsp-cli, .dsp, or structure mapping
  • Performing impact analysis before a refactor or dependency replacement

Core Concepts

Code = graph

DSP models the codebase as a directed graph. Nodes are entities, edges are imports and shared/exports.

Two entity kinds exist:

  • Object: any "thing" that isn't a function (module/file/class/config/resource/external dependency)
  • Function: an exported function/method/handler/pipeline

Identity by UID, not by file path

Every entity gets a stable UID: obj-<8hex> for objects, func-<8hex> for functions. File paths are attributes that can change; UIDs survive renames, moves, and reformatting.

For entities inside a file, the UID is anchored with a comment marker in source code:

// @dsp func-7f3a9c12
export function calculateTotal(items) { ... }
# @dsp obj-e5f6g7h8
class UserService:

Every connection has a "why"

When an import is recorded, DSP stores a short reason explaining why that dependency exists. This lives in the exports/ reverse index of the imported entity. A dependency graph without reasons tells you what imports what; reasons tell you what is safe to change and who will break.

Storage format

Each entity gets a small directory under .dsp/:

.dsp/
├── TOC                        # ordered list of all entity UIDs from root
├── obj-a1b2c3d4/
│   ├── description            # source path, kind, purpose (1-3 sentences)
│   ├── imports                # UIDs this entity depends on (one per line)
│   ├── shared                 # UIDs of public API / exported entities
│   └── exports/               # reverse index: who imports this and why
│       ├── <importer_uid>     # file content = "why" text
│       └── <shared_uid>/
│           ├── description    # what is exported
│           └── <importer_uid> # why this specific export is imported
└── func-7f3a9c12/
    ├── description
    ├── imports
    └── exports/

Everything is plain text. Diffable. Reviewable. No database needed.

Full import coverage

Every file or artifact that is imported anywhere must be represented in .dsp as an Object — code, images, styles, configs, JSON, wasm, everything. External dependencies (npm packages, stdlib, etc.) are recorded as kind: external but their internals are never analyzed.

How It Works

Initial Setup

The skill relies on a standalone Python CLI script dsp-cli.py. If it is missing from the project, download it:

curl -O https://raw.githubusercontent.com/k-kolomeitsev/data-structure-protocol/main/skills/data-structure-protocol/scripts/dsp-cli.py

Requires Python 3.10+. All commands use python dsp-cli.py --root <project-root> <command>.

Bootstrap (initial mapping)

If .dsp/ is empty, traverse the project from root entrypoint(s) via DFS on imports:

  1. Identify root entrypoints (package.json main, framework entry, main.py, etc.)
  2. Document the root file: create-object, create-function for each export, create-shared, add-import for all dependencies
  3. Take the first non-external import, document it fully, descend into its imports
  4. Backtrack when no unvisited local imports remain; continue until all reachable files are documented
  5. External dependencies: create-object --kind external, add to TOC, but never descend into node_modules/site-packages/etc.

…

常见问题

这里的“图”是什么意思?

图就像一张连接关系图。你可以把代码的各个部分想象成城市,把它们之间的联系想象成道路。DSP借助这张图展示你的代码各部分是如何相互连接的。

为什么用UID而不用文件路径?

UID(通用唯一标识符)就像永久的名字。即使你重命名或移动文件,UID也不会改变,从而确保连接关系保持正确。而文件路径是可能改变的。

“每个连接都有原因”是什么意思?

除了记录某个代码部分使用了另一个部分,DSP还会记录这种连接的原因。这有助于AI判断删除或修改某个连接是否安全,以免破坏项目的其他部分。

详情

作者的原始描述

Give agents persistent structural memory of a codebase — navigate dependencies, track public APIs, and understand why connections exist without re-reading the whole repo.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4326
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能