rubik 0.9.1 → 0.10.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 +143 -1
  4. data/lib/rubik/adapter/base.rb +2 -1
  5. data/lib/rubik/adapter/process.rb +28 -67
  6. data/lib/rubik/benchmark/vakanuvis_adoption.rb +10 -3
  7. data/lib/rubik/buffer/apply_contract.rb +3 -3
  8. data/lib/rubik/buffer/apply_transaction.rb +165 -0
  9. data/lib/rubik/buffer/manager.rb +26 -120
  10. data/lib/rubik/config/deep_ops.rb +4 -1
  11. data/lib/rubik/config/defaults.rb +6 -3
  12. data/lib/rubik/config/schema.rb +8 -0
  13. data/lib/rubik/config/secret_policy.rb +197 -0
  14. data/lib/rubik/config.rb +11 -0
  15. data/lib/rubik/diagnostics/collector.rb +0 -9
  16. data/lib/rubik/errors.rb +15 -0
  17. data/lib/rubik/event_bus.rb +2 -1
  18. data/lib/rubik/kernel/dispatcher.rb +12 -7
  19. data/lib/rubik/kernel/unit.rb +4 -1
  20. data/lib/rubik/llm/registry.rb +12 -9
  21. data/lib/rubik/llm/router.rb +2 -5
  22. data/lib/rubik/log.rb +21 -0
  23. data/lib/rubik/lsp/client.rb +77 -273
  24. data/lib/rubik/lsp/manager.rb +14 -10
  25. data/lib/rubik/lsp/transport.rb +365 -0
  26. data/lib/rubik/mcp/boot_lifecycle.rb +6 -2
  27. data/lib/rubik/mcp/boot_run.rb +190 -0
  28. data/lib/rubik/mcp/manager.rb +40 -163
  29. data/lib/rubik/mcp/transport/stdio.rb +4 -1
  30. data/lib/rubik/orchestrator/auto_apply.rb +4 -3
  31. data/lib/rubik/orchestrator/continuation_manager.rb +3 -22
  32. data/lib/rubik/orchestrator/goal_session.rb +53 -39
  33. data/lib/rubik/orchestrator/loop.rb +28 -47
  34. data/lib/rubik/orchestrator/maestro_gate.rb +5 -7
  35. data/lib/rubik/orchestrator/provider_recovery.rb +4 -2
  36. data/lib/rubik/orchestrator/provider_resolver.rb +4 -2
  37. data/lib/rubik/orchestrator/resume_window.rb +96 -0
  38. data/lib/rubik/orchestrator/shell_deps.rb +16 -0
  39. data/lib/rubik/orchestrator/stream_manager.rb +2 -1
  40. data/lib/rubik/orchestrator/subagent/deferred_spec.rb +4 -1
  41. data/lib/rubik/orchestrator/subagent/instance.rb +7 -12
  42. data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
  43. data/lib/rubik/orchestrator/subagent/questioner.rb +3 -1
  44. data/lib/rubik/orchestrator/subagent/reaper.rb +3 -5
  45. data/lib/rubik/orchestrator/subagent/resilience.rb +4 -2
  46. data/lib/rubik/orchestrator/subagent/result_archive.rb +0 -4
  47. data/lib/rubik/orchestrator/subagent/run_cycle.rb +2 -7
  48. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +11 -2
  49. data/lib/rubik/orchestrator/subagent/step_runner.rb +10 -2
  50. data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
  51. data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
  52. data/lib/rubik/platform/io_drain.rb +2 -1
  53. data/lib/rubik/platform/process.rb +144 -54
  54. data/lib/rubik/platform.rb +2 -1
  55. data/lib/rubik/plugin/manager.rb +2 -1
  56. data/lib/rubik/repl/commands/agent_context.rb +8 -7
  57. data/lib/rubik/repl/commands/agent_execution.rb +13 -32
  58. data/lib/rubik/repl/commands/agent_models.rb +4 -3
  59. data/lib/rubik/repl/commands/agent_providers.rb +43 -2
  60. data/lib/rubik/repl/commands/base.rb +47 -2
  61. data/lib/rubik/repl/commands/buffer.rb +5 -4
  62. data/lib/rubik/repl/commands/lsp.rb +2 -1
  63. data/lib/rubik/repl/commands/pruner.rb +2 -1
  64. data/lib/rubik/repl/commands/secrets.rb +151 -0
  65. data/lib/rubik/repl/commands/workspace.rb +60 -150
  66. data/lib/rubik/repl/commands/workspace_approval.rb +209 -0
  67. data/lib/rubik/repl/config_wiring.rb +3 -3
  68. data/lib/rubik/repl/hooks.rb +2 -1
  69. data/lib/rubik/repl/input_execution.rb +158 -76
  70. data/lib/rubik/repl/input_loop.rb +2 -1
  71. data/lib/rubik/repl/lifecycle.rb +59 -209
  72. data/lib/rubik/repl/notice_router.rb +319 -0
  73. data/lib/rubik/repl/paste_support.rb +3 -1
  74. data/lib/rubik/repl/presentation.rb +5 -3
  75. data/lib/rubik/repl/pruner/gate.rb +3 -1
  76. data/lib/rubik/repl/pruner/harness.rb +2 -1
  77. data/lib/rubik/repl/shell.rb +4 -3
  78. data/lib/rubik/repl/turn_recorder.rb +6 -5
  79. data/lib/rubik/runtime/discovery.rb +3 -2
  80. data/lib/rubik/runtime/loop_service.rb +4 -3
  81. data/lib/rubik/runtime/manifest_store.rb +9 -1
  82. data/lib/rubik/runtime/overlay_guard.rb +127 -0
  83. data/lib/rubik/runtime/overlay_storage.rb +92 -146
  84. data/lib/rubik/runtime/task_manager.rb +64 -25
  85. data/lib/rubik/sandbox/driver/docker.rb +5 -1
  86. data/lib/rubik/sandbox/runner.rb +16 -15
  87. data/lib/rubik/security/command_gate.rb +117 -93
  88. data/lib/rubik/security/guard.rb +6 -2
  89. data/lib/rubik/security/secret_store.rb +463 -0
  90. data/lib/rubik/security/synthesis_gate.rb +8 -11
  91. data/lib/rubik/session/manager.rb +7 -1
  92. data/lib/rubik/skills/manager.rb +2 -3
  93. data/lib/rubik/storage/search.rb +49 -0
  94. data/lib/rubik/storage/store.rb +13 -20
  95. data/lib/rubik/storage/vakanuvis/harness.rb +2 -3
  96. data/lib/rubik/tools/base.rb +22 -0
  97. data/lib/rubik/tools/builtins/files.rb +3 -15
  98. data/lib/rubik/tools/builtins/grep.rb +1 -6
  99. data/lib/rubik/tools/builtins/lifecycle.rb +6 -5
  100. data/lib/rubik/tools/lifecycle_rollbacks.rb +14 -1
  101. data/lib/rubik/tools/truncator.rb +48 -36
  102. data/lib/rubik/ui/banner.rb +4 -3
  103. data/lib/rubik/ui/spinner.rb +3 -1
  104. data/lib/rubik/ui/statusline.rb +6 -5
  105. data/lib/rubik/version.rb +1 -1
  106. data/lib/rubik.rb +1 -2
  107. metadata +13 -1
