rubik 0.8.0 → 0.9.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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +2 -2
  3. data/CHANGELOG.md +164 -1
  4. data/bin/rubik +15 -10
  5. data/lib/rubik/cli/workspace_trust.rb +1 -0
  6. data/lib/rubik/concurrency/worker.rb +143 -0
  7. data/lib/rubik/concurrency.rb +1 -0
  8. data/lib/rubik/config/deep_ops.rb +17 -0
  9. data/lib/rubik/config/defaults.rb +0 -1
  10. data/lib/rubik/config/schema.rb +0 -1
  11. data/lib/rubik/config.rb +7 -3
  12. data/lib/rubik/context/repo_context_reader.rb +27 -8
  13. data/lib/rubik/events.rb +18 -0
  14. data/lib/rubik/kernel/dispatcher.rb +19 -23
  15. data/lib/rubik/kernel/init.rb +22 -18
  16. data/lib/rubik/kernel/unit.rb +4 -3
  17. data/lib/rubik/orchestrator/auto_apply.rb +2 -0
  18. data/lib/rubik/orchestrator/budget_manager.rb +18 -2
  19. data/lib/rubik/orchestrator/goal_ledger/deep_ops.rb +41 -0
  20. data/lib/rubik/orchestrator/goal_ledger/drift.rb +2 -1
  21. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +59 -59
  22. data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +29 -9
  23. data/lib/rubik/orchestrator/goal_ledger/patch.rb +10 -17
  24. data/lib/rubik/orchestrator/goal_ledger/suspend_lifecycle.rb +9 -41
  25. data/lib/rubik/orchestrator/goal_ledger/validator.rb +6 -20
  26. data/lib/rubik/orchestrator/goal_ledger/verifier.rb +3 -14
  27. data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +21 -14
  28. data/lib/rubik/orchestrator/goal_state.rb +15 -15
  29. data/lib/rubik/orchestrator/loop.rb +62 -63
  30. data/lib/rubik/orchestrator/lsp_feedback.rb +7 -1
  31. data/lib/rubik/orchestrator/subagent/admission_policy.rb +161 -0
  32. data/lib/rubik/orchestrator/subagent/builtin_types.rb +3 -2
  33. data/lib/rubik/orchestrator/subagent/deferred_spec.rb +51 -2
  34. data/lib/rubik/orchestrator/subagent/dependency.rb +20 -20
  35. data/lib/rubik/orchestrator/subagent/execution_reads.rb +1 -1
  36. data/lib/rubik/orchestrator/subagent/journal.rb +3 -9
  37. data/lib/rubik/orchestrator/subagent/lifecycle.rb +10 -1
  38. data/lib/rubik/orchestrator/subagent/notices.rb +5 -4
  39. data/lib/rubik/orchestrator/subagent/paging.rb +49 -0
  40. data/lib/rubik/orchestrator/subagent/profile_contract.rb +4 -10
  41. data/lib/rubik/orchestrator/subagent/reaper.rb +1 -3
  42. data/lib/rubik/orchestrator/subagent/redeploy_transaction.rb +99 -0
  43. data/lib/rubik/orchestrator/subagent/result_archive.rb +12 -22
  44. data/lib/rubik/orchestrator/subagent/reuse.rb +37 -31
  45. data/lib/rubik/orchestrator/subagent/run_cycle.rb +22 -1
  46. data/lib/rubik/orchestrator/subagent/scoped_registry.rb +34 -2
  47. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +1 -1
  48. data/lib/rubik/orchestrator/subagent/supervisor.rb +6 -2
  49. data/lib/rubik/orchestrator/subagent/task_ownership.rb +2 -2
  50. data/lib/rubik/orchestrator/subagent/transcript_reader.rb +14 -13
  51. data/lib/rubik/orchestrator/subagent/type_registry.rb +19 -1
  52. data/lib/rubik/orchestrator/turn_executor/subagent_channel.rb +6 -1
  53. data/lib/rubik/orchestrator/turn_executor/user_channel.rb +6 -1
  54. data/lib/rubik/orchestrator/turn_executor.rb +2 -1
  55. data/lib/rubik/platform/path.rb +0 -1
  56. data/lib/rubik/prompt/context_builder.rb +24 -18
  57. data/lib/rubik/prompt/context_compactor.rb +31 -8
  58. data/lib/rubik/prompt/conversation_rows.rb +33 -0
  59. data/lib/rubik/prompt/doctrine.rb +4 -2
  60. data/lib/rubik/prompt/emergency_compactor.rb +5 -4
  61. data/lib/rubik/repl/commands/agent_execution.rb +13 -2
  62. data/lib/rubik/repl/commands/buffer.rb +4 -0
  63. data/lib/rubik/repl/commands/mcp.rb +5 -0
  64. data/lib/rubik/repl/commands/subagents.rb +7 -6
  65. data/lib/rubik/repl/commands/workspace.rb +22 -2
  66. data/lib/rubik/repl/config_wiring.rb +24 -7
  67. data/lib/rubik/repl/input_execution.rb +1 -1
  68. data/lib/rubik/repl/lifecycle.rb +3 -2
  69. data/lib/rubik/repl/pruner/harness.rb +52 -67
  70. data/lib/rubik/repl/pruner/rules.rb +3 -1
  71. data/lib/rubik/repl/pruner/service.rb +4 -9
  72. data/lib/rubik/repl/service_catalog.rb +1 -1
  73. data/lib/rubik/repl/synthesized_command_context.rb +3 -0
  74. data/lib/rubik/repl/turn_recorder.rb +5 -4
  75. data/lib/rubik/repl.rb +1 -0
  76. data/lib/rubik/runtime/context.rb +11 -1
  77. data/lib/rubik/runtime/discovery.rb +55 -0
  78. data/lib/rubik/runtime/fiber.rb +17 -5
  79. data/lib/rubik/runtime/manager.rb +19 -12
  80. data/lib/rubik/runtime/overlay_storage.rb +54 -23
  81. data/lib/rubik/runtime/repair_probe.rb +20 -2
  82. data/lib/rubik/runtime/sealed_coeffects.rb +58 -0
  83. data/lib/rubik/runtime/synthesized_command_context.rb +80 -0
  84. data/lib/rubik/runtime/synthesized_tool_context.rb +123 -0
  85. data/lib/rubik/runtime.rb +2 -0
  86. data/lib/rubik/security/classifier/classifier.rb +16 -8
  87. data/lib/rubik/security/classifier/commands/biome.yaml +49 -0
  88. data/lib/rubik/security/classifier/commands/bun.yaml +91 -0
  89. data/lib/rubik/security/classifier/commands/bundle.yaml +107 -0
  90. data/lib/rubik/security/classifier/commands/clang-format.yaml +21 -0
  91. data/lib/rubik/security/classifier/commands/clang.yaml +37 -0
  92. data/lib/rubik/security/classifier/commands/cmake.yaml +37 -0
  93. data/lib/rubik/security/classifier/commands/ctest.yaml +30 -0
  94. data/lib/rubik/security/classifier/commands/gcc.yaml +36 -0
  95. data/lib/rubik/security/classifier/commands/gem.yaml +104 -0
  96. data/lib/rubik/security/classifier/commands/gofmt.yaml +15 -0
  97. data/lib/rubik/security/classifier/commands/pnpm.yaml +8 -8
  98. data/lib/rubik/security/classifier/commands/python.yaml +18 -1
  99. data/lib/rubik/security/classifier/commands/python3.yaml +18 -1
  100. data/lib/rubik/security/classifier/commands/rake.yaml +60 -0
  101. data/lib/rubik/security/classifier/commands/rspec.yaml +42 -0
  102. data/lib/rubik/security/classifier/commands/rubocop.yaml +38 -0
  103. data/lib/rubik/security/classifier/commands/ruby.yaml +25 -0
  104. data/lib/rubik/security/classifier/commands/rustc.yaml +34 -0
  105. data/lib/rubik/security/classifier/commands/zig.yaml +77 -0
  106. data/lib/rubik/security/classifier/database.rb +12 -1
  107. data/lib/rubik/security/classifier/matcher.rb +17 -2
  108. data/lib/rubik/security/classifier/models.rb +3 -2
  109. data/lib/rubik/security/classifier.rb +5 -0
  110. data/lib/rubik/security/guard.rb +133 -39
  111. data/lib/rubik/storage/layout.rb +14 -3
  112. data/lib/rubik/storage/vakanuvis/harness.rb +49 -89
  113. data/lib/rubik/tools/base.rb +55 -7
  114. data/lib/rubik/tools/builtins/dmesg.rb +1 -1
  115. data/lib/rubik/tools/builtins/exec.rb +1 -2
  116. data/lib/rubik/tools/builtins/files.rb +3 -1
  117. data/lib/rubik/tools/builtins/goal_ledger.rb +10 -10
  118. data/lib/rubik/tools/builtins/grep.rb +2 -2
  119. data/lib/rubik/tools/builtins/interactive.rb +1 -3
  120. data/lib/rubik/tools/builtins/lifecycle.rb +1 -1
  121. data/lib/rubik/tools/builtins/lsp.rb +2 -2
  122. data/lib/rubik/tools/builtins/pruner.rb +1 -1
  123. data/lib/rubik/tools/builtins/runtime.rb +1 -1
  124. data/lib/rubik/tools/builtins/send_message.rb +14 -3
  125. data/lib/rubik/tools/builtins/skill.rb +1 -1
  126. data/lib/rubik/tools/builtins/storage.rb +1 -1
  127. data/lib/rubik/tools/builtins/subagent.rb +2 -1
  128. data/lib/rubik/tools/builtins/subagent_lifecycle.rb +5 -3
  129. data/lib/rubik/tools/builtins/symbols.rb +4 -4
  130. data/lib/rubik/tools/builtins/synthesis.rb +121 -64
  131. data/lib/rubik/tools/builtins/task.rb +1 -1
  132. data/lib/rubik/tools/builtins/unsynthesize.rb +38 -0
  133. data/lib/rubik/tools/builtins/vakanuvis.rb +1 -1
  134. data/lib/rubik/tools/catalog.rb +3 -0
  135. data/lib/rubik/tools/declaration.rb +6 -2
  136. data/lib/rubik/tools/preflight_runner.rb +107 -14
  137. data/lib/rubik/tools/registry.rb +2 -0
  138. data/lib/rubik/tools/uri_resolver.rb +3 -1
  139. data/lib/rubik/uris.rb +5 -1
  140. data/lib/rubik/version.rb +1 -1
  141. data/lib/rubik.rb +1 -0
  142. metadata +27 -1
