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.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +164 -0
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile.lock +6 -2
  5. data/README.md +5 -5
  6. data/Rakefile +3 -0
  7. data/doc/agent-tools.md +24 -1
  8. data/doc/api.md +20 -2
  9. data/doc/composer.md +5 -4
  10. data/doc/configuration.md +86 -14
  11. data/doc/extensibility.md +4 -1
  12. data/doc/getting-started.md +3 -3
  13. data/doc/git.md +4 -2
  14. data/doc/memory.md +1 -1
  15. data/doc/pan.md +6 -0
  16. data/doc/permissions.md +4 -4
  17. data/doc/plugins.md +504 -20
  18. data/doc/providers.md +10 -4
  19. data/doc/rpc.md +279 -23
  20. data/doc/sandboxing.md +11 -5
  21. data/doc/security.md +7 -1
  22. data/doc/session-management.md +41 -5
  23. data/doc/shell.md +643 -27
  24. data/doc/tabs.md +8 -3
  25. data/doc/transports.md +15 -0
  26. data/doc/troubleshooting.md +1 -1
  27. data/doc/usage.md +25 -12
  28. data/doc/workspace-tools.md +9 -0
  29. data/examples/plugins/openrouter_proxy/README.md +103 -0
  30. data/examples/plugins/openrouter_proxy/fake_embeddings.rb +85 -0
  31. data/examples/plugins/openrouter_proxy/plugin.rb +7 -0
  32. data/examples/plugins/openrouter_proxy/protocol.rb +202 -0
  33. data/examples/plugins/openrouter_proxy/server.rb +186 -0
  34. data/examples/plugins/space_invaders.rb +1 -2
  35. data/examples/plugins/stardate_footer.rb +2 -2
  36. data/examples/plugins/telegram/plugin.rb +1 -1
  37. data/exe/kward +2 -2
  38. data/exe/kwsh +7 -0
  39. data/kward.gemspec +3 -1
  40. data/lib/kward/agent.rb +66 -19
  41. data/lib/kward/cli/commands.rb +41 -11
  42. data/lib/kward/cli/compaction.rb +9 -3
  43. data/lib/kward/cli/interactive_turn.rb +10 -0
  44. data/lib/kward/cli/plugins.rb +85 -12
  45. data/lib/kward/cli/prompt_interface.rb +29 -6
  46. data/lib/kward/cli/rendering.rb +24 -28
  47. data/lib/kward/cli/runtime_helpers.rb +168 -56
  48. data/lib/kward/cli/sessions.rb +9 -5
  49. data/lib/kward/cli/settings/menus.rb +745 -0
  50. data/lib/kward/cli/settings/model.rb +316 -0
  51. data/lib/kward/cli/settings.rb +6 -1055
  52. data/lib/kward/cli/slash_commands.rb +45 -4
  53. data/lib/kward/cli/tabs.rb +257 -44
  54. data/lib/kward/cli/tool_summaries.rb +2 -0
  55. data/lib/kward/{cli_transcript_formatter.rb → cli/transcript_formatter.rb} +6 -13
  56. data/lib/kward/cli/worktrees.rb +66 -2
  57. data/lib/kward/cli.rb +82 -31
  58. data/lib/kward/compactor.rb +18 -7
  59. data/lib/kward/config/core.rb +400 -0
  60. data/lib/kward/config/extensions.rb +99 -0
  61. data/lib/kward/config/paths.rb +11 -0
  62. data/lib/kward/config/prompts.rb +313 -0
  63. data/lib/kward/config/settings.rb +257 -0
  64. data/lib/kward/config_files.rb +14 -1008
  65. data/lib/kward/conversation.rb +41 -2
  66. data/lib/kward/entrypoint.rb +14 -0
  67. data/lib/kward/events.rb +2 -0
  68. data/lib/kward/generated_images.rb +237 -0
  69. data/lib/kward/image_attachments.rb +1 -1
  70. data/lib/kward/model/catalog.rb +6 -3
  71. data/lib/kward/model/client.rb +107 -38
  72. data/lib/kward/model/codex_images.rb +83 -0
  73. data/lib/kward/model/copilot_models.rb +10 -6
  74. data/lib/kward/model/model_info.rb +42 -7
  75. data/lib/kward/{openrouter_model_cache.rb → model/openrouter_model_cache.rb} +7 -5
  76. data/lib/kward/model/payloads.rb +18 -8
  77. data/lib/kward/model/sources.rb +3 -1
  78. data/lib/kward/model/stream_parser.rb +4 -7
  79. data/lib/kward/model/typesafe_client.rb +78 -0
  80. data/lib/kward/pan/index.html.erb +8 -1
  81. data/lib/kward/pan/server.rb +23 -8
  82. data/lib/kward/permissions/policy.rb +6 -2
  83. data/lib/kward/plugin_registry.rb +2 -659
  84. data/lib/kward/plugins/actions.rb +453 -0
  85. data/lib/kward/plugins/chat_contract.rb +121 -0
  86. data/lib/kward/{plugin_chat_runtime.rb → plugins/chat_runtime.rb} +62 -18
  87. data/lib/kward/plugins/codex_responses.rb +73 -0
  88. data/lib/kward/plugins/host.rb +248 -0
  89. data/lib/kward/plugins/http_server.rb +83 -0
  90. data/lib/kward/plugins/registry.rb +1229 -0
  91. data/lib/kward/plugins/resources.rb +206 -0
  92. data/lib/kward/plugins/turn_request.rb +36 -0
  93. data/lib/kward/plugins/ui.rb +219 -0
  94. data/lib/kward/prompt_interface/composer_controller.rb +0 -1
  95. data/lib/kward/prompt_interface/composer_renderer.rb +160 -73
  96. data/lib/kward/prompt_interface/composer_state.rb +1 -1
  97. data/lib/kward/prompt_interface/editor/controller.rb +2 -2
  98. data/lib/kward/prompt_interface/editor/renderer.rb +10 -7
  99. data/lib/kward/prompt_interface/editor/runner.rb +1 -1
  100. data/lib/kward/prompt_interface/editor/state.rb +1 -1
  101. data/lib/kward/prompt_interface/file_overlay.rb +3 -3
  102. data/lib/kward/prompt_interface/generated_image_preview.rb +162 -0
  103. data/lib/kward/prompt_interface/git_prompt.rb +18 -11
  104. data/lib/kward/prompt_interface/interactive/renderer.rb +1 -1
  105. data/lib/kward/prompt_interface/interactive/state.rb +18 -20
  106. data/lib/kward/prompt_interface/key_handler.rb +108 -25
  107. data/lib/kward/prompt_interface/layout.rb +11 -1
  108. data/lib/kward/prompt_interface/overlay_renderer.rb +26 -9
  109. data/lib/kward/prompt_interface/plugin_ui_requests.rb +82 -0
  110. data/lib/kward/prompt_interface/project_browser.rb +27 -54
  111. data/lib/kward/prompt_interface/prompt_renderer.rb +27 -35
  112. data/lib/kward/prompt_interface/question_prompt.rb +19 -28
  113. data/lib/kward/prompt_interface/runtime_state.rb +37 -10
  114. data/lib/kward/prompt_interface/screen.rb +30 -20
  115. data/lib/kward/prompt_interface/selection_prompt.rb +8 -8
  116. data/lib/kward/prompt_interface/slash_overlay.rb +1 -1
  117. data/lib/kward/prompt_interface/transcript_renderer.rb +7 -6
  118. data/lib/kward/prompt_interface.rb +149 -30
  119. data/lib/kward/prompts/commands.rb +2 -1
  120. data/lib/kward/prompts.rb +7 -1
  121. data/lib/kward/{adaptive_pty_output_sink.rb → pty/adaptive_output_sink.rb} +39 -5
  122. data/lib/kward/{interactive_pty_runner.rb → pty/interactive_runner.rb} +22 -30
  123. data/lib/kward/{local_command_runner.rb → pty/local_command_runner.rb} +1 -1
  124. data/lib/kward/{local_pty_command_runner.rb → pty/local_pty_runner.rb} +3 -9
  125. data/lib/kward/{pty_output_sink.rb → pty/output_sink.rb} +9 -4
  126. data/lib/kward/pty/transcript_normalizer.rb +137 -0
  127. data/lib/kward/rpc/config_manager.rb +3 -0
  128. data/lib/kward/rpc/plugin_chat_manager.rb +30 -10
  129. data/lib/kward/rpc/prompt_bridge.rb +25 -0
  130. data/lib/kward/rpc/server.rb +118 -17
  131. data/lib/kward/rpc/session_manager.rb +208 -60
  132. data/lib/kward/rpc/session_tree_rows.rb +2 -2
  133. data/lib/kward/rpc/tool_metadata.rb +1 -1
  134. data/lib/kward/rpc/transcript_normalizer.rb +11 -7
  135. data/lib/kward/sandbox/command_runner.rb +1 -1
  136. data/lib/kward/{session_catalog.rb → sessions/catalog.rb} +1 -1
  137. data/lib/kward/{session_store.rb → sessions/store.rb} +39 -12
  138. data/lib/kward/{session_tree_nodes.rb → sessions/tree_nodes.rb} +3 -3
  139. data/lib/kward/{session_tree_renderer.rb → sessions/tree_renderer.rb} +4 -4
  140. data/lib/kward/{session_tree_tool_display.rb → sessions/tree_tool_display.rb} +1 -1
  141. data/lib/kward/{kwsh.rb → shell/kwsh.rb} +30 -10
  142. data/lib/kward/{kwshrc.rb → shell/kwshrc.rb} +11 -2
  143. data/lib/kward/shell/native_arithmetic.rb +255 -0
  144. data/lib/kward/shell/native_arrays.rb +102 -0
  145. data/lib/kward/shell/native_braces.rb +96 -0
  146. data/lib/kward/shell/native_builtins.rb +476 -0
  147. data/lib/kward/shell/native_completion.rb +169 -0
  148. data/lib/kward/shell/native_condition.rb +75 -0
  149. data/lib/kward/shell/native_directory.rb +116 -0
  150. data/lib/kward/shell/native_exec_state.rb +73 -0
  151. data/lib/kward/shell/native_expansion.rb +252 -0
  152. data/lib/kward/shell/native_fields.rb +62 -0
  153. data/lib/kward/shell/native_glob.rb +96 -0
  154. data/lib/kward/shell/native_history.rb +242 -0
  155. data/lib/kward/shell/native_interactive.rb +164 -0
  156. data/lib/kward/shell/native_invocation.rb +42 -0
  157. data/lib/kward/shell/native_jobs.rb +250 -0
  158. data/lib/kward/shell/native_line_editor.rb +382 -0
  159. data/lib/kward/shell/native_line_terminal.rb +286 -0
  160. data/lib/kward/shell/native_locale.rb +109 -0
  161. data/lib/kward/shell/native_locals.rb +57 -0
  162. data/lib/kward/shell/native_pattern.rb +200 -0
  163. data/lib/kward/shell/native_process.rb +279 -0
  164. data/lib/kward/shell/native_program.rb +40 -0
  165. data/lib/kward/shell/native_programmable_completion.rb +115 -0
  166. data/lib/kward/shell/native_prompt_format.rb +89 -0
  167. data/lib/kward/shell/native_runtime.rb +964 -0
  168. data/lib/kward/shell/native_substitution.rb +110 -0
  169. data/lib/kward/shell/native_syntax.rb +946 -0
  170. data/lib/kward/shell/native_traps.rb +196 -0
  171. data/lib/kward/shell/native_vi.rb +407 -0
  172. data/lib/kward/shell/native_vi_terminal.rb +19 -0
  173. data/lib/kward/shell/native_worker.rb +82 -0
  174. data/lib/kward/{persistent_shell_session.rb → shell/persistent_session.rb} +187 -193
  175. data/lib/kward/shell/prompt.rb +66 -0
  176. data/lib/kward/shell/prompt_agent.rb +17 -0
  177. data/lib/kward/{shell_prompt_session.rb → shell/prompt_session.rb} +1 -1
  178. data/lib/kward/shell/script_runner.rb +244 -0
  179. data/lib/kward/shell/standalone_agent.rb +31 -0
  180. data/lib/kward/shell/standalone_link.rb +78 -0
  181. data/lib/kward/shell/standalone_terminal.rb +287 -0
  182. data/lib/kward/skills/trust_store.rb +1 -1
  183. data/lib/kward/tabs/driver.rb +194 -0
  184. data/lib/kward/{tab_store.rb → tabs/store.rb} +2 -2
  185. data/lib/kward/{clipboard.rb → terminal/clipboard.rb} +1 -1
  186. data/lib/kward/{terminal_image_support.rb → terminal/image_support.rb} +1 -1
  187. data/lib/kward/{terminal_keys.rb → terminal/keys.rb} +22 -1
  188. data/lib/kward/terminal/locale_text.rb +29 -0
  189. data/lib/kward/{terminal_sequences.rb → terminal/sequences.rb} +45 -4
  190. data/lib/kward/tools/base.rb +18 -0
  191. data/lib/kward/tools/context_for_task.rb +15 -6
  192. data/lib/kward/tools/datetime.rb +85 -0
  193. data/lib/kward/tools/edit_file.rb +9 -6
  194. data/lib/kward/tools/generate_image.rb +36 -0
  195. data/lib/kward/tools/git_commit.rb +13 -7
  196. data/lib/kward/tools/list_directory.rb +4 -4
  197. data/lib/kward/tools/plugin_tool.rb +41 -0
  198. data/lib/kward/tools/prepare_shell_command.rb +1 -1
  199. data/lib/kward/tools/read_file.rb +7 -6
  200. data/lib/kward/tools/registry.rb +130 -21
  201. data/lib/kward/tools/run_shell_command.rb +10 -8
  202. data/lib/kward/tools/search/code.rb +1 -1
  203. data/lib/kward/tools/summarize_file_structure.rb +5 -5
  204. data/lib/kward/tools/tool_call.rb +4 -1
  205. data/lib/kward/tools/typesafe_evaluate.rb +81 -0
  206. data/lib/kward/tools/workspace_targets.rb +58 -0
  207. data/lib/kward/tools/write_file.rb +9 -6
  208. data/lib/kward/{export_path.rb → transcripts/export_path.rb} +1 -1
  209. data/lib/kward/{markdown_transcript.rb → transcripts/markdown_transcript.rb} +10 -2
  210. data/lib/kward/transcripts/turn_summary_formatter.rb +93 -0
  211. data/lib/kward/transport/contracts.rb +200 -0
  212. data/lib/kward/transport/gateway.rb +81 -36
  213. data/lib/kward/transport/plugin_chat_gateway.rb +3 -2
  214. data/lib/kward/transport.rb +1 -200
  215. data/lib/kward/turn_summary.rb +68 -0
  216. data/lib/kward/version.rb +1 -1
  217. data/lib/kward/{workspace_factory.rb → workspace/factory.rb} +2 -2
  218. data/lib/kward/{git_worktree_manager.rb → workspace/git_worktree_manager.rb} +28 -0
  219. data/lib/kward/{workspace.rb → workspace/workspace.rb} +3 -3
  220. data/lib/main.rb +6 -3
  221. data/templates/default/fulldoc/html/css/kward.css +125 -0
  222. data/templates/default/fulldoc/html/images/kward_screen_1.png +0 -0
  223. data/templates/default/fulldoc/html/setup.rb +1 -1
  224. data/templates/default/layout/html/layout.erb +16 -4
  225. metadata +150 -48
  226. data/lib/kward/pty_transcript_normalizer.rb +0 -93
  227. data/lib/kward/shell_prompt.rb +0 -52
  228. data/lib/kward/tab_driver.rb +0 -90
  229. data/templates/default/fulldoc/html/images/kward_workflow.svg +0 -52
  230. /data/lib/kward/{editor_prompt.rb → cli/editor_prompt.rb} +0 -0
  231. /data/lib/kward/{editor_prompt_session.rb → cli/editor_prompt_session.rb} +0 -0
  232. /data/lib/kward/{diff_view_mode.rb → prompt_interface/editor/diff_view_mode.rb} +0 -0
  233. /data/lib/kward/{editor_mode.rb → prompt_interface/editor/editor_mode.rb} +0 -0
  234. /data/lib/kward/{markdown_code_block.rb → prompt_interface/editor/markdown_code_block.rb} +0 -0
  235. /data/lib/kward/{scratchpad_languages.rb → prompt_interface/editor/scratchpad_languages.rb} +0 -0
  236. /data/lib/kward/{scratchpad_runner.rb → prompt_interface/editor/scratchpad_runner.rb} +0 -0
  237. /data/lib/kward/{detached_run.rb → pty/detached_run.rb} +0 -0
  238. /data/lib/kward/{session_diff.rb → sessions/diff.rb} +0 -0
  239. /data/lib/kward/{session_naming.rb → sessions/naming.rb} +0 -0
  240. /data/lib/kward/{session_trash.rb → sessions/trash.rb} +0 -0
  241. /data/lib/kward/{ansi.rb → terminal/ansi.rb} +0 -0
  242. /data/lib/kward/{terminal_text.rb → terminal/text.rb} +0 -0
  243. /data/lib/kward/{transcript_export.rb → transcripts/transcript_export.rb} +0 -0
  244. /data/lib/kward/{project_files.rb → workspace/files.rb} +0 -0
  245. /data/lib/kward/{path_guard.rb → workspace/path_guard.rb} +0 -0