@@ -0,0 +1,319 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../events"
4
+ require_relative "../log"
5
+ require_relative "../orchestrator/subagent/notices"
6
+ require_relative "../prompt/conversation_rows"
7
+ require_relative "pending_notice_queue"
8
+
9
+ module Rubik
10
+ module REPL
11
+ # Issue #469: the notice-routing half of Lifecycle, extracted as a
12
+ # collaborator owning the queue/mutex/token concurrency state
13
+ # (@mcp_notice_tokens, @subagent_event_tokens, @subagent_notices_mutex,
14
+ # @subagent_notices, @pending_notice_queue). Lifecycle keeps the boot
15
+ # phases and delegates; the public Shell surface is unchanged (thin
16
+ # delegating methods).
17
+ #
18
+ # The router holds a reference to its host (Shell or a bare test double)
19
+ # and reads turn/UI state off it via instance_variable_get: @running,
20
+ # @replaying, @autonomous_turn, @active_loop, @output, @terminal_guard,
21
+ # @conversation_history, @config, @event_bus and @runtime_manager are the
22
+ # host's live state and must never be snapshotted.
23
+ #
24
+ # Threading semantics are carried over verbatim: bus dispatch runs on the
25
+ # kworker thread, so handlers touch only the Queue push, the standby
26
+ # Mutex and the guard monitor — never a shell lock. Subscriptions stay
27
+ # inverse-by-construction (unsubscribe registered via ctx.on_dispose in
28
+ # the same breath, AGENTS.md §1A).
29
+ class NoticeRouter
30
+ # Plan 109 Faz B: notice kinds worth interrupting the idle prompt
31
+ # with an autonomous agent-0 turn. Excludes :context_compacted
32
+ # (self-healed, guidance says no action needed) and
33
+ # :auto_apply_failed (informational; the subagent's own next step
34
+ # reports it).
35
+ WAKE_KINDS = [:completed, :budget_exhausted, :error_paused, :message, :question, :task].freeze
36
+
37
+ # Single home of the "safe notice print" fallback pattern that used to
38
+ # be reimplemented per call site (lifecycle boot notices, MCP boot
39
+ # notices, subagent routing, flush; turn_recorder keeps its own until
40
+ # it needs the newline conventions changed): print through the guard
41
+ # when one exists, else fall back to the host output stream.
42
+ def self.print_safe_notice_line(terminal_guard, output, line)
43
+ if terminal_guard
44
+ terminal_guard.print_safe_notice(line)
45
+ else
46
+ output&.puts line
47
+ end
48
+ end
49
+
50
+ # Test seam and lazy storage: the user-channel standby buffer and its
51
+ # mutex (the router owns them; tests pin flush/routing semantics
52
+ # against the router). Lazily created so routing buffers safely even
53
+ # before wire_subagent_events! runs (bare test-double harness mold).
54
+ def subagent_notices
55
+ @subagent_notices ||= []
56
+ end
57
+
58
+ def subagent_notices_mutex
59
+ @subagent_notices_mutex ||= Mutex.new
60
+ end
61
+
62
+ def initialize(shell)
63
+ @shell = shell
64
+ end
65
+
66
+ # Async MCP boot progress notices (mcp-async-boot D8): subscribe BEFORE
67
+ # the boot triggers so no event is missed, with the unsubscribe inverse
68
+ # registered in the same breath (wire_subagent_events! pattern). Async
69
+ # mode only — a synchronous boot finishes before the first prompt, so
70
+ # its failures already surfaced on stderr.
71
+ def wire_mcp_boot_notices!(async:)
72
+ return unless async && event_bus
73
+ return if @mcp_notice_tokens # idempotent re-wire
74
+
75
+ ctx = runtime_manager&.context
76
+ return unless ctx.respond_to?(:on_dispose)
77
+
78
+ @mcp_notice_tokens = [
79
+ [:mcp_server_loaded, event_bus.subscribe(:mcp_server_loaded) { |payload| print_mcp_boot_notice(:loaded, payload) }],
80
+ [:mcp_server_failed, event_bus.subscribe(:mcp_server_failed) { |payload| print_mcp_boot_notice(:failed, payload) }]
81
+ ]
82
+ ctx.on_dispose do
83
+ @mcp_notice_tokens&.each { |(event, token)| event_bus.unsubscribe(event, token) }
84
+ @mcp_notice_tokens = nil
85
+ end
86
+ end
87
+
88
+ # Same kworker-thread contract as handle_subagent_event: no shell locks,
89
+ # drop silently when the UI is not up yet (an instant boot failure is
90
+ # still on stderr and in dmesg). Pure display line — never enters the
91
+ # conversation history and never wakes an idle turn.
92
+ def print_mcp_boot_notice(state, payload)
93
+ return unless shell_state(:running) && shell_state(:output)
94
+ return unless payload.is_a?(Hash)
95
+
96
+ name = payload[:server]
97
+ line = if state == :loaded
98
+ "mcp: server '#{name}' ready (#{payload[:tools] || 0} tools)"
99
+ else
100
+ "mcp: server '#{name}' failed (#{payload[:error]})"
101
+ end
102
+ shell_state(:terminal_guard)&.print_safe_notice(line)
103
+ end
104
+
105
+ def wire_subagent_events!
106
+ return unless event_bus
107
+ return if @subagent_event_tokens # idempotent re-wire (RenderService precedent)
108
+
109
+ # Inverse-by-construction: subscribe only where the unsubscribe
110
+ # inverse can be registered in the same breath (AGENTS.md §1A).
111
+ ctx = runtime_manager&.context
112
+ return unless ctx.respond_to?(:on_dispose)
113
+
114
+ @subagent_notices_mutex = Mutex.new
115
+ @subagent_notices = []
116
+ # Plan 109: the idle-turn wake flag, eagerly initialized BEFORE any
117
+ # subscription exists so handlers never race its construction.
118
+ @pending_notice_queue = PendingNoticeQueue.new
119
+ tokens = Rubik::Orchestrator::Subagent::Notices::EVENTS.keys.map do |event|
120
+ [event, event_bus.subscribe(event) { |payload| handle_subagent_event(event, payload) }]
121
+ end
122
+ tokens << [Rubik::Events::UNIT_STATE_CHANGED, event_bus.subscribe(Rubik::Events::UNIT_STATE_CHANGED) { |payload| handle_unit_event(payload) }]
123
+ tokens << [Rubik::Events::SUBAGENT_MESSAGE_TO_PARENT, event_bus.subscribe(Rubik::Events::SUBAGENT_MESSAGE_TO_PARENT) { |payload| handle_parent_message(payload) }]
124
+ @subagent_event_tokens = tokens
125
+ ctx.on_dispose do
126
+ @subagent_event_tokens&.each { |(event, token)| event_bus.unsubscribe(event, token) }
127
+ @subagent_event_tokens = nil
128
+ end
129
+ end
130
+
131
+ # ONE routing seam for subagent notices (Candidate 02, unified for
132
+ # Plan 109): bus event -> normalized notice -> channel-split
133
+ # delivery. Called on the kworker thread (bus dispatch is
134
+ # synchronous): Queue pushes, the standby Mutex, and the guard
135
+ # monitor only — no shell locks. Model channel (structured hash)
136
+ # enters the active loop queue and is rendered to XML at drain
137
+ # time; user channel (terminal line) is buffered to stdout while a
138
+ # loop is active and flushed at turn end. Between turns the notice
139
+ # is injected into the conversation history, printed, and — when
140
+ # wake-worthy — queued to owe agent-0 an autonomous notice turn.
141
+ def handle_subagent_event(event_name, payload)
142
+ return unless shell_state(:running) && shell_state(:output) && !shell_state(:replaying)
143
+
144
+ notice = Rubik::Orchestrator::Subagent::Notices.normalize(event_name, payload)
145
+ route_subagent_notice(notice) if notice
146
+ end
147
+
148
+ def handle_unit_event(payload)
149
+ return unless shell_state(:running) && shell_state(:output) && !shell_state(:replaying)
150
+ return unless payload.is_a?(Hash)
151
+
152
+ type = payload[:type]&.to_sym
153
+ return unless [:process, :task].include?(type)
154
+
155
+ to_state = payload[:to_state]&.to_sym
156
+ return unless [:completed, :failed].include?(to_state)
157
+
158
+ route_subagent_notice({ kind: :task, id: payload[:unit_id], role: "Background Task", state: to_state.to_s, reason: payload[:reason] })
159
+ end
160
+
161
+ def handle_parent_message(payload)
162
+ return unless shell_state(:running) && shell_state(:output) && !shell_state(:replaying)
163
+ return unless payload.is_a?(Hash)
164
+
165
+ route_subagent_notice({ kind: :message, id: payload[:sender_id] || "subagent",
166
+ role: "Subagent", state: "message", reason: payload[:message].to_s })
167
+ end
168
+
169
+ def route_subagent_notice(notice)
170
+ line = Rubik::Orchestrator::Subagent::Notices.user_line(notice)
171
+ if shell_state(:active_loop)
172
+ active_loop = shell_state(:active_loop)
173
+ active_loop.enqueue_subagent_notice(notice) if active_loop.respond_to?(:enqueue_subagent_notice)
174
+ subagent_notices_mutex.synchronize { subagent_notices << line }
175
+ else
176
+ inject_subagent_notice_into_conversation_history!(notice)
177
+ output = shell_state(:output)
178
+ if shell_state(:terminal_guard)
179
+ shell_state(:terminal_guard).print_safe_notice(line)
180
+ else
181
+ output.puts "\n#{line}"
182
+ end
183
+ # Wakeloop fix 2026-10-09: an event landing inside an AUTONOMOUS
184
+ # turn's idle-path windows (before @active_loop is set, or in the
185
+ # ensure tail after it is cleared) must not arm a follow-up wake —
186
+ # that is the probabilistic residue of the chained-auto-turn bug.
187
+ # History injection and the printed line above still happen (no
188
+ # loss); only the synthetic Enter is withheld. A fresh event at a
189
+ # genuinely idle prompt (@autonomous_turn false) wakes as designed.
190
+ request_reactive_wakeup!(notice) unless shell_state(:autonomous_turn)
191
+ end
192
+ end
193
+
194
+ # Plan 109 Faz B: the reactive wake composition — vocabulary policy
195
+ # (WAKE_KINDS), kill-switch (subagents.reactive_wakeup config),
196
+ # state (PendingNoticeQueue), mechanism (TerminalGuard#safe_wakeup!).
197
+ # Every wake-worthy enqueue attempts the kick (no empty->non-empty
198
+ # coalescing): a kick refused earlier (user typing / paste
199
+ # collection) must retry on the next event, or the wake would wait
200
+ # for a manual Enter. TerminalGuard re-verifies emptiness under its
201
+ # monitor, so a typing user is never disturbed, and a surplus
202
+ # injected Enter degrades to the :empty noop. Runs on the kworker
203
+ # thread: queue push and the guard monitor only.
204
+ def request_reactive_wakeup!(notice)
205
+ return unless reactive_wakeup_enabled?
206
+ return unless notice.is_a?(Hash) && WAKE_KINDS.include?(notice[:kind])
207
+
208
+ pending_notice_queue.enqueue(notice)
209
+ shell_state(:terminal_guard)&.safe_wakeup!
210
+ end
211
+
212
+ def reactive_wakeup_enabled?
213
+ Rubik::Storage::Layout.config_get(shell_state(:config), "subagents.reactive_wakeup", true) != false
214
+ end
215
+
216
+ # Eager init happens in wire_subagent_events! (before any
217
+ # subscription exists); the lazy fallback keeps bare Lifecycle test
218
+ # doubles working (SubagentNoticeInbox mold).
219
+ def pending_notice_queue
220
+ @pending_notice_queue ||= PendingNoticeQueue.new
221
+ end
222
+
223
+ def pending_wake_notices?
224
+ pending_notice_queue.any?
225
+ end
226
+
227
+ def drain_pending_wake_notices!
228
+ pending_notice_queue.drain_all
229
+ end
230
+
231
+ # Staleness rule: any real turn's context already includes the
232
+ # idle-injected notices in the conversation history — a surviving
233
+ # pending wake would turn the next stray Enter into a redundant
234
+ # notice turn.
235
+ def clear_pending_wake_notices!
236
+ pending_notice_queue.clear!
237
+ end
238
+
239
+ def inject_subagent_notice_into_conversation_history!(notice)
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)
245
+ end
246
+ Rubik::Prompt::ConversationRows.append_notice!(history, xml_payload)
247
+ end
248
+
249
+ def flush_subagent_notices!
250
+ output = shell_state(:output)
251
+ return unless output
252
+
253
+ notices = subagent_notices_mutex.synchronize do
254
+ list = subagent_notices.dup
255
+ subagent_notices.clear
256
+ list
257
+ end
258
+ return if notices.empty?
259
+
260
+ if shell_state(:terminal_guard)
261
+ notices.each { |m| shell_state(:terminal_guard).print_safe_notice(m) }
262
+ else
263
+ output.puts ""
264
+ notices.each { |m| output.puts m }
265
+ end
266
+ end
267
+
268
+ # Session review B3 (turn-loss fix): Loop's drain runs at the TOP of each
269
+ # step, so notices landing during the final step stranded in the loop
270
+ # inbox at turn end — the user channel flushed a line, but the model
271
+ # channel never entered history and no wake was owed (Plan 109's
272
+ # documented "late-notice asymmetry" accepted the loss; a live session
273
+ # showed it costs a whole turn). Called from execute_free_text's ensure
274
+ # AFTER the active loop is cleared: the notices are injected into
275
+ # the conversation history (visible to the next turn) and wake-worthy
276
+ # kinds arm the reactive wake, exactly like the idle-path branch of
277
+ # route_subagent_notice. Runs on the turn thread. Per-notice rescue is
278
+ # the ensure block's own contract ("cleanup must never mask the
279
+ # in-flight exception") — and a raising notice must not strand its
280
+ # queue-mates that drain_all already popped.
281
+ #
282
+ # arm_wake: false keeps the model-channel delivery but does NOT fire a
283
+ # synthetic Enter (wakeloop fix 2026-10-09): an INTERRUPTED turn and an
284
+ # AUTONOMOUS notice turn settle instead of re-arming — otherwise every
285
+ # stranded notice chains another auto-turn (the prompt never returns)
286
+ # and the cycle survives Ctrl+C.
287
+ def deliver_stranded_loop_notices!(loop_instance, arm_wake: true)
288
+ return unless loop_instance.respond_to?(:subagent_notice_inbox)
289
+
290
+ loop_instance.subagent_notice_inbox.drain_all.each do |notice|
291
+ inject_subagent_notice_into_conversation_history!(notice)
292
+ request_reactive_wakeup!(notice) if arm_wake
293
+ rescue StandardError => e
294
+ # Load-bearing visibility (wakeloop fix 2026-10-09): this delivery
295
+ # is the fix's "no loss" guarantee, so a dropped notice may not
296
+ # vanish behind the ENV-gated debug_warn. Unconditional, non-raising.
297
+ Rubik::Log.warn(:repl, "stranded notice delivery failed (#{notice[:kind].inspect}): " \
298
+ "#{e.class}: #{e.message}")
299
+ end
300
+ end
301
+
302
+ private
303
+
304
+ # Live host state — never snapshotted; instance_variable_get keeps
305
+ # bare Lifecycle test doubles (plain ivars, no readers) working.
306
+ def shell_state(name)
307
+ @shell.instance_variable_get(:"@#{name}")
308
+ end
309
+
310
+ def event_bus
311
+ shell_state(:event_bus)
312
+ end
313
+
314
+ def runtime_manager
315
+ shell_state(:runtime_manager)
316
+ end
317
+ end
318
+ end
319
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../storage/layout"
4
+
3
5
  module Rubik
