rubik 0.9.0 → 0.9.1

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +108 -43
  4. data/README.md +5 -1
  5. data/lib/rubik/adapter/base.rb +19 -0
  6. data/lib/rubik/adapter/generic.rb +0 -14
  7. data/lib/rubik/adapter/node.rb +2 -0
  8. data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
  9. data/lib/rubik/cli/workspace_trust.rb +16 -0
  10. data/lib/rubik/config/defaults.rb +23 -0
  11. data/lib/rubik/config/store.rb +14 -0
  12. data/lib/rubik/kernel/dispatcher.rb +4 -4
  13. data/lib/rubik/log.rb +2 -1
  14. data/lib/rubik/lsp/client.rb +83 -180
  15. data/lib/rubik/lsp/document_store.rb +209 -0
  16. data/lib/rubik/mcp/client.rb +4 -3
  17. data/lib/rubik/mcp/manager.rb +6 -2
  18. data/lib/rubik/mcp/transport/stdio.rb +51 -9
  19. data/lib/rubik/orchestrator/goal_session.rb +505 -0
  20. data/lib/rubik/orchestrator/subagent/instance.rb +4 -0
  21. data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
  22. data/lib/rubik/orchestrator/subagent/questioner.rb +21 -6
  23. data/lib/rubik/orchestrator/subagent/step_runner.rb +1 -1
  24. data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
  25. data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
  26. data/lib/rubik/orchestrator.rb +1 -0
  27. data/lib/rubik/platform.rb +15 -0
  28. data/lib/rubik/plugin/storage.rb +20 -29
  29. data/lib/rubik/repl/commands/agent_context.rb +1 -1
  30. data/lib/rubik/repl/commands/agent_execution.rb +7 -470
  31. data/lib/rubik/repl/commands/buffer.rb +1 -1
  32. data/lib/rubik/repl/commands/lsp.rb +1 -1
  33. data/lib/rubik/repl/input_loop.rb +1 -1
  34. data/lib/rubik/repl/lifecycle.rb +28 -0
  35. data/lib/rubik/runtime/manifest_store.rb +116 -0
  36. data/lib/rubik/runtime/overlay_storage.rb +247 -196
  37. data/lib/rubik/runtime/task_manager.rb +7 -2
  38. data/lib/rubik/runtime.rb +1 -0
  39. data/lib/rubik/security/allowlist.rb +167 -0
  40. data/lib/rubik/security/audit_log.rb +72 -0
  41. data/lib/rubik/security/classifier/classifier.rb +8 -0
  42. data/lib/rubik/security/command_gate.rb +567 -0
  43. data/lib/rubik/security/guard.rb +88 -1075
  44. data/lib/rubik/security/path_policy.rb +117 -0
  45. data/lib/rubik/security/synthesis_gate.rb +300 -0
  46. data/lib/rubik/security.rb +5 -0
  47. data/lib/rubik/storage/ranking.rb +113 -0
  48. data/lib/rubik/storage/store.rb +2 -92
  49. data/lib/rubik/storage/transcript_indexer.rb +2 -3
  50. data/lib/rubik/tools/builtins/grep.rb +2 -3
  51. data/lib/rubik/tools/builtins/lifecycle.rb +90 -87
  52. data/lib/rubik/tools/builtins/synthesis.rb +3 -0
  53. data/lib/rubik/tools/lifecycle_rollbacks.rb +87 -0
  54. data/lib/rubik/tools/native_search.rb +2 -1
  55. data/lib/rubik/tools/truncator.rb +25 -0
  56. data/lib/rubik/version.rb +1 -1
  57. metadata +11 -1
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "securerandom"
4
- require "time"
5
-
6
3
  require_relative "base"
7
4
  require_relative "../../runtime"
8
5
  require_relative "../../sandbox"
9
6
  require_relative "../../orchestrator/auto_apply"
7
+ require_relative "../../orchestrator/goal_session"
10
8
 
11
9
  module Rubik
12
10
  module REPL
@@ -19,6 +17,9 @@ module Rubik
19
17
  USAGE_PLAN = "Kullanım: !plan <görev açıklaması>"
20
18
  USAGE_GOAL = "Kullanım: !goal [--steps N|-s N] <hedef açıklaması> | !goal resume | !goal list"
21
19
 
20
+ # The !goal run lifecycle (start/suspend/resume/terminal mapping) is
21
+ # the Orchestrator::GoalSession domain (issue #404); this module keeps
22
+ # only command registration, argument parsing and usage rendering.
22
23
  def self.register(shell)
23
24
  register_plan_command(shell)