@@ -3,20 +3,20 @@ require "io/console"
3
3
  require "pathname"
4
4
  require "rbconfig"
5
5
  require "thread"
6
- require_relative "project_files"
6
+ require_relative "workspace/files"
7
7
  require_relative "image_attachments"
8
- require_relative "terminal_image_support"
8
+ require_relative "terminal/image_support"
9
9
  require_relative "prompt_history"
10
10
  require "tty-cursor"
11
11
  require "tty-reader"
12
12
  require "tty-screen"
13
- require_relative "ansi"
14
- require_relative "terminal_sequences"
15
- require_relative "terminal_keys"
16
- require_relative "editor_mode"
17
- require_relative "diff_view_mode"
18
- require_relative "scratchpad_languages"
19
- require_relative "markdown_code_block"
13
+ require_relative "terminal/ansi"
14
+ require_relative "terminal/sequences"
15
+ require_relative "terminal/keys"
16
+ require_relative "prompt_interface/editor/editor_mode"
17
+ require_relative "prompt_interface/editor/diff_view_mode"
18
+ require_relative "prompt_interface/editor/scratchpad_languages"
19
+ require_relative "prompt_interface/editor/markdown_code_block"
20
20
  require_relative "prompt_interface/banner"
21
21
  require_relative "prompt_interface/composer_state"
