Class: LanguageOperator::CLI::Commands::Persona
Overview
Persona management commands
Constant Summary
LanguageOperator::Constants::ALL_MODE_ALIASES, LanguageOperator::Constants::EXECUTION_MODES, LanguageOperator::Constants::PRIMARY_MODES, LanguageOperator::Constants::RESOURCE_AGENT, LanguageOperator::Constants::RESOURCE_AGENT_VERSION, LanguageOperator::Constants::RESOURCE_MODEL, LanguageOperator::Constants::RESOURCE_PERSONA, LanguageOperator::Constants::RESOURCE_TOOL
Instance Method Summary
collapse
#box, #highlight_ruby_code, #logo, #pastel, #prompt, #spinner, #table
current_cluster, current_cluster_config, ensure_cluster_selected!, get_cluster, get_cluster_config, kubernetes_client, validate_cluster_exists!, validate_kubeconfig!
normalize_mode, valid_mode?
Instance Method Details
#create(name) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/language_operator/cli/commands/persona.rb', line 113
def create(name)
handle_command_error('create persona') do
begin
ctx.client.get_resource(RESOURCE_PERSONA, name, ctx.namespace)
Formatters::ProgressFormatter.error("Persona '#{name}' already exists in cluster '#{ctx.name}'")
puts
puts 'Use a different name or delete the existing persona first:'
puts " langop persona delete #{name}"
exit 1
rescue K8s::Error::NotFound
end
base_persona = nil
if options[:from]
base_persona = get_resource_or_exit(RESOURCE_PERSONA, options[:from],
error_message: "Source persona '#{options[:from]}' not found")
Formatters::ProgressFormatter.info("Copying from persona '#{options[:from]}'")
puts
end
require 'tty-prompt'
puts
puts '=' * 80
puts ' Create New Persona'
puts '=' * 80
puts
default_display_name = base_persona&.dig('spec', 'displayName') || name.split('-').map(&:capitalize).join(' ')
display_name = prompt.ask('Display Name:', default: default_display_name)
default_description = base_persona&.dig('spec', 'description') || ''
description = prompt.ask('Description:', default: default_description) do |q|
q.required true
end
default_tone = base_persona&.dig('spec', 'tone') || 'neutral'
tone = prompt.select('Tone:', %w[neutral friendly professional technical creative], default: default_tone)
puts
puts 'System Prompt (press Enter to open editor):'
prompt.keypress('Press any key to continue...')
default_system_prompt = base_persona&.dig('spec', 'systemPrompt') || ''
system_prompt = Helpers::EditorHelper.edit_content(default_system_prompt, 'persona-system-prompt', '.txt')
if system_prompt.strip.empty?
Formatters::ProgressFormatter.error('System prompt cannot be empty')
exit 1
end
puts
puts 'Capabilities (optional, press Enter to open editor, or leave empty to skip):'
puts 'Describe what this persona can do, one per line.'
prompt.keypress('Press any key to continue...')
default_capabilities = base_persona&.dig('spec', 'capabilities')&.join("\n") || ''
capabilities_text = Helpers::EditorHelper.edit_content(default_capabilities, 'persona-capabilities', '.txt')
capabilities = capabilities_text.strip.empty? ? [] : capabilities_text.strip.split("\n").map(&:strip).reject(&:empty?)
persona_spec = {
'displayName' => display_name,
'description' => description,
'tone' => tone,
'systemPrompt' => system_prompt.strip
}
persona_spec['capabilities'] = capabilities unless capabilities.empty?
persona_resource = Kubernetes::ResourceBuilder.build_persona(
name: name,
spec: persona_spec,
namespace: ctx.namespace,
cluster_ref: ctx.name,
k8s_client: ctx.client
)
puts
puts '=' * 80
puts 'Preview:'
puts '=' * 80
puts YAML.dump(persona_resource)
puts '=' * 80
puts
unless prompt.yes?('Create this persona?')
puts 'Creation cancelled'
return
end
Formatters::ProgressFormatter.with_spinner("Creating persona '#{name}'") do
ctx.client.create_resource(persona_resource)
end
Formatters::ProgressFormatter.success("Persona '#{name}' created successfully")
puts
puts 'Use this persona when creating agents:'
puts " langop agent create \"description\" --persona #{name}"
end
end
|
#delete(name) ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'lib/language_operator/cli/commands/persona.rb', line 291
def delete(name)
handle_command_error('delete persona') do
get_resource_or_exit(RESOURCE_PERSONA, name)
return unless check_dependencies_and_confirm('persona', name, force: options[:force])
return unless confirm_deletion_with_force('persona', name, ctx.name, force: options[:force])
Formatters::ProgressFormatter.with_spinner("Deleting persona '#{name}'") do
ctx.client.delete_resource(RESOURCE_PERSONA, name, ctx.namespace)
end
end
end
|
#list ⇒ Object
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
|
# File 'lib/language_operator/cli/commands/persona.rb', line 17
def list
handle_command_error('list personas') do
personas = list_resources_or_empty(RESOURCE_PERSONA) do
puts
puts 'Personas define the personality and capabilities of agents.'
puts
puts 'Create a persona with:'
puts ' langop persona create <name>'
end
return if personas.empty?
agents = ctx.client.list_resources(RESOURCE_AGENT, namespace: ctx.namespace)
table_data = personas.map do |persona|
name = persona.dig('metadata', 'name')
used_by = agents.count { |a| a.dig('spec', 'persona') == name }
{
name: name,
tone: persona.dig('spec', 'tone') || 'neutral',
used_by: used_by,
description: persona.dig('spec', 'description') || ''
}
end
Formatters::TableFormatter.personas(table_data)
end
end
|
#show(name) ⇒ Object
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
97
98
99
100
101
|
# File 'lib/language_operator/cli/commands/persona.rb', line 50
def show(name)
handle_command_error('show persona') do
persona = get_resource_or_exit(RESOURCE_PERSONA, name)
puts
puts "Persona: #{pastel.cyan.bold(name)}"
puts '═' * 80
puts
spec = persona['spec'] || {}
puts "#{pastel.bold('Display Name:')} #{spec['displayName']}"
puts "#{pastel.bold('Tone:')} #{pastel.yellow(spec['tone'])}" if spec['tone']
puts
puts pastel.bold('Description:')
puts " #{spec['description']}"
puts
if spec['systemPrompt']
puts pastel.bold('System Prompt:')
puts " #{spec['systemPrompt']}"
puts
end
if spec['capabilities']&.any?
puts pastel.bold('Capabilities:')
spec['capabilities'].each do |cap|
puts " #{pastel.green('•')} #{cap}"
end
puts
end
if spec['toolPreferences']&.any?
puts pastel.bold('Tool Preferences:')
spec['toolPreferences'].each do |pref|
puts " #{pastel.green('•')} #{pref}"
end
puts
end
if spec['responseFormat']
puts "#{pastel.bold('Response Format:')} #{spec['responseFormat']}"
puts
end
puts '═' * 80
puts
Formatters::ProgressFormatter.info('Use this persona when creating agents:')
puts " langop agent create \"description\" --persona #{name}"
puts
end
end
|