4
6
  module REPL
5
7
  # Multi-line paste desteği (Plan 91): terminaller yapıştırılan bloğu
@@ -20,7 +22,7 @@ module Rubik
20
22
  # Bir yapıştırma bloğunun satırlarının "aynı burst" sayılması için
21
23
  # iki readline dönüşü arasındaki maksimum süre (ms).
22
24
  def paste_join_window_ms
23
- @config ? @config.fetch("ui.paste_join_window_ms", 120).to_f : 120.0
25
+ @config ? Rubik::Storage::Layout.config_get(@config, "ui.paste_join_window_ms", 120).to_f : 120.0
24
26
  end
25
27
 
26
28
  # Monotonic saniye sayacı; testler singleton ile ezebilir.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../storage/layout"
4
+
3
5
  module Rubik
4
6
  module REPL
5
7
  # Presentation helpers mixed into Shell (the Confirmations pattern):
@@ -24,7 +26,7 @@ module Rubik
24
26
  end
25
27
  @ui_renderer = Rubik::UI::RenderService.register(@runtime_manager, shell: self, output: real_output)
26
28
  @ui_theme = @ui_renderer&.theme
27
- @terminal_guard.quiet = (@config.respond_to?(:fetch) ? @config.fetch("ui.quiet_notices", false) : false) == true if @terminal_guard
29
+ @terminal_guard.quiet = Rubik::Storage::Layout.config_get(@config, "ui.quiet_notices", false) == true if @terminal_guard
28
30
  end
