rubik 0.13.0 → 0.15.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +122 -1
  4. data/lib/rubik/adapter/node.rb +4 -1
  5. data/lib/rubik/ast/c_extractor.rb +1 -1
  6. data/lib/rubik/ast/fallback_cleaner.rb +6 -1
  7. data/lib/rubik/ast/graph.rb +38 -57
  8. data/lib/rubik/ast/graph_extensions.rb +57 -15
  9. data/lib/rubik/ast/ruby_extractor.rb +16 -6
  10. data/lib/rubik/ast/treesitter/c_walker.rb +11 -3
  11. data/lib/rubik/buffer/manager.rb +38 -11
  12. data/lib/rubik/buffer/snapshot.rb +116 -28
  13. data/lib/rubik/cli/connect.rb +3 -5
  14. data/lib/rubik/config/defaults.rb +3 -7
  15. data/lib/rubik/config/env_guard.rb +43 -0
  16. data/lib/rubik/config/schema.rb +7 -1
  17. data/lib/rubik/config/scoped.rb +12 -5
  18. data/lib/rubik/config/secret_policy.rb +6 -5
  19. data/lib/rubik/config.rb +1 -1
  20. data/lib/rubik/connect/models_dev.rb +11 -0
  21. data/lib/rubik/connect/probes.rb +9 -2
  22. data/lib/rubik/connect/wizard.rb +117 -57
  23. data/lib/rubik/context/repo_context_reader.rb +8 -4
  24. data/lib/rubik/diagnostics/collector.rb +25 -2
  25. data/lib/rubik/llm/chunk_assembler.rb +12 -1
  26. data/lib/rubik/llm/client.rb +19 -0
  27. data/lib/rubik/llm/connection_pool.rb +7 -1
  28. data/lib/rubik/llm/formatter.rb +22 -2
  29. data/lib/rubik/llm/provider_key.rb +32 -0
  30. data/lib/rubik/llm/registry.rb +18 -2
  31. data/lib/rubik/llm/router.rb +27 -1
  32. data/lib/rubik/llm/session_header.rb +128 -0
  33. data/lib/rubik/llm/sse_parser.rb +57 -10
  34. data/lib/rubik/lsp/client.rb +244 -23
  35. data/lib/rubik/lsp/document_store.rb +6 -0
  36. data/lib/rubik/lsp/manager.rb +14 -0
  37. data/lib/rubik/lsp/transport.rb +34 -7
  38. data/lib/rubik/mcp/transport/stdio.rb +42 -4
  39. data/lib/rubik/orchestrator/continuation_manager.rb +68 -7
  40. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +18 -2
  41. data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +13 -4
  42. data/lib/rubik/orchestrator/goal_ledger/validator.rb +46 -7
  43. data/lib/rubik/orchestrator/goal_ledger/verifier.rb +8 -1
  44. data/lib/rubik/orchestrator/goal_session.rb +14 -14
  45. data/lib/rubik/orchestrator/goal_wait.rb +15 -9
  46. data/lib/rubik/orchestrator/loop.rb +39 -39
  47. data/lib/rubik/orchestrator/provider_resolver.rb +29 -6
  48. data/lib/rubik/orchestrator/step_executor.rb +17 -2
  49. data/lib/rubik/orchestrator/subagent/instance.rb +46 -5
  50. data/lib/rubik/orchestrator/subagent/lifecycle.rb +25 -25
  51. data/lib/rubik/orchestrator/subagent/messaging.rb +5 -1
  52. data/lib/rubik/orchestrator/subagent/narration.rb +2 -1
  53. data/lib/rubik/orchestrator/subagent/notices.rb +7 -3
  54. data/lib/rubik/orchestrator/subagent/questioner.rb +42 -4
  55. data/lib/rubik/orchestrator/subagent/reaper.rb +70 -20
  56. data/lib/rubik/orchestrator/subagent/start_gate.rb +1 -1
  57. data/lib/rubik/orchestrator/subagent/step_runner.rb +7 -7
  58. data/lib/rubik/orchestrator/subagent/supervisor.rb +21 -3
  59. data/lib/rubik/orchestrator/tool_call_id.rb +8 -4
  60. data/lib/rubik/orchestrator/turn_executor/subagent_channel.rb +21 -5
  61. data/lib/rubik/orchestrator/turn_executor/user_channel.rb +40 -5
  62. data/lib/rubik/orchestrator/turn_executor.rb +24 -8
  63. data/lib/rubik/platform/filesystem.rb +52 -24
  64. data/lib/rubik/platform/process.rb +32 -7
  65. data/lib/rubik/platform/sanitize.rb +17 -18
  66. data/lib/rubik/platform.rb +27 -0
  67. data/lib/rubik/plugin/storage.rb +34 -8
  68. data/lib/rubik/prompt/context_builder.rb +2 -1
  69. data/lib/rubik/prompt/doctrine.rb +3 -2
  70. data/lib/rubik/repair/loop.rb +22 -2
  71. data/lib/rubik/repl/commands/agent_context.rb +1 -1
  72. data/lib/rubik/repl/commands/agent_execution.rb +20 -15
  73. data/lib/rubik/repl/commands/base.rb +7 -3
  74. data/lib/rubik/repl/commands/buffer.rb +21 -2
  75. data/lib/rubik/repl/commands/connect.rb +0 -1
  76. data/lib/rubik/repl/commands/lsp.rb +1 -1
  77. data/lib/rubik/repl/commands/plugins.rb +31 -31
  78. data/lib/rubik/repl/commands/session.rb +16 -6
  79. data/lib/rubik/repl/commands/workspace.rb +4 -4
  80. data/lib/rubik/repl/input_execution.rb +33 -32
  81. data/lib/rubik/repl/input_loop.rb +9 -4
  82. data/lib/rubik/repl/lifecycle.rb +1 -2
  83. data/lib/rubik/repl/notice_router.rb +11 -5
  84. data/lib/rubik/repl/paste_support.rb +1 -1
  85. data/lib/rubik/repl/prompt_grace.rb +3 -3
  86. data/lib/rubik/repl/service_catalog.rb +6 -2
  87. data/lib/rubik/repl/shell.rb +10 -2
  88. data/lib/rubik/repl/turn_recorder.rb +18 -4
  89. data/lib/rubik/runtime/context.rb +33 -27
  90. data/lib/rubik/runtime/manager.rb +23 -15
  91. data/lib/rubik/runtime/manifest_store.rb +7 -2
  92. data/lib/rubik/runtime/task_manager.rb +13 -10
  93. data/lib/rubik/sandbox/driver/base.rb +34 -0
  94. data/lib/rubik/sandbox/driver/bubblewrap.rb +60 -8
  95. data/lib/rubik/sandbox/driver/docker.rb +8 -0
  96. data/lib/rubik/sandbox/driver/podman.rb +8 -0
  97. data/lib/rubik/sandbox/driver/process.rb +29 -1
  98. data/lib/rubik/sandbox/runner.rb +9 -1
  99. data/lib/rubik/security/classifier/classifier.rb +147 -13
  100. data/lib/rubik/security/classifier/commands/docker.yaml +1 -1
  101. data/lib/rubik/security/classifier/commands/git.yaml +27 -1
  102. data/lib/rubik/security/classifier/commands/sed.yaml +3 -3
  103. data/lib/rubik/security/classifier/database.rb +2 -2
  104. data/lib/rubik/security/command_gate.rb +8 -1
  105. data/lib/rubik/security/path_policy.rb +28 -3
  106. data/lib/rubik/security/redactor.rb +62 -19
  107. data/lib/rubik/session/recorder.rb +27 -20
  108. data/lib/rubik/session/replayer.rb +29 -7
  109. data/lib/rubik/storage/store.rb +26 -5
  110. data/lib/rubik/tools/builtins/exec.rb +8 -2
  111. data/lib/rubik/tools/builtins/files.rb +8 -12
  112. data/lib/rubik/tools/builtins/grep.rb +3 -2
  113. data/lib/rubik/tools/builtins/interactive.rb +5 -2
  114. data/lib/rubik/tools/builtins/lsp.rb +59 -9
  115. data/lib/rubik/tools/builtins/send_message.rb +7 -2
  116. data/lib/rubik/tools/builtins/show_file.rb +1 -1
  117. data/lib/rubik/tools/builtins/synthesis.rb +4 -4
  118. data/lib/rubik/tools/preflight_runner.rb +4 -1
  119. data/lib/rubik/tools/result_normalizer.rb +1 -1
  120. data/lib/rubik/ui/banner.rb +3 -3
  121. data/lib/rubik/ui/dialog.rb +15 -8
  122. data/lib/rubik/ui/diff_viewer.rb +4 -4
  123. data/lib/rubik/ui/frame.rb +13 -3
  124. data/lib/rubik/ui/markdown_stream.rb +8 -2
  125. data/lib/rubik/ui/panel.rb +11 -11
  126. data/lib/rubik/ui/renderer.rb +10 -7
  127. data/lib/rubik/ui/spinner.rb +1 -1
  128. data/lib/rubik/ui/statusline.rb +3 -3
  129. data/lib/rubik/ui/theme.rb +1 -1
  130. data/lib/rubik/version.rb +1 -1
  131. metadata +4 -1
