aurora-modules 0.1.0

Git, filesystem, system, network, archive, docker, unix, crypto, calculator, QR, color, timer, notes, clipboard, and text processing modules
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
use aurora_core::{AuroraResult, Pipeline, Value, AuroraError};
use std::process::Command;
use std::io::{self, Write, BufRead};

fn check_git_installed() -> AuroraResult<()> {
    let status = Command::new("git").arg("--version").output()
        .map_err(|_| AuroraError::CommandNotFound(
            "Git не установлен. Установи: sudo pacman -S git (Arch) / sudo apt install git (Debian) / brew install git (macOS)".into()
        ))?;
    if !status.status.success() {
        return Err(AuroraError::CommandNotFound(
            "Git не установлен. Установи: sudo pacman -S git (Arch) / sudo apt install git (Debian) / brew install git (macOS)".into()
        ));
    }
    Ok(())
}

fn check_git_repo() -> AuroraResult<bool> {
    Ok(Command::new("git").args(["rev-parse", "--git-dir"]).output()
        .ok()
        .is_some_and(|o| o.status.success()))
}

fn require_git_repo(localizer: &aurora_locale::Localizer) -> AuroraResult<()> {
    if !check_git_repo()? {
        return Err(AuroraError::NotFound(
            localizer.t(
                "Не git-репозиторий. Запусти `aurora dev init` или `git init`.",
                "Not a git repository. Run `aurora dev init` or `git init` first."
            ).to_string()
        ));
    }
    Ok(())
}

fn check_git_config() -> AuroraResult<Option<(String, String)>> {
    let name = Command::new("git").args(["config", "user.name"]).output().ok()
        .and_then(|o| if o.status.success() {
            String::from_utf8(o.stdout).ok().map(|s| s.trim().to_string())
        } else { None });

    let email = Command::new("git").args(["config", "user.email"]).output().ok()
        .and_then(|o| if o.status.success() {
            String::from_utf8(o.stdout).ok().map(|s| s.trim().to_string())
        } else { None });

    match (name, email) {
        (Some(n), Some(e)) => Ok(Some((n, e))),
        _ => Ok(None),
    }
}

fn prompt(prompt_text: &str) -> AuroraResult<String> {
    print!("{prompt_text}");
    io::stdout().flush().ok();
    let mut line = String::new();
    io::stdin().lock().read_line(&mut line)
        .map_err(|_| AuroraError::ModuleError("Не удалось прочитать ввод".into()))?;
    Ok(line.trim().to_string())
}

fn prompt_yes_no(prompt_text: &str) -> AuroraResult<bool> {
    let answer = prompt(&format!("{prompt_text} [y/N]: "))?;
    Ok(answer.eq_ignore_ascii_case("y") || answer.eq_ignore_ascii_case("yes") || answer.eq_ignore_ascii_case("да"))
}

fn run_cmd(args: &[&str]) -> AuroraResult<(bool, String, String)> {
    let output = Command::new("git").args(args).output()
        .map_err(|e| AuroraError::ModuleError(format!("git failed: {e}")))?;
    let stdout = String::from_utf8_lossy(&output.stdout).to_string();
    let stderr = String::from_utf8_lossy(&output.stderr).to_string();
    Ok((output.status.success(), stdout, stderr))
}

const GITIGNORE_TEMPLATE: &str = r#".gitignore           # Локальный — не засоряет репозиторий

# ===== Файлы сборки / зависимостей =====
target/          # Rust: результат компиляции (cargo build)
build/           # C/C++/Make: папка сборки
dist/            # Собранные файлы для публикации
node_modules/    # JavaScript: зависимости npm (их НЕ хранят в git)
vendor/          # PHP / Go: сторонние библиотеки
__pycache__/     # Python: кеш байткода
*.pyc            # Python: скомпилированные файлы
.env             # Локальные переменные (пароли, ключи API)

# ===== IDE и редакторы =====
.idea/           # JetBrains (IntelliJ IDEA, PyCharm, GoLand)
.vscode/         # VS Code — только если там не общие настройки
*.swp            # Vim: временные файлы
*.swo            # Vim: временные файлы
.DS_Store        # macOS: служебные файлы Finder
Thumbs.db        # Windows: кеш миниатюр

# ===== Логи и временные файлы =====
*.log            # Лог-файлы (их не коммитят)
*.tmp            # Временные файлы
*.bak            # Бэкапы
"#;

