返回资讯中心
外部精选
软件工程
#开发者实时流

Strand:基于 Rust 的即时打开单文件图依赖分析工具

来源标题:Strand- dependency/impact analysis on instant-open, single-file graphs

Strand 是一个用 Rust 编写的依赖与影响分析工具,基于内存映射的 CSR 图引擎,可在几秒内回答「改动 X 会破坏什么」,即使图包含数千万条边。它无需服务器和查询语言,支持构建、影响分析和路径追溯等命令,其中的 strand-store 被定位为「图界的 SQLite」,具备事务、快照和预写日志。项目还提供导入器、命令行工具和桌面 GUI。

Hacker News 最新B33332026/11/19 · 今天30 分钟阅读

以下正文由 AI 翻译自 Hacker News 最新(原文版权归原站所有),可能存在偏差,重要内容请以原文为准。

这是一个基于快速、内存映射的 CSR(压缩稀疏行)图引擎构建的 Rust 依赖与影响分析工具。Strand 能在一两秒内回答「如果我改了 X,什么会坏掉?」这个问题,即使图的边数达到数千万条,也无需服务器、无需查询语言:

$ strand build deps.csv -o deps.strand $ strand impact deps.strand serde_json impact of [serde_json]: 20 affected (6 direct, 14 transitive) $ strand why deps.strand my-app serde_json my-app -> serde -> serde_json

为什么选择 Strand

现有工具要么是内存中的库(petgraph、igraph、NetworkX),要么是服务器数据库(Neo4j)。Strand 的定位:

strand-store 是一个可嵌入的读写图存储——「图领域的 SQLite」——支持事务、快照、预写日志(write-ahead log)、崩溃安全的压缩(compaction),并且能在合并视图上运行同一套分析算法。

crates/ strand-core/ 文件格式、mmap 读取器、构建器、算法 strand-import/ 导入器(cargo metadata JSON、CSV/TSV 边列表) strand-cli/ strand 二进制 strand-store/ 可嵌入读写存储(base + WAL delta) strand-gui/ 桌面 GUI(eframe/egui),用于浏览和分析 docs/ FORMAT.md 二进制格式规范(规范性文档,.strand + .strandb) testdata/ 测试和文档使用的示例图

测试位于各 crate 的 tests/ 目录中(参见 Testing)。

预编译二进制——从 Releases 下载对应平台的压缩包,并用 SHA256SUMS.txt 校验。每个压缩包包含 strand(CLI)和 strand-gui(桌面 GUI)。

这些二进制未签名:Windows SmartScreen(「Windows 已保护你的电脑」)和 macOS Gatekeeper(「无法打开,因为无法验证开发者」)会在首次运行时发出警告。这是预期行为——右键 → 打开(macOS)或「更多信息」→「仍要运行」(Windows),或者用下面的方式从源码构建。

从 crates.io 安装(需要 Rust 工具链,无需克隆仓库):

cargo install strand-cli strand-gui # full Strand: CLI + GUI cargo install strand-cli # CLI only (strand) cargo install strand-gui # GUI only (strand-gui)

重复运行上述任意命令会安装最新发布版本——同一条命令即可更新已有安装。

cd path/to/Strand cargo install --path crates/strand-cli # the strand CLI cargo install --path crates/strand-gui # the desktop GUI

cargo install 会把二进制放到 %USERPROFILE%.cargo\bin(Windows 上为 C:\Users<you>.cargo\bin),rustup 会自动将其加入 PATH。若使用预编译二进制,则将压缩包解压到你选择的文件夹(例如 %LOCALAPPDATA%\Programs\strand),如果该文件夹未被自动识别,再将其加入用户 PATH。

From an edge list (src,dst[,weight]; "src depends on dst"):

strand build deps.csv -o deps.strand

Multiple inputs merge into one graph (names must match across files):

strand build frontend.csv backend.csv meta.json -o all.strand

From cargo metadata:

cargo metadata --format-version 1 > meta.json strand build meta.json -o deps.strand

Or straight from lockfiles/manifests (auto-detected by filename):

strand build Cargo.lock -o deps.strand # Rust strand build package-lock.json -o deps.strand # npm strand build poetry.lock -o deps.strand # Python/poetry strand build go.mod -o deps.strand # Go strand build pom.xml -o deps.strand # Maven

(--format cargo-lock|npm-lock|poetry-lock|go-mod|pom overrides)

Scan a project folder and build a source-level dependency graph

(skips target/, .git/, node_modules/, and build-output dirs like

.next/, dist/, out/, coverage/, .turbo/, .firebase/):

strand scan ./my-project -o deps.strand

Rust (mod/use/#[path]/include!/...crate paths), Python (import/from,

relative + absolute imports resolved against ancestor dirs so nested

package roots like repo/pkg/pkg/ work), JS/TS (import/export-from/

require, index resolution, tsconfig/jsconfig paths+extends+baseUrl,

package.json "imports").

--lang rust|python|js restricts to one language; default scans all.

strand scan ./my-project --lang python -o pydeps.strand

Analyze:

strand info deps.strand strand nodes deps.strand # list every node name strand deps deps.strand my-crate --depth 3 strand impact deps.strand serde --by-depth strand why deps.strand my-app serde_json strand cycles deps.strand strand top deps.strand --by impact -n 20

huge DAGs: landmark-sampling estimate, top rows reranked exactly;

tune with --samples N, force sampling with --approx (benchmarking),

force exact (slow!) with --exact

strand order deps.strand --critical-path strand roots deps.strand strand leaves deps.strand strand common deps.strand deps a b

Impact of everything changed vs a git ref (CI use):

maps git diff --name-only <ref> paths onto graph nodes — exact path

for file-level scan graphs, directory/package segment for cargo graphs.

strand impact deps.strand --git-diff origin/main --max-impact 25

exits non-zero when the blast radius exceeds --max-impact

Export diagrams for docs/PRs (Graphviz DOT or Mermaid):

strand export deps.strand --format mermaid --impact serde_json --depth 2 strand export deps.strand --format dot --why my-app serde_json

Enforce architecture rules (exit 1 on violations, CI-friendly):

strand.rules:

forbid ui/ -> db/ # substring match on node names

forbid *.test -> src/ # * and ? globs also work

strand check deps.strand # reads ./strand.rules strand check deps.strand --rules ci.rules --json

Diff two graphs (e.g. rescan after changes, no git required):

strand diff old.strand new.strand

所有命令都支持 --json,便于 CI 使用。

对于会变化的图,strand-store 保留不可变的 .strand 基础层,并在其上叠加一个小型、写优化的增量层:

use strand_store::Store; let db = Store::open("graph.strandb")?; // One writer at a time (enforced by an fd-lock file); readers are unblocked. let mut tx = db.begin_write()?; tx.add_edge("app", "lib")?; tx.remove_edge("app", "old-lib")?; tx.commit()?; // WAL append + fsync -> durable // Any number of consistent point-in-time snapshots; compaction never // invalidates them (they pin their own Arc'd base+delta). let snap = db.begin_read()?;

(原文较长,此处译出前 6000 字,完整内容请点「打开原文」。)

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →