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/worktrees.rb
CHANGED
|
@@ -61,6 +61,7 @@ module Kward
|
|
|
61
61
|
reasoning_effort: current_reasoning_effort
|
|
62
62
|
)
|
|
63
63
|
agent = build_tab_agent(conversation, session, worktree: worktree)
|
|
64
|
+
discard_tab_images(tab)
|
|
64
65
|
tab.session = track_session(session)
|
|
65
66
|
tab.agent = agent
|
|
66
67
|
tab.driver = SessionTabDriver.new(session: tab.session, agent: agent, worktree: worktree)
|
|
@@ -101,10 +102,14 @@ module Kward
|
|
|
101
102
|
remove_active_worktree
|
|
102
103
|
when "merge"
|
|
103
104
|
merge_active_worktree
|
|
105
|
+
when "merge resolve"
|
|
106
|
+
resolve_active_worktree_merge
|
|
107
|
+
when "merge continue"
|
|
108
|
+
continue_active_worktree_merge
|
|
104
109
|
when "merge abort"
|
|
105
110
|
abort_active_worktree_merge
|
|
106
111
|
else
|
|
107
|
-
runtime_output("Usage: /tab worktree [activate|detach|status|merge|
|
|
112
|
+
runtime_output("Usage: /tab worktree [activate|detach|status|merge [resolve|continue|abort]|remove]")
|
|
108
113
|
end
|
|
109
114
|
end
|
|
110
115
|
|
|
@@ -222,6 +227,11 @@ module Kward
|
|
|
222
227
|
raise GitWorktreeManager::Error, "Worktree branch changed: expected #{binding.branch}, found #{info.branch || "detached HEAD"}" unless info.branch == binding.branch
|
|
223
228
|
status = git_worktree_manager.status(binding.path)
|
|
224
229
|
lines << "Changes: #{status.clean? ? "clean" : "#{status.entries.length} local change(s)"}"
|
|
230
|
+
if git_worktree_manager.merge_in_progress?(binding.origin_root)
|
|
231
|
+
conflicts = git_worktree_manager.merge_conflict_marker_paths(binding.origin_root, cached: false)
|
|
232
|
+
lines << "Merge: in progress in origin#{conflicts.empty? ? "; ready to continue" : "; #{conflicts.length} unresolved conflict(s)"}"
|
|
233
|
+
lines << "Conflicts: #{conflicts.join(", ")}" unless conflicts.empty?
|
|
234
|
+
end
|
|
225
235
|
rescue GitWorktreeManager::Error => e
|
|
226
236
|
lines << "State: unavailable (#{e.message})"
|
|
227
237
|
end
|
|
@@ -236,6 +246,10 @@ module Kward
|
|
|
236
246
|
return runtime_output("Activate the worktree before merging it.") unless binding.active?
|
|
237
247
|
|
|
238
248
|
validate_worktree_binding!(binding)
|
|
249
|
+
if git_worktree_manager.merge_in_progress?(binding.origin_root)
|
|
250
|
+
return runtime_output("A merge is already in progress in #{binding.origin_root}. Resolve it with /worktree merge resolve, continue it with /worktree merge continue, or abort it with /worktree merge abort.")
|
|
251
|
+
end
|
|
252
|
+
|
|
239
253
|
source_status = git_worktree_manager.status(binding.path)
|
|
240
254
|
return runtime_output("Worktree has local changes; commit or clean it before merging.") if source_status.dirty?
|
|
241
255
|
|
|
@@ -270,12 +284,62 @@ module Kward
|
|
|
270
284
|
if result.merged?
|
|
271
285
|
runtime_output("Merged #{binding.branch} into #{target_branch}.")
|
|
272
286
|
else
|
|
273
|
-
runtime_output(
|
|
287
|
+
runtime_output(<<~MESSAGE.strip)
|
|
288
|
+
Merge conflicts in #{result.conflicts.join(", ")}.
|
|
289
|
+
Merge paused in #{binding.origin_root}; this tab remains on #{binding.branch}.
|
|
290
|
+
Run /worktree merge resolve to let the agent inspect and fix the conflicts here, or /worktree merge abort to cancel.
|
|
291
|
+
MESSAGE
|
|
274
292
|
end
|
|
275
293
|
rescue GitWorktreeManager::Error => e
|
|
276
294
|
runtime_output("Worktree error: #{e.message}")
|
|
277
295
|
end
|
|
278
296
|
|
|
297
|
+
def resolve_active_worktree_merge
|
|
298
|
+
tab = active_tab
|
|
299
|
+
binding = worktree_binding_for(tab)
|
|
300
|
+
return runtime_output("Tab #{active_tab_number} has no worktree binding.") unless binding
|
|
301
|
+
return runtime_output("Tab #{active_tab_number} is running and cannot resolve its worktree merge yet.") if tab.running? || tab.local_busy? || tab.shell
|
|
302
|
+
return runtime_output("Activate the worktree before resolving its merge.") unless binding.active?
|
|
303
|
+
return runtime_output("No merge is in progress in the original workspace.") unless git_worktree_manager.merge_in_progress?(binding.origin_root)
|
|
304
|
+
|
|
305
|
+
validate_worktree_binding!(binding)
|
|
306
|
+
conflicts = git_worktree_manager.unmerged_paths(binding.origin_root)
|
|
307
|
+
return runtime_output("No unresolved conflicts remain in #{binding.origin_root}; run /worktree merge continue to finish the merge.") if conflicts.empty?
|
|
308
|
+
|
|
309
|
+
submit_tab_input(
|
|
310
|
+
tab,
|
|
311
|
+
<<~PROMPT.strip,
|
|
312
|
+
Resolve the in-progress Git merge in the verified origin workspace. Use target: "origin" for every workspace inspection, edit, and test operation. Read the applicable AGENTS.md files first, inspect the unmerged paths, resolve the conflicts, and run the relevant tests. Do not commit the merge; leave it ready for /worktree merge continue after all conflicts are resolved.
|
|
313
|
+
|
|
314
|
+
Unmerged paths: #{conflicts.join(", ")}
|
|
315
|
+
PROMPT
|
|
316
|
+
display_input: "Resolve merge conflicts in origin"
|
|
317
|
+
)
|
|
318
|
+
rescue GitWorktreeManager::Error => e
|
|
319
|
+
runtime_output("Worktree error: #{e.message}")
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def continue_active_worktree_merge
|
|
323
|
+
tab = active_tab
|
|
324
|
+
binding = worktree_binding_for(tab)
|
|
325
|
+
return runtime_output("Tab #{active_tab_number} has no worktree binding.") unless binding
|
|
326
|
+
return runtime_output("Tab #{active_tab_number} is running and cannot continue its worktree merge yet.") if tab.running? || tab.local_busy? || tab.shell
|
|
327
|
+
return runtime_output("Activate the worktree before continuing its merge.") unless binding.active?
|
|
328
|
+
return runtime_output("No merge is in progress in the original workspace.") unless git_worktree_manager.merge_in_progress?(binding.origin_root)
|
|
329
|
+
|
|
330
|
+
validate_worktree_binding!(binding)
|
|
331
|
+
markers = git_worktree_manager.merge_conflict_marker_paths(binding.origin_root, cached: false)
|
|
332
|
+
return runtime_output("Merge still contains conflict markers: #{markers.join(", ")}.") unless markers.empty?
|
|
333
|
+
target_branch = git_worktree_manager.current_branch(binding.origin_root)
|
|
334
|
+
return runtime_output("Original workspace is in detached HEAD state; resolve that before continuing the merge.") if target_branch.empty?
|
|
335
|
+
return unless confirm_worktree_action("Complete the merge of #{binding.branch} into #{target_branch} in #{binding.origin_root}?")
|
|
336
|
+
|
|
337
|
+
git_worktree_manager.continue_merge(binding.origin_root)
|
|
338
|
+
runtime_output("Completed the merge of #{binding.branch} into #{target_branch}.")
|
|
339
|
+
rescue GitWorktreeManager::Error => e
|
|
340
|
+
runtime_output("Worktree error: #{e.message}")
|
|
341
|
+
end
|
|
342
|
+
|
|
279
343
|
def abort_active_worktree_merge
|
|
280
344
|
tab = active_tab
|
|
281
345
|
binding = worktree_binding_for(tab)
|
data/lib/kward/cli.rb
CHANGED
|
@@ -3,26 +3,27 @@ require "json"
|
|
|
3
3
|
require "thread"
|
|
4
4
|
require "tty-prompt"
|
|
5
5
|
require_relative "agent"
|
|
6
|
-
require_relative "ansi"
|
|
6
|
+
require_relative "terminal/ansi"
|
|
7
|
+
require_relative "terminal/sequences"
|
|
7
8
|
require_relative "version"
|
|
8
9
|
require_relative "model/client"
|
|
9
10
|
require_relative "compactor"
|
|
10
11
|
require_relative "config_files"
|
|
11
|
-
require_relative "clipboard"
|
|
12
|
+
require_relative "terminal/clipboard"
|
|
12
13
|
require_relative "cancellation"
|
|
13
|
-
require_relative "editor_prompt"
|
|
14
|
-
require_relative "editor_prompt_session"
|
|
15
|
-
require_relative "
|
|
16
|
-
require_relative "
|
|
17
|
-
require_relative "
|
|
14
|
+
require_relative "cli/editor_prompt"
|
|
15
|
+
require_relative "cli/editor_prompt_session"
|
|
16
|
+
require_relative "shell/prompt"
|
|
17
|
+
require_relative "shell/prompt_session"
|
|
18
|
+
require_relative "cli/transcript_formatter"
|
|
18
19
|
require_relative "model/context_usage"
|
|
19
20
|
require_relative "events"
|
|
20
|
-
require_relative "export_path"
|
|
21
|
-
require_relative "kwsh"
|
|
22
|
-
require_relative "
|
|
23
|
-
require_relative "
|
|
24
|
-
require_relative "
|
|
25
|
-
require_relative "
|
|
21
|
+
require_relative "transcripts/export_path"
|
|
22
|
+
require_relative "shell/kwsh"
|
|
23
|
+
require_relative "shell/persistent_session"
|
|
24
|
+
require_relative "pty/interactive_runner"
|
|
25
|
+
require_relative "pty/adaptive_output_sink"
|
|
26
|
+
require_relative "pty/transcript_normalizer"
|
|
26
27
|
require_relative "auth/anthropic_oauth"
|
|
27
28
|
require_relative "auth/api_key_store"
|
|
28
29
|
require_relative "auth/github_oauth"
|
|
@@ -30,7 +31,7 @@ require_relative "auth/openrouter_api_key"
|
|
|
30
31
|
require_relative "image_attachments"
|
|
31
32
|
require_relative "memory/manager"
|
|
32
33
|
require_relative "memory/turn_context"
|
|
33
|
-
require_relative "transcript_export"
|
|
34
|
+
require_relative "transcripts/transcript_export"
|
|
34
35
|
require_relative "message_access"
|
|
35
36
|
require_relative "model/model_info"
|
|
36
37
|
require_relative "model/azure_openai_config"
|
|
@@ -38,18 +39,18 @@ require_relative "model/provider_catalog"
|
|
|
38
39
|
require_relative "model/catalog"
|
|
39
40
|
require_relative "auth/openai_oauth"
|
|
40
41
|
require_relative "pan/server"
|
|
41
|
-
require_relative "
|
|
42
|
+
require_relative "plugins/registry"
|
|
42
43
|
require_relative "prompts/commands"
|
|
43
44
|
require_relative "model/retry_message"
|
|
44
45
|
require_relative "rpc/server"
|
|
45
46
|
require_relative "transport/runtime"
|
|
46
|
-
require_relative "
|
|
47
|
-
require_relative "
|
|
48
|
-
require_relative "
|
|
49
|
-
require_relative "
|
|
50
|
-
require_relative "
|
|
51
|
-
require_relative "
|
|
52
|
-
require_relative "
|
|
47
|
+
require_relative "sessions/diff"
|
|
48
|
+
require_relative "sessions/store"
|
|
49
|
+
require_relative "sessions/naming"
|
|
50
|
+
require_relative "tabs/store"
|
|
51
|
+
require_relative "tabs/driver"
|
|
52
|
+
require_relative "sessions/trash"
|
|
53
|
+
require_relative "sessions/tree_renderer"
|
|
53
54
|
require_relative "skills/capture"
|
|
54
55
|
require_relative "starter_pack_installer"
|
|
55
56
|
require_relative "steering"
|
|
@@ -57,8 +58,8 @@ require_relative "update_check"
|
|
|
57
58
|
require_relative "tools/tool_call"
|
|
58
59
|
require_relative "tools/registry"
|
|
59
60
|
require_relative "telemetry/stats"
|
|
60
|
-
require_relative "
|
|
61
|
-
require_relative "git_worktree_manager"
|
|
61
|
+
require_relative "workspace/factory"
|
|
62
|
+
require_relative "workspace/git_worktree_manager"
|
|
62
63
|
require_relative "cli/commands"
|
|
63
64
|
require_relative "cli/auth_commands"
|
|
64
65
|
require_relative "cli/doctor"
|
|
@@ -135,6 +136,7 @@ module Kward
|
|
|
135
136
|
@working_directory = nil
|
|
136
137
|
@prompt_delimited = false
|
|
137
138
|
@requested_mode = "auto"
|
|
139
|
+
@startup_option_name = nil
|
|
138
140
|
@skip_config = false
|
|
139
141
|
@pending_reasoning_config = nil
|
|
140
142
|
@pending_reasoning_config_mutex = Mutex.new
|
|
@@ -147,7 +149,11 @@ module Kward
|
|
|
147
149
|
# @return [void]
|
|
148
150
|
def run
|
|
149
151
|
@argv = extract_global_options(@argv)
|
|
152
|
+
if @startup_option_name && (!@argv.empty? || @prompt_delimited)
|
|
153
|
+
raise ArgumentError, "Plugin startup option #{@startup_option_name} cannot be combined with a prompt or --"
|
|
154
|
+
end
|
|
150
155
|
ConfigFiles.skip_config = @skip_config
|
|
156
|
+
ConfigFiles.ignore_local_instructions = @ignore_local_instructions
|
|
151
157
|
with_working_directory { dispatch }
|
|
152
158
|
rescue ConfigFiles::ConfigError => e
|
|
153
159
|
warn config_error_message(e)
|
|
@@ -167,7 +173,9 @@ module Kward
|
|
|
167
173
|
warn runtime_error_message(e)
|
|
168
174
|
exit 1
|
|
169
175
|
ensure
|
|
176
|
+
shutdown_plugins if respond_to?(:shutdown_plugins, true)
|
|
170
177
|
ConfigFiles.skip_config = false
|
|
178
|
+
ConfigFiles.ignore_local_instructions = false
|
|
171
179
|
end
|
|
172
180
|
|
|
173
181
|
def ensure_client!
|
|
@@ -219,9 +227,8 @@ module Kward
|
|
|
219
227
|
end
|
|
220
228
|
|
|
221
229
|
def dispatch
|
|
222
|
-
if @
|
|
223
|
-
|
|
224
|
-
run_prompt_or_interactive
|
|
230
|
+
if @startup_option_name
|
|
231
|
+
discover_plugin_registry.run_startup_option(@startup_option_name)
|
|
225
232
|
return
|
|
226
233
|
end
|
|
227
234
|
|
|
@@ -239,6 +246,30 @@ module Kward
|
|
|
239
246
|
|
|
240
247
|
ConfigFiles.ensure_default_config!
|
|
241
248
|
|
|
249
|
+
if @argv.first == "filter"
|
|
250
|
+
if help_option_arguments?(@argv[1..] || [])
|
|
251
|
+
print_command_help("filter")
|
|
252
|
+
return
|
|
253
|
+
end
|
|
254
|
+
raise ArgumentError, command_usage("filter") if @argv.length < 2
|
|
255
|
+
|
|
256
|
+
@requested_mode = "filter"
|
|
257
|
+
@argv = ["prompt", *(@argv[1..] || [])]
|
|
258
|
+
run_prompt_or_interactive
|
|
259
|
+
return
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
if @argv.first == "prompt"
|
|
263
|
+
if help_option_arguments?(@argv[1..] || [])
|
|
264
|
+
print_command_help("prompt")
|
|
265
|
+
return
|
|
266
|
+
end
|
|
267
|
+
raise ArgumentError, command_usage("prompt") if @argv.length < 2
|
|
268
|
+
|
|
269
|
+
run_prompt_or_interactive
|
|
270
|
+
return
|
|
271
|
+
end
|
|
272
|
+
|
|
242
273
|
if @argv.first == "init"
|
|
243
274
|
if help_option_arguments?(@argv[1..] || [])
|
|
244
275
|
print_command_help("init")
|
|
@@ -376,10 +407,16 @@ module Kward
|
|
|
376
407
|
return
|
|
377
408
|
end
|
|
378
409
|
|
|
379
|
-
|
|
410
|
+
raise ArgumentError, "Unknown command: #{@argv.first}" unless @argv.empty?
|
|
411
|
+
|
|
412
|
+
ensure_client!
|
|
413
|
+
interactive_loop
|
|
380
414
|
end
|
|
381
415
|
|
|
382
416
|
def edit_file_command(path)
|
|
417
|
+
terminal = $stdout if @stdin.tty? && $stdout.tty? && ENV["TERM"] != "dumb"
|
|
418
|
+
terminal&.write(TerminalSequences::ALTERNATE_SCREEN_ENTER)
|
|
419
|
+
terminal&.flush
|
|
383
420
|
setup_interactive_prompt
|
|
384
421
|
unless @prompt.respond_to?(:edit_file)
|
|
385
422
|
raise ArgumentError, "The integrated editor requires an interactive terminal."
|
|
@@ -387,8 +424,13 @@ module Kward
|
|
|
387
424
|
|
|
388
425
|
@prompt.edit_file(path, base_dir: Dir.pwd, allow_new: true)
|
|
389
426
|
ensure
|
|
390
|
-
|
|
391
|
-
|
|
427
|
+
begin
|
|
428
|
+
@prompt.close if @prompt.respond_to?(:close) && prompt_interface?
|
|
429
|
+
ensure
|
|
430
|
+
terminal&.write(TerminalSequences::ALTERNATE_SCREEN_LEAVE)
|
|
431
|
+
terminal&.flush
|
|
432
|
+
clear_interactive_warning_sink if respond_to?(:clear_interactive_warning_sink, true)
|
|
433
|
+
end
|
|
392
434
|
end
|
|
393
435
|
|
|
394
436
|
def run_prompt_or_interactive
|
|
@@ -424,6 +466,7 @@ module Kward
|
|
|
424
466
|
tool_registry: ToolRegistry.new(
|
|
425
467
|
workspace: configured_workspace,
|
|
426
468
|
prompt: @prompt,
|
|
469
|
+
plugin_tools: plugin_registry.tools,
|
|
427
470
|
hook_manager: hook_manager,
|
|
428
471
|
hook_context: hook_context
|
|
429
472
|
),
|
|
@@ -431,10 +474,12 @@ module Kward
|
|
|
431
474
|
hook_manager: hook_manager,
|
|
432
475
|
hook_context: hook_context
|
|
433
476
|
)
|
|
477
|
+
summary = nil
|
|
434
478
|
answer = if filter
|
|
435
479
|
agent.ask(input)
|
|
436
480
|
else
|
|
437
481
|
agent.ask(input) do |event|
|
|
482
|
+
summary = event.summary if event.is_a?(Events::TurnSummary)
|
|
438
483
|
result = render_blocking_turn_event(event, markdown_chunks)
|
|
439
484
|
streamed = true if result
|
|
440
485
|
assistant_streamed = true if result == :assistant_streamed
|
|
@@ -443,7 +488,13 @@ module Kward
|
|
|
443
488
|
flush_markdown_deltas(markdown_chunks) if streamed
|
|
444
489
|
return answer if filter
|
|
445
490
|
|
|
446
|
-
assistant_streamed ? "" : render_markdown_transcript(answer)
|
|
491
|
+
text = assistant_streamed ? "" : render_markdown_transcript(answer)
|
|
492
|
+
stats = turn_summary_text(summary)
|
|
493
|
+
[text, stats.empty? ? nil : colored(stats, :metadata)].compact.reject(&:empty?).join("\n\n")
|
|
494
|
+
rescue StandardError
|
|
495
|
+
flush_markdown_deltas(markdown_chunks) unless filter
|
|
496
|
+
print_turn_summary(summary) unless filter
|
|
497
|
+
raise
|
|
447
498
|
end
|
|
448
499
|
|
|
449
500
|
def resolved_execution_mode(first_prompt:, stdin_input:)
|
data/lib/kward/compactor.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
require_relative "model/chat_invocation"
|
|
3
|
+
require_relative "cancellation"
|
|
3
4
|
require_relative "compaction/file_operation_tracker"
|
|
4
5
|
require_relative "compaction/token_estimator"
|
|
5
6
|
require_relative "config_files"
|
|
@@ -671,29 +672,33 @@ module Kward
|
|
|
671
672
|
@prompt_builder = prompt_builder
|
|
672
673
|
end
|
|
673
674
|
|
|
674
|
-
def summarize(preparation, custom_instructions: nil)
|
|
675
|
+
def summarize(preparation, custom_instructions: nil, cancellation: nil)
|
|
675
676
|
summary = chat(
|
|
676
677
|
@prompt_builder.build(preparation, custom_instructions: custom_instructions),
|
|
677
|
-
max_tokens: @prompt_builder.normal_summary_max_tokens(preparation.settings, model_max_tokens: model_max_tokens)
|
|
678
|
+
max_tokens: @prompt_builder.normal_summary_max_tokens(preparation.settings, model_max_tokens: model_max_tokens),
|
|
679
|
+
cancellation: cancellation
|
|
678
680
|
)
|
|
679
681
|
if preparation.split_turn && !preparation.turn_prefix_messages.empty?
|
|
680
682
|
turn_summary = chat(
|
|
681
683
|
@prompt_builder.build_split(preparation),
|
|
682
|
-
max_tokens: @prompt_builder.split_turn_max_tokens(preparation.settings, model_max_tokens: model_max_tokens)
|
|
684
|
+
max_tokens: @prompt_builder.split_turn_max_tokens(preparation.settings, model_max_tokens: model_max_tokens),
|
|
685
|
+
cancellation: cancellation
|
|
683
686
|
)
|
|
684
687
|
summary = "#{summary}\n\n---\n\n**Turn Context (split turn):**\n\n#{turn_summary}"
|
|
685
688
|
end
|
|
686
689
|
summary.to_s.strip
|
|
687
690
|
rescue Cancelled
|
|
688
691
|
raise
|
|
692
|
+
rescue Kward::Cancellation::CancelledError
|
|
693
|
+
raise
|
|
689
694
|
rescue StandardError => e
|
|
690
695
|
raise SummarizationFailed, e.message
|
|
691
696
|
end
|
|
692
697
|
|
|
693
698
|
private
|
|
694
699
|
|
|
695
|
-
def chat(messages, max_tokens: nil)
|
|
696
|
-
message = ChatInvocation.call(@client, messages, { tools: [], max_tokens: max_tokens })
|
|
700
|
+
def chat(messages, max_tokens: nil, cancellation: nil)
|
|
701
|
+
message = ChatInvocation.call(@client, messages, { tools: [], max_tokens: max_tokens, cancellation: cancellation })
|
|
697
702
|
content = message_content(message)
|
|
698
703
|
text = message_content_text(content).strip
|
|
699
704
|
raise SummarizationFailed, "Compaction produced an empty summary; context was not changed." if text.empty?
|
|
@@ -752,13 +757,19 @@ module Kward
|
|
|
752
757
|
false
|
|
753
758
|
end
|
|
754
759
|
|
|
755
|
-
def compact(custom_instructions: nil, compaction_summary: true)
|
|
760
|
+
def compact(custom_instructions: nil, compaction_summary: true, cancellation: nil)
|
|
761
|
+
cancellation&.raise_if_cancelled!
|
|
756
762
|
old_count = @conversation.messages.length
|
|
757
763
|
preparation = prepare
|
|
758
|
-
summary =
|
|
764
|
+
summary = if cancellation
|
|
765
|
+
@summarizer.summarize(preparation, custom_instructions: custom_instructions, cancellation: cancellation)
|
|
766
|
+
else
|
|
767
|
+
@summarizer.summarize(preparation, custom_instructions: custom_instructions)
|
|
768
|
+
end
|
|
759
769
|
summary = append_files_section(summary, preparation.file_ops)
|
|
760
770
|
raise Compaction::SummarizationFailed, "Compaction produced an empty summary; context was not changed." if summary.strip.empty?
|
|
761
771
|
|
|
772
|
+
cancellation&.raise_if_cancelled!
|
|
762
773
|
@conversation.compact!(
|
|
763
774
|
summary,
|
|
764
775
|
compaction_summary: compaction_summary,
|