fn ensure_git_repo(localizer: &aurora_locale::Localizer) -> AuroraResult<()> {
    if check_git_repo()? {
        return Ok(());
    }

    println!();
    println!("{}", localizer.t(
        "⚠ Git-репозиторий не найден! Хочешь создать его?",
        "⚠ Git repository not found! Would you like to create one?"
    ));
    println!("  {}", localizer.t(
        "Это создаст папку .git и начнёт отслеживать изменения в проекте.",
        "This creates a .git folder and starts tracking changes in your project."
    ));

    if !prompt_yes_no(localizer.t("Создать репозиторий", "Create repository"))? {
        return Err(AuroraError::ModuleError(
            localizer.t(
                "Коммит отменён — нет репозитория. Создай вручную: git init",
                "Commit cancelled — no repository. Create manually: git init"
            ).to_string()
        ));
    }

    let (ok, _, err) = run_cmd(&["init"])?;
    if !ok {
        return Err(AuroraError::ModuleError(
            format!("git init failed: {err}")
        ));
    }

    println!("{}", localizer.t("✓ Репозиторий создан!", "✓ Repository created!"));
    println!();

    // .gitignore
    if prompt_yes_no(localizer.t(
        "Создать файл .gitignore? Он скрывает мусор (log, tmp, __pycache__...) из репозитория.",
        "Create .gitignore? It hides junk files (logs, tmp, __pycache__...) from the repo."
    ))? {
        let gitignore_path = std::path::Path::new(".gitignore");
        if gitignore_path.exists() {
            println!("  .gitignore уже существует — пропускаем.");
        } else {
            std::fs::write(gitignore_path, GITIGNORE_TEMPLATE)
                .map_err(|e| AuroraError::ModuleError(format!("Не удалось создать .gitignore: {e}")))?;
            println!("{}", localizer.t(
                "✓ .gitignore создан! Отредактируй его под свой проект.",
                "✓ .gitignore created! Edit it for your project."
            ));
        }
    }

    Ok(())
}

fn ensure_git_config(localizer: &aurora_locale::Localizer) -> AuroraResult<()> {
    if let Some((name, email)) = check_git_config()? {
        println!("  {}: {name} <{email}>", localizer.t("Git настроен как", "Git configured as"));
        return Ok(());
    }

    println!();
    println!("{}", localizer.t(
        "⚠ Git не знает твоё имя и email — они нужны для подписи коммитов.",
        "⚠ Git doesn't know your name and email — needed to sign commits."
    ));

    let name = prompt(&localizer.t("Введи имя (как в подписи к коммиту): ", "Enter your name (as commit signature): "))?;
    if name.is_empty() {
        return Err(AuroraError::ModuleError(
            localizer.t("Имя не может быть пустым. Коммит отменён.", "Name cannot be empty. Commit cancelled.").to_string()
        ));
    }

    let email = prompt(&localizer.t("Введи email: ", "Enter your email: "))?;
    if email.is_empty() {
        return Err(AuroraError::ModuleError(
            localizer.t("Email не может быть пустым. Коммит отменён.", "Email cannot be empty. Commit cancelled.").to_string()
        ));
    }

    let (ok1, _, _) = run_cmd(&["config", "user.name", &name])?;
    let (ok2, _, _) = run_cmd(&["config", "user.email", &email])?;

    if ok1 && ok2 {
        println!("{}", localizer.t("✓ Git настроен!", "✓ Git configured!"));
    }

    Ok(())
}

