Class: Ask::AppServer::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/app_server/cli.rb

Overview

CLI for the ask-app-server command.

Usage:

ask-app-server                   # Start in stdio mode (default)
ask-app-server --version         # Show version
ask-app-server --help            # Show help
ask-app-server --config PATH     # Use specific config file

Environment variables:

ASK_APP_SERVER_CONFIG   - Path to config file (default: auto-detect)
ASK_APP_SERVER_MODEL    - Model to use (overrides config file)
ASK_APP_SERVER_PERMISSIONS - Permission mode (overrides config file)
DEBUG                   - Enable debug logging (1/0)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run!(args = ARGV) ⇒ Object



21
22
23
# File 'lib/ask/app_server/cli.rb', line 21

def self.run!(args = ARGV)
  new.run(args)
end

Instance Method Details

#run(args) ⇒ Object



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
# File 'lib/ask/app_server/cli.rb', line 25

def run(args)
  case args.first
  when "--version", "-v"
    puts "ask-app-server v#{Ask::AppServer::VERSION}"
    return
  when "--help", "-h"
    show_help
    return
  end

  # Parse --config from args
  config_path = nil
  remaining_args = []
  args.each_with_index do |arg, i|
    if arg == "--config" && i + 1 < args.length
      config_path = args[i + 1]
    elsif !arg.start_with?("--config")
      remaining_args << arg
    end
  end

  # Load configuration
  config = Config.new(config_path: config_path)

  # Register custom models from config into the model catalog
  config.register_models!

  $stdout.sync = true
  $stderr.sync = true

  if config.debug?
    $stderr.puts "[ask-app-server] Starting v#{Ask::AppServer::VERSION}"
    $stderr.puts "[ask-app-server] Config: #{JSON.pretty_generate(config.to_h)}"
  end

  # Build the session manager with config values
  store = build_state_store(config)
  session_manager = SessionManager.new(
    store: store,
    permission_mode: config.permission_mode,
    blocked_tools: config.blocked_tools,
    permission_timeout: config.permission_timeout
  )

  # Start the server
  server = Server.new(session_manager: session_manager)

  # Wire the server as the protocol sender for permission requests.
  # Every time a new session is created with a PermissionHandler,
  # the server registers its outgoing request callback.
  session_manager.on_new_permission_handler do |handler|
    server.register_permission_handler(handler)
  end

  begin
    server.start
  rescue Interrupt
    $stderr.puts "\n[ask-app-server] Shutting down..." if config.debug?
    server.stop
  end
end