rubik 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +34 -1
  4. data/lib/rubik/ast/c_extractor.rb +1 -1
  5. data/lib/rubik/ast/graph.rb +38 -57
  6. data/lib/rubik/ast/graph_extensions.rb +57 -15
  7. data/lib/rubik/ast/ruby_extractor.rb +4 -0
  8. data/lib/rubik/ast/treesitter/c_walker.rb +11 -3
  9. data/lib/rubik/buffer/manager.rb +33 -11
  10. data/lib/rubik/buffer/snapshot.rb +23 -3
  11. data/lib/rubik/cli/connect.rb +3 -5
  12. data/lib/rubik/config/defaults.rb +3 -7
  13. data/lib/rubik/config/env_guard.rb +43 -0
  14. data/lib/rubik/config/schema.rb +7 -1
  15. data/lib/rubik/config/secret_policy.rb +6 -5
  16. data/lib/rubik/config.rb +1 -1
  17. data/lib/rubik/connect/models_dev.rb +9 -0
  18. data/lib/rubik/connect/probes.rb +9 -2
  19. data/lib/rubik/connect/wizard.rb +108 -56
  20. data/lib/rubik/context/repo_context_reader.rb +8 -4
  21. data/lib/rubik/llm/chunk_assembler.rb +12 -1
  22. data/lib/rubik/llm/formatter.rb +14 -0
  23. data/lib/rubik/llm/provider_key.rb +32 -0
  24. data/lib/rubik/llm/registry.rb +18 -2
  25. data/lib/rubik/llm/router.rb +19 -1
  26. data/lib/rubik/llm/session_header.rb +128 -0
  27. data/lib/rubik/llm/sse_parser.rb +57 -10
  28. data/lib/rubik/lsp/client.rb +11 -5
  29. data/lib/rubik/lsp/transport.rb +17 -7
  30. data/lib/rubik/mcp/transport/stdio.rb +42 -4
  31. data/lib/rubik/orchestrator/continuation_manager.rb +14 -5
  32. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +18 -2
  33. data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +13 -4
  34. data/lib/rubik/orchestrator/goal_ledger/validator.rb +46 -7
  35. data/lib/rubik/orchestrator/goal_ledger/verifier.rb +8 -1
  36. data/lib/rubik/orchestrator/goal_session.rb +4 -4
  37. data/lib/rubik/orchestrator/loop.rb +8 -11
  38. data/lib/rubik/orchestrator/provider_resolver.rb +29 -6
  39. data/lib/rubik/orchestrator/step_executor.rb +17 -2
  40. data/lib/rubik/orchestrator/subagent/instance.rb +24 -1
  41. data/lib/rubik/orchestrator/subagent/notices.rb +1 -1
  42. data/lib/rubik/orchestrator/subagent/reaper.rb +21 -2
  43. data/lib/rubik/orchestrator/subagent/start_gate.rb +1 -1
  44. data/lib/rubik/orchestrator/subagent/step_runner.rb +7 -7
  45. data/lib/rubik/orchestrator/subagent/supervisor.rb +10 -3
  46. data/lib/rubik/orchestrator/turn_executor/user_channel.rb +27 -5
  47. data/lib/rubik/orchestrator/turn_executor.rb +24 -8
  48. data/lib/rubik/platform/filesystem.rb +52 -24
  49. data/lib/rubik/plugin/storage.rb +20 -0
  50. data/lib/rubik/prompt/context_builder.rb +2 -1
  51. data/lib/rubik/repair/loop.rb +22 -2
  52. data/lib/rubik/repl/commands/agent_context.rb +1 -1
  53. data/lib/rubik/repl/commands/agent_execution.rb +20 -15
  54. data/lib/rubik/repl/commands/buffer.rb +15 -0
  55. data/lib/rubik/repl/commands/connect.rb +0 -1
  56. data/lib/rubik/repl/commands/lsp.rb +1 -1
  57. data/lib/rubik/repl/commands/plugins.rb +31 -31
  58. data/lib/rubik/repl/commands/session.rb +5 -5
  59. data/lib/rubik/repl/commands/workspace.rb +4 -4
  60. data/lib/rubik/repl/input_execution.rb +30 -29
  61. data/lib/rubik/repl/input_loop.rb +9 -4
  62. data/lib/rubik/repl/lifecycle.rb +1 -2
  63. data/lib/rubik/repl/notice_router.rb +11 -5
  64. data/lib/rubik/repl/paste_support.rb +1 -1
  65. data/lib/rubik/repl/prompt_grace.rb +3 -3
  66. data/lib/rubik/repl/shell.rb +10 -2
  67. data/lib/rubik/repl/turn_recorder.rb +14 -3
  68. data/lib/rubik/runtime/context.rb +33 -27
  69. data/lib/rubik/runtime/manager.rb +23 -15
  70. data/lib/rubik/sandbox/driver/bubblewrap.rb +58 -8
  71. data/lib/rubik/sandbox/driver/process.rb +32 -1
  72. data/lib/rubik/sandbox/runner.rb +9 -1
  73. data/lib/rubik/security/classifier/classifier.rb +147 -13
  74. data/lib/rubik/security/classifier/commands/docker.yaml +1 -1
  75. data/lib/rubik/security/classifier/commands/git.yaml +27 -1
  76. data/lib/rubik/security/classifier/commands/sed.yaml +3 -3
  77. data/lib/rubik/security/classifier/database.rb +2 -2
  78. data/lib/rubik/security/command_gate.rb +8 -1
  79. data/lib/rubik/security/redactor.rb +62 -19
  80. data/lib/rubik/session/recorder.rb +13 -18
  81. data/lib/rubik/session/replayer.rb +29 -7
  82. data/lib/rubik/storage/store.rb +19 -5
  83. data/lib/rubik/tools/builtins/exec.rb +1 -1
  84. data/lib/rubik/tools/builtins/files.rb +8 -12
  85. data/lib/rubik/tools/builtins/grep.rb +3 -2
  86. data/lib/rubik/tools/builtins/lsp.rb +31 -7
  87. data/lib/rubik/tools/builtins/show_file.rb +1 -1
  88. data/lib/rubik/tools/builtins/synthesis.rb +4 -4
  89. data/lib/rubik/tools/result_normalizer.rb +1 -1
  90. data/lib/rubik/ui/banner.rb +3 -3
  91. data/lib/rubik/ui/dialog.rb +10 -7
  92. data/lib/rubik/ui/diff_viewer.rb +4 -4
  93. data/lib/rubik/ui/frame.rb +13 -3
  94. data/lib/rubik/ui/markdown_stream.rb +8 -2
  95. data/lib/rubik/ui/panel.rb +11 -11
  96. data/lib/rubik/ui/renderer.rb +6 -6
  97. data/lib/rubik/ui/spinner.rb +1 -1
  98. data/lib/rubik/ui/statusline.rb +3 -3
  99. data/lib/rubik/ui/theme.rb +1 -1
  100. data/lib/rubik/version.rb +1 -1
  101. metadata +4 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6a9e85889683534d644e9f88c1f076dce8e91e0503a2e40a823149d6d1ca359