fn ensure_staged(localizer: &aurora_locale::Localizer) -> AuroraResult<bool> {
    let (_, stdout, _) = run_cmd(&["status", "--short"])?;

    if stdout.trim().is_empty() {
        println!("{}", localizer.t(
            "Нет изменений для коммита. Нечего коммитить.",
            "No changes to commit. Nothing to commit."
        ));
        return Ok(false);
    }

    let lines: Vec<&str> = stdout.lines()
        .filter(|l| !l.trim().is_empty())
        .collect();

    // Первый символ — статус в индексе (staging area)
    // ' ' = не в индексе, '?' = untracked, M/A/D/R = staged
    let staged: Vec<&&str> = lines.iter().filter(|l| {
        let c = l.as_bytes().first().copied().unwrap_or(b' ');
        c != b' ' && c != b'?'
    }).collect();

    let unstaged: Vec<&&str> = lines.iter().filter(|l| {
        let c = l.as_bytes().first().copied().unwrap_or(b' ');
        c == b' '
    }).collect();

    let untracked: Vec<&&str> = lines.iter().filter(|l| {
        l.starts_with("??")
    }).collect();

    if !staged.is_empty() {
        return Ok(true);
    }

    if !untracked.is_empty() || !unstaged.is_empty() {
        let total = untracked.len() + unstaged.len();
        println!("  {total} {}", localizer.t(
            "файлов не добавлены в коммит. Нужно git add",
            "files not staged. Need git add"
        ));

        if prompt_yes_no(localizer.t(
            "Добавить ВСЕ (git add -A)?",
            "Add ALL (git add -A)?"
        ))? {
            run_cmd(&["add", "-A"])?;
            println!("{}", localizer.t(
                "✓ Все файлы добавлены!",
                "✓ All files staged!"
            ));
            return Ok(true);
        }

        println!("  {}", localizer.t(
            "Коммит отменён. Добавь файлы: git add <file>",
            "Commit cancelled. Stage files: git add <file>"
        ));
        return Ok(false);
    }

    Ok(false)
}

pub fn dev_commit(msg: &str, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;

    // Шаг 1: репозиторий
    ensure_git_repo(localizer)?;

    // Шаг 2: конфиг git
    ensure_git_config(localizer)?;

    // Шаг 3: staged файлы
    if !ensure_staged(localizer)? {
        return Ok(Pipeline::single(Value::String(
            localizer.t("Коммит отменён.", "Commit cancelled.").to_string()
        )));
    }

    // Шаг 4: если сообщение не указано — спросить
    let commit_msg = if msg.is_empty() || msg == "commit" {
        println!();
        println!("{}", localizer.t(
            "Опиши, что изменилось (описание коммита):",
            "Describe what changed (commit message):"
        ));
        prompt("> ")?
    } else {
        msg.to_string()
    };

    if commit_msg.is_empty() {
        return Err(AuroraError::ModuleError(
            localizer.t("Сообщение коммита не может быть пустым.", "Commit message cannot be empty.").to_string()
        ));
    }

    // Шаг 5: коммит
    let (ok, _stdout, stderr) = run_cmd(&["commit", "-m", &commit_msg])?;

    if !ok {
        return Err(AuroraError::ModuleError(
            format!("{}: {stderr}",
                localizer.t("Git commit не удался", "Git commit failed")
            )
        ));
    }

    println!();
    println!("{}", localizer.t("✓ Закоммичено!", "✓ Committed!"));
    println!("  {commit_msg}");

    Ok(Pipeline::table(
        vec!["status".into(), "message".into()],
        vec![vec![
            Value::String("committed".into()),
            Value::String(commit_msg),
        ]],
    ))
}

pub fn dev_log(oneline: bool, graph: bool, n: Option<usize>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;
    let mut cmd = Command::new("git");
    cmd.arg("log");
    if graph { cmd.arg("--graph"); }
    if let Some(count) = n { cmd.arg(format!("-{count}")); }
    if oneline {
        cmd.arg("--oneline");
    } else {
        cmd.arg("--format=COMMIT%x1e%H%x1f%an%x1f%ai%x1f%s");
    }

    let output = cmd.output()
        .map_err(|e| AuroraError::ModuleError(format!("git log failed: {e}")))?;
    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        return Err(AuroraError::ModuleError(format!("git log: {stderr}")));
    }

    let stdout = String::from_utf8_lossy(&output.stdout);
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in stdout.lines() {
        if line.is_empty() { continue; }
        if oneline {
            let clean = if graph { line.split('\x1e').last().unwrap_or(line) } else { line };
            if let Some(pos) = clean.find(' ') {
                let hash = &clean[..pos];
                let msg = clean[pos + 1..].trim();
                rows.push(vec![
                    Value::String(hash.into()),
                    Value::String(String::new()),
                    Value::String(String::new()),
                    Value::String(msg.into()),
                ]);
            }
        } else {
            let clean = if graph { line.split('\x1e').last().unwrap_or(line) } else { line };
            let parts: Vec<&str> = clean.splitn(4, '\x1f').collect();
            if parts.len() >= 4 {
                rows.push(vec![
                    Value::String(parts[0].into()),
                    Value::String(parts[1].into()),
                    Value::String(parts[2].into()),
                    Value::String(parts[3].into()),
                ]);
            }
        }
    }
    Ok(Pipeline::table(
        vec!["commit".into(), "author".into(), "date".into(), "message".into()],
        rows,
    ))
}