@@ -1,31 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "monitor"
4
+ require_relative "../../concurrency"
5
+ require_relative "../../events"
4
6
 
5
7
  module Rubik
6
8
  module Storage
7
9
  module Vakanuvis
8
- # Düzlem 1 — Deterministik Çekirdek: tek worker thread + sınırlı FIFO kuyruk.
9
- # Olay kapıları mevcut bus abonelikleridir (subagent tamamlanma + goal
10
- # bitişi — K3); NE ZAMAN, NEREYE, NASIL yazılacağı burada kural tabanlıdır.
10
+ # Düzlem 1 — Deterministik Çekirdek: tek worker thread + sınırlı FIFO
11
+ # kuyruk (Concurrency::Worker iskeleti: atomik kabul, idempotent
12
+ # kapanış, busy sayımı ve son-çare ağı iskelettedir). Olay kapıları
13
+ # mevcut bus abonelikleridir (subagent tamamlanma + goal bitişi — K3);
14
+ # NE ZAMAN, NEREYE, NASIL yazılacağı burada kural tabanlıdır.
11
15
  # Sessizlik sözleşmesi (§4.3): WAKE_KINDS dışında kalır, notice yaymaz —
12
16
  # sadece dmesg/stderr. Ömür: ctx dispose'u LIFO ile kapatır (worker kill + abonelik geri alımı).
