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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd6a93a2277eebd80ce20dbf33ceba1ba7354d6540a6906740b4d58274736847
4
- data.tar.gz: 2f46b92bbf23cbcea71767c433ffd45dd55b821e6bb8f1b18cb8c2e7310c5be0
3
+ metadata.gz: 0b147c192626203788c45315062bc380c3937c5ac638a81726ca7f135e6abfd0
4
+ data.tar.gz: d95f5cce661e09ed190d7cf77ec0171d797c700756adb93769be99334f5c7a97
5
5
  SHA512:
6
- metadata.gz: 258d3631c684bfdd719a3b341197dd02da8fc64789c30645b8df0cd4814fc7546392c371737582adab36ff4d46052828fe8d0fed536a1efb592b2c5dcca34571
7
- data.tar.gz: d9a517f0f4b7026d666d3ac0e2f880805ce40d2341613e5cc75ed72b5b37df3eabf60f07cee9cdf2d8a491b3758b0871edc43b62e501b423bde817b814b1edaf
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,88 @@ 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
+
44
+ ## [0.7.0] - 2026-11-03
45
+
46
+ A turn-stall-and-honesty minor: `list_files` and `grep_search` never
47
+ trigger a synchronous full scan again, partial context scans disclose
48
+ themselves instead of serving truncated truth as clean, huge session
49
+ roots get boot-time guidance instead of a silent minutes-long warm
50
+ walk, and a single stalling tool can no longer pin the whole turn —
51
+ the first dispatcher-level call budget lands as an off-by-default knob.
52
+
53
+ ### Added
54
+
55
+ - **Bounded tool execution (`tools.call_timeout`, `tools.call_timeout_overrides`)
56
+ (#355):** an off-by-default dispatcher budget applied at the tool-dispatch seam
57
+ on both orchestrator planes; a fired budget returns an honest error result (the
58
+ call is abandoned, not killed) and the turn continues, with the timeout visible
59
+ via `!dmesg -s tools`. Precedence: an explicit env disable
60
+ (`RUBIK_TOOLS_CALL_TIMEOUT=0`) wins over everything, per-tool overrides refine
61
+ the resolved global, and the env budget beats the config file. Knob unset means
62
+ byte-identical inline execution.
63
+ - **Huge-root guidance (`context.huge_root_notice`, `context.boot_scan_on_huge_root`)
64
+ (#356):** a session root that looks like a huge tree (the user home directory, a
65
+ filesystem root, or a root holding OS data directories) now prints one guidance
66
+ notice at boot and skips the boot-time warm scan; `!context scan` is the explicit
67
+ opt-in, and the knob restores the boot walk. Ordinary repositories boot with no
68
+ new output.
69
+
70
+ ### Fixed
71
+
72
+ - **Partial context scans are disclosed instead of served as truth (#357):** the
73
+ scanner records every dropped-subtree abort into a completeness verdict that
74
+ `Index#status_summary` publishes under the same lock as the files; `!context
75
+ scan` reports `finished PARTIALLY`, `!context status`/`stats` show the flag,
76
+ and `list_files`/`grep_search` append a PARTIAL note to answers served from a
77
+ truncated index (hits, no-matches, and ignored-directory verdicts alike).
78
+ Completed scans produce byte-identical output.
79
+ - **Tools never scan (#358):** an empty context index no longer triggers a
80
+ synchronous full walk inside `list_files`/`grep_search` — in a session rooted
81
+ at a large non-repo tree that walk ran for minutes inside the turn and, the
82
+ Ruby walker holding the GVL, stalled the whole REPL with it. An empty index
83
+ now answers honestly ("not ready, run `!context scan`"), the ignore-rules
84
+ explanation is reserved for indexes that were actually built, grep's
85
+ memory-only dirty-buffer searches disclose their scope on hits and no-hits
86
+ alike, AppData moves to the root-anchored hard-prune set (`.ollama`/`.zcode`
87
+ join the default ignores) with the rg prune globs gaining the any-depth forms
88
+ the Ruby side always applied, and `!context scan` warns on an empty result
89
+ instead of claiming success.
90
+
9
91
  ## [0.6.0] - 2026-11-02
10
92
 
11
93
  A measurement-and-honesty minor: the planned vakanüvis fixes gain their
@@ -1083,7 +1165,9 @@ installation section.
1083
1165
  - Context: serialized index mutations, snapshot-outside-lock reconcile,
1084
1166
  streaming-first truncation.
1085
1167
 
1086
- [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.6.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
1170
+ [0.7.0]: https://github.com/ozgurulukir/rubik/compare/v0.6.0...v0.7.0
1087
1171
  [0.6.0]: https://github.com/ozgurulukir/rubik/compare/v0.5.0...v0.6.0
1088
1172
  [0.5.0]: https://github.com/ozgurulukir/rubik/compare/v0.4.2...v0.5.0
1089
1173
  [0.4.2]: https://github.com/ozgurulukir/rubik/compare/v0.4.1...v0.4.2
@@ -209,6 +209,9 @@ module Rubik
209
209
  def grep_once(repo_dir, native:)
210
210
  best_of(3) do
211
211
  idx = Rubik::Context::Index.new(root_dir: repo_dir, native: native)
212
+ # Tools never scan; build the index up front (scan cost has its
213
+ # own scan_once benchmark).
214
+ idx.full_scan
212
215
  tool = Rubik::Tools::GrepSearchTool.new(nil, idx, root_dir: repo_dir, config: NativeConfig.new(native))
213
216
  ::Benchmark.realtime { tool.execute({ "query" => "needle_rare_marker", "max_results" => 50 }) }
214
217
  end
@@ -45,6 +45,12 @@ module Rubik
45
45
  "max_output_lines" => 300,
46
46
  "truncation_strategy" => "head_tail",
47
47
  "timeout_seconds" => 30,
48
+ # Dispatcher-level call budget in seconds; nil = off (inline execution,
49
+ # current behavior). RUBIK_TOOLS_CALL_TIMEOUT env overrides the file.
50
+ # A timed-out call is abandoned, not killed — bounds turn latency.
51
+ "call_timeout" => nil,
52
+ # Canonical tool name => seconds; 0/false disables for that tool.
53
+ "call_timeout_overrides" => {},
48
54
  "native" => "auto"
49
55
  },
50
56
  "router" => { "mode" => "auto", "sticky" => true },
@@ -79,6 +85,7 @@ module Rubik
79
85
  "enabled" => true,
80
86
  "auto_start" => true,
81
87
  "auto_diagnostics" => true,
88
+ "feedback_timeout" => 0.5,
82
89
  "servers" => {
83
90
  "go" => "gopls", "rust" => "rust-analyzer", "zig" => "zls", "c" => "clangd", "cpp" => "clangd",
84
91
  "vue" => "vue-language-server --stdio", "python" => "ruff server", "ruby" => "typeprof --lsp --stdio",
@@ -104,6 +111,8 @@ module Rubik
104
111
  "tool_chronicle_max_entries" => 15, # Plan 85 D-2/D-3
105
112
  "merge_turn_tool_history" => true, # Plan 85 D-7
106
113
  "merge_turn_tool_max_entries" => 20, # Plan 85 D-7
114
+ "huge_root_notice" => true, # one guidance notice for likely-huge session roots (home dir, OS data)
115
+ "boot_scan_on_huge_root" => false, # false skips the boot warm walk on strong huge-root signals; !context scan opts in
107
116
  "emergency_truncate_strategy" => "head_tail" # EmergencyCompactor hard-truncate layer: "head_tail" | "head_only" | "tail_only"
108
117
  },
109
118
  "ui" => {
@@ -17,6 +17,12 @@ module Rubik
17
17
  # 17006) and can corrupt it. Scanning itself is not changed — only the
18
18
  # shared-state mutation is made thread-safe.
19
19
  @mutex = Mutex.new
20
+ # Serializes whole scan runs (full_scan / incremental_scan) so the
21
+ # files hash and the completeness verdict pair atomically — two
22
+ # concurrent scans would otherwise let one publish the other's
23
+ # clean verdict with its own aborted files. Held only by scanners,
24
+ # never by readers (status_summary stays lock-cheap).
25
+ @scan_mutex = Mutex.new
20
26
  @scanner = scanner || Scanner.new(
21
27
  root_dir: @root_dir,
22
28
  additional_roots: additional_roots,
@@ -27,6 +33,8 @@ module Rubik
27
33
  @files = {}
28
34
  @languages = []
29
35
  @last_scan_time = nil
36
+ @last_scan_aborted = false
37
+ @last_scan_error = nil
30
38
  end
31
39
 
32
40
  def update_file_filters(includes: nil, excludes: nil)
@@ -44,58 +52,66 @@ module Rubik
44
52
  end
45
53
 
46
54
  def full_scan
47
- start_time = Time.now
48
- files = @scanner.scan
49
- languages = @scanner.detect_languages(files)
50
- @mutex.synchronize do
51
- @files = files
52
- @languages = languages
53
- @last_scan_time = Time.now - start_time
55
+ @scan_mutex.synchronize do
56
+ start_time = Time.now
57
+ files = @scanner.scan
58
+ languages = @scanner.detect_languages(files)
59
+ report = scanner_report
60
+ @mutex.synchronize do
61
+ @files = files
62
+ @languages = languages
63
+ @last_scan_time = Time.now - start_time
64
+ store_scan_outcome!(report)
65
+ end
54
66
  end
55
67
  @files
56
68
  end
57
69
 
58
70
  def incremental_scan
59
- start_time = Time.now
60
- snapshot = @mutex.synchronize { @files }
61
- new_scan = @scanner.scan(snapshot)
62
- old_files = snapshot
63
-
64
- added = []
65
- modified = []
66
- deleted = []
67
- unchanged = []
68
-
69
- new_scan.each do |rel_path, info|
70
- if old_files.key?(rel_path)
71
- old_info = old_files[rel_path]
72
- if old_info[:mtime] != info[:mtime] || old_info[:size] != info[:size] || old_info[:hash] != info[:hash]
73
- modified << rel_path
71
+ @scan_mutex.synchronize do
72
+ start_time = Time.now
73
+ snapshot = @mutex.synchronize { @files }
74
+ new_scan = @scanner.scan(snapshot)
75
+ old_files = snapshot
76
+
77
+ added = []
78
+ modified = []
79
+ deleted = []
80
+ unchanged = []
81
+
82
+ new_scan.each do |rel_path, info|
83
+ if old_files.key?(rel_path)
84
+ old_info = old_files[rel_path]
85
+ if old_info[:mtime] != info[:mtime] || old_info[:size] != info[:size] || old_info[:hash] != info[:hash]
86
+ modified << rel_path
87
+ else
88
+ unchanged << rel_path
89
+ end
74
90
  else
75
- unchanged << rel_path
91
+ added << rel_path
76
92
  end
77
- else
78
- added << rel_path
79
93
  end
80
- end
81
94
 
82
- old_files.each_key do |rel_path|
83
- deleted << rel_path unless new_scan.key?(rel_path)
84
- end
95
+ old_files.each_key do |rel_path|
96
+ deleted << rel_path unless new_scan.key?(rel_path)
97
+ end
85
98
 
86
- languages = @scanner.detect_languages(new_scan)
87
- @mutex.synchronize do
88
- @files = new_scan
89
- @languages = languages
90
- @last_scan_time = Time.now - start_time
91
- end
99
+ languages = @scanner.detect_languages(new_scan)
100
+ report = scanner_report
101
+ @mutex.synchronize do
102
+ @files = new_scan
103
+ @languages = languages
104
+ @last_scan_time = Time.now - start_time
105
+ store_scan_outcome!(report)
106
+ end
92
107
 
93
- {
94
- added: added,
95
- modified: modified,
96
- deleted: deleted,
97
- unchanged: unchanged
98
- }
108
+ {
109
+ added: added,
110
+ modified: modified,
111
+ deleted: deleted,
112
+ unchanged: unchanged
113
+ }
114
+ end
99
115
  end
100
116
 
101
117
  def update_file(rel_path)
@@ -125,10 +141,28 @@ module Rubik
125
141
  {
126
142
  file_count: @files.size,
127
143
  languages: @languages,
128
- last_scan_time_sec: @last_scan_time&.round(4)
144
+ last_scan_time_sec: @last_scan_time&.round(4),
145
+ last_scan_aborted: @last_scan_aborted,
146
+ last_scan_error: @last_scan_error
129
147
  }
130
148
  end
131
149
  end
150
+
151
+ private
152
+
153
+ # Test doubles may not carry last_scan_report; a nil report means a
154
+ # clean scan.
155
+ def scanner_report
156
+ @scanner.respond_to?(:last_scan_report) ? @scanner.last_scan_report : nil
157
+ end
158
+
159
+ # Copies the scanner's completeness verdict under the same lock that
160
+ # publishes the files, so a reader never sees files from an aborted
161
+ # scan without also seeing the flag.
162
+ def store_scan_outcome!(report)
163
+ @last_scan_aborted = report ? report.aborted : false
164
+ @last_scan_error = report&.reasons&.any? ? report.reasons.join("; ") : nil
165
+ end
132
166
  end
133
167
  end
134
168
  end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ module Rubik
6
+ module Context
7
+ # Cheap classifiers for a session root that is likely a huge tree (a
8
+ # home directory, a filesystem root, or OS user-data). Equality and
9
+ # presence probes only — never size probing — so a normal-repo boot
10
+ # pays nothing and prints nothing.
11
+ module RootHeuristics
12
+ # strong: true when a signal reliably implies a full walk can stall
13
+ # the REPL (boot skips the warm scan); gitless alone is a weak
14
+ # aggravator reported in the guidance but never skips the scan.
15
+ Assessment = Struct.new(:reasons, :strong, keyword_init: true)
16
+
17
+ OS_DATA_DIRS = ["AppData", "Library"].freeze
18
+
19
+ module_function
20
+
21
+ def assess(root_dir, home_dir: nil, git_probe: nil)
22
+ root = File.expand_path(root_dir.to_s)
23
+ reasons = []
24
+
25
+ reasons << "root is the user home directory" if home_dir && File.expand_path(home_dir) == root
26
+ reasons << "root is a filesystem root" if filesystem_root?(root)
27
+ os_reason = os_data_dir_reason(root)
28
+ reasons << os_reason if os_reason
29
+
30
+ strong = reasons.any?
31
+
32
+ unless git_work_tree?(root, git_probe)
33
+ reasons << (if strong
34
+ "and is not a git repository (the fallback walker is slow)"
35
+ else
36
+ "root is not a git repository"
37
+ end)
38
+ end
39
+
40
+ Assessment.new(reasons: reasons, strong: strong)
41
+ end
42
+
43
+ # Single home for the guidance wording; reused by boot and !context
44
+ # scan. Empty string when nothing was flagged. A strong verdict also
45
+ # discloses the skipped boot scan so the empty index reads as
46
+ # deliberate, not as a stuck build.
47
+ def guidance(assessment, boot_scan_skipped: false)
48
+ return "" if !assessment || assessment.reasons.empty?
49
+
50
+ tail = boot_scan_skipped ? " The boot-time scan was skipped for this root; run '!context scan' to build the index now." : ""
51
+ "Warning: the session root looks like a huge tree (#{assessment.reasons.join('; ')}). " \
52
+ "Scanning it can be very slow. Consider starting rubik in a project root, " \
53
+ "adding 'context.exclude' entries, or running '!context scan' explicitly to opt in.#{tail}"
54
+ end
55
+
56
+ def filesystem_root?(dir)
57
+ File.dirname(dir) == dir
58
+ end
59
+
60
+ def os_data_dir_reason(root)
61
+ present = begin
62
+ Dir.children(root).any? { |name| OS_DATA_DIRS.include?(name) }
63
+ rescue SystemCallError
64
+ false
65
+ end
66
+ return nil unless present
67
+
68
+ "root contains OS data directories (#{OS_DATA_DIRS.join('/')})"
69
+ end
70
+
71
+ # The .git presence fast path keeps normal repos spawn-free; the probe
72
+ # (one `git rev-parse` spawn) only runs for gitless-looking roots. A
73
+ # failed probe (missing binary, ...) reads as gitless — over-warning
74
+ # by design — but stays discoverable in the log.
75
+ def git_work_tree?(dir, probe)
76
+ return true if File.exist?(File.join(dir, ".git"))
77
+
78
+ probe ||= ->(d) { system_git_probe(d) }
79
+ probe.call(dir)
80
+ rescue StandardError => e
81
+ Rubik::Log.debug(:context, "git probe failed for #{dir} (#{e.class}: #{e.message}); treating as not a repository")
82
+ false
83
+ end
84
+
85
+ def system_git_probe(dir)
86
+ out, _err, status = Open3.capture3("git", "-C", dir, "rev-parse", "--is-inside-work-tree")
87
+ # A bare repo also exits 0 but answers "false" — the verdict is the
88
+ # output, not the exit status.
89
+ status.success? && out.to_s.strip == "true"
90
+ end
91
+ end
92
+ end
93
+ end
@@ -65,7 +65,11 @@ module Rubik
65
65
  "dist/**",
66
66
  "build/**",
67
67
  ".cache/**",
68
- "coverage/**"
68
+ "coverage/**",
69
+ # Multi-GB local model blobs; never project sources.
70
+ ".ollama/**",
71
+ # Agent-harness state: transcripts, sessions, caches.
72
+ ".zcode/**"
69
73
  ].freeze
70
74
 
71
75
  # Subtrees whose ignore pattern is "<path>/**" (optionally with a
@@ -77,10 +81,17 @@ module Rubik
77
81
  # leaked into the index. The walker applies the pattern's plain meaning
78
82
  # (whole subtree ignored), matching real gitignore semantics.
79
83
  PRUNABLE_PATTERN = %r{\A(?:\*\*/)?(.+)/\*\*\z}
80
- # Also hard-rejected inside `ignored?`; pruned here before descending.
81
- HARD_PRUNE_ROOTS = [".git", ".rubik", ".ua", ".turbo", ".sst", ".next", ".nuxt"].freeze
84
+ # Also hard-rejected inside `ignored?`; pruned before descending.
85
+ # ROOT-anchored only (comps.first) to match the rg-side `!/X/**`
86
+ # globs — a nested `src/AppData` stays indexed.
87
+ HARD_PRUNE_ROOTS = [".git", ".rubik", ".ua", ".turbo", ".sst", ".next", ".nuxt", "AppData"].freeze
82
88
 
83
- attr_reader :root_dir, :additional_roots
89
+ # Outcome of the most recent scan. A partial index served as ground
90
+ # truth is worse than an honest flag: every rescue boundary that drops
91
+ # data marks the report so Index can surface the truncation.
92
+ ScanReport = Struct.new(:aborted, :reasons, keyword_init: true)
93
+
94
+ attr_reader :root_dir, :additional_roots, :last_scan_report
84
95
  attr_accessor :custom_includes, :custom_excludes
85
96
 
86
97
  def initialize(root_dir: Dir.pwd, additional_roots: [], includes: [], excludes: [], native: nil)
@@ -106,6 +117,7 @@ module Rubik
106
117
  # may itself be nil — content never hashed), only stat-changed files
107
118
  # are read and re-hashed. Cold entries start hash-less.
108
119
  def scan(previous = {})
120
+ @last_scan_report = ScanReport.new(aborted: false, reasons: [])
109
121
  files = {}
110
122
 
111
123
  # 1. Scan primary root
@@ -123,6 +135,7 @@ module Rubik
123
135
  files
124
136
  rescue StandardError => e
125
137
  Rubik::Log.warn(:context, "context scan aborted partway (#{e.class}: #{e.message}); returning partial index")
138
+ mark_scan_aborted!("scan aborted partway: #{e.class}: #{e.message}")
126
139
  files || {}
127
140
  end
128
141
 
@@ -155,6 +168,16 @@ module Rubik
155
168
 
156
169
  private
157
170
 
171
+ # Records one dropped-data event. The first few reasons suffice for
172
+ # display; the log keeps the full detail.
173
+ def mark_scan_aborted!(reason)
174
+ @last_scan_report ||= ScanReport.new(aborted: false, reasons: [])
175
+ @last_scan_report.aborted = true
176
+ return if @last_scan_report.reasons.length >= 5
177
+
178
+ @last_scan_report.reasons << reason.to_s[0, 160]
179
+ end
180
+
158
181
  # Stat-dirty model (à la git): a previous entry whose size and mtime
159
182
  # (microsecond precision) both match is NEVER read from disk — its
160
183
  # content hash is reused verbatim, including when it is nil (content
@@ -210,7 +233,9 @@ module Rubik
210
233
  # workspace_xml entry_points listing) stays deterministic.
211
234
  entries = begin
212
235
  Dir.foreach(current).sort - [".", ".."]
213
- rescue SystemCallError
236
+ rescue SystemCallError => e
237
+ Rubik::Log.warn(:context, "directory unreadable: #{current} (#{e.class}: #{e.message})")
238
+ mark_scan_aborted!("directory unreadable: #{current}")
214
239
  []
215
240
  end
216
241
 
@@ -250,6 +275,7 @@ module Rubik
250
275
  out
251
276
  rescue StandardError => e
252
277
  Rubik::Log.warn(:context, "directory walk failed under #{base_dir} (#{e.class}: #{e.message}); keeping partial results")
278
+ mark_scan_aborted!("directory walk failed under #{base_dir}: #{e.class}: #{e.message}")
253
279
  out
254
280
  end
255
281
 
@@ -306,6 +332,7 @@ module Rubik
306
332
  walk_dir(base_dir, "", prefix, ignore_patterns, previous, needles)
307
333
  rescue StandardError => e
308
334
  Rubik::Log.warn(:context, "root scan failed for #{base_dir} (#{e.class}: #{e.message}); root omitted from index")
335
+ mark_scan_aborted!("root scan failed for #{base_dir}: #{e.class}: #{e.message}")
309
336
  {}
310
337
  end
311
338
 
@@ -365,6 +392,7 @@ module Rubik
365
392
  out
366
393
  rescue StandardError => e
367
394
  Rubik::Log.warn(:context, "git ls-files fast path failed for #{base_dir} (#{e.class}: #{e.message}); keeping partial index")
395
+ mark_scan_aborted!("git ls-files fast path failed for #{base_dir}: #{e.class}: #{e.message}")
368
396
  out
369
397
  end
370
398
 
data/lib/rubik/context.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "context/scanner"
4
4
  require_relative "context/index"
5
+ require_relative "context/root_heuristics"
5
6
  require_relative "context/git_info"
6
7
  require_relative "context/repo_context_reader"
7
8
 
@@ -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