pub fn dev_status() -> AuroraResult<Pipeline> {
    check_git_installed()?;
    if !check_git_repo()? {
        return Ok(Pipeline::single(Value::String(
            "Not a git repository. Use 'aurora dev commit' to create one.".to_string()
        )));
    }
    let output = Command::new("git").args(["status", "--short"]).output()
        .map_err(|e| AuroraError::ModuleError(format!("git status failed: {e}")))?;
    let stdout = String::from_utf8_lossy(&output.stdout);
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in stdout.lines() {
        let line = line.trim();
        if line.is_empty() || line.len() <= 3 { continue; }
        let status = &line[..2];
        let file = &line[3..];
        rows.push(vec![Value::String(status.trim().into()), Value::String(file.into())]);
    }
    Ok(Pipeline::table(vec!["status".into(), "file".into()], rows))
}

pub fn dev_diff(stat: bool, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;
    let mut cmd = Command::new("git");
    cmd.arg("diff");
    if stat { cmd.arg("--stat"); }
    let output = cmd.output()
        .map_err(|e| AuroraError::ModuleError(format!("git diff failed: {e}")))?;
    let stdout = String::from_utf8_lossy(&output.stdout);
    let mut rows: Vec<Vec<Value>> = Vec::new();
    if stat {
        for line in stdout.lines() {
            if line.is_empty() { continue; }
            rows.push(vec![Value::String(line.into())]);
        }
    } else {
        rows.push(vec![Value::String(stdout.into())]);
    }
    Ok(Pipeline::table(vec!["diff".into()], rows))
}

pub fn dev_push(remote: Option<&str>, branch: Option<&str>, upstream: bool, force: bool, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let remote = remote.unwrap_or("origin");
    let current_branch = if branch.is_some() {
        branch.unwrap().to_string()
    } else {
        let (ok, stdout, _) = run_cmd(&["rev-parse", "--abbrev-ref", "HEAD"])?;
        if !ok {
            return Err(AuroraError::ModuleError(
                "Не удалось определить текущую ветку".into()
            ));
        }
        stdout.trim().to_string()
    };

    let remote_str = remote.to_string();
    let branch_str = current_branch.clone();

    if force {
        if !prompt_yes_no(&format!(
            "{} {}/{}? {}",
            localizer.t("⚠ FORCE PUSH на", "⚠ FORCE PUSH to"),
            remote_str, branch_str,
            localizer.t("История будет перезаписана! Продолжить?", "History will be rewritten! Continue?")
        ))? {
            return Ok(Pipeline::single(Value::String(localizer.t("Отменено.", "Cancelled.").to_string())));
        }
    }

    println!("{} {}/{}", localizer.t("→ Пушим в", "→ Pushing to"), remote, current_branch);

    let mut args = vec!["push"];
    if upstream { args.push("-u"); }
    if force { args.push("--force"); }
    args.push(remote);
    args.push(&current_branch);

    let (ok, stdout, stderr) = run_cmd(&args)?;

    if !ok {
        let msg = if stderr.contains("fatal:") && stderr.contains("repository") {
            localizer.t(
                "Репозиторий не найден. Проверь remote: aurora dev remote list",
                "Repository not found. Check remote: aurora dev remote list"
            )
        } else if stderr.contains("fatal:") && stderr.contains("refspec") {
            localizer.t(
                "Ветка не найдена на удалённом репозитории. Попробуй --upstream или git push -u origin <ветка>",
                "Branch not found on remote. Try --upstream or git push -u origin <branch>"
            )
        } else {
            localizer.t(
                "Git push не удался. Проверь remote и права доступа.",
                "Git push failed. Check remote and access rights."
            )
        };
        return Err(AuroraError::ModuleError(format!("{msg}\n{stderr}")));
    }

    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in output.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        rows.push(vec![Value::String(line.into())]);
    }

    println!("{} {}/{}", localizer.t("✓ Запушено в", "✓ Pushed to"), remote, current_branch);
    Ok(Pipeline::table(vec!["output".into()], rows))
}