13
17
  class Harness
14
- STOP = :__vakanuvis_stop__
18
+ include Concurrency::Worker
19
+
20
+ # STOP işareti iskeletin tek ev sahibinde; sabit adı kuyruk gözetimi
21
+ # ve test ikizleri için yaşar.
22
+ STOP = Concurrency::Worker::STOP
15
23
  MAX_QUEUE = 200
16
24
  # v2 §4-V4: damıtıcı kaynak disiplini — yalnız TAMAMLANMIŞ transcript'ler,
17
25
  # damıtıcının kendisi Hariç (özyineleme kirliliği: canlı depoda transcript satırları 'vakanuvis' etiketi taşır).
18
26
  SOURCE_TRANSCRIPT_LIMIT = 8
19
- # Literaller, depolama katmanını orchestrator require'larından
20
- # uzak tutar; test ikizleri her ikisini de sabitlere pinler:
21
- # Notices::COMPLETED_EVENT ve GoalState::FINISH_EVENT. TURN_EVENT,
22
- # REPL TurnRecorder#emit_turn_finished kapısıdır (root-turn planı 2026-10-04).
23
- SUBAGENT_EVENT = :subagent_completed
24
- GOAL_EVENT = :goal_finished
25
- TURN_EVENT = :turn_finished
26
- # Askı kroniği (tarama kartı 2, 2026-11-01): GoalState::SUSPEND_EVENT — abonelik
27
- # :goal akışına yazar; worker status=="suspended" ile ayırt eder.
28
- SUSPEND_EVENT = :goal_suspended
27
+ # Olay adları Rubik::Events yaprağından okunur: yaprak sıfır
28
+ # require'lıdır (uris.rb gramer yaprağı öncülü) — depolama
29
+ # katmanı orchestrator mantığına bağımlı olmadan tek söz
30
+ # dağarcığına bağlanır; izolasyon doktrininin harfi bozulmaz.
31
+ SUBAGENT_EVENT = Rubik::Events::SUBAGENT_COMPLETED
32
+ GOAL_EVENT = Rubik::Events::GOAL_FINISHED
33
+ TURN_EVENT = Rubik::Events::TURN_FINISHED
34
+ # Askı kroniği: abonelik :goal akışına yazar; worker
35
+ # status=="suspended" ile ayırt eder.
36
+ SUSPEND_EVENT = Rubik::Events::GOAL_SUSPENDED
29
37
 
30
38
  attr_reader :store, :config, :supervisor, :dmesg, :session_slug, :gate
31
39
 
@@ -74,61 +82,19 @@ module Rubik
74
82
  self
75
83
  end
76
84
 
77
- def stopped? = @monitor.synchronize { @stopped }
78
-
79
- # Dispose yolu: FIFO'daki her şey (STOP dahil öncesindeki olaylar) işlenir,
80
- # sonra thread sonlanır. Kalan olay yarımda kalmaz; thread 2 saniyede durmazsa
81
- # (yavaş bir flush/spawn içinde) kill gelir ve işlenemeyen olay sayısı dmesg'e düşer — sessiz kayıp yok.
82
- def shutdown
83
- @monitor.synchronize do
84
- return if @stopped
85
-
86
- @stopped = true
87
- @busy += 1 # STOP işaretinin de işleniş sayılır
88
- @queue.push(STOP)
89
- end
90
- begin
91
- auto_digest_touched!(spawn: false)
92
- rescue StandardError => e
93
- Vakanuvis.log_via(@dmesg, :warn, "shutdown auto-digest failed (#{e.class}: #{e.message}) — worker teardown continues")
94
- end
95
- @worker&.join(2)
96
- if @worker&.alive?
97
- Vakanuvis.log_via(@dmesg, :warn, "worker did not stop in 2s — killing with #{queue_size} event(s) unprocessed")
98
- @worker.kill
99
- end
100
- @worker = nil
101
- end
102
-
103
- def wait_idle(timeout: 2.0)
104
- deadline = Time.now + timeout
105
- sleep 0.01 while busy? && Time.now < deadline
106
- !busy?
107
- end
108
-
109
- # Kuyrukta + uçuştaki olay sayısı (push'ta artar, işlenince/düşürülünce azalır) — pop ile işaretleme arasındaki yarış penceresini kapatır.
110
- def busy? = @monitor.synchronize { @busy.positive? }
111
-
112
85
  # ---- olay giriş kapıları (kworker thread'inde çağrılır) -----------
113
86
 
87
+ # Atomik kabul (stopped-kontrol + push tek kritik bölümde) iskelette:
88
+ # kapanış yarışındaki olay ya STOP'tan önce düşer ve işlenir ya da
89
+ # reddedilir — arada kalan işleyeneksiz olay kalamaz.
114
90
  def enqueue_event(kind, payload)
115
91
  unless payload.is_a?(Hash)
116
92
  Vakanuvis.log_via(@dmesg, :warn, "discarded non-hash #{kind} event (#{payload.class})")
117
93
  return false
118
94
  end
119
-
120
- @monitor.synchronize do
121
- return false if @stopped
122
-
123
- drop_oldest! if @queue.size >= @max_queue
124
- @busy += 1
125
- @queue.push([kind, payload])
126
- true
127
- end
95
+ super
128
96
  end
129
97
 
130
- def queue_size = @queue.size
131
-
132
98
  # ---- talep düzlemi (maestro aracı buraya delege eder; K7) ---------
133
99
 
134
100
  # Deterministik geri çağırma Recall düzleminde (recall.rb); burada
@@ -215,37 +181,31 @@ module Rubik
215
181
  @event_bus.subscribe(TURN_EVENT, context: @context) { |p| enqueue_event(:turn, p) } if @root_turns
216
182
  end
217
183
 
218
- # Taşma düşürmesi asla STOP işaretini yutamaz (yutsa worker hiç
219
- # sonlanamazdı): STOP geldiyse kuyruğun sonuna geri konur.
220
- def drop_oldest!
221
- item = @queue.pop(true)
222
- if item == STOP
223
- @queue.push(STOP)
224
- else
225
- @monitor.synchronize do
226
- @dropped += 1
227
- @busy -= 1
228
- end
229
- Vakanuvis.log_via(@dmesg, :warn, "event queue overflow — dropped oldest (total: #{@dropped})")
230
- end
231
- rescue ThreadError
232
- nil
184
+ # ---- Concurrency::Worker iskelet kancaları --------------------------
185
+
186
+ def worker_max_queue = @max_queue
187
+
188
+ def worker_warn(message) = Vakanuvis.log_via(@dmesg, :warn, message)
189
+
190
+ # Kapanış yolundaki son damıtım fırsatı (spawn yok — zombi doğum
191
+ # engeli); hata yalıtılmış: worker sökümü devam eder.
192
+ def worker_before_join
193
+ auto_digest_touched!(spawn: false)
194
+ rescue StandardError => e
195
+ Vakanuvis.log_via(@dmesg, :warn, "shutdown auto-digest failed (#{e.class}: #{e.message}) — worker teardown continues")
233
196
  end
234
197
 
235
- def run_worker
236
- loop do
237
- kind, payload = @queue.pop
238
- break if kind == STOP
198
+ def worker_drop_accounted(_item)
199
+ @monitor.synchronize { @dropped += 1 }
200
+ Vakanuvis.log_via(@dmesg, :warn, "event queue overflow — dropped oldest (total: #{@dropped})")
201
+ end
239
202
 
240
- handle_event(kind, payload)
241
- rescue StandardError => e
242
- # Last-ditch net: a raise escaping handle_event's own rescue
243
- # would kill the worker with queued events unconsumed — and
244
- # shutdown's alive?-check stays blind to that loss.
245
- Vakanuvis.log_via(@dmesg, :warn, "chronicler worker event dispatch failed (#{e.class}: #{e.message}) — worker continues")
246
- ensure
247
- @monitor.synchronize { @busy -= 1 }
248
- end
203
+ def worker_dispatch_failed(kind, _payload, error)
204
+ # A dispatch-lost event must leave a chronicle trace — the same
205
+ # ledger as overflow drops, so the session annal cannot look
206
+ # complete when it is not.
207
+ @monitor.synchronize { @dropped += 1 }
208
+ Vakanuvis.log_via(@dmesg, :warn, "chronicler worker event dispatch failed (#{error.class}: #{error.message}) — #{kind} event lost, worker continues")
249
209
  end
