swarm_cli 3.0.0.alpha2 → 3.0.0.alpha4
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/lib/swarm_cli/v3/cli.rb +46 -3
- data/lib/swarm_cli/v3/display.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4a46dc28301d9944d4780989720a455736cdd45f5f770c7ac1b3d0d44e4740e
|
|
4
|
+
data.tar.gz: daf3e6f7887eef22b502e74da0c527f19c10c99e4a99da7441367cc131ad62bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a9f88d5825f7c5d2ac65d5c891d5f44c35902fb54ba1caf691c8a79a22ecccce5957a6c8e03144ab51077f34b02c440afd6f79ff596f27cdddef5a1c30aad10
|
|
7
|
+
data.tar.gz: c77b804edb2b3c2f348630424ad803d4d1da6d047f0717ba74d593f3989f0a0fe854407163feab417bf7816a96b37fafc852e23133bfc3789becd5e0653e9d17
|
data/lib/swarm_cli/v3/cli.rb
CHANGED
|
@@ -55,18 +55,45 @@ module SwarmCLI
|
|
|
55
55
|
|
|
56
56
|
# Expand @file mentions to include file contents.
|
|
57
57
|
# This is a public utility method that can be used for testing.
|
|
58
|
+
# Uses Read tool for consistent file handling including documents.
|
|
58
59
|
#
|
|
59
60
|
# @param prompt [String] the prompt text with @file mentions
|
|
60
61
|
# @param display [Display, nil] optional display to show read status
|
|
61
62
|
# @return [String] the expanded prompt with file contents
|
|
62
63
|
def expand_file_mentions(prompt, display: nil)
|
|
64
|
+
# Create Read tool for consistent file handling (including documents)
|
|
65
|
+
read_tracker = SwarmSDK::V3::Tools::ReadTracker.new
|
|
66
|
+
read_tool = SwarmSDK::V3::Tools::Read.new(
|
|
67
|
+
agent_name: :cli,
|
|
68
|
+
directory: Dir.pwd,
|
|
69
|
+
read_tracker: read_tracker,
|
|
70
|
+
)
|
|
71
|
+
|
|
63
72
|
prompt.gsub(%r{@([\w/.~-]+)}) do |match|
|
|
64
73
|
path = Regexp.last_match(1)
|
|
65
74
|
|
|
66
75
|
if File.file?(path)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
result = read_tool.execute(file_path: path)
|
|
77
|
+
|
|
78
|
+
# Handle result types
|
|
79
|
+
case result
|
|
80
|
+
when RubyLLM::Content
|
|
81
|
+
# Document with images
|
|
82
|
+
display&.agent_print(ANSIColors.dim(" \u{1F4C4} Read @#{path} (with images)"))
|
|
83
|
+
"\n\n<file path=\"#{path}\">\n#{result.text}\n</file>\n"
|
|
84
|
+
when /^<system-reminder>/
|
|
85
|
+
# Missing gem
|
|
86
|
+
display&.agent_print(ANSIColors.yellow(" \u26A0\uFE0F @#{path} requires gem"))
|
|
87
|
+
match # Keep original
|
|
88
|
+
when /^Error:/
|
|
89
|
+
# Conversion error
|
|
90
|
+
display&.agent_print(ANSIColors.yellow(" \u26A0\uFE0F Could not read @#{path}"))
|
|
91
|
+
match # Keep original
|
|
92
|
+
else
|
|
93
|
+
# Text content
|
|
94
|
+
display&.agent_print(ANSIColors.dim(" \u{1F4C4} Read @#{path}"))
|
|
95
|
+
"\n\n<file path=\"#{path}\">\n#{result}\n</file>\n"
|
|
96
|
+
end
|
|
70
97
|
elsif File.directory?(path)
|
|
71
98
|
entries = Dir.children(path).sort
|
|
72
99
|
display&.agent_print(ANSIColors.dim(" \u{1F4C2} Read @#{path}/ (#{entries.size} entries)"))
|
|
@@ -396,6 +423,8 @@ module SwarmCLI
|
|
|
396
423
|
# Auto-trigger autocomplete if in auto mode
|
|
397
424
|
if @autocomplete_mode == :auto
|
|
398
425
|
handle_autocomplete_trigger(agent, display)
|
|
426
|
+
# Auto-close dropdown if exact unique match
|
|
427
|
+
auto_close_on_exact_match(display)
|
|
399
428
|
elsif display.dropdown_active?
|
|
400
429
|
# Manual mode: close dropdown on typing
|
|
401
430
|
display.dropdown_close
|
|
@@ -407,6 +436,20 @@ module SwarmCLI
|
|
|
407
436
|
end
|
|
408
437
|
end
|
|
409
438
|
|
|
439
|
+
# Auto-close dropdown if buffer exactly matches a unique result.
|
|
440
|
+
# This prevents needing to press Enter twice (once to accept, once to submit).
|
|
441
|
+
def auto_close_on_exact_match(display)
|
|
442
|
+
return unless display.dropdown_active?
|
|
443
|
+
|
|
444
|
+
buffer = display.current_buffer.strip
|
|
445
|
+
dropdown_items = display.dropdown_items || []
|
|
446
|
+
|
|
447
|
+
# If buffer exactly matches the only item, auto-close dropdown
|
|
448
|
+
if dropdown_items.size == 1 && dropdown_items.first == buffer
|
|
449
|
+
display.dropdown_close
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
410
453
|
# Trigger autocomplete: extract word, find matches, show dropdown
|
|
411
454
|
def handle_autocomplete_trigger(agent, display)
|
|
412
455
|
buffer = display.current_buffer
|
data/lib/swarm_cli/v3/display.rb
CHANGED
|
@@ -395,6 +395,13 @@ module SwarmCLI
|
|
|
395
395
|
@mutex.synchronize { !@dropdown.nil? }
|
|
396
396
|
end
|
|
397
397
|
|
|
398
|
+
# Get dropdown items if dropdown is active.
|
|
399
|
+
#
|
|
400
|
+
# @return [Array<String>, nil] dropdown items or nil if no dropdown
|
|
401
|
+
def dropdown_items
|
|
402
|
+
@mutex.synchronize { @dropdown&.items }
|
|
403
|
+
end
|
|
404
|
+
|
|
398
405
|
# Return a copy of the current input buffer (thread-safe).
|
|
399
406
|
#
|
|
400
407
|
# @return [String]
|