@saferun/cli 0.6.60 → 0.6.61

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.
package/README.md CHANGED
@@ -1,11 +1,34 @@
1
- # SafeRun CLI
1
+ # SafeRun
2
2
 
3
- > 🛡️ Human approval layer for AI agent Git operations
3
+ **Banking-grade security for your git workflow.**
4
+ SafeRun acts as a middleware between your terminal and GitHub, preventing accidental data loss and enforcing development policies.
4
5
 
5
- [![npm version](https://img.shields.io/npm/v/@saferun/cli.svg)](https://www.npmjs.com/package/@saferun/cli)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ ## Features
7
7
 
8
- SafeRun protects your Git repositories from dangerous operations executed by AI agents (Cursor, Claude Code, Copilot) and automation tools. It intercepts risky commands and requires human approval via Slack before execution.
8
+ ### Layer 1: Local Protection (Zero Latency)
9
+ SafeRun installs git hooks (`pre-push`, `pre-commit`) that intercept dangerous commands **before** they execute.
10
+ * **Blocks accidental destruction:** Prevents `force-push`, `branch -D`, `reset --hard` on protected branches.
11
+ * **Context-Aware:** Settings are isolated per repository. Protecting `develop` in Project A won't affect Project B.
12
+ * **Smart Caching:** Rules are checked locally (0ms latency).
13
+
14
+ ### Layer 2: Approval Workflow
15
+ Risky operations trigger an interactive approval request in **Slack**.
16
+ 1. You run `git push --force origin main`.
17
+ 2. SafeRun blocks the command and sends a notification.
18
+ 3. You (or a team lead) click **Approve** in Slack.
19
+ 4. The command executes automatically.
20
+
21
+ ### Layer 3: One-Click Revert (Webhooks)
22
+ If a dangerous operation bypasses local checks (e.g., via GitHub UI or another machine), SafeRun's GitHub App detects it and offers instant recovery.
23
+
24
+ * **Force Push:** Restores branch to previous commit SHA.
25
+ * **Delete Branch:** Recreates the deleted branch.
26
+ * **Merge PR:** Creates a revert commit.
27
+ * **Archive Repo:** Unarchives the repository.
28
+
29
+ > ⚠️ **Note:** Revert capabilities require the **SafeRun GitHub App** to be installed. CLI-intercepted operations are prevented *before* they happen, so they don't need reverting.
30
+
31
+ ---
9
32
 
10
33
  ## Installation
11
34
 
@@ -13,92 +36,84 @@ SafeRun protects your Git repositories from dangerous operations executed by AI
13
36
  npm install -g @saferun/cli
14
37
  ```
15
38
 
16
- ## Quick Start
39
+ ## Setup
40
+
41
+ Navigate to your git repository and run the interactive wizard:
17
42
 
18
43
  ```bash
19
- cd your-repo
20
- saferun setup # Complete setup wizard
44
+ saferun setup
21
45
  ```
22
46
 
23
- The wizard guides you through:
24
- 1. **API Key** — Get from [saferun.dev](https://saferun.dev)
25
- 2. **Slack** — Bot token + webhook for notifications
26
- 3. **GitHub App** — Install [SafeRun GitHub App](https://github.com/apps/saferun-ai)
27
- 4. **Shell Wrapper** — Intercepts dangerous commands
47
+ This command will:
28
48
 
29
- ## Protected Operations
49
+ 1. Link your API Key.
50
+ 2. Connect Slack & GitHub App.
51
+ 3. Install necessary Git Hooks (`pre-push`, `reference-transaction`).
52
+ 4. Register the repository in your global config.
30
53
 
31
- - `git push --force` / `git push -f`
32
- - `git reset --hard`
33
- - `git branch -D` / `git branch --delete --force`
34
- - `git clean -fd`
35
- - `git commit --no-verify`
36
- - Direct commits to `main` or `master`
54
+ ---
37
55
 
38
- ## Commands
56
+ ## CLI Cheat Sheet
39
57
 
40
- ```bash
41
- saferun setup # Complete setup wizard
42
- saferun init # Initialize protection in current repo
43
- saferun status # Show protection status
44
- saferun status -n 20 # Show last 20 operations
45
- saferun doctor # Health check
46
- saferun uninstall # Remove from current repo
47
- saferun uninstall --global # Remove completely
48
- ```
58
+ SafeRun works silently in the background. Use these commands for configuration and audit:
49
59
 
50
- ## How It Works
60
+ ### Essentials
51
61
 
52
- SafeRun uses **multiple layers** of protection:
62
+ * **`saferun setup`**
63
+ **Initialize.** Sets up SafeRun in the current repository.
53
64
 
54
- 1. **Shell Wrapper** — Intercepts `git` commands in interactive shells
55
- 2. **Git Hooks** `pre-commit`, `pre-push`, `post-checkout`
56
- 3. **reference-transaction Hook** — Intercepts ALL ref changes at Git core level (Git 2.29+)
65
+ * **`saferun settings branches`**
66
+ **Configure.** Interactively select branches to protect (e.g., `main`, `production`).
57
67
 
58
- The `reference-transaction` hook is the **most reliable** layer — it catches operations even when AI agents call `/usr/bin/git` directly, bypassing shell aliases and PATH wrappers.
68
+ ### Maintenance
59
69
 
60
- ```
61
- AI Agent /usr/bin/git reset --hard Git internals → reference-transaction hook SafeRun blocks!
62
- ```
70
+ * **`saferun sync`**
71
+ **Update.** Manually pulls latest settings from the cloud (Auto-sync runs in background).
72
+
73
+ * **`saferun doctor`**
74
+ **Diagnose.** Checks connection, hooks, and configuration status.
63
75
 
64
- When a dangerous operation is detected:
65
- 1. SafeRun calculates risk score and detects AI agent
66
- 2. Slack notification sent with Approve/Reject buttons
67
- 3. You approve → command executes. You reject → command blocked.
76
+ ### Audit
68
77
 
69
- Approval timeout: 2 hours.
78
+ * **`saferun history`**
79
+ **Audit.** Shows the log of recent intercepted operations and their status.
70
80
 
71
- ## Requirements
81
+ * **`saferun config show`**
82
+ **Inspect.** View the current active configuration.
72
83
 
73
- - **Node.js** 18+
74
- - **Git** 2.29+ (for `reference-transaction` hook)
75
- - **Slack** workspace with bot token
84
+ * **`saferun uninstall`**
85
+ **Remove.** Cleans up hooks and configuration.
86
+
87
+ ---
88
+
89
+ ## Protected Operations
76
90
 
77
- ## Known Limitations (Help Wanted! 🙏)
91
+ SafeRun intercepts the following commands on protected branches:
78
92
 
79
- SafeRun protects **Git ref-changing operations**. Some operations are outside our scope:
93
+ * `git push --force`
94
+ * `git branch -D`
95
+ * `git reset --hard` (via hook)
96
+ * `git clean -fd` (via hook - *requires shell integration*)
97
+ * `git rebase` (via hook)
80
98
 
81
- **✅ Protected Operations** (ref-changing):
82
- - `git reset --hard` changes branch ref
83
- - `git branch -D` — deletes branch ref
84
- - `git push --force` — changes remote ref
85
- - `git rebase` — rewrites branch ref
86
- - `git checkout` to different branch — updates HEAD ref
99
+ **Bypass:**
100
+ If you strictly need to bypass SafeRun (e.g., for scripting), you can disable protection temporarily via `saferun settings branches` or use standard git bypass flags if your policy allows.
87
101
 
88
- **❌ Not Protected** (no ref change):
89
- - `git clean -fd` — deletes untracked files only → *use `.gitignore`*
90
- - `rm -rf .git` — filesystem operation → *use Docker/sandbox*
91
- - Deleting `.git/hooks/` — filesystem operation → *use Docker/sandbox*
102
+ ---
92
103
 
93
- **Why can't we protect `git clean`?**
94
- Git's `reference-transaction` hook only fires when refs change. `git clean` deletes untracked files without touching refs.
104
+ ## Troubleshooting
95
105
 
96
- **Community contributions welcome!** If you know how to intercept these operations, please open an issue or PR.
106
+ **"Config outdated" message**
107
+ SafeRun automatically syncs settings in the background. If you see this, run `saferun sync` to force an update.
97
108
 
98
- ## Documentation
109
+ **Uninstalling**
110
+ To completely remove SafeRun:
99
111
 
100
- Full documentation: [github.com/Cocabadger/saferun-api](https://github.com/Cocabadger/saferun-api)
112
+ 1. Run `saferun uninstall --global` (removes configs and hooks).
113
+ 2. Run `npm uninstall -g @saferun/cli` (removes the binary).
101
114
 
102
- ## License
115
+ ---
103
116
 
104
- MIT © SafeRun Team
117
+ <p align="center">
118
+ Built for developers who value sleep. 😴
119
+ </p>
package/dist/index.js CHANGED
@@ -1,9 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  const commander_1 = require("commander");
8
+ const update_notifier_1 = __importDefault(require("update-notifier"));
5
9
  const register_commands_1 = require("./register-commands");
6
10
  const version_1 = require("./version");
11
+ // Check for updates in background
12
+ const pkg = require('../package.json');
13
+ (0, update_notifier_1.default)({ pkg }).notify();
7
14
  const program = new commander_1.Command();
8
15
  program
9
16
  .name('saferun')
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,2DAAuD;AACvD,uCAA0C;AAE1C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,wCAAwC,CAAC;KACrD,OAAO,CAAC,IAAA,uBAAa,GAAE,EAAE,eAAe,EAAE,kBAAkB,CAAC,CAAC;AAEjE,IAAA,oCAAgB,EAAC,OAAO,CAAC,CAAC;AAE1B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,yCAAoC;AACpC,sEAA6C;AAC7C,2DAAuD;AACvD,uCAA0C;AAE1C,kCAAkC;AAClC,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACvC,IAAA,yBAAc,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAEjC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,wCAAwC,CAAC;KACrD,OAAO,CAAC,IAAA,uBAAa,GAAE,EAAE,eAAe,EAAE,kBAAkB,CAAC,CAAC;AAEjE,IAAA,oCAAgB,EAAC,OAAO,CAAC,CAAC;AAE1B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saferun/cli",
3
- "version": "0.6.60",
3
+ "version": "0.6.61",
4
4
  "description": "AI Safety Middleware - Protect your Git workflows from dangerous AI agent operations",
5
5
  "author": "SafeRun Team",
6
6
  "license": "MIT",
@@ -58,12 +58,14 @@
58
58
  "js-yaml": "^4.1.0",
59
59
  "open": "^10.2.0",
60
60
  "ora": "^9.0.0",
61
+ "update-notifier": "^5.1.0",
61
62
  "uuid": "^9.0.1"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@types/cli-table": "^0.3.4",
65
66
  "@types/js-yaml": "^4.0.9",
66
67
  "@types/node": "^20.11.17",
68
+ "@types/update-notifier": "^6.0.8",
67
69
  "@types/uuid": "^9.0.7",
68
70
  "@typescript-eslint/eslint-plugin": "^6.21.0",
69
71
  "@typescript-eslint/parser": "^6.21.0",