24
25
  register_goal_command(shell)
@@ -77,8 +78,8 @@ module Rubik
77
78
  # Tek-argüman şartı: "Resume the deployment" gibi hedef metinleri
78
79
  # alt-komut olarak yakalanamaz.
79
80
  sub = args.first.to_s.downcase
80
- next resume_suspended_goal(ctx) if args.length == 1 && sub == "resume"
81
- next list_suspended_goals(ctx) if args.length == 1 && sub == "list"
81
+ next Rubik::Orchestrator::GoalSession.resume_suspended_goal(ctx) if args.length == 1 && sub == "resume"
82
+ next Rubik::Orchestrator::GoalSession.list_suspended_goals(ctx) if args.length == 1 && sub == "list"
82
83
 
83
84
  parsed = parse_goal_args(args)
84
85
  if !parsed[:valid]
@@ -90,7 +91,7 @@ module Rubik
90
91
  next
91
92
  end
92
93
 
93
- execute_goal(ctx, parsed[:goal_text], parsed[:custom_steps])
94
+ Rubik::Orchestrator::GoalSession.execute_goal(ctx, parsed[:goal_text], parsed[:custom_steps])
94
95
  end
95
96
  end
96
97
 
@@ -126,470 +127,6 @@ module Rubik
126
127
  { custom_steps: custom_steps, goal_text: goal_text, valid: valid }
127
128
  end
128
129
 