250
210
 
251
211
  # TranscriptIndexer disiplini: kronikçinin kendi hatası akışı
@@ -383,7 +343,7 @@ module Rubik
383
343
  @monitor.synchronize do
384
344
  if @dropped.positive?
385
345
  seq = @seq += 1
386
- overflow = [["dropped.#{seq}", "- [#{seq}] #{@dropped} event(s) dropped — queue overflow (event=dropped.#{seq})"]]
346
+ overflow = [["dropped.#{seq}", "- [#{seq}] #{@dropped} event(s) dropped — queue overflow or dispatch failure (event=dropped.#{seq})"]]
387
347
  @dropped = 0
388
348
  end
389
349
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "pathname"
4
4
  require_relative "declaration"
5
+ require_relative "services" unless defined?(Rubik::Tools::Services)
6
+ require_relative "../coeffects" unless defined?(Rubik::Coeffects)
5
7
 
6
8
  module Rubik
7
9
  module Tools
@@ -76,6 +78,35 @@ module Rubik
76
78
  end
77
79
  end
78
80
 
81
+ # Single home for tool-side coeffect and service resolution (architecture
82
+ # review Candidate A2, issue #368). Unifies the 3 scattered tool-side
83
+ # dialects:
84
+ # 1. Coeffects.resolve(@runtime_context, KEY, @fallback)
85
+ # 2. @fallback || (ctx.respond_to?(:get) ? Coeffects.get(...) : nil)
86
+ # 3. @runtime_manager.context coeffect lookups
87
+ #
88
+ # Delegates directly to Tools::Services::COEFFECTS and Coeffects.get so
89
+ # no third resolution home is created. If the runtime context does not
90
+ # satisfy the coeffect, falls back to the explicitly passed `fallback`,
91
+ # or to an instance variable matching `@#{key}` if defined.
92
+ #
93
+ # task_mgr = service(:task_manager)
94
+ # harness = service(:pruner, @harness)
95
+ # asker = service(:subagent_question_asker)
96
+ def service(key, fallback = nil, ctx: nil)
97
+ effective_ctx = ctx || (defined?(@runtime_context) ? @runtime_context : nil)
98
+ effective_ctx ||= (@runtime_manager.context if defined?(@runtime_manager) && @runtime_manager.respond_to?(:context))
99
+
100
+ coeffect_key = Rubik::Tools::Services::COEFFECTS[key] || Rubik::Coeffects.canonical(key)
101
+ resolved = Rubik::Coeffects.get(effective_ctx, coeffect_key) if effective_ctx
102
+ return resolved unless nil.equal?(resolved)
103
+
104
+ return fallback unless nil.equal?(fallback)
105
+
106
+ ivar = :"@#{key}"
107
+ instance_variable_defined?(ivar) ? instance_variable_get(ivar) : nil
108
+ end
109
+
79
110
  # Normalizes a model-supplied path filter against the tool's root
80
111
  # directory: backslashes become slashes, "./" is stripped, and ABSOLUTE
81
112
  # paths (C:/…, /…) are relativized when they sit inside the root.
@@ -98,18 +129,35 @@ module Rubik
98
129
  return [sub_path, nil]
99
130
  end
100
131
 
101
- return [filter, nil] unless filter =~ %r{\A([A-Za-z]:/|/)}
132
+ # Handle Windows drive letters portably across Linux, macOS and Windows
133
+ filter_drive = filter =~ %r{\A([A-Za-z]):(/.*)?\z} ? Regexp.last_match(1).upcase : nil
134
+ filter_path = filter_drive ? (Regexp.last_match(2) || "/") : filter
135
+ root_drive = norm_root =~ %r{\A([A-Za-z]):(/.*)?\z} ? Regexp.last_match(1).upcase : nil
136
+ root_path = root_drive ? (Regexp.last_match(2) || "/") : norm_root
137
+
138
+ outside = if (filter_drive && !root_drive) ||
139
+ (!filter_drive && root_drive && filter_path.start_with?("/")) ||
140
+ (filter_drive && root_drive && filter_drive != root_drive)
141
+ true
142
+ else
143
+ base_root = File.expand_path(root_path)
144
+ expanded = File.expand_path(filter_path, base_root)
145
+ rel_check = begin
146
+ Pathname.new(expanded).relative_path_from(Pathname.new(base_root)).to_s.tr("\\", "/")
147
+ rescue ArgumentError
148
+ nil
149
+ end
150
+ rel_check.nil? || rel_check == ".." || rel_check.start_with?("../")
151
+ end
102
152
 
