sem - Semantic Version Control Tool

repository·main·Indexed 25 days ago

https://github.com/ataraxy-labs/sem

A semantic version control tool built on top of Git that performs diffing and analysis at the entity level (functions, classes, methods) rather than the line level. It provides high-fidelity code context for humans and AI agents, supporting 30+ languages via tree-sitter. Features include a GitHub Action for entity-level PR diffs, an MCP server for coding agents via @ataraxy-labs/sem-skill, and CLI commands for impact analysis, dependency graphing, and semantic blame.

Tokens
18.9K
Snippets
57
Records
145
Agent score
84%

What's inside sem

  1. Overview of sem CLI commands

    main

    The sem CLI provides entity-level diffs for Git, focusing on code structures like functions, classes, and methods rather than raw lines. Available commands include:

    • sem diff: Semantic diff of changes.
    • sem graph: Visualize the dependency graph.
    • sem impact: Analyze the impact of changes.
    • sem blame: Semantic code blame.
  2. Understand the sem storage engine axes

    main

    The sem storage engine manages three distinct axes to prevent re-computation and optimize performance for agents:

    AxisStructurePurpose
    SpaceEntity graph + content storePrevents re-parsing and cross-file resolution.
    TimeSemantic commit indexPrevents re-computing history walks.
    AttentionSession fill ledgerPrevents re-reading entities and overlapping information in a conversation.

    By addressing space, time, and attention, sem ensures that computations like parsing, history walking, and context filling are paid for only once.

  3. Use sem for semantic version control

    main
    The sem CLI provides entity-level version control capabilities on top of Git. Instead of line-based changes, it identifies modifications to specific code entities like functions or classes. This is particularly useful for agents that need to reason about what changed rather than where in a file.
  4. Build sem from source

    main

    To build the sem binary from the Rust source code, use cargo build with the --release flag. The resulting binary will be located in target/release/sem.

    # Build the release binary
    cargo build --release
    # Binary at target/release/sem
  5. Generate a Large JS/TS Fixture for Benchmarking

    main

    Use the scripts/large-js-fixture.mjs script to generate a repeatable TypeScript/JavaScript fixture for testing graph-build performance. The generator creates a standalone fixture root containing src/, package.json, tsconfig.json, fixture-manifest.json, and a marker file.

    Note: Existing marked fixture roots are replaced for repeatability. Non-empty unmarked directories will be refused unless the --force flag is used.

    node scripts/large-js-fixture.mjs \
      --out /tmp/sem-large-js-fixture \
      --files 1000 \
      --entities-per-file 12 \
      --fanout 5 \
      --import-style-mix named:3,default:1,namespace:1,type:1 \
      --nested-depth 3 \
      --body-lines 40 \
      --language mixed
  6. Add a new language to sem

    main

    To extend sem with support for a new language, follow these steps:

    1. Add the required tree-sitter grammar to sem-core/Cargo.toml.
    2. Create a new parser plugin in sem-core/src/parser/plugins/.
    3. Register the new plugin in sem-core/src/parser/mod.rs.
    4. Add corresponding tests.

    For the complete 7-step implementation guide, refer to CONTRIBUTING.md.

  7. Use sem GitHub Action for PR entity diffs

    main

    Add the GitHub Action to your workflow to automatically comment on Pull Requests with a summary of changed entities (functions, classes, methods). It also identifies cosmetic-only PRs (formatting/comments).

    Workflow Example:

    name: Entity diff
    on: pull_request
    permissions:
      contents: read
      pull-requests: write
    jobs:
      entity-diff:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: Ataraxy-Labs/sem/action@v0.15.1
    uses: Ataraxy-Labs/sem/action@v0.15.1
  8. Integrate sem with AI agents via MCP

    main

    The sem mcp command starts a Model Context Protocol (MCP) server over stdin/stdout. This allows coding agents to use 6 entity-level tools: sem_impact, sem_context, sem_diff, sem_entities, sem_blame, and sem_log.

    Claude Code

    To add sem to Claude Code:

    claude mcp add sem -- sem mcp

    To install the skill so the agent knows when to use it:

    npx @ataraxy-labs/sem-skill

    Cursor, Claude Desktop, or other MCP clients

    Add the following to your mcpServers configuration. If sem is not in your PATH, use the absolute path to the binary:

    {
      "mcpServers": {
        "sem": {
          "command": "sem",
          "args": ["mcp"]
        }
      }
    }
  9. Install sem

    main

    You can install sem using several methods depending on your environment:

    • Shell script: curl -fsSL https://raw.githubusercontent.com/Ataraxy-Labs/sem/main/install.sh | sh
    • Homebrew (macOS): brew install sem-cli
    • Windows (winget): winget install AtaraxyLabs.sem
    • npm (Node.js): npm install --save-dev @ataraxy-labs/sem
    • Bun:
      bun add -d @ataraxy-labs/sem
      bun pm trust @ataraxy-labs/sem
    • Cargo (Rust source): cargo install --git https://github.com/Ataraxy-Labs/sem sem-cli
    • Docker:
      docker build -t sem .
      docker run --rm -it -u "$(id -u):$(id -g)" -v "$(pwd):/repo" sem diff
    curl -fsSL https://raw.githubusercontent.com/Ataraxy-Labs/sem/main/install.sh | sh
  10. Run the Large JS/TS Fixture Benchmark

    main

    Run the benchmark suite using benchmarks/large-js-fixture/run.mjs. This runner automates a full performance testing cycle:

    1. Regenerates the fixture.
    2. Clears the benchmark cache root.
    3. Executes a cold-cache run.
    4. Executes a warm-cache run.
    5. Mutates a marker file to perform a one-file incremental rebuild timing run.

    By default, it executes the command: sem graph . --json --file-exts .ts .js.

    Results are written to benchmarks/large-js-fixture/.generated/results.json. You can use --json-out <path> to specify a different output path or --no-json-out to suppress JSON output and only show the terminal summary.

    node benchmarks/large-js-fixture/run.mjs \
      --sem crates/target/debug/sem \
      --files 1000 \
      --entities-per-file 12 \
      --fanout 5 \
      --import-style-mix named:3,default:1,namespace:1,type:1 \
      --nested-depth 3 \
      --body-lines 40 \
      --language mixed
  11. Enable the sem guard to enforce semantic code analysis

    main

    The sem guard makes sem the mandatory tool for code analysis by installing a PreToolUse hook that denies grep, file reads, and sed/cat on code files. This forces the agent to use semantic tools like sem_context, sem_entities, or sem_impact instead of falling back to text-based searches.

    Behavioral Rules:

    • Pre-edit reads: Allowed (editors must read a file before editing; the second Read of the same path passes).
    • Non-code files: Markdown, JSON, TOML, YAML, etc., are never blocked.
    • Pipe filtering: Commands like cargo test | grep FAILED are allowed; grep -rn foo src/ is denied.
    • Git context: Files outside of a git repository are not blocked.

    Disabling the Guard:

    • Prefix a command with SEM_GUARD=0.
    • Set SEM_GUARD=0 in your environment variables.
    • To remove it permanently, delete the sem-guard.py PreToolUse entries from ~/.claude/settings.json.
    npx @ataraxy-labs/sem-skill --guard