29
31
 
30
32
  # Single accessor for the active display theme; call sites never
@@ -85,7 +87,7 @@ module Rubik
85
87
  # caller's job after the line is accepted.
86
88
  def prepare_prompt_line(heredoc_active)
87
89
  print_statusline unless heredoc_active
88
- boxed = @config.fetch("ui.input_box", false) == true && !heredoc_active
90
+ boxed = Rubik::Storage::Layout.config_get(@config, "ui.input_box", false) == true && !heredoc_active
89
91
  @output.puts box_top_border if boxed
90
92
  base = heredoc_active ? "... > " : prompt
91
93
  [box_prompt_lines(base, boxed: boxed), boxed]
@@ -95,7 +97,7 @@ module Rubik
95
97
  project_name = File.basename(Dir.pwd)
96
98
  git_branch = detect_git_branch
97
99
  branch_part = git_branch ? " [#{git_branch}]" : ""
98
- show_indicator = @config.fetch("buffer.prompt_indicator", true)
100
+ show_indicator = Rubik::Storage::Layout.config_get(@config, "buffer.prompt_indicator", true)
99
101
  dirty_count = @buffer_manager&.dirty? ? @buffer_manager.dirty_files.size : 0
100
102
  dirty_part = show_indicator && dirty_count.positive? ? " [DIRTY: #{dirty_count} ✎]" : ""
