heimdal_ai_analyze 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1de7a84ebfd8fd06367312a54270c64bf6c43923238d3b85cdff16dff2e2e25
4
- data.tar.gz: 6cac8c75b7870aa5a56add62d203053ba505d4f397a8c74e67f9f60ce727e603
3
+ metadata.gz: fc0b28182c96cbd7d687b4e1b219a7010d1773756d5abb17855ebe855fdf5b00
4
+ data.tar.gz: 948d0b8a93c07c392290a6807d6e8010743bf5158e620cf2afaed25b0cb6fa30
5
5
  SHA512:
6
- metadata.gz: 74670f8e9b9bc96c3a6a7f8d1a58260e0b6d8a3f74c6b4df1aa4eaec5f19733268a6491f33ddf5c3389147230d5e4237e09b610fe498f8982beb57745e0b12e4
7
- data.tar.gz: 9c3b237a19785f0c44ef66e6f84afa15465d056af00b4b780d9b18c67895ef94c9923daeb2d4c0506d3a8dc22ceb89f2c985eb2fdd9a0747e764e230cf4e8bf3
6
+ metadata.gz: cfb229eb3a88b328ae677fb235ba09447acc5550cf9981b8245fe88567eba63846f89cf9bea1a8d6f991e5307c7c08799eccd5eca5d459fefa49f464814d0b6d
7
+ data.tar.gz: eafa7b0af64cbbc3d2a161497ec3d3f0a596ecdfa0d8d72600af228cf0883c4edf9703b6c950d826f4d2c78edc425c506637bc01506645c4cf7d561d44ae6e8a
data/README.md CHANGED
@@ -1,19 +1,21 @@
1
1
  # Heimdal AI Analyze
2
2
 