4
- data.tar.gz: 925f5cfb990e06c0f7d1b9ac4911db249853bfde78e9902c20b104b114541f5e
3
+ metadata.gz: a649ff3579ecb32b3d69eae6e53f48a8eb44f9c54a44d847860ed1889284a265
4
+ data.tar.gz: a2a9c1a7ab5ed4d5d769c513fa904ebdbc285fef8f00b1fc9e6dd14c127dbf27
5
5
  SHA512:
6
- metadata.gz: 2b8c173c30baa1c4b9ad7b9cfdc9baabd98d8c8191569693a7baba5299d03448d0ed1f6f163e7b9d4ea77c9732fdb4f2ad47a8959304758f9f9cc0f4d6548df5
7
- data.tar.gz: 409d010dc7e497735871c2e0f84690675f10c0e00750137dea7c1cd6ee93a44c94c861b2d1345f8ac4a005e3801bf76506c2c7f0858681eb0e8f807d2a414292
6
+ metadata.gz: e4679732a909f8bb62ecc0f3b43e3489c86220b717e501896355054235b217f6b4148e70795715a3dcb6eb9b53323ca9ec3d29bbc9d0fad524092d28cd157352
7
+ data.tar.gz: 95f47090b296dbf632c3a941ef8e34ce2cc849ca7a0c95e3b24751e1087a16a5dd1fbd3cef1d5dc8c6e492c0461d4f2a349b6fdfbeebe6c69c3186608a734e20
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,700+ unit, integration, and contract tests. |
124
+ | **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,900+ 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
@@ -8,6 +8,38 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.14.0] - 2026-11-19
12
+
13
+ The session-attribution minor: gateway plumbing that needed a stable
14
+ per-conversation identity arrives as a provider-scoped `session_header`
15
+ knob, subagent lanes learn provider-scoped retry knobs, the UI goes
16
+ English — and a large fix wave hardens sandboxing, the security
17
+ classifier, buffers, the AST graph, transports and the goal ledger.
18
+
19
+ ### Added
20
+
21
+ - **Dynamic session header (`providers.<name>.session_header`):** gateways
22
+ that require per-conversation session attribution — opencode's Go gateway
23
+ hard-400s every request with `MissingSessionID` without
24
+ `x-opencode-session` — are now first-class. Setting the knob on a
25
+ provider spec makes every LLM request (root loop, subagents, and repair
26
+ when its caller forwards `session_key`) carry
27
+ `headers[<name>] = <UUID derived from the active session file>`, stable
28
+ per conversation across `!resume` and restarts. A same-named header set
29
+ explicitly in `providers.<name>.headers` or `llm.headers` wins —
30
+ explicit beats automatic.
31
+
32
+ ### Changed
33
+
34
+ - Subagent lanes now honor provider-scoped `providers.<name>.<retry-knob>`
35
+ overrides (`max_retries`, `max_429_retries`, backoff, wall clock, ...)
36
+ through the same `ProviderResolver` seam as the root loop — previously
37
+ only the global `llm.*` spelling reached them.
38
+ - User-facing REPL, CLI and UI messages now render in English. Bilingual
39
+ Turkish/English strings keep only the English half; `Vakanüvis` domain
40
+ vocabulary, Turkish test fixtures and the generated `TOOLS.md` are
41
+ intentionally unchanged. Turkish resume phrases (`devam et`) still work.
42
+
11
43
  ## [0.13.0] - 2026-11-17