103
- rel = begin
104
- Pathname.new(File.expand_path(filter)).relative_path_from(Pathname.new(File.expand_path(root_dir))).to_s.tr("\\", "/")
105
- rescue ArgumentError
106
- nil
107
- end
108
- outside = rel.nil? || rel == ".." || rel.start_with?("../")
109
153
  if outside
110
154
  return [nil, "Path '#{raw}' is outside the project workspace (#{root_dir}). " \
111
155
  "Use a path relative to the project root, e.g. 'lib'."]
112
156
  end
157
+
158
+ base_root = File.expand_path(root_path)
159
+ expanded = File.expand_path(filter_path, base_root)
160
+ rel = Pathname.new(expanded).relative_path_from(Pathname.new(base_root)).to_s.tr("\\", "/")
113
161
  return ["", nil] if rel == "."
114
162
 
115
163
  [rel, nil]
@@ -67,7 +67,7 @@ module Rubik
67
67
  private
68
68
 
69
69
  def resolve_dmesg
70
- @dmesg || (@runtime_context.respond_to?(:get) ? Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::DMESG) : nil)
70
+ service(:dmesg)
71
71
  end
72
72
  end
73
73
  end
@@ -187,8 +187,7 @@ module Rubik
187
187
  private
188
188
 
189
189
  def execute_background(cmd)
190
- task_mgr = @task_manager ||
191
- (@runtime_context.respond_to?(:get) ? Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::TASK_MANAGER) : nil)
190
+ task_mgr = service(:task_manager)
192
191
  if task_mgr.nil?
193
192
  return Rubik::Tools::Result.new(tool_name: "run_command", status: :error,
194
193
  output: "TaskManager is not available to run commands in background.",
@@ -91,6 +91,7 @@ module Rubik
91
91
  "For surgical edits to existing files, use replace_file_content instead. " \
92
92
  "Use apply_buffer to persist the buffer to disk before running tests or tests will not see your changes.",
93
93
  risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: true, buffer_bound: true,
94
+ buffer_sync_writer: true,
94
95
  params_schema: {
95
96
  type: "object",
96
97
  properties: {
@@ -166,7 +167,7 @@ module Rubik
166
167
  end
167
168
 
168
169
  def context_index
169
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::CONTEXT_INDEX, @context_index)
170
+ service(:context_index, @context_index)
170
171
  end
171
172
 
172
173
  def execute(args = {})
@@ -237,6 +238,7 @@ module Rubik
237
238
  description: "Replace an exact chunk of code within an existing file. Requires exact verbatim matching of target_content " \
238
239
  "(including whitespace and indentation). Optional start_line and end_line narrow the search range.",
239
240
  risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: true, buffer_bound: true,
241
+ buffer_sync_writer: true,
240
242
  params_schema: {
241
243
  type: "object",
242
244
  properties: {
@@ -18,15 +18,15 @@ module Rubik
18
18
 
19
19
  DECLARATION = Declaration.new(
20
20
  name: "update_goal_ledger", aliases: ["ledger"],
21
- description: "Update the structured goal ledger of the RUNNING !goal loop with a " \
22
- "JSON patch ({\"rev\": N, \"ops\": [{\"op\": ..., \"path\": ..., \"value\": ...}]}). " \
23
- "Read the current ledger via read_file(path: 'rubik://goal/ledger') and issue the " \
24
- "patch against the rev it reports. Rejections carry per-op fix hints; after the " \
25
- "retry budget the ledger stays unchanged — read it and continue. A task status of " \
26
- "`stale` means the harness re-checked that entry's verify predicate against the " \
27
- "filesystem and it FAILED (the world drifted): re-inspect reality, then update the " \
28
- "entry (including status) with a normal patch — a stale rev also means the ledger " \
29
- "moved under you.",
21
+ description: "Update the structured goal ledger of the RUNNING !goal loop with an RFC 6902 " \
22
+ "JSON patch ({\"rev\": N, \"ops\": [{\"op\": \"add\"|\"replace\"|\"remove\", \"path\": \"/tasks/0/status\", \"value\": ...}]}). " \
23
+ "Read current state via read_file(path: 'rubik://goal/ledger') (or 'rubik://goal/ledger.json') and issue " \
24
+ "the patch against the rev it reports. Items carry 0-based indices (/tasks/0); append via /tasks/-. " \
25
+ "Tasks and environment notes may carry declarative verify specs: {\"type\": \"file_exists\", \"path\": ...}, " \
26
+ "{\"type\": \"file_contains\", \"path\": ..., \"pattern\": ...}, or {\"type\": \"marker\", \"path\": ..., \"marker\": ...}. " \
27
+ "Rejections carry per-op fix hints; after the retry budget the ledger stays unchanged. A task status of " \
28
+ "`stale` means the harness re-checked that entry's verify predicate against the filesystem and it FAILED " \
29
+ "(the world drifted): re-inspect reality, then update the entry with a normal patch against the bumped rev.",
30
30
  risk: :write, archetypes: [], write_grant: false, root_only: true,
31
31
  maestro_blocked: false, # vakanüvis/pruner emsali: kök düzlem aracı
32
32
  params_schema: {
@@ -53,7 +53,7 @@ module Rubik
53
53
  "{\"rev\": N, \"ops\": [...]}.")
54
54
  end
55
55
 
56
- ledger = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::GOAL_LEDGER, nil)
56
+ ledger = service(:goal_ledger)
57
57
  unless ledger
58
58
  return ToolOutput.error("Goal ledger is not available: no running !goal loop (or goal.ledger.enabled=false). " \
59
59
  "The ledger exists only while a goal loop runs; update it after each meaningful step.")
@@ -45,11 +45,11 @@ module Rubik
45
45
  end
46
46
 
47
47
  def context_index
48
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::CONTEXT_INDEX, @context_index)
48
+ service(:context_index, @context_index)
49
49
  end
50
50
 
51
51
  def buffer_manager
52
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::BUFFER_MANAGER, @buffer_manager)
52
+ service(:buffer_manager, @buffer_manager)
53
53
  end
54
54
 
55
55
  def execute(args = {})
@@ -88,9 +88,7 @@ module Rubik
88
88
  # a subagent child context (ScopedRegistry rebind); the root-context
89
89
  # instance stays nil here and keeps the human-dialog behavior.
90
90
  def init0_asker
91
- return nil unless @runtime_context.respond_to?(:get)
92
-
93
- Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::SUBAGENT_QUESTION_ASKER)
91
+ service(:subagent_question_asker)
94
92
  end
95
93
 
96
94
  # One blocking round-trip for the whole batch: the maestro answers once and
@@ -330,7 +330,7 @@ module Rubik
330
330
  private
331
331
 
332
332
  def verify_binary(target, lang, proposed_cmd, sub_ctx, probe_args: nil)
333
- Rubik::Runtime::RepairProbe.new(root_dir: @root_dir).verify(target, lang, proposed_cmd, sub_ctx, probe_args: probe_args)
333
+ Rubik::Runtime::RepairProbe.new(root_dir: @root_dir, guard: @guard).verify(target, lang, proposed_cmd, sub_ctx, probe_args: probe_args)
334
334
  end
335
335
 
336
336
  def command_provided?(command)
@@ -20,11 +20,11 @@ module Rubik
20
20
  end
21
21
 
22
22
  def effective_lsp_manager
23
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::LSP_MANAGER, @lsp_manager)
23
+ service(:lsp_manager, @lsp_manager)
24
24
  end
