kward 0.84.0 → 0.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +164 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +6 -2
- data/README.md +5 -5
- data/Rakefile +3 -0
- data/doc/agent-tools.md +24 -1
- data/doc/api.md +20 -2
- data/doc/composer.md +5 -4
- data/doc/configuration.md +86 -14
- data/doc/extensibility.md +4 -1
- data/doc/getting-started.md +3 -3
- data/doc/git.md +4 -2
- data/doc/memory.md +1 -1
- data/doc/pan.md +6 -0
- data/doc/permissions.md +4 -4
- data/doc/plugins.md +504 -20
- data/doc/providers.md +10 -4
- data/doc/rpc.md +279 -23
- data/doc/sandboxing.md +11 -5
- data/doc/security.md +7 -1
- data/doc/session-management.md +41 -5
- data/doc/shell.md +643 -27
- data/doc/tabs.md +8 -3
- data/doc/transports.md +15 -0
- data/doc/troubleshooting.md +1 -1
- data/doc/usage.md +25 -12
- data/doc/workspace-tools.md +9 -0
- data/examples/plugins/openrouter_proxy/README.md +103 -0
- data/examples/plugins/openrouter_proxy/fake_embeddings.rb +85 -0
- data/examples/plugins/openrouter_proxy/plugin.rb +7 -0
- data/examples/plugins/openrouter_proxy/protocol.rb +202 -0
- data/examples/plugins/openrouter_proxy/server.rb +186 -0
- data/examples/plugins/space_invaders.rb +1 -2
- data/examples/plugins/stardate_footer.rb +2 -2
- data/examples/plugins/telegram/plugin.rb +1 -1
- data/exe/kward +2 -2
- data/exe/kwsh +7 -0
- data/kward.gemspec +3 -1
- data/lib/kward/agent.rb +66 -19
- data/lib/kward/cli/commands.rb +41 -11
- data/lib/kward/cli/compaction.rb +9 -3
- data/lib/kward/cli/interactive_turn.rb +10 -0
- data/lib/kward/cli/plugins.rb +85 -12
- data/lib/kward/cli/prompt_interface.rb +29 -6
- data/lib/kward/cli/rendering.rb +24 -28
- data/lib/kward/cli/runtime_helpers.rb +168 -56
- data/lib/kward/cli/sessions.rb +9 -5
- data/lib/kward/cli/settings/menus.rb +745 -0
- data/lib/kward/cli/settings/model.rb +316 -0
- data/lib/kward/cli/settings.rb +6 -1055
- data/lib/kward/cli/slash_commands.rb +45 -4
- data/lib/kward/cli/tabs.rb +257 -44
- data/lib/kward/cli/tool_summaries.rb +2 -0
- data/lib/kward/{cli_transcript_formatter.rb → cli/transcript_formatter.rb} +6 -13
- data/lib/kward/cli/worktrees.rb +66 -2
- data/lib/kward/cli.rb +82 -31
- data/lib/kward/compactor.rb +18 -7
- data/lib/kward/config/core.rb +400 -0
- data/lib/kward/config/extensions.rb +99 -0
- data/lib/kward/config/paths.rb +11 -0
- data/lib/kward/config/prompts.rb +313 -0
- data/lib/kward/config/settings.rb +257 -0
- data/lib/kward/config_files.rb +14 -1008
- data/lib/kward/conversation.rb +41 -2
- data/lib/kward/entrypoint.rb +14 -0
- data/lib/kward/events.rb +2 -0
- data/lib/kward/generated_images.rb +237 -0
- data/lib/kward/image_attachments.rb +1 -1
- data/lib/kward/model/catalog.rb +6 -3
- data/lib/kward/model/client.rb +107 -38
- data/lib/kward/model/codex_images.rb +83 -0
- data/lib/kward/model/copilot_models.rb +10 -6
- data/lib/kward/model/model_info.rb +42 -7
- data/lib/kward/{openrouter_model_cache.rb → model/openrouter_model_cache.rb} +7 -5
- data/lib/kward/model/payloads.rb +18 -8
- data/lib/kward/model/sources.rb +3 -1
- data/lib/kward/model/stream_parser.rb +4 -7
- data/lib/kward/model/typesafe_client.rb +78 -0
- data/lib/kward/pan/index.html.erb +8 -1
- data/lib/kward/pan/server.rb +23 -8
- data/lib/kward/permissions/policy.rb +6 -2
- data/lib/kward/plugin_registry.rb +2 -659
- data/lib/kward/plugins/actions.rb +453 -0
- data/lib/kward/plugins/chat_contract.rb +121 -0
- data/lib/kward/{plugin_chat_runtime.rb → plugins/chat_runtime.rb} +62 -18
- data/lib/kward/plugins/codex_responses.rb +73 -0
- data/lib/kward/plugins/host.rb +248 -0
- data/lib/kward/plugins/http_server.rb +83 -0
- data/lib/kward/plugins/registry.rb +1229 -0
- data/lib/kward/plugins/resources.rb +206 -0
- data/lib/kward/plugins/turn_request.rb +36 -0
- data/lib/kward/plugins/ui.rb +219 -0
- data/lib/kward/prompt_interface/composer_controller.rb +0 -1
- data/lib/kward/prompt_interface/composer_renderer.rb +160 -73
- data/lib/kward/prompt_interface/composer_state.rb +1 -1
- data/lib/kward/prompt_interface/editor/controller.rb +2 -2
- data/lib/kward/prompt_interface/editor/renderer.rb +10 -7
- data/lib/kward/prompt_interface/editor/runner.rb +1 -1
- data/lib/kward/prompt_interface/editor/state.rb +1 -1
- data/lib/kward/prompt_interface/file_overlay.rb +3 -3
- data/lib/kward/prompt_interface/generated_image_preview.rb +162 -0
- data/lib/kward/prompt_interface/git_prompt.rb +18 -11
- data/lib/kward/prompt_interface/interactive/renderer.rb +1 -1
- data/lib/kward/prompt_interface/interactive/state.rb +18 -20
- data/lib/kward/prompt_interface/key_handler.rb +108 -25
- data/lib/kward/prompt_interface/layout.rb +11 -1
- data/lib/kward/prompt_interface/overlay_renderer.rb +26 -9
- data/lib/kward/prompt_interface/plugin_ui_requests.rb +82 -0
- data/lib/kward/prompt_interface/project_browser.rb +27 -54
- data/lib/kward/prompt_interface/prompt_renderer.rb +27 -35
- data/lib/kward/prompt_interface/question_prompt.rb +19 -28
- data/lib/kward/prompt_interface/runtime_state.rb +37 -10
- data/lib/kward/prompt_interface/screen.rb +30 -20
- data/lib/kward/prompt_interface/selection_prompt.rb +8 -8
- data/lib/kward/prompt_interface/slash_overlay.rb +1 -1
- data/lib/kward/prompt_interface/transcript_renderer.rb +7 -6
- data/lib/kward/prompt_interface.rb +149 -30
- data/lib/kward/prompts/commands.rb +2 -1
- data/lib/kward/prompts.rb +7 -1
- data/lib/kward/{adaptive_pty_output_sink.rb → pty/adaptive_output_sink.rb} +39 -5
- data/lib/kward/{interactive_pty_runner.rb → pty/interactive_runner.rb} +22 -30
- data/lib/kward/{local_command_runner.rb → pty/local_command_runner.rb} +1 -1
- data/lib/kward/{local_pty_command_runner.rb → pty/local_pty_runner.rb} +3 -9
- data/lib/kward/{pty_output_sink.rb → pty/output_sink.rb} +9 -4
- data/lib/kward/pty/transcript_normalizer.rb +137 -0
- data/lib/kward/rpc/config_manager.rb +3 -0
- data/lib/kward/rpc/plugin_chat_manager.rb +30 -10
- data/lib/kward/rpc/prompt_bridge.rb +25 -0
- data/lib/kward/rpc/server.rb +118 -17
- data/lib/kward/rpc/session_manager.rb +208 -60
- data/lib/kward/rpc/session_tree_rows.rb +2 -2
- data/lib/kward/rpc/tool_metadata.rb +1 -1
- data/lib/kward/rpc/transcript_normalizer.rb +11 -7
- data/lib/kward/sandbox/command_runner.rb +1 -1
- data/lib/kward/{session_catalog.rb → sessions/catalog.rb} +1 -1
- data/lib/kward/{session_store.rb → sessions/store.rb} +39 -12
- data/lib/kward/{session_tree_nodes.rb → sessions/tree_nodes.rb} +3 -3
- data/lib/kward/{session_tree_renderer.rb → sessions/tree_renderer.rb} +4 -4
- data/lib/kward/{session_tree_tool_display.rb → sessions/tree_tool_display.rb} +1 -1
- data/lib/kward/{kwsh.rb → shell/kwsh.rb} +30 -10
- data/lib/kward/{kwshrc.rb → shell/kwshrc.rb} +11 -2
- data/lib/kward/shell/native_arithmetic.rb +255 -0
- data/lib/kward/shell/native_arrays.rb +102 -0
- data/lib/kward/shell/native_braces.rb +96 -0
- data/lib/kward/shell/native_builtins.rb +476 -0
- data/lib/kward/shell/native_completion.rb +169 -0
- data/lib/kward/shell/native_condition.rb +75 -0
- data/lib/kward/shell/native_directory.rb +116 -0
- data/lib/kward/shell/native_exec_state.rb +73 -0
- data/lib/kward/shell/native_expansion.rb +252 -0
- data/lib/kward/shell/native_fields.rb +62 -0
- data/lib/kward/shell/native_glob.rb +96 -0
- data/lib/kward/shell/native_history.rb +242 -0
- data/lib/kward/shell/native_interactive.rb +164 -0
- data/lib/kward/shell/native_invocation.rb +42 -0
- data/lib/kward/shell/native_jobs.rb +250 -0
- data/lib/kward/shell/native_line_editor.rb +382 -0
- data/lib/kward/shell/native_line_terminal.rb +286 -0
- data/lib/kward/shell/native_locale.rb +109 -0
- data/lib/kward/shell/native_locals.rb +57 -0
- data/lib/kward/shell/native_pattern.rb +200 -0
- data/lib/kward/shell/native_process.rb +279 -0
- data/lib/kward/shell/native_program.rb +40 -0
- data/lib/kward/shell/native_programmable_completion.rb +115 -0
- data/lib/kward/shell/native_prompt_format.rb +89 -0
- data/lib/kward/shell/native_runtime.rb +964 -0
- data/lib/kward/shell/native_substitution.rb +110 -0
- data/lib/kward/shell/native_syntax.rb +946 -0
- data/lib/kward/shell/native_traps.rb +196 -0
- data/lib/kward/shell/native_vi.rb +407 -0
- data/lib/kward/shell/native_vi_terminal.rb +19 -0
- data/lib/kward/shell/native_worker.rb +82 -0
- data/lib/kward/{persistent_shell_session.rb → shell/persistent_session.rb} +187 -193
- data/lib/kward/shell/prompt.rb +66 -0
- data/lib/kward/shell/prompt_agent.rb +17 -0
- data/lib/kward/{shell_prompt_session.rb → shell/prompt_session.rb} +1 -1
- data/lib/kward/shell/script_runner.rb +244 -0
- data/lib/kward/shell/standalone_agent.rb +31 -0
- data/lib/kward/shell/standalone_link.rb +78 -0
- data/lib/kward/shell/standalone_terminal.rb +287 -0
- data/lib/kward/skills/trust_store.rb +1 -1
- data/lib/kward/tabs/driver.rb +194 -0
- data/lib/kward/{tab_store.rb → tabs/store.rb} +2 -2
- data/lib/kward/{clipboard.rb → terminal/clipboard.rb} +1 -1
- data/lib/kward/{terminal_image_support.rb → terminal/image_support.rb} +1 -1
- data/lib/kward/{terminal_keys.rb → terminal/keys.rb} +22 -1
- data/lib/kward/terminal/locale_text.rb +29 -0
- data/lib/kward/{terminal_sequences.rb → terminal/sequences.rb} +45 -4
- data/lib/kward/tools/base.rb +18 -0
- data/lib/kward/tools/context_for_task.rb +15 -6
- data/lib/kward/tools/datetime.rb +85 -0
- data/lib/kward/tools/edit_file.rb +9 -6
- data/lib/kward/tools/generate_image.rb +36 -0
- data/lib/kward/tools/git_commit.rb +13 -7
- data/lib/kward/tools/list_directory.rb +4 -4
- data/lib/kward/tools/plugin_tool.rb +41 -0
- data/lib/kward/tools/prepare_shell_command.rb +1 -1
- data/lib/kward/tools/read_file.rb +7 -6
- data/lib/kward/tools/registry.rb +130 -21
- data/lib/kward/tools/run_shell_command.rb +10 -8
- data/lib/kward/tools/search/code.rb +1 -1
- data/lib/kward/tools/summarize_file_structure.rb +5 -5
- data/lib/kward/tools/tool_call.rb +4 -1
- data/lib/kward/tools/typesafe_evaluate.rb +81 -0
- data/lib/kward/tools/workspace_targets.rb +58 -0
- data/lib/kward/tools/write_file.rb +9 -6
- data/lib/kward/{export_path.rb → transcripts/export_path.rb} +1 -1
- data/lib/kward/{markdown_transcript.rb → transcripts/markdown_transcript.rb} +10 -2
- data/lib/kward/transcripts/turn_summary_formatter.rb +93 -0
- data/lib/kward/transport/contracts.rb +200 -0
- data/lib/kward/transport/gateway.rb +81 -36
- data/lib/kward/transport/plugin_chat_gateway.rb +3 -2
- data/lib/kward/transport.rb +1 -200
- data/lib/kward/turn_summary.rb +68 -0
- data/lib/kward/version.rb +1 -1
- data/lib/kward/{workspace_factory.rb → workspace/factory.rb} +2 -2
- data/lib/kward/{git_worktree_manager.rb → workspace/git_worktree_manager.rb} +28 -0
- data/lib/kward/{workspace.rb → workspace/workspace.rb} +3 -3
- data/lib/main.rb +6 -3
- data/templates/default/fulldoc/html/css/kward.css +125 -0
- data/templates/default/fulldoc/html/images/kward_screen_1.png +0 -0
- data/templates/default/fulldoc/html/setup.rb +1 -1
- data/templates/default/layout/html/layout.erb +16 -4
- metadata +150 -48
- data/lib/kward/pty_transcript_normalizer.rb +0 -93
- data/lib/kward/shell_prompt.rb +0 -52
- data/lib/kward/tab_driver.rb +0 -90
- data/templates/default/fulldoc/html/images/kward_workflow.svg +0 -52
- /data/lib/kward/{editor_prompt.rb → cli/editor_prompt.rb} +0 -0
- /data/lib/kward/{editor_prompt_session.rb → cli/editor_prompt_session.rb} +0 -0
- /data/lib/kward/{diff_view_mode.rb → prompt_interface/editor/diff_view_mode.rb} +0 -0
- /data/lib/kward/{editor_mode.rb → prompt_interface/editor/editor_mode.rb} +0 -0
- /data/lib/kward/{markdown_code_block.rb → prompt_interface/editor/markdown_code_block.rb} +0 -0
- /data/lib/kward/{scratchpad_languages.rb → prompt_interface/editor/scratchpad_languages.rb} +0 -0
- /data/lib/kward/{scratchpad_runner.rb → prompt_interface/editor/scratchpad_runner.rb} +0 -0
- /data/lib/kward/{detached_run.rb → pty/detached_run.rb} +0 -0
- /data/lib/kward/{session_diff.rb → sessions/diff.rb} +0 -0
- /data/lib/kward/{session_naming.rb → sessions/naming.rb} +0 -0
- /data/lib/kward/{session_trash.rb → sessions/trash.rb} +0 -0
- /data/lib/kward/{ansi.rb → terminal/ansi.rb} +0 -0
- /data/lib/kward/{terminal_text.rb → terminal/text.rb} +0 -0
- /data/lib/kward/{transcript_export.rb → transcripts/transcript_export.rb} +0 -0
- /data/lib/kward/{project_files.rb → workspace/files.rb} +0 -0
- /data/lib/kward/{path_guard.rb → workspace/path_guard.rb} +0 -0
data/lib/kward/cli/plugins.rb
CHANGED
|
@@ -10,10 +10,14 @@ module Kward
|
|
|
10
10
|
@prompt_templates ||= ConfigFiles.prompt_templates(reserved_commands: builtin_slash_command_names)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def
|
|
13
|
+
def discover_plugin_registry
|
|
14
14
|
@plugin_registry ||= PluginRegistry.load(reserved_commands: reserved_slash_command_names)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
def plugin_registry
|
|
18
|
+
discover_plugin_registry.tap(&:start!)
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
def plugin_commands
|
|
18
22
|
plugin_registry.commands
|
|
19
23
|
end
|
|
@@ -30,15 +34,22 @@ module Kward
|
|
|
30
34
|
plugin_registry.interactive_command_for(command)
|
|
31
35
|
end
|
|
32
36
|
|
|
33
|
-
def reload_plugins(conversation)
|
|
37
|
+
def reload_plugins(conversation, tool_registry: nil)
|
|
34
38
|
@prompt_templates = nil
|
|
35
|
-
|
|
39
|
+
registry = PluginRegistry.load(reserved_commands: reserved_slash_command_names)
|
|
40
|
+
@plugin_registry&.reload!
|
|
41
|
+
@plugin_registry = registry.tap(&:start!)
|
|
36
42
|
@prompt.update_slash_commands(slash_command_entries) if @prompt.respond_to?(:update_slash_commands)
|
|
37
43
|
conversation.plugin_registry = @plugin_registry if conversation.respond_to?(:plugin_registry=)
|
|
38
44
|
conversation.refresh_system_message! if conversation.respond_to?(:refresh_system_message!)
|
|
45
|
+
tool_registry&.replace_plugin_tools!(@plugin_registry.tools)
|
|
39
46
|
runtime_output("Plugins reloaded.")
|
|
40
47
|
end
|
|
41
48
|
|
|
49
|
+
def shutdown_plugins
|
|
50
|
+
@plugin_registry&.shutdown!
|
|
51
|
+
end
|
|
52
|
+
|
|
42
53
|
def lifecycle_hook_manager(conversation)
|
|
43
54
|
manager = Hooks::ConfigLoader.new(ConfigFiles.lifecycle_hooks_config(conversation.workspace_root)).manager
|
|
44
55
|
plugin_registry.hook_handlers.each do |hook|
|
|
@@ -50,7 +61,7 @@ module Kward
|
|
|
50
61
|
end
|
|
51
62
|
|
|
52
63
|
def lifecycle_hook_context(conversation)
|
|
53
|
-
plugin_context(conversation, "")
|
|
64
|
+
plugin_context(conversation, "", requests: false, tool_requests: true)
|
|
54
65
|
end
|
|
55
66
|
|
|
56
67
|
def run_lifecycle_hook(name, conversation:, payload: {}, session: @active_session)
|
|
@@ -81,7 +92,7 @@ module Kward
|
|
|
81
92
|
return [false, nil] unless command
|
|
82
93
|
return [false, nil] unless prompt_interface? && @prompt.respond_to?(:start_interactive)
|
|
83
94
|
|
|
84
|
-
context = plugin_context(agent.conversation, argument)
|
|
95
|
+
context = plugin_context(agent.conversation, argument, requests: false)
|
|
85
96
|
controller = @prompt.start_interactive(title: "/#{name}", rows: command.rows, fps: command.fps)
|
|
86
97
|
command.handler.call(controller, context)
|
|
87
98
|
run_interactive_loop
|
|
@@ -150,26 +161,88 @@ module Kward
|
|
|
150
161
|
PromptCommands.expand(input, templates: prompt_templates, reserved_commands: builtin_slash_command_names)
|
|
151
162
|
end
|
|
152
163
|
|
|
153
|
-
def
|
|
164
|
+
def run_plugin_command_and_turn(name, argument, agent)
|
|
165
|
+
origin_tab = active_tab
|
|
166
|
+
_handled, request = run_busy_local_command_and_requeue(activity: "running") do |cancellation|
|
|
167
|
+
run_plugin_command(name, argument, agent, cancellation: cancellation)
|
|
168
|
+
end
|
|
169
|
+
return [true, nil] unless request
|
|
170
|
+
return [true, nil] if origin_tab && (!@tabs.include?(origin_tab) || !origin_tab.agent.equal?(agent))
|
|
171
|
+
|
|
172
|
+
flush_pending_reasoning_config(conversation: agent.conversation)
|
|
173
|
+
if origin_tab
|
|
174
|
+
session = origin_tab.session
|
|
175
|
+
session.rename(default_session_name(request.to_s)) if session && session.name.to_s.empty?
|
|
176
|
+
submit_tab_input(origin_tab, request, display_input: request.to_s)
|
|
177
|
+
else
|
|
178
|
+
auto_name_active_session(request.to_s)
|
|
179
|
+
pending = run_interactive_turn(agent, request, display_input: request.to_s)
|
|
180
|
+
pending.reverse_each { |input| @pending_inputs.unshift(input) }
|
|
181
|
+
end
|
|
182
|
+
[true, nil]
|
|
183
|
+
rescue Cancellation::CancelledError
|
|
184
|
+
[true, nil]
|
|
185
|
+
rescue StandardError => e
|
|
186
|
+
runtime_output("Error: #{e.message}")
|
|
187
|
+
[true, nil]
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def run_plugin_command(name, argument, agent, cancellation: nil)
|
|
154
191
|
command = plugin_command_for(name)
|
|
155
192
|
return [false, nil] unless command
|
|
156
193
|
|
|
194
|
+
cancellation&.raise_if_cancelled!
|
|
157
195
|
agent.conversation.plugin_registry ||= plugin_registry if agent.conversation.respond_to?(:plugin_registry)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
196
|
+
arguments = command.parse_arguments(argument)
|
|
197
|
+
context = plugin_context(agent.conversation, arguments, cancellation: cancellation, turn_command: command)
|
|
198
|
+
result = command.normalize_result(command.handler.call(arguments, context))
|
|
199
|
+
cancellation&.raise_if_cancelled!
|
|
200
|
+
runtime_output(result.message) if command.typed? && !result.message.to_s.empty?
|
|
201
|
+
[true, context.requested_turn]
|
|
202
|
+
rescue Cancellation::CancelledError
|
|
203
|
+
raise
|
|
161
204
|
rescue StandardError => e
|
|
162
205
|
runtime_output("Plugin command /#{name} error: #{e.message}")
|
|
163
206
|
[true, nil]
|
|
164
207
|
end
|
|
165
208
|
|
|
166
|
-
def plugin_context(conversation, args)
|
|
209
|
+
def plugin_context(conversation, args, requests: true, tool_requests: nil, cancellation: nil, turn_command: nil)
|
|
210
|
+
say_callback = lambda { |message| runtime_output(message) }
|
|
211
|
+
tool_requests = requests if tool_requests.nil?
|
|
167
212
|
PluginRegistry::Context.new(
|
|
168
213
|
conversation: conversation,
|
|
169
214
|
args: args,
|
|
170
215
|
session: @active_session,
|
|
171
216
|
workspace_root: conversation.workspace_root,
|
|
172
|
-
say_callback:
|
|
217
|
+
say_callback: say_callback,
|
|
218
|
+
cancellation: cancellation,
|
|
219
|
+
ui: plugin_ui(say_callback, requests: requests),
|
|
220
|
+
tool_ui: plugin_ui(say_callback, requests: tool_requests),
|
|
221
|
+
turn_command: turn_command
|
|
222
|
+
)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def plugin_ui(say_callback, requests:)
|
|
226
|
+
capabilities = { progress: true, notify: true }
|
|
227
|
+
requester = nil
|
|
228
|
+
if requests && @prompt.respond_to?(:request_plugin_ui)
|
|
229
|
+
capabilities.merge!(question: true, select: true, confirm: true, input: true)
|
|
230
|
+
requester = lambda do |kind, payload, cancellation: nil|
|
|
231
|
+
@prompt.request_plugin_ui(kind, payload, cancellation: cancellation)
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
emitter = lambda do |kind, payload|
|
|
235
|
+
case kind
|
|
236
|
+
when :notify
|
|
237
|
+
runtime_output(payload[:message])
|
|
238
|
+
when :progress
|
|
239
|
+
text = payload[:percent] ? "#{payload[:message]} (#{payload[:percent]}%)" : payload[:message]
|
|
240
|
+
runtime_output(text)
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
PluginUI.new(
|
|
244
|
+
backend: PluginUI::Backend.new(capabilities: capabilities, requester: requester, emitter: emitter),
|
|
245
|
+
say_callback: say_callback
|
|
173
246
|
)
|
|
174
247
|
end
|
|
175
248
|
|
|
@@ -201,7 +274,7 @@ module Kward
|
|
|
201
274
|
return unless conversation
|
|
202
275
|
return if plugin_registry.transcript_event_handlers.empty?
|
|
203
276
|
|
|
204
|
-
plugin_registry.notify_transcript_event(event, plugin_context(conversation, ""))
|
|
277
|
+
plugin_registry.notify_transcript_event(event, plugin_context(conversation, "", requests: false))
|
|
205
278
|
end
|
|
206
279
|
|
|
207
280
|
def notify_plugin_tab_transcript_event(event, driver)
|
|
@@ -247,14 +247,16 @@ module Kward
|
|
|
247
247
|
end
|
|
248
248
|
|
|
249
249
|
def prompt_footer_renderer
|
|
250
|
-
return nil unless plugin_registry.
|
|
250
|
+
return nil unless plugin_registry.status?
|
|
251
251
|
|
|
252
|
-
lambda do
|
|
253
|
-
|
|
254
|
-
next "" unless renderer
|
|
252
|
+
lambda do |max_width = nil|
|
|
253
|
+
next "" unless plugin_registry.status?
|
|
255
254
|
|
|
256
255
|
context = plugin_context(current_footer_conversation, "")
|
|
257
|
-
|
|
256
|
+
segments = plugin_registry.status_segments(context)
|
|
257
|
+
plugin_registry.compose_status(segments, max_width: max_width) do |text|
|
|
258
|
+
TerminalText.width(ANSI.strip(text.to_s))
|
|
259
|
+
end
|
|
258
260
|
rescue StandardError => e
|
|
259
261
|
emit_warning "Warning: Kward plugin footer error: #{e.message}"
|
|
260
262
|
""
|
|
@@ -271,6 +273,8 @@ module Kward
|
|
|
271
273
|
parts = []
|
|
272
274
|
git = composer_git_branch_text
|
|
273
275
|
parts << git if git
|
|
276
|
+
merge = composer_worktree_merge_text
|
|
277
|
+
parts << merge if merge
|
|
274
278
|
diff = composer_session_diff_text
|
|
275
279
|
parts << diff if diff
|
|
276
280
|
usage = composer_context_usage(provider, model)
|
|
@@ -279,6 +283,22 @@ module Kward
|
|
|
279
283
|
parts.join(" · ")
|
|
280
284
|
end
|
|
281
285
|
|
|
286
|
+
def composer_worktree_merge_text
|
|
287
|
+
return nil unless respond_to?(:active_tab, true) && respond_to?(:worktree_binding_for, true)
|
|
288
|
+
|
|
289
|
+
binding = worktree_binding_for(active_tab)
|
|
290
|
+
return nil unless binding&.active?
|
|
291
|
+
return nil unless git_worktree_manager.merge_in_progress?(binding.origin_root)
|
|
292
|
+
|
|
293
|
+
conflicts = git_worktree_manager.merge_conflict_marker_paths(binding.origin_root, cached: false)
|
|
294
|
+
target = git_worktree_manager.current_branch(binding.origin_root)
|
|
295
|
+
count = conflicts.length
|
|
296
|
+
detail = count.zero? ? "ready" : "#{count} conflict#{count == 1 ? "" : "s"}"
|
|
297
|
+
ANSI.colorize("merge→#{target.empty? ? "detached" : target} (#{detail})", :red, enabled: @color_enabled)
|
|
298
|
+
rescue GitWorktreeManager::Error
|
|
299
|
+
nil
|
|
300
|
+
end
|
|
301
|
+
|
|
282
302
|
def composer_session_diff_text
|
|
283
303
|
return nil if @session_diff.nil? || @session_diff.empty?
|
|
284
304
|
|
|
@@ -337,7 +357,10 @@ module Kward
|
|
|
337
357
|
end
|
|
338
358
|
|
|
339
359
|
def footer_tool_schemas
|
|
340
|
-
|
|
360
|
+
return [] unless @footer_tool_registry
|
|
361
|
+
return @footer_tool_registry.schemas unless @footer_tool_registry.respond_to?(:schemas_for)
|
|
362
|
+
|
|
363
|
+
@footer_tool_registry.schemas_for(current_footer_conversation.provider)
|
|
341
364
|
end
|
|
342
365
|
|
|
343
366
|
def current_footer_conversation
|
data/lib/kward/cli/rendering.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative "../transcripts/turn_summary_formatter"
|
|
2
|
+
|
|
1
3
|
# Namespace for the Kward CLI agent runtime.
|
|
2
4
|
module Kward
|
|
3
5
|
# Command-line frontend that coordinates terminal interaction, sessions, tools, and model turns.
|
|
@@ -48,8 +50,7 @@ module Kward
|
|
|
48
50
|
print_user_transcript(
|
|
49
51
|
CLITranscriptFormatter.user_transcript_input(message),
|
|
50
52
|
display_input: CLITranscriptFormatter.user_display_text(message),
|
|
51
|
-
attachment_references: CLITranscriptFormatter.image_references(message)
|
|
52
|
-
image_parts: CLITranscriptFormatter.image_parts(message)
|
|
53
|
+
attachment_references: CLITranscriptFormatter.image_references(message)
|
|
53
54
|
)
|
|
54
55
|
when "assistant"
|
|
55
56
|
render_reasoning(message)
|
|
@@ -64,9 +65,22 @@ module Kward
|
|
|
64
65
|
else
|
|
65
66
|
render_transcript_block(role.to_s.capitalize, CLITranscriptFormatter.content_text(message_content(message)))
|
|
66
67
|
end
|
|
68
|
+
print_turn_summary(MessageAccess.value(message, :turn_summary))
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
|
|
72
|
+
def turn_summary_text(summary)
|
|
73
|
+
return "" unless summary.is_a?(Hash)
|
|
74
|
+
|
|
75
|
+
width = [TTY::Screen.width - 1, 1].max if $stdout.tty?
|
|
76
|
+
TurnSummaryFormatter.render(summary, mode: ConfigFiles.transcript_turn_stats, width: width)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def print_turn_summary(summary)
|
|
80
|
+
text = turn_summary_text(summary)
|
|
81
|
+
write_prompt_transcript("\n#{colored(text, :metadata)}\n") unless text.empty?
|
|
82
|
+
end
|
|
83
|
+
|
|
70
84
|
def render_reasoning(message)
|
|
71
85
|
CLITranscriptFormatter.reasoning_blocks(message).each do |reasoning|
|
|
72
86
|
render_transcript_block("Reasoning", reasoning)
|
|
@@ -221,11 +235,15 @@ module Kward
|
|
|
221
235
|
end
|
|
222
236
|
|
|
223
237
|
# Writes the user transcript output for the terminal CLI flow.
|
|
224
|
-
def print_user_transcript(input, display_input: nil, attachment_references: nil
|
|
238
|
+
def print_user_transcript(input, display_input: nil, attachment_references: nil)
|
|
225
239
|
visible_input = display_input.nil? ? input : display_input
|
|
226
|
-
write_prompt_transcript("\n#{colored("
|
|
240
|
+
write_prompt_transcript("\n#{colored("You>", :blue, :bold)} #{visible_input}\n")
|
|
241
|
+
# System-turn instructions are plain text, never image attachments.
|
|
242
|
+
return if input.is_a?(PluginTurnRequest)
|
|
243
|
+
|
|
244
|
+
# Terminal graphics are not tracked by the text-only scroll/redraw buffer.
|
|
245
|
+
# Keep transcript attachments as badges; /files owns image previews.
|
|
227
246
|
print_attachment_badges(input, references: attachment_references)
|
|
228
|
-
print_pasted_images(input, image_parts: image_parts)
|
|
229
247
|
end
|
|
230
248
|
|
|
231
249
|
# Writes the attachment badges output for the terminal CLI flow.
|
|
@@ -286,27 +304,6 @@ module Kward
|
|
|
286
304
|
"#{formatted} #{unit}"
|
|
287
305
|
end
|
|
288
306
|
|
|
289
|
-
# Writes the pasted images output for the terminal CLI flow.
|
|
290
|
-
def print_pasted_images(input, image_parts: nil)
|
|
291
|
-
parts = image_parts || Kward::ImageAttachments.image_parts_from_text(input)
|
|
292
|
-
protocol = @prompt.inline_image_protocol if @prompt.respond_to?(:inline_image_protocol)
|
|
293
|
-
parts.each do |part|
|
|
294
|
-
next if @prompt.respond_to?(:inline_image_protocol) && protocol.nil?
|
|
295
|
-
|
|
296
|
-
part = Kward::ImageAttachments.terminal_image_part(part, protocol) if protocol
|
|
297
|
-
next if protocol && part.nil?
|
|
298
|
-
|
|
299
|
-
sequence = Kward::ImageAttachments.terminal_image_sequence(part, protocol: protocol)
|
|
300
|
-
next unless sequence
|
|
301
|
-
|
|
302
|
-
if @prompt.respond_to?(:say_visual)
|
|
303
|
-
@prompt.say_visual(sequence)
|
|
304
|
-
else
|
|
305
|
-
@prompt.say(sequence)
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
|
|
310
307
|
# Writes the block delta output for the terminal CLI flow.
|
|
311
308
|
def print_block_delta(label, delta)
|
|
312
309
|
if prompt_interface?
|
|
@@ -410,8 +407,7 @@ module Kward
|
|
|
410
407
|
end
|
|
411
408
|
|
|
412
409
|
def transcript_marker(label)
|
|
413
|
-
|
|
414
|
-
label == "Assistant" ? "✦ #{marker}" : marker
|
|
410
|
+
"#{transcript_label(label)}>"
|
|
415
411
|
end
|
|
416
412
|
|
|
417
413
|
def label_styles(label)
|