pub fn dev_fetch(remote: Option<&str>, branch: Option<&str>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let remote = remote.unwrap_or("origin");
    let mut args = vec!["fetch", remote];
    if let Some(b) = branch { args.push(b); }

    println!("{} {}", localizer.t("→ Получаю из", "→ Fetching from"), remote);
    let (ok, stdout, stderr) = run_cmd(&args)?;

    if !ok {
        return Err(AuroraError::ModuleError(
            format!("git fetch: {stderr}")
        ));
    }

    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in output.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        rows.push(vec![Value::String(line.into())]);
    }

    println!("{} {}{}",
        localizer.t("✓ Получено из", "✓ Fetched from"),
        remote,
        branch.map(|b| format!(" ({b})")).unwrap_or_default()
    );
    Ok(Pipeline::table(vec!["output".into()], rows))
}

pub fn dev_pull(remote: Option<&str>, branch: Option<&str>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let remote = remote.unwrap_or("origin");
    let current_branch = if branch.is_some() {
        branch.unwrap().to_string()
    } else {
        let (ok, stdout, _) = run_cmd(&["rev-parse", "--abbrev-ref", "HEAD"])?;
        if !ok {
            return Err(AuroraError::ModuleError(
                "Не удалось определить текущую ветку".into()
            ));
        }
        stdout.trim().to_string()
    };

    println!("{} {}/{}", localizer.t("→ Тяну из", "→ Pulling from"), remote, current_branch);

    let (ok, stdout, stderr) = run_cmd(&["pull", remote, &current_branch])?;
    if !ok {
        return Err(AuroraError::ModuleError(format!("git pull: {stderr}")));
    }

    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in output.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        rows.push(vec![Value::String(line.into())]);
    }

    Ok(Pipeline::table(vec!["output".into()], rows))
}

pub fn dev_clone(url: &str, target: Option<&str>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;

    let dir = target.unwrap_or("");
    println!("{} {} {}",
        localizer.t("→ Клонирую", "→ Cloning"),
        url,
        if dir.is_empty() { "".into() } else { format!("{dir}") }
    );

    let mut args = vec!["clone", url];
    if !dir.is_empty() { args.push(dir); }

    let (ok, _stdout, stderr) = run_cmd(&args)?;
    if !ok {
        return Err(AuroraError::ModuleError(format!("git clone: {stderr}")));
    }

    println!("{}", localizer.t("✓ Репозиторий склонирован!", "✓ Repository cloned!"));
    Ok(Pipeline::table(
        vec!["url".into(), "target".into()],
        vec![vec![Value::String(url.into()), Value::String(if dir.is_empty() { "." } else { dir }.into())]],
    ))
}

pub fn dev_init(localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;

    if check_git_repo()? {
        return Err(AuroraError::ModuleError(
            localizer.t("Репозиторий уже инициализирован.", "Repository already initialized.").to_string()
        ));
    }

    let (ok, _, stderr) = run_cmd(&["init"])?;
    if !ok {
        return Err(AuroraError::ModuleError(format!("git init: {stderr}")));
    }

    println!("{}", localizer.t("✓ Репозиторий создан!", "✓ Repository created!"));

    // .gitignore
    if prompt_yes_no(localizer.t(
        "Создать .gitignore? Он скрывает мусор из репозитория.",
        "Create .gitignore? It hides junk from the repo."
    ))? {
        let gitignore_path = std::path::Path::new(".gitignore");
        if gitignore_path.exists() {
            println!("  .gitignore уже существует — пропускаем.");
        } else {
            std::fs::write(gitignore_path, GITIGNORE_TEMPLATE)
                .map_err(|e| AuroraError::ModuleError(format!("Не удалось создать .gitignore: {e}")))?;
            println!("{}", localizer.t("✓ .gitignore создан!", "✓ .gitignore created!"));
        }
    }

    // user config
    if let Some((name, email)) = check_git_config()? {
        println!("  {}: {name} <{email}>", localizer.t("Git настроен как", "Git configured as"));
    } else if prompt_yes_no(localizer.t(
        "Настроить имя и email для git?",
        "Set up your git name and email?"
    ))? {
        let name = prompt(&localizer.t("Имя: ", "Name: "))?;
        let email = prompt(&localizer.t("Email: ", "Email: "))?;
        if !name.is_empty() && !email.is_empty() {
            run_cmd(&["config", "user.name", &name])?;
            run_cmd(&["config", "user.email", &email])?;
            println!("{}", localizer.t("✓ Git настроен!", "✓ Git configured!"));
        }
    }

    Ok(Pipeline::table(
        vec!["status".into()],
        vec![vec![Value::String("initialized".into())]],
    ))
}