25
25
 
26
26
  def effective_buffer_manager
27
- @buffer_manager || Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::BUFFER_MANAGER, nil)
27
+ service(:buffer_manager, @buffer_manager)
28
28
  end
29
29
 
30
30
  private
@@ -49,7 +49,7 @@ module Rubik
49
49
 
50
50
  def execute(args = {})
51
51
  action = (args["action"] || args[:action] || "status").to_s
52
- harness = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::PRUNER, @harness)
52
+ harness = service(:pruner, @harness)
53
53
  unless harness
54
54
  return ToolOutput.error("Context pruner is not available: disabled by config " \
55
55
  "(subagents.pruner.enabled=false) or the harness is not wired " \
@@ -63,7 +63,7 @@ module Rubik
63
63
  cmds.sort.each { |name, meta| lines << " !#{name.ljust(16)} : #{meta[:description]}" }
64
64
  end
65
65
 
66
- task_mgr = (Rubik::Coeffects.get(@runtime_manager.context, Rubik::Coeffects::TASK_MANAGER) if @runtime_manager&.context.respond_to?(:get))
66
+ task_mgr = service(:task_manager)
67
67
  task_mgr ||= @shell.task_manager if @shell.respond_to?(:task_manager)
68
68
 
69
69
  if ["all", "tasks"].include?(target) && task_mgr
@@ -72,6 +72,19 @@ module Rubik
72
72
  return delivery_text(recipient) if delivered == true
73
73
  return queued_text(recipient, steps) if delivered == :queued
74
74
 
75
+ # A dependency-queued (or launching) spec exists but has never run:
76
+ # "not found" is false, and the redeploy suggestion below would
77
+ # refuse the same id — the model needs the truthful next action.
78
+ if sup.respond_to?(:get) && (spec = sup.get(recipient)) && spec.respond_to?(:queued?) &&
79
+ (spec.queued? || spec.spawning?)
80
+ return ToolOutput.error(
81
+ "Subagent '#{recipient}' is dependency-queued (deps: #{spec.depends_on.join(', ')}) and will " \
82
+ "launch automatically when its predecessors settle. Messages cannot be buffered on an unborn " \
83
+ "spec — re-send after it launches, or kill it with manage_subagents(action: 'kill', " \
84
+ "conversation_id: '#{recipient}') if the wait is no longer worth it."
85
+ )
86
+ end
87
+
75
88
  ToolOutput.error(
76
89
  "Subagent '#{recipient}' not found or no longer active. If it recently finished, redeploy it with its " \
77
90
  "context intact: manage_subagents(action: 'redeploy', conversation_id: '#{recipient}', prompt: '<task>') " \
@@ -84,9 +97,7 @@ module Rubik
84
97
  # Subagent düzlemi (rebound araç): gönderen coeffect'i GERÇEK subagent
85
98
  # id'sidir. Kök düzleminde sağlanmaz → Supervisor default'u kalır.
86
99
  def subagent_sender_id
87
- return nil unless @runtime_context.respond_to?(:get)
88
-
89
- Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::SUBAGENT_SENDER_ID)
100
+ service(:subagent_sender_id)
90
101
  end
91
102
 
92
103
  # Kök alias'ına giden mesajın yanıtı kök kişisiyle konuşur ("the
@@ -45,7 +45,7 @@ module Rubik
45
45
  end
46
46
 
47
47
  def execute(args = {})
48
- manager = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::SKILL_MANAGER, @manager)
48
+ manager = service(:skill_manager, @manager)
49
49
  return ToolOutput.error("Error: skills manager is not available.") unless manager