@@ -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
@@ -127,6 +127,12 @@ module Rubik
127
127
  FileUtils.mkdir_p(target_dir)
128
128
  target_file = File.join(target_dir, "#{safe_name}.jsonl")
129
129
 
130
+ # Durability barrier before the copy so the copied JSONL can
131
+ # never carry a torn tail from the recorder's append stream
132
+ # (issue #598). Both branches write the same JSONL content; the
133
+ # fallback only fires when no live file exists yet, in which
134
+ # case @events holds the same (recent) events.
135
+ ctx.recorder.flush
130
136
  if ctx.recorder.session_file && File.exist?(ctx.recorder.session_file)
131
137
  FileUtils.cp(ctx.recorder.session_file, target_file)
132
138
  else
@@ -134,7 +140,11 @@ module Rubik
134
140
  ctx.recorder.events.each { |ev| f.puts(JSON.dump(ev)) }
135
141
  end
136
142
  end
137
- ctx.recorder.switch_session_file(target_file, cleanup_empty_current: false)
143
+ # Provenance: the saved copy's parent is the session it was
144
+ # copied FROM (captured before the switch), not the target's
145
+ # own basename (issue #598).
146
+ ctx.recorder.switch_session_file(target_file, cleanup_empty_current: false,
147
+ parent_session_id: ctx.recorder.session_id)
138
148
  ctx.out.puts "[Rubik::Session] Session saved to #{target_file}"
