rubik 0.6.0 → 0.7.1
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/ATTRIBUTION.md +1 -1
- data/CHANGELOG.md +85 -1
- data/lib/rubik/benchmark/runner.rb +3 -0
- data/lib/rubik/config/defaults.rb +9 -0
- data/lib/rubik/context/index.rb +76 -42
- data/lib/rubik/context/root_heuristics.rb +93 -0
- data/lib/rubik/context/scanner.rb +33 -5
- data/lib/rubik/context.rb +1 -0
- data/lib/rubik/diagnostics/collector.rb +8 -2
- data/lib/rubik/lsp/client.rb +26 -6
- data/lib/rubik/lsp/manager.rb +24 -6
- data/lib/rubik/orchestrator/lsp_feedback.rb +2 -1
- data/lib/rubik/orchestrator/step_executor.rb +11 -1
- data/lib/rubik/orchestrator/subagent/tool_dispatch.rb +10 -1
- data/lib/rubik/orchestrator/tool_timeout.rb +193 -0
- data/lib/rubik/repl/command_context.rb +6 -0
- data/lib/rubik/repl/commands/agent_context.rb +17 -1
- data/lib/rubik/repl/commands/lsp.rb +13 -1
- data/lib/rubik/repl/composition.rb +2 -1
- data/lib/rubik/repl/lifecycle.rb +51 -1
- data/lib/rubik/repl/shell.rb +1 -0
- data/lib/rubik/runtime/context.rb +12 -14
- data/lib/rubik/runtime/discovery.rb +1 -0
- data/lib/rubik/tools/builtins/files.rb +24 -5
- data/lib/rubik/tools/builtins/grep.rb +54 -31
- data/lib/rubik/tools/builtins/lsp.rb +127 -110
- data/lib/rubik/tools/catalog.rb +1 -1
- data/lib/rubik/tools/index_messages.rb +38 -0
- data/lib/rubik/tools/native_search.rb +14 -5
- data/lib/rubik/tools/registry.rb +6 -5
- data/lib/rubik/version.rb +1 -1
- metadata +4 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../base"
|
|
4
4
|
require_relative "../../coeffects"
|
|
5
|
+
require_relative "../index_messages"
|
|
5
6
|
require_relative "../output"
|
|
6
7
|
require_relative "../native_search"
|
|
7
8
|
require_relative "../diagnostic_reporter"
|
|
@@ -30,6 +31,10 @@ module Rubik
|
|
|
30
31
|
required: ["query"]
|
|
31
32
|
}
|
|
32
33
|
)
|
|
34
|
+
# Honest not-ready answer: an empty index means "nothing searched
|
|
35
|
+
# yet", not "no matches".
|
|
36
|
+
INDEX_NOT_READY_MESSAGE = "#{IndexMessages::INDEX_NOT_READY_PREFIX}" \
|
|
37
|
+
"search with run_command (e.g. `rg` / `grep`) directly.".freeze
|
|
33
38
|
def initialize(buffer_manager = nil, context_index = nil, root_dir: Dir.pwd, runtime_context: nil, context: nil, config: nil)
|
|
34
39
|
super(DECLARATION)
|
|
35
40
|
@buffer_manager = buffer_manager
|
|
@@ -72,28 +77,53 @@ module Rubik
|
|
|
72
77
|
regex = regex_for(query, case_sensitive)
|
|
73
78
|
|
|
74
79
|
matches = try_native_search(query, path_filter, ext_filter, case_sensitive, max_results, regex)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
scope_note = nil
|
|
81
|
+
if matches.nil?
|
|
82
|
+
# Tools never scan: an absent or empty index answers honestly.
|
|
83
|
+
idx = context_index
|
|
84
|
+
return ToolOutput.error(IndexMessages::INDEX_UNAVAILABLE_MESSAGE) if idx.nil?
|
|
85
|
+
|
|
86
|
+
if idx.files.empty?
|
|
87
|
+
buf = buffer_manager
|
|
88
|
+
dirty = buf&.dirty_files ? buf.dirty_files.keys : []
|
|
89
|
+
scoped = dirty.select { |f| pass_path?(f, path_filter) && pass_extension?(f, ext_filter) }
|
|
90
|
+
return ToolOutput.error(INDEX_NOT_READY_MESSAGE) if scoped.empty?
|
|
91
|
+
|
|
92
|
+
# Memory-only search: the disk was not scanned, so hits and
|
|
93
|
+
# no-hits must both disclose that scope.
|
|
94
|
+
hits = ruby_search(path_filter, ext_filter, regex, max_results)
|
|
95
|
+
scope_note = "Searched only the #{scoped.size} in-memory dirty buffer file(s) — the context index is empty, " \
|
|
96
|
+
"the disk was not searched."
|
|
97
|
+
return ToolOutput.error("#{INDEX_NOT_READY_MESSAGE} #{scope_note} No matches there.") if hits.empty?
|
|
98
|
+
|
|
99
|
+
matches = hits
|
|
93
100
|
end
|
|
94
|
-
lines << "... [Grep output capped at #{MAX_OUTPUT_CHARS / 1024}KB to protect context window. Narrow search via 'path' or 'extension']" if capped
|
|
95
|
-
lines.join("\n")
|
|
96
101
|
end
|
|
102
|
+
matches ||= ruby_search(path_filter, ext_filter, regex, max_results)
|
|
103
|
+
|
|
104
|
+
result = if matches.empty?
|
|
105
|
+
"No matching lines found for '#{query}'.#{" (path filter: '#{path_filter}')" unless path_filter.empty?}"
|
|
106
|
+
else
|
|
107
|
+
lines = ["Found #{matches.size} match(es) for '#{query}':"]
|
|
108
|
+
total_chars = 0
|
|
109
|
+
capped = false
|
|
110
|
+
matches.each do |m|
|
|
111
|
+
content = sanitize_line_content(m[:content].to_s)
|
|
112
|
+
entry = "#{m[:file]}:#{m[:line]}: #{content}"
|
|
113
|
+
if (total_chars + entry.length) > MAX_OUTPUT_CHARS
|
|
114
|
+
capped = true
|
|
115
|
+
break
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
lines << entry
|
|
119
|
+
total_chars += entry.length
|
|
120
|
+
end
|
|
121
|
+
lines << "... [Grep output capped at #{MAX_OUTPUT_CHARS / 1024}KB to protect context window. Narrow search via 'path' or 'extension']" if capped
|
|
122
|
+
lines.join("\n")
|
|
123
|
+
end
|
|
124
|
+
note = IndexMessages.note_for(context_index)
|
|
125
|
+
result = "#{result}#{note}" if note
|
|
126
|
+
scope_note ? "#{scope_note}\n#{result}" : result
|
|
97
127
|
rescue Errno::EACCES => e
|
|
98
128
|
ToolOutput.error(DiagnosticReporter.render_permission_denied(path_filter.empty? ? @root_dir : path_filter, operation: "read", reason: e.message))
|
|
99
129
|
rescue Rubik::Buffer::InvalidPathError
|
|
@@ -150,18 +180,11 @@ module Rubik
|
|
|
150
180
|
(native + memory).sort_by { |m| [m[:file], m[:line]] }.first(max_results)
|
|
151
181
|
end
|
|
152
182
|
|
|
153
|
-
# Pure-Ruby search over the context index
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
# strings otherwise — while the per-file line iteration avoids
|
|
157
|
-
# materializing a line array.
|
|
183
|
+
# Pure-Ruby search over the context index; buffer.read when a buffer
|
|
184
|
+
# manager exists, streamed lines otherwise. Callers guarantee a
|
|
185
|
+
# non-nil, non-empty index (execute refuses otherwise).
|
|
158
186
|
def ruby_search(path_filter, ext_filter, regex, max_results)
|
|
159
|
-
|
|
160
|
-
files = if idx
|
|
161
|
-
idx.files.empty? ? idx.full_scan : idx.files
|
|
162
|
-
else
|
|
163
|
-
Rubik::Context::Scanner.new(root_dir: @root_dir, native: @config&.fetch("tools.native")).scan
|
|
164
|
-
end
|
|
187
|
+
files = context_index.files
|
|
165
188
|
|
|
166
189
|
all_file_keys = files.keys
|
|
167
190
|
all_file_keys = (all_file_keys + buffer_manager.dirty_files.keys).uniq if buffer_manager&.dirty_files
|
|
@@ -3,12 +3,57 @@
|
|
|
3
3
|
require_relative "../base"
|
|
4
4
|
require_relative "../../coeffects"
|
|
5
5
|
require_relative "../output"
|
|
6
|
+
require_relative "../../platform"
|
|
6
7
|
|
|
7
8
|
module Rubik
|
|
8
9
|
module Tools
|
|
9
|
-
class
|
|
10
|
-
|
|
10
|
+
class BaseLSPTool < BaseTool
|
|
11
|
+
REQUIRES = [Rubik::Coeffects::LSP_MANAGER].freeze
|
|
11
12
|
|
|
13
|
+
attr_reader :lsp_manager, :buffer_manager, :runtime_context
|
|
14
|
+
|
|
15
|
+
def initialize(declaration, lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
|
|
16
|
+
super(declaration)
|
|
17
|
+
@lsp_manager = lsp_manager
|
|
18
|
+
@buffer_manager = buffer_manager || buffer_mgr
|
|
19
|
+
@runtime_context = runtime_context || context
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def effective_lsp_manager
|
|
23
|
+
Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::LSP_MANAGER, @lsp_manager)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def effective_buffer_manager
|
|
27
|
+
@buffer_manager || Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::BUFFER_MANAGER, nil)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def buffer_dirty?(path)
|
|
33
|
+
bm = effective_buffer_manager
|
|
34
|
+
return false unless bm && !path.to_s.empty?
|
|
35
|
+
|
|
36
|
+
if bm.respond_to?(:dirty?)
|
|
37
|
+
begin
|
|
38
|
+
bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
|
|
39
|
+
rescue ArgumentError
|
|
40
|
+
bm.dirty?
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
false
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def append_buffer_tip(msg, path)
|
|
48
|
+
return msg unless buffer_dirty?(path)
|
|
49
|
+
|
|
50
|
+
tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
|
|
51
|
+
"Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
|
|
52
|
+
"#{msg}#{tip}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class LSPDiagnosticsTool < BaseLSPTool
|
|
12
57
|
DECLARATION = Declaration.new(
|
|
13
58
|
name: "lsp_diagnostics", aliases: ["get_diagnostics", "diagnostics"],
|
|
14
59
|
description: "Get real-time compiler and linter diagnostics (errors, warnings) for a file or all active project files via LSP",
|
|
@@ -20,26 +65,22 @@ module Rubik
|
|
|
20
65
|
}
|
|
21
66
|
}
|
|
22
67
|
)
|
|
23
|
-
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil)
|
|
24
|
-
super(DECLARATION)
|
|
25
|
-
@lsp_manager = lsp_manager
|
|
26
|
-
@buffer_manager = buffer_manager || buffer_mgr
|
|
27
|
-
end
|
|
28
68
|
|
|
29
|
-
def
|
|
30
|
-
|
|
69
|
+
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
|
|
70
|
+
super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
|
|
31
71
|
end
|
|
32
72
|
|
|
33
73
|
def execute(args = {})
|
|
34
|
-
|
|
35
|
-
return ToolOutput.error("LSP is
|
|
74
|
+
mgr = effective_lsp_manager
|
|
75
|
+
return ToolOutput.error("LSP manager is not connected.") unless mgr
|
|
76
|
+
return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
|
|
36
77
|
|
|
37
78
|
path = (args["file_path"] || args[:file_path] || "").to_s.strip
|
|
38
79
|
bm = effective_buffer_manager
|
|
39
|
-
|
|
80
|
+
mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
|
|
40
81
|
|
|
41
82
|
if path.empty?
|
|
42
|
-
all =
|
|
83
|
+
all = mgr.all_diagnostic_snapshots
|
|
43
84
|
total_issues = all.values.sum { |snapshot| snapshot[:diagnostics].size }
|
|
44
85
|
pending = all.values.count { |snapshot| snapshot[:state] == :pending }
|
|
45
86
|
unversioned = all.values.count { |snapshot| snapshot[:state] == :unversioned }
|
|
@@ -74,7 +115,11 @@ module Rubik
|
|
|
74
115
|
lines.join("\n")
|
|
75
116
|
end
|
|
76
117
|
else
|
|
77
|
-
snapshot =
|
|
118
|
+
snapshot = if mgr.respond_to?(:wait_for_diagnostics)
|
|
119
|
+
mgr.wait_for_diagnostics(path, timeout: 0.5)
|
|
120
|
+
else
|
|
121
|
+
mgr.diagnostics_snapshot_for(path)
|
|
122
|
+
end
|
|
78
123
|
diags = snapshot[:diagnostics]
|
|
79
124
|
if diags.empty?
|
|
80
125
|
message = case snapshot[:state]
|
|
@@ -107,36 +152,9 @@ module Rubik
|
|
|
107
152
|
end
|
|
108
153
|
end
|
|
109
154
|
end
|
|
110
|
-
|
|
111
|
-
private
|
|
112
|
-
|
|
113
|
-
def buffer_dirty?(path)
|
|
114
|
-
bm = effective_buffer_manager
|
|
115
|
-
return false unless bm && !path.to_s.empty?
|
|
116
|
-
|
|
117
|
-
if bm.respond_to?(:dirty?)
|
|
118
|
-
begin
|
|
119
|
-
bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
|
|
120
|
-
rescue ArgumentError
|
|
121
|
-
bm.dirty?
|
|
122
|
-
end
|
|
123
|
-
else
|
|
124
|
-
false
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def append_buffer_tip(msg, path)
|
|
129
|
-
return msg unless buffer_dirty?(path)
|
|
130
|
-
|
|
131
|
-
tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
|
|
132
|
-
"Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
|
|
133
|
-
"#{msg}#{tip}"
|
|
134
|
-
end
|
|
135
155
|
end
|
|
136
156
|
|
|
137
|
-
class LSPHoverTool <
|
|
138
|
-
attr_reader :lsp_manager, :buffer_manager
|
|
139
|
-
|
|
157
|
+
class LSPHoverTool < BaseLSPTool
|
|
140
158
|
DECLARATION = Declaration.new(
|
|
141
159
|
name: "lsp_hover", aliases: ["get_hover", "hover"],
|
|
142
160
|
description: "Get compiler-level type signature, docstring, and symbol details at a specific line and character position via LSP",
|
|
@@ -151,19 +169,15 @@ module Rubik
|
|
|
151
169
|
required: ["file_path", "line", "character"]
|
|
152
170
|
}
|
|
153
171
|
)
|
|
154
|
-
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil)
|
|
155
|
-
super(DECLARATION)
|
|
156
|
-
@lsp_manager = lsp_manager
|
|
157
|
-
@buffer_manager = buffer_manager || buffer_mgr
|
|
158
|
-
end
|
|
159
172
|
|
|
160
|
-
def
|
|
161
|
-
|
|
173
|
+
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
|
|
174
|
+
super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
|
|
162
175
|
end
|
|
163
176
|
|
|
164
177
|
def execute(args = {})
|
|
165
|
-
|
|
166
|
-
return ToolOutput.error("LSP is
|
|
178
|
+
mgr = effective_lsp_manager
|
|
179
|
+
return ToolOutput.error("LSP manager is not connected.") unless mgr
|
|
180
|
+
return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
|
|
167
181
|
|
|
168
182
|
path = (args["file_path"] || args[:file_path]).to_s.strip
|
|
169
183
|
line = (args["line"] || args[:line]).to_i
|
|
@@ -173,9 +187,9 @@ module Rubik
|
|
|
173
187
|
return ToolOutput.error("Line number must be >= 1.") if line < 1
|
|
174
188
|
|
|
175
189
|
bm = effective_buffer_manager
|
|
176
|
-
|
|
190
|
+
mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
|
|
177
191
|
|
|
178
|
-
res =
|
|
192
|
+
res = mgr.hover(path, [line - 1, 0].max, [char - 1, 0].max)
|
|
179
193
|
if res[:ok]
|
|
180
194
|
contents = res.dig(:result, "contents")
|
|
181
195
|
if contents.nil? || contents.empty?
|
|
@@ -191,36 +205,9 @@ module Rubik
|
|
|
191
205
|
ToolOutput.error("LSP Hover failed: #{res[:error]}")
|
|
192
206
|
end
|
|
193
207
|
end
|
|
194
|
-
|
|
195
|
-
private
|
|
196
|
-
|
|
197
|
-
def buffer_dirty?(path)
|
|
198
|
-
bm = effective_buffer_manager
|
|
199
|
-
return false unless bm && !path.to_s.empty?
|
|
200
|
-
|
|
201
|
-
if bm.respond_to?(:dirty?)
|
|
202
|
-
begin
|
|
203
|
-
bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
|
|
204
|
-
rescue ArgumentError
|
|
205
|
-
bm.dirty?
|
|
206
|
-
end
|
|
207
|
-
else
|
|
208
|
-
false
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def append_buffer_tip(msg, path)
|
|
213
|
-
return msg unless buffer_dirty?(path)
|
|
214
|
-
|
|
215
|
-
tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
|
|
216
|
-
"Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
|
|
217
|
-
"#{msg}#{tip}"
|
|
218
|
-
end
|
|
219
208
|
end
|
|
220
209
|
|
|
221
|
-
class LSPDefinitionTool <
|
|
222
|
-
attr_reader :lsp_manager, :buffer_manager
|
|
223
|
-
|
|
210
|
+
class LSPDefinitionTool < BaseLSPTool
|
|
224
211
|
DECLARATION = Declaration.new(
|
|
225
212
|
name: "lsp_definition", aliases: ["goto_definition", "definition"],
|
|
226
213
|
description: "Jump to exact type-safe declaration and definition location of a symbol at line/character position via LSP",
|
|
@@ -235,19 +222,15 @@ module Rubik
|
|
|
235
222
|
required: ["file_path", "line", "character"]
|
|
236
223
|
}
|
|
237
224
|
)
|
|
238
|
-
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil)
|
|
239
|
-
super(DECLARATION)
|
|
240
|
-
@lsp_manager = lsp_manager
|
|
241
|
-
@buffer_manager = buffer_manager || buffer_mgr
|
|
242
|
-
end
|
|
243
225
|
|
|
244
|
-
def
|
|
245
|
-
|
|
226
|
+
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
|
|
227
|
+
super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
|
|
246
228
|
end
|
|
247
229
|
|
|
248
230
|
def execute(args = {})
|
|
249
|
-
|
|
250
|
-
return ToolOutput.error("LSP is
|
|
231
|
+
mgr = effective_lsp_manager
|
|
232
|
+
return ToolOutput.error("LSP manager is not connected.") unless mgr
|
|
233
|
+
return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
|
|
251
234
|
|
|
252
235
|
path = (args["file_path"] || args[:file_path]).to_s.strip
|
|
253
236
|
line = (args["line"] || args[:line]).to_i
|
|
@@ -257,9 +240,9 @@ module Rubik
|
|
|
257
240
|
return ToolOutput.error("Line number must be >= 1.") if line < 1
|
|
258
241
|
|
|
259
242
|
bm = effective_buffer_manager
|
|
260
|
-
|
|
243
|
+
mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
|
|
261
244
|
|
|
262
|
-
res =
|
|
245
|
+
res = mgr.definition(path, [line - 1, 0].max, [char - 1, 0].max)
|
|
263
246
|
if res[:ok]
|
|
264
247
|
result = res[:result]
|
|
265
248
|
if result.nil? || (result.is_a?(Array) && result.empty?)
|
|
@@ -269,7 +252,7 @@ module Rubik
|
|
|
269
252
|
lines = ["Found #{locs.size} definition location(s):"]
|
|
270
253
|
locs.each do |loc|
|
|
271
254
|
uri = loc["uri"] || loc["targetUri"]
|
|
272
|
-
clean_file =
|
|
255
|
+
clean_file = Rubik::Platform.from_file_uri(uri)
|
|
273
256
|
range = loc["range"] || loc["targetSelectionRange"] || {}
|
|
274
257
|
s_line = (range.dig("start", "line") || 0) + 1
|
|
275
258
|
s_char = (range.dig("start", "character") || 0) + 1
|
|
@@ -281,31 +264,65 @@ module Rubik
|
|
|
281
264
|
ToolOutput.error("LSP Definition failed: #{res[:error]}")
|
|
282
265
|
end
|
|
283
266
|
end
|
|
267
|
+
end
|
|
284
268
|
|
|
285
|
-
|
|
269
|
+
class LSPReferencesTool < BaseLSPTool
|
|
270
|
+
DECLARATION = Declaration.new(
|
|
271
|
+
name: "lsp_references", aliases: ["find_references_lsp", "lsp_refs"],
|
|
272
|
+
description: "Find all compiler-accurate usages, call sites, and references of a symbol across the project via LSP",
|
|
273
|
+
risk: :read, archetypes: [:research],
|
|
274
|
+
params_schema: {
|
|
275
|
+
type: "object",
|
|
276
|
+
properties: {
|
|
277
|
+
file_path: { type: "string", description: "Path to source file containing the symbol" },
|
|
278
|
+
line: { type: "integer", description: "1-based line number" },
|
|
279
|
+
character: { type: "integer", description: "1-based character position" }
|
|
280
|
+
},
|
|
281
|
+
required: ["file_path", "line", "character"]
|
|
282
|
+
}
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
|
|
286
|
+
super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def execute(args = {})
|
|
290
|
+
mgr = effective_lsp_manager
|
|
291
|
+
return ToolOutput.error("LSP manager is not connected.") unless mgr
|
|
292
|
+
return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
|
|
293
|
+
|
|
294
|
+
path = (args["file_path"] || args[:file_path]).to_s.strip
|
|
295
|
+
line = (args["line"] || args[:line]).to_i
|
|
296
|
+
char = (args["character"] || args[:character] || args["col"] || args[:col]).to_i
|
|
297
|
+
|
|
298
|
+
return ToolOutput.error("File path is required.") if path.empty?
|
|
299
|
+
return ToolOutput.error("Line number must be >= 1.") if line < 1
|
|
286
300
|
|
|
287
|
-
def buffer_dirty?(path)
|
|
288
301
|
bm = effective_buffer_manager
|
|
289
|
-
|
|
302
|
+
mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
|
|
290
303
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
304
|
+
res = mgr.references(path, [line - 1, 0].max, [char - 1, 0].max)
|
|
305
|
+
if res[:ok]
|
|
306
|
+
result = res[:result]
|
|
307
|
+
if result.nil? || (result.is_a?(Array) && result.empty?)
|
|
308
|
+
append_buffer_tip("No references found for symbol at #{path}:#{line}:#{char}", path)
|
|
309
|
+
else
|
|
310
|
+
locs = result.is_a?(Array) ? result : [result]
|
|
311
|
+
lines = ["Found #{locs.size} reference location(s):"]
|
|
312
|
+
locs.each do |loc|
|
|
313
|
+
uri = loc["uri"] || loc["targetUri"]
|
|
314
|
+
clean_file = Rubik::Platform.from_file_uri(uri)
|
|
315
|
+
range = loc["range"] || loc["targetSelectionRange"] || {}
|
|
316
|
+
s_line = (range.dig("start", "line") || 0) + 1
|
|
317
|
+
s_char = (range.dig("start", "character") || 0) + 1
|
|
318
|
+
lines << " • #{clean_file}:#{s_line}:#{s_char}"
|
|
319
|
+
end
|
|
320
|
+
lines.join("\n")
|
|
296
321
|
end
|
|
297
322
|
else
|
|
298
|
-
|
|
323
|
+
ToolOutput.error("LSP References failed: #{res[:error]}")
|
|
299
324
|
end
|
|
300
325
|
end
|
|
301
|
-
|
|
302
|
-
def append_buffer_tip(msg, path)
|
|
303
|
-
return msg unless buffer_dirty?(path)
|
|
304
|
-
|
|
305
|
-
tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
|
|
306
|
-
"Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
|
|
307
|
-
"#{msg}#{tip}"
|
|
308
|
-
end
|
|
309
326
|
end
|
|
310
327
|
end
|
|
311
328
|
end
|
data/lib/rubik/tools/catalog.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Rubik
|
|
|
20
20
|
BUILTINS = [
|
|
21
21
|
ReadFileTool, ReplaceFileContentTool, WriteFileTool, ListFilesTool, GrepSearchTool,
|
|
22
22
|
SearchSymbolsTool, GetOutlineTool, FindReferencesTool, GetSymbolTool,
|
|
23
|
-
LSPDiagnosticsTool, LSPHoverTool, LSPDefinitionTool, RunTestsTool, RunCommandTool,
|
|
23
|
+
LSPDiagnosticsTool, LSPHoverTool, LSPDefinitionTool, LSPReferencesTool, RunTestsTool, RunCommandTool,
|
|
24
24
|
ManageTaskTool, ExecReplCommandTool, SynthesizeCommandTool, SynthesizeToolTool,
|
|
25
25
|
UnsynthesizeTool, InspectRuntimeTool, ProvideServiceTool, RepairRuntimeTool,
|
|
26
26
|
ApplyBufferTool, AskQuestionTool, InvokeSubagentTool, ManageSubagentsTool,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
module Tools
|
|
5
|
+
# Shared wording for the tools that consume the context index: one
|
|
6
|
+
# prefix keeps the not-ready phrasing consistent across tools.
|
|
7
|
+
module IndexMessages
|
|
8
|
+
# The index exists but holds no files. Tools append their own
|
|
9
|
+
# escape-hatch tail to this prefix.
|
|
10
|
+
INDEX_NOT_READY_PREFIX = "Context index has no files indexed yet (still building, or the scan failed). " \
|
|
11
|
+
"Run '!context scan' to build it, or "
|
|
12
|
+
|
|
13
|
+
# The index coeffect is absent entirely: nothing to search against.
|
|
14
|
+
INDEX_UNAVAILABLE_MESSAGE = "Context index is not available. Run '!context scan' or restart the session to build it."
|
|
15
|
+
|
|
16
|
+
# Suffix for SUCCESS results served from a PARTIAL index: the model
|
|
17
|
+
# must never mistake a truncated index for ground truth. Returns nil
|
|
18
|
+
# for a clean scan so success output stays unchanged.
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
# Reads the completeness verdict off an index's status_summary; nil
|
|
22
|
+
# for a clean scan or an object without the summary seam (test doubles).
|
|
23
|
+
def note_for(idx)
|
|
24
|
+
return nil unless idx.respond_to?(:status_summary)
|
|
25
|
+
|
|
26
|
+
summary = idx.status_summary
|
|
27
|
+
partial_index_note(summary[:last_scan_aborted], summary[:last_scan_error])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def partial_index_note(aborted, error)
|
|
31
|
+
return nil unless aborted
|
|
32
|
+
|
|
33
|
+
" Note: the context index is PARTIAL — the last scan aborted" \
|
|
34
|
+
"#{" (#{error})" if error}. Results may be missing files; '!context scan' rebuilds it."
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -35,12 +35,21 @@ module Rubik
|
|
|
35
35
|
@rg_path = nil
|
|
36
36
|
|
|
37
37
|
class << self
|
|
38
|
-
#
|
|
39
|
-
# may not
|
|
40
|
-
#
|
|
41
|
-
#
|
|
38
|
+
# Keeps the rg-side and Ruby-side file universes identical: the
|
|
39
|
+
# repo's .gitignore may not prune what Rubik prunes. Lazily built
|
|
40
|
+
# (Scanner may be unloaded at require time). DEFAULT_IGNORES needs
|
|
41
|
+
# both glob forms — a middle-slash rg glob is root-anchored while
|
|
42
|
+
# the Ruby side prunes at any depth; HARD_PRUNE_ROOTS is
|
|
43
|
+
# root-anchored on both sides.
|
|
42
44
|
def prune_globs
|
|
43
|
-
@prune_globs ||=
|
|
45
|
+
@prune_globs ||= (
|
|
46
|
+
Rubik::Context::Scanner::DEFAULT_IGNORES.flat_map do |p|
|
|
47
|
+
globs = ["-g", "!#{p}"]
|
|
48
|
+
globs += ["-g", "!**/#{p}"] unless p.start_with?("**/")
|
|
49
|
+
globs
|
|
50
|
+
end +
|
|
51
|
+
Rubik::Context::Scanner::HARD_PRUNE_ROOTS.flat_map { |r| ["-g", "!/#{r}/**"] }
|
|
52
|
+
).freeze
|
|
44
53
|
end
|
|
45
54
|
|
|
46
55
|
# Resolved rg executable, or nil. RUBIK_RG_PATH beats PATH lookup
|
data/lib/rubik/tools/registry.rb
CHANGED
|
@@ -125,7 +125,7 @@ module Rubik
|
|
|
125
125
|
raw_context_index = service_overrides[:context_index]
|
|
126
126
|
|
|
127
127
|
register_file_and_search_tools(registry, buffer_manager: buffer_manager, svc: svc, root_dir: root_dir, native_switch: native_switch, ctx: ctx)
|
|
128
|
-
register_lsp_tools(registry, lsp_manager: lsp_manager, buffer_manager: buffer_manager)
|
|
128
|
+
register_lsp_tools(registry, lsp_manager: lsp_manager, buffer_manager: buffer_manager, ctx: ctx)
|
|
129
129
|
register_execution_tools(registry, svc: svc, raw_context_index: raw_context_index, root_dir: root_dir, native_switch: native_switch, ctx: ctx)
|
|
130
130
|
register_repl_and_synthesis_tools(
|
|
131
131
|
registry,
|
|
@@ -161,10 +161,11 @@ module Rubik
|
|
|
161
161
|
registry.register(GetSymbolTool.new(svc.ast_graph, runtime_context: ctx))
|
|
162
162
|
end
|
|
163
163
|
|
|
164
|
-
def self.register_lsp_tools(registry, lsp_manager:, buffer_manager:)
|
|
165
|
-
registry.register(LSPDiagnosticsTool.new(lsp_manager, buffer_manager: buffer_manager))
|
|
166
|
-
registry.register(LSPHoverTool.new(lsp_manager, buffer_manager: buffer_manager))
|
|
167
|
-
registry.register(LSPDefinitionTool.new(lsp_manager, buffer_manager: buffer_manager))
|
|
164
|
+
def self.register_lsp_tools(registry, lsp_manager:, buffer_manager:, ctx: nil)
|
|
165
|
+
registry.register(LSPDiagnosticsTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
|
|
166
|
+
registry.register(LSPHoverTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
|
|
167
|
+
registry.register(LSPDefinitionTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
|
|
168
|
+
registry.register(LSPReferencesTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
|
|
168
169
|
end
|
|
169
170
|
|
|
170
171
|
def self.register_execution_tools(registry, svc:, raw_context_index:, root_dir:, native_switch:, ctx:)
|
data/lib/rubik/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubik
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Özgür Ulukır
|
|
@@ -296,6 +296,7 @@ files:
|
|
|
296
296
|
- lib/rubik/context/git_lister.rb
|
|
297
297
|
- lib/rubik/context/index.rb
|
|
298
298
|
- lib/rubik/context/repo_context_reader.rb
|
|
299
|
+
- lib/rubik/context/root_heuristics.rb
|
|
299
300
|
- lib/rubik/context/scanner.rb
|
|
300
301
|
- lib/rubik/diagnostics.rb
|
|
301
302
|
- lib/rubik/diagnostics/collector.rb
|
|
@@ -404,6 +405,7 @@ files:
|
|
|
404
405
|
- lib/rubik/orchestrator/tool_call_id.rb
|
|
405
406
|
- lib/rubik/orchestrator/tool_circuit_breaker.rb
|
|
406
407
|
- lib/rubik/orchestrator/tool_history.rb
|
|
408
|
+
- lib/rubik/orchestrator/tool_timeout.rb
|
|
407
409
|
- lib/rubik/orchestrator/turn_executor.rb
|
|
408
410
|
- lib/rubik/orchestrator/turn_executor/subagent_channel.rb
|
|
409
411
|
- lib/rubik/orchestrator/turn_executor/user_channel.rb
|
|
@@ -756,6 +758,7 @@ files:
|
|
|
756
758
|
- lib/rubik/tools/declaration.rb
|
|
757
759
|
- lib/rubik/tools/diagnostic_reporter.rb
|
|
758
760
|
- lib/rubik/tools/fuzzy_matcher.rb
|
|
761
|
+
- lib/rubik/tools/index_messages.rb
|
|
759
762
|
- lib/rubik/tools/native_search.rb
|
|
760
763
|
- lib/rubik/tools/output.rb
|
|
761
764
|
- lib/rubik/tools/preflight_runner.rb
|