← 返回日报
精读 预计 1 分钟

Sem: New primitive for code understanding – not LSPs, but entities on top of Git

摘要

标题为 Sem: New primitive for code understanding – not LSPs, but entities on top of Git;正文介绍 Git 之上构建的语义理解原语,包括 diff、blame、impact、log、entities、context 六条命令和一个二进制文件;具体描述 sem diff 是实体级 diff(含重命名检测、结构哈希和单词级内联高亮)、sem blame 显示每个函数/类/方法的最后修改提交、sem impact 展示跨文件依赖图与受影响测试、sem log 记录单个实体的 Git 历史、sem entities 列出路径下所有函数/类/方法/类型及行范围、sem context 给出带依赖关系和依赖者的实体级上下文;所有命令均支持 --json;支持 26 种语言和 5 种数据格式,无需配置;典型 diff 时间 8ms;下载量 4,000+;安装方式为 brew install sem-cli 或 cargo install --git https://github.com/Ataraxy-Labs/sem sem-cli;提到 AI 代理使用 sem 输出比原始行 diff 准确率高 2.3 倍。

荐读理由

用 sem diff 就能把 git diff 换成实体级 diffs、rename detection、structural hashing 和 word-level inline highlights,3 秒内把函数改动看清,8ms 典型时间直接抄到项目里

原文

Know what changed.

Semantic understanding on top of Git. Diff, blame, impact, log. Functions, not lines.

copied $ brew install sem-cli

~/project

Same commit. Different lens.

Left: what git shows you. Right: what actually happened.

git diff

diff --git a/src/auth/login.ts b/src/auth/login.ts
index 4a2b1c0..8f3d2e1 100644
--- a/src/auth/login.ts
+++ b/src/auth/login.ts
@@ -12,6 +12,18 @@
+export function validateToken(token: string) {
+  const decoded = jwt.verify(token, SECRET);
+  if (!decoded.exp || decoded.exp < Date.now()) {
+    throw new TokenExpiredError();
+  }
+  return decoded;
+}
+
@@ -24,8 +36,10 @@
 export async function authenticateUser(
-  const user = await db.findUser(email);
-  if (!user) return null;
+  const user = await db.findUser(email);
+  if (!user) throw new UserNotFoundError();
+  await rateLimiter.check(email);
@@ -45,12 +59,0 @@
-export function legacyAuth(user, pass) {
-  return db.query('SELECT * FROM users
-    WHERE email = ? AND password = ?',
-    [user, pass]);
-}

sem diff

┌─ src/auth/login.ts ────────────────
│
│  ⊕ function  validateToken    [added]
│  ∆ function  authenticateUser [modified]
│  ⊖ function  legacyAuth       [deleted]
│
└────────────────────────────────────

3 entities changed across 1 file

AI agents are 2.3x more accurate when given sem output vs raw line diffs. See the benchmark.

Six commands. One binary.

Everything works in any Git repo. No config. No plugins.

sem diff

What changed? Entity-level diffs with rename detection, structural hashing, and word-level inline highlights.

│  ⊕ function  validateToken    [added]
│  ∆ function  authenticateUser [modified]
│  ⊖ function  legacyAuth       [deleted]

sem blame

Who changed it? Per-entity blame showing the last commit that touched each function, class, or method.

│  ⊕ render_inline_diff  a1a6fbf  Rohan  04-03
│  ⊕ format_terminal     a1a6fbf  Rohan  04-03

sem impact

What breaks? Cross-file dependency graph shows every entity that depends on a given function, plus affected tests.

⊕ function authenticateUser
  → depends on:  db.findUser, rateLimiter
  ← used by:    loginRoute, authMiddleware
  ! 42 entities transitively affected

sem log

How did it evolve? Git history for a single entity. See every commit that touched a specific function.

│  ae576ab  Rohan  02-05  added
│  a105183  Rohan  02-08  modified (logic)
│  a1a6fbf  Rohan  04-03  modified (logic)

sem entities

What's under a path? Lists every function, class, method, and type with line ranges.

entities: src/auth/login.ts
  function validateToken     (L12:24)
  function authenticateUser  (L26:45)
  interface AuthConfig       (L47:52)

sem context

Smart context for AI. Token-budgeted context window: the entity, its dependencies, and dependents. Fits in any LLM prompt.

context for authenticateUser (budget: 8000)
  target:          ~705 tokens
  dependencies:    ~256 tokens
  dependents:      ~812 tokens

All commands support --json for machine-readable output. Full reference.

Your stack. Covered.

26 languages. 5 data formats. One binary.

TypeScript

JavaScript

Python

Go

Rust

Java

C

C++

C#

Ruby

PHP

Swift

Kotlin

Elixir

Bash

HCL

Fortran

Vue

Svelte

XML

ERB

Dart

Perl

OCaml

Scala

Zig

JSON

YAML

TOML

CSV

Markdown

8ms typical diff

26 languages

0 config needed

4,000+ downloads

Try it. 10 seconds.

$ brew install sem-cli
$ sem setup
✓ Created wrapper script
✓ Set git config --global diff.external = sem
✓ Pre-commit hook installed

Done! Running git diff in any repo will now use sem.
  To revert, run: sem unsetup

One command. Every git diff becomes a sem diff. No config files. Also: cargo install --git https://github.com/Ataraxy-Labs/sem sem-cli

Hacker News · 94 赞 · 38 评 讨论 → 阅读原文 →

这条对你有帮助吗?