pub fn dev_add(files: &[String], localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let (ok, stdout, stderr) = if files.is_empty() {
        run_cmd(&["add", "-A"])?
    } else {
        let mut args = vec!["add"];
        for f in files { args.push(f); }
        run_cmd(&args)?
    };

    if !ok {
        return Err(AuroraError::ModuleError(format!("git add: {stderr}")));
    }

    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in output.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        rows.push(vec![Value::String(line.into())]);
    }

    println!("{}", localizer.t("✓ Файлы добавлены!", "✓ Files staged!"));
    Ok(Pipeline::table(vec!["output".into()], rows))
}

pub fn dev_checkout(target: Option<&str>, create: bool, orphan: bool, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let mut args = vec!["checkout"];
    if orphan {
        args.push("--orphan");
        let branch = target.unwrap_or("");
        if branch.is_empty() {
            return Err(AuroraError::InvalidInput(
                localizer.t("Укажи имя ветки: aurora dev checkout --orphan <имя>", "Specify branch name: aurora dev checkout --orphan <name>").to_string()
            ));
        }
        args.push(branch);
        let (ok, stdout, stderr) = run_cmd(&args)?;
        if !ok { return Err(AuroraError::ModuleError(format!("git checkout --orphan: {stderr}"))); }
        println!("{} {}", localizer.t("✓ Создана orphan-ветка", "✓ Created orphan branch"), branch);
        let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
        return Ok(Pipeline::table(vec!["output".into()], vec![vec![Value::String(output.trim().into())]]));
    }

    let target = target.unwrap_or("");
    if create && !target.is_empty() { args.push("-b"); }
    if !target.is_empty() { args.push(target); }

    let (ok, stdout, stderr) = run_cmd(&args)?;
    if !ok {
        let hint = if stderr.contains("already exists") {
            localizer.t("Ветка уже существует. Используй dev checkout <ветка> без --create.", "Branch exists. Use dev checkout <branch> without --create.")
        } else if stderr.contains("did not match any") {
            localizer.t("Ветка не найдена. Используй --create чтобы создать.", "Branch not found. Use --create to create it.")
        } else { "" };
        return Err(AuroraError::ModuleError(format!("git checkout: {stderr}{}", if hint.is_empty() { "".into() } else { format!("\n{hint}") })));
    }

    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in output.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        rows.push(vec![Value::String(line.into())]);
    }

    println!("{} {}{}", localizer.t("✓ Переключено на", "✓ Switched to"), target,
        if create { localizer.t("(новая ветка)", "(new branch)") } else { "" });
    Ok(Pipeline::table(vec!["output".into()], rows))
}

pub fn dev_stash_push(localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;
    let (ok, _stdout, stderr) = run_cmd(&["stash"])?;
    if !ok { return Err(AuroraError::ModuleError(format!("git stash: {stderr}"))); }
    println!("{}", localizer.t("✓ Изменения спрятаны!", "✓ Changes stashed!"));
    Ok(Pipeline::table(vec!["output".into()], vec![vec![Value::String(stderr.trim().into())]]))
}

pub fn dev_stash_list(localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;
    let (ok, stdout, stderr) = run_cmd(&["stash", "list"])?;
    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    if !ok { return Err(AuroraError::ModuleError(format!("git stash: {stderr}"))); }
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in output.lines() { let l = line.trim(); if l.is_empty() { continue; } rows.push(vec![Value::String(l.into())]); }
    Ok(Pipeline::table(vec!["stash".into()], rows))
}

pub fn dev_stash_pop(localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;
    let (ok, stdout, stderr) = run_cmd(&["stash", "pop"])?;
    if !ok { return Err(AuroraError::ModuleError(format!("git stash: {stderr}"))); }
    println!("{}", localizer.t("✓ Изменения достаны!", "✓ Changes popped!"));
    let output = if stdout.trim().is_empty() { &stderr } else { &stdout };
    Ok(Pipeline::table(vec!["output".into()], vec![vec![Value::String(output.trim().into())]]))
}

