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/tabs.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "json"
|
|
2
|
+
require "securerandom"
|
|
2
3
|
require "thread"
|
|
3
4
|
require_relative "../cancellation"
|
|
4
5
|
|
|
@@ -10,14 +11,16 @@ module Kward
|
|
|
10
11
|
module Tabs
|
|
11
12
|
WORKTREE_AGENT_CONTEXT = <<~PROMPT.strip.freeze
|
|
12
13
|
This is an active Git worktree tab. The workspace is sandboxed separately from the host repository metadata.
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
Workspace tools default to the active worktree. When they advertise `target`, use `target: "origin"` to inspect the verified host repository worktree without leaving this tab. Read the origin's applicable `AGENTS.md` before changing it.
|
|
15
|
+
When the user explicitly asks you to commit, use the advertised `git_commit` tool. Set `target: "origin"` only when the user asks to commit there. Do not use `run_shell_command` for `git add` or `git commit`, because shared Git metadata is intentionally protected.
|
|
16
|
+
`git_commit` requires a commit message and accepts optional target-relative paths; omit paths to include all current changes in the selected worktree. Do not create a commit unless the user requested one.
|
|
15
17
|
PROMPT
|
|
16
18
|
|
|
17
19
|
TabRuntime = Struct.new(
|
|
18
20
|
:session,
|
|
19
21
|
:agent,
|
|
20
22
|
:driver,
|
|
23
|
+
:plugin_host,
|
|
21
24
|
:diff,
|
|
22
25
|
:snapshot,
|
|
23
26
|
:status,
|
|
@@ -41,10 +44,19 @@ module Kward
|
|
|
41
44
|
:transient_shell_entries,
|
|
42
45
|
:error_reported,
|
|
43
46
|
:local_busy_activity,
|
|
47
|
+
:pending_runtime_outputs,
|
|
48
|
+
:image_offers,
|
|
44
49
|
keyword_init: true
|
|
45
50
|
) do
|
|
46
51
|
TRANSIENT_SHELL_OUTPUT_LIMIT = 200_000
|
|
47
52
|
|
|
53
|
+
attr_reader :pending_images
|
|
54
|
+
|
|
55
|
+
def initialize(**attributes)
|
|
56
|
+
super
|
|
57
|
+
@pending_images = Queue.new
|
|
58
|
+
end
|
|
59
|
+
|
|
48
60
|
def running?
|
|
49
61
|
%w[queued running waiting_for_question].include?(status.to_s)
|
|
50
62
|
end
|
|
@@ -53,12 +65,18 @@ module Kward
|
|
|
53
65
|
!local_busy_activity.to_s.empty?
|
|
54
66
|
end
|
|
55
67
|
|
|
68
|
+
def append_pending_runtime_output(text)
|
|
69
|
+
self.pending_runtime_outputs ||= []
|
|
70
|
+
pending_runtime_outputs << text.to_s
|
|
71
|
+
end
|
|
72
|
+
|
|
56
73
|
def idle?
|
|
57
74
|
!running? && !local_busy?
|
|
58
75
|
end
|
|
59
76
|
|
|
60
77
|
def record_event(event)
|
|
61
78
|
event_history << event
|
|
79
|
+
pending_images << event.image if event.is_a?(Events::ImageReady)
|
|
62
80
|
end
|
|
63
81
|
|
|
64
82
|
def append_transient_shell_entry(text)
|
|
@@ -205,14 +223,23 @@ module Kward
|
|
|
205
223
|
end
|
|
206
224
|
|
|
207
225
|
tab_type = plugin_registry.tab_type_for_id(descriptor["plugin_tab_type"])
|
|
226
|
+
host = nil
|
|
208
227
|
driver = if tab_type&.local
|
|
209
|
-
|
|
210
|
-
tab_type.
|
|
228
|
+
descriptor["scope_key"] ||= plugin_tab_scope_key(tab_type)
|
|
229
|
+
host = build_plugin_tab_host(tab_type, workspace_root: session_store.cwd, scope_key: descriptor["scope_key"])
|
|
230
|
+
begin
|
|
231
|
+
created_driver = tab_type.handler.call(host, descriptor)
|
|
232
|
+
raise "Plugin tab #{descriptor["plugin_tab_type"].inspect} did not return a tab driver." unless created_driver
|
|
233
|
+
|
|
234
|
+
tab_type.capabilities.validate_driver!(created_driver)
|
|
235
|
+
rescue StandardError
|
|
236
|
+
host.shutdown
|
|
237
|
+
raise
|
|
238
|
+
end
|
|
211
239
|
else
|
|
212
240
|
UnavailableTabDriver.new(descriptor: descriptor, message: "Plugin tab #{descriptor["plugin_tab_type"].inspect} is unavailable.")
|
|
213
241
|
end
|
|
214
|
-
|
|
215
|
-
build_tab(nil, nil, driver: driver, label: label || descriptor["label"] || tab_type&.title)
|
|
242
|
+
build_tab(nil, nil, driver: driver, plugin_host: host, label: label || descriptor["label"] || tab_type&.title)
|
|
216
243
|
end
|
|
217
244
|
|
|
218
245
|
def open_plugin_tab(name, session_store)
|
|
@@ -223,14 +250,23 @@ module Kward
|
|
|
223
250
|
return switch_tab(@tabs.index(existing))
|
|
224
251
|
end
|
|
225
252
|
|
|
226
|
-
save_active_tab_state
|
|
227
253
|
stop_tab_live_view
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
254
|
+
save_active_tab_state
|
|
255
|
+
suspend_tab_images(active_tab)
|
|
256
|
+
scope_key = plugin_tab_scope_key(tab_type)
|
|
257
|
+
descriptor = { "kind" => "plugin", "plugin_tab_type" => tab_type.id, "label" => tab_type.title, "scope_key" => scope_key }
|
|
258
|
+
host = build_plugin_tab_host(tab_type, workspace_root: session_store.cwd, scope_key: scope_key)
|
|
259
|
+
begin
|
|
260
|
+
driver = tab_type.handler.call(host, descriptor)
|
|
261
|
+
raise "Plugin tab #{name.inspect} did not return a tab driver." unless driver
|
|
262
|
+
|
|
263
|
+
tab_type.capabilities.validate_driver!(driver)
|
|
264
|
+
rescue StandardError
|
|
265
|
+
host.shutdown
|
|
266
|
+
raise
|
|
267
|
+
end
|
|
232
268
|
|
|
233
|
-
@tabs << build_tab(nil, nil, driver: driver, label: tab_type.title)
|
|
269
|
+
@tabs << build_tab(nil, nil, driver: driver, plugin_host: host, label: tab_type.title)
|
|
234
270
|
@active_tab_index = @tabs.length - 1
|
|
235
271
|
activate_tab(@active_tab_index)
|
|
236
272
|
rescue StandardError => e
|
|
@@ -254,22 +290,33 @@ module Kward
|
|
|
254
290
|
strict = worktree&.active? == true
|
|
255
291
|
update_worktree_agent_context(conversation, strict)
|
|
256
292
|
workspace = configured_workspace(root: conversation.workspace_root, strict: strict)
|
|
293
|
+
workspace_targets = if strict
|
|
294
|
+
origin_workspace = configured_workspace(root: worktree.origin_root, strict: true)
|
|
295
|
+
Tools::WorkspaceTargets.new(active: workspace, targets: { origin: origin_workspace })
|
|
296
|
+
end
|
|
257
297
|
prompt = TabQuestionPrompt.new(self)
|
|
258
298
|
hook_manager = strict ? nil : lifecycle_hook_manager(conversation)
|
|
259
299
|
hook_context = strict ? nil : lifecycle_hook_context(conversation)
|
|
260
300
|
git_committer = if strict
|
|
261
|
-
|
|
301
|
+
lambda do |message:, paths:, target: Tools::WorkspaceTargets::ACTIVE|
|
|
302
|
+
commit_workspace = target == "origin" ? worktree.origin_root : workspace.root.to_s
|
|
303
|
+
git_commit_for_agent(commit_workspace, message: message, paths: paths)
|
|
304
|
+
end
|
|
262
305
|
end
|
|
263
306
|
project_skill_paths = project_skill_paths_for(conversation.workspace_root) || []
|
|
264
307
|
tool_registry = ToolRegistry.new(
|
|
265
308
|
workspace: workspace,
|
|
309
|
+
workspace_targets: workspace_targets,
|
|
266
310
|
prompt: prompt,
|
|
267
311
|
skills: ConfigFiles.skills(workspace_root: conversation.workspace_root, project_skill_paths: project_skill_paths),
|
|
268
312
|
tool_approval: tab_tool_approval_callback(prompt),
|
|
269
313
|
hook_manager: hook_manager,
|
|
270
314
|
hook_context: hook_context,
|
|
271
315
|
mcp_clients: strict ? [] : nil,
|
|
272
|
-
|
|
316
|
+
plugin_tools: strict ? [] : plugin_registry.tools,
|
|
317
|
+
git_committer: git_committer,
|
|
318
|
+
image_client: @client,
|
|
319
|
+
generated_images: (@generated_images ||= GeneratedImages.new)
|
|
273
320
|
)
|
|
274
321
|
@footer_conversation = conversation
|
|
275
322
|
@footer_tool_registry = tool_registry
|
|
@@ -301,12 +348,13 @@ module Kward
|
|
|
301
348
|
end
|
|
302
349
|
end
|
|
303
350
|
|
|
304
|
-
def build_tab(session, agent, driver: nil, label: nil)
|
|
351
|
+
def build_tab(session, agent, driver: nil, plugin_host: nil, label: nil)
|
|
305
352
|
driver ||= SessionTabDriver.new(session: session, agent: agent)
|
|
306
353
|
TabRuntime.new(
|
|
307
354
|
session: session,
|
|
308
355
|
agent: agent,
|
|
309
356
|
driver: driver,
|
|
357
|
+
plugin_host: plugin_host,
|
|
310
358
|
diff: session&.path ? SessionDiff.from_session_file(session.path) : SessionDiff.new,
|
|
311
359
|
snapshot: nil,
|
|
312
360
|
status: "idle",
|
|
@@ -329,7 +377,8 @@ module Kward
|
|
|
329
377
|
background_run: nil,
|
|
330
378
|
transient_shell_entries: [],
|
|
331
379
|
error_reported: false,
|
|
332
|
-
local_busy_activity: nil
|
|
380
|
+
local_busy_activity: nil,
|
|
381
|
+
pending_runtime_outputs: []
|
|
333
382
|
).tap { |tab| assign_tab_question_prompt(agent, tab) }
|
|
334
383
|
end
|
|
335
384
|
|
|
@@ -395,6 +444,8 @@ module Kward
|
|
|
395
444
|
case action[:tab_action]
|
|
396
445
|
when :new
|
|
397
446
|
open_new_tab(session_store)
|
|
447
|
+
when :new_after_current
|
|
448
|
+
open_new_tab(session_store, after_current: true)
|
|
398
449
|
when :close
|
|
399
450
|
close_active_tab
|
|
400
451
|
when :next
|
|
@@ -406,18 +457,21 @@ module Kward
|
|
|
406
457
|
end
|
|
407
458
|
end
|
|
408
459
|
|
|
409
|
-
def open_new_tab(session_store)
|
|
460
|
+
def open_new_tab(session_store, after_current: false)
|
|
410
461
|
return say_sessions_unavailable unless session_store
|
|
411
462
|
|
|
412
|
-
save_active_tab_state
|
|
413
463
|
stop_tab_live_view
|
|
464
|
+
save_active_tab_state
|
|
465
|
+
suspend_tab_images(active_tab)
|
|
414
466
|
session = track_session(session_store.create(provider: current_model_provider, model: current_model_id, reasoning_effort: current_reasoning_effort))
|
|
415
467
|
conversation = new_conversation(workspace_root: session_store.cwd)
|
|
416
468
|
session.attach(conversation)
|
|
417
469
|
agent = build_tab_agent(conversation, session)
|
|
418
|
-
|
|
419
|
-
@active_tab_index
|
|
420
|
-
|
|
470
|
+
tab = build_tab(session, agent, driver: SessionTabDriver.new(session: session, agent: agent), label: default_tab_label(@tabs.length))
|
|
471
|
+
index = after_current ? @active_tab_index + 1 : @tabs.length
|
|
472
|
+
@tabs.insert(index, tab)
|
|
473
|
+
@active_tab_index = index
|
|
474
|
+
activate_tab(index)
|
|
421
475
|
end
|
|
422
476
|
|
|
423
477
|
def close_active_tab
|
|
@@ -427,17 +481,19 @@ module Kward
|
|
|
427
481
|
return nil
|
|
428
482
|
end
|
|
429
483
|
|
|
484
|
+
stop_tab_live_view
|
|
485
|
+
discard_tab_images(tab)
|
|
430
486
|
if @tabs.length <= 1
|
|
431
487
|
close_kwsh_session(tab.shell) if tab&.shell && respond_to?(:close_kwsh_session, true)
|
|
488
|
+
close_plugin_tab(tab)
|
|
432
489
|
@tabs.clear
|
|
433
490
|
persist_tabs
|
|
434
491
|
return PromptInterface::EXIT_INPUT
|
|
435
492
|
end
|
|
436
493
|
|
|
437
|
-
stop_tab_live_view
|
|
438
494
|
close_kwsh_session(tab.shell) if tab&.shell && respond_to?(:close_kwsh_session, true)
|
|
439
495
|
tab.session&.delete_if_unused if tab&.session.respond_to?(:delete_if_unused)
|
|
440
|
-
tab
|
|
496
|
+
close_plugin_tab(tab)
|
|
441
497
|
@tabs.delete_at(@active_tab_index)
|
|
442
498
|
@active_tab_index = [@active_tab_index, @tabs.length - 1].min
|
|
443
499
|
activate_tab(@active_tab_index)
|
|
@@ -448,8 +504,9 @@ module Kward
|
|
|
448
504
|
return if index == @active_tab_index
|
|
449
505
|
return unless index.between?(0, @tabs.length - 1)
|
|
450
506
|
|
|
451
|
-
save_active_tab_state
|
|
452
507
|
stop_tab_live_view
|
|
508
|
+
save_active_tab_state
|
|
509
|
+
suspend_tab_images(active_tab)
|
|
453
510
|
@active_tab_index = index
|
|
454
511
|
activate_tab(index)
|
|
455
512
|
end
|
|
@@ -458,6 +515,7 @@ module Kward
|
|
|
458
515
|
tab = active_tab
|
|
459
516
|
return agent unless tab
|
|
460
517
|
|
|
518
|
+
discard_tab_images(tab) unless tab.agent&.conversation.equal?(agent.conversation)
|
|
461
519
|
tab.session = @active_session
|
|
462
520
|
worktree = reconcile_worktree_binding(tab, agent.conversation)
|
|
463
521
|
tab.agent = build_tab_agent(agent.conversation, tab.session, worktree: worktree)
|
|
@@ -534,8 +592,14 @@ module Kward
|
|
|
534
592
|
update_plugin_tab_slash_commands(tab)
|
|
535
593
|
update_prompt_tabs
|
|
536
594
|
render_tab(tab) if render
|
|
595
|
+
offer_tab_images(tab)
|
|
537
596
|
start_tab_live_view(tab) if tab.running?
|
|
538
|
-
|
|
597
|
+
if tab.local_busy? && tab.shell
|
|
598
|
+
@prompt.finish_busy_input if @prompt.respond_to?(:finish_busy_input)
|
|
599
|
+
@prompt.update_prompt_label(tab.shell.prompt_label) if @prompt.respond_to?(:update_prompt_label)
|
|
600
|
+
elsif tab.local_busy? && @prompt.respond_to?(:begin_busy_input)
|
|
601
|
+
@prompt.begin_busy_input("You>", activity: tab.local_busy_activity)
|
|
602
|
+
end
|
|
539
603
|
persist_tabs
|
|
540
604
|
service_active_tab_question
|
|
541
605
|
tab.agent
|
|
@@ -555,8 +619,23 @@ module Kward
|
|
|
555
619
|
end
|
|
556
620
|
report_tab_runtime_error(tab) if %w[failed cancelled].include?(tab.status.to_s)
|
|
557
621
|
render_tab_transient_shell_entries(tab)
|
|
622
|
+
render_background_tab_output(tab)
|
|
558
623
|
end
|
|
559
624
|
restore_tab_composer_snapshot(tab.snapshot) if restore_composer
|
|
625
|
+
render_pending_tab_runtime_outputs(tab)
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
def render_pending_tab_runtime_outputs(tab)
|
|
629
|
+
outputs = Array(tab.pending_runtime_outputs)
|
|
630
|
+
tab.pending_runtime_outputs = []
|
|
631
|
+
outputs.each { |output| runtime_output(output) }
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
def flush_pending_runtime_outputs(tab)
|
|
635
|
+
return false unless tab && tab == active_tab
|
|
636
|
+
|
|
637
|
+
render_pending_tab_runtime_outputs(tab)
|
|
638
|
+
true
|
|
560
639
|
end
|
|
561
640
|
|
|
562
641
|
def render_tab_transient_shell_entries(tab)
|
|
@@ -569,6 +648,17 @@ module Kward
|
|
|
569
648
|
end
|
|
570
649
|
end
|
|
571
650
|
|
|
651
|
+
def render_background_tab_output(tab)
|
|
652
|
+
output = tab.background_run&.fetch(:rendered_output, "").to_s
|
|
653
|
+
return if output.empty?
|
|
654
|
+
|
|
655
|
+
if @prompt.respond_to?(:say)
|
|
656
|
+
@prompt.say(output)
|
|
657
|
+
elsif @prompt.respond_to?(:write_transcript)
|
|
658
|
+
@prompt.write_transcript(output)
|
|
659
|
+
end
|
|
660
|
+
end
|
|
661
|
+
|
|
572
662
|
def clear_active_tab_transient_shell_entries
|
|
573
663
|
active_tab&.clear_transient_shell_entries
|
|
574
664
|
end
|
|
@@ -614,10 +704,15 @@ module Kward
|
|
|
614
704
|
index ? index + 1 : active_tab_number
|
|
615
705
|
end
|
|
616
706
|
|
|
617
|
-
def register_background_tab_run(tab, run, &completion)
|
|
707
|
+
def register_background_tab_run(tab, run, output_kind: nil, &completion)
|
|
618
708
|
return unless tab && run
|
|
619
709
|
|
|
620
|
-
tab.background_run = {
|
|
710
|
+
tab.background_run = {
|
|
711
|
+
run: run,
|
|
712
|
+
completion: completion,
|
|
713
|
+
output_kind: output_kind,
|
|
714
|
+
rendered_output: +""
|
|
715
|
+
}
|
|
621
716
|
tab.local_busy_activity = "running"
|
|
622
717
|
tab.attention = nil
|
|
623
718
|
update_prompt_tabs
|
|
@@ -628,11 +723,19 @@ module Kward
|
|
|
628
723
|
|
|
629
724
|
@tabs.each do |tab|
|
|
630
725
|
state = tab.background_run
|
|
631
|
-
next unless state
|
|
726
|
+
next unless state
|
|
632
727
|
|
|
633
|
-
|
|
728
|
+
complete = state[:run].complete?
|
|
729
|
+
result = state[:run].result if complete
|
|
730
|
+
if state[:output_kind] && respond_to?(:flush_background_tab_output, true)
|
|
731
|
+
flush_background_tab_output(tab, state, result: result, complete: complete)
|
|
732
|
+
end
|
|
733
|
+
next unless complete
|
|
734
|
+
|
|
735
|
+
state[:completion]&.call(state[:run].sink, result, state) if result.is_a?(Struct)
|
|
736
|
+
rendered_output = state[:rendered_output].to_s
|
|
737
|
+
tab.append_transient_shell_entry(rendered_output) unless rendered_output.empty?
|
|
634
738
|
tab.background_run = nil
|
|
635
|
-
state[:completion]&.call(state[:run].sink, result) if result.is_a?(Struct)
|
|
636
739
|
finish_local_busy_command_for_tab(tab)
|
|
637
740
|
if tab != active_tab
|
|
638
741
|
tab.unread = true
|
|
@@ -654,20 +757,39 @@ module Kward
|
|
|
654
757
|
|
|
655
758
|
def submit_tab_input(tab, input, display_input: nil)
|
|
656
759
|
return if input.to_s.strip.empty?
|
|
760
|
+
return unless plugin_tab_attachments_allowed?(tab, input)
|
|
657
761
|
|
|
658
762
|
save_active_tab_state
|
|
659
763
|
start_tab_turn(tab, input, display_input: display_input)
|
|
660
764
|
start_tab_live_view(tab) if tab == active_tab
|
|
661
765
|
end
|
|
662
766
|
|
|
767
|
+
def plugin_tab_attachments_allowed?(tab, input)
|
|
768
|
+
capabilities = tab.plugin_host&.capabilities
|
|
769
|
+
return true unless capabilities&.declared?
|
|
770
|
+
return true if capabilities.allows_attachment?(:image)
|
|
771
|
+
|
|
772
|
+
attached = ImageAttachments.references_from_text(input.to_s).any? { |reference| reference[:status] == :attached }
|
|
773
|
+
return true unless attached
|
|
774
|
+
|
|
775
|
+
runtime_output("This plugin chat does not allow image attachments.")
|
|
776
|
+
false
|
|
777
|
+
end
|
|
778
|
+
|
|
663
779
|
def start_tab_turn(tab, input, display_input: nil)
|
|
664
780
|
prepare_memory_context(tab.agent.conversation, input) if tab.agent.respond_to?(:conversation)
|
|
665
|
-
print_user_transcript(input, display_input: display_input) if prompt_interface?
|
|
781
|
+
print_user_transcript(input, display_input: display_input) if prompt_interface? && tab == active_tab
|
|
666
782
|
tab.status = "queued"
|
|
667
783
|
tab.unread = false
|
|
668
784
|
tab.attention = nil
|
|
669
785
|
tab.cancellation = Cancellation.new
|
|
670
|
-
|
|
786
|
+
steering_capability = tab.plugin_host&.capabilities
|
|
787
|
+
driver_supports_steering = if steering_capability&.declared?
|
|
788
|
+
steering_capability.steering?
|
|
789
|
+
else
|
|
790
|
+
tab.driver.supports_steering?
|
|
791
|
+
end
|
|
792
|
+
tab.steering = driver_supports_steering && steering_supported? ? Steering.new : nil
|
|
671
793
|
tab.error = nil
|
|
672
794
|
tab.answer = nil
|
|
673
795
|
tab.error_reported = false
|
|
@@ -686,6 +808,7 @@ module Kward
|
|
|
686
808
|
update_prompt_tabs
|
|
687
809
|
tab.answer = tab.driver.submit(input, display_input: display_input, cancellation: tab.cancellation, steering: tab.steering) do |event|
|
|
688
810
|
tab.record_event(event)
|
|
811
|
+
update_prompt_tabs if event.is_a?(Events::ImageReady) && !tab.equal?(active_tab)
|
|
689
812
|
end
|
|
690
813
|
tab.status = "ready"
|
|
691
814
|
tab.unread = tab != active_tab
|
|
@@ -718,13 +841,20 @@ module Kward
|
|
|
718
841
|
service_background_tab_runs
|
|
719
842
|
tab = active_tab
|
|
720
843
|
unless tab&.running? || tab&.local_busy?
|
|
844
|
+
offer_tab_images(tab) if tab
|
|
721
845
|
input = @prompt.ask("You>")
|
|
722
846
|
return { tab_action: :close } if input.nil? && tab && @tabs.length > 1
|
|
723
847
|
|
|
724
848
|
return input
|
|
725
849
|
end
|
|
726
850
|
|
|
727
|
-
|
|
851
|
+
if @prompt.respond_to?(:begin_busy_input)
|
|
852
|
+
if tab.shell
|
|
853
|
+
@prompt.begin_busy_input(tab.shell.prompt_label, activity: "running", show_activity: false)
|
|
854
|
+
else
|
|
855
|
+
@prompt.begin_busy_input("You>")
|
|
856
|
+
end
|
|
857
|
+
end
|
|
728
858
|
loop do
|
|
729
859
|
service_background_tab_runs
|
|
730
860
|
refresh_active_tab
|
|
@@ -738,6 +868,7 @@ module Kward
|
|
|
738
868
|
sleep 0.01
|
|
739
869
|
next
|
|
740
870
|
end
|
|
871
|
+
offer_tab_images(tab)
|
|
741
872
|
poll_result = @prompt.poll_input
|
|
742
873
|
case poll_result
|
|
743
874
|
when Hash
|
|
@@ -779,8 +910,12 @@ module Kward
|
|
|
779
910
|
tab.queued_inputs << input
|
|
780
911
|
@prompt.set_queued_count(tab.queued_inputs.length) if @prompt.respond_to?(:set_queued_count)
|
|
781
912
|
return
|
|
782
|
-
elsif busy_tab_command?(input)
|
|
783
|
-
|
|
913
|
+
elsif busy_tab_command?(input) || busy_name_command?(input)
|
|
914
|
+
if busy_tab_command?(input)
|
|
915
|
+
handle_tab_command(input.to_s.strip.sub(%r{\A/tab(?:\s+|\z)}, ""), @session_store)
|
|
916
|
+
else
|
|
917
|
+
handle_local_slash_command(input, tab.agent, @session_store)
|
|
918
|
+
end
|
|
784
919
|
unless active_tab.equal?(tab)
|
|
785
920
|
@prompt.finish_busy_input if @prompt.respond_to?(:finish_busy_input)
|
|
786
921
|
return :active_tab_changed
|
|
@@ -812,6 +947,10 @@ module Kward
|
|
|
812
947
|
input.to_s.strip.match?(%r{\A/tab(?:\s|\z)})
|
|
813
948
|
end
|
|
814
949
|
|
|
950
|
+
def busy_name_command?(input)
|
|
951
|
+
input.to_s.strip.match?(%r{\A/name(?:\s|\z)})
|
|
952
|
+
end
|
|
953
|
+
|
|
815
954
|
def refresh_active_tab
|
|
816
955
|
tab = active_tab
|
|
817
956
|
return unless tab&.thread && !tab.thread.alive? && tab.running?
|
|
@@ -853,6 +992,8 @@ module Kward
|
|
|
853
992
|
break unless @tab_live_view_token.equal?(token)
|
|
854
993
|
|
|
855
994
|
if tab.idle?
|
|
995
|
+
next if tab.seen_events < tab.event_history.length
|
|
996
|
+
|
|
856
997
|
renderer.call(:flush, tab.driver)
|
|
857
998
|
break
|
|
858
999
|
end
|
|
@@ -884,16 +1025,43 @@ module Kward
|
|
|
884
1025
|
end
|
|
885
1026
|
end
|
|
886
1027
|
|
|
1028
|
+
def offer_tab_images(tab)
|
|
1029
|
+
return unless tab.equal?(active_tab) && tab.agent && @prompt.respond_to?(:offer_generated_images)
|
|
1030
|
+
return unless tab_image_waiting?(tab)
|
|
1031
|
+
|
|
1032
|
+
offers = tab.image_offers || []
|
|
1033
|
+
tab.image_offers = nil
|
|
1034
|
+
# Only the input thread drains the queue; the turn worker can only append.
|
|
1035
|
+
tab.pending_images.size.times do
|
|
1036
|
+
offers << { store: @generated_images, owner: tab.agent.conversation, image: tab.pending_images.pop }
|
|
1037
|
+
end
|
|
1038
|
+
@prompt.offer_generated_images(offers)
|
|
1039
|
+
end
|
|
1040
|
+
|
|
1041
|
+
def suspend_tab_images(tab)
|
|
1042
|
+
return unless tab && @prompt.respond_to?(:take_generated_image_offers)
|
|
1043
|
+
|
|
1044
|
+
tab.image_offers = @prompt.take_generated_image_offers
|
|
1045
|
+
end
|
|
1046
|
+
|
|
1047
|
+
def discard_tab_images(tab)
|
|
1048
|
+
return unless tab&.agent && @generated_images
|
|
1049
|
+
|
|
1050
|
+
suspend_tab_images(tab)
|
|
1051
|
+
tab.image_offers = nil
|
|
1052
|
+
tab.pending_images.clear
|
|
1053
|
+
@generated_images.discard_owner(tab.agent.conversation)
|
|
1054
|
+
end
|
|
1055
|
+
|
|
887
1056
|
def plugin_tab_type_for(driver)
|
|
888
1057
|
plugin_registry.tab_type_for_id(driver.descriptor["plugin_tab_type"])
|
|
889
1058
|
end
|
|
890
1059
|
|
|
891
1060
|
def render_tab_answer(tab)
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
@prompt.say("\n#{colored(transcript_marker("Assistant"), :activity, :bold)} #{render_markdown_transcript(tab.answer)}\n")
|
|
1061
|
+
if tab.status == "ready" && !tab.stream_state[:streamed] && !tab.answer.to_s.empty?
|
|
1062
|
+
@prompt.say("\n#{colored(transcript_marker("Assistant"), :activity, :bold)} #{render_markdown_transcript(tab.answer)}\n")
|
|
1063
|
+
end
|
|
1064
|
+
print_turn_summary(tab.stream_state.delete(:turn_summary))
|
|
897
1065
|
end
|
|
898
1066
|
|
|
899
1067
|
def new_tab_stream_state(driver)
|
|
@@ -913,16 +1081,21 @@ module Kward
|
|
|
913
1081
|
label = tab.label.to_s.empty? ? default_tab_label(index) : tab.label.to_s
|
|
914
1082
|
binding = worktree_binding_for(tab)
|
|
915
1083
|
label = "#{label} · #{binding.branch}" if binding&.active?
|
|
1084
|
+
label = "#{label} · image" if tab != active_tab && tab_image_waiting?(tab)
|
|
916
1085
|
{ name: label, color: tab_label_color(tab) }
|
|
917
1086
|
end
|
|
918
1087
|
end
|
|
919
1088
|
|
|
1089
|
+
def tab_image_waiting?(tab)
|
|
1090
|
+
!tab.pending_images.empty? || (tab.image_offers && !tab.image_offers.empty?)
|
|
1091
|
+
end
|
|
1092
|
+
|
|
920
1093
|
def tab_label_color(tab)
|
|
921
1094
|
return :success if tab.status.to_s == "waiting_for_question"
|
|
922
1095
|
return :caution if tab.running? || tab.local_busy?
|
|
923
1096
|
return :failure if %w[failed cancelled].include?(tab.status.to_s) || tab.attention == :failure
|
|
924
1097
|
return :success if tab.attention == :success
|
|
925
|
-
return :
|
|
1098
|
+
return :success if tab.unread
|
|
926
1099
|
|
|
927
1100
|
nil
|
|
928
1101
|
end
|
|
@@ -972,7 +1145,7 @@ module Kward
|
|
|
972
1145
|
end
|
|
973
1146
|
|
|
974
1147
|
def tab_usage
|
|
975
|
-
"/tab 1-n | /tab move 1-n|left|right | /tab close | /tab new | /tab open <plugin-tab> | /tab name <label> | /tab worktree [activate|detach|status|merge|
|
|
1148
|
+
"/tab 1-n | /tab move 1-n|left|right | /tab close | /tab new | /tab open <plugin-tab> | /tab name <label> | /tab worktree [activate|detach|status|merge [resolve|continue|abort]|remove]"
|
|
976
1149
|
end
|
|
977
1150
|
|
|
978
1151
|
def switch_tab_number(number)
|
|
@@ -998,8 +1171,9 @@ module Kward
|
|
|
998
1171
|
return runtime_output("Tab #{value} does not exist.") unless target_index.between?(0, @tabs.length - 1)
|
|
999
1172
|
return if target_index == @active_tab_index
|
|
1000
1173
|
|
|
1001
|
-
save_active_tab_state
|
|
1002
1174
|
stop_tab_live_view
|
|
1175
|
+
save_active_tab_state
|
|
1176
|
+
suspend_tab_images(active_tab)
|
|
1003
1177
|
tab = @tabs.delete_at(@active_tab_index)
|
|
1004
1178
|
@tabs.insert(target_index, tab)
|
|
1005
1179
|
@active_tab_index = target_index
|
|
@@ -1042,16 +1216,55 @@ module Kward
|
|
|
1042
1216
|
end
|
|
1043
1217
|
tab.background_run = nil
|
|
1044
1218
|
close_kwsh_session(tab.shell) if tab&.shell && respond_to?(:close_kwsh_session, true)
|
|
1219
|
+
close_plugin_tab(tab)
|
|
1045
1220
|
rescue StandardError
|
|
1046
1221
|
nil
|
|
1047
1222
|
end
|
|
1223
|
+
ensure
|
|
1224
|
+
@generated_images&.close
|
|
1225
|
+
@generated_images = nil
|
|
1226
|
+
end
|
|
1227
|
+
|
|
1228
|
+
def build_plugin_tab_host(tab_type, workspace_root:, scope_key:)
|
|
1229
|
+
PluginTabHost.new(
|
|
1230
|
+
client: @client,
|
|
1231
|
+
workspace_root: workspace_root,
|
|
1232
|
+
plugin_host: tab_type.plugin_id && plugin_registry.plugin_for(tab_type.plugin_id),
|
|
1233
|
+
type_id: tab_type.id,
|
|
1234
|
+
surface: :local,
|
|
1235
|
+
scope_key: scope_key,
|
|
1236
|
+
capabilities: tab_type.capabilities
|
|
1237
|
+
)
|
|
1238
|
+
end
|
|
1239
|
+
|
|
1240
|
+
def plugin_tab_scope_key(tab_type)
|
|
1241
|
+
tab_type.singleton == :global ? "global" : SecureRandom.uuid
|
|
1242
|
+
end
|
|
1243
|
+
|
|
1244
|
+
def close_plugin_tab(tab)
|
|
1245
|
+
return unless tab&.plugin_host
|
|
1246
|
+
|
|
1247
|
+
if tab.driver.respond_to?(:close)
|
|
1248
|
+
tab.driver.close
|
|
1249
|
+
elsif tab.driver.respond_to?(:shutdown)
|
|
1250
|
+
tab.driver.shutdown
|
|
1251
|
+
end
|
|
1252
|
+
rescue StandardError => e
|
|
1253
|
+
runtime_output("Plugin tab cleanup error: #{e.message}")
|
|
1254
|
+
ensure
|
|
1255
|
+
tab&.plugin_host&.shutdown
|
|
1256
|
+
tab.plugin_host = nil if tab
|
|
1048
1257
|
end
|
|
1049
1258
|
|
|
1050
1259
|
def persist_tabs
|
|
1051
1260
|
return unless @tab_store
|
|
1052
1261
|
|
|
1053
1262
|
@tab_store.save(
|
|
1054
|
-
tabs: @tabs.map
|
|
1263
|
+
tabs: @tabs.map do |tab|
|
|
1264
|
+
descriptor = tab.driver.descriptor.merge("label" => tab.label.to_s)
|
|
1265
|
+
descriptor["scope_key"] ||= tab.plugin_host.scope_key if tab.plugin_host
|
|
1266
|
+
descriptor
|
|
1267
|
+
end,
|
|
1055
1268
|
active_index: @active_tab_index
|
|
1056
1269
|
)
|
|
1057
1270
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "base64"
|
|
2
|
-
require_relative "image_attachments"
|
|
3
|
-
require_relative "message_access"
|
|
4
|
-
require_relative "message_text"
|
|
2
|
+
require_relative "../image_attachments"
|
|
3
|
+
require_relative "../message_access"
|
|
4
|
+
require_relative "../message_text"
|
|
5
5
|
|
|
6
6
|
# Namespace for the Kward CLI agent runtime.
|
|
7
7
|
module Kward
|
|
@@ -19,10 +19,6 @@ module Kward
|
|
|
19
19
|
when "reasoning"
|
|
20
20
|
summary = response_item_text_parts(MessageAccess.value(item, :summary))
|
|
21
21
|
summary.empty? ? response_item_text_parts(MessageAccess.value(item, :content)) : summary
|
|
22
|
-
when "message"
|
|
23
|
-
next [] unless MessageAccess.value(item, :phase).to_s == "commentary"
|
|
24
|
-
|
|
25
|
-
response_item_text_parts(MessageAccess.value(item, :content))
|
|
26
22
|
else
|
|
27
23
|
[]
|
|
28
24
|
end
|
|
@@ -54,15 +50,12 @@ module Kward
|
|
|
54
50
|
end
|
|
55
51
|
|
|
56
52
|
def assistant_content_text(message)
|
|
57
|
-
text =
|
|
58
|
-
return text unless text.empty?
|
|
59
|
-
|
|
60
|
-
response_items(message).filter_map do |item|
|
|
53
|
+
text = response_items(message).filter_map do |item|
|
|
61
54
|
next unless MessageAccess.value(item, :type) == "message"
|
|
62
|
-
next if MessageAccess.value(item, :phase).to_s == "commentary"
|
|
63
55
|
|
|
64
56
|
response_item_text(MessageAccess.value(item, :content))
|
|
65
|
-
end.join
|
|
57
|
+
end.reject(&:empty?).join("\n\n")
|
|
58
|
+
text.empty? ? content_text(MessageAccess.content(message)) : text
|
|
66
59
|
end
|
|
67
60
|
|
|
68
61
|
def user_display_text(message)
|