101
103
  "rubik (#{project_name})#{branch_part}#{dirty_part} > "
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../../storage/layout"
4
+
3
5
  module Rubik
4
6
  module REPL
5
7
  module Pruner
@@ -271,7 +273,7 @@ module Rubik
271
273
  end
272
274
 
273
275
  def fetch_cfg(key, default)
274
- @config.respond_to?(:fetch) ? @config.fetch(key, default) : default
276
+ Rubik::Storage::Layout.config_get(@config, key, default)
275
277
  end
276
278
  end
277
279
  end
@@ -3,6 +3,7 @@
3
3
  require "monitor"
4
4
  require_relative "../../concurrency"
5
5
  require_relative "../../events"
6
+ require_relative "../../storage/layout"
6
7
 
7
8
  module Rubik
8
9
  module REPL
@@ -213,7 +214,7 @@ module Rubik
213
214
  end
214
215
 
215
216
  def fetch_cfg(key, default)
216
- @config.respond_to?(:fetch) ? @config.fetch(key, default) : default
217
+ Rubik::Storage::Layout.config_get(@config, key, default)
217
218
  end
218
219
  end
219
220
  end
@@ -10,6 +10,7 @@ require_relative "hooks"
10
10
  require_relative "commands"
11
11
  require_relative "config_wiring"
