rubik 0.12.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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +71 -1
  4. data/bin/rubik +11 -1
  5. data/lib/rubik/ast/c_extractor.rb +1 -1
  6. data/lib/rubik/ast/graph.rb +38 -57
  7. data/lib/rubik/ast/graph_extensions.rb +57 -15
  8. data/lib/rubik/ast/ruby_extractor.rb +4 -0
  9. data/lib/rubik/ast/treesitter/c_walker.rb +11 -3
  10. data/lib/rubik/buffer/manager.rb +33 -11
  11. data/lib/rubik/buffer/snapshot.rb +23 -3
  12. data/lib/rubik/cli/connect.rb +49 -0
  13. data/lib/rubik/config/defaults.rb +4 -7
  14. data/lib/rubik/config/env_guard.rb +43 -0
  15. data/lib/rubik/config/schema.rb +8 -1
  16. data/lib/rubik/config/secret_policy.rb +6 -5
  17. data/lib/rubik/config.rb +1 -1
  18. data/lib/rubik/connect/http.rb +85 -0
  19. data/lib/rubik/connect/models_dev.rb +173 -0
  20. data/lib/rubik/connect/probes.rb +103 -0
  21. data/lib/rubik/connect/prompt_ui.rb +139 -0
  22. data/lib/rubik/connect/wizard.rb +540 -0
  23. data/lib/rubik/connect.rb +7 -0
  24. data/lib/rubik/context/repo_context_reader.rb +8 -4
  25. data/lib/rubik/llm/chunk_assembler.rb +12 -1
  26. data/lib/rubik/llm/formatter.rb +14 -0
  27. data/lib/rubik/llm/openai_compatible.rb +4 -1
  28. data/lib/rubik/llm/provider_key.rb +32 -0
  29. data/lib/rubik/llm/registry.rb +18 -2
  30. data/lib/rubik/llm/router.rb +19 -1
  31. data/lib/rubik/llm/session_header.rb +128 -0
  32. data/lib/rubik/llm/sse_parser.rb +57 -10
  33. data/lib/rubik/lsp/client.rb +11 -5
  34. data/lib/rubik/lsp/transport.rb +17 -7
  35. data/lib/rubik/mcp/transport/stdio.rb +42 -4
  36. data/lib/rubik/orchestrator/continuation_manager.rb +14 -5
  37. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +18 -2
  38. data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +13 -4
  39. data/lib/rubik/orchestrator/goal_ledger/validator.rb +46 -7
  40. data/lib/rubik/orchestrator/goal_ledger/verifier.rb +8 -1
  41. data/lib/rubik/orchestrator/goal_session.rb +4 -4
  42. data/lib/rubik/orchestrator/loop.rb +8 -11
  43. data/lib/rubik/orchestrator/provider_resolver.rb +29 -6
  44. data/lib/rubik/orchestrator/step_executor.rb +17 -2
  45. data/lib/rubik/orchestrator/subagent/instance.rb +24 -1
  46. data/lib/rubik/orchestrator/subagent/notices.rb +1 -1
  47. data/lib/rubik/orchestrator/subagent/reaper.rb +21 -2
  48. data/lib/rubik/orchestrator/subagent/start_gate.rb +1 -1
  49. data/lib/rubik/orchestrator/subagent/step_runner.rb +7 -7
  50. data/lib/rubik/orchestrator/subagent/supervisor.rb +10 -3
  51. data/lib/rubik/orchestrator/turn_executor/user_channel.rb +27 -5
  52. data/lib/rubik/orchestrator/turn_executor.rb +24 -8
  53. data/lib/rubik/platform/filesystem.rb +52 -24
  54. data/lib/rubik/plugin/storage.rb +20 -0
  55. data/lib/rubik/prompt/context_builder.rb +2 -1
  56. data/lib/rubik/repair/loop.rb +22 -2
  57. data/lib/rubik/repl/commands/agent_context.rb +1 -1
  58. data/lib/rubik/repl/commands/agent_execution.rb +20 -15
  59. data/lib/rubik/repl/commands/buffer.rb +15 -0
  60. data/lib/rubik/repl/commands/connect.rb +51 -0
  61. data/lib/rubik/repl/commands/lsp.rb +1 -1
  62. data/lib/rubik/repl/commands/plugins.rb +31 -31
  63. data/lib/rubik/repl/commands/session.rb +5 -5
  64. data/lib/rubik/repl/commands/workspace.rb +4 -4
  65. data/lib/rubik/repl/commands.rb +2 -0
  66. data/lib/rubik/repl/input_execution.rb +30 -29
  67. data/lib/rubik/repl/input_loop.rb +10 -4
  68. data/lib/rubik/repl/lifecycle.rb +38 -0
  69. data/lib/rubik/repl/notice_router.rb +11 -5
  70. data/lib/rubik/repl/paste_support.rb +1 -1
  71. data/lib/rubik/repl/prompt_grace.rb +3 -3
  72. data/lib/rubik/repl/shell.rb +10 -2
  73. data/lib/rubik/repl/turn_recorder.rb +14 -3
  74. data/lib/rubik/runtime/context.rb +33 -27
  75. data/lib/rubik/runtime/manager.rb +23 -15
  76. data/lib/rubik/sandbox/driver/bubblewrap.rb +58 -8
  77. data/lib/rubik/sandbox/driver/process.rb +32 -1
  78. data/lib/rubik/sandbox/runner.rb +9 -1
  79. data/lib/rubik/security/classifier/classifier.rb +147 -13
  80. data/lib/rubik/security/classifier/commands/docker.yaml +1 -1
  81. data/lib/rubik/security/classifier/commands/git.yaml +27 -1
  82. data/lib/rubik/security/classifier/commands/sed.yaml +3 -3
  83. data/lib/rubik/security/classifier/database.rb +2 -2
  84. data/lib/rubik/security/command_gate.rb +8 -1
  85. data/lib/rubik/security/redactor.rb +62 -19
  86. data/lib/rubik/session/recorder.rb +13 -18
  87. data/lib/rubik/session/replayer.rb +29 -7
  88. data/lib/rubik/storage/store.rb +19 -5
  89. data/lib/rubik/tools/builtins/exec.rb +1 -1
  90. data/lib/rubik/tools/builtins/files.rb +8 -12
  91. data/lib/rubik/tools/builtins/grep.rb +3 -2
  92. data/lib/rubik/tools/builtins/lsp.rb +31 -7
  93. data/lib/rubik/tools/builtins/show_file.rb +1 -1
  94. data/lib/rubik/tools/builtins/synthesis.rb +4 -4
  95. data/lib/rubik/tools/result_normalizer.rb +1 -1
  96. data/lib/rubik/ui/banner.rb +3 -3
  97. data/lib/rubik/ui/dialog.rb +10 -7
  98. data/lib/rubik/ui/diff_viewer.rb +4 -4
  99. data/lib/rubik/ui/frame.rb +13 -3
  100. data/lib/rubik/ui/markdown_stream.rb +8 -2
  101. data/lib/rubik/ui/panel.rb +11 -11
  102. data/lib/rubik/ui/renderer.rb +6 -6
  103. data/lib/rubik/ui/spinner.rb +1 -1
  104. data/lib/rubik/ui/statusline.rb +3 -3
  105. data/lib/rubik/ui/theme.rb +1 -1
  106. data/lib/rubik/version.rb +1 -1
  107. metadata +12 -1
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "securerandom"
4
+
3
5
  module Rubik