pub fn dev_reset(files: &[String], hard: bool, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    if hard {
        if !prompt_yes_no(&localizer.t(
            "⚠ HARD RESET — все несохранённые изменения будут потеряны! Продолжить?",
            "⚠ HARD RESET — all unsaved changes will be lost! Continue?"
        ))? {
            return Ok(Pipeline::single(Value::String(localizer.t("Отменено.", "Cancelled.").to_string())));
        }
        let (ok, _, stderr) = run_cmd(&["reset", "--hard"])?;
        if !ok { return Err(AuroraError::ModuleError(format!("git reset: {stderr}"))); }
        println!("{}", localizer.t("✓ Жёсткий сброс выполнен!", "✓ Hard reset done!"));
    } else if files.is_empty() {
        let (ok, _, stderr) = run_cmd(&["reset"])?;
        if !ok { return Err(AuroraError::ModuleError(format!("git reset: {stderr}"))); }
        println!("{}", localizer.t("✓ Все файлы сняты с индекса!", "✓ All files unstaged!"));
    } else {
        let mut args = vec!["reset"];
        for f in files { args.push(f); }
        let (ok, _, stderr) = run_cmd(&args)?;
        if !ok { return Err(AuroraError::ModuleError(format!("git reset: {stderr}"))); }
    }

    Ok(Pipeline::table(
        vec!["status".into()],
        vec![vec![Value::String(if hard { "hard reset" } else { "reset" }.into())]],
    ))
}

pub fn dev_config(key: Option<&str>, value: Option<&str>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;

    match (key, value) {
        (Some(k), Some(v)) => {
            let (ok, _, stderr) = run_cmd(&["config", k, v])?;
            if !ok { return Err(AuroraError::ModuleError(format!("git config: {stderr}"))); }
            println!("{} {k} = {v}", localizer.t("✓ Установлено:", "✓ Set:"));
            Ok(Pipeline::table(
                vec!["key".into(), "value".into()],
                vec![vec![Value::String(k.into()), Value::String(v.into())]],
            ))
        }
        (Some(k), None) => {
            let (ok, stdout, stderr) = run_cmd(&["config", k])?;
            if !ok { return Err(AuroraError::ModuleError(format!("git config: {stderr}"))); }
            Ok(Pipeline::table(
                vec!["key".into(), "value".into()],
                vec![vec![Value::String(k.into()), Value::String(stdout.trim().into())]],
            ))
        }
        (None, None) => {
            let (ok, stdout, stderr) = run_cmd(&["config", "--list"])?;
            if !ok { return Err(AuroraError::ModuleError(format!("git config: {stderr}"))); }
            let mut rows: Vec<Vec<Value>> = Vec::new();
            for line in stdout.lines() {
                let line = line.trim();
                if line.is_empty() { continue; }
                if let Some(eq) = line.find('=') {
                    rows.push(vec![Value::String(line[..eq].into()), Value::String(line[eq+1..].into())]);
                }
            }
            Ok(Pipeline::table(vec!["key".into(), "value".into()], rows))
        }
        (None, Some(_)) => Err(AuroraError::InvalidInput(
            "нельзя указать значение без ключа. Используй: aurora dev config <key> <value>".into()
        )),
    }
}

pub fn dev_remote_add(name: Option<&str>, url: Option<&str>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let remote_name = name.unwrap_or("origin");

    let repo_url = match url {
        Some(u) => u.to_string(),
        None => {
            println!("{}", localizer.t(
                "Введи URL репозитория (например https://github.com/user/repo.git):",
                "Enter repository URL (e.g. https://github.com/user/repo.git):"
            ));
            prompt("> ")?
        }
    };

    if repo_url.is_empty() {
        return Err(AuroraError::ModuleError(
            localizer.t("URL не может быть пустым.", "URL cannot be empty.").to_string()
        ));
    }

    // Проверяем, существует ли уже такой remote
    let (exists_ok, remotes, _) = run_cmd(&["remote", "get-url", remote_name])?;
    if exists_ok {
        if !prompt_yes_no(&format!(
            "{} {}: {}. {}?",
            localizer.t("Remote", "Remote"),
            remote_name,
            remotes.trim(),
            localizer.t("Перезаписать", "Overwrite")
        ))? {
            return Ok(Pipeline::single(Value::String(
                localizer.t("Отменено.", "Cancelled.").to_string()
            )));
        }
        run_cmd(&["remote", "set-url", remote_name, &repo_url])?;
        println!("{} {} = {repo_url}", localizer.t("✓ Remote обновлён:", "✓ Remote updated:"), remote_name);
    } else {
        run_cmd(&["remote", "add", remote_name, &repo_url])?;
        println!("{} {} = {repo_url}", localizer.t("✓ Remote добавлен:", "✓ Remote added:"), remote_name);
    }

    Ok(Pipeline::table(
        vec!["remote".into(), "url".into()],
        vec![vec![Value::String(remote_name.into()), Value::String(repo_url)]],
    ))
}