22
22
  require_relative "prompt_interface/editor/state"
@@ -29,6 +29,7 @@ require_relative "prompt_interface/file_overlay"
29
29
  require_relative "prompt_interface/project_browser"
30
30
  require_relative "prompt_interface/selection_prompt"
31
31
  require_relative "prompt_interface/question_prompt"
32
+ require_relative "prompt_interface/plugin_ui_requests"
32
33
  require_relative "prompt_interface/approval_prompt"
33
34
  require_relative "prompt_interface/git_prompt"
34
35
  require_relative "prompt_interface/overlay_renderer"
@@ -53,6 +54,7 @@ require_relative "prompt_interface/layout"
53
54
  require_relative "prompt_interface/screen"
54
55
  require_relative "prompt_interface/key_handler"
55
56
  require_relative "prompt_interface/runtime_state"
57
+ require_relative "prompt_interface/generated_image_preview"
56
58
 
57
59
  # Namespace for the Kward CLI agent runtime.
58
60
  module Kward
@@ -69,13 +71,14 @@ module Kward
69
71
  class PromptInterface
70
72
  HELP_TEXT = "Enter sends • Shift+Enter newline • / commands • @ files • ↑/↓ history • Ctrl+D exits".freeze
71
73
  BUSY_HELP_TEXT = "Ctrl+C cancels".freeze