129
- private_class_method def self.initialize_goal_ledger(ctx, goal_text)
130
- return nil unless Rubik::Orchestrator::GoalLedger::Ledger.enabled?(ctx.config)
131
-
132
- store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
133
- dmesg = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::DMESG)
134
- goal_ledger = Rubik::Orchestrator::GoalLedger::Ledger.create!(
135
- goal_text: goal_text, config: ctx.config, store: store, dmesg: dmesg,
136
- event_bus: ctx.event_bus
137
- )
138
- ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, goal_ledger)
139
- goal_ledger
140
- end
141
-
142
- private_class_method def self.execute_goal(ctx, goal_text, custom_steps)
143
- ctx.recorder&.record_user_turn("!goal #{goal_text}")
144
- goal_steps = custom_steps || ctx.config.fetch("agent.goal_max_steps", 100).to_i
145
- warn_ratio = ctx.config.fetch("agent.warn_at_ratio", 0.75).to_f
146
- routed = ctx.router.route(task_type: :goal, prompt: goal_text)
147
- ctx.runtime_manager.provide(:llm_client, routed[:provider]) if routed[:provider]
148
-
149
- # Canlı hedef durumu: maestro ve alt ajanlar read_file
150
- # rubik://goal/state ile aynı anlık görüntüyü okur. Provide swap
151
- # semantiğine sahiptir — tekrarlanan !goal koşuları Ω'ya inverse
152
- # yığmaz; session dispose'u tek delete-inverse ile temizler.
153
- # event_bus: bitiş olayı (GoalState::FINISH_EVENT) Vakanüvis
154
- # kronikçisinin goal kancasına akar (K3) — notice/wake yok.
155
- goal_state = Rubik::Orchestrator::GoalState.new(event_bus: ctx.event_bus)
156
- goal_state.start!(goal_text, goal_steps)
157
- ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
158
-
159
- # Yapılandırılmış Σ defteri (goal-ledger planı A): knob ON iken
160
- # koşuyla doğar, terminal dallarda finalize olur, provide swap
161
- # semantiğiyle tekrarlanan !goal koşuları Ω'ya inverse yığmaz.
162
- # OFF iken hiçbir yüz kurulmaz (araç/URI/prompt bayt-özdeş).
163
- goal_ledger = initialize_goal_ledger(ctx, goal_text)
164
-
165
- # Askı kimliği (issue #106): koşu boyunca SABİT — registry
166
- # girdisinin anahtarı ve Σ damgası meta'sının goal_id'si.
167
- # (Σ satır id'si her kabulde değişir; kimlik olarak kullanılamaz.)
168
- goal_id = "goal-#{Process.pid}-#{SecureRandom.hex(4)}"
169
-
170
- ctx.out.puts "[Rubik::Goal] Starting autonomous goal loop (Budget: #{goal_steps} steps) with #{routed[:role]} model (#{routed[:model]})..."
171
- ctx.out.puts "[Rubik::Goal] Target: #{goal_text}\n"
172
-
173
- orchestrator = ctx.orchestrator_loop(
174
- provider: routed[:provider],
175
- model: routed[:model],
176
- max_steps: goal_steps,
177
- warn_at_ratio: warn_ratio,
178
- context_limit: routed[:context_limit],
179
- max_output_tokens: routed[:max_output_tokens],
180
- on_step: build_goal_on_step(ctx, goal_state)
181
- )
182
-
183
- # Plan 53 D-8 yardımcısı: nötr çift + kayıtçı eşlemesi tek yerde.
184
- # Session restore kayıtçı OLAYLARINDAN hidrate eder — eşlenmiş
185
- # restore için conversation_history VE record_assistant_response
186
- # birlikte yazılmalı (başarısızlıkta da).
187
- record_goal_pair = build_goal_record_pair(ctx, goal_text)
188
-
189
- # Pruner apply seam: hedef döngüsü de aynı sınırda tohumlanır —
190
- # aşamalı budama planı varsa goal promptundan ÖNCE uygulanır.
191
- ctx.apply_staged_prune_plan!
192
-
193
- drive_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state,
194
- goal_ledger: goal_ledger, goal_text: goal_text, goal_id: goal_id,
195
- record_pair: record_goal_pair,
196
- start: ->(loop_inst) { loop_inst.run(goal_text, goal_mode: true, conversation_history: ctx.conversation_history) })
197
- end
198
-
199
- # ------------------------------------------------------------------
200
- # !goal sürücüsü (issue #106): koşu girişi + bütçe-soru döngüsü +
201
- # tek hata kanalı + terminal eşlemesi — start ve resume yollarının
202
- # ORTAK gövdesi. start callable'ı yolu seçer:
203
- # başlangıç → loop.run (taze koşu)
204
- # süreç-içi resume → loop.resume! (history prefix nesne-özdeş)
205
- # çapraz-süreç resume → loop.resume_from (Σ penceresi)
206
- # Askı dalı (#106): SADECE transient ClientError SUSPENDED'a gider;
207
- # kalıcı hatalar (moderasyon/401/read-timeout) bugünkü fail_goal
208
- # çıktısını bayt-baytına korur.
209
- private_class_method def self.drive_goal_turn(ctx, orchestrator:, goal_state:, goal_ledger:,
210
- goal_text:, goal_id:, record_pair:, start:)
211
- ctx.active_loop = orchestrator
212
- begin
213
- res = start.call(orchestrator)
214
- res = handle_goal_budget_extensions(ctx, orchestrator: orchestrator, goal_state: goal_state, res: res)
215
- rescue Interrupt
216
- # ^C hedefi 'running' bırakmasın; eşlenmiş kayıt otursun. Interrupt
217
- # yeniden yükselir — kullanıcı mesajını execute_command basar.
218
- # Resume üstüne ^C = askıyı terk (terminal :stopped damgası).
219
- goal_state.stop!("Interrupted by user (^C)")
220
- finalize_goal_ledger(goal_ledger, goal_state, :stopped)
221
- forget_suspended_goal(ctx, goal_id)
222
- record_pair.call("[Goal attempt interrupted after #{goal_state.step_count} steps]")
223
- raise
224
- rescue Rubik::LLM::ClientError => e
225
- # Tek hata kanalı (#106 uzantısı): transient transport hatası
226
- # (RETRYABLE tükenmesi, tükenmiş 5xx, 429) goal'u SUSPENDED'a
227
- # götürür — loop/counters/Σ korunur, REPL yaşar. Kalıcı hata
228
- # (#105 çıktısı değişmeden) terminal fail. Yeniden yükseltmez —
229
- # spinner temizliği dispatch katmanına (execute_command) aittir.
230
- # next yerine return: rescue sonrası res'siz terminal
231
- # eşlemesine düşülmesin.
232
- if e.respond_to?(:transient?) && e.transient?
233
- suspend_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state, goal_ledger: goal_ledger,
234
- goal_text: goal_text, goal_id: goal_id, record_pair: record_pair, reason: e.message,
235
- tokens: orchestrator.total_tokens)
236
- else
237
- fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
238
- record_pair: record_pair, reason: e.message)
239
- end
240
- return
241
- rescue StandardError => e
242
- fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
243
- record_pair: record_pair, reason: "#{e.class}: #{e.message}")
244
- return
245
- ensure
246
- ctx.active_loop = nil
247
- end
248
-
249
- handle_goal_completion(ctx, res: res, goal_state: goal_state, goal_ledger: goal_ledger,
250
- goal_id: goal_id, record_pair: record_pair)
251
- end
252
-
253
- private_class_method def self.finalize_goal_ledger(goal_ledger, goal_state, status)
254
- return unless goal_ledger
255
-
256
- goal_ledger.finalize!(status)
257
- goal_state.ledger_id = goal_ledger.snapshot[:storage_id]
258
- end
259
-
260
- private_class_method def self.fail_goal_turn(ctx, goal_state:, goal_ledger:, goal_id:, record_pair:,
261
- reason:, tokens: nil, steps: nil)
262
- sanitized = Rubik::Platform.safe_utf8(reason.to_s)
263
- steps_used = steps || goal_state.step_count
264
- goal_state.fail!(sanitized, tokens: tokens)
265
- finalize_goal_ledger(goal_ledger, goal_state, :failed)
266
- forget_suspended_goal(ctx, goal_id)
267
- ctx.out.puts "\n❌ Goal could not be completed: #{sanitized}"
268
- record_pair.call("[Goal attempt ended after #{steps_used} steps: #{sanitized}]", tokens: tokens)
269
- end
270
-
271
- private_class_method def self.suspend_goal_turn(ctx, orchestrator:, goal_state:, goal_ledger:,
272
- goal_text:, goal_id:, record_pair:, reason:, tokens: nil)
273
- attempt = suspended_attempt(ctx, goal_id) + 1
274
- # Ledger kimliği askıdan ÖNCE okunur: suspend! → ledger.suspend!
275
- # sırası metanın bu turun token'larını içermesi için zorunlu,
276
- # ama o damga storage_id'yi değiştirdiği için sonradan atanan id
277
- # SUSPEND_EVENT'e geç kalırdı — ilk askıda kronik satırı slug
278
- # kimliğine düşer, ledger= bağlantısı kaybolurdu.
279
- # resume_cross_process ile aynı uçuş-içi atama önceliği.
280
- goal_state.ledger_id = goal_ledger.snapshot[:storage_id] if goal_ledger
281
- goal_state.suspend!(reason, tokens: tokens)
282
- goal_ledger&.suspend!(suspend_stamp_meta(goal_state, goal_id, reason, attempt))
283
- registry = goal_registry_for(ctx)
284
- registry.register(Rubik::Orchestrator::GoalRegistry::Entry.new(
285
- goal_id: goal_id, goal_text: goal_text, loop: orchestrator,
286
- goal_state: goal_state, ledger: goal_ledger, reason: reason.to_s,
287
- suspended_at: Time.now, attempt: attempt
288
- ))
289
- ctx.out.puts "\n⏸️ [Rubik::Goal] Suspended after #{goal_state.step_count} steps (transient provider error): #{reason}"
290
- ctx.out.puts " Loop, counters and Σ ledger are preserved — resume with `!goal resume`."
291
- record_pair.call("[Goal suspended after #{goal_state.step_count} steps: #{reason}]", tokens: tokens)
292
- end
293
-
294
- private_class_method def self.handle_goal_budget_extensions(ctx, orchestrator:, goal_state:, res:)
295
- # Bütçe tükenince sor (execute_free_text simetrisi; aynı knob,
296
- # aynı +20). continue_loop boyunca active_loop DOLU kalmalı:
297
- # notice yönlendirmesi aktif döngüye bakar (lifecycle.rb
298
- # route_subagent_notice) — soruya beklerken gelen subagent
299
- # olayları loop inbox'a girer ve devam adımında boşaltılır.
300
- auto_extensions = 0
301
- max_auto = ctx.config.fetch("agent.goal_auto_continue_limit", 0).to_i
302
- # Yapılandırılmış neden (loop.rb terminali): insan-okur string
303
- # yalnız gösterim içindir — otomasyon prozu parse etmesin.
304
- while !res[:ok] && res[:reason] == :budget_exhausted
305
- if auto_extensions < max_auto
306
- auto_extensions += 1
307
- ctx.out.puts "\n🤖 [Rubik::Goal] Adım bütçesi doldu (#{res[:error]}). " \
308
- "Otonom devam hakkı (#{auto_extensions}/#{max_auto}) kullanılarak +20 adım ekleniyor..."
309
- goal_state.extend!(goal_state.max_steps + 20)
310
- res = orchestrator.continue_loop(20, auto: true)
311
- next
312
- end
313
-
314
- break unless ctx.config.fetch("agent.ask_continue_on_limit", true)
315
-
316
- ctx.out.puts "\n⚠️ [Rubik::Goal] #{res[:error]}"
317
- ans = ctx.ask_yes_no(" [Rubik::Goal] +20 adım ile devam edilsin mi?", default: "n")
318
- break unless ["y", "yes", "evet"].include?(ans)
319
-
320
- ctx.out.puts " [Rubik::Goal] Adım bütçesi +20 artırılıyor ve hedef sürdürülüyor..."
321
- goal_state.extend!(goal_state.max_steps + 20)
322
- res = orchestrator.continue_loop(20)
323
- end
324
- res
325
- end
326
-
327
- private_class_method def self.handle_goal_completion(ctx, res:, goal_state:, goal_ledger:,
328
- goal_id:, record_pair:)
329
- if res[:ok]
330
- active = goal_active_subagent_count(ctx)
331
- if active.positive?
332
- # Defense behind the loop-level goal guard (GoalWait): a
333
- # success terminal escaping with live subagents means the
334
- # pipeline is mid-flight — an honest stop beats a false
335
- # "Goal Achieved" (field incident 2026-10-05).
336
- reason = "Goal loop concluded with #{active} active subagent(s) still running — not marked complete"
337
- goal_state.stop!(reason)
338
- finalize_goal_ledger(goal_ledger, goal_state, :stopped)
339
- ctx.out.puts "\n⚠️ [Rubik::Goal] #{reason}."
340
- record_pair.call("[Goal attempt ended after #{goal_state.step_count} steps: #{reason}]", tokens: res[:tokens])
341
- else
342
- goal_state.complete!(res[:output].to_s, tokens: res[:tokens])
343
- finalize_goal_ledger(goal_ledger, goal_state, :completed)
344
- forget_suspended_goal(ctx, goal_id)
345
- ctx.out.puts "\n🎉 Goal Achieved in #{res[:steps]} steps!"
346
- ctx.out.puts res[:output]
347
- # Keep the bang syntax out of the LLM context (Plan 53 D-8): the
348
- # session recorder already stores the literal "!goal ..." for replay.
349
- record_pair.call(res[:output].to_s, streamed: res[:streamed] == true, tokens: res[:tokens])
350
-
351
- ctx.out.puts "\nTip: Use `!diff` to review changes and `!apply` to commit to disk." if ctx.buffer_manager.dirty?
352
- end
353
- else
354
- # Başarısızlık eşlemesi yukarıdaki tek hata kanalından akar:
355
- # GoalState → ledger finalize → kayıtçı çifti, istisna yoluyla
356
- # aynı sırayla.
357
- fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
358
- record_pair: record_pair, reason: res[:error], tokens: res[:tokens], steps: res[:steps])
359
- end
360
- end
361
- # ------------------------------------------------------------------
362
- # !goal resume (issue #106). İki yol, dönüşüm sırasına göre:
363
- # 1) Oturum kaydında canlı girdi varsa süreç-içi resume — hayatta
364
- # kalan Loop örneği canlandırılır (subagent konuşmaları gerçekten
365
- # süreklidir; süpervizör sürecin yaşıyor).
366
- # 2) Yoksa çapraz-süreç Σ-only resume — storage'daki "suspended"
367
- # satırından rehidrasyon. Alt ajan konuşmaları süreçle ölür;
368
- # çıktı bunu tek cümleyle dürüstçe söyler.
369
- private_class_method def self.resume_suspended_goal(ctx)
370
- registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
371
- entry = registry.latest if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
372
- entry ? resume_in_process(ctx, entry) : resume_cross_process(ctx)
373
- end
374
-
375
- private_class_method def self.resume_in_process(ctx, entry)
376
- ctx.recorder&.record_user_turn("!goal resume")
377
- goal_state = entry.goal_state
378
- goal_ledger = entry.ledger
379
- ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
380
- ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, goal_ledger) if goal_ledger
381
- goal_ledger&.unsuspend!
382
- goal_state.resume!
383
- ctx.out.puts "[Rubik::Goal] Resuming '#{entry.goal_text}' (attempt #{entry.attempt + 1}, " \
384
- "suspended: #{entry.reason})"
385
- # Dürüst süreklilik cümlesi: alt ajan konuşmaları süreç-içi
386
- # resume'da yaşar — çapraz-süreç yoldaki tek cümlelik uyarı burada
387
- # YOKTUR (gerçek süreklilik).
388
- record_pair = build_goal_record_pair(ctx, entry.goal_text)
389
- ctx.apply_staged_prune_plan!
390
- drive_goal_turn(ctx, orchestrator: entry.loop, goal_state: goal_state,
391
- goal_ledger: goal_ledger, goal_text: entry.goal_text,
392
- goal_id: entry.goal_id, record_pair: record_pair,
393
- start: lambda { |loop_inst|
394
- loop_inst.resume!(reason: entry.reason,
395
- suspended_at: entry.suspended_at,
396
- attempt: entry.attempt)
397
- })
398
- end
399
-
400
- private_class_method def self.resume_cross_process(ctx)
401
- ctx.recorder&.record_user_turn("!goal resume")
402
- store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
403
- unless store
404
- ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goal in this session; storage unavailable — " \
405
- "cross-process resume honestly refused."
406
- return
407
- end
408
-
409
- row = suspended_rows(store).last
410
- unless row
411
- ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goal found (session registry empty, no 'suspended' Σ rows)."
412
- return
413
- end
414
-
415
- dmesg = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::DMESG)
416
- ledger = Rubik::Orchestrator::GoalLedger::Ledger.load(store: store, storage_id: row.id,
417
- config: ctx.config, dmesg: dmesg,
418
- event_bus: ctx.event_bus)
419
- unless ledger
420
- ctx.out.puts "⚠️ [Rubik::Goal] Suspended goal row #{row.id} could not be rehydrated — " \
421
- "cross-process resume refused (corrupt or non-suspended stamp)."
422
- return
423
- end
424
-
425
- meta = ledger.suspend_meta || {}
426
- goal_text = ledger.snapshot[:objective].to_s
427
- goal_steps = meta["max_steps"].to_i.positive? ? meta["max_steps"].to_i : ctx.config.fetch("agent.goal_max_steps", 100).to_i
428
- warn_ratio = ctx.config.fetch("agent.warn_at_ratio", 0.75).to_f
429
- goal_state = Rubik::Orchestrator::GoalState.new(event_bus: ctx.event_bus)
430
- goal_state.start!(goal_text, goal_steps)
431
- goal_state.restore_counters!(steps: meta["steps"], max_steps: goal_steps,
432
- extensions: meta["extensions"], tokens: meta["tokens"])
433
- goal_state.ledger_id = ledger.snapshot[:storage_id]
434
- ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
435
- ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, ledger)
436
-
437
- routed = ctx.router.route(task_type: :goal, prompt: goal_text)
438
- ctx.runtime_manager.provide(:llm_client, routed[:provider]) if routed[:provider]
439
- orchestrator = ctx.orchestrator_loop(
440
- provider: routed[:provider],
441
- model: routed[:model],
442
- max_steps: goal_steps,
443
- warn_at_ratio: warn_ratio,
444
- context_limit: routed[:context_limit],
445
- max_output_tokens: routed[:max_output_tokens],
446
- on_step: build_goal_on_step(ctx, goal_state)
447
- )
448
-
449
- ctx.out.puts "[Rubik::Goal] Cross-process resume of '#{goal_text}' (attempt #{meta['attempt'].to_i})..."
450
- # Dürüst süreklilik cümlesi (tasarım sözleşmesi): alt ajan
451
- # konuşmaları süreçle öldü; disk etkileri ve session kaydı yaşar.
452
- ctx.out.puts " Subagent conversations did not survive the process restart — their disk " \
453
- "effects and the session record have."
454
- ledger.unsuspend!
455
- record_pair = build_goal_record_pair(ctx, goal_text)
456
- ctx.apply_staged_prune_plan!
457
- drive_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state,
458
- goal_ledger: ledger, goal_text: goal_text,
459
- goal_id: meta["goal_id"].to_s.empty? ? row.id : meta["goal_id"],
460
- record_pair: record_pair,
461
- start: lambda { |loop_inst|
462
- loop_inst.resume_from(goal_text: goal_text, ledger: ledger,
463
- reason: meta["reason"].to_s,
464
- suspended_at: parse_suspended_at(meta["suspended_at"]),
465
- attempt: meta["attempt"].to_i,
466
- counters: { steps: meta["steps"], max_steps: goal_steps,
467
- tokens: meta["tokens"] })
468
- })
469
- end
470
-
471
- # !goal list (issue #106 Faz 2a): store'daki status == "suspended"
472
- # Σ satırları — özetler zaten status taşıyor (Store::Summary).
473
- private_class_method def self.list_suspended_goals(ctx)
474
- ctx.recorder&.record_user_turn("!goal list")
475
- store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
476
- unless store
477
- ctx.out.puts "ℹ️ [Rubik::Goal] Storage unavailable — the suspended-goal list needs goal.ledger storage."
478
- return
479
- end
480
-
481
- rows = suspended_rows(store)
482
- if rows.empty?
483
- ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goals."
484
- return
485
- end
486
-
487
- ctx.out.puts "=== Suspended goals ==="
488
- rows.each do |s|
489
- ctx.out.puts " #{s.id} #{s.updated_at} #{s.title}"
490
- end
491
- ctx.out.puts "Resume the latest with: !goal resume"
492
- end
493
-
494
- # Askı satırları: en eski → en yeni sıralı (updated_at; kuiratör
495
- # list yüzeyiyle aynı alan). Sort anahtarı eşitse row sırası.
496
- private_class_method def self.suspended_rows(store)
497
- store.list(type: "goal").select { |s| s.status == "suspended" }.sort_by(&:updated_at)
498
- end
499
-
500
- # Σ damgası meta'sı (issue #106): {goal_id, steps, max_steps,
501
- # extensions, tokens, reason, suspended_at, attempt}. Sembol
502
- # anahtarlar Ledger#suspend! içinde dizgeleştirilir.
503
- private_class_method def self.suspend_stamp_meta(goal_state, goal_id, reason, attempt)
504
- { goal_id: goal_id, steps: goal_state.step_count, max_steps: goal_state.max_steps,
505
- extensions: goal_state.extensions, tokens: goal_state.tokens.dup,
506
- reason: reason.to_s.slice(0, 300), suspended_at: Time.now.utc.iso8601, attempt: attempt }
507
- end
508
-
509
- private_class_method def self.suspended_attempt(ctx, goal_id)
510
- registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
511
- registry&.fetch(goal_id)&.attempt.to_i
512
- end
513
-
514
- # Oturum kaydı coeffect'i: ilk askıda provide edilir (provide-swap
515
- # semantiği — Context#provide anahtar başına TEK delete-inverse
516
- # tutar; tekrarlanan suspend/resume Ω'yı büyütmez).
517
- private_class_method def self.goal_registry_for(ctx)
518
- registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
519
- return registry if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
520
-
521
- registry = Rubik::Orchestrator::GoalRegistry.new
522
- ctx.runtime_manager&.provide(Rubik::Coeffects::GOAL_REGISTRY, registry)
523
- registry
524
- end
525
-
526
- # Terminal yollarda girdi temizliği: kayıt SADECE sağlanmışsa —
527
- # askı hiç yaşanmamış bir koşunun terminali boş registry provide
528
- # ETMEMELİ (Ω disiplini).
529
- private_class_method def self.forget_suspended_goal(ctx, goal_id)
530
- registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
531
- registry.delete(goal_id) if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
532
- end
533
-
534
- # Adım olayı lambda'sı (start + cross-process resume ortak): sayaç
535
- # akışı, kayıtçı tool çiftleri, render — start yolundaki satır içi
536
- # gövdenin birebir taşınması.
537
- private_class_method def self.build_goal_on_step(ctx, goal_state)
538
- lambda { |step_info|
539
- # Adım sayacı rubik://goal/state'e aksın: olaylar bir adım
540
- # içinde tekrarlanabilir, GoalState monotoniktir (zararsız).
541
- goal_state.update_steps(step_info[:step], step_info[:max_steps]) if step_info[:step].is_a?(Integer)
542
- # Session teşhis edilebilirliği (field incident 2026-10-12):
543
- # saatler süren !goal koşuları session dosyasına tek satır
544
- # düşürüyordu — free-text turn simetrisinde tool adımları
545
- # kayıtçıya akar; render ve LLM geçmişi değişmez.
546
- case step_info[:type]&.to_sym
547
- when :tool_call
548
- ctx.recorder&.record_tool_call(step_info[:tool], step_info[:args], call_id: step_info[:call_id])
549
- when :tool_result
550
- ctx.recorder&.record_tool_result(step_info[:tool], step_info[:output], status: step_info[:status] || :ok, call_id: step_info[:call_id])
551
- end
552
- ctx.render_step_event(step_info)
553
- }
554
- end
555
-
556
- # Plan 53 D-8 yardımcısı: nötr çift + kayıtçı eşlemesi tek yerde.
557
- # Session restore kayıtçı OLAYLARINDAN hidrate eder — eşlenmiş
558
- # restore için conversation_history VE record_assistant_response
559
- # birlikte yazılmalı (başarısızlıkta da).
560
- private_class_method def self.build_goal_record_pair(ctx, goal_text)
561
- lambda do |assistant_content, streamed: nil, tokens: nil|
562
- ctx.conversation_history << { role: "user", content: "Goal: #{goal_text}" }
563
- ctx.conversation_history << { role: "assistant", content: assistant_content }
564
- ctx.recorder&.record_assistant_response(assistant_content, tokens: tokens, streamed: streamed)
565
- ctx.trim_conversation_window!
566
- end
567
- end
568
-
569
- # Damga meta'sındaki suspended_at (iso8601) → Time; bozuk değer
570
- # nil — Loop#append_resume_marker! "unknown" downtime basar.
571
- private_class_method def self.parse_suspended_at(value)
572
- Time.iso8601(value.to_s)
573
- rescue ArgumentError, TypeError
574
- nil
575
- end
576
-
577
- # Defense-in-depth behind the loop-level goal guard: if a success
578
- # terminal escapes GoalWait with live subagent units, the goal must
579
- # stop honestly instead of celebrating a false completion. Fails
580
- # CONSERVATIVE: coeffect absence is nil-safe (Coeffects.get never
581
- # raises for a missing subsystem), so a raise here is real breakage
582
- # — reporting zero would launder it into exactly the false
583
- # "Goal Achieved" this backstop exists to refuse.
584
- private_class_method def self.goal_active_subagent_count(ctx)
585
- supervisor = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::SUBAGENT_SUPERVISOR)
586
- supervisor&.active_count.to_i
587
- rescue StandardError => e
588
- Rubik::Log.warn(:orchestrator, "goal completion defense could not inspect subagents " \
589
- "(#{e.class}: #{e.message}); refusing completion")
590
- 1
591
- end
592
-
593
130
  private_class_method def self.register_test_command(shell)
