rubik 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6db8019561c617d4b3006fc7caea11b4f780feb2a55bc200fc8ca4825040720
4
- data.tar.gz: 0acc95f9ae8c299a2d253833c541954d92b1372c6af7c3c1af08ad9a08bb5c53
3
+ metadata.gz: 0b147c192626203788c45315062bc380c3937c5ac638a81726ca7f135e6abfd0
4
+ data.tar.gz: d95f5cce661e09ed190d7cf77ec0171d797c700756adb93769be99334f5c7a97
5
5
  SHA512:
6
- metadata.gz: 6d2e351b5907c057bb29fe1b20d84dfef967afb8571116a147ca7e013149e6c5fe00bd5aa8cb2cccd08e4e7679184e02f126e8b2fab2f11cc5ee33f28d837648
7
- data.tar.gz: b638835c922ad012b30e438f00460704d7f9aaf0d324d9de90267f1d10b6e0dd81b931b4d2491d312825dc0ed2539cd77880bfbddd83765e7e34fdbe27b14dfe
6
+ metadata.gz: ee9551a32ca6cb978a2c6f412f84b7d825e42b9fd73b4c24810117e3376fcf5f12b3def72efca7cdf7b5d7e20e917b5c6a400e18e1a28c72fc35b54d1996fbc8
7
+ data.tar.gz: d29bdf8214f918ed81209540aeff311dfb5f4e8201201bbab85bc642d65aeda4eca6466979cb767862446e644f9cce52fafade3c74350fd81dc90e4f638d5abf
data/ATTRIBUTION.md CHANGED
@@ -121,7 +121,7 @@ SOFTWARE.
121
121
  | **`strings-ansi`** | Piotr Murach | MIT | ANSI-aware string truncation and alignment for REPL formatters. |
122
122
  | **`reline`** | Hiroshi SHIBATA & Ruby Team | Ruby License / BSD-2-Clause | Line-editing, history navigation, autocompletion hooks, and headless terminal adaptation. |
123
123
  | **`prism`** | Kevin Newton & Ruby Core Team | MIT | High-performance Ruby parsing and AST extraction ([`Rubik::AST::RubyExtractor`](lib/rubik/ast/ruby_extractor.rb)). |
124
- | **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,000+ unit, integration, and contract tests. |
124
+ | **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,100+ unit, integration, and contract tests. |
125
125
  | **`rubocop`** | Bozhidar Batsov & contributors | MIT | Static code analysis, style enforcement, and architectural hygiene gates. |
126
126
  | **`benchmark`, `logger`, `pstore`, `reline`, `fiddle`** | Ruby core / rubygems teams | Ruby License / BSD-2-Clause | Ruby stdlib gems pinned explicitly in `rubik.gemspec` as they are unbundled from the default set in Ruby 3.4/3.5. |
127
127
 
data/CHANGELOG.md CHANGED
@@ -6,6 +6,41 @@ commits, 2026-08-23 → 2026-10-09, see `git log`).
6
6
 
7
7
  The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
8
8
 