72
- SPINNER_FRAMES = %w[· • ● •].freeze
73
- SPINNER_INTERVAL = 0.16
74
+ SPINNER_FRAMES = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
75
+ SPINNER_INTERVAL = 0.1
74
76
  FOOTER_REFRESH_INTERVAL = 1.0
75
77
  COMPOSER_STATUS_REFRESH_INTERVAL = 1.0
76
78
  COMPLETION_DISPLAY_SECONDS = 0.8
77
79
  RESPONSE_ARRIVAL_SECONDS = 0.4
78
80
  BUSY_ELAPSED_DELAY_SECONDS = 2.0
81
+ TRANSCRIPT_COMPOSER_GAP_ROWS = 1
79
82
  COMPOSER_MAX_INPUT_ROWS = 6
80
83
  IMAGE_VIEWER_MAX_ROWS = 8
81
84
  TRANSCRIPT_BUFFER_LIMIT = 200_000
@@ -84,8 +87,10 @@ module Kward
84
87
  include SlashOverlay
85
88
  include FileOverlay
86
89
  include ProjectBrowser
90
+ include GeneratedImagePreview
87
91
  include SelectionPrompt
88
92
  include QuestionPrompt
93
+ include PluginUIRequests
89
94
  include ApprovalPrompt
90
95
  include GitPrompt
91
96
  include OverlayRenderer
@@ -140,6 +145,80 @@ module Kward
140
145
  end
141
146
  end
142
147
 
148
+ # Kward owns keyboard encoding while its tab shortcuts are reserved. Child
149
+ # keyboard-mode mutations must not pop our stack entry or change that encoding.
150
+ # Other controls remain terminal-owned, including streamed OSC/DCS payloads.
151
+ class TerminalHandoffOutput
152
+ MAX_SEQUENCE_BYTES = 4096
153
+
154
+ def initialize(output)
155
+ @output = output
156
+ @pending = +"".b
157
+ @string = false
158
+ @string_escape = false
159
+ end
160
+
161
+ def write(value)
162
+ value = value.to_s.b
163
+ forwarded = +"".b
164
+ value.each_byte do |byte|
165
+ if @string
166
+ forwarded << byte
167
+ @string = false if byte == 0x18 || byte == 0x1a || (@string == 0x5d && byte == 0x07) || (@string_escape && byte == 0x5c)
168
+ @string_escape = byte == 0x1b
169
+ elsif @pending.empty?
170
+ byte == 0x1b ? @pending << byte : forwarded << byte
171
+ elsif byte == 0x1b
172
+ forwarded << @pending << TerminalSequences::CONTROL_SEQUENCE_CANCEL
173
+ @pending = +"\e".b
174
+ elsif byte == 0x18 || byte == 0x1a
175
+ forwarded << @pending << byte
176
+ @pending.clear
177
+ elsif byte < 0x20 || byte == 0x7f
178
+ # C0 controls can execute inside CSI without ending its parameters.
179
+ forwarded << byte
180
+ else
181
+ @pending << byte
182
+ consume_sequence(forwarded)
183
+ end
184
+ end
185
+ @output.write(forwarded) unless forwarded.empty?
186
+ value.bytesize
187
+ end
188
+
189
+ def print(*values)
190
+ values.each { |value| write(value) }
191
+ nil
192
+ end
193
+
194
+ def flush
195
+ @output.flush if @output.respond_to?(:flush)
196
+ end
197
+
198
+ private
199
+
200
+ def consume_sequence(forwarded)
201
+ if @pending.bytesize == 2 && [0x5d, 0x50, 0x5e, 0x5f, 0x58].include?(@pending.getbyte(1))
202
+ @string = @pending.getbyte(1)
203
+ @string_escape = false
204
+ elsif @pending.start_with?("\e[")
205
+ return if @pending.bytesize == 2
206
+ byte = @pending.getbyte(-1)
207
+ return if byte.between?(0x20, 0x3f) && @pending.bytesize < MAX_SEQUENCE_BYTES
208
+ elsif @pending.getbyte(-1).between?(0x20, 0x2f) && @pending.bytesize < MAX_SEQUENCE_BYTES
209
+ return
210
+ end
211
+
212
+ unless TerminalSequences.keyboard_mode_mutation?(@pending)
213
+ forwarded << @pending
214
+ forwarded << TerminalSequences::CONTROL_SEQUENCE_CANCEL if @pending.bytesize >= MAX_SEQUENCE_BYTES
215
+ # Main and alternate screens have independent keyboard mode stacks.
216
+ forwarded << TerminalSequences::KEYBOARD_PROTOCOL_SET if TerminalSequences.keyboard_mode_reset?(@pending)
217
+ end
218
+ @pending.clear
219
+ end
220
+ end
221
+
143
222
  def initialize(input: $stdin, output: $stdout, slash_commands: [], overlay_settings: nil, project_browser_icon_theme: "off", footer: nil, composer_status: nil, busy_help: true, attachment_badges: nil, attachment_parser: nil, banner_message: nil, tab_keybindings: nil, prompt_history: nil, workspace_root: Dir.pwd, editor_mode: nil, editor_mode_source: nil, editor_auto_indent: true, editor_auto_indent_source: nil, editor_auto_close_pairs: true, editor_auto_close_pairs_source: nil, editor_soft_wrap: true, editor_soft_wrap_source: nil, editor_bar_cursor: true, editor_bar_cursor_source: nil, editor_line_numbers: "absolute", editor_line_numbers_source: nil, diff_view: "auto", diff_view_source: nil, editor_runners_source: nil, redraw_handler: nil)