4
6
  module Platform
5
7
  # File system operations (atomic writes, newline normalization).
@@ -12,36 +14,62 @@ module Rubik
12
14
  def atomic_write(target_path, content)
13
15
  dir = File.dirname(target_path)
14
16
  FileUtils.mkdir_p(dir) unless File.directory?(dir)
15
- tmp_file = "#{target_path}.tmp.#{::Process.pid}.#{rand(1_000_000)}"
16
17
 
17
- File.open(tmp_file, "wb") do |f|
18
- f.write(content)
19
- f.flush
20
- begin
21
- f.fsync
22
- rescue StandardError, ScriptError
23
- nil
24
- end
18
+ # Preserve the target's permission bits (issue #543): File.open creates
19
+ # a 0644 temp file and rename keeps the temp's mode, so overwriting a
20
+ # 0600 secret would expose it and a 0755 script would lose +x. Capture
21
+ # the mode before writing and carry it onto the temp file before rename.
22
+ existing_mode = begin
23
+ stat = File.stat(target_path)
24
+ stat.mode & 0o7777 if stat.file?
25
+ rescue Errno::ENOENT
26
+ nil
25
27
  end
26
28
 
27
- # Atomic replace: rename tmp_file -> target_path without unlinking first
28
- # (closing TOCTOU). Retry for Windows transient locks.
29
- retries = 3
29
+ # O_EXCL refuses a pre-placed path (including a symlink) instead of
30
+ # following it, and the random suffix makes the temp name unpredictable.
31
+ # Together they close the TOCTOU/symlink redirection of issue #543.
32
+ tmp_file = "#{target_path}.tmp.#{::Process.pid}.#{SecureRandom.hex(12)}"
33
+ created = false
34
+
30
35
  begin
31
- File.rename(tmp_file, target_path)
32
- rescue SystemCallError => e
33
- if retries.positive?
34
- retries -= 1
35
- sleep 0.02
36
- retry
36
+ # Mode 0o600 keeps the in-flight temp private until the final chmod.
37
+ File.open(tmp_file, File::WRONLY | File::CREAT | File::EXCL | File::BINARY, 0o600) do |f|
38
+ created = true
39
+ f.write(content)
40
+ f.flush
41
+ begin
42
+ f.fsync
43
+ rescue StandardError, ScriptError
44
+ nil
45
+ end
37
46
  end
38
- debug_warn("atomic_write failed for #{target_path}: #{e.class}: #{e.message}")
39
- raise
40
- ensure
47
+
48
+ File.chmod(existing_mode, tmp_file) if existing_mode
49
+
50
+ # Atomic replace: rename tmp_file -> target_path without unlinking first
51
+ # (closing TOCTOU). Retry for Windows transient locks.
52
+ retries = 3
41
53
  begin
