gitpanic 1.0.0

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +258 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +111 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/core.d.ts +20 -0
  8. package/dist/core.d.ts.map +1 -0
  9. package/dist/core.js +55 -0
  10. package/dist/core.js.map +1 -0
  11. package/dist/detectors/index.d.ts +41 -0
  12. package/dist/detectors/index.d.ts.map +1 -0
  13. package/dist/detectors/index.js +258 -0
  14. package/dist/detectors/index.js.map +1 -0
  15. package/dist/git/executor.d.ts +15 -0
  16. package/dist/git/executor.d.ts.map +1 -0
  17. package/dist/git/executor.js +62 -0
  18. package/dist/git/executor.js.map +1 -0
  19. package/dist/git/reflog.d.ts +18 -0
  20. package/dist/git/reflog.d.ts.map +1 -0
  21. package/dist/git/reflog.js +58 -0
  22. package/dist/git/reflog.js.map +1 -0
  23. package/dist/git/status.d.ts +22 -0
  24. package/dist/git/status.d.ts.map +1 -0
  25. package/dist/git/status.js +72 -0
  26. package/dist/git/status.js.map +1 -0
  27. package/dist/recoveries/index.d.ts +50 -0
  28. package/dist/recoveries/index.d.ts.map +1 -0
  29. package/dist/recoveries/index.js +422 -0
  30. package/dist/recoveries/index.js.map +1 -0
  31. package/dist/src/core.d.ts +20 -0
  32. package/dist/src/core.d.ts.map +1 -0
  33. package/dist/src/core.js +55 -0
  34. package/dist/src/core.js.map +1 -0
  35. package/dist/src/detectors/index.d.ts +41 -0
  36. package/dist/src/detectors/index.d.ts.map +1 -0
  37. package/dist/src/detectors/index.js +258 -0
  38. package/dist/src/detectors/index.js.map +1 -0
  39. package/dist/src/git/executor.d.ts +15 -0
  40. package/dist/src/git/executor.d.ts.map +1 -0
  41. package/dist/src/git/executor.js +62 -0
  42. package/dist/src/git/executor.js.map +1 -0
  43. package/dist/src/git/reflog.d.ts +18 -0
  44. package/dist/src/git/reflog.d.ts.map +1 -0
  45. package/dist/src/git/reflog.js +58 -0
  46. package/dist/src/git/reflog.js.map +1 -0
  47. package/dist/src/git/status.d.ts +22 -0
  48. package/dist/src/git/status.d.ts.map +1 -0
  49. package/dist/src/git/status.js +72 -0
  50. package/dist/src/git/status.js.map +1 -0
  51. package/dist/src/recoveries/index.d.ts +50 -0
  52. package/dist/src/recoveries/index.d.ts.map +1 -0
  53. package/dist/src/recoveries/index.js +422 -0
  54. package/dist/src/recoveries/index.js.map +1 -0
  55. package/package.json +42 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sulthonzh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,258 @@
