rubik 0.11.0 → 0.13.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +94 -1
  4. data/bin/rubik +11 -1
  5. data/lib/rubik/buffer/manager.rb +3 -3
  6. data/lib/rubik/cli/connect.rb +51 -0
  7. data/lib/rubik/config/deep_ops.rb +3 -1
  8. data/lib/rubik/config/defaults.rb +9 -8
  9. data/lib/rubik/config/schema.rb +8 -0
  10. data/lib/rubik/config/secret_policy.rb +14 -5
  11. data/lib/rubik/config.rb +1 -1
  12. data/lib/rubik/connect/http.rb +85 -0
  13. data/lib/rubik/connect/models_dev.rb +164 -0
  14. data/lib/rubik/connect/probes.rb +96 -0
  15. data/lib/rubik/connect/prompt_ui.rb +139 -0
  16. data/lib/rubik/connect/wizard.rb +488 -0
  17. data/lib/rubik/connect.rb +7 -0
  18. data/lib/rubik/llm/anthropic.rb +2 -1
  19. data/lib/rubik/llm/client.rb +22 -6
  20. data/lib/rubik/llm/formatter.rb +4 -1
  21. data/lib/rubik/llm/ollama.rb +2 -1
  22. data/lib/rubik/llm/openai_compatible.rb +6 -2
  23. data/lib/rubik/llm/router.rb +6 -1
  24. data/lib/rubik/llm/sse_parser.rb +17 -14
  25. data/lib/rubik/mcp/manager.rb +14 -1
  26. data/lib/rubik/mcp/proxy_tool.rb +2 -2
  27. data/lib/rubik/mcp/transport/stdio.rb +3 -2
  28. data/lib/rubik/orchestrator/goal_state.rb +6 -2
  29. data/lib/rubik/orchestrator/loop.rb +30 -6
  30. data/lib/rubik/orchestrator/provider_resolver.rb +12 -0
  31. data/lib/rubik/orchestrator/subagent/step_runner.rb +7 -0
  32. data/lib/rubik/platform/filesystem.rb +2 -2
  33. data/lib/rubik/repair/loop.rb +1 -1
  34. data/lib/rubik/repl/commands/connect.rb +52 -0
  35. data/lib/rubik/repl/commands.rb +2 -0
  36. data/lib/rubik/repl/input_execution.rb +143 -4
  37. data/lib/rubik/repl/input_loop.rb +1 -0
  38. data/lib/rubik/repl/lifecycle.rb +39 -0
  39. data/lib/rubik/repl/shell.rb +9 -1
  40. data/lib/rubik/runtime/fiber.rb +1 -0
  41. data/lib/rubik/runtime/manager.rb +4 -1
  42. data/lib/rubik/runtime/task_manager.rb +3 -3
  43. data/lib/rubik/sandbox/driver/base.rb +7 -0
  44. data/lib/rubik/sandbox/driver/docker.rb +1 -4
  45. data/lib/rubik/sandbox/driver/podman.rb +1 -0
  46. data/lib/rubik/sandbox/runner.rb +1 -1
  47. data/lib/rubik/security/classifier/classifier.rb +2 -0
  48. data/lib/rubik/storage/store.rb +4 -1
  49. data/lib/rubik/tools/registry.rb +36 -16
  50. data/lib/rubik/ui/capability.rb +6 -4
  51. data/lib/rubik/ui/markdown_stream.rb +1 -0
  52. data/lib/rubik/ui/renderer.rb +4 -2
  53. data/lib/rubik/version.rb +1 -1
  54. metadata +9 -1
@@ -185,6 +185,8 @@ module Rubik
185
185
  return unless deferred
186
186
 
187
187
  @retry_gate.attempt(deferred) do |fiber|
188
+ next unless @fibers[fiber.name].equal?(fiber) && fiber.state != :disposed
189
+
188
190
  with_activation_marker(fiber) { fiber.activate!(@context) }
189
191
  end
190
192
  end
@@ -241,7 +243,8 @@ module Rubik
241
243
  # fibers react to canonical re-provides instead of holding stale
242
244
  # service instances.
243
245
  def fiber_depends_on_service?(fiber, changed_key)