139
149
  end
140
150
 
@@ -194,11 +204,11 @@ module Rubik
194
204
  return nil if sessions.empty?
195
205
 
196
206
  prompt = Rubik::UI::Approvals.build_prompt(ctx)
197
- prompt.select("Devam edilecek oturumu seç:") do |menu|
207
+ prompt.select("Select the session to resume:") do |menu|
198
208
  sessions.first(15).each do |s|
199
- menu.choice "#{s[:id]} · #{s[:event_count]} olay · \"#{s[:last_prompt].to_s[0, 40]}\"", s[:id]
209
+ menu.choice "#{s[:id]} · #{s[:event_count]} events · \"#{s[:last_prompt].to_s[0, 40]}\"", s[:id]
200
210
  end
201
- menu.choice "← en son oturum (:latest)", :latest
211
+ menu.choice "← latest session (:latest)", :latest
202
212
  end
203
213
  rescue Interrupt
204
214
  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
@@ -57,7 +57,7 @@ module Rubik
57
57
  cmd_meta[:handler].call(parsed.args, command_context)
58
58
  rescue Interrupt
59
59
  Rubik::REPL::InterruptHandler.restore_console_after_interrupt
60
- @output.puts "\n⚠️ [Rubik] Komut kullanıcı tarafından iptal edildi (^C)."
60
+ @output.puts "\n⚠️ [Rubik] Command cancelled by user (^C)."
61
61
  ensure
62
62
  # !goal dahil lifecycle komutları tracked dal ile aynı spinner
63
63
  # garantisini taşır (field incident 2026-10-12: !goal'ten kaçan
@@ -74,7 +74,7 @@ module Rubik
74
74
  rescue Interrupt
75
75
  cmd_interrupted = true
76
76
  Rubik::REPL::InterruptHandler.restore_console_after_interrupt
77
- @output.puts "\n⚠️ [Rubik] Komut kullanıcı tarafından iptal edildi (^C)."
77
+ @output.puts "\n⚠️ [Rubik] Command cancelled by user (^C)."
78
78
  ensure
79
79
  # A command (!plan/!goal) may leave a live spinner if it died mid-wait.
80
80
  kill_command_spinner!
@@ -99,7 +99,7 @@ module Rubik
99
99
  reap_dead_kernel_units! if respond_to?(:reap_dead_kernel_units!)
100
100
  else
101
101
  available = @commands.keys.sort.map { |c| "!#{c}" }.join(", ")