pub fn dev_remote_list(localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let (ok, stdout, stderr) = run_cmd(&["remote", "-v"])?;
    if !ok {
        return Err(AuroraError::ModuleError(
            format!("git remote: {stderr}")
        ));
    }

    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in stdout.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        let parts: Vec<&str> = line.splitn(2, '\t').collect();
        if parts.len() == 2 {
            rows.push(vec![
                Value::String(parts[0].into()),
                Value::String(parts[1].into()),
            ]);
        }
    }

    if rows.is_empty() {
        println!("{}", localizer.t(
            "Нет удалённых репозиториев. Добавь: aurora dev remote add <url>",
            "No remotes configured. Add one: aurora dev remote add <url>"
        ));
    }

    Ok(Pipeline::table(vec!["remote".into(), "url".into()], rows))
}

pub fn dev_remote_remove(name: &str, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    let (ok, _, stderr) = run_cmd(&["remote", "remove", name])?;
    if !ok {
        let hint = if stderr.contains("No such remote") {
            format!(". {}",
                localizer.t("Проверь список: aurora dev remote list", "Check the list: aurora dev remote list")
            )
        } else { String::new() };
        return Err(AuroraError::ModuleError(format!("git remote remove: {stderr}{hint}")));
    }

    println!("{} {}", localizer.t("✓ Remote удалён:", "✓ Remote removed:"), name);
    Ok(Pipeline::table(
        vec!["remote".into(), "action".into()],
        vec![vec![Value::String(name.into()), Value::String("removed".into())]],
    ))
}

pub fn dev_branch(delete: bool, rename: bool, name: Option<&str>, localizer: &aurora_locale::Localizer) -> AuroraResult<Pipeline> {
    check_git_installed()?;
    require_git_repo(localizer)?;

    if delete {
        let branch = name.unwrap_or("");
        if branch.is_empty() {
            return Err(AuroraError::InvalidInput(
                localizer.t("Укажи ветку для удаления: aurora dev branch -D <имя>", "Specify branch to delete: aurora dev branch -D <name>").to_string()
            ));
        }
        let (ok, _, stderr) = run_cmd(&["branch", "-D", branch])?;
        if !ok { return Err(AuroraError::ModuleError(format!("git branch -D: {stderr}"))); }
        println!("{} {}", localizer.t("✓ Ветка удалена:", "✓ Branch deleted:"), branch);
        return Ok(Pipeline::table(
            vec!["branch".into(), "action".into()],
            vec![vec![Value::String(branch.into()), Value::String("deleted".into())]],
        ));
    }

    if rename {
        let new_name = name.unwrap_or("");
        if new_name.is_empty() {
            return Err(AuroraError::InvalidInput(
                localizer.t("Укажи новое имя: aurora dev branch -m <новое-имя>", "Specify new name: aurora dev branch -m <new-name>").to_string()
            ));
        }
        let (ok, _, stderr) = run_cmd(&["branch", "-m", new_name])?;
        if !ok { return Err(AuroraError::ModuleError(format!("git branch -m: {stderr}"))); }
        println!("{} {}", localizer.t("✓ Ветка переименована в:", "✓ Branch renamed to:"), new_name);
        return Ok(Pipeline::table(
            vec!["branch".into(), "action".into()],
            vec![vec![Value::String(new_name.into()), Value::String("renamed".into())]],
        ));
    }

    let output = Command::new("git").arg("branch").output()
        .map_err(|e| AuroraError::ModuleError(format!("git branch failed: {e}")))?;
    let stdout = String::from_utf8_lossy(&output.stdout);
    let mut rows: Vec<Vec<Value>> = Vec::new();
    for line in stdout.lines() {
        let line = line.trim();
        if line.is_empty() { continue; }
        let current = line.starts_with('*');
        let name = if current { &line[2..] } else { line };
        rows.push(vec![Value::String(name.trim().into()), Value::Bool(current)]);
    }
    Ok(Pipeline::table(vec!["branch".into(), "current".into()], rows))
}