Add a VS Code extension, a preflight command, and VS Code agent hooks · initialcommit-com/git-sim@6af3195 · GitHub
Skip to content

Commit 6af3195

Browse files
Add a VS Code extension, a preflight command, and VS Code agent hooks
vscode/: a thin client over the command line, plain JavaScript with no build step. Simulate a Git command and see git-sim's interactive page in an editor tab; pre-flight one and get the risk, facts, losses, undo and text graph with a Simulate button. Reachable from the Command Palette, the Source Control toolbar, editor and terminal context menus for a selected command, a recent-commands pick, and Ctrl+Alt+G, whose prompt opens with "git-sim " typed. A status bar entry shows whether git-sim is installed. build_vsix.py packages it without Node. git-sim preflight <command>: the pre-flight check from the terminal, readable or --json, with git's own options passing through in order. The extension calls it. git-sim media-dir: prints the folder simulations are saved in. That folder now defaults to the user's cache area outside any repository (%LOCALAPPDATA%, ~/Library/Caches, ~/.cache) with a subfolder per repo; --media-dir and git_sim_media_dir still override it. The hook and MCP server write there too instead of a temp folder. The installer never writes a bare program name: it uses the console script's absolute path, or the interpreter with -m when the scripts are missing (an editable install made before they existed), and recognises either form on later runs. VS Code is a hook-capable agent now: its agent hooks read Copilot CLI hook files, so it shares ~/.copilot/hooks/git-sim.json. The hook understands VS Code's runTerminalCommand payload and answers in a shape both VS Code and Copilot CLI read. Under VS Code it renders the interactive page rather than an image, opens no viewer window, and leaves a note in git-sim_media/inbox that the extension turns into a tab; it also reports SAFE / CAUTION for commands below the threshold so a verdict shows on every git command (GIT_SIM_HOOK_REPORT_SAFE). Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 205c92b commit 6af3195

21 files changed

Lines changed: 1568 additions & 52 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Git-Sim is Free and Open-Source Software (FOSS). Your support will help me work
4545
- Animation only: Add custom branded intro/outro sequences if desired
4646
- Animation only: Speed up or slow down animation speed as desired
4747
- NEW: [MCP server and Claude Code hook](docs/mcp.md) so AI coding agents (Claude Code, Cursor, etc.) run deterministic pre-flight checks — facts, a text commit graph and a simulation image — before executing destructive git commands in your repo. Included in the default install.
48+
- NEW: `git-sim preflight <command>` runs that same check from the terminal, and the [VS Code extension](docs/vscode.md) puts simulations and pre-flight checks in an editor tab.
4849