244
- fiber.inject.any? { |dep| dep == changed_key || Rubik::Coeffects.canonical(dep) == changed_key }
246
+ canonical_changed = Rubik::Coeffects.canonical(changed_key)
247
+ fiber.inject.any? { |dep| dep == changed_key || Rubik::Coeffects.canonical(dep) == canonical_changed }
245
248
  end
246
249
  end
247
250
  end
@@ -83,18 +83,18 @@ module Rubik
83
83
  attr_reader :guard, :context, :root_dir, :max_buffer_lines
84
84
  attr_accessor :init
85
85
 
86
- @instances = []
86
+ @instances = ObjectSpace::WeakMap.new
87
87
  @at_exit_installed = false
88
88
 
89
89
  def self.register_instance(mgr)
90
- @instances << mgr
90
+ @instances[mgr] = true
91
91
  return if @at_exit_installed
92
92
 
93
93
  @at_exit_installed = true
94
94
  at_exit do
95
95
  # Error-isolated sweep: one manager's kill_all raising must not
96
96
  # leave the remaining managers uncleaned at shutdown.
97
- @instances.each do |mgr|
97
+ @instances.each_key do |mgr|
98
98
  mgr.kill_all
99
99
  rescue StandardError => e
100
100
  Rubik::Log.warn(:runtime, "[TaskManager] at_exit kill_all failed: #{e.class}: #{e.message}")
@@ -4,6 +4,13 @@ module Rubik
4
4
  module Sandbox
5
5
  module Driver
6
6
  class Base
7
+ CONTAINER_HARDENING_FLAGS = [
8
+ "--read-only",
9
+ "--cap-drop", "ALL",
10
+ "--security-opt", "no-new-privileges",
11
+ "--tmpfs", "/tmp:rw,noexec,nosuid"
12
+ ].freeze
13
+
7
14
  attr_reader :options
8
15
 
9
16
  def initialize(options = {})