42
- FileUtils.rm_f(tmp_file)
43
- rescue StandardError, ScriptError
44
- nil
54
+ File.rename(tmp_file, target_path)
55
+ rescue SystemCallError => e
56
+ if retries.positive?
57
+ retries -= 1
58
+ sleep 0.02
59
+ retry
60
+ end
61
+ debug_warn("atomic_write failed for #{target_path}: #{e.class}: #{e.message}")
62
+ raise
63
+ end
64
+ ensure
65
+ # Only remove the temp file we created; never delete a pre-placed
66
+ # path (e.g. an attacker's symlink) that made O_EXCL fail.
67
+ if created
68
+ begin
69
+ FileUtils.rm_f(tmp_file)
70
+ rescue StandardError, ScriptError
71
+ nil
72
+ end
45
73
  end
46
74
  end
47
75
  end
@@ -189,6 +189,9 @@ module Rubik
189
189
 
190
190
  def remove_plugin(name, scope: :project)
191
191
  target_dir = scope.to_sym == :global ? global_plugins_dir : project_plugins_dir
192
+
193
+ return { ok: false, error: "Invalid plugin name: #{name.to_s.inspect}." } unless safe_plugin_name?(name, target_dir)
194
+
192
195
  file_path = File.join(target_dir, "#{name}.rb")
193
196
  dir_path = File.join(target_dir, name.to_s)
194
197
 
@@ -219,6 +222,23 @@ module Rubik
219
222
 
220
223
  private
221
224
 
225
+ # A plugin name must resolve to a single path component directly under
226
+ # target_dir. Reject separators, traversal components (`.`/`..`),
227
+ # absolute paths and NUL bytes before any rm_f/rm_rf so a caller-supplied
228
+ # name can never escape the plugins directory (issue #554). Any ordinary
229
+ # single-component name is allowed, so legitimate plugins keep working.
230
+ def safe_plugin_name?(name, target_dir)
231
+ component = name.to_s
232
+ return false if component.empty? || component == "." || component == ".."
233
+ return false if component.match?(%r{[/\\\0]})
234
+
235
+ base = File.expand_path(target_dir)
236
+ candidate = File.expand_path(component, base)
237
+ candidate.start_with?("#{base}#{File::SEPARATOR}") && File.dirname(candidate) == base
238
+ rescue ArgumentError
239
+ false
240
+ end
241
+
222
242
  # The package root for a path inside the plugins dir: plugins/<first
223
243
  # segment> when that segment is a DIRECTORY (directory plugin); nil for
224
244
  # a single-file plugin. A path outside the plugins dir is not a package.
@@ -7,6 +7,7 @@ require_relative "../context/repo_context_reader"
7
7
  # this module is the assembler: structure + service data only.
8
8
  require_relative "doctrine"
9
9
  require_relative "services"
10
+ require_relative "../tools/builtins/lsp"
10
11
 
11
12
  module Rubik
12
13
  module Prompt
@@ -250,7 +251,7 @@ module Rubik
250
251
 
251
252
  all_diags.each do |fpath, diags|
252
253
  diags.each do |d|
253
- sev = d["severity"] == 1 ? "error" : "warning"
254
+ sev = Rubik::Tools::LSPSeverity.label(d["severity"])
254
255
  total_errors += 1 if sev == "error"
255
256
  start_line = (d.dig("range", "start", "line") || 0) + 1
256
257
  msg = Rubik::Platform.xml_escape(d["message"])
@@ -2,18 +2,22 @@
2
2
 
3
3
  require "json"
4
4
  require "tempfile"
5
+ require_relative "../llm/session_header"
6
+ require_relative "../orchestrator/provider_resolver"
5
7
 
6
8
  module Rubik
7
9
  module Repair
8
10
  class Loop
9
11
  attr_reader :max_attempts, :attempts_made, :config
10
12
 
11
- def initialize(provider:, buffer_manager:, snapshot_store:, adapter_registry:, max_attempts: nil, config: nil)
13
+ def initialize(provider:, buffer_manager:, snapshot_store:, adapter_registry:, max_attempts: nil, config: nil,
14
+ session_key: nil)
12
15
  @provider = provider
13
16
  @buffer_manager = buffer_manager
14
17
  @snapshot_store = snapshot_store
15
18
  @adapter_registry = adapter_registry
16
19
  @config = config
20
+ @session_key = session_key
17
21
  @max_attempts = (max_attempts || config&.fetch("repair.max_attempts", 3) || 3).to_i
18
22
  @attempts_made = 0
19
23
  end
@@ -21,15 +25,31 @@ module Rubik
21
25
  def repair(diagnostics, target_file, lang = :ruby)
22
26
  @attempts_made = 0
23
27
  current_diag = diagnostics
28
+ baseline_recorded = false
24
29
 
25
30
  while @attempts_made < @max_attempts
26
31
  @attempts_made += 1
27
32
 
33
+ # Capture the pre-repair state once so an aborted attempt restores
34
+ # pending edits instead of an empty buffer (issue #544).
35
+ unless baseline_recorded
36
+ @snapshot_store.record_baseline(@buffer_manager)
37
+ baseline_recorded = true
38
+ end
39
+
28
40
  @snapshot_store.create_snapshot(@buffer_manager)