9
+ ## [0.7.1] - 2026-11-04
10
+
11
+ An LSP maturity patch: the language-server integration comes back from
12
+ its first full review with twelve findings closed — symmetric coeffect
13
+ retraction, honest restarts, protocol capability declarations, and
14
+ Windows path correctness — and gains a references tool, a diagnostics
15
+ feedback timeout knob, and a `!lsp reset` escape hatch for tripped
16
+ circuit breakers.
17
+
18
+ ### Added
19
+
20
+ - **LSP references tool (`lsp_references`, aliases `lsp_refs`/`find_references_lsp`)
21
+ (#361):** finds the call and reference sites of a symbol through the language
22
+ server instead of text search; declared with explicit `lsp:<lang>` REQUIRES
23
+ coeffects so it degrades honestly when no server is live, and the built-in
24
+ tool count rises to 36.
25
+ - **Diagnostics feedback knob and breaker reset (`lsp.feedback_timeout`, `!lsp reset`)
26
+ (#361):** the seconds to wait for compiler diagnostics after a buffer sync or
27
+ file write are configurable (default 0.5s unchanged) with `wait_for_diagnostics`
28
+ polling; `!lsp reset [lang]` clears tripped circuit breakers without a full
29
+ restart; the default Python server moves to `ruff server`.
30
+
31
+ ### Fixed
32
+
33
+ - **LSP review remediations (#361):** client loss retracts its coeffects
34
+ symmetrically through the new `Context#unregister_disposable`, so
35
+ provide/unprovide cycles return the Omega accumulator to baseline instead of
36
+ growing it; restart stops the dangling process before relaunching and isolates
37
+ the Bundler env from the client child; the initialize request declares
38
+ `workspaceFolders` and the workspace capability, with `open_close` sync
39
+ inferred when omitted alongside incremental sync; the REPL shell dispatches
40
+ `did_close_file` for unindexed and deleted files; Windows file URIs decode
41
+ correctly and relative paths normalize case-insensitively, with absolute
42
+ Windows drive paths preserved by diagnostics collection on posix runners.
43
+
9
44
  ## [0.7.0] - 2026-11-03
10
45
 
11
46
  A turn-stall-and-honesty minor: `list_files` and `grep_search` never
@@ -1130,7 +1165,8 @@ installation section.
1130
1165
  - Context: serialized index mutations, snapshot-outside-lock reconcile,
1131
1166
  streaming-first truncation.
1132
1167
 
1133
- [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.7.0...HEAD
1168
+ [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.7.1...HEAD
1169
+ [0.7.1]: https://github.com/ozgurulukir/rubik/compare/v0.7.0...v0.7.1
1134
1170
  [0.7.0]: https://github.com/ozgurulukir/rubik/compare/v0.6.0...v0.7.0
1135
1171
  [0.6.0]: https://github.com/ozgurulukir/rubik/compare/v0.5.0...v0.6.0
1136
1172
  [0.5.0]: https://github.com/ozgurulukir/rubik/compare/v0.4.2...v0.5.0
@@ -85,6 +85,7 @@ module Rubik
85
85
  "enabled" => true,
86
86
  "auto_start" => true,
87
87
  "auto_diagnostics" => true,
88
+ "feedback_timeout" => 0.5,
88
89
  "servers" => {
89
90
  "go" => "gopls", "rust" => "rust-analyzer", "zig" => "zls", "c" => "clangd", "cpp" => "clangd",
90
91
  "vue" => "vue-language-server --stdio", "python" => "ruff server", "ruby" => "typeprof --lsp --stdio",
@@ -16,7 +16,11 @@ module Rubik
16
16
 
17
17
  def initialize(lsp_manager: nil, root_dir: Dir.pwd)
18
18
  @lsp_manager = lsp_manager
19
- @root_dir = File.expand_path(root_dir)
19
+ @root_dir = if root_dir.to_s.match?(%r{\A[a-zA-Z]:[\\/]})
20
+ root_dir.to_s.tr("\\", "/")
21
+ else
22
+ File.expand_path(root_dir)
23
+ end
20
24
  @entries = []
21
25
  @mutex = Mutex.new
22
26
  end
@@ -193,7 +197,9 @@ module Rubik
193
197
 
194
198
  norm_path = path.to_s.tr("\\", "/")
195
199
  norm_root = @root_dir.to_s.tr("\\", "/")
196
- norm_path.sub(%r{^#{Regexp.escape(norm_root)}/}, "")
200
+ pattern = %r{^#{Regexp.escape(norm_root)}/}
201
+ pattern = Regexp.new(pattern.source, Regexp::IGNORECASE) if Rubik::Platform.windows? || norm_root.match?(%r{\A[a-zA-Z]:/})
202
+ norm_path.sub(pattern, "")
197
203
  end
198
204
  end
199
205
  end
@@ -25,7 +25,7 @@ module Rubik
25
25
  "zig" => "zls",
26
26
  "c" => "clangd",
27
27
  "cpp" => "clangd",
28
- "python" => "pylsp",
28
+ "python" => "ruff server",
29
29
  "ruby" => "typeprof --lsp --stdio",
30
30
  "typescript" => "typescript-language-server --stdio",
31
31
  "javascript" => "typescript-language-server --stdio",
@@ -91,6 +91,8 @@ module Rubik
91
91
  def start
92
92
  return false unless available?
93
93
 
94
+ stop if alive? || @wait_thr&.alive? || @reader_alive
95
+
94
96
  @document_mutex.synchronize do
95
97
  @req_id = 0
96
98
  @open_documents.clear
@@ -114,7 +116,7 @@ module Rubik
114
116
 
115
117
  cmd_parts[0] = resolved_bin if resolved_bin
116
118
 
117
- @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*cmd_parts, chdir: @root_dir)
119
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(sanitized_spawn_env, *cmd_parts, chdir: @root_dir)
118
120
  # Binary mode: LSP framing is byte-exact. Text-mode pipes on Windows
119
121
  # translate CRLF→LF on read, so Content-Length counts and read(len)
120
122
  # disagree and the JSON body arrives truncated (the reader's old
@@ -131,10 +133,18 @@ module Rubik
131
133
  # server itself mid-write; drain continuously, discard content.
132
134
  @stderr_drain = Rubik::Platform::IoDrain.start(@stderr)
133
135
 
136
+ root_uri = Rubik::Platform.to_file_uri(@root_dir)
134
137
  init_res = send_request("initialize", {
135
138
  processId: Process.pid,
136
- rootUri: Rubik::Platform.to_file_uri(@root_dir),
139
+ rootUri: root_uri,
140
+ workspaceFolders: [
141
+ { uri: root_uri, name: File.basename(@root_dir) }
142
+ ],
137
143
  capabilities: {
144
+ workspace: {
145
+ workspaceFolders: true,
146
+ configuration: true
147
+ },
138
148
  textDocument: {
139
149
  hover: { contentFormat: ["markdown", "plaintext"] },
140
150
  synchronization: {
@@ -695,11 +705,13 @@ module Rubik
695
705
  }.freeze
696
706
  when Hash
697
707
  save = value["save"]
708
+ change = (value["change"] || 0).to_i.clamp(0, 2)
709
+ open_close = value.key?("openClose") ? (value["openClose"] == true) : change.positive?
698
710
  {
699
711
  source: :options,
700
- open_close: value["openClose"] == true,
701
- change: (value["change"] || 0).to_i.clamp(0, 2),
702
- save: !!save,
712
+ open_close: open_close,
713
+ change: change,
714
+ save: !save.nil? && save != false,
703
715
  include_text: save.is_a?(Hash) && save["includeText"] == true
704
716
  }.freeze
705
717
  else
@@ -773,6 +785,14 @@ module Rubik
773
785
  end
774
786
  false
775
787
  end
788
+
789
+ def sanitized_spawn_env
790
+ env = {}
791
+ ENV.each_key do |k|
792
+ env[k] = nil if k.start_with?("BUNDLE_", "BUNDLER_") || ["RUBYOPT", "RUBYLIB"].include?(k)
793
+ end
794
+ env
795
+ end
776
796
  end
777
797
  end
778
798
  end
@@ -55,6 +55,7 @@ module Rubik
55
55
  @healthy_since = {}
56
56
  @recovery_errors = {}
57
57
  @registered_disposable_langs = {}
58
+ @client_inverses = {}
58
59
  @monitor = Monitor.new
59
60
  end
60
61
 
@@ -176,6 +177,8 @@ module Rubik
176
177
  else
177
178
  record_crash(lang_str)
178
179
  stop_client_safely(client)
180
+ @clients.delete(lang_str)
181
+ unregister_client_unlocked(lang_str)
179
182
  failure = Runtime::DiagnosticEngine.diagnose(
180
183
  cmd: ServerCommand.display(client.server_cmd),
181
184
  exit_code: 1,
@@ -238,6 +241,15 @@ module Rubik
238
241
  client.did_save(file_path, content)
239
242
  end
240
243
 
244
+ def did_close_file(file_path)
245
+ return false unless enabled?
246
+
247
+ client = client_for(file_path)
248
+ return false unless client&.running
249
+
250
+ client.did_close(file_path)
251
+ end
252
+
241
253
  def sync_buffer_file_if_needed(file_path, buffer_manager)
242
254
  return false unless enabled? && buffer_manager
243
255
 
@@ -455,24 +467,30 @@ module Rubik
455
467
  end
456
468
 
457
469
  def register_client_unlocked(lang, client)
470
+ lang_str = lang.to_s.downcase
458
471
  effective_ctx = @context || @runtime_manager&.context
459
472
  return unless effective_ctx
460
473
 
461
- effective_ctx.provide("lsp:#{lang}", client)
462
- return if @registered_disposable_langs[lang] == effective_ctx.object_id
474
+ effective_ctx.provide("lsp:#{lang_str}", client)
475
+ return if @registered_disposable_langs[lang_str] == effective_ctx.object_id
463
476
 
464
- @registered_disposable_langs[lang] = effective_ctx.object_id
465
- effective_ctx.register_disposable do
466
- current = @clients[lang]
477
+ inverse = effective_ctx.register_disposable do
478
+ current = @clients[lang_str]
467
479
  current.stop if current&.running
468
480
  end
481
+ @registered_disposable_langs[lang_str] = effective_ctx.object_id
482
+ @client_inverses[lang_str] = inverse
469
483
  end
470
484
 
471
485
  def unregister_client_unlocked(lang)
472
486
  lang_str = lang.to_s.downcase
473
487
  @registered_disposable_langs.delete(lang_str)
488
+ inverse = @client_inverses.delete(lang_str)
474
489
  effective_ctx = @context || @runtime_manager&.context
475
- effective_ctx&.unprovide("lsp:#{lang_str}") if effective_ctx.respond_to?(:unprovide)
490
+ return unless effective_ctx
491
+
492
+ effective_ctx.unprovide("lsp:#{lang_str}") if effective_ctx.respond_to?(:unprovide)
493
+ effective_ctx.unregister_disposable(inverse) if inverse && effective_ctx.respond_to?(:unregister_disposable)
476
494
  end
477
495
 
478
496
  def stop_client_safely(client)
@@ -36,8 +36,9 @@ module Rubik
36
36
  end
37
37
 
38
38
  def append_diagnostics(deps, written_file, tool_result)
39
+ timeout = deps.lsp_manager&.config&.fetch("lsp.feedback_timeout", 0.5) || 0.5
39
40
  snapshot = if deps.lsp_manager.respond_to?(:wait_for_diagnostics)
40
- deps.lsp_manager.wait_for_diagnostics(written_file, timeout: 0.2)
41
+ deps.lsp_manager.wait_for_diagnostics(written_file, timeout: timeout)
41
42
  else
42
43
  deps.lsp_manager.diagnostics_snapshot_for(written_file)
43
44
  end
@@ -11,7 +11,7 @@ module Rubik
11
11
 
12
12
  # Whole-command synopses: shared by the spine registration (usage:)
13
13
  # and the fallback branches that print them, so the two cannot drift.
14
- USAGE_LSP = "Usage: !lsp <status | on | off | diag [file] | start <lang> | stop [lang] | restart [lang] | servers> [--project|--global]"
14
+ USAGE_LSP = "Usage: !lsp <status | on | off | diag [file] | start <lang> | stop [lang] | restart [lang] | reset [lang] | servers> [--project|--global]"
15
15
  USAGE_SYMBOLS = "Usage: !symbols <name>"
16
16
  USAGE_OUTLINE = "Usage: !outline <file_path>"
17
17
  USAGE_REFS = "Usage: !refs <symbol_name>"
@@ -113,11 +113,23 @@ module Rubik
113
113
  handle_lsp_stop(clean_args[1], ctx)
114
114
  when "restart"
115
115
  handle_lsp_restart(clean_args[1], ctx)
116
+ when "reset"
117
+ handle_lsp_reset(clean_args[1], ctx)
116
118
  else
117
119
  ctx.out.puts USAGE_LSP
118
120
  end
119
121
  end
120
122
 
123
+ private_class_method def self.handle_lsp_reset(lang, ctx)
124
+ if lang.nil? || lang.empty?
125
+ ctx.lsp_manager.crash_stats.clear
126
+ ctx.out.puts "Reset LSP circuit breaker for all languages."
127
+ else
128
+ ctx.lsp_manager.reset_circuit!(lang)
129
+ ctx.out.puts "Reset LSP circuit breaker for '#{lang}'."
130
+ end
131
+ end
132
+
121
133
  private_class_method def self.handle_lsp_status(ctx)
122
134
  summary = ctx.lsp_manager.status_summary
123
135
  ctx.out.puts "=== LSP Integration Status ==="
@@ -101,6 +101,7 @@ module Rubik
101
101
  end
102
102
  else
103
103
  @ast_graph.remove_file(full_path)
104
+ @lsp_manager&.did_close_file(rel_file) if @lsp_manager&.enabled?
104
105
  end
105
106
  end
106
107
  @ast_graph.save_to_cache(@cache_store) if @cache_store
@@ -55,23 +55,21 @@ module Rubik
55
55
  end
56
56
  alias on_dispose register_disposable
57
57
 
58
- # Number of pending inverse operations in the Omega accumulator.
59
- # Exposed for runtime visualization (!agents panel, !runtime).
60
- def disposable_count
61
- @monitor.synchronize { @disposables.size }
62
- end
63
-
64
- def services
65
- @monitor.synchronize { @services.dup.freeze }
66
- end
58
+ # Symmetric removal of an inverse from the Omega accumulator before
59
+ # context disposal (AGENTS.md §4).
60
+ def unregister_disposable(inverse)
61
+ return unless inverse
67
62
 
68
- def service_names
69
- @monitor.synchronize { @services.keys }
63
+ @monitor.synchronize { @disposables.delete(inverse) }
70
64
  end
65
+ alias prune_disposable unregister_disposable
71
66
 
72
- def last_dispose_errors
73
- @monitor.synchronize { @last_dispose_errors.dup }
74
- end
67
+ # Number of pending inverse operations in the Omega accumulator.
68
+ # Exposed for runtime visualization (!agents panel, !runtime).
69
+ def disposable_count = @monitor.synchronize { @disposables.size }
70
+ def services = @monitor.synchronize { @services.dup.freeze }
71
+ def service_names = @monitor.synchronize { @services.keys }
72
+ def last_dispose_errors = @monitor.synchronize { @last_dispose_errors.dup }
75
73
 
76
74
  def provide(name, service)
77
75
  key = name.to_s.downcase
@@ -14,6 +14,7 @@ module Rubik
14
14
  "typeprof --lsp --stdio"
15
15
  ],
16
16
  "python" => [
17
+ "ruff server",
17
18
  "pyright-langserver --stdio",
18
19
  "pylsp",
19
20
  "jedi-language-server"
@@ -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 LSPDiagnosticsTool < BaseTool
10
- attr_reader :lsp_manager, :buffer_manager
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 effective_buffer_manager
30
- @buffer_manager || @lsp_manager&.context&.get(Rubik::Coeffects::BUFFER_MANAGER)
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
- return ToolOutput.error("LSP manager is not connected.") unless @lsp_manager
35
- return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless @lsp_manager.enabled?
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
- @lsp_manager.sync_buffer_file_if_needed(path, bm) if bm && @lsp_manager.respond_to?(:sync_buffer_file_if_needed)
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 = @lsp_manager.all_diagnostic_snapshots
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 = @lsp_manager.diagnostics_snapshot_for(path)
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 < BaseTool
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 effective_buffer_manager
161
- @buffer_manager || @lsp_manager&.context&.get(Rubik::Coeffects::BUFFER_MANAGER)
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
- return ToolOutput.error("LSP manager is not connected.") unless @lsp_manager
166
- return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless @lsp_manager.enabled?
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
- @lsp_manager.sync_buffer_file_if_needed(path, bm) if bm && @lsp_manager.respond_to?(:sync_buffer_file_if_needed)
190
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
177
191
 
178
- res = @lsp_manager.hover(path, [line - 1, 0].max, [char - 1, 0].max)
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 < BaseTool
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 effective_buffer_manager
245
- @buffer_manager || @lsp_manager&.context&.get(Rubik::Coeffects::BUFFER_MANAGER)
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
- return ToolOutput.error("LSP manager is not connected.") unless @lsp_manager
250
- return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless @lsp_manager.enabled?
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
- @lsp_manager.sync_buffer_file_if_needed(path, bm) if bm && @lsp_manager.respond_to?(:sync_buffer_file_if_needed)
243
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
261
244
 
262
- res = @lsp_manager.definition(path, [line - 1, 0].max, [char - 1, 0].max)
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 = uri.to_s.sub(%r{^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
- private
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
- return false unless bm && !path.to_s.empty?
302
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
290
303
 
291
- if bm.respond_to?(:dirty?)
292
- begin
293
- bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
294
- rescue ArgumentError
295
- bm.dirty?
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
- false
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
@@ -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,
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubik
4
- VERSION = "0.7.0"
4
+ VERSION = "0.7.1"
5
5
  end
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Özgür Ulukır