102
- @output.puts "Bilinmeyen komut: !#{parsed.command_name}. Kullanılabilir komutlar: #{available} (!help'e bakın)."
102
+ @output.puts "Unknown command: !#{parsed.command_name}. Available commands: #{available} (see !help)."
103
103
  end
104
104
  end
105
105
 
@@ -212,7 +212,7 @@ module Rubik
212
212
  # context already includes the idle-injected notices. The notice
213
213
  # turn itself drains first, so this clear is a no-op for it.
214
214
  clear_pending_wake_notices! if respond_to?(:clear_pending_wake_notices!)
215
- @recorder&.record_user_turn(text)
215
+ @recorder&.record_user_turn(text) unless @replaying
216
216
  @event_bus.emit(:prompt_received, prompt: text)
217
217
  task
218
218
  end
@@ -225,7 +225,7 @@ module Rubik
225
225
  return routed if routed[:provider]
226
226
 
227
227
  spec_str = routed[:spec].is_a?(Hash) ? "#{routed[:spec]['provider']}/#{routed[:spec]['name']}" : routed[:spec].to_s
228
- @output.puts "Hata: Model sağlayıcısı başlatılamadı (#{spec_str})."
228
+ @output.puts "Error: Could not initialize model provider (#{spec_str})."
229
229
  record_failed_turn!(text, "failed", "no LLM provider available (#{spec_str})", nil)
230
230
  nil
231
231
  end
@@ -270,12 +270,12 @@ module Rubik
270
270
  md_stream.finish { |seg| @output.print seg }
271
271
  @output.flush if @output.respond_to?(:flush)
272
272
  when :tool_call
273
- @recorder&.record_tool_call(step_info[:tool], step_info[:args], call_id: step_info[:call_id])
273
+ @recorder&.record_tool_call(step_info[:tool], step_info[:args], call_id: step_info[:call_id]) unless @replaying
274
274
  formatted = renderer.render(step_info)
275
275
  @output.puts formatted if formatted && !formatted.empty?
276
276
  @output.flush if @output.respond_to?(:flush)
277
277
  when :tool_result
278
- @recorder&.record_tool_result(step_info[:tool], step_info[:output], status: step_info[:status] || :ok, call_id: step_info[:call_id])
278
+ @recorder&.record_tool_result(step_info[:tool], step_info[:output], status: step_info[:status] || :ok, call_id: step_info[:call_id]) unless @replaying
279
279
  formatted = renderer.render(step_info)
280
280
  @output.puts formatted if formatted && !formatted.empty?
281
281
  @output.flush if @output.respond_to?(:flush)
@@ -314,28 +314,28 @@ module Rubik
314
314
  def drive_budget_continuations!(orchestrator, res)
315
315
  while !res[:ok] && res[:reason] == :budget_exhausted && Rubik::Storage::Layout.config_get(@config, "agent.ask_continue_on_limit", true)
316
316
  @output.puts "\n⚠️ [Rubik::Agent] #{res[:error]}"
317
- ans = ask_yes_no(" [Rubik::Agent] +20 adım ile devam edilsin mi?", default: "n")
317
+ ans = ask_yes_no(" [Rubik::Agent] Continue with +20 steps?", default: "n")
318
318
  break unless ["y", "yes", "evet"].include?(ans)
319
319
 
320
- @output.puts " [Rubik::Agent] Adım bütçesi +20 artırılıyor ve görev sürdürülüyor..."
320
+ @output.puts " [Rubik::Agent] Increasing step budget by +20 and resuming task..."
321
321
  res = orchestrator.continue_loop(20)
322
322
 
323
323
  end
324
324
  res
325
325
  end
326
326
 
327
- # Settle phase: merges the turn's tool history, then records and
328
- # reports the outcome (success render / incomplete report). theme and
329
- # md_enabled arrive from the display phase for the batch render.
327
+ # Settle phase: records the outcome FIRST, then merges the turn's tool
328
+ # history and reports the result. theme and md_enabled arrive from the
329
+ # display phase for the batch render.
330
330
  def settle_free_text_result!(text, res, orchestrator:, theme:, md_enabled:)
331
- # Plan 85 D-7 (kök neden): turn içi @history'deki tool ara adımlarını
332
- # conversation_history'ye kopyala — böylece continue'da model turn sırasındaki
333
- # bağlamı görür ve "sıfırdan keşfe" başlamaz. res[:loop_instance].history,
334
- # turn_result'ın döndürdüğü Loop örneğinin @history'sidir.
335
- merge_unseen_turn_tool_history!(res[:loop_instance])
336
-
337
331
  if res[:ok]
