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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "base64"
|
|
1
2
|
require "securerandom"
|
|
2
3
|
require "thread"
|
|
3
4
|
require "time"
|
|
@@ -9,24 +10,24 @@ require_relative "../config_files"
|
|
|
9
10
|
require_relative "../model/context_usage"
|
|
10
11
|
require_relative "../conversation"
|
|
11
12
|
require_relative "../events"
|
|
12
|
-
require_relative "../export_path"
|
|
13
|
+
require_relative "../transcripts/export_path"
|
|
13
14
|
require_relative "../memory/manager"
|
|
14
15
|
require_relative "../memory/turn_context"
|
|
15
16
|
require_relative "../message_access"
|
|
16
17
|
require_relative "../message_text"
|
|
17
|
-
require_relative "../
|
|
18
|
+
require_relative "../sessions/tree_tool_display"
|
|
18
19
|
require_relative "../skills/capture"
|
|
19
20
|
require_relative "../model/model_info"
|
|
20
|
-
require_relative "../
|
|
21
|
+
require_relative "../plugins/registry"
|
|
21
22
|
require_relative "../prompts/commands"
|
|
22
|
-
require_relative "../
|
|
23
|
-
require_relative "../
|
|
24
|
-
require_relative "../
|
|
23
|
+
require_relative "../sessions/store"
|
|
24
|
+
require_relative "../sessions/naming"
|
|
25
|
+
require_relative "../sessions/trash"
|
|
25
26
|
require_relative "../steering"
|
|
26
27
|
require_relative "../tools/tool_call"
|
|
27
28
|
require_relative "../tools/registry"
|
|
28
|
-
require_relative "../transcript_export"
|
|
29
|
-
require_relative "../
|
|
29
|
+
require_relative "../transcripts/transcript_export"
|
|
30
|
+
require_relative "../workspace/factory"
|
|
30
31
|
require_relative "attachment_normalizer"
|
|
31
32
|
require_relative "config_manager"
|
|
32
33
|
require_relative "memory_methods"
|
|
@@ -66,8 +67,8 @@ module Kward
|
|
|
66
67
|
WORKER_STOP_TIMEOUT = 2.0
|
|
67
68
|
WORKER_STOP = Object.new.freeze
|
|
68
69
|
|
|
69
|
-
RpcSession = Struct.new(:id, :workspace_root, :store, :session, :conversation, :agent, :tool_registry, :execution_profile, :prompt, :plugin_output, :queue, :worker, :running_turn_id, :footer_worker, :last_footer_text, keyword_init: true)
|
|
70
|
-
Turn = Struct.new(:id, :session_id, :input, :display_input, :status, :cancel_requested, :cancellation, :created_at, :started_at, :finished_at, :events, :next_sequence, :error, :streaming_behavior, :plugin_command_name, :plugin_arguments, :steering, :options, :tool_registry, :execution_profile, :mutex, keyword_init: true)
|
|
70
|
+
RpcSession = Struct.new(:id, :workspace_root, :store, :session, :conversation, :agent, :tool_registry, :execution_profile, :prompt, :plugin_output, :queue, :worker, :running_turn_id, :footer_worker, :last_footer_text, :last_footer_segments, keyword_init: true)
|
|
71
|
+
Turn = Struct.new(:id, :session_id, :input, :display_input, :status, :cancel_requested, :cancellation, :created_at, :started_at, :finished_at, :events, :next_sequence, :error, :streaming_behavior, :plugin_command_name, :plugin_arguments, :steering, :options, :tool_registry, :execution_profile, :summary, :mutex, keyword_init: true)
|
|
71
72
|
|
|
72
73
|
# Creates an object for RPC session lifecycle and turn coordination.
|
|
73
74
|
def initialize(
|
|
@@ -82,6 +83,7 @@ module Kward
|
|
|
82
83
|
)
|
|
83
84
|
@server = server
|
|
84
85
|
@client = client
|
|
86
|
+
@generated_images = GeneratedImages.new
|
|
85
87
|
@config_dir = config_dir
|
|
86
88
|
@config_manager = config_manager
|
|
87
89
|
@context_usage = context_usage
|
|
@@ -194,12 +196,34 @@ module Kward
|
|
|
194
196
|
end
|
|
195
197
|
|
|
196
198
|
def tool_schemas(session_id: nil)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
session = fetch_session(session_id) if session_id
|
|
200
|
+
registry = session ? session.tool_registry : build_tool_registry(Dir.pwd, nil)
|
|
201
|
+
provider = session&.conversation&.provider || (@client.current_provider if @client.respond_to?(:current_provider))
|
|
202
|
+
{ tools: registry.schemas_for(provider) }
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def fetch_generated_image(session_id:, image_id:, offset: 0)
|
|
206
|
+
owner = fetch_session(session_id).conversation
|
|
207
|
+
image, bytes = @generated_images.fetch(owner, image_id, offset: offset)
|
|
208
|
+
next_offset = offset + bytes.bytesize
|
|
209
|
+
{ id: image.id, filename: image.filename, mimeType: "image/png", size: image.size,
|
|
210
|
+
offset: offset, data: Base64.strict_encode64(bytes), nextOffset: (next_offset if next_offset < image.size) }
|
|
211
|
+
rescue GeneratedImages::Error => e
|
|
212
|
+
raise ArgumentError, e.message
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def save_generated_image(session_id:, image_id:, directory: ".")
|
|
216
|
+
owner = fetch_session(session_id).conversation
|
|
217
|
+
{ path: @generated_images.save_to_project(owner, image_id, directory) }
|
|
218
|
+
rescue GeneratedImages::Error => e
|
|
219
|
+
raise ArgumentError, e.message
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def discard_generated_image(session_id:, image_id:)
|
|
223
|
+
owner = fetch_session(session_id).conversation
|
|
224
|
+
{ discarded: @generated_images.discard(owner, image_id) }
|
|
225
|
+
rescue GeneratedImages::Error => e
|
|
226
|
+
raise ArgumentError, e.message
|
|
203
227
|
end
|
|
204
228
|
|
|
205
229
|
# Subscribes to frontend-neutral runtime notifications.
|
|
@@ -215,7 +239,7 @@ module Kward
|
|
|
215
239
|
|
|
216
240
|
# Returns the plugin registry shared by RPC sessions and plugin chats.
|
|
217
241
|
def plugin_registry
|
|
218
|
-
@plugin_registry ||= PluginRegistry.load(reserved_commands: reserved_plugin_command_names)
|
|
242
|
+
@plugin_registry ||= PluginRegistry.load(reserved_commands: reserved_plugin_command_names).tap(&:start!)
|
|
219
243
|
end
|
|
220
244
|
|
|
221
245
|
# Renames the persisted session attached to an RPC session id.
|
|
@@ -390,6 +414,13 @@ module Kward
|
|
|
390
414
|
rpc_sessions = @mutex.synchronize { @sessions.values.dup }
|
|
391
415
|
rpc_sessions.reverse_each { |rpc_session| close_rpc_session(rpc_session) }
|
|
392
416
|
{ closed: true }
|
|
417
|
+
ensure
|
|
418
|
+
@generated_images.close
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
def shutdown_plugins
|
|
422
|
+
@plugin_registry&.shutdown!
|
|
423
|
+
{ closed: true }
|
|
393
424
|
end
|
|
394
425
|
|
|
395
426
|
# Returns the normalized transcript for the active RPC session.
|
|
@@ -404,7 +435,7 @@ module Kward
|
|
|
404
435
|
# queue a follow-up, or steer the running turn when the active provider
|
|
405
436
|
# supports native steering. The returned turn id is used for status,
|
|
406
437
|
# cancellation, and event replay.
|
|
407
|
-
def start_turn(session_id:, input:, streaming_behavior: nil, attachments: [], options: {}, context: nil, execution_profile: nil)
|
|
438
|
+
def start_turn(session_id:, input:, streaming_behavior: nil, attachments: [], options: {}, context: nil, execution_profile: nil, image_previews: true)
|
|
408
439
|
rpc_session = fetch_session(session_id)
|
|
409
440
|
execution_profile = validate_execution_profile(execution_profile)
|
|
410
441
|
normalized_options = enforce_execution_profile_options(normalize_turn_options(options), execution_profile)
|
|
@@ -439,7 +470,7 @@ module Kward
|
|
|
439
470
|
plugin_command_name: plugin_command&.name,
|
|
440
471
|
plugin_arguments: plugin_arguments,
|
|
441
472
|
options: normalized_options,
|
|
442
|
-
tool_registry: scoped_tool_registry(rpc_session, normalized_options),
|
|
473
|
+
tool_registry: scoped_tool_registry(rpc_session, normalized_options, image_previews: image_previews),
|
|
443
474
|
execution_profile: execution_profile,
|
|
444
475
|
mutex: Mutex.new
|
|
445
476
|
)
|
|
@@ -490,6 +521,12 @@ module Kward
|
|
|
490
521
|
{ ok: true }
|
|
491
522
|
end
|
|
492
523
|
|
|
524
|
+
def answer_plugin_ui(session_id:, request_id:, value:)
|
|
525
|
+
rpc_session = fetch_session(session_id)
|
|
526
|
+
rpc_session.prompt.answer_plugin_ui(request_id, value)
|
|
527
|
+
{ ok: true }
|
|
528
|
+
end
|
|
529
|
+
|
|
493
530
|
def answer_tool_approval(session_id:, approval_request_id:, approved:)
|
|
494
531
|
rpc_session = fetch_session(session_id)
|
|
495
532
|
rpc_session.prompt.answer_tool_approval(approval_request_id, approved: approved)
|
|
@@ -525,18 +562,39 @@ module Kward
|
|
|
525
562
|
|
|
526
563
|
def run_plugin_command(session_id:, command:, arguments: "")
|
|
527
564
|
rpc_session = fetch_session(session_id)
|
|
565
|
+
raise ArgumentError, "Plugin commands are disabled for this session" if rpc_session.execution_profile && !rpc_session.execution_profile.plugin_commands
|
|
566
|
+
|
|
528
567
|
command = plugin_registry.command_for(command.to_s.delete_prefix("/")) || raise(ArgumentError, "Unknown plugin command: #{command}")
|
|
568
|
+
arguments = command.parse_arguments(arguments)
|
|
529
569
|
output = []
|
|
530
|
-
context = plugin_context(rpc_session, args: arguments
|
|
531
|
-
result = command.handler.call(arguments
|
|
570
|
+
context = plugin_context(rpc_session, args: arguments, say_callback: lambda { |message| output << message.to_s })
|
|
571
|
+
result = command.normalize_result(command.handler.call(arguments, context))
|
|
532
572
|
output = rpc_session.plugin_output.shift(rpc_session.plugin_output.length) + output
|
|
533
|
-
|
|
573
|
+
serialized_result = command.typed? ? result.to_h : (result.nil? ? nil : result.to_s)
|
|
574
|
+
{ command: command.name, output: output, result: serialized_result }
|
|
534
575
|
end
|
|
535
576
|
|
|
536
577
|
def plugin_commands
|
|
537
578
|
plugin_registry.commands
|
|
538
579
|
end
|
|
539
580
|
|
|
581
|
+
def plugin_actions
|
|
582
|
+
plugin_registry.actions
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
def run_plugin_action(session_id:, id:, arguments: {})
|
|
586
|
+
rpc_session = fetch_session(session_id)
|
|
587
|
+
raise ArgumentError, "Plugin actions are disabled for this session" if rpc_session.execution_profile && !rpc_session.execution_profile.plugin_commands
|
|
588
|
+
|
|
589
|
+
action = plugin_registry.action_for(id) || raise(ArgumentError, "Unknown plugin action: #{id}")
|
|
590
|
+
arguments = action.parse_arguments(arguments)
|
|
591
|
+
output = []
|
|
592
|
+
context = plugin_context(rpc_session, args: arguments, say_callback: lambda { |message| output << message.to_s })
|
|
593
|
+
result = action.normalize_result(action.handler.call(arguments, context))
|
|
594
|
+
output = rpc_session.plugin_output.shift(rpc_session.plugin_output.length) + output
|
|
595
|
+
{ action: action.id, output: output, result: result.to_h }
|
|
596
|
+
end
|
|
597
|
+
|
|
540
598
|
def available_models
|
|
541
599
|
models = @client.respond_to?(:available_models) ? Array(@client.available_models) : []
|
|
542
600
|
normalized = models.map { |model| normalize_model(model) }
|
|
@@ -545,9 +603,14 @@ module Kward
|
|
|
545
603
|
normalized
|
|
546
604
|
end
|
|
547
605
|
|
|
548
|
-
def refresh_models(provider: nil)
|
|
549
|
-
|
|
550
|
-
|
|
606
|
+
def refresh_models(provider: nil, with_metadata: false)
|
|
607
|
+
if @client.respond_to?(:refresh_model_catalog)
|
|
608
|
+
refresh = @client.refresh_model_catalog(provider: provider)
|
|
609
|
+
elsif @client.respond_to?(:refresh_available_models)
|
|
610
|
+
@client.refresh_available_models(provider: provider)
|
|
611
|
+
end
|
|
612
|
+
models = available_models
|
|
613
|
+
with_metadata ? { models: models, refresh: refresh }.compact : models
|
|
551
614
|
end
|
|
552
615
|
|
|
553
616
|
def current_model
|
|
@@ -628,6 +691,8 @@ module Kward
|
|
|
628
691
|
|
|
629
692
|
def reload_plugins
|
|
630
693
|
registry = PluginRegistry.load(reserved_commands: reserved_plugin_command_names)
|
|
694
|
+
@plugin_registry&.reload!
|
|
695
|
+
registry.start!
|
|
631
696
|
sessions = @mutex.synchronize do
|
|
632
697
|
@plugin_registry = registry
|
|
633
698
|
@sessions.values
|
|
@@ -636,7 +701,7 @@ module Kward
|
|
|
636
701
|
rpc_session.conversation.plugin_registry = registry if rpc_session.conversation.respond_to?(:plugin_registry=)
|
|
637
702
|
rpc_session.conversation.refresh_system_message! if rpc_session.conversation.respond_to?(:refresh_system_message!)
|
|
638
703
|
rebuild_session_tools(rpc_session)
|
|
639
|
-
if registry.
|
|
704
|
+
if registry.status?
|
|
640
705
|
start_footer_worker(rpc_session)
|
|
641
706
|
emit_footer_update(rpc_session)
|
|
642
707
|
else
|
|
@@ -714,7 +779,9 @@ module Kward
|
|
|
714
779
|
hook_context = lifecycle_hook_context(
|
|
715
780
|
conversation: rpc_session.conversation,
|
|
716
781
|
session: rpc_session.session,
|
|
717
|
-
workspace_root: rpc_session.workspace_root
|
|
782
|
+
workspace_root: rpc_session.workspace_root,
|
|
783
|
+
prompt: rpc_session.prompt,
|
|
784
|
+
session_id: rpc_session.id
|
|
718
785
|
)
|
|
719
786
|
hook_manager = lifecycle_hook_manager(rpc_session.workspace_root)
|
|
720
787
|
tool_registry = build_tool_registry(
|
|
@@ -829,6 +896,7 @@ module Kward
|
|
|
829
896
|
conversation.plugin_registry ||= plugin_registry if conversation.respond_to?(:plugin_registry)
|
|
830
897
|
conversation.update_execution_profile_context!(rpc_session.execution_profile.prompt_context) if rpc_session.execution_profile
|
|
831
898
|
rpc_session.session = session
|
|
899
|
+
@generated_images.discard_owner(rpc_session.conversation)
|
|
832
900
|
rpc_session.conversation = conversation
|
|
833
901
|
rebuild_session_tools(rpc_session)
|
|
834
902
|
emit_footer_update(rpc_session)
|
|
@@ -989,16 +1057,17 @@ module Kward
|
|
|
989
1057
|
value.to_s.empty? ? nil : value
|
|
990
1058
|
end
|
|
991
1059
|
|
|
992
|
-
def scoped_tool_registry(rpc_session, options)
|
|
1060
|
+
def scoped_tool_registry(rpc_session, options, image_previews: true)
|
|
993
1061
|
names = scoped_tool_names(rpc_session, options)
|
|
994
1062
|
approval = tool_approval_callback(rpc_session, options)
|
|
995
|
-
return nil
|
|
1063
|
+
return nil if !names && !approval && image_previews
|
|
996
1064
|
|
|
997
1065
|
build_tool_registry(
|
|
998
1066
|
rpc_session.workspace_root,
|
|
999
1067
|
rpc_session.prompt,
|
|
1000
1068
|
allowed_tool_names: names,
|
|
1001
1069
|
tool_approval: approval,
|
|
1070
|
+
image_previews: image_previews,
|
|
1002
1071
|
hook_manager: lifecycle_hook_manager(rpc_session.workspace_root),
|
|
1003
1072
|
hook_context: plugin_context(rpc_session, say_callback: lambda { |message| rpc_session.plugin_output << message.to_s })
|
|
1004
1073
|
)
|
|
@@ -1042,7 +1111,13 @@ module Kward
|
|
|
1042
1111
|
conversation.plugin_registry ||= plugin_registry if conversation.respond_to?(:plugin_registry)
|
|
1043
1112
|
id = SecureRandom.uuid
|
|
1044
1113
|
prompt = PromptBridge.new(notify: method(:notify), session_id: id)
|
|
1045
|
-
hook_context = lifecycle_hook_context(
|
|
1114
|
+
hook_context = lifecycle_hook_context(
|
|
1115
|
+
conversation: conversation,
|
|
1116
|
+
session: session,
|
|
1117
|
+
workspace_root: workspace_root,
|
|
1118
|
+
prompt: prompt,
|
|
1119
|
+
session_id: id
|
|
1120
|
+
)
|
|
1046
1121
|
hook_manager = lifecycle_hook_manager(workspace_root)
|
|
1047
1122
|
tool_registry = build_tool_registry(workspace_root, prompt, hook_manager: hook_manager, hook_context: hook_context)
|
|
1048
1123
|
agent = Agent.new(
|
|
@@ -1069,13 +1144,16 @@ module Kward
|
|
|
1069
1144
|
)
|
|
1070
1145
|
end
|
|
1071
1146
|
|
|
1072
|
-
def build_tool_registry(workspace_root, prompt, allowed_tool_names: nil, tool_approval: nil, hook_manager: nil, hook_context: nil)
|
|
1147
|
+
def build_tool_registry(workspace_root, prompt, allowed_tool_names: nil, tool_approval: nil, hook_manager: nil, hook_context: nil, image_previews: true)
|
|
1073
1148
|
ToolRegistry.new(
|
|
1074
1149
|
workspace: configured_workspace(workspace_root),
|
|
1075
1150
|
prompt: prompt,
|
|
1076
1151
|
allowed_tool_names: allowed_tool_names,
|
|
1152
|
+
plugin_tools: plugin_registry.tools,
|
|
1077
1153
|
tool_approval: tool_approval,
|
|
1078
1154
|
approval_for_allowed_tools: !tool_approval.nil?,
|
|
1155
|
+
image_client: @client,
|
|
1156
|
+
generated_images: (image_previews ? @generated_images : nil),
|
|
1079
1157
|
hook_manager: hook_manager,
|
|
1080
1158
|
hook_context: hook_context
|
|
1081
1159
|
)
|
|
@@ -1115,13 +1193,16 @@ module Kward
|
|
|
1115
1193
|
})
|
|
1116
1194
|
end
|
|
1117
1195
|
|
|
1118
|
-
def lifecycle_hook_context(conversation:, session:, workspace_root:)
|
|
1196
|
+
def lifecycle_hook_context(conversation:, session:, workspace_root:, prompt: nil, session_id: nil)
|
|
1197
|
+
say_callback = lambda { |message| notify("hook/message", { message: message.to_s }) }
|
|
1119
1198
|
PluginRegistry::Context.new(
|
|
1120
1199
|
conversation: conversation,
|
|
1121
1200
|
args: "",
|
|
1122
1201
|
session: session,
|
|
1123
1202
|
workspace_root: workspace_root,
|
|
1124
|
-
say_callback:
|
|
1203
|
+
say_callback: say_callback,
|
|
1204
|
+
ui: rpc_plugin_ui(prompt: prompt, session_id: session_id, say_callback: say_callback, requests: false),
|
|
1205
|
+
tool_ui: rpc_plugin_ui(prompt: prompt, session_id: session_id, say_callback: say_callback, requests: !prompt.nil?)
|
|
1125
1206
|
)
|
|
1126
1207
|
end
|
|
1127
1208
|
|
|
@@ -1185,6 +1266,7 @@ module Kward
|
|
|
1185
1266
|
@mutex.synchronize { @sessions.delete(rpc_session.id) }
|
|
1186
1267
|
stop_worker(rpc_session)
|
|
1187
1268
|
stop_footer_worker(rpc_session)
|
|
1269
|
+
@generated_images.discard_owner(rpc_session.conversation)
|
|
1188
1270
|
end
|
|
1189
1271
|
|
|
1190
1272
|
def stop_worker(rpc_session, wait: false)
|
|
@@ -1212,7 +1294,7 @@ module Kward
|
|
|
1212
1294
|
end
|
|
1213
1295
|
|
|
1214
1296
|
def start_footer_worker(rpc_session)
|
|
1215
|
-
return unless plugin_registry.
|
|
1297
|
+
return unless plugin_registry.status?
|
|
1216
1298
|
return if rpc_session.footer_worker&.alive?
|
|
1217
1299
|
|
|
1218
1300
|
rpc_session.footer_worker = Thread.new do
|
|
@@ -1290,18 +1372,7 @@ module Kward
|
|
|
1290
1372
|
if turn.plugin_command_name
|
|
1291
1373
|
run_plugin_turn(rpc_session, turn)
|
|
1292
1374
|
else
|
|
1293
|
-
|
|
1294
|
-
prepare_memory_context(rpc_session.conversation, turn.input) unless memory_disabled?(turn)
|
|
1295
|
-
rpc_session.agent.ask(turn.input, display_input: turn_display_input(turn), cancellation: turn.cancellation, steering: turn.steering, options: turn.options || {}, tool_registry: turn.tool_registry) do |event|
|
|
1296
|
-
next if turn.cancel_requested
|
|
1297
|
-
|
|
1298
|
-
notify_plugin_transcript_event(rpc_session, event)
|
|
1299
|
-
handle_agent_event(turn, event)
|
|
1300
|
-
end
|
|
1301
|
-
unless memory_disabled?(turn)
|
|
1302
|
-
persist_memory_state(rpc_session)
|
|
1303
|
-
auto_summarize_memory(rpc_session) unless turn.cancel_requested
|
|
1304
|
-
end
|
|
1375
|
+
run_session_model_turn(rpc_session, turn, input: turn.input, display_input: turn_display_input(turn))
|
|
1305
1376
|
finish_turn(turn, turn.cancel_requested ? "canceled" : "completed")
|
|
1306
1377
|
end
|
|
1307
1378
|
rescue Cancellation::CancelledError
|
|
@@ -1316,6 +1387,22 @@ module Kward
|
|
|
1316
1387
|
rpc_session.running_turn_id = nil
|
|
1317
1388
|
end
|
|
1318
1389
|
|
|
1390
|
+
def run_session_model_turn(rpc_session, turn, input:, display_input: nil)
|
|
1391
|
+
auto_name_session(rpc_session, display_input || turn.display_input || input)
|
|
1392
|
+
memory_input = input.is_a?(PluginTurnRequest) ? input.to_s : input
|
|
1393
|
+
prepare_memory_context(rpc_session.conversation, memory_input) unless memory_disabled?(turn)
|
|
1394
|
+
rpc_session.agent.ask(input, display_input: display_input, cancellation: turn.cancellation, steering: turn.steering, options: turn.options || {}, tool_registry: turn.tool_registry) do |event|
|
|
1395
|
+
next if turn.cancel_requested && !event.is_a?(Events::TurnSummary)
|
|
1396
|
+
|
|
1397
|
+
notify_plugin_transcript_event(rpc_session, event)
|
|
1398
|
+
handle_agent_event(turn, event)
|
|
1399
|
+
end
|
|
1400
|
+
unless memory_disabled?(turn)
|
|
1401
|
+
persist_memory_state(rpc_session)
|
|
1402
|
+
auto_summarize_memory(rpc_session) unless turn.cancel_requested
|
|
1403
|
+
end
|
|
1404
|
+
end
|
|
1405
|
+
|
|
1319
1406
|
def build_steering(_turn)
|
|
1320
1407
|
Steering.new
|
|
1321
1408
|
end
|
|
@@ -1371,12 +1458,44 @@ module Kward
|
|
|
1371
1458
|
turn_payload(turn)
|
|
1372
1459
|
end
|
|
1373
1460
|
|
|
1374
|
-
def plugin_context(rpc_session, args: nil, say_callback:)
|
|
1461
|
+
def plugin_context(rpc_session, args: nil, say_callback:, requests: false, cancellation: nil, turn_command: nil)
|
|
1375
1462
|
PluginRegistry::Context.new(
|
|
1376
1463
|
conversation: rpc_session.conversation,
|
|
1377
1464
|
args: args,
|
|
1378
1465
|
session: rpc_session.session,
|
|
1379
1466
|
workspace_root: rpc_session.workspace_root,
|
|
1467
|
+
say_callback: say_callback,
|
|
1468
|
+
cancellation: cancellation,
|
|
1469
|
+
turn_command: turn_command,
|
|
1470
|
+
ui: rpc_plugin_ui(
|
|
1471
|
+
prompt: rpc_session.prompt,
|
|
1472
|
+
session_id: rpc_session.id,
|
|
1473
|
+
say_callback: say_callback,
|
|
1474
|
+
requests: requests
|
|
1475
|
+
)
|
|
1476
|
+
)
|
|
1477
|
+
end
|
|
1478
|
+
|
|
1479
|
+
def rpc_plugin_ui(prompt:, session_id:, say_callback:, requests:)
|
|
1480
|
+
capabilities = { progress: true, notify: true }
|
|
1481
|
+
requester = nil
|
|
1482
|
+
if requests && prompt
|
|
1483
|
+
capabilities.merge!(question: true, select: true, confirm: true, input: true)
|
|
1484
|
+
requester = lambda do |kind, payload, cancellation: nil|
|
|
1485
|
+
if kind == :question
|
|
1486
|
+
prompt.ask_user_question(payload.fetch(:questions), cancellation: cancellation)
|
|
1487
|
+
else
|
|
1488
|
+
prompt.request_plugin_ui(kind, payload, cancellation: cancellation)
|
|
1489
|
+
end
|
|
1490
|
+
end
|
|
1491
|
+
end
|
|
1492
|
+
emitter = lambda do |kind, payload|
|
|
1493
|
+
method = kind == :progress ? "ui/progress" : "ui/notification"
|
|
1494
|
+
payload = payload.merge(level: payload[:level].to_s) if payload[:level]
|
|
1495
|
+
notify(method, { sessionId: session_id }.merge(payload))
|
|
1496
|
+
end
|
|
1497
|
+
PluginUI.new(
|
|
1498
|
+
backend: PluginUI::Backend.new(capabilities: capabilities, requester: requester, emitter: emitter),
|
|
1380
1499
|
say_callback: say_callback
|
|
1381
1500
|
)
|
|
1382
1501
|
end
|
|
@@ -1384,13 +1503,30 @@ module Kward
|
|
|
1384
1503
|
def run_plugin_turn(rpc_session, turn)
|
|
1385
1504
|
turn.cancellation&.raise_if_cancelled!
|
|
1386
1505
|
command = plugin_registry.command_for(turn.plugin_command_name) || raise(ArgumentError, "Unknown plugin command: #{turn.plugin_command_name}")
|
|
1506
|
+
arguments = command.parse_arguments(turn.plugin_arguments)
|
|
1387
1507
|
output = []
|
|
1388
|
-
context = plugin_context(
|
|
1389
|
-
|
|
1508
|
+
context = plugin_context(
|
|
1509
|
+
rpc_session,
|
|
1510
|
+
args: arguments,
|
|
1511
|
+
say_callback: lambda { |message| output << message.to_s },
|
|
1512
|
+
requests: true,
|
|
1513
|
+
cancellation: turn.cancellation,
|
|
1514
|
+
turn_command: command
|
|
1515
|
+
)
|
|
1516
|
+
result = command.normalize_result(command.handler.call(arguments, context))
|
|
1517
|
+
turn.cancellation&.raise_if_cancelled!
|
|
1518
|
+
if command.typed?
|
|
1519
|
+
emit_turn_event(turn, "pluginCommandResult", { command: command.name, result: result.to_h })
|
|
1520
|
+
result = result.message
|
|
1521
|
+
end
|
|
1390
1522
|
answer = (output + [result]).compact.map(&:to_s).reject(&:empty?).join("\n")
|
|
1391
1523
|
unless answer.empty?
|
|
1392
1524
|
emit_turn_event(turn, "assistantDelta", { delta: answer })
|
|
1393
|
-
emit_turn_event(turn, "answer", { content: answer })
|
|
1525
|
+
emit_turn_event(turn, "answer", { content: answer }) unless context.requested_turn
|
|
1526
|
+
end
|
|
1527
|
+
if context.requested_turn
|
|
1528
|
+
turn.steering = build_steering(turn) if supports_in_flight_steer?
|
|
1529
|
+
run_session_model_turn(rpc_session, turn, input: context.requested_turn, display_input: context.requested_turn.to_s)
|
|
1394
1530
|
end
|
|
1395
1531
|
finish_turn(turn, turn.cancel_requested ? "canceled" : "completed")
|
|
1396
1532
|
end
|
|
@@ -1404,6 +1540,9 @@ module Kward
|
|
|
1404
1540
|
|
|
1405
1541
|
def handle_agent_event(turn, event)
|
|
1406
1542
|
case event
|
|
1543
|
+
when Events::TurnSummary
|
|
1544
|
+
turn.mutex.synchronize { turn.summary = event.summary }
|
|
1545
|
+
emit_turn_event(turn, "turnSummary", { summary: event.summary })
|
|
1407
1546
|
when Events::ReasoningDelta
|
|
1408
1547
|
emit_turn_event(turn, "reasoningDelta", { delta: event.delta })
|
|
1409
1548
|
when Events::ReasoningBoundary
|
|
@@ -1422,6 +1561,9 @@ module Kward
|
|
|
1422
1561
|
emit_turn_event(turn, "toolCall", normalized_tool_event_payload(event.tool_call))
|
|
1423
1562
|
when Events::ToolUpdate
|
|
1424
1563
|
emit_turn_event(turn, "toolUpdate", normalized_tool_update_event_payload(event.tool_call, event.content, elapsed_ms: event.elapsed_ms))
|
|
1564
|
+
when Events::ImageReady
|
|
1565
|
+
image = event.image
|
|
1566
|
+
emit_turn_event(turn, "imageReady", { id: image.id, toolCallId: ToolCall.id(event.tool_call), filename: image.filename, mimeType: "image/png", size: image.size })
|
|
1425
1567
|
when Events::ToolResult
|
|
1426
1568
|
emit_turn_event(turn, "toolResult", normalized_tool_result_event_payload(event.tool_call, event.content))
|
|
1427
1569
|
when Events::Answer
|
|
@@ -1447,7 +1589,9 @@ module Kward
|
|
|
1447
1589
|
|
|
1448
1590
|
turn.status = status
|
|
1449
1591
|
turn.finished_at = now
|
|
1450
|
-
|
|
1592
|
+
payload = { status: status, error: turn.error }
|
|
1593
|
+
payload[:summary] = turn.summary if turn.summary
|
|
1594
|
+
append_turn_event_locked(turn, "turnFinished", payload)
|
|
1451
1595
|
end
|
|
1452
1596
|
return unless event
|
|
1453
1597
|
|
|
@@ -1457,27 +1601,30 @@ module Kward
|
|
|
1457
1601
|
end
|
|
1458
1602
|
|
|
1459
1603
|
def emit_footer_update(rpc_session)
|
|
1460
|
-
|
|
1461
|
-
return clear_footer_update(rpc_session) unless renderer
|
|
1604
|
+
return clear_footer_update(rpc_session) unless plugin_registry.status?
|
|
1462
1605
|
|
|
1463
|
-
|
|
1606
|
+
segments = begin
|
|
1464
1607
|
context = plugin_context(rpc_session, say_callback: lambda { |message| rpc_session.plugin_output << message.to_s })
|
|
1465
|
-
|
|
1608
|
+
plugin_registry.status_segments(context)
|
|
1466
1609
|
rescue StandardError => e
|
|
1467
1610
|
warn "Warning: Kward plugin footer error: #{e.message}"
|
|
1468
|
-
|
|
1611
|
+
[]
|
|
1469
1612
|
end
|
|
1470
|
-
|
|
1613
|
+
segment_payloads = segments.map(&:to_h)
|
|
1614
|
+
text = plugin_registry.compose_status(segments)
|
|
1615
|
+
return if rpc_session.last_footer_text == text && rpc_session.last_footer_segments == segment_payloads
|
|
1471
1616
|
|
|
1472
1617
|
rpc_session.last_footer_text = text
|
|
1473
|
-
|
|
1618
|
+
rpc_session.last_footer_segments = segment_payloads
|
|
1619
|
+
notify("ui/footer", { sessionId: rpc_session.id, text: text, segments: segment_payloads })
|
|
1474
1620
|
end
|
|
1475
1621
|
|
|
1476
1622
|
def clear_footer_update(rpc_session)
|
|
1477
|
-
return if rpc_session.last_footer_text.to_s.empty?
|
|
1623
|
+
return if rpc_session.last_footer_text.to_s.empty? && Array(rpc_session.last_footer_segments).empty?
|
|
1478
1624
|
|
|
1479
1625
|
rpc_session.last_footer_text = ""
|
|
1480
|
-
|
|
1626
|
+
rpc_session.last_footer_segments = []
|
|
1627
|
+
notify("ui/footer", { sessionId: rpc_session.id, text: "", segments: [] })
|
|
1481
1628
|
end
|
|
1482
1629
|
|
|
1483
1630
|
def emit_turn_event(turn, type, payload)
|
|
@@ -1523,6 +1670,7 @@ module Kward
|
|
|
1523
1670
|
createdAt: turn.created_at,
|
|
1524
1671
|
startedAt: turn.started_at,
|
|
1525
1672
|
finishedAt: turn.finished_at,
|
|
1673
|
+
summary: turn.summary,
|
|
1526
1674
|
error: turn.error
|
|
1527
1675
|
}.compact
|
|
1528
1676
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require_relative "../message_access"
|
|
2
2
|
require_relative "../message_text"
|
|
3
|
-
require_relative "../
|
|
4
|
-
require_relative "../
|
|
3
|
+
require_relative "../sessions/tree_nodes"
|
|
4
|
+
require_relative "../sessions/tree_tool_display"
|
|
5
5
|
|
|
6
6
|
# Namespace for the Kward CLI agent runtime.
|
|
7
7
|
module Kward
|
|
@@ -17,7 +17,12 @@ module Kward
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def normalize
|
|
20
|
-
@messages.filter_map
|
|
20
|
+
@messages.filter_map do |message|
|
|
21
|
+
normalized = normalize_message(message)
|
|
22
|
+
summary = MessageAccess.value(message, :turn_summary)
|
|
23
|
+
normalized = normalized.merge(turnSummary: summary) if normalized && summary.is_a?(Hash)
|
|
24
|
+
normalized
|
|
25
|
+
end
|
|
21
26
|
end
|
|
22
27
|
|
|
23
28
|
private
|
|
@@ -65,7 +70,10 @@ module Kward
|
|
|
65
70
|
|
|
66
71
|
def normalize_assistant_message(message)
|
|
67
72
|
content = reasoning_first_content(normalize_content(MessageAccess.content(message), preserve_thinking: true))
|
|
68
|
-
|
|
73
|
+
response_content = response_item_content(message)
|
|
74
|
+
if text_content_empty?(content) || response_content.any? { |part| part[:type] == "text" }
|
|
75
|
+
content = response_content
|
|
76
|
+
end
|
|
69
77
|
reasoning = normalize_reasoning_summary(message)
|
|
70
78
|
content.unshift(reasoning) if reasoning && !thinking_content?(content)
|
|
71
79
|
tool_calls(message).each do |tool_call|
|
|
@@ -176,11 +184,7 @@ module Kward
|
|
|
176
184
|
text = response_message_item_text(item)
|
|
177
185
|
next [] if text.empty?
|
|
178
186
|
|
|
179
|
-
|
|
180
|
-
[{ type: "thinking", thinking: text }]
|
|
181
|
-
else
|
|
182
|
-
[{ type: "text", text: text }]
|
|
183
|
-
end
|
|
187
|
+
[{ type: "text", text: text }]
|
|
184
188
|
else
|
|
185
189
|
[]
|
|
186
190
|
end
|