7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/prompt_objects/cli/serve_command.rb', line 7
def run(args)
options = {
web: false,
mcp: false,
port: 3000,
host: "localhost",
open: false,
environment: nil
}
skip_next = false
args.each_with_index do |arg, i|
if skip_next
skip_next = false
next
end
case arg
when "--web"
options[:web] = true
when "--mcp"
options[:mcp] = true
when "--port"
options[:port] = args[i + 1].to_i
skip_next = true
when "--host"
options[:host] = args[i + 1]
skip_next = true
when "--open", "-o"
options[:open] = true
when "--help", "-h"
help
exit 0
else
options[:environment] = arg unless arg.start_with?("-")
end
end
unless options[:environment]
puts "Error: environment name or path required"
puts "Run '#{Helpers.program_name} serve --help' for usage"
exit 1
end
options[:web] = true unless options[:mcp]
if options[:mcp] && ENV["PROMPT_OBJECTS_LOG"]
$stderr.reopen(ENV["PROMPT_OBJECTS_LOG"], "a")
$stderr.sync = true
end
env_path = Helpers.resolve_environment(options[:environment])
unless env_path
$stderr.puts "Error: environment '#{options[:environment]}' not found"
exit 1
end
runtime = PromptObjects::Runtime.new(env_path: env_path)
Helpers.load_all_objects(runtime, env_path)
if options[:mcp]
connector = PromptObjects::Connectors::MCP.new(runtime: runtime)
connector.start
elsif options[:web]
require "prompt_objects/server"
rebuild_frontend
if options[:open]
url = "http://#{options[:host]}:#{options[:port]}"
Helpers.open_in_browser(url)
end
PromptObjects::Server.start(
runtime: runtime,
host: options[:host],
port: options[:port],
env_path: env_path
)
end
end
|