594
131
  shell.register_command("test", description: "Run test suite via active language adapter") do |args, ctx|
595
132
  if ctx.buffer_manager&.dirty?
@@ -66,7 +66,7 @@ module Rubik
66
66
  if target_path && !target_path.empty?
67
67
  rel = begin
68
68
  ctx.buffer_manager.sanitize_path(target_path)
69
- rescue
69
+ rescue Rubik::Buffer::InvalidPathError
70
70
  target_path
71
71
  end
72
72
  if ctx.buffer_manager.dirty_files.key?(rel)
@@ -219,7 +219,7 @@ module Rubik
219
219
 
220
220
  begin
221
221
  ctx.indexer_thread.join(0.2)
222
- rescue
222
+ rescue StandardError
223
223
  nil
224
224
  end
225
225
  end
@@ -96,7 +96,7 @@ module Rubik
96
96
  # Push non-empty command to history
97
97
  @reline::HISTORY.push(line) if !prompt_grace_interactive? && !line.strip.empty? && line != begin
98
98
  @reline::HISTORY.to_a.last
99
- rescue
99
+ rescue StandardError
100
100
  nil
101
101
  end
102
102
 
@@ -143,6 +143,9 @@ module Rubik
143
143
  # never forces async warm in tests.
144
144
  warm_async = Platform.async_knob(@config, "ast.async_warm")
