rubik 0.10.0 → 0.12.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.
- checksums.yaml +4 -4
- data/ATTRIBUTION.md +1 -1
- data/CHANGELOG.md +117 -1
- data/lib/rubik/ast/extractor.rb +2 -1
- data/lib/rubik/ast/treesitter_extractor.rb +2 -1
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +2 -1
- data/lib/rubik/buffer/manager.rb +3 -3
- data/lib/rubik/config/deep_ops.rb +3 -1
- data/lib/rubik/config/defaults.rb +8 -8
- data/lib/rubik/config/schema.rb +7 -0
- data/lib/rubik/config/secret_policy.rb +20 -10
- data/lib/rubik/config/store.rb +2 -1
- data/lib/rubik/config.rb +3 -3
- data/lib/rubik/context/ignore_rules.rb +193 -0
- data/lib/rubik/context/scanner.rb +46 -161
- data/lib/rubik/llm/anthropic.rb +2 -1
- data/lib/rubik/llm/client.rb +28 -206
- data/lib/rubik/llm/connection_pool.rb +104 -0
- data/lib/rubik/llm/formatter.rb +4 -1
- data/lib/rubik/llm/ollama.rb +2 -1
- data/lib/rubik/llm/openai_compatible.rb +2 -1
- data/lib/rubik/llm/registry.rb +3 -2
- data/lib/rubik/llm/router.rb +6 -1
- data/lib/rubik/llm/sse_parser.rb +113 -0
- data/lib/rubik/lsp/circuit_breaker.rb +98 -0
- data/lib/rubik/lsp/client_provisioner.rb +49 -0
- data/lib/rubik/lsp/manager.rb +55 -88
- data/lib/rubik/mcp/manager.rb +39 -14
- data/lib/rubik/mcp/proxy_tool.rb +2 -2
- data/lib/rubik/mcp/transport/stdio.rb +3 -2
- data/lib/rubik/orchestrator/auto_apply.rb +4 -3
- data/lib/rubik/orchestrator/goal_ledger/ledger.rb +12 -1
- data/lib/rubik/orchestrator/goal_ledger/schema_vocabulary.rb +38 -0
- data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +6 -1
- data/lib/rubik/orchestrator/goal_ledger.rb +1 -0
- data/lib/rubik/orchestrator/goal_state.rb +6 -2
- data/lib/rubik/orchestrator/loop.rb +30 -6
- data/lib/rubik/orchestrator/lsp_feedback.rb +1 -1
- data/lib/rubik/orchestrator/provider_resolver.rb +12 -0
- data/lib/rubik/orchestrator/step_executor.rb +2 -1
- data/lib/rubik/orchestrator/subagent/notices.rb +2 -2
- data/lib/rubik/orchestrator/subagent/step_runner.rb +7 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/platform/filesystem.rb +2 -2
- data/lib/rubik/platform/io_drain.rb +3 -1
- data/lib/rubik/plugin/storage.rb +8 -8
- data/lib/rubik/repair/loop.rb +1 -1
- data/lib/rubik/repl/config_wiring.rb +5 -3
- data/lib/rubik/repl/input_execution.rb +147 -7
- data/lib/rubik/repl/lifecycle.rb +1 -1
- data/lib/rubik/repl/shell.rb +9 -1
- data/lib/rubik/repl/tee_io.rb +2 -1
- data/lib/rubik/runtime/ast_service.rb +2 -1
- data/lib/rubik/runtime/fiber.rb +1 -0
- data/lib/rubik/runtime/manager.rb +4 -1
- data/lib/rubik/runtime/overlay_storage.rb +17 -17
- data/lib/rubik/runtime/task_manager.rb +4 -4
- data/lib/rubik/sandbox/driver/base.rb +7 -0
- data/lib/rubik/sandbox/driver/docker.rb +1 -4
- data/lib/rubik/sandbox/driver/podman.rb +1 -0
- data/lib/rubik/sandbox/runner.rb +6 -5
- data/lib/rubik/security/audit_log.rb +2 -1
- data/lib/rubik/security/classifier/classifier.rb +2 -0
- data/lib/rubik/security/command_gate.rb +11 -152
- data/lib/rubik/security/guard.rb +1 -1
- data/lib/rubik/security/secret_store.rb +32 -3
- data/lib/rubik/security/segment_report.rb +161 -0
- data/lib/rubik/session/recorder.rb +2 -1
- data/lib/rubik/skills/manager.rb +2 -1
- data/lib/rubik/storage/store.rb +4 -1
- data/lib/rubik/storage/transcript_indexer.rb +3 -2
- data/lib/rubik/storage/vakanuvis.rb +2 -1
- data/lib/rubik/tools/builtins/goal_ledger.rb +12 -1
- data/lib/rubik/tools/builtins/synthesis.rb +3 -3
- data/lib/rubik/tools/preflight_runner.rb +2 -1
- data/lib/rubik/tools/registry.rb +36 -16
- data/lib/rubik/tools/uri_resolver.rb +3 -2
- data/lib/rubik/ui/capability.rb +7 -4
- data/lib/rubik/ui/markdown_stream.rb +1 -0
- data/lib/rubik/ui/renderer.rb +4 -2
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +3 -3
- metadata +8 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "stringio"
|
|
4
|
+
require_relative "../log"
|
|
4
5
|
require_relative "tee_io"
|
|
5
6
|
require_relative "../storage/layout"
|
|
6
7
|
|
|
@@ -161,6 +162,10 @@ module Rubik
|
|
|
161
162
|
# an unbound read would mask the in-flight exception with a
|
|
162
163
|
# NameError, breaking the "cleanup must never mask" contract.
|
|
163
164
|
interrupted = false
|
|
165
|
+
# Resume bayatlaşması: kullanıcı yeni bir görev yazdıysa duraklatılmış
|
|
166
|
+
# turn teklifi geçersizdir (otonom notice turn'i stash'i ezmez —
|
|
167
|
+
# kullanıcının "devam et"i bir notice turn'ine kurban edilmesin).
|
|
168
|
+
@resumable_turn = nil unless @autonomous_turn
|
|
164
169
|
task = start_free_text_turn!(text)
|
|
165
170
|
renderer = md_stream = orchestrator = nil
|
|
166
171
|
routed = route_free_text!(text)
|
|
@@ -291,7 +296,22 @@ module Rubik
|
|
|
291
296
|
def run_free_text_loop(orchestrator, text)
|
|
292
297
|
@active_loop = orchestrator
|
|
293
298
|
res = orchestrator.run(text, conversation_history: @conversation_history)
|
|
299
|
+
drive_budget_continuations!(orchestrator, res)
|
|
300
|
+
end
|
|
294
301
|
|
|
302
|
+
# Resume koşusu: ölü turn'in Loop örneği @active_loop olarak
|
|
303
|
+
# yayınlanır (reentrancy guard, run_free_text_loop ile aynı sözleşme)
|
|
304
|
+
# ve taze display kanalı Loop#resume_turn! devam sözleşmesine
|
|
305
|
+
# geçirilir. Sayaçlar ve @history bilinçli korunur.
|
|
306
|
+
def resume_free_text_loop(orchestrator, renderer, md_stream)
|
|
307
|
+
@active_loop = orchestrator
|
|
308
|
+
res = orchestrator.resume_turn!(reason: RESUME_REASON, on_step: turn_step_handler(renderer, md_stream))
|
|
309
|
+
drive_budget_continuations!(orchestrator, res)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# Budget-continue döngüsü (run_free_text_loop'tan çıkarıldı): taze
|
|
313
|
+
# turn ile resume koşusu aynı devam-sorusu kalıbını paylaşır.
|
|
314
|
+
def drive_budget_continuations!(orchestrator, res)
|
|
295
315
|
while !res[:ok] && res[:reason] == :budget_exhausted && Rubik::Storage::Layout.config_get(@config, "agent.ask_continue_on_limit", true)
|
|
296
316
|
@output.puts "\n⚠️ [Rubik::Agent] #{res[:error]}"
|
|
297
317
|
ans = ask_yes_no(" [Rubik::Agent] +20 adım ile devam edilsin mi?", default: "n")
|
|
@@ -312,10 +332,7 @@ module Rubik
|
|
|
312
332
|
# conversation_history'ye kopyala — böylece continue'da model turn sırasındaki
|
|
313
333
|
# bağlamı görür ve "sıfırdan keşfe" başlamaz. res[:loop_instance].history,
|
|
314
334
|
# turn_result'ın döndürdüğü Loop örneğinin @history'sidir.
|
|
315
|
-
|
|
316
|
-
res[:loop_instance]&.history,
|
|
317
|
-
max_entries: Rubik::Storage::Layout.config_get(@config, "context.merge_turn_tool_max_entries", 20).to_i
|
|
318
|
-
)
|
|
335
|
+
merge_unseen_turn_tool_history!(res[:loop_instance])
|
|
319
336
|
|
|
320
337
|
if res[:ok]
|
|
321
338
|
record_turn_outcome!(text, res[:output].to_s, tokens: res[:tokens], streamed: res[:streamed] == true)
|
|
@@ -344,6 +361,125 @@ module Rubik
|
|
|
344
361
|
end
|
|
345
362
|
end
|
|
346
363
|
|
|
364
|
+
# Turn-exit tool-history merge for non-settle exits (LLM error,
|
|
365
|
+
# unexpected error, ^C). Same policy as settle_free_text_result!'s
|
|
366
|
+
# merge: the loop's in-turn @history carries the tool steps the next
|
|
367
|
+
# turn needs, and merge_turn_tool_history!'s own contract is
|
|
368
|
+
# path-independent ("hata veya başarı fark etmez"). Without this the
|
|
369
|
+
# failure handlers persist only the 15-line chronicle, and "devam et"
|
|
370
|
+
# after a mid-run LLM error makes the model re-discover terrain from
|
|
371
|
+
# a summary instead of the actual last tool results (2026-11-16
|
|
372
|
+
# field report: [41/50] Net::ReadTimeout → re-discovery turn).
|
|
373
|
+
# Ordering contract: call AFTER record_failed_turn! — the outcome
|
|
374
|
+
# text (user + failure pair) must lead the window, otherwise trim's
|
|
375
|
+
# leading-role guard evicts the freshly merged tool messages on a
|
|
376
|
+
# fresh/empty conversation window (first-turn failure).
|
|
377
|
+
def merge_failed_turn_tool_history!(orchestrator)
|
|
378
|
+
return unless orchestrator.respond_to?(:history)
|
|
379
|
+
|
|
380
|
+
merge_unseen_turn_tool_history!(orchestrator)
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
def merge_unseen_turn_tool_history!(loop_instance)
|
|
384
|
+
return unless loop_instance.respond_to?(:history)
|
|
385
|
+
|
|
386
|
+
history = loop_instance.history
|
|
387
|
+
return if history.nil?
|
|
388
|
+
|
|
389
|
+
@merged_history_cursors ||= ObjectSpace::WeakMap.new
|
|
390
|
+
cursor = @merged_history_cursors[loop_instance] || 0
|
|
391
|
+
cursor = 0 if cursor > history.length
|
|
392
|
+
unseen = history[cursor..]
|
|
393
|
+
@merged_history_cursors[loop_instance] = history.length
|
|
394
|
+
return if unseen.nil? || unseen.empty?
|
|
395
|
+
|
|
396
|
+
merge_turn_tool_history!(
|
|
397
|
+
unseen,
|
|
398
|
+
max_entries: Rubik::Storage::Layout.config_get(@config, "context.merge_turn_tool_max_entries", 20).to_i
|
|
399
|
+
)
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# ── Hata-sonrası turn resume (2026-11-16) ──────────────────────────
|
|
403
|
+
# LLM hatasıyla ölen serbest-metin turn'i, taze Loop kurulMADAN aynı
|
|
404
|
+
# Loop örneği üzerinden sürdürülebilir: Loop örneği @resumable_turn'te
|
|
405
|
+
# saklanır, kullanıcı resume-niyetinde bir satır yazdığında
|
|
406
|
+
# Loop#resume_turn! devam sözleşmesi (continue_loop/resume! ile aynı
|
|
407
|
+
# execute_steps yolu) işletilir — aynı @history, aynı adım bütçesi
|
|
408
|
+
# (kullanıcının !steps extend'i dahil). Amaç-eşleşmesi BİREBİRDİR:
|
|
409
|
+
# substring eşleşmesi yeni bir görevi yanlışlıkla resume sanabilir.
|
|
410
|
+
RESUME_INTENTS = ["devam et", "devam", "continue", "sürdür"].freeze
|
|
411
|
+
RESUME_PROMPT = "devam et"
|
|
412
|
+
RESUME_REASON = "llm_error_recovery"
|
|
413
|
+
|
|
414
|
+
def resumable_turn? = !!@resumable_turn
|
|
415
|
+
|
|
416
|
+
# Trailing punctuation allowed after a resume phrase ("devam!…"). Kept as
|
|
417
|
+
# a plain string used with #include? — a /[…]+\z/ regex strip on
|
|
418
|
+
# uncontrolled input is a polynomial-ReDoS hazard (CodeQL rb/polynomial-redos).
|
|
419
|
+
RESUME_TRAILING_PUNCT = ".!?…"
|
|
420
|
+
|
|
421
|
+
def resume_intent?(raw)
|
|
422
|
+
return false unless @resumable_turn
|
|
423
|
+
|
|
424
|
+
s = raw.to_s.strip.downcase
|
|
425
|
+
idx = s.length - 1
|
|
426
|
+
idx -= 1 while idx >= 0 && RESUME_TRAILING_PUNCT.include?(s[idx])
|
|
427
|
+
# s[0, idx + 1] — NOT s[0..idx]: with idx == -1 a range slice returns
|
|
428
|
+
# the WHOLE string ("!!!"[0..-1] == "!!!"); length-form never does.
|
|
429
|
+
RESUME_INTENTS.include?(s[0, idx + 1])
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
# Most-recent-wins: yeni bir turn hatayla ölürse önceki resumable'ın
|
|
433
|
+
# yerine geçer. execute_free_text, otonom notice turn'leri hariç,
|
|
434
|
+
# stash'i temizler (kullanıcı yeni görev seçtiyse resume teklifi
|
|
435
|
+
# bayatlaşır); bir turn başarısız olduktan sonra tekrar dolar.
|
|
436
|
+
def stash_resumable_turn!(orchestrator)
|
|
437
|
+
return false unless orchestrator.respond_to?(:resume_turn!) && orchestrator.respond_to?(:history)
|
|
438
|
+
|
|
439
|
+
@resumable_turn = { loop: orchestrator }
|
|
440
|
+
true
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
def stash_and_announce_resume!(orchestrator)
|
|
444
|
+
return unless stash_resumable_turn!(orchestrator)
|
|
445
|
+
|
|
446
|
+
@output.puts "[Rubik] Turn duraklatıldı (adım #{orchestrator.step_count}/#{orchestrator.max_steps}). " \
|
|
447
|
+
"'devam et' yazarsan aynı bağlam ve adım bütçesiyle sürer; başka bir şey yazarsan yeni görev olarak koşar."
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
# Duraklatılmış turn'in yeniden koşusu: taze turn yaşam döngüsünü
|
|
451
|
+
# (arming → display → settle → rescue merdiveni → ensure teardown)
|
|
452
|
+
# resume sözleşmesiyle birleştirir. Kullanıcının yazdığı satır
|
|
453
|
+
# recorder'a ve konuşma hafızasına "devam et" olarak düşer — dürüst
|
|
454
|
+
# provenance; orijinal görev metni Loop'un kendi @history'sinde
|
|
455
|
+
# yaşamaya devam eder ve modele tekrar gönderilmez.
|
|
456
|
+
def execute_resumed_turn!
|
|
457
|
+
rt = @resumable_turn
|
|
458
|
+
@resumable_turn = nil
|
|
459
|
+
return false unless rt
|
|
460
|
+
|
|
461
|
+
interrupted = false
|
|
462
|
+
orchestrator = rt[:loop]
|
|
463
|
+
task = start_free_text_turn!(RESUME_PROMPT)
|
|
464
|
+
renderer = md_stream = nil
|
|
465
|
+
begin
|
|
466
|
+
theme = self.theme
|
|
467
|
+
renderer, md_stream, md_enabled = build_turn_display(theme, orchestrator.max_steps)
|
|
468
|
+
res = resume_free_text_loop(orchestrator, renderer, md_stream)
|
|
469
|
+
settle_free_text_result!(RESUME_PROMPT, res, orchestrator: orchestrator, theme: theme, md_enabled: md_enabled)
|
|
470
|
+
rescue Interrupt
|
|
471
|
+
interrupted = true
|
|
472
|
+
handle_interrupted_free_text!(RESUME_PROMPT, task, orchestrator)
|
|
473
|
+
rescue Rubik::LLM::ClientError => e
|
|
474
|
+
handle_llm_client_error!(RESUME_PROMPT, e, orchestrator)
|
|
475
|
+
rescue StandardError => e
|
|
476
|
+
handle_unexpected_error!(RESUME_PROMPT, e, orchestrator)
|
|
477
|
+
ensure
|
|
478
|
+
teardown_free_text_turn!(interrupted, orchestrator, renderer, md_stream)
|
|
479
|
+
end
|
|
480
|
+
true
|
|
481
|
+
end
|
|
482
|
+
|
|
347
483
|
# Interrupt rescue body: the user cancelled — queued wake debts settle
|
|
348
484
|
# here. Each queued notice already lives in @conversation_history (idle
|
|
349
485
|
# path injects at route time), so draining loses nothing the model
|
|
@@ -364,6 +500,7 @@ module Rubik
|
|
|
364
500
|
"reason" => "Interrupted by user (^C)")
|
|
365
501
|
@output.puts "\n⚠️ [Rubik::Agent] Görev kullanıcı tarafından iptal edildi (^C)."
|
|
366
502
|
record_failed_turn!(text, "cancelled", "Interrupted by user (^C)", orchestrator)
|
|
503
|
+
merge_failed_turn_tool_history!(orchestrator)
|
|
367
504
|
end
|
|
368
505
|
|
|
369
506
|
# LLM::ClientError rescue body. e.message may carry binary bytes (raw
|
|
@@ -375,6 +512,8 @@ module Rubik
|
|
|
375
512
|
message = Rubik::Platform.safe_utf8(error.message)
|
|
376
513
|
@output.puts "[Rubik::LLM Hatası] #{message}"
|
|
377
514
|
record_failed_turn!(text, "failed", message, orchestrator)
|
|
515
|
+
merge_failed_turn_tool_history!(orchestrator)
|
|
516
|
+
stash_and_announce_resume!(orchestrator) unless @autonomous_turn
|
|
378
517
|
end
|
|
379
518
|
|
|
380
519
|
# StandardError rescue body: same binary-byte sanitization as the LLM
|
|
@@ -383,6 +522,7 @@ module Rubik
|
|
|
383
522
|
message = Rubik::Platform.safe_utf8(error.message)
|
|
384
523
|
@output.puts "[Hata] #{error.class}: #{message}"
|
|
385
524
|
record_failed_turn!(text, "failed", "#{error.class}: #{message}", orchestrator)
|
|
525
|
+
merge_failed_turn_tool_history!(orchestrator)
|
|
386
526
|
end
|
|
387
527
|
|
|
388
528
|
# Ensure-phase teardown. Cleanup must never mask the in-flight exception
|
|
@@ -398,7 +538,7 @@ module Rubik
|
|
|
398
538
|
begin
|
|
399
539
|
md_stream&.finish { |seg| @output.print seg }
|
|
400
540
|
rescue StandardError => e
|
|
401
|
-
warn "[rubik] markdown tail flush failed: #{e.class}: #{e.message}"
|
|
541
|
+
Rubik::Log.warn(:repl, "[rubik] markdown tail flush failed: #{e.class}: #{e.message}")
|
|
402
542
|
end
|
|
403
543
|
kill_spinner!(renderer&.spinner)
|
|
404
544
|
flush_subagent_notices! if respond_to?(:flush_subagent_notices!)
|
|
@@ -427,7 +567,7 @@ module Rubik
|
|
|
427
567
|
|
|
428
568
|
supervisor.cancel_owned(task, timeout: Rubik::Storage::Layout.config_get(@config, "subagents.cancel_timeout", 2.0))
|
|
429
569
|
rescue StandardError => e
|
|
430
|
-
warn "[rubik] task cancellation failed: #{e.class}: #{e.message}"
|
|
570
|
+
Rubik::Log.warn(:repl, "[rubik] task cancellation failed: #{e.class}: #{e.message}")
|
|
431
571
|
nil
|
|
432
572
|
end
|
|
433
573
|
|
|
@@ -455,7 +595,7 @@ module Rubik
|
|
|
455
595
|
def kill_spinner!(spinner)
|
|
456
596
|
spinner&.kill
|
|
457
597
|
rescue StandardError => e
|
|
458
|
-
warn "[rubik] spinner cleanup failed: #{e.class}: #{e.message}"
|
|
598
|
+
Rubik::Log.warn(:repl, "[rubik] spinner cleanup failed: #{e.class}: #{e.message}")
|
|
459
599
|
end
|
|
460
600
|
|
|
461
601
|
# Command-dispatch spinner cleanup (both branches).
|
data/lib/rubik/repl/lifecycle.rb
CHANGED
data/lib/rubik/repl/shell.rb
CHANGED
|
@@ -201,7 +201,15 @@ module Rubik
|
|
|
201
201
|
when :command
|
|
202
202
|
execute_command(parsed)
|
|
203
203
|
when :prompt
|
|
204
|
-
|
|
204
|
+
# Hata-sonrası turn resume: duraklatılmış bir turn varsa ve satır
|
|
205
|
+
# birebir resume niyeti taşıyorsa taze Loop kurulmaz — aynı Loop
|
|
206
|
+
# örneği, aynı @history ve adım bütçesiyle sürer (stash yoksa
|
|
207
|
+
# "devam et" sıradan bir serbest-metin görevi olarak koşar).
|
|
208
|
+
if resume_intent?(parsed.raw)
|
|
209
|
+
execute_resumed_turn!
|
|
210
|
+
else
|
|
211
|
+
execute_free_text(parsed.raw)
|
|
212
|
+
end
|
|
205
213
|
end
|
|
206
214
|
|
|
207
215
|
check_dirty_buffer_reminder unless @replaying
|
data/lib/rubik/repl/tee_io.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../log"
|
|
3
4
|
require_relative "../ui/capability"
|
|
4
5
|
|
|
5
6
|
module Rubik
|
|
@@ -94,7 +95,7 @@ module Rubik
|
|
|
94
95
|
|
|
95
96
|
def drop_failed_target(target, method, exception)
|
|
96
97
|
@targets.delete(target)
|
|
97
|
-
warn "[rubik] tee target failed during ##{method} (#{exception.class}: #{exception.message}); detached from output"
|
|
98
|
+
Rubik::Log.warn(:repl, "[rubik] tee target failed during ##{method} (#{exception.class}: #{exception.message}); detached from output")
|
|
98
99
|
end
|
|
99
100
|
|
|
100
101
|
def strip_args(args)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../log"
|
|
3
4
|
require_relative "../ast"
|
|
4
5
|
require_relative "../coeffects"
|
|
5
6
|
require_relative "service_registration"
|
|
@@ -24,7 +25,7 @@ module Rubik
|
|
|
24
25
|
# Report but keep draining: a failed cache save must not abort
|
|
25
26
|
# the LIFO unwind, and silence here would leak a stale symbol
|
|
26
27
|
# cache with no trace.
|
|
27
|
-
warn "[ASTService] cache save failed: #{e.class}: #{e.message}"
|
|
28
|
+
Rubik::Log.warn(:ast, "[ASTService] cache save failed: #{e.class}: #{e.message}")
|
|
28
29
|
end
|
|
29
30
|
ast_graph.clear if ast_graph.respond_to?(:clear)
|
|
30
31
|
end
|
data/lib/rubik/runtime/fiber.rb
CHANGED
|
@@ -185,6 +185,8 @@ module Rubik
|
|
|
185
185
|
return unless deferred
|
|
186
186
|
|
|
187
187
|
@retry_gate.attempt(deferred) do |fiber|
|
|
188
|
+
next unless @fibers[fiber.name].equal?(fiber) && fiber.state != :disposed
|
|
189
|
+
|
|
188
190
|
with_activation_marker(fiber) { fiber.activate!(@context) }
|
|
189
191
|
end
|
|
190
192
|
end
|
|
@@ -241,7 +243,8 @@ module Rubik
|
|
|
241
243
|
# fibers react to canonical re-provides instead of holding stale
|
|
242
244
|
# service instances.
|
|
243
245
|
def fiber_depends_on_service?(fiber, changed_key)
|
|
244
|
-
|
|
246
|
+
canonical_changed = Rubik::Coeffects.canonical(changed_key)
|
|
247
|
+
fiber.inject.any? { |dep| dep == changed_key || Rubik::Coeffects.canonical(dep) == canonical_changed }
|
|
245
248
|
end
|
|
246
249
|
end
|
|
247
250
|
end
|
|
@@ -79,7 +79,7 @@ module Rubik
|
|
|
79
79
|
[project_commands_dir, global_commands_dir, project_tools_dir, global_tools_dir].each do |dir|
|
|
80
80
|
FileUtils.mkdir_p(dir)
|
|
81
81
|
rescue SystemCallError => e
|
|
82
|
-
warn "[WARN] Failed to create overlay directory #{dir}: #{e.message}" if ENV["RUBIK_DEBUG"]
|
|
82
|
+
Rubik::Log.warn(:overlay, "[WARN] Failed to create overlay directory #{dir}: #{e.message}") if ENV["RUBIK_DEBUG"]
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
|
|
@@ -112,7 +112,7 @@ module Rubik
|
|
|
112
112
|
return :trusted if @overlay_guard.trust_mode?
|
|
113
113
|
|
|
114
114
|
unless @overlay_guard.safe_path_under?(file_path, dir)
|
|
115
|
-
warn "[SECURITY] Path traversal attempt detected for overlay '#{file_path}'. Skipping."
|
|
115
|
+
Rubik::Log.warn(:overlay, "[SECURITY] Path traversal attempt detected for overlay '#{file_path}'. Skipping.")
|
|
116
116
|
return :rejected
|
|
117
117
|
end
|
|
118
118
|
|
|
@@ -128,8 +128,8 @@ module Rubik
|
|
|
128
128
|
# Constant-time comparison policy is single-homed in ManifestStore
|
|
129
129
|
# (issue #426), same as plugin verification.
|
|
130
130
|
expected_hash = manifest[basename]["sha256"]
|
|
131
|
-
warn "[SECURITY] Integrity check failed for overlay '#{basename}': file modified " \
|
|
132
|
-
|
|
131
|
+
Rubik::Log.warn(:overlay, "[SECURITY] Integrity check failed for overlay '#{basename}': file modified " \
|
|
132
|
+
"since synthesis. Skipping. (expected: #{expected_hash}, got: #{current_hash})")
|
|
133
133
|
:rejected
|
|
134
134
|
when :unknown
|
|
135
135
|
if bootstrap_eligible && sentinel_content?(current_content)
|
|
@@ -152,7 +152,7 @@ module Rubik
|
|
|
152
152
|
save_manifest(dir, manifest)
|
|
153
153
|
:bootstrapped
|
|
154
154
|
else
|
|
155
|
-
warn "[SECURITY] Unknown overlay file '#{basename}' not in manifest. Skipping."
|
|
155
|
+
Rubik::Log.warn(:overlay, "[SECURITY] Unknown overlay file '#{basename}' not in manifest. Skipping.")
|
|
156
156
|
:rejected
|
|
157
157
|
end
|
|
158
158
|
end
|
|
@@ -208,7 +208,7 @@ module Rubik
|
|
|
208
208
|
if proc_handler.arity == 1
|
|
209
209
|
proc_handler.call(args)
|
|
210
210
|
elsif proc_handler.arity == 2
|
|
211
|
-
warn "[rubik] overlay command invoked without a dispatch CommandContext" unless ctx || ENV["RUBIK_TEST"]
|
|
211
|
+
Rubik::Log.warn(:overlay, "[rubik] overlay command invoked without a dispatch CommandContext") unless ctx || ENV["RUBIK_TEST"]
|
|
212
212
|
sealed_ctx = if ctx.is_a?(Rubik::REPL::SynthesizedCommandContext)
|
|
213
213
|
ctx
|
|
214
214
|
else
|
|
@@ -245,7 +245,7 @@ module Rubik
|
|
|
245
245
|
out_ctx = if ctx
|
|
246
246
|
ctx
|
|
247
247
|
elsif shell.respond_to?(:command_context)
|
|
248
|
-
warn "[rubik] overlay command invoked without a dispatch CommandContext" unless ENV["RUBIK_TEST"]
|
|
248
|
+
Rubik::Log.warn(:overlay, "[rubik] overlay command invoked without a dispatch CommandContext") unless ENV["RUBIK_TEST"]
|
|
249
249
|
shell.command_context
|
|
250
250
|
else
|
|
251
251
|
shell.output
|
|
@@ -292,7 +292,7 @@ module Rubik
|
|
|
292
292
|
# A malformed schema silently claiming "no arguments"
|
|
293
293
|
# hides real overlay bugs; keep loading (the tool is
|
|
294
294
|
# hash-verified) but say so.
|
|
295
|
-
warn "[rubik] overlay tool '#{name}' has a malformed '# Schema:' header; treating as no-arg schema"
|
|
295
|
+
Rubik::Log.warn(:overlay, "[rubik] overlay tool '#{name}' has a malformed '# Schema:' header; treating as no-arg schema")
|
|
296
296
|
{}
|
|
297
297
|
end
|
|
298
298
|
else
|
|
@@ -423,7 +423,7 @@ module Rubik
|
|
|
423
423
|
{ ok: true, path: file_path, name: clean_name, scope: scope }
|
|
424
424
|
rescue StandardError => e
|
|
425
425
|
# Audit 1: surfaced to the caller as ok:false; tool kind logs under RUBIK_DEBUG.
|
|
426
|
-
warn "[WARN] [OVERLAY] Failed to save #{kind.label} '#{name}' to #{file_path}: #{e.class}: #{e.message}" if kind.debug_warn && ENV["RUBIK_DEBUG"]
|
|
426
|
+
Rubik::Log.warn(:overlay, "[WARN] [OVERLAY] Failed to save #{kind.label} '#{name}' to #{file_path}: #{e.class}: #{e.message}") if kind.debug_warn && ENV["RUBIK_DEBUG"]
|
|
427
427
|
{ ok: false, error: e.message }
|
|
428
428
|
end
|
|
429
429
|
|
|
@@ -470,10 +470,10 @@ module Rubik
|
|
|
470
470
|
if yield(name, code, meta[:scope])
|
|
471
471
|
loaded << name
|
|
472
472
|
elsif kind.warn_on_unusable
|
|
473
|
-
warn "[OVERLAY] Custom #{kind.label} '#{name}' from #{file_path} did not evaluate to a usable tool."
|
|
473
|
+
Rubik::Log.warn(:overlay, "[OVERLAY] Custom #{kind.label} '#{name}' from #{file_path} did not evaluate to a usable tool.")
|
|
474
474
|
end
|
|
475
475
|
rescue StandardError => e
|
|
476
|
-
warn "[OVERLAY] Failed to load custom #{kind.label} '#{name}' from #{file_path}: #{e.class}: #{e.message}"
|
|
476
|
+
Rubik::Log.warn(:overlay, "[OVERLAY] Failed to load custom #{kind.label} '#{name}' from #{file_path}: #{e.class}: #{e.message}")
|
|
477
477
|
end
|
|
478
478
|
loaded
|
|
479
479
|
end
|
|
@@ -516,7 +516,7 @@ module Rubik
|
|
|
516
516
|
|
|
517
517
|
case manifest_state(dir)
|
|
518
518
|
when :corrupt
|
|
519
|
-
warn "[SECURITY] Corrupt manifest in #{dir}; skipping #{files.size} overlay(s)."
|
|
519
|
+
Rubik::Log.warn(:overlay, "[SECURITY] Corrupt manifest in #{dir}; skipping #{files.size} overlay(s).")
|
|
520
520
|
[]
|
|
521
521
|
when :missing
|
|
522
522
|
if @overlay_guard.bootstrap_opt_in?
|
|
@@ -527,8 +527,8 @@ module Rubik
|
|
|
527
527
|
{ name: File.basename(f, ".rb"), scope: scope, path: f, integrity: integrity }
|
|
528
528
|
end
|
|
529
529
|
if bootstrapped.positive?
|
|
530
|
-
warn "[BOOTSTRAP] First scan of #{dir}: recorded #{bootstrapped} overlay(s) into .manifest.json; " \
|
|
531
|
-
|
|
530
|
+
Rubik::Log.warn(:overlay, "[BOOTSTRAP] First scan of #{dir}: recorded #{bootstrapped} overlay(s) into .manifest.json; " \
|
|
531
|
+
"unknown files will be rejected from now on.")
|
|
532
532
|
end
|
|
533
533
|
entries
|
|
534
534
|
else
|
|
@@ -536,8 +536,8 @@ module Rubik
|
|
|
536
536
|
# sentinel dosyalar görünür tek satırlık bildirimle atlanır.
|
|
537
537
|
gated = files.count { |f| sentinel_file?(f) }
|
|
538
538
|
if gated.positive?
|
|
539
|
-
warn "[BOOTSTRAP] #{gated} unrecorded sentinel overlay(s) in #{dir} were skipped; " \
|
|
540
|
-
|
|
539
|
+
Rubik::Log.warn(:overlay, "[BOOTSTRAP] #{gated} unrecorded sentinel overlay(s) in #{dir} were skipped; " \
|
|
540
|
+
"first-time acceptance requires RUBIK_BOOTSTRAP_OVERLAYS=1.")
|
|
541
541
|
end
|
|
542
542
|
files.map { |f| { name: File.basename(f, ".rb"), scope: scope, path: f, integrity: verify_integrity(f, dir) } }
|
|
543
543
|
end
|
|
@@ -554,7 +554,7 @@ module Rubik
|
|
|
554
554
|
File.file?(path) && sentinel_content?(File.binread(path))
|
|
555
555
|
rescue StandardError => e
|
|
556
556
|
# Audit 1: unreadable => fail-closed (not a sentinel), but traceable.
|
|
557
|
-
warn "[WARN] [OVERLAY] sentinel check failed for #{path}: #{e.class}: #{e.message}" if ENV["RUBIK_DEBUG"]
|
|
557
|
+
Rubik::Log.warn(:overlay, "[WARN] [OVERLAY] sentinel check failed for #{path}: #{e.class}: #{e.message}") if ENV["RUBIK_DEBUG"]
|
|
558
558
|
false
|
|
559
559
|
end
|
|
560
560
|
|
|
@@ -83,21 +83,21 @@ module Rubik
|
|
|
83
83
|
attr_reader :guard, :context, :root_dir, :max_buffer_lines
|
|
84
84
|
attr_accessor :init
|
|
85
85
|
|
|
86
|
-
@instances =
|
|
86
|
+
@instances = ObjectSpace::WeakMap.new
|
|
87
87
|
@at_exit_installed = false
|
|
88
88
|
|
|
89
89
|
def self.register_instance(mgr)
|
|
90
|
-
@instances
|
|
90
|
+
@instances[mgr] = true
|
|
91
91
|
return if @at_exit_installed
|
|
92
92
|
|
|
93
93
|
@at_exit_installed = true
|
|
94
94
|
at_exit do
|
|
95
95
|
# Error-isolated sweep: one manager's kill_all raising must not
|
|
96
96
|
# leave the remaining managers uncleaned at shutdown.
|
|
97
|
-
@instances.
|
|
97
|
+
@instances.each_key do |mgr|
|
|
98
98
|
mgr.kill_all
|
|
99
99
|
rescue StandardError => e
|
|
100
|
-
warn "[TaskManager] at_exit kill_all failed: #{e.class}: #{e.message}"
|
|
100
|
+
Rubik::Log.warn(:runtime, "[TaskManager] at_exit kill_all failed: #{e.class}: #{e.message}")
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
end
|
|
@@ -4,6 +4,13 @@ module Rubik
|
|
|
4
4
|
module Sandbox
|
|
5
5
|
module Driver
|
|
6
6
|
class Base
|
|
7
|
+
CONTAINER_HARDENING_FLAGS = [
|
|
8
|
+
"--read-only",
|
|
9
|
+
"--cap-drop", "ALL",
|
|
10
|
+
"--security-opt", "no-new-privileges",
|
|
11
|
+
"--tmpfs", "/tmp:rw,noexec,nosuid"
|
|
12
|
+
].freeze
|
|
13
|
+
|
|
7
14
|
attr_reader :options
|
|
8
15
|
|
|
9
16
|
def initialize(options = {})
|
|
@@ -26,10 +26,7 @@ module Rubik
|
|
|
26
26
|
docker_args = [
|
|
27
27
|
"docker", "run", "--rm",
|
|
28
28
|
"--name", container_name,
|
|
29
|
-
|
|
30
|
-
"--cap-drop", "ALL",
|
|
31
|
-
"--security-opt", "no-new-privileges",
|
|
32
|
-
"--tmpfs", "/tmp:rw,noexec,nosuid",
|
|
29
|
+
*CONTAINER_HARDENING_FLAGS,
|
|
33
30
|
"-w", "/workspace",
|
|
34
31
|
"-v", "#{workspace}:/workspace:rw",
|
|
35
32
|
"--memory", "#{memory_limit_mb}m",
|
data/lib/rubik/sandbox/runner.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../log"
|
|
3
4
|
require_relative "driver"
|
|
4
5
|
require_relative "driver/process"
|
|
5
6
|
require_relative "../security/errors"
|
|
@@ -57,7 +58,7 @@ module Rubik
|
|
|
57
58
|
begin
|
|
58
59
|
cleanup.call
|
|
59
60
|
rescue StandardError => e
|
|
60
|
-
warn "[WARN] Sandbox::Runner cleanup failed: #{e.message}"
|
|
61
|
+
Rubik::Log.warn(:sandbox, "[WARN] Sandbox::Runner cleanup failed: #{e.message}")
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
end
|
|
@@ -86,8 +87,8 @@ module Rubik
|
|
|
86
87
|
# previously-merged union (which would leave stale dirs allowed).
|
|
87
88
|
raw_allowed = Rubik::Storage::Layout.config_get(@config, "workspace.allowed_external_dirs", [])
|
|
88
89
|
unless raw_allowed.is_a?(Array)
|
|
89
|
-
warn "[SANDBOX] workspace.allowed_external_dirs must be an Array (got #{raw_allowed.class}); " \
|
|
90
|
-
|
|
90
|
+
Rubik::Log.warn(:sandbox, "[SANDBOX] workspace.allowed_external_dirs must be an Array (got #{raw_allowed.class}); " \
|
|
91
|
+
"treating as empty — the config is authoritative, so stale dirs are revoked.")
|
|
91
92
|
raw_allowed = []
|
|
92
93
|
end
|
|
93
94
|
baseline = @baseline_allowed_dirs || []
|
|
@@ -142,7 +143,7 @@ module Rubik
|
|
|
142
143
|
def verify_chdir_safety!(chdir)
|
|
143
144
|
expanded = File.expand_path(chdir.to_s, @root_dir)
|
|
144
145
|
safe = allowed_paths.any? do |allowed|
|
|
145
|
-
Rubik::Platform.
|
|
146
|
+
Rubik::Platform.resolved_path_under?(expanded, allowed)
|
|
146
147
|
end
|
|
147
148
|
|
|
148
149
|
unless safe
|
|
@@ -163,7 +164,7 @@ module Rubik
|
|
|
163
164
|
return false if cfg_val == false || cfg_val.to_s.downcase == "false"
|
|
164
165
|
|
|
165
166
|
unless cfg_val.nil?
|
|
166
|
-
warn "[SANDBOX] Unparseable sandbox.allow_network value '#{cfg_val}'; defaulting to fail-closed (false)"
|
|
167
|
+
Rubik::Log.warn(:sandbox, "[SANDBOX] Unparseable sandbox.allow_network value '#{cfg_val}'; defaulting to fail-closed (false)")
|
|
167
168
|
return false
|
|
168
169
|
end
|
|
169
170
|
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "time"
|
|
5
5
|
require "fileutils"
|
|
6
|
+
require_relative "../log"
|
|
6
7
|
require_relative "../platform"
|
|
7
8
|
require_relative "redactor"
|
|
8
9
|
|
|
@@ -65,7 +66,7 @@ module Rubik
|
|
|
65
66
|
# Unconditional: an audit trail failing silently is indistinguishable
|
|
66
67
|
# from an operator's intentional disable — the one warn in the guard
|
|
67
68
|
# that must not hide behind RUBIK_DEBUG.
|
|
68
|
-
warn "[WARN] Failed to write audit log #{@audit_log_path}: #{e.message}"
|
|
69
|
+
Rubik::Log.warn(:security, "[WARN] Failed to write audit log #{@audit_log_path}: #{e.message}")
|
|
69
70
|
end
|
|
70
71
|
end
|
|
71
72
|
end
|
|
@@ -367,6 +367,8 @@ module Rubik
|
|
|
367
367
|
return false if p =~ %r{\A[a-zA-Z]:(?![\\/])}
|
|
368
368
|
|
|
369
369
|
return true if p =~ %r{\A/(?:\*|\.+)?/?\z}
|
|
370
|
+
# Root-anchored variable expansion (/$x, /$x/*, /${x}) can expand to / or /* when empty
|
|
371
|
+
return true if p =~ %r{\A/\$}
|
|
370
372
|
return true if p =~ %r{\A[a-zA-Z]:[\\/](?:\*|\.+)?\z}i
|
|
371
373
|
return true if HOME_TOKENS.include?(p) || p.start_with?("~/", "$HOME/", "${HOME}/")
|
|
372
374
|
|