338
332
  record_turn_outcome!(text, res[:output].to_s, tokens: res[:tokens], streamed: res[:streamed] == true)
333
+ # Plan 85 D-7: copy in-turn tool steps into conversation_history so
334
+ # a follow-up sees them. This MUST follow record_turn_outcome! —
335
+ # its trim drops leading rows until a user row leads the window,
336
+ # so merging first evicts every tool row on a fresh/cleared window
337
+ # (issue #557). All rescue paths already use this ordering.
338
+ merge_unseen_turn_tool_history!(res[:loop_instance])
339
339
 
340
340
  # Only print the final answer when it was not already streamed
341
341
  # live; batch answers get full markdown rendering on capable TTYs.
@@ -356,8 +356,9 @@ module Rubik
356
356
  emit_turn_finished(kind: "success", prompt: text, outcome: res[:output].to_s,
357
357
  orchestrator: orchestrator, tokens: res[:tokens])
358
358
  else
359
- @output.puts "Görev tamamlanamadı: #{res[:error]}"
359
+ @output.puts "Task could not be completed: #{res[:error]}"
360
360
  record_failed_turn!(text, "incomplete", res[:error], orchestrator)
361
+ merge_unseen_turn_tool_history!(res[:loop_instance])
361
362
  end
362
363
  end
363
364
 
@@ -407,8 +408,8 @@ module Rubik
407
408
  # execute_steps yolu) işletilir — aynı @history, aynı adım bütçesi
408
409
  # (kullanıcının !steps extend'i dahil). Amaç-eşleşmesi BİREBİRDİR:
409
410
  # substring eşleşmesi yeni bir görevi yanlışlıkla resume sanabilir.
410
- RESUME_INTENTS = ["devam et", "devam", "continue", "sürdür"].freeze
411
- RESUME_PROMPT = "devam et"
411
+ RESUME_INTENTS = ["devam et", "devam", "continue", "sürdür", "resume"].freeze
412
+ RESUME_PROMPT = "continue"
412
413
  RESUME_REASON = "llm_error_recovery"
413
414
 
414
415
  def resumable_turn? = !!@resumable_turn
@@ -443,14 +444,14 @@ module Rubik
443
444
  def stash_and_announce_resume!(orchestrator)
444
445
  return unless stash_resumable_turn!(orchestrator)
445
446
 
446
- @output.puts "[Rubik] Turn duraklatıldı (adım #{orchestrator.step_count}/#{orchestrator.max_steps}). " \
447
- "'devam et' yazarsan aynı bağlam ve adım bütçesiyle sürer; başka bir şey yazarsan yeni görev olarak koşar."
447
+ @output.puts "[Rubik] Turn paused (step #{orchestrator.step_count}/#{orchestrator.max_steps}). " \
448
+ "Type 'continue' to resume with the same context and step budget; type anything else to run as a new task."
448
449
  end
449
450
 
450
451
  # Duraklatılmış turn'in yeniden koşusu: taze turn yaşam döngüsünü
451
452
  # (arming → display → settle → rescue merdiveni → ensure teardown)
452
453
  # resume sözleşmesiyle birleştirir. Kullanıcının yazdığı satır
453
- # recorder'a ve konuşma hafızasına "devam et" olarak düşer — dürüst
454
+ # recorder'a ve konuşma hafızasına "continue" olarak düşer — dürüst
454
455
  # provenance; orijinal görev metni Loop'un kendi @history'sinde
455
456
  # yaşamaya devam eder ve modele tekrar gönderilmez.
456
457
  def execute_resumed_turn!
@@ -498,7 +499,7 @@ module Rubik
498
499
  @recorder&.record("cancelled_turn",
499
500
  "question" => text.to_s.strip[0, 80],
500
501
  "reason" => "Interrupted by user (^C)")
501
- @output.puts "\n⚠️ [Rubik::Agent] Görev kullanıcı tarafından iptal edildi (^C)."
502
+ @output.puts "\n⚠️ [Rubik::Agent] Task cancelled by user (^C)."
502
503
  record_failed_turn!(text, "cancelled", "Interrupted by user (^C)", orchestrator)
503
504
  merge_failed_turn_tool_history!(orchestrator)
504
505
  end
@@ -510,7 +511,7 @@ module Rubik
510
511
  # LLM error. Sanitize before use.