145
145
  maybe_warn_huge_root!
146
+ # Boot accumulated config problems (unknown keys, corrupt YAML, legacy
147
+ # env vars) surface here — same notices seam, still before the banner.
148
+ maybe_emit_config_warnings!
146
149
  # A strong huge-root signal skips the boot warm walk: the index
147
150
  # stays empty and tools answer the honest not-ready message until
148
151
  # an explicit '!context scan' opts in. Warning only — never a block.
@@ -221,6 +224,31 @@ module Rubik
221
224
  !@config.fetch("context.boot_scan_on_huge_root", false)
222
225
  end
223
226
 
227
+ # Boot-time config observability (issue #399): Config#warnings
228
+ # accumulates unknown-key, corrupt-YAML, ~/.rubik and env-deprecation
229
+ # problems during load with no reader; this surfaces them through the
230
+ # notices seam right after the huge-root check, before the banner.
231
+ # Once per REPL process boot — warnings appended later in the session
232
+ # (runtime set()) stay in the array for !config/tests without printing.
233
+ # Rubik::Log.warn mirrors each notice so headless/scripted boots see
234
+ # them on stderr too.
235
+ def maybe_emit_config_warnings!
236
+ warnings = @config&.warnings
237
+ return if warnings.nil? || warnings.empty?
238
+ return if @config_warnings_shown
239
+
240
+ @config_warnings_shown = true
241
+ warnings.each do |w|
242
+ line = "⚠ Config: #{w}"
243
+ Rubik::Log.warn(:config, line)
244
+ if @terminal_guard
245
+ @terminal_guard.print_safe_notice(line)
246
+ else
247
+ @output&.puts line
248
+ end
249
+ end
250
+ end
251
+
224
252
  # Async MCP boot progress notices (mcp-async-boot D8): subscribe BEFORE
225
253
  # the boot triggers so no event is missed, with the unsubscribe inverse
226
254
  # registered in the same breath (wire_subagent_events! pattern). Async