50
50
  return ToolOutput.error("Error: skills are disabled (skills.enabled = false).") unless manager.enabled?
51
51
 
@@ -102,7 +102,7 @@ module Rubik
102
102
  # STORAGE_STORE coeffect'i (parent chain — subagent'lar buradan çözer)
103
103
  # → config'e dayalı tembel fresh default (storage kapalıysa nil).
104
104
  def resolve_store
105
- resolved = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::STORAGE_STORE, @store)
105
+ resolved = service(:storage_store, @store)
106
106
  return resolved if resolved
107
107
 
108
108
  @resolve_store ||= Rubik::Storage::Service.build(config: @config, root_dir: @root_dir)
@@ -16,6 +16,7 @@ module Rubik
16
16
  module SubagentToolHelpers
17
17
  def resolve_supervisor(supervisor, runtime_context)
18
18
  return supervisor if supervisor
19
+ return service(:subagent_supervisor, ctx: runtime_context) if respond_to?(:service)
19
20
  return nil unless runtime_context.respond_to?(:get)
20
21
 
21
22
  Rubik::Coeffects.get(runtime_context, Rubik::Coeffects::SUBAGENT_SUPERVISOR)
@@ -99,7 +100,7 @@ module Rubik
99
100
  # Task ownership (issue #125): the spawning context's token owns the new
100
101
  # work (detached specs opt out per spec). Resolved at call time, so a
101
102
  # nested subagent inherits its ancestor's task through its child ctx.
102
- owner = Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::TASK_CANCELLATION)
103
+ owner = service(:task_cancellation)
103
104
 
104
105
  begin
105
106
  results = sup.spawn_batch(specs, owner: owner)
@@ -113,8 +113,10 @@ module Rubik
113
113
 
114
114
  # Blocked states that need maestro action before their chain proceeds
115
115
  # (bug-llm-timeout-observability ④): a bare JSON list made a stalled
116
- # subagent indistinguishable from a healthy one at a glance.
117
- ATTENTION_STATES = [:paused_error, :waiting_budget, :budget_exhausted, :waiting_input].freeze
116
+ # subagent indistinguishable from a healthy one at a glance. The set
117
+ # itself is owned by Lifecycle (ATTENTION_STATES beside TRANSITIONS) —
118
+ # this file used to hand-copy it.
119
+ def attention_states = Rubik::Orchestrator::Subagent::Lifecycle::ATTENTION_STATES
118
120
 
119
121
  # List with a prominent attention block: any blocked subagent is called
120
122
  # out ABOVE the JSON with its state, last error, and the exact recovery
@@ -124,7 +126,7 @@ module Rubik
124
126
  return "No active or tracked subagents." if instances.empty?
125
127
 
126
128
  lines = []
127
- attention = instances.select { |i| ATTENTION_STATES.include?(i.state.to_sym) }
129
+ attention = instances.select { |i| attention_states.include?(i.state.to_sym) }
128
130
  if attention.any?
129
131
  lines << "⚠ #{attention.size} subagent(s) need attention:"
130
132
  attention.each do |i|
@@ -30,7 +30,7 @@ module Rubik
30
30
  end
31
31
 
32
32
  def ast_graph
33
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
33
+ service(:ast_graph, @ast_graph)
34
34
  end
35
35
 
36
36
  def execute(args = {})
@@ -96,7 +96,7 @@ module Rubik
96
96
  end
97
97
 
98
98
  def ast_graph
99
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
99
+ service(:ast_graph, @ast_graph)
100
100
  end
101
101
 
102
102
  def execute(args = {})
@@ -146,7 +146,7 @@ module Rubik
146
146
  end
147
147
 
148
148
  def ast_graph
149
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
149
+ service(:ast_graph, @ast_graph)
150
150
  end
151
151
 
152
152
  def execute(args = {})
@@ -201,7 +201,7 @@ module Rubik
201
201
  end
202
202
 
203
203
  def ast_graph
204
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
204
+ service(:ast_graph, @ast_graph)
205
205
  end
206
206
 
207
207
  def execute(args = {})