511
512
  def handle_llm_client_error!(text, error, orchestrator)
512
513
  message = Rubik::Platform.safe_utf8(error.message)
513
- @output.puts "[Rubik::LLM Hatası] #{message}"
514
+ @output.puts "[Rubik::LLM Error] #{message}"
514
515
  record_failed_turn!(text, "failed", message, orchestrator)
515
516
  merge_failed_turn_tool_history!(orchestrator)
516
517
  stash_and_announce_resume!(orchestrator) unless @autonomous_turn
@@ -520,7 +521,7 @@ module Rubik
520
521
  # error path above.
521
522
  def handle_unexpected_error!(text, error, orchestrator)
522
523
  message = Rubik::Platform.safe_utf8(error.message)
523
- @output.puts "[Hata] #{error.class}: #{message}"
524
+ @output.puts "[Error] #{error.class}: #{message}"
524
525
  record_failed_turn!(text, "failed", "#{error.class}: #{message}", orchestrator)
525
526
  merge_failed_turn_tool_history!(orchestrator)
526
527
  end
@@ -575,15 +576,15 @@ module Rubik
575
576
  # interrupted WAIT; one with owned work is a cancelled TASK TREE — and
576
577
  # remaining work is named, so an incomplete cleanup is never silent.
577
578
  def task_cancellation_lines(outcome)
578
- return ["⏸️ [Rubik] Bekleme kesildi (^C) — iptal edilecek bağlı alt ajan yok."] unless outcome&.any?
579
+ return ["⏸️ [Rubik] Wait interrupted (^C) — no linked subagents to cancel."] unless outcome&.any?
579
580
 
580
- line = "🛑 [Rubik] Görev ağacı iptal edildi (^C): #{outcome.stopped.size} bağlı alt ajan durduruldu"
581
- line << ", #{outcome.queued_cancelled.size} kuyruk işi iptal edildi" unless outcome.queued_cancelled.empty?
581
+ line = "🛑 [Rubik] Task tree cancelled (^C): #{outcome.stopped.size} linked subagents stopped"
582
+ line << ", #{outcome.queued_cancelled.size} queued jobs cancelled" unless outcome.queued_cancelled.empty?
582
583
  if outcome.complete?
583
- line << "; temizlik tamamlandı."
584
+ line << "; cleanup completed."
584
585
  else
585
586
  remaining = outcome.remaining.map { |r| "#{r[:id]}:#{r[:state]}" }.join(", ")
586
- line << "; temizlik TAMAMLANMADI — kalan: #{remaining}."
587
+ line << "; cleanup INCOMPLETE — remaining: #{remaining}."
587
588
  end
588
589
  [line]
589
590
  end
@@ -197,15 +197,20 @@ module Rubik
197
197
  end
198
198
 
199
199
  def process_normal_line(line, _multiline_buffer)