12
12
  require_relative "tee_io"
13
+ require_relative "../storage/layout"
13
14
  require_relative "interrupt_handler"
14
15
  require_relative "confirmations"
15
16
  require_relative "presentation"
@@ -59,7 +60,7 @@ module Rubik
59
60
  @terminal_guard = terminal_guard || TerminalGuard.new(
60
61
  output: @output,
61
62
  reline: @reline,
62
- quiet: (@config.respond_to?(:fetch) ? @config.fetch("ui.quiet_notices", false) : false) == true
63
+ quiet: Rubik::Storage::Layout.config_get(@config, "ui.quiet_notices", false) == true
63
64
  )
64
65
  @hooks = Hooks.new
65
66
  @commands = {}
@@ -162,7 +163,7 @@ module Rubik
162
163
  end
163
164
 
164
165
  def stop
165
- if @buffer_manager&.dirty? && (@config.nil? || @config.fetch("buffer.exit_guard", true) != false)
166
+ if @buffer_manager&.dirty? && (@config.nil? || Rubik::Storage::Layout.config_get(@config, "buffer.exit_guard", true) != false)
166
167
  count = @buffer_manager.dirty_files.size
167
168
  @output.puts "⚠️ Warning: You have #{count} unapplied dirty buffer change(s)! Run '!apply' to persist or '!diff' to review."