1
+ # gitpanic
2
+
3
+ Interactive CLI that diagnoses git mistakes and guides you through recovery — like `git reflog` but human-friendly.
4
+
5
+ ## Why gitpanic?
6
+
7
+ Every developer has panicked after a bad git operation. Stack Overflow's top git questions are all "how do I undo...":
8
+ - "How to undo last commit" — 16k+ upvotes
9
+ - "How to undo git push" — 5k+ upvotes
10
+ - "How to recover deleted branch" — 3k+ upvotes
11
+ - "How to undo git merge" — 2k+ upvotes
12
+
13
+ `git reflog` is powerful but intimidating. `gitpanic` provides an interactive wizard that:
14
+ 1. **Auto-detects** common git disasters from your repository state
15
+ 2. **Diagnoses** the problem in plain English
16
+ 3. **Guides** you through recovery with risk levels and confirmations
17
+ 4. **Protects** you by never executing without confirmation
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install -g gitpanic
23
+ ```
24
+
25
+ Or use with npx:
26
+
27
+ ```bash
28
+ npx gitpanic
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Basic Scan
34
+
35
+ Run `gitpanic` in any git repository:
36
+
37
+ ```bash
38
+ $ gitpanic
39
+ 🔍 Analyzing your git state...
40
+
41
+ ⚠️ Found 1 potential issue:
42
+
43
+ 1. 🟢 Uncommitted Changes
44
+ You have 3 uncommitted files. 1 staged. 2 modified.
45
+ Confidence: 100%
46
+
47
+ Select an issue to fix [1-1] or press Enter to exit: 1
48
+
49
+ 🔧 Recovery options for: Uncommitted Changes
50
+
51
+ 1. ✅ Stash changes
52
+ Save your changes to apply later
53
+ Risk: safe
54
+ Steps:
55
+ - git stash push -m "WIP"
56
+
57
+ 2. ✅ Commit changes
58
+ Create a commit with your changes
59
+ Risk: safe
60
+ Steps:
61
+ - git add .
62
+ - git commit -m "WIP"
63
+
64
+ 3. ⚠️ Discard all changes
65
+ Remove all uncommitted changes (DANGEROUS)
66
+ Risk: high
67
+ Steps:
68
+ - git reset --hard HEAD
69
+ - git clean -fd
70
+
71
+ Select a recovery option [1-3]: 1
72
+ ⚠️ Confirm: "Stash changes"? This can be undone. [y/N]: y
73
+
74
+ 🚀 Executing recovery...
75
+
76
+ ✅ Recovery complete!
77
+ ```
78
+
79
+ ### Dry Run Mode
80
+
81
+ Preview what would happen without making changes:
82
+
83
+ ```bash
84
+ gitpanic --dry-run
85
+ ```
86
+
87
+ ### Non-Interactive Mode
88
+
89
+ For use in scripts (requires manual implementation of recovery options):
90
+
91
+ ```bash
92
+ gitpanic --non-interactive
93
+ ```
94
+
95
+ ## Detected Disasters
96
+
97
+ `gitpanic` can detect and recover from:
98
+
99
+ | Disaster | Description | Severity |
100
+ |----------|-------------|----------|
101
+ | **Detached HEAD** | You're in detached HEAD state | Medium |
102
+ | **Deleted Branch** | A branch was recently deleted | High |
103
+ | **Force Push** | You recently force-pushed (may have overwritten commits) | High |
104
+ | **Botched Merge** | Merge in progress or recently aborted | Medium |
105
+ | **Accidental Commit** | Recent commit that might be a mistake | Low |
106
+ | **Uncommitted Changes** | Files that need to be committed | Low |
107
+ | **Wrong Branch Commit** | Commit that might belong on main/master | Medium |
108
+
109
+ ## Recovery Options
110
+
111
+ Each disaster comes with multiple recovery strategies with different risk levels:
112
+
113
+ - ✅ **Safe**: Can be easily undone (e.g., stash, soft reset)
114
+ - ⚡ **Medium**: May require manual intervention (e.g., cherry-pick)
115
+ - ⚠️ **High**: Destructive, cannot be undone (e.g., hard reset, clean)
116
+
117
+ ## How It Works
118
+
119
+ 1. **Analysis Phase**: `gitpanic` analyzes your git state using:
120
+ - `git reflog` to find recent operations
121
+ - `git status` to check for uncommitted changes
122
+ - `git log` to examine commit history
123
+
124
+ 2. **Detection Phase**: Multiple detectors scan for patterns:
125
+ - Recent commits (< 2 minutes) → accidental commit?
126
+ - Detached HEAD state → need to reattach?
127
+ - Force push in reflog → overwritten commits?
128
+ - Branch deletion in reflog → can be recovered?
129
+ - MERGE_HEAD file → merge conflict?
130
+ - Untracked/modified files → need to commit?
131
+
132
+ 3. **Recovery Phase**: For each detected disaster, provide:
133
+ - Clear explanation of what happened
134
+ - Multiple recovery options with risk levels
135
+ - Step-by-step command preview
136
+ - Confirmation before execution
137
+
138
+ ## Examples
139
+
140
+ ### Recover a Deleted Branch
141
+
142
+ ```bash
143
+ $ gitpanic
144
+ ⚠️ Found 1 potential issue:
145
+
146
+ 1. 🔴 Deleted Branch
147
+ Branch "feature/login" was deleted 45 seconds ago.
148
+ Confidence: 90%
149
+
150
+ Select an issue to fix [1-1]: 1
151
+
152
+ 🔧 Recovery options for: Deleted Branch
153
+
154
+ 1. ✅ Restore branch "feature/login"
155
+ Recreate the branch from the deleted commit
156
+ Risk: safe
157
+ Steps:
158
+ - git branch feature/login abc1234
159
+ - git checkout feature/login
160
+
161
+ Select a recovery option [1-1]: 1
162
+ ⚠️ Confirm: "Restore branch \"feature/login\""? This can be undone. [y/N]: y
163
+
164
+ ✅ Recovery complete!
165
+ ```
166
+
167
+ ### Undo an Accidental Commit
168
+
169
+ ```bash
170
+ $ gitpanic
171
+ ⚠️ Found 1 potential issue:
172
+
173
+ 1. 🟢 Accidental Commit
174
+ You just committed "typo fix" 12 seconds ago.
175
+ Confidence: 80%
176
+
177
+ Select an issue to fix [1-1]: 1
178
+
179
+ 🔧 Recovery options for: Accidental Commit
180
+
181
+ 1. ✅ Undo commit, keep changes staged
182
+ Remove the commit but keep your changes ready to commit
183
+ Risk: safe
184
+ Steps:
185
+ - git reset --soft HEAD~1
186
+
187
+ Select a recovery option [1-1]: 1
188
+ ⚠️ Confirm: "Undo commit, keep changes staged"? This can be undone. [y/N]: y
189
+
190
+ ✅ Recovery complete!
191
+ ```
192
+
193
+ ### Fix Detached HEAD
194
+
195
+ ```bash
196
+ $ gitpanic
197
+ ⚠️ Found 1 potential issue:
198
+
199
+ 1. 🟡 Detached HEAD
200
+ You are in detached HEAD state. Changes here can be lost.
201
+ Confidence: 100%
202
+
203
+ Select an issue to fix [1-1]: 1
204
+
205
+ 🔧 Recovery options for: Detached HEAD
206
+
207
+ 1. ✅ Reattach to previous branch
208
+ Switch back to main
209
+ Risk: safe
210
+ Steps:
211
+ - git checkout main
212
+
213
+ Select a recovery option [1-1]: 1
214
+ ⚠️ Confirm: "Reattach to previous branch"? This can be undone. [y/N]: y
215
+
216
+ ✅ Recovery complete!
217
+ ```
218
+
219
+ ## Development
220
+
221
+ ```bash
222
+ # Clone
223
+ git clone https://github.com/sulthonzh/gitpanic.git
224
+ cd gitpanic
225
+
226
+ # Install
227
+ npm install
228
+
229
+ # Build
230
+ npm run build
231
+
232
+ # Test
233
+ npm test
234
+
235
+ # Run local
236
+ node dist/cli.js
237
+ ```
238
+
239
+ ## License
240
+
241
+ MIT
242
+
243
+ ## Contributing
244
+
245
+ Contributions welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
246
+
247
+ ## Similar Tools
248
+
249
+ - [git-undo](https://github.com/zhangela/git-undo) - Python-based git undo
250
+ - [ohshitgit.com](https://ohshitgit.com) - Reference site for git disasters
251
+ - [git-reflog](https://git-scm.com/docs/git-reflog) - Raw git reflog reference
252
+
253
+ **What makes gitpanic different?**
254
+ - Interactive wizard UI (not just commands)
255
+ - Auto-detects problems (no manual diagnosis needed)
256
+ - TypeScript (modern, type-safe)
257
+ - Recovery preview with risk levels
258
+ - Safety-first with confirmations
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+ import { GitPanicCore } from './core.js';
3
+ async function main() {
4
+ const args = process.argv.slice(2);
5
+ // Handle flags
6
+ if (args.includes('--version') || args.includes('-v')) {
7
+ console.log('gitpanic v1.0.0');
8
+ process.exit(0);
9
+ }
10
+ if (args.includes('--help') || args.includes('-h')) {
11
+ console.log(`
12
+ gitpanic v1.0.0 - Interactive git disaster recovery
13
+
14
+ Usage:
15
+ gitpanic Run interactive recovery wizard
16
+ gitpanic --dry-run Show what would happen without making changes
17
+ gitpanic --version Show version
18
+ gitpanic --help Show this help
19
+
20
+ Options:
21
+ -n, --dry-run Dry run mode (no changes)
22
+ -v, --version Show version
23
+ -h, --help Show help
24
+ `);
25
+ process.exit(0);
26
+ }
27
+ const dryRun = args.includes('--dry-run') || args.includes('-n');
28
+ console.log('🔍 Analyzing your git state...\n');
29
+ const core = new GitPanicCore();
30
+ const result = await core.scan();
31
+ if (!result.isGitRepo) {
32
+ console.log('❌ Not a git repository. Please run this command inside a git repo.');
33
+ process.exit(1);
34
+ }
35
+ if (result.disasters.length === 0) {
36
+ console.log('✅ No disasters detected! Your git state looks healthy.');
37
+ process.exit(0);
38
+ }
39
+ console.log(`⚠️ Found ${result.disasters.length} potential ${result.disasters.length === 1 ? 'issue' : 'issues'}:\n`);
40
+ // Display disasters
41
+ for (let i = 0; i < result.disasters.length; i++) {
42
+ const disaster = result.disasters[i];
43
+ const severityEmoji = disaster.severity === 'high' ? '🔴' : disaster.severity === 'medium' ? '🟡' : '🟢';
44
+ console.log(`${i + 1}. ${severityEmoji} ${disaster.title}`);
45
+ console.log(` ${disaster.description}`);
46
+ console.log(` Confidence: ${Math.round(disaster.confidence * 100)}%`);
47
+ console.log();
48
+ }
49
+ // Simple interactive mode
50
+ if (!dryRun && !args.includes('--non-interactive')) {
51
+ const readline = (await import('readline')).createInterface({
52
+ input: process.stdin,
53
+ output: process.stdout
54
+ });
55
+ const question = (prompt) => new Promise((resolve) => readline.question(prompt, resolve));
56
+ try {
57
+ const answer = await question('Select an issue to fix [1-3] or press Enter to exit: ');
58
+ const index = parseInt(answer) - 1;
59
+ if (index >= 0 && index < result.disasters.length) {
60
+ const disaster = result.disasters[index];
61
+ console.log(`\n🔧 Recovery options for: ${disaster.title}\n`);
62
+ const options = await core.getRecoveryOptions(disaster);
63
+ for (let i = 0; i < options.length; i++) {
64
+ const opt = options[i];
65
+ const riskEmoji = opt.riskLevel === 'high' ? '⚠️' : opt.riskLevel === 'medium' ? '⚡' : '✅';
66
+ console.log(`${i + 1}. ${riskEmoji} ${opt.title}`);
67
+ console.log(` ${opt.description}`);
68
+ console.log(` Risk: ${opt.riskLevel}`);
69
+ if (opt.steps.length > 0) {
70
+ console.log(` Steps:`);
71
+ for (const step of opt.steps) {
72
+ console.log(` - ${step.command}`);
73
+ }
74
+ }
75
+ console.log();
76
+ }
77
+ const optionAnswer = await question('Select a recovery option [1-3]: ');
78
+ const optionIndex = parseInt(optionAnswer) - 1;
79
+ if (optionIndex >= 0 && optionIndex < options.length) {
80
+ const selectedOption = options[optionIndex];
81
+ const confirm = await question(`\n⚠️ Confirm: "${selectedOption.title}"? This ${selectedOption.riskLevel === 'high' ? 'CANNOT BE UNDONE' : 'can be undone'}. [y/N]: `);
82
+ if (confirm.toLowerCase() === 'y' || confirm.toLowerCase() === 'yes') {
83
+ console.log('\n🚀 Executing recovery...\n');
84
+ const { success, output } = await core.executeRecovery(disaster, selectedOption.id, dryRun);
85
+ console.log(output);
86
+ if (success) {
87
+ console.log('\n✅ Recovery complete!');
88
+ }
89
+ else {
90
+ console.log('\n❌ Recovery failed. Please check the output above.');
91
+ }
92
+ }
93
+ else {
94
+ console.log('\n❌ Recovery cancelled.');
95
+ }
96
+ }
97
+ }
98
+ }
99
+ finally {
100
+ readline.close();
101
+ }
102
+ }
103
+ else if (dryRun) {
104
+ console.log('💡 Dry run mode. Use --dry-run to see what would happen without making changes.');
105
+ }
106
+ }
107
+ main().catch((error) => {
108
+ console.error('Fatal error:', error);
109
+ process.exit(1);
110
+ });
111
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnC,eAAe;IACf,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAA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AAM,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,iFAAiF,CAAC,CAAC;IACjG,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/dist/core.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Disaster } from './detectors/index.js';
2
+ import { RecoveryOption } from './recoveries/index.js';
3
+ export interface ScanResult {
4
+ isGitRepo: boolean;
5
+ disasters: Disaster[];
6
+ currentBranch: string | null;
7
+ hasUncommittedChanges: boolean;
8
+ }
9
+ export declare class GitPanicCore {
10
+ private git;
11
+ constructor();
12
+ scan(): Promise<ScanResult>;
13
+ getRecoveryOptions(disaster: Disaster): Promise<RecoveryOption[]>;
14
+ executeRecovery(disaster: Disaster, optionId: string, dryRun?: boolean): Promise<{
15
+ success: boolean;
16
+ output: string;
17
+ }>;
18
+ previewCommand(command: string): Promise<string>;
19
+ }
20
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAA0B,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE/E,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAc;;IAMnB,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAwB3B,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAKjE,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAmBpH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGvD"}
package/dist/core.js ADDED
@@ -0,0 +1,55 @@
1
+ import { GitExecutor } from './git/executor.js';
2
+ import { runAllDetectors } from './detectors/index.js';
3
+ import { getRecoveryForDisaster } from './recoveries/index.js';
4
+ export class GitPanicCore {
5
+ git;
6
+ constructor() {
7
+ this.git = new GitExecutor();
8
+ }
9
+ async scan() {
10
+ const isGitRepo = await this.git.isGitRepo();
11
+ if (!isGitRepo) {
12
+ return {
13
+ isGitRepo: false,
14
+ disasters: [],
15
+ currentBranch: null,
16
+ hasUncommittedChanges: false
17
+ };
18
+ }
19
+ const disasters = await runAllDetectors(this.git);
20
+ const currentBranch = await this.git.getCurrentBranch();
21
+ const hasUncommittedChanges = await this.git.hasUncommittedChanges();
22
+ return {
23
+ isGitRepo: true,
24
+ disasters,
25
+ currentBranch,
26
+ hasUncommittedChanges
27
+ };
28
+ }
29
+ async getRecoveryOptions(disaster) {
30
+ const recovery = getRecoveryForDisaster(disaster, this.git);
31
+ return recovery.getOptions(disaster);
32
+ }
33
+ async executeRecovery(disaster, optionId, dryRun = false) {
34
+ const recovery = getRecoveryForDisaster(disaster, this.git);
35
+ try {
36
+ const success = await recovery.execute(optionId, disaster, dryRun);
37
+ return {
38
+ success,
39
+ output: success
40
+ ? 'Recovery executed successfully.'
41
+ : 'Recovery failed. Please check the output above.'
42
+ };
43
+ }
44
+ catch (error) {
45
+ return {
46
+ success: false,
47
+ output: `Error: ${error.message}`
48
+ };
49
+ }
50
+ }
51
+ async previewCommand(command) {
52
+ return `[DRY RUN] Would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MAAM,GAAG,KAAK;QACxE,MAAM,QAAQ,GAAG,sBAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAE5D,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YACnE,OAAO;gBACL,OAAO;gBACP,MAAM,EAAE,OAAO;oBACb,CAAC,CAAC,iCAAiC;oBACnC,CAAC,CAAC,iDAAiD;aACtD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,UAAU,KAAK,CAAC,OAAO,EAAE;aAClC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAe;QAClC,OAAO,4BAA4B,OAAO,EAAE,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ import { GitExecutor } from '../git/executor.js';
2
+ import { ReflogParser } from '../git/reflog.js';
3
+ import { StatusAnalyzer } from '../git/status.js';
4
+ export interface Disaster {
5
+ id: string;
6
+ title: string;
7
+ description: string;
8
+ severity: 'low' | 'medium' | 'high';
9
+ confidence: number;
10
+ metadata: Record<string, any>;
11
+ }
12
+ export declare abstract class BaseDetector {
13
+ protected git: GitExecutor;
14
+ protected reflog: ReflogParser;
15
+ protected status: StatusAnalyzer;
16
+ constructor(git: GitExecutor);
17
+ abstract detect(): Promise<Disaster | null>;
18
+ }
19
+ export declare class AccidentalCommitDetector extends BaseDetector {
20
+ detect(): Promise<Disaster | null>;
21
+ }
22
+ export declare class DetachedHeadDetector extends BaseDetector {
23
+ detect(): Promise<Disaster | null>;
24
+ }
25
+ export declare class DeletedBranchDetector extends BaseDetector {
26
+ detect(): Promise<Disaster | null>;
27
+ }
28
+ export declare class ForcePushDetector extends BaseDetector {
29
+ detect(): Promise<Disaster | null>;
30
+ }
31
+ export declare class BotchedMergeDetector extends BaseDetector {
32
+ detect(): Promise<Disaster | null>;
33
+ }
34
+ export declare class UncommittedChangesDetector extends BaseDetector {
35
+ detect(): Promise<Disaster | null>;
36
+ }
37
+ export declare class WrongBranchCommitDetector extends BaseDetector {
38
+ detect(): Promise<Disaster | null>;
39
+ }
40
+ export declare function runAllDetectors(git: GitExecutor): Promise<Disaster[]>;
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/detectors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,8BAAsB,YAAY;IAChC,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC;IAC3B,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;gBAErB,GAAG,EAAE,WAAW;IAM5B,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAC5C;AAED,qBAAa,wBAAyB,SAAQ,YAAY;IAClD,MAAM,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAyBzC;AAED,qBAAa,oBAAqB,SAAQ,YAAY;IAC9C,MAAM,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAuBzC;AAED,qBAAa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