200
- # Only trigger heredoc if line explicitly opens a multiline block (e.g. `<<EOF`, `!plan <<EOF`)
201
- # NEVER trigger on inline operators like `array << item` or `a << b`
202
- heredoc_match = line.match(/\A[ \t]*(?:[a-zA-Z0-9_!.-]+[ \t]+)?<<[-~]?['"]?([A-Za-z0-9_]+)['"]?[ \t]*\z/)
200
+ # Only trigger heredoc if line explicitly opens a multiline block
201
+ # (e.g. `<< EOF`, `!plan << EOF`). Whitespace after `<<` is required:
202
+ # `array <<item` is an inline append operator, not a heredoc (#557).
203
+ heredoc_match = line.match(/\A[ \t]*(?:![a-zA-Z0-9_.-]+[ \t]+)?<<[-~]?[ \t]+['"]?([A-Za-z0-9_]+)['"]?[ \t]*\z/)
203
204
  if heredoc_match && !line.strip.start_with?("#")
204
205
  delimiter = heredoc_match[1]
205
- prefix = line.sub(/<<[-~]?['"]?#{Regexp.escape(delimiter)}['"]?\s*$/, "").strip
206
+ prefix = line.sub(/<<[-~]?[ \t]+['"]?#{Regexp.escape(delimiter)}['"]?\s*$/, "").strip
206
207
  buffer = prefix.empty? ? [] : [prefix]
207
208
  { stop: false, buffer: buffer, delimiter: delimiter }
208
209
  elsif ["exit", "quit", "!exit", "!quit"].include?(line.strip.downcase)
210
+ # Design note (#557): interactive mode stops the REPL here, while
211
+ # stream mode (execute_input) sends the same tokens to the model.
212
+ # This divergence is deliberate — piped scripts use the model as
213
+ # the interpreter — so do not "align" it without a product decision.
209
214
  stop
210
215
  { stop: true, buffer: [], delimiter: nil }
211
216
  else
@@ -151,8 +151,7 @@ module Rubik
151
151
  return unless Rubik::Storage::Layout.config_get(@config, "connect.first_run_offer", true)
152
152
  return unless llm_client_pending?
153
153
 
154
- answer = ask_yes_no("Hiç model sağlayıcısı yapılandırılmamış görünüyor. Bağlantı sihirbazı çalıştırılsın mı? / " \
155
- "No LLM provider is configured yet. Run the connect wizard?", default: "n")
154
+ answer = ask_yes_no("No LLM provider is configured yet. Run the connect wizard?", default: "n")
156
155
  return unless ["y", "yes", "evet"].include?(answer.to_s.downcase)
157
156
 
158
157
  ui = Rubik::Connect::PromptUI.new(input: @input,
@@ -238,12 +238,18 @@ module Rubik
238
238
 
239
239
  def inject_subagent_notice_into_conversation_history!(notice)
240
240
  xml_payload = Rubik::Orchestrator::Subagent::Notices.history_block([notice])
241
- history = shell_state(:conversation_history)
242
- unless history
243
- history = []
244
- @shell.instance_variable_set(:@conversation_history, history)
241
+ # The bus thread injects while the turn thread may replace the whole
242
+ # history array in trim_conversation_window!. Share the standby mutex
243
+ # with that mutation so a notice is never written to a stale array
244
+ # (issue #557).
245
+ subagent_notices_mutex.synchronize do
246
+ history = shell_state(:conversation_history)
247
+ unless history
248
+ history = []
249
+ @shell.instance_variable_set(:@conversation_history, history)
250
+ end
251
+ Rubik::Prompt::ConversationRows.append_notice!(history, xml_payload)
245
252
  end
246
- Rubik::Prompt::ConversationRows.append_notice!(history, xml_payload)
247
253
  end
248
254
 
249
255
  def flush_subagent_notices!
@@ -66,7 +66,7 @@ module Rubik
66
66
  # Plan 109: koleksiyon with_collecting içinde — reaktif bir uyandırma
67
67
  # Enter'ı yapıştırılan metne boş satır eklemez.
68
68
  def read_paste_block
69
- @output.puts "[Rubik] Paste modu: metni yapıştırın, bitirmek için tek başına '.' yazın (Ctrl+C iptal)."
69
+ @output.puts "[Rubik] Paste mode: paste the text, type '.' on its own to finish (Ctrl+C to cancel)."
70
70
  lines = []
71
71
  collector = lambda do
72
72
  loop do
@@ -11,7 +11,7 @@ module Rubik
11
11
  # effects and is pruned from its parent on every exit.
12
12
  class PromptGrace
13
13
  ESCAPE_TIMEOUT = 0.03
14
- STATUS = "Gönderiliyor… Esc: düzenlemeye dön"
14
+ STATUS = "Sending… Esc: return to editing"
15
15
 
16
16
  def initialize(input:, output:, context: nil, clock: nil, reader: nil)
17
17
  @input = input
@@ -42,7 +42,7 @@ module Rubik
42
42
  # the last processed key. Do not let its Enter submit a later turn.
43
43
  if @input.respond_to?(:nread) && @input.nread.positive?
44
44
  @input.iflush
45
- @output.print "\a\r\e[2K[Rubik] Bekleme sırasında gelen tuşlar yok sayıldı.\r\n"
45
+ @output.print "\a\r\e[2K[Rubik] Keys received while waiting were ignored.\r\n"
46
46
  end
47
47
  return :execute
48
48
  end
@@ -58,7 +58,7 @@ module Rubik
58
58
 
59
59
  # Other keys are intentionally rejected, with immediate feedback.
60
60
  # Enter never leaks into the next readline as an accidental submit.
61
- @output.print "\a\r\e[2K#{STATUS} · Tuş yok sayıldı"
61
+ @output.print "\a\r\e[2K#{STATUS} · Key ignored"
62
62
  @output.flush
63
63
  end
64
64
  rescue Interrupt
@@ -138,8 +138,12 @@ module Rubik
138
138
  DEFINITION.new(
139
139
  name: :snapshot_store,
140
140
  builder: lambda do |s|
141
- Rubik::Buffer::SnapshotStore.new(storage_dir: File.join(s.home_dir, ".rubik", "snapshots",
142
- File.basename(s.root_dir)))
141
+ # Issue #589: debounced snapshot persistence (undo granularity
142
+ # stays in memory) + on-disk retention cap.
143
+ Rubik::Buffer::SnapshotStore.new(
144
+ storage_dir: File.join(s.home_dir, ".rubik", "snapshots", File.basename(s.root_dir)),
145
+ min_interval: 1.0, max_snapshots: 200
146
+ )
143
147
  end,
144
148
  provide: Rubik::Coeffects::SNAPSHOT_STORE
145
149
  ),
@@ -193,7 +193,12 @@ module Rubik
193
193
  # @return [void]
194
194
  def execute_input(input_text)
195
195
  parsed = CommandParser.parse(input_text)
196
- @recorder.record(parsed.type, input_text) if !@replaying && parsed.type != :empty && parsed.type != :prompt
196
+ # Redact at the record seam, BEFORE the transcript write: provider
197
+ # CLI forms (`--key=…`, `set <name> key <value>`) are accepted here and
198
+ # must never land in the JSONL even if a recorder wrapper changes
199
+ # (issue #542). The recorder masks again as defence in depth.
200
+ clean_input = Rubik::Security::Redactor.redact(input_text)
201
+ @recorder.record(parsed.type, clean_input) if !@replaying && parsed.type != :empty && parsed.type != :prompt
197
202
 
198
203
  case parsed.type
199
204
  when :empty
@@ -208,7 +213,10 @@ module Rubik
208
213
  if resume_intent?(parsed.raw)
209
214
  execute_resumed_turn!
210
215
  else
211
- execute_free_text(parsed.raw)
216
+ # The redacted form is the one that reaches the recorder, the
217
+ # conversation window and every downstream LLM request — a
218
+ # pasted credential must not become durable prompt memory (#542).
219
+ execute_free_text(clean_input)
212
220
  end
213
221
  end
214
222
 
@@ -47,7 +47,10 @@ module Rubik
47
47
  @conversation_history << { role: "user", content: user_text }
48
48
  @conversation_history << { role: "assistant", content: assistant_content.to_s }
49
49
  trim_conversation_window!
50
- @recorder&.record_assistant_response(assistant_content.to_s, tokens: tokens, streamed: streamed)
50
+ # Same one policy as the input record (shell.rb): replayed turns
51
+ # hydrate the conversation window but must not re-record events
52
+ # into the active session JSONL (issue #598).
53
+ @recorder&.record_assistant_response(assistant_content.to_s, tokens: tokens, streamed: streamed) unless @replaying
51
54
  rescue StandardError => e
52
55
  Rubik::Platform.debug_warn("turn outcome recording failed (#{e.class}: #{e.message}); turn lost from conversation memory")
53
56
  nil
@@ -135,9 +138,20 @@ module Rubik
135
138
  Rubik::Platform.debug_warn("input ceiling lookup failed (#{e.class}: #{e.message}); using nil budget")
136
139
  nil
137
140
  end
138
- @conversation_history = Rubik::Prompt::ContextCompactor.trim_history_to_budget(
139
- @conversation_history, ceiling: ceiling, max_entries: MAX_CONVERSATION_ENTRIES
140
- )
141
+ # Serialize the read-compute-replace of the history array with the
142
+ # bus-thread notice injection (issue #557). Both sides use the same
143
+ # mutex owned by NoticeRouter; bare EmitHost doubles skip the lock.
144
+ if respond_to?(:notice_router)
145
+ notice_router.subagent_notices_mutex.synchronize do
146
+ @conversation_history = Rubik::Prompt::ContextCompactor.trim_history_to_budget(
147
+ @conversation_history, ceiling: ceiling, max_entries: MAX_CONVERSATION_ENTRIES
148
+ )
149
+ end
150
+ else
151
+ @conversation_history = Rubik::Prompt::ContextCompactor.trim_history_to_budget(
152
+ @conversation_history, ceiling: ceiling, max_entries: MAX_CONVERSATION_ENTRIES
153
+ )
154
+ end
141
155
  rescue StandardError => e
142
156
  Rubik::Log.warn(:repl, "conversation trim failed (#{e.class}: #{e.message}); window may exceed token budget")
143
157
  nil