MCPcopy Create free account
hub / github.com/astercloud/aster / runSession

Function runSession

cmd/aster/session.go:41–177  ·  view source on GitHub ↗

runSession 启动交互式 CLI 会话

(args []string)

Source from the content-addressed store, hash-verified

39
40// runSession 启动交互式 CLI 会话
41func runSession(args []string) error {
42 fs := flag.NewFlagSet("session", flag.ExitOnError)
43 recipeFile := fs.String("recipe", "", "Recipe file to use")
44 workDir := fs.String("dir", ".", "Working directory")
45 provider := fs.String("provider", "", "LLM provider (anthropic, openai, deepseek)")
46 model := fs.String("model", "", "Model name")
47 noColor := fs.Bool("no-color", false, "Disable colored output")
48
49 fs.Usage = func() {
50 fmt.Fprintf(os.Stderr, "Usage: aster session [flags]\n\n")
51 fmt.Fprintf(os.Stderr, "Start an interactive AI agent session.\n\n")
52 fmt.Fprintf(os.Stderr, "Flags:\n")
53 fs.PrintDefaults()
54 fmt.Fprintf(os.Stderr, "\nCommands during session:\n")
55 fmt.Fprintf(os.Stderr, " /exit, /quit Exit the session\n")
56 fmt.Fprintf(os.Stderr, " /clear Clear conversation history\n")
57 fmt.Fprintf(os.Stderr, " /help Show help\n")
58 fmt.Fprintf(os.Stderr, " /status Show agent status\n")
59 }
60
61 if err := fs.Parse(args); err != nil {
62 return err
63 }
64
65 // Disable colors if requested or not a terminal
66 useColor := !*noColor && isTerminal(os.Stdout)
67
68 // Resolve working directory
69 absWorkDir, err := filepath.Abs(*workDir)
70 if err != nil {
71 return fmt.Errorf("resolve working directory: %w", err)
72 }
73
74 // Ensure config directories exist
75 if err := config.EnsureAllDirs(); err != nil {
76 return fmt.Errorf("create config directories: %w", err)
77 }
78
79 // Create session store (SQLite for desktop)
80 dbPath := config.DatabaseFile()
81 sessionStore, err := sqlite.New(dbPath)
82 if err != nil {
83 return fmt.Errorf("create session store: %w", err)
84 }
85 defer func() { _ = sessionStore.Close() }() // Best effort cleanup
86
87 // Create data store
88 storeDir := filepath.Join(config.DataDir(), "store")
89 if err := os.MkdirAll(storeDir, 0755); err != nil {
90 return fmt.Errorf("create store directory: %w", err)
91 }
92 dataStore, err := store.NewJSONStore(storeDir)
93 if err != nil {
94 return fmt.Errorf("create data store: %w", err)
95 }
96
97 // Load recipe if specified
98 var recipeConfig *recipe.Recipe

Callers 1

mainFunction · 0.85

Calls 15

EnsureAllDirsFunction · 0.92
DatabaseFileFunction · 0.92
NewFunction · 0.92
DataDirFunction · 0.92
NewJSONStoreFunction · 0.92
LoadFromFileFunction · 0.92
CreateFunction · 0.92
isTerminalFunction · 0.85
printColoredFunction · 0.85
buildModelConfigFunction · 0.85
createAgentDependenciesFunction · 0.85
applyRecipeToConfigFunction · 0.85

Tested by

no test coverage detected