144
223
  @input_io = input
145
224
  @output_io = output
@@ -156,6 +235,7 @@ module Kward
156
235
  @asking = false
157
236
  @busy = false
158
237
  @busy_activity = "thinking"
238
+ @busy_activity_visible = true
159
239
  @busy_started_at = nil
160
240
  @last_busy_elapsed = nil
161
241
  @completion_status = nil
@@ -166,14 +246,14 @@ module Kward
166
246
  @last_spinner_tick = monotonic_now
167
247
  @last_footer_refresh = nil
168
248
  @cached_footer_text = nil
169
- @last_composer_status_refresh = 0.0
249
+ @last_composer_status_refresh = nil
170
250
  @cached_composer_status_text = nil
171
251
  @prompt_label = "You>"
172
252
  @assistant_label = "Assistant"
173
253
  @stream_state = StreamState.new
174
254
  @rendered_rows = 0
175
255
  @last_composer_rows = []
176
- @cursor_rendered_row = 0
256
+ @rendered_composer_cursor = nil
177
257
  @transcript_buffer = TranscriptBuffer.new(limit: TRANSCRIPT_BUFFER_LIMIT)
178
258
  @transcript_viewport_rows = 0
179
259
  @restoring_transcript = false
@@ -284,7 +364,10 @@ module Kward
284
364
 
285
365
  clear_image_viewer_output_locked if image_viewer_active?
286
366
  clear_prompt_for_output_locked
367
+ last_transcript_row = transcript_bottom_row
287
368
  restore_scroll_region_locked
369
+ # Resetting the scroll region homes the cursor on VT terminals.
370
+ move_to_screen(last_transcript_row, 1)
288
371
  disable_editor_mouse_reporting(force: true)
289
372
  print_output_locked(BRACKETED_PASTE_RESTORE)
290
373
  print_output_locked(KEYBOARD_PROTOCOL_RESTORE)
@@ -505,8 +588,8 @@ module Kward
505
588
  editor_open = @mutex.synchronize do
506
589
  if key.nil?
507
590
  resized = handle_resize_locked
508
- footer_refreshed = tick_footer_locked
509
- render_prompt_locked if resized || footer_refreshed
591
+ chrome_changed = tick_composer_chrome_locked
592
+ render_prompt_locked if resized || chrome_changed
510
593
  else
511
594
  result = handle_key(key)
512
595
  action = result if prompt_action_result?(result)
@@ -550,9 +633,10 @@ module Kward
550
633
  @mutex.synchronize do
551
634
  if key.nil?
552
635
  resized = handle_resize_locked
553
- footer_refreshed = tick_footer_locked
636
+ chrome_changed = tick_composer_chrome_locked
554
637
  completion_changed = tick_completion_locked
555
- render_prompt_locked if resized || footer_refreshed || completion_changed
638
+ preview_opened = open_pending_generated_image_locked
639
+ render_prompt_locked if resized || chrome_changed || completion_changed || preview_opened
556
640
  else
557
641
  result = handle_key(key)
558
642
  render_prompt_locked unless result.is_a?(String) || result == EXIT_INPUT || prompt_action_result?(result)
@@ -615,8 +699,8 @@ module Kward
615
699
  @mutex.synchronize do
616
700
  if key.nil?
617
701
  resized = handle_resize_locked
618
- footer_refreshed = tick_footer_locked
619
- render_prompt_locked if resized || footer_refreshed
702
+ chrome_changed = tick_composer_chrome_locked
703
+ render_prompt_locked if resized || chrome_changed
620
704
  else
621
705
  result = handle_select_key(key)
622
706
  result = drain_pending_select_keys_locked(result)
@@ -704,6 +788,7 @@ module Kward
704
788
  input = nil
705
789
  output = nil
706
790
  transition = nil
791
+ keep_view = false
707
792
  @mutex.synchronize do
708
793
  if inline
709
794
  handle_resize_locked
@@ -717,34 +802,51 @@ module Kward
717
802
  print_output_locked(BRACKETED_PASTE_RESTORE)
718
803
  print_output_locked(KEYBOARD_PROTOCOL_RESTORE) unless preserve_tab_keybindings
719
804
  @handoff_input_buffer.clear
805
+ @handoff_escape_deadline = nil
806
+ @handoff_bracketed_paste = false
720
807
  restore_editor_cursor_shape_locked
721
808
  set_cursor_visible_locked(true, force: true)
722
809
  flush_output_locked
723
810
  restore_console_mode_locked
724
811
  input = @input_io
725
- output = @output_io
812
+ output = if preserve_tab_keybindings
813
+ TerminalHandoffOutput.new(@output_io)
814
+ else
815
+ @output_io
816
+ end
726
817
  transition = method(:switch_terminal_handoff_to_exclusive)
727
818
  @terminal_handoff_mode = inline ? :inline : :exclusive
728
819
  @terminal_owner = :child
729
820
  end
730
821
 
731
- yield(input, output, transition)
822
+ yield(input, output, transition, -> { keep_view = true })
732
823
  ensure
733
824
  @mutex.synchronize do
825
+ width, height = screen_size
826
+ keep_view &&= @terminal_handoff_mode == :inline && width == @last_width && height == @last_height
734
827
  @terminal_owner = :kward
735
828
  @terminal_handoff_mode = nil
736
- restore_scroll_region_locked
829
+ print_output_locked(TerminalSequences::CONTROL_SEQUENCE_CANCEL)
830
+ print_output_locked(TerminalSequences::COMPOSER_MODES_RESTORE)
831
+ restore_scroll_region_locked unless keep_view
737
832
  print_output_locked(TerminalSequences::SGR_RESET)
738
833
  enter_raw_mode_locked
739
- print_output_locked(KEYBOARD_PROTOCOL_ENABLE)
834
+ print_output_locked(preserve_tab_keybindings ? TerminalSequences::KEYBOARD_PROTOCOL_SET : KEYBOARD_PROTOCOL_ENABLE)
740
835
  print_output_locked(BRACKETED_PASTE_ENABLE)
741
836
  @handoff_input_buffer.clear
837
+ @handoff_escape_deadline = nil
838
+ @handoff_bracketed_paste = false
742
839
  disable_editor_mouse_reporting(force: true)
743
840
  restore_editor_cursor_shape_locked(force: true)
744
841
  @cursor_visible = nil
745
842
  @last_composer_rows = []
