MCPcopy Create free account
hub / github.com/diillson/chatcli / Start

Method Start

cli/cli.go:1015–1245  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

1013}
1014
1015func (cli *ChatCLI) Start(ctx context.Context) {
1016 cli.sessionCtx = ctx
1017 defer cli.cleanup(ctx)
1018 cli.PrintWelcomeScreen()
1019 cli.startHubSync(ctx) // resume the shared cross-channel conversation, if connected
1020
1021 // Mark the interactive REPL as active so the command-palette trigger only
1022 // fires here — never when HandleCommand is driven headless (scheduler,
1023 // gateway, one-shot), where unwinding the prompt has no meaning.
1024 cli.replActive = true
1025 defer func() { cli.replActive = false }()
1026
1027 shouldContinue := true
1028 for shouldContinue {
1029 func() {
1030 defer func() {
1031 if r := recover(); r != nil {
1032 // On Windows, go-prompt tearDown may panic with "close of closed channel"
1033 // which replaces our original panic value. Use pendingAction as fallback.
1034 action := cli.pendingAction
1035 cli.pendingAction = ""
1036 rErr, _ := r.(error)
1037 switch {
1038 case errors.Is(rErr, errAgentModeRequest) || action == "agent":
1039 // agent mode switch — nothing to undo here.
1040 case errors.Is(rErr, errCoderModeRequest) || action == "coder":
1041 cli.restoreTerminal()
1042 case errors.Is(rErr, errExitRequest) || action == "exit":
1043 shouldContinue = false
1044 default:
1045 panic(r)
1046 }
1047 }
1048 }()
1049
1050 pasteParser := paste.NewBracketedPasteParser(
1051 prompt.NewStandardInputParser(),
1052 func(info paste.Info) {
1053 cli.lastPasteInfo = &info
1054 },
1055 )
1056
1057 p := prompt.New(
1058 cli.executor,
1059 cli.completer,
1060 prompt.OptionParser(pasteParser),
1061 prompt.OptionTitle("ChatCLI - LLM no seu Terminal"),
1062 prompt.OptionLivePrefix(cli.changeLivePrefix),
1063 prompt.OptionPrefixTextColor(prompt.Green),
1064 prompt.OptionInputTextColor(prompt.White),
1065 prompt.OptionSuggestionBGColor(prompt.DarkGray),
1066 prompt.OptionDescriptionBGColor(prompt.Black),
1067 prompt.OptionSuggestionTextColor(prompt.White),
1068 prompt.OptionDescriptionTextColor(prompt.Yellow),
1069 prompt.OptionSelectedSuggestionBGColor(prompt.Blue),
1070 prompt.OptionSelectedDescriptionBGColor(prompt.DarkGray),
1071 prompt.OptionHistory(cli.commandHistory),
1072 prompt.OptionMaxSuggestion(10),

Callers 4

mainFunction · 0.95
initSchedulerMethod · 0.95
RunConnectFunction · 0.95
RunWatchFunction · 0.95

Calls 9

cleanupMethod · 0.95
PrintWelcomeScreenMethod · 0.95
startHubSyncMethod · 0.95
restoreTerminalMethod · 0.95
runCoderLogicMethod · 0.95
runAgentLogicMethod · 0.95
drainPendingResumesMethod · 0.95
NewBracketedPasteParserFunction · 0.92
RunMethod · 0.65

Tested by

no test coverage detected