12
44
 
13
45
  The connect-wizard minor: provider binding collapses into an interactive
@@ -1820,7 +1852,8 @@ installation section.
1820
1852
  - Context: serialized index mutations, snapshot-outside-lock reconcile,
1821
1853
  streaming-first truncation.
1822
1854
 
1823
- [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.13.0...HEAD
1855
+ [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.14.0...HEAD
1856
+ [0.14.0]: https://github.com/ozgurulukir/rubik/compare/v0.13.0...v0.14.0
1824
1857
  [0.13.0]: https://github.com/ozgurulukir/rubik/compare/v0.12.0...v0.13.0
1825
1858
  [0.12.0]: https://github.com/ozgurulukir/rubik/compare/v0.11.0...v0.12.0
1826
1859
  [0.11.0]: https://github.com/ozgurulukir/rubik/compare/v0.10.0...v0.11.0
@@ -40,7 +40,7 @@ module Rubik
40
40
  signature: stripped
41
41
  )
42
42
  elsif (match = stripped.match(/^(?:typedef\s+)?(struct|union|enum)\s+([A-Za-z0-9_]+)?\s*\{?/))
43
- name = match[2] || "anonymous_#{kind}_#{line_num}"
43
+ name = match[2] || "anonymous_#{match[1]}_#{line_num}"
44
44
  end_line = stripped.include?(";") && !stripped.include?("{") ? line_num : find_closing_brace(i)
45
45
  symbols << Symbol.new(
46
46
  name: name,
@@ -144,84 +144,65 @@ module Rubik
144
144
  end
145
145
 
146
146
  def smart_context_for(symbol_name)
147
- @mutex.synchronize do
147
+ target, dependencies = @mutex.synchronize do
148
148
  candidates = _symbol_candidate_pairs_unlocked(symbol_name)
149
- return "" unless candidates.length == 1
149
+ next nil unless candidates.length == 1
150
150
 
151
151
  target = candidates.first.last
152
- context_blocks = []
153
- context_blocks << "# Target symbol: #{target.name} (#{target.file}:#{target.line_start}-#{target.line_end})"
154
- context_blocks << target.body if target.body
155
-
152
+ target_scope = _symbol_scope(target.name)
153
+ deps = []
156
154
  target.calls.each do |called_name|
157
155
  dep_candidates = _symbol_candidate_pairs_unlocked(called_name).map(&:last)
158
- target_scope = _symbol_scope(target.name)
159
156
  matching = dep_candidates.find { |s| s.file && target.file && Rubik::Platform.path_equal?(s.file, target.file) && _symbol_scope(s.name) == target_scope } ||
160
157
  dep_candidates.find { |s| s.file && target.file && Rubik::Platform.path_equal?(s.file, target.file) } ||
161
158
  (dep_candidates.first if dep_candidates.length == 1)
162
- if matching
163
- context_blocks << "# Dependency signature: #{matching.name}"
164
- context_blocks << matching.signature
165
- end
159
+ deps << matching if matching
166
160
  end
167
-
168
- context_blocks.join("\n\n")
161
+ [target, deps]
162
+ end
163
+ return "" unless target
164
+
165
+ # Symbol#body can fall back to File.readlines; keep that disk I/O
166
+ # outside the graph lock so it cannot serialize concurrent readers.
167
+ body = target.body
168
+ context_blocks = []
169
+ context_blocks << "# Target symbol: #{target.name} (#{target.file}:#{target.line_start}-#{target.line_end})"
170
+ context_blocks << body if body
171
+
172
+ dependencies.each do |matching|
173
+ context_blocks << "# Dependency signature: #{matching.name}"
174
+ context_blocks << matching.signature
169
175
  end
176
+
177
+ context_blocks.join("\n\n")
170
178
  end
171
179
 
172
180
  def outline_for(file_path)
173
- @mutex.synchronize do
174
- syms = _get_file_symbols_unlocked(file_path)
175
- syms = _index_file_unlocked(file_path) if syms.empty? && File.exist?(file_path)
181
+ # Snapshot under the lock, but do the parse/source read outside it:
182
+ # the extractor reads from disk and is the slowest path through here.
183
+ syms = @mutex.synchronize { _get_file_symbols_unlocked(file_path).dup }
184
+ if syms.empty?
185
+ return "No symbols found in '#{file_path}'." unless File.exist?(file_path)
186
+
187
+ result = Extractor.extract_result(file_path, nil)
188
+ # Re-acquire only to merge the parse into the in-memory maps.
189
+ syms = @mutex.synchronize { _merge_extraction_result_unlocked(file_path, result).dup }
190
+ end
176
191
 
177
- return "No symbols found in '#{file_path}'." if syms.empty?
192
+ return "No symbols found in '#{file_path}'." if syms.empty?
178
193
 
179
- lines = ["=== Outline for #{file_path} (#{syms.size} symbols) ==="]
180
- syms.sort_by(&:line_start).each do |sym|
181
- indent = [:class, :struct, :module, :interface, :type].include?(sym.kind) ? "" : " "
182
- lines << "#{indent}• [#{sym.kind.to_s.upcase}] #{sym.name} (lines #{sym.line_start}-#{sym.line_end}) -> #{sym.signature}"
183
- end
184
- lines.join("\n")
194
+ lines = ["=== Outline for #{file_path} (#{syms.size} symbols) ==="]
195
+ syms.sort_by(&:line_start).each do |sym|
196
+ indent = [:class, :struct, :module, :interface, :type].include?(sym.kind) ? "" : " "
197
+ lines << "#{indent}• [#{sym.kind.to_s.upcase}] #{sym.name} (lines #{sym.line_start}-#{sym.line_end}) -> #{sym.signature}"
185
198
  end
199
+ lines.join("\n")
186
200
  end
187
201
 
188
202
  private
189
203
 
190
204
  def _index_file_unlocked(file_path, content = nil)
191
- result = Extractor.extract_result(file_path, content)
192
- @extraction_status[file_path] = result.status
193
-
194
- # A failed extraction must not silently DELETE the file's previously
195
- # indexed symbols (issue #147): stale-but-known beats unknown, and
196
- # the log line makes the downgrade visible. The best-effort symbols
197
- # are only indexed when there is nothing to protect.
198
- if result.status == :failed
199
- existing = _get_file_symbols_unlocked(file_path)
200
- unless existing.empty?
201
- Rubik::Log.warn(:ast, "extraction failed for #{file_path} (#{result.detail}); keeping previously indexed symbols")
202
- return existing
203
- end
204
- end
205
-
206
- _remove_file_unlocked(file_path)
207
-
208
- ext = File.extname(file_path).downcase
209
- lang = CacheStore::LANGUAGE_MAP[ext] || "code"
210
-
211
- extracted = result.symbols
212
- if result.status == :failed
213
- # Truthful accounting: the fallback symbols ARE indexed when
214
- # nothing pre-existing needed protection — even when there are
215
- # none, the log must not claim otherwise.
216
- Rubik::Log.warn(:ast, "extraction failed for #{file_path} (#{result.detail}); indexing #{extracted.length} best-effort fallback symbols")
217
- end
218
- extracted.each do |sym|
219
- @symbols[sym.name] = sym
220
- q_key = "#{lang}:#{file_path}##{sym.name}"
221
- @qualified_symbols[q_key] = sym
222
- @file_symbols[file_path] << sym
223
- end
224
- extracted
205
+ _merge_extraction_result_unlocked(file_path, Extractor.extract_result(file_path, content))
225
206
  end
226
207
 
227
208
  def _remove_file_unlocked(file_path, clear_status: false)
@@ -191,27 +191,69 @@ module Rubik
191
191
  end
192
192
 
193
193
  def symbol_definition(symbol_name)
194
- @mutex.synchronize do
194
+ target = @mutex.synchronize do
195
195
  candidates = _symbol_candidate_pairs_unlocked(symbol_name)
196
- return nil unless candidates.length == 1
197
-
198
- target = candidates.first.last
199
- {
200
- name: target.name,
201
- kind: target.kind,
202
- file: target.file,
203
- line_start: target.line_start,
204
- line_end: target.line_end,
205
- signature: target.signature,
206
- body: target.body,
207
- docstring: target.docstring,
208
- calls: target.calls
209
- }
196
+ next nil unless candidates.length == 1
197
+
198
+ candidates.first.last
210
199
  end
200
+ return nil unless target
201
+
202
+ # Symbol#body can fall back to File.readlines; read it outside the
203
+ # graph lock so it cannot serialize concurrent readers (issue #560).
204
+ {
205
+ name: target.name,
206
+ kind: target.kind,
207
+ file: target.file,
208
+ line_start: target.line_start,
209
+ line_end: target.line_end,
210
+ signature: target.signature,
211
+ body: target.body,
212
+ docstring: target.docstring,
213
+ calls: target.calls
214
+ }
211
215
  end
212
216
 
213
217
  private
214
218
 
219
+ # Caller must hold @mutex. outline_for does the (disk-reading) extraction
220
+ # outside the lock and only merges the finished result through here.
221
+ def _merge_extraction_result_unlocked(file_path, result)
222
+ @extraction_status[file_path] = result.status
223
+
224
+ # A failed extraction must not silently DELETE the file's previously
225
+ # indexed symbols (issue #147): stale-but-known beats unknown, and
226
+ # the log line makes the downgrade visible. The best-effort symbols
227
+ # are only indexed when there is nothing to protect.
228
+ if result.status == :failed
229
+ existing = _get_file_symbols_unlocked(file_path)
230
+ unless existing.empty?
231
+ Rubik::Log.warn(:ast, "extraction failed for #{file_path} (#{result.detail}); keeping previously indexed symbols")
232
+ return existing
233
+ end
234
+ end
235
+
236
+ _remove_file_unlocked(file_path)
237
+
238
+ ext = File.extname(file_path).downcase
239
+ lang = CacheStore::LANGUAGE_MAP[ext] || "code"
240
+
241
+ extracted = result.symbols
242
+ if result.status == :failed
243
+ # Truthful accounting: the fallback symbols ARE indexed when
244
+ # nothing pre-existing needed protection — even when there are
245
+ # none, the log must not claim otherwise.
246
+ Rubik::Log.warn(:ast, "extraction failed for #{file_path} (#{result.detail}); indexing #{extracted.length} best-effort fallback symbols")
247
+ end
248
+ extracted.each do |sym|
249
+ @symbols[sym.name] = sym
250
+ q_key = "#{lang}:#{file_path}##{sym.name}"
251
+ @qualified_symbols[q_key] = sym
252
+ @file_symbols[file_path] << sym
253
+ end
254
+ extracted
255
+ end
256
+
215
257
  def _search_rank(name, query)
216
258
  return 0 if name == query
217
259
  return 1 if name.start_with?(query)
@@ -121,6 +121,10 @@ module Rubik
121
121
  body_loader: body_loader_for(line_start, line_end)
122
122
  )
123
123
 
124
+ # Nested defs/classes live under the DefNode; without this walk the
125
+ # Prism path drops symbols the fallback scanner still finds.
126
+ node.compact_child_nodes.each { |child| walk_node(child, current_scope, symbols) }
127
+
124
128
  when Prism::CallNode
125
129
  name = node.name.to_s
126
130
  # PERF: Fast Set lookup avoids Array allocation on every CallNode
@@ -29,6 +29,13 @@ module Rubik
29
29
  "union_specifier" => :union
30
30
  }.freeze
31
31
 
32
+ # A typedef's kind follows its underlying type, not a hardcoded :struct.
33
+ TYPEDEF_KINDS = {
34
+ "struct_specifier" => :struct,
35
+ "union_specifier" => :union,
36
+ "enum_specifier" => :enum
37
+ }.freeze
38
+
32
39
  DECLARATOR_WRAPPERS = [
33
40
  "function_declarator", "pointer_declarator", "reference_declarator", "parenthesized_declarator"
34
41
  ].freeze
@@ -87,22 +94,23 @@ module Rubik
87
94
  end
88
95
 
89
96
  def walk_typedef(node, symbols, scope)
97
+ type_node = node.child_by_field_name("type")
90
98
  declarator = node.child_by_field_name("declarator")
91
99
  name = if declarator
92
100
  text_for(declarator).strip
93
101
  else
94
- type_node = node.child_by_field_name("type")
95
102
  text_for(type_node&.child_by_field_name("name")).strip
96
103
  end
97
104
  return if name.empty?
98
105
 
106
+ kind = TYPEDEF_KINDS.fetch(type_node&.kind, :type)
99
107
  qualified = qualify(scope, name)
100
108
  sig = clean_signature(node)
101
109
  symbols << build_symbol(
102
110
  name: qualified,
103
- kind: :struct,
111
+ kind: kind,
104
112
  node: node,
105
- signature: sig.empty? ? "typedef struct #{qualified}" : sig
113
+ signature: sig.empty? ? "typedef #{kind} #{qualified}" : sig
106
114
  )
107
115
  end
108
116
 
@@ -38,7 +38,7 @@ module Rubik
38
38
  class Manager
39
39
  attr_reader :root_dir, :dirty_files, :additional_roots, :rw_roots, :allowed_external_dirs, :rw_allowed_dirs,
40
40
  :guard, :last_conflicts, :last_skipped
41
- attr_accessor :allow_external_writes, :config
41
+ attr_accessor :allow_external_writes, :config, :snapshot_store
42
42
 
43
43
  def initialize(root_dir: Dir.pwd, additional_roots: [], allowed_external_dirs: [], allow_external_writes: false,
44
44
  event_bus: nil, guard: nil, config: nil)
@@ -170,7 +170,11 @@ module Rubik
170
170
  rel_or_exp
171
171
  end
172
172
 
173
- # Reads a file from the buffer (if dirty) or from disk, normalizing newlines.
173
+ # Reads a file from the buffer (if dirty) or from disk. Raw bytes —
174
+ # including CRLF line endings — are preserved end-to-end: a read/edit/
175
+ # write cycle on a CRLF file must not rewrite every line ending to LF
176
+ # (issue #544). Newline normalization is confined to conflict-detection
177
+ # hashing, never to the content that is buffered or applied to disk.
174
178
  #
175
179
  # @param path [String] file path relative to the root directory
176
180
  # @param reload [Boolean] force reload from disk, discarding in-memory buffer if present
@@ -190,7 +194,7 @@ module Rubik
190
194
  full_path = File.expand_path(rel_path, @root_dir)
191
195
  return nil unless File.exist?(full_path)
192
196
 
193
- return Rubik::Platform.normalize_newlines(Rubik::Platform.read_text(full_path))
197
+ return read_bytes_as_utf8(full_path)
194
198
  elsif @buffer.key?(rel_path)
195
199
  return @buffer[rel_path]
196
200
  end
@@ -198,7 +202,7 @@ module Rubik
198
202
  full_path = File.expand_path(rel_path, @root_dir)
199
203
  return nil unless File.exist?(full_path)
200
204
 
201
- content = Rubik::Platform.normalize_newlines(Rubik::Platform.read_text(full_path))
205
+ content = read_bytes_as_utf8(full_path)
202
206
  @original_hashes[rel_path] = Digest::SHA256.hexdigest(content)
203
207
  content
204
208
  end
@@ -219,17 +223,25 @@ module Rubik
219
223
  def write(path, content, reset_baseline: false)
220
224
  @monitor.synchronize do
221
225
  rel_path = sanitize_path(path, for_write: true)
222
- normalized_content = Rubik::Platform.normalize_newlines(content)
223
-
224
226
  if reset_baseline || !@original_hashes.key?(rel_path)
225
227
  full_path = File.expand_path(rel_path, @root_dir)
226
- @original_hashes[rel_path] = (Digest::SHA256.hexdigest(Rubik::Platform.normalize_newlines(Rubik::Platform.read_text(full_path))) if File.exist?(full_path))
228
+ @original_hashes[rel_path] = (Digest::SHA256.hexdigest(read_bytes_as_utf8(full_path)) if File.exist?(full_path))
227
229
  end
228
230
 
229
- @buffer[rel_path] = normalized_content
231
+ @buffer[rel_path] = content
230
232
  @dirty_files[rel_path] = true
231
233
  @event_bus&.emit(:buffer_changed, path: rel_path)
232
- normalized_content
234
+
235
+ # Give the advertised !undo / !rollback commands a producer in
236
+ # the live write path (issue #544). Snapshotting is auxiliary:
237
+ # a storage failure must not turn a successful edit into a
238
+ # failed write.
239
+ begin
240
+ @snapshot_store&.create_snapshot(self)
241
+ rescue StandardError => e
242
+ warn "[Buffer] snapshot recording failed: #{e.class}: #{e.message}"
243
+ end
244
+ content
233
245
  end
234
246
  end
235
247
 
@@ -309,7 +321,7 @@ module Rubik
309
321
 
310
322
  diffs = snapshot.map do |rel_path, new_content|
311
323
  full_path = File.expand_path(rel_path, @root_dir)
312
- orig_content = File.exist?(full_path) ? Rubik::Platform.normalize_newlines(Rubik::Platform.read_text(full_path)) : ""
324
+ orig_content = File.exist?(full_path) ? read_bytes_as_utf8(full_path) : ""
313
325
  Diff.unified_diff(rel_path, orig_content, new_content)
314
326
  end
315
327
 
@@ -420,10 +432,20 @@ module Rubik
420
432
  full_path = File.expand_path(rel_path, @root_dir)
421
433
  return nil unless File.exist?(full_path)
422
434
 
423
- Digest::SHA256.hexdigest(Rubik::Platform.normalize_newlines(Rubik::Platform.read_text(full_path)))
435
+ Digest::SHA256.hexdigest(read_bytes_as_utf8(full_path))
424
436
  rescue Errno::ENOENT, Errno::EACCES
425
437
  nil
426
438
  end
439
+
440
+ private
441
+
442
+ # Platform.read_text uses File.read (text mode), which translates
443
+ # CRLF to LF on Windows and would silently break the raw-byte
444
+ # newline contract (issue #544). File.binread keeps the bytes;
445
+ # safe_utf8 re-tags and scrubs exactly as read_text does.
446
+ def read_bytes_as_utf8(full_path)
447
+ Rubik::Platform.safe_utf8(File.binread(full_path))
448
+ end
427
449
  end
428
450
  end
429
451
  end
@@ -4,6 +4,7 @@ require "zlib"
4
4
  require "json"
5
5
  require "fileutils"
6
6
  require "securerandom"
7
+ require_relative "../platform"
7
8
 
8
9
  module Rubik
9
10
  module Buffer
@@ -45,13 +46,26 @@ module Rubik
45
46
  class SnapshotStore
46
47
  attr_reader :storage_dir, :snapshots
47
48
 
48
- def initialize(storage_dir: File.join(ENV.fetch("HOME", nil), ".rubik", "snapshots", "default"))
49
+ def initialize(storage_dir: File.join(Rubik::Platform.home_dir, ".rubik", "snapshots", "default"))
49
50
  @storage_dir = storage_dir
50
51
  @snapshots = []
51
52
  @current_index = -1
53
+ # The state undo-to-beginning restores. Defaults to a clean
54
+ # buffer; consumers that snapshot a pre-existing dirty buffer
55
+ # (e.g. Repair::Loop) record that state explicitly so an aborted
56
+ # operation restores the pending edits instead of wiping them
57
+ # (issue #544).
58
+ @baseline = {}
52
59
  FileUtils.mkdir_p(@storage_dir)
53
60
  end
54
61
 
62
+ # Records the state that a full undo should restore. Call once,
63
+ # before the first snapshot, when the buffer already holds edits
64
+ # that must survive an aborted operation.
65
+ def record_baseline(buffer_manager)
66
+ @baseline = buffer_manager.snapshot_state
67
+ end
68
+
55
69
  def create_snapshot(buffer_manager)
56
70
  return nil unless buffer_manager.dirty?
57
71
 
@@ -63,7 +77,13 @@ module Rubik
63
77
  file_path = File.join(@storage_dir, "#{snapshot.id}.zdeflate")
64
78
  File.binwrite(file_path, snapshot.compress)
65
79
 
66
- @snapshots = @snapshots[0..@current_index] if @current_index < @snapshots.size - 1
80
+ # Clamp the redo truncation: with @current_index == -1 the range
81
+ # [0..-1] is the WHOLE array, so a fresh snapshot after undoing
82
+ # to empty would be appended after stale snapshots and a later
83
+ # undo would resurrect the discarded edit (issue #544).
84
+ if @current_index < @snapshots.size - 1
85
+ @snapshots = @current_index.negative? ? [] : @snapshots[0..@current_index]
86
+ end
67
87
 
68
88
  @snapshots << snapshot
69
89
  @current_index = @snapshots.size - 1
@@ -74,7 +94,7 @@ module Rubik
74
94
  return false if @current_index.negative?
75
95
 
76
96
  if @current_index.zero?
77
- buffer_manager.restore_snapshot_state({})
97
+ buffer_manager.restore_snapshot_state(@baseline)
78
98
  @current_index = -1
79
99
  return true
80
100
  end
@@ -23,7 +23,6 @@ module Rubik
23
23
  end
24
24
  if argv.intersect?(["--session", "-s"])
25
25
  output.puts USAGE
26
- output.puts " rubik connect yalnızca kalıcı kapsamlara yazar; oturum-kapsamı için REPL içinde !provider add kullanın."
27
26
  output.puts " rubik connect writes persistent scopes only; use !provider add in the REPL for a session-scoped provider."
28
27
  return 1
29
28
  end
@@ -38,12 +37,11 @@ module Rubik
38
37
  result = wizard.run
39
38
 
40
39
  if result[:reason] == :non_interactive
41
- output.puts "Etkileşimsiz oturum — sihirbaz çalışamaz. 'rubik' ile REPL başlatıp !connect kullanın " \
42
- "veya !provider add <name> [type] <url> [--key=...] sözdizimini uygulayın."
43
- output.puts "Non-interactive session — start the REPL and run !connect, or use !provider add flags."
40
+ output.puts "Non-interactive session — the wizard cannot run. Start the REPL with 'rubik' and use !connect, " \
41
+ "or apply the !provider add <name> [type] <url> [--key=...] syntax."
44
42
  return 2
45
43
  end
46
- output.puts "Çıkmak için 'rubik' ile REPL'i başlatın / Start the REPL with 'rubik'." if result[:ok]
44
+ output.puts "Start the REPL with 'rubik'." if result[:ok]
47
45
  result[:ok] ? 0 : 1
48
46
  end
49
47
  end
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../platform"
4
+ require_relative "env_guard"
4
5
 
5
6
  module Rubik
6
7
  class Config
7
8
  module Defaults
9
+ include EnvGuard
10
+
8
11
  # llm.* transport-resilience fallbacks, reused by both orchestrator seams.
9
12
  LLM_RETRY_DEFAULTS = { "max_retries" => 2, "max_429_retries" => 5, "backoff_base" => 0.2,
10
13
  "max_wall_clock" => 120, "rate_limit_max_delay" => 60 }.freeze
@@ -231,13 +234,6 @@ module Rubik
231
234
 
232
235
  private
233
236
 
234
- # Schema-backed keys must satisfy their spec wherever the merged tree is validated.
235
- def validate_typed_value!(key, value)
236
- return unless Schema::DEFINITIONS.key?(key.to_s)
237
-
238
- Schema.validate_value!(key, value, strict: true)
239
- end
240
-
241
237
  def validate_schema(config, schema = DEFAULT_CONFIG, prefix = "", strict: false)
242
238
  raise ArgumentError, "Configuration must be a Hash, got #{config.class}" unless config.is_a?(Hash)
243
239
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubik
4
+ class Config
5
+ # Issue #561: typed-value validation shared by explicit writes and the
6
+ # boot-time env layer, plus the fail-soft env guard. Kept out of
7
+ # defaults.rb so the schema/default tables stay inside the file-size
8
+ # hygiene limit.
9
+ module EnvGuard
10
+ private
11
+
12
+ # Explicit writes (Config#set / Scoped#set) keep strict validation;
13
+ # boot-time env validation passes strict: false so a malformed RUBIK_*
14
+ # variable is dropped with a warning instead of crashing Config.new.
15
+ def validate_typed_value!(key, value, strict: true)
16
+ return true unless Schema::DEFINITIONS.key?(key.to_s)
17
+
18
+ Schema.validate_value!(key, value, strict: strict)
19
+ end
20
+
21
+ # Walk the env layer's typed leaves and remove any schema-backed value
22
+ # that fails its spec, recording a warning instead of raising. Mutates
23
+ # and returns the layer so the merged config never sees the rejected
24
+ # value (and cannot resurrect it on a later set).
25
+ def validate_env_layer!(layer, warnings, prefix = "")
26
+ return layer unless layer.is_a?(Hash)
27
+
28
+ layer.each_key do |key|
29
+ full = prefix.empty? ? key.to_s : "#{prefix}.#{key}"
30
+ val = layer[key]
31
+ if val.is_a?(Hash)
32
+ validate_env_layer!(val, warnings, full)
33
+ elsif Schema::DEFINITIONS.key?(full) && !validate_typed_value!(full, val, strict: false)
34
+ warnings << "[CONFIG] Ignoring invalid environment value '#{full}=#{val.inspect}'; " \
35
+ "using the configured default instead."
36
+ layer.delete(key)
37
+ end
38
+ end
39
+ layer
40
+ end
41
+ end
42
+ end
43
+ end
@@ -166,7 +166,13 @@ module Rubik
166
166
  when :integer
167
167
  val.strip =~ /^-?\d+$/ ? val.strip.to_i : val
168
168
  when :float
169
- val.strip =~ /^-?\d+(\.\d+)?$/ ? val.strip.to_f : val
169
+ # Accept leading-dot (.2), trailing-dot (2.) and exponent (1e-3,
170
+ # -2.5E+2) forms that Ruby's Float() understands.
171
+ val.strip =~ /\A[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\z/ ? val.strip.to_f : val
172
+ when :array
173
+ # Comma-separated env values (e.g. "ls,cat") become a typed list;
174
+ # blank entries are dropped so trailing commas stay harmless.
175
+ val.strip.split(",").map(&:strip).reject(&:empty?)
170
176
  when :enum
171
177
  val.strip.downcase
172
178
  else
@@ -120,9 +120,10 @@ module Rubik
120
120
  end
121
121
 
122
122
  # Keyring hygiene for Config#delete: a successfully persisted delete
123
- # of an api_key path also drops its stored secret(s) — both scopes'
124
- # names, so neither keyring entry outlives its reference. Best-effort
125
- # — never masks res.
123
+ # of an api_key path also drops the stored secret for the scope being
124
+ # removed. The sibling scope's keyring entry is deliberately left
125
+ # intact — its config pointer still lives in the other layer and must
126
+ # keep resolving. Best-effort — never masks res.
126
127
  def cleanup_stored_secret(key, res, persist, old_val: nil)
127
128
  return unless res[:ok] && persisting?(persist)
128
129
 
@@ -133,9 +134,9 @@ module Rubik
133
134
  else
134
135
  []
135
136
  end
137
+ scope = persist.to_s.downcase.to_sym == :project ? :project : :global
136
138
  keys_to_delete.each do |secret_path|
137
- Rubik::Security::SecretStore.delete(secret_path)
138
- Rubik::Security::SecretStore.delete("#{secret_path}.project")
139
+ Rubik::Security::SecretStore.delete(secret_name(secret_path, scope))
139
140
  end
140
141
  rescue Rubik::Security::SecretStore::Error
141
142
  nil
data/lib/rubik/config.rb CHANGED
@@ -296,7 +296,7 @@ module Rubik
296
296
  @project_layer = filter_untrusted_project_config(@project_layer)
297
297
  end
298
298
 
299
- @env_layer = EnvLoader.load_env(ENV, DEFAULT_CONFIG, @warnings)
299
+ @env_layer = validate_env_layer!(EnvLoader.load_env(ENV, DEFAULT_CONFIG, @warnings), @warnings)
300
300
  @session_layer = {}
301
301
 
302
302
  warn_plaintext_project_secrets