746
- width, height = screen_size
747
- with_synchronized_output_locked { redraw_screen_locked(width: width, height: height) }
843
+ with_synchronized_output_locked do
844
+ if keep_view
845
+ resume_inline_terminal_view_locked(height)
846
+ else
847
+ redraw_screen_locked(width: width, height: height)
848
+ end
849
+ end
748
850
  flush_output_locked
749
851
  end
750
852
  end
@@ -872,11 +974,12 @@ module Kward
872
974
  end
873
975
  end
874
976
 
875
- def begin_busy_input(message = "You>", activity: "thinking")
977
+ def begin_busy_input(message = "You>", activity: "thinking", show_activity: true)
876
978
  start
877
979
  @mutex.synchronize do
878
980
  @prompt_label = message.to_s
879
981
  @busy_activity = normalize_busy_activity(activity)
982
+ @busy_activity_visible = show_activity
880
983
  @completion_status = nil
881
984
  @response_arrival_until = nil
882
985
  self.composer_input = ""
@@ -901,6 +1004,7 @@ module Kward
901
1004
  return false if value == @busy_activity
902
1005
 
903
1006
  @busy_activity = value
1007
+ @image_generation_started_at = value == "Generating image…" ? monotonic_now : nil
904
1008
  render_prompt_locked if @started && @asking && @busy
905
1009
  true
906
1010
  end
@@ -936,6 +1040,7 @@ module Kward
936
1040
  @busy_started_at = nil
937
1041
  @busy = false
938
1042
  @busy_activity = "thinking"
1043
+ @busy_activity_visible = true
939
1044
  @response_arrival_until = nil
940
1045
  @queued_count = 0
941
1046
  @steered_count = 0
@@ -962,6 +1067,10 @@ module Kward
962
1067
  @mutex.synchronize { filter_terminal_handoff_input_locked(chunk) }
963
1068
  end
964
1069
 
1070
+ def flush_terminal_handoff_escape
1071
+ @mutex.synchronize { flush_terminal_handoff_escape_locked }
1072
+ end
1073
+
965
1074
  def poll_input
966
1075
  key = read_key(nonblock: true)
967
1076
  @mutex.synchronize do
@@ -984,9 +1093,10 @@ module Kward
984
1093
  if key.nil?
985
1094
  resized = handle_resize_locked
986
1095
  spun = tick_spinner_locked
987
- footer_refreshed = tick_footer_locked
1096
+ chrome_changed = tick_composer_chrome_locked
988
1097
  completion_changed = tick_completion_locked
989
- render_prompt_locked if resized || spun || footer_refreshed || completion_changed
1098
+ preview_opened = open_pending_generated_image_locked
1099
+ render_prompt_locked if resized || spun || chrome_changed || completion_changed || preview_opened
990
1100
  return nil
991
1101
  end
992
1102
 
@@ -997,7 +1107,7 @@ module Kward
997
1107
 
998
1108
  result = handle_key(key)
999
1109
  render_prompt_locked unless [EXIT_INPUT, CANCEL_INPUT].include?(result) || prompt_action_result?(result)
1000
- [EXIT_INPUT, CANCEL_INPUT].include?(result) ? result : result
1110
+ result
1001
1111
  end
1002
1112
  ensure
1003
1113
  perform_pending_transcript_redraw
@@ -1092,7 +1202,7 @@ module Kward
1092
1202
  @cached_footer_text = nil
1093
1203
  @last_footer_refresh = nil
1094
1204
  @cached_composer_status_text = nil
1095
- @last_composer_status_refresh = 0.0
1205
+ @last_composer_status_refresh = nil
1096
1206
  render_prompt_locked if @started && @asking
1097
1207
  end
1098
1208
  end
@@ -1111,6 +1221,15 @@ module Kward
1111
1221
 
1112
1222
  private
1113
1223
 
1224
+ def resume_inline_terminal_view_locked(height)
1225
+ # Start later transcript output on a blank live row without clearing image placements.
1226
+ move_to_screen(transcript_bottom_row(height), 1)
1227
+ print_output_locked("\r\n")
1228
+ @stream_state.reset
1229
+ render_prompt_locked
1230
+ render_cursor_visibility_locked unless @asking
1231
+ end
1232
+
1114
1233
  def switch_terminal_handoff_to_exclusive
1115
1234
  @mutex.synchronize do
1116
1235
  return unless @terminal_owner == :child && @terminal_handoff_mode == :inline
@@ -11,6 +11,7 @@ module Kward
11
11
  { name: "session", description: "Open saved sessions or name the current session.", argument_hint: "[path]|name [name]" },
12
12
  { name: "resume", description: "Alias for /session.", argument_hint: "[path]" },
13
13
  { name: "rename", description: "Rename the current session.", argument_hint: "<name>" },
14
+ { name: "name", description: "Rename the current session and tab.", argument_hint: "<name>" },
14
15
  { name: "clone", description: "Clone the current session.", argument_hint: "" },
15
16
  { name: "fork", description: "Fork from an earlier prompt into a new session.", argument_hint: "" },
16
17
  { name: "rewind", description: "Revisit an earlier prompt and try a different direction.", argument_hint: "" },
@@ -32,7 +33,7 @@ module Kward
32
33
  { name: "scratchpad", description: "Open an unsaved editor buffer.", argument_hint: "[language|help]" },
33
34
  { name: "pty", description: "Run a command in an interactive PTY passthrough session.", argument_hint: "<command>" },
34
35
  { name: "tab", description: "Manage tabs.", argument_hint: "[1-n|move|close|new|name|worktree]" },
35
- { name: "worktree", description: "Manage the active tab's linked Git worktree.", argument_hint: "[activate|detach|status|merge|merge abort|remove]" },
36
+ { name: "worktree", description: "Manage the active tab's linked Git worktree.", argument_hint: "[activate|detach|status|merge [resolve|continue|abort]|remove]" },
36
37
  { name: "status", description: "Show the current status message.", argument_hint: "" },
37
38
  { name: "stats", description: "Show telemetry logging stats.", argument_hint: "[range]" },
38
39
  { name: "sandbox", description: "Inspect or configure model command sandboxing.", argument_hint: "[status|off|read_only|workspace_write|network allow|network deny]" },
data/lib/kward/prompts.rb CHANGED
@@ -50,7 +50,9 @@ module Kward
50
50
  end
51
51
  skills = ConfigFiles.skills(workspace_root: workspace_root, project_skill_paths: project_skill_paths)
52
52
  sections << prompt_section("Configured skills", skills_prompt(skills), source: skills.empty? ? nil : File.join(ConfigFiles.config_dir, "skills"))