29
41
 
30
42
  begin
31
43
  prompt = build_repair_prompt(current_diag, target_file, @attempts_made)
32
- res = @provider.complete([{ role: "user", content: prompt }])
44
+ # Same per-provider session header as every other lane — repair is
45
+ # auxiliary traffic on the SAME conversation for the gateway.
46
+ header_opts = Rubik::LLM::SessionHeader.apply!(
47
+ {},
48
+ provider_key: Rubik::Orchestrator::ProviderResolver.new(provider: @provider, config: @config).registry_key,
49
+ config: @config,
50
+ session_key: @session_key
51
+ )
52
+ res = @provider.complete([{ role: "user", content: prompt }], header_opts)
33
53
  proposed_code = extract_code(res.text)
34
54
 
35
55
  if proposed_code.empty?
@@ -202,7 +202,7 @@ module Rubik
202
202
  ctx.out.puts " • Default Task Max Steps : #{cur_max}"
203
203
  ctx.out.puts " • Goal Mode Max Steps : #{goal_max}"
204
204
  ctx.out.puts " • Plan Mode Max Steps : #{plan_max}"
205
- ctx.out.puts " • Warning Threshold : #{(warn_r.to_f * 100).to_i}% (#{(cur_max.to_i * warn_r.to_f).ceil}. adım)"
205
+ ctx.out.puts " • Warning Threshold : #{(warn_r.to_f * 100).to_i}% (step #{(cur_max.to_i * warn_r.to_f).ceil})"
206
206
  ctx.out.puts " • Ask Continue on Limit : #{ask_c}"
207
207
  elsif clean_args.first.downcase == "default"
208
208
  num = clean_args[1].to_i
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "shellwords"
3
4
  require_relative "base"
4
5
  require_relative "../../storage/layout"
5
6
  require_relative "../../runtime"
@@ -15,8 +16,8 @@ module Rubik
15
16
 
16
17
  # Whole-command synopses: shared by the spine registration (usage:)
17
18
  # and the empty-args branches that print them, so the two cannot drift.
18
- USAGE_PLAN = "Kullanım: !plan <görev açıklaması>"
19
- USAGE_GOAL = "Kullanım: !goal [--steps N|-s N] <hedef açıklaması> | !goal resume | !goal list"
19
+ USAGE_PLAN = "Usage: !plan <task description>"
20
+ USAGE_GOAL = "Usage: !goal [--steps N|-s N] <goal description> | !goal resume | !goal list"
20
21
 
21
22
  # The !goal run lifecycle (start/suspend/resume/terminal mapping) is
22
23
  # the Orchestrator::GoalSession domain (issue #404); this module keeps
@@ -59,15 +60,15 @@ module Rubik
59
60
  ctx.out.puts "\n=== Proposed Plan ==="
60
61
  ctx.out.puts res[:output]
61
62
  ctx.out.puts "=====================\n"
62
- ans = ctx.ask_yes_no("[Rubik::Plan] Plan uygulansın mı?", default: "y")
63
+ ans = ctx.ask_yes_no("[Rubik::Plan] Should the plan be applied?", default: "y")
63
64
  if ["y", "yes", "evet"].include?(ans)
64
65
  ctx.out.puts "[Rubik::Act] Executing approved plan..."
65
66
  ctx.execute_free_text("Execute the following approved plan step by step:\n#{res[:output]}")
66
67
  else
67
- ctx.out.puts "[Rubik] Plan iptal edildi."
68
+ ctx.out.puts "[Rubik] Plan cancelled."
68
69
  end
69
70
  else
70
- ctx.out.puts "Plan üretilemedi: #{res[:error]}"
71
+ ctx.out.puts "Plan could not be generated: #{res[:error]}"
71
72
  end
72
73
  end
73
74
  end
@@ -85,7 +86,7 @@ module Rubik
85
86
  parsed = parse_goal_args(args)
86
87
  if !parsed[:valid]
87
88
  ctx.out.puts USAGE_GOAL
88
- ctx.out.puts "⚠️ [Rubik::Goal] --steps pozitif bir tam sayı bekliyor (örn. !goal --steps 200 <hedef>)"
89
+ ctx.out.puts "⚠️ [Rubik::Goal] --steps expects a positive integer (e.g. !goal --steps 200 <goal>)"
89
90
  next
90
91
  elsif parsed[:goal_text].empty?
91
92
  ctx.out.puts USAGE_GOAL
@@ -172,7 +173,11 @@ module Rubik
172
173
  shell.register_command("sh", description: "Execute shell command via sandbox runner") do |args, ctx|
173
174
  Base.pre_execution_apply(ctx, "command execution", "Commands")
174
175
 
175
- cmd = args.join(" ")
176
+ # CommandParser already consumed the quotes via Shellwords.split;
177
+ # rebuild a shell-safe command so `!sh grep "foo bar" file` keeps
178
+ # its single argument — both for execution and for the safety
179
+ # gate (issue #557).
180
+ cmd = Shellwords.shelljoin(args)
176
181
  ctx.guard.verify_command_safety!(cmd)
