()
| 31 | var version = "dev" |
| 32 | |
| 33 | func main() { |
| 34 | if len(os.Args) > 1 { |
| 35 | switch os.Args[1] { |
| 36 | case "-v", "--version", "version": |
| 37 | fmt.Println("codehamr", version) |
| 38 | return |
| 39 | case "-h", "--help", "help": |
| 40 | printHelp() |
| 41 | return |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Wipe last session's superseded binary. Apply renames the running exe |
| 46 | // to <path>.old before promoting the new one; on Windows that old file |
| 47 | // stays locked until the prior process exits, so deleting it at launch |
| 48 | // (not at Apply time) always wins. |
| 49 | if exe, err := os.Executable(); err == nil { |
| 50 | update.CleanupOld(exe) |
| 51 | } |
| 52 | |
| 53 | // Pre-launch auto-update; all failures are non-fatal and fall through to |
| 54 | // the old binary. |
| 55 | maybeSelfUpdate() |
| 56 | |
| 57 | cwd := mustCwd() |
| 58 | // created is ignored: any first-run notice printed here is wiped milliseconds |
| 59 | // later by the unconditional screen+scrollback clear below, before the TUI |
| 60 | // draws, so there's nothing to announce. |
| 61 | cfg, _, err := config.Bootstrap(cwd) |
| 62 | if err != nil { |
| 63 | log.Fatalf("codehamr: %v", err) |
| 64 | } |
| 65 | applyEnvOverrides(cfg) |
| 66 | |
| 67 | // Opt-in debug log (`logging: true`): truncates .codehamr/log.txt and |
| 68 | // records every chat exchange. See tui.OpenDebugLog / dbgWrite. |
| 69 | if cfg.Logging { |
| 70 | tui.OpenDebugLog(cfg.Dir) |
| 71 | defer tui.CloseDebugLog() |
| 72 | } |
| 73 | |
| 74 | p := cfg.ActiveProfile() |
| 75 | client := llm.New(cfg.ActiveURL(), p.LLM, p.ResolvedKey()) |
| 76 | |
| 77 | abs, _ := filepath.Abs(cwd) |
| 78 | m := tui.New(cfg, client, abs, version) |
| 79 | |
| 80 | // Hard clear before the TUI takes over: \x1b[2J viewport, \x1b[3J |
| 81 | // scrollback, \x1b[H cursor home, a clean canvas free of prior shell |
| 82 | // history. Inline-mode safe: the session's own scrollback still |
| 83 | // accumulates via tea.Println. |
| 84 | os.Stdout.WriteString("\x1b[2J\x1b[3J\x1b[H") |
| 85 | |
| 86 | // Inline mode (no AltScreen, no mouse capture): only the prompt + status |
| 87 | // bar render live at the bottom; everything else goes to native |
| 88 | // scrollback via tea.Println, leaving scrolling/selection/copy to the |
| 89 | // terminal. |
| 90 | // |
nothing calls this directly
no test coverage detected