53
- sections << prompt_section(workspace_agents_context_label(workspace_root), workspace_agents_context(workspace_root), source: ConfigFiles.workspace_agents_file?(workspace_root) ? ConfigFiles.workspace_agents_path(workspace_root) : nil)
53
+ unless ConfigFiles.ignore_local_instructions?
54
+ sections << prompt_section(workspace_agents_context_label(workspace_root), workspace_agents_context(workspace_root), source: ConfigFiles.workspace_agents_file?(workspace_root) ? ConfigFiles.workspace_agents_path(workspace_root) : nil)
55
+ end
54
56
  sections.compact
55
57
  end
56
58
 
@@ -88,6 +90,8 @@ module Kward
88
90
  end
89
91
 
90
92
  def workspace_agents_context(workspace_root = Dir.pwd)
93
+ return nil if ConfigFiles.ignore_local_instructions?
94
+
91
95
  if ConfigFiles.enforce_workspace_agents_file?
92
96
  ConfigFiles.workspace_agents_prompt(workspace_root)
93
97
  else
@@ -96,6 +100,8 @@ module Kward
96
100
  end
97
101
 
98
102
  def workspace_agents_prompt(workspace_root = Dir.pwd)
103
+ return nil if ConfigFiles.ignore_local_instructions?
104
+
99
105
  ConfigFiles.workspace_agents_prompt(workspace_root)
100
106
  end
101
107
 
@@ -1,4 +1,4 @@
1
- require_relative "terminal_sequences"
1
+ require_relative "../terminal/sequences"
2
2
 
3
3
  # Namespace for the Kward CLI agent runtime.
4
4
  module Kward
@@ -7,6 +7,7 @@ module Kward
7
7
  # screen-oriented or unknown terminal controls.
8
8
  class AdaptivePtyOutputSink
9
9
  MAX_SEQUENCE_BYTES = 4096
10
+ MAX_KITTY_SEQUENCE_BYTES = 4096 + 512
10
11
  SAFE_CONTROLS = [0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d].freeze
11
12
  TERMINAL_STRING_INTRODUCERS = [0x5d, 0x50, 0x5e, 0x5f, 0x58].freeze
12
13
 
@@ -22,14 +23,18 @@ module Kward
22
23
  @mode = :inline
23
24
  @sequence = +"".b
24
25
  @synchronized_output = false
26
+ @kitty_graphics = false
25
27
  end
26
28
 
27
29
  def write(chunk)
28
30
  value = chunk.to_s.b
29
- capture(value)
30
- return @output.write(value) if exclusive?
31
+ if exclusive?
32
+ capture(value)
33
+ return @output.write(value)
34
+ end
31
35
 
32
36
  write_inline(value)
37
+ value.bytesize
33
38
  end
34
39
 
35
40
  def flush
@@ -54,6 +59,11 @@ module Kward
54
59
  inline? && @sequence.empty?
55
60
  end
56
61
 
62
+ # Images and capability probes belong to the live terminal, not transcript replay.
63
+ def preserve_terminal_view?
64
+ inline? && @kitty_graphics
65
+ end
66
+
57
67
  def pre_input_capture_only?
58
68
  true
59
69
  end
@@ -90,6 +100,11 @@ module Kward
90
100
  track_safe_sequence(@sequence)
91
101
  safe_output << @sequence
92
102
  @sequence.clear
103
+ elsif status == :kitty
104
+ flush_safe_output(safe_output)
105
+ @output.write(@sequence)
106
+ @sequence.clear
107
+ @kitty_graphics = true
93
108
  elsif status == :exclusive
94
109
  flush_safe_output(safe_output)
95
110
  remainder = value.byteslice((index + 1)..).to_s.b
@@ -104,10 +119,11 @@ module Kward
104
119
  end
105
120
 
106
121
  def sequence_status
107
- return :exclusive if @sequence.bytesize > MAX_SEQUENCE_BYTES
108
122
  return :pending if @sequence.bytesize == 1
109
123
 
110
124
  second = @sequence.getbyte(1)
125
+ return kitty_sequence_status if second == 0x5f # APC
126
+ return :exclusive if @sequence.bytesize > MAX_SEQUENCE_BYTES
111
127
  return csi_status if second == "[".ord
112
128
  return :exclusive if TERMINAL_STRING_INTRODUCERS.include?(second)
113
129
  return escape_intermediate_status if second.between?(0x20, 0x2f)
@@ -115,6 +131,22 @@ module Kward
115
131
  :exclusive
116
132
  end
117
133
 
134
+ def kitty_sequence_status
135
+ return :pending if @sequence.bytesize == 2
136
+ return :exclusive unless @sequence.start_with?(TerminalSequences::KITTY_GRAPHICS_PREFIX)
137
+ return :exclusive if @sequence.bytesize > MAX_KITTY_SEQUENCE_BYTES
138
+
139
+ if @sequence.end_with?("\e\\")
140
+ return TerminalSequences::KITTY_GRAPHICS_COMMAND.match?(@sequence) ? :kitty : :exclusive
141
+ end
142
+
143
+ # A Kitty payload is base64; no other control can run inside it.
144
+ last = @sequence.getbyte(-1)
145
+ return :exclusive if @sequence.getbyte(-2) == 0x1b || (last < 0x20 && last != 0x1b)
146
+
147
+ :pending
148
+ end
149
+
118
150
  def csi_status
119
151
  return :pending if @sequence.bytesize == 2
120
152
 