177
182
  runner = ctx.sandbox_runner || Rubik::Sandbox::Runner.new(root_dir: Dir.pwd, config: ctx.config, guard: ctx.guard)
178
183
  res = runner.run(cmd)
@@ -190,15 +195,15 @@ module Rubik
190
195
 
191
196
  if clean_args.empty? || subcmd == "status"
192
197
  enabled = Rubik::Storage::Layout.config_get(ctx.config, "sandbox.enabled", false)
193
- state_str = enabled ? "Açık (enabled)" : "Kapalı (disabled - direct safe execution)"
198
+ state_str = enabled ? "Enabled" : "Disabled - direct safe execution"
194
199
  driver_name = ctx.sandbox_runner&.driver&.name || Rubik::Storage::Layout.config_get(ctx.config, "sandbox.driver", "bwrap")
195
200
  net_str = Rubik::Storage::Layout.config_get(ctx.config, "sandbox.allow_network", false) ? "allowed" : "blocked"
196
201
 
197
- ctx.out.puts "=== Sandbox Durumu ==="
198
- ctx.out.puts "Durum: #{state_str}"
199
- ctx.out.puts "Aktif Motor: #{driver_name}"
200
- ctx.out.puts "Ağ: #{net_str}"
201
- ctx.out.puts "Kayıtlı: #{registered_keys.join(', ')}"
202
+ ctx.out.puts "=== Sandbox Status ==="
203
+ ctx.out.puts "Status: #{state_str}"
204
+ ctx.out.puts "Active Driver: #{driver_name}"
205
+ ctx.out.puts "Network: #{net_str}"
206
+ ctx.out.puts "Registered: #{registered_keys.join(', ')}"
202
207
  elsif subcmd == "on"
203
208
  res = ctx.config.set("sandbox.enabled", true, persist: scope)
204
209
  driver_res = ctx.config.set("sandbox.driver", "bwrap", persist: scope) if Rubik::Platform.linux?
@@ -212,7 +217,7 @@ module Rubik
212
217
 
213
218
  ctx.out.puts "[Sandbox] Disabled (direct safe execution active)."
214
219
  elsif registered_map.key?(subcmd)
215
- ctx.out.puts "⚠️ [Sandbox] 'bwrap' yalnızca Linux üzerinde desteklenir." if ["bwrap", "bubblewrap"].include?(subcmd) && !Rubik::Platform.linux?
220
+ ctx.out.puts "⚠️ [Sandbox] 'bwrap' is only supported on Linux." if ["bwrap", "bubblewrap"].include?(subcmd) && !Rubik::Platform.linux?
216
221
  res = ctx.config.set("sandbox.enabled", true, persist: scope)
217
222
  driver_res = ctx.config.set("sandbox.driver", subcmd, persist: scope)
218
223
  next if Base.report_persist_failure(ctx, res, scope)
@@ -220,7 +225,7 @@ module Rubik
220
225
 
221
226
  ctx.out.puts "[Sandbox] Driver set to '#{subcmd}' (enabled)."
222
227
  else
223
- ctx.out.puts "[Sandbox] Bilinmeyen alt komut veya sürücü: '#{subcmd}'. Kayıtlı sürücüler: #{registered_keys.join(', ')}"
228
+ ctx.out.puts "[Sandbox] Unknown subcommand or driver: '#{subcmd}'. Registered drivers: #{registered_keys.join(', ')}"
224
229
  end
225
230
  end
226
231
  end
@@ -17,6 +17,7 @@ module Rubik
17
17
  USAGE_AUTOAPPLY = "Usage: !autoapply <manual | on_test | on_finish | always | status> [--project|--global]"
18
18
 
19
19
  def self.register(shell)
20
+ register_snapshot_recording(shell)
20
21
  register_diff_command(shell)
21
22
  register_apply_command(shell)
22
23
  register_undo_command(shell)
@@ -24,6 +25,20 @@ module Rubik
24
25
  register_autoapply_command(shell)
25
26
  end
26
27
 
28
+ private_class_method def self.register_snapshot_recording(shell)
29
+ return unless shell.respond_to?(:buffer_manager) && shell.respond_to?(:snapshot_store)
30
+
31
+ manager = shell.buffer_manager
32
+ store = shell.snapshot_store
33
+ return unless manager.respond_to?(:snapshot_store=) && store
34
+
35
+ # The manager snapshots the post-write buffer state, so the
36
+ # !undo / !rollback commands registered below always have a
37
+ # producer (issue #544). Kept here so the dependency lives with
38
+ # the command module that advertises them.
39
+ manager.snapshot_store = store
40
+ end
41
+
27
42
  private_class_method def self.register_diff_command(shell)