@@ -26,10 +26,7 @@ module Rubik
26
26
  docker_args = [
27
27
  "docker", "run", "--rm",
28
28
  "--name", container_name,
29
- "--read-only",
30
- "--cap-drop", "ALL",
31
- "--security-opt", "no-new-privileges",
32
- "--tmpfs", "/tmp:rw,noexec,nosuid",
29
+ *CONTAINER_HARDENING_FLAGS,
33
30
  "-w", "/workspace",
34
31
  "-v", "#{workspace}:/workspace:rw",
35
32
  "--memory", "#{memory_limit_mb}m",
@@ -21,6 +21,7 @@ module Rubik
21
21
 
22
22
  podman_args = [
23
23
  "podman", "run", "--rm",
24
+ *CONTAINER_HARDENING_FLAGS,
24
25
  "-w", "/workspace",
25
26
  "-v", "#{workspace}:/workspace:rw",
26
27
  "--memory", "#{memory_limit_mb}m",
@@ -143,7 +143,7 @@ module Rubik
143
143
  def verify_chdir_safety!(chdir)
144
144
  expanded = File.expand_path(chdir.to_s, @root_dir)
145
145
  safe = allowed_paths.any? do |allowed|
146
- Rubik::Platform.path_under?(expanded, allowed)
146
+ Rubik::Platform.resolved_path_under?(expanded, allowed)
147
147
  end
148
148
 
149
149
  unless safe
@@ -367,6 +367,8 @@ module Rubik
367
367
  return false if p =~ %r{\A[a-zA-Z]:(?![\\/])}
368
368
 
369
369
  return true if p =~ %r{\A/(?:\*|\.+)?/?\z}
370
+ # Root-anchored variable expansion (/$x, /$x/*, /${x}) can expand to / or /* when empty
371
+ return true if p =~ %r{\A/\$}
370
372
  return true if p =~ %r{\A[a-zA-Z]:[\\/](?:\*|\.+)?\z}i
371
373
  return true if HOME_TOKENS.include?(p) || p.start_with?("~/", "$HOME/", "${HOME}/")
372
374
 
@@ -272,7 +272,10 @@ module Rubik
272
272
  row = m[2].to_i
273
273
  return records.find { |r| r["type"] == type && r["row"] == row }
274
274
  end
275
- return records.find { |r| r["row"].to_s == selector } if selector.match?(/\A\d+\z/)
275
+ if selector.match?(/\A\d+\z/)
276
+ found = records.find { |r| r["row"].to_s == selector }
277
+ return found if found
278
+ end
276
279
  return records.find { |r| r["hash"].to_s.start_with?(selector.downcase) } if selector.match?(/\A[0-9a-f]{#{HASH_PREFIX_MIN},64}\z/i)
277
280
 
278
281
  # Son şans: alias — refs üzerinden tek sekme. Eski depolarda
@@ -13,6 +13,7 @@ module Rubik
13
13
  def initialize(coeffect_ctx: nil)
14
14
  @tools = {}
15
15
  @aliases = {}
16
+ @alias_owners = {}
16
17
  @tool_aliases = {}
17
18
  @origins = {}
18
19
  @coeffect_ctx = coeffect_ctx
@@ -24,32 +25,34 @@ module Rubik
24
25
  # while still allowing hot-updates of non-builtin tools.
25
26
  def register(tool_instance, aliases: [], origin: :builtin)
26
27
  @monitor.synchronize do
27
- @tools[tool_instance.name] = tool_instance
28
- @origins[tool_instance.name] = origin
28
+ name_str = tool_instance.name
29
+ clear_tool_aliases_unlocked(name_str)
30
+
31
+ @tools[name_str] = tool_instance
32
+ @origins[name_str] = origin
29
33
  all_aliases = (tool_instance.respond_to?(:aliases) ? Array(tool_instance.aliases) : []) + Array(aliases)
30
- @tool_aliases[tool_instance.name] ||= []
34
+ @tool_aliases[name_str] = []
31
35
  all_aliases.each do |al|
32
36
  clean_al = al.to_s.downcase
33
- @aliases[clean_al] = tool_instance.name
34
- @tool_aliases[tool_instance.name] << clean_al
37
+ owners = (@alias_owners[clean_al] ||= [])
38
+ owners.delete(name_str)
39
+ owners << name_str
40
+ @aliases[clean_al] = name_str
41
+ @tool_aliases[name_str] << clean_al unless @tool_aliases[name_str].include?(clean_al)
35
42
  end
36
43
  tool_instance
37
44
  end
38
45
  end
39
46
 
40
- def unregister(name)
47
+ def unregister(name, expected_instance = nil)
41
48
  @monitor.synchronize do
42
49
  canonical_name = @tools.key?(name.to_s) ? name.to_s : @aliases[name.to_s.downcase]
43
- removed_tool = @tools.delete(canonical_name) if canonical_name
44
- @origins.delete(canonical_name) if canonical_name
45
- if canonical_name && @tool_aliases[canonical_name]
46
- @tool_aliases.delete(canonical_name).each do |al|
47
- @aliases.delete(al) if @aliases[al] == canonical_name
48
- end
49
- else
50
- @aliases.delete_if { |_k, v| v == canonical_name || v == name.to_s }
51
- end
52
- @aliases.delete(name.to_s.downcase) if @aliases[name.to_s.downcase] == canonical_name
50
+ return nil unless canonical_name
51
+ return nil if expected_instance && !@tools[canonical_name].equal?(expected_instance)
52
+
53
+ removed_tool = @tools.delete(canonical_name)
54
+ @origins.delete(canonical_name)
55
+ clear_tool_aliases_unlocked(canonical_name)
53
56
  removed_tool
54
57
  end
55
58
  end
@@ -245,6 +248,23 @@ module Rubik
245
248
 
246
249
  @coeffect_ctx.satisfied?(deps)
247
250
  end
251
+
252
+ def clear_tool_aliases_unlocked(canonical_name)
253
+ old_aliases = @tool_aliases.delete(canonical_name) || []
254
+ old_aliases.each do |al|
255
+ owners = @alias_owners[al]
256
+ next unless owners
257
+
258
+ owners.delete(canonical_name)
259
+ if owners.empty?
260
+ @alias_owners.delete(al)
261
+ @aliases.delete(al)
262
+ else
263
+ @aliases[al] = owners.last
264
+ end
265
+ end
266
+ @aliases.delete_if { |_k, v| v == canonical_name }
267
+ end
248
268
  end
249
269
  end
250
270
  end
@@ -19,14 +19,16 @@ module Rubik
19
19
  module Capability
20
20
  FALSY_ENV_VALUES = ["0", "false", "no", "off"].freeze
21
21
 
22
+ OSC_ESCAPE_RE = /\e\][^\a\e]*(?:\a|\e\\|\z)/
23
+
22
24
  module_function
23
25
 
24
- # Strips ANSI SGR escape sequences from a string. Used on the recording
25
- # path (TeeIO -> StringIO) so session files and LLM context stay clean.
26
+ # Strips ANSI/CSI and OSC escape sequences from a string.
26
27
  def strip_ansi(str)
27
- return str unless str.is_a?(String) && str.include?("\e[")
28
+ return str unless str.is_a?(String) && str.include?("\e")
28
29
 
29
- Strings::ANSI.sanitize(str)
30
+ cleaned = str.gsub(OSC_ESCAPE_RE, "")
31
+ Strings::ANSI.sanitize(cleaned)
30
32
  end
31
33
 
32
34
  # True when ANSI color output is allowed for `io` under `config`.
@@ -79,6 +79,7 @@ module Rubik
79
79
  end
80
80
 
81
81
  def render_segment(segment)
82
+ segment = Rubik::UI::Capability.strip_ansi(segment)
82
83
  return segment unless @enabled
83
84
 
84
85
  line = segment.chomp
@@ -130,8 +130,10 @@ module Rubik
130
130
  def render_user_output(step_info)
131
131
  @spinner.stop
132
132
 
133
- header = @theme.paint("#{@theme.glyph(:branch)} #{step_info[:label]}", :dim)
134
- "#{header}\n#{step_info[:content]}\n"
133
+ label = Rubik::UI::Capability.strip_ansi(step_info[:label].to_s)
134
+ content = Rubik::UI::Capability.strip_ansi(step_info[:content].to_s)
135
+ header = @theme.paint("#{@theme.glyph(:branch)} #{label}", :dim)
136
+ "#{header}\n#{content}\n"
135
137
  end
136
138
 
137
139
  def render_tool_result(step_info)
data/lib/rubik/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubik
4
- VERSION = "0.11.0"
4
+ VERSION = "0.13.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Özgür Ulukır
@@ -275,6 +275,7 @@ files:
275
275
  - lib/rubik/buffer/manager.rb
276
276
  - lib/rubik/buffer/path_validator.rb
277
277
  - lib/rubik/buffer/snapshot.rb
278
+ - lib/rubik/cli/connect.rb
278
279
  - lib/rubik/cli/workspace_trust.rb
279
280
  - lib/rubik/coeffects.rb
280
281
  - lib/rubik/concurrency.rb
@@ -298,6 +299,12 @@ files:
298
299
  - lib/rubik/config/scoped.rb
299
300
  - lib/rubik/config/secret_policy.rb
300
301
  - lib/rubik/config/store.rb
302
+ - lib/rubik/connect.rb
303
+ - lib/rubik/connect/http.rb
304
+ - lib/rubik/connect/models_dev.rb
305
+ - lib/rubik/connect/probes.rb
306
+ - lib/rubik/connect/prompt_ui.rb
307
+ - lib/rubik/connect/wizard.rb
301
308
  - lib/rubik/context.rb
302
309
  - lib/rubik/context/git_info.rb
303
310
  - lib/rubik/context/git_lister.rb
@@ -468,6 +475,7 @@ files:
468
475
  - lib/rubik/repl/commands/agent_providers.rb
469
476
  - lib/rubik/repl/commands/base.rb
470
477
  - lib/rubik/repl/commands/buffer.rb
478
+ - lib/rubik/repl/commands/connect.rb
471
479
  - lib/rubik/repl/commands/dmesg.rb
472
480
  - lib/rubik/repl/commands/lsp.rb
473
481
  - lib/rubik/repl/commands/mcp.rb