@@ -139,7 +171,7 @@ module Kward
139
171
  value.match?(/\A\e\[[0-9;]*[CDG`]\z/) ||
140
172
  value.match?(/\A\e\[\?25[hl]\z/) ||
141
173
  value.match?(/\A\e\[\?(?:2004|2026)[hl]\z/) ||
142
- value.match?(/\A\e\[[0-9;]* q\z/)
174
+ value.match?(/\A\e\[[0-9;]* q\z/) || TerminalSequences::DEVICE_QUERY.match?(value)
143
175
  end
144
176
 
145
177
  def track_safe_sequence(sequence)
@@ -157,6 +189,7 @@ module Kward
157
189
  def flush_safe_output(value)
158
190
  return if value.empty?
159
191
 
192
+ capture(value)
160
193
  @output.write(value)
161
194
  value.clear
162
195
  end
@@ -165,6 +198,7 @@ module Kward
165
198
  end_synchronized_output
166
199
  @on_exclusive.call
167
200
  @mode = :exclusive
201
+ capture(value)
168
202
  @output.write(value) unless value.empty?
169
203
  end
170
204
 
@@ -1,8 +1,8 @@
1
1
  require "io/console"
2
2
  require "pty"
3
3
  require "timeout"
4
- require_relative "local_pty_command_runner"
5
- require_relative "pty_output_sink"
4
+ require_relative "local_pty_runner"
5
+ require_relative "output_sink"
6
6
  require_relative "detached_run"
7
7
 
8
8
  # Namespace for the Kward CLI agent runtime.
@@ -17,7 +17,6 @@ module Kward
17
17
 
18
18
  def initialize(window_size_provider: nil)
19
19
  @window_size_provider = window_size_provider
20
- @window_size = nil
21
20
  end
22
21
 
23
22
  def run(*command, env: {}, cwd: Dir.pwd, input: $stdin, sink:, tab_action_handler: nil, on_detach: nil)
@@ -28,6 +27,7 @@ module Kward
28
27
  forwarded = false
29
28
  detached = nil
30
29
 
30
+ @window_size = nil
31
31
  update_window_size(reader, pid)
32
32
  with_raw_input(input) do
33
33
  input_forwarded, tab_action = drain_initial_input(input, writer, sink, tab_action_handler: tab_action_handler)
@@ -117,12 +117,12 @@ module Kward
117
117
  readers << input if input_open
118
118
  readable = IO.select(readers, nil, nil, 0.02)&.first || []
119
119
  forward_pty_output(reader, sink) if readable.include?(reader)
120
- if input_open && readable.include?(input)
121
- input_open, forwarded, tab_action = forward_input(input, writer, sink, tab_action_handler: tab_action_handler)
122
- input_forwarded ||= forwarded
123
- return [nil, input_forwarded, tab_action] if tab_action && on_detach
124
- return [terminate_and_reap(pid), input_forwarded, tab_action] if tab_action
125
- end
120
+ input_open, forwarded, tab_action = forward_input(
121
+ input, writer, sink, input_open: input_open, readable: readable.include?(input), tab_action_handler: tab_action_handler
122
+ )
123
+ input_forwarded ||= forwarded
124
+ return [nil, input_forwarded, tab_action] if tab_action && on_detach
125
+ return [terminate_and_reap(pid), input_forwarded, tab_action] if tab_action
126
126
 
127
127
  status = finished_status(pid)
128
128
  next unless status
@@ -183,31 +183,23 @@ module Kward
183
183
  nil
184
184
  end
185
185
 
186
- def forward_input(input, writer, sink, tab_action_handler: nil)
187
- chunk = input.read_nonblock(READ_SIZE, exception: false)
188
- return [false, false, nil] if chunk.nil?
189
- return [true, false, nil] if chunk == :wait_readable
190
-
191
- filtered = tab_action_handler&.call(chunk)
192
- if filtered
193
- tab_action = filtered[:tab_action]
194
- chunk = filtered[:input].to_s
195
- if tab_action
196
- unless chunk.empty?
197
- sink.input_forwarded if sink.respond_to?(:input_forwarded)
198
- writer.write(chunk)
199
- writer.flush
200
- return [true, true, tab_action]
201
- end
202
- return [true, false, tab_action]
203
- end
186
+ def forward_input(input, writer, sink, input_open:, readable:, tab_action_handler:)
187
+ chunk = readable ? input.read_nonblock(READ_SIZE, exception: false) : :wait_readable
188
+ input_open = false if chunk.nil?
189
+ if chunk.nil? || chunk == :wait_readable
190
+ chunk = tab_action_handler.flush_pending_escape if tab_action_handler.respond_to?(:flush_pending_escape)
191
+ return [input_open, false, nil] unless chunk.is_a?(String)
192
+ else
193
+ filtered = tab_action_handler&.call(chunk)
194
+ chunk = filtered[:input].to_s if filtered
204
195
  end
205
- return [true, false, nil] if chunk.empty?
196
+ tab_action = filtered&.fetch(:tab_action, nil)
197
+ return [input_open, false, tab_action] if chunk.empty?
206
198
 
207
199
  sink.input_forwarded if sink.respond_to?(:input_forwarded)
208
200
  writer.write(chunk)
209
201
  writer.flush
210
- [true, true, nil]
202
+ [input_open, true, tab_action]
211
203
  rescue Errno::EIO, Errno::EPIPE, IOError
212
204
  [false, false, nil]
213
205
  end
@@ -216,8 +208,8 @@ module Kward
216
208
  window_size = terminal_window_size
217
209
  return if window_size == @window_size
218
210
 
219
- @window_size = window_size
220
211
  reader.winsize = window_size
212
+ @window_size = window_size
221
213
  signal_process("WINCH", -pid) || signal_process("WINCH", pid)
222
214
  rescue StandardError
223
215
  nil
@@ -1,7 +1,7 @@
1
1
  require "open3"
2
2
  require "thread"
3
3
  require "timeout"
4
- require_relative "cancellation"
4
+ require_relative "../cancellation"
5
5
 
6
6
  # Namespace for the Kward CLI agent runtime.
7
7
  module Kward
@@ -1,7 +1,7 @@
1
1
  require "io/console"
2
2
  require "pty"
3
3
  require "timeout"
4
- require_relative "cancellation"
4
+ require_relative "../cancellation"
5
5
  require_relative "local_command_runner"
6
6
 
7
7
  # Namespace for the Kward CLI agent runtime.
@@ -52,7 +52,8 @@ module Kward
52
52
  readable, = IO.select([reader], nil, nil, 0.02)
53
53
  next unless readable
54
54
 
55
- chunk = read_chunk(reader)
55
+ chunk = reader.read_nonblock(READ_SIZE, exception: false)
56
+ next if chunk == :wait_readable
56
57
  break if chunk.nil?
57
58
 
58
59
  chunk = normalize_line_endings(chunk)
@@ -102,13 +103,6 @@ module Kward
102
103
  [DEFAULT_ROWS, DEFAULT_COLUMNS]
103
104
  end
104
105
 
105
- def read_chunk(reader)
106
- reader.read_nonblock(READ_SIZE, exception: false).tap do |chunk|
107
- return nil if chunk.nil?
108
- return nil if chunk == :wait_readable
109
- end
110
- end
111
-
112
106
  def normalize_line_endings(chunk)
113
107
  chunk.gsub("\r\r\n", "\n").gsub("\r\n", "\n")
114
108
  end