28
43
  shell.register_command(
29
44
  "diff",
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+ require_relative "../../connect"
5
+
6
+ module Rubik
7
+ module REPL
8
+ module Commands
9
+ # `!connect` — the in-REPL entry to the provider connect wizard.
10
+ # Unlike !provider add's :session default, !connect persists to
11
+ # :global by default: the wizard's purpose is durable setup, and a
12
+ # session-scoped provider silently vanishing on exit would undo the
13
+ # friction reduction this command exists for. --project/--global
14
+ # flags override, exactly like every other config-touching command.
15
+ module Connect
16
+ extend Base
17
+
18
+ USAGE_CONNECT = "Usage: !connect [--project|--global]"
19
+
20
+ def self.register(shell)
21
+ shell.register_command("connect",
22
+ description: "Interactive wizard: add an LLM provider (models.dev catalog, live key check) " \
23
+ "and bind model roles",
24
+ usage: USAGE_CONNECT) do |args, ctx|
25
+ # The wizard has no session tier: an explicit --session/-s would
26
+ # otherwise be silently coerced into the most persistent write
27
+ # the wizard can make. Honest refusal beats silent escalation.
28
+ if args.intersect?(["--session", "-s"])
29
+ ctx.out.puts USAGE_CONNECT
30
+ ctx.out.puts " !connect writes persistent scopes only; use !provider add for a session-scoped provider."
31
+ else
32
+ scope, _clean = Base.parse_scope(args)
33
+ scope = :global if scope == :session
34
+ result = invoke(ctx, scope)
35
+ ctx.out.puts USAGE_CONNECT if result[:reason] == :non_interactive
36
+ end
37
+ end
38
+ end
39
+
40
+ # ui:/probe: kwargs are test seams — shell-level tests inject a
41
+ # scripted PromptUI (and stubbed probes) instead of driving
42
+ # TTY::Prompt against a StringIO.
43
+ def self.invoke(ctx, scope, ui: nil, probe: nil)
44
+ ui ||= Rubik::Connect::PromptUI.new(input: ctx.input, output: ctx.out, theme: ctx.theme)
45
+ Rubik::Connect::Wizard.new(config: ctx.config, ui: ui, io: ctx.out, scope: scope,
46
+ refresh: -> { ctx.refresh_llm_registry! }, probe: probe).run
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -80,7 +80,7 @@ module Rubik
80
80
 
81
81
  private_class_method def self.render_diagnostics(ctx, diags)
82
82
  diags.each do |d|
83
- sev = d["severity"] == 1 ? "ERROR" : "WARN"
83
+ sev = Rubik::Tools::LSPSeverity.display(d["severity"])
84
84
  line = (d.dig("range", "start", "line") || 0) + 1
85
85
  ctx.out.puts " • [#{sev}] Line #{line}: #{d['message']}"
86
86
  end
@@ -6,13 +6,13 @@ module Rubik
6
6
  module Plugins
7
7
  # Whole-command synopsis: shared by the spine registration (usage:)
8
8
  # and the unknown-subcommand fallback branch, so the two cannot drift.
9
- USAGE_PLUGIN = "Kullanım: !plugin [list|add|remove|reload|enable|disable|info]"
9
+ USAGE_PLUGIN = "Usage: !plugin [list|add|remove|reload|enable|disable|info]"
10
10
 
11
11
  def self.register(shell)
12
12
  handler = proc do |args, ctx|
13
13
  manager = ctx.plugin_manager
14
14
  unless manager
15
- ctx.out.puts "Eklenti yöneticisi bulunamadı."
15
+ ctx.out.puts "Plugin manager not found."
16
16
  next
17
17
  end
18
18
 
@@ -37,23 +37,23 @@ module Rubik
37
37
  when "info"
38
38
  info_plugin(ctx, manager, args[1])
39
39
  else
40
- ctx.out.puts "Bilinmeyen komut: #{subcommand}. #{USAGE_PLUGIN}"
40
+ ctx.out.puts "Unknown command: #{subcommand}. #{USAGE_PLUGIN}"
41
41
  end
42
42
  end
43
43
 
44
- shell.register_command("plugin", description: "Eklenti yönetimi: list, add, remove, reload, enable, disable, info",
44
+ shell.register_command("plugin", description: "Plugin management: list, add, remove, reload, enable, disable, info",
45
45
  usage: USAGE_PLUGIN, audience: :human, &handler)
46
- shell.register_command("plugins", description: "Yüklü eklentileri listeler", usage: USAGE_PLUGIN, audience: :human) do |_args, ctx|
46
+ shell.register_command("plugins", description: "Lists installed plugins", usage: USAGE_PLUGIN, audience: :human) do |_args, ctx|
47
47
  handler.call(["list"], ctx)
48
48
  end
49
49
  end
50
50
 
51
51
  def self.list_plugins(ctx, manager, storage)
52
- ctx.out.puts "🧩 Eklentiler (Plugins)"
52
+ ctx.out.puts "🧩 Plugins"
53
53
  ctx.out.puts "======================"
54
54
 
55
55
  if manager.registered_plugins.empty? && (!storage || storage.discover_plugins.empty?)
56
- ctx.out.puts "Yüklü eklenti yok."
56
+ ctx.out.puts "No plugins installed."
57
57
  else
58
58
  manager.registered_plugins.each do |gem_name|
59
59
  component_name = "plugin_#{gem_name}"
@@ -66,7 +66,7 @@ module Rubik
66
66
  if storage
67
67
  dropins = storage.discover_plugins
68
68
  unless dropins.empty?
69
- ctx.out.puts "\n📂 Drop-in Eklentileri"
69
+ ctx.out.puts "\n📂 Drop-in Plugins"
70
70
  ctx.out.puts "======================"
71
71
  dropins.each do |meta|
72
72
  component_name = "plugin_#{meta[:name]}"
@@ -77,10 +77,10 @@ module Rubik
77
77
  end
78
78
  end
79
79
 
80
- ctx.out.puts "\n🔗 Alias Tablosu"
80
+ ctx.out.puts "\n🔗 Alias Table"
81
81
  ctx.out.puts "================"
82
82
  if manager.aliases.empty?
83
- ctx.out.puts "Kayıtlı alias yok."
83
+ ctx.out.puts "No registered aliases."
84
84
  else
85
85
  manager.aliases.each do |short, full|
86
86
  ctx.out.puts "- !#{short} -> !#{full}"
@@ -90,12 +90,12 @@ module Rubik
90
90
 
91
91
  def self.add_plugin(ctx, manager, storage, path, flags)
92
92
  unless storage
93
- ctx.out.puts "Hata: Drop-in eklenti motoru aktif değil."
93
+ ctx.out.puts "Error: Drop-in plugin engine is not active."
94
94
  return
95
95
  end
96
96
 
97
97
  unless path
98
- ctx.out.puts "Hata: Eklenti yolu belirtilmedi. Kullanım: !plugin add <path>"
98
+ ctx.out.puts "Error: Plugin path not specified. Usage: !plugin add <path>"
99
99
  return
100
100
  end
101
101
 
@@ -103,7 +103,7 @@ module Rubik
103
103
  result = storage.add_plugin(path, scope: scope)
104
104
 
105
105
  if result[:ok]
106
- ctx.out.puts "✅ Eklenti #{result[:name]} (#{scope}) başarıyla eklendi."
106
+ ctx.out.puts "✅ Plugin #{result[:name]} (#{scope}) added successfully."
107
107
 
108
108
  # Build a proper plugin_meta for load_plugin_file:
109
109
  # storage.add_plugin returns {ok, name, path, type} but
@@ -112,72 +112,72 @@ module Rubik
112
112
  # $LOAD_PATH.
113
113
  plugin_meta = build_plugin_meta(result, scope)
114
114
  if manager.load_plugin_file(plugin_meta, runtime_manager: ctx.runtime_manager)
115
- ctx.out.puts "🚀 Eklenti #{result[:name]} canlı olarak yüklendi."
115
+ ctx.out.puts "🚀 Plugin #{result[:name]} loaded live."
116
116
  else
117
- ctx.out.puts "⚠️ Eklenti #{result[:name]} dosyası kopyalandı ancak yüklenemedi."
117
+ ctx.out.puts "⚠️ Plugin #{result[:name]} file was copied but could not be loaded."
118
118
  end
119
119
  else
120
- ctx.out.puts "❌ Hata: #{result[:error]}"
120
+ ctx.out.puts "❌ Error: #{result[:error]}"
121
121
  end
122
122
  end
123
123
 
124
124
  def self.remove_plugin(ctx, manager, storage, name, flags)
125
125
  unless storage
126
- ctx.out.puts "Hata: Drop-in eklenti motoru aktif değil."
126
+ ctx.out.puts "Error: Drop-in plugin engine is not active."
127
127
  return
128
128
  end
129
129
  unless name
130
- ctx.out.puts "Hata: Eklenti adı belirtilmedi."
130
+ ctx.out.puts "Error: Plugin name not specified."
131
131
  return
132
132
  end
133
133
 
134
134
  scope = flags.include?("--global") ? :global : :project
135
135
 
136
136
  unloaded = manager.unload_plugin(name, runtime_manager: ctx.runtime_manager)
137
- ctx.out.puts "🧹 Eklenti #{name} fiber'ı sonlandırıldı (ters kayıtlar işletildi)." if unloaded
137
+ ctx.out.puts "🧹 Plugin #{name} fiber terminated (inverse records executed)." if unloaded
138
138
 
139
139
  result = storage.remove_plugin(name, scope: scope)
140
140
  if result[:ok]
141
- ctx.out.puts "🗑️ Eklenti #{name} diskten (#{scope}) silindi."
141
+ ctx.out.puts "🗑️ Plugin #{name} deleted from disk (#{scope})."
142
142
  else
143
- ctx.out.puts "⚠️ Eklenti diskten silinemedi: #{result[:error]}"
143
+ ctx.out.puts "⚠️ Plugin could not be deleted from disk: #{result[:error]}"
144
144
  end
145
145
  end
146
146
 
147
147
  def self.reload_plugin(ctx, manager, storage, name)
148
148
  unless storage
149
- ctx.out.puts "Hata: Drop-in eklenti motoru aktif değil."
149
+ ctx.out.puts "Error: Drop-in plugin engine is not active."
150
150
  return
151
151
  end
152
152
  unless name
153
- ctx.out.puts "Hata: Eklenti adı belirtilmedi."
153
+ ctx.out.puts "Error: Plugin name not specified."
154
154
  return
155
155
  end
156
156
 
157
157
  if manager.reload_plugin(name, storage: storage, runtime_manager: ctx.runtime_manager)
158
- ctx.out.puts "🔄 Eklenti #{name} başarıyla yeniden yüklendi (zero-downtime)."
158
+ ctx.out.puts "🔄 Plugin #{name} reloaded successfully (zero-downtime)."
159
159
  else
160
- ctx.out.puts "❌ Hata: Eklenti #{name} yeniden yüklenemedi."
160
+ ctx.out.puts "❌ Error: Plugin #{name} could not be reloaded."
161
161
  end
162
162
  end
163
163
 
164
164
  def self.enable_plugin(ctx, _manager, name)
165
165
  # Not implemented deeply for now, simply unpauses fiber
166
- ctx.out.puts "Eklenti #{name} etkinleştirildi (placeholder)."
166
+ ctx.out.puts "Plugin #{name} enabled (placeholder)."
167
167
  end
168
168
 
169
169
  def self.disable_plugin(ctx, _manager, name)
170
- ctx.out.puts "Eklenti #{name} devre dışı bırakıldı (placeholder)."
170
+ ctx.out.puts "Plugin #{name} disabled (placeholder)."
171
171
  end
172
172
 
173
173
  def self.info_plugin(ctx, _manager, name)
174
174
  if Rubik::Plugin::Registry.get(name)
175
175
  def_obj = Rubik::Plugin::Registry.get(name)
176
- ctx.out.puts "Eklenti: #{def_obj.name} v#{def_obj.version}"
177
- ctx.out.puts "Açıklama: #{def_obj.description}"
178
- ctx.out.puts "Bağımlılıklar (inject): #{def_obj.inject.join(', ')}"
176
+ ctx.out.puts "Plugin: #{def_obj.name} v#{def_obj.version}"
177
+ ctx.out.puts "Description: #{def_obj.description}"
178
+ ctx.out.puts "Dependencies (inject): #{def_obj.inject.join(', ')}"
179
179
  else
180
- ctx.out.puts "Eklenti bilgisi bulunamadı."
180
+ ctx.out.puts "Plugin info not found."
181
181
  end
182
182
  end
183
183
 
@@ -46,7 +46,7 @@ module Rubik
46
46
 
47
47
  def run_paste(ctx)
48
48
  ctx.request_paste!
49
- ctx.out.puts "[Rubik] Paste modu bir sonraki prompt'ta başlayacak."
49
+ ctx.out.puts "[Rubik] Paste mode will begin on the next prompt."
50
50
  end
51
51
 
52
52
  def run_replay(args, ctx)
@@ -97,7 +97,7 @@ module Rubik
97
97
  if target_id.nil?
98
98
  picked = interactive_session_pick(ctx)
99
99
  if picked == :picker_cancelled
100
- ctx.out.puts "[Rubik::Session] Resume iptal edildi."
100
+ ctx.out.puts "[Rubik::Session] Resume cancelled."
101
101
  return
102
102
  end
103
103
  target_id = picked || :latest
@@ -194,11 +194,11 @@ module Rubik
194
194
  return nil if sessions.empty?
195
195
 
196
196
  prompt = Rubik::UI::Approvals.build_prompt(ctx)
197
- prompt.select("Devam edilecek oturumu seç:") do |menu|
197
+ prompt.select("Select the session to resume:") do |menu|
198
198
  sessions.first(15).each do |s|
199
- menu.choice "#{s[:id]} · #{s[:event_count]} olay · \"#{s[:last_prompt].to_s[0, 40]}\"", s[:id]
199
+ menu.choice "#{s[:id]} · #{s[:event_count]} events · \"#{s[:last_prompt].to_s[0, 40]}\"", s[:id]
200
200
  end
201
- menu.choice "← en son oturum (:latest)", :latest
201
+ menu.choice "← latest session (:latest)", :latest
202
202
  end
203
203
  rescue Interrupt
204
204
  Rubik::REPL::InterruptHandler.restore_console_after_interrupt
@@ -383,13 +383,13 @@ module Rubik
383
383
  end
384
384
  else
385
385
  # Smart guidance for verbless input
386
- ctx.out.puts "[Rubik::Config] Geçersiz kullanım."
386
+ ctx.out.puts "[Rubik::Config] Invalid usage."
387
387
  if clean_args.size >= 2
388
- ctx.out.puts " • Ayar yapmak için : !config set #{clean_args[0]} #{clean_args[1]}"
388
+ ctx.out.puts " • To set a value: !config set #{clean_args[0]} #{clean_args[1]}"
389
389
  else
390
- ctx.out.puts " • Ayar yapmak için : !config set #{clean_args[0]} <val>"
390
+ ctx.out.puts " • To set a value: !config set #{clean_args[0]} <val>"
391
391
  end
392
- ctx.out.puts " • Değer okumak için: !config get #{clean_args[0]}"
392
+ ctx.out.puts " • To read a value: !config get #{clean_args[0]}"
393
393
  end
394
394
  end
395
395
  end