3
- Ruby gem that installs a **git pre-commit** hook for **AI-assisted review** of your **staged diff** via the [Cursor Agent CLI](https://cursor.com/docs/cli/overview). The hook runs only when you commit with analysis enabled (e.g. `git analyze -m "message"`), not on normal commits.
3
+ [![Gem Version](https://badge.fury.io/rb/heimdal_ai_analyze.svg)](https://rubygems.org/gems/heimdal_ai_analyze)
4
4
 
5
- ## Requirements
5
+ **Heimdal AI Analyze** is a Ruby gem that adds a **git pre-commit** hook for **AI-assisted review** of your **staged diff**. Use `git analyze` to run the review before your commit; a normal `git commit` does not trigger analysis unless you opt in.
6
6
 
7
- 1. **Cursor Agent CLI** install from [cursor.com/install](https://cursor.com/install) and ensure `agent` or `cursor-agent` is on your `PATH` (or set `CURSOR_AGENT_BIN`).
8
- 2. **`CURSOR_API_KEY`** — export in your environment, or use a repo-local `scripts/.env.hook`, or `~/.config/heimdal_ai_analyze/env` (see below).
7
+ _Sees every line. Judges every commit. No bad code crosses the Bifrost._
9
8
 
10
- ## Install the gem
9
+ - **RubyGems:** [rubygems.org/gems/heimdal_ai_analyze](https://rubygems.org/gems/heimdal_ai_analyze)
10
+ - **Source:** [github.com/ffarhhan/heimdal_ai_analyze](https://github.com/ffarhhan/heimdal_ai_analyze)
11
+
12
+ ## Installation
11
13
 
12
14
  ```bash
13
15
  gem install heimdal_ai_analyze
14
16
  ```
15
17
 
16
- Or with Bundler:
18
+ With Bundler:
17
19
 
18
20
  ```ruby
19
21
  # Gemfile
@@ -24,59 +26,45 @@ gem "heimdal_ai_analyze", group: :development
24
26
  bundle install
25
27
  ```
26
28
 
27
- ## One-time setup per repository
29
+ Requires **Ruby 3.1**.
28
30
 
29
- From the git repository root:
31
+ ## How it works
30
32
 
31
- ```bash
32
- bundle exec heimdal-ai-analyze-install
33
- # or, if the gem executable is on PATH:
34
- heimdal-ai-analyze-install
35
- ```
33
+ 1. **You run `git analyze -m "message"`** — A `git commit` alias that runs Heimdal’s review **before** your changes are committed.
36
34
 
37
- This symlinks `.git/hooks/pre-commit` to the gem’s hook, sets `git analyze` alias (`ANALYZE=true git commit …`), records `heimdalAiAnalyze.gemPath`, and tries to save `cursorHook.agentPath` for the Cursor Agent binary.
35
+ 2. **Staged changes only** Only files in the commit are analyzed; the rest of the tree is untouched.
38
36
 
39
- ## Credentials
37
+ 3. **Five dimensions** — **Security**, **duplication**, **complexity**, **style**, and **tests**.
40
38
 
41
- **Minimum:** set an API key for the Cursor Agent:
39
+ 4. **Severity** Issues are reported with location, explanation, and a suggested fix (**critical**, **warning**, **info**).
42
40
 
43
- ```bash
44
- export CURSOR_API_KEY="your-key"
45
- ```
41
+ **Result:** **Critical** findings **block** the commit until addressed. With no critical issues, the commit can proceed; lower severities are advisory.
46
42
 
47
- Optional locations (loaded in order; later sources override earlier ones):
43
+ ## One-time setup (per repository)
48
44
 
49
- 1. `~/.config/heimdal_ai_analyze/env` or `$XDG_CONFIG_HOME/heimdal_ai_analyze/env` — `export CURSOR_API_KEY=...`
50
- 2. `scripts/.env.hook` in the project (gitignored) — copy from `templates/env.hook.example` in this gem if you open the installed path under `$(gem env gemdir)`.
51
-
52
- ## Usage
45
+ Run from the repository root:
53
46
 
54
47
  ```bash
55
- git analyze -m "Your commit message" # runs AI review on staged changes, then commits if allowed
56
- git commit -m "message" # normal commit (hook skips AI unless ANALYZE=true)
57
- git commit --no-verify # bypass hooks when needed
48
+ bundle exec heimdal-ai-analyze-install
49
+ # or, if the executable is on your PATH:
50
+ heimdal-ai-analyze-install
58
51
  ```
59
52
 
60
- ## Development
53
+ This links the gem’s pre-commit hook, registers the `git analyze` alias (`ANALYZE=true git commit …`), and stores the gem path in local git config. If an analysis binary is found, its path may be saved locally as well.
61
54
 
62
- Clone [github.com/ffarhhan/heimdal_ai_analyze](https://github.com/ffarhhan/heimdal_ai_analyze):
55
+ ## API key
63
56
 
64
- ```bash
65
- git clone -o personal git@github.com:ffarhhan/heimdal_ai_analyze.git
66
- cd heimdal_ai_analyze
67
- gem build heimdal_ai_analyze.gemspec
68
- gem install ./heimdal_ai_analyze-*.gem --local
69
- ```
57
+ The hook needs **`CURSOR_API_KEY`** whenever you run `git analyze`.
58
+
59
+ - **This shell only:** `export CURSOR_API_KEY="…"` lasts for the current terminal session.
60
+ - **Every session:** add that `export` to your shell profile (for example `~/.zshrc` or `~/.bashrc`), **or** keep the key in a **repository-root `.env`** file and add `.env` to `.gitignore` so it is never committed. The hook loads supported env files when it runs.
70
61
 
71
- ## Publish to RubyGems.org (maintainers)
62
+ For additional options and examples, see **`templates/env.hook.example`** inside the installed gem (`gem contents heimdal_ai_analyze` or `$(gem env gemdir)/gems/heimdal_ai_analyze-*`).
72
63
 
73
- 1. [Create an account](https://rubygems.org/sign_up) and enable MFA as required.
74
- 2. `gem signin` with a [RubyGems API key](https://rubygems.org/profile/edit) (push scope).
75
- 3. Bump `lib/heimdal_ai_analyze/version.rb`, then:
64
+ ## Usage
76
65
 
77
66
  ```bash
78
- gem build heimdal_ai_analyze.gemspec
79
- gem push heimdal_ai_analyze-VERSION.gem
67
+ git analyze -m "Your commit message" # review staged changes, then commit if allowed
80
68
  ```
81
69
 
82
70
  ## License
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["ffarhhan"]
9
9
  spec.email = ["ffarhhan@users.noreply.github.com"]
10
10
 
11
- spec.summary = "Heimdal AI Analyze — Cursor Agent pre-commit gate for staged diffs"
12
- spec.description = "Installs a git pre-commit hook that runs Cursor Agent on ANALYZE=true commits (e.g. git analyze). Requires CURSOR_API_KEY and the Cursor Agent CLI."
11
+ spec.summary = "Heimdal AI Analyze — git pre-commit hook for AI-assisted review of staged diffs (git analyze)"
12
+ spec.description = "Heimdal AI Analyze installs a git pre-commit hook that runs an AI-assisted code review of your staged diff when you commit with analysis enabled (e.g. `git analyze -m \"message\"`). Reviews security, duplication, complexity, style, and tests; critical issues can block the commit. Requires CURSOR_API_KEY in the environment or a repo-local `.env` (gitignored)."
13
13
  spec.homepage = "https://github.com/ffarhhan/heimdal_ai_analyze"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 3.1.0"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HeimdalAiAnalyze
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # Copy to scripts/.env.hook (gitignored). Never commit this file.
2
- # Or use ~/.config/heimdal_ai_analyze/env for all repos on your machine (loaded first; this file overrides).
2
+ # Alternatively use a repo-root .env file (gitignored); the hook loads ~/.config/.../env, then .env, then this file.
3
+ # Or use ~/.config/heimdal_ai_analyze/env for all repos on your machine (loaded first; repo .env and this file override).
3
4
  #
4
5
  # Copy this file to scripts/.env.hook in your app repo (see gem README).
5
6
  #
data/templates/pre-commit CHANGED
@@ -11,9 +11,9 @@
11
11
  #
12
12
  # Requirements:
13
13
  # • Cursor Agent CLI — https://cursor.com/install
14
- # • CURSOR_API_KEY — export in env, or ~/.config/heimdal_ai_analyze/env, or scripts/.env.hook (gitignored)
14
+ # • CURSOR_API_KEY — export in env, or ~/.config/heimdal_ai_analyze/env, or repo .env / scripts/.env.hook (gitignored)
15
15
  #
16
- # Env file load order (later overrides earlier): user config → repo scripts/.env.hook
16
+ # Env file load order (later overrides earlier): user config → repo .env → scripts/.env.hook
17
17
  #
18
18
  # Agent binary lookup (first match):
19
19
  # 1. $CURSOR_AGENT_BIN 2. scripts/.env.hook exports 3. git config cursorHook.agentPath
@@ -32,11 +32,13 @@ set -euo pipefail
32
32
  # │ Bootstrap │
33
33
  # └─────────────────────────────────────────────────────────────────────┘
34
34
  REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || REPO_ROOT=""
35
- # User-level config first (Heimdal gem); repo scripts/.env.hook overrides.
35
+ # User-level config first (Heimdal gem); repo .env then scripts/.env.hook override.
36
36
  for f in "${XDG_CONFIG_HOME:+$XDG_CONFIG_HOME/heimdal_ai_analyze/env}" \
37
37
  "${HOME}/.config/heimdal_ai_analyze/env"; do
38
38
  [[ -n "$f" && -f "$f" ]] && { set -a; . "$f"; set +a; }
39
39
  done
40
+ REPO_DOTENV="${REPO_ROOT:+$REPO_ROOT/.env}"
41
+ [[ -n "$REPO_DOTENV" && -f "$REPO_DOTENV" ]] && { set -a; . "$REPO_DOTENV"; set +a; }
40
42
  ENV_HOOK="${REPO_ROOT:+$REPO_ROOT/scripts/.env.hook}"
41
43
  [[ -n "$ENV_HOOK" && -f "$ENV_HOOK" ]] && { set -a; . "$ENV_HOOK"; set +a; }
42
44
 
@@ -139,7 +141,7 @@ if [[ -z "${CURSOR_API_KEY:-}" ]]; then
139
141
  cat >&2 <<'MSG'
140
142
  pre-commit (analyze): CURSOR_API_KEY is required.
141
143
  → export CURSOR_API_KEY="…"
142
- → Or ~/.config/heimdal_ai_analyze/env or scripts/.env.hook (see gem README / env.hook.example)
144
+ → Or ~/.config/heimdal_ai_analyze/env, .env, or scripts/.env.hook (see gem README / env.hook.example)
143
145
  MSG
144
146
  exit 1
145
147
  fi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdal_ai_analyze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ffarhhan
@@ -10,8 +10,11 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2026-04-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Installs a git pre-commit hook that runs Cursor Agent on ANALYZE=true
14
- commits (e.g. git analyze). Requires CURSOR_API_KEY and the Cursor Agent CLI.
13
+ description: Heimdal AI Analyze installs a git pre-commit hook that runs an AI-assisted
14
+ code review of your staged diff when you commit with analysis enabled (e.g. `git
15
+ analyze -m "message"`). Reviews security, duplication, complexity, style, and tests;
16
+ critical issues can block the commit. Requires CURSOR_API_KEY in the environment
17
+ or a repo-local `.env` (gitignored).
15
18
  email:
16
19
  - ffarhhan@users.noreply.github.com
17
20
  executables:
@@ -53,5 +56,6 @@ requirements: []
53
56
  rubygems_version: 3.4.19
54
57
  signing_key:
55
58
  specification_version: 4
56
- summary: Heimdal AI Analyze — Cursor Agent pre-commit gate for staged diffs
59
+ summary: Heimdal AI Analyze — git pre-commit hook for AI-assisted review of staged
60
+ diffs (git analyze)
57
61
  test_files: []