168
169
  end
@@ -211,7 +212,7 @@ module Rubik
211
212
 
212
213
  if @buffer_manager.dirty?
213
214
  @dirty_turns += 1
214
- interval = @config.fetch("buffer.reminder_interval", 3).to_i
215
+ interval = Rubik::Storage::Layout.config_get(@config, "buffer.reminder_interval", 3).to_i
215
216
  if interval.positive? && @dirty_turns >= interval
216
217
  count = @buffer_manager.dirty_files.size
217
218
  @output.puts "💡 [Rubik::Buffer] #{count} unapplied file modification(s) in buffer. Run '!diff' to review or '!apply' to persist to disk."
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../events"
4
+ require_relative "../storage/layout"
4
5
  require_relative "../prompt/context_compactor"
5
6
  require_relative "../coeffects"
6
7
 
@@ -26,7 +27,7 @@ module Rubik
26
27
  # sync_default_provider; explicit task types (!plan/!goal) never
27
28
  # touch it. Disable with `!config set router.sticky false`.
28
29
  def resolve_turn_route(text)
29
- sticky = @config.fetch("router.sticky", true) != false
30
+ sticky = Rubik::Storage::Layout.config_get(@config, "router.sticky", true) != false
30
31
  return @conversation_route_stamp if sticky && @conversation_route_stamp && !@conversation_history.empty?
31
32
 
32
33
  routed = @router.route(task_type: :auto, prompt: text)
@@ -53,7 +54,7 @@ module Rubik
53
54
  end
54
55
 
55
56
  def record_failed_turn!(user_text, kind, reason, orchestrator)
56
- return if @config.fetch("context.log_failed_turns", true) == false
57
+ return if Rubik::Storage::Layout.config_get(@config, "context.log_failed_turns", true) == false
57
58
 
58
59
  label = case kind
59
60
  when "cancelled" then "[Turn cancelled by user (^C)]"
@@ -67,8 +68,8 @@ module Rubik
67
68
  end
68
69
 
69
70
  # Plan 85 D-3: kronolojik tool listesi (D-2'deki chronological_summary).
70
- chronicle_enabled = @config.fetch("context.tool_chronicle_in_history", true)
71
- max_entries = @config.fetch("context.tool_chronicle_max_entries", 15).to_i
71
+ chronicle_enabled = Rubik::Storage::Layout.config_get(@config, "context.tool_chronicle_in_history", true)
72
+ max_entries = Rubik::Storage::Layout.config_get(@config, "context.tool_chronicle_max_entries", 15).to_i
72
73
  tool_chronicle = if chronicle_enabled &&
73
74
  orchestrator.respond_to?(:activity) &&
74
75
  orchestrator.activity.respond_to?(:chronological_summary)
@@ -151,7 +152,7 @@ module Rubik
151
152
  # döndürür).
152
153
  def merge_turn_tool_history!(turn_history, max_entries: 20)
153
154
  return false if turn_history.nil? || turn_history.empty?
