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

Function runREPL

cmd/aster/session.go:319–374  ·  view source on GitHub ↗

runREPL runs the read-eval-print loop

(ctx context.Context, ag *agent.Agent, sessionStore session.Service, sessionID string, useColor bool)

Source from the content-addressed store, hash-verified

317
318// runREPL runs the read-eval-print loop
319func runREPL(ctx context.Context, ag *agent.Agent, sessionStore session.Service, sessionID string, useColor bool) error {
320 reader := bufio.NewReader(os.Stdin)
321
322 for {
323 // Print prompt
324 printColored(useColor, colorBold+colorBlue, "\naster> ")
325
326 // Read input
327 input, err := reader.ReadString('\n')
328 if err != nil {
329 if err == io.EOF {
330 printColored(useColor, colorYellow, "\n\n👋 Goodbye!\n")
331 return nil
332 }
333 return fmt.Errorf("read input: %w", err)
334 }
335
336 input = strings.TrimSpace(input)
337 if input == "" {
338 continue
339 }
340
341 // Handle commands
342 if strings.HasPrefix(input, "/") {
343 handled, err := handleCommand(ctx, input, ag, sessionStore, sessionID, useColor)
344 if err != nil {
345 printColored(useColor, colorYellow, "Error: %s\n", err)
346 }
347 if handled {
348 if input == "/exit" || input == "/quit" {
349 return nil
350 }
351 continue
352 }
353 }
354
355 // Record user message to session
356 _ = sessionStore.AppendEvent(ctx, sessionID, &session.Event{
357 Author: "user",
358 Content: types.Message{
359 Role: types.RoleUser,
360 Content: input,
361 },
362 })
363
364 // Send to agent
365 fmt.Println()
366 if err := ag.Send(ctx, input); err != nil {
367 printColored(useColor, colorYellow, "Error: %s\n", err)
368 continue
369 }
370
371 // Wait for response to complete
372 waitForCompletion(ctx, ag)
373 }
374}
375
376// handleCommand handles slash commands

Callers 1

runSessionFunction · 0.85

Calls 5

printColoredFunction · 0.85
handleCommandFunction · 0.85
waitForCompletionFunction · 0.85
AppendEventMethod · 0.65
SendMethod · 0.45

Tested by

no test coverage detected