4950
## Quickstart
5051
Note: If you prefer to install git-sim with Docker, skip steps (1) and (2) here and jump to the [Docker installation](#docker-installation) section below, then come back here to step (3).
@@ -101,7 +102,7 @@ Or if you want to do it all in a single command:
101102
$ git-dummy --no-subdir --branches=3 --commits=10 && git-sim [global options] <subcommand> [subcommand options]
102103
```
103104

104-
5) Simulated output will be created as an interactive `.html` page (or a `.jpg` / `.png` image with `--img-format`). Output files are named using the subcommand executed combined with a timestamp, and by default are stored in a subdirectory called `git-sim_media/`. The location of this subdirectory is customizable using the command line flag `--media-dir=path/to/output`. Note that when the `--animate` global flag is used, render times will be much longer and a `.mp4` video output file will be produced.
105+
5) Simulated output will be created as an interactive `.html` page (or a `.jpg` / `.png` image with `--img-format`). Output files are named using the subcommand executed combined with a timestamp, and are stored in a `git-sim_media/` folder with a subfolder per repository. By default that folder lives in your user cache area, outside any repository (`%LOCALAPPDATA%\git-sim_media` on Windows, `~/Library/Caches/git-sim_media` on macOS, `~/.cache/git-sim_media` on Linux); `git-sim media-dir` prints it. Move it with `--media-dir=path/to/output` or the `git_sim_media_dir` environment variable (`--media-dir .` puts it in the current folder, as older versions did). Note that when the `--animate` global flag is used, render times will be much longer and a `.mp4` video output file will be produced.
105106

106107
6) For convenience, environment variables can be set for any global command-line option available in git-sim. All environment variables start with `git_sim_` followed by the name of the option.
107108

@@ -562,7 +563,7 @@ Use light mode (soft off-white background, dark text) instead of the default dar
562563
$ git-sim --light-mode status
563564
```
564565

565-
The default output is a self-contained interactive HTML page, saved under `git-sim_media/` and opened in the git-sim viewer at initialcommit.com. Drag the Before / After slider (or press play) to watch the command happen, hover commits for details, ctrl + wheel to zoom. The graph travels compressed in the link's `#fragment`, which browsers never send to a server, and the link git-sim opens carries nothing else about you or your repository (the command rides in the fragment too), so the server learns nothing about your code. The hosted page notes that git-sim opened it and the name of the local copy. The Share button builds a link meant for posting: that one also puts the command and a short text graph (`git log --oneline`, up to 12 lines) in the query string so the link gets a preview card. `#before`, `#after` or `#step=N` in a link pins the state, and `git_sim_viewer_url` points links at your own copy of the viewer:
566+
The default output is a self-contained interactive HTML page, saved under `git-sim_media/` in your user cache area (see `git-sim media-dir`) and opened in the git-sim viewer at initialcommit.com. Drag the Before / After slider (or press play) to watch the command happen, hover commits for details, ctrl + wheel to zoom. The graph travels compressed in the link's `#fragment`, which browsers never send to a server, and the link git-sim opens carries nothing else about you or your repository (the command rides in the fragment too), so the server learns nothing about your code. The hosted page notes that git-sim opened it and the name of the local copy. The Share button builds a link meant for posting: that one also puts the command and a short text graph (`git log --oneline`, up to 12 lines) in the query string so the link gets a preview card. `#before`, `#after` or `#step=N` in a link pins the state, and `git_sim_viewer_url` points links at your own copy of the viewer:
566567

567568
```console
568569
$ git-sim rebase -i main --todo todo.txt

‎docs/mcp.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,20 @@ its own format:
150150
| Cursor | `~/.cursor/hooks.json` → `hooks.beforeShellExecution` | `~/.cursor/mcp.json` |
151151
| GitHub Copilot CLI | `~/.copilot/hooks/git-sim.json` → `hooks.preToolUse` | `~/.copilot/mcp-config.json` |
152152
| Gemini CLI | `~/.gemini/settings.json` → `hooks.BeforeTool` (matcher `run_shell_command`) | same file → `mcpServers` |
153-
| VS Code (Copilot) | — (no shell hook) | user `mcp.json` → `servers` |
153+
| VS Code (Copilot) | shares Copilot CLI's `~/.copilot/hooks/git-sim.json` (VS Code's agent hooks read it) | user `mcp.json` → `servers` |
154+
155+
Under VS Code the hook behaves a little differently: it renders the
156+
interactive page instead of an image, does not open a viewer window, and leaves
157+
a note in `git-sim_media/inbox/` that the git-sim extension picks up to open the
158+
page in an editor tab. It also answers for git commands that rate below the
159+
threshold with an "allow" carrying a one-line SAFE or CAUTION note, so a
160+
verdict shows on every git command (`GIT_SIM_HOOK_REPORT_SAFE=0` turns that
161+
off; `=1` turns it on for other agents).
162+
163+
The hook and MCP commands are written as absolute paths. Where the console
164+
scripts are missing (an editable install made before they existed) the
165+
interpreter runs the module instead (`python -m git_sim.claude_hook`), so a
166+
bare name that might not be on the agent's PATH is never written.
154167

155168
Options: `--agent claude --agent cursor` to pick agents, `--all` for every
156169
supported one, `--scope project` to write into the current repo instead of

‎docs/vscode.md‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# git-sim for VS Code
2+
3+
The extension in [`vscode/`](../vscode) puts git-sim in the editor: simulate a
4+
Git command in an editor tab, or pre-flight it first and see what it would do,
5+
lose, and how to undo it. It is a thin client over the `git-sim` command line,
6+
so it needs no build step and tracks git-sim releases for free.
7+
8+
## Using it
9+
10+
1. Install git-sim: `pipx install git-sim` (or `uv tool install git-sim`).
11+
2. Install the extension from the Marketplace, or from a `.vsix` (below).
12+
3. In a repository: `Ctrl+Alt+G`, the beaker button in the Source Control view,
13+
or **git-sim: Simulate a Git command...** from the Command Palette. Type the
14+
command as you would after `git`, for example `rebase main`.
15+
16+
**Pre-flight** is the safety half: **git-sim: Pre-flight a Git command...** shows
17+
the risk level, the commits that would become unreachable, the files that would
18+
be lost, how to undo it and a text commit graph, with a button to simulate it.
19+
Select a command in a file or a terminal and the context menu offers both.
20+
21+
Settings live under `git-sim` (executable, extra options, light-mode graphs when
22+
the editor theme is light, open in the browser instead of a tab, timeout).
23+
24+
## The `preflight` command
25+
26+
The extension calls `git-sim preflight --json`, which is also useful on its own:
27+
28+
```
29+
$ git-sim preflight reset --hard HEAD~1
30+
DESTRUCTIVE git reset --hard HEAD~1
31+
32+
Moves main from 3cb9050 to 3808596 (hard reset).
33+
34+
What happens:
35+
1 commit(s) will no longer be reachable from main:
36+
3cb9050 commit 3
37+
...
38+
```
39+
40+
Git's own options pass straight through; quoting the whole command works too
41+
(`git-sim preflight "git stash drop"`). `--json` prints the report the MCP
42+
server returns; `-C <path>` checks another repository. Only analysis runs:
43+
nothing is rendered and the repository is never modified.
44+
45+
## Building the extension
46+
47+
The extension is plain JavaScript, so there is nothing to compile. To package
48+
it without Node, run the bundled script (Python 3.10+):
49+
50+
```
51+
python vscode/build_vsix.py # -> vscode/git-sim-0.1.0.vsix
52+
code --install-extension vscode/git-sim-0.1.0.vsix
53+
```
54+
55+
With Node available, `npx @vscode/vsce package` in `vscode/` produces the same
56+
file. To try changes live, open `vscode/` in VS Code and press F5.
57+
58+
## How it works
59+
60+
- Simulations: `git-sim --img-format html --output-only-path <command>` in the
61+
chosen repository. The self-contained page git-sim writes is shown in a
62+
webview with a content-security policy allowing only its inline parts.
63+
- Pre-flight: `git-sim preflight --json -- <command>`, rendered as a small
64+
report page with a Simulate button.
65+
- The repository is the one holding the active file, else the workspace folder
66+
(a quick pick when there are several).
67+
- `git-sim: Wire git-sim into AI coding agents` runs `git-sim install`, which
68+
gives VS Code both halves of the agent story: the pre-flight hook (VS Code's
69+
agent hooks read Copilot CLI hook files, so it shares
70+
`~/.copilot/hooks/git-sim.json`) and the MCP server in the user `mcp.json`,
71+
for Copilot's Agent mode (see [mcp.md](mcp.md)). Restart VS Code afterwards.

‎src/git_sim/__main__.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,18 @@ def main(
309309
app.command()(git_sim.commands.reflog)
310310
app.command()(git_sim.commands.submodule)
311311

312-
# Agent integration (not git subcommands).
312+
# Agent integration and the pre-flight check (not git subcommands).
313313
from git_sim.install import install, uninstall # noqa: E402
314+
from git_sim.paths import media_dir # noqa: E402
315+
from git_sim.preflight_cli import preflight # noqa: E402
314316

315317
app.command()(install)
316318
app.command()(uninstall)
319+
app.command()(media_dir)
320+
# git's own options (--hard, -f, ...) must pass through to the command being checked
321+
app.command(
322+
context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
323+
)(preflight)
317324

318325

319326
if __name__ == "__main__":

‎src/git_sim/claude_hook.py‎

Lines changed: 127 additions & 16 deletions

0 commit comments

Comments
 (0)