154
- return false unless @config.fetch("context.merge_turn_tool_history", true)
155
+ return false unless Rubik::Storage::Layout.config_get(@config, "context.merge_turn_tool_history", true)
155
156
 
156
157
  # Yalnızca tool sonucu taşıyan mesajları filtrele; en SON max_entries
157
158
  # adımı al — bir sonraki turn'ün ihtiyacı olan, turn'in güncel arazi
@@ -3,6 +3,7 @@
3
3
  require "shellwords"
4
4
  require_relative "../platform"
5
5
  require_relative "../lsp/server_command"
6
+ require_relative "../storage/layout"
6
7
 
7
8
  module Rubik
8
9
  module Runtime
@@ -390,8 +391,8 @@ module Rubik
390
391
  config.dig("project", "test_command")
391
392
  elsif config.respond_to?(:fetch)
392
393
  begin
393
- config.fetch("adapter.#{lang_key}.test_command", nil) ||
394
- config.fetch("project.test_command", nil)
394
+ Rubik::Storage::Layout.config_get(config, "adapter.#{lang_key}.test_command", nil) ||
395
+ Rubik::Storage::Layout.config_get(config, "project.test_command", nil)
395
396
  rescue KeyError, NoMethodError, TypeError
396
397
  nil
397
398
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "fiber"
4
4
  require_relative "../coeffects"
5
+ require_relative "../storage/layout"
5
6
  require_relative "service_registration"
6
7
 
7
8
  module Rubik
@@ -46,13 +47,13 @@ module Rubik
46
47
  app_config = config[:config] || shell&.config ||
47
48
  (ctx.respond_to?(:get) ? Rubik::Coeffects.get(ctx, Rubik::Coeffects::CONFIG) : nil)
48
49
 
49
- max_steps = config[:max_steps] || (app_config.respond_to?(:fetch) ? app_config.fetch("agent.max_steps", 40).to_i : 40)
50
- warn_ratio = config[:warn_at_ratio] || (app_config.respond_to?(:fetch) ? app_config.fetch("agent.warn_at_ratio", 0.75).to_f : 0.75)
50
+ max_steps = config[:max_steps] || Rubik::Storage::Layout.config_get(app_config, "agent.max_steps", 40).to_i
51
+ warn_ratio = config[:warn_at_ratio] || Rubik::Storage::Layout.config_get(app_config, "agent.warn_at_ratio", 0.75).to_f
51
52
  model = config[:model]
52
53
  on_step = config[:on_step]
53
54
  context_limit = config[:context_limit]
54
55
  max_output_tokens = config[:max_output_tokens] ||
55
- (app_config.respond_to?(:fetch) && app_config.fetch("llm.default_max_output_tokens", 4_096)&.to_i) || 4_096
56
+ Rubik::Storage::Layout.config_get(app_config, "llm.default_max_output_tokens", 4_096).to_i
56
57
 
57
58
  require_relative "../orchestrator"
58
59
 
@@ -4,6 +4,7 @@ require "json"
4
4
  require "time"
5
5
  # save_manifest atomik yazımı Platform.atomic_write kullanır; dosyanın tek başına
6
6
  # require edilmesi durumunda da çözümlenebilsin diye açık yüklenir.
7
+ require_relative "../errors"
7
8
  require_relative "../platform"
8
9
  require_relative "../plugin/package_inventory"
9
10
 
@@ -24,6 +25,13 @@ module Rubik
24
25
  class ManifestStore
25
26
  MANIFEST_NAME = ".manifest.json"
26
27
 
28
+ # Fail-closed corrupt-manifest contract (issue #407/#448): record and
29
+ # delete refuse to heal a corrupt manifest (healing would evict the
30
+ # other consented entries) and raise this instead. User-recoverable —
31
+ # the message carries the remediation (delete the manifest and
32
+ # re-record overlays).
33
+ class CorruptManifestError < Rubik::Error; end
34
+
27
35
  def initialize(validate_path: nil)
28
36
  @validate_path = validate_path
29
37
  end
@@ -109,7 +117,7 @@ module Rubik
109
117
  def refuse_corrupt_manifest!(dir, verb, filename)
110
118
  return unless manifest_state(dir) == :corrupt
111
119
 
112
- raise "cannot #{verb} '#{filename}': .manifest.json in #{dir} is corrupt; delete it and re-record overlays"
120
+ raise CorruptManifestError, "cannot #{verb} '#{filename}': .manifest.json in #{dir} is corrupt; delete it and re-record overlays"
113
121
  end
114
122
  end
115
123
  end